CXL: Enable FMAPI Add for MHSLDs
cover CXL: Enable FMAPI Add for MHSLDs
From: Anisa Su <[email protected]>
This patch adds support for FMAPI Initiate Add command (5604h) for MHSLDs. It is based on the following branch:
https://gitlab.com/jic23/qemu/-/tree/cxl-2025-07-03
This code was tested by starting 2 VMs, host_1, which initializes the MHSLD, and host_2, with the following topologies, then sending the FMAPI command from both hosts.
host_1 = "-device usb-ehci,id=ehci \
-object memory-backend-file,id=cxl-mem1,mem-path=/tmp/t3_cxl1.raw,size=4G \
-object memory-backend-file,id=cxl-lsa1,mem-path=/tmp/t3_lsa1.raw,size=1M \
-device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1,hdm_for_passthrough=true \
-device cxl-rp,port=0,bus=cxl.1,id=cxl_rp_port0,chassis=0,slot=2 \
-device cxl-mhsld,bus=cxl_rp_port0,num-dc-regions=2,volatile-dc-memdev=cxl-mem1,id=cxl-mhd0,sn=99,mhd-head=0,mhd-state_file=mhd_metadata,mhd-init=true \
-device usb-cxl-mctp,bus=ehci.0,id=usb0,target=cxl-mhd0\
-machine cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=1k"host_2 = "-device usb-ehci,id=ehci \
-object memory-backend-file,id=cxl-mem1,mem-path=/tmp/t3_cxl1.raw,size=4G \
-object memory-backend-file,id=cxl-lsa1,mem-path=/tmp/t3_lsa1.raw,size=1M \
-device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1,hdm_for_passthrough=true \
-device cxl-rp,port=0,bus=cxl.1,id=cxl_rp_port0,chassis=0,slot=2 \
-device cxl-mhsld,bus=cxl_rp_port0,num-dc-regions=2,volatile-dc-memdev=cxl-mem1,id=cxl-mhd0,sn=99,mhd-head=1,mhd-state_file=mhd_metadata,mhd-init=false \
-device usb-cxl-mctp,bus=ehci.0,id=usb0,target=cxl-mhd0\
-machine cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=1k"libcxlmi is cloned on both hosts and used to send the FMAPI add/release commands from both host_1 and host_2 and the expected behavior is verified by printing the response payload from the Get DC Region Lists command (5603h).
The following interactive program from libcxlmi is
used to do so: https://github.com/computexpresslink/libcxlmi/blob/main/examples/fmapi-mctp.c
Question:
Currently, the input payload to FMAPI Init Add contains an array of CXLDCExtentRaw elements. The mshld_reserve_extents() function expects a pointer of type CxlDynamicCapacityExtentList, so a loop is introduced to convert CXLDCExtentRaw[] to CxlDynamicCapacityExtentList.
I am wondering why the typedefs for extents/extent list in qapi-types-cxl.h are separate from the typedefs in cxl_device.h? Is there a nice way to avoid introducing a loop here just to convert types here?
Anisa Su (1):
hw/cxl/cxl-mailbox-utils: Enable FMAPI Initiate Add for MHSLD
hw/cxl/cxl-mailbox-utils.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
Signature · 1 line
2.51.0
PATCH 1/1 hw/cxl/cxl-mailbox-utils: Enable FMAPI Initiate Add for MHSLD
From: Anisa Su <[email protected]>
Call mhd_reserve_extents in FMAPI Init Add (5604h)to enable sending FMAPI Add command to MHSLD.
--- hw/cxl/cxl-mailbox-utils.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
hw/cxl/cxl-mailbox-utils.c +25 -0
@@ -24,6 +24,7 @@#include "system/hostmem.h" #include "qemu/range.h" #include "qapi/qapi-types-cxl.h" +#include "hw/cxl/mhsld/mhsld.h" #define CXL_CAPACITY_MULTIPLIER (256 * MiB)#define CXL_DC_EVENT_LOG_SIZE 8
@@ -4163,6 +4164,8 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd,CXLDCExtentRaw extents[]; }QEMU_PACKED *in = (void *)payload_in;CXLType3Dev *ct3d =CXL_TYPE3 (cci->d); +CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d); +CXLDCRegion *region = &ct3d->dc.regions[in->reg_num];int i, rc;switch (in->selection_policy) {
@@ -4201,6 +4204,28 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd,return rc; } +/* If this is an MHD, attempt to reserve the extents */ +if (cvc->mhd_reserve_extents) { + g_autofree CxlDynamicCapacityExtentList *records = +g_malloc0 (in->ext_count *sizeof (*records)); + g_autofree CxlDynamicCapacityExtent *dc_exts = +g_malloc0 (in->ext_count *sizeof (*dc_exts)); + +for (i =0 ; i < in->ext_count; i++) { +CxlDynamicCapacityExtent *value = &dc_exts[i]; + value->offset = + in->extents[i].start_dpa - region->base; + value->len = in->extents[i].len; + + records[i].value = value; + records[i].next = &records[i +1 ]; + } + records[in->ext_count -1 ].next =NULL ; +if (!cvc->mhd_reserve_extents (&ct3d->parent_obj, records, in->reg_num)) { +return CXL_MBOX_INVALID_INPUT ; + } + } +CXLDCExtentGroup *group =NULL ;for (i =0 ; i < in->ext_count; i++) {CXLDCExtentRaw *ext = &in->extents[i];
Signature · 1 line
2.51.0
Re: [QEMU PATCH 1/1] hw/cxl/cxl-mailbox-utils: Enable FMAPI Initiate Add for MHSLD
Quoted 6 lines · On Sat, 27 Sep 2025 00:18:07 +0000 [email protected] wrote:
From: Anisa Su <[email protected]>
Call
mhd_reserve_extentsin FMAPI Init Add (5604h)to enable sending FMAPI Add command to MHSLD.Signed-off-by Anisa Su <[email protected]>
Hi Anisa,
I've not been quick on this one partly because it sits on top of the MHSLD work that I think needs a proper revisit to establish what is an up streamable path, but I haven't had time to do that :(
Anyhow in meantime I'll take a look. I suppose nothing stops me carrying this on top.
Just one minor comment inline.
Quoted 26 lines
--- hw/cxl/cxl-mailbox-utils.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)hw/cxl/cxl-mailbox-utils.c +3
-0@@ -24,6 +24,7 @@#include "system/hostmem.h" #include "qemu/range.h" #include "qapi/qapi-types-cxl.h" +#include "hw/cxl/mhsld/mhsld.h" #define CXL_CAPACITY_MULTIPLIER (256 * MiB)#define CXL_DC_EVENT_LOG_SIZE 8@@ -4163,6 +4164,8 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd,CXLDCExtentRaw extents[]; }QEMU_PACKED *in = (void *)payload_in;CXLType3Dev *ct3d =CXL_TYPE3 (cci->d); +CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d); +CXLDCRegion *region = &ct3d->dc.regions[in->reg_num];int i, rc;switch (in->selection_policy) {
hw/cxl/cxl-mailbox-utils.c static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd, · line 4210
Quoted 7 lines
hw/cxl/cxl-mailbox-utils.c +4
-0@@ -4201,6 +4204,28 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd,return rc; } +/* If this is an MHD, attempt to reserve the extents */ +if (cvc->mhd_reserve_extents) { + g_autofree CxlDynamicCapacityExtentList *records = +g_malloc0 (in->ext_count *sizeof (*records));
I think it makes sense to use g_malloc0_n for these
I changed this whilst applying it locally so it'll be there next time I push out a tree.
Thanks,
Jonathan
Quoted 21 lines
hw/cxl/cxl-mailbox-utils.c +18
-0+ g_autofree CxlDynamicCapacityExtent *dc_exts = +g_malloc0 (in->ext_count *sizeof (*dc_exts)); + +for (i =0 ; i < in->ext_count; i++) { +CxlDynamicCapacityExtent *value = &dc_exts[i]; + value->offset = + in->extents[i].start_dpa - region->base; + value->len = in->extents[i].len; + + records[i].value = value; + records[i].next = &records[i +1 ]; + } + records[in->ext_count -1 ].next =NULL ; +if (!cvc->mhd_reserve_extents (&ct3d->parent_obj, records, in->reg_num)) { +return CXL_MBOX_INVALID_INPUT ; + } + } +CXLDCExtentGroup *group =NULL ;for (i =0 ; i < in->ext_count; i++) {CXLDCExtentRaw *ext = &in->extents[i];
Re: [QEMU PATCH 1/1] hw/cxl/cxl-mailbox-utils: Enable FMAPI Initiate Add for MHSLD
Quoted 56 lines
Tue, Oct 28, 2025 at 04:21:00PM +0000, Jonathan Cameron wrote:
Quoted 6 lines · On Sat, 27 Sep 2025 00:18:07 +0000 [email protected] wrote:
From: Anisa Su <[email protected]>
Call
mhd_reserve_extentsin FMAPI Init Add (5604h)to enable sending FMAPI Add command to MHSLD.Signed-off-by Anisa Su <[email protected]>Hi Anisa,
I've not been quick on this one partly because it sits on top of the MHSLD work that I think needs a proper revisit to establish what is an up streamable path, but I haven't had time to do that :(
Anyhow in meantime I'll take a look. I suppose nothing stops me carrying this on top.
Just one minor comment inline.
Quoted 26 lines
--- hw/cxl/cxl-mailbox-utils.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)hw/cxl/cxl-mailbox-utils.c +3
-0@@ -24,6 +24,7 @@#include "system/hostmem.h" #include "qemu/range.h" #include "qapi/qapi-types-cxl.h" +#include "hw/cxl/mhsld/mhsld.h" #define CXL_CAPACITY_MULTIPLIER (256 * MiB)#define CXL_DC_EVENT_LOG_SIZE 8@@ -4163,6 +4164,8 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd,CXLDCExtentRaw extents[]; }QEMU_PACKED *in = (void *)payload_in;CXLType3Dev *ct3d =CXL_TYPE3 (cci->d); +CXLType3Class *cvc =CXL_TYPE3_GET_CLASS (ct3d); +CXLDCRegion *region = &ct3d->dc.regions[in->reg_num];int i, rc;switch (in->selection_policy) {hw/cxl/cxl-mailbox-utils.c static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd, · line 4210
Quoted 7 lines
hw/cxl/cxl-mailbox-utils.c +4
-0@@ -4201,6 +4204,28 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd,return rc; } +/* If this is an MHD, attempt to reserve the extents */ +if (cvc->mhd_reserve_extents) { + g_autofree CxlDynamicCapacityExtentList *records = +g_malloc0 (in->ext_count *sizeof (*records));I think it makes sense to use
g_malloc0_nfor these
Quoted 7 lines
I changed this whilst applying it locally so it'll be there next time I push out a tree.
Thanks,
Jonathan
Gotcha, thanks Jonathan :D
- Anisa
Quoted 23 lines
Quoted 22 lines
hw/cxl/cxl-mailbox-utils.c +18
-0+ g_autofree CxlDynamicCapacityExtent *dc_exts = +g_malloc0 (in->ext_count *sizeof (*dc_exts)); + +for (i =0 ; i < in->ext_count; i++) { +CxlDynamicCapacityExtent *value = &dc_exts[i]; + value->offset = + in->extents[i].start_dpa - region->base; + value->len = in->extents[i].len; + + records[i].value = value; + records[i].next = &records[i +1 ]; + } + records[in->ext_count -1 ].next =NULL ; +if (!cvc->mhd_reserve_extents (&ct3d->parent_obj, records, in->reg_num)) { +return CXL_MBOX_INVALID_INPUT ; + } + } +CXLDCExtentGroup *group =NULL ;for (i =0 ; i < in->ext_count; i++) {CXLDCExtentRaw *ext = &in->extents[i];