From nobody Sat Feb 7 20:58:02 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 3ADE2346A18 for ; Tue, 6 Jan 2026 17:21:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767720107; cv=none; b=iYyxoh57C7kNFVpQEDtxdA/rzlbr9ky0kZy3hvr9R3WDOOCz8O1ah14oi/KN75YGwUHgZFG9whNIWrRo8ntzGX2BGq4xxb26OvYiu7iebhC6aEI3l5GkqMRY1kvZMiqyq3NMSawETUBsroqi8GrXVPommKD6fwNATvStQQ8zAWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767720107; c=relaxed/simple; bh=574nViD3Ekg7B8qaFiH5i9ESrWlBcUwH8a7+I+wJd0k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rad7ez8hmKuEG7C3bRZPfzOlWTW97gL14r0BpZACeiHznebeWG8rDxbfP6DWQ7soF1dj6zh9/VbVOK0mpva108Ped3vd4mzcoTiJJzJHq7UHTPlR9h7yF4BRpt34nr36VGEPspfMUoJgKpPjgzqAP5BdE5fQ1jwvh6paEHz3XUw= 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=sP3loB8b; arc=none smtp.client-ip=91.218.175.185 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="sP3loB8b" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767720103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oH5uvc/HIHJHvUDH1FHA2g822OEsdqyIpxTdGkj+aPM=; b=sP3loB8byZBmR1LqrU23UR+FYC4Bf9UVEJ+RmM5goMOD5zk9VH84b1iMRuqdkqv6FjgwJ3 jTH71FXVn2/x1ceZcPUq6eVUtzkkpv0BJb2h1B4NehHtfqn8EMhft/BNSTFp8RqmIV/Gc+ yKyC8WxozOJGoCDx01HYSm+/dm4CfH0= From: Leon Hwang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Christian Brauner , Oleg Nesterov , Leon Hwang , Seth Forshee , Yuichiro Tsuji , Andrey Albershteyn , Willem de Bruijn , Jason Xing , Paul Chaignon , 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 Subject: [RESEND PATCH bpf-next v4 6/9] bpf: Add common attr support for btf_load Date: Wed, 7 Jan 2026 01:20:15 +0800 Message-ID: <20260106172018.57757-7-leon.hwang@linux.dev> In-Reply-To: <20260106172018.57757-1-leon.hwang@linux.dev> References: <20260106172018.57757-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The log buffer of common attributes would be confusing with the one in 'union bpf_attr' for BPF_BTF_LOAD. In order to clarify the usage of these two log buffers, they both can be used for logging if: * They are same, including 'log_buf', 'log_level' and 'log_size'. * One of them is missing, then another one will be used for logging. If they both have 'log_buf' but they are not same totally, return -EUSERS. Signed-off-by: Leon Hwang --- kernel/bpf/syscall.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index ce349a059d5d..14fc5738f2b9 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -6211,14 +6211,35 @@ static int copy_prog_load_log_true_size(union bpf_a= ttr *attr, bpfptr_t uattr, un &attr->log_true_size); } =20 -static int copy_btf_load_log_true_size(union bpf_attr *attr, bpfptr_t uatt= r, unsigned int size) +static int check_btf_load_log_attrs(union bpf_attr *attr, struct bpf_commo= n_attr *common_attrs) +{ + int err; + + err =3D check_log_attrs(attr->btf_log_buf, attr->btf_log_size, attr->btf_= log_level, + common_attrs); + if (err) + return err; + + if (!attr->btf_log_buf && common_attrs->log_buf) { + attr->btf_log_buf =3D common_attrs->log_buf; + attr->btf_log_size =3D common_attrs->log_size; + attr->btf_log_level =3D common_attrs->log_level; + } + + return 0; +} + +static int copy_btf_load_log_true_size(union bpf_attr *attr, bpfptr_t uatt= r, unsigned int size, + struct bpf_common_attr *common_attrs, bpfptr_t uattr_common, + unsigned int size_common) { if (size >=3D offsetofend(union bpf_attr, btf_log_true_size) && copy_to_bpfptr_offset(uattr, offsetof(union bpf_attr, btf_log_true_si= ze), &attr->btf_log_true_size, sizeof(attr->btf_log_true_size))) return -EFAULT; =20 - return 0; + return copy_common_attr_log_true_size(uattr_common, size_common, + &attr->btf_log_true_size); } =20 static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr, unsigned int size, @@ -6328,9 +6349,13 @@ static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uatt= r, unsigned int size, err =3D bpf_raw_tracepoint_open(&attr); break; case BPF_BTF_LOAD: + err =3D check_btf_load_log_attrs(&attr, &common_attrs); + if (err) + break; attr.btf_log_true_size =3D 0; err =3D bpf_btf_load(&attr, uattr); - ret =3D copy_btf_load_log_true_size(&attr, uattr, size); + ret =3D copy_btf_load_log_true_size(&attr, uattr, size, &common_attrs, u= attr_common, + size_common); err =3D ret ? ret : err; break; case BPF_BTF_GET_FD_BY_ID: --=20 2.52.0