1218437 Commits

Author SHA1 Message Date
Octavian Purdila
776984711d Merge pull request #568 from ddiss/lklfuse_udev_systemd
lkl: systemd: add example udev and systemd service files
2025-02-20 00:41:02 -08:00
Octavian Purdila
e2b7eed3ae Merge pull request #563 from ddiss/preadv_pwritev_blkio
lkl: posix: use preadv/pwritev for block I/O
2025-02-20 00:40:30 -08:00
David Disseldorp
ca2165640b lkl: posix: use preadv/pwritev for block I/O
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>
2025-02-20 11:44:08 +11:00
Hajime Tazaki
1f42eb481f Merge pull request #567 from thehajime/bump-circleci-img
lkl: update CI images on circleci
2025-02-20 09:23:06 +09:00
David Disseldorp
d95384af67 lkl: systemd: add example udev and systemd service files
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>
2025-02-19 23:09:59 +11:00
Hajime Tazaki
f54d031f45 lkl: update CI images on circleci
this contains a fix for android build (arm64) of missing preadv/pwritev
symbols.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
2025-02-19 11:24:48 +09:00
Octavian Purdila
3e92231891 Merge pull request #565 from ddiss/rework_do_rw
lkl: posix: rework do_rw() types
2025-02-18 09:21:05 -08:00
David Disseldorp
d188b39448 lkl: posix: rework do_rw() types
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>
2025-02-17 19:57:10 +11:00
Octavian Purdila
4eb8d9e6d6 Merge pull request #562 from ddiss/host_timer_drop_cb_arg
lkl: host: drop unused timer callback parameter
2025-02-13 22:40:25 -08:00
David Disseldorp
ff8f51294c lkl: host: drop unused timer parameter
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>
2025-02-14 16:21:10 +11:00
David Disseldorp
d4cb6d1620 Revert "lkl: posix: implement wrapper for timer callback"
This reverts commit 648f7902bc.

We can rework this to avoid the new alloc/free.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2025-02-14 15:19:42 +11:00
Hajime Tazaki
1848ab8296 Merge pull request #561 from tavip/fix-build-warnings
Fix build warnings
2025-02-14 10:36:20 +09:00
Octavian Purdila
75f1587578 lkl: syscalls: use void pointers to store syscall handlers
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>
2025-02-12 11:37:56 -08:00
Octavian Purdila
5ffc613eaf lkl: posix: add thread wrapper function
Add thread wrapper function. Fixes the following compile warning:

lib/posix-host.c: In function ‘thread_create’:
lib/posix-host.c:195:56: warning: cast between incompatible function \
 types from ‘void (*)(void *)’ to ‘void * (*)(void *)’ [-Wcast-function-type]
  195 |         if (WARN_PTHREAD(pthread_create(&thread, NULL, (void* (*)(void *))fn, arg)))
      |                                                        ^
lib/posix-host.c:77:41: note: in definition of macro ‘WARN_PTHREAD’
   77 | #define WARN_PTHREAD(exp) _warn_pthread(exp, #exp)
      |                                         ^~~

Signed-off-by: Octavian Purdila <tavip@google.com>
2025-02-12 11:37:31 -08:00
Octavian Purdila
648f7902bc lkl: posix: implement wrapper for timer callback
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>
2025-02-11 18:16:49 -08:00
Octavian Purdila
2286d495bb lkl: fix redundant generic-y build warnings
Remove a few redundant generic-y statements.

Signed-off-by: Octavian Purdila <tavip@google.com>
2025-02-11 16:13:32 -08:00
Octavian Purdila
2231833d98 Merge pull request #559 from tavip/lkl-build-fixes
Build fixes
2025-02-06 20:39:54 -08:00
Octavian Purdila
e758fd8b34 lkl: don't install tests
Separate the tests targets in a different set so that we don't install
them with make install.

Signed-off-by: Octavian Purdila <tavip@google.com>
2025-02-06 09:06:41 -08:00
Octavian Purdila
3c97822a40 lkl: add tests build barrier
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>
2025-02-06 09:00:59 -08:00
Octavian Purdila
66e6ad4ee4 Merge pull request #556 from ddiss/lkl_tests_parallel_build_fix
lkl: 32-bit timespec fixes
2025-02-06 08:55:49 -08:00
David Disseldorp
0692c1e050 lkl: fix 32-bit timespec casts
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>
2025-02-06 09:47:30 +11:00
David Disseldorp
ab1c2d0c6f lkl: rework broken lkl_sys_select timeval conversion
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>
2025-02-06 09:21:47 +11:00
David Disseldorp
75fd3b6e74 lkl cptofs: handle stat errors earlier
Don't bother parsing the results if the initial stat call failed.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2025-02-06 09:21:47 +11:00
Jiri Olsa
a593a3baa4 tools/build: Fix -s detection code in tools/build/Makefile.build
As Dmitry described in [1] changelog the current way of detecting
-s option is broken for new make.

Changing the tools/build -s option detection the same way as it was
fixed for root Makefile in [1].

[1] 4bf7358816 ("kbuild: Port silent mode detection to future gnu make.")

