Skip to contentSkip to conversation

iommu/amd: Continue the completion sequence in SNP kdump

PATCH New Vasant Hegde 1 participant 1 message Nov 5

Subsystems (2)
lore
Share & tools
lore

Vasant Hegde

author maintainer
#0 lore raw

PATCH 1/1 iommu/amd: Continue the completion sequence in SNP kdump

SNP kdump remaps the previous kernel's completion-wait semaphore because the completion-store registers are locked. That page already holds the last sequence number the IOMMU stored, but cmd_sem_val starts at zero.

wait_on_sem() returns once the stored value is at least the target. Until the new counter catches up, every completion wait succeeds before the IOMMU has executed the command. That includes the cache flushes issued while the kdump kernel adopts the old device table.

When the old device table is reused, sample the semaphore after the command buffer is disabled. A completion wait fetched before that can still store a later sequence number. The old command buffer holds at most 512 commands, so continue that far past the sampled value.

Fixes d2a0cac10597 ("iommu/amd: move wait_on_sem() out of spinlock")
Cc Ankit Soni <[email protected]>
Assisted-by Cursor
---
 drivers/iommu/amd/init.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/iommu/amd/init.c +14 -0
index de6db5621194..28a4067a7a05 100644
@@ -2992,6 +2992,20 @@ static void early_enable_iommus(void)
 
 		for_each_iommu(iommu) {
 			iommu_disable_command_buffer(iommu);
+
+			/*
+			 * SNP reuses the previous kernel's completion
+			 * semaphore. wait_on_sem() returns once the stored
+			 * value is at least the target. A completion wait
+			 * fetched before CmdBufEn was cleared can still
+			 * store a later value, and the old command buffer
+			 * holds at most CMD_BUFFER_ENTRIES such commands.
+			 * Continue past that range. A new page reads as
+			 * zero, so this only skips those entries.
+			 */
+			iommu->cmd_sem_val = READ_ONCE(*iommu->cmd_sem) +
+					     CMD_BUFFER_ENTRIES;
+
 			iommu_disable_event_buffer(iommu);
 			iommu_disable_irtcachedis(iommu);
 			iommu_enable_command_buffer(iommu);
Signature · 1 line
2.31.1