Provide a ukalloc compatible interface. This enables the usage of pools
with common allocator interfaces, like `uk_malloc()`, `uk_free()`,
and `uk_memalign()`.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Simon Kuenzer [Tue, 22 Dec 2020 12:52:34 +0000 (13:52 +0100)]
lib/ukallocpool: LIFO pool implementation
Initial implementation of a memory pool (same-sized and fixed-sized object
allocator) following LIFO principle by using a single list to keep track of
free objects. LIFO is chosen to potentially better utilize hardware caches.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
lib/vfscore: Add missing goto statement in pwritev
The label out_errno in pwritev() is not used, though it should be, as it
is the case with preadv(). This updates pwritev() and add a missing goto
statement to the out_errno label. It makes the implementation of
pwritev() consistent with preadv().
Signed-off-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro> Reviewed-by: Alexander Jung <a.jung@lancs.ac.uk> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Pull-Request: #96
The out_error jump label used by goto in lib/vfscore/main.c is not
properly named. It results in an error when using vfscore. This fix
renames it to out_errno.
Signed-off-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro> Reviewed-by: Alexander Jung <a.jung@lancs.ac.uk> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Pull-Request: #96
Alexander Jung [Mon, 18 Jan 2021 15:45:32 +0000 (16:45 +0100)]
build: Upgrade missing platform to error
This commit turns the missing platform selection into an error.
This is useful when build step is pipelined to prevent further
steps to be completed as the build will not start without a target
platform.
Signed-off-by: Alexander Jung <a.jung@lancs.ac.uk> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Pull-Request: #88
dragosargint [Fri, 27 Nov 2020 13:55:42 +0000 (15:55 +0200)]
solve ukswrand does not generate random numbers
If you configure ukswrand with the platform timestamp
as initial seed, and you'll try to use getrandom function
or try to read from /dev/urandom you won't get random
numbers. This is because the initialization of the random
number generator, which is located in the swrand.c file,
is done earlier than the initialization of TSC clock.
Alexander Jung [Mon, 14 Dec 2020 17:23:55 +0000 (18:23 +0100)]
lib/vfscore: Change preadv and pwritev fd error handling.
This commit discards the `has_error` method in favour of in-line checks against
the file descriptor. In BSD's internal implementation, the error is simply
passed upwards from `dofilewrite` and `dofileread`. Additionally, the
`has_error` method would return a false positive in the circumstance where an
error was non-zero and did not constitute a EWOULDBLOCK or EINTR and the number
of bytes read was greater than zero. This scenario was discovered when a
buffer greater than the number of bytes available was read from a vnop read op
which returns the number of bytes read (as per POSIX requirements).
Additional checks inline with FreeBSD's[0][1] implementation are for whether
the fd is seekable; the offset of the file is non-zero; and, the file type is
not a character device.
Alexander Jung [Mon, 14 Dec 2020 17:21:11 +0000 (18:21 +0100)]
lib/vfscore: Reduce pread() and pwrite() to their -v() counterparts.
This commit reorganizes the pread() and pwrite() method such that they rely on
preadv() and pwritev(), respectively. This is due the overlap in
functionality, where pread() and pwrite() simply create a struct iovec method
which is to be passed in their relevant sys_ method.
Signed-off-by: Alexander Jung <alexander.jung@neclab.eu> Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com> Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Pull-Request: #79
The 9pfs driver fails to get the configuration when the
virtio_config_get returns a value greater than 0. The function
description on virtio_config_get was incorrect. The patches
changes the error check in the virtio-9p and the function
description
Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu> Reviewed-by: Alexander Jung <a.jung@lancs.ac.uk>
Simon Kuenzer [Tue, 22 Dec 2020 15:37:56 +0000 (16:37 +0100)]
lib/ukblkdev: API refactoring: `uk_blkdev_queue_configure()`
For API consistency reasons, this patch renames
`uk_blkdev_queue_setup()` to `uk_blkdev_queue_configure()`. This is
done to be inline with lib/uknetdev. Additionally and as counterpart
for queue configuration, we rename `uk_blkdev_release()` to
`uk_blkdev_unconfigure()`.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Laurentiu Barbulescu <lrbarbulescu@gmail.com>
Simon Kuenzer [Tue, 22 Dec 2020 15:37:55 +0000 (16:37 +0100)]
lib/ukblkdev: blkreq.h: Use UK_BLKREQ_ prefix for states and ops
Instead of using `UK_BLKDEV_REQ_` prefix for `struct uk_blkreq`
states (finished, unfinished) and `UK_BLKDEV_` prefix for operation
requests (read, write, flush) this commits simplifies the API by using
the `UK_BLKREQ_` prefix.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Laurentiu Barbulescu <lrbarbulescu@gmail.com>
Simon Kuenzer [Tue, 22 Dec 2020 15:37:54 +0000 (16:37 +0100)]
lib/ukblkdev: blkreq.h: Use typedef for __sector
Introduces `__sector` with a type definition instead with an alias
macro. This is done for consistency reasons. Additionally, the print
format macro `__PRIsctr` is introduced so that a sector number can be
printed correctly.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Laurentiu Barbulescu <lrbarbulescu@gmail.com>
Hugo Lefeuvre [Fri, 11 Dec 2020 16:35:14 +0000 (16:35 +0000)]
plat/kvm: enable XSAVE for PKRU register
According to Intel 64 and IA-32 Architectures Software Developer’s
Manual Vol. 1, Section 13.5.7 'PKRU State':
software can use the XSAVE feature set to manage PKRU state
only if XCR0[9] = 1
This patch sets XCR0[9] if PKU is available (and enabled via
CONFIG_HAVE_X86PKU).
Note: we do not support PKU without XSAVE. If CONFIG_HAVE_X86PKU is
selected but XSAVE is not available, we simply don't initialize PKU
and let the boot process gracefully abort later.
Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@manchester.ac.uk> Reviewed-by: Mocanu Gabriel <gabi.mocanu98@gmail.com>
Hugo Lefeuvre [Fri, 11 Dec 2020 16:35:12 +0000 (16:35 +0000)]
plat/kvm: toggle PKE bit if HAVE_X86PKU is enabled
Provided that PKU is advertised by cpuid (EAX=7, ECX=0, ECX bit 4),
Memory Protection Keys can be enabled by setting bit 22 (PKE) in CR4
(see Intel 64 and IA-32 Architectures Software Developer's Manual Vol.
3A, Section 2.5 'Control Registers').
Since we do not want to pay the cost of MPK-related code when MPK is
not enabled, we introduce a new HAVE_X86PKU property; MPK code is
compile-guarded so that it does not get compiled in without
HAVE_X86PKU. HAVE_X86PKU will be set by PKU kernel libraries later on.
At boot time, if HAVE_X86PKU is enabled, the kernel now checks whether
PKU is advertised by cpuid. If not, it aborts the boot process. The
underlying idea is that images compiled with HAVE_X86PKU are
*specialized* to be executed on PKU-enabled hardware. Hence, provided
that HAVE_X86PKU is set, there is a guarantee that PKU is supported
*and* enabled, effectively removing the need for checks later at
runtime. This might benefit performance when the domain switching rate
is high.
Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@manchester.ac.uk> Reviewed-by: Mocanu Gabriel <gabi.mocanu98@gmail.com>
For libraries with lots of object files, such as musl, `make clean` was
failing with "make: execvp: /bin/sh: Argument list too long" on some
machines (depending on default maximum command-line length).
The user could not solve this problem by changing his shell limits,
because GNU make resets those to system defaults.
This patch removes the direct call to `rm`, and replace it with a call
to `xargs rm`, using an intermediate file generated by `make`. The
intermediate file is kept after `clean` so that the user can inspect
which files have been removed.
Signed-off-by: Cyril Soldani <cyril.soldani@uliege.be> Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
-no-pie is not configurable for LIBLDFLAGS. It is always part of
LIBLDFLAGS, as -Wl,-r enforces that. If PIC/PIE is configured by
updating COMPFLAGS/LDFLAGS, no update will be required for LIBLDFLAGS.
Signed-off-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro> Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
If path is null and the memory is allocated by us then if size < len
we exit the call without freeing the memory. We solve this by moving the
check for sizer earlier.
Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@upb.ro> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
lib/vfscore: Fix bug where newdp is freed before initialization
When vp->v_type == VDIR we jump to out where newdp is freed
via the drele call but newdp has yet to be initialized. We
solve this by checking the output of namei first.
Signed-off-by: Constantin Raducanu <raducanu.costi@gmail.com> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Simon Kuenzer [Thu, 3 Dec 2020 00:03:42 +0000 (01:03 +0100)]
lib/syscall_shim: Avoid warning about unused system call arguments
Some system call implementations may not use all arguments which causes
a compiler warning. This commit adds the `__maybe_unused` attribute to
the arguments when one of the following macros is used for a system call
implementation: `UK_SYSCALL_DEFINE()`, `UK_LLSYSCALL_DEFINE()`,
`UK_SYSCALL_R_DEFINE()`, and `UK_LLSYSCALL_R_DEFINE()`.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Daniel Dinca <dincadaniel97@gmail.com>
Simon Kuenzer [Mon, 19 Oct 2020 10:17:27 +0000 (12:17 +0200)]
lib/ukboot: Provide option to initialize TLSF
Provides the option to initialize TLSF as allocator. The option is only made
available when `LIBTLSF_INCLUDED` is set. This should be done by the TLSF
library as soon included to Unikraft. It is expected that this solution
intermediate until we are able to dynamically register configuration options to
core libraries.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Hugo Lefeuvre <hugo.lefeuvre@manchester.ac.uk>
Simon Kuenzer [Thu, 1 Oct 2020 12:43:14 +0000 (14:43 +0200)]
plat/xen: x86: Maximum command line length from Xen headers
Instead of defining an own maximum size for the command line, in this
commit we use `MAX_GUEST_CMDLINE` from the Xen headers to defining the
maximum command line length.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Mon, 14 Sep 2020 12:47:56 +0000 (14:47 +0200)]
lib/ukboot: Additional Unikraft banners
Adds additional Unikraft banners to choose from. The "Powered by" banners are
intended to be the text-version of the official Unikraft project logo. The most
compatible variant (non-UTF8, non-extended ASCII) is set as the new default.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Simon Kuenzer [Mon, 14 Sep 2020 12:21:59 +0000 (14:21 +0200)]
include: Provide ANSI control sequence helper
Provide ANSI control sequence helper macros with <uk/plat/console.h>. Those
helpers and definitions can be used by console programs and ANSI console
drivers (e.g., VGA).
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
Simon Kuenzer [Fri, 30 Oct 2020 13:41:33 +0000 (14:41 +0100)]
lib/uknetdev: Introduce ioalign
Similar to lib/ukblkdev, we introduce a device info parameter (`struct
uk_netdev_info`) to query alignment requirements of packet buffer areas
for a uknetdev device: `ioalign`.
At the same time the commit clarifies a confusion with the queue
information parameter `nb_align`. This parameter is intended to describe
requirements for sizing a rx/tx queue. The comment is updated and the
`virtio-net` driver is corrected. This fixes commit a52168588.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
The API function `uk_netbuf_alloc_buf()` gets an alignment parameter which
can be used to request an aligned allocation for the packet buffer area
(`m->buf`).
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Fri, 30 Oct 2020 13:41:31 +0000 (14:41 +0100)]
lib/uknetdev: netbuf: Metadata at the end of an allocation
Place the netbuf metadata (`struct netbuf`) at the end of an allocation.
This enables forwarding possible alignments of an underlying allocation
to the buffer area of a netbuf. The metadata will no longer cause an offset
of the buffer start address (`m->buf`).
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Fri, 30 Oct 2020 13:41:30 +0000 (14:41 +0100)]
lib/uknetdev: netbuf: Store allocation base
In order to support flexible location of meta data (`struct uk_netbuf`) as
part of a corresponding allocation, we store the base address of it as
netbuf internal data. This address will be hand-over to the free operation
when such a netbuf is released.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>