Skip to contentSkip to conversation

Make the pcidevs_lock a recursive one

PATCH Superseded Quan Xu 3 participants 10 messages Mar 8, 2016

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Quan Xu

author
#0 lore raw

cover Make the pcidevs_lock a recursive one

This patch set makes the pcidevs_lock a recursive one. It is a prereq patch set for Patch:'VT-d Device-TLB flush issue', as the pcidevs_lock may be recursively held for hiding the ATS device, when IOMMU Device-TLB flush timed out.

In detail:
1. Fix a bug found in AMD IOMMU initialization.
Doing what we do serves as a fix for a bug found in AMD IOMMU initialization.

The current code is using spin_lock{_irqsave(), _irqrestore()} to protect pci_get_dev() in the set_iommu_interrupt_handler(). However, this can only be called during AMD IOMMU initialization, with interrupt enabled, so at least it is not necessary to disable interrupts, or save/restore interrupt flag.

In order to fix this, we can use just plain spin{_lock(),_unlock()}, instead of spin_lock{_irqsave(),_irqrestore()}.

2. Make the pcidevs_lock a recursive one.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Suravee Suthikulpanit <[email protected]>
CC Aravind Gopalakrishnan <[email protected]>
CC Feng Wu <[email protected]>
CC Kevin Tian <[email protected]>
CC Dario Faggioli <[email protected]>

Quan Xu (2):
IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization. IOMMU/spinlock: Make the pcidevs_lock a recursive one

 xen/arch/x86/domctl.c                       |  8 +--
 xen/arch/x86/hvm/vmsi.c                     |  4 +-
 xen/arch/x86/irq.c                          |  8 +--
 xen/arch/x86/msi.c                          | 16 ++---
 xen/arch/x86/pci.c                          |  4 +-
 xen/arch/x86/physdev.c                      | 16 ++---
 xen/common/sysctl.c                         |  4 +-
 xen/drivers/passthrough/amd/iommu_init.c    |  9 ++-
 xen/drivers/passthrough/amd/iommu_map.c     |  2 +-
 xen/drivers/passthrough/amd/pci_amd_iommu.c |  4 +-
 xen/drivers/passthrough/pci.c               | 96 +++++++++++++++++------------
 xen/drivers/passthrough/vtd/iommu.c         | 14 ++---
 xen/drivers/video/vga.c                     |  4 +-
 xen/include/xen/pci.h                       |  5 +-
 14 files changed, 108 insertions(+), 86 deletions(-)
Signature · 7 lines
1.9.1


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

PATCH 1/2 IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization.

Doing what we do serves as a fix for a bug found in AMD IOMMU initialization.

The current code is using spin_lock{_irqsave(), _irqrestore()} to protect pci_get_dev() in the set_iommu_interrupt_handler(). However, this can only be called during AMD IOMMU initialization, with interrupt enabled, so at least it is not necessary to disable interrupts, or save/restore interrupt flag.

In order to fix this, we can use just plain spin{_lock(),_unlock()}, instead of spin_lock{_irqsave(),_irqrestore()}.

CC Suravee Suthikulpanit <[email protected]>
CC Aravind Gopalakrishnan <[email protected]>
CC Dario Faggioli <[email protected]>
CC Jan Beulich <[email protected]>
---
 xen/drivers/passthrough/amd/iommu_init.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
xen/drivers/passthrough/amd/iommu_init.c +2 -3
index d90a2d2..a400497 100644
@@ -778,7 +778,6 @@ static bool_t __init set_iommu_interrupt_handler(struct amd_iommu *iommu)
 {
     int irq, ret;
     hw_irq_controller *handler;
-    unsigned long flags;
     u16 control;
 
     irq = create_irq(NUMA_NO_NODE);
@@ -788,10 +787,10 @@ static bool_t __init set_iommu_interrupt_handler(struct amd_iommu *iommu)
         return 0;
     }
 
-    spin_lock_irqsave(&pcidevs_lock, flags);
+    spin_lock(&pcidevs_lock);
     iommu->msi.dev = pci_get_pdev(iommu->seg, PCI_BUS(iommu->bdf),
                                   PCI_DEVFN2(iommu->bdf));
-    spin_unlock_irqrestore(&pcidevs_lock, flags);
+    spin_unlock(&pcidevs_lock);
     if ( !iommu->msi.dev )
     {
         AMD_IOMMU_DEBUG("IOMMU: no pdev for %04x:%02x:%02x.%u\n",
Signature · 7 lines
1.9.1


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

Re: [PATCH 1/2] IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization.

Quoted 3 lines · Quan Xu

Doing what we do serves as a fix for a bug found in AMD IOMMU initialization.

This first line is rather useless, if not worse. :-)

I don't know (provided a new version is not necessary, and provided maintainers agree with me :-)) whether you need to repost or it can be removed when code is committed.

Quoted 4 lines
CC Suravee Suthikulpanit <[email protected]>
CC Aravind Gopalakrishnan <[email protected]>

get_maintainer.pl gives me only Suravee, as Aravind stepped down a few days ago, so he shouldn't be bothered (and, in fact, I'm moving him from Cc to Bcc).

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

