From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEB2513AF2 for ; Fri, 16 Jan 2026 14:17:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768573059; cv=none; b=dyztuHfu/6h1sCdetyB8uXHUDkKS6ZgYQZicEp8dl7Cy6rcFbcH98tlECH+B3y5abJYRRETGQa4BMuHlDWxnecxIZEaDGdgmRaBKdCobrBj3fKx/vlVz8TQlZImK343P54rg5kYd758i7oUfSCN23dqDzgYTfKz17je++J8rMj0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768573059; c=relaxed/simple; bh=tFAb7kU+GUoUou6pVG4vlKLk0Na2EuYIDz5ZFMRn7jQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=O8oVhz7Ov3lqfXZpACwqCQ5rhbtJwSzwOjeMLVVEJGmt75ZFwNELfcKbz6vEqukin0+lms65mIUdJBe4p1bnPrw3tdYq5RGkdfmx+/n78bOzvpWusHuHUZvNbsL3adrgG7/FXeVG67i36LQMEG6BOwcHNBBJpFELoRxHIFRhMdo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ckUPJAd3; arc=none smtp.client-ip=95.215.58.179 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) header.d=linux.dev header.i=@linux.dev header.b="ckUPJAd3" Message-ID: <22e0de9a-8963-454b-8b35-f8c9be15dee3@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768573055; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AyxPKtVnYEhbqY5ej9xEJpQHHwFramyrAhZn0x12s5U=; b=ckUPJAd3AWNAzWG97rpe0cF0VTKDfX59rtFnngz7SQij8DTo8BgeJF3Ln4lP7Ic9HbHP61 mqpyDrYxm7kU0I5vONV/s4RuQf1ugVizWLwm/dh92y5Nn5kfNarN8fi82Vpo9htNbHJn40 xLjerGNKDdt38fClMkTqaSxZfZLCCXU= Date: Fri, 16 Jan 2026 22:17:20 +0800 Precedence: bulk X-Mailing-List: linux-api@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v5 8/9] libbpf: Add common attr support for map_create To: Andrii Nakryiko Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Christian Brauner , Seth Forshee , Yuichiro Tsuji , Andrey Albershteyn , Willem de Bruijn , Jason Xing , Tao Chen , Mykyta Yatsenko , Kumar Kartikeya Dwivedi , Anton Protopopov , Amery Hung , Rong Tao , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-patches-bot@fb.com References: <20260112145616.44195-1-leon.hwang@linux.dev> <20260112145616.44195-9-leon.hwang@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Leon Hwang In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 2026/1/16 09:03, Andrii Nakryiko wrote: > On Mon, Jan 12, 2026 at 6:59 AM Leon Hwang wrote: >> >> With the previous commit adding common attribute support for >> BPF_MAP_CREATE, users can now retrieve detailed error messages when map >> creation fails via the log_buf field. >> >> Introduce struct bpf_syscall_common_attr_opts with the following fields: >> log_buf, log_size, log_level, and log_true_size. >> >> Extend bpf_map_create_opts with a new field common_attr_opts, allowing >> users to capture and inspect log messages on map creation failures. >> >> Signed-off-by: Leon Hwang >> --- >> tools/lib/bpf/bpf.c | 15 ++++++++++++++- >> tools/lib/bpf/bpf.h | 17 ++++++++++++++++- >> 2 files changed, 30 insertions(+), 2 deletions(-) >> >> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c >> index d44e667aaf02..d65df1b7b2be 100644 >> --- a/tools/lib/bpf/bpf.c >> +++ b/tools/lib/bpf/bpf.c >> @@ -207,6 +207,9 @@ 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 common_attr_sz = sizeof(struct bpf_common_attr); >> + struct bpf_syscall_common_attr_opts *common_attr_opts; >> + struct bpf_common_attr common_attr; >> union bpf_attr attr; >> int fd; >> >> @@ -240,7 +243,17 @@ int bpf_map_create(enum bpf_map_type map_type, >> attr.excl_prog_hash = ptr_to_u64(OPTS_GET(opts, excl_prog_hash, NULL)); >> attr.excl_prog_hash_size = OPTS_GET(opts, excl_prog_hash_size, 0); >> >> - fd = sys_bpf_fd(BPF_MAP_CREATE, &attr, attr_sz); >> + common_attr_opts = OPTS_GET(opts, common_attr_opts, NULL); >> + if (common_attr_opts && feat_supported(NULL, FEAT_EXTENDED_SYSCALL)) { >> + memset(&common_attr, 0, common_attr_sz); >> + common_attr.log_buf = ptr_to_u64(OPTS_GET(common_attr_opts, log_buf, NULL)); >> + common_attr.log_size = OPTS_GET(common_attr_opts, log_size, 0); >> + common_attr.log_level = OPTS_GET(common_attr_opts, log_level, 0); >> + fd = sys_bpf_ext_fd(BPF_MAP_CREATE, &attr, attr_sz, &common_attr, common_attr_sz); >> + OPTS_SET(common_attr_opts, log_true_size, common_attr.log_true_size); >> + } else { >> + fd = sys_bpf_fd(BPF_MAP_CREATE, &attr, attr_sz); > > OPTS_SET(log_true_size) to zero here, maybe? > Unnecessary, but ok to do it. >> + } >> return libbpf_err_errno(fd); >> } >> >> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h >> index 2c8e88ddb674..c4a26e6b71ea 100644 >> --- a/tools/lib/bpf/bpf.h >> +++ b/tools/lib/bpf/bpf.h >> @@ -37,6 +37,18 @@ extern "C" { >> >> LIBBPF_API int libbpf_set_memlock_rlim(size_t memlock_bytes); >> >> +struct bpf_syscall_common_attr_opts { >> + size_t sz; /* size of this struct for forward/backward compatibility */ >> + >> + char *log_buf; >> + __u32 log_size; >> + __u32 log_level; >> + __u32 log_true_size; >> + >> + size_t :0; >> +}; >> +#define bpf_syscall_common_attr_opts__last_field log_true_size > > see below, let's drop this struct and just add these 4 fields directly > to bpf_map_create_opts > >> + >> struct bpf_map_create_opts { >> size_t sz; /* size of this struct for forward/backward compatibility */ >> >> @@ -57,9 +69,12 @@ struct bpf_map_create_opts { >> >> const void *excl_prog_hash; >> __u32 excl_prog_hash_size; >> + >> + struct bpf_syscall_common_attr_opts *common_attr_opts; > > maybe let's just add those log_xxx fields here directly? This whole > extra bpf_syscall_common_attr_opts pointer and struct seems like a > cumbersome API. > Oops... This struct was suggested by the v3 discussion [1]. This struct was used to report 'log_true_size' without changing 'bpf_map_create()' API. Links [1] https://lore.kernel.org/bpf/CAEf4Bzaw9cboFSf1OXmD84S7pKaeyj=bcQg_diUzGwAkFsjUgg@mail.gmail.com/ Thanks, Leon >> + >> size_t :0; >> }; >> -#define bpf_map_create_opts__last_field excl_prog_hash_size >> +#define bpf_map_create_opts__last_field common_attr_opts >> >> LIBBPF_API int bpf_map_create(enum bpf_map_type map_type, >> const char *map_name, >> -- >> 2.52.0 >>