Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1193122pxp; Sat, 12 Mar 2022 04:22:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5XClY2iALrcQCSHi9GiGYBxbioaOsWZW0shR2FcHOrgX5GCnqOph0u9/+qcs+mOPcDZHh X-Received: by 2002:a17:906:4fd2:b0:6db:21ba:e434 with SMTP id i18-20020a1709064fd200b006db21bae434mr12241688ejw.714.1647087720663; Sat, 12 Mar 2022 04:22:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647087720; cv=none; d=google.com; s=arc-20160816; b=Vn0gKnFoRgiXOYz++aj2JJu+iFWWP3jjTM42+3aIsl+UVJj15rHiLU3ol7kGqVsU+Z dBEFZF+Uicsk4n5BSWeUSwDiPShHpSb4Dt6iRsT4Qi9Ne4JGjKwSIpycKYII3pl7S5qS N/WY/nPOaX4fwHIoNLK17LxLYB+rY4NCxr77iMJyIMQT2wGuMBAwRzL947OihjBo/wYc zeZ3GrKvJP7l9mqjs0opuvinfSiK2P1aLtT7WPGk3tsGTasP/8Z0ffELzAOxjjiIroOH MLNWYW18ZkMheu3/TCG2VJYQPJT2jgEZu4AwJjtKtKfS87yj6nXldK0lLP5d0WYRAV0A SDBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=2VXjwmNun5zLYMHcoKmnJVT+lwzaJJ928ADDsw4Q0GQ=; b=t9f06LoxYVdN5+oiplLvzqwIkgb3NL3gDF3SLF1vaHE1BF1l7uba539VGgUAJLoH8M ciUQY/7uKLA4KdnP2O3t8AlzlT0dV7RTPGseK3iMc/DXrbRBE/ZMyEGGLn5pec5hTWqB 77k9Btm1eWdfay/mpjGSG950O7lDsnUdlZMqru14DoiJYc+vfIlIKIvHTZyQg3mk/mXb 2K1bzSvBC4egJFgB9iSBujcTeoC/GUSX+GYheXgzJmTRqtjy9VqEEljjBM3sSkdS/6g5 VF9+dcHx0a0vzpO9pB/fA5cjmDJ1ZDNxh1afUdXgQix4MdSM6vjeOtPJiGPzjuH2nFfw BMnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bi20-20020a05640221d400b004107aa9cf7dsi7465802edb.116.2022.03.12.04.21.33; Sat, 12 Mar 2022 04:22:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230347AbiCLEo0 (ORCPT + 99 others); Fri, 11 Mar 2022 23:44:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbiCLEoZ (ORCPT ); Fri, 11 Mar 2022 23:44:25 -0500 Received: from out28-1.mail.aliyun.com (out28-1.mail.aliyun.com [115.124.28.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 741961FF41C; Fri, 11 Mar 2022 20:43:18 -0800 (PST) X-Alimail-AntiSpam: AC=CONTINUE;BC=0.1887753|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_alarm|0.00849406-0.00236518-0.989141;FP=0|0|0|0|0|-1|-1|-1;HT=ay29a033018047203;MF=michael@allwinnertech.com;NM=1;PH=DS;RN=9;RT=9;SR=0;TI=SMTPD_---.N2bFkqv_1647060194; Received: from sunxibot.allwinnertech.com(mailfrom:michael@allwinnertech.com fp:SMTPD_---.N2bFkqv_1647060194) by smtp.aliyun-inc.com(10.147.40.233); Sat, 12 Mar 2022 12:43:15 +0800 From: Michael Wu To: ulf.hansson@linaro.org (maintainer:MULTIMEDIA CARD (MMC), SECURE DIGITAL (SD) AND...,commit_signer:11/9=100%,authored:4/9=44% ,added_lines:26/61=43%,removed_lines:25/35=71%), adrian.hunter@intel.com (commit_signer:3/9=33%,authored:4/9=44% ,added_lines:26/61=43%,removed_lines:25/35=71%), avri.altman@wdc.com (commit_signer:2/9=22%,authored:4/9=44% ,authored:2/9=22%,added_lines:26/61=43%,added_lines:16/61=26% ,removed_lines:25/35=71%), beanhuo@micron.com (commit_signer:1/9=11%,authored:4/9=44% ,authored:1/9=11%,added_lines:26/61=43%,removed_lines:25/35=71%), porzio@gmail.com (commit_signer:1/9=11%,authored:4/9=44% ,authored:1/9=11%,added_lines:26/61=43%,added_lines:4/61=7% ,removed_lines:25/35=71%,removed_lines:3/35=9%), michael@allwinnertech.com (authored:1/9=11%,added_lines:26/61=43% ,added_lines:14/61=23%,removed_lines:25/35=71%,removed_lines:6/35=17%) Cc: Michael Wu , Ulf Hansson , Adrian Hunter , Avri Altman , Luca Porzio , lixiang , Bean Huo , linux-mmc@vger.kernel.org (open list:MULTIMEDIA CARD (MMC), SECURE DIGITAL (SD) AND...), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] mmc: block: enable cache-flushing when mmc cache is on Date: Sat, 12 Mar 2022 12:43:13 +0800 Message-Id: <20220312044315.7994-1-michael@allwinnertech.com> X-Mailer: git-send-email 2.29.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The mmc core enable cache on default. But it only enables cache-flushing when host supports cmd23 and eMMC supports reliable write. For hosts which do not support cmd23 or eMMCs which do not support reliable write, the cache can not be flushed by `sync` command. This may leads to cache data lost. This patch enables cache-flushing as long as cache is enabled, no matter host supports cmd23 and/or eMMC supports reliable write or not. Signed-off-by: Michael Wu --- drivers/mmc/core/block.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 689eb9afeeed..1e508c079c1e 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2279,6 +2279,8 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, struct mmc_blk_data *md; int devidx, ret; char cap_str[10]; + bool enable_cache = false; + bool enable_fua = false; devidx = ida_simple_get(&mmc_blk_ida, 0, max_devices, GFP_KERNEL); if (devidx < 0) { @@ -2375,12 +2377,18 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, md->flags |= MMC_BLK_CMD23; } - if (mmc_card_mmc(card) && - md->flags & MMC_BLK_CMD23 && - ((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) || - card->ext_csd.rel_sectors)) { - md->flags |= MMC_BLK_REL_WR; - blk_queue_write_cache(md->queue.queue, true, true); + if (mmc_card_mmc(card)) { + if (md->flags & MMC_BLK_CMD23 && + ((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) || + card->ext_csd.rel_sectors)) { + md->flags |= MMC_BLK_REL_WR; + enable_fua = true; + } + + if (mmc_cache_enabled(card->host)) + enable_cache = true; + + blk_queue_write_cache(md->queue.queue, enable_cache, enable_fua); } string_get_size((u64)size, 512, STRING_UNITS_2, -- 2.29.0