From: Alison Schofield <alison.schofield@intel.com>
To: Anisa Su <anisa.su887@gmail.com>
Cc: <linux-cxl@vger.kernel.org>, <nvdimm@lists.linux.dev>,
<linux-kernel@vger.kernel.org>, Dave Jiang <dave.jiang@intel.com>,
"Jonathan Cameron" <jic23@kernel.org>,
Davidlohr Bueso <dave@stgolabs.net>,
Ira Weiny <iweiny@kernel.org>,
Vishal Verma <vishal.l.verma@intel.com>,
Fan Ni <nifan.cxl@gmail.com>, Li Ming <ming.li@zohomail.com>,
Benjamin Cheatham <benjamin.cheatham@amd.com>,
Gregory Price <gourry@gourry.net>,
Richard Cheng <icheng@nvidia.com>,
Anisa Su <anisa.su@samsung.com>
Subject: Re: [PATCH v1 04/14] cxl/mem: Introduce DC event handlers
Date: Tue, 24 Nov 2026 11:29:15 -0800 [thread overview]
Message-ID: <awXli-IrNpWrDC0t@aschofie-mobl2.lan> (raw)
In-Reply-To: <20261104230445.66625-5-anisa.su@samsung.com>
On Thu, Nov 05, 2026 at 08:02:28AM +0900, Anisa Su wrote:
> From: Ira Weiny <iweiny@kernel.org>
>
> Add the handling skeleton for DC Add and DC Release events. Per CXL
> r4.0 Section 8.2.10.9.9.3, the host is expected to respond to one or
> more Add Capacity Event Record(s) with an Add Dynamic Capacity Response
> (Opcode 4802h) to acknowledge which extents the host accepts for use.
> Similarly, per CXL r4.0 Section 8.2.10.9.9.4, the host is expected to
> respond to Release Capacity Event Record(s) with a Release Dynamic
> Capacity command (Opcode 4803h), or to issue one that is not
> associated with any event to release capacity on its own.
>
> The records of one operation can be chained by the More flag. Chained
> records are contiguous in the event log and share one event type (CXL
> r4.0 Table 8-229), so a single staging context, mds->dc_chain, holds
> the records of the open chain until the closing record (More=0)
> arrives and the chain is processed and responded to as a whole. A
> record that fails to stage, or one of the other type arriving inside an
> open chain, drops the chain: an add is refused with an empty response,
> a release is left for the device to retry.
>
> This commit refuses all extents from Add Capacity chains and acks all
> Release Capacity chains. Subsequent commits implement accepting and
> releasing extents.
'This commit' and 'Subsequent commits' is awkward and not imperative
mood per submitting-patches.rst. Perhaps:
"Until the host tracks accepted extents, refuse all extents from Add
Capacity chains and acknowledge all Release Capacity chains."
>
> Forced Capacity Release and Region Configuration Updated events are
> logged and ignored.
>
> Based on an original patch by Navneet Singh.
>
> Signed-off-by: Ira Weiny <iweiny@kernel.org>
> Co-developed-by: Anisa Su <anisa.su@samsung.com>
> Signed-off-by: Anisa Su <anisa.su@samsung.com>
> Tested-by: Wonjae Lee <wj28.lee@samsung.com>
> Tested-by: Junhee Park <jh9934.park@samsung.com>
> Tested-by: Heesoo Kim <habil.kim@samsung.com>
> ---
> drivers/cxl/core/mbox.c | 246 ++++++++++++++++++++++++++++++++++++++-
> drivers/cxl/core/trace.h | 3 +-
> drivers/cxl/cxl.h | 9 ++
> drivers/cxl/cxlmem.h | 46 ++++++++
> drivers/cxl/pci.c | 20 +++-
> include/cxl/event.h | 37 ++++++
> 6 files changed, 353 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
> index 13a68f5cef69..3acf5ace48db 100644
> --- a/drivers/cxl/core/mbox.c
> +++ b/drivers/cxl/core/mbox.c
> @@ -5,6 +5,7 @@
> #include <linux/ktime.h>
> #include <linux/mutex.h>
> #include <linux/unaligned.h>
> +#include <linux/list.h>
> #include <cxlpci.h>
> #include <cxlmem.h>
> #include <cxl.h>
> @@ -1100,6 +1101,237 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,
> return rc;
> }
>
> +static int send_one_response(struct cxl_mailbox *cxl_mbox,
> + struct cxl_mbox_dc_response *response,
> + int opcode, u32 extent_list_size, u8 flags)
> +{
> + struct cxl_mbox_cmd mbox_cmd = (struct cxl_mbox_cmd) {
Is that cast needed in the initializer?
snip
> +static int cxl_send_dc_response(struct cxl_memdev_state *mds, int opcode,
> + struct list_head *extent_list, int cnt)
> +{
> + struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox;
> + struct cxl_mbox_dc_response *p;
> + struct cxl_extent_list_node *pos, *tmp;
> + struct cxl_extent *extent;
> + u32 pl_index;
> +
> + size_t pl_size = struct_size(p, extent_list, cnt);
> + u32 max_extents = cnt;
> +
> + /* May have to use more bit on response. */
Huh?
Is this trying to say: "A list larger than the mailbox payload is split
across responses chained with the More flag"
> + if (pl_size > cxl_mbox->payload_size) {
> + max_extents = (cxl_mbox->payload_size - sizeof(*p)) /
> + sizeof(struct updated_extent_list);
> + pl_size = struct_size(p, extent_list, max_extents);
> + }
> +
> + struct cxl_mbox_dc_response *response __free(kfree) =
> + kzalloc(pl_size, GFP_KERNEL);
> + if (!response) {
> + struct cxl_mbox_dc_response empty = { };
> +
> + /* An empty Release DC is invalid (CXL r4.0 Table 8-352) */
> + if (opcode == CXL_MBOX_OP_RELEASE_DC)
> + return -ENOMEM;
> + /* Refuse all extents rather than stall the device. */
> + return send_one_response(cxl_mbox, &empty, opcode, 0, 0);
> + }
Should this fallback report the failure to the caller? When the empty
Add response goes out, the function returns 0, so caller can't tell
that the extents it asked to accept were refused.
Sashiko raised seemingly valid questions here also.
> +
> + /* Set __counted_by to capacity before populating; reset per response. */
> + response->extent_list_size = cpu_to_le32(max_extents);
> +
> + if (cnt == 0)
> + return send_one_response(cxl_mbox, response, opcode, 0, 0);
Should this refuse an empty Release DC, like the -ENOMEM branch above does?
Could the helper count extent_list itself, rather than trust cnt to match
it? A short cnt would let the loop below write past max_extents
> +
> + pl_index = 0;
> + list_for_each_entry_safe(pos, tmp, extent_list, list) {
Nothing is removed from the list inside the loop, so a plain
list_for_each_entry() is OK.
> + extent = pos->extent;
> + response->extent_list[pl_index].dpa_start = extent->start_dpa;
> + response->extent_list[pl_index].length = extent->length;
> + pl_index++;
> +
> + if (pl_index == max_extents) {
> + u8 flags = 0;
> + int rc;
> +
> + if (pl_index < cnt)
> + flags |= CXL_DCD_EVENT_MORE;
> + rc = send_one_response(cxl_mbox, response, opcode,
> + pl_index, flags);
I think another mailbox command can land between the More-chained payloads?
Each send_one_response() goes through cxl_internal_send_cmd(), which takes
the mailbox mutex for that one command only.
Asking because of this in the spec -
For Release Dynamic Capacity, Table 8-352 says "Payloads grouped this way
shall be submitted with no unrelated records between them and shall
contain the same mailbox opcode", and 8.2.10.9.9.3 calls the Add response
payloads "back-to-back". This only matters once the list is longer than
one payload, which is about ten extents with a 256 byte mailbox.
And, that makes me wonder if that was required in other command where
we are chaining multiple payloads. Making a note to take a look!
> + if (rc)
> + return rc;
> + cnt -= pl_index;
> + if (cnt < max_extents)
> + max_extents = cnt;
> + pl_index = 0;
> + }
> + }
> +
> + if (!pl_index) /* nothing more to do */
> + return 0;
"nothing more to do is" leftover narration. Drop that comment.
snip
> +static int handle_dcd_chain_event(struct cxl_memdev_state *mds,
> + struct cxl_event_dcd *event)
> +{
> + struct cxl_dc_event_chain *chain = &mds->dc_chain;
> + struct device *dev = mds->cxlds.dev;
> + int rc;
> +
> + /* Chained records share one event type (CXL r4.0 Table 8-229) */
> + if (list_empty(&chain->pending_extents)) {
> + chain->event_type = event->event_type;
> + } else if (chain->event_type != event->event_type) {
> + dev_warn_ratelimited(dev, "DC %s record inside an open %s chain; dropping the chain\n",
> + cxl_dcd_evt_type_str(event->event_type),
> + cxl_dcd_evt_type_str(chain->event_type));
> + cxl_dc_chain_abort(mds);
> + chain->event_type = event->event_type;
> + }
> +
> + rc = stage_pending_extent(&chain->pending_extents, &event->extent);
> + if (rc) {
> + cxl_dc_chain_abort(mds);
> + return rc;
> + }
Same as Sashiko and Jonathan here. The abort on a record of the other
type above can leave a tail the same way.
snip
> +static void cxl_handle_dcd_event_records(struct cxl_memdev_state *mds,
> + struct cxl_event_record_raw *raw_rec)
> +{
> + struct cxl_event_dcd *event = &raw_rec->event.dcd;
> + struct cxl_extent *extent = &event->extent;
> + struct device *dev = mds->cxlds.dev;
> + uuid_t *id = &raw_rec->id;
> + int rc;
> +
> + if (!uuid_equal(id, &CXL_EVENT_DC_EVENT_UUID))
> + return;
> +
> + dev_dbg(dev, "DCD event %s : DPA:%#llx LEN:%#llx\n",
> + cxl_dcd_evt_type_str(event->event_type),
> + le64_to_cpu(extent->start_dpa), le64_to_cpu(extent->length));
> +
> + switch (event->event_type) {
> + case DCD_ADD_CAPACITY:
> + case DCD_RELEASE_CAPACITY:
> + rc = handle_dcd_chain_event(mds, event);
> + break;
> + case DCD_FORCED_CAPACITY_RELEASE:
> + dev_err_ratelimited(dev, "Forced release event ignored.\n");
> + rc = 0;
> + break;
Same as Jonathan here. Once "cxl/extent: Handle DC Add Capacity events"
tracks extents, the host also keeps tracking a forcibly released one.
Should forced release at least drop the host's tracking of the named
extents?
snip
> @@ -1136,9 +1368,13 @@ static void cxl_mem_get_records_log(struct cxl_memdev_state *mds,
> if (!nr_rec)
> break;
>
> - for (i = 0; i < nr_rec; i++)
> + for (i = 0; i < nr_rec; i++) {
> __cxl_event_trace_record(cxlmd, type,
> &payload->records[i]);
> + if (type == CXL_EVENT_TYPE_DCD)
> + cxl_handle_dcd_event_records(mds,
> + &payload->records[i]);
> + }
>
> if (payload->flags & CXL_GET_EVENT_FLAG_OVERFLOW)
> trace_cxl_overflow(cxlmd, type, payload);
Spec 9.13.3 says "If the Dynamic Capacity Event Log overflows at any point,
the host shall utilize Get Dynamic Capacity Extent List to retrieve the
current list of host accessible DC blocks."
Here the overflow is only traced. Is that OK?
snip
> @@ -1781,6 +2020,11 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial,
> }
>
> mutex_init(&mds->event.log_lock);
> + INIT_LIST_HEAD(&mds->dc_chain.pending_extents);
> +
> + rc = devm_add_action_or_reset(dev, clear_pending_extents, mds);
> + if (rc)
> + return ERR_PTR(rc);
Does unbind leave an open add chain without its response? ie device
doens't get expected response (Table 8-229). Maybe an open add chain
can be refused before teardown instead of just freed.
snip
> diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
> index 35268d1c387c..c88de7cb65d1 100644
> --- a/drivers/cxl/cxlmem.h
> +++ b/drivers/cxl/cxlmem.h
snip
> 0x40, 0x3d, 0x86)
>
> +/*
> + * Add Dynamic Capacity Response
> + * CXL r4.0 Section 8.2.10.9.9.3; Table 8-350 & Table 8-351
> + */
also used for Release Dynamic Capacity, maybe add to above comment
snip
>
> +/*
> + * Dynamic Capacity Event Record
> + * CXL r4.0 section 8.2.10.2.1; Table 8-221
> + */
check that spec reference above
snip
> diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
> index 3ed7c3e70042..29541b8f79f2 100644
> --- a/drivers/cxl/pci.c
> +++ b/drivers/cxl/pci.c
> @@ -510,12 +510,20 @@ static bool cxl_alloc_irq_vectors(struct pci_dev *pdev)
> return true;
> }
>
> -/* Event logs the driver drains: standard logs when native_cxl */
> -static u32 cxl_event_drain_mask(struct pci_host_bridge *host_bridge)
> +/*
> + * Event logs the driver drains: standard logs when native_cxl, DCD when
> + * supported.
> + */
> +static u32 cxl_event_drain_mask(struct pci_host_bridge *host_bridge,
> + struct cxl_memdev_state *mds)
> {
> + u32 mask = 0;
> +
> if (host_bridge->native_cxl_error)
> - return CXLDEV_EVENT_STATUS_STANDARD_LOGS;
> - return 0;
> + mask |= CXLDEV_EVENT_STATUS_STANDARD_LOGS;
> + if (cxl_dcd_supported(mds))
> + mask |= CXLDEV_EVENT_STATUS_DCD;
> + return mask;
> }
Who drains the Dynamic Capacity log once cxl_dcd_dsmas_missing() disables
DCD at endpoint probe? Should the log keep being drained, refusing adds,
or should the DCD interrupt be disarmed when DCD is disabled?
snip to end
-- Alison
next prev parent reply other threads:[~2026-11-24 19:29 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 23:02 [PATCH v1 00/14] DCD CXL Series: Dynamic Capacity extent handling Anisa Su
2026-11-04 23:02 ` [PATCH v1 01/14] cxl/core: Return endpoint decoder information from region search Anisa Su
2026-11-24 18:31 ` Alison Schofield
2026-11-04 23:02 ` [PATCH v1 02/14] cxl/port: Add dynamic capacity options to endpoint decoder mode Anisa Su
2026-11-17 2:22 ` Jonathan Cameron
2026-11-24 18:36 ` Alison Schofield
2026-11-04 23:02 ` [PATCH v1 03/14] cxl/region: Add dynamic DAX region support Anisa Su
2026-11-17 2:32 ` Jonathan Cameron
2026-11-24 18:55 ` Alison Schofield
2026-11-04 23:02 ` [PATCH v1 04/14] cxl/mem: Introduce DC event handlers Anisa Su
2026-11-17 2:54 ` Jonathan Cameron
2026-11-24 19:29 ` Alison Schofield [this message]
2026-11-04 23:02 ` [PATCH v1 05/14] cxl/mem: Add 20 second timeout for stalled DC event chains Anisa Su
2026-11-17 3:00 ` Jonathan Cameron
2026-11-20 20:47 ` Anisa Su
2026-11-24 19:30 ` Alison Schofield
2026-11-04 23:02 ` [PATCH v1 06/14] cxl/extent: Handle DC Add Capacity events Anisa Su
2026-11-12 3:34 ` Richard Cheng
2026-11-16 21:53 ` Anisa Su
2026-11-04 23:02 ` [PATCH v1 07/14] cxl/mem: Drop misaligned DCD extent groups Anisa Su
2026-11-04 23:02 ` [PATCH v1 08/14] cxl/extent: Validate DC extent partition Anisa Su
2026-11-04 23:02 ` [PATCH v1 09/14] cxl/mem: Enforce tag-group semantics Anisa Su
2026-11-04 23:02 ` [PATCH v1 10/14] cxl/extent: Enforce cross-region tag uniqueness Anisa Su
2026-11-04 23:02 ` [PATCH v1 11/14] cxl/extent: Handle DC Release Capacity events Anisa Su
2026-11-12 7:34 ` Richard Cheng
2026-11-04 23:02 ` [PATCH v1 12/14] cxl/region: Read existing extents on region creation Anisa Su
2026-11-04 23:02 ` [PATCH v1 13/14] cxl/mem: Trace Dynamic capacity Event Record Anisa Su
2026-11-04 23:02 ` [PATCH v1 14/14] Documentation/cxl: Document DCD extent handling Anisa Su
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=awXli-IrNpWrDC0t@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=anisa.su887@gmail.com \
--cc=anisa.su@samsung.com \
--cc=benjamin.cheatham@amd.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=gourry@gourry.net \
--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=nifan.cxl@gmail.com \
--cc=nvdimm@lists.linux.dev \
--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®