Skip to contentSkip to conversation

Check VT-d Device-TLB flush error

PATCH Superseded Quan Xu 5 participants 78 messages Apr 18, 2016 – Apr 29, 2016

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Quan Xu

author
#0 lore raw

v2 cover Check VT-d Device-TLB flush error

This patch set is a prereq patch set for Patch:'VT-d Device-TLB flush issue'.

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to the call trees.

This patch set is also based on the discussion of 'abstract model of IOMMU unmaping/mapping failures'

In this version, I try that splitting things is to go function by function, top level ones first, and leaf ones last, one function per patch (maybe pairs of functions, as in the map/unmap case).

Quan Xu (11):
vt-d: fix the IOMMU flush issue
IOMMU: handle IOMMU mapping and unmapping failures IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping
grant_table: avoid unnecessary work during grant table unmapping
vt-d: propagate IOMMU Device-TLB flush error up to IOMMU unmapping.
vt-d: propagate IOMMU Device-TLB flush error up to IOMMU mapping. IOMMU/MMU: propagate IOMMU Device-TLB flush error up to
iommu_iotlb_flush{,_all} (top level ones).
IOMMU: propagate IOMMU Device-TLB flush error up to
iommu_iotlb_flush{,_all} (leaf ones).
IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending
vt-d: propagate IOMMU Device-TLB flush error up to vt-d hardware
initialization
vt-d: propagate error up to ME phantom function mapping and unmapping

 xen/arch/arm/p2m.c                            |   5 +-
 xen/arch/x86/acpi/power.c                     |  14 ++-
 xen/arch/x86/mm.c                             |  13 ++-
 xen/arch/x86/mm/p2m-ept.c                     |  25 ++++-
 xen/arch/x86/mm/p2m-pt.c                      |  22 +++-
 xen/arch/x86/mm/p2m.c                         |  11 +-
 xen/common/grant_table.c                      |  10 +-
 xen/common/memory.c                           |   5 +-
 xen/drivers/passthrough/amd/iommu_init.c      |   9 +-
 xen/drivers/passthrough/amd/pci_amd_iommu.c   |   2 +-
 xen/drivers/passthrough/arm/smmu.c            |  10 +-
 xen/drivers/passthrough/iommu.c               |  49 +++++++--
 xen/drivers/passthrough/vtd/extern.h          |   2 +-
 xen/drivers/passthrough/vtd/iommu.c           | 140 +++++++++++++++++---------
 xen/drivers/passthrough/vtd/quirks.c          |  26 +++--
 xen/drivers/passthrough/x86/iommu.c           |   5 +-
 xen/include/asm-x86/hvm/svm/amd-iommu-proto.h |   2 +-
 xen/include/asm-x86/iommu.h                   |   2 +-
 xen/include/xen/iommu.h                       |  12 +--
 19 files changed, 256 insertions(+), 108 deletions(-)
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#1 lore raw

PATCH v2 1/11 vt-d: fix the IOMMU flush issue

The propagation value from IOMMU flush interfaces may be positive, which indicates callers need to flush cache, not one of faliures.

when the propagation value is positive, this patch fixes this flush issue as follows:
- call iommu_flush_write_buffer() to flush cache.
- return zero.

CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
---
 xen/drivers/passthrough/vtd/iommu.c | 94 ++++++++++++++++++++++++-------------
 xen/include/asm-x86/iommu.h         |  2 +-
 2 files changed, 63 insertions(+), 33 deletions(-)
xen/drivers/passthrough/vtd/iommu.c +62 -32
index 5ad25dc..50d98ac 100644
@@ -558,14 +558,16 @@ static void iommu_flush_all(void)
     }
 }
 
-static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
-        int dma_old_pte_present, unsigned int page_count)
+static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
+                             int dma_old_pte_present,
+                             unsigned int page_count)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     int flush_dev_iotlb;
     int iommu_domid;
+    int rc = 0;
 
     /*
      * No need pcideves_lock here because we have flush
@@ -584,29 +586,34 @@ static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
             continue;
 
         if ( page_count != 1 || gfn == INVALID_GFN )
-        {
-            if ( iommu_flush_iotlb_dsi(iommu, iommu_domid,
-                        0, flush_dev_iotlb) )
-                iommu_flush_write_buffer(iommu);
-        }
+            rc = iommu_flush_iotlb_dsi(iommu, iommu_domid,
+                                       0, flush_dev_iotlb);
         else
+            rc = iommu_flush_iotlb_psi(iommu, iommu_domid,
+                                       (paddr_t)gfn << PAGE_SHIFT_4K,
+                                       PAGE_ORDER_4K,
+                                       !dma_old_pte_present,
+                                       flush_dev_iotlb);
+
+        if ( rc > 0 )
         {
-            if ( iommu_flush_iotlb_psi(iommu, iommu_domid,
-                        (paddr_t)gfn << PAGE_SHIFT_4K, PAGE_ORDER_4K,
-                        !dma_old_pte_present, flush_dev_iotlb) )
-                iommu_flush_write_buffer(iommu);
-        }
+            iommu_flush_write_buffer(iommu);
+            rc = 0;
+        } else if ( rc < 0 )
+            break;
     }
+
+    return rc;
 }
 
 static void intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
 {
-    __intel_iommu_iotlb_flush(d, gfn, 1, page_count);
+    iommu_flush_iotlb(d, gfn, 1, page_count);
 }
 
 static void intel_iommu_iotlb_flush_all(struct domain *d)
 {
-    __intel_iommu_iotlb_flush(d, INVALID_GFN, 0, 0);
+    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }
 
 /* clear one page's page table */
@@ -640,7 +647,7 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr)
     iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
 
     if ( !this_cpu(iommu_dont_flush_iotlb) )
-        __intel_iommu_iotlb_flush(domain, addr >> PAGE_SHIFT_4K, 1, 1);
+        iommu_flush_iotlb(domain, addr >> PAGE_SHIFT_4K, 1, 1);
 
     unmap_vtd_domain_page(page);
 }
@@ -1281,6 +1288,7 @@ int domain_context_mapping_one(
     u64 maddr, pgd_maddr;
     u16 seg = iommu->intel->drhd->segment;
     int agaw;
+    int rc;
 
     ASSERT(pcidevs_locked());
     spin_lock(&iommu->lock);
@@ -1394,13 +1402,19 @@ int domain_context_mapping_one(
     spin_unlock(&iommu->lock);
 
     /* Context entry was previously non-present (with domid 0). */
-    if ( iommu_flush_context_device(iommu, 0, (((u16)bus) << 8) | devfn,
-                                    DMA_CCMD_MASK_NOBIT, 1) )
-        iommu_flush_write_buffer(iommu);
-    else
+    rc = iommu_flush_context_device(iommu, 0, (((u16)bus) << 8) | devfn,
+                                    DMA_CCMD_MASK_NOBIT, 1);
+
+    if ( !rc )
     {
         int flush_dev_iotlb = find_ats_dev_drhd(iommu) ? 1 : 0;
-        iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
+        rc = iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
+    }
+
+    if ( rc > 0 )
+    {
+        iommu_flush_write_buffer(iommu);
+        rc = 0;
     }
 
     set_bit(iommu->index, &hd->arch.iommu_bitmap);
@@ -1410,7 +1424,7 @@ int domain_context_mapping_one(
     if ( !seg )
         me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
 
-    return 0;
+    return rc;
 }
 
 static int domain_context_mapping(
@@ -1505,6 +1519,7 @@ int domain_context_unmap_one(
     struct context_entry *context, *context_entries;
     u64 maddr;
     int iommu_domid;
+    int rc;
 
     ASSERT(pcidevs_locked());
     spin_lock(&iommu->lock);
@@ -1532,14 +1547,20 @@ int domain_context_unmap_one(
         return -EINVAL;
     }
 
-    if ( iommu_flush_context_device(iommu, iommu_domid,
+    rc = iommu_flush_context_device(iommu, iommu_domid,
                                     (((u16)bus) << 8) | devfn,
-                                    DMA_CCMD_MASK_NOBIT, 0) )
-        iommu_flush_write_buffer(iommu);
-    else
+                                    DMA_CCMD_MASK_NOBIT, 0);
+
+    if ( !rc )
     {
         int flush_dev_iotlb = find_ats_dev_drhd(iommu) ? 1 : 0;
-        iommu_flush_iotlb_dsi(iommu, iommu_domid, 0, flush_dev_iotlb);
+        rc = iommu_flush_iotlb_dsi(iommu, iommu_domid, 0, flush_dev_iotlb);
+    }
+
+    if ( rc > 0 )
+    {
+        iommu_flush_write_buffer(iommu);
+        rc = 0;
     }
 
     spin_unlock(&iommu->lock);
@@ -1548,7 +1569,7 @@ int domain_context_unmap_one(
     if ( !iommu->intel->drhd->segment )
         me_wifi_quirk(domain, bus, devfn, UNMAP_ME_PHANTOM_FUNC);
 
-    return 0;
+    return rc;
 }
 
 static int domain_context_unmap(
@@ -1738,7 +1759,7 @@ static int intel_iommu_map_page(
     unmap_vtd_domain_page(page);
 
     if ( !this_cpu(iommu_dont_flush_iotlb) )
-        __intel_iommu_iotlb_flush(d, gfn, dma_pte_present(old), 1);
+        iommu_flush_iotlb(d, gfn, dma_pte_present(old), 1);
 
     return 0;
 }
@@ -1754,14 +1775,15 @@ static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn)
     return 0;
 }
 
-void iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte,
-                     int order, int present)
+int iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte,
+                    int order, int present)
 {
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu = NULL;
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     int flush_dev_iotlb;
     int iommu_domid;
+    int rc = 0;
 
     iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
 
@@ -1775,11 +1797,19 @@ void iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte,
         iommu_domid= domain_iommu_domid(d, iommu);
         if ( iommu_domid == -1 )
             continue;
-        if ( iommu_flush_iotlb_psi(iommu, iommu_domid,
+
+        rc = iommu_flush_iotlb_psi(iommu, iommu_domid,
                                    (paddr_t)gfn << PAGE_SHIFT_4K,
-                                   order, !present, flush_dev_iotlb) )
+                                   order, !present, flush_dev_iotlb);
+        if ( rc > 0 )
+        {
             iommu_flush_write_buffer(iommu);
+            rc = 0;
+        } else if ( rc < 0 )
+            break;
     }
+
+    return rc;
 }
 
 static int __init vtd_ept_page_compatible(struct iommu *iommu)
xen/include/asm-x86/iommu.h +1 -1
index f22b3a5..790701e 100644
@@ -26,7 +26,7 @@ int iommu_setup_hpet_msi(struct msi_desc *);
 
 /* While VT-d specific, this must get declared in a generic header. */
 int adjust_vtd_irq_affinities(void);
-void iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte, int order, int present);
+int iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte, int order, int present);
 bool_t iommu_supports_eim(void);
 int iommu_enable_x2apic_IR(void);
 void iommu_disable_x2apic_IR(void);
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH v2 01/11] vt-d: fix the IOMMU flush issue

Quoted 30 lines

From: Xu, Quan
Sent: Monday, April 18, 2016 10:00 PM

The propagation value from IOMMU flush interfaces may be positive, which indicates callers need to flush cache, not one of faliures.

when the propagation value is positive, this patch fixes this flush issue as follows:
- call iommu_flush_write_buffer() to flush cache.
- return zero.

CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
---
 xen/drivers/passthrough/vtd/iommu.c | 94
++++++++++++++++++++++++-------------
 xen/include/asm-x86/iommu.h         |  2 +-
 2 files changed, 63 insertions(+), 33 deletions(-)
xen/drivers/passthrough/vtd/iommu.c +0 -0
index 5ad25dc..50d98ac 100644

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 561

Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +1 -2
@@ -558,14 +558,16 @@ static void iommu_flush_all(void)
     }
 }
 
-static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
-        int dma_old_pte_present, unsigned int page_count)
+static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,

any reason for the renaming here?

Quoted 49 lines
xen/drivers/passthrough/vtd/iommu.c +18 -10
+                             int dma_old_pte_present,
+                             unsigned int page_count)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     int flush_dev_iotlb;
     int iommu_domid;
+    int rc = 0;
 
     /*
      * No need pcideves_lock here because we have flush
@@ -584,29 +586,34 @@ static void __intel_iommu_iotlb_flush(struct domain *d,
 unsigned long gfn,
             continue;
 
         if ( page_count != 1 || gfn == INVALID_GFN )
-        {
-            if ( iommu_flush_iotlb_dsi(iommu, iommu_domid,
-                        0, flush_dev_iotlb) )
-                iommu_flush_write_buffer(iommu);
-        }
+            rc = iommu_flush_iotlb_dsi(iommu, iommu_domid,
+                                       0, flush_dev_iotlb);
         else
+            rc = iommu_flush_iotlb_psi(iommu, iommu_domid,
+                                       (paddr_t)gfn << PAGE_SHIFT_4K,
+                                       PAGE_ORDER_4K,
+                                       !dma_old_pte_present,
+                                       flush_dev_iotlb);
+
+        if ( rc > 0 )
         {
-            if ( iommu_flush_iotlb_psi(iommu, iommu_domid,
-                        (paddr_t)gfn << PAGE_SHIFT_4K, PAGE_ORDER_4K,
-                        !dma_old_pte_present, flush_dev_iotlb) )
-                iommu_flush_write_buffer(iommu);
-        }
+            iommu_flush_write_buffer(iommu);
+            rc = 0;
+        } else if ( rc < 0 )
+            break;
     }
+
+    return rc;
 }
 
 static void intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int
 page_count)

xen/drivers/passthrough/vtd/iommu.c static void __intel_iommu_iotlb_flush(struct domain *d, · line 619

Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.c +2 -2
 {
-    __intel_iommu_iotlb_flush(d, gfn, 1, page_count);
+    iommu_flush_iotlb(d, gfn, 1, page_count);
 }
 
 static void intel_iommu_iotlb_flush_all(struct domain *d)
 {
-    __intel_iommu_iotlb_flush(d, INVALID_GFN, 0, 0);
+    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }

Do you plan to change return value of above 2 functions in another patch, or will keep it current form w/o propagation?

Quoted 31 lines

/* clear one page's page table */

xen/drivers/passthrough/vtd/iommu.c +6 -5
@@ -640,7 +647,7 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr)
     iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
 
     if ( !this_cpu(iommu_dont_flush_iotlb) )
-        __intel_iommu_iotlb_flush(domain, addr >> PAGE_SHIFT_4K, 1, 1);
+        iommu_flush_iotlb(domain, addr >> PAGE_SHIFT_4K, 1, 1);
 
     unmap_vtd_domain_page(page);
 }
@@ -1281,6 +1288,7 @@ int domain_context_mapping_one(
     u64 maddr, pgd_maddr;
     u16 seg = iommu->intel->drhd->segment;
     int agaw;
+    int rc;
 
     ASSERT(pcidevs_locked());
     spin_lock(&iommu->lock);
@@ -1394,13 +1402,19 @@ int domain_context_mapping_one(
     spin_unlock(&iommu->lock);
 
     /* Context entry was previously non-present (with domid 0). */
-    if ( iommu_flush_context_device(iommu, 0, (((u16)bus) << 8) | devfn,
-                                    DMA_CCMD_MASK_NOBIT, 1) )
-        iommu_flush_write_buffer(iommu);
-    else
+    rc = iommu_flush_context_device(iommu, 0, (((u16)bus) << 8) | devfn,
+                                    DMA_CCMD_MASK_NOBIT, 1);
+
+    if ( !rc )

xen/drivers/passthrough/vtd/iommu.c int domain_context_mapping_one( · line 1417

Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.c +7 -1
     {
         int flush_dev_iotlb = find_ats_dev_drhd(iommu) ? 1 : 0;
-        iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
+        rc = iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
+    }
+
+    if ( rc > 0 )
+    {
+        iommu_flush_write_buffer(iommu);
+        rc = 0;

what about 'rc>0' in iommu_flush_context_device while "rc<0" in iommu_flush_iotlb_dsi, which will leave write buffer not flushed?

Quoted 34 lines
xen/drivers/passthrough/vtd/iommu.c +6 -5
     }
 
     set_bit(iommu->index, &hd->arch.iommu_bitmap);
@@ -1410,7 +1424,7 @@ int domain_context_mapping_one(
     if ( !seg )
         me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
 
-    return 0;
+    return rc;
 }
 
 static int domain_context_mapping(
@@ -1505,6 +1519,7 @@ int domain_context_unmap_one(
     struct context_entry *context, *context_entries;
     u64 maddr;
     int iommu_domid;
+    int rc;
 
     ASSERT(pcidevs_locked());
     spin_lock(&iommu->lock);
@@ -1532,14 +1547,20 @@ int domain_context_unmap_one(
         return -EINVAL;
     }
 
-    if ( iommu_flush_context_device(iommu, iommu_domid,
+    rc = iommu_flush_context_device(iommu, iommu_domid,
                                     (((u16)bus) << 8) | devfn,
-                                    DMA_CCMD_MASK_NOBIT, 0) )
-        iommu_flush_write_buffer(iommu);
-    else
+                                    DMA_CCMD_MASK_NOBIT, 0);
+
+    if ( !rc )
     {

xen/drivers/passthrough/vtd/iommu.c int domain_context_unmap_one( · line 1564

Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.c +7 -1
         int flush_dev_iotlb = find_ats_dev_drhd(iommu) ? 1 : 0;
-        iommu_flush_iotlb_dsi(iommu, iommu_domid, 0, flush_dev_iotlb);
+        rc = iommu_flush_iotlb_dsi(iommu, iommu_domid, 0, flush_dev_iotlb);
+    }
+
+    if ( rc > 0 )
+    {
+        iommu_flush_write_buffer(iommu);
+        rc = 0;
     }

ditto

Thanks
Kevin

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#3 lore raw

Re: [PATCH v2 01/11] vt-d: fix the IOMMU flush issue

Quoted 33 lines · Kevin
Quoted 33 lines

From: Xu, Quan
Sent: Monday, April 18, 2016 10:00 PM

The propagation value from IOMMU flush interfaces may be positive, which indicates callers need to flush cache, not one of faliures.

when the propagation value is positive, this patch fixes this flush issue as follows:
- call iommu_flush_write_buffer() to flush cache.
- return zero.

CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
---
 xen/drivers/passthrough/vtd/iommu.c | 94
++++++++++++++++++++++++-------------
 xen/include/asm-x86/iommu.h         |  2 +-
 2 files changed, 63 insertions(+), 33 deletions(-)
xen/drivers/passthrough/vtd/iommu.c +0 -0
index 5ad25dc..50d98ac 100644
@@ -558,14 +558,16 @@ static void iommu_flush_all(void)
     }
 }
 
Quoted 6 lines

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 561

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +1 -2
-static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
-        int dma_old_pte_present, unsigned int page_count)
+static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,

any reason for the renaming here?

As Jan mentioned,
"this would be a good opportunity to also drop the stray double underscores: You need to touch all callers anyway."
http://lists.xenproject.org/archives/html/xen-devel/2016-03/msg02456.html

think twice, I dropped the stray double underscores.
both intel_iommu_iotlb_flush and iommu_iotlb_flush were already in use, So I tried to rename it to ' iommu_flush_iotlb'.

Quoted 57 lines
Quoted 17 lines
xen/drivers/passthrough/vtd/iommu.c +4 -0
+                             int dma_old_pte_present,
+                             unsigned int page_count)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     int flush_dev_iotlb;
     int iommu_domid;
+    int rc = 0;
 
     /*
      * No need pcideves_lock here because we have flush @@ -584,29
+586,34 @@ static void __intel_iommu_iotlb_flush(struct domain *d,

unsigned long gfn,

             continue;

         if ( page_count != 1 || gfn == INVALID_GFN )

xen/drivers/passthrough/vtd/iommu.c static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,

Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.c +4 -5
-        {
-            if ( iommu_flush_iotlb_dsi(iommu, iommu_domid,
-                        0, flush_dev_iotlb) )
-                iommu_flush_write_buffer(iommu);
-        }
+            rc = iommu_flush_iotlb_dsi(iommu, iommu_domid,
+                                       0, flush_dev_iotlb);
         else
+            rc = iommu_flush_iotlb_psi(iommu, iommu_domid,
+                                       (paddr_t)gfn <<

PAGE_SHIFT_4K,

xen/drivers/passthrough/vtd/iommu.c static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,

Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +5 -2
+                                       PAGE_ORDER_4K,
+                                       !dma_old_pte_present,
+                                       flush_dev_iotlb);
+
+        if ( rc > 0 )
         {
-            if ( iommu_flush_iotlb_psi(iommu, iommu_domid,
-                        (paddr_t)gfn << PAGE_SHIFT_4K,

PAGE_ORDER_4K,

Quoted 20 lines
xen/drivers/passthrough/vtd/iommu.c +6 -3
-                        !dma_old_pte_present, flush_dev_iotlb) )
-                iommu_flush_write_buffer(iommu);
-        }
+            iommu_flush_write_buffer(iommu);
+            rc = 0;
+        } else if ( rc < 0 )
+            break;
     }
+
+    return rc;
 }
 
 static void intel_iommu_iotlb_flush(struct domain *d, unsigned long

gfn, unsigned int
page_count)
{

xen/drivers/passthrough/vtd/iommu.c +1 -1
-    __intel_iommu_iotlb_flush(d, gfn, 1, page_count);
+    iommu_flush_iotlb(d, gfn, 1, page_count);
 }
Quoted 8 lines

xen/drivers/passthrough/vtd/iommu.c static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, · line 617

Quoted 4 lines

static void intel_iommu_iotlb_flush_all(struct domain *d) {

xen/drivers/passthrough/vtd/iommu.c +1 -1
-    __intel_iommu_iotlb_flush(d, INVALID_GFN, 0, 0);
+    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }

Do you plan to change return value of above 2 functions in another patch, or will keep it current form w/o propagation?

Change return value of above 2 functions in another patches.

Quoted 37 lines

xen/drivers/passthrough/vtd/iommu.c static void dma_pte_clear_one(struct domain

Quoted 3 lines

/* clear one page's page table */

xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -640,7 +647,7 @@ static void dma_pte_clear_one(struct domain

*domain, u64 addr)

Quoted 33 lines
xen/drivers/passthrough/vtd/iommu.c +8 -6
     iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
 
     if ( !this_cpu(iommu_dont_flush_iotlb) )
-        __intel_iommu_iotlb_flush(domain, addr >> PAGE_SHIFT_4K, 1, 1);
+        iommu_flush_iotlb(domain, addr >> PAGE_SHIFT_4K, 1, 1);
 
     unmap_vtd_domain_page(page);
 }
@@ -1281,6 +1288,7 @@ int domain_context_mapping_one(
     u64 maddr, pgd_maddr;
     u16 seg = iommu->intel->drhd->segment;
     int agaw;
+    int rc;
 
     ASSERT(pcidevs_locked());
     spin_lock(&iommu->lock);
@@ -1394,13 +1402,19 @@ int domain_context_mapping_one(
     spin_unlock(&iommu->lock);
 
     /* Context entry was previously non-present (with domid 0). */
-    if ( iommu_flush_context_device(iommu, 0, (((u16)bus) << 8) | devfn,
-                                    DMA_CCMD_MASK_NOBIT, 1) )
-        iommu_flush_write_buffer(iommu);
-    else
+    rc = iommu_flush_context_device(iommu, 0, (((u16)bus) << 8) | devfn,
+                                    DMA_CCMD_MASK_NOBIT, 1);
+
+    if ( !rc )
     {
         int flush_dev_iotlb = find_ats_dev_drhd(iommu) ? 1 : 0;
-        iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
+        rc = iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
+    }
Quoted 8 lines

xen/drivers/passthrough/vtd/iommu.c int domain_context_mapping_one( · line 1417

Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +5 -0
+
+    if ( rc > 0 )
+    {
+        iommu_flush_write_buffer(iommu);
+        rc = 0;

what about 'rc>0' in iommu_flush_context_device while "rc<0" in iommu_flush_iotlb_dsi, which will leave write buffer not flushed?

That's true, but IMO it is impossible.
IOW, if 'rc>0' is in iommu_flush_context_device, the rc should be "rc>0" in iommu_flush_iotlb_dsi too.
As the flush_non_present_entry parameter is '1' to both, and read the same register 'iommu->cap' at the beginning of the functions.

To be honest, this modification is an aggressive approach and looks good to me, but I am open for any other suggestions.

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH v2 01/11] vt-d: fix the IOMMU flush issue

In reply to Quan Xu

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 562

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +2 -2
@@ -558,14 +558,16 @@ static void iommu_flush_all(void)
     }
 }
 
-static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
-        int dma_old_pte_present, unsigned int page_count)
+static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
+                             int dma_old_pte_present,

With the rename, please also make this boolean parameter bool_t.

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 570

Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +2 -0
+                             unsigned int page_count)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     int flush_dev_iotlb;
     int iommu_domid;
