]> xenbits.xensource.com Git - people/royger/xen.git/log
people/royger/xen.git
16 months agoautomation: add x86-64 livepatching test test-livepatch gitlab/test-livepatch
Roger Pau Monne [Wed, 5 Apr 2023 11:47:28 +0000 (13:47 +0200)]
automation: add x86-64 livepatching test

Introduce a new gitlab tests for livepatching, using livepatch-build-tools,
which better reflects how downstreams build live patches rather than the
in-tree tests.

The tests applies the dummy in-tree patch example, checks that the patch is
applied correctly and then reverts and unloads it.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
Changes since v2:
 - Split livepatch build into a separate script.

16 months agox86/livepatch: introduce a basic live patch test to gitlab CI
Roger Pau Monne [Fri, 24 Nov 2023 08:45:04 +0000 (09:45 +0100)]
x86/livepatch: introduce a basic live patch test to gitlab CI

Introduce a basic livepatch test using the interface to run self modifying
tests.  The introduced test relies on changing a function from returning false
to returning true.

To simplify the burden of keeping a patch that can be provided to
livepatch-build-tools, introduce two new files: one containing the unpatched
test functions, and another one that contains the patched forms of such
functions.  Note that only the former is linked into the Xen image, the latter
is built but the object file is not consumed afterwards.  Do this to assert
that the file containing the patched functions continues to build.

Since livepatch testing will ensure that the functions are not patched previous
the applying the livepatch, allow the livepatch related tests to fail without
tainting the hypervisor.

Note the livepatch tests are not run as part of the self modifying checks
executed during boot, as they would obviously fail.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
---
Changes since v3:
 - Rebase over previous changes.

Changes since v2:
 - Clarify comment about xor vs mov instructions for return false/true
   encodings.

Changes since v1:
 - New interface & test.

16 months agoxen/x86: introduce self modifying code test
Roger Pau Monne [Thu, 23 Nov 2023 17:34:55 +0000 (18:34 +0100)]
xen/x86: introduce self modifying code test

Introduce a helper to perform checks related to self modifying code, and start
by creating a simple test to check that alternatives have been applied.

Such test is hooked into the boot process and called just after alternatives
have been applied.  In case of failure a message is printed, and the hypervisor
is tainted as not having passed the tests, this does require introducing a new
taint bit (printed as 'T').

A new sysctl is also introduced to run the tests on demand.  While there are no
current users introduced here, further changes will introduce those, and it's
helpful to have the interface defined in the sysctl header from the start.

Note the sysctl visibility is not limited to x86, albeit the only
implementation is for x86.  It's expected that other architectures can reuse
the same sysctl and structure, with possibly different tests.  Leave adjusting
those to when support for a different architecture is introduced, as the
sysctl interface is not stable anyway.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v3:
 - Rename taint variable.
 - Introduce a wrapper to run all selftests.
 - Only print messages and taint the hypervisor when tests are executed on
   boot.

Changes since v2:
 - Rename to smoc and place in test/smoc*
 - fix inline assembly.

Changes since v1:
 - Rework test and interface.

16 months agox86/livepatch: align functions to ensure minimal distance between entry points
Roger Pau Monne [Tue, 12 Dec 2023 15:28:36 +0000 (16:28 +0100)]
x86/livepatch: align functions to ensure minimal distance between entry points

The minimal function size requirements for livepatch are either 5 bytes (for
jmp) or 9 bytes (for endbr + jmp) on x86, and always 4 bytes on Arm.  Ensure
that distance between functions entry points is always at least of the minimal
required size for livepatch instruction replacement to be successful.

Add an additional align directive to the linker script, in order to ensure that
the next section placed after the .text.* (per-function sections) is also
aligned to the required boundary, so that the distance of the last function
entry point with the next symbol is also of minimal size.

Note that it's possible for the compiler to end up using a higher function
alignment regardless of the passed value, so this change just make sure that
the minimum required for livepatch to work is present.  Different compilers
handle the option differently, as clang will ignore -falign-functions value
if it's smaller than the one that would be set by the optimization level, while
gcc seems to always honor the function alignment passed in -falign-functions.
In order to cope with this behavior and avoid that setting -falign-functions
results in an alignment inferior to what the optimization level would have
selected force x86 release builds to use a function alignment of 16 bytes.

The compiler option -falign-functions is not available on at least clang 3.8,
so introduce a Kconfig check for it and make the livepatch option depend on the
compiler supporting the option.

The naming of the option(s) CONFIG_FUNCTION_ALIGNMENT is explicitly not
mentioning CC in preparation for the option also being used by assembly code.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v3:
 - Test for compiler option with -falign-functions.
 - Make FUNCTION_ALIGNMENT depend on CC_HAS_FUNCTION_ALIGNMENT.
 - Set 16byte function alignment for x86 release builds.

Changes since v2:
 - Add Arm side.
 - Align end of section in the linker script to ensure enough padding for the
   last function.
 - Expand commit message and subject.
 - Rework Kconfig options.
 - Check that the compiler supports the option.

Changes since v1:
 - New in this version.

16 months agosmp: move cpu_is_offline() definition
Jan Beulich [Thu, 14 Dec 2023 09:56:07 +0000 (10:56 +0100)]
smp: move cpu_is_offline() definition

It's all the same for the 3 arch-es which have it, and RISC-V would
introduce a 4th instance. Put it in xen/smp.h instead, while still
permitting asm/smp.h to define a custom variant if need be.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: George Dunlap <george.dunlap@cloud.com>
Reviewed-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Acked-by: Julien Grall <jgrall@amazon.com>
16 months agotools/libs/evtchn: fix locking in Mini-OS
Juergen Gross [Thu, 14 Dec 2023 09:55:24 +0000 (10:55 +0100)]
tools/libs/evtchn: fix locking in Mini-OS

When adding locking to tools/libs/evtchn/minios.c a semaphore was
used. This can result in deadlocks, as the lock is taken inside the
event handler, which can interrupt an already locked region.

The fix is rather simple, as Mini-OS is supporting a single vcpu
only. So instead of the semaphore it is enough to disable interrupts
when operating on the port list.

Fixes: bc4fe94a69d4 ("ools/libs/evtchn: replace assert()s in stubdom with proper locking")
Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
16 months agoxen/arm: ffa: return FFA_RET_NOT_SUPPORTED on unhandled calls
Jens Wiklander [Wed, 13 Dec 2023 10:32:41 +0000 (11:32 +0100)]
xen/arm: ffa: return FFA_RET_NOT_SUPPORTED on unhandled calls

