]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mtk-sd: Fix a pagefault in dma_unmap_sg() for not prepared data
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Thu, 5 Jun 2025 01:07:38 +0000 (10:07 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Jul 2025 16:27:45 +0000 (18:27 +0200)
commit 539d80575b810c7a5987c7ac8915e3bc99c03695 upstream.

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@kernel.org>
Tested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/174908565814.4056588.769599127120955383.stgit@mhiramat.tok.corp.google.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mmc/host/mtk-sd.c

index 2c9ea5ed0b2fcb03a1da2078873772f42b10b5e2..3f82e0f9dc05730e582925b46626ac2e8f5d85b6 100644 (file)
@@ -713,9 +713,10 @@ static void msdc_prepare_data(struct msdc_host *host, struct mmc_request *mrq)
        struct mmc_data *data = mrq->data;
 
        if (!(data->host_cookie & MSDC_PREPARE_FLAG)) {
-               data->host_cookie |= MSDC_PREPARE_FLAG;
                data->sg_count = dma_map_sg(host->dev, data->sg, data->sg_len,
                                            mmc_get_dma_dir(data));
+               if (data->sg_count)
+                       data->host_cookie |= MSDC_PREPARE_FLAG;
        }
 }