linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
To: linux-pci@vger.kernel.org, devicetree@vger.kernel.org,
	linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	iommu@lists.linux-foundation.org
Cc: mark.rutland@arm.com, lorenzo.pieralisi@arm.com,
	will.deacon@arm.com, joro@8bytes.org, thunder.leizhen@huawei.com,
	rjw@rjwysocki.net, okaya@codeaurora.org, robh+dt@kernel.org,
	hanjun.guo@linaro.org, sudeep.holla@arm.com, bhelgaas@google.com,
	tn@semihalf.com, sunil.kovvuri@gmail.com, robin.murphy@arm.com,
	lenb@kernel.org
Subject: [PATCH 5/7] iommu/arm-smmu-v3: Link domains and devices
Date: Wed, 24 May 2017 19:01:41 +0100	[thread overview]
Message-ID: <20170524180143.19855-6-jean-philippe.brucker@arm.com> (raw)
In-Reply-To: <20170524180143.19855-1-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 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 | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
index 380969aa60d5..524e1b051962 100644
--- a/drivers/iommu/arm-smmu-v3.c
+++ b/drivers/iommu/arm-smmu-v3.c
@@ -630,6 +630,9 @@ 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 */
 };
 
 /* SMMU private data for an IOMMU domain */
@@ -654,6 +657,9 @@ struct arm_smmu_domain {
 	};
 
 	struct iommu_domain		domain;
+
+	struct list_head		devices;
+	spinlock_t			devices_lock;
 };
 
 struct arm_smmu_option_prop {
@@ -1407,6 +1413,9 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type)
 
 	mutex_init(&smmu_domain->init_mutex);
 	spin_lock_init(&smmu_domain->pgtbl_lock);
+	INIT_LIST_HEAD(&smmu_domain->devices);
+	spin_lock_init(&smmu_domain->devices_lock);
+
 	return &smmu_domain->domain;
 }
 
@@ -1609,7 +1618,17 @@ static void arm_smmu_install_ste_for_dev(struct iommu_fwspec *fwspec)
 
 static void arm_smmu_detach_dev(struct device *dev)
 {
+	unsigned long flags;
 	struct arm_smmu_master_data *master = dev->iommu_fwspec->iommu_priv;
+	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(dev->iommu_fwspec);
@@ -1618,6 +1637,7 @@ static void arm_smmu_detach_dev(struct device *dev)
 static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
 {
 	int ret = 0;
+	unsigned long flags;
 	struct arm_smmu_device *smmu;
 	struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
 	struct arm_smmu_master_data *master;
@@ -1653,6 +1673,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;
-- 
2.12.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2017-05-24 18:01 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 18:01 [PATCH 0/7] Add PCI ATS support to SMMUv3 Jean-Philippe Brucker
2017-05-24 18:01 ` [PATCH 1/7] PCI: Move ATS declarations outside of CONFIG_PCI Jean-Philippe Brucker
2017-05-24 18:01 ` [PATCH 2/7] dt-bindings: PCI: Describe ATS property for root complex nodes Jean-Philippe Brucker
2017-05-30 10:01   ` Joerg Roedel
2017-05-30 10:58     ` Jean-Philippe Brucker
2017-05-31 17:17       ` Rob Herring
2017-05-31 17:23   ` Rob Herring
2017-06-01 12:28     ` Jean-Philippe Brucker
2017-06-05 17:20       ` Rob Herring
2017-06-06 11:11         ` Jean-Philippe Brucker
2017-06-20 11:38           ` Jean-Philippe Brucker
2017-05-24 18:01 ` [PATCH 3/7] iommu/of: Check ATS capability in " Jean-Philippe Brucker
2017-05-24 18:01 ` [PATCH 4/7] ACPI/IORT: " Jean-Philippe Brucker
2017-05-24 18:01 ` Jean-Philippe Brucker [this message]
2017-05-24 18:01 ` [PATCH 6/7] iommu/arm-smmu-v3: Add support for PCI ATS Jean-Philippe Brucker
2017-05-30 10:28   ` Joerg Roedel
2017-05-30 10:58     ` Jean-Philippe Brucker
2017-05-24 18:01 ` [PATCH 7/7] iommu/arm-smmu-v3: Disable tagged pointers Jean-Philippe Brucker
2017-05-31 15:27 ` [PATCH 0/7] Add PCI ATS support to SMMUv3 Nate Watterson
2017-06-01 12:23   ` Jean-Philippe Brucker

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=20170524180143.19855-6-jean-philippe.brucker@arm.com \
    --to=jean-philippe.brucker@arm.com \
    --cc=bhelgaas@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hanjun.guo@linaro.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=okaya@codeaurora.org \
    --cc=rjw@rjwysocki.net \
    --cc=robh+dt@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=sudeep.holla@arm.com \
    --cc=sunil.kovvuri@gmail.com \
    --cc=thunder.leizhen@huawei.com \
    --cc=tn@semihalf.com \
    --cc=will.deacon@arm.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).