History

Merge tag 'kvm-x86-fixes-6.13-rcN' of https://github.com/kvm-x86/linux into HEAD

KVM x86 fixes for 6.13: - 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.

Paolo Bonzini committed 1 year ago

Commit 10b2c8a2 parents a066bad 386d69f7 files · +30 −22Browse files

Unified · Split

7 files
  1. arch/x86/include/asm/cpufeatures.h +1 −0
  2. arch/x86/kvm/mmu/mmu.c +0 −12
  3. arch/x86/kvm/mmu/spte.h +17 −0
  4. arch/x86/kvm/mmu/tdp_mmu.c +5 −0
  5. arch/x86/kvm/svm/avic.c +6 −0
  6. arch/x86/kvm/svm/svm.c +0 −9
  7. arch/x86/kvm/x86.c +1 −1
arch/x86/include/asm/cpufeatures.h+1−0
@@ -452,6 +452,7 @@ · 451 unmodified lines
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+0−12
@@ -3364,18 +3364,6 @@ static bool fast_pf_fix_direct_spte(struct kvm_vcpu *vcpu, · 3363 unmodified lines
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+17−0
@@ -461,6 +461,23 @@ static inline bool is_mmu_writable_spte(u64 spte) · 460 unmodified lines
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+5−0
@@ -985,6 +985,11 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu, · 984 unmodified lines
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+6−0
@@ -1199,6 +1199,12 @@ bool avic_hardware_setup(void) · 1198 unmodified lines
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+0−9
@@ -3201,15 +3201,6 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) · 3200 unmodified lines
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/x86.c+1−1
@@ -9976,7 +9976,7 @@ static int complete_hypercall_exit(struct kvm_vcpu *vcpu) · 9975 unmodified lines
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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t