Re: [PATCH] [RESEND] VT-d: Fix iommu map page for mmio pages

2008-10-02 Thread Avi Kivity

Han, Weidong wrote:

From 61028d958dc7c57ee02de32ea89b025dccb9650d Mon Sep 17 00:00:00 2001
From: Weidong Han [EMAIL PROTECTED]
Date: Thu, 25 Sep 2008 23:32:02 +0800
Subject: [PATCH] Map mmio pages into VT-d page table

Assigned device could DMA to mmio pages, so also need to map mmio pages
into VT-d page table.

  


Well, Muli says at least on one machine this allows on guest to kill the 
host.  What are we doing with this?


If it's a hardware bug which is planned to be fixed (or is already 
fixed), great, but I need to know.


--
error compiling committee.c: too many arguments to function

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] [RESEND] VT-d: Fix iommu map page for mmio pages

2008-10-02 Thread Muli Ben-Yehuda
On Thu, Oct 02, 2008 at 02:56:55PM +0300, Avi Kivity wrote:
 Han, Weidong wrote:
 From 61028d958dc7c57ee02de32ea89b025dccb9650d Mon Sep 17 00:00:00 2001
 From: Weidong Han [EMAIL PROTECTED]
 Date: Thu, 25 Sep 2008 23:32:02 +0800
 Subject: [PATCH] Map mmio pages into VT-d page table

 Assigned device could DMA to mmio pages, so also need to map mmio pages
 into VT-d page table.

   

 Well, Muli says at least on one machine this allows on guest to kill
 the host.  What are we doing with this?

 If it's a hardware bug which is planned to be fixed (or is already
 fixed), great, but I need to know.

Unfortunately I don't have access to the machine any more. We did
spend some time perusing the PCIe spec on this point, and although it
is pretty vague, the bottom line appears to be that peer-to-peer
traffic (device-to-device traffic) is allowed. I'm fine with applying
the patch.

Cheers,
Muli
-- 
The First Workshop on I/O Virtualization (WIOV '08)
Dec 2008, San Diego, CA, http://www.usenix.org/wiov08/
  xxx
SYSTOR 2009---The Israeli Experimental Systems Conference
http://www.haifa.il.ibm.com/conferences/systor2009/
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [RESEND] VT-d: Fix iommu map page for mmio pages

2008-09-25 Thread Han, Weidong
From 61028d958dc7c57ee02de32ea89b025dccb9650d Mon Sep 17 00:00:00 2001
From: Weidong Han [EMAIL PROTECTED]
Date: Thu, 25 Sep 2008 23:32:02 +0800
Subject: [PATCH] Map mmio pages into VT-d page table

Assigned device could DMA to mmio pages, so also need to map mmio pages
into VT-d page table.

Signed-off-by: Weidong Han [EMAIL PROTECTED]
---
 arch/x86/kvm/vtd.c |   29 +++--
 include/asm-x86/kvm_host.h |2 --
 virt/kvm/kvm_main.c|2 +-
 3 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/arch/x86/kvm/vtd.c b/arch/x86/kvm/vtd.c
index 667bf3f..a770874 100644
--- a/arch/x86/kvm/vtd.c
+++ b/arch/x86/kvm/vtd.c
@@ -36,37 +36,30 @@ int kvm_iommu_map_pages(struct kvm *kvm,
 {
gfn_t gfn = base_gfn;
pfn_t pfn;
-   int i, r;
+   int i, r = 0;
struct dmar_domain *domain = kvm-arch.intel_iommu_domain;
 
/* check if iommu exists and in use */
if (!domain)
return 0;
 
-   r = -EINVAL;
for (i = 0; i  npages; i++) {
/* check if already mapped */
pfn = (pfn_t)intel_iommu_iova_to_pfn(domain,
 gfn_to_gpa(gfn));
-   if (pfn  !is_mmio_pfn(pfn))
+   if (pfn)
continue;
 
pfn = gfn_to_pfn(kvm, gfn);
-   if (!is_mmio_pfn(pfn)) {
-   r = intel_iommu_page_mapping(domain,
-gfn_to_gpa(gfn),
-pfn_to_hpa(pfn),
-PAGE_SIZE,
-DMA_PTE_READ |
-DMA_PTE_WRITE);
-   if (r) {
-   printk(KERN_DEBUG kvm_iommu_map_pages:
-  iommu failed to map pfn=%lx\n,
pfn);
-   goto unmap_pages;
-   }
-   } else {
-   printk(KERN_DEBUG kvm_iommu_map_page:
-  invalid pfn=%lx\n, pfn);
+   r = intel_iommu_page_mapping(domain,
+gfn_to_gpa(gfn),
+pfn_to_hpa(pfn),
+PAGE_SIZE,
+DMA_PTE_READ |
+DMA_PTE_WRITE);
+   if (r) {
+   printk(KERN_ERR kvm_iommu_map_pages:
+  iommu failed to map pfn=%lx\n, pfn);
goto unmap_pages;
}
gfn++;
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index d1175b8..357dd20 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -495,8 +495,6 @@ 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 6cf0427..98cd916 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -76,7 +76,7 @@ static inline int valid_vcpu(int n)
return likely(n = 0  n  KVM_MAX_VCPUS);
 }
 
-inline int is_mmio_pfn(pfn_t pfn)
+static inline int is_mmio_pfn(pfn_t pfn)
 {
if (pfn_valid(pfn))
return PageReserved(pfn_to_page(pfn));
-- 
1.5.1


0001-Map-mmio-pages-into-VT-d-page-table.patch
Description: 0001-Map-mmio-pages-into-VT-d-page-table.patch