Skip to content

Commit

Permalink
xfrm: state: do not acquire lock in get_mtu helpers
Browse files Browse the repository at this point in the history
Once flow cache gets removed the mtu initialisation happens for every skb
that gets an xfrm attached, so this lock starts to show up in perf.

It is not obvious why this lock is required -- the caller holds
reference on the state struct, type->destructor is only called from the
state gc worker (all state structs on gc list must have refcount 0).

xfrm_init_state already has been called (else private data accessed
by type->get_mtu() would not be set up).

So just remove the lock -- the race on the state (DEAD?) doesn't
matter (could change right after dropping the lock too).

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
  • Loading branch information
Florian Westphal authored and Steffen Klassert committed Jan 6, 2017
1 parent 1365e54 commit b3b73b8
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions net/xfrm/xfrm_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -2000,16 +2000,13 @@ EXPORT_SYMBOL(xfrm_state_delete_tunnel);

int xfrm_state_mtu(struct xfrm_state *x, int mtu)
{
int res;
const struct xfrm_type *type = READ_ONCE(x->type);

spin_lock_bh(&x->lock);
if (x->km.state == XFRM_STATE_VALID &&
x->type && x->type->get_mtu)
res = x->type->get_mtu(x, mtu);
else
res = mtu - x->props.header_len;
spin_unlock_bh(&x->lock);
return res;
type && type->get_mtu)
return type->get_mtu(x, mtu);

return mtu - x->props.header_len;
}

int __xfrm_init_state(struct xfrm_state *x, bool init_replay)
Expand Down

0 comments on commit b3b73b8

Please sign in to comment.