From: Yijing Wang <wangyijing-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
To: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
Cc: Vinod Koul <vinod.koul-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
dmaengine-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Hanjun Guo <guohanjun-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>,
Bjorn Helgaas <bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
Dan Williams
<dan.j.williams-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
Subject: Re: [PATCH v2] IOMMU: enhance dmar to support device hotplug
Date: Wed, 5 Mar 2014 10:53:35 +0800 [thread overview]
Message-ID: <531691AF.2010604@huawei.com> (raw)
In-Reply-To: <20140304143158.GC2799-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
On 2014/3/4 22:31, Joerg Roedel wrote:
> On Thu, Nov 21, 2013 at 04:21:56PM +0800, Yijing Wang wrote:
>> @@ -3641,21 +3681,42 @@ static int device_notifier(struct notifier_block *nb,
>> struct device *dev = data;
>> struct pci_dev *pdev = to_pci_dev(dev);
>> struct dmar_domain *domain;
>> + struct dmar_device *dmar_dev;
>> + struct dmar_drhd_unit *drhd;
>>
>> - if (iommu_no_mapping(dev))
>> - return 0;
>> -
>> - domain = find_domain(pdev);
>> - if (!domain)
>> - return 0;
>> + switch (action) {
>> + case BUS_NOTIFY_ADD_DEVICE:
>> + for_each_drhd_unit(drhd)
>> + list_for_each_entry(dmar_dev, &drhd->devices, list)
>> + if (dmar_dev->segment == pci_domain_nr(pdev->bus)
>> + && dmar_dev->bus == pdev->bus->number
>> + && dmar_dev->devfn == pdev->devfn)
>> + dmar_dev->pdev = pci_dev_get(pdev);
>> + break;
>> + case BUS_NOTIFY_DEL_DEVICE:
>> + for_each_drhd_unit(drhd)
>> + list_for_each_entry(dmar_dev, &drhd->devices, list)
>> + if (dmar_dev->pdev == pdev) {
>> + pci_dev_put(pdev);
>> + dmar_dev->pdev = NULL;
>> + }
>
> How is that synchronized with other users of this dmar_dev structure.
> Could it happen that you drop the device reference while other parts of
> the driver still use it?
Hi Joerg,
Thanks for your review and comments!
We use original struct dmar_drhd_unit->devices to attach the pci device to specific DMAR,
eg. use dmar_find_matched_drhd_unit() to find the attached DMAR by pci_dev * pointer.
So if the related pci_dev was removed, I think we can safely set dmar_dev->pdev = NULL;
No pci device will use it again until the new pci device hot add.
One problem in this solution is PCI bus number maybe changed after device hotplug,
so use the bus,device,function id to update the dmar device scope maybe unreliable.
Jiang Liu also provide a solution to fix this problem by save device scope pathes,
I think that's a good idea.
link:http://lkml.org/lkml/2014/1/7/108
Thanks!
Yijing.
>
>
> Joerg
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
> .
>
--
Thanks!
Yijing
WARNING: multiple messages have this Message-ID (diff)
From: Yijing Wang <wangyijing@huawei.com>
To: Joerg Roedel <joro@8bytes.org>
Cc: Alex Williamson <alex.williamson@redhat.com>,
Bjorn Helgaas <bhelgaas@google.com>,
David Woodhouse <dwmw2@infradead.org>,
Vinod Koul <vinod.koul@intel.com>,
Dan Williams <dan.j.williams@intel.com>,
<dmaengine@vger.kernel.org>, <iommu@lists.linux-foundation.org>,
<linux-kernel@vger.kernel.org>, Hanjun Guo <guohanjun@huawei.com>
Subject: Re: [PATCH v2] IOMMU: enhance dmar to support device hotplug
Date: Wed, 5 Mar 2014 10:53:35 +0800 [thread overview]
Message-ID: <531691AF.2010604@huawei.com> (raw)
In-Reply-To: <20140304143158.GC2799@8bytes.org>
On 2014/3/4 22:31, Joerg Roedel wrote:
> On Thu, Nov 21, 2013 at 04:21:56PM +0800, Yijing Wang wrote:
>> @@ -3641,21 +3681,42 @@ static int device_notifier(struct notifier_block *nb,
>> struct device *dev = data;
>> struct pci_dev *pdev = to_pci_dev(dev);
>> struct dmar_domain *domain;
>> + struct dmar_device *dmar_dev;
>> + struct dmar_drhd_unit *drhd;
>>
>> - if (iommu_no_mapping(dev))
>> - return 0;
>> -
>> - domain = find_domain(pdev);
>> - if (!domain)
>> - return 0;
>> + switch (action) {
>> + case BUS_NOTIFY_ADD_DEVICE:
>> + for_each_drhd_unit(drhd)
>> + list_for_each_entry(dmar_dev, &drhd->devices, list)
>> + if (dmar_dev->segment == pci_domain_nr(pdev->bus)
>> + && dmar_dev->bus == pdev->bus->number
>> + && dmar_dev->devfn == pdev->devfn)
>> + dmar_dev->pdev = pci_dev_get(pdev);
>> + break;
>> + case BUS_NOTIFY_DEL_DEVICE:
>> + for_each_drhd_unit(drhd)
>> + list_for_each_entry(dmar_dev, &drhd->devices, list)
>> + if (dmar_dev->pdev == pdev) {
>> + pci_dev_put(pdev);
>> + dmar_dev->pdev = NULL;
>> + }
>
> How is that synchronized with other users of this dmar_dev structure.
> Could it happen that you drop the device reference while other parts of
> the driver still use it?
Hi Joerg,
Thanks for your review and comments!
We use original struct dmar_drhd_unit->devices to attach the pci device to specific DMAR,
eg. use dmar_find_matched_drhd_unit() to find the attached DMAR by pci_dev * pointer.
So if the related pci_dev was removed, I think we can safely set dmar_dev->pdev = NULL;
No pci device will use it again until the new pci device hot add.
One problem in this solution is PCI bus number maybe changed after device hotplug,
so use the bus,device,function id to update the dmar device scope maybe unreliable.
Jiang Liu also provide a solution to fix this problem by save device scope pathes,
I think that's a good idea.
link:http://lkml.org/lkml/2014/1/7/108
Thanks!
Yijing.
>
>
> Joerg
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
> .
>
--
Thanks!
Yijing
next prev parent reply other threads:[~2014-03-05 2:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-21 8:21 [PATCH v2] Enhance dmar to support device hotplug Yijing Wang
2013-11-21 8:21 ` Yijing Wang
[not found] ` <1385022116-228-1-git-send-email-wangyijing-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-11-21 8:21 ` [PATCH v2] IOMMU: enhance " Yijing Wang
2013-11-21 8:21 ` Yijing Wang
[not found] ` <1385022116-228-2-git-send-email-wangyijing-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-03-04 14:31 ` Joerg Roedel
2014-03-04 14:31 ` Joerg Roedel
[not found] ` <20140304143158.GC2799-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2014-03-05 2:53 ` Yijing Wang [this message]
2014-03-05 2:53 ` Yijing Wang
2013-12-10 17:03 ` [PATCH v2] Enhance " Don Dutile
2013-12-10 17:03 ` Don Dutile
[not found] ` <52A7495D.6010905-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-12-12 11:46 ` Yijing Wang
2013-12-12 11:46 ` Yijing Wang
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=531691AF.2010604@huawei.com \
--to=wangyijing-hv44wf8li93qt0dzr+alfa@public.gmane.org \
--cc=bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=dan.j.williams-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=dmaengine-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=guohanjun-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=vinod.koul-ral2JQCrhuEAvxtiuMwx3w@public.gmane.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.