From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58D8A43E08F; Tue, 21 Jul 2026 22:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784672937; cv=none; b=sXMhAW9bGqoKBbXiafpZqZIB1IJ83RV1OABs9VqO1lZzx5jW9eAh9DfecIZqWJ83JT2KWUarHQBbJwJtxDW4gbtNefkWtzm+9G+HSFJ3Qqki/StJq9VvClSoa9tfPrEJRhc5bl67jzwI6rTQYiRDTuhkmHJqnwyiP5ICGfRQ25Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784672937; c=relaxed/simple; bh=CwZsgZ7Wh/I2/LTkpR2HV1Bi+FVVaITbkFRzKBkm/6E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=apl10MhI8d9E6ROLiP6ju/5Xplc/5PSCcv0/jF0oZBLXL9KWocEYg+kO/PkA6DCfBdqaAxUJUJ3kS4Xh3e6+b0s/6Ox8X/p3funh7CQ9m4fSDbZlmD69wL56nOUWUfN+NuzQ/qh203o3R2SvtI9SPnePFSfQt0DBeUViTtN90es= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=WOeuJYPW; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="WOeuJYPW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE5261F000E9; Tue, 21 Jul 2026 22:28:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784672936; bh=0ykE4A1TVqmi59HsG81tJTEds5xstWcNSSP7QxPy+vs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WOeuJYPWk0QPSihYqldeqfPsH/BWbBGfazqrdGuimEMWkiHsY3WxWnwYA5zrFzdn5 1tBD7DYRkNQIrUPTlS1s7/tReyFzUHc2aWXWI6wjqT1wFaEd1EKQi8QG7fQzB2lsdx ShyGhNFkkOdG8m09bECaY7ODTXJKEWZhjWDGqQn0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andrii Nakryiko , Daniel Borkmann , Jiri Olsa , Sasha Levin Subject: [PATCH 5.15 811/843] bpf: Consistently use bpf_rcu_lock_held() everywhere Date: Tue, 21 Jul 2026 17:27:26 +0200 Message-ID: <20260721152424.316547021@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152405.946368001@linuxfoundation.org> References: <20260721152405.946368001@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrii Nakryiko [ Upstream commit 48a97ffc6c826640907d13b199e29008f4fe2c15 ] We have many places which open-code what's now is bpf_rcu_lock_held() macro, so replace all those places with a clean and short macro invocation. For that, move bpf_rcu_lock_held() macro into include/linux/bpf.h. Signed-off-by: Andrii Nakryiko Signed-off-by: Daniel Borkmann Acked-by: Jiri Olsa Link: https://lore.kernel.org/bpf/20251014201403.4104511-1-andrii@kernel.org Stable-dep-of: 2f884d371faf ("bpf: Allow LPM map access from sleepable BPF programs") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/linux/bpf.h | 4 ++++ kernel/bpf/hashtab.c | 21 +++++++-------------- kernel/bpf/helpers.c | 9 +++------ 3 files changed, 14 insertions(+), 20 deletions(-) --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -23,6 +23,7 @@ #include #include #include +#include struct bpf_verifier_env; struct bpf_verifier_log; @@ -1482,6 +1483,9 @@ out: _ret; \ }) +#define bpf_rcu_lock_held() \ + (rcu_read_lock_held() || rcu_read_lock_trace_held() || rcu_read_lock_bh_held()) + #ifdef CONFIG_BPF_SYSCALL DECLARE_PER_CPU(int, bpf_prog_active); extern struct mutex bpf_stats_enabled_mutex; --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -642,8 +642,7 @@ static void *__htab_map_lookup_elem(stru struct htab_elem *l; u32 hash, key_size; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && - !rcu_read_lock_bh_held()); + WARN_ON_ONCE(!bpf_rcu_lock_held()); key_size = map->key_size; @@ -1047,8 +1046,7 @@ static int htab_map_update_elem(struct b /* unknown flags */ return -EINVAL; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && - !rcu_read_lock_bh_held()); + WARN_ON_ONCE(!bpf_rcu_lock_held()); key_size = map->key_size; @@ -1149,8 +1147,7 @@ static int htab_lru_map_update_elem(stru /* unknown flags */ return -EINVAL; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && - !rcu_read_lock_bh_held()); + WARN_ON_ONCE(!bpf_rcu_lock_held()); key_size = map->key_size; @@ -1218,8 +1215,7 @@ static int __htab_percpu_map_update_elem /* unknown flags */ return -EINVAL; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && - !rcu_read_lock_bh_held()); + WARN_ON_ONCE(!bpf_rcu_lock_held()); key_size = map->key_size; @@ -1273,8 +1269,7 @@ static int __htab_lru_percpu_map_update_ /* unknown flags */ return -EINVAL; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && - !rcu_read_lock_bh_held()); + WARN_ON_ONCE(!bpf_rcu_lock_held()); key_size = map->key_size; @@ -1349,8 +1344,7 @@ static int htab_map_delete_elem(struct b u32 hash, key_size; int ret; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && - !rcu_read_lock_bh_held()); + WARN_ON_ONCE(!bpf_rcu_lock_held()); key_size = map->key_size; @@ -1385,8 +1379,7 @@ static int htab_lru_map_delete_elem(stru u32 hash, key_size; int ret; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && - !rcu_read_lock_bh_held()); + WARN_ON_ONCE(!bpf_rcu_lock_held()); key_size = map->key_size; --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -30,8 +30,7 @@ */ BPF_CALL_2(bpf_map_lookup_elem, struct bpf_map *, map, void *, key) { - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && - !rcu_read_lock_bh_held()); + WARN_ON_ONCE(!bpf_rcu_lock_held()); return (unsigned long) map->ops->map_lookup_elem(map, key); } @@ -47,8 +46,7 @@ const struct bpf_func_proto bpf_map_look BPF_CALL_4(bpf_map_update_elem, struct bpf_map *, map, void *, key, void *, value, u64, flags) { - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && - !rcu_read_lock_bh_held()); + WARN_ON_ONCE(!bpf_rcu_lock_held()); return map->ops->map_update_elem(map, key, value, flags); } @@ -65,8 +63,7 @@ const struct bpf_func_proto bpf_map_upda BPF_CALL_2(bpf_map_delete_elem, struct bpf_map *, map, void *, key) { - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && - !rcu_read_lock_bh_held()); + WARN_ON_ONCE(!bpf_rcu_lock_held()); return map->ops->map_delete_elem(map, key); }