Until now an unsupported FF-A request has been reported back with
ARM_SMCCC_ERR_UNKNOWN_FUNCTION in register x0. A FF-A caller would
rather expect FFA_ERROR in x0 and FFA_RET_NOT_SUPPORTED in x2 so update
ffa_handle_call() to return true and with the cpu_user_regs updated.

Fixes: 38846de2176b ("xen/arm: tee: add a primitive FF-A mediator")
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
16 months agoxen/arm: don't pass iommu properties to hwdom for iommu-map
Stewart Hildebrand [Thu, 9 Nov 2023 18:27:04 +0000 (13:27 -0500)]
xen/arm: don't pass iommu properties to hwdom for iommu-map

A device tree node for a PCIe root controller may have an iommu-map property [1]
with a phandle reference to the SMMU node, but not necessarily an iommus
property. In this case, we want to treat it the same as we currently handle
devices with an iommus property: don't pass the iommu related properties to
hwdom.

[1] https://www.kernel.org/doc/Documentation/devicetree/bindings/pci/pci-iommu.txt

Reported-by: Michal Orzel <michal.orzel@amd.com>
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Acked-by: Julien Grall <jgrall@amazon.com>
16 months agoxen/iommu: address leftover violation of MISRA C:2012 Rule 8.2
Federico Serafini [Wed, 13 Dec 2023 09:40:39 +0000 (10:40 +0100)]
xen/iommu: address leftover violation of MISRA C:2012 Rule 8.2

Add missing parameter name. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
16 months agoxen/drivers: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Wed, 13 Dec 2023 09:40:08 +0000 (10:40 +0100)]
xen/drivers: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
16 months agox86/include: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Wed, 13 Dec 2023 09:39:30 +0000 (10:39 +0100)]
x86/include: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
16 months agoxen/compat: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Wed, 13 Dec 2023 09:38:19 +0000 (10:38 +0100)]
xen/compat: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
16 months agoMAINTAINERS: add me as Mini-OS maintainer
Juergen Gross [Wed, 13 Dec 2023 09:37:44 +0000 (10:37 +0100)]
MAINTAINERS: add me as Mini-OS maintainer

I've been the main contributor to Mini-OS since several years now.
Add me as a maintainer.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
16 months agoxen/riscv: define bug frame tables in xen.lds.S
Oleksii Kurochko [Wed, 13 Dec 2023 09:37:22 +0000 (10:37 +0100)]
xen/riscv: define bug frame tables in xen.lds.S

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
16 months agoRevert "xen: make include/xen/unaligned.h usable on all architectures"
Julien Grall [Tue, 12 Dec 2023 15:43:49 +0000 (15:43 +0000)]
Revert "xen: make include/xen/unaligned.h usable on all architectures"

This breaks gitlab CI:

https://gitlab.com/xen-project/hardware/xen/-/jobs/5733143618

This reverts commit 6c4be4950391d77b78e824d41115def397dbc487.

16 months agoRevert "xen: remove asm/unaligned.h"
Julien Grall [Tue, 12 Dec 2023 15:43:19 +0000 (15:43 +0000)]
Revert "xen: remove asm/unaligned.h"

This breaks gitlab CI:

https://gitlab.com/xen-project/hardware/xen/-/jobs/5733143618

This reverts commit 6619c6f8913a8c7b2b980dd49a430c62ce6ce5ab.

16 months agoxen/spinlock: make spinlock initializers more readable
Juergen Gross [Tue, 12 Dec 2023 13:05:19 +0000 (14:05 +0100)]
xen/spinlock: make spinlock initializers more readable

Use named member initializers instead of positional ones for the macros
used to initialize structures.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
16 months agoxen/spinlock: reduce lock profile ifdefs
Juergen Gross [Tue, 12 Dec 2023 13:04:47 +0000 (14:04 +0100)]
xen/spinlock: reduce lock profile ifdefs

With some small adjustments to the LOCK_PROFILE_* macros some #ifdefs
can be dropped from spinlock.c.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Acked-by: Julien Grall <jgrall@amazon.com>
16 months agoxen/arm: smmu: move phys_addr_t definition to linux-compat.h
Federico Serafini [Tue, 12 Dec 2023 13:04:22 +0000 (14:04 +0100)]
xen/arm: smmu: move phys_addr_t definition to linux-compat.h

Both smmu and smmu-v3 (ported from Linux) define the typedef name
"phys_addr_t": move the type definition to the common header
linux-compat.h to address violations of MISRA C:2012 Rule 5.6
("A typedef name shall be a unique identifier").
No functional change.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Suggested-by: Julien Grall <julien@xen.org>
Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
16 months agoxen/sched: address MISRA C:2012 Rule 2.1
Nicola Vetrini [Tue, 12 Dec 2023 13:03:58 +0000 (14:03 +0100)]
xen/sched: address MISRA C:2012 Rule 2.1

The break statement after the return statement is definitely unreachable
and can be removed with no functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: George Dunlap <george.dunlap@cloud.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
16 months agoAMD/IOMMU: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Tue, 12 Dec 2023 13:03:33 +0000 (14:03 +0100)]
AMD/IOMMU: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names to address violations of MISRA C:2012
Rule 8.2. Remove trailing spaces and use C standard types to comply
with XEN coding style. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
16 months agox86/mm: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Tue, 12 Dec 2023 13:02:58 +0000 (14:02 +0100)]
x86/mm: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
16 months agox86/mm: remove compat_subarch_memory_op()
Federico Serafini [Tue, 12 Dec 2023 13:02:25 +0000 (14:02 +0100)]
x86/mm: remove compat_subarch_memory_op()

Remove remove compat_subarch_memory_op() declaration: there is no
definition and there are no calls to such function in the XEN project.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
16 months agoxen/acpi: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Tue, 12 Dec 2023 13:01:56 +0000 (14:01 +0100)]
xen/acpi: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
16 months agoxen/arm: page: Avoid pointer overflow on cache clean & invalidate
Michal Orzel [Thu, 23 Nov 2023 14:53:02 +0000 (15:53 +0100)]
xen/arm: page: Avoid pointer overflow on cache clean & invalidate

On Arm32, after cleaning and invalidating the last dcache line of the top
domheap page i.e. VA = 0xfffff000 (as a result of flushing the page to
RAM), we end up adding the value of a dcache line size to the pointer
once again, which results in a pointer arithmetic overflow (with 64B line
size, operation 0xffffffc0 + 0x40 overflows to 0x0). Such behavior is
undefined and given the wide range of compiler versions we support, it is
difficult to determine what could happen in such scenario.

