From patchwork Thu Oct 13 17:52:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 2129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp404492wrs; Thu, 13 Oct 2022 10:55:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7hNpSNa1mxnl94bOzCaz5WFVcs6lQ1A7hXDdDr7mMSdmlpCYJrzUEpmXG/5CGzooxzDi8N X-Received: by 2002:a65:464b:0:b0:42c:b0:9643 with SMTP id k11-20020a65464b000000b0042c00b09643mr974870pgr.232.1665683711841; Thu, 13 Oct 2022 10:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665683711; cv=none; d=google.com; s=arc-20160816; b=XXqhbCOkjGGQdllnPzfdiV0vJe78RwBIK9VJyj/o5UYo1wxJiNcf1vJOxZPUGFzW3T zJbijROIraMWJIx8mFmqP/ehNPuMOStgC3mZJkITzwY4Q9zmZ+PsswuAEpV4yM0W1pGZ sY9xxO3DMpqVf8Gq6gGfsIud6CN+1R5H31Y2IVvOmBnlp94kVMPXoaVg1cyDgNSJp9mV o2D7HnSVQQLf2yJwpwcka1qpcCA+2cYQFBK4HwBDMs9NZN9B7IoBNkrjceyUWJ7ar11s /8hqxGXvHie3ePl0gyENJtHn8WXAYwuREIMhkX5dXilhkUmSPxCLaAiTQq2Uj8QaSFKI UVnA== 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=vSusF7UnJuHJsuuhn7rfJAHkaMmD4CX9OqeBVv90ZvE=; b=0bm5cKRDFoLqP1jDRUJmFz3r8YcUoEYBh4A2hLg0MSoPeDjCNgKPcpuEM+/S3lCPjd ntX0EdVNcOTSW2xmhweaPgdvakB1tgVF4iL61nCpa7Il+iASAvSW7QtS4Rmb0E4WzhDs GHvx8Sct4iymFN+3JHqd/GibBZbmi7Z25ZHkAihhvt7Xq0/f99MO2ZPmU6MlO7RHoEdh eyQaW0BrtcxjfiCaOe8x62t7CMun5EUxGq/EgqQtbZ4xN6ZhmFA9mfDVZUqqv+KCt078 P4jVt3TArgmBu8KSeKZ437ESqZTiwMM1a2i8dJaiSpwFeEiUg1aMbiJ+QoUa9BapvjkE dYXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IbhuCf5O; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e66-20020a636945000000b0041dfe50f675si23186113pgc.634.2022.10.13.10.54.59; Thu, 13 Oct 2022 10:55:11 -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=IbhuCf5O; 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 S230019AbiJMRyg (ORCPT + 99 others); Thu, 13 Oct 2022 13:54:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229916AbiJMRxx (ORCPT ); Thu, 13 Oct 2022 13:53:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87236152029; Thu, 13 Oct 2022 10:53:25 -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 9BC8DB82026; Thu, 13 Oct 2022 17:53:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14516C433D7; Thu, 13 Oct 2022 17:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683602; bh=beHM6p8L43oHqLXfN/3Q+tAnkkBD31uvAhb+FMk75Sw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IbhuCf5O48Ts04StuFvclg516afriUPHgBLa2sIrpWscDXUz9DlAp5qYT2+OU0dbM 6eyQhSnXLeOSb4qpok/ZzQf85MiIqWZ+GzjSyw4ohL18ctLNS/c+TBOK9alliLcJbj pRWsDs5tODs1yFTEHMIsGaYCuY8z5C2wafIRauxA= 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 5.4 16/38] mmc: core: Terminate infinite loop in SD-UHS voltage switch Date: Thu, 13 Oct 2022 19:52:17 +0200 Message-Id: <20221013175144.817058806@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175144.245431424@linuxfoundation.org> References: <20221013175144.245431424@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746595963735671720?= X-GMAIL-MSGID: =?utf-8?q?1746595963735671720?= 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 @@ -799,7 +799,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--;