From patchwork Mon Jul 17 19:42:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 1809632 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=4vwnMeNT; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=gwgZ2+RK; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=S3cq2YVG; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R5QBL1d4Kz20FV for ; Wed, 19 Jul 2023 15:59:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Z3V48YvKCataN/GErriaTwQdcJKX/s7KHbVu91xEQdc=; b=4vwnMeNTythkkw RjlSVZCiwZdiX6oGc9VGtA244/tq3mV/z8C7AX0zlbNKR1YVsI4mMgrHlxFCACktMRw560V0Y7eJl cZcfxTKh3TUKKa4ntJx8O5ClJaPlEWRDEzfg7XMWzESAgfRvelg1CPw5LmCDKEruq3WVqu6UDvd0v Dk2dmaKNuhMwaIociIqoNPir6lDf5kaNfTJ1i0cg1eB4IT+GgqO8lzbSlngCc6coErnNNAXkfWfF9 Ft9raKNGE6Gi5yY0nChSIiOFDWg7iOtbQC2kHhqjZrDLA418rjfKAs7Ar2US2MTSIAQ9XQEcL/MJY +vyYMmLe3jQt/Yr2mp+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM0D9-005UUP-01; Wed, 19 Jul 2023 05:58:55 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM0D2-005UOy-2U for linux-mtd@bombadil.infradead.org; Wed, 19 Jul 2023 05:58:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:In-Reply-To:References; bh=RW03N0S/bEhxMDlvc7ZnHFSbKTSNbVdEvn4DEIHdDvw=; b=gwgZ2+RKk8pmh3+5yV73ipA4Vi qL7dbPwVMj3ijP/TzC2HZquyD3WdQU4jl6UjlG+IVhyJJkDQJ+ASD24ggtMJv/BlvUxDOBD9paveZ rxabMY42g+xYcGEDnujuOiDFpslO1QXn/87OxBidbn/S0ENWYzWi4kustjvragi1o7x66b9um+GdG rLaGlGrjGJJHtsXEp+Ub8MNf8oio+qCm9N4ndDR0xiASzn3m9L4kE2WkkjLnpRZu2qr2AaKR2xkOf E7zasyiaNz0BCzDKTi4TFm64480uJh9bMi1P8bGJB+sM7Wi1hjyFpG6AjyfHmwoBJR1j2RNuaNviw JK9bLXEw==; Received: from relay8-d.mail.gandi.net ([217.70.183.201]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLU7i-009FWp-09 for linux-mtd@lists.infradead.org; Mon, 17 Jul 2023 19:43:12 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id EE27E1BF204; Mon, 17 Jul 2023 19:42:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1689622946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RW03N0S/bEhxMDlvc7ZnHFSbKTSNbVdEvn4DEIHdDvw=; b=S3cq2YVGjPjyLO/zN1cJlZ/PGK5hAMYIFnMJ1pD5D/T2hlneLXaOKNuMcrvbAh78yqYs5Y BNSL6M0l1tI5SMJ2x47bdO4igVcWXKwSBpX0mWBAyiUP7bp74JFn/8/ymfLzdCxQotxk5b Way8MBFUx7Z8hv5ekT2cGMpRDA+nMPgBvQvV7J/kVOKErlJOJY834hrNXFJJbq0Id+GYjF 6OBFrKMQex+TrPF+drrhJ81hQ2nfNhFGSXZ1WcsZKKncr3/KGcDbhsN79oUudj/dDayntN FVfigHBnxSfDxF6JvA86GDLjcs8+nG7GJ1v5vRYp/E0JpWvpflTE4vJI8uME6g== From: Miquel Raynal To: Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus , Pratyush Yadav , Michael Walle , Cc: Thomas Petazzoni , Miquel Raynal , stable@vger.kernel.org, Aviram Dali Subject: [PATCH 1/3] mtd: rawnand: marvell: Ensure program page operations are successful Date: Mon, 17 Jul 2023 21:42:19 +0200 Message-Id: <20230717194221.229778-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230717_204310_572732_EBD19F91 X-CRM114-Status: GOOD ( 15.27 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The NAND core complies with the ONFI specification, which itself mentions that after any program or erase operation, a status check should be performed to see whether the operation was finished *and* [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [217.70.183.201 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [217.70.183.201 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The NAND core complies with the ONFI specification, which itself mentions that after any program or erase operation, a status check should be performed to see whether the operation was finished *and* successful. The NAND core offers helpers to finish a page write (sending the "PAGE PROG" command, waiting for the NAND chip to be ready again, and checking the operation status). But in some cases, advanced controller drivers might want to optimize this and craft their own page write helper to leverage additional hardware capabilities, thus not always using the core facilities. Some drivers, like this one, do not use the core helper to finish a page write because the final cycles are automatically managed by the hardware. In this case, the additional care must be taken to manually perform the final status check. Let's read the NAND chip status at the end of the page write helper and return -EIO upon error. Cc: stable@vger.kernel.org Fixes: 02f26ecf8c77 ("mtd: nand: add reworked Marvell NAND controller driver") Reported-by: Aviram Dali Signed-off-by: Miquel Raynal Tested-by: Ravi Chandra Minnikanti --- Hello Aviram, I have not tested this, but based on your report I believe the status check is indeed missing here and could sometimes lead to unnoticed partial writes. Please test on your side and reply with your Tested-by if you validate the change. Any backport on kernels predating v4.17 will likely fail because of a folder rename, so you will have to do the backport manually if needed. Thanks, Miquèl --- drivers/mtd/nand/raw/marvell_nand.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/marvell_nand.c b/drivers/mtd/nand/raw/marvell_nand.c index 30c15e4e1cc0..576441095012 100644 --- a/drivers/mtd/nand/raw/marvell_nand.c +++ b/drivers/mtd/nand/raw/marvell_nand.c @@ -1162,6 +1162,7 @@ static int marvell_nfc_hw_ecc_hmg_do_write_page(struct nand_chip *chip, .ndcb[2] = NDCB2_ADDR5_PAGE(page), }; unsigned int oob_bytes = lt->spare_bytes + (raw ? lt->ecc_bytes : 0); + u8 status; int ret; /* NFCv2 needs more information about the operation being executed */ @@ -1195,7 +1196,18 @@ static int marvell_nfc_hw_ecc_hmg_do_write_page(struct nand_chip *chip, ret = marvell_nfc_wait_op(chip, PSEC_TO_MSEC(sdr->tPROG_max)); - return ret; + if (ret) + return ret; + + /* Check write status on the chip side */ + ret = nand_status_op(chip, &status); + if (ret) + return ret; + + if (status & NAND_STATUS_FAIL) + return -EIO; + + return 0; } static int marvell_nfc_hw_ecc_hmg_write_page_raw(struct nand_chip *chip, @@ -1624,6 +1636,7 @@ static int marvell_nfc_hw_ecc_bch_write_page(struct nand_chip *chip, int data_len = lt->data_bytes; int spare_len = lt->spare_bytes; int chunk, ret; + u8 status; marvell_nfc_select_target(chip, chip->cur_cs); @@ -1660,6 +1673,14 @@ static int marvell_nfc_hw_ecc_bch_write_page(struct nand_chip *chip, if (ret) return ret; + /* Check write status on the chip side */ + ret = nand_status_op(chip, &status); + if (ret) + return ret; + + if (status & NAND_STATUS_FAIL) + return -EIO; + return 0; }