Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2478355pxb; Fri, 8 Oct 2021 08:35:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCxzlyFSHVbjt7zveGtQKtKjBPCGUJDnsm92BIzA2dEDMoqmTgiuZK4DDKfc0yWgjQzPni X-Received: by 2002:a17:906:2ed1:: with SMTP id s17mr5310721eji.261.1633707342924; Fri, 08 Oct 2021 08:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633707342; cv=none; d=google.com; s=arc-20160816; b=K3uYb0WyEC9f7ZKOft+VRlxnJFo5ktUKDVqT10dcpfDVB/QHFfY3CvjE5ajK7GpT8y VNL/skl4t40w4s8glFHS6WqynwAQYIrTfYjG43RwxGUJMxqY2KqC/Z0bGhg29mt31DrH rWZ3okFs1R5V/PeFKgtqOl+8ZCzZDQCYaqIbCVqaPj1R9v5TWp9Yd83KNb6KZjYKpei7 Ji0FB3UYfWDrGWEaXljbd5uci7FeSZLkSLtD65oQAJJhyUowCxzOmFn+t0NXminrNvrR rK8P9pqn+oVn1ESDWQwwEjAJnSw7GVleBh+KOjsEOo7mvVRobJNfNEEGR6Tz+3HKp4ns HZtQ== 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=anekvRJ0UWfv4n0l6SXN5jltq1MteJzaZHFjrU4lRvs=; b=u9Ct7K5FIC6kR740A4PV68hzSSCDM8H4b4BJaNeZ7jD9KI8X+kHKMwVPU7BB/DXaSH jtq9Fl/BSVXIcZ2swtWULn6e3HW4nQcISE72ELruDla2WySY9msZzMzJhGmUbPjNaO/H dXUfgZq1MYD2Ux6bfuD/6XHuNv7yb29pVsAw6fH0M8e0wkp9oA4vjQH92VoN7jb/eUCr I1MyYTjTJng1btq+THUNuebl23PC99GVb93bUfZ2Sps+M4i5uMX3jR3RwVBiTcht0Z3a XVDY4ShbW3O66dXqm9oN85qdbNlJA6tMn3dDBHD//N51orevTcXmd/WRhdhOQWaoIs9+ l17g== 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 bu3si3599514ejb.435.2021.10.08.08.35.14; Fri, 08 Oct 2021 08:35:42 -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 S242986AbhJHPcv (ORCPT + 99 others); Fri, 8 Oct 2021 11:32:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242978AbhJHPct (ORCPT ); Fri, 8 Oct 2021 11:32:49 -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 16DECC061755 for ; Fri, 8 Oct 2021 08:30:54 -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 879331F45B04; Fri, 8 Oct 2021 16:30:52 +0100 (BST) Date: Fri, 8 Oct 2021 17:30:43 +0200 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: [RFC PATCH 1/2] mtd: core: protect access to mtd devices while in suspend Message-ID: <20211008173043.6263ba80@collabora.com> In-Reply-To: <20211008143825.3717116-1-sean@geanix.com> References: <20211008141524.20ca8219@collabora.com> <20211008143825.3717116-1-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 Hi Sean, Can you please submit that as a separate thread, ideally with an incremented version number, a changelog and a reference to all your previous attempts. On Fri, 8 Oct 2021 16:38:24 +0200 Sean Nyekjaer wrote: > This will prevent reading/writing/erasing to a suspended mtd device. > It will force mtd_write()/mtd_read()/mtd_erase() to wait for > mtd_resume() to unlock access to mtd devices. I think this has to be done for all the hooks except ->_reboot(), ->_get_device() and ->_put_device(). > > Exec_op[0] speed things up, so we see this race when rawnand devices going Mention the commit directly: Commit ef347c0cfd61 ("mtd: rawnand: gpmi: Implement exec_op") speed things up, so we see this race when rawnand devices going ... > into suspend. But it's actually "mtd: rawnand: Simplify the locking" that But it's actually commit 013e6292aaf5 ("mtd: rawnand: Simplify the locking") that ... > allows it to return errors rather than locking, before that commit it would > have waited for the rawnand device to resume. > > Tested on a iMX6ULL. > > [0]: > ef347c0cfd61 ("mtd: rawnand: gpmi: Implement exec_op") > > Fixes: 013e6292aaf5 ("mtd: rawnand: Simplify the locking") > Signed-off-by: Sean Nyekjaer You flagged yourself as the author even though you didn't really write that code. I guess I'm fine with that, but I'd appreciate a Suggested-by: Boris Brezillon here, at least. > --- > > Hope I got it all :) > > drivers/mtd/mtdcore.c | 57 ++++++++++++++++++++++++++++++++++++++++- > include/linux/mtd/mtd.h | 36 ++++++++++++++++++-------- > 2 files changed, 81 insertions(+), 12 deletions(-) > > diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c > index c8fd7f758938..3c93202e6cbb 100644 > --- a/drivers/mtd/mtdcore.c > +++ b/drivers/mtd/mtdcore.c > @@ -36,6 +36,44 @@ > > struct backing_dev_info *mtd_bdi; > > +static void mtd_start_access(struct mtd_info *mtd) > +{ > + struct mtd_info *master = mtd_get_master(mtd); > + > + /* > + * Don't take the suspend_lock on devices that don't > + * implement the suspend hook. Otherwise, lockdep will > + * complain about nested locks when trying to suspend MTD > + * partitions or MTD devices created by gluebi which are > + * backed by real devices. > + */ > + if (!master->_suspend) > + return; > + You need to remove the ->_suspend()/->_resume() implementation in mtd_concat.c, otherwise you'll hit the case described in the comment. BTW, did you test this series with lockdep enabled to make sure we don't introduce a deadlock? > + /* > + * Wait until the device is resumed. Should we have a > + * non-blocking mode here? > + */ > + while (1) { > + down_read(&master->master.suspend_lock); > + if (!master->master.suspended) > + return; > + > + up_read(&master->master.suspend_lock); > + wait_event(master->master.resume_wq, master->master.suspended == 0); > + } > +} > + > +static void mtd_end_access(struct mtd_info *mtd) > +{ > + struct mtd_info *master = mtd_get_master(mtd); > + > + if (!master->_suspend) > + return; > + > + up_read(&master->master.suspend_lock); > +} > +