Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10469080imu; Thu, 6 Dec 2018 01:26:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/XzW6ivtd6f2dgoAQ/srZ1Mq8BBDsEBZ7jybXVQSt4AKnxPReCcCMO+YRaAylAnqeV4QjD+ X-Received: by 2002:a62:3811:: with SMTP id f17mr28295626pfa.206.1544088396763; Thu, 06 Dec 2018 01:26:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544088396; cv=none; d=google.com; s=arc-20160816; b=fWj5zb6ZLilhE3Dy7r+pLW5G9tLgpBPf4U8a8Rdiy6C+120Yywrow49lJnYNIaZI8A r7WSnPFkNfQJv+YJqzt+p76SSBsD6W9j+wu6jY014d6bAqZNqD/A9nlLV19xTDBe+pbs sakGOh4w+H7S8OVKJ1NZYpGLOhGp6pmShQFg4+thLPlsJ0TDMQ5CSfdlCMMF9EdmRWa9 n0BDPyaLhtv14PAlIjLpyonEiReBU+iWJDFtBWSPgYnh5w542wLKzoq1TOgdRLRr7sJp eHs8KujZUlhRlYmW3nJoSIbK1mlIc59qfVPDw9m4MiPQ3waQD6denOV+N8dPaa/xWy3E /L7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=S7fGJaIkq5mAc95wwnaWHesXoUygKSbgDN1zGsAF9Qw=; b=wcemFz3BM0pBbmliL8ca0J57z+hrwEdZA0UIh8MpAoH+InQxvmjiT1D6y3F9Sgwr3s kMID0QIJ0sYQY93CH7g73q/ECJz/uUwtcHRxgt5t30ukBGeBFkSMMou/ekpWb7aqQHiL MB0MP3edksT0J8y+gDnMpdZMWyOBEdwSvxhnViUZie7hRoiEXjFGSvr4EYTRuCkjIUe7 sCxhzodglfgSS1qlDBao6WU0tMUXaAtFDXpKdEy/wlAG0b7muzy04HWu3a7zJTjwKgwW zWqlL5Pj8H57aQEZIEFMHLn7t1qMZIagTVMr+8iPuim5ypRUUagRpHKH7193Lcv72A2z JZVg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3si20423929pgm.441.2018.12.06.01.26.21; Thu, 06 Dec 2018 01:26:36 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729403AbeLFJZV (ORCPT + 99 others); Thu, 6 Dec 2018 04:25:21 -0500 Received: from mga01.intel.com ([192.55.52.88]:51071 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728250AbeLFJZU (ORCPT ); Thu, 6 Dec 2018 04:25:20 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Dec 2018 01:25:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,321,1539673200"; d="scan'208";a="116484582" Received: from xdu1-desk.sh.intel.com ([10.239.154.142]) by FMSMGA003.fm.intel.com with ESMTP; 06 Dec 2018 01:25:19 -0800 From: alek.du@intel.com To: ulf.hansson@linaro.org Cc: adrian.hunter@intel.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Alek Du , stable@vger.kernel.org Subject: [PATCH] mmc: sdhci: fix the timeout check window for clock and reset Date: Thu, 6 Dec 2018 17:24:59 +0800 Message-Id: <20181206092459.26202-1-alek.du@intel.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alek Du 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 --- drivers/mmc/host/sdhci.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 99bdae53fa2e..451b08a818a9 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -216,8 +216,12 @@ void sdhci_reset(struct sdhci_host *host, u8 mask) 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); @@ -1608,9 +1612,13 @@ void sdhci_enable_clk(struct sdhci_host *host, u16 clk) /* 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); -- 2.17.1