• Sebastian Andrzej Siewior's avatar
    seg6: Use nested-BH locking for seg6_bpf_srh_states. · d1542d4a
    Sebastian Andrzej Siewior authored
    The access to seg6_bpf_srh_states is protected by disabling preemption.
    Based on the code, the entry point is input_action_end_bpf() and
    every other function (the bpf helper functions bpf_lwt_seg6_*()), that
    is accessing seg6_bpf_srh_states, should be called from within
    input_action_end_bpf().
    
    input_action_end_bpf() accesses seg6_bpf_srh_states first at the top of
    the function and then disables preemption. This looks wrong because if
    preemption needs to be disabled as part of the locking mechanism then
    the variable shouldn't be accessed beforehand.
    
    Looking at how it is used via test_lwt_seg6local.sh then
    input_action_end_bpf() is always invoked from softirq context. If this
    is always the case then the preempt_disable() statement is superfluous.
    If this is not always invoked from softirq then disabling only
    preemption is not sufficient.
    
    Replace the preempt_disable() statement with nested-BH locking. This is
    not an equivalent replacement as it assumes that the invocation of
    input_action_end_bpf() always occurs in softirq context and thus the
    preempt_disable() is superfluous.
    Add a local_lock_t the data structure and use local_lock_nested_bh() for
    locking. Add lockdep_assert_held() to ensure the lock is held while the
    per-CPU variable is referenced in the helper functions.
    
    Cc: Alexei Starovoitov <ast@kernel.org>
    Cc: Andrii Nakryiko <andrii@kernel.org>
    Cc: David Ahern <dsahern@kernel.org>
    Cc: Hao Luo <haoluo@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Fastabend <john.fastabend@gmail.com>
    Cc: KP Singh <kpsingh@kernel.org>
    Cc: Martin KaFai Lau <martin.lau@linux.dev>
    Cc: Song Liu <song@kernel.org>
    Cc: Stanislav Fomichev <sdf@google.com>
    Cc: Yonghong Song <yonghong.song@linux.dev>
    Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
    Link: https://patch.msgid.link/20240620132727.660738-13-bigeasy@linutronix.deSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
    d1542d4a
seg6_local.c 68.4 KB