Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10519287imu; Thu, 6 Dec 2018 02:29:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/ViWWZ0+WlwXJJON+Ock9GeodTTXA7QqWKg3WT3wbYUFcLFlq+G9A8SyDoQLP6bTPkazXxP X-Received: by 2002:a17:902:96a:: with SMTP id 97mr26905741plm.45.1544092187680; Thu, 06 Dec 2018 02:29:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544092187; cv=none; d=google.com; s=arc-20160816; b=RMWMkKvgYoPcLwRdfJ2McO/P3lR/DOAQnn/clumS6rwKmR8UjCOiGpHRlbwmVE/lLI L/D8PfoNkl1v5xFc7tpIQZZY551FN9ZmcQlw8X0nZlMjYMfSm4CaGe/R+ttWWsthVCrk Ih7xSm2IUCpGgvVnDg09puGQNtsl63GmNrYgRNW263abbxoa0J6YK+G9pmXTwWcPfeoD M4ESV7aY8yNxePhnLXH5xZtLUseCugiHVkZvGURuKc/N3jrUZ2d/QXeoheoPpD7FsM7J luoIUmJXQ1bKmeNMe/npOi/590LnR1Gb5Hs4VfIv+w8bUfeeHjexHMhCtKMPXk08z3h6 THpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=uiZbs/IWyJmPT+sDvCny8fkscFvsHrRENfmDgBKbIiQ=; b=nCoKaFs63sdVzuVXghtdFmH6EabfWg8imf4QVGHGSBpxVMkpG4Rp/YTaUM3hY2a3dv m1mPQnDqOshzmkwkNqZ2lpu0vN8dHXiNRcnPmbv4xuzuTES4yAgPFsK/Ev3QGJACHKes 5VSLQpdz2B/1UHh07bH9E7CxiNV1ZZ/U/uhXODp1xZ6TcZtCXK04fxOaX2HZTzs/ibeF OvxT1Ah/jOqDUIFGI9e9XB4qDV4aXmgCba4UyZ6SmnV/GODVMkUHQngor9K77Pt+maGU +X1p8aLKCXxyTRH6LaAnpEyN9Je38GdCpDawRM5Km4FBY3tHPnjXUVS5883wpbFLSokw Lu3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bYYBy2rl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f186si23870828pfb.67.2018.12.06.02.29.32; Thu, 06 Dec 2018 02:29:47 -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=@linaro.org header.s=google header.b=bYYBy2rl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729435AbeLFK1c (ORCPT + 99 others); Thu, 6 Dec 2018 05:27:32 -0500 Received: from mail-vs1-f66.google.com ([209.85.217.66]:43913 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729410AbeLFK1c (ORCPT ); Thu, 6 Dec 2018 05:27:32 -0500 Received: by mail-vs1-f66.google.com with SMTP id x1so13940271vsc.10 for ; Thu, 06 Dec 2018 02:27:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uiZbs/IWyJmPT+sDvCny8fkscFvsHrRENfmDgBKbIiQ=; b=bYYBy2rlDwrimwH6KDutik+LW6SYbPhHr2f/V8NeUcpIlcRB8NvwUo+aStV4N0rkAZ Z0lXL9g9MemCTSPo6uM0mR/7tI2aMP4qGsIAmxNhbvLvLWzzhYRG4fiWPfts7HIB1XA2 uGNsq17oY3mGXUFO7m50RCmnku3ZbXF9pfL+w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uiZbs/IWyJmPT+sDvCny8fkscFvsHrRENfmDgBKbIiQ=; b=jUGH46eIntiDet/RStjfJh7+lLevKGwP0e6XBZGtuVpKFM6VPNk7KwYoiNrlXeK5WN +FjFAMBXDmWNwOdlPGjccOlp+YgnA+SCIhmAeCIiGc816aP+co1/2GNiGy8aGZwYWX1X CnC79OGlpdpmGisPoUwghWWw2TL6Vp4FdOLtZOw+oICOPECos0IjaStTtgVgI5ohj+Za TBM6Y9ApvgMLB2k89MFd4oHzYoIVpjUw91khBdPJL6yw6ILdnrMrwXFY1qYn22sg7Duw IUUL+hvNg9QA08qou+xM4mQ19XCNOprXh2Fi+/cJ/SvcSTsWVkGfHsDjZ8IEt/F9RgFO PY9g== X-Gm-Message-State: AA+aEWZCb51uhyxDnHKlFk38NmJKlrvoEsXauyQy7xRpIlp9aHuIA7SM WSECFG7kDAeW24KMd80t4649FJ1e2DEONKLDxFeoJQ== X-Received: by 2002:a67:7685:: with SMTP id r127mr12304642vsc.35.1544092050476; Thu, 06 Dec 2018 02:27:30 -0800 (PST) MIME-Version: 1.0 References: <20181206092459.26202-1-alek.du@intel.com> In-Reply-To: <20181206092459.26202-1-alek.du@intel.com> From: Ulf Hansson Date: Thu, 6 Dec 2018 11:26:54 +0100 Message-ID: Subject: Re: [PATCH] mmc: sdhci: fix the timeout check window for clock and reset To: alek.du@intel.com Cc: Adrian Hunter , "linux-mmc@vger.kernel.org" , Linux Kernel Mailing List , "# 4.0+" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 6 Dec 2018 at 10:25, wrote: > > 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 Yes, now it works better! Applied for fixes and by adding Adrian's ack, thanks! Kind regards Uffe > --- > 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 >