Skip to contentSkip to conversation

VT-d Device-TLB flush issue

PATCH Superseded Quan Xu 3 participants 31 messages Feb 5, 2016 – Feb 23, 2016

v5 of 14 Superseded Latest is v14 →

lore
Share & tools
lore

Quan Xu

author
#0 lore raw

v5 cover VT-d Device-TLB flush issue

This patches fix current timeout concern and also allow limited ATS support:

1. Check VT-d Device-TLB flush error.
This patch checks all kinds of error and all the way up the call trees of VT-d Device-TLB flush.

2. Reduce spin timeout to 1ms, which can be boot-time changed with 'vtd_qi_timeout'. For example:
multiboot /boot/xen.gz ats=1 vtd_qi_timeout=100

3. Pass down a flag indicating whether the lock is being held.

4. Fix vt-d Device-TLB flush timeout issue.
If Device-TLB flush is timeout, we'll hide the target ATS device and crash the domain owning this ATS device. If impacted domain is hardware domain, just throw out a warning.
The hidden device will be disallowed to be further assigned to any domain.

----

* DMAR_OPERATION_TIMEOUT should be also chopped down to a low number of milliseconds.
As Kevin Tian mentioned in 'Revisit VT-d asynchronous flush issue', We also confirmed with hardware team that 1ms is large enough for IOMMU internal flush. So I can change DMAR_OPERATION_TIMEOUT from 1000 ms to 1 ms.

IOMMU_WAIT_OP() is only for VT-d registers read/write, and there is also a panic. We need a further discussion whether or how to remove this panic in next patch set.

* The coming patch set will fix IOTLB/Context/IETC flush timeout.

-Changes in v5:
* Split the 'check VT-d Device-TLB flush error' into MMU part and IOMMU part. (P1-P2)
* Add a new standalone entry for new command 'vtd_qi_timeout' in docs/misc/xen-command-line.markdown.(P3)
* Change the option name from 'iommu_qi_timeout_ms' to 'vtd_qi_timeout'.(P3)
* Pass down a flag indicating whether the lock is being held.(P4-P6)
* Fix multiple return points when this can be trivially avoided.(P7)
* Enhance the print out message. (P7)
* Enhance the comment.(P7)
* Consult the bitmap along with the domain ID array.(P7)

Quan Xu (7):
VT-d: Check VT-d Device-TLB flush error(IOMMU part).
VT-d: Check VT-d Device-TLB flush error(MMU part).
VT-d: Reduce spin timeout to 1ms, which can be boot-time changed.
VT-d: Refactor iommu_ops .iotlb_flush() and iotlb_flush_all()
VT-d: Refactor iommu_ops .map_page() and unmap_page()
VT-d: Refactor iommu_flush .iotlb()
VT-d: Fix vt-d Device-TLB flush timeout issue.

 docs/misc/xen-command-line.markdown           |   7 ++
 xen/arch/arm/p2m.c                            |   2 +-
 xen/arch/x86/acpi/power.c                     |   6 +-
 xen/arch/x86/crash.c                          |   3 +-
 xen/arch/x86/domain_build.c                   |   5 +-
 xen/arch/x86/mm.c                             |  15 ++-
 xen/arch/x86/mm/p2m-ept.c                     |  15 ++-
 xen/arch/x86/mm/p2m-pt.c                      |  14 ++-
 xen/arch/x86/mm/p2m.c                         |  24 ++--
 xen/arch/x86/x86_64/mm.c                      |   5 +-
 xen/common/domain.c                           |   2 +-
 xen/common/grant_table.c                      |  16 ++-
 xen/common/memory.c                           |   5 +-
 xen/drivers/passthrough/amd/iommu_init.c      |   4 +-
 xen/drivers/passthrough/amd/iommu_map.c       |   7 +-
 xen/drivers/passthrough/amd/pci_amd_iommu.c   |   7 +-
 xen/drivers/passthrough/arm/smmu.c            |  15 ++-
 xen/drivers/passthrough/iommu.c               |  47 ++++---
 xen/drivers/passthrough/pci.c                 |   2 +-
 xen/drivers/passthrough/vtd/extern.h          |  12 +-
 xen/drivers/passthrough/vtd/iommu.c           | 173 +++++++++++++++++---------
 xen/drivers/passthrough/vtd/iommu.h           |   3 +-
 xen/drivers/passthrough/vtd/qinval.c          |  93 +++++++++++++-
 xen/drivers/passthrough/vtd/quirks.c          |  26 ++--
 xen/drivers/passthrough/vtd/x86/ats.c         |  14 ++-
 xen/drivers/passthrough/vtd/x86/vtd.c         |  18 ++-
 xen/drivers/passthrough/x86/iommu.c           |   9 +-
 xen/include/asm-x86/hvm/svm/amd-iommu-proto.h |   8 +-
 xen/include/asm-x86/iommu.h                   |   3 +-
 xen/include/asm-x86/p2m.h                     |   6 +-
 xen/include/xen/iommu.h                       |  37 +++---
 31 files changed, 429 insertions(+), 174 deletions(-)
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v5 1/7 VT-d: Check VT-d Device-TLB flush error(IOMMU part).

This patch checks all kinds of error and all the way up the call trees of VT-d Device-TLB flush(IOMMU part).

---
 xen/drivers/passthrough/amd/iommu_init.c      |   4 +-
 xen/drivers/passthrough/amd/pci_amd_iommu.c   |   4 +-
 xen/drivers/passthrough/arm/smmu.c            |  13 +--
 xen/drivers/passthrough/iommu.c               |  37 +++++---
 xen/drivers/passthrough/vtd/extern.h          |   4 +-
 xen/drivers/passthrough/vtd/iommu.c           | 125 ++++++++++++++++----------
 xen/drivers/passthrough/vtd/qinval.c          |   2 +-
 xen/drivers/passthrough/vtd/quirks.c          |  26 +++---
 xen/drivers/passthrough/vtd/x86/vtd.c         |  17 +++-
 xen/drivers/passthrough/x86/iommu.c           |   6 +-
 xen/include/asm-x86/hvm/svm/amd-iommu-proto.h |   4 +-
 xen/include/asm-x86/iommu.h                   |   2 +-
 xen/include/xen/iommu.h                       |  20 ++---
 13 files changed, 166 insertions(+), 98 deletions(-)
xen/drivers/passthrough/amd/iommu_init.c +3 -1
index d90a2d2..ec47e22 100644
@@ -1340,12 +1340,14 @@ 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_resume(void)
xen/drivers/passthrough/amd/pci_amd_iommu.c +3 -1
index c1c0b6b..449de13 100644
@@ -280,7 +280,7 @@ static int amd_iommu_domain_init(struct domain *d)
     return 0;
 }
 
-static void __hwdom_init amd_iommu_hwdom_init(struct domain *d)
+static int __hwdom_init amd_iommu_hwdom_init(struct domain *d)
 {
     unsigned long i; 
     const struct amd_iommu *iommu;
@@ -312,6 +312,8 @@ static void __hwdom_init amd_iommu_hwdom_init(struct domain *d)
             BUG();
 
     setup_hwdom_pci_devices(d, amd_iommu_setup_hwdom_device);
+
+    return 0;
 }
 
 void amd_iommu_disable_domain_device(struct domain *domain,
xen/drivers/passthrough/arm/smmu.c +8 -5
index bb08827..155b7f3 100644
@@ -2544,7 +2544,7 @@ static int force_stage = 2;
  */
 static u32 platform_features = ARM_SMMU_FEAT_COHERENT_WALK;
 
-static void arm_smmu_iotlb_flush_all(struct domain *d)
+static int arm_smmu_iotlb_flush_all(struct domain *d)
 {
 	struct arm_smmu_xen_domain *smmu_domain = domain_hvm_iommu(d)->arch.priv;
 	struct iommu_domain *cfg;
@@ -2561,13 +2561,15 @@ static void arm_smmu_iotlb_flush_all(struct domain *d)
 		arm_smmu_tlb_inv_context(cfg->priv);
 	}
 	spin_unlock(&smmu_domain->lock);
+
+        return 0;
 }
 
-static void arm_smmu_iotlb_flush(struct domain *d, unsigned long gfn,
-                                 unsigned int page_count)
+static int arm_smmu_iotlb_flush(struct domain *d, unsigned long gfn,
+                                unsigned int page_count)
 {
     /* ARM SMMU v1 doesn't have flush by VMA and VMID */
-    arm_smmu_iotlb_flush_all(d);
+    return arm_smmu_iotlb_flush_all(d);
 }
 
 static struct iommu_domain *arm_smmu_get_domain(struct domain *d,
@@ -2737,8 +2739,9 @@ static int arm_smmu_iommu_domain_init(struct domain *d)
 	return 0;
 }
 
-static void __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d)
+static int __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d)
 {
+        return 0;
 }
 
 static void arm_smmu_iommu_domain_teardown(struct domain *d)
xen/drivers/passthrough/iommu.c +24 -13
index d5137733..cdf8e9a 100644
@@ -146,14 +146,15 @@ static void __hwdom_init check_hwdom_reqs(struct domain *d)
     iommu_dom0_strict = 1;
 }
 
-void __hwdom_init iommu_hwdom_init(struct domain *d)
+int __hwdom_init iommu_hwdom_init(struct domain *d)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    int rc = 0;
 
     check_hwdom_reqs(d);
 
     if ( !iommu_enabled )
-        return;
+        return 0;
 
     register_keyhandler('o', &iommu_p2m_table);
     d->need_iommu = !!iommu_dom0_strict;
@@ -171,7 +172,10 @@ 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);
+            rc = hd->platform_ops->map_page(d, gfn, mfn, mapping);
+            if ( rc )
+                return rc;
+
             if ( !(i++ & 0xfffff) )
                 process_pending_softirqs();
         }
@@ -266,24 +270,24 @@ static void iommu_free_pagetables(unsigned long unused)
                             cpumask_cycle(smp_processor_id(), &cpu_online_map));
 }
 
-void iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
+int iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
 
     if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush )
-        return;
+        return 0;
 
-    hd->platform_ops->iotlb_flush(d, gfn, page_count);
+    return hd->platform_ops->iotlb_flush(d, gfn, page_count);
 }
 
-void iommu_iotlb_flush_all(struct domain *d)
+int iommu_iotlb_flush_all(struct domain *d)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
 
     if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush_all )
-        return;
+        return 0;
 
-    hd->platform_ops->iotlb_flush_all(d);
+    return hd->platform_ops->iotlb_flush_all(d);
 }
 
 int __init iommu_setup(void)
@@ -354,11 +358,14 @@ int iommu_do_domctl(
     return ret;
 }
 
-void iommu_suspend()
+int iommu_suspend()
 {
     const struct iommu_ops *ops = iommu_get_ops();
+
     if ( iommu_enabled )
-        ops->suspend();
+        return ops->suspend();
+
+    return 0;
 }
 
 void iommu_share_p2m_table(struct domain* d)
@@ -369,12 +376,16 @@ void iommu_share_p2m_table(struct domain* d)
         ops->share_p2m(d);
 }
 
-void iommu_crash_shutdown(void)
+int iommu_crash_shutdown(void)
 {
     const struct iommu_ops *ops = iommu_get_ops();
+
     if ( iommu_enabled )
-        ops->crash_shutdown();
+        return ops->crash_shutdown();
+
     iommu_enabled = iommu_intremap = 0;
+
+    return 0;
 }
 
 int iommu_get_reserved_device_memory(iommu_grdm_t *func, void *ctxt)
xen/drivers/passthrough/vtd/extern.h +2 -2
index 8acf889..ec9c513 100644
@@ -91,11 +91,11 @@ 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 *);
 int platform_supports_intremap(void);
 int platform_supports_x2apic(void);
 
-void vtd_set_hwdom_mapping(struct domain *d);
+int vtd_set_hwdom_mapping(struct domain *d);
 
 #endif // _VTD_EXTERN_H_
xen/drivers/passthrough/vtd/iommu.c +77 -48

316 lines not on this page · raw message

xen/drivers/passthrough/vtd/qinval.c +1 -1
index b81b0bd..946e812 100644
@@ -324,7 +324,7 @@ static int flush_iotlb_qi(
     if ( flush_non_present_entry )
     {
         if ( !cap_caching_mode(iommu->cap) )
-            return 1;
+            return 0;
         else
             did = 0;
     }
xen/drivers/passthrough/vtd/quirks.c +16 -10
index 1888843..d9aea7e 100644
@@ -332,10 +332,11 @@ void __init platform_quirks_init(void)
  * assigning Intel integrated wifi device to a guest.
  */
 
-static void map_me_phantom_function(struct domain *domain, u32 dev, int map)
+static int map_me_phantom_function(struct domain *domain, u32 dev, int map)
 {
     struct acpi_drhd_unit *drhd;
     struct pci_dev *pdev;
+    int rc = 0;
 
     /* find ME VT-d engine base on a real ME device */
     pdev = pci_get_pdev(0, 0, PCI_DEVFN(dev, 0));
@@ -343,23 +344,26 @@ static void map_me_phantom_function(struct domain *domain, u32 dev, int map)
 
     /* map or unmap ME phantom function */
     if ( map )
-        domain_context_mapping_one(domain, drhd->iommu, 0,
-                                   PCI_DEVFN(dev, 7), NULL);
+        rc = domain_context_mapping_one(domain, drhd->iommu, 0,
+                                        PCI_DEVFN(dev, 7), NULL);
     else
-        domain_context_unmap_one(domain, drhd->iommu, 0,
-                                 PCI_DEVFN(dev, 7));
+        rc = domain_context_unmap_one(domain, drhd->iommu, 0,
+                                      PCI_DEVFN(dev, 7));
+
+    return rc;
 }
 
-void me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map)
+int me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map)
 {
     u32 id;
+    int rc = 0;
 
     id = pci_conf_read32(0, 0, 0, 0, 0);
     if ( IS_CTG(id) )
     {
         /* quit if ME does not exist */
         if ( pci_conf_read32(0, 0, 3, 0, 0) == 0xffffffff )
-            return;
+            return -ENOENT;
 
         /* if device is WLAN device, map ME phantom device 0:3.7 */
         id = pci_conf_read32(0, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), 0);
@@ -373,7 +377,7 @@ void me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map)
             case 0x423b8086:
             case 0x423c8086:
             case 0x423d8086:
