Re: [PATCH v2 6/6] iommu/vt-d: Add debugfs support for Intel IOMMU Interrupt remapping

2017-11-22 Thread Andy Shevchenko
On Wed, 2017-11-22 at 11:25 -0800, Sohil Mehta wrote:
> Debugfs extension for Intel IOMMU to dump Interrupt remapping table
> entries for Interrupt remapping and Interrupt posting.

> +static int intel_iommu_ir_open(struct inode *inode, struct file
> *file)
> +{
> + return single_open(file, intel_iommu_ir_show, inode-
> >i_private);
> +}
> +
> +static const struct file_operations intel_iommu_ir_fops = {
> + .open   = intel_iommu_ir_open,
> + .read   = seq_read,
> + .llseek = seq_lseek,
> + .release= single_release,
> + .owner  = THIS_MODULE,
> +};
> 

Same comments as per patch 4.

-- 
Andy Shevchenko 
Intel Finland Oy


Re: [PATCH v2 6/6] iommu/vt-d: Add debugfs support for Intel IOMMU Interrupt remapping

2017-11-22 Thread Andy Shevchenko
On Wed, 2017-11-22 at 11:25 -0800, Sohil Mehta wrote:
> Debugfs extension for Intel IOMMU to dump Interrupt remapping table
> entries for Interrupt remapping and Interrupt posting.

> +static int intel_iommu_ir_open(struct inode *inode, struct file
> *file)
> +{
> + return single_open(file, intel_iommu_ir_show, inode-
> >i_private);
> +}
> +
> +static const struct file_operations intel_iommu_ir_fops = {
> + .open   = intel_iommu_ir_open,
> + .read   = seq_read,
> + .llseek = seq_lseek,
> + .release= single_release,
> + .owner  = THIS_MODULE,
> +};
> 

Same comments as per patch 4.

-- 
Andy Shevchenko 
Intel Finland Oy


[PATCH v2 6/6] iommu/vt-d: Add debugfs support for Intel IOMMU Interrupt remapping

2017-11-22 Thread Sohil Mehta
Debugfs extension for Intel IOMMU to dump Interrupt remapping table
entries for Interrupt remapping and Interrupt posting.

The file /sys/kernel/debug/intel_iommu/intel_iommu_interrupt_remap
provides detailed information, such as Index, Source Id, Destination Id,
Vector and the raw values for entries with the present bit set, in the
format shown.

Remapped Interrupt supported on IOMMU: dmar5
 IR table address:93e09d54c310
---
 Index  SID  Dest_ID  Vct Raw_value_high   Raw_value_low
 1  3a00 0600 2c  00043a00 062c0009
 1114301 0900 a2  00044301 09a20009

Posted Interrupt supported on IOMMU: dmar5
 IR table address:93e09d54c310

 Index  SID  PDA_high PDA_low  Vct Raw_value_high   Raw_value_low
 4  4300 0010 40c7c880 41  00144300 40c7c88000418001
 5  4300 0010 40c7c880 51  00144300 40c7c88000518001

Cc: Gayatri Kammela 
Cc: Jacob Pan 
Cc: Fenghua Yu 
Cc: Ashok Raj 
Signed-off-by: Sohil Mehta 
---

v2: Handle the case when IR is not enabled. Fix seq_printf formatting

 drivers/iommu/intel-iommu-debug.c | 123 ++
 1 file changed, 123 insertions(+)

diff --git a/drivers/iommu/intel-iommu-debug.c 
b/drivers/iommu/intel-iommu-debug.c
index 22a0683..7fda862 100644
--- a/drivers/iommu/intel-iommu-debug.c
+++ b/drivers/iommu/intel-iommu-debug.c
@@ -12,6 +12,7 @@
  *
  * Authors: Gayatri Kammela 
  *  Jacob Pan 
+ *  Sohil Mehta 
  *
  */
 
@@ -280,6 +281,119 @@ static const struct file_operations intel_iommu_regs_fops 
= {
.release= single_release,
 };
 
