* [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19
@ 2022-05-10 2:33 Lu Baolu
2022-05-10 2:34 ` [PATCH 1/8] iommu/vt-d: Remove unneeded validity check on dev Lu Baolu
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Lu Baolu @ 2022-05-10 2:33 UTC (permalink / raw)
To: Joerg Roedel
Cc: Kevin Tian, Muhammad Usama Anjum, iommu, Jason Gunthorpe,
Christoph Hellwig
Hi Joerg,
This includes patches queued for v5.19. It includes:
- Domain force snooping improvement.
- Cleanups, no intentional functional changes.
Please consider them for v5.19.
[This series cannot be directly applied to vt-d branch. Some domain
force snooping patches have been merged on the core branch. You may
also need to add those patches to the vt-d branch, or just merge
this series into the core branch.]
Best regards,
Baolu
Lu Baolu (7):
iommu/vt-d: Change return type of dmar_insert_one_dev_info()
iommu/vt-d: Fold dmar_insert_one_dev_info() into its caller
iommu/vt-d: Size Page Request Queue to avoid overflow condition
iommu/vt-d: Block force-snoop domain attaching if no SC support
iommu/vt-d: Check domain force_snooping against attached devices
iommu/vt-d: Remove domain_update_iommu_snooping()
iommu/vt-d: Remove hard coding PGSNP bit in PASID entries
Muhammad Usama Anjum (1):
iommu/vt-d: Remove unneeded validity check on dev
include/linux/intel-iommu.h | 1 +
include/linux/intel-svm.h | 2 +-
drivers/iommu/intel/pasid.h | 2 +
drivers/iommu/intel/iommu.c | 201 ++++++++++++++++++------------------
drivers/iommu/intel/pasid.c | 45 +++++++-
5 files changed, 149 insertions(+), 102 deletions(-)
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/8] iommu/vt-d: Remove unneeded validity check on dev
2022-05-10 2:33 [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Lu Baolu
@ 2022-05-10 2:34 ` Lu Baolu
2022-05-10 2:34 ` [PATCH 2/8] iommu/vt-d: Change return type of dmar_insert_one_dev_info() Lu Baolu
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lu Baolu @ 2022-05-10 2:34 UTC (permalink / raw)
To: Joerg Roedel
Cc: Kevin Tian, Muhammad Usama Anjum, iommu, Jason Gunthorpe,
Christoph Hellwig
From: Muhammad Usama Anjum <usama.anjum@collabora.com>
dev_iommu_priv_get() is being used at the top of this function which
dereferences dev. Dev cannot be NULL after this. Remove the validity
check on dev and simplify the code.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Link: https://lore.kernel.org/r/20220313150337.593650-1-usama.anjum@collabora.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/intel/iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 2990f80c5e08..626c2927344f 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2522,7 +2522,7 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
}
}
- if (dev && domain_context_mapping(domain, dev)) {
+ if (domain_context_mapping(domain, dev)) {
dev_err(dev, "Domain context map failed\n");
dmar_remove_one_dev_info(dev);
return NULL;
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/8] iommu/vt-d: Change return type of dmar_insert_one_dev_info()
2022-05-10 2:33 [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Lu Baolu
2022-05-10 2:34 ` [PATCH 1/8] iommu/vt-d: Remove unneeded validity check on dev Lu Baolu
@ 2022-05-10 2:34 ` Lu Baolu
2022-05-10 2:34 ` [PATCH 3/8] iommu/vt-d: Fold dmar_insert_one_dev_info() into its caller Lu Baolu
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lu Baolu @ 2022-05-10 2:34 UTC (permalink / raw)
To: Joerg Roedel
Cc: Kevin Tian, Muhammad Usama Anjum, iommu, Jason Gunthorpe,
Christoph Hellwig
The dmar_insert_one_dev_info() returns the pass-in domain on success and
NULL on failure. This doesn't make much sense. Change it to an integer.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220416120423.879552-1-baolu.lu@linux.intel.com
---
drivers/iommu/intel/iommu.c | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 626c2927344f..a5ca2b536ea8 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2473,10 +2473,9 @@ static bool dev_is_real_dma_subdevice(struct device *dev)
pci_real_dma_dev(to_pci_dev(dev)) != to_pci_dev(dev);
}
-static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
- int bus, int devfn,
- struct device *dev,
- struct dmar_domain *domain)
+static int dmar_insert_one_dev_info(struct intel_iommu *iommu, int bus,
+ int devfn, struct device *dev,
+ struct dmar_domain *domain)
{
struct device_domain_info *info = dev_iommu_priv_get(dev);
unsigned long flags;
@@ -2489,7 +2488,7 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
spin_unlock(&iommu->lock);
if (ret) {
spin_unlock_irqrestore(&device_domain_lock, flags);
- return NULL;
+ return ret;
}
list_add(&info->link, &domain->devices);
spin_unlock_irqrestore(&device_domain_lock, flags);
@@ -2500,7 +2499,7 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
if (ret) {
dev_err(dev, "PASID table allocation failed\n");
dmar_remove_one_dev_info(dev);
- return NULL;
+ return ret;
}
/* Setup the PASID entry for requests without PASID: */
@@ -2518,17 +2517,18 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
if (ret) {
dev_err(dev, "Setup RID2PASID failed\n");
dmar_remove_one_dev_info(dev);
- return NULL;
+ return ret;
}
}
- if (domain_context_mapping(domain, dev)) {
+ ret = domain_context_mapping(domain, dev);
+ if (ret) {
dev_err(dev, "Domain context map failed\n");
dmar_remove_one_dev_info(dev);
- return NULL;
+ return ret;
}
- return domain;
+ return 0;
}
static int iommu_domain_identity_map(struct dmar_domain *domain,
@@ -2606,7 +2606,6 @@ static int __init si_domain_init(int hw)
static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
{
- struct dmar_domain *ndomain;
struct intel_iommu *iommu;
u8 bus, devfn;
@@ -2614,11 +2613,7 @@ static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
if (!iommu)
return -ENODEV;
- ndomain = dmar_insert_one_dev_info(iommu, bus, devfn, dev, domain);
- if (ndomain != domain)
- return -EBUSY;
-
- return 0;
+ return dmar_insert_one_dev_info(iommu, bus, devfn, dev, domain);
}
static bool device_has_rmrr(struct device *dev)
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/8] iommu/vt-d: Fold dmar_insert_one_dev_info() into its caller
2022-05-10 2:33 [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Lu Baolu
2022-05-10 2:34 ` [PATCH 1/8] iommu/vt-d: Remove unneeded validity check on dev Lu Baolu
2022-05-10 2:34 ` [PATCH 2/8] iommu/vt-d: Change return type of dmar_insert_one_dev_info() Lu Baolu
@ 2022-05-10 2:34 ` Lu Baolu
2022-05-10 2:34 ` [PATCH 4/8] iommu/vt-d: Size Page Request Queue to avoid overflow condition Lu Baolu
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lu Baolu @ 2022-05-10 2:34 UTC (permalink / raw)
To: Joerg Roedel
Cc: Kevin Tian, Muhammad Usama Anjum, Christoph Hellwig, iommu,
Jason Gunthorpe, Christoph Hellwig
Fold dmar_insert_one_dev_info() into domain_add_dev_info() which is its
only caller.
No intentional functional impact.
Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220416120423.879552-1-baolu.lu@linux.intel.com
---
drivers/iommu/intel/iommu.c | 110 +++++++++++++++++-------------------
1 file changed, 51 insertions(+), 59 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index a5ca2b536ea8..cf43e8f9091b 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2473,64 +2473,6 @@ static bool dev_is_real_dma_subdevice(struct device *dev)
pci_real_dma_dev(to_pci_dev(dev)) != to_pci_dev(dev);
}
-static int dmar_insert_one_dev_info(struct intel_iommu *iommu, int bus,
- int devfn, struct device *dev,
- struct dmar_domain *domain)
-{
- struct device_domain_info *info = dev_iommu_priv_get(dev);
- unsigned long flags;
- int ret;
-
- spin_lock_irqsave(&device_domain_lock, flags);
- info->domain = domain;
- spin_lock(&iommu->lock);
- ret = domain_attach_iommu(domain, iommu);
- spin_unlock(&iommu->lock);
- if (ret) {
- spin_unlock_irqrestore(&device_domain_lock, flags);
- return ret;
- }
- list_add(&info->link, &domain->devices);
- spin_unlock_irqrestore(&device_domain_lock, flags);
-
- /* PASID table is mandatory for a PCI device in scalable mode. */
- if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
- ret = intel_pasid_alloc_table(dev);
- if (ret) {
- dev_err(dev, "PASID table allocation failed\n");
- dmar_remove_one_dev_info(dev);
- return ret;
- }
-
- /* Setup the PASID entry for requests without PASID: */
- spin_lock_irqsave(&iommu->lock, flags);
- if (hw_pass_through && domain_type_is_si(domain))
- ret = intel_pasid_setup_pass_through(iommu, domain,
- dev, PASID_RID2PASID);
- else if (domain_use_first_level(domain))
- ret = domain_setup_first_level(iommu, domain, dev,
- PASID_RID2PASID);
- else
- ret = intel_pasid_setup_second_level(iommu, domain,
- dev, PASID_RID2PASID);
- spin_unlock_irqrestore(&iommu->lock, flags);
- if (ret) {
- dev_err(dev, "Setup RID2PASID failed\n");
- dmar_remove_one_dev_info(dev);
- return ret;
- }
- }
-
- ret = domain_context_mapping(domain, dev);
- if (ret) {
- dev_err(dev, "Domain context map failed\n");
- dmar_remove_one_dev_info(dev);
- return ret;
- }
-
- return 0;
-}
-
static int iommu_domain_identity_map(struct dmar_domain *domain,
unsigned long first_vpfn,
unsigned long last_vpfn)
@@ -2606,14 +2548,64 @@ static int __init si_domain_init(int hw)
static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
{
+ struct device_domain_info *info = dev_iommu_priv_get(dev);
struct intel_iommu *iommu;
+ unsigned long flags;
u8 bus, devfn;
+ int ret;
iommu = device_to_iommu(dev, &bus, &devfn);
if (!iommu)
return -ENODEV;
- return dmar_insert_one_dev_info(iommu, bus, devfn, dev, domain);
+ spin_lock_irqsave(&device_domain_lock, flags);
+ info->domain = domain;
+ spin_lock(&iommu->lock);
+ ret = domain_attach_iommu(domain, iommu);
+ spin_unlock(&iommu->lock);
+ if (ret) {
+ spin_unlock_irqrestore(&device_domain_lock, flags);
+ return ret;
+ }
+ list_add(&info->link, &domain->devices);
+ spin_unlock_irqrestore(&device_domain_lock, flags);
+
+ /* PASID table is mandatory for a PCI device in scalable mode. */
+ if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
+ ret = intel_pasid_alloc_table(dev);
+ if (ret) {
+ dev_err(dev, "PASID table allocation failed\n");
+ dmar_remove_one_dev_info(dev);
+ return ret;
+ }
+
+ /* Setup the PASID entry for requests without PASID: */
+ spin_lock_irqsave(&iommu->lock, flags);
+ if (hw_pass_through && domain_type_is_si(domain))
+ ret = intel_pasid_setup_pass_through(iommu, domain,
+ dev, PASID_RID2PASID);
+ else if (domain_use_first_level(domain))
+ ret = domain_setup_first_level(iommu, domain, dev,
+ PASID_RID2PASID);
+ else
+ ret = intel_pasid_setup_second_level(iommu, domain,
+ dev, PASID_RID2PASID);
+ spin_unlock_irqrestore(&iommu->lock, flags);
+ if (ret) {
+ dev_err(dev, "Setup RID2PASID failed\n");
+ dmar_remove_one_dev_info(dev);
+ return ret;
+ }
+ }
+
+ ret = domain_context_mapping(domain, dev);
+ if (ret) {
+ dev_err(dev, "Domain context map failed\n");
+ dmar_remove_one_dev_info(dev);
+ return ret;
+ }
+
+ return 0;
}
static bool device_has_rmrr(struct device *dev)
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/8] iommu/vt-d: Size Page Request Queue to avoid overflow condition
2022-05-10 2:33 [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Lu Baolu
` (2 preceding siblings ...)
2022-05-10 2:34 ` [PATCH 3/8] iommu/vt-d: Fold dmar_insert_one_dev_info() into its caller Lu Baolu
@ 2022-05-10 2:34 ` Lu Baolu
2022-05-10 2:34 ` [PATCH 5/8] iommu/vt-d: Block force-snoop domain attaching if no SC support Lu Baolu
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lu Baolu @ 2022-05-10 2:34 UTC (permalink / raw)
To: Joerg Roedel
Cc: Kevin Tian, Muhammad Usama Anjum, iommu, Jason Gunthorpe,
Christoph Hellwig
PRQ overflow may cause I/O throughput congestion, resulting in unnecessary
degradation of I/O performance. Appropriately increasing the length of PRQ
can greatly reduce the occurrence of PRQ overflow. The count of maximum
page requests that can be generated in parallel by a PCIe device is
statically defined in the Outstanding Page Request Capacity field of the
PCIe ATS configure space.
The new length of PRQ is calculated by summing up the value of Outstanding
Page Request Capacity register across all devices where Page Requests are
supported on the real PR-capable platform (Intel Sapphire Rapids). The
result is round to the nearest higher power of 2.
The PRQ length is also double sized as the VT-d IOMMU driver only updates
the Page Request Queue Head Register (PQH_REG) after processing the entire
queue.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20220421113558.3504874-1-baolu.lu@linux.intel.com
---
include/linux/intel-svm.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/intel-svm.h b/include/linux/intel-svm.h
index b3b125b332aa..207ef06ba3e1 100644
--- a/include/linux/intel-svm.h
+++ b/include/linux/intel-svm.h
@@ -9,7 +9,7 @@
#define __INTEL_SVM_H__
/* Page Request Queue depth */
-#define PRQ_ORDER 2
+#define PRQ_ORDER 4
#define PRQ_RING_MASK ((0x1000 << PRQ_ORDER) - 0x20)
#define PRQ_DEPTH ((0x1000 << PRQ_ORDER) >> 5)
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/8] iommu/vt-d: Block force-snoop domain attaching if no SC support
2022-05-10 2:33 [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Lu Baolu
` (3 preceding siblings ...)
2022-05-10 2:34 ` [PATCH 4/8] iommu/vt-d: Size Page Request Queue to avoid overflow condition Lu Baolu
@ 2022-05-10 2:34 ` Lu Baolu
2022-05-10 2:34 ` [PATCH 6/8] iommu/vt-d: Check domain force_snooping against attached devices Lu Baolu
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lu Baolu @ 2022-05-10 2:34 UTC (permalink / raw)
To: Joerg Roedel
Cc: Kevin Tian, Muhammad Usama Anjum, iommu, Jason Gunthorpe,
Christoph Hellwig
In the attach_dev callback of the default domain ops, if the domain has
been set force_snooping, but the iommu hardware of the device does not
support SC(Snoop Control) capability, the callback should block it and
return a corresponding error code.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20220508123525.1973626-1-baolu.lu@linux.intel.com
---
drivers/iommu/intel/iommu.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index cf43e8f9091b..d68f5bbf3e93 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4354,6 +4354,9 @@ static int prepare_domain_attach_device(struct iommu_domain *domain,
if (!iommu)
return -ENODEV;
+ if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap))
+ return -EOPNOTSUPP;
+
/* check if this iommu agaw is sufficient for max mapped address */
addr_width = agaw_to_width(iommu->agaw);
if (addr_width > cap_mgaw(iommu->cap))
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/8] iommu/vt-d: Check domain force_snooping against attached devices
2022-05-10 2:33 [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Lu Baolu
` (4 preceding siblings ...)
2022-05-10 2:34 ` [PATCH 5/8] iommu/vt-d: Block force-snoop domain attaching if no SC support Lu Baolu
@ 2022-05-10 2:34 ` Lu Baolu
2022-05-10 2:34 ` [PATCH 7/8] iommu/vt-d: Remove domain_update_iommu_snooping() Lu Baolu
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Lu Baolu @ 2022-05-10 2:34 UTC (permalink / raw)
To: Joerg Roedel
Cc: Kevin Tian, Muhammad Usama Anjum, iommu, Jason Gunthorpe,
Christoph Hellwig
As domain->force_snooping only impacts the devices attached with the
domain, there's no need to check against all IOMMU units. On the other
hand, force_snooping could be set on a domain no matter whether it has
been attached or not, and once set it is an immutable flag. If no
device attached, the operation always succeeds. Then this empty domain
can be only attached to a device of which the IOMMU supports snoop
control.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20220508123525.1973626-1-baolu.lu@linux.intel.com
---
include/linux/intel-iommu.h | 1 +
drivers/iommu/intel/pasid.h | 2 ++
drivers/iommu/intel/iommu.c | 53 ++++++++++++++++++++++++++++++++++---
drivers/iommu/intel/pasid.c | 42 +++++++++++++++++++++++++++++
4 files changed, 95 insertions(+), 3 deletions(-)
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index 72e5d7900e71..4f29139bbfc3 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -540,6 +540,7 @@ struct dmar_domain {
u8 has_iotlb_device: 1;
u8 iommu_coherency: 1; /* indicate coherency of iommu access */
u8 force_snooping : 1; /* Create IOPTEs with snoop control */
+ u8 set_pte_snp:1;
struct list_head devices; /* all devices' list */
struct iova_domain iovad; /* iova's that belong to this domain */
diff --git a/drivers/iommu/intel/pasid.h b/drivers/iommu/intel/pasid.h
index ab4408c824a5..583ea67fc783 100644
--- a/drivers/iommu/intel/pasid.h
+++ b/drivers/iommu/intel/pasid.h
@@ -123,4 +123,6 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu,
bool fault_ignore);
int vcmd_alloc_pasid(struct intel_iommu *iommu, u32 *pasid);
void vcmd_free_pasid(struct intel_iommu *iommu, u32 pasid);
+void intel_pasid_setup_page_snoop_control(struct intel_iommu *iommu,
+ struct device *dev, u32 pasid);
#endif /* __INTEL_PASID_H */
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index d68f5bbf3e93..6ac49daa483b 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2459,7 +2459,7 @@ static int domain_setup_first_level(struct intel_iommu *iommu,
if (level == 5)
flags |= PASID_FLAG_FL5LP;
- if (domain->domain.type == IOMMU_DOMAIN_UNMANAGED)
+ if (domain->force_snooping)
flags |= PASID_FLAG_PAGE_SNOOP;
return intel_pasid_setup_first_level(iommu, dev, (pgd_t *)pgd, pasid,
@@ -4431,7 +4431,7 @@ static int intel_iommu_map(struct iommu_domain *domain,
prot |= DMA_PTE_READ;
if (iommu_prot & IOMMU_WRITE)
prot |= DMA_PTE_WRITE;
- if (dmar_domain->force_snooping)
+ if (dmar_domain->set_pte_snp)
prot |= DMA_PTE_SNP;
max_addr = iova + size;
@@ -4554,13 +4554,60 @@ static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain,
return phys;
}
+static bool domain_support_force_snooping(struct dmar_domain *domain)
+{
+ struct device_domain_info *info;
+ bool support = true;
+
+ assert_spin_locked(&device_domain_lock);
+ list_for_each_entry(info, &domain->devices, link) {
+ if (!ecap_sc_support(info->iommu->ecap)) {
+ support = false;
+ break;
+ }
+ }
+
+ return support;
+}
+
+static void domain_set_force_snooping(struct dmar_domain *domain)
+{
+ struct device_domain_info *info;
+
+ assert_spin_locked(&device_domain_lock);
+
+ /*
+ * Second level page table supports per-PTE snoop control. The
+ * iommu_map() interface will handle this by setting SNP bit.
+ */
+ if (!domain_use_first_level(domain)) {
+ domain->set_pte_snp = true;
+ return;
+ }
+
+ list_for_each_entry(info, &domain->devices, link)
+ intel_pasid_setup_page_snoop_control(info->iommu, info->dev,
+ PASID_RID2PASID);
+}
+
static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)
{
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
+ unsigned long flags;
- if (!domain_update_iommu_snooping(NULL))
+ if (dmar_domain->force_snooping)
+ return true;
+
+ spin_lock_irqsave(&device_domain_lock, flags);
+ if (!domain_support_force_snooping(dmar_domain)) {
+ spin_unlock_irqrestore(&device_domain_lock, flags);
return false;
+ }
+
+ domain_set_force_snooping(dmar_domain);
dmar_domain->force_snooping = true;
+ spin_unlock_irqrestore(&device_domain_lock, flags);
+
return true;
}
diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
index f8d215d85695..d19dd66a670c 100644
--- a/drivers/iommu/intel/pasid.c
+++ b/drivers/iommu/intel/pasid.c
@@ -762,3 +762,45 @@ int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
return 0;
}
+
+/*
+ * Set the page snoop control for a pasid entry which has been set up.
+ */
+void intel_pasid_setup_page_snoop_control(struct intel_iommu *iommu,
+ struct device *dev, u32 pasid)
+{
+ struct pasid_entry *pte;
+ u16 did;
+
+ spin_lock(&iommu->lock);
+ pte = intel_pasid_get_entry(dev, pasid);
+ if (WARN_ON(!pte || !pasid_pte_is_present(pte))) {
+ spin_unlock(&iommu->lock);
+ return;
+ }
+
+ pasid_set_pgsnp(pte);
+ did = pasid_get_domain_id(pte);
+ spin_unlock(&iommu->lock);
+
+ if (!ecap_coherent(iommu->ecap))
+ clflush_cache_range(pte, sizeof(*pte));
+
+ /*
+ * VT-d spec 3.4 table23 states guides for cache invalidation:
+ *
+ * - PASID-selective-within-Domain PASID-cache invalidation
+ * - PASID-selective PASID-based IOTLB invalidation
+ * - If (pasid is RID_PASID)
+ * - Global Device-TLB invalidation to affected functions
+ * Else
+ * - PASID-based Device-TLB invalidation (with S=1 and
+ * Addr[63:12]=0x7FFFFFFF_FFFFF) to affected functions
+ */
+ pasid_cache_invalidation_with_pasid(iommu, did, pasid);
+ qi_flush_piotlb(iommu, did, pasid, 0, -1, 0);
+
+ /* Device IOTLB doesn't need to be flushed in caching mode. */
+ if (!cap_caching_mode(iommu->cap))
+ devtlb_invalidation_with_pasid(iommu, dev, pasid);
+}
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 7/8] iommu/vt-d: Remove domain_update_iommu_snooping()
2022-05-10 2:33 [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Lu Baolu
` (5 preceding siblings ...)
2022-05-10 2:34 ` [PATCH 6/8] iommu/vt-d: Check domain force_snooping against attached devices Lu Baolu
@ 2022-05-10 2:34 ` Lu Baolu
2022-05-10 2:34 ` [PATCH 8/8] iommu/vt-d: Remove hard coding PGSNP bit in PASID entries Lu Baolu
2022-05-13 13:15 ` [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Joerg Roedel
8 siblings, 0 replies; 10+ messages in thread
From: Lu Baolu @ 2022-05-10 2:34 UTC (permalink / raw)
To: Joerg Roedel
Cc: Kevin Tian, Muhammad Usama Anjum, iommu, Jason Gunthorpe,
Christoph Hellwig
The IOMMU force snooping capability is not required to be consistent
among all the IOMMUs anymore. Remove force snooping capability check
in the IOMMU hot-add path and domain_update_iommu_snooping() becomes
a dead code now.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20220508123525.1973626-1-baolu.lu@linux.intel.com
---
drivers/iommu/intel/iommu.c | 34 +---------------------------------
1 file changed, 1 insertion(+), 33 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 6ac49daa483b..e56b3a4b6998 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -533,33 +533,6 @@ static void domain_update_iommu_coherency(struct dmar_domain *domain)
rcu_read_unlock();
}
-static bool domain_update_iommu_snooping(struct intel_iommu *skip)
-{
- struct dmar_drhd_unit *drhd;
- struct intel_iommu *iommu;
- bool ret = true;
-
- rcu_read_lock();
- for_each_active_iommu(iommu, drhd) {
- if (iommu != skip) {
- /*
- * If the hardware is operating in the scalable mode,
- * the snooping control is always supported since we
- * always set PASID-table-entry.PGSNP bit if the domain
- * is managed outside (UNMANAGED).
- */
- if (!sm_supported(iommu) &&
- !ecap_sc_support(iommu->ecap)) {
- ret = false;
- break;
- }
- }
- }
- rcu_read_unlock();
-
- return ret;
-}
-
static int domain_update_iommu_superpage(struct dmar_domain *domain,
struct intel_iommu *skip)
{
@@ -3593,12 +3566,7 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)
iommu->name);
return -ENXIO;
}
- if (!ecap_sc_support(iommu->ecap) &&
- domain_update_iommu_snooping(iommu)) {
- pr_warn("%s: Doesn't support snooping.\n",
- iommu->name);
- return -ENXIO;
- }
+
sp = domain_update_iommu_superpage(NULL, iommu) - 1;
if (sp >= 0 && !(cap_super_page_val(iommu->cap) & (1 << sp))) {
pr_warn("%s: Doesn't support large page.\n",
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 8/8] iommu/vt-d: Remove hard coding PGSNP bit in PASID entries
2022-05-10 2:33 [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Lu Baolu
` (6 preceding siblings ...)
2022-05-10 2:34 ` [PATCH 7/8] iommu/vt-d: Remove domain_update_iommu_snooping() Lu Baolu
@ 2022-05-10 2:34 ` Lu Baolu
2022-05-13 13:15 ` [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Joerg Roedel
8 siblings, 0 replies; 10+ messages in thread
From: Lu Baolu @ 2022-05-10 2:34 UTC (permalink / raw)
To: Joerg Roedel
Cc: Kevin Tian, Muhammad Usama Anjum, iommu, Jason Gunthorpe,
Christoph Hellwig
As enforce_cache_coherency has been introduced into the iommu_domain_ops,
the kernel component which owns the iommu domain is able to opt-in its
requirement for force snooping support. The iommu driver has no need to
hard code the page snoop control bit in the PASID table entries anymore.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20220508123525.1973626-1-baolu.lu@linux.intel.com
---
drivers/iommu/intel/pasid.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
index d19dd66a670c..cb4c1d0cf25c 100644
--- a/drivers/iommu/intel/pasid.c
+++ b/drivers/iommu/intel/pasid.c
@@ -710,9 +710,6 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu,
pasid_set_fault_enable(pte);
pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
- if (domain->domain.type == IOMMU_DOMAIN_UNMANAGED)
- pasid_set_pgsnp(pte);
-
/*
* Since it is a second level only translation setup, we should
* set SRE bit as well (addresses are expected to be GPAs).
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19
2022-05-10 2:33 [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Lu Baolu
` (7 preceding siblings ...)
2022-05-10 2:34 ` [PATCH 8/8] iommu/vt-d: Remove hard coding PGSNP bit in PASID entries Lu Baolu
@ 2022-05-13 13:15 ` Joerg Roedel
8 siblings, 0 replies; 10+ messages in thread
From: Joerg Roedel @ 2022-05-13 13:15 UTC (permalink / raw)
To: Lu Baolu
Cc: Kevin Tian, iommu, Christoph Hellwig, Jason Gunthorpe,
Muhammad Usama Anjum
On Tue, May 10, 2022 at 10:33:59AM +0800, Lu Baolu wrote:
> This includes patches queued for v5.19. It includes:
>
> - Domain force snooping improvement.
> - Cleanups, no intentional functional changes.
>
> Please consider them for v5.19.
>
> [This series cannot be directly applied to vt-d branch. Some domain
> force snooping patches have been merged on the core branch. You may
> also need to add those patches to the vt-d branch, or just merge
> this series into the core branch.]
Alright, merged the core branch into x86/vt-d and applied these patches
on-top.
Thanks Baolu.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-05-13 13:15 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-10 2:33 [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Lu Baolu
2022-05-10 2:34 ` [PATCH 1/8] iommu/vt-d: Remove unneeded validity check on dev Lu Baolu
2022-05-10 2:34 ` [PATCH 2/8] iommu/vt-d: Change return type of dmar_insert_one_dev_info() Lu Baolu
2022-05-10 2:34 ` [PATCH 3/8] iommu/vt-d: Fold dmar_insert_one_dev_info() into its caller Lu Baolu
2022-05-10 2:34 ` [PATCH 4/8] iommu/vt-d: Size Page Request Queue to avoid overflow condition Lu Baolu
2022-05-10 2:34 ` [PATCH 5/8] iommu/vt-d: Block force-snoop domain attaching if no SC support Lu Baolu
2022-05-10 2:34 ` [PATCH 6/8] iommu/vt-d: Check domain force_snooping against attached devices Lu Baolu
2022-05-10 2:34 ` [PATCH 7/8] iommu/vt-d: Remove domain_update_iommu_snooping() Lu Baolu
2022-05-10 2:34 ` [PATCH 8/8] iommu/vt-d: Remove hard coding PGSNP bit in PASID entries Lu Baolu
2022-05-13 13:15 ` [PATCH 0/8] [PULL REQUEST] Intel IOMMU updates for Linux v5.19 Joerg Roedel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox