Yuri Volchkov [Mon, 18 Feb 2019 14:54:31 +0000 (15:54 +0100)]
lib/vfscore: introduce fget, fdrop, fdalloc
These functions are used in the imported code, which is not enabled
yet. This required to expand functionality of vfscore_install_fd and
friends with locking and reference counting.
Simon Kuenzer [Sun, 17 Feb 2019 18:46:46 +0000 (19:46 +0100)]
plat/kvm: Acknowledge all interrupts
Acknowledge interrupts even in the case when there was no
handler for it. We do this to (1) compensate potential
spurious interrupts like currently happening on virtio,
and (2) to minimize impact on device drivers that share
one interrupt line that got previously disabled. Whenever
an interrupt was unhandled a critical warning is still
printed to the kernel console.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Tue, 12 Feb 2019 17:07:49 +0000 (18:07 +0100)]
lib/ukdebug: Align hexdump with print system
With the recent update of the print system, the hexdump functionality
was not adopted. This made this functionality useless. With this
commit hexdump is align with the printing again system. For instance,
uk_hexdumpd() is only enabled in the code when either UK_DEBUG is
defined for the compilation unit or debug messages are enabled
globally. uk_hexdumpk() depends on having kernel console enabled and
on the configured maximum message level.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Dafna Hirschfeld [Tue, 12 Feb 2019 13:03:11 +0000 (14:03 +0100)]
plat/xen: arm: Initialize the bss section to 0
Clear the bss section during boot so that it is initialized with 0.
Additonally, we make sure with the linker script that all
bss-related symbols are placed within the bss area marked with
_end and __bss_start when the compile option "dropping of unused
symbols" is enabled.
Simon Kuenzer [Wed, 13 Feb 2019 13:07:37 +0000 (14:07 +0100)]
plat/xen: CPU definition for Arm32
Introduce minimal CPU definitons to enable compiling for Arm32.
This commits also removes x86 specific CPU functions from the
Arm32 build unit and introduces CONFIG_XN_HVMLITE as invisible
menu configuraiton. Its intention is to support switching
between PV and PVH mode later. For now, we set PV mode for x86
and PVH mode for Arm.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Wed, 13 Feb 2019 12:26:26 +0000 (13:26 +0100)]
plat/xen: Split emergency and hypervisor console
Splits the two console implemetations (hvc, emergency) from each other.
Similar to plat/kvm, a console option menu is populated in the platform
configuration where each console can be individually selected as output
for kernel or debug messages. Because hvc is currently not yet supported
on Arm32, we set the debug console as default output on Arm32.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Tue, 12 Feb 2019 16:09:49 +0000 (17:09 +0100)]
plat/xen: Grant table support as menu option
Introduces a menu option to enable or disable grant table support.
The reason is that our grant table implementation depends on
libuklock, libuksched, and libukalloc. A minimal configuration
requires these libraries selected, too. This may be an obstacle
when running implementation written in higher-level languages.
Additionally, some of these libraries are currenlty not supported
on Arm32. It is wiser to give an option for disabling grant table
support.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Mon, 11 Feb 2019 17:01:10 +0000 (18:01 +0100)]
build: Notice user when to do `make clean`
The little helper script `configupdate` did not detect any config changes
with `.config` anymore because it did prefix `CONFIG_` prefix for the
configuration symbols.
This commit makes sure that `configupdate` can detect changes
(e.g., CPU architecture, code optimizations) that requires `make clean`
before continuing. It is still called automatically by the build system.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Yuri Volchkov [Tue, 12 Feb 2019 22:26:54 +0000 (23:26 +0100)]
lib/ukboot: include uk/essentials.h in weak_main
In case of compiling with newlib enabled, essentials.h is not getting
included. Because of that, compiler does not know what '__weak' means,
and the compilation fails. Let's include essentials.h explicitly.
Signed-off-by: Yuri Volchkov <yuri.volchkov@neclab.eu> Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Simon Kuenzer [Fri, 8 Feb 2019 10:38:08 +0000 (11:38 +0100)]
plat/kvm: Disconnect console options from ukdebug
Like on the other platforms, the console options for debugging
messages should not be hidden when global debug output is not
enabled. One may still want to enable individual debugging for a
particular library or file. This commit makes this configuration
option independent in the menu.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Yuri Volchkov [Fri, 4 Jan 2019 16:18:00 +0000 (17:18 +0100)]
lib/ukboot: move weak main in separate sub-lib
Link Time Optimization does not work well with incremental linking (ld
-r), which is heavily used by Unikraft.
The ukboot has a weak main() function, which is supposed to be called
if no other library/application provided a proper main. However gcc
resolves main() to whatever is available while linking the
libukboot.ld.o. Which is the weak one.
In the upcoming gcc v9 release a better support of incremental link
optimization is announced. Which hopefully will fix this issue. But
for now, let's fix it with a workaround.
Let's create a sublib under the ukboot, containing only the weak
main. This way we will leave no chance for the first "ld -r" to link
with the wrong main. The next "ld -r" will have all the objects, so it
will be able to make correct decision.
Florian Schmidt [Thu, 17 Jan 2019 12:39:29 +0000 (13:39 +0100)]
support: don't throw error message when not in a git repo
The gitsha1 script is used to create a version string for unikraft that
includes the git hash. However, if we are not building from a git repo
checkout, it will throw error messages on the command line. Suppress
these because there's little gain in them.
Signed-off-by: Florian Schmidt <florian.schmidt@neclab.eu> Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Simon Kuenzer [Thu, 31 Jan 2019 11:12:52 +0000 (11:12 +0000)]
build: `print-libs`, `print-objs`, `print-srcs` depend on `.config`
As soon as no configuration `.config` is available, the Make targets
`print-libs`, `print-objs`, and `print-srcs` will return an error
message. Without a configuration file these targets are not able
to do any listing of which units are used or created by a build.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Thu, 31 Jan 2019 11:12:50 +0000 (11:12 +0000)]
build: `distclean`, `properclean` independent of `.config`
Until now, the targets `distclean` and `properclean` were not
available if `.config` file is not present. This does not make sense,
because these targets have nothing to do with the configuration. They
just clean everything (except .config in case of properclean).
Since these targets use some functions declared in
`support/build/Makefile.rules`, we include this file at an earlier
point.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Yuri Volchkov [Tue, 4 Dec 2018 17:16:26 +0000 (18:16 +0100)]
lib/nolibc/string: fix underflow in strnlen
The memchr return NULL if it did not find '\0' character. The strnlen
did not take this into account and always did subtraction to count the
string length.
Return the provided length limit if the line ending is not found
within this limit.
Simon Kuenzer [Wed, 30 Jan 2019 23:44:58 +0000 (23:44 +0000)]
lib/ukdebug: Fix spelling in configuration menu
The help text of LIBUKDEBUG_PRINTK was speaking about debug messages
although the option configures kernel messages.
The option LIBUKDEBUG_PRINTK_INFO enables all types of kernel messages
instead of debug messages.
The message redirection option does not have a dependency on
LIBUKDEBUG_PRINTD neither on LIBUKDEBUG_PRINTK.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Disabling interrupts by virtio_netdev_recv() is not needed because in
normal cases they are already disabled by the internal receive
interrupt handler, right before a uknetdev API program can call the
receive function. When the device is used in pure polling mode, queue
interrutps are never enabled.
We remove this step because of performance reasons. An assertion is
making sure that the API is used as intended.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Simon Kuenzer [Thu, 31 Jan 2019 15:48:42 +0000 (15:48 +0000)]
lib/uknetdev: Flag-based status report on rx and tx functions
Introduce flag based status return codes on receive and transmit
functions. They are replacing the current enum-like return codes. The
flags are able to inform the API user about additional driver
states (e.g., queue underruns).
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
The idea of having a fill-up parameter on the receive function is
inconvenient because a user never knows how many receive buffers have
to be programmed before calling the receive function.
This commit introduces registering a callback when configuring a
receive queue. This callback has to be provided by the NETDEV API user
and is called by the driver whenever it programs new receive buffers to
the receive queue. In order to still provide performance, this
allocation callback function is called for a batch of receive buffers.
This new mechanism replaces the fill-up parameter on the receive function.
This commit also adopts virtio-net in order to comply with the API change.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Yuri Volchkov [Wed, 30 Jan 2019 16:38:54 +0000 (17:38 +0100)]
lib/nolibc/include: import statfs.h from musl
This is a combination of include/sys/statfs.h and
arch/generic/bits/statfs.h. We do not need to provide different
statfs.h for different architectures, because this files differs only
for mips*, s390x, x32, which we do not have plans to support.
Yuri Volchkov [Fri, 25 Jan 2019 14:09:59 +0000 (15:09 +0100)]
include/uk/list: remove unneeded workarounds from imported code
This implementation of lists intended to be the only one and going to
replace the existing one completely. There is no need of LIST_HEAD
conflict avoidance. The prefetch is not belong here either.
Yuri Volchkov [Fri, 25 Jan 2019 14:09:57 +0000 (15:09 +0100)]
include/uk/list: rename UK_LIST_HEAD in the old implementation
UK_LIST_HEAD from the new list implementation conflicts with the old
one. Since the current UK_LIST_HEAD is never used, and the current
implementation will be a subject for removal, rename it to
UK_COMPAT_LIST_HEAD
The new linked list will replace the existing one. The old
implementation is moved to compat_list.h.
The only difference in the imported code from the original one is a
"#if 0/endif" pair, to keep it from compilation, since some
modifications are needed before. And, at the end of that block the
old (compat_list.h) implementation is included. So by including
<uk/list.h> user will get both implementations.
Yuri Volchkov [Fri, 25 Jan 2019 14:09:54 +0000 (15:09 +0100)]
build: resolve common symbols in each lib individually
If a symbol is not initialized, gcc declares it as a weak. It will be
resolved during the linking time.
Common symbols inside a library are fine, but we don't want them to be
resolved together with common symbols from another library.
For example:
lib/foo/main.c:
int some_variable;
int main(void) {
printf("libfoo: %p\n", some_variable);
}
lib/bar/main.c:
char some_variable;
int main(void) {
printf("libbar: %p\n", some_variable);
}
After linking the final Unikraft image, both libfoo and libbar will
get one address for their some_variable. Even if neither of them was
never declared "extern". Even if they have different types. Even if
some_variable is not listed in exportsyms.uk
The solution is to link library object files (libname.ld.o) with
'-d'. This will force linker to do allocation for common symbols.
Florian Schmidt [Wed, 16 Jan 2019 09:35:15 +0000 (10:35 +0100)]
plat/common: Add a notice regarding trap handling
While traps.c itself is compiled with NO_X86_EXTREGS_FLAGS, it still
doesn't hurt to remind potential editors of the file that calling any
other function from your trap handler is potentially dangerous.
Florian Schmidt [Wed, 16 Jan 2019 09:35:14 +0000 (10:35 +0100)]
arch/x86: Introduce NO_X86_EXTREGS_FLAGS
This set of flags disables the use of extended registers: FP, MMX/XMM,
YMM, and hence should be used on files that implement
trap/exception/interrupt handler functions, because we do not save the
extended x86 register state when those events happen.
Florian Schmidt [Wed, 16 Jan 2019 09:35:13 +0000 (10:35 +0100)]
plat/common: Support to save and restore extended (x86) registers
On creation of a sw_ctx struct, allocate an area sufficiently large to
save all extended registers. On context switch, use the appropriate CPU
instruction to save and restore those registers to/from that area.
Florian Schmidt [Wed, 16 Jan 2019 09:35:08 +0000 (10:35 +0100)]
plat/{kvm, xen}: Clean up Makefile.uk conditional build rules
1) Those ifeqs aren't needed because the $(CONFIG_ARCH...) part already
deals with the conditions under which to build those files.
2) Add $(LIBKVMPLAT_BASE)/include as include directory for libkvmpci.
Florian Schmidt [Wed, 2 Jan 2019 15:46:24 +0000 (16:46 +0100)]
plat/*: Make timer interrupt frequency selectable
Add new configuration options for choosing a timer interrupt frequency.
The configured frequency is converted to the timer tick length which can
be of use for other modules (e.g., preemptive schedulers).
Previously, the tick was 100 Hz on KVM and 1000 Hz on Xen. The default
value is now 100 Hz across both platforms.
Simon Kuenzer [Thu, 27 Sep 2018 12:41:13 +0000 (14:41 +0200)]
lib/ukdebug: uk_printd() and uk_printk() use same format engine
The same output engine is used for uk_printd() and
uk_printk(). Whenever uk_printd() is directed to a different output as
uk_printk(), individual states are kept.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
Simon Kuenzer [Thu, 27 Sep 2018 12:41:12 +0000 (14:41 +0200)]
lib/ukdebug: Swap uk_printk() and uk_printd()
Exchanges uk_printk() with uk_printd(). uk_printk gets a lvl parameter:
uk_printk(lvl, fmt, ...)
with having KLVL_INFO (former DLVL_INFO), KLVL_WARN (former
DLVL_WARN), KLVL_ERR (KLVL_ERR), DLVL_CRIT (former KLVL_CRIT) as
value for parameter `lvl`.
uk_printd() implements former uk_printk(). Its purpose is to replace
the previous DLVL_EXTRA level. Whenever `UK_DEBUG` is defined as macro
while compiling a source file, uk_printd() statements are
effective. libukdebug additionally provides a global flag to enable
debug messages in all source files.
uk_printd(fmt, ...)
It seems to be more meaningful to redirect all messages to
ukplat_coutk() as default configuration. The uk_pr_*() shortcut
macros are updated to reflect this new scheme.
This patch adds the stdin operation inside lib/vfscore/stdio.c.
The stdio is mapped by default to fd 0. This implementation mimics
the normal read behaviour.(read until count bytes or read until VEOF or
\n is met). The '\r' is replaced with '\n' because ukplat_cink returns
'\r' on KVM and Xen.
For every successful call of ukplat_cink the input is printed
to the stdout.
This patch combines include/termios.h with generic/bits/termios.h
from musl. It provides all the defines found in generic/bits/termios.h
but not the function declarations from include/termios.h.
The following changes are made to the original files:
*) add missing declarations from include/termios.h for cc_t, speed_t
and tcflag_t
*) add compile-time check of the architecture
*) add compile guards
We introduce buffer padding while transmitting and receiving data. We
explicitly introduce padding to make sure that each network packet
needs two descriptors (one for virtio header and another for
network packet).
According the specification 5.1.6.6, we need to explicitly use 2
descriptor for each transmit and receive network packet since we do not
negotiate for VIRTIO_F_ANY_LAYOUT.
In the previous implementation the sg list merged the two descriptor
into one as the memory region were contiguous.
Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu> Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
As a part of this patch, we configure the max queue size as the
configuration for the number descriptor if the user set the number
of descriptors to zero.
Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu> Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Simon Kuenzer [Mon, 3 Dec 2018 10:23:18 +0000 (11:23 +0100)]
lib/uknetdev: Zero-initialize netdev data
Whenever a network device is registered by a driver to the uknetdev
API, libuknetdev allocates an API-internal data structure that is used
to track the state of the device state. Subsequent API calls are
assuming that this allocation was zero-initialized. Otherwise,
assertions fail unexpectedly.
Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu> Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Florian Schmidt [Mon, 17 Dec 2018 09:46:16 +0000 (10:46 +0100)]
plat/kvm: Make mxcsr_ptr in entry64.S a 32-bit value
LDMXCSR reads 32 bits into the register. If mxcsr_ptr is only a .word
(and thus 16 bits), the instruction reads adjacent bytes into the MXCSR
register, which can to produce #GP faults on LDMXCSR when those adjacent
bytes contain 1's in bit locations that are reserved in MXCSR.
Cristian Banu [Fri, 7 Dec 2018 05:19:00 +0000 (07:19 +0200)]
plat/virtio: Update off-by-one device id
Extract the virtio_device_id for legacy devices from the PCI Subsystem
Device ID. The previous behaviour resulted in some devices having the
wrong ID attributed to them. For example, a virtio-9p device has a PCI
Device ID of 0x1009 (which would have resulted in virtio_device_id of
10), but a PCI Subsystem Device ID of 9 (which is the correct constant
under virtio_ids.h).
Removes now unused function virtio_device_id_add and misleading macro
VIRTIO_PCI_LEGACY_DEVICEID_START.
Cristian Banu [Wed, 5 Dec 2018 14:27:55 +0000 (16:27 +0200)]
plat/virtio: Fix virtio-bus init getting hanged
This patch fixes getting hanged in virtio-bus initialization. The inner
while loop does not iterate through all the dev_ids, and failing to find
a match against the first dev_id results in an infinite loop.
Bogdan Lascu [Sat, 24 Nov 2018 13:05:18 +0000 (15:05 +0200)]
plat/xen/xenbus: Add _GNU_SOURCE define when using asprintf
Compiling xenbus.c and xs.c gives the warning "implicit definition
of asprintf". Asprintf is not C nor POSIX, so its declaration is
conditioned by a header define that is activated by defining _GNU_SOURCE
before including stdio.h.
This is the setup to reproduce the bug:
Library Configuration -> enable uknetdev
Platform Configuration -> enable KVM guest:
-> disable Virtio bus driver
-> Virtio -> enable Virtio Net device
With this setup, the following error occurs on build:
"undefined reference to ` _virtio_bus_register_driver'"
This fix solves the issue by enabling Virtio bus driver every time
Virtio Net device is enabled.
Radu Nicolau [Sat, 24 Nov 2018 11:23:21 +0000 (13:23 +0200)]
plat/xen/common: Move event channel functions in events.h
Move mask_evtchn, unmask_evtchn and clear_evtchn function
prototypes from hypervisor.h to events.h. Change parameter
type to evtchn_port_t. Remove hypervisor.h inclusion from
arm/arch_events.c and arm/arch_time.c
Signed-off-by: Radu Nicolau <radunicolau102@gmail.com> Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
Radu Nicolau [Sat, 24 Nov 2018 11:23:20 +0000 (13:23 +0200)]
include/xen-x86: Remove os.h on x86
Remove os.h from the project as it was unused.
mm_pv.h included os.h but did not use anything from
it. The rest of the changes have been made in sources
which need the extern definition for the shared info
page.
Signed-off-by: Radu Nicolau <radunicolau102@gmail.com> Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>