Skip to content

Commit

Permalink
KVM: x86: apply guest MTRR virtualization on host reserved pages
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bonzini committed Jul 10, 2015
1 parent e098223 commit fd717f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
7 changes: 2 additions & 5 deletions arch/x86/kvm/svm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,14 +1166,11 @@ static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
u8 mtrr;

/*
* 1. MMIO: always map as UC
* 1. MMIO: trust guest MTRR, so same as item 3.
* 2. No passthrough: always map as WB, and force guest PAT to WB as well
* 3. Passthrough: can't guarantee the result, try to trust guest.
*/
if (is_mmio)
return _PAGE_NOCACHE;

if (!kvm_arch_has_assigned_device(vcpu->kvm))
if (!is_mmio && !kvm_arch_has_assigned_device(vcpu->kvm))
return 0;

mtrr = kvm_mtrr_get_guest_memory_type(vcpu, gfn);
Expand Down
11 changes: 3 additions & 8 deletions arch/x86/kvm/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -8632,22 +8632,17 @@ static u64 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
u64 ipat = 0;

/* For VT-d and EPT combination
* 1. MMIO: always map as UC
* 1. MMIO: guest may want to apply WC, trust it.
* 2. EPT with VT-d:
* a. VT-d without snooping control feature: can't guarantee the
* result, try to trust guest.
* result, try to trust guest. So the same as item 1.
* b. VT-d with snooping control feature: snooping control feature of
* VT-d engine can guarantee the cache correctness. Just set it
* to WB to keep consistent with host. So the same as item 3.
* 3. EPT without VT-d: always map as WB and set IPAT=1 to keep
* consistent with host MTRR
*/
if (is_mmio) {
cache = MTRR_TYPE_UNCACHABLE;
goto exit;
}

if (!kvm_arch_has_noncoherent_dma(vcpu->kvm)) {
if (!is_mmio && !kvm_arch_has_noncoherent_dma(vcpu->kvm)) {
ipat = VMX_EPT_IPAT_BIT;
cache = MTRR_TYPE_WRBACK;
goto exit;
Expand Down

0 comments on commit fd717f1

Please sign in to comment.