+#ifdef CONFIG_IRQ_REMAP
+static void ir_tbl_remap_entry_show(struct seq_file *m, void *unused,
+  struct intel_iommu *iommu)
+{
+   int idx;
+   struct irte *ri_entry;
+
+   /* Print the header only once */
+   seq_printf(m, " Index  SID  Dest_ID  Vct"
+  " Raw_value_high   Raw_value_low\n");
+
+   for (idx = 0; idx < INTR_REMAP_TABLE_ENTRIES; idx++) {
+   ri_entry = >ir_table->base[idx];
+   if (!ri_entry->present || ri_entry->p_pst)
+   continue;
+   seq_printf(m,
+  " %d\t%04x %08x %02x  %016llx %016llx\n",
+  idx, ri_entry->sid,
+  ri_entry->dest_id, ri_entry->vector,
+  ri_entry->high, ri_entry->low);
+   }
+}
+
+static void ir_tbl_posted_entry_show(struct seq_file *m, void *unused,
+   struct intel_iommu *iommu)
+{
+   int idx;
+   struct irte *pi_entry;
+
+   /* Print the header only once */
+   seq_printf(m, " Index  SID  PDA_high PDA_low  Vct"
+  " Raw_value_high   Raw_value_low\n");
+
+   for (idx = 0; idx < INTR_REMAP_TABLE_ENTRIES; idx++) {
+   pi_entry = >ir_table->base[idx];
+   if (!pi_entry->present || !pi_entry->p_pst)
+   continue;
+   seq_printf(m,
+  " %d\t%04x %08x %08x %02x  %016llx %016llx\n",
+  idx, pi_entry->sid,
+  pi_entry->pda_h, (pi_entry->pda_l)<<6,
+  pi_entry->vector, pi_entry->high,
+  pi_entry->low);
+   }
+}
+
+/*
+ * For active IOMMUs go through the Interrupt remapping
+ * table and print valid entries in a table format for
+ * Remapped and Posted Interrupts.
+ */
+static int intel_iommu_ir_show(struct seq_file *m, void *unused)
+{
+   struct dmar_drhd_unit *drhd;
+   struct intel_iommu *iommu;
+
+   rcu_read_lock();
+   for_each_active_iommu(iommu, drhd) {
+   if (!iommu || !ecap_ir_support(iommu->ecap))
+   continue;
+
+   seq_printf(m,
+  "\nRemapped Interrupt supported on IOMMU: %s\n"
+  " IR table address:%p\n",
+  iommu->name, iommu->ir_table);
+
+   seq_printf(m, "---"
+  "\n");
+
+   if (iommu->ir_table)
+   ir_tbl_remap_entry_show(m, unused, iommu);
+   else
+   seq_printf(m, "Interrupt Remapping is not enabled\n");
+   }
+
+   seq_printf(m, "\n\t\t\t\t\t\t\t\n");
+
+   for_each_active_iommu(iommu, drhd) {
+   if (!iommu || !cap_pi_support(iommu->cap))
+   continue;
+
+   seq_printf(m,
+  "\nPosted 

[PATCH v2 6/6] iommu/vt-d: Add debugfs support for Intel IOMMU Interrupt remapping

2017-11-22 Thread Sohil Mehta
Debugfs extension for Intel IOMMU to dump Interrupt remapping table
entries for Interrupt remapping and Interrupt posting.

The file /sys/kernel/debug/intel_iommu/intel_iommu_interrupt_remap
provides detailed information, such as Index, Source Id, Destination Id,
Vector and the raw values for entries with the present bit set, in the
format shown.

Remapped Interrupt supported on IOMMU: dmar5
 IR table address:93e09d54c310
---
 Index  SID  Dest_ID  Vct Raw_value_high   Raw_value_low
 1  3a00 0600 2c  00043a00 062c0009
 1114301 0900 a2  00044301 09a20009

Posted Interrupt supported on IOMMU: dmar5
 IR table address:93e09d54c310

 Index  SID  PDA_high PDA_low  Vct Raw_value_high   Raw_value_low
 4  4300 0010 40c7c880 41  00144300 40c7c88000418001
 5  4300 0010 40c7c880 51  00144300 40c7c88000518001

Cc: Gayatri Kammela 
Cc: Jacob Pan 
Cc: Fenghua Yu 
Cc: Ashok Raj 
Signed-off-by: Sohil Mehta 
---

v2: Handle the case when IR is not enabled. Fix seq_printf formatting

 drivers/iommu/intel-iommu-debug.c | 123 ++
 1 file changed, 123 insertions(+)

diff --git a/drivers/iommu/intel-iommu-debug.c 
b/drivers/iommu/intel-iommu-debug.c
index 22a0683..7fda862 100644
--- a/drivers/iommu/intel-iommu-debug.c
+++ b/drivers/iommu/intel-iommu-debug.c
@@ -12,6 +12,7 @@
  *
  * Authors: Gayatri Kammela 
  *  Jacob Pan 
+ *  Sohil Mehta 
  *
  */
 
@@ -280,6 +281,119 @@ static const struct file_operations intel_iommu_regs_fops 
= {
.release= single_release,
 };
 
+#ifdef CONFIG_IRQ_REMAP
+static void ir_tbl_remap_entry_show(struct seq_file *m, void *unused,
+  struct intel_iommu *iommu)
+{
+   int idx;
+   struct irte *ri_entry;
+
+   /* Print the header only once */
+   seq_printf(m, " Index  SID  Dest_ID  Vct"
+  " Raw_value_high   Raw_value_low\n");
+
+   for (idx = 0; idx < INTR_REMAP_TABLE_ENTRIES; idx++) {
+   ri_entry = >ir_table->base[idx];
+   if (!ri_entry->present || ri_entry->p_pst)
+   continue;
+   seq_printf(m,
+  " %d\t%04x %08x %02x  %016llx %016llx\n",
+  idx, ri_entry->sid,
+  ri_entry->dest_id, ri_entry->vector,
+  ri_entry->high, ri_entry->low);
+   }
+}
+
+static void ir_tbl_posted_entry_show(struct seq_file *m, void *unused,
+   struct intel_iommu *iommu)
+{
+   int idx;
+   struct irte *pi_entry;
+
+   /* Print the header only once */
+   seq_printf(m, " Index  SID  PDA_high PDA_low  Vct"
+  " Raw_value_high   Raw_value_low\n");
+
+   for (idx = 0; idx < INTR_REMAP_TABLE_ENTRIES; idx++) {
+   pi_entry = >ir_table->base[idx];
+   if (!pi_entry->present || !pi_entry->p_pst)
+   continue;
+   seq_printf(m,
+  " %d\t%04x %08x %08x %02x  %016llx %016llx\n",
+  idx, pi_entry->sid,
+  pi_entry->pda_h, (pi_entry->pda_l)<<6,
+  pi_entry->vector, pi_entry->high,
+  pi_entry->low);
+   }
+}
+
+/*
+ * For active IOMMUs go through the Interrupt remapping
+ * table and print valid entries in a table format for
+ * Remapped and Posted Interrupts.
+ */
+static int intel_iommu_ir_show(struct seq_file *m, void *unused)
+{
+   struct dmar_drhd_unit *drhd;
+   struct intel_iommu *iommu;
+
+   rcu_read_lock();
+   for_each_active_iommu(iommu, drhd) {
+   if (!iommu || !ecap_ir_support(iommu->ecap))
+   continue;
+
+   seq_printf(m,
+  "\nRemapped Interrupt supported on IOMMU: %s\n"
+  " IR table address:%p\n",
+  iommu->name, iommu->ir_table);
+
+   seq_printf(m, "---"
+  "\n");
+
+   if (iommu->ir_table)
+   ir_tbl_remap_entry_show(m, unused, iommu);
+   else
+   seq_printf(m, "Interrupt Remapping is not enabled\n");
+   }
+
+   seq_printf(m, "\n\t\t\t\t\t\t\t\n");
+
+   for_each_active_iommu(iommu, drhd) {
+   if (!iommu || !cap_pi_support(iommu->cap))
+   continue;
+
+   seq_printf(m,
+  "\nPosted Interrupt supported on IOMMU: %s\n"
+  " IR table address:%p\n",
+  iommu->name, iommu->ir_table);
+
+   seq_printf(m,