-                map_me_phantom_function(domain, 3, map);
+                rc = map_me_phantom_function(domain, 3, map);
                 break;
             default:
                 break;
@@ -383,7 +387,7 @@ void me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map)
     {
         /* quit if ME does not exist */
         if ( pci_conf_read32(0, 0, 22, 0, 0) == 0xffffffff )
-            return;
+            return -ENOENT;
 
         /* if device is WLAN device, map ME phantom device 0:22.7 */
         id = pci_conf_read32(0, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), 0);
@@ -399,12 +403,14 @@ void me_wifi_quirk(struct domain *domain, u8 bus, u8 devfn, int map)
             case 0x42388086:        /* Puma Peak */
             case 0x422b8086:
             case 0x422c8086:
-                map_me_phantom_function(domain, 22, map);
+                rc = map_me_phantom_function(domain, 22, map);
                 break;
             default:
                 break;
         }
     }
+
+    return rc;
 }
 
 void pci_vtd_quirk(const struct pci_dev *pdev)
xen/drivers/passthrough/vtd/x86/vtd.c +14 -3
index c0d6aab..a19177c 100644
@@ -108,9 +108,10 @@ void hvm_dpci_isairq_eoi(struct domain *d, unsigned int isairq)
     spin_unlock(&d->event_lock);
 }
 
-void __hwdom_init vtd_set_hwdom_mapping(struct domain *d)
+int __hwdom_init vtd_set_hwdom_mapping(struct domain *d)
 {
     unsigned long i, j, tmp, top;
+    int rc = 0;
 
     BUG_ON(!is_hardware_domain(d));
 
@@ -140,11 +141,21 @@ void __hwdom_init vtd_set_hwdom_mapping(struct domain *d)
 
         tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);
         for ( j = 0; j < tmp; j++ )
-            iommu_map_page(d, pfn * tmp + j, pfn * tmp + j,
-                           IOMMUF_readable|IOMMUF_writable);
+        {
+            rc = iommu_map_page(d, pfn * tmp + j, pfn * tmp + j,
+                                IOMMUF_readable|IOMMUF_writable);
+            if ( rc )
+            {
+                while ( j-- > 0 )
+                    iommu_unmap_page(d, pfn * tmp + j);
+                break;
+            }
+        }
 
         if (!(i & (0xfffff >> (PAGE_SHIFT - PAGE_SHIFT_4K))))
             process_pending_softirqs();
     }
+
+    return rc;
 }
 
xen/drivers/passthrough/x86/iommu.c +5 -1
index 8cbb655..6674fb0 100644
@@ -104,7 +104,11 @@ int arch_iommu_populate_page_table(struct domain *d)
     this_cpu(iommu_dont_flush_iotlb) = 0;
 
     if ( !rc )
-        iommu_iotlb_flush_all(d);
+    {
+        rc = iommu_iotlb_flush_all(d);
+        if ( rc )
+            return rc;
+    }
     else if ( rc != -ERESTART )
         iommu_teardown(d);
 
xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +2 -2
index 9c51172..4691f9b 100644
@@ -119,8 +119,8 @@ extern unsigned long *shared_intremap_inuse;
 
 /* power management support */
 void amd_iommu_resume(void);
-void amd_iommu_suspend(void);
-void amd_iommu_crash_shutdown(void);
+int amd_iommu_suspend(void);
+int amd_iommu_crash_shutdown(void);
 
 /* guest iommu support */
 void amd_iommu_send_guest_cmd(struct amd_iommu *iommu, u32 cmd[]);
xen/include/asm-x86/iommu.h +1 -1
index 29203d7..cf2a269 100644
@@ -26,7 +26,7 @@ int iommu_setup_hpet_msi(struct msi_desc *);
 
 /* While VT-d specific, this must get declared in a generic header. */
 int adjust_vtd_irq_affinities(void);
-void iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte, int order, int present);
+int iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte, int order, int present);
 int iommu_supports_eim(void);
 int iommu_enable_x2apic_IR(void);
 void iommu_disable_x2apic_IR(void);
xen/include/xen/iommu.h +10 -10
index 8f3a20e..f5b6f7e 100644
@@ -55,7 +55,7 @@ int iommu_add_device(struct pci_dev *pdev);
 int iommu_enable_device(struct pci_dev *pdev);
 int iommu_remove_device(struct pci_dev *pdev);
 int iommu_domain_init(struct domain *d);
-void iommu_hwdom_init(struct domain *d);
+int iommu_hwdom_init(struct domain *d);
 void iommu_domain_destroy(struct domain *d);
 int deassign_device(struct domain *d, u16 seg, u8 bus, u8 devfn);
 
@@ -134,7 +134,7 @@ typedef int iommu_grdm_t(xen_pfn_t start, xen_ulong_t nr, u32 id, void *ctxt);
 
 struct iommu_ops {
     int (*init)(struct domain *d);
-    void (*hwdom_init)(struct domain *d);
+    int (*hwdom_init)(struct domain *d);
     int (*add_device)(u8 devfn, device_t *dev);
     int (*enable_device)(device_t *dev);
     int (*remove_device)(u8 devfn, device_t *dev);
@@ -157,19 +157,19 @@ 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);
-    void (*iotlb_flush)(struct domain *d, unsigned long gfn, unsigned int page_count);
-    void (*iotlb_flush_all)(struct domain *d);
+    int (*crash_shutdown)(void);
+    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);
 };
 
-void iommu_suspend(void);
+int iommu_suspend(void);
 void iommu_resume(void);
-void iommu_crash_shutdown(void);
+int iommu_crash_shutdown(void);
 int iommu_get_reserved_device_memory(iommu_grdm_t *, void *);
 
 void iommu_share_p2m_table(struct domain *d);
