From nobody Sat Jun 20 14:12:41 2026 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 D59304779BC for ; Thu, 30 Apr 2026 16:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777567302; cv=none; b=Qhx6V3pznOawCBpZqW6sjXZqPnPN8wiNnJ0L6tRYCQtdBr8KkyZhHJw51N99m71yV6pftP/Qw37LjyRwpS1ojUXdmfACf6aJfzpWqm/r9KXdOLzUlcKO9e8KCeDxU0Eu2KG+omirOmLiY7XUO9n7Rga6BcJ+aDvqg3sXMC4RIew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777567302; c=relaxed/simple; bh=Urv1NMxqy7fqRmjv6fW3AacM+kfhc4l6HlvpHKM8Hyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=azxwDYo/IC507TiIJtyAMfXNg/LcYp0OoWXcsDos6L5z4oi13IQKUu3UaZXOYlVvd/Jra4M2rhGDz60gpPGOb/lxtnHi4OboaJeWby/uBpck8+Jf/UADYZRj0tq6+vLGjl+dfwqiGYdBKqpNbZZR4hBgEpX06/ALCuagn1c9TaU= 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=Z3pccUkL; arc=none smtp.client-ip=209.85.215.182 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="Z3pccUkL" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-b6ce6d1d3dcso441815a12.3 for ; Thu, 30 Apr 2026 09:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1777567299; x=1778172099; 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=WYsW7L8CITDm1iPPurBgxm3JHO8q1VbtP3QHlmc070s=; b=Z3pccUkL+n10B1Zi18oJ1TPkesXoDjZ4/JbVYTgoFeAReoAglOgThco+xqmZMSf0F/ c5W1vPknOvjb4umoNch7PhlfwY7WssZ1DP4/nXwYLKE7cE+ZU6EphBo7+U5RHrxHZEZt UwiwNK7/Ew88kJhPRRmE8aTd6wg3icyXUfB/w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777567299; x=1778172099; 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=WYsW7L8CITDm1iPPurBgxm3JHO8q1VbtP3QHlmc070s=; b=LxXf0GvrDAYlpxo/06+M7qpbEQEgR+zAkPAO8KFiIOKrHEEOgjaPwHXVOYBDqnbwrs hayFFn+MWxe48ndUDunN989DFNei7QLD/qR21mr7pYHF7igmPGLA6c82FXpqXaUnuwbB W9mNao+BlLP9U4NctcCkYu4Hcyq+hNyAlrQJ50X7FYPFhDZruGWtd82TcQgWUg2zhuqN A2S8GfDf90bFpgSL60LZwRs6tmo48ZDIq7ZOvOrOcrz1IQnLf00LZ2D7q7laZq7AP36Y E7aEhCIqM2tU72pJKO7CmVBAXpWuyqJUCD7lBqnYposplAUxnnyPE/FwbAzw+Dop1uSG opsQ== X-Gm-Message-State: AOJu0YwTF2QD1J3M2pywyXfJPmoThrKy2lZ7+d3+a0HrslefwJd0Zeyb 4xDBxscGU0pLxPRPshmFchwa1ul023pOcDrv/8tPl0PY8ypgZ7VobzE3tEdmlY+llErgfjbYJ2Q dsoGY X-Gm-Gg: AeBDiev/kLiZRqkgVga2PHtFU78/eTAnXawZV/opZghoRxe88zWVNxB2+pR4gYZhxJg Andh0rcc5ZjFMSpEQ8eNw6K95QYB+sysy6sIZqVy6+f46NtCWT8dw2G8QVR6CO/7mpISyn2pDIK CnBRVGqZGAKPD8m5Zxcx4C29btP5wCqNlWG1/qQoDmC2rx8MSM5MUyEjTeCuAFrx3E1iRbnJTXJ XRIxzNPrg0G43DqzGugCt3KkZuUc/sC+QK/NRULg2qeT4h9Fhdquv2zdcBdbXvbwg1E/hPgB1OZ 0WGtlRVBuKW1qMsLeqqCLnntFW5dc04+0qa8ZaxnPR625RwZGBUSJIdoLX4hoz8Fdg3RUfg0r8E zvz8hcvmrXPgbsLGHNas5h4tMirEeH1HlgUmb8+EDb2JJ2FvR4R1ke52Gz1BLW6OwX6Z1RqHb5I HCSXILBEqumVDb5sXqdI4019Qqy56No4iwtBJOYHCROszsBdBf430UvMnF6FiMOQvLMqGdg5jPu g7SsnDf4q9SnguisDTWQf+H5uOl8YMT9OHdaA== X-Received: by 2002:a05:6a20:734e:b0:39f:82bd:298 with SMTP id adf61e73a8af0-3a3cf112d5bmr4427139637.0.1777567298834; Thu, 30 Apr 2026 09:41:38 -0700 (PDT) Received: from kinako.work.home.arpa (p1387170-ipxg00a01sizuokaden.shizuoka.ocn.ne.jp. [153.221.239.170]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-83515b543b0sm130519b3a.53.2026.04.30.09.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2026 09:41:38 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v3 1/2] tools/nolibc: fcntl: Add fallocate() Date: Fri, 1 May 2026 01:41:24 +0900 Message-ID: <20260430164125.1106350-2-daniel@thingy.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260430164125.1106350-1-daniel@thingy.jp> References: <20260430164125.1106350-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 Acked-by: Willy Tarreau --- tools/include/nolibc/arch-mips.h | 11 +++++++++++ tools/include/nolibc/fcntl.h | 33 ++++++++++++++++++++++++++++++++ tools/include/nolibc/sys.h | 8 ++++++++ 3 files changed, 52 insertions(+) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index 1400653c76c1..e4e42f2bcaf4 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" @@ -256,6 +257,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 014910a8e928..dbc99188a49e 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]); */ @@ -80,4 +83,34 @@ int creat(const char *path, mode_t mode) return open(path, O_CREAT | O_WRONLY | O_TRUNC, 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 offset and size, 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 33f9c970ae57..b7136a3a7d6a 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.53.0 From nobody Sat Jun 20 14:12:41 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 8DF394779B9 for ; Thu, 30 Apr 2026 16:41:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777567303; cv=none; b=QlOzKEm/l1AtDMqDZoEUModprnI1G/mv4jNA1odpAVX8i/PgoiuxJ3dL0Nhb6z07ma8bl21FJEkHr7QSbqAtyX0HK4tHMzvxO3JFAABiDWDHPCXkr2mKbvUjNuPWKWwn8d2rG3kq7d+wgnCIT3Qz37HuRCQkniGUpyodf6LzeHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777567303; c=relaxed/simple; bh=Q+mj5tOpWprawCyKSxQvWS9f0xkXgaZq6bjn0F/KSww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SQXtAuypGjzEIXezcqiAxaW+J4EK3cgXkoEU0lgaB7WfXLyjZzO/Fwi/ybQkjQtGkAGxbKvQ1uO5AK51B2YuOWvQ9iuL/SyI2nuA6BTCmMeVo/oB7xqdrQ+un7LfuSFBlhFuq9zUxcbK27CpQo94W++Dqu/CZO9lu9oHWeZ6yZI= 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=N6DmJap9; arc=none smtp.client-ip=209.85.210.177 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="N6DmJap9" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-83177129e28so552721b3a.1 for ; Thu, 30 Apr 2026 09:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1777567300; x=1778172100; 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=BmsKRGljhhKJgxL+hpJaEbt7k4QMLUdUPZtSPvqBX8E=; b=N6DmJap9lX1/0mxhBeeq8ahbp9W31qHpXbTLXHypuyX2X4tQHh/unhYwE9xV6whLaV gUjqYKPeX7sMD4cpir2utXuD4hLtR7HVnMLxguwsNGET+/49NCBvuFFcPQEkXfK5fXLK 68JyWN/CkAVipQrKVz7cG+MDy5lFsn/ktOCLA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777567300; x=1778172100; 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=BmsKRGljhhKJgxL+hpJaEbt7k4QMLUdUPZtSPvqBX8E=; b=DtDm88eiY2kApxFzHN5VNx2mUIj3VtY/PgulBMzbErms6Rghw6hYWiRWz2MQF7AYWs WMESS8ex7Jq06HS63n5kzGF7rjQFLPmevdUGuvWn3yfmXWFmeFBbtwLyuf9kvgaZPebY +IopK8ONo2RmpMx9LFbzx9bbxLeXy7AZbXUFV0o0HknrdabAghsa8WsILrGF6P/bNrCL hPMIOz9PUmJ1vTeclRkivL/PjLdLkNeg4oMQb+IFbbmvkTpbs47G7FFve+3nEIJE4j0x l5tOnR/ffcJSOhXVDOm8DfDLCSuMFefQh+XOKTpDBILHL5FsdsPLsW+C9L9NR50Q/G/s /8xg== X-Gm-Message-State: AOJu0YwVjmgACNhOFZ450pJFu0vDD00Vg0oIv7pjiwOhJbtORigN///d MMaLaUJLLTBrimMP18IPAPRHJS7dhopIfP9V7BKPC2FEPzkW709mVKqasJq7dTNmSvh+0i2FN8k mksPo X-Gm-Gg: AeBDieskNfo5qcNDZWJeKGo0Keqec9Rvy4CPADe12GYQVLGhfPhS3wfPR/sYN7+oYPm s8cXo5XEGOQAhgXvWqCIeLd+84m0whc8IaamgniU1r0P/HshQJPjyHs3ipo0wsJ6s0TDpRwyDnM 8kZSLb2nITED5Al3rMdJLPCArl2jDZJSiOgQjhr/EM+/xSMVK7xSgihY9EEpUldNwE63689Q2nX U1GcJbShAVFF+93orUM+GDoyQJS1LMYdut34u8p731oeMYgFlDUnM3UJkg2Nf7/lAy8aqECBF5s WHOOzWCOgM8ad9jUEFngwuwOauszk7hSn90by8L1pcrXUBzyPC4g1qkgzudur9kKtWHw8nkVR1i CkQA+MWunbr9o421DcfzvRUcPu2t2v2RFydKEMBO2Eb7Vmow6wSeuc4KfAlTer0F7nkjMWwfJpM V9ZdWEIh+Vo2i+GZSICL0vNm9QYWmElyWhSoI9t41DuajsY/W9GUncEpf3ZOMSNF0AXtUDQHR4t jgetWDlb5QWIN7g7CUhBL76oh4= X-Received: by 2002:a05:6a00:4503:b0:82d:5da9:adbf with SMTP id d2e1a72fcca58-834fdccc01fmr4688962b3a.41.1777567300396; Thu, 30 Apr 2026 09:41:40 -0700 (PDT) Received: from kinako.work.home.arpa (p1387170-ipxg00a01sizuokaden.shizuoka.ocn.ne.jp. [153.221.239.170]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-83515b543b0sm130519b3a.53.2026.04.30.09.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2026 09:41:39 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v3 2/2] selftests/nolibc: Add a very basic test for fallocate() Date: Fri, 1 May 2026 01:41:25 +0900 Message-ID: <20260430164125.1106350-3-daniel@thingy.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260430164125.1106350-1-daniel@thingy.jp> References: <20260430164125.1106350-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 << 20), this should work. 3: Try to fallocate() (1 << 52), this should cause ENOSPC or EFBIG. 2 and 3 are basically to make sure if the offset or size are split into a pair of registers for the syscall that we are passing them the correct way around. sparc32 seems to return EOPNOTSUPP for fallocate() so skip the test there. Signed-off-by: Daniel Palmer Acked-by: Willy Tarreau --- tools/testing/selftests/nolibc/nolibc-test.c | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 08610cacf030..a586e9d9ede2 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -89,6 +89,14 @@ static const int is_glibc =3D #endif ; =20 +static const int is_sparc32 =3D +#if defined(__sparc__) && !defined(__arch64__) + 1 +#else + 0 +#endif +; + #if !defined(NOLIBC) /* Some disabled tests may not compile. */ =20 @@ -898,6 +906,66 @@ 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 1MiB. This puts a single bit + * into one of the registers if the size is split into + * two registers. This shouldn't fail if the bit is in + * the correct register. + */ + r =3D fallocate(fd, 0, 0, (1ll << 20)); + if (r) + goto close_tmpfile; + + /* Check a massive size that puts a single bit into + * the other register if splitting. + * This should return an error and errno =3D ENOSPC or + * EFBIG indicating the value was passed correctly but it + * was rejected. + */ + r =3D fallocate(fd, 0, 0, (1ll << (20 + 32))); + if (r !=3D -1) { + r =3D -1; + goto close_tmpfile; + } + if (errno !=3D ENOSPC && 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; @@ -1507,6 +1575,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(!is_sparc32, 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.53.0