soc: apple: sep: unmap the firmware IOVA, not the physical address - #592
Open
brentkearney wants to merge 1 commit into
Open
soc: apple: sep: unmap the firmware IOVA, not the physical address#592brentkearney wants to merge 1 commit into
brentkearney wants to merge 1 commit into
Conversation
load_fw_and_shmem() maps the SEP firmware region with dma_map_resource(), which returns an IOVA, but keeps only the shifted copy needed for the MSG_BOOT_IMG4 message and discards the IOVA itself. remove() then calls dma_unmap_resource() with region_params.addr, the physical address of the reserved region. The two are unrelated, so the unmap tears down page table entries that were never present, and the real mapping is leaked. On t6000 the region sits at 0x10006340000, far outside the device's DART address space, and unbinding the driver warns twice: WARNING: drivers/iommu/io-pgtable-dart.c:308 at dart_unmap_pages+0x11c/0x140 dart_unmap_pages+0x11c/0x140 apple_dart_unmap_pages+0x24/0x30 __iommu_dma_unmap+0x94/0x140 iommu_dma_unmap_phys+0xf8/0x118 ...3sep9SepDriverEE20post_unbind_callback+0x34/0x70 WARNING: drivers/iommu/dma-iommu.c:844 at __iommu_dma_unmap+0x128/0x140 __iommu_dma_unmap+0x128/0x140 iommu_dma_unmap_phys+0xf8/0x118 ...3sep9SepDriverEE20post_unbind_callback+0x34/0x70 Keep the IOVA alongside the existing fw_mapped flag and unmap that instead. Reproduced on an Apple MacBook Pro (16-inch, 2021), t6000/j316s, by enabling the sep node and unbinding the driver.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unbinding
apple_sepwarns twice in the IOMMU and leaks the SEP firmware mapping becauseremove()passes the region's physical address todma_unmap_resource()instead of the IOVA thatdma_map_resource()returned. This change keeps the IOVA and unmaps that.Closes #591.
Changes
fw_iova: Atomic<u64>toSepDataand store the return value ofdma_map_resource()in it next to the existingfw_mappedflag.fw_iovainstead ofregion_params.addrtodma_unmap_resource()in the unbind path.Bind and boot paths are unchanged.
Testing
asahi-7.1.6-1with rustc 1.93.1:drivers/soc/apple/sep.obuilds before and after.CLIPPY=1introduces no new warnings;rustfmt --checkpasses.apple,t6000/j316sMacBook Pro with the unpatched driver; I have not booted a patched kernel to confirm the unmap is silent.