iommu/vt-d: Improve PASID id and table management
cover iommu/vt-d: Improve PASID id and table management
This patch set improves the PASID id and PASID table management for Intel IOMMU driver.
PATCH 1~3 replace per IOMMU idr name space with a global one. Current per IOMMU idr doesn't work in some cases where one application (associated with a PASID) might talk to two physical devices simultaneously while the two devices could reside behind two different IOMMU units.
PATCH 4~9 implement per domain PASID table. Current per IOMMU PASID table implementation is insecure in the cases where multiple devices under one single IOMMU unit support PASID feature. With per domain PASID table, we can achieve finer protection and isolation granularity.
Best regards,
Lu Baolu
Lu Baolu (9):
iommu/vt-d: Global PASID name space iommu/vt-d: Decouple idr bond pointer from svm iommu/vt-d: Use global PASID for SVM usage iommu/vt-d: Move device_domain_info to header iommu/vt-d: Per domain pasid table interfaces iommu/vt-d: Allocate and free pasid table iommu/vt-d: Calculate PTS value
iommu/vt-d: Use per-domain pasid table iommu/vt-d: Clean up PASID talbe management for SVM
drivers/iommu/Makefile | 2 +- drivers/iommu/intel-iommu.c | 122 +++++++++++++++------------------------ drivers/iommu/intel-pasid.c | 135 ++++++++++++++++++++++++++++++++++++++++++++ drivers/iommu/intel-pasid.h | 34 +++++++++++ drivers/iommu/intel-svm.c | 98 ++++++++++++++++---------------- include/linux/intel-iommu.h | 90 +++++++++++++++++++++++++++-- 6 files changed, 346 insertions(+), 135 deletions(-) create mode 100644 drivers/iommu/intel-pasid.c create mode 100644 drivers/iommu/intel-pasid.h
Signature · 1 line
2.7.4
PATCH 1/9 iommu/vt-d: Global PASID name space
This adds the system wide PASID name space for the PASID allocation. Currently we are using per IOMMU PASID name spaces which are not suitable for some use cases. For an example, one application (associated with a PASID) might talk to two physical devices simultaneously while the two devices could reside behind two different IOMMU units.
--- drivers/iommu/Makefile | 2 +- drivers/iommu/intel-iommu.c | 13 ++++++++++ drivers/iommu/intel-pasid.c | 60 +++++++++++++++++++++++++++++++++++++++++++++ drivers/iommu/intel-pasid.h | 30 +++++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 drivers/iommu/intel-pasid.c create mode 100644 drivers/iommu/intel-pasid.h
drivers/iommu/Makefile +1 -1
@@ -14,7 +14,7 @@ obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o obj-$(CONFIG_ARM_SMMU) += arm-smmu.o obj-$(CONFIG_ARM_SMMU_V3) += arm-smmu-v3.o obj-$(CONFIG_DMAR_TABLE) += dmar.o -obj-$(CONFIG_INTEL_IOMMU) += intel-iommu.o +obj-$(CONFIG_INTEL_IOMMU) += intel-iommu.o intel-pasid.o obj-$(CONFIG_INTEL_IOMMU_SVM) += intel-svm.o obj-$(CONFIG_IPMMU_VMSA) += ipmmu-vmsa.o obj-$(CONFIG_IRQ_REMAP) += intel_irq_remapping.o irq_remapping.o
drivers/iommu/intel-iommu.c +13 -0
@@ -53,6 +53,7 @@#include <asm/iommu.h> #include "irq_remapping.h" +#include "intel-pasid.h" #define ROOT_SIZE VTD_PAGE_SIZE#define CONTEXT_SIZE VTD_PAGE_SIZE
@@ -3265,6 +3266,18 @@ static int __init init_dmars(void) }for_each_active_iommu (iommu, drhd) { +/* +* Find the max pasid size of all IOMMU's in the system. +* we need to ensure the system pasid table is no bigger +* than the smallest supported. +*/ +if (pasid_enabled (iommu)) { +u32 temp =2 <<ecap_pss (iommu->ecap); + + intel_pasid_max_id =min_t (u32, temp, + intel_pasid_max_id); + } + g_iommus[iommu->seq_id] = iommu;intel_iommu_init_qi (iommu);
drivers/iommu/intel-pasid.c new file +60 -0
60 lines not on this page · raw message
drivers/iommu/intel-pasid.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* intel-pasid.h - PASID idr, table and entry header +* +* Copyright (C) 2018 Intel Corporation +* +* Author: Lu Baolu <baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]> +*/ + +#ifndef __INTEL_PASID_H +#define __INTEL_PASID_H + +/* +* Eventually I'm promised we will get a multi-level PASID table +* and it won't have to be physically contiguous. Until then, +* limit the size because 8MiB contiguous allocations can be hard +* to come by. The limit of 0x20000, which is 1MiB for each of +* the PASID and PASID-state tables, is somewhat arbitrary. +* +* PASID 0 is reserved in caching mode (virtualised IOMMU). +*/ +#define PASID_MIN 0x1 +#define PASID_MAX 0x20000 + +extern u32 intel_pasid_max_id; +int intel_pasid_alloc_id (void *ptr,int start,int end,gfp_t gfp); +void intel_pasid_free_id (int pasid); +void *intel_pasid_lookup_id (int pasid); + +#endif /* __INTEL_PASID_H */
Signature · 1 line
2.7.4
RE: [PATCH 1/9] iommu/vt-d: Global PASID name space
Quoted 9 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AMThis adds the system wide PASID name space for the PASID allocation. Currently we are using per IOMMU PASID name spaces which are not suitable for some use cases. For an example, one application (associated with a PASID) might talk to two physical devices simultaneously while the two devices could reside behind two different IOMMU units.
Looks good to me.
Quoted 165 lines
Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>Suggested-by Ashok Raj <[email protected]>Reviewed-by Kevin Tian <[email protected]>--- drivers/iommu/Makefile | 2 +- drivers/iommu/intel-iommu.c | 13 ++++++++++ drivers/iommu/intel-pasid.c | 60 +++++++++++++++++++++++++++++++++++++++++++++ drivers/iommu/intel-pasid.h | 30 +++++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 drivers/iommu/intel-pasid.c create mode 100644 drivers/iommu/intel-pasid.hdrivers/iommu/Makefile +1
-1@@ -14,7 +14,7 @@ obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o obj-$(CONFIG_ARM_SMMU) += arm-smmu.o obj-$(CONFIG_ARM_SMMU_V3) += arm-smmu-v3.o obj-$(CONFIG_DMAR_TABLE) += dmar.o -obj-$(CONFIG_INTEL_IOMMU) += intel-iommu.o +obj-$(CONFIG_INTEL_IOMMU) += intel-iommu.o intel-pasid.o obj-$(CONFIG_INTEL_IOMMU_SVM) += intel-svm.o obj-$(CONFIG_IPMMU_VMSA) += ipmmu-vmsa.o obj-$(CONFIG_IRQ_REMAP) += intel_irq_remapping.o irq_remapping.odrivers/iommu/intel-iommu.c +13
-0@@ -53,6 +53,7 @@#include <asm/iommu.h> #include "irq_remapping.h" +#include "intel-pasid.h" #define ROOT_SIZE VTD_PAGE_SIZE#define CONTEXT_SIZE VTD_PAGE_SIZE@@ -3265,6 +3266,18 @@ static int __init init_dmars(void) }for_each_active_iommu (iommu, drhd) { +/* +* Find the max pasid size of all IOMMU's in the system. +* we need to ensure the system pasid table is no bigger +* than the smallest supported. +*/ +if (pasid_enabled (iommu)) { +u32 temp =2 <<ecap_pss (iommu->ecap); + + intel_pasid_max_id =min_t (u32, temp, + intel_pasid_max_id); + } + g_iommus[iommu->seq_id] = iommu;intel_iommu_init_qi (iommu);drivers/iommu/intel-pasid.c new file +60
-0@@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0 +/** +* intel-pasid.c - PASID idr, table and entry manipulation +* +* Copyright (C) 2018 Intel Corporation +* +* Author: Lu Baolu <baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]> +*/ + +#define pr_fmt (fmt) "DMAR: " fmt + +#include <linux/dmar.h> +#include <linux/intel-iommu.h> +#include <linux/iommu.h> +#include <linux/memory.h> +#include <linux/spinlock.h> + +#include "intel-pasid.h" + +/* +* Intel IOMMU global PASID pool: +*/ +static DEFINE_SPINLOCK (pasid_lock); +u32 intel_pasid_max_id =PASID_MAX ; +static DEFINE_IDR (pasid_idr); + +int intel_pasid_alloc_id (void *ptr,int start,int end,gfp_t gfp) +{ +int ret, min, max; + + min =max_t (int, start,PASID_MIN ); + max =min_t (int, end, intel_pasid_max_id); + +WARN_ON (in_interrupt ()); +idr_preload (gfp); +spin_lock (&pasid_lock); + ret =idr_alloc (&pasid_idr, ptr, min, max,GFP_ATOMIC ); +spin_unlock (&pasid_lock); +idr_preload_end (); + +return ret; +} + +void intel_pasid_free_id (int pasid) +{ +spin_lock (&pasid_lock); +idr_remove (&pasid_idr, pasid); +spin_unlock (&pasid_lock); +} + +void *intel_pasid_lookup_id (int pasid) +{ +void *p; + +spin_lock (&pasid_lock); + p =idr_find (&pasid_idr, pasid); +spin_unlock (&pasid_lock); + +return p; +}drivers/iommu/intel-pasid.h new file +30
-1@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* intel-pasid.h - PASID idr, table and entry header +* +* Copyright (C) 2018 Intel Corporation +* +* Author: Lu Baolu <baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]> +*/ + +#ifndef __INTEL_PASID_H +#define __INTEL_PASID_H + +/* +* Eventually I'm promised we will get a multi-level PASID table +* and it won't have to be physically contiguous. Until then, +* limit the size because 8MiB contiguous allocations can be hard +* to come by. The limit of 0x20000, which is 1MiB for each of +* the PASID and PASID-state tables, is somewhat arbitrary. +* +* PASID 0 is reserved in caching mode (virtualised IOMMU). +*/ +#define PASID_MIN 0x1 +#define PASID_MAX 0x20000 + +extern u32 intel_pasid_max_id; +int intel_pasid_alloc_id (void *ptr,int start,int end,gfp_t gfp); +void intel_pasid_free_id (int pasid); +void *intel_pasid_lookup_id (int pasid); + +#endif /* __INTEL_PASID_H */ --2.7.4
PATCH 2/9 iommu/vt-d: Decouple idr bond pointer from svm
In reply to Lu BaoluAs we move the PASID idr out of SVM code and make it serving as a global PASID name space, the consumer can specify a ptr to bind it with a PASID. We shouldn't assume that each PASID will be bond with a ptr of struct intel_svm anymore.
This patch cleans up a idr_for_each_entry() usage in the SVM code. It's required to replace the SVM-specific idr with the global PASID idr.
--- drivers/iommu/intel-svm.c | 14 ++++++++++---- include/linux/intel-iommu.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-)
drivers/iommu/intel-svm.c +10 -4
@@ -298,6 +298,7 @@ static const struct mmu_notifier_ops intel_mmuops = { };static DEFINE_MUTEX (pasid_mutex); +static LIST_HEAD (global_svm_list);int intel_svm_bind_mm (struct device *dev,int *pasid,int flags,struct svm_dev_ops *ops) {
@@ -329,13 +330,13 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_mutex_lock (&pasid_mutex);if (pasid && !(flags &SVM_FLAG_PRIVATE_PASID )) { -int i; +struct intel_svm *t; -idr_for_each_entry (&iommu->pasid_idr, svm, i) { -if (svm->mm != mm || - (svm->flags &SVM_FLAG_PRIVATE_PASID )) +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",
@@ -404,6 +405,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_ svm->mm = mm; svm->flags = flags;INIT_LIST_HEAD_RCU (&svm->devs); +INIT_LIST_HEAD (&svm->list); ret = -ENOMEM ;if (mm) { ret =mmu_notifier_register (&svm->notifier, mm);
@@ -430,6 +432,8 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_*/ if (cap_caching_mode (iommu->cap))intel_flush_pasid_dev (svm, sdev, svm->pasid); + +list_add_tail (&svm->list, &global_svm_list); }list_add_rcu (&sdev->list, &svm->devs);
@@ -485,6 +489,8 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)if (svm->mm)mmu_notifier_unregister (&svm->notifier, svm->mm); +list_del (&svm->list); +/* 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.
include/linux/intel-iommu.h +1 -0
@@ -486,6 +486,7 @@ struct intel_svm {int flags;int pasid;struct list_head devs; +struct list_head list; };extern int intel_iommu_enable_pasid (struct intel_iommu *iommu,struct intel_svm_dev *sdev);
Signature · 1 line
2.7.4
RE: [PATCH 2/9] iommu/vt-d: Decouple idr bond pointer from svm
Quoted 12 lines
From: Lu Baolu [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AM
Subject: [PATCH 2/9] iommu/vt-d: Decouple idr bond pointer from svmAs we move the PASID idr out of SVM code and make it serving as a global PASID name space, the consumer can specify a ptr to bind it with a PASID. We shouldn't assume that each PASID will be bond with a ptr of struct
intel_svmanymore. This patch cleans up aidr_for_each_entry()usage in the SVM code. It's required to replace the SVM-specific idr with the global PASID idr.
Quoted 6 lines
Cc Ashok Raj <[email protected]>Cc Jacob Pan <[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>Signed-off-by Lu Baolu <[email protected]>Reviewed-by Kevin Tian <[email protected]>
Looks good to me.
Regards,
Yi Liu
Quoted 84 lines
drivers/iommu/intel-svm.c | 14 ++++++++++---- include/linux/intel-iommu.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-)drivers/iommu/intel-svm.c +1
-0@@ -298,6 +298,7 @@ static const struct mmu_notifier_ops intel_mmuops = { };static DEFINE_MUTEX (pasid_mutex); +static LIST_HEAD (global_svm_list);int intel_svm_bind_mm (struct device *dev,int *pasid,int flags,struct svm_dev_ops *ops){
drivers/iommu/intel-svm.c +0
-0@@ -329,13 +330,13 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, intflags, struct
svm_dev_drivers/iommu/intel-svm.c +4
-4mutex_lock (&pasid_mutex);if (pasid && !(flags &SVM_FLAG_PRIVATE_PASID )) { -int i; +struct intel_svm *t; -idr_for_each_entry (&iommu->pasid_idr, svm, i) { -if (svm->mm != mm || - (svm->flags &SVM_FLAG_PRIVATE_PASID )) +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 existingPASID %d\n",
drivers/iommu/intel-svm.c +0
-0@@ -404,6 +405,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, intflags, struct
svm_dev_drivers/iommu/intel-svm.c +1
-0svm->mm = mm; svm->flags = flags;INIT_LIST_HEAD_RCU (&svm->devs); +INIT_LIST_HEAD (&svm->list); ret = -ENOMEM ;if (mm) { ret =mmu_notifier_register (&svm->notifier, mm);@@ -430,6 +432,8 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, intflags, struct
svm_dev_drivers/iommu/intel-svm.c +4
-0*/ if (cap_caching_mode (iommu->cap))intel_flush_pasid_dev (svm, sdev, svm->pasid); + +list_add_tail (&svm->list, &global_svm_list); }list_add_rcu (&sdev->list, &svm->devs);@@ -485,6 +489,8 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)if (svm->mm)mmu_notifier_unregister (&svm- >notifier, svm->mm); +list_del (&svm->list); +/* We mandate that no page faults may be outstanding
* for the PASID whenintel_svm_unbind_mm()is called.
* If that is not obeyed, subtle errors will
happen.include/linux/intel-iommu.h +1
-0@@ -486,6 +486,7 @@ struct intel_svm {int flags;int pasid;struct list_head devs; +struct list_head list; }; extern int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct
intel_svm_dev*sdev);
--
2.7.4
PATCH 3/9 iommu/vt-d: Use global PASID for SVM usage
In reply to Lu BaoluThis patch switches PASID management for SVM from per iommu idr to the global idr.
--- drivers/iommu/intel-svm.c | 22 +++++++++++----------- include/linux/intel-iommu.h | 1 - 2 files changed, 11 insertions(+), 12 deletions(-)
drivers/iommu/intel-svm.c +11 -11
@@ -26,6 +26,8 @@#include <linux/interrupt.h> #include <asm/page.h> +#include "intel-pasid.h" +#define PASID_ENTRY_P BIT_ULL(0)#define PASID_ENTRY_FLPM_5LP BIT_ULL(9)#define PASID_ENTRY_SRE BIT_ULL(11)
@@ -85,8 +87,6 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu) iommu->name); } -idr_init (&iommu->pasid_idr); -return 0 ; }
@@ -102,7 +102,7 @@ int intel_svm_free_pasid_tables(struct intel_iommu *iommu)free_pages ((unsigned long )iommu->pasid_state_table, order); iommu->pasid_state_table =NULL ; } -idr_destroy (&iommu->pasid_idr); +return 0 ; }
@@ -392,9 +392,9 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_ pasid_max = iommu->pasid_max;/* Do not use PASID 0 in caching mode (virtualised IOMMU) */ - ret =idr_alloc (&iommu->pasid_idr, svm, - !!cap_caching_mode (iommu->cap), - pasid_max -1 ,GFP_KERNEL ); + ret =intel_pasid_alloc_id (svm, + !!cap_caching_mode (iommu->cap), + pasid_max -1 ,GFP_KERNEL );if (ret <0 ) {kfree (svm);kfree (sdev);
@@ -410,7 +410,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_if (mm) { ret =mmu_notifier_register (&svm->notifier, mm);if (ret) { -idr_remove (&svm->iommu->pasid_idr, svm->pasid); +intel_pasid_free_id (svm->pasid);kfree (svm);kfree (sdev); goto out;
@@ -460,7 +460,7 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)if (!iommu || !iommu->pasid_table) goto out; - svm =idr_find (&iommu->pasid_idr, pasid); + svm =intel_pasid_lookup_id (pasid);if (!svm) goto out;
@@ -485,7 +485,7 @@ int intel_svm_unbind_mm(struct device *dev, int pasid) svm->iommu->pasid_table[svm->pasid].val =0 ;wmb (); -idr_remove (&svm->iommu->pasid_idr, svm->pasid); +intel_pasid_free_id (svm->pasid);if (svm->mm)mmu_notifier_unregister (&svm->notifier, svm->mm);
@@ -520,7 +520,7 @@ int intel_svm_is_pasid_valid(struct device *dev, int pasid)if (!iommu || !iommu->pasid_table) goto out; - svm =idr_find (&iommu->pasid_idr, pasid); + svm =intel_pasid_lookup_id (pasid);if (!svm) goto out;
@@ -618,7 +618,7 @@ static irqreturn_t prq_event_thread(int irq, void *d)if (!svm || svm->pasid != req->pasid) {rcu_read_lock (); - svm =idr_find (&iommu->pasid_idr, req->pasid); + svm =intel_pasid_lookup_id (req->pasid);/* It *can't* go away, because the driver is not permitted * to unbind the mm while any page faults are outstanding. * So we only need RCU to protect the internal idr code. */
include/linux/intel-iommu.h +0 -1
@@ -418,7 +418,6 @@ struct intel_iommu {struct pasid_state_entry *pasid_state_table;struct page_req_dsc *prq;unsigned char prq_name[16 ];/* Name for PRQ interrupt */ -struct idr pasid_idr;u32 pasid_max;#endif struct q_inval *qi;/* Queued invalidation info */
Signature · 1 line
2.7.4
RE: [PATCH 3/9] iommu/vt-d: Use global PASID for SVM usage
Quoted 10 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AM
This patch switches PASID management for SVM from per iommu idr to the global idr.Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>Reviewed-by Kevin Tian <[email protected]>
Looks good to me.
Regards,
Yi Liu
Quoted 113 lines
--- drivers/iommu/intel-svm.c | 22 +++++++++++----------- include/linux/intel-iommu.h | 1 - 2 files changed, 11 insertions(+), 12 deletions(-)drivers/iommu/intel-svm.c index renamed from drivers/iommu/intel-svm.c +0
-0983af0c..24d0ea1 100644
drivers/iommu/intel-svm.c +3
-3@@ -26,6 +26,8 @@#include <linux/interrupt.h> #include <asm/page.h> +#include "intel-pasid.h" +#define PASID_ENTRY_P BIT_ULL(0)#define PASID_ENTRY_FLPM_5LP BIT_ULL(9)#define PASID_ENTRY_SRE BIT_ULL(11)@@ -85,8 +87,6 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu) iommu->name); } -idr_init (&iommu->pasid_idr); -return 0 ; }@@ -102,7 +102,7 @@ int intel_svm_free_pasid_tables(struct intel_iommu *iommu)free_pages ((unsigned long )iommu->pasid_state_table, order); iommu->pasid_state_table =NULL ; } -idr_destroy (&iommu->pasid_idr); +return 0 ; }@@ -392,9 +392,9 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, intflags, struct
svm_dev_drivers/iommu/intel-svm.c +3
-3pasid_max = iommu->pasid_max;/* Do not use PASID 0 in caching mode (virtualised IOMMU) */ - ret =idr_alloc (&iommu->pasid_idr, svm, - !!cap_caching_mode (iommu->cap), - pasid_max -1 ,GFP_KERNEL ); + ret =intel_pasid_alloc_id (svm, + !!cap_caching_mode (iommu->cap), + pasid_max -1 ,GFP_KERNEL );if (ret <0 ) {kfree (svm);kfree (sdev);@@ -410,7 +410,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, intflags, struct
svm_dev_drivers/iommu/intel-svm.c +3
-3if (mm) { ret =mmu_notifier_register (&svm->notifier, mm);if (ret) { -idr_remove (&svm->iommu->pasid_idr, svm->pasid); +intel_pasid_free_id (svm->pasid);kfree (svm);kfree (sdev); goto out;@@ -460,7 +460,7 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)if (!iommu || !iommu->pasid_table) goto out; - svm =idr_find (&iommu->pasid_idr, pasid); + svm =intel_pasid_lookup_id (pasid);if (!svm) goto out;@@ -485,7 +485,7 @@ int intel_svm_unbind_mm(struct device *dev, int pasid) svm->iommu->pasid_table[svm->pasid].val =0 ;wmb (); -idr_remove (&svm->iommu->pasid_idr, svm->pasid); +intel_pasid_free_id (svm->pasid);if (svm->mm)mmu_notifier_unregister(&svm-
Quoted 1 line
notifier,
svm->mm);drivers/iommu/intel-svm.c +2
-2@@ -520,7 +520,7 @@ int intel_svm_is_pasid_valid(struct device *dev, int pasid)if (!iommu || !iommu->pasid_table) goto out; - svm =idr_find (&iommu->pasid_idr, pasid); + svm =intel_pasid_lookup_id (pasid);if (!svm) goto out;@@ -618,7 +618,7 @@ static irqreturn_t prq_event_thread(int irq, void *d)if (!svm || svm->pasid != req->pasid) {rcu_read_lock (); - svm =idr_find (&iommu->pasid_idr, req->pasid); + svm =intel_pasid_lookup_id (req->pasid);/* It *can't* go away, because the driver is not permitted * to unbind the mm while any page faults are outstanding. * So we only need RCU to protect the internal idr code. */ include/linux/intel-iommu.h index renamed from include/linux/intel-iommu.h +0
-0795717e..6b5ef6c 100644
include/linux/intel-iommu.h +0
-2@@ -418,7 +418,6 @@ struct intel_iommu {struct pasid_state_entry *pasid_state_table;struct page_req_dsc *prq;unsigned char prq_name[16 ];/* Name for PRQ interrupt */ -struct idr pasid_idr;u32 pasid_max;#endif struct q_inval *qi;/* Queued invalidation info */ --2.7.4
PATCH 4/9 iommu/vt-d: Move device_domain_info to header
In reply to Lu BaoluThis allows the per device iommu data to be accessed from other files.
--- drivers/iommu/intel-iommu.c | 62 +++-------------------------------------- include/linux/intel-iommu.h | 68 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 58 deletions(-)
drivers/iommu/intel-iommu.c +4 -58
@@ -381,60 +381,6 @@ static int hw_pass_through = 1;for (idx =0 ; idx < g_num_of_iommus; idx++) \if (domain->iommu_refcnt[idx]) -struct dmar_domain { -int nid;/* node id */ - -unsigned iommu_refcnt[DMAR_UNITS_SUPPORTED ]; -/* Refcount of devices per iommu */ - - -u16 iommu_did[DMAR_UNITS_SUPPORTED ]; -/* Domain ids per IOMMU. Use u16 since -* domain ids are 16 bit wide according -* to VT-d spec, section 9.3 */ - -bool has_iotlb_device; -struct list_head devices;/* all devices' list */ -struct iova_domain iovad;/* iova's that belong to this domain */ - -struct dma_pte *pgd;/* virtual address */ -int gaw;/* max guest address width */ - -/* adjusted guest address width, 0 is level 2 30-bit */ -int agaw; - -int flags;/* flags to find out type of domain */ - -int iommu_coherency;/* indicate coherency of iommu access */ -int iommu_snooping;/* indicate snooping control feature*/ -int iommu_count;/* reference count of iommu */ -int iommu_superpage;/* Level of superpages supported: -0 == 4KiB (no superpages), 1 == 2MiB, -2 == 1GiB, 3 == 512GiB, 4 == 1TiB */ -u64 max_addr;/* maximum mapped address */ - -struct iommu_domain domain;/* generic domain data structure for -iommu core */ -}; - -/* PCI domain-device relationship */ -struct device_domain_info { -struct list_head link;/* link to domain siblings */ -struct list_head global;/* link to global list */ -u8 bus;/* PCI bus number */ -u8 devfn;/* PCI devfn number */ -u8 pasid_supported:3 ; -u8 pasid_enabled:1 ; -u8 pri_supported:1 ; -u8 pri_enabled:1 ; -u8 ats_supported:1 ; -u8 ats_enabled:1 ; -u8 ats_qdep; -struct device *dev;/* it's NULL for PCIe-to-PCI bridge */ -struct intel_iommu *iommu;/* IOMMU used by this device */ -struct dmar_domain *domain;/* pointer to domain */ -}; - struct dmar_rmrr_unit {struct list_head list;/* list of rmrr units */ struct acpi_dmar_header *hdr;/* ACPI header */
@@ -631,7 +577,7 @@ static void set_iommu_domain(struct intel_iommu *iommu, u16 did, domains[did &0xff ] = domain; } -static inline void *alloc_pgtable_page (int node) +void *alloc_pgtable_page (int node) {struct page *page;void *vaddr =NULL ;
@@ -642,7 +588,7 @@ static inline void *alloc_pgtable_page(int node)return vaddr; } -static inline void free_pgtable_page (void *vaddr) +void free_pgtable_page (void *vaddr) {free_page ((unsigned long )vaddr); }
@@ -725,7 +671,7 @@ int iommu_calculate_agaw(struct intel_iommu *iommu) }/* This functionin only returns single iommu in a domain */ -static struct intel_iommu *domain_get_iommu (struct dmar_domain *domain) +struct intel_iommu *domain_get_iommu (struct dmar_domain *domain) {int iommu_id;
@@ -3500,7 +3446,7 @@ static unsigned long intel_alloc_iova(struct device *dev,return iova_pfn; } -static struct dmar_domain *get_valid_domain_for_dev (struct device *dev) +struct dmar_domain *get_valid_domain_for_dev (struct device *dev) {struct dmar_domain *domain, *tmp;struct dmar_rmrr_unit *rmrr;
include/linux/intel-iommu.h +68 -0
92 lines not on this page · raw message
Signature · 1 line
2.7.4
RE: [PATCH 4/9] iommu/vt-d: Move device_domain_info to header
Quoted 11 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AMThis allows the per device iommu data to be accessed from other files.
Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>
Looks good to me.
Regards,
Yi Liu
Quoted 213 lines
--- drivers/iommu/intel-iommu.c | 62 +++-------------------------------------- include/linux/intel-iommu.h | 68 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 58 deletions(-)drivers/iommu/intel-iommu.c +0
-54@@ -381,60 +381,6 @@ static int hw_pass_through = 1;for (idx = 0; idx < g_num_of_iommus; idx++) \ if (domain->iommu_refcnt[idx]) -struct dmar_domain { -int nid;/* node id */ - -unsigned iommu_refcnt[DMAR_UNITS_SUPPORTED ]; -/* Refcount of devices per iommu */ - - -u16 iommu_did[DMAR_UNITS_SUPPORTED ]; -/* Domain ids per IOMMU. Use u16 since -* domain ids are 16 bit wide according -* to VT-d spec, section 9.3 */ - -bool has_iotlb_device; -struct list_head devices;/* all devices' list */ -struct iova_domain iovad;/* iova's that belong to this domain */ - -struct dma_pte *pgd;/* virtual address */ -int gaw;/* max guest address width */ - -/* adjusted guest address width, 0 is level 2 30-bit */ -int agaw; - -int flags;/* flags to find out type of domain */ - -int iommu_coherency;/* indicate coherency of iommu access */ -int iommu_snooping;/* indicate snooping control feature*/ -int iommu_count;/* reference count of iommu */ -int iommu_superpage;/* Level of superpages supported: -0 == 4KiB (no superpages), 1 == 2MiB, -2 == 1GiB, 3 == 512GiB, 4 == 1TiB */ -u64 max_addr;/* maximum mapped address */ - -struct iommu_domain domain;/* generic domain data structure for -iommu core */ -}; - -/* PCI domain-device relationship */ -struct device_domain_info { -struct list_head link;/* link to domain siblings */ -struct list_head global;/* link to global list */ -u8 bus;/* PCI bus number */ -u8 devfn;/* PCI devfn number */ -u8 pasid_supported:3 ; -u8 pasid_enabled:1 ; -u8 pri_supported:1 ; -u8 pri_enabled:1 ; -u8 ats_supported:1 ; -u8 ats_enabled:1 ; -u8 ats_qdep; -struct device *dev;/* it's NULL for PCIe-to-PCI bridge */ -struct intel_iommu *iommu;/* IOMMU used by this device */ -struct dmar_domain *domain;/* pointer to domain */ -}; -struct dmar_rmrr_unit {struct list_head list;/* list of rmrr units */ drivers/iommu/intel-iommu.c +1
-1struct acpi_dmar_header *hdr;/* ACPI header */ @@ -631,7 +577,7 @@ static void set_iommu_domain(struct intel_iommu *iommu,u16 did, domains[did &0xff ] = domain; } -static inline void *alloc_pgtable_page (int node) +void *alloc_pgtable_page (int node) {struct page *page;drivers/iommu/intel-iommu.c +3
-3void *vaddr =NULL ;@@ -642,7 +588,7 @@ static inline void *alloc_pgtable_page(int node)return vaddr; } -static inline void free_pgtable_page (void *vaddr) +void free_pgtable_page (void *vaddr) {free_page ((unsigned long )vaddr); }@@ -725,7 +671,7 @@ int iommu_calculate_agaw(struct intel_iommu *iommu) }/* This functionin only returns single iommu in a domain */ -static struct intel_iommu *domain_get_iommu (struct dmar_domain *domain) +struct intel_iommu *domain_get_iommu (struct dmar_domain *domain) {int iommu_id;@@ -3500,7 +3446,7 @@ static unsigned long intel_alloc_iova(struct device *dev,return iova_pfn; } -static struct dmar_domain *get_valid_domain_for_dev (struct device *dev) +struct dmar_domain *get_valid_domain_for_dev (struct device *dev) {struct dmar_domain *domain, *tmp;struct dmar_rmrr_unit *rmrr;include/linux/intel-iommu.h +45
-0@@ -31,6 +31,7 @@#include <linux/list.h> #include <linux/iommu.h> #include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/dmar.h> #include <asm/cacheflush.h> #include <asm/iommu.h> @@ -385,6 +386,50 @@ struct pasid_entry;struct pasid_state_entry ;struct page_req_dsc ; +struct dmar_domain { +int nid;/* node id */ + +unsigned int iommu_refcnt[DMAR_UNITS_SUPPORTED ]; +/* Refcount of devices per iommu */ + +u16 iommu_did[DMAR_UNITS_SUPPORTED ]; +/* +* Domain ids per IOMMU. Use u16 since +* domain ids are 16 bit wide according +* to VT-d spec, section 9.3 +*/ + +bool has_iotlb_device; +struct list_head devices;/* all devices' list */ +struct iova_domain iovad;/* iova's that belong to this domain */ + +struct dma_pte *pgd;/* virtual address */ +int gaw;/* max guest address width */ + +int agaw;/* +* adjusted guest address width, +* 0 is level 2 30-bit +*/ + +int flags;/* flags to find out type of domain */ + +int iommu_coherency;/* indicate coherency of iommu access */ +int iommu_snooping;/* indicate snooping control feature*/ +int iommu_count;/* reference count of iommu */ +int iommu_superpage;/* +* Level of superpages supported: +* 0 == 4KiB (no superpages), +* 1 == 2MiB, 2 == 1GiB, +* 3 == 512GiB, 4 == 1TiB +*/ +u64 max_addr;/* maximum mapped address */ + +struct iommu_domain domain;/* +* generic domain data structure for +* iommu core +*/ +}; +struct intel_iommu {void __iomem *reg;/* Pointer to hardware regs, virtual addr */ include/linux/intel-iommu.h +23
-0u64 reg_phys;/* physical address of hw register set */ @@ -433,6 +478,24 @@ struct intel_iommu {u32 flags;/* Software defined flags */ }; +/* PCI domain-device relationship */ +struct device_domain_info { +struct list_head link;/* link to domain siblings */ +struct list_head global;/* link to global list */ +u8 bus;/* PCI bus number */ +u8 devfn;/* PCI devfn number */ +u8 pasid_supported:3 ; +u8 pasid_enabled:1 ; +u8 pri_supported:1 ; +u8 pri_enabled:1 ; +u8 ats_supported:1 ; +u8 ats_enabled:1 ; +u8 ats_qdep; +struct device *dev;/* it's NULL for PCIe-to-PCI bridge */ +struct intel_iommu *iommu;/* IOMMU used by this device */ +struct dmar_domain *domain;/* pointer to domain */ +}; +static inline void __iommu_flush_cache (struct intel_iommu *iommu,void *addr,int size) {@@ -459,6 +522,11 @@ extern int qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu);extern int dmar_ir_support (void ); +struct dmar_domain *get_valid_domain_for_dev (struct device *dev); +void *alloc_pgtable_page (int node); +void free_pgtable_page (void *vaddr); +struct intel_iommu *domain_get_iommu (struct dmar_domain *domain); +#ifdef CONFIG_INTEL_IOMMU_SVM extern int intel_svm_alloc_pasid_tables (struct intel_iommu *iommu);extern int
intel_svm_free_pasid_tables(struct intel_iommu *iommu);
--
2.7.4
PATCH 5/9 iommu/vt-d: Per domain pasid table interfaces
In reply to Lu BaoluThis patch adds the interfaces for per domain pasid table management. Currently we allocate one pasid table for all devices under the scope of an IOMMU. It's insecure in the cases where multiple devices under one single IOMMU unit support PASID feature. With per domain pasid table, we can achieve finer protection and isolation granularity.
--- drivers/iommu/intel-pasid.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ drivers/iommu/intel-pasid.h | 4 +++ include/linux/intel-iommu.h | 5 +++ 3 files changed, 84 insertions(+)
drivers/iommu/intel-pasid.c +75 -0
@@ -13,6 +13,7 @@#include <linux/intel-iommu.h> #include <linux/iommu.h> #include <linux/memory.h> +#include <linux/pci.h> #include <linux/spinlock.h> #include "intel-pasid.h"
@@ -58,3 +59,77 @@ void *intel_pasid_lookup_id(int pasid)return p; } + +/* +* Interfaces for per domain pasid table management: +*/ +int intel_pasid_alloc_table (struct device *dev,size_t entry_size, +size_t entry_count) +{ +struct device_domain_info *info; +struct dmar_domain *domain; +struct page *pages; +int order; + + info = dev->archdata.iommu; +if (WARN_ON (!info || !dev_is_pci (dev) || + !info->pasid_supported || + !info->domain)) +return -EINVAL ; + + domain = info->domain; + +if (entry_count > intel_pasid_max_id) + entry_count = intel_pasid_max_id; + + order =get_order (entry_size * entry_count); + pages =alloc_pages_node (domain->nid,GFP_KERNEL | __GFP_ZERO, order); +if (!pages) +return -ENOMEM ; + +spin_lock (&pasid_lock); +if (domain->pasid_table) { +__free_pages (pages, order); + }else { + domain->pasid_table =page_address (pages); + domain->order = order; + domain->max_pasid = entry_count; + } + domain->pasid_users++; +spin_unlock (&pasid_lock); + +return 0 ; +} + +void intel_pasid_free_table (struct device *dev) +{ +struct dmar_domain *domain; + + domain =get_valid_domain_for_dev (dev); +if (!domain || !dev_is_pci (dev)) +return ; + +spin_lock (&pasid_lock); +if (domain->pasid_table) { + domain->pasid_users--; +if (!domain->pasid_users) { +free_pages ((unsigned long )domain->pasid_table, + domain->order); + domain->pasid_table =NULL ; + domain->order =0 ; + domain->max_pasid =0 ; + } + } +spin_unlock (&pasid_lock); +} + +void *intel_pasid_get_table (struct device *dev) +{ +struct dmar_domain *domain; + + domain =get_valid_domain_for_dev (dev); +if (!domain) +return NULL ; + +return domain->pasid_table; +}
drivers/iommu/intel-pasid.h +4 -0
@@ -26,5 +26,9 @@ extern u32 intel_pasid_max_id;int intel_pasid_alloc_id (void *ptr,int start,int end,gfp_t gfp);void intel_pasid_free_id (int pasid);void *intel_pasid_lookup_id (int pasid); +int intel_pasid_alloc_table (struct device *dev,size_t entry_size, +size_t entry_count); +void intel_pasid_free_table (struct device *dev); +void *intel_pasid_get_table (struct device *dev);#endif /* __INTEL_PASID_H */
include/linux/intel-iommu.h +5 -0
@@ -424,6 +424,11 @@ struct dmar_domain {*/ u64 max_addr;/* maximum mapped address */ +void *pasid_table;/* pointer of pasid table */ +unsigned int pasid_users;/* User number of pasid table */ +int order;/* the page order of tables */ +int max_pasid;/* max pasid */ +struct iommu_domain domain;/* * generic domain data structure for * iommu core
Signature · 1 line
2.7.4
RE: [PATCH 5/9] iommu/vt-d: Per domain pasid table interfaces
Quoted 59 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AMThis patch adds the interfaces for per domain pasid table management. Currently we allocate one pasid table for all devices under the scope of an IOMMU. It's insecure in the cases where multiple devices under one single IOMMU unit support PASID feature. With per domain pasid table, we can achieve finer protection and isolation granularity.
Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>Suggested-by Ashok Raj <[email protected]>--- drivers/iommu/intel-pasid.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ drivers/iommu/intel-pasid.h | 4 +++ include/linux/intel-iommu.h | 5 +++ 3 files changed, 84 insertions(+)drivers/iommu/intel-pasid.c +21
-0@@ -13,6 +13,7 @@#include <linux/intel-iommu.h> #include <linux/iommu.h> #include <linux/memory.h> +#include <linux/pci.h> #include <linux/spinlock.h> #include "intel-pasid.h" @@ -58,3 +59,77 @@ void *intel_pasid_lookup_id(int pasid)return p; } + +/* +* Interfaces for per domain pasid table management: +*/ +int intel_pasid_alloc_table (struct device *dev,size_t entry_size, +size_t entry_count) +{ +struct device_domain_info *info; +struct dmar_domain *domain; +struct page *pages; +int order; + + info = dev->archdata.iommu; +if (WARN_ON (!info || !dev_is_pci (dev) || + !info->pasid_supported || + !info->domain)) +return -EINVAL ; + + domain = info->domain; +
drivers/iommu/intel-pasid.c void *intel_pasid_lookup_id(int pasid) · line 91
Quoted 10 lines
drivers/iommu/intel-pasid.c +10
-0+if (entry_count > intel_pasid_max_id) + entry_count = intel_pasid_max_id; + + order =get_order (entry_size * entry_count); + pages =alloc_pages_node (domain->nid,GFP_KERNEL | __GFP_ZERO, order); +if (!pages) +return -ENOMEM ; + +spin_lock (&pasid_lock); +if (domain->pasid_table) {
Can the check be moved prior to the page allocation?
Quoted 25 lines
drivers/iommu/intel-pasid.c +25
-0+__free_pages (pages, order); + }else { + domain->pasid_table =page_address (pages); + domain->order = order; + domain->max_pasid = entry_count; + } + domain->pasid_users++; +spin_unlock (&pasid_lock); + +return 0 ; +} + +void intel_pasid_free_table (struct device *dev) +{ +struct dmar_domain *domain; + + domain =get_valid_domain_for_dev (dev); +if (!domain || !dev_is_pci (dev)) +return ; + +spin_lock (&pasid_lock); +if (domain->pasid_table) { + domain->pasid_users--; +if (!domain->pasid_users) { + free_pages((unsigned long)domain->pasid_table,
drivers/iommu/intel-pasid.c void *intel_pasid_lookup_id(int pasid) · line 126
Quoted 10 lines
drivers/iommu/intel-pasid.c +10
-0+ domain->order); + domain->pasid_table =NULL ; + domain->order =0 ; + domain->max_pasid =0 ; + } + } +spin_unlock (&pasid_lock); +} + +void *intel_pasid_get_table (struct device *dev)
Will intel_iommu_get_pasid_table() more accurate?
Regards,
Yi Liu
Quoted 41 lines
drivers/iommu/intel-pasid.c +9
-0+{ +struct dmar_domain *domain; + + domain =get_valid_domain_for_dev (dev); +if (!domain) +return NULL ; + +return domain->pasid_table; +}drivers/iommu/intel-pasid.h +4
-0@@ -26,5 +26,9 @@ extern u32 intel_pasid_max_id;int intel_pasid_alloc_id (void *ptr,int start,int end,gfp_t gfp);void intel_pasid_free_id (int pasid);void *intel_pasid_lookup_id (int pasid); +int intel_pasid_alloc_table (struct device *dev,size_t entry_size, +size_t entry_count); +void intel_pasid_free_table (struct device *dev); +void *intel_pasid_get_table (struct device *dev);#endif /* __INTEL_PASID_H */ include/linux/intel-iommu.h +5
-1@@ -424,6 +424,11 @@ struct dmar_domain {*/ u64 max_addr;/* maximum mapped address */ +void *pasid_table;/* pointer of pasid table */ +unsigned int pasid_users;/* User number of pasid table */ +int order;/* the page order of tables */ +int max_pasid;/* max pasid */ +struct iommu_domain domain;/* * generic domain data structure for * iommu core -- 2.7.4
Re: [PATCH 5/9] iommu/vt-d: Per domain pasid table interfaces
Hi Yi,
Thank you very much for reviewing my patches.
Quoted 62 lines · Yi L
Quoted 62 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AMThis patch adds the interfaces for per domain pasid table management. Currently we allocate one pasid table for all devices under the scope of an IOMMU. It's insecure in the cases where multiple devices under one single IOMMU unit support PASID feature. With per domain pasid table, we can achieve finer protection and isolation granularity.
Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>Suggested-by Ashok Raj <[email protected]>--- drivers/iommu/intel-pasid.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ drivers/iommu/intel-pasid.h | 4 +++ include/linux/intel-iommu.h | 5 +++ 3 files changed, 84 insertions(+)drivers/iommu/intel-pasid.c +24
-0@@ -13,6 +13,7 @@#include <linux/intel-iommu.h> #include <linux/iommu.h> #include <linux/memory.h> +#include <linux/pci.h> #include <linux/spinlock.h> #include "intel-pasid.h" @@ -58,3 +59,77 @@ void *intel_pasid_lookup_id(int pasid)return p; } + +/* +* Interfaces for per domain pasid table management: +*/ +int intel_pasid_alloc_table (struct device *dev,size_t entry_size, +size_t entry_count) +{ +struct device_domain_info *info; +struct dmar_domain *domain; +struct page *pages; +int order; + + info = dev->archdata.iommu; +if (WARN_ON (!info || !dev_is_pci (dev) || + !info->pasid_supported || + !info->domain)) +return -EINVAL ; + + domain = info->domain; + +if (entry_count > intel_pasid_max_id) + entry_count = intel_pasid_max_id; +
Quoted 8 lines
drivers/iommu/intel-pasid.c void *intel_pasid_lookup_id(int pasid) · line 91
Quoted 7 lines
drivers/iommu/intel-pasid.c +7
-0+ order =get_order (entry_size * entry_count); + pages =alloc_pages_node (domain->nid,GFP_KERNEL | __GFP_ZERO, order); +if (!pages) +return -ENOMEM ; + +spin_lock (&pasid_lock); +if (domain->pasid_table) {Can the check be moved prior to the page allocation?
I chose allocation and then assignment with lock to avoid race and possible page allocation failure.
Quoted 29 lines
Quoted 29 lines
drivers/iommu/intel-pasid.c +28
-0+__free_pages (pages, order); + }else { + domain->pasid_table =page_address (pages); + domain->order = order; + domain->max_pasid = entry_count; + } + domain->pasid_users++; +spin_unlock (&pasid_lock); + +return 0 ; +} + +void intel_pasid_free_table (struct device *dev) +{ +struct dmar_domain *domain; + + domain =get_valid_domain_for_dev (dev); +if (!domain || !dev_is_pci (dev)) +return ; + +spin_lock (&pasid_lock); +if (domain->pasid_table) { + domain->pasid_users--; +if (!domain->pasid_users) { +free_pages ((unsigned long )domain->pasid_table, + domain->order); + domain->pasid_table =NULL ; + domain->order =0 ;
Quoted 8 lines
drivers/iommu/intel-pasid.c void *intel_pasid_lookup_id(int pasid) · line 126
Quoted 7 lines
drivers/iommu/intel-pasid.c +7
-0+ domain->max_pasid =0 ; + } + } +spin_unlock (&pasid_lock); +} + +void *intel_pasid_get_table (struct device *dev)Will
intel_iommu_get_pasid_table()more accurate?
This function defines in intel-pasid.c. The name pattern for global functions defined in this function is intel_pasid_xxx_xxxx().
Quoted 4 lines
Regards,
Yi Liu
Best regards,
Lu Baolu
PATCH 6/9 iommu/vt-d: Allocate and free pasid table
In reply to Lu BaoluThis patch allocates PASID table for a domain at the time when it is being created (if any devices using this domain supports PASID feature), and free it when the domain is freed.
--- drivers/iommu/intel-iommu.c | 13 +++++++++++++ drivers/iommu/intel-svm.c | 8 -------- include/linux/intel-iommu.h | 10 ++++++++-- 3 files changed, 21 insertions(+), 10 deletions(-)
drivers/iommu/intel-iommu.c +13 -0
@@ -2460,6 +2460,18 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, dev->archdata.iommu = info;spin_unlock_irqrestore (&device_domain_lock, flags); +if (dev &&dev_is_pci (dev) && info->pasid_supported) { +if (pasid_enabled (iommu)) { +size_t size, count; + + size =sizeof (struct pasid_entry ); + count =min_t (int, +pci_max_pasids (to_pci_dev (dev)), + intel_pasid_max_id); + ret =intel_pasid_alloc_table (dev, size, count); + } + } +if (dev &&domain_context_mapping (domain, dev)) {pr_err ("Domain context map for %s failed\n" ,dev_name (dev));dmar_remove_one_dev_info (domain, dev);
@@ -4826,6 +4838,7 @@ static void dmar_remove_one_dev_info(struct dmar_domain *domain,unsigned long flags;spin_lock_irqsave (&device_domain_lock, flags); +intel_pasid_free_table (dev); info = dev->archdata.iommu;__dmar_remove_one_dev_info (info);spin_unlock_irqrestore (&device_domain_lock, flags);
drivers/iommu/intel-svm.c +0 -8
@@ -34,14 +34,6 @@static irqreturn_t prq_event_thread (int irq,void *d); -struct pasid_entry { -u64 val; -}; - -struct pasid_state_entry { -u64 val; -}; -int intel_svm_alloc_pasid_tables (struct intel_iommu *iommu) {struct page *pages;
include/linux/intel-iommu.h +8 -2
@@ -382,8 +382,14 @@ enum {#define VTD_FLAG_TRANS_PRE_ENABLED (1 << 0)#define VTD_FLAG_IRQ_REMAP_PRE_ENABLED (1 << 1) -struct pasid_entry ; -struct pasid_state_entry ; +struct pasid_entry { +u64 val; +}; + +struct pasid_state_entry { +u64 val; +}; +struct page_req_dsc ;struct dmar_domain {
Signature · 1 line
2.7.4
RE: [PATCH 6/9] iommu/vt-d: Allocate and free pasid table
Quoted 26 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AMThis patch allocates PASID table for a domain at the time when it is being created (if any devices using this domain supports PASID feature), and free it when the domain is freed.
Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>--- drivers/iommu/intel-iommu.c | 13 +++++++++++++ drivers/iommu/intel-svm.c | 8 -------- include/linux/intel-iommu.h | 10 ++++++++-- 3 files changed, 21 insertions(+), 10 deletions(-)drivers/iommu/intel-iommu.c +0
-0@@ -2460,6 +2460,18 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, dev->archdata.iommu = info;spin_unlock_irqrestore (&device_domain_lock, flags);
drivers/iommu/intel-iommu.c static struct dmar_domain · line 2472
Quoted 10 lines
drivers/iommu/intel-iommu.c +9
-0+if (dev &&dev_is_pci (dev) && info->pasid_supported) { +if (pasid_enabled (iommu)) { +size_t size, count; + + size =sizeof (struct pasid_entry ); + count =min_t (int, +pci_max_pasids (to_pci_dev (dev)), + intel_pasid_max_id); + ret =intel_pasid_alloc_table (dev, size, count);
No check for the return value?
Quoted 45 lines
drivers/iommu/intel-iommu.c +3
-0+ } + } +if (dev &&domain_context_mapping (domain, dev)) {pr_err ("Domain context map for %s failed\n" ,dev_name (dev));drivers/iommu/intel-iommu.c +1
-0dmar_remove_one_dev_info (domain, dev);@@ -4826,6 +4838,7 @@ static void dmar_remove_one_dev_info(structdmar_domain *domain, unsigned long flags;spin_lock_irqsave (&device_domain_lock, flags); +intel_pasid_free_table (dev); info = dev->archdata.iommu;__dmar_remove_one_dev_info (info);drivers/iommu/intel-iommu.c +0
-0spin_unlock_irqrestore (&device_domain_lock, flags);drivers/iommu/intel-svm.c +0
-8@@ -34,14 +34,6 @@static irqreturn_t prq_event_thread (int irq,void *d); -struct pasid_entry { -u64 val; -}; - -struct pasid_state_entry { -u64 val; -}; -int intel_svm_alloc_pasid_tables (struct intel_iommu *iommu) {struct page *pages;include/linux/intel-iommu.h +1
-2@@ -382,8 +382,14 @@ enum {#define VTD_FLAG_TRANS_PRE_ENABLED (1 << 0)#define VTD_FLAG_IRQ_REMAP_PRE_ENABLED (1 << 1) -struct pasid_entry ; -struct pasid_state_entry ; +struct pasid_entry {
include/linux/intel-iommu.h enum { · line 395
Quoted 10 lines
include/linux/intel-iommu.h +7
-0+u64 val; +}; + +struct pasid_state_entry { +u64 val; +}; +struct page_req_dsc ;struct dmar_domain {
Overall, this patch looks good to me. But need to fix the comment above.
Regards,
Yi Liu
Re: [PATCH 6/9] iommu/vt-d: Allocate and free pasid table
Hi,
Quoted 27 lines · Yi L
Quoted 27 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AMThis patch allocates PASID table for a domain at the time when it is being created (if any devices using this domain supports PASID feature), and free it when the domain is freed.
Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>--- drivers/iommu/intel-iommu.c | 13 +++++++++++++ drivers/iommu/intel-svm.c | 8 -------- include/linux/intel-iommu.h | 10 ++++++++-- 3 files changed, 21 insertions(+), 10 deletions(-)drivers/iommu/intel-iommu.c +0
-0@@ -2460,6 +2460,18 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, dev->archdata.iommu = info;spin_unlock_irqrestore (&device_domain_lock, flags);
Quoted 10 lines
drivers/iommu/intel-iommu.c static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, · line 2471
Quoted 9 lines
drivers/iommu/intel-iommu.c +9
-0+if (dev &&dev_is_pci (dev) && info->pasid_supported) { +if (pasid_enabled (iommu)) { +size_t size, count; + + size =sizeof (struct pasid_entry ); + count =min_t (int, +pci_max_pasids (to_pci_dev (dev)), + intel_pasid_max_id); + ret =intel_pasid_alloc_table (dev, size, count);No check for the return value?
Nice catch. Will fix it in a v2.
Quoted 55 lines
Quoted 55 lines
drivers/iommu/intel-iommu.c +3
-0+ } + } +if (dev &&domain_context_mapping (domain, dev)) {pr_err ("Domain context map for %s failed\n" ,dev_name (dev));drivers/iommu/intel-iommu.c +1
-0dmar_remove_one_dev_info (domain, dev);@@ -4826,6 +4838,7 @@ static void dmar_remove_one_dev_info(structdmar_domain *domain, unsigned long flags;spin_lock_irqsave (&device_domain_lock, flags); +intel_pasid_free_table (dev); info = dev->archdata.iommu;__dmar_remove_one_dev_info (info);drivers/iommu/intel-iommu.c +0
-0spin_unlock_irqrestore (&device_domain_lock, flags);drivers/iommu/intel-svm.c +0
-8@@ -34,14 +34,6 @@static irqreturn_t prq_event_thread (int irq,void *d); -struct pasid_entry { -u64 val; -}; - -struct pasid_state_entry { -u64 val; -}; -int intel_svm_alloc_pasid_tables (struct intel_iommu *iommu) {struct page *pages;include/linux/intel-iommu.h +8
-2@@ -382,8 +382,14 @@ enum {#define VTD_FLAG_TRANS_PRE_ENABLED (1 << 0)#define VTD_FLAG_IRQ_REMAP_PRE_ENABLED (1 << 1) -struct pasid_entry ; -struct pasid_state_entry ; +struct pasid_entry { +u64 val; +}; + +struct pasid_state_entry { +u64 val; +}; +struct page_req_dsc ;
Quoted 7 lines
include/linux/intel-iommu.h enum { · line 395
Quoted 1 line
include/linux/intel-iommu.h +0
-0struct dmar_domain {Overall, this patch looks good to me. But need to fix the comment above.
Reviewed-by Liu, Yi L <[email protected]>Regards,
Yi Liu
Sure.
Best regards,
Lu Baolu
PATCH 7/9 iommu/vt-d: Calculate PTS value
In reply to Lu BaoluCalculate PTS (PASID Table Size) value for the extended context entry from the real size of the PASID table for a domain.
--- drivers/iommu/intel-iommu.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
drivers/iommu/intel-iommu.c +8 -14
@@ -5146,22 +5146,16 @@ static void intel_iommu_put_resv_regions(struct device *dev,#ifdef CONFIG_INTEL_IOMMU_SVM #define MAX_NR_PASID_BITS (20) -static inline unsigned long intel_iommu_get_pts (struct intel_iommu *iommu) +static inline unsigned long intel_iommu_get_pts (struct dmar_domain *domain) { -/* -* Convert ecap_pss to extend context entry pts encoding, also -* respect the soft pasid_max value set by the iommu. -* - number of PASID bits = ecap_pss + 1 -* - number of PASID table entries = 2^(pts + 5) -* Therefore, pts = ecap_pss - 4 -* e.g. KBL ecap_pss = 0x13, PASID has 20 bits, pts = 15 -*/ -if (ecap_pss (iommu->ecap) <5 ) +int pts; + + pts =find_first_bit ((unsigned long *)&domain->max_pasid, +MAX_NR_PASID_BITS ); +if (pts <5 )return 0 ; -/* pasid_max is encoded as actual number of entries not the bits */ -return find_first_bit ((unsigned long *)&iommu->pasid_max, -MAX_NR_PASID_BITS ) -5 ; +return pts -5 ; }int intel_iommu_enable_pasid (struct intel_iommu *iommu,struct intel_svm_dev *sdev)
@@ -5198,7 +5192,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct intel_svm_dev *sdif (iommu->pasid_state_table) context[1 ].hi = (u64 )virt_to_phys (iommu->pasid_state_table); context[1 ].lo = (u64 )virt_to_phys (iommu->pasid_table) | -intel_iommu_get_pts (iommu); +intel_iommu_get_pts (domain);wmb ();/* CONTEXT_TT_MULTI_LEVEL and CONTEXT_TT_DEV_IOTLB are both
Signature · 1 line
2.7.4
RE: [PATCH 7/9] iommu/vt-d: Calculate PTS value
Quoted 7 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AMCalculate PTS (PASID Table Size) value for the extended context entry from the real size of the PASID table for a domain.
Quoted 5 lines
Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>
Looks good to me.
Regards,
Yi Liu
Quoted 54 lines
--- drivers/iommu/intel-iommu.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)drivers/iommu/intel-iommu.c +7
-13@@ -5146,22 +5146,16 @@ static void intel_iommu_put_resv_regions(struct device *dev,#ifdef CONFIG_INTEL_IOMMU_SVM #define MAX_NR_PASID_BITS (20) -static inline unsigned long intel_iommu_get_pts (struct intel_iommu *iommu) +static inline unsigned long intel_iommu_get_pts (struct dmar_domain *domain) { -/* -* Convert ecap_pss to extend context entry pts encoding, also -* respect the soft pasid_max value set by the iommu. -* - number of PASID bits = ecap_pss + 1 -* - number of PASID table entries = 2^(pts + 5) -* Therefore, pts = ecap_pss - 4 -* e.g. KBL ecap_pss = 0x13, PASID has 20 bits, pts = 15 -*/ -if (ecap_pss (iommu->ecap) <5 ) +int pts; + + pts =find_first_bit ((unsigned long *)&domain->max_pasid, +MAX_NR_PASID_BITS ); +if (pts <5 )return 0 ; -/* pasid_max is encoded as actual number of entries not the bits */ -return find_first_bit ((unsigned long *)&iommu->pasid_max, -MAX_NR_PASID_BITS ) -5 ; +return pts -5 ; }int intel_iommu_enable_pasid(struct
intel_iommu*iommu, structintel_svm_dev
*sdev)drivers/iommu/intel-iommu.c +1
-1@@ -5198,7 +5192,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct intel_svm_dev *sdif (iommu->pasid_state_table) context[1 ].hi = (u64 )virt_to_phys (iommu- >pasid_state_table); context[1 ].lo = (u64 )virt_to_phys (iommu->pasid_table) | -intel_iommu_get_pts (iommu); +intel_iommu_get_pts (domain);drivers/iommu/intel-iommu.c +0
-0wmb ();/* CONTEXT_TT_MULTI_LEVEL and CONTEXT_TT_DEV_IOTLB are both
--
2.7.4
PATCH 8/9 iommu/vt-d: Use per-domain pasid table
In reply to Lu BaoluThis patch replaces current per iommu pasid table with the new added per domain pasid table. Each svm-capable PCI device will have its own pasid table.
--- drivers/iommu/intel-iommu.c | 6 +++--- drivers/iommu/intel-svm.c | 37 +++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 15 deletions(-)
drivers/iommu/intel-iommu.c +3 -3
@@ -5191,7 +5191,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct intel_svm_dev *sdif (!(ctx_lo &CONTEXT_PASIDE )) {if (iommu->pasid_state_table) context[1 ].hi = (u64 )virt_to_phys (iommu->pasid_state_table); - context[1 ].lo = (u64 )virt_to_phys (iommu->pasid_table) | + context[1 ].lo = (u64 )virt_to_phys (domain->pasid_table) |intel_iommu_get_pts (domain);wmb ();
@@ -5259,8 +5259,8 @@ struct intel_iommu *intel_svm_device_to_iommu(struct device *dev)return NULL ; } -if (!iommu->pasid_table) { -dev_err (dev,"PASID not enabled on IOMMU; cannot enable SVM\n" ); +if (!intel_pasid_get_table (dev)) { +dev_err (dev,"No PASID table for device; cannot enable SVM\n" );return NULL ; }
drivers/iommu/intel-svm.c +25 -12
@@ -256,6 +256,7 @@ static void intel_flush_pasid_dev(struct intel_svm *svm, struct intel_svm_dev *sstatic void intel_mm_release (struct mmu_notifier *mn,struct mm_struct *mm) { struct intel_svm *svm = container_of(mn, struct intel_svm, notifier); +struct pasid_entry *pasid_table;struct intel_svm_dev *sdev;/* This might end up being called from exit_mmap(), *before* the page
@@ -270,11 +271,16 @@ static void intel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm)* page) so that we end up taking a fault that the hardware really * *has* to handle gracefully without affecting other processes. */ - svm->iommu->pasid_table[svm->pasid].val =0 ; -wmb (); -rcu_read_lock ();list_for_each_entry_rcu (sdev, &svm->devs, list) { + pasid_table =intel_pasid_get_table (sdev->dev); +if (!pasid_table) +continue ; + + pasid_table[svm->pasid].val =0 ; +/* Make sure the entry update is visible before translation. */ +wmb (); +intel_flush_pasid_dev (svm, sdev, svm->pasid);intel_flush_svm_range_dev (svm, sdev,0 ,-1 ,0 , !svm->mm); }
@@ -295,6 +301,7 @@ static LIST_HEAD(global_svm_list);int intel_svm_bind_mm (struct device *dev,int *pasid,int flags,struct svm_dev_ops *ops) {struct intel_iommu *iommu =intel_svm_device_to_iommu (dev); +struct pasid_entry *pasid_table;struct intel_svm_dev *sdev;struct intel_svm *svm =NULL ;struct mm_struct *mm =NULL ;
@@ -302,7 +309,8 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_int pasid_max;int ret; -if (WARN_ON (!iommu || !iommu->pasid_table)) + pasid_table =intel_pasid_get_table (dev); +if (WARN_ON (!iommu || !pasid_table))return -EINVAL ;if (dev_is_pci (dev)) {
@@ -380,8 +388,8 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_ } svm->iommu = iommu; -if (pasid_max > iommu->pasid_max) - pasid_max = iommu->pasid_max; +if (pasid_max > intel_pasid_max_id) + pasid_max = intel_pasid_max_id;/* Do not use PASID 0 in caching mode (virtualised IOMMU) */ ret = intel_pasid_alloc_id(svm,
@@ -414,7 +422,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_if (cpu_feature_enabled (X86_FEATURE_LA57 )) pasid_entry_val |=PASID_ENTRY_FLPM_5LP ; - iommu->pasid_table[svm->pasid].val = pasid_entry_val; + pasid_table[svm->pasid].val = pasid_entry_val;wmb ();
@@ -442,6 +450,7 @@ EXPORT_SYMBOL_GPL(intel_svm_bind_mm);int intel_svm_unbind_mm (struct device *dev,int pasid) { +struct pasid_entry *pasid_table;struct intel_svm_dev *sdev;struct intel_iommu *iommu;struct intel_svm *svm;
@@ -449,7 +458,8 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)mutex_lock (&pasid_mutex); iommu =intel_svm_device_to_iommu (dev); -if (!iommu || !iommu->pasid_table) + pasid_table =intel_pasid_get_table (dev); +if (!iommu || !pasid_table) goto out; svm =intel_pasid_lookup_id (pasid);
@@ -472,11 +482,14 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)intel_flush_pasid_dev (svm, sdev, svm->pasid);intel_flush_svm_range_dev (svm, sdev,0 ,-1 ,0 , !svm->mm);kfree_rcu (sdev, rcu); + pasid_table[svm->pasid].val =0 ; +/* +* Make sure the entry update is visible +* before translation. +*/ +wmb ();if (list_empty (&svm->devs)) { - svm->iommu->pasid_table[svm->pasid].val =0 ; -wmb (); -intel_pasid_free_id (svm->pasid);if (svm->mm)mmu_notifier_unregister (&svm->notifier, svm->mm);
@@ -509,7 +522,7 @@ int intel_svm_is_pasid_valid(struct device *dev, int pasid)mutex_lock (&pasid_mutex); iommu =intel_svm_device_to_iommu (dev); -if (!iommu || !iommu->pasid_table) +if (!iommu) goto out; svm =intel_pasid_lookup_id (pasid);
Signature · 1 line
2.7.4
RE: [PATCH 8/9] iommu/vt-d: Use per-domain pasid table
Quoted 6 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AMThis patch replaces current per iommu pasid table with the new added per domain pasid table. Each svm-capable PCI device will have its own pasid table.
This is not accurate. pasid table is per-iommu domain. May more accurate "Each svm-capable PCI device will be configed with a pasid table which shares with other svm-capable device within its iommu domain"
Can include my reviewed by after refining the description.
Thanks,
Yi Liu
Quoted 165 lines
Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>--- drivers/iommu/intel-iommu.c | 6 +++--- drivers/iommu/intel-svm.c | 37 +++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 15 deletions(-)drivers/iommu/intel-iommu.c +1
-1@@ -5191,7 +5191,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct intel_svm_dev *sdif (!(ctx_lo &CONTEXT_PASIDE )) {if (iommu->pasid_state_table) context[1 ].hi = (u64 )virt_to_phys (iommu- >pasid_state_table); - context[1 ].lo = (u64 )virt_to_phys (iommu->pasid_table) | + context[1 ].lo = (u64 )virt_to_phys (domain->pasid_table) |intel_iommu_get_pts (domain);drivers/iommu/intel-iommu.c +2
-2wmb ();@@ -5259,8 +5259,8 @@ struct intel_iommu *intel_svm_device_to_iommu(struct device *dev)return NULL ; } -if (!iommu->pasid_table) { -dev_err (dev,"PASID not enabled on IOMMU; cannot enable SVM\n"); +if (!intel_pasid_get_table (dev)) { +dev_err (dev,"No PASID table for device; cannot enable SVM\n" );return NULL ;drivers/iommu/intel-iommu.c +0
-0}drivers/iommu/intel-svm.c +0
-0@@ -256,6 +256,7 @@ static void intel_flush_pasid_dev(struct intel_svm *svm,struct
intel_svm_dev*s
static voidintel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm){drivers/iommu/intel-svm.c +9
-3struct intel_svm *svm = container_of(mn, struct intel_svm, notifier); +struct pasid_entry *pasid_table;struct intel_svm_dev *sdev;/* This might end up being called from exit_mmap(), *before* the page @@ -270,11 +271,16 @@ static void intel_mm_release(struct mmu_notifier *mn,struct mm_struct *mm) * page) so that we end up taking a fault that the hardware really * *has* to handle gracefully without affecting other processes. */ - svm->iommu->pasid_table[svm->pasid].val =0 ; -wmb (); -rcu_read_lock ();list_for_each_entry_rcu (sdev, &svm->devs, list) { + pasid_table =intel_pasid_get_table (sdev->dev); +if (!pasid_table) +continue ; + + pasid_table[svm->pasid].val =0 ; +/* Make sure the entry update is visible before translation. */ +wmb (); +intel_flush_pasid_dev (svm, sdev, svm->pasid);intel_flush_svm_range_dev (svm, sdev,0 ,-1 ,0 , !svm->mm);drivers/iommu/intel-svm.c +1
-0}@@ -295,6 +301,7 @@ static LIST_HEAD(global_svm_list);int intel_svm_bind_mm (struct device *dev,int *pasid,int flags,struct svm_dev_ops *ops) {struct intel_iommu *iommu =intel_svm_device_to_iommu (dev); +struct pasid_entry *pasid_table;struct intel_svm_dev *sdev;struct intel_svm *svm =NULL ;drivers/iommu/intel-svm.c +0
-0struct mm_struct *mm =NULL ;@@ -302,7 +309,8 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, intflags, struct
svm_dev_drivers/iommu/intel-svm.c +2
-1int pasid_max;int ret; -if (WARN_ON (!iommu || !iommu->pasid_table)) + pasid_table =intel_pasid_get_table (dev); +if (WARN_ON (!iommu || !pasid_table))return -EINVAL ;if (dev_is_pci (dev)) {@@ -380,8 +388,8 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, intflags, struct
svm_dev_drivers/iommu/intel-svm.c +2
-2} svm->iommu = iommu; -if (pasid_max > iommu->pasid_max) - pasid_max = iommu->pasid_max; +if (pasid_max > intel_pasid_max_id) + pasid_max = intel_pasid_max_id;/* Do not use PASID 0 in caching mode (virtualised IOMMU) */ ret = intel_pasid_alloc_id(svm,@@ -414,7 +422,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, intflags, struct
svm_dev_drivers/iommu/intel-svm.c +10
-5if (cpu_feature_enabled (X86_FEATURE_LA57 )) pasid_entry_val |=PASID_ENTRY_FLPM_5LP ; - iommu->pasid_table[svm->pasid].val = pasid_entry_val; + pasid_table[svm->pasid].val = pasid_entry_val;wmb ();@@ -442,6 +450,7 @@ EXPORT_SYMBOL_GPL(intel_svm_bind_mm);int intel_svm_unbind_mm (struct device *dev,int pasid) { +struct pasid_entry *pasid_table;struct intel_svm_dev *sdev;struct intel_iommu *iommu;struct intel_svm *svm;@@ -449,7 +458,8 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)mutex_lock (&pasid_mutex); iommu =intel_svm_device_to_iommu (dev); -if (!iommu || !iommu->pasid_table) + pasid_table =intel_pasid_get_table (dev); +if (!iommu || !pasid_table) goto out; svm =intel_pasid_lookup_id (pasid);@@ -472,11 +482,14 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)intel_flush_pasid_dev (svm, sdev, svm->pasid);intel_flush_svm_range_dev (svm, sdev,0 ,-1 ,0 , !svm->mm);kfree_rcu (sdev, rcu); + pasid_table[svm->pasid].val =0 ; +/* +* Make sure the entry update is visible +* before translation. +*/ +wmb ();if (list_empty (&svm->devs)) { - svm->iommu->pasid_table[svm->pasid].val = 0; -wmb (); -intel_pasid_free_id (svm->pasid);drivers/iommu/intel-svm.c +0
-0if (svm->mm) mmu_notifier_unregister(&svm-Quoted 1 line
notifier,
svm->mm);drivers/iommu/intel-svm.c +1
-2@@ -509,7 +522,7 @@ int intel_svm_is_pasid_valid(struct device *dev, int pasid)mutex_lock (&pasid_mutex); iommu =intel_svm_device_to_iommu (dev); -if (!iommu || !iommu->pasid_table) +if (!iommu) goto out; svm =intel_pasid_lookup_id (pasid); --2.7.4
Re: [PATCH 8/9] iommu/vt-d: Use per-domain pasid table
Hi,
Quoted 10 lines · Yi L
Quoted 6 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AMThis patch replaces current per iommu pasid table with the new added per domain pasid table. Each svm-capable PCI device will have its own pasid table.
This is not accurate. pasid table is per-iommu domain. May more accurate "Each svm-capable PCI device will be configed with a pasid table which shares with other svm-capable device within its iommu domain"
Yes. Should be refined.
Quoted 4 lines
Can include my reviewed by after refining the description.
Reviewed-by Liu, Yi L <[email protected]>
Sure.
Quoted 3 lines
Thanks,
Yi Liu
Best regards,
Lu Baolu
Quoted 165 lines
Quoted 164 lines
Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>--- drivers/iommu/intel-iommu.c | 6 +++--- drivers/iommu/intel-svm.c | 37 +++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 15 deletions(-)drivers/iommu/intel-iommu.c +1
-1@@ -5191,7 +5191,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct intel_svm_dev *sdif (!(ctx_lo &CONTEXT_PASIDE )) {if (iommu->pasid_state_table) context[1 ].hi = (u64 )virt_to_phys (iommu- > pasid_state_table); - context[1 ].lo = (u64 )virt_to_phys (iommu->pasid_table) | + context[1 ].lo = (u64 )virt_to_phys (domain->pasid_table) |intel_iommu_get_pts (domain);drivers/iommu/intel-iommu.c +2
-2wmb ();@@ -5259,8 +5259,8 @@ struct intel_iommu *intel_svm_device_to_iommu(struct device *dev)return NULL ; } -if (!iommu->pasid_table) { -dev_err (dev,"PASID not enabled on IOMMU; cannot enable SVM\n"); +if (!intel_pasid_get_table (dev)) { +dev_err (dev,"No PASID table for device; cannot enable SVM\n" );return NULL ;drivers/iommu/intel-iommu.c +0
-0}drivers/iommu/intel-svm.c +0
-0@@ -256,6 +256,7 @@ static void intel_flush_pasid_dev(struct intel_svm *svm,struct
intel_svm_dev*s
static voidintel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm){drivers/iommu/intel-svm.c +9
-3struct intel_svm *svm = container_of(mn, struct intel_svm, notifier); +struct pasid_entry *pasid_table;struct intel_svm_dev *sdev;/* This might end up being called from exit_mmap(), *before* the page @@ -270,11 +271,16 @@ static void intel_mm_release(struct mmu_notifier *mn,struct mm_struct *mm) * page) so that we end up taking a fault that the hardware really * *has* to handle gracefully without affecting other processes. */ - svm->iommu->pasid_table[svm->pasid].val =0 ; -wmb (); -rcu_read_lock ();list_for_each_entry_rcu (sdev, &svm->devs, list) { + pasid_table =intel_pasid_get_table (sdev->dev); +if (!pasid_table) +continue ; + + pasid_table[svm->pasid].val =0 ; +/* Make sure the entry update is visible before translation. */ +wmb (); +intel_flush_pasid_dev (svm, sdev, svm->pasid);intel_flush_svm_range_dev (svm, sdev,0 ,-1 ,0 , !svm->mm);drivers/iommu/intel-svm.c +1
-0}@@ -295,6 +301,7 @@ static LIST_HEAD(global_svm_list);int intel_svm_bind_mm (struct device *dev,int *pasid,int flags,struct svm_dev_ops *ops) {struct intel_iommu *iommu =intel_svm_device_to_iommu (dev); +struct pasid_entry *pasid_table;struct intel_svm_dev *sdev;struct intel_svm *svm =NULL ;drivers/iommu/intel-svm.c +0
-0struct mm_struct *mm =NULL ;@@ -302,7 +309,8 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, intflags, struct
svm_dev_drivers/iommu/intel-svm.c +2
-1int pasid_max;int ret; -if (WARN_ON (!iommu || !iommu->pasid_table)) + pasid_table =intel_pasid_get_table (dev); +if (WARN_ON (!iommu || !pasid_table))return -EINVAL ;if (dev_is_pci (dev)) {@@ -380,8 +388,8 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, intflags, struct
svm_dev_drivers/iommu/intel-svm.c +2
-2} svm->iommu = iommu; -if (pasid_max > iommu->pasid_max) - pasid_max = iommu->pasid_max; +if (pasid_max > intel_pasid_max_id) + pasid_max = intel_pasid_max_id;/* Do not use PASID 0 in caching mode (virtualised IOMMU) */ ret = intel_pasid_alloc_id(svm,@@ -414,7 +422,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, intflags, struct
svm_dev_drivers/iommu/intel-svm.c +10
-5if (cpu_feature_enabled (X86_FEATURE_LA57 )) pasid_entry_val |=PASID_ENTRY_FLPM_5LP ; - iommu->pasid_table[svm->pasid].val = pasid_entry_val; + pasid_table[svm->pasid].val = pasid_entry_val;wmb ();@@ -442,6 +450,7 @@ EXPORT_SYMBOL_GPL(intel_svm_bind_mm);int intel_svm_unbind_mm (struct device *dev,int pasid) { +struct pasid_entry *pasid_table;struct intel_svm_dev *sdev;struct intel_iommu *iommu;struct intel_svm *svm;@@ -449,7 +458,8 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)mutex_lock (&pasid_mutex); iommu =intel_svm_device_to_iommu (dev); -if (!iommu || !iommu->pasid_table) + pasid_table =intel_pasid_get_table (dev); +if (!iommu || !pasid_table) goto out; svm =intel_pasid_lookup_id (pasid);@@ -472,11 +482,14 @@ int intel_svm_unbind_mm(struct device *dev, int pasid)intel_flush_pasid_dev (svm, sdev, svm->pasid);intel_flush_svm_range_dev (svm, sdev,0 ,-1 ,0 , !svm->mm);kfree_rcu (sdev, rcu); + pasid_table[svm->pasid].val =0 ; +/* +* Make sure the entry update is visible +* before translation. +*/ +wmb ();if (list_empty (&svm->devs)) { - svm->iommu->pasid_table[svm->pasid].val = 0; -wmb (); -intel_pasid_free_id (svm->pasid);drivers/iommu/intel-svm.c +0
-0if (svm->mm) mmu_notifier_unregister(&svm-Quoted 1 line
notifier,
svm->mm);drivers/iommu/intel-svm.c +1
-2@@ -509,7 +522,7 @@ int intel_svm_is_pasid_valid(struct device *dev, int pasid)mutex_lock (&pasid_mutex); iommu =intel_svm_device_to_iommu (dev); -if (!iommu || !iommu->pasid_table) +if (!iommu) goto out; svm =intel_pasid_lookup_id (pasid); --2.7.4
PATCH 9/9 iommu/vt-d: Clean up PASID talbe management for SVM
In reply to Lu BaoluThe previous per iommu pasid table alloc/free interfaces are no longer used. Clean up the driver by removing it.
--- drivers/iommu/intel-iommu.c | 6 +++--- drivers/iommu/intel-svm.c | 17 ++--------------- include/linux/intel-iommu.h | 5 ++--- 3 files changed, 7 insertions(+), 21 deletions(-)
drivers/iommu/intel-iommu.c +3 -3
@@ -1736,7 +1736,7 @@ static void free_dmar_iommu(struct intel_iommu *iommu)if (pasid_enabled (iommu)) {if (ecap_prs (iommu->ecap))intel_svm_finish_prq (iommu); -intel_svm_free_pasid_tables (iommu); +intel_svm_exit (iommu); }#endif }
@@ -3291,7 +3291,7 @@ static int __init init_dmars(void) hw_pass_through =0 ;#ifdef CONFIG_INTEL_IOMMU_SVM if (pasid_enabled (iommu)) -intel_svm_alloc_pasid_tables (iommu); +intel_svm_init (iommu);#endif }
@@ -4268,7 +4268,7 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)#ifdef CONFIG_INTEL_IOMMU_SVM if (pasid_enabled (iommu)) -intel_svm_alloc_pasid_tables (iommu); +intel_svm_init (iommu);#endif if (dmaru->ignored) {
drivers/iommu/intel-svm.c +2 -15
@@ -34,7 +34,7 @@static irqreturn_t prq_event_thread (int irq,void *d); -int intel_svm_alloc_pasid_tables (struct intel_iommu *iommu) +int intel_svm_init (struct intel_iommu *iommu) {struct page *pages;int order;
@@ -59,15 +59,6 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu) iommu->pasid_max =0x20000 ; order =get_order (sizeof (struct pasid_entry ) * iommu->pasid_max); - pages =alloc_pages (GFP_KERNEL | __GFP_ZERO, order); -if (!pages) { -pr_warn ("IOMMU: %s: Failed to allocate PASID table\n" , - iommu->name); -return -ENOMEM ; - } - iommu->pasid_table =page_address (pages); -pr_info ("%s: Allocated order %d PASID table.\n" , iommu->name, order); -if (ecap_dis (iommu->ecap)) {/* Just making it explicit... */ BUILD_BUG_ON (sizeof (struct pasid_entry ) !=sizeof (struct pasid_state_entry ));
@@ -82,14 +73,10 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu)return 0 ; } -int intel_svm_free_pasid_tables (struct intel_iommu *iommu) +int intel_svm_exit (struct intel_iommu *iommu) {int order =get_order (sizeof (struct pasid_entry ) * iommu->pasid_max); -if (iommu->pasid_table) { -free_pages ((unsigned long )iommu->pasid_table, order); - iommu->pasid_table =NULL ; - }if (iommu->pasid_state_table) {free_pages ((unsigned long )iommu->pasid_state_table, order); iommu->pasid_state_table =NULL ;
include/linux/intel-iommu.h +2 -3
@@ -470,7 +470,6 @@ struct intel_iommu {* devices away to userspace processes (e.g. for DPDK) and don't * want to trust that userspace will use *only* the PASID it was * told to. But while it's all driver-arbitrated, we're fine. */ -struct pasid_entry *pasid_table;struct pasid_state_entry *pasid_state_table;struct page_req_dsc *prq;unsigned char prq_name[16 ];/* Name for PRQ interrupt */
@@ -539,8 +538,8 @@ void free_pgtable_page(void *vaddr);struct intel_iommu *domain_get_iommu (struct dmar_domain *domain);#ifdef CONFIG_INTEL_IOMMU_SVM -extern int intel_svm_alloc_pasid_tables (struct intel_iommu *iommu); -extern int intel_svm_free_pasid_tables (struct intel_iommu *iommu); +int intel_svm_init (struct intel_iommu *iommu); +int intel_svm_exit (struct intel_iommu *iommu);extern int intel_svm_enable_prq (struct intel_iommu *iommu);extern int intel_svm_finish_prq (struct intel_iommu *iommu);
Signature · 1 line
2.7.4
RE: [PATCH 9/9] iommu/vt-d: Clean up PASID talbe management for SVM
Quoted 5 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AMThe previous per iommu pasid table alloc/free interfaces are no longer used. Clean up the driver by removing it.
I think this patch major cleans intel_svm_alloc_pasid_tables and intel_svm_free_pasid_tables. Actually, only PASID State table allocation is remained in these two functions.
Since PASID Table is modified to be per-iommu domain. How about the PASID State Table? Should it also be per-iommu domain?
Thanks,
Yi Liu
Quoted 114 lines
Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>--- drivers/iommu/intel-iommu.c | 6 +++--- drivers/iommu/intel-svm.c | 17 ++--------------- include/linux/intel-iommu.h | 5 ++--- 3 files changed, 7 insertions(+), 21 deletions(-)drivers/iommu/intel-iommu.c +3
-3@@ -1736,7 +1736,7 @@ static void free_dmar_iommu(struct intel_iommu *iommu)if (pasid_enabled (iommu)) {if (ecap_prs (iommu->ecap))intel_svm_finish_prq (iommu); -intel_svm_free_pasid_tables (iommu); +intel_svm_exit (iommu); }#endif }@@ -3291,7 +3291,7 @@ static int __init init_dmars(void) hw_pass_through =0 ;#ifdef CONFIG_INTEL_IOMMU_SVM if (pasid_enabled (iommu)) -intel_svm_alloc_pasid_tables (iommu); +intel_svm_init (iommu);#endif }@@ -4268,7 +4268,7 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)#ifdef CONFIG_INTEL_IOMMU_SVM if (pasid_enabled (iommu)) -intel_svm_alloc_pasid_tables (iommu); +intel_svm_init (iommu);#endif if (dmaru->ignored) {drivers/iommu/intel-svm.c +1
-10@@ -34,7 +34,7 @@static irqreturn_t prq_event_thread (int irq,void *d); -int intel_svm_alloc_pasid_tables (struct intel_iommu *iommu) +int intel_svm_init (struct intel_iommu *iommu) {struct page *pages;int order;@@ -59,15 +59,6 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu) iommu->pasid_max =0x20000 ; order =get_order (sizeof (struct pasid_entry ) * iommu->pasid_max); - pages =alloc_pages (GFP_KERNEL | __GFP_ZERO, order); -if (!pages) { -pr_warn ("IOMMU: %s: Failed to allocate PASID table\n" , - iommu->name); -return -ENOMEM ; - } - iommu->pasid_table =page_address (pages); -pr_info ("%s: Allocated order %d PASID table.\n" , iommu->name, order); -if (ecap_dis (iommu->ecap)) {/* Just making it explicit... */ BUILD_BUG_ON(sizeof(struct pasid_entry) != sizeof(struct
pasid_state_entry));drivers/iommu/intel-svm.c +1
-5@@ -82,14 +73,10 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu)return 0 ; } -int intel_svm_free_pasid_tables (struct intel_iommu *iommu) +int intel_svm_exit (struct intel_iommu *iommu) {int order =get_order (sizeof (struct pasid_entry ) * iommu->pasid_max); -if (iommu->pasid_table) { -free_pages ((unsigned long )iommu->pasid_table, order); - iommu->pasid_table =NULL ; - }if (iommu->pasid_state_table) {free_pages ((unsigned long )iommu->pasid_state_table, order);drivers/iommu/intel-svm.c +0
-0iommu->pasid_state_table =NULL ;include/linux/intel-iommu.h +2
-4@@ -470,7 +470,6 @@ struct intel_iommu {* devices away to userspace processes (e.g. for DPDK) and don't * want to trust that userspace will use *only* the PASID it was * told to. But while it's all driver-arbitrated, we're fine. */ -struct pasid_entry *pasid_table;struct pasid_state_entry *pasid_state_table;struct page_req_dsc *prq;unsigned char prq_name[16 ];/* Name for PRQ interrupt */ @@ -539,8 +538,8 @@ void free_pgtable_page(void *vaddr);struct intel_iommu *domain_get_iommu (struct dmar_domain *domain);#ifdef CONFIG_INTEL_IOMMU_SVM -extern int intel_svm_alloc_pasid_tables (struct intel_iommu *iommu); -extern int intel_svm_free_pasid_tables (struct intel_iommu *iommu); +int intel_svm_init (struct intel_iommu *iommu); +int intel_svm_exit (struct intel_iommu *iommu);extern int intel_svm_enable_prq (struct intel_iommu *iommu);extern int intel_svm_finish_prq (struct intel_iommu *iommu); --2.7.4
Re: [PATCH 9/9] iommu/vt-d: Clean up PASID talbe management for SVM
Hi,
Quoted 7 lines · Yi L
Quoted 5 lines
From: Lu Baolu [mailto:baolu.lu-VuQAYsv1563Yd54FQh9/[email protected]]
Sent: Tuesday, April 17, 2018 11:03 AMThe previous per iommu pasid table alloc/free interfaces are no longer used. Clean up the driver by removing it.
I think this patch major cleans
intel_svm_alloc_pasid_tablesandintel_svm_free_pasid_tables.
Yes.
Quoted 2 lines
Actually, only PASID State
table allocation is remained in these two functions.
Together with GB pages and 5-level page table support checks.
Quoted 3 lines
Since PASID Table is modified to be per-iommu domain. How about the PASID State Table? Should it also be per-iommu domain?
Yes. This is in plan. I will do this in another patch series.
Quoted 3 lines
Thanks,
Yi Liu
Best regards,
Lu Baolu
Quoted 115 lines
Quoted 114 lines
Cc Ashok Raj <[email protected]>Cc Jacob Pan <jacob.jun.pan-VuQAYsv1563Yd54FQh9/[email protected]>Cc Kevin Tian <[email protected]>Cc Liu Yi L <[email protected]>--- drivers/iommu/intel-iommu.c | 6 +++--- drivers/iommu/intel-svm.c | 17 ++--------------- include/linux/intel-iommu.h | 5 ++--- 3 files changed, 7 insertions(+), 21 deletions(-)drivers/iommu/intel-iommu.c +3
-3@@ -1736,7 +1736,7 @@ static void free_dmar_iommu(struct intel_iommu *iommu)if (pasid_enabled (iommu)) {if (ecap_prs (iommu->ecap))intel_svm_finish_prq (iommu); -intel_svm_free_pasid_tables (iommu); +intel_svm_exit (iommu); }#endif }@@ -3291,7 +3291,7 @@ static int __init init_dmars(void) hw_pass_through =0 ;#ifdef CONFIG_INTEL_IOMMU_SVM if (pasid_enabled (iommu)) -intel_svm_alloc_pasid_tables (iommu); +intel_svm_init (iommu);#endif }@@ -4268,7 +4268,7 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)#ifdef CONFIG_INTEL_IOMMU_SVM if (pasid_enabled (iommu)) -intel_svm_alloc_pasid_tables (iommu); +intel_svm_init (iommu);#endif if (dmaru->ignored) {drivers/iommu/intel-svm.c +1
-10@@ -34,7 +34,7 @@static irqreturn_t prq_event_thread (int irq,void *d); -int intel_svm_alloc_pasid_tables (struct intel_iommu *iommu) +int intel_svm_init (struct intel_iommu *iommu) {struct page *pages;int order;@@ -59,15 +59,6 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu) iommu->pasid_max =0x20000 ; order =get_order (sizeof (struct pasid_entry ) * iommu->pasid_max); - pages =alloc_pages (GFP_KERNEL | __GFP_ZERO, order); -if (!pages) { -pr_warn ("IOMMU: %s: Failed to allocate PASID table\n" , - iommu->name); -return -ENOMEM ; - } - iommu->pasid_table =page_address (pages); -pr_info ("%s: Allocated order %d PASID table.\n" , iommu->name, order); -if (ecap_dis (iommu->ecap)) {/* Just making it explicit... */ BUILD_BUG_ON(sizeof(struct pasid_entry) != sizeof(struct
pasid_state_entry));drivers/iommu/intel-svm.c +1
-5@@ -82,14 +73,10 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu)return 0 ; } -int intel_svm_free_pasid_tables (struct intel_iommu *iommu) +int intel_svm_exit (struct intel_iommu *iommu) {int order =get_order (sizeof (struct pasid_entry ) * iommu->pasid_max); -if (iommu->pasid_table) { -free_pages ((unsigned long )iommu->pasid_table, order); - iommu->pasid_table =NULL ; - }if (iommu->pasid_state_table) {free_pages ((unsigned long )iommu->pasid_state_table, order);drivers/iommu/intel-svm.c +0
-0iommu->pasid_state_table =NULL ;include/linux/intel-iommu.h +2
-4@@ -470,7 +470,6 @@ struct intel_iommu {* devices away to userspace processes (e.g. for DPDK) and don't * want to trust that userspace will use *only* the PASID it was * told to. But while it's all driver-arbitrated, we're fine. */ -struct pasid_entry *pasid_table;struct pasid_state_entry *pasid_state_table;struct page_req_dsc *prq;unsigned char prq_name[16 ];/* Name for PRQ interrupt */ @@ -539,8 +538,8 @@ void free_pgtable_page(void *vaddr);struct intel_iommu *domain_get_iommu (struct dmar_domain *domain);#ifdef CONFIG_INTEL_IOMMU_SVM -extern int intel_svm_alloc_pasid_tables (struct intel_iommu *iommu); -extern int intel_svm_free_pasid_tables (struct intel_iommu *iommu); +int intel_svm_init (struct intel_iommu *iommu); +int intel_svm_exit (struct intel_iommu *iommu);extern int intel_svm_enable_prq (struct intel_iommu *iommu);extern int intel_svm_finish_prq (struct intel_iommu *iommu); --2.7.4