@@ -182,8 +182,8 @@ int iommu_do_pci_domctl(struct xen_domctl *, struct domain *d,
 int iommu_do_domctl(struct xen_domctl *, struct domain *d,
                     XEN_GUEST_HANDLE_PARAM(xen_domctl_t));
 
-void iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count);
-void iommu_iotlb_flush_all(struct domain *d);
+int iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count);
+int iommu_iotlb_flush_all(struct domain *d);
 
 /*
  * The purpose of the iommu_dont_flush_iotlb optional cpu flag is to
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:

This patch checks all kinds of error and all the way up the call trees of VT-d Device-TLB flush(IOMMU part).

Quoted 15 lines
---
 xen/drivers/passthrough/amd/iommu_init.c      |   4 +-
 xen/drivers/passthrough/amd/pci_amd_iommu.c   |   4 +-
 xen/drivers/passthrough/arm/smmu.c            |  13 +--
 xen/drivers/passthrough/iommu.c               |  37 +++++---
 xen/drivers/passthrough/vtd/extern.h          |   4 +-
 xen/drivers/passthrough/vtd/iommu.c           | 125 ++++++++++++++++----------
 xen/drivers/passthrough/vtd/qinval.c          |   2 +-
 xen/drivers/passthrough/vtd/quirks.c          |  26 +++---
 xen/drivers/passthrough/vtd/x86/vtd.c         |  17 +++-
 xen/drivers/passthrough/x86/iommu.c           |   6 +-
 xen/include/asm-x86/hvm/svm/amd-iommu-proto.h |   4 +-
 xen/include/asm-x86/iommu.h                   |   2 +-
 xen/include/xen/iommu.h                       |  20 ++---
 13 files changed, 166 insertions(+), 98 deletions(-)

Please be sure to Cc all maintainers of code you modify.

xen/drivers/passthrough/arm/smmu.c static int arm_smmu_iommu_domain_init(struct domain *d) · line 2745

Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c +2 -1
@@ -2737,8 +2739,9 @@ static int arm_smmu_iommu_domain_init(struct domain *d)
 	return 0;
 }
 
-static void __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d)
+static int __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d)
 {
+        return 0;
 }

Bad indentation.

xen/drivers/passthrough/iommu.c static void __hwdom_init check_hwdom_reqs(struct domain *d) · line 152

Quoted 11 lines
xen/drivers/passthrough/iommu.c +2 -1
@@ -146,14 +146,15 @@ static void __hwdom_init check_hwdom_reqs(struct domain *d)
     iommu_dom0_strict = 1;
 }
 
-void __hwdom_init iommu_hwdom_init(struct domain *d)
+int __hwdom_init iommu_hwdom_init(struct domain *d)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    int rc = 0;

Pointless initializer (more elsewhere).

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

Quoted 8 lines
xen/drivers/passthrough/iommu.c +3 -1
@@ -171,7 +172,10 @@ 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);
+            rc = hd->platform_ops->map_page(d, gfn, mfn, mapping);
+            if ( rc )
+                return rc;

So in this patch I can't find error checking getting introduced for the caller of this function. And if you were to add it - what would your intentions be? Panic? IOW I'm not sure bailing here is a good idea. Logging an error message (but only once in this loop) would be a possibility. (This pattern repeats further down.)

Quoted 7 lines
xen/drivers/passthrough/iommu.c +1 -1
@@ -369,12 +376,16 @@ void iommu_share_p2m_table(struct domain* d)
         ops->share_p2m(d);
 }
 
-void iommu_crash_shutdown(void)
+int iommu_crash_shutdown(void)
 {

xen/drivers/passthrough/iommu.c void iommu_share_p2m_table(struct domain* d) · line 389

Quoted 10 lines
xen/drivers/passthrough/iommu.c +5 -1
     const struct iommu_ops *ops = iommu_get_ops();
+
     if ( iommu_enabled )
-        ops->crash_shutdown();
+        return ops->crash_shutdown();
+
     iommu_enabled = iommu_intremap = 0;
+
+    return 0;
 }

Here again the question is - what is the error value going to be used for? We're trying to shut down a crashed system when coming here.

Quoted 17 lines
xen/drivers/passthrough/iommu.c +3 -8
@@ -584,37 +587,37 @@ static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
             continue;
 
         if ( page_count > 1 || gfn == -1 )
-        {
-            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
-        {
-            if ( iommu_flush_iotlb_psi(iommu, iommu_domid,
+            rc = iommu_flush_iotlb_psi(iommu, iommu_domid,
                         (paddr_t)gfn << PAGE_SHIFT_4K, 0,
-                        !dma_old_pte_present, flush_dev_iotlb) )

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

Quoted 10 lines
xen/drivers/passthrough/iommu.c +6 -2
-                iommu_flush_write_buffer(iommu);
-        }
+                        !dma_old_pte_present, flush_dev_iotlb);
+
+        if ( rc )
+            iommu_flush_write_buffer(iommu);
     }
+
+    return rc;
 }

rc may be positive here (and afaict that's the indication to do the flush, not one of failure). Quite likely this code didn't mean to flush iommu_flush_iotlb_{d,p}si() returning a negative value...

xen/drivers/passthrough/iommu.c static int intel_iommu_map_page( · line 1762

Quoted 8 lines
xen/drivers/passthrough/iommu.c +3 -1
@@ -1742,7 +1757,9 @@ 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);
+    {
+        return __intel_iommu_iotlb_flush(d, gfn, dma_pte_present(old), 1);
+    }

Pointless introduction of braces.

xen/drivers/passthrough/x86/iommu.c int arch_iommu_populate_page_table(struct domain *d) · line 111

Quoted 12 lines
xen/drivers/passthrough/x86/iommu.c +5 -1
@@ -104,7 +104,11 @@ int arch_iommu_populate_page_table(struct domain *d)
     this_cpu(iommu_dont_flush_iotlb) = 0;
 
     if ( !rc )
-        iommu_iotlb_flush_all(d);
+    {
+        rc = iommu_iotlb_flush_all(d);
+        if ( rc )
+            return rc;
+    }

But you leave all page tables set up?

xen/drivers/passthrough/x86/iommu.c int arch_iommu_populate_page_table(struct domain *d) · line 113

Quoted 2 lines
xen/drivers/passthrough/x86/iommu.c +0 -0
     else if ( rc != -ERESTART )
         iommu_teardown(d);

I think you should let things reach this tear down in that case.

Jan

author
#3 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

Quoted 7 lines · On February 11, 2016 at 1:01am, <[email protected]> wrote:
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:

This patch checks all kinds of error and all the way up the call trees of VT-d Device-TLB flush(IOMMU part).

Please be sure to Cc all maintainers of code you modify.

OK, also CCed Dario Faggioli.
Jan, could I re-send out the V5 and cc all maintainers of code I modify?

Quoted 5 lines

Review static int arm_smmu_iommu_domain_init(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -2737,8 +2739,9 @@ static int arm_smmu_iommu_domain_init(struct

domain *d)

Quoted 3 lines
xen/drivers/passthrough/amd/pci_amd_iommu.c +0 -0
 	return 0;
 }
 
Quoted 8 lines

xen/drivers/passthrough/arm/smmu.c static int arm_smmu_iommu_domain_init(struct domain *d) · line 2745

Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +2 -1
-static void __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d)
+static int __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d)
 {
+        return 0;
 }

Bad indentation.

I will modify it in next version. I tried to align with the coding style, as There was similar indentation nearby arm_smmu_iommu_hwdom_init() in that file.

Quoted 7 lines

xen/drivers/passthrough/iommu.c static void __hwdom_init

Quoted 3 lines
xen/drivers/passthrough/iommu.c +0 -0
@@ -146,14 +146,15 @@ static void __hwdom_init

check_hwdom_reqs(struct domain *d)

Quoted 3 lines
xen/drivers/passthrough/iommu.c +0 -0
     iommu_dom0_strict = 1;
 }
 
Quoted 8 lines

xen/drivers/passthrough/iommu.c static void __hwdom_init check_hwdom_reqs(struct domain *d) · line 152

Quoted 5 lines
xen/drivers/passthrough/iommu.c +2 -1
-void __hwdom_init iommu_hwdom_init(struct domain *d)
+int __hwdom_init iommu_hwdom_init(struct domain *d)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
+    int rc = 0;

Pointless initializer (more elsewhere).

I will modify them in next version.

Quoted 10 lines

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

Quoted 1 line
xen/drivers/passthrough/iommu.c +0 -0
@@ -171,7 +172,10 @@ void __hwdom_init iommu_hwdom_init(struct

domain *d)

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

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

So in this patch I can't find error checking getting introduced for the caller of this function. And if you were to add it - what would your intentions be? Panic? IOW I'm not sure bailing here is a good idea. Logging an error message (but only once in this loop) would be a possibility. (This pattern repeats further down.)

Could I log an error message and break in this loop?

Quoted 4 lines
Quoted 4 lines
xen/drivers/passthrough/iommu.c +0 -0
@@ -369,12 +376,16 @@ void iommu_share_p2m_table(struct domain* d)
         ops->share_p2m(d);
 }
 
Quoted 17 lines

xen/drivers/passthrough/iommu.c void iommu_share_p2m_table(struct domain* d) · line 389

Quoted 13 lines
xen/drivers/passthrough/iommu.c +6 -2
-void iommu_crash_shutdown(void)
+int iommu_crash_shutdown(void)
 {
     const struct iommu_ops *ops = iommu_get_ops();
+
     if ( iommu_enabled )
-        ops->crash_shutdown();
+        return ops->crash_shutdown();
+
     iommu_enabled = iommu_intremap = 0;
+
+    return 0;
 }

Here again the question is - what is the error value going to be used for? We're trying to shut down a crashed system when coming here.

I tried to clean up in error handling path chained up. It logs an error message, When it calls iommu_crash_shutdown() and returns a non-zero value [in patch 2/7].

Quoted 24 lines

xen/drivers/passthrough/iommu.c static void __intel_iommu_iotlb_flush(struct

Quoted 1 line
xen/drivers/passthrough/iommu.c +0 -0
@@ -584,37 +587,37 @@ static void __intel_iommu_iotlb_flush(struct

domain *d, unsigned long gfn,

Quoted 22 lines
xen/drivers/passthrough/iommu.c +7 -10
             continue;
 
         if ( page_count > 1 || gfn == -1 )
-        {
-            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
-        {
-            if ( iommu_flush_iotlb_psi(iommu, iommu_domid,
+            rc = iommu_flush_iotlb_psi(iommu, iommu_domid,
                         (paddr_t)gfn << PAGE_SHIFT_4K, 0,
-                        !dma_old_pte_present, flush_dev_iotlb) )
-                iommu_flush_write_buffer(iommu);
-        }
+                        !dma_old_pte_present, flush_dev_iotlb);
+
+        if ( rc )
+            iommu_flush_write_buffer(iommu);
Quoted 10 lines

xen/drivers/passthrough/iommu.c static void __intel_iommu_iotlb_flush(struct · line 602

Quoted 4 lines
xen/drivers/passthrough/iommu.c +2 -0
     }
+
+    return rc;
 }

rc may be positive here (and afaict that's the indication to do the flush, not one of failure). Quite likely this code didn't mean to flush iommu_flush_iotlb_{d,p}si() returning a negative value...

IIUC, you refer to the follow:
flush_iotlb_qi(
{
...

          if ( !cap_caching_mode(iommu->cap) )
            return 1;

...
}

As Kevin mentioned, originally 0/1 is used to indicate whether caller needs to flush cache.
But I try to return ZERO in [PATCH v5 1/7]. Because:
1) if It returns _1_, device passthrough doesn't work when I tried to clean up in error handling path chained up.
2) as VT-d spec said, Caching Mode is 0: invalidations are not required for modifications to individual not present or invalid entries.

That is tricky for this point. Correct me if I am wrong.

Quoted 12 lines

xen/drivers/passthrough/iommu.c static int intel_iommu_map_page( · line 1761

Quoted 7 lines
xen/drivers/passthrough/iommu.c +2 -1
@@ -1742,7 +1757,9 @@ 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);
+    {
+        return __intel_iommu_iotlb_flush(d, gfn, dma_pte_present(old),

1);

xen/drivers/passthrough/iommu.c static int intel_iommu_map_page( · line 1762

Quoted 1 line
xen/drivers/passthrough/iommu.c +1 -0
+    }

Pointless introduction of braces.

I will modify it in next version.

Quoted 14 lines

xen/drivers/passthrough/x86/iommu.c int arch_iommu_populate_page_table(struct

Quoted 3 lines
xen/drivers/passthrough/x86/iommu.c +0 -0
@@ -104,7 +104,11 @@ int arch_iommu_populate_page_table(struct

domain *d)

xen/drivers/passthrough/x86/iommu.c int arch_iommu_populate_page_table(struct domain *d) · line 111

Quoted 9 lines
xen/drivers/passthrough/x86/iommu.c +5 -1
     this_cpu(iommu_dont_flush_iotlb) = 0;
 
     if ( !rc )
-        iommu_iotlb_flush_all(d);
+    {
+        rc = iommu_iotlb_flush_all(d);
+        if ( rc )
+            return rc;
+    }
Quoted 7 lines

But you leave all page tables set up?

xen/drivers/passthrough/x86/iommu.c int arch_iommu_populate_page_table(struct domain *d) · line 113

Quoted 2 lines
xen/drivers/passthrough/x86/iommu.c +0 -0
     else if ( rc != -ERESTART )
         iommu_teardown(d);

I think you should let things reach this tear down in that case.

Agreed.

Jan, thanks for your comments.
BTW, just for a check, did you only review patch v5 1/7 ? Hope I didn't miss your other comments.

Quan

#4 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

Quoted 10 lines
Quoted 8 lines
Quoted 1 line · On 16.02.16 at 11:50, <[email protected]> wrote:
Quoted 3 lines · On February 11, 2016 at 1:01am, <[email protected]> wrote:
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:

This patch checks all kinds of error and all the way up the call trees of VT-d Device-TLB flush(IOMMU part).

Please be sure to Cc all maintainers of code you modify.

OK, also CCed Dario Faggioli.
Jan, could I re-send out the V5 and cc all maintainers of code I modify?

I'd say rather make sure you Cc the right people on v6, to avoid spamming everyone's mailboxes.

Quoted 14 lines
Quoted 5 lines

Review static int arm_smmu_iommu_domain_init(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -2737,8 +2739,9 @@ static int arm_smmu_iommu_domain_init(struct

domain *d)

Quoted 3 lines
xen/drivers/passthrough/amd/pci_amd_iommu.c +0 -0
 	return 0;
 }
 
Quoted 8 lines

xen/drivers/passthrough/arm/smmu.c static int arm_smmu_iommu_domain_init(struct domain *d) · line 2745

Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +2 -1
-static void __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d)
+static int __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d)
 {
+        return 0;
 }

Bad indentation.

Quoted 4 lines

I will modify it in next version. I tried to align with the coding style, as

There was similar indentation nearby arm_smmu_iommu_hwdom_init() in that file.

Then I'm afraid you didn't check enough of the properties of the
file: It appears to use Linux style, and hence indentation is by tabs instead of spaces.

Quoted 13 lines
Quoted 11 lines

Review void __hwdom_init iommu_hwdom_init(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -171,7 +172,10 @@ void __hwdom_init iommu_hwdom_init(struct

domain *d)

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

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

So in this patch I can't find error checking getting introduced for the

caller of

Quoted 1 line

this function. And if you were to add it - what would your intentions be?

Quoted 8 lines

Panic?

Quoted 1 line

IOW I'm not sure bailing here is a good idea. Logging an error message (but

only

Quoted 1 line

once in this loop) would be a possibility. (This pattern repeats further

down.)

Quoted 1 line

Could I log an error message and break in this loop?

Logging an error message - yes. Breaking the loop - no; this should continue to be a best effort attempt at getting things set up for Dom0.

Quoted 21 lines
Quoted 4 lines
Quoted 4 lines
xen/drivers/passthrough/iommu.c +0 -0
@@ -369,12 +376,16 @@ void iommu_share_p2m_table(struct domain* d)
         ops->share_p2m(d);
 }
 
Quoted 17 lines

xen/drivers/passthrough/iommu.c void iommu_share_p2m_table(struct domain* d) · line 389

Quoted 13 lines
xen/drivers/passthrough/iommu.c +6 -2
-void iommu_crash_shutdown(void)
+int iommu_crash_shutdown(void)
 {
     const struct iommu_ops *ops = iommu_get_ops();
+
     if ( iommu_enabled )
-        ops->crash_shutdown();
+        return ops->crash_shutdown();
+
     iommu_enabled = iommu_intremap = 0;
+
+    return 0;
 }

Here again the question is - what is the error value going to be used for? We're trying to shut down a crashed system when coming here.

Quoted 4 lines

I tried to clean up in error handling path chained up. It logs an error
message,
When it calls iommu_crash_shutdown() and returns a non-zero value [in patch
2/7].

That sounds okay than (I didn't get around to look at patches 2-7 yet), but is somewhat contrary to me request of adding __must_check as far as possible, which - if done here - would break the build without also adjusting the caller(s).

Quoted 54 lines
Quoted 22 lines

Review static void __intel_iommu_iotlb_flush(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -584,37 +587,37 @@ static void __intel_iommu_iotlb_flush(struct

domain *d, unsigned long gfn,

Quoted 20 lines
xen/drivers/passthrough/vtd/iommu.c +5 -10
             continue;
 
         if ( page_count > 1 || gfn == -1 )
-        {
-            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
-        {
-            if ( iommu_flush_iotlb_psi(iommu, iommu_domid,
+            rc = iommu_flush_iotlb_psi(iommu, iommu_domid,
                         (paddr_t)gfn << PAGE_SHIFT_4K, 0,
-                        !dma_old_pte_present, flush_dev_iotlb) )
-                iommu_flush_write_buffer(iommu);
-        }
+                        !dma_old_pte_present, flush_dev_iotlb);
+
Quoted 8 lines

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

Quoted 6 lines
xen/drivers/passthrough/vtd/iommu.c +4 -0
+        if ( rc )
+            iommu_flush_write_buffer(iommu);
     }
+
+    return rc;
 }

rc may be positive here (and afaict that's the indication to do the flush,

not one

Quoted 4 lines

of failure). Quite likely this code didn't mean to flush iommu_flush_iotlb_{d,p}si() returning a negative value...

IIUC, you refer to the follow:
flush_iotlb_qi(
{
...

          if ( !cap_caching_mode(iommu->cap) )
            return 1;

...
}

As Kevin mentioned, originally 0/1 is used to indicate whether caller needs to flush cache.
But I try to return ZERO in [PATCH v5 1/7]. Because:
1) if It returns _1_, device passthrough doesn't work when I tried to clean up in error handling path chained up.
2) as VT-d spec said, Caching Mode is 0: invalidations are not required for modifications to individual not present
or invalid entries.

Quoted 1 line

That is tricky for this point. Correct me if I am wrong.

I'm not sure I see the trickiness: All you need is
- call iommu_flush_write_buffer() only when rc > 0 (if I remember the polarity right, else it might be rc == 0)
- return zero from this function when rc is positive.

Jan

author
#5 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

Quoted 27 lines · On February 16, 2016 7:06pm, <[email protected]> wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 1 line · On 16.02.16 at 11:50, <[email protected]> wrote:

Review void iommu_share_p2m_table(struct domain*

Quoted 3 lines · On February 11, 2016 at 1:01am, <[email protected]> wrote:
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -369,12 +376,16 @@ void iommu_share_p2m_table(struct domain*

d)

Quoted 20 lines
Quoted 20 lines
Quoted 6 lines
xen/drivers/passthrough/iommu.c +1 -1
         ops->share_p2m(d);
 }
 
-void iommu_crash_shutdown(void)
+int iommu_crash_shutdown(void)
 {

xen/drivers/passthrough/iommu.c void iommu_share_p2m_table(struct domain* d) · line 389

Quoted 10 lines
xen/drivers/passthrough/iommu.c +5 -1
     const struct iommu_ops *ops = iommu_get_ops();
+
     if ( iommu_enabled )
-        ops->crash_shutdown();
+        return ops->crash_shutdown();
+
     iommu_enabled = iommu_intremap = 0;
+
+    return 0;
 }

Here again the question is - what is the error value going to be used for? We're trying to shut down a crashed system when coming here.

Quoted 8 lines
Quoted 3 lines

I tried to clean up in error handling path chained up. It logs an
error message, When it calls iommu_crash_shutdown() and returns a non-zero value [in patch 2/7].

That sounds okay than (I didn't get around to look at patches 2-7 yet), but is somewhat contrary to me request of adding __must_check as far as possible, which - if done here - would break the build without also adjusting the caller(s).

If they are in the same patch set, I think it is acceptable.
BTW, with patch 1/7, I can build Xen successfully( make xen ).
To align this rule, I'd better merge patch1/7 and patch 2/7 into a large patch.

Quan

#6 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

Quoted 33 lines
Quoted 28 lines
Quoted 1 line · On 17.02.16 at 13:49, <[email protected]> wrote:
Quoted 5 lines · On February 16, 2016 7:06pm, <[email protected]> wrote:
Quoted 5 lines
Quoted 1 line · On 16.02.16 at 11:50, <[email protected]> wrote:

Review void iommu_share_p2m_table(struct domain*

Quoted 3 lines · On February 11, 2016 at 1:01am, <[email protected]> wrote:
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -369,12 +376,16 @@ void iommu_share_p2m_table(struct domain*

d)

Quoted 20 lines
Quoted 20 lines
Quoted 6 lines
xen/drivers/passthrough/iommu.c +1 -1
         ops->share_p2m(d);
 }
 
-void iommu_crash_shutdown(void)
+int iommu_crash_shutdown(void)
 {

xen/drivers/passthrough/iommu.c void iommu_share_p2m_table(struct domain* d) · line 389

Quoted 10 lines
xen/drivers/passthrough/iommu.c +5 -1
     const struct iommu_ops *ops = iommu_get_ops();
+
     if ( iommu_enabled )
-        ops->crash_shutdown();
+        return ops->crash_shutdown();
+
     iommu_enabled = iommu_intremap = 0;
+
+    return 0;
 }

Here again the question is - what is the error value going to be used for? We're trying to shut down a crashed system when coming here.

Quoted 5 lines
Quoted 3 lines

I tried to clean up in error handling path chained up. It logs an
error message, When it calls iommu_crash_shutdown() and returns a non-zero value [in patch 2/7].

That sounds okay than (I didn't get around to look at patches 2-7 yet), but

Quoted 8 lines

is

Quoted 2 lines

somewhat contrary to me request of adding __must_check as far as possible, which - if done here - would break the build without also adjusting the

caller(s).

Quoted 1 line

If they are in the same patch set, I think it is acceptable.

If unavoidable, yes. But please remember that patch series don't necessarily get committed in one go.

Quoted 3 lines

BTW, with patch 1/7, I can build Xen successfully( make xen ). To align this rule, I'd better merge patch1/7 and patch 2/7 into a large patch.

Not having looked at patch 2 yet (I'm about to), I can't tell whether this makes sense. I'd rather not see large patches become even larger though - please make a reasonable attempt at splitting things (in the case here for example by adjusting top level functions first, working your way down to leaf ones, thus guaranteeing that newly added __must_check annotations will be properly honored at each patch boundary).

Jan

author
#7 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

Quoted 49 lines · On February 17, 2016 9:05pm, <[email protected]> wrote:
Quoted 7 lines
Quoted 7 lines
Quoted 1 line · On 17.02.16 at 13:49, <[email protected]> wrote:
Quoted 5 lines · On February 16, 2016 7:06pm, <[email protected]> wrote:
Quoted 5 lines
Quoted 1 line · On 16.02.16 at 11:50, <[email protected]> wrote:

Review void iommu_share_p2m_table(struct

Quoted 3 lines · On February 11, 2016 at 1:01am, <[email protected]> wrote:
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -369,12 +376,16 @@ void iommu_share_p2m_table(struct

domain*

Quoted 28 lines
Quoted 21 lines

d)

Quoted 20 lines
Quoted 20 lines
Quoted 6 lines
xen/drivers/passthrough/iommu.c +1 -1
         ops->share_p2m(d);
 }
 
-void iommu_crash_shutdown(void)
+int iommu_crash_shutdown(void)
 {

xen/drivers/passthrough/iommu.c void iommu_share_p2m_table(struct domain* d) · line 389

Quoted 10 lines
xen/drivers/passthrough/iommu.c +5 -1
     const struct iommu_ops *ops = iommu_get_ops();
+
     if ( iommu_enabled )
-        ops->crash_shutdown();
+        return ops->crash_shutdown();
+
     iommu_enabled = iommu_intremap = 0;
+
+    return 0;
 }

Here again the question is - what is the error value going to be used for? We're trying to shut down a crashed system when coming here.

Quoted 6 lines
Quoted 3 lines

I tried to clean up in error handling path chained up. It logs an
error message, When it calls iommu_crash_shutdown() and returns a non-zero value [in patch 2/7].

That sounds okay than (I didn't get around to look at patches 2-7 yet), but

is

Quoted 8 lines
Quoted 3 lines

somewhat contrary to me request of adding __must_check as far as possible, which - if done here - would break the build without also adjusting the

caller(s).

Quoted 1 line

If they are in the same patch set, I think it is acceptable.

If unavoidable, yes. But please remember that patch series don't necessarily get committed in one go.

Quoted 6 lines
Quoted 3 lines

BTW, with patch 1/7, I can build Xen successfully( make xen ). To align this rule, I'd better merge patch1/7 and patch 2/7 into a large patch.

Not having looked at patch 2 yet
(I'm about to),

Good news. :):)
I think there are maybe some minor issues for this patch set ( _my_estimate_), and I will address these issues immediately.

Quoted 7 lines

I can't tell whether this makes
sense. I'd rather not see large patches become even larger though - please make a reasonable attempt at splitting things (in the case here for example by adjusting top level functions first, working your way down to leaf ones, thus guaranteeing that newly added __must_check annotations will be properly honored at each patch boundary).

Okay, I will try to do it in v6. Thanks.

Quan

#8 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

Quoted 7 lines

From: Xu, Quan
Sent: Wednesday, February 17, 2016 9:38 PM

Quoted 5 lines
Quoted 4 lines

BTW, with patch 1/7, I can build Xen successfully( make xen ). To align this rule, I'd better merge patch1/7 and patch 2/7 into a large patch.

Quoted 7 lines
Quoted 2 lines

Not having looked at patch 2 yet
(I'm about to),

Good news. :):)
I think there are maybe some minor issues for this patch set ( _my_estimate_), and I will address these issues immediately.

Hi, Quan, are you expecting people to continue looking at your v5, or better to wait for v7? :-)

Thanks
Kevin

author
#9 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

Quoted 11 lines · On February 18, 2016 2:16pm, <Tian, Kevin> wrote:
Quoted 10 lines

From: Xu, Quan
Sent: Wednesday, February 17, 2016 9:38 PM

Quoted 7 lines
Quoted 4 lines

BTW, with patch 1/7, I can build Xen successfully( make xen ). To align this rule, I'd better merge patch1/7 and patch 2/7 into a large patch.

Not having looked at patch 2 yet
(I'm about to),

Quoted 8 lines
Quoted 4 lines

Good news. :):)
I think there are maybe some minor issues for this patch set ( _my_estimate_), and I will address these issues immediately.

Hi, Quan, are you expecting people to continue looking at your v5, or better to wait for v7? :-)

V7?
I think the other people would better wait for v6. I plan to send out v6 in next week. Jan gave some valuable comments for v5. I will fix it ASAP.
I apologize to everyone who has to go through v5 patch set. I missed some v4 comments and didn't fully test the v5 patch set, as I tried my best to send out v5 on the last working day before Chinese Spring Festival and it was a long periods for v4 discussion.

Quan

#10 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

Quoted 19 lines

From: Xu, Quan
Sent: Thursday, February 18, 2016 2:34 PM

Quoted 16 lines · On February 18, 2016 2:16pm, <Tian, Kevin> wrote:
Quoted 14 lines

From: Xu, Quan
Sent: Wednesday, February 17, 2016 9:38 PM

Quoted 7 lines
Quoted 4 lines

BTW, with patch 1/7, I can build Xen successfully( make xen ). To align this rule, I'd better merge patch1/7 and patch 2/7 into a large patch.

Not having looked at patch 2 yet
(I'm about to),

Good news. :):)
I think there are maybe some minor issues for this patch set ( _my_estimate_), and I will address these issues immediately.

Quoted 5 lines
Quoted 3 lines

Hi, Quan, are you expecting people to continue looking at your v5, or better to wait for v7? :-)

V7?

sorry. I meant v6.

Quoted 7 lines

I think the other people would better wait for v6. I plan to send out v6 in next week. Jan gave some valuable comments for v5. I will fix it ASAP.
I apologize to everyone who has to go through v5 patch set. I missed some v4 comments and didn't fully test the v5 patch set, as I tried my best to send out v5 on the last
working day before Chinese Spring Festival and it was a long periods for v4 discussion.

Thanks for your work.
Kevin

author
#11 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

Quoted 7 lines · On February 18, 2016 2:37pm, <Tian, Kevin> wrote:
Quoted 2 lines

From: Xu, Quan
Sent: Thursday, February 18, 2016 2:34 PM

Thanks for your work.
Kevin

I appreciate your help!:)
Quan

author
#12 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

In reply to Jan Beulich
Quoted 14 lines · Jan Beulich

Review void __hwdom_init iommu_hwdom_init(struct

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:

This patch checks all kinds of error and all the way up the call trees of VT-d Device-TLB flush(IOMMU part).

(quoted diff) +0 -0
@@ -171,7 +172,10 @@ void __hwdom_init iommu_hwdom_init(struct

domain *d)

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

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

So in this patch I can't find error checking getting introduced for the caller of this function. And if you were to add it - what would your intentions be? Panic? IOW I'm not sure bailing here is a good idea. Logging an error message (but only once in this loop) would be a possibility. (This pattern repeats further down.)

While I read the code/email again and again,
I think I'd better _not_ return error value. Then the below modifications are pointless:
1.
- void (*hwdom_init)(struct domain *d);
+ int (*hwdom_init)(struct domain *d);

2.
-void iommu_hwdom_init(struct domain *d);
+int iommu_hwdom_init(struct domain *d);

Quoted 4 lines
Quoted 4 lines
xen/drivers/passthrough/iommu.c +0 -0
@@ -369,12 +376,16 @@ void iommu_share_p2m_table(struct domain* d)
         ops->share_p2m(d);
 }
 
Quoted 17 lines

xen/drivers/passthrough/iommu.c void iommu_share_p2m_table(struct domain* d) · line 389

Quoted 13 lines
xen/drivers/passthrough/iommu.c +6 -2
-void iommu_crash_shutdown(void)
+int iommu_crash_shutdown(void)
 {
     const struct iommu_ops *ops = iommu_get_ops();
+
     if ( iommu_enabled )
-        ops->crash_shutdown();
+        return ops->crash_shutdown();
+
     iommu_enabled = iommu_intremap = 0;
+
+    return 0;
 }

Here again the question is - what is the error value going to be used for? We're trying to shut down a crashed system when coming here.

It is similar as the above case.
I think I'd better _not_ return error value. Then the below modifications are pointless:
1.
- void (*crash_shutdown)(void);
+ int (*crash_shutdown)(void);

2.
-void amd_iommu_crash_shutdown(void);
+int amd_iommu_crash_shutdown(void);

3.
-void iommu_crash_shutdown(void);
+int iommu_crash_shutdown(void);

Right?

Quan

#13 lore raw

Re: [PATCH v5 1/7] VT-d: Check VT-d Device-TLB flush error(IOMMU part).

Quoted 28 lines
Quoted 15 lines
Quoted 1 line · On 23.02.16 at 12:43, <[email protected]> wrote:

Review void __hwdom_init iommu_hwdom_init(struct

Quoted 4 lines · Jan Beulich
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:

This patch checks all kinds of error and all the way up the call trees of VT-d Device-TLB flush(IOMMU part).

(quoted diff) +0 -0
@@ -171,7 +172,10 @@ void __hwdom_init iommu_hwdom_init(struct

domain *d)

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

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

So in this patch I can't find error checking getting introduced for the caller of this function. And if you were to add it - what would your intentions be? Panic? IOW I'm not sure bailing here is a good idea. Logging an error message (but only once in this loop) would be a possibility. (This pattern repeats further down.)

While I read the code/email again and again,
I think I'd better _not_ return error value. Then the below modifications are pointless:
1.

xen/include/xen/iommu.h +1 -1
-    void (*hwdom_init)(struct domain *d);
+    int (*hwdom_init)(struct domain *d);

2.

xen/include/xen/iommu.h int iommu_add_device(struct pci_dev *pdev); · line 58

Quoted 2 lines
xen/include/xen/iommu.h +1 -1
-void iommu_hwdom_init(struct domain *d);
+int iommu_hwdom_init(struct domain *d);

Agreed. Just log some message for failure in the case above, but make sure that is (a) useful for debugging and (b) not one message per page.

Quoted 34 lines
Quoted 4 lines
Quoted 4 lines
xen/drivers/passthrough/iommu.c +0 -0
@@ -369,12 +376,16 @@ void iommu_share_p2m_table(struct domain* d)
         ops->share_p2m(d);
 }
 
Quoted 17 lines

xen/drivers/passthrough/iommu.c void iommu_share_p2m_table(struct domain* d) · line 389

Quoted 13 lines
xen/drivers/passthrough/iommu.c +6 -2
-void iommu_crash_shutdown(void)
+int iommu_crash_shutdown(void)
 {
     const struct iommu_ops *ops = iommu_get_ops();
+
     if ( iommu_enabled )
-        ops->crash_shutdown();
+        return ops->crash_shutdown();
+
     iommu_enabled = iommu_intremap = 0;
+
+    return 0;
 }

Here again the question is - what is the error value going to be used for? We're trying to shut down a crashed system when coming here.

It is similar as the above case.
I think I'd better _not_ return error value. Then the below modifications are pointless:
1.

xen/include/xen/iommu.h +1 -1
-    void (*crash_shutdown)(void);
+    int (*crash_shutdown)(void);

2.

xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +1 -1
-void amd_iommu_crash_shutdown(void);
+int amd_iommu_crash_shutdown(void);

3.

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

Quoted 2 lines
xen/include/xen/iommu.h +1 -1
-void iommu_crash_shutdown(void);
+int iommu_crash_shutdown(void);

Indeed, same as above.

Jan

author
#14 lore raw

PATCH v5 2/7 VT-d: Check VT-d Device-TLB flush error(MMU part).

In reply to Quan Xu

This patch checks all kinds of error and all the way up the call trees of VT-d Device-TLB flush(MMU part).

---
 xen/arch/x86/acpi/power.c   |  6 +++++-
 xen/arch/x86/crash.c        |  3 ++-
 xen/arch/x86/domain_build.c |  5 ++++-
 xen/arch/x86/mm.c           | 10 +++++++---
 xen/arch/x86/mm/p2m-ept.c   | 11 +++++++++--
 xen/arch/x86/mm/p2m-pt.c    | 11 +++++++++--
 xen/common/domain.c         |  2 +-
 xen/common/grant_table.c    |  5 +++--
 xen/common/memory.c         |  5 +++--
 9 files changed, 43 insertions(+), 15 deletions(-)
xen/arch/x86/acpi/power.c +5 -1
index f41f0de..ff397c3 100644
@@ -45,6 +45,8 @@ void do_suspend_lowlevel(void);
 
 static int device_power_down(void)
 {
+    int rc;
+
     console_suspend();
 
     time_suspend();
@@ -53,7 +55,9 @@ static int device_power_down(void)
 
     ioapic_suspend();
 
-    iommu_suspend();
+    rc = iommu_suspend();
+    if ( rc )
+        return rc;
 
     lapic_suspend();
 
xen/arch/x86/crash.c +2 -1
index 888a214..59e1af6 100644
@@ -170,7 +170,8 @@ static void nmi_shootdown_cpus(void)
 
     /* Crash shutdown any IOMMU functionality as the crashdump kernel is not
      * happy when booting if interrupt/dma remapping is still enabled */
-    iommu_crash_shutdown();
+    if ( iommu_crash_shutdown() )
+        printk("Failed to shut down IOMMU.\n");
 
     __stop_this_cpu();
 
xen/arch/x86/domain_build.c +4 -1
index bca6fe7..d10321a 100644
@@ -1627,7 +1627,10 @@ int __init construct_dom0(
     }
 
     if ( d->domain_id == hardware_domid )
-        iommu_hwdom_init(d);
+    {
+        rc = iommu_hwdom_init(d);
+        BUG_ON(rc != 0);
+    }
 
     return 0;
 
xen/arch/x86/mm.c +7 -3
index 202ff76..1e50b94 100644
@@ -2445,9 +2445,13 @@ static int __get_page_type(struct page_info *page, unsigned long type,
             if ( (x & PGT_type_mask) == PGT_writable_page )
                 iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
             else if ( type == PGT_writable_page )
-                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
-                               page_to_mfn(page),
-                               IOMMUF_readable|IOMMUF_writable);
+            {
+                rc = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                    page_to_mfn(page),
+                                    IOMMUF_readable|IOMMUF_writable);
+                if ( rc )
+                    iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+            }
         }
     }
 
xen/arch/x86/mm/p2m-ept.c +9 -2
index 9860c6c..9e1f5c6 100644
@@ -829,12 +829,19 @@ out:
          need_modify_vtd_table )
     {
         if ( iommu_hap_pt_share )
-            iommu_pte_flush(d, gfn, &ept_entry->epte, order, vtd_pte_present);
+            rc = iommu_pte_flush(d, gfn, &ept_entry->epte, order, vtd_pte_present);
         else
         {
             if ( iommu_flags )
                 for ( i = 0; i < (1 << order); i++ )
-                    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 ( rc )
+                    {
+                        while ( i-- > 0 )
+                            iommu_unmap_page(d, gfn + i);
+                    }
+                }
             else
                 for ( i = 0; i < (1 << order); i++ )
                     iommu_unmap_page(d, gfn + i);
xen/arch/x86/mm/p2m-pt.c +9 -2
index 709920a..942a11c 100644
@@ -675,8 +675,15 @@ 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);
+            {
+                rc = iommu_map_page(p2m->domain, gfn + i, mfn_x(mfn) + i,
+                                    iommu_pte_flags);
+                if ( rc )
+                {
+                    while ( i-- > 0 )
+                        iommu_unmap_page(p2m->domain, gfn + i);
+                }
+            }
         else
             for ( i = 0; i < (1UL << page_order); i++ )
                 iommu_unmap_page(p2m->domain, gfn + i);
