Skip to contentSkip to conversation

intel-iommu: fix Read DMAR IQA REG DW

PATCH In review YeeLi 3 participants 8 messages Jul 4, 2024 – Jul 24, 2024

lore
Share & tools
lore

YeeLi

author
#0 lore raw

PATCH 1/1 intel-iommu: fix Read DMAR IQA REG DW

From: yeeli <[email protected]>

When dmar_readq or devmem2 read the DW of IQA always 0UL because "& VTD_IQA_QS". So, try to fix it.

case:
after vtd_mem_write
IQA val: 0x100206801

after vtd_mem_read
IQA val: 0x100206001

---
 hw/i386/intel_iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/i386/intel_iommu.c +2 -1
index 37c21a0aec..e230a45940 100644
@@ -2938,7 +2938,8 @@ static uint64_t vtd_mem_read(void *opaque, hwaddr addr, unsigned size)
 
     /* Invalidation Queue Address Register, 64-bit */
     case DMAR_IQA_REG:
-        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & VTD_IQA_QS);
+        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & VTD_IQA_QS
+                | VTD_IQA_DW_MASK);
         if (size == 4) {
             val = val & ((1ULL << 32) - 1);
         }
Signature · 1 line
2.34.1
author
#1 lore raw

Sorry, the patch missing "(( ))"
Replace "& VTD_IQA_QS" with "& (VTD_IQA_QS | VTD_IQA_DW_MASK))" is correct. Revised patch as follows,

---
 hw/i386/intel_iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/i386/intel_iommu.c +0 -0
index 37c21a0aec..23562ba26b 100644
@@ -2938,7 +2938,8 @@ static uint64_t vtd_mem_read(void *opaque,

hwaddr addr, unsigned size)

     /* Invalidation Queue Address Register, 64-bit */
     case DMAR_IQA_REG:
-        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & VTD_IQA_QS);
+        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & (VTD_IQA_QS
+                    | VTD_IQA_DW_MASK));
         if (size == 4) {
             val = val & ((1ULL << 32) - 1);
         }
Signature · 1 line
2.34.1
Quoted 35 lines · YeeLi <[email protected]> 于2024年7月4日周四 11:53写道:

From: yeeli <[email protected]>

When dmar_readq or devmem2 read the DW of IQA always 0UL because "& VTD_IQA_QS". So, try to fix it.

case:
after vtd_mem_write
IQA val: 0x100206801

after vtd_mem_read
IQA val: 0x100206001

---
 hw/i386/intel_iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/i386/intel_iommu.c +2 -2
index 37c21a0aec..e230a45940 100644
@@ -2938,7 +2938,8 @@ static uint64_t vtd_mem_read(void *opaque, hwaddr addr, unsigned size)
 
     /* Invalidation Queue Address Register, 64-bit */
     case DMAR_IQA_REG:
-        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & VTD_IQA_QS);
+        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & VTD_IQA_QS
+                | VTD_IQA_DW_MASK);
         if (size == 4) {
             val = val & ((1ULL << 32) - 1);
         }
--

2.34.1

#2 lore raw
Quoted 4 lines · Yee Li

Sorry, the patch missing "(( ))"
Replace "& VTD_IQA_QS" with "& (VTD_IQA_QS | VTD_IQA_DW_MASK))" is correct. Revised patch as follows,

So submit it properly.
Also, how did you test the patch?

Quoted 14 lines
---
 hw/i386/intel_iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/i386/intel_iommu.c +0 -0
index 37c21a0aec..23562ba26b 100644

hw/i386/intel_iommu.c static uint64_t vtd_mem_read(void *opaque, · line 2943

Quoted 7 lines
hw/i386/intel_iommu.c +2 -1
@@ -2938,7 +2938,8 @@ static uint64_t vtd_mem_read(void *opaque,
 hwaddr addr, unsigned size)
 
     /* Invalidation Queue Address Register, 64-bit */
     case DMAR_IQA_REG:
-        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & VTD_IQA_QS);
+        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & (VTD_IQA_QS
+                    | VTD_IQA_DW_MASK));

This is a very messy way to write this.
Align things properly pls.

Quoted 42 lines
hw/i386/intel_iommu.c +0 -0
         if (size == 4) {
             val = val & ((1ULL << 32) - 1);
         }
Signature · 1 line
2.34.1
Quoted 35 lines · YeeLi <[email protected]> 于2024年7月4日周四 11:53写道:

From: yeeli <[email protected]>

When dmar_readq or devmem2 read the DW of IQA always 0UL because "& VTD_IQA_QS". So, try to fix it.

case:
after vtd_mem_write
IQA val: 0x100206801

after vtd_mem_read
IQA val: 0x100206001

---
 hw/i386/intel_iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/i386/intel_iommu.c +2 -2
index 37c21a0aec..e230a45940 100644
@@ -2938,7 +2938,8 @@ static uint64_t vtd_mem_read(void *opaque, hwaddr addr, unsigned size)
 
     /* Invalidation Queue Address Register, 64-bit */
     case DMAR_IQA_REG:
