Date: Wed, 6 Jun 2018 15:49:01 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334720 - head/sys/compat/linuxkpi/common/include/linux Message-ID: <201806061549.w56Fn1Xe077167@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Wed Jun 6 15:49:01 2018 New Revision: 334720 URL: https://svnweb.freebsd.org/changeset/base/334720 Log: Make some list functions RCU safe in the LinuxKPI. While at it rename hlist_add_after() into hlist_add_behind(). Submitted by: Johannes Lundberg <johalun0@gmail.com> MFC after: 1 week Sponsored by: Mellanox Technologies Sponsored by: Limelight Networks Modified: head/sys/compat/linuxkpi/common/include/linux/list.h Modified: head/sys/compat/linuxkpi/common/include/linux/list.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/list.h Wed Jun 6 15:45:57 2018 (r334719) +++ head/sys/compat/linuxkpi/common/include/linux/list.h Wed Jun 6 15:49:01 2018 (r334720) @@ -337,16 +337,16 @@ static inline int hlist_empty(const struct hlist_head *h) { - return !h->first; + return !READ_ONCE(h->first); } static inline void hlist_del(struct hlist_node *n) { - if (n->next) + WRITE_ONCE(*(n->pprev), n->next); + if (n->next != NULL) n->next->pprev = n->pprev; - *n->pprev = n->next; } static inline void @@ -364,9 +364,9 @@ hlist_add_head(struct hlist_node *n, struct hlist_head { n->next = h->first; - if (h->first) + if (h->first != NULL) h->first->pprev = &n->next; - h->first = n; + WRITE_ONCE(h->first, n); n->pprev = &h->first; } @@ -377,18 +377,19 @@ hlist_add_before(struct hlist_node *n, struct hlist_no n->pprev = next->pprev; n->next = next; next->pprev = &n->next; - *(n->pprev) = n; + WRITE_ONCE(*(n->pprev), n); } static inline void -hlist_add_after(struct hlist_node *n, struct hlist_node *next) +hlist_add_behind(struct hlist_node *n, struct hlist_node *prev) { - next->next = n->next; - n->next = next; - next->pprev = &n->next; - if (next->next) - next->next->pprev = &next->next; + n->next = prev->next; + WRITE_ONCE(prev->next, n); + n->pprev = &prev->next; + + if (n->next != NULL) + n->next->pprev = &n->next; } static inline void
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806061549.w56Fn1Xe077167>