2019-08-15 14:33:26

by Ivan Khoronzhuk

[permalink] [raw]
Subject: [PATCH bpf-next v2 0/3] xdpsock: allow mmap2 usage for 32bits

This patchset contains several improvements for af_xdp socket umem
mappings for 32bit systems. Also, there is one more patch outside of
this series that on linux-next tree and related to mmap2 af_xdp umem
offsets: "mm: mmap: increase sockets maximum memory size pgoff for 32bits"
https://lkml.org/lkml/2019/8/12/549

Based on bpf-next/master

Prev: https://lkml.org/lkml/2019/8/13/437

v2..v1:
- replaced "libbpf: add asm/unistd.h to xsk to get __NR_mmap2" on
"libbpf: use LFS (_FILE_OFFSET_BITS) instead of direct mmap2
syscall"
- use vmap along with page_address to avoid overkill
- define mmap syscall trace5 for mmap if defined

Ivan Khoronzhuk (3):
libbpf: use LFS (_FILE_OFFSET_BITS) instead of direct mmap2 syscall
xdp: xdp_umem: replace kmap on vmap for umem map
samples: bpf: syscal_nrs: use mmap2 if defined

net/xdp/xdp_umem.c | 36 +++++++++++++++++++++++-----
samples/bpf/syscall_nrs.c | 6 +++++
samples/bpf/tracex5_kern.c | 13 ++++++++++
tools/lib/bpf/Makefile | 1 +
tools/lib/bpf/xsk.c | 49 +++++++++++---------------------------
5 files changed, 64 insertions(+), 41 deletions(-)

--
2.17.1


2019-08-15 14:33:36

by Ivan Khoronzhuk

[permalink] [raw]
Subject: [PATCH bpf-next v2 3/3] samples: bpf: syscal_nrs: use mmap2 if defined

For arm32 xdp sockets mmap2 is preferred, so use it if it's defined.
Declaration of __NR_mmap can be skipped and it breaks build.

Signed-off-by: Ivan Khoronzhuk <[email protected]>
---
samples/bpf/syscall_nrs.c | 6 ++++++
samples/bpf/tracex5_kern.c | 13 +++++++++++++
2 files changed, 19 insertions(+)

diff --git a/samples/bpf/syscall_nrs.c b/samples/bpf/syscall_nrs.c
index 516e255cbe8f..88f940052450 100644
--- a/samples/bpf/syscall_nrs.c
+++ b/samples/bpf/syscall_nrs.c
@@ -9,5 +9,11 @@ void syscall_defines(void)
COMMENT("Linux system call numbers.");
SYSNR(__NR_write);
SYSNR(__NR_read);
+#ifdef __NR_mmap2
+ SYSNR(__NR_mmap2);
+#endif
+#ifdef __NR_mmap
SYSNR(__NR_mmap);
+#endif
+
}
diff --git a/samples/bpf/tracex5_kern.c b/samples/bpf/tracex5_kern.c
index f57f4e1ea1ec..35cb0eed3be5 100644
--- a/samples/bpf/tracex5_kern.c
+++ b/samples/bpf/tracex5_kern.c
@@ -68,12 +68,25 @@ PROG(SYS__NR_read)(struct pt_regs *ctx)
return 0;
}

+#ifdef __NR_mmap2
+PROG(SYS__NR_mmap2)(struct pt_regs *ctx)
+{
+ char fmt[] = "mmap2\n";
+
+ bpf_trace_printk(fmt, sizeof(fmt));
+ return 0;
+}
+#endif
+
+#ifdef __NR_mmap
PROG(SYS__NR_mmap)(struct pt_regs *ctx)
{
char fmt[] = "mmap\n";
+
bpf_trace_printk(fmt, sizeof(fmt));
return 0;
}
+#endif

char _license[] SEC("license") = "GPL";
u32 _version SEC("version") = LINUX_VERSION_CODE;
--
2.17.1

2019-08-19 21:19:54

by Jonathan Lemon

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 3/3] samples: bpf: syscal_nrs: use mmap2 if defined



