Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp834146pxb; Thu, 28 Jan 2021 01:03:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0vcKg5rEnXAzIfXyZ+nH17HqoMw/m905rq5oChv04YNN/+tVfDM+fwYdizvY86N+90n7Y X-Received: by 2002:a17:906:6407:: with SMTP id d7mr8645913ejm.133.1611824592481; Thu, 28 Jan 2021 01:03:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611824592; cv=none; d=google.com; s=arc-20160816; b=FMHfoNoPoMo9CfiKiY6WVzuS02uCTJ0Ict1pfqB7d1aMXfD3GerKJxy+WATlldzDUw d1bgHGfK7kOMiM8lEOtIKp1rGBxP+WfZIikw/X7LtXDBjPzPmcrY/fF08oylBMIOy21w YRZwy9Ch60MzcRndCA8FuXzly0kYPp9ahnnb6CQf6yPiyopbkTTJvCuawl+4xRmS+GjV 3QGbP7S6mGEVu+EthStyMI/eMrUx4AubZdVgwVLd8JAjTRR70gQ7j0aWvdcIz6cLAtt8 dVEsgwgnERTY7OJTZpeBbKpkGUEUnZkF+H8zj5yOZi2QFAysLg+I0gO8+QxwuWcjdSGf Rnqw== 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=+Un8B8UjDgdgWqCEFk1yMZJPY+5p3v8hKjjzLz4ruck=; b=LyI6/zO+83G+OJJ7Pl0/ocAw3RWIc7AoiY4fDjlardexeog2TQI0z8BBhl1mzHisC2 A77kSrM7n+KGwo2UBKxbOvbkNrV8W3jc64Bcm4wgozojKBRauz4XQGt/cj3ICuvCzDtc RIfLVKHgbnmlN/et031JhCCqUrzq6O2RAl6ReU23TRbFKX8jiHJbCe/fTR5nzEzLHIMn uZMy3hc/6gGJPh2SFLKUTouauOYEs5G8NqEskTZG+ea52NQA7RHW19HnioZBZM7wuQVr aH5PS2tpst3nfSViZvWUyEDW6NmR8UJ76zALR1pejFz24znRqQI0J+5NoLmKLsse9IMl azrQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dc22si833434edb.145.2021.01.28.01.02.47; Thu, 28 Jan 2021 01:03:12 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231610AbhA1I7x convert rfc822-to-8bit (ORCPT + 99 others); Thu, 28 Jan 2021 03:59:53 -0500 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:42593 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231583AbhA1I7w (ORCPT ); Thu, 28 Jan 2021 03:59:52 -0500 X-Originating-IP: 86.210.203.150 Received: from xps13 (lfbn-tou-1-972-150.w86-210.abo.wanadoo.fr [86.210.203.150]) (Authenticated sender: miquel.raynal@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id A1B11FF818; Thu, 28 Jan 2021 09:00:33 +0000 (UTC) Date: Thu, 28 Jan 2021 10:00:32 +0100 From: Miquel Raynal To: "Winkler, Tomas" Cc: Richard Weinberger , Vignesh Raghavendra , linux-mtd , linux-kernel Subject: Re: [PATCH] mtd: use refcount to prevent corruption Message-ID: <20210128100032.5eb542c6@xps13> In-Reply-To: References: <20210127200319.662842-1-tomas.winkler@intel.com> <9732911.325628.1611780400338.JavaMail.zimbra@nod.at> <1776363776.325713.1611782270873.JavaMail.zimbra@nod.at> <1665542284.336646.1611820031174.JavaMail.zimbra@nod.at> Organization: Bootlin X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tomas, "Winkler, Tomas" wrote on Thu, 28 Jan 2021 08:53:43 +0000: > > Tomas, > > > > ----- Ursprüngliche Mail ----- > > >> >> Can you please explain a little more what devices are involved? > > >> >> Does it implement _get_device() and _put_device()? > > >> > No this is not connected to those handlers of the underlying device > > >> > and those won't help. > > >> > I have a spi device provided by MFD framework so it can go away anytime. > > >> > > >> Can it go away physically or just in software? > > > Software, but since this is mfd it's basically hotplug. The kernel is > > > crashing when I simulate hardware failure. > > >> > > >> Usually the pattern is that you make sure in the device driver that > > >> nobody can orphan the MTD while it is in use. > > >> e.g. drivers/mtd/ubi/gluebi.c does so. In _get_device() it grabs a > > >> reference on the underlying UBI volume to make sure it cannot go away > > >> while the MTD (on top of UBI) is in use. > > > > > > I can try that if it helps, because we are simulating possible lower > > > level crash. > > > In an case I believe that the proper refcouting is much more robust > > > solution, than the current one. > > > I'd appreciate if someone can review the actual implementation. > > > > This happens right now, I try to understand why exactly the current way is not > > good in enough. :-) > > > > Your approach makes sure that the MTD itself does not go away while it has > > users but how does this help in the case where the underlying MFD just > > vanishes? > > The MTD can be in use and the MFD can go away while e.g. mtd_read() or such > > takes place. > > Read will fail, but kernel won't crash on access to memory that was freed. As Richard was saying, we are really open to enhance MTD refcounting. However, the issue you are facing is, IMHO, not related to MTD but to MFD. There should be a way to avoid MFD to vanish by taking a reference of it through mtd->_get_device(). I don't think addressing the case where MFD vanishes while MTD (as a user) is still active is the right approach. Thanks, Miquèl