iommu/vt-d: Serialize IOMMU GCMD register modifications
Subsystems (2)
Lu Baolu
maintainerPATCH v3 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. It also checks the status register before writing command register to avoid unnecessary register write.
--- drivers/iommu/intel/irq_remapping.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
Change log:v1->v2:
- v1 posted here
https://lore.kernel.org/linux-iommu/[email protected]/ - Add status check before disabling CFI (Kevin) v2->v3: - v2 posted here https://lore.kernel.org/linux-iommu/[email protected]/
- Remove unnecessary register read (Kevin)
drivers/iommu/intel/irq_remapping.c +8 -2
@@ -507,12 +507,18 @@ 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 */ +if (sts &DMA_GSTS_CFIS ) { + 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 · 1 line
2.17.1
Quoted 67 lines
From: Lu Baolu <[email protected]>
Sent: Friday, August 28, 2020 8:06 AMThe VT-d spec requires (10.4.4 Global Command Register,
GCMD_REGGeneral
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. It also checks the status register before writing command register to avoid unnecessary register write.Fixes af8d102f999a4 ("x86/intel/irq_remapping: Clean up x2apic opt-outsecurity warning mess")
Cc Andy Lutomirski <[email protected]>Cc Jacob Pan <[email protected]>Cc Kevin Tian <[email protected]>Cc Ashok Raj <[email protected]>Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/intel/irq_remapping.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)Change log:
v1->v2:
- v1 posted herehttps://lore.kernel.org/linux-iommu/20200826025825.2322-1-[email protected]/
- Add status check before disabling CFI (Kevin)v2->v3:
- v2 posted herehttps://lore.kernel.org/linux-iommu/20200827042513.30292-1-[email protected]/
- Remove unnecessary register read (Kevin)drivers/iommu/intel/irq_remapping.c +0
-1@@ -507,12 +507,18 @@ 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 +8
-2writel (iommu->gcmd, iommu->reg +DMAR_GCMD_REG ); -IOMMU_WAIT_OP (iommu,DMAR_GSTS_REG , readl, (sts &DMA_GSTS_IRES ), sts); +/* Block compatibility-format MSIs */ +if (sts &DMA_GSTS_CFIS ) { + 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 --
Quoted 1 line
2.17.1
Joerg Roedel
maintainerQuoted 17 lines · Lu Baolu
The VT-d spec requires (10.4.4 Global Command Register,
GCMD_REGGeneral 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. It also checks the status register before writing command register to avoid unnecessary register write.Fixes af8d102f999a4 ("x86/intel/irq_remapping: Clean up x2apic opt-out security warning mess")Cc Andy Lutomirski <[email protected]>Cc Jacob Pan <[email protected]>Cc Kevin Tian <[email protected]>Cc Ashok Raj <[email protected]>Signed-off-by Lu Baolu <[email protected]>
Quoted 3 lines
--- drivers/iommu/intel/irq_remapping.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
Applied for v5.9, thanks.