Skip to contentSkip to conversation

VT-d minor fixes

PATCH Superseded CLEMENT MATHIEU--DRIF 3 participants 12 messages Jul 5, 2024

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 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.

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 (3):
intel_iommu: fix FRCD construction macro.
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 | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH v3 1/3 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
Reviewed-by on v3 1/3
#2 lore raw

RE: [PATCH v3 1/3] intel_iommu: fix FRCD construction macro.

Quoted 25 lines

-----Original Message-----
From: CLEMENT MATHIEU--DRIF <[email protected]>
Subject: [PATCH v3 1/3] 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 +0 -0
index f8cf99bddf..cbc4030031 100644

hw/i386/intel_iommu_internal.h line 270

Quoted 5 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)

VTD_FRCD_PV and VTD_FRCD_PP are MACROs for high 64-bit. By this chance, maybe we can move them under:

/* For the high 64-bit of 128-bit */

Thanks
Zhenzhong

Quoted 5 lines
hw/i386/intel_iommu_internal.h +0 -1
 #define VTD_FRCD_IR_IDX(val)    (((val) & 0xffffULL) << 48)
 
 /* DMA Remapping Fault Conditions */
--

2.45.2

#3 lore raw

PATCH v3 2/3 intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo

In reply to CLEMENT MATHIEU--DRIF

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

VTDIOTLBPageInvInfo.mask might not fit in an uint8_t. Moreover, this field is used in binary operations with 64-bit addresses.

---
 hw/i386/intel_iommu_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -1
index cbc4030031..5fcbe2744f 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
Reviewed-by on v3 2/3
#4 lore raw

RE: [PATCH v3 2/3] intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo

Quoted 7 lines

-----Original Message-----
From: CLEMENT MATHIEU--DRIF <[email protected]>
Subject: [PATCH v3 2/3] intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo

Quoted 6 lines

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

VTDIOTLBPageInvInfo.mask might not fit in an uint8_t. Moreover, this field is used in binary operations with 64-bit addresses.

Thanks
Zhenzhong

Quoted 20 lines

---
hw/i386/intel_iommu_internal.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -2
index cbc4030031..5fcbe2744f 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;
 
--

2.45.2

#5 lore raw

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

In reply to CLEMENT MATHIEU--DRIF
Quoted 3 lines · CLEMENT MATHIEU--DRIF

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

VTDIOTLBPageInvInfo.mask might not fit in an uint8_t.

I think what you mean is that is assigned values that might not fit .... it's u8 ATM so of course it fits.

Quoted 1 line

Moreover, this field is used in binary operations with 64-bit addresses.

So what?

Quoted 21 lines
---
 hw/i386/intel_iommu_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -1
index cbc4030031..5fcbe2744f 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
#6 lore raw

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

On 05/07/2024 10:51, Michael S. Tsirkin wrote:

Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.

On Fri, Jul 05, 2024 at 05:03:17AM +0000, CLEMENT MATHIEU--DRIF wrote:

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

VTDIOTLBPageInvInfo.mask might not fit in an uint8_t.

I think what you mean is that is assigned values that might not fit .... it's u8 ATM so of course it fits.

What about :
"The mask stored into VTDIOTLBPageInvInfo.mask might not fit in an uint8_t. Use uint64_t to avoid overflows"

Moreover, this field is used in binary operations with 64-bit addresses.

So what?

I thing the first part of the message is enough, the issue comes from the fact that the mask does not fit into the type

---
 hw/i386/intel_iommu_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -1
index cbc4030031..5fcbe2744f 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;
 

--
2.45.2

#7 lore raw

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

Quoted 11 lines · CLEMENT MATHIEU--DRIF

On 05/07/2024 10:51, Michael S. Tsirkin wrote:

Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.

On Fri, Jul 05, 2024 at 05:03:17AM +0000, CLEMENT MATHIEU--DRIF wrote:

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

Quoted 8 lines

VTDIOTLBPageInvInfo.mask might not fit in an uint8_t.

I think what you mean is that is assigned values that might not fit .... it's u8 ATM so of course it fits.

What about :
"The mask stored into VTDIOTLBPageInvInfo.mask might not fit in an uint8_t. Use uint64_t to avoid overflows"

No, the mask stored there is u8.
You mean "that we are trying to store into ".

Quoted 33 lines

Moreover, this field is used in binary operations with 64-bit addresses.

So what?

I thing the first part of the message is enough, the issue comes from the fact that the mask does not fit into the type

        Signed-off-by: Clément Mathieu--Drif <[email protected]>
        ---
         hw/i386/intel_iommu_internal.h | 2 +-
         1 file changed, 1 insertion(+), 1 deletion(-)

        diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h
        index cbc4030031..5fcbe2744f 100644
        --- a/hw/i386/intel_iommu_internal.h
        +++ b/hw/i386/intel_iommu_internal.h
        @@ -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;

        --
        2.45.2
#8 lore raw

PATCH v3 3/3 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.

---
 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
#9 lore raw

RE: [PATCH v3 3/3] intel_iommu: make types match

Quoted 21 lines

-----Original Message-----
From: CLEMENT MATHIEU--DRIF <[email protected]>
Subject: [PATCH v3 3/3] intel_iommu: make types match

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.

---
hw/i386/intel_iommu.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu.c +0 -0
index 37c21a0aec..be0cb39b5c 100644

hw/i386/intel_iommu.c static VTDIOTLBEntry · line 362

Quoted 6 lines
hw/i386/intel_iommu.c +1 -1
@@ -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;

Will it bring any issue if int is used?

Quoted 5 lines
hw/i386/intel_iommu.c +0 -1
    for (level = VTD_SL_PT_LEVEL; level < VTD_SL_PML4_LEVEL; level++) {
        key.gfn = vtd_get_iotlb_gfn(addr, level);
--

2.45.2

#10 lore raw

Re: [PATCH v3 3/3] intel_iommu: make types match

Quoted 17 lines · Zhenzhong

Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.

Quoted 14 lines

-----Original Message-----
From: CLEMENT MATHIEU--DRIF <[email protected]>
Subject: [PATCH v3 3/3] intel_iommu: make types match

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.

---
hw/i386/intel_iommu.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

hw/i386/intel_iommu.c static VTDIOTLBEntry · line 362

Quoted 11 lines
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;

Will it bring any issue if int is used?

It shouldn't, but it might trigger static analyzer warnings. Do you want me to drop the patch?

Quoted 5 lines
Quoted 5 lines
hw/i386/intel_iommu.c +0 -1
     for (level = VTD_SL_PT_LEVEL; level < VTD_SL_PML4_LEVEL; level++) {
         key.gfn = vtd_get_iotlb_gfn(addr, level);
--

2.45.2

#11 lore raw

Re: [PATCH v3 3/3] intel_iommu: make types match

Quoted 32 lines · CLEMENT MATHIEU--DRIF
Quoted 17 lines · Zhenzhong

Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.

Quoted 14 lines

-----Original Message-----
From: CLEMENT MATHIEU--DRIF <[email protected]>
Subject: [PATCH v3 3/3] intel_iommu: make types match

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.

---
hw/i386/intel_iommu.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

hw/i386/intel_iommu.c static VTDIOTLBEntry · line 362

Quoted 11 lines
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;

Will it bring any issue if int is used?

Quoted 2 lines

It shouldn't, but it might trigger static analyzer warnings. Do you want me to drop the patch?

just write a better commit log.
"Not an issue by itself, but using unsigned here seems cleaner".

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hw/i386/intel_iommu.c +0 -1
     for (level = VTD_SL_PT_LEVEL; level < VTD_SL_PML4_LEVEL; level++) {
         key.gfn = vtd_get_iotlb_gfn(addr, level);
--

2.45.2