Modify clean_and_invalidate_dcache_va_range() as well as
clean_dcache_va_range() and invalidate_dcache_va_range() due to similarity
of handling to prevent pointer arithmetic overflow. Modify the loops to
use an additional variable to store the index of the next cacheline.
Add an assert to prevent passing a region that wraps around which is
illegal and would end up in a page fault anyway (region 0-2MB is
unmapped). Lastly, return early if size passed is 0.

Note that on Arm64, we don't have this problem given that the max VA
space we support is 48-bits.

This is XSA-447 / CVE-2023-46837.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
16 months agoMAINTAINERS: Hand over the release manager role to Oleksii Kurochko
Henry Wang [Thu, 7 Dec 2023 16:20:36 +0000 (00:20 +0800)]
MAINTAINERS: Hand over the release manager role to Oleksii Kurochko

I've finished the opportunity to do two releases (4.17 and 4.18)
and Oleksii Kurochko has volunteered to be the next release manager.
Hand over the role to him by changing the maintainership of the
CHANGELOG.md.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
Acked-by: Julien Grall <jgrall@amazon.com>
Acked-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
16 months agoxen: remove asm/unaligned.h
Juergen Gross [Mon, 11 Dec 2023 13:16:16 +0000 (14:16 +0100)]
xen: remove asm/unaligned.h

With include/xen/unaligned.h now dealing properly with unaligned
accesses for all architectures, asm/unaligned.h can be removed and
users can be switched to include xen/unaligned.h instead.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
16 months agoxen: make include/xen/unaligned.h usable on all architectures
Juergen Gross [Mon, 11 Dec 2023 13:16:15 +0000 (14:16 +0100)]
xen: make include/xen/unaligned.h usable on all architectures

Instead of defining get_unaligned() and put_unaligned() in a way that
is only supporting architectures allowing unaligned accesses, use the
same approach as the Linux kernel and let the compiler do the
decision how to generate the code for probably unaligned data accesses.

Update include/xen/unaligned.h from include/asm-generic/unaligned.h of
the Linux kernel.

The generated code has been checked to be the same on x86.

Modify the Linux variant to not use underscore prefixed identifiers,
avoid unneeded parentheses and drop the 24-bit accessors.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 803f4e1eab7a
Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
16 months agoxen/arm: set -mno-unaligned-access compiler option for Arm32
Juergen Gross [Mon, 11 Dec 2023 13:16:14 +0000 (14:16 +0100)]
xen/arm: set -mno-unaligned-access compiler option for Arm32

As the hypervisor is disabling unaligned accesses for Arm32, set the
-mno-unaligned-access compiler option for building. This will prohibit
unaligned accesses when e.g. accessing 2- or 4-byte data items in
packed data structures.

Backport: 4.15+
Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
16 months agotools/xenstored: potentially split trace_io() out message
Juergen Gross [Thu, 23 Nov 2023 16:08:34 +0000 (17:08 +0100)]
tools/xenstored: potentially split trace_io() out message

Today write_messages() will call trace_io() after having written the
complete message to the ring buffer or socket.

In case the message can't be written in one go, split it by writing
one trace entry when starting the write and one when finishing it.

In order to distinguish a complete OUT message from a split one, let the
caller of trace_io specify the prefix string ("IN", "OUT", "OUT(START)",
"OUT(END)") directly instead via an int.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
16 months agox86/viridian: make build_assertions static
Nicola Vetrini [Mon, 11 Dec 2023 10:28:02 +0000 (11:28 +0100)]
x86/viridian: make build_assertions static

This is consistent with other instances of the same function
and also resolves a violation of MISRA C:2012 Rule 8.4.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Paul Durrant <paul@xen.org>
16 months agodocs/misra/rules.rst: add more rules
Stefano Stabellini [Mon, 11 Dec 2023 10:27:20 +0000 (11:27 +0100)]
docs/misra/rules.rst: add more rules

Add the rules accepted in the last three MISRA C working group meetings.

Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
16 months agoxen: address violations of MISRA C:2012 Rule 14.4
Maria Celeste Cesario [Mon, 11 Dec 2023 10:27:07 +0000 (11:27 +0100)]
xen: address violations of MISRA C:2012 Rule 14.4

The xen sources contain violations of MISRA C:2012 Rule 14.4 whose
headline states:
"The controlling expression of an if statement and the controlling
expression of an iteration-statement shall have essentially Boolean type".

Struct domain member is_dying is an anonymous enum designed to act as boolean.
Add deviation to mark its uses in controlling expressions as deliberate.

Signed-off-by: Maria Celeste Cesario <maria.celeste.cesario@bugseng.com>
Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
16 months agox86/acpi: remove acpi_pic_sci_set_trigger()
Federico Serafini [Mon, 11 Dec 2023 10:26:16 +0000 (11:26 +0100)]
x86/acpi: remove acpi_pic_sci_set_trigger()

Remove apci_pic_set_trigger() declaration: there is no definition and there are
no calls to such function in the XEN project.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
16 months agotools/libs/evtchn: replace assert()s in stubdom with proper locking
Juergen Gross [Thu, 7 Dec 2023 06:25:51 +0000 (07:25 +0100)]
tools/libs/evtchn: replace assert()s in stubdom with proper locking

In tools/libs/evtchn/minios.c there are assert()s for the current
thread being the main thread when binding an event channel.

As Mini-OS is supporting multiple threads, there is no real reason
why the binding shouldn't be allowed to happen in any other thread.

Drop the assert()s and replace them with proper locking of the
port_list.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jason Andryuk <jandryuk@gmail.com>
16 months agoConfig: Update MiniOS revision
Andrew Cooper [Thu, 7 Dec 2023 18:54:45 +0000 (18:54 +0000)]
Config: Update MiniOS revision

Fixes for CI breakages

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
16 months agoCODING_STYLE: Add a section of the naming convention
Julien Grall [Tue, 5 Dec 2023 18:12:18 +0000 (18:12 +0000)]
CODING_STYLE: Add a section of the naming convention

Several maintainers have expressed a stronger preference
to use '-' when in filename and option that contains multiple
words.

So document it in CODING_STYLE.

Signed-off-by: Julien Grall <jgrall@amazon.com>
16 months agoxen/sched: do some minor cleanup of sched_move_domain()
Juergen Gross [Mon, 4 Dec 2023 15:23:21 +0000 (16:23 +0100)]
xen/sched: do some minor cleanup of sched_move_domain()

Do some minor cleanups:

- Move setting of old_domdata and old_units next to each other
- Drop incrementing unit_idx in the final loop of sched_move_domain()
  as it isn't used afterwards
- Rename new_p to new_cpu and unit_p to unit_cpu

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: George Dunlap <george.dunlap@cloud.com>
16 months agoxen/sched: fix sched_move_domain()
Juergen Gross [Mon, 4 Dec 2023 15:23:20 +0000 (16:23 +0100)]
xen/sched: fix sched_move_domain()

Do cleanup in sched_move_domain() in a dedicated service function,
which is called either in error case with newly allocated data, or in
success case with the old data to be freed.

This will at once fix some subtle bugs which sneaked in due to
forgetting to overwrite some pointers in the error case.

Fixes: 70fadc41635b ("xen/cpupool: support moving domain between cpupools with different granularity")
Reported-by: René Winther Højgaard <renewin@proton.me>
Initial-fix-by: Jan Beulich <jbeulich@suse.com>
Initial-fix-by: George Dunlap <george.dunlap@cloud.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: George Dunlap <george.dunlap@cloud.com>
16 months agoxen/arm: bootfdt: Check return code of device_tree_for_each_node()
Michal Orzel [Thu, 7 Dec 2023 10:14:32 +0000 (11:14 +0100)]
xen/arm: bootfdt: Check return code of device_tree_for_each_node()

As a result of not checking the return code of device_tree_for_each_node()
in boot_fdt_info(), any error occured during early FDT parsing does not
stop Xen from booting. This can result in an unwanted behavior in later
boot stages. Fix it by checking the return code and panicing on an error.

Fixes: 9cf4a9a46717 ("device tree: add device_tree_for_each_node()")
Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Julien Grall <jgrall@amazon.com>
16 months agotools/xenstored: remove the "-R" command line option
Juergen Gross [Tue, 21 Nov 2023 11:40:47 +0000 (12:40 +0100)]
tools/xenstored: remove the "-R" command line option

The "-R" (no recovery) command line option enables to omit fixing the
node store in case of detected inconsistencies.

This might have been of interest in the past, when the node data base
was kept in a file, but now the usability of this option is zero.

Remove the "-R" option.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
16 months agotools/xenstored: remove the "-P" command line option
Juergen Gross [Tue, 21 Nov 2023 11:40:46 +0000 (12:40 +0100)]
tools/xenstored: remove the "-P" command line option

The "-P" command line option just results in printing the PID of the
xenstored daemon to stdout before stdout is being closed. The same
information can be retrieved from the PID file via the "-F" option.

Remove the redundant "-P" option.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
16 months agotools/xenstored: remove "-V" command line option
Juergen Gross [Tue, 21 Nov 2023 11:40:45 +0000 (12:40 +0100)]
tools/xenstored: remove "-V" command line option

The "-V" (verbose) command line option is nearly completely redundant
with "io" tracing. Just the time of the printed data is a little bit
different, while the tracing is more informative.

Remove the verbose option.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
16 months agotools/xenstored: remove "-D" command line parameter
Juergen Gross [Tue, 21 Nov 2023 11:40:44 +0000 (12:40 +0100)]
tools/xenstored: remove "-D" command line parameter

Remove the "-D" command parameter, which is disabling initialization of
the mandatory domain data handling.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
16 months agox86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Jan Beulich [Thu, 7 Dec 2023 07:33:55 +0000 (08:33 +0100)]
x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3

The rule demands that all array elements be initialized (or dedicated
initializers be used). Introduce a small set of macros to allow doing so
without unduly affecting use sites (in particular in terms of how many
elements .matches[] actually has; right now there's no use of
DMI_MATCH4(), so we could even consider reducing the array size to 3).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
16 months agoRevert "x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3"
Jan Beulich [Thu, 7 Dec 2023 07:32:38 +0000 (08:32 +0100)]
Revert "x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3"

This reverts commit 59df2851318357763be3ad8a5f300d6a9e7c6e38.
I mistakenly committed v1 of the patch, instead of v2.

16 months agoxen/hypervisor: Don't use cc-option-add for -Wdeclaration-after-statement
Julien Grall [Wed, 6 Dec 2023 19:19:58 +0000 (19:19 +0000)]
xen/hypervisor: Don't use cc-option-add for -Wdeclaration-after-statement

Per Andrew's comment in [1] all the compilers we support should
recognize the flag.

I forgot to address the comment while committing.

[1] fcf00090-304a-49f7-8a61-a54347e90a3b@citrix.com

Signed-off-by: Julien Grall <jgrall@amazon.com>
16 months agoOnly compile the hypervisor with -Wdeclaration-after-statement
Julien Grall [Tue, 5 Dec 2023 18:32:26 +0000 (18:32 +0000)]
Only compile the hypervisor with -Wdeclaration-after-statement

Right now, all tools and hypervisor will be complied with the option
-Wdeclaration-after-statement. While most of the code in the hypervisor
is controlled by us, for tools we may import external libraries.

The build will fail if one of them are using the construct we are
trying to prevent. This is the case when building against Python 3.12
and Yocto:

| In file included from /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/Python.h:44,
|                  from xen/lowlevel/xc/xc.c:8:
| /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/object.h: In function 'Py_SIZE':
| /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/object.h:233:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
|   233 |     PyVarObject *var_ob = _PyVarObject_CAST(ob);
|       |     ^~~~~~~~~~~
| In file included from /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/Python.h:53:
| /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/cpython/longintrepr.h: In function '_PyLong_CompactValue':
| /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/cpython/longintrepr.h:121:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
|   121 |     Py_ssize_t sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK);
|       |     ^~~~~~~~~~
| cc1: all warnings being treated as errors

Looking at the tools directory, a fair few directory already add
-Wno-declaration-after-statement to inhibit the default behavior.

We have always build the hypervisor with the flag, so for now remove
only the flag for anything but the hypervisor. We can decide at later
time whether we want to relax.

Also remove the -Wno-declaration-after-statement in some subdirectory
as the flag is now unnecessary.

Part of the commit message was take from Alexander's first proposal:

Link: https://lore.kernel.org/xen-devel/20231128174729.3880113-1-alex@linutronix.de/
Reported-by: Alexander Kanavin <alex@linutronix.de>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Tested-by: Jason Andryuk <jandryuk@gmail.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
17 months agox86/DMI: adjustments to comply with Misra C:2012 Rule 9.3
Jan Beulich [Wed, 6 Dec 2023 09:25:21 +0000 (10:25 +0100)]
x86/DMI: adjustments to comply with Misra C:2012 Rule 9.3