(BTW, it's of course fine to include me and Jan, despite what get_maintainer.pl's output, as we've been involved in previous rounds of review.)

All that being said:

Thanks and Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

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

author
#3 lore raw

Re: [PATCH 1/2] IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization.

Quoted 6 lines · On March 08, 2016 8:13pm, <[email protected]> wrote:
Quoted 3 lines · Quan Xu

Doing what we do serves as a fix for a bug found in AMD IOMMU initialization.

This first line is rather useless, if not worse. :-)

I will remove it in next v2. :)

Quoted 4 lines

I don't know (provided a new version is not necessary, and provided maintainers agree with me :-)) whether you need to repost or it can be removed when code is committed.

I think I'd better send out v2. :)

Quoted 7 lines
Quoted 4 lines
CC Suravee Suthikulpanit <[email protected]>
CC Aravind Gopalakrishnan <[email protected]>

get_maintainer.pl gives me only Suravee, as Aravind stepped down a few days ago, so he shouldn't be bothered (and, in fact, I'm moving him from Cc to Bcc).

Got it, thanks for your advice.

Quoted 10 lines
Quoted 3 lines
CC Dario Faggioli <[email protected]>
CC Jan Beulich <[email protected]>

(BTW, it's of course fine to include me and Jan, despite what get_maintainer.pl's output, as we've been involved in previous rounds of review.)

All that being said:

Dario, thanks.

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

#4 lore raw

Re: [PATCH 1/2] IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization.

In reply to Quan Xu
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.03.16 at 12:09, <[email protected]> wrote:

Doing what we do serves as a fix for a bug found in AMD IOMMU initialization.

The current code is using spin_lock{_irqsave(), _irqrestore()} to protect pci_get_dev() in the set_iommu_interrupt_handler(). However, this can only be called during AMD IOMMU initialization, with interrupt enabled, so at least it is not necessary to disable interrupts, or save/restore interrupt flag.

On top of what Dario said: This description isn't very accurate either:
If the code in question runs with interrupts enabled (which I'm not sure it does; would take me following back up the call chain to see whether this happens before or after interrupts get enabled for the first time), then it may very well be necessary to disable interrupts for a particular purpose - from an abstract pov. That's not the case here, but the description of such a change shouldn't make incorrect claims or statements.

Jan

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

author
#5 lore raw

PATCH 2/2 IOMMU/spinlock: Make the pcidevs_lock a recursive one

In reply to Quan Xu
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Suravee Suthikulpanit <[email protected]>
CC Aravind Gopalakrishnan <[email protected]>
CC Feng Wu <[email protected]>
CC Kevin Tian <[email protected]>
CC Dario Faggioli <[email protected]>
---
 xen/arch/x86/domctl.c                       |  8 +--
 xen/arch/x86/hvm/vmsi.c                     |  4 +-
 xen/arch/x86/irq.c                          |  8 +--
 xen/arch/x86/msi.c                          | 16 ++---
 xen/arch/x86/pci.c                          |  4 +-
 xen/arch/x86/physdev.c                      | 16 ++---
 xen/common/sysctl.c                         |  4 +-
 xen/drivers/passthrough/amd/iommu_init.c    |  8 +--
 xen/drivers/passthrough/amd/iommu_map.c     |  2 +-
 xen/drivers/passthrough/amd/pci_amd_iommu.c |  4 +-
 xen/drivers/passthrough/pci.c               | 96 +++++++++++++++++------------
 xen/drivers/passthrough/vtd/iommu.c         | 14 ++---
 xen/drivers/video/vga.c                     |  4 +-
 xen/include/xen/pci.h                       |  5 +-
 14 files changed, 108 insertions(+), 85 deletions(-)
xen/arch/x86/domctl.c +4 -4
index bf62a88..21cc161 100644
@@ -427,9 +427,9 @@ long arch_do_domctl(
         ret = -ESRCH;
         if ( iommu_enabled )
         {
-            spin_lock(&pcidevs_lock);
+            pcidevs_lock();
             ret = pt_irq_create_bind(d, bind);
-            spin_unlock(&pcidevs_lock);
+            pcidevs_unlock();
         }
         if ( ret < 0 )
             printk(XENLOG_G_ERR "pt_irq_create_bind failed (%ld) for dom%d\n",
@@ -452,9 +452,9 @@ long arch_do_domctl(
 
         if ( iommu_enabled )
         {
-            spin_lock(&pcidevs_lock);
+            pcidevs_lock();
             ret = pt_irq_destroy_bind(d, bind);
-            spin_unlock(&pcidevs_lock);
+            pcidevs_unlock();
         }
         if ( ret < 0 )
             printk(XENLOG_G_ERR "pt_irq_destroy_bind failed (%ld) for dom%d\n",
xen/arch/x86/hvm/vmsi.c +2 -2
index ac838a9..8e0817b 100644
@@ -388,7 +388,7 @@ int msixtbl_pt_register(struct domain *d, struct pirq *pirq, uint64_t gtable)
     struct msixtbl_entry *entry, *new_entry;
     int r = -EINVAL;
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
     ASSERT(spin_is_locked(&d->event_lock));
 
     /*
@@ -443,7 +443,7 @@ void msixtbl_pt_unregister(struct domain *d, struct pirq *pirq)
     struct pci_dev *pdev;
     struct msixtbl_entry *entry;
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
     ASSERT(spin_is_locked(&d->event_lock));
 
     irq_desc = pirq_spin_lock_irq_desc(pirq, NULL);
xen/arch/x86/irq.c +4 -4
index bf2e822..68bdf19 100644
@@ -1955,7 +1955,7 @@ int map_domain_pirq(
         struct pci_dev *pdev;
         unsigned int nr = 0;
 
-        ASSERT(spin_is_locked(&pcidevs_lock));
+        ASSERT(pcidevs_is_locked());
 
         ret = -ENODEV;
         if ( !cpu_has_apic )
@@ -2100,7 +2100,7 @@ int unmap_domain_pirq(struct domain *d, int pirq)
     if ( (pirq < 0) || (pirq >= d->nr_pirqs) )
         return -EINVAL;
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
     ASSERT(spin_is_locked(&d->event_lock));
 
     info = pirq_info(d, pirq);
@@ -2226,7 +2226,7 @@ void free_domain_pirqs(struct domain *d)
 {
     int i;
 
-    spin_lock(&pcidevs_lock);
+    pcidevs_lock();
     spin_lock(&d->event_lock);
 
     for ( i = 0; i < d->nr_pirqs; i++ )
@@ -2234,7 +2234,7 @@ void free_domain_pirqs(struct domain *d)
             unmap_domain_pirq(d, i);
 
     spin_unlock(&d->event_lock);
-    spin_unlock(&pcidevs_lock);
+    pcidevs_unlock();
 }
 
 static void dump_irqs(unsigned char key)
xen/arch/x86/msi.c +8 -8
index 3dbb84d..6e5e33e 100644
@@ -694,7 +694,7 @@ static int msi_capability_init(struct pci_dev *dev,
     u8 slot = PCI_SLOT(dev->devfn);
     u8 func = PCI_FUNC(dev->devfn);
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
     pos = pci_find_cap_offset(seg, bus, slot, func, PCI_CAP_ID_MSI);
     if ( !pos )
         return -ENODEV;
@@ -852,7 +852,7 @@ static int msix_capability_init(struct pci_dev *dev,
     u8 func = PCI_FUNC(dev->devfn);
     bool_t maskall = msix->host_maskall;
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
 
     control = pci_conf_read16(seg, bus, slot, func, msix_control_reg(pos));
     /*
@@ -1042,7 +1042,7 @@ static int __pci_enable_msi(struct msi_info *msi, struct msi_desc **desc)
     struct pci_dev *pdev;
     struct msi_desc *old_desc;
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
     pdev = pci_get_pdev(msi->seg, msi->bus, msi->devfn);
     if ( !pdev )
         return -ENODEV;
@@ -1103,7 +1103,7 @@ static int __pci_enable_msix(struct msi_info *msi, struct msi_desc **desc)
     u8 func = PCI_FUNC(msi->devfn);
     struct msi_desc *old_desc;
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
     pdev = pci_get_pdev(msi->seg, msi->bus, msi->devfn);
     pos = pci_find_cap_offset(msi->seg, msi->bus, slot, func, PCI_CAP_ID_MSIX);
     if ( !pdev || !pos )
@@ -1205,7 +1205,7 @@ int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool_t off)
     if ( !pos )
         return -ENODEV;
 
-    spin_lock(&pcidevs_lock);
+    pcidevs_lock();
     pdev = pci_get_pdev(seg, bus, devfn);
     if ( !pdev )
         rc = -ENODEV;
@@ -1224,7 +1224,7 @@ int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool_t off)
         rc = msix_capability_init(pdev, pos, NULL, NULL,
                                   multi_msix_capable(control));
     }
-    spin_unlock(&pcidevs_lock);
+    pcidevs_unlock();
 
     return rc;
 }
@@ -1235,7 +1235,7 @@ int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool_t off)
  */
 int pci_enable_msi(struct msi_info *msi, struct msi_desc **desc)
 {
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
 
     if ( !use_msi )
         return -EPERM;
@@ -1351,7 +1351,7 @@ int pci_restore_msi_state(struct pci_dev *pdev)
     unsigned int type = 0, pos = 0;
     u16 control = 0;
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
 
     if ( !use_msi )
         return -EOPNOTSUPP;
xen/arch/x86/pci.c +2 -2
index 5bcecbb..892278d 100644
@@ -82,13 +82,13 @@ int pci_conf_write_intercept(unsigned int seg, unsigned int bdf,
     if ( reg < 64 || reg >= 256 )
         return 0;
 
-    spin_lock(&pcidevs_lock);
+    pcidevs_lock();
 
     pdev = pci_get_pdev(seg, PCI_BUS(bdf), PCI_DEVFN2(bdf));
     if ( pdev )
         rc = pci_msi_conf_write_intercept(pdev, reg, size, data);
 
-    spin_unlock(&pcidevs_lock);
+    pcidevs_unlock();
 
     return rc;
 }
xen/arch/x86/physdev.c +8 -8
index 57b7800..1cb9b58 100644
@@ -167,7 +167,7 @@ int physdev_map_pirq(domid_t domid, int type, int *index, int *pirq_p,
         goto free_domain;
     }
 
-    spin_lock(&pcidevs_lock);
+    pcidevs_lock();
     /* Verify or get pirq. */
     spin_lock(&d->event_lock);
     pirq = domain_irq_to_pirq(d, irq);
@@ -237,7 +237,7 @@ int physdev_map_pirq(domid_t domid, int type, int *index, int *pirq_p,
 
  done:
     spin_unlock(&d->event_lock);
-    spin_unlock(&pcidevs_lock);
+    pcidevs_unlock();
     if ( ret != 0 )
         switch ( type )
         {
@@ -275,11 +275,11 @@ int physdev_unmap_pirq(domid_t domid, int pirq)
             goto free_domain;
     }
 
-    spin_lock(&pcidevs_lock);
+    pcidevs_lock();
     spin_lock(&d->event_lock);
     ret = unmap_domain_pirq(d, pirq);
     spin_unlock(&d->event_lock);
-    spin_unlock(&pcidevs_lock);
+    pcidevs_unlock();
 
  free_domain:
     rcu_unlock_domain(d);
@@ -689,10 +689,10 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( copy_from_guest(&restore_msi, arg, 1) != 0 )
             break;
 
-        spin_lock(&pcidevs_lock);
+        pcidevs_lock();
         pdev = pci_get_pdev(0, restore_msi.bus, restore_msi.devfn);
         ret = pdev ? pci_restore_msi_state(pdev) : -ENODEV;
-        spin_unlock(&pcidevs_lock);
+        pcidevs_unlock();
         break;
     }
 
@@ -704,10 +704,10 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( copy_from_guest(&dev, arg, 1) != 0 )
             break;
 
-        spin_lock(&pcidevs_lock);
+        pcidevs_lock();
         pdev = pci_get_pdev(dev.seg, dev.bus, dev.devfn);
         ret = pdev ? pci_restore_msi_state(pdev) : -ENODEV;
-        spin_unlock(&pcidevs_lock);
+        pcidevs_unlock();
         break;
     }
 
xen/common/sysctl.c +2 -2
index 85e853f..401edb9 100644
@@ -426,7 +426,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
                 break;
             }
 
-            spin_lock(&pcidevs_lock);
+            pcidevs_lock();
             pdev = pci_get_pdev(dev.seg, dev.bus, dev.devfn);
             if ( !pdev )
                 node = XEN_INVALID_DEV;
@@ -434,7 +434,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
                 node = XEN_INVALID_NODE_ID;
             else
                 node = pdev->node;
-            spin_unlock(&pcidevs_lock);
+            pcidevs_unlock();
 
             if ( copy_to_guest_offset(ti->nodes, i, &node, 1) )
             {
xen/drivers/passthrough/amd/iommu_init.c +4 -4
index a400497..4536106 100644
@@ -673,9 +673,9 @@ void parse_ppr_log_entry(struct amd_iommu *iommu, u32 entry[])
     bus = PCI_BUS(device_id);
     devfn = PCI_DEVFN2(device_id);
 
-    spin_lock(&pcidevs_lock);
+    pcidevs_lock();
     pdev = pci_get_real_pdev(iommu->seg, bus, devfn);
-    spin_unlock(&pcidevs_lock);
+    pcidevs_unlock();
 
     if ( pdev )
         guest_iommu_add_ppr_log(pdev->domain, entry);
@@ -787,10 +787,10 @@ static bool_t __init set_iommu_interrupt_handler(struct amd_iommu *iommu)
         return 0;
     }
 
-    spin_lock(&pcidevs_lock);
+    pcidevs_lock();
     iommu->msi.dev = pci_get_pdev(iommu->seg, PCI_BUS(iommu->bdf),
                                   PCI_DEVFN2(iommu->bdf));
-    spin_unlock(&pcidevs_lock);
+    pcidevs_unlock();
     if ( !iommu->msi.dev )
     {
         AMD_IOMMU_DEBUG("IOMMU: no pdev for %04x:%02x:%02x.%u\n",
xen/drivers/passthrough/amd/iommu_map.c +1 -1
index 78862c9..9d91dfc 100644
@@ -593,7 +593,7 @@ static int update_paging_mode(struct domain *d, unsigned long gfn)
         hd->arch.paging_mode = level;
         hd->arch.root_table = new_root;
 
-        if ( !spin_is_locked(&pcidevs_lock) )
+        if ( !pcidevs_is_locked() )
             AMD_IOMMU_DEBUG("%s Try to access pdev_list "
                             "without aquiring pcidevs_lock.\n", __func__);
 
xen/drivers/passthrough/amd/pci_amd_iommu.c +2 -2
index c1c0b6b..dc3bfab 100644
@@ -158,7 +158,7 @@ static void amd_iommu_setup_domain_device(
 
     spin_unlock_irqrestore(&iommu->lock, flags);
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
 
     if ( pci_ats_device(iommu->seg, bus, pdev->devfn) &&
          !pci_ats_enabled(iommu->seg, bus, pdev->devfn) )
@@ -345,7 +345,7 @@ void amd_iommu_disable_domain_device(struct domain *domain,
     }
     spin_unlock_irqrestore(&iommu->lock, flags);
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
 
     if ( devfn == pdev->devfn &&
          pci_ats_device(iommu->seg, bus, devfn) &&
xen/drivers/passthrough/pci.c +58 -38

285 lines not on this page · raw message

xen/drivers/passthrough/vtd/iommu.c +7 -7
index dd13865..30f007e 100644
@@ -1286,7 +1286,7 @@ int domain_context_mapping_one(
     u16 seg = iommu->intel->drhd->segment;
     int agaw;
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
     spin_lock(&iommu->lock);
     maddr = bus_to_context_maddr(iommu, bus);
     context_entries = (struct context_entry *)map_vtd_domain_page(maddr);
@@ -1428,7 +1428,7 @@ static int domain_context_mapping(
     if ( !drhd )
         return -ENODEV;
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
 
     switch ( pdev->type )
     {
@@ -1510,7 +1510,7 @@ int domain_context_unmap_one(
     u64 maddr;
     int iommu_domid;
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
     spin_lock(&iommu->lock);
 
     maddr = bus_to_context_maddr(iommu, bus);
@@ -1820,7 +1820,7 @@ static int rmrr_identity_mapping(struct domain *d, bool_t map,
     struct mapped_rmrr *mrmrr;
     struct hvm_iommu *hd = domain_hvm_iommu(d);
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
     ASSERT(rmrr->base_address < rmrr->end_address);
 
     /*
@@ -1885,7 +1885,7 @@ static int intel_iommu_add_device(u8 devfn, struct pci_dev *pdev)
     u16 bdf;
     int ret, i;
 
-    ASSERT(spin_is_locked(&pcidevs_lock));
+    ASSERT(pcidevs_is_locked());
 
     if ( !pdev->domain )
         return -EINVAL;
@@ -2113,7 +2113,7 @@ static void __hwdom_init setup_hwdom_rmrr(struct domain *d)
     u16 bdf;
     int ret, i;
 
-    spin_lock(&pcidevs_lock);
+    pcidevs_lock();
     for_each_rmrr_device ( rmrr, bdf, i )
     {
         /*
@@ -2127,7 +2127,7 @@ static void __hwdom_init setup_hwdom_rmrr(struct domain *d)
             dprintk(XENLOG_ERR VTDPREFIX,
                      "IOMMU: mapping reserved region failed\n");
     }
-    spin_unlock(&pcidevs_lock);
+    pcidevs_unlock();
 }
 
 int __init intel_vtd_setup(void)
xen/drivers/video/vga.c +2 -2
index 40e5963..61c6b13 100644
@@ -117,9 +117,9 @@ void __init video_endboot(void)
                 const struct pci_dev *pdev;
                 u8 b = bus, df = devfn, sb;
 
-                spin_lock(&pcidevs_lock);
+                pcidevs_lock();
                 pdev = pci_get_pdev(0, bus, devfn);
-                spin_unlock(&pcidevs_lock);
+                pcidevs_unlock();
 
                 if ( !pdev ||
                      pci_conf_read16(0, bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
xen/include/xen/pci.h +4 -1
index a5aef55..b87571d 100644
@@ -94,7 +94,10 @@ struct pci_dev {
  * interrupt handling related (the mask bit register).
  */
 
-extern spinlock_t pcidevs_lock;
+void pcidevs_lock(void);
+void pcidevs_unlock(void);
+int pcidevs_is_locked(void);
+int pcidevs_trylock(void);
 
 bool_t pci_known_segment(u16 seg);
 bool_t pci_device_detect(u16 seg, u8 bus, u8 dev, u8 func);
Signature · 7 lines
1.9.1


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

Re: [PATCH 2/2] IOMMU/spinlock: Make the pcidevs_lock a recursive one

Quoted 10 lines · Quan Xu
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Suravee Suthikulpanit <[email protected]>
CC Aravind Gopalakrishnan <[email protected]>
CC Feng Wu <[email protected]>
CC Kevin Tian <[email protected]>
CC Dario Faggioli <[email protected]>

I've gone through the code, and it looks fine.

However, when trying to apply the patch, on top of this morning's staging, I got this:

[dario@Solace xen.git] $ patch -p1 < \[PATCH_2_2\]_IOMMU_spinlock\:_Make_the_pcidevs_lock_a_recursive_one.mbox patching file xen/arch/x86/domctl.c
Hunk #1 succeeded at 472 (offset 45 lines).
Hunk #2 succeeded at 497 (offset 45 lines).
patching file xen/arch/x86/hvm/vmsi.c
Hunk #1 succeeded at 388 with fuzz 1.
Hunk #2 succeeded at 446 with fuzz 1 (offset 3 lines).
patching file xen/arch/x86/irq.c
Hunk #1 succeeded at 1960 (offset 5 lines).
Hunk #2 succeeded at 2105 (offset 5 lines).
Hunk #3 succeeded at 2231 (offset 5 lines).
Hunk #4 succeeded at 2239 (offset 5 lines).
patching file xen/arch/x86/msi.c
patching file xen/arch/x86/pci.c
Hunk #1 succeeded at 88 (offset 6 lines).
patching file xen/arch/x86/physdev.c
patching file xen/common/sysctl.c
patching file xen/drivers/passthrough/amd/iommu_init.c
patching file xen/drivers/passthrough/amd/iommu_map.c
patching file xen/drivers/passthrough/amd/pci_amd_iommu.c
patching file xen/drivers/passthrough/pci.c
Hunk #17 succeeded at 1226 with fuzz 1.
Hunk #18 succeeded at 1262 (offset -6 lines).
Hunk #19 succeeded at 1291 (offset -6 lines).
Hunk #20 succeeded at 1340 (offset -6 lines).
Hunk #21 succeeded at 1364 (offset -6 lines).
Hunk #22 succeeded at 1401 (offset -6 lines).
Hunk #23 succeeded at 1416 (offset -6 lines).
Hunk #24 succeeded at 1471 (offset -6 lines).
Hunk #25 succeeded at 1490 (offset -6 lines).
Hunk #26 succeeded at 1625 (offset -6 lines).
patching file xen/drivers/passthrough/vtd/iommu.c
Hunk #1 succeeded at 1282 (offset -4 lines).
Hunk #2 succeeded at 1424 (offset -4 lines).
Hunk #3 succeeded at 1506 (offset -4 lines).
Hunk #4 succeeded at 1816 (offset -4 lines).
Hunk #5 succeeded at 1881 (offset -4 lines).
Hunk #6 succeeded at 2109 (offset -4 lines).
Hunk #7 succeeded at 2123 (offset -4 lines).
patching file xen/drivers/video/vga.c
patching file xen/include/xen/pci.h

And, when building:

gcc -O2 -fomit-frame-pointer -m64 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable -Wno-unused-local-typedefs   -DNDEBUG -I/home/SOURCES/xen/xen/xen.git/xen/include -I/home/SOURCES/xen/xen/xen.git/xen/include/asm-x86/mach-generic -I/home/SOURCES/xen/xen/xen.git/xen/include/asm-x86/mach-default '-D__OBJECT_LABEL__=drivers$passthrough$vtd$intremap.o' -msoft-float -fno-stack-protector -fno-exceptions -Wnested-externs -DHAVE_GAS_VMX -DHAVE_GAS_EPT -DHAVE_GAS_FSGSBASE -U__OBJECT_LABEL__ -DHAVE_GAS_QUOTED_SYM '-D__OBJECT_LABEL__=drivers/passthrough/vtd/intremap.o' -mno-red-zone -mno-sse -fpic -fno-asynchronous-unwind-tables -DGCC_HAS_VISIBILITY_ATTRIBUTE -nostdinc -fno-builtin -fno-common -Werror -Wredundant-decls -Wno-pointer-arith -pipe -g -D__XEN__ -include /home/SOURCES/xen/xen/xen.git/xen/include/xen/config.h '-D__OBJECT_FILE__="intremap.o"' -DPERF_COUNTERS -DPERF_ARRAYS -MMD -MF ./.intremap.o.d -c intremap.c -o intremap.o In file included from /home/SOURCES/xen/xen/xen.git/xen/include/xen/bitmap.h:6:0,
                 from /home/SOURCES/xen/xen/xen.git/xen/include/xen/cpumask.h:78,
                 from /home/SOURCES/xen/xen/xen.git/xen/include/xen/irq.h:4,
                 from intremap.c:20:
intremap.c: In function 'pi_update_irte':
intremap.c:987:27: error: passing argument 1 of '_spin_is_locked' from incompatible pointer type [-Werror]
     ASSERT(spin_is_locked(&pcidevs_lock));
                           ^
/home/SOURCES/xen/xen/xen.git/xen/include/xen/lib.h:35:35: note: in definition of macro 'ASSERT'
 #define ASSERT(p) do { if ( 0 && (p) ) {} } while (0)
                                   ^
intremap.c:987:12: note: in expansion of macro 'spin_is_locked'
     ASSERT(spin_is_locked(&pcidevs_lock));
            ^
In file included from /home/SOURCES/xen/xen/xen.git/xen/include/xen/rcupdate.h:35:0,
                 from /home/SOURCES/xen/xen/xen.git/xen/include/xen/irq.h:5,
                 from intremap.c:20:
/home/SOURCES/xen/xen/xen.git/xen/include/xen/spinlock.h:163:5: note: expected 'struct spinlock_t *' but argument is of type 'void (*)(void)'
 int _spin_is_locked(spinlock_t *lock);

So, I think a refresh is necessary.

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

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

author
#7 lore raw

Re: [PATCH 2/2] IOMMU/spinlock: Make the pcidevs_lock a recursive one

Quoted 11 lines · On March 08, 2016 8:29pm, <[email protected]> wrote:
Quoted 10 lines · Quan Xu
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Suravee Suthikulpanit <[email protected]>
CC Aravind Gopalakrishnan <[email protected]>
CC Feng Wu <[email protected]>
CC Kevin Tian <[email protected]>
CC Dario Faggioli <[email protected]>
Quoted 5 lines

I've gone through the code, and it looks fine.

However, when trying to apply the patch, on top of this morning's staging, I got this:

Oh, sorry, it is not against this morning's staging.
I would try to send out patch against this morning's staging soon. Thanks.

-Quan

Quoted 92 lines

[dario@Solace xen.git] $ patch -p1 < \[PATCH_2_2\]_IOMMU_spinlock\:_Make_the_pcidevs_lock_a_recursive_one. mbox
patching file xen/arch/x86/domctl.c
Hunk #1 succeeded at 472 (offset 45 lines).
Hunk #2 succeeded at 497 (offset 45 lines).
patching file xen/arch/x86/hvm/vmsi.c
Hunk #1 succeeded at 388 with fuzz 1.
Hunk #2 succeeded at 446 with fuzz 1 (offset 3 lines).
patching file xen/arch/x86/irq.c
Hunk #1 succeeded at 1960 (offset 5 lines).
Hunk #2 succeeded at 2105 (offset 5 lines).
Hunk #3 succeeded at 2231 (offset 5 lines).
Hunk #4 succeeded at 2239 (offset 5 lines).
patching file xen/arch/x86/msi.c
patching file xen/arch/x86/pci.c
Hunk #1 succeeded at 88 (offset 6 lines).
patching file xen/arch/x86/physdev.c
patching file xen/common/sysctl.c
patching file xen/drivers/passthrough/amd/iommu_init.c
patching file xen/drivers/passthrough/amd/iommu_map.c
patching file xen/drivers/passthrough/amd/pci_amd_iommu.c patching file xen/drivers/passthrough/pci.c Hunk #17 succeeded at 1226 with fuzz 1.
Hunk #18 succeeded at 1262 (offset -6 lines).
Hunk #19 succeeded at 1291 (offset -6 lines).
Hunk #20 succeeded at 1340 (offset -6 lines).
Hunk #21 succeeded at 1364 (offset -6 lines).
Hunk #22 succeeded at 1401 (offset -6 lines).
Hunk #23 succeeded at 1416 (offset -6 lines).
Hunk #24 succeeded at 1471 (offset -6 lines).
Hunk #25 succeeded at 1490 (offset -6 lines).
Hunk #26 succeeded at 1625 (offset -6 lines).
patching file xen/drivers/passthrough/vtd/iommu.c
Hunk #1 succeeded at 1282 (offset -4 lines).
Hunk #2 succeeded at 1424 (offset -4 lines).
Hunk #3 succeeded at 1506 (offset -4 lines).
Hunk #4 succeeded at 1816 (offset -4 lines).
Hunk #5 succeeded at 1881 (offset -4 lines).
Hunk #6 succeeded at 2109 (offset -4 lines).
Hunk #7 succeeded at 2123 (offset -4 lines).
patching file xen/drivers/video/vga.c
patching file xen/include/xen/pci.h

And, when building:

gcc -O2 -fomit-frame-pointer -m64 -fno-strict-aliasing -std=gnu99 -Wall

(quoted diff) +0 -5
-Wstrict-prototypes -Wdeclaration-after-statement
-Wno-unused-but-set-variable -Wno-unused-local-typedefs   -DNDEBUG
-I/home/SOURCES/xen/xen/xen.git/xen/include
-I/home/SOURCES/xen/xen/xen.git/xen/include/asm-x86/mach-generic
-I/home/SOURCES/xen/xen/xen.git/xen/include/asm-x86/mach-default

'-D__OBJECT_LABEL__=drivers$passthrough$vtd$intremap.o' -msoft-float

(quoted diff) +0 -3
-fno-stack-protector -fno-exceptions -Wnested-externs -DHAVE_GAS_VMX
-DHAVE_GAS_EPT -DHAVE_GAS_FSGSBASE -U__OBJECT_LABEL__
-DHAVE_GAS_QUOTED_SYM

'-D__OBJECT_LABEL__=drivers/passthrough/vtd/intremap.o' -mno-red-zone

(quoted diff) +0 -3
-mno-sse -fpic -fno-asynchronous-unwind-tables
-DGCC_HAS_VISIBILITY_ATTRIBUTE -nostdinc -fno-builtin -fno-common
-Werror -Wredundant-decls -Wno-pointer-arith -pipe -g -D__XEN__ -include

/home/SOURCES/xen/xen/xen.git/xen/include/xen/config.h '-D__OBJECT_FILE__="intremap.o"' -DPERF_COUNTERS -DPERF_ARRAYS -MMD -MF ./.intremap.o.d -c intremap.c -o intremap.o In file included from /home/SOURCES/xen/xen/xen.git/xen/include/xen/bitmap.h:6:0, from /home/SOURCES/xen/xen/xen.git/xen/include/xen/cpumask.h:78, from /home/SOURCES/xen/xen/xen.git/xen/include/xen/irq.h:4,
                 from intremap.c:20:
intremap.c: In function 'pi_update_irte':
intremap.c:987:27: error: passing argument 1 of '_spin_is_locked' from incompatible pointer type [-Werror] ASSERT(spin_is_locked(&pcidevs_lock));
                           ^ /home/SOURCES/xen/xen/xen.git/xen/include/xen/lib.h:35:35: note: in definition of macro 'ASSERT'
 #define ASSERT(p) do { if ( 0 && (p) ) {} } while (0)
                                   ^
intremap.c:987:12: note: in expansion of macro 'spin_is_locked' ASSERT(spin_is_locked(&pcidevs_lock));
            ^
In file included from /home/SOURCES/xen/xen/xen.git/xen/include/xen/rcupdate.h:35:0, from /home/SOURCES/xen/xen/xen.git/xen/include/xen/irq.h:5,
                 from intremap.c:20:
/home/SOURCES/xen/xen/xen.git/xen/include/xen/spinlock.h:163:5: note:
expected 'struct spinlock_t *' but argument is of type 'void (*)(void)' int _spin_is_locked(spinlock_t *lock);

So, I think a refresh is necessary.

Quoted 7 lines

Regards,
Dario
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

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

#8 lore raw

Re: [PATCH 2/2] IOMMU/spinlock: Make the pcidevs_lock a recursive one

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 08.03.16 at 13:39, <[email protected]> wrote:
Quoted 11 lines · On March 08, 2016 8:29pm, <[email protected]> wrote:
Quoted 10 lines · Quan Xu
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Suravee Suthikulpanit <[email protected]>
CC Aravind Gopalakrishnan <[email protected]>
CC Feng Wu <[email protected]>
CC Kevin Tian <[email protected]>
CC Dario Faggioli <[email protected]>
Quoted 7 lines
Quoted 5 lines

I've gone through the code, and it looks fine.

However, when trying to apply the patch, on top of this morning's staging, I got this:

Oh, sorry, it is not against this morning's staging.
I would try to send out patch against this morning's staging soon. Thanks.

Well, with e.g.

Quoted 9 lines
Quoted 9 lines

[dario@Solace xen.git] $ patch -p1 < \[PATCH_2_2\]_IOMMU_spinlock\:_Make_the_pcidevs_lock_a_recursive_one. mbox
patching file xen/arch/x86/domctl.c
Hunk #1 succeeded at 472 (offset 45 lines).
Hunk #2 succeeded at 497 (offset 45 lines).
patching file xen/arch/x86/hvm/vmsi.c
Hunk #1 succeeded at 388 with fuzz 1.
Hunk #2 succeeded at 446 with fuzz 1 (offset 3 lines).

... this it must have been quite old a tree - this file didn't change in the last 4 months. I consider it rather unfriendly to post such a patch without RFC tag, and without stating that it's against a stale tree. Was the recent v6 of the 5-patch series this way too? If so, I'm glad I didn't spend time looking at it yet.

Jan

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

author
#9 lore raw

Re: [PATCH 2/2] IOMMU/spinlock: Make the pcidevs_lock a recursive one

Quoted 35 lines · On March 08, 2016 9:49pm, <[email protected]> wrote:
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 08.03.16 at 13:39, <[email protected]> wrote:
Quoted 11 lines · On March 08, 2016 8:29pm, <[email protected]> wrote:
Quoted 10 lines · Quan Xu
CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Andrew Cooper <[email protected]>
CC Suravee Suthikulpanit <[email protected]>
CC Aravind Gopalakrishnan <[email protected]>
CC Feng Wu <[email protected]>
CC Kevin Tian <[email protected]>
CC Dario Faggioli <[email protected]>
Quoted 8 lines
Quoted 6 lines

I've gone through the code, and it looks fine.

However, when trying to apply the patch, on top of this morning's staging, I got
this:

Oh, sorry, it is not against this morning's staging.
I would try to send out patch against this morning's staging soon. Thanks.

Well, with e.g.

Quoted 2 lines
Quoted 2 lines

[dario@Solace xen.git] $ patch -p1 <

\[PATCH_2_2\]_IOMMU_spinlock\:_Make_the_pcidevs_lock_a_recursive_one.

Quoted 7 lines
Quoted 7 lines

mbox
patching file xen/arch/x86/domctl.c
Hunk #1 succeeded at 472 (offset 45 lines).
Hunk #2 succeeded at 497 (offset 45 lines).
patching file xen/arch/x86/hvm/vmsi.c Hunk #1 succeeded at 388 with fuzz 1.
Hunk #2 succeeded at 446 with fuzz 1 (offset 3 lines).

Quoted 4 lines

... this it must have been quite old a tree - this file didn't change in the last 4 months. I consider it rather unfriendly to post such a patch without RFC tag, and without stating that it's against a stale tree. Was the recent v6 of the 5-patch series this way too?

Yes,
sorry, I didn't rebase since from v1. :(:(
I will try to rebase against current staging and send out new patch sets.

Quan

Quoted 1 line

If so, I'm glad I didn't spend time looking at it yet.

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