On 15 Aug 2019, at 5:13, Ivan Khoronzhuk wrote:

> For arm32 xdp sockets mmap2 is preferred, so use it if it's defined.
> Declaration of __NR_mmap can be skipped and it breaks build.
>
> Signed-off-by: Ivan Khoronzhuk <[email protected]>

Acked-by: Jonathan Lemon <[email protected]>


> ---
> samples/bpf/syscall_nrs.c | 6 ++++++
> samples/bpf/tracex5_kern.c | 13 +++++++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/samples/bpf/syscall_nrs.c b/samples/bpf/syscall_nrs.c
> index 516e255cbe8f..88f940052450 100644
> --- a/samples/bpf/syscall_nrs.c
> +++ b/samples/bpf/syscall_nrs.c
> @@ -9,5 +9,11 @@ void syscall_defines(void)
> COMMENT("Linux system call numbers.");
> SYSNR(__NR_write);
> SYSNR(__NR_read);
> +#ifdef __NR_mmap2
> + SYSNR(__NR_mmap2);
> +#endif
> +#ifdef __NR_mmap
> SYSNR(__NR_mmap);
> +#endif
> +
> }
> diff --git a/samples/bpf/tracex5_kern.c b/samples/bpf/tracex5_kern.c
> index f57f4e1ea1ec..35cb0eed3be5 100644
> --- a/samples/bpf/tracex5_kern.c
> +++ b/samples/bpf/tracex5_kern.c
> @@ -68,12 +68,25 @@ PROG(SYS__NR_read)(struct pt_regs *ctx)
> return 0;
> }
>
> +#ifdef __NR_mmap2
> +PROG(SYS__NR_mmap2)(struct pt_regs *ctx)
> +{
> + char fmt[] = "mmap2\n";
> +
> + bpf_trace_printk(fmt, sizeof(fmt));
> + return 0;
> +}
> +#endif
> +
> +#ifdef __NR_mmap
> PROG(SYS__NR_mmap)(struct pt_regs *ctx)
> {
> char fmt[] = "mmap\n";
> +
> bpf_trace_printk(fmt, sizeof(fmt));
> return 0;
> }
> +#endif
>
> char _license[] SEC("license") = "GPL";
> u32 _version SEC("version") = LINUX_VERSION_CODE;
> --
> 2.17.1

2019-08-21 12:44:08

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 0/3] xdpsock: allow mmap2 usage for 32bits

On 8/15/19 2:13 PM, Ivan Khoronzhuk wrote:
> This patchset contains several improvements for af_xdp socket umem
> mappings for 32bit systems. Also, there is one more patch outside of
> this series that on linux-next tree and related to mmap2 af_xdp umem
> offsets: "mm: mmap: increase sockets maximum memory size pgoff for 32bits"
> https://lkml.org/lkml/2019/8/12/549
>
> Based on bpf-next/master
>
> Prev: https://lkml.org/lkml/2019/8/13/437
>
> v2..v1:
> - replaced "libbpf: add asm/unistd.h to xsk to get __NR_mmap2" on
> "libbpf: use LFS (_FILE_OFFSET_BITS) instead of direct mmap2
> syscall"
> - use vmap along with page_address to avoid overkill
> - define mmap syscall trace5 for mmap if defined
>
> Ivan Khoronzhuk (3):
> libbpf: use LFS (_FILE_OFFSET_BITS) instead of direct mmap2 syscall
> xdp: xdp_umem: replace kmap on vmap for umem map
> samples: bpf: syscal_nrs: use mmap2 if defined
>
> net/xdp/xdp_umem.c | 36 +++++++++++++++++++++++-----
> samples/bpf/syscall_nrs.c | 6 +++++
> samples/bpf/tracex5_kern.c | 13 ++++++++++
> tools/lib/bpf/Makefile | 1 +
> tools/lib/bpf/xsk.c | 49 +++++++++++---------------------------
> 5 files changed, 64 insertions(+), 41 deletions(-)
>

Applied, and fixed up typo in last one's subject, thanks!