Michalis Pappas [Fri, 4 Oct 2024 09:57:26 +0000 (11:57 +0200)]
plat/xen: Relax requirement for RDRAND
Enabling cpu-generated randomness by default breaks execution on
legacy x86_64 CPUs that don't support RDRAND. Update config to
enable CPU-generated randomness conditionally to the selection
of libukrandom.
In x86_64 libukrandom will seed the CSPRNG using RDRAND if the CPU
implements these instruction, unless LIBUKRANDOM_CMDLINE_SEED is
selected in the config.
On arm64 libukrandom will check if a device-tree is provided and
if a seed is set in the `/chosen/rng-seed` property, and otherwise
fall back to RNDR / RNDRRS if the CPU implements FEAT_RNG.
Signed-off-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Maria Pana <maria.pana4@gmail.com> Reviewed-by: Alex Apostolescu <alexx.apostolescu@gmail.com> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1496
Enabling cpu-generated randomness by default breaks execution on
legacy x86_64 CPUs that don't support RDRAND, as well as older
versions of QEMU provided by some distros when executing with TCG,
given that RDRAND support in TCG is introduced in QEMU 8.0.0.
Update config to enable CPU-generated randomness conditionally
to the selection of libukrandom. The TRNG will only be enabled
by applications that select libukrandom.
While this does not fix the problem at its core, it reduces its
scope to applications that explicitly require randomness.
Signed-off-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Maria Pana <maria.pana4@gmail.com> Reviewed-by: Alex Apostolescu <alexx.apostolescu@gmail.com> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1496
drivers/ukrandom: Introduce driver for CPU generated randomness
This is based on the implementation of ukarch_random (RDRAND / RDSEED
for x86_64, RNDR / RNDRRS for arm64).
Register to earlytab after earlycon. Libraries that require CSRNG
facilities at earlytab must register at a priority higher than
UK_RANDOM_EARLY_DRIVER_PRIO.
On arm64 this requires a CPU revision of at least armv8-5.a that
implements FEAT_RNG.
On x86_64 the minimum CPU requirement is Intel Ivy Bridge / AMD
Excavator (2012). RDSEED support is now optional, as it was introduced
in Intel Broadwell / AMD Zen (2015), so CPUs released between 2012 and
2015 support RDRAND but not RDSEED. On these CPUs seed_bytes() will
return an error, and seed_bytes_fb() will fall-back to random_bytes().
Michalis Pappas [Mon, 2 Dec 2024 13:12:53 +0000 (14:12 +0100)]
lib/ukrandom: Tighten the implementation of ukswrand
Add an internal check to ensure that the CSPRNG has been initialized.
This is an additional check so that we don't merely rely on the caller's
logic. Use __check_result on the definition of uk_swrand_randr().
Signed-off-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Maria Pana <maria.pana4@gmail.com> Reviewed-by: Alex Apostolescu <alexx.apostolescu@gmail.com> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1496
This assertion is redundant and breaks earlytab calls that
happen before we configure the interrupt controller. Protect
the global context with a spinlock instead.
Signed-off-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Maria Pana <maria.pana4@gmail.com> Reviewed-by: Alex Apostolescu <alexx.apostolescu@gmail.com> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1496
Add a new Kconfing option, namely LIBUKRANDOM_CMDLINE_INIT
to seed the CSPRNG via the cmdline. In ChaCha this is used
to pass 8 bytes for the key followed by 2 bytes for the nonce
in `random.seed` cmdline parameter.
When this option is enabled AND initialziation parameters are
passed to the cmdline, the underlying RNG driver is not used.
lib/ukrandom: Seed the CSPRNG from the cmdline
Provide the ability to seed ChaCha20 from the kernel's command
line. This is controlled by a newly introduced Kconfig option,
CONFIG_LIBUKRANDOM_CMDLINE_SEED. The relevant cmdline parameter
is `random.seed` that should by populted by the loader with an
array of 8 random 32-bit unsigned integers for the ChaCha20 key.
Seeding via the cmdline takes precedence over the device-tree and
drivers to RNG devices.
Checkpatch-Ignore: SPACING Signed-off-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Maria Pana <maria.pana4@gmail.com> Reviewed-by: Alex Apostolescu <alexx.apostolescu@gmail.com> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1496
Michalis Pappas [Tue, 1 Oct 2024 14:51:54 +0000 (16:51 +0200)]
lib/ukrandom: Seed the CSPRNG from the device-tree
Provide the ability to seed ChaCha20 from the `/chosen/rng-seed` node
of the dtb. This is controlled by a newly introduced Kconfig option
CONFIG_LIBUKRANDOM_DTB_SEED, enabled by default in platforms that
select LIBFDT.
Seeding via the device-tree takes precedence over the drivers, so if
a seed is set in the dtb, any driver selected is not used.
Signed-off-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Maria Pana <maria.pana4@gmail.com> Reviewed-by: Alex Apostolescu <alexx.apostolescu@gmail.com> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1496
Michalis Pappas [Tue, 1 Oct 2024 14:23:41 +0000 (16:23 +0200)]
lib/ukrandom: Limit libukrandom seed to ChaCha key
Unlike encryption, the nonce is not important when generating random
numbers as ChaCha20 can generate 2**64 blocks / 1ZiB with the same
(key, nonce) pair.
Set the nonce to a fixed value similarly to other ChaCha-based CSPRNG
implementations like [1]. This brings us in line with the device-tree's
`/chosen/rng-seed` node used by linux that consists of eight 32-bit
unsigned random integers for initializing the ChaCha key, allowing
Unikraft to use unmodified dtbs generated by VMMs.
Signed-off-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Maria Pana <maria.pana4@gmail.com> Reviewed-by: Alex Apostolescu <alexx.apostolescu@gmail.com> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1496
Michalis Pappas [Mon, 7 Oct 2024 13:52:19 +0000 (15:52 +0200)]
lib/ukrandom: Increase ChaCha rounds to 20
Although 8 rounds most likely provide enough security [1], ChaCha20
brings us in alignment with Linux, and allows us to implement tests
using the vectors defined in RFC8439.
[1] https://eprint.iacr.org/2019/1492.pdf
Signed-off-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Maria Pana <maria.pana4@gmail.com> Reviewed-by: Alex Apostolescu <alexx.apostolescu@gmail.com> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1496
lib/ukrandom: Update library to use the driver API
Update libukrandom to use the newly defined driver API. Make sure that
boot does not fail if libukrandom has not been successfully initialized.
Runtime errors should be returned instead. Specifically, getrandom() will
return -ENOSYS and device nodes won't be created. Similarly, calls to
the kernel API will return a negative value.
Update ChaCha to use seed with fallback, to handles cases where the
conditioned entropy is exhausted. Update /dev/hwrng to fill the buffer
with random_bytes() instead of random_seed().
Checkpatch-Ignore: AVOID_EXTERNS
Checkpatch-Ignore: ENOSYS Signed-off-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Maria Pana <maria.pana4@gmail.com> Reviewed-by: Alex Apostolescu <alexx.apostolescu@gmail.com> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1496
Simon Kuenzer [Thu, 21 Nov 2024 10:22:22 +0000 (11:22 +0100)]
lib/vfscore: Support embedded initrd with custom compiled-in fstabs
This commit enables compiling images with embedded initrds with "custom"
compiled-in mount tables (fstabs). As soon as one of the activated
compiled-in mount table references to the device `"embedded"`, the
configuration requires a path for an initrd for embedding at compile
time. Prio this change, an initrd could only be embedded via using
pre-configured (and non-"custom") table configuration that depends on
an embedded initrd, for example: "Embedded InitRD (CPIO)".
Robert Zamfir [Mon, 14 Oct 2024 18:51:25 +0000 (21:51 +0300)]
lib/vfscore: Change faccessat with AT_SYMLINK_NOFOLLOW
* Change faccessat with AT_SYMLINK_NOFOLLOW
* Move the path creation and logic before the AT_SYMLINK_NOFOLLOW
* Apply AT_SYMLINK_NOFOLLOW only if the file is an actual symlink
* I didn't implement the `don't follow link logic`
Checkpatch-Ignore: LONG_LINE_STRING
Checkpatch-Ignore: STRLCPY Signed-off-by: Robert Zamfir <georobi.016@gmail.com> Reviewed-by: Mihnea Firoiu <mihneafiroiu0@gmail.com> Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com> Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1462
Stefan Jumarea [Mon, 23 Sep 2024 12:14:27 +0000 (15:14 +0300)]
include/uk/arch: Define bool types for C++ compilers
If compiling using a C++ compiler, `_Bool` is undefined, as it is a C
built-in type and C++ compilers do not recognize it. Define `__bool`,
`__true` and `__false` for C++ compiler as `bool`, `true` and `false`.
Checkpatch-Ignore: REPEATED_WORD
Github-Fixes: #1513 Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com> Reviewed-by: Razvan Deaconescu <razvand@unikraft.io> Reviewed-by: Maria Pana <maria.pana4@gmail.com> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1500
build: use different progress flags based on the wget version
The Unikraft build system uses the `--show-progress` flag for
Wget1. This flag has been renamed to `--force-progress` in Wget2.
That's why we need to check the version of Wget before using either
one of the flags. There's a list of CLI changes from Wget1 to Wget2
here:
https://gitlab.com/gnuwget/wget2/-/wikis/Home
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io> Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com> Reviewed-by: Razvan Deaconescu <razvand@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1442
plat/xen: Include fp_arm64.c in FPSIMD Xen ARM64 builds
`fp_arm64.c` implements `fpsimd_save_state()` and
`fpsimd_restore_state()` that are required by FPSIMD ARM64 builds. The
file was not included in the build rules (in `Makefile.uk`) resulting in
a build error.
Fix the build error by including `fp_arm64.c` in the Xen build rules.
This is similar to its inclusion in the KVM build rules.
Sergiu Moga [Fri, 7 Jun 2024 15:28:58 +0000 (18:28 +0300)]
plat/common/x86: Use `X86_VIDEO_MEM_START` for SIPI vector allocation
Commit a001e41f607c ("plat/common/x86: Increase legacy high regions granularity")
changed the definitions of some x86 memregion related macro-definitions.
By mistake it forgot to adapt the `ukplat_memregion_alloc_sipi_vect`
function which was using one them. This was not caught at the time as it
required one to have SMP enabled in order to get the build error.
Andrei Tatar [Wed, 5 Jun 2024 15:30:09 +0000 (17:30 +0200)]
lib/nolibc: Compile string.c with -O3
This change makes nolibc's string.c compile with -O3 optimizations when
optimizing for performance. This gives compilers more freedom to better
optimize the often-used mem* and str* functions.
Signed-off-by: Andrei Tatar <andrei@unikraft.io> Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1454
Andrei Tatar [Wed, 5 Jun 2024 18:45:55 +0000 (20:45 +0200)]
lib/posix-process: Use posix-fdtab for prlimit
This change makes the prlimit syscall report the maximum file descriptor
using Kconfig options of posix-fdtab, instead of the vfscore hardcoded
default, thus correctly reporting the fdtab size.
Signed-off-by: Andrei Tatar <andrei@unikraft.io> Reviewed-by: Radu Nichita <radunichita99@gmail.com> Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1455
Andrei Tatar [Wed, 5 Jun 2024 18:37:00 +0000 (20:37 +0200)]
lib/posix-sysinfo: Use posix-fdtab for SC_OPEN_MAX
This change makes `sysinfo` take the size of the fdtab from Kconfig
options of posix-fdtab instead of a macro defined by vfscore.
This correctly reports the size of the file descriptor table, instead of
the vfscore hardcoded default.
Signed-off-by: Andrei Tatar <andrei@unikraft.io> Reviewed-by: Radu Nichita <radunichita99@gmail.com> Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1455
plat/xen: Fix Arm setup to work with new Xen console
This fixes a regression introduced in the `ukconsole`
changes. The recent updates to the Xen console drivers
removed the `prepare_console()` and `init_console()`
functions in favor of calling the same code through
the early init tab.
The primary function of this README is to document how the
GDB stub is used. In future commits, this README could
potentially be extended with extra documentation describing
the other features of `ukdebug`.
The `plat/common/arm/fp_arm64.c` file uses the `|isr` flag as suffix.
This enables the `-mgeneral-regs-only` flag, as shown in
`arch/arm/arm64/Makefile.uk` file. The `-mgeneral-regs-only` flag
disables the use of specialized registers (such as floating-point
registers), with the aim of not saving them during ISR processing.
However, the `plat/common/arm/fp_arm64.c` file uses floating point. So,
when `-mgeneral-regs-only` is enabled, it causes a build error, as
floating point registers are undefined. For some reason, neither GCC,
not Clang <= 17 don't fail the build. It does happen, however with Clang
>= 18.
Fix the build error by removing the `|isr` flag.
Also make the `fp_arm64.c` build only if both `CONFIG_FPSIMD` and
`CONFIG_ARCH_ARM_64` configuration options are enabled.
Signed-off-by: Razvan Deaconescu <razvand@unikraft.io> Approved-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com> Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com> Reviewed-by: Maria Pana <maria.pana4@gmail.com>
GitHub-Closes: #1497
If no [symbol] is associated with a choice, then you can not have multiple
definitions of that choice. If a [symbol] is associated to the choice,
then you may define the same choice (ie. with the same entries) in another
place."
libuklibparam: Fix symbols not present after linkage
In certain build (nginx/bincompat) linkage results into libukparam
symbols from individual libraries not making it into the executable
object.
Although the internal behavior of ld is not clear, it looks like the
issue is resolved by updating libuparam.ld.S to collect each library's
section rather than its individual symbols.
Razvan Rus [Sat, 30 Mar 2024 15:41:37 +0000 (17:41 +0200)]
libs/vfscore: Fix dirent64 warning
Current Musl-based builds generate warnings related to dirent64 definition.
Define _GNU_SOURCE in all souce files so it prevents the warning from happening.
Signed-off-by: Razvan Rus <razvanrus2003@gmail.com> Reviewed-by: Radu Nichita <radunichita99@gmail.com> Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com> Reviewed-by: Razvan Deaconescu <razvand@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1372
plat/kvm/arm64: Do not unmask PSTATE.D on IRQ entry
Enabling PSTATE.D at IRQ entry results into nested debug exceptions.
This is incorrect as the context restored on IRQ exit invalidates
any changes to the context made by the debug exception's handler.
Also remove the unmasking of PSTATE.F as at the present we don't
deal with FIQs.
Andrei Tatar [Wed, 5 Jun 2024 14:53:57 +0000 (16:53 +0200)]
include/uk/errptr: Fix NULL being an error pointer
Previously, `PTRISERR` would be true for NULL, breaking the convention
of error pointers that `PTR2ERR` returns a negative error code for
any pointer for which `PTRISERR` is true. This would add a subtle corner
case where errors could be silently ignored.
This change fixes this oversight. Code using `PTRISERR` ambiguously or
to erroneously check for NULL is also fixed.
Signed-off-by: Andrei Tatar <andrei@unikraft.io> Reviewed-by: Radu Nichita <radunichita99@gmail.com> Reviewed-by: Maria Pana <maria.pana4@gmail.com> Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1453
Xen console dependency on nolibc in `Config.uk` (`select LIBNOLIBC`)
causes conflict with the `plat/xen/Config.uk` configuration (`select
LIBNOLIBC if !HAVE_LIBC`) when a libc (such as Musl) is used.
The dependency must consider both using nolibc and using a libc (such as
Musl). Update dependency to select nolibc only when a libc is absent.
Signed-off-by: Razvan Deaconescu <razvand@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1487
lib/ukdebug: Disable gdb's ack mode if the stub is connected
Using acknowledgment packets only makes sense on unreliable connections.
But if the connection is reliable, disabling acknowledgment packets
makes the communication between gdb and the stub much faster.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
Thassilo Schulze [Thu, 27 Jun 2024 11:35:09 +0000 (13:35 +0200)]
drivers/uktty: Remove newline conversion from drivers
Turning a `\n` character into a `\r\n` character sequence
breaks the communication between the gdb stub and the gdb
host. The stub will calculate a checksum on the message
without the extra carriage returns but the host will receive
a message with the extra carriage returns that the drivers
add and thus the host will calculate a different checksum
than the stub.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
lib/ukdebug: Add breakpoints to set up and connect to stub
If the gdb stub is enabled, it registers a function in the inittab
that tries to connect to the gdb host. This function first checks
if the console with the ID from `debug.gdbcon` is available. If so,
this function executes a breakpoint instruction to enter the gdb
stub. If the console is not available, the breakpoint is skipped.
Checkpatch-Ignore: LONG_LINE_STRING Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
lib/ukdebug: Add virtual kernel console to gdb stub
The `debug.gdb_kern` parameter is a tristate. It determines
if the gdb stub should send kernel output to the gdb host
over the gdb remote protocol. A negative value means "auto".
In this case, the gdb stub sends kernel output to the gdb
host if the backing console had the `UK_CONSOLE_FLAG_STD[OUT|IN]`
flags set. "auto" is the default. A value of zero means "off";
kernel output is never sent to the gdb host. A positive value
means "on"; kernel output is always sent to the gdb host.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
Thassilo Schulze [Wed, 26 Jun 2024 14:04:47 +0000 (16:04 +0200)]
lib/ukdebug: Communicate with gdb host through `ukconsole`
The gdb stub now uses the `ukconsole` interface to talk
to gdb. That's why the stub also depends on `LIBUKCONSOLE`.
Without `ukconsole` providing a serial connection, the
stub is entirely useless.
The gdb stub communicates with the gdb host using one of
the console devices that are registered with `ukconsole`.
The ID of the console device that the stub should use is
specified in the `debug.gdb_cons` parameter. The stub will
clear the `UK_CONSOLE_FLAG_STD[OUT|IN]` flags on that device
and keep a reference to it to communicate with the gdb host.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
Thassilo Schulze [Tue, 27 Aug 2024 09:39:39 +0000 (11:39 +0200)]
lib/ukdebug: Add `qAttached` packet to gdb stub
This packet is not mandatory but gdb will probe for
it. Now we respond properly to the probing. This
packet must be updated to support the multiprocess
features of the gdb remote protocol.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
Marc Rittinghaus [Mon, 19 Aug 2024 09:44:28 +0000 (11:44 +0200)]
lib/ukdebug: Add `vCont` packet to gdb stub
This packet is used by the gdb host as a replacement for the
`c`, `s`, `C` and `S` packets. `vCont` has some more features
than these packets on their own. These features are related to
multi-threading support for the most part. We don't support
the multi-threading features of the gdb remote protocol, so
the `vCont` packet isn't a real improvement over the `c`,
`s`, `C` and `S` packets. But the gdb host still prefers to
use it.
Co-authored-by: Thassilo Schulze <thassilo@unikraft.io> Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
Marc Rittinghaus [Mon, 19 Aug 2024 09:38:23 +0000 (11:38 +0200)]
lib/ukdebug: Add `q` commands to gdb stub for target information
The two `q` commands (`qSupported` and `qXfer:features:read:target.xml`)
allow the gdb host to retrieve information about the target system
that's being debugged.
Checkpatch-Ignore: AVOID_EXTERNS
Checkpatch-Ignore: UNNECESSARY_PARENTHESES
Checkpatch-Ignore: SPDX_LICENSE_TAG Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
NOTE: The `target.xml` file from the QEMU source tree does not
strictly adhere to the gdb remote procol docs because it doesn't
include a `target` element. But in practice this element seems
to be optional.
NOTE: We aim to support the `org.gnu.gdb.i386.core` feature with
the target description for x86_64. The GDB docs specify the minimal
list of registers that must be included in the description for this
feature. See
https://sourceware.org/gdb/current/onlinedocs/gdb.html/i386-Features.html
The x86_64 target description that we have imported from QEMU includes
more register definitions than required by this feature. At present, we
do not support getting the extra registers. That's why any registers
that are included in the target description from QEMU but not required
by the `org.gnu.gdb.i386.core` feature have been removed. The removed
register definitions are: `ss_base` through `k_gs_base`, `cr0`, `cr2`,
`cr3`, `cr4`, `cr8`, `efer`, `xmm0` through `xmm15`, `mxcsr`.
Checkpatch-Ignore: LONG_LINE
Checkpatch-Ignore: COMMIT_LOG_USE_LINK Co-authored-by: Thassilo Schulze <thassilo@unikraft.io> Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
Marc Rittinghaus [Mon, 19 Aug 2024 09:12:06 +0000 (11:12 +0200)]
lib/ukdebug: Add memory read and write packets to gdb stub
These packets allow the gdb host to read and write memory on the
target system. This capability is used to implement breakpoints for
example.
There's an edge-case that the implementation of `gdb_arch_write_memory`
must handle. Assume virtual memory is enabled with `ukvmem` and consider
the following sequence of events:
1. the system starts and the gdb stub is entered early on in the boot
sequence
2. the gdb stub writes a breakpoint to some location in the program's
text
3. execution is resumed. Now virtual memory is initialized. The location
in the program's text that the stub wrote to is marked read-only
4. the breakpoint that the stub created is hit. The stub has to write
to the read-only page to remove the breakpoint and resume exeuction
This edge-case is handled by using addresses from `ukplat_page_kmap`
instead of the addresses that are passed to `gdb_arch_write_memory`.
Checkpatch-Ignore: UNNECESSARY_PARENTHESES Co-authored-by: Thassilo Schulze <thassilo@unikraft.io> Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
arch: Add SP and PC getters and setters for struct __regs
Add architecture-specific getters/setters for the stack pointer
and program counter of a `struct __regs`. ELR_EL1 is used as the
PC on Arm since `struct __regs` is used in exception context.
`isrlib` had a libc dependency because `isrlib` used libc-defined
types. However, there are equivalent types defined in the kernel
so that we can remove the libc dependency by switching to the
Unikraft-internal types. By removing the libc dependency, we also
remove the potential for a recursive dependency cycle. E.g., now
a library used by `nolibc` can safely select `isrlib`.
Checkpatch-Ignore: SPACING Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
The gdb stub selects `uknofault` to access memory in a safe way.
But making the stub select `uknofault` creates two circular dependencies.
There is a similar issue with `uktest`. This commit works around these
circular dependency issues by switching from `select` to `depends on`.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
Marc Rittinghaus [Mon, 19 Aug 2024 08:34:37 +0000 (10:34 +0200)]
lib/ukdebug, arch/arm: Add main loop to handle incoming packets
The main loop of the gdb stub receives packets, calls the appropriate
handlers and responds to the gdb host. The loop is entered after a
debug trap has been caught. The code in `lib/ukdebug/arch/*` implements
the trap handling for the ARM64 and x86_64 architectures.
Checkpatch-Ignore: COMPLEX_MACRO
Checkpatch-Ignore: UNNECESSARY_PARENTHESES Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
Marc Rittinghaus [Mon, 19 Aug 2024 08:23:22 +0000 (10:23 +0200)]
lib/ukdebug: Introduce gdb stub beginning with send/receive functions
This commit starts introducing the gdb stub with the functions that
allow the stub to send data to and receive data from the gdb host.
The actual transmission of data isn't implemented yet. That's why
the `gdb_dbg_putc` and `gdb_dbg_getc` functions are stubs for now.
Checkpatch-Ignore: MACRO_WITH_FLOW_CONTROL Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1479
Thassilo Schulze [Mon, 24 Jun 2024 12:57:32 +0000 (14:57 +0200)]
plat/xen: Update Xen to use console drivers in `drivers/`
* Imply the console drivers from the Xen platform
if `ukconsole` is enabled.
* The original Xen console header that was called
`common/console.h` in the platform now lives in
the `drivers/` folder where it's accessible as
`xen/console.h`.
* The Xen console drivers in the `drivers/` directory
will register in the early init tab. That's why the
setup on x86 and Arm has to change slightly (see diff)
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1464
Thassilo Schulze [Mon, 17 Jun 2024 14:37:46 +0000 (16:37 +0200)]
plat/kvm: Delete console driver files for x86_64
* The implementation of the console drivers now lives
in `drivers/`. Additional functionality that was in
the platform before is in `ukconsole`.
* The delete console driver configuration options now
live in the `drivers/uktty/` subdirectories
* Delete MRD-related code for x86 video memory. This
MRD is inserted by the VGA driver on init now.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1464
drivers/ukconsole: Adapt PL011 driver to work with `ukconsole`
The PL011 driver can register devices in the early init table
and in the inittab. There can only be a single device that's
registers in the early init table and the base address for
that device can be configured using kconfig or using a kernel
parameter.
Any number of devices can be registered in the init table. The
DTB is searched for PL011 UARTs. If a device is found, a new
device structure is dynamically allocated and registered with
`ukconsole`.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1464
drivers/ukconsole: Adapt VGA driver for use with `ukconsole`
The VGA driver registers a device with `ukconsole` in
the early init table. The device that the driver registers
only has the `UK_CONSOLE_FLAG_STDOUT` flag set because the
VGA driver doesn't implement keyboard input.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1464
drivers/ukconsole: Adapt COM driver to work with `ukconsole`
The COM driver now exposes COM ports COM1 to COM4. The
driver registers a `struct uk_console` for a port to
make that port available to `ukconsole`. One of the
ports can be configured as the "early console". This
port is initialized and registered in the early init
table. All other ports besides the configured "early
console" are initialized and registered when the init
table runs.
Checkpatch-Ignore: EMBEDDED_FUNCTION_NAME Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1464
Thassilo Schulze [Tue, 25 Jun 2024 13:51:33 +0000 (15:51 +0200)]
plat/kvm: Move `serial_console.c` into `drivers/ukconsole/ns16550/`
`serial_console.c` implements a driver for the COM ports
on x86. The driver is now moved out of the platform and
will be registered with `ukconsole` in the future. The device
underlying the COM port interface is a 16550 / 8250 so the
`ns16550` subdirectory is the right place to put this driver.
Because the device is the same on Arm and on x86, the `com.c`
and `ns16550.c` driver should be merged into one driver in
the future.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1464
Thassilo Schulze [Thu, 20 Jun 2024 11:38:18 +0000 (13:38 +0200)]
lib/syscall_shim: Switch from `ukplat` to `ukconsole` for printing
This commit makes the syscall shim call into `ukconsole`
to print some message. Direct calls to `ukconsole` like
this one should normally be avoided in favor of calling
into `ukdebug`. But in this case, we don't want to print
the extra information that `ukdebug` always includes.
When there is a kernel print system in the future, the
new print calls in this commit will be updated.
This commit avoids creating a direct dependency between
the syscall shim and `ukconsole` because the call into
`ukconsole` is a workaround anyway and will be removed
in the future.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1464
lib/ukconsole: Add abstraction layer for console drivers
`ukconsole` is a new library that implements a generic
interface for console devices. It will be used to replace
the current kernel/debug print system that's based on the
`ukplat_c[out|in][k|d]` functions. `ukconsole` is
groundwork for properly integrating the gdb stub with
Unikraft and for adding a proper kernel print system
later on.
Signed-off-by: Thassilo Schulze <thassilo@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1464
Samuel Hym [Mon, 24 Jun 2024 13:04:15 +0000 (15:04 +0200)]
build: Log calls to the `multiboot` and `mkefi` scripts
Use `build_cmd` to log calls to `multiboot.py` as `MULTIBT` and to
`mkefi.py` as `MKEFI` instead of completely hiding them
This uses fake `.multiboot` and `.efi` extensions to avoid clashing with
the first rule generating the target (ie overwriting its `.cmd` file)
Note this is already done with the `.bin` extension when generating the
binary image
Signed-off-by: Samuel Hym <samuel@tarides.com> Approved-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1469
Andrei Stan [Fri, 6 Sep 2024 19:07:41 +0000 (22:07 +0300)]
plat/xen: Fix implicit conversion on return type
Clang throws an error when trying to implicitly convert
from `const void*` to `const char *`.
Signed-off-by: Andrei Stan <andreistan2003@gmail.com> Approved-by: Simon Kuenzer <simon@unikraft.io> Reviewed-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1482
When PL011_EARLY_CONSOLE is set, the base address of the MMIO
region is provided by the node pointed by the device'tree's
`/chosen/stdout-path`, or by the pl011.base cmdline parameter.
When NS16550_EARLY_CONSOLE is set, the base address of the MMIO
region is provided by the node pointed by the device'tree's
`/chosen/stdout-path`, or by the ns16550.base cmdline parameter.
The register-shift and register-width parameters are provided by
the device-tree via the `reg-shift` and `reg-io-width` properties.
Add fdt_chosen_stdout_path() helper to derive the boot console.
This returns the node pointed by `/chosen/stdout-path` as well
as any console options set.
Update plat/kvm for newly introduced libukboot early init.
arm64:
- Deprecate kvm/arm64/early_init.c and calls.
arm64 & x86_64:
- Remove ukplat_memregion_list_coalesce() from boot protocols.
Coalescing is now part of libukboot early init.
- Remove cmdline_init() from kvm/arm64 and kvm/x86_64. Command line
initialization is now performed of libukboot early init.
- Call uk_boot_early_init() from _ukplat_entry()
- Remove call to ukplat_entry_argp() and jump directly to
uk_boot_entry()
Signed-off-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Oleksii Moisieiev <oleksii_moisieiev@epam.com> Reviewed-by: Sergiu Moga <sergiu@unikraft.io> Reviewed-by: Andrei Stan <andreistan2003@gmail.com> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1472
plat: Move SIPI vector mrd allocation to lcpu_mp_init
Move the SIPI vector mdr allocation from the boot protocol
to lcpu_arch_mp_init(). Notice that lcpu_arch_mp_init() must
be called after mrd coalescing.
Signed-off-by: Michalis Pappas <michalis@unikraft.io> Reviewed-by: Oleksii Moisieiev <oleksii_moisieiev@epam.com> Reviewed-by: Sergiu Moga <sergiu@unikraft.io> Reviewed-by: Andrei Stan <andreistan2003@gmail.com> Reviewed-by: Simon Kuenzer <simon@unikraft.io> Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1472