Received: by 10.223.185.116 with SMTP id b49csp6088756wrg; Wed, 28 Feb 2018 03:54:41 -0800 (PST) X-Google-Smtp-Source: AH8x225k10A2Rhnx5f2SSMhEJpKUPlQVlYFEVwjiJUmufH4gw3Dmg2LHY85CsdhAur8l9OPGtnFU X-Received: by 10.98.149.90 with SMTP id p87mr17366395pfd.28.1519818881711; Wed, 28 Feb 2018 03:54:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519818881; cv=none; d=google.com; s=arc-20160816; b=fvXkSXkmkowvhysk4M1/mBS6mcttCoHqAPONDrNQ8+fjWE9e5rLprXWP/wNO9ASJQT WbUj0hwOTBVydzmlGo3/WR7cIY2CcnGdpmyUwOFAF1NhIgoenZHSyt6aIvp4kW5e3U5C ILtn+Vh6XMsPncnxsav7kbhLCDunlcwBv+mAe6drTN0opFoMnIeg3SCoqs02t/uXUmUJ ioL7FN2wexP+8v+xo6W3QrZiZiFrBUOSQObVNu4oGSQn27UBg6tK9MJELxyxV4l/k1Al QxmeiPCSDlVaURqLNp/3LrKys2qC1zHne4I2TA6bncVYN4LYSukDFXxWrL4dv+9l+nJt Ea3w== 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 :arc-authentication-results; bh=+oTPYvEzjyqb2QN7yilnizNksCX7KBlgUqouFQ4uvww=; b=O0P1QaJvassV2tVsntafq4orQvVnU7J8AmcGN88BFPQcrbm5oVUG/BL5ORcWrRKGPS TohqFJn3ReFXFSzwX5lX2+XsQ9VopznjWAO8EsgKJcJfxBNUyjbgerfDz3Oru1H47eAa 5BktsG3rPQNkxBmXNjBC0dpxpiyunYDKVQg3dT9HDLLlJ1a2LZXHJzTzXWW3mzOfbeLH 20jNh0IPxuFtoRHENWOwfkrM+Z/n05Tz5ZO20NFVKHb1cKT/QuRZ+PuTa1znQUJSiSw/ LXNt2X+s2T3QCA9PIt6ZGxtVsXQwUA5yMqZt5FHGNXpz5NMaVH/hWTgJ0Eglhk69k4v2 RDoQ== 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=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k20-v6si1198107pls.294.2018.02.28.03.54.24; Wed, 28 Feb 2018 03:54:41 -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=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752455AbeB1Lxl (ORCPT + 99 others); Wed, 28 Feb 2018 06:53:41 -0500 Received: from us01smtprelay-2.synopsys.com ([198.182.60.111]:37562 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752366AbeB1Lxf (ORCPT ); Wed, 28 Feb 2018 06:53:35 -0500 Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.13.184.66]) by smtprelay.synopsys.com (Postfix) with ESMTP id 0663510C080F; Wed, 28 Feb 2018 03:53:35 -0800 (PST) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id D92B33E2B; Wed, 28 Feb 2018 03:53:34 -0800 (PST) Received: from ru20arcgnu1.internal.synopsys.com (ru20arcgnu1.internal.synopsys.com [10.121.9.48]) by mailhost.synopsys.com (Postfix) with ESMTP id AB9BB3E15; Wed, 28 Feb 2018 03:53:31 -0800 (PST) From: Evgeniy Didin To: linux-mmc@vger.kernel.org Cc: Evgeniy Didin , Alexey Brodkin , Eugeniy Paltsev , Douglas Anderson , Ulf Hansson , Andy Shevchenko , Jisheng Zhang , Shawn Lin , Vineet Gupta , linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, stable@vger.kernel.org Subject: [PATCH v4] mmc: dw_mmc: Fix the DTO/CTO timeout overflow calculation for 32-bit systems Date: Wed, 28 Feb 2018 14:53:18 +0300 Message-Id: <20180228115318.20154-1-Evgeniy.Didin@synopsys.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: --- 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