mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robert Richter <rrichter@amd.com>
To: Richard Cheng <icheng@nvidia.com>
Cc: dave@stgolabs.net, jic23@kernel.org, dave.jiang@intel.com,
	alison.schofield@intel.com, vishal.l.verma@intel.com,
	djbw@kernel.org, iweiny@kernel.org, ming.li@zohomail.com,
	gourry@gourry.net, linux-cxl@vger.kernel.org,
	linux-kernel@vger.kernel.org, newtonl@nvidia.com,
	kristinc@nvidia.com, kaihengf@nvidia.com, kobak@nvidia.com
Subject: Re: [PATCH v2] cxl/region: Add cxl_decoder_is_passthrough() helper
Date: Thu, 13 Aug 2026 15:53:23 +0200	[thread overview]
Message-ID: <an3MU6_wgm1E6L-Q@rric.localdomain> (raw)
In-Reply-To: <20260805065935.27837-1-icheng@nvidia.com>

On 05.08.26 14:59:34, Richard Cheng wrote:
> commit_decoder() open-codes the passthrough test.
> A NULL ->commit() plus a switch decoder with at most one target. The
> call site is hard to read, and it suggests a NULL ->commit() alone
> identifies a passthrough decoder. It does not.
> DVSEC-emulated endpoint decoders also leave ->commit() NULL, and root
> decoders never set it. A future caller testing ->commit() alone would
> silently include them.
> 
> Move the test into cxl_decoder_is_passthrough() and document what each
> condition rules out. The helper runs the same tests in the same order,
> no functional change.
> 
> Signed-off-by: Richard Cheng <icheng@nvidia.com>
> ---
> Changelog:
> 
> v1 -> v2:
>     - Dropped the passthrough F_ENABLE restore patch. The bug was
>       already fixed.
>     - What remains is only the clarify helper function patch, so the
>       patch is retitled accordingly
> 
> v1:
> https://lore.kernel.org/linux-cxl/20260727103743.63343-1-icheng@nvidia.com/
> 
> Best regards,
> Richard Cheng.
> ---
>  drivers/cxl/core/region.c | 28 ++++++++++++++++++++++------
>  1 file changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 27e63e6dab7c..cd73684fbe97 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -293,17 +293,33 @@ static void cxl_region_decode_reset(struct cxl_region *cxlr, int count)
>  	clear_bit(CXL_REGION_F_NEEDS_RESET, &cxlr->flags);
>  }
>  
> -static int commit_decoder(struct cxl_decoder *cxld)
> +/*
> + * A single-dport host-bridge need not publish an HDM decoder capability
> + * when passthrough decode can be assumed. The resulting decoder is a
> + * software-only construct with no registers to program, so it carries no
> + * ->commit() operation, see devm_cxl_add_passthrough_decoder().
> + *
> + * A NULL ->commit() alone does not identify one, it is also NULL for
> + * DVSEC-emulated endpoint decoders. Test the decoder type and target
> + * count as well.
> + */
> +static bool cxl_decoder_is_passthrough(struct cxl_decoder *cxld)

This is much noise for just checking if ->commit() is required in some
cases and generate an error if not.

>  {
> -	struct cxl_switch_decoder *cxlsd = NULL;
> +	if (cxld->commit)
> +		return false;

That duplicates the test and the code is never executed.

> +
> +	if (!is_switch_decoder(&cxld->dev))
> +		return false;
> +
> +	return to_cxl_switch_decoder(&cxld->dev)->nr_targets <= 1;

cxlsd->nr_targets is easier to read and explains that nr_targets is in
struct cxl_switch_decoder, which wouln't be obious else. So the change
does not improve readability and instead does multiple things in a
single line.

> +}
>  
> +static int commit_decoder(struct cxl_decoder *cxld)
> +{
>  	if (cxld->commit)
>  		return cxld->commit(cxld);
>  
> -	if (is_switch_decoder(&cxld->dev))
> -		cxlsd = to_cxl_switch_decoder(&cxld->dev);
> -
> -	if (dev_WARN_ONCE(&cxld->dev, !cxlsd || cxlsd->nr_targets > 1,
> +	if (dev_WARN_ONCE(&cxld->dev, !cxl_decoder_is_passthrough(cxld),
>  			  "->commit() is required\n"))

The original was pretty straight forward: if it is a switch decoder
with multiple targets, raise an error. It looks like an assert here as
!cxld->commit is only created in devm_cxl_add_passthrough_decoder()
which sets the number of targets to one (not looking into test code
here, but if that causes an issue, fix it there).

So I don't see much sense in this patch.

Thanks,

-Robert

>  		return -ENXIO;
>  	return 0;
> 
> base-commit: 212e015fc34712c849653cdb3179cd643c915015
> -- 
> 2.43.0
> 

      reply	other threads:[~2026-08-13 13:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  6:59 Richard Cheng
2026-08-13 13:53 ` Robert Richter [this message]

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=an3MU6_wgm1E6L-Q@rric.localdomain \
    --to=rrichter@amd.com \
    --cc=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=djbw@kernel.org \
    --cc=gourry@gourry.net \
    --cc=icheng@nvidia.com \
    --cc=iweiny@kernel.org \
    --cc=jic23@kernel.org \
    --cc=kaihengf@nvidia.com \
    --cc=kobak@nvidia.com \
    --cc=kristinc@nvidia.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.li@zohomail.com \
    --cc=newtonl@nvidia.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

all inboxes | Powered by JetHome®