From patchwork Thu Sep 16 16:01:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 513041 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1444192jao; Thu, 16 Sep 2021 10:44:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztYPfWmfPCwDR2EPgPqkLcUygZTWQq+L4Bm8kUDjJlbmEufcOAD2HkjKaFOaAnRG5nX20t X-Received: by 2002:a6b:6c17:: with SMTP id a23mr5369048ioh.110.1631814242398; Thu, 16 Sep 2021 10:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631814242; cv=none; d=google.com; s=arc-20160816; b=0EQCZrffjtDUnamJeY02qRAdjYn8FwEMoUh0YMthkBNnPF+8SRmxYJRJDRrsvY7SHH z1gO/4cPBg75JCq8oXjMUrwQYJ77xKw/5XaI6tg+hWrVapNPdPGpnzOg0rcqVCu3jM8k rZXCY9b/bIUzHuoZ+g6CZvWoC8s+0Tkmh965969xKbK56VTTW2Vq4yN0nV/7X1I/Hj6O II8+zp/C5hlGs9nwo9iWiRk1jLe+HBMqcGjeZUAjeeyKHEWxqJrxRCXVzrcPupsVnveE wbaG7M0qqGsFy0WfyYVLtiuZSaLNQQ1oY0X+ApGBgXiS71anIN1G5VOFxOWdVwL6SqA8 eO/g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ygZDhIvKdBNTwXYTnwT+urLTBpDb1DH3xNDy6IDT/0A=; b=TFNZcvcAIsKBfIjftsuFlfD2tgjWiI3fLIUWH91Z6EnQTzEtICRmfJ9WiLAnKnsCo0 E/ZAoKDPPzej/4wlOb61PFSuLPwfTZh5UJ2UzOj/tr0J0x4ZqlC6f6HK3gDDS82/B0TF x4NLXEfDRNK3kwOHPlTJzc9BchdD6CWHEiyJvNUlWj4jpeWbMHisnZrKV8eqhhxRap9D MVEOQKrkXe/3AyX+cTogmStpi1cc1QiCG4zAW9AV2NYFG0cEeGrCvRnzv8cNCBsn1jzy Nr7X4D2mRlUknTELn9wUICiJamXdncdfCnF6NgdX5r1qLeVllqsW7LR62MyKZci+6091 vzog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OVaNWrqf; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c184si3522977iof.111.2021.09.16.10.44.02; Thu, 16 Sep 2021 10:44:02 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=@linuxfoundation.org header.s=korg header.b=OVaNWrqf; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344901AbhIPRnQ (ORCPT + 11 others); Thu, 16 Sep 2021 13:43:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:53758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353972AbhIPRh7 (ORCPT ); Thu, 16 Sep 2021 13:37:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 79B6063239; Thu, 16 Sep 2021 16:49:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810998; bh=WDaXINiMYnSPoVIWWMbXLKEYHtBosDCawATmgnV4R7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OVaNWrqfg5uEahzwHxo8pb1EEjjAYWmxmsYrJYNOSXOarzZd+6F019AqrppsBdd4R SwiQBMmvSpIHei8AUYZFchteFfdMnogN2QvrK6GMWq3o/sHghd2DZXJqg2TVxKORB/ uuifyXNU4MwQYRP01GnJmNb9QAFyxjoW984UfP8w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ulf Hansson , Shawn Lin , Sasha Levin Subject: [PATCH 5.14 346/432] mmc: core: Avoid hogging the CPU while polling for busy after I/O writes Date: Thu, 16 Sep 2021 18:01:35 +0200 Message-Id: <20210916155822.556347951@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ulf Hansson [ Upstream commit 6966e6094c6d594044ef1b740dd827e05881331c ] When mmc_blk_card_busy() calls card_busy_detect() to poll for the card's state with CMD13, this is done without any delays in between the commands being sent. Rather than fixing card_busy_detect() in this regards, let's instead convert into using the common __mmc_poll_for_busy(), which also helps us to avoid open-coding. Signed-off-by: Ulf Hansson Reviewed-by: Shawn Lin Link: https://lore.kernel.org/r/20210702134229.357717-4-ulf.hansson@linaro.org Signed-off-by: Sasha Levin --- drivers/mmc/core/block.c | 69 ++++++++++++++++---------------------- drivers/mmc/core/mmc_ops.c | 1 + 2 files changed, 30 insertions(+), 40 deletions(-) -- 2.30.2 diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index c30d0ab15539..a9ad9f5fa949 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -98,6 +98,11 @@ static int max_devices; static DEFINE_IDA(mmc_blk_ida); static DEFINE_IDA(mmc_rpmb_ida); +struct mmc_blk_busy_data { + struct mmc_card *card; + u32 status; +}; + /* * There is one mmc_blk_data per slot. */ @@ -417,42 +422,6 @@ static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd __user *ic_ptr, return 0; } -static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms, - u32 *resp_errs) -{ - unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms); - int err = 0; - u32 status; - - do { - bool done = time_after(jiffies, timeout); - - err = __mmc_send_status(card, &status, 5); - if (err) { - dev_err(mmc_dev(card->host), - "error %d requesting status\n", err); - return err; - } - - /* Accumulate any response error bits seen */ - if (resp_errs) - *resp_errs |= status; - - /* - * Timeout if the device never becomes ready for data and never - * leaves the program state. - */ - if (done) { - dev_err(mmc_dev(card->host), - "Card stuck in wrong state! %s status: %#x\n", - __func__, status); - return -ETIMEDOUT; - } - } while (!mmc_ready_for_data(status)); - - return err; -} - static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, struct mmc_blk_ioc_data *idata) { @@ -1852,28 +1821,48 @@ static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq) brq->data.error || brq->cmd.resp[0] & CMD_ERRORS; } +static int mmc_blk_busy_cb(void *cb_data, bool *busy) +{ + struct mmc_blk_busy_data *data = cb_data; + u32 status = 0; + int err; + + err = mmc_send_status(data->card, &status); + if (err) + return err; + + /* Accumulate response error bits. */ + data->status |= status; + + *busy = !mmc_ready_for_data(status); + return 0; +} + static int mmc_blk_card_busy(struct mmc_card *card, struct request *req) { struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req); - u32 status = 0; + struct mmc_blk_busy_data cb_data; int err; if (mmc_host_is_spi(card->host) || rq_data_dir(req) == READ) return 0; - err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, &status); + cb_data.card = card; + cb_data.status = 0; + err = __mmc_poll_for_busy(card, MMC_BLK_TIMEOUT_MS, &mmc_blk_busy_cb, + &cb_data); /* * Do not assume data transferred correctly if there are any error bits * set. */ - if (status & mmc_blk_stop_err_bits(&mqrq->brq)) { + if (cb_data.status & mmc_blk_stop_err_bits(&mqrq->brq)) { mqrq->brq.data.bytes_xfered = 0; err = err ? err : -EIO; } /* Copy the exception bit so it will be seen later on */ - if (mmc_card_mmc(card) && status & R1_EXCEPTION_EVENT) + if (mmc_card_mmc(card) && cb_data.status & R1_EXCEPTION_EVENT) mqrq->brq.cmd.resp[0] |= R1_EXCEPTION_EVENT; return err; diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index e2c431c0ce5d..90d213a2203f 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -510,6 +510,7 @@ int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, return 0; } +EXPORT_SYMBOL_GPL(__mmc_poll_for_busy); int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, bool retry_crc_err, enum mmc_busy_cmd busy_cmd)