]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iommu/amd: Skip enabling command/event buffers for kdump
authorAshish Kalra <ashish.kalra@amd.com>
Mon, 25 Aug 2025 21:46:53 +0000 (21:46 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Nov 2025 20:37:14 +0000 (15:37 -0500)
[ Upstream commit 9be15fbfc6c5c89c22cf6e209f66ea43ee0e58bb ]

After a panic if SNP is enabled in the previous kernel then the kdump
kernel boots with IOMMU SNP enforcement still enabled.

IOMMU command buffers and event buffer registers remain locked and
exclusive to the previous kernel. Attempts to enable command and event
buffers in the kdump kernel will fail, as hardware ignores writes to
the locked MMIO registers as per AMD IOMMU spec Section 2.12.2.1.

Skip enabling command buffers and event buffers for kdump boot as they
are already enabled in the previous kernel.

Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Tested-by: Sairaj Kodilkar <sarunkod@amd.com>
Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
Link: https://lore.kernel.org/r/576445eb4f168b467b0fc789079b650ca7c5b037.1756157913.git.ashish.kalra@amd.com
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/iommu/amd/init.c

index 309951e57f301cbb5c86706b99086daa81bb881f..d0cd40ee0dec69dcdc907748a0e7df6bdce0d637 100644 (file)
@@ -815,11 +815,16 @@ static void iommu_enable_command_buffer(struct amd_iommu *iommu)
 
        BUG_ON(iommu->cmd_buf == NULL);
 
-       entry = iommu_virt_to_phys(iommu->cmd_buf);
-       entry |= MMIO_CMD_SIZE_512;
-
-       memcpy_toio(iommu->mmio_base + MMIO_CMD_BUF_OFFSET,
-                   &entry, sizeof(entry));
+       if (!is_kdump_kernel()) {
+               /*
+                * Command buffer is re-used for kdump kernel and setting
+                * of MMIO register is not required.
+                */
+               entry = iommu_virt_to_phys(iommu->cmd_buf);
+               entry |= MMIO_CMD_SIZE_512;
+               memcpy_toio(iommu->mmio_base + MMIO_CMD_BUF_OFFSET,
+                           &entry, sizeof(entry));
+       }
 
        amd_iommu_reset_cmd_buffer(iommu);
 }
@@ -870,10 +875,15 @@ static void iommu_enable_event_buffer(struct amd_iommu *iommu)
 
        BUG_ON(iommu->evt_buf == NULL);
 
-       entry = iommu_virt_to_phys(iommu->evt_buf) | EVT_LEN_MASK;
-
-       memcpy_toio(iommu->mmio_base + MMIO_EVT_BUF_OFFSET,
-                   &entry, sizeof(entry));
+       if (!is_kdump_kernel()) {
+               /*
+                * Event buffer is re-used for kdump kernel and setting
+                * of MMIO register is not required.
+                */
+               entry = iommu_virt_to_phys(iommu->evt_buf) | EVT_LEN_MASK;
+               memcpy_toio(iommu->mmio_base + MMIO_EVT_BUF_OFFSET,
+                           &entry, sizeof(entry));
+       }
 
        /* set head and tail to zero manually */
        writel(0x00, iommu->mmio_base + MMIO_EVT_HEAD_OFFSET);