From patchwork Thu Oct 13 11:16:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Loehle X-Patchwork-Id: 2021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp217272wrs; Thu, 13 Oct 2022 04:26:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6l2HlkTrhsT1wr64GM9sWuR9UWmDi8YI6I/FBEutqjxiXJDdJwBTIxTht0Pd3D+EZbrjaQ X-Received: by 2002:a17:90a:f192:b0:20d:2ea6:4b18 with SMTP id bv18-20020a17090af19200b0020d2ea64b18mr10782301pjb.27.1665660396627; Thu, 13 Oct 2022 04:26:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665660396; cv=none; d=google.com; s=arc-20160816; b=r5DfkTOWNsguE91S7CnSvXS4eEKzlnOcT78SHrrVp2h/ncGVkXbB3UYY8vSlNf/mD2 qByjTgvqVlXpkSBRB2q8JX3RSPhDFspgHCU9sKXz/dXAtojlELyp4oW4UxplsloCBnqW 8nVBz2FUDE7hiyTOwyfnZFKK6YUfBRnT3+iqGca/OC7eqMTzLd1XgpYqdPbNfixpxsC8 RlXqqnQdbc8s9Iyw7ybOsuXkm50Wfdl71aBhdOV1CJ8qnfiJNmv0XoUzrmM2J32E4KpZ FxTtsofbqeEzKHkw0fFZLVYjKIApQSIG+S9OTL3iorEbPyUIZUUM44ZDhTyVpKJa97y7 eEsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=zjFlG+8nK54yGXKDQpuTbwFPOg4EgNHpJjfLzM7W0qQ=; b=YJZrmhkbI+N9dUrIw0J3aenHqsibKFwwbo/BK43FilJB2DCMkaW0LSyw9J5TJP5/cf sMSLFzmD2TsspUzg0JIZpF3UiH1OAMHB83UfbZim25DZkLX6BR/a9Dd72+5STd1R7sn3 7szpwawbGjAKkUvElLrj3gaUsw1xdVnUyI0L6otKkjc6ckXa9avDE1dPdCkvJM3D8IN6 15/HZ6uvK0N4sxMAr4rt/fsLPS7hIUzKzI1jICxnrAi9OPdzvDWt1i3oCIZLe3HEOsYw czIgGecd1AA4gGAfNO9AJj2PIz9uqb3EyvkbfaiOFvAFExEiqcV4Mrifqy5TUX2WItr1 Q58Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hyperstone.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b17-20020a63cf51000000b0043f06af7736si20340725pgj.306.2022.10.13.04.26.22; Thu, 13 Oct 2022 04:26:36 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hyperstone.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbiJMLQo convert rfc822-to-8bit (ORCPT + 99 others); Thu, 13 Oct 2022 07:16:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbiJMLQm (ORCPT ); Thu, 13 Oct 2022 07:16:42 -0400 Received: from mail5.swissbit.com (mail5.swissbit.com [148.251.244.252]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3B85120044; Thu, 13 Oct 2022 04:16:40 -0700 (PDT) Received: from mail5.swissbit.com (localhost [127.0.0.1]) by DDEI (Postfix) with ESMTP id 906243A1924; Thu, 13 Oct 2022 13:16:38 +0200 (CEST) Received: from mail5.swissbit.com (localhost [127.0.0.1]) by DDEI (Postfix) with ESMTP id 745233A17F5; Thu, 13 Oct 2022 13:16:38 +0200 (CEST) X-TM-AS-ERS: 10.149.2.42-127.5.254.253 X-TM-AS-SMTP: 1.0 ZXguc3dpc3NiaXQuY29t Y2xvZWhsZUBoeXBlcnN0b25lLmNvbQ== X-DDEI-TLS-USAGE: Used Received: from ex.swissbit.com (sbdeex04.sbitdom.lan [10.149.2.42]) by mail5.swissbit.com (Postfix) with ESMTPS; Thu, 13 Oct 2022 13:16:38 +0200 (CEST) Received: from sbdeex04.sbitdom.lan (10.149.2.42) by sbdeex04.sbitdom.lan (10.149.2.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.9; Thu, 13 Oct 2022 13:16:37 +0200 Received: from sbdeex04.sbitdom.lan ([fe80::2047:4968:b5a0:1818]) by sbdeex04.sbitdom.lan ([fe80::2047:4968:b5a0:1818%9]) with mapi id 15.02.1118.009; Thu, 13 Oct 2022 13:16:37 +0200 From: =?iso-8859-1?q?Christian_L=F6hle?= To: Ulf Hansson , Linux MMC List , "linux-kernel@vger.kernel.org" CC: Adrian Hunter Subject: [PATCHv5 1/2] mmc: block: Remove error check of hw_reset on reset Thread-Topic: [PATCHv5 1/2] mmc: block: Remove error check of hw_reset on reset Thread-Index: Adje8+ttHfHV80CJTqaaNKWQWqaf3w== Date: Thu, 13 Oct 2022 11:16:37 +0000 Message-ID: Accept-Language: en-US, de-DE Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.242.2.2] MIME-Version: 1.0 X-TMASE-Version: DDEI-5.1-9.0.1002-27198.007 X-TMASE-Result: 10-0.521300-10.000000 X-TMASE-MatchedRID: dc8Jy61QoRpgljMcj2tyXt5x7RpGJf1a4SkIdSwphgahLh9e7qvSIg2V 4b0zHULvGgn/HW4MjTmKoat5I/Uj/worSvYb1VTuKsurITpSv+M2LwvzxRX0gMC5DTEMxpeQfiq 1gj2xET9dBLSzNqCHg1o4rfBbwEORvvHAd28bGMe5x7uAXGEprfWr7HvOSElar4YC4lUEmf2Ypu G7kpoKR5p6VbtqvFM0+WatSktubmiel3N+gDvB54knvYO5kHScNUSduuqYHDuZtziFUn+D+UzAk Vmkw08mi/rJKndm3e8gE0bHoPl2Aq+/EguYor8cEzQnFLEeMUndB/CxWTRRu/558CedkGIvqcoA hihTwviYPPIGKI9LSplNS0wJuvcSHXU/7YOpZJDHQadHeF1BN7liudJTCnnh X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-TMASE-INERTIA: 0-0;;;; X-TMASE-XGENCLOUD: 836db844-50eb-4e6e-9298-7b44347260d8-0-0-200-0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746571516018882924?= X-GMAIL-MSGID: =?utf-8?q?1746571516018882924?= Before switching back to the right partition in mmc_blk_reset there used to be a check if hw_reset was even supported. This return value was removed, so there is no reason to check. Furthermore ensure part_curr is not falsely set to a valid value on reset or partition switch error. As part of this change the code paths of mmc_blk_reset calls were checked to ensure no commands are issued after a failed mmc_blk_reset directly without going through the block layer. Fixes: fefdd3c91e0a ("mmc: core: Drop superfluous validations in mmc_hw|sw_reset()") Cc: stable@vger.kernel.org Signed-off-by: Christian Loehle Reviewed-by: Adrian Hunter --- -v5: Remove nested if -v4: Only partition switch if necessary and fix one mmc_blk_reset call -v3: Ensure invalid part_curr on error -v2: Do not attempt to switch partitions if reset failed drivers/mmc/core/block.c | 44 ++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index ce89611a136e..0be7ab6ce1c8 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -134,6 +134,7 @@ struct mmc_blk_data { * track of the current selected device partition. */ unsigned int part_curr; +#define MMC_BLK_PART_INVALID UINT_MAX /* Unknown partition active */ int area_type; /* debugfs files (only in main mmc_blk_data) */ @@ -987,33 +988,39 @@ static unsigned int mmc_blk_data_timeout_ms(struct mmc_host *host, return ms; } +/* + * Attempts to reset the card and get back to the requested partition. + * Therefore any error here must result in cancelling the block layer + * request, it must not be reattempted without going through the mmc_blk + * partition sanity checks. + */ static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host, int type) { int err; + struct mmc_blk_data *main_md = dev_get_drvdata(&host->card->dev); if (md->reset_done & type) return -EEXIST; md->reset_done |= type; err = mmc_hw_reset(host->card); + /* + * A successful reset will leave the card in the main partition, but + * upon failure it might not be, so set it to MMC_BLK_PART_INVALID + * in that case. + */ + main_md->part_curr = err ? MMC_BLK_PART_INVALID : main_md->part_type; + if (err) + return err; /* Ensure we switch back to the correct partition */ - if (err) { - struct mmc_blk_data *main_md = - dev_get_drvdata(&host->card->dev); - int part_err; - - main_md->part_curr = main_md->part_type; - part_err = mmc_blk_part_switch(host->card, md->part_type); - if (part_err) { - /* - * We have failed to get back into the correct - * partition, so we need to abort the whole request. - */ - return -ENODEV; - } - } - return err; + if (mmc_blk_part_switch(host->card, md->part_type)) + /* + * We have failed to get back into the correct + * partition, so we need to abort the whole request. + */ + return -ENODEV; + return 0; } static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type) @@ -1867,8 +1874,9 @@ static void mmc_blk_mq_rw_recovery(struct mmc_queue *mq, struct request *req) return; /* Reset before last retry */ - if (mqrq->retries + 1 == MMC_MAX_RETRIES) - mmc_blk_reset(md, card->host, type); + if (mqrq->retries + 1 == MMC_MAX_RETRIES && + mmc_blk_reset(md, card->host, type)) + return; /* Command errors fail fast, so use all MMC_MAX_RETRIES */ if (brq->sbc.error || brq->cmd.error)