iommu/vt-d: Several misc cleanups
Subsystems (3)
Lu Baolu
maintainercover iommu/vt-d: Several misc cleanups
Hi Joerg et al,
This series includes several cleanups in the VT-d driver. Please help to review.
Best regards,
baolu
Lu Baolu (5):
iommu/vt-d: Remove unused dma map/unmap trace events iommu/vt-d: Remove svm_dev_ops
iommu/vt-d: Remove SVM_FLAG_PRIVATE_PASID iommu/vt-d: Remove unused function declarations iommu/vt-d: Make unnecessarily global functions static
drivers/iommu/intel/pasid.c | 4 +- drivers/iommu/intel/pasid.h | 5 -- drivers/iommu/intel/svm.c | 55 +++++-------- include/linux/intel-iommu.h | 3 - include/linux/intel-svm.h | 23 +----- include/trace/events/intel_iommu.h | 120 ----------------------------- 6 files changed, 24 insertions(+), 186 deletions(-)
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Lu Baolu
maintainerPATCH 1/5 iommu/vt-d: Remove unused dma map/unmap trace events
With commit c588072bba6b5 ("iommu/vt-d: Convert intel iommu driver to the iommu ops"), the trace events for dma map/unmap have no users any more. Cleanup them to make the code neat.
--- include/trace/events/intel_iommu.h | 120 ----------------------------- 1 file changed, 120 deletions(-)
include/trace/events/intel_iommu.h +0 -120
@@ -15,126 +15,6 @@#include <linux/tracepoint.h> #include <linux/intel-iommu.h> -DECLARE_EVENT_CLASS (dma_map, - TP_PROTO(struct device *dev, dma_addr_t dev_addr, phys_addr_t phys_addr, - size_t size), - -TP_ARGS (dev, dev_addr, phys_addr, size), - -TP_STRUCT__entry ( - __string(dev_name, dev_name(dev)) - __field(dma_addr_t, dev_addr) - __field(phys_addr_t, phys_addr) -__field (size_t, size) - ), - -TP_fast_assign ( - __assign_str(dev_name, dev_name(dev)); - __entry->dev_addr = dev_addr; - __entry->phys_addr = phys_addr; - __entry->size = size; - ), - -TP_printk ("dev=%s dev_addr=0x%llx phys_addr=0x%llx size=%zu" , -__get_str (dev_name), - (unsigned long long )__entry->dev_addr, - (unsigned long long )__entry->phys_addr, - __entry->size) -); - -DEFINE_EVENT (dma_map, map_single, - TP_PROTO(struct device *dev, dma_addr_t dev_addr, phys_addr_t phys_addr, - size_t size), -TP_ARGS (dev, dev_addr, phys_addr, size) -); - -DEFINE_EVENT (dma_map, bounce_map_single, - TP_PROTO(struct device *dev, dma_addr_t dev_addr, phys_addr_t phys_addr, - size_t size), -TP_ARGS (dev, dev_addr, phys_addr, size) -); - -DECLARE_EVENT_CLASS (dma_unmap, - TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size), - -TP_ARGS (dev, dev_addr, size), - -TP_STRUCT__entry ( - __string(dev_name, dev_name(dev)) - __field(dma_addr_t, dev_addr) -__field (size_t, size) - ), - -TP_fast_assign ( - __assign_str(dev_name, dev_name(dev)); - __entry->dev_addr = dev_addr; - __entry->size = size; - ), - -TP_printk ("dev=%s dev_addr=0x%llx size=%zu" , -__get_str (dev_name), - (unsigned long long )__entry->dev_addr, - __entry->size) -); - -DEFINE_EVENT (dma_unmap, unmap_single, - TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size), -TP_ARGS (dev, dev_addr, size) -); - -DEFINE_EVENT (dma_unmap, unmap_sg, - TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size), -TP_ARGS (dev, dev_addr, size) -); - -DEFINE_EVENT (dma_unmap, bounce_unmap_single, - TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size), -TP_ARGS (dev, dev_addr, size) -); - -DECLARE_EVENT_CLASS (dma_map_sg, - TP_PROTO(struct device *dev, int index, int total, - struct scatterlist *sg), - -TP_ARGS (dev, index, total, sg), - -TP_STRUCT__entry ( - __string(dev_name, dev_name(dev)) - __field(dma_addr_t, dev_addr) - __field(phys_addr_t, phys_addr) - __field(size_t, size) - __field(int, index) -__field (int, total) - ), - -TP_fast_assign ( - __assign_str(dev_name, dev_name(dev)); - __entry->dev_addr = sg->dma_address; - __entry->phys_addr = sg_phys(sg); - __entry->size = sg->dma_length; - __entry->index = index; - __entry->total = total; - ), - -TP_printk ("dev=%s [%d/%d] dev_addr=0x%llx phys_addr=0x%llx size=%zu" , -__get_str (dev_name), __entry->index, __entry->total, - (unsigned long long )__entry->dev_addr, - (unsigned long long )__entry->phys_addr, - __entry->size) -); - -DEFINE_EVENT (dma_map_sg, map_sg, - TP_PROTO(struct device *dev, int index, int total, - struct scatterlist *sg), -TP_ARGS (dev, index, total, sg) -); - -DEFINE_EVENT (dma_map_sg, bounce_map_sg, - TP_PROTO(struct device *dev, int index, int total, - struct scatterlist *sg), -TP_ARGS (dev, index, total, sg) -); - TRACE_EVENT(qi_submit, TP_PROTO(struct intel_iommu *iommu, u64 qw0, u64 qw1, u64 qw2, u64 qw3),
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Lu Baolu
maintainerPATCH 2/5 iommu/vt-d: Remove svm_dev_ops
In reply to Lu BaoluThe svm_dev_ops has never been referenced in the tree, and there's no plan to have anything to use it. Remove it to make the code neat.
--- drivers/iommu/intel/svm.c | 15 +-------------- include/linux/intel-iommu.h | 3 --- include/linux/intel-svm.h | 7 ------- 3 files changed, 1 insertion(+), 24 deletions(-)
drivers/iommu/intel/svm.c +1 -14
@@ -462,7 +462,6 @@ static void load_pasid(struct mm_struct *mm, u32 pasid)/* Caller must hold pasid_mutex, mm reference */ static int intel_svm_bind_mm (struct device *dev,unsigned int flags, -struct svm_dev_ops *ops,struct mm_struct *mm,struct intel_svm_dev **sd) {struct intel_iommu *iommu =device_to_iommu (dev,NULL ,NULL );
@@ -512,10 +511,6 @@ intel_svm_bind_mm(struct device *dev, unsigned int flags,/* Find the matching device in svm list */ for_each_svm_dev (sdev, svm, dev) { -if (sdev->ops != ops) { - ret = -EBUSY ; - goto out; - } sdev->users++; goto success; }
@@ -550,7 +545,6 @@ intel_svm_bind_mm(struct device *dev, unsigned int flags,/* Finish the setup now we know we're keeping it */ sdev->users =1 ; - sdev->ops = ops;init_rcu_head (&sdev->rcu);if (!svm) {
@@ -1006,13 +1000,6 @@ static irqreturn_t prq_event_thread(int irq, void *d)mmap_read_unlock (svm->mm);mmput (svm->mm); bad_req: -WARN_ON (!sdev); -if (sdev && sdev->ops && sdev->ops->fault_cb) { -int rwxp = (req->rd_req <<3 ) | (req->wr_req <<2 ) | - (req->exe_req <<1 ) | (req->pm_req); - sdev->ops->fault_cb (sdev->dev, req->pasid, req->addr, - req->priv_data, rwxp, result); - }/* We get here in the error case where the PASID lookup failed, and these can be NULL. Do not use them below this point! */ sdev =NULL ;
@@ -1087,7 +1074,7 @@ intel_svm_bind(struct device *dev, struct mm_struct *mm, void *drvdata)if (drvdata) flags = *(unsigned int *)drvdata;mutex_lock (&pasid_mutex); - ret =intel_svm_bind_mm (dev, flags,NULL , mm, &sdev); + ret =intel_svm_bind_mm (dev, flags, mm, &sdev);if (ret) sva =ERR_PTR (ret);else if (sdev)
include/linux/intel-iommu.h +0 -3
@@ -770,14 +770,11 @@ u32 intel_svm_get_pasid(struct iommu_sva *handle);int intel_svm_page_response (struct device *dev,struct iommu_fault_event *evt,struct iommu_page_response *msg); -struct svm_dev_ops ; -struct intel_svm_dev {struct list_head list;struct rcu_head rcu;struct device *dev;struct intel_iommu *iommu; -struct svm_dev_ops *ops;struct iommu_sva sva;u32 pasid;int users;
include/linux/intel-svm.h +0 -7
@@ -8,13 +8,6 @@#ifndef __INTEL_SVM_H__#define __INTEL_SVM_H__ -struct device ; - -struct svm_dev_ops { -void (*fault_cb)(struct device *dev,u32 pasid,u64 address, -void *private,int rwxp,int response); -}; -/* Values for rxwp in fault_cb callback */ #define SVM_REQ_READ (1<<3)#define SVM_REQ_WRITE (1<<2)
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Lu Baolu
maintainerPATCH 3/5 iommu/vt-d: Remove SVM_FLAG_PRIVATE_PASID
In reply to Lu BaoluThe SVM_FLAG_PRIVATE_PASID has never been referenced in the tree, and there's no plan to have anything to use it. So cleanup it.
--- drivers/iommu/intel/svm.c | 40 ++++++++++++++++++--------------------- include/linux/intel-svm.h | 16 +++------------- 2 files changed, 21 insertions(+), 35 deletions(-)
drivers/iommu/intel/svm.c +18 -22
@@ -465,9 +465,9 @@ intel_svm_bind_mm(struct device *dev, unsigned int flags, struct mm_struct *mm, struct intel_svm_dev **sd) { struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL); +struct intel_svm *svm =NULL , *t;struct device_domain_info *info;struct intel_svm_dev *sdev; -struct intel_svm *svm =NULL ;unsigned long iflags;int pasid_max;int ret;
@@ -493,30 +493,26 @@ intel_svm_bind_mm(struct device *dev, unsigned int flags, } } -if (!(flags &SVM_FLAG_PRIVATE_PASID )) { -struct intel_svm *t; - -list_for_each_entry (t, &global_svm_list, list) { -if (t->mm != mm || (t->flags &SVM_FLAG_PRIVATE_PASID )) -continue ; - - svm = t; -if (svm->pasid >= pasid_max) { -dev_warn (dev, -"Limited PASID width. Cannot use existing PASID %d\n" , - svm->pasid); - ret = -ENOSPC ; - goto out; - } +list_for_each_entry (t, &global_svm_list, list) { +if (t->mm != mm) +continue ; -/* Find the matching device in svm list */ -for_each_svm_dev (sdev, svm, dev) { - sdev->users++; - goto success; - } + svm = t; +if (svm->pasid >= pasid_max) { +dev_warn (dev, +"Limited PASID width. Cannot use existing PASID %d\n" , + svm->pasid); + ret = -ENOSPC ; + goto out; + } -break ; +/* Find the matching device in svm list */ +for_each_svm_dev (sdev, svm, dev) { + sdev->users++; + goto success; } + +break ; } sdev =kzalloc (sizeof (*sdev),GFP_KERNEL );
include/linux/intel-svm.h +3 -13
@@ -14,16 +14,6 @@#define SVM_REQ_EXEC (1<<1)#define SVM_REQ_PRIV (1<<0) -/* -* The SVM_FLAG_PRIVATE_PASID flag requests a PASID which is *not* the "main" -* PASID for the current process. Even if a PASID already exists, a new one -* will be allocated. And the PASID allocated with SVM_FLAG_PRIVATE_PASID -* will not be given to subsequent callers. This facility allows a driver to -* disambiguate between multiple device contexts which access the same MM, -* if there is no other way to do so. It should be used sparingly, if at all. -*/ -#define SVM_FLAG_PRIVATE_PASID (1<<0) -/* * The SVM_FLAG_SUPERVISOR_MODE flag requests a PASID which can be used only * for access to kernel addresses. No IOTLB flushes are automatically done
@@ -35,18 +25,18 @@* It is unlikely that we will ever hook into flush_tlb_kernel_range() to * do such IOTLB flushes automatically. */ -#define SVM_FLAG_SUPERVISOR_MODE (1<<1) +#define SVM_FLAG_SUPERVISOR_MODE BIT(0)/* * The SVM_FLAG_GUEST_MODE flag is used when a PASID bind is for guest * processes. Compared to the host bind, the primary differences are: * 1. mm life cycle management * 2. fault reporting */ -#define SVM_FLAG_GUEST_MODE (1<<2) +#define SVM_FLAG_GUEST_MODE BIT(1)/* * The SVM_FLAG_GUEST_PASID flag is used when a guest has its own PASID space, * which requires guest and host PASID translation at both directions. */ -#define SVM_FLAG_GUEST_PASID (1<<3) +#define SVM_FLAG_GUEST_PASID BIT(2)#endif /* __INTEL_SVM_H__ */
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Lu Baolu
maintainerPATCH 4/5 iommu/vt-d: Remove unused function declarations
In reply to Lu BaoluSome functions have been deprecated. Remove the remaining function delarations.
--- drivers/iommu/intel/pasid.h | 3 --- 1 file changed, 3 deletions(-)
drivers/iommu/intel/pasid.h +0 -3
@@ -99,9 +99,6 @@ static inline bool pasid_pte_is_present(struct pasid_entry *pte) }extern unsigned int intel_pasid_max_id; -int intel_pasid_alloc_id (void *ptr,int start,int end,gfp_t gfp); -void intel_pasid_free_id (u32 pasid); -void *intel_pasid_lookup_id (u32 pasid);int intel_pasid_alloc_table (struct device *dev);void intel_pasid_free_table (struct device *dev);struct pasid_table *intel_pasid_get_table (struct device *dev);
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Lu Baolu
maintainerPATCH 5/5 iommu/vt-d: Make unnecessarily global functions static
In reply to Lu BaoluMake some functions static as they are only used inside pasid.c.
--- drivers/iommu/intel/pasid.c | 4 ++-- drivers/iommu/intel/pasid.h | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/iommu/intel/pasid.c +2 -2
@@ -230,7 +230,7 @@ struct pasid_table *intel_pasid_get_table(struct device *dev)return info->pasid_table; } -int intel_pasid_get_dev_max_id (struct device *dev) +static int intel_pasid_get_dev_max_id (struct device *dev) {struct device_domain_info *info;
@@ -241,7 +241,7 @@ int intel_pasid_get_dev_max_id(struct device *dev)return info->pasid_table->max_pasid; } -struct pasid_entry *intel_pasid_get_entry (struct device *dev,u32 pasid) +static struct pasid_entry *intel_pasid_get_entry (struct device *dev,u32 pasid) {struct device_domain_info *info;struct pasid_table *pasid_table;
drivers/iommu/intel/pasid.h +0 -2
@@ -102,8 +102,6 @@ extern unsigned int intel_pasid_max_id;int intel_pasid_alloc_table (struct device *dev);void intel_pasid_free_table (struct device *dev);struct pasid_table *intel_pasid_get_table (struct device *dev); -int intel_pasid_get_dev_max_id (struct device *dev); -struct pasid_entry *intel_pasid_get_entry (struct device *dev,u32 pasid);int intel_pasid_setup_first_level (struct intel_iommu *iommu,struct device *dev,pgd_t *pgd,u32 pasid,u16 did,int flags);
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 1/5] iommu/vt-d: Remove unused dma map/unmap trace events
In reply to Lu BaoluQuoted 5 lines · Lu Baolu
With commit
c588072bba6b5("iommu/vt-d: Convert intel iommu driver to the iommu ops"), the trace events for dma map/unmap have no users any more. Cleanup them to make the code neat.Signed-off-by Lu Baolu <[email protected]>
Looks good,
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 2/5] iommu/vt-d: Remove svm_dev_ops
In reply to Lu BaoluLooks good,
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 3/5] iommu/vt-d: Remove SVM_FLAG_PRIVATE_PASID
In reply to Lu BaoluQuoted 4 lines · Lu Baolu
The
SVM_FLAG_PRIVATE_PASIDhas never been referenced in the tree, and there's no plan to have anything to use it. So cleanup it.Signed-off-by Lu Baolu <[email protected]>
Looks good,
But can we take this a little further? SVM_FLAG_GUEST_PASID is unused as well. SVM_FLAG_GUEST_MODE is only used in drivers/iommu/intel/svm.c, and SVM_FLAG_SUPERVISOR_MODE is actually used as an API flag to iommu_sva_bind_device. So IMHO the latter should be elevated to an IOMMU API level flag, and then include/linux/intel-svm.h can go away entirely or at least be moved to drivers/iommu/intel/.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 4/5] iommu/vt-d: Remove unused function declarations
In reply to Lu BaoluQuoted 2 lines · Lu Baolu
Some functions have been deprecated. Remove the remaining function delarations.
s/deprecated/removed/g
Otherwise looks good:
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 5/5] iommu/vt-d: Make unnecessarily global functions static
In reply to Lu BaoluQuoted 3 lines · Lu Baolu
Make some functions static as they are only used inside
pasid.c.Signed-off-by Lu Baolu <[email protected]>
Looks good,
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Lu Baolu
maintainerRe: [PATCH 3/5] iommu/vt-d: Remove SVM_FLAG_PRIVATE_PASID
In reply to Christoph HellwigHi Christoph,
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Lu Baolu
The
SVM_FLAG_PRIVATE_PASIDhas never been referenced in the tree, and there's no plan to have anything to use it. So cleanup it.Signed-off-by Lu Baolu <[email protected]>Looks good,
Reviewed-by Christoph Hellwig <[email protected]>
Thank you!
Quoted 8 lines
But can we take this a little further?
SVM_FLAG_GUEST_PASIDis unused as well.SVM_FLAG_GUEST_MODEis only used indrivers/iommu/intel/svm.c, andSVM_FLAG_SUPERVISOR_MODEis actually used as an API flag toiommu_sva_bind_device. So IMHO the latter should be elevated to an IOMMU API level flag, and theninclude/linux/intel-svm.hcan go away entirely or at least be moved todrivers/iommu/intel/.
Sure. I will consider it and make it in separated patches.
Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerQuoted 6 lines · Lu Baolu
Lu Baolu (5):
iommu/vt-d: Remove unused dma map/unmap trace events iommu/vt-d: Removesvm_dev_ops
iommu/vt-d: RemoveSVM_FLAG_PRIVATE_PASIDiommu/vt-d: Remove unused function declarations iommu/vt-d: Make unnecessarily global functions static
Applied all, thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu