Linux CXL
 help / color / mirror / Atom feed
* [PATCH v6 0/3] cxl/edac: Fix event record lookups for memory repair
@ 2026-11-26  2:35 Jongwon Lee
  2026-11-26  2:35 ` [PATCH v6 1/3] cxl/edac: Read cached DRAM event records under the xarray lock Jongwon Lee
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jongwon Lee @ 2026-11-26  2:35 UTC (permalink / raw)
  To: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
	Vishal Verma
  Cc: Dan Williams, Ira Weiny, Li Ming, Richard Cheng, Ben Cheatham,
	Michal Schmidt, linux-cxl, linux-kernel

This series fixes the cached event record lookups in the CXL memory
repair path.

Patch 1 fixes a use-after-free that Sashiko reported on v2 [1]. The
repair path reads cached DRAM records without a lock, and the event
path can free them at the same time. The DRAM lookup now runs under
the xarray lock, and the sparing path works on a copy of the record.

Patch 2 makes both lookups skip records that the device marked
NOT_REPAIRABLE.

Patch 3 masks the DPA flag bits in the cache key, and depends on
patch 2. With the masked key alone, the trace event DPA would also
match NOT_REPAIRABLE records and let them be repaired.

I used xa_lock() for the race. kfree_rcu() would need a wrapper with
an rcu_head around the record structs from the spec. Taking
device_lock() in the repair path could deadlock with unbind, which
removes the EDAC sysfs files while holding device_lock().

Changes in v6:
- Rebase on cxl/next (32af7819352b), no conflicts
- Patch 2: rename cxl_find_rec_gen_media() to
  cxl_check_for_rec_gen_media() and split the two tests (Jonathan)
- Patch 2: changelog wording for the online repair case (Alison)
- Patch 2: drop the Fixes: tag (Jonathan). Patch 3 keeps its Fixes:
  tag, so a backport of patch 3 needs patch 2.
- Add the Reviewed-by tags from v5
- Cc Michal Schmidt for guard(xa_lock), as Jonathan suggested, and
  Ben Cheatham as a CXL reviewer

There is no guard(xa_lock) in the tree, and the 2024 patch for it [2]
was not merged. v6 keeps xa_lock()/xa_unlock(), and I can convert
these sites in a follow-up once a guard exists.

Changes in v5:
- New patch 2: NOT_REPAIRABLE check split out of v4 patch 2 and moved
  before the masking patch (Li Ming)
- Patch 3: rename cxl_rec_key() to cxl_rec_dpa() (Li Ming)
- Patch 1: drop the found variable in cxl_find_rec_dram() (Li Ming)
- Richard's Reviewed-by on v4 2/2 not carried over, as it was split
- Rebase on cxl/next (e44dc3a303)

Changes in v4:
- Patch 1: copy the whole struct cxl_event_dram out instead of only
  validity_flags (Richard Cheng)
- Patch 2: make cxl_rec_key() and cxl_rec_not_repairable() static
  inline (Richard Cheng)
- Cover letter: describe patch 1 first (Richard Cheng)

Changes in v3:
- New patch 1 for the record lifetime race (Sashiko)
- Patch 2: General Media lookup under the xarray lock, returns bool

Changes in v2:
- Moved the Claude Code note below the --- (Dave Jiang)

v5: https://lore.kernel.org/r/20261108022022.3352-1-ai@linux.com
v4: https://lore.kernel.org/r/20261102123233.74598-1-ai@linux.com
v3: https://lore.kernel.org/r/20261101013418.87326-1-ai@linux.com
v2: https://lore.kernel.org/r/20261031161121.15948-1-ai@linux.com
v1: https://lore.kernel.org/r/20261030072721.31970-1-ai@linux.com

Tested in QEMU (master b574eaf) with a CXL type 3 device and a
committed region, on cxl/next 32af7819352b, with KASAN, lockdep,
kmemleak and preempt=full. Not tested on real CXL hardware.

- Repair requests for eight DPAs on all five mem_repair devices. With
  the series, 0x1000 and 0x2000 succeed, 0x5000 succeeds for PPR only,
  and NOT_REPAIRABLE (0x3000, 0x6000), missing (0x7000) and unmasked
  (0x1001, 0x3002) DPAs get -EINVAL. Unpatched, 0x1000 and PPR at
  0x5000 fail, and 0x1001 and 0x3002 are accepted.
- Race test: event injection from the host, four guest repair loops,
  and a test-only mdelay(20) after the lookups. Unpatched, KASAN
  reports a slab-use-after-free in cxl_find_rec_dram() within seconds.
  With the series: 600 s, 10,950 repairs, 274,946 events, no report.
  Without the delay, on the previous base (2101c39473a0) with the same
  code: 1,800 s, 98,220 repairs, 1,155,590 events, no report.
- Unbind test: cxl_mem unbound and rebound in a loop during repairs
  and event injection. 600 s, 78 cycles, 7,260 repairs, no report.
- kmemleak finds nothing after each run.
- edac.o builds with W=1 after each patch, sparse, clang W=1 (x86_64,
  arm64) and CONFIG_CXL_EDAC_MEM_REPAIR=n with no new warnings. The
  series also applies to cxl/fixes and v7.4-rc4.

This series was developed with Claude Code.

Thanks to Richard, Li Ming, Jonathan and Alison for the reviews.

[1] https://lore.kernel.org/r/sashiko-outbox-192042@kernel.org
[2] https://lore.kernel.org/all/20240228135352.14444-1-mschmidt@redhat.com/

Jongwon Lee (3):
  cxl/edac: Read cached DRAM event records under the xarray lock
  cxl/edac: Skip event records marked NOT_REPAIRABLE
  cxl/edac: Mask DPA flags in the event record cache key

 drivers/cxl/core/edac.c | 116 ++++++++++++++++++++++++++--------------
 1 file changed, 77 insertions(+), 39 deletions(-)


base-commit: 32af7819352bae9c690ebe277a44eceb501d5c68
-- 
2.55.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-26  2:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  2:35 [PATCH v6 0/3] cxl/edac: Fix event record lookups for memory repair Jongwon Lee
2026-11-26  2:35 ` [PATCH v6 1/3] cxl/edac: Read cached DRAM event records under the xarray lock Jongwon Lee
2026-11-26  2:35 ` [PATCH v6 2/3] cxl/edac: Skip event records marked NOT_REPAIRABLE Jongwon Lee
2026-11-26  2:35 ` [PATCH v6 3/3] cxl/edac: Mask DPA flags in the event record cache key Jongwon Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox