Skip to contentSkip to conversation

iommu/vt-d: Serialize IOMMU GCMD register modifications

PATCH Superseded Lu Baolu 2 participants 3 messages Aug 26, 2020 – Aug 27, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Lu Baolu

author maintainer
#0 lore raw

PATCH 1/1 iommu/vt-d: Serialize IOMMU GCMD register modifications

The VT-d spec requires (10.4.4 Global Command Register, GCMD_REG General Description) that:

If multiple control fields in this register need to be modified, software must serialize the modifications through multiple writes to this register.

However, in irq_remapping.c, modifications of IRE and CFI are done in one write. We need to do two separate writes with STS checking after each.

Fixes af8d102f999a4 ("x86/intel/irq_remapping: Clean up x2apic opt-out security warning mess")
Cc Andy Lutomirski <[email protected]>
Cc Jacob Pan <[email protected]>
---
 drivers/iommu/intel/irq_remapping.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iommu/intel/irq_remapping.c +6 -2
index 9564d23d094f..19d7e18876fe 100644
@@ -507,12 +507,16 @@ static void iommu_enable_irq_remapping(struct intel_iommu *iommu)
 
 	/* Enable interrupt-remapping */
 	iommu->gcmd |= DMA_GCMD_IRE;
-	iommu->gcmd &= ~DMA_GCMD_CFI;  /* Block compatibility-format MSIs */
 	writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
-
 	IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
 		      readl, (sts & DMA_GSTS_IRES), sts);
 
+	/* Block compatibility-format MSIs */
+	iommu->gcmd &= ~DMA_GCMD_CFI;
+	writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
+	IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
+		      readl, !(sts & DMA_GSTS_CFIS), sts);
+
 	/*
 	 * With CFI clear in the Global Command register, we should be
 	 * protected from dangerous (i.e. compatibility) interrupts
Signature · 6 lines
2.17.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
#1 lore raw
Quoted 35 lines

From: Lu Baolu
Sent: Wednesday, August 26, 2020 10:58 AM

The VT-d spec requires (10.4.4 Global Command Register, GCMD_REG General
Description) that:

If multiple control fields in this register need to be modified, software must serialize the modifications through multiple writes to this register.

However, in irq_remapping.c, modifications of IRE and CFI are done in one write. We need to do two separate writes with STS checking after each.

Fixes af8d102f999a4 ("x86/intel/irq_remapping: Clean up x2apic opt-out

security warning mess")

Cc Andy Lutomirski <[email protected]>
Cc Jacob Pan <[email protected]>
---
 drivers/iommu/intel/irq_remapping.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iommu/intel/irq_remapping.c +0 -1
index 9564d23d094f..19d7e18876fe 100644
@@ -507,12 +507,16 @@ static void iommu_enable_irq_remapping(struct
 intel_iommu *iommu)
 
 	/* Enable interrupt-remapping */
 	iommu->gcmd |= DMA_GCMD_IRE;
-	iommu->gcmd &= ~DMA_GCMD_CFI;  /* Block compatibility-format

MSIs */

drivers/iommu/intel/irq_remapping.c +0 -0
 	writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);

drivers/iommu/intel/irq_remapping.c static void iommu_enable_irq_remapping(struct intel_iommu *iommu) · line 519

Quoted 10 lines
drivers/iommu/intel/irq_remapping.c +6 -1
-
 	IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
 		      readl, (sts & DMA_GSTS_IRES), sts);
 
+	/* Block compatibility-format MSIs */
+	iommu->gcmd &= ~DMA_GCMD_CFI;
+	writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
+	IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
+		      readl, !(sts & DMA_GSTS_CFIS), sts);
+

Better do it only when CFI is actually enabled (by checking sts).

Quoted 10 lines
drivers/iommu/intel/irq_remapping.c +0 -1
 	/*
 	 * With CFI clear in the Global Command register, we should be
 	 * protected from dangerous (i.e. compatibility) interrupts
--

2.17.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

author maintainer
#2 lore raw

Hi Kevin,

Quoted 39 lines · Kevin
Quoted 39 lines

From: Lu Baolu
Sent: Wednesday, August 26, 2020 10:58 AM

The VT-d spec requires (10.4.4 Global Command Register, GCMD_REG General
Description) that:

If multiple control fields in this register need to be modified, software must serialize the modifications through multiple writes to this register.

However, in irq_remapping.c, modifications of IRE and CFI are done in one write. We need to do two separate writes with STS checking after each.

Fixes af8d102f999a4 ("x86/intel/irq_remapping: Clean up x2apic opt-out

security warning mess")

Cc Andy Lutomirski <[email protected]>
Cc Jacob Pan <[email protected]>
---
  drivers/iommu/intel/irq_remapping.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iommu/intel/irq_remapping.c +0 -1
index 9564d23d094f..19d7e18876fe 100644
@@ -507,12 +507,16 @@ static void iommu_enable_irq_remapping(struct
 intel_iommu *iommu)
 
  	/* Enable interrupt-remapping */
  	iommu->gcmd |= DMA_GCMD_IRE;
-	iommu->gcmd &= ~DMA_GCMD_CFI;  /* Block compatibility-format

MSIs */
writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
-
IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
readl, (sts & DMA_GSTS_IRES), sts);

Quoted 8 lines

drivers/iommu/intel/irq_remapping.c static void iommu_enable_irq_remapping(struct intel_iommu *iommu) · line 519

Quoted 6 lines
drivers/iommu/intel/irq_remapping.c +6 -0
+	/* Block compatibility-format MSIs */
+	iommu->gcmd &= ~DMA_GCMD_CFI;
+	writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
+	IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
+		      readl, !(sts & DMA_GSTS_CFIS), sts);
+

Better do it only when CFI is actually enabled (by checking sts).

Yes. Make sense. Will send a new version with this changed.

Best regards,
baolu

Quoted 11 lines
Quoted 11 lines

/*
* With CFI clear in the Global Command register, we should be
* protected from dangerous (i.e. compatibility) interrupts
--
2.17.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu