diff mbox series

[bpf-next] bpf/devmap: convert remaining READ_ONCE() to rcu_dereference()

Message ID 20210628230051.556099-1-toke@redhat.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next] bpf/devmap: convert remaining READ_ONCE() to rcu_dereference() | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers fail 1 blamed authors not CCed: daniel@iogearbox.net; 9 maintainers not CCed: yhs@fb.com kpsingh@kernel.org daniel@iogearbox.net andrii@kernel.org hawk@kernel.org ast@kernel.org john.fastabend@gmail.com songliubraving@fb.com davem@davemloft.net
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: 3 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 3 this patch: 1
netdev/header_inline success Link

Commit Message

Toke Høiland-Jørgensen June 28, 2021, 11 p.m. UTC
There were a couple of READ_ONCE()-invocations left-over by the devmap RCU
conversion. Convert these to rcu_dereference() as well to avoid complaints
from sparse.

Fixes: 782347b6bcad ("xdp: Add proper __rcu annotations to redirect map entries")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 kernel/bpf/devmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Paul E. McKenney June 28, 2021, 11:05 p.m. UTC | #1
On Tue, Jun 29, 2021 at 01:00:51AM +0200, Toke Høiland-Jørgensen wrote:
> There were a couple of READ_ONCE()-invocations left-over by the devmap RCU
> conversion. Convert these to rcu_dereference() as well to avoid complaints
> from sparse.
> 
> Fixes: 782347b6bcad ("xdp: Add proper __rcu annotations to redirect map entries")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>

Reviewed-by: Paul E. McKenney <paulmck@kernel.org>

> ---
>  kernel/bpf/devmap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
> index 2f6bd75cd682..7a0c008f751b 100644
> --- a/kernel/bpf/devmap.c
> +++ b/kernel/bpf/devmap.c
> @@ -558,7 +558,7 @@ int dev_map_enqueue_multi(struct xdp_buff *xdp, struct net_device *dev_rx,
>  
>  	if (map->map_type == BPF_MAP_TYPE_DEVMAP) {
>  		for (i = 0; i < map->max_entries; i++) {
> -			dst = READ_ONCE(dtab->netdev_map[i]);
> +			dst = rcu_dereference(dtab->netdev_map[i]);
>  			if (!is_valid_dst(dst, xdp, exclude_ifindex))
>  				continue;
>  
> @@ -654,7 +654,7 @@ int dev_map_redirect_multi(struct net_device *dev, struct sk_buff *skb,
>  
>  	if (map->map_type == BPF_MAP_TYPE_DEVMAP) {
>  		for (i = 0; i < map->max_entries; i++) {
> -			dst = READ_ONCE(dtab->netdev_map[i]);
> +			dst = rcu_dereference(dtab->netdev_map[i]);
>  			if (!dst || dst->dev->ifindex == exclude_ifindex)
>  				continue;
>  
> -- 
> 2.32.0
>
Martin KaFai Lau June 28, 2021, 11:55 p.m. UTC | #2
On Tue, Jun 29, 2021 at 01:00:51AM +0200, Toke Høiland-Jørgensen wrote:
> There were a couple of READ_ONCE()-invocations left-over by the devmap RCU
> conversion. Convert these to rcu_dereference() as well to avoid complaints
> from sparse.
> 
> Fixes: 782347b6bcad ("xdp: Add proper __rcu annotations to redirect map entries")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> ---
>  kernel/bpf/devmap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
> index 2f6bd75cd682..7a0c008f751b 100644
> --- a/kernel/bpf/devmap.c
> +++ b/kernel/bpf/devmap.c
> @@ -558,7 +558,7 @@ int dev_map_enqueue_multi(struct xdp_buff *xdp, struct net_device *dev_rx,
>  
>  	if (map->map_type == BPF_MAP_TYPE_DEVMAP) {
>  		for (i = 0; i < map->max_entries; i++) {
> -			dst = READ_ONCE(dtab->netdev_map[i]);
> +			dst = rcu_dereference(dtab->netdev_map[i]);
__dev_map_lookup_elem() uses rcu_dereference_check(dtab->netdev_map[key], rcu_read_lock_bh_held()).
It is not needed here?
Toke Høiland-Jørgensen June 29, 2021, 9:37 a.m. UTC | #3
Martin KaFai Lau <kafai@fb.com> writes:

> On Tue, Jun 29, 2021 at 01:00:51AM +0200, Toke Høiland-Jørgensen wrote:
>> There were a couple of READ_ONCE()-invocations left-over by the devmap RCU
>> conversion. Convert these to rcu_dereference() as well to avoid complaints
>> from sparse.
>> 
>> Fixes: 782347b6bcad ("xdp: Add proper __rcu annotations to redirect map entries")
>> Reported-by: kernel test robot <lkp@intel.com>
>> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
>> ---
>>  kernel/bpf/devmap.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
>> index 2f6bd75cd682..7a0c008f751b 100644
>> --- a/kernel/bpf/devmap.c
>> +++ b/kernel/bpf/devmap.c
>> @@ -558,7 +558,7 @@ int dev_map_enqueue_multi(struct xdp_buff *xdp, struct net_device *dev_rx,
>>  
>>  	if (map->map_type == BPF_MAP_TYPE_DEVMAP) {
>>  		for (i = 0; i < map->max_entries; i++) {
>> -			dst = READ_ONCE(dtab->netdev_map[i]);
>> +			dst = rcu_dereference(dtab->netdev_map[i]);
> __dev_map_lookup_elem() uses rcu_dereference_check(dtab->netdev_map[key], rcu_read_lock_bh_held()).
> It is not needed here?

Hmm, I somehow managed to convince myself last night that it wasn't, but
looking at it again now I think you're right. Will send a v2.

-Toke
diff mbox series

Patch

diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 2f6bd75cd682..7a0c008f751b 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -558,7 +558,7 @@  int dev_map_enqueue_multi(struct xdp_buff *xdp, struct net_device *dev_rx,
 
 	if (map->map_type == BPF_MAP_TYPE_DEVMAP) {
 		for (i = 0; i < map->max_entries; i++) {
-			dst = READ_ONCE(dtab->netdev_map[i]);
+			dst = rcu_dereference(dtab->netdev_map[i]);
 			if (!is_valid_dst(dst, xdp, exclude_ifindex))
 				continue;
 
@@ -654,7 +654,7 @@  int dev_map_redirect_multi(struct net_device *dev, struct sk_buff *skb,
 
 	if (map->map_type == BPF_MAP_TYPE_DEVMAP) {
 		for (i = 0; i < map->max_entries; i++) {
-			dst = READ_ONCE(dtab->netdev_map[i]);
+			dst = rcu_dereference(dtab->netdev_map[i]);
 			if (!dst || dst->dev->ifindex == exclude_ifindex)
 				continue;