xen/common/domain.c +1 -1
index 1b9fcfc..577eb3d 100644
@@ -228,7 +228,7 @@ static int late_hwdom_init(struct domain *d)
 
     rcu_unlock_domain(dom0);
 
-    iommu_hwdom_init(d);
+    rv = iommu_hwdom_init(d);
 
     return rv;
 #else
xen/common/grant_table.c +3 -2
index 2b449d5..1b9bd05 100644
@@ -919,8 +919,9 @@ __gnttab_map_grant_ref(
             {
                 nr_gets++;
                 (void)get_page(pg, rd);
-                if ( !(op->flags & GNTMAP_readonly) )
-                    get_page_type(pg, PGT_writable_page);
+                if ( !(op->flags & GNTMAP_readonly) &&
+                     get_page_type(pg, PGT_writable_page) )
+                        goto could_not_pin;
             }
         }
     }
xen/common/memory.c +3 -2
index b541f4a1..c228d9f 100644
@@ -631,8 +631,9 @@ static int xenmem_add_to_physmap(struct domain *d,
     if ( need_iommu(d) )
     {
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        iommu_iotlb_flush(d, xatp->idx - done, done);
-        iommu_iotlb_flush(d, xatp->gpfn - done, done);
+        rc = iommu_iotlb_flush(d, xatp->idx - done, done);
+        if ( !rc )
+            rc = iommu_iotlb_flush(d, xatp->gpfn - done, done);
     }
 #endif
 
Signature · 1 line
1.9.1
#15 lore raw

Re: [PATCH v5 2/7] VT-d: Check VT-d Device-TLB flush error(MMU part).

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:
xen/arch/x86/acpi/power.c +2 -0
@@ -45,6 +45,8 @@ void do_suspend_lowlevel(void);
 
 static int device_power_down(void)
 {
+    int rc;
+
     console_suspend();
 
     time_suspend();

xen/arch/x86/acpi/power.c static int device_power_down(void) · line 60

Quoted 7 lines
xen/arch/x86/acpi/power.c +3 -1
@@ -53,7 +55,9 @@ static int device_power_down(void)
 
     ioapic_suspend();
 
-    iommu_suspend();
+    rc = iommu_suspend();
+    if ( rc )
+        return rc;

I'm not going to look at the rest of this patch, seeing that the v4 comment[1] regarding the issue here was left un-addressed.

Jan

[1] http://lists.xenproject.org/archives/html/xen-devel/2016-01/msg01555.html

author
#16 lore raw

PATCH v5 3/7 VT-d: Reduce spin timeout to 1ms, which can be boot-time changed.

In reply to Quan Xu
---
 docs/misc/xen-command-line.markdown  |  7 +++++++
 xen/drivers/passthrough/vtd/qinval.c | 11 +++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
docs/misc/xen-command-line.markdown +7 -0
index a565c1b..6ed5cd8 100644
@@ -968,6 +968,13 @@ Use this to work around firmware issues providing correct RMRR entries. Rather
 than only mapping RAM pages for IOMMU accesses for Dom0, with this option all
 pages not marked as unusable in the E820 table will get a mapping established.
 
+### vtd\_qi\_timeout (VT-d)
+> `= <integer>`
+
+> Default: `1`
+
+>> Specify the timeout of the VT-d Queued Invalidation in ms.
+
 ### irq\_ratelimit
 > `= <integer>`
 
xen/drivers/passthrough/vtd/qinval.c +9 -2
index 946e812..f9e752b 100644
@@ -28,6 +28,11 @@
 #include "vtd.h"
 #include "extern.h"
 
+static unsigned int __read_mostly vtd_qi_timeout = 1;
+integer_param("vtd_qi_timeout", vtd_qi_timeout);
+
+#define IOMMU_QI_TIMEOUT (vtd_qi_timeout * MILLISECS(1))
+
 static void print_qi_regs(struct iommu *iommu)
 {
     u64 val;
@@ -167,10 +172,12 @@ static int queue_invalidate_wait(struct iommu *iommu,
         start_time = NOW();
         while ( poll_slot != QINVAL_STAT_DONE )
         {
-            if ( NOW() > (start_time + DMAR_OPERATION_TIMEOUT) )
+            if ( NOW() > (start_time + IOMMU_QI_TIMEOUT) )
             {
                 print_qi_regs(iommu);
-                panic("queue invalidate wait descriptor was not executed");
+                dprintk(XENLOG_WARNING VTDPREFIX,
+                        "Queue invalidate wait descriptor was timeout.\n");
+                return -ETIMEDOUT;
             }
             cpu_relax();
         }
Signature · 1 line
1.9.1
#17 lore raw

Re: [PATCH v5 3/7] VT-d: Reduce spin timeout to 1ms, which can be boot-time changed.

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:
docs/misc/xen-command-line.markdown +0 -0
@@ -968,6 +968,13 @@ Use this to work around firmware issues providing correct RMRR entries. Rather
 than only mapping RAM pages for IOMMU accesses for Dom0, with this option all
 pages not marked as unusable in the E820 table will get a mapping 

established.

docs/misc/xen-command-line.markdown Use this to work around firmware issues providing correct RMRR entries. Rather · line 979

Quoted 9 lines
docs/misc/xen-command-line.markdown +7 -0
+### vtd\_qi\_timeout (VT-d)
+> `= <integer>`
+
+> Default: `1`
+
+>> Specify the timeout of the VT-d Queued Invalidation in ms.
+
 ### irq\_ratelimit
 > `= <integer>`

Just like for patch 2: I'm sure it was mentioned to you before that this file has its entries (at least mostly) alphabetically sorted.

Quoted 5 lines
docs/misc/xen-command-line.markdown +0 -1
@@ -167,10 +172,12 @@ static int queue_invalidate_wait(struct iommu *iommu,
         start_time = NOW();
         while ( poll_slot != QINVAL_STAT_DONE )
         {
-            if ( NOW() > (start_time + DMAR_OPERATION_TIMEOUT) )

docs/misc/xen-command-line.markdown static int queue_invalidate_wait(struct iommu *iommu, · line 183

Quoted 10 lines
docs/misc/xen-command-line.markdown +4 -1
+            if ( NOW() > (start_time + IOMMU_QI_TIMEOUT) )
             {
                 print_qi_regs(iommu);
-                panic("queue invalidate wait descriptor was not executed");
+                dprintk(XENLOG_WARNING VTDPREFIX,
+                        "Queue invalidate wait descriptor was timeout.\n");
+                return -ETIMEDOUT;
             }
             cpu_relax();
         }

Without a __must_check annotation on the function I cannot see how I should reasonably convince myself that all call sites now handle such an error in one way or another.

Jan

author
#18 lore raw

PATCH v5 4/7 VT-d: Refactor iommu_ops .iotlb_flush() and iotlb_flush_all()

In reply to Quan Xu

to pass down a flag indicating whether the lock is being held.

---
 xen/arch/arm/p2m.c                  |  2 +-
 xen/common/memory.c                 |  4 ++--
 xen/drivers/passthrough/iommu.c     |  9 +++++----
 xen/drivers/passthrough/vtd/iommu.c |  5 +++--
 xen/drivers/passthrough/x86/iommu.c |  2 +-
 xen/include/xen/iommu.h             | 17 +++++++++++++----
 6 files changed, 25 insertions(+), 14 deletions(-)
xen/arch/arm/p2m.c +1 -1
index e396c40..6eec959 100644
@@ -1100,7 +1100,7 @@ tlbflush:
     if ( flush )
     {
         flush_tlb_domain(d);
-        iommu_iotlb_flush(d, sgfn, egfn - sgfn);
+        iommu_iotlb_flush(d, sgfn, egfn - sgfn, NONE_LOCK);
     }
 
 out:
xen/common/memory.c +2 -2
index c228d9f..e68c3dd 100644
@@ -631,9 +631,9 @@ static int xenmem_add_to_physmap(struct domain *d,
     if ( need_iommu(d) )
     {
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        rc = iommu_iotlb_flush(d, xatp->idx - done, done);
+        rc = iommu_iotlb_flush(d, xatp->idx - done, done, NONE_LOCK);
         if ( !rc )
-            rc = iommu_iotlb_flush(d, xatp->gpfn - done, done);
+            rc = iommu_iotlb_flush(d, xatp->gpfn - done, done, NONE_LOCK);
     }
 #endif
 
xen/drivers/passthrough/iommu.c +5 -4
index cdf8e9a..ebd6d47 100644
@@ -270,24 +270,25 @@ static void iommu_free_pagetables(unsigned long unused)
                             cpumask_cycle(smp_processor_id(), &cpu_online_map));
 }
 
-int iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
+int iommu_iotlb_flush(struct domain *d, unsigned long gfn,
+                      unsigned int page_count, unsigned int lock)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
 
     if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush )
         return 0;
 
-    return hd->platform_ops->iotlb_flush(d, gfn, page_count);
+    return hd->platform_ops->iotlb_flush(d, gfn, page_count, lock);
 }
 
-int iommu_iotlb_flush_all(struct domain *d)
+int iommu_iotlb_flush_all(struct domain *d, unsigned int lock)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
 
     if ( !iommu_enabled || !hd->platform_ops || !hd->platform_ops->iotlb_flush_all )
         return 0;
 
-    return hd->platform_ops->iotlb_flush_all(d);
+    return hd->platform_ops->iotlb_flush_all(d, lock);
 }
 
 int __init iommu_setup(void)
xen/drivers/passthrough/vtd/iommu.c +3 -2
index a780632..e8cbfdb 100644
@@ -601,12 +601,13 @@ static int __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
     return rc;
 }
 
-static int intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count)
+static int intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn,
+                                   unsigned int page_count, unsigned int lock)
 {
     return __intel_iommu_iotlb_flush(d, gfn, 1, page_count);
 }
 
-static int intel_iommu_iotlb_flush_all(struct domain *d)
+static int intel_iommu_iotlb_flush_all(struct domain *d, unsigned int lock)
 {
     return __intel_iommu_iotlb_flush(d, 0, 0, 0);
 }
xen/drivers/passthrough/x86/iommu.c +1 -1
index 6674fb0..4bbf5f8 100644
@@ -105,7 +105,7 @@ int arch_iommu_populate_page_table(struct domain *d)
 
     if ( !rc )
     {
-        rc = iommu_iotlb_flush_all(d);
+        rc = iommu_iotlb_flush_all(d, PCIDEVS_LOCK);
         if ( rc )
             return rc;
     }
xen/include/xen/iommu.h +13 -4
index f5b6f7e..f58e9d6 100644
@@ -131,6 +131,13 @@ struct page_info;
  * callback pair.
  */
 typedef int iommu_grdm_t(xen_pfn_t start, xen_ulong_t nr, u32 id, void *ctxt);
+/*
+ * A flag indicates whether the lock is being held.
+ * NONE_LOCK - no lock is being held.
+ * PCIDEVS_LOCK - pcidevs_lock is being held.
+ */
+#define NONE_LOCK 0
+#define PCIDEVS_LOCK 1
 
 struct iommu_ops {
     int (*init)(struct domain *d);
@@ -161,8 +168,9 @@ struct iommu_ops {
     void (*resume)(void);
     void (*share_p2m)(struct domain *d);
     int (*crash_shutdown)(void);
-    int (*iotlb_flush)(struct domain *d, unsigned long gfn, unsigned int page_count);
-    int (*iotlb_flush_all)(struct domain *d);
+    int (*iotlb_flush)(struct domain *d, unsigned long gfn, unsigned int page_count,
+                       unsigned int lock);
+    int (*iotlb_flush_all)(struct domain *d, unsigned int lock);
     int (*get_reserved_device_memory)(iommu_grdm_t *, void *);
     void (*dump_p2m_table)(struct domain *d);
 };
@@ -182,8 +190,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));
 
