Received: by 10.223.185.116 with SMTP id b49csp6436442wrg; Wed, 28 Feb 2018 09:21:34 -0800 (PST) X-Google-Smtp-Source: AH8x224/rS2huIavMG0eQGnhjhFv0fwPSs1xrrFd7e0EiNeIhW7CJpvIoqqG1f/YHRBVgO6ibEsd X-Received: by 2002:a17:902:8214:: with SMTP id x20-v6mr18483341pln.182.1519838494512; Wed, 28 Feb 2018 09:21:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519838494; cv=none; d=google.com; s=arc-20160816; b=1E21f3O8GS4oCaPvHLhmKRCPpEGQ47uxLPvwOZSy2e74u8ndS55ks7qI7QD+Qr8ZTY 5+7KFhs2bnMAu87LxG9lzI3xl17KUutitW5Xx2ipNRZ1aqK4U7dIocfNYLnlzLyogPzU 7B2qHse/Zj4Ae07n3JQIUsx5eQAUTEydFmJ0fc3S61D+pbh7iGlugnv21hILwVPGxYgO mmZr20kebQJZ5xn9KByD5ZXkNIj2wtoN4Sn+ACmbU2C3MbSqT05oiElq8oAduljK8+n4 C6Lc+LJiU2CG4C31QeQDBTKoMaGmYZlDY5dbEhonxIeaKoh3Mw2zDKXlIM3rDtCGrZSv f+jw== 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=Sx6jMB1GryE8FILddFDfY28qnymRgA5/0gfgREThDHg=; b=mNb02pzEg07fdsGuBjb1/ZeeSpi79N+nSGKnT8JsuCIrNDO8yTYKwxsICRlOvMDH2P 1iNVQEhi0q3UFSxrKzuee6hGG2mIjEfOKnXq0xxFUwgghrPM2XaXBbqV9KPMbi8HnPA+ EzPVWPlNio6lBNlBQF6eBhfmDgCPXGiwWA3EELJdjFGhLjpfkMhF/N6QzBYy+kw6ygjq 4OR4N659RpXBqUB0QeudvPbRIn2aDy5EX9gqDxKQeD+fKAMMVBU96/pU8cEeGXmnBGMC LiSaF9Q6sDPUHOB9IiyNKPP6Jgi7g975vodLAjmywvLSx0A0iyuK/EJ16vjkXr5eYJYy 0TYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MLwPRu3q; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si1478086pfg.278.2018.02.28.09.21.19; Wed, 28 Feb 2018 09:21:34 -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=@gmail.com header.s=20161025 header.b=MLwPRu3q; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933451AbeB1Prv (ORCPT + 99 others); Wed, 28 Feb 2018 10:47:51 -0500 Received: from mail-qk0-f193.google.com ([209.85.220.193]:34096 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933433AbeB1Prr (ORCPT ); Wed, 28 Feb 2018 10:47:47 -0500 Received: by mail-qk0-f193.google.com with SMTP id l206so3546499qke.1; Wed, 28 Feb 2018 07:47:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Sx6jMB1GryE8FILddFDfY28qnymRgA5/0gfgREThDHg=; b=MLwPRu3qdX6l8XsxoVAM2kvXt6jmYtxXe2C0JllgShC0eJHIEF1LZFfz1bpOozQHrZ HiUUtc01n3uNIKRUnfEv6JitbS+lpco+BxF724wJjsEZknxuBthMe0smt+siv21woCRf tXZqv/v+4S7nvTHQ188kK7cAHtU35zO2BdYEL9As1NdQ6AIBzIuZBaE0yUsqK2wbSxlS 9lPxK/J+OAIMlOiyTY4S+mD07+VAwgdOmTX1Y/f/jpCSNUDN8yAke2KqrZcE6OUEYtBM 6/ONoVRUE9ciIZha+luNS2PW+KdoCWdiQbpUYwmApeiyu09G1vZioDJwTA8e6qs3cWBX iGlw== 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=Sx6jMB1GryE8FILddFDfY28qnymRgA5/0gfgREThDHg=; b=jXVPei04RkqHuiv2anlD6m+z+aeYj+LcAG5yYvYTfxcu6iODPhSZsbl0jIoSyorE9s 3uykVWS7e692FDc3NZbmsB8SKZN14EC9pZhrvoxzfj8+hzbRJw4/vW9g7lIDo72jpvGJ DLJ4sFr5VDg56ccTq4biERJpQv+4iN1lQxyCldNUOZpjoLJovio5uSFrtzlwwmN4xYOw ibLtnDQ2uQLYOKd/zJojOrgWwz1xqgnsBSI7b0g/AnIOXVE53ExomDdZBnkLYHL3EEkb aupfqo1O7W1Jf/qlbfXqVNLqDNmq9dz1H3VFSmZVowTLd2MRB9DEFQTUla9e3u6lWKvn valw== X-Gm-Message-State: APf1xPAYe99D0rzgqZAl6/uh2V07xD0dzHklzZPSh1gn8fSCiDapF159 5A5WhLmAdTBDXKi1Sa3mRO6UEW0qkjDW9TNigNU= X-Received: by 10.55.15.147 with SMTP id 19mr27189774qkp.301.1519832866476; Wed, 28 Feb 2018 07:47:46 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.195.80 with HTTP; Wed, 28 Feb 2018 07:47:45 -0800 (PST) In-Reply-To: <20180228115318.20154-1-Evgeniy.Didin@synopsys.com> References: <20180228115318.20154-1-Evgeniy.Didin@synopsys.com> From: Andy Shevchenko Date: Wed, 28 Feb 2018 17:47:45 +0200 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 , Ulf Hansson , Jisheng Zhang , Shawn Lin , Vineet Gupta , Linux Kernel Mailing List , linux-snps-arc@lists.infradead.org, Stable 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 Wed, Feb 28, 2018 at 1:53 PM, 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. > FWIW, Reviewed-by: Andy Shevchenko > 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: > --- > 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 > -- With Best Regards, Andy Shevchenko