From: Alison Schofield <alison.schofield@intel.com>
To: Robert Richter <rrichter@amd.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>
Subject: Re: [PATCH v3 2/9] cxl/region: Validate interleave selector bits
Date: Thu, 20 Aug 2026 15:14:30 -0700 [thread overview]
Message-ID: <aod8RoI1gJoKkrry@aschofie-mobl2.lan> (raw)
In-Reply-To: <aoQiLpojRvgfZA7I@rric.localdomain>
On Tue, Aug 18, 2026 at 11:13:18AM +0200, Robert Richter wrote:
> On 30.07.26 15:20:22, Alison Schofield wrote:
> > Each decoder level in an interleave uses a field of host physical
> > address (HPA) bits, called a selector, to choose which of its
> > downstream targets a given address routes to. In a multi-level
> > interleave the selectors of the root, the switches, and the endpoints
> > must occupy distinct address bits so that every level makes an
> > independent routing decision.
> >
> > The existing setup does not check the selectors directly. It instead
> > requires each level's granularity to equal the parent granularity
> > multiplied by the parent ways, which only holds for a subset of the
> > legal selector layouts. Layouts that place non-overlapping selectors
> > in a different order, as mixed-granularity regions do, are rejected
> > even though they are valid.
> >
> > Add selector-bit accounting to cxl_port_setup_targets(). Accumulate
> > the selector of each level from the root toward the current port,
> > reject any selector that overlaps a bit already claimed by another
> > level, and reject an accumulated selector that does not fit within
> > the region selector. The root decoder's selector is walked alongside
> > the switch levels rather than tracked separately.
> >
> > This patch adds selector validation but does not yet enable the
> > mixed-granularity layouts. A temporary gate rejects region granularity
> > finer than the root granularity until the position arithmetic is
> > updated.
Thanks for the review Robert,
I took the simplification comments here more broadly in v4. The selector
accumulation, fanout tracking, and the associated single-use helpers are
all gone. Port decoder setup now derives the needed geometry directly from
the parent granularity and target count.
Replies to the individual comments below.
snip
> > +/**
> > + * get_parent_selectors() - Collect selectors and fan-out above a port
> > * @parent_port: first ancestor port
> > * @cxlr: region under construction
> > + * @cxlrd: region root decoder
> > + * @accum: filled with the selectors claimed by the ancestors
> > * @fanout: filled with the product of the ancestor switch ways
> > *
> > - * Walk from @parent_port to the root and multiply the interleave ways of
> > - * each switch decoder. Root decoder ways are not included.
> > + * Start with the root decoder selector and walk the ancestor switch
> > + * decoders. Reject selectors that overlap. Passthrough decoders contribute
> > + * neither selector bits nor fan-out.
> > *
> > - * Return: 0 on success.
> > + * Root decoder ways are not included in @fanout.
> > + *
> > + * Return: 0 on success, -ENXIO on selector overlap.
> > */
>
> See my comment on comments in the previous patch. It should not be
> documented.
Agreed. This helper and its kernel-doc are gone in v4.
snip
> > +/**
> > + * region_selectors_fit() - Check ancestor selectors against the region
> > + * @port: port being configured
> > + * @cxlr: region under construction
> > + * @accum: selectors used by the ancestor decoders
> > + *
> > + * Return: true when every accumulated selector bit is present in the region
> > + * selector.
> > + */
> > +static bool region_selectors_fit(struct cxl_port *port,
> > + struct cxl_region *cxlr, u64 accum)
>
> Better have this inline in the code, this functions does not help
> much.
This helper is gone in v4. The selector-fit validation it was wrapping
is gone as well with the selector-walk approach.
snip
> > @@ -1517,6 +1594,7 @@ static int cxl_port_setup_targets(struct cxl_port *port,
> > int ig, iw = cxl_rr->nr_targets;
> > int fanout, rc;
> > int pos = cxled->pos;
> > + u64 accum;
>
> rename: "total_sel", "parent_sel", ...?
Agree that accum was not very descriptive. The accumulated selector
state is gone in v4, so the variable disappears with it.
>
> > u16 eig;
> > u8 eiw;
> >
> > @@ -1538,10 +1616,13 @@ static int cxl_port_setup_targets(struct cxl_port *port,
> > return -ENXIO;
> > }
> >
> > - rc = get_parent_fanout(parent_port, cxlr, &fanout);
> > + rc = get_parent_selectors(parent_port, cxlr, cxlrd, &accum, &fanout);
>
> An easy and straight for loop could be a good alternative.
Yes. This was another sign that the helper structure was getting in the
way. v4 drops this ancestor selector walk entirely rather than moving it
back inline.
>
> fanout can be dropped from the function interface. Weight of the
> selector can be used instead.
>
The fanout state is gone in v4, along with the selector accumulation.
I did not replace it with selector weight, though. The v4 approach
derives each decoder's granularity directly from its parent granularity
and target count, which also accounts for the mod3 configurations.
> > if (rc)
> > return rc;
> >
> > + if (!region_selectors_fit(port, cxlr, accum))
> > + return -ENXIO;
> > +
>
> Without a helper it is actually better readable:
>
> cxlr_sel = ...;
> total_sel = ...;
>
> if ((cxlr_sel & total_sel) != total_sel) {
> ...
>
> So, only use helpers if really needed. And, assign values directly.
Agreed on the larger point. v4 removes these single-use helpers and the
intermediate selector state rather than trying to reorganize them. The
target setup is now much closer to the original flow.
>
> > if (cxl_rr->nr_targets_set) {
> > for (int i = 0; i < cxl_rr->nr_targets_set; i++)
> > if (ep->dport == cxlsd->target[i]) {
> > @@ -2087,6 +2168,14 @@ static int cxl_region_attach(struct cxl_region *cxlr,
> > return -ENXIO;
> > }
> >
> > + /*
> > + * Mixed-granularity position calculation is added by the next patch.
> > + * Reject it until then so this intermediate state remains bisectable.
> > + */
> > + if (cxlrd->cxlsd.cxld.interleave_granularity >
> > + p->interleave_granularity)
> > + return -ENXIO;
> > +
>
> That change did not remove anything that would make existing code
> break, right? It just adds selector calculation. I don't see a need
> for this additional check.
The check was needed to keep this intermediate commit bisectable.
This patch relaxes validation enough that mixed-granularity attach can
proceed before the position calculation supports it.
The v4 set avoids that intermediate state, so the gate is no longer
needed.
>
> -Robert
>
> > if (p->nr_targets >= p->interleave_ways) {
> > dev_dbg(&cxlr->dev, "region already has %d endpoints\n",
> > p->nr_targets);
> > --
> > 2.37.3
> >
>
next prev parent reply other threads:[~2026-08-20 22:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 22:20 [PATCH v3 0/9] cxl: Support mixed-granularity region interleaves Alison Schofield
2026-07-30 22:20 ` [PATCH v3 1/9] cxl/region: Factor port target calculations Alison Schofield
2026-07-30 22:36 ` sashiko-bot
2026-08-18 8:20 ` Robert Richter
2026-08-20 21:58 ` Alison Schofield
2026-07-30 22:20 ` [PATCH v3 2/9] cxl/region: Validate interleave selector bits Alison Schofield
2026-08-18 9:13 ` Robert Richter
2026-08-20 22:14 ` Alison Schofield [this message]
2026-07-30 22:20 ` [PATCH v3 3/9] cxl/region: Derive port granularity from " Alison Schofield
2026-08-18 10:01 ` Robert Richter
2026-08-20 22:48 ` Alison Schofield
2026-07-30 22:20 ` [PATCH v3 4/9] cxl/region: Account for mixed-granularity in position calculations Alison Schofield
2026-07-30 22:20 ` [PATCH v3 5/9] cxl/region: Allow mixed-granularity regions Alison Schofield
2026-07-30 22:20 ` [PATCH v3 6/9] cxl/region: Enforce coarse-to-fine ordering for " Alison Schofield
2026-07-30 22:20 ` [PATCH v3 7/9] cxl/region: Fail region creation on position check mismatch Alison Schofield
2026-07-30 22:40 ` sashiko-bot
2026-07-30 22:20 ` [PATCH v3 8/9] cxl/test: Add a topology to test mixed-granularity regions Alison Schofield
2026-07-30 22:20 ` [PATCH v3 9/9] Documentation/cxl: Describe multi-level interleave validation Alison Schofield
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=aod8RoI1gJoKkrry@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=iweiny@kernel.org \
--cc=jic23@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=ming.li@zohomail.com \
--cc=rrichter@amd.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox