Re: [PATCH] KVM: arm64: Properly restore PMU state during live-migration

2021-06-08 Thread Jain, Jinank
On Tue, 2021-06-08 at 09:18 +0100, Marc Zyngier wrote: > CAUTION: This email originated from outside of the organization. Do > not click links or open attachments unless you can confirm the sender > and know the content is safe. > > > > On Mon, 07 Jun 2021 19:34:08 +0100, > "Jain, Jinank"

[PATCH v1 02/13] KVM: arm64: MDCR_EL2 is a 64-bit register

2021-06-08 Thread Fuad Tabba
Fix the places in KVM that treat MDCR_EL2 as a 32-bit register. More recent features (e.g., FEAT_SPEv1p2) use bits above 31. No functional change intended. Signed-off-by: Fuad Tabba --- arch/arm64/include/asm/kvm_arm.h | 20 ++-- arch/arm64/include/asm/kvm_asm.h | 2 +-

[PATCH v1 00/13] KVM: arm64: Fixed features for protected VMs

2021-06-08 Thread Fuad Tabba
Hi, This patch series adds support for restricting CPU features for protected VMs in KVM [1]. Various feature configurations are allowed in KVM/arm64. Supporting all these features in pKVM is difficult, as it either involves moving much of the handling code to EL2, which adds bloat and results

[PATCH v1 11/13] KVM: arm64: Trap access to pVM restricted features

2021-06-08 Thread Fuad Tabba
Trap accesses to restricted features for VMs running in protected mode. Access to feature registers are emulated, and only supported features are exposed to protected VMs. Accesses to restricted registers as well as restricted instructions are trapped, and an undefined exception is injected into

[PATCH v1 06/13] KVM: arm64: Add feature register flag definitions

2021-06-08 Thread Fuad Tabba
Add feature register flag definitions to clarify which features might be toggled. No functional change intended. Signed-off-by: Fuad Tabba --- arch/arm64/include/asm/sysreg.h | 6 ++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/include/asm/sysreg.h

[PATCH v1 07/13] KVM: arm64: Add config register bit definitions

2021-06-08 Thread Fuad Tabba
Add hardware configuration register bit definitions for HCR_EL2 and MDCR_EL2. Future patches toggle these hyp configuration register bits to trap on certain accesses. No functional change intended. Signed-off-by: Fuad Tabba --- arch/arm64/include/asm/kvm_arm.h | 8 1 file changed, 8

[PATCH v1 12/13] KVM: arm64: Handle protected guests at 32 bits

2021-06-08 Thread Fuad Tabba
Protected KVM does not support protected AArch32 guests. However, it is possible for the guest to force run AArch32, potentially causing problems. Add an extra check so that if the hypervisor catches the guest doing that, it can prevent the guest from running again by resetting vcpu->arch.target

[PATCH v1 13/13] KVM: arm64: Check vcpu features at pVM creation

2021-06-08 Thread Fuad Tabba
Check that a protected VM is not setting any of the unsupported features when it's created. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/pkvm.c | 31 +++ 1 file changed, 31 insertions(+) diff --git a/arch/arm64/kvm/pkvm.c b/arch/arm64/kvm/pkvm.c index

[PATCH v1 01/13] KVM: arm64: Remove trailing whitespace in comments

2021-06-08 Thread Fuad Tabba
Editing this file later, and my editor always cleans up trailing whitespace. Removing it earler for clearer future patches. No functional change intended. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/sys_regs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git

[PATCH v1 03/13] KVM: arm64: Fix name of HCR_TACR to match the spec

2021-06-08 Thread Fuad Tabba
Makes it easier to grep and to cross-check with the Arm Architecture Reference Manual. No functional change intended. Signed-off-by: Fuad Tabba --- arch/arm64/include/asm/kvm_arm.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_arm.h

[PATCH v1 04/13] KVM: arm64: Refactor sys_regs.h,c for nVHE reuse

2021-06-08 Thread Fuad Tabba
Refactor sys_regs.h and sys_regs.c to make it easier to reuse common code. It will be used in nVHE in a later patch. No functional change intended. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/sys_regs.c | 58 ++- arch/arm64/kvm/sys_regs.h | 35

[PATCH v1 05/13] KVM: arm64: Restore mdcr_el2 from vcpu

2021-06-08 Thread Fuad Tabba
On deactivating traps, restore the value of mdcr_el2 from the vcpu context, rather than directly reading the hardware register. Currently, the two values are the same, i.e., the hardware register and the vcpu one. A future patch will be changing the value of mdcr_el2 on activating traps, and this

[PATCH v1 10/13] KVM: arm64: Move sanitized copies of CPU features

2021-06-08 Thread Fuad Tabba
Move the sanitized copies of the CPU feature registers to the recently created sys_regs.c. This consolidates all copies in a more relevant file. No functional change intended. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 6 -- arch/arm64/kvm/hyp/nvhe/sys_regs.c

[PATCH v1 08/13] KVM: arm64: Guest exit handlers for nVHE hyp

2021-06-08 Thread Fuad Tabba
Add an array of pointers to handlers for various trap reasons in nVHE code. The current code selects how to fixup a guest on exit based on a series of if/else statements. Future patches will also require different handling for guest exists. Create an array of handlers to consolidate them. No

[PATCH v1 09/13] KVM: arm64: Add trap handlers for protected VMs

2021-06-08 Thread Fuad Tabba
Add trap handlers for protected VMs. These are mainly for Sys64 and debug traps. No functional change intended as these are not hooked in yet. Signed-off-by: Fuad Tabba --- arch/arm64/include/asm/kvm_hyp.h | 4 + arch/arm64/kvm/arm.c | 4 + arch/arm64/kvm/hyp/nvhe/Makefile

Re: [PATCH] KVM: selftests: Rename vm_handle_exception in evmcs test

