Skip to content

Commit 2d91eca

Browse files
committed
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 <[email protected]>
1 parent 67d7ebd commit 2d91eca

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

include/net/strparser.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,19 @@ struct _strp_msg {
6565
struct sk_skb_cb {
6666
#define SK_SKB_CB_PRIV_LEN 20
6767
unsigned char data[SK_SKB_CB_PRIV_LEN];
68+
/* align strp on cache line boundary within skb->cb[] */
69+
unsigned char pad[4];
6870
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 */
7373
struct tls_msg {
7474
u8 control;
7575
u8 decrypted;
7676
} 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;
7781
};
7882

7983
static inline struct strp_msg *strp_msg(struct sk_buff *skb)

net/strparser/strparser.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ EXPORT_SYMBOL_GPL(strp_check_rcv);
533533

534534
static int __init strp_dev_init(void)
535535
{
536+
BUILD_BUG_ON(sizeof(struct sk_skb_cb) >
537+
sizeof_field(struct sk_buff, cb));
538+
536539
strp_wq = create_singlethread_workqueue("kstrp");
537540
if (unlikely(!strp_wq))
538541
return -ENOMEM;

0 commit comments

Comments
 (0)