Skip to contentSkip to conversation

Application Specific Tagged Memory Support in CXL Type 3 Devices

PATCH In review Alireza Sanaee 3 participants 23 messages Mar 25 – Apr 1 Arm STM32

lore
Share & tools
lore
#0 lore raw

cover Application Specific Tagged Memory Support in CXL Type 3 Devices

Hi,

This series is a rework of the earlier RFC posted at:
https://lore.kernel.org/all/[email protected]/

The overall goal is still to support application-specific tagged memory for CXL Type 3 dynamic capacity, but the backend model is now different.

The earlier RFC introduced a dedicated tagged memory backend object. This version does not. Instead, the first patch adds a tag property to generic host memory backends, and the rest of the series teaches the CXL Type 3 DC flow to find and hook up those tagged backends lazily at runtime.

In practice, a device may now be created with dc-regions-total-size and no volatile-dc-memdev. When add-capacity is requested with a tag, the tagged host memory backend is looked up, validated, and only mapped after host acceptance. The committed extent keeps the backend and fixed window metadata so that:

- direct alias mapping can be installed for the performant path,
- teardown can happen correctly at release time, and
- tag-based removal can locate and release extents by tag.

Assumptions, limitations and reasons behind it:

1. Each lazy-backed extent maps to exactly one tagged host memory backend. In VM scenarios, we just need to add a backend which has one extent representing the entire backend tied to one region. If more extents required then more regions can be added.
2. Partial release of a backend-backed extent is rejected. If a backend is represented by the one extent then partial release of a region does not makes sense.
3. The current lazy flow only supports a single extent per add request. This can be changed if required later.

This series contains:

- add generic host memory backend tag support;
- allow creating DC-only Type 3 devices with total capacity but no backing device at init time;
- wire tagged host memory backends into the DC add flow;
- store per-extent backend and fixed-window metadata;
- map the backend after host acceptance;
- add the direct alias fast path for accesses;
- tear down aliases and lazy mappings on release;
- add tag-based removal support; and
- add a status QMP helper for orchestration layers.

Tested with two tagged memory-backend-ram objects and QMP-driven add and release flows, including tag-based release.

Example flow
============

Below is a short tutorial-style example based on the earlier RFC, but updated for the current design where generic host memory backends carry the tag.

1. Start QEMU with a Type 3 device that advertises dynamic capacity via dc-regions-total-size, without an initial volatile-dc-memdev.

   -device cxl-type3,bus=root_port13,id=cxl-vmem0,num-dc-regions=1, \
           dc-regions-total-size=4G

2. Create tagged backends at runtime with QMP:

{
    "execute": "object-add",
    "arguments": {
        "qom-type": "memory-backend-ram",
        "id": "tm0",
        "size": 1073741824,
        "share": true,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a"
    }
}
{
    "execute": "object-add",
    "arguments": {
        "qom-type": "memory-backend-ram",
        "id": "tm1",
        "size": 1073741824,
        "share": true,
        "tag": "6be13bce-ae34-4a77-b6c3-16df975fcf1a"
    }
}

3. Add capacity by tag:

{
    "execute": "cxl-add-dynamic-capacity",
    "arguments": {
        "path": "/machine/peripheral/cxl-vmem0",
        "host-id": 0,
        "selection-policy": "prescriptive",
        "region": 0,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a",
        "extents": [
            {
                "offset": 0,
                "len": 1073741824
            }
        ]
    }
}

After the host accepts the extent, the tagged backend is mapped and the direct alias path becomes active for the committed extent.

4. Release by tag:

{
    "execute": "cxl-release-dynamic-capacity",
    "arguments": {
        "path": "/machine/peripheral/cxl-vmem0",
        "host-id": 0,
        "removal-policy": "tag-based",
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a",
        "region": 0,
        "extents": [
            {
                "offset": 0,
                "len": 1073741824
            }
        ]
    }
}

5. Query whether the tagged extent is still present:

{
    "execute": "cxl-release-dynamic-capacity-status",
    "arguments": {
        "path": "/machine/peripheral/cxl-vmem0",
        "host-id": 0,
        "tag": "5be13bce-ae34-4a77-b6c3-16df975fcf1a",
        "region": 0
    }
}

For the Ira patchset from Intel, I allowed UUIDs in the kernel-side flow, and that change is available here:
https://github.com/sarsanaee/linux/tree/allow_uuid_ira

Depends-on:
https://lore.kernel.org/all/[email protected]/

Depends-on:
https://lore.kernel.org/all/[email protected]/

--
Alireza Sanaee

Alireza Sanaee (9):
hw/mem: Add tag support to generic host memory backends hw/cxl: Allow initializing type3 device with no backing device hw/cxl: Hook up tagged host memory backends at runtime for DC extents hw/cxl: Carry backend metadata in DC extent records hw/cxl: Map lazy memory backend after host acceptance hw/cxl: Create direct fixed-window aliases for accepted extents hw/cxl: Add release-time teardown for direct-mapped extents hw/cxl: Add tag-based dynamic-capacity release support hw/cxl: Add QMP status query for dynamic-capacity extent release

 backends/hostmem.c          |  72 +++++++
 hw/cxl/cxl-host.c           |   6 +
 hw/cxl/cxl-mailbox-utils.c  | 223 ++++++++++++++++++++--
 hw/mem/cxl_type3.c          | 361 +++++++++++++++++++++++++++++++-----
 hw/mem/cxl_type3_stubs.c    |  10 +
 include/hw/cxl/cxl_device.h |  41 +++-
 include/system/hostmem.h    |   2 +
 qapi/cxl.json               |  46 +++++
 qapi/qom.json               |   3 +
 tests/qtest/qom-test.c      |   8 +-
 10 files changed, 703 insertions(+), 69 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

PATCH 1/9 hw/mem: Add tag support to generic host memory backends

Add a string tag property to HostMemoryBackend so that backends can be identified by a user-assigned name at runtime. Expose the property through QOM and add a host_memory_backend_find_by_tag() helper that walks the object tree to locate a backend by its tag.

This is used by the following CXL patches to resolve a named backend for a pending DC extent and attach it to the accepted extent when the host acknowledges the add request.

---
 backends/hostmem.c       | 72 ++++++++++++++++++++++++++++++++++++++++
 include/system/hostmem.h |  2 ++
 qapi/qom.json            |  3 ++
 tests/qtest/qom-test.c   |  8 +++--
 4 files changed, 83 insertions(+), 2 deletions(-)
backends/hostmem.c +72 -0
index 15d4365b69..270cae9569 100644
@@ -47,6 +47,50 @@ host_memory_backend_get_name(HostMemoryBackend *backend)
     return object_get_canonical_path(OBJECT(backend));
 }
 
+typedef struct HostMemoryBackendTagSearch {
+    const char *tag;
+    HostMemoryBackend *backend;
+} HostMemoryBackendTagSearch;
+
+static int host_memory_backend_find_by_tag_cb(Object *obj, void *opaque)
+{
+    HostMemoryBackendTagSearch *ctx = opaque;
+    HostMemoryBackend *backend;
+
+    if (!object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
+        return 0;
+    }
+
+    backend = MEMORY_BACKEND(obj);
+    if (!backend->tag) {
+        return 0;
+    }
+
+    if (strcmp(backend->tag, ctx->tag) == 0) {
+        ctx->backend = backend;
+        return 1;
+    }
+
+    return 0;
+}
+
+HostMemoryBackend *host_memory_backend_find_by_tag(const char *tag)
+{
+    HostMemoryBackendTagSearch ctx = {
+        .tag = tag,
+        .backend = NULL,
+    };
+
+    if (!tag) {
+        return NULL;
+    }
+
+    object_child_foreach_recursive(object_get_objects_root(),
+                                   host_memory_backend_find_by_tag_cb, &ctx);
+
+    return ctx.backend;
+}
+
 static void
 host_memory_backend_get_size(Object *obj, Visitor *v, const char *name,
                              void *opaque, Error **errp)
@@ -460,6 +504,22 @@ static void host_memory_backend_set_share(Object *o, bool value, Error **errp)
     backend->share = value;
 }
 
+static void
+host_memory_backend_set_tag(Object *obj, const char *value, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    g_free(backend->tag);
+    backend->tag = g_strdup(value);
+}
+
+static char *host_memory_backend_get_tag(Object *obj, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    return g_strdup(backend->tag);
+}
+
 #ifdef CONFIG_LINUX
 static bool host_memory_backend_get_reserve(Object *o, Error **errp)
 {
@@ -501,6 +561,13 @@ host_memory_backend_set_use_canonical_path(Object *obj, bool value,
     backend->use_canonical_path = value;
 }
 
+static void host_memory_backend_finalize(Object *obj)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    g_free(backend->tag);
+}
+
 static void
 host_memory_backend_class_init(ObjectClass *oc, const void *data)
 {
@@ -557,6 +624,10 @@ host_memory_backend_class_init(ObjectClass *oc, const void *data)
         host_memory_backend_get_share, host_memory_backend_set_share);
     object_class_property_set_description(oc, "share",
         "Mark the memory as private to QEMU or shared");
+    object_class_property_add_str(oc, "tag",
+        host_memory_backend_get_tag, host_memory_backend_set_tag);
+    object_class_property_set_description(oc, "tag",
+        "A user-defined tag to identify this memory backend");
 #ifdef CONFIG_LINUX
     object_class_property_add_bool(oc, "reserve",
         host_memory_backend_get_reserve, host_memory_backend_set_reserve);
@@ -586,6 +657,7 @@ static const TypeInfo host_memory_backend_info = {
     .class_init = host_memory_backend_class_init,
     .instance_size = sizeof(HostMemoryBackend),
     .instance_init = host_memory_backend_init,
+    .instance_finalize = host_memory_backend_finalize,
     .instance_post_init = host_memory_backend_post_init,
     .interfaces = (const InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
include/system/hostmem.h +2 -0
index 88fa791ac7..a02e173d48 100644
@@ -81,12 +81,14 @@ struct HostMemoryBackend {
     ThreadContext *prealloc_context;
     DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
     HostMemPolicy policy;
+    char *tag;
 
     MemoryRegion mr;
 };
 
 bool host_memory_backend_mr_inited(HostMemoryBackend *backend);
 MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend);
+HostMemoryBackend *host_memory_backend_find_by_tag(const char *tag);
 
 void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
 bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
qapi/qom.json +3 -0
index c653248f85..e6feeb324a 100644
@@ -658,6 +658,8 @@
 # @reserve: if true, reserve swap space (or huge pages) if applicable
 #     (default: true) (since 6.1)
 #
+# @tag: user-defined memory backend tag (since 11.1)
+#
 # @size: size of the memory region in bytes
 #
 # @x-use-canonical-path-for-ramblock-id: if true, the canonical path
@@ -683,6 +685,7 @@
             '*prealloc-context': 'str',
             '*share': 'bool',
             '*reserve': 'bool',
+            '*tag': 'str',
             'size': 'size',
             '*x-use-canonical-path-for-ramblock-id': 'bool' } }
 
tests/qtest/qom-test.c +6 -2
index 6421f2d9d9..3109b47cca 100644
@@ -17,6 +17,7 @@
 
 #define RAM_NAME "node0"
 #define RAM_SIZE 65536
+#define RAM_TAG "ramtag0"
 
 static int verbosity_level;
 
