[PATCH 8/8] KVM: PCIPT: VT-d: dont map mmio memory slots

Ben-Ami Yassour
2008-07-16T13:18:02Z

Avoid mapping mmio memory slots.

Signed-off-by: Ben-Ami Yassour <benami@il.ibm.com>
---
arch/x86/kvm/vtd.c | 20 +++++++++++++-------
include/asm-x86/kvm_host.h | 2 ++
virt/kvm/kvm_main.c | 2 +-
3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/vtd.c b/arch/x86/kvm/vtd.c
index 83efb8a..77044fb 100644
--- a/arch/x86/kvm/vtd.c
+++ b/arch/x86/kvm/vtd.c
@@ -40,14 +40,20 @@ int kvm_iommu_map_pages(struct kvm *kvm,

for (i = 0; i < npages; i++) {
pfn = gfn_to_pfn(kvm, gfn);
- rc = intel_iommu_page_mapping(domain,
- gfn << PAGE_SHIFT,
+ if (!is_mmio_pfn(pfn)) {
+ rc = intel_iommu_page_mapping(domain,
+ gfn << PAGE_SHIFT,
pfn << PAGE_SHIFT,
- PAGE_SIZE,
- DMA_PTE_READ |
- DMA_PTE_WRITE);
- if (rc)
- kvm_release_pfn_clean(pfn);
+ PAGE_SIZE,
+ DMA_PTE_READ |
+ DMA_PTE_WRITE);
+ if (rc)
+ kvm_release_pfn_clean(pfn);
+ } else {
+ printk(KERN_DEBUG "kvm_iommu_map_page:"
+ "invalid pfn=%lx\n", pfn);
+ return 0;
+ }

gfn++;
}
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 6185ed7..ee4685c 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -513,6 +513,8 @@ int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
int kvm_pv_mmu_op(struct kvm_vcpu *vcpu, unsigned long bytes,
gpa_t addr, unsigned long *ret);

+int is_mmio_pfn(pfn_t pfn);
+
extern bool tdp_enabled;

enum emulation_result {
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 77d7001..0653ec1 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -77,7 +77,7 @@ static inline int valid_vcpu(int n)
return likely(n >= 0 && n < KVM_MAX_VCPUS);
}

-static inline int is_mmio_pfn(pfn_t pfn)
+inline int is_mmio_pfn(pfn_t pfn)
{
if (pfn_valid(pfn))
return PageReserved(pfn_to_page(pfn));
--
1.5.6