Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2749637pxb; Mon, 1 Nov 2021 00:39:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygPEI4yRDZvTk7Y0A7j2bAbP6zEu02DNJmRv8thL9vZKayO9BThELV4LHXXrmu9t6RcxGD X-Received: by 2002:a02:6027:: with SMTP id i39mr19806874jac.91.1635752387971; Mon, 01 Nov 2021 00:39:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635752387; cv=none; d=google.com; s=arc-20160816; b=LhHX2wcxPAfYE4Xs8Hm8MPvetkdu2k5sbeqpoAPNM9ffbFJIDDMqkXeBFjcegK3G1W i7x98DAK0lDgYLGiDoya/YwsXj7v7T83aHMoR80YE4GqfmX79MUS/sRos3xUAro+5HgL Yg86uA62eWN6wV2xBqSKKXnwTO/U/wqEa/xbv0lMoczp0UJiPKPLY9tMDz5qJ/SRrW/P 4RWOCbNj0Lu3ApJ9ah1DIr0v/O97yglhyl3KPQNT4va4SQFVUGgxUh7ubqHqZJ7QH5SR InLeJ/LPvs0SVggJcduW+23Fjrsea7Mjhr+QCKfXHqbsfXOPPDvCkNmLCZvEnkGBSXE3 b9LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=Rzl98P+ow6nEvFB8xWgHAkQGMsn2lKIgdLrx/wCMKWk=; b=r9Zx6+Gw2ClOf6sngJRIWc+z1zy2nkLFw/LG1NxWb2dftx6GeXEuNqSdHqDJ8d0FWO 05S1z+Ug+ybSkbnUNDM+gTAU5wA0V/bMRAue4e6Hu+bR1T1Ht7A2cPBB/fNNji0Ed1jk cS9Gqk5J0O+NYci4QgbS06OVf/0aDhPNwiJx0WKcDlbgkdYRYYbZh/igUJlglYlrwT4M ZZ6y+9moKqOgBy8ERvc+2Z/Yc/b8oKSei/vR/nMQMDAKYbGkt40a1ZLpV/KrerX4xma/ QNNbtNl4ZhCxIZR2ZPUOZHYZSz+sEU0ulmuga+flXQIeZk5MzKkgvD7GWwIk6zm7I+m8 g8vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id a2si519798iow.21.2021.11.01.00.39.35; Mon, 01 Nov 2021 00:39:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230289AbhKAHlM (ORCPT + 99 others); Mon, 1 Nov 2021 03:41:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbhKAHlL (ORCPT ); Mon, 1 Nov 2021 03:41:11 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BD6AC061714 for ; Mon, 1 Nov 2021 00:38:36 -0700 (PDT) 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 19EDD1F438BB; Mon, 1 Nov 2021 07:38:33 +0000 (GMT) Date: Mon, 1 Nov 2021 08:38:24 +0100 From: Boris Brezillon To: Sean Nyekjaer Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Boris Brezillon , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 1/4] mtd: rawnand: nand_bbt: hide suspend/resume hooks while scanning bbt Message-ID: <20211101083824.236b9983@collabora.com> In-Reply-To: <20211026055551.3053598-2-sean@geanix.com> References: <20211026055551.3053598-1-sean@geanix.com> <20211026055551.3053598-2-sean@geanix.com> Organization: Collabora X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 26 Oct 2021 07:55:48 +0200 Sean Nyekjaer wrote: > From: Boris Brezillon > > The BBT scan logic use the MTD helpers before the MTD layer had a > chance to initialize the device, and that leads to issues when > accessing the uninitialized suspend lock. Let's temporarily set the > suspend/resume hooks to NULL to skip the lock acquire/release step. > > Fixes: 013e6292aaf5 ("mtd: rawnand: Simplify the locking") I think I already mentioned this Fixes tag should not be there. > Tested-by: Sean Nyekjaer > Signed-off-by: Boris Brezillon > Signed-off-by: Sean Nyekjaer > --- > drivers/mtd/nand/raw/nand_bbt.c | 28 +++++++++++++++++++++++++++- > 1 file changed, 27 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/nand/raw/nand_bbt.c b/drivers/mtd/nand/raw/nand_bbt.c > index b7ad030225f8..93d385703469 100644 > --- a/drivers/mtd/nand/raw/nand_bbt.c > +++ b/drivers/mtd/nand/raw/nand_bbt.c > @@ -1397,8 +1397,28 @@ static int nand_create_badblock_pattern(struct nand_chip *this) > */ > int nand_create_bbt(struct nand_chip *this) > { > + struct mtd_info *mtd = nand_to_mtd(this); > + int (*suspend) (struct mtd_info *) = mtd->_suspend; > + void (*resume) (struct mtd_info *) = mtd->_resume; > int ret; > > + /* > + * The BBT scan logic use the MTD helpers before the MTD layer had a > + * chance to initialize the device, and that leads to issues when > + * accessing the uninitialized suspend lock. Let's temporarily set the > + * suspend/resume hooks to NULL to skip the lock acquire/release step. > + * > + * FIXME: This is an ugly hack, so please don't copy this pattern to > + * other MTD implementations. The proper fix would be to implement a > + * generic BBT scan logic at the NAND level that's not using any of the > + * MTD helpers to access pages. We also might consider doing a two > + * step initialization at the MTD level (mtd_device_init() + > + * mtd_device_register()) so some of the fields are initialized > + * early. > + */ > + mtd->_suspend = NULL; > + mtd->_resume = NULL; > + > /* Is a flash based bad block table requested? */ > if (this->bbt_options & NAND_BBT_USE_FLASH) { > /* Use the default pattern descriptors */ > @@ -1422,7 +1442,13 @@ int nand_create_bbt(struct nand_chip *this) > return ret; > } > > - return nand_scan_bbt(this, this->badblock_pattern); > + ret = nand_scan_bbt(this, this->badblock_pattern); > + > + /* Restore the suspend/resume hooks. */ > + mtd->_suspend = suspend; > + mtd->_resume = resume; > + > + return ret; > } > EXPORT_SYMBOL(nand_create_bbt); >