]> xenbits.xensource.com Git - unikraft/unikraft.git/log
unikraft/unikraft.git
2 years agolib/9pfs: Add README.md file for 9pfs
Delia-Maria Pavel [Sat, 15 Apr 2023 15:17:34 +0000 (18:17 +0300)]
lib/9pfs: Add README.md file for 9pfs

Signed-off-by: Delia-Maria Pavel <delia_maria.pavel@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: #837

2 years agolib/syscall_shim: Add (F|R|W|X)_OK and access
Marc Rittinghaus [Fri, 14 Apr 2023 15:01:15 +0000 (17:01 +0200)]
lib/syscall_shim: Add (F|R|W|X)_OK and access

This commit adds a definition of the (F|R|W|X)_OK flags
and the access syscall

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

2 years agolib/syscall_shim: Add pread64 syscall
Marc Rittinghaus [Fri, 14 Apr 2023 14:57:26 +0000 (16:57 +0200)]
lib/syscall_shim: Add pread64 syscall

This commit adds a definition of the pread64 syscall to prsyscall

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

2 years agolib/syscall_shim: Add utsname struct and uname
Marc Rittinghaus [Fri, 14 Apr 2023 14:55:57 +0000 (16:55 +0200)]
lib/syscall_shim: Add utsname struct and uname

This commit adds a definition of the utsname struct
and the uname syscall to prsyscall

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

2 years agolib/syscall_shim: Add stat struct
Marc Rittinghaus [Fri, 14 Apr 2023 14:49:53 +0000 (16:49 +0200)]
lib/syscall_shim: Add stat struct

This commit adds a definition of the stat struct to prsyscall

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

2 years agolib/syscall_shim: Add timespec struct
Marc Rittinghaus [Fri, 14 Apr 2023 14:23:20 +0000 (16:23 +0200)]
lib/syscall_shim: Add timespec struct

This commit adds a definition of the timespec struct to prsyscall

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

2 years agolib/syscall_shim: Add struct printing
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

2 years agolib/syscall_shim: Add 0x prefix to PT_HEX
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

2 years agolib/syscall_shim: Add PT_OCTAL to print octals
Marc Rittinghaus [Fri, 14 Apr 2023 14:46:14 +0000 (16:46 +0200)]
lib/syscall_shim: Add PT_OCTAL to print octals

There are already types for decimal and hexadecimal printing.
This commit adds a type for octals.

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

2 years agolib/syscall_shim: Make printing type optional
Marc Rittinghaus [Fri, 14 Apr 2023 16:10:56 +0000 (18:10 +0200)]
lib/syscall_shim: Make printing type optional

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

2 years agolib/syscall_shim: Print PT_OUT only on success
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

2 years agolib/posix-event: Implement the EFD_NONBLOCK flag for eventfd
Marco Schlumpp [Wed, 1 Feb 2023 13:40:47 +0000 (14:40 +0100)]
lib/posix-event: Implement the EFD_NONBLOCK flag for eventfd

This flag allows conveniently setting O_NONBLOCK without having to use
a separate `fcntl` call.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #754

2 years agolib/syscall_shim: Add `syscall` alias to `uk_syscall`
Marco Schlumpp [Wed, 1 Feb 2023 13:39:22 +0000 (14:39 +0100)]
lib/syscall_shim: Add `syscall` alias to `uk_syscall`

The symbol is required for binaries that were compiled against a Linux
musl and use musl's system call wrapper.

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

2 years agolib/posix-event: Add an empty implementation of ioctl to eventfd
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

2 years agolib/posix-event: Update `uio_offset` and `uio_resid` on successful reads
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

2 years agolib/9pfs: Add truncate to 9P_PROTO_2000U
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.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <teodor.teugea@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: #834

2 years agolib/9pfs: Add fsync to 9P_PROTO_2000U
Marc Rittinghaus [Wed, 12 Apr 2023 13:19:43 +0000 (15:19 +0200)]
lib/9pfs: Add fsync to 9P_PROTO_2000U

Using the unmodified "dont-touch" stat structure in uk_9pfs_setattr is
equivalent to performing an fsync on the file.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <teodor.teugea@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: #834

