Re: [PATCH v3 0/5] arm64: Treat ESR_ELx as a 64-bit register

2022-04-28 Thread Marc Zyngier
On Mon, 25 Apr 2022 12:44:39 +0100, Alexandru Elisei wrote: > > The ESR_EL{1,2} registers were originally 32-bit, then were extended to > 64-bit with the upper 32 bits RES0, and in ARM DDI 0487H.a the FEAT_LS64 > feature was added which now makes use of the upper bits. This series aims > to teach

Re: [PATCH] KVM: arm64: Handle host stage-2 faults from 32-bit EL0

2022-04-28 Thread Marc Zyngier
On Wed, 27 Apr 2022 18:13:32 +0100, Will Deacon wrote: > When pKVM is enabled, host memory accesses are translated by an identity > mapping at stage-2, which is populated lazily in response to synchronous > exceptions from 64-bit EL1 and EL0. > > Extend this handling to cover exceptions originatin

Re: [PATCH] KVM/arm64: Don't emulate a PMU for 32-bit guests if feature not set

2022-04-28 Thread Marc Zyngier
On Mon, 25 Apr 2022 15:55:30 +0100, Alexandru Elisei wrote: > kvm->arch.arm_pmu is set when userspace attempts to set the first PMU > attribute. As certain attributes are mandatory, arm_pmu ends up always > being set to a valid arm_pmu, otherwise KVM will refuse to run the VCPU. > However, this onl

Re: [PATCH v8 0/6] KVM: arm64: Hypervisor stack enhancements

2022-04-28 Thread Marc Zyngier
On Wed, 20 Apr 2022 14:42:51 -0700, Kalesh Singh wrote: > This is v8 of the nVHE hypervisor stack enhancements. This version is based > on 5.18-rc3. > > Previous versions can be found at: > v7: https://lore.kernel.org/r/20220408200349.1529080-1-kaleshsi...@google.com/ > v6: https://lore.kernel.org

Re: [PATCH v2] KVM: arm64: Inject exception on out-of-IPA-range translation fault

2022-04-28 Thread Marc Zyngier
On Thu, 28 Apr 2022 17:07:21 +0100, Alexandru Elisei wrote: > > Hi, > > On Thu, Apr 28, 2022 at 04:22:58PM +0100, Marc Zyngier wrote: > > On Thu, 28 Apr 2022 09:46:21 +0100, > > Alexandru Elisei wrote: > > > > > > Hi, > > > > > > On Wed, Apr 27, 2022 at 11:04:34PM +0100, Marc Zyngier wrote: >

Re: [PATCH v2] KVM: arm64: Inject exception on out-of-IPA-range translation fault

2022-04-28 Thread Alexandru Elisei
Hi, On Thu, Apr 28, 2022 at 04:22:58PM +0100, Marc Zyngier wrote: > On Thu, 28 Apr 2022 09:46:21 +0100, > Alexandru Elisei wrote: > > > > Hi, > > > > On Wed, Apr 27, 2022 at 11:04:34PM +0100, Marc Zyngier wrote: > > > When taking a translation fault for an IPA that is outside of > > > the range

[PATCH kvmtool 15/15] arm/arm64: Validate firmware address in kvm__arch_validate_cfg()

2022-04-28 Thread Alexandru Elisei
We know at user configuration time if the firmware address is outside RAM, validate the address in kvm__arch_validate_cfg() before creating the VM. Signed-off-by: Alexandru Elisei --- arm/kvm.c | 36 ++-- 1 file changed, 14 insertions(+), 22 deletions(-) diff --g

[PATCH kvmtool 14/15] arm/arm64: Treat --firmware-address when no --firmware as an error

2022-04-28 Thread Alexandru Elisei
It makes little sense for the user to specify the firmware address when loading a kernel instead of a firmware image. Treat it as an error. Signed-off-by: Alexandru Elisei --- arm/aarch32/kvm.c | 2 +- arm/aarch64/kvm.c | 2 +- arm/include/arm-common/kvm-arch.h |

[PATCH kvmtool 12/15] arm64: Allow the user to specify the RAM base address

2022-04-28 Thread Alexandru Elisei
Allow the user to specify the RAM base address by using -m/--mem size@addr command line argument. The base address must be above 2GB, as to not overlap with the MMIO I/O region. Signed-off-by: Alexandru Elisei --- arm/aarch64/include/kvm/kvm-arch.h | 2 ++ arm/aarch64/kvm.c |

[PATCH kvmtool 13/15] arm/arm64: Allow standard size specifiers for firmware address

2022-04-28 Thread Alexandru Elisei
The arm and arm64 permit the user to specify the load address, in RAM, for the firmware image. Make it possible to use the standard size specifiers (B/K/M/G/P/T) when doing so. Signed-off-by: Alexandru Elisei --- arm/include/arm-common/kvm-config-arch.h | 7 +-- arm/kvm.c

[PATCH kvmtool 11/15] Introduce kvm__arch_default_ram_address()

2022-04-28 Thread Alexandru Elisei
Add a new function, kvm__arch_default_ram_address(), which returns the default address for guest RAM for each architecture. Signed-off-by: Alexandru Elisei --- arm/aarch32/kvm.c | 5 + arm/aarch64/kvm.c | 5 + include/kvm/kvm.h | 1 + mips/kvm.c| 5 + powerpc/kvm.c | 5 ++

[PATCH kvmtool 10/15] arm/arm64: Consolidate RAM initialization in kvm__init_ram()

2022-04-28 Thread Alexandru Elisei
From: Julien Grall RAM initialization is unnecessarily split between kvm__init_ram() and kvm__arch_init(). Move all code related to RAM initialization to kvm__init_ram(), making the code easier to follow and to modify. One thing to note is that the initialization order is slightly altered: kvm__

[PATCH kvmtool 09/15] kvm__arch_init: Remove hugetlbfs_path and ram_size as parameters

2022-04-28 Thread Alexandru Elisei
From: Julien Grall The kvm struct already contains a pointer to the configuration, which contains both hugetlbfs_path and ram_size, so is it not necessary to pass them as arguments to kvm__arch_init(). Signed-off-by: Julien Grall Signed-off-by: Alexandru Elisei --- arm/kvm.c | 7 -

[PATCH kvmtool 05/15] arm/arm64: Fail if RAM size is too large for 32-bit guests

2022-04-28 Thread Alexandru Elisei
For 64-bit guests, kvmtool exists with an error in kvm__get_vm_type() if the memory size is larger than what KVM supports. For 32-bit guests, the RAM size is silently rounded down to ARM_LOMAP_MAX_MEMORY in kvm__arch_init(). Be consistent and exit with an error when the user has configured the wro

[PATCH kvmtool 07/15] arm/arm64: Kill the ARM_MAX_MEMORY() macro

2022-04-28 Thread Alexandru Elisei
For 32-bit guests, the maximum memory size is represented by the define ARM_LOMAP_MAX_MEMORY, which ARM_MAX_MEMORY() returns. For 64-bit guests, the RAM size is checked against the maximum allowed by KVM in kvm__get_vm_type(). There are no users left for the ARM_MAX_MEMORY() macro, remove it. Si

[PATCH kvmtool 06/15] builtin_run: Allow standard size specifiers for memory

2022-04-28 Thread Alexandru Elisei
From: Suzuki K Poulose Allow the user to use the standard B (bytes), K (kilobytes), M (megabytes), G (gigabytes), T (terabytes) and P (petabytes) suffixes for memory size. When none are specified, the default is megabytes. Also raise an error if the guest specifies 0 as the memory size, instead

[PATCH kvmtool 08/15] arm/arm64: Kill the ARM_HIMAP_MAX_MEMORY() macro

2022-04-28 Thread Alexandru Elisei
The ARM_HIMAP_MAX_MEMORY() is a remnant of a time when KVM only supported 40 bits if IPA. There are no users left for this macro, remove it. Signed-off-by: Alexandru Elisei --- arm/include/arm-common/kvm-arch.h | 1 - 1 file changed, 1 deletion(-) diff --git a/arm/include/arm-common/kvm-arch.h

[PATCH kvmtool 04/15] builtin-run: Add arch hook to validate VM configuration

2022-04-28 Thread Alexandru Elisei
Architectures are free to set their own command line options. Add an architecture specific hook to validate these options. For now, the hook does nothing, but it will be used in later patches. Signed-off-by: Alexandru Elisei --- Makefile | 3 ++- arm/aarch32/kvm.c | 5 + arm/aarch6

[PATCH kvmtool 03/15] builtin-run: Rework RAM size validation

2022-04-28 Thread Alexandru Elisei
host_ram_size() uses sysconf() to calculate the available ram, and sysconf() can fail. When that happens, host_ram_size() returns 0. kvmtool warns the user when the configured VM ram size exceeds the size of the host's memory, but doesn't take into account that host_ram_size() can return 0. If the

[PATCH kvmtool 02/15] builtin-run: Always use RAM size in bytes

2022-04-28 Thread Alexandru Elisei
The user can specify the virtual machine memory size in MB, which is saved in cfg->ram_size. kvmtool validates it against the host memory size, converted from bytes to MB. ram_size is then converted to bytes, and this is how it is used throughout the rest of kvmtool. To avoid any confusion about t

[PATCH kvmtool 00/15] arm64: Allow the user to set RAM base address

