public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: konrad@kernel.org
To: xen-devel@lists.xenproject.org, david.vrabel@citrix.com,
	boris.ostrovsky@oracle.com, linux-kernel@vger.kernel.org
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [PATCH v3 2/7] xen/pciback: Don't deadlock when unbinding.
Date: Tue,  8 Jul 2014 14:58:24 -0400	[thread overview]
Message-ID: <1404845909-13563-3-git-send-email-konrad@kernel.org> (raw)
In-Reply-To: <1404845909-13563-1-git-send-email-konrad@kernel.org>

From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

As commit 0a9fd0152929db372ff61b0d6c280fdd34ae8bdb
'xen/pciback: Document the entry points for 'pcistub_put_pci_dev''
explained there are four entry points in this function.
Two of them are when the user fiddles in the SysFS to
unbind a device which might be in use by a guest or not.

Both 'unbind' states will cause a deadlock as the the PCI lock has
already been taken, which then pci_device_reset tries to take.

We can omit this by detecting this and using the  'already
locked' variant of the pci_device_reset - but we don't need to
do either as that is done much later when the PCIback device
structures are destroyed. As such lets use the 'try_reset'
variant. That means we still end up FLR-ing the device in
between swapping it from one guest to another. The FLR when
'unbind' part is still taken care by pci_device_reset.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 drivers/xen/xen-pciback/pci_stub.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c
index 8a69a9f..b1fb099 100644
--- a/drivers/xen/xen-pciback/pci_stub.c
+++ b/drivers/xen/xen-pciback/pci_stub.c
@@ -277,10 +277,15 @@ void pcistub_put_pci_dev(struct pci_dev *dev)
 	 * (so it's ready for the next domain)
 	 */
 
-	/* This is OK - we are running from workqueue context
-	 * and want to inhibit the user from fiddling with 'reset'
+	/* We might be holding the PCI lock (see comment at the top of the
+	 * function) - as such try lock and if we can't then don't worry -
+	 * as either:
+	 *  - we are 'unbind' in which case 'pcistub_device_release' gets
+	 *    called which does the locked version of this.
+	 *  - the toolstack has the smarts to do it and has done the
+	 *    reset on SysFS before assigning this device to another guest.
 	 */
-	pci_reset_function(dev);
+	pci_try_reset_function(dev);
 	pci_restore_state(dev);
 
 	/* This disables the device. */
-- 
1.7.7.6


  parent reply	other threads:[~2014-07-08 17:57 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-08 18:58 [PATCH] Xen PCIbackend support for slot and bus reset (v3) konrad
2014-07-08 18:58 ` [PATCH v3 1/7] xen-pciback: Document the various parameters and attributes in SysFS konrad
2014-07-08 18:18   ` [Xen-devel] " Andrew Cooper
2014-07-09 12:17   ` David Vrabel
2014-07-09 13:59     ` Konrad Rzeszutek Wilk
2014-07-09 14:05       ` Andrew Cooper
2014-07-09 14:13         ` Konrad Rzeszutek Wilk
2014-07-09 14:22           ` Andrew Cooper
2014-07-09 14:25             ` Konrad Rzeszutek Wilk
2014-07-09 14:45               ` David Vrabel
2014-07-09 14:47                 ` Konrad Rzeszutek Wilk
2014-07-09 14:57                   ` David Vrabel
2014-07-09 15:11                     ` Konrad Rzeszutek Wilk
2014-07-08 18:58 ` konrad [this message]
2014-07-09 12:21   ` [PATCH v3 2/7] xen/pciback: Don't deadlock when unbinding David Vrabel
2014-07-09 14:01     ` Konrad Rzeszutek Wilk
2014-07-08 18:58 ` [PATCH v3 3/7] xen/pciback: Move the FLR code to a function konrad
2014-07-08 18:58 ` [PATCH v3 4/7] xen/pciback: Implement PCI reset slot or bus with 'do_flr' SysFS attribute konrad
2014-07-08 18:02   ` David Vrabel
2014-07-08 18:46     ` Konrad Rzeszutek Wilk
2014-07-08 19:28       ` Konrad Rzeszutek Wilk
2014-07-09 12:32       ` David Vrabel
2014-07-09 14:11         ` [Xen-devel] " David Vrabel
2014-07-09 14:12         ` Konrad Rzeszutek Wilk
2014-07-09 14:26           ` David Vrabel
2014-07-09 15:07             ` Konrad Rzeszutek Wilk
2014-07-08 18:17   ` [Xen-devel] " Andrew Cooper
2014-07-08 18:58 ` [PATCH v3 5/7] xen/pciback: Include the domain id if removing the device whilst still in use konrad
2014-07-09 12:34   ` David Vrabel
2014-07-08 18:58 ` [PATCH v3 6/7] xen/pciback: Print out the domain owning the device konrad
2014-07-09 13:04   ` David Vrabel
2014-07-08 18:58 ` [PATCH v3 7/7] xen/pciback: Remove tons of dereferences konrad
2014-07-08 19:15 ` [Xen-devel] [PATCH] Xen PCIbackend support for slot and bus reset (v3) Sander Eikelenboom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404845909-13563-3-git-send-email-konrad@kernel.org \
    --to=konrad@kernel.org \
    --cc=boris.ostrovsky@oracle.com \
    --cc=david.vrabel@citrix.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox