From: Anisa Su <anisa.su887@gmail.com>
To: Dave Jiang <dave.jiang@intel.com>
Cc: Anisa Su <anisa.su887@gmail.com>,
linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org,
nvdimm@lists.linux.dev, Dan Williams <djbw@kernel.org>,
Jonathan Cameron <jic23@kernel.org>,
Davidlohr Bueso <dave@stgolabs.net>,
Ira Weiny <iweiny@kernel.org>,
Alison Schofield <alison.schofield@intel.com>,
John Groves <John@groves.net>, Gregory Price <gourry@gourry.net>,
Ira Weiny <ira.weiny@intel.com>
Subject: Re: [PATCH v6 4/7] libcxl: Add extent functionality to DC regions
Date: Thu, 25 Jun 2026 02:18:34 -0700 [thread overview]
Message-ID: <ajzyail9KEDk59XZ@AnisaLaptop.localdomain> (raw)
In-Reply-To: <7ef3859e-2140-4daf-a9d5-ca7816fe9a4e@intel.com>
On Mon, Jun 08, 2026 at 05:05:58PM -0700, Dave Jiang wrote:
>
>
> On 5/23/26 2:50 AM, Anisa Su wrote:
> > From: Ira Weiny <ira.weiny@intel.com>
> >
> > DCD regions have 0 or more extents. The ability to list those and their
> > properties is useful to end users.
> >
> > Add extent scanning and reporting functionality to libcxl.
> >
> > Signed-off-by: Ira Weiny <ira.weiny@intel.com>
>
> Missing Anisa sign-off
>
Added
>
> >
> > ---
> > Changes:
> > [alison: s/tag/uuid/ for extents]
> > ---
> > Documentation/cxl/lib/libcxl.txt | 27 ++++++
> > cxl/lib/libcxl.c | 138 +++++++++++++++++++++++++++++++
> > cxl/lib/libcxl.sym | 5 ++
> > cxl/lib/private.h | 11 +++
> > cxl/libcxl.h | 11 +++
> > 5 files changed, 192 insertions(+)
> >
> > diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
> > index 9921ac1..0ad294c 100644
> > --- a/Documentation/cxl/lib/libcxl.txt
> > +++ b/Documentation/cxl/lib/libcxl.txt
> > @@ -635,6 +635,33 @@ where its properties can be interrogated by daxctl. The helper
> > cxl_region_get_daxctl_region() returns an 'struct daxctl_region *' that
> > can be used with other libdaxctl APIs.
> >
> > +EXTENTS
> > +-------
> > +
> > +=== EXTENT: Enumeration
> > +----
> > +struct cxl_region_extent;
> > +struct cxl_region_extent *cxl_extent_get_first(struct cxl_region *region);
> > +struct cxl_region_extent *cxl_extent_get_next(struct cxl_region_extent *extent);
> > +#define cxl_extent_foreach(region, extent) \
> > + for (extent = cxl_extent_get_first(region); \
> > + extent != NULL; \
> > + extent = cxl_extent_get_next(extent))
> > +
> > +----
> > +
> > +=== EXTENT: Attributes
> > +----
> > +unsigned long long cxl_extent_get_offset(struct cxl_region_extent *extent);
> > +unsigned long long cxl_extent_get_length(struct cxl_region_extent *extent);
> > +void cxl_extent_get_uuid(struct cxl_region_extent *extent, uuid_t uuid);
> > +----
> > +
> > +Extents represent available memory within a dynamic capacity region. Extent
> > +objects are available for informational purposes to aid in allocation of
> > +memory.
> > +
> > +
> > include::../../copyright.txt[]
> >
> > SEE ALSO
> > diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
> > index be0bc03..c096666 100644
> > --- a/cxl/lib/libcxl.c
> > +++ b/cxl/lib/libcxl.c
> > @@ -635,6 +635,7 @@ static void *add_cxl_region(void *parent, int id, const char *cxlregion_base)
> > region->ctx = ctx;
> > region->decoder = decoder;
> > list_head_init(®ion->mappings);
> > + list_head_init(®ion->extents);
> >
> > region->dev_path = strdup(cxlregion_base);
> > if (!region->dev_path)
> > @@ -1257,6 +1258,143 @@ cxl_mapping_get_next(struct cxl_memdev_mapping *mapping)
> > return list_next(®ion->mappings, mapping, list);
> > }
> >
> > +static void cxl_extents_init(struct cxl_region *region)
> > +{
> > + const char *devname = cxl_region_get_devname(region);
> > + struct cxl_ctx *ctx = cxl_region_get_ctx(region);
> > + char *extent_path, *dax_region_path;
> > + struct dirent *de;
> > + DIR *dir = NULL;
> > +
> > + if (region->extents_init)
> > + return;
> > + region->extents_init = 1;
> > +
> > + dax_region_path = calloc(1, strlen(region->dev_path) + 64);
> > + if (!dax_region_path) {
> > + err(ctx, "%s: allocation failure\n", devname);
> > + return;
> > + }
> > +
> > + extent_path = calloc(1, strlen(region->dev_path) + 100);
> > + if (!extent_path) {
> > + err(ctx, "%s: allocation failure\n", devname);
> > + free(dax_region_path);
> > + return;
> > + }
> > +
> > + sprintf(dax_region_path, "%s/dax_region%d",
> > + region->dev_path, region->id);
> > + dir = opendir(dax_region_path);
> > + if (!dir) {
> > + err(ctx, "no extents found (%s): %s\n",
> > + strerror(errno), dax_region_path);
> > + free(extent_path);
> > + free(dax_region_path);
> > + return;
> > + }
> > +
> > + while ((de = readdir(dir)) != NULL) {
> > + struct cxl_region_extent *extent;
> > + char buf[SYSFS_ATTR_SIZE];
> > + u64 offset, length;
> > + int id, region_id;
> > +
> > + if (sscanf(de->d_name, "extent%d.%d", ®ion_id, &id) != 2)
> > + continue;
> > +
> > + sprintf(extent_path, "%s/extent%d.%d/offset",
> > + dax_region_path, region_id, id);
> > + if (sysfs_read_attr(ctx, extent_path, buf) < 0) {
> > + err(ctx, "%s: failed to read extent%d.%d/offset\n",
> > + devname, region_id, id);
> > + continue;
> > + }
> > +
> > + offset = strtoull(buf, NULL, 0);
> > + if (offset == ULLONG_MAX) {
> > + err(ctx, "%s extent%d.%d: failed to read offset\n",
> > + devname, region_id, id);
> > + continue;
> > + }
> > +
> > + sprintf(extent_path, "%s/extent%d.%d/length",
> > + dax_region_path, region_id, id);
> > + if (sysfs_read_attr(ctx, extent_path, buf) < 0) {
> > + err(ctx, "%s: failed to read extent%d.%d/length\n",
> > + devname, region_id, id);
> > + continue;
> > + }
> > +
> > + length = strtoull(buf, NULL, 0);
> > + if (length == ULLONG_MAX) {
> > + err(ctx, "%s extent%d.%d: failed to read length\n",
> > + devname, region_id, id);
> > + continue;
> > + }
> > +
> > + sprintf(extent_path, "%s/extent%d.%d/tag",
> > + dax_region_path, region_id, id);
> > + buf[0] = '\0';
> > + if (sysfs_read_attr(ctx, extent_path, buf) != 0)
> > + dbg(ctx, "%s extent%d.%d: failed to read uuid\n",
> > + devname, region_id, id);
> > +
> > + extent = calloc(1, sizeof(*extent));
> > + if (!extent) {
> > + err(ctx, "%s extent%d.%d: allocation failure\n",
> > + devname, region_id, id);
> > + continue;
> > + }
> > + if (strlen(buf) && uuid_parse(buf, extent->uuid) < 0)
> > + err(ctx, "%s:%s\n", extent_path, buf);
> > + extent->region = region;
> > + extent->offset = offset;
> > + extent->length = length;
> > +
> > + list_node_init(&extent->list);
> > + list_add(®ion->extents, &extent->list);
>
> free_region() never frees any of the extents allocated and added here and thus leak the memory when region is freed.
>
added loop to free extents in free_region():
list_for_each_safe(®ion->extents, extent, _e, list) {
list_del_from(®ion->extents, &extent->list);
free(extent);
}
>
> > + dbg(ctx, "%s added extent%d.%d\n", devname, region_id, id);
> > + }
> > + free(dax_region_path);
> > + free(extent_path);
> > + closedir(dir);
> > +}
> > +
> > +CXL_EXPORT struct cxl_region_extent *
> > +cxl_extent_get_first(struct cxl_region *region)
> > +{
> > + cxl_extents_init(region);
> > +
> > + return list_top(®ion->extents, struct cxl_region_extent, list);
> > +}
> > +
> > +CXL_EXPORT struct cxl_region_extent *
> > +cxl_extent_get_next(struct cxl_region_extent *extent)
> > +{
> > + struct cxl_region *region = extent->region;
> > +
> > + return list_next(®ion->extents, extent, list);
> > +}
> > +
> > +CXL_EXPORT unsigned long long
> > +cxl_extent_get_offset(struct cxl_region_extent *extent)
> > +{
> > + return extent->offset;
> > +}
> > +
> > +CXL_EXPORT unsigned long long
> > +cxl_extent_get_length(struct cxl_region_extent *extent)
> > +{
> > + return extent->length;
> > +}
> > +
> > +CXL_EXPORT void
> > +cxl_extent_get_uuid(struct cxl_region_extent *extent, uuid_t uuid)
> > +{
> > + memcpy(uuid, extent->uuid, sizeof(uuid_t));
> > +}
> > +
> > CXL_EXPORT struct cxl_decoder *
> > cxl_mapping_get_decoder(struct cxl_memdev_mapping *mapping)
> > {
> > diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
> > index 258bdd3..dcfe242 100644
> > --- a/cxl/lib/libcxl.sym
> > +++ b/cxl/lib/libcxl.sym
> > @@ -298,6 +298,11 @@ global:
> > cxl_memdev_get_dynamic_ram_a_qos_class;
> > cxl_decoder_is_dynamic_ram_a_capable;
> > cxl_decoder_create_dynamic_ram_a_region;
> > + cxl_extent_get_first;
> > + cxl_extent_get_next;
> > + cxl_extent_get_offset;
> > + cxl_extent_get_length;
> > + cxl_extent_get_uuid;
> > } LIBECXL_8;
Now in LIBCXL_13
> >
> > LIBCXL_10 {
> > diff --git a/cxl/lib/private.h b/cxl/lib/private.h
> > index 37b7b06..c5f3bed 100644
> > --- a/cxl/lib/private.h
> > +++ b/cxl/lib/private.h
> > @@ -183,6 +183,7 @@ struct cxl_region {
> > struct cxl_decoder *decoder;
> > struct list_node list;
> > int mappings_init;
> > + int extents_init;
> > struct cxl_ctx *ctx;
> > void *dev_buf;
> > size_t buf_len;
> > @@ -200,6 +201,7 @@ struct cxl_region {
> > struct daxctl_region *dax_region;
> > struct kmod_module *module;
> > struct list_head mappings;
> > + struct list_head extents;
> > };
> >
> > struct cxl_memdev_mapping {
> > @@ -209,6 +211,15 @@ struct cxl_memdev_mapping {
> > struct list_node list;
> > };
> >
> > +#define CXL_REGION_EXTENT_TAG 0x10
>
> defined but never used
>
thanks for the catch! deleted
> DJ
>
Thanks,
Anisa
> > +struct cxl_region_extent {
> > + struct cxl_region *region;
> > + u64 offset;
> > + u64 length;
> > + uuid_t uuid;
> > + struct list_node list;
> > +};
> > +
> > enum cxl_cmd_query_status {
> > CXL_CMD_QUERY_NOT_RUN = 0,
> > CXL_CMD_QUERY_OK,
> > diff --git a/cxl/libcxl.h b/cxl/libcxl.h
> > index fd41122..a60509f 100644
> > --- a/cxl/libcxl.h
> > +++ b/cxl/libcxl.h
> > @@ -394,6 +394,17 @@ unsigned int cxl_mapping_get_position(struct cxl_memdev_mapping *mapping);
> > mapping != NULL; \
> > mapping = cxl_mapping_get_next(mapping))
> >
> > +struct cxl_region_extent;
> > +struct cxl_region_extent *cxl_extent_get_first(struct cxl_region *region);
> > +struct cxl_region_extent *cxl_extent_get_next(struct cxl_region_extent *extent);
> > +#define cxl_extent_foreach(region, extent) \
> > + for (extent = cxl_extent_get_first(region); \
> > + extent != NULL; \
> > + extent = cxl_extent_get_next(extent))
> > +unsigned long long cxl_extent_get_offset(struct cxl_region_extent *extent);
> > +unsigned long long cxl_extent_get_length(struct cxl_region_extent *extent);
> > +void cxl_extent_get_uuid(struct cxl_region_extent *extent, uuid_t uuid);
> > +
> > struct cxl_cmd;
> > const char *cxl_cmd_get_devname(struct cxl_cmd *cmd);
> > struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev, int opcode);
>
next prev parent reply other threads:[~2026-06-25 9:18 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-23 9:50 [PATCH v6 0/7] ndctl: Dynamic Capacity additions for cxl-cli Anisa Su
2026-05-23 9:50 ` [PATCH v6 1/7] " Anisa Su
2026-06-08 23:18 ` Dave Jiang
2026-05-23 9:50 ` [PATCH v6 2/7] libcxl: Add Dynamic RAM A partition mode support Anisa Su
2026-06-08 23:19 ` Dave Jiang
2026-06-10 3:51 ` Richard Cheng
2026-06-10 16:55 ` Dave Jiang
2026-06-25 9:08 ` Anisa Su
2026-06-25 9:07 ` Anisa Su
2026-05-23 9:50 ` [PATCH v6 3/7] cxl/region: Add cxl-cli support for dynamic RAM A Anisa Su
2026-06-08 23:58 ` Dave Jiang
2026-05-23 9:50 ` [PATCH v6 4/7] libcxl: Add extent functionality to DC regions Anisa Su
2026-06-09 0:05 ` Dave Jiang
2026-06-25 9:18 ` Anisa Su [this message]
2026-05-23 9:50 ` [PATCH v6 5/7] cxl/region: Add extent output to region query Anisa Su
2026-06-09 0:08 ` Dave Jiang
2026-06-10 3:55 ` Richard Cheng
2026-06-16 10:47 ` Anisa Su
2026-06-16 10:45 ` Anisa Su
2026-05-23 9:50 ` [PATCH v6 6/7] daxctl: Add --uuid option to create-device for sparse regions Anisa Su
2026-06-09 0:12 ` Dave Jiang
2026-06-25 9:30 ` Anisa Su
2026-05-23 9:50 ` [PATCH v6 7/7] cxl/test: Add Dynamic Capacity tests Anisa Su
2026-06-09 0:24 ` Dave Jiang
2026-06-25 9:34 ` Anisa Su
2026-06-05 5:43 ` [PATCH v6 0/7] ndctl: Dynamic Capacity additions for cxl-cli Alison Schofield
2026-06-08 8:11 ` Anisa Su
2026-06-17 7:10 ` Alison Schofield
2026-06-18 5:52 ` Anisa Su
2026-06-19 0:38 ` Alison Schofield
2026-06-24 4:51 ` 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=ajzyail9KEDk59XZ@AnisaLaptop.localdomain \
--to=anisa.su887@gmail.com \
--cc=John@groves.net \
--cc=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=djbw@kernel.org \
--cc=gourry@gourry.net \
--cc=ira.weiny@intel.com \
--cc=iweiny@kernel.org \
--cc=jic23@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
/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