All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: <dave.jiang@intel.com>, <jic23@kernel.org>,
	<ming.li@zohomail.com>, <icheng@nvidia.com>,
	<linux-cxl@vger.kernel.org>
Subject: Re: [PATCH] cxl/hdm: Account for locked decoders regardless of commit state
Date: Thu, 19 Nov 2026 16:16:54 -0800	[thread overview]
Message-ID: <av-Rdu4k9alDszsE@aschofie-mobl2.lan> (raw)
In-Reply-To: <20261029201327.1119231-1-dave@stgolabs.net>

On Thu, Oct 29, 2026 at 01:13:27PM -0700, Davidlohr Bueso wrote:
> Firmware may arm a locked decoder it leaves uncommitted, a corner
> case albeit a valid one. Enumeration only records the bit for committed
> decoders, yet setup_hw_decoder() carries it through and the driver's
> own commit triggers it read-only.
> 
> A later region teardown then writes a reset the hardware ignores and
> clears CXL_DECODER_F_ENABLE anyway, so the decoder looks free while it
> still decodes and releases its DPA.
> 
> Record the bit regardless of the commit state, such that the decoder
> then reads locked from probe, and a region built on it is locked at
> attach.
> 
> Tested on qemu modified to enforce locked, arming the bit on an
> uncommitted endpoint decoder before the endpoint probes, then
> committing and deleting a 256M region on it and creating a 512M one.
> Before, the decoder and region read unlocked, the DPA is freed and the
> second region reports committed while the hardware still decodes the
> first; after, both read locked from attach, decommit fails with
> -EPERM, the DPA release with -EBUSY, and the second region cannot
> allocate DPA.

Hi Davidlohr,

This does fix the stated problem. When firmware sets Lock On Commit on a
decoder but leaves it uncommitted (armed, below), the driver's own commit
locks it. Region teardown then marks the decoder free while the hardware
still decodes, and its DPA can be handed to a second region while the first
still decodes to it. Refusing that teardown is the safer way to fail.

It calls attention to a wider cleanup of the lock tracking. Lock On Commit
doesn't lock anything until the decoder commits but the flag is now set at
probe, the region picks it up at attach, and is never cleared afterwards.

The problem with that is the driver treats a region as locked before
anything in the hardware is, and keeps it locked even if the armed
decoder never commits. A locked region skips all decoder teardown, so -

- If the armed decoder is detached before commit, the region stays
  locked. A region then committed with only unlocked decoders can't be
  decommitted even though the hardware would allow it.
- If a region commit fails partway, before the armed decoder commits,
  the unwind is skipped. The decoders that did commit stay committed
  after the region is deleted, and their DPA can't be freed, though
  none of them is locked.
- An SBR clears the hardware bit, but if nothing was committed the
  decoder keeps the lock flag. The driver then commits it unlocked, yet
  the region on it can't be decommitted.

Could we record the decoder lock when the driver's commit actually locks
it? The region handling would then need to cover both a successful region
commit and a decoder becoming locked before a later commit fails, preserving
the locked decoder's resources while unwinding decoders that can still be
reset. Locking the region only after the entire commit succeeds would miss
that partial failure.

Your modified QEMU is the only way I know to test it, since cxl_test
doesn't go through the real enumeration or commit paths.

I didn't prototype anything of this at all, so nothing to concrete to
share other than my words. 

-- Alison



> 
> Fixes: 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
> ---
>  drivers/cxl/core/hdm.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
> index fdcef20e01ba..a34f3509ab1f 100644
> --- a/drivers/cxl/core/hdm.c
> +++ b/drivers/cxl/core/hdm.c
> @@ -1064,11 +1064,12 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
>  		.end = base + size - 1,
>  	};
>  
> +	if (ctrl & CXL_HDM_DECODER0_CTRL_LOCK)
> +		cxld->flags |= CXL_DECODER_F_LOCK;
> +
>  	/* decoders are enabled if committed */
>  	if (committed) {
>  		cxld->flags |= CXL_DECODER_F_ENABLE;
> -		if (ctrl & CXL_HDM_DECODER0_CTRL_LOCK)
> -			cxld->flags |= CXL_DECODER_F_LOCK;
>  		if (FIELD_GET(CXL_HDM_DECODER0_CTRL_HOSTONLY, ctrl))
>  			cxld->target_type = CXL_DECODER_HOSTONLYMEM;
>  		else
> -- 
> 2.39.5
> 

      parent reply	other threads:[~2026-11-20  0:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 20:13 [PATCH] cxl/hdm: Account for locked decoders regardless of commit state Davidlohr Bueso
2026-10-29 23:08 ` Dave Jiang
2026-10-29 23:25   ` Davidlohr Bueso
2026-11-20  0:16 ` Alison Schofield [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=av-Rdu4k9alDszsE@aschofie-mobl2.lan \
    --to=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=icheng@nvidia.com \
    --cc=jic23@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=ming.li@zohomail.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.