kvmarm.lists.cs.columbia.edu archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap
@ 2020-08-04 17:05 Andrew Jones
  2020-08-04 17:05 ` [PATCH v2 1/6] KVM: arm64: pvtime: steal-time is only supported when configured Andrew Jones
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Andrew Jones @ 2020-08-04 17:05 UTC (permalink / raw)
  To: kvm, kvmarm; +Cc: maz, pbonzini, steven.price

v2:
  - ARM_SMCCC_HV_PV_TIME_FEATURES now also returns SMCCC_RET_NOT_SUPPORTED
    when steal time is not supported
  - Added READ_ONCE() for the run_delay read
  - Reworked kvm_put/get_guest to not require type as a parameter
  - Added some more text to the documentation for KVM_CAP_STEAL_TIME
  - Enough changed that I didn't pick up Steven's r-b's


The first four patches in the series are fixes that come from testing
and reviewing pvtime code while writing the QEMU support[*]. The last
patch is only a convenience for userspace, and I wouldn't be heartbroken
if it wasn't deemed worth it. The QEMU patches are currently written
without the cap. However, if the cap is accepted, then I'll change the
QEMU code to use it.

Thanks,
drew

[*] https://lists.gnu.org/archive/html/qemu-devel/2020-07/msg03856.html
    (a v2 of this series will also be posted shortly)

Andrew Jones (6):
  KVM: arm64: pvtime: steal-time is only supported when configured
  KVM: arm64: pvtime: Fix potential loss of stolen time
  KVM: arm64: Drop type input from kvm_put_guest
  KVM: arm64: pvtime: Fix stolen time accounting across migration
  KVM: Documentation: Minor fixups
  arm64/x86: KVM: Introduce steal-time cap

 Documentation/virt/kvm/api.rst    | 22 ++++++++++++++++++----
 arch/arm64/include/asm/kvm_host.h |  2 +-
 arch/arm64/kvm/arm.c              |  3 +++
 arch/arm64/kvm/pvtime.c           | 29 +++++++++++++----------------
 arch/x86/kvm/x86.c                |  3 +++
 include/linux/kvm_host.h          | 31 ++++++++++++++++++++++++++-----
 include/uapi/linux/kvm.h          |  1 +
 7 files changed, 65 insertions(+), 26 deletions(-)

-- 
2.25.4

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/6] KVM: arm64: pvtime: steal-time is only supported when configured
  2020-08-04 17:05 [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Andrew Jones
@ 2020-08-04 17:05 ` Andrew Jones
  2020-08-04 17:06 ` [PATCH v2 2/6] KVM: arm64: pvtime: Fix potential loss of stolen time Andrew Jones
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2020-08-04 17:05 UTC (permalink / raw)
  To: kvm, kvmarm; +Cc: maz, pbonzini, steven.price

Don't confuse the guest by saying steal-time is supported when
it hasn't been configured by userspace and won't work.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arch/arm64/kvm/pvtime.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/pvtime.c b/arch/arm64/kvm/pvtime.c
index f7b52ce1557e..c3ef4ebd6846 100644
--- a/arch/arm64/kvm/pvtime.c
+++ b/arch/arm64/kvm/pvtime.c
@@ -43,7 +43,8 @@ long kvm_hypercall_pv_features(struct kvm_vcpu *vcpu)
 	switch (feature) {
 	case ARM_SMCCC_HV_PV_TIME_FEATURES:
 	case ARM_SMCCC_HV_PV_TIME_ST:
-		val = SMCCC_RET_SUCCESS;
+		if (vcpu->arch.steal.base != GPA_INVALID)
+			val = SMCCC_RET_SUCCESS;
 		break;
 	}
 
-- 
2.25.4

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/6] KVM: arm64: pvtime: Fix potential loss of stolen time
  2020-08-04 17:05 [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Andrew Jones
  2020-08-04 17:05 ` [PATCH v2 1/6] KVM: arm64: pvtime: steal-time is only supported when configured Andrew Jones
@ 2020-08-04 17:06 ` Andrew Jones
  2020-08-04 17:06 ` [PATCH v2 3/6] KVM: arm64: Drop type input from kvm_put_guest Andrew Jones
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2020-08-04 17:06 UTC (permalink / raw)
  To: kvm, kvmarm; +Cc: maz, pbonzini, steven.price

