Re: [PATCH v17 13/19] cxl: Validate and synchronize HDM ranges around reset

From: Srirangan Madhavan

Date: Fri Nov 20 2026 - 03:20:52 EST


On 11/17/26 9:32 AM, Alison Schofield wrote:
Refuse reset unless enabled system-physical HDM ranges can be reserved
exclusively and CPU-cache invalidation is available. Invalidate before
reset and again before ending IOMMU exclusion, holding range reservations
until the second invalidation completes. A later patch places state
restoration before the second invalidation.

Userspace is expected to offline CXL.mem users before reset. The
reservation enforces this for claimed ranges: the reset fails while a
conflicting resource is claimed, and no one can claim the range during
the reset. It cannot see accesses by code that uses the range without
claiming it, which the offline expectation also covers.

Reject normalized-addressing decoders because their cached ranges are not
system physical addresses. Record Normalized Addressing in the cache when
region discovery sets it, since the cache is filled earlier. A reset that
takes its snapshot between endpoint probe and that update can still
miss it.
What prevents reset during this window? If the snapshot misses the
normalized-addressing flag can a reset proceed and use a range that is
not a system physical address?

Does this mean we need to prevent reset until discovery has resolved
the address interpretation, or is there another check that makes
reset safe before then?

On this first part: nothing prevents it in v17. For v18 I'd reject a range
that isn't inside a platform CXL window, on top of the existing flag
check.
Ignore zero-size decoders because they map no address range. Refuse reset
when the device decodes memory through its DVSEC ranges instead of HDM
decoders, since the cache holds no range to reserve for that memory.

Hold the global cxl_rwsem.region write lock across snapshot, reset and
restoration to keep the decoder state and reserved ranges stable. This also
blocks region and decoder sysfs, region probe, poison operations, sanitize
and region-aware event tracing across CXL devices. The Memory Clear wait
lasts up to the timeout the device advertises, at most 100 seconds; cache
flushes and other reset work extend the hold.
Similar to questions on previous versions and in cover letter -

Can a reset acquire this lock while other CXL devices are still being
discovered and their regions assembled, and block that work for the
full reset duration?

What limits the disruption to unrelated devices, including repeated
resets? Could the locking be scoped to the affected device or regions
rather than holding the global region lock throughout the wait?

On this part, yes. As posted the lock is held across the whole reset.
For v18 I'm proposing to hold it only briefly to snapshot and restore, and refuse commits of that device's decoders while it resets.

Details are in my reply to the cover letter: https://lore.kernel.org/linux-cxl/20261105185917.2667656-1-smadhavan@xxxxxxxxxx/T/#m82b76ee0215d67d91f67ec6fa72036615f1adb4f

--
Regards,
Srirangan