From: Dan Williams <dan.j.williams@intel.com>
To: <shiju.jose@huawei.com>, <linux-cxl@vger.kernel.org>,
<dan.j.williams@intel.com>, <dave@stgolabs.net>,
<jonathan.cameron@huawei.com>, <dave.jiang@intel.com>,
<alison.schofield@intel.com>, <vishal.l.verma@intel.com>,
<ira.weiny@intel.com>, <david@redhat.com>,
<Vilas.Sridharan@amd.com>
Cc: <linux-edac@vger.kernel.org>, <linux-acpi@vger.kernel.org>,
<linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
<bp@alien8.de>, <tony.luck@intel.com>, <rafael@kernel.org>,
<lenb@kernel.org>, <mchehab@kernel.org>, <leo.duran@amd.com>,
<Yazen.Ghannam@amd.com>, <rientjes@google.com>,
<jiaqiyan@google.com>, <Jon.Grimm@amd.com>,
<dave.hansen@linux.intel.com>, <naoya.horiguchi@nec.com>,
<james.morse@arm.com>, <jthoughton@google.com>,
<somasundaram.a@hpe.com>, <erdemaktas@google.com>,
<pgonda@google.com>, <duenwen@google.com>, <gthelen@google.com>,
<wschwartz@amperecomputing.com>, <dferguson@amperecomputing.com>,
<wbs@os.amperecomputing.com>, <nifan.cxl@gmail.com>,
<tanxiaofei@huawei.com>, <prime.zeng@hisilicon.com>,
<roberto.sassu@huawei.com>, <kangkang.shen@futurewei.com>,
<wanghuiqiang@huawei.com>, <linuxarm@huawei.com>,
<shiju.jose@huawei.com>
Subject: Re: [PATCH v2 6/8] cxl: Support for finding memory operation attributes from the current boot
Date: Thu, 27 Mar 2025 13:43:58 -0400 [thread overview]
Message-ID: <67e58e5eda9d8_13cb294a4@dwillia2-mobl3.amr.corp.intel.com.notmuch> (raw)
In-Reply-To: <20250320180450.539-7-shiju.jose@huawei.com>
shiju.jose@ wrote:
> From: Shiju Jose <shiju.jose@huawei.com>
>
> Certain operations on memory, such as memory repair, are permitted
> only when the address and other attributes for the operation are
> from the current boot. This is determined by checking whether the
> memory attributes for the operation match those in the CXL gen_media
> or CXL DRAM memory event records reported during the current boot.
>
> The CXL event records must be backed up because they are cleared
> in the hardware after being processed by the kernel.
>
> Support is added for storing CXL gen_media or CXL DRAM memory event
> records in xarrays. Additionally, helper functions are implemented
> to find a matching record in the xarray storage based on the memory
> attributes and repair type.
>
> Add validity check, when matching attributes for sparing, using
> the validity flag in the DRAM event record, to ensure that all
> required attributes for a requested repair operation are valid and
> set.
>
> Co-developed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
> ---
> drivers/cxl/core/mbox.c | 11 ++-
> drivers/cxl/core/memdev.c | 9 +++
> drivers/cxl/core/ras.c | 145 ++++++++++++++++++++++++++++++++++++++
I thought we agreed to call the file edac.c since "ras" concepts are
spread throughout the driver?
> drivers/cxl/cxlmem.h | 46 ++++++++++++
> drivers/cxl/pci.c | 3 +
> 5 files changed, 212 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
> index 19d46a284650..c9328f1b6464 100644
> --- a/drivers/cxl/core/mbox.c
> +++ b/drivers/cxl/core/mbox.c
> @@ -956,12 +956,19 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
> hpa_alias = hpa - cache_size;
> }
>
> - if (event_type == CXL_CPER_EVENT_GEN_MEDIA)
> + if (event_type == CXL_CPER_EVENT_GEN_MEDIA) {
> + if (cxl_store_rec_gen_media((struct cxl_memdev *)cxlmd, evt))
> + dev_dbg(&cxlmd->dev, "CXL store rec_gen_media failed\n");
> +
All of this should be turned off when there is no EDAC consumer.
I don't see anything that triggers releasing the cache when a repair
makes continuing to save the information irrelevant.
I don't see any safety with respect to error storms and burning
unlimited memory in this cache.
The cache is storing 100% of the event record which seems wasteful if
100% of the data is not needed for validating repair operations.
The memory overhead expense of this feature needs to be estimated and
documented in the Kconfig so that distros can make a reasonable decision
about turning this on.
> trace_cxl_general_media(cxlmd, type, cxlr, hpa,
> hpa_alias, &evt->gen_media);
> - else if (event_type == CXL_CPER_EVENT_DRAM)
> + } else if (event_type == CXL_CPER_EVENT_DRAM) {
> + if (cxl_store_rec_dram((struct cxl_memdev *)cxlmd, evt))
> + dev_dbg(&cxlmd->dev, "CXL store rec_dram failed\n");
> +
> trace_cxl_dram(cxlmd, type, cxlr, hpa, hpa_alias,
> &evt->dram);
> + }
> }
> }
> EXPORT_SYMBOL_NS_GPL(cxl_event_trace_record, "CXL");
> diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> index a16a5886d40a..bd9ba50bc01e 100644
> --- a/drivers/cxl/core/memdev.c
> +++ b/drivers/cxl/core/memdev.c
> @@ -25,8 +25,17 @@ static DEFINE_IDA(cxl_memdev_ida);
> static void cxl_memdev_release(struct device *dev)
> {
> struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
> + struct cxl_event_gen_media *rec_gen_media;
> + struct cxl_event_dram *rec_dram;
> + unsigned long index;
>
> ida_free(&cxl_memdev_ida, cxlmd->id);
> + xa_for_each(&cxlmd->rec_dram, index, rec_dram)
> + kfree(rec_dram);
> + xa_destroy(&cxlmd->rec_dram);
> + xa_for_each(&cxlmd->rec_gen_media, index, rec_gen_media)
> + kfree(rec_gen_media);
> + xa_destroy(&cxlmd->rec_gen_media);
> kfree(cxlmd);
> }
>
> diff --git a/drivers/cxl/core/ras.c b/drivers/cxl/core/ras.c
> index 485a831695c7..c703d4e7e05b 100644
> --- a/drivers/cxl/core/ras.c
> +++ b/drivers/cxl/core/ras.c
> @@ -7,6 +7,151 @@
> #include <cxlmem.h>
> #include "trace.h"
>
> +struct cxl_event_gen_media *
> +cxl_find_rec_gen_media(struct cxl_memdev *cxlmd,
> + struct cxl_mem_repair_attrbs *attrbs)
> +{
> + struct cxl_event_gen_media *rec;
> +
> + rec = xa_load(&cxlmd->rec_gen_media, attrbs->dpa);
> + if (!rec)
> + return NULL;
> +
> + if (attrbs->repair_type == CXL_PPR)
> + return rec;
> +
> + return NULL;
> +}
> +EXPORT_SYMBOL_NS_GPL(cxl_find_rec_gen_media, "CXL");
> +
> +struct cxl_event_dram *cxl_find_rec_dram(struct cxl_memdev *cxlmd,
> + struct cxl_mem_repair_attrbs *attrbs)
> +{
> + struct cxl_event_dram *rec;
> + u16 validity_flags;
> +
> + rec = xa_load(&cxlmd->rec_dram, attrbs->dpa);
> + if (!rec)
> + return NULL;
> +
> + validity_flags = get_unaligned_le16(rec->media_hdr.validity_flags);
> + if (!(validity_flags & CXL_DER_VALID_CHANNEL) ||
> + !(validity_flags & CXL_DER_VALID_RANK))
> + return NULL;
> +
> + switch (attrbs->repair_type) {
> + case CXL_PPR:
> + if (!(validity_flags & CXL_DER_VALID_NIBBLE) ||
> + get_unaligned_le24(rec->nibble_mask) == attrbs->nibble_mask)
> + return rec;
> + break;
> + case CXL_CACHELINE_SPARING:
> + if (!(validity_flags & CXL_DER_VALID_BANK_GROUP) ||
> + !(validity_flags & CXL_DER_VALID_BANK) ||
> + !(validity_flags & CXL_DER_VALID_ROW) ||
> + !(validity_flags & CXL_DER_VALID_COLUMN))
> + return NULL;
> +
> + if (rec->media_hdr.channel == attrbs->channel &&
> + rec->media_hdr.rank == attrbs->rank &&
> + rec->bank_group == attrbs->bank_group &&
> + rec->bank == attrbs->bank &&
> + get_unaligned_le24(rec->row) == attrbs->row &&
> + get_unaligned_le16(rec->column) == attrbs->column &&
> + (!(validity_flags & CXL_DER_VALID_NIBBLE) ||
> + get_unaligned_le24(rec->nibble_mask) ==
> + attrbs->nibble_mask) &&
> + (!(validity_flags & CXL_DER_VALID_SUB_CHANNEL) ||
> + rec->sub_channel == attrbs->sub_channel))
> + return rec;
> + break;
> + case CXL_ROW_SPARING:
> + if (!(validity_flags & CXL_DER_VALID_BANK_GROUP) ||
> + !(validity_flags & CXL_DER_VALID_BANK) ||
> + !(validity_flags & CXL_DER_VALID_ROW))
> + return NULL;
> +
> + if (rec->media_hdr.channel == attrbs->channel &&
> + rec->media_hdr.rank == attrbs->rank &&
> + rec->bank_group == attrbs->bank_group &&
> + rec->bank == attrbs->bank &&
> + get_unaligned_le24(rec->row) == attrbs->row &&
> + (!(validity_flags & CXL_DER_VALID_NIBBLE) ||
> + get_unaligned_le24(rec->nibble_mask) ==
> + attrbs->nibble_mask))
> + return rec;
> + break;
> + case CXL_BANK_SPARING:
> + if (!(validity_flags & CXL_DER_VALID_BANK_GROUP) ||
> + !(validity_flags & CXL_DER_VALID_BANK))
> + return NULL;
> +
> + if (rec->media_hdr.channel == attrbs->channel &&
> + rec->media_hdr.rank == attrbs->rank &&
> + rec->bank_group == attrbs->bank_group &&
> + rec->bank == attrbs->bank &&
> + (!(validity_flags & CXL_DER_VALID_NIBBLE) ||
> + get_unaligned_le24(rec->nibble_mask) ==
> + attrbs->nibble_mask))
> + return rec;
> + break;
> + case CXL_RANK_SPARING:
> + if (rec->media_hdr.channel == attrbs->channel &&
> + rec->media_hdr.rank == attrbs->rank &&
> + (!(validity_flags & CXL_DER_VALID_NIBBLE) ||
> + get_unaligned_le24(rec->nibble_mask) ==
> + attrbs->nibble_mask))
> + return rec;
> + break;
> + default:
> + return NULL;
> + }
> +
> + return NULL;
> +}
> +EXPORT_SYMBOL_NS_GPL(cxl_find_rec_dram, "CXL");
> +
> +int cxl_store_rec_gen_media(struct cxl_memdev *cxlmd, union cxl_event *evt)
> +{
> + void *old_rec;
> + struct cxl_event_gen_media *rec =
> + kmemdup(&evt->gen_media, sizeof(*rec), GFP_KERNEL);
> + if (!rec)
> + return -ENOMEM;
> +
> + old_rec = xa_store(&cxlmd->rec_gen_media,
> + le64_to_cpu(rec->media_hdr.phys_addr), rec,
> + GFP_KERNEL);
> + if (xa_is_err(old_rec))
> + return xa_err(old_rec);
> +
> + kfree(old_rec);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_NS_GPL(cxl_store_rec_gen_media, "CXL");
> +
> +int cxl_store_rec_dram(struct cxl_memdev *cxlmd, union cxl_event *evt)
> +{
> + void *old_rec;
> + struct cxl_event_dram *rec =
> + kmemdup(&evt->dram, sizeof(*rec), GFP_KERNEL);
> +
> + if (!rec)
> + return -ENOMEM;
> +
> + old_rec = xa_store(&cxlmd->rec_dram,
> + le64_to_cpu(rec->media_hdr.phys_addr), rec,
> + GFP_KERNEL);
> + if (xa_is_err(old_rec))
> + return xa_err(old_rec);
> +
> + kfree(old_rec);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_NS_GPL(cxl_store_rec_dram, "CXL");
> +
> static void cxl_cper_trace_corr_port_prot_err(struct pci_dev *pdev,
> struct cxl_ras_capability_regs ras_cap)
> {
> diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
> index 7ab257e0c85e..24ece579a145 100644
> --- a/drivers/cxl/cxlmem.h
> +++ b/drivers/cxl/cxlmem.h
> @@ -34,6 +34,41 @@
> (FIELD_GET(CXLMDEV_RESET_NEEDED_MASK, status) != \
> CXLMDEV_RESET_NEEDED_NOT)
>
> +enum cxl_mem_repair_type {
> + CXL_PPR,
> + CXL_CACHELINE_SPARING,
> + CXL_ROW_SPARING,
> + CXL_BANK_SPARING,
> + CXL_RANK_SPARING,
> + CXL_REPAIR_MAX,
> +};
> +
> +/**
> + * struct cxl_mem_repair_attrbs - CXL memory repair attributes
Between attr, param, attrbs the names of intermediate objects seem to
have no rhyme or reason in these patches. I don't have a specific
suggestion here beyond please take another pass over the whole set and
be consistent.
In general attr is an overloaded term especially in code files that have
sysfs attributes, so please steer away from "attr" for that reason.
> + * @dpa: DPA of memory to repair
> + * @nibble_mask: nibble mask, identifies one or more nibbles on the memory bus
> + * @row: row of memory to repair
> + * @column: column of memory to repair
> + * @channel: channel of memory to repair
> + * @sub_channel: sub channel of memory to repair
> + * @rank: rank of memory to repair
> + * @bank_group: bank group of memory to repair
> + * @bank: bank of memory to repair
> + * @repair_type: repair type. For eg. PPR, memory sparing etc.
> + */
> +struct cxl_mem_repair_attrbs {
> + u64 dpa;
> + u32 nibble_mask;
> + u32 row;
> + u16 column;
> + u8 channel;
> + u8 sub_channel;
> + u8 rank;
> + u8 bank_group;
> + u8 bank;
> + enum cxl_mem_repair_type repair_type;
> +};
> +
> /**
> * struct cxl_memdev - CXL bus object representing a Type-3 Memory Device
> * @dev: driver core device object
> @@ -45,6 +80,8 @@
> * @endpoint: connection to the CXL port topology for this memory device
> * @id: id number of this memdev instance.
> * @depth: endpoint port depth
> + * @rec_gen_media: xarray to store CXL general media records
> + * @rec_dram: xarray to store CXL DRAM records
> */
> struct cxl_memdev {
> struct device dev;
> @@ -56,6 +93,8 @@ struct cxl_memdev {
> struct cxl_port *endpoint;
> int id;
> int depth;
> + struct xarray rec_gen_media;
> + struct xarray rec_dram;
Can this move to an EDAC context object to not burden 'struct
cxl_memdev' by default?
next prev parent reply other threads:[~2025-03-27 17:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-20 18:04 [PATCH v2 0/8] cxl: support CXL memory RAS features shiju.jose
2025-03-20 18:04 ` [PATCH v2 1/8] cxl: Add helper function to retrieve a feature entry shiju.jose
2025-03-26 21:32 ` Dan Williams
2025-03-27 16:59 ` Shiju Jose
2025-03-31 23:35 ` Dan Williams
2025-03-20 18:04 ` [PATCH v2 2/8] EDAC: Update documentation for the CXL memory patrol scrub control feature shiju.jose
2025-03-21 10:03 ` Jonathan Cameron
2025-03-24 10:37 ` Shiju Jose
2025-03-26 21:46 ` Dan Williams
2025-03-20 18:04 ` [PATCH v2 3/8] cxl/edac: Add CXL memory device " shiju.jose
2025-03-27 1:47 ` Dan Williams
2025-03-28 10:18 ` Shiju Jose
2025-03-20 18:04 ` [PATCH v2 4/8] cxl/edac: Add CXL memory device ECS " shiju.jose
2025-03-27 17:12 ` Dan Williams
2025-03-20 18:04 ` [PATCH v2 5/8] cxl/mbox: Add support for PERFORM_MAINTENANCE mailbox command shiju.jose
2025-03-27 17:23 ` Dan Williams
2025-03-20 18:04 ` [PATCH v2 6/8] cxl: Support for finding memory operation attributes from the current boot shiju.jose
2025-03-27 17:43 ` Dan Williams [this message]
2025-03-20 18:04 ` [PATCH v2 7/8] cxl/memfeature: Add CXL memory device soft PPR control feature shiju.jose
2025-03-27 17:01 ` Borislav Petkov
2025-03-27 17:08 ` Borislav Petkov
2025-03-28 13:05 ` Shiju Jose
2025-03-20 18:04 ` [PATCH v2 8/8] cxl/memfeature: Add CXL memory device memory sparing " shiju.jose
2025-03-21 7:39 ` [PATCH v2 0/8] cxl: support CXL memory RAS features Christophe Leroy
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=67e58e5eda9d8_13cb294a4@dwillia2-mobl3.amr.corp.intel.com.notmuch \
--to=dan.j.williams@intel.com \
--cc=Jon.Grimm@amd.com \
--cc=Vilas.Sridharan@amd.com \
--cc=Yazen.Ghannam@amd.com \
--cc=alison.schofield@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=david@redhat.com \
--cc=dferguson@amperecomputing.com \
--cc=duenwen@google.com \
--cc=erdemaktas@google.com \
--cc=gthelen@google.com \
--cc=ira.weiny@intel.com \
--cc=james.morse@arm.com \
--cc=jiaqiyan@google.com \
--cc=jonathan.cameron@huawei.com \
--cc=jthoughton@google.com \
--cc=kangkang.shen@futurewei.com \
--cc=lenb@kernel.org \
--cc=leo.duran@amd.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxarm@huawei.com \
--cc=mchehab@kernel.org \
--cc=naoya.horiguchi@nec.com \
--cc=nifan.cxl@gmail.com \
--cc=pgonda@google.com \
--cc=prime.zeng@hisilicon.com \
--cc=rafael@kernel.org \
--cc=rientjes@google.com \
--cc=roberto.sassu@huawei.com \
--cc=shiju.jose@huawei.com \
--cc=somasundaram.a@hpe.com \
--cc=tanxiaofei@huawei.com \
--cc=tony.luck@intel.com \
--cc=vishal.l.verma@intel.com \
--cc=wanghuiqiang@huawei.com \
--cc=wbs@os.amperecomputing.com \
--cc=wschwartz@amperecomputing.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