]> xenbits.xensource.com Git - unikraft/unikraft.git/log
unikraft/unikraft.git
20 months agolib/syscall_shim: Utilize `SUBBUILD` feature within `Makefile.uk`
Simon Kuenzer [Thu, 30 Mar 2023 16:32:03 +0000 (18:32 +0200)]
lib/syscall_shim: Utilize `SUBBUILD` feature within `Makefile.uk`

This commit utilizes the recently added `SUBBUILD` feature of the build
system to natively generate all dynamic headers of the library. This has
several reasons:
 1) The `Makefile.uk` of `syscall_shim` becomes more readable
 2) No custom rule for creating the subdirectory structure is needed
 3) No custom `awk`-rules are needed for generating the headers
 4) The build system can take care of handling build order dependencies

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Robert Kuban <robert.kuban@opensynergy.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #938

20 months agobuild: Provide $(IMPORT_BASE) to `Makefile.uk` files
Simon Kuenzer [Tue, 8 Aug 2023 23:00:52 +0000 (01:00 +0200)]
build: Provide $(IMPORT_BASE) to `Makefile.uk` files

This commit makes the variable `$(IMPORT_BASE)` usable in `Makefile.uk`
files. This is needed to include libraries that do not use the `addlib`
or `addlib_s` registration functions. An example are libraries that are
shipped in binary form.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Robert Kuban <robert.kuban@opensynergy.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #938

20 months agobuild: Support generating .uk files with preprocessor
Simon Kuenzer [Tue, 8 Aug 2023 21:59:36 +0000 (23:59 +0200)]
build: Support generating .uk files with preprocessor

This commit registers the `.uk` file extension as known extension that can
be generated by the build system with a pre-processor (e.g., M4, AWK).

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Robert Kuban <robert.kuban@opensynergy.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #938

20 months agobuild: Introduce `*_SUBBUILD` for compilation units
Simon Kuenzer [Thu, 1 Jun 2023 12:36:30 +0000 (14:36 +0200)]
build: Introduce `*_SUBBUILD` for compilation units

This commit adds to the build system the ability to place generated
files (e.g., pre-processed, compiled) in a subdirectory of the
corresponding library build directory (instead of just placing them in the
top-level directory). For this purpose, the build system looks for a
file-scoped variable with the suffix `_SUBBUILD`. Such a variable can
contain a path that is created below the library build directory.

Example (`Makefile.uk`):
 # Create `myheader.h` under `build/libmylib/include/uk/`
 LIBMYLIB_SRCS-y += $(LIBMYLIB_BASE)/myheader.m4>.h
 LIBMYLIB_MYHEADER_SUBBUILD += include/uk

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Robert Kuban <robert.kuban@opensynergy.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #938

20 months agobuild: Only first-level subdirectories with `mk_sub_build_dir`
Simon Kuenzer [Thu, 1 Jun 2023 12:33:30 +0000 (14:33 +0200)]
build: Only first-level subdirectories with `mk_sub_build_dir`

We have two pairs of functions that are internally used to create the
directory structure the build output directory (normally `build/`):
- The function `mk_sub_build_dir` is intended to create only the first
  level subdirectory under the build output directory for a library.
  `sub_build_dir` is a companion function that returns the full path
  of such a first-level subdirectory for a given library name.
- The function `mk_sub_libbuild_dir` is intended to create further
  subdirectories under a library build directory that was created by
  `mk_sub_build_dir`. This function allows multiple levels of
  subdirectories (example: to create an header include folder:
  'include/uk/bits').
  `sub_libbuild_dir` is the companion function that returns the
  full path of such a library subdirectory.

This commit corrects the implementation so that this behavior is
enforced.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Robert Kuban <robert.kuban@opensynergy.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #938

20 months agobuild/Makefile.rules: Improve parameter description of functions
Simon Kuenzer [Thu, 1 Jun 2023 10:52:16 +0000 (12:52 +0200)]
build/Makefile.rules: Improve parameter description of functions

Most of our Makefile commands have a preceding usage description in the
form of:
 # func_name $param_desc,$param_desc,...
Because most of these functions reference the parameters by their
position, this commits changes the description to:
 # func_name $1:param_desc,$2:param_desc,...
This should simplify the reading of Makefile function definitions.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Robert Kuban <robert.kuban@opensynergy.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #938

20 months agolib/ukcpio: Fix symlinks not being extracted
Andrei Tatar [Mon, 24 Jul 2023 15:14:15 +0000 (17:14 +0200)]
lib/ukcpio: Fix symlinks not being extracted

Previously the CPIO extraction code would only handle sections whose
header was of type directory or file, skipping symlinks.
This change adds code to handle extracting symlinks from CPIO archives,
as well as a warning message for unknown CPIO sections.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #992

20 months agolib/vfscore: Accept negative timestamps
Andrei Tatar [Mon, 24 Jul 2023 16:29:34 +0000 (18:29 +0200)]
lib/vfscore: Accept negative timestamps

Previously vfs code would reject timestamps that are more than 1 second
before the epoch as invalid. This is wrong; unix time is defined as a
signed offset and as such can and must support dates before the epoch.
This change relaxes the overly-strict validity check, allowing the full
range of valid file timestamps to be used.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #991

20 months agolib/nolibc: Fix compiler warning for `(f)scanf()` prototypes
Simon Kuenzer [Tue, 8 Aug 2023 15:02:38 +0000 (17:02 +0200)]
lib/nolibc: Fix compiler warning for `(f)scanf()` prototypes

This commit fixes a compiler warning about empty declarations introduced
with commit e622c0043f50 ("lib/nolibc: scanf and fscanf functions").

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1029

21 months agolib/nolibc: Add missing floating point headers
Andrei Tatar [Tue, 25 Jul 2023 14:08:48 +0000 (16:08 +0200)]
lib/nolibc: Add missing floating point headers

This change adds float.h, along with arch-specific sub-headers, which
define constants regarding floating-point numbers.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Delia Pavel <delia_maria.pavel@stud.acs.upb.ro>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1002

21 months agolib/nolibc: Add integer literal macros to stdint.h
Andrei Tatar [Tue, 25 Jul 2023 14:05:32 +0000 (16:05 +0200)]
lib/nolibc: Add integer literal macros to stdint.h

This change adds the missing `*_C` integer literal macros to stdint.h.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Delia Pavel <delia_maria.pavel@stud.acs.upb.ro>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1002

21 months agolib/nolibc: Fix typo in CHAR_BIT in limits.h
Andrei Tatar [Tue, 25 Jul 2023 14:03:00 +0000 (16:03 +0200)]
lib/nolibc: Fix typo in CHAR_BIT in limits.h

This change fixes a typo in the `CHAR_BIT` constant in limits.h.
Previously it was incorrectly spelled as `CHAR_BITS`.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Delia Pavel <delia_maria.pavel@stud.acs.upb.ro>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1002

21 months agolib/vfscore: Fix behavior of writable open on dirs
Andrei Tatar [Tue, 20 Jun 2023 11:30:32 +0000 (13:30 +0200)]
lib/vfscore: Fix behavior of writable open on dirs

Previously the open syscall, when called on a directory with write mode
would either fail with EINVAL or, worse, finish successfully, whereas
the expected behavior is to return EISDIR.
This change corrects this behavior, bringing open() in line with
expectations.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #953

21 months agolib/vfscore: Fix double-lock bug in symlink
Andrei Tatar [Tue, 20 Jun 2023 11:19:42 +0000 (13:19 +0200)]
lib/vfscore: Fix double-lock bug in symlink

This change fixes an issue where the lock of the destination parent
directory was being taken more than once in the symlink syscall by using
the locked variant of namei_last_nofollow.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #952

21 months agolib/vfscore: Add locked namei_last_nofollow
Andrei Tatar [Tue, 20 Jun 2023 11:17:06 +0000 (13:17 +0200)]
lib/vfscore: Add locked namei_last_nofollow

This change adds a variant of namei_last_nofollow that can be called
with the lock on ddp->d_vnode held, as well as factoring out common code
between the two function variants.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #952

21 months agolib/vfscore: Reorder locks in *at syscalls
Andrei Tatar [Tue, 20 Jun 2023 10:13:08 +0000 (12:13 +0200)]
lib/vfscore: Reorder locks in *at syscalls

*at syscalls are implemented in Unikraft in two stages: (1) build the
full target path relative to the supplied dirfd, and (2) delegate to the
regular syscall. Previously these syscalls held the lock on the dirfd
vnode throughout steps (1) and (2); however, the sub-syscalls often need
to acquire the same lock (along with perhaps others), causing
double-lock asserts to trigger.
This commit changes this logic to only hold the vnode lock during step
(1) and release it immediately before (2). While this relaxes the
previous atomicity guarantees somewhat, holding the vnode lock on dirfd
only prevented concurrent changes to first-generation descendents, and
unorthogonal and arguably unexpected behavior. The useful purpose of
holding the dirfd lock is to ensure we build a full path that was (at
one point in time) valid, with the sub-syscalls implementing their own
atomicity guarantees as per usual.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #951

21 months agolib/nolibc: Provide declaration of sysconf
Andrei Tatar [Tue, 25 Jul 2023 13:58:01 +0000 (15:58 +0200)]
lib/nolibc: Provide declaration of sysconf

This change adds a missing declaration of `sysconf()` in the unistd.h
header provided by nolibc, complementing the _SC_* constants.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #936

21 months agolib/posix-sysinfo: Provide _SC_GETPW_R_SIZE_MAX
Andrei Tatar [Wed, 7 Jun 2023 10:18:46 +0000 (12:18 +0200)]
lib/posix-sysinfo: Provide _SC_GETPW_R_SIZE_MAX

Calling code expects sysconf(_SC_GETPW_R_SIZE_MAX) to be either -1 or a
non-zero value for an initial buffer size. The previous default value of
0 is outside of specifications and can cause unintended behavior.
This change makes sysconf(_SC_GETPW_R_SIZE_MAX) return -1.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #936

21 months agolib/ukdebug: Add `LVLC_THREAD` macro
Stefan Jumarea [Sun, 4 Jun 2023 18:57:50 +0000 (21:57 +0300)]
lib/ukdebug: Add `LVLC_THREAD` macro

If `LIBUKDEBUG_PRINT_THREAD` is selected in the configuration menu and
`LIBUKDEBUG_ANSI_COLOR` is not, a build error is thrown because the
`LVLC_THREAD` macro is not set.

Fix this by setting the macro to an empty string if `LIBUKDEBUG_ANSI_COLOR`
is not set.

Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Eduard-Florin Mihailescu <mihailescu.eduard@gmail.com>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #929

21 months agoarch/x86: Silence warning about incomplete switch
Andrei Tatar [Wed, 31 May 2023 11:40:08 +0000 (13:40 +0200)]
arch/x86: Silence warning about incomplete switch

Commit ffdbb486c4dd ("arch/*: Add sanitization function for ectx memory")
added a function for sanitizing ECTX memory in cases where it is needed.
It also triggers a warning about the switch not handling all values.
This change silences this warning by adding a no-op default.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #926

21 months agoarch/x86: Introduce NMI event for x86
Marco Schlumpp [Fri, 26 May 2023 15:22:37 +0000 (17:22 +0200)]
arch/x86: Introduce NMI event for x86

This allows libraries to handle NMI interrupts.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #920

21 months agolib/nolibc: Include and export htonl(3) and ntohl(3)
Christiano Haesbaert [Sat, 8 Jul 2023 09:18:21 +0000 (11:18 +0200)]
lib/nolibc: Include and export htonl(3) and ntohl(3)

Add htonl and ntohl functions to keep consistency, since their shorter
equivalents, ntohs(3) and htons(3) are already present.

Signed-off-by: Christiano Haesbaert <haesbaert@haesbaert.org>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #974

21 months agolib/nolibc: Fix a typo in the exportsymk.uk file for the ntohs(3) symbol.
Christiano Haesbaert [Sat, 8 Jul 2023 09:15:07 +0000 (11:15 +0200)]
lib/nolibc: Fix a typo in the exportsymk.uk file for the ntohs(3) symbol.

The symbol is called ntohs not nthos.

Signed-off-by: Christiano Haesbaert <haesbaert@haesbaert.org>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #974

21 months agolib/nolibc: scanf and fscanf functions
Radu Nichita [Wed, 12 Jul 2023 22:47:09 +0000 (01:47 +0300)]
lib/nolibc: scanf and fscanf functions

Adding scanf and fscanf function to nolibc, since their symbols were
exported, but no implementation was provided.

Signed-off-by: Radu Nichita <radunichita99@gmail.com>
Reviewed-by: Adina-Maria Vaman <adinamaariav22@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #977

21 months agolib/ramfs: Implement new file timestamps
Andrei Tatar [Mon, 24 Jul 2023 15:39:35 +0000 (17:39 +0200)]
lib/ramfs: Implement new file timestamps

This change implements setting the file times of newly created files to
the current time, filling in a placeholder that previously would set the
times to the epoch (i.e., 1970-01-01 00:00 UTC).

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Delia Pavel <delia_maria.pavel@stud.acs.upb.ro>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #995

