From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 AFFBE3E3C45 for ; Wed, 15 Apr 2026 15:56:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776268605; cv=none; b=UUHbYOUV/JhZ1jVPM7wBL7G6oE59EJuDXFEs3mR5AwJJKR/zKD8y7ItjzjkQIqYG1DNU5Y1xbQ1Qo0E7O02ZITFgppfvj/5c/1QOsjw0jgWuz/N8mxkvkR7L4KATt+az+SfXNF9RHYNEeyAh/Lj3VLwX/AVS0Zy+kWvKlgyF2zQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776268605; c=relaxed/simple; bh=2EUEjLqLyl/TwRf1Vtu0TUYjN62+/XyXB4IjPNLkd0g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CJMJpaFJyc9vuos2eU8QKHLAJ09sCOckiSjAaPnTPT4HXXqO9nrP/yBwvWh5u2zaeqCynmBhFJae7mkFkYgPkUOXDZW5mb2xx1iddnDgj0kv7f29l95oqEgefwKywyDwonA27uKkox9A/+iEB06B3FUsdl7R/VjZh1g76hHNR+g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=b9ZMJNFP; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="b9ZMJNFP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1776268594; bh=2EUEjLqLyl/TwRf1Vtu0TUYjN62+/XyXB4IjPNLkd0g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=b9ZMJNFPqNI3dl3AaPI+0I03Zdws21/0LVf8VKMY9uk9vvjAU9tqWUqoZF/11kZ82 JcTdS+qdEVDdm21sqbnHuefRp5K9jIlKyeGM+BwyHgYkVh7Gjwx6BNQh7ioiA8Q5vg h60KWSG8DM2YEMF5TtKex/HWYPkwEUAD7DOVGqbc= Date: Wed, 15 Apr 2026 17:56:34 +0200 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Daniel Palmer Cc: w@1wt.eu, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] tools/nolibc: fcntl: Add fallocate() Message-ID: References: <20260415143225.561998-1-daniel@thingy.jp> <20260415143225.561998-2-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260415143225.561998-2-daniel@thingy.jp> Hi Daniel! thanks for the patches. On 2026-04-15 23:32:24+0900, Daniel Palmer wrote: > Add fallocate(), some special care is needed to > put the offset and size into the syscall parameters > for 32bit machines and for x32. > > Signed-off-by: Daniel Palmer > --- > tools/include/nolibc/fcntl.h | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/tools/include/nolibc/fcntl.h b/tools/include/nolibc/fcntl.h > index ed2f5553c65a..0ebfdb7bc792 100644 > --- a/tools/include/nolibc/fcntl.h > +++ b/tools/include/nolibc/fcntl.h > @@ -66,4 +66,34 @@ int open(const char *path, int flags, ...) > return __sysret(_sys_open(path, flags, mode)); > } > > +/* > + * int fallocate(int fd, int mode, off_t offset, off_t size); > + */ > + > +#define __NOLIBC_LLARGPART(_arg, _part) \ > + (((union { long long ll; long l[2]; }) { .ll = _arg }).l[_part]) This should go into sys.h, as it is fairly generic. > +static __attribute__((unused)) > +int sys_fallocate(int fd, int mode, off_t offset, off_t size) This should be _sys_fallocate() to avoid clashing with user symbols. > +{ > +#if defined(__x86_64__) && defined(__ILP32__) > + const bool offsetsz_two_args = false; > +#else > + const bool offsetsz_two_args = sizeof(long) != sizeof(off_t); > +#endif We try to avoid architecture-specific logic in the generic files. x32 would be covered with sizeof(__kernel_long_t). But MIPS N32 is also detected incorrectly here. In my opinion the best solution would be to have an override mechansim like for _sys_mmap and override it for x32 and N32 in arch-x86.h and arch-mips.h. Maybe also look at the recent proposal for ftruncate() which is somewhat related: https://git.kernel.org/pub/scm/linux/kernel/git/thomas.weissschuh/linux.git/commit/?h=b4/nolibc-ftruncate https://lore.kernel.org/lkml/20260303010039.2969125-2-jordanrichards@google.com/ > + > + if (offsetsz_two_args) > + return __nolibc_syscall6(__NR_fallocate, fd, mode, > + __NOLIBC_LLARGPART(offset, 0), __NOLIBC_LLARGPART(offset, 1), > + __NOLIBC_LLARGPART(size, 0), __NOLIBC_LLARGPART(size, 1)); > + else > + return __nolibc_syscall4(__NR_fallocate, fd, mode, offset, size); > +} > + > +static __attribute__((unused)) > +int fallocate(int fd, int mode, off_t offset, off_t size) > +{ > + return __sysret(sys_fallocate(fd, mode, offset, size)); > +} > + > #endif /* _NOLIBC_FCNTL_H */ > -- > 2.51.0 >