From nobody Sat Nov 29 10:48:41 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1764284340; cv=none; d=zohomail.com; s=zohoarc; b=QTOv1pgWlUIX58Fo67jAqrXxqgimRFgA7aD1nG5Kh/+zqnwKEXolgj6mro6GpZJCi1zLqh5JCep51EzWXS4CvnF8S5m9tzk5C3L2gjYnhCjWxshSY0OVD26YRoofS0xyiWcKRNgAThHdTHyJI/YuMjR6dGjgCKeOPpunX5KUI5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764284340; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=x9jGExPCjWJNTTbh6XjI9AXosalck/ioYE6K0xoQCjQ=; b=Chvk/O7jkKsEW+Wnk7eRod9MRYQJyKva740/A9nOGIeLGqY9VXrcoO6HZflRBgDNBFGASOWvPnj52wgdNk0PTV53i9bzV06goKGZxxq0UkLdnEtg3xkpK7utZv9qBnWJjeQehuF7S11Enk0DzDvV/mSvIwA/zGAnVJD9MFLULgw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764284340862847.4712325716207; Thu, 27 Nov 2025 14:59:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOkwu-0005Cd-3b; Thu, 27 Nov 2025 17:58:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vOkws-0005B8-L5 for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:58:50 -0500 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vOkwq-0001qk-KQ for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:58:50 -0500 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4dHWzd5WTJzJ467f; Fri, 28 Nov 2025 06:57:49 +0800 (CST) Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207]) by mail.maildlp.com (Postfix) with ESMTPS id 59AC81404C5; Fri, 28 Nov 2025 06:58:47 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.72.83) by dubpeml500005.china.huawei.com (7.214.145.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 27 Nov 2025 22:58:46 +0000 To: CC: , , , , , , , , , Subject: [RFC PATCH 6/7] hw/cxl: Add remove alias functionality for extent direct mapping Date: Thu, 27 Nov 2025 22:55:24 +0000 Message-ID: <20251127225526.700-7-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.51.0.windows.2 In-Reply-To: <20251127225526.700-1-alireza.sanaee@huawei.com> References: <20251127225526.700-1-alireza.sanaee@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.47.72.83] X-ClientProxiedBy: lhrpeml100012.china.huawei.com (7.191.174.184) To dubpeml500005.china.huawei.com (7.214.145.207) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.176.79.56; envelope-from=alireza.sanaee@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Alireza Sanaee From: Alireza Sanaee via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1764284341142019200 Content-Type: text/plain; charset="utf-8" Remove alias related to an extent when the extent is longer available, from removed from the VM. Signed-off-by: Alireza Sanaee --- hw/cxl/cxl-mailbox-utils.c | 57 ++++++++++++++++++++++++++++++------- hw/mem/cxl_type3.c | 29 +++++++++++++++++-- include/hw/cxl/cxl_device.h | 9 ++++-- 3 files changed, 81 insertions(+), 14 deletions(-) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 15114a5314..e0ac31ac41 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -2847,7 +2847,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, + uint32_t direct_window_idx) { CXLDCExtent *extent; =20 @@ -2863,6 +2864,7 @@ void cxl_insert_extent_to_extent_list(CXLDCExtentList= *list, memcpy(extent->tag, tag, 0x10); } extent->shared_seq =3D shared_seq; + extent->direct_window_idx =3D direct_window_idx; =20 QTAILQ_INSERT_TAIL(list, extent, node); } @@ -2887,14 +2889,16 @@ CXLDCExtentGroup *cxl_insert_extent_to_extent_group= (CXLDCExtentGroup *group, uint8_t *tag, uint16_t shared_seq, int rid, - uint64_t offset) + uint64_t offset, + uint32_t direct_window= _idx) { if (!group) { group =3D g_new0(CXLDCExtentGroup, 1); QTAILQ_INIT(&group->list); } - cxl_insert_extent_to_extent_list(&group->list, host_mem, fw, dpa, len, - tag, shared_seq, rid, offset); + cxl_insert_extent_to_extent_list(&group->list, host_mem, fw, dpa, len,= tag, + shared_seq, rid, offset, + direct_window_idx); return group; } =20 @@ -3173,10 +3177,10 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const str= uct cxl_cmd *cmd, } =20 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, -1); + NULL, 0, -1, -1, -1); } =20 ct3d->dc.total_extent_count +=3D 1; @@ -3207,7 +3211,8 @@ static uint32_t copy_extent_list(CXLDCExtentList *dst, QTAILQ_FOREACH(ent, src, node) { cxl_insert_extent_to_extent_list(dst, ent->hm, ent->fw, ent->start= _dpa, ent->len, ent->tag, ent->shared_s= eq, - ent->rid, ent->offset); + ent->rid, ent->offset, + ent->direct_window_idx); cnt++; } return cnt; @@ -3215,6 +3220,7 @@ static uint32_t copy_extent_list(CXLDCExtentList *dst, =20 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; @@ -3224,6 +3230,9 @@ static CXLRetCode cxl_dc_extent_release_dry_run(CXLTy= pe3Dev *ct3d, CXLRetCode ret =3D CXL_MBOX_SUCCESS; =20 QTAILQ_INIT(updated_list); + if (updated_removed_list) { + QTAILQ_INIT(updated_removed_list); + } copy_extent_list(updated_list, &ct3d->dc.extents); =20 for (i =3D 0; i < in->num_entries_updated; i++) { @@ -3257,6 +3266,19 @@ static CXLRetCode cxl_dc_extent_release_dry_run(CXLT= ype3Dev *ct3d, } len_done =3D ent_len - len1 - len2; =20 + /* Cannot split extents with direct window mapping */ + if (ent->direct_window_idx >=3D 0 && (len1 || len2)) { + ret =3D 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->share= d_seq, + ent->rid, ent->offset, ent->direct_window_idx); + } + cxl_remove_extent_from_extent_list(updated_list, ent); cnt_delta--; =20 @@ -3264,14 +3286,16 @@ static CXLRetCode cxl_dc_extent_release_dry_run(CXL= Type3Dev *ct3d, cxl_insert_extent_to_extent_list(updated_list, NUL= L, NULL, ent_start_d= pa, len1, ent->tag, 0, - ent->rid, ent->of= fset); + ent->rid, ent->of= fset, + ent->direct_windo= w_idx); cnt_delta++; } if (len2) { cxl_insert_extent_to_extent_list(updated_list, NUL= L, NULL, dpa + len, len2, ent->tag, 0, - ent->rid, ent->of= fset); + ent->rid, ent->of= fset, + ent->direct_windo= w_idx); cnt_delta++; } =20 @@ -3313,6 +3337,7 @@ static CXLRetCode cmd_dcd_release_dyn_cap(const struc= t cxl_cmd *cmd, CXLUpdateDCExtentListInPl *in =3D (void *)payload_in; CXLType3Dev *ct3d =3D CXL_TYPE3(cci->d); CXLDCExtentList updated_list; + CXLDCExtentList updated_removed_list; CXLDCExtent *ent, *ent_next; uint32_t updated_list_size; CXLRetCode ret; @@ -3336,11 +3361,22 @@ static CXLRetCode cmd_dcd_release_dyn_cap(const str= uct cxl_cmd *cmd, } =20 ret =3D cxl_dc_extent_release_dry_run(ct3d, in, &updated_list, + &updated_removed_list, &updated_list_size); if (ret !=3D CXL_MBOX_SUCCESS) { return ret; } =20 + 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_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 @@ -3747,7 +3783,7 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct= cxl_cmd *cmd, ext->start_dpa, ext->len, ext->t= ag, ext->shared_seq,= 0, - -1); + -1, -1); } =20 cxl_extent_group_list_insert_tail(&ct3d->dc.extents_pending, g= roup); @@ -3829,6 +3865,7 @@ static CXLRetCode cmd_fm_initiate_dc_release(const st= ruct cxl_cmd *cmd, rc =3D cxl_dc_extent_release_dry_run(ct3d, list, &updated_list, + NULL, &updated_list_size); if (rc) { return rc; diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index e3093f63a3..d3ea62ef3f 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -2140,7 +2140,8 @@ static void qmp_cxl_process_dynamic_capacity_prescrip= tive(const char *path, extents[i].tag, extents[i].share= d_seq, rid, - offset); + offset, + 0); } else { group =3D cxl_insert_extent_to_extent_group(group, dcd->dc.host_dc, @@ -2150,7 +2151,8 @@ static void qmp_cxl_process_dynamic_capacity_prescrip= tive(const char *path, extents[i].tag, extents[i].share= d_seq, rid, - offset); + offset, + 0); } } =20 @@ -2216,6 +2218,29 @@ void qmp_cxl_release_dynamic_capacity(const char *pa= th, uint16_t host_id, } } =20 +void cxl_remove_memory_alias(CXLType3Dev *dcd, struct CXLFixedWindow *fw, + uint32_t hdm_id) +{ + MemoryRegion *mr; + + if (dcd->dc.total_capacity_cmd > 0) { + mr =3D &dcd->dc.dc_direct_mr[hdm_id]; + } else { + qemu_log("No dynamic capacity command support, " + "cannot remove memory region alias\n"); + return; + } + + if (!fw) { + qemu_log( + "Cannot remove memory region alias without a valid fixed windo= w\n"); + return; + } + + memory_region_del_subregion(&fw->mr, mr); + return; +} + static void ct3_class_init(ObjectClass *oc, const void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 1a521df881..c8c57ac837 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -525,6 +525,7 @@ typedef struct CXLDCExtent { uint8_t rsvd[0x6]; int rid; uint64_t offset; + int direct_window_idx; =20 QTAILQ_ENTRY(CXLDCExtent) node; } CXLDCExtent; @@ -739,7 +740,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, + uint32_t 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, @@ -752,7 +754,8 @@ CXLDCExtentGroup *cxl_insert_extent_to_extent_group(CXL= DCExtentGroup *group, uint8_t *tag, uint16_t shared_seq, int rid, - uint64_t offset); + uint64_t offset, + uint32_t direct_window= _idx); void cxl_extent_group_list_insert_tail(CXLDCExtentGroupList *list, CXLDCExtentGroup *group); uint32_t cxl_extent_group_list_delete_front(CXLDCExtentGroupList *list); @@ -773,4 +776,6 @@ bool cxl_extents_overlaps_dpa_range(CXLDCExtentList *li= st, uint64_t dpa, uint64_t len); bool cxl_extent_groups_overlaps_dpa_range(CXLDCExtentGroupList *list, uint64_t dpa, uint64_t len); +void cxl_remove_memory_alias(CXLType3Dev *dcd, struct CXLFixedWindow *fw, + uint32_t hdm_id); #endif --=20 2.43.0