+    int rc = 0;

Pointless initializer.

Quoted 18 lines
xen/drivers/passthrough/vtd/iommu.c +8 -5
@@ -584,29 +586,34 @@ static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
             continue;
 
         if ( page_count != 1 || gfn == INVALID_GFN )
-        {
-            if ( iommu_flush_iotlb_dsi(iommu, iommu_domid,
-                        0, flush_dev_iotlb) )
-                iommu_flush_write_buffer(iommu);
-        }
+            rc = iommu_flush_iotlb_dsi(iommu, iommu_domid,
+                                       0, flush_dev_iotlb);
         else
+            rc = iommu_flush_iotlb_psi(iommu, iommu_domid,
+                                       (paddr_t)gfn << PAGE_SHIFT_4K,
+                                       PAGE_ORDER_4K,
+                                       !dma_old_pte_present,
+                                       flush_dev_iotlb);
+

xen/drivers/passthrough/vtd/iommu.c static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, · line 602

Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.c +4 -5
+        if ( rc > 0 )
         {
-            if ( iommu_flush_iotlb_psi(iommu, iommu_domid,
-                        (paddr_t)gfn << PAGE_SHIFT_4K, PAGE_ORDER_4K,
-                        !dma_old_pte_present, flush_dev_iotlb) )
-                iommu_flush_write_buffer(iommu);
-        }
+            iommu_flush_write_buffer(iommu);
+            rc = 0;
+        } else if ( rc < 0 )

Coding style.

xen/drivers/passthrough/vtd/iommu.c static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, · line 603

Quoted 1 line
xen/drivers/passthrough/vtd/iommu.c +1 -0
+            break;

I thought we had agreed on best effort flushing when an error occurs. That means you shouldn't break out of the loop here, but accumulate errors. (Breaking out of the loop would be okay if it was conditional upon the domain having got crashed.)

(The same issue exists again near the end of the patch).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#5 lore raw

Re: [PATCH v2 01/11] vt-d: fix the IOMMU flush issue

Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:

I thought we had agreed on best effort flushing when an error occurs. That means you shouldn't break out of the loop here, but accumulate errors. (Breaking out of the loop would be okay if it was conditional upon the domain having got crashed.)

I will follow it for coming version.
I indeed agreed to that single point, however, I wondered whether I could extend it as a pattern for this series or not. Now I am clear.

Quan

Quoted 2 lines

(The same issue exists again near the end of the patch).

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#6 lore raw

Re: [PATCH v2 01/11] vt-d: fix the IOMMU flush issue

In reply to Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -558,14 +558,16 @@ static void iommu_flush_all(void)
     }
 }
 
Quoted 15 lines

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 570

Quoted 12 lines
xen/drivers/passthrough/vtd/iommu.c +4 -2
-static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
-        int dma_old_pte_present, unsigned int page_count)
+static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
+                             int dma_old_pte_present,
+                             unsigned int page_count)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     int flush_dev_iotlb;
     int iommu_domid;
+    int rc = 0;

Pointless initializer.

I am afraid not.
In case I don't initialize 'rc', the compiler prints out " error: 'rc' may be used uninitialized in this function [-Werror=maybe-uninitialized]".

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#7 lore raw

Re: [PATCH v2 01/11] vt-d: fix the IOMMU flush issue

Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 26.04.16 at 04:18, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -558,14 +558,16 @@ static void iommu_flush_all(void)
     }
 }
 
Quoted 14 lines

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 570

Quoted 12 lines
xen/drivers/passthrough/vtd/iommu.c +4 -2
-static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
-        int dma_old_pte_present, unsigned int page_count)
+static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
+                             int dma_old_pte_present,
+                             unsigned int page_count)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     int flush_dev_iotlb;
     int iommu_domid;
+    int rc = 0;

Pointless initializer.

Quoted 3 lines

I am afraid not.
In case I don't initialize 'rc', the compiler prints out " error: 'rc' may be used uninitialized in this function [-Werror=maybe-uninitialized]".

Looking at the patch again I can't see why that would be the case. Are you certain this isn't a result of subsequent patches, IOW did you try this with just this one patch applied? rc gets initialized in both the if() and the else branches, and there's no label allowing that initialization to be bypassed...

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#8 lore raw

Re: [PATCH v2 01/11] vt-d: fix the IOMMU flush issue

Quoted 25 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.04.16 at 04:18, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 561

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -1
@@ -558,14 +558,16 @@ static void iommu_flush_all(void)
     }
 }
 
-static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long

gfn,

Quoted 14 lines
Quoted 13 lines

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 570

Quoted 11 lines
xen/drivers/passthrough/vtd/iommu.c +4 -1
-        int dma_old_pte_present, unsigned int page_count)
+static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
+                             int dma_old_pte_present,
+                             unsigned int page_count)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     int flush_dev_iotlb;
     int iommu_domid;
+    int rc = 0;

Pointless initializer.

Quoted 7 lines
Quoted 3 lines

I am afraid not.
In case I don't initialize 'rc', the compiler prints out " error:
'rc' may be used uninitialized in this function [-Werror=maybe-uninitialized]".

Looking at the patch again I can't see why that would be the case. Are you certain this isn't a result of subsequent patches, IOW did you try this with just this one patch applied?

Yes, I test it with this only patch again.

The same result.

Quoted 2 lines

rc gets initialized in both the if() and the else
branches, and there's no label allowing that initialization to be bypassed...

look at this function again,

Quoted 1 line
Quoted 1 line

func

iommu_flush_iotlb()

{
    int rc;

    for_each_drhd_unit ( drhd )
    {
        if ()
            rc ..
        else
            rc ..
    }

    return rc;
}

<< func

The case drhd is NULL, the rc may be not initialized.

Development ENV:
Ubuntu 14.04.1,
GCC 4.8

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#9 lore raw

Re: [PATCH v2 01/11] vt-d: fix the IOMMU flush issue

Quoted 49 lines
Quoted 1 line
Quoted 1 line · On 26.04.16 at 12:15, <[email protected]> wrote:
Quoted 28 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.04.16 at 04:18, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 561

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -1
@@ -558,14 +558,16 @@ static void iommu_flush_all(void)
     }
 }
 
-static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long

gfn,

Quoted 17 lines
Quoted 12 lines

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 570

Quoted 11 lines
xen/drivers/passthrough/vtd/iommu.c +4 -1
-        int dma_old_pte_present, unsigned int page_count)
+static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
+                             int dma_old_pte_present,
+                             unsigned int page_count)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     int flush_dev_iotlb;
     int iommu_domid;
+    int rc = 0;
Quoted 1 line

Pointless initializer.

I am afraid not.
In case I don't initialize 'rc', the compiler prints out " error:
'rc' may be used uninitialized in this function

[-Werror=maybe-uninitialized]".

Quoted 3 lines

Looking at the patch again I can't see why that would be the case. Are you certain this isn't a result of subsequent patches, IOW did you try

this

Quoted 1 line

with just this one patch applied?

Yes, I test it with this only patch again.

The same result.

Quoted 2 lines

rc gets initialized in both the if() and the else branches, and there's no label allowing that initialization to be

bypassed...

look at this function again,

Quoted 1 line
Quoted 1 line

func

iommu_flush_iotlb()

Quoted 13 lines
{
    int rc;

    for_each_drhd_unit ( drhd )
    {
        if ()
            rc ..
        else
            rc ..
    }

    return rc;
}

Ah, I'm sorry - the patch context didn't make it obvious this is in a loop.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#10 lore raw

Re: [PATCH v2 01/11] vt-d: fix the IOMMU flush issue

Quoted 62 lines · Jan Beulich
Quoted 62 lines
Quoted 1 line
Quoted 1 line · On 26.04.16 at 12:15, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 26.04.16 at 04:18, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -558,14 +558,16 @@ static void iommu_flush_all(void)
     }
 }
 
Quoted 20 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
xen/drivers/passthrough/vtd/iommu.c +0 -1
-static void __intel_iommu_iotlb_flush(struct domain *d,

unsigned long

gfn,

Quoted 17 lines
Quoted 12 lines

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 570

Quoted 11 lines
xen/drivers/passthrough/vtd/iommu.c +4 -1
-        int dma_old_pte_present, unsigned int page_count)
+static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
+                             int dma_old_pte_present,
+                             unsigned int page_count)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     int flush_dev_iotlb;
     int iommu_domid;
+    int rc = 0;
Quoted 1 line

Pointless initializer.

I am afraid not.
In case I don't initialize 'rc', the compiler prints out " error:
'rc' may be used uninitialized in this function

[-Werror=maybe-uninitialized]".

Quoted 4 lines

Looking at the patch again I can't see why that would be the case. Are you certain this isn't a result of subsequent patches, IOW did you try

this

Quoted 1 line

with just this one patch applied?

Yes, I test it with this only patch again.

The same result.

Quoted 2 lines

rc gets initialized in both the if() and the else branches, and there's no label allowing that initialization to be

bypassed...

look at this function again,

Quoted 1 line
Quoted 1 line

func

iommu_flush_iotlb()

{
    int rc;

    for_each_drhd_unit ( drhd )
    {
        if ()
            rc ..
        else
            rc ..
    }
Quoted 5 lines
Quoted 2 lines
    return rc;
}

Ah, I'm sorry - the patch context didn't make it obvious this is in a loop.

Never mind. It is _not_ quite as obvious, but compiler helps us. Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#11 lore raw

PATCH v2 2/11 IOMMU: handle IOMMU mapping and unmapping failures

In reply to Quan Xu

Now IOMMU mapping and unmapping failures are treated as a fatal to the domain (with the exception of the hardware domain).

If IOMMU mapping and unmapping failed, crash the domain (with the exception of the hardware domain) and propagate the error up to the call trees.

CC Jan Beulich <[email protected]>
---
 xen/drivers/passthrough/iommu.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
xen/drivers/passthrough/iommu.c +14 -2
index b64676f..850101b 100644
@@ -243,21 +243,33 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
                    unsigned int flags)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    int rc;
 
     if ( !iommu_enabled || !hd->platform_ops )
         return 0;
 
-    return hd->platform_ops->map_page(d, gfn, mfn, flags);
+    rc = hd->platform_ops->map_page(d, gfn, mfn, flags);
+
+    if ( rc && !is_hardware_domain(d) )
+        domain_crash(d);
+
+    return rc;
 }
 
 int iommu_unmap_page(struct domain *d, unsigned long gfn)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    int rc;
 
     if ( !iommu_enabled || !hd->platform_ops )
         return 0;
 
-    return hd->platform_ops->unmap_page(d, gfn);
+    rc = hd->platform_ops->unmap_page(d, gfn);
+
+    if ( rc && !is_hardware_domain(d) )
+        domain_crash(d);
+
+    return rc;
 }
 
 static void iommu_free_pagetables(unsigned long unused)
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 2/11
#12 lore raw

Re: [PATCH v2 02/11] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 5 lines

From: Quan Xu
Sent: Monday, April 18, 2016 10:00 PM

Now IOMMU mapping and unmapping failures are treated as a fatal to the domain (with the exception of the hardware domain).

'Now' is more about eixsting state, while it's actually what you want to change towards. Better directly say "Treat IOMMU mapping...".

Quoted 8 lines

If IOMMU mapping and unmapping failed, crash the domain (with the exception of the hardware domain) and propagate the error up to the call trees.

CC Jan Beulich <[email protected]>

Otherwise looks OK to me.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#13 lore raw

Re: [PATCH v2 02/11] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 9 lines · Kevin
Quoted 5 lines

From: Quan Xu
Sent: Monday, April 18, 2016 10:00 PM

Now IOMMU mapping and unmapping failures are treated as a fatal to the domain (with the exception of the hardware domain).

'Now' is more about eixsting state, while it's actually what you want to change towards. Better directly say "Treat IOMMU mapping...".

Agreed. I'll modify it in next v3. Thanks for your review!! Quan

Quoted 5 lines
Quoted 5 lines

If IOMMU mapping and unmapping failed, crash the domain (with the exception of the hardware domain) and propagate the error up to the call trees.

Quoted 7 lines
Quoted 3 lines
CC Jan Beulich <[email protected]>

Otherwise looks OK to me.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#14 lore raw

Re: [PATCH v2 02/11] IOMMU: handle IOMMU mapping and unmapping failures

In reply to Quan Xu
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +1 -0
@@ -243,21 +243,33 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
                    unsigned int flags)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    int rc;
 
     if ( !iommu_enabled || !hd->platform_ops )

xen/drivers/passthrough/iommu.c int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, · line 257

Quoted 10 lines
xen/drivers/passthrough/iommu.c +6 -1
         return 0;
 
-    return hd->platform_ops->map_page(d, gfn, mfn, flags);
+    rc = hd->platform_ops->map_page(d, gfn, mfn, flags);
+
+    if ( rc && !is_hardware_domain(d) )
+        domain_crash(d);
+
+    return rc;
 }

As said before - letting this go completely silently for the hardware domain is bad. At least the first instance of such an event needs a message to be logged. Advanced variants where a message gets logged once in a while if the issue re-occurs would be nice, but aren't strictly necessary imo. And note that even logging all occurrences would not be a security issue, but just a usability one (but I still recommend against this).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#15 lore raw

Re: [PATCH v2 02/11] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 12 lines · Jan Beulich

xen/drivers/passthrough/iommu.c int iommu_map_page(struct domain *d,

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +0 -0
@@ -243,21 +243,33 @@ int iommu_map_page(struct domain *d,

unsigned long gfn, unsigned long mfn,

Quoted 7 lines
xen/drivers/passthrough/iommu.c +1 -0
                    unsigned int flags)  {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    int rc;
 
     if ( !iommu_enabled || !hd->platform_ops )
         return 0;
 
Quoted 16 lines

xen/drivers/passthrough/iommu.c int iommu_map_page(struct domain *d, · line 256

Quoted 8 lines
xen/drivers/passthrough/iommu.c +6 -1
-    return hd->platform_ops->map_page(d, gfn, mfn, flags);
+    rc = hd->platform_ops->map_page(d, gfn, mfn, flags);
+
+    if ( rc && !is_hardware_domain(d) )
+        domain_crash(d);
+
+    return rc;
 }

As said before - letting this go completely silently for the hardware domain is bad. At least the first instance of such an event needs a message to be logged. Advanced variants where a message gets logged once in a while if the issue re- occurs would be nice, but aren't strictly necessary imo. And note that even logging all occurrences would not be a security issue, but just a usability one (but I still recommend against this).

IMO the IOMMU map/unmap failures are the small probability events. I think the log message wouldn't spam log message.

I'd like modify it as following:

xen/drivers/passthrough/iommu.c +14 -1
@@ -243,11 +243,24 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
                    unsigned int flags)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    int rc;
 
     if ( !iommu_enabled || !hd->platform_ops )
         return 0;
 
-    return hd->platform_ops->map_page(d, gfn, mfn, flags);
+    rc = hd->platform_ops->map_page(d, gfn, mfn, flags);
+
+    if ( rc )
+    {
+        printk(XENLOG_ERR
+               "iommu_map_page: IOMMU mapping gfn %#lx mfn %#lx failed for dom%d.",
+               gfn, mfn, d->domain_id);
+
+        if ( !is_hardware_domain(d) )
+            domain_crash(d);
+    }
+
+    return rc;
 }
 
 int iommu_unmap_page(struct domain *d, unsigned long gfn)

btw, in case I have print-out for mapping failure, I think it is no need to print out an extra message for the hardware domain. If this is still not what you want, I'll continue to enhance it. Also I am not good at description, so I try to send out code modification directly.

Ditto for iommu_unmap_page().

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#16 lore raw

Re: [PATCH v2 02/11] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 27.04.16 at 16:26, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich

xen/drivers/passthrough/iommu.c int iommu_map_page(struct domain *d,

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +0 -0
@@ -243,21 +243,33 @@ int iommu_map_page(struct domain *d,

unsigned long gfn, unsigned long mfn,

Quoted 7 lines
xen/drivers/passthrough/iommu.c +1 -0
                    unsigned int flags)  {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    int rc;
 
     if ( !iommu_enabled || !hd->platform_ops )
         return 0;
 
Quoted 10 lines

xen/drivers/passthrough/iommu.c int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, · line 264

Quoted 8 lines
xen/drivers/passthrough/iommu.c +6 -1
-    return hd->platform_ops->map_page(d, gfn, mfn, flags);
+    rc = hd->platform_ops->map_page(d, gfn, mfn, flags);
+
+    if ( rc && !is_hardware_domain(d) )
+        domain_crash(d);
+
+    return rc;
 }

As said before - letting this go completely silently for the hardware domain

is

Quoted 1 line

bad. At least the first instance of such an event needs a message to be

logged.

Quoted 1 line

Advanced variants where a message gets logged once in a while if the issue

re-

Quoted 2 lines

occurs would be nice, but aren't strictly necessary imo. And note that even logging all occurrences would not be a security issue, but just a usability

Quoted 7 lines

one

Quoted 2 lines

(but I still recommend against this).

IMO the IOMMU map/unmap failures are the small probability events. I think the log message wouldn't
spam log message.

That's when things work right. The case to consider is when something goes wrong, leading to a myriad of failures. To see what went wrong first it is necessary to not write overly many messages when many failures occur in close succession.

Quoted 17 lines

I'd like modify it as following:

xen/drivers/passthrough/iommu.c +5 -1
@@ -243,11 +243,24 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
                    unsigned int flags)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    int rc;
 
     if ( !iommu_enabled || !hd->platform_ops )
         return 0;
 
-    return hd->platform_ops->map_page(d, gfn, mfn, flags);
+    rc = hd->platform_ops->map_page(d, gfn, mfn, flags);
+
+    if ( rc )
+    {

xen/drivers/passthrough/iommu.c int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, · line 264

Quoted 10 lines
xen/drivers/passthrough/iommu.c +9 -0
+        printk(XENLOG_ERR
+               "iommu_map_page: IOMMU mapping gfn %#lx mfn %#lx failed for dom%d.",
+               gfn, mfn, d->domain_id);
+
+        if ( !is_hardware_domain(d) )
+            domain_crash(d);
+    }
+
+    return rc;
 }

That's okay as long as no code path would ever trigger hundreds of these messages before getting back to the pointer where the now dead domain gets unscheduled. And note that this can't just be "I don't think this can happen", but it needs to be guaranteed, or else you introduce a security issue.

Quoted 4 lines

