All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch V1 0/2] iommu/vtd: Fixes to the IOMMU debugfs
@ 2020-03-09 20:09 Megha Dey
  2020-03-09 20:09 ` [Patch V1 1/2] iommu/vt-d: Fix debugfs register reads Megha Dey
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Megha Dey @ 2020-03-09 20:09 UTC (permalink / raw)
  To: dwmw2, baolu.lu, iommu; +Cc: Megha Dey, megha.dey

This patchset aims to fix some of the existing issues in the iommu debugfs.

The first patch aims to fix the debugfs register reads by using the correct
read function variant while reading the contents of iommu registers while
the second patch ensures the debugfs directory is populated even if DMA
remapping is disabled.

Megha Dey (2):
  iommu/vt-d: Fix debugfs register reads
  iommu/vt-d: Populate debugfs if IOMMUs are detected

 drivers/iommu/intel-iommu-debugfs.c | 53 ++++++++++++++++++++++++++-----------
 drivers/iommu/intel-iommu.c         |  4 ++-
 include/linux/intel-iommu.h         |  2 ++
 3 files changed, 43 insertions(+), 16 deletions(-)

-- 
2.7.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Patch V1 1/2] iommu/vt-d: Fix debugfs register reads
  2020-03-09 20:09 [Patch V1 0/2] iommu/vtd: Fixes to the IOMMU debugfs Megha Dey
@ 2020-03-09 20:09 ` Megha Dey
  2020-03-10  1:25   ` Lu Baolu
  2020-03-09 20:09 ` [Patch V1 2/2] iommu/vt-d: Populate debugfs if IOMMUs are detected Megha Dey
  2020-03-10  0:50 ` [Patch V1 0/2] iommu/vtd: Fixes to the IOMMU debugfs Lu Baolu
  2 siblings, 1 reply; 6+ messages in thread
From: Megha Dey @ 2020-03-09 20:09 UTC (permalink / raw)
  To: dwmw2, baolu.lu, iommu; +Cc: Megha Dey, megha.dey

Commit 6825d3ea6cde ("iommu/vt-d: Add debugfs support to show register
contents") dumps the register contents for all IOMMU devices.

Currently, a 64 bit read(dmar_readq) is done for all the IOMMU registers,
even though some of the registers are 32 bits, which is incorrect.

Use the correct read function variant (dmar_readl/dmar_readq) while 
reading the contents of 32/64 bit registers respectively.

Signed-off-by: Megha Dey <megha.dey@linux.intel.com>
---
 drivers/iommu/intel-iommu-debugfs.c | 40 +++++++++++++++++++++++--------------
 include/linux/intel-iommu.h         |  2 ++
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/drivers/iommu/intel-iommu-debugfs.c b/drivers/iommu/intel-iommu-debugfs.c
index c1257be..0a77919 100644
--- a/drivers/iommu/intel-iommu-debugfs.c
+++ b/drivers/iommu/intel-iommu-debugfs.c
@@ -33,38 +33,42 @@ struct iommu_regset {
 
 #define IOMMU_REGSET_ENTRY(_reg_)					\
 	{ DMAR_##_reg_##_REG, __stringify(_reg_) }
-static const struct iommu_regset iommu_regs[] = {
+
+static const struct iommu_regset iommu_regs_32[] = {
 	IOMMU_REGSET_ENTRY(VER),
-	IOMMU_REGSET_ENTRY(CAP),
-	IOMMU_REGSET_ENTRY(ECAP),
 	IOMMU_REGSET_ENTRY(GCMD),
 	IOMMU_REGSET_ENTRY(GSTS),
-	IOMMU_REGSET_ENTRY(RTADDR),
-	IOMMU_REGSET_ENTRY(CCMD),
 	IOMMU_REGSET_ENTRY(FSTS),
 	IOMMU_REGSET_ENTRY(FECTL),
 	IOMMU_REGSET_ENTRY(FEDATA),
 	IOMMU_REGSET_ENTRY(FEADDR),
 	IOMMU_REGSET_ENTRY(FEUADDR),
-	IOMMU_REGSET_ENTRY(AFLOG),
 	IOMMU_REGSET_ENTRY(PMEN),
 	IOMMU_REGSET_ENTRY(PLMBASE),
 	IOMMU_REGSET_ENTRY(PLMLIMIT),
+	IOMMU_REGSET_ENTRY(ICS),
+	IOMMU_REGSET_ENTRY(PRS),
+	IOMMU_REGSET_ENTRY(PECTL),
+	IOMMU_REGSET_ENTRY(PEDATA),
+	IOMMU_REGSET_ENTRY(PEADDR),
+	IOMMU_REGSET_ENTRY(PEUADDR),
+};
+
+static const struct iommu_regset iommu_regs_64[] = {
+	IOMMU_REGSET_ENTRY(CAP),
+	IOMMU_REGSET_ENTRY(ECAP),
+	IOMMU_REGSET_ENTRY(RTADDR),
+	IOMMU_REGSET_ENTRY(CCMD),
+	IOMMU_REGSET_ENTRY(AFLOG),
 	IOMMU_REGSET_ENTRY(PHMBASE),
 	IOMMU_REGSET_ENTRY(PHMLIMIT),
 	IOMMU_REGSET_ENTRY(IQH),
 	IOMMU_REGSET_ENTRY(IQT),
 	IOMMU_REGSET_ENTRY(IQA),
-	IOMMU_REGSET_ENTRY(ICS),
 	IOMMU_REGSET_ENTRY(IRTA),
 	IOMMU_REGSET_ENTRY(PQH),
 	IOMMU_REGSET_ENTRY(PQT),
 	IOMMU_REGSET_ENTRY(PQA),
-	IOMMU_REGSET_ENTRY(PRS),
-	IOMMU_REGSET_ENTRY(PECTL),
-	IOMMU_REGSET_ENTRY(PEDATA),
-	IOMMU_REGSET_ENTRY(PEADDR),
-	IOMMU_REGSET_ENTRY(PEUADDR),
 	IOMMU_REGSET_ENTRY(MTRRCAP),
 	IOMMU_REGSET_ENTRY(MTRRDEF),
 	IOMMU_REGSET_ENTRY(MTRR_FIX64K_00000),
@@ -127,10 +131,16 @@ static int iommu_regset_show(struct seq_file *m, void *unused)
 		 * by adding the offset to the pointer (virtual address).
 		 */
 		raw_spin_lock_irqsave(&iommu->register_lock, flag);
-		for (i = 0 ; i < ARRAY_SIZE(iommu_regs); i++) {
-			value = dmar_readq(iommu->reg + iommu_regs[i].offset);
+		for (i = 0 ; i < ARRAY_SIZE(iommu_regs_32); i++) {
+			value = dmar_readl(iommu->reg + iommu_regs_32[i].offset);
+			seq_printf(m, "%-16s\t0x%02x\t\t0x%016llx\n",
+				   iommu_regs_32[i].regs, iommu_regs_32[i].offset,
+				   value);
+		}
+		for (i = 0 ; i < ARRAY_SIZE(iommu_regs_64); i++) {
+			value = dmar_readq(iommu->reg + iommu_regs_64[i].offset);
 			seq_printf(m, "%-16s\t0x%02x\t\t0x%016llx\n",
-				   iommu_regs[i].regs, iommu_regs[i].offset,
+				   iommu_regs_64[i].regs, iommu_regs_64[i].offset,
 				   value);
 		}
 		raw_spin_unlock_irqrestore(&iommu->register_lock, flag);
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index 4a16b39..980234a 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -123,6 +123,8 @@
 
 #define dmar_readq(a) readq(a)
 #define dmar_writeq(a,v) writeq(v,a)
+#define dmar_readl(a) readl(a)
+#define dmar_writel(a, v) writel(v, a)
 
 #define DMAR_VER_MAJOR(v)		(((v) & 0xf0) >> 4)
 #define DMAR_VER_MINOR(v)		((v) & 0x0f)
-- 
2.7.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Patch V1 2/2] iommu/vt-d: Populate debugfs if IOMMUs are detected
  2020-03-09 20:09 [Patch V1 0/2] iommu/vtd: Fixes to the IOMMU debugfs Megha Dey
  2020-03-09 20:09 ` [Patch V1 1/2] iommu/vt-d: Fix debugfs register reads Megha Dey
