From: Bjorn Helgaas <bhelgaas@google.com>
To: Joerg Roedel <joro@8bytes.org>
Cc: Gregor Dick <gdick@solarflare.com>,
linux-pci@vger.kernel.org, iommu@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, Joerg Roedel <jroedel@suse.de>,
stable@kernel.org
Subject: Re: [PATCH] PCI: Don't use SR-IOV lock for ATS
Date: Thu, 16 Jul 2015 18:08:31 -0500 [thread overview]
Message-ID: <20150716230831.GF25591@google.com> (raw)
In-Reply-To: <1434617420-18313-1-git-send-email-joro@8bytes.org>
Hi Joerg,
On Thu, Jun 18, 2015 at 10:50:20AM +0200, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel@suse.de>
>
> The use of the SR-IOV lock for ATS causes a dead-lock in the
> AMD-IOMMU driver when virtual functions are added that have
> an ATS capability.
>
> The problem is that the VFs will be added to the bus with
> the SR-IOV lock held. While added to the bus the
> device-notifiers will run and invoke AMD IOMMU code, which
> itself will assign the device to a domain try to enable ATS.
> When it calls pci_enable_ats() this will dead-lock.
I'm trying to connect the dots here. What's the notifier that invokes the
AMD IOMMU code? I thought it would be a BUS_NOTIFY_ADD_DEVICE notifier,
but I haven't found it yet.
> Fix this by introducing a global ats_lock. ATS enablement
> and disablement isn't in any fast-path, so a global lock
> shouldn't hurt here.
>
> Cc: stable@kernel.org
> Reported-by: Gregor Dick <gdick@solarflare.com>
> Signed-off-by: Joerg Roedel <jroedel@suse.de>
> ---
> drivers/pci/ats.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c
> index a8099d4..f0c3c6f 100644
> --- a/drivers/pci/ats.c
> +++ b/drivers/pci/ats.c
> @@ -17,6 +17,8 @@
>
> #include "pci.h"
>
> +static DEFINE_MUTEX(ats_lock);
> +
> static int ats_alloc_one(struct pci_dev *dev, int ps)
> {
> int pos;
> @@ -67,7 +69,7 @@ int pci_enable_ats(struct pci_dev *dev, int ps)
> if (dev->is_physfn || dev->is_virtfn) {
> struct pci_dev *pdev = dev->is_physfn ? dev : dev->physfn;
>
> - mutex_lock(&pdev->sriov->lock);
> + mutex_lock(&ats_lock);
> if (pdev->ats)
> rc = pdev->ats->stu == ps ? 0 : -EINVAL;
> else
> @@ -75,7 +77,7 @@ int pci_enable_ats(struct pci_dev *dev, int ps)
>
> if (!rc)
> pdev->ats->ref_cnt++;
> - mutex_unlock(&pdev->sriov->lock);
> + mutex_unlock(&ats_lock);
The mutex was originally added by e277d2fc79d6 ("PCI: handle Virtual
Function ATS enabling"). I assume the purpose is to protect the
ats_alloc_one().
This seems overly complicated. I think we can simplify this by doing some
of this work earlier, in pci_init_capabilities(). I'll work this up and
you can see what you think.
Bjorn
> if (rc)
> return rc;
> }
> @@ -116,11 +118,11 @@ void pci_disable_ats(struct pci_dev *dev)
> if (dev->is_physfn || dev->is_virtfn) {
> struct pci_dev *pdev = dev->is_physfn ? dev : dev->physfn;
>
> - mutex_lock(&pdev->sriov->lock);
> + mutex_lock(&ats_lock);
> pdev->ats->ref_cnt--;
> if (!pdev->ats->ref_cnt)
> ats_free_one(pdev);
> - mutex_unlock(&pdev->sriov->lock);
> + mutex_unlock(&ats_lock);
> }
>
> if (!dev->is_physfn)
> --
> 1.9.1
>
next prev parent reply other threads:[~2015-07-16 23:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-18 8:50 [PATCH] PCI: Don't use SR-IOV lock for ATS Joerg Roedel
2015-06-18 8:50 ` Joerg Roedel
2015-07-16 23:08 ` Bjorn Helgaas [this message]
2015-07-17 7:51 ` Joerg Roedel
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=20150716230831.GF25591@google.com \
--to=bhelgaas@google.com \
--cc=gdick@solarflare.com \
--cc=iommu@lists.linux-foundation.org \
--cc=joro@8bytes.org \
--cc=jroedel@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=stable@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.