* [RFC PATCH 0/4] cxl/memdev: Activate firmware without a reset
@ 2026-11-25 12:43 Unsung Lee
2026-11-25 12:43 ` [RFC PATCH 1/4] cxl/memdev: Poll for completion of Activate FW Unsung Lee
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Unsung Lee @ 2026-11-25 12:43 UTC (permalink / raw)
To: linux-cxl
Cc: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, John Groves
This series lets userspace activate an uploaded slot online once the
device no longer decodes any memory, the same condition sanitize uses.
Uploads keep their current behaviour; activation is a separate,
explicit step:
1. upload as today (slot N becomes pending for the next cold reset)
2. move the data away, offline the memory, destroy the region
3. echo N > /sys/bus/cxl/devices/memX/firmware_activate
4. recreate the region and online the memory
Patch 1 lets Activate FW complete as a background command; without a
poll budget the mailbox reports a timeout at once.
Patch 2 keeps the pending slot and the activation capability from Get
FW Info.
Patch 3 adds the attribute.
Patch 4 lets cxl_test advertise online activation.
Questions:
- Patch 3 requires that the device decode no memory, as sanitize does.
The driver cannot tell how long a device holds CXL.mem requests while
it switches firmware, and the comment on the RAW command block list
says activation "requires adjustment / coordination of transaction
timeout values at the root bridge level". With no memory decoded
nothing can time out. Is that the right condition, or too strict? It
means moving the data away first.
- The Online FW Activation Capabilities ECN to CXL 3.1 allows Activate
FW to complete as a background command (8.2.9.3.3), so patch 1 waits
for it like Transfer FW. Should it carry a Fixes: tag? John Groves
raised activations longer than the 2 s mailbox timeout at the June
2025 CXL collab sync; patch 1 may overlap with a patch from that.
- Patch 3 holds cxl_rwsem.region only to check the decoders and set a
FW state bit that makes decoder commit refuse the device with EBUSY,
as sanitize does. An earlier version held the rwsem across the
command (up to 30 s); with an activation emulated in the kernel,
create-region and region sysfs reads on other devices then waited
for the whole activation. The cost is that a create-region on this
device that races the write fails instead of waiting. Is that the
preferred trade-off?
- After a timeout the device may still be activating, so patch 3 keeps
refusing regions, uploads and sanitize until the slot shows as
running or a later activation succeeds. A later error does not count,
since it may come while the device is still busy. A device that ends
up on its old firmware stays refused until cxl_pci is bound again.
Reading the Background Command Status register would end this
sooner, but needs a new mailbox callback. Would that be acceptable?
- Should the pending slot stay set after an online activation? QEMU
keeps it, cxl_test clears it.
Not addressed in this series:
- State cached at probe (CEL, timestamp, event interrupt policy,
features, Identify, CDAT) is not re-read after activation.
- Unbinding the port above the endpoint during the command tears the
endpoint down, which clears HDM decoder enable and Mem_Enable on the
activating device (exercised in QEMU without kernel warnings).
Testing (QEMU 11.1.3, one type3 device, guest v7.3.1 unless noted; no
real hardware, so an activation that really takes long, polling while
it runs, other hosts and other CCIs are not covered):
- Functional and race tests (concurrent writes, upload, create-region,
cxl_mem and cxl_pci unbind, mailbox readers, kill -9, sanitize,
upload cancel) on release and lockdep/KASAN kernels, 20-50x: no
warnings; kprobes showed no activation while a decoder was committed
and no commit while activating.
- A test-only build emulating slow and timed-out activations, release
and debug, 20x each: refusal during and after a timeout; a failed
activation after a timeout stays refused, with uploads and sanitize,
until cxl_pci is bound again; a cxl_mem unbind waits for the command;
a port unbind during the command. Create-region failing after the
port is bound again also happens on plain v7.3.1, so that test does
not check regions afterwards.
- The whole flow (move the data away, offline, activate, online, move
it back): 100x without data; 20x with a process rewriting 2 GB on
the device's node (longest write stall 78 ms, in QEMU only); through
a maintenance script, deferring when there is no room (10x), rolling
back when room runs out (20x), and SIGINT/SIGTERM/SIGKILL at each step
(60x); and these mixed for 4 hours (1,462 iterations). No failures,
and the data was intact after every iteration.
- cxl/next 32af781935: applies cleanly, no W=1 warnings; QEMU gets no
root decoder there (CFMWS with both HDM-H and HDM-DB, rejected since
e4c3f0d966), so only the tests without a region ran (all passing).
I designed the change and directed the work. An LLM coding assistant
(Claude Code) wrote parts of the code, the changelogs and the test
harness at my direction, and was used to review the code and run the
tests. I reviewed every line of the series and take responsibility for
it.
Unsung Lee (4):
cxl/memdev: Poll for completion of Activate FW
cxl/memdev: Keep pending slot and activation capabilities from Get FW
Info
cxl/memdev: Add firmware_activate to activate firmware without a reset
tools/testing/cxl: Add a knob to advertise online FW activation
Documentation/ABI/testing/sysfs-bus-cxl | 45 +++++
drivers/cxl/core/hdm.c | 7 +
drivers/cxl/core/mbox.c | 5 +
drivers/cxl/core/memdev.c | 209 +++++++++++++++++++++++-
drivers/cxl/cxlmem.h | 8 +
tools/testing/cxl/test/mem.c | 8 +-
6 files changed, 274 insertions(+), 8 deletions(-)
base-commit: 32af7819352bae9c690ebe277a44eceb501d5c68
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC PATCH 1/4] cxl/memdev: Poll for completion of Activate FW
2026-11-25 12:43 [RFC PATCH 0/4] cxl/memdev: Activate firmware without a reset Unsung Lee
@ 2026-11-25 12:43 ` 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
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Unsung Lee @ 2026-11-25 12:43 UTC (permalink / raw)
To: linux-cxl
Cc: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, John Groves
cxl_mem_activate_fw() sends Activate FW without poll_interval_ms and
poll_count. If the device answers "background command started", the
mailbox code skips its wait loop and fails at once with -ETIMEDOUT
("timeout waiting for background (0 ms)"), so the firmware upload is
reported as a hardware error while the device may still be activating.
Give the command the same 1 s x 30 budget as Transfer FW.
Signed-off-by: Unsung Lee <unsung0317@gmail.com>
---
drivers/cxl/core/memdev.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
index 787988e929..67f467c267 100644
--- a/drivers/cxl/core/memdev.c
+++ b/drivers/cxl/core/memdev.c
@@ -949,10 +949,18 @@ static int cxl_mem_activate_fw(struct cxl_memdev_state *mds, int slot)
if (slot == 0 || slot > mds->fw.num_slots)
return -EINVAL;
+ /*
+ * Activate FW may complete as a background operation. Without a
+ * poll budget the mailbox gives up at once and reports a timeout
+ * even though the device is still activating. Use the same budget
+ * as Transfer FW.
+ */
mbox_cmd = (struct cxl_mbox_cmd) {
.opcode = CXL_MBOX_OP_ACTIVATE_FW,
.size_in = sizeof(activate),
.payload_in = &activate,
+ .poll_interval_ms = 1000,
+ .poll_count = 30,
};
/* Only offline activation supported for now */
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH 2/4] cxl/memdev: Keep pending slot and activation capabilities from Get FW Info
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 ` Unsung Lee
2026-11-25 12:43 ` [RFC PATCH 3/4] cxl/memdev: Add firmware_activate to activate firmware without a reset Unsung Lee
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Unsung Lee @ 2026-11-25 12:43 UTC (permalink / raw)
To: linux-cxl
Cc: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, John Groves
cxl_mem_get_fw_info() keeps only the number of slots and the active
slot. Also keep the slot that will be activated on the next cold reset
and the FW Activation Capabilities, for use by online activation in a
following patch.
No functional change.
Signed-off-by: Unsung Lee <unsung0317@gmail.com>
---
drivers/cxl/core/memdev.c | 3 +++
drivers/cxl/cxlmem.h | 4 ++++
2 files changed, 7 insertions(+)
diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
index 67f467c267..cdbebd1225 100644
--- a/drivers/cxl/core/memdev.c
+++ b/drivers/cxl/core/memdev.c
@@ -925,6 +925,9 @@ static int cxl_mem_get_fw_info(struct cxl_memdev_state *mds)
mds->fw.num_slots = info.num_slots;
mds->fw.cur_slot = FIELD_GET(CXL_FW_INFO_SLOT_INFO_CUR_MASK,
info.slot_info);
+ mds->fw.pending_slot = FIELD_GET(CXL_FW_INFO_SLOT_INFO_NEXT_MASK,
+ info.slot_info);
+ mds->fw.activation_cap = info.activation_cap;
return 0;
}
diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
index 4cf8a0f6cf..a67e451a62 100644
--- a/drivers/cxl/cxlmem.h
+++ b/drivers/cxl/cxlmem.h
@@ -388,6 +388,8 @@ struct cxl_mbox_activate_fw {
* @num_slots: Number of FW slots available
* @cur_slot: Slot number currently active
* @next_slot: Slot number for the new firmware
+ * @pending_slot: Slot to be activated on the next cold reset, 0 if none
+ * @activation_cap: FW Activation Capabilities from Get FW Info
*/
struct cxl_fw_state {
DECLARE_BITMAP(state, CXL_FW_STATE_BITS);
@@ -395,6 +397,8 @@ struct cxl_fw_state {
int num_slots;
int cur_slot;
int next_slot;
+ int pending_slot;
+ u8 activation_cap;
};
/**
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH 3/4] cxl/memdev: Add firmware_activate to activate firmware without a reset
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 ` Unsung Lee
2026-11-25 12:57 ` sashiko-bot
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
4 siblings, 1 reply; 7+ messages in thread
From: Unsung Lee @ 2026-11-25 12:43 UTC (permalink / raw)
To: linux-cxl
Cc: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, John Groves
Linux activates newly uploaded firmware only on the next cold reset, so
running it requires a reboot or a power cycle even when the device
reports that it supports online activation (FW Activation Capabilities
bit 0 in Get FW Info).
Add a write-only memdev attribute, firmware_activate, that activates a
given slot online. Uploads are unchanged and still set up the new slot
for activation on the next cold reset, so nothing changes unless
userspace asks for an online activation.
Online activation is meant to let the device keep serving requests, but
the driver cannot tell how long a given device holds CXL.mem requests
while it switches firmware, and a stall the platform does not tolerate
would take the memory down. Apply the same condition as sanitize: the
memdev must be bound and no endpoint decoder may be committed, checked
under the device lock, which is held until the command completes, and
under cxl_rwsem.region. There a FW state bit is set that makes decoder
commit refuse the device until the command has completed, as
sanitize_active does for sanitize. cxl_rwsem.region is not held across
the command, which may take up to 30 seconds, so regions of other
devices are not held up. If the command times out the device may still
be activating, so the bit stays set until Get FW Info reports the slot
as running or an activation succeeds. An error from a later Activate FW
may come while the device is still busy with the earlier one, so it
leaves the bit set; a device that ends up keeping its old firmware then
refuses regions until cxl_pci is bound again. While the bit stays set
after a timeout, also refuse firmware uploads and sanitize, which would
otherwise send state changing commands to a device that may still be
activating and rely on it to answer Busy.
Userspace is expected to move the data away, take the memory offline and
destroy the regions before writing the attribute, and to recreate them
afterwards. The policy of when to do this, or to leave the activation to
the next reset, stays in userspace.
Check the slot number against Get FW Info before the state checks, so
an invalid slot gets EINVAL rather than EBUSY; a device without online
activation support reports EOPNOTSUPP first. Also refuse while a
sanitize is running, and when another slot is set up for activation on
the next cold reset, since that reset would silently replace the
firmware activated now. Exclude concurrent uploads with a busy bit in
the FW state. After the command, read Get FW Info again and report the
slot the device runs, so that a failure shows whether the device kept
the old firmware, and warn if the device still reports another slot for
the next cold reset.
Only decoders of this host are visible, so devices shared with other
hosts are not covered by the check.
Signed-off-by: Unsung Lee <unsung0317@gmail.com>
---
Documentation/ABI/testing/sysfs-bus-cxl | 45 ++++++
drivers/cxl/core/hdm.c | 7 +
drivers/cxl/core/mbox.c | 5 +
drivers/cxl/core/memdev.c | 198 +++++++++++++++++++++++-
drivers/cxl/cxlmem.h | 4 +
5 files changed, 252 insertions(+), 7 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl
index cf45b3fde0..d1135b2fb8 100644
--- a/Documentation/ABI/testing/sysfs-bus-cxl
+++ b/Documentation/ABI/testing/sysfs-bus-cxl
@@ -18,6 +18,45 @@ Description:
specification.
+What: /sys/bus/cxl/devices/memX/firmware_activate
+Date: November, 2026
+KernelVersion: v7.6
+Contact: linux-cxl@vger.kernel.org
+Description:
+ (WO) Write a firmware slot number to activate the firmware in
+ that slot now, without a reset ("online" activation in the
+ Activate FW command). Firmware uploaded through
+ /sys/class/firmware/memX/ is set up for activation on the next
+ cold reset; this attribute lets userspace switch to it earlier.
+ Like sanitize, this requires the device to be disabled, that
+ is, not actively decoding any HPA ranges, so the caller has to
+ take its memory offline and destroy its regions first. The
+ write fails with EOPNOTSUPP if the device does not support
+ online activation, EINVAL for an invalid or already active
+ slot, and EBUSY if the device is decoding memory, a firmware
+ upload or a sanitize is in progress, or a different slot is set
+ up for activation on the next cold reset. Only the decoders of
+ this host are checked. If the device fails the command, the
+ write fails with the error of the mailbox command: ENXIO for
+ most device errors, including a device still busy with an
+ earlier activation, or ETIMEDOUT if the command does not
+ complete in time. While the device activates, committing a
+ region on it fails with EBUSY. If the command times out, the
+ device may still be activating. Until a later write finds the
+ slot running or an activation succeeds, committing a region
+ still fails with EBUSY, a firmware upload fails with the error
+ device-busy, and sanitize and secure erase fail with EBUSY. If
+ the device ends up keeping its old firmware, this lasts until
+ cxl_pci is bound again; firmware can be uploaded again after
+ that. If the device still reports another slot set up for
+ activation on the next cold reset after the online activation,
+ a warning is logged. The firmware_version attribute is read
+ once at probe and is not updated by an online activation; the
+ version of each slot is available from the Get FW Info command.
+ If this file is not present, the device does not support
+ firmware update.
+
+
What: /sys/bus/cxl/devices/memX/payload_max
Date: December, 2020
KernelVersion: v5.12
@@ -140,6 +179,9 @@ Description:
transitions between software programmed and hardware committed
states. If this file is not present, then there is no hardware
support for the operation.
+ While an online firmware activation started through
+ firmware_activate may still be running, the write fails with
+ EBUSY.
What /sys/bus/cxl/devices/memX/security/erase
@@ -156,6 +198,9 @@ Description:
transitions between software programmed and hardware committed
states. If this file is not present, then there is no hardware
support for the operation.
+ While an online firmware activation started through
+ firmware_activate may still be running, the write fails with
+ EBUSY.
What: /sys/bus/cxl/devices/memX/firmware/
diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
index ad60be0964..503f8f4a18 100644
--- a/drivers/cxl/core/hdm.c
+++ b/drivers/cxl/core/hdm.c
@@ -923,6 +923,7 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
/*
* For endpoint decoders hosted on CXL memory devices that
* support the sanitize operation, make sure sanitize is not in-flight.
+ * Likewise for an online firmware activation.
*/
if (is_endpoint_decoder(&cxld->dev)) {
struct cxl_endpoint_decoder *cxled =
@@ -937,6 +938,12 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
dev_name(&cxld->dev));
return -EBUSY;
}
+ if (mds && test_bit(CXL_FW_ACTIVATING, mds->fw.state)) {
+ dev_dbg(&cxlmd->dev,
+ "attempted to commit %s during firmware activation\n",
+ dev_name(&cxld->dev));
+ return -EBUSY;
+ }
}
scoped_guard(rwsem_read, &cxl_rwsem.dpa)
diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
index f9f1c6ce79..5eef96d39f 100644
--- a/drivers/cxl/core/mbox.c
+++ b/drivers/cxl/core/mbox.c
@@ -1339,6 +1339,11 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd)
guard(device)(&cxlmd->dev);
endpoint = cxlmd->endpoint;
guard(rwsem_read)(&cxl_rwsem.region);
+
+ /* An online FW activation that timed out may still be running */
+ if (test_bit(CXL_FW_ACTIVATING, mds->fw.state))
+ return -EBUSY;
+
/*
* Require an endpoint to be safe otherwise the driver can not
* be sure that the device is unmapped.
diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
index cdbebd1225..cc9ff0dd9c 100644
--- a/drivers/cxl/core/memdev.c
+++ b/drivers/cxl/core/memdev.c
@@ -51,6 +51,35 @@ static ssize_t firmware_version_show(struct device *dev,
}
static DEVICE_ATTR_RO(firmware_version);
+static int cxl_mem_activate_fw_online(struct cxl_memdev_state *mds,
+ unsigned int slot);
+
+static ssize_t firmware_activate_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
+ struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
+ unsigned int slot;
+ int rc;
+
+ if (!mds)
+ return -EOPNOTSUPP;
+
+ rc = kstrtouint(buf, 0, &slot);
+ if (rc)
+ return rc;
+
+ /* Exclude a firmware upload and a second activation */
+ if (test_and_set_bit(CXL_FW_BUSY, mds->fw.state))
+ return -EBUSY;
+ rc = cxl_mem_activate_fw_online(mds, slot);
+ clear_bit(CXL_FW_BUSY, mds->fw.state);
+
+ return rc ? rc : len;
+}
+static DEVICE_ATTR_WO(firmware_activate);
+
static ssize_t payload_max_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -412,6 +441,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_clear_poison, "CXL");
static struct attribute *cxl_memdev_attributes[] = {
&dev_attr_serial.attr,
&dev_attr_firmware_version.attr,
+ &dev_attr_firmware_activate.attr,
&dev_attr_payload_max.attr,
&dev_attr_label_storage_size.attr,
&dev_attr_numa_node.attr,
@@ -475,6 +505,18 @@ static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a,
{
if (!IS_ENABLED(CONFIG_NUMA) && a == &dev_attr_numa_node.attr)
return 0;
+
+ if (a == &dev_attr_firmware_activate.attr) {
+ struct device *dev = kobj_to_dev(kobj);
+ struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
+ struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
+
+ /* Same condition as devm_cxl_setup_fw_upload() */
+ if (!mds || !test_bit(CXL_MEM_COMMAND_ID_GET_FW_INFO,
+ mds->cxlds.cxl_mbox.enabled_cmds))
+ return 0;
+ }
+
return a->mode;
}
@@ -936,6 +978,7 @@ static int cxl_mem_get_fw_info(struct cxl_memdev_state *mds)
* cxl_mem_activate_fw - Activate Firmware
* @mds: The device data for the operation
* @slot: slot number to activate
+ * @action: CXL_FW_ACTIVATE_ONLINE or CXL_FW_ACTIVATE_OFFLINE
*
* Activate firmware in a given slot for the device specified.
*
@@ -943,7 +986,8 @@ static int cxl_mem_get_fw_info(struct cxl_memdev_state *mds)
*
* See CXL-3.0 8.2.9.3.3 Activate FW
*/
-static int cxl_mem_activate_fw(struct cxl_memdev_state *mds, int slot)
+static int cxl_mem_activate_fw(struct cxl_memdev_state *mds, int slot,
+ u8 action)
{
struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
struct cxl_mbox_activate_fw activate;
@@ -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);
+ }
+
+ 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);
+
+ if (rc) {
+ if (info_rc)
+ dev_err(&cxlmd->dev,
+ "online activation of slot %u failed: %d\n",
+ slot, rc);
+ else
+ dev_err(&cxlmd->dev,
+ "online activation of slot %u failed: %d, active slot %d\n",
+ slot, rc, mds->fw.cur_slot);
+ return rc;
+ }
+
+ dev_info(&cxlmd->dev, "firmware slot %u activated online\n", slot);
+
+ /*
+ * Whether a reset-activation set up by the upload stays pending
+ * after an online activation is up to the device. Tell the user if
+ * the next cold reset would switch to another slot.
+ */
+ if (!info_rc && mds->fw.pending_slot &&
+ mds->fw.pending_slot != mds->fw.cur_slot)
+ dev_warn(&cxlmd->dev,
+ "slot %d is still set up for activation on the next cold reset\n",
+ mds->fw.pending_slot);
+ return 0;
+}
+
/**
* cxl_mem_abort_fw_xfer - Abort an in-progress FW transfer
* @mds: The device data for the operation
@@ -1015,6 +1182,7 @@ static void cxl_fw_cleanup(struct fw_upload *fwl)
struct cxl_memdev_state *mds = fwl->dd_handle;
mds->fw.next_slot = 0;
+ clear_bit(CXL_FW_BUSY, mds->fw.state);
}
static int cxl_fw_do_cancel(struct fw_upload *fwl)
@@ -1041,18 +1209,33 @@ static enum fw_upload_err cxl_fw_prepare(struct fw_upload *fwl, const u8 *data,
if (!size)
return FW_UPLOAD_ERR_INVALID_SIZE;
+ /* Exclude an online activation running from sysfs */
+ if (test_and_set_bit(CXL_FW_BUSY, mds->fw.state))
+ return FW_UPLOAD_ERR_BUSY;
+
+ /* ... and one that timed out, which the device may still be running */
+ if (test_bit(CXL_FW_ACTIVATING, mds->fw.state)) {
+ clear_bit(CXL_FW_BUSY, mds->fw.state);
+ return FW_UPLOAD_ERR_BUSY;
+ }
+
mds->fw.oneshot = struct_size(transfer, data, size) <=
cxl_mbox->payload_size;
- if (cxl_mem_get_fw_info(mds))
+ if (cxl_mem_get_fw_info(mds)) {
+ clear_bit(CXL_FW_BUSY, mds->fw.state);
return FW_UPLOAD_ERR_HW_ERROR;
+ }
/*
* So far no state has been changed, hence no other cleanup is
- * necessary. Simply return the cancelled status.
+ * necessary. Simply return the cancelled status. ->cleanup() is
+ * not called when ->prepare() fails.
*/
- if (test_and_clear_bit(CXL_FW_CANCEL, mds->fw.state))
+ if (test_and_clear_bit(CXL_FW_CANCEL, mds->fw.state)) {
+ clear_bit(CXL_FW_BUSY, mds->fw.state);
return FW_UPLOAD_ERR_CANCELED;
+ }
return FW_UPLOAD_ERR_NONE;
}
@@ -1142,7 +1325,8 @@ static enum fw_upload_err cxl_fw_write(struct fw_upload *fwl, const u8 *data,
if (mds->fw.oneshot || remaining == 0) {
dev_dbg(&cxlmd->dev, "Activating firmware slot: %d\n",
mds->fw.next_slot);
- rc = cxl_mem_activate_fw(mds, mds->fw.next_slot);
+ rc = cxl_mem_activate_fw(mds, mds->fw.next_slot,
+ CXL_FW_ACTIVATE_OFFLINE);
if (rc < 0) {
dev_err(&cxlmd->dev, "Error activating firmware: %d\n",
rc);
diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
index a67e451a62..7674390a73 100644
--- a/drivers/cxl/cxlmem.h
+++ b/drivers/cxl/cxlmem.h
@@ -379,6 +379,8 @@ struct cxl_mbox_activate_fw {
/* FW state bits */
#define CXL_FW_STATE_BITS 32
#define CXL_FW_CANCEL 0
+#define CXL_FW_BUSY 1
+#define CXL_FW_ACTIVATING 2
/**
* struct cxl_fw_state - Firmware upload / activation state
@@ -390,6 +392,7 @@ struct cxl_mbox_activate_fw {
* @next_slot: Slot number for the new firmware
* @pending_slot: Slot to be activated on the next cold reset, 0 if none
* @activation_cap: FW Activation Capabilities from Get FW Info
+ * @activating_slot: Slot of an online activation that timed out, 0 if none
*/
struct cxl_fw_state {
DECLARE_BITMAP(state, CXL_FW_STATE_BITS);
@@ -399,6 +402,7 @@ struct cxl_fw_state {
int next_slot;
int pending_slot;
u8 activation_cap;
+ int activating_slot;
};
/**
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH 4/4] tools/testing/cxl: Add a knob to advertise online FW activation
2026-11-25 12:43 [RFC PATCH 0/4] cxl/memdev: Activate firmware without a reset Unsung Lee
` (2 preceding siblings ...)
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:43 ` Unsung Lee
2026-11-25 12:53 ` [RFC PATCH 0/4] cxl/memdev: Activate firmware without a reset Unsung Lee
4 siblings, 0 replies; 7+ messages in thread
From: Unsung Lee @ 2026-11-25 12:43 UTC (permalink / raw)
To: linux-cxl
Cc: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, John Groves
cxl_test memdevs report no online activation support, so the new
firmware_activate attribute can only be tested for the EOPNOTSUPP case.
Add a fw_online_activation module parameter that sets bit 0 of FW
Activation Capabilities in Get FW Info. The default keeps the current
behaviour.
Signed-off-by: Unsung Lee <unsung0317@gmail.com>
---
tools/testing/cxl/test/mem.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
index c740372bda..7fefc91921 100644
--- a/tools/testing/cxl/test/mem.c
+++ b/tools/testing/cxl/test/mem.c
@@ -23,6 +23,11 @@
#define MOCK_INJECT_DEV_MAX 8
#define MOCK_INJECT_TEST_MAX 128
+static bool fw_online_activation;
+module_param(fw_online_activation, bool, 0444);
+MODULE_PARM_DESC(fw_online_activation,
+ "Advertise online FW activation in Get FW Info");
+
static unsigned int poison_inject_dev_max = MOCK_INJECT_DEV_MAX;
enum cxl_command_effects {
@@ -1327,7 +1332,8 @@ static int mock_fw_info(struct cxl_mockmem_data *mdata,
.num_slots = FW_SLOTS,
.slot_info = (mdata->fw_slot & 0x7) |
((mdata->fw_staged & 0x7) << 3),
- .activation_cap = 0,
+ .activation_cap = fw_online_activation ?
+ CXL_FW_INFO_ACTIVATION_CAP_HAS_LIVE_ACTIVATE : 0,
};
strcpy(fw_info.slot_1_revision, "cxl_test_fw_001");
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 0/4] cxl/memdev: Activate firmware without a reset
2026-11-25 12:43 [RFC PATCH 0/4] cxl/memdev: Activate firmware without a reset Unsung Lee
` (3 preceding siblings ...)
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 ` Unsung Lee
4 siblings, 0 replies; 7+ messages in thread
From: Unsung Lee @ 2026-11-25 12:53 UTC (permalink / raw)
To: linux-cxl
Sorry for the noise. A mistake in my test sends put six copies of this
cover letter on the list on their own (12:10 to 12:42 UTC), without the
patches, and some with older text. Please ignore those; this thread,
with patches 1-4, is the series.
Unsung
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 3/4] cxl/memdev: Add firmware_activate to activate firmware without a reset
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
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-25 12:57 UTC (permalink / raw)
To: Unsung Lee, linux-cxl
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-25 12:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox