nolibc: Add fallocate()
Subsystems (2)
v3 cover nolibc: Add fallocate()
While poking around with my "static PIE for nommu" series I found I needed fallocate(). Implementing it turned out a bit more interesting than I thought it would be due to how the offset and size need to be passed on 32bit machines.
v3:
- Reworked the test a bit, ran it on all the targets I could get to run (s390, loongarch and sh currently don't work for me). sparc32 doesn't seem to support fallocate() so made it skip the test.
- Rebase on nolibc/for-next with the large file support bits.
v2:
- Addressed Thomas' comments
- Trial and error'd a test for the arguments being passed correctly. Hopefully someone smarter than I am can tell if it actually works.
Daniel Palmer (2):
tools/nolibc: fcntl: Add fallocate() selftests/nolibc: Add a very basic test for fallocate()
tools/include/nolibc/arch-mips.h | 11 ++++ tools/include/nolibc/fcntl.h | 33 ++++++++++ tools/include/nolibc/sys.h | 8 +++ tools/testing/selftests/nolibc/nolibc-test.c | 69 ++++++++++++++++++++ 4 files changed, 121 insertions(+)
Signature · 1 line
2.53.0
PATCH v3 1/2 tools/nolibc: fcntl: Add fallocate()
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.
--- tools/include/nolibc/arch-mips.h | 11 +++++++++++ tools/include/nolibc/fcntl.h | 33 ++++++++++++++++++++++++++++++++ tools/include/nolibc/sys.h | 8 ++++++++ 3 files changed, 52 insertions(+)
tools/include/nolibc/arch-mips.h +11 -0
@@ -6,6 +6,7 @@#ifndef _NOLIBC_ARCH_MIPS_H#define _NOLIBC_ARCH_MIPS_H +#include <linux/unistd.h> #include "compiler.h" #include "crt.h"
@@ -256,6 +257,16 @@ _arg4 ? -_num : _num; \ }) +/* 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 */ #ifndef NOLIBC_NO_RUNTIME
tools/include/nolibc/fcntl.h +33 -0
@@ -14,6 +14,9 @@#include "types.h" #include "sys.h" +/* For fallocate() modes */ +#include <linux/falloc.h> +/* * 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); } +/* +* 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 =sizeof (__kernel_long_t) !=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 */
tools/include/nolibc/sys.h +8 -0
@@ -29,6 +29,14 @@#include "stdarg.h" #include "types.h" +/* +* Helper for 32bit machines where a 64bit syscall arg needs to be split into +* two 32bit parts while making sure the order of the low/high parts are correct +* for the endian: +* __NOLIBC_LLARGPART(x, 0), __NOLIBC_LLARGPART(x, 1) +*/ +#define __NOLIBC_LLARGPART (_arg, _part) \ + (((union { long long ll; long l[2]; }) { .ll = _arg }).l[_part])/* Syscall return helper: takes the syscall value in argument and checks for an * error in it. This may only be used with signed returns (int or long), but
Signature · 1 line
2.53.0
Re: [PATCH v3 1/2] tools/nolibc: fcntl: Add fallocate()
Quoted 70 lines · On Fri, 1 May 2026 01:41:24 +0900 Daniel Palmer <[email protected]> wrote:
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_tand use the same path asx86_64.For mipsn32 we override the generic version and provide one that does the right thing.
Signed-off-by Daniel Palmer <[email protected]>--- tools/include/nolibc/arch-mips.h | 11 +++++++++++ tools/include/nolibc/fcntl.h | 33 ++++++++++++++++++++++++++++++++ tools/include/nolibc/sys.h | 8 ++++++++ 3 files changed, 52 insertions(+)tools/include/nolibc/arch-mips.h +11
-0@@ -6,6 +6,7 @@#ifndef _NOLIBC_ARCH_MIPS_H#define _NOLIBC_ARCH_MIPS_H +#include <linux/unistd.h> #include "compiler.h" #include "crt.h" @@ -256,6 +257,16 @@ _arg4 ? -_num : _num; \ }) +/* 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 */ #ifndef NOLIBC_NO_RUNTIME tools/include/nolibc/fcntl.h +7
-0@@ -14,6 +14,9 @@#include "types.h" #include "sys.h" +/* For fallocate() modes */ +#include <linux/falloc.h> +/* * 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); } +/* +* int fallocate(int fd, int mode, off_t offset, off_t size); +*/ +
tools/include/nolibc/fcntl.h int creat(const char *path, mode_t mode) · line 99
Quoted 10 lines
tools/include/nolibc/fcntl.h +10
-0+#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 =sizeof (__kernel_long_t) !=sizeof (off_t);
I don't think you care about the size of off_t.
Were it to be 4 the code would be badly wrong.
tools/include/nolibc/fcntl.h int creat(const char *path, mode_t mode) · line 107
Quoted 8 lines
tools/include/nolibc/fcntl.h +8
-0+ +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); +}
The above might be more readable as:
if (sizeof(__kernel_long_t) == 8)
/* 64 bit, values fit in single arguments */
return __nolibc_syscall4(__NR_fallocate, fd, mode, offset, size);
/* 32 bit, values need splitting, order depends on endianness */
/* This test for endianness doesn't rely on any pre-processor defines */
if (({union {int x; char c;} u; u.x = 1; u.c;}))
/* Little endian */
return __nolibc_syscall6(__NR_fallocate, fd, mode,
offset, offset >> 32, size, size >> 32);
/* Big endian */
return __nolibc_syscall6(__NR_fallocate, fd, mode,
offset >> 32, offset, size >> 32, size);Although you might want to change/factor out the endianness test.
-- David
Quoted 28 lines
tools/include/nolibc/fcntl.h +8
-0+#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 */ tools/include/nolibc/sys.h +8
-0@@ -29,6 +29,14 @@#include "stdarg.h" #include "types.h" +/* +* Helper for 32bit machines where a 64bit syscall arg needs to be split into +* two 32bit parts while making sure the order of the low/high parts are correct +* for the endian: +* __NOLIBC_LLARGPART(x, 0), __NOLIBC_LLARGPART(x, 1) +*/ +#define __NOLIBC_LLARGPART (_arg, _part) \ + (((union { long long ll; long l[2]; }) { .ll = _arg }).l[_part])/* Syscall return helper: takes the syscall value in argument and checks for an * error in it. This may only be used with signed returns (int or long), but
Willy Tarreau
maintainerRe: [PATCH v3 1/2] tools/nolibc: fcntl: Add fallocate()
Quoted 97 lines · David Laight
Quoted 70 lines · On Fri, 1 May 2026 01:41:24 +0900 Daniel Palmer <[email protected]> wrote:
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_tand use the same path asx86_64.For mipsn32 we override the generic version and provide one that does the right thing.
Signed-off-by Daniel Palmer <[email protected]>--- tools/include/nolibc/arch-mips.h | 11 +++++++++++ tools/include/nolibc/fcntl.h | 33 ++++++++++++++++++++++++++++++++ tools/include/nolibc/sys.h | 8 ++++++++ 3 files changed, 52 insertions(+)tools/include/nolibc/arch-mips.h +11
-0@@ -6,6 +6,7 @@#ifndef _NOLIBC_ARCH_MIPS_H#define _NOLIBC_ARCH_MIPS_H +#include <linux/unistd.h> #include "compiler.h" #include "crt.h" @@ -256,6 +257,16 @@ _arg4 ? -_num : _num; \ }) +/* 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 */ #ifndef NOLIBC_NO_RUNTIME tools/include/nolibc/fcntl.h +7
-0@@ -14,6 +14,9 @@#include "types.h" #include "sys.h" +/* For fallocate() modes */ +#include <linux/falloc.h> +/* * 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); } +/* +* int fallocate(int fd, int mode, off_t offset, off_t size); +*/ +tools/include/nolibc/fcntl.h int creat(const char *path, mode_t mode) · line 99
Quoted 10 lines
tools/include/nolibc/fcntl.h +10
-0+#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 =sizeof (__kernel_long_t) !=sizeof (off_t);I don't think you care about the size of
off_t.
Were it to be 4 the code would be badly wrong.tools/include/nolibc/fcntl.h int creat(const char *path, mode_t mode) · line 107
Quoted 8 lines
tools/include/nolibc/fcntl.h +8
-0+ +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); +}The above might be more readable as:
Quoted 13 lines
if (sizeof(__kernel_long_t) == 8)
/* 64 bit, values fit in single arguments */
return __nolibc_syscall4(__NR_fallocate, fd, mode, offset, size);
/* 32 bit, values need splitting, order depends on endianness */
/* This test for endianness doesn't rely on any pre-processor defines */
if (({union {int x; char c;} u; u.x = 1; u.c;}))
/* Little endian */
return __nolibc_syscall6(__NR_fallocate, fd, mode,
offset, offset >> 32, size, size >> 32);
/* Big endian */
return __nolibc_syscall6(__NR_fallocate, fd, mode,
offset >> 32, offset, size >> 32, size);Honestly David, I find Daniel's version way more readable :-) Precisely because the repeated variations are abstracted with this more readable macro. If it was used only once I could possibly agree. Even the endianness test is hard to read, better rely on __BYTE_ORDER__ for this.
Cheers,
Willy
Re: [PATCH v3 1/2] tools/nolibc: fcntl: Add fallocate()
Quoted 112 lines · On Sat, 2 May 2026 05:00:06 +0200 Willy Tarreau <[email protected]> wrote:
Quoted 97 lines · David Laight
Quoted 70 lines · On Fri, 1 May 2026 01:41:24 +0900 Daniel Palmer <[email protected]> wrote:
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_tand use the same path asx86_64.For mipsn32 we override the generic version and provide one that does the right thing.
Signed-off-by Daniel Palmer <[email protected]>--- tools/include/nolibc/arch-mips.h | 11 +++++++++++ tools/include/nolibc/fcntl.h | 33 ++++++++++++++++++++++++++++++++ tools/include/nolibc/sys.h | 8 ++++++++ 3 files changed, 52 insertions(+)tools/include/nolibc/arch-mips.h +11
-0@@ -6,6 +6,7 @@#ifndef _NOLIBC_ARCH_MIPS_H#define _NOLIBC_ARCH_MIPS_H +#include <linux/unistd.h> #include "compiler.h" #include "crt.h" @@ -256,6 +257,16 @@ _arg4 ? -_num : _num; \ }) +/* 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 */ #ifndef NOLIBC_NO_RUNTIME tools/include/nolibc/fcntl.h +7
-0@@ -14,6 +14,9 @@#include "types.h" #include "sys.h" +/* For fallocate() modes */ +#include <linux/falloc.h> +/* * 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); } +/* +* int fallocate(int fd, int mode, off_t offset, off_t size); +*/ +tools/include/nolibc/fcntl.h int creat(const char *path, mode_t mode) · line 99
Quoted 10 lines
tools/include/nolibc/fcntl.h +10
-0+#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 =sizeof (__kernel_long_t) !=sizeof (off_t);I don't think you care about the size of
off_t.
Were it to be 4 the code would be badly wrong.tools/include/nolibc/fcntl.h int creat(const char *path, mode_t mode) · line 107
Quoted 8 lines
tools/include/nolibc/fcntl.h +8
-0+ +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); +}The above might be more readable as:
Quoted 13 lines
if (sizeof(__kernel_long_t) == 8) /* 64 bit, values fit in single arguments */ return __nolibc_syscall4(__NR_fallocate, fd, mode, offset, size); /* 32 bit, values need splitting, order depends on endianness */ /* This test for endianness doesn't rely on any pre-processor defines */ if (({union {int x; char c;} u; u.x = 1; u.c;})) /* Little endian */ return __nolibc_syscall6(__NR_fallocate, fd, mode, offset, offset >> 32, size, size >> 32); /* Big endian */ return __nolibc_syscall6(__NR_fallocate, fd, mode, offset >> 32, offset, size >> 32, size);
Quoted 5 lines
Honestly David, I find Daniel's version way more readable :-) Precisely because the repeated variations are abstracted with this more readable macro. If it was used only once I could possibly agree. Even the endianness test is hard to read, better rely on
__BYTE_ORDER__for this.
I did say 'might' :-) and I should probably have used __BYTE_ORDER__.
Looking again, the code is trying to copy what the compiler generates when it passes a 64bit quantity on stack or in 2 registers.
So f(a, b, c, d) is traditionally 'push d; push c; push b, push a; call f'. With the normal 'stack grows down' this gives (in increasing addresses):
return address
a
b
c
d
If 'b,c' is replaced by a 64bit value then you want the stack memory to contain the correct representation of a 64bit value.
So for LE you need to pass the low part before the high part.
But there is one architecture (parisc) where the stack goes the other way. It is BE (I believe), but would need the LE argument order.
I think all the conditionals could be moved out of the fallocate code. I'm not sure of the exact pre-processor conditionals but something like:
#if (__BITS_PER_LONG == 64) || defined(x86_x32) || defined(mips_n32) #define __NOLIBC_ARG64(x) (x)
#else
/* The on-stack data has to be in the natural order for a 64bit value. */ #if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN_) ^ defined(STACK_GROWS_UP) #define __NOLIBC_ARG64(x) ((int)(x)), ((int)((long long)(x) >> 32)) #else
#define __NOLIBC_ARG64(x) ((int)((long long)(x) >> 32)), ((int)(x)) #endif
#endif
Then (if I've got it right):
static __attribute__((unused))
int _sys_fallocate(int fd, int mode, off_t offset, off_t size)
{
return _syscall(__NR_fallocate, fd, mode, __NOLIBC_ARG64(offset),
__NOLIBC_ARG64(size));
}There is the other problem that arm32 (and maybe others) requires the 64bit variable be aligned in the stack frame.
So f(int a, long long b) is effectively f(int a, int pad, long long b). (This usually causes grief with lseek().)
So a pad might be needed for some system calls on some 32bit architectures. This could be done with something that expands to '' or '0,'.
David
Quoted 3 lines
Cheers,
Willy
Thomas Weißschuh
maintainerRe: [PATCH v3 1/2] tools/nolibc: fcntl: Add fallocate()
Quoted 6 lines · David Laight
Quoted 3 lines · On Sat, 2 May 2026 05:00:06 +0200 Willy Tarreau <[email protected]> wrote:
Quoted 2 lines · David Laight
On Fri, 1 May 2026 01:41:24 +0900
Daniel Palmer <[email protected]> wrote:
(...)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
tools/include/nolibc/fcntl.h +9
-0+/* +* 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) +{ +/*
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/include/nolibc/fcntl.h int creat(const char *path, mode_t mode) · line 99
Quoted 5 lines
tools/include/nolibc/fcntl.h +5
-0+* 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 =sizeof (__kernel_long_t) !=sizeof (off_t);I don't think you care about the size of
off_t.
Were it to be 4 the code would be badly wrong.
I agree here that sizeof(__kernel_long_t) != 8 would be clearer a bit. Also the intermediate variable could go away.
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
tools/include/nolibc/fcntl.h int creat(const char *path, mode_t mode) · line 107
Quoted 9 lines
tools/include/nolibc/fcntl.h +8
-0+ +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); +}The above might be more readable as:
if (sizeof(__kernel_long_t) == 8) /* 64 bit, values fit in single arguments */ return __nolibc_syscall4(__NR_fallocate, fd, mode, offset, size); /* 32 bit, values need splitting, order depends on endianness */ /* This test for endianness doesn't rely on any pre-processor defines */ if (({union {int x; char c;} u; u.x = 1; u.c;})) /* Little endian */ return __nolibc_syscall6(__NR_fallocate, fd, mode, offset, offset >> 32, size, size >> 32); /* Big endian */ return __nolibc_syscall6(__NR_fallocate, fd, mode, offset >> 32, offset, size >> 32, size);
Quoted 5 lines
Quoted 5 lines
Honestly David, I find Daniel's version way more readable :-) Precisely because the repeated variations are abstracted with this more readable macro. If it was used only once I could possibly agree. Even the endianness test is hard to read, better rely on
__BYTE_ORDER__for this.
Here I agree with Daniel and Willy, the original aproach looks cleaner.
Quoted 14 lines
I did say 'might' :-) and I should probably have used
__BYTE_ORDER__.Looking again, the code is trying to copy what the compiler generates when it passes a 64bit quantity on stack or in 2 registers.
Sof(a, b, c, d)is traditionally 'push d; push c; push b, push a; call f'. With the normal 'stack grows down' this gives (in increasing addresses):
return address
a
b
c
d
If 'b,c' is replaced by a 64bit value then you want the stack memory to contain the correct representation of a 64bit value.
So for LE you need to pass the low part before the high part.
Most architectures should use registers and not the stack.
Quoted 6 lines
But there is one architecture (parisc) where the stack goes the other way. It is BE (I believe), but would need the LE argument order.
I think all the conditionals could be moved out of the fallocate code. I'm not sure of the exact pre-processor conditionals but something like:
Quoted 10 lines
#if (
__BITS_PER_LONG== 64) ||defined(x86_x32)||defined(mips_n32)#define__NOLIBC_ARG64(x)(x)
#else
/* The on-stack data has to be in the natural order for a 64bit value. */ #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN_) ^defined(STACK_GROWS_UP)#define__NOLIBC_ARG64(x)((int)(x)), ((int)((long long)(x) >> 32)) #else
#define__NOLIBC_ARG64(x)((int)((long long)(x) >> 32)), ((int)(x)) #endif
#endif
I highly dislike macros like these which may expand to either a single or multiple arguments. Also this logic looks much more complicated than what Daniel proposed.
Quoted 7 lines
Then (if I've got it right):
static __attribute__((unused))
int_sys_fallocate(int fd, int mode, off_t offset, off_t size){ return _syscall(__NR_fallocate, fd, mode, __NOLIBC_ARG64(offset), __NOLIBC_ARG64(size)); }
We intentionally use __nolibc_syscallX() inside nolibc proper over _syscall()/syscall() to have the arity of the syscall written out.
Quoted 6 lines
There is the other problem that arm32 (and maybe others) requires the 64bit variable be aligned in the stack frame.
Sof(int a, long long b)is effectivelyf(int a, int pad, long long b). (This usually causes grief withlseek().)
So a pad might be needed for some system calls on some 32bit architectures. This could be done with something that expands to '' or '0,'.
I don't see why we have to worry about variable alignment or stack direction at all. That's the compilers job. We do have both lseek() and parisc32 nowadays and both work fine. Also with Daniel's series on top. Am I missing something?
Thomas
Re: [PATCH v3 1/2] tools/nolibc: fcntl: Add fallocate()
Quoted 9 lines · On Sun, 3 May 2026 18:28:39 +0200 Thomas Weißschuh <[email protected]> wrote:
Quoted 6 lines · David Laight
Quoted 3 lines · On Sat, 2 May 2026 05:00:06 +0200 Willy Tarreau <[email protected]> wrote:
Quoted 2 lines · David Laight
On Fri, 1 May 2026 01:41:24 +0900
Daniel Palmer <[email protected]> wrote:(...)
...
Quoted 13 lines
Quoted 4 lines
Looking again, the code is trying to copy what the compiler generates when it passes a 64bit quantity on stack or in 2 registers.
Sof(a, b, c, d)is traditionally 'push d; push c; push b, push a; call f'. With the normal 'stack grows down' this gives (in increasing addresses):Quoted 8 lines
return address
a
b
c
d
If 'b,c' is replaced by a 64bit value then you want the stack memory to contain the correct representation of a 64bit value. So for LE you need to pass the low part before the high part.
Quoted 1 line
Most architectures should use registers and not the stack.
Indeed, but the registers are picked as though they are caching on-stack locations. So the way the stack would look is relevant.
Quoted 18 lines
Quoted 7 lines
But there is one architecture (parisc) where the stack goes the other way. It is BE (I believe), but would need the LE argument order.
I think all the conditionals could be moved out of the fallocate code. I'm not sure of the exact pre-processor conditionals but something like:
Quoted 10 lines
#if (
__BITS_PER_LONG== 64) ||defined(x86_x32)||defined(mips_n32)#define__NOLIBC_ARG64(x)(x)
#else
/* The on-stack data has to be in the natural order for a 64bit value. */ #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN_) ^defined(STACK_GROWS_UP)#define__NOLIBC_ARG64(x)((int)(x)), ((int)((long long)(x) >> 32)) #else
#define__NOLIBC_ARG64(x)((int)((long long)(x) >> 32)), ((int)(x)) #endif
#endif
Quoted 4 lines
I highly dislike macros like these which may expand to either a single or multiple arguments.
Also this logic looks much more complicated than what Daniel proposed.
I'm not sure the casts are needed.
The implicit casts from the function calls may mean that it is enough to use (x) and (x) >> 32.
I really didn't like the expansions Daniel proposed in sys_fallocate() itself. Neither the fallocate code nor the header file really said what was going on. You had to read both together and then read between the lines so see why it was necessary at all.
Quoted 10 lines
Quoted 7 lines
Then (if I've got it right):
static __attribute__((unused))
int_sys_fallocate(int fd, int mode, off_t offset, off_t size){ return _syscall(__NR_fallocate, fd, mode, __NOLIBC_ARG64(offset), __NOLIBC_ARG64(size)); }We intentionally use
__nolibc_syscallX()inside nolibc proper over _syscall()/syscall() to have the arity of the syscall written out.
In this case the number of arguments varies - so that wouldn't work. But I can see why it would normally be better.
Quoted 10 lines
Quoted 7 lines
There is the other problem that arm32 (and maybe others) requires the 64bit variable be aligned in the stack frame.
Sof(int a, long long b)is effectivelyf(int a, int pad, long long b). (This usually causes grief withlseek().)
So a pad might be needed for some system calls on some 32bit architectures. This could be done with something that expands to '' or '0,'.I don't see why we have to worry about variable alignment or stack direction at all. That's the compilers job.
Except you do because you are trying to match what the compiler would generate for a 64bit argument by passing two 32bit values.
I'm pretty sure that the normal syscall interface just passes the registers that contain arguments over from user space to kernel space and then calls the kernel function (ie without any regard for the types of the parameters). This is normally fine except for lseek() and mmap() - they may have an interface that re-orders the arguments.
Quoted 3 lines
We do have both
lseek()and
parisc32 nowadays and both work fine. Also with Daniel's series on top. Am I missing something?
godbolt doesn't have a parisc32 compiler - so I couldn't check. But I think if you compare the code for calls to f1(int, int, int, int), f2(int, long long, int) and f3(int, int long long) for f1(1,2,3,4), f2(1, 2ull<<32 | 3, 4) and f3(1, 2, 3ull<<32 | 4) against another BE system the 64bit constants will overlay different 32bit ones.
David
Quoted 3 lines
Thomas
Thomas Weißschuh
maintainerRe: [PATCH v3 1/2] tools/nolibc: fcntl: Add fallocate()
Hi David,
sorry for the long delay.
Quoted 26 lines · David Laight
Quoted 9 lines · On Sun, 3 May 2026 18:28:39 +0200 Thomas Weißschuh <[email protected]> wrote:
Quoted 6 lines · David Laight
Quoted 3 lines · On Sat, 2 May 2026 05:00:06 +0200 Willy Tarreau <[email protected]> wrote:
Quoted 2 lines · David Laight
On Fri, 1 May 2026 01:41:24 +0900
Daniel Palmer <[email protected]> wrote:(...)
...
Quoted 13 lines
Quoted 12 lines
Looking again, the code is trying to copy what the compiler generates when it passes a 64bit quantity on stack or in 2 registers.
Sof(a, b, c, d)is traditionally 'push d; push c; push b, push a; call f'. With the normal 'stack grows down' this gives (in increasing addresses):
return address
a
b
c
d
If 'b,c' is replaced by a 64bit value then you want the stack memory to contain the correct representation of a 64bit value.
So for LE you need to pass the low part before the high part.
Quoted 4 lines
Quoted 1 line
Most architectures should use registers and not the stack.
Indeed, but the registers are picked as though they are caching on-stack locations. So the way the stack would look is relevant.
So I was a bit confused about the 64-bit arguments.
When I worked on llseek(), the system call definition explicitly splits the 64-bit arguments into two 32-bit ones. For fallocate, that split happens implicitly according to the function-call ABI.
I still don't see, where the stack layout is supposed to come into play.
Quoted 22 lines
Quoted 17 lines
Quoted 6 lines
But there is one architecture (parisc) where the stack goes the other way. It is BE (I believe), but would need the LE argument order.
I think all the conditionals could be moved out of the fallocate code. I'm not sure of the exact pre-processor conditionals but something like:
Quoted 10 lines
#if (
__BITS_PER_LONG== 64) ||defined(x86_x32)||defined(mips_n32)#define__NOLIBC_ARG64(x)(x)
#else
/* The on-stack data has to be in the natural order for a 64bit value. */ #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN_) ^defined(STACK_GROWS_UP)#define__NOLIBC_ARG64(x)((int)(x)), ((int)((long long)(x) >> 32)) #else
#define__NOLIBC_ARG64(x)((int)((long long)(x) >> 32)), ((int)(x)) #endif
#endifQuoted 4 lines
I highly dislike macros like these which may expand to either a single or multiple arguments.
Also this logic looks much more complicated than what Daniel proposed.
Quoted 8 lines
I'm not sure the casts are needed.
The implicit casts from the function calls may mean that it is enough to use (x) and (x) >> 32.I really didn't like the expansions Daniel proposed in
sys_fallocate()itself. Neither the fallocate code nor the header file really said what was going on. You had to read both together and then read between the lines so see why it was necessary at all.
We should have a longer explanatory comment next to the macros which explains them.
Quoted 22 lines
Quoted 10 lines
Quoted 7 lines
Then (if I've got it right):
static __attribute__((unused))
int_sys_fallocate(int fd, int mode, off_t offset, off_t size){ return _syscall(__NR_fallocate, fd, mode, __NOLIBC_ARG64(offset), __NOLIBC_ARG64(size)); }We intentionally use
__nolibc_syscallX()inside nolibc proper over _syscall()/syscall() to have the arity of the syscall written out.In this case the number of arguments varies - so that wouldn't work. But I can see why it would normally be better.
Quoted 8 lines
Quoted 7 lines
There is the other problem that arm32 (and maybe others) requires the 64bit variable be aligned in the stack frame.
Sof(int a, long long b)is effectivelyf(int a, int pad, long long b). (This usually causes grief withlseek().)
So a pad might be needed for some system calls on some 32bit architectures. This could be done with something that expands to '' or '0,'.
Quoted 5 lines
Quoted 2 lines
I don't see why we have to worry about variable alignment or stack direction at all. That's the compilers job.
Except you do because you are trying to match what the compiler would generate for a 64bit argument by passing two 32bit values.
I still can't follow.
Quoted 5 lines
I'm pretty sure that the normal syscall interface just passes the registers that contain arguments over from user space to kernel space and then calls the kernel function (ie without any regard for the types of the parameters). This is normally fine except for
lseek()andmmap()- they may have an interface that re-orders the arguments.
Yes, but if we explain that our custom macros do the same as the implicit argument splitting, and test that it works, that should be clear enough.
Quoted 9 lines
Quoted 3 lines
We do have both
lseek()and
parisc32 nowadays and both work fine. Also with Daniel's series on top. Am I missing something?godbolt doesn't have a parisc32 compiler - so I couldn't check. But I think if you compare the code for calls to
f1(int, int, int, int),f2(int, long long, int)andf3(int, int long long)forf1(1,2,3,4),f2(1, 2ull<<32 | 3, 4)andf3(1, 2, 3ull<<32 | 4)against another BE system the 64bit constants will overlay different 32bit ones.
There are parisc compilers here:
https://mirrors.edge.kernel.org/pub/tools/crosstool/
Thomas
Re: [PATCH v3 1/2] tools/nolibc: fcntl: Add fallocate()
Quoted 33 lines · On Thu, 14 May 2026 13:51:59 +0200 Thomas Weißschuh <[email protected]>…
Hi David,
sorry for the long delay.
Quoted 28 lines · David Laight
Quoted 9 lines · On Sun, 3 May 2026 18:28:39 +0200 Thomas Weißschuh <[email protected]> wrote:
Quoted 6 lines · David Laight
Quoted 3 lines · On Sat, 2 May 2026 05:00:06 +0200 Willy Tarreau <[email protected]> wrote:
Quoted 2 lines · David Laight
On Fri, 1 May 2026 01:41:24 +0900
Daniel Palmer <[email protected]> wrote:(...)
...
Quoted 14 lines
Quoted 4 lines
Looking again, the code is trying to copy what the compiler generates when it passes a 64bit quantity on stack or in 2 registers.
Sof(a, b, c, d)is traditionally 'push d; push c; push b, push a; call f'. With the normal 'stack grows down' this gives (in increasing addresses):Quoted 8 lines
return address
a
b
c
d
If 'b,c' is replaced by a 64bit value then you want the stack memory to contain the correct representation of a 64bit value. So for LE you need to pass the low part before the high part.Most architectures should use registers and not the stack.
Quoted 8 lines
Quoted 2 lines
Indeed, but the registers are picked as though they are caching on-stack locations. So the way the stack would look is relevant.
So I was a bit confused about the 64-bit arguments.
When I worked onllseek(), the system call definition explicitly splits the 64-bit arguments into two 32-bit ones. For fallocate, that split happens implicitly according to the function-call ABI.
I still don't see, where the stack layout is supposed to come into play.
Think about what happens if/when a 64bit value is passed on stack (on 32bit). The called code wants the two 32bit values be the same way around and have the same alignment constraints as any other 64bit value so that it can be passed by address to another function.
If the 64bit value is put on the stack with two 'push' instructions then the order of the 32bit words in memory depends on whether the stack grow up or down. Since the last argument is pushed first (so the called code can always find the first argument), if the stack grows down (normal) then LE wants the LSW on the lower address so it must pushed second and thus be first in the argument list. The order needs swapping for BE (as done here) but also swapping if the stack grows in the opposite direction.
When integer arguments are passed in registers AFAICT the registers match what would have been placed on the stack.
So for arm32 the pad that would be required to align an on-stack 64bit value results in an unset/unused register.
And, if you think about it, the kernel syscall takes the registers used to pass the arguments and converts them back to into a normal C function call without knowing anything about the function signature.
So although the (no)libc stub is copying values into registers they have to look like a normal function call.
Quoted 57 lines
Quoted 23 lines
Quoted 18 lines
Quoted 7 lines
But there is one architecture (parisc) where the stack goes the other way. It is BE (I believe), but would need the LE argument order.
I think all the conditionals could be moved out of the fallocate code. I'm not sure of the exact pre-processor conditionals but something like:
Quoted 10 lines
#if (
__BITS_PER_LONG== 64) ||defined(x86_x32)||defined(mips_n32)#define__NOLIBC_ARG64(x)(x)
#else
/* The on-stack data has to be in the natural order for a 64bit value. */ #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN_) ^defined(STACK_GROWS_UP)#define__NOLIBC_ARG64(x)((int)(x)), ((int)((long long)(x) >> 32)) #else
#define__NOLIBC_ARG64(x)((int)((long long)(x) >> 32)), ((int)(x)) #endif
#endifQuoted 4 lines
I highly dislike macros like these which may expand to either a single or multiple arguments.
Also this logic looks much more complicated than what Daniel proposed.
Quoted 8 lines
I'm not sure the casts are needed.
The implicit casts from the function calls may mean that it is enough to use (x) and (x) >> 32.I really didn't like the expansions Daniel proposed in
sys_fallocate()itself. Neither the fallocate code nor the header file really said what was going on. You had to read both together and then read between the lines so see why it was necessary at all.We should have a longer explanatory comment next to the macros which explains them.
Quoted 22 lines
Quoted 10 lines
Quoted 7 lines
Then (if I've got it right):
static __attribute__((unused))
int_sys_fallocate(int fd, int mode, off_t offset, off_t size){ return _syscall(__NR_fallocate, fd, mode, __NOLIBC_ARG64(offset), __NOLIBC_ARG64(size)); }We intentionally use
__nolibc_syscallX()inside nolibc proper over _syscall()/syscall() to have the arity of the syscall written out.In this case the number of arguments varies - so that wouldn't work. But I can see why it would normally be better.
Quoted 8 lines
Quoted 7 lines
There is the other problem that arm32 (and maybe others) requires the 64bit variable be aligned in the stack frame.
Sof(int a, long long b)is effectivelyf(int a, int pad, long long b). (This usually causes grief withlseek().)
So a pad might be needed for some system calls on some 32bit architectures. This could be done with something that expands to '' or '0,'.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
I don't see why we have to worry about variable alignment or stack direction at all. That's the compilers job.
Except you do because you are trying to match what the compiler would generate for a 64bit argument by passing two 32bit values.
I still can't follow.
The syscall entry code just treats the parameters as two 32bit values (in the same order as they are passed).
But the called kernel function will interpret them as a 64bit value. It'll want that in the 'native' word order, and that depends on LE/BE and (I'm pretty sure) the stack direction.
The compiler doesn't help you get them in the right order.
Quoted 15 lines
Quoted 6 lines
I'm pretty sure that the normal syscall interface just passes the registers that contain arguments over from user space to kernel space and then calls the kernel function (ie without any regard for the types of the parameters). This is normally fine except for
lseek()andmmap()- they may have an interface that re-orders the arguments.Yes, but if we explain that our custom macros do the same as the implicit argument splitting, and test that it works, that should be clear enough.
Quoted 4 lines
Quoted 3 lines
We do have both
lseek()and
parisc32 nowadays and both work fine. Also with Daniel's series on top. Am I missing something?
Quoted 8 lines
Quoted 5 lines
godbolt doesn't have a parisc32 compiler - so I couldn't check. But I think if you compare the code for calls to
f1(int, int, int, int),f2(int, long long, int)andf3(int, int long long)forf1(1,2,3,4),f2(1, 2ull<<32 | 3, 4)andf3(1, 2, 3ull<<32 | 4)against another BE system the 64bit constants will overlay different 32bit ones.There are parisc compilers here:
https://mirrors.edge.kernel.org/pub/tools/crosstool/
I'll take a look tomorrow.
-- David
Quoted 3 lines
Thomas
Thomas Weißschuh
maintainerRe: [PATCH v3 1/2] tools/nolibc: fcntl: Add fallocate()
Quoted 56 lines · David Laight
Quoted 29 lines · On Thu, 14 May 2026 13:51:59 +0200 Thomas Weißschuh <[email protected]>…
Quoted 28 lines · David Laight
Quoted 9 lines · On Sun, 3 May 2026 18:28:39 +0200 Thomas Weißschuh <[email protected]> wrote:
Quoted 6 lines · David Laight
Quoted 3 lines · On Sat, 2 May 2026 05:00:06 +0200 Willy Tarreau <[email protected]> wrote:
Quoted 2 lines · David Laight
On Fri, 1 May 2026 01:41:24 +0900
Daniel Palmer <[email protected]> wrote:(...)
...
Quoted 14 lines
Quoted 4 lines
Looking again, the code is trying to copy what the compiler generates when it passes a 64bit quantity on stack or in 2 registers.
Sof(a, b, c, d)is traditionally 'push d; push c; push b, push a; call f'. With the normal 'stack grows down' this gives (in increasing addresses):Quoted 8 lines
return address
a
b
c
d
If 'b,c' is replaced by a 64bit value then you want the stack memory to contain the correct representation of a 64bit value. So for LE you need to pass the low part before the high part.Most architectures should use registers and not the stack.
Quoted 8 lines
Quoted 2 lines
Indeed, but the registers are picked as though they are caching on-stack locations. So the way the stack would look is relevant.
So I was a bit confused about the 64-bit arguments.
When I worked onllseek(), the system call definition explicitly splits the 64-bit arguments into two 32-bit ones. For fallocate, that split happens implicitly according to the function-call ABI.
I still don't see, where the stack layout is supposed to come into play.Think about what happens if/when a 64bit value is passed on stack (on 32bit). The called code wants the two 32bit values be the same way around and have the same alignment constraints as any other 64bit value so that it can be passed by address to another function.
If the 64bit value is put on the stack with two 'push' instructions then the order of the 32bit words in memory depends on whether the stack grow up or down. Since the last argument is pushed first (so the called code can always find the first argument), if the stack grows down (normal) then LE wants the LSW on the lower address so it must pushed second and thus be first in the argument list. The order needs swapping for BE (as done here) but also swapping if the stack grows in the opposite direction.
When integer arguments are passed in registers AFAICT the registers match what would have been placed on the stack.
So for arm32 the pad that would be required to align an on-stack 64bit value results in an unset/unused register.
Quoted 5 lines
And, if you think about it, the kernel syscall takes the registers used to pass the arguments and converts them back to into a normal C function call without knowing anything about the function signature.
So although the (no)libc stub is copying values into registers they have to look like a normal function call.
Fair enough. But the result of all of these considerations are done in the kernel side. In the end for each specific system call and architecture the 64-bit argument parts have to end up in certain registers, which is very similar to how normal system call arguments are also required to be in certain registers. For nolibc we can ignore *why* these requirements exist and only need to make sure we satisfy them. Doing this for arbitrary function prototypes would require the knowledge about the architecture-specific rules, but we only need to do this for a few system calls. And the solution from Daniel seems to be sufficient for fallocate(). I think we shouldn't make things more complicated than they need to be.
For example all of the stack alignment considerations would matter for i386, but in fact there is a dedicated system call entry point ia32_fallocate() which instead explicitly takes the 64-bit as two 32-bit arguments, so they are irrelevant. For arm 32-bit, we have the implicit handling. But then in the arm64 compat code the requirements are spelled out explicitly again and match what Daniel proposed.
This all does not look like an accident but intentional design decisions. So I trust if we need to support other 64-bit argument system calls, the result will be similar.
Thomas
PATCH v3 2/2 selftests/nolibc: Add a very basic test for fallocate()
In reply to Daniel Palmer1: 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.
--- tools/testing/selftests/nolibc/nolibc-test.c | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+)
tools/testing/selftests/nolibc/nolibc-test.c +69 -0
@@ -89,6 +89,14 @@ static const int is_glibc =#endif ; +static const int is_sparc32 = +#if defined(__sparc__) && !defined(__arch64__) + 1 +#else + 0 +#endif +; +#if !defined(NOLIBC )/* Some disabled tests may not compile. */
@@ -898,6 +906,66 @@ int test_getpagesize(void)return !c; } +int test_fallocate (void ) +{ +struct stat st; +int fd, r; + +/* Create a new tmp file */ + fd =open ("/tmp" ,O_TMPFILE |O_RDWR ,0644 ); +if (fd ==-1 ) +return -1 ; + +/* Expand it to 42 bytes */ + r =fallocate (fd,0 ,0 ,42 ); +if (r) + goto close_tmpfile; + +/* Get the new stat */ + r =fstat (fd, &st); +if (r) + goto close_tmpfile; + +/* It should be 42 bytes long */ +if (st.st_size !=42 ) { + r =-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 =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 = ENOSPC or +* EFBIG indicating the value was passed correctly but it +* was rejected. +*/ + r =fallocate (fd,0 ,0 , (1ll << (20 +32 ))); +if (r !=-1 ) { + r =-1 ; + goto close_tmpfile; + } +if (errno !=ENOSPC && errno !=EFBIG ) { + r =-1 ; + goto close_tmpfile; + } + +/* Test passed */ + r =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 =dup3 (0 ,100 ,0 );EXPECT_SYSNE (1 , tmp,-1 );close (tmp);break ;CASE_TEST (dup3_m1); tmp =dup3 (-1 ,100 ,0 );EXPECT_SYSER (1 , tmp,-1 ,EBADF );if (tmp !=-1 )close (tmp);break ;CASE_TEST (execve_root);EXPECT_SYSER (1 ,execve ("/" , (char *[]){ [0 ] ="/" , [1 ] =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 );break ;CASE_TEST (file_stream);EXPECT_SYSZR (1 ,test_file_stream ());break ;
Signature · 1 line
2.53.0
Willy Tarreau
maintainerRe: [PATCH v3 2/2] selftests/nolibc: Add a very basic test for fallocate()
Quoted 6 lines · Daniel Palmer
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.
Note that I've already seen one place with more than 4PB on a shared FS, so I don't know how long such a test could hold true without causing a havoc. I understand the reason behind the +32 though, and I'm not worried for the short-to-mid term.
Willy
Re: [PATCH v3 2/2] selftests/nolibc: Add a very basic test for fallocate()
Hi Willy,
Quoted 4 lines · Willy Tarreau
Note that I've already seen one place with more than 4PB on a shared FS, so I don't know how long such a test could hold true without causing a havoc. I understand the reason behind the +32 though, and I'm not worried for the short-to-mid term.
I think there is the assumption that the file is on tmpfs and since tmpfs is in memory it can't be bigger that your system memory. I think with current memory prices we might be ok for now? :)
Thanks,
Daniel
Willy Tarreau
maintainerRe: [PATCH v3 2/2] selftests/nolibc: Add a very basic test for fallocate()
Quoted 11 lines · Daniel Palmer
Hi Willy,
Quoted 4 lines · Willy Tarreau
Note that I've already seen one place with more than 4PB on a shared FS, so I don't know how long such a test could hold true without causing a havoc. I understand the reason behind the +32 though, and I'm not worried for the short-to-mid term.
I think there is the assumption that the file is on tmpfs and since tmpfs is in memory it can't be bigger that your system memory. I think with current memory prices we might be ok for now? :)
Agreed :-)
Willy
Thomas Weißschuh
maintainerRe: [PATCH v3 2/2] selftests/nolibc: Add a very basic test for fallocate()
In reply to Daniel PalmerQuoted 5 lines · Daniel Palmer
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.
Quoted 8 lines
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.
This is because the kernel created in our testsuite does not enable CONFIG_TMPFS, falling back to ramfs/rootfs for /tmp. We should gracefully handle EOPNOTSUPP from fallocate() but also enable CONFIG_TMPFS for our test kernels to increase the test coverage.
Quoted 7 lines
Signed-off-by Daniel Palmer <[email protected]>--- tools/testing/selftests/nolibc/nolibc-test.c | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+)tools/testing/selftests/nolibc/nolibc-test.c +0
-0
(...)
Quoted 12 lines · Daniel Palmer
While poking around with my "static PIE for nommu" series I found I needed
fallocate(). Implementing it turned out a bit more interesting than I thought it would be due to how the offset and size need to be passed on 32bit machines.v3:
- Reworked the test a bit, ran it on all the targets I could get to run (s390, loongarch and sh currently don't work for me). sparc32 doesn't seem to supportfallocate()so made it skip the test.
- Rebase on nolibc/for-next with the large file support bits.
Quoted 4 lines
v2:
- Addressed Thomas' comments
- Trial and error'd a test for the arguments being passed correctly. Hopefully someone smarter than I am can tell if it actually works.
The series looks good to me, I don't have any particular comment, but let's wait for Thomas since he's been reviewing it from day one.
Thanks,
Willy
Thomas Weißschuh
maintainerQuoted 8 lines · Daniel Palmer
While poking around with my "static PIE for nommu" series I found I needed
fallocate(). Implementing it turned out a bit more interesting than I thought it would be due to how the offset and size need to be passed on 32bit machines.v3:
- Reworked the test a bit, ran it on all the targets I could get to run (s390, loongarch and sh currently don't work for me).
Can you elaborate on what is broken?
Quoted 3 lines
sparc32 doesn't seem to support
fallocate()so made it skip the test.
- Rebase on nolibc/for-next with the large file support bits.
(...)
Hi Thomas,
Quoted 7 lines · Thomas Weißschuh
Can you elaborate on what is broken?
Quoted 3 lines
sparc32 doesn't seem to support
fallocate()so made it skip the test.
- Rebase on nolibc/for-next with the large file support bits.(...)
For loongarch I seem to be missing OVMF:
qemu-system-loongarch64 -display none -no-reboot -kernel "/home/daniel/.cache/nolibc-tests/loongarch/arch/loongarch/boot/vmlinuz.efi" -initrd initramfs.cpio -serial file:/dev/stdout -m 1G
-M virt -append "console=ttyS0,115200 panic=-1 " -bios /usr/share/edk2//loongarch64/OVMF_CODE.fd > "/home/daniel/coding/cleantrees/linux-nolibc/tools/testing/selftests/nolibc/run.out"
qemu-system-loongarch64: Could not find ROM image '/usr/share/edk2//loongarch64/OVMF_CODE.fd'
make: *** [Makefile.nolibc:341: run] Error 1
Debian doesn't seem to have a package for this.
For s390x, fixed now. Missing package.
For sh4, qemu-system-sh4 is 100% on one CPU and the test never completes. I guess it's getting stuck during boot.
Thanks,
Daniel
Thomas Weißschuh
maintainerQuoted 21 lines · Daniel Palmer
Quoted 7 lines · Thomas Weißschuh
Can you elaborate on what is broken?
Quoted 3 lines
sparc32 doesn't seem to support
fallocate()so made it skip the test.
- Rebase on nolibc/for-next with the large file support bits.(...)
For loongarch I seem to be missing OVMF:
qemu-system-loongarch64 -display none -no-reboot -kernel "
/home/daniel/.cache/nolibc-tests/loongarch/arch/loongarch/boot/vmlinuz.efi"(quoted diff) +0
-2-initrd initramfs.cpio -serial file:/dev/stdout -m 1G -M virt -append "console=ttyS0,115200 panic=-1 " -bios
/usr/share/edk2//loongarch64/OVMF_CODE.fd> "/home/daniel/coding/cleantrees/linux-nolibc/tools/testing/selftests/nolibc/run.out"
qemu-system-loongarch64: Could not find ROM image '/usr/share/edk2//loongarch64/OVMF_CODE.fd'
make: *** [Makefile.nolibc:341: run] Error 1
Quoted 1 line
Debian doesn't seem to have a package for this.
There is this in trixie:
https://packages.debian.org/trixie/all/qemu-efi-loongarch64
Unfortunately the path to the firmware files differ between distros and QEMU versions. There are standard JSON descriptors which could be queried but no tool for that is provided...
(...)
Quoted 2 lines
For sh4, qemu-system-sh4 is 100% on one CPU and the test never completes. I guess it's getting stuck during boot.
See commit b0aa5e4b087b ("sh: Fix fallout from ZERO_PAGE consolidation"). I now merged v7.1-rc2 into the nolibc tree to get this fix.
Thomas
Hi Thomas,
Quoted 5 lines · Thomas Weißschuh
Quoted 1 line
Debian doesn't seem to have a package for this.
There is this in trixie:
For sid it is now /usr/share/qemu-efi-loongarch64/QEMU_EFI.fd I've changed to that locally and the tests complete now.
Quoted 6 lines
Quoted 2 lines
For sh4, qemu-system-sh4 is 100% on one CPU and the test never completes. I guess it's getting stuck during boot.
See commit
b0aa5e4b087b("sh: Fix fallout fromZERO_PAGEconsolidation"). I now merged v7.1-rc2 into the nolibc tree to get this fix.
SH4 is also completing now.
Thanks,
Daniel