All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jongwon Lee <ai@linux.com>
To: Davidlohr Bueso <dave@stgolabs.net>,
	Jonathan Cameron <jic23@kernel.org>,
	Dave Jiang <dave.jiang@intel.com>,
	Alison Schofield <alison.schofield@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>
Cc: Dan Williams <djbw@kernel.org>, Ira Weiny <iweiny@kernel.org>,
	Li Ming <ming.li@zohomail.com>, Richard Cheng <icheng@nvidia.com>,
	Ben Cheatham <benjamin.cheatham@amd.com>,
	Michal Schmidt <mschmidt@redhat.com>,
	linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v6 0/3] cxl/edac: Fix event record lookups for memory repair
Date: Thu, 26 Nov 2026 11:35:20 +0900	[thread overview]
Message-ID: <20261126023520.39368-1-ai@linux.com> (raw)

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


             reply	other threads:[~2026-11-26  2:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  2:35 Jongwon Lee [this message]
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
2026-11-30 20:50 ` [PATCH v6 0/3] cxl/edac: Fix event record lookups for memory repair Dave Jiang

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=20261126023520.39368-1-ai@linux.com \
    --to=ai@linux.com \
    --cc=alison.schofield@intel.com \
    --cc=benjamin.cheatham@amd.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=djbw@kernel.org \
    --cc=icheng@nvidia.com \
    --cc=iweiny@kernel.org \
    --cc=jic23@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.li@zohomail.com \
    --cc=mschmidt@redhat.com \
    --cc=vishal.l.verma@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.