]> xenbits.xensource.com Git - xen.git/log
xen.git
22 months agoxen/arm32: head: Add mising isb in switch_to_runtime_mapping()
Julien Grall [Tue, 4 Jul 2023 18:58:14 +0000 (19:58 +0100)]
xen/arm32: head: Add mising isb in switch_to_runtime_mapping()

Per the Arm Arm (ARM DDI 0406C.d A3.8.3):

"The DMB and DSB memory barriers affect reads and writes to the memory
system generated by load/store instructions and data or unified cache
maintenance operations being executed by the processor. Instruction
fetches or accesses caused by a hardware translation table access are
not explicit accesses."

The function switch_to_runtime_mapping() is responsible to map the
Xen at its runtime address if we were using the temporary area before
jumping returning using a runtime address. So we need to ensure the
'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes: fbd9b5fb4c26 ("xen/arm32: head: Remove restriction where to load Xen")
Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
22 months agoxen/arm32: head: Add missing isb in setup_fixmap()
Julien Grall [Tue, 4 Jul 2023 18:57:00 +0000 (19:57 +0100)]
xen/arm32: head: Add missing isb in setup_fixmap()

Per the Arm Arm (ARM DDI 0406C.d A3.8.3):

"The DMB and DSB memory barriers affect reads and writes to the memory
system generated by load/store instructions and data or unified cache
maintenance operations being executed by the processor. Instruction
fetches or accesses caused by a hardware translation table access are
not explicit accesses."

In setup_fixmap(), we write the fixmap area and may be used soon after,
for instance, to write to the UART. IOW, there could be hardware
translation table access. So we need to ensure the 'dsb' has completed
before continuing. Therefore add an 'isb'.

Fixes: e79999e587d7 ("xen/arm32: head: Remove 1:1 mapping as soon as it is not used")
Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
Tested-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
22 months agoxen/arm: Allow the user to build Xen with UBSAN
Julien Grall [Tue, 4 Jul 2023 18:31:13 +0000 (19:31 +0100)]
xen/arm: Allow the user to build Xen with UBSAN

UBSAN has been enabled a few years ago on x86 but was never
enabled on Arm because the final binary is bigger than 2MB (
the maximum we can currently handled).

With the recent rework, it is now possible to grow Xen over 2MB.
So there is no more roadblock to enable Xen other than increasing
the reserved area.

On my setup, for arm32, the final binaray was very close to 4MB.
Furthermore, one may want to enable UBSAN and GCOV which would put
the binary well-over 4MB (both features require for some space).
Therefore, increase the size to 8MB which should us some margin.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>o
22 months agoxen/arm: Rework the code mapping Xen to avoid relying on the size of Xen
Julien Grall [Tue, 4 Jul 2023 18:29:11 +0000 (19:29 +0100)]
xen/arm: Rework the code mapping Xen to avoid relying on the size of Xen

At the moment, the maximum size of Xen binary we can support is 2MB.
This is what we reserved in the virtual address but also what all
the code in Xen relies on as we only allocate one L3 page-table.

When feature like UBSAN (will be enabled in a follow-up patch) and GCOV
are enabled, the binary will be way over 2MB.

The code is now reworked so it doesn't rely on a specific size but
will instead look at the reversed size and compute the number of
page-table to allocate/map.

While at it, replace any reference to 4KB mappings with a more
generic word because the page-size may change in the future.

Also fix the typo s/tlb/tbl/ in code move in arm32/head.S

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
22 months agoxen/arm32: head: Don't map too much in boot_third
Julien Grall [Tue, 4 Jul 2023 18:27:40 +0000 (19:27 +0100)]
xen/arm32: head: Don't map too much in boot_third

At the moment, we are mapping the size of the reserved area for Xen
(i.e. 2MB) even if the binary is smaller. We don't exactly know what's
after Xen, so it is not a good idea to map more than necessary for a
couple of reasons:
    * We would need to use break-before-make if the extra PTE needs to
      be updated to point to another region
    * The extra area mapped may be mapped again by Xen with different
      memory attribute. This would result to attribute mismatch.

Therefore, rework the logic in create_page_tables() to map only what's
necessary.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
22 months agoxen/arm64: head: Don't map too much in boot_third
Julien Grall [Tue, 4 Jul 2023 18:26:13 +0000 (19:26 +0100)]
xen/arm64: head: Don't map too much in boot_third

At the moment, we are mapping the size of the reserved area for Xen
(i.e. 2MB) even if the binary is smaller. We don't exactly know what's
after Xen, so it is not a good idea to map more than necessary for a
couple of reasons:
    * We would need to use break-before-make if the extra PTE needs to
      be updated to point to another region
    * The extra area mapped may be mapped again by Xen with different
      memory attribute. This would result to attribute mismatch.

Therefore, rework the logic in create_page_tables() to map only what's
necessary. To simplify the logic, we also want to make sure _end
is page-aligned. So align the symbol in the linker and add an assert
to catch any change.

Lastly, take the opportunity to confirm that _start is equal to
XEN_VIRT_START as the assembly is using both interchangeably.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
22 months agoxen/arm: grant-table: Correct the prototype of the arch helpers
Julien Grall [Tue, 4 Jul 2023 18:21:42 +0000 (19:21 +0100)]
xen/arm: grant-table: Correct the prototype of the arch helpers

Both the stub and the x86 prototypes for replace_grant_host_mapping()
and create_grant_host_mapping() will define the first parameter (and
third for the former) as uint64_t. Yet Arm will define it as
'unsigned long'.

While there are no differences for 64-bit, for 32-bit it means
that the address should be truncated as 32-bit guest could support
up to 40-bit addresses.

So replace 'unsigned long' with 'uint64_t' for the first parameter
(and third parameter for replace_grant_host_mapping()).

Signed-off-by: Julien Grall <jgrall@amazon.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
Tested-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
22 months agoxen: Correct comments after renaming xen_{dom,sys}ctl_cpu_policy fields
Andrew Cooper [Thu, 29 Jun 2023 10:23:27 +0000 (11:23 +0100)]
xen: Correct comments after renaming xen_{dom,sys}ctl_cpu_policy fields

Fixes: 21e3ef57e040 ("x86: Rename {domctl,sysctl}.cpu_policy.{cpuid,msr}_policy fields")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
22 months agox86/vlapic: Change parameter names in function definitions
Federico Serafini [Thu, 29 Jun 2023 15:55:31 +0000 (17:55 +0200)]
x86/vlapic: Change parameter names in function definitions

Change parameter names in guest_wrmsr_x2apic() and
guest_wrmsr_apic_base() definitions in order to:
1) keep consistency with parameter names used in guest_* function
   declarations;
2) fix violations of MISRA C:2012 Rule 8.3.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agox86/hvm: Change parameter names of nestedhvm_vcpu_iomap_get() definition
Federico Serafini [Thu, 29 Jun 2023 15:55:30 +0000 (17:55 +0200)]
x86/hvm: Change parameter names of nestedhvm_vcpu_iomap_get() definition

Change parameter names of nestedhvm_vcpu_iomap_get() definition to
those used in the function declaration in order to:
1) improve readability;
2) fix violations of MISRA C:2012 Rule 8.3.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agox86/hvm: Swap parameter names of hvm_copy_context_and_params() declaration
Federico Serafini [Thu, 29 Jun 2023 15:55:29 +0000 (17:55 +0200)]
x86/hvm: Swap parameter names of hvm_copy_context_and_params() declaration

Swap parameter names 'src' and 'dst' of hvm_copy_context_and_params()
declaration for consistency with the corresponding definition and the
uses of such function.
Also, this fixes a violation of MISRA C:2012 Rule 8.3.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agox86: Add Kconfig option to require NX bit support
Alejandro Vallejo [Thu, 29 Jun 2023 12:17:13 +0000 (13:17 +0100)]
x86: Add Kconfig option to require NX bit support

This option hardens Xen by forcing it to write secure (NX-enhanced) PTEs
regardless of the runtime NX feature bit in boot_cpu_data. This prevents an
attacker with partial write support from affecting Xen's PTE generation
logic by overriding the NX feature flag. The patch asserts support for the
NX bit in PTEs at boot time and if so short-circuits the cpu_has_nx macro
to 1.

It has the nice benefit of replacing many instances of runtime checks with
folded constants. This has several knock-on effects that improve codegen,
saving 2.5KiB off the text section.

The config option defaults to OFF for compatibility with previous
behaviour.

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agox86/boot: Clear XD_DISABLE from the early boot path
Alejandro Vallejo [Thu, 29 Jun 2023 12:17:12 +0000 (13:17 +0100)]
x86/boot: Clear XD_DISABLE from the early boot path

Intel CPUs have a bit in MSR_IA32_MISC_ENABLE that may prevent the NX bit
from being advertised. Clear it unconditionally if we can't find the NX
feature right away on boot.

The conditions for the MSR being read on early boot are (in this order):

* Long Mode is supported
* NX isn't advertised
* The vendor is Intel

The order of checks has been chosen carefully so a virtualized Xen on a
hypervisor that doesn't emulate that MSR (but supports NX) doesn't triple
fault trying to access the non-existing MSR.

With that done, we can remove the XD_DISABLE checks in the intel-specific
init path (as they are already done in early assembly). Keep a printk to
highlight the fact that NX was forcefully enabled.

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agotools: Add __AC() macro to common-macros.h
Alejandro Vallejo [Thu, 29 Jun 2023 12:17:11 +0000 (13:17 +0100)]
tools: Add __AC() macro to common-macros.h

Currently libxl and the x86-emulator tests carry their own versions. Factor
those out into the common macros header so every library can make use of
it. This is required so the following patch can add this macro to a header
used both in Xen and tools/libs.

No functional change.

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months ago{x86,arm}/mm.c: Make populate_pt_range __init
George Dunlap [Tue, 6 Oct 2020 11:03:52 +0000 (12:03 +0100)]
{x86,arm}/mm.c: Make populate_pt_range __init

It's only called from another __init function.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agoxenalyze: Basic TRC_HVM_EMUL handling
George Dunlap [Fri, 30 Jun 2023 10:25:34 +0000 (11:25 +0100)]
xenalyze: Basic TRC_HVM_EMUL handling

For now, mainly just do volume analysis and get rid of the warnings.

Signed-off-by: George Dunlap <george.dunlap@cloud.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
22 months agoxenalyze: Handle start-of-day ->RUNNING transitions
George Dunlap [Fri, 30 Jun 2023 10:25:33 +0000 (11:25 +0100)]
xenalyze: Handle start-of-day ->RUNNING transitions

A recent xentrace highlighted an unhandled corner case in the vcpu
"start-of-day" logic, if the trace starts after the last running ->
non-running transition, but before the first non-running -> running
transition.  Because start-of-day wasn't handled, vcpu_next_update()
was expecting p->current to be NULL, and tripping out with the
following error message when it wasn't:

vcpu_next_update: FATAL: p->current not NULL! (d32768dv$p, runstate RUNSTATE_INIT)

where 32768 is the DEFAULT_DOMAIN, and $p is the pcpu number.

Instead of calling vcpu_start() piecemeal throughout
sched_runstate_process(), call it at the top of the function if the
vcpu in question is still in RUNSTATE_INIT, so that we can handle all
the cases in one place.

Sketch out at the top of the function all cases which we need to
handle, and what to do in those cases.  Some transitions tell us where
v is running; some transitions tell us about what is (or is not)
running on p; some transitions tell us neither.

If a transition tells us where v is now running, update its state;
otherwise leave it in INIT, in order to avoid having to deal with TSC
skew on start-up.

If a transition tells us what is or is not running on p, update
p->current (either to v or NULL).  Otherwise leave it alone.

If neither, do nothing.

Reifying those rules:

- If we're continuing to run, set v to RUNNING, and use p->first_tsc
  as the runstate time.

- If we're starting to run, set v to RUNNING, and use ri->tsc as the
  runstate time.

- If v is being deschedled, leave v in the INIT state to avoid dealing
  with TSC skew; but set p->current to NULL so that whatever is
  scheduled next won't trigger the assert in vcpu_next_update().

- If a vcpu is waking up (switching from one non-runnable state to
  another non-runnable state), leave v in INIT, and p in whatever
  state it's in (which may be the default domain, or some other vcpu
  which has already run).

While here, fix the comment above vcpu_start; it's called when the
vcpu state is INIT, not when current is the default domain.

Signed-off-by: George Dunlap <george.dunlap@cloud.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
22 months agotools/xenstore: remove unused stuff from list.h
Juergen Gross [Tue, 27 Jun 2023 12:27:50 +0000 (14:27 +0200)]
tools/xenstore: remove unused stuff from list.h

Remove the hlist defines/functions and the rcu related functions from
tools/xenstore/list.h, as they are not used.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agotools/xenstore: split out rest of live update control code
Juergen Gross [Tue, 27 Jun 2023 12:27:49 +0000 (14:27 +0200)]
tools/xenstore: split out rest of live update control code

Move the rest of live update related code from xenstored_control.c to
a dedicated new source file.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agotools/xenstore: split out environment specific live update code
Juergen Gross [Tue, 27 Jun 2023 12:27:48 +0000 (14:27 +0200)]
tools/xenstore: split out environment specific live update code

Instead of using #ifdef in xenstored_control.c split out the code of
environment specific functions (daemon or Mini-OS) to dedicated source
files.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
22 months agotools/xenstore: replace xs_lib.c with a header
Juergen Gross [Tue, 27 Jun 2023 12:27:47 +0000 (14:27 +0200)]
tools/xenstore: replace xs_lib.c with a header

Instead of including the same small C source in multiple binaries from
2 source directories, use a header file with inline functions as a
replacement.

As some of the functions are exported by libxenstore, rename the inline
functions from xs_*() do xenstore_*() and add xs_*() wrappers to
libxenstore.

With that no sources required to build libxenstore are left in
tools/xenstore, so the file COPYING can be removed now.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agotools/xenstore: remove no longer needed functions from xs_lib.c
Juergen Gross [Tue, 27 Jun 2023 12:27:46 +0000 (14:27 +0200)]
tools/xenstore: remove no longer needed functions from xs_lib.c

xs_daemon_tdb() in xs_lib.c is no longer used at all, so it can be
removed. xs_domain_dev() and xs_write_all() are not used by xenstored,
so they can be moved to tools/libs/store/xs.c.

xs_daemon_rootdir() is used by xenstored only and it only calls
xs_daemon_rundir(), so replace its use cases with xs_daemon_rundir()
and remove it from xs_lib.c.

xs_daemon_socket_ro() is needed in libxenstore only, so move it to
tools/libs/store/xs.c.

Move functions used by xenstore-client only to xenstore_client.c.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/arm: arm32: Allow Xen to boot on unidentified CPUs
Ayan Kumar Halder [Mon, 26 Jun 2023 18:14:44 +0000 (19:14 +0100)]
xen/arm: arm32: Allow Xen to boot on unidentified CPUs

Currently if the processor id is not identified (ie it is missing in proc-v7.S)
, then Xen boot fails quite early.
We have removed this restriction as for some CPUs (eg Cortex-R52), there isn't
any special initialization required.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
22 months agoxen/arm32: vfp: Add missing U for shifted constant
Julien Grall [Thu, 29 Jun 2023 19:57:10 +0000 (20:57 +0100)]
xen/arm32: vfp: Add missing U for shifted constant

