mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-31 14:13:39 +00:00
KVM: x86: block KVM_CAP_SYNC_REGS if guest state is protected
KVM_CAP_SYNC_REGS does not make sense for VMs with protected guest state,
since the register values cannot actually be written. Return 0
when using the VM-level KVM_CHECK_EXTENSION ioctl, and accordingly
return -EINVAL from KVM_RUN if the valid/dirty fields are nonzero.
However, on exit from KVM_RUN userspace could have placed a nonzero
value into kvm_run->kvm_valid_regs, so check guest_state_protected
again and skip store_regs() in that case.
Cc: stable@vger.kernel.org
Fixes: 517987e3fb
("KVM: x86: add fields to struct kvm_arch for CoCo features")
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-ID: <20250306202923.646075-1-pbonzini@redhat.com>
Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
adafea1106
commit
74c1807f6c
@ -4580,6 +4580,11 @@ static bool kvm_is_vm_type_supported(unsigned long type)
|
|||||||
return type < 32 && (kvm_caps.supported_vm_types & BIT(type));
|
return type < 32 && (kvm_caps.supported_vm_types & BIT(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline u32 kvm_sync_valid_fields(struct kvm *kvm)
|
||||||
|
{
|
||||||
|
return kvm && kvm->arch.has_protected_state ? 0 : KVM_SYNC_X86_VALID_FIELDS;
|
||||||
|
}
|
||||||
|
|
||||||
int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
|
int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
|
||||||
{
|
{
|
||||||
int r = 0;
|
int r = 0;
|
||||||
@ -4688,7 +4693,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case KVM_CAP_SYNC_REGS:
|
case KVM_CAP_SYNC_REGS:
|
||||||
r = KVM_SYNC_X86_VALID_FIELDS;
|
r = kvm_sync_valid_fields(kvm);
|
||||||
break;
|
break;
|
||||||
case KVM_CAP_ADJUST_CLOCK:
|
case KVM_CAP_ADJUST_CLOCK:
|
||||||
r = KVM_CLOCK_VALID_FLAGS;
|
r = KVM_CLOCK_VALID_FLAGS;
|
||||||
@ -11481,6 +11486,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
|
|||||||
{
|
{
|
||||||
struct kvm_queued_exception *ex = &vcpu->arch.exception;
|
struct kvm_queued_exception *ex = &vcpu->arch.exception;
|
||||||
struct kvm_run *kvm_run = vcpu->run;
|
struct kvm_run *kvm_run = vcpu->run;
|
||||||
|
u32 sync_valid_fields;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = kvm_mmu_post_init_vm(vcpu->kvm);
|
r = kvm_mmu_post_init_vm(vcpu->kvm);
|
||||||
@ -11526,8 +11532,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((kvm_run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) ||
|
sync_valid_fields = kvm_sync_valid_fields(vcpu->kvm);
|
||||||
(kvm_run->kvm_dirty_regs & ~KVM_SYNC_X86_VALID_FIELDS)) {
|
if ((kvm_run->kvm_valid_regs & ~sync_valid_fields) ||
|
||||||
|
(kvm_run->kvm_dirty_regs & ~sync_valid_fields)) {
|
||||||
r = -EINVAL;
|
r = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -11585,7 +11592,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
kvm_put_guest_fpu(vcpu);
|
kvm_put_guest_fpu(vcpu);
|
||||||
if (kvm_run->kvm_valid_regs)
|
if (kvm_run->kvm_valid_regs && likely(!vcpu->arch.guest_state_protected))
|
||||||
store_regs(vcpu);
|
store_regs(vcpu);
|
||||||
post_kvm_run_save(vcpu);
|
post_kvm_run_save(vcpu);
|
||||||
kvm_vcpu_srcu_read_unlock(vcpu);
|
kvm_vcpu_srcu_read_unlock(vcpu);
|
||||||
|
Loading…
Reference in New Issue
Block a user