]> xenbits.xensource.com Git - xen.git/log
xen.git
11 months agox86/cpu-policy: Fix migration from Ice Lake to Cascade Lake
Andrew Cooper [Tue, 7 May 2024 11:19:41 +0000 (12:19 +0100)]
x86/cpu-policy: Fix migration from Ice Lake to Cascade Lake

Ever since Xen 4.14, there has been a latent bug with migration.

While some toolstacks can level the features properly, they don't shink
feat.max_subleaf when all features have been dropped.  This is because
we *still* have not completed the toolstack side work for full CPU Policy
objects.

As a consequence, even when properly feature levelled, VMs can't migrate
"backwards" across hardware which reduces feat.max_subleaf.  One such example
is Ice Lake (max_subleaf=2 for INTEL_PSFD) to Cascade Lake (max_subleaf=0).

Extend the max policies feat.max_subleaf to the hightest number Xen knows
about, but leave the default policies matching the host.  This will allow VMs
with a higher feat.max_subleaf than strictly necessary to migrate in.

Eventually we'll manage to teach the toolstack how to avoid creating such VMs
in the first place, but there's still more work to do there.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
11 months agotools/libxs: Open /dev/xen/xenbus fds as O_CLOEXEC
Andrew Cooper [Sat, 4 May 2024 01:10:33 +0000 (02:10 +0100)]
tools/libxs: Open /dev/xen/xenbus fds as O_CLOEXEC

The header description for xs_open() goes as far as to suggest that the fd is
O_CLOEXEC, but it isn't actually.

`xl devd` has been observed leaking /dev/xen/xenbus into children.

Link: https://github.com/QubesOS/qubes-issues/issues/8292
Reported-by: Demi Marie Obenour <demi@invisiblethingslab.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
12 months agox86/platform: correct #undef in compat checking
Jan Beulich [Mon, 6 May 2024 12:53:17 +0000 (14:53 +0200)]
x86/platform: correct #undef in compat checking

A stray 'p' was there, rendering the #undef ineffectual.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
12 months agoAMD/IOMMU: add helper to check whether ATS is to be used for a device
Jan Beulich [Mon, 6 May 2024 12:52:48 +0000 (14:52 +0200)]
AMD/IOMMU: add helper to check whether ATS is to be used for a device

The same set of conditions is used in three places, requiring to be kept
in sync. Introduce a helper to centralize these checks.

To allow all parameters of the new helper be pointer-to-const,
iommu_has_cap() also needs its 1st parameter to be constified. Beyond
that further "modernize" that function.

Requested-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
12 months agoVT-d: parse ACPI "SoC Integrated Address Translation Cache Reporting Structure"s
Jan Beulich [Mon, 6 May 2024 12:52:12 +0000 (14:52 +0200)]
VT-d: parse ACPI "SoC Integrated Address Translation Cache Reporting Structure"s

This is a prereq to us, in particular, respecting the "ATC required"
flag.

Note that ACPI_SATC_ATC_REQUIRED has its #define put in dmar.h, as we
try to keep actbl*.h in sync what Linux (who in turn inherit from ACPI
CA) has.

Note further that some perhaps sub-optimal style aspects are mainly the
way they are in order to stay consistent with other pre-existing code.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
12 months agoVT-d: tidy error handling of RMRR parsing
Jan Beulich [Mon, 6 May 2024 12:51:29 +0000 (14:51 +0200)]
VT-d: tidy error handling of RMRR parsing

It's acpi_parse_one_rmrr() where the allocation is coming from (by way
of invoking acpi_parse_dev_scope()), or in add_one_user_rmrr()'s case
allocation is even open-coded there, so freeing would better also happen
there. Care needs to be taken to preserve acpi_parse_one_rmrr()'s
ultimate return value.

While fiddling with callers also move scope_devices_free() to .init and
have it use XFREE() instead of open-coding it. To avoid making the
situation worse for register_one_rmrr(), mark that __init right here as
well.

In register_one_rmrr() also have the "ignore" path take the main
function return path.

Suggested-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
12 months agoautomation/eclair: add deviation for Rule 16.4
Federico Serafini [Mon, 6 May 2024 07:24:50 +0000 (09:24 +0200)]
automation/eclair: add deviation for Rule 16.4

MISRA C:2012 Rule 16.4 states that "Every switch statement shall have a
default label".
Update ECLAIR configuration to take into account the deviations
agreed during MISRA meetings.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agodocs/misra: add Terms & Definitions section to rules.rst
Federico Serafini [Mon, 6 May 2024 07:24:37 +0000 (09:24 +0200)]
docs/misra: add Terms & Definitions section to rules.rst

Add a section for terms and definitions used by MISRA but expressed
in terms of the C specification.

Add a definition of "switch clause" to the newly-introduced section.

Link the first use of the term "switch clause" in the document to its
definition.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agoppc/riscv: fix arch_acquire_resource_check()
Roger Pau Monné [Mon, 6 May 2024 07:24:10 +0000 (09:24 +0200)]
ppc/riscv: fix arch_acquire_resource_check()

None of the implementations support set_foreign_p2m_entry() yet, neither they
have a p2m walk in domain_relinquish_resources() in order to remove the foreign
mappings from the p2m and thus drop the extra refcounts.

Adjust the arch helpers to return false and introduce a comment that clearly
states it is not only taking extra refcounts that's needed, but also dropping
them on domain teardown.

Fixes: 4988704e00d8 ('xen/riscv: introduce p2m.h')
Fixes: 4a2f68f90930 ('xen/ppc: Define minimal stub headers required for full build')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Shawn Anastasio <sanastasio@raptorengineering.com>
12 months agodrivers/char: address violation of MISRA C Rule 20.7
Nicola Vetrini [Mon, 6 May 2024 07:23:30 +0000 (09:23 +0200)]
drivers/char: address violation of MISRA C Rule 20.7

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional chage.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agoVT-d: correct ATS checking for root complex integrated devices
Jan Beulich [Mon, 6 May 2024 07:22:45 +0000 (09:22 +0200)]
VT-d: correct ATS checking for root complex integrated devices

Spec version 4.1 says

"The ATSR structures identifies PCI Express Root-Ports supporting
 Address Translation Services (ATS) transactions. Software must enable
 ATS on endpoint devices behind a Root Port only if the Root Port is
 reported as supporting ATS transactions."

Clearly root complex integrated devices aren't "behind root ports",
matching my observation on a SapphireRapids system having an ATS-
capable root complex integrated device. Hence for such devices we
shouldn't try to locate a corresponding ATSR.

Since both pci_find_ext_capability() and pci_find_cap_offset() return
"unsigned int", change "pos" to that type at the same time.

Fixes: 903b93211f56 ("[VTD] laying the ground work for ATS")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
12 months agoxen/Kconfig: Drop the final remnants of ---help---
Andrew Cooper [Thu, 2 May 2024 17:35:09 +0000 (18:35 +0100)]
xen/Kconfig: Drop the final remnants of ---help---