btw, in case I have print-out for mapping failure, I think it is no need to print out an extra message for the hardware domain.
If this is still not what you want, I'll continue to enhance it. Also I am not good at description, so I try to send out code modification directly.

I.e. I continue to think that

    if ( is_hardware_domain() )
        printk();
    else
        domain_crash();

is the better approach (and still subject to preventing spamming the log as per the first part of my reply).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#17 lore raw

Re: [PATCH v2 02/11] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 5 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 27.04.16 at 16:26, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:

I.e. I continue to think that

Quoted 8 lines
    if ( is_hardware_domain() )
        printk();
    else
        domain_crash();

is the better approach (and still subject to preventing spamming the log as per the first part of my reply).

agreed. I will follow this approach. Thanks.

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#18 lore raw

PATCH v2 3/11 IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

In reply to Quan Xu

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

For the hardware domain, we do things on a best effort basis. When rollback is not feasible (in early initialization phase or trade-off of complexity), at least, unmap upon maps error or then throw out error message.

IOMMU unmapping should perhaps continue despite an error, in an attempt to do best effort cleanup.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Jun Nakajima <[email protected]>
CC Kevin Tian <[email protected]>
CC George Dunlap <[email protected]>
---
 xen/arch/x86/mm.c               | 13 ++++++++-----
 xen/arch/x86/mm/p2m-ept.c       | 25 ++++++++++++++++++++++---
 xen/arch/x86/mm/p2m-pt.c        | 22 ++++++++++++++++++----
 xen/arch/x86/mm/p2m.c           | 11 +++++++++--
 xen/drivers/passthrough/iommu.c | 14 +++++++++++++-
 5 files changed, 70 insertions(+), 15 deletions(-)
xen/arch/x86/mm.c +8 -5
index c997b53..5c4fb58 100644
@@ -2467,7 +2467,7 @@ static int __get_page_type(struct page_info *page, unsigned long type,
                            int preemptible)
 {
     unsigned long nx, x, y = page->u.inuse.type_info;
-    int rc = 0;
+    int rc = 0, ret = 0;
 
     ASSERT(!(type & ~(PGT_type_mask | PGT_pae_xen_l2)));
 
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info *page, unsigned long type,
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                ret = iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+                ret = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                     page_to_mfn(page),
+                                     IOMMUF_readable|IOMMUF_writable);
         }
     }
 
@@ -2599,6 +2599,9 @@ static int __get_page_type(struct page_info *page, unsigned long type,
     if ( (x & PGT_partial) && !(nx & PGT_partial) )
         put_page(page);
 
+    if ( unlikely(ret) )
+        rc = ret;
+
     return rc;
 }
 
xen/arch/x86/mm/p2m-ept.c +22 -3
index 3cb6868..22c8d17 100644
@@ -665,7 +665,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     ept_entry_t *table, *ept_entry = NULL;
     unsigned long gfn_remainder = gfn;
     unsigned int i, target = order / EPT_TABLE_ORDER;
-    int ret, rc = 0;
+    int ret, err = 0, rc = 0;
     bool_t direct_mmio = (p2mt == p2m_mmio_direct);
     uint8_t ipat = 0;
     bool_t need_modify_vtd_table = 1;
@@ -830,10 +830,26 @@ out:
         {
             if ( iommu_flags )
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_map_page(d, gfn + i, mfn_x(mfn) + i, iommu_flags);
+                {
+                    ret = iommu_map_page(d, gfn + i, mfn_x(mfn) + i, iommu_flags);
+
+                    if ( unlikely(ret) )
+                    {
+                        while (i)
+                            iommu_unmap_page(d, gfn + --i);
+
+                        err = ret;
+                        break;
+                    }
+                }
             else
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_unmap_page(d, gfn + i);
+                {
+                    ret = iommu_unmap_page(d, gfn + i);
+
+                    if ( unlikely(ret) )
+                        err = ret;
+                }
         }
     }
 
@@ -849,6 +865,9 @@ out:
     if ( rc == 0 && p2m_is_hostp2m(p2m) )
         p2m_altp2m_propagate_change(d, _gfn(gfn), mfn, order, p2mt, p2ma);
 
+    if ( unlikely(err) )
+        rc = err;
+
     return rc;
 }
 
xen/arch/x86/mm/p2m-pt.c +18 -4
index 3d80612..db4257a 100644
@@ -498,7 +498,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     l1_pgentry_t intermediate_entry = l1e_empty();
     l2_pgentry_t l2e_content;
     l3_pgentry_t l3e_content;
-    int rc;
+    int rc, ret;
     unsigned int iommu_pte_flags = p2m_get_iommu_flags(p2mt);
     /*
      * old_mfn and iommu_old_flags control possible flush/update needs on the
@@ -680,11 +680,25 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
         }
         else if ( iommu_pte_flags )
             for ( i = 0; i < (1UL << page_order); i++ )
-                iommu_map_page(p2m->domain, gfn + i, mfn_x(mfn) + i,
-                               iommu_pte_flags);
+            {
+                ret = iommu_map_page(p2m->domain, gfn + i, mfn_x(mfn) + i,
+                                     iommu_pte_flags);
+                if ( unlikely(ret) )
+                {
+                    while (i)
+                        iommu_unmap_page(p2m->domain, gfn + --i);
+
+                    rc = ret;
+                }
+            }
         else
             for ( i = 0; i < (1UL << page_order); i++ )
-                iommu_unmap_page(p2m->domain, gfn + i);
+            {
+                ret = iommu_unmap_page(p2m->domain, gfn + i);
+
+                if ( unlikely(ret) )
+                    rc = ret;
+            }
     }
 
     /*
xen/arch/x86/mm/p2m.c +9 -2
index b3fce1b..98450a4 100644
@@ -610,13 +610,20 @@ p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn,
     mfn_t mfn_return;
     p2m_type_t t;
     p2m_access_t a;
+    int ret = 0, rc;
 
     if ( !paging_mode_translate(p2m->domain) )
     {
         if ( need_iommu(p2m->domain) )
             for ( i = 0; i < (1 << page_order); i++ )
-                iommu_unmap_page(p2m->domain, mfn + i);
-        return 0;
+            {
+               rc = iommu_unmap_page(p2m->domain, mfn + i);
+
+               if ( unlikely(rc) )
+                   ret = rc;
+            }
+
+        return ret;
     }
 
     ASSERT(gfn_locked_by_me(p2m, gfn));
xen/drivers/passthrough/iommu.c +13 -1
index 850101b..c351209 100644
@@ -172,6 +172,8 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
     {
         struct page_info *page;
         unsigned int i = 0;
+        int ret, rc = 0;
+
         page_list_for_each ( page, &d->page_list )
         {
             unsigned long mfn = page_to_mfn(page);
@@ -182,10 +184,20 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
                  ((page->u.inuse.type_info & PGT_type_mask)
                   == PGT_writable_page) )
                 mapping |= IOMMUF_writable;
-            hd->platform_ops->map_page(d, gfn, mfn, mapping);
+
+            ret = hd->platform_ops->map_page(d, gfn, mfn, mapping);
+
+            if ( unlikely(ret) )
+                rc = ret;
+
             if ( !(i++ & 0xfffff) )
                 process_pending_softirqs();
         }
+
+        if ( rc )
+            printk(XENLOG_G_ERR
+                   "dom%d: IOMMU mapping is failed for hardware domain.",
+                   d->domain_id);
     }
 
     return hd->platform_ops->hwdom_init(d);
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#19 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

Quoted 6 lines

From: Xu, Quan
Sent: Monday, April 18, 2016 10:00 PM

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

What do you mean by 'lighter weight"? Please clarify it.

Quoted 4 lines

For the hardware domain, we do things on a best effort basis. When rollback is not feasible (in early initialization phase or trade-off of complexity), at least, unmap upon maps error or then throw out error message.

remove 'or'. Based on next sentence, is above specific for IOMMU mapping?

Quoted 78 lines

IOMMU unmapping should perhaps continue despite an error, in an attempt to do best effort cleanup.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Jun Nakajima <[email protected]>
CC Kevin Tian <[email protected]>
CC George Dunlap <[email protected]>
---
 xen/arch/x86/mm.c               | 13 ++++++++-----
 xen/arch/x86/mm/p2m-ept.c       | 25 ++++++++++++++++++++++---
 xen/arch/x86/mm/p2m-pt.c        | 22 ++++++++++++++++++----
 xen/arch/x86/mm/p2m.c           | 11 +++++++++--
 xen/drivers/passthrough/iommu.c | 14 +++++++++++++-
 5 files changed, 70 insertions(+), 15 deletions(-)
xen/arch/x86/mm.c +8 -5
index c997b53..5c4fb58 100644
@@ -2467,7 +2467,7 @@ static int __get_page_type(struct page_info *page, unsigned
 long type,
                            int preemptible)
 {
     unsigned long nx, x, y = page->u.inuse.type_info;
-    int rc = 0;
+    int rc = 0, ret = 0;
 
     ASSERT(!(type & ~(PGT_type_mask | PGT_pae_xen_l2)));
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info *page, unsigned
 long type,
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                ret = iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+                ret = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                     page_to_mfn(page),
+                                     IOMMUF_readable|IOMMUF_writable);
         }
     }
@@ -2599,6 +2599,9 @@ static int __get_page_type(struct page_info *page, unsigned
 long type,
     if ( (x & PGT_partial) && !(nx & PGT_partial) )
         put_page(page);
 
+    if ( unlikely(ret) )
+        rc = ret;
+
     return rc;
 }
xen/arch/x86/mm/p2m-ept.c +1 -1
index 3cb6868..22c8d17 100644
@@ -665,7 +665,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn,
 mfn_t mfn,
     ept_entry_t *table, *ept_entry = NULL;
     unsigned long gfn_remainder = gfn;
     unsigned int i, target = order / EPT_TABLE_ORDER;
-    int ret, rc = 0;
+    int ret, err = 0, rc = 0;
     bool_t direct_mmio = (p2mt == p2m_mmio_direct);
     uint8_t ipat = 0;
     bool_t need_modify_vtd_table = 1;
xen/arch/x86/mm/p2m-ept.c +0 -0
@@ -830,10 +830,26 @@ out:
         {

xen/arch/x86/mm/p2m-ept.c out: · line 839

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +7 -1
             if ( iommu_flags )
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_map_page(d, gfn + i, mfn_x(mfn) + i, iommu_flags);
+                {
+                    ret = iommu_map_page(d, gfn + i, mfn_x(mfn) + i, iommu_flags);
+
+                    if ( unlikely(ret) )
+                    {
+                        while (i)
+                            iommu_unmap_page(d, gfn + --i);

How about below?

while (i-- >= 0)

	iommu_unmap_page(d, gfn + i);
Quoted 18 lines
xen/arch/x86/mm/p2m-ept.c +11 -1
+
+                        err = ret;
+                        break;
+                    }
+                }
             else
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_unmap_page(d, gfn + i);
+                {
+                    ret = iommu_unmap_page(d, gfn + i);
+
+                    if ( unlikely(ret) )
+                        err = ret;
+                }
         }
     }
 

xen/arch/x86/mm/p2m-ept.c out: · line 870

Quoted 6 lines
xen/arch/x86/mm/p2m-ept.c +3 -0
@@ -849,6 +865,9 @@ out:
     if ( rc == 0 && p2m_is_hostp2m(p2m) )
         p2m_altp2m_propagate_change(d, _gfn(gfn), mfn, order, p2mt, p2ma);
 
+    if ( unlikely(err) )
+        rc = err;
+

not sure we need three return values here: rc, ret, err...

Quoted 111 lines
xen/arch/x86/mm/p2m-ept.c +0 -0
     return rc;
 }
 
xen/arch/x86/mm/p2m-pt.c +1 -1
index 3d80612..db4257a 100644
@@ -498,7 +498,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn,
 mfn_t mfn,
     l1_pgentry_t intermediate_entry = l1e_empty();
     l2_pgentry_t l2e_content;
     l3_pgentry_t l3e_content;
-    int rc;
+    int rc, ret;
     unsigned int iommu_pte_flags = p2m_get_iommu_flags(p2mt);
     /*

* old_mfn and iommu_old_flags control possible flush/update needs on the

xen/arch/x86/mm/p2m-pt.c +17 -3
@@ -680,11 +680,25 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long
 gfn, mfn_t mfn,
         }
         else if ( iommu_pte_flags )
             for ( i = 0; i < (1UL << page_order); i++ )
-                iommu_map_page(p2m->domain, gfn + i, mfn_x(mfn) + i,
-                               iommu_pte_flags);
+            {
+                ret = iommu_map_page(p2m->domain, gfn + i, mfn_x(mfn) + i,
+                                     iommu_pte_flags);
+                if ( unlikely(ret) )
+                {
+                    while (i)
+                        iommu_unmap_page(p2m->domain, gfn + --i);
+
+                    rc = ret;
+                }
+            }
         else
             for ( i = 0; i < (1UL << page_order); i++ )
-                iommu_unmap_page(p2m->domain, gfn + i);
+            {
+                ret = iommu_unmap_page(p2m->domain, gfn + i);
+
+                if ( unlikely(ret) )
+                    rc = ret;
+            }
     }
 
     /*
xen/arch/x86/mm/p2m.c +9 -2
index b3fce1b..98450a4 100644
@@ -610,13 +610,20 @@ p2m_remove_page(struct p2m_domain *p2m, unsigned long
 gfn, unsigned long mfn,
     mfn_t mfn_return;
     p2m_type_t t;
     p2m_access_t a;
+    int ret = 0, rc;
 
     if ( !paging_mode_translate(p2m->domain) )
     {
         if ( need_iommu(p2m->domain) )
             for ( i = 0; i < (1 << page_order); i++ )
-                iommu_unmap_page(p2m->domain, mfn + i);
-        return 0;
+            {
+               rc = iommu_unmap_page(p2m->domain, mfn + i);
+
+               if ( unlikely(rc) )
+                   ret = rc;
+            }
+
+        return ret;
     }
 
     ASSERT(gfn_locked_by_me(p2m, gfn));
xen/drivers/passthrough/iommu.c +13 -2
index 850101b..c351209 100644
@@ -172,6 +172,8 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
     {
         struct page_info *page;
         unsigned int i = 0;
+        int ret, rc = 0;
+
         page_list_for_each ( page, &d->page_list )
         {
             unsigned long mfn = page_to_mfn(page);
@@ -182,10 +184,20 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
                  ((page->u.inuse.type_info & PGT_type_mask)
                   == PGT_writable_page) )
                 mapping |= IOMMUF_writable;
-            hd->platform_ops->map_page(d, gfn, mfn, mapping);
+
+            ret = hd->platform_ops->map_page(d, gfn, mfn, mapping);
+
+            if ( unlikely(ret) )
+                rc = ret;
+
             if ( !(i++ & 0xfffff) )
                 process_pending_softirqs();
         }
+
+        if ( rc )
+            printk(XENLOG_G_ERR
+                   "dom%d: IOMMU mapping is failed for hardware domain.",
+                   d->domain_id);
     }
 
     return hd->platform_ops->hwdom_init(d);
--
Quoted 1 line

1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#20 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

Quoted 10 lines · Kevin
Quoted 6 lines

From: Xu, Quan
Sent: Monday, April 18, 2016 10:00 PM

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

What do you mean by 'lighter weight"? Please clarify it.

Quoted 1 line
Quoted 11 lines
Quoted 3 lines

For the hardware domain, we do things on a best effort basis. When rollback is not feasible (in early initialization phase or trade-off of complexity), at least, unmap upon maps error or then throw out error

message.

remove 'or'. Based on next sentence, is above specific for IOMMU mapping?

Quoted 4 lines

IOMMU unmapping should perhaps continue despite an error, in an attempt to do best effort cleanup.

Could I enhance the commit log as below:
"""
If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight (at least errors need to be propagated).

IOMMU mapping breaks for an error, unmapping upon maps, throwing out error message and then reporting the error up the call trees. When rollback is not feasible (in early initialization phase or trade-off of complexity) for the hardware domain, we do things on a best effort basis, only throwing out error message.

IOMMU unmapping should perhaps continue despite an error, in an attempt to do best effort cleanup. """

I am still not sure whether we really need throw out error message for each IOMMU mapping or not. If yes, I will throw out error message for each IOMMU mapping in next v3.

Quoted 91 lines
Quoted 30 lines
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Jun Nakajima <[email protected]>
CC Kevin Tian <[email protected]>
CC George Dunlap <[email protected]>
---
 xen/arch/x86/mm.c               | 13 ++++++++-----
 xen/arch/x86/mm/p2m-ept.c       | 25 ++++++++++++++++++++++---
 xen/arch/x86/mm/p2m-pt.c        | 22 ++++++++++++++++++----
 xen/arch/x86/mm/p2m.c           | 11 +++++++++--
 xen/drivers/passthrough/iommu.c | 14 +++++++++++++-
 5 files changed, 70 insertions(+), 15 deletions(-)
xen/arch/x86/mm.c index renamed from xen/arch/x86/mm.c +0 -0

c997b53..5c4fb58 100644

xen/arch/x86/mm.c +1 -1
@@ -2467,7 +2467,7 @@ static int __get_page_type(struct page_info
 *page, unsigned long type,
                            int preemptible)  {
     unsigned long nx, x, y = page->u.inuse.type_info;
-    int rc = 0;
+    int rc = 0, ret = 0;
 
     ASSERT(!(type & ~(PGT_type_mask | PGT_pae_xen_l2)));
 

xen/arch/x86/mm.c static int __get_page_type(struct page_info · line 2582

Quoted 5 lines
xen/arch/x86/mm.c +0 -1
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info
 *page, unsigned long type,
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d,

page_to_mfn(page)));

xen/arch/x86/mm.c static int __get_page_type(struct page_info · line 2584

Quoted 4 lines
xen/arch/x86/mm.c +2 -1
+                ret = iommu_unmap_page(d, mfn_to_gmfn(d,
+ page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d,

page_to_mfn(page)),

xen/arch/x86/mm.c static int __get_page_type(struct page_info · line 2586

Quoted 2 lines
xen/arch/x86/mm.c +0 -2
-                               page_to_mfn(page),
-

IOMMUF_readable|IOMMUF_writable);

xen/arch/x86/mm.c static int __get_page_type(struct page_info · line 2585

Quoted 1 line
xen/arch/x86/mm.c +1 -0
+                ret = iommu_map_page(d, mfn_to_gmfn(d,

page_to_mfn(page)),

Quoted 34 lines
xen/arch/x86/mm.c +6 -0
+                                     page_to_mfn(page),
+
+ IOMMUF_readable|IOMMUF_writable);
         }
     }
@@ -2599,6 +2599,9 @@ static int __get_page_type(struct page_info
 *page, unsigned long type,
     if ( (x & PGT_partial) && !(nx & PGT_partial) )
         put_page(page);
 
+    if ( unlikely(ret) )
+        rc = ret;
+
     return rc;
 }
xen/arch/x86/mm/p2m-ept.c +1 -1
index 3cb6868..22c8d17 100644
@@ -665,7 +665,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned
 long gfn, mfn_t mfn,
     ept_entry_t *table, *ept_entry = NULL;
     unsigned long gfn_remainder = gfn;
     unsigned int i, target = order / EPT_TABLE_ORDER;
-    int ret, rc = 0;
+    int ret, err = 0, rc = 0;
     bool_t direct_mmio = (p2mt == p2m_mmio_direct);
     uint8_t ipat = 0;
     bool_t need_modify_vtd_table = 1; @@ -830,10 +830,26 @@ out:
         {
             if ( iommu_flags )
                 for ( i = 0; i < (1 << order); i++ )
Quoted 1 line

- iommu_map_page(d, gfn + i, mfn_x(mfn) + i,

iommu_flags);

xen/arch/x86/mm/p2m-ept.c out: · line 839

Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +8 -0
+                {
+                    ret = iommu_map_page(d, gfn + i, mfn_x(mfn) + i,
+ iommu_flags);
+
+                    if ( unlikely(ret) )
+                    {
+                        while (i)
+                            iommu_unmap_page(d, gfn + --i);
Quoted 5 lines

How about below?

while (i-- >= 0)

	iommu_unmap_page(d, gfn + i);

this modification is based on discussion rooted at http://lists.xenproject.org/archives/html/xen-devel/2016-03/msg01779.html
wait for Jan's decision.

Quoted 22 lines
Quoted 22 lines
xen/arch/x86/mm/p2m-ept.c +11 -1
+
+                        err = ret;
+                        break;
+                    }
+                }
             else
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_unmap_page(d, gfn + i);
+                {
+                    ret = iommu_unmap_page(d, gfn + i);
+
+                    if ( unlikely(ret) )
+                        err = ret;
+                }
         }
     }
@@ -849,6 +865,9 @@ out:
     if ( rc == 0 && p2m_is_hostp2m(p2m) )
         p2m_altp2m_propagate_change(d, _gfn(gfn), mfn, order, p2mt,
 p2ma);
 
Quoted 6 lines

xen/arch/x86/mm/p2m-ept.c out: · line 870

Quoted 3 lines
xen/arch/x86/mm/p2m-ept.c +3 -0
+    if ( unlikely(err) )
+        rc = err;
+

not sure we need three return values here: rc, ret, err...

I am afraid that we need three return values here.
As similar as George mentioned, we need to make sure that the altp2m gets updated when the hostp2m is updated, even if the IOMMU mapping or unmapping fail. if altp2m is enabled, rc cannot be non-zero here due to IOMMU mapping or unmapping, so I need another return value.

Quan

Quoted 105 lines

xen/arch/x86/mm/p2m-pt.c p2m_pt_set_entry(struct p2m_domain *p2m,

Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +0 -0
     return rc;
 }
xen/arch/x86/mm/p2m-pt.c index renamed from xen/arch/x86/mm/p2m-pt.c +0 -0

3d80612..db4257a 100644

xen/arch/x86/mm/p2m-pt.c +0 -0
@@ -498,7 +498,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m,

unsigned

Quoted 10 lines
xen/arch/x86/mm/p2m-pt.c +1 -1
 long gfn, mfn_t mfn,
     l1_pgentry_t intermediate_entry = l1e_empty();
     l2_pgentry_t l2e_content;
     l3_pgentry_t l3e_content;
-    int rc;
+    int rc, ret;
     unsigned int iommu_pte_flags = p2m_get_iommu_flags(p2mt);
     /*

* old_mfn and iommu_old_flags control possible flush/update
needs on the @@ -680,11 +680,25 @@ p2m_pt_set_entry(struct

p2m_domain

xen/arch/x86/mm/p2m-pt.c p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,

Quoted 8 lines

*p2m, unsigned long gfn, mfn_t mfn,

         }
         else if ( iommu_pte_flags )
             for ( i = 0; i < (1UL << page_order); i++ )
xen/arch/x86/mm/p2m-pt.c +2 -2
-                iommu_map_page(p2m->domain, gfn + i, mfn_x(mfn) + i,
-                               iommu_pte_flags);
+            {
+                ret = iommu_map_page(p2m->domain, gfn + i,

mfn_x(mfn) + i,

xen/arch/x86/mm/p2m.c p2m_remove_page(struct p2m_domain *p2m,

Quoted 26 lines
xen/arch/x86/mm/p2m-pt.c +15 -1
+                                     iommu_pte_flags);
+                if ( unlikely(ret) )
+                {
+                    while (i)
+                        iommu_unmap_page(p2m->domain, gfn + --i);
+
+                    rc = ret;
+                }
+            }
         else
             for ( i = 0; i < (1UL << page_order); i++ )
-                iommu_unmap_page(p2m->domain, gfn + i);
+            {
+                ret = iommu_unmap_page(p2m->domain, gfn + i);
+
+                if ( unlikely(ret) )
+                    rc = ret;
+            }
     }
 
     /*
xen/arch/x86/mm/p2m.c index renamed from xen/arch/x86/mm/p2m.c +0 -0

b3fce1b..98450a4 100644

xen/arch/x86/mm/p2m.c +0 -0
@@ -610,13 +610,20 @@ p2m_remove_page(struct p2m_domain *p2m,

unsigned

xen/drivers/passthrough/iommu.c void __hwdom_init iommu_hwdom_init(struct

Quoted 28 lines
xen/arch/x86/mm/p2m.c +9 -2
 long gfn, unsigned long mfn,
     mfn_t mfn_return;
     p2m_type_t t;
     p2m_access_t a;
+    int ret = 0, rc;
 
     if ( !paging_mode_translate(p2m->domain) )
     {
         if ( need_iommu(p2m->domain) )
             for ( i = 0; i < (1 << page_order); i++ )
-                iommu_unmap_page(p2m->domain, mfn + i);
-        return 0;
+            {
+               rc = iommu_unmap_page(p2m->domain, mfn + i);
+
+               if ( unlikely(rc) )
+                   ret = rc;
+            }
+
+        return ret;
     }
 
     ASSERT(gfn_locked_by_me(p2m, gfn)); diff --git

a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 850101b..c351209 100644

xen/drivers/passthrough/iommu.c +0 -0
@@ -172,6 +172,8 @@ void __hwdom_init iommu_hwdom_init(struct

domain *d)

xen/drivers/passthrough/iommu.c void __hwdom_init iommu_hwdom_init(struct domain *d)

Quoted 8 lines
xen/drivers/passthrough/iommu.c +2 -0
     {
         struct page_info *page;
         unsigned int i = 0;
+        int ret, rc = 0;
+
         page_list_for_each ( page, &d->page_list )
         {
             unsigned long mfn = page_to_mfn(page); @@ -182,10

+184,20

Quoted 11 lines

@@ void __hwdom_init iommu_hwdom_init(struct domain *d)

                  ((page->u.inuse.type_info & PGT_type_mask)
                   == PGT_writable_page) )
                 mapping |= IOMMUF_writable;
xen/drivers/passthrough/iommu.c +6 -1
-            hd->platform_ops->map_page(d, gfn, mfn, mapping);
+
+            ret = hd->platform_ops->map_page(d, gfn, mfn, mapping);
+
+            if ( unlikely(ret) )
+                rc = ret;
+
Quoted 14 lines

xen/drivers/passthrough/iommu.c void __hwdom_init iommu_hwdom_init(struct domain *d)

Quoted 7 lines
             if ( !(i++ & 0xfffff) )
                 process_pending_softirqs();
         }
xen/drivers/passthrough/iommu.c +4 -0
+
+        if ( rc )
+            printk(XENLOG_G_ERR
+                   "dom%d: IOMMU mapping is failed for hardware

domain.",

Quoted 6 lines
+                   d->domain_id);
     }

     return hd->platform_ops->hwdom_init(d);

--
1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#21 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

Quoted 28 lines

From: Xu, Quan
Sent: Wednesday, April 20, 2016 1:27 PM

Quoted 10 lines · Kevin
Quoted 6 lines

From: Xu, Quan
Sent: Monday, April 18, 2016 10:00 PM

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

What do you mean by 'lighter weight"? Please clarify it.

Quoted 1 line
Quoted 11 lines
Quoted 3 lines

For the hardware domain, we do things on a best effort basis. When rollback is not feasible (in early initialization phase or trade-off of complexity), at least, unmap upon maps error or then throw out error

message.

remove 'or'. Based on next sentence, is above specific for IOMMU mapping?

Quoted 4 lines

IOMMU unmapping should perhaps continue despite an error, in an attempt to do best effort cleanup.

Quoted 6 lines

Could I enhance the commit log as below:
"""
If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed,
treated as a fatal error. Rollback can be lighter weight (at least errors need to be propagated).

Still not clear about 'lighter weight'. Then what is the 'heavier weight' side then? Isn't "at least errors need to be propagated" exactly what 'rollback' means?

Quoted 7 lines

IOMMU mapping breaks for an error, unmapping upon maps, throwing out error message and then reporting
the error up the call trees. When rollback is not feasible (in early initialization phase or trade-off of complexity)
for the hardware domain, we do things on a best effort basis, only throwing out error message.

If above elaborates what earlier 'lighter weight" means, then please just say a best-effort rollack.

Quoted 9 lines

IOMMU unmapping should perhaps continue despite an error, in an attempt to do best effort cleanup.
"""

I am still not sure whether we really need throw out error message for each IOMMU mapping or not.
If yes, I will throw out error message for each IOMMU mapping in next v3.

I'm not sure about your question here. Have to judge based on specific case.

Quoted 16 lines
Quoted 16 lines
Quoted 4 lines
         {
             if ( iommu_flags )
                 for ( i = 0; i < (1 << order); i++ )

- iommu_map_page(d, gfn + i, mfn_x(mfn) + i,

iommu_flags);

xen/arch/x86/mm/p2m-ept.c out: · line 839

Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +8 -0
+                {
+                    ret = iommu_map_page(d, gfn + i, mfn_x(mfn) + i,
+ iommu_flags);
+
+                    if ( unlikely(ret) )
+                    {
+                        while (i)
+                            iommu_unmap_page(d, gfn + --i);

How about below?

Quoted 7 lines
Quoted 3 lines

while (i-- >= 0)

	iommu_unmap_page(d, gfn + i);

this modification is based on discussion rooted at
http://lists.xenproject.org/archives/html/xen-devel/2016-03/msg01779.html
wait for Jan's decision.

Either way is OK. 'gfn + --I' just looks not very readable to me.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#22 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

In reply to Xu, Quan
Quoted 3 lines
Quoted 1 line
Quoted 1 line

"Xu, Quan" <[email protected]> 04/20/16 7:29 AM >>>

I am still not sure whether we really need throw out error message for each IOMMU mapping or not. If yes, I will throw out error message for each IOMMU mapping in next v3.

Ideally not, if it's a batch that it failing, The question just is whether at the point you issue the error message you can know another got already emitted. In no case must this lead to spamming of the console originating from an unprivileged domain.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c +4 -0
+                    if ( unlikely(ret) )
+                    {
+                        while (i)
+                            iommu_unmap_page(d, gfn + --i);
Quoted 7 lines
Quoted 4 lines

How about below?

while (i-- >= 0)

	iommu_unmap_page(d, gfn + i);

this modification is based on discussion rooted at http://lists.xenproject.org/archives/html/xen-devel/2016-03/msg01779.html
wait for Jan's decision.

But did you really _follow_ that discussion? The adjustment done by that patch was specifically not deemed good, so the shape Kevin suggests is in line with the outcome of that discussion (except that I'd suggest omitting the ">= 0", the more that i at least ought to be unsigned here).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#23 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

Quoted 21 lines · On April 20, 2016 2:12pm, <[email protected] > wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Xu, Quan" <[email protected]> 04/20/16 7:29 AM >>>

Ideally not, if it's a batch that it failing, The question just is whether at the point you issue the error message you can know another got already emitted. In no case must this lead to spamming of the console originating from an unprivileged domain.

Quoted 7 lines
Quoted 7 lines

xen/arch/x86/mm/p2m-ept.c out: · line 839

Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c +4 -0
+                    if ( unlikely(ret) )
+                    {
+                        while (i)
+                            iommu_unmap_page(d, gfn + --i);

How about below?

Quoted 7 lines
Quoted 2 lines

while (i-- >= 0)

	iommu_unmap_page(d, gfn + i);

this modification is based on discussion rooted at
http://lists.xenproject.org/archives/html/xen-devel/2016-03/msg01779.ht
ml
wait for Jan's decision.

Quoted 5 lines

But did you really _follow_ that discussion? The adjustment done by that patch was specifically not deemed good, so the shape Kevin suggests is in line with the outcome of that discussion (except that I'd suggest omitting the ">= 0", the more that i at least ought to be unsigned here).

Based on your suggestions, I will fix it as below:

+while ( i-- )
+ iommu_unmap_page(d, gfn + i);

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#24 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

In reply to Quan Xu
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/arch/x86/mm.c +5 -5
@@ -2467,7 +2467,7 @@ static int __get_page_type(struct page_info *page, unsigned long type,
                            int preemptible)
 {
     unsigned long nx, x, y = page->u.inuse.type_info;
-    int rc = 0;
+    int rc = 0, ret = 0;
 
     ASSERT(!(type & ~(PGT_type_mask | PGT_pae_xen_l2)));
 
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info *page, unsigned long type,
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                ret = iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+                ret = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                     page_to_mfn(page),
+                                     IOMMUF_readable|IOMMUF_writable);
         }
     }
 

xen/arch/x86/mm.c static int __get_page_type(struct page_info *page, unsigned long type, · line 2603

Quoted 5 lines
xen/arch/x86/mm.c +2 -0
@@ -2599,6 +2599,9 @@ static int __get_page_type(struct page_info *page, unsigned long type,
     if ( (x & PGT_partial) && !(nx & PGT_partial) )
         put_page(page);
 
+    if ( unlikely(ret) )
+        rc = ret;

Please don't overwrite the more relevant "rc" value in situations like this in case that is already non-zero. In this specific case you can actually get away without introducing a second error code variable, since the only place rc gets altered is between the two hunks above, and overwriting the rc value from map/unmap is then exactly what we want (but I'd much appreciate if you added a comment to this effect).

xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, · line 668

Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +1 -1
@@ -665,7 +665,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     ept_entry_t *table, *ept_entry = NULL;
     unsigned long gfn_remainder = gfn;
     unsigned int i, target = order / EPT_TABLE_ORDER;
-    int ret, rc = 0;
+    int ret, err = 0, rc = 0;

Just like Kevin, and despite your reply to him I do not see the need fir the 3rd error indicator variable here:

xen/arch/x86/mm/p2m-ept.c out: · line 838

Quoted 11 lines
xen/arch/x86/mm/p2m-ept.c +6 -1
@@ -830,10 +830,26 @@ out:
         {
             if ( iommu_flags )
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_map_page(d, gfn + i, mfn_x(mfn) + i, iommu_flags);
+                {
+                    ret = iommu_map_page(d, gfn + i, mfn_x(mfn) + i, iommu_flags);
+
+                    if ( unlikely(ret) )
+                    {
+                        while (i)

while ( i-- )

Quoted 6 lines
xen/arch/x86/mm/p2m-ept.c +6 -0
+                            iommu_unmap_page(d, gfn + --i);
+
+                        err = ret;
+                        break;
+                    }
+                }

xen/arch/x86/mm/p2m-ept.c out: · line 853

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +6 -1
             else
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_unmap_page(d, gfn + i);
+                {
+                    ret = iommu_unmap_page(d, gfn + i);
+
+                    if ( unlikely(ret) )
+                        err = ret;
+                }
         }

You can simply utilize that rc is zero upon entering this if(), clearing it back to zero here.

xen/arch/x86/mm/p2m-ept.c out: · line 869

Quoted 6 lines
xen/arch/x86/mm/p2m-ept.c +2 -0
@@ -849,6 +865,9 @@ out:
     if ( rc == 0 && p2m_is_hostp2m(p2m) )
         p2m_altp2m_propagate_change(d, _gfn(gfn), mfn, order, p2mt, p2ma);
 
+    if ( unlikely(err) )
+        rc = err;

Same comment as for mm.c (and also for mm/p2m-pt.c and mm/p2m.c below, albeit the impact there is limited - the only difference is whether to return first or last error encountered, but I'd still prefer the first one to be used, as for a crashed domain later errors may end up being kind of meaningless wrt what caused the domain to get crashed).

Quoted 9 lines
xen/arch/x86/mm/p2m-ept.c +4 -1
@@ -182,10 +184,20 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
                  ((page->u.inuse.type_info & PGT_type_mask)
                   == PGT_writable_page) )
                 mapping |= IOMMUF_writable;
-            hd->platform_ops->map_page(d, gfn, mfn, mapping);
+
+            ret = hd->platform_ops->map_page(d, gfn, mfn, mapping);
+
+            if ( unlikely(ret) )

xen/arch/x86/mm/p2m-ept.c void __hwdom_init iommu_hwdom_init(struct domain *d) · line 200

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +7 -0
+                rc = ret;
+
             if ( !(i++ & 0xfffff) )
                 process_pending_softirqs();
         }
+
+        if ( rc )
+            printk(XENLOG_G_ERR
+                   "dom%d: IOMMU mapping is failed for hardware domain.",
+                   d->domain_id);

Leaving the admin / developer with no indication of at least one specific case of a page where a failure occurred. As said in various places before: Log messages should provide useful information for at least getting started at investigating the issue, without first of all having to further instrument the code.

In any event the "is" should be dropped from the text.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#25 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

Quoted 39 lines · Jan Beulich

xen/arch/x86/mm.c static int __get_page_type(struct page_info

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/arch/x86/mm.c +0 -0
@@ -2467,7 +2467,7 @@ static int __get_page_type(struct page_info

*page, unsigned long type,

xen/arch/x86/mm.c static int __get_page_type(struct page_info

Quoted 8 lines
xen/arch/x86/mm.c +1 -1
                            int preemptible)  {
     unsigned long nx, x, y = page->u.inuse.type_info;
-    int rc = 0;
+    int rc = 0, ret = 0;
 
     ASSERT(!(type & ~(PGT_type_mask | PGT_pae_xen_l2)));
 
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info

*page, unsigned long type,

xen/arch/x86/mm.c static int __get_page_type(struct page_info

Quoted 18 lines
xen/arch/x86/mm.c +6 -4
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                ret = iommu_unmap_page(d, mfn_to_gmfn(d,
+ page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+                ret = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                     page_to_mfn(page),
+
+ IOMMUF_readable|IOMMUF_writable);
         }
     }
@@ -2599,6 +2599,9 @@ static int __get_page_type(struct page_info

*page, unsigned long type,

xen/arch/x86/mm.c static int __get_page_type(struct page_info · line 2603

Quoted 5 lines
xen/arch/x86/mm.c +2 -0
     if ( (x & PGT_partial) && !(nx & PGT_partial) )
         put_page(page);
 
+    if ( unlikely(ret) )
+        rc = ret;
Quoted 7 lines

Please don't overwrite the more relevant "rc" value in situations like this in case that is already non-zero. In this specific case you can actually get away without introducing a second error code variable, since the only place rc gets altered is between the two hunks above, and overwriting the rc value from map/unmap is then exactly what we want (but I'd much appreciate if you added a comment to this effect).

Make sense.
I hope I have got your point.. then, I will modify it as below:

xen/arch/x86/mm.c +6 -4
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info *page, unsigned long type,
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                rc = iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+                rc = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                    page_to_mfn(page),
+                                    IOMMUF_readable|IOMMUF_writable);
         }
     }
 
@@ -2593,6 +2593,8 @@ static int __get_page_type(struct page_info *page, unsigned long type,
             page->nr_validated_ptes = 0;
             page->partial_pte = 0;
         }
+
+        /* Overwrite the rc value from IOMMU map and unmap. */
         rc = alloc_page_type(page, type, preemptible);
     }
 

