From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 4F7CE3E5EE8 for ; Wed, 1 Apr 2026 10:18:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775038725; cv=none; b=W1Lgmn4c9sX4OBZISrlbqC6MZU21w6z2CVZ6jaXsJLXmqBKOadg7tCEBABOI8hbt8WosVz/sluab2dXe46sWQDSykkjl8mrVWOh4XVoRvxvKi2TgFaM6Wt/mAg3vSZWhNRwhiFjWJPUE8LN/+v5oiFzhZZ44RU9uXxsM/nOMrR8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775038725; c=relaxed/simple; bh=EyjYid29bAhw9hm/p8J3Ub+EF1bcpIqDrqHLvERCp1E=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mKhWoIHcWscAw1kEREmzGRyyRkDKhq57TkBhoD+uOT65Hrnpa29ZcyPdLMd6Eu1DrGi9oeihTRNshGoYvjHLjD4RiimnJSTkxw/P8pSLbpBoqouUmIyabI5UJVyWt0ywjgvCBsn0iBhcxP8w12+cqsSdFCUpGznZiNn1h9GDwe0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IlC015rD; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IlC015rD" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4853c1ca73aso69459155e9.2 for ; Wed, 01 Apr 2026 03:18:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775038711; x=1775643511; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=7LdBImJvw09LuSxdczLfZcSvTflB+c8zMehtT9Cz5Bw=; b=IlC015rDCB1h4EE0sOeTzCnjUMxck6NDppiAktoSh0bS4MOY4jT+qxtM6EOpqfVFxS uT9XDSD+YGP+GJiHHhPorNoLuT/M8BfTOStzAfrXtksxbSgmIwwfR9Wnb5vuxF0HafX5 cNPhd4xqD7FZAdLfZY00/oFRwHBB84+pKaoXuQVz5BNoU/8QY3O/0nB5lsogiAPT7/aw wRi15JIkkUJvcke1L0Zh1sSsuHrwLR+5MEHDigonECWS/a6qAUiDtNRrNE8WEAflHGDw lsnSE3xxS19tFX/GnIvIOAzLVFa+6NIuWLyMpcSOMLyqom++6M1ANcBv04iWXOUkJlb4 nnbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775038711; x=1775643511; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7LdBImJvw09LuSxdczLfZcSvTflB+c8zMehtT9Cz5Bw=; b=U8+D5usEJA5vbn3X1/higonYePESuQ0/ct4wRifwJN7JqrZkYbbHoAHHZRvbKMEyxv EdiCL7DkVNyS5CQQkZhgMIr662b9KxngDEy5cUsP92nnLGeWth4z+st3v417iFOZrH6p OvjD5V0UmS1Wd+NkUbSD6e/u9rHZ/njDxs/+QwYT1FKUxcbtS2uU3iB53oBIAxiij1am KyVTMHSGjSViEU3kL34npggaDX2oN2gRuL8eY6J9UwaDa43uoV7SoiGpW15yOGkhllff Hqb/KiKV1FwbGfE0TUzAYABy1QJr5qppTilQ9biNAGCumG+TX0QqIUtIHipE6TMcsvdn G3Zw== X-Forwarded-Encrypted: i=1; AJvYcCVYSYlYW0plUX6rlfr8yGHXTHqc3Cek+ABCKibDu046GqUkgPl/kJTaqqPWg33QEwmVaECs6JUoEAACXYk=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+3XTbVNefAY+4OIcYrvGsn9plEi5Grx5s5v5WyMejWHCuTvM+ kFvsttTfmfXrJwojSH4TTUHmEL8WT6M4y5T5v/EaK9QZdxMNseeAWBty X-Gm-Gg: ATEYQzwePKDbqW82V65qkO+2zGNYDLKfww1fmylo/Mf9AI+I+JTIsWpwaez0p0idaq3 Ydk374XHnxOL5bweFpDZJSqrcLW53Lmr2C9vuefC+KbWyvxGZzZc9K/GphMNDEvXJRlYaQ0Wm3Y C9M2VprT6bQKeWCFkMEPGKD05mMtXRCthuRQv0Igkp0+4fy2ODTqdBXAx7ryKDZ/6DxAdZM3VIi vqWrGT8GmWNpQJ+JTQqYFO7qMhkni+5vl7pvPWHBtWU9/xzGLPqBFYffDaf9FtBw9n6VKBcg91B PpxWOM7gMrsvCwuWX3GGt6dVgTRSdn08z8hLJdXXmnnlvYs1mYmIvepolyHdgsv+0u7mpH9Sx4C G+KD02CssCgKtmO2JauoBfpdEuD4rDeAjR/wA/96rJQR3KQc+qM2atB97ooYIk2vxWS+3vroa X-Received: by 2002:a05:600c:3516:b0:480:690e:f14a with SMTP id 5b1f17b1804b1-48883597ccdmr44164355e9.14.1775038711170; Wed, 01 Apr 2026 03:18:31 -0700 (PDT) Received: from krava ([2a02:8308:a00c:e200::d99c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4887e884dacsm150889635e9.15.2026.04.01.03.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 03:18:30 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Wed, 1 Apr 2026 12:18:29 +0200 To: Hoyeon Lee Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Shuah Khan , Feng Yang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH bpf-next v6 2/3] libbpf: clarify raw-address single kprobe attach behavior Message-ID: References: <20260401070738.122709-1-hoyeon.lee@suse.com> <20260401070738.122709-3-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260401070738.122709-3-hoyeon.lee@suse.com> On Wed, Apr 01, 2026 at 04:05:03PM +0900, Hoyeon Lee wrote: > bpf_program__attach_kprobe_opts() documents single-kprobe attach > through func_name, with an optional offset. For the PMU-based path, > func_name = 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 = 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 jirka > --- > 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_program *prog, > default: > return libbpf_err_ptr(-EINVAL); > } > + if (!func_name && legacy) > + return libbpf_err_ptr(-EOPNOTSUPP); > > if (!legacy) { > pfd = 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 = 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 = bpf_program__attach_perf_event_opts(prog, pfd, &pe_opts); > err = 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 == 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 > > +/** > + * @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, > -- > 2.52.0 >