All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: Richard Cheng <icheng@nvidia.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
	Jonathan Cameron <jic23@kernel.org>,
	Dave Jiang <dave.jiang@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Ira Weiny <iweiny@kernel.org>, Li Ming <ming.li@zohomail.com>,
	<linux-cxl@vger.kernel.org>,
	Sashiko AI Review <sashiko-bot@kernel.org>
Subject: Re: [PATCH v3 1/2] cxl/region: Allow passthrough decoders with >16K granularity
Date: Thu, 3 Sep 2026 20:17:04 -0700	[thread overview]
Message-ID: <apo4MPeJkMSvPOqy@aschofie-mobl2.lan> (raw)
In-Reply-To: <amxHLqcwROvNP6Mz@MWDK4CY14F>

On Fri, Jul 31, 2026 at 03:41:54PM +0800, Richard Cheng wrote:
> On Fri, Jul 24, 2026 at 06:08:54PM +0800, Alison Schofield wrote:

snip

> > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> > index 1e211542b6b6..5a443551288c 100644
> > --- a/drivers/cxl/core/region.c
> > +++ b/drivers/cxl/core/region.c
> > @@ -1521,12 +1521,20 @@ static int cxl_port_setup_targets(struct cxl_port *port,
> >  		parent_iw = parent_cxld->interleave_ways;
> >  	}
> >  
> > -	rc = granularity_to_eig(parent_ig, &peig);
> > -	if (rc) {
> > -		dev_dbg(&cxlr->dev, "%s:%s: invalid parent granularity: %d\n",
> > -			dev_name(parent_port->uport_dev),
> > -			dev_name(&parent_port->dev), parent_ig);
> > -		return rc;
> > +	/*
> > +	 * A non-interleaving parent does not encode its granularity, so its
> > +	 * stored value may exceed the maximum encodable and need not be
> > +	 * validated here.
> > +	 */
> > +	if (parent_iw > 1) {
> > +		rc = granularity_to_eig(parent_ig, &peig);
> > +		if (rc) {
> > +			dev_dbg(&cxlr->dev,
> > +				"%s:%s: invalid parent granularity: %d\n",
> > +				dev_name(parent_port->uport_dev),
> > +				dev_name(&parent_port->dev), parent_ig);
> > +			return rc;
> > +		}
> >  	}
> >  
> >  	rc = ways_to_eiw(parent_iw, &peiw);
> > @@ -1549,20 +1557,21 @@ static int cxl_port_setup_targets(struct cxl_port *port,
> >  	 * Interleave granularity is a multiple of @parent_port granularity.
> >  	 * Multiplier is the parent port interleave ways.
> >  	 */
> > -	rc = granularity_to_eig(parent_ig * parent_iw, &eig);
> > -	if (rc) {
> > -		dev_dbg(&cxlr->dev,
> > -			"%s: invalid granularity calculation (%d * %d)\n",
> > -			dev_name(&parent_port->dev), parent_ig, parent_iw);
> > -		return rc;
> > -	}
> > +	ig = parent_ig * parent_iw;
> >  
> > -	rc = eig_to_granularity(eig, &ig);
> > -	if (rc) {
> > -		dev_dbg(&cxlr->dev, "%s:%s: invalid interleave: %d\n",
> > -			dev_name(port->uport_dev), dev_name(&port->dev),
> > -			256 << eig);
> > -		return rc;
> > +	/*
> > +	 * Keep the computed granularity for descendant setup. Only
> > +	 * interleaving decoders require an encodable granularity.
> > +	 */
> > +	if (iw > 1) {
> > +		rc = granularity_to_eig(ig, &eig);
> > +		if (rc) {
> > +			dev_dbg(&cxlr->dev,
> > +				"%s: invalid granularity calculation (%d * %d)\n",
> > +				dev_name(&parent_port->dev), parent_ig,
> > +				parent_iw);
> > +			return rc;
> > +		}
> >  	}
> >
> 
> Hi Alison,
> 
> Looks sane to me, just that this check pattern appears twice and peig
> and eig are both write-only afterwards.
> Could they be formed into a helper or macro ?
> 
> Something like the following might do ?
> """
> static bool granularity_is_encodable(int ways, int granularity)
> {
>     u16 eig;
>     if (ways <= 1)
>         return true;
> 
>     return granularity_to_eig(granularity, &eig) == 0;
> }
> 
> if (!granularity_is_encodable(parent_iw, parent_ig) {
>     dev_dbg();
>     return -EINVAL;
> }
> """
> 
> Reviewed-by: Richard Cheng <icheng@nvidia.com>


Thanks Richard!
I took the helper but wrote it to return an errno rather than a bool
because it seemed that a bool would answer true for any gran at all
when ways is 1.

Went w the style of the other check_*() helpers in region.c that return
errno.

Please take a look in v4.

-- Alison


> 
> Best regards,
> Richard Cheng.
> 
> >  	if (iw > 8 || iw > cxlsd->nr_targets) {
> > -- 
> > 2.37.3
> > 
> > 

  reply	other threads:[~2026-09-04  3:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-25  1:08 [PATCH v3 0/2] cxl: Allow passthrough decoders with >16K granularity Alison Schofield
2026-07-25  1:08 ` [PATCH v3 1/2] cxl/region: " Alison Schofield
2026-07-25  1:26   ` sashiko-bot
2026-07-25  1:42     ` Alison Schofield
2026-07-31  7:41   ` Richard Cheng
2026-09-04  3:17     ` Alison Schofield [this message]
2026-07-25  1:08 ` [PATCH v3 2/2] cxl/test: Add a 2-way 16K root decoder for passthrough testing Alison Schofield
2026-07-31  7:44   ` Richard Cheng
2026-09-04  3:12     ` Alison Schofield
2026-07-27 23:36 ` [PATCH v3 0/2] cxl: Allow passthrough decoders with >16K granularity Dave Jiang

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=apo4MPeJkMSvPOqy@aschofie-mobl2.lan \
    --to=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=icheng@nvidia.com \
    --cc=iweiny@kernel.org \
    --cc=jic23@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=ming.li@zohomail.com \
    --cc=sashiko-bot@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 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.