Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 470A727FD5B; Mon, 23 Mar 2026 15:23:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774279410; cv=none; b=DPdnObX6rcWFeQ2IAtt0zsmbQJXhoezEuUCgWpCZwoyKN36B3jWNhBR+Ur7LFXL4YQIyByFkxLvq5zI5PmKSuks9VrM4kYR5ct5uBaEL4QM6fiVph1fO2wrS736O0pacZJUI51XhBK+aNW55tnMasbs89XWCdIN5tLwwm+HZ05Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774279410; c=relaxed/simple; bh=YKezCIi7T184QUiBpBTyfPNjY1k0u/nS7OREoSRvQTQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sX7zJi7YULynY3MzcAEUFYXJtZGXMcS9WowuXHK+CKIONc2fWP3d0xu6JQ8Ppp/q1M/6Mkx2wfbQKMMg5O82hcvkKuPngc7HpyOEycvRvloYyaRF14rmLvuJM/vIG5pjdPrf7Hi/JIEhwZ5YRjeaR7mIZbZ0clVimIfV4UYuTes= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=zeG9EaUD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="zeG9EaUD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85415C2BCB1; Mon, 23 Mar 2026 15:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774279409; bh=YKezCIi7T184QUiBpBTyfPNjY1k0u/nS7OREoSRvQTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zeG9EaUDNJ6Gl8anxgB1M1teWzLiqPCZzfae6lJzP49WmaydbtIgSHz2OlFcUz5ql 48r6D4Emasr+A60IGXXQUsODO9ZBu2rsqIxI6wyDcVggaXbpjn49glYj9mcXSUtZ8Q sLsGkRkYTbmKXqYN4FHIAdZnhAOgKpB9Tw7t+F5w= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kamal Dasu , William Zhang , Miquel Raynal , Sasha Levin Subject: [PATCH 6.6 560/567] mtd: rawnand: serialize lock/unlock against other NAND operations Date: Mon, 23 Mar 2026 14:48:00 +0100 Message-ID: <20260323134547.887357740@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134533.749096647@linuxfoundation.org> References: <20260323134533.749096647@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kamal Dasu [ Upstream commit bab2bc6e850a697a23b9e5f0e21bb8c187615e95 ] nand_lock() and nand_unlock() call into chip->ops.lock_area/unlock_area without holding the NAND device lock. On controllers that implement SET_FEATURES via multiple low-level PIO commands, these can race with concurrent UBI/UBIFS background erase/write operations that hold the device lock, resulting in cmd_pending conflicts on the NAND controller. Add nand_get_device()/nand_release_device() around the lock/unlock operations to serialize them against all other NAND controller access. Fixes: 92270086b7e5 ("mtd: rawnand: Add support for manufacturer specific lock/unlock operation") Signed-off-by: Kamal Dasu Reviewed-by: William Zhang Signed-off-by: Miquel Raynal Signed-off-by: Sasha Levin --- drivers/mtd/nand/raw/nand_base.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index fe0b298f8425e..896a7d819e3c7 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4849,11 +4849,16 @@ static void nand_shutdown(struct mtd_info *mtd) static int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { struct nand_chip *chip = mtd_to_nand(mtd); + int ret; if (!chip->ops.lock_area) return -ENOTSUPP; - return chip->ops.lock_area(chip, ofs, len); + nand_get_device(chip); + ret = chip->ops.lock_area(chip, ofs, len); + nand_release_device(chip); + + return ret; } /** @@ -4865,11 +4870,16 @@ static int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) static int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { struct nand_chip *chip = mtd_to_nand(mtd); + int ret; if (!chip->ops.unlock_area) return -ENOTSUPP; - return chip->ops.unlock_area(chip, ofs, len); + nand_get_device(chip); + ret = chip->ops.unlock_area(chip, ofs, len); + nand_release_device(chip); + + return ret; } /* Set default functions */ -- 2.51.0