Linux CXL
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Unsung Lee" <unsung0317@gmail.com>, linux-cxl@vger.kernel.org
Subject: Re: [RFC PATCH 3/4] cxl/memdev: Add firmware_activate to activate firmware without a reset
Date: Wed, 25 Nov 2026 12:57:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-233405@kernel.org> (raw)
In-Reply-To: <20261125124358.3583223-4-unsung0317@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] cxl/memdev: stale CXL_FW_ACTIVATING bit in
  cxl_mem_activate_fw_online()
- [Medium] cxl/memdev: activating_slot overwrite in
  cxl_mem_activate_fw_online()
--

commit 19d55015d9b6225e3059d6173d8fb4365535c893
Author: Unsung Lee <unsung0317@gmail.com>

cxl/memdev: Add firmware_activate to activate firmware without a reset

This commit adds a write-only firmware_activate sysfs attribute to activate
a firmware slot online when the device is not decoding memory, while blocking
decoder commits, firmware uploads, and sanitization until activation
completes.

> diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> index cdbebd12258b9..cc9ff0dd9cd8a 100644
> --- a/drivers/cxl/core/memdev.c
> +++ b/drivers/cxl/core/memdev.c
[ ... ]
> @@ -966,13 +1010,136 @@ static int cxl_mem_activate_fw(struct cxl_memdev_state *mds, int slot)
>  		.poll_count = 30,
>  	};
>  
> -	/* Only offline activation supported for now */
> -	activate.action = CXL_FW_ACTIVATE_OFFLINE;
> +	activate.action = action;
>  	activate.slot = slot;
>  
>  	return cxl_internal_send_cmd(cxl_mbox, &mbox_cmd);
>  }
>  
> +/*
> + * cxl_mem_activate_fw_online - Activate a FW slot without a reset
> + *
> + * How long a device holds CXL.mem requests while it switches to the new
> + * firmware is not known here, and a stall the platform does not tolerate
> + * would take the memory down. Like sanitize, only proceed when the device
> + * is not decoding any HPA range, i.e. no endpoint decoder is committed,
> + * and set CXL_FW_ACTIVATING under cxl_rwsem.region so that none can be
> + * committed until the command has completed. After a timeout the device
> + * may still be activating: keep CXL_FW_ACTIVATING until Get FW Info
> + * reports the slot as running or an activation succeeds. A device that
> + * keeps its old firmware then refuses regions until cxl_pci is bound
> + * again.
> + *
> + * Decoders of other hosts sharing the device are not visible here.
> + */
> +static int cxl_mem_activate_fw_online(struct cxl_memdev_state *mds,
> +				      unsigned int slot)
> +{
> +	struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
> +	struct cxl_memdev *cxlmd = mds->cxlds.cxlmd;
> +	int rc, info_rc;
> +
> +	rc = cxl_mem_get_fw_info(mds);
> +	if (rc)
> +		return rc;
> +
> +	/* An activation that timed out has completed (cur_slot is never 0) */
> +	if (mds->fw.activating_slot == mds->fw.cur_slot) {
> +		mds->fw.activating_slot = 0;
> +		clear_bit(CXL_FW_ACTIVATING, mds->fw.state);
> +	}

[Severity: Medium]
What happens if an online activation of one slot times out (leaving
mds->fw.activating_slot set) and a subsequent write to firmware_activate
requests a different slot before the first activation finishes?

cxl_mem_activate_fw_online() proceeds to issue an online Activate FW
command for the new slot while the earlier activation may still be running.
If the second command also times out, mds->fw.activating_slot = slot
overwrites the original slot number; once the device finishes switching to
the first slot, mds->fw.cur_slot will not match the overwritten
mds->fw.activating_slot, leaving CXL_FW_ACTIVATING set and blocking region
commits, firmware uploads, and sanitization.

> +
> +	if (!(mds->fw.activation_cap &
> +	      CXL_FW_INFO_ACTIVATION_CAP_HAS_LIVE_ACTIVATE))
> +		return -EOPNOTSUPP;
> +
> +	if (!slot || slot > mds->fw.num_slots || slot == mds->fw.cur_slot)
> +		return -EINVAL;
> +
> +	/*
> +	 * A different slot set up for activation on the next cold reset
> +	 * would silently replace this firmware at that reset.
> +	 */
> +	if (mds->fw.pending_slot && mds->fw.pending_slot != slot &&
> +	    mds->fw.pending_slot != mds->fw.cur_slot) {
> +		dev_err(&cxlmd->dev,
> +			"slot %d is pending activation on reset, not activating slot %u\n",
> +			mds->fw.pending_slot, slot);
> +		return -EBUSY;
> +	}
> +
> +	/*
> +	 * synchronize with cxl_mem_probe(), sanitize and decoder write
> +	 * operations
> +	 */
> +	guard(device)(&cxlmd->dev);
> +
> +	/* A running sanitize owns the device until it completes */
> +	scoped_guard(mutex, &cxl_mbox->mbox_mutex) {
> +		if (mds->security.sanitize_active)
> +			return -EBUSY;
> +	}
> +
> +	scoped_guard(rwsem_read, &cxl_rwsem.region) {
> +		/* Without a bound endpoint the device may still be mapped */
> +		if (!cxlmd->dev.driver ||
> +		    cxl_num_decoders_committed(cxlmd->endpoint)) {
> +			dev_err(&cxlmd->dev,
> +				"device is decoding memory, not activating firmware online\n");
> +			return -EBUSY;
> +		}
> +		set_bit(CXL_FW_ACTIVATING, mds->fw.state);
> +	}
> +
> +	rc = cxl_mem_activate_fw(mds, slot, CXL_FW_ACTIVATE_ONLINE);
> +	if (rc == -ETIMEDOUT) {
> +		mds->fw.activating_slot = slot;
> +		dev_warn(&cxlmd->dev,
> +			 "slot %u may still be activating, refusing regions on this device\n",
> +			 slot);
> +	} else if (!rc || !mds->fw.activating_slot) {
> +		/*
> +		 * After a timeout only a success shows that the device is
> +		 * done. Any error may come while it is still busy with the
> +		 * activation that timed out, so the mark stays.
> +		 */
> +		mds->fw.activating_slot = 0;
> +		clear_bit(CXL_FW_ACTIVATING, mds->fw.state);
> +	}
> +
> +	/* Report the slot the device runs now, also after a failure */
> +	info_rc = cxl_mem_get_fw_info(mds);
> +	if (info_rc)
> +		dev_warn(&cxlmd->dev, "cannot read FW slot state: %d\n",
> +			 info_rc);

[Severity: Medium]
Should the post-command cxl_mem_get_fw_info() call also clear
mds->fw.activating_slot and CXL_FW_ACTIVATING when
mds->fw.activating_slot == mds->fw.cur_slot?

If cxl_mem_activate_fw() times out (or fails while a previous timed-out
activation was finishing) and the activation completes right before this
second cxl_mem_get_fw_info() call, mds->fw.cur_slot is updated to the new
slot, but CXL_FW_ACTIVATING remains set and locks out region commits,
firmware uploads, and sanitization until another write to
firmware_activate. Re-attempting firmware_activate on that same slot will
also see slot == mds->fw.cur_slot and fail with -EINVAL after clearing the
bit.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125124358.3583223-1-unsung0317@gmail.com?part=3

  reply	other threads:[~2026-11-25 12:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 12:43 [RFC PATCH 0/4] cxl/memdev: Activate firmware without a reset Unsung Lee
2026-11-25 12:43 ` [RFC PATCH 1/4] cxl/memdev: Poll for completion of Activate FW Unsung Lee
2026-11-25 12:43 ` [RFC PATCH 2/4] cxl/memdev: Keep pending slot and activation capabilities from Get FW Info Unsung Lee
2026-11-25 12:43 ` [RFC PATCH 3/4] cxl/memdev: Add firmware_activate to activate firmware without a reset Unsung Lee
2026-11-25 12:57   ` sashiko-bot [this message]
2026-11-25 12:43 ` [RFC PATCH 4/4] tools/testing/cxl: Add a knob to advertise online FW activation Unsung Lee
2026-11-25 12:53 ` [RFC PATCH 0/4] cxl/memdev: Activate firmware without a reset Unsung Lee

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=sashiko-outbox-233405@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=unsung0317@gmail.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