Cc: Dmitry Goncharov <dgoncharov@users.sf.net>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: KP Singh <kpsingh@chromium.org>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Stanislav Fomichev <sdf@google.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Quentin Monnet <quentin@isovalent.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: bpf@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
Link: https://lore.kernel.org/r/20231008212251.236023-2-jolsa@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2025-02-05 12:37:49 -08:00
David Disseldorp
4348d61e00 lkl tools: fix some -Wincompatible-pointer-types errors
Explicitly cast between unsigned long and size_t for malloc, memcpy and
memset.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2025-01-31 16:27:14 +11:00
David Disseldorp
ef3fb8c37b lkl tools: use 64-bit lkl_sys_nanosleep on 32-bit builds
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>
2025-01-31 16:26:36 +11:00
Octavian Purdila
b357b84371 Merge pull request #555 from ddiss/lkl_test_icmp_buf_overflow
lkl tools: fix lkl_test_icmp malloc size
2025-01-29 17:36:39 -08:00
David Disseldorp
b54c6b9462 lkl tools: fix lkl_test_icmp malloc size
We need to allocate more than just the size of a pointer here.
Found via gcc -Walloc-size.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2025-01-29 08:42:16 +11:00
Hajime Tazaki
74da3bda01 Merge pull request #553 from rodionov/new_tgid
Enable creation of host tasks with new tgid in LKL.
2025-01-14 08:35:43 +09:00
Zi Fan Tan
b0159f06a6 Enable creation of host tasks with new tgid in LKL.
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>
2025-01-07 20:08:17 -08:00
Octavian Purdila
2bc46f7a6e Merge pull request #551 from rodionov/mmu_rc
LKL MMU support
2025-01-05 00:56:49 -08:00
Eugene Rodionov
1ee079e00a Add LKL test suite with MMU for github CI.
Run LKL tests (boot, disk, network) for LKL built with MMU configuration
and KASan enabled.

Signed-off-by: Eugene Rodionov <radius.evgeniy@gmail.com>
2025-01-04 15:52:27 -08:00
Eugene Rodionov
a01f3cecea Fix makefile to handle PATH variable with whitespaces.
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>
2025-01-04 15:52:27 -08:00
Eugene Rodionov
440d190679 Implement LKL MMU Kunit test suite.
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>
2025-01-04 15:52:27 -08:00
Eugene Rodionov
3b8a3911df Add MMU tests to LKL boot test suite.
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>
2025-01-04 15:52:27 -08:00
Eugene Rodionov
c54ac0adc3 Add mrproper to clean-conf LKL make target.
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>
2025-01-04 15:52:26 -08:00
Eugene Rodionov
571714d3a7 Implement MMU support in LKL arch.
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>
2025-01-04 15:52:22 -08:00
Hajime Tazaki
7682a9e105 Merge pull request #552 from thehajime/fix-win10-build
fix win10 build
2024-12-31 11:47:52 +09:00
Hajime Tazaki
1c2c85de69 lkl: fix windows python issue (freeze_support)
On windows build, python script should declar freeze_support() according
to the document.  This commit adds this line to our headers_install.py
script.

Link: https://docs.python.org/3.13/library/multiprocessing.html#multiprocessing.freeze_support
Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
2024-12-26 16:56:23 +09:00
Hajime Tazaki
9ea6634d72 lkl: fix python warnings on escape sequence
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>
2024-12-26 16:53:39 +09:00
Hajime Tazaki
3995e1daab lkl: fix windows build on pip installation
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>
2024-12-26 16:52:44 +09:00
Hajime Tazaki
269c2431b2 Merge pull request #547 from retrage/2024-09-22-update-gha-actions
lkl: Update GitHub Actions actions
2024-12-26 07:09:26 +09:00
Octavian Purdila
63bed8b238 Merge pull request #548 from ddiss/fix_some_minor_compiler_warnings
Fix some minor compiler warnings
2024-11-14 14:59:05 -08:00
David Disseldorp
b1339686db lkl: silence bootmem compiler warning
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>
2024-11-14 05:36:44 +01:00
David Disseldorp
19a12600d8 lkl: silence compiler warning
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>
2024-11-14 05:36:38 +01:00
David Disseldorp
6e382bda57 lkl: minor vfio_pci error handling improvements
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>
2024-11-14 05:23:34 +01:00
David Disseldorp
d764e22937 lkl: fix vfio_pci warnings
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>
2024-11-14 05:23:12 +01:00
Akira Moroo
920da51dab lkl: Update GitHub Actions actions
The actions/upload-artifact v2 is deprecated, and it's no longer
available. [1]

[1] https://github.blog/changelog/2024-02-13-deprecation-notice-v1-and-v2-of-the-artifact-actions/

Signed-off-by: Akira Moroo <retrage01@gmail.com>
2024-09-22 05:39:50 +00:00
Octavian Purdila
699f87c5ee Merge pull request #545 from ddiss/lklfuse_vfs_open_flags
Lklfuse: vfs mount and open flags
2024-06-27 00:14:48 -07:00
David Disseldorp
b42cf5fbc6 lklfuse: map more open flags
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>
2024-06-27 14:31:57 +10:00