Skip to contentSkip to conversation

VT-d minor fixes

PATCH Superseded CLEMENT MATHIEU--DRIF 4 participants 16 messages Jul 5, 2024 – Jul 20, 2024

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover VT-d minor fixes

From: Clément Mathieu--Drif <[email protected]>

Various fixes for VT-d

This series contains fixes that will be necessary when adding in-guest (fully emulated) SVM support.

v4
- Move declarations of VTD_FRCD_PV and VTD_FRCD_PP
- intel_iommu: make types match:
- edit commit message to explain that we are not fixing a bug
- intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo
- edit commit message

v3
FRCD construction macro :
- Longer sha1 for the 'Fixes' tag
- Add '.' at the end of the sentence

Make types match :
- Split into 2 patches (one for the fix and one for type matching)

Remove patch for wait descriptor handling (will be in the PRI series)

v2
Make commit author consistent

Clément Mathieu--Drif (4):
intel_iommu: fix FRCD construction macro
intel_iommu: move VTD_FRCD_PV and VTD_FRCD_PP declarations
intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo
intel_iommu: make types match

 hw/i386/intel_iommu.c          | 2 +-
 hw/i386/intel_iommu_internal.h | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH v4 1/4 intel_iommu: fix FRCD construction macro

From: Clément Mathieu--Drif <[email protected]>

The constant must be unsigned, otherwise the two's complement overrides the other fields when a PASID is present.

Fixes 1b2b12376c8a ("intel-iommu: PASID support")
---
 hw/i386/intel_iommu_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -1
index f8cf99bddf..cbc4030031 100644
@@ -267,7 +267,7 @@
 /* For the low 64-bit of 128-bit */
 #define VTD_FRCD_FI(val)        ((val) & ~0xfffULL)
 #define VTD_FRCD_PV(val)        (((val) & 0xffffULL) << 40)
-#define VTD_FRCD_PP(val)        (((val) & 0x1) << 31)
+#define VTD_FRCD_PP(val)        (((val) & 0x1ULL) << 31)
 #define VTD_FRCD_IR_IDX(val)    (((val) & 0xffffULL) << 48)
 
 /* DMA Remapping Fault Conditions */
Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH v4 1/4] intel_iommu: fix FRCD construction macro

Quoted 7 lines · CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

The constant must be unsigned, otherwise the two's complement overrides the other fields when a PASID is present.

Fixes 1b2b12376c8a ("intel-iommu: PASID support")

The extra line behind the "Fixes tag" is not needed.

Quoted 12 lines
---
  hw/i386/intel_iommu_internal.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +0 -0
index f8cf99bddf..cbc4030031 100644

hw/i386/intel_iommu_internal.h line 273

Quoted 8 lines
hw/i386/intel_iommu_internal.h +1 -1
@@ -267,7 +267,7 @@
  /* For the low 64-bit of 128-bit */
  #define VTD_FRCD_FI(val)        ((val) & ~0xfffULL)
  #define VTD_FRCD_PV(val)        (((val) & 0xffffULL) << 40)
-#define VTD_FRCD_PP(val)        (((val) & 0x1) << 31)
+#define VTD_FRCD_PP(val)        (((val) & 0x1ULL) << 31)
  #define VTD_FRCD_IR_IDX(val)    (((val) & 0xffffULL) << 48)
 
  /* DMA Remapping Fault Conditions */

It might be fine to squash patch 02 of this series into this one. @Jason?

Signature · 2 lines
Regards,
Yi Liu
#3 lore raw

Re: [PATCH v4 1/4] intel_iommu: fix FRCD construction macro

Quoted 31 lines · Yi Liu
Quoted 7 lines · CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

The constant must be unsigned, otherwise the two's complement overrides the other fields when a PASID is present.

Fixes 1b2b12376c8a ("intel-iommu: PASID support")

The extra line behind the "Fixes tag" is not needed.

Quoted 19 lines
---
  hw/i386/intel_iommu_internal.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -1
index f8cf99bddf..cbc4030031 100644
@@ -267,7 +267,7 @@
  /* For the low 64-bit of 128-bit */
  #define VTD_FRCD_FI(val)        ((val) & ~0xfffULL)
  #define VTD_FRCD_PV(val)        (((val) & 0xffffULL) << 40)
-#define VTD_FRCD_PP(val)        (((val) & 0x1) << 31)
+#define VTD_FRCD_PP(val)        (((val) & 0x1ULL) << 31)
  #define VTD_FRCD_IR_IDX(val)    (((val) & 0xffffULL) << 48)
 
Quoted 3 lines

hw/i386/intel_iommu_internal.h line 273

Quoted 1 line
hw/i386/intel_iommu_internal.h +0 -0
  /* DMA Remapping Fault Conditions */

It might be fine to squash patch 02 of this series into this one. @Jason?

Not sure, we may need this for -stable. So having a standalone patch doesn't hurt.

Thanks

Quoted 5 lines

--
Regards,
Yi Liu

#4 lore raw

Re: [PATCH v4 1/4] intel_iommu: fix FRCD construction macro

Quoted 32 lines · Jason Wang
Quoted 31 lines · Yi Liu
Quoted 7 lines · CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

The constant must be unsigned, otherwise the two's complement overrides the other fields when a PASID is present.

Fixes 1b2b12376c8a ("intel-iommu: PASID support")

The extra line behind the "Fixes tag" is not needed.

Quoted 19 lines
---
   hw/i386/intel_iommu_internal.h | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -1
index f8cf99bddf..cbc4030031 100644
@@ -267,7 +267,7 @@
   /* For the low 64-bit of 128-bit */
   #define VTD_FRCD_FI(val)        ((val) & ~0xfffULL)
   #define VTD_FRCD_PV(val)        (((val) & 0xffffULL) << 40)
-#define VTD_FRCD_PP(val)        (((val) & 0x1) << 31)
+#define VTD_FRCD_PP(val)        (((val) & 0x1ULL) << 31)
   #define VTD_FRCD_IR_IDX(val)    (((val) & 0xffffULL) << 48)
 
Quoted 6 lines
Quoted 3 lines

hw/i386/intel_iommu_internal.h line 273

Quoted 1 line
hw/i386/intel_iommu_internal.h +0 -0
   /* DMA Remapping Fault Conditions */

It might be fine to squash patch 02 of this series into this one. @Jason?

Not sure, we may need this for -stable. So having a standalone patch doesn't hurt.

I see. :)

Signature · 2 lines
Regards,
Yi Liu
#5 lore raw

PATCH v4 2/4 intel_iommu: move VTD_FRCD_PV and VTD_FRCD_PP declarations

In reply to CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

These 2 macros are for high 64-bit of the FRCD registers. Declarations have to be moved accordingly.

---
 hw/i386/intel_iommu_internal.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/i386/intel_iommu_internal.h +2 -2
index cbc4030031..faea23e8d6 100644
@@ -264,10 +264,10 @@
 #define VTD_FRCD_FR(val)        (((val) & 0xffULL) << 32)
 #define VTD_FRCD_SID_MASK       0xffffULL
 #define VTD_FRCD_SID(val)       ((val) & VTD_FRCD_SID_MASK)
-/* For the low 64-bit of 128-bit */
-#define VTD_FRCD_FI(val)        ((val) & ~0xfffULL)
 #define VTD_FRCD_PV(val)        (((val) & 0xffffULL) << 40)
 #define VTD_FRCD_PP(val)        (((val) & 0x1ULL) << 31)
+/* For the low 64-bit of 128-bit */
+#define VTD_FRCD_FI(val)        ((val) & ~0xfffULL)
 #define VTD_FRCD_IR_IDX(val)    (((val) & 0xffffULL) << 48)
 
 /* DMA Remapping Fault Conditions */
Signature · 1 line
2.45.2
#6 lore raw

PATCH v4 3/4 intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo

In reply to CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

