From: Alex Williamson <alex.williamson@redhat.com>
To: david@gibson.dropbear.id.au, aik@ozlabs.ru, dwmw2@infradead.org
Cc: kvm@vger.kernel.org, iommu@lists.linux-foundation.org,
qemu-devel@nongnu.org, alex.williamson@redhat.com,
joerg.roedel@amd.com, linux-kernel@vger.kernel.org
Subject: [Qemu-devel] [PATCH 2/2] intel-iommu: Basic isolation group provider support
Date: Mon, 12 Mar 2012 16:33:02 -0600 [thread overview]
Message-ID: <20120312223302.30321.91922.stgit@bling.home> (raw)
In-Reply-To: <20120312220109.30321.83419.stgit@bling.home>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
drivers/iommu/intel-iommu.c | 70 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index c9c6053..2e5a709 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -42,6 +42,7 @@
#include <linux/dmi.h>
#include <linux/pci-ats.h>
#include <linux/memblock.h>
+#include <linux/isolation.h>
#include <asm/cacheflush.h>
#include <asm/iommu.h>
@@ -3597,6 +3598,73 @@ static struct notifier_block device_nb = {
.notifier_call = device_notifier,
};
+static int isolation_notifier(struct notifier_block *nb,
+ unsigned long action, void *data)
+{
+ struct device *dev = data;
+ struct pci_dev *pdev = to_pci_dev(dev);
+
+ if (iommu_no_mapping(dev) ||
+ !device_to_iommu(pci_domain_nr(pdev->bus),
+ pdev->bus->number, pdev->devfn))
+ return NOTIFY_DONE;
+
+
+ if (action == ISOLATION_NOTIFY_ADD_DEVICE) {
+ struct device *dma_dev = NULL;
+ struct pci_dev *bridge = pci_find_upstream_pcie_bridge(pdev);
+ struct isolation_group *group;
+
+ if (bridge) {
+ if (pci_is_pcie(bridge)) {
+ struct pci_dev *dma_pdev;
+ dma_pdev = pci_get_domain_bus_and_slot(
+ pci_domain_nr(pdev->bus),
+ bridge->subordinate->number, 0);
+ dma_dev = &dma_pdev->dev;
+ }
+
+ if (!dma_dev)
+ dma_dev = &bridge->dev;
+ } else
+ dma_dev = dev;
+
+ group = to_isolation_group(dma_dev);
+
+ if (!group) {
+ group = isolation_create_group();
+ if (IS_ERR(group))
+ return NOTIFY_BAD;
+
+ isolation_group_set_iommu_ops(group, &intel_iommu_ops);
+
+ if (dma_dev != dev)
+ isolation_group_add_dev(group, dma_dev);
+ }
+
+ if (isolation_group_add_dev(group, dev))
+ return NOTIFY_BAD;
+
+ return NOTIFY_STOP;
+
+ } else if (action == ISOLATION_NOTIFY_DEL_DEVICE) {
+ struct isolation_group *group = to_isolation_group(dev);
+
+ if (isolation_group_del_dev(dev))
+ return NOTIFY_BAD;
+
+ isolation_free_group(group);
+
+ return NOTIFY_STOP;
+ }
+
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block isolation_nb = {
+ .notifier_call = isolation_notifier,
+};
+
int __init intel_iommu_init(void)
{
int ret = 0;
@@ -3663,6 +3731,8 @@ int __init intel_iommu_init(void)
bus_register_notifier(&pci_bus_type, &device_nb);
+ isolation_register_notifier(&pci_bus_type, &isolation_nb);
+
intel_iommu_enabled = 1;
return 0;
next prev parent reply other threads:[~2012-03-12 22:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-12 22:32 [Qemu-devel] [PATCH 0/2] RFC Isolation API Alex Williamson
2012-03-12 22:32 ` [Qemu-devel] [PATCH 1/2] Isolation groups Alex Williamson
2012-03-13 14:33 ` David Gibson
2012-03-13 16:49 ` Alex Williamson
2012-03-14 9:58 ` David Gibson
2012-03-15 20:15 ` Alex Williamson
2012-03-16 3:45 ` David Gibson
2012-03-16 19:31 ` Alex Williamson
2012-03-17 4:57 ` David Gibson
2012-03-21 21:12 ` Alex Williamson
2012-03-27 5:14 ` David Gibson
2012-03-27 19:34 ` Alex Williamson
2012-03-30 4:19 ` David Gibson
2012-03-12 22:33 ` Alex Williamson [this message]
2012-03-13 13:57 ` [Qemu-devel] [PATCH 0/2] RFC Isolation API David Gibson
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=20120312223302.30321.91922.stgit@bling.home \
--to=alex.williamson@redhat.com \
--cc=aik@ozlabs.ru \
--cc=david@gibson.dropbear.id.au \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=joerg.roedel@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).