@ 2020-03-09 20:09 ` Megha Dey
  2020-03-10  0:50 ` [Patch V1 0/2] iommu/vtd: Fixes to the IOMMU debugfs Lu Baolu
  2 siblings, 0 replies; 6+ messages in thread
From: Megha Dey @ 2020-03-09 20:09 UTC (permalink / raw)
  To: dwmw2, baolu.lu, iommu; +Cc: Megha Dey, megha.dey

Currently, the intel iommu debugfs directory(/sys/kernel/debug/iommu/intel)
gets populated only when DMA remapping is enabled (dmar_disabled = 0)
irrespective of whether interrupt remapping is enabled or not.

Instead, populate the intel iommu debugfs directory if any IOMMUs are
detected.

Signed-off-by: Megha Dey <megha.dey@linux.intel.com>
---
 drivers/iommu/intel-iommu-debugfs.c | 13 +++++++++++++
 drivers/iommu/intel-iommu.c         |  4 +++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-iommu-debugfs.c b/drivers/iommu/intel-iommu-debugfs.c
index 0a77919..8d24c4d 100644
--- a/drivers/iommu/intel-iommu-debugfs.c
+++ b/drivers/iommu/intel-iommu-debugfs.c
@@ -282,9 +282,15 @@ static int dmar_translation_struct_show(struct seq_file *m, void *unused)
 {
 	struct dmar_drhd_unit *drhd;
 	struct intel_iommu *iommu;
+	u32 sts;
 
 	rcu_read_lock();
 	for_each_active_iommu(iommu, drhd) {
+		sts = dmar_readl(iommu->reg + DMAR_GSTS_REG);
+		if (!(sts & DMA_GSTS_TES)) {
+			seq_puts(m, "DMA Remapping is not enabled\n");
+			return 0;
+		}
 		root_tbl_walk(m, iommu);
 		seq_putc(m, '\n');
 	}
@@ -425,6 +431,7 @@ static int ir_translation_struct_show(struct seq_file *m, void *unused)
 	struct dmar_drhd_unit *drhd;
 	struct intel_iommu *iommu;
 	u64 irta;
+	u32 sts;
 
 	rcu_read_lock();
 	for_each_active_iommu(iommu, drhd) {
@@ -434,6 +441,12 @@ static int ir_translation_struct_show(struct seq_file *m, void *unused)
 		seq_printf(m, "Remapped Interrupt supported on IOMMU: %s\n",
 			   iommu->name);
 
+		sts = dmar_readl(iommu->reg + DMAR_GSTS_REG);
+		if (!(sts & DMA_GSTS_IRES)) {
+			seq_puts(m, "Interrupt Remapping is not enabled\n");
+			return 0;
+		}
+
 		if (iommu->ir_table) {
 			irta = virt_to_phys(iommu->ir_table->base);
 			seq_printf(m, " IR table address:%llx\n", irta);
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 9dc3767..0bf0ba7 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -5123,6 +5123,9 @@ int __init intel_iommu_init(void)
 
 	down_write(&dmar_global_lock);
 
+	if (!no_iommu)
+		intel_iommu_debugfs_init();
+
 	if (no_iommu || dmar_disabled) {
 		/*
 		 * We exit the function here to ensure IOMMU's remapping and
@@ -5215,7 +5218,6 @@ int __init intel_iommu_init(void)
 	pr_info("Intel(R) Virtualization Technology for Directed I/O\n");
 
 	intel_iommu_enabled = 1;
-	intel_iommu_debugfs_init();
 
 	return 0;
 
-- 
2.7.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Patch V1 0/2] iommu/vtd: Fixes to the IOMMU debugfs
  2020-03-09 20:09 [Patch V1 0/2] iommu/vtd: Fixes to the IOMMU debugfs Megha Dey
  2020-03-09 20:09 ` [Patch V1 1/2] iommu/vt-d: Fix debugfs register reads Megha Dey
  2020-03-09 20:09 ` [Patch V1 2/2] iommu/vt-d: Populate debugfs if IOMMUs are detected Megha Dey
@ 2020-03-10  0:50 ` Lu Baolu
  2020-03-10 10:51   ` Joerg Roedel
  2 siblings, 1 reply; 6+ messages in thread
From: Lu Baolu @ 2020-03-10  0:50 UTC (permalink / raw)
  To: Megha Dey, dwmw2, iommu, Joerg Roedel; +Cc: megha.dey

Hi Megha,

Thanks for the fixes. For two patches in this series:

Acked-by: Lu Baolu <baolu.lu@linux.intel.com>

Best regards,
baolu

On 2020/3/10 4:09, Megha Dey wrote:
> This patchset aims to fix some of the existing issues in the iommu debugfs.
> 
> The first patch aims to fix the debugfs register reads by using the correct
> read function variant while reading the contents of iommu registers while
> the second patch ensures the debugfs directory is populated even if DMA
> remapping is disabled.
> 
> Megha Dey (2):
>    iommu/vt-d: Fix debugfs register reads
>    iommu/vt-d: Populate debugfs if IOMMUs are detected
> 
>   drivers/iommu/intel-iommu-debugfs.c | 53 ++++++++++++++++++++++++++-----------
>   drivers/iommu/intel-iommu.c         |  4 ++-
>   include/linux/intel-iommu.h         |  2 ++
>   3 files changed, 43 insertions(+), 16 deletions(-)
> 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch V1 1/2] iommu/vt-d: Fix debugfs register reads
  2020-03-09 20:09 ` [Patch V1 1/2] iommu/vt-d: Fix debugfs register reads Megha Dey
@ 2020-03-10  1:25   ` Lu Baolu
  0 siblings, 0 replies; 6+ messages in thread
From: Lu Baolu @ 2020-03-10  1:25 UTC (permalink / raw)
  To: Megha Dey, dwmw2, iommu; +Cc: megha.dey

On 2020/3/10 4:09, Megha Dey wrote:
> Commit 6825d3ea6cde ("iommu/vt-d: Add debugfs support to show register
> contents") dumps the register contents for all IOMMU devices.
> 
> Currently, a 64 bit read(dmar_readq) is done for all the IOMMU registers,
> even though some of the registers are 32 bits, which is incorrect.
> 
> Use the correct read function variant (dmar_readl/dmar_readq) while
> reading the contents of 32/64 bit registers respectively.
> 
> Signed-off-by: Megha Dey <megha.dey@linux.intel.com>

Fixes: 6825d3ea6cdea ("iommu/vt-d: Add debugfs support to show register 
contents")
Cc: Cc: stable@vger.kernel.org # v4.20

Best regards,
baolu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch V1 0/2] iommu/vtd: Fixes to the IOMMU debugfs
  2020-03-10  0:50 ` [Patch V1 0/2] iommu/vtd: Fixes to the IOMMU debugfs Lu Baolu
@ 2020-03-10 10:51   ` Joerg Roedel
  0 siblings, 0 replies; 6+ messages in thread
From: Joerg Roedel @ 2020-03-10 10:51 UTC (permalink / raw)
  To: Lu Baolu; +Cc: dwmw2, iommu, Megha Dey, megha.dey

On Tue, Mar 10, 2020 at 08:50:47AM +0800, Lu Baolu wrote:
> Thanks for the fixes. For two patches in this series:
> 
> Acked-by: Lu Baolu <baolu.lu@linux.intel.com>
> 
> Best regards,
> baolu
> 
> On 2020/3/10 4:09, Megha Dey wrote:
> > This patchset aims to fix some of the existing issues in the iommu debugfs.
> > 
> > The first patch aims to fix the debugfs register reads by using the correct
> > read function variant while reading the contents of iommu registers while
> > the second patch ensures the debugfs directory is populated even if DMA
> > remapping is disabled.
> > 
> > Megha Dey (2):
> >    iommu/vt-d: Fix debugfs register reads
> >    iommu/vt-d: Populate debugfs if IOMMUs are detected

Applied both, thanks.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-03-10 10:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-09 20:09 [Patch V1 0/2] iommu/vtd: Fixes to the IOMMU debugfs Megha Dey
2020-03-09 20:09 ` [Patch V1 1/2] iommu/vt-d: Fix debugfs register reads Megha Dey
2020-03-10  1:25   ` Lu Baolu
2020-03-09 20:09 ` [Patch V1 2/2] iommu/vt-d: Populate debugfs if IOMMUs are detected Megha Dey
2020-03-10  0:50 ` [Patch V1 0/2] iommu/vtd: Fixes to the IOMMU debugfs Lu Baolu
2020-03-10 10:51   ` Joerg Roedel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.