The mask we are trying to store into VTDIOTLBPageInvInfo.mask might not fit in an uint8_t. Use uint64_t to avoid overflows

---
 hw/i386/intel_iommu_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -1
index faea23e8d6..5f32c36943 100644
@@ -436,7 +436,7 @@ struct VTDIOTLBPageInvInfo {
     uint16_t domain_id;
     uint32_t pasid;
     uint64_t addr;
-    uint8_t mask;
+    uint64_t mask;
 };
 typedef struct VTDIOTLBPageInvInfo VTDIOTLBPageInvInfo;
 
Signature · 1 line
2.45.2
#7 lore raw

Re: [PATCH v4 3/4] intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo

Quoted 4 lines · CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

The mask we are trying to store into VTDIOTLBPageInvInfo.mask might not fit in an uint8_t. Use uint64_t to avoid overflows

Per the below code, it can overflow as am can be larger than 8 according to the CH 6.5.2.3 IOTLB Invalidate. And you may want a fix tag as well.

info.mask = ~((1 << am) - 1);

CH 6.5.2.3 IOTLB Invalidate

Address Mask (AM): For page-selective-within-domain invalidations, the Address Mask specifies the number of low order bits of the ADDR field that must be masked for the invalidation operation. This field enables software to request invalidation of contiguous mappings for size-aligned regions. Refer to Table 19 for encodings of this field. When invalidating a large-page translation, software must use the appropriate Address Mask value (0 for 4KByte page, 9 for 2-MByte page, and 18 for 1-GByte page). Hardware implementations report the maximum supported address mask value through the Capability register

Quoted 18 lines
---
  hw/i386/intel_iommu_internal.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -1
index faea23e8d6..5f32c36943 100644
@@ -436,7 +436,7 @@ struct VTDIOTLBPageInvInfo {
      uint16_t domain_id;
      uint32_t pasid;
      uint64_t addr;
-    uint8_t mask;
+    uint64_t mask;
  };
  typedef struct VTDIOTLBPageInvInfo VTDIOTLBPageInvInfo;
 
Signature · 2 lines
Regards,
Yi Liu
#8 lore raw

Re: [PATCH v4 3/4] intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo

Quoted 8 lines · Yi Liu
Quoted 4 lines · CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

The mask we are trying to store into VTDIOTLBPageInvInfo.mask might not fit in an uint8_t. Use uint64_t to avoid overflows

Per the below code, it can overflow as am can be larger than 8 according to the CH 6.5.2.3 IOTLB Invalidate.

I don't understand what you are saying. What can overflow? Are you suggesting text for commit log here?

Quoted 1 line

And you may want a fix tag as well.

why not.

Quoted 39 lines

info.mask = ~((1 << am) - 1);

CH 6.5.2.3 IOTLB Invalidate

Address Mask (AM): For page-selective-within-domain invalidations, the Address Mask specifies
the number of low order bits of the ADDR field that must be masked for the invalidation operation.
This field enables software to request invalidation of contiguous mappings for size-aligned
regions. Refer to Table 19 for encodings of this field. When invalidating a large-page translation,
software must use the appropriate Address Mask value (0 for 4KByte page, 9 for 2-MByte page,
and 18 for 1-GByte page). Hardware implementations report the maximum supported address
mask value through the Capability register

Quoted 17 lines
---
  hw/i386/intel_iommu_internal.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -1
index faea23e8d6..5f32c36943 100644
@@ -436,7 +436,7 @@ struct VTDIOTLBPageInvInfo {
      uint16_t domain_id;
      uint32_t pasid;
      uint64_t addr;
-    uint8_t mask;
+    uint64_t mask;
  };
  typedef struct VTDIOTLBPageInvInfo VTDIOTLBPageInvInfo;
Signature · 2 lines
Regards,
Yi Liu
#9 lore raw

Re: [PATCH v4 3/4] intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo

Quoted 10 lines · Michael S. Tsirkin
Quoted 8 lines · Yi Liu
Quoted 4 lines · CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

