Linux CXL
 help / color / mirror / Atom feed
From: <dan.j.williams@intel.com>
To: Alison Schofield <alison.schofield@intel.com>,
	<dan.j.williams@intel.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
	Jonathan Cameron <jonathan.cameron@huawei.com>,
	Dave Jiang <dave.jiang@intel.com>,
	"Vishal Verma" <vishal.l.verma@intel.com>,
	Ira Weiny <ira.weiny@intel.com>, <linux-cxl@vger.kernel.org>
Subject: Re: [PATCH] cxl/port: Validate decoder nr_targets against supported ways
Date: Thu, 14 Aug 2025 10:36:19 -0700	[thread overview]
Message-ID: <689e1e938b5e0_27091002f@dwillia2-xfh.jf.intel.com.notmuch> (raw)
In-Reply-To: <aJ1UJOySCoM2M_-M@aschofie-mobl2.lan>

Alison Schofield wrote:
> On Wed, Aug 13, 2025 at 05:57:50PM -0700, Dan Williams wrote:
> > alison.schofield@ wrote:
> > > From: Alison Schofield <alison.schofield@intel.com>
> > > 
> > > nr_targets is the number of downstream ports in a decoder's target
> > > list. It is limited to the supported interleave ways: 1, 2, 3, 4, 6,
> > > 8, 12, 16. The existing check only enforces nr_targets <=
> > > CXL_DECODER_MAX_INTERLEAVE (16), allowing invalid values, like 5, 7,
> > > etc, to pass through.
> > > 
> > > Add is_nr_targets_valid() to check for supported interleave ways using
> > > ways_to_eiw(). Use it before allocating a decoder to avoid alloc/free
> > > churn when nr_targets is already known to be invalid.
> > > 
> > > This was found by inspection and hardens the code.
> > 
> > Well, now seeing this and trying to answer the risk question in 1/ led
> > to me to reconsider whether this is a good idea and whether we have a
> > deeper confusion at play:
> > 
> > 1/ "Hardening" needs to come with an actual risk claim. For
> >    cxl_switch_decoder_alloc() the values come from hardware or ACPI and if
> >    those are buggy all bets are off. ACPI is already protected by a
> >    eiw_to_ways() conversion prior to calling cxl_root_decoder_alloc(), and
> >    hardware is even more accurate than this
> >    approach because it considers interleave ways capability.
> 
> If all callers comes thru ACPI then agree no need. When you voiced
> concern over valid host bridge interleave ways, which would be the
> nr_targets of the root decoder (a switch decoder) I imagined you
> were thinking of a path to root decoder alloc outside of ACPI.
> Guess not.

I was looking at the patch in isolation and wondering out loud if we
needed something, but now upon seeing the patch, not so sure.

> > 2/ nr_targets != ways. ways_to_eiw() is the wrong validity check for
> >    switch decoders, nr_targets is a topology limitation, not a
> >    interleave_ways limitation. As far as I can see nothing breaks if a
> >    decoder claims to support a target count that is not a valid
> >    interleave_ways number.
> 
> nr_targets does not have to equal interleave ways for the ways_to_eiw()
> to be a useful helper for validating nr_targets. nr_targets has to be one
> of 1,2,3,4,6,8,12,16 and if it's not ways_to_eiw() fails. I saw it as
> simple code reuse.

See "Target Count" in 8.2.4.20.1 CXL HDM Decoder Capability Register.
The only hardware valid values today for target count are 1, 2, 4, and
8. That is different than ACPI CFMWS which can target 1,2,3,4,6,8,12,16
because CFMWS has a tighter relationship between nr_targets and
interleave_ways. It wants to define regions that target host bridges and
non-host-bridge targets.

The next question is, what if a switch decoder put 5 in its target count
field? Would the driver need to fall over immediately? I think the
answer is no. It would simply be the case that a decoder would set ways
to 1, 2, or 4 and select from the 5 potential targets.

So, I led you astray to make this a wider check beyond the root decoder
special case, and even there the risk of it being a problem in practice.
is low.

> I explored using cxl/test, changing nr_targets at decoder init time,
> and predictable passes if greater than needed, and fails when less.
> But it's not a thorough simulation and not worthy of a more detailed
> simulation.
> 
> Thanks for the review. It was a worthwhile exploration :)

Thanks for the patience to work through it with me! I learned something
about being more careful about the nr_targets:ways relationship.

  reply	other threads:[~2025-08-14 17:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-13 21:42 [PATCH] cxl/port: Validate decoder nr_targets against supported ways alison.schofield
2025-08-14  0:57 ` dan.j.williams
2025-08-14  3:12   ` Alison Schofield
2025-08-14 17:36     ` dan.j.williams [this message]
2025-08-21  0:37       ` 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=689e1e938b5e0_27091002f@dwillia2-xfh.jf.intel.com.notmuch \
    --to=dan.j.williams@intel.com \
    --cc=alison.schofield@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=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