Skip to contentSkip to conversation

cxl/memdev: Activate firmware without a reset

RFC PATCH New Unsung Lee 1 participant 1 message Nov 25

lore
Share & tools
lore

Unsung Lee

author
#0 lore raw

cover cxl/memdev: Activate firmware without a reset

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.

Open questions:
- Online activation is meant to let the device keep serving requests. Patch 3 still requires the device not to decode memory, as sanitize does, because the driver cannot tell how long a given device holds CXL.mem requests while it switches firmware. 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 there is no transaction to time out, which is how patch 3 avoids that coordination. Is that the right condition, or too strict? It means moving the data away first.
- Can Activate FW be a background command per the spec? QEMU's CEL marks it so, and patch 1 waits for it like Transfer FW; no Fixes: tag until that is confirmed.
- John Groves raised at the CXL collab sync in June 2025 that firmware activation can take longer than the 2 s mailbox timeout. A patch from that discussion may overlap with patch 1.
- Patch 1 assumes the device can still be polled for completion while it activates in the background. A device may stop answering the mailbox meanwhile; this needs checking on real devices.
- State cached at probe (CEL, timestamp, event interrupt policy, features, Identify, CDAT) may change with the new firmware. This series does not refresh it.
- Patch 3 holds cxl_rwsem.region only to check the decoders and set a FW state bit; decoder commit then refuses this device with EBUSY, like sanitize. An earlier version held the rwsem across the command (up to 30 s). With an activation emulated in the kernel (QEMU completes it at once), create-region and region sysfs reads on other devices then waited as long as the activation (about 30 s for 30 s), against tens of ms with the bit; after a timeout the earlier version let a decoder of the still activating device commit. The cost is that a create-region on the device racing the write fails instead of waiting, and after a timeout the device refuses regions until a later write finds the slot running or an activation succeeds. Is that the preferred trade-off?
- After a timeout patch 3 clears its mark only on a fact: the slot shows as running, or a later activation succeeds. An error from a later Activate FW is not taken as a sign that the device is done, since it may come while the device is still busy with the earlier one. The cost is that a device which ends up keeping its old firmware refuses regions, firmware uploads and sanitize until cxl_pci is bound again (uploads and sanitize are refused so that no state changing command depends on the device answering Busy). The Background Command Status register, which cxl_pci already uses to detect completion, would tell when the earlier activation has finished; reading it from patch 3 needs a new mailbox callback. Would that be acceptable?
- Hosts sharing the device are not visible to the decoder check, and an activation through another CCI (e.g. MCTP from a BMC) is not reported to the host.
- The device lock held across the command keeps cxl_mem from being unbound or probed meanwhile, but unbinding the port above the endpoint (or the endpoint port) still tears the endpoint down. No decoder is committed then, so none is reset, but the teardown clears HDM decoder enable and Mem_Enable if the driver set them, i.e. it writes to the device while it activates.
- Should the pending slot stay set after an online activation? QEMU keeps it, cxl_test clears it.

Testing (QEMU 11.1.3, one type3 device, guest v7.3.1 unless noted; no real hardware, so an activation that really takes long, 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. Once the port is bound again, create-region fails on plain v7.3.1 as well, so that test checks no region 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

Signature · 1 line
2.34.1