@@ -59,6 +60,8 @@ static void test_list_get_value(QTestState *qts)
 
         } else if (!strcmp(prop_name, "size")) {
             g_assert_cmpint(qdict_get_int(prop, "value"), ==, RAM_SIZE);
+        } else if (!strcmp(prop_name, "tag")) {
+            g_assert_cmpstr(qdict_get_str(prop, "value"), ==, RAM_TAG);
         }
     }
 }
@@ -195,8 +198,9 @@ static void test_machine(gconstpointer data)
     QTestState *qts;
     g_autoptr(QList) paths = qlist_new();
 
-    qts = qtest_initf("-machine %s -object memory-backend-ram,id=%s,size=%d",
-                      machine, RAM_NAME, RAM_SIZE);
+    qts = qtest_initf("-machine %s -object memory-backend-ram,id=%s,size=%d"
+                      ",tag=%s",
+                      machine, RAM_NAME, RAM_SIZE, RAM_TAG);
 
     if (g_test_slow()) {
         /* Make sure we can get the machine class properties: */
Signature · 1 line
2.50.1 (Apple Git-155)
#2 lore raw

Re: [PATCH 1/9] hw/mem: Add tag support to generic host memory backends

Quoted 4 lines · Alireza Sanaee

Add a string tag property to HostMemoryBackend so that backends can be identified by a user-assigned name at runtime. Expose the property through QOM and add a host_memory_backend_find_by_tag() helper that walks the object tree to locate a backend by its tag.

Why can't you use the QOM ID?

$ qemu-system-x86_64 -S -display none -monitor stdio -object memory-backend-ram,id=fred,size=1M
QEMU 10.2.90 monitor - type 'help' for more information
(qemu) info qom-tree /objects/fred
/fred (memory-backend-ram)
  /fred[0] (memory-region)
#3 lore raw

Re: [PATCH 1/9] hw/mem: Add tag support to generic host memory backends

On Thu, 26 Mar 2026 11:42:17 +0100
Markus Armbruster <[email protected]> wrote:

Hi Markus,

Quoted 7 lines
Quoted 4 lines · Alireza Sanaee

Add a string tag property to HostMemoryBackend so that backends can be identified by a user-assigned name at runtime. Expose the property through QOM and add a host_memory_backend_find_by_tag() helper that walks the object tree to locate a backend by its tag.

Quoted 9 lines

Why can't you use the QOM ID?

$ qemu-system-x86_64 -S -display none -monitor stdio -object memory-backend-ram,id=fred,size=1M
QEMU 10.2.90 monitor - type 'help' for more information
(qemu) info qom-tree /objects/fred
/fred (memory-backend-ram)
  /fred[0] (memory-region)

Fair question. The ID would have been a solution if it had accepted GUIDs. CXL spec requires GUIDs for extents as identification, hence new tag property.

alireza@blue-ocean:~/Downloads$ qemu-system-x86_64 -s -display none -monitor std
io -object memory-backend-ram,id=02bb2436-e87d-4aa1-b2be-aaffdd76bb79,size=1M
qemu-system-x86_64: -object memory-backend-ram,id=02bb2436-e87d-4aa1-b2be-aaffdd
76bb79,size=1M: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.

Thanks,
Ali

#4 lore raw

Re: [PATCH 1/9] hw/mem: Add tag support to generic host memory backends

Quoted 22 lines · Alireza Sanaee

On Thu, 26 Mar 2026 11:42:17 +0100
Markus Armbruster <[email protected]> wrote:

Hi Markus,

Quoted 7 lines
Quoted 4 lines · Alireza Sanaee

Add a string tag property to HostMemoryBackend so that backends can be identified by a user-assigned name at runtime. Expose the property through QOM and add a host_memory_backend_find_by_tag() helper that walks the object tree to locate a backend by its tag.

Quoted 9 lines

Why can't you use the QOM ID?

$ qemu-system-x86_64 -S -display none -monitor stdio -object memory-backend-ram,id=fred,size=1M
QEMU 10.2.90 monitor - type 'help' for more information
(qemu) info qom-tree /objects/fred
/fred (memory-backend-ram)
  /fred[0] (memory-region)
Quoted 2 lines

Fair question. The ID would have been a solution if it had accepted GUIDs. CXL spec requires GUIDs for extents as identification, hence new tag property.

Your commit message should state that this needs to be a GUID and why.

Quoted 8 lines
alireza@blue-ocean:~/Downloads$ qemu-system-x86_64 -s -display none -monitor std
io -object memory-backend-ram,id=02bb2436-e87d-4aa1-b2be-aaffdd76bb79,size=1M
qemu-system-x86_64: -object memory-backend-ram,id=02bb2436-e87d-4aa1-b2be-aaffdd
76bb79,size=1M: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.

Thanks,
Ali

#5 lore raw

Re: [PATCH 1/9] hw/mem: Add tag support to generic host memory backends

On Thu, 26 Mar 2026 14:01:06 +0100
Markus Armbruster <[email protected]> wrote:

Hi Markus,

Sure, absolutely.

Quoted 39 lines
Quoted 22 lines · Alireza Sanaee

On Thu, 26 Mar 2026 11:42:17 +0100
Markus Armbruster <[email protected]> wrote:

Hi Markus,

Quoted 7 lines
Quoted 4 lines · Alireza Sanaee

Add a string tag property to HostMemoryBackend so that backends can be identified by a user-assigned name at runtime. Expose the property through QOM and add a host_memory_backend_find_by_tag() helper that walks the object tree to locate a backend by its tag.

Quoted 9 lines

Why can't you use the QOM ID?

$ qemu-system-x86_64 -S -display none -monitor stdio -object memory-backend-ram,id=fred,size=1M
QEMU 10.2.90 monitor - type 'help' for more information
(qemu) info qom-tree /objects/fred
/fred (memory-backend-ram)
  /fred[0] (memory-region)
Quoted 2 lines

Fair question. The ID would have been a solution if it had accepted GUIDs. CXL spec requires GUIDs for extents as identification, hence new tag property.

Your commit message should state that this needs to be a GUID and why.

Quoted 8 lines
alireza@blue-ocean:~/Downloads$ qemu-system-x86_64 -s -display none -monitor std
io -object memory-backend-ram,id=02bb2436-e87d-4aa1-b2be-aaffdd76bb79,size=1M
qemu-system-x86_64: -object memory-backend-ram,id=02bb2436-e87d-4aa1-b2be-aaffdd
76bb79,size=1M: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.

Thanks,
Ali

#6 lore raw

PATCH 2/9 hw/cxl: Allow initializing type3 device with no backing device

In reply to Alireza Sanaee

Add a dc-regions-total-size property that allows creating a CXL type3 device with DC regions but without a backing memory device at init time. In Dynamic Capacity scenarios, memory can show up asynchronously from different resources (RAM, PMEM, file-backed). For these cases, only the total DC size needs to be known upfront.

When dc-regions-total-size is set (instead of volatile-dc-memdev), the device initializes DC regions using the specified total size but does not set up any backing memory. Any FMAPI or QMP command that attempts to add or release extents will fail with an error, since no backing device is available yet. The runtime hookup of tagged memory backends will be added in a subsequent patch.

---
 hw/cxl/cxl-mailbox-utils.c  |  8 ++++
 hw/mem/cxl_type3.c          | 92 ++++++++++++++++++++++---------------
 include/hw/cxl/cxl_device.h |  1 +
 3 files changed, 65 insertions(+), 36 deletions(-)
hw/cxl/cxl-mailbox-utils.c +8 -0
index c83b5f90d4..e6e136cf44 100644
@@ -4270,6 +4270,10 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd,
     CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
     int i, rc;
 
+    if (ct3d->dc.total_capacity_cmd) {
+        return CXL_MBOX_UNSUPPORTED;
+    }
+
     switch (in->selection_policy) {
         case CXL_EXTENT_SELECTION_POLICY_PRESCRIPTIVE: {
             /* Adding extents exceeds device's extent tracking ability. */
@@ -4357,6 +4361,10 @@ static CXLRetCode cmd_fm_initiate_dc_release(const struct cxl_cmd *cmd,
     CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
     int i, rc;
 
+    if (ct3d->dc.total_capacity_cmd) {
+        return CXL_MBOX_UNSUPPORTED;
+    }
+
     switch (in->flags & CXL_EXTENT_REMOVAL_POLICY_MASK) {
         case CXL_EXTENT_REMOVAL_POLICY_PRESCRIPTIVE: {
             CXLDCExtentList updated_list;
hw/mem/cxl_type3.c +56 -36

131 lines not on this page · raw message

include/hw/cxl/cxl_device.h +1 -0
index ba551fa5f9..630cf44e0e 100644
@@ -785,6 +785,7 @@ struct CXLType3Dev {
          * memory region size.
          */
         uint64_t total_capacity; /* 256M aligned */
+        uint64_t total_capacity_cmd; /* 256M aligned */
         CXLDCExtentList extents;
         CXLDCExtentGroupList extents_pending;
         uint32_t total_extent_count;
Signature · 1 line
2.50.1 (Apple Git-155)
#7 lore raw

PATCH 3/9 hw/cxl: Hook up tagged host memory backends at runtime for DC extents

In reply to Alireza Sanaee

When a type3 device is created with dc-regions-total-size instead of an initial volatile-dc-memdev, prescriptive DC add requests need a way to name the backend to attach to the accepted extent.

Teach the QMP and mailbox paths to carry that tag through the lazy dynamic-capacity flow. In the add path, resolve the tag to a generic host memory backend, reject reuse of an already-mapped backend, and verify that the backend size matches the requested extent.

Store the selected backend metadata on the pending extent so a later patch can bind the accepted extent to the chosen backend when the host acknowledges the request.

---
 hw/cxl/cxl-mailbox-utils.c |  8 ----
 hw/mem/cxl_type3.c         | 77 ++++++++++++++++++++++++++++++++------
 2 files changed, 65 insertions(+), 20 deletions(-)
hw/cxl/cxl-mailbox-utils.c +0 -8
index e6e136cf44..c83b5f90d4 100644
@@ -4270,10 +4270,6 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd,
     CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
     int i, rc;
 
-    if (ct3d->dc.total_capacity_cmd) {
-        return CXL_MBOX_UNSUPPORTED;
-    }
-
     switch (in->selection_policy) {
         case CXL_EXTENT_SELECTION_POLICY_PRESCRIPTIVE: {
             /* Adding extents exceeds device's extent tracking ability. */
@@ -4361,10 +4357,6 @@ static CXLRetCode cmd_fm_initiate_dc_release(const struct cxl_cmd *cmd,
     CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
     int i, rc;
 
-    if (ct3d->dc.total_capacity_cmd) {
-        return CXL_MBOX_UNSUPPORTED;
-    }
-
     switch (in->flags & CXL_EXTENT_REMOVAL_POLICY_MASK) {
         case CXL_EXTENT_REMOVAL_POLICY_PRESCRIPTIVE: {
             CXLDCExtentList updated_list;
hw/mem/cxl_type3.c +65 -12

137 lines not on this page · raw message

Signature · 1 line
2.50.1 (Apple Git-155)
#8 lore raw

PATCH 4/9 hw/cxl: Carry backend metadata in DC extent records

In reply to Alireza Sanaee

The lazy dc-regions-total-size flow needs more than DPA and length for each pending or committed extent. Later stages need to remember which backend was selected for the extent, which fixed window owns the mapping, and which region/offset the request came from.

Extend CXLDCExtent and the helper APIs so add, copy, and release paths can carry that metadata alongside the range information. This is preparatory plumbing for the patches that map accepted extents into the fixed window and tear them down on release.

---
 hw/cxl/cxl-mailbox-utils.c  | 45 ++++++++++++++++++++++++++-----------
 hw/mem/cxl_type3.c          | 23 ++++++++++++++-----
 include/hw/cxl/cxl_device.h | 21 +++++++++++++----
 3 files changed, 67 insertions(+), 22 deletions(-)
hw/cxl/cxl-mailbox-utils.c +32 -13
index c83b5f90d4..c5427adb3a 100644
@@ -3525,20 +3525,26 @@ CXLDCRegion *cxl_find_dc_region(CXLType3Dev *ct3d, uint64_t dpa, uint64_t len)
 }
 
 void cxl_insert_extent_to_extent_list(CXLDCExtentList *list,
+                                             HostMemoryBackend *hm,
+                                             struct CXLFixedWindow *fw,
                                              uint64_t dpa,
                                              uint64_t len,
                                              uint8_t *tag,
-                                             uint16_t shared_seq)
+                                             uint16_t shared_seq,
+                                             int rid)
 {
     CXLDCExtent *extent;
 
     extent = g_new0(CXLDCExtent, 1);
+    extent->hm = hm;
+    extent->fw = fw;
     extent->start_dpa = dpa;
     extent->len = len;
     if (tag) {
         memcpy(extent->tag, tag, 0x10);
     }
     extent->shared_seq = shared_seq;
+    extent->rid = rid;
 
     QTAILQ_INSERT_TAIL(list, extent, node);
 }
@@ -3556,17 +3562,21 @@ void cxl_remove_extent_from_extent_list(CXLDCExtentList *list,
  * Return value: the extent group where the extent is inserted.
  */
 CXLDCExtentGroup *cxl_insert_extent_to_extent_group(CXLDCExtentGroup *group,
+                                                    HostMemoryBackend *host_mem,
+                                                    struct CXLFixedWindow *fw,
                                                     uint64_t dpa,
                                                     uint64_t len,
                                                     uint8_t *tag,
-                                                    uint16_t shared_seq)
+                                                    uint16_t shared_seq,
+                                                    int rid)
 {
     if (!group) {
         group = g_new0(CXLDCExtentGroup, 1);
         QTAILQ_INIT(&group->list);
     }
-    cxl_insert_extent_to_extent_list(&group->list, dpa, len,
-                                     tag, shared_seq);
+    cxl_insert_extent_to_extent_list(&group->list,
+                                     host_mem, fw, dpa, len,
+                                     tag, shared_seq, rid);
     return group;
 }
 
@@ -3747,7 +3757,9 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
         dpa = in->updated_entries[i].start_dpa;
         len = in->updated_entries[i].len;
 
-        cxl_insert_extent_to_extent_list(extent_list, dpa, len, NULL, 0);
+        cxl_insert_extent_to_extent_list(extent_list,
+                                         NULL, NULL, dpa, len,
+                                         NULL, 0, 0);
         ct3d->dc.total_extent_count += 1;
         ct3d->dc.nr_extents_accepted += 1;
         ct3_set_region_block_backed(ct3d, dpa, len);
@@ -3774,8 +3786,11 @@ static uint32_t copy_extent_list(CXLDCExtentList *dst,
     }
 
     QTAILQ_FOREACH(ent, src, node) {
-        cxl_insert_extent_to_extent_list(dst, ent->start_dpa, ent->len,
-                                         ent->tag, ent->shared_seq);
+        cxl_insert_extent_to_extent_list(dst,
+                                         ent->hm, ent->fw,
+                                         ent->start_dpa, ent->len,
+                                         ent->tag, ent->shared_seq,
+                                         ent->rid);
         cnt++;
     }
     return cnt;
@@ -3830,14 +3845,16 @@ static CXLRetCode cxl_dc_extent_release_dry_run(CXLType3Dev *ct3d,
 
                     if (len1) {
                         cxl_insert_extent_to_extent_list(updated_list,
-                                                         ent_start_dpa,
-                                                         len1, NULL, 0);
+                                                         NULL, NULL,
+                                                         ent_start_dpa, len1,
+                                                         NULL, 0, ent->rid);
                         cnt_delta++;
                     }
                     if (len2) {
                         cxl_insert_extent_to_extent_list(updated_list,
-                                                         dpa + len,
-                                                         len2, NULL, 0);
+                                                         NULL, NULL,
+                                                         dpa + len, len2,
+                                                         NULL, 0, ent->rid);
                         cnt_delta++;
                     }
 
@@ -4310,9 +4327,11 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd,
             for (i = 0; i < in->ext_count; i++) {
                 CXLDCExtentRaw *ext = &in->extents[i];
 
-                group = cxl_insert_extent_to_extent_group(group, ext->start_dpa,
+                group = cxl_insert_extent_to_extent_group(group,
+                                                          NULL, NULL,
+                                                          ext->start_dpa,
                                                           ext->len, ext->tag,
-                                                          ext->shared_seq);
+                                                          ext->shared_seq, 0);
             }
 
             cxl_extent_group_list_insert_tail(&ct3d->dc.extents_pending, group);
hw/mem/cxl_type3.c +18 -5
index 569184975f..bd32532c7a 100644
@@ -2457,11 +2457,24 @@ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path,
         memcpy(extents[i].tag, &uuid.data, 0x10);
         extents[i].shared_seq = 0;
         if (type == DC_EVENT_ADD_CAPACITY) {
-            group = cxl_insert_extent_to_extent_group(group,
-                                                      extents[i].start_dpa,
-                                                      extents[i].len,
-                                                      extents[i].tag,
-                                                      extents[i].shared_seq);
+            if (!dcd->dc.total_capacity_cmd) {
+                group = cxl_insert_extent_to_extent_group(group,
+                                                          NULL, NULL,
+                                                          extents[i].start_dpa,
+                                                          extents[i].len,
+                                                          extents[i].tag,
+                                                          extents[i].shared_seq,
+                                                          rid);
+            } else {
+                group = cxl_insert_extent_to_extent_group(group,
+                                                          dcd->dc.host_dc,
+                                                          dcd->dc.fw,
+                                                          extents[i].start_dpa,
+                                                          extents[i].len,
+                                                          extents[i].tag,
+                                                          extents[i].shared_seq,
+                                                          rid);
+            }
         }
 
         list = list->next;
include/hw/cxl/cxl_device.h +17 -4
index 630cf44e0e..a84b8ab358 100644
@@ -10,6 +10,7 @@
 #ifndef CXL_DEVICE_H
 #define CXL_DEVICE_H
 
+#include "hw/cxl/cxl.h"
 #include "hw/cxl/cxl_component.h"
 #include "hw/pci/pci_device.h"
 #include "hw/core/register.h"
@@ -643,11 +644,14 @@ typedef struct CXLDCExtentRaw {
 } QEMU_PACKED CXLDCExtentRaw;
 
 typedef struct CXLDCExtent {
+    HostMemoryBackend *hm;
+    struct CXLFixedWindow *fw;
     uint64_t start_dpa;
     uint64_t len;
     uint8_t tag[0x10];
     uint16_t shared_seq;
     uint8_t rsvd[0x6];
+    int rid;
 
     QTAILQ_ENTRY(CXLDCExtent) node;
 } CXLDCExtent;
@@ -780,6 +784,7 @@ struct CXLType3Dev {
     struct dynamic_capacity {
         HostMemoryBackend *host_dc;
         AddressSpace host_dc_as;
+        struct CXLFixedWindow *fw;
         /*
          * total_capacity is equivalent to the dynamic capability
          * memory region size.
@@ -854,18 +859,26 @@ CXLDCRegion *cxl_find_dc_region(CXLType3Dev *ct3d, uint64_t dpa, uint64_t len);
 
 void cxl_remove_extent_from_extent_list(CXLDCExtentList *list,
                                         CXLDCExtent *extent);
-void cxl_insert_extent_to_extent_list(CXLDCExtentList *list, uint64_t dpa,
-                                      uint64_t len, uint8_t *tag,
-                                      uint16_t shared_seq);
+void cxl_insert_extent_to_extent_list(CXLDCExtentList *list,
+                                      HostMemoryBackend *hm,
+                                      struct CXLFixedWindow *fw,
+                                      uint64_t dpa,
+                                      uint64_t len,
+                                      uint8_t *tag,
+                                      uint16_t shared_seq,
+                                      int rid);
 bool test_any_bits_set(const unsigned long *addr, unsigned long nr,
                        unsigned long size);
 bool cxl_extents_contains_dpa_range(CXLDCExtentList *list,
                                     uint64_t dpa, uint64_t len);
 CXLDCExtentGroup *cxl_insert_extent_to_extent_group(CXLDCExtentGroup *group,
+                                                    HostMemoryBackend *host_mem,
+                                                    struct CXLFixedWindow *fw,
                                                     uint64_t dpa,
                                                     uint64_t len,
                                                     uint8_t *tag,
-                                                    uint16_t shared_seq);
+                                                    uint16_t shared_seq,
+                                                    int rid);
 void cxl_extent_group_list_insert_tail(CXLDCExtentGroupList *list,
                                        CXLDCExtentGroup *group);
 uint32_t cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list);
Signature · 1 line
2.50.1 (Apple Git-155)
#9 lore raw

PATCH 5/9 hw/cxl: Map lazy memory backend after host acceptance

In reply to Alireza Sanaee

In the dc-regions-total-size flow, a requested extent is not backed when it is queued. It becomes usable only after the host accepts it with Add Dynamic Capacity Response.

Use that response path to look up the first pending group's metadata for each accepted extent, enable the selected host backend, and move the backend and fixed-window references onto the committed extent list. The accepted range is then marked backed just like the non-lazy path.

This wires host acceptance to the lazy backend lifecycle and leaves the fixed-window direct aliasing to the following patch.

---
 hw/cxl/cxl-mailbox-utils.c | 76 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 73 insertions(+), 3 deletions(-)
hw/cxl/cxl-mailbox-utils.c +73 -3
index c5427adb3a..cc7be6e68c 100644
@@ -3668,6 +3668,28 @@ static CXLRetCode cxl_detect_malformed_extent_list(CXLType3Dev *ct3d,
     return CXL_MBOX_SUCCESS;
 }
 
+/* Find extent details (backend, window, tag, rid) in the first pending group */
+static bool cxl_extent_find_extent_detail(CXLDCExtentGroupList *list,
+                                          uint64_t start_dpa, uint64_t len,
+                                          uint8_t *tag, HostMemoryBackend **hmb,
+                                          struct CXLFixedWindow **fw, int *rid)
+{
+    CXLDCExtent *ent;
+    CXLDCExtentGroup *group = QTAILQ_FIRST(list);
+
+    QTAILQ_FOREACH(ent, &group->list, node) {
+        if (ent->start_dpa == start_dpa && ent->len == len) {
+            *fw = ent->fw;
+            *hmb = ent->hm;
+            memcpy(tag, ent->tag, 0x10);
+            *rid = ent->rid;
+            return true;
+        }
+    }
+
+    return false;
+}
+
 static CXLRetCode cxl_dcd_add_dyn_cap_rsp_dry_run(CXLType3Dev *ct3d,
         const CXLUpdateDCExtentListInPl *in)
 {
@@ -3718,8 +3740,12 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
     CXLUpdateDCExtentListInPl *in = (void *)payload_in;
     CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
     CXLDCExtentList *extent_list = &ct3d->dc.extents;
+    struct CXLFixedWindow *fw;
+    HostMemoryBackend *hmb_dc;
+    uint8_t tag[0x10];
     uint32_t i, num;
     uint64_t dpa, len;
+    int rid;
     CXLRetCode ret;
 
     if (len_in < sizeof(*in)) {
@@ -3756,10 +3782,54 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
     for (i = 0; i < in->num_entries_updated; i++) {
         dpa = in->updated_entries[i].start_dpa;
         len = in->updated_entries[i].len;
+        if (ct3d->dc.total_capacity_cmd) {
+            bool found;
+            MemoryRegion *mr;
+
+            found = cxl_extent_find_extent_detail(&ct3d->dc.extents_pending,
+                                                  dpa, len, tag,
+                                                  &hmb_dc, &fw, &rid);
+
+            /*
+             * Host accepted an extent where device lacks details including
+             * wrong DPA or wrong length.
+             */
+            if (!found) {
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "Could not find the extent detail for DPA 0x%"
+                              PRIx64 " LEN 0x%" PRIx64 "\n", dpa, len);
+                return CXL_MBOX_INVALID_PA;
+            }
+
+            /* The host memory backend should not be already mapped */
+            if (host_memory_backend_is_mapped(hmb_dc)) {
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "The host memory backend for DPA 0x%" PRIx64
+                              " LEN 0x%" PRIx64 " is already mapped\n",
+                              dpa, len);
+                return CXL_MBOX_INVALID_PA;
+            }
 
-        cxl_insert_extent_to_extent_list(extent_list,
-                                         NULL, NULL, dpa, len,
-                                         NULL, 0, 0);
+            mr = host_memory_backend_get_memory(hmb_dc);
+            if (!mr) {
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "Could not get memory region from "
+                              "host memory backend\n");
+                return CXL_MBOX_INVALID_PA;
+            }
+
+            memory_region_set_nonvolatile(mr, false);
+            memory_region_set_enabled(mr, true);
+            host_memory_backend_set_mapped(hmb_dc, true);
+
+            cxl_insert_extent_to_extent_list(extent_list,
+                                             hmb_dc, fw, dpa, len,
+                                             NULL, 0, rid);
+        } else {
+            cxl_insert_extent_to_extent_list(extent_list,
+                                             NULL, NULL, dpa, len,
+                                             NULL, 0, -1);
+        }
         ct3d->dc.total_extent_count += 1;
         ct3d->dc.nr_extents_accepted += 1;
         ct3_set_region_block_backed(ct3d, dpa, len);
Signature · 1 line
2.50.1 (Apple Git-155)
#10 lore raw

Re: [PATCH 5/9] hw/cxl: Map lazy memory backend after host acceptance

Quoted 21 lines · Alireza Sanaee

In the dc-regions-total-size flow, a requested extent is not backed when it is queued. It becomes usable only after the host accepts it with Add Dynamic Capacity Response.

Use that response path to look up the first pending group's metadata for each accepted extent, enable the selected host backend, and move the backend and fixed-window references onto the committed extent list. The accepted range is then marked backed just like the non-lazy path.

This wires host acceptance to the lazy backend lifecycle and leaves the fixed-window direct aliasing to the following patch.

---
 hw/cxl/cxl-mailbox-utils.c | 76 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 73 insertions(+), 3 deletions(-)
hw/cxl/cxl-mailbox-utils.c +0 -0
index c5427adb3a..cc7be6e68c 100644

[snip]

Quoted 17 lines

static CXLRetCode cxl_dcd_add_dyn_cap_rsp_dry_run(CXLType3Dev *ct3d,
const CXLUpdateDCExtentListInPl *in)
{

hw/cxl/cxl-mailbox-utils.c +4 -0
@@ -3718,8 +3740,12 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
     CXLUpdateDCExtentListInPl *in = (void *)payload_in;
     CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
     CXLDCExtentList *extent_list = &ct3d->dc.extents;
+    struct CXLFixedWindow *fw;
+    HostMemoryBackend *hmb_dc;
+    uint8_t tag[0x10];
     uint32_t i, num;
     uint64_t dpa, len;
+    int rid;
     CXLRetCode ret;
 
     if (len_in < sizeof(*in)) {

hw/cxl/cxl-mailbox-utils.c static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd, · line 3785

Quoted 4 lines
hw/cxl/cxl-mailbox-utils.c +1 -0
@@ -3756,10 +3782,54 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
     for (i = 0; i < in->num_entries_updated; i++) {
         dpa = in->updated_entries[i].start_dpa;
         len = in->updated_entries[i].len;
+        if (ct3d->dc.total_capacity_cmd) {
               memcpy(tag, in->updated_entries[i], 0x10);

hw/cxl/cxl-mailbox-utils.c static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd, · line 3792

Quoted 7 lines
hw/cxl/cxl-mailbox-utils.c +7 -0
+            bool found;
+            MemoryRegion *mr;
+
+            found = cxl_extent_find_extent_detail(&ct3d->dc.extents_pending,
+                                                  dpa, len, tag,
+                                                  &hmb_dc, &fw, &rid);
+

Btw, I'm using this patchset to test my current DCD RFC :) The main thing is I want to test having multiple extents in the same add request for the new requirements for tags on the host side. Since we can only add/remove tagged capacity at once (no incremental add/partial release), would it be possible to support that? Sorry I didn't have a look sooner

Thanks,
Anisa
--

Quoted 2 lines
hw/cxl/cxl-mailbox-utils.c +0 -0
 2.50.1 (Apple Git-155)
 
#11 lore raw

Re: [PATCH 5/9] hw/cxl: Map lazy memory backend after host acceptance

Quoted 38 lines · Anisa Su
Quoted 21 lines · Alireza Sanaee

In the dc-regions-total-size flow, a requested extent is not backed when it is queued. It becomes usable only after the host accepts it with Add Dynamic Capacity Response.

Use that response path to look up the first pending group's metadata for each accepted extent, enable the selected host backend, and move the backend and fixed-window references onto the committed extent list. The accepted range is then marked backed just like the non-lazy path.

This wires host acceptance to the lazy backend lifecycle and leaves the fixed-window direct aliasing to the following patch.

---
 hw/cxl/cxl-mailbox-utils.c | 76 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 73 insertions(+), 3 deletions(-)
hw/cxl/cxl-mailbox-utils.c +0 -0
index c5427adb3a..cc7be6e68c 100644

[snip]

Quoted 15 lines

static CXLRetCode cxl_dcd_add_dyn_cap_rsp_dry_run(CXLType3Dev *ct3d,
const CXLUpdateDCExtentListInPl *in)
{

hw/cxl/cxl-mailbox-utils.c +4 -0
@@ -3718,8 +3740,12 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
     CXLUpdateDCExtentListInPl *in = (void *)payload_in;
     CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
     CXLDCExtentList *extent_list = &ct3d->dc.extents;
+    struct CXLFixedWindow *fw;
+    HostMemoryBackend *hmb_dc;
+    uint8_t tag[0x10];
     uint32_t i, num;
     uint64_t dpa, len;
+    int rid;
     CXLRetCode ret;
 
Quoted 7 lines

hw/cxl/cxl-mailbox-utils.c static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd, · line 3785

Quoted 6 lines
hw/cxl/cxl-mailbox-utils.c +1 -0
     if (len_in < sizeof(*in)) {
@@ -3756,10 +3782,54 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
     for (i = 0; i < in->num_entries_updated; i++) {
         dpa = in->updated_entries[i].start_dpa;
         len = in->updated_entries[i].len;
+        if (ct3d->dc.total_capacity_cmd) {
               memcpy(tag, in->updated_entries[i], 0x10);

^sorry that was totally wrong lol! ignore that. but I did encounter a null tag on host side when I sent the qmp tag-based rls cmd that resolved when I changed it to prescriptive, so let me see what happened there

Quoted 18 lines

hw/cxl/cxl-mailbox-utils.c static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd, · line 3792

Quoted 7 lines
hw/cxl/cxl-mailbox-utils.c +7 -0
+            bool found;
+            MemoryRegion *mr;
+
+            found = cxl_extent_find_extent_detail(&ct3d->dc.extents_pending,
+                                                  dpa, len, tag,
+                                                  &hmb_dc, &fw, &rid);
+

Btw, I'm using this patchset to test my current DCD RFC :) The main thing is I want to test having multiple extents in the same add request for the new requirements for tags on the host side. Since we can only add/remove tagged capacity at once (no incremental add/partial release), would it be possible to support that? Sorry I didn't have a look sooner

Thanks,
Anisa
--

Quoted 2 lines
hw/cxl/cxl-mailbox-utils.c +0 -0
 2.50.1 (Apple Git-155)
 
#12 lore raw

PATCH 6/9 hw/cxl: Create direct fixed-window aliases for accepted extents

In reply to Alireza Sanaee

For devices using dc-regions-total-size, the fallback read/write path still routes through host_dc_as, but accepted extents are backed by individual host memory backends rather than a single preconfigured address space. Install aliases into the owning fixed window so accepted dynamic-capacity memory is reachable through the normal CXL decoder path.

Record the non-interleaved decoder window discovered during HDM setup, reserve per-device alias slots for lazy DC extents, and create an alias from the accepted backend into that window when Add Dynamic Capacity Response commits the extent.

This is scoped to the current non-interleaved direct-mapping model and uses a small fixed pool of alias slots for now.

---
 hw/cxl/cxl-host.c           |  6 ++++
 hw/cxl/cxl-mailbox-utils.c  | 61 +++++++++++++++++++++++++++++--------
 hw/mem/cxl_type3.c          |  6 ++--
 include/hw/cxl/cxl_device.h | 18 +++++++++--
 4 files changed, 75 insertions(+), 16 deletions(-)
hw/cxl/cxl-host.c +6 -0
index 079b27133b..4647754cc9 100644
@@ -300,6 +300,7 @@ static void cxl_fmws_direct_passthrough_setup(CXLDirectPTState *state,
             offset = state->dpa_base - vmr_size;
         }
     }
+
     if (!mr) {
         return;
     }
@@ -358,10 +359,15 @@ static int cxl_fmws_direct_passthrough(Object *obj, void *opaque)
 
     /* Verify not interleaved */
     if (!cxl_cfmws_find_device(fw, state->decoder_base, false)) {
+        state->ct3d->direct_mr_enabled = false;
         return 0;
     }
+    state->ct3d->direct_mr_enabled = true;
 
     cxl_fmws_direct_passthrough_setup(state, fw);
+    state->ct3d->dc.fw = fw;
+    state->ct3d->dc.dc_decoder_window.base = state->decoder_base;
+    state->ct3d->dc.dc_decoder_window.size = state->decoder_size;
 
     return 0;
 }
hw/cxl/cxl-mailbox-utils.c +49 -12

149 lines not on this page · raw message

hw/mem/cxl_type3.c +4 -2
index bd32532c7a..e13826eb0b 100644
@@ -2464,7 +2464,8 @@ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path,
                                                           extents[i].len,
                                                           extents[i].tag,
                                                           extents[i].shared_seq,
-                                                          rid);
+                                                          rid,
+                                                          offset);
             } else {
                 group = cxl_insert_extent_to_extent_group(group,
                                                           dcd->dc.host_dc,
@@ -2473,7 +2474,8 @@ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path,
                                                           extents[i].len,
                                                           extents[i].tag,
                                                           extents[i].shared_seq,
-                                                          rid);
+                                                          rid,
+                                                          offset);
             }
         }
 
include/hw/cxl/cxl_device.h +16 -2
index a84b8ab358..1e904d7b48 100644
@@ -634,6 +634,7 @@ typedef struct CXLMemSparingWriteAttrs {
 #define CXL_MEMDEV_SOFT_SPARING_SUPPORT_FLAG    BIT(2)
 
 #define DCD_MAX_NUM_REGION 8
+#define CXL_DC_MAX_DIRECT_MR 4
 
 typedef struct CXLDCExtentRaw {
     uint64_t start_dpa;
@@ -652,6 +653,7 @@ typedef struct CXLDCExtent {
     uint16_t shared_seq;
     uint8_t rsvd[0x6];
     int rid;
+    uint64_t offset;
 
     QTAILQ_ENTRY(CXLDCExtent) node;
 } CXLDCExtent;
@@ -720,6 +722,7 @@ struct CXLType3Dev {
     /* State */
     MemoryRegion direct_mr[CXL_HDM_DECODER_COUNT];
     CXLFixedWindow *direct_mr_fw[CXL_HDM_DECODER_COUNT];
+    bool direct_mr_enabled;
     AddressSpace hostvmem_as;
     AddressSpace hostpmem_as;
     CXLComponentState cxl_cstate;
@@ -785,6 +788,14 @@ struct CXLType3Dev {
         HostMemoryBackend *host_dc;
         AddressSpace host_dc_as;
         struct CXLFixedWindow *fw;
+        uint32_t direct_mr_bitmap;
+        /*
+         * dc_decoder_window represents the CXL Decoder Window
+         */
+        struct decoder_window {
+            hwaddr base;
+            hwaddr size;
+        } dc_decoder_window;
         /*
          * total_capacity is equivalent to the dynamic capability
          * memory region size.
@@ -799,6 +810,7 @@ struct CXLType3Dev {
 
         uint8_t num_regions; /* 0-8 regions */
         CXLDCRegion regions[DCD_MAX_NUM_REGION];
+        MemoryRegion dc_direct_mr[CXL_DC_MAX_DIRECT_MR];
     } dc;
 
     struct CXLSanitizeInfo *media_op_sanitize;
@@ -866,7 +878,8 @@ void cxl_insert_extent_to_extent_list(CXLDCExtentList *list,
                                       uint64_t len,
                                       uint8_t *tag,
                                       uint16_t shared_seq,
-                                      int rid);
+                                      int rid,
+                                      uint64_t offset);
 bool test_any_bits_set(const unsigned long *addr, unsigned long nr,
                        unsigned long size);
 bool cxl_extents_contains_dpa_range(CXLDCExtentList *list,
@@ -878,7 +891,8 @@ CXLDCExtentGroup *cxl_insert_extent_to_extent_group(CXLDCExtentGroup *group,
                                                     uint64_t len,
                                                     uint8_t *tag,
                                                     uint16_t shared_seq,
-                                                    int rid);
+                                                    int rid,
+                                                    uint64_t offset);
 void cxl_extent_group_list_insert_tail(CXLDCExtentGroupList *list,
                                        CXLDCExtentGroup *group);
 uint32_t cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list);
Signature · 1 line
2.50.1 (Apple Git-155)
#13 lore raw

PATCH 7/9 hw/cxl: Add release-time teardown for direct-mapped extents

In reply to Alireza Sanaee

Consolidate teardown into the release path so all cleanup flows through a single place.

When an extent is removed, tear down any direct alias tied to it and unmap a lazy-mode tagged backend before dropping the extent record. Partial release of backend-backed extents is rejected, since those backends are tracked one-per-extent and cannot be split.

---
 hw/cxl/cxl-mailbox-utils.c  | 103 +++++++++++++++++++++++++++++-------
 hw/mem/cxl_type3.c          |  37 ++++++++++++-
 include/hw/cxl/cxl_device.h |   9 +++-
 3 files changed, 126 insertions(+), 23 deletions(-)
hw/cxl/cxl-mailbox-utils.c +84 -19
index 4684c33ba1..9853740994 100644
@@ -3532,7 +3532,8 @@ void cxl_insert_extent_to_extent_list(CXLDCExtentList *list,
                                              uint8_t *tag,
                                              uint16_t shared_seq,
                                              int rid,
-                                             uint64_t offset)
+                                             uint64_t offset,
+                                             int direct_window_idx)
 {
     CXLDCExtent *extent;
 
@@ -3547,6 +3548,7 @@ void cxl_insert_extent_to_extent_list(CXLDCExtentList *list,
     }
     extent->shared_seq = shared_seq;
     extent->rid = rid;
+    extent->direct_window_idx = direct_window_idx;
 
     QTAILQ_INSERT_TAIL(list, extent, node);
 }
@@ -3571,7 +3573,8 @@ CXLDCExtentGroup *cxl_insert_extent_to_extent_group(CXLDCExtentGroup *group,
                                                     uint8_t *tag,
                                                     uint16_t shared_seq,
                                                     int rid,
-                                                    uint64_t offset)
+                                                    uint64_t offset,
+                                                    int direct_window_idx)
 {
     if (!group) {
         group = g_new0(CXLDCExtentGroup, 1);
@@ -3579,7 +3582,8 @@ CXLDCExtentGroup *cxl_insert_extent_to_extent_group(CXLDCExtentGroup *group,
     }
     cxl_insert_extent_to_extent_list(&group->list,
                                      host_mem, fw, dpa, len,
-                                     tag, shared_seq, rid, offset);
+                                     tag, shared_seq, rid, offset,
+                                     direct_window_idx);
     return group;
 }
 
@@ -3695,6 +3699,25 @@ static bool cxl_extent_find_extent_detail(CXLDCExtentGroupList *list,
     return false;
 }
 
+static void cxl_unmap_extent_backend(CXLDCExtent *ent)
+{
+    MemoryRegion *mr;
+
+    if (!ent->hm) {
+        return;
+    }
+
+    mr = host_memory_backend_get_memory(ent->hm);
+    if (!mr) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "Could not get memory region from host memory backend\n");
+        return;
+    }
+
+    memory_region_set_enabled(mr, false);
+    host_memory_backend_set_mapped(ent->hm, false);
+}
+
 static CXLRetCode cxl_dcd_add_dyn_cap_rsp_dry_run(CXLType3Dev *ct3d,
         const CXLUpdateDCExtentListInPl *in)
 {
@@ -3856,11 +3879,12 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
 
             cxl_insert_extent_to_extent_list(extent_list,
                                              hmb_dc, fw, dpa, len,
-                                             tag, 0, rid, offset);
+                                             tag, 0, rid, offset, mr_idx);
         } else {
             cxl_insert_extent_to_extent_list(extent_list,
                                              NULL, NULL, dpa, len,
-                                             NULL, 0, -1, (uint64_t)-1);
+                                             NULL, 0, -1,
+                                             (uint64_t)-1, -1);
         }
         ct3d->dc.total_extent_count += 1;
         ct3d->dc.nr_extents_accepted += 1;
@@ -3892,7 +3916,8 @@ static uint32_t copy_extent_list(CXLDCExtentList *dst,
                                          ent->hm, ent->fw,
                                          ent->start_dpa, ent->len,
                                          ent->tag, ent->shared_seq,
-                                         ent->rid, ent->offset);
+                                         ent->rid, ent->offset,
+                                         ent->direct_window_idx);
         cnt++;
     }
     return cnt;
@@ -3900,6 +3925,7 @@ static uint32_t copy_extent_list(CXLDCExtentList *dst,
 
 static CXLRetCode cxl_dc_extent_release_dry_run(CXLType3Dev *ct3d,
         const CXLUpdateDCExtentListInPl *in, CXLDCExtentList *updated_list,
+        CXLDCExtentList *updated_removed_list,
         uint32_t *updated_list_size)
 {
     CXLDCExtent *ent, *ent_next;
@@ -3909,6 +3935,9 @@ static CXLRetCode cxl_dc_extent_release_dry_run(CXLType3Dev *ct3d,
     CXLRetCode ret = CXL_MBOX_SUCCESS;
 
     QTAILQ_INIT(updated_list);
+    if (updated_removed_list) {
+        QTAILQ_INIT(updated_removed_list);
+    }
     copy_extent_list(updated_list, &ct3d->dc.extents);
 
     for (i = 0; i < in->num_entries_updated; i++) {
@@ -3942,25 +3971,44 @@ static CXLRetCode cxl_dc_extent_release_dry_run(CXLType3Dev *ct3d,
                     }
                     len_done = ent_len - len1 - len2;
 
+                    /*
+                     * Tagged backends are mapped one-backend-per-extent.
+                     * Partial release would leave a backend-backed extent
+                     * behind without a clean backend lifecycle.
+                     */
+                    if (ent->hm && (len1 || len2)) {
+                        ret = CXL_MBOX_INVALID_INPUT;
+                        goto free_and_exit;
+                    }
+
+                    /* Cannot split extents with direct window mapping */
+                    if (ent->direct_window_idx >= 0 && (len1 || len2)) {
+                        ret = CXL_MBOX_INVALID_INPUT;
+                        goto free_and_exit;
+                    }
+
+                    if (updated_removed_list) {
+                        cxl_insert_extent_to_extent_list(
+                            updated_removed_list, ent->hm, ent->fw,
+                            ent->start_dpa, ent->len, ent->tag, ent->shared_seq,
+                            ent->rid, ent->offset, ent->direct_window_idx);
+                    }
+
                     cxl_remove_extent_from_extent_list(updated_list, ent);
                     cnt_delta--;
 
                     if (len1) {
-                        cxl_insert_extent_to_extent_list(updated_list,
-                                                         NULL, NULL,
-                                                         ent_start_dpa, len1,
-                                                         ent->tag, 0,
-                                                         ent->rid,
-                                                         ent->offset);
+                        cxl_insert_extent_to_extent_list(
+                            updated_list, NULL, NULL,
+                            ent_start_dpa, len1, ent->tag, 0,
+                            ent->rid, ent->offset, ent->direct_window_idx);
                         cnt_delta++;
                     }
                     if (len2) {
-                        cxl_insert_extent_to_extent_list(updated_list,
-                                                         NULL, NULL,
-                                                         dpa + len, len2,
-                                                         ent->tag, 0,
-                                                         ent->rid,
-                                                         ent->offset);
+                        cxl_insert_extent_to_extent_list(
+                            updated_list, NULL, NULL,
+                            dpa + len, len2, ent->tag, 0,
+                            ent->rid, ent->offset, ent->direct_window_idx);
                         cnt_delta++;
                     }
 
@@ -4002,6 +4050,7 @@ static CXLRetCode cmd_dcd_release_dyn_cap(const struct cxl_cmd *cmd,
     CXLUpdateDCExtentListInPl *in = (void *)payload_in;
     CXLType3Dev *ct3d = CXL_TYPE3(cci->d);
     CXLDCExtentList updated_list;
+    CXLDCExtentList updated_removed_list;
     CXLDCExtent *ent, *ent_next;
     uint32_t updated_list_size;
     CXLRetCode ret;
@@ -4025,11 +4074,26 @@ static CXLRetCode cmd_dcd_release_dyn_cap(const struct cxl_cmd *cmd,
     }
 
     ret = cxl_dc_extent_release_dry_run(ct3d, in, &updated_list,
+                                        &updated_removed_list,
                                         &updated_list_size);
     if (ret != CXL_MBOX_SUCCESS) {
         return ret;
     }
 
+    if (ct3d->direct_mr_enabled) {
+        /* Remove memory alias for the removed extents */
+        QTAILQ_FOREACH_SAFE(ent, &updated_removed_list, node, ent_next) {
+            cxl_remove_memory_alias(ct3d, ent->fw, ent->direct_window_idx);
+            cxl_unmap_extent_backend(ent);
+            cxl_remove_extent_from_extent_list(&updated_removed_list, ent);
+        }
+    } else {
+        QTAILQ_FOREACH_SAFE(ent, &updated_removed_list, node, ent_next) {
+            cxl_unmap_extent_backend(ent);
+            cxl_remove_extent_from_extent_list(&updated_removed_list, ent);
+        }
+    }
+
     /*
      * If the dry run release passes, the returned updated_list will
      * be the updated extent list and we just need to clear the extents
@@ -4438,7 +4502,7 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd,
                                                           ext->start_dpa,
                                                           ext->len, ext->tag,
                                                           ext->shared_seq, 0,
-                                                          (uint64_t)-1);
+                                                          (uint64_t)-1, -1);
             }
 
             cxl_extent_group_list_insert_tail(&ct3d->dc.extents_pending, group);
@@ -4520,6 +4584,7 @@ static CXLRetCode cmd_fm_initiate_dc_release(const struct cxl_cmd *cmd,
             rc = cxl_dc_extent_release_dry_run(ct3d,
                                                list,
                                                &updated_list,
+                                               NULL,
                                                &updated_list_size);
             if (rc) {
                 return rc;
hw/mem/cxl_type3.c +35 -2
index e13826eb0b..6b73d58358 100644
@@ -2465,7 +2465,8 @@ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path,
                                                           extents[i].tag,
                                                           extents[i].shared_seq,
                                                           rid,
-                                                          offset);
+                                                          offset,
+                                                          0);
             } else {
                 group = cxl_insert_extent_to_extent_group(group,
                                                           dcd->dc.host_dc,
@@ -2475,7 +2476,8 @@ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path,
                                                           extents[i].tag,
                                                           extents[i].shared_seq,
                                                           rid,
-                                                          offset);
+                                                          offset,
+                                                          0);
             }
         }
 
@@ -2541,6 +2543,37 @@ void qmp_cxl_release_dynamic_capacity(const char *path, uint16_t host_id,
     }
 }
 
+void cxl_remove_memory_alias(CXLType3Dev *dcd, struct CXLFixedWindow *fw,
+                             int hdm_id)
+{
+    MemoryRegion *mr;
+
+    if (hdm_id < 0 || hdm_id >= CXL_DC_MAX_DIRECT_MR) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "Invalid direct window index %d\n", hdm_id);
+        return;
+    }
+
+    if (dcd->dc.total_capacity_cmd > 0) {
+        mr = &dcd->dc.dc_direct_mr[hdm_id];
+    } else {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "No dynamic capacity command support, "
+                      "cannot remove memory region alias\n");
+        return;
+    }
+
+    if (!fw) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "Cannot remove memory region alias "
+                      "without a valid fixed window\n");
+        return;
+    }
+
+    memory_region_del_subregion(&fw->mr, mr);
+    dcd->dc.direct_mr_bitmap &= ~(1u << hdm_id);
+}
+
 static void ct3_class_init(ObjectClass *oc, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
include/hw/cxl/cxl_device.h +7 -2
index 1e904d7b48..42db9c7ce4 100644
@@ -654,6 +654,7 @@ typedef struct CXLDCExtent {
     uint8_t rsvd[0x6];
     int rid;
     uint64_t offset;
+    int direct_window_idx;
 
     QTAILQ_ENTRY(CXLDCExtent) node;
 } CXLDCExtent;
@@ -879,7 +880,8 @@ void cxl_insert_extent_to_extent_list(CXLDCExtentList *list,
                                       uint8_t *tag,
                                       uint16_t shared_seq,
                                       int rid,
-                                      uint64_t offset);
+                                      uint64_t offset,
+                                      int direct_window_idx);
 bool test_any_bits_set(const unsigned long *addr, unsigned long nr,
                        unsigned long size);
 bool cxl_extents_contains_dpa_range(CXLDCExtentList *list,
@@ -892,7 +894,8 @@ CXLDCExtentGroup *cxl_insert_extent_to_extent_group(CXLDCExtentGroup *group,
                                                     uint8_t *tag,
                                                     uint16_t shared_seq,
                                                     int rid,
-                                                    uint64_t offset);
+                                                    uint64_t offset,
+                                                    int direct_window_idx);
 void cxl_extent_group_list_insert_tail(CXLDCExtentGroupList *list,
                                        CXLDCExtentGroup *group);
 uint32_t cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list);
@@ -900,6 +903,8 @@ void ct3_set_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa,
                                  uint64_t len);
 void ct3_clear_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa,
                                    uint64_t len);
+void cxl_remove_memory_alias(CXLType3Dev *dcd, struct CXLFixedWindow *fw,
+                             int hdm_id);
 bool ct3_test_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa,
                                   uint64_t len);
 void cxl_assign_event_header(CXLEventRecordHdr *hdr,
Signature · 1 line
2.50.1 (Apple Git-155)
#14 lore raw

PATCH 8/9 hw/cxl: Add tag-based dynamic-capacity release support

In reply to Alireza Sanaee

Add support for the tag-based dynamic-capacity release policy via the QMP interface. The new path scans committed extents, selects those whose stored tag matches the requested UUID, and emits a Release Dynamic Capacity event for each matching range.

This is intentionally scoped to tag-driven selection. Prescriptive release handling and the underlying extent teardown stay in the existing paths.

---
 hw/mem/cxl_type3.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
hw/mem/cxl_type3.c +61 -0
index 6b73d58358..d5fa8a530a 100644
@@ -2492,6 +2492,63 @@ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path,
     cxl_create_dc_event_records_for_extents(dcd, type, extents, num_extents);
 }
 
+static void qmp_cxl_process_dynamic_capacity_tag_based(const char *path,
+        uint16_t hid, CXLDCEventType type, uint8_t rid, const char *tag,
+        CxlDynamicCapacityExtentList *records, Error **errp)
+{
+    Object *obj;
+    CXLType3Dev *dcd;
+    CXLDCExtentList *list = NULL;
+    CXLDCExtent *ent;
+    g_autofree CXLDCExtentRaw *extents = NULL;
+
+    obj = object_resolve_path_type(path, TYPE_CXL_TYPE3, NULL);
+    if (!obj) {
+        error_setg(errp, "Unable to resolve CXL type 3 device");
+        return;
+    }
+
+    dcd = CXL_TYPE3(obj);
+    if (!dcd->dc.num_regions) {
+        error_setg(errp, "No dynamic capacity support from the device");
+        return;
+    }
+
+    if (rid >= dcd->dc.num_regions) {
+        error_setg(errp, "region id is too large");
+        return;
+    }
+
+    QemuUUID uuid_req;
+    qemu_uuid_parse(tag, &uuid_req);
+
+    list = &dcd->dc.extents;
+    size_t cap = 8, n = 0;
+    extents = g_new0(CXLDCExtentRaw, cap);
+    QTAILQ_FOREACH(ent, list, node) {
+        QemuUUID uuid_ext;
+        memcpy(&uuid_ext.data, ent->tag, sizeof(ent->tag));
+        if (!qemu_uuid_is_equal(&uuid_req, &uuid_ext)) {
+            continue;
+        }
+
+        if (n == cap) {
+            cap *= 2;
+            extents = g_renew(CXLDCExtentRaw, extents, cap);
+        }
+
+        extents[n++] = (CXLDCExtentRaw){ .start_dpa = ent->start_dpa,
+                                         .len = ent->len,
+                                         .shared_seq = 0 };
+    }
+
+    if (n == 0) {
+        return;
+    }
+    extents = g_renew(CXLDCExtentRaw, extents, n);
+    cxl_create_dc_event_records_for_extents(dcd, type, extents, n);
+}
+
 void qmp_cxl_add_dynamic_capacity(const char *path, uint16_t host_id,
                                   CxlExtentSelectionPolicy sel_policy,
                                   uint8_t region, const char *tag,
@@ -2537,6 +2594,10 @@ void qmp_cxl_release_dynamic_capacity(const char *path, uint16_t host_id,
                                                       region, tag,
                                                       extents, errp);
         return;
+    case CXL_EXTENT_REMOVAL_POLICY_TAG_BASED:
+        qmp_cxl_process_dynamic_capacity_tag_based(path, host_id, type, region,
+                                                   tag, extents, errp);
+        return;
     default:
         error_setg(errp, "Removal policy not supported");
         return;
Signature · 1 line
2.50.1 (Apple Git-155)
#15 lore raw

Re: [PATCH 8/9] hw/cxl: Add tag-based dynamic-capacity release support

Quoted 59 lines · Alireza Sanaee

Add support for the tag-based dynamic-capacity release policy via the QMP interface. The new path scans committed extents, selects those whose stored tag matches the requested UUID, and emits a Release Dynamic Capacity event for each matching range.

This is intentionally scoped to tag-driven selection. Prescriptive release handling and the underlying extent teardown stay in the existing paths.

---
 hw/mem/cxl_type3.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
hw/mem/cxl_type3.c +38 -0
index 6b73d58358..d5fa8a530a 100644
@@ -2492,6 +2492,63 @@ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path,
     cxl_create_dc_event_records_for_extents(dcd, type, extents, num_extents);
 }
 
+static void qmp_cxl_process_dynamic_capacity_tag_based(const char *path,
+        uint16_t hid, CXLDCEventType type, uint8_t rid, const char *tag,
+        CxlDynamicCapacityExtentList *records, Error **errp)
+{
+    Object *obj;
+    CXLType3Dev *dcd;
+    CXLDCExtentList *list = NULL;
+    CXLDCExtent *ent;
+    g_autofree CXLDCExtentRaw *extents = NULL;
+
+    obj = object_resolve_path_type(path, TYPE_CXL_TYPE3, NULL);
+    if (!obj) {
+        error_setg(errp, "Unable to resolve CXL type 3 device");
+        return;
+    }
+
+    dcd = CXL_TYPE3(obj);
+    if (!dcd->dc.num_regions) {
+        error_setg(errp, "No dynamic capacity support from the device");
+        return;
+    }
+
+    if (rid >= dcd->dc.num_regions) {
+        error_setg(errp, "region id is too large");
+        return;
+    }
+
+    QemuUUID uuid_req;
+    qemu_uuid_parse(tag, &uuid_req);
+
+    list = &dcd->dc.extents;
+    size_t cap = 8, n = 0;
+    extents = g_new0(CXLDCExtentRaw, cap);
+    QTAILQ_FOREACH(ent, list, node) {
+        QemuUUID uuid_ext;
+        memcpy(&uuid_ext.data, ent->tag, sizeof(ent->tag));
+        if (!qemu_uuid_is_equal(&uuid_req, &uuid_ext)) {
+            continue;

hw/mem/cxl_type3.c static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path, · line 2542

Quoted 10 lines
hw/mem/cxl_type3.c +10 -0
+        }
+
+        if (n == cap) {
+            cap *= 2;
+            extents = g_renew(CXLDCExtentRaw, extents, cap);
+        }
+
+        extents[n++] = (CXLDCExtentRaw){ .start_dpa = ent->start_dpa,
+                                         .len = ent->len,
+                                         .shared_seq = 0 };
	extents[n] = (CXLDCExtentRaw){ .start_dpa = ent->start_dpa,
                                       .len = ent->len,
                                       .shared_seq = 0 };
        memcpy(extents[n].tag, uuid_ext.data, 0x10);
        n++;

That should fix the issue I was talking about earlier in the other thread haha (I tested it this time)

Quoted 26 lines
hw/mem/cxl_type3.c +13 -0
+    }
+
+    if (n == 0) {
+        return;
+    }
+    extents = g_renew(CXLDCExtentRaw, extents, n);
+    cxl_create_dc_event_records_for_extents(dcd, type, extents, n);
+}
+
 void qmp_cxl_add_dynamic_capacity(const char *path, uint16_t host_id,
                                   CxlExtentSelectionPolicy sel_policy,
                                   uint8_t region, const char *tag,
@@ -2537,6 +2594,10 @@ void qmp_cxl_release_dynamic_capacity(const char *path, uint16_t host_id,
                                                       region, tag,
                                                       extents, errp);
         return;
+    case CXL_EXTENT_REMOVAL_POLICY_TAG_BASED:
+        qmp_cxl_process_dynamic_capacity_tag_based(path, host_id, type, region,
+                                                   tag, extents, errp);
+        return;
     default:
         error_setg(errp, "Removal policy not supported");
         return;
Signature · 1 line
2.50.1 (Apple Git-155)
#16 lore raw

Re: [PATCH 8/9] hw/cxl: Add tag-based dynamic-capacity release support

On Mon, 30 Mar 2026 11:03:10 -0700
Anisa Su <[email protected]> wrote:

Hi Anisa,

Thanks for testing. I will make this change and send a new version then.

Quoted 105 lines · Alireza Sanaee
Quoted 59 lines

Add support for the tag-based dynamic-capacity release policy via the QMP interface. The new path scans committed extents, selects those whose stored tag matches the requested UUID, and emits a Release Dynamic Capacity event for each matching range.

This is intentionally scoped to tag-driven selection. Prescriptive release handling and the underlying extent teardown stay in the existing paths.

---
 hw/mem/cxl_type3.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
hw/mem/cxl_type3.c +38 -0
index 6b73d58358..d5fa8a530a 100644
@@ -2492,6 +2492,63 @@ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path,
     cxl_create_dc_event_records_for_extents(dcd, type, extents, num_extents);
 }
 
+static void qmp_cxl_process_dynamic_capacity_tag_based(const char *path,
+        uint16_t hid, CXLDCEventType type, uint8_t rid, const char *tag,
+        CxlDynamicCapacityExtentList *records, Error **errp)
+{
+    Object *obj;
+    CXLType3Dev *dcd;
+    CXLDCExtentList *list = NULL;
+    CXLDCExtent *ent;
+    g_autofree CXLDCExtentRaw *extents = NULL;
+
+    obj = object_resolve_path_type(path, TYPE_CXL_TYPE3, NULL);
+    if (!obj) {
+        error_setg(errp, "Unable to resolve CXL type 3 device");
+        return;
+    }
+
+    dcd = CXL_TYPE3(obj);
+    if (!dcd->dc.num_regions) {
+        error_setg(errp, "No dynamic capacity support from the device");
+        return;
+    }
+
+    if (rid >= dcd->dc.num_regions) {
+        error_setg(errp, "region id is too large");
+        return;
+    }
+
+    QemuUUID uuid_req;
+    qemu_uuid_parse(tag, &uuid_req);
+
+    list = &dcd->dc.extents;
+    size_t cap = 8, n = 0;
+    extents = g_new0(CXLDCExtentRaw, cap);
+    QTAILQ_FOREACH(ent, list, node) {
+        QemuUUID uuid_ext;
+        memcpy(&uuid_ext.data, ent->tag, sizeof(ent->tag));
+        if (!qemu_uuid_is_equal(&uuid_req, &uuid_ext)) {
+            continue;

hw/mem/cxl_type3.c static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path, · line 2542

Quoted 10 lines
hw/mem/cxl_type3.c +10 -0
+        }
+
+        if (n == cap) {
+            cap *= 2;
+            extents = g_renew(CXLDCExtentRaw, extents, cap);
+        }
+
+        extents[n++] = (CXLDCExtentRaw){ .start_dpa = ent->start_dpa,
+                                         .len = ent->len,
+                                         .shared_seq = 0 };  
	extents[n] = (CXLDCExtentRaw){ .start_dpa = ent->start_dpa,
                                       .len = ent->len,
                                       .shared_seq = 0 };
        memcpy(extents[n].tag, uuid_ext.data, 0x10);
        n++;

That should fix the issue I was talking about earlier in the other thread haha (I tested it this time)

Quoted 26 lines
hw/mem/cxl_type3.c +13 -0
+    }
+
+    if (n == 0) {
+        return;
+    }
+    extents = g_renew(CXLDCExtentRaw, extents, n);
+    cxl_create_dc_event_records_for_extents(dcd, type, extents, n);
+}
+
 void qmp_cxl_add_dynamic_capacity(const char *path, uint16_t host_id,
                                   CxlExtentSelectionPolicy sel_policy,
                                   uint8_t region, const char *tag,
@@ -2537,6 +2594,10 @@ void qmp_cxl_release_dynamic_capacity(const char *path, uint16_t host_id,
                                                       region, tag,
                                                       extents, errp);
         return;
+    case CXL_EXTENT_REMOVAL_POLICY_TAG_BASED:
+        qmp_cxl_process_dynamic_capacity_tag_based(path, host_id, type, region,
+                                                   tag, extents, errp);
+        return;
     default:
         error_setg(errp, "Removal policy not supported");
         return;
Signature · 1 line
2.50.1 (Apple Git-155)
#17 lore raw

PATCH 9/9 hw/cxl: Add QMP status query for dynamic-capacity extent release

In reply to Alireza Sanaee

Add a small status query so orchestration layers can check whether a tagged extent is still pending, committed, or no longer present after a release request.

Introduce the ExtentStatus QAPI struct and the
cxl-release-dynamic-capacity-status command.

---
 hw/mem/cxl_type3.c       | 85 ++++++++++++++++++++++++++++++++++++++++
 hw/mem/cxl_type3_stubs.c | 10 +++++
 qapi/cxl.json            | 46 ++++++++++++++++++++++
 3 files changed, 141 insertions(+)
hw/mem/cxl_type3.c +85 -0
index d5fa8a530a..8999b36e61 100644
@@ -2635,6 +2635,91 @@ void cxl_remove_memory_alias(CXLType3Dev *dcd, struct CXLFixedWindow *fw,
     dcd->dc.direct_mr_bitmap &= ~(1u << hdm_id);
 }
 
+/*
+ * This function allows for a simple check to make sure that
+ * our extent is removed. It can be used by an orchestration layer.
+ */
+ExtentStatus *
+qmp_cxl_release_dynamic_capacity_status(const char *path,
+                                        uint16_t hid, uint8_t rid,
+                                        const char *tag,
+                                        Error **errp)
+{
+    Object *obj;
+    CXLType3Dev *dcd;
+    CXLDCExtentList *list = NULL;
+    CXLDCExtent *ent;
+    QemuUUID uuid_req;
+    ExtentStatus *res;
+
+    obj = object_resolve_path_type(path, TYPE_CXL_TYPE3, NULL);
+    if (!obj) {
+        error_setg(errp, "Unable to resolve CXL type 3 device");
+        return NULL;
+    }
+
+    dcd = CXL_TYPE3(obj);
+    if (!dcd->dc.num_regions) {
+        error_setg(errp, "No dynamic capacity support from the device");
+        return NULL;
+    }
+
+    if (rid >= dcd->dc.num_regions) {
+        error_setg(errp, "Region id is too large");
+        return NULL;
+    }
+
+    if (!tag) {
+        error_setg(errp, "Tag must be valid");
+        return NULL;
+    }
+
+    list = &dcd->dc.extents;
+    qemu_uuid_parse(tag, &uuid_req);
+    res = g_new0(ExtentStatus, 1);
+
+    /* Check committed extents */
+    QTAILQ_FOREACH(ent, list, node) {
+        QemuUUID uuid_ext;
+        g_autofree char *uuid_str = NULL;
+        memcpy(&uuid_ext.data, ent->tag, sizeof(ent->tag));
+        if (qemu_uuid_is_equal(&uuid_req, &uuid_ext)) {
+            uuid_str = qemu_uuid_unparse_strdup(&uuid_ext);
+            res->status = g_strdup("Committed");
+            res->message =
+                g_strdup_printf("Found committed extent with tag %s dpa 0x%"
+                                PRIx64 " len 0x%" PRIx64,
+                                uuid_str, ent->start_dpa, ent->len);
+            return res;
+        }
+    }
+
+    /* Check pending extents (not yet committed by kernel) */
+    {
+        CXLDCExtentGroup *group;
+        QTAILQ_FOREACH(group, &dcd->dc.extents_pending, node) {
+            QTAILQ_FOREACH(ent, &group->list, node) {
+                QemuUUID uuid_ext;
+                g_autofree char *uuid_str = NULL;
+                memcpy(&uuid_ext.data, ent->tag, sizeof(ent->tag));
+                if (qemu_uuid_is_equal(&uuid_req, &uuid_ext)) {
+                    uuid_str = qemu_uuid_unparse_strdup(&uuid_ext);
+                    res->status = g_strdup("Pending");
+                    res->message =
+                        g_strdup_printf("Found pending extent with tag %s"
+                                        " dpa 0x%" PRIx64 " len 0x%" PRIx64,
+                                        uuid_str, ent->start_dpa, ent->len);
+                    return res;
+                }
+            }
+        }
+    }
+
+    res->status = g_strdup("Released");
+    res->message = g_strdup_printf("Tag %s released or not found", tag);
+    return res;
+}
+
 static void ct3_class_init(ObjectClass *oc, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
hw/mem/cxl_type3_stubs.c +10 -0
index 98292a931c..17f9414142 100644
@@ -127,3 +127,13 @@ void qmp_cxl_release_dynamic_capacity(const char *path, uint16_t host_id,
 {
     error_setg(errp, "CXL Type 3 support is not compiled in");
 }
+
+ExtentStatus *qmp_cxl_release_dynamic_capacity_status(const char *path,
+                                                      uint16_t host_id,
+                                                      uint8_t region,
+                                                      const char *tag,
+                                                      Error **errp)
+{
+    error_setg(errp, "CXL Type 3 support is not compiled in");
+    return NULL;
+}
qapi/cxl.json +46 -0

49 lines not on this page · raw message

Signature · 1 line
2.50.1 (Apple Git-155)
#18 lore raw

Re: [PATCH 9/9] hw/cxl: Add QMP status query for dynamic-capacity extent release

I'm a near-complete CXL ignoramus, and beg your patience.

Quoted 3 lines · Alireza Sanaee

Add a small status query so orchestration layers can check whether a tagged extent is still pending, committed, or no longer present after a release request.

Why would they want to check?

What is a "release request"?

Quoted 5 lines

Introduce the ExtentStatus QAPI struct and the
cxl-release-dynamic-capacity-status command.

[...]

qapi/cxl.json line 641

Quoted 11 lines
qapi/cxl.json +3 -0
index 81d6198ba0..53325ba530 100644
@@ -636,3 +636,49 @@
            },
   'features': [ 'unstable' ]
 }
+
+##
+# @ExtentStatus:

Blank line here, please.

qapi/cxl.json line 644

Quoted 3 lines
qapi/cxl.json +3 -0
+# This is an object that describes the status of an extent.
+#
+# @status:   String indicating the overall result, e.g. "success".

What are the possible values? Are they defined in some spec?

qapi/cxl.json line 645

Quoted 1 line
qapi/cxl.json +1 -0
+# @message:  Human-readable description of the outcome.

Intended use?

qapi/cxl.json line 647

Quoted 2 lines
qapi/cxl.json +2 -0
+#
+# Since: 9.1

11.1 most likely.

qapi/cxl.json line 656

Quoted 9 lines
qapi/cxl.json +9 -0
+##
+{ 'struct': 'ExtentStatus',
+      'data': { 'status': 'str', 'message': 'str' }
+}
+
+##
+# @cxl-release-dynamic-capacity-status:
+#
+# This commands checks if an extent tag has been released or not.

Use imperative mood to describe commands: "Check whether an extent tag has been released."

qapi/cxl.json line 658

Quoted 2 lines
qapi/cxl.json +2 -0
+#
+# @path: path to the CXL Dynamic Capacity Device in the QOM tree.

We commonly call such members @qom-path.

qapi/cxl.json line 668

Quoted 10 lines
qapi/cxl.json +10 -0
+#
+# @host-id: The "Host ID" field as defined in Compute Express Link
+#     (CXL) Specification, Revision 3.1, Table 7-71.
+#
+# @region: The "Region Number" field as defined in Compute Express
+#     Link Specification, Revision 3.1, Table 7-71.  Valid range
+#     is from 0-7.
+#
+# @tag: The "Tag" field as defined in Compute Express Link (CXL)
+#     Specification, Revision 3.1, Table 7-71.

I guess the command interrogates something called "extent", and the something is related to the CXL device at @path in the QOM tree. Correct?

How is it related? Is it a part of the device?

I further guess multiple extends can be so related, and @host-id, @region, and @tag identify select the one we want to interrogate. Correct?

qapi/cxl.json line 672

Quoted 4 lines
qapi/cxl.json +4 -0
+#
+# Features:
+#
+# @unstable: For now this command is subject to change.

The conventional language is "This command is experimental."

qapi/cxl.json line 674

Quoted 2 lines
qapi/cxl.json +2 -0
+#
+# Since: 9.1

11.1 most likely.

qapi/cxl.json line 683

Quoted 9 lines
qapi/cxl.json +9 -0
+##
+{ 'command': 'cxl-release-dynamic-capacity-status',
+  'data': { 'path': 'str',
+            'host-id': 'uint16',
+            'region': 'uint8',
+            'tag': 'str'
+          },
+  'features': [ 'unstable' ],
+  'returns': 'ExtentStatus'

Swap these two lines, please.

Quoted 1 line
qapi/cxl.json +1 -0
+}
#19 lore raw

Re: [PATCH 9/9] hw/cxl: Add QMP status query for dynamic-capacity extent release

On Thu, 26 Mar 2026 16:15:40 +0100
Markus Armbruster <[email protected]> wrote:

Hi Markus,

This commit adds a test command to check whether an extent (a piece of memory region) has been released or not by the guest. The process of removal is highly asynchronous, that's why I needed to add a new command to check it.

I would be happy to drop this patch, as this is extra.

Thanks,
Ali

Quoted 115 lines

I'm a near-complete CXL ignoramus, and beg your patience.

Quoted 3 lines · Alireza Sanaee

Add a small status query so orchestration layers can check whether a tagged extent is still pending, committed, or no longer present after a release request.

Why would they want to check?

What is a "release request"?

Quoted 5 lines

Introduce the ExtentStatus QAPI struct and the
cxl-release-dynamic-capacity-status command.

[...]

qapi/cxl.json line 641

Quoted 11 lines
qapi/cxl.json +3 -0
index 81d6198ba0..53325ba530 100644
@@ -636,3 +636,49 @@
            },
   'features': [ 'unstable' ]
 }
+
+##
+# @ExtentStatus:  

Blank line here, please.

qapi/cxl.json line 644

Quoted 3 lines
qapi/cxl.json +3 -0
+# This is an object that describes the status of an extent.
+#
+# @status:   String indicating the overall result, e.g. "success".  

What are the possible values? Are they defined in some spec?

qapi/cxl.json line 645

Quoted 1 line
qapi/cxl.json +1 -0
+# @message:  Human-readable description of the outcome.  

Intended use?

qapi/cxl.json line 647

Quoted 2 lines
qapi/cxl.json +2 -0
+#
+# Since: 9.1  

11.1 most likely.

qapi/cxl.json line 656

Quoted 9 lines
qapi/cxl.json +9 -0
+##
+{ 'struct': 'ExtentStatus',
+      'data': { 'status': 'str', 'message': 'str' }
+}
+
+##
+# @cxl-release-dynamic-capacity-status:
+#
+# This commands checks if an extent tag has been released or not.  

Use imperative mood to describe commands: "Check whether an extent tag has been released."

qapi/cxl.json line 658

Quoted 2 lines
qapi/cxl.json +2 -0
+#
+# @path: path to the CXL Dynamic Capacity Device in the QOM tree.  

We commonly call such members @qom-path.

qapi/cxl.json line 668

Quoted 10 lines
qapi/cxl.json +10 -0
+#
+# @host-id: The "Host ID" field as defined in Compute Express Link
+#     (CXL) Specification, Revision 3.1, Table 7-71.
+#
+# @region: The "Region Number" field as defined in Compute Express
+#     Link Specification, Revision 3.1, Table 7-71.  Valid range
+#     is from 0-7.
+#
+# @tag: The "Tag" field as defined in Compute Express Link (CXL)
+#     Specification, Revision 3.1, Table 7-71.  

I guess the command interrogates something called "extent", and the something is related to the CXL device at @path in the QOM tree. Correct?

How is it related? Is it a part of the device?

I further guess multiple extends can be so related, and @host-id, @region, and @tag identify select the one we want to interrogate. Correct?

qapi/cxl.json line 672

Quoted 4 lines
qapi/cxl.json +4 -0
+#
+# Features:
+#
+# @unstable: For now this command is subject to change.  

The conventional language is "This command is experimental."

qapi/cxl.json line 674

Quoted 2 lines
qapi/cxl.json +2 -0
+#
+# Since: 9.1  

11.1 most likely.

qapi/cxl.json line 683

Quoted 9 lines
qapi/cxl.json +9 -0
+##
+{ 'command': 'cxl-release-dynamic-capacity-status',
+  'data': { 'path': 'str',
+            'host-id': 'uint16',
+            'region': 'uint8',
+            'tag': 'str'
+          },
+  'features': [ 'unstable' ],
+  'returns': 'ExtentStatus'  

Swap these two lines, please.

Quoted 1 line
qapi/cxl.json +1 -0
+}  
#20 lore raw

Re: [PATCH 9/9] hw/cxl: Add QMP status query for dynamic-capacity extent release

Quoted 9 lines · Alireza Sanaee

On Thu, 26 Mar 2026 16:15:40 +0100
Markus Armbruster <[email protected]> wrote:

Hi Markus,

This commit adds a test command to check whether an extent (a piece of memory region) has been released or not by the guest. The process of removal is highly asynchronous, that's why I needed to add a new command to check it.

I would be happy to drop this patch, as this is extra.

So your motivation for adding the command is "just" testing. Correct?

Can you think of other uses?

In particular, would a management application need this query to monitor removal?

The description of feature @unstable may need to be adjusted for the answers we work out here.

Quoted 3 lines

Thanks,
Ali

#21 lore raw

Re: [PATCH 9/9] hw/cxl: Add QMP status query for dynamic-capacity extent release

On Sat, 28 Mar 2026 07:01:51 +0100
Markus Armbruster <[email protected]> wrote:

+CC Ira

Hi Markus,

Please look inline. I believe Ira might be able to help and we can see what he thinks.

Quoted 5 lines
Quoted 3 lines · Alireza Sanaee

On Thu, 26 Mar 2026 16:15:40 +0100
Markus Armbruster <[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines

Hi Markus,

This commit adds a test command to check whether an extent (a piece of memory region) has been released or not by the guest. The process of removal is highly asynchronous, that's why I needed to add a new command to check it.

I would be happy to drop this patch, as this is extra.

So your motivation for adding the command is "just" testing. Correct?

I wrote tests to make sure extents were released, and I used this QMP command to check.

Now there is background about extents where DCD was developed in Linux by @Ira, CCed [1].

In the DCD extent tracking section of the CXL spec, I see some commands
related to getting the extent list, maybe Ira can comment here. To be fair, knowing if an extent was released or not is a useful information in general from orchestrator perspective.

[1] https://patchew.org/linux/[email protected]/

Quoted 5 lines

Can you think of other uses?

In particular, would a management application need this query to monitor removal?

I think management will get a signal on the removal given the schema in Ira's Linux kernel patchset. I do not think this is implemented in QEMU at least (I might be missing something).

Quoted 3 lines

The description of feature @unstable may need to be adjusted for the answers we work out here.

Absolutely.

Quoted 6 lines
Quoted 4 lines

Thanks,
Ali

#22 lore raw

Re: [PATCH 9/9] hw/cxl: Add QMP status query for dynamic-capacity extent release

Quoted 16 lines · Alireza Sanaee

On Sat, 28 Mar 2026 07:01:51 +0100
Markus Armbruster <[email protected]> wrote:

+CC Ira

Hi Markus,

Please look inline. I believe Ira might be able to help and we can see what he thinks.

Quoted 7 lines
Quoted 5 lines · Alireza Sanaee

On Thu, 26 Mar 2026 16:15:40 +0100
Markus Armbruster <[email protected]> wrote:

Hi Markus,

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

This commit adds a test command to check whether an extent (a piece of memory region) has been released or not by the guest. The process of removal is highly asynchronous, that's why I needed to add a new command to check it.

I would be happy to drop this patch, as this is extra.

So your motivation for adding the command is "just" testing. Correct?

I wrote tests to make sure extents were released, and I used this QMP command to check.

As long as this is the only known use case, we want

# @unstable: This command is meant for debugging.

in the QAPI schema.

Quoted 7 lines

Now there is background about extents where DCD was developed in Linux by @Ira, CCed [1].

In the DCD extent tracking section of the CXL spec, I see some commands
related to getting the extent list, maybe Ira can comment here. To be fair, knowing if an extent was released or not is a useful information in general from orchestrator perspective.

[1] https://patchew.org/linux/[email protected]/

If we believe there are other uses, but we're unsure the command actually serves them:

# @unstable: This command is experimental.

Quoted 7 lines
Quoted 4 lines

Can you think of other uses?

In particular, would a management application need this query to monitor removal?

I think management will get a signal on the removal given the schema in Ira's Linux kernel patchset. I do not think this is implemented in QEMU at least (I might be missing something).

I'm getting a feeling of "this is underbaked" :) But that's for the CXL maintainers to judge.

Quoted 11 lines
Quoted 2 lines

The description of feature @unstable may need to be adjusted for the answers we work out here.

Absolutely.

Quoted 6 lines
Quoted 4 lines

Thanks,
Ali