Skip to contentSkip to conversation

Check VT-d Device-TLB flush error

PATCH Superseded Quan Xu 3 participants 64 messages May 6, 2016 – May 13, 2016

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Quan Xu

author
#0 lore raw

v4 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'

Quan Xu (10):
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
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).
vt-d/ept: propagate IOMMU Device-TLB flush error up to EPT update.
IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending
vt-d: propagate error up to ME phantom function mapping and unmapping

 xen/arch/arm/p2m.c                            |   5 +-
 xen/arch/x86/acpi/power.c                     |  72 ++++++++---
 xen/arch/x86/mm.c                             |  13 +-
 xen/arch/x86/mm/p2m-ept.c                     |  43 +++++--
 xen/arch/x86/mm/p2m-pt.c                      |  26 +++-
 xen/arch/x86/mm/p2m.c                         |  11 +-
 xen/common/memory.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            |  12 +-
 xen/drivers/passthrough/iommu.c               |  64 ++++++++--
 xen/drivers/passthrough/vtd/extern.h          |   3 +-
 xen/drivers/passthrough/vtd/iommu.c           | 168 ++++++++++++++++++--------
 xen/drivers/passthrough/vtd/quirks.c          |  28 +++--
 xen/drivers/passthrough/x86/iommu.c           |   5 +-
 xen/include/asm-x86/hvm/svm/amd-iommu-proto.h |   2 +-
 xen/include/asm-x86/iommu.h                   |   3 +-
 xen/include/xen/iommu.h                       |  13 +-
 18 files changed, 360 insertions(+), 133 deletions(-)
Signature · 7 lines
1.9.1


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

PATCH v4 1/10 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 | 99 ++++++++++++++++++++++++-------------
 xen/include/asm-x86/iommu.h         |  2 +-
 2 files changed, 65 insertions(+), 36 deletions(-)
xen/drivers/passthrough/vtd/iommu.c +64 -35
index db83949..64093a9 100644
@@ -557,14 +557,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,
+                             bool_t dma_old_pte_present,
+                             unsigned int page_count)
 {
     struct domain_iommu *hd = dom_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
@@ -583,29 +585,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;
         }
     }
+
+    return rc;
 }
 
-static void intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
+static void iommu_flush_iotlb_page(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)
+static void iommu_flush_iotlb_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 */
@@ -639,7 +646,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);
 }
@@ -1278,6 +1285,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);
@@ -1391,13 +1399,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);
@@ -1407,7 +1421,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(
@@ -1502,6 +1516,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);
@@ -1529,14 +1544,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);
@@ -1545,7 +1566,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(
@@ -1734,7 +1755,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;
 }
@@ -1750,14 +1771,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, bool_t present)
 {
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu = NULL;
     struct domain_iommu *hd = dom_iommu(d);
     int flush_dev_iotlb;
     int iommu_domid;
+    int rc = 0;
 
     iommu_flush_cache_entry(pte, sizeof(struct dma_pte));
 
@@ -1771,11 +1793,18 @@ 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;
+        }
     }
+
+    return rc;
 }
 
 static int __init vtd_ept_page_compatible(struct iommu *iommu)
@@ -2553,8 +2582,8 @@ const struct iommu_ops intel_iommu_ops = {
     .resume = vtd_resume,
     .share_p2m = iommu_set_pgd,
     .crash_shutdown = vtd_crash_shutdown,
-    .iotlb_flush = intel_iommu_iotlb_flush,
-    .iotlb_flush_all = intel_iommu_iotlb_flush_all,
+    .iotlb_flush = iommu_flush_iotlb_page,
+    .iotlb_flush_all = iommu_flush_iotlb_all,
     .get_reserved_device_memory = intel_iommu_get_reserved_device_memory,
     .dump_p2m_table = vtd_dump_p2m_table,
 };
xen/include/asm-x86/iommu.h +1 -1
index e82a2f0..43f1620 100644
@@ -27,7 +27,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, bool_t 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 v4 01/10] vt-d: fix the IOMMU flush issue

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

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +2 -1
-static void intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
+static void iommu_flush_iotlb_page(struct domain *d, unsigned long gfn,
+                                   unsigned int page_count)

The new name suggests just one page. Please use e.g. iommu_flush_iotlb_pages() instead.

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

Quoted 4 lines

{

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);
 }

But of course the question is whether having this wrapper is useful in the first place, the more that ...

xen/drivers/passthrough/vtd/iommu.c static void dma_pte_clear_one(struct domain *domain, u64 addr) · line 649

Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -639,7 +646,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);

... it's being open coded here. IOW if you want to retain the wrapper, please use it here.

Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +0 -2
@@ -1391,13 +1399,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) )

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

Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.c +5 -3
-        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);

Please take the opportunity and add the missing blank line (between declaration(s) and statement(s) in cases like this.

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

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+    }
+
+    if ( rc > 0 )

Can iommu_flush_context_device() return a positive value? If so, the logic is now likely wrong. If not (which is what I assume) I'd like to suggest adding a respective ASSERT() (even if only to document the fact). Or alternatively this if() could move into the immediately preceding one.

Jan

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

author
#3 lore raw

Re: [PATCH v4 01/10] vt-d: fix the IOMMU flush issue

Quoted 9 lines · Jan Beulich

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

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

-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 void iommu_flush_iotlb_page(struct domain *d, unsigned long gfn,
+                                   unsigned int page_count)

The new name suggests just one page. Please use e.g. iommu_flush_iotlb_pages() instead.

Make sense.

Quoted 7 lines

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

Quoted 4 lines

{

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);
 }

But of course the question is whether having this wrapper is useful in the first place,

This wrapper assumes the 'dma_old_pte_present' is '1', but in another caller intel_iommu_map_page(), i.e.

     intel_iommu_map_page()
    {
       ...
             if ( !this_cpu(iommu_dont_flush_iotlb) )
                  iommu_flush_iotlb(d, gfn, dma_pte_present(old), 1);
       ...
    }

the 'dma_old_pte_present' is not sure.

in intel_iommu_map_page(), if we can check the 'dma_pte_present(old)':
-- 1, flush the pages.
-- 0, don't flush the pages.

Then we can remove this wrapper.

If my description is not clear, I can send out the related change.

Quoted 4 lines

the more that ...

Review static void dma_pte_clear_one(struct domain

Quoted 1 line
(quoted diff) +0 -0
@@ -639,7 +646,7 @@ static void dma_pte_clear_one(struct domain

*domain, u64 addr)

Quoted 9 lines

xen/drivers/passthrough/vtd/iommu.c static void dma_pte_clear_one(struct domain *domain, u64 addr) · line 649

Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
     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);

... it's being open coded here. IOW if you want to retain the wrapper, please use it here.

Waiting for the above discussion, if we still need the wrapper, I will use it here.

Quoted 20 lines
Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +0 -2
@@ -1391,13 +1399,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) )

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

Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.c +5 -3
-        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);

Please take the opportunity and add the missing blank line (between declaration(s) and statement(s) in cases like this.

Quoted 9 lines

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

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+    }
+
+    if ( rc > 0 )

Can iommu_flush_context_device() return a positive value? If so, the logic is now likely wrong. If not (which is what I assume) I'd like to suggest adding a respective ASSERT() (even if only to document the fact). Or alternatively this if() could move into the immediately preceding one.

Check it again. iommu_flush_context_device() can return a positive value.

If VT-d QI is enabled, the call tree up to iommu_flush_context_device():
-- flush_context_qi() -- iommu_flush_context_device()

i.e.

In flush_context_qi()
{
...

    if ( flush_non_present_entry )
    {
        if ( !cap_caching_mode(iommu->cap) )
            return 1;
        else
            did = 0;
    }

...
}

and the ' flush_non_present_entry ' is really '1' for above code.

Could you tell me why the logic is now likely wrong? I will fix it first.

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

#4 lore raw

Re: [PATCH v4 01/10] vt-d: fix the IOMMU flush issue

Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 09:50, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich

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

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

-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 void iommu_flush_iotlb_page(struct domain *d, unsigned long gfn,
+                                   unsigned int page_count)

The new name suggests just one page. Please use e.g. iommu_flush_iotlb_pages() instead.

Make sense.

Quoted 7 lines

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

Quoted 4 lines

{

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);
 }

But of course the question is whether having this wrapper is useful in the first place,

This wrapper assumes the 'dma_old_pte_present' is '1', but in another caller intel_iommu_map_page(), i.e.

     intel_iommu_map_page()
    {
       ...
             if ( !this_cpu(iommu_dont_flush_iotlb) )
                  iommu_flush_iotlb(d, gfn, dma_pte_present(old), 1);
       ...
    }
Quoted 1 line

the 'dma_old_pte_present' is not sure.

I'm sorry, but you're looking at this backwards: I suggested to remove the wrapper, not to move any check into iommu_flush_iotlb(). Removing the wrapper simply means to move the passing of the hard coded 1 into the current callers of that wrapper.

Quoted 24 lines
Quoted 24 lines
Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +0 -2
@@ -1391,13 +1399,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) )

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

Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.c +5 -3
-        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);

Please take the opportunity and add the missing blank line (between declaration(s) and statement(s) in cases like this.

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+    }
+
+    if ( rc > 0 )
Quoted 8 lines
Quoted 4 lines

Can iommu_flush_context_device() return a positive value? If so, the logic is now likely wrong. If not (which is what I assume) I'd like to suggest adding a respective ASSERT() (even if only to document the fact). Or alternatively this if() could move into the immediately preceding one.

Check it again. iommu_flush_context_device() can return a positive value. [...]
Could you tell me why the logic is now likely wrong? I will fix it first.

With

    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;
        rc = iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
    }

    if ( rc > 0 )
    {
        iommu_flush_write_buffer(iommu);
        rc = 0;
    }

it seems pretty clear that you won't call iommu_flush_iotlb_dsi() if iommu_flush_context_device() returned 1, which doesn't look like what is wanted at the first glance. But I may be wrong, hence the "likely" in my earlier reply.

Jan

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

author
#5 lore raw

Re: [PATCH v4 01/10] vt-d: fix the IOMMU flush issue

Quoted 37 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 09:50, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

-static void intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
+static void iommu_flush_iotlb_page(struct domain *d, unsigned long

gfn,

Quoted 30 lines
Quoted 5 lines
Quoted 1 line

+ unsigned int page_count)

The new name suggests just one page. Please use e.g. iommu_flush_iotlb_pages() instead.

Make sense.

Quoted 7 lines

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

Quoted 4 lines

{

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);
 }

But of course the question is whether having this wrapper is useful in the first place,

This wrapper assumes the 'dma_old_pte_present' is '1', but in another caller intel_iommu_map_page(), i.e.

     intel_iommu_map_page()
    {
       ...
             if ( !this_cpu(iommu_dont_flush_iotlb) )
                  iommu_flush_iotlb(d, gfn, dma_pte_present(old), 1);
       ...
    }
Quoted 7 lines
Quoted 1 line

the 'dma_old_pte_present' is not sure.

I'm sorry, but you're looking at this backwards: I suggested to remove the wrapper, not to move any check into iommu_flush_iotlb(). Removing the wrapper simply means to move the passing of the hard coded 1 into the current callers of that wrapper.

A little bit confused.
Check one thing, do the wrappers refer to iommu_flush_iotlb_page() and iommu_flush_iotlb_all() ?

If yes, we can't ignore another thing:

These two wrappers are also initialized for 2 .callbacks at the bottom of this file:

....
.iotlb_flush = iommu_flush_iotlb_pages,
.iotlb_flush_all = iommu_flush_iotlb_all,
....

Quoted 52 lines
Quoted 9 lines
Quoted 9 lines

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

Quoted 9 lines
xen/drivers/passthrough/vtd/iommu.c +1 -4
@@ -1391,13 +1399,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,

Quoted 21 lines
Quoted 15 lines

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

Quoted 7 lines
xen/drivers/passthrough/vtd/iommu.c +4 -1
+                                    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);

Please take the opportunity and add the missing blank line (between declaration(s) and statement(s) in cases like this.

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

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+    }
+
+    if ( rc > 0 )
Quoted 5 lines

Can iommu_flush_context_device() return a positive value? If so, the logic is now likely wrong. If not (which is what I assume) I'd like to suggest adding a respective ASSERT() (even if only to document the fact). Or alternatively this
if() could move into the immediately preceding one.

Quoted 3 lines

Check it again. iommu_flush_context_device() can return a positive value. [...]
Could you tell me why the logic is now likely wrong? I will fix it first.

With

    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;
        rc = iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
    }

    if ( rc > 0 )
    {
        iommu_flush_write_buffer(iommu);
        rc = 0;
    }
Quoted 5 lines

it seems pretty clear that you won't call iommu_flush_iotlb_dsi() if iommu_flush_context_device() returned 1, which doesn't look like what is wanted at the first glance. But I may be wrong, hence the "likely" in my earlier reply.

Oh, this was on purpose.

If iommu_flush_context_device() returned 1, the iommu_flush_iotlb_dsi() returned 1 too. As both flush_context_qi() and flush_iotlb_qi () are the same at the beginning of the functions.

One concern is if iommu_flush_context_device() is failed, then we won't call iommu_flush_iotlb_dsi(), which is not best effort to flush.

Quan

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

#6 lore raw

Re: [PATCH v4 01/10] vt-d: fix the IOMMU flush issue

Quoted 53 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 15:29, <[email protected]> wrote:
Quoted 37 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 09:50, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

-static void intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
+static void iommu_flush_iotlb_page(struct domain *d, unsigned long

gfn,

Quoted 30 lines
Quoted 5 lines
Quoted 1 line

+ unsigned int page_count)

The new name suggests just one page. Please use e.g. iommu_flush_iotlb_pages() instead.

Make sense.

Quoted 7 lines

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

Quoted 4 lines

{

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);
 }

But of course the question is whether having this wrapper is useful in the first place,

This wrapper assumes the 'dma_old_pte_present' is '1', but in another caller intel_iommu_map_page(), i.e.

     intel_iommu_map_page()
    {
       ...
             if ( !this_cpu(iommu_dont_flush_iotlb) )
                  iommu_flush_iotlb(d, gfn, dma_pte_present(old), 1);
       ...
    }
Quoted 7 lines
Quoted 1 line

the 'dma_old_pte_present' is not sure.

I'm sorry, but you're looking at this backwards: I suggested to remove the wrapper, not to move any check into iommu_flush_iotlb(). Removing the wrapper simply means to move the passing of the hard coded 1 into the current callers of that wrapper.

