preadv and pwritev have been around for a long time, and should be
usable on BSD and Linux (v2.6.30, glibc 2.10, Bionic API level 24).
Short reads or writes trigger fallback to the old do_rw() handler.
Signed-off-by: David Disseldorp <ddiss@suse.de>
lklfuse-mount@.service:
Mount a block device (specified via @instance) using lklfuse. The
lklfuse binary is run as an unprivileged "lklfuse" user. The
fuse "allow_other" mount option is used to provide access for users
other than "lklfuse", and requires a "user_allow_other" setting in
fuse3.conf
61-lklfuse.rules:
Detect USB block device add/remove events and start/stop the
lklfuse-mount@<dev> service. Block device ownership changed to provide
unprivileged "lklfuse" user access.
Signed-off-by: David Disseldorp <ddiss@suse.de>
This satisfies "gcc -Werror=strict-prototypes" and cleans up error
handling to return either -1 or 0, instead of potentially returning
partial (last iovec) I/O lengths.
Signed-off-by: David Disseldorp <ddiss@suse.de>
The lkl timer IRQ doesn't use its callback parameter, so drop it from
lkl_host_ops altogether. This avoids the extra posix-host alloc/free
while still addressing the compiler warnings fixed with commit
648f7902bc ("lkl: posix: implement wrapper for timer callback").
Signed-off-by: David Disseldorp <ddiss@suse.de>
This fixes a bunch of Wcast-function-type compile warnings:
arch/lkl/kernel/syscalls.c:27:35: warning: cast between incompatible function types from ‘long int (*)(pid_t, pid_t, int, long unsigned int, long unsigned int)’ {aka ‘long int (*)(int, int, int, long unsigned int, long unsigned int)’} to ‘long int (*)(void)’ [-Wcast-function-type]
27 | #define __SYSCALL(nr, sym) [nr] = (syscall_handler_t)sym,
| ^
./include/uapi/asm-generic/unistd.h:662:1: note: in expansion of macro ‘__SYSCALL’
662 | __SYSCALL(__NR_kcmp, sys_kcmp)
| ^~~~~~~~~
Signed-off-by: Octavian Purdila <tavip@google.com>
Implement a wrapper for the timer callback to fix the following
compile warning:
lib/posix-host.c:383:42: warning: cast between incompatible \
function types from ‘void (*)(void *)’ to ‘void (*)(union sigval)’ \
[-Wcast-function-type]
383 | .sigev_notify_function = (void (*)(union sigval))fn,
| ^
Signed-off-by: Octavian Purdila <tavip@google.com>
tools/build does not support parallel builds when objects are shared
between build targets. Keep the test that uses the most common object
first and insert a build barrier to avoid rebuilding common objects.
Signed-off-by: Octavian Purdila <tavip@google.com>
On 32-bit architectures, struct lkl_timespec is 2*sizeof(long) while
__lkl__kernel_timespec is 2*sizeof(long long); casting these pointer
types is unsafe.
Fixes: 3d4047ac9a ("lkl: follow up fixes after v5.1 merge (y2038)")
Signed-off-by: David Disseldorp <ddiss@suse.de>
max_time is incorrect for both 8-byte and 4-byte time_t sizes.
It should be 0x7fffffffffffffff on 64-bit arches instead of 0x7fe.
Given that we will (in the next commit) be casting from a (long x 2)
lkl_timeval to a (long long x 2) __lkl__kernel_timespec, I think we
can ignore overflow and match the nolibc conversion logic.
Link: https://github.com/lkl/linux/issues/557
Fixes: 780bdc7a66 ("lkl: follow up fixes after 4.17 merge")
Signed-off-by: David Disseldorp <ddiss@suse.de>
Use the always-64-bit __lkl__kernel_timespec struct for
lkl_sys_nanosleep calls and rewrite the lkl_sys_nanosleep_time32 wrapper
to use __lkl__NR_clock_nanosleep_time64 on 32-bit builds.
This fixes the following -Wincompatible-pointer-types errors:
lib/fs.c:287:43: error: passing argument 1 of ‘lkl_sys_nanosleep_time32’ from incompatible pointer type [-Wincompatible-pointer-types]
287 | lkl_sys_nanosleep((struct __lkl__kernel_timespec *)&ts,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| struct __lkl__kernel_timespec *
In file included from tools/lkl//include/lkl_host.h:9,
from lib/fs.c:5:
tools/lkl//include/lkl.h:68:65: note: expected ‘struct lkl_timespec *’ but argument is of type ‘struct __lkl__kernel_timespec *’
68 | static inline int lkl_sys_nanosleep_time32(struct lkl_timespec *rqtp,
| ~~~~~~~~~~~~~~~~~~~~~^~~~
make[1]: *** [tools/build/Makefile.build:98: tools/lkl/lib/fs.o] Error 1
Signed-off-by: David Disseldorp <ddiss@suse.de>
Introduce a new LKL-specific syscall `new_thread_group_leader` which
creates a new task_struct for the host thread with new tgid. This
should be the very first LKL syscall invoked by a newly spawned thread
which wants to be threat group leader.
Upon return from the syscall LKL creates a new tast_struct with a new
tgid for the calling thread. The parent of the thread invoking the
syscall (as returned via `lkl_sys_getppid`) is equal to pid of the
thread which spawned the child thread.
The child thread is cloned from the parent using CLONE_VM, CLONE_FS,
CLONE_FILES and CLONE_SIGHAND flags.
Signed-off-by: Zi Fan Tan <zifantan@google.com>
Signed-off-by: Eugene Rodionov <rodionov@google.com>
If PATH variable contains paths with whitespaces this could lead to
build breackage. This change fixes this issue.
Signed-off-by: Eugene Rodionov <radius.evgeniy@gmail.com>
The test suite implements just a single test case verifying that
`vmalloc` works as expected.
```
make -C tools/lkl MMU=1 MMU_KUNIT=1 clean-conf all
tools/lkl/tests/boot
```
Signed-off-by: Eugene Rodionov <rodionov@google.com>
The two test cases verify that `mmap` works both for `MAP_SHARED` and
`MAP_PRIVATE` mappings.
It is important to use `MAP_POPULATE` flag when calling `lkl_sys_mmap`
syscall. This flag populates the mapping with the pages so that no page
fault happens when the mapping is accessed.
```
make -C tools/lkl MMU=1 clean-conf all
tools/lkl/test/boot
```
Signed-off-by: Eugene Rodionov <rodionov@google.com>
Running `make -C tools/lkl clean-conf` doesn't remove generated kernel
configuration (.config and .config.old) as well as generated kernel
header files. As a result, subsequent `make -C tools/lkl all` might
use .config from the previous build even if arch/lkl/Kconfig is
changed.
Adding mrproper target to clean-conf fixes this issue.
Signed-off-by: Eugene Rodionov <rodionov@google.com>
In its current implementation MMU support is limited to 64-bit LKL
configurations. However, nothing limits it to be extended for 32-bit
configurations.
It is largely inspired by MMU implementation in UML. Currently, we
implement 3-level page tables: page global directory, page middle
directory and page table entries (while p4ds and puds are folded into
pgd level). This enables it to translate 39-bit virtual addresses to
physical addresses in flat memory configuration with kernel virtual
addresses identity-mapped to the corresponding physical addresses
(with the exception of vmalloc-allocated virtual memory).
To build LKL with MMU enabled run:
```
make -C tools/lkl MMU=1 clean-conf all
```
Signed-off-by: Eugene Rodionov <rodionov@google.com>
This commit fixes the warnings (i.e., SyntaxWarning: invalid escape
sequence) shown in later python version (after 3.12) during installation
process of header files.
Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
recent pip (version 23.0 or later) cannot install packages to a host
system without explicit option thus, failed under github actions. This
commit fixes this issue.
Link: https://github.com/pypa/pip/issues/11381
Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
gcc-14 complains about the type mismatch:
arch/lkl/mm/bootmem.c: In function ‘bootmem_init’:
arch/lkl/mm/bootmem.c:39:35: error: passing argument 1 of ‘virt_to_pfn’
makes pointer from integer without a cast [-Wint-conversion]
39 | max_low_pfn = virt_to_pfn(memory_end);
| ^~~~~~~~~~
| |
| long unsigned int
...
./include/asm-generic/page.h:77:53: note: expected ‘const void *’ but
argument is of type ‘long unsigned int’
77 | static inline unsigned long virt_to_pfn(const void *kaddr)
| ~~~~~~~~~~~~^~~~~
Add a cast to silence the warning. Drop some unnecessary casts for
_memory_start and empty_zero_page, which can both be void *.
Signed-off-by: David Disseldorp <ddiss@suse.de>
arch/lkl/kernel/misc.c: In function ‘wrong_size_cmpxchg’:
arch/lkl/kernel/misc.c:18:16: warning: function declared ‘noreturn’ has
a ‘return’ statement
18 | return 0;
Drop the return after panic().
Signed-off-by: David Disseldorp <ddiss@suse.de>
readlink() can fill up to sizeof(link), in which case the nulterm would
overflow. Fix this and avoid assuming that the link carries a '/'.
Signed-off-by: David Disseldorp <ddiss@suse.de>
Calling snprintf() with overlapping source and destination buffers is
undefined behavior, as per C/POSIX specs. Avoid this by adding a second
buffer, and also eliminate a compiler warning from similar readlink()
source-is-dest logic:
lib/vfio_pci.c: In function ‘vfio_pci_add’:
lib/vfio_pci.c:80:28: warning: passing argument 2 to
‘restrict’-qualified parameter aliases with argument 1 [-Wrestrict]
80 | i = readlink(path, path, sizeof(path));
| ~~~~ ^~~~
Signed-off-by: David Disseldorp <ddiss@suse.de>
Proper open flag semantics are important for some applications and tests
such as xfstests generic/130 (for O_TRUNCATE). Pass all open flags from
fuse through to the corresponding LKL open syscall, with the exception
of O_CREAT, O_EXCL and O_NOCTTY, which fuse handles internally. Other
flags may also be filtered out by fuse.
Signed-off-by: David Disseldorp <ddiss@suse.de>