The rule demands that all array elements be initialized (or dedicated
initializers be used). Introduce a small set of macros to allow doing so
without unduly affecting use sites (in particular in terms of how many
elements .matches[] actually has; right now there's no use of
DMI_MATCH4(), so we could even consider reducing the array size to 3).

Note that DMI_MATCH() needs adjustment because of the comma included in
its expansion, which - due to being unparenthesized - would otherwise
cause macro arguments in the "further replacement" step to be wrong.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoxen/pci: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Wed, 6 Dec 2023 09:24:47 +0000 (10:24 +0100)]
xen/pci: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names to address violations of MISRA C:2012
Rule 8.2. Furthermore, use C standard types to comply with XEN coding style.
No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
17 months agox86/mce: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Wed, 6 Dec 2023 09:24:14 +0000 (10:24 +0100)]
x86/mce: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
17 months agox86/page: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Wed, 6 Dec 2023 09:23:35 +0000 (10:23 +0100)]
x86/page: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
17 months agoconfig: update Mini-OS commit
Juergen Gross [Wed, 6 Dec 2023 09:23:20 +0000 (10:23 +0100)]
config: update Mini-OS commit

Update the Mini-OS upstream revision.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
17 months agox86/vPIC: vpic_elcr_mask() master bit 2 control
Jan Beulich [Wed, 6 Dec 2023 09:22:46 +0000 (10:22 +0100)]
x86/vPIC: vpic_elcr_mask() master bit 2 control

Master bit 2 is treated specially: We force it set, but we don't expose
the bit being set to the guest. While right now the read and write
handling can easily use the fixed mask, the restore input checking that
is about to be put in place wants to use the inverted mask to prove that
no bits are unduly set. That will require master bit 2 to be set. Otoh
the read path requires the bit to be clear (the bit can have either
value for the use on the write path). Hence allow use sites control over
that bit.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
17 months agox86/HVM: introduce hvm_get_entry()
Jan Beulich [Wed, 6 Dec 2023 09:21:51 +0000 (10:21 +0100)]
x86/HVM: introduce hvm_get_entry()

... to accompany hvm_read_entry() when actual copying isn't desirable.
This allows to remove open-coded stream accesses from hpet_load(),
along with using the helper in hvm_load() itself.

Since arch_hvm_load()'s declaration would need changing, and since the
function is not used from elsewhere, purge the declaration. With that it
makes little sense to keep arch_hvm_save()'s around; convert that
function to static then at the same time.

In hpet_load() simplify the specific case of error return that's in
context anyway: There's no need to hold the lock when only updating a
local variable.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
17 months agoxen/riscv: introduce spinlock.h
Oleksii Kurochko [Wed, 6 Dec 2023 09:20:27 +0000 (10:20 +0100)]
xen/riscv: introduce spinlock.h

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
17 months agoxen/riscv:introduce asm/byteorder.h
Oleksii Kurochko [Wed, 6 Dec 2023 09:19:59 +0000 (10:19 +0100)]
xen/riscv:introduce asm/byteorder.h

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
17 months agoautomation/eclair: tag function calls to address violations of MISRA C:2012 Rule...
Simone Ballarin [Fri, 24 Nov 2023 17:29:41 +0000 (18:29 +0100)]
automation/eclair: tag function calls to address violations of MISRA C:2012 Rule 13.1

Rule 13.1: Initializer lists shall not contain persistent side effects

Invocations of functions in initializer lists cause violations of rule
13.1 if the called functions are not tagged with __attribute_pure__ or
__attribute_const__ as they can produce persistent side effects.

Handling these violations with  attributes is not always possible: the
pure and const attributes may cause unwanted and potentially dangerous
optimisations.

To avoid this problem ECLAIR allows using the same attributes in the
-call_properties setting. Additionally, it adds the noeffect attribute
with the following definition:
"like pure but can also read volatile variable not triggering side effects"

These patch tags some functions used in initializer lists to address
violations of Rule 13.1.

No functional changes.

Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoautomation/eclair: add deviations for MISRA C:2012 Rule 5.6
Federico Serafini [Wed, 29 Nov 2023 08:35:05 +0000 (09:35 +0100)]
automation/eclair: add deviations for MISRA C:2012 Rule 5.6

Update ECLAIR configuration to take into account the adopted files
and type "ret_t".
Update docs/misra/deviations.rst accordingly.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agodocs/misra: deviate deliberately unused labels
Nicola Vetrini [Mon, 4 Dec 2023 18:23:11 +0000 (19:23 +0100)]
docs/misra: deviate deliberately unused labels

The labels marked with __maybe_unused are either used only
in certain build configurations or deliberately unused.
See the justification in docs/misra/deviations.rst.

No functional changes.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoCI: Fix fallout from adding elfutils-dev to the build container
Andrew Cooper [Tue, 5 Dec 2023 21:54:25 +0000 (21:54 +0000)]
CI: Fix fallout from adding elfutils-dev to the build container

Commit 948e03303138 ("automation/alpine: add elfutils-dev") had an unintended
consequence of causing Qemu to gain a runtime dependency on libdw.so

The {adl,zen3p}-pci-hvm-x86-64-gcc-debug tests, which are the only two tests
that run the built Qemu, started failing with:

  Error loading shared library libdw.so.1: No such file or directory (needed by /usr/local/lib/xen/bin/qemu-system-i386)
  Error relocating /usr/local/lib/xen/bin/qemu-system-i386: dwfl_begin: symbol not found

Update the test container with libelf to cope.

While editing the runtime dependency list, fix up two other problems.  texinfo
isn't a runtime dependency, and we should be using xz itself, not it's
development libraries.  Both changes shrink the initrd used for tests.

Fixes: 948e03303138 ("automation/alpine: add elfutils-dev")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agons16550: remove partial explicit initializer
Nicola Vetrini [Tue, 5 Dec 2023 16:31:23 +0000 (17:31 +0100)]
ns16550: remove partial explicit initializer

The initializer of 'ns16550_com' violates MISRA C Rule 9.3
because it explicitly initializes only the first element of the array,
but the semantics is the same if the explicit initialization is
omitted.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
17 months agoautomation/alpine: add elfutils-dev
Roger Pau Monne [Tue, 28 Nov 2023 10:03:49 +0000 (11:03 +0100)]
automation/alpine: add elfutils-dev

