From nobody Thu Apr 2 19:00:05 2026 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 8AA4820298D for ; Thu, 12 Feb 2026 15:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770909651; cv=none; b=QuUwl4ugSHV9ZoPrHo8fILDhi6AGg8hskkRVe7dEJPk0ckmcXV6i9R8RU96me3cIRl4HrRmLMC6224GqlK6J+HBSpjlctyXHduIOZywgztkrE+ZIQ5+ycOZBjA0mJB580wjgiROt8SFUvcn5R1TiaOKY1R3db6N3nDWuYtptV7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770909651; c=relaxed/simple; bh=y3/Zft9RtaunwArVFlLk1lfDfG9fKjc0Fa8tLxaFbqc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WHAAagKwyehfvcf0rd6HbxvEdA8PN0ewACmFZpHAjQuAdq0Nd59KxU12efNpHBDQzeBOXutz1aLpzsCXUMMfsE2MWqk+23M++M0miaRR65AGgxaUcsCYWMO1qmXCFJKDfj/nenjCS3kL6u3tOo9n9CBO1W/uFFswyxhyB+wx/2I= 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=Z0/tUw18; arc=none smtp.client-ip=209.85.214.174 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="Z0/tUw18" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2a79ded11a2so21442595ad.3 for ; Thu, 12 Feb 2026 07:20:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770909649; x=1771514449; 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=UDwv8yNiuDH+se7b+twM3cODmLXHz04TBPbHtHsRt58=; b=Z0/tUw187YdNXiZFHp/BkSCxh/HEWqla2ifS/+6fcP4WcDwPE6b4tgzdRX1gzzZ+eJ VQ9b0LqBXZ2+iV7imD7SltiHEATtmZTr6yFPU59HvQgoYPi8W+1+a0A7Ltnpyy2Xe9h8 JFBKoXoaqhBvV9cC6pnPsiFyBkzu45A2gPtA2t8giyOZXDlmKJsPYNbwIFM8QILWTsC1 /ckL3fejKYoA/E3Nxpmz7DKv7lh/8iApwFB/VxGGZV60YmalXw0f2d+UOcbkLFf0Tidy 6KW9e4EX3YwuhYvnKYz2Y6JD+sgjht2XF7vMJcCBaRMXnzXKQAnutLZNZ+GVzxY9Yfx9 tI8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770909649; x=1771514449; 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=UDwv8yNiuDH+se7b+twM3cODmLXHz04TBPbHtHsRt58=; b=JYgxv2lYKHDSr0lFUJ6HTm8VsAd0LTVPAnOL0CQym9gKIBfhoHZ2SIDVa3s9LsBGil spWa9GiGn/Lp/qhTgQT8I+SwS/nzX1HTrGcnhSkmyZu78ByHUJkv+Zg5x/r/rAesBCuA y6loyYXa0bZXf+tAwdtWNG4DIasyTBFFdMIqC7Z/eTI/Y3EnFWdrVluAQAG02AMMlFpj gKlh5jGgarl0GGu8vpnJ9cdPA8MO+SKKLeV4bHdoouxkajwKn/ldE43fvinqdEAozLk1 VAh9GV2ltHZWOYgWHPXZ9Uxf4By3ozuyeQmAg+qxublsdp42M1wqoMIfAVn2cJsYstF6 61NQ== X-Forwarded-Encrypted: i=1; AJvYcCUI+qbMHNjidC60Ac047m2k6pchM7L3qD2bpxPhlPTEo+Lxv5HVW/W45zreUnwjZ0/VRXLTuAmtSqVwJaI=@vger.kernel.org X-Gm-Message-State: AOJu0Yyy241NEUDFfJ26aD/s9ixWvG64bjvt5ubwu9pSGOc5kQKIBuDo 3mXscGo55iCPDuX0QITIFSVnf7UKb1bzN0CcCqr2LJADhj/IuXahs3xx X-Gm-Gg: AZuq6aKG8GaJBBpkGg++ngwn+nSY1nrJSWqHZ7NkX/LlzdUsMQz0bArkwUzorgwS6ke lo1MuDQW5F0YFrnu04xMS+kjCE7a+sckbg9C9Z1VCE6kqTWc0iVpoyIoUNJqiNEufFfByIXEXO4 t88zx6qoExirQflKabV9XMOwkQdupdJAAlBzW/N4fxJ9A1TjYm1osAYnEZxDcPnoDasxRatNjot kQx3AgTZtzlOlxxPbCM3Kmbzt+nMt8/GL7ghRFabm1QRU2KhbDyrkJhitoqNO6JQ8ZOZsQ5vkEq TQxOjsFbGyukWNP/OyvtiUYhHM3tyAXQMG4EMAjD9xm/ASreEe+OhpGsZXjI7lGA2+Xec085KyF NXMZx2S7QY6aEK9gy5tKCq3GB80tkjV2axmUhLs5JCRjsCG426m4LoiHnun53rC8iBHVrBBcquJ zpPfnpqTXKrREj4jebCPz/eD9w01ew/xWgHKlSYzTNgKvR3qnmPtN5mAqGmbSlOOm+G2w= X-Received: by 2002:a17:902:ce0e:b0:2a5:8c1c:744f with SMTP id d9443c01a7336-2ab3b258fbemr28127615ad.40.1770909648756; Thu, 12 Feb 2026 07:20:48 -0800 (PST) Received: from computer.goose-salary.ts.net ([2a09:bac5:40b4:a82::10c:60]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ab2984ad4asm55943795ad.6.2026.02.12.07.20.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 07:20:48 -0800 (PST) From: Varun R Mallya To: andrii@kernel.org, alan.maguire@oracle.com Cc: ast@kernel.org, daniel@iogearbox.net, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, varunrmallya@gmail.com Subject: [RFC PATCH bpf-next 1/1] libbpf: Auto-upgrade uprobes to multi-uprobes when supported Date: Thu, 12 Feb 2026 20:50:13 +0530 Message-ID: <20260212152013.17351-2-varunrmallya@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260212152013.17351-1-varunrmallya@gmail.com> References: <20260212152013.17351-1-varunrmallya@gmail.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" This patch modifies libbpf to automatically "upgrade" standard SEC("uprobe") and SEC("uretprobe") programs to use the multi-uprobe infrastructure (BPF_TRACE_UPROBE_MULTI) at load time if the kernel supports it, making them compatible with BPF tokens. To maintain backward compatibility and handle rare cases where singular uprobes are required, new SEC("uprobe.single") and SEC("uretprobe.single") section types are introduced. These force libbpf to use the legacy perf_event_open() attachment path. Signed-off-by: Varun R Mallya --- tools/lib/bpf/libbpf.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 0c8bf0b5cce4..a32f221d3245 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -8265,6 +8265,22 @@ static int bpf_object_init_progs(struct bpf_object *= obj, const struct bpf_object prog->type =3D prog->sec_def->prog_type; prog->expected_attach_type =3D prog->sec_def->expected_attach_type; =20 + /* set BPF_TRACE_UPROBE_MULTI if sec_name matches "u[ret]probe" + * otherwise, leave alone. + */ + if (kernel_supports(obj, FEAT_UPROBE_MULTI_LINK)) { + char *probe_type =3D NULL; + int n; + + n =3D sscanf(prog->sec_name, "%m[^/]", &probe_type); + if (n >=3D 1) + if (!strcmp(probe_type, "uprobe") || + !strcmp(probe_type, "uretprobe")) + prog->expected_attach_type =3D BPF_TRACE_UPROBE_MULTI; + + free(probe_type); + } + /* sec_def can have custom callback which should be called * after bpf_program is initialized to adjust its properties */ @@ -9822,9 +9838,11 @@ static const struct bpf_sec_def section_defs[] =3D { SEC_DEF("kprobe+", KPROBE, 0, SEC_NONE, attach_kprobe), SEC_DEF("uprobe+", KPROBE, 0, SEC_NONE, attach_uprobe), SEC_DEF("uprobe.s+", KPROBE, 0, SEC_SLEEPABLE, attach_uprobe), + SEC_DEF("uprobe.single+", KPROBE, 0, SEC_NONE, attach_uprobe), SEC_DEF("kretprobe+", KPROBE, 0, SEC_NONE, attach_kprobe), SEC_DEF("uretprobe+", KPROBE, 0, SEC_NONE, attach_uprobe), SEC_DEF("uretprobe.s+", KPROBE, 0, SEC_SLEEPABLE, attach_uprobe), + SEC_DEF("uretprobe.single+", KPROBE, 0, SEC_NONE, attach_uprobe), SEC_DEF("kprobe.multi+", KPROBE, BPF_TRACE_KPROBE_MULTI, SEC_NONE, attach= _kprobe_multi), SEC_DEF("kretprobe.multi+", KPROBE, BPF_TRACE_KPROBE_MULTI, SEC_NONE, att= ach_kprobe_multi), SEC_DEF("kprobe.session+", KPROBE, BPF_TRACE_KPROBE_SESSION, SEC_NONE, at= tach_kprobe_session), @@ -12722,10 +12740,10 @@ bpf_program__attach_uprobe_opts(const struct bpf_= program *prog, pid_t pid, */ static int attach_uprobe(const struct bpf_program *prog, long cookie, stru= ct bpf_link **link) { - DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, opts); char *probe_type =3D NULL, *binary_path =3D NULL, *func_name =3D NULL, *f= unc_off; int n, c, ret =3D -EINVAL; long offset =3D 0; + bool is_retprobe; =20 *link =3D NULL; =20 @@ -12752,15 +12770,27 @@ static int attach_uprobe(const struct bpf_program= *prog, long cookie, struct bpf else offset =3D 0; } - opts.retprobe =3D strcmp(probe_type, "uretprobe") =3D=3D 0 || - strcmp(probe_type, "uretprobe.s") =3D=3D 0; - if (opts.retprobe && offset !=3D 0) { + is_retprobe =3D strcmp(probe_type, "uretprobe") =3D=3D 0 || + strcmp(probe_type, "uretprobe.s") =3D=3D 0; + if (is_retprobe && offset !=3D 0) { pr_warn("prog '%s': uretprobes do not support offset specification\n", prog->name); break; } - opts.func_name =3D func_name; - *link =3D bpf_program__attach_uprobe_opts(prog, -1, binary_path, offset,= &opts); + if (prog->expected_attach_type =3D=3D BPF_TRACE_UPROBE_MULTI) { + DECLARE_LIBBPF_OPTS(bpf_uprobe_multi_opts, opts); + + opts.retprobe =3D is_retprobe; + *link =3D bpf_program__attach_uprobe_multi(prog, -1, binary_path, + func_name, &opts); + } else { + DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, opts); + + opts.retprobe =3D is_retprobe; + opts.func_name =3D func_name; + *link =3D bpf_program__attach_uprobe_opts(prog, -1, binary_path, + offset, &opts); + } ret =3D libbpf_get_error(*link); break; default: --=20 2.52.0