Skip to contentSkip to conversation

iommu/amd: Explicitly disable GAPPI

PATCH In review Naveen N Rao (AMD) 2 participants 2 messages Dec 2 – Dec 4

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/amd: Explicitly disable GAPPI

Since commit b03500f03ea0 ("KVM: SVM: Generate GA log IRQs only if the associated vCPUs is blocking"), running a VM with AVIC enabled and a passed-through (VFIO) device can result in unexpected host interrupts with kernel log messages such as:
No irq handler for 99.39

Or worse, the host hangs, or panics with:

  Kernel panic - not syncing: Unexpected external interrupt 0x80

AMD IOMMU supports GAPPI mode (Guest APIC Physical Processor Interrupt) wherein device interrupts for vCPUs that are not running can result in host interrupts. More specifically, if IRTE[IsRun]=0 and IRTE[GALogIntr]=0, and if GAPPI mode is enabled, IOMMU sends a host interrupt to IRTE[destination] with vector number derived from the low byte of IRTE[GATag] (which KVM populates with the vCPU index).

Prior to the above commit, KVM never cleared IRTE[GALogIntr] and so device interrupts for non-running vCPUs always resulted in a GALog entry, with an optional GALog interrupt to the host. Since the above commit, KVM clears IRTE[GALogIntr] if the vCPU is scheduled out without blocking, which can trigger GAPPI interrupts if GAPPI mode is enabled.

GAPPI mode is controlled by GAPPIEn in the IOMMU Control register with a reset value of 0 and Linux never sets it. So, GAPPI mode is not enabled by default. However, enabling SEV-SNP in the BIOS sets GAPPIEn to 1 resulting in GAPPI mode being enabled on boot.

Fix this by disabling GAPPI mode in iommu_disable(). Disabling GAPPI mode in kdump path is left for the series that enables GAPPI, since GAPPI is never otherwise left enabled by Linux kernel today.

Fixes b03500f03ea0 ("KVM: SVM: Generate GA log IRQs only if the associated vCPUs is blocking")
---
 drivers/iommu/amd/amd_iommu_types.h | 1 +
 drivers/iommu/amd/init.c            | 3 +++
 2 files changed, 4 insertions(+)
drivers/iommu/amd/amd_iommu_types.h +1 -0
index f98770db0090..31bdcb6b3bbf 100644
@@ -180,6 +180,7 @@
 #define CONTROL_EPH_EN		45
 #define CONTROL_XT_EN		50
 #define CONTROL_INTCAPXT_EN	51
+#define CONTROL_GAPPI_EN	55
 #define CONTROL_GCR3TRPMODE	58
 #define CONTROL_IRTCACHEDIS	59
 #define CONTROL_SNPAVIC_EN	61
drivers/iommu/amd/init.c +3 -0
index 58f63298493b..a31ad62b472b 100644
@@ -481,6 +481,9 @@ static void iommu_disable(struct amd_iommu *iommu)
 	iommu_feature_disable(iommu, CONTROL_GALOG_EN);
 	iommu_feature_disable(iommu, CONTROL_GAINT_EN);
 
+	/* Disable IOMMU GAPPI */
+	iommu_feature_disable(iommu, CONTROL_GAPPI_EN);
+
 	/* Disable IOMMU PPR logging */
 	iommu_feature_disable(iommu, CONTROL_PPRLOG_EN);
 	iommu_feature_disable(iommu, CONTROL_PPRINT_EN);

base-commit: 10bcc637f7a657725dd8bbcc2b30d027acee6f2d

Signature · 1 line
2.56.0
maintainer
#1 lore raw
Quoted 22 lines · Naveen N Rao (AMD)

Since commit b03500f03ea0 ("KVM: SVM: Generate GA log IRQs only if the associated vCPUs is blocking"), running a VM with AVIC enabled and a passed-through (VFIO) device can result in unexpected host interrupts with kernel log messages such as:
No irq handler for 99.39

Or worse, the host hangs, or panics with:

  Kernel panic - not syncing: Unexpected external interrupt 0x80

AMD IOMMU supports GAPPI mode (Guest APIC Physical Processor Interrupt) wherein device interrupts for vCPUs that are not running can result in host interrupts. More specifically, if IRTE[IsRun]=0 and IRTE[GALogIntr]=0, and if GAPPI mode is enabled, IOMMU sends a host interrupt to IRTE[destination] with vector number derived from the low byte of IRTE[GATag] (which KVM populates with the vCPU index).

Prior to the above commit, KVM never cleared IRTE[GALogIntr] and so device interrupts for non-running vCPUs always resulted in a GALog entry, with an optional GALog interrupt to the host. Since the above commit, KVM clears IRTE[GALogIntr] if the vCPU is scheduled out without blocking, which can trigger GAPPI interrupts if GAPPI mode is enabled.

Quoted 8 lines

GAPPI mode is controlled by GAPPIEn in the IOMMU Control register with a reset value of 0 and Linux never sets it. So, GAPPI mode is not enabled by default. However, enabling SEV-SNP in the BIOS sets GAPPIEn to 1 resulting in GAPPI mode being enabled on boot.

Fix this by disabling GAPPI mode in iommu_disable(). Disabling GAPPI mode in kdump path is left for the series that enables GAPPI, since GAPPI is never otherwise left enabled by Linux kernel today.

I believe right way is to clear the control register during boot and enable the individual features. That way OS knows/controls what it enabled. But this needs larger rework and more testing.

Hence for now I have applied this fix. Thanks!

-Vasant