-int iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count);
-int iommu_iotlb_flush_all(struct domain *d);
+int iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count,
+                      unsigned int lock);
+int iommu_iotlb_flush_all(struct domain *d, unsigned int lock);
 
 /*
  * The purpose of the iommu_dont_flush_iotlb optional cpu flag is to
Signature · 1 line
1.9.1
#19 lore raw

Re: [PATCH v5 4/7] VT-d: Refactor iommu_ops .iotlb_flush() and iotlb_flush_all()

Quoted 1 line
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:

(Side note: The VT-d: prefix of the subject seems inadequate here.)

Quoted 1 line

to pass down a flag indicating whether the lock is being held.

"the lock" being which one?

Quoted 14 lines
xen/arch/arm/p2m.c +1 -1
@@ -1100,7 +1100,7 @@ tlbflush:
     if ( flush )
     {
         flush_tlb_domain(d);
-        iommu_iotlb_flush(d, sgfn, egfn - sgfn);
+        iommu_iotlb_flush(d, sgfn, egfn - sgfn, NONE_LOCK);
     }
 
 out:

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

Quoted 9 lines
xen/common/memory.c +2 -2
@@ -631,9 +631,9 @@ static int xenmem_add_to_physmap(struct domain *d,
     if ( need_iommu(d) )
     {
         this_cpu(iommu_dont_flush_iotlb) = 0;
-        rc = iommu_iotlb_flush(d, xatp->idx - done, done);
+        rc = iommu_iotlb_flush(d, xatp->idx - done, done, NONE_LOCK);
         if ( !rc )
-            rc = iommu_iotlb_flush(d, xatp->gpfn - done, done);
+            rc = iommu_iotlb_flush(d, xatp->gpfn - done, done, NONE_LOCK);
     }

Considering both of these changes, I think it would be better to hide this implementation detail from callers outside of xen/drivers/passthrough/, by making iommu_iotlb_flush() a wrapper around the actual implementation. (This at once would limit the amount of ack-s such a patch will require.)

xen/include/xen/iommu.h struct page_info; · line 140

Quoted 13 lines
xen/include/xen/iommu.h +7 -0
@@ -131,6 +131,13 @@ struct page_info;
  * callback pair.
  */
 typedef int iommu_grdm_t(xen_pfn_t start, xen_ulong_t nr, u32 id, void *ctxt);
+/*
+ * A flag indicates whether the lock is being held.
+ * NONE_LOCK - no lock is being held.
+ * PCIDEVS_LOCK - pcidevs_lock is being held.
+ */
+#define NONE_LOCK 0
+#define PCIDEVS_LOCK 1

If you really assume further lock holding might need to be communicated here, this should be made more obviously a bit mask (by e.g. using hex constants, not having a NON_LOCKS constant, and not making the first part of the comment refer to just one lock). If, however, the pcidevs_lock is all you care about, I think code readability would benefit from making the respective function parameters bool_t, and adding (besides the already mentioned wrapper) another wrapper named e.g. iommu_iotlb_flush_all_locked().

Jan

author
#20 lore raw

Re: [PATCH v5 4/7] VT-d: Refactor iommu_ops .iotlb_flush() and iotlb_flush_all()

Quoted 8 lines · On February 17, 2016 10:20pm, <[email protected]> wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:

(Side note: The VT-d: prefix of the subject seems inadequate here.)

Quoted 1 line

to pass down a flag indicating whether the lock is being held.

"the lock" being which one?

"pcidevs_lock".

Quoted 26 lines

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

Quoted 14 lines
xen/arch/arm/p2m.c +1 -1
@@ -1100,7 +1100,7 @@ tlbflush:
     if ( flush )
     {
         flush_tlb_domain(d);
-        iommu_iotlb_flush(d, sgfn, egfn - sgfn);
+        iommu_iotlb_flush(d, sgfn, egfn - sgfn, NONE_LOCK);
     }
 
 out:
xen/common/memory.c +0 -0
@@ -631,9 +631,9 @@ static int xenmem_add_to_physmap(struct domain

*d,

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

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

Considering both of these changes, I think it would be better to hide this implementation detail from callers outside of xen/drivers/passthrough/, by making iommu_iotlb_flush() a wrapper around the actual implementation. (This at once would limit the amount of ack-s such a patch will require.)

Good idea.

Quoted 15 lines
Quoted 4 lines
xen/include/xen/iommu.h +0 -0
@@ -131,6 +131,13 @@ struct page_info;
  * callback pair.

xen/include/xen/iommu.h struct page_info; · line 141

Quoted 10 lines
xen/include/xen/iommu.h +7 -0
  */
 typedef int iommu_grdm_t(xen_pfn_t start, xen_ulong_t nr, u32 id,
 void *ctxt);
+/*
+ * A flag indicates whether the lock is being held.
+ * NONE_LOCK - no lock is being held.
+ * PCIDEVS_LOCK - pcidevs_lock is being held.
+ */
+#define NONE_LOCK 0
+#define PCIDEVS_LOCK 1
Quoted 9 lines

If you really assume further lock holding might need to be communicated here, this should be made more obviously a bit mask (by e.g. using hex constants, not having a NON_LOCKS constant, and not making the first part of the comment refer to just one lock). If, however, the pcidevs_lock is all you care about, I think code readability would benefit from making the respective function parameters bool_t, and adding (besides the already mentioned wrapper) another wrapper named e.g.
iommu_iotlb_flush_all_locked().

Yes, the pcidevs_lock is all I care about. I would make the respective function parameters bool_t, and add another wrapper in v6.

e.g.
iommu_iotlb_flush_all_locked() -- The pcidevs_lock is being held. iommu_iotlb_flush_all() -- The pcidevs_lock is NOT being held.
...

iommu_iotlb_flush()
iommu_iotlb_flush_locked()
...
.etc.

Quan

author
#21 lore raw

PATCH v5 5/7 VT-d: Refactor iommu_ops .map_page() and unmap_page()

In reply to Quan Xu

to pass down a flag indicating whether the lock is being held, and check the way up the call trees.

---
 xen/arch/x86/mm.c                             |  9 ++++++---
 xen/arch/x86/mm/p2m-ept.c                     |  7 ++++---
 xen/arch/x86/mm/p2m-pt.c                      |  7 ++++---
 xen/arch/x86/mm/p2m.c                         | 24 +++++++++++++++---------
 xen/arch/x86/x86_64/mm.c                      |  5 +++--
 xen/common/grant_table.c                      | 11 +++++++----
 xen/drivers/passthrough/amd/iommu_map.c       |  7 ++++---
 xen/drivers/passthrough/amd/pci_amd_iommu.c   |  3 ++-
 xen/drivers/passthrough/arm/smmu.c            |  2 +-
 xen/drivers/passthrough/iommu.c               | 11 ++++++-----
 xen/drivers/passthrough/vtd/iommu.c           | 10 ++++++----
 xen/drivers/passthrough/vtd/x86/vtd.c         |  5 +++--
 xen/drivers/passthrough/x86/iommu.c           |  3 ++-
 xen/include/asm-x86/hvm/svm/amd-iommu-proto.h |  4 ++--
 xen/include/asm-x86/p2m.h                     |  6 ++++--
 xen/include/xen/iommu.h                       |  8 ++++----
 16 files changed, 73 insertions(+), 49 deletions(-)
xen/arch/x86/mm.c +6 -3
index 1e50b94..f9030e5 100644
@@ -2443,14 +2443,17 @@ 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)));
+                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                 NONE_LOCK);
             else if ( type == PGT_writable_page )
             {
                 rc = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
                                     page_to_mfn(page),
-                                    IOMMUF_readable|IOMMUF_writable);
+                                    IOMMUF_readable|IOMMUF_writable,
+                                    NONE_LOCK);
                 if ( rc )
-                    iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
+                    iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
+                                     NONE_LOCK);
             }
         }
     }
xen/arch/x86/mm/p2m-ept.c +4 -3
index 9e1f5c6..ecf7e67 100644
@@ -835,16 +835,17 @@ out:
             if ( iommu_flags )
                 for ( i = 0; i < (1 << order); i++ )
                 {
-                    rc = 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, NONE_LOCK);
                     if ( rc )
                     {
                         while ( i-- > 0 )
-                            iommu_unmap_page(d, gfn + i);
+                            iommu_unmap_page(d, gfn + i, NONE_LOCK);
                     }
                 }
             else
                 for ( i = 0; i < (1 << order); i++ )
-                    iommu_unmap_page(d, gfn + i);
+                    iommu_unmap_page(d, gfn + i, NONE_LOCK);
         }
     }
 
xen/arch/x86/mm/p2m-pt.c +4 -3
index 942a11c..e73c0e8 100644
@@ -677,16 +677,17 @@ p2m_pt_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn,
             for ( i = 0; i < (1UL << page_order); i++ )
             {
                 rc = iommu_map_page(p2m->domain, gfn + i, mfn_x(mfn) + i,
-                                    iommu_pte_flags);
+                                    iommu_pte_flags, NONE_LOCK);
                 if ( rc )
                 {
                     while ( i-- > 0 )
-                        iommu_unmap_page(p2m->domain, gfn + i);
+                        iommu_unmap_page(p2m->domain, gfn + i,
+                                         NONE_LOCK);
                 }
             }
         else
             for ( i = 0; i < (1UL << page_order); i++ )
-                iommu_unmap_page(p2m->domain, gfn + i);
+                iommu_unmap_page(p2m->domain, gfn + i, NONE_LOCK);
     }
 
     /*
xen/arch/x86/mm/p2m.c +15 -9
index c6b883d..76748d4 100644
@@ -610,7 +610,7 @@ p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn, unsigned long mfn,
     {
         if ( need_iommu(p2m->domain) )
             for ( i = 0; i < (1 << page_order); i++ )
-                iommu_unmap_page(p2m->domain, mfn + i);
+                iommu_unmap_page(p2m->domain, mfn + i, NONE_LOCK);
         return 0;
     }
 
@@ -662,12 +662,13 @@ guest_physmap_add_entry(struct domain *d, unsigned long gfn,
         {
             for ( i = 0; i < (1 << page_order); i++ )
             {
-                rc = iommu_map_page(
-                    d, mfn + i, mfn + i, IOMMUF_readable|IOMMUF_writable);
+                rc = iommu_map_page(d, mfn + i, mfn + i,
+                                    IOMMUF_readable|IOMMUF_writable,
+                                    NONE_LOCK);
                 if ( rc != 0 )
                 {
                     while ( i-- > 0 )
-                        iommu_unmap_page(d, mfn + i);
+                        iommu_unmap_page(d, mfn + i, NONE_LOCK);
                     return rc;
                 }
             }
@@ -948,7 +949,8 @@ int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn,
 }
 
 int set_identity_p2m_entry(struct domain *d, unsigned long gfn,
-                           p2m_access_t p2ma, unsigned int flag)
+                           p2m_access_t p2ma, unsigned int flag,
+                           unsigned int lock)
 {
     p2m_type_t p2mt;
     p2m_access_t a;
@@ -960,7 +962,8 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn,
     {
         if ( !need_iommu(d) )
             return 0;
-        return iommu_map_page(d, gfn, gfn, IOMMUF_readable|IOMMUF_writable);
+        return iommu_map_page(d, gfn, gfn, IOMMUF_readable|IOMMUF_writable,
+                              lock);
     }
 
     gfn_lock(p2m, gfn, 0);
@@ -979,7 +982,9 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn,
          * RMRRs are correctly mapped with IOMMU.
          */
         if ( is_hardware_domain(d) && !iommu_use_hap_pt(d) )
-            ret = iommu_map_page(d, gfn, gfn, IOMMUF_readable|IOMMUF_writable);
+            ret = iommu_map_page(d, gfn, gfn,
+                                 IOMMUF_readable|IOMMUF_writable,
+                                 lock);
     }
     else
     {
@@ -1032,7 +1037,8 @@ int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn)
     return rc;
 }
 
-int clear_identity_p2m_entry(struct domain *d, unsigned long gfn)
+int clear_identity_p2m_entry(struct domain *d, unsigned long gfn,
+                             unsigned int lock)
 {
     p2m_type_t p2mt;
     p2m_access_t a;
@@ -1044,7 +1050,7 @@ int clear_identity_p2m_entry(struct domain *d, unsigned long gfn)
     {
         if ( !need_iommu(d) )
             return 0;
-        return iommu_unmap_page(d, gfn);
+        return iommu_unmap_page(d, gfn, lock);
     }
 
     gfn_lock(p2m, gfn, 0);
xen/arch/x86/x86_64/mm.c +3 -2
index d918002..ebd6fad 100644
@@ -1433,12 +1433,13 @@ int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm)
     if ( iommu_enabled && !iommu_passthrough && !need_iommu(hardware_domain) )
     {
         for ( i = spfn; i < epfn; i++ )
-            if ( iommu_map_page(hardware_domain, i, i, IOMMUF_readable|IOMMUF_writable) )
+            if ( iommu_map_page(hardware_domain, i, i,
+                 IOMMUF_readable|IOMMUF_writable, NONE_LOCK) )
                 break;
         if ( i != epfn )
         {
             while (i-- > old_max)
-                iommu_unmap_page(hardware_domain, i);
+                iommu_unmap_page(hardware_domain, i, NONE_LOCK);
             goto destroy_m2p;
         }
     }
xen/common/grant_table.c +7 -4
index 1b9bd05..8bc233e 100644
@@ -953,12 +953,14 @@ __gnttab_map_grant_ref(
         {
             if ( !(kind & MAPKIND_WRITE) )
                 err = iommu_map_page(ld, frame, frame,
-                                     IOMMUF_readable|IOMMUF_writable);
+                                     IOMMUF_readable|IOMMUF_writable,
+                                     NONE_LOCK);
         }
         else if ( act_pin && !old_pin )
         {
             if ( !kind )
-                err = iommu_map_page(ld, frame, frame, IOMMUF_readable);
+                err = iommu_map_page(ld, frame, frame,
+                                     IOMMUF_readable, NONE_LOCK);
         }
         if ( err )
         {
@@ -1178,9 +1180,10 @@ __gnttab_unmap_common(
 
         kind = mapkind(lgt, rd, op->frame);
         if ( !kind )
-            err = iommu_unmap_page(ld, op->frame);
+            err = iommu_unmap_page(ld, op->frame, NONE_LOCK);
         else if ( !(kind & MAPKIND_WRITE) )
-            err = iommu_map_page(ld, op->frame, op->frame, IOMMUF_readable);
+            err = iommu_map_page(ld, op->frame, op->frame,
+                                 IOMMUF_readable, NONE_LOCK);
 
         double_gt_unlock(lgt, rgt);
 
xen/drivers/passthrough/amd/iommu_map.c +4 -3
index 78862c9..523feec 100644
@@ -634,7 +634,7 @@ static int update_paging_mode(struct domain *d, unsigned long gfn)
 }
 
 int amd_iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
-                       unsigned int flags)
+                       unsigned int flags, unsigned int lock)
 {
     bool_t need_flush = 0;
     struct hvm_iommu *hd = domain_hvm_iommu(d);
@@ -714,7 +714,7 @@ out:
     return 0;
 }
 
