From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
To: will.deacon@arm.com, lorenzo.pieralisi@arm.com, bhelgaas@google.com
Cc: iommu@lists.linux-foundation.org,
linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org,
robin.murphy@arm.com, joro@8bytes.org, hanjun.guo@linaro.org,
sudeep.holla@arm.com, rjw@rjwysocki.net, lenb@kernel.org,
okaya@kernel.org, zhongmiao@hisilicon.com, eric.auger@redhat.com,
linux-pci@vger.kernel.org
Subject: [PATCH v3 7/9] iommu/arm-smmu-v3: Link domains and devices
Date: Wed, 17 Apr 2019 19:24:46 +0100 [thread overview]
Message-ID: <20190417182448.12382-8-jean-philippe.brucker@arm.com> (raw)
In-Reply-To: <20190417182448.12382-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 when updating the context descriptor of a live domain,
we'll need to send invalidations for all devices attached to it.
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 | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
index 7b425483f4b6..3e7198ee9530 100644
--- a/drivers/iommu/arm-smmu-v3.c
+++ b/drivers/iommu/arm-smmu-v3.c
@@ -581,6 +581,7 @@ struct arm_smmu_device {
struct arm_smmu_master {
struct arm_smmu_device *smmu;
struct arm_smmu_domain *domain;
+ struct list_head domain_head;
u32 *sids;
unsigned int num_sids;
};
@@ -607,6 +608,9 @@ struct arm_smmu_domain {
};
struct iommu_domain domain;
+
+ struct list_head devices;
+ spinlock_t devices_lock;
};
struct arm_smmu_option_prop {
@@ -1504,6 +1508,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;
}
@@ -1721,9 +1728,16 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master)
static void arm_smmu_detach_dev(struct arm_smmu_master *master)
{
- if (!master->domain)
+ unsigned long flags;
+ struct arm_smmu_domain *smmu_domain = master->domain;
+
+ if (!smmu_domain)
return;
+ spin_lock_irqsave(&smmu_domain->devices_lock, flags);
+ list_del(&master->domain_head);
+ spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
+
master->domain = NULL;
arm_smmu_install_ste_for_dev(master);
}
@@ -1731,6 +1745,7 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master)
static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
{
int ret = 0;
+ unsigned long flags;
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
struct arm_smmu_device *smmu;
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
@@ -1764,6 +1779,10 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
master->domain = smmu_domain;
+ spin_lock_irqsave(&smmu_domain->devices_lock, flags);
+ list_add(&master->domain_head, &smmu_domain->devices);
+ spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
+
if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1)
arm_smmu_write_ctx_desc(smmu, &smmu_domain->s1_cfg);
--
2.21.0
next prev parent reply other threads:[~2019-04-17 18:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-17 18:24 [PATCH v3 0/9] Add PCI ATS support to Arm SMMUv3 Jean-Philippe Brucker
2019-04-17 18:24 ` [PATCH v3 1/9] PCI: Move ATS declarations outside of CONFIG_PCI Jean-Philippe Brucker
2019-04-17 19:47 ` Bjorn Helgaas
2019-04-17 18:24 ` [PATCH v3 2/9] PCI: Add a stub for pci_ats_disabled() Jean-Philippe Brucker
2019-04-17 19:48 ` Bjorn Helgaas
2019-04-17 18:24 ` [PATCH v3 3/9] ACPI/IORT: Check ATS capability in root complex nodes Jean-Philippe Brucker
2019-04-18 11:20 ` Lorenzo Pieralisi
2019-04-17 18:24 ` [PATCH v3 4/9] iommu/arm-smmu-v3: Rename arm_smmu_master_data to arm_smmu_master Jean-Philippe Brucker
2019-04-17 18:24 ` [PATCH v3 5/9] iommu/arm-smmu-v3: Store SteamIDs in master Jean-Philippe Brucker
2019-04-17 18:24 ` [PATCH v3 6/9] iommu/arm-smmu-v3: Add a master->domain pointer Jean-Philippe Brucker
2019-04-17 18:24 ` Jean-Philippe Brucker [this message]
2019-04-17 18:24 ` [PATCH v3 8/9] iommu/arm-smmu-v3: Add support for PCI ATS Jean-Philippe Brucker
2019-07-01 17:41 ` Robin Murphy
2019-07-02 14:59 ` Jean-Philippe Brucker
2019-04-17 18:24 ` [PATCH v3 9/9] iommu/arm-smmu-v3: Disable tagged pointers Jean-Philippe Brucker
2019-04-23 11:21 ` [PATCH v3 0/9] Add PCI ATS support to Arm SMMUv3 Will Deacon
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=20190417182448.12382-8-jean-philippe.brucker@arm.com \
--to=jean-philippe.brucker@arm.com \
--cc=bhelgaas@google.com \
--cc=eric.auger@redhat.com \
--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=okaya@kernel.org \
--cc=rjw@rjwysocki.net \
--cc=robin.murphy@arm.com \
--cc=sudeep.holla@arm.com \
--cc=will.deacon@arm.com \
--cc=zhongmiao@hisilicon.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).