From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (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 41B6822DFBB; Thu, 24 Apr 2025 12:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745496048; cv=none; b=pW2ilFm1kh8n7dX87rITtIDHDNrZThaKWWp1PZa2CI8q4eXs6M8ZzkskG/szd+YskyGFTDJaYFnaurEF8z4G98vYOCoTv2IoT2x7jDkm6Z6yrJ8eF7+6a5wf+gMk5iMWzk3VCXqTBsPmS3PK2Ss0CSOuWEMaIAHa45iJIjzP1t4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745496048; c=relaxed/simple; bh=g6ZhCYqUsjw43UU7D94qUabJWGyv4hN727Jz1O4EMew=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=JHnLBh/zNE/somawXAYL0EGWBRBArnYCz5yOSr3AGsTgqynY3cqA6aqbpxZzURvKiIgqSgpeKgj2rVxCXv7SxQM5e3k+yhVo5PcHhVEm8SGRR7TG9n2VtXGHbRxvR6LACgLa/20n32n5d7ObH64Wg/JBX1xskm7uJ9Q5h9CjqpA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Zjvg35YvJz4f3k5x; Thu, 24 Apr 2025 20:00:15 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 6F12B1A18C2; Thu, 24 Apr 2025 20:00:34 +0800 (CST) Received: from [10.67.111.192] (unknown [10.67.111.192]) by APP4 (Coremail) with SMTP id gCh0CgCnVlveJwpoXVW4KQ--.17342S2; Thu, 24 Apr 2025 20:00:32 +0800 (CST) Message-ID: <6b6472c3-0718-4e60-9972-c166d51962a3@huaweicloud.com> Date: Thu, 24 Apr 2025 20:00:30 +0800 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC bpf-next 1/4] bpf: add struct largest member size in func model Content-Language: en-US To: =?UTF-8?Q?Alexis_Lothor=C3=A9?= , Andrii Nakryiko Cc: 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 , Puranjay Mohan , Catalin Marinas , Will Deacon , Mykola Lysenko , Shuah Khan , Maxime Coquelin , Alexandre Torgue , Florent Revest , Bastien Curutchet , ebpf@linuxfoundation.org, Thomas Petazzoni , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com References: <20250411-many_args_arm64-v1-0-0a32fe72339e@bootlin.com> <20250411-many_args_arm64-v1-1-0a32fe72339e@bootlin.com> From: Xu Kuohai In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:gCh0CgCnVlveJwpoXVW4KQ--.17342S2 X-Coremail-Antispam: 1UD129KBjvJXoWxAw4DtFy5WF18uFW8Wr4xXrb_yoW5CF4fpF WFgF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Wed Apr 23, 2025 at 7:15 PM CEST, Andrii Nakryiko wrote: >> On Thu, Apr 17, 2025 at 12:14 AM Alexis Lothoré >> wrote: >>> >>> Hi Andrii, >>> >>> On Wed Apr 16, 2025 at 11:24 PM CEST, Andrii Nakryiko wrote: >>>> On Fri, Apr 11, 2025 at 1:32 PM Alexis Lothoré (eBPF Foundation) >>>> wrote: > > [...] > >>> Indeed I initially checked whether I could return directly some alignment >>> info from btf, but it then involves the alignment computation in the btf >>> module. Since there could be minor differences between architectures about >>> alignment requirements, I though it would be better to in fact keep alignment >>> computation out of the btf module. For example, I see that 128 bits values >>> are aligned on 16 bytes on ARM64, while being aligned on 8 bytes on S390. >>> >>> And since for ARM64, all needed alignments are somehow derived from size >>> (it is either directly size for fundamental types, or alignment of the >>> largest member for structs, which is then size of largest member), >>> returning the size seems to be enough to allow the JIT side to compute >>> alignments. >> >> If you mean the size of "primitive" field and/or array element >> (applied recursively for all embedded structs/unions) then yes, that's >> close enough. But saying just "largest struct member" is wrong, >> because for >> >> struct blah { >> struct { >> int whatever[128]; >> } heya; >> }; >> >> >> blah.heya has a large size, but alignment is still just 4 bytes. > > Indeed, that's another case making my proposal fail :) > >> I'd suggest looking at btf__align_of() in libbpf (tools/lib/bpf/btf.c) >> to see how we calculate alignment there. It seems to work decently >> enough. It won't cover any arch-specific extra rules like double >> needing 16-byte alignment (I vaguely remember something like that for >> some architectures, but I might be misremembering), or anything >> similar. It also won't detect (I don't think it's possible without >> DWARF) artificially increased alignment with attribute((aligned(N))). > > Thanks for the pointer, I'll take a look at it. The more we discuss this > series, the less member size sounds relevant for what I'm trying to achieve > here. > > Following Xu's comments, I have been thinking about how I could detect the > custom alignments and packing on structures, and I was wondering if I could > somehow benefit from __attribute__ encoding in BTF info ([1]). But > following your hint, I also see some btf_is_struct_packed() in > tools/lib/bpf/btf_dump.c that could help. I'll dig this further and see if > I can manage to make something work with all of this. > With DWARF info, we might not need to detect the structure alignment anymore, since the DW_AT_location attribute tells us where the structure parameter is located on the stack, and DW_AT_byte_size gives us the size of the structure. > Thanks, > > Alexis > > [1] https://lore.kernel.org/bpf/20250130201239.1429648-1-ihor.solodrai@linux.dev/ >