The mask we are trying to store into VTDIOTLBPageInvInfo.mask might not fit in an uint8_t. Use uint64_t to avoid overflows

Per the below code, it can overflow as am can be larger than 8 according to the CH 6.5.2.3 IOTLB Invalidate.

Quoted 6 lines

I don't understand what you are saying. What can overflow? Are you suggesting text for commit log here?

Quoted 1 line

And you may want a fix tag as well.

why not.

ignore pls this is on old version.

Quoted 39 lines
Quoted 39 lines

info.mask = ~((1 << am) - 1);

CH 6.5.2.3 IOTLB Invalidate

Address Mask (AM): For page-selective-within-domain invalidations, the Address Mask specifies
the number of low order bits of the ADDR field that must be masked for the invalidation operation.
This field enables software to request invalidation of contiguous mappings for size-aligned
regions. Refer to Table 19 for encodings of this field. When invalidating a large-page translation,
software must use the appropriate Address Mask value (0 for 4KByte page, 9 for 2-MByte page,
and 18 for 1-GByte page). Hardware implementations report the maximum supported address
mask value through the Capability register

Quoted 17 lines
---
  hw/i386/intel_iommu_internal.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -1
index faea23e8d6..5f32c36943 100644
@@ -436,7 +436,7 @@ struct VTDIOTLBPageInvInfo {
      uint16_t domain_id;
      uint32_t pasid;
      uint64_t addr;
-    uint8_t mask;
+    uint64_t mask;
  };
  typedef struct VTDIOTLBPageInvInfo VTDIOTLBPageInvInfo;
Signature · 2 lines
Regards,
Yi Liu
#10 lore raw

PATCH v4 4/4 intel_iommu: make types match

In reply to CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

The 'level' field in vtd_iotlb_key is an unsigned integer. We don't need to store level as an int in vtd_lookup_iotlb.

This is not an issue by itself, but using unsigned here seems cleaner.

---
 hw/i386/intel_iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu.c +1 -1
