Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3357403pxb; Mon, 4 Oct 2021 00:00:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqbUQUU9OUiT7yWDqcOaAd6L3ed0yW4joCs2mteQC5BZYx8+rwCHqETto5FawMKmra+dN8 X-Received: by 2002:a05:6402:2787:: with SMTP id b7mr1080136ede.285.1633330859697; Mon, 04 Oct 2021 00:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633330859; cv=none; d=google.com; s=arc-20160816; b=jH+HRLaMSPBFc8nylCU5BnlxLvcQXqKkzhGMdELplHblpVzzIHGURhWOefzwzcIyXT 15uEct3Fq6gIFiRgOijbMtuyfKu2fihaV7zOD0nOTIerfEgk72+5IrWqeNfHhWm4tZul r71emUUPCtgtGkO3nNsbIY02UoQXd5WDIvH0YX/0blhcv5EtXiyR1bLEYuOozSI81ttK nCPanvWoq+ymRJIFOLgt8Jk7/DS73Wii5ZrvpCQ3IzRdT/Iog1flHKx8oPYwe7jMRXm9 I/QRyafJB8YB0trPaMc6G9qTltuYMSE2dZlqGgmqqKXPHPTu9NRc9UdaFNi+lal+Frcb qa8g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=JTWzx8UZg7SehcaqZiFTht8delHg/EKmNux+MYmC8UY=; b=PrdvoQOzk9OTDtzKbvFz60jvqFr+URN8y/xWh6M/yMHKKdVhqTdnobMgM7PDc3tWHE +Yv165vvQmLQZxL4jEex3iKbqwxxxazui9jifQB/c0An2y3h4vSgME8zzPrBp8PUAdcX nm2oNbAlUeuuezfepTl9yxZLgksc5hGRnxC/LEF/N6emtyfpJFC5vCV7PeD66DI2YKGc JTCKk9pCEhQBBjqtjHuSRD8ZqM0eRCUOOKf5PRQh6U+mb7boA+DwV2wXGlHY3S1ABJYu vHtNezpDmZQBIgrNuY+BEMovl1NKXluopOMW4TGz8RU+1I4Emp6Xrcxb8c1Yb+gMXNel 9D4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=AwD6f2E5; 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=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h22si14323697ede.632.2021.10.04.00.00.34; Mon, 04 Oct 2021 00:00:59 -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; dkim=pass header.i=@geanix.com header.s=first header.b=AwD6f2E5; 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=pass (p=NONE sp=NONE dis=NONE) header.from=geanix.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232870AbhJDG6z (ORCPT + 99 others); Mon, 4 Oct 2021 02:58:55 -0400 Received: from first.geanix.com ([116.203.34.67]:37328 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232655AbhJDG6y (ORCPT ); Mon, 4 Oct 2021 02:58:54 -0400 Received: from zen.. (unknown [185.17.218.86]) by first.geanix.com (Postfix) with ESMTPSA id BA3F9B37B5; Mon, 4 Oct 2021 06:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1633330623; bh=Wz7aNGZ4h8K0IMIM6FbsYYWN7J3JFO9PsGOhVVuoFkY=; h=From:To:Cc:Subject:Date; b=AwD6f2E5sWwDs+CaLjRpQXJjc6jGgT6aLezeJEHWsymKs+ghV3r5iMaXOA+AbvMz0 IHdQbehtMACeFORXsOHY+Gp8vtFwBK1tUEMHUTmA/335JbGx+8NQ6lu56o9s8BJuWh sYaziK8VfzdNKK71AYkQFD+Z8hF7j+Mr3Jan+Mbdd3l2ULVLwaYR6tcmL6wc7kucTL eN3T/uYHxZpvODBr3NJgjTJsq0LTbVxRjdt/uB6ZMaNfk9U6wND07dUj2Sv8OIVU2h necZ0ghakrsdoB+ynGgdW2Ka+OXFHfXyGr9JsQJ+SvB5RtWOy7AMfbl9g4QXlNI2MI 9Ru28RmJDIp+A== From: Sean Nyekjaer To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Boris Brezillon Cc: Sean Nyekjaer , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] mtd: rawnand: use mutex to protect access while in suspend Date: Mon, 4 Oct 2021 08:56:09 +0200 Message-Id: <20211004065608.3190348-1-sean@geanix.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=4.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_BLOCKED autolearn=disabled version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 13e2a5895688 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This will prevent nand_get_device() from returning -EBUSY. It will force mtd_write()/mtd_read() to wait for the nand_resume() to unlock access to the mtd device. Then we avoid -EBUSY is returned to ubifsi via mtd_write()/mtd_read(), that will in turn hard error on every error returened. We have seen during ubifs tries to call mtd_write before the mtd device is resumed. Exec_op[0] speed things up, so we see this race when the device is resuming. But it's actually "mtd: rawnand: Simplify the locking" that allows it to return -EBUSY, before that commit it would have waited for the mtd 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 --- I did this a RFC as we probably will need to remove the suspended variable as it's kinda made obsolute by this change. Should we introduce a new mutex? Or maybe a spin_lock? drivers/mtd/nand/raw/nand_base.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 3d6c6e880520..0ea343404cac 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4567,7 +4567,6 @@ static int nand_suspend(struct mtd_info *mtd) ret = chip->ops.suspend(chip); if (!ret) chip->suspended = 1; - mutex_unlock(&chip->lock); return ret; } @@ -4580,7 +4579,6 @@ static void nand_resume(struct mtd_info *mtd) { struct nand_chip *chip = mtd_to_nand(mtd); - mutex_lock(&chip->lock); if (chip->suspended) { if (chip->ops.resume) chip->ops.resume(chip); -- 2.33.0