* [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
` (5 more replies)
0 siblings, 6 replies; 12+ 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] 12+ 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
` (4 subsequent siblings)
5 siblings, 0 replies; 12+ 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] 12+ 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
` (3 subsequent siblings)
5 siblings, 0 replies; 12+ 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] 12+ 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-27 20:05 ` Davidlohr Bueso
2026-11-25 12:43 ` [RFC PATCH 4/4] tools/testing/cxl: Add a knob to advertise online FW activation Unsung Lee
` (2 subsequent siblings)
5 siblings, 2 replies; 12+ 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] 12+ 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
2026-11-27 19:51 ` Davidlohr Bueso
5 siblings, 0 replies; 12+ 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] 12+ 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
2026-11-27 19:51 ` Davidlohr Bueso
5 siblings, 0 replies; 12+ 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] 12+ 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
2026-11-27 20:05 ` Davidlohr Bueso
1 sibling, 0 replies; 12+ 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] 12+ 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
` (4 preceding siblings ...)
2026-11-25 12:53 ` [RFC PATCH 0/4] cxl/memdev: Activate firmware without a reset Unsung Lee
@ 2026-11-27 19:51 ` Davidlohr Bueso
2026-11-28 6:23 ` us l
5 siblings, 1 reply; 12+ messages in thread
From: Davidlohr Bueso @ 2026-11-27 19:51 UTC (permalink / raw)
To: Unsung Lee
Cc: linux-cxl, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, John Groves
On Wed, 25 Nov 2026, Unsung Lee wrote:
>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
Is this a real use case for online activation?
This now seems like an interface clash, memX/firmware/activate would
be better. The upload device is registered to the fw class.
> 4. recreate the region and online the memory
So this work requires a CXL equivalent of
Documentation/driver-api/nvdimm/firmware-activate.rst
.. describing the flow, states and the results. Patch 3 only extends the
ABI file. The capability would be quiescence-like.
>
>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.
This makes sense but really is the show stopper for your patch 1, where
bg polling timeouts (albeit 30 secs) leave things in a very bad state if
the device is to ever be onlined again.
>- 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.
Semantically, transfer fw makes sense to have with the timeouts because
users can partition the work, which is the whole point. Activate fw
lacks those semantics, so while 30 secs seems like a value unlikely
to timeout, there are no guarantees (I have no idea about activation
time expectations really).
This plus the above answer means that we should just move activate fw
to the sanitize category as a potential mailbox hogger and just wait
asynchronously... which is what I did with the followup series to this
collab sync meeting:
https://lore.kernel.org/all/20250617193611.564668-3-dave@stgolabs.net/
(i am rebasing this series and will send out)
>- 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?
See above.
>- 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).
Dave wants new features without dependencies to be based against Linus'
latest, instead of cxl/next. That said, testing cxl/next is quite welcome
always, so while the qemu breakage is inconvenient, it's worth just using
a newer qemu from source.
Thanks,
Davidlohr
^ permalink raw reply [flat|nested] 12+ 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
@ 2026-11-27 20:05 ` Davidlohr Bueso
2026-12-01 23:20 ` Dave Jiang
1 sibling, 1 reply; 12+ messages in thread
From: Davidlohr Bueso @ 2026-11-27 20:05 UTC (permalink / raw)
To: Unsung Lee
Cc: linux-cxl, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, John Groves
On Wed, 25 Nov 2026, Unsung Lee wrote:
>+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.
EWAYTOOLONG ... please less specific details about return codes and comparisons
with with other ABI files.
Thanks,
Davidlohr
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH 0/4] cxl/memdev: Activate firmware without a reset
2026-11-27 19:51 ` Davidlohr Bueso
@ 2026-11-28 6:23 ` us l
2026-12-01 19:07 ` Davidlohr Bueso
0 siblings, 1 reply; 12+ messages in thread
From: us l @ 2026-11-28 6:23 UTC (permalink / raw)
To: Davidlohr Bueso
Cc: linux-cxl, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, John Groves
Hello Davidlohr,
Thanks for the review and for pointing me to your series. I read
the June 2025 thread and the sashiko report.
On the use case: online activation is part of CXL r3.2, but the
kernel only issues offline activation, so there is no way to use
it today. The motivation is the same as for nvdimm runtime firmware
activation: updating memory device firmware should not require a
reboot. This series is a first step and only allows it when the
device is not decoding memory. I do not have hardware that
supports it; testing so far is QEMU only.
On the ABI: v2 will add a CXL counterpart of
Documentation/driver-api/nvdimm/firmware-activate.rst and keep the
ABI entry short. On placement, see question 1 below.
On timeouts: agreed. v2 drops patch 1 and builds on your series,
with Activate FW handled asynchronously like sanitize. What remains
on my side is the "not decoding" check before starting and refusing
decoder commits while the activation runs. Both sashiko findings
are valid; they come from the timeout handling, which goes away
with this.
On the base: v2 will be based on Linus' latest and tested on
cxl/next with QEMU built from master.
Questions:
1. I looked at placing the attribute under memX/firmware/. That
directory is the firmware loader's class directory: the upload
files live in memX/firmware/memX/ and their set is fixed by the
loader core, and a memdev attribute group named "firmware"
would collide with it. So it would need either loader core
support for driver attributes, or keeping it on the memdev, as
intel-m10-bmc-sec-update does with its "security" group. Which
would you prefer?
2. Once the command runs asynchronously, the caller gets success
right away and the result in the background command status is
not kept. For online activation, userspace needs to wait for
completion and see whether it succeeded, as with the sanitize
state and the nvdimm result attribute. Would you prefer to
record the result in your series, or should I add it on top?
3. Is there a branch with your rebased series that I could build
on until you resend?
Thanks,
Unsung
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH 0/4] cxl/memdev: Activate firmware without a reset
2026-11-28 6:23 ` us l
@ 2026-12-01 19:07 ` Davidlohr Bueso
0 siblings, 0 replies; 12+ messages in thread
From: Davidlohr Bueso @ 2026-12-01 19:07 UTC (permalink / raw)
To: us l
Cc: linux-cxl, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, John Groves
On Sat, 28 Nov 2026, us l wrote:
>Hello Davidlohr,
>
>Thanks for the review and for pointing me to your series. I read
>the June 2025 thread and the sashiko report.
>
>On the use case: online activation is part of CXL r3.2, but the
>kernel only issues offline activation, so there is no way to use
>it today. The motivation is the same as for nvdimm runtime firmware
>activation: updating memory device firmware should not require a
>reboot. This series is a first step and only allows it when the
>device is not decoding memory. I do not have hardware that
>supports it; testing so far is QEMU only.
Ok, I was curious if this was actual a real device.
>
>On the ABI: v2 will add a CXL counterpart of
>Documentation/driver-api/nvdimm/firmware-activate.rst and keep the
>ABI entry short. On placement, see question 1 below.
>
>On timeouts: agreed. v2 drops patch 1 and builds on your series,
>with Activate FW handled asynchronously like sanitize. What remains
>on my side is the "not decoding" check before starting and refusing
>decoder commits while the activation runs. Both sashiko findings
>are valid; they come from the timeout handling, which goes away
>with this.
Please see below.
>
>On the base: v2 will be based on Linus' latest and tested on
>cxl/next with QEMU built from master.
>
>Questions:
>
>1. I looked at placing the attribute under memX/firmware/. That
> directory is the firmware loader's class directory: the upload
> files live in memX/firmware/memX/ and their set is fixed by the
> loader core, and a memdev attribute group named "firmware"
> would collide with it. So it would need either loader core
> support for driver attributes, or keeping it on the memdev, as
> intel-m10-bmc-sec-update does with its "security" group. Which
> would you prefer?
>
>2. Once the command runs asynchronously, the caller gets success
> right away and the result in the background command status is
> not kept. For online activation, userspace needs to wait for
> completion and see whether it succeeded, as with the sanitize
> state and the nvdimm result attribute. Would you prefer to
> record the result in your series, or should I add it on top?
Correct, I added the diff below to my series (patch 2).
However, regarding online activation, it seems that quiescence is
actually not required (so device need not be offlined). Per the
spec 8.2.10.3.3:
""
Online FW activation does not affect the data, the Metadata bits (if present), and/or
Extended Metadata (if present), that are stored by the device. In addition, CXL
requests are correctly processed during online firmware activation.
""
... but I still think waiting async is better because users cannot
timeslice. However, for the loader layer <-> core mbox driver, the
caller would have to wait synchronously (per below) so we don't run
into the returning success right away issue you mention. This is a bit
daft and adds complexity, unfortunately.
When compared with nvdimm, the hw does give an estimate to how long
the online would take (and has an ABI that reports if it will timeout).
This makes me think that your patch 1 would be ok if CXL would provide
that (ie: via Get FW Info) and arm the timeout accordingly. So if this
is not a _real hw_ use case, then maybe just try to add this to the spec
first?
John, any thoughts?
Thanks,
Davidlohr
----8<-----------------------
diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
index fcb3807d2581..e688e82d2401 100644
--- a/drivers/cxl/core/mbox.c
+++ b/drivers/cxl/core/mbox.c
@@ -1822,6 +1822,7 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial,
}
mutex_init(&mds->event.log_lock);
+ rcuwait_init(&mds->fw.wait);
return mds;
}
diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
index 3edc28e9aa0d..37f06d8491bd 100644
--- a/drivers/cxl/core/memdev.c
+++ b/drivers/cxl/core/memdev.c
@@ -945,6 +945,7 @@ static int cxl_mem_activate_fw(struct cxl_memdev_state *mds, int slot)
struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
struct cxl_mbox_activate_fw activate;
struct cxl_mbox_cmd mbox_cmd;
+ int rc;
if (slot == 0 || slot > mds->fw.num_slots)
return -EINVAL;
@@ -959,7 +960,12 @@ static int cxl_mem_activate_fw(struct cxl_memdev_state *mds, int slot)
activate.action = CXL_FW_ACTIVATE_OFFLINE;
activate.slot = slot;
- return cxl_internal_send_cmd(cxl_mbox, &mbox_cmd);
+ rc = cxl_internal_send_cmd(cxl_mbox, &mbox_cmd);
+ /* left running in the background, see cxl_fw_poll_complete() */
+ mds->fw.activate_bg = !rc &&
+ mbox_cmd.return_code == CXL_MBOX_CMD_RC_BACKGROUND;
+
+ return rc;
}
/**
@@ -1150,6 +1156,12 @@ static enum fw_upload_err cxl_fw_write(struct fw_upload *fwl, const u8 *data,
static enum fw_upload_err cxl_fw_poll_complete(struct fw_upload *fwl)
{
struct cxl_memdev_state *mds = fwl->dd_handle;
+ struct cxl_dev_state *cxlds = &mds->cxlds;
+ struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox;
+ struct device *dev = &cxlds->cxlmd->dev;
+ struct cxl_mbox_cmd activate = {
+ .opcode = CXL_MBOX_OP_ACTIVATE_FW,
+ };
/*
* cxl_internal_send_cmd() handles background operations synchronously.
@@ -1157,8 +1169,37 @@ static enum fw_upload_err cxl_fw_poll_complete(struct fw_upload *fwl)
* reported and handled during the ->write() call(s).
* Just check if a cancel request was received, and return success.
*/
- if (test_and_clear_bit(CXL_FW_CANCEL, mds->fw.state))
- return cxl_fw_do_cancel(fwl);
+ if (!mds->fw.activate_bg) {
+ if (test_and_clear_bit(CXL_FW_CANCEL, mds->fw.state))
+ return cxl_fw_do_cancel(fwl);
+
+ return FW_UPLOAD_ERR_NONE;
+ }
+
+ /*
+ * The exception is an Activate FW that was left running in the
+ * background: wait for it here, for as long as hardware takes. The
+ * transfer is over, so a cancel request has nothing to abort and
+ * only gives up on the wait.
+ */
+ mds->fw.activate_bg = false;
+ rcuwait_wait_event(&mds->fw.wait,
+ !test_bit(CXL_FW_ACTIVATING, mds->fw.state) ||
+ test_bit(CXL_FW_CANCEL, mds->fw.state),
+ TASK_IDLE);
+
+ clear_bit(CXL_FW_CANCEL, mds->fw.state);
+ if (test_bit(CXL_FW_ACTIVATING, mds->fw.state))
+ return FW_UPLOAD_ERR_CANCELED;
+
+ scoped_guard(mutex, &cxl_mbox->mbox_mutex)
+ activate.return_code = mds->fw.activate_rc;
+
+ if (activate.return_code != CXL_MBOX_CMD_RC_SUCCESS) {
+ dev_err(dev, "Error activating firmware: %s\n",
+ cxl_mbox_cmd_rc2str(&activate));
+ return FW_UPLOAD_ERR_HW_ERROR;
+ }
return FW_UPLOAD_ERR_NONE;
}
@@ -1168,6 +1209,8 @@ static void cxl_fw_cancel(struct fw_upload *fwl)
struct cxl_memdev_state *mds = fwl->dd_handle;
set_bit(CXL_FW_CANCEL, mds->fw.state);
+ /* cxl_fw_poll_complete() may be waiting for an Activate FW */
+ rcuwait_wake_up(&mds->fw.wait);
}
static const struct fw_upload_ops cxl_memdev_fw_ops = {
diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
index ba28d34fe6a4..8567206b5db9 100644
--- a/drivers/cxl/cxlmem.h
+++ b/drivers/cxl/cxlmem.h
@@ -7,6 +7,7 @@
#include <linux/cdev.h>
#include <linux/uuid.h>
#include <linux/node.h>
+#include <linux/rcuwait.h>
#include <cxl/event.h>
#include <cxl/mailbox.h>
#include "cxl.h"
@@ -390,22 +391,29 @@ struct cxl_mbox_activate_fw {
/* FW state bits */
#define CXL_FW_STATE_BITS 32
#define CXL_FW_CANCEL 0
+#define CXL_FW_ACTIVATING 1
/**
* struct cxl_fw_state - Firmware upload / activation state
*
* @state: fw_uploader state bitmask
+ * @wait: where the fw upload waits for a background Activate FW
* @oneshot: whether the fw upload fits in a single transfer
+ * @activate_bg: whether Activate FW was left running in the background
* @num_slots: Number of FW slots available
* @cur_slot: Slot number currently active
* @next_slot: Slot number for the new firmware
+ * @activate_rc: result of the last Activate FW that ran in the background
*/
struct cxl_fw_state {
DECLARE_BITMAP(state, CXL_FW_STATE_BITS);
+ struct rcuwait wait;
bool oneshot;
+ bool activate_bg;
int num_slots;
int cur_slot;
int next_slot;
+ u16 activate_rc;
};
/**
diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
index c55e44b270e9..b03c5ab12654 100644
--- a/drivers/cxl/pci.c
+++ b/drivers/cxl/pci.c
@@ -164,6 +164,17 @@ static void cxl_mbox_bg_end(struct cxl_memdev_state *mds)
mds->security.sanitize_node)
sysfs_notify_dirent(mds->security.sanitize_node);
+ /* the firmware upload is waiting to hear how it went */
+ if (mds->bg.opcode == CXL_MBOX_OP_ACTIVATE_FW && !mds->bg.user) {
+ u64 reg = readq(cxlds->regs.mbox +
+ CXLDEV_MBOX_BG_CMD_STATUS_OFFSET);
+
+ mds->fw.activate_rc =
+ FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_RC_MASK, reg);
+ clear_bit(CXL_FW_ACTIVATING, mds->fw.state);
+ rcuwait_wake_up(&mds->fw.wait);
+ }
+
dev_dbg(cxlds->dev, "Mailbox background operation (0x%04x) ended\n",
mds->bg.opcode);
mds->bg.opcode = 0;
@@ -356,6 +367,9 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_mailbox *cxl_mbox,
mds->bg.poll_tmo_secs = timeout;
mds->bg.opcode = mbox_cmd->opcode;
mds->bg.user = mbox_cmd->user;
+ if (mbox_cmd->opcode == CXL_MBOX_OP_ACTIVATE_FW &&
+ !mbox_cmd->user)
+ set_bit(CXL_FW_ACTIVATING, mds->fw.state);
schedule_delayed_work(&mds->bg.poll_dwork,
timeout * HZ);
} else {
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [RFC PATCH 3/4] cxl/memdev: Add firmware_activate to activate firmware without a reset
2026-11-27 20:05 ` Davidlohr Bueso
@ 2026-12-01 23:20 ` Dave Jiang
0 siblings, 0 replies; 12+ messages in thread
From: Dave Jiang @ 2026-12-01 23:20 UTC (permalink / raw)
To: Davidlohr Bueso, Unsung Lee
Cc: linux-cxl, Jonathan Cameron, Alison Schofield, Vishal Verma,
Ira Weiny, Dan Williams, John Groves
On 11/27/26 1:05 PM, Davidlohr Bueso wrote:
> On Wed, 25 Nov 2026, Unsung Lee wrote:
>
>> +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.
>
> EWAYTOOLONG ... please less specific details about return codes and comparisons
> with with other ABI files.
Agreed. And it reads AI generated. In general for commit logs, comments, and documentation, AI tends to be way too wordy on the verbiage. Please rewrite it so it's easily readable for a human and gets to the point. Providing a possible example below. I used an agent to rework it. Feel free to modify further with what Davidlohr asked.
What: /sys/bus/cxl/devices/memX/firmware_activate
Date: November, 2026
KernelVersion: v7.6
Contact: linux-cxl@vger.kernel.org
Description:
(WO) Write a slot number to activate its firmware now, with
no reset (online Activate FW). Otherwise firmware uploaded
through /sys/class/firmware/memX/ activates on the next cold
reset. Absent if the device does not support firmware update.
Offline the device's memory and destroy its regions first.
Only this host's decoders are checked.
EOPNOTSUPP: no online activation support.
EINVAL: invalid or already active slot.
EBUSY: device decoding memory, upload or sanitize in
progress, or another slot pending for cold reset.
ENXIO: most device errors, including an earlier
activation still running.
ETIMEDOUT: command timed out.
Region commit fails with EBUSY during activation. After
ETIMEDOUT, region commit, sanitize and secure erase (EBUSY)
and firmware upload (device-busy) stay blocked until a later
write finds the slot running or an activation succeeds. If
the old firmware stays, rebind cxl_pci to clear this.
A warning is logged if another slot is still pending for cold
reset afterward. firmware_version is not updated; read slot
versions with Get FW Info.
>
> Thanks,
> Davidlohr
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-12-01 23:20 UTC | newest]
Thread overview: 12+ 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-27 20:05 ` Davidlohr Bueso
2026-12-01 23:20 ` Dave Jiang
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
2026-11-27 19:51 ` Davidlohr Bueso
2026-11-28 6:23 ` us l
2026-12-01 19:07 ` Davidlohr Bueso
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.