From c0862b2b1fa91636d308a1a41d8dc370691d656e Mon Sep 17 00:00:00 2001 From: Vladimir Kondratyev Date: Mon, 5 Jul 2021 03:19:35 +0300 Subject: [PATCH] LinuxKPI: Add compiler barriers to list_for_each_entry_lockless macro so this list-traversal primitive may safely run concurrently with the _rcu list-mutation primitives such as list_add_rcu() as long as the traversal is guarded by rcu_read_lock(). Do it by reusing the "list_for_each_entry_rcu" macro which does the same. On Linux it implements some additional lockdep stuff which we skip. Also move the macro to linux/rculist.h where it resides on Linux. Reviewed by: hselasky Differential revision: https://reviews.freebsd.org/D30795 --- sys/compat/linuxkpi/common/include/linux/list.h | 2 -- sys/compat/linuxkpi/common/include/linux/rculist.h | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/list.h b/sys/compat/linuxkpi/common/include/linux/list.h index 93db449a4473..37b5b751d21b 100644 --- a/sys/compat/linuxkpi/common/include/linux/list.h +++ b/sys/compat/linuxkpi/common/include/linux/list.h @@ -202,8 +202,6 @@ list_del_init(struct list_head *entry) for (p = list_entry((h)->next, typeof(*p), field); &(p)->field != (h); \ p = list_entry((p)->field.next, typeof(*p), field)) -#define list_for_each_entry_lockless(...) list_for_each_entry(__VA_ARGS__) - #define list_for_each_entry_safe(p, n, h, field) \ for (p = list_entry((h)->next, typeof(*p), field), \ n = list_entry((p)->field.next, typeof(*p), field); &(p)->field != (h);\ diff --git a/sys/compat/linuxkpi/common/include/linux/rculist.h b/sys/compat/linuxkpi/common/include/linux/rculist.h index bff2f7e13184..6c21a6943f98 100644 --- a/sys/compat/linuxkpi/common/include/linux/rculist.h +++ b/sys/compat/linuxkpi/common/include/linux/rculist.h @@ -44,6 +44,9 @@ &(pos)->member != (head); \ pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member)) +#define list_for_each_entry_lockless(pos, head, member) \ + list_for_each_entry_rcu(pos, head, member) + static inline void linux_list_add_rcu(struct list_head *new, struct list_head *prev, struct list_head *next)