-int amd_iommu_unmap_page(struct domain *d, unsigned long gfn)
+int amd_iommu_unmap_page(struct domain *d, unsigned long gfn, unsigned int lock)
 {
     unsigned long pt_mfn[7];
     struct hvm_iommu *hd = domain_hvm_iommu(d);
@@ -777,7 +777,8 @@ int amd_iommu_reserve_domain_unity_map(struct domain *domain,
     gfn = phys_addr >> PAGE_SHIFT;
     for ( i = 0; i < npages; i++ )
     {
-        rt = amd_iommu_map_page(domain, gfn +i, gfn +i, flags);
+        rt = amd_iommu_map_page(domain, gfn +i, gfn +i, flags,
+                                PCIDEVS_LOCK);
         if ( rt != 0 )
             return rt;
     }
xen/drivers/passthrough/amd/pci_amd_iommu.c +2 -1
index 449de13..1655dd9 100644
@@ -298,7 +298,8 @@ static int __hwdom_init amd_iommu_hwdom_init(struct domain *d)
              */
             if ( mfn_valid(pfn) )
                 amd_iommu_map_page(d, pfn, pfn, 
-                                   IOMMUF_readable|IOMMUF_writable);
+                                   IOMMUF_readable|IOMMUF_writable,
+                                   PCIDEVS_LOCK);
 
             if ( !(i & 0xfffff) )
                 process_pending_softirqs();
xen/drivers/passthrough/arm/smmu.c +1 -1
index 155b7f3..f89ee1b 100644
@@ -2781,7 +2781,7 @@ static int arm_smmu_map_page(struct domain *d, unsigned long gfn,
 	return guest_physmap_add_entry(d, gfn, mfn, 0, t);
 }
 
-static int arm_smmu_unmap_page(struct domain *d, unsigned long gfn)
+static int arm_smmu_unmap_page(struct domain *d, unsigned long gfn, unsigned int lock)
 {
 	/*
 	 * This function should only be used by gnttab code when the domain
xen/drivers/passthrough/iommu.c +6 -5
index ebd6d47..8b5c0a3 100644
@@ -172,7 +172,8 @@ int __hwdom_init iommu_hwdom_init(struct domain *d)
                  ((page->u.inuse.type_info & PGT_type_mask)
                   == PGT_writable_page) )
                 mapping |= IOMMUF_writable;
-            rc = hd->platform_ops->map_page(d, gfn, mfn, mapping);
+            rc = hd->platform_ops->map_page(d, gfn, mfn, mapping,
+                                            PCIDEVS_LOCK);
             if ( rc )
                 return rc;
 
@@ -233,24 +234,24 @@ void iommu_domain_destroy(struct domain *d)
 }
 
 int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
-                   unsigned int flags)
+                   unsigned int flags, unsigned int lock)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
 
     if ( !iommu_enabled || !hd->platform_ops )
         return 0;
 
-    return hd->platform_ops->map_page(d, gfn, mfn, flags);
+    return hd->platform_ops->map_page(d, gfn, mfn, flags, lock);
 }
 
-int iommu_unmap_page(struct domain *d, unsigned long gfn)
+int iommu_unmap_page(struct domain *d, unsigned long gfn, unsigned int lock)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
 
     if ( !iommu_enabled || !hd->platform_ops )
         return 0;
 
-    return hd->platform_ops->unmap_page(d, gfn);
+    return hd->platform_ops->unmap_page(d, gfn, lock);
 }
 
 static void iommu_free_pagetables(unsigned long unused)
xen/drivers/passthrough/vtd/iommu.c +6 -4
index e8cbfdb..6696b16 100644
@@ -1711,7 +1711,7 @@ static void iommu_domain_teardown(struct domain *d)
 
 static int intel_iommu_map_page(
     struct domain *d, unsigned long gfn, unsigned long mfn,
-    unsigned int flags)
+    unsigned int flags, unsigned int lock)
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct dma_pte *page = NULL, *pte = NULL, old, new = { 0 };
@@ -1765,7 +1765,8 @@ static int intel_iommu_map_page(
     return 0;
 }
 
-static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn)
+static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn,
+                                  unsigned int lock)
 {
     /* Do nothing if hardware domain and iommu supports pass thru. */
     if ( iommu_passthrough && is_hardware_domain(d) )
@@ -1865,7 +1866,7 @@ static int rmrr_identity_mapping(struct domain *d, bool_t map,
 
             while ( base_pfn < end_pfn )
             {
-                if ( clear_identity_p2m_entry(d, base_pfn) )
+                if ( clear_identity_p2m_entry(d, base_pfn, PCIDEVS_LOCK) )
                     ret = -ENXIO;
                 base_pfn++;
             }
@@ -1881,7 +1882,8 @@ static int rmrr_identity_mapping(struct domain *d, bool_t map,
 
     while ( base_pfn < end_pfn )
     {
-        int err = set_identity_p2m_entry(d, base_pfn, p2m_access_rw, flag);
+        int err = set_identity_p2m_entry(d, base_pfn, p2m_access_rw, flag,
+                                         PCIDEVS_LOCK);
 
         if ( err )
             return err;
xen/drivers/passthrough/vtd/x86/vtd.c +3 -2
index a19177c..0d4aea7 100644
@@ -143,11 +143,12 @@ int __hwdom_init vtd_set_hwdom_mapping(struct domain *d)
         for ( j = 0; j < tmp; j++ )
         {
             rc = iommu_map_page(d, pfn * tmp + j, pfn * tmp + j,
-                                IOMMUF_readable|IOMMUF_writable);
+                                IOMMUF_readable|IOMMUF_writable,
+                                NONE_LOCK);
             if ( rc )
             {
                 while ( j-- > 0 )
-                    iommu_unmap_page(d, pfn * tmp + j);
+                    iommu_unmap_page(d, pfn * tmp + j, NONE_LOCK);
                 break;
             }
         }
xen/drivers/passthrough/x86/iommu.c +2 -1
index 4bbf5f8..9267a54 100644
@@ -67,7 +67,8 @@ int arch_iommu_populate_page_table(struct domain *d)
                 BUG_ON(SHARED_M2P(gfn));
                 rc = hd->platform_ops->map_page(d, gfn, mfn,
                                                 IOMMUF_readable |
-                                                IOMMUF_writable);
+                                                IOMMUF_writable,
+                                                PCIDEVS_LOCK);
             }
             if ( rc )
             {
xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +2 -2
index 4691f9b..9fc678a 100644
@@ -52,8 +52,8 @@ int amd_iommu_update_ivrs_mapping_acpi(void);
 
 /* mapping functions */
 int amd_iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
-                       unsigned int flags);
-int amd_iommu_unmap_page(struct domain *d, unsigned long gfn);
+                       unsigned int flags, unsigned int lock);
+int amd_iommu_unmap_page(struct domain *d, unsigned long gfn, unsigned int lock);
 u64 amd_iommu_get_next_table_from_pte(u32 *entry);
 int amd_iommu_reserve_domain_unity_map(struct domain *domain,
                                        u64 phys_addr, unsigned long size,
xen/include/asm-x86/p2m.h +4 -2
index 5e99ac6..3c12c95 100644
@@ -562,8 +562,10 @@ int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn);
 
 /* Set identity addresses in the p2m table (for pass-through) */
 int set_identity_p2m_entry(struct domain *d, unsigned long gfn,
-                           p2m_access_t p2ma, unsigned int flag);
-int clear_identity_p2m_entry(struct domain *d, unsigned long gfn);
+                           p2m_access_t p2ma, unsigned int flag,
+                           unsigned int lock);
+int clear_identity_p2m_entry(struct domain *d, unsigned long gfn,
+                             unsigned int lock);
 
 /* Add foreign mapping to the guest's p2m table. */
 int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
xen/include/xen/iommu.h +4 -4
index f58e9d6..27e0e23 100644
@@ -75,8 +75,8 @@ void iommu_teardown(struct domain *d);
 #define _IOMMUF_writable 1
 #define IOMMUF_writable  (1u<<_IOMMUF_writable)
 int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
-                   unsigned int flags);
-int iommu_unmap_page(struct domain *d, unsigned long gfn);
+                   unsigned int flags, unsigned int lock);
+int iommu_unmap_page(struct domain *d, unsigned long gfn, unsigned int lock);
 
 enum iommu_feature
 {
@@ -156,8 +156,8 @@ struct iommu_ops {
 
     void (*teardown)(struct domain *d);
     int (*map_page)(struct domain *d, unsigned long gfn, unsigned long mfn,
-                    unsigned int flags);
-    int (*unmap_page)(struct domain *d, unsigned long gfn);
+                    unsigned int flags, unsigned int lock);
+    int (*unmap_page)(struct domain *d, unsigned long gfn, unsigned int lock);
     void (*free_page_table)(struct page_info *);
 #ifdef CONFIG_X86
     void (*update_ire_from_apic)(unsigned int apic, unsigned int reg, unsigned int value);
Signature · 1 line
1.9.1
#22 lore raw

Re: [PATCH v5 5/7] VT-d: Refactor iommu_ops .map_page() and unmap_page()

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:

to pass down a flag indicating whether the lock is being held, and check the way up the call trees.

Same comments as on the previous patch; most of the changes outside of xen/drivers/passthrough/ seem to be avoidable here.

Jan

author
#23 lore raw

PATCH v5 6/7 VT-d: Refactor iommu_flush .iotlb()

In reply to Quan Xu

to pass down a flag indicating whether the lock is being held, and check the way up the call trees.

---
 xen/arch/x86/mm/p2m-ept.c            |  3 +-
 xen/drivers/passthrough/vtd/iommu.c  | 73 ++++++++++++++++++++++--------------
 xen/drivers/passthrough/vtd/iommu.h  |  3 +-
 xen/drivers/passthrough/vtd/qinval.c |  3 +-
 xen/include/asm-x86/iommu.h          |  3 +-
 5 files changed, 53 insertions(+), 32 deletions(-)
xen/arch/x86/mm/p2m-ept.c +2 -1
index ecf7e67..4c9bdfe 100644
@@ -829,7 +829,8 @@ out:
          need_modify_vtd_table )
     {
         if ( iommu_hap_pt_share )
-            rc = iommu_pte_flush(d, gfn, &ept_entry->epte, order, vtd_pte_present);
+            rc = iommu_pte_flush(d, gfn, &ept_entry->epte, order,
+                                 vtd_pte_present, NONE_LOCK);
         else
         {
             if ( iommu_flags )
xen/drivers/passthrough/vtd/iommu.c +45 -28

227 lines not on this page · raw message

xen/drivers/passthrough/vtd/iommu.h +2 -1
index ac71ed1..0d9d3c4 100644
@@ -494,7 +494,8 @@ struct iommu_flush {
     int (*context)(void *iommu, u16 did, u16 source_id,
                    u8 function_mask, u64 type, int non_present_entry_flush);
     int (*iotlb)(void *iommu, u16 did, u64 addr, unsigned int size_order,
-                 u64 type, int flush_non_present_entry, int flush_dev_iotlb);
+                 u64 type, int flush_non_present_entry, int flush_dev_iotlb,
+                 unsigned int lock);
 };
 
 struct intel_iommu {
xen/drivers/passthrough/vtd/qinval.c +2 -1
index f9e752b..f2e7ffb 100644
@@ -315,7 +315,8 @@ static int flush_context_qi(
 static int flush_iotlb_qi(
     void *_iommu, u16 did,
     u64 addr, unsigned int size_order, u64 type,
-    int flush_non_present_entry, int flush_dev_iotlb)
+    int flush_non_present_entry, int flush_dev_iotlb,
+    unsigned int lock)
 {
     u8 dr = 0, dw = 0;
     int ret = 0;
xen/include/asm-x86/iommu.h +2 -1
index cf2a269..f9499e0 100644
@@ -26,7 +26,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, int present);
+int iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte, int order,
+                    int present, unsigned int lock);
 int iommu_supports_eim(void);
 int iommu_enable_x2apic_IR(void);
 void iommu_disable_x2apic_IR(void);
Signature · 1 line
1.9.1
author
#24 lore raw

PATCH v5 7/7 VT-d: Fix vt-d Device-TLB flush timeout issue.

In reply to Quan Xu

If Device-TLB flush is timeout, we'll hide the target ATS device and crash the domain owning this ATS device.

If impacted domain is hardware domain, just throw out a warning.

The hidden device will be disallowed to be further assigned to any domain.

---
 xen/drivers/passthrough/pci.c         |  2 +-
 xen/drivers/passthrough/vtd/extern.h  |  8 +++-
 xen/drivers/passthrough/vtd/qinval.c  | 77 ++++++++++++++++++++++++++++++++++-
 xen/drivers/passthrough/vtd/x86/ats.c | 14 ++++++-
 4 files changed, 95 insertions(+), 6 deletions(-)
xen/drivers/passthrough/pci.c +1 -1
index 27b3ca7..2d7dc59 100644
@@ -407,7 +407,7 @@ static void _pci_hide_device(struct pci_dev *pdev)
     list_add(&pdev->domain_list, &dom_xen->arch.pdev_list);
 }
 
-int __init pci_hide_device(int bus, int devfn)
+int pci_hide_device(int bus, int devfn)
 {
     struct pci_dev *pdev;
     int rc = -ENOMEM;
xen/drivers/passthrough/vtd/extern.h +6 -2
index ec9c513..a129460 100644
@@ -56,8 +56,12 @@ struct acpi_drhd_unit * find_ats_dev_drhd(struct iommu *iommu);
 
 int ats_device(const struct pci_dev *, const struct acpi_drhd_unit *);
 
-int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
-                         u64 addr, unsigned int size_order, u64 type);
+int dev_invalidate_iotlb(struct iommu *iommu, u16 did, u64 addr,
+                         unsigned int size_order, u64 type,
+                         unsigned int lock);
+int dev_invalidate_iotlb_sync(struct iommu *iommu, u16 did,
+                              u16 seg, u8 bus, u8 devfn,
+                              unsigned int lock);
 
 int qinval_device_iotlb(struct iommu *iommu,
                         u32 max_invs_pend, u16 sid, u16 size, u64 addr);
xen/drivers/passthrough/vtd/qinval.c +75 -2

90 lines not on this page · raw message

xen/drivers/passthrough/vtd/x86/ats.c +13 -1
index 7c797f6..dcc3394 100644
@@ -106,7 +106,7 @@ out:
 }
 
 int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
