Skip to content

Commit 0eb5db7

Browse files
kaberummakynes
authored andcommitted
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>
1 parent 3e90ebd commit 0eb5db7

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎include/linux/netfilter/nfnetlink.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid,
4444

4545
void nfnl_lock(__u8 subsys_id);
4646
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))
4768

4869
#define MODULE_ALIAS_NFNL_SUBSYS(subsys) \
4970
MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys))

‎net/netfilter/nfnetlink.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ void nfnl_unlock(__u8 subsys_id)
6161
}
6262
EXPORT_SYMBOL_GPL(nfnl_unlock);
6363

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+
6472
int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n)
6573
{
6674
nfnl_lock(n->subsys_id);

0 commit comments

Comments
 (0)