bpf: Introduce global percpu data#12395
Conversation
|
Upstream branch: 50dff00 |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
|
Forwarding comment 4650565744 via email |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
|
Forwarding comment 4650789834 via email |
c7e2962 to
68b80e2
Compare
|
Upstream branch: b9452b5 |
10db936 to
6ee896a
Compare
68b80e2 to
9978c13
Compare
|
Upstream branch: dd0f968 |
6ee896a to
4df17d8
Compare
9978c13 to
e25ce50
Compare
|
Upstream branch: f1a660b |
4df17d8 to
e11d62b
Compare
e25ce50 to
a572b20
Compare
|
Upstream branch: 68f4e48 |
e11d62b to
ea21b6c
Compare
a572b20 to
3a26044
Compare
|
Upstream branch: c15261b |
ea21b6c to
5ba1021
Compare
3a26044 to
818f7b1
Compare
|
Upstream branch: 140fa23 |
5ba1021 to
13ef75b
Compare
818f7b1 to
d9ed865
Compare
|
Upstream branch: 2e8ad1f |
13ef75b to
5a7b360
Compare
d9ed865 to
1b36123
Compare
There are many adjacent blank lines in the verifier that have accumulated over time. Drop them for cleanup. No functional changes intended. Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Introduce global percpu data, inspired by the commit 6316f78 ("Merge branch 'support-global-data'"). It enables the definition of global percpu variables in BPF, similar to the include/linux/percpu-defs.h::DEFINE_PER_CPU() macro. For example, in BPF, it is able to define a global percpu variable like: int data SEC(".percpu"); With this patch, tools like retsnoop [1] and bpfsnoop [2] can simplify their BPF code for handling LBRs. The code can be updated from static struct perf_branch_entry lbrs[1][MAX_LBR_ENTRIES] SEC(".data.lbrs"); to static struct perf_branch_entry lbrs[MAX_LBR_ENTRIES] SEC(".percpu.lbrs"); This eliminates the need to retrieve the CPU ID using the bpf_get_smp_processor_id() helper. Additionally, by reusing global percpu data map, sharing information between tail callers and callees or freplace callers and callees becomes simpler compared to reusing percpu_array maps. Links: [1] https://github.com/anakryiko/retsnoop [2] https://github.com/bpfsnoop/bpfsnoop Assisted-by: Codex:gpt-5.5-xhigh Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
libbpf needs a reliable way to distinguish kernels that can support global percpu data from those that cannot. Add a dedicated feature probe, so libbpf can make capability decisions early and fail predictably when global percpu data is unavailable. Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Add support for global percpu data in libbpf by adding a new ".percpu" section, similar to ".data". It enables efficient handling of percpu global variables in bpf programs. When generating loader for lightweight skeleton, update the percpu_array map used for global percpu data using BPF_F_ALL_CPUS, in order to update values across all CPUs using one value slot. Unlike global data, the mmaped data for global percpu data will be marked as read-only after populating the percpu_array map. Thereafter, users can read those initialized percpu data after loading prog. If they want to update the percpu data after loading prog, they have to update the percpu_array map using key=0 instead. Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Enhance bpftool to generate skeletons that properly handle global percpu
variables. The generated skeleton now includes a dedicated structure for
percpu data, allowing users to initialize and access percpu variables more
efficiently.
For global percpu variables, the skeleton now includes a nested
structure, e.g.:
struct test_global_percpu_data {
struct bpf_object_skeleton *skeleton;
struct bpf_object *obj;
struct {
struct bpf_map *percpu;
} maps;
// ...
struct test_global_percpu_data__percpu {
int data;
char run;
struct {
char set;
int i;
int nums[7];
} struct_data;
int nums[7];
} *percpu;
// ...
};
* The "struct test_global_percpu_data__percpu *percpu" points to
initialized data, which is actually "maps.percpu->mmaped".
* Before loading the skeleton, updating the
"struct test_global_percpu_data__percpu *percpu" modifies the initial
value of the corresponding global percpu variables.
* After loading the skeleton, "maps.percpu->mmaped" has been marked as
read-only in libbpf. If users want to update the global percpu
variables, they have to update the "maps.percpu" map instead.
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
|
Upstream branch: 30dee2c |
If the arch, like s390x, does not support percpu insn, these cases won't test global percpu data by checking FEAT_PERCPU_DATA support. The following APIs have been tested for global percpu data: 1. bpf_map__set_initial_value() 2. bpf_map__initial_value() 3. generated percpu struct pointer pointing to internal map's mmaped data 4. bpf_map__lookup_elem() for global percpu data map At the same time, the case is also tested with 'bpftool gen skeleton -L'. Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Add two tests to verify the verifier log "R%d points to percpu_array map which cannot be used as const string\n". Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Add a test to verify global percpu data related xlated insns: 1. ld_imm64: compare xlated one with the one in ELF object file. 2. mov64_percpu_reg: it is added by verifier. Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Add a test to verify that it is OK to iter the percpu_array map used for global percpu data. Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
5a7b360 to
ae4f3d7
Compare
Pull request for series with
subject: bpf: Introduce global percpu data
version: 5
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1107932