BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] Ignore additional fields in the struct_ops maps in an updated version.
@ 2024-03-12 18:32 Kui-Feng Lee
  2024-03-12 18:32 ` [PATCH bpf-next 1/2] libbpf: Skip zeroed or null fields if not found in the kernel type Kui-Feng Lee
  2024-03-12 18:32 ` [PATCH bpf-next 2/2] selftests/bpf: Ensure libbpf skip all-zeros fields of struct_ops maps Kui-Feng Lee
  0 siblings, 2 replies; 8+ messages in thread
From: Kui-Feng Lee @ 2024-03-12 18:32 UTC (permalink / raw)
  To: bpf, ast, martin.lau, song, kernel-team, andrii
  Cc: sinquersw, kuifeng, Kui-Feng Lee

According to an offline discussion, it would be beneficial to
implement a backward-compatible method for struct_ops types with
additional fields that are not present in older kernels.

This patchset accepts additional fields of a struct_ops map with all
zero values even if these fields are not in the corresponding type in
the kernel. This provides a way to be backward compatible. User space
programs can use the same map on a machine running an old kernel by
clearing fields that do not exist in the kernel.

For example, in a test case, it adds an additional field "zeroed" that
doesn't exist in struct bpf_testmod_ops of the kernel.

    struct bpf_testmod_ops___zeroed {
    	int (*test_1)(void);
    	void (*test_2)(int a, int b);
    	int (*test_maybe_null)(int dummy, struct task_struct *task);
    	int zeroed;
    };
    
    SEC(".struct_ops.link")
    struct bpf_testmod_ops___zeroed testmod_zeroed = {
    	.test_1 = (void *)test_1,
    	.test_2 = (void *)test_2_v2,
    };

Here, it doesn't assign a value to "zeroed" of testmod_zeroed, and by
default the value of this field will be zero. So, the map will be
accepted by libbpf, but libbpf will skip the "zeroed" field. However,
if the "zeroed" field is assigned to any value other than "0", libbpf
will reject to load this map.

Kui-Feng Lee (2):
  libbpf: Skip zeroed or null fields if not found in the kernel type.
  selftests/bpf: Ensure libbpf skip all-zeros fields of struct_ops maps.

 tools/lib/bpf/libbpf.c                        | 30 ++++++++++++----
 .../bpf/prog_tests/test_struct_ops_module.c   | 35 +++++++++++++++++++
 .../selftests/bpf/progs/struct_ops_module.c   | 13 +++++++
 3 files changed, 71 insertions(+), 7 deletions(-)

-- 
2.34.1


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

end of thread, other threads:[~2024-03-13 15:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-12 18:32 [PATCH bpf-next 0/2] Ignore additional fields in the struct_ops maps in an updated version Kui-Feng Lee
2024-03-12 18:32 ` [PATCH bpf-next 1/2] libbpf: Skip zeroed or null fields if not found in the kernel type Kui-Feng Lee
2024-03-12 23:01   ` Andrii Nakryiko
2024-03-13  0:22     ` Kui-Feng Lee
2024-03-12 18:32 ` [PATCH bpf-next 2/2] selftests/bpf: Ensure libbpf skip all-zeros fields of struct_ops maps Kui-Feng Lee
2024-03-12 23:10   ` Andrii Nakryiko
2024-03-13  0:56     ` Kui-Feng Lee
2024-03-13 15:52       ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox