bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf v2 0/3] AF_XDP small fixes
@ 2021-03-03 18:56 Maciej Fijalkowski
  2021-03-03 18:56 ` [PATCH bpf v2 1/3] xsk: remove dangling function declaration from header file Maciej Fijalkowski
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Maciej Fijalkowski @ 2021-03-03 18:56 UTC (permalink / raw)
  To: daniel, ast, bpf
  Cc: bjorn.topel, magnus.karlsson, john.fastabend, 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

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(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH bpf v2 1/3] xsk: remove dangling function declaration from header file
  2021-03-03 18:56 [PATCH bpf v2 0/3] AF_XDP small fixes Maciej Fijalkowski
@ 2021-03-03 18:56 ` Maciej Fijalkowski
  2021-03-03 18:56 ` [PATCH bpf v2 2/3] samples: bpf: add missing munmap in xdpsock Maciej Fijalkowski
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Maciej Fijalkowski @ 2021-03-03 18:56 UTC (permalink / raw)
  To: daniel, ast, bpf
  Cc: bjorn.topel, magnus.karlsson, john.fastabend, Maciej Fijalkowski

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")
Acked-by: Björn Töpel <bjorn.topel@intel.com>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
 include/linux/netdevice.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 6cef47b76cc6..226303976310 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -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);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH bpf v2 2/3] samples: bpf: add missing munmap in xdpsock
  2021-03-03 18:56 [PATCH bpf v2 0/3] AF_XDP small fixes Maciej Fijalkowski
  2021-03-03 18:56 ` [PATCH bpf v2 1/3] xsk: remove dangling function declaration from header file Maciej Fijalkowski
@ 2021-03-03 18:56 ` Maciej Fijalkowski
  2021-03-03 18:56 ` [PATCH bpf v2 3/3] libbpf: clear map_info before each bpf_obj_get_info_by_fd Maciej Fijalkowski
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Maciej Fijalkowski @ 2021-03-03 18:56 UTC (permalink / raw)
  To: daniel, ast, bpf
  Cc: bjorn.topel, magnus.karlsson, john.fastabend, 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")
Acked-by: Björn Töpel <bjorn.topel@intel.com>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
 samples/bpf/xdpsock_user.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index db0cb73513a5..1e2a1105d0e6 100644
--- a/samples/bpf/xdpsock_user.c
+++ b/samples/bpf/xdpsock_user.c
@@ -1699,5 +1699,7 @@ int main(int argc, char **argv)
 
 	xdpsock_cleanup();
 
+	munmap(bufs, NUM_FRAMES * opt_xsk_frame_size);
+
 	return 0;
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH bpf v2 3/3] libbpf: clear map_info before each bpf_obj_get_info_by_fd
  2021-03-03 18:56 [PATCH bpf v2 0/3] AF_XDP small fixes Maciej Fijalkowski
  2021-03-03 18:56 ` [PATCH bpf v2 1/3] xsk: remove dangling function declaration from header file Maciej Fijalkowski
  2021-03-03 18:56 ` [PATCH bpf v2 2/3] samples: bpf: add missing munmap in xdpsock Maciej Fijalkowski
@ 2021-03-03 18:56 ` Maciej Fijalkowski
  2021-03-03 19:19 ` [PATCH bpf v2 0/3] AF_XDP small fixes Björn Töpel
  2021-03-04 15:00 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Maciej Fijalkowski @ 2021-03-03 18:56 UTC (permalink / raw)
  To: daniel, ast, bpf
  Cc: bjorn.topel, magnus.karlsson, john.fastabend, 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")
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
 tools/lib/bpf/xsk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index ffbb588724d8..526fc35c0b23 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -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);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf v2 0/3] AF_XDP small fixes
  2021-03-03 18:56 [PATCH bpf v2 0/3] AF_XDP small fixes Maciej Fijalkowski
                   ` (2 preceding siblings ...)
  2021-03-03 18:56 ` [PATCH bpf v2 3/3] libbpf: clear map_info before each bpf_obj_get_info_by_fd Maciej Fijalkowski
@ 2021-03-03 19:19 ` Björn Töpel
  2021-03-04 15:00 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Björn Töpel @ 2021-03-03 19:19 UTC (permalink / raw)
  To: Maciej Fijalkowski, daniel, ast, bpf; +Cc: magnus.karlsson, john.fastabend

On 2021-03-03 19:56, Maciej Fijalkowski 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.
>

Thanks Maciej!

For the series:

Acked-by: Björn Töpel <bjorn.topel@intel.com>


> 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(-)
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf v2 0/3] AF_XDP small fixes
  2021-03-03 18:56 [PATCH bpf v2 0/3] AF_XDP small fixes Maciej Fijalkowski
                   ` (3 preceding siblings ...)
  2021-03-03 19:19 ` [PATCH bpf v2 0/3] AF_XDP small fixes Björn Töpel
@ 2021-03-04 15:00 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-03-04 15:00 UTC (permalink / raw)
  To: Maciej Fijalkowski
  Cc: daniel, ast, bpf, bjorn.topel, magnus.karlsson, john.fastabend

Hello:

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

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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-04 15:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03 18:56 [PATCH bpf v2 0/3] AF_XDP small fixes Maciej Fijalkowski
2021-03-03 18:56 ` [PATCH bpf v2 1/3] xsk: remove dangling function declaration from header file Maciej Fijalkowski
2021-03-03 18:56 ` [PATCH bpf v2 2/3] samples: bpf: add missing munmap in xdpsock Maciej Fijalkowski
2021-03-03 18:56 ` [PATCH bpf v2 3/3] libbpf: clear map_info before each bpf_obj_get_info_by_fd Maciej Fijalkowski
2021-03-03 19:19 ` [PATCH bpf v2 0/3] AF_XDP small fixes Björn Töpel
2021-03-04 15:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).