btw, I am clumsy at comment, I'd be pleased if you could help me enhance it.

Quoted 4 lines

xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, unsigned

Quoted 3 lines
xen/arch/x86/mm/p2m-ept.c +0 -0
@@ -665,7 +665,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned

long gfn, mfn_t mfn,

Quoted 9 lines

xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, unsigned · line 668

Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +1 -1
     ept_entry_t *table, *ept_entry = NULL;
     unsigned long gfn_remainder = gfn;
     unsigned int i, target = order / EPT_TABLE_ORDER;
-    int ret, rc = 0;
+    int ret, err = 0, rc = 0;

Just like Kevin, and despite your reply to him I do not see the need fir the 3rd error indicator variable here:

Agreed.

Quoted 27 lines

xen/arch/x86/mm/p2m-ept.c void __hwdom_init iommu_hwdom_init(struct

Quoted 1 line
xen/arch/x86/mm/p2m-ept.c +0 -0
@@ -182,10 +184,20 @@ void __hwdom_init iommu_hwdom_init(struct

domain *d)

Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +4 -1
                  ((page->u.inuse.type_info & PGT_type_mask)
                   == PGT_writable_page) )
                 mapping |= IOMMUF_writable;
-            hd->platform_ops->map_page(d, gfn, mfn, mapping);
+
+            ret = hd->platform_ops->map_page(d, gfn, mfn, mapping);
+
+            if ( unlikely(ret) )

xen/arch/x86/mm/p2m-ept.c void __hwdom_init iommu_hwdom_init(struct · line 200

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +7 -0
+                rc = ret;
+
             if ( !(i++ & 0xfffff) )
                 process_pending_softirqs();
         }
+
+        if ( rc )
+            printk(XENLOG_G_ERR
+                   "dom%d: IOMMU mapping is failed for hardware domain.",
+                   d->domain_id);

Leaving the admin / developer with no indication of at least one specific case of a page where a failure occurred. As said in various places before: Log messages should provide useful information for at least getting started at investigating the issue, without first of all having to further instrument the code.

Quoted 2 lines

In any event the "is" should be dropped from the text.

What about:

+ if ( rc )
+ printk(XENLOG_WARNING
+ "iommu_hwdom_init: IOMMU mapping failed for dom%d.",
+ d->domain_id);

If this is still not what you want, could you help me enhance it and I can follow it as a pattern. Sorry to bother you with such a case.

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#26 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 27.04.16 at 10:49, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich

