Re: [PATCH v8 24/25] powerpc: Adopt nvram module for PPC64

From: Finn Thain
Date: Mon Dec 31 2018 - 20:38:50 EST


On Mon, 31 Dec 2018, Arnd Bergmann wrote:

> On Sun, Dec 30, 2018 at 4:29 AM Finn Thain <fthain@xxxxxxxxxxxxxxxxxxx> wrote:
> >
> > On Sat, 29 Dec 2018, Arnd Bergmann wrote:
> >
> > > On Wed, Dec 26, 2018 at 1:43 AM Finn Thain <fthain@xxxxxxxxxxxxxxxxxxx> wrote:
> > >
> > > > +static ssize_t ppc_nvram_get_size(void)
> > > > +{
> > > > + if (ppc_md.nvram_size)
> > > > + return ppc_md.nvram_size();
> > > > + return -ENODEV;
> > > > +}
> > >
> > > > +const struct nvram_ops arch_nvram_ops = {
> > > > + .read = ppc_nvram_read,
> > > > + .write = ppc_nvram_write,
> > > > + .get_size = ppc_nvram_get_size,
> > > > + .sync = ppc_nvram_sync,
> > > > +};
> > >
> > > Coming back to this after my comment on the m68k side, I notice that
> > > there is now a double indirection through function pointers. Have
> > > you considered completely removing the operations from ppc_md
> > > instead by having multiple copies of nvram_ops?
> > >
> >
> > I considered a few alternatives. I figured that it was refactoring
> > that could be deferred, as it would be confined to arch/powerpc. I was
> > more interested in the cross-platform API.
>
> Fair enough.
>
> > > With the current method, it does seem odd to have a single
> > > per-architecture instance of the exported structure containing
> > > function pointers. This doesn't give us the flexibility of having
> > > multiple copies in the kernel the way that ppc_md does, but it adds
> > > overhead compared to simply exporting the functions directly.
> > >
> >
> > You're right, there is overhead here.
> >
> > With a bit of auditing, wrappers like the one you quoted (which merely
> > checks whether or not a ppc_md method is implemented) could surely be
> > avoided.
> >
> > The arch_nvram_ops methods are supposed to optional (that is, they are
> > allowed to be NULL).
> >
> > We could call exactly the same function pointers though either ppc_md
> > or arch_nvram_ops. That would avoid the double indirection.
>
> I think you can have a 'const' structure in the __ro_after_init section,
> so without changing anything else, powerpc could just copy the function
> pointers from ppc_md into the arch_nvram_ops at early init time, which
> should ideally simplify your implementation as well.
>

This "early init time" could be hard to pin down... It has to be after
ppc_md methods are initialized but before the nvram_ops methods get used
(e.g. by the framebuffer console). Seems a bit fragile (?)

Your suggestion to completely remove the ppc_md.nvram* methods might be a
better way. It just means functions get assigned to nvram_ops pointers
instead of ppc_md pointers.

The patch is simple enough, but it assumes that arch_nvram_ops is not
const. The struct machdep_calls ppc_md is not const, so should we worry
about dropping the const for the struct nvram_ops arch_nvram_ops?

--

> Arnd
>