From nobody Tue Jun 16 08:55:58 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 313F638D6A3 for ; Fri, 17 Apr 2026 11:26:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776425194; cv=none; b=kFyK0C/+2lYObl0YvAm8+i9GquDcr0fVnt/X/zqZ7lx9oaB2O7Z/R+QbY2eHSBmDpVB0gkY/2n32Jav5Vz60XG+emgNjNt612nBdcXDgi/0JauVqCQMbrx3sAII5/xKbZM/0O6rZXeoDqpDYeUov2G80DQs82iagwbe+RTJiJUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776425194; c=relaxed/simple; bh=XWxbxly3C05WxnzOggJ3XL4kQdJP1qReZkFpEQ5thDU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A8e1Z6an5iyN+/xmQ3DDVu2ucgMk2T3UH5n8c0zG43X58zpHEBtrXCko6diN9p5krXnRTOBkYd+836rIJ1tGCJHReE9ZIjZRupaYwBZLwCK0PYpX17d0aUAatDB+reENaNDQLAs8q/GADiQmTbgaJjLz1bppwjbj0Aq/ou6PWaY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=g5mMZ+S7; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="g5mMZ+S7" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2b2429f98d0so3032275ad.2 for ; Fri, 17 Apr 2026 04:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1776425192; x=1777029992; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3F+FS0a+dkWq0VvcunVsHxcOiTsK17K0BF2llo9C6Xg=; b=g5mMZ+S723bqWnfUL0PhNplXdpZ1F3K9lxWnmahO+nLe2TClP6RmxX8b44of6l+DWN uRynbMO10CSFnZuPo1AtQttNXzRJGm3Vl5MUq5GiFcyOuHd/CIwvY+ukdsoQC93JQZXl PRGXwN+Bxvyhl7QOis6BWb5BleypFWwmgBx68= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776425192; x=1777029992; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=3F+FS0a+dkWq0VvcunVsHxcOiTsK17K0BF2llo9C6Xg=; b=kBCKoN5AfS10hD9Je3lZrHS2MOPTqer64kIeg2bc//osU/Zzqxxabh59I+Pup8OESt G4iAmYscRTTSYxHw4rBVDIoqaIcVFpox2/Gfci0ybKO+5tYNRq+/cIjzfiE8n4ORM0Kb JIVKvdGABlZwTNd9pGVAlGFh2C2PseGVlOibcKa5OPlyrdjSLhSx7RuSNfjnQQlb9tZU Av8UsOi/3AfWZ2YHHMb4thMdUfA+Qh9yK23bdQQwe22lbsHBCop9/m6i4pbOZn7KBlpq z39KarNJskjf8GZwT4UeALYLYKT2sekhqH5FThDoswBux84hdHpH9tHvH9JtdfVzF+m9 KFtQ== X-Gm-Message-State: AOJu0YxSgh4uzTTQhbtvbdxq5/KmqYg8utd0zSIWzi1arMOp4kDmU46Y OUR1E9bZcGZrrLCqLJkpyGztpSvgRHo0GLWAO8oOno7p0s9hMsrnSK9u7wOyVmwWY3g= X-Gm-Gg: AeBDieu3RD2bRUZ1sOjFy5+lJYDzBPmLbwMg1iBjEMLxzCyks2/fr0pCfPfEBd98fG/ pvEiQ+rH79rKEbpH3yB81jE5R0DPXknaUTJToXpf04RmoF59ao8N88Q8Pqij0i8V10fz/IGC8Nt 8iEmVWSLejN8u6SX9Mv6yGUnQtmFr/ep4c3o08cCID73WksjPUovTmhc2Ui4ODR8FSWY2LcpMey M2mlJ9yepj/Knl2hEY2Y/UvP7DFfB66sUfhnNfMX1HjDDEtmk0HMJaTpEJluiX9QoCDy0DVedxZ a8wWT2YC47ar8jZS3uE9rbzI6+zd34SAclkHTZzV6SVaMdEjJCAxcZ9o6FO/Z5ZJULkSPll7qi1 pV6hCzmYR06xNrb9GGfzH0Ey84QgNPp/K9uilSWPtutFkORNhbimYZOJzMa/RgNcj7miRAtrQdI FlAPJVOsLhDacnGhBowkfZYZKzDr8xeL977Om+zJL3w8YqHcEezeWts+pWXAA/2D5L0Uty5iw4i 85C7CSHG64zZRgL6db0HX8k X-Received: by 2002:a17:902:b697:b0:2b0:9a61:9e9 with SMTP id d9443c01a7336-2b5f9f61d3amr19886395ad.32.1776425192438; Fri, 17 Apr 2026 04:26:32 -0700 (PDT) Received: from kinako.work.home.arpa (p1329195-ipxg00a01sizuokaden.shizuoka.ocn.ne.jp. [114.145.5.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2b5faa2e5cesm21407035ad.25.2026.04.17.04.26.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2026 04:26:32 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v2 1/2] tools/nolibc: fcntl: Add fallocate() Date: Fri, 17 Apr 2026 20:26:21 +0900 Message-ID: <20260417112622.1182216-2-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260417112622.1182216-1-daniel@thingy.jp> References: <20260417112622.1182216-1-daniel@thingy.jp> 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 Content-Type: text/plain; charset="utf-8" Add fallocate(). Some special care is needed to put the offset and size into the syscall parameters for 32bit machines, x32, and mipsn32. For x32 we can just check if the kernel long size is the same as off_t and use the same path as x86_64. For mipsn32 we override the generic version and provide one that does the right thing. Signed-off-by: Daniel Palmer --- tools/include/nolibc/arch-mips.h | 11 +++++++++++ tools/include/nolibc/fcntl.h | 32 ++++++++++++++++++++++++++++++++ tools/include/nolibc/sys.h | 8 ++++++++ 3 files changed, 51 insertions(+) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index bb9d580ea1b1..2c5cda632911 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -6,6 +6,7 @@ =20 #ifndef _NOLIBC_ARCH_MIPS_H #define _NOLIBC_ARCH_MIPS_H +#include =20 #include "compiler.h" #include "crt.h" @@ -252,6 +253,16 @@ _arg4 ? -_num : _num; \ }) =20 +/* The generic version of this will split offset and size for _ABIN32, + * override it and do the right thing here. + */ +static __attribute__((unused)) +int _sys_fallocate(int fd, int mode, off_t offset, off_t size) +{ + return __nolibc_syscall4(__NR_fallocate, fd, mode, offset, size); +} +#define _sys_fallocate _sys_fallocate + #endif /* _ABIO32 */ =20 #ifndef NOLIBC_NO_RUNTIME diff --git a/tools/include/nolibc/fcntl.h b/tools/include/nolibc/fcntl.h index ed2f5553c65a..e65be2f84cbd 100644 --- a/tools/include/nolibc/fcntl.h +++ b/tools/include/nolibc/fcntl.h @@ -14,6 +14,9 @@ #include "types.h" #include "sys.h" =20 +/* For fallocate() modes */ +#include + /* * int openat(int dirfd, const char *path, int flags[, mode_t mode]); */ @@ -66,4 +69,33 @@ int open(const char *path, int flags, ...) return __sysret(_sys_open(path, flags, mode)); } =20 +/* + * int fallocate(int fd, int mode, off_t offset, off_t size); + */ + +#if !defined(_sys_fallocate) +static __attribute__((unused)) +int _sys_fallocate(int fd, int mode, off_t offset, off_t size) +{ + /* + * For 32 bit machines __kernel_long_t will be 4, off_t will be 8 + * and we need to split it for 64 machines we can use the values as-is + */ + const bool offsetsz_two_args =3D sizeof(__kernel_long_t) !=3D sizeof(off_= t); + + 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); +} +#endif + +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 */ diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 6335fd51f07f..4f4491af9426 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -29,6 +29,14 @@ #include "stdarg.h" #include "types.h" =20 +/* + * Helper for 32bit machines where a 64bit syscall arg needs to be split i= nto + * two 32bit parts while making sure the order of the low/high parts are c= orrect + * for the endian: + * __NOLIBC_LLARGPART(x, 0), __NOLIBC_LLARGPART(x, 1) + */ +#define __NOLIBC_LLARGPART(_arg, _part) \ + (((union { long long ll; long l[2]; }) { .ll =3D _arg }).l[_part]) =20 /* Syscall return helper: takes the syscall value in argument and checks f= or an * error in it. This may only be used with signed returns (int or long), b= ut --=20 2.51.0 From nobody Tue Jun 16 08:55:58 2026 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9882138F23A for ; Fri, 17 Apr 2026 11:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776425196; cv=none; b=trTKQcAZGgzW+hecJFXyWIDURwnA26ws+aGJA9guEf4FFcqtA51ZxPuj/4qfznBQvaxn4Xb+pR7BWy6faX7sJyecnLpuIoZFPT1iRvuj40j8BU+eh2kJaQHOGHiQ9RIh+G71p0Ts8pCtpIJuY4r+aaAoYPHH1LUj3fuosUV0qBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776425196; c=relaxed/simple; bh=pip/hk2yvLKdGfeGANiXPHHeth7OM6uNiuH2AvXqSMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PK94zCaT/DtL5oA+T2atbHQKq6hQwWR6MwavJe3Y/HOM+G55ed8id22uaeswrN1NECaNG+Jt7WZ0fNQb7Xd2SM3R5rbwJevROfx8JrnIQHcnQz1voj7mrOJd/ZvSWEB/20jjdHhcahcjG2yz7/H/6r2RbnOfV3MI4NB86xJV0mk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=HbNybBu5; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="HbNybBu5" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-36143b0dbdbso212577a91.2 for ; Fri, 17 Apr 2026 04:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1776425194; x=1777029994; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kyAwC7S7/jOi7XNSEXsqrfiZtwsiSBzqI812noxwDq4=; b=HbNybBu51dC21Q6IzYxBByWT7NhMsKz0MJHrxvNE4d8jveHk1fZhMxcLLxOPd0XJy9 pfsxZOzoDfyI6/RLCbAGsD47nhIkhZTkBbbAT8GT2IUYe+wtzmE2koLJqEUQkhthgNIN 4moJbtlO2YeOZmRTLr2oZBPVPkuKOlcxy1tf4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776425194; x=1777029994; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kyAwC7S7/jOi7XNSEXsqrfiZtwsiSBzqI812noxwDq4=; b=pyyMVKpM1ctVM/GToyAVD0Wb0Ec2lQelcm6iOlplX4sk6eAx9tMpXo/i8bSk7uX7SO KPRUzie7jbrh7gtrBG6nsMCu1sbjOXmIU2KjSz2ygC30cc/m/1CvjOXN+dzrycxoGS60 PbdD6vuuxGsqtyOTklVYmgS6kf8bHprfF5f25ccCFCfGGZHAMt/OfxXGQkrLbi6xk4JA DcPyHFOlbnkEllcbtpSaUcR9AN2bgXdKSpFUZGeSmYztWEt50ZRpm2v1arzOipXFKXV8 vIt/G3afQQTwKgEmPr9TG+uxXmbSyLlW4eF1JXXgaRXTfwIIo5nJjUenoWgnBZ1YIUHd n60Q== X-Gm-Message-State: AOJu0YxPgcmvNua8MSDDjQlWNBgDt6rwzqqPDOhdO5SqDwuCJyO6DSV9 5UYmHwpRLy7CD8ZMga97ce/suveAOwm6VT4Leno10lNZrsUoFMRhKq14+dQKmpTJsjk= X-Gm-Gg: AeBDieutnHWzPs2HH4ITHSn+lf7Q7C0gt06Pg30NJUnnvzd8znGQm5VwZ7Pn00eLquE ub0y+7Z/HtS59QQHLlt4oZAk6zVNJGHsYNZ7KOl0e3vK7KMWA1cIjAxEyNusiJTE8rgGAODPcio n4hHk69FEnh4H5/3wEe9yA6rp9DLo0FtuaUQnfSvy9yaErVMkGJKc6CqUeb7jANtrWOr4VV+o4Q S8xT2+4zJvUFHog2HizFlhTWDCLc/UZcA1I2RsOEgiVh0f9mAX+kdVhaNEmTMdJefDt6gdYmNIp rJufoWKCQcrdFfA3wRb465MbScc+IBuePBkiF4kdFRxDvsXyCwc50S/gScgSB0tviVZueoHROmG N13wDgyJ8+8i7IfRl2HNHKZC42IKbAnZFx6VG+YlAIVx0AohnpR7cQfILY5sAzfpL9/8mb8iqd5 tPB4JEIeBANHgvC4IzIPXGqECM/K4shyvQnAYH6pqugNqGz55yi/csk0LTSTz0sfoOga+I9sEl+ sd+rBQ6gzt5rA1UVY/3APRT9hFiSge0UeM= X-Received: by 2002:a17:90a:f94f:b0:35e:576e:5bc with SMTP id 98e67ed59e1d1-361404990eamr2454382a91.25.1776425193913; Fri, 17 Apr 2026 04:26:33 -0700 (PDT) Received: from kinako.work.home.arpa (p1329195-ipxg00a01sizuokaden.shizuoka.ocn.ne.jp. [114.145.5.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2b5faa2e5cesm21407035ad.25.2026.04.17.04.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2026 04:26:33 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v2 2/2] selftests/nolibc: Add a very basic test for fallocate() Date: Fri, 17 Apr 2026 20:26:22 +0900 Message-ID: <20260417112622.1182216-3-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260417112622.1182216-1-daniel@thingy.jp> References: <20260417112622.1182216-1-daniel@thingy.jp> 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 Content-Type: text/plain; charset="utf-8" 1: Create a tmp file, fallocate() to make it a bit bigger, check the size is what was expected. 2: Try to fallocate() (1 << 28), 3: Try to fallocate() (1 << 60), this causes a EFBIG Signed-off-by: Daniel Palmer --- tools/testing/selftests/nolibc/nolibc-test.c | 58 ++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index d3c4facb54c0..6dcc2f631c3e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -896,6 +896,63 @@ int test_getpagesize(void) return !c; } =20 +int test_fallocate(void) +{ + struct stat st; + int fd, r; + + /* Create a new tmp file */ + fd =3D open("/tmp", O_TMPFILE | O_RDWR, 0644); + if (fd =3D=3D -1) + return -1; + + /* Expand it to 42 bytes */ + r =3D fallocate(fd, 0, 0, 42); + if (r) + goto close_tmpfile; + + /* Get the new stat */ + r =3D fstat(fd, &st); + if (r) + goto close_tmpfile; + + /* It should be 42 bytes long */ + if (st.st_size !=3D 42) { + r =3D -1; + goto close_tmpfile; + } + + /* Now try to allocate 256MiB, this shouldn't fail + */ + r =3D fallocate(fd, 0, 0, (1ll << 28)); + if (r) + goto close_tmpfile; + + /* Check that a massive size that happens to be the + * opposite endian version of the above. This should + * returns an error and errno =3D EFBIG indicating the + * value was passed correctly but the kernel rejected + * it. + */ + r =3D fallocate(fd, 0, 0, (1ll << (28 + 32))); + if (r !=3D -1) { + r =3D -1; + goto close_tmpfile; + } + if (errno !=3D EFBIG) { + r =3D -1; + goto close_tmpfile; + } + + /* Test passed */ + r =3D 0; + +close_tmpfile: + close(fd); + + return r; +} + int test_file_stream(void) { FILE *f; @@ -1442,6 +1499,7 @@ int run_syscall(int min, int max) CASE_TEST(dup3_0); tmp =3D dup3(0, 100, 0); EXPECT_SYSNE(1, = tmp, -1); close(tmp); break; CASE_TEST(dup3_m1); tmp =3D dup3(-1, 100, 0); EXPECT_SYSER(1, = tmp, -1, EBADF); if (tmp !=3D -1) close(tmp); break; CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0]= =3D "/", [1] =3D NULL }, NULL), -1, EACCES); break; + CASE_TEST(fallocate); EXPECT_SYSZR(1, test_fallocate()); break; CASE_TEST(fchdir_stdin); EXPECT_SYSER(1, fchdir(STDIN_FILENO), -1, = ENOTDIR); break; CASE_TEST(fchdir_badfd); EXPECT_SYSER(1, fchdir(-1), -1, EBADF); br= eak; CASE_TEST(file_stream); EXPECT_SYSZR(1, test_file_stream()); break; --=20 2.51.0