Skip to content

Commit a1a56aa

Browse files
edumazetummakynes
authored andcommitted
netfilter: x_tables: align per cpu xt_counter
Let's force a 16 bytes alignment on xt_counter percpu allocations, so that bytes and packets sit in same cache line. xt_counter being exported to user space, we cannot add __align(16) on the structure itself. Signed-off-by: Eric Dumazet <[email protected]> Cc: Florian Westphal <[email protected]> Acked-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 01555e7 commit a1a56aa

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/linux/netfilter/x_tables.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ static inline unsigned long ifname_compare_aligned(const char *_a,
356356
* so nothing needs to be done there.
357357
*
358358
* xt_percpu_counter_alloc returns the address of the percpu
359-
* counter, or 0 on !SMP.
359+
* counter, or 0 on !SMP. We force an alignment of 16 bytes
360+
* so that bytes/packets share a common cache line.
360361
*
361362
* Hence caller must use IS_ERR_VALUE to check for error, this
362363
* allows us to return 0 for single core systems without forcing
@@ -365,7 +366,8 @@ static inline unsigned long ifname_compare_aligned(const char *_a,
365366
static inline u64 xt_percpu_counter_alloc(void)
366367
{
367368
if (nr_cpu_ids > 1) {
368-
void __percpu *res = alloc_percpu(struct xt_counters);
369+
void __percpu *res = __alloc_percpu(sizeof(struct xt_counters),
370+
sizeof(struct xt_counters));
369371

370372
if (res == NULL)
371373
return (u64) -ENOMEM;

0 commit comments

Comments
 (0)