Skip to content

Commit 004a012

Browse files
Andrew JonesMarc Zyngier
authored andcommitted
arm64/x86: KVM: Introduce steal-time cap
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. Signed-off-by: Andrew Jones <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Steven Price <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 739c7af commit 004a012

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6160,3 +6160,16 @@ KVM can therefore start protected VMs.
61606160
This capability governs the KVM_S390_PV_COMMAND ioctl and the
61616161
KVM_MP_STATE_LOAD MP_STATE. KVM_SET_MP_STATE can fail for protected
61626162
guests when the state change is invalid.
6163+
6164+
8.24 KVM_CAP_STEAL_TIME
6165+
-----------------------
6166+
6167+
:Architectures: arm64, x86
6168+
6169+
This capability indicates that KVM supports steal time accounting.
6170+
When steal time accounting is supported it may be enabled with
6171+
architecture-specific interfaces. This capability and the architecture-
6172+
specific interfaces must be consistent, i.e. if one says the feature
6173+
is supported, than the other should as well and vice versa. For arm64
6174+
see Documentation/virt/kvm/devices/vcpu.rst "KVM_ARM_VCPU_PVTIME_CTRL".
6175+
For x86 see Documentation/virt/kvm/msr.rst "MSR_KVM_STEAL_TIME".

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ long kvm_hypercall_pv_features(struct kvm_vcpu *vcpu);
543543
gpa_t kvm_init_stolen_time(struct kvm_vcpu *vcpu);
544544
void kvm_update_stolen_time(struct kvm_vcpu *vcpu);
545545

546+
bool kvm_arm_pvtime_supported(void);
546547
int kvm_arm_pvtime_set_attr(struct kvm_vcpu *vcpu,
547548
struct kvm_device_attr *attr);
548549
int kvm_arm_pvtime_get_attr(struct kvm_vcpu *vcpu,

arch/arm64/kvm/arm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
206206
*/
207207
r = 1;
208208
break;
209+
case KVM_CAP_STEAL_TIME:
210+
r = kvm_arm_pvtime_supported();
211+
break;
209212
default:
210213
r = kvm_arch_vm_ioctl_check_extension(kvm, ext);
211214
break;

arch/arm64/kvm/pvtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ gpa_t kvm_init_stolen_time(struct kvm_vcpu *vcpu)
7171
return base;
7272
}
7373

74-
static bool kvm_arm_pvtime_supported(void)
74+
bool kvm_arm_pvtime_supported(void)
7575
{
7676
return !!sched_info_on();
7777
}

arch/x86/kvm/x86.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,6 +3581,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
35813581
case KVM_CAP_SMALLER_MAXPHYADDR:
35823582
r = (int) allow_smaller_maxphyaddr;
35833583
break;
3584+
case KVM_CAP_STEAL_TIME:
3585+
r = sched_info_on();
3586+
break;
35843587
default:
35853588
break;
35863589
}

include/uapi/linux/kvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ struct kvm_ppc_resize_hpt {
10351035
#define KVM_CAP_LAST_CPU 184
10361036
#define KVM_CAP_SMALLER_MAXPHYADDR 185
10371037
#define KVM_CAP_S390_DIAG318 186
1038+
#define KVM_CAP_STEAL_TIME 187
10381039

10391040
#ifdef KVM_CAP_IRQ_ROUTING
10401041

0 commit comments

Comments
 (0)