]> xenbits.xensource.com Git - people/tklengyel/xen.git/log
people/tklengyel/xen.git
2 years agoxen/x86: Make XEN_DOMCTL_get_vcpu_msrs more configurable get_msrs
Tamas K Lengyel [Thu, 22 Sep 2022 18:49:55 +0000 (18:49 +0000)]
xen/x86: Make XEN_DOMCTL_get_vcpu_msrs more configurable

Currently the XEN_DOMCTL_get_vcpu_msrs is only capable of gathering a handful
of predetermined vcpu MSRs. In our use-case gathering the vPMU MSRs by an
external privileged tool is necessary, thus we extend the domctl to allow for
querying for any guest MSRs. To remain compatible with the existing setup if
no specific MSR is requested via the domctl the default list is returned.

Signed-off-by: Tamas K Lengyel <tamas.lengyel@intel.com>
2 years agoUpdate Xen version to 4.17-rc
Julien Grall [Fri, 7 Oct 2022 09:13:41 +0000 (10:13 +0100)]
Update Xen version to 4.17-rc

Signed-off-by: Julien Grall <jgrall@amazon.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
2 years agoConfig.mk pin QEMU_UPSTREAM_REVISION (prep for Xen 4.17 RC1)
Julien Grall [Fri, 7 Oct 2022 09:13:40 +0000 (10:13 +0100)]
Config.mk pin QEMU_UPSTREAM_REVISION (prep for Xen 4.17 RC1)

Signed-off-by: Julien Grall <jgrall@amazon.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
2 years agox86/NUMA: correct off-by-1 in node map population
Jan Beulich [Wed, 5 Oct 2022 08:55:27 +0000 (10:55 +0200)]
x86/NUMA: correct off-by-1 in node map population

As it turns out populate_memnodemap() so far "relied" on
extract_lsb_from_nodes() setting memnodemapsize one too high in edge
cases. Correct the issue there as well, by changing "epdx" to be an
inclusive PDX and adjusting the respective relational operators.

While there also limit the scope of both related variables.

Fixes: b1f4b45d02ca ("x86/NUMA: correct off-by-1 in node map size calculation")
Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
2 years agoxen/arm: fix booting ACPI based system after static evtchn series
Rahul Singh [Fri, 23 Sep 2022 11:02:18 +0000 (12:02 +0100)]
xen/arm: fix booting ACPI based system after static evtchn series

When ACPI is enabled and the system booted with ACPI, BUG() is observed
after merging the static event channel series. As there is no DT when
booted with ACPI there will be no chosen node because of that
"BUG_ON(chosen == NULL)" will be hit.

(XEN) Xen BUG at arch/arm/domain_build.c:3578

Move call to alloc_static_evtchn() under acpi_disabled check to fix the
issue.

Fixes: 1fe16b3ed78a (xen/arm: introduce xen-evtchn dom0less property)
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
[stefano: minor spelling fix in commit message]
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Reviewed-by: Ayan Kumar Halder <ayankuma@amd.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
2 years agoxen: Add static event channel in SUPPORT.md on ARM
Rahul Singh [Fri, 23 Sep 2022 11:02:17 +0000 (12:02 +0100)]
xen: Add static event channel in SUPPORT.md on ARM

Static event channel support is tech preview, which shall be documented
in SUPPORT.md

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Reviewed-by: Ayan Kumar Halder <ayankuma@amd.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
2 years agox86/NUMA: improve memnode_shift calculation for multi node system
Jan Beulich [Fri, 30 Sep 2022 13:16:22 +0000 (15:16 +0200)]
x86/NUMA: improve memnode_shift calculation for multi node system