21 months agolib/ramfs: Ensure stability of inode numbers
Andrei Tatar [Mon, 24 Jul 2023 15:30:24 +0000 (17:30 +0200)]
lib/ramfs: Ensure stability of inode numbers

Previously ramfs would assign a new unique inode number to a file on
every successful filesystem lookup. This can lead to the same file being
allocated multiple different inodes, breaking code that (correctly) uses
inodes as reliable indicators of file identity.
This change makes inode numbers persistent, allocated along with the
filesystem node, and stable across multiple lookups of the same file.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #996

21 months agolib/vfscore: Fix create through broken symlink
Andrei Tatar [Mon, 24 Jul 2023 15:21:33 +0000 (17:21 +0200)]
lib/vfscore: Fix create through broken symlink

Previously a vfs syscall on a broken symlink would fail with ENOENT
instead of attempting the syscall on the symlink target. This would make
open(O_CREAT) to fail instead of creating the missing target file.
This change fixes this behavior, bringing it in line with expectations.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #998

21 months agolib/ukmmap|posix-mmap/Config.uk: Change ukmmap - posix-mmap dependency
Eduard Vintilă [Wed, 26 Jul 2023 10:44:54 +0000 (13:44 +0300)]
lib/ukmmap|posix-mmap/Config.uk: Change ukmmap - posix-mmap dependency

This ensures that both libraries cannot be selected at the same time.

Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1005

21 months agoMakefile: Change gccgo-7 to gccgo
Marc Rittinghaus [Thu, 20 Oct 2022 08:42:21 +0000 (10:42 +0200)]
Makefile: Change gccgo-7 to gccgo

The current Makefile refers to gccgo via gccgo-7. This commit removes
the version suffix.

Co-authored-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1005

21 months agoMakefile: Allow external Makefile.build
Marc Rittinghaus [Mon, 1 Aug 2022 15:20:28 +0000 (17:20 +0200)]
Makefile: Allow external Makefile.build

The current method of building libraries is to iterate over
each library's source files and invoke a file type specific
build rule. For libgo this is insufficient as we have to do
more complex operations for dependency resolution
before starting the actual build. This commit allows libraries
to supply an own `Makefile.build` that enables custom
build mechanics.

Co-authored-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1005

21 months agoplat/common: Add support for pvpanic devices for x86
Cezar Craciunoiu [Mon, 7 Aug 2023 09:03:40 +0000 (12:03 +0300)]
plat/common: Add support for pvpanic devices for x86

Unikraft already offers exit codes through the ISA device, but these
are only a convention and are not understood by QEMU itself.

When using `-device pvpanic`, a GUEST_PANICKED event[1] is sent to QEMU
when the unikernel crashes.
This event can be seen when using QMP[1] for example.
The bits corresponding to each even are set as per the documentation[2].

The main usage of this is in kraftkit where unikernels are detached
and exit codes are lost.
Using this can signal when the unikernel crashes.

[1] https://qemu-project.gitlab.io/qemu/interop/qemu-qmp-ref.html#qapidoc-152
[2] https://github.com/qemu/qemu/blob/master/docs/specs/pvpanic.txt

Signed-off-by: Cezar Craciunoiu <cezar.craciunoiu@gmail.com>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1022

21 months agolib/posix-event: Use correct allocator for vfscore_file
Marco Schlumpp [Wed, 26 Jul 2023 10:43:25 +0000 (12:43 +0200)]
lib/posix-event: Use correct allocator for vfscore_file

Same reasoning as in the previous commit.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1000

21 months agolib/posix-socket: Use correct allocator for vfscore_file
Marco Schlumpp [Mon, 3 Jul 2023 15:31:50 +0000 (17:31 +0200)]
lib/posix-socket: Use correct allocator for vfscore_file

vfscore will always use the default system allocator to free the
structure. This ensures a matching allocate for that.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1000

21 months agolib/posix-mmap: Stub `mlock` & `msync`
Tianyi Liu [Tue, 25 Jul 2023 17:15:29 +0000 (01:15 +0800)]
lib/posix-mmap: Stub `mlock` & `msync`

Signed-off-by: Tianyi Liu <i.pear@outlook.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1004

21 months agolib/uksched: Stub `sched_getaffinity` & `sched_setaffinity`
Tianyi Liu [Tue, 25 Jul 2023 17:15:33 +0000 (01:15 +0800)]
lib/uksched: Stub `sched_getaffinity` & `sched_setaffinity`

Signed-off-by: Tianyi Liu <i.pear@outlook.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1004

