Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10100580imu; Wed, 5 Dec 2018 16:18:57 -0800 (PST) X-Google-Smtp-Source: AFSGD/XCxRGFFqoz11xeFNyI0LH9zTv0ZXLDET/1HhB364iHLCeLGsciwH+IdQcEV8wexMyANEch X-Received: by 2002:a17:902:1102:: with SMTP id d2mr22030166pla.138.1544055537707; Wed, 05 Dec 2018 16:18:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544055537; cv=none; d=google.com; s=arc-20160816; b=fTogUsmJ2UDLjEUM6cI/UugaXdBVwcXaT3latsUjNWi9gZUsFtJrKFwyYy7+LSqxsX 3SOouriKauvyrT5bHh8plK3Sb2L9Qm/wkF5YnX5KwZ5RNEMNx6Jq+GenPtecCX3+yaAC qJ+aiehRXeonFtuD879vSq1mQ+gZayIIPHaXnColRXZtYhdp7IQ+HGzGJcDBFp7sd54+ NJrL7g9s+NyXpONktJVjy3UKlpVF3sg7CQ8hpfzaNLIaxBPBuHtRL4ZCixQSzlvfyP5x MIReBveRvLSCKReLBCLFpNuZvf28Q0ZrYf5K+KaqFPG3XSlKf3IXJgRqkD6vyTKqolzp 0EVA== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=dSnhgQpv7WbrQICEbxckUbIEfJTM7aldueOvPHmHJws=; b=0QpnyAKH+I4CL1oCFA/yKhN+Nqb6s1g+bhCxPmttrc01qqzBjFa4ei5XZNw0CmoIg7 VTwVkoy5kxZZvEpashuf9R0cI7J2ZTyMHOx8Usp87fwXzlCCT/mFvSpuZa06ShwuZeUu ShMI+0Y3A9i+MsdZbM+XC6LcWpkpjD39etTd0YgMwjB6dracGrBfpg8GUyY6Fs6bknvm 8jJfV2ykgZPvlczBCRMXM1ZkCk1yPWBVIE201dG7LH3xUeKusVKxgRPTwcnvRtUzvntg Y4tInpEOKk4b0SjF1e39uIrmAXOZxT72hluOIr3R81fRPa2TVuE10Jd8O4Yd8GthPC2b hKgQ== 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 1si23088156plb.103.2018.12.05.16.18.36; Wed, 05 Dec 2018 16:18:57 -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 S1728702AbeLEXdV convert rfc822-to-8bit (ORCPT + 99 others); Wed, 5 Dec 2018 18:33:21 -0500 Received: from mga03.intel.com ([134.134.136.65]:31561 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727592AbeLEXdV (ORCPT ); Wed, 5 Dec 2018 18:33:21 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Dec 2018 15:33:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,320,1539673200"; d="scan'208,223";a="107322007" Received: from xdu1-desk.sh.intel.com (HELO xdu1-desk) ([10.239.154.142]) by fmsmga008.fm.intel.com with ESMTP; 05 Dec 2018 15:33:19 -0800 Date: Thu, 6 Dec 2018 07:33:18 +0800 From: "Du, Alek" To: Ulf Hansson Cc: Adrian Hunter , "linux-mmc@vger.kernel.org" , Linux Kernel Mailing List Subject: [PATCH V3 rebase] mmc: sdhci: fix the timeout check window for clock and reset Message-ID: <20181206073318.049065a8@xdu1-desk> In-Reply-To: References: <20181130150028.732896d8@xdu1-mobl> <81ba3745-8277-d16e-3aad-48324f51dc8a@intel.com> <20181130221300.4ef2956c@xdu1-mobl> <20181201134251.26573207@xdu1-mobl> <20181204090120.63b5f0a4@xdu1-mobl> <229dc468-1155-b81f-9fda-b71402387e3f@intel.com> <20181205111450.300e0478@xdu1-mobl> Organization: Intel X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From a081e783383adf1179c71bc37b4e199d087af643 Mon Sep 17 00:00:00 2001 From: Alek Du Date: Fri, 30 Nov 2018 14:02:28 +0800 Subject: [PATCH] mmc: sdhci: fix the timeout check window for clock and reset 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