Article View: linux.kernel.netdev
Article #7530Re: [PATCH bpf-next v4 4/6] libbpf: Factor out __sys_bpf_fd helper
From: Leon Hwang
Date: Mon, 26 Oct 2026 15:07
Date: Mon, 26 Oct 2026 15:07
85 lines
12388 bytes
12388 bytes
On 2026/10/25 00:13, bot+bpf-ci@kernel.org wrote:
>> libbpf: Factor out __sys_bpf_fd helper
>
> TL;DR: Nit only, not a bug: the new libbpf helper __sys_bpf_fd() has a
> misleading name and a different argument order (cmd not first) than
> sys_bpf_fd(); a name like sys_bpf_fd_log() is suggested.
>
>> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
>> index b49822d212ae..9a2107d4f6d8 100644
>> --- a/tools/lib/bpf/bpf.c
>> +++ b/tools/lib/bpf/bpf.c
>> @@ -203,6 +203,30 @@ int bump_rlimit_memlock(void)
>> return 0;
>> }
>>
>> +static int __sys_bpf_fd(union bpf_attr *attr, const size_t attr_sz, enum bpf_cmd cmd,
>> + struct bpf_log_opts *log_opts)
>> +{
>> + const size_t attr_common_sz = sizeof(struct bpf_common_attr);
>> + struct bpf_common_attr attr_common;
>> + int fd;
>> +
>> + if (!OPTS_VALID(log_opts, bpf_log_opts))
>> + return libbpf_err(-EINVAL);
>> +
>> + if (log_opts && feat_supported(NULL, FEAT_BPF_SYSCALL_COMMON_ATTRS)) {
>> + memset(&attr_common, 0, attr_common_sz);
>> + attr_common.log_buf = ptr_to_u64(OPTS_GET(log_opts, buf, NULL));
>> + attr_common.log_size = OPTS_GET(log_opts, size, 0);
>> + attr_common.log_level = OPTS_GET(log_opts, level, 0);
>> + fd = sys_bpf_ext_fd(cmd, attr, attr_sz, &attr_common, attr_common_sz);
>> + OPTS_SET(log_opts, true_size, attr_common.log_true_size);
>> + } else {
>> + fd = sys_bpf_fd(cmd, attr, attr_sz);
>> + OPTS_SET(log_opts, true_size, 0);
>> + }
>> + return fd;
>> +}
>> +
>
> [ ... ]
>
>> @@ -248,20 +270,7 @@ int bpf_map_create(enum bpf_map_type map_type,
>> attr.excl_prog_hash_size = OPTS_GET(opts, excl_prog_hash_size, 0);
>>
>> log_opts = OPTS_GET(opts, log_opts, NULL);
>> - if (!OPTS_VALID(log_opts, bpf_log_opts))
>> - return libbpf_err(-EINVAL);
>> -
>> - if (log_opts && feat_supported(NULL, FEAT_BPF_SYSCALL_COMMON_ATTRS)) {
>> - memset(&attr_common, 0, attr_common_sz);
>> - attr_common.log_buf = ptr_to_u64(OPTS_GET(log_opts, buf, NULL));
>> - attr_common.log_size = OPTS_GET(log_opts, size, 0);
>> - attr_common.log_level = OPTS_GET(log_opts, level, 0);
>> - fd = sys_bpf_ext_fd(BPF_MAP_CREATE, &attr, attr_sz, &attr_common, attr_common_sz);
>> - OPTS_SET(log_opts, true_size, attr_common.log_true_size);
>> - } else {
>> - fd = sys_bpf_fd(BPF_MAP_CREATE, &attr, attr_sz);
>> - OPTS_SET(log_opts, true_size, 0);
>> - }
>> + fd = __sys_bpf_fd(&attr, attr_sz, BPF_MAP_CREATE, log_opts);
>> return libbpf_err_errno(fd);
>> }
>
> This isn't a bug, but __sys_bpf_fd() is a higher-level wrapper that
> dispatches to sys_bpf_fd() or sys_bpf_ext_fd() after validating log_opts and
> probing FEAT_BPF_SYSCALL_COMMON_ATTRS, while a leading double underscore
> usually marks the lower-level variant of a function.
>
> The helper also takes (attr, attr_sz, cmd, log_opts), whereas sys_bpf(),
> sys_bpf_fd(), sys_bpf_ext() and sys_bpf_ext_fd() all take cmd first, so the
> new call reads differently from the nearby calls:
>
> fd = __sys_bpf_fd(&attr, attr_sz, BPF_MAP_CREATE, log_opts);
>
> Would a name that describes what the helper adds (for example something like
> sys_bpf_fd_log()), with cmd as the first argument like the other sys_bpf*()
> wrappers, read more naturally next to sys_bpf_fd() and sys_bpf_ext_fd()?
>
I'd like to move cmd as the first argument, and keep name __sys_bpf_fd()
for the helper.
Thanks,
Leon
Technical Details
Message-ID:
<3d70768f-8d0a-496a-ac3a-9ee3438b2091@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-351958-linux-kernel-netdev=dewy.ruReferences:
<20261024153608.58569-5-leon.hwang@linux.dev> <5d94730579f232c7be1c83bc7287e91af9a858bcea83765e58bdd2fc3956a229@mail.kernel.org>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-351958-linux-kernel-netdev=dewy.ru From: leon.hwang@linux.dev (Leon Hwang) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH bpf-next v4 4/6] libbpf: Factor out __sys_bpf_fd helper Date: Mon, 26 Oct 2026 23:07:28 +0800 Organization: Usenet Network Message-ID: <3d70768f-8d0a-496a-ac3a-9ee3438b2091@linux.dev> References: <20261024153608.58569-5-leon.hwang@linux.dev> <5d94730579f232c7be1c83bc7287e91af9a858bcea83765e58bdd2fc3956a229@mail.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1333693"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:3ESLa520l1t3xPx2CzlE0/bwTTY= sha256:2GdCEYq06LInvPp3EgXKBFbxUZzCz5KgYY4k2/sZoeY= sha1:9/mltsCisLoneBRhcQolY9sLF6w= sha256:Gu3ttWNK8qMKTeFGF5TkB1mANA0R2MK+jas9k5yz/1M= Content-Language: en-US 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 99C37125BAE; Mon, 26 Oct 2026 18:10:22 +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 ilxz-TiF3ls3; Mon, 26 Oct 2026 18:10:19 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-351958-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 2D1FF125BA9; Mon, 26 Oct 2026 18:10:11 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 0BB022C432; Mon, 26 Oct 2026 15:07:49 +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=1793027263; b=m2E7z2BCQBQUgZgamsHMYBcVTGLpZFsM+XeqOYUCSAXqAHa0WccnICwv+Z/RiE/F0+Dx WMH00piRmfW2MoZKPpDZ9j0jLlBNKzXtMG7FsgiOPhyOf5n+mrDf3ofWecHjk8TEHXEea dOvoFBnRID/lqC+0m5eAzEt8ZClTUg9pZdDpiYEDd2pVJdtAYEIGD/F2LMW5N3999OtMv BB8JAOuRl5qf9oO0hIlsdsytPrQXuJe4zs6sTGkb25aYnFG5BGxQwH2jTamczFHL7Ygl5 fAobXluf384rsogVLiXYG6o3c/X3GPirLWtM5EibipYzcxWczi0NqKnBfJHkNBrOlyA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793027263; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=wnhw2bwataB6NDJxxOJekLvhPHu4AY/2Eqvomh/enxc=; b=SlyrBJMFtS241xh+oayII6rg6xn+Ay74unU0NjeTSTOmmzqksF6pR6G85fnyGIzIY2BZ YZ3R2pfxstygpBe838pZNYk12fenwAHMBbYduBAdwmVnjTsVQG9lIMTyb3UtUSEch5LlZ v1inLReS6qFhMGXbG9NcpC7NzMCLLasWGGQ+LrVjQIAB3EMxb2OxKXsvdyxc5lS8zLKwf dDDiItv9UsFepQ7w8FJFDXWgX307PmV1pUAPIv92mafTXrv8z6eqJuGfZPu4vy4bCCXyZ +sPvEKX5bqKkaFBNB6W5MLRkcrz62XWkvAOSJYgPGiQyFOS2rK5HMQ5ngKJ1y6knCMw== 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=FYUbSmh1; 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 A58A2606A337; Mon, 26 Oct 2026 15:07:43 +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=FYUbSmh1 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.17 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793027262; b=3tqP7mA3tL7qkFkFHcrpWUhilvAqeg/in3JmTNEu/DYFvMRnW+SYh1pPrsXFlucSatpD ok9Ntu92ZfCgcx0fbWWlc+drEe1n9+sqMT+GCXg0yJFKem+jiAeSRMII19bvBFISH3m3J ywyAqaJtqCoRVk9vAU3qFHCvgoJXDPRvFOTSqeorw14lIVgFhWKeK18sxQ8XwPPmnR+EM vuPLBTxu1ZbRO0Na60V3STKKBZJaH2zHdtkXHUGDspaspbzVXZ6yDGklJXbpN5iZk96I6 YChadtn5cl4NHFDiuNM280za9hjVdmoVAmN5aStRaQGFjbyX9BgrIWXz0jRUXkcBeDA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793027262; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=wnhw2bwataB6NDJxxOJekLvhPHu4AY/2Eqvomh/enxc=; b=D8ZK7YstLm+pT2whWacrMb+v22x7NniC88evtz94hXxHOaLdRs3QZZbwyBVxybO9EevI 2edpX1jRzyW8G8h5Q7nvikoyujmHZ8pXtjRZG6ZF9/8UZj9pNlXkYknyJfNxdJ6ar3LyR auSWXYfjQQJwgvRxa23pqGqs1V5AiIZXGo1e4qGP0YJFbFEGnp71G6bCRPtlFIQJp/OYR OP5HkXc4fkn7dGeldmzK0w9hmqWxVnevn5MMZmjd8F/8EsSwE1xol/zIMuO493L1WdNQB sCmpu1+Oc5DEqoE/cjhGRRDaGt8fmlqsN2iyiSt71qr1yg6vjF1R8I6QQYdKVhOxuQg== 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=FYUbSmh1; arc=none smtp.remote-ip=95.215.58.17 X-Received: from mta1.migadu.com (out-17.mta1.migadu.com [95.215.58.17]) (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 AF95C606A320 for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 15:07:41 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AF95C606A320 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=uFNLB3HiqIo+JkFlJtk4vr4134/LdgXjZ5iBc9vByl8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793027259; v=1; x=1793632059; b=FYUbSmh1HZNpzOVb/j9jQiGPtlRSf+EmWoeTZKP6NNptf1MfXjXvgCBUBYfxKPCUsnqQzOry B6c9VkeyrvG9AnJqnmN12juYRb6EnLcyUeeA298swzv8xWG0IXGxLWeSVGWblQCUZh45xKBcx1e 4HiG58XT29EpLBntuaMgTpEg= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id e3fb3f0e5d8099b8; Mon, 26 Oct 2026 15:07:39 +0000 X-Mizu-Trace-ID: e3fb3f0e5d8099b8 X-Migadu-Flow: FLOW_OUT 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 X-User-Agent: Mozilla Thunderbird X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, shuah@kernel.org, kuniyu@google.com, liuhangbin@gmail.com, mkarsten@uwaterloo.ca, masashi.honma@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, martin.lau@kernel.org, mason@kernel.org X-In-Reply-To: <5d94730579f232c7be1c83bc7287e91af9a858bcea83765e58bdd2fc3956a229@mail.kernel.org>