2 years agolib/9pfs: Fix I/O error with chmod on directories
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.

Github-Fixes: #812
Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <teodor.teugea@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: #834

2 years agolib/uksglist: Make sure buffers are mapped
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.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <teodor.teugea@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: #834

2 years agolib/uksignal: Add sigaltstack stub
Marc Rittinghaus [Wed, 12 Apr 2023 12:46:26 +0000 (14:46 +0200)]
lib/uksignal: Add sigaltstack stub

This commit adds a stub for the sigaltstack system call, which is
necessary to run GO applications in binary compat mode.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <teodor.teugea@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: #834

2 years agoplat/x86: Enable NX bit when initializing paging
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

2 years agoplat/common: Merge `.gcc_except_table`s
Marco Schlumpp [Tue, 7 Feb 2023 11:12:01 +0000 (12:12 +0100)]
plat/common: Merge `.gcc_except_table`s

These tables are generated by GCC for exception handling. This merges
the individual section together instead of keeping thousands of them
separate.

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: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #753

2 years agolib/vfscore: Remove _BSD_SOURCE from mount.h
Taehyun Noh [Sun, 2 Apr 2023 11:33:51 +0000 (20:33 +0900)]
lib/vfscore: Remove _BSD_SOURCE from mount.h

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.

Github-Fixes: #821
Signed-off-by: Taehyun Noh <likeinstein42@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: #824

2 years agolib/ukalloc: Ensure the ifpages metadata does not break any alignments
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

2 years agolib/nolibc: Define max_align_t type
Marco Schlumpp [Thu, 9 Feb 2023 14:27:09 +0000 (15:27 +0100)]
lib/nolibc: Define max_align_t type

Every scalar type has an alignment requirement that is less than or
equal the alignment requirement of this type.

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

2 years agolib/vfscore: Enable FIONBIO in fcntl(F_SETFL)
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

2 years agolib/nolibc: Fix ioctl signature
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

2 years agolib/nolibc: Prototypes for `pread` and `pwrite`
Simon Kuenzer [Tue, 18 Apr 2023 14:20:50 +0000 (16:20 +0200)]
lib/nolibc: Prototypes for `pread` and `pwrite`

This commit introduces the prototypes for `pread` and `pwrite` with
nolibc's `<unistd.h>` header. These functions are provided by
`lib/vfscore`.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Andra Paraschiv <andra@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: #846

2 years agolib/vfscore: Fix error return on symlink syscall
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

2 years agolib/posix-event: Fix type of `revents` pointer
Marco Schlumpp [Thu, 2 Mar 2023 14:12:10 +0000 (15:12 +0100)]
lib/posix-event: Fix type of `revents` pointer

The type of revents is a `short` and not an `int`. This caused
out-of-bounds writes and possibly in stack corruption.

Signed-off-by: Marco Schlumpp <marco@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: #775

2 years agolib/9pfs: Add comments to 9pfs.h file
Delia-Maria Pavel [Sat, 11 Mar 2023 14:09:17 +0000 (16:09 +0200)]
lib/9pfs: Add comments to 9pfs.h file

Signed-off-by: Delia-Maria 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: #794

2 years agolib/9pfs: Enable the symlink support for UK_9P_PROTO_2000U 9pfs version
Andra Paraschiv [Mon, 10 Apr 2023 09:25:04 +0000 (09:25 +0000)]
lib/9pfs: Enable the symlink support for UK_9P_PROTO_2000U 9pfs version

Till now, symlink files could be created / opened only when using the
UK_9P_PROTO_2000L 9pfs version.

The current default 9pfs version is UK_9P_PROTO_2000U.

Enable the symlink support also for the UK_9P_PROTO_2000U 9pfs version.

Signed-off-by: Andra Paraschiv <andra@unikraft.io>
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: #830

2 years agolib/vfscore: Initialize the fp variable to an empty string
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.

Signed-off-by: Andra Paraschiv <andra@unikraft.io>
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: #830

2 years agolib/vfscore: Fix the mountpoint length for the symlink support
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.

Signed-off-by: Andra Paraschiv <andra@unikraft.io>
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: #830

