Article View: linux.kernel.netdev
Article #7080[PATCH bpf-next v4 5/6] libbpf: Add log_opts support for bpf_link_create
From: Leon Hwang
Date: Sat, 24 Oct 2026 15:36
Date: Sat, 24 Oct 2026 15:36
107 lines
12774 bytes
12774 bytes
Since the iter_info and iter_info_len in struct bpf_link_create_opts are
legacy, reuse the slot of iter_info to place log_opts.
When adding log_opts support for iter link_create in the future, we will
move the iter_info and iter_info_len to the last union, see below. And,
keep the backward compatibility meanwhile, that uses iter_info if
iter_info_len is set.
struct bpf_link_create_opts {
/* ... */
union {
/* ... */
strut {
struct bpf_iter_link_info *info;
__u32 len;
} iter;
};
};
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
tools/lib/bpf/bpf.c | 20 +++++++++++++++++---
tools/lib/bpf/bpf.h | 5 ++++-
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 9a2107d4f6d8..00efa90a6ed9 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -794,6 +794,8 @@ int bpf_link_create(int prog_fd, int target_fd,
{
const size_t attr_sz = offsetofend(union bpf_attr, link_create);
__u32 target_btf_id, iter_info_len, relative_id;
+ union bpf_iter_link_info *iter_info = NULL;
+ struct bpf_log_opts *log_opts = NULL;
int fd, err, relative_fd;
union bpf_attr attr;
@@ -803,6 +805,14 @@ int bpf_link_create(int prog_fd, int target_fd,
iter_info_len = OPTS_GET(opts, iter_info_len, 0);
target_btf_id = OPTS_GET(opts, target_btf_id, 0);
+ if (iter_info_len && attach_type != BPF_TRACE_ITER)
+ return libbpf_err(-EINVAL);
+
+ if (iter_info_len)
+ iter_info = OPTS_GET(opts, iter_info, (void *)0);
+ else
+ log_opts = OPTS_GET(opts, log_opts, (void *)0);
+
/* validate we don't have unexpected combinations of non-zero fields */
if (iter_info_len || target_btf_id) {
if (iter_info_len && target_btf_id)
@@ -824,7 +834,7 @@ int bpf_link_create(int prog_fd, int target_fd,
switch (attach_type) {
case BPF_TRACE_ITER:
- attr.link_create.iter_info = ptr_to_u64(OPTS_GET(opts, iter_info, (void *)0));
+ attr.link_create.iter_info = ptr_to_u64(iter_info);
attr.link_create.iter_info_len = iter_info_len;
break;
case BPF_PERF_EVENT:
@@ -960,12 +970,12 @@ int bpf_link_create(int prog_fd, int target_fd,
return libbpf_err(-EINVAL);
break;
default:
- if (!OPTS_ZEROED(opts, flags))
+ if (!OPTS_ZEROED(opts, iter_info_len))
return libbpf_err(-EINVAL);
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 +985,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
*/
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 826d9cc9ab65..fe3b7fd8512b 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -422,7 +422,10 @@ union bpf_iter_link_info; /* defined in up-to-date linux/bpf.h */
struct bpf_link_create_opts {
size_t sz; /* size of this struct for forward/backward compatibility */
__u32 flags;
- union bpf_iter_link_info *iter_info;
+ union {
+ union bpf_iter_link_info *iter_info;
+ struct bpf_log_opts *log_opts;
+ };
__u32 iter_info_len;
__u32 target_btf_id;
union {
--
2.55.0
Technical Details
Message-ID:
<20261024153608.58569-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-351404-linux-kernel-netdev=dewy.ruReferences:
<20261024153608.58569-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-351404-linux-kernel-netdev=dewy.ru From: leon.hwang@linux.dev (Leon Hwang) Newsgroups: linux.kernel.netdev Subject: [PATCH bpf-next v4 5/6] libbpf: Add log_opts support for bpf_link_create Date: Sat, 24 Oct 2026 23:36:06 +0800 Organization: Usenet Network Message-ID: <20261024153608.58569-6-leon.hwang@linux.dev> References: <20261024153608.58569-1-leon.hwang@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="795431"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:wiHikkJ+fjAJ+rKdOX3LFM0L4Y8= sha256:L3mKy0W4bKzTbdO8oQBuUkw6tLBsQJ/rXLHneEubEuk= sha1:M0heVUzJ2QrockSSPXC1N9K/vZ0= sha256:z6g2vwuWgf+jaWRGlL4Q26OsgiPsOSnpKl6qbWEutYs= 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 952EE11166E; Sat, 24 Oct 2026 18:41:45 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.049 X-Spam-Status: No, score=-3.049 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, URIBL_BLOCKED=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 cQHA6wNOdA06; Sat, 24 Oct 2026 18:41:41 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-351404-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 2092A11166B; Sat, 24 Oct 2026 18:41:33 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 7A6DD3C7C1; Sat, 24 Oct 2026 15:37:25 +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=1792856244; b=M1Ov1sDw3OWPu3e8JdzoUGOr/Kp3vxWNmCdAZ+mWPKk7W1CrhP7lZH/NHz9un4rn+iMb NTf64qxdlFNsuziTDWC9D3nYFkCJTHezi8Pvod/uts8twXKWpTRjY6eO5sGuE7T5Q75zZ qGl1AWP3DyO7wnIKmvnxmwl8oclOoAnm9T8F0OyvhsvVdV9/x4gIyjt3Rt6AlN6GfZ+l7 xCdjYit9eodcc47LTYoIBmjrQymmNZ71L2uuBZwlks9/MmUu/JI50rLyX3SmHtIJnhsr9 tY7adtn5rAYF3MtPOA1oJYIX57vSSHpvLWjI/05fOrPexKDX8ES+7hkY5euCzd367fQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792856244; 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=+Pvjw8HRLnHni+FZwWrlUa2T4PGWR53RxB/HrY99yOw=; b=UILyLML86LW6GlShJDoJMPpp+d4OfyUolkPYj5shghcg/DxUfkhB+J9idWVjZU5qsPni QCGtvF2lJM5r6/gopJzY+Gv7MUvWWNmk1cOoesIjKfksMrjMjWXzHrV4lVq9/zjnJhQT/ pnnlnRI5Mg01fSk3wIUN9YDqS0PDFE+FNhO2lv2RLDRYWCCe74W/aUjVQYS8aw1UJ7STc MSOlli+hAiT0fCA3Pobg5dWkyM3eG7Z6lI+ooj2Lf/Fmi0FvdyVa2G/iFQDQxRsQrfoMI 61rlz8AHy5RKavJP2DfpiqWFaie0NKaASo8M5XKNluoJ6Ynx4WuBjB5PV8pEVdpRD1w== 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=WmYUaefL; 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 8B24D606A32F; Sat, 24 Oct 2026 15:37:24 +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=WmYUaefL X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.220 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792856243; b=FeY4vLFsLQx8AfueC9ZAr32HGA4e6jU2SglZsNCWHPZWsUmpDWiapVbTL7JjMLBb9Y3R 0Nmdgh7xc0dwt2lX4pnL2BVGQq37qWATUWgyTxaKgldLQFuH4mq37lhww6VTtYENBsKtp ZB5UitVsyw+ThAe5nMaqm3N/p9i+AxgTD8Kow+p+S0pct/8kSl7xVnLUn3OJyIoxJkFld RAH2ZwU4o4/HDkKIZeeShKkkjsTbwZLJDo1i1aP2IN5O5VhzNVkPDxraPjdWcGq0SmleV /MG2MJMJWPr+nACYZqgPs/cyHj9yUGcrOYt7n0QXNtL/5ODSKIBMpv8BQEfUdCdqWcg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792856243; 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=+Pvjw8HRLnHni+FZwWrlUa2T4PGWR53RxB/HrY99yOw=; b=JK66dlRW5wjHoH/Ihz6c6OLwc8LSC/ZeXwtMqFb7UtJ5PEJnRNAda8c2cj8l7eqOsb3c KMvdDCdIIYlX/GnQyAAF3GEyFGneGSAszdqLt0VQXFjHaI94lQZX45bXWLX/mODuNjG2h tiAqU5g/4Mb46mILJsnunOa8rsWZaaYPUQ62FrYERrWkKoQ5kZnO+tSu3aBjaZT4rjl6Z d8o54bDHPlwi/zZz6A7tJnNeLs/baZczETdMakZZmXljTMZbl4fmjzT0WzWOsyDlFDNWj DlMcou9PC97pXUlEhib1J++LtH9UAffuq2HEFGdn8feqXBxTgEt5UHq9JMBBX16w62w== 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=WmYUaefL; arc=none smtp.remote-ip=91.218.175.220 X-Received: from mta0.migadu.com (out-220.mta0.migadu.com [91.218.175.220]) (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 17888606A31D for <netdev@vger.kernel.org>; Sat, 24 Oct 2026 15:37:22 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 17888606A31D 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=zJC9ty/LE7pzfzpMn8wblErHaCPAeoPMnKwSsk4yqEw=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1792856241; v=1; x=1793461041; b=WmYUaefLhVXM3AUT3y9mM0zREYdHkAzlgM+IUe/UYGu3YdLoDrA+e4qHiRRPbHVp9UEe9pLt 8u28GYNpjKpFykMWAtaqlIcVS1dfODYomU9MjqTJvXP0vJY+Qs0shd0dfkkjc4XTC9ceq27zTIf 9uRw6Ksy89nKNMJNIuHy/0W8= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id b106be7095f877d4; Sat, 24 Oct 2026 15:37:21 +0000 X-Mizu-Trace-ID: b106be7095f877d4 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: <20261024153608.58569-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