🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #5035

[PATCH bpf-next v2 5/6] libbpf: Add bpf_link_create_log API

#5035
From: Leon Hwang
Date: Mon, 19 Oct 2026 15:36
144 lines
13973 bytes
Add a new API to accept the log opts, instead of extending the existing
struct bpf_link_create_opts.

Appending log_opts to struct bpf_link_create_opts would place them after
attach-type-specific fields of varying sizes, making it difficult to
extend the struct while preserving forward compatibility.

For example, adding log_opts would prevent extending uprobe_multi
directly with a new build_id field. Instead, a separate union would
be needed:

struct bpf_link_create_opts {
        /* ... */
        union {
                /* ... */
                struct {
                        /* ... */
                        __u32 path_fd;
                } uprobe_multi;
        };
        struct bpf_log_opts *log_opts;
        union {
                struct {
                        __u64 build_id;
                } uprobe_multi_ext;
        };
        size_t :0;
};

Without log_opts, build_id could be added directly to uprobe_multi:

struct bpf_link_create_opts {
        /* ... */
        union {
                /* ... */
                struct {
                        /* ... */
                        __u32 path_fd;
                        __u64 build_id;
                } uprobe_multi;
        };
        size_t :0;
};

Introduce bpf_link_create_log() to accept struct bpf_log_opts separately,
preserving the forward compatibility of struct bpf_link_create_opts.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
 tools/lib/bpf/bpf.c      | 28 ++++++++++++++++++++++++----
 tools/lib/bpf/bpf.h      |  5 +++++
 tools/lib/bpf/libbpf.map |  2 ++
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 9a2107d4f6d8..263a1d516a02 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -788,9 +788,10 @@ int bpf_prog_detach2(int prog_fd, int target_fd, enum bpf_attach_type type)
 	return bpf_prog_detach_opts(prog_fd, target_fd, type, NULL);
 }
 
-int bpf_link_create(int prog_fd, int target_fd,
-		    enum bpf_attach_type attach_type,
-		    const struct bpf_link_create_opts *opts)
+static int __bpf_link_create(int prog_fd, int target_fd,
+			     enum bpf_attach_type attach_type,
+			     const struct bpf_link_create_opts *opts,
+			     struct bpf_log_opts *log_opts)
 {
 	const size_t attr_sz = offsetofend(union bpf_attr, link_create);
 	__u32 target_btf_id, iter_info_len, relative_id;
@@ -965,7 +966,7 @@ int bpf_link_create(int prog_fd, int target_fd,
 		break;
 	}
 proceed:
-	fd = sys_bpf_fd(BPF_LINK_CREATE, &attr, attr_sz);
+	fd = __sys_bpf_fd(&attr, attr_sz, BPF_LINK_CREATE, log_opts);
 	if (fd >= 0)
 		return fd;
 	/* we'll get EINVAL if LINK_CREATE doesn't support attaching fentry
@@ -975,6 +976,10 @@ int bpf_link_create(int prog_fd, int target_fd,
 	if (err != -EINVAL)
 		return libbpf_err(err);
 
+	/* bpf_raw_tracepoint_open() does not support log_opts */
+	if (log_opts)
+		return libbpf_err(err);
+
 	/* if user used features not supported by
 	 * BPF_RAW_TRACEPOINT_OPEN command, then just give up immediately
 	 */
@@ -999,6 +1004,21 @@ int bpf_link_create(int prog_fd, int target_fd,
 	}
 }
 
