xfrm: remove three registration spinlocks

xfrm_state_afinfo[], xfrm_translator and xfrm_mode_cbs_map[] are
RCU protected pointers which are only written when a module or an
address family registers or unregisters itself. All their readers
already use rcu_read_lock() and rcu_dereference(), and the unregister
functions already call synchronize_rcu().

Each of them has a dedicated spinlock which only serializes these
rare writers:

- xfrm_state_afinfo_lock and xfrm_translator_lock make "install if
  the slot is empty" and "clear if the slot is ours" atomic. Use
  cmpxchg() instead. The return values are unchanged: -EEXIST if the
  slot is already used at registration, -EINVAL when unregistering
  while another object is installed, 0 otherwise.

- xfrm_mode_cbs_map_lock protects nothing: registration overwrites
  the slot and unregistration clears it, both unconditionally. Remove
  it, the existing behavior is kept.

Tested with the xfrm_policy.sh and xfrm_state.sh selftests. The
translator code was only compile tested, with
CONFIG_XFRM_USER_COMPAT=y, and the unregister paths were not
exercised. sparse (C=2) reports no warning.

Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 file changed