-    u64 addr, unsigned int size_order, u64 type)
+    u64 addr, unsigned int size_order, u64 type, unsigned int lock)
 {
     struct pci_ats_dev *pdev;
     int ret = 0;
@@ -162,6 +162,18 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
             return -EOPNOTSUPP;
         }
 
+        /*
+         * Synchronize with hardware for Device-TLB invalidate
+         * descriptor.
+         */
+        ret = dev_invalidate_iotlb_sync(iommu, did, pdev->seg,
+                                        pdev->bus, pdev->devfn, lock);
+        if ( ret )
+            printk(XENLOG_ERR
+                   "Flush error %d on device %04x:%02x:%02x.%02x \n",
+                   ret, pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
+                   PCI_FUNC(pdev->devfn));
+
         if ( !ret )
             ret = rc;
     }
Signature · 1 line
1.9.1
#25 lore raw

Re: [PATCH v5 7/7] VT-d: Fix vt-d Device-TLB flush timeout issue.

Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +10 -0
@@ -229,6 +229,69 @@ int qinval_device_iotlb(struct iommu *iommu,
     return 0;
 }
 
+static void dev_invalidate_iotlb_timeout(struct iommu *iommu, u16 did,
+                                         u16 seg, u8 bus, u8 devfn,
+                                         unsigned int lock)
+{
+    struct domain *d = NULL;
+    struct pci_dev *pdev;
+
+    if ( test_bit(did, iommu->domid_bitmap) )
+        d = rcu_lock_domain_by_id(iommu->domid_map[did]);
+

xen/drivers/passthrough/vtd/qinval.c int qinval_device_iotlb(struct iommu *iommu, · line 251

Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c +10 -0
+    if ( d == NULL )
+        return;
+
+    for_each_pdev(d, pdev)
+    {
+        if ( (pdev->seg == seg) &&
+             (pdev->bus == bus) &&
+             (pdev->devfn == devfn) )
+        {
+            ASSERT ( pdev->domain );

Stray blanks inside the parentheses.

xen/drivers/passthrough/vtd/qinval.c int qinval_device_iotlb(struct iommu *iommu, · line 256

Quoted 5 lines
xen/drivers/passthrough/vtd/qinval.c +5 -0
+            list_del(&pdev->domain_list);
+            pdev->domain = NULL;
+
+            if ( !(lock & PCIDEVS_LOCK) )
+                spin_lock(&pcidevs_lock);

This is too late - you may not iterate over pdev-s without holding that lock, and the list_del() may not be done in that case either. Plus this should be accompanied be an ASSERT() in the else case.

xen/drivers/passthrough/vtd/qinval.c int qinval_device_iotlb(struct iommu *iommu, · line 258

Quoted 1 line
xen/drivers/passthrough/vtd/qinval.c +1 -0
+            if ( pci_hide_device(bus, devfn) )

But now I'm _really_ puzzled: You acquire the exact lock that pci_hide_device() acquires. Hence, unless I've overlooked an earlier change, I can't see this as other than an unconditional dead lock. Did you test this code path at all?

xen/drivers/passthrough/vtd/qinval.c int qinval_device_iotlb(struct iommu *iommu, · line 263

Quoted 5 lines
xen/drivers/passthrough/vtd/qinval.c +5 -0
+            {
+                printk(XENLOG_ERR
+                       "IOMMU hide device %04x:%02x:%02x.%02x error.",
+                       seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
+            }

I hate to repeat myself: SBDF need to be printed in canonical ssss:bb:dd.f form, to be grep-able. Also no full stops at the end of log messages please. And (also mentioned before) if there are error codes available, log them to aid diagnosis of problems.

Also - unnecessary figure braces.

Quoted 11 lines
xen/drivers/passthrough/vtd/qinval.c +5 -2
@@ -350,9 +413,19 @@ static int flush_iotlb_qi(
         queue_invalidate_iotlb(iommu,
                                type >> DMA_TLB_FLUSH_GRANU_OFFSET, dr,
                                dw, did, size_order, 0, addr);
-        if ( flush_dev_iotlb )
-            ret = dev_invalidate_iotlb(iommu, did, addr, size_order, type);
+
+        /*
+         * Before Device-TLB invalidation we need to synchronize
+         * invalidation completions with hardware.
+         */

xen/drivers/passthrough/vtd/qinval.c static int flush_iotlb_qi( · line 430

Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c +7 -0
         rc = invalidate_sync(iommu);
+        if ( rc )
+             return rc;
+
+        if ( flush_dev_iotlb )
+            ret = dev_invalidate_iotlb(iommu, did, addr, size_order,
+                                       type, lock);
+
         if ( !ret )
             ret = rc;

These two lines have now become pointless, and hence should be deleted.

Quoted 8 lines
xen/drivers/passthrough/vtd/qinval.c +4 -0
@@ -162,6 +162,18 @@ int dev_invalidate_iotlb(struct iommu *iommu, u16 did,
             return -EOPNOTSUPP;
         }
 
+        /*
+         * Synchronize with hardware for Device-TLB invalidate
+         * descriptor.
+         */

xen/drivers/passthrough/vtd/qinval.c int dev_invalidate_iotlb(struct iommu *iommu, u16 did, · line 178

Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c +8 -0
+        ret = dev_invalidate_iotlb_sync(iommu, did, pdev->seg,
+                                        pdev->bus, pdev->devfn, lock);
+        if ( ret )
+            printk(XENLOG_ERR
+                   "Flush error %d on device %04x:%02x:%02x.%02x \n",
+                   ret, pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
+                   PCI_FUNC(pdev->devfn));
+
         if ( !ret )
             ret = rc;

The two context lines here show that you're now clobbering "ret".

Jan

author
#26 lore raw

Re: [PATCH v5 7/7] VT-d: Fix vt-d Device-TLB flush timeout issue.

Quoted 10 lines · On February 17, 2016 10:41pm, <[email protected]> wrote:

xen/drivers/passthrough/vtd/qinval.c int qinval_device_iotlb(struct iommu *iommu, · line 258

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +1 -0
+            if ( pci_hide_device(bus, devfn) )

But now I'm _really_ puzzled: You acquire the exact lock that pci_hide_device() acquires. Hence, unless I've overlooked an earlier change, I can't see this as other than an unconditional dead lock. Did you test this code path at all?

Sorry, I didn't test this code path.
I did test the follows:
1) Create domain with ATS device.
2) Attach / Detach ATS device.

I think I could add a variation of pci_hide_device(), without "spin_lock(&pcidevs_lock) / spin_unlock(&pcidevs_lock)" Or "__init".

But it is sure that different lock state is possible for different call trees when to flush an ATS device. I verify it as follows:
1.print pcidevs_lock status in flush_iotlb_qi()

flush_iotlb_qi()
{
...
+ printk("__ pcidevs_lock : %d *__\n", spin_is_locked(&pcidevs_lock));
...
}

2. attach ATS device

      $xl pci-attach TestDom 0000:81:00.0

#The print is "(XEN) __ pcidevs_lock : 1 *__"

3. reset memory of domain

      $ xl mem-set TestDom 2047m
  #the print is "(XEN) __ pcidevs_lock : 0 *__"

Quan

#27 lore raw

Re: [PATCH v5 7/7] VT-d: Fix vt-d Device-TLB flush timeout issue.

Quoted 14 lines
Quoted 9 lines
Quoted 1 line · On 18.02.16 at 08:36, <[email protected]> wrote:

xen/drivers/passthrough/vtd/qinval.c int qinval_device_iotlb(struct iommu *iommu, · line 258

Quoted 4 lines · On February 17, 2016 10:41pm, <[email protected]> wrote:
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +1 -0
+            if ( pci_hide_device(bus, devfn) )

But now I'm _really_ puzzled: You acquire the exact lock that pci_hide_device() acquires. Hence, unless I've overlooked an earlier change,

I

Quoted 1 line

can't see this as other than an unconditional dead lock. Did you test this

code

Quoted 1 line

path at all?

Quoted 8 lines

Sorry, I didn't test this code path.
I did test the follows:
1) Create domain with ATS device.
2) Attach / Detach ATS device.

I think I could add a variation of pci_hide_device(), without "spin_lock(&pcidevs_lock) / spin_unlock(&pcidevs_lock)" Or "__init".

Which we already have - _pci_hide_device(). The function would just need to be made non-static, but would otherwise fit your purposes since you also don't need the alloc_pdev() the other function does.

Quoted 2 lines

But it is sure that different lock state is possible for different call trees when to flush an ATS device.

Sure, that's why you pass down the flag. Presumably easiest (albeit not nicest) will be to call the respective of the two functions depending on the lock holding flag.

Jan

author
#28 lore raw

Re: [PATCH v5 7/7] VT-d: Fix vt-d Device-TLB flush timeout issue.

Quoted 22 lines · On February 18, 2016 4:36pm, <[email protected]> wrote:
Quoted 21 lines
Quoted 10 lines
Quoted 1 line · On 18.02.16 at 08:36, <[email protected]> wrote:

xen/drivers/passthrough/vtd/qinval.c int qinval_device_iotlb(struct iommu *iommu, · line 258

Quoted 4 lines · On February 17, 2016 10:41pm, <[email protected]> wrote:
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +1 -0
+            if ( pci_hide_device(bus, devfn) )

But now I'm _really_ puzzled: You acquire the exact lock that pci_hide_device() acquires. Hence, unless I've overlooked an earlier change,

I

Quoted 2 lines

can't see this as other than an unconditional dead lock. Did you test this

code

Quoted 1 line

path at all?

Sorry, I didn't test this code path.
I did test the follows:
1) Create domain with ATS device.
2) Attach / Detach ATS device.

Quoted 8 lines
Quoted 3 lines

I think I could add a variation of pci_hide_device(), without "spin_lock(&pcidevs_lock) / spin_unlock(&pcidevs_lock)" Or "__init".

Which we already have - _pci_hide_device(). The function would just need to be made non-static, but would otherwise fit your purposes since you also don't need the alloc_pdev() the other function does.

But the _pci_hide_device() starts with '_', I think it is not a good idea to make it non-static. I'd better introduce a new function to wrap the '_pci_hide_device()'. It is difficult to name the new function.

Quoted 7 lines
Quoted 2 lines

But it is sure that different lock state is possible for different call trees when to flush an ATS device.

Sure, that's why you pass down the flag. Presumably easiest (albeit not nicest) will be to call the respective of the two functions depending on the lock holding flag.

It is really a good idea. Thanks you for your advice.

Quan

#29 lore raw

Re: [PATCH v5 7/7] VT-d: Fix vt-d Device-TLB flush timeout issue.

Quoted 27 lines
Quoted 27 lines
Quoted 1 line · On 18.02.16 at 09:47, <[email protected]> wrote:
Quoted 24 lines · On February 18, 2016 4:36pm, <[email protected]> wrote:
Quoted 10 lines
Quoted 1 line · On 18.02.16 at 08:36, <[email protected]> wrote:

xen/drivers/passthrough/vtd/qinval.c int qinval_device_iotlb(struct iommu *iommu, · line 258

Quoted 4 lines · On February 17, 2016 10:41pm, <[email protected]> wrote:
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +1 -0
+            if ( pci_hide_device(bus, devfn) )

But now I'm _really_ puzzled: You acquire the exact lock that pci_hide_device() acquires. Hence, unless I've overlooked an earlier change,

I

Quoted 2 lines

can't see this as other than an unconditional dead lock. Did you test this

code

Quoted 1 line

path at all?

Sorry, I didn't test this code path.
I did test the follows:
1) Create domain with ATS device.
2) Attach / Detach ATS device.

I think I could add a variation of pci_hide_device(), without "spin_lock(&pcidevs_lock) / spin_unlock(&pcidevs_lock)" Or "__init".

Quoted 8 lines
Quoted 3 lines

Which we already have - _pci_hide_device(). The function would just need to be made non-static, but would otherwise fit your purposes since you also don't need the alloc_pdev() the other function does.

But the _pci_hide_device() starts with '_', I think it is not a good idea to make it non-static.
I'd better introduce a new function to wrap the '_pci_hide_device()'. It is difficult to name the new function.

Why add a wrapper - just rename the function (I indeed appreciate you not wanting to globalize a function whose name starts with an underscore), e.g. to pci_hide_device_locked() or pci_hide_existing_device().

Jan

author
#30 lore raw

Re: [PATCH v5 7/7] VT-d: Fix vt-d Device-TLB flush timeout issue.

Quoted 32 lines · On February 18, 2016 5:21pm, <[email protected]> wrote:
Quoted 31 lines
Quoted 30 lines
Quoted 1 line · On 18.02.16 at 09:47, <[email protected]> wrote:
Quoted 16 lines · On February 18, 2016 4:36pm, <[email protected]> wrote:
Quoted 10 lines
Quoted 1 line · On 18.02.16 at 08:36, <[email protected]> wrote:

xen/drivers/passthrough/vtd/qinval.c int qinval_device_iotlb(struct iommu *iommu, · line 258

Quoted 4 lines · On February 17, 2016 10:41pm, <[email protected]> wrote:
Quoted 1 line
Quoted 1 line · On 05.02.16 at 11:18, <[email protected]> wrote:
xen/drivers/passthrough/vtd/qinval.c +1 -0
+            if ( pci_hide_device(bus, devfn) )

But now I'm _really_ puzzled: You acquire the exact lock that pci_hide_device() acquires. Hence, unless I've overlooked an earlier change,

I

Quoted 2 lines

can't see this as other than an unconditional dead lock. Did you test this

code

Quoted 1 line

path at all?

Quoted 8 lines

Sorry, I didn't test this code path.
I did test the follows:
1) Create domain with ATS device.
2) Attach / Detach ATS device.

I think I could add a variation of pci_hide_device(), without "spin_lock(&pcidevs_lock) / spin_unlock(&pcidevs_lock)" Or "__init".

Which we already have - _pci_hide_device(). The function would just need to be made non-static, but would otherwise fit your purposes since you also don't need the alloc_pdev() the other function does.

Quoted 9 lines
Quoted 4 lines

But the _pci_hide_device() starts with '_', I think it is not a good idea to make it non-static.
I'd better introduce a new function to wrap the '_pci_hide_device()'. It is difficult to name the new function.

Why add a wrapper - just rename the function (I indeed appreciate you not wanting to globalize a function whose name starts with an underscore), e.g. to pci_hide_device_locked() or pci_hide_existing_device().

Okay, I will rename the _pci_hide_device() to pci_hide_existing_device() in v6. Quan