xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Make the pcidevs_lock a recursive one
@ 2016-03-09  3:08 Quan Xu
  2016-03-09  3:08 ` [PATCH v2 1/2] IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization Quan Xu
  2016-03-09  3:08 ` [PATCH v2 2/2] IOMMU/spinlock: Make the pcidevs_lock a recursive one Quan Xu
  0 siblings, 2 replies; 17+ messages in thread
From: Quan Xu @ 2016-03-09  3:08 UTC (permalink / raw)
  To: xen-devel
  Cc: Kevin Tian, Feng Wu, Jan Beulich, Andrew Cooper, Dario Faggioli,
	Suravee Suthikulpanit, Quan Xu, Keir Fraser

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 VT-d Device-TLB
flush timed out.

In detail:
1. Fix a bug found in AMD IOMMU initialization.

  When iommu_setup() is called in __start_xen(), interrupts have
  already been enabled, and nothing disables (without reenabling)
  them again in the path that leads to calling
  set_iommu_interrupt_handler(). There's therefore no risk of them
  being disabled and needing remaining so, and hence no need for
  saving and restoring the flags. This means that, even if interrupt
  would need to be disabled when taking pcidevs_lock, spin_lock_irq()
  and spin_unlock_irq() could be used.

  Inside set_iommu_interrupt_handler(), pcidevs_lock serializes calls
  to pci_get_pdev(), which does not require interrupts to be disabled
  during its execution. In fact, pcidevs_lock is always (except for
  this case) taken without disabling interrupts, and disabling them in
  this case would make the BUG_ON() in check_lock() trigger, if it
  wasn't for the fact that spinlock debugging checks are still
  disabled, during initialization, when iommu_setup() (which then end
  up calling set_iommu_interrupt_handler()) is called.

  In order to fix this, we can use just plain spin_lock() and spin_unlock(),
  instead of spin_lock_irqsave() and spin_unlock_irqrestore().

2.  Make the pcidevs_lock a recursive one.

CC: Keir Fraser <keir@xen.org>
CC: Jan Beulich <jbeulich@suse.com>
CC: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
CC: Feng Wu <feng.wu@intel.com>
CC: Kevin Tian <kevin.tian@intel.com>
CC: Dario Faggioli <dario.faggioli@citrix.com>

--Changes in v2:
 * Enhance patch1/2 changelog.
 * Rebase against 1bd52e1fd66c4.


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/intremap.c      |  2 +-
 xen/drivers/passthrough/vtd/iommu.c         | 14 ++---
 xen/drivers/video/vga.c                     |  4 +-
 xen/include/xen/pci.h                       |  5 +-
 15 files changed, 109 insertions(+), 87 deletions(-)

-- 
1.9.1


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

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization.
@ 2016-03-09 12:18 Xu, Quan
  0 siblings, 0 replies; 17+ messages in thread
From: Xu, Quan @ 2016-03-09 12:18 UTC (permalink / raw)
  To: Jan Beulich; +Cc: dario.faggioli, Tian, Kevin, suravee.suthikulpanit, xen-devel

On March 09, 2016 6:10pm, <jbeulich@suse.com> wrote:
> >>> "Xu, Quan" <quan.xu@intel.com> 03/09/16 8:32 AM >>>
> >On March 09, 2016 1:19pm, <Tian, Kevin> wrote:
> >> > Inside set_iommu_interrupt_handler(), pcidevs_lock serializes calls
> >> > to pci_get_pdev(), which does not require interrupts to be disabled
> >> > during its execution. In fact, pcidevs_lock is always (except for
> >> > this
> >> > case) taken without disabling interrupts, and disabling them in
> >> > this case would make the BUG_ON() in check_lock() trigger, if it
> >> > wasn't for the fact that spinlock debugging checks are still
> >> > disabled, during initialization, when iommu_setup() (which then end
> >> > up calling
> >> > set_iommu_interrupt_handler()) is called.
> >>
> >> The key problem is that we need consistent lock usage in all places
> >> (either all in IRQ-safe or all in IRQ-unsafe), regardless of whether
> >> check_lock is activated or not (which is just a debug method to help identify
> such inconsistency problem).
> >
> >IMO, this is not the key problem,  __Wait for Dario's / Jan's opinions__.
> 
> The inconsistency is one way of look at the problem, so with that it is kind of
> "key".
> 

Thanks for correcting me. 
Before this email, I really think inconsistency is one of the problem, and
The key problem is the case would make the BUG_ON() in check_lock() trigger. :(

> >> However there remains an
> >> exception in AMD IOMMU code, where the lock is acquired with
> >> interrupt disabled. This inconsistency can lead to deadlock.
> >>
> >> The fix is straightforward to use spin_lock instead. Also interrupt
> >> has been enabled when this function is invoked, so we're sure
> >> consistency around pcidevs_lock can be guaranteed after this fix.
> >
> >I really appreciate you send out a revised one, but I think it is not only for
> consistency.
> >__Wait for Dario's / Jan's opinions__.
> >
> >To be honest, to me, __my_changlog_ is complicated.
> 
> I think Kevin's text above is okay. Perhaps weaken the "can lead to a deadlock"
> slightly, because that's just a theoretical concern, not one that's possible in
> practice on that code path.

Thanks.
I would use Kevin's text above and change 'can lead to a deadlock' to 'might lead to a deadlock' as changelog.

Quan


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

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2016-03-10  5:36 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-09  3:08 [PATCH v2 0/2] Make the pcidevs_lock a recursive one Quan Xu
2016-03-09  3:08 ` [PATCH v2 1/2] IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization Quan Xu
2016-03-09  5:19   ` Tian, Kevin
2016-03-09  7:31     ` Xu, Quan
2016-03-09 10:09       ` Jan Beulich
2016-03-09 10:24       ` Dario Faggioli
2016-03-09 12:52         ` Xu, Quan
2016-03-09 13:19           ` Dario Faggioli
2016-03-09 13:46             ` Xu, Quan
2016-03-09 13:55               ` Jan Beulich
2016-03-09 14:45                 ` Dario Faggioli
2016-03-10  5:36                   ` Xu, Quan
2016-03-10  3:21                 ` Xu, Quan
2016-03-09  3:08 ` [PATCH v2 2/2] IOMMU/spinlock: Make the pcidevs_lock a recursive one Quan Xu
2016-03-09  5:21   ` Tian, Kevin
2016-03-09  5:50     ` Xu, Quan
2016-03-09 12:18 [PATCH v2 1/2] IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization Xu, Quan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).