]> xenbits.xensource.com Git - xen.git/log
xen.git
13 days agoCI: switch x86 EFI smoke test runner to qemu-xtf.sh
Denis Mukhin [Tue, 22 Apr 2025 16:18:53 +0000 (16:18 +0000)]
CI: switch x86 EFI smoke test runner to qemu-xtf.sh

Use qemu-xtf.sh for qemu-smoke-x86-64-gcc-efi job.

Lead time is reduced a bit since not all XTF code base is built, just the
required test.

Signed-off-by: Denis Mukhin <dmukhin@ford.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
13 days agoCI: unify x86 XTF test runner
Denis Mukhin [Tue, 22 Apr 2025 16:18:48 +0000 (16:18 +0000)]
CI: unify x86 XTF test runner

Add test runner script qemu-xtf.sh which is allows any XTF x86 test to be
easily executed. Test runner is invoked from the qemu-smoke* jobs with the
hardcoded parameters.

Each x86 XTF job lead time is reduced a bit since only the test-related code
is built, not the entire XTF project.

Add .gitignore to avoid committing test artifacts by mistake.

Signed-off-by: Denis Mukhin <dmukhin@ford.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
13 days agox86/alternative: Clean up headers
Andrew Cooper [Mon, 21 Apr 2025 15:31:17 +0000 (16:31 +0100)]
x86/alternative: Clean up headers

alternative.h doesn't need lib.h now that macros.h exists.  Futhermore, STR()
is already the prevailing style, so convert the final __stringify() to drop
stringify.h too.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
13 days agox86/AMD: Convert rdmsr_amd_safe() to use asm goto()
Andrew Cooper [Mon, 7 Apr 2025 15:10:57 +0000 (16:10 +0100)]
x86/AMD: Convert rdmsr_amd_safe() to use asm goto()

Unlike the WRMSR side, we can't use asm goto() unconditionally, because our
toolchain baseline doesn't support asm goto with outputs.

However, the code generation improvements are substantial enough to warrant
the duplicate implementations.

Detect support, and use asm goto() when available.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
13 days agoxen: Drop CONFIG_CC_HAS_VISIBILITY_ATTRIBUTE
Andrew Cooper [Tue, 22 Apr 2025 11:36:01 +0000 (12:36 +0100)]
xen: Drop CONFIG_CC_HAS_VISIBILITY_ATTRIBUTE

All supported toolchains now have it.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
13 days agoxen: Drop CONFIG_CC_HAS_UBSAN
Andrew Cooper [Tue, 22 Apr 2025 11:35:54 +0000 (12:35 +0100)]
xen: Drop CONFIG_CC_HAS_UBSAN

All supported toolchains now have it.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 weeks agoxenstored: Remove setjmp.h
Jason Andryuk [Tue, 22 Apr 2025 09:25:48 +0000 (11:25 +0200)]
xenstored: Remove setjmp.h

Use of setjmp/longjmp as removed in 2006, but the include remained.
Remove it now.

Fixes: 1bac3b49cdd4 ("Import the current version of talloc from the Samba 3 source base")
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
2 weeks agocompat/memory: avoid UB shifts in XENMEM_exchange handling
Jan Beulich [Tue, 22 Apr 2025 09:25:23 +0000 (11:25 +0200)]
compat/memory: avoid UB shifts in XENMEM_exchange handling

Add an early basic check, yielding the same error code as the more
thorough one the main handler would produce.

Fixes: b8a7efe8528a ("Enable compatibility mode operation for HYPERVISOR_memory_op")
Reported-by: Manuel Andreas <manuel.andreas@tum.de>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
2 weeks agox86/boot: add cmdline to struct boot_domain
Daniel P. Smith [Tue, 22 Apr 2025 09:24:57 +0000 (11:24 +0200)]
x86/boot: add cmdline to struct boot_domain

Add a container for the "cooked" command line for a domain. This
provides for the backing memory to be directly associated with the
domain being constructed.  This is done in anticipation that the domain
construction path may need to be invoked multiple times, thus ensuring
each instance had a distinct memory allocation.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Signed-off-by: Alejandro Vallejo <agarciav@amd.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Denis Mukhin <dmukhin@ford.com>
2 weeks agox86emul: also clip repetition count for STOS
Jan Beulich [Tue, 22 Apr 2025 09:24:20 +0000 (11:24 +0200)]
x86emul: also clip repetition count for STOS

Like MOVS, INS, and OUTS, STOS also has a special purpose hook, where
the hook function may legitimately have the same expectation as to the
request not straddling address space start/end.

Fixes: 5dfe4aa4eeb6 ("x86_emulate: Do not request emulation of REP instructions beyond the")
Reported-by: Fabian Specht <f.specht@tum.de>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
2 weeks agoArm: rename smp_clear_cpu_maps()
Jan Beulich [Tue, 22 Apr 2025 09:23:41 +0000 (11:23 +0200)]
Arm: rename smp_clear_cpu_maps()

The function has lost all clearing operations. Use the commonly
available name (declared in xen/smp.h), that x86 also uses. This then
also addresses a Misra C:2012 rule 8.6 violation (not really covered
by the deviation we have).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
2 weeks agovpci/msix: use host msix table address
Stewart Hildebrand [Tue, 22 Apr 2025 09:21:54 +0000 (11:21 +0200)]
vpci/msix: use host msix table address

Introduce vmsix_table_host_{addr,base} returning the host physical MSI-X
table address and base. Use them in update_entry() and get_table().

Remove stale comment.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
2 weeks agoiommu/arm: Add iommu_dt_xlate()
Oleksandr Tyshchenko [Fri, 14 Mar 2025 13:34:50 +0000 (13:34 +0000)]
iommu/arm: Add iommu_dt_xlate()

Move code for processing DT IOMMU specifier to a separate helper.
This helper will be re-used for adding PCI devices by the subsequent
patches as we will need exact the same actions for processing
DT PCI-IOMMU specifier.

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 weeks agoxen/arm: Add capabilities to dom0less
Jason Andryuk [Wed, 16 Apr 2025 21:29:11 +0000 (17:29 -0400)]
xen/arm: Add capabilities to dom0less

Add a capabilities property to dom0less to allow building a
disaggregated system.  Only a single hardware domain and single xenstore
domain can be specified.  Multiple control domains are possible.

Introduce bootfdt.h to contain these constants.

When using the hardware or xenstore capabilities, adjust the grant and
event channel limits similar to dom0.

For a hardware domain, disallow specifying "vpl011", "nr_spis",
"multiboot,device-tree" and "passthrough" nodes.  Also, require an IOMMU
when not direct-mapped,

Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 weeks agoxen/arm: dom0less use has_dtb local variable
Jason Andryuk [Wed, 16 Apr 2025 21:29:10 +0000 (17:29 -0400)]
xen/arm: dom0less use has_dtb local variable

Store the result of finding a "multiboot,device-tree" node.  This will
simplity adding hardware domain checks.

Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 weeks agotools/init-dom0less: Only seed legacy xenstore grants
Jason Andryuk [Wed, 16 Apr 2025 21:29:09 +0000 (17:29 -0400)]
tools/init-dom0less: Only seed legacy xenstore grants

The hardware domain is unable to seed a control domain, but we want the
control domain to use xenstore.  Rely on the hypervisor to seed dom0less
grant table entries for Xenstore, so this seeding is unnecessary.

