linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Auger <eric.auger@redhat.com>
To: eric.auger.pro@gmail.com, eric.auger@redhat.com,
	iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
	joro@8bytes.org, alex.williamson@redhat.com,
	jacob.jun.pan@linux.intel.com, yi.l.liu@linux.intel.com,
	jean-philippe.brucker@arm.com, will.deacon@arm.com,
	robin.murphy@arm.com
Cc: kevin.tian@intel.com, ashok.raj@intel.com, marc.zyngier@arm.com,
	christoffer.dall@arm.com, peter.maydell@linaro.org,
	vincent.stehle@arm.com
Subject: [PATCH v5 10/22] iommu/arm-smmu-v3: Link domains and devices
Date: Fri, 15 Mar 2019 17:08:54 +0100	[thread overview]
Message-ID: <20190315160906.12900-11-eric.auger@redhat.com> (raw)
In-Reply-To: <20190315160906.12900-1-eric.auger@redhat.com>

From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>

When removing a mapping from a domain, we need to send an invalidation to
all devices that might have stored it in their Address Translation Cache
(ATC). In addition with SVM, we'll need to invalidate context descriptors
of all devices attached to a live domain.

Maintain a list of devices in each domain, protected by a spinlock. It is
updated every time we attach or detach devices to and from domains.

It needs to be a spinlock because we'll invalidate ATC entries from
within hardirq-safe contexts, but it may be possible to relax the read
side with RCU later.

Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
---
 drivers/iommu/arm-smmu-v3.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
index d3880010c6cf..ff998c967a0a 100644
--- a/drivers/iommu/arm-smmu-v3.c
+++ b/drivers/iommu/arm-smmu-v3.c
@@ -594,6 +594,11 @@ struct arm_smmu_device {
 struct arm_smmu_master_data {
 	struct arm_smmu_device		*smmu;
 	struct arm_smmu_strtab_ent	ste;
+
+	struct arm_smmu_domain		*domain;
+	struct list_head		list; /* domain->devices */
+
+	struct device			*dev;
 };
 
 /* SMMU private data for an IOMMU domain */
@@ -618,6 +623,9 @@ struct arm_smmu_domain {
 	};
 
 	struct iommu_domain		domain;
+
+	struct list_head		devices;
+	spinlock_t			devices_lock;
 };
 
 struct arm_smmu_option_prop {
@@ -1493,6 +1501,9 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type)
 	}
 
 	mutex_init(&smmu_domain->init_mutex);
+	INIT_LIST_HEAD(&smmu_domain->devices);
+	spin_lock_init(&smmu_domain->devices_lock);
+
 	return &smmu_domain->domain;
 }
 
