Skip to content

Commit 456010c

Browse files
Sebastian Andrzej SiewiorFlorian Westphal
authored andcommitted
netfilter: nft_set_pipapo: Use nested-BH locking for nft_pipapo_scratch
nft_pipapo_scratch is a per-CPU variable and relies on disabled BH for its locking. Without per-CPU locking in local_bh_disable() on PREEMPT_RT this data structure requires explicit locking. Add a local_lock_t to the data structure and use local_lock_nested_bh() for locking. This change adds only lockdep coverage and does not alter the functional behaviour for !PREEMPT_RT. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Florian Westphal <[email protected]>
1 parent 6aa67d5 commit 456010c

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

net/netfilter/nft_set_pipapo.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ static struct nft_pipapo_elem *pipapo_get_slow(const struct nft_pipapo_match *m,
429429
scratch = *raw_cpu_ptr(m->scratch);
430430
if (unlikely(!scratch))
431431
goto out;
432+
__local_lock_nested_bh(&scratch->bh_lock);
432433

433434
map_index = scratch->map_index;
434435

@@ -465,6 +466,7 @@ static struct nft_pipapo_elem *pipapo_get_slow(const struct nft_pipapo_match *m,
465466
last);
466467
if (b < 0) {
467468
scratch->map_index = map_index;
469+
__local_unlock_nested_bh(&scratch->bh_lock);
468470
local_bh_enable();
469471

470472
return NULL;
@@ -484,6 +486,7 @@ static struct nft_pipapo_elem *pipapo_get_slow(const struct nft_pipapo_match *m,
484486
* *next* bitmap (not initial) for the next packet.
485487
*/
486488
scratch->map_index = map_index;
489+
__local_unlock_nested_bh(&scratch->bh_lock);
487490
local_bh_enable();
488491
return e;
489492
}
@@ -498,6 +501,7 @@ static struct nft_pipapo_elem *pipapo_get_slow(const struct nft_pipapo_match *m,
498501
data += NFT_PIPAPO_GROUPS_PADDING(f);
499502
}
500503

504+
__local_unlock_nested_bh(&scratch->bh_lock);
501505
out:
502506
local_bh_enable();
503507
return NULL;
@@ -1215,6 +1219,7 @@ static int pipapo_realloc_scratch(struct nft_pipapo_match *clone,
12151219
}
12161220

12171221
pipapo_free_scratch(clone, i);
1222+
local_lock_init(&scratch->bh_lock);
12181223
*per_cpu_ptr(clone->scratch, i) = scratch;
12191224
}
12201225

net/netfilter/nft_set_pipapo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ struct nft_pipapo_field {
124124

125125
/**
126126
* struct nft_pipapo_scratch - percpu data used for lookup and matching
127+
* @bh_lock: PREEMPT_RT local spinlock
127128
* @map_index: Current working bitmap index, toggled between field matches
128129
* @__map: store partial matching results during lookup
129130
*/
130131
struct nft_pipapo_scratch {
132+
local_lock_t bh_lock;
131133
u8 map_index;
132134
unsigned long __map[];
133135
};

net/netfilter/nft_set_pipapo_avx2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ struct nft_pipapo_elem *pipapo_get_avx2(const struct nft_pipapo_match *m,
11631163
if (unlikely(!scratch))
11641164
return NULL;
11651165

1166+
__local_lock_nested_bh(&scratch->bh_lock);
11661167
map_index = scratch->map_index;
11671168
map = NFT_PIPAPO_LT_ALIGN(&scratch->__map[0]);
11681169
res = map + (map_index ? m->bsize_max : 0);
@@ -1228,6 +1229,7 @@ struct nft_pipapo_elem *pipapo_get_avx2(const struct nft_pipapo_match *m,
12281229
if (ret < 0) {
12291230
scratch->map_index = map_index;
12301231
kernel_fpu_end();
1232+
__local_unlock_nested_bh(&scratch->bh_lock);
12311233
return NULL;
12321234
}
12331235

@@ -1241,6 +1243,7 @@ struct nft_pipapo_elem *pipapo_get_avx2(const struct nft_pipapo_match *m,
12411243

12421244
scratch->map_index = map_index;
12431245
kernel_fpu_end();
1246+
__local_unlock_nested_bh(&scratch->bh_lock);
12441247
return e;
12451248
}
12461249

@@ -1250,6 +1253,7 @@ struct nft_pipapo_elem *pipapo_get_avx2(const struct nft_pipapo_match *m,
12501253
}
12511254

12521255
kernel_fpu_end();
1256+
__local_unlock_nested_bh(&scratch->bh_lock);
12531257
return NULL;
12541258
}
12551259

0 commit comments

Comments
 (0)