Skip to contentSkip to conversation

intel_iommu: Use correct shift for 256 bits qi descriptor

PATCH In review Liu Yi L 3 participants 4 messages Jul 4, 2020 – Jul 7, 2020

lore
Share & tools
lore

Liu Yi L

author
#0 lore raw

PATCH 1/1 intel_iommu: Use correct shift for 256 bits qi descriptor

In chapter 10.4.23 of VT-d spec 3.0, Descriptor Width bit was introduced in VTD_IQA_REG. Sfotware could set this bit to tell VT-d the QI descriptor from software would be 256 bits. Accordingly, the VTD_IQH_QH_SHIFT should be 5 when descriptor size is 256 bits.

This patch adds the DW bit check when deciding the shift used to update VTD_IQH_REG.

---
 hw/i386/intel_iommu.c          | 7 ++++++-
 hw/i386/intel_iommu_internal.h | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)
hw/i386/intel_iommu.c +6 -1
index df7ad25..8703a2d 100644
@@ -2549,6 +2549,11 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s)
 /* Try to fetch and process more Invalidation Descriptors */
 static void vtd_fetch_inv_desc(IntelIOMMUState *s)
 {
+    int qi_shift;
+
+    /* Refer to 10.4.23 of VT-d spec 3.0 */
+    qi_shift = s->iq_dw ? VTD_IQH_QH_SHIFT_5 : VTD_IQH_QH_SHIFT_4;
+
     trace_vtd_inv_qi_fetch();
 
     if (s->iq_tail >= s->iq_size) {
@@ -2567,7 +2572,7 @@ static void vtd_fetch_inv_desc(IntelIOMMUState *s)
         }
         /* Must update the IQH_REG in time */
         vtd_set_quad_raw(s, DMAR_IQH_REG,
-                         (((uint64_t)(s->iq_head)) << VTD_IQH_QH_SHIFT) &
+                         (((uint64_t)(s->iq_head)) << qi_shift) &
                          VTD_IQH_QH_MASK);
     }
 }
hw/i386/intel_iommu_internal.h +2 -1
index 862033e..3d5487f 100644
@@ -230,7 +230,8 @@
 #define VTD_IQA_DW_MASK             0x800
 
 /* IQH_REG */
-#define VTD_IQH_QH_SHIFT            4
+#define VTD_IQH_QH_SHIFT_4          4
+#define VTD_IQH_QH_SHIFT_5          5
 #define VTD_IQH_QH_MASK             0x7fff0ULL
 
 /* ICS_REG */
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Liu Yi L

In chapter 10.4.23 of VT-d spec 3.0, Descriptor Width bit was introduced in VTD_IQA_REG. Sfotware could set this bit to tell VT-d the QI descriptor from software would be 256 bits. Accordingly, the VTD_IQH_QH_SHIFT should be 5 when descriptor size is 256 bits.

This patch adds the DW bit check when deciding the shift used to update VTD_IQH_REG.

Signature · 1 line
Peter Xu
author
#2 lore raw
Quoted 9 lines

From: Peter Xu <[email protected]>
Sent: Tuesday, July 7, 2020 4:58 AM

Quoted 5 lines · Liu Yi L

In chapter 10.4.23 of VT-d spec 3.0, Descriptor Width bit was introduced in VTD_IQA_REG. Sfotware could set this bit to tell VT-d the QI descriptor from software would be 256 bits. Accordingly, the VTD_IQH_QH_SHIFT should be 5 when descriptor size is 256 bits.

Quoted 6 lines
Quoted 4 lines

This patch adds the DW bit check when deciding the shift used to update VTD_IQH_REG.

thanks.

Regards,
Yi Liu

Acked-by on v1 1/1
#3 lore raw
In reply to Liu Yi L
Quoted 2 lines · Liu Yi L

In chapter 10.4.23 of VT-d spec 3.0, Descriptor Width bit was introduced in VTD_IQA_REG. Sfotware could set this bit to tell VT-d the QI descriptor

Typo.

Quoted 7 lines

from software would be 256 bits. Accordingly, the VTD_IQH_QH_SHIFT should be 5 when descriptor size is 256 bits.

This patch adds the DW bit check when deciding the shift used to update VTD_IQH_REG.

Quoted 44 lines
---
  hw/i386/intel_iommu.c          | 7 ++++++-
  hw/i386/intel_iommu_internal.h | 3 ++-
  2 files changed, 8 insertions(+), 2 deletions(-)
hw/i386/intel_iommu.c +6 -1
index df7ad25..8703a2d 100644
@@ -2549,6 +2549,11 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s)
  /* Try to fetch and process more Invalidation Descriptors */
  static void vtd_fetch_inv_desc(IntelIOMMUState *s)
  {
+    int qi_shift;
+
+    /* Refer to 10.4.23 of VT-d spec 3.0 */
+    qi_shift = s->iq_dw ? VTD_IQH_QH_SHIFT_5 : VTD_IQH_QH_SHIFT_4;
+
      trace_vtd_inv_qi_fetch();
 
      if (s->iq_tail >= s->iq_size) {
@@ -2567,7 +2572,7 @@ static void vtd_fetch_inv_desc(IntelIOMMUState *s)
          }
          /* Must update the IQH_REG in time */
          vtd_set_quad_raw(s, DMAR_IQH_REG,
-                         (((uint64_t)(s->iq_head)) << VTD_IQH_QH_SHIFT) &
+                         (((uint64_t)(s->iq_head)) << qi_shift) &
                           VTD_IQH_QH_MASK);
      }
  }
hw/i386/intel_iommu_internal.h +2 -1
index 862033e..3d5487f 100644
@@ -230,7 +230,8 @@
  #define VTD_IQA_DW_MASK             0x800
 
  /* IQH_REG */
-#define VTD_IQH_QH_SHIFT            4
+#define VTD_IQH_QH_SHIFT_4          4
+#define VTD_IQH_QH_SHIFT_5          5
  #define VTD_IQH_QH_MASK             0x7fff0ULL
 
  /* ICS_REG */