Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp98102imj; Thu, 7 Feb 2019 00:58:16 -0800 (PST) X-Google-Smtp-Source: AHgI3IZhpAwlkiZXYVdbYkqIsHbpXzXI3TeU+gWMP9rsXSmSW6/vlU0G4NxHqMeSyuzbBId+jOAk X-Received: by 2002:a63:eb0e:: with SMTP id t14mr13955111pgh.445.1549529896775; Thu, 07 Feb 2019 00:58:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549529896; cv=none; d=google.com; s=arc-20160816; b=nykezqUJX0KIub/3wW4R5jlLs9JFAbBfIqa69d3GI8+bgzFzT4Nsx3e3TWpOAygFCS zRcid3odSnMbAU9YseBjGCOaf19Btd2Ew4HlpoVDEJjqqFtxv+q5YXCT0GbPg53bemVl bCwq966DCCWH/XNVMs1JTrmwSLUQH/Pboe/GDv8yL+/Zc4T/lD/m5eNJFCAuT4mBI1Fa d+ZBlQLAuBzPIga2HU8TZ3g8Ml5pA0paEO5PTVjyLPVx3/1sUSx1BgMH/ed3eE968SKc SF2QX0a5YrP53YjzMu0ji2s+tIIjHFburxT8JAcubhGoidMwrVgmHOYh4g3GXQg8dYO3 JpmQ== 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=MVqNg/aqfGNeqvQh6RAxCArd0NbtXN7YMiQfpVw9zoY=; b=T2tpEdS0+BojDLmLQFL85qEFQYRuQi5BU3V+o0E/968RCH51X9+YUw9Y6uvWDDV2dK RBWx3iqKi/VH353MgZwlmu2mgqbWfhIdBcCRXPLwXS8alZobGYvuHF3fqp6DnKFerTCm 7qH8iyfcfdlIlb+k81Ufs6QAJtvOsSuFe2w6LN/UEuSSqdWxyF9G81sOgQKisTZSz9xS hBiLmLe3N1+Z0WZlEldqdI+KUwZ0d2UlKtqB7X9ub8nGFNxpDkMwf3TNRh1S/7QGbXHf /XmNhuIwxwDiCOpcVVmPhgkMYGH61GVtCvNvJ1MZC4giut6+40IIxsUjWug50FUvn81p kbUA== 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=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d189si1558796pgc.393.2019.02.07.00.58.01; Thu, 07 Feb 2019 00:58:16 -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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726796AbfBGI4x (ORCPT + 99 others); Thu, 7 Feb 2019 03:56:53 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:49718 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbfBGI4x (ORCPT ); Thu, 7 Feb 2019 03:56:53 -0500 Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 1BB2227DFBF; Thu, 7 Feb 2019 08:56:50 +0000 (GMT) Date: Thu, 7 Feb 2019 09:56:47 +0100 From: Boris Brezillon To: "Sobon, Przemyslaw" Cc: Liu Jian , "ikegami@allied-telesis.co.jp" , "dwmw2@infradead.org" , "computersforpeace@gmail.com" , "marek.vasut@gmail.com" , "richard@nod.at" , "joakim.tjernlund@infinera.com" , "keescook@chromium.org" , "linux-mtd@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] cfi: fix deadloop in cfi_cmdset_0002.c do_write_buffer Message-ID: <20190207095635.0fc3b411@kernel.org> In-Reply-To: References: <1548977439-318904-1-git-send-email-liujian56@huawei.com> <20190203092645.18d1495b@bbrezillon> <20190203093509.269bf1e1@bbrezillon> Organization: Collabora X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sobon, On Tue, 5 Feb 2019 22:28:44 +0000 "Sobon, Przemyslaw" wrote: > > From: Boris Brezillon > > Sent: Sunday, February 3, 2019 12:35 AM > > > +Przemyslaw > > > > > > On Fri, 1 Feb 2019 07:30:39 +0800 > > > Liu Jian wrote: > > > > > > > In function do_write_buffer(), in the for loop, there is a case > > > > chip_ready() returns 1 while chip_good() returns 0, so it never > > > > break the loop. > > > > To fix this, chip_good() is enough and it should timeout if it stay > > > > bad for a while. > > > > > > Looks like Przemyslaw reported and fixed the same problem. > > > > > > > > > > > Fixes: dfeae1073583(mtd: cfi_cmdset_0002: Change write buffer to > > > > check correct value) > > > > > > Can you put the Fixes tag on a single, and the format is > > > > > > Fixes: ("message") > > > > > > > Signed-off-by: Yi Huaijie > > > > Signed-off-by: Liu Jian > > > > > > [1]http://patchwork.ozlabs.org/patch/1025566/ > > > > > > > --- > > > > drivers/mtd/chips/cfi_cmdset_0002.c | 6 +++--- > > > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > > > > > diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c > > > > b/drivers/mtd/chips/cfi_cmdset_0002.c > > > > index 72428b6..818e94b 100644 > > > > --- a/drivers/mtd/chips/cfi_cmdset_0002.c > > > > +++ b/drivers/mtd/chips/cfi_cmdset_0002.c > > > > @@ -1876,14 +1876,14 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, > > > > continue; > > > > } > > > > > > > > - if (time_after(jiffies, timeo) && !chip_ready(map, adr)) > > > > - break; > > > > - > > > > if (chip_good(map, adr, datum)) { > > > > xip_enable(map, chip, adr); > > > > goto op_done; > > > > } > > > > > > > > + if (time_after(jiffies, timeo)) > > > > + break; > > > > + > > > > /* Latency issues. Drop the lock, wait a while and retry */ > > > > UDELAY(map, chip, adr, 1); > > > > } > > > > > > > BTW, the patch itself looks good to me. Ikegami, can you confirm it does the right thing? > > > > Thanks, > > > > Boris > > > > One comment to this patch. If value is written incorrectly quickly we will be > stuck in the loop even though nothing is going to change. For example a value was > written incorrectly after 1us, the loop was set to 1ms, function will return > after 1ms, this solution is not optimized for performance. I considered same > when working on this change and decided to do it different way. Seems like you're right if we assume that checking for GOOD state does not require a delay after the READY check, but if that's not the case and an extra delay is actually required, you might end up with a BAD status while it could have turned GOOD at some point with the 'check only for GOOD state until we timeout' approach. TBH, I don't know how CFI flashes work, so I'll let you guys sort this out. Regards, Boris