public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: "Michael Walle" <michael@walle.cc>
Cc: "Marco Felsch" <m.felsch@pengutronix.de>,
	<srinivas.kandagatla@linaro.org>, <gregkh@linuxfoundation.org>,
	<rafal@milecki.pl>, <linux-kernel@vger.kernel.org>,
	<kernel@pengutronix.de>
Subject: Re: [RFC PATCH] nvmem: core: add sysfs cell write support
Date: Tue, 20 Feb 2024 10:18:11 +0100	[thread overview]
Message-ID: <20240220101811.6ae23f2e@xps-13> (raw)
In-Reply-To: <CZ938PEUZ1JQ.2DJE7C03HI9OO@walle.cc>

Hi,

michael@walle.cc wrote on Mon, 19 Feb 2024 14:26:16 +0100:

> On Mon Feb 19, 2024 at 12:53 PM CET, Marco Felsch wrote:
> > On 24-02-19, Miquel Raynal wrote:  
> > > Hi Marco,
> > > 
> > > m.felsch@pengutronix.de wrote on Fri, 16 Feb 2024 11:07:50 +0100:
> > >   
> > > > Hi Michael,
> > > > 
> > > > On 24-02-16, Michael Walle wrote:  
> > > > > Hi,
> > > > > 
> > > > > On Thu Feb 15, 2024 at 10:14 PM CET, Marco Felsch wrote:    
> > > > > > @@ -432,6 +466,7 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
> > > > > >  	struct bin_attribute **cells_attrs, *attrs;
> > > > > >  	struct nvmem_cell_entry *entry;
> > > > > >  	unsigned int ncells = 0, i = 0;
> > > > > > +	umode_t mode;
> > > > > >  	int ret = 0;
> > > > > >  
> > > > > >  	mutex_lock(&nvmem_mutex);
> > > > > > @@ -456,15 +491,18 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
> > > > > >  		goto unlock_mutex;
> > > > > >  	}
> > > > > >  
> > > > > > +	mode = nvmem_bin_attr_get_umode(nvmem);
> > > > > > +
> > > > > >  	/* Initialize each attribute to take the name and size of the cell */
> > > > > >  	list_for_each_entry(entry, &nvmem->cells, node) {
> > > > > >  		sysfs_bin_attr_init(&attrs[i]);
> > > > > >  		attrs[i].attr.name = devm_kasprintf(&nvmem->dev, GFP_KERNEL,
> > > > > >  						    "%s@%x", entry->name,
> > > > > >  						    entry->offset);
> > > > > > -		attrs[i].attr.mode = 0444;    
> > > > > 
> > > > > cells are not writable if there is a read post process hook, see
> > > > > __nvmem_cell_entry_write().
> > > > > 
> > > > > if (entry->read_post_processing)
> > > > > 	mode &= ~0222;    
> > > > 
> > > > good point, thanks for the hint :) I will add this and send a non-rfc
> > > > version if write-support is something you would like to have.  
> > > 
> > > I like the idea but, what about mtd devices (and soon maybe UBI
> > > devices)? This may only work on EEPROM-like devices I guess, where each
> > > area is fully independent and where no erasure is actually expected.  
> >
> > For MTD I would say that you need to ensure that you need to align the
> > cells correctly. The cell-write should handle the page erase/write cycle
> > properly. E.g. an SPI-NOR need to align the cells to erase-page size or
> > the nvmem-cell-write need to read-copy-update the cells if they are not
> > erase-paged aligned.
> >
> > Regarding UBI(FS) I'm not sure if this is required at all since you have
> > an filesystem. IMHO nvmem-cells are very lowelevel and are not made for
> > filesystem backed backends.

I'm really talking about UBI, not UBIFS. UBI is just like MTD but
handles wear leveling. There is a pending series for enabling nvmem
cells on top of UBI.

> > That beeing said: I have no problem if we provide write support for
> > EEPROMs only and adapt it later on to cover spi-nor/nand devices as
> > well.  
> 
> Agreed. Honestly, I don't know how much sense this makes for MTD
> devices. First, the operation itself, seems really dangerous, as
> you'll have to delete the whole sector. Second, during initial
> provisioning, I don't think it will make much sense to use the sysfs
> cells because you cannot combine multiple writes into one. You'll
> always end up with unnecessary erases.

One cell per erase block would be an immense waste.
Read-copy-update would probably work but would as well be very
sub-optimal. I guess we could live with it, but as for now there has
not been any real request for it, I'd also advise to keep this feature
out of the mtd world in general.

Thanks,
Miquèl

  reply	other threads:[~2024-02-20  9:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-15 21:14 [RFC PATCH] nvmem: core: add sysfs cell write support Marco Felsch
2024-02-16  8:47 ` Michael Walle
2024-02-16 10:07   ` Marco Felsch
2024-02-19 11:04     ` Miquel Raynal
2024-02-19 11:53       ` Marco Felsch
2024-02-19 13:26         ` Michael Walle
2024-02-20  9:18           ` Miquel Raynal [this message]
2024-02-20  9:50             ` Marco Felsch
2024-02-20 10:07               ` Miquel Raynal
2024-02-20 10:16               ` Michael Walle

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=20240220101811.6ae23f2e@xps-13 \
    --to=miquel.raynal@bootlin.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.felsch@pengutronix.de \
    --cc=michael@walle.cc \
    --cc=rafal@milecki.pl \
    --cc=srinivas.kandagatla@linaro.org \
    /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