Thread (8 messages) 8 messages, 2 authors, 2021-10-29

Re: [PATCH bpf-next 2/3] bpf: Add alignment padding for "map_extra" + consolidate holes

From: Yonghong Song <hidden>
Date: 2021-10-29 21:30:25


On 10/29/21 10:01 AM, Joanne Koong wrote:
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 36f9814a494a ("bpf: fix uapi hole
for 32 bit compat applications")

Signed-off-by: Joanne Koong <redacted>
Acked-by: Yonghong Song <redacted>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help