From nobody Thu Oct 2 11:51:11 2025 Received: from SEYPR02CU001.outbound.protection.outlook.com (mail-koreacentralazon11013000.outbound.protection.outlook.com [40.107.44.0]) (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 780BC3016F6; Wed, 17 Sep 2025 07:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.44.0 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758093820; cv=fail; b=uR/u/1j0lc2++vJmvFZgmd+w6CjXKl43WC5LoTceGurvmGvn6HX5twKdG4snheMQVXZGb+/46Uk4Zh9Lc01Q/mbanaObBr/IHSAw7ix17ILZcqANx/QJMD7stgDUoSdySFGxzW+MYRIqQhets9S5A0MC6TPagbA8nhNRUGkDvtk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758093820; c=relaxed/simple; bh=9+ejYfeAFd83QO7MarSlYXLhZ1fXbTqebkFXCRqiLu4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=PerMYc4hduPxEBz+02eZPEQpzejQlM+3pDSrt+r8t/0iKFQZTTb5TOlvpSTLJOYR3rIXWOg+Qn8gSZfUEeWWobX9r8rG80R2TGy5YwBJM7j6nmUA/4WYB2i0lxVSSlnhBh8fYCuPDLy0ByY0fWo4hIBc7pSo0cqEvD8sCgOXuiA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com; spf=pass smtp.mailfrom=vivo.com; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b=GgdphCm0; arc=fail smtp.client-ip=40.107.44.0 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="GgdphCm0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NwccvdfSA+p37tD9DhH9vNFHuEHGq/cenMCdyh08N3CqDpBIPo8ih1fterCJzQMuH9jb3c3zq2ZV0ip97gzCvQvQm1O4hyIxJPVdUMKniZhq/XAdxMuAIWvsNKo/OvpYJnSgokbgqPsm/5CXm2J9b4qcnNQhFF1OY4AZOSb+oxjbwfwVNqq5eXvyJcytFH7oneJwdM7xRvpqQa3uEsJsN+xXryTASNJ2PlexbBHW5ImcYfp40ko+z7RJV4eKvJw/KRTA8qiACh7R9U5IDqNKQ7pDDI1dtg1nkK2qQfeOhAdrlRX74MxSOpQVtu5+Vps4O3GuAmhPnH55EYJ56uQUJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hRo19hDr5AtkWZPl/HJOdkMxAMyDEbkSfhGIiamt2+s=; b=NtpA1q1uhRqsb13wUk1PvaswqR8wtYDG2vc/s/2LCgb/h4tYKjfF7qMizfXCQMXNthNcLtIbqJD2MDrnHT1En9D6795N7kK2AMCpewuccE+jsQlAhorZ7t5hMITUX4W2TAqavjiIR/tBKD1241OR5iZLhPV/dfrqBTMJdtYqqtQJwSUUCJ0z6U2Ln/MO6l3S4gFohWYZdCy3KIq/6OAWG1o8GnNv3fUJup8I6G/Vl+u+G7vQA2IZqIBe6WY65cOexQTUXh5U/HXDfdjEfUGPXIEYqVEGj6JJCptZGFxU35mWkTNnqAuuVL6EP2F4m1huhp7ej1l+b8ljd3knCdxxkA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hRo19hDr5AtkWZPl/HJOdkMxAMyDEbkSfhGIiamt2+s=; b=GgdphCm0O4sRAX+OMPbaZftcEt4mebAdlKd3k0zlaU54iIKd/iSHKGfO3dNWZn0hYmSiXysXp7r12w8LLYMYMMfFWprTnvgZVbqI7F7srQe43qV7VY6drMN7CMlp1iQvZivohixJBU94BGZAmt4pHib9MDcUGlym4jsfAvis0s7NpFdikRb2hKwHnMTJchxt8oXSLMrpFNG8a2E5XmvFylYL7aVaYGBelSGKj6HRqgOQwsOleuPGhC04u3zNN6MYESLKL6Nm0eokFGx9NLr332K87i/HUhzIcAdDGvglRvj4fdkW6eep160wvicG/ptvHylD4mKhiUCwG9tw/Ucyuw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from PUZPR06MB4742.apcprd06.prod.outlook.com (2603:1096:301:b5::13) by KL1PR06MB6043.apcprd06.prod.outlook.com (2603:1096:820:d6::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.23; Wed, 17 Sep 2025 07:23:31 +0000 Received: from PUZPR06MB4742.apcprd06.prod.outlook.com ([fe80::206c:c661:9838:5571]) by PUZPR06MB4742.apcprd06.prod.outlook.com ([fe80::206c:c661:9838:5571%4]) with mapi id 15.20.9137.012; Wed, 17 Sep 2025 07:23:31 +0000 From: Fuyu Zhao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, haoluo@google.com, jolsa@kernel.org, eddyz87@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, shuah@kernel.org, willemb@google.com, kerneljasonxing@gmail.com, paul.chaignon@gmail.com, chen.dylane@linux.dev, memxor@gmail.com, martin.kelly@crowdstrike.com, zhaofuyu@vivo.com, ameryhung@gmail.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: yikai.lin@vivo.com Subject: [RFC PATCH bpf-next v1 1/3] bpf: Introduce BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE Date: Wed, 17 Sep 2025 15:22:40 +0800 Message-ID: <20250917072242.674528-2-zhaofuyu@vivo.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250917072242.674528-1-zhaofuyu@vivo.com> References: <20250917072242.674528-1-zhaofuyu@vivo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SI2PR02CA0043.apcprd02.prod.outlook.com (2603:1096:4:196::12) To PUZPR06MB4742.apcprd06.prod.outlook.com (2603:1096:301:b5::13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB4742:EE_|KL1PR06MB6043:EE_ X-MS-Office365-Filtering-Correlation-Id: ad0b585e-2488-4012-6ba6-08ddf5bb1ac6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|52116014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?pK9retHz9TnmYYfGJKvuO+bXzK7zKlf6H5TVac86X1EttxwzEMY1/oi5wuwT?= =?us-ascii?Q?UwON7dC/iRJKYXVw1yWoYn78AozyOtbz6C+vzoKvpepgkxiX2MHoY7C6ZHxz?= =?us-ascii?Q?xEs/cSgS3JQggq1Z6B20x0ExMQAxwxTblSy5PhbU+61IOT7Yg2YoKOuMbQt6?=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VBAT9Q24CPn66zkOsSYTtsSkOXFznu?= =?us-ascii?Q?ma57QEDew7cWGrmwuNvWBPCE90vIjzVQT3VC8osfOFp9ItU4L3TuKYFpHEUz?= =?us-ascii?Q?lS6XyLre06lQkLILfjCBBjV79RS2wVLurj1bGMuENoFDqs5pMO/Dh8wlevn6?= =?us-ascii?Q?iEFQP5fgL1GKHxBGJs7bffRjOQsrO3jE8P8ilkZsh3wi4wlMh0/kE34sDSsg?= =?us-ascii?Q?YTufPDi6XeDMbtnEMmBB2LhYKcruwiRAYik3tRAluJOglTaikkni7LQ53ygI?= =?us-ascii?Q?wXefyzgzMRaz34sANWuQCtsBd2+okJByBzS0YqR2fsF3nWnYn4WsLnPwgu26?= =?us-ascii?Q?0vqcMhLOkWNmEYsth5Az32Rw5OHGNKir7ZBH96jm1MNrraHpzEQvGoFNiBO1?= =?us-ascii?Q?G61uTweoElS49NQSgkKPmRqkblcsXdKPqMKd888tlZDeoMWAgeZlqOvhdFRa?= =?us-ascii?Q?/zSR+YzxHGaqstA=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR06MB4742.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(7416014)(52116014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?TEItbHJ0N4IlHLZKRjsBwbD3Ou5T+XyYFERO9pZGws+oixs60vssWfDgjuFp?= =?us-ascii?Q?wXmuocFDPOPB8/v+O7v4RKkHbmsgApQxWGtwW9mEx4Y3UnRDm9d2Vyx0rmB5?= =?us-ascii?Q?911gtU2w5v+1SgDyZ8U9Omd+6KbV7yklZYuUgnq5gXndkuN42ljezoawUDw7?= =?us-ascii?Q?uE78CzYhHKiR7QRzVR8o3KoDuthw5GBe53eXdv/oEzGjR+D2j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eQ6VjCpIyccgMN+iQ6LmtBR1QIWQjLpND5A?= =?us-ascii?Q?wkfp/LNztpfYUUooIkfUKZbJPCLflEt4ct4HjiGv3biTYEQlJBbLZO1zZ2lp?= =?us-ascii?Q?jvPd8Ubuoaa9AkLPiAGUzDcIknkEd//Qn0htPQdBxiso7JZLXq5KRw/kRh/4?= =?us-ascii?Q?NEPpSlCPL9wQHh6zfueGHPuBoz7XQhJoz/kyWGnrTD2/WdLaKStC7eixyeVc?= =?us-ascii?Q?OotMIcwqsOonTCJ82q2csAmfs86de6wzARZPQCP60EMj5fc7xpD3dDcjy8+o?= =?us-ascii?Q?mpkmVQqtekKcu5yvZ05ZfngCk89ZK87jYE8GHQePJAZGmnwdZ7bPz/ES3MI5?= =?us-ascii?Q?VJ6NPptbvdrLnlxJdVzu0zsG38ZmEKNC97MWrJ6COiiJ/TF9IW8yN4Z813c2?= =?us-ascii?Q?ec2cxmobnqLTwKbjdURTryDoNml/dxe0cTTo05zT6KOY4kynj9XLt0tq/Fmw?= =?us-ascii?Q?uezLRs1sJf4nLnsEq0zIXCE0xFvQ9EshmRPQieHF?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad0b585e-2488-4012-6ba6-08ddf5bb1ac6 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB4742.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2025 07:23:31.5308 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3lPfSvAaqzmRzse54zjzL/gO0wgRSGUoGsLRluR+dGf6ANuAcg1zJa65GVlFlVokdS9hV0VDDBCCZLD42uZWOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6043 Content-Type: text/plain; charset="utf-8" This patch introduces a new program type -- BPF_PROG_TYPE_RAW_TRACEPOINT_OV= ERRIDE. Program of this type requires an additional parameter -- probe_name, to loc= ate the target tracepoint probe function registered by register_trace_* in the = kernel. This type reuses existing RAW_TRACEPOINT infrastructure, and differs only when probe_name is specified. In that case, the newly attached RAW_TRACEPOINT_OVERRIDE program and the target probe function are paired and stored in a snapshot. When the BPF program is detached, snapshots are consulted to determine whether restoration of the original probe function is required. Signed-off-by: Fuyu Zhao --- include/linux/bpf_types.h | 2 + include/linux/trace_events.h | 9 ++ include/linux/tracepoint-defs.h | 6 + include/linux/tracepoint.h | 3 + include/uapi/linux/bpf.h | 2 + kernel/bpf/syscall.c | 35 ++++-- kernel/trace/bpf_trace.c | 31 ++++++ kernel/tracepoint.c | 190 +++++++++++++++++++++++++++++++- 8 files changed, 269 insertions(+), 9 deletions(-) diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h index fa78f49d4a9a..e5cf8a1af6cd 100644 --- a/include/linux/bpf_types.h +++ b/include/linux/bpf_types.h @@ -48,6 +48,8 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE, raw_= tracepoint_writable, struct bpf_raw_tracepoint_args, u64) BPF_PROG_TYPE(BPF_PROG_TYPE_TRACING, tracing, void *, void *) +BPF_PROG_TYPE(BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE, raw_tracepoint_overri= de, + struct bpf_raw_tracepoint_args, u64) #endif #ifdef CONFIG_CGROUP_BPF BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_DEVICE, cg_dev, diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index 04307a19cde3..fcb2d62d0c9f 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -768,6 +768,9 @@ int perf_event_query_prog_array(struct perf_event *even= t, void __user *info); struct bpf_raw_tp_link; int bpf_probe_register(struct bpf_raw_event_map *btp, struct bpf_raw_tp_li= nk *link); int bpf_probe_unregister(struct bpf_raw_event_map *btp, struct bpf_raw_tp_= link *link); +int bpf_probe_override(struct bpf_raw_event_map *btp, + struct bpf_raw_tp_link *link, + const char *probe_name); =20 struct bpf_raw_event_map *bpf_get_raw_tracepoint(const char *name); void bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp); @@ -805,6 +808,12 @@ static inline int bpf_probe_unregister(struct bpf_raw_= event_map *btp, struct bpf { return -EOPNOTSUPP; } +static inline int bpf_probe_override(struct bpf_raw_event_map *btp, + struct bpf_raw_tp_link *link, + const char *probe_name) +{ + return -EOPNOTSUPP; +} static inline struct bpf_raw_event_map *bpf_get_raw_tracepoint(const char = *name) { return NULL; diff --git a/include/linux/tracepoint-defs.h b/include/linux/tracepoint-def= s.h index aebf0571c736..9d7b1710c0aa 100644 --- a/include/linux/tracepoint-defs.h +++ b/include/linux/tracepoint-defs.h @@ -29,6 +29,11 @@ struct tracepoint_func { int prio; }; =20 +struct tracepoint_func_snapshot { + struct tracepoint_func orig; + struct tracepoint_func override; +}; + struct tracepoint_ext { int (*regfunc)(void); void (*unregfunc)(void); @@ -45,6 +50,7 @@ struct tracepoint { void *probestub; struct tracepoint_func __rcu *funcs; struct tracepoint_ext *ext; + struct tracepoint_func_snapshot *snapshot; }; =20 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 826ce3f8e1f8..399001e2afca 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -50,6 +50,9 @@ tracepoint_probe_register_may_exist(struct tracepoint *tp= , void *probe, return tracepoint_probe_register_prio_may_exist(tp, probe, data, TRACEPOINT_DEFAULT_PRIO); } +extern int +tracepoint_probe_override(struct tracepoint *tp, void *probe, void *data, + const char *func_replaced); extern void for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv), void *priv); diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 233de8677382..cd3d889fe634 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1071,6 +1071,7 @@ enum bpf_prog_type { BPF_PROG_TYPE_SK_LOOKUP, BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */ BPF_PROG_TYPE_NETFILTER, + BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE, __MAX_BPF_PROG_TYPE }; =20 @@ -1707,6 +1708,7 @@ union bpf_attr { __u32 prog_fd; __u32 :32; __aligned_u64 cookie; + __aligned_u64 probe_name; } raw_tracepoint; =20 struct { /* anonymous struct for BPF_BTF_LOAD */ diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 3f178a0f8eb1..e360062db34e 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -4092,14 +4092,16 @@ static int bpf_perf_link_attach(const union bpf_att= r *attr, struct bpf_prog *pro #endif /* CONFIG_PERF_EVENTS */ =20 static int bpf_raw_tp_link_attach(struct bpf_prog *prog, - const char __user *user_tp_name, u64 cookie, + const char __user *user_tp_name, + const char __user *user_probe_name, + u64 cookie, enum bpf_attach_type attach_type) { struct bpf_link_primer link_primer; struct bpf_raw_tp_link *link; struct bpf_raw_event_map *btp; - const char *tp_name; - char buf[128]; + const char *tp_name, *probe_name; + char buf[128], probe[128]; int err; =20 switch (prog->type) { @@ -4124,6 +4126,17 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *p= rog, buf[sizeof(buf) - 1] =3D 0; tp_name =3D buf; break; + case BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE: + if (strncpy_from_user(buf, user_tp_name, sizeof(buf) - 1) < 0) + return -EFAULT; + buf[sizeof(buf) - 1] =3D 0; + tp_name =3D buf; + + if (strncpy_from_user(probe, user_probe_name, sizeof(probe) - 1) < 0) + return -EFAULT; + probe[sizeof(probe) - 1] =3D 0; + probe_name =3D probe; + break; default: return -EINVAL; } @@ -4149,7 +4162,10 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *p= rog, goto out_put_btp; } =20 - err =3D bpf_probe_register(link->btp, link); + if (prog->type =3D=3D BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE) + err =3D bpf_probe_override(link->btp, link, probe_name); + else + err =3D bpf_probe_register(link->btp, link); if (err) { bpf_link_cleanup(&link_primer); goto out_put_btp; @@ -4162,12 +4178,12 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *= prog, return err; } =20 -#define BPF_RAW_TRACEPOINT_OPEN_LAST_FIELD raw_tracepoint.cookie +#define BPF_RAW_TRACEPOINT_OPEN_LAST_FIELD raw_tracepoint.probe_name =20 static int bpf_raw_tracepoint_open(const union bpf_attr *attr) { struct bpf_prog *prog; - void __user *tp_name; + void __user *tp_name, *probe_name; __u64 cookie; int fd; =20 @@ -4180,7 +4196,9 @@ static int bpf_raw_tracepoint_open(const union bpf_at= tr *attr) =20 tp_name =3D u64_to_user_ptr(attr->raw_tracepoint.name); cookie =3D attr->raw_tracepoint.cookie; - fd =3D bpf_raw_tp_link_attach(prog, tp_name, cookie, prog->expected_attac= h_type); + probe_name =3D u64_to_user_ptr(attr->raw_tracepoint.probe_name); + fd =3D bpf_raw_tp_link_attach(prog, tp_name, probe_name, + cookie, prog->expected_attach_type); if (fd < 0) bpf_prog_put(prog); return fd; @@ -5565,7 +5583,8 @@ static int link_create(union bpf_attr *attr, bpfptr_t= uattr) goto out; } if (prog->expected_attach_type =3D=3D BPF_TRACE_RAW_TP) - ret =3D bpf_raw_tp_link_attach(prog, NULL, attr->link_create.tracing.co= okie, + ret =3D bpf_raw_tp_link_attach(prog, NULL, NULL, + attr->link_create.tracing.cookie, attr->link_create.attach_type); else if (prog->expected_attach_type =3D=3D BPF_TRACE_ITER) ret =3D bpf_iter_link_attach(attr, uattr, prog); diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 606007c387c5..1e965517ba05 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1998,6 +1998,14 @@ const struct bpf_verifier_ops raw_tracepoint_writabl= e_verifier_ops =3D { const struct bpf_prog_ops raw_tracepoint_writable_prog_ops =3D { }; =20 +const struct bpf_verifier_ops raw_tracepoint_override_verifier_ops =3D { + .get_func_proto =3D raw_tp_prog_func_proto, + .is_valid_access =3D raw_tp_writable_prog_is_valid_access, +}; + +const struct bpf_prog_ops raw_tracepoint_override_prog_ops =3D { +}; + static bool pe_prog_is_valid_access(int off, int size, enum bpf_access_typ= e type, const struct bpf_prog *prog, struct bpf_insn_access_aux *info) @@ -2307,6 +2315,29 @@ BPF_TRACE_DEFN_x(10); BPF_TRACE_DEFN_x(11); BPF_TRACE_DEFN_x(12); =20 +int bpf_probe_override(struct bpf_raw_event_map *btp, + struct bpf_raw_tp_link *link, + const char *probe_name) +{ + struct tracepoint *tp =3D btp->tp; + struct bpf_prog *prog =3D link->link.prog; + + if (!probe_name) + return -EINVAL; + + /* + * check that program doesn't access arguments beyond what's + * available in this tracepoint + */ + if (prog->aux->max_ctx_offset > btp->num_args * sizeof(u64)) + return -EINVAL; + + if (prog->aux->max_tp_access > btp->writable_size) + return -EINVAL; + + return tracepoint_probe_override(tp, (void *)btp->bpf_func, link, probe_n= ame); +} + int bpf_probe_register(struct bpf_raw_event_map *btp, struct bpf_raw_tp_li= nk *link) { struct tracepoint *tp =3D btp->tp; diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 62719d2941c9..3b8317306edc 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -14,6 +14,7 @@ #include #include #include +#include =20 enum tp_func_state { TP_FUNC_0, @@ -130,6 +131,121 @@ static void debug_print_probes(struct tracepoint_func= *funcs) printk(KERN_DEBUG "Probe %d : %pSb\n", i, funcs[i].func); } =20 +static struct tracepoint_func * +find_func_to_override(struct tracepoint_func *funcs, + unsigned long probe_addr) +{ + int iter; + + if (!funcs) + return NULL; + + for (iter =3D 0; funcs[iter].func; iter++) { + if ((unsigned long)funcs[iter].func =3D=3D probe_addr) + return &(funcs[iter]); + } + + return NULL; +} + +static struct tracepoint_func_snapshot * +find_func_snapshot(struct tracepoint_func_snapshot **ss, + struct tracepoint_func *func, + bool *is_override) +{ + int iter; + struct tracepoint_func_snapshot *shots; + + shots =3D *ss; + if (!shots) + return NULL; + + for (iter =3D 0; shots[iter].override.func; iter++) { + if (shots[iter].override.func =3D=3D func->func && + shots[iter].override.data =3D=3D func->data) { + *is_override =3D true; + return &(shots[iter]); + } + + if (shots[iter].orig.func =3D=3D func->func && + shots[iter].orig.data =3D=3D func->data) { + *is_override =3D false; + return &(shots[iter]); + } + } + + return NULL; +} + +static void drop_func_snapshot(struct tracepoint_func_snapshot **ss, + struct tracepoint_func_snapshot *drop) +{ + struct tracepoint_func_snapshot *old, *new; + int nr_snapshots; /* Counter for snapshots */ + int iter; /* Iterate over old snapshots */ + int idx =3D 0; /* Index of snapshot to drop */ + + old =3D *ss; + if (!old) + return; + + for (nr_snapshots =3D 0; old[nr_snapshots].override.func; nr_snapshots++)= { + if (&(old[nr_snapshots]) =3D=3D drop) + idx =3D nr_snapshots; + } + + if (nr_snapshots =3D=3D 0) { + kfree(old); + *ss =3D NULL; + return; + } + + new =3D kmalloc_array(nr_snapshots, sizeof(struct tracepoint_func_snapsho= t), GFP_KERNEL); + if (!new) { + for (iter =3D idx; iter < nr_snapshots - 1; iter++) + old[iter] =3D old[iter + 1]; + memset(&(old[nr_snapshots - 1]), 0, sizeof(struct tracepoint_func_snapsh= ot)); + } else { + int j =3D 0; + + for (iter =3D 0; iter < nr_snapshots; iter++) { + if (iter !=3D idx) + new[j++] =3D old[iter]; + } + kfree(old); + *ss =3D new; + } +} + +static int save_func_snapshot(struct tracepoint_func_snapshot **ss, + struct tracepoint_func *new_func, + struct tracepoint_func *old_func) +{ + struct tracepoint_func_snapshot *old, *new; + int nr_shots =3D 0; /* Counter for old snapshots */ + int total; /* Total count of new snapshots */ + + old =3D *ss; + if (old) + while (old[nr_shots].override.func) + nr_shots++; + + /* + 2 : one for new snapshot, one for NULL snapshot */ + total =3D nr_shots + 2; + new =3D kmalloc_array(total, sizeof(struct tracepoint_func_snapshot), GFP= _KERNEL); + if (!new) + return -ENOMEM; + + memcpy(new, old, nr_shots * sizeof(struct tracepoint_func_snapshot)); + new[nr_shots].orig =3D *old_func; + new[nr_shots].override =3D *new_func; + new[nr_shots + 1].override.func =3D NULL; + + *ss =3D new; + kfree(old); + return 0; +} + static struct tracepoint_func * func_add(struct tracepoint_func **funcs, struct tracepoint_func *tp_func, int prio) @@ -412,6 +528,52 @@ static int tracepoint_remove_func(struct tracepoint *t= p, return 0; } =20 +static int tracepoint_override_func(struct tracepoint *tp, + struct tracepoint_func *func, + struct tracepoint_func *func_override) +{ + int ret =3D tracepoint_remove_func(tp, func); + + return ret ? : tracepoint_add_func(tp, func_override, + func_override->prio, false); +} + +static int tracepoint_restore_func(struct tracepoint *tp, + struct tracepoint_func *func, + struct tracepoint_func *func_restore) +{ + int ret =3D tracepoint_remove_func(tp, func); + + return ret ? : tracepoint_add_func(tp, func_restore, + func_restore->prio, false); +} + +int tracepoint_probe_override(struct tracepoint *tp, void *probe, + void *data, const char *probe_name) +{ + struct tracepoint_func tp_func; + struct tracepoint_func *target_func; + unsigned long probe_addr; + int ret; + + probe_addr =3D kallsyms_lookup_name(probe_name); + mutex_lock(&tracepoints_mutex); + target_func =3D find_func_to_override(tp->funcs, probe_addr); + if (!target_func) + return -ESRCH; + tp_func.func =3D probe; + tp_func.data =3D data; + tp_func.prio =3D target_func->prio; + ret =3D save_func_snapshot(&(tp->snapshot), &tp_func, target_func); + if (ret) + goto unlock; + + ret =3D tracepoint_override_func(tp, target_func, &tp_func); +unlock: + mutex_unlock(&tracepoints_mutex); + return ret; +} + /** * tracepoint_probe_register_prio_may_exist - Connect a probe to a tracep= oint with priority * @tp: tracepoint @@ -496,12 +658,38 @@ EXPORT_SYMBOL_GPL(tracepoint_probe_register); int tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *= data) { struct tracepoint_func tp_func; + struct tracepoint_func_snapshot *shot; int ret; + bool is_override; /* whether probe is an overriding func */ =20 mutex_lock(&tracepoints_mutex); tp_func.func =3D probe; tp_func.data =3D data; - ret =3D tracepoint_remove_func(tp, &tp_func); + + shot =3D find_func_snapshot(&(tp->snapshot), &tp_func, &is_override); + if (!shot) { + ret =3D tracepoint_remove_func(tp, &tp_func); + } else { + /* unregister probe rengistered by raw_tracepoint_open, + * restore to original tp_func. + * + * 1. restore orig func from snapshot. + * 2. remove snapshot. + */ + if (is_override) + ret =3D tracepoint_restore_func(tp, &tp_func, &(shot->orig)); + /* unregister orig probe registered by register_trace_*. + * + * 1. remove curr probe func(registered by raw_tracepoint_open) + * from tp->funcs. + * 2. remove snapshot. + */ + else + ret =3D tracepoint_remove_func(tp, &(shot->override)); + if (!ret) + drop_func_snapshot(&(tp->snapshot), shot); + } + mutex_unlock(&tracepoints_mutex); return ret; } --=20 2.43.0 From nobody Thu Oct 2 11:51:11 2025 Received: from TYDPR03CU002.outbound.protection.outlook.com (mail-japaneastazon11013037.outbound.protection.outlook.com [52.101.127.37]) (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 3B9853016F8; Wed, 17 Sep 2025 07:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.127.37 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758093822; cv=fail; b=CUwRye8mjkFHdx+kxUdlDrQ6wnMKrVonibqshivnMk6NFbmjWydL4D44GhwlEIDOy8kSXk1nhHfvpK1Uda9pcJgBLoyAw8cgqaMCpNLOR2MDObPNQ/mW18RYxfZfUnFxE2SZZVR1+pyBHHUND/SnqqOzi6JtI6SM+37DhPS7Uoo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758093822; c=relaxed/simple; bh=Z0gekOetFarjFG0A4pRwAAS2344RzODgv8vdt3u9U+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=uVLgPPy9xpptLnP0Z90uPMAOhEFqgM4e65lW+bIvz7d5E1LkBOFcQyKJbL/+5Ioz273SEAXpl31zzmH+H21l2y/d/rIaB6T838FK+2pzE589K4aSZtHO2rPHSmn5SYQU67BxGp3NwDcMRZqfgKRqGpwbSU3fzS9lFeTZ2MZV5to= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com; spf=pass smtp.mailfrom=vivo.com; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b=hSvnNj39; arc=fail smtp.client-ip=52.101.127.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="hSvnNj39" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=g5u+K5r6eaxF1Ggp8N7YZHlhLuHI4gUFo8ynrc1xWqnFSg4Mn+lAYTrolxt+ZA9dG+CcjZeGiH7kx1VQpuR1x/n4q+sFFR/OIKjQZL2xc3gNYc0nWbAUGQhi8gLuGkTa7PxLhSIBan+SJtAzIWEfDfBes7QvDWfGITP99VFGnTjMpH8n0sIDRC1yJihoNnPg67ctRSCuCFMyhkCunF2EqJVslekEz/Fcl2TTCSMKoIu42buwKl5jFZ1HBiKRP7e6LyKz7N3R9o0FKxOrCUjPCxku4uYVyqdJOREaXznllT/R17SNLzve9ydgJkndez8MZS3qbF6y+tGnrds6snoRqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FcSEcLty3kVH7KefJKWuN62WrkncK/xny/4DQYNUGaY=; b=s52oYm52BIFmPW9lKqb1mWAdz6ylj7P9vMSa5ZW5PWJdpqGmauqfFh74CBpcYJo6VFqxcew4mEUX8sVnhoeq1cchi/GcMmqHbm9Aj5rr2mtKCB2pGxfstQuMe3Aibx18EdiIFN6U3R6PsoVQ6iHT33Li6MEocM2HNfiAMoO1oJ9yibM0b2i6Q4mHgDeBP+abwMjNgIb9RKJu99sEzNZl1E6hsujoYxwQnAzW1dntAZrLNfLWs8htTJdR/LYFdDZ3ffjGGHTCfrhWJcKPIIWjZU2wrDfH/juv4piZ5aTV1sVuNOzWrnXsk20FVpzT26F1fOoOZzYnD/1/yWzrsWXoGw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FcSEcLty3kVH7KefJKWuN62WrkncK/xny/4DQYNUGaY=; b=hSvnNj39WOfMWNPt9TqmuOtoABM2G/pLOf/vgQ6GtzphLvwC4q3IIzYpL0qdscl4YIpqHwgQXD5z4lu9nrKtnSyB69GNU+hoy+0VNM4C+Vysvu2PoViO8PN3AIArBEAeE5/5Y2IpTslxWuIrcyj4MNZE8HYpvkoFOHUzuOgtMYTTFpT0BT3wFNkm2fyvcO6InnuUs+8LzAnup3kJFLTRKSQ2cycH47pkEUcvyFfEbGFYPnzJMdAFzP/AbNwk2beY986I2dwiCzPa+MEO8cC08YbvBbiLJtzLqHZbHfq/KcXULuKE6DjTN4L5yINMK+o/GotmU7aZ10wEbxZyfk3Jmw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from PUZPR06MB4742.apcprd06.prod.outlook.com (2603:1096:301:b5::13) by PS1PPF56C578557.apcprd06.prod.outlook.com (2603:1096:308::24f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.19; Wed, 17 Sep 2025 07:23:35 +0000 Received: from PUZPR06MB4742.apcprd06.prod.outlook.com ([fe80::206c:c661:9838:5571]) by PUZPR06MB4742.apcprd06.prod.outlook.com ([fe80::206c:c661:9838:5571%4]) with mapi id 15.20.9137.012; Wed, 17 Sep 2025 07:23:35 +0000 From: Fuyu Zhao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, haoluo@google.com, jolsa@kernel.org, eddyz87@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, shuah@kernel.org, willemb@google.com, kerneljasonxing@gmail.com, paul.chaignon@gmail.com, chen.dylane@linux.dev, memxor@gmail.com, martin.kelly@crowdstrike.com, zhaofuyu@vivo.com, ameryhung@gmail.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: yikai.lin@vivo.com Subject: [RFC PATCH bpf-next v1 2/3] libbpf: Add support for BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE Date: Wed, 17 Sep 2025 15:22:41 +0800 Message-ID: <20250917072242.674528-3-zhaofuyu@vivo.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250917072242.674528-1-zhaofuyu@vivo.com> References: <20250917072242.674528-1-zhaofuyu@vivo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SI2PR02CA0043.apcprd02.prod.outlook.com (2603:1096:4:196::12) To PUZPR06MB4742.apcprd06.prod.outlook.com (2603:1096:301:b5::13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB4742:EE_|PS1PPF56C578557:EE_ X-MS-Office365-Filtering-Correlation-Id: 24256d5e-2c43-4f5a-08b1-08ddf5bb1d11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|52116014|366016|376014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?5T93MRoFK7TrlTc1yhYwCHOaeY480kpByXYQPe8haq6p1g8NxTI3MGzGbQJ3?= =?us-ascii?Q?+g2d9+OEHw/bCr50LdTTOVBa6lVXeOOK9VcDvEjKFvZzut+nUJoLtoVnQcCU?= =?us-ascii?Q?xmETJpzSCwK4wMb85wAV04eJkM9hWN4xbfhZeAG0Hj8dkjkSR8qQTgDAFTge?= =?us-ascii?Q?SFssVQEB9VFJmUgA+KABEe67l4hNzP5nsL1DF9VdGMq647zBOHgFDXgj6kxq?= =?us-ascii?Q?dwZ3LiADUgPq0lO1ySZmdbI4dkEhjQe7iC6eI1c0+9yopfg7ArfF8UIN1bDU?= =?us-ascii?Q?BHIeexPX/Hd5eZEVGeJp7NXpcRBwnnqaC1ysMA5t2uFZEeH4EN4G6HsXuRZF?= =?us-ascii?Q?NNBPW7u35H59P40BfQa8qqLTZpSlIrHq+OJ+sQEBDYtfLit5y2tFEIZEdMfd?= =?us-ascii?Q?Tapu3Saqhs+VtDgplq1LZOVSIaILj9cFUkMBRl7OFZNZ8iBAHoTx3MGTRbO+?= =?us-ascii?Q?8qih6seRqNgc1uDgeEyOBNwyoTq3Dq08GNP1JICOBS0DUua4RY0qrtCISWUN?= =?us-ascii?Q?sx3rpEkgYp5xE1OpwYiOuQKVNU4cLzGqb8AswoBEH0QnXje5C62j9pkuQ7la?= =?us-ascii?Q?FlUkYE9OwRnCnYerLRMFvS+3KYR6mY4k1owK+mPu00i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gXsfVM3c=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR06MB4742.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(52116014)(366016)(376014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?BOZs8lR7f2/OOV7LTxwdgmxg2SDdMeTkfZI96d6fHooDZxS5/pcmU0qdmhr8?= =?us-ascii?Q?2/w7kpnObar9VjXLHBFkvjnmC36puFTjCOfwEoOhp2/YGycQQ1s+trEFg5Dz?= =?us-ascii?Q?EWoNC1QJtRmJfNA6l1BOJosX9KAfwQydTmVvVUzVe6lVbGdwFMA0eYVo/ZQ8?= =?us-ascii?Q?74qw/lrdiAuczrCu7t+4Rf806NYAn0zaYs8XGp5HKR+I8XUzNNkuAH6/vVc5?= =?us-ascii?Q?9aJULHpS/I/jbBKw/5LcCS51eg1pjGsQkK4TByCkXyPsYOhn75/DgFJkd796?= =?us-ascii?Q?MDlsFwV+iffCJWWfMBdf/u1Ezc4IK/0+haU56p4TDLvS8uPoElVVIWEjbnEa?= =?us-ascii?Q?G2ykjbpwfHXNkwy3Nm5xngLyml4PanuYnJfDmsW6olzHLIeVKup4yuD2uzJv?= =?us-ascii?Q?15U0hIWe9Y6si8XXuuA08Rwuw7k5xDj5yZTF8vV4lWBJ9okwjvbwcEhLDJNU?= =?us-ascii?Q?+bZf0AV6jh56uQmwwTWYN8HUSR5FiS/zw6rYbHMhud/Kd+hpVoon8Iv4EBdk?= =?us-ascii?Q?ByD//BBnHHZc6bC87oPs78bHToIGcoDdUlzFVpC6g4haPM0grWE7A3wWlwKW?= =?us-ascii?Q?JcFlnC8zSjLuD34cbOXbxQjMxrzqRNeiQKjUNxSxE66mVErq4Ty5zrEcZ4Cn?= =?us-ascii?Q?Jp7v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LU?= =?us-ascii?Q?Gu7lzl3ET3cyFMIFDCmTWm9oYs3hR0LcHQAKfvxA?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24256d5e-2c43-4f5a-08b1-08ddf5bb1d11 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB4742.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2025 07:23:35.4063 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XVRpXHmARkNmEzy94q8sWCSRjKk5X2Z/0HJdEb76R87X7ALOnNe0GvqZcxQBka5ND9+yfJBq4Hv/U0xBnTjndw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PS1PPF56C578557 Content-Type: text/plain; charset="utf-8" Extend libbpf to support the new BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE program type, making it available to user space applications through the standard libbpf API. Signed-off-by: Fuyu Zhao --- tools/include/uapi/linux/bpf.h | 2 ++ tools/lib/bpf/bpf.c | 1 + tools/lib/bpf/bpf.h | 3 ++- tools/lib/bpf/libbpf.c | 27 ++++++++++++++++++++++++++- tools/lib/bpf/libbpf.h | 3 ++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 233de8677382..7438836b3e4b 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -1071,6 +1071,7 @@ enum bpf_prog_type { BPF_PROG_TYPE_SK_LOOKUP, BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */ BPF_PROG_TYPE_NETFILTER, + BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE, __MAX_BPF_PROG_TYPE }; =20 @@ -1707,6 +1708,7 @@ union bpf_attr { __u32 prog_fd; __u32 :32; __aligned_u64 cookie; + __aligned_u64 probe_name; } raw_tracepoint; =20 struct { /* anonymous struct for BPF_BTF_LOAD */ diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index ab40dbf9f020..95b73f94ce72 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -1235,6 +1235,7 @@ int bpf_raw_tracepoint_open_opts(int prog_fd, struct = bpf_raw_tp_opts *opts) attr.raw_tracepoint.prog_fd =3D prog_fd; attr.raw_tracepoint.name =3D ptr_to_u64(OPTS_GET(opts, tp_name, NULL)); attr.raw_tracepoint.cookie =3D OPTS_GET(opts, cookie, 0); + attr.raw_tracepoint.probe_name =3D ptr_to_u64(OPTS_GET(opts, probe_name, = NULL)); =20 fd =3D sys_bpf_fd(BPF_RAW_TRACEPOINT_OPEN, &attr, attr_sz); return libbpf_err_errno(fd); diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 7252150e7ad3..0ebedbd99fe5 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -630,9 +630,10 @@ struct bpf_raw_tp_opts { size_t sz; /* size of this struct for forward/backward compatibility */ const char *tp_name; __u64 cookie; + const char *probe_name; size_t :0; }; -#define bpf_raw_tp_opts__last_field cookie +#define bpf_raw_tp_opts__last_field probe_name =20 LIBBPF_API int bpf_raw_tracepoint_open_opts(int prog_fd, struct bpf_raw_tp= _opts *opts); LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd); diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index fe4fc5438678..ce67c917ba59 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9557,6 +9557,8 @@ static const struct bpf_sec_def section_defs[] =3D { SEC_DEF("raw_tp+", RAW_TRACEPOINT, 0, SEC_NONE, attach_raw_tp), SEC_DEF("raw_tracepoint.w+", RAW_TRACEPOINT_WRITABLE, 0, SEC_NONE, attach= _raw_tp), SEC_DEF("raw_tp.w+", RAW_TRACEPOINT_WRITABLE, 0, SEC_NONE, attach_raw_tp= ), + SEC_DEF("raw_tracepoint.o+", RAW_TRACEPOINT_OVERRIDE, 0, SEC_NONE, attach= _raw_tp), + SEC_DEF("raw_tp.o+", RAW_TRACEPOINT_OVERRIDE, 0, SEC_NONE, attach_raw_tp= ), SEC_DEF("tp_btf+", TRACING, BPF_TRACE_RAW_TP, SEC_ATTACH_BTF, attach_tra= ce), SEC_DEF("fentry+", TRACING, BPF_TRACE_FENTRY, SEC_ATTACH_BTF, attach_tra= ce), SEC_DEF("fmod_ret+", TRACING, BPF_MODIFY_RETURN, SEC_ATTACH_BTF, attach_= trace), @@ -12684,6 +12686,7 @@ bpf_program__attach_raw_tracepoint_opts(const struc= t bpf_program *prog, =20 raw_opts.tp_name =3D tp_name; raw_opts.cookie =3D OPTS_GET(opts, cookie, 0); + raw_opts.probe_name =3D OPTS_GET(opts, probe_name, NULL); pfd =3D bpf_raw_tracepoint_open_opts(prog_fd, &raw_opts); if (pfd < 0) { pfd =3D -errno; @@ -12704,14 +12707,18 @@ struct bpf_link *bpf_program__attach_raw_tracepoi= nt(const struct bpf_program *pr =20 static int attach_raw_tp(const struct bpf_program *prog, long cookie, stru= ct bpf_link **link) { + LIBBPF_OPTS(bpf_raw_tracepoint_opts, raw_opts); static const char *const prefixes[] =3D { "raw_tp", "raw_tracepoint", "raw_tp.w", "raw_tracepoint.w", + "raw_tp.o", + "raw_tracepoint.o", }; size_t i; const char *tp_name =3D NULL; + char *dup =3D NULL, *sep =3D NULL; =20 *link =3D NULL; =20 @@ -12739,7 +12746,25 @@ static int attach_raw_tp(const struct bpf_program = *prog, long cookie, struct bpf return -EINVAL; } =20 - *link =3D bpf_program__attach_raw_tracepoint(prog, tp_name); + if (prog->type =3D=3D BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE) { + dup =3D strdup(tp_name); + if (!dup) + return -ENOMEM; + + sep =3D strchr(dup, ':'); + if (!sep) { + free(dup); + return -EINVAL; + } + *sep =3D '\0'; + + tp_name =3D dup; + raw_opts.probe_name =3D sep + 1, + *link =3D bpf_program__attach_raw_tracepoint_opts(prog, tp_name, &raw_op= ts); + free(dup); + } else { + *link =3D bpf_program__attach_raw_tracepoint(prog, tp_name); + } return libbpf_get_error(*link); } =20 diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 2e91148d9b44..f4e9cb819b75 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -820,9 +820,10 @@ bpf_program__attach_tracepoint_opts(const struct bpf_p= rogram *prog, struct bpf_raw_tracepoint_opts { size_t sz; /* size of this struct for forward/backward compatibility */ __u64 cookie; + const char *probe_name; size_t :0; }; -#define bpf_raw_tracepoint_opts__last_field cookie +#define bpf_raw_tracepoint_opts__last_field probe_name =20 LIBBPF_API struct bpf_link * bpf_program__attach_raw_tracepoint(const struct bpf_program *prog, --=20 2.43.0 From nobody Thu Oct 2 11:51:11 2025 Received: from SEYPR02CU001.outbound.protection.outlook.com (mail-koreacentralazon11013026.outbound.protection.outlook.com [40.107.44.26]) (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 962EA2DECBF; Wed, 17 Sep 2025 07:23:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.44.26 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758093824; cv=fail; b=eIduLycVO+MsQN8dr9uvxgRoT1tf1T/eoV+7gR+gcgSdkFbraR/E88dQJapArbmhRgfXXdZTSE5WkGfD9xubeY7nFfDx5ktyDIX3OlBTkIOk9vG+7o096emsDFevZn4Ogbrm/9nsvQzOLH0fM0HBFXzZevFW87ItiC8kneE/nQc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758093824; c=relaxed/simple; bh=7HEDEWOft+vuizNagusAZfyVbE3yFAGDFTkmdqiQLgQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=BNoZ46hak4bf0ZFYsCzxPM6Nbl5gaF69/iwjNOEbTkDOnKM7lMVKqr0EHj1JYF2lozTinKJGSQenP8OmpPhWvqWOXQYY5nKmacbAeYbScj253zOscMSWDhuKysjgL/0XCRQSEb2bd6Gm137avaNTnu2GDmvJqSfti4IHItmQUN4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com; spf=pass smtp.mailfrom=vivo.com; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b=J33KV1OF; arc=fail smtp.client-ip=40.107.44.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="J33KV1OF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rgblTieBaRhKdupOJkhbD4nG1SmOiqPV61emBJAvQhgFQkybut3royHu5dp0tQk1eh/nU/h16fNofd4rrocpSXtjpMRw0B6sKk2J89spAHXoYo76A/fWcBTIDgHmVls9JNP8FCVFbpIhdAAABlN3H6qN/+1IaADEzUh6PAWX6ilWbzF/Sseak8LjRCMJVYS4T1tlCcCz4d2yyIxHhmkfKYXu2a8P3pBPw5VfS2JAw53sCdH0zO2+I6KU+4K918g/h5SANZxvm3Qf8Zh2miJsxlAWE1bHNfhfvltheiXMz2J3vgDt+fQMQFjgBSquWAnqNZyzsQvY/CeZmZqENb37VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eCnN+8NULcSkchjFQQINPlAU8TWJGNxGDWaxpipStTs=; b=KjYlDgl8p6qrivO9u+wFud34/Q6ZCdQ6ack4RT+uM/1EuTRzAm77+H8U0bwcPHpUMaWbzv8pnt7UyEkOwMXGNgfIX1kpttHPU8KBUvy7LApzT/gDZ9rQ+veXRhhUjxTVutOUJOYsva9LVXKC74QeV3tHz8S/QWh7nDP+Rls8OuXJa5oJdx+uHyXIxP3yQ8bk3/F8tqSZTIhlG+kOsMwMI4h9WuqVXwRLlda/9l0kE/TZ/7sXDj4IxkPxYp1zvXmFrxzJhZd790lV02L16KG8bMIuJTXyeC+pn3Tcu4pxa0HntFkusmaozPSIOJc0ybOJBt2a4999RTlZQnmd+8G6uw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eCnN+8NULcSkchjFQQINPlAU8TWJGNxGDWaxpipStTs=; b=J33KV1OFfPmBIO3lI96CnlYIBRWN7WqMcqjZZGBCQfV5LxDBnBNIHQrQb5RRwzTYrsI+5QWs8Ji0EdX6J2g6SUP9QusJWiIgizIqiqYObwBJCgdF1Zx0kNkSd2Ad0FSPvx/47dkY0/XU03Qw8WUT7UgX65/Qj8QsDGHyCx3LKTAzC3eTnBKdN0OyCrWYe//Tq7o3zNn8UCQg9YGMFs+X8+lqEqtCPyWR5bZroihNFEO5g/PIy88LR9cOCz5+pMc+dDsWlCfUZj8vpZr6lM8RGd7mfRemaFq/TYe4xoxrFBwtfeWAxdqRlHYm8q3z8NGcrJbRACHVis3oj+evDT0CfA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from PUZPR06MB4742.apcprd06.prod.outlook.com (2603:1096:301:b5::13) by KL1PR06MB6043.apcprd06.prod.outlook.com (2603:1096:820:d6::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.23; Wed, 17 Sep 2025 07:23:39 +0000 Received: from PUZPR06MB4742.apcprd06.prod.outlook.com ([fe80::206c:c661:9838:5571]) by PUZPR06MB4742.apcprd06.prod.outlook.com ([fe80::206c:c661:9838:5571%4]) with mapi id 15.20.9137.012; Wed, 17 Sep 2025 07:23:39 +0000 From: Fuyu Zhao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, haoluo@google.com, jolsa@kernel.org, eddyz87@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, shuah@kernel.org, willemb@google.com, kerneljasonxing@gmail.com, paul.chaignon@gmail.com, chen.dylane@linux.dev, memxor@gmail.com, martin.kelly@crowdstrike.com, zhaofuyu@vivo.com, ameryhung@gmail.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: yikai.lin@vivo.com Subject: [RFC PATCH bpf-next v1 3/3] selftests/bpf: Add selftest for "raw_tp.o" Date: Wed, 17 Sep 2025 15:22:42 +0800 Message-ID: <20250917072242.674528-4-zhaofuyu@vivo.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250917072242.674528-1-zhaofuyu@vivo.com> References: <20250917072242.674528-1-zhaofuyu@vivo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SI2PR02CA0043.apcprd02.prod.outlook.com (2603:1096:4:196::12) To PUZPR06MB4742.apcprd06.prod.outlook.com (2603:1096:301:b5::13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB4742:EE_|KL1PR06MB6043:EE_ X-MS-Office365-Filtering-Correlation-Id: 44380af7-b878-4122-85af-08ddf5bb1f5d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|52116014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?sGt9VEZlu2G9jKiJSD/eTjqTlkKvxtSLhPR0u1yMTKvEStIIqYzm4tOmHF4t?= =?us-ascii?Q?iG9dgjy5ep07bgEjNV95FOWAD26LPea5Ogkr/iHY0BtlGzZ1uxvSV8Nq8jJ9?= =?us-ascii?Q?SPsOXKfxo6krjfe9qO6vYQcX+DGWSQdKabO63dGWT3sD/AYCifvs+PtTVlv1?= =?us-ascii?Q?CtwOI06f1odO011REi0FyXoONBX4QHeK3yaMxguTCcRU9TENc/Y0ZdQ5rhgb?= =?us-ascii?Q?A9gMIqLjoXSys7pltHH+NRgIgKlaaIhlnuQc0TD6bxPmywX9O4ANy7vIuBxy?= =?us-ascii?Q?nYT1BYNkEdnPvnmISUClztfDGuVerffYWIYCwCKF5f758J3g/ZtXG3jOvPSY?= =?us-ascii?Q?PWo8e8RByAsqH1gU7od10He8gy/iOqZn4AjX+6yWCcRKlfF9US22E/kALhw/?= =?us-ascii?Q?OgrSPe8+tEPJz9hxws23TmFAKBmwnPKVansas3J2Ay/hrseFmD4Hv/mr4Ttm?= =?us-ascii?Q?982TRL1677EdwJJwjHTzhAcmPi8In7sJgvzQcUrVjpzRti++I0M5pdCekZdM?= =?us-ascii?Q?Qf1WYLaHaFoFbRBrQpw/FZ3WWY1z+lkAwvqSujhc0WGKkszIArHKhS3pNO4U?= =?us-ascii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4h9YmF8GJTZFaAnY?= =?us-ascii?Q?EmSumJvl18U9TTg=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR06MB4742.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(7416014)(52116014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?fYd1hdK7+269z+5ZwXkUAHnk85SKFAb6oZa857nSPbaXAkI5dg3Yo0Tj1hgK?= =?us-ascii?Q?PxF9e/urf/RruTkdhLD6hvtsEzHi4u63zgJ+rBZlp2Z6xkBTTHF7dwJ+TYk3?= =?us-ascii?Q?6vwp7XF8MAOHW5DZ9eX5NpuzbS4KTaRbXyDNEwElLWN8L7+X7dSoBHJ8ILxS?= =?us-ascii?Q?R5+Fi5oFJcAFV5lEeGpUNylZ/oELl4W5K5Q10fPXdL8j0riSYt0m9P6kO4uh?= =?us-ascii?Q?Uc3ha1ktQmYMOlmsAUAjJQBJdtZqNTwh9sbYaKxUxJGj46vg2KvIJBVGNt0/?= =?us-ascii?Q?DxRacyZZBNtwm3trVT1QPFIvKo3DylaHRgcwAT6SNbdQ6doi/PVe760yql2P?= =?us-ascii?Q?cKJfkYD23yoxz8LKZZcd9r6uyz5ow3gdquaJ+0Ru6H5doYzsA7JR8vYks3gk?= =?us-ascii?Q?Yc9jLQtlvu2pcOKs8uMh7WT0SrwCvQE3ljKHh9sZpngvgumDhSWhS/aK84mK?= =?us-ascii?Q?9gBsNRB27Aak126K28cCJEzCQBT1hvTcByITfxZrvHy04+XmtK7fRHbiK4ns?= =?us-ascii?Q?p5TUfz+srxC/YRFmENEXk68N8g/NDM8t88HBWuUHx5XYeUwVOi4Ud6m7f9O/?= =?us-ascii?Q?0IBVxrtxAQHEkhDIJavM1DkhwXvrWzmZkL3G36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ascii?Q?g8eKr8rmxdeW2rNXKIIM9x208wAvg9pATMr/8N4VYd6MEpKc7OMASzJKgNdh?= =?us-ascii?Q?9kmasMR7V4BzOCg5sITEfXzGSTAoalCMjPzqRTXw?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44380af7-b878-4122-85af-08ddf5bb1f5d X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB4742.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2025 07:23:39.2251 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: C8H119WNUB33rS3IhyNnaQuW8JfCJ0OAYv9UWI79met2DNhvRQu/j5Do0HwFR4lcxigjEEcpAj1IriTHoPlIdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6043 Content-Type: text/plain; charset="utf-8" Add test for the new BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE program type. This test verifies whether a BPF program can successfully override the target tracepoint probe function. Signed-off-by: Fuyu Zhao --- .../bpf/prog_tests/raw_tp_override_test_run.c | 23 +++++++++++++++++++ .../bpf/progs/test_raw_tp_override_test_run.c | 20 ++++++++++++++++ .../selftests/bpf/test_kmods/bpf_testmod.c | 7 ++++++ 3 files changed, 50 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/raw_tp_override_= test_run.c create mode 100644 tools/testing/selftests/bpf/progs/test_raw_tp_override_= test_run.c diff --git a/tools/testing/selftests/bpf/prog_tests/raw_tp_override_test_ru= n.c b/tools/testing/selftests/bpf/prog_tests/raw_tp_override_test_run.c new file mode 100644 index 000000000000..02301253cd9b --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/raw_tp_override_test_run.c @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include "bpf/libbpf_internal.h" +#include "test_raw_tp_override_test_run.skel.h" + +void test_raw_tp_override_test_run(void) +{ + struct test_raw_tp_override_test_run *skel; + + skel =3D test_raw_tp_override_test_run__open_and_load(); + if (!ASSERT_OK_PTR(skel, "test_raw_tp_override_test_run__open_and_load")) + return; + + if (!ASSERT_OK(test_raw_tp_override_test_run__attach(skel), + "test_raw_tp_override_test_run__attach")) + goto cleanup; + ASSERT_OK(trigger_module_test_write(1), "trigger_write"); + ASSERT_EQ(skel->bss->flag, 1, "check_flag"); + +cleanup: + test_raw_tp_override_test_run__destroy(skel); +} diff --git a/tools/testing/selftests/bpf/progs/test_raw_tp_override_test_ru= n.c b/tools/testing/selftests/bpf/progs/test_raw_tp_override_test_run.c new file mode 100644 index 000000000000..eb6d24e1c737 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_raw_tp_override_test_run.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "vmlinux.h" +#include +#include + +__u32 flag =3D 0; + +/** + * This program overrides raw_tp_override_probe handler in + * tracepoint bpf_testmode_test_raw_tp_null_tp. + */ +SEC("raw_tp.o/bpf_testmod_test_write_bare_tp:raw_tp_override_probe") +int BPF_PROG(tp_override, struct task_struct *task, char *comm) +{ + flag =3D 1; + return 0; +} + +char _license[] SEC("license") =3D "GPL"; diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/t= esting/selftests/bpf/test_kmods/bpf_testmod.c index 2beb9b2fcbd8..7a49178d2343 100644 --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c @@ -1628,6 +1628,11 @@ static struct bpf_testmod_multi_st_ops multi_st_ops_= cfi_stubs =3D { .test_1 =3D bpf_testmod_multi_st_ops__test_1, }; =20 +static void raw_tp_override_probe(void *ignored, struct task_struct *task, + struct bpf_testmod_test_write_ctx *ctx) +{ +} + struct bpf_struct_ops testmod_multi_st_ops =3D { .verifier_ops =3D &bpf_testmod_verifier_ops, .init =3D multi_st_ops_init, @@ -1665,6 +1670,7 @@ static int bpf_testmod_init(void) ret =3D ret ?: register_btf_id_dtor_kfuncs(bpf_testmod_dtors, ARRAY_SIZE(bpf_testmod_dtors), THIS_MODULE); + ret =3D ret ?: register_trace_bpf_testmod_test_write_bare_tp(raw_tp_overr= ide_probe, NULL); if (ret < 0) return ret; if (bpf_fentry_test1(0) < 0) @@ -1701,6 +1707,7 @@ static void bpf_testmod_exit(void) bpf_kfunc_close_sock(); sysfs_remove_bin_file(kernel_kobj, &bin_attr_bpf_testmod_file); unregister_bpf_testmod_uprobe(); + unregister_trace_bpf_testmod_test_write_bare_tp(raw_tp_override_probe, NU= LL); } =20 module_init(bpf_testmod_init); --=20 2.43.0