In preparation for adding some livepatch-build-tools test update the Alpine
container to also install elfutils-dev.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
17 months agoubsan: Introduce CONFIG_UBSAN_FATAL to panic on UBSAN failure
Michal Orzel [Mon, 27 Nov 2023 14:41:55 +0000 (15:41 +0100)]
ubsan: Introduce CONFIG_UBSAN_FATAL to panic on UBSAN failure

Introduce the CONFIG_UBSAN_FATAL option to cater to scenarios where prompt
attention to undefined behavior issues, notably during CI test runs, is
essential. When enabled, this option causes Xen to panic upon detecting
UBSAN failure (as the last step in ubsan_epilogue()).

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
17 months agoxen/domain: fix error path in domain_create()
Stewart Hildebrand [Tue, 5 Dec 2023 09:00:51 +0000 (10:00 +0100)]
xen/domain: fix error path in domain_create()

If rangeset_new() fails, err would not be set to an appropriate error
code. Set it to -ENOMEM.

Fixes: 580c458699e3 ("xen/domain: Call arch_domain_create() as early as possible in domain_create()")
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
17 months agoxen/vpci: header: filter PCI capabilities
Stewart Hildebrand [Tue, 5 Dec 2023 09:00:18 +0000 (10:00 +0100)]
xen/vpci: header: filter PCI capabilities

Currently, Xen vPCI only supports virtualizing the MSI and MSI-X capabilities.
Hide all other PCI capabilities (including extended capabilities) from domUs for
now, even though there may be certain devices/drivers that depend on being able
to discover certain capabilities.

We parse the physical PCI capabilities linked list and add vPCI register
handlers for the next elements, inserting our own next value, thus presenting a
modified linked list to the domU.

Introduce helper functions vpci_hw_read8 and vpci_read_val. The vpci_read_val
helper function returns a fixed value, which may be used for read as zero
registers, or registers whose value doesn't change.

Introduce pci_find_next_cap_ttl() helper while adapting the logic from
pci_find_next_cap() to suit our needs, and implement the existing
pci_find_next_cap() in terms of the new helper.

Rename init_bars() to init_header() since it is now doing more than initializing
BARs.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
17 months agoxen/vpci: header: status register handler
Stewart Hildebrand [Tue, 5 Dec 2023 08:59:45 +0000 (09:59 +0100)]
xen/vpci: header: status register handler

Introduce a handler for the PCI status register, with ability to mask
the capabilities bit. The status register contains RsvdZ bits,
read-only bits, and write-1-to-clear bits. Additionally, we use RsvdP to
mask the capabilities bit. Introduce bitmasks to handle these in vPCI.
If a bit in the bitmask is set, then the special meaning applies:

  ro_mask: read normal, guest write ignore (preserve on write to hardware)
  rw1c_mask: read normal, write 1 to clear
  rsvdp_mask: read as zero, guest write ignore (preserve on write to hardware)
  rsvdz_mask: read as zero, guest write ignore (write zero to hardware)

The RO/RW1C/RsvdP/RsvdZ naming and definitions were borrowed from the
PCI Express Base 6.1 specification. RsvdP/RsvdZ bits help Xen enforce
our view of the world. Xen preserves the value of read-only bits on
write to hardware, discarding the guests write value. This is done in
case hardware wrongly implements R/O bits as R/W.

The mask_cap_list flag will be set in a follow-on change.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
17 months agoxen: address violations of MISRA C:2012 Rule 11.8
Maria Celeste Cesario [Tue, 5 Dec 2023 08:58:37 +0000 (09:58 +0100)]
xen: address violations of MISRA C:2012 Rule 11.8

Remove or amend casts to comply with Rule 11.8.

Fix violations by adding missing const qualifier in cast.
Fix violations by removing unnecessary cast.
Change type of operands from char* to uintptr_t: uintptr_t is
the appropriate type for memory address operations.

No functional changes.

Signed-off-by: Maria Celeste Cesario <maria.celeste.cesario@bugseng.com>
Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
17 months agobump default SeaBIOS version to 1.16.3
Jan Beulich [Tue, 5 Dec 2023 08:58:17 +0000 (09:58 +0100)]
bump default SeaBIOS version to 1.16.3

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
17 months agoxen/sched: fix adding offline cpu to cpupool
Juergen Gross [Tue, 5 Dec 2023 08:57:38 +0000 (09:57 +0100)]
xen/sched: fix adding offline cpu to cpupool

Trying to add an offline cpu to a cpupool can crash the hypervisor,
as the probably non-existing percpu area of the cpu is accessed before
the availability of the cpu is being tested. This can happen in case
the cpupool's granularity is "core" or "socket".

Fix that by testing the cpu to be online.

Fixes: cb563d7665f2 ("xen/sched: support core scheduling for moving cpus to/from cpupools")
Reported-by: René Winther Højgaard <renewin@proton.me>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
17 months agox86emul: avoid triggering event related assertions
Jan Beulich [Tue, 5 Dec 2023 08:57:05 +0000 (09:57 +0100)]
x86emul: avoid triggering event related assertions

The assertion at the end of x86_emulate_wrapper() as well as the ones
in x86_emul_{hw_exception,pagefault}() can trigger if we ignore
X86EMUL_EXCEPTION coming back from certain hook functions. Squash
exceptions when merely probing MSRs, plus on SWAPGS'es "best effort"
error handling path.

In adjust_bnd() add another assertion after the read_xcr(0, ...)
invocation, paralleling the one in x86emul_get_fpu() - XCR0 reads should
never fault when XSAVE is (implicitly) known to be available.

Also update the respective comment in x86_emulate_wrapper().

Fixes: 14a6be89ec04 ("x86emul: correct EFLAGS.TF handling")
Fixes: cb2626c75813 ("x86emul: conditionally clear BNDn for branches")
Fixes: 6eb43fcf8a0b ("x86emul: support SWAPGS")
Reported-by: AFL
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
17 months agoxen/public: fix flexible array definitions
Juergen Gross [Tue, 5 Dec 2023 08:56:08 +0000 (09:56 +0100)]
xen/public: fix flexible array definitions

Flexible arrays in public headers can be problematic with some
compilers.

With XEN_FLEX_ARRAY_DIM there is a mechanism available to deal with
this issue, but care must be taken to not change the affected structs
in an incompatible way.

So bump __XEN_LATEST_INTERFACE_VERSION__ and introduce a new macro
XENPV_FLEX_ARRAY_DIM which will be XENPV_FLEX_ARRAY_DIM with the
interface version being new enough and "1" (the value used today in
the affected headers) when the interface version is an old one.

Replace the arr[1] instances (this includes the ones seen to be
problematic in recent Linux kernels [1]) with arr[XENPV_FLEX_ARRAY_DIM]
in order to avoid compilation errors.

