Skip to contentSkip to conversation

iommu: intel: Flush the IOTLB to get rid of the initial kdump mappings

PATCH Applied KarimAllah Ahmed 3 participants 3 messages May 5, 2017 – May 17, 2017 IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu: intel: Flush the IOTLB to get rid of the initial kdump mappings

Ever since commit 091d42e43d ("iommu/vt-d: Copy translation tables from old kernel") the kdump kernel copies the IOMMU context tables from the previous kernel. Each device mappings will be destroyed once the driver for the respective device takes over.

This unfortunately breaks the workflow of mapping and unmapping a new context to the IOMMU. The mapping function assumes that either:

1) Unmapping did the proper IOMMU flushing and it only ever flush if the IOMMU unit supports caching invalid entries.
2) The system just booted and the initialization code took care of flushing all IOMMU caches.

This assumption is not true for the kdump kernel since the context tables have been copied from the previous kernel and translations could have been cached ever since. So make sure to flush the IOTLB as well when we destroy these old copied mappings.

Cc Joerg Roedel <[email protected]>
Cc David Woodhouse <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Anthony Liguori <[email protected]>
---
 drivers/iommu/intel-iommu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iommu/intel-iommu.c +4 -1
index d412a31..478130d 100644
@@ -2050,11 +2050,14 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
 	if (context_copied(context)) {
 		u16 did_old = context_domain_id(context);
 
-		if (did_old >= 0 && did_old < cap_ndoms(iommu->cap))
+		if (did_old >= 0 && did_old < cap_ndoms(iommu->cap)) {
 			iommu->flush.flush_context(iommu, did_old,
 						   (((u16)bus) << 8) | devfn,
 						   DMA_CCMD_MASK_NOBIT,
 						   DMA_CCMD_DEVICE_INVL);
+			iommu->flush.flush_iotlb(iommu, did_old, 0, 0,
+						 DMA_TLB_DSI_FLUSH);
+		}
 	}
 
 	pgd = domain->pgd;
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · KarimAllah Ahmed

Ever since commit 091d42e43d ("iommu/vt-d: Copy translation tables from old kernel") the kdump kernel copies the IOMMU context tables from the previous kernel. Each device mappings will be destroyed once the driver for the respective device takes over.

This unfortunately breaks the workflow of mapping and unmapping a new context to the IOMMU. The mapping function assumes that either:

1) Unmapping did the proper IOMMU flushing and it only ever flush if the IOMMU unit supports caching invalid entries.
2) The system just booted and the initialization code took care of flushing all IOMMU caches.

This assumption is not true for the kdump kernel since the context tables have been copied from the previous kernel and translations could have been cached ever since. So make sure to flush the IOTLB as well when we destroy these old copied mappings.

Quoted 5 lines
Cc Joerg Roedel <[email protected]>
Cc David Woodhouse <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Anthony Liguori <[email protected]>

I'm still moderately unhappy about the whole "preserve existing mappings during kdump" thing, and wanted to have a PCI quirk for the known-broken-can't-be-reset-after-fault devices, and trigger this behaviour only then. Although I have a vague recollection of there being a slightly saner justification for it... perhaps this should be documented, if there is one?

maintainer Applied
#2 lore raw
In reply to KarimAllah Ahmed
Quoted 2 lines · KarimAllah Ahmed

Ever since commit 091d42e43d ("iommu/vt-d: Copy translation tables from old kernel")

Please put the commit-information into a Fixes: tag next time. I'll added a Fixes tag to the commit this time.

Quoted 17 lines

the kdump kernel copies the IOMMU context tables from the previous kernel. Each device mappings will be destroyed once the driver for the respective device takes over.

This unfortunately breaks the workflow of mapping and unmapping a new context to the IOMMU. The mapping function assumes that either:

1) Unmapping did the proper IOMMU flushing and it only ever flush if the IOMMU unit supports caching invalid entries.
2) The system just booted and the initialization code took care of flushing all IOMMU caches.

This assumption is not true for the kdump kernel since the context tables have been copied from the previous kernel and translations could have been cached ever since. So make sure to flush the IOTLB as well when we destroy these old copied mappings.

Quoted 5 lines
Cc Joerg Roedel <[email protected]>
Cc David Woodhouse <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Anthony Liguori <[email protected]>

Applied to iommu/fixes, thanks.