Re: [PATCH] selftests: KVM: Call ucall_init when setting up in rseq_test

2021-09-23 Thread Oliver Upton
On Thu, Sep 23, 2021 at 5:09 PM Sean Christopherson wrote: > > On Thu, Sep 23, 2021, Oliver Upton wrote: > > While x86 does not require any additional setup to use the ucall > > infrastructure, arm64 needs to set up the MMIO address used to signal a > > ucall to userspace. rseq_test does not

Re: [PATCH] selftests: KVM: Call ucall_init when setting up in rseq_test

2021-09-23 Thread Sean Christopherson
On Thu, Sep 23, 2021, Oliver Upton wrote: > While x86 does not require any additional setup to use the ucall > infrastructure, arm64 needs to set up the MMIO address used to signal a > ucall to userspace. rseq_test does not initialize the MMIO address, > resulting in the test spinning

[PATCH] selftests: KVM: Call ucall_init when setting up in rseq_test

2021-09-23 Thread Oliver Upton
While x86 does not require any additional setup to use the ucall infrastructure, arm64 needs to set up the MMIO address used to signal a ucall to userspace. rseq_test does not initialize the MMIO address, resulting in the test spinning indefinitely. Fix the issue by calling ucall_init() during

Re: [PATCH v2 00/11] KVM: arm64: Implement PSCI SYSTEM_SUSPEND support

2021-09-23 Thread Oliver Upton
On Thu, Sep 23, 2021 at 07:15:59PM +, Oliver Upton wrote: > Certain VMMs/operators may wish to give their guests the ability to > initiate a system suspend that could result in the VM being saved to > persistent storage to be resumed at a later time. The PSCI v1.0 > specification describes an

[PATCH v2 11/11] selftests: KVM: Test SYSTEM_SUSPEND PSCI call

2021-09-23 Thread Oliver Upton
Assert that the vCPU exits to userspace with KVM_SYSTEM_EVENT_SUSPEND if it correctly executes the SYSTEM_SUSPEND PSCI call. Additionally, assert that the guest PSCI call fails if preconditions are not met (more than 1 running vCPU). Signed-off-by: Oliver Upton ---

[PATCH v2 09/11] selftests: KVM: Use KVM_SET_MP_STATE to power off vCPU in psci_test

2021-09-23 Thread Oliver Upton
Setting a vCPU's MP state to KVM_MP_STATE_STOPPED has the effect of powering off the vCPU. Rather than using the vCPU init feature flag, use the KVM_SET_MP_STATE ioctl to power off the target vCPU. Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/aarch64/psci_test.c | 13

[PATCH v2 04/11] KVM: arm64: Rename the KVM_REQ_SLEEP handler

2021-09-23 Thread Oliver Upton
The naming of the kvm_req_sleep function is confusing: the function itself sleeps the vCPU, it does not request such an event. Rename the function to make its purpose more clear. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/kvm/arm.c | 4 ++-- 1 file changed, 2

[PATCH v2 03/11] KVM: arm64: Encapsulate reset request logic in a helper function

2021-09-23 Thread Oliver Upton
In its implementation of the PSCI function, KVM needs to request that a target vCPU resets before its next entry into the guest. Wrap the logic for requesting a reset in a function for later use by other implemented PSCI calls. No functional change intended. Signed-off-by: Oliver Upton ---

[PATCH v2 08/11] selftests: KVM: Create helper for making SMCCC calls

2021-09-23 Thread Oliver Upton
The PSCI and PV stolen time tests both need to make SMCCC calls within the guest. Create a helper for making SMCCC calls and rework the existing tests to use the library function. Signed-off-by: Oliver Upton --- .../testing/selftests/kvm/aarch64/psci_test.c | 25 ++-

[PATCH v2 00/11] KVM: arm64: Implement PSCI SYSTEM_SUSPEND support

