Received: by 10.223.185.116 with SMTP id b49csp2384578wrg; Mon, 5 Mar 2018 01:47:40 -0800 (PST) X-Google-Smtp-Source: AG47ELsXGv01Qw45jLOLXZIPRF28Zp+XwZjC9jnjPm5mpohkR+TKN48NFeA9MAYup8/F5xyquKcf X-Received: by 2002:a17:902:9306:: with SMTP id bc6-v6mr2435077plb.133.1520243260231; Mon, 05 Mar 2018 01:47:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520243260; cv=none; d=google.com; s=arc-20160816; b=k5b5jKaGMgqtDGOP9ZFpMUUavizpJlU9Z1/9SlRUwJkIffx/p/MDJAelSGrS/Neh8V /ydCnfXrWOnOwO66yOr3bpVJqwK7Upj5wbv9FRmOKWe5ai6kwSwr0aL3lCS+fQOmBBIC EXQieTCxQL6eKTDVTEe2Vic+BmfexFHZsoQPcOVgLckKXSqFAw8Z1zLoI8S2b4HSlUvo XwpI3i0QyK/9HyTzCZXfXppRglRRVY/dmMekI1tLFz6kZgsDwdHBHbLEvMWcFY8b0bIi xxmv5ONkCYssX9Wn/ugP0n8uvxF//kS1Ai7/E302GTlE1Tocu9aGHrb8oz9o19bDz8pV r3Yg== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=09qa1dlQyHYOubsApxhvfpqKXe54WBOYr62wSb3GNI8=; b=Ux1cDZfU+5nDFF8Fs/zjxphTe7vKcWmeZTBzSXb8k6A+CELHRbzHM+C4hqBYh1GOhN D1UfbkUMvFQBOnctJGQrk2xi4DkGwI77sh98Hr99w36I6pO+ELBS3gpPBmglP1o6zzTC mtgeSBXCkY57GBitJbYH8zRWS5sGjdUuHVu8+rDoVs5dnBFjaHGi2I9Oa78wlWjpk/Bj YBbySA8G5wk4VOUjat3tgxxC8wy4OpK9RMwOBKzKUv8VIQ6EZOaWgVESLrlEZT9hmPlY ZNdNoA6eb8d2fINlXbF/o5YEoGSRaYZELVO4FGoMjTK7r+PbK5WN+5FvMkm/jZalgaM3 djCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KtQ8T27p; 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 p75si9939113pfi.293.2018.03.05.01.47.26; Mon, 05 Mar 2018 01:47:40 -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=KtQ8T27p; 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 S933408AbeCEIq1 (ORCPT + 99 others); Mon, 5 Mar 2018 03:46:27 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:43506 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933252AbeCEIqL (ORCPT ); Mon, 5 Mar 2018 03:46:11 -0500 Received: by mail-io0-f193.google.com with SMTP id l12so17072430ioc.10 for ; Mon, 05 Mar 2018 00:46:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=09qa1dlQyHYOubsApxhvfpqKXe54WBOYr62wSb3GNI8=; b=KtQ8T27pIWkrX7HO2YqdeU/zVCDkmU9xbCh2RCLteEEZbamSfIHimTQVIzG4WtP7AH pcArJAjcMFjrS8Cg1RWsRyzi/MfsBsiPidHZ2kos2BJvJpWD0dS5KoV7lrRLuMTbfa0Q 2+Mn3ItPuyPWaGDXBbL7hUt1i1OtFI7H6WAjE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=09qa1dlQyHYOubsApxhvfpqKXe54WBOYr62wSb3GNI8=; b=W7cMSFOzfwt2TghTv8Of5noMhVNSkRBiTvypx2j4LlVEMWZ0e5RJRDm4mAStrSawcV auu3RZDnvvp23iakYnzM3l1UmulYF4wcoVD/dvUILVhMkCWO/01xgmBxW6HjNQVbGN7p apw0+yQxWOz4C9Hr/MkbwRJLC9zRrVSsG2WjexruFSLR+2YaZ3ofdtWwij4GeutAQJ4w Hrko1T5P70U+dKNawQ0wwtFdTROns9OIAw3aOZVMq2aLWkpZVb7ICDjjEgB3v2a/F9NW DVdl+r01oJcIjBzgKvPIs+KpVJwdrbfcXyCEUQ8kRL9UBBUfOsMRsGoZB1pz/5MI4+uF yhOg== X-Gm-Message-State: AElRT7EEPm8AdS43+vck80ztSG2nps1Qcp2Zv1YeWVTG0knpSG+rYKej JgXSRlvDvBLdKbCOQ14GH7KSc/ZzNzg8x98oDDQp0w== X-Received: by 10.107.104.1 with SMTP id d1mr16151476ioc.119.1520239570269; Mon, 05 Mar 2018 00:46:10 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.91.10 with HTTP; Mon, 5 Mar 2018 00:46:09 -0800 (PST) In-Reply-To: <20180228115318.20154-1-Evgeniy.Didin@synopsys.com> References: <20180228115318.20154-1-Evgeniy.Didin@synopsys.com> From: Ulf Hansson Date: Mon, 5 Mar 2018 09:46:09 +0100 Message-ID: Subject: Re: [PATCH v4] mmc: dw_mmc: Fix the DTO/CTO timeout overflow calculation for 32-bit systems To: Evgeniy Didin Cc: "linux-mmc@vger.kernel.org" , Alexey Brodkin , Eugeniy Paltsev , Douglas Anderson , Andy Shevchenko , Jisheng Zhang , Shawn Lin , Vineet Gupta , Linux Kernel Mailing List , linux-snps-arc@lists.infradead.org, "# 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 28 February 2018 at 12:53, Evgeniy Didin wrote: > In commit 9d9491a7da2a ("mmc: dw_mmc: Fix the DTO timeout calculation") and > commit 4c2357f57dd5 ("mmc: dw_mmc: Fix the CTO timeout calculation") > have been made changes which cause multiply overflow for 32-bit systems. > The broken timeout calculations leads to unexpected ETIMEDOUT errors and > causes stacktrace splat (such as below) during normal data exchange > with SD-card. > > | Running : 4M-check-reassembly-tcp-cmykw2-rotatew2.out -v0 -w1 > | - Info: Finished target initialization. > | mmcblk0: error -110 transferring data, sector 320544, nr 2048, cmd response > | 0x900, card status 0x0 > > DIV_ROUND_UP_ULL helps to escape usage of __udivdi3() from libgcc and so > code gets compiled on all 32-bit platforms as opposed to usage > of DIV_ROUND_UP when we may only compile stuff on a very few arches. > > Lets cast this multiply to u64 type which prevents overflow. > > Tested-by: Vineet Gupta > Reported-by: Vineet Gupta # ARC STAR 9001306872 HSDK, sdio: board crashes when copying big files > Fixes: 9d9491a7da2a ("mmc: dw_mmc: Fix the DTO timeout calculation") > Fixes: 4c2357f57dd5 ("mmc: dw_mmc: Fix the CTO timeout calculation") > > Signed-off-by: Evgeniy Didin > > CC: Alexey Brodkin > CC: Eugeniy Paltsev > CC: Douglas Anderson > CC: Ulf Hansson > CC: Andy Shevchenko > CC: Jisheng Zhang > CC: Shawn Lin > CC: Vineet Gupta > CC: linux-kernel@vger.kernel.org > CC: linux-snps-arc@lists.infradead.org > Cc: Thanks, applied for fixes! I took the liberty to remove this cc-list and did some additional minor cleanups of the change log. Kind regards Uffe > --- > Changes since v3: > -Switch DIV_ROUND_UP macro to DIV_ROUND_UP_ULL > -Make one patch from two patches > -Modify commit message > > Changes sinve v2: > -add fix for cto_ms > > Changes since v1: > -uint64_t switched to u64 > > drivers/mmc/host/dw_mmc.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c > index 0aa39975f33b..cba534d4c81b 100644 > --- a/drivers/mmc/host/dw_mmc.c > +++ b/drivers/mmc/host/dw_mmc.c > @@ -409,7 +409,9 @@ static inline void dw_mci_set_cto(struct dw_mci *host) > cto_div = (mci_readl(host, CLKDIV) & 0xff) * 2; > if (cto_div == 0) > cto_div = 1; > - cto_ms = DIV_ROUND_UP(MSEC_PER_SEC * cto_clks * cto_div, host->bus_hz); > + > + cto_ms = DIV_ROUND_UP_ULL((u64)MSEC_PER_SEC * cto_clks * cto_div, > + host->bus_hz); > > /* add a bit spare time */ > cto_ms += 10; > @@ -1944,8 +1946,9 @@ static void dw_mci_set_drto(struct dw_mci *host) > drto_div = (mci_readl(host, CLKDIV) & 0xff) * 2; > if (drto_div == 0) > drto_div = 1; > - drto_ms = DIV_ROUND_UP(MSEC_PER_SEC * drto_clks * drto_div, > - host->bus_hz); > + > + drto_ms = DIV_ROUND_UP_ULL((u64)MSEC_PER_SEC * drto_clks * drto_div, > + host->bus_hz); > > /* add a bit spare time */ > drto_ms += 10; > -- > 2.11.0 >