Skip to content

Commit 8845b46

Browse files
jkoong-fbAlexei Starovoitov
authored andcommitted
bpf: Add alignment padding for "map_extra" + consolidate holes
This patch makes 2 changes regarding alignment padding for the "map_extra" field. 1) In the kernel header, "map_extra" and "btf_value_type_id" are rearranged to consolidate the hole. Before: struct bpf_map { ... u32 max_entries; /* 36 4 */ u32 map_flags; /* 40 4 */ /* XXX 4 bytes hole, try to pack */ u64 map_extra; /* 48 8 */ int spin_lock_off; /* 56 4 */ int timer_off; /* 60 4 */ /* --- cacheline 1 boundary (64 bytes) --- */ u32 id; /* 64 4 */ int numa_node; /* 68 4 */ ... bool frozen; /* 117 1 */ /* XXX 10 bytes hole, try to pack */ /* --- cacheline 2 boundary (128 bytes) --- */ ... struct work_struct work; /* 144 72 */ /* --- cacheline 3 boundary (192 bytes) was 24 bytes ago --- */ struct mutex freeze_mutex; /* 216 144 */ /* --- cacheline 5 boundary (320 bytes) was 40 bytes ago --- */ u64 writecnt; /* 360 8 */ /* size: 384, cachelines: 6, members: 26 */ /* sum members: 354, holes: 2, sum holes: 14 */ /* padding: 16 */ /* forced alignments: 2, forced holes: 1, sum forced holes: 10 */ } __attribute__((__aligned__(64))); After: struct bpf_map { ... u32 max_entries; /* 36 4 */ u64 map_extra; /* 40 8 */ u32 map_flags; /* 48 4 */ int spin_lock_off; /* 52 4 */ int timer_off; /* 56 4 */ u32 id; /* 60 4 */ /* --- cacheline 1 boundary (64 bytes) --- */ int numa_node; /* 64 4 */ ... bool frozen /* 113 1 */ /* XXX 14 bytes hole, try to pack */ /* --- cacheline 2 boundary (128 bytes) --- */ ... struct work_struct work; /* 144 72 */ /* --- cacheline 3 boundary (192 bytes) was 24 bytes ago --- */ struct mutex freeze_mutex; /* 216 144 */ /* --- cacheline 5 boundary (320 bytes) was 40 bytes ago --- */ u64 writecnt; /* 360 8 */ /* size: 384, cachelines: 6, members: 26 */ /* sum members: 354, holes: 1, sum holes: 14 */ /* padding: 16 */ /* forced alignments: 2, forced holes: 1, sum forced holes: 14 */ } __attribute__((__aligned__(64))); 2) Add alignment padding to the bpf_map_info struct More details can be found in commit 36f9814 ("bpf: fix uapi hole for 32 bit compat applications") Signed-off-by: Joanne Koong <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 6fdc348 commit 8845b46

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

include/linux/bpf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,23 @@ struct bpf_map {
168168
u32 key_size;
169169
u32 value_size;
170170
u32 max_entries;
171-
u32 map_flags;
172171
u64 map_extra; /* any per-map-type extra fields */
172+
u32 map_flags;
173173
int spin_lock_off; /* >=0 valid offset, <0 error */
174174
int timer_off; /* >=0 valid offset, <0 error */
175175
u32 id;
176176
int numa_node;
177177
u32 btf_key_type_id;
178178
u32 btf_value_type_id;
179+
u32 btf_vmlinux_value_type_id;
179180
struct btf *btf;
180181
#ifdef CONFIG_MEMCG_KMEM
181182
struct mem_cgroup *memcg;
182183
#endif
183184
char name[BPF_OBJ_NAME_LEN];
184-
u32 btf_vmlinux_value_type_id;
185185
bool bypass_spec_v1;
186186
bool frozen; /* write-once; write-protected by freeze_mutex */
187-
/* 22 bytes hole */
187+
/* 14 bytes hole */
188188

189189
/* The 3rd and 4th cacheline with misc members to avoid false sharing
190190
* particularly with refcounting.

include/uapi/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5662,6 +5662,7 @@ struct bpf_map_info {
56625662
__u32 btf_id;
56635663
__u32 btf_key_type_id;
56645664
__u32 btf_value_type_id;
5665+
__u32 :32; /* alignment pad */
56655666
__u64 map_extra;
56665667
} __attribute__((aligned(8)));
56675668

tools/include/uapi/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5662,6 +5662,7 @@ struct bpf_map_info {
56625662
__u32 btf_id;
56635663
__u32 btf_key_type_id;
56645664
__u32 btf_value_type_id;
5665+
__u32 :32; /* alignment pad */
56655666
__u64 map_extra;
56665667
} __attribute__((aligned(8)));
56675668

0 commit comments

Comments
 (0)