Marc Rittinghaus [Fri, 14 Apr 2023 14:14:00 +0000 (16:14 +0200)]
lib/syscall_shim: Add struct printing
This commit adds macros for printing selected members of
struct types in the prsyscall output just like strace. The PT_STRUCT
macro takes the struct's name to form a new parameter type name.
The PR_STRUCT macro prints the fields specified in the var args. Nested
printing of struct fields members is supported for structs pointers as
well as for embedded structs. Whenever fields that are usually pointers
(e.g., PT_CHARP or PT_STRUCT) are embedded, the `PT_SVAL` flag must
be specified.
Checkpatch-Ignore: DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Razvan Deaconescu <razvand@unikraft.io> Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #836
Marc Rittinghaus [Fri, 14 Apr 2023 16:22:32 +0000 (18:22 +0200)]
lib/syscall_shim: Add 0x prefix to PT_HEX
Currently, it is hard to know if a value is a hexadecimal or decimal
number if there are no letters in the output. This commit adds the
hex prefix 0x to avoid the confusion.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Razvan Deaconescu <razvand@unikraft.io> Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #836
Marc Rittinghaus [Fri, 14 Apr 2023 15:47:19 +0000 (17:47 +0200)]
lib/syscall_shim: Print PT_OUT only on success
Previously, we are printing buffers and output strings also when the
call fails. However, in that case it will usually contain no meaningful
value so we reduce trace output by just printing the buffer's target
address.
Checkpatch-Ignore: COMPLEX_MACRO
Checkpatch-Ignore: TRAILING_SEMICOLON
Checkpatch-Ignore: DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON
Checkpatch-Ignore: MULTISTATEMENT_MACRO_USE_DO_WHILE Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Razvan Deaconescu <razvand@unikraft.io> Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #836
Marco Schlumpp [Wed, 1 Feb 2023 13:42:17 +0000 (14:42 +0100)]
lib/posix-event: Add an empty implementation of ioctl to eventfd
The fcntl function will forward fcntl(O_NONBLOCK), to the
underlying vnode `ioctl` op function, when a definition of FIONBIO and
FIOASYNC is present. This effectively makes `ioctl` a required function
for the vnops structure.
Signed-off-by: Marco Schlumpp <marco@unikraft.io> Reviewed-by: Maria Sfiraiala <maria.sfiraiala@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: #756
Eduard Vintilă [Sat, 11 Mar 2023 18:29:59 +0000 (20:29 +0200)]
lib/posix-event: Update `uio_offset` and `uio_resid` on successful reads
This commit updates (on a sucessful read) the `uio_offset` and
`uio_resid` members of the `uio` structure passed to the
`eventfd_vfscore_read` function. Without updating those members, the
`read` function from the vfscore layer will always report that no bytes
have been read at all.
Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com> Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io> Reviewed-by: Delia Pavel <delia_maria.pavel@stud.acs.upb.ro> Reviewed-by: Razvan Deaconescu <razvand@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #798
Marc Rittinghaus [Wed, 12 Apr 2023 13:22:54 +0000 (15:22 +0200)]
lib/9pfs: Add truncate to 9P_PROTO_2000U
When providing a length in the stat structure the 9pfs server on the
host will truncate the file to the specified size. We use this to also
enable truncation for the 2000U protocol version. Since uk_9pfs_setattr
checks for the protocol to use, the check can be completely dropped in
uk_9pfs_truncate.
Marc Rittinghaus [Wed, 12 Apr 2023 13:14:56 +0000 (15:14 +0200)]
lib/9pfs: Fix I/O error with chmod on directories
When we perform a chmod on a directory with the 9P_PROTO_2000U
protocol, the TWSTAT command is used with a previously received and
modified stat structure as parameter. There are two bugs in this.
First, updating the mode will remove the type information stored in the
high bits of the mode field. The call to the 9pfs device thus fails because
the 9pfs server thinks we want to change the directory to a regular
file.
Fixing this, will reveal another issue. The update should use a
specifically initialized "dont-touch" stat structure instead of
receiving the current structure. The 9pfs server will only update
the properties that divert from this "dont-touch" structure. This
is important because otherwise the length field of the stat
structure is set and the server tries to truncate the directory
object on the host, which fails and eventually will be reported
as failed chmod to the guest application.
Marc Rittinghaus [Wed, 12 Apr 2023 12:55:03 +0000 (14:55 +0200)]
lib/uksglist: Make sure buffers are mapped
With ukvmem and demand-paging enabled it can happen that buffers
supplied to the sglist are not fully backed by physical memory. In that
case the call to ukplat_virt_to_phys() fails, which expects a valid
mapping.
This commit adds a call to uk_vma_advise() to make sure the entire
buffer is backed by physical memory.
A future optimization should integrate the address translation and
backing with physical memory in a visitor pattern that traverses the
page tables only once instead of doing it one time for the advise and
then an extra time for each page of the buffer.
Marco Schlumpp [Thu, 9 Feb 2023 11:28:50 +0000 (12:28 +0100)]
plat/x86: Enable NX bit when initializing paging
There are a few reasons to enable the NX bit in the paging init routine:
* Setting the bit before checking for actual support is risky.
Currently, the check happens in the paging initialization routine.
* The bit is not used, when the Unikraft paging support is not enabled.
* Every boot entry point (32-bit/64-bit) would have a duplicated enable.
Signed-off-by: Marco Schlumpp <marco@unikraft.io> Reviewed-by: Florin Postolache <florin.postolache80@gmail.com> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #752
The issue #821 was caused by defining the feature macro `_BSD_SOURCE` in
a header file `include/vfscore/mount.h`. This commit moves the macro
from the header to its source files, resolving the issue.
Marco Schlumpp [Thu, 9 Feb 2023 14:46:02 +0000 (15:46 +0100)]
lib/ukalloc: Ensure the ifpages metadata does not break any alignments
By using the rounded version of the metadata size, we can ensure that
the resulting alignments are suitable for any C scalar type. This is a
requirement for any malloc implementation.
Signed-off-by: Marco Schlumpp <marco@unikraft.io> Reviewed-by: Andra Paraschiv <andra@unikraft.io> Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #757
Marc Rittinghaus [Thu, 20 Apr 2023 07:49:02 +0000 (09:49 +0200)]
lib/vfscore: Enable FIONBIO in fcntl(F_SETFL)
Currently, we are synching FIONBIO to the underlying file
implementation via an ioctl only if FIONBIO is defined in
vfscore. Since this is not the case, setting O_NONBLOCK on
a file descriptor does not have any effect. This commit
includes the necessary header and also fixes the
fcntl(F_SETFL) and ioctl() to make sure that the state of
the file stays in sync with its flags.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Andra Paraschiv <andra@unikraft.io> 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: #850
Marc Rittinghaus [Thu, 20 Apr 2023 07:12:35 +0000 (09:12 +0200)]
lib/nolibc: Fix ioctl signature
The signature of ioctl imported from musl uses a signed int as second
argument. This, however, differs from the definition in Linux, glibc,
and our own implementation, which use an unsigned long. Since using
int has lead to all sorts of problems also for musl (e.g., overflow into
sign bit), this commit adopts unsigned long also for the musl imported
header.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Andra Paraschiv <andra@unikraft.io> 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: #850
Stefan Jumarea [Thu, 20 Apr 2023 10:29:49 +0000 (13:29 +0300)]
lib/vfscore: Fix error return on symlink syscall
The `sys_symlink()` function returns `ENOENT` if the lookup failed,
instead of the actual error code `lookup()` exited with.
This may not always be right, since `lookup()` can return other error
codes (for example `ELOOP`).
Fix that by not setting the error code and just jump to the end of the
function.
Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
GitHub-Closes: #849 Reviewed-by: Andra Paraschiv <andra@unikraft.io> Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #851
Andra Paraschiv [Wed, 12 Apr 2023 05:12:52 +0000 (05:12 +0000)]
lib/vfscore: Initialize the fp variable to an empty string
Sometimes the fp local string variable includes data that was
used before e.g. previous file paths. Thus, fp can contain characters
that are not part of the currently processed file path and different
errors can appear e.g. ENOENT (No such file or directory), when trying
to open a file.
Initialize the fp variable to an empty string before using it.
Andra Paraschiv [Mon, 10 Apr 2023 09:11:32 +0000 (09:11 +0000)]
lib/vfscore: Fix the mountpoint length for the symlink support
Opening a symlink file doesn't successfully complete. The mountpoint
length provided to the function that resolves a symlink needs to be
adjusted.
Update the mountpoint length to be the difference in size between the
full path of the symlink file and the relative path of the symlink file
to the mountpoint.
Non-writable shared file mappings are treated as anonymous read-only file
mappings. Note that any writes made to the underlying file will not be
reflected in memory.
Signed-off-by: Cosmin Vancea <csvancea@gmail.com> Reviewed-by: Andra Paraschiv <andra@unikraft.io> Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #832
Hugo Lefeuvre [Sun, 16 Apr 2023 15:14:19 +0000 (17:14 +0200)]
lib/uk9p: Fix cast to invalid type
req is cast to void*, which is somewhat confusing since the function
returns a struct uk_9pfid *.
This patch was generated by the following Coccinelle semantic patch:
@@
expression E;
type T;
type R;
function f;
@@
T* f(...) {
<... when any
- return (R*)E;
+ return (T*)E;
...>
}
@@
type T;
identifier X;
function f;
@@
f(...) {
...
T* X;
<... when any
- return (T*)X;
+ return X;
...>
}
Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@manchester.ac.uk> Reviewed-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Approved-by: Marco Schlumpp <marco@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #844
Marco Schlumpp [Thu, 9 Feb 2023 12:04:57 +0000 (13:04 +0100)]
lib/ukvmem: Compile all source files for ISR context
The main and individual pagefault handlers are executed in an ISR
context. Not marking the files as `isr`, will cause the usual trouble
(clobbered vector registers).
Signed-off-by: Marco Schlumpp <marco@unikraft.io> Reviewed-by: Radu Nichita <radunichita99@gmail.com> Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #751
Marco Schlumpp [Mon, 13 Mar 2023 10:03:33 +0000 (11:03 +0100)]
lib/ukdebug: Handle a full tracing buffer correctly
The `__uk_trace_save_arg` function sets the `uk_trace_buffer_free` to
zero. The code previously subtracted the size from the
`uk_trace_buffer_free` variable even in this case causing an integer
underflow. Further trace-point emissions would then happily write past
the tracing buffer.
Signed-off-by: Marco Schlumpp <marco@unikraft.io> Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com> Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io> Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #810
Marco Schlumpp [Thu, 2 Mar 2023 14:16:40 +0000 (15:16 +0100)]
plat/common: Ensure the `.eh_frame` section stays
Using the `CONFIG_OPTIMIZE_DEADELIM` KConfig option adds the
`--gc-sections` command-line flag to the linker. Because the `.eh_frame`
section is not really referenced anywhere the linker will happily throw
it away. The solution is to mark it with `KEEP` in the linker scripts.
Signed-off-by: Marco Schlumpp <marco@unikraft.io> Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io> Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com> Approved-by: Alexander Jung <alex@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #776
Simon Kuenzer [Thu, 16 Mar 2023 10:51:22 +0000 (11:51 +0100)]
build: Detect if `gawk` can be used instead of `awk`
This commit lets the build system pick preferably `gawk` as drop-in
replacement for `awk`. GNU AWK has the advantage that it emits
understandable error messages on AWK script errors. This simplifies
developing or editing awk files.
Signed-off-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com> Reviewed-by: Florin Postolache <florin.postolache.of@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: #803
Marco Schlumpp [Mon, 20 Feb 2023 14:11:32 +0000 (15:11 +0100)]
plat/kvm: Change unhandled irq message to a tracepoint
It's not possible to call a print function in an interrupt context,
because these are not ISR safe and will mess up the interrupted context.
Signed-off-by: Marco Schlumpp <marco@unikraft.io> Reviewed-by: Andra Paraschiv <andra@unikraft.io> Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #768
The currently used syscall shim macro handles a return value of -1
by setting the return value to the value of errno, which results in
incorrect behaviour with mmap, which returns a MAP_FAILED (-1) address
as an indicator of failure. The result is that in case of mmap error,
the syscall will return the value of errno as the address, rather
than returning -1 and setting errno.
This commit fixes the issue by setting errno to the correct value
in case of mmap error.
Co-authored-by: Razvan Deaconescu <razvand@unikraft.io> Co-authored-by: Stefan Jumarea <stefanjumarea02@gmail.com> Signed-off-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro> Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com> Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #799
Marc Rittinghaus [Fri, 10 Mar 2023 10:03:32 +0000 (11:03 +0100)]
lib/posix-mmap: Fix MAP_SHARED_VALIDATE
MAP_SHARED_VALIDATE is defined as 3, while MAP_PRIVATE is defined
as 2. A MAP_PRIVATE will thus also evaluate to true for the
MAP_SHARED_VALIDATE test. This commit fixes the flag test.
Co-authored-by: Cosmin Vancea <csvancea@gmail.com> Co-authored-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro> 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: #790
Although using IST does not allow nested exceptions we go back to
a dedicated stack for regular traps and use IST to switch to it. This
prevents an issue with ukvmem, where a stack is allocated from pageable
heap and pushing to a non-present stack page leads to a double fault.
With this change the stack is switched to the dedicated trap stack and
the page fault for the original stack can be resolved.
A solution to allow nested exceptions would be to reconfigure the trap
to not use IST before executing code that can potentially fail and
restoring IST configuration on afterwards.
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: #790
Simon Kuenzer [Tue, 7 Feb 2023 10:03:58 +0000 (11:03 +0100)]
lib/syscall_shim: uk_prsyscall: Fix typecast for PT_BUFP
PT_BUFP prints binary buffer content human readable but had one
particular problem: Due to incomplete typecasting, printing of a
negative byte (__s8) caused printing a 4-byte hex sequence instead
of just one byte with the format: `\0xHH`.
This commit fixes this with proper typecasting.
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: #750
Currently, the user stack is used as kernel stack. This can be
a problem if the stack is not aligned on syscall entry. However, it
may be aligned for some calls. We thus cannot just push a fixed
amount of words. Instead, we store the original stack pointer and
align it using an and operation, which guarantees correct alignment
in any case.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Razvan Deaconescu <razvand@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #748
Simon Kuenzer [Sat, 4 Feb 2023 13:17:05 +0000 (14:17 +0100)]
lib/uksched: Align allocated stacks to arch requirement
This commits introduces aligns stack allocation that are done by
`lib/uksched` to the requirement of the target architecture. Without
aligned stacks, random crashed may occur because the compiler is assuming
such an alignment. An incorrect stack alignment can cause crashes because
the compiler may placed instructions in the code that will fail when
accessing values on the stack if not properly aligned.
Signed-off-by: Simon Kuenzer <simon@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: #747
support/scripts: Allow overlapping bootinfo region
Preliminary fix: Unikraft expects memory regions in the boot info
to not overlap and be page aligned. This is, however, not
compatible with having the .tdata section being assigned its
dedicated segment. This commit removes the sanity checks for
now as Unikraft can handle this specific case.
Signed-off-by: Marco Schlumpp <marco@unikraft.io> Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Michalis Pappas <michalis.pappas@opensynergy.com> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Reviewed-by: Razvan Deaconescu <razvand@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #746
When building Unikraft a warning might pop up stating that
the allocated section .tdata is not assigned to a loadable
segment. This commit puts the section into a segment which
is added to the PT_LOAD program headers.
Checkpatch-Ignore: SPACING Signed-off-by: Marco Schlumpp <marco@unikraft.io> Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Michalis Pappas <michalis.pappas@opensynergy.com> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Reviewed-by: Razvan Deaconescu <razvand@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #746
This commit introduces initial print format and decoding definitions for
the following system calls: `SYS_socket`, `SYS_bind`, `SYS_sendto`,
`SYS_recvmsg`
Signed-off-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com> Reviewed-by: Andra Paraschiv <andra@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #737
Simon Kuenzer [Wed, 1 Feb 2023 17:07:16 +0000 (18:07 +0100)]
lib/posix-futex: Remove circular config dependency to syscall_shim
This commit removes the unit test dependency of `lib/posix-futex` to
syscall_shim which caused a circular dependency over `lib/uktest`:
`lib/uktest` started to be dependent on `lib/syscall_shim` and because the
`lib/syscall_shim` depends on `lib/ukstreambuf`, the unit tests of
`lib/ukstreambuf` depend on `lib/uktest` too.
Signed-off-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com> Reviewed-by: Andra Paraschiv <andra@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #737
Simon Kuenzer [Wed, 1 Feb 2023 15:22:22 +0000 (16:22 +0100)]
lib/syscall_shim: strace-like output for binary system calls
This commit introduces the option to enable a strace-like output for binary
system calls. The option can be found under the debugging options of
`lib/syscall_shim`. The implementation utilizes the pretty-print function
`uk_snprsyscall()` for system call requests.
Signed-off-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com> Reviewed-by: Andra Paraschiv <andra@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #737
Simon Kuenzer [Wed, 1 Feb 2023 21:36:24 +0000 (22:36 +0100)]
lib/syscall_shim: Functions to pretty-print system call requests
This commit introduces an initial implementation of `uk_snprsyscall()` and
`uk_vsnprsyscall()`, two functions that pretty print a system call request
to a given C-string buffer. The system call name, the given arguments
(including flags and definitions) and the response are decoded.
As a start, this commit implements the formatting of the following system
calls: brk, open, openat, write, read, stat, fstat, close, dup, dup2,
gettid, getpid
Yet unsupported system calls are printed with the raw values of arguments.
Checkpatch-Ignore: DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON
Checkpatch-Ignore: MULTISTATEMENT_MACRO_USE_DO_WHILE
Checkpatch-Ignore: TRAILING_SEMICOLON
Checkpatch-Ignore: MISSING_BREAK
Checkpatch-Ignore: COMPLEX_MACRO
Checkpatch-Ignore: SPACING Signed-off-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com> Reviewed-by: Andra Paraschiv <andra@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #737
Simon Kuenzer [Mon, 30 Jan 2023 14:09:24 +0000 (15:09 +0100)]
lib/syscall_shim: Use `UK_NARGS()` from `<uk/essentials.h>`
This commit removes the macros `__UK_SYSCALL_NARGS()` and
`__UK_SYSCALL_DEF_NARGS()` and replaces their usage with `UK_NARGS()`
provided by `<uk/essentials.h>`.
Checkpatch-Ignore: LONG_LINE
Checkpatch-Ignore: COMPLEX_MACRO
Checkpatch-Ignore: SPACING Signed-off-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com> Reviewed-by: Andra Paraschiv <andra@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #737
Simon Kuenzer [Mon, 30 Jan 2023 02:34:07 +0000 (03:34 +0100)]
lib/ukstreambuf: Append operations for binary data
This commit introduces append operations for binary data:
- `uk_streambuf_memcpy()`: Append a copy of binary data
- `uk_streambuf_reserve()`: In-place appending of binary data (zero copy)
Signed-off-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com> Reviewed-by: Andra Paraschiv <andra@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #737
Simon Kuenzer [Mon, 30 Jan 2023 02:30:49 +0000 (03:30 +0100)]
lib/ukstreambuf: Append operations for C-strings
This commit introduces append operations for C-strings:
- `uk_streambuf_printf()`, `uk_streambuf_vprintf()`:
Append a printf-formatted string
- `uk_streambuf_strcpy`: Append a copy of a C-string
Signed-off-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com> Reviewed-by: Andra Paraschiv <andra@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #737
Simon Kuenzer [Mon, 30 Jan 2023 02:25:09 +0000 (03:25 +0100)]
lib/ukstreambuf: Initialization and basic operations
This commit introduces functions to allocate and/or initialize a streambuf
object for a given memory buffer. It also adds basic operations, like
resetting a streambuf buffer and querying its current state.
Signed-off-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com> Reviewed-by: Andra Paraschiv <andra@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #737
lib/uksched: Silence warning about unused variable
The parent variable was not used outside the assert. This leads to a
warning when asserts are disabled. This commit fixes the warning
be removing the variable.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@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: #739
Simon Kuenzer [Fri, 3 Feb 2023 19:40:05 +0000 (20:40 +0100)]
lib/vfscore: Cast initrd vbase to (void *)
PR #722 (Boot code refactoring) introduced an update to
`struct ukplat_memregion_desc` where the virtual base of a memory region is
now specified as a __vaddr_t integer value. Since it is a virtual address
we can cast it to (void *) to avoid build warnings in
`lib/vfscore/rootfs.c`.
Signed-off-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #744
Michalis Pappas [Sun, 11 Dec 2022 12:13:37 +0000 (13:13 +0100)]
plat/common: Use ukarch_random to generate PAuth key
With the addition of the ukarch_random() API it is now possible to
generate PAuth keys without delegating the implementation of key
generation to the platform. Remove ukplat_pauth_gen_key() from the
platform API and generate PAuth keys using the ukarch_random() API.
This commit fixes a typo in the ukplat_memregion_find_initrd0 macro.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #742
The current implementation uses the heap to allocate memory for the
virtio queues. This is problematic when used in conjunction with
on-demand paging for the heap. It can cause pages of the virtio
queue to be non-contiguous in physical memory. Some pages may
not even mapped to physical memory, yet. Since the hypervisor
does not care about the virtual mapping but only gets the physical
start address of the virtio queue (i.e., the physical address of the
first page), it will write on any physical page in the range of the
virtio queue (i.e., start physical address + size of queue). However,
these physical pages may belong to arbitrary other mappings. And
even if they belong to the same virtqueue, they might not be mapped
in the same order as in the virtual space. This is especially hard to
debug, because the guest is not performing the corrupting memory
writes.
To fix this, we request contiguous memory from the frame allocator
and map this in the same order in the virtual address space using
uk_vma_map_dma().
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Approved-by: Michalis Pappas <michalis.pappas@opensynergy.com> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #603
ukvmem provides the means to perform virtual address space management
where each virtual address space is build from a set of virtual memory
areas. This allows the library to select virtual addresses for mappings.
This is in contrast to the primitive paging API which does not manage
virtual address allocation. The library implements different VMA types
via VMA operations that define the VMA's behavior and contents.
Just like on Linux contiguous VMAs are merged and split depending on
the compatibility of their flags and the behavior defined by the VMA.
The library provides functions for mapping, unmapping, and
changing of memory attributes. The initial version comes with
support for x86_64, only.
Checkpatch-Ignore: LONG_LINE_COMMENT
Checkpatch-Ignore: FUNCTION_WITHOUT_ARGS
Checkpatch-Ignore: SPLIT_STRING Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Approved-by: Michalis Pappas <michalis.pappas@opensynergy.com> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #603
This commit updates the function documentation in the platform paging
header to the new coding convention so it is inline with the newly added
functions.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Approved-by: Michalis Pappas <michalis.pappas@opensynergy.com> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #603
ukplat_page_unmap() ignores non-existent PTEs and just goes on to the
next PTE in the memory range. The same behavior can be achieved with
ukplat_page_mapx(). However, ukplat_page_set_attr() stops at the first
non-existent PTE. This is problematic when on-demand paging has
lead to some pages in a memory range being present and others not.
This commit changes the behavior of ukplat_page_set_attr() to just
ignore this like the other mapping functions.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Approved-by: Michalis Pappas <michalis.pappas@opensynergy.com> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #603
Currently, the pg_ffree() function already ignored any errors, but it
has an assert to check if the error could be expected. We add
-ENOMEM to this, which signals that the memory has not been
allocated. While this would indicate a true error condition in case
a physical page is mapped only once, this is not the case if
the same page is mapped multiple times in a certain range and this
range is unmap en-bloc. In this case, the first free would free the
frame in the allocator while the other mappings would cause an
expected error.
An example for such a mapping could be a memory range which
should be zero-initialized by mapping all pages to the same
zero frame and using a CoW-style mapping.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Approved-by: Michalis Pappas <michalis.pappas@opensynergy.com> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #603
For temporary mappings of physical memory within the unikernel,
it is useful to have a fast alternative to ukplat_page_mapx() that also
automatically selects a virtual address for the mapping. This commit
introduces ukplat_page_kmap() and ukplat_page_kunmap() for this
purpose. However, they are not guaranteed to succeed if for some
reason no kernel mapping can be established.
However, for direct-mapped physical memory implementations the
functions just return the virtual address of the direct mapping. This
makes the kmap() very fast. In addition, this implementation cannot
fail and the unmap is a noop. The commit comes with an
implementation for x86_64 and arm64.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Approved-by: Michalis Pappas <michalis.pappas@opensynergy.com> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #603
The current ukplat_page_map() functions allows to map a range of virtual
pages to physical ones with a defined set of protections. This function
has the following limitations that create problems in the context of
virtual memory management:
1) If a mapping the virtual range already exists, the function
aborts with an error. The caller has no knowledge about the virtual
address that caused the error.
2) If the page attributes are set to read only while physical memory
should be allocated at the same time with paddr=__PADDR_ANY, the
caller has no chance of initializing the frame contents.
This commit replaces ukplat_page_map() with ukplat_page_mapx()
with the x being execute/extended. The mapx version allows the caller
to specify a function that should be called during mapping before
writing a PTE. The function can modify the PTE, instruct the mapping to
skip the current page, or switch to a smaller page size. The original
function behavior is provided when the mapx argument is NULL.
The mapx function can be used in case 1) to either overwrite or skip
existing mappings. The mapx function can also be used together with
a temporary mapping to initialize the physical memory of the current
page before establishing the mapping. This way, we avoid
map/rw -> remap/ro windows, which can also pose a security problem
besides the runtime overhead. If the caller sets paddr=0, it is also
possible to completely leave physical memory allocation to the mapx
function, for example, to serve memory from a cache.
For compatibility, a wrapper for ukplat_page_map() is provided.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Approved-by: Michalis Pappas <michalis.pappas@opensynergy.com> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #603
This commit introduces PT_Lx_PTE_SET_PADDR() which allows
to set the physical address in a page table entry. This commit
comes only with the x86_64 implementation.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Approved-by: Michalis Pappas <michalis.pappas@opensynergy.com> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #603
This commit introduces a macro called PAGE_SHIFT_Lx() that is
the reverse operation of PAGE_Lx_SHIFT() and allows to compute
the page table level from the page size order.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Approved-by: Michalis Pappas <michalis.pappas@opensynergy.com> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #603
Currently, the macro uses the shift to define the mask. However, the
mask is determined by the number of bits reserved for the size, not
by the number of bits shifted in the flag word.
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Marco Schlumpp <marco@unikraft.io> Approved-by: Michalis Pappas <michalis.pappas@opensynergy.com> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #603