From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.119 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793029861; b=e20NwcwdP+nFIbf2YOfUrDFK963fO+pF6Gk3WnTyzPNZbuaXTnDcSRnwpgPAnXvGlCXz NOS/ve54wC97vT5HkQ7JUqmbzTHeu8sJ4fYXaVJS1LBV2BLJJXPCcLCJSMhqKTOnsFr+0 p/SaRkEblYeakWcRV5TwWagwRByYgIIKTcCkGQiM81gLADNIVH6QaQgqt+EgnTfdBNHu7 ElPKDQrjRfEaVjlAGB2Oo9vZkP6En1YvaLtrppRTyyyY4lCJojz7bkYDXBW884JfaFe6b nEiK0Tu121LBSE1brHaLmEAX7su13WUoy2tQlblktegE25/h/TpPg+E6g8aa/V593pQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793029861; 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=rNyXcCTs6E/eyv+VrJNiB97hukPlhcv7oRvxhJ4yyjA=; b=cbXxn3DXrMmmr5IryroQoZkSG4As/pYSHlv1eg6nAozFAknW5f8fz6oHh1gjGlV/HK4o 4Z89Ggru6ufW8gpGm1Qp8faEOBdW5Wr9tAOAqSUY7gkWyvTSBbHAIcwt8oXTAQbb1LCMk Crxqg54XVK3KGOojzTgeQB5hQYltugtzgb+g0Z5rQNNcTU0VgTfe7yRgoQBt192BwtnHU VLG6pTNXDqYSS3sY/vFhRSR9+Ppai6vB+Yg7Gg49eSQwwFa5SqU7n9M59rbWwujldLPzo JqoPEVfFnnuHstZbDlL81RPSYGJnidLRVsd3ZxDu3rUaGN1vcoEBk9r/MUDxxiJUzjw== 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=Lw5howYs; arc=none smtp.remote-ip=91.218.175.119 Received: from mta0.migadu.com (out-119.mta0.migadu.com [91.218.175.119]) (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 EDE18606A31B for ; Mon, 26 Oct 2026 15:51:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EDE18606A31B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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=Lw5howYs X-Envelope-To: linux-trace-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=Sd7qJsJbPJmazKFGOrx4OFnOy6W60jF/TweIlJooOec=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793029859; v=1; x=1793634659; b=Lw5howYsMx6m2Goe3okJ9l62Zss5j64TFYYm+JIJ3LHxab75AX59g4aa4wg/64ScJRlKGPLu Z+hhsmJjXc4F/4L1r7dzkNv+SZbqViHuTgIz3KrgHr+TBEy4td4rtzq/gxVPiqQn6NP2Y+841sC XVLrxRlaZpr3GTuUzWWI2ZKk= X-Envelope-To: linux-trace-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 23bda684e57ad343; Mon, 26 Oct 2026 15:50:58 +0000 X-Mizu-Trace-ID: 23bda684e57ad343 X-Migadu-Flow: FLOW_OUT From: Leon Hwang To: bpf@vger.kernel.org Cc: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Shuah Khan , Kuniyuki Iwashima , Hangbin Liu , Martin Karsten , Masashi Honma , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Leon Hwang Subject: [PATCH bpf-next v5 4/6] libbpf: Factor out __sys_bpf_fd helper Date: Mon, 26 Oct 2026 23:49:45 +0800 Message-ID: <20261026154948.99408-5-leon.hwang@linux.dev> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261026154948.99408-1-leon.hwang@linux.dev> References: <20261026154948.99408-1-leon.hwang@linux.dev> X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In the next patch, it also needs to use the extended BPF syscall to receive the reported log. So, factor out __sys_bpf_fd helper. No functional changes intended. Signed-off-by: Leon Hwang --- tools/lib/bpf/bpf.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index b49822d212ae..aea534764dfe 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(enum bpf_cmd cmd, union bpf_attr *attr, const size_t attr_sz, + 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; +} + int bpf_map_create(enum bpf_map_type map_type, const char *map_name, __u32 key_size, @@ -211,8 +235,6 @@ int bpf_map_create(enum bpf_map_type map_type, const struct bpf_map_create_opts *opts) { const size_t attr_sz = offsetofend(union bpf_attr, excl_prog_hash_size); - const size_t attr_common_sz = sizeof(struct bpf_common_attr); - struct bpf_common_attr attr_common; struct bpf_log_opts *log_opts; union bpf_attr attr; int 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(BPF_MAP_CREATE, &attr, attr_sz, log_opts); return libbpf_err_errno(fd); } -- 2.55.0