From: Niklas Schnelle <schnelle@linux.ibm.com>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Wenjia Zhang <wenjia@linux.ibm.com>
Cc: Matthew Rosato <mjrosato@linux.ibm.com>,
Gerd Bayer <gbayer@linux.ibm.com>,
Pierre Morel <pmorel@linux.ibm.com>,
iommu@lists.linux.dev, linux-s390@vger.kernel.org,
borntraeger@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com,
gerald.schaefer@linux.ibm.com, agordeev@linux.ibm.com,
svens@linux.ibm.com, linux-kernel@vger.kernel.org,
Julian Ruess <julianr@linux.ibm.com>
Subject: [PATCH v3 7/7] iommu/dma: Add IOMMU op to choose lazy domain type
Date: Mon, 2 Jan 2023 12:56:19 +0100 [thread overview]
Message-ID: <20230102115619.2088685-8-schnelle@linux.ibm.com> (raw)
In-Reply-To: <20230102115619.2088685-1-schnelle@linux.ibm.com>
With two flush queue variants add an IOMMU operation that allows the
IOMMU driver to choose its preferred flush queue variant on a per device
basis. For s390 use this callback to choose the single queue variant
whenever the device requires explicit IOTLB flushes on map indicating
that we're running in a paged memory guest with expensive IOTLB flushes.
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
drivers/iommu/iommu.c | 13 +++++++++++++
drivers/iommu/s390-iommu.c | 11 +++++++++++
include/linux/iommu.h | 5 +++++
3 files changed, 29 insertions(+)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 7ae2ff35b88e..c4699a0e5feb 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1616,6 +1616,16 @@ static int iommu_get_def_domain_type(struct device *dev)
return 0;
}
+static int iommu_get_lazy_domain_type(struct device *dev)
+{
+ const struct iommu_ops *ops = dev_iommu_ops(dev);
+
+ if (ops->lazy_domain_type)
+ return ops->lazy_domain_type(dev);
+
+ return 0;
+}
+
static int iommu_group_alloc_default_domain(struct bus_type *bus,
struct iommu_group *group,
unsigned int type)
@@ -1649,6 +1659,9 @@ static int iommu_alloc_default_domain(struct iommu_group *group,
type = iommu_get_def_domain_type(dev) ? : iommu_def_domain_type;
+ if (!!(type & __IOMMU_DOMAIN_DMA_LAZY))
+ type = iommu_get_lazy_domain_type(dev) ? : type;
+
return iommu_group_alloc_default_domain(dev->bus, group, type);
}
diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
index 122219b3e89f..2575acd081b5 100644
--- a/drivers/iommu/s390-iommu.c
+++ b/drivers/iommu/s390-iommu.c
@@ -459,6 +459,16 @@ static void s390_iommu_get_resv_regions(struct device *dev,
}
}
+static int s390_iommu_lazy_domain_type(struct device *dev)
+{
+ struct zpci_dev *zdev = to_zpci_dev(dev);
+
+ if (zdev->tlb_refresh)
+ return IOMMU_DOMAIN_DMA_SQ;
+
+ return IOMMU_DOMAIN_DMA_FQ;
+}
+
static struct iommu_device *s390_iommu_probe_device(struct device *dev)
{
struct zpci_dev *zdev;
@@ -798,6 +808,7 @@ static const struct iommu_ops s390_iommu_ops = {
.device_group = generic_device_group,
.pgsize_bitmap = SZ_4K,
.get_resv_regions = s390_iommu_get_resv_regions,
+ .lazy_domain_type = s390_iommu_lazy_domain_type,
.default_domain_ops = &(const struct iommu_domain_ops) {
.attach_dev = s390_iommu_attach_device,
.detach_dev = s390_iommu_detach_device,
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 74cee59516aa..aec895087f63 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -250,6 +250,10 @@ struct iommu_iotlb_gather {
* - IOMMU_DOMAIN_IDENTITY: must use an identity domain
* - IOMMU_DOMAIN_DMA: must use a dma domain
* - 0: use the default setting
+ * @lazy_domain_type: Domain type for lazy TLB invalidation, return value:
+ * - IOMMU_DOMAIN_DMA_FQ: Use per-CPU flush queue
+ * - IOMMU_DOMAIN_DMA_SQ: Use single flush queue
+ * - 0: use the default setting
* @default_domain_ops: the default ops for domains
* @remove_dev_pasid: Remove any translation configurations of a specific
* pasid, so that any DMA transactions with this pasid
@@ -283,6 +287,7 @@ struct iommu_ops {
struct iommu_page_response *msg);
int (*def_domain_type)(struct device *dev);
+ int (*lazy_domain_type)(struct device *dev);
void (*remove_dev_pasid)(struct device *dev, ioasid_t pasid);
const struct iommu_domain_ops *default_domain_ops;
--
2.34.1
prev parent reply other threads:[~2023-01-02 12:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-02 11:56 [PATCH v3 0/7 iommu/dma: s390 DMA API conversion and optimized IOTLB flushing Niklas Schnelle
2023-01-02 11:56 ` [PATCH v3 1/7] s390/ism: Set DMA coherent mask Niklas Schnelle
2023-01-02 18:18 ` Alexandra Winter
2023-01-02 11:56 ` [PATCH v3 2/7] iommu: Allow .iotlb_sync_map to fail and handle s390's -ENOMEM return Niklas Schnelle
2023-01-02 18:25 ` Alexandra Winter
2023-01-03 8:16 ` Niklas Schnelle
2023-01-03 9:25 ` Niklas Schnelle
2023-01-03 9:26 ` Heiko Carstens
2023-01-03 16:03 ` Niklas Schnelle
2023-01-02 11:56 ` [PATCH v3 3/7] s390/pci: prepare is_passed_through() for dma-iommu Niklas Schnelle
2023-01-02 11:56 ` [PATCH v3 4/7] s390/pci: Use dma-iommu layer Niklas Schnelle
2023-01-02 11:56 ` [PATCH v3 5/7] iommu/dma: Allow a single FQ in addition to per-CPU FQs Niklas Schnelle
2023-01-02 11:56 ` [PATCH v3 6/7] iommu/dma: Enable variable queue size and use larger single queue Niklas Schnelle
2023-01-02 11:56 ` Niklas Schnelle [this message]
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=20230102115619.2088685-8-schnelle@linux.ibm.com \
--to=schnelle@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gbayer@linux.ibm.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=julianr@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mjrosato@linux.ibm.com \
--cc=pmorel@linux.ibm.com \
--cc=robin.murphy@arm.com \
--cc=svens@linux.ibm.com \
--cc=wenjia@linux.ibm.com \
--cc=will@kernel.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.