Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp662982lqi; Thu, 7 Mar 2024 08:03:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWruCKDjuUID0CqEauiJCCmVRVLx0ypXtoGnKGgWKor38t3Lxmg/tV/XKHliDpouccM0KjSH5rQx/Cfgz+R/7FfXQtNiQE2GwF566pZNg== X-Google-Smtp-Source: AGHT+IG9m6f5NbSgjd1Pe0b4Snl1sNHlJ+CCi3vMNH1KlT+CMNi+4cut7gJbuXYFZPMY82DO7G3g X-Received: by 2002:a17:902:9897:b0:1dd:5bd6:50c8 with SMTP id s23-20020a170902989700b001dd5bd650c8mr1141547plp.64.1709827430830; Thu, 07 Mar 2024 08:03:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709827430; cv=pass; d=google.com; s=arc-20160816; b=uL61FuQPC4AcbMN3mRVFa0E70X2lxzfFiRv6WMaw7jwGwlCTwSdSHGsQnIAByZ8D6n Dvup4ToSwh/VKeykVp3W7Nw789Se2Q7lGr0LN+6KCQSJxlUqlpY/uKUpEMcvPOVRdWrn W3iytxZESyQybOyof3YTF2U5Ah5BVnWk5lqhQCG/OLO1tn/E5n3qoXjFHAC3KRikBpyM aGb385TzHmaxe1axbwBgWuPo2Ecz/o1hJ987kzpg2M4fbo5GdU5srWEUc0yr+6jRf2JG GKTQH3aMOiXfMfHkQimBLyuik9n/j1bqrz9KGUrYUUYPGWRNmR+NmMxSLxUFEqlYPDpT 1KmA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to :content-disposition:references:mail-followup-to:message-id:subject :cc:to:from:dkim-signature:date; bh=qNHy0ey9Rh5SkT/53hLFdIyIDdFiIk0IR0E13PdFioI=; fh=tNwGgq48rDpbGL7X/Mwnq5OaseWDir5u1+tYZeyTa5o=; b=b09p8q5JHp9QL4vtAgIcd4PxwN2/ZLmlpDJnNowcJdYCw9LXRFtf7nT3wVMoozZIaH wIeWHD7pvIa3CyYCnBJiIWL+9COuDVDCGzTwllyYA8sf+OChzCJKsT/ZDAldKb+ySbCw p7F5VoRwsx8TCs5hdz4G/2cQo2YAP7rrHuBktjpbUZ1xyZItAWOuE8FJ8VirgcaWuSd2 D7c8Pxjg8hgPuUBsj44hvXGlkZacEzDWL7pM9YXkk6UhGojHWtXnMXjXYazBNAJ7l1iP vN+kxxCVcyX9be+VJWHWiBkxg1lIyWN8+koG8y+bQFcguKSR3+mctLmvVUI9l1s8ML62 LI3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@thorsis.com header.s=default header.b=E+e5my4E; arc=pass (i=1 spf=pass spfdomain=thorsis.com dkim=pass dkdomain=thorsis.com dmarc=pass fromdomain=thorsis.com); spf=pass (google.com: domain of linux-kernel+bounces-95840-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95840-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=thorsis.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id lm13-20020a170903298d00b001dc7aa0654esi14269160plb.413.2024.03.07.08.03.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 08:03:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-95840-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@thorsis.com header.s=default header.b=E+e5my4E; arc=pass (i=1 spf=pass spfdomain=thorsis.com dkim=pass dkdomain=thorsis.com dmarc=pass fromdomain=thorsis.com); spf=pass (google.com: domain of linux-kernel+bounces-95840-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95840-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=thorsis.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 54A79283F70 for ; Thu, 7 Mar 2024 16:02:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49ED612EBF6; Thu, 7 Mar 2024 16:02:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=thorsis.com header.i=@thorsis.com header.b="E+e5my4E" Received: from mail.thorsis.com (mail.thorsis.com [92.198.35.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D277B1EEEA for ; Thu, 7 Mar 2024 16:02:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=92.198.35.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709827347; cv=none; b=suYJyhQMofOk7PY0nhq9uK93z2wpFO1qikKGayeo4A5yF6hygrI4hRlxDwVaYynS2OlIsDrFFHJIi6dm0xniynedcg5BKukk5awc6sEqmBDPOxdjpD/6RQn7LAiB51Unq3MExrqZu3L+T6JKoYyN2tZpAr648yEIJTchlKPwnQg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709827347; c=relaxed/simple; bh=KnOCTDumG/A9/5/SUytK/rT0ZUv7KFO9BrmC1LlkoEw=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To; b=A6Q8NDgOmJALsuKjyWrwgMGOy2tCQw/TAoQ6Kp7iXkTSLlQg8Py9DfgLa5t7MASSbL9aLM7wMzGBxPlk7xwMNsyN4iLfOflsRgp/ikl6/i/x0ycXqo72M3nKc6b874TVs5nMi5yDnw930UFL15F8i54IvZiSvPV/YlzUL1MmQNI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=thorsis.com; spf=pass smtp.mailfrom=thorsis.com; dkim=pass (2048-bit key) header.d=thorsis.com header.i=@thorsis.com header.b=E+e5my4E; arc=none smtp.client-ip=92.198.35.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=thorsis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=thorsis.com Date: Thu, 7 Mar 2024 17:02:16 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thorsis.com; s=default; t=1709827335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type:in-reply-to:in-reply-to: references:references; bh=qNHy0ey9Rh5SkT/53hLFdIyIDdFiIk0IR0E13PdFioI=; b=E+e5my4E7F4awvZ2mTvJztGmw9kmA5Znr5n03/FWxR0jS5qXRXTTys4QY6IsLuVIFV26pM 08Y/Nlif9P6prtPxiiXob2ffH7N7K/hXIi1+A1DuQOeslZivL4UoQuZ474fK4r7M5ptgeI fSvjhUYED8Or2XoRjIxvCA+KlIpIG6F3WlXAml3J7DxJhP39HSys5QDM4zVdybs5rmm3M7 qMVnH7zzVgSsH2R0YWAKkv46TTFB3GDjgnOP5qtAgvzwKv04E1FNj4y2m7WF/+X9mAF1eV juvo/if/vvrMB6Tiz16qew6OgVwWqVbgTwtVeH7eA4PZ1eBjBGlZLoLnIjTrgA== From: Alexander Dahl To: Miquel Raynal Cc: Alexander Dahl , linux-mtd@lists.infradead.org, Richard Weinberger , Vignesh Raghavendra , linux-kernel@vger.kernel.org Subject: Re: mtd: nand: raw: Possible bug in nand_onfi_detect()? Message-ID: <20240307-pantry-deceit-78ce20f47899@thorsis.com> Mail-Followup-To: Miquel Raynal , linux-mtd@lists.infradead.org, Richard Weinberger , Vignesh Raghavendra , linux-kernel@vger.kernel.org References: <20240306-shaky-bunion-d28b65ea97d7@thorsis.com> <20240306164831.29eed907@xps-13> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240306164831.29eed907@xps-13> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Hello Miquel, thanks for looking into this, see my remarks below. Am Wed, Mar 06, 2024 at 04:48:31PM +0100 schrieb Miquel Raynal: > Hi Alexander, > > ada@thorsis.com wrote on Wed, 6 Mar 2024 15:36:04 +0100: > > > Hello everyone, > > > > I think I found a bug in nand_onfi_detect() which was introduced with > > commit c27842e7e11f ("mtd: rawnand: onfi: Adapt the parameter page > > read to constraint controllers") back in 2020. > > Interesting. I don't think this patch did broke anything, as > constrained controllers would just not support the read_data_op() call > anyway. > > That being said, I don't see why the atmel controller would > refuse this operation, as it is supposed to support all > operations without limitation. This is one of the three issues > you have, that probably needs fixing. I found a flaw in my debug messages hiding the underlying issue for this. I'm afraid this is another bug introduced by you with commit 9f820fc0651c ("mtd: rawnand: Check the data only read pattern only once"). See this line in rawnand_check_data_only_read_support(): if (!nand_read_data_op(chip, NULL, SZ_512, true, true)) This leads to nand_read_data_op() returning -EINVAL, because it checks if its second argument is non-NULL. I guess not only the atmel nand controller is affected here, but _all_ nand controllers? The flag can never be set, and so use_datain is false here? > > Background on how I found this: I'm currently struggling getting raw > > nand flash access to fly with an at91 sam9x60 SoC and a S34ML02G1 > > Spansion SLC raw NAND flash on a custom board. The setup is > > comparable to the sam9x60 curiosity board and can be reproduced with > > that one. > > > > NAND flash on sam9x60 curiosity board works fine with what is in > > mainline Linux kernel. However after removing the line 'rb-gpios = > > <&pioD 5 GPIO_ACTIVE_HIGH>;' from at91-sam9x60_curiosity.dts all data > > read from the flash appears to be zeros only. (I did not add that > > line to the dts of my custom board first, this is how I stumbled over > > this.) > > > > I have no explanation for that behaviour, it should work without R/B# > > by reading the status register, maybe we investigate that > > in depth later. > > I don't see why at a first look. The default is "no RB" if no property > is given in the DT so it should work. Correct, nand_soft_waitrdy() is used in that case. > Tracing the wait ready function calls might help. Did that already. On each call here the status register read contains E0h and nand_soft_waitrdy() returns without error, because the NAND_STATUS_READY flag is set. It just looks fine, although it is not afterwards. > > However those all zeros data reads happens when > > reading the ONFI param page as well es data read from OOB/spare area > > later and I bet it's the same with usual data. > > Reading data without observing tWB + tR may lead to this. I already suspected some timing issue. Deeper investigation will have to wait until we soldered some wires to the chip and connect a logic analyzer however. At least that's the plan, but this will have to wait some days until after I finished some other tasks. > > This read error reveals a bug in nand_onfi_detect(). After setting > > up some things there's this for loop: > > > > for (i = 0; i < ONFI_PARAM_PAGES; i++) { > > > > For i = 0 nand_read_param_page_op() is called and in my case all zeros > > are returned and thus the CRC calculated does not match the all zeros > > CRC read. So the usual break on successful reading the first page is > > skipped and for reading the second page nand_change_read_column_op() > > is called. I think that one always fails on this line: > > > > if (offset_in_page + len > mtd->writesize + mtd->oobsize) { > > > > Those variables contain the following values: > > > > offset_in_page: 256 > > len: 256 > > mtd->writesize: 0 > > mtd->oobsize: 0 > > Indeed. We probably need some kind of extra check that does not perform > the if clause above if !mtd->writesize. > > > The condition is true and nand_change_read_column_op() returns with > > -EINVAL, because mtd->writesize and mtd->oobsize are not set yet in > > that code path. Those are probably initialized later, maybe with > > parameters read from that ONFI param page? > > > > Returning with error from nand_change_read_column_op() leads to > > jumping out of nand_onfi_detect() early, and no ONFI param page is > > evaluated at all, although the second or third page could be intact. > > > > I guess this would also fail with any other reason for not matching > > CRCs in the first page, but I have not faulty NAND flash chip to > > confirm that. > > Thanks for the whole report, it is interesting and should lead to fixes: > - why does the controller refuses the datain op? See above. > - why nand_soft_waitrdy is not enough? I don't know. That's one reason I asked here. > - changing the condition in nand_change_read_column_op() > > Can you take care of these? The last one probably after in depth reading of the code again, unsure for the other two. Greets Alex