Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7360008rwi; Mon, 24 Oct 2022 13:31:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5aAECyg802x0JGjUqJ57lPtSbY6L8TMi5F1vcaPWbmgsO19gyg60jqxYqImV0nYdue7lvJ X-Received: by 2002:a17:907:74a:b0:77e:9455:b4e3 with SMTP id xc10-20020a170907074a00b0077e9455b4e3mr29748221ejb.471.1666643463646; Mon, 24 Oct 2022 13:31:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666643463; cv=none; d=google.com; s=arc-20160816; b=mR3m8lrfXAB3cd3RLLihO02Gk0U+2QLoI8pGJljaN4/mBxxcOH43+iblf2kHL2Vr52 g9xdbrY3y9HBFs2oXhGh3Lgrk9rvCS59toR6f3qmR2V7L0WzfCT7FINTG6P5c5R6SEdl 1CLhGDWEcWymh19JvYGKpQjQTwyrrcY9M92SErFwrciFT8xeCQUJTKrDJ7k7IqPLw0gK FaiSfFyx2H5JHbExTH+D7VGA9X4YnSB8Z5iZOw1tm3xTDk4NFctC1yR73/LGvgCytSlb WzENfxemzRpFPBbAZF1RMWqu8rc6L3X2cj1vEZGSU1PZhZuP060n7JTCUDtOseviEbaL Or4A== 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=uxyJr9lsdoPWP5cf3oL4fX1m3W/ZP2SpkHYLR2qjw2w=; b=WZLLBvmUDwQ4abfdU03KIhNeuKPrLxe/0JXBJ6ULfa8eGlVA14rNZy+aLLtruE8ptd E9Wk/KtXhyWAyVGL3yQj2Kb34W/bdkQtiYFDZbnlj6clg5/+J5SbUlMroyWIdgtK4iSj RQrJi4T98Q0OPL8K/RAPX9SzJ0vnOXMSBQk+g0JPZzBg58M/4FXukPqNfOW8PwzLGHFa FFJI0uIKcS/DwxSafreHZbGrgAS+I+DYL25DBLIAsSgw9dEYRAHNE3Jza9G5HyAI2BaY DmeFXwDEFxjTvotkWvGTxlUEAMHxPDFRWypwHK2WTrBOt/KbD1W2V1tWqwMmi6lJJHSM eCkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wXBp99J/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020aa7ce0b000000b00461f1c61f1esi623060edv.386.2022.10.24.13.30.38; Mon, 24 Oct 2022 13:31:03 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wXBp99J/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233666AbiJXTwL (ORCPT + 99 others); Mon, 24 Oct 2022 15:52:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233459AbiJXTvc (ORCPT ); Mon, 24 Oct 2022 15:51:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98C3D68CF7; Mon, 24 Oct 2022 11:17:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 32284B8113E; Mon, 24 Oct 2022 11:47:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 881ACC433D6; Mon, 24 Oct 2022 11:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612048; bh=fmEfxgR2XiP4itflL2YB4yqVWS0agT7IBfMJR4Hzlro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wXBp99J/8X/ESOp/53QuKkxEWT63+P/1JDW0kUOOdYMCfHla9NGlsgSJtR3GxTXzR r3rRRfZNpF8SwcXsc/dmobXkXO2032Pl5mXvzhHPVRzsuU8Sz9N8XpsfYxrOSiX5/+ 1V4z4LCPVo7OreDJkRiRcuznMKOyfgRMmRYoQtCY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Norris , Guenter Roeck , Ulf Hansson Subject: [PATCH 4.14 033/210] mmc: core: Terminate infinite loop in SD-UHS voltage switch Date: Mon, 24 Oct 2022 13:29:10 +0200 Message-Id: <20221024112958.037368570@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Brian Norris commit e9233917a7e53980664efbc565888163c0a33c3f upstream. This loop intends to retry a max of 10 times, with some implicit termination based on the SD_{R,}OCR_S18A bit. Unfortunately, the termination condition depends on the value reported by the SD card (*rocr), which may or may not correctly reflect what we asked it to do. Needless to say, it's not wise to rely on the card doing what we expect; we should at least terminate the loop regardless. So, check both the input and output values, so we ensure we will terminate regardless of the SD card behavior. Note that SDIO learned a similar retry loop in commit 0797e5f1453b ("mmc: core: Fixup signal voltage switch"), but that used the 'ocr' result, and so the current pre-terminating condition looks like: rocr & ocr & R4_18V_PRESENT (i.e., it doesn't have the same bug.) This addresses a number of crash reports seen on ChromeOS that look like the following: ... // lots of repeated: ... <4>[13142.846061] mmc1: Skipping voltage switch <4>[13143.406087] mmc1: Skipping voltage switch <4>[13143.964724] mmc1: Skipping voltage switch <4>[13144.526089] mmc1: Skipping voltage switch <4>[13145.086088] mmc1: Skipping voltage switch <4>[13145.645941] mmc1: Skipping voltage switch <3>[13146.153969] INFO: task halt:30352 blocked for more than 122 seconds. ... Fixes: f2119df6b764 ("mmc: sd: add support for signal voltage switch procedure") Cc: Signed-off-by: Brian Norris Reviewed-by: Guenter Roeck Link: https://lore.kernel.org/r/20220914014010.2076169-1-briannorris@chromium.org Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/sd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -793,7 +793,8 @@ try_again: * the CCS bit is set as well. We deliberately deviate from the spec in * regards to this, which allows UHS-I to be supported for SDSC cards. */ - if (!mmc_host_is_spi(host) && rocr && (*rocr & SD_ROCR_S18A)) { + if (!mmc_host_is_spi(host) && (ocr & SD_OCR_S18R) && + rocr && (*rocr & SD_ROCR_S18A)) { err = mmc_set_uhs_voltage(host, pocr); if (err == -EAGAIN) { retries--;