Skip to contentSkip to conversation

AF_XDP small fixes

PATCH Applied Maciej Fijalkowski 3 participants 6 messages Mar 3, 2021 – Mar 4, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover AF_XDP small fixes

Hi,

This time three no-brainers, one is a fix that I sent among with bpf_link for AF_XDP set where John suggested that it should land in bpf tree.

Other is the missing munmap on xdpsock and some ancient function declaration removal.

Thanks!
Maciej

v2:
- collect Bjorn's Acks
- change strlen to sizeof in patch 3

Maciej Fijalkowski (3):
xsk: remove dangling function declaration from header file
samples: bpf: add missing munmap in xdpsock
libbpf: clear map_info before each bpf_obj_get_info_by_fd

 include/linux/netdevice.h  | 2 --
 samples/bpf/xdpsock_user.c | 2 ++
 tools/lib/bpf/xsk.c        | 5 +++--
 3 files changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/3 xsk: remove dangling function declaration from header file

xdp_umem_query() is dead for a long time, drop the declaration from include/linux/netdevice.h

Fixes c9b47cc1fabc ("xsk: fix bug when trying to use both copy and zero-copy on one queue id")
---
 include/linux/netdevice.h | 2 --
 1 file changed, 2 deletions(-)
include/linux/netdevice.h +0 -2
index 6cef47b76cc6..226303976310 100644
@@ -3932,8 +3932,6 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
 int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
 u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode);
 
-int xdp_umem_query(struct net_device *dev, u16 queue_id);
-
 int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
 int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
 int dev_forward_skb_nomtu(struct net_device *dev, struct sk_buff *skb);
Signature · 1 line
2.20.1
#2 lore raw

PATCH v2 2/3 samples: bpf: add missing munmap in xdpsock

In reply to Maciej Fijalkowski

We mmap the umem region, but we never munmap it.
Add the missing call at the end of the cleanup.

Fixes 3945b37a975d ("samples/bpf: use hugepages in xdpsock app")
---
 samples/bpf/xdpsock_user.c | 2 ++
 1 file changed, 2 insertions(+)
samples/bpf/xdpsock_user.c +2 -0
index db0cb73513a5..1e2a1105d0e6 100644
@@ -1699,5 +1699,7 @@ int main(int argc, char **argv)
 
 	xdpsock_cleanup();
 
+	munmap(bufs, NUM_FRAMES * opt_xsk_frame_size);
+
 	return 0;
 }
Signature · 1 line
2.20.1
#3 lore raw

PATCH v2 3/3 libbpf: clear map_info before each bpf_obj_get_info_by_fd

In reply to Maciej Fijalkowski

xsk_lookup_bpf_maps, based on prog_fd, looks whether current prog has a reference to XSKMAP. BPF prog can include insns that work on various BPF maps and this is covered by iterating through map_ids.

The bpf_map_info that is passed to bpf_obj_get_info_by_fd for filling needs to be cleared at each iteration, so that it doesn't contain any outdated fields and that is currently missing in the function of interest.

To fix that, zero-init map_info via memset before each bpf_obj_get_info_by_fd call.

Also, since the area of this code is touched, in general strcmp is considered harmful, so let's convert it to strncmp and provide the size of the array name for current map_info.

While at it, do s/continue/break/ once we have found the xsks_map to terminate the search.

Fixes 5750902a6e9b ("libbpf: proper XSKMAP cleanup")
---
 tools/lib/bpf/xsk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/lib/bpf/xsk.c +3 -2
index ffbb588724d8..526fc35c0b23 100644
@@ -610,15 +610,16 @@ static int xsk_lookup_bpf_maps(struct xsk_socket *xsk)
 		if (fd < 0)
 			continue;
 
+		memset(&map_info, 0, map_len);
 		err = bpf_obj_get_info_by_fd(fd, &map_info, &map_len);
 		if (err) {
 			close(fd);
 			continue;
 		}
 
-		if (!strcmp(map_info.name, "xsks_map")) {
+		if (!strncmp(map_info.name, "xsks_map", sizeof(map_info.name))) {
 			ctx->xsks_map_fd = fd;
-			continue;
+			break;
 		}
 
 		close(fd);
Signature · 1 line
2.20.1
Acked-by on the v2 series
#4 lore raw
In reply to Maciej Fijalkowski
Quoted 9 lines · Maciej Fijalkowski

Hi,

This time three no-brainers, one is a fix that I sent among with bpf_link for AF_XDP set where John suggested that it should land in bpf tree.

Other is the missing munmap on xdpsock and some ancient function declaration removal.

Thanks Maciej!

For the series:

Quoted 17 lines

Thanks!
Maciej

v2:
- collect Bjorn's Acks
- change strlen to sizeof in patch 3

Maciej Fijalkowski (3):
xsk: remove dangling function declaration from header file
samples: bpf: add missing munmap in xdpsock
libbpf: clear map_info before each bpf_obj_get_info_by_fd

  include/linux/netdevice.h  | 2 --
  samples/bpf/xdpsock_user.c | 2 ++
  tools/lib/bpf/xsk.c        | 5 +++--
  3 files changed, 5 insertions(+), 4 deletions(-)
#5 lore raw
In reply to Maciej Fijalkowski
This series was applied to bpf/bpf.git (refs/heads/master):

Hello:

This series was applied to bpf/bpf.git (refs/heads/master):

Quoted 10 lines · On Wed, 3 Mar 2021 19:56:33 +0100 you wrote:

Hi,

This time three no-brainers, one is a fix that I sent among with bpf_link for AF_XDP set where John suggested that it should land in bpf tree.

Other is the missing munmap on xdpsock and some ancient function declaration removal.

[...]

Here is the summary with links:
- [bpf,v2,1/3] xsk: remove dangling function declaration from header file

    https://git.kernel.org/bpf/bpf/c/c95c34f01bbd
  - [bpf,v2,2/3] samples: bpf: add missing munmap in xdpsock
    https://git.kernel.org/bpf/bpf/c/6bc669988101
  - [bpf,v2,3/3] libbpf: clear map_info before each bpf_obj_get_info_by_fd
    https://git.kernel.org/bpf/bpf/c/2b2aedabc44e

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html