[PATCH v18 00/19] PCI/CXL: Add CXL reset support for Type 2 devices

From: Srirangan Madhavan

Date: Fri Dec 04 2026 - 23:15:17 EST


Hi folks,

This series adds CXL Reset for Type 2 devices through the existing PCI
reset_method and reset sysfs attributes. It disables CXL.cache, performs
supported cache writeback, initiates CXL Reset with Memory Clear, and
restores cached HDM decoder and CXL Device DVSEC state before PCI use
resumes. Active HDM ranges are reserved and CPU caches invalidated
before and after reset. The method remains limited to eligible
single-function devices with both CXL.cache and CXL.mem enabled. CXL bus
reset restores the same cached state and flushes the host and device
caches around the reset.

The reset sequence follows the CXL 4.0 specification [5], including
CXL.cache disable, optional cache writeback, CXL Reset Memory Clear,
ResetComplete polling, and ResetError reporting. Sections 9.7.2 and
9.7.3 define the completion timeout encodings and reset access
restrictions.

The userspace ABI is the existing PCI reset interface:

/sys/bus/pci/devices/.../reset_method
/sys/bus/pci/devices/.../reset

Userspace selects "cxl_reset" in reset_method and triggers the reset
through reset. Following Dan's v6 feedback, this uses the PCI interface
instead of adding a memdev-specific sysfs ABI.

For sysfs reset, the generic PCI path invokes the driver's
reset_prepare() callback when provided and disables PCI I/O, memory
decoding, and bus mastering. The CXL path reserves affected HDM ranges
exclusively and blocks IOMMU translations where applicable. It does not
offline memory or revoke mappings: userspace is expected to offline
CXL.mem users before reset. The reservation enforces this for claimed
ranges by failing the reset while a conflicting resource is claimed.

Locking changed in v18. The global region lock is no longer held across
the reset. Both reset paths take cxl_rwsem.region only for four short
windows:

prepare: snapshot the cache, validate and reserve the HPA ranges,
set reset_pending
(no region lock) host cache flush, device cache writeback
offline: set regs_offline
(no region lock) reset, Memory Clear wait for cxl_reset
restore: re-read the cached decoders, restore the state,
clear regs_offline
(no region lock) host cache flush
unmark: clear reset_pending

While reset_pending is set, cxl_decoder_commit() returns -EBUSY for that
device, so no region using it can commit in the middle of a reset. While
regs_offline is set, a region teardown only updates the software state
and the cache and leaves the registers alone; the restore then programs
the decoders from the updated cache. Dave's lockdep reproducer [6] (a
region read, a device remove and a slot power-off during the reset) no
longer hangs.

Changes from v17 [1]:
- Rebased onto cxl/for-7.5/cxl-kunit (Alison)
- Reworked the locking as described above, for both cxl_reset and
cxl_bus (Dave, Alison) [6][7]. disable_hdm() now also updates the
cached global control, and the restore re-reads the decoders from the
cache (Dave)
- Fixes from the Sashiko review [10]: the reset preconditions are
checked in the prepare step, so a refused CXL reset no longer falls
back to FLR; DVSEC-decoded memory is judged from the snapshot;
Normalized Addressing survives decoder refreshes; CXL.cache stays off
until the host caches are flushed; a bus reset checks that it can run
before touching the device; function 0 of an ARI device is rejected
when other functions share the bus; all-ones config reads are rejected
when filling the cache
- cxl_reset now refuses, as cxl_bus already did, when CXL.cache is
enabled but the device cannot write back its cache
- Smaller cleanups in patches 2 and 9-12 (Dave, Li Ming). Each patch has
the details.
- Dropped the Assisted-by trailers and added Dave's Reviewed-by to
patches 7 and 8

Still open: Alison's question about resetting before Normalized
Addressing is known [8] and Alejandro's CXL.io/IOMMU question [9]. I'll
follow up in those threads. Earlier history is in the v16 [2] and v15
[3] cover letters.

HDM caching needs the CXL.cache, CXL.mem, CXL Reset and Reset Memory
Clear capabilities, and CXL bus reset restores its state from the same
cache.

CXL Reset also needs a CPU cache clean/invalidate provider, such as the
SMCCC series [4]. Without one, cxl_reset is still listed but fails with
-ENXIO and does not fall back to FLR, unless the test-only
CXL_REGION_INVALIDATION_TEST option is set.

The KUnit suite covers HDM range boundaries, zero-size and uncommitted
decoders, lock and target-type decoding, and 12-way interleave.

AI coding assistants were used to help write and review parts of this
series, and an AI review found two of the v18 fixes. I have reviewed
all AI-assisted changes.

Testing: I ran v18 in QEMU with two cxl-type2 devices behind two CXL
host bridges and lockdep on, for both cxl_reset and cxl_bus, with a
delay added in the prepare step. A region read and a device remove
complete during the delay, and lockdep reports nothing for the CXL
locks. The pciehp slot power-off path still shows the existing
pci_rescan_remove_lock vs reset_lock warning, which also shows up
without this series. Each patch builds with W=1, and Clang 23 context
analysis is clean for the touched files. The CXL KUnit suites, including
cxl_hdm_unpack_kunit, pass.

