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 > > s

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 (cntvc

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 + tools/testing/selftests/kvm

[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 --- .../testing/selftests/kvm

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

2021-08-04 Thread Oliver Upton
on ECV systems as ECV is required for hardware offsetting of the physical counter-timer. Signed-off-by: Oliver Upton --- Documentation/virt/kvm/devices/vcpu.rst | 28 ++ arch/arm64/include/asm/kvm_asm.h| 2 + arch/arm64/include/asm/sysreg.h | 2 + arch/arm64/include/uapi

[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 --- arch/arm64/kvm

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

2021-08-04 Thread Oliver Upton
the elapsed cycles to a direct read of the hardware register. Reviewed-by: Ricardo Koller Signed-off-by: Oliver Upton Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/.gitignore| 1 + tools/testing/selftests/kvm/Makefile | 1 + .../kvm/aarch64

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

2021-08-04 Thread Oliver Upton
counter in the fast exit path. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/sysreg.h | 1 + arch/arm64/kvm/arch_timer.c | 53 +++-- arch/arm64/kvm/hyp/include/hyp/switch.h | 29 ++ arch/arm64/kvm/hyp/nvhe/timer-sr.c | 11 - 4

[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 --- Documentation/virt

[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 --- tools/testing/selftests/kvm

[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 --- arch/arm64/kvm

[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 --- tools/testing

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

2021-08-04 Thread Oliver Upton
offset register writes from the hardware values utilized by KVM. Signed-off-by: Oliver Upton --- arch/arm64/kvm/arch_timer.c | 48 include/kvm/arm_arch_timer.h | 3 +++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/arch_timer.c

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

2021-08-04 Thread Oliver Upton
sted-by: Paolo Bonzini Signed-off-by: Oliver Upton --- Documentation/virt/kvm/api.rst | 42 --- arch/x86/include/asm/kvm_host.h | 3 + arch/x86/kvm/x86.c | 127 ++-- include/uapi/linux/kvm.h| 7 +- 4 files changed, 112 insertions(+)

[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
the pvclock_gtod_sync_lock. Suggested-by: Sean Christopherson Signed-off-by: Oliver Upton --- arch/x86/kvm/x86.c | 39 --- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8cdf4ac6990b..34287c522f4e 100644

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

2021-08-04 Thread Oliver Upton
3: https://lore.kernel.org/r/20210719184949.1385910-1-oup...@google.com v4: https://lore.kernel.org/r/20210729001012.70394-1-oup...@google.com v5: https://lore.kernel.org/r/20210729173300.181775-1-oup...@google.com Oliver Upton (21): KVM: x86: Fix potential race in KVM_GET_CLOCK KVM: x86: Report

[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 ++ tools/testing/selftests/kvm/lib

[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
-by: Oliver Upton --- Documentation/virt/kvm/api.rst| 10 ++ arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/kvm/arch_timer.c | 11 +++ arch/arm64/kvm/guest.c| 6 +- include/kvm/arm_arch_timer.h | 1 + 5 files changed, 28 insertions(+), 1 deletion

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

2021-08-04 Thread Oliver Upton
to capture a (realtime, host_tsc) pair at the instant when the guest is paused. Cc: David Matlack Cc: Sean Christopherson Signed-off-by: Oliver Upton --- Documentation/virt/kvm/devices/vcpu.rst | 57 + arch/x86/include/asm/kvm_host.h | 1 + arch/x86/include/uapi/asm/kvm.h

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, > &

Re: [PATCH v5 02/13] KVM: x86: Refactor tsc synchronization code

2021-08-03 Thread Oliver Upton
On Fri, Jul 30, 2021 at 11:08 AM Sean Christopherson wrote: > > On Thu, Jul 29, 2021, Oliver Upton wrote: > > Refactor kvm_synchronize_tsc to make a new function that allows callers > > to specify TSC parameters (offset, value, nanoseconds, etc.) explicitly > > for t

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

2021-08-02 Thread Oliver Upton
On Fri, Jul 30, 2021 at 3:12 AM Marc Zyngier wrote: > > On Thu, 29 Jul 2021 18:32:56 +0100, > Oliver Upton wrote: > > > > Add a new vCPU attribute that allows userspace to directly manipulate > > the virtual counter-timer offset. Exposing such an interface allows fo

[PATCH v3 2/3] entry: KVM: Allow use of generic KVM entry w/o full generic support

2021-08-02 Thread Oliver Upton
by tightening up the include list. No functional change intended. Signed-off-by: Oliver Upton --- include/linux/entry-kvm.h | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/entry-kvm.h b/include/linux/entry-kvm.h index 136b8d97d8c0..0d7865a0731c 100644

[PATCH v3 0/3] KVM: arm64: Use generic guest entry infrastructure

2021-08-02 Thread Oliver Upton
tag v2 -> v3: - Roll all exit conditions into kvm_vcpu_exit_request() (Marc) - Avoid needlessly checking for work twice (Marc) v1: http://lore.kernel.org/r/20210729195632.489978-1-oup...@google.com v2: http://lore.kernel.org/r/20210729220916.1672875-1-oup...@google.com Oliver Upton (3): KV

[PATCH v3 1/3] KVM: arm64: Record number of signal exits as a vCPU stat

2021-08-02 Thread Oliver Upton
Most other architectures that implement KVM record a statistic indicating the number of times a vCPU has exited due to a pending signal. Add support for that stat to arm64. Reviewed-by: Jing Zhang Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c

[PATCH v3 3/3] KVM: arm64: Use generic KVM xfer to guest work function

2021-08-02 Thread Oliver Upton
Clean up handling of checks for pending work by switching to the generic infrastructure to do so. We pick up handling for TIF_NOTIFY_RESUME from this switch, meaning that task work will be correctly handled. Signed-off-by: Oliver Upton --- arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/arm.c

Re: [PATCH v5 01/13] KVM: x86: Report host tsc and realtime values in KVM_GET_CLOCK

2021-07-30 Thread Oliver Upton
On Fri, Jul 30, 2021 at 10:48 AM Sean Christopherson wrote: > > On Thu, Jul 29, 2021, Oliver Upton wrote: > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 916c976e99ab..e052c7afaac4 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/

Re: [PATCH v2 3/3] KVM: arm64: Use generic KVM xfer to guest work function

2021-07-30 Thread Oliver Upton
On Fri, Jul 30, 2021 at 9:56 AM Sean Christopherson wrote: > > On Fri, Jul 30, 2021, Oliver Upton wrote: > > > > On Fri, Jul 30, 2021 at 2:41 AM Marc Zyngier wrote: > > > > > > On Thu, 29 Jul 2021 23:09:16 +0100, Oliver Upton > > > wr

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

2021-07-30 Thread Oliver Upton
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 I'll help you with the setup. > > In general, I tend to trust the ARM

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

2021-07-30 Thread Oliver Upton
On Fri, Jul 30, 2021 at 4:08 AM Marc Zyngier wrote: > > FEAT_ECV provides a guest physical counter-timer offset register > > (CNTPOFF_EL2), but ECV-enabled hardware is nonexistent at the time of > > writing so support for it was elided for the sake of the author :) > > You seem to have done most

Re: [PATCH v2 3/3] KVM: arm64: Use generic KVM xfer to guest work function

2021-07-30 Thread Oliver Upton
Marc, On Fri, Jul 30, 2021 at 2:41 AM Marc Zyngier wrote: > > Hi Oliver, > > On Thu, 29 Jul 2021 23:09:16 +0100, > Oliver Upton wrote: > > > > Clean up handling of checks for pending work by switching to the generic > > infrastructure to do so. > > > &

[PATCH v2 2/3] entry: KVM: Allow use of generic KVM entry w/o full generic support

2021-07-29 Thread Oliver Upton
by tightening up the include list. No functional change intended. Signed-off-by: Oliver Upton --- include/linux/entry-kvm.h | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/entry-kvm.h b/include/linux/entry-kvm.h index 136b8d97d8c0..0d7865a0731c 100644

[PATCH v2 3/3] KVM: arm64: Use generic KVM xfer to guest work function

2021-07-29 Thread Oliver Upton
Clean up handling of checks for pending work by switching to the generic infrastructure to do so. We pick up handling for TIF_NOTIFY_RESUME from this switch, meaning that task work will be correctly handled. Signed-off-by: Oliver Upton --- arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/arm.c

[PATCH v2 1/3] KVM: arm64: Record number of signal exits as a vCPU stat

2021-07-29 Thread Oliver Upton
Most other architectures that implement KVM record a statistic indicating the number of times a vCPU has exited due to a pending signal. Add support for that stat to arm64. Reviewed-by: Jing Zhang Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c

[PATCH v2 0/3] KVM: arm64: Use generic guest entry infrastructure

2021-07-29 Thread Oliver Upton
tag v1: http://lore.kernel.org/r/20210729195632.489978-1-oup...@google.com Oliver Upton (3): KVM: arm64: Record number of signal exits as a vCPU stat entry: KVM: Allow use of generic KVM entry w/o full generic support KVM: arm64: Use generic KVM xfer to guest work function arch/arm6

Re: [PATCH 1/3] KVM: arm64: Record number of signal exits as a vCPU stat

2021-07-29 Thread Oliver Upton
On Thu, Jul 29, 2021 at 1:07 PM Jing Zhang wrote: > > On Thu, Jul 29, 2021 at 12:56 PM Oliver Upton wrote: > > > > Most other architectures that implement KVM record a statistic > > indicating the number of times a vCPU has exited due to a pending > > signal. Add

[PATCH 3/3] KVM: arm64: Use generic KVM xfer to guest work function

2021-07-29 Thread Oliver Upton
Clean up handling of checks for pending work by switching to the generic infrastructure to do so. We pick up handling for TIF_NOTIFY_RESUME from this switch, meaning that task work will be correctly handled. Signed-off-by: Oliver Upton --- arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/arm.c

[PATCH 1/3] KVM: arm64: Record number of signal exits as a vCPU stat

2021-07-29 Thread Oliver Upton
Most other architectures that implement KVM record a statistic indicating the number of times a vCPU has exited due to a pending signal. Add support for that stat to arm64. Cc: Jing Zhang Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c

[PATCH 2/3] entry: KVM: Allow use of generic KVM entry w/o full generic support

2021-07-29 Thread Oliver Upton
by tightening up the include list. No functional change intended. Signed-off-by: Oliver Upton --- include/linux/entry-kvm.h | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/entry-kvm.h b/include/linux/entry-kvm.h index 136b8d97d8c0..0d7865a0731c 100644

[PATCH 0/3] KVM: arm64: Use generic guest entry infrastructure

2021-07-29 Thread Oliver Upton
applies to kvm/queue (note that this is deliberate as the generic kvm stats patches have not yet propagated to kvm-arm/queue) at the following commit: 8ad5e63649ff ("KVM: Don't take mmu_lock for range invalidation unless necessary") Oliver Upton (3): KVM: arm64: Record number of si

[PATCH v5 13/13] selftests: KVM: Add counter emulation benchmark

2021-07-29 Thread Oliver Upton
the elapsed cycles to a direct read of the hardware register. Cc: Andrew Jones Reviewed-by: Ricardo Koller Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/.gitignore| 1 + tools/testing/selftests/kvm/Makefile | 1 + .../kvm/aarch64/counter_emulation_benchmark.c

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

2021-07-29 Thread Oliver Upton
interface, wherein a write to a single vCPU is broadcasted to all vCPUs within a VM. Reviewed-by: Andrew Jones Signed-off-by: Oliver Upton --- Documentation/virt/kvm/devices/vcpu.rst | 22 arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/kvm/arch_timer.c | 68

[PATCH v5 05/13] selftests: KVM: Add test for KVM_{GET,SET}_CLOCK

2021-07-29 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 --- tools/testing

[PATCH v5 12/13] selftests: KVM: Test physical counter offsetting

2021-07-29 Thread Oliver Upton
Test that userpace adjustment of the guest physical counter-timer results in the correct view of within the guest. Reviewed-by: Andrew Jones Signed-off-by: Oliver Upton --- .../selftests/kvm/include/aarch64/processor.h | 12 .../kvm/system_counter_offset_test.c | 29

[PATCH v5 10/13] selftests: KVM: Add support for aarch64 to system_counter_offset_test

2021-07-29 Thread Oliver Upton
KVM/arm64 now allows userspace to adjust the guest virtual counter-timer via a vCPU device attribute. 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 --- tools/testing/selftests

[PATCH v5 01/13] KVM: x86: Report host tsc and realtime values in KVM_GET_CLOCK

2021-07-29 Thread Oliver Upton
sted-by: Paolo Bonzini Signed-off-by: Oliver Upton --- Documentation/virt/kvm/api.rst | 42 +++-- arch/x86/include/asm/kvm_host.h | 3 + arch/x86/kvm/x86.c | 149 include/uapi/linux/kvm.h| 7 +- 4 files changed, 137 insertions(+)

[PATCH v5 04/13] tools: arch: x86: pull in pvclock headers

2021-07-29 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 v5 07/13] selftests: KVM: Add helpers for vCPU device attributes

2021-07-29 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 --- .../testing/selftests/kvm

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

2021-07-29 Thread Oliver Upton
hardware is nonexistent at the time of writing so support for it was elided for the sake of the author :) Reviewed-by: Andrew Jones Signed-off-by: Oliver Upton --- Documentation/virt/kvm/devices/vcpu.rst | 22 +++ arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/include/asm

[PATCH v5 02/13] KVM: x86: Refactor tsc synchronization code

2021-07-29 Thread Oliver Upton
gtod lock while holding the tsc write lock, whereas before these locks were disjoint. Reviewed-by: David Matlack Signed-off-by: Oliver Upton --- Documentation/virt/kvm/locking.rst | 11 +++ arch/x86/kvm/x86.c | 106 + 2 files changed, 74 insertions

[PATCH v5 06/13] selftests: KVM: Fix kvm device helper ioctl assertions

2021-07-29 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 v5 03/13] KVM: x86: Expose TSC offset controls to userspace

2021-07-29 Thread Oliver Upton
to capture a (realtime, host_tsc) pair at the instant when the guest is paused. Cc: David Matlack Signed-off-by: Oliver Upton --- Documentation/virt/kvm/devices/vcpu.rst | 57 arch/x86/include/asm/kvm_host.h | 1 + arch/x86/include/uapi/asm/kvm.h | 4 + arch/x86/kvm/x86.c

[PATCH v5 00/13] KVM: Add idempotent controls for migrating system counter state

2021-07-29 Thread Oliver Upton
p...@google.com v4: https://lore.kernel.org/r/20210729001012.70394-1-oup...@google.com Oliver Upton (13): KVM: x86: Report host tsc and realtime values in KVM_GET_CLOCK KVM: x86: Refactor tsc synchronization code KVM: x86: Expose TSC offset controls to userspace tools: arch: x86: pull in pvclock

[PATCH v5 08/13] selftests: KVM: Introduce system counter offset test

2021-07-29 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 + tools/testing/selftests/kvm

Re: [PATCH v4 13/13] selftests: KVM: Add counter emulation benchmark

2021-07-29 Thread Oliver Upton
On Thu, Jul 29, 2021 at 9:56 AM Andrew Jones wrote: > > On Thu, Jul 29, 2021 at 12:10:12AM +, Oliver Upton wrote: > > 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 > > vir

[PATCH v4 13/13] selftests: KVM: Add counter emulation benchmark

2021-07-28 Thread Oliver Upton
the elapsed cycles to a direct read of the hardware register. Reviewed-by: Ricardo Koller Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/.gitignore| 1 + tools/testing/selftests/kvm/Makefile | 1 + .../kvm/aarch64/counter_emulation_benchmark.c | 215

[PATCH v4 10/13] selftests: KVM: Add support for aarch64 to system_counter_offset_test

2021-07-28 Thread Oliver Upton
KVM/arm64 now allows userspace to adjust the guest virtual counter-timer via a vCPU device attribute. 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 --- tools/testing/selftests

[PATCH v4 08/13] selftests: KVM: Introduce system counter offset test

2021-07-28 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 + tools/testing/selftests/kvm

[PATCH v4 07/13] selftests: KVM: Add helpers for vCPU device attributes

2021-07-28 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 --- .../testing/selftests/kvm

[PATCH v4 05/13] selftests: KVM: Add test for KVM_{GET,SET}_CLOCK

2021-07-28 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 --- tools/testing

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

2021-07-28 Thread Oliver Upton
interface, wherein a write to a single vCPU is broadcasted to all vCPUs within a VM. Reviewed-by: Andrew Jones Signed-off-by: Oliver Upton --- Documentation/virt/kvm/devices/vcpu.rst | 22 arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/kvm/arch_timer.c | 68

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

2021-07-28 Thread Oliver Upton
hardware is nonexistent at the time of writing so support for it was elided for the sake of the author :) Cc: Andrew Jones Signed-off-by: Oliver Upton --- Documentation/virt/kvm/devices/vcpu.rst | 22 +++ arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/include/asm/kvm_hyp.h

[PATCH v4 04/13] tools: arch: x86: pull in pvclock headers

2021-07-28 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 v4 06/13] selftests: KVM: Fix kvm device helper ioctl assertions

2021-07-28 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 Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm

[PATCH v4 00/13] KVM: Add idempotent controls for migrating system counter state

2021-07-28 Thread Oliver Upton
ps://lore.kernel.org/r/20210716212629.2232756-1-oup...@google.com v3: https://lore/kernel.org/r/20210719184949.1385910-1-oup...@google.com Oliver Upton (13): KVM: x86: Report host tsc and realtime values in KVM_GET_CLOCK KVM: x86: Refactor tsc synchronization code KVM: x86: Expose TSC offset controls to usersp

[PATCH v4 01/13] KVM: x86: Report host tsc and realtime values in KVM_GET_CLOCK

2021-07-28 Thread Oliver Upton
-off-by: Oliver Upton --- Documentation/virt/kvm/api.rst | 42 +++-- arch/x86/include/asm/kvm_host.h | 3 + arch/x86/kvm/x86.c | 149 include/uapi/linux/kvm.h| 7 +- 4 files changed, 137 insertions(+), 64 deletions(-) diff -

[PATCH v4 12/13] selftests: KVM: Test physical counter offsetting

2021-07-28 Thread Oliver Upton
Test that userpace adjustment of the guest physical counter-timer results in the correct view of within the guest. Reviewed-by: Andrew Jones Signed-off-by: Oliver Upton --- .../selftests/kvm/include/aarch64/processor.h | 12 .../kvm/system_counter_offset_test.c | 29

[PATCH v4 02/13] KVM: x86: Refactor tsc synchronization code

2021-07-28 Thread Oliver Upton
gtod lock while holding the tsc write lock, whereas before these locks were disjoint. Reviewed-by: David Matlack Signed-off-by: Oliver Upton --- Documentation/virt/kvm/locking.rst | 11 +++ arch/x86/kvm/x86.c | 106 + 2 files changed, 74 insertions

[PATCH v4 03/13] KVM: x86: Expose TSC offset controls to userspace

2021-07-28 Thread Oliver Upton
to capture a (realtime, host_tsc) pair at the instant when the guest is paused. Cc: David Matlack Signed-off-by: Oliver Upton --- Documentation/virt/kvm/devices/vcpu.rst | 57 arch/x86/include/asm/kvm_host.h | 1 + arch/x86/include/uapi/asm/kvm.h | 4 + arch/x86/kvm/x86.c

Re: [PATCH] KVM: ARM: count remote TLB flushes

2021-07-28 Thread Oliver Upton
ro. > > Signed-off-by: Paolo Bonzini Reviewed-by: Oliver Upton > --- > arch/arm64/kvm/mmu.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index c10207fed2f3..6cf16b43bfcc 100644 > --- a/arch/arm64/kvm/mmu.c

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

2021-07-22 Thread Oliver Upton
On Wed, Jul 21, 2021 at 8:28 AM Andrew Jones wrote: > > On Fri, Jul 16, 2021 at 09:26:17PM +, 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 > >

Re: [PATCH v3 14/15] KVM: arm64: Handle protected guests at 32 bits

2021-07-19 Thread Oliver Upton
On Mon, Jul 19, 2021 at 9:04 AM Fuad Tabba wrote: > > 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

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

2021-07-19 Thread Oliver Upton
On Mon, Jul 19, 2021 at 11:02 AM Jean-Philippe Brucker wrote: > We forward the whole PSCI function range, so it's either KVM or userspace. > If KVM manages PSCI and the guest calls an unimplemented function, that > returns directly to the guest without going to userspace. > > The concern is valid

[PATCH v3 11/12] selftests: KVM: Test physical counter offsetting

2021-07-19 Thread Oliver Upton
Test that userpace adjustment of the guest physical counter-timer results in the correct view of within the guest. Signed-off-by: Oliver Upton --- .../selftests/kvm/include/aarch64/processor.h | 12 .../kvm/system_counter_offset_test.c | 29 --- 2 files changed

[PATCH v3 10/12] KVM: arm64: Provide userspace access to the physical counter offset

2021-07-19 Thread Oliver Upton
hardware is nonexistent at the time of writing so support for it was elided for the sake of the author :) Signed-off-by: Oliver Upton --- Documentation/virt/kvm/devices/vcpu.rst | 22 ++ arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/include/asm/kvm_hyp.h | 2

[PATCH v3 07/12] selftests: KVM: Introduce system counter offset test

2021-07-19 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. Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/.gitignore| 1 + tools/testing/selftests/kvm/Makefile | 1

[PATCH v3 08/12] KVM: arm64: Allow userspace to configure a vCPU's virtual offset

2021-07-19 Thread Oliver Upton
interface, wherein a write to a single vCPU is broadcasted to all vCPUs within a VM. Signed-off-by: Oliver Upton --- Documentation/virt/kvm/devices/vcpu.rst | 22 arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/kvm/arch_timer.c | 68 - 3

[PATCH v3 09/12] selftests: KVM: Add support for aarch64 to system_counter_offset_test

2021-07-19 Thread Oliver Upton
KVM/arm64 now allows userspace to adjust the guest virtual counter-timer via a vCPU device attribute. Test that changes to the virtual counter-timer offset result in the correct view being presented to the guest. Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/Makefile | 1

[PATCH v3 12/12] selftests: KVM: Add counter emulation benchmark

2021-07-19 Thread Oliver Upton
the elapsed cycles to a direct read of the hardware register. Reviewed-by: Ricardo Koller Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/.gitignore| 1 + tools/testing/selftests/kvm/Makefile | 1 + .../kvm/aarch64/counter_emulation_benchmark.c | 215

[PATCH v3 02/12] KVM: x86: Refactor tsc synchronization code

2021-07-19 Thread Oliver Upton
gtod lock while holding the tsc write lock, whereas before these locks were disjoint. Reviewed-by: David Matlack Signed-off-by: Oliver Upton --- Documentation/virt/kvm/locking.rst | 11 +++ arch/x86/kvm/x86.c | 106 + 2 files changed, 74 insertions

[PATCH v3 05/12] selftests: KVM: Add test for KVM_{GET,SET}_CLOCK

2021-07-19 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. Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm

[PATCH v3 06/12] selftests: KVM: Add helpers for vCPU device attributes

2021-07-19 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. Signed-off-by: Oliver Upton --- .../testing/selftests/kvm/include/kvm_util.h | 9

[PATCH v3 04/12] tools: arch: x86: pull in pvclock headers

2021-07-19 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 v3 03/12] KVM: x86: Expose TSC offset controls to userspace

2021-07-19 Thread Oliver Upton
to capture a (realtime, host_tsc) pair at the instant when the guest is paused. Cc: David Matlack Signed-off-by: Oliver Upton --- Documentation/virt/kvm/devices/vcpu.rst | 57 arch/x86/include/asm/kvm_host.h | 1 + arch/x86/include/uapi/asm/kvm.h | 4 + arch/x86/kvm/x86.c

[PATCH v3 01/12] KVM: x86: Report host tsc and realtime values in KVM_GET_CLOCK

2021-07-19 Thread Oliver Upton
-off-by: Oliver Upton --- Documentation/virt/kvm/api.rst | 42 +++-- arch/x86/include/asm/kvm_host.h | 3 + arch/x86/kvm/x86.c | 149 include/uapi/linux/kvm.h| 7 +- 4 files changed, 137 insertions(+), 64 deletions(-) diff -

[PATCH v3 00/12] KVM: Add idempotent controls for migrating system counter state

2021-07-19 Thread Oliver Upton
hroughout series - Rename KVM_CLOCK_REAL_TIME -> KVM_CLOCK_REALTIME v1: https://lore.kernel.org/kvm/20210608214742.1897483-1-oup...@google.com/ v2: https://lore.kernel.org/r/20210716212629.2232756-1-oup...@google.com Oliver Upton (12): KVM: x86: Report host tsc and realtime values in KVM_G

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

2021-07-16 Thread Oliver Upton
On Fri, Jul 16, 2021 at 2:26 PM 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 > val

[PATCH v2 11/12] selftests: KVM: Test physical counter offsetting

2021-07-16 Thread Oliver Upton
Test that userpace adjustment of the guest physical counter-timer results in the correct view of within the guest. Signed-off-by: Oliver Upton --- .../selftests/kvm/include/aarch64/processor.h | 12 .../kvm/system_counter_offset_test.c | 29 --- 2 files changed

[PATCH v2 12/12] selftests: KVM: Add counter emulation benchmark

2021-07-16 Thread Oliver Upton
the elapsed cycles to a direct read of the hardware register. Reviewed-by: Ricardo Koller Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/.gitignore| 1 + tools/testing/selftests/kvm/Makefile | 1 + .../kvm/aarch64/counter_emulation_benchmark.c | 215

[PATCH v2 07/12] selftests: KVM: Introduce system counter offset test

2021-07-16 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. Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/.gitignore| 1 + tools/testing/selftests/kvm/Makefile | 1

[PATCH v2 03/12] KVM: x86: Expose TSC offset controls to userspace

2021-07-16 Thread Oliver Upton
to capture a (realtime, host_tsc) pair at the instant when the guest is paused. Cc: David Matlack Signed-off-by: Oliver Upton --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/include/uapi/asm/kvm.h | 4 + arch/x86/kvm/x86.c | 166 3 files changed

[PATCH v2 02/12] KVM: x86: Refactor tsc synchronization code

2021-07-16 Thread Oliver Upton
gtod lock while holding the tsc write lock, whereas before these locks were disjoint. Reviewed-by: David Matlack Signed-off-by: Oliver Upton --- Documentation/virt/kvm/locking.rst | 11 +++ arch/x86/kvm/x86.c | 106 + 2 files changed, 74 insertions

[PATCH v2 08/12] KVM: arm64: Allow userspace to configure a vCPU's virtual offset

2021-07-16 Thread Oliver Upton
interface, wherein a write to a single vCPU is broadcasted to all vCPUs within a VM. Signed-off-by: Oliver Upton --- arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/kvm/arch_timer.c | 68 ++- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git

[PATCH v2 04/12] tools: arch: x86: pull in pvclock headers

2021-07-16 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

<    1   2   3   4   5   6   7   >