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=1764284383; cv=none; d=zohomail.com; s=zohoarc; b=KZLydMiR2ivUVCQ1nkMH8KKJDEVsW5zRj3v8/Ip0vPhcY9luIbmIfRULqqzo+kaFt387d3bRoPiuu4Ovyy1BREnyGV7eaIhvZvm+2dOEg90hnZTEYZoNyO9EOMCn+F9US3HgLpvmgn+zUXoY9+jgTFi8I5iC0WYUlhX3uChLxc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764284383; 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=k4C/CFq/68kQedE2TwI+evGOSHP3lQqt8n4qcdGDvz0=; b=UD885B77ShTab9aNz9ERpqsatqb2TkCXu4oad10d1iS/fYc0Ymn+OvRGlKdSQj15Z13PDgTniejOst65FD7vYHzSXFpwWr6Yeu646rkHiG96OhMRWpq1MuUM2QztATAM+AynXvXdraZio8mV/uhzZ2tFPvAxdWP4myGDTN1Zyew= 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 1764284383827741.5813459885289; Thu, 27 Nov 2025 14:59:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOkxZ-0005vJ-AK; Thu, 27 Nov 2025 17:59:33 -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 1vOkxW-0005uF-9a for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:59:30 -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 1vOkxU-0001x5-7G for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:59:30 -0500 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4dHX0Q2b8GzHnGcp; Fri, 28 Nov 2025 06:58:30 +0800 (CST) Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207]) by mail.maildlp.com (Postfix) with ESMTPS id AF1781402F1; Fri, 28 Nov 2025 06:59:19 +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:59:18 +0000 To: CC: , , , , , , , , , Subject: [RFC PATCH 7/7] hw/cxl: Add tag-based removal functionality Date: Thu, 27 Nov 2025 22:55:25 +0000 Message-ID: <20251127225526.700-8-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: 1764284385566019200 Content-Type: text/plain; charset="utf-8" Add tag based removal, in which alias tear down must be done properly. Signed-off-by: Alireza Sanaee --- hw/mem/cxl_type3.c | 119 +++++++++++++++++++++++++++++++++++++++++++++ qapi/cxl.json | 46 ++++++++++++++++++ 2 files changed, 165 insertions(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index d3ea62ef3f..29355792da 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -2186,6 +2186,61 @@ void qmp_cxl_add_dynamic_capacity(const char *path, = uint16_t host_id, } } =20 +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 =3D NULL; + CXLDCExtent *ent; + g_autofree CXLDCExtentRaw *extents =3D NULL; + + obj =3D object_resolve_path_type(path, TYPE_CXL_TYPE3, NULL); + if (!obj) { + error_setg(errp, "Unable to resolve CXL type 3 device"); + return; + } + + dcd =3D CXL_TYPE3(obj); + if (!dcd->dc.num_regions) { + error_setg(errp, "No dynamic capacity support from the device"); + return; + } + + if (rid >=3D dcd->dc.num_regions) { + error_setg(errp, "region id is too large"); + return; + } + + QemuUUID uuid_req; + qemu_uuid_parse(tag, &uuid_req); + + list =3D &dcd->dc.extents; + size_t cap =3D 8, n =3D 0; + extents =3D 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 =3D=3D cap) { + cap =3D cap < 8 ? 8 : cap * 2; + extents =3D g_renew(CXLDCExtentRaw, extents, cap); + } + + extents[n++] =3D (CXLDCExtentRaw){ .start_dpa =3D ent->start_dpa, + .len =3D ent->len, + .shared_seq =3D 0 }; + } + + extents =3D g_renew(CXLDCExtentRaw, extents, n); + cxl_create_dc_event_records_for_extents(dcd, type, extents, n); + return; +} + void qmp_cxl_release_dynamic_capacity(const char *path, uint16_t host_id, CxlExtentRemovalPolicy removal_polic= y, bool has_forced_removal, @@ -2212,6 +2267,10 @@ void qmp_cxl_release_dynamic_capacity(const char *pa= th, 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, re= gion, + tag, extents, errp); + return; default: error_setg(errp, "Removal policy not supported"); return; @@ -2241,6 +2300,66 @@ void cxl_remove_memory_alias(CXLType3Dev *dcd, struc= t CXLFixedWindow *fw, return; } =20 +/* + * 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 =3D NULL; + CXLDCExtent *ent; + QemuUUID uuid_req; + ExtentStatus *res =3D g_new0(ExtentStatus, 1); + + obj =3D object_resolve_path_type(path, TYPE_CXL_TYPE3, NULL); + if (!obj) { + error_setg(errp, "Unable to resolve CXL type 3 device"); + return NULL; + } + + dcd =3D CXL_TYPE3(obj); + if (!dcd->dc.num_regions) { + error_setg(errp, "No dynamic capacity support from the device"); + return NULL; + } + + if (rid >=3D 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 =3D &dcd->dc.extents; + qemu_uuid_parse(tag, &uuid_req); + + 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) =3D=3D true) { + res->status =3D g_strdup("Not Released"); + res->message =3D + g_strdup_printf("Found extent with tag %s dpa 0x%" PRIx64 + " len 0x%" PRIx64 "\n", + ent->tag, ent->start_dpa, ent->len); + return res; + } + } + + + res->status =3D g_strdup("Released"); + res->message =3D g_strdup_printf("Tag %s released or not found\n", tag= ); + return res; +} + static void ct3_class_init(ObjectClass *oc, const void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); diff --git a/qapi/cxl.json b/qapi/cxl.json index 52cc5d4f33..3372ce3745 100644 --- a/qapi/cxl.json +++ b/qapi/cxl.json @@ -555,3 +555,49 @@ }, 'features': [ 'unstable' ] } + +## +# @ExtentStatus: +# This is an object that describes the status of an extent. +# +# @status: String indicating the overall result, e.g. "success". +# @message: Human-readable description of the outcome. +# +# Since: 9.1 +## +{ 'struct': 'ExtentStatus', + 'data': { 'status': 'str', 'message': 'str' } +} + +## +# @cxl-release-dynamic-capacity-status: +# +# This commands checks if an extent tag has been released or not. +# +# @path: path to the CXL Dynamic Capacity Device in the QOM tree. +# +# @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. +# +# Features: +# +# @unstable: For now this command is subject to change. +# +# Since: 9.1 +## +{ 'command': 'cxl-release-dynamic-capacity-status', + 'data': { 'path': 'str', + 'host-id': 'uint16', + 'region': 'uint8', + 'tag': 'str' + }, + 'features': [ 'unstable' ], + 'returns': 'ExtentStatus' +} --=20 2.43.0