Skip to content

Commit 7407889

Browse files
Sebastian Sewiorgregkh
authored andcommitted
xfrm: Don't disable preemption while looking up cache state.
[ Upstream commit 6c9b7db ] For the state cache lookup xfrm_input_state_lookup() first disables preemption, to remain on the CPU and then retrieves a per-CPU pointer. Within the preempt-disable section it also acquires netns_xfrm::xfrm_state_lock, a spinlock_t. This lock must not be acquired with explicit disabled preemption (such as by get_cpu()) because this lock becomes a sleeping lock on PREEMPT_RT. To remain on the same CPU is just an optimisation for the CPU local lookup. The actual modification of the per-CPU variable happens with netns_xfrm::xfrm_state_lock acquired. Remove get_cpu() and use the state_cache_input on the current CPU. Reported-by: Alexei Starovoitov <[email protected]> Closes: https://lore.kernel.org/all/CAADnVQKkCLaj=roayH=Mjiiqz_svdf1tsC3OE4EC0E=mAD+L1A@mail.gmail.com/ Fixes: 81a331a ("xfrm: Add an inbound percpu state cache.") Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Steffen Klassert <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent b3c0a89 commit 7407889

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

net/xfrm/xfrm_state.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,9 +1150,8 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark,
11501150
struct xfrm_hash_state_ptrs state_ptrs;
11511151
struct hlist_head *state_cache_input;
11521152
struct xfrm_state *x = NULL;
1153-
int cpu = get_cpu();
11541153

1155-
state_cache_input = per_cpu_ptr(net->xfrm.state_cache_input, cpu);
1154+
state_cache_input = raw_cpu_ptr(net->xfrm.state_cache_input);
11561155

11571156
rcu_read_lock();
11581157
hlist_for_each_entry_rcu(x, state_cache_input, state_cache_input) {
@@ -1186,7 +1185,6 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark,
11861185

11871186
out:
11881187
rcu_read_unlock();
1189-
put_cpu();
11901188
return x;
11911189
}
11921190
EXPORT_SYMBOL(xfrm_input_state_lookup);

0 commit comments

Comments
 (0)