We should only check current->sched_info.run_delay once when
updating stolen time. Otherwise there's a chance there could
be a change between checks that we miss (preemption disabling
comes after vcpu request checks).

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arch/arm64/kvm/pvtime.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kvm/pvtime.c b/arch/arm64/kvm/pvtime.c
index c3ef4ebd6846..95f9580275b1 100644
--- a/arch/arm64/kvm/pvtime.c
+++ b/arch/arm64/kvm/pvtime.c
@@ -13,6 +13,7 @@
 void kvm_update_stolen_time(struct kvm_vcpu *vcpu)
 {
 	struct kvm *kvm = vcpu->kvm;
+	u64 last_steal = vcpu->arch.steal.last_steal;
 	u64 steal;
 	__le64 steal_le;
 	u64 offset;
@@ -24,8 +25,8 @@ void kvm_update_stolen_time(struct kvm_vcpu *vcpu)
 
 	/* Let's do the local bookkeeping */
 	steal = vcpu->arch.steal.steal;
-	steal += current->sched_info.run_delay - vcpu->arch.steal.last_steal;
-	vcpu->arch.steal.last_steal = current->sched_info.run_delay;
+	vcpu->arch.steal.last_steal = READ_ONCE(current->sched_info.run_delay);
+	steal += vcpu->arch.steal.last_steal - last_steal;
 	vcpu->arch.steal.steal = steal;
 
 	steal_le = cpu_to_le64(steal);
-- 
2.25.4

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 3/6] KVM: arm64: Drop type input from kvm_put_guest
  2020-08-04 17:05 [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Andrew Jones
  2020-08-04 17:05 ` [PATCH v2 1/6] KVM: arm64: pvtime: steal-time is only supported when configured Andrew Jones
  2020-08-04 17:06 ` [PATCH v2 2/6] KVM: arm64: pvtime: Fix potential loss of stolen time Andrew Jones
@ 2020-08-04 17:06 ` Andrew Jones
  2020-08-04 17:06 ` [PATCH v2 4/6] KVM: arm64: pvtime: Fix stolen time accounting across migration Andrew Jones
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2020-08-04 17:06 UTC (permalink / raw)
  To: kvm, kvmarm; +Cc: maz, pbonzini, steven.price

We can use typeof() to avoid the need for the type input.

Suggested-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arch/arm64/kvm/pvtime.c  |  2 +-
 include/linux/kvm_host.h | 11 ++++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch/arm64/kvm/pvtime.c b/arch/arm64/kvm/pvtime.c
index 95f9580275b1..241ded7ee0ad 100644
--- a/arch/arm64/kvm/pvtime.c
+++ b/arch/arm64/kvm/pvtime.c
@@ -32,7 +32,7 @@ void kvm_update_stolen_time(struct kvm_vcpu *vcpu)
 	steal_le = cpu_to_le64(steal);
 	idx = srcu_read_lock(&kvm->srcu);
 	offset = offsetof(struct pvclock_vcpu_stolen_time, stolen_time);
-	kvm_put_guest(kvm, base + offset, steal_le, u64);
+	kvm_put_guest(kvm, base + offset, steal_le);
 	srcu_read_unlock(&kvm->srcu, idx);
 }
 
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index d564855243d8..cf51b06a5edd 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -749,25 +749,26 @@ int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
 int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
 			      gpa_t gpa, unsigned long len);
 
-#define __kvm_put_guest(kvm, gfn, offset, value, type)			\
+#define __kvm_put_guest(kvm, gfn, offset, v)				\
 ({									\
 	unsigned long __addr = gfn_to_hva(kvm, gfn);			\
-	type __user *__uaddr = (type __user *)(__addr + offset);	\
+	typeof(v) __user *__uaddr = (typeof(__uaddr))(__addr + offset);	\
 	int __ret = -EFAULT;						\
 									\
 	if (!kvm_is_error_hva(__addr))					\
-		__ret = put_user(value, __uaddr);			\
+		__ret = put_user(v, __uaddr);				\
 	if (!__ret)							\
 		mark_page_dirty(kvm, gfn);				\
 	__ret;								\
 })
 
-#define kvm_put_guest(kvm, gpa, value, type)				\
+#define kvm_put_guest(kvm, gpa, v)					\
 ({									\
 	gpa_t __gpa = gpa;						\
 	struct kvm *__kvm = kvm;					\
+									\
 	__kvm_put_guest(__kvm, __gpa >> PAGE_SHIFT,			\
-			offset_in_page(__gpa), (value), type);		\
+			offset_in_page(__gpa), v);			\
 })
 
 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
