Re: [PATCH v8 5/9] block: implement NVMEM provider
From: Loic Poulain
Date: Fri Jul 24 2026 - 05:18:21 EST
Hi Christoph,
On Fri, Jul 24, 2026 at 6:57 AM Christoph Hellwig <hch@xxxxxxxxxxxxx> wrote:
>
> On Fri, Jul 03, 2026 at 03:45:18PM +0200, Loic Poulain wrote:
> > + Allow block devices (or partitions) to act as NVMEM providers,
>
> Based on the code below I don't think you actually support partitions.
Right, I was planning to add partition support in a follow-up series.
But since this is really supposed to be a block-agnostic feature,
whether it's a disk or a partition, I'll include partition in v8.
>
> > +static int blk_nvmem_reg_read(void *priv, unsigned int from, void *val, size_t bytes)
>
> Overly long line.
>
> > +{
> > + dev_t devt = (dev_t)(uintptr_t)priv;
> > + size_t bytes_left = bytes;
> > + loff_t pos = from;
> > + int ret = 0;
> > +
> > + struct file *bdev_file __free(fput) =
> > + bdev_file_open_by_dev(devt, BLK_OPEN_READ, NULL, NULL);
>
> Please try to avoid all that magic autfree stuff that makes the code
> impossible to read about.
Ack, I've received mixed feedback on this. However, given that there
aren't any particularly complex or numerous exit paths, I guess the
explicit release will make the code clearer.
> > + if (IS_ERR(bdev_file))
> > + return PTR_ERR(bdev_file);
> > +
> > + while (bytes_left) {
>
> .. and just use __kernel_read instead of badly reimplementing it.
Ack.
>
> > + config.name = dev_name(dev);
> > + config.owner = THIS_MODULE;
> > + config.priv = (void *)(uintptr_t)dev->devt;
>
> Why is this storing the dev_t and not the block device itself?
It was originally intended to avoid races with device removal, but now
that we're synchronized with the block subsystem, that's no longer
strictly necessary.
>
> > +
> > + blk_nvmem_add(disk->part0);
>
> Hmm, and you're always doing it for the whole device. So the intefaces
> really should be based on a gendisk, not a block_device.
I will add it for partitions as well.
>
> Also once you register the whole devices as nvmem provider, we really
> should keep it from being used a block device, shouldn't we?
I'm not sure, the whole concept is block backed NVMEM, so we still
need to add that block as base layer, though we could discuss
suppressing uevent for it. Preventing block usage would make the
feature much more intrusive than other NVMEM providers like MTD, where
the underlying device stays accessible. And we may genuinely still
want to write the disk (e.g. for factory provisioning), updating the
very data the cells point to, etc. There's also the layering aspect,
if a disk (e.g. mmcblk0) has logical partitions on top (mmcblk0pX), we
still register/expose the whole disk mmcblk0 as a block device
regardless. So if a disk contains NVMEM cells, I think it should still
be exposed as a block device as well.
Regards,
Loic