However, that only works for the new xenstore late init.  The legacy
protocol which uses init-dom0less to populate the page still needs to
seed the grant.

Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 weeks agoxen/arm: dom0less seed xenstore grant table entry
Jason Andryuk [Wed, 16 Apr 2025 21:29:08 +0000 (17:29 -0400)]
xen/arm: dom0less seed xenstore grant table entry

xenstored maps other domains' xenstore pages.  Currently this relies on
init-dom0less or xl to seed the grants from Dom0.  With split
hardware/control/xenstore domains, this is problematic since we don't
want the hardware domain to be able to map other domains' resources
without their permission.  Instead have the hypervisor seed the grant
table entry for every dom0less domain.  The grant is then accessible as
normal.

C xenstored uses grants, so it can map the xenstore pages from a
non-dom0 xenstore domain.  OCaml xenstored uses foreign mappings, so it
can only run from a privileged domain (dom0).

Add a define to indicate the late alloc xsentore PFN, to better indicate
what is being checked.  Use UINT64_MAX instead of ~0ULL as the HVM_PARAM
field is a uint64_t.  UINT64_MAX is not defined, so add it.

Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 weeks agoxen/arm: dom0less delay xenstore initialization
Jason Andryuk [Wed, 16 Apr 2025 21:29:07 +0000 (17:29 -0400)]
xen/arm: dom0less delay xenstore initialization

To allocate the xenstore event channel and initialize the grant table
entry, the xenstore domid is neeed.  A dom0 is created before the domUs,
so it is normally available through hardware_domain.  With capabilities
and dom0less, the xenstore domain may not be created first.

Keep the population of the page and HVM_PARAM_STORE_PFN in the normal
domain construction, but delay event channel creation and grant seeding
to after all domUs are created.  HVM_PARAM_STORE_PFN now serves as
indication to setup xenstore since the device tree is no longer
immediately available.  0 means no xenstore.  ~0ULL means legacy so only
the event channel needs setup, and any other value means to seed the
page.

dom0 needs to set xs_domid when it is serving as the xenstore domain.

The domain running xenstored needs to be the handler for VIRQ_DOM_EXC,
so set that as well - it otherwise defaults to hardware domain.

Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 weeks agoxen/arm: dom0less hwdom construction
Jason Andryuk [Wed, 16 Apr 2025 21:29:06 +0000 (17:29 -0400)]
xen/arm: dom0less hwdom construction

When creating a hardware domain, have the dom0less code call
construct_hwdom() which is shared with the dom0 code.  The hardware
domain requires building that best matches the dom0 build path.  Re-use
it to keep them in sync.

The device tree node of the dom0less config is now passed into
construct_hwdom().  dom0 uses /chosen for process_shm while a hwdom will
use the value from its dom0less device tree node.

Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 weeks agoxen: introduce hardware domain create flag
Daniel P. Smith [Wed, 16 Apr 2025 21:29:05 +0000 (17:29 -0400)]
xen: introduce hardware domain create flag

Add and use a new internal create domain flag to specify the hardware
domain.  This removes the hardcoding of domid 0 as the hardware domain.

This allows more flexibility with domain creation.

The assignment of d->cdf is moved later so CDF_hardware is added for the
late_hwdom case.  Also old_hwdom has the flag removed to reflect the
change.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 weeks agovmx: Don't open-code vmresume/vmlaunch instructions
Teddy Astie [Thu, 17 Apr 2025 14:24:44 +0000 (14:24 +0000)]
vmx: Don't open-code vmresume/vmlaunch instructions

binutils 2.25 has support for assembling vmresume/vmlaunch
instructions, so we don't need to open-code the byte sequences
for these opcodes anymore.

Signed-off-by: Teddy Astie <teddy.astie@vates.tech>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
2 weeks agox86: Drop asm/byteorder.h
Andrew Cooper [Fri, 28 Mar 2025 11:19:23 +0000 (11:19 +0000)]
x86: Drop asm/byteorder.h

With the common code moved fully onto xen/byteorder.h, clean up the dregs.

