* [PATCH 0/4] iommu/vt-d: SVM implementation cleanup
@ 2023-01-09 1:49 Lu Baolu
2023-01-09 1:49 ` [PATCH 1/4] iommu/vt-d: Remove include/linux/intel-svm.h Lu Baolu
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Lu Baolu @ 2023-01-09 1:49 UTC (permalink / raw)
To: iommu
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian, linux-kernel,
Lu Baolu
This is a cleanup series after the merge of commit be51b1d6bbff
("iommu/sva: Refactoring iommu_sva_bind/unbind_device()"). It removes
the unused/duplicate data and code.
Lu Baolu (4):
iommu/vt-d: Remove include/linux/intel-svm.h
iommu/vt-d: Remove unused fields in svm structures
iommu/vt-d: Remove users from intel_svm_dev
iommu/vt-d: Remove sva from intel_svm_dev
include/linux/intel-svm.h | 16 -------
drivers/iommu/intel/iommu.h | 11 +++--
drivers/iommu/intel/iommu.c | 1 -
drivers/iommu/intel/svm.c | 88 +++++++++++++++----------------------
MAINTAINERS | 1 -
5 files changed, 41 insertions(+), 76 deletions(-)
delete mode 100644 include/linux/intel-svm.h
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] iommu/vt-d: Remove include/linux/intel-svm.h
2023-01-09 1:49 [PATCH 0/4] iommu/vt-d: SVM implementation cleanup Lu Baolu
@ 2023-01-09 1:49 ` Lu Baolu
2023-01-09 1:49 ` [PATCH 2/4] iommu/vt-d: Remove unused fields in svm structures Lu Baolu
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2023-01-09 1:49 UTC (permalink / raw)
To: iommu
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian, linux-kernel,
Lu Baolu
There's no need to have a public header for Intel SVA implementation.
The device driver should interact with Intel SVA implementation via
the IOMMU generic APIs.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
include/linux/intel-svm.h | 16 ----------------
drivers/iommu/intel/iommu.h | 5 +++++
drivers/iommu/intel/iommu.c | 1 -
drivers/iommu/intel/svm.c | 1 -
MAINTAINERS | 1 -
5 files changed, 5 insertions(+), 19 deletions(-)
delete mode 100644 include/linux/intel-svm.h
diff --git a/include/linux/intel-svm.h b/include/linux/intel-svm.h
deleted file mode 100644
index f9a0d44f6fdb..000000000000
--- a/include/linux/intel-svm.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright © 2015 Intel Corporation.
- *
- * Authors: David Woodhouse <David.Woodhouse@intel.com>
- */
-
-#ifndef __INTEL_SVM_H__
-#define __INTEL_SVM_H__
-
-/* Page Request Queue depth */
-#define PRQ_ORDER 4
-#define PRQ_RING_MASK ((0x1000 << PRQ_ORDER) - 0x20)
-#define PRQ_DEPTH ((0x1000 << PRQ_ORDER) >> 5)
-
-#endif /* __INTEL_SVM_H__ */
diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h
index 06e61e474856..f89f63d7a72a 100644
--- a/drivers/iommu/intel/iommu.h
+++ b/drivers/iommu/intel/iommu.h
@@ -438,6 +438,11 @@ struct q_inval {
int free_cnt;
};
+/* Page Request Queue depth */
+#define PRQ_ORDER 4
+#define PRQ_RING_MASK ((0x1000 << PRQ_ORDER) - 0x20)
+#define PRQ_DEPTH ((0x1000 << PRQ_ORDER) >> 5)
+
struct dmar_pci_notify_info;
#ifdef CONFIG_IRQ_REMAP
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 59df7e42fd53..317af67b6098 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -16,7 +16,6 @@
#include <linux/crash_dump.h>
#include <linux/dma-direct.h>
#include <linux/dmi.h>
-#include <linux/intel-svm.h>
#include <linux/memory.h>
#include <linux/pci.h>
#include <linux/pci-ats.h>
diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c
index c76b66263467..d38a54396c23 100644
--- a/drivers/iommu/intel/svm.c
+++ b/drivers/iommu/intel/svm.c
@@ -9,7 +9,6 @@
#include <linux/sched.h>
#include <linux/sched/mm.h>
#include <linux/slab.h>
-#include <linux/intel-svm.h>
#include <linux/rculist.h>
#include <linux/pci.h>
#include <linux/pci-ats.h>
diff --git a/MAINTAINERS b/MAINTAINERS
index a36df9ed283d..43fd97f0e1df 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10459,7 +10459,6 @@ L: iommu@lists.linux.dev
S: Supported
T: git git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git
F: drivers/iommu/intel/
-F: include/linux/intel-svm.h
INTEL IPU3 CSI-2 CIO2 DRIVER
M: Yong Zhi <yong.zhi@intel.com>
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] iommu/vt-d: Remove unused fields in svm structures
2023-01-09 1:49 [PATCH 0/4] iommu/vt-d: SVM implementation cleanup Lu Baolu
2023-01-09 1:49 ` [PATCH 1/4] iommu/vt-d: Remove include/linux/intel-svm.h Lu Baolu
@ 2023-01-09 1:49 ` Lu Baolu
2023-01-09 1:49 ` [PATCH 3/4] iommu/vt-d: Remove users from intel_svm_dev Lu Baolu
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2023-01-09 1:49 UTC (permalink / raw)
To: iommu
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian, linux-kernel,
Lu Baolu
They aren't used anywhere. Remove them to avoid dead code.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/intel/iommu.h | 4 ----
drivers/iommu/intel/svm.c | 2 --
2 files changed, 6 deletions(-)
diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h
index f89f63d7a72a..e7c732979364 100644
--- a/drivers/iommu/intel/iommu.h
+++ b/drivers/iommu/intel/iommu.h
@@ -762,18 +762,14 @@ struct intel_svm_dev {
struct device *dev;
struct intel_iommu *iommu;
struct iommu_sva sva;
- u32 pasid;
int users;
u16 did;
- u16 dev_iotlb:1;
u16 sid, qdep;
};
struct intel_svm {
struct mmu_notifier notifier;
struct mm_struct *mm;
-
- unsigned int flags;
u32 pasid;
struct list_head devs;
};
diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c
index d38a54396c23..d1e445f03aa6 100644
--- a/drivers/iommu/intel/svm.c
+++ b/drivers/iommu/intel/svm.c
@@ -351,11 +351,9 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
sdev->did = FLPT_DEFAULT_DID;
sdev->sid = PCI_DEVID(info->bus, info->devfn);
sdev->users = 1;
- sdev->pasid = svm->pasid;
sdev->sva.dev = dev;
init_rcu_head(&sdev->rcu);
if (info->ats_enabled) {
- sdev->dev_iotlb = 1;
sdev->qdep = info->ats_qdep;
if (sdev->qdep >= QI_DEV_EIOTLB_MAX_INVS)
sdev->qdep = 0;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] iommu/vt-d: Remove users from intel_svm_dev
2023-01-09 1:49 [PATCH 0/4] iommu/vt-d: SVM implementation cleanup Lu Baolu
2023-01-09 1:49 ` [PATCH 1/4] iommu/vt-d: Remove include/linux/intel-svm.h Lu Baolu
2023-01-09 1:49 ` [PATCH 2/4] iommu/vt-d: Remove unused fields in svm structures Lu Baolu
@ 2023-01-09 1:49 ` Lu Baolu
2023-01-09 1:49 ` [PATCH 4/4] iommu/vt-d: Remove sva " Lu Baolu
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2023-01-09 1:49 UTC (permalink / raw)
To: iommu
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian, linux-kernel,
Lu Baolu
It was used as a reference counter of an existing bond between device
and user application memory address. Commit be51b1d6bbff ("iommu/sva:
Refactoring iommu_sva_bind/unbind_device()") has added this in iommu
core. Remove it to avoid duplicate code.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/intel/iommu.h | 1 -
drivers/iommu/intel/svm.c | 62 ++++++++++++++++---------------------
2 files changed, 27 insertions(+), 36 deletions(-)
diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h
index e7c732979364..2a1619ff0d79 100644
--- a/drivers/iommu/intel/iommu.h
+++ b/drivers/iommu/intel/iommu.h
@@ -762,7 +762,6 @@ struct intel_svm_dev {
struct device *dev;
struct intel_iommu *iommu;
struct iommu_sva sva;
- int users;
u16 did;
u16 sid, qdep;
};
diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c
index d1e445f03aa6..c7dc53e40c26 100644
--- a/drivers/iommu/intel/svm.c
+++ b/drivers/iommu/intel/svm.c
@@ -333,13 +333,6 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
}
}
- /* Find the matching device in svm list */
- sdev = svm_lookup_device_by_dev(svm, dev);
- if (sdev) {
- sdev->users++;
- goto success;
- }
-
sdev = kzalloc(sizeof(*sdev), GFP_KERNEL);
if (!sdev) {
ret = -ENOMEM;
@@ -350,7 +343,6 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
sdev->iommu = iommu;
sdev->did = FLPT_DEFAULT_DID;
sdev->sid = PCI_DEVID(info->bus, info->devfn);
- sdev->users = 1;
sdev->sva.dev = dev;
init_rcu_head(&sdev->rcu);
if (info->ats_enabled) {
@@ -367,7 +359,7 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
goto free_sdev;
list_add_rcu(&sdev->list, &svm->devs);
-success:
+
return &sdev->sva;
free_sdev:
@@ -401,32 +393,32 @@ static int intel_svm_unbind_mm(struct device *dev, u32 pasid)
mm = svm->mm;
if (sdev) {
- sdev->users--;
- if (!sdev->users) {
- list_del_rcu(&sdev->list);
- /* Flush the PASID cache and IOTLB for this device.
- * Note that we do depend on the hardware *not* using
- * the PASID any more. Just as we depend on other
- * devices never using PASIDs that they have no right
- * to use. We have a *shared* PASID table, because it's
- * large and has to be physically contiguous. So it's
- * hard to be as defensive as we might like. */
- intel_pasid_tear_down_entry(iommu, dev,
- svm->pasid, false);
- intel_svm_drain_prq(dev, svm->pasid);
- kfree_rcu(sdev, rcu);
-
- if (list_empty(&svm->devs)) {
- if (svm->notifier.ops)
- mmu_notifier_unregister(&svm->notifier, mm);
- pasid_private_remove(svm->pasid);
- /* We mandate that no page faults may be outstanding
- * for the PASID when intel_svm_unbind_mm() is called.
- * If that is not obeyed, subtle errors will happen.
- * Let's make them less subtle... */
- memset(svm, 0x6b, sizeof(*svm));
- kfree(svm);
- }
+ list_del_rcu(&sdev->list);
+ /*
+ * Flush the PASID cache and IOTLB for this device.
+ * Note that we do depend on the hardware *not* using
+ * the PASID any more. Just as we depend on other
+ * devices never using PASIDs that they have no right
+ * to use. We have a *shared* PASID table, because it's
+ * large and has to be physically contiguous. So it's
+ * hard to be as defensive as we might like.
+ */
+ intel_pasid_tear_down_entry(iommu, dev, svm->pasid, false);
+ intel_svm_drain_prq(dev, svm->pasid);
+ kfree_rcu(sdev, rcu);
+
+ if (list_empty(&svm->devs)) {
+ if (svm->notifier.ops)
+ mmu_notifier_unregister(&svm->notifier, mm);
+ pasid_private_remove(svm->pasid);
+ /*
+ * We mandate that no page faults may be outstanding
+ * for the PASID when intel_svm_unbind_mm() is called.
+ * If that is not obeyed, subtle errors will happen.
+ * Let's make them less subtle...
+ */
+ memset(svm, 0x6b, sizeof(*svm));
+ kfree(svm);
}
}
out:
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] iommu/vt-d: Remove sva from intel_svm_dev
2023-01-09 1:49 [PATCH 0/4] iommu/vt-d: SVM implementation cleanup Lu Baolu
` (2 preceding siblings ...)
2023-01-09 1:49 ` [PATCH 3/4] iommu/vt-d: Remove users from intel_svm_dev Lu Baolu
@ 2023-01-09 1:49 ` Lu Baolu
2023-01-10 2:46 ` [PATCH 0/4] iommu/vt-d: SVM implementation cleanup Tian, Kevin
2023-01-31 7:51 ` Baolu Lu
5 siblings, 0 replies; 7+ messages in thread
From: Lu Baolu @ 2023-01-09 1:49 UTC (permalink / raw)
To: iommu
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian, linux-kernel,
Lu Baolu
After commit be51b1d6bbff ("iommu/sva: Refactoring
iommu_sva_bind/unbind_device()"), the iommu driver doesn't need to
return an iommu_sva pointer anymore. This removes the sva field
from intel_svm_dev and cleanups the code accordingly.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/intel/iommu.h | 1 -
drivers/iommu/intel/svm.c | 23 +++++++++--------------
2 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h
index 2a1619ff0d79..f0222ad38757 100644
--- a/drivers/iommu/intel/iommu.h
+++ b/drivers/iommu/intel/iommu.h
@@ -761,7 +761,6 @@ struct intel_svm_dev {
struct rcu_head rcu;
struct device *dev;
struct intel_iommu *iommu;
- struct iommu_sva sva;
u16 did;
u16 sid, qdep;
};
diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c
index c7dc53e40c26..e7b9bedebcc0 100644
--- a/drivers/iommu/intel/svm.c
+++ b/drivers/iommu/intel/svm.c
@@ -298,9 +298,8 @@ static int pasid_to_svm_sdev(struct device *dev, unsigned int pasid,
return 0;
}
-static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
- struct device *dev,
- struct mm_struct *mm)
+static int intel_svm_bind_mm(struct intel_iommu *iommu, struct device *dev,
+ struct mm_struct *mm)
{
struct device_domain_info *info = dev_iommu_priv_get(dev);
struct intel_svm_dev *sdev;
@@ -312,7 +311,7 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
if (!svm) {
svm = kzalloc(sizeof(*svm), GFP_KERNEL);
if (!svm)
- return ERR_PTR(-ENOMEM);
+ return -ENOMEM;
svm->pasid = mm->pasid;
svm->mm = mm;
@@ -322,14 +321,14 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
ret = mmu_notifier_register(&svm->notifier, mm);
if (ret) {
kfree(svm);
- return ERR_PTR(ret);
+ return ret;
}
ret = pasid_private_add(svm->pasid, svm);
if (ret) {
mmu_notifier_unregister(&svm->notifier, mm);
kfree(svm);
- return ERR_PTR(ret);
+ return ret;
}
}
@@ -343,7 +342,6 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
sdev->iommu = iommu;
sdev->did = FLPT_DEFAULT_DID;
sdev->sid = PCI_DEVID(info->bus, info->devfn);
- sdev->sva.dev = dev;
init_rcu_head(&sdev->rcu);
if (info->ats_enabled) {
sdev->qdep = info->ats_qdep;
@@ -360,7 +358,7 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
list_add_rcu(&sdev->list, &svm->devs);
- return &sdev->sva;
+ return 0;
free_sdev:
kfree(sdev);
@@ -371,7 +369,7 @@ static struct iommu_sva *intel_svm_bind_mm(struct intel_iommu *iommu,
kfree(svm);
}
- return ERR_PTR(ret);
+ return ret;
}
/* Caller must hold pasid_mutex */
@@ -843,13 +841,10 @@ static int intel_svm_set_dev_pasid(struct iommu_domain *domain,
struct device_domain_info *info = dev_iommu_priv_get(dev);
struct intel_iommu *iommu = info->iommu;
struct mm_struct *mm = domain->mm;
- struct iommu_sva *sva;
- int ret = 0;
+ int ret;
mutex_lock(&pasid_mutex);
- sva = intel_svm_bind_mm(iommu, dev, mm);
- if (IS_ERR(sva))
- ret = PTR_ERR(sva);
+ ret = intel_svm_bind_mm(iommu, dev, mm);
mutex_unlock(&pasid_mutex);
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* RE: [PATCH 0/4] iommu/vt-d: SVM implementation cleanup
2023-01-09 1:49 [PATCH 0/4] iommu/vt-d: SVM implementation cleanup Lu Baolu
` (3 preceding siblings ...)
2023-01-09 1:49 ` [PATCH 4/4] iommu/vt-d: Remove sva " Lu Baolu
@ 2023-01-10 2:46 ` Tian, Kevin
2023-01-31 7:51 ` Baolu Lu
5 siblings, 0 replies; 7+ messages in thread
From: Tian, Kevin @ 2023-01-10 2:46 UTC (permalink / raw)
To: Lu Baolu, iommu@lists.linux.dev
Cc: Joerg Roedel, Will Deacon, Robin Murphy,
linux-kernel@vger.kernel.org
> From: Lu Baolu <baolu.lu@linux.intel.com>
> Sent: Monday, January 9, 2023 9:50 AM
>
> This is a cleanup series after the merge of commit be51b1d6bbff
> ("iommu/sva: Refactoring iommu_sva_bind/unbind_device()"). It removes
> the unused/duplicate data and code.
>
> Lu Baolu (4):
> iommu/vt-d: Remove include/linux/intel-svm.h
> iommu/vt-d: Remove unused fields in svm structures
> iommu/vt-d: Remove users from intel_svm_dev
> iommu/vt-d: Remove sva from intel_svm_dev
>
For the series:
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] iommu/vt-d: SVM implementation cleanup
2023-01-09 1:49 [PATCH 0/4] iommu/vt-d: SVM implementation cleanup Lu Baolu
` (4 preceding siblings ...)
2023-01-10 2:46 ` [PATCH 0/4] iommu/vt-d: SVM implementation cleanup Tian, Kevin
@ 2023-01-31 7:51 ` Baolu Lu
5 siblings, 0 replies; 7+ messages in thread
From: Baolu Lu @ 2023-01-31 7:51 UTC (permalink / raw)
To: iommu
Cc: baolu.lu, Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian,
linux-kernel
On 2023/1/9 9:49, Lu Baolu wrote:
> This is a cleanup series after the merge of commit be51b1d6bbff
> ("iommu/sva: Refactoring iommu_sva_bind/unbind_device()"). It removes
> the unused/duplicate data and code.
>
> Lu Baolu (4):
> iommu/vt-d: Remove include/linux/intel-svm.h
> iommu/vt-d: Remove unused fields in svm structures
> iommu/vt-d: Remove users from intel_svm_dev
> iommu/vt-d: Remove sva from intel_svm_dev
Patches queued for v6.3.
https://lore.kernel.org/linux-iommu/20230131073740.378984-1-baolu.lu@linux.intel.com/
Best regards,
baolu
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-01-31 7:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-09 1:49 [PATCH 0/4] iommu/vt-d: SVM implementation cleanup Lu Baolu
2023-01-09 1:49 ` [PATCH 1/4] iommu/vt-d: Remove include/linux/intel-svm.h Lu Baolu
2023-01-09 1:49 ` [PATCH 2/4] iommu/vt-d: Remove unused fields in svm structures Lu Baolu
2023-01-09 1:49 ` [PATCH 3/4] iommu/vt-d: Remove users from intel_svm_dev Lu Baolu
2023-01-09 1:49 ` [PATCH 4/4] iommu/vt-d: Remove sva " Lu Baolu
2023-01-10 2:46 ` [PATCH 0/4] iommu/vt-d: SVM implementation cleanup Tian, Kevin
2023-01-31 7:51 ` Baolu Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox