From: Jonathan Cameron <jonathan.cameron@huawei.com>
To: Alireza Sanaee <alireza.sanaee@huawei.com>
Cc: <qemu-devel@nongnu.org>, <linuxarm@huawei.com>,
<eblake@redhat.com>, <armbru@redhat.com>, <berrange@redhat.com>,
<pbonzini@redhat.com>, <mst@redhat.com>, <lizhijian@fujitsu.com>,
<anisa.su@samsung.com>, <linux-cxl@vger.kernel.org>
Subject: Re: [RFC PATCH 4/7] hw/cxl: Map lazy memory backend after host acceptance
Date: Fri, 6 Feb 2026 12:33:55 +0000 [thread overview]
Message-ID: <20260206123355.00006698@huawei.com> (raw)
In-Reply-To: <20251127225526.700-5-alireza.sanaee@huawei.com>
On Thu, 27 Nov 2025 22:55:22 +0000
Alireza Sanaee <alireza.sanaee@huawei.com> wrote:
> Map relevant memory backend when host accepted an extent.
Explain what works at this point. Does the old non performant
read / write land in this memory after this patch?
We could decide not to support that, but key is the patch
should explain where we are at this point.
No comments inline.
>
> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com>
> ---
> hw/cxl/cxl-mailbox-utils.c | 74 ++++++++++++++++++++++++++++++++++++--
> 1 file changed, 71 insertions(+), 3 deletions(-)
>
> diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> index ae723c03ec..b785553225 100644
> --- a/hw/cxl/cxl-mailbox-utils.c
> +++ b/hw/cxl/cxl-mailbox-utils.c
> @@ -2979,6 +2979,30 @@ static CXLRetCode cxl_detect_malformed_extent_list(CXLType3Dev *ct3d,
> return CXL_MBOX_SUCCESS;
> }
>
> +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, *ent_next;
> + CXLDCExtentGroup *group = QTAILQ_FIRST(list);
> +
> + QTAILQ_FOREACH_SAFE(ent, &group->list, node, ent_next) {
> + 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)
> {
> @@ -3029,8 +3053,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)) {
> @@ -3065,12 +3093,52 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struct cxl_cmd *cmd,
> }
>
> for (i = 0; i < in->num_entries_updated; i++) {
> + bool found;
> + MemoryRegion *mr;
> +
> dpa = in->updated_entries[i].start_dpa;
> len = in->updated_entries[i].len;
>
> - cxl_insert_extent_to_extent_list(extent_list, NULL,
> - NULL, dpa, len,
> - NULL, 0, 0);
> + if (ct3d->dc.total_capacity_cmd) {
> + found = cxl_extent_find_extent_detail(
> + &ct3d->dc.extents_pending, dpa, len, tag, &hmb_dc, &fw, &rid);
> +
> + /*
> + * This only occurs when host accepts an extent where device does
> + * not know anything about it.
> + */
> + if (!found) {
> + qemu_log("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("The host memory backend for DPA 0x%" PRIx64
> + " LEN 0x%" PRIx64 " is already mapped\n",
> + dpa, len);
> + return CXL_MBOX_INVALID_PA;
> + }
> +
> + mr = host_memory_backend_get_memory(hmb_dc);
> + if (!mr) {
> + qemu_log("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);
next prev parent reply other threads:[~2026-02-06 12:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-27 22:55 [RFC QEMU PATCH 0/7] Application Specific Tagged Memory Support in CXL Type 3 Devices Alireza Sanaee
2025-11-27 22:55 ` [RFC PATCH 1/7] hw/mem: Add tagged memory backend object Alireza Sanaee
2026-02-06 12:16 ` Jonathan Cameron
2025-11-27 22:55 ` [RFC PATCH 2/7] hw/cxl: Allow initializing type3 device with no backing device Alireza Sanaee
2026-02-06 12:28 ` Jonathan Cameron
2025-11-27 22:55 ` [RFC PATCH 3/7] hw/cxl: Change Extent add/remove APIs for lazy memory backend Alireza Sanaee
2026-02-06 12:30 ` Jonathan Cameron
2025-11-27 22:55 ` [RFC PATCH 4/7] hw/cxl: Map lazy memory backend after host acceptance Alireza Sanaee
2026-02-06 12:33 ` Jonathan Cameron [this message]
2025-11-27 22:55 ` [RFC PATCH 5/7] hw/cxl: Add performant direct mapping for extents Alireza Sanaee
2026-02-06 12:41 ` Jonathan Cameron
2025-11-27 22:55 ` [RFC PATCH 6/7] hw/cxl: Add remove alias functionality for extent direct mapping Alireza Sanaee
2026-02-06 12:43 ` Jonathan Cameron
2025-11-27 22:55 ` [RFC PATCH 7/7] hw/cxl: Add tag-based removal functionality Alireza Sanaee
2026-02-06 12:49 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260206123355.00006698@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=alireza.sanaee@huawei.com \
--cc=anisa.su@samsung.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=lizhijian@fujitsu.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox