Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1607988pxb; Mon, 11 Oct 2021 09:23:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxK0WlZVhbkvOZqOeMapgvfGsh8qfxuWxks+8fo4YeV0iScXoapzOT9blsOZcTMhZveYczK X-Received: by 2002:a17:90b:380d:: with SMTP id mq13mr31126041pjb.131.1633969394609; Mon, 11 Oct 2021 09:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969394; cv=none; d=google.com; s=arc-20160816; b=so3f8WSJdgCPrDnlMgunIog5ESNRW3LUdLdWuKaAStqedntdAqIKisyPV/0ptDJWGA p0s2V8csZOdpeZTu7UYXiB0/SE2KkAgjdQrDAjTDo1mOJN7w/qlbfpewRBQC8q/NeY5R Y62nAwWAKHqq/usnd1Ci2FIJcL0UerI85SqjNtKPORIs89mwFe/6yIqtaLCxW/t50s7P opW/Az8ICGgYASCGSxt38dlR/PaqsCbXGQQp3vaNDLHITDJX+b0YbFszT+Wqb5/mX7Fp me0EEpI+h/PuA3Fk5DetzIJ6wgNc8IkHSL3O0ZUg6kAhQQCnvQzmFk5/NvmdQX5WSrgr P/hg== 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=BTKtGFP17/26uXiYFhGfTxW5jaks8DGNt7EPIeDPZ6o=; b=rk2wkH0Yyl/+ZoYWwUZIpFHPuvo0ui0alRHKbkIXJQUzJnQVEDrwyBvjxQ6En/x4Yb RI2xKGTSG454PhSwWFDPH6UCA8QP4H/b6Juuff/3IxwG/6wlj6idBtbcjpE3/NpgOlAo ubeq7xxi01LQlfgQmYEjJYwabOrYgaZLQnMbQZ7w+Cz9U57XxPXz5Q/iFIhI2WF6BJPs 9ujxFmf1KlgIrsg9g87NQp5YKfv5sswI0UHED4Fcaagy4DExaOZS0IYZcbqm+jdHk2ah gIzs0E+OuISCnxhNjvAYVrbJjARZQVJCDYPKESb2eKUseWU2oBdXhKy+V1M4JJy0anKf B/MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=OsjGAR6d; 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 q13si11709631pgq.238.2021.10.11.09.23.00; Mon, 11 Oct 2021 09:23:14 -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=OsjGAR6d; 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 S236180AbhJKLzP (ORCPT + 99 others); Mon, 11 Oct 2021 07:55:15 -0400 Received: from first.geanix.com ([116.203.34.67]:37358 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234148AbhJKLzO (ORCPT ); Mon, 11 Oct 2021 07:55:14 -0400 Received: from zen.. (unknown [185.17.218.86]) by first.geanix.com (Postfix) with ESMTPSA id 11810C2CD3; Mon, 11 Oct 2021 11:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1633953192; bh=pbRkeukv21LDSj8H7Ux10RpLsbQPs7ZZl4KidK4wSvg=; h=From:To:Cc:Subject:Date; b=OsjGAR6dpz8i7hOsD+TCN++BHttqyMSMRGpetl+m5Weqs6Wqn70EZ3cO8gd5Yp9pT 1cCcBdZjibK0cS2ojAn7wGn9xyq+e/y4hqZh2cjhAPXE9Rr/XyiDEHW3gk4hfZKpiT t0VqIM2g7uOG0nnh3sCiKA7rxlSBQcxIZE3hT8Tq1wZPmNcqq68N561gTBPuooWiLw e1W9d1Yj2Bgfik4hvL3ohZD8F0yMX7n4YkodE67VRzkNFPyxQ/ArQhScyr8hiOau/Z xL6mwM5/cpiiwppgq8lbyYoZ/nVZOMm9I96HYezpkY8D9q2huZow7KUkCsZIeN3s9f n3tQ8NKs1zZ9w== From: Sean Nyekjaer To: Boris Brezillon Cc: Sean Nyekjaer , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Boris Brezillon , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/3] mtd: core: protect access to mtd devices while in suspend Date: Mon, 11 Oct 2021 13:52:50 +0200 Message-Id: <20211011115253.38497-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=-1.2 required=4.0 tests=ALL_TRUSTED,BAYES_40, 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 Follow-up on discussion in https://lkml.org/lkml/2021/10/4/41 Changes since from rfc v1/v2: - added access protection for all device access hooks in mtd_info. - added Suggested-by to [1/3] patch. - removed refereces to commit ef347c0cfd61 ("mtd: rawnand: gpmi: Implement exec_op") from commit msg as commit 013e6292aaf5 ("mtd: rawnand: Simplify the locking") is to be blamed. - tested on a kernel with LOCKDEP enabled. @Miquel: I havn't covered every ioctl, to me it looks like they havn't direct device access. One (small) issue still present. gpmi_nand.c uses the rwsem before it's initialized. Seems cumbersome to have every mtd/nand driver to call init_waitqueue_head() and init_rwsem(). Could we somehow move the call to mtd_set_dev_defaults() before nand_create_bbt()? --- nand: device found, Manufacturer ID: 0x98, Chip ID: 0xdc nand: Toshiba NAND 512MiB 3,3V 8-bit nand: 512 MiB, SLC, erase size: 256 KiB, page size: 4096, OOB size: 128 ------------[ cut here ]------------ WARNING: CPU: 0 PID: 1 at kernel/locking/rwsem.c:1240 down_read+0x160/0x184 DEBUG_RWSEMS_WARN_ON(sem->magic != sem): count = 0x0, magic = 0x0, owner = 0x0, curr 0xc40b0000, list not empty Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.15.0-rc3-00002-g7eab985fa8cd-dirty #163 Hardware name: Freescale i.MX6 Ultralite (Device Tree) [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (dump_stack_lvl+0x58/0x70) [] (dump_stack_lvl) from [] (__warn+0xd4/0x154) [] (__warn) from [] (warn_slowpath_fmt+0x94/0xbc) [] (warn_slowpath_fmt) from [] (down_read+0x160/0x184) [] (down_read) from [] (mtd_read_oob+0xc8/0x284) [] (mtd_read_oob) from [] (scan_block_fast+0x78/0xf4) [] (scan_block_fast) from [] (search_bbt+0x268/0x304) [] (search_bbt) from [] (nand_create_bbt+0x240/0x6dc) [] (nand_create_bbt) from [] (gpmi_nand_probe+0x568/0x6d0) [] (gpmi_nand_probe) from [] (platform_probe+0x58/0xb8) [] (platform_probe) from [] (really_probe.part.0+0x9c/0x32c) [] (really_probe.part.0) from [] (__driver_probe_device+0xa0/0x138) [] (__driver_probe_device) from [] (driver_probe_device+0x30/0x10c) [] (driver_probe_device) from [] (__driver_attach+0xb4/0x174) [] (__driver_attach) from [] (bus_for_each_dev+0x78/0xb8) [] (bus_for_each_dev) from [] (bus_add_driver+0xf0/0x1d8) [] (bus_add_driver) from [] (driver_register+0x88/0x118) [] (driver_register) from [] (do_one_initcall+0x74/0x378) [] (do_one_initcall) from [] (kernel_init_freeable+0x2a4/0x348) [] (kernel_init_freeable) from [] (kernel_init+0x10/0x124) [] (kernel_init) from [] (ret_from_fork+0x14/0x38) Exception stack(0xc40a7fb0 to 0xc40a7ff8) 7fa0: ???????? ???????? ???????? ???????? 7fc0: ???????? ???????? ???????? ???????? ???????? ???????? ???????? ???????? 7fe0: ???????? ???????? ???????? ???????? ???????? ???????? irq event stamp: 110936 hardirqs lastenabled at (110935): [] __irq_svc+0x64/0x80 hardirqs last disabled at (110936): [] __irq_svc+0x50/0x80 softirqs lastenabled at (110906): [] netlink_insert+0x60/0x8a4 softirqs last disabled at (110904): [] release_sock+0x18/0x98 ---[ end trace c70a1a8da23b619d ]--- Bad block table found at page 131008, version 0x01 Bad block table found at page 130944, version 0x01 --- Sean Nyekjaer (3): mtd: core: protect access to MTD devices while in suspend mtd: rawnand: remove suspended check mtd: mtdconcat: add suspend lock handling drivers/mtd/mtdconcat.c | 11 ++- drivers/mtd/mtdcore.c | 133 +++++++++++++++++++++++++++---- drivers/mtd/nand/raw/nand_base.c | 52 +++--------- include/linux/mtd/mtd.h | 109 +++++++++++++++++++++---- include/linux/mtd/rawnand.h | 5 +- 5 files changed, 234 insertions(+), 76 deletions(-) -- 2.33.0