From: Jonathan Cameron <jic23@kernel.org>
To: Jongwon Lee <ai@linux.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
Dave Jiang <dave.jiang@intel.com>,
Alison Schofield <alison.schofield@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Dan Williams <djbw@kernel.org>, Ira Weiny <iweiny@kernel.org>,
Li Ming <ming.li@zohomail.com>, Richard Cheng <icheng@nvidia.com>,
linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 1/3] cxl/edac: Read cached DRAM event records under the xarray lock
Date: Tue, 17 Nov 2026 01:35:21 +0000 [thread overview]
Message-ID: <20261117013521.5b4d034a@jic23-hlaptop> (raw)
In-Reply-To: <20261108022022.3352-2-ai@linux.com>
On Sun, 08 Nov 2026 11:20:23 +0900
Jongwon Lee <ai@linux.com> wrote:
> The event path caches DRAM event records in an xarray. It frees a record
> when xa_store() replaces it, when the record expires, and when the cache
> overflows. The event path runs with device_lock() and cxl_rwsem held for
> read.
>
> The repair path looks up records with cxl_find_rec_dram() while holding
> only cxl_rwsem for read, so both paths can run at the same time.
> cxl_find_rec_dram() reads the record after xa_load() returns, and
> cxl_mem_perform_sparing() reads validity_flags from the returned record
> again later. Both reads can hit a record that the event path has just
> freed.
>
> Move the lookup into __cxl_find_rec_dram(), which is called with the
> xarray lock held. cxl_find_rec_dram() now returns whether a record
> matched, and copies the matching record into a buffer passed in by the
> caller. The PPR path only needs to know whether there is a match, so it
> passes NULL. No caller keeps a pointer to the record after the lock is
> dropped. The event path frees a record only after xa_store() or
> xa_erase() has removed it from the xarray, and both of them take the
> same lock.
>
> Fixes: 0b5ccb0de1e2 ("cxl/edac: Support for finding memory operation attributes from the current boot")
> Fixes: 588ca944c277 ("cxl/edac: Add CXL memory device memory sparing control feature")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://lore.kernel.org/r/sashiko-outbox-192042@kernel.org
> Reviewed-by: Richard Cheng <icheng@nvidia.com>
> Reviewed-by: Li Ming <ming.li@zohomail.com>
> Signed-off-by: Jongwon Lee <ai@linux.com>
This seems fine to me, but a suggestion inline that might make the code cleaner.
Reviewed-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
> ---
> drivers/cxl/core/edac.c | 70 +++++++++++++++++++++++++++--------------
> 1 file changed, 47 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/cxl/core/edac.c b/drivers/cxl/core/edac.c
> index 34b81e8dfb..4624ab4644 100644
> --- a/drivers/cxl/core/edac.c
> +++ b/drivers/cxl/core/edac.c
> @@ -1029,6 +1028,30 @@ cxl_find_rec_dram(struct cxl_memdev *cxlmd,
> return NULL;
> }
>
> +/*
> + * cxl_store_rec_dram() replaces and frees records while the repair path only
> + * holds cxl_rwsem for read, so look the record up and read it under the
> + * xarray lock, and hand back a copy of the record.
> + */
> +static bool cxl_find_rec_dram(struct cxl_memdev *cxlmd,
> + struct cxl_mem_repair_attrbs *attrbs,
> + struct cxl_event_dram *out)
> +{
> + struct cxl_mem_err_rec *array_rec = cxlmd->err_rec_array;
> + struct cxl_event_dram *rec;
> +
> + if (!array_rec)
> + return false;
> +
> + xa_lock(&array_rec->rec_dram);
> + rec = __cxl_find_rec_dram(&array_rec->rec_dram, attrbs);
> + if (rec && out)
> + *out = *rec;
> + xa_unlock(&array_rec->rec_dram);
As I just sent to next patch. It would be nice to have a guard()
for these. Maybe it is worth including as part of this.
> +
> + return rec;
> +}
next prev parent reply other threads:[~2026-11-17 1:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 2:20 [PATCH v5 0/3] cxl/edac: Fix event record lookups for memory repair Jongwon Lee
2026-11-08 2:20 ` [PATCH v5 1/3] cxl/edac: Read cached DRAM event records under the xarray lock Jongwon Lee
2026-11-17 1:35 ` Jonathan Cameron [this message]
2026-11-08 2:20 ` [PATCH v5 2/3] cxl/edac: Skip event records marked NOT_REPAIRABLE Jongwon Lee
2026-11-10 12:53 ` Li Ming
2026-11-17 1:30 ` Jonathan Cameron
2026-11-08 2:20 ` [PATCH v5 3/3] cxl/edac: Mask DPA flags in the event record cache key Jongwon Lee
2026-11-10 12:54 ` Li Ming
2026-11-17 1:39 ` Jonathan Cameron
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=20261117013521.5b4d034a@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=ai@linux.com \
--cc=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=djbw@kernel.org \
--cc=icheng@nvidia.com \
--cc=iweiny@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.li@zohomail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®