index 37c21a0aec..be0cb39b5c 100644
@@ -358,7 +358,7 @@ static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id,
 {
     struct vtd_iotlb_key key;
     VTDIOTLBEntry *entry;
-    int level;
+    unsigned level;
 
     for (level = VTD_SL_PT_LEVEL; level < VTD_SL_PML4_LEVEL; level++) {
         key.gfn = vtd_get_iotlb_gfn(addr, level);
Signature · 1 line
2.45.2
#11 lore raw

Re: [PATCH v4 4/4] intel_iommu: make types match

Quoted 6 lines · CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

The 'level' field in vtd_iotlb_key is an unsigned integer. We don't need to store level as an int in vtd_lookup_iotlb.

This is not an issue by itself, but using unsigned here seems cleaner.

a nit to the subject. s/"make types match"/"make type match"/

Quoted 18 lines
---
  hw/i386/intel_iommu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu.c +1 -1
index 37c21a0aec..be0cb39b5c 100644
@@ -358,7 +358,7 @@ static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id,
  {
      struct vtd_iotlb_key key;
      VTDIOTLBEntry *entry;
-    int level;
+    unsigned level;
 
      for (level = VTD_SL_PT_LEVEL; level < VTD_SL_PML4_LEVEL; level++) {
          key.gfn = vtd_get_iotlb_gfn(addr, level);
Signature · 2 lines
Regards,
Yi Liu
#12 lore raw

Re: [PATCH v4 4/4] intel_iommu: make types match

Quoted 9 lines · Yi Liu
Quoted 6 lines · CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

The 'level' field in vtd_iotlb_key is an unsigned integer. We don't need to store level as an int in vtd_lookup_iotlb.

This is not an issue by itself, but using unsigned here seems cleaner.

a nit to the subject. s/"make types match"/"make type match"/

Hmm not sure I agree.
There are two variables, they have types. We make them match.

Quoted 21 lines
Quoted 17 lines
---
  hw/i386/intel_iommu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu.c +1 -1
index 37c21a0aec..be0cb39b5c 100644
@@ -358,7 +358,7 @@ static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id,
  {
      struct vtd_iotlb_key key;
      VTDIOTLBEntry *entry;
-    int level;
+    unsigned level;
      for (level = VTD_SL_PT_LEVEL; level < VTD_SL_PML4_LEVEL; level++) {
          key.gfn = vtd_get_iotlb_gfn(addr, level);
Signature · 2 lines
Regards,
Yi Liu
#13 lore raw

Re: [PATCH v4 4/4] intel_iommu: make types match

Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Yi Liu
Quoted 5 lines · CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

The 'level' field in vtd_iotlb_key is an unsigned integer. We don't need to store level as an int in vtd_lookup_iotlb.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

This is not an issue by itself, but using unsigned here seems cleaner.

a nit to the subject. s/"make types match"/"make type match"/

Hmm not sure I agree.
There are two variables, they have types. We make them match.

ignore pls this is on old version

Quoted 22 lines
Quoted 22 lines
Quoted 18 lines
---
  hw/i386/intel_iommu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu.c +1 -1
index 37c21a0aec..be0cb39b5c 100644
@@ -358,7 +358,7 @@ static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id,
  {
      struct vtd_iotlb_key key;
      VTDIOTLBEntry *entry;
-    int level;
+    unsigned level;
      for (level = VTD_SL_PT_LEVEL; level < VTD_SL_PML4_LEVEL; level++) {
          key.gfn = vtd_get_iotlb_gfn(addr, level);
Signature · 2 lines
Regards,
Yi Liu
#14 lore raw
In reply to CLEMENT MATHIEU--DRIF
Quoted 6 lines · CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

Various fixes for VT-d

This series contains fixes that will be necessary when adding in-guest (fully emulated) SVM support.

Clément are you going to address Yi Liu's comments?

Quoted 34 lines

v4
- Move declarations of VTD_FRCD_PV and VTD_FRCD_PP
- intel_iommu: make types match:
- edit commit message to explain that we are not fixing a bug
- intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo
- edit commit message

v3
FRCD construction macro :
- Longer sha1 for the 'Fixes' tag
- Add '.' at the end of the sentence

Make types match :
- Split into 2 patches (one for the fix and one for type matching)

Remove patch for wait descriptor handling (will be in the PRI series)

v2
Make commit author consistent

Clément Mathieu--Drif (4):
intel_iommu: fix FRCD construction macro
intel_iommu: move VTD_FRCD_PV and VTD_FRCD_PP declarations
intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo
intel_iommu: make types match

 hw/i386/intel_iommu.c          | 2 +-
 hw/i386/intel_iommu_internal.h | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.45.2
#15 lore raw
Quoted 9 lines · Michael S. Tsirkin
Quoted 6 lines · CLEMENT MATHIEU--DRIF

From: Clément Mathieu--Drif <[email protected]>

Various fixes for VT-d

This series contains fixes that will be necessary when adding in-guest (fully emulated) SVM support.

Clément are you going to address Yi Liu's comments?

sorry this is old version, pls ignore

Quoted 34 lines
Quoted 34 lines

v4
- Move declarations of VTD_FRCD_PV and VTD_FRCD_PP
- intel_iommu: make types match:
- edit commit message to explain that we are not fixing a bug
- intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo
- edit commit message

v3
FRCD construction macro :
- Longer sha1 for the 'Fixes' tag
- Add '.' at the end of the sentence

Make types match :
- Split into 2 patches (one for the fix and one for type matching)

Remove patch for wait descriptor handling (will be in the PRI series)

v2
Make commit author consistent

Clément Mathieu--Drif (4):
intel_iommu: fix FRCD construction macro
intel_iommu: move VTD_FRCD_PV and VTD_FRCD_PP declarations
intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo
intel_iommu: make types match

 hw/i386/intel_iommu.c          | 2 +-
 hw/i386/intel_iommu_internal.h | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.45.2