All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2] libbpf: fix crash in XDP socket part with new larger BPF_LOG_BUF_SIZE
@ 2019-04-10  6:54 Magnus Karlsson
  2019-04-10  7:58 ` Daniel Borkmann
  2019-04-10 17:29 ` Y Song
  0 siblings, 2 replies; 3+ messages in thread
From: Magnus Karlsson @ 2019-04-10  6:54 UTC (permalink / raw)
  To: magnus.karlsson, bjorn.topel, ast, daniel, netdev, bpf

In commit da11b417583e ("libbpf: teach libbpf about log_level bit 2"),
the BPF_LOG_BUF_SIZE was increased to 16M. The XDP socket part of
libbpf allocated the log_buf on the stack, but for the new 16M buffer
size this is not going to work. Change the code so it uses a 16K buffer
instead.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
v2: simplified code as suggested by Daniel Borkmann

 tools/lib/bpf/xsk.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index 8d0078b..557ef8d 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -259,7 +259,8 @@ int xsk_umem__create(struct xsk_umem **umem_ptr, void *umem_area, __u64 size,

 static int xsk_load_xdp_prog(struct xsk_socket *xsk)
 {
-	char bpf_log_buf[BPF_LOG_BUF_SIZE];
+	static const int log_buf_size = 16 * 1024;
+	char log_buf[log_buf_size];
 	int err, prog_fd;

 	/* This is the C-program:
@@ -308,10 +309,10 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
 	size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);

 	prog_fd = bpf_load_program(BPF_PROG_TYPE_XDP, prog, insns_cnt,
-				   "LGPL-2.1 or BSD-2-Clause", 0, bpf_log_buf,
-				   BPF_LOG_BUF_SIZE);
+				   "LGPL-2.1 or BSD-2-Clause", 0, log_buf,
+				   log_buf_size);
 	if (prog_fd < 0) {
-		pr_warning("BPF log buffer:\n%s", bpf_log_buf);
+		pr_warning("BPF log buffer:\n%s", log_buf);
 		return prog_fd;
 	}

--
2.7.4

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

* Re: [PATCH bpf-next v2] libbpf: fix crash in XDP socket part with new larger BPF_LOG_BUF_SIZE
  2019-04-10  6:54 [PATCH bpf-next v2] libbpf: fix crash in XDP socket part with new larger BPF_LOG_BUF_SIZE Magnus Karlsson
@ 2019-04-10  7:58 ` Daniel Borkmann
  2019-04-10 17:29 ` Y Song
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2019-04-10  7:58 UTC (permalink / raw)
  To: Magnus Karlsson, bjorn.topel, ast, netdev, bpf

On 04/10/2019 08:54 AM, Magnus Karlsson wrote:
> In commit da11b417583e ("libbpf: teach libbpf about log_level bit 2"),
> the BPF_LOG_BUF_SIZE was increased to 16M. The XDP socket part of
> libbpf allocated the log_buf on the stack, but for the new 16M buffer
> size this is not going to work. Change the code so it uses a 16K buffer
> instead.
> 
> Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> ---
> v2: simplified code as suggested by Daniel Borkmann

Applied, thanks.

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

* Re: [PATCH bpf-next v2] libbpf: fix crash in XDP socket part with new larger BPF_LOG_BUF_SIZE
  2019-04-10  6:54 [PATCH bpf-next v2] libbpf: fix crash in XDP socket part with new larger BPF_LOG_BUF_SIZE Magnus Karlsson
  2019-04-10  7:58 ` Daniel Borkmann
@ 2019-04-10 17:29 ` Y Song
  1 sibling, 0 replies; 3+ messages in thread
From: Y Song @ 2019-04-10 17:29 UTC (permalink / raw)
  To: Magnus Karlsson
  Cc: Björn Töpel, Alexei Starovoitov, Daniel Borkmann, netdev, bpf

On Tue, Apr 9, 2019 at 11:55 PM Magnus Karlsson
<magnus.karlsson@intel.com> wrote:
>
> In commit da11b417583e ("libbpf: teach libbpf about log_level bit 2"),
> the BPF_LOG_BUF_SIZE was increased to 16M. The XDP socket part of
> libbpf allocated the log_buf on the stack, but for the new 16M buffer
> size this is not going to work. Change the code so it uses a 16K buffer
> instead.
>
> Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>

Acked-by: Yonghong Song <yhs@fb.com>

> ---
> v2: simplified code as suggested by Daniel Borkmann
>
>  tools/lib/bpf/xsk.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

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

end of thread, other threads:[~2019-04-10 17:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-10  6:54 [PATCH bpf-next v2] libbpf: fix crash in XDP socket part with new larger BPF_LOG_BUF_SIZE Magnus Karlsson
2019-04-10  7:58 ` Daniel Borkmann
2019-04-10 17:29 ` Y Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.