From: Srirangan Madhavan <smadhavan@nvidia.com>
To: Alison Schofield <alison.schofield@intel.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Dave Jiang <dave.jiang@intel.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Ira Weiny <iweiny@kernel.org>,
Jonathan Cameron <jic23@kernel.org>,
Vishal Verma <vishal.l.verma@intel.com>,
linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Li Ming <ming.li@zohomail.com>,
Joshua Machauer <machaujo@amazon.de>,
Alex Williamson <alex.williamson@redhat.com>,
vsethi@nvidia.com, alwilliamson@nvidia.com,
Sai Yashwanth Reddy Kancherla <skancherla@nvidia.com>,
Vishal Aslot <vaslot@nvidia.com>,
Manish Honap <mhonap@nvidia.com>, Jiandi An <jan@nvidia.com>,
Richard Cheng <icheng@nvidia.com>,
linux-tegra@vger.kernel.org,
Alejandro Lucero Palau <alejandro.lucero-palau@amd.com>,
Srirangan Madhavan <smadhavan@nvidia.com>
Subject: [PATCH v18 00/19] PCI/CXL: Add CXL reset support for Type 2 devices
Date: Sat, 5 Dec 2026 04:14:34 +0000 [thread overview]
Message-ID: <20261205041453.3946529-1-smadhavan@nvidia.com> (raw)
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@nvidia.com/
[2] https://lore.kernel.org/linux-cxl/20261029145703.2185231-1-smadhavan@nvidia.com/
[3] https://lore.kernel.org/linux-cxl/20261011021422.3428136-1-smadhavan@nvidia.com/
[4] https://lore.kernel.org/linux-arm-kernel/20261021224557.1827361-1-smadhavan@nvidia.com/
[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@intel.com/
[7] https://lore.kernel.org/linux-cxl/avyOoQjiD7Uh_3rE@aschofie-mobl2.lan/
[8] https://lore.kernel.org/linux-cxl/avyPsvwV1_lc9va5@aschofie-mobl2.lan/
[9] https://lore.kernel.org/linux-cxl/f5fdc266-aed3-47e6-a10f-e8188b58c93f@amd.com/
[10] https://sashiko.dev/#/patchset/20261105185917.2667656-1-smadhavan@nvidia.com
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
next reply other threads:[~2026-12-05 4:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 4:14 Srirangan Madhavan [this message]
2026-12-05 4:14 ` [PATCH v18 01/19] cxl: Clarify decoder interleave limit Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 02/19] cxl: Share CXL port upstream PCI device lookup Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 03/19] cxl: Move decoder declarations to shared header Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 04/19] cxl: Embed decoder configuration in a standalone structure Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 05/19] cxl: Introduce endpoint HDM decoder settings Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 06/19] cxl: Move HDM decoder helpers to built-in code Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 07/19] cxl: Share HDM decoder register unpacking Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 08/19] cxl: Move cxl_rwsem into built-in code Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 09/19] cxl: Refresh cached PCI HDM decoder settings Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 10/19] cxl: Build register block helpers into the kernel Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 11/19] PCI/CXL: Cache endpoint HDM state during PCI enumeration Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 12/19] PCI/CXL: Add CXL Device Reset sequencing Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 13/19] cxl: Validate and synchronize HDM ranges around reset Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 14/19] PCI/CXL: Reject reset with unsafe function scope Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 15/19] PCI/CXL: Restore CXL state after PCI reset Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 16/19] PCI/CXL: Expose CXL Reset as a PCI reset method Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 17/19] PCI/CXL: Restore CXL state after CXL bus reset Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 18/19] PCI/CXL: Flush host and device caches for " Srirangan Madhavan
2026-12-05 4:14 ` [PATCH v18 19/19] cxl: Add KUnit checks for HDM decoder unpacking Srirangan Madhavan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205041453.3946529-1-smadhavan@nvidia.com \
--to=smadhavan@nvidia.com \
--cc=alejandro.lucero-palau@amd.com \
--cc=alex.williamson@redhat.com \
--cc=alison.schofield@intel.com \
--cc=alwilliamson@nvidia.com \
--cc=bhelgaas@google.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=icheng@nvidia.com \
--cc=iweiny@kernel.org \
--cc=jan@nvidia.com \
--cc=jic23@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=machaujo@amazon.de \
--cc=mhonap@nvidia.com \
--cc=ming.li@zohomail.com \
--cc=skancherla@nvidia.com \
--cc=vaslot@nvidia.com \
--cc=vishal.l.verma@intel.com \
--cc=vsethi@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox