linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ira Weiny <ira.weiny@intel.com>
To: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: Dan Williams <dan.j.williams@intel.com>,
	Alison Schofield <alison.schofield@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Ben Widawsky <ben.widawsky@intel.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH 5/5] cxl/cdat: Parse out DSMAS data from CDAT table
Date: Wed, 10 Nov 2021 19:58:24 -0800	[thread overview]
Message-ID: <20211111035824.GM3538886@iweiny-DESK2.sc.intel.com> (raw)
In-Reply-To: <20211108145239.000010a5@Huawei.com>

On Mon, Nov 08, 2021 at 02:52:39PM +0000, Jonathan Cameron wrote:
> On Fri, 5 Nov 2021 16:50:56 -0700
> <ira.weiny@intel.com> wrote:
> 
> > From: Ira Weiny <ira.weiny@intel.com>
> > 
> > Parse and cache the DSMAS data from the CDAT table.  Store this data in
> > Unmarshaled data structures for use later.
> > 
> > Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> 
> A few minor comments inline.  In particular I think we need to conclude if
> failure to parse is an error or not.  Right now it's reported as an error
> but then we carry on anyway.

I report it as an error because if the device supports CDAT I made the
assumption that it was required for something up the stack.  However, I did not
want to make that decision at this point because all this code does is cache
the raw data.

So it may not be a fatal error depending on what the data is used for.  But IMO
it is still and error.

> 
> Jonathan
> 
> > 
> > ---
> > Changes from V4
> > 	New patch
> > ---
> >  drivers/cxl/core/memdev.c | 111 ++++++++++++++++++++++++++++++++++++++
> >  drivers/cxl/cxlmem.h      |  23 ++++++++
> >  2 files changed, 134 insertions(+)
> > 
> > diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> > index c35de9e8298e..e5a2d30a3491 100644
> > --- a/drivers/cxl/core/memdev.c
> > +++ b/drivers/cxl/core/memdev.c
> > @@ -6,6 +6,7 @@
> 
> ...
> 
> > +
> > +static int parse_dsmas(struct cxl_memdev *cxlmd)
> > +{
> > +	struct cxl_dsmas *dsmas_ary = NULL;
> > +	u32 *data = cxlmd->cdat_table;
> > +	int bytes_left = cxlmd->cdat_length;
> > +	int nr_dsmas = 0;
> > +	size_t dsmas_byte_size;
> > +	int rc = 0;
> > +
> > +	if (!data || !cdat_hdr_valid(cxlmd))
> 
> If that's invalid, right answer might be to run it again as we probably
> just raced with an update...  Perhaps try it a couple of times before
> failing hard?

I find it odd that the mailbox would return invalid data even during an update?

That said perhaps validating the header should be done as part of reading the
CDAT.

Thoughts?  Should I push this back to the previous patch?

> 
> > +		return -ENXIO;
> > +
> > +	/* Skip header */
> > +	data += CDAT_HEADER_LENGTH_DW;
> > +	bytes_left -= CDAT_HEADER_LENGTH_BYTES;
> > +
> > +	while (bytes_left > 0) {
> > +		u32 *cur_rec = data;
> > +		u8 type = FIELD_GET(CDAT_STRUCTURE_DW0_TYPE, cur_rec[0]);
> > +		u16 length = FIELD_GET(CDAT_STRUCTURE_DW0_LENGTH, cur_rec[0]);
> > +
> > +		if (type == CDAT_STRUCTURE_DW0_TYPE_DSMAS) {
> > +			struct cxl_dsmas *new_ary;
> > +			u8 flags;
> > +
> > +			new_ary = krealloc(dsmas_ary,
> > +					   sizeof(*dsmas_ary) * (nr_dsmas+1),
> 
> Spaces around the +

Sure.

> You could do this with devm_krealloc() and then just assign it at the end
> rather than allocate a new one and copy.

I failed to see that call when I wrote this...  yes thanks!

> 
> 
> > +					   GFP_KERNEL);
> > +			if (!new_ary) {
> > +				dev_err(&cxlmd->dev,
> > +					"Failed to allocate memory for DSMAS data\n");
> > +				rc = -ENOMEM;
> > +				goto free_dsmas;
> > +			}
> > +			dsmas_ary = new_ary;
> > +
> > +			flags = FIELD_GET(CDAT_DSMAS_DW1_FLAGS, cur_rec[1]);
> > +
> > +			dsmas_ary[nr_dsmas].dpa_base = CDAT_DSMAS_DPA_OFFSET(cur_rec);
> > +			dsmas_ary[nr_dsmas].dpa_length = CDAT_DSMAS_DPA_LEN(cur_rec);
> > +			dsmas_ary[nr_dsmas].non_volatile = CDAT_DSMAS_NON_VOLATILE(flags);
> > +
> > +			dev_dbg(&cxlmd->dev, "DSMAS %d: %llx:%llx %s\n",
> > +				nr_dsmas,
> > +				dsmas_ary[nr_dsmas].dpa_base,
> > +				dsmas_ary[nr_dsmas].dpa_base +
> > +					dsmas_ary[nr_dsmas].dpa_length,
> > +				(dsmas_ary[nr_dsmas].non_volatile ?
> > +					"Persistent" : "Volatile")
> > +				);
> > +
> > +			nr_dsmas++;
> > +		}
> > +
> > +		data += (length/sizeof(u32));
> 
> spaces around /

Yep.

> 

> > +		bytes_left -= length;
> > +	}
> > +
> > +	if (nr_dsmas == 0) {
> > +		rc = -ENXIO;
> > +		goto free_dsmas;
> > +	}
> > +
> > +	dev_dbg(&cxlmd->dev, "Found %d DSMAS entries\n", nr_dsmas);
> > +
> > +	dsmas_byte_size = sizeof(*dsmas_ary) * nr_dsmas;
> > +	cxlmd->dsmas_ary = devm_kzalloc(&cxlmd->dev, dsmas_byte_size, GFP_KERNEL);
> 
> As above, you could have done a devm_krealloc() and then just assigned here.
> Side effect of that being direct returns should be fine.

Yep devm_krealloc is much cleaner.

> However, that relies
> treating an error from this function as an error that will result in failures below.
> 
> 
> > +	if (!cxlmd->dsmas_ary) {
> > +		rc = -ENOMEM;
> > +		goto free_dsmas;
> > +	}
> > +
> > +	memcpy(cxlmd->dsmas_ary, dsmas_ary, dsmas_byte_size);
> > +	cxlmd->nr_dsmas = nr_dsmas;
> > +
> > +free_dsmas:
> > +	kfree(dsmas_ary);
> > +	return rc;
> > +}
> > +
> >  struct cxl_memdev *
> >  devm_cxl_add_memdev(struct cxl_dev_state *cxlds)
> >  {
> > @@ -339,6 +446,10 @@ devm_cxl_add_memdev(struct cxl_dev_state *cxlds)
> >  		cxl_mem_cdat_read_table(cxlds, cxlmd->cdat_table, cxlmd->cdat_length);
> >  	}
> >  
> > +	rc = parse_dsmas(cxlmd);
> > +	if (rc)
> > +		dev_err(dev, "No DSMAS data found: %d\n", rc);
> 
> dev_info() maybe as it's not being treated as an error?

This is an error.  But not a fatal error.

> 
> However I think it should be treated as an error.  It's a device failure if
> we can't parse this (and table protocol is available)

Shouldn't we let the consumer of this data determine if this is a fatal error and
bail out at that point?

Ira

> 
> If it turns out we need to quirk some devices, then fair enough.
> 
> 
> 
> > +
> >  	/*
> >  	 * Activate ioctl operations, no cxl_memdev_rwsem manipulation
> >  	 * needed as this is ordered with cdev_add() publishing the device.
> 

  reply	other threads:[~2021-11-11  3:58 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05 23:50 [PATCH 0/5] CXL: Read CDAT and DSMAS data from the device ira.weiny
2021-11-05 23:50 ` [PATCH 1/5] PCI: Add vendor ID for the PCI SIG ira.weiny
2021-11-17 21:50   ` Bjorn Helgaas
2021-11-05 23:50 ` [PATCH 2/5] PCI/DOE: Add Data Object Exchange Aux Driver ira.weiny
2021-11-08 12:15   ` Jonathan Cameron
2021-11-10  5:45     ` Ira Weiny
2021-11-18 18:48       ` Jonathan Cameron
2021-11-16 23:48   ` Bjorn Helgaas
2021-12-03 20:48     ` Dan Williams
2021-12-03 23:56       ` Bjorn Helgaas
2021-12-04 15:47         ` Dan Williams
2021-12-06 12:27           ` Jonathan Cameron
2021-11-05 23:50 ` [PATCH 3/5] cxl/pci: Add DOE Auxiliary Devices ira.weiny
2021-11-08 13:09   ` Jonathan Cameron
2021-11-11  1:31     ` Ira Weiny
2021-11-11 11:53       ` Jonathan Cameron
2021-11-16 23:48   ` Bjorn Helgaas
2021-11-17 12:23     ` Jonathan Cameron
2021-11-17 22:15       ` Bjorn Helgaas
2021-11-18 10:51         ` Jonathan Cameron
2021-11-19  6:48         ` Christoph Hellwig
2021-11-29 23:37           ` Dan Williams
2021-11-29 23:59             ` Dan Williams
2021-11-30  6:42               ` Christoph Hellwig
2021-11-05 23:50 ` [PATCH 4/5] cxl/mem: Add CDAT table reading from DOE ira.weiny
2021-11-08 13:21   ` Jonathan Cameron
2021-11-08 23:19     ` Ira Weiny
2021-11-08 15:02   ` Jonathan Cameron
2021-11-08 22:25     ` Ira Weiny
2021-11-09 11:09       ` Jonathan Cameron
2021-11-19 14:40   ` Jonathan Cameron
2021-11-05 23:50 ` [PATCH 5/5] cxl/cdat: Parse out DSMAS data from CDAT table ira.weiny
2021-11-08 14:52   ` Jonathan Cameron
2021-11-11  3:58     ` Ira Weiny [this message]
2021-11-11 11:58       ` Jonathan Cameron
2021-11-18 17:02   ` Jonathan Cameron
2021-11-19 14:55   ` Jonathan Cameron

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=20211111035824.GM3538886@iweiny-DESK2.sc.intel.com \
    --to=ira.weiny@intel.com \
    --cc=Jonathan.Cameron@Huawei.com \
    --cc=alison.schofield@intel.com \
    --cc=ben.widawsky@intel.com \
    --cc=bhelgaas@google.com \
    --cc=dan.j.williams@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=vishal.l.verma@intel.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;
as well as URLs for NNTP newsgroup(s).