Skip to content

Commit 43a21a0

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Include VM type when checking VM capabilities in pKVM
Certain features and capabilities are restricted in protected mode. Most of these features are restricted only for protected VMs, but some are restricted for ALL VMs in protected mode. Extend the pKVM capability check to pass the VM (kvm), and use that when determining supported features. Signed-off-by: Fuad Tabba <tabba@google.com> Link: https://patch.msgid.link/20251211104710.151771-6-tabba@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent c273fee commit 43a21a0

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

arch/arm64/include/asm/kvm_pkvm.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ void pkvm_destroy_hyp_vm(struct kvm *kvm);
2323
int pkvm_create_hyp_vcpu(struct kvm_vcpu *vcpu);
2424

2525
/*
26-
* This functions as an allow-list of protected VM capabilities.
27-
* Features not explicitly allowed by this function are denied.
26+
* Check whether the specific capability is allowed in pKVM.
27+
*
28+
* Certain features are allowed only for non-protected VMs in pKVM, which is why
29+
* this takes the VM (kvm) as a parameter.
2830
*/
29-
static inline bool kvm_pvm_ext_allowed(long ext)
31+
static inline bool kvm_pkvm_ext_allowed(struct kvm *kvm, long ext)
3032
{
3133
switch (ext) {
3234
case KVM_CAP_IRQCHIP:
@@ -43,7 +45,7 @@ static inline bool kvm_pvm_ext_allowed(long ext)
4345
case KVM_CAP_ARM_PTRAUTH_GENERIC:
4446
return true;
4547
default:
46-
return false;
48+
return !kvm || !kvm_vm_is_protected(kvm);
4749
}
4850
}
4951

arch/arm64/kvm/arm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
8787
if (cap->flags)
8888
return -EINVAL;
8989

90-
if (kvm_vm_is_protected(kvm) && !kvm_pvm_ext_allowed(cap->cap))
90+
if (is_protected_kvm_enabled() && !kvm_pkvm_ext_allowed(kvm, cap->cap))
9191
return -EINVAL;
9292

9393
switch (cap->cap) {
@@ -303,7 +303,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
303303
{
304304
int r;
305305

306-
if (kvm && kvm_vm_is_protected(kvm) && !kvm_pvm_ext_allowed(ext))
306+
if (is_protected_kvm_enabled() && !kvm_pkvm_ext_allowed(kvm, ext))
307307
return 0;
308308

309309
switch (ext) {

arch/arm64/kvm/hyp/nvhe/pkvm.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,23 +354,23 @@ static void pkvm_init_features_from_host(struct pkvm_hyp_vm *hyp_vm, const struc
354354
return;
355355
}
356356

357-
if (kvm_pvm_ext_allowed(KVM_CAP_ARM_MTE))
357+
if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_MTE))
358358
kvm->arch.flags |= host_arch_flags & BIT(KVM_ARCH_FLAG_MTE_ENABLED);
359359

360360
bitmap_zero(allowed_features, KVM_VCPU_MAX_FEATURES);
361361

362362
set_bit(KVM_ARM_VCPU_PSCI_0_2, allowed_features);
363363

364-
if (kvm_pvm_ext_allowed(KVM_CAP_ARM_PMU_V3))
364+
if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_PMU_V3))
365365
set_bit(KVM_ARM_VCPU_PMU_V3, allowed_features);
366366

367-
if (kvm_pvm_ext_allowed(KVM_CAP_ARM_PTRAUTH_ADDRESS))
367+
if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_PTRAUTH_ADDRESS))
368368
set_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, allowed_features);
369369

370-
if (kvm_pvm_ext_allowed(KVM_CAP_ARM_PTRAUTH_GENERIC))
370+
if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_PTRAUTH_GENERIC))
371371
set_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, allowed_features);
372372

373-
if (kvm_pvm_ext_allowed(KVM_CAP_ARM_SVE)) {
373+
if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_SVE)) {
374374
set_bit(KVM_ARM_VCPU_SVE, allowed_features);
375375
kvm->arch.flags |= host_arch_flags & BIT(KVM_ARCH_FLAG_GUEST_HAS_SVE);
376376
}

0 commit comments

Comments
 (0)