On hardware, I ran v18 with the SMCCC provider series [4] (provider in
use, CXL_REGION_INVALIDATION_TEST off) on an ARM64 system with four CXL
Type 2 devices and the vendor driver bound. On each device I onlined
the memory as a NUMA node, left dirty CPU cache lines in it, offlined
it, and then issued the driver's CXL reset and CXL bus reset requests
(which select cxl_reset and cxl_bus) once each. All of them succeeded.
Afterwards all four devices still had the CXL DVSEC, CXL.cache and
CXL.mem were still enabled on the device I checked, and a CPU fill and
verify of the device memory matched.

[1] https://lore.kernel.org/linux-cxl/20261105185917.2667656-1-smadhavan@xxxxxxxxxx/
[2] https://lore.kernel.org/linux-cxl/20261029145703.2185231-1-smadhavan@xxxxxxxxxx/
[3] https://lore.kernel.org/linux-cxl/20261011021422.3428136-1-smadhavan@xxxxxxxxxx/
[4] https://lore.kernel.org/linux-arm-kernel/20261021224557.1827361-1-smadhavan@xxxxxxxxxx/
[5] https://computeexpresslink.org/wp-content/uploads/2026/02/CXL-Specification_rev4p0_ver1p0_2026February26_clean_evalcopy_v2.pdf
[6] https://lore.kernel.org/linux-cxl/5616c825-454e-4eba-9352-b06d98dc123a@xxxxxxxxx/
[7] https://lore.kernel.org/linux-cxl/avyOoQjiD7Uh_3rE@xxxxxxxxxxxxxxxxxx/
[8] https://lore.kernel.org/linux-cxl/avyPsvwV1_lc9va5@xxxxxxxxxxxxxxxxxx/
[9] https://lore.kernel.org/linux-cxl/f5fdc266-aed3-47e6-a10f-e8188b58c93f@xxxxxxx/
[10] https://sashiko.dev/#/patchset/20261105185917.2667656-1-smadhavan@xxxxxxxxxx

Srirangan Madhavan (19):
cxl: Clarify decoder interleave limit
cxl: Share CXL port upstream PCI device lookup
cxl: Move decoder declarations to shared header
cxl: Embed decoder configuration in a standalone structure
cxl: Introduce endpoint HDM decoder settings
cxl: Move HDM decoder helpers to built-in code
cxl: Share HDM decoder register unpacking
cxl: Move cxl_rwsem into built-in code
cxl: Refresh cached PCI HDM decoder settings
cxl: Build register block helpers into the kernel
PCI/CXL: Cache endpoint HDM state during PCI enumeration
PCI/CXL: Add CXL Device Reset sequencing
cxl: Validate and synchronize HDM ranges around reset
PCI/CXL: Reject reset with unsafe function scope
PCI/CXL: Restore CXL state after PCI reset
PCI/CXL: Expose CXL Reset as a PCI reset method
PCI/CXL: Restore CXL state after CXL bus reset
PCI/CXL: Flush host and device caches for CXL bus reset
cxl: Add KUnit checks for HDM decoder unpacking

MAINTAINERS | 1 +
drivers/cxl/Kconfig | 8 +-
drivers/cxl/acpi.c | 26 +-
drivers/cxl/core/Makefile | 2 +-
drivers/cxl/core/atl.c | 4 +-
drivers/cxl/core/core.h | 15 +
drivers/cxl/core/hdm.c | 315 ++++----
drivers/cxl/core/hdm_regs.c | 443 +++++++++++
drivers/cxl/core/hdm_state.c | 499 +++++++++++++
drivers/cxl/core/pci.c | 140 ++--
drivers/cxl/core/port.c | 62 +-
drivers/cxl/core/region.c | 117 +--
drivers/cxl/core/regs.c | 9 +
drivers/cxl/cxl.h | 46 +-
drivers/cxl/pci.c | 2 +-
drivers/cxl/port.c | 4 +-
drivers/cxl/tests/Makefile | 3 +
drivers/cxl/tests/hdm_unpack_kunit.c | 91 +++
drivers/pci/Makefile | 1 +
drivers/pci/bus.c | 1 +
drivers/pci/cxl.c | 1029 ++++++++++++++++++++++++++
drivers/pci/pci.c | 57 +-
drivers/pci/pci.h | 51 ++
drivers/pci/probe.c | 1 +
include/cxl/cxl.h | 57 +-
include/cxl/hdm.h | 119 +++
include/cxl/pci.h | 13 +
include/linux/pci.h | 8 +-
include/uapi/linux/pci_regs.h | 14 +
tools/testing/cxl/Kbuild | 1 -
tools/testing/cxl/test/cxl.c | 158 ++--
31 files changed, 2850 insertions(+), 447 deletions(-)
create mode 100644 drivers/cxl/core/hdm_regs.c
create mode 100644 drivers/cxl/core/hdm_state.c
create mode 100644 drivers/cxl/tests/hdm_unpack_kunit.c
create mode 100644 drivers/pci/cxl.c
create mode 100644 include/cxl/hdm.h


base-commit: 533928808ac1e6a96a7daa74b6ad68c3f7f43a28
--
2.43.0