diff mbox series

[bpf-next,03/17] dev: add rcu_read_lock_bh_held() as a valid check when getting a RCU dev ref

Message ID 20210609103326.278782-4-toke@redhat.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series Clean up and document RCU-based object protection for XDP_REDIRECT | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count fail Series longer than 15 patches
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 15 maintainers not CCed: yhs@fb.com kpsingh@kernel.org daniel@iogearbox.net andrii@kernel.org hawk@kernel.org ast@kernel.org ap420073@gmail.com john.fastabend@gmail.com edumazet@google.com kuba@kernel.org songliubraving@fb.com alobakin@pm.me atenart@kernel.org davem@davemloft.net weiwan@google.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 6 this patch: 6
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 6 this patch: 6
netdev/header_inline success Link

Commit Message

Toke Høiland-Jørgensen June 9, 2021, 10:33 a.m. UTC
Some of the XDP helpers (in particular, xdp_do_redirect()) will get a
struct net_device reference using dev_get_by_index_rcu(). These are called
from a NAPI poll context, which means the RCU reference liveness is ensured
by local_bh_disable(). Add rcu_read_lock_bh_held() as a condition to the
RCU list traversal in dev_get_by_index_rcu() so lockdep understands that
the dereferences are safe from *both* an rcu_read_lock() *and* with
local_bh_disable().

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Martin KaFai Lau June 10, 2021, 7:37 p.m. UTC | #1
On Wed, Jun 09, 2021 at 12:33:12PM +0200, Toke Høiland-Jørgensen wrote:
> Some of the XDP helpers (in particular, xdp_do_redirect()) will get a
> struct net_device reference using dev_get_by_index_rcu(). These are called
> from a NAPI poll context, which means the RCU reference liveness is ensured
> by local_bh_disable(). Add rcu_read_lock_bh_held() as a condition to the
> RCU list traversal in dev_get_by_index_rcu() so lockdep understands that
> the dereferences are safe from *both* an rcu_read_lock() *and* with
> local_bh_disable().
> 
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> ---
>  net/core/dev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/core/dev.c b/net/core/dev.c
> index febb23708184..a499c5ffe4a5 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -1002,7 +1002,7 @@ struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
>  	struct net_device *dev;
>  	struct hlist_head *head = dev_index_hash(net, ifindex);
>  
> -	hlist_for_each_entry_rcu(dev, head, index_hlist)
> +	hlist_for_each_entry_rcu(dev, head, index_hlist, rcu_read_lock_bh_held())
Is it needed?  hlist_for_each_entry_rcu() checks for
rcu_read_lock_any_held().  Did lockdep complain?
Toke Høiland-Jørgensen June 10, 2021, 11:05 p.m. UTC | #2
Martin KaFai Lau <kafai@fb.com> writes:

> On Wed, Jun 09, 2021 at 12:33:12PM +0200, Toke Høiland-Jørgensen wrote:
>> Some of the XDP helpers (in particular, xdp_do_redirect()) will get a
>> struct net_device reference using dev_get_by_index_rcu(). These are called
>> from a NAPI poll context, which means the RCU reference liveness is ensured
>> by local_bh_disable(). Add rcu_read_lock_bh_held() as a condition to the
>> RCU list traversal in dev_get_by_index_rcu() so lockdep understands that
>> the dereferences are safe from *both* an rcu_read_lock() *and* with
>> local_bh_disable().
>> 
>> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
>> ---
>>  net/core/dev.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/net/core/dev.c b/net/core/dev.c
>> index febb23708184..a499c5ffe4a5 100644
>> --- a/net/core/dev.c
>> +++ b/net/core/dev.c
>> @@ -1002,7 +1002,7 @@ struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
>>  	struct net_device *dev;
>>  	struct hlist_head *head = dev_index_hash(net, ifindex);
>>  
>> -	hlist_for_each_entry_rcu(dev, head, index_hlist)
>> +	hlist_for_each_entry_rcu(dev, head, index_hlist, rcu_read_lock_bh_held())
> Is it needed?  hlist_for_each_entry_rcu() checks for
> rcu_read_lock_any_held().  Did lockdep complain?

Ah, yes, I think you're right. I totally missed that
rcu_read_lock_any_held() includes a '!preemptible()' check at the end.
I'll drop this patch, then!

-Toke
diff mbox series

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index febb23708184..a499c5ffe4a5 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1002,7 +1002,7 @@  struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
 	struct net_device *dev;
 	struct hlist_head *head = dev_index_hash(net, ifindex);
 
-	hlist_for_each_entry_rcu(dev, head, index_hlist)
+	hlist_for_each_entry_rcu(dev, head, index_hlist, rcu_read_lock_bh_held())
 		if (dev->ifindex == ifindex)
 			return dev;