public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: "Winkler, Tomas" <tomas.winkler@intel.com>
Cc: Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	linux-mtd <linux-mtd@lists.infradead.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mtd: use refcount to prevent corruption
Date: Thu, 28 Jan 2021 10:00:32 +0100	[thread overview]
Message-ID: <20210128100032.5eb542c6@xps13> (raw)
In-Reply-To: <f91d7eff1d764ba7b47f023bc0fafacb@intel.com>

Hi Tomas,

"Winkler, Tomas" <tomas.winkler@intel.com> 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

  reply	other threads:[~2021-01-28  9:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27 20:03 [PATCH] mtd: use refcount to prevent corruption Tomas Winkler
2021-01-27 20:46 ` Richard Weinberger
2021-01-27 20:55   ` Winkler, Tomas
2021-01-27 21:17     ` Richard Weinberger
2021-01-28  6:33       ` Winkler, Tomas
2021-01-28  7:47         ` Richard Weinberger
2021-01-28  8:53           ` Winkler, Tomas
2021-01-28  9:00             ` Miquel Raynal [this message]
2021-01-28 17:57               ` Winkler, Tomas
2021-01-28 20:23                 ` Richard Weinberger
2021-02-13 17:09                   ` Winkler, Tomas
2021-02-15 13:43                     ` Richard Weinberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210128100032.5eb542c6@xps13 \
    --to=miquel.raynal@bootlin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=tomas.winkler@intel.com \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox