Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2427656ybl; Thu, 9 Jan 2020 12:34:17 -0800 (PST) X-Google-Smtp-Source: APXvYqxsOC0jw1igM8qiJm3gxDZvhvEOTwS2Fge1wD1OkKPMJK7ZSNTlSM9gffK5r+7dDEYoROyJ X-Received: by 2002:a9d:53cb:: with SMTP id i11mr10340276oth.158.1578602057205; Thu, 09 Jan 2020 12:34:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578602057; cv=none; d=google.com; s=arc-20160816; b=ncPOD3SNV47Az4scN/tPLFspNM+y0jXz5HWr450P/6djhQKKaan5QUl9T3wkUEPA9x hgkR2L1ITbMx30TAwU5SemeXMYmUCUcIV58ClJq438RWwtUShGs7TVtkKmCl2Ruu2XR/ +uL0uz0V4e4i+zs9Or2VJidmpWdy1TLnB77P7k5NQ0J58cqARInzKUBgrrtC+baIyzxr GjtJ957vU/WAJXcMhW785vtQ8RmrBUw4gKbjfhlP5lo8D0X+RJb9hxpenK/g9Ce6Hn1Y zIhljtLyOuBCPEBqkUe9NubF3x8kQcp5RL1kSzo+o9X7ngwYtp/ol8JpvSvwuhnluU18 LRBQ== 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=95eRf1seuQuE1Led61p617dfaMi93+r0ob4vbHqK/ps=; b=0zNPaPSS1zXyIfdM9Ery3f+AvviHqi+lO1G57tiduqzP2WFCe6lSqR68wTnavWXEf7 NP7iUSDyBjz4EuBLKaAJ2A/pm9rhibL5soNce10KnTE5t+2S1BX67FeaexvfSEsXItP/ dwaEcXZTweVgbspQLHjXNI1TQxXys8wXj5/26wjgT+avaqXEMbmLpm60c1D3CqwSw2Ru iWW4TppgKwDIy9DmUBRvU/uUEyaErDpISfMHfhdF25zD0kLDDL5TqUAxzct2oASCfLJV giHXdKLjfKDasPBHZfZzlyav24iUD+eCmXjhMg2tJ04GKBNNa0ZwUEoiTzNUVhuV4zgF WLeQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q131si4347833oig.203.2020.01.09.12.34.05; Thu, 09 Jan 2020 12:34:17 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387888AbgAIRWr convert rfc822-to-8bit (ORCPT + 99 others); Thu, 9 Jan 2020 12:22:47 -0500 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:43235 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731563AbgAIRWr (ORCPT ); Thu, 9 Jan 2020 12:22:47 -0500 X-Originating-IP: 91.224.148.103 Received: from xps13 (unknown [91.224.148.103]) (Authenticated sender: miquel.raynal@bootlin.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 20A53C0006; Thu, 9 Jan 2020 17:22:43 +0000 (UTC) Date: Thu, 9 Jan 2020 18:22:42 +0100 From: Miquel Raynal To: Martin DEVERA Cc: linux-kernel@vger.kernel.org, jan.pohanka@merz.cz, Christophe Kerello , Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , linux-mtd@lists.infradead.org Subject: Re: [PATCH] mtd: rawnand: Fix unexpected timeouts in waitrdy Message-ID: <20200109182242.03743cf7@xps13> In-Reply-To: <73164aea-d889-21e4-4e7d-345ebd4e5197@eaxlabs.cz> References: <20191210150319.3125-1-devik@eaxlabs.cz> <20200109163752.621c6248@xps13> <73164aea-d889-21e4-4e7d-345ebd4e5197@eaxlabs.cz> Organization: Bootlin X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Martin, Martin DEVERA wrote on Thu, 9 Jan 2020 17:17:30 +0100: > On 1/9/20 4:37 PM, Miquel Raynal wrote: > > Hi Martin, > > > > Martin Devera wrote on Tue, 10 Dec 2019 16:03:18 > > +0100: > > > >> The used way to compute jiffies timeout brokes when > >> jiffie difference is 1. Simply add 1 - it has no other > >> side effects. > >> Fixes STM32MP1 FMC2 NAND controller which sometimes failed > >> exactly in this way. > >> > >> Signed-off-by: Martin Devera > >> --- > >> drivers/mtd/nand/raw/nand_base.c | 6 +++++- > >> 1 file changed, 5 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c > >> index d527e448ce19..beab3a775cc7 100644 > >> --- a/drivers/mtd/nand/raw/nand_base.c > >> +++ b/drivers/mtd/nand/raw/nand_base.c > >> @@ -721,7 +721,11 @@ int nand_soft_waitrdy(struct nand_chip *chip, unsigned long timeout_ms) > >> if (ret) > >> return ret; > >> >> - timeout_ms = jiffies + msecs_to_jiffies(timeout_ms); > >> + /* +1 below is necessary because if we are now in the last fraction > >> + * of jiffy and msecs_to_jiffies is 1 then we will wait only that > >> + * small jiffy fraction - possibly leading to false timeout > >> + */ > >> + timeout_ms = jiffies + msecs_to_jiffies(timeout_ms) + 1; > >> do { > >> ret = nand_read_data_op(chip, &status, sizeof(status), true); > >> if (ret) > > I don't really what you are fixing here, I suspect the root cause to be > > a wrongly calculated timeout_ms in the calling driver. > > > > It is the responsibility of the caller to use this function with a > > relevant timeout_ms parameter. Maybe Christophe can help you here? > > > Hi Miquel, > > assume that nand_soft_waitrdy is called with timeout_ms==1. I suppose it is > valid case. Jiffies are 1000 for example (assume something more like 1000.99 - > just before incrementing to 1001). > We compute timeout_ms = 1000+msecs_to_jiffies(1) = 1001 (at least for my jiffies rate). > nand_read_data_op is called for the first time and returns 0. During the call jiffies changes > to 1001 thus "while loop" ends here (wrongly). > Notice that routine was called with expected timeout 1ms but actual timeout used was something > between 0...1ms (which I also measured by tracing & scope on the bus). > Or is my analysis flawed somewhere ? I agree with your analysis. Even if nand_soft_waitrdy will no longer be used by the stm32 driver (Christophe sent a patch for that) I am fine applying this change. Could you add a comment to explain the '+1' and resend? Thanks, Miquèl