]> xenbits.xensource.com Git - unikraft/unikraft.git/log
unikraft/unikraft.git
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

23 months agoinclude/arch: Add macros for atomic add, sub, or
Sairaj Kodilkar [Tue, 31 Jan 2023 06:47:50 +0000 (12:17 +0530)]
include/arch: Add macros for atomic add, sub, or

This commit adds macros to atomically add, subtract, and
perform a bitwise or based on the builtins provided by GCC.

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/vfscore: Avoid recursive locking in sys_rename
Marc Rittinghaus [Fri, 12 May 2023 15:24:10 +0000 (17:24 +0200)]
lib/vfscore: Avoid recursive locking in sys_rename

If the source and destination directories are the same in sys_rename,
the vnode is locked two times. This is problematic with non-recursive
mutexes. Also the double checks for access are not needed. This commit
adds a check to make sure in this case, only a single lock is done and
redundant checks are avoided.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@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: #888

23 months agolib/ukswrand: Add missing errno include
Marc Rittinghaus [Fri, 12 May 2023 14:19:06 +0000 (16:19 +0200)]
lib/ukswrand: Add missing errno include

This commit adds an include for errno.h that might not be included
otherwise and causes the build to fail.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@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: #887

23 months agolib/uk9p: Add workaround for QEMU WSTAT fsync bug
Marc Rittinghaus [Fri, 12 May 2023 12:00:38 +0000 (14:00 +0200)]
lib/uk9p: Add workaround for QEMU WSTAT fsync bug

This commit adds a workaround for a bug in QEMU where performing
an fsync using the WSTAT command in 9P2000.u leads to a zero-sized
response.

Checkpatch-Ignore: SUSPECT_CODE_INDENT
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
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: #886

23 months agolib/9pfs: Fix wrong fid for fsync in 9P2000.u
Marc Rittinghaus [Fri, 12 May 2023 11:58:50 +0000 (13:58 +0200)]
lib/9pfs: Fix wrong fid for fsync in 9P2000.u

Performing an fsync with the 9P2000.u protocol version previously
resulted in an I/O error. This is because we used the wrong fid
in the request. This commit moves the implementation of setattr
into a separate function that accepts the fid to use, and adjusts all
callers to provide the fid.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
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: #886

23 months agolib/nolibc: Add -ffreestanding flag
Razvan Deaconescu [Fri, 3 Feb 2023 11:41:38 +0000 (13:41 +0200)]
lib/nolibc: Add -ffreestanding flag

GCC optimizes the use of `memcmp()` if the `-ffreestanding` flag is
missing. In the current configuration, the flag is missing for GCC <= 9.
The resulting optimization causes in an infinite loop for `lib/nolibc`.

This commit fixes the issue by adding the `-ffreestanding` flag for
`lib/nolibc`, irrespective of the GCC version.

GitHub-Fixes: #728

Signed-off-by: Razvan Deaconescu <razvand@unikraft.io>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #740

23 months agolib/posix-process: Fix debug printing of TIDs
Florin Postolache [Thu, 11 May 2023 19:48:53 +0000 (22:48 +0300)]
lib/posix-process: Fix debug printing of TIDs

This commit makes so that the correct info will be printed when the current
thread gets killed. Before, instead of the actual TID, the empty TID from
the iterator would be printed.

Signed-off-by: Florin Postolache <florin.postolache.of@gmail.com>
Reviewed-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Andra Paraschiv <andra@unikraft.org>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #885

23 months agolib/posix-process: Reserve PID/TID 0 for kernel
Florin Postolache [Thu, 11 May 2023 10:07:48 +0000 (13:07 +0300)]
lib/posix-process: Reserve PID/TID 0 for kernel

This commit marks the TID/PID as unavailable to mimic the behaviour of
other kernels. This change also make pthread_rwlocks from glibc work in
binary compatibility mode.

Signed-off-by: Florin Postolache <florin.postolache.of@gmail.com>
Reviewed-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Andra Paraschiv <andra@unikraft.org>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #885

23 months agolib/posix-process: Correct MAX_PID config option
Florin Postolache [Thu, 11 May 2023 09:44:58 +0000 (12:44 +0300)]
lib/posix-process: Correct MAX_PID config option

This commit changes the tid_map size to reflect the kernel
reservation of the 0 TID/PID value. Before, the first thread
would set the 0 position in all used structures. Now, because
it will be already set, we need to make room for another.