xen/arch/x86/mm.c static int __get_page_type(struct page_info

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/arch/x86/mm.c +0 -0
@@ -2467,7 +2467,7 @@ static int __get_page_type(struct page_info

*page, unsigned long type,

xen/arch/x86/mm.c static int __get_page_type(struct page_info

Quoted 8 lines
xen/arch/x86/mm.c +1 -1
                            int preemptible)  {
     unsigned long nx, x, y = page->u.inuse.type_info;
-    int rc = 0;
+    int rc = 0, ret = 0;
 
     ASSERT(!(type & ~(PGT_type_mask | PGT_pae_xen_l2)));
 
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info

*page, unsigned long type,

xen/arch/x86/mm.c static int __get_page_type(struct page_info

Quoted 18 lines
xen/arch/x86/mm.c +6 -4
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                ret = iommu_unmap_page(d, mfn_to_gmfn(d,
+ page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+                ret = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                     page_to_mfn(page),
+
+ IOMMUF_readable|IOMMUF_writable);
         }
     }
@@ -2599,6 +2599,9 @@ static int __get_page_type(struct page_info

*page, unsigned long type,

Quoted 7 lines

xen/arch/x86/mm.c static int __get_page_type(struct page_info · line 2603

Quoted 5 lines
xen/arch/x86/mm.c +2 -0
     if ( (x & PGT_partial) && !(nx & PGT_partial) )
         put_page(page);
 
+    if ( unlikely(ret) )
+        rc = ret;

Please don't overwrite the more relevant "rc" value in situations like this

in

Quoted 1 line

case that is already non-zero. In this specific case you can actually get

away

Quoted 1 line

without introducing a second error code variable, since the only place rc

gets

Quoted 8 lines
Quoted 4 lines

altered is between the two hunks above, and overwriting the rc value from map/unmap is then exactly what we want (but I'd much appreciate if you added a comment to this effect).

Make sense.
I hope I have got your point.. then, I will modify it as below:

But I screwed it up. Looking at it as you have it:

Quoted 20 lines
xen/arch/x86/mm.c +4 -4
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info *page, 
 unsigned long type,
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                rc = iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+                rc = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                    page_to_mfn(page),
+                                    IOMMUF_readable|IOMMUF_writable);
         }
     }

xen/arch/x86/mm.c static int __get_page_type(struct page_info *page, unsigned long type, · line 2599

Quoted 7 lines
xen/arch/x86/mm.c +2 -0
@@ -2593,6 +2593,8 @@ static int __get_page_type(struct page_info *page, unsigned long type,
             page->nr_validated_ptes = 0;
             page->partial_pte = 0;
         }
+
+        /* Overwrite the rc value from IOMMU map and unmap. */
         rc = alloc_page_type(page, type, preemptible);
     }

... it is clear that this is wrong: You'd now also discard an error from the map/unmap with possible success coming back here. I.e. you want to overwrite the earlier rc only when you get a non-zero value back here.

Quoted 1 line

btw, I am clumsy at comment, I'd be pleased if you could help me enhance it.

With the above, the comment is not needed anymore.

Quoted 9 lines

What about:

xen/arch/x86/mm.c +4 -0
+        if ( rc )
+            printk(XENLOG_WARNING
+                   "iommu_hwdom_init: IOMMU mapping failed for dom%d.",
+                   d->domain_id);

If this is still not what you want, could you help me enhance it and I can follow it as a pattern. Sorry to bother you with such a case.

Looks okay.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#27 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

Quoted 92 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 27.04.16 at 10:49, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich

xen/arch/x86/mm.c static int __get_page_type(struct page_info

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/arch/x86/mm.c +0 -0
@@ -2467,7 +2467,7 @@ static int __get_page_type(struct page_info

*page, unsigned long type,

xen/arch/x86/mm.c static int __get_page_type(struct page_info

Quoted 8 lines
xen/arch/x86/mm.c +1 -1
                            int preemptible)  {
     unsigned long nx, x, y = page->u.inuse.type_info;
-    int rc = 0;
+    int rc = 0, ret = 0;
 
     ASSERT(!(type & ~(PGT_type_mask | PGT_pae_xen_l2)));
 
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info

*page, unsigned long type,

Quoted 11 lines
Quoted 11 lines

xen/arch/x86/mm.c static int __get_page_type(struct page_info · line 2584

Quoted 11 lines
xen/arch/x86/mm.c +3 -4
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                ret = iommu_unmap_page(d, mfn_to_gmfn(d,
+ page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+                ret = iommu_map_page(d, mfn_to_gmfn(d,

page_to_mfn(page)),

Quoted 23 lines
Quoted 8 lines

xen/arch/x86/mm.c static int __get_page_type(struct page_info

Quoted 7 lines
xen/arch/x86/mm.c +3 -0
+                                     page_to_mfn(page),
+
+ IOMMUF_readable|IOMMUF_writable);
         }
     }
@@ -2599,6 +2599,9 @@ static int __get_page_type(struct page_info

*page, unsigned long type,

Quoted 8 lines

xen/arch/x86/mm.c static int __get_page_type(struct page_info · line 2603

Quoted 5 lines
xen/arch/x86/mm.c +2 -0
     if ( (x & PGT_partial) && !(nx & PGT_partial) )
         put_page(page);
 
+    if ( unlikely(ret) )
+        rc = ret;

Please don't overwrite the more relevant "rc" value in situations like this

in

Quoted 2 lines

case that is already non-zero. In this specific case you can actually get

away

Quoted 2 lines

without introducing a second error code variable, since the only place rc

gets

Quoted 8 lines
Quoted 4 lines

altered is between the two hunks above, and overwriting the rc value from map/unmap is then exactly what we want (but I'd much appreciate if you added a comment to this effect).

Make sense.
I hope I have got your point.. then, I will modify it as below:

But I screwed it up. Looking at it as you have it:

xen/arch/x86/mm.c static int __get_page_type(struct page_info

Quoted 21 lines
xen/arch/x86/mm.c +5 -4
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info
 *page, unsigned long type,
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                rc = iommu_unmap_page(d, mfn_to_gmfn(d,
+ page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+                rc = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                    page_to_mfn(page),
+                                    IOMMUF_readable|IOMMUF_writable);
         }
     }
@@ -2593,6 +2593,8 @@ static int __get_page_type(struct page_info

*page, unsigned long type,

xen/arch/x86/mm.c static int __get_page_type(struct page_info · line 2599

Quoted 7 lines
xen/arch/x86/mm.c +2 -0
             page->nr_validated_ptes = 0;
             page->partial_pte = 0;
         }
+
+        /* Overwrite the rc value from IOMMU map and unmap. */
         rc = alloc_page_type(page, type, preemptible);
     }
Quoted 4 lines

... it is clear that this is wrong: You'd now also discard an error from the map/unmap with possible success coming back here. I.e. you want to overwrite the earlier rc only when you get a non-zero value back here.

A little bit confused.
I need to introduce a second error code variable for this point, right?
Also I shouldn't overwrite the relevant 'rc' value in case that is already non-zero.

I want to send out my modification for this point, making sure we are on the same page, even I may be still wrong. Then this code is:

xen/arch/x86/mm.c +8 -5
@@ -2467,7 +2467,7 @@ static int __get_page_type(struct page_info *page, unsigned long type,
                            int preemptible)
 {
     unsigned long nx, x, y = page->u.inuse.type_info;
-    int rc = 0;
+    int rc = 0, ret = 0;
 
     ASSERT(!(type & ~(PGT_type_mask | PGT_pae_xen_l2)));
 
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info *page, unsigned long type,
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                ret = iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+                ret = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                     page_to_mfn(page),
+                                     IOMMUF_readable|IOMMUF_writable);
         }
     }
 
@@ -2594,6 +2594,9 @@ static int __get_page_type(struct page_info *page, unsigned long type,
             page->partial_pte = 0;
         }
         rc = alloc_page_type(page, type, preemptible);
+
+        if ( !rc )
+            rc = ret;
     }
 
     if ( (x & PGT_partial) && !(nx & PGT_partial) )
Quoted 4 lines
Quoted 1 line

btw, I am clumsy at comment, I'd be pleased if you could help me enhance it.

With the above, the comment is not needed anymore.

I will drop this comment.

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#28 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 27.04.16 at 15:10, <[email protected]> wrote:

Then this code is:

xen/arch/x86/mm.c +5 -5
@@ -2467,7 +2467,7 @@ static int __get_page_type(struct page_info *page, unsigned long type,
                            int preemptible)
 {
     unsigned long nx, x, y = page->u.inuse.type_info;
-    int rc = 0;
+    int rc = 0, ret = 0;
 
     ASSERT(!(type & ~(PGT_type_mask | PGT_pae_xen_l2)));
 
@@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info *page, unsigned long type,
         if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
         {
             if ( (x & PGT_type_mask) == PGT_writable_page )
-                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                ret = iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+                ret = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                     page_to_mfn(page),
+                                     IOMMUF_readable|IOMMUF_writable);
         }
     }
 

xen/arch/x86/mm.c static int __get_page_type(struct page_info *page, unsigned long type, · line 2602

Quoted 9 lines
xen/arch/x86/mm.c +3 -0
@@ -2594,6 +2594,9 @@ static int __get_page_type(struct page_info *page, unsigned long type,
             page->partial_pte = 0;
         }
         rc = alloc_page_type(page, type, preemptible);
+
+        if ( !rc )
+            rc = ret;
     }
 
     if ( (x & PGT_partial) && !(nx & PGT_partial) )

Looks okay now.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#29 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

In reply to Quan Xu
Quoted 4 lines · Quan Xu

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

Quoted 8 lines

For the hardware domain, we do things on a best effort basis. When rollback is not feasible (in early initialization phase or trade-off of complexity), at least, unmap upon maps error or then throw out error message.

IOMMU unmapping should perhaps continue despite an error, in an attempt to do best effort cleanup.

FWIW, looking through this I think Jan and Kevin covered everything I would have brought up.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#30 lore raw

Re: [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

Quoted 10 lines · George Dunlap
Quoted 7 lines · Quan Xu

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

For the hardware domain, we do things on a best effort basis. When rollback is not feasible (in early initialization phase or trade-off of complexity), at least, unmap upon maps error or then throw out error

message.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

IOMMU unmapping should perhaps continue despite an error, in an attempt to do best effort cleanup.

FWIW, looking through this I think Jan and Kevin covered everything I would have brought up.

George, thanks for your attention. Your comments as always are greatly appreciated too. :) Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#31 lore raw

PATCH v2 4/11 grant_table: avoid unnecessary work during grant table unmapping

In reply to Quan Xu

While grant table is unmapping, the domain (with the exception of the hardware domain) may be crashed due to IOMMU mapping and unmapping failures, and then it is unnecessary to flush specified CPUs' TLBs.

CC Ian Jackson <[email protected]>
CC Jan Beulich <[email protected]>
CC Keir Fraser <[email protected]>
CC Tim Deegan <[email protected]>
---
 xen/common/grant_table.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
xen/common/grant_table.c +6 -4
index 8b22299..1801fe9 100644
@@ -1366,8 +1366,9 @@ gnttab_unmap_grant_ref(
      
     return 0;
 
-fault:
-    gnttab_flush_tlb(current->domain);
+ fault:
+    if ( current->domain->is_shut_down )
+        gnttab_flush_tlb(current->domain);
 
     for ( i = 0; i < partial_done; i++ )
         __gnttab_unmap_common_complete(&(common[i]));
@@ -1429,8 +1430,9 @@ gnttab_unmap_and_replace(
 
     return 0;
 
-fault:
-    gnttab_flush_tlb(current->domain);
+ fault:
+    if ( current->domain->is_shut_down )
+        gnttab_flush_tlb(current->domain);
 
     for ( i = 0; i < partial_done; i++ )
         __gnttab_unmap_common_complete(&(common[i]));
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#32 lore raw

Re: [PATCH v2 04/11] grant_table: avoid unnecessary work during grant table unmapping

Quoted 4 lines

From: Quan Xu
Sent: Monday, April 18, 2016 10:00 PM

While grant table is unmapping, the domain (with the exception of the

unmapping -> unmapped.

Quoted 2 lines

hardware domain) may be crashed due to IOMMU mapping and unmapping failures, and then it is unnecessary to flush specified CPUs' TLBs.

Above description is not complete. You said "with the exception of the hardware domain". Then people will ask whether 'unnecessary' is also true for hardware domain (if not restriction for hardware domain to invoke those interfaces).

Quoted 43 lines
CC Ian Jackson <[email protected]>
CC Jan Beulich <[email protected]>
CC Keir Fraser <[email protected]>
CC Tim Deegan <[email protected]>
---
 xen/common/grant_table.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
xen/common/grant_table.c +6 -5
index 8b22299..1801fe9 100644
@@ -1366,8 +1366,9 @@ gnttab_unmap_grant_ref(
 
     return 0;
 
-fault:
-    gnttab_flush_tlb(current->domain);
+ fault:
+    if ( current->domain->is_shut_down )
+        gnttab_flush_tlb(current->domain);
 
     for ( i = 0; i < partial_done; i++ )
         __gnttab_unmap_common_complete(&(common[i]));
@@ -1429,8 +1430,9 @@ gnttab_unmap_and_replace(
 
     return 0;
 
-fault:
-    gnttab_flush_tlb(current->domain);
+ fault:
+    if ( current->domain->is_shut_down )
+        gnttab_flush_tlb(current->domain);
 
     for ( i = 0; i < partial_done; i++ )
         __gnttab_unmap_common_complete(&(common[i]));
--

1.9.1

Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#33 lore raw

Re: [PATCH v2 04/11] grant_table: avoid unnecessary work during grant table unmapping

Quoted 7 lines · Kevin
Quoted 4 lines

From: Quan Xu
Sent: Monday, April 18, 2016 10:00 PM

While grant table is unmapping, the domain (with the exception of the

unmapping -> unmapped.

A slightly different take, IMO the hypercall is not returned, so it is DOING.

Quoted 8 lines
Quoted 2 lines

hardware domain) may be crashed due to IOMMU mapping and unmapping failures, and then it is unnecessary to flush specified CPUs' TLBs.

Above description is not complete. You said "with the exception of the hardware domain". Then people will ask whether 'unnecessary'
is also true for hardware domain (if not restriction for hardware domain to invoke those interfaces).

Make sense.
Could I only drop '(with the exception of the hardware domain)'?

Quoted 43 lines
Quoted 43 lines
CC Ian Jackson <[email protected]>
CC Jan Beulich <[email protected]>
CC Keir Fraser <[email protected]>
CC Tim Deegan <[email protected]>
---
 xen/common/grant_table.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
xen/common/grant_table.c index renamed from xen/common/grant_table.c +0 -0

8b22299..1801fe9 100644

xen/common/grant_table.c +6 -5
@@ -1366,8 +1366,9 @@ gnttab_unmap_grant_ref(
 
     return 0;
 
-fault:
-    gnttab_flush_tlb(current->domain);
+ fault:
+    if ( current->domain->is_shut_down )
+        gnttab_flush_tlb(current->domain);
 
     for ( i = 0; i < partial_done; i++ )
         __gnttab_unmap_common_complete(&(common[i]));
@@ -1429,8 +1430,9 @@ gnttab_unmap_and_replace(
 
     return 0;
 
-fault:
-    gnttab_flush_tlb(current->domain);
+ fault:
+    if ( current->domain->is_shut_down )
+        gnttab_flush_tlb(current->domain);
 
     for ( i = 0; i < partial_done; i++ )
         __gnttab_unmap_common_complete(&(common[i]));
--

1.9.1

Quoted 4 lines
Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#34 lore raw

Re: [PATCH v2 04/11] grant_table: avoid unnecessary work during grant table unmapping

Quoted 7 lines

From: Xu, Quan
Sent: Tuesday, April 19, 2016 9:28 PM

Quoted 3 lines · Kevin
Quoted 3 lines

From: Quan Xu
Sent: Monday, April 18, 2016 10:00 PM

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

While grant table is unmapping, the domain (with the exception of the

unmapping -> unmapped.

A slightly different take, IMO the hypercall is not returned, so it is DOING.

More accurately you might want to say "When a granted page is being unmapped".

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

hardware domain) may be crashed due to IOMMU mapping and unmapping failures, and then it is unnecessary to flush specified CPUs' TLBs.

Quoted 9 lines
Quoted 5 lines

Above description is not complete. You said "with the exception of the hardware domain". Then people will ask whether 'unnecessary'
is also true for hardware domain (if not restriction for hardware domain to invoke those interfaces).

Make sense.
Could I only drop '(with the exception of the hardware domain)'?

Still didn't get the rationale here. After another look at the patch, actually I'm even not sure how the change is related to the purpose of this patch series. Also the change is opposite to your comment - you limit flush to crashed domain instead:

Quoted 5 lines

xen/common/grant_table.c gnttab_unmap_grant_ref( · line 1371

Quoted 5 lines
xen/common/grant_table.c +3 -2
-fault:
-    gnttab_flush_tlb(current->domain);
+ fault:
+    if ( current->domain->is_shut_down )
+        gnttab_flush_tlb(current->domain);

Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#35 lore raw

Re: [PATCH v2 04/11] grant_table: avoid unnecessary work during grant table unmapping

In reply to Quan Xu

xen/common/grant_table.c gnttab_unmap_grant_ref( · line 1371

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/common/grant_table.c +3 -2
@@ -1366,8 +1366,9 @@ gnttab_unmap_grant_ref(
 
     return 0;
 
-fault:
-    gnttab_flush_tlb(current->domain);
+ fault:
+    if ( current->domain->is_shut_down )
+        gnttab_flush_tlb(current->domain);

First of all: Is avoiding this really all that useful? You don't avoid further work in any of the earlier patches. I.e. not the least for consistency reasons I'd suggest dropping this patch.

And then, besides the condition being inverted as Kevin has already pointed out, I think you mean ->is_shutting_down, not ->is_shut_down.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#36 lore raw

Re: [PATCH v2 04/11] grant_table: avoid unnecessary work during grant table unmapping

Quoted 17 lines · Jan Beulich

xen/common/grant_table.c gnttab_unmap_grant_ref( · line 1371

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/common/grant_table.c +3 -2
@@ -1366,8 +1366,9 @@ gnttab_unmap_grant_ref(
 
     return 0;
 
-fault:
-    gnttab_flush_tlb(current->domain);
+ fault:
+    if ( current->domain->is_shut_down )
+        gnttab_flush_tlb(current->domain);

First of all: Is avoiding this really all that useful? You don't avoid further work in any of the earlier patches. I.e. not the least for consistency reasons I'd suggest dropping this patch.

Quoted 4 lines

And then, besides the condition being inverted as Kevin has already pointed out, I think you mean ->is_shutting_down, not
->is_shut_down.

I will drop this patch in next v3.

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#37 lore raw

PATCH v2 5/11 vt-d: propagate IOMMU Device-TLB flush error up to IOMMU unmapping.

In reply to Quan Xu

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to IOMMU unmapping.

CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
CC Jan Beulich <[email protected]>
---
 xen/drivers/passthrough/vtd/iommu.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
xen/drivers/passthrough/vtd/iommu.c +8 -7
index 50d98ac..580a9cf 100644
@@ -617,11 +617,12 @@ static void intel_iommu_iotlb_flush_all(struct domain *d)
 }
 
 /* clear one page's page table */
-static void dma_pte_clear_one(struct domain *domain, u64 addr)
+static int dma_pte_clear_one(struct domain *domain, u64 addr)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(domain);
     struct dma_pte *page = NULL, *pte = NULL;
     u64 pg_maddr;
+    int rc = 0;
 
     spin_lock(&hd->arch.mapping_lock);
     /* get last level pte */
@@ -629,7 +630,7 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr)
     if ( pg_maddr == 0 )
     {
         spin_unlock(&hd->arch.mapping_lock);
-        return;
+        return 0;
     }
 
     page = (struct dma_pte *)map_vtd_domain_page(pg_maddr);
@@ -639,7 +640,7 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr)
     {
         spin_unlock(&hd->arch.mapping_lock);
         unmap_vtd_domain_page(page);
-        return;
+        return 0;
     }
 
     dma_clear_pte(*pte);
@@ -647,9 +648,11 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr)
     iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
 
     if ( !this_cpu(iommu_dont_flush_iotlb) )
-        iommu_flush_iotlb(domain, addr >> PAGE_SHIFT_4K, 1, 1);
+        rc = iommu_flush_iotlb(domain, addr >> PAGE_SHIFT_4K, 1, 1);
 
     unmap_vtd_domain_page(page);
+
+    return rc;
 }
 
 static void iommu_free_pagetable(u64 pt_maddr, int level)
@@ -1770,9 +1773,7 @@ static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn)
     if ( iommu_passthrough && is_hardware_domain(d) )
         return 0;
 
-    dma_pte_clear_one(d, (paddr_t)gfn << PAGE_SHIFT_4K);
-
-    return 0;
+    return dma_pte_clear_one(d, (paddr_t)gfn << PAGE_SHIFT_4K);
 }
 
 int iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte,
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v2 5/11
#38 lore raw

Re: [PATCH v2 05/11] vt-d: propagate IOMMU Device-TLB flush error up to IOMMU unmapping.

Quoted 6 lines

From: Xu, Quan
Sent: Monday, April 18, 2016 10:00 PM

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to IOMMU unmapping.

Thought you don't need replicate the same reason in every patch. clear enough to just keep last line.

Quoted 6 lines
CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
CC Jan Beulich <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#39 lore raw

Re: [PATCH v2 05/11] vt-d: propagate IOMMU Device-TLB flush error up to IOMMU unmapping.

Quoted 10 lines · Kevin
Quoted 6 lines

From: Xu, Quan
Sent: Monday, April 18, 2016 10:00 PM

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to IOMMU unmapping.

Thought you don't need replicate the same reason in every patch. clear enough to just keep last line.

That's good. I also hesitated to add this same reason. I'll drop it in next v3. Quan

Quoted 8 lines
Quoted 6 lines
CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
CC Jan Beulich <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#40 lore raw

Re: [PATCH v2 05/11] vt-d: propagate IOMMU Device-TLB flush error up to IOMMU unmapping.

In reply to Quan Xu

xen/drivers/passthrough/vtd/iommu.c static void intel_iommu_iotlb_flush_all(struct domain · line 621

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -617,11 +617,12 @@ static void intel_iommu_iotlb_flush_all(struct domain 
 *d)
 }
 
 /* clear one page's page table */
-static void dma_pte_clear_one(struct domain *domain, u64 addr)
+static int dma_pte_clear_one(struct domain *domain, u64 addr)

This, at the latest in this series, is where __must_check should come into play.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#41 lore raw

Re: [PATCH v2 05/11] vt-d: propagate IOMMU Device-TLB flush error up to IOMMU unmapping.

Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -617,11 +617,12 @@ static void intel_iommu_iotlb_flush_all(struct

domain
*d)
}

Quoted 6 lines

xen/drivers/passthrough/vtd/iommu.c static void intel_iommu_iotlb_flush_all(struct domain *d) · line 620

Quoted 3 lines

/* clear one page's page table */

xen/drivers/passthrough/vtd/iommu.c +1 -1
-static void dma_pte_clear_one(struct domain *domain, u64 addr)
+static int dma_pte_clear_one(struct domain *domain, u64 addr)

This, at the latest in this series, is where __must_check should come into play.

Agreed.
Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#42 lore raw

PATCH v2 6/11 vt-d: propagate IOMMU Device-TLB flush error up to IOMMU mapping.

In reply to Quan Xu

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to IOMMU mapping.

CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
CC Jan Beulich <[email protected]>
---
 xen/drivers/passthrough/vtd/iommu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
xen/drivers/passthrough/vtd/iommu.c +3 -2
index 580a9cf..5cc70ca 100644
@@ -1720,6 +1720,7 @@ static int intel_iommu_map_page(
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct dma_pte *page = NULL, *pte = NULL, old, new = { 0 };
     u64 pg_maddr;
+    int rc = 0;
 
     /* Do nothing if VT-d shares EPT page table */
     if ( iommu_use_hap_pt(d) )
@@ -1762,9 +1763,9 @@ static int intel_iommu_map_page(
     unmap_vtd_domain_page(page);
 
     if ( !this_cpu(iommu_dont_flush_iotlb) )
-        iommu_flush_iotlb(d, gfn, dma_pte_present(old), 1);
+        rc = iommu_flush_iotlb(d, gfn, dma_pte_present(old), 1);
 
-    return 0;
+    return rc;
 }
 
 static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn)
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v2 6/11
#43 lore raw

Re: [PATCH v2 06/11] vt-d: propagate IOMMU Device-TLB flush error up to IOMMU mapping.

Quoted 7 lines

From: Xu, Quan
Sent: Monday, April 18, 2016 10:00 PM

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to IOMMU mapping.

Quoted 5 lines
CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
CC Jan Beulich <[email protected]>

same comment on above message. for code itself:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#44 lore raw

PATCH v2 7/11 IOMMU/MMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (top level ones).

In reply to Quan Xu

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to the iommu_iotlb_flush{,_all}.

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

This patch fixes the top level ones (this patch doesn't fix the leaf ones but the next patch does).

CC Stefano Stabellini <[email protected]>
CC Julien Grall <[email protected]>
CC Jan Beulich <[email protected]>
---
 xen/arch/arm/p2m.c                  |  5 ++++-
 xen/common/memory.c                 |  5 +++--
 xen/drivers/passthrough/iommu.c     | 12 ++++++++----
 xen/drivers/passthrough/x86/iommu.c |  5 +++--
 xen/include/xen/iommu.h             |  4 ++--
 5 files changed, 20 insertions(+), 11 deletions(-)
xen/arch/arm/p2m.c +4 -1
index a2a9c4b..11d2c02 100644
@@ -1177,7 +1177,10 @@ out:
     if ( flush )
     {
         flush_tlb_domain(d);
-        iommu_iotlb_flush(d, sgfn, egfn - sgfn);
+        ret = iommu_iotlb_flush(d, sgfn, egfn - sgfn);
+
+        if ( ret )
+            rc = ret;
     }
 
     while ( (pg = page_list_remove_head(&free_pages)) )
xen/common/memory.c +3 -2
index c7fca96..965bd51 100644
@@ -678,8 +678,9 @@ static int xenmem_add_to_physmap(struct domain *d,
     if ( need_iommu(d) )
     {
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        iommu_iotlb_flush(d, xatp->idx - done, done);
-        iommu_iotlb_flush(d, xatp->gpfn - done, done);
+        rc = iommu_iotlb_flush(d, xatp->idx - done, done);
+        if ( !rc )
+            rc = iommu_iotlb_flush(d, xatp->gpfn - done, done);
     }
 #endif
 
xen/drivers/passthrough/iommu.c +8 -4
index c351209..9254760 100644
@@ -301,24 +301,28 @@ static void iommu_free_pagetables(unsigned long unused)
                             cpumask_cycle(smp_processor_id(), &cpu_online_map));
 }
 
-void iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
+int iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
 
     if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush )
-        return;
+        return 0;
 
     hd->platform_ops->iotlb_flush(d, gfn, page_count);
+
+    return 0;
 }
 
-void iommu_iotlb_flush_all(struct domain *d)
+int iommu_iotlb_flush_all(struct domain *d)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
 
     if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush_all )
-        return;
+        return 0;
 
     hd->platform_ops->iotlb_flush_all(d);
+
+    return 0;
 }
 
 int __init iommu_setup(void)
xen/drivers/passthrough/x86/iommu.c +3 -2
index 8cbb655..c2c1ee3 100644
@@ -104,8 +104,9 @@ int arch_iommu_populate_page_table(struct domain *d)
     this_cpu(iommu_dont_flush_iotlb) = 0;
 
     if ( !rc )
-        iommu_iotlb_flush_all(d);
-    else if ( rc != -ERESTART )
+        rc = iommu_iotlb_flush_all(d);
+
+    if ( rc && rc != -ERESTART )
         iommu_teardown(d);
 
     return rc;
xen/include/xen/iommu.h +2 -2
index 8217cb7..ff4608d 100644
@@ -182,8 +182,8 @@ int iommu_do_pci_domctl(struct xen_domctl *, struct domain *d,
 int iommu_do_domctl(struct xen_domctl *, struct domain *d,
                     XEN_GUEST_HANDLE_PARAM(xen_domctl_t));
 
-void iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count);
-void iommu_iotlb_flush_all(struct domain *d);
+int iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count);
+int iommu_iotlb_flush_all(struct domain *d);
 
 /*
  * The purpose of the iommu_dont_flush_iotlb optional cpu flag is to
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#45 lore raw

Re: [PATCH v2 07/11] IOMMU/MMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (top level ones).

xen/common/memory.c static int xenmem_add_to_physmap(struct domain *d, · line 683

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/common/memory.c +3 -2
@@ -678,8 +678,9 @@ static int xenmem_add_to_physmap(struct domain *d,
     if ( need_iommu(d) )
     {
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        iommu_iotlb_flush(d, xatp->idx - done, done);
-        iommu_iotlb_flush(d, xatp->gpfn - done, done);
+        rc = iommu_iotlb_flush(d, xatp->idx - done, done);
+        if ( !rc )
+            rc = iommu_iotlb_flush(d, xatp->gpfn - done, done);

And again - best effort flushing in all cases. I.e. you shouldn't bypass the second one if the first one failed, but instead properly accumulate the return value, and also again not clobber any negative value rc may already hold. What's worse (and makes me wonder whether this got tested) - you also clobber the positive return value this function may produce, even in the case the flushes succeed (and hence the function as a whole was successful).

xen/include/xen/iommu.h int iommu_do_pci_domctl(struct xen_domctl *, struct domain *d, · line 186

Quoted 10 lines
xen/include/xen/iommu.h +2 -2
@@ -182,8 +182,8 @@ int iommu_do_pci_domctl(struct xen_domctl *, struct domain *d,
 int iommu_do_domctl(struct xen_domctl *, struct domain *d,
                     XEN_GUEST_HANDLE_PARAM(xen_domctl_t));
 
-void iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count);
-void iommu_iotlb_flush_all(struct domain *d);
+int iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count);
+int iommu_iotlb_flush_all(struct domain *d);

__must_check

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#46 lore raw

Re: [PATCH v2 07/11] IOMMU/MMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (top level ones).

Quoted 14 lines · Jan Beulich

xen/common/memory.c static int xenmem_add_to_physmap(struct domain

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/common/memory.c +0 -0
@@ -678,8 +678,9 @@ static int xenmem_add_to_physmap(struct domain

*d,

xen/common/memory.c static int xenmem_add_to_physmap(struct domain *d, · line 683

Quoted 8 lines
xen/common/memory.c +3 -2
     if ( need_iommu(d) )
     {
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        iommu_iotlb_flush(d, xatp->idx - done, done);
-        iommu_iotlb_flush(d, xatp->gpfn - done, done);
+        rc = iommu_iotlb_flush(d, xatp->idx - done, done);
+        if ( !rc )
+            rc = iommu_iotlb_flush(d, xatp->gpfn - done, done);
Quoted 3 lines

And again - best effort flushing in all cases. I.e. you shouldn't bypass the second one if the first one failed, but instead properly accumulate the return value, and also again not clobber any negative value rc may already hold.

Thanks for correcting me. I did like accumulating the return value. :( I will follow your suggestion in next v3.

Quoted 4 lines

What's worse (and makes me wonder whether this got tested) - you also clobber the positive return value this function may produce, even in the case the flushes succeed (and hence the function as a whole was successful).

I have tested it with previous patches (i.e. 1st patch), launching a VM with PT ATS device to invoke this call tree. btw, I fix the positive issue in 1st patch.
I know this is not strict, as I assume this patch set will be committed at the same time.

Quoted 5 lines
Quoted 4 lines
xen/include/xen/iommu.h +0 -0
@@ -182,8 +182,8 @@ int iommu_do_pci_domctl(struct xen_domctl *,

struct domain *d, int iommu_do_domctl(struct xen_domctl *, struct domain

*d,

Quoted 9 lines

xen/include/xen/iommu.h

Quoted 6 lines
                     XEN_GUEST_HANDLE_PARAM(xen_domctl_t));

-void iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count); -void iommu_iotlb_flush_all(struct domain *d);

xen/include/xen/iommu.h +2 -0
+int iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned
+int page_count); int iommu_iotlb_flush_all(struct domain *d);

__must_check

Agreed.

Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#47 lore raw

Re: [PATCH v2 07/11] IOMMU/MMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (top level ones).

Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 26.04.16 at 14:23, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich

xen/common/memory.c static int xenmem_add_to_physmap(struct domain

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/common/memory.c +0 -0
@@ -678,8 +678,9 @@ static int xenmem_add_to_physmap(struct domain

*d,

xen/common/memory.c static int xenmem_add_to_physmap(struct domain *d, · line 683

Quoted 8 lines
xen/common/memory.c +3 -2
     if ( need_iommu(d) )
     {
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        iommu_iotlb_flush(d, xatp->idx - done, done);
-        iommu_iotlb_flush(d, xatp->gpfn - done, done);
+        rc = iommu_iotlb_flush(d, xatp->idx - done, done);
+        if ( !rc )
+            rc = iommu_iotlb_flush(d, xatp->gpfn - done, done);
Quoted 3 lines

And again - best effort flushing in all cases. I.e. you shouldn't bypass the second one if the first one failed, but instead properly accumulate the return value, and also again not clobber any negative value rc may already hold.

Thanks for correcting me. I did like accumulating the return value. :( I will follow your suggestion in next v3.

Quoted 4 lines

What's worse (and makes me wonder whether this got tested) - you also clobber the positive return value this function may produce, even in the case the flushes succeed (and hence the function as a whole was successful).

Quoted 5 lines

I have tested it with previous patches (i.e. 1st patch), launching a VM with PT ATS device to invoke this call tree.
btw, I fix the positive issue in 1st patch.
I know this is not strict, as I assume this patch set will be committed at the same time.

Hmm, the "positive" here has nothing to do with the "positive" in patch 1. Please just have a look at xenmem_add_to_physmap() as a whole.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#48 lore raw

Re: [PATCH v2 07/11] IOMMU/MMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (top level ones).

Quoted 31 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 26.04.16 at 14:23, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/common/memory.c static int xenmem_add_to_physmap(struct

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/common/memory.c +0 -0
@@ -678,8 +678,9 @@ static int xenmem_add_to_physmap(struct

domain

Quoted 10 lines
Quoted 10 lines

*d,

Quoted 8 lines
xen/common/memory.c +3 -2
     if ( need_iommu(d) )
     {
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        iommu_iotlb_flush(d, xatp->idx - done, done);
-        iommu_iotlb_flush(d, xatp->gpfn - done, done);
+        rc = iommu_iotlb_flush(d, xatp->idx - done, done);
+        if ( !rc )
+            rc = iommu_iotlb_flush(d, xatp->gpfn - done, done);
Quoted 3 lines
Quoted 3 lines

And again - best effort flushing in all cases. I.e. you shouldn't bypass the second one if the first one failed, but instead properly accumulate the return value, and also again not clobber any negative value

rc may already hold.

Quoted 8 lines

Thanks for correcting me. I did like accumulating the return value. :( I will follow your suggestion in next v3.

Quoted 3 lines

What's worse (and makes me wonder whether this got tested) - you also clobber the positive return value this function may produce, even in the case the flushes succeed (and hence the function as a whole was

successful).

Quoted 1 line
Quoted 1 line
Quoted 9 lines
Quoted 5 lines

I have tested it with previous patches (i.e. 1st patch), launching a VM with PT ATS device to invoke this call tree.
btw, I fix the positive issue in 1st patch.
I know this is not strict, as I assume this patch set will be committed at the same time.

Hmm, the "positive" here has nothing to do with the "positive" in patch 1. Please just have a look at xenmem_add_to_physmap() as a whole.

Thanks for reminding me. The 'positive' is ' rc = start + done'..

Think twice, I found I need two other new return values for this function (correct me if I am wrong!). If the first iommu_iotlb_flush() is failed, I shouldn't accumulate the return value of the second iommu_iotlb_flush() -- but instead properly accumulate the return value.

The following is my modification:

xen/common/memory.c +13 -2
@@ -640,6 +640,10 @@ static int xenmem_add_to_physmap(struct domain *d,
     unsigned int done = 0;
     long rc = 0;
 
+#ifdef CONFIG_HAS_PASSTHROUGH
+    int ret, rv;
+#endif
+
     if ( xatp->space != XENMAPSPACE_gmfn_range )
         return xenmem_add_to_physmap_one(d, xatp->space, DOMID_INVALID,
                                          xatp->idx, xatp->gpfn);
@@ -678,8 +682,15 @@ static int xenmem_add_to_physmap(struct domain *d,
     if ( need_iommu(d) )
     {
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        iommu_iotlb_flush(d, xatp->idx - done, done);
-        iommu_iotlb_flush(d, xatp->gpfn - done, done);
+        ret = iommu_iotlb_flush(d, xatp->idx - done, done);
+
+        if ( rc >= 0 && ret < 0 )
+            rc = ret;
+
+        rv = iommu_iotlb_flush(d, xatp->gpfn - done, done);
+
+        if ( rc >=0 && ret == 0 && rv < 0 )
+            rc = rv;
     }
 #endif
 

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#49 lore raw

Re: [PATCH v2 07/11] IOMMU/MMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (top level ones).

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 27.04.16 at 08:21, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich

Hmm, the "positive" here has nothing to do with the "positive" in patch 1. Please just have a look at xenmem_add_to_physmap() as a whole.

Quoted 8 lines

Thanks for reminding me. The 'positive' is ' rc = start + done'..

Think twice, I found I need two other new return values for this function (correct me if I am wrong!).
If the first iommu_iotlb_flush() is failed, I shouldn't accumulate the return value of
the second iommu_iotlb_flush() -- but instead properly accumulate the return value.

I think just one will do.

xen/common/memory.c static int xenmem_add_to_physmap(struct domain *d, · line 645

Quoted 11 lines

The following is my modification:

xen/common/memory.c +3 -0
@@ -640,6 +640,10 @@ static int xenmem_add_to_physmap(struct domain *d,
     unsigned int done = 0;
     long rc = 0;
 
+#ifdef CONFIG_HAS_PASSTHROUGH
+    int ret, rv;
+#endif

This should go into the scope below, allowing to avoid the extra #ifdef.

xen/common/memory.c static int xenmem_add_to_physmap(struct domain *d, · line 687

Quoted 9 lines
xen/common/memory.c +3 -2
@@ -678,8 +682,15 @@ static int xenmem_add_to_physmap(struct domain *d,
     if ( need_iommu(d) )
     {
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        iommu_iotlb_flush(d, xatp->idx - done, done);
-        iommu_iotlb_flush(d, xatp->gpfn - done, done);
+        ret = iommu_iotlb_flush(d, xatp->idx - done, done);
+
+        if ( rc >= 0 && ret < 0 )

Why "ret < 0" instead of just "ret"?

xen/common/memory.c static int xenmem_add_to_physmap(struct domain *d, · line 693

Quoted 6 lines
xen/common/memory.c +6 -0
+            rc = ret;
+
+        rv = iommu_iotlb_flush(d, xatp->gpfn - done, done);
+
+        if ( rc >=0 && ret == 0 && rv < 0 )
+            rc = rv;

I don't see the middle part being needed here, eliminating the need for "rv".

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#50 lore raw

Re: [PATCH v2 07/11] IOMMU/MMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (top level ones).

Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 27.04.16 at 08:21, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich

Hmm, the "positive" here has nothing to do with the "positive" in patch 1. Please just have a look at xenmem_add_to_physmap() as a whole.

Thanks for reminding me. The 'positive' is ' rc = start + done'..

Quoted 8 lines
Quoted 5 lines

Think twice, I found I need two other new return values for this function (correct me if I am wrong!).
If the first iommu_iotlb_flush() is failed, I shouldn't accumulate the return value of the second iommu_iotlb_flush() -- but instead properly accumulate the return value.

I think just one will do.

Got it.

Quoted 6 lines

xen/common/memory.c static int xenmem_add_to_physmap(struct

Quoted 5 lines

The following is my modification:

xen/common/memory.c +0 -0
@@ -640,6 +640,10 @@ static int xenmem_add_to_physmap(struct

domain *d,

Quoted 9 lines

xen/common/memory.c static int xenmem_add_to_physmap(struct domain *d, · line 645

Quoted 6 lines
xen/common/memory.c +3 -0
     unsigned int done = 0;
     long rc = 0;
 
+#ifdef CONFIG_HAS_PASSTHROUGH
+    int ret, rv;
+#endif

This should go into the scope below, allowing to avoid the extra #ifdef.

Agreed .

Quoted 4 lines

xen/common/memory.c static int xenmem_add_to_physmap(struct

Quoted 1 line
xen/common/memory.c +0 -0
@@ -678,8 +682,15 @@ static int xenmem_add_to_physmap(struct

domain *d,

Quoted 2 lines
xen/common/memory.c +0 -0
     if ( need_iommu(d) )
     {

Check it again. The 'int ret' declaration should be here?

Quoted 9 lines

xen/common/memory.c static int xenmem_add_to_physmap(struct domain *d, · line 687

Quoted 6 lines
xen/common/memory.c +3 -2
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        iommu_iotlb_flush(d, xatp->idx - done, done);
-        iommu_iotlb_flush(d, xatp->gpfn - done, done);
+        ret = iommu_iotlb_flush(d, xatp->idx - done, done);
+
+        if ( rc >= 0 && ret < 0 )

Why "ret < 0" instead of just "ret"?

"ret" is enough.

Quoted 9 lines

xen/common/memory.c static int xenmem_add_to_physmap(struct domain *d, · line 693

Quoted 6 lines
xen/common/memory.c +6 -0
+            rc = ret;
+
+        rv = iommu_iotlb_flush(d, xatp->gpfn - done, done);
+
+        if ( rc >=0 && ret == 0 && rv < 0 )
+            rc = rv;

I don't see the middle part being needed here, eliminating the need for "rv".

I will drop 'rv'.

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#51 lore raw

Re: [PATCH v2 07/11] IOMMU/MMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (top level ones).

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 27.04.16 at 11:08, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich

Review static int xenmem_add_to_physmap(struct

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 27.04.16 at 08:21, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -678,8 +682,15 @@ static int xenmem_add_to_physmap(struct

domain *d,

Quoted 2 lines
xen/common/memory.c +0 -0
     if ( need_iommu(d) )
     {

Check it again. The 'int ret' declaration should be here?

Yes, exactly.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#52 lore raw

PATCH v2 8/11 IOMMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (leaf ones).

In reply to Quan Xu

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to the iommu_iotlb_flush{,_all}.

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

This patch fixes the leaf ones.

CC Jan Beulich <[email protected]>
CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
---
 xen/drivers/passthrough/iommu.c     | 8 ++------
 xen/drivers/passthrough/vtd/iommu.c | 8 ++++----
 xen/include/xen/iommu.h             | 4 ++--
 3 files changed, 8 insertions(+), 12 deletions(-)
xen/drivers/passthrough/iommu.c +2 -6
index 9254760..d44fc39 100644
@@ -308,9 +308,7 @@ int iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_cou
     if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush )
         return 0;
 
-    hd->platform_ops->iotlb_flush(d, gfn, page_count);
-
-    return 0;
+    return hd->platform_ops->iotlb_flush(d, gfn, page_count);
 }
 
 int iommu_iotlb_flush_all(struct domain *d)
@@ -320,9 +318,7 @@ int iommu_iotlb_flush_all(struct domain *d)
     if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush_all )
         return 0;
 
-    hd->platform_ops->iotlb_flush_all(d);
-
-    return 0;
+    return hd->platform_ops->iotlb_flush_all(d);
 }
 
 int __init iommu_setup(void)
xen/drivers/passthrough/vtd/iommu.c +4 -4
index 5cc70ca..930661a 100644
@@ -606,14 +606,14 @@ static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
     return rc;
 }
 
-static void intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
+static int intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
 {
-    iommu_flush_iotlb(d, gfn, 1, page_count);
+    return iommu_flush_iotlb(d, gfn, 1, page_count);
 }
 
-static void intel_iommu_iotlb_flush_all(struct domain *d)
+static int intel_iommu_iotlb_flush_all(struct domain *d)
 {
-    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
+    return iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }
 
 /* clear one page's page table */
xen/include/xen/iommu.h +2 -2
index ff4608d..ca1c409 100644
@@ -161,8 +161,8 @@ struct iommu_ops {
     void (*resume)(void);
     void (*share_p2m)(struct domain *d);
     void (*crash_shutdown)(void);
-    void (*iotlb_flush)(struct domain *d, unsigned long gfn, unsigned int page_count);
-    void (*iotlb_flush_all)(struct domain *d);
+    int (*iotlb_flush)(struct domain *d, unsigned long gfn, unsigned int page_count);
+    int (*iotlb_flush_all)(struct domain *d);
     int (*get_reserved_device_memory)(iommu_grdm_t *, void *);
     void (*dump_p2m_table)(struct domain *d);
 };
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#53 lore raw

Re: [PATCH v2 08/11] IOMMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (leaf ones).

Quoted 7 lines

From: Xu, Quan
Sent: Monday, April 18, 2016 10:00 PM

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to the iommu_iotlb_flush{,_all}.

Quoted 5 lines

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

This patch fixes the leaf ones.

what about other leaves like AMD/ARM callbacks?

Quoted 82 lines
CC Jan Beulich <[email protected]>
CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
---
 xen/drivers/passthrough/iommu.c     | 8 ++------
 xen/drivers/passthrough/vtd/iommu.c | 8 ++++----
 xen/include/xen/iommu.h             | 4 ++--
 3 files changed, 8 insertions(+), 12 deletions(-)
xen/drivers/passthrough/iommu.c +0 -0
index 9254760..d44fc39 100644
@@ -308,9 +308,7 @@ int iommu_iotlb_flush(struct domain *d, unsigned long gfn,

unsigned int page_cou

     if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush )
         return 0;
xen/drivers/passthrough/iommu.c +2 -6
-    hd->platform_ops->iotlb_flush(d, gfn, page_count);
-
-    return 0;
+    return hd->platform_ops->iotlb_flush(d, gfn, page_count);
 }
 
 int iommu_iotlb_flush_all(struct domain *d)
@@ -320,9 +318,7 @@ int iommu_iotlb_flush_all(struct domain *d)
     if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush_all )
         return 0;
 
-    hd->platform_ops->iotlb_flush_all(d);
-
-    return 0;
+    return hd->platform_ops->iotlb_flush_all(d);
 }
 
 int __init iommu_setup(void)
xen/drivers/passthrough/vtd/iommu.c +4 -4
index 5cc70ca..930661a 100644
@@ -606,14 +606,14 @@ static int iommu_flush_iotlb(struct domain *d, unsigned long
 gfn,
     return rc;
 }
 
-static void intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int
 page_count)
+static int intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int
 page_count)
 {
-    iommu_flush_iotlb(d, gfn, 1, page_count);
+    return iommu_flush_iotlb(d, gfn, 1, page_count);
 }
 
