From nobody Wed Apr 1 10:32:04 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77DF237FF66 for ; Wed, 1 Apr 2026 05:25:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775021157; cv=none; b=M4zTqyz5a6E067EYSo439e8JVBGbsBPHq/R2qpWqdNv9ahzBdFKn4esvXlABPA/V6fLmB8v0PtGi7fncw3WPW+kYqJPaS81rask34dJF5FbfIDwDLxR/BZaUn87A0kOfvlZGETsNh9tkXJhytjI/n1kGlfasWbCmMJVwSSrIBWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775021157; c=relaxed/simple; bh=qmeQHRkGzK4lii5ZAyRn9mbpws0lEvcKha0BrFEw8H4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kPMTWfA+kApFZTPltxP8mk3UbvQRKGJoiG/PP1mv5KPfT/BoAGKuw4hUQuTWvZLIEwncLLiFyyPn0D1wZA5Ur9uLGjLgC2YyoooROvHD4NFGdn91TU+57XH+lxNbjRPrbnGq1aGUWULuzYDQO2NDcDMLtkH+NaRWP2Yoj0pQybY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Y5fUQ68p; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Y5fUQ68p" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4853c1ca73aso66200675e9.2 for ; Tue, 31 Mar 2026 22:25:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1775021154; x=1775625954; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=agD2j9lHJEiH0O0fE306beCiWzd2jKbZSkmxgbBvFK8=; b=Y5fUQ68p7FTx4FgxBYQq2M0MpOq4AIxi42KmcWYRnOFJO9pSENMSWW3LYsT2GdiOj7 8OxhB5ggvxUVMyF8uu7dRK1ZvZtKlrBHR0q4rwrsHC5IwQSg1Rn0wXVgkHAkJIq3C1zR ZBC6MOXu3C4cwSImYnVnh++Xln7PxJ93TYsPr1DePLpBsATGakuzAxnxuVBKGPHLdjK+ 7x5/zYJQJB35iovFcLqZvUo7W7zxsAKlwLuxVrbuRXMj9n8EdOb7ePIOgD5CLtTDnDnX SGreWq4Z7cKpXPoGvVbCqXBu2nA8ifwPv9dD5rc3LimrxeNem4yZiYDfJyINqODeG3f+ UtYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775021154; x=1775625954; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=agD2j9lHJEiH0O0fE306beCiWzd2jKbZSkmxgbBvFK8=; b=pQxbPbqOmQWkdtbzTf4KpHhZpp+IcLX2rAOMpw/HteH5no6QvqI3zeda8nJqw7jiGH zQweS7WNNoU4k7ZDV5UnQmRasN9QCsiCv7/SYifuJggqb14PxOMDJp9nwrnhkZfXk9Dz 8uQv3Bi/ij7Kd2mDWENgQuKTm2P9ISVaH0qHmhsz9t35qnnADhAY5AzmaI7XLXfl42v5 TBwt41frdDWWRJO9euGhg8Yu5yTtoljTanK95Ue8vbJTWuthBx1cKG9kvA1NrGv0N8vc fTpzqwMBINbblfRNIhPh3gaUX5blI3PozpiYK2ZjxZwCfSuXtIso/fXbH8hWiGxUnpba YJpg== X-Forwarded-Encrypted: i=1; AJvYcCWb+XHgk9DYDZm9u9Tpmt+yPiF6HS7f25nh9lbWDWUOxSKRt03XOvWWMOUP+eFGwbi4IWFzsHFzDZziB2A=@vger.kernel.org X-Gm-Message-State: AOJu0Yxn/Wq/oRxTBAkHyzCeEGoCYib8FhQ3/Or6woeIfizQfYz+HUdG LTO9FVWIekGfqn15N1vs/bKGz18kBiLLe1zKI4/x0Tr7bCZ9NiabYRiIEbZvICwTLYM= X-Gm-Gg: ATEYQzwazpfL6v6kxa0sQqP36nX3/xZpn1QcXS9dXxFgGKwjNczdfzKiwc5ZjZQ2h4j C7aoZlp+2OvzkAF4O9jEsvo7FqjyKLsixg7U4G1J6CpLbV1KuhafV1MdC11E/PTFrap77wu8vSH wkuRhv8zwMtPhlbKPqmP6VF2rX+/FH9kixOR/Xvtg+5sQCRWV6lSarszZ38GHJ9jwjbu0WNcqSf FcHk/JBXxnKU3/YGBOTnOvFkrb6CsvGECNd0m4B1kGJ1IQ7ZrmrZtM8Em4d2dNm2LFOdB7Bdu/I kqXR+MqMPSrvEm3DWSeH1dJCUZqgrGOAxTt6Z9D+j+q2ie3acMRlRbr4CyN5g5GGPPsbH/LnfFn mIVChZLMOlISr/IiawGjwU+SISFG/YSk0JZakmuQDB4ZhAzkpjf+f40V1kMU8u/VLwsnrl0pyxp Ly5O4TKv9qYxdXv7uHMqZNWUE+JcfbpIpFTTLyNDB51cfse5YWGyb1NSRGNn8k4Q== X-Received: by 2002:a05:600c:3ba5:b0:471:700:f281 with SMTP id 5b1f17b1804b1-4888359db41mr30178075e9.25.1775021153781; Tue, 31 Mar 2026 22:25:53 -0700 (PDT) Received: from f16.localdomain ([121.167.230.140]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82ca843b818sm15308214b3a.6.2026.03.31.22.25.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2026 22:25:52 -0700 (PDT) From: Hoyeon Lee To: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau Cc: Eduard Zingerman , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , Shuah Khan , Feng Yang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v5 1/2] libbpf: clarify raw-address single kprobe attach behavior Date: Wed, 1 Apr 2026 14:25:10 +0900 Message-ID: <20260401052544.100968-2-hoyeon.lee@suse.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260401052544.100968-1-hoyeon.lee@suse.com> References: <20260401052544.100968-1-hoyeon.lee@suse.com> 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" bpf_program__attach_kprobe_opts() documents single-kprobe attach through func_name, with an optional offset. For the PMU-based path, func_name =3D NULL with an absolute address in offset already works as well, but that is not described in the API. This commit clarifies this existing behavior by documenting it in bpf_program__attach_kprobe() and bpf_program__attach_kprobe_opts(), and rejecting this form explicitly for legacy tracefs/debugfs kprobes. Signed-off-by: Hoyeon Lee --- tools/lib/bpf/libbpf.c | 16 +++++++++------- tools/lib/bpf/libbpf.h | 29 ++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 9ea41f40dc82..b27832ff6051 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -11816,6 +11816,8 @@ bpf_program__attach_kprobe_opts(const struct bpf_pr= ogram *prog, default: return libbpf_err_ptr(-EINVAL); } + if (!func_name && legacy) + return libbpf_err_ptr(-EOPNOTSUPP); =20 if (!legacy) { pfd =3D perf_event_open_probe(false /* uprobe */, retprobe, @@ -11835,21 +11837,21 @@ bpf_program__attach_kprobe_opts(const struct bpf_= program *prog, offset, -1 /* pid */); } if (pfd < 0) { - err =3D -errno; - pr_warn("prog '%s': failed to create %s '%s+0x%zx' perf event: %s\n", + err =3D pfd; + pr_warn("prog '%s': failed to create %s '%s%s0x%zx' perf event: %s\n", prog->name, retprobe ? "kretprobe" : "kprobe", - func_name, offset, - errstr(err)); + func_name ?: "", func_name ? "+" : "", + offset, errstr(err)); goto err_out; } link =3D bpf_program__attach_perf_event_opts(prog, pfd, &pe_opts); err =3D libbpf_get_error(link); if (err) { close(pfd); - pr_warn("prog '%s': failed to attach to %s '%s+0x%zx': %s\n", + pr_warn("prog '%s': failed to attach to %s '%s%s0x%zx': %s\n", prog->name, retprobe ? "kretprobe" : "kprobe", - func_name, offset, - errstr(err)); + func_name ?: "", func_name ? "+" : "", + offset, errstr(err)); goto err_clean_legacy; } if (legacy) { diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 0be34852350f..f691f05aa68c 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -557,7 +557,7 @@ struct bpf_kprobe_opts { size_t sz; /* custom user-provided value fetchable through bpf_get_attach_cookie() */ __u64 bpf_cookie; - /* function's offset to install kprobe to */ + /* function offset, or raw address if func_name =3D=3D NULL */ size_t offset; /* kprobe is return probe */ bool retprobe; @@ -565,11 +565,38 @@ struct bpf_kprobe_opts { enum probe_attach_mode attach_mode; size_t :0; }; + #define bpf_kprobe_opts__last_field attach_mode =20 +/** + * @brief **bpf_program__attach_kprobe()** attaches a BPF program to a + * kernel function entry or return. + * + * @param prog BPF program to attach + * @param retprobe Attach to function return + * @param func_name Name of the kernel function to attach to + * @return Reference to the newly created BPF link; or NULL is returned on + * error, error code is stored in errno + */ LIBBPF_API struct bpf_link * bpf_program__attach_kprobe(const struct bpf_program *prog, bool retprobe, const char *func_name); + +/** + * @brief **bpf_program__attach_kprobe_opts()** is just like + * bpf_program__attach_kprobe() except with an options struct + * for various configurations. + * + * @param prog BPF program to attach + * @param func_name Name of the kernel function to attach to. If NULL, + * opts->offset is treated as a raw kernel address. This form is + * supported with PROBE_ATTACH_MODE_PERF and PROBE_ATTACH_MODE_LINK, + * and can fail with PROBE_ATTACH_MODE_DEFAULT if libbpf falls back to + * legacy attach. + * @param opts Options for altering program attachment + * @return Reference to the newly created BPF link; or NULL is returned on + * error, error code is stored in errno + */ LIBBPF_API struct bpf_link * bpf_program__attach_kprobe_opts(const struct bpf_program *prog, const char *func_name, --=20 2.52.0