When enabling UBSAN on arm32, the following splat will be printed:

(XEN) ================================================================================
(XEN) UBSAN: Undefined behaviour in arch/arm/arm32/vfp.c:75:22
(XEN) left shift of 255 by 24 places cannot be represented in type 'int'

This is referring to the shift in FPSID_IMPLEMENTER_MASK. While we could
only add the U to the value shift there, it would be better to be
consistent and also add it for every value shifted.

This should also addressing MISRA Rule 7.2:

    A "u" or "U" suffix shall be applied to all integer constants that
    are represented in an unsigned type

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
22 months agoxen/arm64: head: Rework PRINT() to work when the string is not withing +/- 1MB
Julien Grall [Thu, 29 Jun 2023 19:56:18 +0000 (20:56 +0100)]
xen/arm64: head: Rework PRINT() to work when the string is not withing +/- 1MB

The instruction ADR is able to load an address of a symbol that is
within the range +/- 1 MB of the instruction.

While today Xen is quite small (~1MB), it could grow up to 2MB in the
current setup. So there is no guarantee that the instruction can
load the string address (stored in rodata).

So replace the instruction ADR with the pseudo-instruction ADR_L
which is able to handle symbol within the range +/- 4GB.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
22 months agoxen/arm64: entry: Don't jump outside of an alternative
Julien Grall [Thu, 29 Jun 2023 19:55:18 +0000 (20:55 +0100)]
xen/arm64: entry: Don't jump outside of an alternative

The instruction CBNZ can only jump to a pc-relative that is in the
range +/- 1MB.

Alternative instructions replacement are living in a separate
subsection of the init section. This is usually placed towards
the end of the linker. Whereas text is towards the beginning.

While today Xen is quite small (~1MB), it could grow up to
2MB in the current setup. So there is no guarantee that the
target address in the text section will be within the range +/-
1MB of the CBNZ in alternative section.

The easiest solution is to have the target address within the
same section of the alternative. This means that we need to
duplicate a couple of instructions.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
----

I couldn't come up with a solution that would not change the number
of instructions executed in the entry path.

22 months agoxen/arm32: head: Remove 'r6' from the clobber list of create_page_tables()
Julien Grall [Thu, 29 Jun 2023 19:47:12 +0000 (20:47 +0100)]
xen/arm32: head: Remove 'r6' from the clobber list of create_page_tables()

Since commit 62529f16c8a2 ("xen/arm32: head: Use a page mapping for the
1:1 mapping in create_page_tables()"), the register 'r6' is not used
anymore within create_page_tables(). So remove it from the documentation.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
22 months agoxen/arm: Check Xen size when linking
Julien Grall [Thu, 29 Jun 2023 19:44:17 +0000 (20:44 +0100)]
xen/arm: Check Xen size when linking

The linker will happily link Xen if it is bigger than what we can handle
(e.g 2MB). This will result to unexpected failure after boot.

This unexpected failure can be prevented by forbidding linking if Xen is
bigger than the area we reserved.

Signed-off-by: Julien Grall <julien@xen.org>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Tested-by: Henry Wang <Henry.Wang@arm.com>
22 months agoxen/arm: tlbflush: fix violations of MISRA C:2012 Rule 3.1
Nicola Vetrini [Thu, 29 Jun 2023 10:06:15 +0000 (12:06 +0200)]
xen/arm: tlbflush: fix violations of MISRA C:2012 Rule 3.1

In the files `xen/arch/arm/include/asm/arm(32|64)/flushtlb.h' there are a
few occurrences of nested '//' character sequences inside C-style comment
blocks, which violate Rule 3.1. The patch aims to resolve those by changing
the inner comments to arm asm comments, delimited by ';' instead.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
22 months agodocs/misra: rules: Remove incorrect deviation guidance
Michal Orzel [Wed, 28 Jun 2023 08:37:01 +0000 (10:37 +0200)]
docs/misra: rules: Remove incorrect deviation guidance

It creates confusion since the new format of documenting violations can
be found in: docs/misra/documenting-violations.rst.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
22 months agodocs/misra: add Rules 8.2, 8.3, 8.14
Stefano Stabellini [Wed, 21 Jun 2023 01:26:18 +0000 (18:26 -0700)]
docs/misra: add Rules 8.2, 8.3, 8.14

Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
22 months agoxen/arm: change parameter names in replace_grant_host_mapping().
Federico Serafini [Mon, 26 Jun 2023 09:52:18 +0000 (11:52 +0200)]
xen/arm: change parameter names in replace_grant_host_mapping().

In the current version of replace_grant_host_mapping() function, the
declaration (correctly) uses the parameter names 'gpaddr' and
'new_gpaddr', while the definition uses the parameter names 'addr' and
'new_addr'.
Change the parameter names of the definition to 'gpaddr' and
'new_gpaddr' so that it is clear what type of address is expected and
violations of MISRA C:2012 Rule 8.3 are fixed.

In both declaration and definition of function
replace_grant_host_mapping() change the parameter name 'mfn' to 'frame',
thus improving readability and keeping consistency with name used in
create_grant_host_mapping().

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/arm: make parameter names of function declarations consistent.
Federico Serafini [Mon, 26 Jun 2023 09:52:17 +0000 (11:52 +0200)]
xen/arm: make parameter names of function declarations consistent.

Change the parameter names of function declarations to be consistent
with the names used in the corresponding function definitions, thus
fixing violations of MISRA C:2012 Rule 8.3.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/arm: vgic: change parameter name in 'init' and 'free' functions.
Federico Serafini [Mon, 26 Jun 2023 09:52:16 +0000 (11:52 +0200)]
xen/arm: vgic: change parameter name in 'init' and 'free' functions.

In the current versions of vcpu_vgic_init() and vcpu_vgic_free(),
the declarations (correctly) use the parameter name 'v' while the
corresponding definitions use the parameter name 'vcpu'.
Since it is common to use 'v' to denote a vCPU, change the parameter
name 'vcpu' of function definitions to 'v', thus fixing violations of
MISRA C:2012 Rule 8.3.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/arm: change parameter name 'pa' in ioremap_addr() definition.
Federico Serafini [Mon, 26 Jun 2023 09:52:15 +0000 (11:52 +0200)]
xen/arm: change parameter name 'pa' in ioremap_addr() definition.

In the current version of ioremap_addr() function, the declaration
uses the parameter name 'start' (consistenly with the other ioremap_*
function declarations), while the definition uses the parameter name
'pa'.
Change the parameter name 'pa' of function definition to 'start', thus
fixing a violation of MISRA C:2012 Rule 8.3 and keeping the consistency
with other ioremap_* functions.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/arm: change parameter name 'vcpu' in domain() function definition.
Federico Serafini [Mon, 26 Jun 2023 09:52:14 +0000 (11:52 +0200)]
xen/arm: change parameter name 'vcpu' in domain() function definition.

In the current version of domain() function, the declaration
(correctly) uses the parameter name 'v' while the definition uses the
parameter name 'vcpu'.
Since it is common to use 'v' to denote a vCPU, change the parameter
name 'vcpu' of function definition to 'v', thus fixing a violation of
MISRA C:2012 Rule 8.3.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/arm: change names in function access_guest_memory_by_ipa().
Federico Serafini [Mon, 26 Jun 2023 09:52:13 +0000 (11:52 +0200)]
xen/arm: change names in function access_guest_memory_by_ipa().

Change the function name 'access_guest_memory_by_ipa' to
'access_guest_memory_by_gpa' and change its formal parameter name from
'ipa' to 'gpa' because of the following:
1) 'gpa' is used more frequently and therefore is preferable;
2) changing parameter name makes the declaration consistent with the
   corresponding definition thus fixing a violation of MISRA C:2012 Rule
   8.3.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
22 months agox86/vpmu: Simplify is_pmc_quirk
Andrew Cooper [Tue, 20 Jun 2023 16:36:19 +0000 (17:36 +0100)]
x86/vpmu: Simplify is_pmc_quirk

This should be static, and there's no need for a separate (non-init, even)
function to perform a simple equality test.  Drop the is_ prefix which is
gramatically questionable, and make it __ro_after_init.

Leave a TODO, because the behaviour is definitely wrong to be applied to all
modern Intel CPUs.  The question has been raised on xen-devel previously
without conclusion.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
22 months agoxen/decompress: Drop bool_t and use bool instead
Andrew Cooper [Tue, 20 Jun 2023 16:43:55 +0000 (17:43 +0100)]
xen/decompress: Drop bool_t and use bool instead

In particular, the libxg wrapper for unxz.c uses char for bool_t which is a
major antipattern.  Luckily the code doesn't suffer from truncated values.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
22 months agoautomation: Fix KBUILD_DEFCONFIG for *ppc64le jobs
Shawn Anastasio [Wed, 21 Jun 2023 16:59:51 +0000 (11:59 -0500)]
automation: Fix KBUILD_DEFCONFIG for *ppc64le jobs

During an iteration of the initial ppc64le support patchset the default
defconfig was renamed but build.yaml wasn't updated to reflect this. Fix
it up.

Signed-off-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agoautomation: Add QEMU to bullseye-ppc64le
Shawn Anastasio [Wed, 21 Jun 2023 16:59:50 +0000 (11:59 -0500)]
automation: Add QEMU to bullseye-ppc64le

Add qemu-system-ppc package to the bullseye-ppc64le container to allow
running smoke tests in CI.

Signed-off-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agomaintainers: Add ppc64 maintainer
Shawn Anastasio [Tue, 20 Jun 2023 18:12:49 +0000 (13:12 -0500)]
maintainers: Add ppc64 maintainer

Signed-off-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agoautomation: Add ppc64le cross-build jobs
Shawn Anastasio [Tue, 20 Jun 2023 18:12:48 +0000 (13:12 -0500)]
automation: Add ppc64le cross-build jobs

Add build jobs to cross-compile Xen for ppc64le.

Signed-off-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agoxen: Add files needed for minimal ppc64le build
Shawn Anastasio [Tue, 20 Jun 2023 18:12:47 +0000 (13:12 -0500)]
xen: Add files needed for minimal ppc64le build

Add the build system changes required to build for ppc64le (POWER8+).
As of now the resulting image simply boots to an infinite loop.

$ make XEN_TARGET_ARCH=ppc64 -C xen build

This port targets POWER8+ CPUs running in Little Endian mode specifically,
and does not boot on older machines. Additionally, this initial skeleton
only implements the PaPR/pseries boot protocol which allows it to be
booted in a standard QEMU virtual machine:

$ qemu-system-ppc64 -M pseries-5.2 -m 256M -kernel xen/xen

Signed-off-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agobuild: Drop CONFIG_$ARCH_$(XEN_OS) definitions
Andrew Cooper [Mon, 19 Jun 2023 17:54:18 +0000 (18:54 +0100)]
build: Drop CONFIG_$ARCH_$(XEN_OS) definitions

These aren't used, and are not obvious useful either.

tools/ does have some logic which works on $(XEN_OS) directly, and some on
CONFIG_$(XEN_OS) too, but this isn't how we typically refer to things.

The only user ever of this scheme (AFAICT) was introduced in
c0fd920e987 (2006) and deleted in fa2244104b4 (2010).

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Tested-by: Jiamei Xie <jiamei.xie@arm.com>
22 months agox86/vPIT: account for "counter stopped" time
Jan Beulich [Wed, 21 Jun 2023 11:45:36 +0000 (13:45 +0200)]
x86/vPIT: account for "counter stopped" time

For an approach like that used in "x86: detect PIT aliasing on ports
other than 0x4[0-3]" [1] to work, channel 2 may not (appear to) continue
counting when "gate" is low. Record the time when "gate" goes low, and
adjust pit_get_{count,out}() accordingly. Additionally for most of the
modes a rising edge of "gate" doesn't mean just "resume counting", but
"initiate counting", i.e. specifically the reloading of the counter with
its init value.

No special handling for state save/load: See the comment near the end of
pit_load().

Along with introducing the get_count() helper to have the calculations
(and the locking check) in a single place, switch pit_get_count()'s d,
counter, and return type to unsigned int.

[1] https://lists.xen.org/archives/html/xen-devel/2023-05/msg00898.html

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
22 months agox86/vPIT: re-order functions
Jan Beulich [Wed, 21 Jun 2023 11:44:43 +0000 (13:44 +0200)]
x86/vPIT: re-order functions

To avoid the need for a forward declaration of pit_load_count() in a
subsequent change, move it earlier in the file (along with its helper
callback).

While moving the code, address a few style issues.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
22 months agox86: Use printk_once() instead of opencoding it
Andrew Cooper [Wed, 10 May 2023 19:21:12 +0000 (20:21 +0100)]
x86: Use printk_once() instead of opencoding it

Technically our helper post-dates all of these examples, but it's good cleanup
nevertheless.  None of these examples should be using fully locked
test_and_set_bool() in the first place.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
22 months agoxen/evtchn: Purge ERROR_EXIT{,_DOM}()
Andrew Cooper [Tue, 13 Jun 2023 16:06:47 +0000 (17:06 +0100)]
xen/evtchn: Purge ERROR_EXIT{,_DOM}()

These interfere with code legibility by hiding control flow.  Expand and drop
them.

 * Rearrange the order of actions to write into rc, then render rc in the
   gdprintk().
 * Drop redundant "rc = rc" assignments
 * Switch to using %pd for rendering domains

As a side effect, this fixes several violations of MISRA rule 2.1 (dead code -
the while() following a goto).

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/arm: pl011: Add SBSA UART device-tree support
Michal Orzel [Wed, 7 Jun 2023 09:27:27 +0000 (11:27 +0200)]
xen/arm: pl011: Add SBSA UART device-tree support

We already have all the bits necessary in PL011 driver to support SBSA
UART thanks to commit 032ea8c736d10f02672863c6e369338f948f7ed8 that
enabled it for ACPI. Plumb in the remaining part for device-tree boot:
 - add arm,sbsa-uart compatible to pl011_dt_match (no need for a separate
   struct and DT_DEVICE_START as SBSA is a subset of PL011),
 - from pl011_dt_uart_init(), check for SBSA UART compatible to determine
   the UART type in use.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Tested-by: Henry Wang <Henry.Wang@arm.com>
22 months agoxen/arm: pl011: Use correct accessors
Michal Orzel [Wed, 7 Jun 2023 09:27:26 +0000 (11:27 +0200)]
xen/arm: pl011: Use correct accessors

At the moment, we use 32-bit only accessors (i.e. readl/writel) to match
the SBSA v2.x requirement. This should not be the default case for normal
PL011 where accesses shall be 8/16-bit (max register size is 16-bit).
There are however implementations of this UART that can only handle 32-bit
MMIO. This is advertised by dt property "reg-io-width" set to 4.

Introduce new struct pl011 member mmio32 and replace pl011_{read/write}
macros with static inline helpers that use 32-bit or 16-bit accessors
(largest-common not to end up using different ones depending on the actual
register size) according to mmio32 value. By default this property is set
to false, unless:
 - reg-io-width is specified with value 4,
 - SBSA UART is in use.

For now, no changes done for ACPI due to lack of testing possibilities
(i.e. current behavior maintained resulting in 32-bit accesses).

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Tested-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
22 months agoxen/arm: debug-pl011: Add support for 32-bit only MMIO
Michal Orzel [Wed, 7 Jun 2023 09:27:25 +0000 (11:27 +0200)]
xen/arm: debug-pl011: Add support for 32-bit only MMIO

There are implementations of PL011 that can only handle 32-bit accesses
as oppose to the normal behavior where accesses are 8/16-bit wide. This
is usually advertised by setting a dt property 'reg-io-width' to 4.

Introduce CONFIG_EARLY_UART_PL011_MMIO32 Kconfig option to be able to
enable the use of 32-bit only accessors in PL011 early printk code.
Define macros PL011_{STRH,STRB,LDRH} to distinguish accessors for normal
case from 32-bit MMIO one and use them in arm32/arm64 pl011 early printk
code.

Update documentation accordingly.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Tested-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
22 months agoxen/arm: debug-pl011: Use correct accessors
Michal Orzel [Wed, 7 Jun 2023 09:27:24 +0000 (11:27 +0200)]
xen/arm: debug-pl011: Use correct accessors

Although most PL011 UARTs can cope with 32-bit accesses, some of the old
legacy ones might not. PL011 registers are 8/16-bit wide and this shall
be perceived as the normal behavior.

Modify early printk pl011 code for arm32/arm64 to use the correct
accessors depending on the register size (refer ARM DDI 0183G, Table 3.1).

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Tested-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
22 months agoxen/misra: add rules 1.4 and 2.1
Stefano Stabellini [Thu, 15 Jun 2023 21:27:16 +0000 (14:27 -0700)]
xen/misra: add rules 1.4 and 2.1

Also add a comment at the top of the file to say rules.rst could be
changed.

Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
22 months agodocs/misra: new rules addition
Stefano Stabellini [Thu, 15 Jun 2023 21:19:22 +0000 (14:19 -0700)]
docs/misra: new rules addition

For Dir 1.1, a document describing all implementation-defined behaviour
(i.e. gcc-specific behavior) will be added to docs/misra, also including
implementation-specific (gcc-specific) appropriate types for bit-field
relevant to Rule 6.1.

Rule 21.21 is lacking an example on gitlab but the rule is
straightforward: we don't use stdlib at all in Xen.

Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
22 months agox86/boot: Clean up early error asm
Andrew Cooper [Fri, 16 Jun 2023 16:28:21 +0000 (17:28 +0100)]
x86/boot: Clean up early error asm

The asm forming early error handling is a mix of local and non-local symbols,
and has some pointless comments.  Drop the "# Error message" comments,
tweaking the style on modified lines, and make the symbols local.

However, leave behind one real symbol so this logic disassembles nicely
without merging in to acpi_boot_init(), which is the thing that happens to be
immediately prior in my build.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
22 months agoxen/riscv: introduce reset_stack() function
Oleksii Kurochko [Mon, 19 Jun 2023 13:47:37 +0000 (15:47 +0200)]
xen/riscv: introduce reset_stack() function

The reason for reset_stack() introduction is that stack should be
reset twice:
1. Before jumping to C world at the start of _start() function.
2. After jumping from 1:1 mapping world.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
22 months agoxen/riscv: add .sbss section to .bss
Oleksii Kurochko [Mon, 19 Jun 2023 13:47:23 +0000 (15:47 +0200)]
xen/riscv: add .sbss section to .bss

Sometimes variables are located in .sbss section but it won't
be mapped after MMU will be enabled.
To avoid MMU failures .sbss should be mapped

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
22 months agoConfig.mk: update OVMF to edk2-stable202305
Anthony PERARD [Mon, 19 Jun 2023 13:47:05 +0000 (15:47 +0200)]
Config.mk: update OVMF to edk2-stable202305

Update to OVMF's latest stable tag.

This is been prompt by trying to build Xen on Debian Bookworm,
where edk2-stable202108 doesn't build. Also, it's been too long since
the last update.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
22 months agoiommu/vtd: fix address translation for leaf entries
Roger Pau Monné [Mon, 19 Jun 2023 13:46:03 +0000 (15:46 +0200)]
iommu/vtd: fix address translation for leaf entries

Fix two issues related to leaf address lookups in VT-d:

* When translating an address that falls inside of a superpage in the
  IOMMU page tables the fetching of the PTE value wasn't masking of the
  contiguous related data, which caused the returned data to be
  corrupt as it would contain bits that the caller would interpret as
  part of the address.

* When the requested leaf address wasn't mapped by a superpage the
  returned value wouldn't have any of the low 12 bits set, thus missing
  the permission bits expected by the caller.

Take the opportunity to also adjust the function comment to note that
when returning the full PTE the bits above PADDR_BITS are removed.

Fixes: c71e55501a61 ('VT-d: have callers specify the target level for page table walks')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
22 months agoSUPPORT.md: write down restriction of 32-bit tool stacks
Jan Beulich [Mon, 19 Jun 2023 13:45:07 +0000 (15:45 +0200)]
SUPPORT.md: write down restriction of 32-bit tool stacks

Let's try to avoid giving the impression that 32-bit tool stacks are as
capable as 64-bit ones.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agoautomation: Disable QEMU build with Clang older than 10.0
Anthony PERARD [Mon, 19 Jun 2023 09:09:32 +0000 (10:09 +0100)]
automation: Disable QEMU build with Clang older than 10.0

Since QEMU commit 74a1b256d775 ("configure: Bump minimum Clang version
to 10.0"), or QEMU v8.0, Clang 10.0 is now the minimum to build QEMU.

QEMU 8.0 fails to build on Ubuntu Bionic.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agoxen/arm: p2m: Enable support for 32bit IPA for ARM_32
Ayan Kumar Halder [Fri, 2 Jun 2023 12:07:54 +0000 (13:07 +0100)]
xen/arm: p2m: Enable support for 32bit IPA for ARM_32

Refer ARM DDI 0406C.d ID040418, B3-1345,

"A stage 2 translation with an input address range of 31-34 bits can
start the translation either:

- With a first-level lookup, accessing a first-level translation
  table with 2-16 entries.

- With a second-level lookup, accessing a set of concatenated
  second-level translation tables"

Thus, for 32 bit IPA, there will be no concatenated root level tables.
So, the root-order is 0.

Also, Refer ARM DDI 0406C.d ID040418, B3-1348
"Determining the required first lookup level for stage 2 translations

For a stage 2 translation, the output address range from the stage 1
translations determines the required input address range for the stage 2
translation. The permitted values of VTCR.SL0 are:
0b00 Stage 2 translation lookup must start at the second level.
0b01 Stage 2 translation lookup must start at the first level.

VTCR.T0SZ must indicate the required input address range. The size of
the input address region is 2^(32-T0SZ) bytes."

Thus VTCR.SL0 = 1 (maximum value) and VTCR.T0SZ = 0 when the size of
input address region is 2^32 bytes.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/arm: Restrict zeroeth_table_offset for ARM_64
Ayan Kumar Halder [Fri, 2 Jun 2023 12:07:53 +0000 (13:07 +0100)]
xen/arm: Restrict zeroeth_table_offset for ARM_64

When 32 bit physical addresses are used (ie PHYS_ADDR_T_32=y),
"va >> ZEROETH_SHIFT" causes an overflow.
Also, there is no zeroeth level page table on Arm32.

Also took the opportunity to clean up dump_pt_walk(). One could use
DECLARE_OFFSETS() macro instead of declaring an array of page table
offsets.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/arm: guest_walk: LPAE specific bits should be enclosed within "ifndef CONFIG_PHYS...
Ayan Kumar Halder [Fri, 2 Jun 2023 12:07:52 +0000 (13:07 +0100)]
xen/arm: guest_walk: LPAE specific bits should be enclosed within "ifndef CONFIG_PHYS_ADDR_T_32"

As the previous patch introduces CONFIG_PHYS_ADDR_T_32 to support 32 bit
physical addresses, the code specific to "Large Physical Address Extension"
(ie LPAE) should be enclosed within "ifndef CONFIG_PHYS_ADDR_T_32".

Refer xen/arch/arm/include/asm/short-desc.h, "short_desc_l1_supersec_t"
unsigned int extbase1:4;    /* Extended base address, PA[35:32] */
unsigned int extbase2:4;    /* Extended base address, PA[39:36] */

Thus, extbase1 and extbase2 are not valid when 32 bit physical addresses
are supported.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
22 months agoxen/arm: Introduce choice to enable 64/32 bit physical addressing
Ayan Kumar Halder [Fri, 2 Jun 2023 12:07:51 +0000 (13:07 +0100)]
xen/arm: Introduce choice to enable 64/32 bit physical addressing

Some Arm based hardware platforms which does not support LPAE
(eg Cortex-R52), uses 32 bit physical addresses.
Also, users may choose to use 32 bits to represent physical addresses
for optimization.

To support the above use cases, we have introduced arch independent
config to choose if the physical address can be represented using
32 bits (PHYS_ADDR_T_32) or 64 bits (!PHYS_ADDR_T_32).
For now only ARM_32 provides support to enable 32 bit physical
addressing.

When PHYS_ADDR_T_32 is defined, PADDR_BITS is set to 32. Note that we
use "unsigned long" (not "uint32_t") to denote the datatype of physical
address. This is done to avoid using a cast each time PAGE_* macros are
used on paddr_t. For eg PAGE_SIZE is defined as unsigned long. Thus,
each time PAGE_SIZE is used with paddr_t, the result will be
"unsigned long".
On 32-bit architecture, "unsigned long" is 32-bit wide. Thus, it can be
used to denote physical address.

When PHYS_ADDR_T_32 is not defined for ARM_32, PADDR_BITS is set to 40.
For ARM_64, PADDR_BITS is set to 48.
The last two are same as the current configuration used today on Xen.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/arm: p2m: Use the pa_range_info table to support arm32 and arm64
Ayan Kumar Halder [Fri, 2 Jun 2023 12:07:50 +0000 (13:07 +0100)]
xen/arm: p2m: Use the pa_range_info table to support arm32 and arm64

Restructure the code so that one can use pa_range_info[] table for both
arm32 as well as arm64.

Also, removed the hardcoding for P2M_ROOT_ORDER and P2M_ROOT_LEVEL as
p2m_root_order can be obtained from the pa_range_info[].root_order and
p2m_root_level can be obtained from pa_range_info[].sl0.

Refer ARM DDI 0406C.d ID040418, B3-1345,
"Use of concatenated first-level translation tables

...However, a 40-bit input address range with a translation granularity of 4KB
requires a total of 28 bits of address resolution. Therefore, a stage 2
translation that supports a 40-bit input address range requires two concatenated
first-level translation tables,..."

Thus, root-order is 1 for 40-bit IPA on arm32.

Refer ARM DDI 0406C.d ID040418, B3-1348,

"Determining the required first lookup level for stage 2 translations

For a stage 2 translation, the output address range from the stage 1
translations determines the required input address range for the stage 2
translation. The permitted values of VTCR.SL0 are:

0b00 Stage 2 translation lookup must start at the second level.
0b01 Stage 2 translation lookup must start at the first level.

VTCR.T0SZ must indicate the required input address range. The size of the input
address region is 2^(32-T0SZ) bytes."

Thus VTCR.SL0 = 1 (maximum value) and VTCR.T0SZ = -8 when the size of input
address region is 2^40 bytes.

Thus, pa_range_info[].t0sz = 1 (VTCR.S) | 8 (VTCR.T0SZ) ie 11000b which is 24.

VTCR.T0SZ, is bits [5:0] for arm64.
VTCR.T0SZ is bits [3:0] and S(sign extension), bit[4] for arm32.

For this, we have used struct bitfields to convert pa_range_info[].t0sz to its
arm32 variant.

pa_range_info[] is indexed by ID_AA64MMFR0_EL1.PARange which is present in Arm64
only. This is the reason we do not specify the indices for arm32. Also, we
duplicated the entry "{ 40,      24/*24*/,  1,          1 }" between arm64 and
arm32. This is done to avoid introducing extra #if-defs.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
[julien: Tweak some comments and one check]
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agoautomation: Add container for ppc64le builds
Shawn Anastasio [Tue, 13 Jun 2023 14:49:59 +0000 (09:49 -0500)]
automation: Add container for ppc64le builds

Add a container for cross-compiling xen for ppc64le.

Signed-off-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agox86/cpu-policy: Derive RSBA/RRSBA for guest policies
Andrew Cooper [Wed, 24 May 2023 14:41:21 +0000 (15:41 +0100)]
x86/cpu-policy: Derive RSBA/RRSBA for guest policies

The RSBA bit, "RSB Alternative", means that the RSB may use alternative
predictors when empty.  From a practical point of view, this mean "Retpoline
not safe".

Enhanced IBRS (officially IBRS_ALL in Intel's docs, previously IBRS_ATT) is a
statement that IBRS is implemented in hardware (as opposed to the form
retrofitted to existing CPUs in microcode).

The RRSBA bit, "Restricted-RSBA", is a combination of RSBA, and the eIBRS
property that predictions are tagged with the mode in which they were learnt.
Therefore, it means "when eIBRS is active, the RSB may fall back to
alternative predictors but restricted to the current prediction mode".  As
such, it's stronger statement than RSBA, but still means "Retpoline not safe".

CPUs are not expected to enumerate both RSBA and RRSBA.

Add feature dependencies for EIBRS and RRSBA.  While technically they're not
linked, absolutely nothing good can come of letting the guest see RRSBA
without EIBRS.  Nor a guest seeing EIBRS without IBRSB.  Furthermore, we use
this dependency to simplify the max derivation logic.

The max policies gets RSBA and RRSBA unconditionally set (with the EIBRS
dependency maybe hiding RRSBA).  We can run any VM, even if it has been told
"somewhere you might run, Retpoline isn't safe".

The default policies are more complicated.  A guest shouldn't see both bits,
but it needs to see one if the current host suffers from any form of RSBA, and
which bit it needs to see depends on whether eIBRS is visible or not.
Therefore, the calculation must be performed after sanitise_featureset().

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
22 months agox86/spec-ctrl: Fix up the RSBA/RRSBA bits as appropriate
Andrew Cooper [Thu, 25 May 2023 19:31:22 +0000 (20:31 +0100)]
x86/spec-ctrl: Fix up the RSBA/RRSBA bits as appropriate

In order to level a VM safely for migration, the toolstack needs to know the
RSBA/RRSBA properties of the CPU, whether or not they happen to be enumerated.

See the code comment for details.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
22 months agox86/spec-ctrl: Rename retpoline_safe() to retpoline_calculations()
Andrew Cooper [Fri, 26 May 2023 09:35:47 +0000 (10:35 +0100)]
x86/spec-ctrl: Rename retpoline_safe() to retpoline_calculations()

This is prep work, split out to simply the diff on the following change.

 * Rename to retpoline_calculations(), and call unconditionally.  It is
   shortly going to synthesise missing enumerations required for guest safety.
 * For the model check switch statement, store the result in a variable and
   break rather than returning directly.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
22 months agox86/spec-ctrl: Use a taint for CET without MSR_SPEC_CTRL
Andrew Cooper [Mon, 5 Jun 2023 10:09:11 +0000 (11:09 +0100)]
x86/spec-ctrl: Use a taint for CET without MSR_SPEC_CTRL

Reword the comment for 'S' to include an incompatible set of features on the
same core.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
22 months agox86/spec-ctrl: Fix the rendering of FB_CLEAR
Andrew Cooper [Mon, 12 Jun 2023 19:24:00 +0000 (20:24 +0100)]
x86/spec-ctrl: Fix the rendering of FB_CLEAR

FB_CLEAR is a read-only status bit, not a read-write control.  Move it from
"Hardware features" into "Hardware hints".

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
22 months agoxen: Append a newline character to panic() where missing
Michal Orzel [Wed, 14 Jun 2023 07:30:18 +0000 (09:30 +0200)]
xen: Append a newline character to panic() where missing

Missing newline is inconsistent with the rest of the callers, since
panic() expects it.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
22 months agoxen/arm: Remove stray semicolon at VREG_REG_HELPERS/TLB_HELPER* callers
Michal Orzel [Wed, 14 Jun 2023 09:41:44 +0000 (11:41 +0200)]
xen/arm: Remove stray semicolon at VREG_REG_HELPERS/TLB_HELPER* callers

This is inconsistent with the rest of the code where macros are used
to define functions, as it results in an empty declaration (i.e.
semicolon with nothing before it) after function definition. This is also
not allowed by C99.

Take the opportunity to undefine TLB_HELPER* macros after last use.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
22 months agoxen/arm: traps: remove inlining of handle_ro_raz()
Federico Serafini [Thu, 15 Jun 2023 13:50:16 +0000 (15:50 +0200)]
xen/arm: traps: remove inlining of handle_ro_raz()

To comply with MISRA C:2012 Rule 8.10 ("An inline function shall be
declared with the static storage class"), remove inline function
specifier from handle_ro_raz() since asking the compiler to inline
such function does not seem to add any kind of value.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/grant: Purge PIN_FAIL()
Andrew Cooper [Tue, 13 Jun 2023 16:25:42 +0000 (17:25 +0100)]
xen/grant: Purge PIN_FAIL()

The name PIN_FAIL() is poor; it's not used only for pinning failures.  More
importantly, it interferes with code legibility by hiding control flow.
Expand and drop it.

 * Drop redundant "rc = rc" assignment
 * Rework gnttab_copy_buf() to be simpler by dropping the rc variable

As a side effect, this fixes several violations of MISRA rule 2.1 (dead code -
the while() following a goto).

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
22 months agox86/shadow: Don't use signed bitfield in sh_emulate_ctxt
Andrew Cooper [Mon, 9 May 2022 10:18:20 +0000 (11:18 +0100)]
x86/shadow: Don't use signed bitfield in sh_emulate_ctxt

'int' bitfields in particular have implementation defined behaviour under gcc
and can change signed-ness with -funsigned-bitfields.

There is no need for low_bit_was_clear to be a bitfield in the first place; it
is only used as a boolean.  Doing so even improves the code generation in
sh_emulate_map_dest() to avoid emitting a merge with structure padding.

Spotted by Eclair MISRA scanner.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
22 months agox86/p2m.h: Add include guards
Andrew Cooper [Mon, 9 May 2022 10:17:35 +0000 (11:17 +0100)]
x86/p2m.h: Add include guards

Spotted by Eclair MISRA scanner.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
22 months agoArm: drop bogus ALIGN() from linker script
Jan Beulich [Thu, 15 Jun 2023 09:00:22 +0000 (11:00 +0200)]
Arm: drop bogus ALIGN() from linker script

Having ALIGN() inside a section definition usually makes sense only with
a label definition following (an exception case is a few lines out of
context, where cache line sharing is intended to be avoided).
Constituents of .bss.page_aligned need to specify their own alignment
correctly anyway, or else they're susceptible to link order changing.
This requirement is already met: Arm-specific code has no such object,
while common (EFI) code has another one. That one has suitable alignment
specified.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
22 months agospinlock: alter inlining of _spin_lock_cb()
Jan Beulich [Thu, 15 Jun 2023 08:59:56 +0000 (10:59 +0200)]
spinlock: alter inlining of _spin_lock_cb()

To comply with Misra rule 8.10 ("An inline function shall be declared
with the static storage class"), convert what is presently
_spin_lock_cb() to an always-inline (and static) helper, while making
the function itself a thin wrapper, just like _spin_lock() is.

While there drop the unlikely() from the callback check, and correct
indentation in _spin_lock().

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
22 months agolibxg: shrink variable scope in xc_core_arch_map_p2m_list_rw()
Jan Beulich [Thu, 15 Jun 2023 08:59:30 +0000 (10:59 +0200)]
libxg: shrink variable scope in xc_core_arch_map_p2m_list_rw()

This in particular allows to drop a dead assignment to "ptes" from near
the end of the function.

Coverity ID: 1532314
Fixes: bd7a29c3d0b9 ("tools/libs/ctrl: fix xc_core_arch_map_p2m() to support linear p2m table")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
22 months agolibxl: drop dead assignment to transaction variable from libxl__domain_make()
Jan Beulich [Wed, 14 Jun 2023 10:32:10 +0000 (12:32 +0200)]
libxl: drop dead assignment to transaction variable from libxl__domain_make()

"t" is written first thing at the "retry_transaction" label.

Coverity ID: 1532321
Fixes: 1057300109ea ("libxl: fix error handling (xenstore transaction leak) in libxl__domain_make")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
22 months agolibxg: drop dead assignment to "rc" from xc_cpuid_apply_policy()
Jan Beulich [Wed, 14 Jun 2023 10:31:54 +0000 (12:31 +0200)]
libxg: drop dead assignment to "rc" from xc_cpuid_apply_policy()

"rc" is written immediately below the outer if(). Fold the remaining two
if()s.

Coverity ID: 1532320
Fixes: 685e922d6f30 ("tools/libxc: Rework xc_cpuid_apply_policy() to use {get,set}_cpu_policy()")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
22 months agolibxl: drop dead assignments to "ret" from libxl__domain_config_setdefault()
Jan Beulich [Wed, 14 Jun 2023 10:31:23 +0000 (12:31 +0200)]
libxl: drop dead assignments to "ret" from libxl__domain_config_setdefault()

The variable needs to be properly set only on the error paths.

Coverity ID: 1532311
Fixes: ab4440112bec ("xl / libxl: push parsing of SSID and CPU pool ID down to libxl")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Daniel P. Smith <dpsmith@apertussolutions.cm>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
22 months agoxen-mfndump: drop dead assignment to "page" from lookup_pte_func()
Jan Beulich [Wed, 14 Jun 2023 10:31:02 +0000 (12:31 +0200)]
xen-mfndump: drop dead assignment to "page" from lookup_pte_func()

The variable isn't used past the loop, and its value also isn't
meaningful across iterations. Reduce its scope to make this more
obvious.

Coverity ID: 1532310
Fixes: ae763e422430 ("tools/misc: introduce xen-mfndump")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Jason Andryuk <jandryuk@gmail.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
22 months agotools: fix make rpmball
Olaf Hering [Tue, 13 Jun 2023 12:42:14 +0000 (14:42 +0200)]
tools: fix make rpmball

Commit 438c5ffa44e99cceb574c0f9946aacacdedd2952 ("rpmball: Adjust to
new rpm, do not require --force") attempted to handle stricter
directory permissions in newer distributions.

This introduced a few issues:
- /boot used to be a constant prior commit
  6475d700055fa952f7671cee982a23de2f5e4a7c ("use BOOT_DIR as xen.gz
  install location"), since this commit the location has to be
  referenced via ${BOOT_DIR}
- it assumed the prefix and the various configurable paths match the
  glob pattern /*/*/*

Adjust the code to build a filelist on demand and filter directories
from an installed filesystem.rpm. This works on a SUSE system, and
will likely work on a RedHat based system as well.

Take the opportunity to replace the usage of $RPM_BUILD_ROOT with
%buildroot, and use pushd/popd pairs.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
22 months agoiommu/amd-vi: fix checking for Invalidate All support in amd_iommu_resume()
Roger Pau Monné [Tue, 13 Jun 2023 12:41:32 +0000 (14:41 +0200)]
iommu/amd-vi: fix checking for Invalidate All support in amd_iommu_resume()

The iommu local variable does not point to to a valid amd_iommu element
after the call to for_each_amd_iommu().  Instead check whether any IOMMU
on the system doesn't support Invalidate All in order to perform the
per-domain and per-device flushes.

Fixes: 9c46139de889 ('amd iommu: Support INVALIDATE_IOMMU_ALL command.')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
22 months agox86: minor tidying of identify_cpu()
Jan Beulich [Tue, 13 Jun 2023 09:14:50 +0000 (11:14 +0200)]
x86: minor tidying of identify_cpu()

Fields that generic_identify() sets unconditionally don't need pre-
setting. (In fact the compiler removes some of those assignments anyway,
at least in release builds.)

With the setting of ->cpuid_level to -1 gone, also drop the respective
BUG_ON() from default_init().

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
22 months agolivepatch: apply_alternatives() is only used for livepatch
Roger Pau Monné [Tue, 13 Jun 2023 09:13:39 +0000 (11:13 +0200)]
livepatch: apply_alternatives() is only used for livepatch

Guard it with CONFIG_LIVEPATCH.  Note alternatives are applied at boot
using _apply_alternatives().

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/riscv: add __ASSEMBLY__ guard to asm/page.h
Oleksii Kurochko [Tue, 13 Jun 2023 09:13:06 +0000 (11:13 +0200)]
xen/riscv: add __ASSEMBLY__ guard to asm/page.h

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
22 months agolibxl: Call libxl__virtio_devtype.set_default() early enough
Viresh Kumar [Tue, 13 Jun 2023 09:12:24 +0000 (11:12 +0200)]
libxl: Call libxl__virtio_devtype.set_default() early enough

The _setdefault() function for virtio devices is getting called after
libxl__prepare_dtb(), which is late as libxl__prepare_dtb() expects the
defaults to be already set by this time.

Call libxl__virtio_devtype.set_default() from
libxl__domain_config_setdefault(), in a similar way as other devices
like disk, etc.

Suggested-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
22 months agolibxl: virtio: Remove unused frontend nodes
Viresh Kumar [Tue, 13 Jun 2023 09:12:10 +0000 (11:12 +0200)]
libxl: virtio: Remove unused frontend nodes

Only the VirtIO backend will watch xenstore to find out when a new
instance needs to be created for a guest, and read the parameters from
there. VirtIO frontend are only virtio, so they will not do anything
with the xenstore nodes. They can be removed.

While at it, also add a comment to the libxl_virtio.c file.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
22 months agotools/xenstored: Correct the prototype of domain_max_chk()
Julien Grall [Mon, 12 Jun 2023 10:13:19 +0000 (11:13 +0100)]
tools/xenstored: Correct the prototype of domain_max_chk()

Some version of GCC will complain because the prototype and the
declaration of domain_max_chk() don't match:

xenstored_domain.c:1503:6: error: conflicting types for 'domain_max_chk' due to enum/integer mismatch; have '_Bool(const struct connection *, enum accitem,  unsigned int)' [-Werror=enum-int-mismatch]
 1503 | bool domain_max_chk(const struct connection *conn, enum accitem what,
      |      ^~~~~~~~~~~~~~
In file included from xenstored_domain.c:31:
xenstored_domain.h:146:6: note: previous declaration of 'domain_max_chk' with type '_Bool(const struct connection *, unsigned int,  unsigned int)'
  146 | bool domain_max_chk(const struct connection *conn, unsigned int what,
      |      ^~~~~~~~~~~~~~

Update the prototype to match the declaration.

This was spotted by Gitlab CI with the job opensuse-tumbleweed-gcc.

Fixes: 685048441e1c ("tools/xenstore: switch quota management to be table based")
Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Jason Andryuk <jandryuk@gmail.com>
Tested-by: Jason Andryuk <jandryuk@gmail.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
22 months agotools/libs/store: make libxenstore independent of utils.h
Juergen Gross [Tue, 30 May 2023 08:54:13 +0000 (10:54 +0200)]
tools/libs/store: make libxenstore independent of utils.h

There is no real need for including tools/xenstore/utils.h from
libxenstore, as only streq() and ARRAY_SIZE() are obtained via that
header.

streq() is just !strcmp(), and ARRAY_SIZE() is brought in via
xen-tools/common-macros.h.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agotools/libs/store: use xen_list.h instead of xenstore/list.h
Juergen Gross [Tue, 30 May 2023 08:54:12 +0000 (10:54 +0200)]
tools/libs/store: use xen_list.h instead of xenstore/list.h

Replace the usage of the xenstore private list.h header with the
common xen_list.h one.

Use the XEN_TAILQ type list, as it allows to directly swap the
related macros/functions without having to change the logic.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
22 months agoxen/arm: rename guest_cpuinfo in domain_cpuinfo
Bertrand Marquis [Mon, 12 Jun 2023 13:00:46 +0000 (15:00 +0200)]
xen/arm: rename guest_cpuinfo in domain_cpuinfo

Rename the guest_cpuinfo structure to domain_cpuinfo as it is not only
used for guests but also for dom0 so domain is a more suitable name.

While there also rename the create_guest_cpuinfo function to
create_domain_cpuinfo to be coherent and fix comments accordingly.

Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
23 months agotools/ocaml/xc: Fix xc_physinfo() bindings
Andrew Cooper [Thu, 8 Jun 2023 09:59:37 +0000 (10:59 +0100)]
tools/ocaml/xc: Fix xc_physinfo() bindings

The original change doesn't compile on ARM:

  xenctrl_stubs.c: In function 'stub_xc_physinfo':
  xenctrl_stubs.c:821:16: error: unused variable 'arch_cap_flags_tag' [-Werror=unused-variable]
    821 |         int r, arch_cap_flags_tag;
        |                ^~~~~~~~~~~~~~~~~~
  cc1: all warnings being treated as errors

but it was buggy too.

First, it tried storing an int in a pointer slot, causing heap corruption.

Next, it is not legitimate to exclude arm32 in the toolstack as it explicitly
can operate an arm64 toolstack and build arm64 domains.  That in turn means
that you can't stash a C uint32_t in an OCaml int.

Rewrite the arch_capabilities handling from scratch.  Break it out into a
separate function, and make the construction of arch_physinfo_cap_flags common
to prevent other indirection bugs.

Reintroduce arm_physinfo_caps with the fields broken out.

Fixes: 56a7aaa16bfe ("tools: add physinfo arch_capabilities handling for Arm")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Christian Lindig <christian.lindig@cloud.com>
23 months agoCI: Add Ocaml to the alpine containers
Andrew Cooper [Fri, 9 Jun 2023 15:59:20 +0000 (16:59 +0100)]
CI: Add Ocaml to the alpine containers

This gets more coverage of optional parts of the build, and makes it easier to
trial Ocaml related changes in the smoke tests.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
23 months agotools/xenstore: remove support of file backed data base
Juergen Gross [Tue, 30 May 2023 08:54:11 +0000 (10:54 +0200)]
tools/xenstore: remove support of file backed data base

In order to prepare the replacement of TDB with direct accessible nodes
in memory, remove the support for a file backed data base.

This allows to remove xs_tdb_dump, too.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>