-static void intel_iommu_iotlb_flush_all(struct domain *d)
+static int intel_iommu_iotlb_flush_all(struct domain *d)
 {
-    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
+    return iommu_flush_iotlb(d, INVALID_GFN, 0, 0);

}

/* clear one page's page table */

xen/include/xen/iommu.h +2 -3
index ff4608d..ca1c409 100644
@@ -161,8 +161,8 @@ struct iommu_ops {
     void (*resume)(void);
     void (*share_p2m)(struct domain *d);
     void (*crash_shutdown)(void);
-    void (*iotlb_flush)(struct domain *d, unsigned long gfn, unsigned int page_count);
-    void (*iotlb_flush_all)(struct domain *d);
+    int (*iotlb_flush)(struct domain *d, unsigned long gfn, unsigned int page_count);
+    int (*iotlb_flush_all)(struct domain *d);
     int (*get_reserved_device_memory)(iommu_grdm_t *, void *);
     void (*dump_p2m_table)(struct domain *d);
 };
--
Quoted 1 line

1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#54 lore raw

Re: [PATCH v2 08/11] IOMMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (leaf ones).

Quoted 8 lines · Kevin
Quoted 6 lines

From: Xu, Quan
Sent: Monday, April 18, 2016 10:00 PM

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to the

iommu_iotlb_flush{,_all}.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

