netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nfnetlink: use rcu_assign_pointer in nfnetlink_subsys_unregister
@ 2013-10-08 10:04 Gao feng
  2013-10-08 15:23 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Gao feng @ 2013-10-08 10:04 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Gao feng

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

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
---
 net/netfilter/nfnetlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index 572d87d..3cd2fe6 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -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;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] nfnetlink: use rcu_assign_pointer in nfnetlink_subsys_unregister
  2013-10-08 10:04 [PATCH] nfnetlink: use rcu_assign_pointer in nfnetlink_subsys_unregister Gao feng
@ 2013-10-08 15:23 ` Eric Dumazet
  2013-10-09  3:28   ` Gao feng
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2013-10-08 15:23 UTC (permalink / raw)
  To: Gao feng; +Cc: netfilter-devel

On Tue, 2013-10-08 at 18:04 +0800, Gao feng wrote:
> Though I don't face an oops, but it is more safer to
> set table's subsys through rcu_assign_pointer.
> 
> Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
> ---
>  net/netfilter/nfnetlink.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
> index 572d87d..3cd2fe6 100644
> --- a/net/netfilter/nfnetlink.c
> +++ b/net/netfilter/nfnetlink.c
> @@ -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.

diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index 572d87d..649958b 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -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;





^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] nfnetlink: use rcu_assign_pointer in nfnetlink_subsys_unregister
  2013-10-08 15:23 ` Eric Dumazet
@ 2013-10-09  3:28   ` Gao feng
  0 siblings, 0 replies; 3+ messages in thread
From: Gao feng @ 2013-10-09  3:28 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: netfilter-devel

On 10/08/2013 11:23 PM, Eric Dumazet wrote:
> On Tue, 2013-10-08 at 18:04 +0800, Gao feng wrote:
>> Though I don't face an oops, but it is more safer to
>> set table's subsys through rcu_assign_pointer.
>>
>> Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
>> ---
>>  net/netfilter/nfnetlink.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
>> index 572d87d..3cd2fe6 100644
>> --- a/net/netfilter/nfnetlink.c
>> +++ b/net/netfilter/nfnetlink.c
>> @@ -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.
> 

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?

> diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
> index 572d87d..649958b 100644
> --- a/net/netfilter/nfnetlink.c
> +++ b/net/netfilter/nfnetlink.c
> @@ -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;
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-10-09  3:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-08 10:04 [PATCH] nfnetlink: use rcu_assign_pointer in nfnetlink_subsys_unregister Gao feng
2013-10-08 15:23 ` Eric Dumazet
2013-10-09  3:28   ` Gao feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).