Re: [PATCH v6 00/21] KVM: Add idempotent controls for migrating system counter state

2021-08-04 Thread Oliver Upton
On Wed, Aug 4, 2021 at 4:05 AM Oliver Upton wrote: > > On Wed, Aug 4, 2021 at 1:58 AM Oliver Upton wrote: > > > > KVM's current means of saving/restoring system counters is plagued with > > temporal issues. At least on ARM64 and x86, we migrate the guest's > > system counter by-value through the

Re: [PATCH v6 00/21] KVM: Add idempotent controls for migrating system counter state

2021-08-04 Thread Oliver Upton
On Wed, Aug 4, 2021 at 1:58 AM Oliver Upton wrote: > > KVM's current means of saving/restoring system counters is plagued with > temporal issues. At least on ARM64 and x86, we migrate the guest's > system counter by-value through the respective guest system register > values (cntvct_el0,

Re: [PATCH v6 17/21] KVM: arm64: Allow userspace to configure a guest's counter-timer offset

2021-08-04 Thread Oliver Upton
On Wed, Aug 4, 2021 at 3:17 AM Andrew Jones wrote: > > diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c > > index a8815b09da3e..f15058612994 100644 > > --- a/arch/arm64/kvm/arch_timer.c > > +++ b/arch/arm64/kvm/arch_timer.c > > @@ -85,11 +85,15 @@ u64 timer_get_cval(struct

[PATCH v6 10/21] selftests: KVM: Introduce system counter offset test

2021-08-04 Thread Oliver Upton
Introduce a KVM selftest to verify that userspace manipulation of the TSC (via the new vCPU attribute) results in the correct behavior within the guest. Reviewed-by: Andrew Jones Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/.gitignore| 1 +

[PATCH v6 09/21] selftests: KVM: Add helpers for vCPU device attributes

2021-08-04 Thread Oliver Upton
vCPU file descriptors are abstracted away from test code in KVM selftests, meaning that tests cannot directly access a vCPU's device attributes. Add helpers that tests can use to get at vCPU device attributes. Reviewed-by: Andrew Jones Signed-off-by: Oliver Upton ---

[PATCH v6 17/21] KVM: arm64: Allow userspace to configure a guest's counter-timer offset

2021-08-04 Thread Oliver Upton
Presently, KVM provides no facilities for correctly migrating a guest that depends on the physical counter-timer. Whie most guests (barring NV, of course) should not depend on the physical counter-timer, an operator may wish to provide a consistent view of the physical counter-timer across

[PATCH v6 16/21] arm64: cpufeature: Enumerate support for Enhanced Counter Virtualization

2021-08-04 Thread Oliver Upton
Introduce a new cpucap to indicate if the system supports full enhanced counter virtualization (i.e. ID_AA64MMFR0_EL1.ECV==0x2). Signed-off-by: Oliver Upton --- arch/arm64/include/asm/sysreg.h | 2 ++ arch/arm64/kernel/cpufeature.c | 10 ++ arch/arm64/tools/cpucaps| 1 + 3

[PATCH v6 11/21] KVM: arm64: Refactor update_vtimer_cntvoff()

2021-08-04 Thread Oliver Upton
Make the implementation of update_vtimer_cntvoff() generic w.r.t. guest timer context and spin off into a new helper method for later use. Require callers of this new helper method to grab the kvm lock beforehand. No functional change intended. Signed-off-by: Oliver Upton ---

[PATCH v6 21/21] selftests: KVM: Add counter emulation benchmark

2021-08-04 Thread Oliver Upton
Add a test case for counter emulation on arm64. A side effect of how KVM handles physical counter offsetting on non-ECV systems is that the virtual counter will always hit hardware and the physical could be emulated. Force emulation by writing a nonzero offset to the physical counter and compare

[PATCH v6 19/21] KVM: arm64: Emulate physical counter offsetting on non-ECV systems

2021-08-04 Thread Oliver Upton
Unfortunately, ECV hasn't yet arrived in any tangible hardware. At the same time, controlling the guest view of the physical counter-timer is useful. Support guest counter-timer offsetting on non-ECV systems by trapping guest accesses to the physical counter-timer. Emulate reads of the physical

[PATCH v6 08/21] selftests: KVM: Fix kvm device helper ioctl assertions

2021-08-04 Thread Oliver Upton
The KVM_CREATE_DEVICE and KVM_{GET,SET}_DEVICE_ATTR ioctls are defined to return a value of zero on success. As such, tighten the assertions in the helper functions to only pass if the return code is zero. Suggested-by: Andrew Jones Reviewed-by: Andrew Jones Signed-off-by: Oliver Upton ---

[PATCH v6 03/21] KVM: x86: Take the pvclock sync lock behind the tsc_write_lock

2021-08-04 Thread Oliver Upton
A later change requires that the pvclock sync lock be taken while holding the tsc_write_lock. Change the locking in kvm_synchronize_tsc() to align with the requirement to isolate the locking change to its own commit. Cc: Sean Christopherson Signed-off-by: Oliver Upton ---

[PATCH v6 15/21] selftests: KVM: Add support for aarch64 to system_counter_offset_test

2021-08-04 Thread Oliver Upton
KVM/arm64 now allows userspace to adjust the guest virtual counter-timer via a vCPU register. Test that changes to the virtual counter-timer offset result in the correct view being presented to the guest. Reviewed-by: Andrew Jones Signed-off-by: Oliver Upton ---

[PATCH v6 18/21] KVM: arm64: Configure timer traps in vcpu_load() for VHE

2021-08-04 Thread Oliver Upton
In preparation for emulated physical counter-timer offsetting, configure traps on every vcpu_load() for VHE systems. As before, these trap settings do not affect host userspace, and are only active for the guest. Suggested-by: Marc Zyngier Signed-off-by: Oliver Upton ---

[PATCH v6 07/21] selftests: KVM: Add test for KVM_{GET,SET}_CLOCK

2021-08-04 Thread Oliver Upton
Add a selftest for the new KVM clock UAPI that was introduced. Ensure that the KVM clock is consistent between userspace and the guest, and that the difference in realtime will only ever cause the KVM clock to advance forward. Cc: Andrew Jones Signed-off-by: Oliver Upton ---

[PATCH v6 12/21] KVM: arm64: Separate guest/host counter offset values

2021-08-04 Thread Oliver Upton
In some instances, a VMM may want to update the guest's counter-timer offset in a transparent manner, meaning that changes to the hardware value do not affect the synthetic register presented to the guest or the VMM through said guest's architectural state. Lay the groundwork to separate guest

[PATCH v6 02/21] KVM: x86: Report host tsc and realtime values in KVM_GET_CLOCK

2021-08-04 Thread Oliver Upton
Handling the migration of TSCs correctly is difficult, in part because Linux does not provide userspace with the ability to retrieve a (TSC, realtime) clock pair for a single instant in time. In lieu of a more convenient facility, KVM can report similar information in the kvm_clock structure.

[PATCH v6 04/21] KVM: x86: Refactor tsc synchronization code

2021-08-04 Thread Oliver Upton
Refactor kvm_synchronize_tsc to make a new function that allows callers to specify TSC parameters (offset, value, nanoseconds, etc.) explicitly for the sake of participating in TSC synchronization. Signed-off-by: Oliver Upton --- arch/x86/kvm/x86.c | 105

[PATCH v6 20/21] selftests: KVM: Test physical counter offsetting

2021-08-04 Thread Oliver Upton
Test that userspace adjustment of the guest physical counter-timer results in the correct view within the guest. Cc: Andrew Jones Signed-off-by: Oliver Upton --- .../selftests/kvm/include/aarch64/processor.h | 12 +++ .../kvm/system_counter_offset_test.c | 31 +--

[PATCH v6 01/21] KVM: x86: Fix potential race in KVM_GET_CLOCK

2021-08-04 Thread Oliver Upton
Sean noticed that KVM_GET_CLOCK was checking kvm_arch.use_master_clock outside of the pvclock sync lock. This is problematic, as the clock value written to the user may or may not actually correspond to a stable TSC. Fix the race by populating the entire kvm_clock_data structure behind the

[PATCH v6 00/21] KVM: Add idempotent controls for migrating system counter state

2021-08-04 Thread Oliver Upton
KVM's current means of saving/restoring system counters is plagued with temporal issues. At least on ARM64 and x86, we migrate the guest's system counter by-value through the respective guest system register values (cntvct_el0, ia32_tsc). Restoring system counters by-value is brittle as the state

[PATCH v6 14/21] selftests: KVM: Add helper to check for register presence

2021-08-04 Thread Oliver Upton
The KVM_GET_REG_LIST vCPU ioctl returns a list of supported registers for a given vCPU. Add a helper to check if a register exists in the list of supported registers. Signed-off-by: Oliver Upton --- .../testing/selftests/kvm/include/kvm_util.h | 2 ++

[PATCH v6 06/21] tools: arch: x86: pull in pvclock headers

2021-08-04 Thread Oliver Upton
Copy over approximately clean versions of the pvclock headers into tools. Reconcile headers/symbols missing in tools that are unneeded. Signed-off-by: Oliver Upton --- tools/arch/x86/include/asm/pvclock-abi.h | 48 +++ tools/arch/x86/include/asm/pvclock.h | 103

[PATCH v6 13/21] KVM: arm64: Allow userspace to configure a vCPU's virtual offset

2021-08-04 Thread Oliver Upton
Allow userspace to access the guest's virtual counter-timer offset through the ONE_REG interface. The value read or written is defined to be an offset from the guest's physical counter-timer. Add some documentation to clarify how a VMM should use this and the existing CNTVCT_EL0. Signed-off-by:

[PATCH v6 05/21] KVM: x86: Expose TSC offset controls to userspace

2021-08-04 Thread Oliver Upton
To date, VMM-directed TSC synchronization and migration has been a bit messy. KVM has some baked-in heuristics around TSC writes to infer if the VMM is attempting to synchronize. This is problematic, as it depends on host userspace writing to the guest's TSC within 1 second of the last write. A

Re: [PATCH v2 0/2] KVM: arm64: Prevent kmemleak from accessing HYP data

2021-08-04 Thread Marc Zyngier
On Mon, 2 Aug 2021 13:38:28 +0100, Marc Zyngier wrote: > This is a rework of the patch previously posted at [1]. > > The gist of the problem is that kmemleak can legitimately access data > that has been removed from the kernel view, for two reasons: > > (1) .hyp.rodata is lumped together with

Re: [PATCH v6 19/21] KVM: arm64: Emulate physical counter offsetting on non-ECV systems

2021-08-04 Thread Andrew Jones
On Wed, Aug 04, 2021 at 08:58:17AM +, Oliver Upton wrote: > Unfortunately, ECV hasn't yet arrived in any tangible hardware. At the > same time, controlling the guest view of the physical counter-timer is > useful. Support guest counter-timer offsetting on non-ECV systems by > trapping guest

Re: [PATCH v6 20/21] selftests: KVM: Test physical counter offsetting

2021-08-04 Thread Andrew Jones
On Wed, Aug 04, 2021 at 08:58:18AM +, Oliver Upton wrote: > Test that userspace adjustment of the guest physical counter-timer > results in the correct view within the guest. > > Cc: Andrew Jones > Signed-off-by: Oliver Upton > --- > .../selftests/kvm/include/aarch64/processor.h | 12

Re: [PATCH v5 11/13] KVM: arm64: Provide userspace access to the physical counter offset

2021-08-04 Thread Oliver Upton
Hi Marc, On Fri, Jul 30, 2021 at 9:48 AM Oliver Upton wrote: > > On Fri, Jul 30, 2021 at 9:18 AM Marc Zyngier wrote: > > You want the ARM FVP model, or maybe even the Foundation model. It has > > support all the way to ARMv8.7 apparently. I personally use the FVP, > > get in touch offline and

Re: [PATCH v6 18/21] KVM: arm64: Configure timer traps in vcpu_load() for VHE

2021-08-04 Thread Andrew Jones
On Wed, Aug 04, 2021 at 08:58:16AM +, Oliver Upton wrote: > In preparation for emulated physical counter-timer offsetting, configure > traps on every vcpu_load() for VHE systems. As before, these trap > settings do not affect host userspace, and are only active for the > guest. > >

Re: [PATCH v6 13/21] KVM: arm64: Allow userspace to configure a vCPU's virtual offset

2021-08-04 Thread Andrew Jones
On Wed, Aug 04, 2021 at 08:58:11AM +, Oliver Upton wrote: > Allow userspace to access the guest's virtual counter-timer offset > through the ONE_REG interface. The value read or written is defined to > be an offset from the guest's physical counter-timer. Add some > documentation to clarify

Re: [PATCH v6 12/21] KVM: arm64: Separate guest/host counter offset values

2021-08-04 Thread Andrew Jones
On Wed, Aug 04, 2021 at 08:58:10AM +, Oliver Upton wrote: > In some instances, a VMM may want to update the guest's counter-timer > offset in a transparent manner, meaning that changes to the hardware > value do not affect the synthetic register presented to the guest or the > VMM through said

Re: [PATCH v6 17/21] KVM: arm64: Allow userspace to configure a guest's counter-timer offset

2021-08-04 Thread Andrew Jones
On Wed, Aug 04, 2021 at 08:58:15AM +, Oliver Upton wrote: > Presently, KVM provides no facilities for correctly migrating a guest > that depends on the physical counter-timer. Whie most guests (barring > NV, of course) should not depend on the physical counter-timer, an > operator may wish to

Re: [PATCH v3] memblock: make memblock_find_in_range method private

2021-08-04 Thread Catalin Marinas
On Tue, Aug 03, 2021 at 10:07:37PM +0300, Mike Rapoport wrote: > On Tue, Aug 03, 2021 at 07:05:26PM +0100, Catalin Marinas wrote: > > On Tue, Aug 03, 2021 at 09:42:18AM +0300, Mike Rapoport wrote: > > > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > > > index 8490ed2917ff..0bffd2d1854f

Re: [PATCH v6 11/21] KVM: arm64: Refactor update_vtimer_cntvoff()

2021-08-04 Thread Andrew Jones
On Wed, Aug 04, 2021 at 08:58:09AM +, Oliver Upton wrote: > Make the implementation of update_vtimer_cntvoff() generic w.r.t. guest > timer context and spin off into a new helper method for later use. > Require callers of this new helper method to grab the kvm lock > beforehand. > > No

Re: [PATCH v6 14/21] selftests: KVM: Add helper to check for register presence

2021-08-04 Thread Andrew Jones
On Wed, Aug 04, 2021 at 08:58:12AM +, Oliver Upton wrote: > The KVM_GET_REG_LIST vCPU ioctl returns a list of supported registers > for a given vCPU. Add a helper to check if a register exists in the list > of supported registers. > > Signed-off-by: Oliver Upton > --- >