mirror of
https://github.com/torvalds/linux.git
synced 2024-11-25 13:41:51 +00:00
d1542d4ae4
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: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Link: https://patch.msgid.link/20240620132727.660738-13-bigeasy@linutronix.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
31 lines
667 B
C
31 lines
667 B
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* SR-IPv6 implementation
|
|
*
|
|
* Authors:
|
|
* David Lebrun <david.lebrun@uclouvain.be>
|
|
* eBPF support: Mathieu Xhonneux <m.xhonneux@gmail.com>
|
|
*/
|
|
|
|
#ifndef _NET_SEG6_LOCAL_H
|
|
#define _NET_SEG6_LOCAL_H
|
|
|
|
#include <linux/percpu.h>
|
|
#include <linux/net.h>
|
|
#include <linux/ipv6.h>
|
|
|
|
extern int seg6_lookup_nexthop(struct sk_buff *skb, struct in6_addr *nhaddr,
|
|
u32 tbl_id);
|
|
extern bool seg6_bpf_has_valid_srh(struct sk_buff *skb);
|
|
|
|
struct seg6_bpf_srh_state {
|
|
local_lock_t bh_lock;
|
|
struct ipv6_sr_hdr *srh;
|
|
u16 hdrlen;
|
|
bool valid;
|
|
};
|
|
|
|
DECLARE_PER_CPU(struct seg6_bpf_srh_state, seg6_bpf_srh_states);
|
|
|
|
#endif
|