Juergen Gross [Wed, 9 Oct 2024 14:05:54 +0000 (16:05 +0200)]
add config support for each Xen library
Instead of Xen libraries being all or nothing (controlled by
CONFIG_XC), support a dedicated config option for each library
instead, defaulting to disabled.
As it is no longer needed now, drop the CONFIG_XC support.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Hide the sanity_check() function, as it is used nowhere. By putting it
under #ifdef CONFIG_TEST it will stay around, but it won't be
included in normal production builds.
Call sanity_check() from the periodic thread of the test app, causing
a sanity check every second.
Since any application linked with Mini-OS can't call sanity_check()
(there is no EXPORT_SYMBOL for it), there is zero chance of breaking
any use case.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
mini-os: mm: don't have two large arrays of the same kind
In the CONFIG_PARAVIRT case there are two identical static arrays of
more than 8kB size with function scope. As the two functions never
nest, a single array of file scope can replace the two existing
instances.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
mini-os: mm: reduce buddy allocator list administration data
Today the administration data for the buddy allocator's lists consists
of 2 arrays: one pointer array and one list element array for easier
handling of the lists' tails.
Those arrays can be combined into one by dropping the pointer array and
using a different list end indicator.
Add enqueue and dequeue helpers for better readability.
Change the level member type to unsigned int.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
monotonic_clock() in arch/x86/time.c is more complex than needed: it
has basically two nested loops making sure the time data obtained from
Xen are valid.
Simplify that by merging some of the used sub-functions into the main
function and using only a single loop. Further simplify the code by
using struct vcpu_time_info for the local instance instead of defining
a similar structure in the code.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Instead of having #ifdefs sprinkled around in x86 code, add some
macros defining constants for asm statements to address differences
between 32- and 64-bit mode.
Modify existing code to use those macros.
While at it convert the assembler parts of run_idle_thread() to a more
sane variant.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Jan Beulich <jbeulich@suse.com>
Charles Arnold [Tue, 25 Jun 2024 07:50:11 +0000 (09:50 +0200)]
mman: correct m{,un}lock() definitions
gcc14 no longer (silently) accepts functions with no return type
specified.
Signed-off-by: Charles Arnold <carnold@suse.com> Signed-off-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Thu, 29 Feb 2024 07:01:03 +0000 (08:01 +0100)]
Mini-OS: add symbol exports for xenstore stubdom
Xenstore stubdom needs some more symbols exported.
Reported-by: Andrew Cooper <andrew.cooper3@citrix.com> Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Anthony PERARD [Fri, 19 Jan 2024 08:42:09 +0000 (09:42 +0100)]
x86/mm: add EXPORT_SYMBOL() for `pt_base`
Without this, building "ioemu-stubdom" fails on Debian Buster or
Bookworm, with:
/home/osstest/build.184372.build-amd64/xen/stubdom/mini-os-x86_64-ioemu/mini-os.o: in function `xenfb_pv_display_init':
ungetc.c:(.text+0x43533): undefined reference to `pt_base'
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Wed, 13 Dec 2023 09:50:17 +0000 (10:50 +0100)]
Mini-OS: cleanup hypervisor.c
Do the following cleanups in hypervisor.c:
- Let hypervisor.c conform to the coding style.
- Drop the bogus "inline" attributes of exported functions.
- Replace a always zero cpu variable with smp_processor_id() as
elsewhere in the code.
- Replace "if () BUG()" with BUG_ON() in case the condition has no
side effects.
- Drop the unused cpu parameter from the active_evtchns() macro.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Wed, 13 Dec 2023 09:49:54 +0000 (10:49 +0100)]
Mini-OS: drop in_callback variable
Now that do_hypervisor_callback() is always called with interrupts off
the in_callback variable meant to handle recursive calls of
do_hypervisor_callback() can be dropped.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Wed, 13 Dec 2023 09:49:40 +0000 (10:49 +0100)]
Mini-OS: call event handlers always with interrupts off
When unmasking an event channel the associated event handler can be
called with interrupts enabled when not running as a PV guest.
This can result in hard to debug races in case e.g. a handler is
registered for multiple events or when the handler is not using a lock
as it assumes to have interrupts disabled.
Instead of using the PV interrupt disabling points just before calling
the handler, do the disabling once at the very start of
force_evtchn_callback().
Replace the evtchn_upcall_mask test in unmask_evtchn() with the more
appropriate irqs_disabled() test.
As a precaution add a test to do_hypervisor_callback() that interrupts
are really disabled and crash in case this is not true.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Wed, 6 Dec 2023 16:17:44 +0000 (17:17 +0100)]
Mini-OS: don't use objcopy --dump-section
The objcopy option "--dump-section" isn't supported in binutils before
version 2.25, which are still supported by the Xen build system.
Avoid that by using the "-O binary" format together with
"--only-section". This requires to set the "alloc" section flag.
Fixes: 33411a11f848 ("Mini-OS: hide all symbols not exported via EXPORT_SYMBOLS()") Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Juergen Gross [Mon, 27 Nov 2023 10:24:53 +0000 (11:24 +0100)]
Mini-OS: explicitly mark symbols to be visible for apps
Add an EXPORT_SYMBOL() macro to explicitly mark a symbol to be visible
for an app or library linked with Mini-OS. This prepares hiding all
other symbols from external components, avoiding any problems with
duplicate symbol names.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Tue, 21 Nov 2023 09:49:53 +0000 (10:49 +0100)]
Mini-OS: fix 9pfs response receiving
When copying a 9pfs response chunk from the ring buffer across the
ring end, the local ring pointer and length field are not updated
correctly. Fix that.
Fixes: 0924fec1de58 ("Mini-OS: add 9pfs transport layer") Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Tue, 21 Nov 2023 09:49:52 +0000 (10:49 +0100)]
Mini-OS: fix 9pfs stat receive format
The format string of the received data for the 9pfs stat command is
missing the initial 2 byte total length specifier. Add it.
Fixes: 2d1dfccd3aa3 ("Mini-OS: add read and write support to 9pfsfront") Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Jason Andryuk <jandryuk@gmail.com>
Juergen Gross [Tue, 21 Nov 2023 09:49:51 +0000 (10:49 +0100)]
Mini-OS: don't crash if no shutdown node is available
It might be perfectly fine not to have a control/shutdown Xenstore
node. If this is the case, don't crash, but just terminate the
shutdown thread after issuing a message that shutdown isn't available.
In fini_shutdown() clearing the watch can result in an error now, in
case the early exit above was taken. Just ignore this error now.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Jason Andryuk <jandryuk@gmail.com>
Juergen Gross [Tue, 21 Nov 2023 09:49:50 +0000 (10:49 +0100)]
Mini-OS: get own domid
Get the own domid via creation of a temporary event channel. There is
no "official" way to read the own domid in PV guests, so use the event
channel interface to get it:
- allocate an unbound event channel specifying DOMID_SELF for the
other end
- read the event channel status which will contain the own domid in
unbound.dom
- close the event channel
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Jan Beulich [Thu, 2 Nov 2023 07:25:59 +0000 (08:25 +0100)]
build: silence GNU ld 2.39 warning about executable stacks
While for C files the compiler is supposed to arrange for emitting
respective information, for assembly sources we're responsible ourselves.
For the new use of cc-option to work we cannot pass -S to the compiler
anymore. We need the compiler to actually invoke the assembler, so switch
to using -c.
Signed-off-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Mon, 13 Feb 2023 08:44:10 +0000 (09:44 +0100)]
Mini-OS: add 9pfs transport layer
Add the transport layer of 9pfs. This is basically the infrastructure
to send requests to the backend and to receive the related answers via
the rings.
As a first example add the version and attach requests of the 9pfs
protocol when mounting a new 9pfs device. For the version use the
"9P2000.u" variant, as it is the smallest subset supported by the qemu
based backend.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Mon, 13 Feb 2023 08:44:09 +0000 (09:44 +0100)]
Mini-OS: add 9pfs frontend
Add a frontend for the 9pfs PV device. For now add only the code needed
to connect to the backend and the related disconnect functionality. The
9pfs protocol support will be added later.
Due to its nature (ability to access files) the whole code is guarded
by "#ifdef HAVE_LIBC".
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Mon, 13 Feb 2023 08:44:07 +0000 (09:44 +0100)]
Mini-OS: add concept of mount points
Add the concept of mount points to Mini-OS. A mount point is a path
associated with a device pointer and an open() callback. A mount point
can be either a file (e.g. "/dev/mem") or a directory ("/var/log").
This allows to replace the special casing in the generic open()
handling with a generic mount point handling.
Prepare the open() callbacks to support creating new files by adding a
mode parameter.
Additionally add a close() prototype to include/lib.h, as it is missing
today.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Mon, 13 Feb 2023 08:44:06 +0000 (09:44 +0100)]
Mini-OS: xenbus: add support for reading node from directory
Especially PV device drivers often need to read multiple Xenstore
nodes from a common directory. Add support for reading a string or an
unsigned value by specifying the directory and the node.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Tue, 21 Jun 2022 07:23:13 +0000 (09:23 +0200)]
mini-os: fix number of pages for PVH
When getting the current allocation from Xen, this value includes the
pages allocated in the MMIO area. Fix the highest available RAM page
by subtracting the size of that area.
This requires to read the E820 map before needing this value. Add two
functions returning the current and the maximum number of RAM pages
taking this correction into account.
At the same time add the LAPIC page to the memory map in order to
avoid reusing that PFN for internal purposes.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Tue, 21 Jun 2022 07:23:12 +0000 (09:23 +0200)]
mini-os: prefer memory map via start_info for PVH
Since some time now a guest started in PVH mode will get the memory
map from Xen via the start_info structure.
Modify the PVH initialization to prefer this memory map over the one
obtained via hypercall, as this will allow to add information to the
memory map for a new kernel when supporting kexec.
In case the start_info structure doesn't contain memory map information
fall back to the hypercall.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Sun, 16 Jan 2022 08:33:26 +0000 (09:33 +0100)]
add struct file_ops for file type socket
Even with some special handling needed in select_poll(), add a struct
file_ops for FTYPE_SOCKET. Due to the need of the special handling it
isn't possible to use a dynamically allocated file type.
Most functions calling the file_ops methods can be simplified a lot now
that no file type specific handling is left. Same applies to the file
type name printing in debug/verbose mode.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Sun, 16 Jan 2022 08:33:25 +0000 (09:33 +0100)]
use file_ops and get_file_from_fd() for console
Add struct file_ops for the console related file types (FTYPE_CONSOLE
and savefile). FTYPE_CONSOLE remains statically defined, as it is used
to statically init stdin, stdout and stderr.
Instead of directly accessing the files[] array use get_file_from_fd().
With CONSOLE now handled via file_ops the bogus file descriptor case in
select_poll() now needs to be handled more explicit instead of dropping
into console handling, assuming that this case was basically meant to
cover SAVEFILE.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Sun, 16 Jan 2022 08:33:18 +0000 (09:33 +0100)]
remove gnttab specific member from struct file
The gnttab specific union member in struct file is no longer
needed, so remove it.
The gnttab file type and its associated handling can be removed, too,
as libxengnttab is now supplying a struct file_ops via a call of
alloc_file_type().
This removes all contents of CONFIG_LIBXENGNTTAB guarded sections, so
this config option can be removed.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Sun, 16 Jan 2022 08:33:17 +0000 (09:33 +0100)]
remove event channel specific struct file definitions
The event channel specific union member in struct file is no longer
needed, so remove it together with the associated structure
definitions.
The event channel file type and its associated handling can be removed,
too, as libxenevtchn is now supplying a struct file_ops via a call of
alloc_file_type().
This removes all contents of CONFIG_LIBXENEVTCHN guarded sections, so
this config option can be removed.
Add an extern declaration for event_queue as it is used by
libxenevtchn.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Sun, 16 Jan 2022 06:45:27 +0000 (07:45 +0100)]
add CONFIG_LIBXS item
Mini-OS contains a stripped down version of libxenstore in lib/xs.c.
Today it is being built always if CONFIG_XENBUS is set and libc
support is enabled.
In order to allow a Mini-OS specific build of libxenstore to be used
instead add a new CONFIG_LIBXS item which per default will have the
same setting as CONFIG_XENBUS. A user wanting to replace lib/xs.c
with libxenstore would just need to set CONFIG_XENBUS=y and
CONFIG_LIBXS=n.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Sun, 16 Jan 2022 06:45:26 +0000 (07:45 +0100)]
use function vectors instead of switch for file operations
Introduce file type specific function vectors for all the needed file
operations which are file type specific in order to prepare replacing
the large switch statements in each generic file function.
Add a function to allocate a new file type dynamically in order to
prepare removing direct dependencies to external components in the
future. For this reason switch the file type from an enum to an
unsigned int. Prepare removal of some statically defines file types
by putting them at the end of the defined list.
Change the debug output for the file type from a single character to
a string in order to support a future removal of the file_types[]
array.
Provide some functions useful for file_ops in future patches.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Juergen Gross [Sun, 16 Jan 2022 06:45:25 +0000 (07:45 +0100)]
remove file type FTYPE_XC
The only reason for the file type FTYPE_XC has been gone long time
ago: it was needed for xc_map_foreign_bulk(), which has been switched
to use libxenforeignmemory and doesn't need this special file any
more.
So remove everything related to FTYPE_XC.
Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>