-- 
2.25.4

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 4/6] KVM: arm64: pvtime: Fix stolen time accounting across migration
  2020-08-04 17:05 [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Andrew Jones
                   ` (2 preceding siblings ...)
  2020-08-04 17:06 ` [PATCH v2 3/6] KVM: arm64: Drop type input from kvm_put_guest Andrew Jones
@ 2020-08-04 17:06 ` Andrew Jones
  2020-08-04 17:06 ` [PATCH v2 5/6] KVM: Documentation: Minor fixups Andrew Jones
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2020-08-04 17:06 UTC (permalink / raw)
  To: kvm, kvmarm; +Cc: maz, pbonzini, steven.price

When updating the stolen time we should always read the current
stolen time from the user provided memory, not from a kernel
cache. If we use a cache then we'll end up resetting stolen time
to zero on the first update after migration.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arch/arm64/include/asm/kvm_host.h |  1 -
 arch/arm64/kvm/pvtime.c           | 23 +++++++++--------------
 include/linux/kvm_host.h          | 20 ++++++++++++++++++++
 3 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index e21d4a01372f..1b65dfeb6fed 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -343,7 +343,6 @@ struct kvm_vcpu_arch {
 
 	/* Guest PV state */
 	struct {
-		u64 steal;
 		u64 last_steal;
 		gpa_t base;
 	} steal;
diff --git a/arch/arm64/kvm/pvtime.c b/arch/arm64/kvm/pvtime.c
index 241ded7ee0ad..75234321d896 100644
--- a/arch/arm64/kvm/pvtime.c
+++ b/arch/arm64/kvm/pvtime.c
@@ -13,26 +13,22 @@
 void kvm_update_stolen_time(struct kvm_vcpu *vcpu)
 {
 	struct kvm *kvm = vcpu->kvm;
+	u64 base = vcpu->arch.steal.base;
 	u64 last_steal = vcpu->arch.steal.last_steal;
-	u64 steal;
-	__le64 steal_le;
-	u64 offset;
+	u64 offset = offsetof(struct pvclock_vcpu_stolen_time, stolen_time);
+	u64 steal = 0;
 	int idx;
-	u64 base = vcpu->arch.steal.base;
 
 	if (base == GPA_INVALID)
 		return;
 
-	/* Let's do the local bookkeeping */
-	steal = vcpu->arch.steal.steal;
-	vcpu->arch.steal.last_steal = READ_ONCE(current->sched_info.run_delay);
-	steal += vcpu->arch.steal.last_steal - last_steal;
-	vcpu->arch.steal.steal = steal;
-
-	steal_le = cpu_to_le64(steal);
 	idx = srcu_read_lock(&kvm->srcu);
-	offset = offsetof(struct pvclock_vcpu_stolen_time, stolen_time);
-	kvm_put_guest(kvm, base + offset, steal_le);
+	if (!kvm_get_guest(kvm, base + offset, steal)) {
+		steal = le64_to_cpu(steal);
+		vcpu->arch.steal.last_steal = READ_ONCE(current->sched_info.run_delay);
+		steal += vcpu->arch.steal.last_steal - last_steal;
+		kvm_put_guest(kvm, base + offset, cpu_to_le64(steal));
+	}
 	srcu_read_unlock(&kvm->srcu, idx);
 }
 
@@ -66,7 +62,6 @@ gpa_t kvm_init_stolen_time(struct kvm_vcpu *vcpu)
 	 * Start counting stolen time from the time the guest requests
 	 * the feature enabled.
 	 */
-	vcpu->arch.steal.steal = 0;
 	vcpu->arch.steal.last_steal = current->sched_info.run_delay;
 
 	idx = srcu_read_lock(&kvm->srcu);
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index cf51b06a5edd..3ed6697763f7 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -749,6 +749,26 @@ int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
 int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
 			      gpa_t gpa, unsigned long len);
 
+#define __kvm_get_guest(kvm, gfn, offset, v)				\
+({									\
+	unsigned long __addr = gfn_to_hva(kvm, gfn);			\
+	typeof(v) __user *__uaddr = (typeof(__uaddr))(__addr + offset);	\
+	int __ret = -EFAULT;						\
+									\
+	if (!kvm_is_error_hva(__addr))					\
+		__ret = get_user(v, __uaddr);				\
+	__ret;								\
+})
+
+#define kvm_get_guest(kvm, gpa, v)					\
+({									\
+	gpa_t __gpa = gpa;						\
+	struct kvm *__kvm = kvm;					\
+									\
+	__kvm_get_guest(__kvm, __gpa >> PAGE_SHIFT,			\
+			offset_in_page(__gpa), v);			\
+})
+
 #define __kvm_put_guest(kvm, gfn, offset, v)				\
 ({									\
 	unsigned long __addr = gfn_to_hva(kvm, gfn);			\
-- 
2.25.4

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 5/6] KVM: Documentation: Minor fixups
  2020-08-04 17:05 [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Andrew Jones
                   ` (3 preceding siblings ...)
  2020-08-04 17:06 ` [PATCH v2 4/6] KVM: arm64: pvtime: Fix stolen time accounting across migration Andrew Jones
@ 2020-08-04 17:06 ` Andrew Jones
  2020-08-04 17:06 ` [PATCH v2 6/6] arm64/x86: KVM: Introduce steal-time cap Andrew Jones
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2020-08-04 17:06 UTC (permalink / raw)
  To: kvm, kvmarm; +Cc: maz, pbonzini, steven.price

In preparation for documenting a new capability let's fix up the
formatting of the current ones.

Reviewed-by: Steven Price <steven.price@arm.com>
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 Documentation/virt/kvm/api.rst | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 320788f81a05..3bd96c1a3962 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -6122,7 +6122,7 @@ HvCallSendSyntheticClusterIpi, HvCallSendSyntheticClusterIpiEx.
 8.21 KVM_CAP_HYPERV_DIRECT_TLBFLUSH
 -----------------------------------
 
-:Architecture: x86
+:Architectures: x86
 
 This capability indicates that KVM running on top of Hyper-V hypervisor
 enables Direct TLB flush for its guests meaning that TLB flush
@@ -6135,16 +6135,17 @@ in CPUID and only exposes Hyper-V identification. In this case, guest
 thinks it's running on Hyper-V and only use Hyper-V hypercalls.
 
 8.22 KVM_CAP_S390_VCPU_RESETS
+-----------------------------
 
-Architectures: s390
+:Architectures: s390
 
 This capability indicates that the KVM_S390_NORMAL_RESET and
 KVM_S390_CLEAR_RESET ioctls are available.
 
 8.23 KVM_CAP_S390_PROTECTED
+---------------------------
 
-Architecture: s390
-
+:Architectures: s390
 
 This capability indicates that the Ultravisor has been initialized and
 KVM can therefore start protected VMs.
-- 
2.25.4

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 6/6] arm64/x86: KVM: Introduce steal-time cap
  2020-08-04 17:05 [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Andrew Jones
                   ` (4 preceding siblings ...)
  2020-08-04 17:06 ` [PATCH v2 5/6] KVM: Documentation: Minor fixups Andrew Jones
@ 2020-08-04 17:06 ` Andrew Jones
  2020-08-05 15:37 ` [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Steven Price
  2020-08-19 12:50 ` Andrew Jones
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2020-08-04 17:06 UTC (permalink / raw)
  To: kvm, kvmarm; +Cc: maz, pbonzini, steven.price

arm64 requires a vcpu fd (KVM_HAS_DEVICE_ATTR vcpu ioctl) to probe
support for steal-time. However this is unnecessary, as only a KVM
fd is required, and it complicates userspace (userspace may prefer
delaying vcpu creation until after feature probing). Introduce a cap
that can be checked instead. While x86 can already probe steal-time
support with a kvm fd (KVM_GET_SUPPORTED_CPUID), we add the cap there
too for consistency.

Reviewed-by: Steven Price <steven.price@arm.com>
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 Documentation/virt/kvm/api.rst    | 13 +++++++++++++
 arch/arm64/include/asm/kvm_host.h |  1 +
 arch/arm64/kvm/arm.c              |  3 +++
 arch/arm64/kvm/pvtime.c           |  2 +-
 arch/x86/kvm/x86.c                |  3 +++
 include/uapi/linux/kvm.h          |  1 +
 6 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 3bd96c1a3962..51208c5d6ac2 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -6152,3 +6152,16 @@ KVM can therefore start protected VMs.
 This capability governs the KVM_S390_PV_COMMAND ioctl and the
 KVM_MP_STATE_LOAD MP_STATE. KVM_SET_MP_STATE can fail for protected
 guests when the state change is invalid.
+
+8.24 KVM_CAP_STEAL_TIME
+-----------------------
+
+:Architectures: arm64, x86
+
+This capability indicates that KVM supports steal time accounting.
+When steal time accounting is supported it may be enabled with
+architecture-specific interfaces.  This capability and the architecture-
+specific interfaces must be consistent, i.e. if one says the feature
+is supported, than the other should as well and vice versa.  For arm64
+see Documentation/virt/kvm/devices/vcpu.rst "KVM_ARM_VCPU_PVTIME_CTRL".
+For x86 see Documentation/virt/kvm/msr.rst "MSR_KVM_STEAL_TIME".
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 1b65dfeb6fed..57c44bc56087 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -505,6 +505,7 @@ long kvm_hypercall_pv_features(struct kvm_vcpu *vcpu);
 gpa_t kvm_init_stolen_time(struct kvm_vcpu *vcpu);
 void kvm_update_stolen_time(struct kvm_vcpu *vcpu);
 
+bool kvm_arm_pvtime_supported(void);
 int kvm_arm_pvtime_set_attr(struct kvm_vcpu *vcpu,
 			    struct kvm_device_attr *attr);
 int kvm_arm_pvtime_get_attr(struct kvm_vcpu *vcpu,
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 90cb90561446..0f7f8cd2f341 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -222,6 +222,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 		 */
 		r = 1;
 		break;
+	case KVM_CAP_STEAL_TIME:
+		r = kvm_arm_pvtime_supported();
+		break;
 	default:
 		r = kvm_arch_vm_ioctl_check_extension(kvm, ext);
 		break;
diff --git a/arch/arm64/kvm/pvtime.c b/arch/arm64/kvm/pvtime.c
index 75234321d896..920ac43077ad 100644
--- a/arch/arm64/kvm/pvtime.c
+++ b/arch/arm64/kvm/pvtime.c
@@ -71,7 +71,7 @@ gpa_t kvm_init_stolen_time(struct kvm_vcpu *vcpu)
 	return base;
 }
 
-static bool kvm_arm_pvtime_supported(void)
+bool kvm_arm_pvtime_supported(void)
 {
 	return !!sched_info_on();
 }
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 88c593f83b28..27fc86bb28c4 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3538,6 +3538,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_HYPERV_ENLIGHTENED_VMCS:
 		r = kvm_x86_ops.nested_ops->enable_evmcs != NULL;
 		break;
+	case KVM_CAP_STEAL_TIME:
+		r = sched_info_on();
+		break;
 	default:
 		break;
 	}
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 4fdf30316582..121fb29ac004 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -1031,6 +1031,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_PPC_SECURE_GUEST 181
 #define KVM_CAP_HALT_POLL 182
 #define KVM_CAP_ASYNC_PF_INT 183
+#define KVM_CAP_STEAL_TIME 184
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
-- 
2.25.4

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap
  2020-08-04 17:05 [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Andrew Jones
                   ` (5 preceding siblings ...)
  2020-08-04 17:06 ` [PATCH v2 6/6] arm64/x86: KVM: Introduce steal-time cap Andrew Jones
@ 2020-08-05 15:37 ` Steven Price
  2020-08-19 12:50 ` Andrew Jones
  7 siblings, 0 replies; 10+ messages in thread
From: Steven Price @ 2020-08-05 15:37 UTC (permalink / raw)
  To: Andrew Jones, kvm, kvmarm; +Cc: maz, pbonzini

On 04/08/2020 18:05, Andrew Jones wrote:
> v2:
>    - ARM_SMCCC_HV_PV_TIME_FEATURES now also returns SMCCC_RET_NOT_SUPPORTED
>      when steal time is not supported
>    - Added READ_ONCE() for the run_delay read
>    - Reworked kvm_put/get_guest to not require type as a parameter
>    - Added some more text to the documentation for KVM_CAP_STEAL_TIME
>    - Enough changed that I didn't pick up Steven's r-b's

Feel free to add my r-b's - the changes all look fine to me.

Thanks,

Steve

> 
> The first four patches in the series are fixes that come from testing
> and reviewing pvtime code while writing the QEMU support[*]. The last
> patch is only a convenience for userspace, and I wouldn't be heartbroken
> if it wasn't deemed worth it. The QEMU patches are currently written
> without the cap. However, if the cap is accepted, then I'll change the
> QEMU code to use it.
> 
> Thanks,
> drew
> 
> [*] https://lists.gnu.org/archive/html/qemu-devel/2020-07/msg03856.html
>      (a v2 of this series will also be posted shortly)
> 
> Andrew Jones (6):
>    KVM: arm64: pvtime: steal-time is only supported when configured
>    KVM: arm64: pvtime: Fix potential loss of stolen time
>    KVM: arm64: Drop type input from kvm_put_guest
>    KVM: arm64: pvtime: Fix stolen time accounting across migration
>    KVM: Documentation: Minor fixups
>    arm64/x86: KVM: Introduce steal-time cap
> 
>   Documentation/virt/kvm/api.rst    | 22 ++++++++++++++++++----
>   arch/arm64/include/asm/kvm_host.h |  2 +-
>   arch/arm64/kvm/arm.c              |  3 +++
>   arch/arm64/kvm/pvtime.c           | 29 +++++++++++++----------------
>   arch/x86/kvm/x86.c                |  3 +++
>   include/linux/kvm_host.h          | 31 ++++++++++++++++++++++++++-----
>   include/uapi/linux/kvm.h          |  1 +
>   7 files changed, 65 insertions(+), 26 deletions(-)
> 

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap
  2020-08-04 17:05 [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Andrew Jones
                   ` (6 preceding siblings ...)
  2020-08-05 15:37 ` [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Steven Price
@ 2020-08-19 12:50 ` Andrew Jones
  2020-08-21 13:04   ` Marc Zyngier
  7 siblings, 1 reply; 10+ messages in thread
From: Andrew Jones @ 2020-08-19 12:50 UTC (permalink / raw)
  To: kvm, kvmarm; +Cc: maz, steven.price, pbonzini

On Tue, Aug 04, 2020 at 07:05:58PM +0200, Andrew Jones wrote:
> v2:
>   - ARM_SMCCC_HV_PV_TIME_FEATURES now also returns SMCCC_RET_NOT_SUPPORTED
>     when steal time is not supported
>   - Added READ_ONCE() for the run_delay read
>   - Reworked kvm_put/get_guest to not require type as a parameter
>   - Added some more text to the documentation for KVM_CAP_STEAL_TIME
>   - Enough changed that I didn't pick up Steven's r-b's
> 
> 
> The first four patches in the series are fixes that come from testing
> and reviewing pvtime code while writing the QEMU support[*]. The last
> patch is only a convenience for userspace, and I wouldn't be heartbroken
> if it wasn't deemed worth it. The QEMU patches are currently written
> without the cap. However, if the cap is accepted, then I'll change the
> QEMU code to use it.
> 
> Thanks,
> drew
> 
> [*] https://lists.gnu.org/archive/html/qemu-devel/2020-07/msg03856.html
>     (a v2 of this series will also be posted shortly)
> 
> Andrew Jones (6):
>   KVM: arm64: pvtime: steal-time is only supported when configured
>   KVM: arm64: pvtime: Fix potential loss of stolen time
>   KVM: arm64: Drop type input from kvm_put_guest
>   KVM: arm64: pvtime: Fix stolen time accounting across migration
>   KVM: Documentation: Minor fixups
>   arm64/x86: KVM: Introduce steal-time cap
> 
>  Documentation/virt/kvm/api.rst    | 22 ++++++++++++++++++----
>  arch/arm64/include/asm/kvm_host.h |  2 +-
>  arch/arm64/kvm/arm.c              |  3 +++
>  arch/arm64/kvm/pvtime.c           | 29 +++++++++++++----------------
>  arch/x86/kvm/x86.c                |  3 +++
>  include/linux/kvm_host.h          | 31 ++++++++++++++++++++++++++-----
>  include/uapi/linux/kvm.h          |  1 +
>  7 files changed, 65 insertions(+), 26 deletions(-)
> 
> -- 
> 2.25.4
> 
> _______________________________________________
> kvmarm mailing list
> kvmarm@lists.cs.columbia.edu
> https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
>

Hi Marc,

Gentle ping. I'd like to to switch the QEMU code to using the proposed
KVM cap, if the cap is accepted.

Thanks,
drew 

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap
  2020-08-19 12:50 ` Andrew Jones
@ 2020-08-21 13:04   ` Marc Zyngier
  0 siblings, 0 replies; 10+ messages in thread
From: Marc Zyngier @ 2020-08-21 13:04 UTC (permalink / raw)
  To: Andrew Jones, pbonzini; +Cc: kvmarm, kvm, steven.price

On 2020-08-19 13:50, Andrew Jones wrote:
> On Tue, Aug 04, 2020 at 07:05:58PM +0200, Andrew Jones wrote:
>> v2:
>>   - ARM_SMCCC_HV_PV_TIME_FEATURES now also returns 
>> SMCCC_RET_NOT_SUPPORTED
>>     when steal time is not supported
>>   - Added READ_ONCE() for the run_delay read
>>   - Reworked kvm_put/get_guest to not require type as a parameter
>>   - Added some more text to the documentation for KVM_CAP_STEAL_TIME
>>   - Enough changed that I didn't pick up Steven's r-b's
>> 
>> 
>> The first four patches in the series are fixes that come from testing
>> and reviewing pvtime code while writing the QEMU support[*]. The last
>> patch is only a convenience for userspace, and I wouldn't be 
>> heartbroken
>> if it wasn't deemed worth it. The QEMU patches are currently written
>> without the cap. However, if the cap is accepted, then I'll change the
>> QEMU code to use it.
>> 
>> Thanks,
>> drew
>> 
>> [*] 
>> https://lists.gnu.org/archive/html/qemu-devel/2020-07/msg03856.html
>>     (a v2 of this series will also be posted shortly)
>> 
>> Andrew Jones (6):
>>   KVM: arm64: pvtime: steal-time is only supported when configured
>>   KVM: arm64: pvtime: Fix potential loss of stolen time
>>   KVM: arm64: Drop type input from kvm_put_guest
>>   KVM: arm64: pvtime: Fix stolen time accounting across migration
>>   KVM: Documentation: Minor fixups
>>   arm64/x86: KVM: Introduce steal-time cap
>> 
>>  Documentation/virt/kvm/api.rst    | 22 ++++++++++++++++++----
>>  arch/arm64/include/asm/kvm_host.h |  2 +-
>>  arch/arm64/kvm/arm.c              |  3 +++
>>  arch/arm64/kvm/pvtime.c           | 29 +++++++++++++----------------
>>  arch/x86/kvm/x86.c                |  3 +++
>>  include/linux/kvm_host.h          | 31 
>> ++++++++++++++++++++++++++-----
>>  include/uapi/linux/kvm.h          |  1 +
>>  7 files changed, 65 insertions(+), 26 deletions(-)
>> 
>> --
>> 2.25.4
>> 
>> _______________________________________________
>> kvmarm mailing list
>> kvmarm@lists.cs.columbia.edu
>> https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
>> 
> 
> Hi Marc,
> 
> Gentle ping. I'd like to to switch the QEMU code to using the proposed
> KVM cap, if the cap is accepted.

I'm fine with it. To be honest, this series is mostly fixes, except
for that last patch.

Paolo, are you OK with me sending the whole thing as fixes, including
the UAPI patch? At least we'd have something consistent for 5.9.

Thanks,

         M.
-- 
Jazz is not dead. It just smells funny...
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-08-21 13:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-04 17:05 [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Andrew Jones
2020-08-04 17:05 ` [PATCH v2 1/6] KVM: arm64: pvtime: steal-time is only supported when configured Andrew Jones
2020-08-04 17:06 ` [PATCH v2 2/6] KVM: arm64: pvtime: Fix potential loss of stolen time Andrew Jones
2020-08-04 17:06 ` [PATCH v2 3/6] KVM: arm64: Drop type input from kvm_put_guest Andrew Jones
2020-08-04 17:06 ` [PATCH v2 4/6] KVM: arm64: pvtime: Fix stolen time accounting across migration Andrew Jones
2020-08-04 17:06 ` [PATCH v2 5/6] KVM: Documentation: Minor fixups Andrew Jones
2020-08-04 17:06 ` [PATCH v2 6/6] arm64/x86: KVM: Introduce steal-time cap Andrew Jones
2020-08-05 15:37 ` [PATCH v2 0/6] KVM: arm64: pvtime: Fixes and a new cap Steven Price
2020-08-19 12:50 ` Andrew Jones
2020-08-21 13:04   ` Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).