Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nfnetlink: add rcu_dereference_protected() helpers

Add a lockdep_nfnl_is_held() function and a nfnl_dereference() macro for
RCU dereferences protected by a NFNL subsystem mutex.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Patrick McHardy and committed by
Pablo Neira Ayuso
0eb5db7a 3e90ebd3

+29
+21
include/linux/netfilter/nfnetlink.h
··· 44 44 45 45 void nfnl_lock(__u8 subsys_id); 46 46 void nfnl_unlock(__u8 subsys_id); 47 + #ifdef CONFIG_PROVE_LOCKING 48 + int lockdep_nfnl_is_held(__u8 subsys_id); 49 + #else 50 + static inline int lockdep_nfnl_is_held(__u8 subsys_id) 51 + { 52 + return 1; 53 + } 54 + #endif /* CONFIG_PROVE_LOCKING */ 55 + 56 + /* 57 + * nfnl_dereference - fetch RCU pointer when updates are prevented by subsys mutex 58 + * 59 + * @p: The pointer to read, prior to dereferencing 60 + * @ss: The nfnetlink subsystem ID 61 + * 62 + * Return the value of the specified RCU-protected pointer, but omit 63 + * both the smp_read_barrier_depends() and the ACCESS_ONCE(), because 64 + * caller holds the NFNL subsystem mutex. 65 + */ 66 + #define nfnl_dereference(p, ss) \ 67 + rcu_dereference_protected(p, lockdep_nfnl_is_held(ss)) 47 68 48 69 #define MODULE_ALIAS_NFNL_SUBSYS(subsys) \ 49 70 MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys))
+8
net/netfilter/nfnetlink.c
··· 61 61 } 62 62 EXPORT_SYMBOL_GPL(nfnl_unlock); 63 63 64 + #ifdef CONFIG_PROVE_LOCKING 65 + int lockdep_nfnl_is_held(u8 subsys_id) 66 + { 67 + return lockdep_is_held(&table[subsys_id].mutex); 68 + } 69 + EXPORT_SYMBOL_GPL(lockdep_nfnl_is_held); 70 + #endif 71 + 64 72 int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n) 65 73 { 66 74 nfnl_lock(n->subsys_id);