-        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & VTD_IQA_QS);
+        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & VTD_IQA_QS
+                | VTD_IQA_DW_MASK);
         if (size == 4) {
             val = val & ((1ULL << 32) - 1);
         }
--

2.34.1

#3 lore raw
In reply to YeeLi
Quoted 5 lines · YeeLi

From: yeeli <[email protected]>

When dmar_readq or devmem2 read the DW of IQA always 0UL because "& VTD_IQA_QS". So, try to fix it.

Quoted 8 lines

case:
after vtd_mem_write
IQA val: 0x100206801

after vtd_mem_read
IQA val: 0x100206001

how was this tested?

Quoted 20 lines
---
 hw/i386/intel_iommu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/i386/intel_iommu.c +2 -1
index 37c21a0aec..e230a45940 100644
@@ -2938,7 +2938,8 @@ static uint64_t vtd_mem_read(void *opaque, hwaddr addr, unsigned size)
 
     /* Invalidation Queue Address Register, 64-bit */
     case DMAR_IQA_REG:
-        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & VTD_IQA_QS);
+        val = s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & VTD_IQA_QS
+                | VTD_IQA_DW_MASK);
         if (size == 4) {
             val = val & ((1ULL << 32) - 1);
         }
Signature · 1 line
2.34.1
author
#4 lore raw
Quoted 7 lines
Quoted 7 lines

When dmar_readq or devmem2 read the DW of IQA always 0UL because "& VTD_IQA_QS". So, try to fix it.

case:
after vtd_mem_write
IQA val: 0x100206801

Quoted 7 lines
Quoted 4 lines

after vtd_mem_read
IQA val: 0x100206001

how was this tested?

If VT-D hardware supports scalable mode, Linux will set the IQA DW (bit 11). In qemu, the vtd_mem_write and vtd_update_iq_dw set DW well, however, vtd_mem_read the DW wrong because "& VTD_IQA_QS" dropped the value of DW (bit 11).

So testing the patch is easy,

config the "x-scalable-mode" option as below:

"-device intel-iommu,caching-mode=on,x-scalable-mode=on,aw-bits=48"

after Linux OS boot, check the IQA_REG DW (bit 11) as below:

IOMMU_DEBUGFS:

"cat /sys/kernel/debug/iommu/intel |grep IQA"
"IQA 0x90 0x00000001001da801"

or devmem2 read the reg:

"devmem2 0xfed90090"
"/dev/mem opened."
"Memory mapped at address 0x7f983014f000." "Value at address 0xFED90090 (0x7f983014f000): 0x0"

author
#5 lore raw
Quoted 6 lines

or devmem2 read the reg:

"devmem2 0xfed90090"
"/dev/mem opened."
"Memory mapped at address 0x7f983014f000." "Value at address 0xFED90090 (0x7f983014f000): 0x0"

Sorry, correct the devmem2 read value.
"Value at address 0xFED90090 (0x7f983014f000): 0x1DA801"

#6 lore raw
In reply to Yee Li
Quoted 11 lines · Yee Li
Quoted 11 lines
Quoted 11 lines

When dmar_readq or devmem2 read the DW of IQA always 0UL because "& VTD_IQA_QS". So, try to fix it.

case:
after vtd_mem_write
IQA val: 0x100206801

after vtd_mem_read
IQA val: 0x100206001

I think you may need to capitalize the first character of your first and last name.

Quoted 21 lines
Quoted 2 lines

how was this tested?

If VT-D hardware supports scalable mode, Linux will set the IQA DW (bit 11). In qemu, the vtd_mem_write and vtd_update_iq_dw set DW well, however, vtd_mem_read the DW wrong because "& VTD_IQA_QS" dropped the value of DW (bit 11).

So testing the patch is easy,

config the "x-scalable-mode" option as below:

"-device intel-iommu,caching-mode=on,x-scalable-mode=on,aw-bits=48"

after Linux OS boot, check the IQA_REG DW (bit 11) as below:

IOMMU_DEBUGFS:

"cat /sys/kernel/debug/iommu/intel |grep IQA"
"IQA 0x90 0x00000001001da801"

Quoted 7 lines

or devmem2 read the reg:

"devmem2 0xfed90090"
"/dev/mem opened."
"Memory mapped at address 0x7f983014f000." "Value at address 0xFED90090 (0x7f983014f000): 0x0"

So you found it by checking the debugfs output, and it looks to miss the DW bit. is it? Put a clearer commit message would be helpful.

Please address Michael's comment, add a "Fixes: xxx" tag and resend.

Signature · 2 lines
Regards,
Yi Liu
author
#7 lore raw
Quoted 2 lines

So you found it by checking the debugfs output, and it looks to miss the DW bit. is it? Put a clearer commit message would be helpful.

Yes, it is. So, "dropped the value of DW field" is indeed a bug?

Quoted 1 line

Please address Michael's comment, add a "Fixes: xxx" tag and resend.

OK, I will.