Skip to contentSkip to conversation

iommu/vt-d: Miscellaneous cleanups

PATCH In review Lu Baolu 3 participants 13 messages Nov 16, 2023 – Nov 18, 2023

Subsystems (2)
lore
Share & tools
lore

Lu Baolu

author maintainer
#0 lore raw

cover iommu/vt-d: Miscellaneous cleanups

This series includes several miscellaneous cleanups that were discovered during recent development. Please let me know if anything I have overlooked.

Best regards,
baolu

Lu Baolu (4):
iommu/vt-d: Introduce dev_to_iommu()
iommu/vt-d: Remove unused parameter of
intel_pasid_setup_pass_through()
iommu/vt-d: Remove unused vcmd interfaces
iommu/vt-d: Move inline helpers to header files

 drivers/iommu/intel/iommu.h | 184 +++++++++++++++++++++++-
 drivers/iommu/intel/pasid.h | 213 +++++++++++++++++++++++++++-
 drivers/iommu/intel/iommu.c | 237 +++----------------------------
 drivers/iommu/intel/pasid.c | 274 +-----------------------------------
 drivers/iommu/intel/svm.c   |  20 +--
 5 files changed, 421 insertions(+), 507 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/4 iommu/vt-d: Introduce dev_to_iommu()

The device_to_iommu() helper was originally designed to look up the DMAR ACPI table to retrieve the iommu device and the request ID for a given device. However, it was also being used in other places where there was no need to lookup the ACPI table at all.

Introduce a new helper dev_to_iommu() which returns the iommu device saved in the per-device iommu driver data. This function can be used after the iommu_probe_device() returns success.

Rename the original device_to_iommu() function to a more meaningful name, device_lookup_iommu(), to avoid mis-using it.

---
 drivers/iommu/intel/iommu.h | 11 ++++++++++-
 drivers/iommu/intel/iommu.c | 28 ++++++++--------------------
 drivers/iommu/intel/svm.c   | 20 +++-----------------
 3 files changed, 21 insertions(+), 38 deletions(-)
drivers/iommu/intel/iommu.h +10 -1
index 65d37a138c75..049d6af6aae8 100644
@@ -851,6 +851,16 @@ static inline bool context_present(struct context_entry *context)
 	return (context->lo & 1);
 }
 
+static inline struct intel_iommu *dev_to_iommu(struct device *dev)
+{
+	/*
+	 * Assume that valid per-device iommu structure must be installed
+	 * if iommu_probe_device() has succeeded. This helper could only
+	 * be used after device is probed.
+	 */
+	return ((struct device_domain_info *)dev_iommu_priv_get(dev))->iommu;
+}
+
 struct dmar_drhd_unit *dmar_find_matched_drhd_unit(struct pci_dev *dev);
 
 int dmar_enable_qi(struct intel_iommu *iommu);
@@ -897,7 +907,6 @@ int dmar_ir_support(void);
 void *alloc_pgtable_page(int node, gfp_t gfp);
 void free_pgtable_page(void *vaddr);
 void iommu_flush_write_buffer(struct intel_iommu *iommu);
-struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn);
 struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent,
 					       const struct iommu_user_data *user_data);
 
drivers/iommu/intel/iommu.c +8 -20
index 3531b956556c..b50ade814e94 100644
@@ -703,7 +703,7 @@ static bool iommu_is_dummy(struct intel_iommu *iommu, struct device *dev)
 	return false;
 }
 
-struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn)
+static struct intel_iommu *device_lookup_iommu(struct device *dev, u8 *bus, u8 *devfn)
 {
 	struct dmar_drhd_unit *drhd = NULL;
 	struct pci_dev *pdev = NULL;
@@ -2081,14 +2081,11 @@ static int domain_context_mapping_cb(struct pci_dev *pdev,
 static int
 domain_context_mapping(struct dmar_domain *domain, struct device *dev)
 {
+	struct device_domain_info *info = dev_iommu_priv_get(dev);
 	struct domain_context_mapping_data data;
+	struct intel_iommu *iommu = info->iommu;
+	u8 bus = info->bus, devfn = info->devfn;
 	struct pasid_table *table;
-	struct intel_iommu *iommu;
-	u8 bus, devfn;
-
-	iommu = device_to_iommu(dev, &bus, &devfn);
-	if (!iommu)
-		return -ENODEV;
 
 	table = intel_pasid_get_table(dev);
 
@@ -2447,15 +2444,10 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
 				     struct device *dev)
 {
 	struct device_domain_info *info = dev_iommu_priv_get(dev);
-	struct intel_iommu *iommu;
+	struct intel_iommu *iommu = info->iommu;
 	unsigned long flags;
-	u8 bus, devfn;
 	int ret;
 
-	iommu = device_to_iommu(dev, &bus, &devfn);
-	if (!iommu)
-		return -ENODEV;
-
 	ret = domain_attach_iommu(domain, iommu);
 	if (ret)
 		return ret;
@@ -4117,13 +4109,9 @@ int prepare_domain_attach_device(struct iommu_domain *domain,
 				 struct device *dev)
 {
 	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
-	struct intel_iommu *iommu;
+	struct intel_iommu *iommu = dev_to_iommu(dev);
 	int addr_width;
 
-	iommu = device_to_iommu(dev, NULL, NULL);
-	if (!iommu)
-		return -ENODEV;
-
 	if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap))
 		return -EINVAL;
 
@@ -4399,7 +4387,7 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
 	u8 bus, devfn;
 	int ret;
 
-	iommu = device_to_iommu(dev, &bus, &devfn);
+	iommu = device_lookup_iommu(dev, &bus, &devfn);
 	if (!iommu || !iommu->iommu.ops)
 		return ERR_PTR(-ENODEV);
 
@@ -4735,8 +4723,8 @@ static int intel_iommu_iotlb_sync_map(struct iommu_domain *domain,
 
 static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid)
 {
-	struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL);
 	struct dev_pasid_info *curr, *dev_pasid = NULL;
+	struct intel_iommu *iommu = dev_to_iommu(dev);
 	struct dmar_domain *dmar_domain;
 	struct iommu_domain *domain;
 	unsigned long flags;
drivers/iommu/intel/svm.c +3 -17
index 50a481c895b8..cc138e3ed4a6 100644
@@ -366,14 +366,9 @@ static int intel_svm_bind_mm(struct intel_iommu *iommu, struct device *dev,
 void intel_svm_remove_dev_pasid(struct device *dev, u32 pasid)
 {
 	struct intel_svm_dev *sdev;
-	struct intel_iommu *iommu;
 	struct intel_svm *svm;
 	struct mm_struct *mm;
 
-	iommu = device_to_iommu(dev, NULL, NULL);
-	if (!iommu)
-		return;
-
 	if (pasid_to_svm_sdev(dev, pasid, &svm, &sdev))
 		return;
 	mm = svm->mm;
@@ -724,25 +719,16 @@ int intel_svm_page_response(struct device *dev,
 			    struct iommu_fault_event *evt,
 			    struct iommu_page_response *msg)
 {
+	struct device_domain_info *info = dev_iommu_priv_get(dev);
+	struct intel_iommu *iommu = info->iommu;
+	u8 bus = info->bus, devfn = info->devfn;
 	struct iommu_fault_page_request *prm;
-	struct intel_iommu *iommu;
 	bool private_present;
 	bool pasid_present;
 	bool last_page;
-	u8 bus, devfn;
 	int ret = 0;
 	u16 sid;
 
-	if (!dev || !dev_is_pci(dev))
-		return -ENODEV;
-
-	iommu = device_to_iommu(dev, &bus, &devfn);
-	if (!iommu)
-		return -ENODEV;
-
-	if (!msg || !evt)
-		return -EINVAL;
-
 	prm = &evt->fault.prm;
 	sid = PCI_DEVID(bus, devfn);
 	pasid_present = prm->flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID;
Signature · 1 line
2.34.1
author maintainer
#6 lore raw

PATCH 2/4 iommu/vt-d: Remove unused parameter of intel_pasid_setup_pass_through()

In reply to Lu Baolu

The domain parameter of this helper is unused and can be deleted to avoid dead code.

---
 drivers/iommu/intel/pasid.h | 1 -
 drivers/iommu/intel/iommu.c | 5 ++---
 drivers/iommu/intel/pasid.c | 1 -
 3 files changed, 2 insertions(+), 5 deletions(-)
drivers/iommu/intel/pasid.h +0 -1
index dd37611175cc..16265bc1f7ec 100644
@@ -111,7 +111,6 @@ int intel_pasid_setup_dirty_tracking(struct intel_iommu *iommu,
 				     struct device *dev, u32 pasid,
 				     bool enabled);
 int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
-				   struct dmar_domain *domain,
 				   struct device *dev, u32 pasid);
 int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev,
 			     u32 pasid, struct dmar_domain *domain);
drivers/iommu/intel/iommu.c +2 -3
index b50ade814e94..3ccc2739236b 100644
@@ -2460,7 +2460,7 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
 	if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
 		/* Setup the PASID entry for requests without PASID: */
 		if (hw_pass_through && domain_type_is_si(domain))
-			ret = intel_pasid_setup_pass_through(iommu, domain,
+			ret = intel_pasid_setup_pass_through(iommu,
 					dev, IOMMU_NO_PASID);
 		else if (domain->use_first_level)
 			ret = domain_setup_first_level(iommu, domain, dev,
@@ -4795,8 +4795,7 @@ static int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
 		goto out_free;
 
 	if (domain_type_is_si(dmar_domain))
-		ret = intel_pasid_setup_pass_through(iommu, dmar_domain,
-						     dev, pasid);
+		ret = intel_pasid_setup_pass_through(iommu, dev, pasid);
 	else if (dmar_domain->use_first_level)
 		ret = domain_setup_first_level(iommu, dmar_domain,
 					       dev, pasid);
drivers/iommu/intel/pasid.c +0 -1
index 74e8e4c17e81..8a1bcabf71a9 100644
@@ -767,7 +767,6 @@ int intel_pasid_setup_dirty_tracking(struct intel_iommu *iommu,
  * Set up the scalable mode pasid entry for passthrough translation type.
  */
 int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
-				   struct dmar_domain *domain,
 				   struct device *dev, u32 pasid)
 {
 	u16 did = FLPT_DEFAULT_DID;
Signature · 1 line
2.34.1
author maintainer
#8 lore raw

PATCH 3/4 iommu/vt-d: Remove unused vcmd interfaces

In reply to Lu Baolu

Commit 99b5726b4423 ("iommu: Remove ioasid infrastructure") has removed ioasid allocation interfaces from the iommu subsystem. As a result, these vcmd interfaces have become obsolete. Remove them to avoid dead code.

---
 drivers/iommu/intel/pasid.h |  2 --
 drivers/iommu/intel/pasid.c | 57 -------------------------------------
 2 files changed, 59 deletions(-)
drivers/iommu/intel/pasid.h +0 -2
index 16265bc1f7ec..647723c650bf 100644
@@ -117,8 +117,6 @@ int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev,
 void intel_pasid_tear_down_entry(struct intel_iommu *iommu,
 				 struct device *dev, u32 pasid,
 				 bool fault_ignore);
-int vcmd_alloc_pasid(struct intel_iommu *iommu, u32 *pasid);
-void vcmd_free_pasid(struct intel_iommu *iommu, u32 pasid);
 void intel_pasid_setup_page_snoop_control(struct intel_iommu *iommu,
 					  struct device *dev, u32 pasid);
 #endif /* __INTEL_PASID_H */
drivers/iommu/intel/pasid.c +0 -57

63 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#11 lore raw

PATCH 4/4 iommu/vt-d: Move inline helpers to header files

In reply to Lu Baolu

Move inline helpers to header files so that other files can use them without duplicating the code.

---
 drivers/iommu/intel/iommu.h | 173 +++++++++++++++++++++++++++++
 drivers/iommu/intel/pasid.h | 210 +++++++++++++++++++++++++++++++++++
 drivers/iommu/intel/iommu.c | 204 ++--------------------------------
 drivers/iommu/intel/pasid.c | 216 +-----------------------------------
 4 files changed, 398 insertions(+), 405 deletions(-)
drivers/iommu/intel/iommu.h +173 -0
index 049d6af6aae8..d747c33e4767 100644
@@ -861,6 +861,179 @@ static inline struct intel_iommu *dev_to_iommu(struct device *dev)
 	return ((struct device_domain_info *)dev_iommu_priv_get(dev))->iommu;
 }
 
+#define LEVEL_STRIDE		(9)
+#define LEVEL_MASK		(((u64)1 << LEVEL_STRIDE) - 1)
+#define MAX_AGAW_WIDTH		(64)
+#define MAX_AGAW_PFN_WIDTH	(MAX_AGAW_WIDTH - VTD_PAGE_SHIFT)
+
+static inline int agaw_to_level(int agaw)
+{
+	return agaw + 2;
+}
+
+static inline int agaw_to_width(int agaw)
+{
+	return min_t(int, 30 + agaw * LEVEL_STRIDE, MAX_AGAW_WIDTH);
+}
+
+static inline int width_to_agaw(int width)
+{
+	return DIV_ROUND_UP(width - 30, LEVEL_STRIDE);
+}
+
+static inline unsigned int level_to_offset_bits(int level)
+{
+	return (level - 1) * LEVEL_STRIDE;
+}
+
+static inline int pfn_level_offset(u64 pfn, int level)
+{
+	return (pfn >> level_to_offset_bits(level)) & LEVEL_MASK;
+}
+
+static inline u64 level_mask(int level)
+{
+	return -1ULL << level_to_offset_bits(level);
+}
+
+static inline u64 level_size(int level)
+{
+	return 1ULL << level_to_offset_bits(level);
+}
+
+static inline u64 align_to_level(u64 pfn, int level)
+{
+	return (pfn + level_size(level) - 1) & level_mask(level);
+}
+
+static inline unsigned long lvl_to_nr_pages(unsigned int lvl)
+{
+	return 1UL << min_t(int, (lvl - 1) * LEVEL_STRIDE, MAX_AGAW_PFN_WIDTH);
+}
+
+/* VT-d pages must always be _smaller_ than MM pages. Otherwise things
+   are never going to work. */
+static inline unsigned long mm_to_dma_pfn_start(unsigned long mm_pfn)
+{
+	return mm_pfn << (PAGE_SHIFT - VTD_PAGE_SHIFT);
+}
+static inline unsigned long mm_to_dma_pfn_end(unsigned long mm_pfn)
+{
+	return ((mm_pfn + 1) << (PAGE_SHIFT - VTD_PAGE_SHIFT)) - 1;
+}
+static inline unsigned long page_to_dma_pfn(struct page *pg)
+{
+	return mm_to_dma_pfn_start(page_to_pfn(pg));
+}
+static inline unsigned long virt_to_dma_pfn(void *p)
+{
+	return page_to_dma_pfn(virt_to_page(p));
+}
+
+static inline void context_set_present(struct context_entry *context)
+{
+	context->lo |= 1;
+}
+
+static inline void context_set_fault_enable(struct context_entry *context)
+{
+	context->lo &= (((u64)-1) << 2) | 1;
+}
+
+static inline void context_set_translation_type(struct context_entry *context,
+						unsigned long value)
+{
+	context->lo &= (((u64)-1) << 4) | 3;
+	context->lo |= (value & 3) << 2;
+}
+
+static inline void context_set_address_root(struct context_entry *context,
+					    unsigned long value)
+{
+	context->lo &= ~VTD_PAGE_MASK;
+	context->lo |= value & VTD_PAGE_MASK;
+}
+
+static inline void context_set_address_width(struct context_entry *context,
+					     unsigned long value)
+{
+	context->hi |= value & 7;
+}
+
+static inline void context_set_domain_id(struct context_entry *context,
+					 unsigned long value)
+{
+	context->hi |= (value & ((1 << 16) - 1)) << 8;
+}
+
+static inline void context_set_pasid(struct context_entry *context)
+{
+	context->lo |= CONTEXT_PASIDE;
+}
+
+static inline int context_domain_id(struct context_entry *c)
+{
+	return((c->hi >> 8) & 0xffff);
+}
+
+static inline void context_clear_entry(struct context_entry *context)
+{
+	context->lo = 0;
+	context->hi = 0;
+}
+
+static inline bool context_copied(struct intel_iommu *iommu, u8 bus, u8 devfn)
+{
+	if (!iommu->copied_tables)
+		return false;
+
+	return test_bit(((long)bus << 8) | devfn, iommu->copied_tables);
+}
+
+static inline void
+set_context_copied(struct intel_iommu *iommu, u8 bus, u8 devfn)
+{
+	set_bit(((long)bus << 8) | devfn, iommu->copied_tables);
+}
+
+static inline void
+clear_context_copied(struct intel_iommu *iommu, u8 bus, u8 devfn)
+{
+	clear_bit(((long)bus << 8) | devfn, iommu->copied_tables);
+}
+
+/*
+ * Set the RID_PASID field of a scalable mode context entry. The
+ * IOMMU hardware will use the PASID value set in this field for
+ * DMA translations of DMA requests without PASID.
+ */
+static inline void
+context_set_sm_rid2pasid(struct context_entry *context, unsigned long pasid)
+{
+	context->hi |= pasid & ((1 << 20) - 1);
+}
+
+/*
+ * Set the DTE(Device-TLB Enable) field of a scalable mode context
+ * entry.
+ */
+static inline void context_set_sm_dte(struct context_entry *context)
+{
+	context->lo |= BIT_ULL(2);
+}
+
+/*
+ * Set the PRE(Page Request Enable) field of a scalable mode context
+ * entry.
+ */
+static inline void context_set_sm_pre(struct context_entry *context)
+{
+	context->lo |= BIT_ULL(4);
+}
+
+/* Convert value to context PASID directory size field coding. */
+#define context_pdts(pds)	(((pds) & 0x7) << 9)
+
 struct dmar_drhd_unit *dmar_find_matched_drhd_unit(struct pci_dev *dev);
 
 int dmar_enable_qi(struct intel_iommu *iommu);
drivers/iommu/intel/pasid.h +210 -0

216 lines not on this page · raw message

drivers/iommu/intel/iommu.c +12 -192

286 lines not on this page · raw message

drivers/iommu/intel/pasid.c +3 -213

234 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

RE: [PATCH 1/4] iommu/vt-d: Introduce dev_to_iommu()

In reply to Lu Baolu
Quoted 12 lines

From: Lu Baolu <[email protected]>
Sent: Thursday, November 16, 2023 9:51 AM

drivers/iommu/intel/iommu.h +8 -0
+static inline struct intel_iommu *dev_to_iommu(struct device *dev)
+{
+	/*
+	 * Assume that valid per-device iommu structure must be installed
+	 * if iommu_probe_device() has succeeded. This helper could only
+	 * be used after device is probed.
+	 */
+	return ((struct device_domain_info *)dev_iommu_priv_get(dev))-
Quoted 1 line

iommu;

Quoted 1 line

+}

Not sure whether this helper is useful. This is only used by 2 out of 5 post-probe users. Probably just open-coding in all 5 places is clearer.

#9 lore raw

RE: [PATCH 3/4] iommu/vt-d: Remove unused vcmd interfaces

In reply to Lu Baolu
Quoted 9 lines

From: Lu Baolu <[email protected]>
Sent: Thursday, November 16, 2023 9:51 AM

Commit 99b5726b4423 ("iommu: Remove ioasid infrastructure") has removed
ioasid allocation interfaces from the iommu subsystem. As a result, these vcmd interfaces have become obsolete. Remove them to avoid dead code.

it's a surprise to see some remaining vcmd bits not removed.

with a grep actually there are more (mostly in the header files):

drivers/iommu/intel/debugfs.c: IOMMU_REGSET_ENTRY(VCMD),

drivers/iommu/intel/pasid.h:#define VCMD_CMD_ALLOC                      0x1
drivers/iommu/intel/pasid.h:#define VCMD_CMD_FREE                       0x2
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_IP                        0x1
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_SC(e)                     (((e) & 0xff) >> 1)
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_SC_SUCCESS                0
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_SC_NO_PASID_AVAIL 16
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_SC_INVALID_PASID  16
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_RESULT_PASID(e)   (((e) >> 16) & 0xfffff)
drivers/iommu/intel/pasid.h:#define VCMD_CMD_OPERAND(e)         ((e) << 16)
drivers/iommu/intel/iommu.h:#define DMAR_VCMD_REG               0xe00 /* Virtual command register */
author maintainer
#3 lore raw

Re: [PATCH 1/4] iommu/vt-d: Introduce dev_to_iommu()

In reply to Tian, Kevin
Quoted 11 lines · Kevin
Quoted 11 lines

From: Lu Baolu <[email protected]>
Sent: Thursday, November 16, 2023 9:51 AM

drivers/iommu/intel/iommu.h +8 -0
+static inline struct intel_iommu *dev_to_iommu(struct device *dev)
+{
+	/*
+	 * Assume that valid per-device iommu structure must be installed
+	 * if iommu_probe_device() has succeeded. This helper could only
+	 * be used after device is probed.
+	 */
+	return ((struct device_domain_info *)dev_iommu_priv_get(dev))-
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

iommu;

+}

Not sure whether this helper is useful. This is only used by 2 out of 5 post-probe users. Probably just open-coding in all 5 places is clearer.

I thought it should get more users in the future development.

Best regards,
baolu

author maintainer
#10 lore raw

Re: [PATCH 3/4] iommu/vt-d: Remove unused vcmd interfaces

In reply to Tian, Kevin
Quoted 15 lines · Kevin
Quoted 9 lines

From: Lu Baolu <[email protected]>
Sent: Thursday, November 16, 2023 9:51 AM

Commit 99b5726b4423 ("iommu: Remove ioasid infrastructure") has removed
ioasid allocation interfaces from the iommu subsystem. As a result, these vcmd interfaces have become obsolete. Remove them to avoid dead code.

it's a surprise to see some remaining vcmd bits not removed.

with a grep actually there are more (mostly in the header files):

drivers/iommu/intel/debugfs.c: IOMMU_REGSET_ENTRY(VCMD),

Quoted 12 lines
drivers/iommu/intel/pasid.h:#define VCMD_CMD_ALLOC                      0x1
drivers/iommu/intel/pasid.h:#define VCMD_CMD_FREE                       0x2
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_IP                        0x1
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_SC(e)                     (((e) & 0xff) >> 1)
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_SC_SUCCESS                0
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_SC_NO_PASID_AVAIL 16
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_SC_INVALID_PASID  16
drivers/iommu/intel/pasid.h:#define VCMD_VRSP_RESULT_PASID(e)   (((e) >> 16) & 0xfffff)
drivers/iommu/intel/pasid.h:#define VCMD_CMD_OPERAND(e)         ((e) << 16)
drivers/iommu/intel/iommu.h:#define DMAR_VCMD_REG               0xe00 /* Virtual command register */

Yeah! I will also remove these bits. Thanks!

Best regards,
baolu

#4 lore raw

Re: [PATCH 1/4] iommu/vt-d: Introduce dev_to_iommu()

In reply to Baolu Lu
Quoted 12 lines · Baolu Lu
Quoted 11 lines · Kevin
Quoted 11 lines

From: Lu Baolu <[email protected]>
Sent: Thursday, November 16, 2023 9:51 AM

drivers/iommu/intel/iommu.h +8 -0
+static inline struct intel_iommu *dev_to_iommu(struct device *dev)
+{
+	/*
+	 * Assume that valid per-device iommu structure must be installed
+	 * if iommu_probe_device() has succeeded. This helper could only
+	 * be used after device is probed.
+	 */
+	return ((struct device_domain_info *)dev_iommu_priv_get(dev))-
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

iommu;

+}

Not sure whether this helper is useful. This is only used by 2 out of 5 post-probe users. Probably just open-coding in all 5 places is clearer.

I thought it should get more users in the future development.

The pattern in the SMMUv2 driver is like

  struct device_domain_info *info = dev_iommu_priv_get(dev);
  struct intel_iommu *iommu = info->iommu;

Which really isn't worth the helper, unless you have lots of caes where info isn't needed at all?

Jason

author maintainer
#5 lore raw

Re: [PATCH 1/4] iommu/vt-d: Introduce dev_to_iommu()

Quoted 17 lines · Jason Gunthorpe
Quoted 16 lines · Baolu Lu
Quoted 15 lines · Kevin
Quoted 12 lines

From: Lu Baolu<[email protected]>
Sent: Thursday, November 16, 2023 9:51 AM

drivers/iommu/intel/iommu.h +8 -0
+static inline struct intel_iommu *dev_to_iommu(struct device *dev)
+{
+	/*
+	 * Assume that valid per-device iommu structure must be installed
+	 * if iommu_probe_device() has succeeded. This helper could only
+	 * be used after device is probed.
+	 */
+	return ((struct device_domain_info *)dev_iommu_priv_get(dev))-
Quoted 1 line

iommu;

Quoted 1 line

+}

Not sure whether this helper is useful. This is only used by 2 out of 5 post-probe users. Probably just open-coding in all 5 places is clearer.

Quoted 8 lines
Quoted 1 line

I thought it should get more users in the future development.

The pattern in the SMMUv2 driver is like

   struct device_domain_info *info = dev_iommu_priv_get(dev);
   struct intel_iommu *iommu = info->iommu;

Which really isn't worth the helper, unless you have lots of caes where info isn't needed at all?

No. As Kevin pointed out, there are only 2 places.

I will drop this helper.

Best regards,
baolu