Skip to content

Commit fd717f1

Browse files
committed
KVM: x86: apply guest MTRR virtualization on host reserved pages
Currently guest MTRR is avoided if kvm_is_reserved_pfn returns true. However, the guest could prefer a different page type than UC for such pages. A good example is that pass-throughed VGA frame buffer is not always UC as host expected. This patch enables full use of virtual guest MTRRs. Suggested-by: Xiao Guangrong <guangrong.xiao@linux.intel.com> Tested-by: Joerg Roedel <jroedel@suse.de> (on AMD) Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent e098223 commit fd717f1

2 files changed

Lines changed: 5 additions & 13 deletions

File tree

arch/x86/kvm/svm.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,14 +1166,11 @@ static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
11661166
u8 mtrr;
11671167

11681168
/*
1169-
* 1. MMIO: always map as UC
1169+
* 1. MMIO: trust guest MTRR, so same as item 3.
11701170
* 2. No passthrough: always map as WB, and force guest PAT to WB as well
11711171
* 3. Passthrough: can't guarantee the result, try to trust guest.
11721172
*/
1173-
if (is_mmio)
1174-
return _PAGE_NOCACHE;
1175-
1176-
if (!kvm_arch_has_assigned_device(vcpu->kvm))
1173+
if (!is_mmio && !kvm_arch_has_assigned_device(vcpu->kvm))
11771174
return 0;
11781175

11791176
mtrr = kvm_mtrr_get_guest_memory_type(vcpu, gfn);

arch/x86/kvm/vmx.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8632,22 +8632,17 @@ static u64 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
86328632
u64 ipat = 0;
86338633

86348634
/* For VT-d and EPT combination
8635-
* 1. MMIO: always map as UC
8635+
* 1. MMIO: guest may want to apply WC, trust it.
86368636
* 2. EPT with VT-d:
86378637
* a. VT-d without snooping control feature: can't guarantee the
8638-
* result, try to trust guest.
8638+
* result, try to trust guest. So the same as item 1.
86398639
* b. VT-d with snooping control feature: snooping control feature of
86408640
* VT-d engine can guarantee the cache correctness. Just set it
86418641
* to WB to keep consistent with host. So the same as item 3.
86428642
* 3. EPT without VT-d: always map as WB and set IPAT=1 to keep
86438643
* consistent with host MTRR
86448644
*/
8645-
if (is_mmio) {
8646-
cache = MTRR_TYPE_UNCACHABLE;
8647-
goto exit;
8648-
}
8649-
8650-
if (!kvm_arch_has_noncoherent_dma(vcpu->kvm)) {
8645+
if (!is_mmio && !kvm_arch_has_noncoherent_dma(vcpu->kvm)) {
86518646
ipat = VMX_EPT_IPAT_BIT;
86528647
cache = MTRR_TYPE_WRBACK;
86538648
goto exit;

0 commit comments

Comments
 (0)