From nobody Thu Oct 2 03:23:00 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7E9AF30E82D; Tue, 23 Sep 2025 21:53:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758664394; cv=none; b=kRhE0x9v4tEceS1VyGRbLQC8rojVGjP3IpSqN907tkqNTvgFAFoO6E8sKK6iKOLJFSVKwA5k7WOtYbvjGuSXPYjplC6a2kA+r2WrvReRecMbrhkJJv6VNSQzU9fxFN18XILTNOyvw/CNG3a9if9aVmqsi0ZPO5ye5B2iV6grqdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758664394; c=relaxed/simple; bh=Uwsp9gplgTwpqAp66Yn02rMHn1hEFutbsYgZHk2p0JI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n0qUCz+QCmOP3MyTw5RyoF2CHODwcy1i2rBHZUdj/bPeiDBaq7ZJ/rvZrslojgY+304OFClQrlD5zsAUUAnwzUePww1PIo6WLgRtOcxfuhBhXWa+caZtgzT3cLRRezbGHP/D0xg2n9+oF4vJxycZWah9OwRp7iBBizVhIgc6+ws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T0us82hA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T0us82hA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2B7AC4CEF5; Tue, 23 Sep 2025 21:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758664394; bh=Uwsp9gplgTwpqAp66Yn02rMHn1hEFutbsYgZHk2p0JI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T0us82hAVX0ap4TCL9y8VXnNkg3BBkCEkOQkqxp31s/Pwt//JL+mQ5hV1mi5bghks IkumBZXCGU+NK3pTDJ4+8DATUQCmSJVXtV/Rp29s8Zu2C+qL3CToFvYHJ5ue91hOL0 PPXOWXk5eTWCVt5rniQ1Xf+0irjmBjyM9DNymy5FoPmH5n1/jZROqCUG8kMzTUtMV0 ETZ9TXLYRshVwuDv5nH2O26fVCuQsoCiVhXWJCLcgTogRn0z/CAAww/U6jS4eCMYQo HHHNUcZpAOmN+jG6Do7eOTeNDaqjksdJfK2OUhFjqRstf4Agh37WV5DuK3PKSon74O vT0ZRk0n8/eoA== From: Jiri Olsa To: Steven Rostedt , Florent Revest , Mark Rutland Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Menglong Dong Subject: [PATCH 7/9] bpf: Add trampoline ip hash table Date: Tue, 23 Sep 2025 23:51:45 +0200 Message-ID: <20250923215147.1571952-8-jolsa@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250923215147.1571952-1-jolsa@kernel.org> References: <20250923215147.1571952-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Following changes need to lookup trampoline based on its ip address, adding hash table for that. Signed-off-by: Jiri Olsa --- include/linux/bpf.h | 7 +++++-- kernel/bpf/trampoline.c | 30 +++++++++++++++++++----------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index dfc1a27b56d5..9d97c64cbf47 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1271,14 +1271,17 @@ struct bpf_tramp_image { }; =20 struct bpf_trampoline { - /* hlist for trampoline_table */ - struct hlist_node hlist; + /* hlist for trampoline_key_table */ + struct hlist_node hlist_key; + /* hlist for trampoline_ip_table */ + struct hlist_node hlist_ip; struct ftrace_ops *fops; /* serializes access to fields of this trampoline */ struct mutex mutex; refcount_t refcnt; u32 flags; u64 key; + unsigned long ip; struct { struct btf_func_model model; void *addr; diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index 97df6e482bf4..bdebaa94ca37 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -24,9 +24,10 @@ const struct bpf_prog_ops bpf_extension_prog_ops =3D { #define TRAMPOLINE_HASH_BITS 10 #define TRAMPOLINE_TABLE_SIZE (1 << TRAMPOLINE_HASH_BITS) =20 -static struct hlist_head trampoline_table[TRAMPOLINE_TABLE_SIZE]; +static struct hlist_head trampoline_key_table[TRAMPOLINE_TABLE_SIZE]; +static struct hlist_head trampoline_ip_table[TRAMPOLINE_TABLE_SIZE]; =20 -/* serializes access to trampoline_table */ +/* serializes access to trampoline tables */ static DEFINE_MUTEX(trampoline_mutex); =20 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS @@ -135,15 +136,15 @@ void bpf_image_ksym_del(struct bpf_ksym *ksym) PAGE_SIZE, true, ksym->name); } =20 -static struct bpf_trampoline *bpf_trampoline_lookup(u64 key) +static struct bpf_trampoline *bpf_trampoline_lookup(u64 key, unsigned long= ip) { struct bpf_trampoline *tr; struct hlist_head *head; int i; =20 mutex_lock(&trampoline_mutex); - head =3D &trampoline_table[hash_64(key, TRAMPOLINE_HASH_BITS)]; - hlist_for_each_entry(tr, head, hlist) { + head =3D &trampoline_key_table[hash_64(key, TRAMPOLINE_HASH_BITS)]; + hlist_for_each_entry(tr, head, hlist_key) { if (tr->key =3D=3D key) { refcount_inc(&tr->refcnt); goto out; @@ -164,8 +165,12 @@ static struct bpf_trampoline *bpf_trampoline_lookup(u6= 4 key) #endif =20 tr->key =3D key; - INIT_HLIST_NODE(&tr->hlist); - hlist_add_head(&tr->hlist, head); + tr->ip =3D ip; + INIT_HLIST_NODE(&tr->hlist_key); + INIT_HLIST_NODE(&tr->hlist_ip); + hlist_add_head(&tr->hlist_key, head); + head =3D &trampoline_ip_table[hash_64(ip, TRAMPOLINE_HASH_BITS)]; + hlist_add_head(&tr->hlist_ip, head); refcount_set(&tr->refcnt, 1); mutex_init(&tr->mutex); for (i =3D 0; i < BPF_TRAMP_MAX; i++) @@ -800,7 +805,7 @@ void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog = *prog) prog->aux->attach_btf_id); =20 bpf_lsm_find_cgroup_shim(prog, &bpf_func); - tr =3D bpf_trampoline_lookup(key); + tr =3D bpf_trampoline_lookup(key, 0); if (WARN_ON_ONCE(!tr)) return; =20 @@ -820,7 +825,7 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key, { struct bpf_trampoline *tr; =20 - tr =3D bpf_trampoline_lookup(key); + tr =3D bpf_trampoline_lookup(key, tgt_info->tgt_addr); if (!tr) return NULL; =20 @@ -856,7 +861,8 @@ void bpf_trampoline_put(struct bpf_trampoline *tr) * fexit progs. The fentry-only trampoline will be freed via * multiple rcu callbacks. */ - hlist_del(&tr->hlist); + hlist_del(&tr->hlist_key); + hlist_del(&tr->hlist_ip); if (tr->fops) { ftrace_free_filter(tr->fops); kfree(tr->fops); @@ -1129,7 +1135,9 @@ static int __init init_trampolines(void) int i; =20 for (i =3D 0; i < TRAMPOLINE_TABLE_SIZE; i++) - INIT_HLIST_HEAD(&trampoline_table[i]); + INIT_HLIST_HEAD(&trampoline_key_table[i]); + for (i =3D 0; i < TRAMPOLINE_TABLE_SIZE; i++) + INIT_HLIST_HEAD(&trampoline_ip_table[i]); return 0; } late_initcall(init_trampolines); --=20 2.51.0