iommu/vtd: Fixes to the IOMMU debugfs
cover iommu/vtd: Fixes to the IOMMU debugfs
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(-)
Signature · 6 lines
2.7.4 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 1/2 iommu/vt-d: Fix debugfs register reads
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.
--- drivers/iommu/intel-iommu-debugfs.c | 40 +++++++++++++++++++++++-------------- include/linux/intel-iommu.h | 2 ++ 2 files changed, 27 insertions(+), 15 deletions(-)
drivers/iommu/intel-iommu-debugfs.c +25 -15
@@ -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);
include/linux/intel-iommu.h +2 -0
@@ -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)
Signature · 6 lines
2.7.4 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [Patch V1 1/2] iommu/vt-d: Fix debugfs register reads
Quoted 10 lines · 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 <[email protected]>
Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 2/2 iommu/vt-d: Populate debugfs if IOMMUs are detected
In reply to Megha DeyCurrently, 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.
--- drivers/iommu/intel-iommu-debugfs.c | 13 +++++++++++++ drivers/iommu/intel-iommu.c | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-)
drivers/iommu/intel-iommu-debugfs.c +13 -0
@@ -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);
drivers/iommu/intel-iommu.c +3 -1
@@ -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 ;
Signature · 6 lines
2.7.4 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hi Megha,
Thanks for the fixes. For two patches in this series:
Best regards,
baolu
Quoted 7 lines · 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.
Quoted 9 lines
Megha Dey (2):
iommu/vt-d: Fix debugfs register reads iommu/vt-d: Populate debugfs if IOMMUs are detecteddrivers/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
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerQuoted 18 lines · Lu Baolu
Thanks for the fixes. For two patches in this series:
Acked-by Lu Baolu <[email protected]>Best regards,
baoluQuoted 10 lines · 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
Applied both, thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu