All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yuquan Wang <wangyuquan1236@phytium.com.cn>
To: Fan Ni <nifan.cxl@gmail.com>
Cc: dave@stgolabs.net, jonathan.cameron@huawei.com,
	dave.jiang@intel.com, alison.schofield@intel.com,
	vishal.l.verma@intel.com, ira.weiny@intel.com,
	dan.j.williams@intel.com, linux-cxl@vger.kernel.org,
	linux-kernel@vger.kernel.org, chenbaozi@phytium.com.cn
Subject: Re: [PATCH v3 1/1] cxl/pmem: debug invalid serial number data
Date: Tue, 18 Feb 2025 11:01:23 +0800	[thread overview]
Message-ID: <Z7P4A+3hfRdNnMM3@phytium.com.cn> (raw)
In-Reply-To: <67b3ee67.a70a0220.21e7fd.0285@mx.google.com>

On Mon, Feb 17, 2025 at 06:20:18PM -0800, Fan Ni wrote:
> On Tue, Feb 18, 2025 at 09:47:46AM +0800, Yuquan Wang wrote:
> > In a nvdimm interleave-set each device with an invalid or zero
> > serial number may cause pmem region initialization to fail, but in
> > cxl case such device could still set cookies of nd_interleave_set
> > and create a nvdimm pmem region.
> > 
> > This adds the validation of serial number in cxl pmem region creation.
> > The event of no serial number would cause to fail to set the cookie
> > and pmem region.
> > 
> > For cxl-test to work properly, always +1 on mock device's serial
> > number.
> > 
> > Signed-off-by: Yuquan Wang <wangyuquan1236@phytium.com.cn>
> > ---
> >  drivers/cxl/pmem.c           | 8 ++++++++
> >  tools/testing/cxl/test/mem.c | 2 +-
> >  2 files changed, 9 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c
> > index f9c95996e937..73787afe1b9d 100644
> > --- a/drivers/cxl/pmem.c
> > +++ b/drivers/cxl/pmem.c
> > @@ -383,6 +383,14 @@ static int cxl_pmem_region_probe(struct device *dev)
> >  			.position = i,
> >  		};
> >  		info[i].offset = m->start;
> > +
> > +		if (cxlds->serial == 0) {
> > +			/* include missing alongside invalid in this error message. */
> > +			dev_err(dev, "%s: invalid or missing serial number\n",
> > +				dev_name(&cxlmd->dev));
> > +			rc = -ENXIO;
> > +			goto out_nvd;
> > +		}
> 
> Should we do the check earlier in the code? 
> For example, right below if (!nvdimm) {}
> 
> Fan

I agree. This would removes unnecessary struct value assignments
and make the code easier to read. Jonathan, what's your opinion?

Yuquan

> 
> >  		info[i].serial = cxlds->serial;
> >  	}
> >  	ndr_desc.num_mappings = cxlr_pmem->nr_mappings;
> > diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
> > index 8d731bd63988..9e098cf06603 100644
> > --- a/tools/testing/cxl/test/mem.c
> > +++ b/tools/testing/cxl/test/mem.c
> > @@ -1533,7 +1533,7 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
> >  	mds->event.buf = (struct cxl_get_event_payload *) mdata->event_buf;
> >  	INIT_DELAYED_WORK(&mds->security.poll_dwork, cxl_mockmem_sanitize_work);
> >  
> > -	cxlds->serial = pdev->id;
> > +	cxlds->serial = pdev->id + 1;
> >  	if (is_rcd(pdev))
> >  		cxlds->rcd = true;
> >  
> > -- 
> > 2.34.1
> > 


  reply	other threads:[~2025-02-18  3:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-18  1:47 [PATCH v3 0/1] cxl/pmem: debug invalid serial number data Yuquan Wang
2025-02-18  1:47 ` [PATCH v3 1/1] " Yuquan Wang
2025-02-18  2:20   ` Fan Ni
2025-02-18  3:01     ` Yuquan Wang [this message]
2025-02-18 17:08       ` 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=Z7P4A+3hfRdNnMM3@phytium.com.cn \
    --to=wangyuquan1236@phytium.com.cn \
    --cc=alison.schofield@intel.com \
    --cc=chenbaozi@phytium.com.cn \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=ira.weiny@intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nifan.cxl@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.