This patch fixes the leaf ones.

what about other leaves like AMD/ARM callbacks?

Thank you for reminding me of such cases. I really missed them in this v2.

Quan

Quoted 80 lines
Quoted 18 lines
CC Jan Beulich <[email protected]>
CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
---
 xen/drivers/passthrough/iommu.c     | 8 ++------
 xen/drivers/passthrough/vtd/iommu.c | 8 ++++----
 xen/include/xen/iommu.h             | 4 ++--
 3 files changed, 8 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/xen/drivers/passthrough/iommu.c index 9254760..d44fc39 100644

xen/drivers/passthrough/iommu.c +0 -0
@@ -308,9 +308,7 @@ int iommu_iotlb_flush(struct domain *d, unsigned

long gfn, unsigned int page_cou

Quoted 1 line
     if ( !iommu_enabled || !hd->platform_ops
|| !hd->platform_ops->iotlb_flush )
>          return 0;
Quoted 10 lines
xen/drivers/passthrough/iommu.c +1 -3
-    hd->platform_ops->iotlb_flush(d, gfn, page_count);
-
-    return 0;
+    return hd->platform_ops->iotlb_flush(d, gfn, page_count);
 }
 
 int iommu_iotlb_flush_all(struct domain *d) @@ -320,9 +318,7 @@ int

iommu_iotlb_flush_all(struct domain *d)

     if ( !iommu_enabled || !hd->platform_ops
|| !hd->platform_ops->iotlb_flush_all )
>          return 0;
Quoted 42 lines
xen/drivers/passthrough/iommu.c +1 -3
-    hd->platform_ops->iotlb_flush_all(d);
-
-    return 0;
+    return hd->platform_ops->iotlb_flush_all(d);
 }
 
 int __init iommu_setup(void)
xen/drivers/passthrough/vtd/iommu.c +0 -1
index 5cc70ca..930661a 100644
@@ -606,14 +606,14 @@ static int iommu_flush_iotlb(struct domain *d,
 unsigned long gfn,
     return rc;
 }
 
-static void intel_iommu_iotlb_flush(struct domain *d, unsigned long

gfn, unsigned int
page_count)

xen/drivers/passthrough/vtd/iommu.c +2 -0
+static int intel_iommu_iotlb_flush(struct domain *d, unsigned long
+gfn, unsigned int

page_count)
{

xen/drivers/passthrough/vtd/iommu.c +3 -3
-    iommu_flush_iotlb(d, gfn, 1, page_count);
+    return iommu_flush_iotlb(d, gfn, 1, page_count);
 }
 
-static void intel_iommu_iotlb_flush_all(struct domain *d)
+static int intel_iommu_iotlb_flush_all(struct domain *d)
 {
-    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
+    return iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }
 
 /* clear one page's page table */
xen/include/xen/iommu.h index renamed from xen/include/xen/iommu.h +0 -0

ff4608d..ca1c409 100644

xen/include/xen/iommu.h struct iommu_ops { · line 164

Quoted 4 lines
xen/include/xen/iommu.h +0 -1
@@ -161,8 +161,8 @@ struct iommu_ops {
     void (*resume)(void);
     void (*share_p2m)(struct domain *d);
     void (*crash_shutdown)(void);
-    void (*iotlb_flush)(struct domain *d, unsigned long gfn, unsigned int

page_count);

Quoted 8 lines

xen/include/xen/iommu.h struct iommu_ops { · line 164

Quoted 2 lines
xen/include/xen/iommu.h +1 -1
-    void (*iotlb_flush_all)(struct domain *d);
+    int (*iotlb_flush)(struct domain *d, unsigned long gfn, unsigned int

page_count);

Quoted 5 lines
xen/include/xen/iommu.h +1 -1
+    int (*iotlb_flush_all)(struct domain *d);
     int (*get_reserved_device_memory)(iommu_grdm_t *, void *);
     void (*dump_p2m_table)(struct domain *d);  };
--

1.9.1

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#55 lore raw

Re: [PATCH v2 08/11] IOMMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (leaf ones).

In reply to Quan Xu
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to the iommu_iotlb_flush{,_all}.

Quoted 7 lines

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

This patch fixes the leaf ones.

Looks okay except for the again missing uses of __must_check on function declarations or, where needed, definitions.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#56 lore raw

Re: [PATCH v2 08/11] IOMMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (leaf ones).

Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to the iommu_iotlb_flush{,_all}.

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

Quoted 7 lines
Quoted 3 lines

This patch fixes the leaf ones.

Looks okay except for the again missing uses of __must_check on function declarations or, where needed, definitions.

This patch modifies the common part 'iommu_ops', but not to
fix the ARM/AMD callbacks ( it seems the callbacks are not initialized for AMD code, but ARM does). I need to fix ARM callbacks as well.

I wonder whether it is good to use __must_check on these callbacks or not.
IMO I'd better use __must_check on functions, i.e. iommu_iotlb_flush_all(), invoking these callbacks, instead of these callbacks.

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#57 lore raw

Re: [PATCH v2 08/11] IOMMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (leaf ones).

Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 26.04.16 at 13:50, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to the iommu_iotlb_flush{,_all}.

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

Quoted 6 lines
Quoted 3 lines

This patch fixes the leaf ones.

Looks okay except for the again missing uses of __must_check on function declarations or, where needed, definitions.

Quoted 7 lines

This patch modifies the common part 'iommu_ops', but not to fix the ARM/AMD callbacks ( it seems the callbacks are not initialized for AMD code, but ARM does).
I need to fix ARM callbacks as well.

I wonder whether it is good to use __must_check on these callbacks or not.

For callbacks it's indeed questionable.

Quoted 2 lines

IMO I'd better use __must_check on functions, i.e. iommu_iotlb_flush_all(), invoking these callbacks, instead of these callbacks.

At least the two functions in xen/drivers/passthrough/iommu.c that this patch alters need to gain __must_check annotations (if they don't already in an earlier patch - that's simply not possible to tell on this version, which fails to add any such annotations).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#58 lore raw

Re: [PATCH v2 08/11] IOMMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (leaf ones).

Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 26.04.16 at 13:50, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to the iommu_iotlb_flush{,_all}.

If IOMMU mapping and unmapping failed, the domain (with the exception of the hardware domain) is crashed, treated as a fatal error. Rollback can be lighter weight.

Quoted 6 lines
Quoted 3 lines

This patch fixes the leaf ones.

Looks okay except for the again missing uses of __must_check on function declarations or, where needed, definitions.

This patch modifies the common part 'iommu_ops', but not to fix the ARM/AMD callbacks ( it seems the callbacks are not initialized for AMD code, but ARM does).
I need to fix ARM callbacks as well.

Quoted 4 lines
Quoted 1 line

I wonder whether it is good to use __must_check on these callbacks or not.

For callbacks it's indeed questionable.

I think so.

Quoted 9 lines
Quoted 2 lines

IMO I'd better use __must_check on functions, i.e.
iommu_iotlb_flush_all(), invoking these callbacks, instead of these

callbacks.

At least the two functions in xen/drivers/passthrough/iommu.c that this patch alters need to gain __must_check annotations (if they don't already in an earlier patch - that's simply not possible to tell on this version, which fails to add any such annotations).

I didn't add __must_check annotations in v2.
I will consider __must_check annotations carefully in next v3.

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#59 lore raw

PATCH v2 9/11 IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

In reply to Quan Xu

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to IOMMU suspending.

CC Jan Beulich <[email protected]>
CC Liu Jinsong <[email protected]>
CC Keir Fraser <[email protected]>
CC Andrew Cooper <[email protected]>
CC Suravee Suthikulpanit <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Julien Grall <[email protected]>
CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
---
 xen/arch/x86/acpi/power.c                     | 14 +++++++++++++-
 xen/drivers/passthrough/amd/iommu_init.c      |  9 ++++++++-
 xen/drivers/passthrough/amd/pci_amd_iommu.c   |  2 +-
 xen/drivers/passthrough/arm/smmu.c            | 10 ++++++----
 xen/drivers/passthrough/iommu.c               |  7 +++++--
 xen/drivers/passthrough/vtd/iommu.c           | 22 +++++++++++++++++-----
 xen/include/asm-x86/hvm/svm/amd-iommu-proto.h |  2 +-
 xen/include/xen/iommu.h                       |  4 ++--
 8 files changed, 53 insertions(+), 17 deletions(-)
xen/arch/x86/acpi/power.c +13 -1
index 2885e31..9b87f00 100644
@@ -45,19 +45,31 @@ void do_suspend_lowlevel(void);
 
 static int device_power_down(void)
 {
+    int err;
+
     console_suspend();
 
     time_suspend();
 
     i8259A_suspend();
 
-    ioapic_suspend();
+    err = iommu_suspend();
+    if ( err )
+        goto iommu_suspend_error;
 
     iommu_suspend();
 
     lapic_suspend();
 
     return 0;
+
+ iommu_suspend_error:
+    ioapic_resume();
+    i8259A_resume();
+    time_resume();
+    console_resume();
+
+    return err;
 }
 
 static void device_power_up(void)
xen/drivers/passthrough/amd/iommu_init.c +8 -1
index 4536106..02588aa 100644
@@ -1339,12 +1339,19 @@ static void invalidate_all_devices(void)
     iterate_ivrs_mappings(_invalidate_all_devices);
 }
 
-void amd_iommu_suspend(void)
+int amd_iommu_suspend(void)
 {
     struct amd_iommu *iommu;
 
     for_each_amd_iommu ( iommu )
         disable_iommu(iommu);
+
+    return 0;
+}
+
+void amd_iommu_crash_shutdown(void)
+{
+    amd_iommu_suspend();
 }
 
 void amd_iommu_resume(void)
xen/drivers/passthrough/amd/pci_amd_iommu.c +1 -1
index c8ee8dc..fb8e816 100644
@@ -628,6 +628,6 @@ const struct iommu_ops amd_iommu_ops = {
     .suspend = amd_iommu_suspend,
     .resume = amd_iommu_resume,
     .share_p2m = amd_iommu_share_p2m,
-    .crash_shutdown = amd_iommu_suspend,
+    .crash_shutdown = amd_iommu_crash_shutdown,
     .dump_p2m_table = amd_dump_p2m_table,
 };
xen/drivers/passthrough/arm/smmu.c +6 -4
index 62da087..36c2c83 100644
@@ -2540,7 +2540,7 @@ static int force_stage = 2;
  */
 static u32 platform_features = ARM_SMMU_FEAT_COHERENT_WALK;
 
-static void arm_smmu_iotlb_flush_all(struct domain *d)
+static int arm_smmu_iotlb_flush_all(struct domain *d)
 {
 	struct arm_smmu_xen_domain *smmu_domain = domain_hvm_iommu(d)->arch.priv;
 	struct iommu_domain *cfg;
@@ -2557,13 +2557,15 @@ static void arm_smmu_iotlb_flush_all(struct domain *d)
 		arm_smmu_tlb_inv_context(cfg->priv);
 	}
 	spin_unlock(&smmu_domain->lock);
+
+    return 0;
 }
 
-static void arm_smmu_iotlb_flush(struct domain *d, unsigned long gfn,
-                                 unsigned int page_count)
+static int arm_smmu_iotlb_flush(struct domain *d, unsigned long gfn,
+                                unsigned int page_count)
 {
     /* ARM SMMU v1 doesn't have flush by VMA and VMID */
-    arm_smmu_iotlb_flush_all(d);
+    return arm_smmu_iotlb_flush_all(d);
 }
 
 static struct iommu_domain *arm_smmu_get_domain(struct domain *d,
xen/drivers/passthrough/iommu.c +5 -2
index d44fc39..98b934b 100644
@@ -392,11 +392,14 @@ int iommu_do_domctl(
     return ret;
 }
 
-void iommu_suspend()
+int iommu_suspend()
 {
     const struct iommu_ops *ops = iommu_get_ops();
+
     if ( iommu_enabled )
-        ops->suspend();
+        return ops->suspend();
+
+    return 0;
 }
 
 void iommu_share_p2m_table(struct domain* d)
xen/drivers/passthrough/vtd/iommu.c +17 -5
index 930661a..a821306 100644
@@ -542,11 +542,12 @@ static int iommu_flush_iotlb_psi(
     return status;
 }
 
-static void iommu_flush_all(void)
+static int iommu_flush_all(void)
 {
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     int flush_dev_iotlb;
+    int rc = 0;
 
     flush_all_cache();
     for_each_drhd_unit ( drhd )
@@ -554,8 +555,13 @@ static void iommu_flush_all(void)
         iommu = drhd->iommu;
         iommu_flush_context_global(iommu, 0);
         flush_dev_iotlb = find_ats_dev_drhd(iommu) ? 1 : 0;
-        iommu_flush_iotlb_global(iommu, 0, flush_dev_iotlb);
+        rc = iommu_flush_iotlb_global(iommu, 0, flush_dev_iotlb);
+
+        if ( rc )
+            break;
     }
+
+    return rc;
 }
 
 static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
@@ -2421,16 +2427,20 @@ static int intel_iommu_group_id(u16 seg, u8 bus, u8 devfn)
 }
 
 static u32 iommu_state[MAX_IOMMUS][MAX_IOMMU_REGS];
-static void vtd_suspend(void)
+static int vtd_suspend(void)
 {
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     u32    i;
+    int rc;
 
     if ( !iommu_enabled )
-        return;
+        return 0;
 
-    iommu_flush_all();
+    rc = iommu_flush_all();
+
+    if ( rc )
+        return rc;
 
     for_each_drhd_unit ( drhd )
     {
@@ -2459,6 +2469,8 @@ static void vtd_suspend(void)
         if ( !iommu_intremap && iommu_qinval )
             disable_qinval(iommu);
     }
+
+    return 0;
 }
 
 static void vtd_crash_shutdown(void)
xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +1 -1
index 9c51172..f540fc8 100644
@@ -119,7 +119,7 @@ extern unsigned long *shared_intremap_inuse;
 
 /* power management support */
 void amd_iommu_resume(void);
-void amd_iommu_suspend(void);
+int amd_iommu_suspend(void);
 void amd_iommu_crash_shutdown(void);
 
 /* guest iommu support */
