From: Anisa Su <anisa.su887@gmail.com>
To: Anisa Su <anisa.su887@gmail.com>
Cc: linux-cxl@vger.kernel.org, alison.schofield@intel.com,
jic23@kernel.org, dave.jiang@intel.com, gourry@gourry.net,
icheng@nvidia.com, ming.li@zohomail.com,
vishal.l.verma@intel.com, dave@stgolabs.net,
benjamin.cheatham@amd.com, Ira Weiny <iweiny@kernel.org>,
Wonjae Lee <wj28.lee@samsung.com>,
Junhee Park <jh9934.park@samsung.com>,
Heesoo Kim <habil.kim@samsung.com>
Subject: Re: [RESEND PATCH v13 2/8] cxl/mem: Read dynamic capacity configuration from the device
Date: Fri, 18 Sep 2026 13:09:11 -0700 [thread overview]
Message-ID: <aq2aZ2FxeLkv_NdJ@4470NRD-ASU.ssi.samsung.com> (raw)
In-Reply-To: <20260908102124.2231730-4-anisa.su@samsung.com>
On Tue, Sep 08, 2026 at 03:15:06AM -0700, Anisa Su wrote:
> From: Ira Weiny <iweiny@kernel.org>
>
> Devices which support Dynamic Capacity (DC) are configured
> via mailbox commands. CXL r4.0 section 9.13.3 requires the host to issue
> the Get DC Configuration command in order to properly configure DCDs.
>
> Implement the DC mailbox commands as specified in CXL 4.0 section
> 8.2.10.9.9 (opcodes 48XXh) to read and store the DCD configuration
> information. Disable DCD if an invalid configuration is found.
>
> Linux has no support for more than one dynamic capacity partition. Read
> all the partitions the device reports but validate only the first, and
> configure it as 'dynamic ram 1'.
>
> The specification requires that volatile capacity starts at DPA 0 and pmem
> starts at the DPA immediately following it, but DC partitions only need
> to be 256MB aligned according to CXL r4.0 section 8.2.10.9.9.1 Table 8-347.
> So a device could leave a gap between ram/pmem (static) capacity and its first
> DC partition, or between one DC partition and the next.
>
> However, Linux follows the precedent set by PMEM/RAM partitions and requires the
> first DC partition to begin at the DPA immediately following static
> capacity.
>
> Based on an original patch by Navneet Singh.
>
> Signed-off-by: Ira Weiny <iweiny@kernel.org>
> 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>
>
> ---
> Changes:
> 1. mbox.c: validate only the first DC partition. Other partitions are read
> to make it easier to add support for additional partitions but not
> checked. Richard/Alison
>
> 2. mbox.c: rework the cxl_dc_check() validation. Run the checks in
> dependency order -- block size, decode length, length, base -- so the
> block size is validated before IS_ALIGNED() uses it as an alignment,
> and give each failure its own message naming the field that is wrong.
> Drop the block size alignment requirement on the region base; CXL
> r4.0 Table 8-347 requires the base to be 256M aligned and states the
> block size alignment for extent start DPAs, not for the base.
> Reported by Alison.
>
> 3. mbox.c: range check the number of available DC partitions reported by
> the device. CXL r4.0 Table 8-346 requires a DCD to report between 1
> and 8 regions, but the count was used unchecked as the read loop
> bound, so an out of range value failed later as "Invalid num of
> dynamic capacity partitions". Reported by Alison.
>
> 4. mbox.c/pci.c: cxl_configure_dcd() returns an error instead of void,
> and cxl_pci_probe() decides what to do with it. Failure to read the
> DC configuration is now reported rather than silently swallowed;
> -EINVAL for a partition overlapping static capacity, -EOPNOTSUPP for
> the gap Linux does not support, and the mailbox error propagated
> otherwise. cxl_disable_dcd() moves to the caller so the function
> reports and the caller sets policy. Probe still continues without
> DCD rather than failing the memdev, which would cost the device its
> static capacity too. Reported by Jonathan Cameron.
>
> 5. mbox.c: check the block size is a power of 2 in 64 bits.
> is_power_of_2() takes an unsigned long, so on a 32 bit build blk_size
> was truncated to its low 32 bits and a value such as 0x100000040 --
> non-zero and a multiple of 40h -- passed validation. CXL_BUS only
> depends on PCI, so this builds on 32 bit. Reported by Sashiko.
> ---
> drivers/cxl/core/hdm.c | 2 +
> drivers/cxl/core/mbox.c | 235 ++++++++++++++++++++++++++++++++++++++
> drivers/cxl/core/memdev.c | 37 ++++++
> drivers/cxl/cxlmem.h | 55 +++++++++
> drivers/cxl/pci.c | 6 +
> include/cxl/cxl.h | 3 +-
> 6 files changed, 337 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> index b3419df586b9..fdd6b395dcdf 100644
> --- a/drivers/cxl/core/memdev.c
> +++ b/drivers/cxl/core/memdev.c
> @@ -643,6 +643,43 @@ int cxl_mem_dpa_fetch(struct cxl_memdev_state *mds, struct cxl_dpa_info *info)
> }
> EXPORT_SYMBOL_NS_GPL(cxl_mem_dpa_fetch, "CXL");
>
> +int cxl_configure_dcd(struct cxl_memdev_state *mds, struct cxl_dpa_info *info)
> +{
> + struct cxl_dc_partition_info dc_info = { };
> + struct device *dev = mds->cxlds.dev;
> + int rc;
> +
Check media_ready here, similar to cxl_mem_dpa_fetch, which doesn't configure
ram/pmem partitions if !media_ready.
if (!mds->cxlds.media_ready)
return 0;
Reported-by Claude with /kreview skill
(https://github.com/masoncl/review-prompts)
> + rc = cxl_dev_dc_identify(&mds->cxlds.cxl_mbox, &dc_info);
> + if (rc) {
> + dev_warn(dev,
> + "Failed to read Dynamic Capacity config: %d\n", rc);
> + return rc;
> + }
> +
> + if (dc_info.start < info->size) {
> + dev_err(dev,
> + "DC partition 0 base %#llx overlaps static capacity ending at %#llx\n",
> + dc_info.start, info->size);
> + return -EINVAL;
> + }
> +
> + /* A gap between static capacity and the DC partition is not supported */
> + if (dc_info.start > info->size) {
> + dev_warn(dev,
> + "DC partition 0 base %#llx leaves a gap from static capacity ending at %#llx\n",
> + dc_info.start, info->size);
> + return -EOPNOTSUPP;
> + }
> +
> + info->size += dc_info.size;
> + dev_dbg(dev, "Adding dynamic ram partition 1; %#llx size %#llx\n",
> + dc_info.start, dc_info.size);
> + add_part(info, dc_info.start, dc_info.size, CXL_PARTMODE_DYNAMIC_RAM_1);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_NS_GPL(cxl_configure_dcd, "CXL");
> +
>
> /**
> * cxl_set_capacity: initialize dpa by a driver without a mailbox.
> diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
> index 0c8e23276dc6..4fac65dbb808 100644
> --- a/drivers/cxl/cxlmem.h
> +++ b/drivers/cxl/cxlmem.h
> @@ -407,6 +407,8 @@ struct cxl_security_state {
> struct kernfs_node *sanitize_node;
> };
>
> +#define CXL_MAX_DC_PARTITIONS 8
> +
> static inline resource_size_t cxl_pmem_size(struct cxl_dev_state *cxlds)
> {
> /*
> @@ -689,6 +691,39 @@ struct cxl_mbox_set_shutdown_state_in {
> u8 state;
> } __packed;
>
> +/* See CXL r4.0 Table 8-345 get dynamic capacity config Input Payload */
> +struct cxl_mbox_get_dc_config_in {
> + u8 partition_count;
> + u8 start_partition_index;
> +} __packed;
> +
> +/* See CXL r4.0 Table 8-346 get dynamic capacity config Output Payload */
> +struct cxl_mbox_get_dc_config_out {
> + u8 avail_partition_count;
> + u8 partitions_returned;
> + u8 rsvd[6];
> + /* See CXL r4.0 Table 8-347 */
> + struct cxl_dc_partition {
> + __le64 base;
> + __le64 decode_length;
> + __le64 length;
> + __le64 block_size;
> + __le32 dsmad_handle;
> + u8 flags;
> + u8 rsvd[3];
> + } __packed partition[] __counted_by(partitions_returned);
> + /* Trailing extent/tag count fields unused */
> +} __packed;
> +
> +/* Trailing counts; cannot be a member after the flex array above */
> +struct cxl_mbox_get_dc_config_tail {
> + __le32 num_extents_supported;
> + __le32 num_extents_available;
> + __le32 num_tags_supported;
> + __le32 num_tags_available;
> +} __packed;
> +#define CXL_DCD_BLOCK_LINE_SIZE 0x40
> +
> /* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */
> struct cxl_mbox_set_timestamp_in {
> __le64 timestamp;
> @@ -812,9 +847,18 @@ enum {
> int cxl_internal_send_cmd(struct cxl_mailbox *cxl_mbox,
> struct cxl_mbox_cmd *cmd);
> int cxl_dev_state_identify(struct cxl_memdev_state *mds);
> +
> +struct cxl_dc_partition_info {
> + u64 start;
> + u64 size;
> +};
> +
> +int cxl_dev_dc_identify(struct cxl_mailbox *mbox,
> + struct cxl_dc_partition_info *dc_info);
> int cxl_await_media_ready(struct cxl_dev_state *cxlds);
> int cxl_enumerate_cmds(struct cxl_memdev_state *mds);
> int cxl_mem_dpa_fetch(struct cxl_memdev_state *mds, struct cxl_dpa_info *info);
> +int cxl_configure_dcd(struct cxl_memdev_state *mds, struct cxl_dpa_info *info);
> struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial,
> u16 dvsec);
> void set_exclusive_cxl_commands(struct cxl_memdev_state *mds,
> @@ -828,6 +872,17 @@ void cxl_event_trace_record(struct cxl_memdev *cxlmd,
> const uuid_t *uuid, union cxl_event *evt);
> int cxl_get_dirty_count(struct cxl_memdev_state *mds, u32 *count);
> int cxl_arm_dirty_shutdown(struct cxl_memdev_state *mds);
> +
> +static inline bool cxl_dcd_supported(struct cxl_memdev_state *mds)
> +{
> + return mds->dcd_supported;
> +}
> +
> +static inline void cxl_disable_dcd(struct cxl_memdev_state *mds)
> +{
> + mds->dcd_supported = false;
> +}
> +
> int cxl_set_timestamp(struct cxl_memdev_state *mds);
> int cxl_poison_state_init(struct cxl_memdev_state *mds);
> int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
> diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
> index c7c91e8dc51d..2fe9db4b3d86 100644
> --- a/drivers/cxl/pci.c
> +++ b/drivers/cxl/pci.c
> @@ -868,6 +868,12 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> if (rc)
> return rc;
>
> + if (cxl_dcd_supported(mds)) {
> + rc = cxl_configure_dcd(mds, &range_info);
> + if (rc)
> + cxl_disable_dcd(mds);
> + }
> +
> rc = cxl_dpa_setup(cxlds, &range_info);
> if (rc)
> return rc;
> diff --git a/include/cxl/cxl.h b/include/cxl/cxl.h
> index 802b143de83d..4ef9511fbbdd 100644
> --- a/include/cxl/cxl.h
> +++ b/include/cxl/cxl.h
> @@ -133,6 +133,7 @@ struct cxl_dpa_perf {
> enum cxl_partition_mode {
> CXL_PARTMODE_RAM,
> CXL_PARTMODE_PMEM,
> + CXL_PARTMODE_DYNAMIC_RAM_1,
> };
>
> /**
> @@ -147,7 +148,7 @@ struct cxl_dpa_partition {
> enum cxl_partition_mode mode;
> };
>
> -#define CXL_NR_PARTITIONS_MAX 2
> +#define CXL_NR_PARTITIONS_MAX 3
>
> /**
> * struct cxl_dev_state - The driver device state
> --
> 2.43.0
>
next prev parent reply other threads:[~2026-09-18 20:09 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 10:15 [RESEND PATCH v13 0/8] DCD Prep Series Anisa Su
2026-09-08 10:15 ` [RESEND PATCH v13 1/8] cxl/mbox: Flag support for Dynamic Capacity Devices (DCD) Anisa Su
2026-09-08 15:39 ` dave
2026-09-08 18:45 ` Jonathan Cameron
2026-09-15 7:04 ` Richard Cheng
2026-09-15 17:20 ` Anisa Su
2026-09-16 1:24 ` Alison Schofield
2026-09-08 10:15 ` [RESEND PATCH v13 2/8] cxl/mem: Read dynamic capacity configuration from the device Anisa Su
2026-09-08 15:59 ` Davidlohr Bueso
2026-09-08 20:43 ` Jonathan Cameron
2026-09-10 23:56 ` Anisa Su
2026-09-11 0:53 ` Jonathan Cameron
2026-09-11 16:38 ` Anisa Su
2026-09-15 7:30 ` Richard Cheng
2026-09-15 20:38 ` Anisa Su
2026-09-16 1:28 ` Alison Schofield
2026-09-18 20:09 ` Anisa Su [this message]
2026-09-08 10:15 ` [RESEND PATCH v13 3/8] cxl/cdat: Gather DSMAS data for DCD partitions Anisa Su
2026-09-08 20:52 ` Jonathan Cameron
2026-09-11 0:02 ` Anisa Su
2026-09-11 0:56 ` Jonathan Cameron
2026-09-11 16:37 ` Anisa Su
2026-09-14 20:33 ` Anisa Su
2026-09-16 1:08 ` Jonathan Cameron
2026-09-15 9:16 ` Richard Cheng
2026-09-15 21:24 ` Anisa Su
2026-09-16 1:30 ` Alison Schofield
2026-09-08 10:15 ` [RESEND PATCH v13 4/8] cxl/events: Split event msgnum configuration from irq setup Anisa Su
2026-09-08 16:37 ` Davidlohr Bueso
2026-09-08 10:15 ` [RESEND PATCH v13 5/8] cxl/pci: Factor out interrupt policy check Anisa Su
2026-09-08 17:17 ` Davidlohr Bueso
2026-09-16 1:32 ` Alison Schofield
2026-09-08 10:15 ` [RESEND PATCH v13 6/8] cxl/mem: Configure dynamic capacity interrupts Anisa Su
2026-09-08 10:43 ` sashiko-bot
2026-09-11 21:10 ` Anisa Su
2026-09-12 0:09 ` Gregory Price
2026-09-14 17:48 ` Anisa Su
2026-09-08 22:14 ` Jonathan Cameron
2026-09-11 18:21 ` Anisa Su
2026-09-16 1:35 ` Alison Schofield
2026-09-18 20:13 ` Anisa Su
2026-09-08 10:15 ` [RESEND PATCH v13 7/8] cxl/core: Enforce partition order/simplify partition calls Anisa Su
2026-09-16 1:38 ` Alison Schofield
2026-09-08 10:15 ` [RESEND PATCH v13 8/8] Documentation/cxl: Document DPA partition layout and ordering rules Anisa Su
2026-09-08 22:17 ` Jonathan Cameron
2026-09-11 20:39 ` Anisa Su
2026-09-09 15:19 ` Davidlohr Bueso
2026-09-11 20:38 ` Anisa Su
2026-09-11 20:50 ` Davidlohr Bueso
2026-09-14 19:56 ` Anisa Su
2026-09-12 0:20 ` Gregory Price
2026-09-14 19:30 ` Anisa Su
2026-09-16 1:11 ` Jonathan Cameron
2026-09-16 1:39 ` Alison Schofield
2026-09-16 1:22 ` [RESEND PATCH v13 0/8] DCD Prep Series Alison Schofield
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=aq2aZ2FxeLkv_NdJ@4470NRD-ASU.ssi.samsung.com \
--to=anisa.su887@gmail.com \
--cc=alison.schofield@intel.com \
--cc=benjamin.cheatham@amd.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=gourry@gourry.net \
--cc=habil.kim@samsung.com \
--cc=icheng@nvidia.com \
--cc=iweiny@kernel.org \
--cc=jh9934.park@samsung.com \
--cc=jic23@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=ming.li@zohomail.com \
--cc=vishal.l.verma@intel.com \
--cc=wj28.lee@samsung.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.