diff mbox

[net-next] bpf: netdev is never null in __dev_map_flush

Message ID d8e0306b70b05bdd5e628459863d1027c8c26959.1503537400.git.daniel@iogearbox.net
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Daniel Borkmann Aug. 24, 2017, 1:20 a.m. UTC
No need to test for it in fast-path, every dev in bpf_dtab_netdev
is guaranteed to be non-NULL, otherwise dev_map_update_elem() will
fail in the first place.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
 kernel/bpf/devmap.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Alexei Starovoitov Aug. 24, 2017, 1:25 a.m. UTC | #1
On 8/23/17 6:20 PM, Daniel Borkmann wrote:
> No need to test for it in fast-path, every dev in bpf_dtab_netdev
> is guaranteed to be non-NULL, otherwise dev_map_update_elem() will
> fail in the first place.
>
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

wow. interesting. I'm surprised you see a difference from
such micro-optimization.
Acked-by: Alexei Starovoitov <ast@kernel.org>
John Fastabend Aug. 24, 2017, 3:10 a.m. UTC | #2
On 08/23/2017 06:25 PM, Alexei Starovoitov wrote:
> On 8/23/17 6:20 PM, Daniel Borkmann wrote:
>> No need to test for it in fast-path, every dev in bpf_dtab_netdev
>> is guaranteed to be non-NULL, otherwise dev_map_update_elem() will
>> fail in the first place.
>>
>> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
> 
> wow. interesting. I'm surprised you see a difference from
> such micro-optimization.
> Acked-by: Alexei Starovoitov <ast@kernel.org>
> 
> 

Thanks for the clean up, I was a bit over paranoid here as well. Is
this actually noticeable in pps benchmark or just making the code
cleaner? Just curious.

Acked-by: John Fastabend <john.fastabend@gmail.com>
David Miller Aug. 24, 2017, 5:43 a.m. UTC | #3
From: Daniel Borkmann <daniel@iogearbox.net>
Date: Thu, 24 Aug 2017 03:20:11 +0200

> No need to test for it in fast-path, every dev in bpf_dtab_netdev
> is guaranteed to be non-NULL, otherwise dev_map_update_elem() will
> fail in the first place.
> 
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

Applied.
Daniel Borkmann Aug. 24, 2017, 8:34 a.m. UTC | #4
On 08/24/2017 05:10 AM, John Fastabend wrote:
> On 08/23/2017 06:25 PM, Alexei Starovoitov wrote:
>> On 8/23/17 6:20 PM, Daniel Borkmann wrote:
>>> No need to test for it in fast-path, every dev in bpf_dtab_netdev
>>> is guaranteed to be non-NULL, otherwise dev_map_update_elem() will
>>> fail in the first place.
>>>
>>> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
>>
>> wow. interesting. I'm surprised you see a difference from
>> such micro-optimization.
>> Acked-by: Alexei Starovoitov <ast@kernel.org>
>
> Thanks for the clean up, I was a bit over paranoid here as well. Is
> this actually noticeable in pps benchmark or just making the code
> cleaner? Just curious.

No, just from going over the code wondering why it could be
null here but not elsewhere.
diff mbox

Patch

diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index bfecabf..ecf9f99 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -226,12 +226,10 @@  void __dev_map_flush(struct bpf_map *map)
 		if (unlikely(!dev))
 			continue;
 
-		netdev = dev->dev;
 		__clear_bit(bit, bitmap);
-		if (unlikely(!netdev || !netdev->netdev_ops->ndo_xdp_flush))
-			continue;
-
-		netdev->netdev_ops->ndo_xdp_flush(netdev);
+		netdev = dev->dev;
+		if (likely(netdev->netdev_ops->ndo_xdp_flush))
+			netdev->netdev_ops->ndo_xdp_flush(netdev);
 	}
 }