Signed-off-by: Florin Postolache <florin.postolache.of@gmail.com>
Reviewed-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Andra Paraschiv <andra@unikraft.org>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #885

23 months agolib/vfscore: Fix file path resolution for 9pfs setup
Andra Paraschiv [Wed, 10 May 2023 10:40:27 +0000 (13:40 +0300)]
lib/vfscore: Fix file path resolution for 9pfs setup

The path resolution doesn't correctly work for a set of file cases
(e.g. symlinks to binaries or shared libraries).

One setup example is using 9pfs and the entire root local filesystem,
while running the "ls" binary and loading the shared libraries:

unikraft/support/scripts/qemu-guest -k build/app-elfloader_qemu-x86_64
-e / -a "/bin/ls /"

A "/" character is omitted from the last part of the path e.g. "/binls"
instead of "/bin/ls". Update the logic to include the missing character.

Signed-off-by: Andra Paraschiv <andra@unikraft.org>
Reviewed-by: Florin Postolache <florin.postolache.of@gmail.com>
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: #883

23 months agolib/vfscore: `fs0` as default device name for 9PFS
Simon Kuenzer [Fri, 5 May 2023 13:44:28 +0000 (15:44 +0200)]
lib/vfscore: `fs0` as default device name for 9PFS

This commit changes the default device/tag name for an automatically
mounted 9pfs root volume from `rootfs` to `fs0`. This is done for
convenience because `fs0` is the tag name that the `qemu-guest` support
script uses to name the first 9pfs share.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@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: #875

23 months agobuild: Disable compiler control flow protection
Andrei Tatar [Mon, 8 May 2023 09:02:45 +0000 (11:02 +0200)]
build: Disable compiler control flow protection

Compiler flag -fcf-protection sets control-flow integrity measures
that improve security, and sometimes defaults to enabled on distro
compilers. Some aspects of this feature are implemented in the compiler
header <cet.h> for e.g., stack unwinders. If this header is missing some
programs fail to compile.
Since we don't (yet) support pulling compiler headers into unikraft
build, this change disables cf-protection globally.

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: #881

23 months agoplat/kvm/x86: Fix register names for clang
Stefan Jumarea [Sun, 7 May 2023 10:53:19 +0000 (13:53 +0300)]
plat/kvm/x86: Fix register names for clang

`clang` does not understand the `rflags` register name, so the build
will fail. On the other hand, `gcc` does not understand `flags`, so the
register naming needs to be placed inside `#ifdef` guards.

Signed-off-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: #877

23 months agoplat/*, lib/ukalloc: Use PAGE_ALIGN_UP(), PAGE_ALIGN_DOWN()
Hugo Lefeuvre [Sun, 16 Apr 2023 13:08:17 +0000 (15:08 +0200)]
plat/*, lib/ukalloc: Use PAGE_ALIGN_UP(), PAGE_ALIGN_DOWN()

We have PAGE_ALIGN_DOWN, PAGE_ALIGN_UP, and PAGE_ALIGN macros, but don't
use them consistently. At places we still have code that does custom
ALIGN_DOWN, ALIGN_UP, and masks. Use appropriate macros everywhere.

This patch was generated by the following Coccinelle rule:

    @@
    expression E;
    @@

    - ALIGN_DOWN(E, __PAGE_SIZE)
    + PAGE_ALIGN_DOWN(E)

    @@
    expression E;
    type T;
    @@

    - ALIGN_DOWN(E, (T) __PAGE_SIZE)
    + PAGE_ALIGN_DOWN(E)

    @@
    expression E;
    @@

    - ALIGN_UP(E, __PAGE_SIZE)
    + PAGE_ALIGN_UP(E)

    @@
    expression E;
    type T;
    @@

    - ALIGN_UP(E, (T) __PAGE_SIZE)
    + PAGE_ALIGN_UP(E)

    @@
    expression E;
    @@

    - (E + PAGE_SIZE - 1) & PAGE_MASK
    + PAGE_ALIGN(E)

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@manchester.ac.uk>
Reviewed-by: Dragos Petre <dragos.petre27@gmailcom>
Reviewed-by: Alexandru Calciu <alxcalciu@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #842

23 months agolib/{nolibc,isrlib}: Modify pointer comparison
Maria Sfiraiala [Mon, 8 May 2023 07:49:43 +0000 (10:49 +0300)]
lib/{nolibc,isrlib}: Modify pointer comparison

This commit typecasts `src` and `dst` strings from `memmove()` to ensure
that their values are treated as pointers.

It also modifies the function implementation to handle overlapping.

Co-authored-by: Soumya Ranjan <ranjan42069@gmail.com>
Signed-off-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Signed-off-by: Soumya Ranjan <ranjan42069@gmail.com>
Reviewed-by: Radu Nichita <radunichita99@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: #880

23 months agobuild: Do not use segment annotations on linuxu
Marco Schlumpp [Wed, 12 Apr 2023 09:09:26 +0000 (11:09 +0200)]
build: Do not use segment annotations on linuxu

For the linuxu platform we rely on the default linker script and only
add some additional sections on top of that one. That also means that
there aren't any segments defined. This makes the segment specification
opt-in instead of assuming the segments are always defined.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Checkpatch-Ignore: SPACING
Checkpatch-Ignore: COMPLEX_MACRO
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #833

23 months agolib/ukdebug: Mark tracepoint sections as unallocated notes
Marco Schlumpp [Wed, 12 Apr 2023 09:06:17 +0000 (11:06 +0200)]
lib/ukdebug: Mark tracepoint sections as unallocated notes

At runtime we don't care about the content of them, and we only need
them on host side to decode the trace buffer.
This also prevents the linker from adding a segment for these sections.
Because the resulting segment sometimes only contained these two
sections, the final `strip` step would end up with an empty segment.
And in the case of the linuxu platform the resulting image was not
working anymore.

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

23 months agoplat/linuxu: Avoid re-initialization of the `heap` and `initrd`
Diego Alejandro Parra Guzman [Wed, 10 May 2023 11:12:39 +0000 (14:12 +0300)]
plat/linuxu: Avoid re-initialization of the `heap` and `initrd`

Keep a locally declared static variable `init` to cache the
current amount of memory region descriptors. This way, whenever
`ukplat_memregion_count` is called, `__linuxu_plat_heap_init` and
`__linuxu_plat_initrd_init` do not have to be executed more than
once.

Co-authored-by: Sergiu Moga <sergiu.moga@protonmail.com>
Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Signed-off-by: Diego Alejandro Parra Guzman <diego-alejandro.parra-guzman@tttech.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #878

23 months agoplat/linuxu: Add check for memory region index out of range
Diego Alejandro Parra Guzman [Wed, 10 May 2023 11:12:01 +0000 (14:12 +0300)]
plat/linuxu: Add check for memory region index out of range

Ensure that we do not try to fetch a memory region descriptor by an
index that is larger than our current memory region descriptor count.

Furthermore, this guarantees that `ukplat_memregion_count` is always
called before `ukplat_memregion_get` is executed fully. This way we
will always have the memory region descriptors as well as their count
set up and available before we try to fetch one.

Co-authored-by: Sergiu Moga <sergiu.moga@protonmail.com>
Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Signed-off-by: Diego Alejandro Parra Guzman <diego-alejandro.parra-guzman@tttech.com>
GitHub-Fixes: #766
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #878

23 months agosupport/scripts: Add additional recognised Git trailers to checkpatch
Alexander Jung [Mon, 8 May 2023 07:43:37 +0000 (07:43 +0000)]
support/scripts: Add additional recognised Git trailers to checkpatch

This commit introduces 3 additional Git trailers to be recognised by the
checkpatch program:

 - GitHub-Fixes   - Used to reference and address an open issue, often
                    a specific bug or problem. GitHub will automatically
                    close the issue once the commit with this Git
                    trailer is merged.
 - GitHub-Closes  - Used to reference an open issue or PR, which is not
                    specific to a particular bug.  For example, it can
                    be used to supercede another PR.  GitHub will
                    automatically close the referenced issue or PR once
                    a commit with this Git trailer is merged.
 - Co-authored-by - Similar to providing additional Signed-off-by's,
                    this trailer is recognised by GitHub and helps
                    attribute authorship, making the user's profile
                    more visible.
 - Approved-by    - Signifies the authoritive representative (usually a
                    project maintainer) who approved the commit.

Additional adjustments to the checkpatch script are made in order to
recognise non-standard Git trailer values (those from GitHub).

Signed-off-by: Alexander Jung <alex@unikraft.io>
Reviewed-by: Gabi Mocanu <gabi.mocanu98@gmail.com>
Reviewed-by: Radu Nichita <radunichita99@gmail.com>
Reviewed-by: Gabi Mocanu <gabi.mocanu98@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #879

23 months agodoc: Add Codacy code quality status badge to README.md
Aryan Verma [Thu, 16 Feb 2023 09:49:32 +0000 (15:19 +0530)]
doc: Add Codacy code quality status badge to README.md

GitHub-Fixes: #650
Signed-off-by: Aryan Verma <aryanvarma7272@gmail.com>
Co-authored-by: Alexander Jung <alex@unikraft.io>
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@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: #764

23 months agolib/uklibparam: Fixes for review PR #867
Simon Kuenzer [Mon, 8 May 2023 14:38:14 +0000 (16:38 +0200)]
lib/uklibparam: Fixes for review PR #867

Commits
 - 7741af97 "`UK_LIBPARAM_PARAM_ALIAS()`,`UK_LIBPARAM_PARAM_ARR_ALIAS()`"
 - 1cc3a2f6 "Rewrite of parser"
 - 243f0c45 "Declare __LIBNAME__, __BASENAME__ and __VARIANT__ for .lds.S"
 - 910b9bef "Add linker scripts to link dependencies"
should have been included with PR #867 but got merged by mistake with
PR #868 due to a dependency.

This commit addresses the comments provided with the review for PR #867.

Signed-off-by: Simon Kuenzer <simon@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: #882

23 months agoplat/xen: Fix unchecked uk_palloc() value in x86/mm.c
Hugo Lefeuvre [Sun, 16 Apr 2023 09:57:44 +0000 (11:57 +0200)]
plat/xen: Fix unchecked uk_palloc() value in x86/mm.c

The return value of uk_palloc is not checked in _arch_init_p2m.

Allocation failure at that point should never happen, but it's not a
reason not to check.

At this stage, in the event of a failure, we should probably abort the
boot altogether.

This bug was detected using the following Coccinelle spatch:

    @call@
    expression ptr;
    position p;
    @@

    ptr@p = uk_palloc(...);

    @ok@
    expression ptr;
    position call.p;
    @@

    ptr@p = uk_palloc(...);
    ... when != ptr
    (
     (ptr == NULL || ...)
    |
     (ptr != NULL || ...)
    )

    @depends on !ok@
    expression ptr;
    position call.p;
    @@

    ptr@p = uk_palloc(...);
    + if (ptr == NULL) return;

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@manchester.ac.uk>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #839

23 months agolib/vfscore: Handle `FIONBIO` command in `pipe_ioctl()`
Eduard Vintilă [Mon, 1 May 2023 16:13:55 +0000 (19:13 +0300)]
lib/vfscore: Handle `FIONBIO` command in `pipe_ioctl()`

The current `ioctl` implementation for pipes does not handle
the `FIONBIO` command, which leads to a negative error value being
returned. This commit introduces a simple case which sets the FNONBLOCK
flag when such a command is passed.

Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Reviewed-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
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: #874

2 years agoplat/common: Add firecracker shutdown signal
Andrei Tudor TOPALĂ (101668) [Thu, 14 Apr 2022 21:36:51 +0000 (00:36 +0300)]
plat/common: Add firecracker shutdown signal

Firecracker emulates a PS/2 controller and detects attempted writes to
the CPU reset line.

Co-authored-by: Marco Schlumpp <marco@unikraft.io>
Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

2 years agoplat/kvm: Include target hypervisor in image name
Marco Schlumpp [Mon, 17 Apr 2023 09:19:33 +0000 (11:19 +0200)]
plat/kvm: Include target hypervisor in image name

This makes it more clear on what hypervisor the image works on.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

2 years agoplat/kvm/x86: Use position independent code for lxboot
Marco Schlumpp [Tue, 11 Apr 2023 15:58:08 +0000 (17:58 +0200)]
plat/kvm/x86: Use position independent code for lxboot

This should make it easier in the future to extend the entry point to
support proper boot loaders such as the one in QEMU.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

2 years agoplat/kvm/x86: Workaround re-mapping low-mem areas
Marco Schlumpp [Thu, 9 Feb 2023 13:47:36 +0000 (14:47 +0100)]
plat/kvm/x86: Workaround re-mapping low-mem areas

The paging code currently does not unmap the memory area before the
kernel image, but then tries to re-map any region in that area.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

2 years agoplat/kvm/x86: Add an entry point for the firecracker hypervisor
Marco Schlumpp [Thu, 9 Feb 2023 13:43:51 +0000 (14:43 +0100)]
plat/kvm/x86: Add an entry point for the firecracker hypervisor

This is currently not conforming to the actual Linux boot protocol and
only suitable for firecracker. The kernel image would have to include a
proper Linux boot protocol header to allow loading with proper
bootloaders such as the one in QEMU.

Co-authored-by: Marc Rittinghaus <marc@unikraft.io>
Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

2 years agoplat/kvm/x86: Add structures/definitions for the linux boot protocol
Marco Schlumpp [Thu, 9 Feb 2023 13:41:00 +0000 (14:41 +0100)]
plat/kvm/x86: Add structures/definitions for the linux boot protocol

This defines the necessary structures to parse the information passed by
a linux boot protocol compatible bootloader.

Co-authored-by: Marc Rittinghaus <marc@unikraft.io>
Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

2 years agoplat/kvm: Add hypervisor/boot protocol configuration
Marco Schlumpp [Thu, 9 Feb 2023 13:38:27 +0000 (14:38 +0100)]
plat/kvm: Add hypervisor/boot protocol configuration

This allows the configuration of a target hypervisor. Depending on the
hypervisor a suitable boot protocol is selected.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

2 years agoplat/common: Extract non-multiboot specific memory region helpers
Marco Schlumpp [Mon, 13 Feb 2023 15:58:19 +0000 (16:58 +0100)]
plat/common: Extract non-multiboot specific memory region helpers

The multiboot entry point had a few internal functions that are also
useful for other entry points.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

2 years agoinclude/uk: Simplify RANGE_OVERLAP macro
Marco Schlumpp [Tue, 25 Apr 2023 08:05:41 +0000 (10:05 +0200)]
include/uk: Simplify RANGE_OVERLAP macro

We can simplify the check by observing that there are only two
conditions necessary to check whether a range does *not* overlap:
 - the end of range 0 is before the start of range 1
   [--0--) [--1--)
 - OR the start of range 0 is after the end of range 1
   [--1--) [--0--)
Inverting this gives us a simple condition for checking whether ranges
*do* overlap.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

2 years agoplat/*: Introduce cmdline length to bootinfo
Marco Schlumpp [Thu, 9 Feb 2023 13:34:39 +0000 (14:34 +0100)]
plat/*: Introduce cmdline length to bootinfo

Some boot protocols already have the length information and the internal
command line handling works with non-null terminated strings anyway.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

2 years agoplat/kvm/x86: Don't create fine-grained mapping for low memory
Marco Schlumpp [Thu, 9 Feb 2023 12:09:03 +0000 (13:09 +0100)]
plat/kvm/x86: Don't create fine-grained mapping for low memory

Mapping all memory makes the page table more independent of the actual
boot protocol. Firecracker currently puts the protocol information at a
very low address (0x7000).

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

2 years agoplat/kvm: Remove intermediate relocatable object step
Marco Schlumpp [Fri, 24 Feb 2023 16:18:55 +0000 (17:18 +0100)]
plat/kvm: Remove intermediate relocatable object step

This object was previously used to hide all symbols except the entry
point. But this step was removed making the relocatable object creation
unnecessary.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #789

2 years agoplat/drivers/ofw: Fix search in `fdt_node_offset_by_compatible_list`
Eduard Vintilă [Thu, 16 Mar 2023 12:13:06 +0000 (14:13 +0200)]
plat/drivers/ofw: Fix search in `fdt_node_offset_by_compatible_list`

The current implementation returns as soon as a node that matches a
compatible string is found. However, we should iterate through all of
the compatible list to make sure that we return the node with the least
offset value such that future searches will not skip any matching nodes.

Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Reviewed-by: Robert Kuban <robert.kuban@opensynergy.com>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #805

2 years agoplat/drivers/ofw: Fix incorrect offset in `fdt_translate_one`
Eduard Vintilă [Thu, 16 Mar 2023 12:10:46 +0000 (14:10 +0200)]
plat/drivers/ofw: Fix incorrect offset in `fdt_translate_one`

When a node is missing the "ranges" property, offset should be set to 0.
The current implementation sets offset to the address to be translated,
which ignores the fact that `fdt_default_translate`  is later called.
The latter function adds the offset to the same address,
resulting in doubling the effective address, when in fact a 1-to-1
mapping is necessary.

Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Reviewed-by: Robert Kuban <robert.kuban@opensynergy.com>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #805

2 years agolib/nolibc: Remove warnings of timespec
Takeru Wada [Mon, 13 Mar 2023 14:37:51 +0000 (14:37 +0000)]
lib/nolibc: Remove warnings of timespec

This commit fixes the definition of pointer arguments in GCC >= 11.

Signed-off-by: Takeru Wada <takew@asg.cs.tuat.ac.jp>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #800

2 years agolib/ukboot: Print environment variables before entering main
Simon Kuenzer [Thu, 16 Mar 2023 16:31:42 +0000 (17:31 +0100)]
lib/ukboot: Print environment variables before entering main

Signed-off-by: Simon Kuenzer <simon@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: #868

2 years agolib/posix-environ: Symbol aliases for `environ`
Simon Kuenzer [Tue, 14 Mar 2023 14:18:12 +0000 (15:18 +0100)]
lib/posix-environ: Symbol aliases for `environ`

In order to comply with common libc behavior, we provide the following
symbol aliases for environ`: `_environ`, `__environ`, `___environ`.

Signed-off-by: Simon Kuenzer <simon@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: #868

2 years agolib/posix-environ: Variables from kernel command line
Simon Kuenzer [Fri, 24 Feb 2023 00:45:52 +0000 (01:45 +0100)]
lib/posix-environ: Variables from kernel command line

Introduces the ability to populate additional environment variables via the
kernel command line.

Checkpatch-Ignore: SPACING
Signed-off-by: Simon Kuenzer <simon@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: #868

2 years agolib/posix-environ: Compiled-in environment variables
Simon Kuenzer [Tue, 14 Feb 2023 23:32:29 +0000 (00:32 +0100)]
lib/posix-environ: Compiled-in environment variables

We introduce the ability to compile-in up to 16 environment variables.
The values can be set via `menuconfig`. The initial `environ` array is
automatically sized to match the number of compiled-in values.

Signed-off-by: Simon Kuenzer <simon@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: #868

2 years agolib/posix-environ: Register and make it compile
Simon Kuenzer [Thu, 9 Feb 2023 20:54:40 +0000 (21:54 +0100)]
lib/posix-environ: Register and make it compile

This commit integrates and enables compiling of the imported environment
helper functions (see previous commit).

Signed-off-by: Simon Kuenzer <simon@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: #868

2 years agolib/posix-environ: Import from musl 1.2.3
Simon Kuenzer [Wed, 8 Feb 2023 16:01:41 +0000 (17:01 +0100)]
lib/posix-environ: Import from musl 1.2.3

This commit imports needed code from musl 1.2.3. This concentrates mostly
on the following helper functions for environment variables:
 - `clearenv()`
 - `getenv()`
 - `putenv()`
 - `setenv()`
 - `unsetenv()`

Checkpatch-Ignore: FUNCTION_WITHOUT_ARGS
Checkpatch-Ignore: LINE_SPACING
Checkpatch-Ignore: SPACING
Checkpatch-Ignore: TRAILING_STATEMENTS
Checkpatch-Ignore: SIZEOF_PARENTHESIS
Checkpatch-Ignore: TYPO_SPELLING
Signed-off-by: Simon Kuenzer <simon@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: #868

2 years agolib/uklibparam: `UK_LIBPARAM_PARAM_ALIAS()`,`UK_LIBPARAM_PARAM_ARR_ALIAS()`
Simon Kuenzer [Fri, 24 Feb 2023 00:42:55 +0000 (01:42 +0100)]
lib/uklibparam: `UK_LIBPARAM_PARAM_ALIAS()`,`UK_LIBPARAM_PARAM_ARR_ALIAS()`

This commit provides `UK_LIBPARAM_PARAM_ALIAS()` and
`UK_LIBPARAM_PARAM_ARR_ALIAS()` which are variants of `UK_LIBPARAM_PARAM()`
and `UK_LIBPARAM_PARAM_ARR()`. These registration macros allow to set a
custom parameter name instead of deriving it from the variable name.

Signed-off-by: Simon Kuenzer <simon@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: #868

2 years agolib/uklibparam: Rewrite of parser
Simon Kuenzer [Thu, 23 Feb 2023 23:42:29 +0000 (00:42 +0100)]
lib/uklibparam: Rewrite of parser

This commit introduces a rewrite of `lib/uklibparam`. The rewrite ensures
that it is errno-free, malloc-free, and TLS-free. This makes it ideal for
processing library parameters early during boot. It includes an own and
modified version of `strtoull` function that is used for parsing integer
values from the command line.
Additionally, the parser can handle arrays more intuitively (and for any
data type of the elements) while fully utilizing pre-processed argument
vectors. It relies on the fact that whitespacing and quoting is already
handled (e.g., by `lib/ukargparse`). There are new types that are more
inline with the ones defined by ukstore.

This rewrite introduces the ability to provide a parameter description
with updated parameter registration macros:
  UK_LIBPARAM_PARAM(variable, type, description)
  UK_LIBPARAM_PARAM_ARR(variable, type, count, description)
The description is printed on the help output.

The previous interfaces are kept for backwards compatibility. However,
it is planned to remove them as soon as the code base is completely
adopted.

Checkpatch-Ignore: SPACING
Checkpatch-Ignore: OPEN_BRACE
Checkpatch-Ignore: MACRO_WITH_FLOW_CONTROL
Signed-off-by: Simon Kuenzer <simon@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: #868

2 years agobuild: Declare __LIBNAME__, __BASENAME__ and __VARIANT__ for .lds.S
Simon Kuenzer [Thu, 23 Feb 2023 21:21:04 +0000 (22:21 +0100)]
build: Declare __LIBNAME__, __BASENAME__ and __VARIANT__ for .lds.S

.lds.S files are linker script files that use the C preprocessor in order
to generate the final .lds file. This commit provides Unikraft's common
declarations of `__LIBNAME__`, `__BASENAME__`, `__VARIANT__` to this
pre-processing step so that they can be used for generating linker scripts.

Signed-off-by: Simon Kuenzer <simon@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: #868

2 years agoplat/*: Add linker scripts to link dependencies
Simon Kuenzer [Thu, 23 Feb 2023 20:47:59 +0000 (21:47 +0100)]
plat/*: Add linker scripts to link dependencies

This commit adds needed linker scripts as dependency to the linking rule
of the final image. This dependency was mostly indirectly covered via
libraries. However, updates to platform linker scripts did not trigger
relinking the final image.
Additionally, pure API libraries (like `lib/ukfalloc`) would not even cause
building a linker script that is shipped with the library or injected with
an `EACHOLIB_SRCS` declaration. The library buildrule is generated but
because no library object is generated, the linker script was never be part
of a dependency list.

Signed-off-by: Simon Kuenzer <simon@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: #868

2 years agolib/nolibc: Add README.md
calex257 [Sat, 25 Feb 2023 15:53:56 +0000 (17:53 +0200)]
lib/nolibc: Add README.md

Add a brief description of nolibc, providing an overview
of its purpose, usage and limitations.

This commit also shows a relevant example of how to configure
an application to use Unikraft-specific assertions or the ones
implemented in nolibc.

Signed-off-by: Alexandru Calciu <alexandru.calciu@stud.acs.upb.ro>
Reviewed-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: #778

2 years agolib/vfscore: Cleanup sys_symlink
Marc Rittinghaus [Tue, 25 Apr 2023 10:24:08 +0000 (12:24 +0200)]
lib/vfscore: Cleanup sys_symlink

This commit cleans up sys_symlink() according to the current coding
conventions and uses separate jump labels for exits depending on
if the vnode lock needs to be released or not.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #866

2 years agolib/vfscore: Do not copy oldpath in symlink
Marc Rittinghaus [Tue, 25 Apr 2023 10:19:05 +0000 (12:19 +0200)]
lib/vfscore: Do not copy oldpath in symlink

With the changes to the vnode ops definitions the symlink operation
takes a constant string. We can thus just pass the input string on
without having to copy it.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #866

2 years agolib/ramfs: Switch to const strings for vnops
Marc Rittinghaus [Tue, 25 Apr 2023 10:16:06 +0000 (12:16 +0200)]
lib/ramfs: Switch to const strings for vnops

This commit changes all vnode operations to accept constant
string parameters to be inline with the changed definitions.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #866

2 years agolib/devfs: Switch to const strings for vnops
Marc Rittinghaus [Tue, 25 Apr 2023 10:14:49 +0000 (12:14 +0200)]
lib/devfs: Switch to const strings for vnops

This commit changes all vnode operations to accept constant
string parameters to be inline with the changed definitions.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #866