Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp854037pxf; Thu, 1 Apr 2021 15:50:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ+9Cudtvi5mBWJJlWZoiXIRqwPa2wuquOVtXRMQsSeT9VGeLS6evgjSlP9Luw9PLFGgB2 X-Received: by 2002:a05:6602:2f0c:: with SMTP id q12mr8440024iow.82.1617317447129; Thu, 01 Apr 2021 15:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617317447; cv=none; d=google.com; s=arc-20160816; b=BuJHgfpKDY7nx4ioqJxJb/TEgLUkhcvb2kwL6fNI2sszj/+QjdVPriChNG0lTaOcYg 3zb+zUjN+2xL22JchqrzBH4lVHFLJa9XQ94pY00alhewwEMiI++v9SXOhuPmebk/3Irr OBNAZZlIJ0rOyU8L93gwL05sQDTlDXPmeQvciHSvCKXW0A+bJSDKeEBXkVbridL/QaZ0 jA5Nu7y604YknxwrLjQz3KfjdpMdcfMfHAgpk04HiBDmQsIEt0MNCHIrZf7Nc3PSvynX 5YodPanyT6NWcjTcWppCTqlfLl0AonAN/GsEF3WetGW4VMbGW2OY1W5FnWMZaT7rT8QS LlKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=CuQ+fCWT1rB0+aM1K1k9N1tiDK8VwSM2eHjqwE/nxl4=; b=Bqtet8biNRuEFKCwPycCmE8qqDKNHSlVbTlZiCfzUIlrcS7nmHu7Pu+O6Cd2OWsvXZ MttYjKTAOTMiLja5kUGGsgbpHRFsS7/y1IsuWAEsBcpqRgh/36igrBsMANrEwDx0CQzx ramNjUM09YaVkRrJ0/h+6Cme4AKMWovBAjoXrn+DYXsBuiquidqn8G2yoDvaxyqPrcTR 1dZ4gFVARX6OTd77c8ZVVDYzIGNCrZQ60ThPQgFDlBTiVU+ZJ5MQTGS4P92gX4Fi7oxs /0DAYoVHXbQ/nHUDiI8+mSZfZ4iDtwwN/+ig3d15ad8QxkO/n1nL1jr8ObW2qgPdsCQz 6ETw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NgEFUiTA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g5si5677243ild.65.2021.04.01.15.50.33; Thu, 01 Apr 2021 15:50:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NgEFUiTA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234734AbhDAWtB (ORCPT + 99 others); Thu, 1 Apr 2021 18:49:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234043AbhDAWtB (ORCPT ); Thu, 1 Apr 2021 18:49:01 -0400 Received: from mail-vs1-xe2f.google.com (mail-vs1-xe2f.google.com [IPv6:2607:f8b0:4864:20::e2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23148C061788 for ; Thu, 1 Apr 2021 15:49:01 -0700 (PDT) Received: by mail-vs1-xe2f.google.com with SMTP id r12so2005446vsj.5 for ; Thu, 01 Apr 2021 15:49:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CuQ+fCWT1rB0+aM1K1k9N1tiDK8VwSM2eHjqwE/nxl4=; b=NgEFUiTAnq7fFFmR24/kSiMIspDQaRD7nNmLUnNyKOeW+G7lpmB+ONc5P+2KgMxBYI /ZX3auaZZMpq+VpOTviFa1VUNFiAc2DjCwrO4KcfwEyDgqEoyZW7UBlVPP4ubw4GjUzv BL18fLWz1/rsIafumpOMnTAD24pdNJHlV+SluJpL3Ve6gZDzFMUdRq5ov3ZJ61MoORy3 GO7ZjIhQv6xkN1wD/FeI46rPxqEcGtXRkmez1C5hmU/SQHlK1Wn6JRsEZXSM8VhKy6r9 glg0xX6ZrJm57eqjA/FUUt2xj7qmDxXIhgdXt9lHSIAwsr5dboaC1UFNjwiAkm9/Cn7Q vlEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CuQ+fCWT1rB0+aM1K1k9N1tiDK8VwSM2eHjqwE/nxl4=; b=OJnMzaPI7SnxriCaauiXnTH3aYvSGdaxxtku6On7L1AIkU6qS6YhElMuxAtAKoCD6h s8R7WZAhlmwx4mg2zFZBl18IcphiEmCuJ1h4m3gOnVhiLQsRx+ZYIcRrMb0BM5UqFivV N1LXRMh4rP9sse/MJUbRET1PJlITyea/F77ypRiR4fLr7IT4C2FZuKyWllgJYYmTkVHG lPWFqTCkuRnwxUf5Q11aC0bV5JBsb71pYLU8OujczMAuBwfwOJU4MRCqcWOYZUtKKEyU rtdoXxCZUhcLAzh/MqxETz4QzYTJaKyxITddeDI/t/2IyxendT0fvrNxtODgHwWoDBRW 30kw== X-Gm-Message-State: AOAM530tz+v1kboIZFkJ3x30nysQ1wLy1vhImRq5/nUMlo9hg1zfihwA YGK44WOOSDoF00PKpor9BzUaLALlADrMDWO+UaJM2Q== X-Received: by 2002:a67:6942:: with SMTP id e63mr7698810vsc.48.1617317340138; Thu, 01 Apr 2021 15:49:00 -0700 (PDT) MIME-Version: 1.0 References: <20210401132853.105448-1-huobean@gmail.com> <20210401132853.105448-2-huobean@gmail.com> In-Reply-To: <20210401132853.105448-2-huobean@gmail.com> From: Ulf Hansson Date: Fri, 2 Apr 2021 00:48:23 +0200 Message-ID: Subject: Re: [PATCH v2 1/2] mmc: core: Let sanitize timeout readable/writable via sysfs To: Bean Huo Cc: "Shimoda, Yoshihiro" , Wolfram Sang , Adrian Hunter , linux-mmc , Linux Kernel Mailing List , Bean Huo Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 1 Apr 2021 at 15:29, Bean Huo wrote: > > From: Bean Huo > > As the density increases, the 4-minute timeout value for > sanitize is no longer feasible. At the same time, devices > of different densities have different timeout values, and it is > difficult to obtain a unified standard timeout value. Therefore, > it is better to let the user explicitly change sanitize timeout > value according to the eMMC density on the board. This makes sense. The current timeout in the mmc core isn't good enough. However, I think there is a better option than inventing a sysfs node to allow userspace to specify the timeout. First, we have the card quirks that the mmc core uses to allow us to modify a common behaviour (in this case timeouts values for sanitize operations). This can be used to enforce a specific timeout for the eMMC card. I think this should take precedence over anything else. Second, the ioctl command allows you to specify a specific command timeout in the struct mmc_ioc_cmd (.cmd_timeout_ms). If this is specified from user space we could forward it to mmc_santize() and use that rather than the default MMC_SANITIZE_TIMEOUT_MS. Would this satisfy your needs? Kind regards Uffe > > Signed-off-by: Bean Huo > --- > drivers/mmc/core/mmc.c | 34 ++++++++++++++++++++++++++++++++++ > drivers/mmc/core/mmc_ops.c | 3 +-- > include/linux/mmc/card.h | 1 + > 3 files changed, 36 insertions(+), 2 deletions(-) > > diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c > index 8741271d3971..3885cc1780ac 100644 > --- a/drivers/mmc/core/mmc.c > +++ b/drivers/mmc/core/mmc.c > @@ -28,6 +28,7 @@ > > #define DEFAULT_CMD6_TIMEOUT_MS 500 > #define MIN_CACHE_EN_TIMEOUT_MS 1600 > +#define MMC_SANITIZE_TIMEOUT_MS (240 * 1000) /* 240s */ > > static const unsigned int tran_exp[] = { > 10000, 100000, 1000000, 10000000, > @@ -835,6 +836,37 @@ static ssize_t mmc_dsr_show(struct device *dev, > > static DEVICE_ATTR(dsr, S_IRUGO, mmc_dsr_show, NULL); > > +static ssize_t sanitize_timeout_ms_show(struct device *dev, > + struct device_attribute *attr, > + char *buf) > +{ > + struct mmc_card *card = mmc_dev_to_card(dev); > + > + return sysfs_emit(buf, "%d\n", card->sanitize_timeout_ms); > +} > + > +static ssize_t sanitize_timeout_ms_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t len) > +{ > + struct mmc_card *card = mmc_dev_to_card(dev); > + unsigned int new; > + int ret; > + > + ret = kstrtouint(buf, 0, &new); > + if (ret < 0) > + return ret; > + > + if (new == 0) > + return -EINVAL; > + > + card->sanitize_timeout_ms = new; > + > + return len; > +} > +static DEVICE_ATTR_RW(sanitize_timeout_ms); > + > + > static struct attribute *mmc_std_attrs[] = { > &dev_attr_cid.attr, > &dev_attr_csd.attr, > @@ -861,6 +893,7 @@ static struct attribute *mmc_std_attrs[] = { > &dev_attr_rca.attr, > &dev_attr_dsr.attr, > &dev_attr_cmdq_en.attr, > + &dev_attr_sanitize_timeout_ms.attr, > NULL, > }; > ATTRIBUTE_GROUPS(mmc_std); > @@ -1623,6 +1656,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, > card->ocr = ocr; > card->type = MMC_TYPE_MMC; > card->rca = 1; > + card->sanitize_timeout_ms = MMC_SANITIZE_TIMEOUT_MS; > memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); > } > > diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c > index f413474f0f80..40a4f9e22d30 100644 > --- a/drivers/mmc/core/mmc_ops.c > +++ b/drivers/mmc/core/mmc_ops.c > @@ -21,7 +21,6 @@ > > #define MMC_BKOPS_TIMEOUT_MS (120 * 1000) /* 120s */ > #define MMC_CACHE_FLUSH_TIMEOUT_MS (30 * 1000) /* 30s */ > -#define MMC_SANITIZE_TIMEOUT_MS (240 * 1000) /* 240s */ > > static const u8 tuning_blk_pattern_4bit[] = { > 0xff, 0x0f, 0xff, 0x00, 0xff, 0xcc, 0xc3, 0xcc, > @@ -1025,7 +1024,7 @@ int mmc_sanitize(struct mmc_card *card) > mmc_retune_hold(host); > > err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_SANITIZE_START, > - 1, MMC_SANITIZE_TIMEOUT_MS); > + 1, card->sanitize_timeout_ms); > if (err) > pr_err("%s: Sanitize failed err=%d\n", mmc_hostname(host), err); > > diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h > index f9ad35dd6012..9db0dcd9661e 100644 > --- a/include/linux/mmc/card.h > +++ b/include/linux/mmc/card.h > @@ -273,6 +273,7 @@ struct mmc_card { > > bool reenable_cmdq; /* Re-enable Command Queue */ > > + unsigned int sanitize_timeout_ms; > unsigned int erase_size; /* erase size in sectors */ > unsigned int erase_shift; /* if erase unit is power 2 */ > unsigned int pref_erase; /* in sectors */ > -- > 2.25.1 >