Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

strparser: pad sk_skb_cb to avoid straddling cachelines

sk_skb_cb lives within skb->cb[]. skb->cb[] straddles
2 cache lines, each containing 24B of data.
The first cache line does not contain much interesting
information for users of strparser, so pad things a little.
Previously strp_msg->full_len would live in the first cache
line and strp_msg->offset in the second.

We need to reorder the 8 byte temp_reg with struct tls_msg
to prevent a 4B hole which would push the struct over 48B.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+11 -4
+8 -4
include/net/strparser.h
··· 65 65 struct sk_skb_cb { 66 66 #define SK_SKB_CB_PRIV_LEN 20 67 67 unsigned char data[SK_SKB_CB_PRIV_LEN]; 68 + /* align strp on cache line boundary within skb->cb[] */ 69 + unsigned char pad[4]; 68 70 struct _strp_msg strp; 69 - /* temp_reg is a temporary register used for bpf_convert_data_end_access 70 - * when dst_reg == src_reg. 71 - */ 72 - u64 temp_reg; 71 + 72 + /* strp users' data follows */ 73 73 struct tls_msg { 74 74 u8 control; 75 75 u8 decrypted; 76 76 } tls; 77 + /* temp_reg is a temporary register used for bpf_convert_data_end_access 78 + * when dst_reg == src_reg. 79 + */ 80 + u64 temp_reg; 77 81 }; 78 82 79 83 static inline struct strp_msg *strp_msg(struct sk_buff *skb)
+3
net/strparser/strparser.c
··· 533 533 534 534 static int __init strp_dev_init(void) 535 535 { 536 + BUILD_BUG_ON(sizeof(struct sk_skb_cb) > 537 + sizeof_field(struct sk_buff, cb)); 538 + 536 539 strp_wq = create_singlethread_workqueue("kstrp"); 537 540 if (unlikely(!strp_wq)) 538 541 return -ENOMEM;