SRAT may describe individual nodes using multiple ranges. When they're
adjacent (with or without a gap in between), only the start of the first
such range actually needs accounting for. Furthermore the very first
range doesn't need considering of its start address at all, as it's fine
to associate all lower addresses (with no memory) with that same node.
For this to work, the array of ranges needs to be sorted by address -
adjust logic accordingly in acpi_numa_memory_affinity_init().

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
2 years agoArm/vGIC: adjust gicv3_its_deny_access() to fit other gic*_iomem_deny_access(
Jan Beulich [Fri, 30 Sep 2022 07:56:27 +0000 (09:56 +0200)]
Arm/vGIC: adjust gicv3_its_deny_access() to fit other gic*_iomem_deny_access(

While an oversight in 9982fe275ba4 ("arm/vgic: drop const attribute
from gic_iomem_deny_access()"), the issue really became apparent only
when iomem_deny_access() was switched to have a non-const first
parameter.

Fixes: c4e5cc2ccc5b ("x86/ept: limit calls to memory_type_changed()")
Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Tested-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
2 years agox86/NUMA: correct off-by-1 in node map size calculation
Jan Beulich [Fri, 30 Sep 2022 07:55:34 +0000 (09:55 +0200)]
x86/NUMA: correct off-by-1 in node map size calculation

extract_lsb_from_nodes() accumulates "memtop" from all PDXes one past
the covered ranges. Hence the maximum address which can validly by used
to index the node map is one below this value, and we may currently set
up a node map with an unused (and never initialized) trailing entry. In
boundary cases this may also mean we dynamically allocate a page when
the static (64-entry) map would suffice.

While there also correct the comment ahead of the function, for it to
match the actual code: Linux commit 54413927f022 ("x86-64:
x86_64-make-the-numa-hash-function-nodemap-allocation fix fix") removed
the ORing in of the end address before we actually cloned their code.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Wei Chen <Wei.Chen@arm.com>
2 years agox86/vpmu: Fix race-condition in vpmu_load
Tamas K Lengyel [Fri, 30 Sep 2022 07:53:49 +0000 (09:53 +0200)]
x86/vpmu: Fix race-condition in vpmu_load

The vPMU code-bases attempts to perform an optimization on saving/reloading the
PMU context by keeping track of what vCPU ran on each pCPU. When a pCPU is
getting scheduled, checks if the previous vCPU isn't the current one. If so,
attempts a call to vpmu_save_force. Unfortunately if the previous vCPU is
already getting scheduled to run on another pCPU its state will be already
runnable, which results in an ASSERT failure.

Fix this by always performing a pmu context save in vpmu_save when called from
vpmu_switch_from, and do a vpmu_load when called from vpmu_switch_to.

While this presents a minimal overhead in case the same vCPU is getting
rescheduled on the same pCPU, the ASSERT failure is avoided and the code is a
lot easier to reason about.

Signed-off-by: Tamas K Lengyel <tamas.lengyel@intel.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agoautomation: Information about running containers for a different arch
Anthony PERARD [Thu, 29 Sep 2022 09:51:31 +0000 (10:51 +0100)]
automation: Information about running containers for a different arch

Adding pointer to 'qemu-user-static'.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
2 years agoxen/arm: domain_build: Always print the static shared memory region
Michal Orzel [Mon, 19 Sep 2022 18:37:37 +0000 (20:37 +0200)]
xen/arm: domain_build: Always print the static shared memory region

At the moment, the information about allocating static shared memory
region is only printed during the debug build. This information can also
be helpful for the end user (which may not be the same as the person
building the package), so switch to printk(). Also drop XENLOG_INFO to be
consistent with other printk() used to print the domain information.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
2 years agox86: wire up VCPUOP_register_vcpu_time_memory_area for 32-bit guests
Jan Beulich [Thu, 29 Sep 2022 12:47:45 +0000 (14:47 +0200)]
x86: wire up VCPUOP_register_vcpu_time_memory_area for 32-bit guests

Forever sinced its introduction VCPUOP_register_vcpu_time_memory_area
was available only to native domains. Linux, for example, would attempt
to use it irrespective of guest bitness (including in its so called
PVHVM mode) as long as it finds XEN_PVCLOCK_TSC_STABLE_BIT set (which we
set only for clocksource=tsc, which in turn needs engaging via command
line option).

Fixes: a5d39947cb89 ("Allow guests to register secondary vcpu_time_info")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
2 years agox86: re-connect VCPUOP_send_nmi for 32-bit guests
Jan Beulich [Thu, 29 Sep 2022 12:46:50 +0000 (14:46 +0200)]
x86: re-connect VCPUOP_send_nmi for 32-bit guests

With the "inversion" of VCPUOP handling, processing arch-specific ones
first, the forwarding of this sub-op from the (common) compat handler to
(common) non-compat one did no longer have the intended effect. It now
needs forwarding between the arch-specific handlers.

Fixes: 8a96c0ea7999 ("xen: move do_vcpu_op() to arch specific code")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
2 years agox86/ept: limit calls to memory_type_changed()
Roger Pau Monné [Thu, 29 Sep 2022 12:44:10 +0000 (14:44 +0200)]
x86/ept: limit calls to memory_type_changed()

memory_type_changed() is currently only implemented for Intel EPT, and
results in the invalidation of EMT attributes on all the entries in
the EPT page tables.  Such invalidation causes EPT_MISCONFIG vmexits
when the guest tries to access any gfns for the first time, which
results in the recalculation of the EMT for the accessed page.  The
vmexit and the recalculations are expensive, and as such should be
avoided when possible.

Remove the call to memory_type_changed() from
XEN_DOMCTL_memory_mapping: there are no modifications of the
iomem_caps ranges anymore that could alter the return of
cache_flush_permitted() from that domctl.

Encapsulate calls to memory_type_changed() resulting from changes to
the domain iomem_caps or ioport_caps ranges in the helpers themselves
(io{ports,mem}_{permit,deny}_access()), and add a note in
epte_get_entry_emt() to remind that changes to the logic there likely
need to be propagaed to the IO capabilities helpers.

Note changes to the IO ports or memory ranges are not very common
during guest runtime, but Citrix Hypervisor has an use case for them
related to device passthrough.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2 years agoarm/vgic: drop const attribute from gic_iomem_deny_access()
Roger Pau Monné [Thu, 29 Sep 2022 12:41:13 +0000 (14:41 +0200)]
arm/vgic: drop const attribute from gic_iomem_deny_access()

While correct from a code point of view, the usage of the const
attribute for the domain parameter of gic_iomem_deny_access() is at
least partially bogus.  Contents of the domain structure (the iomem
rangeset) is modified by the function.  Such modifications succeed
because right now the iomem rangeset is allocated separately from
struct domain, and hence is not subject to the constness of struct
domain.

Amend this by dropping the const attribute from the function
parameter.

This is required by further changes that will convert
iomem_{permit,deny}_access into a function.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
2 years agox86/NUMA: correct memnode_shift calculation for single node system
Jan Beulich [Thu, 29 Sep 2022 12:39:52 +0000 (14:39 +0200)]
x86/NUMA: correct memnode_shift calculation for single node system

SRAT may describe even a single node system (including such with
multiple nodes, but only one having any memory) using multiple ranges.
Hence simply counting the number of ranges (note that function
parameters are mis-named) is not an indication of the number of nodes in
use. Since we only care about knowing whether we're on a single node
system, accounting for this is easy: Increment the local variable only
when adjacent ranges are for different nodes. That way the count may
still end up larger than the number of nodes in use, but it won't be
larger than 1 when only a single node has any memory.

To compensate populate_memnodemap() now needs to be prepared to find
the correct node ID already in place for a range. (This could of course
also happen when there's more than one node with memory, while at least
one node has multiple adjacent ranges, provided extract_lsb_from_nodes()
would also know to recognize this case.)

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
2 years agoMAINTAINERS: ARINC 653 scheduler maintainer updates
Stewart Hildebrand [Thu, 29 Sep 2022 12:38:22 +0000 (14:38 +0200)]
MAINTAINERS: ARINC 653 scheduler maintainer updates

Add Nathan Studer as co-maintainer.

I am departing DornerWorks. I will still be working with Xen in my next
role, and I still have an interest in co-maintaining the ARINC 653
scheduler, so change to my personal email address.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@dornerworks.com>
Acked-by: Nathan Studer <nathan.studer@dornerworks.com>
2 years agotools: remove xenstore entries on vchan server closure
Oleksandr Andrushchenko [Thu, 29 Sep 2022 12:38:02 +0000 (14:38 +0200)]
tools: remove xenstore entries on vchan server closure

vchan server creates XenStore entries to advertise its event channel and
ring, but those are not removed after the server quits.
Add additional cleanup step, so those are removed, so clients do not try
to connect to a non-existing server.

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Signed-off-by: Dmytro Semenets <dmytro_semenets@epam.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
2 years agoCI: Force CONFIG_XEN_IBT in the buster-gcc-ibt test
Andrew Cooper [Mon, 26 Sep 2022 13:02:13 +0000 (14:02 +0100)]
CI: Force CONFIG_XEN_IBT in the buster-gcc-ibt test

buster-gcc-ibt is a dedicated test to run a not-yet-upstreamed compiler patch
which is relevant to CONFIG_XEN_IBT in 4.17 and later.

Force it on, rather than having 50% of the jobs not testing what they're
supposed to be testing.

Fixes: 5d59421815d5 ("x86: Use control flow typechecking where possible")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
[stefano: minor code style improvement]
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
2 years agoautomation: qemu-smoke-arm{32/64}.sh: Fix typo in DEBIAN_FRONTENT
Michal Orzel [Tue, 27 Sep 2022 09:47:18 +0000 (11:47 +0200)]
automation: qemu-smoke-arm{32/64}.sh: Fix typo in DEBIAN_FRONTENT

The correct variable name is DEBIAN_FRONTEND and not DEBIAN_FRONTENT.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoBuild: Drop -no-pie from EMBEDDED_EXTRA_CFLAGS
Andrew Cooper [Tue, 27 Sep 2022 15:47:08 +0000 (16:47 +0100)]
Build: Drop -no-pie from EMBEDDED_EXTRA_CFLAGS

This breaks all Clang builds, as demostrated by Gitlab CI.

Contrary to the description in ecd6b9759919, -no-pie is not even an option
passed to the linker.  GCC's actual behaviour is to inhibit the passing of
-pie to the linker, as well as selecting different cr0 artefacts to be linked.

EMBEDDED_EXTRA_CFLAGS is not used for $(CC)-doing-linking, and not liable to
gain such a usecase.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Tested-by: Stefano Stabellini <sstabellini@kernel.org>
Fixes: ecd6b9759919 ("Config.mk: correct PIE-related option(s) in EMBEDDED_EXTRA_CFLAGS")
2 years agodrivers/char: Fix build when CET-IBT is enabled
Andrew Cooper [Mon, 26 Sep 2022 10:46:15 +0000 (11:46 +0100)]
drivers/char: Fix build when CET-IBT is enabled

https://gitlab.com/xen-project/xen/-/jobs/3083068950#L1763

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Fixes: 022e40edd4dc ("drivers/char: allow using both dbgp=xhci and dbgp=ehci")
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
2 years agoautomation: Use custom build jobs when extra config options are needed
Michal Orzel [Mon, 26 Sep 2022 11:04:14 +0000 (13:04 +0200)]
automation: Use custom build jobs when extra config options are needed

Currently, all the arm64 defconfig build jobs, regardless of the
container used, end up building Xen with the extra config options
specified in the main build script (e.g. CONFIG_EXPERT,
CONFIG_STATIC_MEMORY). Because these options are only needed for
specific test jobs, the current behavior of the CI is incorrect
as we add the extra options to all the defconfig builds. This means
that on arm64 there is not a single job performing proper defconfig build.

To fix this issue, add custom build jobs each time there is a need for
building Xen with additional config options. Introduce EXTRA_XEN_CONFIG
variable to be used by these jobs to store the required options. This
variable will be then read by the main build script to modify the .config
file. This will also help users to understand what is needed to run specific
test.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agobuild: fix x86 out-of-tree build without EFI
Anthony PERARD [Mon, 26 Sep 2022 09:16:04 +0000 (11:16 +0200)]
build: fix x86 out-of-tree build without EFI

We can't have a source file with the same name that exist in both the
common code and in the arch specific code for efi/. This can lead to
confusion in make and it can pick up the wrong source file. This issue
lead to a failure to build a pv-shim for x86 out-of-tree, as this is
one example of an x86 build using the efi/stub.c.

The issue is that in out-of-tree, make might find x86/efi/stub.c via
VPATH, but as the target needs to be rebuilt due to FORCE, make
actually avoid changing the source tree and rebuilt the target with
VPATH ignored, so $@ lead to the build tree where "stub.c" doesn't
exist yet so a link is made to "common/stub.c".

Rework the new common/stub.c file to have a different name than the
already existing one, by renaming the existing one. We can hide the
compat aliases that x86 uses behind CONFIG_COMPAT so a Arm build will
not have them.

Also revert the change to the rule that creates symbolic links it's
better to just recreate the link in cases where an existing file exist
or the link goes to the wrong file.

Avoid using $(EFIOBJ-y) as an alias for $(clean-files), add
"stub.c" directly to $(clean-files).

Also update .gitignore as this was also missing from the original
patch.

Fixes: 7f96859b0d00 ("xen: reuse x86 EFI stub functions for Arm")
Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
2 years agoxsm/flask: adjust print messages to use %pd
Daniel P. Smith [Mon, 26 Sep 2022 09:14:19 +0000 (11:14 +0200)]
xsm/flask: adjust print messages to use %pd

Print messages from flask use an inconsistent format when printing the domain
id. When referencing system domains, the domain id is printed which is not
immediately identifiable. The %pd conversion specifier provides a consistent
and clear way to format for the domain id. In addition this will assist in
aligning FLASK with current hypervisor code practices.

While addressing the domain id formating, two related issues were addressed.
The first being that avc_printk() was not applying any conversion specifier
validation. To address this, the printf annotation was added to avc_printk() to
help ensure the correct types are passed to each conversion specifier. The second
was concern that source and target domains were being appropriately reported for
an AVC. This was addressed by simplifying the conditional logic.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Jason Andryuk <jandryuk@gmail.com>
2 years agodrivers/char: add console=ehci as an alias for console=dbgp
Marek Marczykowski-Górecki [Mon, 26 Sep 2022 09:13:31 +0000 (11:13 +0200)]
drivers/char: add console=ehci as an alias for console=dbgp

Make it consistent with console=xhci.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agodrivers/char: allow driving the rest of XHCI by a domain while Xen uses DbC
Marek Marczykowski-Górecki [Mon, 26 Sep 2022 09:13:06 +0000 (11:13 +0200)]
drivers/char: allow driving the rest of XHCI by a domain while Xen uses DbC

That's possible, because the capability was designed specifically to
allow separate driver handle it, in parallel to unmodified xhci driver
(separate set of registers, pretending the port is "disconnected" for
the main xhci driver etc). It works with Linux dom0, although requires
an awful hack - re-enabling bus mastering behind dom0's backs.
Linux driver does similar thing - see
drivers/usb/early/xhci-dbc.c:xdbc_handle_events().

When controller sharing is enabled in kconfig (option marked as
experimental), dom0 is allowed to use the controller even if Xen uses it
for debug console. Additionally, option `dbgp=xhci,share=` is available
to either prevent even dom0 from using it (`no` value), or allow any
domain using it (`any` value).

In any case, to avoid Linux messing with the DbC, mark this MMIO area as
read-only. This might cause issues for Linux's driver (if it tries to
write something on the same page - like anoter xcap), but makes Xen's
use safe. In practice, as of Linux 5.18, it seems to work without
issues.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2 years agodrivers/char: fix handling cable re-plug in XHCI console driver
Marek Marczykowski-Górecki [Mon, 26 Sep 2022 09:12:39 +0000 (11:12 +0200)]
drivers/char: fix handling cable re-plug in XHCI console driver

When cable is unplugged, dbc_ensure_running() correctly detects this
situation (DBC_CTRL_DCR flag is clear), and prevent sending data
immediately to the device. It gets only queued in work ring buffers.
When cable is plugged in again, subsequent dbc_flush() will send the
buffered data.
But there is a corner case, where no subsequent data was buffered in the
work buffer, but a TRB was still pending. Ring the doorbell to let the
controller re-send them. For console output it is rare corner case (TRB
is pending for a very short time), but for console input it is very
normal case (there is always one pending TRB for input).

Extract doorbell ringing into separate function to avoid duplication.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agodrivers/char: add RX support to the XHCI driver
Marek Marczykowski-Górecki [Mon, 26 Sep 2022 09:12:03 +0000 (11:12 +0200)]
drivers/char: add RX support to the XHCI driver

Add another work ring buffer for received data, and point IN TRB at it.
Ensure there is always at least one pending IN TRB, so the controller
has a way to send incoming data to the driver.
Note that both "success" and "short packet" completion codes are okay -
in fact it will be "short packet" most of the time, as the TRB length is
about maximum size, not required size.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agodrivers/char: mark DMA buffers as reserved for the XHCI
Marek Marczykowski-Górecki [Mon, 26 Sep 2022 09:11:33 +0000 (11:11 +0200)]
drivers/char: mark DMA buffers as reserved for the XHCI

The important part is to include those buffers in IOMMU page table
relevant for the USB controller. Otherwise, DbC will stop working as
soon as IOMMU is enabled, regardless of to which domain device assigned
(be it xen or dom0).
If the device is passed through to dom0 or other domain (see later
patches), that domain will effectively have access to those buffers too.
It does give such domain yet another way to DoS the system (as is the
case when having PCI device assigned already), but also possibly steal
the console ring content. Thus, such domain should be a trusted one.
In any case, prevent anything else being placed on those pages by adding
artificial padding.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agoIOMMU/AMD: wire common device reserved memory API
Marek Marczykowski-Górecki [Mon, 26 Sep 2022 09:11:07 +0000 (11:11 +0200)]
IOMMU/AMD: wire common device reserved memory API

Register common device reserved memory similar to how ivmd= parameter is
handled.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agoIOMMU: add common API for device reserved memory
Marek Marczykowski-Górecki [Mon, 26 Sep 2022 09:10:31 +0000 (11:10 +0200)]
IOMMU: add common API for device reserved memory

Add API similar to rmrr= and ivmd= arguments, but in a common code. This
will allow drivers to register reserved memory regardless of the IOMMU
vendor.
The direct reason for this API is xhci-dbc console driver (aka xue),
that needs to use DMA. But future change may unify command line
arguments for user-supplied reserved memory, and it may be useful for
other drivers in the future too.

This commit just introduces an API, subsequent patches will plug it in
appropriate places. The reserved memory ranges needs to be saved
locally, because at the point when they are collected, Xen doesn't know
yet which IOMMU driver will be used.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agodrivers/char: allow using both dbgp=xhci and dbgp=ehci
Marek Marczykowski-Górecki [Mon, 26 Sep 2022 09:09:19 +0000 (11:09 +0200)]
drivers/char: allow using both dbgp=xhci and dbgp=ehci

This allows configuring EHCI and XHCI consoles separately,
simultaneously, such that e.g. one can be used for the console and the
other by the debugger.

This changes string_param() to custom_param() in both ehci and xhci
drivers. Both drivers parse only values applicable to them.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agobuild: correct cppcheck-misra make rule
Jan Beulich [Mon, 26 Sep 2022 09:07:48 +0000 (11:07 +0200)]
build: correct cppcheck-misra make rule

Having cppcheck-misra.json depend on cppcheck-misra.txt does not
properly address the multiple targets problem. If cppcheck-misra.json
is deleted from the build tree but cppcheck-misra.txt is still there,
nothing will re-generate cppcheck-misra.json.

With GNU make 4.3 or newer we could use the &: grouped target separator,
but since we support older make as well we need to use some other
mechanism. Convert the rule to a pattern one (with "cppcheck" kind of
arbitrarily chosen as the stem), thus making known to make that both
files are created by a single command invocation. Since, as a result,
the JSON file is now "intermediate" from make's perspective, prevent it
being deleted again by making it a prereq of .PRECIOUS.

Fixes: 57caa5375321 ("xen: Add MISRA support to cppcheck make rule")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
2 years agoxsm/flask: correcting initial sid assignment on context allocation
Daniel P. Smith [Wed, 14 Sep 2022 13:22:01 +0000 (15:22 +0200)]
xsm/flask: correcting initial sid assignment on context allocation

The current flow for initial SID assignment is that the function
flask_domain_alloc_security() allocates the security context and assigns an
initial SID based on the limited state information it can access. Specifically
the initial SID is determined by the domid of the domain, where it would assign
the label for one of the domains the hypervisor constructed with the exception
of initial domain (dom0). In the case of the initial domain and all other
domains it would use the unlabeled_t SID.

When it came to the SID for the initial domain, its assignment was managed by
flask_domain_create() where it would be switched from unlabeled_t to dom0_t.
This logic worked under the assumption that the first call to
flask_domain_create() would be the hypervisor constructing the initial domain.
After which it would be the toolstack constructing the domain, for which it is
expected to provide an appropriate SID or else unlabeled_t would be used.

The issue is that the assumptions upon which the current flow is built were
weak and are invalid for PV shim and dom0less. Under the current flow even
though the initial domain for PV shim is not set as privileged, flask would
label the domain as dom0_t. For dom0less, the situation is two-fold. First is
that every domain after the first domain creation will fail as they will be
labeled as unlabeled_t. The second is that if the dom0less configuration does
not include a "dom0", the first domain created would be labeled as dom0_t.

This commit only seeks to address the situation for PV shim, by including a
check for xenboot_t context in flask_domain_alloc_security() to determine if
the domain is being constructed at system boot. Then a check for is_privilged
and pv_shim is added to differentiate between a "dom0" initial domain and a PV
shim initial domain.

The logic for flask_domain_create() was altered to allow the incoming SID to
override the initial label. This allows a domain builder, whether it is a
toolstack, dom0less, or hyperlaunch, to provide the correct label for the
domain at construction.

The base policy was adjusted to allow the idle domain under the xenboot_t
context the ability to construct domains of both types, dom0_t and domu_t.
This will enable a hypervisor resident domain builder to construct domains
beyond the initial domain,

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Reviewed-by: Jason Andryuk <jandryuk@gmail.com>
2 years agoxen/arm, device-tree: Make static-mem use #{address,size}-cells
Henry Wang [Fri, 9 Sep 2022 05:23:57 +0000 (05:23 +0000)]
xen/arm, device-tree: Make static-mem use #{address,size}-cells

In order to keep consistency in the device tree binding, there is
no need for static memory allocation feature to define a specific
set of address and size cells for "xen,static-mem" property.

Therefore, this commit reuses the regular #{address,size}-cells
for parsing the device tree "xen,static-mem" property. Update
the documentation accordingly.

Also, take the chance to remove the unnecessary "#address-cells"
and "#size-cells" in the domU1 node of the device tree to only
emphasize the related part that the example is showing.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/pci: replace call to is_memory_hole to pci_check_bar
Rahul Singh [Fri, 9 Sep 2022 09:34:40 +0000 (10:34 +0100)]
xen/pci: replace call to is_memory_hole to pci_check_bar

is_memory_hole was implemented for x86 and not for ARM when introduced.
Replace is_memory_hole call to pci_check_bar as function should check
if device BAR is in defined memory range. Also, add an implementation
for ARM which is required for PCI passthrough.

On x86, pci_check_bar will call is_memory_hole which will check if BAR
is not overlapping with any memory region defined in the memory map.

On ARM, pci_check_bar will go through the host bridge ranges and check
if the BAR is in the range of defined ranges.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: pci: modify pci_find_host_bridge_node argument to const pdev
Rahul Singh [Fri, 9 Sep 2022 09:34:39 +0000 (10:34 +0100)]
xen/arm: pci: modify pci_find_host_bridge_node argument to const pdev

Modify pci_find_host_bridge_node argument to const pdev to avoid
converting the dev to pdev in pci_find_host_bridge_node and also
constify the return.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
2 years agoxen: Add static memory sharing in SUPPORT.md
Penny Zheng [Thu, 8 Sep 2022 13:55:13 +0000 (21:55 +0800)]
xen: Add static memory sharing in SUPPORT.md

on ARM, static memory sharing is tech preview, which shall be documented
in SUPPORT.md

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/arm: enable statically shared memory on Dom0
Penny Zheng [Thu, 8 Sep 2022 13:55:12 +0000 (21:55 +0800)]
xen/arm: enable statically shared memory on Dom0

To add statically shared memory nodes in Dom0, user shall put according
static shared memory configuration under /chosen node.

This commit adds shm-processing function process_shm in construct_dom0
to enable statically shared memory on Dom0.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: create shared memory nodes in guest device tree
Penny Zheng [Thu, 8 Sep 2022 13:55:11 +0000 (21:55 +0800)]
xen/arm: create shared memory nodes in guest device tree

We expose the shared memory to the domU using the "xen,shared-memory-v1"
reserved-memory binding. See
Documentation/devicetree/bindings/reserved-memory/xen,shared-memory.txt
in Linux for the corresponding device tree binding.

To save the cost of re-parsing shared memory device tree configuration when
creating shared memory nodes in guest device tree, this commit adds new field
"shm_mem" to store shm-info per domain.

For each shared memory region, a range is exposed under
the /reserved-memory node as a child node. Each range sub-node is
named xen-shmem@<address> and has the following properties:
- compatible:
        compatible = "xen,shared-memory-v1"
- reg:
        the base guest physical address and size of the shared memory region
- xen,id:
        a string that identifies the shared memory region.
- xen,offset: (borrower VMs only)
        64 bit integer offset within the owner virtual machine's shared
        memory region used for the mapping in the borrower VM.
Currently, we provide "xen,offset=<0x0>" as a temporary placeholder.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
[stefano: fix code style, add return -EOPNOTSUPP;]
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
2 years agoxen/arm: set up shared memory foreign mapping for borrower domain
Penny Zheng [Thu, 8 Sep 2022 13:55:10 +0000 (21:55 +0800)]
xen/arm: set up shared memory foreign mapping for borrower domain

This commit sets up shared memory foreign mapping for borrower domain.

If owner domain is the default dom_io, all shared domain are treated as
borrower domain.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: Add additional reference to owner domain when the owner is allocated
Penny Zheng [Thu, 8 Sep 2022 13:55:09 +0000 (21:55 +0800)]
xen/arm: Add additional reference to owner domain when the owner is allocated

Borrower domain will fail to get a page ref using the owner domain
during allocation, when the owner is created after borrower.

So here, we decide to get and add the right amount of reference, which
is the number of borrowers, when the owner is allocated.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/arm: introduce put_page_nr and get_page_nr
Penny Zheng [Thu, 8 Sep 2022 13:55:08 +0000 (21:55 +0800)]
xen/arm: introduce put_page_nr and get_page_nr

Later, we need to add the right amount of references, which should be
the number of borrower domains, to the owner domain. Since we only have
get_page() to increment the page reference by 1, a loop is needed per
page, which is inefficient and time-consuming.

To save the loop time, this commit introduces a set of new helpers
put_page_nr() and get_page_nr() to increment/drop the page reference by nr.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/arm: allocate static shared memory to a specific owner domain
Penny Zheng [Thu, 8 Sep 2022 13:55:07 +0000 (21:55 +0800)]
xen/arm: allocate static shared memory to a specific owner domain

If owner property is defined, then owner domain of a static shared memory
region is not the default dom_io anymore, but a specific domain.

This commit implements allocating static shared memory to a specific domain
when owner property is defined.

Coding flow for dealing borrower domain will be introduced later in the
following commits.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: assign static shared memory to the default owner dom_io
Penny Zheng [Thu, 8 Sep 2022 13:55:06 +0000 (21:55 +0800)]
xen/arm: assign static shared memory to the default owner dom_io

This commit introduces process_shm to cope with static shared memory in
domain construction.

DOMID_IO will be the default owner of memory pre-shared among multiple domains
at boot time, when no explicit owner is specified.
And DOMID_IO is a fake domain and is not described in the Device-Tree.
Therefore When the owner of the shared region is DOMID_IO, we will only
find the borrowers when parsing the Device-Tree.
When we found the first borrower of the region, we need to assign the region to
DOMID_IO

This commit only considers allocating static shared memory to dom_io
when owner domain is not explicitly defined in device tree, all the left,
including the "borrower" code path, the "explicit owner" code path, shall
be introduced later in the following patches.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/arm: introduce static shared memory
Penny Zheng [Thu, 8 Sep 2022 13:55:05 +0000 (21:55 +0800)]
xen/arm: introduce static shared memory

This patch series introduces a new feature: setting up static
shared memory on a dom0less system, through device tree configuration.

This commit parses shared memory node at boot-time, and reserve it in
bootinfo.reserved_mem to avoid other use.

This commits proposes a new Kconfig CONFIG_STATIC_SHM to wrap
static-shm-related codes, and this option depends on static memory(
CONFIG_STATIC_MEMORY). That's because that later we want to reuse a few
helpers, guarded with CONFIG_STATIC_MEMORY, like acquire_staticmem_pages, etc,
on static shared memory.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/gnttab: fix gnttab_acquire_resource()
Juergen Gross [Fri, 9 Sep 2022 12:53:47 +0000 (14:53 +0200)]
xen/gnttab: fix gnttab_acquire_resource()

Commit 9dc46386d89d ("gnttab: work around "may be used uninitialized"
warning") was wrong, as vaddrs can legitimately be NULL in case
XENMEM_resource_grant_table_id_status was specified for a grant table
v1. This would result in crashes in debug builds due to
ASSERT_UNREACHABLE() triggering.

Check vaddrs only to be NULL in the rc == 0 case.

Expand the tests in tools/tests/resource to tickle this path, and verify that
using XENMEM_resource_grant_table_id_status on a v1 grant table fails.

Fixes: 9dc46386d89d ("gnttab: work around "may be used uninitialized" warning")
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com> # xen
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
2 years agodocs/device-tree: Place the static-heap dt-binding in proper place
Henry Wang [Thu, 8 Sep 2022 12:07:28 +0000 (12:07 +0000)]
docs/device-tree: Place the static-heap dt-binding in proper place

The static-heap dt-binding should be placed after the last feature,
namely static-evtchn.

Fixes: 4596329291f5 ("docs, xen/arm: Introduce static heap memory")
Signed-off-by: Henry Wang <Henry.Wang@arm.com>
Acked-by: Julien Grall <jgrall@amazon.com>
2 years agoautomation: Add a new job for testing boot time cpupools on arm64
Michal Orzel [Thu, 8 Sep 2022 09:22:30 +0000 (11:22 +0200)]
automation: Add a new job for testing boot time cpupools on arm64

Add a new test job qemu-smoke-arm64-gcc-boot-cpupools that will execute
script qemu-smoke-arm64.sh to test boot time cpupools feature.
Enable CONFIG_BOOT_TIME_CPUPOOLS for the arm64 build and add a new test
case in qemu-smoke-arm64.sh that if selected will make use of the
ImageBuilder feature to create cpupool with cpu@1, null scheduler and
assign it to domU. Add a check in dom0 xen.start to see if domU is
assigned a Pool-1 with null scheduler.

Take the opportunity to refactor the qemu-smoke-arm64.sh script as
follows:
 - use domU_check to store the test's commands to be run from domU
 - use dom0_check to store the test's commands to be run from dom0
 - use fdtput instead of sed to perform dtb modifications
 - use more meaningful messages for "passed" variable. This way we can
   grep for messages reported either by domU or dom0 and get rid of
   assumption that tests can only be run from domU

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoautomation: qemu-smoke-arm64: Silence ifconfig error messages
Michal Orzel [Thu, 8 Sep 2022 09:22:29 +0000 (11:22 +0200)]
automation: qemu-smoke-arm64: Silence ifconfig error messages

During the ping test, dom1 tries to assign an ip to eth0 in a loop.
Before setting up the network interface by dom0, this results in
printing the following error message several times:
(XEN) DOM1: ifconfig: SIOCSIFADDR: No such device

Silence this by redirecting stderr/stdout to /dev/null as we do not
care about the output and we should not pollute the log file.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Ayan Kumar Halder <ayankuma@amd.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoautomation: qemu-alpine-arm64-gcc: Use kernel 5.19
Michal Orzel [Thu, 8 Sep 2022 09:22:28 +0000 (11:22 +0200)]
automation: qemu-alpine-arm64-gcc: Use kernel 5.19

After qemu-smoke-arm64 was changed to use kernel 5.19 we end up having
two kernel configurations. This is something not needed and maintaining
a single kernel version is always easier. Modify qemu-alpine-arm64-gcc
to use kernel 5.19 and remove kernel 5.9 from tests-artifacts.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Ayan Kumar Halder <ayankuma@amd.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agotools/xenstore: add migration stream extensions for new features
Juergen Gross [Thu, 8 Sep 2022 08:15:52 +0000 (10:15 +0200)]
tools/xenstore: add migration stream extensions for new features

Extend the definition of the Xenstore migration stream to cover new
features:

- per domain features
- extended watches (watch depth)
- per domain quota

Some of those additions (per domain features and extended watches)
require bumping the migration stream version to "2", as usage of those
features will require to transport mandatory new information in the
migration stream.

One note regarding the GLOBAL_QUOTA_DATA record: the split of quota
between global and per-domain ones is meant to support the possibility
to pass on unknown quota settings for newly created domains to other
Xenstore instances:

Imagine Xenstore A knows about global quota g and domain quota d, while
Xenstore B doesn't know both. Initially I'm running Xenstore A on a
host, then I'm live-updating to B.

B gets the information that g is global, and d is per-domain, but has
no other idea what to do with the values of g and d. OTOH it knows that
each new domain should get d with the related value, so it can set d
for each newly created domain.

When B is either downgraded to A again, or a domain is migrated to
another host running A, B can add the quota information of d for all
domains.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/arm: Handle static heap pages in boot and heap allocator
Henry Wang [Thu, 8 Sep 2022 11:09:10 +0000 (11:09 +0000)]
xen/arm: Handle static heap pages in boot and heap allocator

This commit firstly adds a bool field `static_heap` to bootinfo.
This newly introduced field is set at the device tree parsing time
if the static heap ranges are defined in the device tree chosen
node.

For Arm32, In `setup_mm`, if the static heap is enabled, we use the
static heap region for both domheap and xenheap allocation. Note
that the xenheap on Arm32 should be always contiguous, so also add
a helper fit_xenheap_in_static_heap() for Arm32 to find the required
xenheap in the static heap regions.

For Arm64, In `setup_mm`, if the static heap is enabled and used,
we make sure that only these static heap pages are added to the boot
allocator. These static heap pages in the boot allocator are
added to the heap allocator at `end_boot_allocator()`.

If the static heap is disabled, we stick to current page allocation
strategy at boot time.

Also, take the chance to correct a "double not" print in Arm32
`setup_mm()` and replace the open-coding address ~0 by INVALID_PADDR.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/arm: mm: Rename xenheap_* variable to directmap_*
Henry Wang [Thu, 8 Sep 2022 11:09:09 +0000 (11:09 +0000)]
xen/arm: mm: Rename xenheap_* variable to directmap_*

With the static heap setup, keep using xenheap_* in the function
setup_xenheap_mappings() will make the code confusing to read,
because we always need to map the full RAM on Arm64. Therefore,
renaming all "xenheap_*" variables to "directmap_*" to make clear
the area is used to access the RAM easily.

On Arm32, only the xenheap is direct mapped today. So the renaming
to "directmap_*" would be still valid for Arm32.

As the xenheap_* is renamed to directmap_*, rename the function
setup_xenheap_mappings() to setup_directmap_mappings() to reflect
the variable renaming, also change the code comment and printed
error message in the function accordingly.

No functional change is intended.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
Acked-by: Julien Grall <jgrall@amazon.com>
2 years agodocs, xen/arm: Introduce static heap memory
Henry Wang [Thu, 8 Sep 2022 11:09:08 +0000 (11:09 +0000)]
docs, xen/arm: Introduce static heap memory

This commit introduces the static heap memory, which is parts of RAM
reserved in the beginning of the boot time for heap.

Firstly, since a new type of memory bank is needed for marking the
memory bank solely as the heap, this commit defines `enum membank_type`
and use this enum in function device_tree_get_meminfo(). Changes of
code are done accordingly following the introduction of this enum.

Also, this commit introduces the logic to parse the static heap
configuration in device tree. If the memory bank is reserved as heap
through `xen,static-heap` property in device tree `chosen` node, the
memory will be marked as static heap type.

A documentation section is added, describing the definition of static
heap memory and the method of enabling the static heap memory through
device tree at boot time.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/arm: bootfdt: Make process_chosen_node() return int
Henry Wang [Thu, 8 Sep 2022 11:09:07 +0000 (11:09 +0000)]
xen/arm: bootfdt: Make process_chosen_node() return int

At the boot time, it is saner to stop booting early if an error occurs
when parsing the device tree chosen node, rather than seeing random
behavior afterwards. Therefore, this commit changes the return type of
the process_chosen_node() from void to int, and return correct errno
based on the error type.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/arm: introduce xen-evtchn dom0less property
Rahul Singh [Wed, 7 Sep 2022 16:27:38 +0000 (17:27 +0100)]
xen/arm: introduce xen-evtchn dom0less property

Introduce a new sub-node under /chosen node to establish static event
channel communication between domains on dom0less systems.

An event channel will be created beforehand to allow the domains to
send notifications to each other.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: introduce new xen,enhanced property value
Rahul Singh [Wed, 7 Sep 2022 16:27:37 +0000 (17:27 +0100)]
xen/arm: introduce new xen,enhanced property value

Introduce a new "xen,enhanced" dom0less property value "no-xenstore" to
disable xenstore interface for dom0less guests.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/evtchn: modify evtchn_bind_interdomain to support static evtchn
Rahul Singh [Wed, 7 Sep 2022 16:27:36 +0000 (17:27 +0100)]
xen/evtchn: modify evtchn_bind_interdomain to support static evtchn

Static event channel support will be added for dom0less domains. Modify
evtchn_bind_interdomain to support static evtchn.

It is necessary to have access to the evtchn_bind_interdomain function
to do that, so make evtchn_bind_interdomain global and also make it
__must_check.

Currently evtchn_bind_interdomain() always allocates the next available
local port. Static event channel support for dom0less domains requires
allocating a specified port. Modify the evtchn_bind_interdomain to
accept the port number as an argument and allocate the specified port
if available. If the port number argument is zero, the next available
port will be allocated.

Currently evtchn_bind_interdomain() finds the local domain from
"current->domain" pointer. evtchn_bind_interdomain() will be called from
the XEN to create static event channel during domain creation.
"current" pointer is not valid at that time, therefore modify the
evtchn_bind_interdomain() to pass domain as an argument.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/evtchn: modify evtchn_alloc_unbound to allocate specified port
Rahul Singh [Wed, 7 Sep 2022 16:27:35 +0000 (17:27 +0100)]
xen/evtchn: modify evtchn_alloc_unbound to allocate specified port

Currently evtchn_alloc_unbound() always allocates the next available
port. Static event channel support for dom0less domains requires
allocating a specified port.

Modify the evtchn_alloc_unbound() to accept the port number as an
argument and allocate the specified port if available. If the port
number argument is zero, the next available port will be allocated.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/evtchn: restrict the maximum number of evtchn supported for domUs
Rahul Singh [Wed, 7 Sep 2022 16:27:34 +0000 (17:27 +0100)]
xen/evtchn: restrict the maximum number of evtchn supported for domUs

Restrict the maximum number of evtchn supported for domUs to avoid
allocating a large amount of memory in Xen.

Set the default value of max_evtchn_port to 1023. The value of 1023
should be sufficient for guests because on ARM we don't bind physical
interrupts to event channels. The only use of the evtchn port is
inter-domain communications. Another reason why we choose the value
of 1023 is to follow the default behavior of libxl.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/evtchn: Add an helper to reserve/allocate a port
Stanislav Kinsburskii [Wed, 7 Sep 2022 16:27:33 +0000 (17:27 +0100)]
xen/evtchn: Add an helper to reserve/allocate a port

In a follow-up patch we will want to either reserve or allocate a port
for various event channel helpers.

A new wrapper is introduced to either reserve a given port or allocate
a fresh one if zero.

Take the opportunity to replace the open-coded version in
evtchn_bind_virq().

Signed-off-by: Stanislav Kinsburskii <staskins@amazon.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agoxen/evtchn: Make sure all buckets below d->valid_evtchns are allocated
Julien Grall [Wed, 7 Sep 2022 16:27:32 +0000 (17:27 +0100)]
xen/evtchn: Make sure all buckets below d->valid_evtchns are allocated

Since commit 01280dc19cf3 "evtchn: simplify port_is_valid()", the event
channels code assumes that all the buckets below d->valid_evtchns are
always allocated.

This assumption hold in most of the situation because a guest is not
allowed to chose the port. Instead, it will be the first free from port
0.

When static event channel support will be added for dom0less domains
user can request to allocate the evtchn port numbers that are scattered
in nature.

The existing implementation of evtchn_allocate_port() is not able to
deal with such situation and will end up to override bucket or/and leave
some bucket unallocated. The latter will result to a droplet crash if
the event channel belongs to an unallocated bucket.

This can be solved by making sure that all the buckets below
d->valid_evtchns are allocated. There should be no impact for most of
the situation but LM/LU as only one bucket would be allocated. For
LM/LU, we may end up to allocate multiple buckets if ports in use are
sparse.

A potential alternative is to check that the bucket is valid in
is_port_valid(). This should still possible to do it without taking
per-domain lock but will result a couple more of memory access.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2 years ago.gitignore: add init-dom0less
Viresh Kumar [Thu, 8 Sep 2022 07:32:14 +0000 (09:32 +0200)]
.gitignore: add init-dom0less

Add tools/helpers/init-dom0less to gitignore.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agoxen: add macro for version number string
Leo Yan [Thu, 8 Sep 2022 07:28:58 +0000 (09:28 +0200)]
xen: add macro for version number string

On Arm64 Linux kernel prints log for Xen version number:

  Xen XEN_VERSION.XEN_SUBVERSION support found

The header file "xen/compile.h" is missed so that XEN_VERSION and
XEN_SUBVERSION are not defined, __stringify() wrongly converts them as
strings and concatenate to string "XEN_VERSION.XEN_SUBVERSION".

This patch introduces a string macro XEN_VERSION_STRING, we can directly
use it as version number string, as a result it drops to use of
__stringify() to make the code more readable.

The change has been tested on Ampere AVA Arm64 platform.

Fixes: 5d797ee199b3 ("xen/arm: split domain_build.c")
Suggested-by: Bertrand Marquis <bertrand.marquis@arm.com>
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2 years agotools/xenstore: add documentation for extended watch command
Juergen Gross [Thu, 8 Sep 2022 07:28:30 +0000 (09:28 +0200)]
tools/xenstore: add documentation for extended watch command

Add documentation for an extension of the WATCH command used to limit
the scope of watched paths. Additionally it enables to receive more
information in the events related to special watches (@introduceDomain
or @releaseDomain).

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 years agotools/xenstore: add documentation for new set/get-quota commands
Juergen Gross [Thu, 8 Sep 2022 07:27:59 +0000 (09:27 +0200)]
tools/xenstore: add documentation for new set/get-quota commands

Add documentation for two new Xenstore wire commands SET_QUOTA and
GET_QUOTA used to set or query the global Xenstore quota or those of
a given domain.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 years agotools/xenstore: minor fix of the migration stream doc
Juergen Gross [Thu, 8 Sep 2022 07:25:58 +0000 (09:25 +0200)]
tools/xenstore: minor fix of the migration stream doc

Drop mentioning the non-existent read-only socket in the migration
stream description document.

The related record field was removed in commit 8868a0e3f674 ("docs:
update the xenstore migration stream documentation).

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
2 years agoConfig.mk: correct PIE-related option(s) in EMBEDDED_EXTRA_CFLAGS
Jan Beulich [Thu, 8 Sep 2022 07:25:26 +0000 (09:25 +0200)]
Config.mk: correct PIE-related option(s) in EMBEDDED_EXTRA_CFLAGS

I haven't been able to find evidence of "-nopie" ever having been a
supported compiler option. The correct spelling is "-no-pie".
Furthermore like "-pie" this is an option which is solely passed to the
linker. The compiler only recognizes "-fpie" / "-fPIE" / "-fno-pie", and
it doesn't infer these options from "-pie" / "-no-pie".

Add the compiler recognized form, but for the possible case of the
variable also being used somewhere for linking keep the linker option as
well (with corrected spelling).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
2 years agoxen: retrieve reserved pages on populate_physmap
Penny Zheng [Tue, 6 Sep 2022 07:39:19 +0000 (15:39 +0800)]
xen: retrieve reserved pages on populate_physmap

When a static domain populates memory through populate_physmap at runtime,
it shall retrieve reserved pages from resv_page_list to make sure that
domain's RAM is still restricted in statically configured memory regions.
This commit also introduces a new helper acquire_reserved_page to make it work.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 years agoxen: rename free_staticmem_pages to unprepare_staticmem_pages
Penny Zheng [Tue, 6 Sep 2022 07:39:18 +0000 (15:39 +0800)]
xen: rename free_staticmem_pages to unprepare_staticmem_pages

The name of free_staticmem_pages is inappropriate, considering it is
the opposite of function prepare_staticmem_pages.

Rename free_staticmem_pages to unprepare_staticmem_pages.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agoxen: introduce prepare_staticmem_pages
Penny Zheng [Tue, 6 Sep 2022 07:39:17 +0000 (15:39 +0800)]
xen: introduce prepare_staticmem_pages

Later, we want to use acquire_domstatic_pages() for populating memory
for static domain on runtime, however, there are a lot of pointless work
(checking mfn_valid(), scrubbing the free part, cleaning the cache...)
considering we know the page is valid and belong to the guest.

This commit splits acquire_staticmem_pages() in two parts, and
introduces prepare_staticmem_pages to bypass all "pointless work".

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
2 years agoxen: unpopulate memory when domain is static
Penny Zheng [Tue, 6 Sep 2022 07:39:16 +0000 (15:39 +0800)]
xen: unpopulate memory when domain is static

Today when a domain unpopulates the memory on runtime, they will always
hand the memory back to the heap allocator. And it will be a problem if domain
is static.

Pages as guest RAM for static domain shall be reserved to only this domain
and not be used for any other purposes, so they shall never go back to heap
allocator.

This commit puts reserved page on the new list resv_page_list after
it has been freed.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/arm: introduce CDF_staticmem
Penny Zheng [Tue, 6 Sep 2022 07:39:15 +0000 (15:39 +0800)]
xen/arm: introduce CDF_staticmem

In order to have an easy and quick way to find out whether this domain memory
is statically configured, this commit introduces a new flag CDF_staticmem and a
new helper is_domain_using_staticmem() to tell.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Acked-by: Julien Grall <jgrall@amazon.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agoxen: do not free reserved memory into heap
Penny Zheng [Tue, 6 Sep 2022 07:39:14 +0000 (15:39 +0800)]
xen: do not free reserved memory into heap

Pages used as guest RAM for static domain, shall be reserved to this
domain only.
So in case reserved pages being used for other purpose, users
shall not free them back to heap, even when last ref gets dropped.

This commit introduces a new helper free_domstatic_page to free
static page in runtime, and free_staticmem_pages will be called by it
in runtime, so let's drop the __init flag.

Wrapper #ifdef CONFIG_STATIC_MEMORY around function declaration(
free_staticmem_pages, free_domstatic_page, etc) is kinds of redundant,
so we decide to remove it here.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/arm: smmuv3: Avoid open coded arithmetic in memory allocation
Christophe JAILLET [Tue, 23 Aug 2022 14:44:18 +0000 (15:44 +0100)]
xen/arm: smmuv3: Avoid open coded arithmetic in memory allocation

Backport Linux commit 98b64741d611. This is the clean backport without
any changes

kmalloc_array()/kcalloc() should be used to avoid potential overflow
when a multiplication is needed to compute the size of the requested
memory.

So turn a devm_kzalloc()+explicit size computation into an
equivalent devm_kcalloc().

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/3f7b9b202c6b6f5edc234ab7af5f208fbf8bc944.1644274051.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Will Deacon <will@kernel.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 98b64741d611
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: smmuv3: Fix fall-through warning for Clang
Gustavo A. R. Silva [Tue, 23 Aug 2022 14:34:08 +0000 (15:34 +0100)]
xen/arm: smmuv3: Fix fall-through warning for Clang

Backport Linux commit 5a1ab5c0299a. This is the clean backport without
any changes.

Fix the following fallthrough warning (arm64-randconfig with Clang):

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:382:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]

Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/lkml/60edca25.k00ut905IFBjPyt5%25lkp@intel.com/
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 5a1ab5c0299a
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: smmuv3: Remove unnecessary oom message
Zhen Lei [Tue, 23 Aug 2022 14:30:38 +0000 (15:30 +0100)]
xen/arm: smmuv3: Remove unnecessary oom message

Backport Linux commit affa909571b0. This is the clean backport without
any changes.

Fixes scripts/checkpatch.pl warning:
WARNING: Possible unnecessary 'out of memory' message

Remove it can help us save a bit of memory.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20210609125438.14369-1-thunder.leizhen@huawei.com
Signed-off-by: Will Deacon <will@kernel.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git affa909571b0
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: smmuv3: Change *array into *const array
Bixuan Cui [Tue, 23 Aug 2022 14:11:04 +0000 (15:11 +0100)]
xen/arm: smmuv3: Change *array into *const array

Backport Linux commit d56d5162e317. This is the clean backport without
any changes.

Fix checkpatch warning in arm-smmu-v3.c:
static const char * array should probably be static const char
* const

Signed-off-by: Bixuan Cui <cuibixuan@huawei.com>
Signed-off-by: Will Deacon <will@kernel.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git d56d5162e317
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: smmuv3: Remove the unused fields for PREFETCH_CONFIG command
Zenghui Yu [Tue, 23 Aug 2022 14:05:36 +0000 (15:05 +0100)]
xen/arm: smmuv3: Remove the unused fields for PREFETCH_CONFIG command

Backport Linux commit e0bb4b735404. This is the clean backport without
any changes.

Per SMMUv3 spec, there is no Size and Addr field in the
PREFETCH_CONFIG command and they're not used by the driver.
Remove them.

We can add them back if we're going to use PREFETCH_ADDR in the
future.

Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
Link: https://lore.kernel.org/r/20210407084448.1838-1-yuzenghui@huawei.com
Signed-off-by: Will Deacon <will@kernel.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e0bb4b735404
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: smmuv3: Remove the page 1 fixup
Robin Murphy [Tue, 11 Jan 2022 17:10:51 +0000 (17:10 +0000)]
xen/arm: smmuv3: Remove the page 1 fixup

Backport Linux commit 86d2d9214880. This is the clean backport without
any changes.

Since we now keep track of page 1 via a separate pointer that
already encapsulates aliasing to page 0 as necessary, we can remove
the clunky fixup routine and simply use the relevant bases directly.
The current architecture spec (IHI0070D.a) defines
SMMU_{EVENTQ,PRIQ}_{PROD,CONS} as offsets relative to page 1, so the
cleanup represents a little bit of convergence as well as just
lines of code saved.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 86d2d9214880
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: smmuv3: Move definitions to a header
Jean-Philippe Brucker [Tue, 11 Jan 2022 12:33:43 +0000 (12:33 +0000)]
xen/arm: smmuv3: Move definitions to a header

Backport Linux commit e881e7839fba. Also, move Xen related struct
definition to header to get it compiled.

Allow sharing structure definitions with the upcoming SVA support for
Arm SMMUv3, by moving them to a separate header. We could surgically
extract only what is needed but keeping all definitions in one place
looks nicer.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/20200918101852.582559-8-jean-philippe@linaro.org
Signed-off-by: Will Deacon <will@kernel.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e881e7839fba
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: smmuv3: Ensure queue is read after updating prod pointer
Zhou Wang [Mon, 22 Aug 2022 15:52:31 +0000 (16:52 +0100)]
xen/arm: smmuv3: Ensure queue is read after updating prod pointer

Backport Linux commit a76a37777f2c. Introduce _iomb() in the smmu-v3.c
file with other Linux compatibility definitions.

Reading the 'prod' MMIO register in order to determine whether or
not there is valid data beyond 'cons' for a given queue does not
provide sufficient dependency ordering, as the resulting access is
address dependent only on 'cons' and can therefore be speculated
ahead of time, potentially allowing stale data to be read by the
CPU.

Use readl() instead of readl_relaxed() when updating the shadow copy
of the 'prod' pointer, so that all speculated memory reads from the
corresponding queue can occur only from valid slots.

Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com>
Link: https://lore.kernel.org/r/1601281922-117296-1-git-send-email-wangzhou1@hisilicon.com
[will: Use readl() instead of explicit barrier. Update 'cons' side to match.]
Signed-off-by: Will Deacon <will@kernel.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git a76a37777f2c
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
2 years agoxen/arm: smmuv3: Fix endianness annotations
Jean-Philippe Brucker [Mon, 22 Aug 2022 15:27:29 +0000 (16:27 +0100)]
xen/arm: smmuv3: Fix endianness annotations

Backport Linux commit 376cdf66f624. This is the clean backport without
any changes.

When building with C=1, sparse reports some issues regarding
endianness annotations:

arm-smmu-v3.c:221:26: warning: cast to restricted __le64
arm-smmu-v3.c:221:24: warning: incorrect type in assignment (different base types)
arm-smmu-v3.c:221:24:    expected restricted __le64 [usertype]
arm-smmu-v3.c:221:24:    got unsigned long long [usertype]
arm-smmu-v3.c:229:20: warning: incorrect type in argument 1 (different base types)
arm-smmu-v3.c:229:20:    expected restricted __le64 [usertype] *[assigned] dst
arm-smmu-v3.c:229:20:    got unsigned long long [usertype] *ent
arm-smmu-v3.c:229:25: warning: incorrect type in argument 2 (different base types)
arm-smmu-v3.c:229:25:    expected unsigned long long [usertype] *[assigned] src
arm-smmu-v3.c:229:25:    got restricted __le64 [usertype] *
arm-smmu-v3.c:396:20: warning: incorrect type in argument 1 (different base types)
arm-smmu-v3.c:396:20:    expected restricted __le64 [usertype] *[assigned] dst
arm-smmu-v3.c:396:20:    got unsigned long long *
arm-smmu-v3.c:396:25: warning: incorrect type in argument 2 (different base types)
arm-smmu-v3.c:396:25:    expected unsigned long long [usertype] *[assigned] src
arm-smmu-v3.c:396:25:    got restricted __le64 [usertype] *
arm-smmu-v3.c:1349:32: warning: invalid assignment: |=
arm-smmu-v3.c:1349:32:    left side has type restricted __le64
arm-smmu-v3.c:1349:32:    right side has type unsigned long
arm-smmu-v3.c:1396:53: warning: incorrect type in argument 3 (different base types)
arm-smmu-v3.c:1396:53:    expected restricted __le64 [usertype] *dst
arm-smmu-v3.c:1396:53:    got unsigned long long [usertype] *strtab
arm-smmu-v3.c:1424:39: warning: incorrect type in argument 1 (different base types)
arm-smmu-v3.c:1424:39:    expected unsigned long long [usertype] *[assigned] strtab
arm-smmu-v3.c:1424:39:    got restricted __le64 [usertype] *l2ptr

While harmless, they are incorrect and could hide actual errors during
development. Fix them.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/20200918141856.629722-1-jean-philippe@linaro.org
Signed-off-by: Will Deacon <will@kernel.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 376cdf66f624
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoxen/arm: smmuv3: Fix l1 stream table size in the error message
Zenghui Yu [Mon, 22 Aug 2022 15:19:01 +0000 (16:19 +0100)]
xen/arm: smmuv3: Fix l1 stream table size in the error message

Backport Linux commit dc898eb84b25. This is the clean backport without
any changes.

The actual size of level-1 stream table is l1size. This looks like an
oversight on commit d2e88e7c081ef ("iommu/arm-smmu: Fix LOG2SIZE setting
for 2-level stream tables") which forgot to update the @size in error
message as well.

As memory allocation failure is already bad enough, nothing worse would
happen. But let's be careful.

Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
Link: https://lore.kernel.org/r/20200826141758.341-1-yuzenghui@huawei.com
Signed-off-by: Will Deacon <will@kernel.org>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git dc898eb84b25
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
2 years agoautomation: only filter build-*/ in gitignore
Bertrand Marquis [Tue, 6 Sep 2022 15:21:57 +0000 (17:21 +0200)]
automation: only filter build-*/ in gitignore

...because there are some script in automation corresponding to the
build-* filter (build-test.sh and build-each-commit.sh)

Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2 years agox86/public: move XEN_ACPI_ in a new header
Bertrand Marquis [Tue, 6 Sep 2022 14:04:34 +0000 (16:04 +0200)]
x86/public: move XEN_ACPI_ in a new header

When Xen is compiled for x86 on an arm machine, libacpi build is failing
due to a wrong include path:
- arch-x86/xen.h includes xen.h
- xen.h includes arch-arm.h (as __i386__ and __x86_64__ are not defined
but arm ones are).

To solve this issue move XEN_ACPI_ definitions in a new header
guest-acpi.h that can be included cleanly by mk_dsdt.c.
Inside this header, only protect the definitions using ifdef
__XEN_TOOLS__ as the defines are not used anywhere in the hypervisor and
are not expected to be.

Previous users needing any of the XEN_ACPI_ definitions will now need to
include arch-x86/guest-acpi.h instead of arch-x86/xen.h

Fixes: d6ac8e22c7c5 ("acpi/x86: define ACPI IO registers for PVH guests")
Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
2 years agoxsm/flask: fix MISRA C 2012 Rule 20.7 violations
Xenia Ragiadakou [Tue, 6 Sep 2022 14:02:28 +0000 (16:02 +0200)]
xsm/flask: fix MISRA C 2012 Rule 20.7 violations

In macros SIDTAB_HASH(), INIT_SIDTAB_LOCK(), SIDTAB_LOCK() and SIDTAB_UNLOCK(),
add parentheses around the macro parameter to prevent against unintended
expansions.

Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Daniel P. Smith <dpsmith@apertussolutions.com>
2 years agoxen/sched: fix cpu hotplug
Juergen Gross [Mon, 5 Sep 2022 07:00:05 +0000 (09:00 +0200)]
xen/sched: fix cpu hotplug

Cpu unplugging is calling schedule_cpu_rm() via stop_machine_run() with
interrupts disabled, thus any memory allocation or freeing must be
avoided.

Since commit 5047cd1d5dea ("xen/common: Use enhanced
ASSERT_ALLOC_CONTEXT in xmalloc()") this restriction is being enforced
via an assertion, which will now fail.

Fix this by allocating needed memory before entering stop_machine_run()
and freeing any memory only after having finished stop_machine_run().

Fixes: 1ec410112cdd ("xen/sched: support differing granularity in schedule_cpu_[add/rm]()")
Reported-by: Gao Ruifeng <ruifeng.gao@intel.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>
2 years agoxen/sched: carve out memory allocation and freeing from schedule_cpu_rm()
Juergen Gross [Mon, 5 Sep 2022 07:00:04 +0000 (09:00 +0200)]
xen/sched: carve out memory allocation and freeing from schedule_cpu_rm()

In order to prepare not allocating or freeing memory from
schedule_cpu_rm(), move this functionality to dedicated functions.

For now call those functions from schedule_cpu_rm().

No change of behavior expected.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
2 years agoxen/sched: introduce cpupool_update_node_affinity()
Juergen Gross [Mon, 5 Sep 2022 07:00:03 +0000 (09:00 +0200)]
xen/sched: introduce cpupool_update_node_affinity()

For updating the node affinities of all domains in a cpupool add a new
function cpupool_update_node_affinity().

In order to avoid multiple allocations of cpumasks carve out memory
allocation and freeing from domain_update_node_affinity() into new
helpers, which can be used by cpupool_update_node_affinity().

Modify domain_update_node_affinity() to take an additional parameter
for passing the allocated memory in and to allocate and free the memory
via the new helpers in case NULL was passed.

This will help later to pre-allocate the cpumasks in order to avoid
allocations in stop-machine context.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Tested-by: Andrew Cooper <andrew.cooper3@citrix.com>
2 years agoxen/arm32: traps: Dump more information for hypervisor data abort
Julien Grall [Fri, 12 Aug 2022 19:24:48 +0000 (20:24 +0100)]
xen/arm32: traps: Dump more information for hypervisor data abort

Unlike arm64, on arm32 there are no extra information dumped (e.g.
page table walk) for hypervisor data abort.

For data abort, the HSR will be set properly and so call
do_trap_hyp_sync() instead of do_unexpected_trap() on arm32 to have
the print the same information as arm64.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
2 years agoxen/arm: Tweak the dump page-table walk output
Julien Grall [Fri, 12 Aug 2022 19:24:45 +0000 (20:24 +0100)]
xen/arm: Tweak the dump page-table walk output

Currently the output is looking like:

(XEN) 1ST[0x1] = 0x000000004015ff7f
(XEN) 2ND[0x1f] = 0x00500000bfe00f7d

The content of the entries are not aligned making a bit trickier to
read (I appreciate this is a matter of taste).

Align the values by forcing the index to be always printed using
3 characters (enough to cover 512 in hexadecimal).

New output:

(XEN) 1ST[0x001] = 0x000000004015ff7f
(XEN) 2ND[0x01f] = 0x00500000bfe00f7d

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Henry Wang <Henry.Wang@arm.com>
2 years agoxen/arm32: head: Move earlyprintk messages to .rodata.str
Julien Grall [Fri, 12 Aug 2022 19:24:44 +0000 (20:24 +0100)]
xen/arm32: head: Move earlyprintk messages to .rodata.str

At the moment, the strings are in text right after each use because
the instruction 'adr' has specific requirement on the location
and the compiler will forbid cross section label.

The macro 'adr_l' was recently reworked so the caller doesn't need
to know whether the MMU is on. This makes it easier to use where
instructions can be run in both context.

This also means that the strings don't need to be part of .text
anymore. So move them to .rodata.str.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Jiamei Xie <jiamei.xie@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Tested-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Wei Chen <Wei.Chen@arm.com>
2 years agoxen/arm32: heap: Rework adr_l so it doesn't rely on where Xen is loaded
Julien Grall [Fri, 12 Aug 2022 19:24:43 +0000 (20:24 +0100)]
xen/arm32: heap: Rework adr_l so it doesn't rely on where Xen is loaded

At the moment, the macro addr_l needs to know whether the caller
is running with the MMU on. This is fine today because there are
only two possible cases:
 1) MMU off
 2) MMU on and linked to the virtual address

This is still cumbersome to use for the developer as they need
to know if the MMU is on.

Thankfully, Linux developpers came up with a great way to allow
adr_l to work within the range +/- 4GB of PC by emitting a PC-relative
reference [1].

Re-use the same approach on Arm and drop the parameter 'mmu'.

[1] 0b1674638a5c ("ARM: assembler: introduce adr_l, ldr_l and str_l macros")

Signed-off-by: Julien Grall <jgrall@amazon.com>
2 years agoxen/arm32: head: Introduce get_table_slot() and use it
Julien Grall [Fri, 12 Aug 2022 19:24:42 +0000 (20:24 +0100)]
xen/arm32: head: Introduce get_table_slot() and use it

There are a few places in the code that need to find the slot at a
given page-table level.

So create a new macro get_table_slot() for that. This will reduce
the effort to figure out whether the code is doing the right thing.

The new macro is using 'ubfx' (or 'lsr' for the first level) rather
than the existing sequence (mov_w, lsr, and) because it doesn't require
a scratch register and reduce the number of instructions (4 -> 1).

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Tested-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Wei Chen <Wei.Chen@arm.com>
2 years agoxen/arm64: head: Introduce get_table_slot() and use it
Julien Grall [Fri, 12 Aug 2022 19:24:41 +0000 (20:24 +0100)]
xen/arm64: head: Introduce get_table_slot() and use it

There are a few places in the code that need to find the slot
at a given page-table level.

So create a new macro get_table_slot() for that. This will reduce
the effort to figure out whether the code is doing the right thing.

Take the opportunity to use 'ubfx'. The only benefits is reducing
the number of instructions from 2 to 1.

The new macro is used everywhere we need to compute the slot. This
requires to tweak the parameter of create_table_entry() to pass
a level rather than shift.

Note, for slot 0 the code is currently skipping the masking part. While
this is fine, it is safer to mask it as technically slot 0 only covers
bit 48 - 39 bit (assuming 4KB page granularity).

Take the opportunity to correct the comment when finding the second
slot for the identity mapping (we are computing the second slot
rather than first).

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
2 years agoxen/arm64: head: Don't set x22 and update the documentation
Julien Grall [Fri, 12 Aug 2022 19:24:40 +0000 (20:24 +0100)]
xen/arm64: head: Don't set x22 and update the documentation

Since commit 7e14a47e7c73 ("xen/arm64: head Rework and document
launch()"), the boot code is setting x22 but not read it.

So remove the two instructions setting x22 and update the documentation
to show x22 has no specific purpose.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Wei Chen <Wei.Chen@arm.com>