diff mbox series

[v16,bpf-next,09/20] bpf: introduce BPF_F_XDP_MB flag in prog_flags loading the ebpf program

Message ID 0a48666cfb23d1ceef8d529506e7ad2da90079de.1634301224.git.lorenzo@kernel.org (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series mvneta: introduce XDP multi-buffer support | expand

Checks

Context Check Description
netdev/cover_letter success Series has a cover letter
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count fail Series longer than 15 patches (and no cover letter)
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 10 maintainers not CCed: joe@cilium.io andrii@kernel.org hawk@kernel.org songliubraving@fb.com revest@chromium.org yhs@fb.com liuhangbin@gmail.com jackmanb@google.com kafai@fb.com kpsingh@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 11790 this patch: 11790
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch warning CHECK: Prefer using the BIT macro
netdev/build_allmodconfig_warn success Errors and warnings before: 11421 this patch: 11421
netdev/header_inline success No static functions without inline keyword in header files
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary

Commit Message

Lorenzo Bianconi Oct. 15, 2021, 1:08 p.m. UTC
Introduce BPF_F_XDP_MB and the related field in bpf_prog_aux in order to
notify the driver the loaded program support xdp multi-buffer.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 include/linux/bpf.h            | 1 +
 include/uapi/linux/bpf.h       | 5 +++++
 kernel/bpf/syscall.c           | 4 +++-
 tools/include/uapi/linux/bpf.h | 5 +++++
 4 files changed, 14 insertions(+), 1 deletion(-)

Comments

Toke Høiland-Jørgensen Oct. 15, 2021, 1:22 p.m. UTC | #1
Lorenzo Bianconi <lorenzo@kernel.org> writes:

> Introduce BPF_F_XDP_MB and the related field in bpf_prog_aux in order to
> notify the driver the loaded program support xdp multi-buffer.

We should also add some restrictions in the BPF core. In particular,
tail call, cpumap and devmap maps should not be able to mix multi-buf
and non-multibuf programs.

-Toke
Lorenzo Bianconi Oct. 15, 2021, 1:29 p.m. UTC | #2
> Lorenzo Bianconi <lorenzo@kernel.org> writes:
> 
> > Introduce BPF_F_XDP_MB and the related field in bpf_prog_aux in order to
> > notify the driver the loaded program support xdp multi-buffer.
> 
> We should also add some restrictions in the BPF core. In particular,
> tail call, cpumap and devmap maps should not be able to mix multi-buf
> and non-multibuf programs.

ack. How can we detect if a cpumap or a devmap is running in XDP multi-buff
mode in order to reject loading the legacy XDP program?
Should we just discard the XDP multi-buff in this case?

Lorenzo

> 
> -Toke
>
Toke Høiland-Jørgensen Oct. 15, 2021, 4:03 p.m. UTC | #3
Lorenzo Bianconi <lorenzo@kernel.org> writes:

>> Lorenzo Bianconi <lorenzo@kernel.org> writes:
>> 
>> > Introduce BPF_F_XDP_MB and the related field in bpf_prog_aux in order to
>> > notify the driver the loaded program support xdp multi-buffer.
>> 
>> We should also add some restrictions in the BPF core. In particular,
>> tail call, cpumap and devmap maps should not be able to mix multi-buf
>> and non-multibuf programs.
>
> ack. How can we detect if a cpumap or a devmap is running in XDP multi-buff
> mode in order to reject loading the legacy XDP program?

I was hoping we could copy the same mechanism that tail call maps to
ensure that callers and callees are the same type. And amend that to
also consider the xdp_mb flag while we're at it :)

> Should we just discard the XDP multi-buff in this case?

If I'm right in the above, we won't have to because the verifier can
ensure that the program types match...

-Toke
diff mbox series

Patch

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index d604c8251d88..1d199501031e 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -868,6 +868,7 @@  struct bpf_prog_aux {
 	bool func_proto_unreliable;
 	bool sleepable;
 	bool tail_call_reachable;
+	bool xdp_mb;
 	struct hlist_node tramp_hlist;
 	/* BTF_KIND_FUNC_PROTO for valid attach_btf_id */
 	const struct btf_type *attach_func_proto;
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 6fc59d61937a..87c10a90c243 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1110,6 +1110,11 @@  enum bpf_link_type {
  */
 #define BPF_F_SLEEPABLE		(1U << 4)
 
+/* If BPF_F_XDP_MB is used in BPF_PROG_LOAD command, the loaded program
+ * fully support xdp multi-buffer
+ */
+#define BPF_F_XDP_MB		(1U << 5)
+
 /* When BPF ldimm64's insn[0].src_reg != 0 then this can have
  * the following extensions:
  *
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 4e50c0bfdb7d..48e4eda2abd5 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2174,7 +2174,8 @@  static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr)
 				 BPF_F_ANY_ALIGNMENT |
 				 BPF_F_TEST_STATE_FREQ |
 				 BPF_F_SLEEPABLE |
-				 BPF_F_TEST_RND_HI32))
+				 BPF_F_TEST_RND_HI32 |
+				 BPF_F_XDP_MB))
 		return -EINVAL;
 
 	if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) &&
@@ -2260,6 +2261,7 @@  static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr)
 	prog->aux->dst_prog = dst_prog;
 	prog->aux->offload_requested = !!attr->prog_ifindex;
 	prog->aux->sleepable = attr->prog_flags & BPF_F_SLEEPABLE;
+	prog->aux->xdp_mb = attr->prog_flags & BPF_F_XDP_MB;
 
 	err = security_bpf_prog_alloc(prog->aux);
 	if (err)
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 6fc59d61937a..87c10a90c243 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1110,6 +1110,11 @@  enum bpf_link_type {
  */
 #define BPF_F_SLEEPABLE		(1U << 4)
 
+/* If BPF_F_XDP_MB is used in BPF_PROG_LOAD command, the loaded program
+ * fully support xdp multi-buffer
+ */
+#define BPF_F_XDP_MB		(1U << 5)
+
 /* When BPF ldimm64's insn[0].src_reg != 0 then this can have
  * the following extensions:
  *