[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC PATCH 2/7] iommu: add iommu_lookup_page to lookup guest gfn for a particular IOMMU mapping



If IOMMU driver does not implement lookup_page function then it returns -ENOMEM.

Returns 0 on success and any other value on failure.

Signed-off-by: Malcolm Crossley <malcolm.crossley@xxxxxxxxxx>
--
Cc: jbeulich@xxxxxxxx
Cc: xen-devel@xxxxxxxxxxxxx
---
 xen/drivers/passthrough/iommu.c | 21 +++++++++++++++++++++
 xen/include/xen/iommu.h         |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index 0b2abf4..06f21ee 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -257,6 +257,27 @@ int iommu_unmap_page(struct domain *d, unsigned long gfn)
     return hd->platform_ops->unmap_page(d, gfn);
 }
 
+int iommu_lookup_page(struct domain *d, unsigned long bfn, unsigned long *gfn)
+{
+    struct hvm_iommu *hd = domain_hvm_iommu(d);
+
+    /* 
+     * BFN maps 1:1 to GFN when iommu passthrough is enabled or 
+     * when IOMMU shared page tables is in use
+     */
+    if ( iommu_use_hap_pt(d) || (iommu_passthrough && is_hardware_domain(d)) )
+    {
+        *gfn = bfn;
+        return 0;
+    }
+
+    if ( !iommu_enabled || !hd->platform_ops ||
+            !hd->platform_ops->lookup_page )
+        return -ENOMEM;
+
+    return hd->platform_ops->lookup_page(d, bfn, gfn);
+}
+
 static void iommu_free_pagetables(unsigned long unused)
 {
     do {
diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
index 8217cb7..49ca087 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -77,6 +77,7 @@ void iommu_teardown(struct domain *d);
 int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
                    unsigned int flags);
 int iommu_unmap_page(struct domain *d, unsigned long gfn);
+int iommu_lookup_page(struct domain *d, unsigned long bfn, unsigned long *gfn);
 
 enum iommu_feature
 {
@@ -151,6 +152,7 @@ struct iommu_ops {
     int (*map_page)(struct domain *d, unsigned long gfn, unsigned long mfn,
                     unsigned int flags);
     int (*unmap_page)(struct domain *d, unsigned long gfn);
+    int (*lookup_page)(struct domain *d, unsigned long bfn, unsigned long 
*gfn);
     void (*free_page_table)(struct page_info *);
 #ifdef CONFIG_X86
     void (*update_ire_from_apic)(unsigned int apic, unsigned int reg, unsigned 
int value);
-- 
1.7.12.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.