Skip to content

Commit b1fdbe7

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM x86 fixes from Paolo Bonzini: - Disable AVIC on SNP-enabled systems that don't allow writes to the virtual APIC page, as such hosts will hit unexpected RMP #PFs in the host when running VMs of any flavor. - Fix a WARN in the hypercall completion path due to KVM trying to determine if a guest with protected register state is in 64-bit mode (KVM's ABI is to assume such guests only make hypercalls in 64-bit mode). - Allow the guest to write to supported bits in MSR_AMD64_DE_CFG to fix a regression with Windows guests, and because KVM's read-only behavior appears to be entirely made up. - Treat TDP MMU faults as spurious if the faulting access is allowed given the existing SPTE. This fixes a benign WARN (other than the WARN itself) due to unexpectedly replacing a writable SPTE with a read-only SPTE. - Emit a warning when KVM is configured with ignore_msrs=1 and also to hide the MSRs that the guest is looking for from the kernel logs. ignore_msrs can trick guests into assuming that certain processor features are present, and this in turn leads to bogus bug reports. * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: x86: let it be known that ignore_msrs is a bad idea KVM: VMX: don't include '<linux/find.h>' directly KVM: x86/mmu: Treat TDP MMU faults as spurious if access is already allowed KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits KVM: x86: Play nice with protected guests in complete_hypercall_exit() KVM: SVM: Disable AVIC on SNP-enabled system without HvInUseWrAllowed feature
2 parents bcde95c + 8afa5b1 commit b1fdbe7

File tree

8 files changed

+38
-23
lines changed

8 files changed

+38
-23
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@
452452
#define X86_FEATURE_SME_COHERENT (19*32+10) /* AMD hardware-enforced cache coherency */
453453
#define X86_FEATURE_DEBUG_SWAP (19*32+14) /* "debug_swap" AMD SEV-ES full debug state swap support */
454454
#define X86_FEATURE_SVSM (19*32+28) /* "svsm" SVSM present */
455+
#define X86_FEATURE_HV_INUSE_WR_ALLOWED (19*32+30) /* Allow Write to in-use hypervisor-owned pages */
455456

456457
/* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */
457458
#define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0) /* No Nested Data Breakpoints */

arch/x86/kvm/mmu/mmu.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,18 +3364,6 @@ static bool fast_pf_fix_direct_spte(struct kvm_vcpu *vcpu,
33643364
return true;
33653365
}
33663366

3367-
static bool is_access_allowed(struct kvm_page_fault *fault, u64 spte)
3368-
{
3369-
if (fault->exec)
3370-
return is_executable_pte(spte);
3371-
3372-
if (fault->write)
3373-
return is_writable_pte(spte);
3374-
3375-
/* Fault was on Read access */
3376-
return spte & PT_PRESENT_MASK;
3377-
}
3378-
33793367
/*
33803368
* Returns the last level spte pointer of the shadow page walk for the given
33813369
* gpa, and sets *spte to the spte value. This spte may be non-preset. If no

arch/x86/kvm/mmu/spte.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,23 @@ static inline bool is_mmu_writable_spte(u64 spte)
461461
return spte & shadow_mmu_writable_mask;
462462
}
463463

464+
/*
465+
* Returns true if the access indicated by @fault is allowed by the existing
466+
* SPTE protections. Note, the caller is responsible for checking that the
467+
* SPTE is a shadow-present, leaf SPTE (either before or after).
468+
*/
469+
static inline bool is_access_allowed(struct kvm_page_fault *fault, u64 spte)
470+
{
471+
if (fault->exec)
472+
return is_executable_pte(spte);
473+
474+
if (fault->write)
475+
return is_writable_pte(spte);
476+
477+
/* Fault was on Read access */
478+
return spte & PT_PRESENT_MASK;
479+
}
480+
464481
/*
465482
* If the MMU-writable flag is cleared, i.e. the SPTE is write-protected for
466483
* write-tracking, remote TLBs must be flushed, even if the SPTE was read-only,

arch/x86/kvm/mmu/tdp_mmu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,11 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu,
985985
if (fault->prefetch && is_shadow_present_pte(iter->old_spte))
986986
return RET_PF_SPURIOUS;
987987

988+
if (is_shadow_present_pte(iter->old_spte) &&
989+
is_access_allowed(fault, iter->old_spte) &&
990+
is_last_spte(iter->old_spte, iter->level))
991+
return RET_PF_SPURIOUS;
992+
988993
if (unlikely(!fault->slot))
989994
new_spte = make_mmio_spte(vcpu, iter->gfn, ACC_ALL);
990995
else

arch/x86/kvm/svm/avic.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,12 @@ bool avic_hardware_setup(void)
11991199
return false;
12001200
}
12011201

1202+
if (cc_platform_has(CC_ATTR_HOST_SEV_SNP) &&
1203+
!boot_cpu_has(X86_FEATURE_HV_INUSE_WR_ALLOWED)) {
1204+
pr_warn("AVIC disabled: missing HvInUseWrAllowed on SNP-enabled system\n");
1205+
return false;
1206+
}
1207+
12021208
if (boot_cpu_has(X86_FEATURE_AVIC)) {
12031209
pr_info("AVIC enabled\n");
12041210
} else if (force_avic) {

arch/x86/kvm/svm/svm.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,15 +3201,6 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
32013201
if (data & ~supported_de_cfg)
32023202
return 1;
32033203

3204-
/*
3205-
* Don't let the guest change the host-programmed value. The
3206-
* MSR is very model specific, i.e. contains multiple bits that
3207-
* are completely unknown to KVM, and the one bit known to KVM
3208-
* is simply a reflection of hardware capabilities.
3209-
*/
3210-
if (!msr->host_initiated && data != svm->msr_decfg)
3211-
return 1;
3212-
32133204
svm->msr_decfg = data;
32143205
break;
32153206
}

arch/x86/kvm/vmx/posted_intr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef __KVM_X86_VMX_POSTED_INTR_H
33
#define __KVM_X86_VMX_POSTED_INTR_H
44

5-
#include <linux/find.h>
5+
#include <linux/bitmap.h>
66
#include <asm/posted_intr.h>
77

88
void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu);

arch/x86/kvm/x86.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9976,7 +9976,7 @@ static int complete_hypercall_exit(struct kvm_vcpu *vcpu)
99769976
{
99779977
u64 ret = vcpu->run->hypercall.ret;
99789978

9979-
if (!is_64_bit_mode(vcpu))
9979+
if (!is_64_bit_hypercall(vcpu))
99809980
ret = (u32)ret;
99819981
kvm_rax_write(vcpu, ret);
99829982
++vcpu->stat.hypercalls;
@@ -12724,6 +12724,13 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
1272412724
kvm_hv_init_vm(kvm);
1272512725
kvm_xen_init_vm(kvm);
1272612726

12727+
if (ignore_msrs && !report_ignored_msrs) {
12728+
pr_warn_once("Running KVM with ignore_msrs=1 and report_ignored_msrs=0 is not a\n"
12729+
"a supported configuration. Lying to the guest about the existence of MSRs\n"
12730+
"may cause the guest operating system to hang or produce errors. If a guest\n"
12731+
"does not run without ignore_msrs=1, please report it to [email protected].\n");
12732+
}
12733+
1272712734
return 0;
1272812735

1272912736
out_uninit_mmu:

0 commit comments

Comments
 (0)