We deprecated the use of ---help--- a while ago, but a lot of new content
copy&pastes bad examples.  Convert the remaining instances, and update
Kconfig's parser to no longer recongise it.

This now causes builds to fail with:

  Kconfig.debug:8: syntax error
  Kconfig.debug:7: unknown statement "---help---"

which short circuits one common piece of churn in new content.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Release-acked-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
12 months agotools/tests: let test-xenstore exit with non-0 status in case of error
Juergen Gross [Thu, 2 May 2024 09:22:13 +0000 (11:22 +0200)]
tools/tests: let test-xenstore exit with non-0 status in case of error

In case a test is failing in test-xenstore, let the tool exit with an
exit status other than 0.

Fix a typo in an error message.

Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Fixes: 3afc5e4a5b75 ("tools/tests: add xenstore testing framework")
Signed-off-by: Juergen Gross <jgross@suse.com>
12 months agotools/tests: don't let test-xenstore write nodes exceeding default size
Juergen Gross [Thu, 2 May 2024 13:21:36 +0000 (15:21 +0200)]
tools/tests: don't let test-xenstore write nodes exceeding default size

Today test-xenstore will write nodes with 3000 bytes node data. This
size is exceeding the default quota for the allowed node size. While
working in dom0 with C-xenstored, OCAML-xenstored does not like that.

Use a size of 2000 instead, which is lower than the allowed default
node size of 2048.

Fixes: 3afc5e4a5b75 ("tools/tests: add xenstore testing framework")
Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agoautomation/eclair: make explicit there are no adopted files by default
Federico Serafini [Mon, 29 Apr 2024 15:21:59 +0000 (17:21 +0200)]
automation/eclair: make explicit there are no adopted files by default

Update ECLAIR configuration to consider no adopted files by default.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agoautomation: do not allow failure for triggered analyses
Federico Serafini [Mon, 29 Apr 2024 15:21:58 +0000 (17:21 +0200)]
automation: do not allow failure for triggered analyses

Do not allow_failure for triggered analyses:
introducing regressions of clean guidelines will cause a CI failure.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agoautomation/eclair: tag Rule 7.2 as clean and temporarily remove Rules 1.1 and 8.2
Federico Serafini [Mon, 29 Apr 2024 15:21:57 +0000 (17:21 +0200)]
automation/eclair: tag Rule 7.2 as clean and temporarily remove Rules 1.1 and 8.2

Update ECLAIR configuration to consider Rule 7.2 as clean.

Temporarily remove the clean tag from Rules 1.1 and 8.2:
when violations of such rules will be addressed, the clean tag will be
reintroduced.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agox86/cpu-policy: Annotate the accumulated features
Andrew Cooper [Fri, 26 Apr 2024 15:53:08 +0000 (16:53 +0100)]
x86/cpu-policy: Annotate the accumulated features

Some features need accumulating rather than intersecting to make migration
safe.  Introduce the new '|' attribute for this purpose.

Right now, it's only used by the Xapi toolstack, but it will be used by
xl/libxl when the full policy-object work is complete, and until then it's
still a useful hint for hand-crafted cpuid= lines in vm.cfg files.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
12 months agorevert "x86/mm: re-implement get_page_light() using an atomic increment"
Jan Beulich [Tue, 30 Apr 2024 06:37:19 +0000 (08:37 +0200)]
revert "x86/mm: re-implement get_page_light() using an atomic increment"

This reverts commit c40bc0576dcc5acd4d7e22ef628eb4642f568533.

That change aimed at eliminating an open-coded lock-like construct,
which really isn't all that similar to, in particular, get_page(). The
function always succeeds. Any remaining concern would want taking care
of by placing block_lock_speculation() at the end of the function.
Since the function is called only during page (de)validation, any
possible performance concerns over such extra serialization could
likely be addressed by pre-validating (e.g. via pinning) page tables.

The fundamental issue with the change being reverted is that it detects
bad state only after already having caused possible corruption. While
the system is going to be halted in such an event, there is a time
window during which the resulting incorrect state could be leveraged by
a clever (in particular: fast enough) attacker.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
12 months agoxen/riscv: improve check-extension() macro
Oleksii Kurochko [Tue, 30 Apr 2024 06:36:39 +0000 (08:36 +0200)]
xen/riscv: improve check-extension() macro

Now, the check-extension() macro has 1 argument instead of 2.
This change helps to reduce redundancy around usage of extensions
name (in the case of the zbb extension, the name was used 3 times).

To implement this, a new variable was introduced:
  <extension name>-insn
which represents the instruction support that is being checked.

Additionally, zbb-insn is updated to use $(comma) instead of ",".

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
12 months agoxen/x86: Fix Syntax warning in gen-cpuid.py
Jason Andryuk [Tue, 30 Apr 2024 06:34:37 +0000 (08:34 +0200)]
xen/x86: Fix Syntax warning in gen-cpuid.py

Python 3.12.2 warns:

xen/tools/gen-cpuid.py:50: SyntaxWarning: invalid escape sequence '\s'
  "\s+([\s\d]+\*[\s\d]+\+[\s\d]+)\)"
xen/tools/gen-cpuid.py:51: SyntaxWarning: invalid escape sequence '\s'
  "\s+/\*([\w!]*) .*$")

Specify the strings as raw strings so '\s' is read as literal '\' + 's'.
This avoids escaping all the '\'s in the strings.

Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agoxen/xsm: Wire up get_dom0_console
Jason Andryuk [Tue, 30 Apr 2024 06:33:41 +0000 (08:33 +0200)]
xen/xsm: Wire up get_dom0_console

An XSM hook for get_dom0_console is currently missing.  Using XSM with
a PVH dom0 shows:
(XEN) FLASK: Denying unknown platform_op: 64.

Wire up the hook, and allow it for dom0.

Fixes: 4dd160583c ("x86/platform: introduce hypercall to get initial video console settings")
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Acked-by: Daniel P. Smith <dpsmith@apertussolutions.com>
12 months agox86/MCE: guard call to Intel-specific intel_get_extended_msrs()
Sergiy Kibrik [Tue, 30 Apr 2024 06:32:03 +0000 (08:32 +0200)]
x86/MCE: guard call to Intel-specific intel_get_extended_msrs()

Add check for CONFIG_INTEL build option to conditional call of this routine,
so that if Intel support is disabled the call would be eliminated.

No functional change intended.

Signed-off-by: Sergiy Kibrik <Sergiy_Kibrik@epam.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/msi: passthrough all MSI-X vector ctrl writes to device model
Marek Marczykowski-Górecki [Tue, 30 Apr 2024 06:31:01 +0000 (08:31 +0200)]
x86/msi: passthrough all MSI-X vector ctrl writes to device model

QEMU needs to know whether clearing maskbit of a vector is really
clearing, or was already cleared before. Currently Xen sends only
clearing that bit to the device model, but not setting it, so QEMU
cannot detect it. Because of that, QEMU is working this around by
checking via /dev/mem, but that isn't the proper approach.

Give all necessary information to QEMU by passing all ctrl writes,
including masking a vector. Advertise the new behavior via
XENVER_get_features, so QEMU can know it doesn't need to access /dev/mem
anymore.

While this commit doesn't move the whole maskbit handling to QEMU (as
discussed on xen-devel as one of the possibilities), it is a necessary
first step anyway. Including telling QEMU it will get all the required
information to do so. The actual implementation would need to include:
 - a hypercall for QEMU to control just maskbit (without (re)binding the
   interrupt again
 - a method for QEMU to tell Xen it will actually do the work
Those are not part of this series.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
12 months agoxen-livepatch: fix --force option comparison
Roger Pau Monné [Fri, 26 Apr 2024 10:43:44 +0000 (12:43 +0200)]
xen-livepatch: fix --force option comparison

The check for --force option shouldn't be against 0.

Reported-by: Jan Beulich <jbeulich@suse.com>
Fixes: 62a72092a517 ('livepatch: introduce --force option')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
12 months agoxen/spinlock: use correct pointer
Stewart Hildebrand [Fri, 26 Apr 2024 10:43:24 +0000 (12:43 +0200)]
xen/spinlock: use correct pointer

The ->profile member is at different offsets in struct rspinlock and
struct spinlock. When initializing the profiling bits of an rspinlock,
an unrelated member in struct rspinlock was being overwritten, leading
to mild havoc. Use the correct pointer.

Fixes: b053075d1a7b ("xen/spinlock: make struct lock_profile rspinlock_t aware")
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/entry: shrink insn size for some of our EFLAGS manipulation
Jan Beulich [Fri, 26 Apr 2024 10:43:01 +0000 (12:43 +0200)]
x86/entry: shrink insn size for some of our EFLAGS manipulation

Much like was recently done for setting entry vector, and along the
lines of what we already had in handle_exception_saved, avoid 32-bit
immediates where 8-bit ones do. Reduces .text.entry size by 16 bytes in
my non-CET reference build, while in my CET reference build section size
doesn't change (there and in .text only padding space increases).

Inspired by other long->byte conversion work.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agogzip: clean up comments and fix code alignment
Daniel P. Smith [Fri, 26 Apr 2024 10:42:14 +0000 (12:42 +0200)]
gzip: clean up comments and fix code alignment

This commit cleans up the comments and fixes the code alignment using Xen
coding style. This is done to make the code more legible before refactoring.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agoarm/vpci: make prefetchable mem 64 bit
Stewart Hildebrand [Wed, 24 Apr 2024 16:27:22 +0000 (12:27 -0400)]
arm/vpci: make prefetchable mem 64 bit

The vPCI prefetchable memory range is >= 4GB, so the memory space flags
should be set to 64-bit. See IEEE Std 1275-1994 [1] chapter 2.2.1.1 for
a definition of the field.

[1] https://www.devicetree.org/open-firmware/bindings/pci/pci2_1.pdf

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
Acked-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Rahul Singh <rahul.singh@arm.com>
12 months agoCI: Drop glibc-i386 from the build containers
Andrew Cooper [Thu, 25 Apr 2024 17:47:37 +0000 (18:47 +0100)]
CI: Drop glibc-i386 from the build containers

Xen 4.14 no longer runs in Gitlab CI.  Drop the dependency to shrink the build
containers a little.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agoautomation/eclair: reorganize pipelines
Simone Ballarin [Tue, 23 Apr 2024 15:14:33 +0000 (17:14 +0200)]
automation/eclair: reorganize pipelines

Introduce accepted_guidelines.sh: a script to autogenerate the
configuration file accepted.ecl from docs/misra/rules.rst which enables
all accepted guidelines.

Introduce monitored.ecl: a manual selection of accepted guidelines
which are clean or almost clean, it is intended to be used for the
analyses triggered by commits.

Reorganize tagging.ecl:
  -Remove "accepted" tags: keeping track of accepted guidelines tagging
   them as "accepted" in the configuration file tagging.ecl is no
   longer needed since docs/rules.rst is keeping track of them.
  -Tag more guidelines as clean.

Reorganize eclair pipelines:
  - Set1, Set2, Set3 are now obsolete: remove the corresponding
    pipelines and ecl files.
  - Amend scheduled eclair pipeline to use accepted.ecl.
  - Amend triggered eclair pipeline to use monitored.ecl.

Rename and improve action_check_clean_regressions.sh to print a
diagnostic in case a commit introduces a violation of a clean guideline.

An example of diagnostic is the following:

Failure: 13 regressions found for clean guidelines
  service MC3R1.R8.2: (required) Function types shall be in prototype form with named parameters:
   violation: 13

Signed-off-by: Simone Ballarin <simone.ballarin@bugseng.com>
Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Signed-off-by: Alessandro Zucchelli <alessandro.zucchelli@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agoVMX: no open-coding in vmx_get_cpl()
Jan Beulich [Thu, 25 Apr 2024 14:38:01 +0000 (16:38 +0200)]
VMX: no open-coding in vmx_get_cpl()

Neither X86_SEG_AR_DPL nor MASK_EXTR() should really be avoided here,
using literal number instead.

No difference in generated code (with gcc13 at least).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agoMAINTAINERS: Update my email address
Anthony PERARD [Thu, 25 Apr 2024 14:37:34 +0000 (16:37 +0200)]
MAINTAINERS: Update my email address

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/spec: adjust logic that elides lfence
Roger Pau Monné [Thu, 25 Apr 2024 14:37:01 +0000 (16:37 +0200)]
x86/spec: adjust logic that elides lfence

It's currently too restrictive by just checking whether there's a BHB clearing
sequence selected.  It should instead check whether BHB clearing is used on
entry from PV or HVM specifically.

Switch to use opt_bhb_entry_{pv,hvm} instead, and then remove cpu_has_bhb_seq
since it no longer has any users.

Reported-by: Jan Beulich <jbeulich@suse.com>
Fixes: 954c983abcee ('x86/spec-ctrl: Software BHB-clearing sequences')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agox86/spec: fix reporting of BHB clearing usage from guest entry points
Roger Pau Monné [Thu, 25 Apr 2024 14:35:56 +0000 (16:35 +0200)]
x86/spec: fix reporting of BHB clearing usage from guest entry points

Reporting whether the BHB clearing on entry is done for the different domains
types based on cpu_has_bhb_seq is unhelpful, as that variable signals whether
there's a BHB clearing sequence selected, but that alone doesn't imply that
such sequence is used from the PV and/or HVM entry points.

Instead use opt_bhb_entry_{pv,hvm} which do signal whether BHB clearing is
performed on entry from PV/HVM.

Fixes: 689ad48ce9cf ('x86/spec-ctrl: Wire up the Native-BHI software sequences')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agotools/ocaml: Fix warnings in config.ml
Edwin Török [Wed, 27 Mar 2024 16:30:21 +0000 (16:30 +0000)]
tools/ocaml: Fix warnings in config.ml

Fixes warnings such as:

  File "config.ml", line 102, characters 12-27:
  102 |         | Failure "int_of_string"   -> append (k, "expect int arg")
                          ^^^^^^^^^^^^^^^
  Warning 52: Code should not depend on the actual values of
  this constructor's arguments. They are only for information
  and may change in future versions. (See manual section 9.5)

Do not rely on the string values of the `Failure` exception, but use the
`_opt` functions instead.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
Acked-by: Christian Lindig <christian.lindig@cloud.com>
Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agox86/hap: Refactor boolean field assignments
Petr Beneš [Thu, 25 Apr 2024 07:55:00 +0000 (09:55 +0200)]
x86/hap: Refactor boolean field assignments

No functional change.

Signed-off-by: Petr Beneš <w1benny@gmail.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/shadow: correct shadow_vcpu_init()'s comment
Jan Beulich [Thu, 25 Apr 2024 07:54:28 +0000 (09:54 +0200)]
x86/shadow: correct shadow_vcpu_init()'s comment

As of the commit referenced below the update_paging_modes() hook is per-
domain and hence also set (already) during domain construction.

Fixes: d0816a9085b5 ("x86/paging: move update_paging_modes() hook")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
12 months agox86/paging: vCPU host mode is always set
Jan Beulich [Thu, 25 Apr 2024 07:53:55 +0000 (09:53 +0200)]
x86/paging: vCPU host mode is always set

... thanks to paging_vcpu_init() being part of vCPU creation. Further
if paging is enabled on a domain, it's also guaranteed to be either HAP
or shadow. Drop respective unnecessary (parts of) conditionals.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
12 months agox86/msr: add suffix 'U' to MSR_AMD_CSTATE_CFG macro
Alessandro Zucchelli [Thu, 25 Apr 2024 07:53:24 +0000 (09:53 +0200)]
x86/msr: add suffix 'U' to MSR_AMD_CSTATE_CFG macro

This addresses violations of MISRA C:2012 Rule 7.2 which states as
following: A “u” or “U” suffix shall be applied to all integer constants
that are represented in an unsigned type.

No functional change.

Fixes: 652683e1aeaa ("x86/hvm: address violations of MISRA C:2012 Rule 7.2")
Signed-off-by: Alessandro Zucchelli <alessandro.zucchelli@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/pci: add suffix 'U' to PCI_CONF_ADDRESS macro
Alessandro Zucchelli [Thu, 25 Apr 2024 07:52:51 +0000 (09:52 +0200)]
x86/pci: add suffix 'U' to PCI_CONF_ADDRESS macro

This addresses violations of MISRA C:2012 Rule 7.2 which states as
following: A “u” or “U” suffix shall be applied to all integer constants
that are represented in an unsigned type.

No functional change.

Signed-off-by: Alessandro Zucchelli <alessandro.zucchelli@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agolivepatch: introduce --force option
Roger Pau Monné [Thu, 25 Apr 2024 07:52:16 +0000 (09:52 +0200)]
livepatch: introduce --force option

Introduce a xen-livepatch tool --force option, that's propagated into the
hyerpvisor for livepatch operations.  The intention is for the option to be
used to bypass some checks that would otherwise prevent the patch from being
loaded.

Re purpose the pad field in xen_sysctl_livepatch_op to be a flags field that
applies to all livepatch operations.  The flag is currently only set by the
hypercall wrappers for the XEN_SYSCTL_LIVEPATCH_UPLOAD operation, as that's so
far the only one where it will be used initially.  Other uses can be added as
required.

Note that helpers would set the .pad field to 0, that's been removed since the
structure is already zero initialized at definition.

No functional usages of the new flag introduced in this patch.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
12 months agoxen-livepatch: fix parameter name parsing
Roger Pau Monné [Thu, 25 Apr 2024 07:51:57 +0000 (09:51 +0200)]
xen-livepatch: fix parameter name parsing

It's incorrect to restrict strncmp to the length of the command line input
parameter, as then a user passing a rune like:

% xen-livepatch up foo.livepatch

Would match against the "upload" command, because the string comparison has
been truncated to the length of the input argument.  Use strcmp instead which
doesn't truncate.  Otherwise in order to keep using strncmp we would need to
also check strings are of the same length before doing the comparison.

Fixes: 05bb8afedede ('xen-xsplice: Tool to manipulate xsplice payloads')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
12 months agox86/mm: address violations of MISRA C Rule 20.7
Nicola Vetrini [Thu, 25 Apr 2024 07:51:31 +0000 (09:51 +0200)]
x86/mm: address violations of MISRA C Rule 20.7

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/debugreg: address violation of MISRA C Rule 20.7
Nicola Vetrini [Thu, 25 Apr 2024 07:51:13 +0000 (09:51 +0200)]
x86/debugreg: address violation of MISRA C Rule 20.7

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/vhpet: address violations of MISRA C Rule 20.7
Nicola Vetrini [Thu, 25 Apr 2024 07:50:55 +0000 (09:50 +0200)]
x86/vhpet: address violations of MISRA C Rule 20.7

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/acpi: address violations of MISRA Rule 20.7
Nicola Vetrini [Thu, 25 Apr 2024 07:50:33 +0000 (09:50 +0200)]
x86/acpi: address violations of MISRA Rule 20.7

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/pci: address violation of MISRA C Rule 20.7
Nicola Vetrini [Thu, 25 Apr 2024 07:50:03 +0000 (09:50 +0200)]
x86/pci: address violation of MISRA C Rule 20.7

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agoxen/spinlock: address violations of MISRA C Rule 20.7
Nicola Vetrini [Thu, 25 Apr 2024 07:49:34 +0000 (09:49 +0200)]
xen/spinlock: address violations of MISRA C Rule 20.7

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agoxen/page-defs: address violation of MISRA C Rule 20.7
Nicola Vetrini [Thu, 25 Apr 2024 07:49:04 +0000 (09:49 +0200)]
xen/page-defs: address violation of MISRA C Rule 20.7

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agolibelf: address violations of MISRA C Rule 20.7
Nicola Vetrini [Thu, 25 Apr 2024 07:48:11 +0000 (09:48 +0200)]
libelf: address violations of MISRA C Rule 20.7

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agolibxl: Support blktap with HVM device model
Jason Andryuk [Thu, 25 Apr 2024 07:47:52 +0000 (09:47 +0200)]
libxl: Support blktap with HVM device model

blktap exposes disks over UNIX socket Network Block Device (NBD).
Modify libxl__device_disk_find_local_path() to provide back the
QEMU-formatted NBD path.  This allows tapdisk to be used for booting an
HVM.

Use the nbd+unix:/// format specified by the protocol at
https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
12 months agohotplug: Update block-tap
Jason Andryuk [Thu, 25 Apr 2024 07:46:56 +0000 (09:46 +0200)]
hotplug: Update block-tap

Implement a sharing check like the regular block script.

Checking tapback inside block-tap is too late since it needs to be
running to transition the backend to InitWait before block-tap is run.

tap-ctl check will be removed when the requirement for the blktap kernel
driver is removed.  Remove it now as it is of limited use.

find_device() needs to be non-fatal allow a sharing check.

Only write physical-device-path because that is all that tapback needs.
Also write_dev doesn't handled files and would incorrectly store
physical-device as 0:0 which would confuse the minor inside tapback

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
12 months agoautomation: Add arm64 test for running Xen with GICv3
Michal Orzel [Tue, 23 Apr 2024 16:11:21 +0000 (18:11 +0200)]
automation: Add arm64 test for running Xen with GICv3

At the moment, all the Arm64 Qemu tests use GICv2 which is the default
GIC version used by Qemu. Improve the coverage by adding a new test in
which Qemu will be configured to have GICv3.

Rename host device tree name to "virt.dtb" to be GIC version agnostic.
Use "gic-version" Qemu option to select the version to use. Unless the
test variant is set to "gicv3", version 2 will be used.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agoautomation: Add arm{64,32} earlyprintk jobs
Michal Orzel [Tue, 23 Apr 2024 16:11:20 +0000 (18:11 +0200)]
automation: Add arm{64,32} earlyprintk jobs

Introduce qemu based Arm earlyprintk test and build jobs to cover this
feature in debug variant. The tests simply check for the presence of the
last message printed by the bootstrap code before entering the C world.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agoautomation: Drop some of the non-debug variants of the same Arm jobs
Michal Orzel [Tue, 23 Apr 2024 16:11:19 +0000 (18:11 +0200)]
automation: Drop some of the non-debug variants of the same Arm jobs

To save some bandwith that can be later on used to increase the test
coverage by adding new tests, drop the following non-debug test/build
jobs existing in both debug and non-debug variants:
 - static memory (arm64, arm32)
 - static shared memory (arm64)
 - static heap (arm64)
 - boot cpupools (arm64)
 - gzip (arm32)

More generic tests existing in both variants were left unmodified.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agoxen/arm: List static shared memory regions as /memory nodes
Luca Fancellu [Mon, 22 Apr 2024 11:02:07 +0000 (12:02 +0100)]
xen/arm: List static shared memory regions as /memory nodes

Currently Xen is not exporting the static shared memory regions
to the device tree as /memory node, this commit is fixing this
issue.

Given that now make_memory_node needs a parameter 'struct kernel_info'
in order to call the new function shm_mem_node_fill_reg_range,
take the occasion to remove the unused struct domain parameter.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agoxen/arm: fix duplicate /reserved-memory node in Dom0
Penny Zheng [Thu, 18 Apr 2024 07:36:51 +0000 (08:36 +0100)]
xen/arm: fix duplicate /reserved-memory node in Dom0

In case there is a /reserved-memory node already present in the host
dtb, current Xen codes would create yet another /reserved-memory node
when the static shared memory feature is enabled and static shared
memory regions are present.
This would result in an incorrect device tree generation and hwdom
would not be able to detect the static shared memory region.

Avoid this issue by checking the presence of the /reserved-memory
node and appending the nodes instead of generating a duplicate
/reserved-memory.

Make make_shm_memory_node externally visible and rename it to
make_shm_resv_memory_node to make clear it produces childs for
/reserved-memory.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agoxen/arm: remove shm holes from extended regions
Penny Zheng [Thu, 18 Apr 2024 07:36:50 +0000 (08:36 +0100)]
xen/arm: remove shm holes from extended regions

Static shared memory acts as reserved memory in guest, so it shall be
excluded from extended regions.

Extended regions are taken care of under three different scenarios:
normal DomU, direct-map domain with iommu on, and direct-map domain
with iommu off.

For normal DomU, we create a new function "remove_shm_holes_for_domU",
to firstly transfer original outputs into the format of
"struct rangeset", then use "remove_shm_from_rangeset" to remove static
shm from them.

For direct-map domain with iommu on, after we get guest shm info from "kinfo",
we use "remove_shm_from_rangeset" to remove static shm.

For direct-map domain with iommu off, as static shm has already been taken
care of through find_unallocated_memory, we do nothing.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agoxen/arm: Reduce struct membank size on static shared memory
Luca Fancellu [Thu, 18 Apr 2024 07:36:49 +0000 (08:36 +0100)]
xen/arm: Reduce struct membank size on static shared memory

Currently the memory footprint of the static shared memory feature
is impacting all the struct meminfo instances with memory space
that is not going to be used.

To solve this issue, rework the static shared memory extra
information linked to the memory bank to another structure,
struct shmem_membank_extra, and exploit the struct membank
padding to host a pointer to that structure in a union with the
enum membank_type, with this trick the 'struct membank' has the
same size with or without the static shared memory, given that
the 'type' and 'shmem_extra' are never used at the same time,
hence the 'struct membank' won't grow in size.

Afterwards, create a new structure 'struct shared_meminfo' which
has the same interface of 'struct meminfo', but requires less
banks, defined by the number in NR_SHMEM_BANKS, which is 32 at the
moment and should be enough for the current use cases, the value
might be increased in te future if needed.
Finally, this structure hosts also the extra information for the
static shared memory banks.
The fields 'bank' and 'extra' of this structure are meant to be
linked by the index (e.g. extra[idx] will have the information for
the bank[idx], for i=0..NR_SHMEM_BANKS), the convinient pointer
'shmem_extra' of 'struct membank' is then linked to the related
'extra' bank to ease the fruition when a function has access only
to the 'struct membanks common' of 'struct shared_meminfo'.

The last part of this work is to move the allocation of the
static shared memory banks from the 'reserved_mem' to a new
'shmem' member of the 'struct bootinfo'.
Change also the 'shm_mem' member type to be 'struct shared_meminfo'
in order to match the above changes and allow a memory space
reduction also in 'struct kernel_info'.

Now that the structure

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agoxen/arm: Introduce helper for static memory pages
Luca Fancellu [Thu, 18 Apr 2024 07:36:48 +0000 (08:36 +0100)]
xen/arm: Introduce helper for static memory pages

Introduce a new helper function in the static-memory module
that can be called to manage static memory banks, this is
done to reuse the code when other modules would like to
manage static memory banks that are not part of the
reserved_mem structure, this is done because the static
shared memory banks will be removed from reserved_mem.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agoxen/arm: Avoid code duplication in check_reserved_regions_overlap
Luca Fancellu [Thu, 18 Apr 2024 07:36:47 +0000 (08:36 +0100)]
xen/arm: Avoid code duplication in check_reserved_regions_overlap

The function check_reserved_regions_overlap is calling
'meminfo_overlap_check' on the same type of structure, this code
can be written in a way to avoid code duplication, so rework the
function to do that.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agoxen/arm: Avoid code duplication in find_unallocated_memory
Luca Fancellu [Thu, 18 Apr 2024 07:36:46 +0000 (08:36 +0100)]
xen/arm: Avoid code duplication in find_unallocated_memory

The function find_unallocated_memory is using the same code to
loop through 2 structure of the same type, in order to avoid
code duplication, rework the code to have only one loop that
goes through all the structures, this will be used to avoid
duplication when the static shared memory banks will be introduced
as a separate structure from reserved memory.

Take the occasion to add the error code to the error message in
case 'rangeset_remove_range' fails.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agoxen/arm: Conditional compilation of kernel_info.shm_mem member
Luca Fancellu [Thu, 18 Apr 2024 07:36:45 +0000 (08:36 +0100)]
xen/arm: Conditional compilation of kernel_info.shm_mem member

The user of shm_mem member of the 'struct kernel_info' is only
the code managing the static shared memory feature, which can be
compiled out using CONFIG_STATIC_SHM, so in case the feature is
not requested, that member won't be used and will waste memory
space.

To address this issue, protect the member with the Kconfig parameter
and modify the signature of the only function using it to remove
any reference to the member from outside the static-shmem module.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agoxen/arm: Introduce a generic way to access memory bank structures
Luca Fancellu [Thu, 18 Apr 2024 07:36:44 +0000 (08:36 +0100)]
xen/arm: Introduce a generic way to access memory bank structures

Currently the 'struct meminfo' is defining a static defined array of
'struct membank' of NR_MEM_BANKS elements, some features like
shared memory don't require such amount of memory allocation but
might want to reuse existing code to manipulate this kind of
structure that is just as 'struct meminfo' but less bulky.

For this reason introduce a generic way to access this kind of
structure using a new structure 'struct membanks', which implements
all the fields needed by a structure related to memory banks
without the need to specify at build time the size of the
'struct membank' array, using a flexible array member.

Modify 'struct meminfo' to implement the field related to the new
introduced structure, given the change all usage of this structure
are updated in this way:
 - code accessing bootinfo.{mem,reserved_mem,acpi} field now uses
   3 new introduced static inline helpers to access the new field
   of 'struct meminfo' named 'common'.
 - code accessing 'struct kernel_info *' member 'mem' now use the
   new introduced macro 'kernel_info_get_mem(...)' to access the
   new field of 'struct meminfo' named 'common'.
 - introduced KERNEL_INFO_INIT and BOOTINFO_INIT that from now on
   will be used to initialize 'struct kernel_info' and 'struct bootinfo'
   respectively, in order to initialize their 'struct meminfo'
   .common.max_banks members.

Constify pointers where needed.

Suggested-by: Julien Grall <julien@xen.org>
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agoxen/arm: Pass struct kernel_info parameter to make_{resv,shm}_memory_node
Luca Fancellu [Thu, 18 Apr 2024 07:36:43 +0000 (08:36 +0100)]
xen/arm: Pass struct kernel_info parameter to make_{resv,shm}_memory_node

The struct domain parameter is not used in make_resv_memory_node and in
its called function make_shm_memory_node, so drop it from both functions,
also, take the occasion to pass directly struct kernel_info, from which
we can infer other parameters passed to the functions and drop them as
well.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agoxen/arm: avoid repetitive checking in process_shm_node
Penny Zheng [Thu, 18 Apr 2024 07:36:42 +0000 (08:36 +0100)]
xen/arm: avoid repetitive checking in process_shm_node

Putting overlap and overflow checking in the loop is causing repetitive
operation, so this commit extracts both checking outside the loop.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agoxen/arm: remove stale addr_cells/size_cells in assign_shared_memory
Penny Zheng [Thu, 18 Apr 2024 07:36:41 +0000 (08:36 +0100)]
xen/arm: remove stale addr_cells/size_cells in assign_shared_memory

Function parameters {addr_cells,size_cells} are stale parameters in
assign_shared_memory, so we shall remove them.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
12 months agotools/golang: Run `go vet` as part of the build process
George Dunlap [Fri, 19 Apr 2024 10:35:57 +0000 (11:35 +0100)]
tools/golang: Run `go vet` as part of the build process

Signed-off-by: George Dunlap <george.dunlap@cloud.com>
Acked-by: Nick Rosbrook <rosbrookn@gmail.com>
12 months agogolang/xenlight: Ensure comments aren't interpreted as docstrings
George Dunlap [Fri, 19 Apr 2024 11:03:13 +0000 (12:03 +0100)]
golang/xenlight: Ensure comments aren't interpreted as docstrings

Go has always interpreted a comment directly before a function as a
docstring, so having the C function prototypes which the golang method
is meant to wrap in the comment before was always a bit non-standard.
However, recent versions of `go fmt` now attempt to normalize these
docstrings as well, leading to strange changes, particularly if `go
fmt` is run on save.

Go through and put a space between non-docstring comments and methods,
so that `go fmt` leaves the comments alone.

No functional change.

Signed-off-by: George Dunlap <george.dunlap@cloud.com>
Acked-by: Nick Rosbrook <rosbrookn@gmail.com>
12 months agotools/golang: When returning pointers, actually allocate structrues
George Dunlap [Fri, 19 Apr 2024 09:57:04 +0000 (10:57 +0100)]
tools/golang: When returning pointers, actually allocate structrues

In a handful of cases, it was decided to return a pointer to a
structure rather than the plain structure itself, due to the size.
However, in these cases the structure was never allocated, leading to
a nil pointer exception when calling the relevant `fromC` method.

Allocate structures before attempting to fill them in.

Fixes: 453713b1750 ("golang/xenlight: Add host-related functionality")
Reported-by: Tobias Fitschen <tobias.fitschen@posteo.de>
Signed-off-by: George Dunlap <george.dunlap@cloud.com>
Tested-by: Tobias Fitschen <tobias.fitschen@posteo.de>
Acked-by: Nick Rosbrook <rosbrookn@gmail.com>
12 months agosvm/nestedsvm: Introduce nested capabilities bit
George Dunlap [Mon, 5 Feb 2024 01:39:00 +0000 (01:39 +0000)]
svm/nestedsvm: Introduce nested capabilities bit

In order to make implementation and testing tractable, we will require
specific host functionality.  Add a nested_virt bit to hvm_funcs.caps,
and return an error if a domain is created with nested virt and this
bit isn't set.  Create VMX and SVM callbacks to be executed from
nestedhvm_setup(), which is guaranteed to execute after all
command-line options have been procesed.

For VMX, start with always enabling it if HAP is present; this
shouldn't change current behvior.

For SVM, require some basic functionality, adding a document
explaining the rationale.

NB that only SVM CPUID bits 0-7 have been considered.  Bits 10-16 may
be considered in a follow-up patch.

Signed-off-by: George Dunlap <george.dunlap@cloud.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/monitor: allow fast-singlestepping without enabling singlestep monitor
Petr Beneš [Sun, 14 Apr 2024 18:21:14 +0000 (18:21 +0000)]
x86/monitor: allow fast-singlestepping without enabling singlestep monitor

Reorder the condition checks within the HVM_MONITOR_SINGLESTEP_BREAKPOINT
case to enable fast singlestepping independently of the singlestep monitor
being enabled. Previously, fast singlestepping required the singlestep
monitor to be explicitly enabled through xc_monitor_singlestep, even though
it operates entirely within Xen and does not generate external events.

Signed-off-by: Petr Beneš <w1benny@gmail.com>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
12 months agox86/MTRR: correct inadvertently inverted WC check
Jan Beulich [Tue, 23 Apr 2024 12:13:48 +0000 (14:13 +0200)]
x86/MTRR: correct inadvertently inverted WC check

The ! clearly got lost by mistake.

Fixes: e9e0eb30d4d6 ("x86/MTRR: avoid several indirect calls")
Reported-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
12 months agoxen: introduce header file with section related symbols
Roger Pau Monné [Tue, 23 Apr 2024 12:12:04 +0000 (14:12 +0200)]
xen: introduce header file with section related symbols

Start by declaring the beginning and end of the init section.

No functional change intended.

Requested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agodocs/man: Add xenwatchdog manual page
Leigh Brown [Tue, 23 Apr 2024 12:11:14 +0000 (14:11 +0200)]
docs/man: Add xenwatchdog manual page

Add a manual page for xenwatchdogd.

Signed-off-by: Leigh Brown <leigh@solinno.co.uk>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
12 months agotools/misc: Add xenwatchdogd.c copyright notice
Leigh Brown [Tue, 23 Apr 2024 12:10:16 +0000 (14:10 +0200)]
tools/misc: Add xenwatchdogd.c copyright notice

Add copyright notice and description of the program.

Signed-off-by: Leigh Brown <leigh@solinno.co.uk>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
12 months agotools/misc: xenwatchdogd enhancements
Leigh Brown [Tue, 23 Apr 2024 12:10:03 +0000 (14:10 +0200)]
tools/misc: xenwatchdogd enhancements

Add usage() function, the ability to run in the foreground, and
the ability to disarm the watchdog timer when exiting.

Add enhanced parameter parsing and validation, making use of
getopt_long().  Check the number of parameters are correct, the
timeout is at least two seconds (to allow a minimum sleep time of
one second), and that the sleep time is at least one and less
than the watchdog timeout.

With these changes, the daemon will no longer instantly reboot
the domain if you enter a zero timeout (or non-numeric parameter),
and prevent the daemon consuming 100% of a CPU due to zero sleep
time.

Signed-off-by: Leigh Brown <leigh@solinno.co.uk>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
12 months agotools/misc: xenwatchdogd: add parse_secs()
Leigh Brown [Tue, 23 Apr 2024 12:09:50 +0000 (14:09 +0200)]
tools/misc: xenwatchdogd: add parse_secs()

Create a new parse_secs() function to parse the timeout and sleep
parameters. This ensures that non-numeric parameters are not
accidentally treated as numbers.

Signed-off-by: Leigh Brown <leigh@solinno.co.uk>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
12 months agox86/rtc: Avoid UIP flag being set for longer than expected
Ross Lagerwall [Tue, 23 Apr 2024 12:09:18 +0000 (14:09 +0200)]
x86/rtc: Avoid UIP flag being set for longer than expected

In a test, OVMF reported an error initializing the RTC without
indicating the precise nature of the error. The only plausible
explanation I can find is as follows:

As part of the initialization, OVMF reads register C and then reads
register A repatedly until the UIP flag is not set. If this takes longer
than 100 ms, OVMF fails and reports an error. This may happen with the
following sequence of events:

At guest time=0s, rtc_init() calls check_update_timer() which schedules
update_timer for t=(1 - 244us).

At t=1s, the update_timer function happens to have been called >= 244us
late. In the timer callback, it sets the UIP flag and schedules
update_timer2 for t=1s.

Before update_timer2 runs, the guest reads register C which calls
check_update_timer(). check_update_timer() stops the scheduled
update_timer2 and since the guest time is now outside of the update
cycle, it schedules update_timer for t=(2 - 244us).

The UIP flag will therefore be set for a whole second from t=1 to t=2
while the guest repeatedly reads register A waiting for the UIP flag to
clear. Fix it by clearing the UIP flag when scheduling update_timer.

I was able to reproduce this issue with a synthetic test and this
resolves the issue.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/pvh: zero VGA information
Roger Pau Monné [Mon, 22 Apr 2024 13:13:30 +0000 (15:13 +0200)]
x86/pvh: zero VGA information

PVH guests skip real mode VGA detection, and never have a VGA available, hence
the default VGA selection is not applicable, and at worse can cause confusion
when parsing Xen boot log.

Zero the boot_vid_info structure when Xen is booted from the PVH entry point.

This fixes Xen incorrectly reporting:

(XEN) Video information:
(XEN)  VGA is text mode 80x25, font 8x16

When booted as a PVH guest.

Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/video: add boot_video_info offset generation to asm-offsets
Roger Pau Monné [Mon, 22 Apr 2024 13:13:00 +0000 (15:13 +0200)]
x86/video: add boot_video_info offset generation to asm-offsets

Currently the offsets into the boot_video_info struct are manually encoded in
video.S, which is fragile.  Generate them in asm-offsets.c and switch the
current code to use those instead.

No functional change intended.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agoautomation/eclair_analysis: substitute deprecated service STD.emptrecd
Nicola Vetrini [Mon, 22 Apr 2024 13:12:47 +0000 (15:12 +0200)]
automation/eclair_analysis: substitute deprecated service STD.emptrecd

The ECLAIR service STD.emptrecd (which checks for empty structures) is being
deprecated; hence, as a preventive measure, STD.anonstct (which checks for
structures with no named members, an UB in C99) is used here; the latter being
a more general case than the previous one, this change does not affect the
analysis. This new service is already supported by the current version of
ECLAIR.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Julien Grall <jgrall@amazon.com>
12 months agoxen/riscv: check whether the assembler has Zbb extension support
Oleksii Kurochko [Mon, 22 Apr 2024 13:12:03 +0000 (15:12 +0200)]
xen/riscv: check whether the assembler has Zbb extension support

Update the argument of the as-insn for the Zbb case to verify that
Zbb is supported not only by a compiler, but also by an assembler.

Also, check-extenstion(ext_name, "insn") helper macro is introduced
to check whether extension is supported by a compiler and an assembler.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agoxen/domain: deviate MISRA C Rule 16.2 violation
Nicola Vetrini [Mon, 22 Apr 2024 13:11:38 +0000 (15:11 +0200)]
xen/domain: deviate MISRA C Rule 16.2 violation

MISRA C Rule 16.2 states:
"A switch label shall only be used when the most closely-enclosing
compound statement is the body of a switch statement".

The PROGRESS_VCPU local helper specifies a case that is directly
inside the compound statement of a for loop, hence violating the rule.
To avoid this, the construct is deviated with a text-based deviation.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/PVH: Use unsigned int for dom0 e820 index
Jason Andryuk [Mon, 22 Apr 2024 13:11:02 +0000 (15:11 +0200)]
x86/PVH: Use unsigned int for dom0 e820 index

Switch to unsigned int for the dom0 e820 index.  This eliminates the
potential for array underflows, and the compiler might be able to
generate better code.

Requested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/svm: Add flushbyasid in the supported features
Vaishali Thakkar [Tue, 16 Apr 2024 09:08:12 +0000 (09:08 +0000)]
x86/svm: Add flushbyasid in the supported features

TLB Flush by ASID is missing in the list of supported features
here. So, add it.

Signed-off-by: Vaishali Thakkar <vaishali.thakkar@vates.tech>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agoeclair_analysis: deviate x86 emulator for Rule 16.2
Nicola Vetrini [Fri, 19 Apr 2024 06:51:24 +0000 (08:51 +0200)]
eclair_analysis: deviate x86 emulator for Rule 16.2

MISRA C Rule 16.2 states:
"A switch label shall only be used when the most closely-enclosing
compound statement is the body of a switch statement".

Since complying with this rule of the x86 emulator would lead to
a lot of code duplication, it is deemed better to exempt those
files for this guideline.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
12 months agoxen/riscv: add minimal stuff to page.h to build full Xen
Oleksii Kurochko [Fri, 19 Apr 2024 06:47:36 +0000 (08:47 +0200)]
xen/riscv: add minimal stuff to page.h to build full Xen

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agoxen/riscv: introduce io.h
Oleksii Kurochko [Fri, 19 Apr 2024 06:47:13 +0000 (08:47 +0200)]
xen/riscv: introduce io.h

The header taken form Linux 6.4.0-rc1 and is based on
arch/riscv/include/asm/mmio.h with the following changes:
- drop forcing of endianess for read*(), write*() functions as
  no matter what CPU endianness, what endianness a particular device
  (and hence its MMIO region(s)) is using is entirely independent.
  Hence conversion, where necessary, needs to occur at a layer up.
  Another one reason to drop endianess conversion here is:
  https://patchwork.kernel.org/project/linux-riscv/patch/20190411115623.5749-3-hch@lst.de/
  One of the answers of the author of the commit:
    And we don't know if Linux will be around if that ever changes.
    The point is:
     a) the current RISC-V spec is LE only
     b) the current linux port is LE only except for this little bit
    There is no point in leaving just this bitrotting code around.  It
    just confuses developers, (very very slightly) slows down compiles
    and will bitrot.  It also won't be any significant help to a future
    developer down the road doing a hypothetical BE RISC-V Linux port.