[1]: https://bugzilla.kernel.org/show_bug.cgi?id=217693

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Henry Wang <Henry.Wang@arm.com> # CHANGELOG
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
17 months agox86/p2m: address a violation of MISRA C:2012 Rule 8.3
Federico Serafini [Tue, 5 Dec 2023 08:54:52 +0000 (09:54 +0100)]
x86/p2m: address a violation of MISRA C:2012 Rule 8.3

Make function declaration and definition consistent changing
parameter name from "gpfn" to "gfn".
For consistency, rename also "old_gpfn" to "old_gfn".
No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
17 months agox86/p2m: preparation work for xenmem_add_to_physmap_one()
Federico Serafini [Tue, 5 Dec 2023 08:54:07 +0000 (09:54 +0100)]
x86/p2m: preparation work for xenmem_add_to_physmap_one()

The objective is to use parameter name "gfn" for
xenmem_add_to_physmap_one().
Since the name "gfn" is currently used as identifier for a local
variable, bad things could happen if new uses of such variable are
committed while a renaming patch is waiting for the approval.
To avoid such danger, as first thing rename the local variable from
"gfn" to "gmfn", in line with XENMAPSPACE_gmfn which is the only
space it is used with.

No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
17 months agoxen/arm: Move static event channel feature to a separate module
Michal Orzel [Thu, 30 Nov 2023 09:57:57 +0000 (10:57 +0100)]
xen/arm: Move static event channel feature to a separate module

Move static event channel feature related code to a separate module
(static-evtchn.{c,h}) in the spirit of fine granular configuration, so
that the feature can be disabled if not needed.

Introduce Kconfig option CONFIG_STATIC_EVTCHN, enabled by default (to
keep the current behavior) dependent on CONFIG_DOM0LESS. While it could
be possible to create a loopback connection for dom0 only, this use case
does not really need this feature and all the docs and commit messages
refer explicitly to the use in dom0less system.

The only function visible externally is alloc_static_evtchn(), so move
the prototype to static-evtchn.h and provide a stub in case a feature
is disabled. Guard static_evtchn_created in struct dt_device_node as
well as its helpers.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
17 months agotools/xg: Fix potential memory leak in cpu policy getters/setters
Alejandro Vallejo [Fri, 1 Dec 2023 09:53:07 +0000 (10:53 +0100)]
tools/xg: Fix potential memory leak in cpu policy getters/setters

They allocate two different hypercall buffers, but leak the first
allocation if the second one failed due to an early return that bypasses
cleanup.

Remove the early exit and go through _post() instead. Invoking _post() is
benign even if _pre() failed.

Fixes: 6b85e427098c ('x86/sysctl: Implement XEN_SYSCTL_get_cpu_policy')
Fixes: 60529dfeca14 ('x86/domctl: Implement XEN_DOMCTL_get_cpu_policy')
Fixes: 14ba07e6f816 ('x86/domctl: Implement XEN_DOMCTL_set_cpumsr_policy')
Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
17 months ago.gitignore: generalize *.new
Jan Beulich [Fri, 1 Dec 2023 09:52:44 +0000 (10:52 +0100)]
.gitignore: generalize *.new

It's not only in xen/include/xen/ that we generate (intermediate) *.new
files.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Julien Grall <jgrall@amazon.com>
17 months agodocs/misra: add entry to exclude-list.json
Nicola Vetrini [Fri, 1 Dec 2023 09:52:23 +0000 (10:52 +0100)]
docs/misra: add entry to exclude-list.json

x86/efi/check.c is not part of the final Xen binary, therefore
it doesn't need to conform to MISRA guidelines at the moment.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
17 months agoxen/arm: mmu: add headers for missing declarations
Nicola Vetrini [Fri, 1 Dec 2023 09:51:43 +0000 (10:51 +0100)]
xen/arm: mmu: add headers for missing declarations

The definitions needing the inclusion of asm/setup.h are
boot_{first,second,third}(_id)?, whereas vmap.h is needed by arch_vmap_virt_end.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoxen/serial: address a violation of MISRA C:2012 Rule 8.2
Federico Serafini [Fri, 1 Dec 2023 09:50:58 +0000 (10:50 +0100)]
xen/serial: address a violation of MISRA C:2012 Rule 8.2

Add missing parameter name. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoxen/perfc: address a violation of MISRA C:2012 Rule 8.2
Federico Serafini [Fri, 1 Dec 2023 09:50:44 +0000 (10:50 +0100)]
xen/perfc: address a violation of MISRA C:2012 Rule 8.2

Add missing parameter name. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoxen/param: address a violation of MISRA C:2012 Rule 8.2
Federico Serafini [Fri, 1 Dec 2023 09:50:34 +0000 (10:50 +0100)]
xen/param: address a violation of MISRA C:2012 Rule 8.2

Add missing parameter name. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoxen/kernel: address a violation of MISRA C:2012 Rule 8.2
Federico Serafini [Fri, 1 Dec 2023 09:50:01 +0000 (10:50 +0100)]
xen/kernel: address a violation of MISRA C:2012 Rule 8.2

Add missing parameter name. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoxen/iommu: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Fri, 1 Dec 2023 09:49:49 +0000 (10:49 +0100)]
xen/iommu: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names to address violations of MISRA C:2012
Rule 8.2 and remove uses of u{8,16,32} in favor of C standard types.
No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
17 months agoxen/notifier: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Fri, 1 Dec 2023 09:49:34 +0000 (10:49 +0100)]
xen/notifier: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoxen/domain: address violations of MISRA C:2012 Rule 8.2
Federico Serafini [Fri, 1 Dec 2023 09:48:38 +0000 (10:48 +0100)]
xen/domain: address violations of MISRA C:2012 Rule 8.2

Add missing parameter names. No functional change.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoautomation/eclair: improve scheduled analyses
Simone Ballarin [Thu, 30 Nov 2023 17:04:53 +0000 (18:04 +0100)]
automation/eclair: improve scheduled analyses

The scheduled analyses are intended to maintain an overall vision
of the MISRA complaince of the entire project. For this reason,
the file exclusions in "out_of_scope.ecl" should not be applied.

This patch amends ECLAIR settings to prevent exempting files for
scheduled analyses.

Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agodocs/misra: fix a typo in rules.rst
Nicola Vetrini [Thu, 30 Nov 2023 17:15:43 +0000 (18:15 +0100)]
docs/misra: fix a typo in rules.rst

No functional changes.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoautomation: Switch u-boot boot command to bootz for arm32 tests
Michal Orzel [Fri, 24 Nov 2023 12:09:07 +0000 (13:09 +0100)]
automation: Switch u-boot boot command to bootz for arm32 tests

Thanks to recent changes added to ImageBuilder to support the bootz
command, which allows obtaining the effective image size (including NOLOAD
sections) from the zImage header, switch the BOOT_CMD for arm32 tests to
bootz. Among other scenarios, this change will enable us, in the future,
to add tests with UBSAN enabled Xen, which would otherwise fail due to
incorrect image placement resulting in overlapping.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agodocs/misra: add guidance on the format of Dir 4.1 docs for ECLAIR
Nicola Vetrini [Fri, 17 Nov 2023 08:53:26 +0000 (09:53 +0100)]
docs/misra: add guidance on the format of Dir 4.1 docs for ECLAIR

Additional guidance on the formatting of the document for ECLAIR
is supplied.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Julien Grall <jgrall@amazon.com>
17 months agoautomation/eclair: make the docs for MISRA C:2012 Dir 4.1 visible to ECLAIR
Nicola Vetrini [Fri, 17 Nov 2023 08:53:25 +0000 (09:53 +0100)]
automation/eclair: make the docs for MISRA C:2012 Dir 4.1 visible to ECLAIR

To be able to check for the existence of the necessary subsections in
the documentation for MISRA C:2012 Dir 4.1, ECLAIR needs to have a source
file that is built.

This file is generated from 'C-runtime-failures.rst' in docs/misra
and the configuration is updated accordingly.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoarm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1
Nicola Vetrini [Wed, 29 Nov 2023 09:32:39 +0000 (10:32 +0100)]
arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1

The definitions of ffs{l}? violate Rule 10.1, by using the well-known
pattern (x & -x); its usage is wrapped by the ISOLATE_LSB macro.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoxen/livepatch: fix livepatch tests
Roger Pau Monne [Tue, 28 Nov 2023 17:41:31 +0000 (18:41 +0100)]
xen/livepatch: fix livepatch tests

The current set of in-tree livepatch tests in xen/test/livepatch started
failing after the constify of the payload funcs array, and the movement of the
status data into a separate array.

Fix the tests so they respect the constness of the funcs array and also make
use of the new location of the per-func state data.

Fixes: 82182ad7b46e ('livepatch: do not use .livepatch.funcs section to store internal state')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
17 months agocirrus-ci: update FreeBSD versions
Roger Pau Monne [Tue, 28 Nov 2023 17:11:50 +0000 (18:11 +0100)]
cirrus-ci: update FreeBSD versions

FreeBSD 14.0 has already been released, so switch to the release version image,
and introduce a FreeBSD 15.0 version to track current FreeBSD unstable
(development) branch.

Sample output at:

https://github.com/royger/xen/runs/19105278189

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
17 months agoxen/arm64: Move print_reg macro to asm/arm64/macros.h
Michal Orzel [Wed, 29 Nov 2023 09:06:45 +0000 (10:06 +0100)]
xen/arm64: Move print_reg macro to asm/arm64/macros.h

Macro print_reg is used to print a value of a register passed as an
argument. While today it is only used from within the common head.S,
in the future we might want to make use of it from other files, just
like PRINT(). It also serves as a great aid when debugging.

Expose print_reg macro by moving it to asm/arm64/macros.h and:
 - rename putn to asm_putn to denote the usage from assembly only,
 - use ENTRY() for asm_putn to make it globally visible.

This way the behavior will be consistent with what we already do on arm32.

Take the opportunity to get rid of unneeded stubs for early_puts,
init_uart and putn since the calls to them are already protected by
respective #ifdef CONFIG_EARLY_PRINTK.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Tested-by: Luca Fancellu <luca.fancellu@arm.com>
Acked-by: Julien Grall <jgrall@amazon.com>
17 months agoxen/asm-generic: introduce generic header altp2m.h
Oleksii Kurochko [Wed, 29 Nov 2023 09:12:16 +0000 (10:12 +0100)]
xen/asm-generic: introduce generic header altp2m.h

<asm/alt2pm.h> is common between several archs so it is
moved to asm-generic.

Arm and PPC were switched to asm-generic version of altp2m.h.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Shawn Anastasio <sanastasio@raptorengineering.com>
17 months agoxen/asm-generic: introduce generalized hardirq.h
Oleksii Kurochko [Wed, 29 Nov 2023 09:11:50 +0000 (10:11 +0100)]
xen/asm-generic: introduce generalized hardirq.h

<asm/hardirq.h> is common through archs thereby it is moved
to asm-generic.

Arm and PPC were switched to asm generic verstion of hardirq.h.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
Acked-by: Shawn Anastasio <sanastasio@raptorengineering.com>
17 months agoxen/asm-generic: introduce generic header percpu.h
Oleksii Kurochko [Wed, 29 Nov 2023 09:10:23 +0000 (10:10 +0100)]
xen/asm-generic: introduce generic header percpu.h

The patch introduces generic percpu.h which was based on Arm's version
with the following changes:
 * makes __per_cpu_data_end[] constant
 * introduce get_per_cpu_offset() for macros this_cpu() and this_cpu_ptr()
 * add inclustion of <asm/current.h> as get_per_cpu_offset() is located there.

Also it was changed a place where <asm/percpu.h> is included in <xen/percpu.h>
because asm-generic version of percpu.h started to include <asm/current.h> which
requires definition of DECLARE_PER_CPU.

As well the patch switches Arm, PPC and x86 architectures to use asm-generic
version of percpu.h.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Shawn Anastasio <sanastasio@raptorengineering.com>
17 months agoxen/asm-generic: introduce stub header <asm/random.h>
Oleksii Kurochko [Wed, 29 Nov 2023 09:09:55 +0000 (10:09 +0100)]
xen/asm-generic: introduce stub header <asm/random.h>

<asm/random.h> is common for Arm, PPC and RISC-V thereby it
is moved to asm-generic.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
Acked-by: Shawn Anastasio <sanastasio@raptorengineering.com>
17 months agoxen/asm-generic: introduce generic header iocap.h
Oleksii Kurochko [Wed, 29 Nov 2023 09:08:52 +0000 (10:08 +0100)]
xen/asm-generic: introduce generic header iocap.h

iocap.h is common for Arm, PPC and RISC-V architectures thereby
it was moved to asm-generic.

Also Arm and PPC were switched to asm-generic version of iocap.h.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
Acked-by: Shawn Anastasio <sanastasio@raptorengineering.com>