@@ -1713,6 +1724,16 @@ static void arm_smmu_detach_dev(struct device *dev)
 {
 	struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
 	struct arm_smmu_master_data *master = fwspec->iommu_priv;
+	unsigned long flags;
+	struct arm_smmu_domain *smmu_domain = master->domain;
+
+	if (smmu_domain) {
+		spin_lock_irqsave(&smmu_domain->devices_lock, flags);
+		list_del(&master->list);
+		spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
+
+		master->domain = NULL;
+	}
 
 	master->ste.assigned = false;
 	arm_smmu_install_ste_for_dev(fwspec);
@@ -1722,6 +1743,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
 {
 	int ret = 0;
 	struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+	unsigned long flags;
 	struct arm_smmu_device *smmu;
 	struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
 	struct arm_smmu_master_data *master;
@@ -1757,6 +1779,11 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
 	}
 
 	ste->assigned = true;
+	master->domain = smmu_domain;
+
+	spin_lock_irqsave(&smmu_domain->devices_lock, flags);
+	list_add(&master->list, &smmu_domain->devices);
+	spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
 
 	if (smmu_domain->stage == ARM_SMMU_DOMAIN_BYPASS) {
 		ste->s1_cfg = NULL;
@@ -1883,6 +1910,7 @@ static int arm_smmu_add_device(struct device *dev)
 			return -ENOMEM;
 
 		master->smmu = smmu;
+		master->dev = dev;
 		fwspec->iommu_priv = master;
 	}
 
-- 
2.20.1


  parent reply	other threads:[~2019-03-15 16:10 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-15 16:08 [PATCH v5 00/22] SMMUv3 Nested Stage Setup Eric Auger
2019-03-15 16:08 ` [PATCH v5 01/22] driver core: add per device iommu param Eric Auger
2019-03-15 16:08 ` [PATCH v5 02/22] iommu: introduce device fault data Eric Auger
2019-03-15 16:08 ` [PATCH v5 03/22] iommu: introduce device fault report API Eric Auger
2019-03-15 16:08 ` [PATCH v5 04/22] iommu: Introduce attach/detach_pasid_table API Eric Auger
2019-03-15 16:08 ` [PATCH v5 05/22] iommu: Introduce cache_invalidate API Eric Auger
2019-03-15 18:37   ` Jacob Pan
2019-03-17 16:43     ` Auger Eric
2019-03-18 11:01       ` Jean-Philippe Brucker
2019-03-18 12:44         ` Auger Eric
2019-03-15 16:08 ` [PATCH v5 06/22] iommu: Introduce bind/unbind_guest_msi Eric Auger
2019-03-15 16:08 ` [PATCH v5 07/22] vfio: VFIO_IOMMU_ATTACH/DETACH_PASID_TABLE Eric Auger
2019-03-15 16:08 ` [PATCH v5 08/22] vfio: VFIO_IOMMU_CACHE_INVALIDATE Eric Auger
2019-03-15 16:08 ` [PATCH v5 09/22] vfio: VFIO_IOMMU_BIND/UNBIND_MSI Eric Auger
2019-03-15 16:08 ` Eric Auger [this message]
2019-03-15 16:08 ` [PATCH v5 11/22] iommu/arm-smmu-v3: Maintain a SID->device structure Eric Auger
2019-03-15 16:08 ` [PATCH v5 12/22] iommu/smmuv3: Get prepared for nested stage support Eric Auger
2019-03-15 16:08 ` [PATCH v5 13/22] iommu/smmuv3: Implement attach/detach_pasid_table Eric Auger
2019-03-15 16:08 ` [PATCH v5 14/22] iommu/smmuv3: Implement cache_invalidate Eric Auger
2019-03-15 16:08 ` [PATCH v5 15/22] dma-iommu: Implement NESTED_MSI cookie Eric Auger
2019-03-15 16:09 ` [PATCH v5 16/22] iommu/smmuv3: Implement bind/unbind_guest_msi Eric Auger
2019-03-15 16:09 ` [PATCH v5 17/22] iommu/smmuv3: Report non recoverable faults Eric Auger
2019-03-15 16:09 ` [PATCH v5 18/22] vfio-pci: Add a new VFIO_REGION_TYPE_NESTED region type Eric Auger
2019-03-15 16:09 ` [PATCH v5 19/22] vfio-pci: Register an iommu fault handler Eric Auger
2019-03-15 16:09 ` [PATCH v5 20/22] vfio_pci: Allow to mmap the fault queue Eric Auger
2019-03-15 16:09 ` [PATCH v5 21/22] vfio-pci: Add VFIO_PCI_DMA_FAULT_IRQ_INDEX Eric Auger
2019-03-15 16:09 ` [PATCH v5 22/22] vfio: Document nested stage control Eric Auger

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=20190315160906.12900-11-eric.auger@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=christoffer.dall@arm.com \
    --cc=eric.auger.pro@gmail.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=jean-philippe.brucker@arm.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=peter.maydell@linaro.org \
    --cc=robin.murphy@arm.com \
    --cc=vincent.stehle@arm.com \
    --cc=will.deacon@arm.com \
    --cc=yi.l.liu@linux.intel.com \
    /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).