+int bpf_link_create(int prog_fd, int target_fd,
+		    enum bpf_attach_type attach_type,
+		    const struct bpf_link_create_opts *opts)
+{
+	return __bpf_link_create(prog_fd, target_fd, attach_type, opts, NULL);
+}
+
+int bpf_link_create_log(int prog_fd, int target_fd,
+			enum bpf_attach_type attach_type,
+			const struct bpf_link_create_opts *opts,
+			struct bpf_log_opts *log_opts)
+{
+	return __bpf_link_create(prog_fd, target_fd, attach_type, opts, log_opts);
+}
+
 int bpf_link_detach(int link_fd)
 {
 	const size_t attr_sz = offsetofend(union bpf_attr, link_detach);
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 826d9cc9ab65..dedaf8086902 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -484,6 +484,11 @@ LIBBPF_API int bpf_link_create(int prog_fd, int target_fd,
 			       enum bpf_attach_type attach_type,
 			       const struct bpf_link_create_opts *opts);
 
+LIBBPF_API int bpf_link_create_log(int prog_fd, int target_fd,
+				   enum bpf_attach_type attach_type,
+				   const struct bpf_link_create_opts *opts,
+				   struct bpf_log_opts *log_opts);
+
 LIBBPF_API int bpf_link_detach(int link_fd);
 
 struct bpf_link_update_opts {
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index eeba4072a5da..f6eb57151f7d 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -475,4 +475,6 @@ LIBBPF_1.8.0 {
 } LIBBPF_1.7.0;
 
 LIBBPF_1.9.0 {
+	global:
+		bpf_link_create_log;
 } LIBBPF_1.8.0;
-- 
2.55.0
Technical Details
Message-ID: <20261019153628.15912-6-leon.hwang@linux.dev>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348679-linux-kernel-netdev=dewy.ru
References: <20261019153628.15912-1-leon.hwang@linux.dev>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348679-linux-kernel-netdev=dewy.ru
From: leon.hwang@linux.dev (Leon Hwang)
Newsgroups: linux.kernel.netdev
Subject: [PATCH bpf-next v2 5/6] libbpf: Add bpf_link_create_log API
Date: Mon, 19 Oct 2026 23:36:27 +0800
Organization: Usenet Network
Message-ID: <20261019153628.15912-6-leon.hwang@linux.dev>
References: <20261019153628.15912-1-leon.hwang@linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3669898"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:NQ6oKqIeC3H64YK4smYDWfb/FIE= sha256:wY51jZM8TPlTbCq4Tvk03416uy6KPGBrLrLcJlwy1Zg=
	sha1:kFwDUkRaTaNFoLoCGmTHjjlQm90= sha256:dD/3tn7DNNNpYG34Qs8qnT/AQQg3isWxvMNo00lbv4o=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 51887110A90; Mon, 19 Oct 2026 20:44:17 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 9WQPbPjXNLks;
	Mon, 19 Oct 2026 20:44:14 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-348679-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 04FCB110A3D; Mon, 19 Oct 2026 20:44:06 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (aws-us-west-2-korg-listserv-alma10-1.taild15c8.ts.net [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 98C8A18455B; Mon, 19 Oct 2026 15:55:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792424258;
	b=0WvLMv2zVycEO7/bhNBlkNrOeXziv0aaJIPrYmBEzm6PEMN5pZWWNTZPVbZIV3j9tw/Y
	 XGjeKBdMIHtbfnmwq/3ImhHs9n/XjbITAPpj0XJpQ8K7UT6rmjEMp4ChNiGdAdmLDgD7c
	 GCw1SNSpYLX5g6FOQYQxZ6L0tXxlp5wVNrknXJ/8sC9/mn8yKkkQMx0j9j9jZH1ecQqd/
	 4tgun9qQ1e60as06x3DRoIX7eeKMS70/7H5+NWtIbadF/eR09PIZEJlO9Ffc5W8Eofwws
	 QqY6wpXgBPh2AzdEOdlU9PKOmQpXClIbGrBvHKfbUIctmOn7UmeXYRgggbbgi+JL+8A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792424258;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:
	 Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=dUJTYJsLlzyXXUY346kwM0qbEb7/ZcRCJp3v3CTcxII=;
	b=27Px5NNVdvJTGP06dYylLKK+/dT7EnkqsU/JFLU4WKshWeqx55MF0a42iDuxzGL4Zykh
	 RCOkwzIJWJ+DfM1F6vBb/TSFlQiHMyvXETXQLTjBzr7iPl657IRxLYQOhjqayQ0uCFvWl
	 0jngwaH7nbsCXMpW9y0zI7jeMA+K7lBZm1vo5YN+EmTWO1CtF92ePAj+kOq5sOV3IH9k3
	 BUjEmyaot+SeBfd04G5fIPUCB/KCtvCjWbtVeHKgPXMo3IuCxuITcamLAo2EizVuty+os
	 GCnwts27w+0JDERvC0xdh1kBSZbiNR+PZ0M5UxZXmB5dUfB3+QCApB3EqDI8I3ho9QQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=NB+MtaXv;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id C17A0608342A;
	Mon, 19 Oct 2026 15:37:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=NB+MtaXv
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.108
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792424257;
	b=JkWgygY/0RD/nprWIUU5L+Ibh20Afg3rdtlSSIB15VtmjNwa97zIwhJ/hnLeb+LshYt4
	 tRj8mZNqEZrAaGvtbPbHD/1br3zrhYETY/bTJSM+EOE2f5EK+7vW8OoUBUAQzluk/ao02
	 wJgSdawuL1ATc4hXAr+wC6WOVAnI+S3pkOGv3dK6qN2XhngUyMmuTbfd9mxpxfV2/5i40
	 MHDbYzI4Q2vH2WQbmzz/yN/m/DK/a2Zj6uVsP+1oT5sn860H5v+6KyAJ1/gp2dXqUSl2Y
	 bwctcWHto5i2sKwBWEY+btMzXYZD0+yoRG3DL816VVD/9pfMN3aPyKkIHQeF2pOA+xQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792424257;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=dUJTYJsLlzyXXUY346kwM0qbEb7/ZcRCJp3v3CTcxII=;
	b=QBMz6XDw6tv+EbB5djjWipTbOIul9beuz5oClSs9u7R0Oq6UaWls6sYjo2+SGLnIwoll
	 X8VPUmsVFqz9bDFH7fzo2BTyzbuV8QI7qPHHhJ/Wd2vLsHMV2fT24pxnwQ1WrIZ8d/mVK
	 iFLhMaWOfEKhSbcO4obnAV48XZCxqwmjmIbvbwpQ98EyojcK1sUF+iPqq1nyrcD1Xu4aB
	 mjfjvMtOKVLgszmOPGaefxp4cMKyC4jg5t11PxBAi5dlJnxs04NpdotONO4V13xRzOURh
	 N8BlmbKyl8oIlfzhj7f7d0AWPIWbVwUN+J8Gik65wWTCq8BZJHVBlDmbTDRylJAVijA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=NB+MtaXv;
	arc=none smtp.remote-ip=95.215.58.108
X-Received: from mta1.migadu.com (out-108.mta1.migadu.com [95.215.58.108])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27B786083403
	for <netdev@vger.kernel.org>; Mon, 19 Oct 2026 15:37:36 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 27B786083403
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=oA/tXzZewa3e1Eee5uSA/aYj+j+eif8gKx6dS9PYgCk=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1792424255; v=1; x=1793029055;
 b=NB+MtaXvTaeOYBOzBzOpI+ex4jCH7doRKORA+v/0S5q77izL4FdeG19kF2Nhp5avEyXtGkkR
 jC/2ulPQPdDi7zPYbXzVAhAsMYqVzkCgVdSuEzoklRy2ICLRQ/VvoOBgoYKzl7w+MIJVFDpjNoX
 mlk4XryaMk4QcIvZoxYru6xM=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 1854e421e9778bac;
	Mon, 19 Oct 2026 15:37:35 +0000
X-Mizu-Trace-ID: 1854e421e9778bac
X-Migadu-Flow: FLOW_OUT
X-Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Shuah Khan <shuah@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Hangbin Liu <liuhangbin@gmail.com>,
	Martin Karsten <mkarsten@uwaterloo.ca>,
	Masashi Honma <masashi.honma@gmail.com>,
	linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	Leon Hwang <leon.hwang@linux.dev>
X-Mailer: git-send-email 2.55.0
X-In-Reply-To: <20261019153628.15912-1-leon.hwang@linux.dev>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list