2021-06-08 Thread Ricardo Koller
On Fri, Jun 04, 2021 at 09:26:54PM +, Sean Christopherson wrote: > On Fri, Jun 04, 2021, Ricardo Koller wrote: > > Kernel test robot reports this: > > > > > /usr/bin/ld: tools/testing/selftests/kvm/x86_64/evmcs_test.c:157: > > > undefined reference to `vm_handle_exception' > > > /usr/bin/ld:

Re: [PATCH v7 1/4] KVM: stats: Separate generic stats from architecture specific ones

2021-06-08 Thread Krish Sadhukhan
On 6/3/21 2:14 PM, Jing Zhang wrote: Put all generic statistics in a separate structure to ease statistics handling for the incoming new statistics API. No functional change intended. Reviewed-by: David Matlack Reviewed-by: Ricardo Koller Signed-off-by: Jing Zhang ---

Re: [PATCH v7 3/4] KVM: stats: Add documentation for statistics data binary interface

2021-06-08 Thread Krish Sadhukhan
On 6/3/21 2:14 PM, Jing Zhang wrote: Update KVM API documentation for binary statistics. Reviewed-by: David Matlack Reviewed-by: Ricardo Koller Signed-off-by: Jing Zhang --- Documentation/virt/kvm/api.rst | 180 + 1 file changed, 180 insertions(+) diff

Re: [PATCH v7 4/4] KVM: selftests: Add selftest for KVM statistics data binary interface

2021-06-08 Thread Krish Sadhukhan
On 6/3/21 2:14 PM, Jing Zhang wrote: Add selftest to check KVM stats descriptors validity. Reviewed-by: David Matlack Reviewed-by: Ricardo Koller Signed-off-by: Jing Zhang --- tools/testing/selftests/kvm/.gitignore| 1 + tools/testing/selftests/kvm/Makefile | 3 +

Re: [PATCH v7 2/4] KVM: stats: Add fd-based API to read binary stats data

2021-06-08 Thread Krish Sadhukhan
On 6/3/21 2:14 PM, Jing Zhang wrote: Provides a file descriptor per VM to read VM stats info/data. Provides a file descriptor per vCPU to read vCPU stats info/data. Reviewed-by: David Matlack Reviewed-by: Ricardo Koller Signed-off-by: Jing Zhang --- arch/arm64/kvm/guest.c| 26 +++

Re: [PATCH] KVM: arm64: Properly restore PMU state during live-migration

2021-06-08 Thread Marc Zyngier
On Mon, 07 Jun 2021 19:34:08 +0100, "Jain, Jinank" wrote: > > Hi Marc. > > On Mon, 2021-06-07 at 17:35 +0100, Marc Zyngier wrote: > > CAUTION: This email originated from outside of the organization. Do > > not click links or open attachments unless you can confirm the sender > > and know the

Re: [PATCH 3/4] KVM: arm64: Parse reserved-memory node for pkvm guest firmware region

2021-06-08 Thread Will Deacon
Hi Mark, On Fri, Jun 04, 2021 at 03:21:41PM +0100, Mark Rutland wrote: > On Thu, Jun 03, 2021 at 07:33:46PM +0100, Will Deacon wrote: > > Add support for a "linux,pkvm-guest-firmware-memory" reserved memory > > region, which can be used to identify a firmware image for protected > > VMs. > > The

[PATCH v2] KVM: arm64: Properly restore PMU state during live-migration

2021-06-08 Thread Jinank Jain
Currently if a guest is live-migrated while it is actively using perf counters, then after live-migrate it will notice that all counters would suddenly start reporting 0s. This is due to the fact we are not re-creating the relevant perf events inside the kernel. Usually on live-migration guest

Re: [RFC PATCH 4/4] KVM: arm64: Introduce KVM_CAP_ARM_PROTECTED_VM

2021-06-08 Thread Will Deacon
On Fri, Jun 04, 2021 at 03:41:10PM +0100, Mark Rutland wrote: > On Thu, Jun 03, 2021 at 07:33:47PM +0100, Will Deacon wrote: > > +7.26.1 KVM_CAP_ARM_PROTECTED_VM_FLAGS_ENABLE > > + > > + > > +:Capability: 'flag' parameter to KVM_CAP_ARM_PROTECTED_VM > >

Re: [RFC PATCH 4/4] KVM: arm64: Introduce KVM_CAP_ARM_PROTECTED_VM

2021-06-08 Thread Will Deacon
Hi Sean, Thanks for having a look. On Thu, Jun 03, 2021 at 08:15:55PM +, Sean Christopherson wrote: > On Thu, Jun 03, 2021, Will Deacon wrote: > > +Enabling this capability causes all memory slots of the specified VM to be > > +unmapped from the host system and put into a state where they

Re: [PATCH] KVM: arm64: Properly restore PMU state during live-migration

2021-06-08 Thread Jain, Jinank
Hi Marc. On Mon, 2021-06-07 at 17:35 +0100, Marc Zyngier wrote: > CAUTION: This email originated from outside of the organization. Do > not click links or open attachments unless you can confirm the sender > and know the content is safe. > > > > On Mon, 07 Jun 2021 17:05:01 +0100, > "Jain,

Re: [PATCH v1 00/13] KVM: arm64: Fixed features for protected VMs

2021-06-08 Thread Andrew Jones
On Tue, Jun 08, 2021 at 03:11:28PM +0100, Fuad Tabba wrote: > Hi, > > This patch series adds support for restricting CPU features for protected VMs > in KVM [1]. > > Various feature configurations are allowed in KVM/arm64. Supporting all > these features in pKVM is difficult, as it either

[PATCH v3 0/7] KVM: arm64: Reduce hyp_vmemmap overhead

2021-06-08 Thread Quentin Perret
Hi all, This is a v3 of the patch series previously posted here: https://lore.kernel.org/r/20210602094347.3730846-1-qper...@google.com Please refer to the cover letter of v1 for the context and motivation behind the series. Changes since v2: - Rebased on kvmarm/next Thanks, Quentin

[PATCH v3 2/7] KVM: arm64: Use refcount at hyp to check page availability

2021-06-08 Thread Quentin Perret
The hyp buddy allocator currently checks the struct hyp_page list node to see if a page is available for allocation or not when trying to coalesce memory. Now that decrementing the refcount and attaching to the buddy tree is done in the same critical section, we can rely on the refcount of the

[PATCH v3 7/7] KVM: arm64: Use less bits for hyp_page refcount

2021-06-08 Thread Quentin Perret
The hyp_page refcount is currently encoded on 4 bytes even though we never need to count that many objects in a page. Make it 2 bytes to save some space in the vmemmap. As overflows are more likely to happen as well, make sure to catch those with a BUG in the increment function. Signed-off-by:

[PATCH v3 4/7] KVM: arm64: Unify MMIO and mem host stage-2 pools

2021-06-08 Thread Quentin Perret
We currently maintain two separate memory pools for the host stage-2, one for pages used in the page-table when mapping memory regions, and the other to map MMIO regions. The former is large enough to map all of memory with page granularity and the latter can cover an arbitrary portion of IPA

[PATCH v3 3/7] KVM: arm64: Remove list_head from hyp_page

2021-06-08 Thread Quentin Perret
The list_head member of struct hyp_page is only needed when the page is attached to a free-list, which by definition implies the page is free. As such, nothing prevents us from using the page itself to store the list_head, hence reducing the size of the vmemmap. Signed-off-by: Quentin Perret ---

[PATCH v3 6/7] KVM: arm64: Use less bits for hyp_page order

2021-06-08 Thread Quentin Perret
The hyp_page order is currently encoded on 4 bytes even though it is guaranteed to be smaller than this. Make it 2 bytes to reduce the hyp vmemmap overhead. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/gfp.h| 6 +++--- arch/arm64/kvm/hyp/include/nvhe/memory.h | 2 +-

[PATCH v3 1/7] KVM: arm64: Move hyp_pool locking out of refcount helpers

2021-06-08 Thread Quentin Perret
The hyp_page refcount helpers currently rely on the hyp_pool lock for serialization. However, this means the refcounts can't be changed from the buddy allocator core as it already holds the lock, which means pages have to go through odd transient states. For example, when a page is freed, its

[PATCH v3 5/7] KVM: arm64: Remove hyp_pool pointer from struct hyp_page

2021-06-08 Thread Quentin Perret
Each struct hyp_page currently contains a pointer to a hyp_pool struct where the page should be freed if its refcount reaches 0. However, this information can always be inferred from the context in the EL2 code, so drop the pointer to save a few bytes in the vmemmap. Signed-off-by: Quentin Perret

[RFC PATCH 2/5] KVM: arm64: Move WFI execution to check_vcpu_requests()

2021-06-08 Thread Jean-Philippe Brucker
Prepare for WFI requests from userspace, by adding a suspend request and moving the WFI execution into check_vcpu_requests(), next to the power-off logic. vcpu->arch.mp_state, previously only RUNNABLE or STOPPED, supports an additional state HALTED and two new state transitions: RUNNABLE ->

[RFC PATCH 1/5] KVM: arm64: Replace power_off with mp_state in struct kvm_vcpu_arch

2021-06-08 Thread Jean-Philippe Brucker
In order to add a new "suspend" power state, replace power_off with mp_state in struct kvm_vcpu_arch. Factor the vcpu_off() function while we're here. No functional change intended. Signed-off-by: Jean-Philippe Brucker --- arch/arm64/include/asm/kvm_host.h | 6 -- arch/arm64/kvm/arm.c

[RFC PATCH 3/5] KVM: arm64: Allow userspace to request WFI

2021-06-08 Thread Jean-Philippe Brucker
To help userspace implement PSCI CPU_SUSPEND, allow setting the "HALTED" MP state to request a WFI before returning to the guest. Userspace won't obtain a HALTED mp_state from a KVM_GET_MP_STATE call unless they set it themselves. When set by KVM, to handle wfi or CPU_SUSPEND, it is consumed

[RFC PATCH 0/5] KVM: arm64: Pass PSCI to userspace

2021-06-08 Thread Jean-Philippe Brucker
Allow userspace to request handling PSCI calls from guests. Our goal is to enable a vCPU hot-add solution for Arm where the VMM presents possible resources to the guest at boot, and controls which vCPUs can be brought up by allowing or denying PSCI CPU_ON calls. Passing HVC and PSCI to userspace

[RFC PATCH 4/5] KVM: arm64: Pass hypercalls to userspace

2021-06-08 Thread Jean-Philippe Brucker
Let userspace request to handle all hypercalls that aren't handled by KVM, by setting the KVM_CAP_ARM_HVC_TO_USER capability. With the help of another capability, this will allow userspace to handle PSCI calls. Suggested-by: James Morse Signed-off-by: Jean-Philippe Brucker --- Notes on this

[RFC PATCH 5/5] KVM: arm64: Pass PSCI calls to userspace

2021-06-08 Thread Jean-Philippe Brucker
Let userspace request to handle PSCI calls, by setting the new KVM_CAP_ARM_PSCI_TO_USER capability. SMCCC probe requires PSCI v1.x. If userspace only implements PSCI v0.2, the guest won't query SMCCC support through PSCI and won't use the spectre workarounds. We could hijack PSCI_VERSION and