From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6555 invoked by alias); 10 Nov 2013 08:24:34 -0000 Mailing-List: contact libc-ports-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: libc-ports-owner@sourceware.org Received: (qmail 6544 invoked by uid 89); 10 Nov 2013 08:24:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Nov 2013 08:24:31 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1VfQJb-00061f-Qc from ChungLin_Tang@mentor.com ; Sun, 10 Nov 2013 00:24:15 -0800 Received: from SVR-ORW-FEM-04.mgc.mentorg.com ([147.34.97.41]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Sun, 10 Nov 2013 00:24:15 -0800 Received: from [0.0.0.0] (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.2.247.3; Sun, 10 Nov 2013 00:24:14 -0800 Message-ID: <527F42AF.8060204@codesourcery.com> Date: Sun, 10 Nov 2013 08:24:00 -0000 From: Chung-Lin Tang User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Chris Metcalf , "libc-ports@sourceware.org" , Andrew Pinski Subject: Re: struct statfs/statfs64 in linux-generic References: <52774A2F.5010505@codesourcery.com> <527BF01B.9080704@tilera.com> In-Reply-To: <527BF01B.9080704@tilera.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2013-11/txt/msg00005.txt.bz2 On 2013/11/8 03:55 AM, Chris Metcalf wrote: > On 11/4/2013 2:18 AM, Chung-Lin Tang wrote: >> Hi, >> >> I'm currently working on the glibc port for Altera Nios II, and per the >> kernel upstreaming requirements, we're making it a user of linux-generic >> in glibc. >> >> I've come across an issue about struct statfs/statfs64, where I've >> listed the struct definitions in both glibc and the kernel below. >> >> In linux-generic, both struct statfs/statfs64 has some fields as 64-bit >> words, padded properly if need on 32-bit targets. Effectively, they have >> to be same-format, to pass to the statfs64 syscall uniformly. >> >> __SWORD_TYPE appears to be int/long on 32/64-bit targets. This means >> that for 32-bit targets, struct statfs[64] will be made of 32-bit words, >> with a few 64-bit fields embedded in the middle. >> >> >> In the kernel however, the fields of importance in struct statfs is made >> up of entirely '__statfs_word', defined to be 64-bit or 32-bit depending >> on target (putting aside signedness for now). > > I have to carefully swap all this stuff back into my head every time I look at this issue :-) Thanks for caring to do that :) > For native 32-bit (for us that means tilepro) the constraint is that the kernel's "struct statfs64" has to match the two structs in glibc's . Most of the statfs types are fixed-size (fsid_t and the __u64 types), with __statfs_word/__SWORD_TYPE being the exception. For tilepro both of those kernel and glibc types are 32-bit types. > > For 32-bit userspace in a 64-bit kernel (for us that means tilegx -m32) the constraint is that the kernel's "struct compat_statfs64" match the types, which again, it seems that they should. (Note that tilegx -m32 is explicitly a "compat" syscall model.) > > A quick look suggests that nios2 is a pure 32-bit architecture, so more like the tilepro model. > > Andrew Pinski's email was a bit confusing since __SYSCALL_SLONG_TYPE seems to be the same size as __SWORD_TYPE, and I don't see any redefinitions of it for aarch64. I believe his usecase is the 32-bit userspace on 64-bit kernel model. One thing to watch out for is that some architectures (like x32) actually use the 64-bit syscalls natively (no compat_statfs64) so they need to use "long long" types to match the 64-bit fields, etc., so it's a different problem. In retrospect that might have been a cleaner model for tilegx -m32, but I suspect that ship has sailed for us. > > In your followup email you write: > >> Still, I'm not sure if using full 64-bit fields should be the intended >> solution. A full 32-bit target should be able to have those fields as >> 32-bit (which means a kernel patch to differentiate the current uses of >> '__statfs_word' into 32/64-bit words) > > I have a guess as to what the problem you're seeing is: are you looking at "struct statfs" in the kernel? That structure is completely unused on 32-bit platforms, since it's only relevant for the 64-bit platform's sys_statfs/sys_fstatfs syscalls, whereas on 32-bit platforms you only get sys_statfs64/sys_fstatfs64. In other words there is no syscall that fills in a structure with 32-bit "f_blocks" (for example). See the __NR3264_statfs macro in and how it resolves with the __SC_COMP_3264() macro, to the __SC_3264() macro, to the 32-bit version of the syscall. I think I found my problem, which is more simpler than I thought: unlike the majority of targets, 64-bit types are 4-byte aligned under Nios II, which causes a 4-byte difference between the glibc/kernel structure definitions because the kernel one doesn't have __attribute__((aligned(8))) forced on to it. Stack alignment is 4-bytes as well in nios2, so I'll probably be maintaining that and using a specific nios2/bits/statfs.h header without the double-word alignment bits. Thanks, Chung-Lin