xen/include/xen/iommu.h +2 -2
index ca1c409..8710dfe 100644
@@ -157,7 +157,7 @@ struct iommu_ops {
     unsigned int (*read_apic_from_ire)(unsigned int apic, unsigned int reg);
     int (*setup_hpet_msi)(struct msi_desc *);
 #endif /* CONFIG_X86 */
-    void (*suspend)(void);
+    int (*suspend)(void);
     void (*resume)(void);
     void (*share_p2m)(struct domain *d);
     void (*crash_shutdown)(void);
@@ -167,7 +167,7 @@ struct iommu_ops {
     void (*dump_p2m_table)(struct domain *d);
 };
 
-void iommu_suspend(void);
+int iommu_suspend(void);
 void iommu_resume(void);
 void iommu_crash_shutdown(void);
 int iommu_get_reserved_device_memory(iommu_grdm_t *, void *);
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#60 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/arch/x86/acpi/power.c +2 -0
@@ -45,19 +45,31 @@ void do_suspend_lowlevel(void);
 
 static int device_power_down(void)
 {
+    int err;
+
     console_suspend();
 

xen/arch/x86/acpi/power.c void do_suspend_lowlevel(void); · line 60

Quoted 10 lines
xen/arch/x86/acpi/power.c +3 -1
     time_suspend();
 
     i8259A_suspend();
 
-    ioapic_suspend();
+    err = iommu_suspend();
+    if ( err )
+        goto iommu_suspend_error;
 
     iommu_suspend();

A little more care please - this is definitely not what you meant.

xen/arch/x86/acpi/power.c void do_suspend_lowlevel(void); · line 72

Quoted 7 lines
xen/arch/x86/acpi/power.c +7 -0
+ iommu_suspend_error:
+    ioapic_resume();
+    i8259A_resume();
+    time_resume();
+    console_resume();
+
+    return err;

Instead of mostly repeating what device_power_up() does I wonder whether it wouldn't be better to re-use that function for the error path here. Either by suitably making information available to device_power_up() to skip the call to lapic_resume() or by making lapic_resume() itself recognize it got called without lapic_suspend() having got called first.

Quoted 12 lines
xen/drivers/passthrough/arm/smmu.c +1 -1
@@ -2540,7 +2540,7 @@ static int force_stage = 2;
  */
 static u32 platform_features = ARM_SMMU_FEAT_COHERENT_WALK;
 
-static void arm_smmu_iotlb_flush_all(struct domain *d)
+static int arm_smmu_iotlb_flush_all(struct domain *d)
 {
 	struct arm_smmu_xen_domain *smmu_domain = domain_hvm_iommu(d)->arch.priv;
 	struct iommu_domain *cfg;

xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iotlb_flush_all(struct domain *d) · line 2562

Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +2 -0
@@ -2557,13 +2557,15 @@ static void arm_smmu_iotlb_flush_all(struct domain *d)
 		arm_smmu_tlb_inv_context(cfg->priv);
 	}
 	spin_unlock(&smmu_domain->lock);
+
+    return 0;
 }

Even if indentation looks inconsistent in this file, please make your addition match surrounding code.

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb_psi( · line 545

Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -542,11 +542,12 @@ static int iommu_flush_iotlb_psi(
     return status;
 }
 
-static void iommu_flush_all(void)
+static int iommu_flush_all(void)

__must_check

xen/drivers/passthrough/vtd/iommu.c static void iommu_flush_all(void) · line 561

Quoted 9 lines
xen/drivers/passthrough/vtd/iommu.c +4 -1
@@ -554,8 +555,13 @@ static void iommu_flush_all(void)
         iommu = drhd->iommu;
         iommu_flush_context_global(iommu, 0);
         flush_dev_iotlb = find_ats_dev_drhd(iommu) ? 1 : 0;
-        iommu_flush_iotlb_global(iommu, 0, flush_dev_iotlb);
+        rc = iommu_flush_iotlb_global(iommu, 0, flush_dev_iotlb);
+
+        if ( rc )
+            break;

This again violates the best effort flushing principle.

xen/drivers/passthrough/vtd/iommu.c static int intel_iommu_group_id(u16 seg, u8 bus, u8 devfn) · line 2430

Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -2421,16 +2427,20 @@ static int intel_iommu_group_id(u16 seg, u8 bus, u8 devfn)
 }
 
 static u32 iommu_state[MAX_IOMMUS][MAX_IOMMU_REGS];
-static void vtd_suspend(void)
+static int vtd_suspend(void)

Please take the opportunity to add the missing blank line between variable and function definition.

Quoted 12 lines
xen/include/xen/iommu.h +1 -1
@@ -157,7 +157,7 @@ struct iommu_ops {
     unsigned int (*read_apic_from_ire)(unsigned int apic, unsigned int reg);
     int (*setup_hpet_msi)(struct msi_desc *);
 #endif /* CONFIG_X86 */
-    void (*suspend)(void);
+    int (*suspend)(void);
     void (*resume)(void);
     void (*share_p2m)(struct domain *d);
     void (*crash_shutdown)(void);

xen/include/xen/iommu.h struct iommu_ops { · line 170

Quoted 5 lines
xen/include/xen/iommu.h +1 -1
@@ -167,7 +167,7 @@ struct iommu_ops {
     void (*dump_p2m_table)(struct domain *d);
 };
 
-void iommu_suspend(void);
+int iommu_suspend(void);

At the very least this one should become __must_check.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#61 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Hi Jan,

Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/arm/smmu.c +0 -0
@@ -2540,7 +2540,7 @@ static int force_stage = 2;
   */
  static u32 platform_features = ARM_SMMU_FEAT_COHERENT_WALK;
 
Quoted 15 lines

xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iotlb_flush_all(struct domain *d) · line 2562

Quoted 12 lines
xen/drivers/passthrough/arm/smmu.c +3 -1
-static void arm_smmu_iotlb_flush_all(struct domain *d)
+static int arm_smmu_iotlb_flush_all(struct domain *d)
  {
  	struct arm_smmu_xen_domain *smmu_domain = domain_hvm_iommu(d)->arch.priv;
  	struct iommu_domain *cfg;
@@ -2557,13 +2557,15 @@ static void arm_smmu_iotlb_flush_all(struct domain *d)
  		arm_smmu_tlb_inv_context(cfg->priv);
  	}
  	spin_unlock(&smmu_domain->lock);
+
+    return 0;
  }

Even if indentation looks inconsistent in this file, please make your addition match surrounding code.

The file smmu.c was imported from Linux and supposed to use only Linux coding style. This is in order to help porting fixes.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#62 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Quoted 23 lines · On April 25, 2016 9:58pm, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich

xen/drivers/passthrough/arm/smmu.c static int force_stage = 2; · line 2545

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/arm/smmu.c +1 -1
@@ -2540,7 +2540,7 @@ static int force_stage = 2;
   */
  static u32 platform_features = ARM_SMMU_FEAT_COHERENT_WALK;
 
-static void arm_smmu_iotlb_flush_all(struct domain *d)
+static int arm_smmu_iotlb_flush_all(struct domain *d)
  {
  	struct arm_smmu_xen_domain *smmu_domain =

domain_hvm_iommu(d)->arch.priv;

Quoted 2 lines

xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iotlb_flush_all(struct

Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +0 -0
  	struct iommu_domain *cfg;
@@ -2557,13 +2557,15 @@ static void arm_smmu_iotlb_flush_all(struct

domain *d)

Quoted 7 lines
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +2 -0
  		arm_smmu_tlb_inv_context(cfg->priv);
  	}
  	spin_unlock(&smmu_domain->lock);
+
+    return 0;
  }
Quoted 6 lines
Quoted 2 lines

Even if indentation looks inconsistent in this file, please make your addition match surrounding code.

The file smmu.c was imported from Linux and supposed to use only Linux coding style. This is in order to help porting fixes.

Julien, A 'tab' ?
Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#63 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Hi Quan,

Quoted 24 lines · Quan
Quoted 23 lines · On April 25, 2016 9:58pm, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich

xen/drivers/passthrough/arm/smmu.c static int force_stage = 2; · line 2545

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/arm/smmu.c +1 -1
@@ -2540,7 +2540,7 @@ static int force_stage = 2;
    */
   static u32 platform_features = ARM_SMMU_FEAT_COHERENT_WALK;
 
-static void arm_smmu_iotlb_flush_all(struct domain *d)
+static int arm_smmu_iotlb_flush_all(struct domain *d)
   {
   	struct arm_smmu_xen_domain *smmu_domain =

domain_hvm_iommu(d)->arch.priv;

Quoted 2 lines

xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iotlb_flush_all(struct

Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +0 -0
   	struct iommu_domain *cfg;
@@ -2557,13 +2557,15 @@ static void arm_smmu_iotlb_flush_all(struct

domain *d)

Quoted 7 lines
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c +2 -0
   		arm_smmu_tlb_inv_context(cfg->priv);
   	}
   	spin_unlock(&smmu_domain->lock);
+
+    return 0;
   }
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Even if indentation looks inconsistent in this file, please make your addition match surrounding code.

The file smmu.c was imported from Linux and supposed to use only Linux coding style. This is in order to help porting fixes.

Julien, A 'tab' ?

Yes, Linux is using hard tabulation for the indentation.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#64 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

In reply to Jan Beulich
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/arch/x86/acpi/power.c +2 -0
@@ -45,19 +45,31 @@ void do_suspend_lowlevel(void);
 
 static int device_power_down(void)
 {
+    int err;
+
     console_suspend();
 
     time_suspend();
 
     i8259A_suspend();
 
Quoted 9 lines

xen/arch/x86/acpi/power.c void do_suspend_lowlevel(void); · line 60

Quoted 6 lines
xen/arch/x86/acpi/power.c +3 -1
-    ioapic_suspend();
+    err = iommu_suspend();
+    if ( err )
+        goto iommu_suspend_error;
 
     iommu_suspend();

A little more care please - this is definitely not what you meant.

Very sorry for this..:(

Quoted 8 lines

xen/arch/x86/acpi/power.c void do_suspend_lowlevel(void); · line 72

Quoted 7 lines
xen/arch/x86/acpi/power.c +7 -0
+ iommu_suspend_error:
+    ioapic_resume();
+    i8259A_resume();
+    time_resume();
+    console_resume();
+
+    return err;
Quoted 7 lines

Instead of mostly repeating what device_power_up() does I wonder whether it wouldn't be better to re-use that function for the error path here. Either by suitably making information available to device_power_up() to skip the call to lapic_resume() or by making lapic_resume() itself recognize it got called without
lapic_suspend() having got called first.

To be honest, now this modification is much more readable to me, however I will reconsider your suggestion.

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#65 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

In reply to Jan Beulich
Quoted 10 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb_psi( · line 545

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +1 -1
 
 
-static void iommu_flush_all(void)
+static int iommu_flush_all(void)

__must_check

The iommu_flush_all() is also called in intel_iommu_hwdom_init() and vtd_crash_shutdown(). As we were on the same page, we can ignore the error code propagation for these two call trees.

I wonder whether we really need this '__must_check' or not, furthermore, print-out message Is pointless (at least, to me).

Jan, could I ignore this '__must_check '?

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#66 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 16:14, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb_psi( · line 545

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +1 -1
 
 
-static void iommu_flush_all(void)
+static int iommu_flush_all(void)

__must_check

Quoted 4 lines

The iommu_flush_all() is also called in intel_iommu_hwdom_init() and vtd_crash_shutdown().
As we were on the same page, we can ignore the error code propagation for these two call trees.

I don't know what you're referring to here with "we were on the same page". I don't think I've ever agreed (in the context of this series) to ignore any error returns.

Jan

Quoted 7 lines

I wonder whether we really need this '__must_check' or not, furthermore, print-out message
Is pointless (at least, to me).

Jan, could I ignore this '__must_check '?

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#67 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 16:14, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb_psi( · line 545

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +1 -1
 
 
-static void iommu_flush_all(void)
+static int iommu_flush_all(void)

__must_check

Quoted 9 lines
Quoted 4 lines

The iommu_flush_all() is also called in intel_iommu_hwdom_init() and vtd_crash_shutdown().
As we were on the same page, we can ignore the error code propagation for these two call trees.

I don't know what you're referring to here with "we were on the same page". I don't think I've ever agreed (in the context of this series) to ignore any error returns.

Look at the below link.
http://lists.xenproject.org/archives/html/xen-devel/2016-02/msg03234.html

I hope I understand this correctly.

Quan

Quoted 12 lines

Jan

Quoted 6 lines

I wonder whether we really need this '__must_check' or not, furthermore, print-out message Is pointless (at least, to me).

Jan, could I ignore this '__must_check '?

Quan

Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#68 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 17:03, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 16:14, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb_psi( · line 545

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +1 -1
 
 
-static void iommu_flush_all(void)
+static int iommu_flush_all(void)

__must_check

Quoted 6 lines
Quoted 4 lines

The iommu_flush_all() is also called in intel_iommu_hwdom_init() and vtd_crash_shutdown().
As we were on the same page, we can ignore the error code propagation for these two call trees.

I don't know what you're referring to here with "we were on the same page".

I

Quoted 8 lines
Quoted 1 line

don't think I've ever agreed (in the context of this series) to ignore any

error

Quoted 2 lines

returns.

Look at the below link.
http://lists.xenproject.org/archives/html/xen-devel/2016-02/msg03234.html

Which still talks about (conditionally) logging messages, not ignoring of errors.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#69 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Quoted 30 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 17:03, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 16:14, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb_psi( · line 545

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +1 -1
 
 
-static void iommu_flush_all(void)
+static int iommu_flush_all(void)

__must_check

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

The iommu_flush_all() is also called in intel_iommu_hwdom_init() and vtd_crash_shutdown().
As we were on the same page, we can ignore the error code propagation for these two call trees.

I don't know what you're referring to here with "we were on the same

page".

Quoted 8 lines

I

Quoted 2 lines

don't think I've ever agreed (in the context of this series) to ignore any

error

Quoted 2 lines

returns.

Quoted 6 lines
Quoted 3 lines

Look at the below link.
http://lists.xenproject.org/archives/html/xen-devel/2016-02/msg03234.h
tml

Which still talks about (conditionally) logging messages, not ignoring of errors.

Sorry, check it again.
in intel_iommu_hwdom_init() and vtd_crash_shutdown(), I still need to log messages as:

if ( iommu_flush_all() )
printk()

?

Thanks for your patience.
Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#70 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Quoted 45 lines

From: Xu, Quan
Sent: Friday, April 29, 2016 12:09 AM

Quoted 30 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 17:03, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 16:14, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +1 -1
 
 
-static void iommu_flush_all(void)
+static int iommu_flush_all(void)

__must_check

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

The iommu_flush_all() is also called in intel_iommu_hwdom_init() and vtd_crash_shutdown().
As we were on the same page, we can ignore the error code propagation for these two call trees.

I don't know what you're referring to here with "we were on the same

page".

Quoted 8 lines

I

Quoted 2 lines

don't think I've ever agreed (in the context of this series) to ignore any

error

Quoted 2 lines

returns.

Quoted 6 lines
Quoted 3 lines

Look at the below link.
http://lists.xenproject.org/archives/html/xen-devel/2016-02/msg03234.h
tml

Which still talks about (conditionally) logging messages, not ignoring of errors.

Sorry, check it again.
in intel_iommu_hwdom_init() and vtd_crash_shutdown(), I still need to log messages as:

Quoted 7 lines

if ( iommu_flush_all() )
printk()

?

Thanks for your patience.
Quan

Yes, but please make sure you only print once to be useful.

Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#71 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Quoted 51 lines · Kevin
Quoted 7 lines

From: Xu, Quan
Sent: Friday, April 29, 2016 12:09 AM

Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 17:03, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 28.04.16 at 16:14, <[email protected]> wrote:

On April 25, 2016 7:53 PM, Jan Beulich <[email protected]>

Quoted 27 lines · wrote:
Quoted 27 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

xen/drivers/passthrough/vtd/iommu.c

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +1 -1
 
 
-static void iommu_flush_all(void)
+static int iommu_flush_all(void)

__must_check

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

The iommu_flush_all() is also called in intel_iommu_hwdom_init() and vtd_crash_shutdown(). As we were on the same page, we can ignore the error code propagation for these two call trees.

I don't know what you're referring to here with "we were on the same

page".

Quoted 8 lines

I

Quoted 2 lines

don't think I've ever agreed (in the context of this series) to ignore any

error

Quoted 2 lines

returns.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Look at the below link.
http://lists.xenproject.org/archives/html/xen-devel/2016-02/msg032
34.h
tml

Which still talks about (conditionally) logging messages, not ignoring of

errors.

Quoted 9 lines
Quoted 1 line

Sorry, check it again.
in intel_iommu_hwdom_init() and vtd_crash_shutdown(), I still need to log messages as:

if ( iommu_flush_all() )
printk()

Quoted 7 lines
Quoted 4 lines

?

Thanks for your patience.
Quan

Yes, but please make sure you only print once to be useful.

Thanks.
Now I check the status in caller to make the print include caller which is failed, instead print in iommu_flush_all(). i.e.,
vtd_crash_shutdown()
{
..
if ( iommu_flush_all() )
printk(XENLOG_WARNING VTDPREFIX
" vtd_crash_shutdown: IOMMU flush all failed.\n");
..
}

I am afraid I still don't get the point. To be honest, in such a fix, The print is not so useful to me ( Correct me, I will continue to enhance it).

Quan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#72 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 29.04.16 at 04:41, <[email protected]> wrote:

Now I check the status in caller to make the print include caller which is failed, instead print in iommu_flush_all().
i.e.,
vtd_crash_shutdown()
{
..
if ( iommu_flush_all() )
printk(XENLOG_WARNING VTDPREFIX
" vtd_crash_shutdown: IOMMU flush all failed.\n");
..
}

Quoted 3 lines

I am afraid I still don't get the point. To be honest, in such a fix, The print is not so useful to me ( Correct me, I will continue to enhance it).

So do you think it would be more useful to leave the admin with no clue why a system misbehaves, instead of providing clear indication? IOW - what usefulness concerns do you have?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#73 lore raw

Re: [PATCH v2 09/11] IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 29.04.16 at 04:41, <[email protected]> wrote:

Now I check the status in caller to make the print include caller which is failed, instead print in iommu_flush_all(). i.e.,
vtd_crash_shutdown()
{
..
if ( iommu_flush_all() )
printk(XENLOG_WARNING VTDPREFIX
" vtd_crash_shutdown: IOMMU flush all failed.\n"); ..
}

Quoted 8 lines
Quoted 3 lines

I am afraid I still don't get the point. To be honest, in such a fix, The print is not so useful to me ( Correct me, I will continue to enhance it).

So do you think it would be more useful to leave the admin with no clue why a system misbehaves, instead of providing clear indication?
IOW - what usefulness concerns do you have?

Jan, I will follow your suggestion for v3. I look forward to hearing the other CCed maintainers' opinions on this.

...
i.e., In above case, in case I am an admin, I may be much more interested in what causes vt-d crash, keeping quite during crash. It is just a matter of my personal preference. Ignore me.
...

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#74 lore raw

PATCH v2 10/11 vt-d: propagate IOMMU Device-TLB flush error up to vt-d hardware initialization

In reply to Quan Xu

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to vt-d hardware initialization.

CC Jan Beulich <[email protected]>
CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
---
 xen/drivers/passthrough/vtd/iommu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/drivers/passthrough/vtd/iommu.c +2 -2
index a821306..223522f 100644
@@ -2137,8 +2137,8 @@ static int init_vtd_hw(void)
             return -EIO;
         }
     }
-    iommu_flush_all();
-    return 0;
+
+    return iommu_flush_all();
 }
 
 static void __hwdom_init setup_hwdom_rmrr(struct domain *d)
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#75 lore raw

PATCH v2 11/11 vt-d: propagate error up to ME phantom function mapping and unmapping

In reply to Quan Xu

While IOMMU Device-TLB flush timed out, xen calls panic() at present. However the existing panic() is going to be eliminated, so we must propagate the IOMMU Device-TLB flush error up to ME phantom function mapping and unmapping.

CC Jan Beulich <[email protected]>
CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
---
 xen/drivers/passthrough/vtd/extern.h |  2 +-
 xen/drivers/passthrough/vtd/quirks.c | 26 ++++++++++++++++----------
 2 files changed, 17 insertions(+), 11 deletions(-)
xen/drivers/passthrough/vtd/extern.h +1 -1
index cbe0286..d4d37c3 100644
@@ -91,7 +91,7 @@ int is_igd_vt_enabled_quirk(void);
 void platform_quirks_init(void);
 void vtd_ops_preamble_quirk(struct iommu* iommu);
 void vtd_ops_postamble_quirk(struct iommu* iommu);
-void me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map);
+int me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map);
 void pci_vtd_quirk(const struct pci_dev *);
 bool_t platform_supports_intremap(void);
 bool_t platform_supports_x2apic(void);
xen/drivers/passthrough/vtd/quirks.c +16 -10
index 49df41d..c6d9a03 100644
@@ -332,10 +332,11 @@ void __init platform_quirks_init(void)
  * assigning Intel integrated wifi device to a guest.
  */
 
-static void map_me_phantom_function(struct domain *domain, u32 dev, int map)
+static int map_me_phantom_function(struct domain *domain, u32 dev, int map)
 {
     struct acpi_drhd_unit *drhd;
     struct pci_dev *pdev;
+    int rc;
 
     /* find ME VT-d engine base on a real ME device */
     pdev = pci_get_pdev(0, 0, PCI_DEVFN(dev, 0));
@@ -343,23 +344,26 @@ static void map_me_phantom_function(struct domain *domain, u32 dev, int map)
 
     /* map or unmap ME phantom function */
     if ( map )
-        domain_context_mapping_one(domain, drhd->iommu, 0,
-                                   PCI_DEVFN(dev, 7), NULL);
+        rc = domain_context_mapping_one(domain, drhd->iommu, 0,
+                                        PCI_DEVFN(dev, 7), NULL);
     else
-        domain_context_unmap_one(domain, drhd->iommu, 0,
-                                 PCI_DEVFN(dev, 7));
+        rc = domain_context_unmap_one(domain, drhd->iommu, 0,
+                                      PCI_DEVFN(dev, 7));
+
+    return rc;
 }
 
-void me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map)
+int me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map)
 {
     u32 id;
+    int rc = 0;
 
     id = pci_conf_read32(0, 0, 0, 0, 0);
     if ( IS_CTG(id) )
     {
         /* quit if ME does not exist */
         if ( pci_conf_read32(0, 0, 3, 0, 0) == 0xffffffff )
-            return;
+            return 0;
 
         /* if device is WLAN device, map ME phantom device 0:3.7 */
         id = pci_conf_read32(0, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), 0);
@@ -373,7 +377,7 @@ void me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map)
             case 0x423b8086:
             case 0x423c8086:
             case 0x423d8086:
-                map_me_phantom_function(domain, 3, map);
+                rc = map_me_phantom_function(domain, 3, map);
                 break;
             default:
                 break;
@@ -383,7 +387,7 @@ void me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map)
     {
         /* quit if ME does not exist */
         if ( pci_conf_read32(0, 0, 22, 0, 0) == 0xffffffff )
-            return;
+            return 0;
 
         /* if device is WLAN device, map ME phantom device 0:22.7 */
         id = pci_conf_read32(0, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), 0);
@@ -399,12 +403,14 @@ void me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map)
             case 0x42388086:        /* Puma Peak */
             case 0x422b8086:
             case 0x422c8086:
-                map_me_phantom_function(domain, 22, map);
+                rc = map_me_phantom_function(domain, 22, map);
                 break;
             default:
                 break;
         }
     }
+
+    return rc;
 }
 
 void pci_vtd_quirk(const struct pci_dev *pdev)
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#76 lore raw

Re: [PATCH v2 11/11] vt-d: propagate error up to ME phantom function mapping and unmapping

xen/drivers/passthrough/vtd/extern.h int is_igd_vt_enabled_quirk(void); · line 94

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/extern.h +1 -1
@@ -91,7 +91,7 @@ int is_igd_vt_enabled_quirk(void);
 void platform_quirks_init(void);
 void vtd_ops_preamble_quirk(struct iommu* iommu);
 void vtd_ops_postamble_quirk(struct iommu* iommu);
-void me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map);
+int me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map);

__must_check

xen/drivers/passthrough/vtd/quirks.c void __init platform_quirks_init(void) · line 335

Quoted 8 lines
xen/drivers/passthrough/vtd/quirks.c +1 -1
@@ -332,10 +332,11 @@ void __init platform_quirks_init(void)
  * assigning Intel integrated wifi device to a guest.
  */
 
-static void map_me_phantom_function(struct domain *domain, u32 dev, int map)
+static int map_me_phantom_function(struct domain *domain, u32 dev, int map)

Again.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#77 lore raw

Re: [PATCH v2 11/11] vt-d: propagate error up to ME phantom function mapping and unmapping

Quoted 11 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 18.04.16 at 16:00, <[email protected]> wrote:
xen/drivers/passthrough/vtd/extern.h +0 -0
@@ -91,7 +91,7 @@ int is_igd_vt_enabled_quirk(void);  void

platform_quirks_init(void); void vtd_ops_preamble_quirk(struct iommu* iommu); void vtd_ops_postamble_quirk(struct iommu* iommu); -void me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map); +int me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map);

__must_check

Agreed, I will add it in next v3.

Quoted 6 lines
Quoted 6 lines
xen/drivers/passthrough/vtd/quirks.c +0 -0
@@ -332,10 +332,11 @@ void __init platform_quirks_init(void)
  * assigning Intel integrated wifi device to a guest.
  */
 
Quoted 7 lines

xen/drivers/passthrough/vtd/quirks.c void __init platform_quirks_init(void) · line 337

Quoted 4 lines
xen/drivers/passthrough/vtd/quirks.c +2 -1
-static void map_me_phantom_function(struct domain *domain, u32 dev,
 int map)
+static int map_me_phantom_function(struct domain *domain, u32 dev,
+int map)

Again.

Ditto.

Quan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel