Skip to content

Commit 539d805

Browse files
mhiramatstorulf
authored andcommitted
mtk-sd: Fix a pagefault in dma_unmap_sg() for not prepared data
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: 2084890 ("mmc: mediatek: Add Mediatek MMC driver") Signed-off-by: Masami Hiramatsu (Google) <[email protected]> Tested-by: Sergey Senozhatsky <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/174908565814.4056588.769599127120955383.stgit@mhiramat.tok.corp.google.com Signed-off-by: Ulf Hansson <[email protected]>
1 parent 3358b83 commit 539d805

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/mmc/host/mtk-sd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,9 +846,10 @@ static inline void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma,
846846
static void msdc_prepare_data(struct msdc_host *host, struct mmc_data *data)
847847
{
848848
if (!(data->host_cookie & MSDC_PREPARE_FLAG)) {
849-
data->host_cookie |= MSDC_PREPARE_FLAG;
850849
data->sg_count = dma_map_sg(host->dev, data->sg, data->sg_len,
851850
mmc_get_dma_dir(data));
851+
if (data->sg_count)
852+
data->host_cookie |= MSDC_PREPARE_FLAG;
852853
}
853854
}
854855

0 commit comments

Comments
 (0)