2021-09-23 Thread Oliver Upton
Certain VMMs/operators may wish to give their guests the ability to initiate a system suspend that could result in the VM being saved to persistent storage to be resumed at a later time. The PSCI v1.0 specification describes an SMC, SYSTEM_SUSPEND, that allows a kernel to request a system suspend.

[PATCH v2 01/11] KVM: arm64: Drop unused vcpu param to kvm_psci_valid_affinity()

2021-09-23 Thread Oliver Upton
The helper function does not need a pointer to the vCPU, as it only consults a constant mask; drop the unused vcpu parameter. Signed-off-by: Oliver Upton --- arch/arm64/kvm/psci.c | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/psci.c

[PATCH v2 10/11] selftests: KVM: Refactor psci_test to make it amenable to new tests

2021-09-23 Thread Oliver Upton
Split up the current test into several helpers that will be useful to subsequent test cases added to the PSCI test suite. Signed-off-by: Oliver Upton --- .../testing/selftests/kvm/aarch64/psci_test.c | 68 --- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git

[PATCH v2 06/11] KVM: arm64: Add support for SYSTEM_SUSPEND PSCI call

2021-09-23 Thread Oliver Upton
ARM DEN0022D 5.19 "SYSTEM_SUSPEND" describes a PSCI call that may be used to request a system be suspended. This is optional for PSCI v1.0 and to date KVM has elected to not implement the call. However, a VMM/operator may wish to provide their guests with the ability to suspend/resume,

[PATCH v2 02/11] KVM: arm64: Clean up SMC64 PSCI filtering for AArch32 guests

2021-09-23 Thread Oliver Upton
The only valid calling SMC calling convention from an AArch32 state is SMC32. Disallow any PSCI function that sets the SMC64 function ID bit when called from AArch32 rather than comparing against known SMC64 PSCI functions. Signed-off-by: Oliver Upton --- arch/arm64/kvm/psci.c | 14

[PATCH v2 07/11] selftests: KVM: Rename psci_cpu_on_test to psci_test

2021-09-23 Thread Oliver Upton
There are other interactions with PSCI worth testing; rename the PSCI test to make it more generic. No functional change intended. Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/.gitignore | 2 +- tools/testing/selftests/kvm/Makefile

[PATCH v2 05/11] KVM: arm64: Defer WFI emulation as a requested event

2021-09-23 Thread Oliver Upton
The emulation of WFI-like instructions (WFI, PSCI CPU_SUSPEND) is done by calling kvm_vcpu_block() directly from the respective exit handlers. A subsequent change to KVM will allow userspace to request a vCPU be suspended on the next KVM_RUN, necessitating a deferral mechanism for WFI emulation.

Re: [PATCH] Documentation, dt, numa: Add note to empty NUMA node

2021-09-23 Thread Rob Herring
On Thu, Sep 23, 2021 at 1:32 AM Gavin Shan wrote: > > Hi Rob and Ard, > > On 9/22/21 9:05 PM, Ard Biesheuvel wrote: > > On Tue, 21 Sept 2021 at 21:45, Rob Herring wrote: > >> On Sun, Sep 5, 2021 at 11:16 PM Gavin Shan wrote: > >>> > >>> The empty memory nodes, where no memory resides in, are

Re: [RFC PATCH v4 00/39] KVM: arm64: Add Statistical Profiling Extension (SPE) support

2021-09-23 Thread Alexandru Elisei
Hi Suzuki, Thank you for having a look! On 9/22/21 11:11, Suzuki K Poulose wrote: > On 25/08/2021 17:17, Alexandru Elisei wrote: >> This is v4 of the SPE series posted at [1]. v2 can be found at [2], and the >> original series at [3]. >> >> Statistical Profiling Extension (SPE) is an optional

Re: [PATCH v1 3/3] KVM: arm64: Add histogram stats for handling time of arch specific exit reasons