It turns out that msi.h has not needed byteorder.h since the use of
__{BIG,LITTLE}_ENDIAN_BITFIELD was dropped in commit d58f3941ce3f ("x86/MSI:
use standard C types in structures/unions").

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 weeks agoriscv: Remove asm/byteorder.h
Andrew Cooper [Fri, 28 Mar 2025 11:50:16 +0000 (11:50 +0000)]
riscv: Remove asm/byteorder.h

With the common code moved fully onto xen/byteorder.h, clean up the dregs.

The use of byteorder.h in io.h appears to have been copy&paste from ARM.  It's
not needed, but macros and types are.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
2 weeks agoppc: Drop asm/byteorder.h
Andrew Cooper [Fri, 28 Mar 2025 13:10:58 +0000 (13:10 +0000)]
ppc: Drop asm/byteorder.h

With the common code moved fully onto xen/byteorder.h, clean up the dregs.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Shawn Anastasio <sanastasio@raptorengineering.com>
2 weeks agoarm: Remove asm/byteorder.h
Andrew Cooper [Fri, 28 Mar 2025 13:11:06 +0000 (13:11 +0000)]
arm: Remove asm/byteorder.h

With the common code moved fully onto xen/byteorder.h, clean up the dregs.

Sort includes in some files while swapping over to xen/byteorder.h.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 weeks agoxen/common: Switch {asm -> xen}/byteorder.h
Andrew Cooper [Fri, 28 Mar 2025 13:06:42 +0000 (13:06 +0000)]
xen/common: Switch {asm -> xen}/byteorder.h

Sort the includes.  Drop useless includes of xen/types.h

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 weeks agoxsm/flask: Switch {asm -> xen}/byteorder.h
Andrew Cooper [Fri, 28 Mar 2025 13:02:53 +0000 (13:02 +0000)]
xsm/flask: Switch {asm -> xen}/byteorder.h

Sort the includes while at it.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Daniel P. Smith <dpsmith@apertussolutions.com>
2 weeks agocrypto/vmac: Switch to xen/byteswap.h
Lin Liu [Mon, 18 Oct 2021 10:32:39 +0000 (10:32 +0000)]
crypto/vmac: Switch to xen/byteswap.h

This file has its own implementation of swap bytes. Clean up
the code with xen/byteswap.h.

No functional change.

Signed-off-by: Lin Liu <lin.liu@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
2 weeks agoxen: Remove old byteorder infrastructure
Lin Liu [Thu, 21 Oct 2021 02:54:19 +0000 (02:54 +0000)]
xen: Remove old byteorder infrastructure

It is no longer used.

Signed-off-by: Lin Liu <lin.liu@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
2 weeks agoxen/decompressors: Use new byteorder infrastructure
Lin Liu [Fri, 5 Nov 2021 08:15:29 +0000 (04:15 -0400)]
xen/decompressors: Use new byteorder infrastructure

unaligned.h already includes byteorder.h, so most can simply be dropped.

No functional change.

Signed-off-by: Lin Liu <lin.liu@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 weeks agoxen/arch: Switch to new byteorder infrastructure
Lin Liu [Mon, 9 May 2022 05:47:10 +0000 (06:47 +0100)]
xen/arch: Switch to new byteorder infrastructure

This needs to be done in several steps, because of common vs arch issues.
Start by using the new common infrastructure inside the arch infrastructure.

libelf-private.h is awkward, and the only thing in Xen using swab??()
directly.  It needs updating at the same time.

Signed-off-by: Lin Liu <lin.liu@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2 weeks agoxen/decompressors: Remove use of *_to_cpup() helpers
Lin Liu [Thu, 21 Oct 2021 02:52:39 +0000 (02:52 +0000)]
xen/decompressors: Remove use of *_to_cpup() helpers

These wrappers simply hide a deference, which adds to the cognitive complexity
of reading the code.  As such, they're not going to be included in the new
byteswap infrastructure.

No functional change.

Signed-off-by: Lin Liu <lin.liu@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2 weeks agoxen/device-tree: Remove use of *_to_cpup() helpers
Lin Liu [Thu, 21 Oct 2021 02:52:39 +0000 (03:52 +0100)]
xen/device-tree: Remove use of *_to_cpup() helpers

These wrappers simply hide a deference, which adds to the cognitive complexity
of reading the code.  As such, they're not going to be included in the new
byteswap infrastructure.

No functional change.

Signed-off-by: Lin Liu <lin.liu@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Bertrand Marquis <bertrand.marquis@arm.com>
2 weeks agoxen/lib: Switch to xen/byteorder.h
Lin Liu [Wed, 20 Oct 2021 04:29:46 +0000 (04:29 +0000)]
xen/lib: Switch to xen/byteorder.h

In divmod.c, additionally swap xen/lib.h for xen/macros.h as only ABS() is
needed.

In find-next-bit.c, ext2 has nothing to do with this logic.  It was a local
modification when the logic was imported from Linux, because Xen didn't have a
suitable helper at the time.

The new infrastructure does have a suitable primitive, so use it.

No functional change.

Signed-off-by: Lin Liu <lin.liu@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2 weeks agodrivers/smmu-v3: Fix impending MISRA R20.6 violation
Andrew Cooper [Wed, 16 Apr 2025 10:54:04 +0000 (11:54 +0100)]
drivers/smmu-v3: Fix impending MISRA R20.6 violation

cpu_to_le64() is about to become a macro, at which point the #ifdef in the
middle of it becomes undefined behaviour.

Use a local variable to prepare strtab, where the #ifdef is fine to use.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
2 weeks agoxen: Implement common byte{order,swap}.h
Lin Liu [Mon, 9 May 2022 05:47:10 +0000 (01:47 -0400)]
xen: Implement common byte{order,swap}.h

The current swab??() infrastructure is unnecessarily complicated, and can be
replaced entirely with compiler builtins.

All supported compilers provide __BYTE_ORDER__ and __builtin_bswap??().

Nothing in Xen cares about the values of __{BIG,LITTLE}_ENDIAN; just that one
of them is defined.  Therefore, centralise their definitions in xen/config.h

Signed-off-by: Lin Liu <lin.liu@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2 weeks agoxen/percpu: NUMA-position the per-CPU area
Andrew Cooper [Thu, 17 Apr 2025 08:14:03 +0000 (09:14 +0100)]
xen/percpu: NUMA-position the per-CPU area

This seems to have been quite an oversight in Xen's NUMA support, albeit it
probably because NUMA was arch-specific at first.

This is unlikely to be useful for CONFIG_SEPARATE_XENHEAP builds, but that's
only ARM32 right now, and unlikely to be interested in NUMA.

Take the opportunity to sort the includes.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2 weeks agox86/HVM: update repeat count upon nested lin->phys failure
Jan Beulich [Thu, 17 Apr 2025 08:01:19 +0000 (10:01 +0200)]
x86/HVM: update repeat count upon nested lin->phys failure

For the X86EMUL_EXCEPTION case the repeat count must be correctly
propagated back. Since for the recursive invocation we use a local
helper variable, its value needs copying to the caller's one.

While there also correct the off-by-1 range in the comment ahead of the
function (strictly speaking for the "DF set" case we'd need to put
another, different range there as well).

Fixes: 53f87c03b4ea ("x86emul: generalize exception handling for rep_* hooks")
Reported-by: Manuel Andreas <manuel.andreas@tum.de>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
2 weeks agoArm: cpu_*_map adjustments
Jan Beulich [Thu, 17 Apr 2025 08:00:41 +0000 (10:00 +0200)]
Arm: cpu_*_map adjustments

First, they all start out zeroed. There's no point doing an initial
cpumask_clear() on them.

Next, only cpu_online_map may be altered post-boot, and even that only
rarely. Add respective placement attributes.

Finally, cpu_present_map really isn't anything more than an alias of
cpu_possible_map. Avoid the copying, and have the linker provide the
symbol (if needed in the first place; it is needed right now as
common code references the symbol).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
2 weeks agoEFI: Avoid crash calling PrintErrMesg from efi_multiboot2
Frediano Ziglio [Thu, 17 Apr 2025 07:59:41 +0000 (09:59 +0200)]
EFI: Avoid crash calling PrintErrMesg from efi_multiboot2

Although code is compiled with -fpic option data is not position
independent. This causes data pointer to become invalid if
code is not relocated properly which is what happens for
efi_multiboot2 which is called by multiboot entry code.

Code tested adding
   PrintErrMesg(L"Test message", EFI_BUFFER_TOO_SMALL);
in efi_multiboot2 before calling efi_arch_edd (this function
can potentially call PrintErrMesg).

Before the patch (XenServer installation on Qemu, xen replaced
with vanilla xen.gz):
  Booting `XenServer (Serial)'Booting `XenServer (Serial)'
  Test message: !!!! X64 Exception Type - 0E(#PF - Page-Fault)  CPU Apic ID - 00000000 !!!!
  ExceptionData - 0000000000000000  I:0 R:0 U:0 W:0 P:0 PK:0 SS:0 SGX:0
  RIP  - 000000007EE21E9A, CS  - 0000000000000038, RFLAGS - 0000000000210246
  RAX  - 000000007FF0C1B5, RCX - 0000000000000050, RDX - 0000000000000010
  RBX  - 0000000000000000, RSP - 000000007FF0C180, RBP - 000000007FF0C210
  RSI  - FFFF82D040467CE8, RDI - 0000000000000000
  R8   - 000000007FF0C1C8, R9  - 000000007FF0C1C0, R10 - 0000000000000000
  R11  - 0000000000001020, R12 - FFFF82D040467CE8, R13 - 000000007FF0C1B8
  R14  - 000000007EA33328, R15 - 000000007EA332D8
  DS   - 0000000000000030, ES  - 0000000000000030, FS  - 0000000000000030
  GS   - 0000000000000030, SS  - 0000000000000030
  CR0  - 0000000080010033, CR2 - FFFF82D040467CE8, CR3 - 000000007FC01000
  CR4  - 0000000000000668, CR8 - 0000000000000000
  DR0  - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000
  DR3  - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400
  GDTR - 000000007F9DB000 0000000000000047, LDTR - 0000000000000000
  IDTR - 000000007F48E018 0000000000000FFF,   TR - 0000000000000000
  FXSAVE_STATE - 000000007FF0BDE0
  !!!! Find image based on IP(0x7EE21E9A) (No PDB)  (ImageBase=000000007EE20000, EntryPoint=000000007EE23935) !!!!

After the patch:
  Booting `XenServer (Serial)'Booting `XenServer (Serial)'
  Test message: Buffer too small
  BdsDxe: loading Boot0000 "UiApp" from Fv(7CB8BDC9-F8EB-4F34-AAEA-3EE4AF6516A1)/FvFile(462CAA21-7614-4503-836E-8AB6F4662331)
  BdsDxe: starting Boot0000 "UiApp" from Fv(7CB8BDC9-F8EB-4F34-AAEA-3EE4AF6516A1)/FvFile(462CAA21-7614-4503-836E-8AB6F4662331)

This partially rollback commit 00d5d5ce23e6.

Fixes: 9180f5365524 ("x86: add multiboot2 protocol support for EFI platforms")
Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2 weeks agoCI: Add Arm64/Arm32 MPU build jobs
Michal Orzel [Wed, 16 Apr 2025 08:21:30 +0000 (10:21 +0200)]
CI: Add Arm64/Arm32 MPU build jobs

Just like for RISCV and PPC, the earlier we enable the CI build the
better.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 weeks agoCI: Build with --prefix=/usr rather than setting LD_LIBRARY_PATH
Andrew Cooper [Tue, 15 Apr 2025 12:49:01 +0000 (13:49 +0100)]
CI: Build with --prefix=/usr rather than setting LD_LIBRARY_PATH

This also moves executables too.

I'm not sure why xilinx-smoke-dom0-x86_64.sh was overriding PATH too, as
/usr/local is clearly in PATH given the other tests, but drop that too.

No practical change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 weeks agoxen/arm32: mpu: Stubs to build MPU for arm32
Ayan Kumar Halder [Mon, 14 Apr 2025 16:45:14 +0000 (17:45 +0100)]
xen/arm32: mpu: Stubs to build MPU for arm32

Add stubs to enable compilation.

is_xen_heap_page() and is_xen_heap_mfn() are not implemented for arm32 MPU.
Thus, introduce the stubs for these functions in asm/mpu/mm.h and move the
original code to asm/mmu/mm.h (as it is used for arm32 MMU based system).

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Tested-by: Luca Fancellu <luca.fancellu@arm.com>
2 weeks agoxen/arm32: Create the same boot-time MPU regions as arm64
Ayan Kumar Halder [Mon, 14 Apr 2025 16:45:13 +0000 (17:45 +0100)]
xen/arm32: Create the same boot-time MPU regions as arm64

Create Boot-time MPU protection regions (similar to Armv8-R AArch64) for
Armv8-R AArch32.
Also, defined *_PRBAR macros for arm32. The only difference from arm64 is that
XN is 1-bit for arm32.
Define the system registers and macros in mpu/cpregs.h.

Introduce WRITE_SYSREG_ASM() to write to system registers in assembly.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Tested-by: Luca Fancellu <luca.fancellu@arm.com>
2 weeks agoxen/arm: Move some of the functions to common file
Ayan Kumar Halder [Mon, 14 Apr 2025 16:45:12 +0000 (17:45 +0100)]
xen/arm: Move some of the functions to common file

regions.inc is added to hold the common earlyboot MPU regions configurations
between arm64 and arm32.

prepare_xen_region, fail_insufficient_regions() will be used by both arm32 and
arm64. Thus, they have been moved to regions.inc.

*_PRBAR are moved to arm64/sysregs.h.
*_PRLAR are moved to regions.inc as they are common between arm32 and arm64.

Introduce WRITE_SYSREG_ASM to write to the system registers from regions.inc.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Tested-by: Luca Fancellu <luca.fancellu@arm.com>
2 weeks agox86/mm: account for the offset when performing subpage r/o MMIO access
Roger Pau Monne [Wed, 9 Apr 2025 16:51:31 +0000 (18:51 +0200)]
x86/mm: account for the offset when performing subpage r/o MMIO access

The current logic in subpage_mmio_write_emulate() doesn't take into account
the page offset, and always performs the writes at offset 0 (start of the
page).

Fix this by accounting for the offset before performing the write.

Fixes: 8847d6e23f97 ('x86/mm: add API for marking only part of a MMIO page read only')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
3 weeks agoxen/riscv: implement get_s_time()
Oleksii Kurochko [Tue, 15 Apr 2025 11:25:19 +0000 (13:25 +0200)]
xen/riscv: implement get_s_time()

Also tick_to_ns() is implemeted as it is used in get_s_time().

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich<jbeulich@suse.com>
3 weeks agoxen/config.h: Move BITS_PER_* definitions from asm/config.h to xen/config.h
Oleksii Kurochko [Tue, 15 Apr 2025 11:23:39 +0000 (13:23 +0200)]
xen/config.h: Move BITS_PER_* definitions from asm/config.h to xen/config.h

BITS_PER_* values can be defined in a common way using compiler-provided macros.
Thus, these definitions are moved to xen/config.h to reduce duplication across
architectures.

Additionally, *_BYTEORDER macros are removed, as BITS_PER_* values now come
directly from the compiler environment.

The arch_fls() implementation for Arm and PPC is updated to use BITS_PER_INT
instead of a hardcoded value of 32.

Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
3 weeks agoCI: Include microcode for x86 hardware jobs
Andrew Cooper [Fri, 11 Apr 2025 19:28:15 +0000 (20:28 +0100)]
CI: Include microcode for x86 hardware jobs

All the x86 hardware runners are out of date, to varying degrees, in terms of
microcode.

Microcode must be uncompressed and prepended to the initrd in order for Xen to
be able to use it during early boot.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
3 weeks agoCI: save toolstack artifact as cpio.gz
Marek Marczykowski-Górecki [Fri, 11 Apr 2025 20:32:19 +0000 (22:32 +0200)]
CI: save toolstack artifact as cpio.gz

This avoids the need to re-compress it in every test job.  This saves minutes
of wallclock time.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
3 weeks agoCI: Switch to new argo artefact
Andrew Cooper [Thu, 10 Apr 2025 20:39:16 +0000 (21:39 +0100)]
CI: Switch to new argo artefact

The argo artefact is now a cpio archive and can be appended to dom?-rootfs
directly, rather than being part of of the overlay.  Drop the
copy_dom?_files() functions.

xen-argo.ko has moved into the standard location, so update the insmod path.

No practical change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
3 weeks agoCI: remove now unused alpine-3.18-arm64-rootfs job and its container
Marek Marczykowski-Górecki [Fri, 11 Apr 2025 13:47:22 +0000 (15:47 +0200)]
CI: remove now unused alpine-3.18-arm64-rootfs job and its container

This got moved to test-artifacts.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Anthony PERARD <anthony.perard@vates.tech>
3 weeks agoCI: avoid repacking initrd as part of the test job
Marek Marczykowski-Górecki [Fri, 11 Apr 2025 20:32:17 +0000 (22:32 +0200)]
CI: avoid repacking initrd as part of the test job

Use the new test-artifacts which provide rootfs.cpio.gz rather than
initrd.tar.gz.  rootfs.cpio.gz also has all the necessary top-level
directories, and includes the rc_verbose setting, so these modifications can
be dropped.

Having that, do not repack the whole initrd, but only pack modified
files and rely on Linux handling of concatenated archives.
This allows packing just test-related files (which includes the whole
toolstack), instead of the whole initrd.

For xilinx-smoke-dom0-x86_64.sh, this involves instructing grub not to unzip
the archive, as doing so corrupts it.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
3 weeks agoCI: Rename intermediate artefacts in qemu-* scripts
Andrew Cooper [Sat, 12 Apr 2025 14:33:01 +0000 (15:33 +0100)]
CI: Rename intermediate artefacts in qemu-* scripts

Right now, we have initrd.cpio.gz as domU, and initrd.tar.gz as the base for
dom0.

Rename initrd.cpio.gz to domU-rootfs.cpio.gz, and xen-rootfs.cpio.gz to
dom0-rootfs.cpio.gz to make it clearer which is which.  Rename the VM from
test to domU.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
3 weeks agoCI: fix waiting for final test message (again)
Marek Marczykowski-Górecki [Sun, 13 Apr 2025 13:47:31 +0000 (15:47 +0200)]
CI: fix waiting for final test message (again)

The previous attempt has correct diagnosis, but added -notransfer flag
in a wrong place - it should be used in the first (outer) match out of
two, not the second (inner) one.

Fixes: 1e12cbd6af2c ("CI: fix waiting for final test message")
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
3 weeks agoxen/cpufreq: only set gov NULL when cpufreq_driver.setpolicy is NULL
Penny Zheng [Mon, 14 Apr 2025 11:10:55 +0000 (13:10 +0200)]
xen/cpufreq: only set gov NULL when cpufreq_driver.setpolicy is NULL

amd-cppc on active mode bypasses the scaling governor layer, and
provides its own P-state selection algorithms in hardware. Consequently,
when it is used, the driver's -> setpolicy() callback is invoked
to register per-CPU utilization update callbacks, not the ->target()
callback.

So, only when cpufreq_driver.setpolicy is NULL, we need to deliberately
set old gov as NULL to trigger the according gov starting.

Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
3 weeks agokconfig: introduce option to independently enable libfdt
Daniel P. Smith [Mon, 14 Apr 2025 11:08:56 +0000 (13:08 +0200)]
kconfig: introduce option to independently enable libfdt

Currently, the inclusion of libfdt is controlled by the CONFIG_HAS_DEVICE_TREE
kconfig flag. This flag also changes behavior in a few places, such as boot
module processing for XSM. To support the ability to include libfdt without
changing these behaviors, introduce CONFIG_LIBFDT. The inclusion of
libfdt is then moved under CONFIG_LIBFDT.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Denis Mukhin <dmukhin@ford.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
3 weeks agoCHANGELOG.md: Mention stack-protector feature
Volodymyr Babchuk [Mon, 14 Apr 2025 11:08:27 +0000 (13:08 +0200)]
CHANGELOG.md: Mention stack-protector feature

Stack protector is meant to be enabled on all architectures, but
currently it is tested (and enabled) only on ARM, so mention it in ARM
section.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Acked-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
3 weeks agoxen: arm: enable stack protector feature
Volodymyr Babchuk [Mon, 14 Apr 2025 11:07:38 +0000 (13:07 +0200)]
xen: arm: enable stack protector feature

Enable previously added CONFIG_STACK_PROTECTOR feature for ARM
platform. Initialize stack protector magic value very early, at the
very beginning of start_xen() function.

We want to do this early because prior to that
boot_stack_chk_guard_setup() call, default stack protector guard value
is used. While it is fine for general development and testing, it does
not provide highest security level, because potential attacker will
know the default value and can alter a payload, so correct stack
guard value will be placed in the correct position.

Apart from that argument, boot_stack_chk_guard_setup() should be
called prior to enabling secondary CPUs to avoid race with them.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Acked-by: Julien Grall <jgrall@amazon.com>
3 weeks agoxen: common: add ability to enable stack protector
Volodymyr Babchuk [Mon, 14 Apr 2025 11:07:12 +0000 (13:07 +0200)]
xen: common: add ability to enable stack protector

Both GCC and Clang support -fstack-protector feature, which add stack
canaries to functions where stack corruption is possible. This patch
makes general preparations to enable this feature on different
supported architectures:

 - Added CONFIG_HAS_STACK_PROTECTOR option so each architecture
   can enable this feature individually
 - Added user-selectable CONFIG_STACK_PROTECTOR option
 - Implemented code that sets up random stack canary and a basic
   handler for stack protector failures

Stack guard value is initialized in two phases:

1. Pre-defined randomly-selected value.

2. Own implementation of linear congruent random number generator. It
relies on get_cycles() being available very early. If get_cycles()
returns zero, it would leave pre-defined value from the previous step.

boot_stack_chk_guard_setup() is declared as always_inline to ensure
that it will not trigger stack protector by itself. And of course,
caller should ensure that stack protection code will not be reached
later. It is possible to call the same function from an ASM code by
introducing simple trampoline in stack-protector.c, but right now
there is no use case for such trampoline.

As __stack_chk_fail() is not called by Xen source code directly, and
only called by compiler-generated code, it does not needed to be
declared separately. So we need separate MISRA deviation for it.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
3 weeks agox86/mem-sharing: short-circuit p2m_is_shared() when MEM_SHARING=n
Jan Beulich [Mon, 14 Apr 2025 11:05:52 +0000 (13:05 +0200)]
x86/mem-sharing: short-circuit p2m_is_shared() when MEM_SHARING=n

Some of the uses of dom_cow aren't easily DCE-able (without extra
#ifdef-ary), and hence it being constantly NULL when MEM_SHARING=n
misguides Coverity into thinking that there may be a NULL deref in

        if ( p2m_is_shared(t) )
            d = dom_cow;

        if ( get_page(page, d) )
            return page;

(in get_page_from_mfn_and_type()). Help the situation by making
p2m_is_shared() be compile-time false when MEM_SHARING=n, thus also
permitting the compiler to DCE some other code.

Note that p2m_is_sharable() isn't used outside of mem_sharing.c, and
hence P2M_SHARABLE_TYPES can simply be left undefined when
MEM_SHARING=n.

Coverity ID: 1645573
Fixes: 79d91e178a1a ("dom_cow is needed for mem-sharing only")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Tamas K Lengyel <tamas@tklengyel.com>
3 weeks agox86/EFI: sanitize DLL characteristics in binary
Jan Beulich [Mon, 14 Apr 2025 11:04:28 +0000 (13:04 +0200)]
x86/EFI: sanitize DLL characteristics in binary

In GNU ld --disable-reloc-section implies --disable-dynamicbase (and
also --disable-high-entropy-va, just fyi). Therefore to yield
functionally identical binaries independent of whether mkreloc needs to
come into play, add --dynamicbase as well.

GNU ld further defaults to --high-entropy-va (along with --dynamicbase
and --nxcompat) unless "Cygwin-like". This seems wrong to me; that
default should be dependent upon "MinGW-like" instead; for the purpose
of building EFI binaries with a PE32+-capable ELF linker neither
"Cygwin-like" nor "MinGW-like" ought to be true. We certainly don't mean
to have this bit set in the DLL characteristics, so suppress its
setting.

Sadly while --high-entropy-va is supported by GNU ld 2.25,
--disable-high-entropy-va was introduced only in 2.36. Luckily the
defaulting to --high-entropy-va was also only introduced in 2.36. Plus
--disable-reloc-section was introduced precisely there, too. Hence
leverage the probing we do as to base relocation generation, to also
determine whether to pass --disable-high-entropy-va.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Daniel P. Smith <dpsmith@apertussolutions.com>
3 weeks agoCI: write whole etc/issue for domU initrd
Marek Marczykowski-Górecki [Fri, 11 Apr 2025 20:32:16 +0000 (22:32 +0200)]
CI: write whole etc/issue for domU initrd

Upcoming changes won't unpack original rootfs anymore, so sed on
existing file cannot be used. Override the whole file instead.

No functional change intended.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
3 weeks agoCI: switch qubes runners to use console.exp
Marek Marczykowski-Górecki [Fri, 11 Apr 2025 20:32:15 +0000 (22:32 +0200)]
CI: switch qubes runners to use console.exp

It appears as sometimes it takes more time for Xen even start booting,
mostly due to firmware and fetching large boot files by grub. In some
jobs the current timeout is pretty close to the actual time needed, and
sometimes (rarely for now) test fails due to timeout expiring in the
middle of dom0 booting. This will be happening more often if the
initramfs will grow (and with more complex tests).
This has been observed on some dom0pvh-hvm jobs, at least on runners hw3
and hw11.

Switch to using expect (console.exp) for more robust test output
handling. This allows waiting separately for Xen starting to boot and
then for the test to complete. For now, set both of those to 120s, which
pessimistically bumps timeout for the whole test to 240s (from 120s).

Add S3 handling to console.exp via SUSPEND_MSG + WAKEUP_CMD.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
3 weeks agoCI: fix waiting for final test message
Marek Marczykowski-Górecki [Fri, 11 Apr 2025 20:32:14 +0000 (22:32 +0200)]
CI: fix waiting for final test message

Expect normally discards initial part of its buffer after matching the
patter, before looking for the next one. If both PASSED and LOG_MSG
happen to be in the buffer at the same time, depending on their order,
only one will be matched and the waiting for the other will timeout.
Example expect -d output of this happening (parts eclipsed for brevity):

    expect: does "\r\r\r\nWelcome to Alpine Linux 3.18\r\r\r\n...\r\r\r\r\n(domU) + echo 'pci test passed'\r\r\r\r\n(domU) pci test passed\r\r\r\r..." (spawn_id exp4) match regular expression "pci test passed"? Gate "pci test passed"? gate=yes re=yes
    ...
    Gate keeper glob pattern for '\nWelcome to Alpine Linux' is '
    Welcome to Alpine Linux'. Activating booster.
    expect: does "'\r\r\r\r\n(domU) pci test passed\r\r\r\r\n(domU)  [ ok ]\r\r\r\r\n(domU)  [ ok ]\r\r\r\r\n(domU) \r\r\r\r\r\n(domU) domU Welcome to Alpine Linux 3.18\r\r\r\r\n(domU) \rKernel 6.6.56 on an x86_64 (/dev/hvc0)\r\r\r\r\n(domU) \r\r\r\r\r\n" (spawn_id exp4) match regular expression "\nWelcome to Alpine Linux"? Gate "\nWelcome to Alpine Linux"? gate=no

Fix this by using -notransfer flag to keep matched part in the buffer.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Andrew Cooper <andrew.cooper3@citix.com>
3 weeks agoCI: wait for Xen to start before waiting for test to complete
Marek Marczykowski-Górecki [Fri, 11 Apr 2025 20:32:13 +0000 (22:32 +0200)]
CI: wait for Xen to start before waiting for test to complete

Add additional stage in console output parsing - wait for first message
from Xen. The message is defined via BOOT_MSG variable. This has two
effects:
- distinguishes failing Xen to load at all from later test failures
- resets timeout when Xen starts loading

The latter is especially relevant for hardware tests where firmware +
network boot may take some time before Xen starts booting. The two-stage
timeout is more robust solution than increasing the overall timeout.
The issue has been observed on some dom0pvh-hvm jobs, at least on
runners hw3 and hw11. This patch is a first stage before qubes-x86-64.sh
is switched to use expect in the next stage.

While at it, consistently use 'expect -re' for all matches. This
especially allows matching newlines ("\n"), which will become relevant
in the next patch. And document variables used in console.exp.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
3 weeks agotootls/tests: introduce unit tests for rangesets
Roger Pau Monne [Thu, 3 Apr 2025 08:43:42 +0000 (10:43 +0200)]
tootls/tests: introduce unit tests for rangesets

Introduce some basic infrastructure for doing rangeset unit tests, and add
a few tests that ensure correctness of rangeset subtraction.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
3 weeks agoxen/rangeset: fix incorrect subtraction
Roger Pau Monne [Wed, 2 Apr 2025 16:50:46 +0000 (18:50 +0200)]
xen/rangeset: fix incorrect subtraction

Given the following rangset operation:

{ [0, 1], [4, 5] } - { [3, 4] }

The current rangeset logic will output a rangeset:

{ [0, 2], [5, 5] }

This is incorrect, and also has the undesirable property of being bogus in
a way that the resulting rangeset is expanded.

Fix this by making sure the bounds are correctly checked before modifying
the previous range.

Fixes: 484a058c4828 ('Add auto-destructing per-domain rangeset data structure...')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
3 weeks agoautomation/eclair: Remove bespoke service B.UNEVALEFF
Nicola Vetrini [Thu, 10 Apr 2025 19:32:14 +0000 (21:32 +0200)]
automation/eclair: Remove bespoke service B.UNEVALEFF

The Eclair runners in GitlabCI have been update.  This service is now
included, and redefining results in an error.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
3 weeks agoCI: Drop stale test-artifacts/alpine/3.18.dockerfile
Andrew Cooper [Mon, 7 Apr 2025 17:15:32 +0000 (18:15 +0100)]
CI: Drop stale test-artifacts/alpine/3.18.dockerfile

This should have been dropped too, as the authoritative copy lives in another
repo now.

Fixes: babe11b46c1a ("CI: Drop alpine-3.18-rootfs-export and use test-artefacts")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
3 weeks agoCI: Update ARM64 tests from Linux 6.6.74 to 6.6.86
Andrew Cooper [Wed, 9 Apr 2025 16:22:54 +0000 (17:22 +0100)]
CI: Update ARM64 tests from Linux 6.6.74 to 6.6.86

Switch over to test-artifacts.

Drop the associated export job, and dockerfile.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
3 weeks agoCI: Update x86 tests from Linux 6.1.19 to 6.6.56
Andrew Cooper [Wed, 9 Apr 2025 12:50:00 +0000 (13:50 +0100)]
CI: Update x86 tests from Linux 6.1.19 to 6.6.56

Linux 6.6.56 was already added to test-artifacts for the argo testing, and
this removes one moving part while cleaning things up.

Drop the associated export job, and dockerfile.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
3 weeks agox86/HVM: improve local variable use in hvm_hap_nested_page_fault()
Jan Beulich [Thu, 10 Apr 2025 08:56:49 +0000 (10:56 +0200)]
x86/HVM: improve local variable use in hvm_hap_nested_page_fault()

First, gfn can be set just once, rather than (conditionally) twice.

And then gfn can be used in two function calls, rather than re-
calculating the value there.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
3 weeks agoinclude: sort $(wildcard ...) results
Jan Beulich [Thu, 10 Apr 2025 08:56:29 +0000 (10:56 +0200)]
include: sort $(wildcard ...) results

The order of items is stored in .*.chk.cmd, and hence variations between
how items are ordered would result in re-invocation of the checking rule
during "make install-xen" despite that already having successfully run
earlier on. The difference can become noticable when building (as non-
root) and installing (as root) use different GNU make versions: In 3.82
the sorting was deliberately undone, just for it to be restored in 4.3.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
3 weeks agox86/domain: revisit logging in arch_domain_create()
Denis Mukhin [Wed, 9 Apr 2025 13:33:04 +0000 (15:33 +0200)]
x86/domain: revisit logging in arch_domain_create()

Use %pd in all logs issued from arch_domain_create() and reword some of the
messages.

Also, expand error message in arch_domain_create() under !emulation_flags_ok()
case to help debugging.

Signed-off-by: Denis Mukhin <dmukhin@ford.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
3 weeks agox86/boot: introduce domid field to struct boot_domain
Daniel P. Smith [Wed, 9 Apr 2025 13:32:26 +0000 (15:32 +0200)]
x86/boot: introduce domid field to struct boot_domain

boot_domain stores the domid until it is used to create (and allocate)
struct domain. d->domain_id is not available early enough.

boot_domain domids are initialized to DOMID_INVALID. If not overridden
by device tree, domids of DOMID_INVALID are assigned a valid value. The
domid will be optionally parsed from the device tree configuration.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Signed-off-by: Alejandro Vallejo <agarciav@amd.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
3 weeks agox86/boot: introduce boot domain
Daniel P. Smith [Wed, 9 Apr 2025 13:32:02 +0000 (15:32 +0200)]
x86/boot: introduce boot domain

To begin moving toward allowing the hypervisor to construct more than one
domain at boot, a container is needed for a domain's build information.
Introduce a new header, <xen/asm/bootdomain.h>, that contains the initial
struct boot_domain that encapsulate the build information for a domain.

Add a kernel and ramdisk boot module reference along with a struct domain
reference to the new struct boot_domain. This allows a struct boot_domain
reference to be the only parameter necessary to pass down through the domain
construction call chain.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
Signed-off-by: Alejandro Vallejo <agarciav@amd.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
3 weeks agox86emul/test: drop check for AVX512-4FMAPS
Jan Beulich [Wed, 9 Apr 2025 13:30:51 +0000 (15:30 +0200)]
x86emul/test: drop check for AVX512-4FMAPS

Use of Xeon Phi features was dropped earlier on; this one was overlooked.

Fixes: 85191cf32180 ("x86: drop Xeon Phi support")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
3 weeks agolibxc/PM: correct (not just) error handling in xc_get_cpufreq_para()
Jan Beulich [Wed, 9 Apr 2025 13:30:15 +0000 (15:30 +0200)]
libxc/PM: correct (not just) error handling in xc_get_cpufreq_para()

From their introduction all xc_hypercall_bounce_pre() uses, when they
failed, would properly cause exit from the function including cleanup,
yet without informing the caller of the failure. Purge the unlock_1
label for being both pointless and mis-named.

An earlier attempt to switch to the usual split between return value and
errno wasn't quite complete.

HWP work made the cleanup of the "available governors" array
conditional, neglecting the fact that the condition used may not be the
condition that was used to allocate the buffer (as the structure field
is updated upon getting back EAGAIN). Since cleanup can be done even if
no buffer was allocated, drop the conditional there again.

Fixes: 4513025a8790 ("libxc: convert sysctl interfaces over to hypercall buffers")
Amends: 73367cf3b4b4 ("libxc: Fix xc_pm API calls to return negative error and stash error in errno")
Fixes: 31e264c672bc ("pmstat&xenpm: Re-arrage for cpufreq union")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
3 weeks agox86/ucode: Extend warning about disabling digest check too
Andrew Cooper [Wed, 9 Apr 2025 10:36:40 +0000 (11:36 +0100)]
x86/ucode: Extend warning about disabling digest check too

This was missed by accident.

Fixes: b63951467e96 ("x86/ucode: Extend AMD digest checks to cover Zen5 CPUs")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
3 weeks agox86/hvm: remove unreachable MMCFG write emulation
Roger Pau Monne [Tue, 8 Apr 2025 08:58:09 +0000 (10:58 +0200)]
x86/hvm: remove unreachable MMCFG write emulation

The current implementation of PVH dom0 relies on vPCI to trap and handle
accesses to the MMCFG area.  Previous implementation of PVH dom0 (v1)
didn't have vPCI, and as a classic PV dom0, relied on the MMCFG range being
RO.  As such hvm_emulate_one_mmio() had to special case write accesses to
the MMCFG area.

With PVH dom0 using vPCI, and the MMCFG accesses being fully handled there,
hvm_emulate_one_mmio() should never handle accesses to MMCFG, making the
code effectively unreachable.

Remove it and leave an ASSERT to make sure MMCFG accesses never get into
hvm_emulate_one_mmio().  As a result of the removal of one of the users of
mmcfg_intercept_write(), the function can now be moved into the same
translation unit where it's solely used, allowing it to be made static and
effectively built only when PV support is enabled.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
3 weeks agoautomation/dockers: add to README how to rebuild all containers
Roger Pau Monne [Mon, 31 Mar 2025 16:56:01 +0000 (18:56 +0200)]
automation/dockers: add to README how to rebuild all containers

Document in the README how to rebuild all containers.  This is helpful when
populating a local docker registry for testing purposes.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
3 weeks agox86/ucode: Extend AMD digest checks to cover Zen5 CPUs
Andrew Cooper [Tue, 8 Apr 2025 16:09:15 +0000 (17:09 +0100)]
x86/ucode: Extend AMD digest checks to cover Zen5 CPUs

AMD have updated the SB-7033 advisory to include Zen5 CPUs.  Extend the digest
check to cover Zen5 too.

In practice, cover everything until further notice.

Observant readers may be wondering where the update to the digest list is.  At
the time of writing, no Zen5 patches are available via a verifiable channel.

Link: https://www.amd.com/en/resources/product-security/bulletin/amd-sb-7033.html
Fixes: 630e8875ab36 ("x86/ucode: Perform extra SHA2 checks on AMD Fam17h/19h microcode")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
4 weeks agoRevert "tools/libxl: search PATH for QEMU if `QEMU_XEN_PATH` is not absolute"
Jan Beulich [Tue, 8 Apr 2025 10:37:37 +0000 (12:37 +0200)]
Revert "tools/libxl: search PATH for QEMU if `QEMU_XEN_PATH` is not absolute"

This reverts commit f3ba5baf54de38efa1fb46c315b52bfaa7035292, for
breaking the build in gitlab CI.

4 weeks agoxen: x86: irq: initialize irq desc in create_irq()
Volodymyr Babchuk [Tue, 8 Apr 2025 07:40:39 +0000 (09:40 +0200)]
xen: x86: irq: initialize irq desc in create_irq()

While building xen with GCC 14.2.1 with "-fcondition-coverage" option
or with "-Og", the compiler produces a false positive warning:

  arch/x86/irq.c: In function ‘create_irq’:
  arch/x86/irq.c:281:11: error: ‘desc’ may be used uninitialized [-Werror=maybe-uninitialized]
    281 |     ret = init_one_irq_desc(desc);
        |           ^~~~~~~~~~~~~~~~~~~~~~~
  arch/x86/irq.c:269:22: note: ‘desc’ was declared here
    269 |     struct irq_desc *desc;
        |                      ^~~~
  cc1: all warnings being treated as errors
  make[2]: *** [Rules.mk:252: arch/x86/irq.o] Error 1

While we have signed/unsigned comparison both in "for" loop and in
"if" statement, this still can't lead to use of uninitialized "desc",
as either loop will be executed at least once, or the function will
return early. So this is a clearly false positive warning due to a
bug [1] in GCC.

Initialize "desc" with NULL to make GCC happy.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119665

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
4 weeks agolibxl{,u}: replace TOSTRING()
Jan Beulich [Tue, 8 Apr 2025 07:39:50 +0000 (09:39 +0200)]
libxl{,u}: replace TOSTRING()

Now that common-macros.h has STR() available, which is even slightly
more flexible, use that and drop the custom macros.

No difference in generated code (except for line numbers, of course,
where embedded in code/data).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
4 weeks agox86/MTRR: make hold_mtrr_updates_on_aps static and bool
Jan Beulich [Tue, 8 Apr 2025 07:39:11 +0000 (09:39 +0200)]
x86/MTRR: make hold_mtrr_updates_on_aps static and bool

It's not used outside of the CU defining it, and it is clearly of
boolean nature.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 weeks agoConfig.mk: correct gcc5 check
Jan Beulich [Tue, 8 Apr 2025 07:38:36 +0000 (09:38 +0200)]
Config.mk: correct gcc5 check

Passing the -dumpversion option to gcc may only print the major version
(my system 4.x.y printed major and minor, which in nowaday's scheme is
then indeed just 5 for 5.x, which in turn is what my secondary system
compiler does).

Fixes: 40458f752550 ("Xen: Update compiler baseline checks")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 weeks agotools/libxl: search PATH for QEMU if `QEMU_XEN_PATH` is not absolute
Hongbo [Tue, 8 Apr 2025 07:38:07 +0000 (09:38 +0200)]
tools/libxl: search PATH for QEMU if `QEMU_XEN_PATH` is not absolute

`QEMU_XEN_PATH` will be configured as `qemu-system-i386` with no clue where, if
`--with-system-qemu` is set without giving a path (as matched in the case `yes`
but not `*`). However, the existence of the executable is checked by `access()`,
that will not look for anywhere in $PATH but the current directory. And since it
is possible for `qemu-system-i386` (or any other configured values) to be
executed from PATH later, we'd better find that in PATH and return the full path
for the caller to check against.

Signed-off-by: Hongbo <hehongbo@mail.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
4 weeks agox86/cpu: Validate CPUID leaf 0x2 EDX output
Ahmed S. Darwish [Tue, 8 Apr 2025 07:37:38 +0000 (09:37 +0200)]
x86/cpu: Validate CPUID leaf 0x2 EDX output

CPUID leaf 0x2 emits one-byte descriptors in its four output registers
EAX, EBX, ECX, and EDX.  For these descriptors to be valid, the most
significant bit (MSB) of each register must be clear.

Leaf 0x2 parsing at intel.c only validated the MSBs of EAX, EBX, and
ECX, but left EDX unchecked.

Validate EDX's most-significant bit as well.

Fixes: 1aa6feb63bfd ("Port CPU setup code from Linux 2.6")
Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20250304085152.51092-3-darwi@linutronix.de
Use ARRAY_SIZE() though.

Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 1881148215c6
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 weeks agoxen: vm_event: do not do vm_event_op for an invalid domain
Volodymyr Babchuk [Tue, 8 Apr 2025 07:36:38 +0000 (09:36 +0200)]
xen: vm_event: do not do vm_event_op for an invalid domain

A privileged domain can issue XEN_DOMCTL_vm_event_op with
op->domain == DOMID_INVALID. In this case vm_event_domctl()
function will get NULL as the first parameter and this will
cause hypervisor panic, as it tries to derefer this pointer.

Fix the issue by checking if valid domain is passed in.

Fixes: 48b84249459f ("xen/vm-event: Drop unused u_domctl parameter from vm_event_domctl()")
Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
4 weeks agodocs: update xenstore migration stream definition
Juergen Gross [Tue, 8 Apr 2025 07:36:21 +0000 (09:36 +0200)]
docs: update xenstore migration stream definition

In order to close a race window for Xenstore live update when using
the new unique_id of domains, the migration stream needs to contain
this unique_id for each domain known by Xenstore.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Anthony PERARD <anthony.perard@vates.tech>
4 weeks agoCI: adjust resolving network interface into PCI device
Marek Marczykowski-Górecki [Mon, 7 Apr 2025 12:31:09 +0000 (14:31 +0200)]
CI: adjust resolving network interface into PCI device

Change how PCI device lookup is done to handle also USB devices, in
which case get the USB controller. Instead of taking basename of the
'device' symlink, resolve the full path (example:
/sys/devices/pci0000:00/0000:00:09.0/usb4/4-7/4-7:1.0) and take the
first part after pci0000:00. Theoretically it could be a bridge, but VM
has flat PCI topology.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
4 weeks agoCI: wait for the network interface in PCI passthrough tests
Marek Marczykowski-Górecki [Mon, 7 Apr 2025 12:31:07 +0000 (14:31 +0200)]
CI: wait for the network interface in PCI passthrough tests

The network driver initializes asynchronously, and it may not be ready
yet by the time the startup script is called. This is especially the
case for USB network adapter (where the PCI device is the USB
controller) in the upcoming runner.

Don't bother about separate timeout - test timeout will cover this part
too.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
4 weeks agoCI: consistently use DOCKER_CMD in makefiles
Marek Marczykowski-Górecki [Mon, 7 Apr 2025 12:31:06 +0000 (14:31 +0200)]
CI: consistently use DOCKER_CMD in makefiles

This allows rebuilding containers using podman too.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
4 weeks agoCI: increase verbosity of starting a domain
Marek Marczykowski-Górecki [Mon, 7 Apr 2025 12:31:05 +0000 (14:31 +0200)]
CI: increase verbosity of starting a domain

And start collecting qemu log earlier, so it isn't lost in case of a
timeout during domain startup.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 weeks agoCI: include domU kernel messages in the console output log
Marek Marczykowski-Górecki [Mon, 7 Apr 2025 12:31:04 +0000 (14:31 +0200)]
CI: include domU kernel messages in the console output log

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
4 weeks agoCI: enable XHCI console in Xen debug build on Alpine
Marek Marczykowski-Górecki [Mon, 7 Apr 2025 12:31:03 +0000 (14:31 +0200)]
CI: enable XHCI console in Xen debug build on Alpine

This build is used for hardware tests, and some runners use XHCI console

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
4 weeks agoCI: prevent grub unpacking initramfs
Marek Marczykowski-Górecki [Mon, 7 Apr 2025 12:31:01 +0000 (14:31 +0200)]
CI: prevent grub unpacking initramfs

It fails on larger initramfs (~250MB one) and sometimes even smaller
depending on memory size/memory map, let Linux do it.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
4 weeks agox86/AMD: Convert wrmsr_amd_safe() to use asm goto()
Andrew Cooper [Thu, 3 Apr 2025 14:37:23 +0000 (15:37 +0100)]
x86/AMD: Convert wrmsr_amd_safe() to use asm goto()

Bloat-o-meter reports:

  add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-29 (-29)
  Function                                     old     new   delta
  _probe_mask_msr                               99      94      -5
  init_amd                                    2418    2394     -24

but this under-reports because .fixup doesn't contain sized/typed symbols.
This also drops two "mov -EFAULT, %reg; jmp ...;" sequences too, so the net
saving is -50.

wrmsr_amd_safe()'s return value is only checked against 0 (if at all), and
because of this, the compiler can now avoid manifesting the 0/-EFAULT
constants entirely, and the %[fault] label simply lands on the right basic
block.

Convert to Xen style while rewriting.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>