Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4162416imu; Tue, 18 Dec 2018 10:01:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/WZaCMgmGAMCPkOsmjiwwcQoi1LbNaBgCHBtyiWMYqBOcUV4Y/XKp7ZnqLnwNrKYP0hNu71 X-Received: by 2002:a17:902:9a41:: with SMTP id x1mr17133203plv.126.1545156102888; Tue, 18 Dec 2018 10:01:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545156102; cv=none; d=google.com; s=arc-20160816; b=EtgEH9qtVOnrEq+FyJTpf7FhhKy3UTQzHe9oiaSwn+TnrHooj8mXUM4dg7ZSib+tYC LHu9zO0ledu7Fdgy7WmMn+7DiQCqVEKjwMr5O7zVpvcwhEw3sB7h6YNp7tOEG5NtpOf1 QMtCrMoCzYExsOjYt+SJYkwVKGowX6Q8DQcTSR5xLZ7GiNH+19ZRe9Ti37yoHHTbX1WY 9KLthtBVJE5dAQxbiG0DvJtSt8n2i4NqCJqSjovf3jJ6tc801biScQdFPphaqYPBnYGW uU1JuJ4OrOUNGr56zjVrtcMLbuqVbqTImeZi7D5Xf6Gd76li2pYRKloM1oom3s3iXjQz 3Zeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D3+Af8gEdgvCkkV5DzVqtK/9TManvsIf5Qp8ShwRUqE=; b=B7A5t3K8FH8OjGYF3SliLsXsxn9xHh+nRjFT2nKUSHgiaL/WNzzHqkxyncF4zI3w15 fCeeQOUZcwsjU4/Tv3D5tIppJ6p4BH53qmM4kBOYCcsQ9lq9zrRjK0lLwBNfSQ8vnjS/ r6nMCtVxl1frbZKbw2YzkZDgfF8mZEK9NCWF8HXMpBbIihGbOn6s7NLinYhsq7VQThq9 drH8Kb1GWm4VJ39rZFWhMczqJXeE4pqJK+O7T2WUOHZ8NbvtK7OOhFc6YQnmqhcApRSf ZjJfxEPLR2pqFAIoVIlmGDJtp3tLDaTKZYuuvwXgTL+WduVdOrzrYSmQdNwbp76Ig5qe /2Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mYDJqJhS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s8si13195314plq.345.2018.12.18.10.01.27; Tue, 18 Dec 2018 10:01:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mYDJqJhS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727304AbeLRQkg (ORCPT + 99 others); Tue, 18 Dec 2018 11:40:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:37696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727153AbeLRQkf (ORCPT ); Tue, 18 Dec 2018 11:40:35 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B0387218A5; Tue, 18 Dec 2018 16:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545151234; bh=40HQvD5gtbJ5c7qycQ2+xgh0rBixMUc+dX842omhrrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mYDJqJhSOg6walClAGmcwERfp0QM8o9dBy4tW8CMv2gTYvoYY8YtMKxPYxeOauieq B+o1qOucQnxO71kTq56WjdE6mvA1fslZwPdCRXYGdGjKZA7HyOXfoiXqNIBvYG+bAn 0F2XHO/Ug2VGdDiE0+jpnx3wBcLhjjymyIofaNcc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alek Du , Adrian Hunter , Ulf Hansson Subject: [PATCH 4.19 20/44] mmc: sdhci: fix the timeout check window for clock and reset Date: Tue, 18 Dec 2018 17:39:32 +0100 Message-Id: <20181218163929.871016709@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181218163927.119623235@linuxfoundation.org> References: <20181218163927.119623235@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alek Du commit b704441e38f645dcfba1348ca3cc1ba43d1a9f31 upstream. We observed some premature timeouts on a virtualization platform, the log is like this: case 1: [159525.255629] mmc1: Internal clock never stabilised. [159525.255818] mmc1: sdhci: ============ SDHCI REGISTER DUMP =========== [159525.256049] mmc1: sdhci: Sys addr: 0x00000000 | Version: 0x00001002 ... [159525.257205] mmc1: sdhci: Wake-up: 0x00000000 | Clock: 0x0000fa03 >From the clock control register dump, we are pretty sure the clock was stablized. case 2: [ 914.550127] mmc1: Reset 0x2 never completed. [ 914.550321] mmc1: sdhci: ============ SDHCI REGISTER DUMP =========== [ 914.550608] mmc1: sdhci: Sys addr: 0x00000010 | Version: 0x00001002 After checking the sdhci code, we found the timeout check actually has a little window that the CPU can be scheduled out and when it comes back, the original time set or check is not valid. Fixes: 5a436cc0af62 ("mmc: sdhci: Optimize delay loops") Cc: stable@vger.kernel.org # v4.12+ Signed-off-by: Alek Du Acked-by: Adrian Hunter Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/host/sdhci.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -193,8 +193,12 @@ void sdhci_reset(struct sdhci_host *host timeout = ktime_add_ms(ktime_get(), 100); /* hw clears the bit when it's done */ - while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) { - if (ktime_after(ktime_get(), timeout)) { + while (1) { + bool timedout = ktime_after(ktime_get(), timeout); + + if (!(sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask)) + break; + if (timedout) { pr_err("%s: Reset 0x%x never completed.\n", mmc_hostname(host->mmc), (int)mask); sdhci_dumpregs(host); @@ -1495,9 +1499,13 @@ void sdhci_enable_clk(struct sdhci_host /* Wait max 20 ms */ timeout = ktime_add_ms(ktime_get(), 20); - while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL)) - & SDHCI_CLOCK_INT_STABLE)) { - if (ktime_after(ktime_get(), timeout)) { + while (1) { + bool timedout = ktime_after(ktime_get(), timeout); + + clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); + if (clk & SDHCI_CLOCK_INT_STABLE) + break; + if (timedout) { pr_err("%s: Internal clock never stabilised.\n", mmc_hostname(host->mmc)); sdhci_dumpregs(host);