2021-09-23 Thread David Matlack
On Wed, Sep 22, 2021 at 11:53 AM Marc Zyngier wrote: > > On Wed, 22 Sep 2021 19:13:40 +0100, > Sean Christopherson wrote: > > > Stepping back a bit, this is one piece of the larger issue of how to > > modernize KVM for hyperscale usage. BPF and tracing are great when > > the debugger has root

Re: [PATCH 5/5] KVM: arm64: Disable privileged hypercalls after pKVM finalisation

2021-09-23 Thread Marc Zyngier
On Thu, 23 Sep 2021 14:02:11 +0100, Will Deacon wrote: > > On Thu, Sep 23, 2021 at 01:56:21PM +0100, Marc Zyngier wrote: > > On Thu, 23 Sep 2021 12:22:56 +0100, > > Will Deacon wrote: [...] > > > static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) > > > { > > >

Re: [PATCH 5/5] KVM: arm64: Disable privileged hypercalls after pKVM finalisation

2021-09-23 Thread Will Deacon
On Thu, Sep 23, 2021 at 01:56:21PM +0100, Marc Zyngier wrote: > On Thu, 23 Sep 2021 12:22:56 +0100, > Will Deacon wrote: > > > > After pKVM has been 'finalised' using the __pkvm_prot_finalize hypercall, > > the calling CPU will have a Stage-2 translation enabled to prevent access > > to memory

Re: [PATCH 5/5] KVM: arm64: Disable privileged hypercalls after pKVM finalisation

2021-09-23 Thread Will Deacon
On Thu, Sep 23, 2021 at 12:22:56PM +0100, Will Deacon wrote: > After pKVM has been 'finalised' using the __pkvm_prot_finalize hypercall, > the calling CPU will have a Stage-2 translation enabled to prevent access > to memory pages owned by EL2. > > Although this forms a significant part of the

Re: [PATCH 5/5] KVM: arm64: Disable privileged hypercalls after pKVM finalisation

2021-09-23 Thread Marc Zyngier
On Thu, 23 Sep 2021 12:22:56 +0100, Will Deacon wrote: > > After pKVM has been 'finalised' using the __pkvm_prot_finalize hypercall, > the calling CPU will have a Stage-2 translation enabled to prevent access > to memory pages owned by EL2. > > Although this forms a significant part of the

Re: [PATCH 1/5] arm64: Prevent kexec and hibernation if is_protected_kvm_enabled()

2021-09-23 Thread Will Deacon
On Thu, Sep 23, 2021 at 12:45:06PM +0100, Mark Rutland wrote: > On Thu, Sep 23, 2021 at 12:22:52PM +0100, Will Deacon wrote: > > When pKVM is enabled, the hypervisor code at EL2 and its data structures > > are inaccessible to the host kernel and cannot be torn down or replaced > > as this would

Re: [PATCH 0/5] KVM: arm64: Restrict host hypercalls when pKVM is enabled

2021-09-23 Thread Marc Zyngier
On Thu, 23 Sep 2021 12:22:51 +0100, Will Deacon wrote: > > Hi folks, > > This series restricts the hypercalls available to the KVM host on arm64 > when pKVM is enabled so that it is not possible for the host to use them > to replace the EL2 component with something else. > > This occurs in two

Re: [PATCH 1/5] arm64: Prevent kexec and hibernation if is_protected_kvm_enabled()

2021-09-23 Thread Mark Rutland
On Thu, Sep 23, 2021 at 12:22:52PM +0100, Will Deacon wrote: > When pKVM is enabled, the hypervisor code at EL2 and its data structures > are inaccessible to the host kernel and cannot be torn down or replaced > as this would defeat the integrity properies which pKVM aims to provide. >

[PATCH 5/5] KVM: arm64: Disable privileged hypercalls after pKVM finalisation

2021-09-23 Thread Will Deacon
After pKVM has been 'finalised' using the __pkvm_prot_finalize hypercall, the calling CPU will have a Stage-2 translation enabled to prevent access to memory pages owned by EL2. Although this forms a significant part of the process to deprivilege the host kernel, we also need to ensure that the

[PATCH 4/5] KVM: arm64: Prevent re-finalisation of pKVM for a given CPU

2021-09-23 Thread Will Deacon
__pkvm_prot_finalize() completes the deprivilege of the host when pKVM is in use by installing a stage-2 translation table for the calling CPU. Issuing the hypercall multiple times for a given CPU makes little sense, but in such a case just return early with -EPERM rather than go through the

[PATCH 3/5] KVM: arm64: Propagate errors from __pkvm_prot_finalize hypercall

2021-09-23 Thread Will Deacon
If the __pkvm_prot_finalize hypercall returns an error, we WARN but fail to propagate the failure code back to kvm_arch_init(). Pass a pointer to a zero-initialised return variable so that failure to finalise the pKVM protections on a host CPU can be reported back to KVM. Cc: Marc Zyngier Cc:

[PATCH 2/5] KVM: arm64: Reject stub hypercalls after pKVM has been initialised

2021-09-23 Thread Will Deacon
The stub hypercalls provide mechanisms to reset and replace the EL2 code, so uninstall them once pKVM has been initialised in order to ensure the integrity of the hypervisor code. To ensure pKVM initialisation remains functional, split cpu_hyp_reinit() into two helper functions to separate usage

[PATCH 1/5] arm64: Prevent kexec and hibernation if is_protected_kvm_enabled()

2021-09-23 Thread Will Deacon
When pKVM is enabled, the hypervisor code at EL2 and its data structures are inaccessible to the host kernel and cannot be torn down or replaced as this would defeat the integrity properies which pKVM aims to provide. Furthermore, the ABI between the host and EL2 is flexible and private to

[PATCH 0/5] KVM: arm64: Restrict host hypercalls when pKVM is enabled

2021-09-23 Thread Will Deacon
Hi folks, This series restricts the hypercalls available to the KVM host on arm64 when pKVM is enabled so that it is not possible for the host to use them to replace the EL2 component with something else. This occurs in two stages: when switching to the pKVM vectors, the stub hypercalls are

Re: [PATCH v1 3/3] KVM: arm64: Add histogram stats for handling time of arch specific exit reasons

2021-09-23 Thread Paolo Bonzini
On 23/09/21 09:45, Marc Zyngier wrote: On Thu, 23 Sep 2021 07:36:21 +0100, Paolo Bonzini wrote: On 22/09/21 20:53, Marc Zyngier wrote: I definitely regret adding the current KVM trace points, as they don't show what I need, and I can't change them as they are ABI. I disagree that they are

Re: [PATCH v1 3/3] KVM: arm64: Add histogram stats for handling time of arch specific exit reasons

2021-09-23 Thread Marc Zyngier
On Thu, 23 Sep 2021 07:36:21 +0100, Paolo Bonzini wrote: > > On 22/09/21 20:53, Marc Zyngier wrote: > > I definitely regret adding the current KVM trace points, as they > > don't show what I need, and I can't change them as they are ABI. > > I disagree that they are ABI. And even if you don't

Re: [PATCH v1 3/3] KVM: arm64: Add histogram stats for handling time of arch specific exit reasons

2021-09-23 Thread Paolo Bonzini
On 22/09/21 20:53, Marc Zyngier wrote: I definitely regret adding the current KVM trace points, as they don't show what I need, and I can't change them as they are ABI. I disagree that they are ABI. And even if you don't want to change them, you can always add parameters or remove them.

Re: [PATCH] Documentation, dt, numa: Add note to empty NUMA node

2021-09-23 Thread Gavin Shan
Hi Rob and Ard, On 9/22/21 9:05 PM, Ard Biesheuvel wrote: On Tue, 21 Sept 2021 at 21:45, Rob Herring wrote: On Sun, Sep 5, 2021 at 11:16 PM Gavin Shan wrote: The empty memory nodes, where no memory resides in, are allowed. For these empty memory nodes, the 'len' of 'reg' property is zero.