[PATCH] mtk-sd: Fix a pagefault in dma_unmap_sg() for not prepared data
Sergey Senozhatsky
senozhatsky at chromium.org
Wed Jun 4 18:14:15 PDT 2025
On (25/06/05 10:07), Masami Hiramatsu (Google) wrote:
> From: Masami Hiramatsu (Google) <mhiramat at kernel.org>
>
> mtk-msdc driver causes a kernel crash after swiotlb buffer is full.
>
> ---
> mtk-msdc 11240000.mmc: swiotlb buffer is full (sz: 16384 bytes), total 32768 (slots), used 32732 (slots)
> mtk-msdc 11240000.mmc: msdc_track_cmd_data: cmd=18 arg=0397A6F8; host->error=0x00000004
> Unable to handle kernel paging request at virtual address ffffffffc0001fc0
> ---
>
> When swiotlb buffer is full, the dma_map_sg() returns 0 to
> msdc_prepare_data(), but it does not check it and sets the
> MSDC_PREPARE_FLAG.
>
> swiotlb_tbl_map_single() /* prints "swiotlb buffer is full" */
> <-swiotlb_map()
> <-dma_direct_map_page()
> <-dma_direct_map_sg()
> <-__dma_map_sg_attrs()
> <-dma_map_sg_attrs()
> <-dma_map_sg() /* returns 0 (pages mapped) */
> <-msdc_prepare_data()
>
> Then, the msdc_unprepare_data() checks MSDC_PREPARE_FLAG and calls
> dma_unmap_sg() with unmapped pages. It causes a page fault.
>
> To fix this problem, Do not set MSDC_PREPARE_FLAG if dma_map_sg()
> fails because this is not prepared.
>
> Fixes: 208489032bdd ("mmc: mediatek: Add Mediatek MMC driver")
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat at kernel.org>
Tested-by: Sergey Senozhatsky <senozhatsky at chromium.org>
More information about the Linux-mediatek
mailing list