AF_XDP small fixes
Subsystems (5)
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
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
PATCH 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
--- include/linux/netdevice.h | 2 -- 1 file changed, 2 deletions(-)
include/linux/netdevice.h +0 -2
@@ -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
Re: [PATCH bpf 1/3] xsk: remove dangling function declaration from header file
Quoted 5 lines · Maciej Fijalkowski
xdp_umem_query()is dead for a long time, drop the declaration frominclude/linux/netdevice.hFixes c9b47cc1fabc ("xsk: fix bug when trying to use both copy and zero-copy on one queue id")Signed-off-by Maciej Fijalkowski <[email protected]>
Quoted 18 lines
--- include/linux/netdevice.h | 2 -- 1 file changed, 2 deletions(-)include/linux/netdevice.h +0
-2@@ -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);
PATCH 2/3 samples: bpf: add missing munmap in xdpsock
In reply to Maciej FijalkowskiWe mmap the umem region, but we never munmap it.
Add the missing call at the end of the cleanup.
--- samples/bpf/xdpsock_user.c | 2 ++ 1 file changed, 2 insertions(+)
samples/bpf/xdpsock_user.c +2 -0
@@ -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
Re: [PATCH bpf 2/3] samples: bpf: add missing munmap in xdpsock
Quoted 5 lines · 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")Signed-off-by Maciej Fijalkowski <[email protected]>
Quoted 17 lines
--- samples/bpf/xdpsock_user.c | 2 ++ 1 file changed, 2 insertions(+)samples/bpf/xdpsock_user.c +2
-0@@ -1699,5 +1699,7 @@ int main(int argc, char **argv)xdpsock_cleanup (); +munmap (bufs,NUM_FRAMES * opt_xsk_frame_size); +return 0 ; }
PATCH 3/3 libbpf: clear map_info before each bpf_obj_get_info_by_fd
In reply to Maciej Fijalkowskixsk_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 length of the array name from current map_info.
Last but not least, do s/continue/break/ once we have found the xsks_map to terminate the search.
--- tools/lib/bpf/xsk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/lib/bpf/xsk.c +3 -2
@@ -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" ,strlen (map_info.name))) { ctx->xsks_map_fd = fd; -continue ; +break ; }close (fd);
Signature · 1 line
2.20.1
Re: [PATCH bpf 3/3] libbpf: clear map_info before each bpf_obj_get_info_by_fd
Quoted 32 lines · Maciej Fijalkowski
xsk_lookup_bpf_maps, based onprog_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 throughmap_ids.The
bpf_map_infothat is passed tobpf_obj_get_info_by_fdfor 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_infovia memset before eachbpf_obj_get_info_by_fdcall.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 length of the array name from current
map_info.Last but not least, do s/continue/break/ once we have found the
xsks_mapto terminate the search.Fixes 5750902a6e9b ("libbpf: proper XSKMAP cleanup")Signed-off-by Maciej Fijalkowski <[email protected]>--- tools/lib/bpf/xsk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)tools/lib/bpf/xsk.c +0
-0@@ -610,15 +610,16 @@ static int xsk_lookup_bpf_maps(struct xsk_socket *xsk)if (fd <0 )continue ;
tools/lib/bpf/xsk.c static int xsk_lookup_bpf_maps(struct xsk_socket *xsk) · line 620
Quoted 10 lines
tools/lib/bpf/xsk.c +2
-1+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" ,strlen (map_info.name))) {
This should be sizeof(map_info.name) and not strlen, otherwise it's kind of useless! :-P
Björn
Quoted 7 lines
tools/lib/bpf/xsk.c +1
-1ctx->xsks_map_fd = fd; -continue ; +break ; }close (fd);