2 years agolib/ukvmem: Allow non-writable shared file mappings
Cosmin Vancea [Mon, 10 Apr 2023 15:43:11 +0000 (18:43 +0300)]
lib/ukvmem: Allow non-writable shared file mappings

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

2 years agolib/uk9p: Fix cast to invalid type
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

2 years agolib/vfscore: Fix potential free(NULL)
Hugo Lefeuvre [Sun, 16 Apr 2023 13:45:43 +0000 (15:45 +0200)]
lib/vfscore: Fix potential free(NULL)

This bug was found by Coccinelle with the following spatch:

    @@
    expression E;
    @@

    if(E) {...}
    -free(E);

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@manchester.ac.uk>
Reviewed-by: Tu Dinh Ngoc <dinhngoc.tu@irit.fr>
Reviewed-by: Eduard-Florin Mihailescu <mihailescu.eduard@gmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #843

2 years agolib/ukvmem: Compile all source files for ISR context
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

2 years agolib/ukdebug: Handle a full tracing buffer correctly
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

2 years agoplat/common: Ensure the `.eh_frame` section stays
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

2 years agolib/ukmmap: Unit tests: check mmap/munmap results
Kha Dinh [Thu, 16 Mar 2023 10:02:06 +0000 (19:02 +0900)]
lib/ukmmap: Unit tests: check mmap/munmap results

I added the unit test (adapted from posix-mmap tests) that call mmap/munmap
and check the results to see if they executed successfully.

Signed-off-by: Kha Dinh <dalo2903@gmail.com>
Reviewed-by: Delia Pavel <delia_maria.pavel@stud.acs.upb.ro>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #802

2 years agolib/ukmmap: replace deprecated WARN_STUBBED
Kha Dinh [Thu, 16 Mar 2023 09:32:30 +0000 (18:32 +0900)]
lib/ukmmap: replace deprecated WARN_STUBBED

WARN_STUBBED is now replaced by UK_WARN_STUBBED.

Signed-off-by: Kha Dinh <dalo2903@gmail.com>
Reviewed-by: Delia Pavel <delia_maria.pavel@stud.acs.upb.ro>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #802

2 years agobuild: Detect if `gawk` can be used instead of `awk`
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

2 years agolib/nolibc: Fix wrong type for the `st_nlink` field inside `struct stat`
Cosmin Vancea [Sun, 9 Apr 2023 20:52:33 +0000 (23:52 +0300)]
lib/nolibc: Fix wrong type for the `st_nlink` field inside `struct stat`

For Linux x64 it is supposed to be of type `unsigned long`, yet we
had it defined as `unsigned int`. Here is a link to the relevant
kernel structure:

https://elixir.bootlin.com/linux/v6.2.10/source/arch/x86/include/uapi/asm/stat.h#L86

Signed-off-by: Cosmin Vancea <csvancea@gmail.com>
Reviewed-by: Andra Paraschiv <andra@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: #829

2 years agoplat/kvm: Change unhandled irq message to a tracepoint
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

2 years agolib/posix-process: Fix build warnings
Konstantinos Koukopoulos [Fri, 31 Mar 2023 08:01:15 +0000 (11:01 +0300)]
lib/posix-process: Fix build warnings

GitHub-Fixes: #818

Co-authored-by: Nikos Oikonomou <el20014@mail.ntua.gr>
Signed-off-by: Nikos Oikonomou <el20014@mail.ntua.gr>
Signed-off-by: Konstantinos Koukopoulos <koukopoulos@gmail.com>
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: #820

2 years agolib/posix-mmap: Fix wrong errno value
Ioan-Teodor Teugea [Sat, 11 Mar 2023 20:04:08 +0000 (22:04 +0200)]
lib/posix-mmap: Fix wrong errno value

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

2 years agolib/posix-mmap: Fix MAP_SHARED_VALIDATE
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

2 years agolib/posix-mmap: Fix missing address update
Marc Rittinghaus [Thu, 9 Mar 2023 11:21:40 +0000 (12:21 +0100)]
lib/posix-mmap: Fix missing address update

The mmap() call does not return the allocated virtual address via the
addr argument.

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