2022-04-28 Thread Alexandru Elisei
The series can be found at [1]. It is loosely based on the patches that allow the user to define the VM memory layout (RAM + MMIO) [2]. I've cherry-picked a handful of patches from that series, the rest I wrote from scratch since there have been several changes to the way guest memory is handled. I

[PATCH kvmtool 01/15] Use MB for megabytes consistently

2022-04-28 Thread Alexandru Elisei
The help text for the -m/--mem argument states that the guest memory size is in MiB (mebibyte). MiB is the same thing as MB (megabyte), and indeed this is how MB is used throughout kvmtool. Replace MiB with MB, so people don't get the wrong idea and start believing that for kvmtool a MB is 10^6 by

Re: [PATCH v2] KVM: arm64: Inject exception on out-of-IPA-range translation fault

2022-04-28 Thread Marc Zyngier
On Thu, 28 Apr 2022 09:46:21 +0100, Alexandru Elisei wrote: > > Hi, > > On Wed, Apr 27, 2022 at 11:04:34PM +0100, Marc Zyngier wrote: > > When taking a translation fault for an IPA that is outside of > > the range defined by the hypervisor (between the HW PARange and > > the IPA range), we stupi

Re: [PATCH v14 00/39] arm64/sme: Initial support for the Scalable Matrix Extension

2022-04-28 Thread Qian Cai
On Tue, Apr 19, 2022 at 12:22:08PM +0100, Mark Brown wrote: > This series provides initial support for the ARMv9 Scalable Matrix > Extension (SME). SME takes the approach used for vectors in SVE and > extends this to provide architectural support for matrix operations. A > more detailed overview

Re: [PATCH v14 00/39] arm64/sme: Initial support for the Scalable Matrix Extension

2022-04-28 Thread Qian Cai
On Wed, Apr 27, 2022 at 06:14:31PM +0100, Mark Brown wrote: > On Wed, Apr 27, 2022 at 01:08:58PM -0400, Qian Cai wrote: > > On Tue, Apr 19, 2022 at 12:22:08PM +0100, Mark Brown wrote: > > > > but not SVE, SME is an ARMv9 feature and SVE is mandatory for ARMv9. > > > The code attempts to handle any

[PATCH] arm64: kvm: avoid unnecessary absolute addressing via literals

2022-04-28 Thread Ard Biesheuvel
There are a few cases in the nVHE code where we take the absolute address of a symbol via a literal pool entry, and subsequently translate it to another address space (PA, kimg VA, kernel linear VA, etc). Originally, this literal was needed because we relied on a different translation for absolute

[PATCH v2 2/2] KVM/arm64: Print emulated register table name when it is unsorted

2022-04-28 Thread Alexandru Elisei
When a sysreg table entry is out-of-order, KVM attempts to print the address of the table: [0.143911] kvm [1]: sys_reg table (ptrval) out of order (1) Printing the name of the table instead of a pointer is more helpful in this case. The message has also been slightly tweaked to be poi

[PATCH v2 1/2] KVM/arm64: Don't BUG_ON() if emulated register table is unsorted

2022-04-28 Thread Alexandru Elisei
To emulate a register access, KVM uses a table of registers sorted by register encoding to speed up queries using binary search. When Linux boots, KVM checks that the table is sorted and uses a BUG_ON() statement to let the user know if it's not. The unfortunate side effect is that an unsorted sys

[PATCH v2 0/2] KVM/arm64: sys_reg_table_init() small improvements

2022-04-28 Thread Alexandru Elisei
These are two small improvements to how KVM handles an out-of-order sys_reg_desc table. These should only affect KVM developers, as the end user should never see an error caused by an unsorted sys_reg_desc table. Changes in v2: * Tweaked how the error is detected and propagated in kvm_arch_init()

Re: [PATCH v14 04/39] arm64/sme: Provide ABI documentation for SME

2022-04-28 Thread Catalin Marinas
On Tue, Apr 19, 2022 at 12:22:12PM +0100, Mark Brown wrote: > +* There are a number of optional SME features, presence of these is reported > + through AT_HWCAP2 through: > + > + HWCAP2_SME_I16I64 > + HWCAP2_SME_F64F64 > + HWCAP2_SME_I8I32 > + HWCAP2_SME_F16F32 > + HWCAP2_SME_B

Re: [PATCH v2] KVM: arm64: Inject exception on out-of-IPA-range translation fault

2022-04-28 Thread Alexandru Elisei
Hi, On Wed, Apr 27, 2022 at 11:04:34PM +0100, Marc Zyngier wrote: > When taking a translation fault for an IPA that is outside of > the range defined by the hypervisor (between the HW PARange and > the IPA range), we stupidly treat it as an IO and forward the access > to userspace. Of course, user