Re: [PATCH] libnvdimm: Fix nvdimm_probe error on NVDIMM-N

From: Kani, Toshimitsu
Date: Tue Aug 16 2016 - 11:22:14 EST


On Mon, 2016-08-15 at 14:20 -0700, Dan Williams wrote:
> On Mon, Aug 15, 2016 at 10:52 AM, Toshi Kani <toshi.kani@xxxxxxx>
> wrote:
> >
> > 'ndctl list --buses --dimms' does not list any NVDIMM-Ns since
> > they are considered as idle.ÂÂndctl checks if any driver is
> > attached to nmem device.ÂÂnvdimm_probe() always fails in
> > nvdimm_init_nsarea() since NVDIMM-Ns do not implement optinal
> > ND_CMD_GET_CONFIG_DATA command.
> >
> > Change nvdimm_probe() to accept the case that the CONFIG_DATA
> > command is not implemented for NVDIMM-Ns.ÂÂThe driver attaches
> > without ndd, which keeps it no-op to the device.
> >
> > Reported-by: Brian Boylston <brian.boylston@xxxxxxx>
> > Signed-off-by: Toshi Kani <toshi.kani@xxxxxxx>
> > Cc: Dan Williams <dan.j.williams@xxxxxxxxx>
> > ---
> > Âdrivers/nvdimm/dimm.cÂÂÂÂÂÂ|ÂÂÂ10 ++++++++++
> > Âdrivers/nvdimm/dimm_devs.c |ÂÂÂ27 ++++++++++++++++-----------
> > Âdrivers/nvdimm/nd.hÂÂÂÂÂÂÂÂ|ÂÂÂÂ1 +
> > Â3 files changed, 27 insertions(+), 11 deletions(-)
>
> This fails the ndctl unit test suite, see below plus some other
> cleanups...

Sorry, I had overlooked about this test suite... I built it to run the
test and was able to reproduce the failures.

> >
> > diff --git a/drivers/nvdimm/dimm.c b/drivers/nvdimm/dimm.c
> > index 71d12bb..07e09c2 100644
> > --- a/drivers/nvdimm/dimm.c
> > +++ b/drivers/nvdimm/dimm.c
> > @@ -26,6 +26,13 @@ static int nvdimm_probe(struct device *dev)
> > ÂÂÂÂÂÂÂÂstruct nvdimm_drvdata *ndd;
> > ÂÂÂÂÂÂÂÂint rc;
> >
> > +ÂÂÂÂÂÂÂrc = nvdimm_check_config_data(dev);
> > +ÂÂÂÂÂÂÂif (rc == -ENOENT)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ/* not required for non-aliased nvdimm, ex. NVDIMM-
> > N */
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn 0;
> > +ÂÂÂÂÂÂÂelse
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn rc;
> > +
>
> Change usage of ENOENT to ENOTTY throughout...

Will do.

> >
> > ÂÂÂÂÂÂÂÂndd = kzalloc(sizeof(*ndd), GFP_KERNEL);
> > ÂÂÂÂÂÂÂÂif (!ndd)
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn -ENOMEM;
> > @@ -72,6 +79,9 @@ static int nvdimm_remove(struct device *dev)
> > Â{
> > ÂÂÂÂÂÂÂÂstruct nvdimm_drvdata *ndd = dev_get_drvdata(dev);
> >
> > +ÂÂÂÂÂÂÂif (!ndd)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn 0;
> > +
> > ÂÂÂÂÂÂÂÂnvdimm_bus_lock(dev);
> > ÂÂÂÂÂÂÂÂdev_set_drvdata(dev, NULL);
> > ÂÂÂÂÂÂÂÂnvdimm_bus_unlock(dev);
> > diff --git a/drivers/nvdimm/dimm_devs.c
> > b/drivers/nvdimm/dimm_devs.c
> > index d9bba5e..fee82d3 100644
> > --- a/drivers/nvdimm/dimm_devs.c
> > +++ b/drivers/nvdimm/dimm_devs.c
> > @@ -28,28 +28,33 @@ static DEFINE_IDA(dimm_ida);
> > Â * Retrieve bus and dimm handle and return if this bus supports
> > Â * get_config_data commands
> > Â */
> > -static int __validate_dimm(struct nvdimm_drvdata *ndd)
> > +int nvdimm_check_config_data(struct device *dev)
> > Â{
> > -ÂÂÂÂÂÂÂstruct nvdimm *nvdimm;
> > -
> > -ÂÂÂÂÂÂÂif (!ndd)
> > -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn -EINVAL;
> > -
> > -ÂÂÂÂÂÂÂnvdimm = to_nvdimm(ndd->dev);
> > +ÂÂÂÂÂÂÂstruct nvdimm *nvdimm = to_nvdimm(dev);
> >
> > ÂÂÂÂÂÂÂÂif (!nvdimm->cmd_mask)
> > -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn -ENXIO;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂgoto err;
> > ÂÂÂÂÂÂÂÂif (!test_bit(ND_CMD_GET_CONFIG_DATA, &nvdimm->cmd_mask))
> > -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn -ENXIO;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂgoto err;
> >
> > ÂÂÂÂÂÂÂÂreturn 0;
> > +
> > + err:
> > +ÂÂÂÂÂÂÂif (nvdimm->flags & NDD_ALIASING)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn -ENXIO;
> > +ÂÂÂÂÂÂÂelse
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn -ENOENT;
>
>
> Let's not use "goto" since there is nothing to unwind.

Got it.

> >
> > Â}
> >
> > Âstatic int validate_dimm(struct nvdimm_drvdata *ndd)
> > Â{
> > -ÂÂÂÂÂÂÂint rc = __validate_dimm(ndd);
> > +ÂÂÂÂÂÂÂint rc;
> >
> > -ÂÂÂÂÂÂÂif (rc && ndd)
> > +ÂÂÂÂÂÂÂif (!ndd)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn -EINVAL;
>
> Since we've called nvdimm_check_config_data() before allocating ndd
> it will always be NULL causing DIMMs with label areas to fail init.

I am still puzzled at the moment, but will look into the issue.

Thanks!
-Toshi