netfilter: helper: Remove useless rcu lock when get expectfn
Subsystems (2)
PATCH v2 1/1 netfilter: helper: Remove useless rcu lock when get expectfn
From: Gao Feng <[email protected]>
Because these two functions return the nf_ct_helper_expectfn pointer which should be protected by rcu lock. So it should makes sure the caller should hold the rcu lock, not inside these functions.
---
v2: Shorter subject, per Pablo
v1: Initial version
net/netfilter/nf_conntrack_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/netfilter/nf_conntrack_helper.c +2 -4
@@ -311,38 +311,36 @@ void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_unregister); +/* Caller should hold the rcu lock */ struct nf_ct_helper_expectfn *nf_ct_helper_expectfn_find_by_name (const char *name) {struct nf_ct_helper_expectfn *cur;bool found = false; -rcu_read_lock ();list_for_each_entry_rcu (cur, &nf_ct_helper_expectfn_list, head) {if (!strcmp (cur->name, name)) { found = true;break ; } } -rcu_read_unlock ();return found ? cur :NULL ; }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_find_by_name); +/* Caller should hold the rcu lock */ struct nf_ct_helper_expectfn *nf_ct_helper_expectfn_find_by_symbol (const void *symbol) {struct nf_ct_helper_expectfn *cur;bool found = false; -rcu_read_lock ();list_for_each_entry_rcu (cur, &nf_ct_helper_expectfn_list, head) {if (cur->expectfn == symbol) { found = true;break ; } } -rcu_read_unlock ();return found ? cur :NULL ; }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_find_by_symbol);
Signature · 1 line
1.9.1
Pablo Neira Ayuso
maintainerQuoted 30 lines · On Wed, Mar 22, 2017 at 10:15:02AM +0800, [email protected] wrote:
From: Gao Feng <[email protected]>
Because these two functions return the
nf_ct_helper_expectfnpointer which should be protected by rcu lock. So it should makes sure the caller should hold the rcu lock, not inside these functions.Signed-off-by Gao Feng <[email protected]>---
v2: Shorter subject, per Pablo
v1: Initial versionnet/netfilter/nf_conntrack_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)net/netfilter/nf_conntrack_helper.c +1
-1@@ -311,38 +311,36 @@ void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_unregister); +/* Caller should hold the rcu lock */ struct nf_ct_helper_expectfn *nf_ct_helper_expectfn_find_by_name (const char *name) {struct nf_ct_helper_expectfn *cur;bool found = false; -rcu_read_lock ();
net/netfilter/nf_conntrack_helper.c void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) · line 329
Quoted 10 lines
net/netfilter/nf_conntrack_helper.c +0
-1list_for_each_entry_rcu (cur, &nf_ct_helper_expectfn_list, head) {if (!strcmp (cur->name, name)) { found = true;break ; } } -rcu_read_unlock ();return found ? cur :NULL ; }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_find_by_name);
nf_ct_helper_expectfn_find_by_name() is called from ctnetlink, via ctnetlink_create_expect() and rcu read side lock is not held there.
Hi Pablo,
Quoted 6 lines
-----Original Message-----
From: Pablo Neira Ayuso [mailto:[email protected]]
Sent: Wednesday, March 29, 2017 6:08 PM
To: [email protected]
Cc: [email protected]; Gao Feng <[email protected]>
Subject: Re: [PATCH nf-next v2 1/1] netfilter: helper: Remove useless rcu
lock
Quoted 32 lines
when get expectfn
Quoted 29 lines · On Wed, Mar 22, 2017 at 10:15:02AM +0800, [email protected] wrote:
From: Gao Feng <[email protected]>
Because these two functions return the
nf_ct_helper_expectfnpointer which should be protected by rcu lock. So it should makes sure the caller should hold the rcu lock, not inside these functions.Signed-off-by Gao Feng <[email protected]>---
v2: Shorter subject, per Pablo
v1: Initial versionnet/netfilter/nf_conntrack_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)net/netfilter/nf_conntrack_helper.c +1
-0@@ -311,38 +311,36 @@ void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_unregister); +/* Caller should hold the rcu lock */ struct nf_ct_helper_expectfn *nf_ct_helper_expectfn_find_by_name (const char *name) {struct nf_ct_helper_expectfn *cur;bool found = false;
Quoted 14 lines
net/netfilter/nf_conntrack_helper.c void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) · line 329
Quoted 11 lines
net/netfilter/nf_conntrack_helper.c +0
-2-rcu_read_lock ();list_for_each_entry_rcu (cur, &nf_ct_helper_expectfn_list, head) {if (!strcmp (cur->name, name)) { found = true;break ; } } -rcu_read_unlock ();return found ? cur :NULL ; }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_find_by_name);
nf_ct_helper_expectfn_find_by_name()is called from ctnetlink, viactnetlink_create_expect()and rcu read side lock is not held there.
There are two reasons.
1. The rcu lock would be added in my patch " netfilter: helper: Add the rcu lock when call __nf_conntrack_helper_find" for nf
https://patchwork.ozlabs.org/patch/741865/.
So the ctnetlink_create_expect would hold the rcu lock after apply that patch.
2. Because these two functions return one pointer which needs RCU lock, so the caller must hold rcu lock.
Or it still meets one error even though there is one rcu lock in these two functions.
Because the memory which the returned pointer point to would be freed already after rcu_read_unlock.
So the rcu lock is unnecessary in these functions.
Best Regards
Feng
Pablo Neira Ayuso
maintainerQuoted 55 lines · Gao Feng
Hi Pablo,
Quoted 6 lines
-----Original Message-----
From: Pablo Neira Ayuso [mailto:[email protected]]
Sent: Wednesday, March 29, 2017 6:08 PM
To: [email protected]
Cc: [email protected]; Gao Feng <[email protected]>
Subject: Re: [PATCH nf-next v2 1/1] netfilter: helper: Remove useless rculock
Quoted 32 lines
when get expectfn
Quoted 29 lines · On Wed, Mar 22, 2017 at 10:15:02AM +0800, [email protected] wrote:
From: Gao Feng <[email protected]>
Because these two functions return the
nf_ct_helper_expectfnpointer which should be protected by rcu lock. So it should makes sure the caller should hold the rcu lock, not inside these functions.Signed-off-by Gao Feng <[email protected]>---
v2: Shorter subject, per Pablo
v1: Initial versionnet/netfilter/nf_conntrack_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)net/netfilter/nf_conntrack_helper.c +1
-0@@ -311,38 +311,36 @@ void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_unregister); +/* Caller should hold the rcu lock */ struct nf_ct_helper_expectfn *nf_ct_helper_expectfn_find_by_name (const char *name) {struct nf_ct_helper_expectfn *cur;bool found = false;Quoted 14 lines
net/netfilter/nf_conntrack_helper.c void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) · line 329
Quoted 11 lines
net/netfilter/nf_conntrack_helper.c +0
-2-rcu_read_lock ();list_for_each_entry_rcu (cur, &nf_ct_helper_expectfn_list, head) {if (!strcmp (cur->name, name)) { found = true;break ; } } -rcu_read_unlock ();return found ? cur :NULL ; }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_find_by_name);
nf_ct_helper_expectfn_find_by_name()is called from ctnetlink, viactnetlink_create_expect()and rcu read side lock is not held there.
Quoted 4 lines
There are two reasons.
1. The rcu lock would be added in my patch " netfilter: helper: Add the rcu lock when call__nf_conntrack_helper_find" for nf
https://patchwork.ozlabs.org/patch/741865/.
If you have interdependencies between two patches like this, it's better to make it in one single go.
Quoted 10 lines
So the
ctnetlink_create_expectwould hold the rcu lock after apply that patch.2. Because these two functions return one pointer which needs RCU lock, so the caller must hold rcu lock.
Or it still meets one error even though there is one rcu lock in these two functions.
Because the memory which the returned pointer point to would be freed already afterrcu_read_unlock.
So the rcu lock is unnecessary in these functions.
That's right. You're fixing up a real problem, no doubt.
I'm just questioning that I think that if you are fixing up rcu locking, which seems to be the case, you just do it in one single patch.
Thanks!
Hi Pablo,
Quoted 6 lines
-----Original Message-----
From: Pablo Neira Ayuso [mailto:[email protected]]
Sent: Wednesday, March 29, 2017 6:44 PM
To: Gao Feng <[email protected]>
Cc: [email protected]; 'Gao Feng' <[email protected]>
Subject: Re: [PATCH nf-next v2 1/1] netfilter: helper: Remove useless rcu
lock
Quoted 12 lines
when get expectfn
Quoted 9 lines · Gao Feng
Hi Pablo,
Quoted 7 lines
-----Original Message-----
From: Pablo Neira Ayuso [mailto:[email protected]]
Sent: Wednesday, March 29, 2017 6:08 PM
To: [email protected]
Cc: [email protected]; Gao Feng <[email protected]>
Subject: Re: [PATCH nf-next v2 1/1] netfilter: helper: Remove useless rcu
Quoted 10 lines
Quoted 4 lines
lock
Quoted 3 lines
when get expectfn
On Wed, Mar 22, 2017 at 10:15:02AM +0800, [email protected]
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 5 lines
From: Gao Feng <[email protected]>
Because these two functions return the
nf_ct_helper_expectfnpointer which should be protected by rcu lock. So it should makes sure the caller should hold the rcu lock, not inside these
functions.
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Signed-off-by Gao Feng <[email protected]>---
v2: Shorter subject, per Pablo
v1: Initial versionnet/netfilter/nf_conntrack_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)net/netfilter/nf_conntrack_helper.c +0
-0@@ -311,38 +311,36 @@ void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_unregister);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/netfilter/nf_conntrack_helper.c void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n)
Quoted 8 lines
net/netfilter/nf_conntrack_helper.c +1
-1+/* Caller should hold the rcu lock */ struct nf_ct_helper_expectfn *nf_ct_helper_expectfn_find_by_name (const char *name) {struct nf_ct_helper_expectfn *cur;bool found = false; -rcu_read_lock (); list_for_each_entry_rcu(cur, &nf_ct_helper_expectfn_list,
head) {
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
net/netfilter/nf_conntrack_helper.c void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) · line 329
Quoted 9 lines
net/netfilter/nf_conntrack_helper.c +0
-1if (!strcmp (cur->name, name)) { found = true;break ; } } -rcu_read_unlock ();return found ? cur :NULL ; }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_find_by_name);
nf_ct_helper_expectfn_find_by_name()is called from ctnetlink, viactnetlink_create_expect()and rcu read side lock is not held there.
Quoted 6 lines
Quoted 4 lines
There are two reasons.
1. The rcu lock would be added in my patch " netfilter: helper: Add the rcu lock when call__nf_conntrack_helper_find" for nf
https://patchwork.ozlabs.org/patch/741865/.If you have interdependencies between two patches like this, it's better
to
Quoted 13 lines
make it in one single go.
Quoted 10 lines
So the
ctnetlink_create_expectwould hold the rcu lock after apply that patch.2. Because these two functions return one pointer which needs RCU lock, so the caller must hold rcu lock.
Or it still meets one error even though there is one rcu lock in these two functions.
Because the memory which the returned pointer point to would be freed already afterrcu_read_unlock.
So the rcu lock is unnecessary in these functions.
Quoted 3 lines
That's right. You're fixing up a real problem, no doubt.
I'm just questioning that I think that if you are fixing up rcu locking,
which
Quoted 3 lines
seems to be the case, you just do it in one single patch.
Thanks!
Ok, I would merge them into one patch.
Actually I couldn't get that what modifications could be done in the nf. I learnt only bug fix could be accepted in net.git, so I assumed the nf.git did too.
Best Regards
Feng
Pablo Neira Ayuso
maintainerQuoted 95 lines · Gao Feng
Hi Pablo,
Quoted 6 lines
-----Original Message-----
From: Pablo Neira Ayuso [mailto:[email protected]]
Sent: Wednesday, March 29, 2017 6:44 PM
To: Gao Feng <[email protected]>
Cc: [email protected]; 'Gao Feng' <[email protected]>
Subject: Re: [PATCH nf-next v2 1/1] netfilter: helper: Remove useless rculock
Quoted 12 lines
when get expectfn
Quoted 9 lines · Gao Feng
Hi Pablo,
Quoted 7 lines
-----Original Message-----
From: Pablo Neira Ayuso [mailto:[email protected]]
Sent: Wednesday, March 29, 2017 6:08 PM
To: [email protected]
Cc: [email protected]; Gao Feng <[email protected]>
Subject: Re: [PATCH nf-next v2 1/1] netfilter: helper: Remove useless rcuQuoted 10 lines
Quoted 4 lines
lock
Quoted 3 lines
when get expectfn
On Wed, Mar 22, 2017 at 10:15:02AM +0800, [email protected]
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 5 lines
From: Gao Feng <[email protected]>
Because these two functions return the
nf_ct_helper_expectfnpointer which should be protected by rcu lock. So it should makes sure the caller should hold the rcu lock, not inside thesefunctions.
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Signed-off-by Gao Feng <[email protected]>---
v2: Shorter subject, per Pablo
v1: Initial versionnet/netfilter/nf_conntrack_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)net/netfilter/nf_conntrack_helper.c +0
-0@@ -311,38 +311,36 @@ void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_unregister);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/netfilter/nf_conntrack_helper.c void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n)
Quoted 8 lines
net/netfilter/nf_conntrack_helper.c +1
-1+/* Caller should hold the rcu lock */ struct nf_ct_helper_expectfn *nf_ct_helper_expectfn_find_by_name (const char *name) {struct nf_ct_helper_expectfn *cur;bool found = false; -rcu_read_lock (); list_for_each_entry_rcu(cur, &nf_ct_helper_expectfn_list,head) {
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
net/netfilter/nf_conntrack_helper.c void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) · line 329
Quoted 9 lines
net/netfilter/nf_conntrack_helper.c +0
-1if (!strcmp (cur->name, name)) { found = true;break ; } } -rcu_read_unlock ();return found ? cur :NULL ; }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_find_by_name);
nf_ct_helper_expectfn_find_by_name()is called from ctnetlink, viactnetlink_create_expect()and rcu read side lock is not held there.Quoted 6 lines
Quoted 4 lines
There are two reasons.
1. The rcu lock would be added in my patch " netfilter: helper: Add the rcu lock when call__nf_conntrack_helper_find" for nf
https://patchwork.ozlabs.org/patch/741865/.If you have interdependencies between two patches like this, it's better
to
Quoted 13 lines
make it in one single go.
Quoted 10 lines
So the
ctnetlink_create_expectwould hold the rcu lock after apply that patch.2. Because these two functions return one pointer which needs RCU lock, so the caller must hold rcu lock.
Or it still meets one error even though there is one rcu lock in these two functions.
Because the memory which the returned pointer point to would be freed already afterrcu_read_unlock.
So the rcu lock is unnecessary in these functions.Quoted 3 lines
That's right. You're fixing up a real problem, no doubt.
I'm just questioning that I think that if you are fixing up rcu locking,
which
Quoted 8 lines
Quoted 3 lines
seems to be the case, you just do it in one single patch.
Thanks!
Ok, I would merge them into one patch.
Actually I couldn't get that what modifications could be done in the nf. I learnt only bug fix could be accepted in net.git, so I assumed the nf.git did too.
Yes, fixes go to nf.git and updates go to nf-next.git.
But in this case this has to go through nf.git since both patches (that should be one) are part of the same logical changes since they are required to fix up the RCU read side locking there consistently.