From nobody Wed Apr 1 22:01:19 2026 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 94E782BDC28 for ; Wed, 1 Apr 2026 14:31:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775053892; cv=none; b=ndzZvek/XFIIMHNUpkkqyCUR0PetdY755Hu/aduw8unUyOXqYZbxMGxU7K8n+zhr0JCvkXeCYow+dERo1mQdryrzwFbO+ZCjeGZPIZnwXjHroj5BPm+soWDOH62aD8QROkisHGU4lYEBnDjekxK4b4ReogAVuT1ZqLVUIogzfXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775053892; c=relaxed/simple; bh=HP2K0MyLrfe+AsyxLn/Wacw/MVV8JD/vRaJarcE84rg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dWwwScdKxeME4dm56fs+c6d5/DstuU9dL+IwJ7GS+vxuDElAqh9H4QSg6McDTpf0CuHBNwO6Bt2OwIWWI4Rw8r4de1L3MiNopme4LsGNbAI8RdihR4wTRBfcbBmRNYKjVCKL5jwsmWDT8ZXwZOiWcP5nQ3n9QvWOxxsYcZjUVto= 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=Flmf45sm; arc=none smtp.client-ip=209.85.218.48 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="Flmf45sm" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-b9910707d82so820475466b.1 for ; Wed, 01 Apr 2026 07:31:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1775053889; x=1775658689; 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=4HxiPrvpqH7118QkqrxrVkR44ZtadZ7EsUhuBxmrRAk=; b=Flmf45sm+lOdm9bnBOqe4ocMoLTZsPdL8Tl6TAkiPkHCh0xNXU0g62hLRCasuuXCvR oKAJXj08FjC4P8/etnQZP+8lJFkpTXa7Q+exKExo/pys3tLelD5zV+2uXEXAu3KvG7E6 2JC3kCy7lqgGo6FsysYyvkxruL5SnbpcFIVgmiMQt9zbWkh3bQ8F91M0NxaXkTyT47RU lKfhFDiUxZAWWxiW36YbCPxtcFZE7qJFu7rfil+Wa6nC4SfSuTKiGPqqWCdKodUjhQcy k7KWgigJWSwjUFAu7omHprbVxLHuVpY/sidSWEutOtS90Zc3qfzidp5w+tQ1UDhLBc6x qyUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775053889; x=1775658689; 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=4HxiPrvpqH7118QkqrxrVkR44ZtadZ7EsUhuBxmrRAk=; b=RfIFNdHEaxs+Msc8JEpARnyg0EONh6JJczchul1bitJhL3ht/04SFlP/b6FFcaEyU/ SCttfPhQStJxCM9WswqcSYAIfYFdyFDsklryz8ilPl5NaUTQ7XhxrWUIKjz7nclvGzVN It8c1oUE4THo1RbshL2kCuOXM3gktxB/d3NOfOQycS30ZHlVzcbuBavbw44MGxalulHH 0PaJazwZb1jNYIsUf+PaSWnXP1lOzm17FqUs+fWs2rwjI0ituddS76bAiMoDFSnIHNv7 DosEF9n7qbPPNiGZf6odi9ktBQ3/velJjkXVhm4m2GDn+EB6vqcYdm8rD7W/PYan75BO TB5A== X-Forwarded-Encrypted: i=1; AJvYcCV6/RA2hy5CRHqOgeALgTk7cMqknJIrb2+pmnW8VpnrL/Y3qUWOSYTAa0oeDQuPcLho3WM+efwD6wUy+pM=@vger.kernel.org X-Gm-Message-State: AOJu0YyXlbtwjsHnAvcTzEgN3WnyfRCLrJJTdb7R90dCy+P9pGS65D7h wD6CXLeaGHIC3onTuN9tD+b+e9D8ifjoN07Qy00YADmAgxU9RZOARUeHbGGPMTFKpwM= X-Gm-Gg: ATEYQzxWACgVsdT9sKA+V93OuTEsOmZMWyRLlL5+CNZ3H6iO2h3UzM5YWrinGz1qpoh vYUyvjNx7WqJT4nvsIl8QIqOMBNgIJ+ByQvQB5tLIdaVnGJPXSU6F6KQ43se77bWEkfsi/aZB73 2hFDOOet4phh4XO8719WhdpjrksN9XEadMcIV6rZPrnzgPTGKvNf0NaC+3XouvpQ1kfEeycc2rh hgvonTOmJfOQciCS8BCwicCqDXAqnZ9IXoUdACws+cJDOF5fBTsu2C97zs54YsppeQSeZYS/FLT nSy2gO3YSow4OlByrczhx0pDZYbEJwHQOH/phH9TVPbGlwBZyzxmryZe2v8DsJk0dObRh8e3929 z1m2stFzoJxRLwEoxGALzFDf5PSFV4Un7H1aMEeNE0QIvmIxvNtpLHxQd5KTb4uXS21Su7OAE0n Qq5RNH/lurUrrFtFMsBG6cK4wF7weykX+N0lSiih/qeZaw6RDxRAwtrSUV9kDkxQ== X-Received: by 2002:a17:907:e105:b0:b98:4b8:1046 with SMTP id a640c23a62f3a-b9c13af90bfmr196794166b.31.1775053888733; Wed, 01 Apr 2026 07:31:28 -0700 (PDT) Received: from f16.localdomain ([121.167.230.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b2427658e4sm199047295ad.48.2026.04.01.07.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 07:31:27 -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 v7 2/3] libbpf: clarify raw-address single kprobe attach behavior Date: Wed, 1 Apr 2026 23:29:30 +0900 Message-ID: <20260401143116.185049-3-hoyeon.lee@suse.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260401143116.185049-1-hoyeon.lee@suse.com> References: <20260401143116.185049-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 non-legacy behavior. For PMU-based attach, callers can use func_name =3D NULL with an absolute address in offset as the raw-address form. For legacy tracefs/debugfs kprobes, reject this form explicitly. Signed-off-by: Hoyeon Lee Acked-by: Jiri Olsa --- tools/lib/bpf/libbpf.c | 14 ++++++++------ tools/lib/bpf/libbpf.h | 27 ++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 536c19c14d21..ebb965230bb4 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, @@ -11836,20 +11838,20 @@ bpf_program__attach_kprobe_opts(const struct bpf_= program *prog, } if (pfd < 0) { err =3D pfd; - pr_warn("prog '%s': failed to create %s '%s+0x%zx' perf event: %s\n", + 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..bba4e8464396 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,36 @@ 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. Raw-address attach + * is supported with PROBE_ATTACH_MODE_PERF and PROBE_ATTACH_MODE_LINK. + * @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