arm64: Fix swiotlb fallback allocation
PATCH 1/1 arm64: Fix swiotlb fallback allocation
Commit b67a8b29df introduced logic to skip swiotlb allocation when all memory is DMA accessible anyway.
While this is a great idea, __dma_alloc still calls swiotlb code unconditionally to allocate memory when there is no CMA memory available. The swiotlb code is called to ensure that we at least try get_free_pages().
Without initialization, swiotlb allocation code tries to access io_tlb_list which is NULL. That results in a stack trace like this:
Unable to handle kernel NULL pointer dereference at virtual address 00000000 [...] [<ffff00000845b908>] swiotlb_tbl_map_single+0xd0/0x2b0 [<ffff00000845be94>] swiotlb_alloc_coherent+0x10c/0x198 [<ffff000008099dc0>] __dma_alloc+0x68/0x1a8 [<ffff000000a1b410>] drm_gem_cma_create+0x98/0x108 [drm] [<ffff000000abcaac>] drm_fbdev_cma_create_with_funcs+0xbc/0x368 [drm_kms_helper] [<ffff000000abcd84>] drm_fbdev_cma_create+0x2c/0x40 [drm_kms_helper] [<ffff000000abc040>] drm_fb_helper_initial_config+0x238/0x410 [drm_kms_helper] [<ffff000000abce88>] drm_fbdev_cma_init_with_funcs+0x98/0x160 [drm_kms_helper] [<ffff000000abcf90>] drm_fbdev_cma_init+0x40/0x58 [drm_kms_helper] [<ffff000000b47980>] vc4_kms_load+0x90/0xf0 [vc4] [<ffff000000b46a94>] vc4_drm_bind+0xec/0x168 [vc4] [...]
Thankfully swiotlb code just learned how to not do allocations with the FORCE_NO option. This patch configures the swiotlb code to use that if we decide not to initialize the swiotlb framework.
--- arch/arm64/mm/init.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/mm/init.c +2 -0
@@ -404,6 +404,8 @@ void __init mem_init(void)if (swiotlb_force ==SWIOTLB_FORCE || max_pfn > (arm64_dma_phys_limit >>PAGE_SHIFT ))swiotlb_init (1 ); +else + swiotlb_force =SWIOTLB_NO_FORCE ;set_max_mapnr (pfn_to_page (max_pfn) - mem_map);
Signature · 1 line
1.8.5.6
Catalin Marinas
maintainerQuoted 29 lines · Alexander Graf
Commit
b67a8b29dfintroduced logic to skip swiotlb allocation when all memory is DMA accessible anyway.While this is a great idea,
__dma_allocstill calls swiotlb code unconditionally to allocate memory when there is no CMA memory available. The swiotlb code is called to ensure that we at least tryget_free_pages().Without initialization, swiotlb allocation code tries to access
io_tlb_listwhich is NULL. That results in a stack trace like this:Unable to handle kernel NULL pointer dereference at virtual address 00000000 [...] [<ffff00000845b908>] swiotlb_tbl_map_single+0xd0/0x2b0 [<ffff00000845be94>] swiotlb_alloc_coherent+0x10c/0x198 [<ffff000008099dc0>] __dma_alloc+0x68/0x1a8 [<ffff000000a1b410>] drm_gem_cma_create+0x98/0x108 [drm] [<ffff000000abcaac>] drm_fbdev_cma_create_with_funcs+0xbc/0x368 [drm_kms_helper] [<ffff000000abcd84>] drm_fbdev_cma_create+0x2c/0x40 [drm_kms_helper] [<ffff000000abc040>] drm_fb_helper_initial_config+0x238/0x410 [drm_kms_helper] [<ffff000000abce88>] drm_fbdev_cma_init_with_funcs+0x98/0x160 [drm_kms_helper] [<ffff000000abcf90>] drm_fbdev_cma_init+0x40/0x58 [drm_kms_helper] [<ffff000000b47980>] vc4_kms_load+0x90/0xf0 [vc4] [<ffff000000b46a94>] vc4_drm_bind+0xec/0x168 [vc4] [...]Thankfully swiotlb code just learned how to not do allocations with the
FORCE_NOoption. This patch configures the swiotlb code to use that if we decide not to initialize the swiotlb framework.
Quoted 6 lines
Fixes b67a8b29df ("arm64: mm: only initialize swiotlb when necessary")Signed-off-by Alexander Graf <[email protected]>CC Catalin Marinas <[email protected]>CC Jisheng Zhang <[email protected]>CC Geert Uytterhoeven <[email protected]>CC Konrad Rzeszutek Wilk <[email protected]>
Thanks for the fix.
BTW, I wonder whether we also need to improve the original commit slightly, in case we get a device mask smaller than what max_pfn covers:
arch/arm64/mm/dma-mapping.c +1 -1
@@ -349,7 +349,7 @@ static int __swiotlb_dma_supported(struct device *hwdev, u64 mask) {if (swiotlb)return swiotlb_dma_supported (hwdev, mask); -return 1 ; +return phys_to_dma (hwdev,PFN_PHYS (max_pfn) -1 ) <= mask; }static struct dma_map_ops swiotlb_dma_ops = {
Signature · 1 line
Catalin
Quoted 29 lines · Alexander Graf
Commit
b67a8b29dfintroduced logic to skip swiotlb allocation when all memory is DMA accessible anyway.While this is a great idea,
__dma_allocstill calls swiotlb code unconditionally to allocate memory when there is no CMA memory available. The swiotlb code is called to ensure that we at least tryget_free_pages().Without initialization, swiotlb allocation code tries to access
io_tlb_listwhich is NULL. That results in a stack trace like this:Unable to handle kernel NULL pointer dereference at virtual address 00000000 [...] [<ffff00000845b908>] swiotlb_tbl_map_single+0xd0/0x2b0 [<ffff00000845be94>] swiotlb_alloc_coherent+0x10c/0x198 [<ffff000008099dc0>] __dma_alloc+0x68/0x1a8 [<ffff000000a1b410>] drm_gem_cma_create+0x98/0x108 [drm] [<ffff000000abcaac>] drm_fbdev_cma_create_with_funcs+0xbc/0x368 [drm_kms_helper] [<ffff000000abcd84>] drm_fbdev_cma_create+0x2c/0x40 [drm_kms_helper] [<ffff000000abc040>] drm_fb_helper_initial_config+0x238/0x410 [drm_kms_helper] [<ffff000000abce88>] drm_fbdev_cma_init_with_funcs+0x98/0x160 [drm_kms_helper] [<ffff000000abcf90>] drm_fbdev_cma_init+0x40/0x58 [drm_kms_helper] [<ffff000000b47980>] vc4_kms_load+0x90/0xf0 [vc4] [<ffff000000b46a94>] vc4_drm_bind+0xec/0x168 [vc4] [...]Thankfully swiotlb code just learned how to not do allocations with the
FORCE_NOoption. This patch configures the swiotlb code to use that if we decide not to initialize the swiotlb framework.
Quoted 6 lines
Fixes b67a8b29df ("arm64: mm: only initialize swiotlb when necessary")Signed-off-by Alexander Graf <[email protected]>CC Catalin Marinas <[email protected]>CC Jisheng Zhang <[email protected]>CC Geert Uytterhoeven <[email protected]>CC Konrad Rzeszutek Wilk <[email protected]>
Queued for 4.10. Thanks.
Signature · 1 line
Catalin