A little bit confused.
Check one thing, do the wrappers refer to iommu_flush_iotlb_page() and iommu_flush_iotlb_all() ?

If yes, we can't ignore another thing:

Quoted 7 lines

These two wrappers are also initialized for 2 .callbacks at the bottom of this file:

....
.iotlb_flush = iommu_flush_iotlb_pages,
.iotlb_flush_all = iommu_flush_iotlb_all,
....

Ah, good point. With the renaming going on I didn't realize these are used here. So in fact they're not just wrappers. Please disregard my respective comments then.

Quoted 59 lines
Quoted 52 lines
Quoted 9 lines
Quoted 9 lines

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

Quoted 9 lines
xen/drivers/passthrough/vtd/iommu.c +1 -4
@@ -1391,13 +1399,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,

Quoted 21 lines
Quoted 15 lines

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

Quoted 7 lines
xen/drivers/passthrough/vtd/iommu.c +4 -1
+                                    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);

Please take the opportunity and add the missing blank line (between declaration(s) and statement(s) in cases like this.

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

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+    }
+
+    if ( rc > 0 )
Quoted 5 lines

Can iommu_flush_context_device() return a positive value? If so, the logic is now likely wrong. If not (which is what I assume) I'd like to suggest adding a respective ASSERT() (even if only to document the fact). Or alternatively this
if() could move into the immediately preceding one.

Quoted 3 lines

Check it again. iommu_flush_context_device() can return a positive value. [...]
Could you tell me why the logic is now likely wrong? I will fix it first.

With

    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;
        rc = iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
    }

    if ( rc > 0 )
    {
        iommu_flush_write_buffer(iommu);
        rc = 0;
    }
Quoted 3 lines

it seems pretty clear that you won't call iommu_flush_iotlb_dsi() if iommu_flush_context_device() returned 1, which doesn't look like what is wanted at the first glance. But I may be wrong, hence the "likely" in my

earlier

Quoted 2 lines

reply.

Quoted 6 lines

Oh, this was on purpose.

If iommu_flush_context_device() returned 1, the iommu_flush_iotlb_dsi() returned 1 too.
As both flush_context_qi() and flush_iotlb_qi () are the same at the beginning of the functions.

Such implications need to be commented on, so readers (like me) don't assume brokenness.

Quoted 2 lines

One concern is if iommu_flush_context_device() is failed, then we won't call iommu_flush_iotlb_dsi(), which is not best effort to flush.

Indeed.

Jan

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

author
#7 lore raw

Re: [PATCH v4 01/10] vt-d: fix the IOMMU flush issue

Quoted 71 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 15:29, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 09:50, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich

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

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -1
@@ -1391,13 +1399,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,

Quoted 60 lines
Quoted 50 lines
Quoted 5 lines
Quoted 5 lines

xen/drivers/passthrough/vtd/iommu.c int domain_context_mapping_one(

Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +2 -3
-                                    DMA_CCMD_MASK_NOBIT, 1) )
-        iommu_flush_write_buffer(iommu);
-    else
+    rc = iommu_flush_context_device(iommu, 0, (((u16)bus) << 8)
+ |

devfn,

Quoted 23 lines
Quoted 17 lines

xen/drivers/passthrough/vtd/iommu.c int domain_context_mapping_one(

Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +5 -1
+                                    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);

Please take the opportunity and add the missing blank line (between
declaration(s) and statement(s) in cases like this.

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

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +3 -0
+    }
+
+    if ( rc > 0 )
Quoted 5 lines

Can iommu_flush_context_device() return a positive value? If so, the logic is now likely wrong. If not (which is what I assume) I'd like to suggest adding a respective ASSERT() (even if only to document the fact). Or alternatively this
if() could move into the immediately preceding one.

Quoted 3 lines

Check it again. iommu_flush_context_device() can return a positive value. [...]
Could you tell me why the logic is now likely wrong? I will fix it first.

With

    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;
        rc = iommu_flush_iotlb_dsi(iommu, 0, 1, flush_dev_iotlb);
    }

    if ( rc > 0 )
    {
        iommu_flush_write_buffer(iommu);
        rc = 0;
    }
Quoted 4 lines

it seems pretty clear that you won't call iommu_flush_iotlb_dsi() if iommu_flush_context_device() returned 1, which doesn't look like what is wanted at the first glance. But I may be wrong, hence the "likely" in my

earlier

Quoted 2 lines

reply.

Oh, this was on purpose.

Quoted 8 lines
Quoted 4 lines

If iommu_flush_context_device() returned 1, the iommu_flush_iotlb_dsi() returned 1 too.
As both flush_context_qi() and flush_iotlb_qi () are the same at the beginning of the functions.

Such implications need to be commented on, so readers (like me) don't assume brokenness.

ok, I will add a comment.

Quoted 5 lines
Quoted 2 lines

One concern is if iommu_flush_context_device() is failed, then we won't call iommu_flush_iotlb_dsi(), which is not best effort to flush.

Indeed.

I'll fix it as well.

Quan

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

author
#8 lore raw

PATCH v4 2/10 IOMMU: handle IOMMU mapping and unmapping failures

In reply to Quan Xu

Treat IOMMU mapping and unmapping failures 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]>
CC Kevin Tian <[email protected]>
---
 xen/drivers/passthrough/iommu.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
xen/drivers/passthrough/iommu.c +28 -2
index c59b2ab..09560c0 100644
@@ -240,21 +240,47 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
                    unsigned int flags)
 {
     const struct domain_iommu *hd = dom_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 ( unlikely(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)
 {
     const struct domain_iommu *hd = dom_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 ( unlikely(rc) )
+    {
+        printk(XENLOG_ERR
+               "iommu_unmap_page: IOMMU unmapping gfn %#lx failed for dom%d.",
+               gfn, d->domain_id);
+
+        if ( !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
#9 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +2 -1
@@ -240,21 +240,47 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
                    unsigned int flags)
 {
     const struct domain_iommu *hd = dom_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);

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

Quoted 10 lines
xen/drivers/passthrough/iommu.c +10 -0
+
+    if ( unlikely(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);
+    }

This still may spam the console in at least the case of Dom0. For DomU I'd really expect you to state in the commit message why no spamming can occur (of course assuming it really can't, which I'm not convinced of).

Jan

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

author
#10 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 19 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 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +0 -0
@@ -240,21 +240,47 @@ int iommu_map_page(struct domain *d,

unsigned long gfn, unsigned long mfn,

Quoted 4 lines
xen/drivers/passthrough/iommu.c +1 -0
                    unsigned int flags)  {
     const struct domain_iommu *hd = dom_iommu(d);
+    int rc;
 

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

Quoted 10 lines
xen/drivers/passthrough/iommu.c +6 -1
     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 ( unlikely(rc) )
+    {
+        printk(XENLOG_ERR
+               "iommu_map_page: IOMMU mapping gfn %#lx mfn %#lx failed for
Quoted 8 lines

dom%d.",

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

Quoted 5 lines
xen/drivers/passthrough/iommu.c +5 -0
+               gfn, mfn, d->domain_id);
+
+        if ( !is_hardware_domain(d) )
+            domain_crash(d);
+    }

This still may spam the console in at least the case of Dom0.

I am afraid we may need a minor trade-off. What about:

       dprintk(XENLOG_ERR, "...");

to print out in debug mode.

Quoted 4 lines

For DomU I'd
really expect you to state in the commit message why no spamming can occur (of course assuming it really can't, which I'm not convinced of).

In this v4, I think we will still spam the console in extreme cases :(:(..

For mapping:

+                ret = iommu_map_page();
+                if ( unlikely(ret) )
+                {

+ while ( i-- )
+ iommu_unmap_page();
+ }

We'll stop map against any error and unmapping the previous mappings. The extreme case is error for unmapping the previous mappings.

Again -- I think dprintk is a better solution. Any suggestion?

Quan

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

#11 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 05:41, <[email protected]> wrote:
Quoted 26 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 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +0 -0
@@ -240,21 +240,47 @@ int iommu_map_page(struct domain *d,

unsigned long gfn, unsigned long mfn,

Quoted 4 lines
xen/drivers/passthrough/iommu.c +1 -0
                    unsigned int flags)  {
     const struct domain_iommu *hd = dom_iommu(d);
+    int rc;
 

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

Quoted 10 lines
xen/drivers/passthrough/iommu.c +6 -1
     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 ( unlikely(rc) )
+    {
+        printk(XENLOG_ERR
+               "iommu_map_page: IOMMU mapping gfn %#lx mfn %#lx failed for

dom%d.",

Quoted 5 lines
xen/drivers/passthrough/iommu.c +5 -0
+               gfn, mfn, d->domain_id);
+
+        if ( !is_hardware_domain(d) )
+            domain_crash(d);
+    }
Quoted 7 lines
Quoted 1 line

This still may spam the console in at least the case of Dom0.

I am afraid we may need a minor trade-off. What about:

       dprintk(XENLOG_ERR, "...");

to print out in debug mode.

And be silent in non-debug mode? That's not what we want.

Quoted 15 lines
Quoted 4 lines

For DomU I'd
really expect you to state in the commit message why no spamming can occur (of course assuming it really can't, which I'm not convinced of).

In this v4, I think we will still spam the console in extreme cases :(:(..

For mapping:

(quoted diff) +6 -0
+                ret = iommu_map_page();
+                if ( unlikely(ret) )
+                {
+                    while ( i-- )
+                        iommu_unmap_page();
+                }
Quoted 4 lines

We'll stop map against any error and unmapping the previous mappings. The extreme case is error for unmapping the previous mappings.

Again -- I think dprintk is a better solution. Any suggestion?

For DomU the solution seems quite obvious: Only log a message if the domain is not already marked crashed. For Dom0 you'll need to get a little more creative (but by leveraging the fact that there's only one in the system, this can't be too difficult a problem to solve:
e.g. "manually" rate limit these messages - see printk_ratelimit() et al).

Jan

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

author
#12 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 31 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 05:41, <[email protected]> wrote:
Quoted 28 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 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +0 -0
@@ -240,21 +240,47 @@ int iommu_map_page(struct domain *d,

unsigned long gfn, unsigned long mfn,

Quoted 5 lines
xen/drivers/passthrough/iommu.c +1 -0
                    unsigned int flags)  {
     const struct domain_iommu *hd = dom_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,

Quoted 10 lines
xen/drivers/passthrough/iommu.c +7 -1
         return 0;
 
-    return hd->platform_ops->map_page(d, gfn, mfn, flags);
+    rc = hd->platform_ops->map_page(d, gfn, mfn, flags);
+
+    if ( unlikely(rc) )
+    {
+        printk(XENLOG_ERR
+               "iommu_map_page: IOMMU mapping gfn %#lx mfn %#lx
+ failed for

dom%d.",

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

Quoted 5 lines
xen/drivers/passthrough/iommu.c +5 -0
+               gfn, mfn, d->domain_id);
+
+        if ( !is_hardware_domain(d) )
+            domain_crash(d);
+    }

This still may spam the console in at least the case of Dom0.

Quoted 8 lines
Quoted 5 lines

I am afraid we may need a minor trade-off. What about:

       dprintk(XENLOG_ERR, "...");

to print out in debug mode.

And be silent in non-debug mode? That's not what we want.

Without your below suggestion, this is really my best solution.

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines

For DomU I'd
really expect you to state in the commit message why no spamming can occur (of course assuming it really can't, which I'm not convinced of).

In this v4, I think we will still spam the console in extreme cases :(:(..

For mapping:

(quoted diff) +6 -0
+                ret = iommu_map_page();
+                if ( unlikely(ret) )
+                {
+                    while ( i-- )
+                        iommu_unmap_page();
+                }

We'll stop map against any error and unmapping the previous mappings. The extreme case is error for unmapping the previous mappings.

Quoted 7 lines
Quoted 1 line

Again -- I think dprintk is a better solution. Any suggestion?

For DomU the solution seems quite obvious: Only log a message if the domain is not already marked crashed. For Dom0 you'll need to get a little more creative (but by leveraging the fact that there's only one in the system, this can't be too difficult a problem to solve:
e.g. "manually" rate limit these messages - see printk_ratelimit() et al).

Amazing!!
As the comment said, printk_ratelimit() is lifted from Linux. referred to the Linux, __iiuc__ , I will fix this issue as below (a variant):

...
+ rc = hd->platform_ops->unmap_page(d, gfn);
+
+ if ( unlikely(rc) )
+ {
+ if ( printk_ratelimit() )
+ printk(XENLOG_ERR
+ "iommu_unmap_page: IOMMU unmapping gfn %#lx failed for dom%d.",
+ gfn, d->domain_id);
+
+ if ( !is_hardware_domain(d) )
+ domain_crash(d);
+ }
+
+ return rc;
...

Thanks!!

Quan

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

#13 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 09:53, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +4 -0
+    rc = hd->platform_ops->unmap_page(d, gfn);
+
+    if ( unlikely(rc) )
+    {

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

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

But please - as said - also avoid logging any message for already dying domains.

Jan

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

author
#14 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 9 lines · Jan Beulich

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

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 09:53, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +7 -0
+    rc = hd->platform_ops->unmap_page(d, gfn);
+
+    if ( unlikely(rc) )
+    {
+        if ( printk_ratelimit() )
+            printk(XENLOG_ERR
+                   "iommu_unmap_page: IOMMU unmapping gfn %#lx failed for

dom%d.",

Quoted 11 lines

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

Quoted 7 lines
xen/drivers/passthrough/iommu.c +7 -0
+                   gfn, d->domain_id);
+
+        if ( !is_hardware_domain(d) )
+            domain_crash(d);
+    }
+
+    return rc;

But please - as said - also avoid logging any message for already dying domains.

Kept Kevin's opinion for later, I hope I have got your point as below:
...
+ rc = hd->platform_ops->unmap_page(d, gfn);
+
+ if ( unlikely(rc) )
+ {
+ if ( is_hardware_domain(d) )
+ if ( printk_ratelimit() )
+ printk(XENLOG_ERR
+ "iommu_unmap_page: IOMMU unmapping gfn %#lx failed for dom%d.",
+ gfn, d->domain_id);
+ else
+ domain_crash(d);
+ }
+
+ return rc;
...

Thanks for your patience.
Quan

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

#15 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 10:20, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich

But please - as said - also avoid logging any message for already dying domains.

Kept Kevin's opinion for later, I hope I have got your point as below:
...

(quoted diff) +5 -0
+    rc = hd->platform_ops->unmap_page(d, gfn);
+
+    if ( unlikely(rc) )
+    {
+        if ( is_hardware_domain(d) )

Review

Quoted 10 lines
(quoted diff) +9 -0
+            if ( printk_ratelimit() )
+                printk(XENLOG_ERR
+                       "iommu_unmap_page: IOMMU unmapping gfn %#lx failed for dom%d.",
+                       gfn, d->domain_id);
+        else
+            domain_crash(d);
+    }
+
+    return rc;
...

I don't see how this would address my previous comment (not to speak of the "else" now being associated with the wrong "if").

Jan

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

author
#16 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

In reply to Jan Beulich
Quoted 5 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 05:41, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

For DomU the solution seems quite obvious: Only log a message if the domain is not already marked crashed.

Jan, I am still confused about this sentence and your another sentence ( _as said_ also avoid logging any message for already dying domains).

Quoted 5 lines

For Dom0 you'll need to get a little more
creative (but by leveraging the fact that there's only one in the system, this can't be too difficult a problem to solve:
e.g. "manually" rate limit these messages - see printk_ratelimit() et al).

Reading this thread again and again, sorry, I am still inclined to:

+ rc = hd->platform_ops->unmap_page(d, gfn);
+
+ if ( unlikely(rc) )
+ {
+ if ( printk_ratelimit() )
+ printk(XENLOG_ERR
+ "dom%d: IOMMU unmapping gfn %#lx failed %d.",
+ d->domain_id, gfn, rc);
+
+ if ( !is_hardware_domain(d) )
+ domain_crash(d);
+ }
+
+ return rc;

Waiting for Kevin's opinion..

Quan

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

#17 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 16:28, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 05:41, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

For DomU the solution seems quite obvious: Only log a message if the domain is not already marked crashed.

Jan, I am still confused about this sentence and your another sentence ( _as said_ also avoid logging any message for already dying domains).

The two say the same, so I don't see what you're confused about. Please be more precise.

Quoted 13 lines
Quoted 2 lines

For Dom0 you'll need to get a little more
creative (but by leveraging the fact that there's only one in the system,

this

Quoted 3 lines

can't be too difficult a problem to solve:
e.g. "manually" rate limit these messages - see printk_ratelimit() et al).

Reading this thread again and again, sorry, I am still inclined to:

xen/drivers/passthrough/iommu.c +4 -0
+    rc = hd->platform_ops->unmap_page(d, gfn);
+
+    if ( unlikely(rc) )
+    {

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

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

This is certainly better than unconditional logging, but will still produce more than one message per crashed guest (or for Dom0) on a batch of unmaps.

Jan

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

author
#18 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 16:28, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 05:41, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

Jan,

Try it again, I hope I have got it. If not, could you write some sample code for me as an exception? :)

xen/drivers/passthrough/iommu.c +44 -2
@@ -240,21 +240,63 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
                    unsigned int flags)
 {
     const struct domain_iommu *hd = dom_iommu(d);
+    static int printed = 0;
+    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 ( unlikely(rc) )
+    {
+        if ( is_hardware_domain(d) )
+        {
+            if ( !printed )
+            {
+                printk(XENLOG_ERR
+                       "d%d: IOMMU mapping gfn %#lx mfn %#lx failed %d.",
+                       d->domain_id, gfn, mfn, rc);
+
+                printed = 1;
+            }
+        }
+        else
+            domain_crash(d);
+    }
+
+    return rc;
 }
 
 int iommu_unmap_page(struct domain *d, unsigned long gfn)
 {
     const struct domain_iommu *hd = dom_iommu(d);
+    static int printed = 0;
+    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 ( unlikely(rc) )
+    {
+        if ( is_hardware_domain(d) )
+        {
+            if ( !printed )
+            {
+                printk(XENLOG_ERR
+                       "d%d: IOMMU unmapping gfn %#lx failed %d.",
+                       d->domain_id, gfn, rc);
+
+                printed = 1;
+            }
+        }
+        else
+            domain_crash(d);
+    }
+
+    return rc;
 }
 
 

Thanks again!!
Quan

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

#19 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.05.16 at 10:04, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 16:28, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 05:41, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

Try it again, I hope I have got it. If not, could you write some sample code for me as an exception? :)

Well, this would be acceptable (albeit not ideal) to me as a first cut (and instead of continuing this apparently fruitless discussion I'd then see to provide a follow-up patch improving it), but won't (I'm afraid) please Kevin: You now again don't log anything for DomU-s. That's one half of the "not ideal" part; the other is that of two far apart events for Dom0, only the first one would get logged.

In any event there's stylistic cleanup necessary:

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

Quoted 7 lines
xen/drivers/passthrough/iommu.c +1 -0
@@ -240,21 +240,63 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
                    unsigned int flags)
 {
     const struct domain_iommu *hd = dom_iommu(d);
+    static int printed = 0;

This doesn't need an initializer, should be bool_t, and should get moved ...

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

Quoted 12 lines
xen/drivers/passthrough/iommu.c +7 -1
+    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 ( unlikely(rc) )
+    {
+        if ( is_hardware_domain(d) )
+        {

... here.

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

Quoted 12 lines
xen/drivers/passthrough/iommu.c +12 -0
+            if ( !printed )
+            {
+                printk(XENLOG_ERR
+                       "d%d: IOMMU mapping gfn %#lx mfn %#lx failed %d.",
+                       d->domain_id, gfn, mfn, rc);
+
+                printed = 1;
+            }
+        }
+        else
+            domain_crash(d);
+    }

What I think might at least come close to what Kevin and I would like to see is something like

	if ( !d->is_shutting_down && printk_ratelimit() )
		printk(...);
	if ( !is_hardware_domain(d) )
		domain_crash(d);

For Dom0 that'll still be more verbose than we'd really like, but it at least wouldn't outright flood the console.

Jan

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

author
#20 lore raw

Re: [PATCH v4 02/10] IOMMU: handle IOMMU mapping and unmapping failures

Quoted 10 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.05.16 at 10:04, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 16:28, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 05:41, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

What I think might at least come close to what Kevin and I would like to see is something like

Quoted 8 lines
	if ( !d->is_shutting_down && printk_ratelimit() )
		printk(...);
	if ( !is_hardware_domain(d) )
		domain_crash(d);

For Dom0 that'll still be more verbose than we'd really like, but it at least wouldn't outright flood the console.

Thanks!!
It is really better to come close to Kevin's previous suggestion. I'll follow it for v5.

Quan

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

author
#21 lore raw

PATCH v4 3/10 IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping

In reply to Quan Xu

When IOMMU mapping is failed, we issue a best effort rollback, stopping IOMMU mapping, unmapping the previous IOMMU maps and then reporting the error up to 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 an 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       | 40 ++++++++++++++++++++++++++++++++--------
 xen/arch/x86/mm/p2m-pt.c        | 26 ++++++++++++++++++++++----
 xen/arch/x86/mm/p2m.c           | 11 +++++++++--
 xen/drivers/passthrough/iommu.c | 14 +++++++++++++-
 5 files changed, 84 insertions(+), 20 deletions(-)
xen/arch/x86/mm.c +8 -5
index 2bb920b..14b54a9 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 ( !rc )
+        rc = ret;
+
     return rc;
 }
 
xen/arch/x86/mm/p2m-ept.c +32 -8
index 1ed5b47..814cb72 100644
@@ -667,6 +667,7 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     unsigned long gfn_remainder = gfn;
     unsigned int i, target = order / EPT_TABLE_ORDER;
     int ret, rc = 0;
+    bool_t entry_written = 0;
     bool_t direct_mmio = (p2mt == p2m_mmio_direct);
     uint8_t ipat = 0;
     bool_t need_modify_vtd_table = 1;
@@ -812,17 +813,22 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     rc = atomic_write_ept_entry(ept_entry, new_entry, target);
     if ( unlikely(rc) )
         old_entry.epte = 0;
-    else if ( p2mt != p2m_invalid &&
-              (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
-        /* Track the highest gfn for which we have ever had a valid mapping */
-        p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    else
+    {
+        entry_written = 1;
+
+        if ( p2mt != p2m_invalid &&
+             (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
+            /* Track the highest gfn for which we have ever had a valid mapping */
+            p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    }
 
 out:
     if ( needs_sync )
         ept_sync_domain(p2m);
 
     /* For host p2m, may need to change VT-d page table.*/
-    if ( rc == 0 && p2m_is_hostp2m(p2m) && need_iommu(d) &&
+    if ( entry_written && p2m_is_hostp2m(p2m) && need_iommu(d) &&
          need_modify_vtd_table )
     {
         if ( iommu_hap_pt_share )
@@ -831,10 +837,28 @@ 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(p2m->domain, gfn + i);
+
+                        if ( !rc )
+                            rc = ret;
+
+                        break;
+                    }
+                }
             else
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_unmap_page(d, gfn + i);
+                {
+                    ret = iommu_unmap_page(d, gfn + i);
+
+                    if ( !rc )
+                        rc = ret;
+                }
         }
     }
 
@@ -847,7 +871,7 @@ out:
     if ( is_epte_present(&old_entry) )
         ept_free_entry(p2m, &old_entry, target);
 
-    if ( rc == 0 && p2m_is_hostp2m(p2m) )
+    if ( entry_written && p2m_is_hostp2m(p2m) )
         p2m_altp2m_propagate_change(d, _gfn(gfn), mfn, order, p2mt, p2ma);
 
     return rc;
xen/arch/x86/mm/p2m-pt.c +22 -4
index 3d80612..5426f92 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,29 @@ 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);
+
+                    if ( !rc )
+                        rc = ret;
+
+                    break;
+                }
+            }
         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 ( !rc )
+                    rc = ret;
+            }
     }
 
     /*
xen/arch/x86/mm/p2m.c +9 -2
index 94eabf6..cb77ef2 100644
@@ -638,13 +638,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 rc = 0, ret;
 
     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;
+            {
+               ret = iommu_unmap_page(p2m->domain, mfn + i);
+
+               if ( !rc )
+                   rc = ret;
+            }
+
+        return rc;
     }
 
     ASSERT(gfn_locked_by_me(p2m, gfn));
xen/drivers/passthrough/iommu.c +13 -1
index 09560c0..cca4cf3 100644
@@ -171,6 +171,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);
@@ -181,10 +183,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_WARNING
+                   "iommu_hwdom_init: IOMMU mapping failed for dom%d.",
+                   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
#22 lore raw

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

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

When IOMMU mapping is failed, we issue a best effort rollback, stopping IOMMU mapping, unmapping the previous IOMMU maps and then reporting the error up to 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 an error message.

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

Quoted 7 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]>

---

Somewhere here I continue to miss a summary on what has changed compared to the previous version. For review especially of larger patches (where preferably one wouldn't want to re-review the entire thing) this is more than just a nice-to-have.

Quoted 17 lines
xen/arch/x86/mm/p2m-ept.c +9 -4
@@ -812,17 +813,22 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     rc = atomic_write_ept_entry(ept_entry, new_entry, target);
     if ( unlikely(rc) )
         old_entry.epte = 0;
-    else if ( p2mt != p2m_invalid &&
-              (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
-        /* Track the highest gfn for which we have ever had a valid mapping */
-        p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    else
+    {
+        entry_written = 1;
+
+        if ( p2mt != p2m_invalid &&
+             (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
+            /* Track the highest gfn for which we have ever had a valid mapping */
+            p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    }

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

Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c +1 -1
 
 out:
     if ( needs_sync )
         ept_sync_domain(p2m);
 
     /* For host p2m, may need to change VT-d page table.*/
-    if ( rc == 0 && p2m_is_hostp2m(p2m) && need_iommu(d) &&
+    if ( entry_written && p2m_is_hostp2m(p2m) && need_iommu(d) &&
          need_modify_vtd_table )
     {

I'd prefer this conditional to remain untouched, but I'll leave the decision to the maintainers of the file.

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

Quoted 12 lines
xen/arch/x86/mm/p2m-ept.c +7 -1
@@ -831,10 +837,28 @@ 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(p2m->domain, gfn + i);

Loops like this are, btw., good examples of the log spam issue I've been pointing out on an earlier patch of this series.

Quoted 13 lines
xen/arch/x86/mm/p2m.c +1 -1
@@ -638,13 +638,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 rc = 0, ret;
 
     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);

xen/arch/x86/mm/p2m.c p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn, · line 655

Quoted 10 lines
xen/arch/x86/mm/p2m.c +8 -1
-        return 0;
+            {
+               ret = iommu_unmap_page(p2m->domain, mfn + i);
+
+               if ( !rc )
+                   rc = ret;
+            }
+
+        return rc;
     }

In code like this, btw., restricting the scope of "ret" to the innermost block would help future readers see immediately that the value of "ret" is of no further interest outside of that block.

Having reached the end of the patch, I'm missing the __must_check additions that you said you would do in this new iteration. Is there any reason for their absence? Did I overlook something?

Jan

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

#23 lore raw

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

Quoted 47 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

When IOMMU mapping is failed, we issue a best effort rollback, stopping IOMMU mapping, unmapping the previous IOMMU maps and then reporting the error up to 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 an error message.

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

Quoted 7 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]>

---

Somewhere here I continue to miss a summary on what has changed compared to the previous version. For review especially of larger patches (where preferably one wouldn't want to re-review the entire thing) this is more than just a nice-to-have.

Quoted 22 lines
xen/arch/x86/mm/p2m-ept.c +9 -4
@@ -812,17 +813,22 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     rc = atomic_write_ept_entry(ept_entry, new_entry, target);
     if ( unlikely(rc) )
         old_entry.epte = 0;
-    else if ( p2mt != p2m_invalid &&
-              (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
-        /* Track the highest gfn for which we have ever had a valid mapping */
-        p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    else
+    {
+        entry_written = 1;
+
+        if ( p2mt != p2m_invalid &&
+             (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
+            /* Track the highest gfn for which we have ever had a valid mapping */
+            p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    }
 
 out:
     if ( needs_sync )
         ept_sync_domain(p2m);
 
Quoted 8 lines

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

Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +1 -1
     /* For host p2m, may need to change VT-d page table.*/
-    if ( rc == 0 && p2m_is_hostp2m(p2m) && need_iommu(d) &&
+    if ( entry_written && p2m_is_hostp2m(p2m) && need_iommu(d) &&
          need_modify_vtd_table )
     {

I'd prefer this conditional to remain untouched, but I'll leave the decision to the maintainers of the file.

Any particular reason you think it would be better untouched?

I asked for it to be changed to "entry_written", because it seemed to me that's what was actually wanted (i.e., you're checking whether rc == 0 to determine whether the entry was written or not). At the moment the checks will be identical, but if someone changed something later, rc might be non-zero even though the entry had been written, in which case (I think) you'd want the iommu update to happen.

It's not that big a deal to me, but I do prefer it this way (unless I've misunderstood something).

Quoted 19 lines
Quoted 19 lines
xen/arch/x86/mm/p2m.c +6 -2
@@ -638,13 +638,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 rc = 0, ret;
 
     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;
+            {
+               ret = iommu_unmap_page(p2m->domain, mfn + i);
+
+               if ( !rc )
+                   rc = ret;
Quoted 8 lines

xen/arch/x86/mm/p2m.c p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn, · line 655

Quoted 4 lines
xen/arch/x86/mm/p2m.c +3 -0
+            }
+
+        return rc;
     }

In code like this, btw., restricting the scope of "ret" to the innermost block would help future readers see immediately that the value of "ret" is of no further interest outside of that block.

I wouldn't ask for re-send just for this, but...

Quoted 3 lines

Having reached the end of the patch, I'm missing the __must_check additions that you said you would do in this new iteration. Is there any reason for their absence? Did I overlook something?

If it's going to be re-sent anyway, moving the ret declaration inside the loop might as well be done.

Other than that, it looks good to me, thanks.

-George

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

#24 lore raw

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

Quoted 66 lines · George Dunlap
Quoted 47 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

When IOMMU mapping is failed, we issue a best effort rollback, stopping IOMMU mapping, unmapping the previous IOMMU maps and then reporting the error up to 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 an error message.

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

Quoted 7 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]>

---

Somewhere here I continue to miss a summary on what has changed compared to the previous version. For review especially of larger patches (where preferably one wouldn't want to re-review the entire thing) this is more than just a nice-to-have.

Quoted 22 lines
xen/arch/x86/mm/p2m-ept.c +9 -4
@@ -812,17 +813,22 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     rc = atomic_write_ept_entry(ept_entry, new_entry, target);
     if ( unlikely(rc) )
         old_entry.epte = 0;
-    else if ( p2mt != p2m_invalid &&
-              (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
-        /* Track the highest gfn for which we have ever had a valid mapping */
-        p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    else
+    {
+        entry_written = 1;
+
+        if ( p2mt != p2m_invalid &&
+             (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
+            /* Track the highest gfn for which we have ever had a valid mapping */
+            p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    }
 
 out:
     if ( needs_sync )
         ept_sync_domain(p2m);
 
Quoted 8 lines

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

Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +1 -1
     /* For host p2m, may need to change VT-d page table.*/
-    if ( rc == 0 && p2m_is_hostp2m(p2m) && need_iommu(d) &&
+    if ( entry_written && p2m_is_hostp2m(p2m) && need_iommu(d) &&
          need_modify_vtd_table )
     {

I'd prefer this conditional to remain untouched, but I'll leave the decision to the maintainers of the file.

Any particular reason you think it would be better untouched?

I asked for it to be changed to "entry_written", because it seemed to me that's what was actually wanted (i.e., you're checking whether rc == 0 to determine whether the entry was written or not). At the moment the checks will be identical, but if someone changed something later, rc might be non-zero even though the entry had been written, in which case (I think) you'd want the iommu update to happen.

Quoted 2 lines

It's not that big a deal to me, but I do prefer it this way (unless I've misunderstood something).

See the discussion on patch 8 regarding why I now think Jan is probably right.

-George

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

author
#25 lore raw

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

Quoted 73 lines · George Dunlap
Quoted 4 lines · George Dunlap
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

When IOMMU mapping is failed, we issue a best effort rollback, stopping IOMMU mapping, unmapping the previous IOMMU maps and

then

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

reporting the error up to 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 an error message.

Quoted 14 lines
Quoted 14 lines
Quoted 13 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]>

---

Quoted 6 lines
Quoted 6 lines

Somewhere here I continue to miss a summary on what has changed compared to the previous version. For review especially of larger patches (where preferably one wouldn't want to re-review the entire thing) this is more than just a nice-to-have.

Review ept_set_entry(struct p2m_domain *p2m,

Quoted 1 line
(quoted diff) +0 -0
@@ -812,17 +813,22 @@ ept_set_entry(struct p2m_domain *p2m,

unsigned long gfn, mfn_t mfn,

Quoted 6 lines
Quoted 6 lines

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

Quoted 6 lines
xen/arch/x86/mm/p2m-ept.c +0 -3
     rc = atomic_write_ept_entry(ept_entry, new_entry, target);
     if ( unlikely(rc) )
         old_entry.epte = 0;
-    else if ( p2mt != p2m_invalid &&
-              (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
-        /* Track the highest gfn for which we have ever had a valid mapping

*/

Quoted 8 lines
Quoted 8 lines

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

Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +7 -1
-        p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    else
+    {
+        entry_written = 1;
+
+        if ( p2mt != p2m_invalid &&
+             (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
+            /* Track the highest gfn for which we have ever had a valid

mapping */

Quoted 25 lines
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/mm/p2m-ept.c +2 -0
+            p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    }
 
 out:
     if ( needs_sync )
         ept_sync_domain(p2m);
 
Quoted 8 lines

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

Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +1 -1
     /* For host p2m, may need to change VT-d page table.*/
-    if ( rc == 0 && p2m_is_hostp2m(p2m) && need_iommu(d) &&
+    if ( entry_written && p2m_is_hostp2m(p2m) && need_iommu(d) &&
          need_modify_vtd_table )
     {

I'd prefer this conditional to remain untouched, but I'll leave the decision to the maintainers of the file.

Any particular reason you think it would be better untouched?

I asked for it to be changed to "entry_written", because it seemed to me that's what was actually wanted (i.e., you're checking whether rc == 0 to determine whether the entry was written or not). At the moment the checks will be identical, but if someone changed something later, rc might be non-zero even though the entry had been written, in which case (I think) you'd want the iommu update to happen.

Quoted 5 lines
Quoted 2 lines

It's not that big a deal to me, but I do prefer it this way (unless I've misunderstood something).

See the discussion on patch 8 regarding why I now think Jan is probably right.

Agreed. Thanks for your careful checking.

Check it again --
1. then I am no need to check 'rc' as below:

      if ( rc == 0 && p2m_is_hostp2m(p2m) && need_iommu(d) &&
           need_modify_vtd_table )
     {

+ if ( !rc )
+ rc = ret;
...

+ if ( !rc && unlikely(ret) )

+                        rc = ret;
     }

2. leave the below as is:

- if ( rc == 0 && p2m_is_hostp2m(p2m) )
+ if ( entry_written && p2m_is_hostp2m(p2m) )

Quan

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

#26 lore raw

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

Quoted 8 lines · Quan

Agreed. Thanks for your careful checking.

Check it again --
1. then I am no need to check 'rc' as below:

      if ( rc == 0 && p2m_is_hostp2m(p2m) && need_iommu(d) &&
           need_modify_vtd_table )
     {

Review

Quoted 7 lines
(quoted diff) +4 -0
+                        if ( !rc )
+                            rc = ret;
...
 
+                    if ( !rc && unlikely(ret) )
+                        rc = ret;
     }

Actually, in the case of iommu_map_page(), you can just use rc directly and not bother using ret at all. (In the case of iommu_unmap_page(), you still need to use ret and check that rc != 0 to make sure you get the first error.)

Something like applying the attached patch (not built or nitpicked for style, just for clarity).

-George

xen/arch/x86/mm/p2m-ept.c +3 -6
index 814cb72..f8360c6 100644
@@ -828,7 +828,7 @@ out:
         ept_sync_domain(p2m);
 
     /* For host p2m, may need to change VT-d page table.*/
-    if ( entry_written && p2m_is_hostp2m(p2m) && need_iommu(d) &&
+    if ( rc == 0  && p2m_is_hostp2m(p2m) && need_iommu(d) &&
          need_modify_vtd_table )
     {
         if ( iommu_hap_pt_share )
@@ -838,16 +838,13 @@ out:
             if ( iommu_flags )
                 for ( i = 0; i < (1 << order); i++ )
                 {
-                    ret = iommu_map_page(d, gfn + i, mfn_x(mfn) + i, iommu_flags);
+                    rc = iommu_map_page(d, gfn + i, mfn_x(mfn) + i, iommu_flags);
 
-                    if ( unlikely(ret) )
+                    if ( unlikely(rc) )
                     {
                         while ( i-- )
                             iommu_unmap_page(p2m->domain, gfn + i);
 
-                        if ( !rc )
-                            rc = ret;
-
                         break;
                     }
                 }

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

author
#27 lore raw

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

Quoted 17 lines · George Dunlap
Quoted 8 lines · Quan

Agreed. Thanks for your careful checking.

Check it again --
1. then I am no need to check 'rc' as below:

      if ( rc == 0 && p2m_is_hostp2m(p2m) && need_iommu(d) &&
           need_modify_vtd_table )
     {

Review

Quoted 7 lines
(quoted diff) +4 -0
+                        if ( !rc )
+                            rc = ret;
...
 
+                    if ( !rc && unlikely(ret) )
+                        rc = ret;
     }
Quoted 7 lines

Actually, in the case of iommu_map_page(), you can just use rc directly and not bother using ret at all. (In the case of iommu_unmap_page(), you still need to use ret and check that rc != 0 to make sure you get the first error.)

Something like applying the attached patch (not built or nitpicked for style, just for clarity).

Got it, thanks.

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

#28 lore raw

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

In reply to George Dunlap
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 16:45, <[email protected]> wrote:
Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +9 -4
@@ -812,17 +813,22 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
     rc = atomic_write_ept_entry(ept_entry, new_entry, target);
     if ( unlikely(rc) )
         old_entry.epte = 0;
-    else if ( p2mt != p2m_invalid &&
-              (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
-        /* Track the highest gfn for which we have ever had a valid mapping */
-        p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    else
+    {
+        entry_written = 1;
+
+        if ( p2mt != p2m_invalid &&
+             (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
+            /* Track the highest gfn for which we have ever had a valid mapping */
+            p2m->max_mapped_pfn = gfn + (1UL << order) - 1;
+    }
 
 out:
     if ( needs_sync )
         ept_sync_domain(p2m);
 
Quoted 8 lines

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

Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +1 -1
     /* For host p2m, may need to change VT-d page table.*/
-    if ( rc == 0 && p2m_is_hostp2m(p2m) && need_iommu(d) &&
+    if ( entry_written && p2m_is_hostp2m(p2m) && need_iommu(d) &&
          need_modify_vtd_table )
     {

I'd prefer this conditional to remain untouched, but I'll leave the decision to the maintainers of the file.

Quoted 1 line

Any particular reason you think it would be better untouched?

IMO it's misleading here, and appropriate only in the other place (where the altp2m-s get updated).

Quoted 38 lines

I asked for it to be changed to "entry_written", because it seemed to me that's what was actually wanted (i.e., you're checking whether rc == 0 to determine whether the entry was written or not). At the moment the checks will be identical, but if someone changed something later, rc might be non-zero even though the entry had been written, in which case (I think) you'd want the iommu update to happen.

It's not that big a deal to me, but I do prefer it this way (unless I've misunderstood something).

Quoted 19 lines
Quoted 19 lines
xen/arch/x86/mm/p2m.c +6 -2
@@ -638,13 +638,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 rc = 0, ret;
 
     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;
+            {
+               ret = iommu_unmap_page(p2m->domain, mfn + i);
+
+               if ( !rc )
+                   rc = ret;
Quoted 8 lines

xen/arch/x86/mm/p2m.c p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn, · line 655

Quoted 4 lines
xen/arch/x86/mm/p2m.c +3 -0
+            }
+
+        return rc;
     }

In code like this, btw., restricting the scope of "ret" to the innermost block would help future readers see immediately that the value of "ret" is of no further interest outside of that block.

Quoted 1 line

I wouldn't ask for re-send just for this, but...

I agree, and I meant to express this with the "btw".

Jan

Quoted 10 lines
Quoted 3 lines

Having reached the end of the patch, I'm missing the __must_check additions that you said you would do in this new iteration. Is there any reason for their absence? Did I overlook something?

If it's going to be re-sent anyway, moving the ret declaration inside the loop might as well be done.

Other than that, it looks good to me, thanks.

-George

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

author
#29 lore raw

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

In reply to George Dunlap
Quoted 44 lines · George Dunlap
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

When IOMMU mapping is failed, we issue a best effort rollback, stopping IOMMU mapping, unmapping the previous IOMMU maps and

then

Quoted 3 lines
Quoted 3 lines

reporting the error up to 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 an error message.

Quoted 7 lines

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

Quoted 7 lines

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

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

unsigned long gfn, unsigned long mfn,

Quoted 16 lines
Quoted 16 lines
xen/arch/x86/mm/p2m.c +6 -2
     mfn_t mfn_return;
     p2m_type_t t;
     p2m_access_t a;
+    int rc = 0, ret;
 
     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;
+            {
+               ret = iommu_unmap_page(p2m->domain, mfn + i);
+
+               if ( !rc )
+                   rc = ret;
Quoted 8 lines

xen/arch/x86/mm/p2m.c p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn, · line 655

Quoted 4 lines
xen/arch/x86/mm/p2m.c +3 -0
+            }
+
+        return rc;
     }

In code like this, btw., restricting the scope of "ret" to the innermost block would help future readers see immediately that the value of "ret" is of no further interest outside of that block.

I wouldn't ask for re-send just for this, but...

Quoted 9 lines
Quoted 3 lines

Having reached the end of the patch, I'm missing the __must_check additions that you said you would do in this new iteration. Is there any reason for their absence? Did I overlook something?

If it's going to be re-sent anyway, moving the ret declaration inside the loop might as well be done.

Other than that, it looks good to me, thanks.

I'll fix and re-send it in next v5.

Quan

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

author
#30 lore raw

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

In reply to Jan Beulich
Quoted 30 lines · Jan Beulich

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

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +0 -0
@@ -638,13 +638,20 @@ p2m_remove_page(struct p2m_domain *p2m,

unsigned long gfn, unsigned long mfn,

Quoted 10 lines
xen/arch/x86/mm/p2m.c +1 -1
     mfn_t mfn_return;
     p2m_type_t t;
     p2m_access_t a;
+    int rc = 0, ret;
 
     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);

xen/arch/x86/mm/p2m.c p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn, · line 655

Quoted 10 lines
xen/arch/x86/mm/p2m.c +8 -1
-        return 0;
+            {
+               ret = iommu_unmap_page(p2m->domain, mfn + i);
+
+               if ( !rc )
+                   rc = ret;
+            }
+
+        return rc;
     }

In code like this, btw., restricting the scope of "ret" to the innermost block would help future readers see immediately that the value of "ret" is of no further interest outside of that block.

Quoted 4 lines

Having reached the end of the patch, I'm missing the __must_check additions that you said you would do in this new iteration. Is there any reason for their absence? Did I overlook something?

Sorry, I did overlook something.
Checked the v2/v3 replies again, I still can't find it.
I only add the __must_check annotation for these functions you point out.
Do I need to add the __must_check annotation for these functions (but not void function) in this patch?

Quan

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

#31 lore raw

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

Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 05:39, <[email protected]> wrote:
Quoted 19 lines · Jan Beulich

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

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +0 -0
@@ -638,13 +638,20 @@ p2m_remove_page(struct p2m_domain *p2m,

unsigned long gfn, unsigned long mfn,

Quoted 14 lines
xen/arch/x86/mm/p2m.c +4 -2
     mfn_t mfn_return;
     p2m_type_t t;
     p2m_access_t a;
+    int rc = 0, ret;
 
     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;
+            {
+               ret = iommu_unmap_page(p2m->domain, mfn + i);
+
Quoted 8 lines

xen/arch/x86/mm/p2m.c p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn, · line 655

Quoted 6 lines
xen/arch/x86/mm/p2m.c +5 -0
+               if ( !rc )
+                   rc = ret;
+            }
+
+        return rc;
     }

In code like this, btw., restricting the scope of "ret" to the innermost

block

Quoted 5 lines

would help future readers see immediately that the value of "ret" is of no further interest outside of that block.

Having reached the end of the patch, I'm missing the __must_check additions that you said you would do in this new iteration. Is there any reason for

Quoted 7 lines

their

Quoted 2 lines

absence? Did I overlook something?

Sorry, I did overlook something.
Checked the v2/v3 replies again, I still can't find it.
I only add the __must_check annotation for these functions you point out.

Okay, that's the problem then: When we discussed this originally (in abstract terms) I had clearly said that all involved functions should become __must_check ones to make sure all cases get caught where so far error returns got ignored. And on that basis (as well as on the common grounds that I try to avoid repeating the same comment over and over when reviewing a patch or a series of patches) you should have determined yourself the full set of functions needing the annotation. The rule of thumb is: If a function calls a __must_check one and doesn't itself consume the return value, it should also obtain __must_check.

Quoted 2 lines

Do I need to add the __must_check annotation for these functions (but not void function) in this patch?

IOW - yes. And you'll need to apply the same consideration to most (all?) other patches in this series.

Jan

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

author
#32 lore raw

PATCH v4 4/10 vt-d: propagate IOMMU Device-TLB flush error up to IOMMU unmapping.

In reply to Quan Xu

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 64093a9..e0e1126 100644
@@ -616,11 +616,12 @@ static void iommu_flush_iotlb_all(struct domain *d)
 }
 
 /* clear one page's page table */
-static void dma_pte_clear_one(struct domain *domain, u64 addr)
+static int __must_check dma_pte_clear_one(struct domain *domain, u64 addr)
 {
     struct domain_iommu *hd = dom_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 */
@@ -628,7 +629,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);
@@ -638,7 +639,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);
@@ -646,9 +647,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)
@@ -1766,9 +1769,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
Reviewed-by on v4 4/10
#33 lore raw

Re: [PATCH v4 04/10] vt-d: propagate IOMMU Device-TLB flush error up to IOMMU unmapping.

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

Propagate the IOMMU Device-TLB flush error up to IOMMU unmapping.

but note ...

xen/drivers/passthrough/vtd/iommu.c static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn) · line 1773

Quoted 9 lines
xen/drivers/passthrough/vtd/iommu.c +1 -3
@@ -1766,9 +1769,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);
 }

... how you lose the __must_check here, since intel_iommu_unmap_page() isn't __must_check (which we said you may skip as long as the common code wrapper has it, but in the context here I'm no longer convinced skipping this at any layer is a good idea, as that makes validation of the call trees more difficult). (This is just a remark regarding the comment on the earlier patch, i.e. not something needing any further change here.)

Jan

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

author
#34 lore raw

Re: [PATCH v4 04/10] vt-d: propagate IOMMU Device-TLB flush error up to IOMMU unmapping.

Quoted 21 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:

Propagate the IOMMU Device-TLB flush error up to IOMMU unmapping.

but note ...

Review static int intel_iommu_unmap_page(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -1766,9 +1769,7 @@ static int intel_iommu_unmap_page(struct

domain *d, unsigned long gfn)

xen/drivers/passthrough/vtd/iommu.c static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn) · line 1773

Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +1 -3
     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);
 }
Quoted 8 lines

... how you lose the __must_check here, since intel_iommu_unmap_page() isn't __must_check (which we said you may skip as long as the common code wrapper has it, but in the context here I'm no longer convinced skipping this at any layer is a good idea, as that makes validation of the call trees more difficult).
(This is just a remark regarding the comment on the earlier patch, i.e. not something needing any further change here.)

I'll be bold to add __must_check..
Quan

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

author
#35 lore raw

PATCH v4 5/10 vt-d: propagate IOMMU Device-TLB flush error up to IOMMU mapping.

In reply to Quan Xu

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 e0e1126..584982a 100644
@@ -1716,6 +1716,7 @@ static int intel_iommu_map_page(
     struct domain_iommu *hd = dom_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) )
@@ -1758,9 +1759,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
author
#36 lore raw

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

In reply to Quan Xu

Propagate the IOMMU Device-TLB flush error up to the iommu_iotlb_flush{,_all}.

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]>
CC Kevin Tian <[email protected]>
---
 xen/arch/arm/p2m.c                  |  5 ++++-
 xen/common/memory.c                 | 14 ++++++++++++--
 xen/drivers/passthrough/iommu.c     | 13 +++++++++----
 xen/drivers/passthrough/x86/iommu.c |  5 +++--
 xen/include/xen/iommu.h             |  5 +++--
 5 files changed, 31 insertions(+), 11 deletions(-)
xen/arch/arm/p2m.c +4 -1
index db21433..fe201d0 100644
@@ -1178,7 +1178,10 @@ out:
     if ( flush )
     {
         flush_tlb_domain(d);
-        iommu_iotlb_flush(d, sgfn, egfn - sgfn);
+        ret = iommu_iotlb_flush(d, sgfn, egfn - sgfn);
+
+        if ( !rc )
+            rc = ret;
     }
 
     while ( (pg = page_list_remove_head(&free_pages)) )
xen/common/memory.c +12 -2
index 644f81a..21b8098 100644
@@ -677,9 +677,19 @@ static int xenmem_add_to_physmap(struct domain *d,
 #ifdef CONFIG_HAS_PASSTHROUGH
     if ( need_iommu(d) )
     {
+        int ret;
+
         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 && unlikely(ret) )
+            rc = ret;
+
+        ret = iommu_iotlb_flush(d, xatp->gpfn - done, done);
+
+        if ( rc >= 0 && unlikely(ret) )
+            rc = ret;
     }
 #endif
 
xen/drivers/passthrough/iommu.c +9 -4
index cca4cf3..7b5fc59 100644
@@ -312,24 +312,29 @@ 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 __must_check iommu_iotlb_flush(struct domain *d, unsigned long gfn,
+                                   unsigned int page_count)
 {
     const struct domain_iommu *hd = dom_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 __must_check iommu_iotlb_flush_all(struct domain *d)
 {
     const struct domain_iommu *hd = dom_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 b64b98f..a18a608 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 +3 -2
index 19ba976..75c17a7 100644
@@ -200,8 +200,9 @@ 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 __must_check iommu_iotlb_flush(struct domain *d, unsigned long gfn,
+                                   unsigned int page_count);
+int __must_check 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
Reviewed-by on v4 6/10
#37 lore raw

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

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/common/memory.c +2 -2
@@ -677,9 +677,19 @@ static int xenmem_add_to_physmap(struct domain *d,
 #ifdef CONFIG_HAS_PASSTHROUGH
     if ( need_iommu(d) )
     {
+        int ret;
+
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        iommu_iotlb_flush(d, xatp->idx - done, done);
-        iommu_iotlb_flush(d, xatp->gpfn - done, done);

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

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

In both cases I think it would be preferable to switch the two sides of the &&.

xen/drivers/passthrough/iommu.c static void iommu_free_pagetables(unsigned long unused) · line 316

Quoted 9 lines
xen/drivers/passthrough/iommu.c +2 -1
@@ -312,24 +312,29 @@ 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 __must_check iommu_iotlb_flush(struct domain *d, unsigned long gfn,
+                                   unsigned int page_count)

The annotation generally belongs on declarations; the only exception are static functions which don't have any (i.e. they get defined before first getting used).

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

Quoted 11 lines
xen/include/xen/iommu.h +3 -2
@@ -200,8 +200,9 @@ 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 __must_check iommu_iotlb_flush(struct domain *d, unsigned long gfn,
+                                   unsigned int page_count);
+int __must_check iommu_iotlb_flush_all(struct domain *d);

I.e. these changes suffice, repeating the annotations on the function definitions is redundant with the ones put here.

With respective adjustments done

Jan

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

author
#38 lore raw

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

Quoted 17 lines · Jan Beulich

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

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/common/memory.c +0 -0
@@ -677,9 +677,19 @@ static int xenmem_add_to_physmap(struct

domain

Quoted 12 lines
xen/common/memory.c +6 -2
 *d,  #ifdef CONFIG_HAS_PASSTHROUGH
     if ( need_iommu(d) )
     {
+        int ret;
+
         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 && unlikely(ret) )
Quoted 9 lines

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

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

In both cases I think it would be preferable to switch the two sides of the &&.

Make sense. Thanks for your careful check.

Quoted 7 lines

xen/drivers/passthrough/iommu.c static void iommu_free_pagetables(unsigned

Quoted 3 lines
xen/drivers/passthrough/iommu.c +0 -0
@@ -312,24 +312,29 @@ static void iommu_free_pagetables(unsigned

long unused)

Quoted 3 lines
xen/drivers/passthrough/iommu.c +0 -0
                             cpumask_cycle(smp_processor_id(),
 &cpu_online_map));  }
 
Quoted 9 lines

xen/drivers/passthrough/iommu.c static void iommu_free_pagetables(unsigned long unused) · line 316

Quoted 4 lines
xen/drivers/passthrough/iommu.c +2 -1
-void iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned
 int page_count)
+int __must_check iommu_iotlb_flush(struct domain *d, unsigned long gfn,
+                                   unsigned int page_count)

The annotation generally belongs on declarations; the only exception are static functions which don't have any (i.e. they get defined before first getting used).

You are right. I will drop these __must_check annotation here.

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

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

*d,

Quoted 2 lines
                     XEN_GUEST_HANDLE_PARAM(xen_domctl_t));
Quoted 9 lines

xen/include/xen/iommu.h

Quoted 5 lines

-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 +3 -0
+int __must_check iommu_iotlb_flush(struct domain *d, unsigned long gfn,
+                                   unsigned int page_count); int
+__must_check iommu_iotlb_flush_all(struct domain *d);

I.e. these changes suffice, repeating the annotations on the function definitions is redundant with the ones put here.

Agreed.

Quoted 2 lines

With respective adjustments done

Quan

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

author
#39 lore raw

PATCH v4 7/10 IOMMU: propagate IOMMU Device-TLB flush error up to iommu_iotlb_flush{, _all} (leaf ones).

In reply to Quan Xu

Propagate the IOMMU Device-TLB flush error up to the iommu_iotlb_flush{,_all}.

This patch fixes the leaf ones.

CC Stefano Stabellini <[email protected]>
CC Julien Grall <[email protected]>
CC Jan Beulich <[email protected]>
CC Kevin Tian <[email protected]>
CC Feng Wu <[email protected]>
---
 xen/drivers/passthrough/arm/smmu.c  | 12 +++++++-----
 xen/drivers/passthrough/iommu.c     |  8 ++------
 xen/drivers/passthrough/vtd/iommu.c | 10 +++++-----
 xen/include/xen/iommu.h             |  4 ++--
 4 files changed, 16 insertions(+), 18 deletions(-)
xen/drivers/passthrough/arm/smmu.c +7 -5
index 54a03a6..1864b6d 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 = dom_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);
+	/* ARM SMMU v1 doesn't have flush by VMA and VMID */
+	return arm_smmu_iotlb_flush_all(d);
 }
 
 static struct iommu_domain *arm_smmu_get_domain(struct domain *d,
xen/drivers/passthrough/iommu.c +2 -6
index 7b5fc59..c013d91 100644
@@ -320,9 +320,7 @@ int __must_check iommu_iotlb_flush(struct domain *d, unsigned long gfn,
     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 __must_check iommu_iotlb_flush_all(struct domain *d)
@@ -332,9 +330,7 @@ int __must_check 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 +5 -5
index 584982a..a749c67 100644
@@ -604,15 +604,15 @@ static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
     return rc;
 }
 
-static void iommu_flush_iotlb_page(struct domain *d, unsigned long gfn,
-                                   unsigned int page_count)
+static int iommu_flush_iotlb_page(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 iommu_flush_iotlb_all(struct domain *d)
+static int iommu_flush_iotlb_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 75c17a7..6a64014 100644
@@ -179,8 +179,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
#40 lore raw

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

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +2 -2
@@ -604,15 +604,15 @@ static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
     return rc;
 }
 
-static void iommu_flush_iotlb_page(struct domain *d, unsigned long gfn,
-                                   unsigned int page_count)
+static int iommu_flush_iotlb_page(struct domain *d, unsigned long gfn,
+                                  unsigned int page_count)
 {

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain *d, unsigned long gfn, · line 616

Quoted 10 lines
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 iommu_flush_iotlb_all(struct domain *d)
+static int iommu_flush_iotlb_all(struct domain *d)
 {
-    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
+    return iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }

As already indicated in a reply to an earlier patch, despite what was said on the earlier version I think we should have __must_check here and ...

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

Quoted 10 lines
xen/include/xen/iommu.h +2 -2
@@ -179,8 +179,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);

... here.

Jan

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

author
#41 lore raw

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

Quoted 17 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain *d,

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -604,15 +604,15 @@ static int iommu_flush_iotlb(struct domain *d,

unsigned long gfn,

Quoted 12 lines
xen/drivers/passthrough/vtd/iommu.c +3 -3
     return rc;
 }
 
-static void iommu_flush_iotlb_page(struct domain *d, unsigned long gfn,
-                                   unsigned int page_count)
+static int iommu_flush_iotlb_page(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);
 }
 
Quoted 9 lines

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain *d, unsigned long gfn, · line 616

Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +2 -2
-static void iommu_flush_iotlb_all(struct domain *d)
+static int iommu_flush_iotlb_all(struct domain *d)
 {
-    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
+    return iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }

As already indicated in a reply to an earlier patch, despite what was said on the earlier version I think we should have __must_check here

If the static one is initialized for .callback, is it really necessary to add __must_check here? I check it with compiler, and it is ok when I didn't add __must_check here.

If yes, I'll add __must_check for ARM one as well.

Quoted 10 lines

and ...

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

Quoted 7 lines
xen/include/xen/iommu.h +0 -1
@@ -179,8 +179,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 6 lines

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

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);

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

Quoted 1 line
xen/include/xen/iommu.h +1 -0
+    int (*iotlb_flush_all)(struct domain *d);

... here.

Yes, it is necessary here.

Quan

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

#42 lore raw

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

Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 08:47, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain *d,

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -604,15 +604,15 @@ static int iommu_flush_iotlb(struct domain *d,

unsigned long gfn,

Quoted 12 lines
xen/drivers/passthrough/vtd/iommu.c +3 -3
     return rc;
 }
 
-static void iommu_flush_iotlb_page(struct domain *d, unsigned long gfn,
-                                   unsigned int page_count)
+static int iommu_flush_iotlb_page(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);
 }
 
Quoted 9 lines

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain *d, unsigned long gfn, · line 616

Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +2 -2
-static void iommu_flush_iotlb_all(struct domain *d)
+static int iommu_flush_iotlb_all(struct domain *d)
 {
-    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
+    return iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }

As already indicated in a reply to an earlier patch, despite what was said on the earlier version I think we should have __must_check here

Quoted 3 lines

If the static one is initialized for .callback, is it really necessary to add __must_check here?
I check it with compiler, and it is ok when I didn't add __must_check here.

Without you telling us what exactly you checked, I can't respond to this. Extending from the reply just sent to patch 3(?) and for the avoidance of doubt, you now obviously also need to __must_check-annotate the function pointer (to match the desire of wanting to never lose such an annotation on the way back up the call tree).

Quoted 1 line

If yes, I'll add __must_check for ARM one as well.

Of course.

Jan

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

author
#43 lore raw

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

Quoted 35 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 08:47, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain · line 604

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -604,15 +604,15 @@ static int iommu_flush_iotlb(struct domain
 *d,

unsigned long gfn,

Quoted 4 lines
Quoted 4 lines

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

Quoted 4 lines
xen/drivers/passthrough/vtd/iommu.c +0 -1
     return rc;
 }
 
-static void iommu_flush_iotlb_page(struct domain *d, unsigned long

gfn,

Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +3 -2
-                                   unsigned int page_count)
+static int iommu_flush_iotlb_page(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);
 }
 
Quoted 9 lines

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain *d, unsigned long gfn, · line 616

Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +2 -2
-static void iommu_flush_iotlb_all(struct domain *d)
+static int iommu_flush_iotlb_all(struct domain *d)
 {
-    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
+    return iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }

As already indicated in a reply to an earlier patch, despite what was said on the earlier version I think we should have __must_check here

Quoted 3 lines

If the static one is initialized for .callback, is it really necessary to add __must_check here?
I check it with compiler, and it is ok when I didn't add __must_check here.

Quoted 6 lines

Without you telling us what exactly you checked, I can't respond to this. Extending from the reply just sent to patch 3(?) and for the avoidance of doubt, you now obviously also need to __must_check-annotate the function pointer (to match the desire of wanting to never lose such an annotation on the way back up the call tree).

I checked -- without __must_check for iommu_flush_iotlb_page() / iommu_flush_iotlb_all().

Quoted 4 lines
Quoted 1 line

If yes, I'll add __must_check for ARM one as well.

Of course.

Got it.

Quan

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

#44 lore raw

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

Quoted 44 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 09:12, <[email protected]> wrote:
Quoted 35 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 08:47, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain · line 604

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -604,15 +604,15 @@ static int iommu_flush_iotlb(struct domain
 *d,

unsigned long gfn,

Quoted 4 lines
Quoted 4 lines

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

Quoted 4 lines
xen/drivers/passthrough/vtd/iommu.c +0 -1
     return rc;
 }
 
-static void iommu_flush_iotlb_page(struct domain *d, unsigned long

gfn,

Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +3 -2
-                                   unsigned int page_count)
+static int iommu_flush_iotlb_page(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);
 }
 
Quoted 9 lines

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain *d, unsigned long gfn, · line 616

Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +2 -2
-static void iommu_flush_iotlb_all(struct domain *d)
+static int iommu_flush_iotlb_all(struct domain *d)
 {
-    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
+    return iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }

As already indicated in a reply to an earlier patch, despite what was said on the earlier version I think we should have __must_check here

Quoted 3 lines

If the static one is initialized for .callback, is it really necessary to add __must_check here?
I check it with compiler, and it is ok when I didn't add __must_check here.

Quoted 6 lines

Without you telling us what exactly you checked, I can't respond to this. Extending from the reply just sent to patch 3(?) and for the avoidance of doubt, you now obviously also need to __must_check-annotate the function pointer (to match the desire of wanting to never lose such an annotation on the way back up the call tree).

Quoted 2 lines

I checked -- without __must_check for iommu_flush_iotlb_page() / iommu_flush_iotlb_all().

But _what_ did you check? I.e. the question isn't which functions you did your check with, but what behavioral checking you did.

Jan

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

author
#45 lore raw

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

Quoted 47 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 09:12, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 08:47, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain · line 604

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -604,15 +604,15 @@ static int iommu_flush_iotlb(struct domain
 *d,

unsigned long gfn,

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +0 -1
     return rc;
 }
 
-static void iommu_flush_iotlb_page(struct domain *d, unsigned

long

gfn,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
-                                   unsigned int page_count)
+static int iommu_flush_iotlb_page(struct domain *d, unsigned long

gfn,

Quoted 28 lines
Quoted 27 lines
Quoted 17 lines
Quoted 6 lines
Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +2 -1
+                                  unsigned int page_count)
 {
-    iommu_flush_iotlb(d, gfn, 1, page_count);
+    return iommu_flush_iotlb(d, gfn, 1, page_count);
 }
Quoted 10 lines

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain *d, unsigned long gfn, · line 616

Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +2 -2
-static void iommu_flush_iotlb_all(struct domain *d)
+static int iommu_flush_iotlb_all(struct domain *d)
 {
-    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
+    return iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }

As already indicated in a reply to an earlier patch, despite what was said on the earlier version I think we should have __must_check here

Quoted 3 lines

If the static one is initialized for .callback, is it really necessary to add __must_check here?
I check it with compiler, and it is ok when I didn't add __must_check here.

Without you telling us what exactly you checked, I can't respond to this. Extending from the reply just sent to patch 3(?) and for the avoidance of doubt, you now obviously also need to __must_check-annotate the function pointer (to match the desire of wanting to never lose such an annotation on the way back up the call tree).

Quoted 6 lines
Quoted 2 lines

I checked -- without __must_check for iommu_flush_iotlb_page() / iommu_flush_iotlb_all().

But _what_ did you check? I.e. the question isn't which functions you did your check with, but what behavioral checking you did.

without __must_check for iommu_flush_iotlb_page() /iommu_flush_iotlb_all(), I can run 'make xen' successfully. Sorry.

Quan

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

#46 lore raw

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

Quoted 53 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 09:20, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 09:12, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 08:47, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich

xen/drivers/passthrough/vtd/iommu.c static int iommu_flush_iotlb(struct domain · line 604

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +0 -0
@@ -604,15 +604,15 @@ static int iommu_flush_iotlb(struct domain
 *d,

unsigned long gfn,

Quoted 3 lines
xen/drivers/passthrough/vtd/iommu.c +0 -0
     return rc;
 }
 
Quoted 26 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
xen/drivers/passthrough/vtd/iommu.c +0 -1
-static void iommu_flush_iotlb_page(struct domain *d, unsigned

long

gfn,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
xen/drivers/passthrough/vtd/iommu.c +1 -1
-                                   unsigned int page_count)
+static int iommu_flush_iotlb_page(struct domain *d, unsigned long

gfn,

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 6 lines
Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +2 -1
+                                  unsigned int page_count)
 {
-    iommu_flush_iotlb(d, gfn, 1, page_count);
+    return iommu_flush_iotlb(d, gfn, 1, page_count);
 }
Quoted 10 lines

xen/drivers/passthrough/vtd/iommu.c

Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +2 -2
-static void iommu_flush_iotlb_all(struct domain *d)
+static int iommu_flush_iotlb_all(struct domain *d)
 {
-    iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
+    return iommu_flush_iotlb(d, INVALID_GFN, 0, 0);
 }

As already indicated in a reply to an earlier patch, despite what was said on the earlier version I think we should have __must_check here

If the static one is initialized for .callback, is it really necessary to add __must_check here?
I check it with compiler, and it is ok when I didn't add __must_check

here.

Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

Without you telling us what exactly you checked, I can't respond to this. Extending from the reply just sent to patch 3(?) and for the avoidance of doubt, you now obviously also need to __must_check-annotate the function pointer (to match the desire of wanting to never lose such an annotation on the way back up the call tree).

I checked -- without __must_check for iommu_flush_iotlb_page() / iommu_flush_iotlb_all().

Quoted 6 lines
Quoted 1 line

But _what_ did you check? I.e. the question isn't which functions you did

your

Quoted 2 lines

check with, but what behavioral checking you did.

without __must_check for iommu_flush_iotlb_page() /iommu_flush_iotlb_all(), I can run 'make xen' successfully. Sorry.

Oh, sure you can. Leaving the annotation out will always result in no more (and likely less) diagnostics. I.e. that's not a valid criteria.

Jan

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

author
#47 lore raw

PATCH v4 8/10 vt-d/ept: propagate IOMMU Device-TLB flush error up to EPT update.

In reply to Quan Xu

Propagate the IOMMU Device-TLB flush error up to the ept_set_entry(), when VT-d shares EPT page table.

CC Jun Nakajima <[email protected]>
CC Kevin Tian <[email protected]>
CC George Dunlap <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Feng Wu <[email protected]>
---
 xen/arch/x86/mm/p2m-ept.c           | 3 ++-
 xen/drivers/passthrough/vtd/iommu.c | 4 ++--
 xen/include/asm-x86/iommu.h         | 3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)
xen/arch/x86/mm/p2m-ept.c +2 -1
index 814cb72..34b96f8 100644
@@ -832,7 +832,8 @@ out:
          need_modify_vtd_table )
     {
         if ( iommu_hap_pt_share )
-            iommu_pte_flush(d, gfn, &ept_entry->epte, order, vtd_pte_present);
+            ret = iommu_pte_flush(d, gfn, &ept_entry->epte,
+                                  order, vtd_pte_present);
         else
         {
             if ( iommu_flags )
xen/drivers/passthrough/vtd/iommu.c +2 -2
index a749c67..bf77417 100644
@@ -1773,8 +1773,8 @@ static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn)
     return dma_pte_clear_one(d, (paddr_t)gfn << PAGE_SHIFT_4K);
 }
 
-int iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte,
-                    int order, bool_t present)
+int __must_check iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte,
+                                 int order, bool_t present)
 {
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu = NULL;
xen/include/asm-x86/iommu.h +2 -1
index 43f1620..3d2c354 100644
@@ -27,7 +27,8 @@ 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);
-int iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte, int order, bool_t present);
+int __must_check iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte,
+                                 int order, bool_t 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
#48 lore raw

Re: [PATCH v4 08/10] vt-d/ept: propagate IOMMU Device-TLB flush error up to EPT update.

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

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +2 -1
@@ -832,7 +832,8 @@ out:
          need_modify_vtd_table )
     {
         if ( iommu_hap_pt_share )
-            iommu_pte_flush(d, gfn, &ept_entry->epte, order, vtd_pte_present);
+            ret = iommu_pte_flush(d, gfn, &ept_entry->epte,
+                                  order, vtd_pte_present);
         else
         {
             if ( iommu_flags )

Looking at this in conjunction with patch 3, I can't see where "ret" would get consumed.

Jan

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

#49 lore raw

Re: [PATCH v4 08/10] vt-d/ept: propagate IOMMU Device-TLB flush error up to EPT update.

Quoted 16 lines · Jan Beulich

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

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +2 -1
@@ -832,7 +832,8 @@ out:
          need_modify_vtd_table )
     {
         if ( iommu_hap_pt_share )
-            iommu_pte_flush(d, gfn, &ept_entry->epte, order, vtd_pte_present);
+            ret = iommu_pte_flush(d, gfn, &ept_entry->epte,
+                                  order, vtd_pte_present);
         else
         {
             if ( iommu_flags )

Looking at this in conjunction with patch 3, I can't see where "ret" would get consumed.

Hmm, and here I see where "rc == 0" might be a better option than "entry_written".

If we know rc is zero, we can just use rc here instead of 'ret', and I think everything falls out.

If rc is not zero, then we have to do this "if ( !rc ) rc = ret;" business, which seems a bit silly to do when we know it's zero and don't expect that to change.

On the other hand, using rc *without* actually checking that it's zero seems like asking for trouble.

So perhaps it would be better if we take your advice for patch 3, and then use 'rc' here?

Everything else looks good.

-George

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

#50 lore raw

Re: [PATCH v4 08/10] vt-d/ept: propagate IOMMU Device-TLB flush error up to EPT update.

Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 10.05.16 at 16:58, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich

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

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +0 -1
@@ -832,7 +832,8 @@ out:
          need_modify_vtd_table )
     {
         if ( iommu_hap_pt_share )
-            iommu_pte_flush(d, gfn, &ept_entry->epte, order, 

vtd_pte_present);

Quoted 8 lines

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

Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +2 -0
+            ret = iommu_pte_flush(d, gfn, &ept_entry->epte,
+                                  order, vtd_pte_present);
         else
         {
             if ( iommu_flags )

Looking at this in conjunction with patch 3, I can't see where "ret" would get consumed.

Hmm, and here I see where "rc == 0" might be a better option than "entry_written".

If we know rc is zero, we can just use rc here instead of 'ret', and I think everything falls out.

If rc is not zero, then we have to do this "if ( !rc ) rc = ret;" business, which seems a bit silly to do when we know it's zero and don't expect that to change.

Quoted 5 lines

On the other hand, using rc *without* actually checking that it's zero seems like asking for trouble.

So perhaps it would be better if we take your advice for patch 3, and then use 'rc' here?

Ah, yes, that's a good 2nd reason.

Jan

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

author
#51 lore raw

Re: [PATCH v4 08/10] vt-d/ept: propagate IOMMU Device-TLB flush error up to EPT update.

In reply to Jan Beulich
Quoted 17 lines · Jan Beulich

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

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/arch/x86/mm/p2m-ept.c +2 -1
@@ -832,7 +832,8 @@ out:
          need_modify_vtd_table )
     {
         if ( iommu_hap_pt_share )
-            iommu_pte_flush(d, gfn, &ept_entry->epte, order, vtd_pte_present);
+            ret = iommu_pte_flush(d, gfn, &ept_entry->epte,
+                                  order, vtd_pte_present);
         else
         {
             if ( iommu_flags )

Looking at this in conjunction with patch 3, I can't see where "ret" would get consumed.

Sorry, this 'ret' should be 'rc' here, as I removed the pending

"
+ if ( !rc )
+ rc = ret;
+
"

from v4.

Quan

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

author
#52 lore raw

PATCH v4 9/10 IOMMU: propagate IOMMU Device-TLB flush error up to IOMMU suspending

In reply to Quan Xu

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                     | 72 ++++++++++++++++++++-------
 xen/drivers/passthrough/amd/iommu_init.c      |  9 +++-
 xen/drivers/passthrough/amd/pci_amd_iommu.c   |  2 +-
 xen/drivers/passthrough/iommu.c               |  7 ++-
 xen/drivers/passthrough/vtd/iommu.c           | 39 +++++++++++----
 xen/include/asm-x86/hvm/svm/amd-iommu-proto.h |  2 +-
 xen/include/xen/iommu.h                       |  4 +-
 7 files changed, 101 insertions(+), 34 deletions(-)
xen/arch/x86/acpi/power.c +54 -18
index 2885e31..1f7b8bf 100644
@@ -43,36 +43,71 @@ struct acpi_sleep_info acpi_sinfo;
 
 void do_suspend_lowlevel(void);
 
+enum dev_power_type
+{
+    /* Use for all of device power type */
+    TYPE_ALL,
+    TYPE_CONSOLE,
+    TYPE_TIME,
+    TYPE_I8259A,
+    TYPE_IOAPIC,
+    TYPE_IOMMU,
+    TYPE_LAPIC,
+    /* Use for error */
+    TYPE_UNKNOWN
+};
+
 static int device_power_down(void)
 {
-    console_suspend();
+    if ( console_suspend() )
+        return TYPE_CONSOLE;
 
-    time_suspend();
+    if ( time_suspend() )
+        return TYPE_TIME;
 
-    i8259A_suspend();
+    if ( i8259A_suspend() )
+        return TYPE_I8259A;
 
+    /* ioapic_suspend should never fail */
     ioapic_suspend();
 
-    iommu_suspend();
+    if ( iommu_suspend() )
+        return TYPE_IOMMU;
 
-    lapic_suspend();
+    if ( lapic_suspend() )
+        return TYPE_LAPIC;
 
     return 0;
 }
 
-static void device_power_up(void)
+static void device_power_up(enum dev_power_type type)
 {
-    lapic_resume();
-
-    iommu_resume();
-
-    ioapic_resume();
-
-    i8259A_resume();
-
-    time_resume();
-
-    console_resume();
+    switch ( type )
+    {
+    case TYPE_ALL:
+        /* fall through */
+    case TYPE_LAPIC:
+        lapic_resume();
+        /* fall through */
+    case TYPE_IOMMU:
+        iommu_resume();
+        /* fall through */
+    case TYPE_IOAPIC:
+        ioapic_resume();
+        /* fall through */
+    case TYPE_I8259A:
+        i8259A_resume();
+        /* fall through */
+    case TYPE_TIME:
+        time_resume();
+        /* fall through */
+    case TYPE_CONSOLE:
+        console_resume();
+        break;
+    default:
+        BUG();
+        break;
+    }
 }
 
 static void freeze_domains(void)
@@ -169,6 +204,7 @@ static int enter_state(u32 state)
     {
         printk(XENLOG_ERR "Some devices failed to power down.");
         system_state = SYS_STATE_resume;
+        device_power_up(error);
         goto done;
     }
 
@@ -196,7 +232,7 @@ static int enter_state(u32 state)
     write_cr4(cr4 & ~X86_CR4_MCE);
     write_efer(read_efer());
 
-    device_power_up();
+    device_power_up(TYPE_ALL);
 
     mcheck_init(&boot_cpu_data, 0);
     write_cr4(cr4);
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 70b7475..ac40f63 100644
@@ -626,6 +626,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/iommu.c +5 -2
index c013d91..8b26b1c 100644
@@ -404,11 +404,14 @@ int iommu_do_domctl(
     return ret;
 }
 
-void iommu_suspend()
+int __must_check 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 +30 -9
index bf77417..29cf870 100644
@@ -541,11 +541,12 @@ static int iommu_flush_iotlb_psi(
     return status;
 }
 
-static void iommu_flush_all(void)
+static int __must_check iommu_flush_all(void)
 {
     struct acpi_drhd_unit *drhd;
     struct iommu *iommu;
     int flush_dev_iotlb;
+    int rc = 0, ret;
 
     flush_all_cache();
     for_each_drhd_unit ( drhd )
@@ -553,8 +554,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);
+        ret = iommu_flush_iotlb_global(iommu, 0, flush_dev_iotlb);
+
+        if ( ret )
+            rc = ret;
     }
+
+    return rc;
 }
 
 static int iommu_flush_iotlb(struct domain *d, unsigned long gfn,
@@ -1267,7 +1273,9 @@ static void __hwdom_init intel_iommu_hwdom_init(struct domain *d)
     setup_hwdom_pci_devices(d, setup_hwdom_device);
     setup_hwdom_rmrr(d);
 
-    iommu_flush_all();
+    if ( iommu_flush_all() )
+        printk(XENLOG_WARNING VTDPREFIX
+               " intel_iommu_hwdom_init: IOMMU flush all failed.\n");
 
     for_each_drhd_unit ( drhd )
     {
@@ -2126,8 +2134,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)
@@ -2416,16 +2424,25 @@ 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 )
+    {
+        printk(XENLOG_WARNING VTDPREFIX
+               " vtd_suspend: IOMMU flush all failed.\n");
+        return rc;
+    }
 
     for_each_drhd_unit ( drhd )
     {
@@ -2454,6 +2471,8 @@ static void vtd_suspend(void)
         if ( !iommu_intremap && iommu_qinval )
             disable_qinval(iommu);
     }
+
+    return 0;
 }
 
 static void vtd_crash_shutdown(void)
@@ -2464,7 +2483,9 @@ static void vtd_crash_shutdown(void)
     if ( !iommu_enabled )
         return;
 
-    iommu_flush_all();
+    if ( iommu_flush_all() )
+        printk(XENLOG_WARNING VTDPREFIX
+               " vtd_crash_shutdown: IOMMU flush all failed.\n");
 
     for_each_drhd_unit ( drhd )
     {
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 6a64014..fee5a8f 100644
@@ -175,7 +175,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);
@@ -185,7 +185,7 @@ struct iommu_ops {
     void (*dump_p2m_table)(struct domain *d);
 };
 
-void iommu_suspend(void);
+int __must_check 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
#53 lore raw

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

xen/arch/x86/acpi/power.c struct acpi_sleep_info acpi_sinfo; · line 48

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/arch/x86/acpi/power.c +3 -0
@@ -43,36 +43,71 @@ struct acpi_sleep_info acpi_sinfo;
 
 void do_suspend_lowlevel(void);
 
+enum dev_power_type
+{
+    /* Use for all of device power type */

No sure what this comment is meant to say. Also if you mean it to apply to just TYPE_ALL, it would probably better be placed on that same line. In any event it is missing a full stop.

xen/arch/x86/acpi/power.c struct acpi_sleep_info acpi_sinfo; · line 56

Quoted 8 lines
xen/arch/x86/acpi/power.c +8 -0
+    TYPE_ALL,
+    TYPE_CONSOLE,
+    TYPE_TIME,
+    TYPE_I8259A,
+    TYPE_IOAPIC,
+    TYPE_IOMMU,
+    TYPE_LAPIC,
+    /* Use for error */

Same here, but ...

xen/arch/x86/acpi/power.c struct acpi_sleep_info acpi_sinfo; · line 57

Quoted 1 line
xen/arch/x86/acpi/power.c +1 -0
+    TYPE_UNKNOWN

... this isn't used anywhere anyway, and hence should be left out. Errors would better be reported via -E... values anyway.

xen/arch/x86/acpi/power.c struct acpi_sleep_info acpi_sinfo; · line 63

Quoted 5 lines
xen/arch/x86/acpi/power.c +2 -1
 static int device_power_down(void)
 {
-    console_suspend();
+    if ( console_suspend() )
+        return TYPE_CONSOLE;

This (together with the resume side) makes me guess that the use of TYPE_ as a prefix confused not just me, but also you: Here you want to tell the caller that everything _prior_ to console suspend (which happens to be nothing in this specific case) needs to be undone. Yet below you use TYPE_CONSOLE as an indication that console_resume() needs to be called.

xen/arch/x86/acpi/power.c struct acpi_sleep_info acpi_sinfo; · line 72

Quoted 10 lines
xen/arch/x86/acpi/power.c +5 -2
-    time_suspend();
+    if ( time_suspend() )
+        return TYPE_TIME;
 
-    i8259A_suspend();
+    if ( i8259A_suspend() )
+        return TYPE_I8259A;
 
+    /* ioapic_suspend should never fail */
     ioapic_suspend();

The comment is bogus: "should" means it can in theory. Yet the function having void return type means it just cannot fail.

Quoted 9 lines
xen/arch/x86/acpi/power.c +1 -7
-static void device_power_up(void)
+static void device_power_up(enum dev_power_type type)
 {
-    lapic_resume();
-
-    iommu_resume();
-
-    ioapic_resume();
-

xen/arch/x86/acpi/power.c struct acpi_sleep_info acpi_sinfo; · line 89

Quoted 10 lines
xen/arch/x86/acpi/power.c +5 -5
-    i8259A_resume();
-
-    time_resume();
-
-    console_resume();
+    switch ( type )
+    {
+    case TYPE_ALL:
+        /* fall through */
+    case TYPE_LAPIC:

No need for a fall-through comment between immediately adjacent case labels.

xen/arch/x86/acpi/power.c static int enter_state(u32 state) · line 207

Quoted 5 lines
xen/arch/x86/acpi/power.c +1 -0
@@ -169,6 +204,7 @@ static int enter_state(u32 state)
     {
         printk(XENLOG_ERR "Some devices failed to power down.");
         system_state = SYS_STATE_resume;
+        device_power_up(error);

Either error's and device_power_down()'s return type get changed to enum dev_power_type, or this needs a "error > 0" conditional.

xen/arch/x86/acpi/power.c static void __hwdom_init intel_iommu_hwdom_init(struct domain *d) · line 1278

Quoted 8 lines
xen/arch/x86/acpi/power.c +3 -1
@@ -1267,7 +1273,9 @@ static void __hwdom_init intel_iommu_hwdom_init(struct domain *d)
     setup_hwdom_pci_devices(d, setup_hwdom_device);
     setup_hwdom_rmrr(d);
 
-    iommu_flush_all();
+    if ( iommu_flush_all() )
+        printk(XENLOG_WARNING VTDPREFIX
+               " intel_iommu_hwdom_init: IOMMU flush all failed.\n");

As said (and I think a number of times) before: At least when you already hold the error value in your hands, please also log it. Also personally I'm opposed to including function names in non-debug log messages, but I'll leave that decision to the VT-d maintainers here.

Jan

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

author
#54 lore raw

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

Quoted 11 lines · Jan Beulich

xen/arch/x86/acpi/power.c struct acpi_sleep_info acpi_sinfo; · line 63

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/arch/x86/acpi/power.c +2 -1
 static int device_power_down(void)
 {
-    console_suspend();
+    if ( console_suspend() )
+        return TYPE_CONSOLE;

This (together with the resume side) makes me guess that the use of TYPE_ as a prefix confused not just me, but also you:

Yes, this is really not a good prefix, and probably pretty bad to use 'ERROR_'. What about 'PRIOR_'? then I also need to adjust device_power_up() as ...

Quoted 5 lines

Here you want to tell the caller
that everything _prior_ to console suspend (which happens to be nothing in this specific case) needs to be undone. Yet below you use TYPE_CONSOLE as an indication that
console_resume() needs to be called.

... this,

+ switch ( prior )

+    {
       ...

+ time_resume();
+ case PRIOR_TIME:
+ console_resume();
+ case PRIOR_CONSOLE:

        ...

+ }

Quoted 9 lines
Quoted 9 lines
xen/arch/x86/acpi/power.c +4 -2
-    time_suspend();
+    if ( time_suspend() )
+        return TYPE_TIME;
 
-    i8259A_suspend();
+    if ( i8259A_suspend() )
+        return TYPE_I8259A;
Quoted 6 lines
Quoted 2 lines

+ /* ioapic_suspend should never fail */

     ioapic_suspend();

The comment is bogus: "should" means it can in theory. Yet the function having void return type means it just cannot fail.

I'll use 'cannot', instead of 'should'.
Another question, I check the code again, and the rest of the functions (console_suspend/ time_suspend/ i8259A_suspend / ioapic_suspend / lapic_suspend ), in device_power_down(), always returned '0'. Maybe I need to fix these functions annotation from 'int' to 'void', and then I can add a comment on the device_power_down().

More that, if the ' iommu_suspend()' is the only fail, could we re-consider the previous v2/v3 solution with 'goto'?

Quoted 14 lines

xen/arch/x86/acpi/power.c static int enter_state(u32 state) · line 207

Quoted 5 lines
xen/arch/x86/acpi/power.c +1 -0
@@ -169,6 +204,7 @@ static int enter_state(u32 state)
     {
         printk(XENLOG_ERR "Some devices failed to power down.");
         system_state = SYS_STATE_resume;
+        device_power_up(error);

Either error's and device_power_down()'s return type get changed to enum dev_power_type, or this needs a "error > 0" conditional.

xen/arch/x86/acpi/power.c static void __hwdom_init

Quoted 1 line
xen/arch/x86/acpi/power.c +0 -0
@@ -1267,7 +1273,9 @@ static void __hwdom_init

intel_iommu_hwdom_init(struct domain *d)

Quoted 3 lines
xen/arch/x86/acpi/power.c +0 -0
     setup_hwdom_pci_devices(d, setup_hwdom_device);
     setup_hwdom_rmrr(d);
 
Quoted 7 lines

xen/arch/x86/acpi/power.c static void __hwdom_init · line 1278

Quoted 4 lines
xen/arch/x86/acpi/power.c +3 -1
-    iommu_flush_all();
+    if ( iommu_flush_all() )
+        printk(XENLOG_WARNING VTDPREFIX
+               " intel_iommu_hwdom_init: IOMMU flush all failed.\n");

As said (and I think a number of times) before: At least when you already hold the error value in your hands, please also log it.

Agreed, and I will apply for other patches.

Quoted 4 lines

Also personally I'm opposed to
including function names in non-debug log messages, but I'll leave that decision to the VT-d maintainers here.

Albeit Reluctantly, I will fix it.

Quan

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

#55 lore raw

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

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 13.05.16 at 05:39, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich

xen/arch/x86/acpi/power.c struct acpi_sleep_info acpi_sinfo; · line 63

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/arch/x86/acpi/power.c +2 -1
 static int device_power_down(void)
 {
-    console_suspend();
+    if ( console_suspend() )
+        return TYPE_CONSOLE;

This (together with the resume side) makes me guess that the use of TYPE_ as a prefix confused not just me, but also you:

Quoted 3 lines

Yes, this is really not a good prefix, and probably pretty bad to use 'ERROR_'.
What about 'PRIOR_'? then I also need to adjust device_power_up() as ...

What about SAVED_?

Quoted 15 lines
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/acpi/power.c +4 -2
-    time_suspend();
+    if ( time_suspend() )
+        return TYPE_TIME;
 
-    i8259A_suspend();
+    if ( i8259A_suspend() )
+        return TYPE_I8259A;
Quoted 6 lines
Quoted 2 lines

+ /* ioapic_suspend should never fail */

     ioapic_suspend();

The comment is bogus: "should" means it can in theory. Yet the function having void return type means it just cannot fail.

Quoted 6 lines

I'll use 'cannot', instead of 'should'.
Another question, I check the code again, and the rest of the functions (console_suspend/ time_suspend/ i8259A_suspend / ioapic_suspend / lapic_suspend ), in device_power_down(), always returned '0'. Maybe I need to fix these functions annotation from 'int' to 'void', and then I can add a comment on the device_power_down().

Please don't. Generally the possibility of failure exists, and hence if functions have already been written to account for that, we shouldn't strip that capability out.

Jan

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

author
#56 lore raw

Re: [PATCH v4 09/10] 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 13.05.16 at 05:39, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

xen/arch/x86/acpi/power.c struct acpi_sleep_info acpi_sinfo; · line 63

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/arch/x86/acpi/power.c +2 -1
 static int device_power_down(void)  {
-    console_suspend();
+    if ( console_suspend() )
+        return TYPE_CONSOLE;

This (together with the resume side) makes me guess that the use of TYPE_ as a prefix confused not just me, but also you:

Quoted 6 lines
Quoted 3 lines

Yes, this is really not a good prefix, and probably pretty bad to use 'ERROR_'.
What about 'PRIOR_'? then I also need to adjust device_power_up() as ...

What about SAVED_?

much better, I'll take it in v5. Thanks.

Quoted 19 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
xen/arch/x86/acpi/power.c +5 -2
-    time_suspend();
+    if ( time_suspend() )
+        return TYPE_TIME;
 
-    i8259A_suspend();
+    if ( i8259A_suspend() )
+        return TYPE_I8259A;
 
+    /* ioapic_suspend should never fail */
     ioapic_suspend();
Quoted 8 lines
Quoted 3 lines

The comment is bogus: "should" means it can in theory. Yet the function having void return type means it just cannot fail.

I'll use 'cannot', instead of 'should'.
Another question, I check the code again, and the rest of the functions (console_suspend/ time_suspend/ i8259A_suspend / ioapic_suspend / lapic_suspend ), in device_power_down(), always returned

Quoted 8 lines

'0'.

Quoted 2 lines

Maybe I need to fix these functions annotation from 'int' to 'void', and then I can add a comment on the device_power_down().

Please don't. Generally the possibility of failure exists, and hence if functions have already been written to account for that, we shouldn't strip that capability out.

Got it.

Quan

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

author
#57 lore raw

PATCH v4 10/10 vt-d: propagate error up to ME phantom function mapping and unmapping

In reply to Quan Xu

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 |  3 ++-
 xen/drivers/passthrough/vtd/iommu.c  | 18 ++++++++++++++----
 xen/drivers/passthrough/vtd/quirks.c | 28 ++++++++++++++++++----------
 3 files changed, 34 insertions(+), 15 deletions(-)
xen/drivers/passthrough/vtd/extern.h +2 -1
index cbe0286..6772839 100644
@@ -91,7 +91,8 @@ 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 __must_check 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/iommu.c +14 -4
index 29cf870..ac81c8a 100644
@@ -1296,7 +1296,7 @@ int domain_context_mapping_one(
     u64 maddr, pgd_maddr;
     u16 seg = iommu->intel->drhd->segment;
     int agaw;
-    int rc;
+    int rc, ret;
 
     ASSERT(pcidevs_locked());
     spin_lock(&iommu->lock);
@@ -1430,7 +1430,12 @@ int domain_context_mapping_one(
     unmap_vtd_domain_page(context_entries);
 
     if ( !seg )
-        me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+    {
+        ret = me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+
+        if ( !rc )
+            rc = ret;
+    }
 
     return rc;
 }
@@ -1527,7 +1532,7 @@ int domain_context_unmap_one(
     struct context_entry *context, *context_entries;
     u64 maddr;
     int iommu_domid;
-    int rc;
+    int rc, ret;
 
     ASSERT(pcidevs_locked());
     spin_lock(&iommu->lock);
@@ -1575,7 +1580,12 @@ int domain_context_unmap_one(
     unmap_vtd_domain_page(context_entries);
 
     if ( !iommu->intel->drhd->segment )
-        me_wifi_quirk(domain, bus, devfn, UNMAP_ME_PHANTOM_FUNC);
+    {
+        ret = me_wifi_quirk(domain, bus, devfn, UNMAP_ME_PHANTOM_FUNC);
+
+        if ( !rc )
+            rc = ret;
+    }
 
     return rc;
 }
xen/drivers/passthrough/vtd/quirks.c +18 -10
index 473d1fc..e37060c 100644
@@ -331,10 +331,12 @@ 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 __must_check 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));
@@ -342,23 +344,27 @@ 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 __must_check 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);
@@ -372,7 +378,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;
@@ -382,7 +388,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);
@@ -398,12 +404,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
#58 lore raw

Re: [PATCH v4 10/10] vt-d: propagate error up to ME phantom function mapping and unmapping

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

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
xen/drivers/passthrough/vtd/iommu.c +6 -1
@@ -1430,7 +1430,12 @@ int domain_context_mapping_one(
     unmap_vtd_domain_page(context_entries);
 
     if ( !seg )
-        me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+    {
+        ret = me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+
+        if ( !rc )
+            rc = ret;
+    }

Is there any use in calling this function if an earlier error occurred? If not, the change can be more lightweight (while in the unmap case it should probably stay as is, to fit the "best effort" theme).

Jan

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

author
#59 lore raw

Re: [PATCH v4 10/10] vt-d: propagate error up to ME phantom function mapping and unmapping

Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -1430,7 +1430,12 @@ int domain_context_mapping_one(
     unmap_vtd_domain_page(context_entries);
 
Quoted 11 lines

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

Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +6 -1
     if ( !seg )
-        me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+    {
+        ret = me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+
+        if ( !rc )
+            rc = ret;
+    }

Is there any use in calling this function if an earlier error occurred? If not,

It is no use.

We may need to consider this call tree:

   $ me_wifi_quirk()--domain_context_mapping_one()--domain_context_mapping()--reassign_device_ownership()--...

Then, what about dropping this patch? Leave it as is,
or remove ' __must_check' annotation and propagate error up to the above call tree only?

Quoted 3 lines

the change can be more lightweight (while in the unmap case it should
probably stay as is, to fit the "best effort" theme).

Quan

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

#60 lore raw

Re: [PATCH v4 10/10] vt-d: propagate error up to ME phantom function mapping and unmapping

Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 10:35, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -1430,7 +1430,12 @@ int domain_context_mapping_one(
     unmap_vtd_domain_page(context_entries);
 
Quoted 11 lines

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

Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +6 -1
     if ( !seg )
-        me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+    {
+        ret = me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+
+        if ( !rc )
+            rc = ret;
+    }

Is there any use in calling this function if an earlier error occurred? If not,

Quoted 1 line

It is no use.

With this I don't understand ...

Quoted 8 lines

We may need to consider this call tree:

   $ 

me_wifi_quirk()--domain_context_mapping_one()--domain_context_mapping()--reass ign_device_ownership()--...

Then, what about dropping this patch? Leave it as is,
or remove ' __must_check' annotation and propagate error up to the above
call tree only?

... this. If calling the function is pointless if an earlier error occurred, why don't you just check rc to be zero alongside the !seg check?

Jan

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

author
#61 lore raw

Re: [PATCH v4 10/10] vt-d: propagate error up to ME phantom function mapping and unmapping

Quoted 30 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 11.05.16 at 10:35, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.05.16 at 10:54, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -1430,7 +1430,12 @@ int domain_context_mapping_one(
     unmap_vtd_domain_page(context_entries);
 
Quoted 12 lines

Review int domain_context_mapping_one( · line 1439

Quoted 9 lines
(quoted diff) +7 -1
     if ( !seg )
-        me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+    {
+        ret = me_wifi_quirk(domain, bus, devfn,
+ MAP_ME_PHANTOM_FUNC);
+
+        if ( !rc )
+            rc = ret;
+    }

Is there any use in calling this function if an earlier error occurred? If not,

Quoted 1 line

It is no use.

With this I don't understand ...

Quoted 3 lines

We may need to consider this call tree:

   $

me_wifi_quirk()--domain_context_mapping_one()--

domain_context_mapping(

Quoted 3 lines

)--reass
ign_device_ownership()--...

Quoted 7 lines
Quoted 3 lines

Then, what about dropping this patch? Leave it as is, or remove ' __must_check' annotation and propagate error up to the above call tree only?

... this. If calling the function is pointless if an earlier error occurred, why don't you just check rc to be zero alongside the !seg check?

---
Good idea.

---

Taken together, there are 3 call trees to me_wifi_quirk():

1). ...--me_wifi_quirk()--domain_context_mapping_one()--domain_context_mapping()--setup_hwdom_device()

There is no use in calling this function if an earlier error occurred. The change can be more lightweight (the detailed change is pending).

2). me_wifi_quirk()--domain_context_unmap_one()--...

As you mentioned, while in the unmap case it should probably stay as is, to fit the "best effort" theme.

Then I need to remove the __must_check annotation of me_wifi_quirk().

3). me_wifi_quirk()--domain_context_mapping_one()--domain_context_mapping()--reassign_device_ownership()
This is not an earlier error, so we need propagate the error up to the call tree (the detailed change is pending).

The below is based on previous v4 p1...p9:
---

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/iommu.c +2 -2
index 29cf870..0ac7894 100644
@@ -1429,8 +1429,8 @@ int domain_context_mapping_one(
 
     unmap_vtd_domain_page(context_entries);
 
-    if ( !seg )
-        me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+    if ( !seg && !rc )
+        rc = me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
 
     return rc;
 }
xen/drivers/passthrough/vtd/quirks.c +18 -10
index 473d1fc..3606b52 100644
@@ -331,10 +331,12 @@ 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 __must_check 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));
@@ -342,23 +344,27 @@ 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);
@@ -372,7 +378,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;
@@ -382,7 +388,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);
@@ -398,12 +404,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)

--
1.9.1

Quan

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

#62 lore raw

Re: [PATCH v4 10/10] vt-d: propagate error up to ME phantom function mapping and unmapping

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 07:16, <[email protected]> wrote:

Taken together, there are 3 call trees to me_wifi_quirk():

1).
...--me_wifi_quirk()--domain_context_mapping_one()--domain_context_mapping()--se tup_hwdom_device()

There is no use in calling this function if an earlier
error occurred. The change can be more lightweight (the detailed change is pending).

Quoted 7 lines

2). me_wifi_quirk()--domain_context_unmap_one()--...

As you mentioned, while in the unmap case it should
probably stay as is, to fit the "best effort" theme.

Then I need to remove the __must_check annotation of
me_wifi_quirk().

This does not follow from the above. You again should propagate the error in all cases (unless it would overwrite an earlier error - as you're doing in various other places).

Jan

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

author
#63 lore raw

Re: [PATCH v4 10/10] vt-d: propagate error up to ME phantom function mapping and unmapping

Quoted 18 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 12.05.16 at 07:16, <[email protected]> wrote:

Taken together, there are 3 call trees to me_wifi_quirk():

1).
...--me_wifi_quirk()--domain_context_mapping_one()--

domain_context_map

Quoted 12 lines

ping()--se
tup_hwdom_device()

There is no use in calling this function if an
earlier error occurred. The change can be more lightweight (the detailed change is pending).

2). me_wifi_quirk()--domain_context_unmap_one()--...

As you mentioned, while in the unmap case it
should probably stay as is, to fit the "best effort" theme.

Quoted 7 lines
Quoted 2 lines

Then I need to remove the __must_check annotation
of me_wifi_quirk().

This does not follow from the above. You again should propagate the error in all cases (unless it would overwrite an earlier error - as you're doing in various other places).

Sorry, I know the item 2). is tricky, as I am confused about ' while in the unmap case it should probably stay as is, to fit the "best effort" theme '.

Actually, what I need to enhance the p10 are:

- drop ret
- replace the

     if ( !seg )

- me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+ {
+ ret = me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+
+ if ( !rc )
+ rc = ret;
+ }

____TO_____

- if ( !seg )
- me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);
+ if ( !seg && !rc )
+ rc = me_wifi_quirk(domain, bus, devfn, MAP_ME_PHANTOM_FUNC);

btw, I found I am struggling in this v4 and I will spend more time fixing. thanks for your patience. Quan

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