2 years agoplat/kvm-x86: Use IST for regular traps
Marc Rittinghaus [Thu, 9 Mar 2023 11:19:45 +0000 (12:19 +0100)]
plat/kvm-x86: Use IST for regular traps

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

2 years agoRelease: v0.12.0 Epimetheus RELEASE-0.12.0
Alexander Jung [Tue, 7 Feb 2023 14:00:31 +0000 (14:00 +0000)]
Release: v0.12.0 Epimetheus

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>
2 years agolib/syscall_shim: uk_prsyscall: Fix typecast for PT_BUFP
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

2 years agoplat/common/x86: 16-byte align syscall stack
Marc Rittinghaus [Sun, 5 Feb 2023 11:02:52 +0000 (12:02 +0100)]
plat/common/x86: 16-byte align syscall stack

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

2 years agolib/uksched: Align allocated stacks to arch requirement
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

2 years agosupport/scripts: Allow overlapping bootinfo region
Marc Rittinghaus [Sat, 4 Feb 2023 04:32:20 +0000 (05:32 +0100)]
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

2 years agoplat/xen/x86: Add tls_load segment
Marc Rittinghaus [Sat, 4 Feb 2023 04:14:14 +0000 (05:14 +0100)]
plat/xen/x86: Add tls_load segment

This commit adds the tls_load segment that is needed for the .tdata
section.

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

2 years agoplat/xen/arm: Add tls_load segment
Marc Rittinghaus [Sat, 4 Feb 2023 04:13:51 +0000 (05:13 +0100)]
plat/xen/arm: Add tls_load segment

This commit adds the tls_load segment that is needed for the .tdata
section.

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

2 years agoplat/kvm/arm: Add tls_load segment
Marc Rittinghaus [Sat, 4 Feb 2023 04:13:28 +0000 (05:13 +0100)]
plat/kvm/arm: Add tls_load segment

This commit adds the tls_load segment that is needed for the .tdata
section.

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

2 years agoplat/kvm/x86: Add tls_load segment
Marc Rittinghaus [Sat, 4 Feb 2023 04:24:33 +0000 (05:24 +0100)]
plat/kvm/x86: Add tls_load segment

This commit adds the tls_load segment that is needed for the .tdata
section.

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

2 years agoplat/common: Put .tdata in tls_load segment
Marc Rittinghaus [Sat, 4 Feb 2023 04:04:28 +0000 (05:04 +0100)]
plat/common: Put .tdata in tls_load segment

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

2 years agolib/syscall_shim: Pretty-print format: clone
Simon Kuenzer [Wed, 1 Feb 2023 22:13:05 +0000 (23:13 +0100)]
lib/syscall_shim: Pretty-print format: clone

This commit introduces initial print format and decoding definitions for
the following system calls: `SYS_clone`

Checkpatch-Ignore: MISSING_BREAK
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

2 years agolib/syscall_shim: Pretty-print format: socket, bind, sendto, recvmsg
Simon Kuenzer [Wed, 1 Feb 2023 22:12:13 +0000 (23:12 +0100)]
lib/syscall_shim: Pretty-print format: socket, bind, sendto, recvmsg

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

2 years agolib/syscall_shim: Pretty-print format: clock_gettime
Simon Kuenzer [Wed, 1 Feb 2023 22:10:26 +0000 (23:10 +0100)]
lib/syscall_shim: Pretty-print format: clock_gettime

This commit introduces initial print format and decoding definitions for
the following system calls: `SYS_clock_gettime`

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

2 years agolib/syscall_shim: Pretty-print format: futex
Simon Kuenzer [Wed, 1 Feb 2023 22:08:59 +0000 (23:08 +0100)]
lib/syscall_shim: Pretty-print format: futex

This commit introduces initial print format and decoding definitions for
the following system calls: `SYS_futex`

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

2 years agolib/syscall_shim: Pretty-print format: mmap, munmap, mprotect
Simon Kuenzer [Wed, 1 Feb 2023 22:07:24 +0000 (23:07 +0100)]
lib/syscall_shim: Pretty-print format: mmap, munmap, mprotect

This commit introduces initial print format and decoding definitions for
the following system calls: `SYS_mmap`, `SYS_munmap`, `SYS_mprotect`

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

2 years agolib/posix-futex: Remove circular config dependency to syscall_shim
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

2 years agolib/syscall_shim: strace-like output for binary system calls
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

2 years agolib/syscall_shim: Functions to pretty-print system call requests
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

2 years agolib/syscall_shim: Use `UK_NARGS()` from `<uk/essentials.h>`
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

2 years agoinclude/essentials: UK_NARGS(): Support up to 25 arguments
Simon Kuenzer [Mon, 30 Jan 2023 14:05:32 +0000 (15:05 +0100)]
include/essentials: UK_NARGS(): Support up to 25 arguments

Increase the number of supported arguments of `UK_NARGS()` from 7 to 25.

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

2 years agolib/ukstreambuf: Unit tests: Append operations for binary data
Simon Kuenzer [Mon, 30 Jan 2023 02:53:36 +0000 (03:53 +0100)]
lib/ukstreambuf: Unit tests: Append operations for binary data

Registers `libuktest` unit tests for append operations of binary data to a
streambuf object.

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

2 years agolib/ukstreambuf: Unit tests: Append operations for C-strings
Simon Kuenzer [Mon, 30 Jan 2023 02:51:50 +0000 (03:51 +0100)]
lib/ukstreambuf: Unit tests: Append operations for C-strings

Registers `libuktest` unit tests for append operations of C-strings to a
streambuf object.

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

2 years agolib/ukstreambuf: Unit tests: Initialization and basic operations
Simon Kuenzer [Mon, 30 Jan 2023 02:46:37 +0000 (03:46 +0100)]
lib/ukstreambuf: Unit tests: Initialization and basic operations

Registers `libuktest` unit tests for initialization and basic operations of
a streambuf object.

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

2 years agolib/ukstreambuf: Append operations for binary data
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

2 years agolib/ukstreambuf: Append operations for C-strings
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

2 years agolib/ukstreambuf: Initialization and basic operations
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

2 years agolib/ukstreambuf: Add library skeleton
Simon Kuenzer [Mon, 30 Jan 2023 02:13:20 +0000 (03:13 +0100)]
lib/ukstreambuf: Add library skeleton

The library will provide helper functions and macros to simplify dealing
with appending of data and/or C-string to buffers.

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

2 years agolib/uksched: Silence warning about unused variable
Marc Rittinghaus [Fri, 3 Feb 2023 10:58:19 +0000 (11:58 +0100)]
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

2 years agolib/ukschedcoop: Silence warning about unused args
Marc Rittinghaus [Fri, 3 Feb 2023 10:54:58 +0000 (11:54 +0100)]
lib/ukschedcoop: Silence warning about unused args

When asserts are disabled we get warnings about unused args. This
commit silences the warnings.

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

2 years agolib/ukdebug: Silence warnings about unused args
Marc Rittinghaus [Fri, 3 Feb 2023 10:53:20 +0000 (11:53 +0100)]
lib/ukdebug: Silence warnings about unused args

If printing of source line and file is disabled, we get warnings about
srcline and srcname not being used. This commit silences the warning.

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

2 years agolib/vfscore: Cast initrd vbase to (void *)
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

2 years agoplat/kvm: Enable Pointer Authentication in KVM
Michalis Pappas [Sun, 11 Dec 2022 12:17:58 +0000 (13:17 +0100)]
plat/kvm: Enable Pointer Authentication in KVM

Signed-off-by: Michalis Pappas <mpappas@fastmail.fm>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #686

2 years agoplat/common: Use ukarch_random to generate PAuth key
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.

Signed-off-by: Michalis Pappas <mpappas@fastmail.fm>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #686

2 years agoinclude/uk/plat: Fix initrd0 macro
Marc Rittinghaus [Fri, 3 Feb 2023 18:35:25 +0000 (19:35 +0100)]
include/uk/plat: Fix initrd0 macro

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

2 years agolib/ramfs: Add README.md file
Delia-Maria Pavel [Tue, 27 Dec 2022 14:43:48 +0000 (16:43 +0200)]
lib/ramfs: Add README.md file

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

2 years agolib/ramfs: Add comments to ramfs.h file
Delia-Maria Pavel [Tue, 27 Dec 2022 14:34:45 +0000 (16:34 +0200)]
lib/ramfs: Add comments to ramfs.h file

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

2 years agolib/uknofault: Fix warning with ukvmem
Marc Rittinghaus [Thu, 2 Feb 2023 19:30:04 +0000 (20:30 +0100)]
lib/uknofault: Fix warning with ukvmem

When ukvmem is activated a warning may be observed during build
about ps being potentially uninitialized. This commit fixes this.

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

2 years agolib/posix-mmap: Introduce POSIX memory functions
Marc Rittinghaus [Thu, 2 Feb 2023 18:47:36 +0000 (19:47 +0100)]
lib/posix-mmap: Introduce POSIX memory functions

This commit adds the posix-mmap library that implements the POSIX
memory-mapping related functions such as mmap and munmap based
on ukvmem.

Checkpatch-Ignore: NON_RAW_SYSCALL
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

2 years agodrivers/virtio: Use DMA mapping with ukvmem
Marc Rittinghaus [Thu, 2 Feb 2023 19:03:37 +0000 (20:03 +0100)]
drivers/virtio: Use DMA mapping with ukvmem

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

2 years agolib/ukboot: Initialize VAS + Heap
Marc Rittinghaus [Thu, 2 Feb 2023 18:45:51 +0000 (19:45 +0100)]
lib/ukboot: Initialize VAS + Heap

When ukvmem is available, we can represent the heap as a virtual
memory area. This has the advantage of enabling on-demand paging
for the heap.

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

2 years agolib/ukvmem: Introduce virtual memory library
Marc Rittinghaus [Thu, 2 Feb 2023 18:43:54 +0000 (19:43 +0100)]
lib/ukvmem: Introduce virtual memory library

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

2 years agoinclude/plat: Update paging header to new CC
Marc Rittinghaus [Thu, 2 Feb 2023 18:19:37 +0000 (19:19 +0100)]
include/plat: Update paging header to new CC

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

2 years agoplat/common: Ignore non-existent PTEs
Marc Rittinghaus [Thu, 2 Feb 2023 18:37:19 +0000 (19:37 +0100)]
plat/common: Ignore non-existent PTEs

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

2 years agoplat/common: Ignore -ENOMEM errors in pg_ffree()
Marc Rittinghaus [Thu, 2 Feb 2023 18:30:13 +0000 (19:30 +0100)]
plat/common: Ignore -ENOMEM errors in pg_ffree()

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

2 years agoplat/common: Introduce ukplat_page_k(un)map()
Marc Rittinghaus [Thu, 2 Feb 2023 18:17:43 +0000 (19:17 +0100)]
plat/common: Introduce ukplat_page_k(un)map()

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

2 years agoplat/common: Introduce ukplat_page_mapx()
Marc Rittinghaus [Thu, 2 Feb 2023 18:11:39 +0000 (19:11 +0100)]
plat/common: Introduce ukplat_page_mapx()

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

2 years agoinclude/arch/x86_64: Add page fault error bits
Marc Rittinghaus [Thu, 2 Feb 2023 17:52:40 +0000 (18:52 +0100)]
include/arch/x86_64: Add page fault error bits

This commit adds bit definitions for parsing x86_64 page fault
error codes.

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

2 years agoinclude/arch/x86_64: Add PT_Lx_PTE_SET_PADDR()
Marc Rittinghaus [Thu, 2 Feb 2023 17:48:40 +0000 (18:48 +0100)]
include/arch/x86_64: Add PT_Lx_PTE_SET_PADDR()

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

2 years agoinclude/arch/[x86_64,arm64]: Add PAGE_SHIFT_Lx()
Marc Rittinghaus [Thu, 2 Feb 2023 17:44:33 +0000 (18:44 +0100)]
include/arch/[x86_64,arm64]: Add PAGE_SHIFT_Lx()

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

2 years agoinclude/uk/plat: Fix PAGE_FLAG_SIZE_MASK
Marc Rittinghaus [Thu, 2 Feb 2023 17:36:36 +0000 (18:36 +0100)]
include/uk/plat: Fix PAGE_FLAG_SIZE_MASK

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