- drop unused argument of __io_ar() macros.
- drop "#define _raw_{read,write}{b,w,l,d,q} _raw_{read,write}{b,w,l,d,q}"
  as they are unnecessary.
- Adopt the Xen code style for this header, considering that significant changes
  are not anticipated in the future.
  In the event of any issues, adapting them to Xen style should be easily
  manageable.
- drop unnecessary  __r variables in macros read*_cpu()
- update inline assembler constraints for addr argument for
  __raw_read{b,w,l,q} and __raw_write{b,w,l,q} to tell a compiler that
 *addr will be accessed.
- add stubs for __raw_readq() and __raw_writeq() for RISCV_32

Addionally, to the header was added definions of ioremap_*().

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
12 months agoxen/ppc: mm-radix: Replace debug printing code with printk
Shawn Anastasio [Fri, 19 Apr 2024 06:46:29 +0000 (08:46 +0200)]
xen/ppc: mm-radix: Replace debug printing code with printk

Now that we have common code building, there's no need to keep the old
itoa64+debug print function in mm-radix.c

Signed-off-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
12 months agox86/MCE: move intel mcheck init code to separate file
Sergiy Kibrik [Fri, 19 Apr 2024 06:45:23 +0000 (08:45 +0200)]
x86/MCE: move intel mcheck init code to separate file

Separate Intel nonfatal MCE initialization code from generic MCE code, the same
way it is done for AMD code. This is to be able to later make intel/amd MCE
code optional in the build.

Convert to Xen coding style. Clean up unused includes. Remove seemingly
outdated comment about MCE check period.

No functional change intended.

Signed-off-by: Sergiy Kibrik <Sergiy_Kibrik@epam.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
12 months agoxen/gzip: Drop huffman code table tracking
Daniel P. Smith [Wed, 17 Apr 2024 14:37:16 +0000 (10:37 -0400)]
xen/gzip: Drop huffman code table tracking

The memory usage tracking isn't used outside of a debugging option which can't
compile under Xen anyway.  Drop it.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agoxen/gzip: Remove custom memory allocator
Daniel P. Smith [Wed, 17 Apr 2024 14:37:13 +0000 (10:37 -0400)]
xen/gzip: Remove custom memory allocator

All the other decompression routines use xmalloc_bytes(), thus there is no
reason for gzip to be handling its own allocation of memory. In fact, there is
a bug somewhere in the allocator as decompression started to break when adding
additional allocations. Instead of troubleshooting the allocator, replace it
with xmalloc_bytes().

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agoxen/gzip: Drop unused define checks
Daniel P. Smith [Wed, 17 Apr 2024 14:37:11 +0000 (10:37 -0400)]
xen/gzip: Drop unused define checks

Drop various macros and checks which are never used.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agox86/emul: Simplify segment override prefix decoding
Andrew Cooper [Thu, 28 Dec 2023 18:41:30 +0000 (18:41 +0000)]
x86/emul: Simplify segment override prefix decoding

x86_seg_* uses architectural encodings.  Therefore, we can fold the prefix
handling cases together and derive the segment from the prefix byte itself.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
12 months agoxen/efi: Rewrite DOS/PE magic checking without memcmp()
Andrew Cooper [Tue, 16 Apr 2024 15:21:34 +0000 (16:21 +0100)]
xen/efi: Rewrite DOS/PE magic checking without memcmp()

Misra Rule 21.16 doesn't like the use of memcmp() against character arrays (a
string literal in this case).  This is a rare piece of logic where we're
looking for a magic marker that just happens to make sense when expressed as
ASCII.  Rewrite using plain compares.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
12 months agodocs/misra: mark the gzip folder as adopted code
Federico Serafini [Mon, 15 Apr 2024 09:56:30 +0000 (11:56 +0200)]
docs/misra: mark the gzip folder as adopted code

Mark the whole gzip folder as adopted code and remove the redundant
deviation of file inflate.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
12 months agoRevert "public: s/int/int32_t"
Julien Grall [Wed, 17 Apr 2024 12:46:55 +0000 (13:46 +0100)]
Revert "public: s/int/int32_t"

This reverts commit afab29d0882f1d6889c73302fdf04632a492c529.

This is breaking the build. I mistakenly committed the wrong version.

Signed-off-by: Julien Grall <jgrall@amazon.com>
12 months agodocs: arm: Update where Xen should be loaded in memory
Michal Orzel [Fri, 12 Apr 2024 06:16:24 +0000 (08:16 +0200)]
docs: arm: Update where Xen should be loaded in memory

Since commit 6cd046c501bc ("xen/arm: Enlarge identity map space to 10TB")
Xen can be loaded below 10 TiB. Update docs accordingly.

Take the opportunity to update stale links to Linux docs.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>