21 months agolib/*: Remove unused variables
Andrei Tatar [Tue, 27 Jun 2023 17:27:18 +0000 (19:27 +0200)]
lib/*: Remove unused variables

Removes unused counter variables that were triggering compiler warnings.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Rares Miculescu <miculescur@gmail.com>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #976

21 months agolib/syscall_shim: Make compiler flag GCC-specific
Andrei Tatar [Tue, 27 Jun 2023 17:21:34 +0000 (19:21 +0200)]
lib/syscall_shim: Make compiler flag GCC-specific

-Wno-builtin-declaration-mismatch is only supported by GCC.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Rares Miculescu <miculescur@gmail.com>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #976

21 months agobuild: Remove default C-specific -fhosted flag
Andrei Tatar [Tue, 27 Jun 2023 17:17:29 +0000 (19:17 +0200)]
build: Remove default C-specific -fhosted flag

This change removes the -fhosted flag as it is default for C code,
also silencing a warning that appears when compiling C++ code.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Rares Miculescu <miculescur@gmail.com>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #976

21 months agolib/vfscore: Fix wrong application of umask
Andrei Tatar [Mon, 24 Jul 2023 16:12:06 +0000 (18:12 +0200)]
lib/vfscore: Fix wrong application of umask

Previously vfscore would apply the umask to the mode bits in the
emulated libc functions `open` and `openat`, instead of within the
open/openat syscall implementation where it would be correct to do so.
This lead to the umask being ignored when a real libc was in use.
This change fixes this bug, restoring expected behavior with or without
a libc.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #990

21 months agolib/vfscore: Correct behavior of utime(NULL)
Andrei Tatar [Mon, 24 Jul 2023 16:25:54 +0000 (18:25 +0200)]
lib/vfscore: Correct behavior of utime(NULL)

Previously, as a placeholder behavior, utime(NULL) would set the file
times to the epoch (1970-01-01 00:00 -0000) instead of the current time.
This change corrects this oversight, bringing the syscall in line with
expected and documented behavior.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #993

21 months agolib/vfscore: Add unlinkat syscall
Andrei Tatar [Mon, 24 Jul 2023 16:20:43 +0000 (18:20 +0200)]
lib/vfscore: Add unlinkat syscall

Unikraft was previously missing an implementation of `unlinkat`, a
syscall often used by modern runtimes and libcs in lieu of the older
`unlink` and `rmdir` for deleting files and directories.
This change provides an implementation of `unlinkat` based off existing
syscalls, in the same vein as other `*at` syscalls.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Delia Pavel <delia_maria.pavel@stud.acs.upb.ro>
Reviewed-by: Adina-Maria Vaman <adinamariav22@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #994

21 months agolib/ramfs: Support setting file mode on creation
Andrei Tatar [Mon, 24 Jul 2023 16:07:06 +0000 (18:07 +0200)]
lib/ramfs: Support setting file mode on creation

Previously any file created on ramfs would have the mode bits set to
0777, regardless of the mode bits supplied to open/creat/mkdir, which
can break software that explicitly checks these bits.
This change corrects this oversight, having new files be created with
the requested mode bits set.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #997

21 months agobuild: Add `UK_LDEPS`
Martin Kröning [Wed, 28 Jun 2023 08:35:48 +0000 (10:35 +0200)]
build: Add `UK_LDEPS`

This adds support for the `UK_LDEPS` environment variable.
This variable specifies external files that are watched for changes by make.
If any of the specified files change, the final linking step is redone.

The files are only watched and not consumed to avoid changing the order of supplied `LDFLAGS`.

This was inspired by `cargo:rerun-if-changed=PATH`:
- https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-changed

Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #957

21 months agobuild: Allow setting flags from the environment
Martin Kröning [Fri, 23 Jun 2023 09:38:30 +0000 (11:38 +0200)]
build: Allow setting flags from the environment

This adds `UK_ASFLAGS`, `UK_CFLAGS`, `UK_CXXFLAGS`, `UK_GOCFLAGS`, and
`UK_LDFLAGS` for explicitly setting these build flags for Unikraft.

For reference, see
- https://github.com/torvalds/linux/blob/v6.4/Documentation/kbuild/kbuild.rst#environment-variables
- https://github.com/torvalds/linux/blob/v6.4/Makefile#L1097-L1101

Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #957

21 months agoAdd ULiège to ADOPTERS.md.
Gaulthier Gain [Thu, 3 Aug 2023 14:43:15 +0000 (16:43 +0200)]
Add ULiège to ADOPTERS.md.

Add the University of Liège (ULiège) to ADOPTERS.md.

Signed-off-by: Gaulthier Gain <gaulthier.gain@uliege.be>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1020

21 months agoplat/*: Signal shutdown cause on QEMU
Marco Schlumpp [Thu, 3 Aug 2023 09:17:06 +0000 (11:17 +0200)]
plat/*: Signal shutdown cause on QEMU

This uses the `isa-debug-exit` device to pass an exit code to QEMU. By
default this device is not available but can be enabled using the
`-device isa-debug-exit` switch on the QEMU command-line.

Github-Fixes: unikraft#1018
Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1019

21 months agoplat/kvm/x86: Fix build error due to missing `assert.h` header
Sergiu Moga [Wed, 2 Aug 2023 18:30:37 +0000 (21:30 +0300)]
plat/kvm/x86: Fix build error due to missing `assert.h` header

Once the commit
dbfb886b5312 ("plat: Ensure IRQ's disabled in `ukplat_lcpu_halt_irq`")
got merged, a new build error appeared:
```
 E  /usr/bin/ld: /github/workspace/_helloworld/.unikraft/build/libkvmplat.o: in function `ukplat_lcpu_halt_irq':
 E  /github/workspace/plat/kvm/x86/lcpu.c:50: undefined reference to `UK_ASSERT'
 E  collect2: error: ld returned 1 exit status
```

This happened due to `uk/assert.h` not being included.

Github-Fixes: #980
Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Alexander Jung <alex@unikraft.io>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1017

21 months agoplat/kvm/arm: Do not enable interrupts before `wfi`
Robert Kuban [Thu, 13 Jul 2023 10:53:53 +0000 (12:53 +0200)]
plat/kvm/arm: Do not enable interrupts before `wfi`

There is the opportunity to miss an IRQ on the path to `wfi` from the
idle thread after deciding to sleep:
The interrupts are enable just before exuting `wfi`.
If the interrupt already arrived before that, it will be executed
before `wfi`, and `wfi` will go to sleep afterward, not being woken
up by the interrupt.

This patch removes calls to enable/disable interrupts around `wfi`.
`wfi` will be woken up by pending interrupts regardless.

Signed-off-by: Robert Kuban <robert.kuban@opensynergy.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #980

21 months agoplat: Ensure IRQ's disabled in `ukplat_lcpu_halt_irq`
Robert Kuban [Sat, 29 Jul 2023 10:55:19 +0000 (12:55 +0200)]
plat: Ensure IRQ's disabled in `ukplat_lcpu_halt_irq`

Make sure that `IRQ`'s are disabled when calling `ukplat_lcpu_halt_irq`.

Signed-off-by: Robert Kuban <robert.kuban@opensynergy.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #980

21 months agodoc: Add EPAM Systems to the ADOPTERS.md
Oleksii Moisieiev [Wed, 2 Aug 2023 15:05:10 +0000 (18:05 +0300)]
doc: Add EPAM Systems to the ADOPTERS.md

Signed-off-by: Oleksii Moisieiev <oleksii_moisieiev@epam.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1015

21 months ago.github/workflows: Introduce GitHub Actions Workflow integrations
Alexander Jung [Tue, 1 Aug 2023 14:47:45 +0000 (14:47 +0000)]
.github/workflows: Introduce GitHub Actions Workflow integrations

This commit introduces GitHub-centric CI/CD definition that is intended
to be executed on incoming PRs such that the incoming PR can be
determined as working.  This supplementary file is based on-top of the
KraftKit GitHub Action Workflow Step[0] which is a native-to-Unikraft
integration.  This integration allows for seamless building, packaging,
distributing and executing (via TCG-based emulation) of Unikraft
unikernels in a clear and declarative manner.

In this first integration pipeline, incoming PRs will be built against
the following variant of the helloworld application:

- qemu/x86_64
- qemu/arm64
- xen/x86_64
- fc/x86_64
- linuxu/x86_64
- linuxu/arm64

Additionally, a more comprensive test will be executed with libc-test[1]
via uktest in emulation mode for qemu on x86_64 only in order to display
maximum coverage.

[0]: https://github.com/unikraft/kraftkit/blob/staging/action.yml
[1]: https://github.com/unikraft/lib-libc-test

Signed-off-by: Alexander Jung <alex@unikraft.io>
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1012

21 months agoAdd The University of Manchester to ADOPTERS.md
Pierre Olivier [Wed, 2 Aug 2023 13:04:17 +0000 (14:04 +0100)]
Add The University of Manchester to ADOPTERS.md

Signed-off-by: Pierre Olivier <pierre.olivier@manchester.ac.uk>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1013

21 months agodoc: Introduce `ADOPTERS.md`
Alexander Jung [Mon, 15 May 2023 12:34:04 +0000 (12:34 +0000)]
doc: Introduce `ADOPTERS.md`

This commit introduces a new top-level file, `ADOPTERS.md`, which
contains a list of adopters of Unikraft.

Signed-off-by: Alexander Jung <a.jung@lancs.ac.uk>
Signed-off-by: Alexander Jung <alexander.jung@neclab.eu>
Co-authored-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #892

21 months agoarch/arm: Update cpu models compiler version checks
Stefan Jumarea [Tue, 20 Jun 2023 12:41:23 +0000 (15:41 +0300)]
arch/arm: Update cpu models compiler version checks

Previously the cpu selections were available only when compiling with `GCC`.
This commit adds `Clang` support by checking if the feature is available for
the compiler version.

A lot of checks will also be completely removed, since minimum required
compiler versions were introduced (`GCC` >= 7, `Clang` >= 9).

Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #949

21 months agoarch/arm64: Fix cpu and erratas for clang
Stefan Jumarea [Tue, 20 Jun 2023 08:09:26 +0000 (11:09 +0300)]
arch/arm64: Fix cpu and erratas for clang

Previously the cpu selections and the erratas were available only when
compiling with `GCC`. This commit adds `Clang` support by checking if
the feature is available for the compiler version.

A lot of checks will also be completely removed, since minimum required
compiler versions were introduced (`GCC` >= 7, `Clang` >= 9).

Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #949

21 months agobuild: Add minimum compiler version checks
Stefan Jumarea [Tue, 20 Jun 2023 08:12:38 +0000 (11:12 +0300)]
build: Add minimum compiler version checks

Since a lot of required features rely on some minimum compiler versions,
we check the version for every build.

The required versions are:
* `GCC` >= 7.0
* `Clang` >= 9.0

Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #949

21 months agoMakfile: Add target flags for `clang` with `AArch64`
Maria Sfiraiala [Fri, 9 Dec 2022 21:07:52 +0000 (23:07 +0200)]
Makfile: Add target flags for `clang` with `AArch64`

This commit adds target flags needed for cross-compiling with `clang`
for`AArch64`.
They are guarded by a condition which checks if these flags
are really needed (the compiler is `clang` and the architecture is
`AArch64`).

Signed-off-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #685

21 months agoplat/drivers/virtio-ring: Downgrade saturated descriptors error
Martin Kröning [Thu, 20 Jul 2023 13:20:48 +0000 (15:20 +0200)]
plat/drivers/virtio-ring: Downgrade saturated descriptors error

Real-world applications may run into this error many times per second.
I posted a simple reproduction into the issue.
According to @mschlumpp, this just means that Unikraft is filling up the
virtio descriptors faster than the host consumes them.
This commit downgrades the error to a debug message to avoid scaring and
to spend less time printing errors instead of doing work.

Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
GitHub-Closes: #853
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #984

21 months agolib/vfscore: Initialize stdio file lock
Marco Schlumpp [Mon, 3 Jul 2023 15:20:59 +0000 (17:20 +0200)]
lib/vfscore: Initialize stdio file lock

The code was previously relying on being able to zero initialize the
lock structure.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #999

21 months agobuild: Add compiler version checking for Clang
Andrei Tatar [Tue, 18 Jul 2023 16:43:30 +0000 (18:43 +0200)]
build: Add compiler version checking for Clang

This change adds version checking make functions in line with what we
have already for GCC. Also added are *_lt functions that check for a
maximum compiler version.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #983

21 months agolib/uksignal: Use correct kernel struct sigaction
Andrei Tatar [Wed, 31 May 2023 11:17:07 +0000 (13:17 +0200)]
lib/uksignal: Use correct kernel struct sigaction

The structs passed to the `sigaction` library call and the
`rt_sigaction` Linux syscall have different sizes and layouts; uksignal
previously used the incorrect library struct in the syscall, leading to
possible memory corruptions when called from a real libc (musl, newlib).
This change corrects this behavior by using the kernel struct.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #924

21 months agoplat/linuxu: Add fpsimd source file to build system
Stefan Jumarea [Tue, 27 Jun 2023 11:28:57 +0000 (14:28 +0300)]
plat/linuxu: Add fpsimd source file to build system

If `CONFIG_FPSIMD`, the `fp_arm64.c` source file should be added to the
build. Currently this is only done for `kvm`, so trying to build anything
for `linuxu` will fail with undefined references to the `fpsimd_*_state`
functions.

Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #962

21 months agolib/posix-event: `SYS_eventfd2`: Fix assertion with O_NONBLOCK
Simon Kuenzer [Thu, 18 May 2023 13:50:30 +0000 (15:50 +0200)]
lib/posix-event: `SYS_eventfd2`: Fix assertion with O_NONBLOCK

Commit
 fc96850 - lib/vfscore: Enable FIONBIO in fcntl(F_SETFL)
introduced a complete implementation of handling `FNONBLOCK` and `FASYNC`
with `fcntl`, including forwarding of error codes to the caller. Because
a standard `EINVAL` handler for `ioctl` was used for `eventfd` file
descriptors, setting `O_NONBLOCK` caused a failing assertion.

Checkpatch-Ignore: USE_NEGATIVE_ERRNO
Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Florin Postolache <florin.postolache.of@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #903

21 months agolib/posix-event: `SYS_eventfd2`: Use low-level `fcntl` syscall
Simon Kuenzer [Thu, 18 May 2023 13:48:28 +0000 (15:48 +0200)]
lib/posix-event: `SYS_eventfd2`: Use low-level `fcntl` syscall

The eventfd constructor system call `eventfd2` uses the the `fcntl` system
call to setup the file descriptor flag `O_NONBLOCK` during creation. This
commit makes sure that the low-level implementation is directly called so
that there is no dependency to `errno`.

Checkpatch-Ignore: AVOID_EXTERNS
Checkpatch-Ignore: FUNCTION_ARGUMENTS
Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Florin Postolache <florin.postolache.of@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #903

21 months agolib/posix-event: Debug config option
Simon Kuenzer [Thu, 18 May 2023 13:43:41 +0000 (15:43 +0200)]
lib/posix-event: Debug config option

Introduces a configuration option to enable debug messages for
`lib/posix-event`.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Florin Postolache <florin.postolache.of@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #903

21 months agolib/syscall_shim: uk_prsyscall(): Decode `eventfd`, `eventfd2`
Simon Kuenzer [Thu, 18 May 2023 13:41:56 +0000 (15:41 +0200)]
lib/syscall_shim: uk_prsyscall(): Decode `eventfd`, `eventfd2`

Adds the format definitions for the system calls`eventfd` and `eventfd2`
for decoding with `uk_prsyscall()`.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Florin Postolache <florin.postolache.of@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #903

21 months agolib/syscall_shim: uk_prsyscall(): Signed decimal parameter format
Simon Kuenzer [Thu, 18 May 2023 13:41:27 +0000 (15:41 +0200)]
lib/syscall_shim: uk_prsyscall(): Signed decimal parameter format

Introduces the parameter type `PT_DEC` as format for signed decimal
arguments.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Florin Postolache <florin.postolache.of@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #903

21 months agolib/9pfs: Provide `TIOCGWINSZ`-aware `ioctl` stub
Sergiu Moga [Thu, 13 Jul 2023 15:53:42 +0000 (18:53 +0300)]
lib/9pfs: Provide `TIOCGWINSZ`-aware `ioctl` stub

`python3` uses `isatty()`, which does an `ioctl()` with
`TIOCGWINSZ` as an argument for checking whether it should invoke
the interactive interpretor or just start interpreting a given
file.

Since `9pfs` is not a pseudo filesystem, it should be able to respond
to such `ioctl` accordingly for scripts defined in its filesystem
with a `ENOTTY`.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #981

21 months agolib/posix-sysinfo: Fill the `totalram` and `freeram` fields of `sysinfo`
Cosmin Vancea [Sun, 4 Jun 2023 20:37:17 +0000 (23:37 +0300)]
lib/posix-sysinfo: Fill the `totalram` and `freeram` fields of `sysinfo`

Newer glibc versions translate `sysconf(_SC_PHYS_PAGES)` to a `sysinfo`
syscall. Internally, `totalram` is used to compute the number of physical
pages.

Signed-off-by: Cosmin Vancea <csvancea@gmail.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #930

21 months agolib/posix-sysinfo: Add stub for `getcpu`
Cosmin Vancea [Sun, 4 Jun 2023 20:14:19 +0000 (23:14 +0300)]
lib/posix-sysinfo: Add stub for `getcpu`

It is hardcoded to always return the first CPU (index 0)

Signed-off-by: Cosmin Vancea <csvancea@gmail.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #930

22 months agolib/ukschedcoop: Add early check for runnable thread in idle thread
Sergiu Moga [Wed, 14 Jun 2023 14:11:39 +0000 (17:11 +0300)]
lib/ukschedcoop: Add early check for runnable thread in idle thread

Since we enable IRQ's before context switching, there is a chance that
IRQ's may fire in the short time frame between the enabling of IRQ's
in the scheduler before context switching and disabling of IRQ's before
entering the idle thread's halting state.

To fix this, make sure we disable IRQ's at the beginning of the idle
thread's halting loop and do a quick early check for runnable threads
alongside the one for exited threads.

Co-authored-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
Approved-by: Marco Schlumpp <marco@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #941

22 months agoplat/common: Ensure `IRQ`'s disabled in `ukplat_lcpu_halt_to`
Sergiu Moga [Wed, 14 Jun 2023 13:37:25 +0000 (16:37 +0300)]
plat/common: Ensure `IRQ`'s disabled in `ukplat_lcpu_halt_to`

Make sure that `IRQ`'s are disabled when calling `ukplat_lcpu_halt_to`.
Furthermore, do not surround the call to `time_block_until` with `IRQ`
`save`/`restore` and inform the function user through a `NOTE` to take
care of that himself.

Therefore, with this commit, change every other reference to this
function accordingly. Furthermore, change the name of the function to
reflect this.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Suggested-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
Approved-by: Marco Schlumpp <marco@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #941

22 months agoarch/arm/arm64: Fix `stxr`'s used in `spinlock`s register size
Sergiu Moga [Thu, 25 May 2023 07:08:42 +0000 (10:08 +0300)]
arch/arm/arm64: Fix `stxr`'s used in `spinlock`s register size

Our `spinlock`s have a size of 4-bytes and an alignment of 8, which,
in our `semaphore` implementation, causes a padding of 4 bytes. This
is fine, but it is an inconsistency.

With `QEMU` direct kernel boot, all of our free memory is zeroed out.
However, when using a previous boot phase such as `UEFI`, this
inconsistency shows itself through an always locked `spinlock`.
`UEFI` firmware "poisons" all of its free memory with `0xaf` bytes
which leads to our `stxr`, whose second register argument is 64-bit
instead of 32-bit, also atomically storing the `poisoned` padding.

Thus, make sure that our `stxr` uses 32-bit register for the to be
transferred register.

Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
GitHub-Fixes: #289
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #907

22 months agolib/ukboot: Allow disabling weak main using KConfig
Marco Schlumpp [Fri, 3 Feb 2023 08:26:33 +0000 (09:26 +0100)]
lib/ukboot: Allow disabling weak main using KConfig

This allows other modules to disable the weak main function. This is
useful in situations where the main is in a static library and the weak
symbol causes a premature end of search.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Gabriel Mocanu <gabi.mocanu98@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #898

22 months agolib/ukalloc: Fix underallocation bug in malloc
Andrei Tatar [Fri, 2 Jun 2023 09:59:50 +0000 (11:59 +0200)]
lib/ukalloc: Fix underallocation bug in malloc

This change fixes a logic error that allocates less memory than
necessary in specific cases, risking the memory corruption of internal
data structures, leading to unpredictable behavior and crashes.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Eduard-Florin Mihailescu <mihailescu.eduard@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #931

22 months agodoc: Correct docstring format to silence warnings
Andrei Tatar [Wed, 31 May 2023 13:20:58 +0000 (15:20 +0200)]
doc: Correct docstring format to silence warnings

Several unikraft files have inconsistent docstrings which generate many
warnings when building with clang.
This change corrects all inconsistencies, silencing the warnings.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #927

22 months agolib/9pfs: Stub uk_9pfs_ioctl
Razvan Deaconescu [Sun, 4 Jun 2023 15:03:51 +0000 (18:03 +0300)]
lib/9pfs: Stub uk_9pfs_ioctl

Change `uk_9pfs_ioctl` from `vfscore_vop_einval` to
`vfscore_vop_nullop`, effectively stubbing it. This means a call to
`uk_9pfs_ioctl` will no longer return `-EINVAL`, but it will return
`0`, tricking the caller into thinking `ioctl()` functionality is
available.

This is useful in binary-compatibility mode, where certain `ioctl()`
calls may cause the application to end, if an error code (such as
`-EINVAL` is returned). This is the case of Ruby interpreter running in
binary-compatibility mode.

Signed-off-by: Razvan Deaconescu <razvand@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #928

23 months agoplat/kvm/x86/tscclock: Switch i8254 to sw-triggered strobe on init
Federico Parola [Wed, 31 May 2023 23:16:08 +0000 (16:16 -0700)]
plat/kvm/x86/tscclock: Switch i8254 to sw-triggered strobe on init

To switch the i8254 to sw-triggered strobe mode a value must be
written into the counter. Previously the timer remained in rate
generator mode and kept generating interrupts until the counter
was written (e.g., for a sleep())

Signed-off-by: Federico Parola <federico.parola@polito.it>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #923

23 months agolib/ukschedcoop: Fix idling without wakeup time
Federico Parola [Wed, 31 May 2023 22:30:38 +0000 (15:30 -0700)]
lib/ukschedcoop: Fix idling without wakeup time

A wrong check caused the idle thread to keep busy looping instead of
halting the cpu when no wakeup time is set (i.e., wake_up_time == 0)

Signed-off-by: Federico Parola <federico.parola@polito.it>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #923

23 months agoposix-process: Add glibc compatible rusage structure
Stefan Jumarea [Sat, 27 May 2023 11:41:08 +0000 (14:41 +0300)]
posix-process: Add glibc compatible rusage structure

The musl imported rusage structure keeps an extra buffer in the rusage.
This can lead to errors if running applications in binary compatibility,
due to buffer overflows.

GitHub-Fixes: #915
Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #917

23 months agoRelease: v0.13.1 Atlas RELEASE-0.13.1
Alexander Jung [Thu, 1 Jun 2023 12:55:17 +0000 (14:55 +0200)]
Release: v0.13.1 Atlas

Signed-off-by: Razvan Deaconescu <razvand@unikraft.io>
Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Signed-off-by: Alexander Jung <alex@unikraft.io>
23 months agobuild: Add proper compiler detection
Stefan Jumarea [Mon, 22 May 2023 10:06:32 +0000 (13:06 +0300)]
build: Add proper compiler detection

Checking for the output of `$(CC) -v` may fail depending on compiler
versions (e.g. `clang-15 -v` on ubuntu will output `Ubuntu clang ...`,
making `CC_NAME` `Ubuntu` instead of `clang`).

Use a preprocessor program to find the proper compiler name and version.

The `cc-version.sh` script is taken from the linux kernel tree, and will
return a string containing the compiler name and version:
`GCC|Clang MAJOR_V.MINOR_V`.

Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #902

23 months ago9pfs: Change default 9p version to `9P 2000L`
Stefan Jumarea [Sat, 27 May 2023 08:57:40 +0000 (11:57 +0300)]
9pfs: Change default 9p version to `9P 2000L`

Using the `9p 2000U` version as the default leads to problems,
especially when using Unikraft in binary compatibility mode, since it
has a lot of limitation. There is no actual reason to use it as the
default 9P protocol version, so we just change it to `2000L`.

Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Andra Paraschiv <andra@unikraft.org>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #914

23 months agoplat/kvm: Add vmm option for arm64
Stefan Jumarea [Wed, 17 May 2023 08:15:32 +0000 (11:15 +0300)]
plat/kvm: Add vmm option for arm64

Add the option to choose a VMM when building for arm64. There are build
options that depend on the chosen VMM (i.e. PCI support), so the VMM
should be selected no matter what the chosen architecture is.

Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #900

23 months ago.github: Update Prerequisites in PR template to reference checkpatch.uk
Michalis Pappas [Sat, 27 May 2023 13:51:57 +0000 (15:51 +0200)]
.github: Update Prerequisites in PR template to reference checkpatch.uk

checkpatch.uk has been introduced to allow invoking checkpatch.uk with
Unikraft's configuration from any directory. Update the Prerequisites
section in the PR template to use that instead.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Alexander Jung <alex@unikraft.io>
Approved-by: Alexander Jung <alex@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #918

23 months agolib/syscall_shim: Sanitize ectx memory before use
Andrei Tatar [Fri, 21 Apr 2023 16:45:16 +0000 (18:45 +0200)]
lib/syscall_shim: Sanitize ectx memory before use

`ukplat_syscall_handler` allocates uninitialized stack space for saving
ectx; this coupled with brittle store/load routines (e.g., x86
XSAVE/XRSTOR) can result in a fatal fault.
This change sanitizes the allocated space before use.
Sanitizing is preferable to zero-ing out the entire area because
(1) we're on the syscall hot path, and (2) it's only needed in specific
situations.

Signed-off-by: Andrei Tatar <andrei.ttr@gmail.com>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #863

23 months agoarch/*: Add sanitization function for ectx memory
Andrei Tatar [Fri, 21 Apr 2023 16:24:12 +0000 (18:24 +0200)]
arch/*: Add sanitization function for ectx memory

Most context saving instructions/routines overwrite the target area with
a valid representation that can be loaded back. x86 XSAVE/XSAVEOPT are
an exception, as garbage data can remain in the context area causing the
following XRSTOR to fault. Thus any potentially dirty memory passed to
XSAVE* must be (minimally) sanitized before its first use.
This change introduces `ukarch_ectx_sanitize` as a function to perform
this sanitization if needed. It differs from `ukarch_ectx_init` in that
it does only the minimum work necessary to make memory ready for
`ukarch_ectx_store`, instead of preparing a valid argument for
`ukarch_ectx_load`.

Signed-off-by: Andrei Tatar <andrei.ttr@gmail.com>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #863

23 months agolib/uknetdev: Fix typo in uk_netdev_tx_one
Christiano Haesbaert [Wed, 17 May 2023 08:19:42 +0000 (10:19 +0200)]
lib/uknetdev: Fix typo in uk_netdev_tx_one

Signed-off-by: Christiano Haesbaert <haesbaert@haesbaert.org>
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
Approved-by: Alexander Jung <alex@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #901

23 months agoRelease: v0.13.0 Atlas RELEASE-0.13.0
Alexander Jung [Mon, 15 May 2023 21:09:49 +0000 (23:09 +0200)]
Release: v0.13.0 Atlas

Signed-off-by: Razvan Deaconescu <razvand@unikraft.io>
Signed-off-by: Marc Rittinghaus <marc@unikraft.io>
Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Signed-off-by: Alexander Jung <alex@unikraft.io>
23 months agolib/ukargparse: Support escaping of quotes
Simon Kuenzer [Fri, 24 Mar 2023 16:33:17 +0000 (17:33 +0100)]
lib/ukargparse: Support escaping of quotes

This commit introduces the support of escaping single (`'`) and double
quotes (`"`) with the escape character `\`. The behaviour is similar to
what one expects from Unix shells, like `sh` or `bash`.

Single-quoted characters and character sequences preserve each character.
Double-quoted characters and character sequences preserve each character
except the backslash `\`. The backslash can be used to switch of the
special meaning of a character, like the double quote (`\"`) or a
backslash (`\\`).

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #893

23 months agolib/posix-time: Add clock_nanosleep syscall
Costin Sin [Sat, 13 May 2023 06:48:31 +0000 (06:48 +0000)]
lib/posix-time: Add clock_nanosleep syscall

clock_nanosleep syscall should mimic the nanosleep syscall
when the clockid equals CLOCK_REALTIME and the TIMER_ABSTIME flag is
missing.

Signed-off-by: Costin Sin <sin.costinrobert@gmail.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #891

23 months agolib/vfscore: Dynamically allocate mount paths
Tu Dinh Ngoc [Tue, 4 Apr 2023 20:17:40 +0000 (20:17 +0000)]
lib/vfscore: Dynamically allocate mount paths

Currently `m_path` and `m_special` are statically-allocated arrays,
meaning their storage spaces are wasted in `static struct mount`
variables.  Dynamically allocate these variables to save on binary size.

Also add initcalls to initialize `struct mounts` in lib/posix-event,
lib/posix-socket and lib/vfscore.

Signed-off-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #826

23 months agolib/vfscore: Initialize lists for stdio_vnode
Razvan Deaconescu [Fri, 12 May 2023 22:28:57 +0000 (01:28 +0300)]
lib/vfscore: Initialize lists for stdio_vnode

The VFS `struct vnode` structure has two `uk_list_head` members:
`v_link` and `v_names`. These need to be initialized by a dedicated
macro / function, such as `UK_LIST_HEAD_INIT`.

The `stdio_vnode` variable (of type `struct vnode`) is not initializing
these members (they are filled with zeros). This will cause crashes when
using them.

This commit fixes that by properly initializing the `v_link` and
`v_names` members of the `stdio_vnode` variable.

Signed-off-by: Razvan Deaconescu <razvand@unikraft.io>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #889

23 months agolib/vfscore: Add semicolon to DPRINTF macro
Razvan Deaconescu [Fri, 12 May 2023 22:45:43 +0000 (01:45 +0300)]
lib/vfscore: Add semicolon to DPRINTF macro

The `DPRINTF()` macro in `vfscore` requires a semicolon (`;`). If this
is not present (once `DEBUG_VFS` is enabled), a build issue occurs.

Signed-off-by: Razvan Deaconescu <razvand@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #890

23 months agolib/uklock: Add SMP-safe reader-writer lock
Sairaj Kodilkar [Mon, 13 Mar 2023 05:42:46 +0000 (11:12 +0530)]
lib/uklock: Add SMP-safe reader-writer lock

This commit introduces a reader-writer lock. To avoid
starvation of readers and writer, the lock maintains the current
count of readers and writers waiting for the lock. New readers give
priority to waiting writers and writers give priority to readers on
unlock.

Co-authored-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Signed-off-by: Sairaj Kodilkar <skodilkar7@gmail.com>
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Reviewed-by: Andra Paraschiv <andra@unikraft.org>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #476

23 months agolib/uklock: Make semaphore SMP safe
Sairaj Kodilkar [Tue, 31 Jan 2023 10:19:53 +0000 (15:49 +0530)]
lib/uklock: Make semaphore SMP safe

On uniprocessor systems, it is sufficient to disable interrupts.
In SMP environments, however, it is not because a thread executing on a
different core can give rise to a race condition. Hence, to make the
semaphore SMP safe, we use a spinlock.

Signed-off-by: Sairaj Kodilkar <skodilkar7@gmail.com>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Reviewed-by: Andra Paraschiv <andra@unikraft.org>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #476

23 months agolib/uklock: Make mutex SMP safe
Sairaj Kodilkar [Tue, 31 Jan 2023 09:36:02 +0000 (15:06 +0530)]
lib/uklock: Make mutex SMP safe

We can safely acquire a lock on uniprocessor systems by disabling the
interrupts, but this does not work in an SMP environment. Hence, to
make the mutex SMP safe, this commit uses atomic compare exchange.
The commit also makes recursive locking optional (disabled by default).
While this is a breaking change, recursive locks are discouraged and
should only be used with caution. The current Unikraft core does not
use recursive locks anywhere.

Co-authored-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Signed-off-by: Sairaj Kodilkar <skodilkar7@gmail.com>
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Reviewed-by: Andra Paraschiv <andra@unikraft.org>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #476

23 months agolib/uklock: Provide irqf wrappers for uk_spinlock
Sairaj Kodilkar [Tue, 31 Jan 2023 06:52:01 +0000 (12:22 +0530)]
lib/uklock: Provide irqf wrappers for uk_spinlock

Holding a spinlock which is required by an interrupt handler, causes a
deadlock. To avoid this, the programmer must disable the interrupt
before acquiring such spinlocks. This involves saving the interrupt
flags before acquiring the spinlock and restoring them after
releasing the spinlock.

This commit provides versions of the ukplat_spin_* macros for the
uk_spinlock.

Co-authored-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Signed-off-by: Sairaj Kodilkar <skodilkar7@gmail.com>
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Reviewed-by: Andra Paraschiv <andra@unikraft.org>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #476

23 months agolib/uksched: Add unconditional wait and wakeup_one
Sairaj Kodilkar [Sun, 12 Mar 2023 07:55:56 +0000 (13:25 +0530)]
lib/uksched: Add unconditional wait and wakeup_one

This commit adds an unconditional wait, which is required
for reader-writer locks. The commit also adds an interface to
wakeup only a single thread sleeping on a wait queue.

Co-authored-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Signed-off-by: Sairaj Kodilkar <skodilkar7@gmail.com>
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Reviewed-by: Andra Paraschiv <andra@unikraft.org>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #476

23 months agolib/uksched: Make wait queues SMP safe
Sairaj Kodilkar [Tue, 31 Jan 2023 11:22:53 +0000 (16:52 +0530)]
lib/uksched: Make wait queues SMP safe

Wait queues use a linked list to store the threads waiting on a
particular condition. But operations such as add to and remove
from the list are not SMP safe. Hence, this commit associates
a spin lock with each wait queue.

Co-authored-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Signed-off-by: Sairaj Kodilkar <skodilkar7@gmail.com>
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Reviewed-by: Andra Paraschiv <andra@unikraft.org>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #476