From: Jakub Kicinski Date: Fri, 8 Jul 2022 01:03:09 +0000 (-0700) Subject: strparser: pad sk_skb_cb to avoid straddling cachelines X-Git-Tag: v6.1-rc5~731^2~172^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2d91ecace6614cf6254001566292b808d7f70a91;p=platform%2Fkernel%2Flinux-starfive.git 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 --- diff --git a/include/net/strparser.h b/include/net/strparser.h index a191486..88900b0 100644 --- a/include/net/strparser.h +++ b/include/net/strparser.h @@ -65,15 +65,19 @@ struct _strp_msg { struct sk_skb_cb { #define SK_SKB_CB_PRIV_LEN 20 unsigned char data[SK_SKB_CB_PRIV_LEN]; + /* align strp on cache line boundary within skb->cb[] */ + unsigned char pad[4]; struct _strp_msg strp; - /* temp_reg is a temporary register used for bpf_convert_data_end_access - * when dst_reg == src_reg. - */ - u64 temp_reg; + + /* strp users' data follows */ struct tls_msg { u8 control; u8 decrypted; } tls; + /* temp_reg is a temporary register used for bpf_convert_data_end_access + * when dst_reg == src_reg. + */ + u64 temp_reg; }; static inline struct strp_msg *strp_msg(struct sk_buff *skb) diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c index 1a72c67a..8299ceb 100644 --- a/net/strparser/strparser.c +++ b/net/strparser/strparser.c @@ -533,6 +533,9 @@ EXPORT_SYMBOL_GPL(strp_check_rcv); static int __init strp_dev_init(void) { + BUILD_BUG_ON(sizeof(struct sk_skb_cb) > + sizeof_field(struct sk_buff, cb)); + strp_wq = create_singlethread_workqueue("kstrp"); if (unlikely(!strp_wq)) return -ENOMEM;