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

netfilter: nft_inner: Use nested-BH locking for nft_pcpu_tun_ctx

nft_pcpu_tun_ctx 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.

Make a struct with a nft_inner_tun_ctx member (original
nft_pcpu_tun_ctx) and a local_lock_t 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 <bigeasy@linutronix.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Sebastian Andrzej Siewior and committed by
Pablo Neira Ayuso
ba36fada a1f1acb9

+15 -3
+15 -3
net/netfilter/nft_inner.c
··· 23 23 #include <linux/ip.h> 24 24 #include <linux/ipv6.h> 25 25 26 - static DEFINE_PER_CPU(struct nft_inner_tun_ctx, nft_pcpu_tun_ctx); 26 + struct nft_inner_tun_ctx_locked { 27 + struct nft_inner_tun_ctx ctx; 28 + local_lock_t bh_lock; 29 + }; 30 + 31 + static DEFINE_PER_CPU(struct nft_inner_tun_ctx_locked, nft_pcpu_tun_ctx) = { 32 + .bh_lock = INIT_LOCAL_LOCK(bh_lock), 33 + }; 27 34 28 35 /* Same layout as nft_expr but it embeds the private expression data area. */ 29 36 struct __nft_expr { ··· 244 237 struct nft_inner_tun_ctx *this_cpu_tun_ctx; 245 238 246 239 local_bh_disable(); 247 - this_cpu_tun_ctx = this_cpu_ptr(&nft_pcpu_tun_ctx); 240 + local_lock_nested_bh(&nft_pcpu_tun_ctx.bh_lock); 241 + this_cpu_tun_ctx = this_cpu_ptr(&nft_pcpu_tun_ctx.ctx); 248 242 if (this_cpu_tun_ctx->cookie != (unsigned long)pkt->skb) { 249 243 local_bh_enable(); 244 + local_unlock_nested_bh(&nft_pcpu_tun_ctx.bh_lock); 250 245 return false; 251 246 } 252 247 *tun_ctx = *this_cpu_tun_ctx; 248 + local_unlock_nested_bh(&nft_pcpu_tun_ctx.bh_lock); 253 249 local_bh_enable(); 254 250 255 251 return true; ··· 264 254 struct nft_inner_tun_ctx *this_cpu_tun_ctx; 265 255 266 256 local_bh_disable(); 267 - this_cpu_tun_ctx = this_cpu_ptr(&nft_pcpu_tun_ctx); 257 + local_lock_nested_bh(&nft_pcpu_tun_ctx.bh_lock); 258 + this_cpu_tun_ctx = this_cpu_ptr(&nft_pcpu_tun_ctx.ctx); 268 259 if (this_cpu_tun_ctx->cookie != tun_ctx->cookie) 269 260 *this_cpu_tun_ctx = *tun_ctx; 261 + local_unlock_nested_bh(&nft_pcpu_tun_ctx.bh_lock); 270 262 local_bh_enable(); 271 263 } 272 264