Skip to contentSkip to conversation

nfnetlink: use rcu_assign_pointer in nfnetlink_subsys_unregister

PATCH In review Gao feng 2 participants 3 messages Oct 8, 2013 – Oct 9, 2013

Subsystems (2)
lore
Share & tools
lore

Gao feng

author
#0 lore raw

PATCH 1/1 nfnetlink: use rcu_assign_pointer in nfnetlink_subsys_unregister

Though I don't face an oops, but it is more safer to set table's subsys through rcu_assign_pointer.

---
 net/netfilter/nfnetlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nfnetlink.c +1 -1
index 572d87d..3cd2fe6 100644
@@ -78,7 +78,7 @@ EXPORT_SYMBOL_GPL(nfnetlink_subsys_register);
 int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n)
 {
 	nfnl_lock(n->subsys_id);
-	table[n->subsys_id].subsys = NULL;
+	rcu_assign_pointer(table[n->subsys_id].subsys, NULL);
 	nfnl_unlock(n->subsys_id);
 	synchronize_rcu();
 	return 0;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 13 lines · Gao feng

Though I don't face an oops, but it is more safer to set table's subsys through rcu_assign_pointer.

---
 net/netfilter/nfnetlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nfnetlink.c +0 -0
index 572d87d..3cd2fe6 100644

net/netfilter/nfnetlink.c EXPORT_SYMBOL_GPL(nfnetlink_subsys_register); · line 84

Quoted 8 lines
net/netfilter/nfnetlink.c +1 -1
@@ -78,7 +78,7 @@ EXPORT_SYMBOL_GPL(nfnetlink_subsys_register);
 int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n)
 {
 	nfnl_lock(n->subsys_id);
-	table[n->subsys_id].subsys = NULL;
+	rcu_assign_pointer(table[n->subsys_id].subsys, NULL);
 	nfnl_unlock(n->subsys_id);
 	synchronize_rcu();
 	return 0;

Certainly not.

Assigning a NULL pointer do not require rcu_assign_pointer() but this, if you want to be really really clean.

net/netfilter/nfnetlink.c +1 -1
index 572d87d..649958b 100644
@@ -78,7 +78,7 @@ EXPORT_SYMBOL_GPL(nfnetlink_subsys_register);
 int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n)
 {
 	nfnl_lock(n->subsys_id);
-	table[n->subsys_id].subsys = NULL;
+	RCU_INIT_POINTER(table[n->subsys_id].subsys, NULL);
 	nfnl_unlock(n->subsys_id);
 	synchronize_rcu();
 	return 0;
author
#2 lore raw
Quoted 25 lines · Eric Dumazet
Quoted 13 lines · Gao feng

Though I don't face an oops, but it is more safer to set table's subsys through rcu_assign_pointer.

---
 net/netfilter/nfnetlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nfnetlink.c +0 -0
index 572d87d..3cd2fe6 100644

net/netfilter/nfnetlink.c EXPORT_SYMBOL_GPL(nfnetlink_subsys_register); · line 84

Quoted 8 lines
net/netfilter/nfnetlink.c +1 -1
@@ -78,7 +78,7 @@ EXPORT_SYMBOL_GPL(nfnetlink_subsys_register);
 int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n)
 {
 	nfnl_lock(n->subsys_id);
-	table[n->subsys_id].subsys = NULL;
+	rcu_assign_pointer(table[n->subsys_id].subsys, NULL);
 	nfnl_unlock(n->subsys_id);
 	synchronize_rcu();
 	return 0;

Certainly not.

Quoted 3 lines

Assigning a NULL pointer do not require rcu_assign_pointer() but this, if you want to be really really clean.

The reason assigning a NULL pointer do not require rcu_assign_pointer is it's impossible for a reader to access to uninitialized content? So we don't need write barrier here to make sure the resource being initialized before reader accessing it. Right?

Quoted 18 lines
net/netfilter/nfnetlink.c +1 -1
index 572d87d..649958b 100644
@@ -78,7 +78,7 @@ EXPORT_SYMBOL_GPL(nfnetlink_subsys_register);
 int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n)
 {
 	nfnl_lock(n->subsys_id);
-	table[n->subsys_id].subsys = NULL;
+	RCU_INIT_POINTER(table[n->subsys_id].subsys, NULL);
 	nfnl_unlock(n->subsys_id);
 	synchronize_rcu();
 	return 0;