From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E70B72E9EB2; Tue, 15 Jul 2025 13:53:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752587621; cv=none; b=PvNghOSAf847SDavvvFB+9DnoLYwQuddt2asC1qnSrguPk0KJMijyqJex8YVk+SsxrRjrqKwx8XO2YLJZZcdCf2XMHEVZRQ4B/u7QmLZxyKi7PnGpl1u1+FnKpDu4FtkZ9q6Llo5yZky827eIhjY3c1kgOQitjYBx0ZZp+1Er88= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752587621; c=relaxed/simple; bh=6kQ3qvVIwtAaXamy//zwcW+mLG1xEpUCTH5GWlfu+14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iGMR28mSdS8iFKm4iOYdpJz/AVLPmh6s7lEXL95pSEZ4/TuYOfZ9jehtp/6x6tJN44Y9ht4DahBFEZc9hX5lyWcRyP0a7nYcJ7b+n3sR5DTOjSfd2Ezi4yxtSYLHsth2wLVXOJkt4/U387fPufHSTCDgvG7XLRIb+s3wsy48vCA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=v8W9bva2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="v8W9bva2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37141C4CEE3; Tue, 15 Jul 2025 13:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1752587620; bh=6kQ3qvVIwtAaXamy//zwcW+mLG1xEpUCTH5GWlfu+14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v8W9bva2vlafmlF2PLM8CJkH+Y4IrmwqAHY4tjFjEaRf6TnVxqiTPnNwDpCC1JN10 DmL7dWdCFhF9qDz4EEasa+nZ+q8b6I+ZGzQWtuheKplNcTSFuy6SU2AxlEeimvCV1k XRc/kVMoAwJuRG0+Cn00KPcyUMVEusg6kHU5pQuY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Masami Hiramatsu (Google)" , Sergey Senozhatsky , AngeloGioacchino Del Regno , Ulf Hansson Subject: [PATCH 5.10 080/208] mtk-sd: Fix a pagefault in dma_unmap_sg() for not prepared data Date: Tue, 15 Jul 2025 15:13:09 +0200 Message-ID: <20250715130814.147230320@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250715130810.830580412@linuxfoundation.org> References: <20250715130810.830580412@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Masami Hiramatsu (Google) 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) Tested-by: Sergey Senozhatsky Reviewed-by: AngeloGioacchino Del Regno 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 Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/host/mtk-sd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -713,9 +713,10 @@ static void msdc_prepare_data(struct msd 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; } }