From nobody Sat Nov 29 10:19:14 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=1764284204; cv=none; d=zohomail.com; s=zohoarc; b=WbtPN3TtDZp0VTBntr9liQS/tz2ciPWTGvR5NnRlDfFF14sQ2hPLodQnIPtxoSsTsfm3TZig7GNFs51XTONTb8WvgpTJjts20MmyvCwnqe3q43CE8tfy2kj6EyjWnDKFNGhiif2aYwkYmy0iWtc9GYWripz7PacxykuCqwybWHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764284204; 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=/WrqooxE5TEj9ydqNw99xG1SyKjaMVBUqDj9oI/ibag=; b=A5EohC1ztKJ8UMehugt5CxWrHP8Ub3Vyy1fHu7bGOx9TvsXtzx/X44t0rHLM7HuU10AcRTHMOQlxkLwB+9UB/QdHP6y/UNV0PsDG+ES54fUnl3GBSOLLQ7jg5Im770OoEJC/pnI9qpoKEJ5LwC4mPqB01UiMbiX4t9Jdg4ld7DU= 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 1764284204210802.7291877777848; Thu, 27 Nov 2025 14:56:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOkuH-0001gz-Qd; Thu, 27 Nov 2025 17:56:09 -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 1vOkuG-0001gn-6r for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:56:08 -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 1vOkuE-0001V2-CM for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:56:07 -0500 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4dHWwV1VPszJ467Q; Fri, 28 Nov 2025 06:55:06 +0800 (CST) Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207]) by mail.maildlp.com (Postfix) with ESMTPS id C2D751402E9; Fri, 28 Nov 2025 06:56:03 +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:56:02 +0000 To: CC: , , , , , , , , , Subject: [RFC PATCH 1/7] hw/mem: Add tagged memory backend object Date: Thu, 27 Nov 2025 22:55:19 +0000 Message-ID: <20251127225526.700-2-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: 1764284207814019200 Content-Type: text/plain; charset="utf-8" Add a new memory-backend-tagged supports a tag property where you can find it based on tag. This is useful for scenarios where you want to add a piece of memory for a particular purpose to be passed for another device. At the moment, this only supports a ram-backed object where we add a tag to it, and it temporary. However, we are planning for a generalized approach. The plan is to have a shim object where we add a tag to it, and then it can be later linked to any BACKEND object types. Example use QMP API: { "execute": "object-add", "arguments": { "qom-type": "memory-backend-tagged", "id": "tm0", "size": 1073741824, "tag": "6be13bce-ae34-4a77-b6c3-16df975fcf1a" } } Tags are assumed to be UUID. But this is something for debate maybe. Signed-off-by: Alireza Sanaee --- hw/mem/meson.build | 1 + hw/mem/tagged_mem.c | 116 ++++++++++++++++++++++++++++++++++++ include/hw/mem/tagged_mem.h | 31 ++++++++++ qapi/qom.json | 15 +++++ 4 files changed, 163 insertions(+) create mode 100644 hw/mem/tagged_mem.c create mode 100644 include/hw/mem/tagged_mem.h diff --git a/hw/mem/meson.build b/hw/mem/meson.build index 1c1c6da24b..529d86f840 100644 --- a/hw/mem/meson.build +++ b/hw/mem/meson.build @@ -10,3 +10,4 @@ system_ss.add(when: 'CONFIG_MEM_DEVICE', if_false: files(= 'memory-device-stubs.c' system_ss.add_all(when: 'CONFIG_MEM_DEVICE', if_true: mem_ss) =20 system_ss.add(when: 'CONFIG_SPARSE_MEM', if_true: files('sparse-mem.c')) +system_ss.add(files('tagged_mem.c')) diff --git a/hw/mem/tagged_mem.c b/hw/mem/tagged_mem.c new file mode 100644 index 0000000000..27b88e845e --- /dev/null +++ b/hw/mem/tagged_mem.c @@ -0,0 +1,116 @@ +/* + * Tagged memory backend. Temporary implementation for testing purposes and + * only supports RAM based. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/mem/tagged_mem.h" +#include "qapi/error.h" +#include "qemu/module.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" +#include "qapi/error.h" +#include "qemu/log.h" +#include "qom/object.h" +#include "qom/qom-qobject.h" + +static int check_property_equals_test(Object *obj, void *opaque) +{ + Error *err =3D NULL; + struct TagSearchContext *ctx =3D opaque; + g_autofree char *value; + + if (!object_dynamic_cast(OBJECT(obj), TYPE_MEMORY_BACKEND_TAGGED)) { + return 0; + } + + value =3D object_property_get_str(obj, "tag", &err); + if (err) { + error_report_err(err); + return 0; + } + + if (strcmp(value, ctx->tag_value) =3D=3D 0) { + ctx->result =3D MEMORY_BACKEND(obj); + return 1; + } + + return 0; +} + +HostMemoryBackend *memory_backend_tagged_find_by_tag(const char *tag, + Error **errp) +{ + struct TagSearchContext ctx =3D { + .tag_value =3D tag, + .result =3D NULL, + }; + + object_child_foreach_recursive(object_get_objects_root(), + check_property_equals_test, &ctx); + + if (!ctx.result) { + qemu_log("didn't find any results!\n"); + return NULL; + } + + return ctx.result; +} + +static void tagged_mem_set_tag(Object *obj, const char *value, Error **err= p) +{ + MemoryBackendTagged *tm =3D MEMORY_BACKEND_TAGGED(obj); + g_free(tm->tag); + tm->tag =3D g_strdup(value); +} + +static char *tagged_mem_get_tag(Object *obj, Error **errp) +{ + MemoryBackendTagged *tm =3D MEMORY_BACKEND_TAGGED(obj); + return g_strdup(tm->tag); +} + +static bool ram_backend_memory_alloc(HostMemoryBackend *backend, Error **e= rrp) +{ + g_autofree char *name =3D NULL; + uint32_t ram_flags; + + if (!backend->size) { + error_setg(errp, "can't create backend with size 0"); + return false; + } + + name =3D host_memory_backend_get_name(backend); + ram_flags =3D backend->share ? RAM_SHARED : RAM_PRIVATE; + ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; + ram_flags |=3D backend->guest_memfd ? RAM_GUEST_MEMFD : 0; + return memory_region_init_ram_flags_nomigrate( + &backend->mr, OBJECT(backend), name, backend->size, ram_flags, err= p); +} + +static void memory_backend_tagged_class_init(ObjectClass *oc, const void *= data) +{ + HostMemoryBackendClass *bc =3D MEMORY_BACKEND_CLASS(oc); + + bc->alloc =3D ram_backend_memory_alloc; + object_class_property_add_str(oc, "tag", tagged_mem_get_tag, + tagged_mem_set_tag); + object_class_property_set_description(oc, "tag", + "A user-defined tag to identify this memory backend"); +} + +static const TypeInfo memory_backend_tagged_info =3D { + .name =3D TYPE_MEMORY_BACKEND_TAGGED, + .parent =3D TYPE_MEMORY_BACKEND, + .instance_size =3D sizeof(MemoryBackendTagged), + .class_init =3D memory_backend_tagged_class_init, +}; + +static void memory_backend_tagged_register_types(void) +{ + type_register_static(&memory_backend_tagged_info); +} + +type_init(memory_backend_tagged_register_types); diff --git a/include/hw/mem/tagged_mem.h b/include/hw/mem/tagged_mem.h new file mode 100644 index 0000000000..4f3b033597 --- /dev/null +++ b/include/hw/mem/tagged_mem.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Tagged Memory backend + * + * Copyright (c) 2025 Alireza Sanaee + */ +#ifndef HW_TAGGED_MEM_H +#define HW_TAGGED_MEM_H + +#include "hw/qdev-core.h" +#include "system/memory.h" +#include "system/hostmem.h" + +#define TYPE_MEMORY_BACKEND_TAGGED "memory-backend-tagged" +OBJECT_DECLARE_SIMPLE_TYPE(MemoryBackendTagged, MEMORY_BACKEND_TAGGED) + +typedef struct MemoryBackendTagged { + HostMemoryBackend parent_obj; + + char *tag; +} MemoryBackendTagged; + +struct TagSearchContext { + const char *tag_value; + HostMemoryBackend *result; +}; + +HostMemoryBackend *memory_backend_tagged_find_by_tag(const char *tag, + Error **errp); + +#endif diff --git a/qapi/qom.json b/qapi/qom.json index 830cb2ffe7..96d0184864 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -687,6 +687,19 @@ 'size': 'size', '*x-use-canonical-path-for-ramblock-id': 'bool' } } =20 +## +# @MemoryBackendTaggedProperties: +# +# Properties for objects of classes derived from memory-backend. +# +# @tag: Memory tag +# +# Since: 11.0 +## +{ 'struct': 'MemoryBackendTaggedProperties', + 'base': 'MemoryBackendProperties', + 'data': { '*tag': 'str' } } + ## # @MemoryBackendFileProperties: # @@ -1218,6 +1231,7 @@ { 'name': 'memory-backend-memfd', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram', + 'memory-backend-tagged', { 'name': 'memory-backend-shm', 'if': 'CONFIG_POSIX' }, 'pef-guest', @@ -1296,6 +1310,7 @@ 'memory-backend-memfd': { 'type': 'MemoryBackendMemfdPropertie= s', 'if': 'CONFIG_LINUX' }, 'memory-backend-ram': 'MemoryBackendProperties', + 'memory-backend-tagged': 'MemoryBackendTaggedProperties', 'memory-backend-shm': { 'type': 'MemoryBackendShmProperties', 'if': 'CONFIG_POSIX' }, 'pr-manager-helper': { 'type': 'PrManagerHelperProperties', --=20 2.43.0 From nobody Sat Nov 29 10:19:14 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=1764284216; cv=none; d=zohomail.com; s=zohoarc; b=UKTu6SmDxhIS0IR+uUOFToqHKRTVytsedFaIqSoHcyjqGJHHPOFjyoaCjzrRHG4Tl+2cd/1ZBNQEBk3htokKd7hNyRVlbBpcCqX4gIygp0zeSm0WAYKKRsuCHYHYA4lHwNvQ8l08pGhYPOpFpVgThKJxMcaGjT8foJ8uEpYcKA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764284216; 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=0XUTEy/eOo3GL9CwpSLegeFFCsqNLydtfzq1ZxIehG0=; b=UN0QY+IRILTyqy7IdjC7Haik4ma7DsyY7lElWGqnsSjGXvilky9uv2Iu50SHESoL53oa3UyAXNkK/zOl/6fpP9rwuWjrclIU2bOWxbyxWzj3PYBBcisVtd2B79CHEqTtPiof7wB3EoTx3VFla2x2f6aRlJ/fPxWoRiijdLKuPhE= 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 1764284216707808.6620431604875; Thu, 27 Nov 2025 14:56:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOkun-0001vw-4m; Thu, 27 Nov 2025 17:56:41 -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 1vOkul-0001vh-Ja for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:56:39 -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 1vOkuj-0001W6-GA for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:56:39 -0500 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4dHWxG5ZhrzHnGch; Fri, 28 Nov 2025 06:55:46 +0800 (CST) Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207]) by mail.maildlp.com (Postfix) with ESMTPS id 208491402E9; Fri, 28 Nov 2025 06:56:36 +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:56:35 +0000 To: CC: , , , , , , , , , Subject: [RFC PATCH 2/7] hw/cxl: Allow initializing type3 device with no backing device Date: Thu, 27 Nov 2025 22:55:20 +0000 Message-ID: <20251127225526.700-3-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: 1764284218841019200 Content-Type: text/plain; charset="utf-8" Allow creating a type3 device without any backing device for DC. In Dynamic Capacity scenarios, memory can show up asynchronously and it can be coming from difference resources, RAM, PMEM, FILE BACKED. For these cases, only one parameter will be needed to know total size of DC which is exposed by dc-total-regions-size. Signed-off-by: Alireza Sanaee --- hw/mem/cxl_type3.c | 157 ++++++++++++++++++++++++++---------- include/hw/cxl/cxl_device.h | 1 + 2 files changed, 115 insertions(+), 43 deletions(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 8cdb3bff7e..690b3ab658 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -30,6 +30,7 @@ #include "system/numa.h" #include "hw/cxl/cxl.h" #include "hw/pci/msix.h" +#include "hw/mem/tagged_mem.h" =20 /* type3 device private */ enum CXL_T3_MSIX_VECTOR { @@ -190,12 +191,15 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat= _table, void *priv) } =20 if (ct3d->dc.num_regions) { - if (!ct3d->dc.host_dc) { - return -EINVAL; - } - dc_mr =3D host_memory_backend_get_memory(ct3d->dc.host_dc); - if (!dc_mr) { - return -EINVAL; + /* Only check if DC is static */ + if (ct3d->dc.total_capacity_cmd =3D=3D 0) { + if (!ct3d->dc.host_dc) { + return -EINVAL; + } + dc_mr =3D host_memory_backend_get_memory(ct3d->dc.host_dc); + if (!dc_mr) { + return -EINVAL; + } } len +=3D CT3_CDAT_NUM_ENTRIES * ct3d->dc.num_regions; } @@ -216,7 +220,7 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_t= able, void *priv) cur_ent +=3D CT3_CDAT_NUM_ENTRIES; } =20 - if (dc_mr) { + if (dc_mr || ct3d->dc.total_capacity_cmd) { int i; uint64_t region_base =3D vmr_size + pmr_size; =20 @@ -651,8 +655,13 @@ static bool cxl_create_dc_regions(CXLType3Dev *ct3d, E= rror **errp) MemoryRegion *mr; uint64_t dc_size; =20 - mr =3D host_memory_backend_get_memory(ct3d->dc.host_dc); - dc_size =3D memory_region_size(mr); + if (ct3d->dc.total_capacity_cmd !=3D 0) { + dc_size =3D ct3d->dc.total_capacity_cmd; + } else { + mr =3D host_memory_backend_get_memory(ct3d->dc.host_dc); + dc_size =3D memory_region_size(mr); + } + region_len =3D DIV_ROUND_UP(dc_size, ct3d->dc.num_regions); =20 if (dc_size % (ct3d->dc.num_regions * CXL_CAPACITY_MULTIPLIER) !=3D 0)= { @@ -810,39 +819,43 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error= **errp) =20 ct3d->dc.total_capacity =3D 0; if (ct3d->dc.num_regions > 0) { - MemoryRegion *dc_mr; - char *dc_name; + if (ct3d->dc.total_capacity_cmd =3D=3D 0) { + MemoryRegion *dc_mr; + char *dc_name; =20 - if (!ct3d->dc.host_dc) { - error_setg(errp, "dynamic capacity must have a backing device"= ); - return false; - } + if (!ct3d->dc.host_dc) { + error_setg(errp, "dynamic capacity must have a backing dev= ice"); + return false; + } =20 - dc_mr =3D host_memory_backend_get_memory(ct3d->dc.host_dc); - if (!dc_mr) { - error_setg(errp, "dynamic capacity must have a backing device"= ); - return false; - } + dc_mr =3D host_memory_backend_get_memory(ct3d->dc.host_dc); + if (!dc_mr) { + error_setg(errp, "dynamic capacity must have a backing dev= ice"); + return false; + } =20 - if (host_memory_backend_is_mapped(ct3d->dc.host_dc)) { - error_setg(errp, "memory backend %s can't be used multiple tim= es.", - object_get_canonical_path_component(OBJECT(ct3d->dc.host_dc= ))); - return false; - } - /* - * Set DC regions as volatile for now, non-volatile support can - * be added in the future if needed. - */ - memory_region_set_nonvolatile(dc_mr, false); - memory_region_set_enabled(dc_mr, true); - host_memory_backend_set_mapped(ct3d->dc.host_dc, true); - if (ds->id) { - dc_name =3D g_strdup_printf("cxl-dcd-dpa-dc-space:%s", ds->id); - } else { - dc_name =3D g_strdup("cxl-dcd-dpa-dc-space"); + if (host_memory_backend_is_mapped(ct3d->dc.host_dc)) { + error_setg(errp, + "memory backend %s can't be used multiple times= .", + object_get_canonical_path_component( + OBJECT(ct3d->dc.host_dc))); + return false; + } + /* + * Set DC regions as volatile for now, non-volatile support can + * be added in the future if needed. + */ + memory_region_set_nonvolatile(dc_mr, false); + memory_region_set_enabled(dc_mr, true); + host_memory_backend_set_mapped(ct3d->dc.host_dc, true); + if (ds->id) { + dc_name =3D g_strdup_printf("cxl-dcd-dpa-dc-space:%s", ds-= >id); + } else { + dc_name =3D g_strdup("cxl-dcd-dpa-dc-space"); + } + address_space_init(&ct3d->dc.host_dc_as, dc_mr, dc_name); + g_free(dc_name); } - address_space_init(&ct3d->dc.host_dc_as, dc_mr, dc_name); - g_free(dc_name); =20 if (!cxl_create_dc_regions(ct3d, errp)) { error_append_hint(errp, "setup DC regions failed"); @@ -1284,6 +1297,8 @@ static const Property ct3_props[] =3D { DEFINE_PROP_UINT8("num-dc-regions", CXLType3Dev, dc.num_regions, 0), DEFINE_PROP_LINK("volatile-dc-memdev", CXLType3Dev, dc.host_dc, TYPE_MEMORY_BACKEND, HostMemoryBackend *), + DEFINE_PROP_SIZE("dc-regions-total-size", CXLType3Dev, + dc.total_capacity_cmd, 0), DEFINE_PROP_PCIE_LINK_SPEED("x-speed", CXLType3Dev, speed, PCIE_LINK_SPEED_32), DEFINE_PROP_PCIE_LINK_WIDTH("x-width", CXLType3Dev, @@ -1952,12 +1967,38 @@ bool cxl_extent_groups_overlaps_dpa_range(CXLDCExte= ntGroupList *list, return false; } =20 +static bool cxl_device_lazy_dynamic_capacity_init(CXLType3Dev *ct3d, + const char *tag, Error *= *errp) +{ + MemoryRegion *dc_mr; + + ct3d->dc.host_dc =3D memory_backend_tagged_find_by_tag(tag, errp); + if (!ct3d->dc.host_dc) { + error_setg(errp, "dynamic capacity must have a backing device"); + return false; + } + + dc_mr =3D host_memory_backend_get_memory(ct3d->dc.host_dc); + if (!dc_mr) { + error_setg(errp, "test dynamic capacity must have a backing device= "); + return false; + } + + if (host_memory_backend_is_mapped(ct3d->dc.host_dc)) { + qemu_log("Warning: memory backend %s is already mapped. Reusing it= .\n", + object_get_canonical_path_component(OBJECT(ct3d->dc.host_dc= ))); + return true; + } + + return true; +} + /* * The main function to process dynamic capacity event with extent list. * Currently DC extents add/release requests are processed. */ static void qmp_cxl_process_dynamic_capacity_prescriptive(const char *path, - uint16_t hid, CXLDCEventType type, uint8_t rid, + uint16_t hid, CXLDCEventType type, uint8_t rid, const char *tag, CxlDynamicCapacityExtentList *records, Error **errp) { Object *obj; @@ -1966,8 +2007,10 @@ static void qmp_cxl_process_dynamic_capacity_prescri= ptive(const char *path, CxlDynamicCapacityExtentList *list; CXLDCExtentGroup *group =3D NULL; g_autofree CXLDCExtentRaw *extents =3D NULL; - uint64_t dpa, offset, len, block_size; + uint64_t dpa, offset, block_size; + uint64_t len =3D 0; g_autofree unsigned long *blk_bitmap =3D NULL; + QemuUUID uuid; int i; =20 obj =3D object_resolve_path_type(path, TYPE_CXL_TYPE3, NULL); @@ -1996,6 +2039,7 @@ static void qmp_cxl_process_dynamic_capacity_prescrip= tive(const char *path, offset =3D list->value->offset; len =3D list->value->len; dpa =3D offset + dcd->dc.regions[rid].base; + qemu_uuid_parse(tag, &uuid); =20 if (len =3D=3D 0) { error_setg(errp, "extent with 0 length is not allowed"); @@ -2049,6 +2093,31 @@ static void qmp_cxl_process_dynamic_capacity_prescri= ptive(const char *path, num_extents++; } =20 + if (type =3D=3D DC_EVENT_ADD_CAPACITY && dcd->dc.total_capacity_cmd) { + MemoryRegion *host_dc_mr; + uint64_t size; + + if (num_extents > 1) { + error_setg(errp, "Only single extent add is supported currentl= y"); + return; + } + + if (!cxl_device_lazy_dynamic_capacity_init(dcd, tag, errp)) { + return; + } + + host_dc_mr =3D host_memory_backend_get_memory(dcd->dc.host_dc); + size =3D memory_region_size(host_dc_mr); + + if (size !=3D len) { + error_setg(errp, + "Host memory backend size 0x%" PRIx64 + " does not match extent length 0x%" PRIx64, + size, len); + return; + } + } + /* Create extent list for event being passed to host */ i =3D 0; list =3D records; @@ -2060,7 +2129,7 @@ static void qmp_cxl_process_dynamic_capacity_prescrip= tive(const char *path, =20 extents[i].start_dpa =3D dpa; extents[i].len =3D len; - memset(extents[i].tag, 0, 0x10); + memcpy(extents[i].tag, &uuid.data, 0x10); extents[i].shared_seq =3D 0; if (type =3D=3D DC_EVENT_ADD_CAPACITY) { group =3D cxl_insert_extent_to_extent_group(group, @@ -2091,7 +2160,8 @@ void qmp_cxl_add_dynamic_capacity(const char *path, u= int16_t host_id, case CXL_EXTENT_SELECTION_POLICY_PRESCRIPTIVE: qmp_cxl_process_dynamic_capacity_prescriptive(path, host_id, DC_EVENT_ADD_CAPACIT= Y, - region, extents, err= p); + region, tag, extents, + errp); return; default: error_setg(errp, "Selection policy not supported"); @@ -2122,7 +2192,8 @@ void qmp_cxl_release_dynamic_capacity(const char *pat= h, uint16_t host_id, switch (removal_policy) { case CXL_EXTENT_REMOVAL_POLICY_PRESCRIPTIVE: qmp_cxl_process_dynamic_capacity_prescriptive(path, host_id, type, - region, extents, err= p); + region, tag, extents, + errp); return; default: error_setg(errp, "Removal policy not supported"); diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 1d199d035e..bfd1a97e03 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -633,6 +633,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; --=20 2.43.0 From nobody Sat Nov 29 10:19:14 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=1764284242; cv=none; d=zohomail.com; s=zohoarc; b=HCkHvlcFoqS2FEP9+yB5dp76TMqwcqO/RZvMO7U2oz5tKh6pCducKO5AO/YAGGuDles1Fo4OWNGog+ZBxfQPd6U6QvYja3otpGN9JOxb1sMBVXfG+/g+qapRx9x7ePrs+CkLptspEFkBHhoZD4kZw/oig6OJkYbayOXPs3/3tKo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764284242; 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=D27y6jGCFg9ctkivynsEMlWl/zAQbLlrYeeCheoykD8=; b=FYLTCXjqB1J+quUV8pmq24OvHUMox5DiaQvJyrFcorFF2PXWzcyqdHVHjGlaSxbKliXPIz+uv9RVlQ0BZkmhJfxOkMgkij2GT69MZLpD1Ue3piETyf8Ox7u9eOkNYI67X66O74erkV3mG8ikvIq4+/rDx0RgA49IF8gOhqkWImA= 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 1764284242236827.2817029119743; Thu, 27 Nov 2025 14:57:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOkvK-0002zo-Kx; Thu, 27 Nov 2025 17:57:14 -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 1vOkvI-0002y4-9R for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:57:12 -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 1vOkvG-0001Y5-HN for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:57:12 -0500 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4dHWxv2Rm4zHnGcx; Fri, 28 Nov 2025 06:56:19 +0800 (CST) Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207]) by mail.maildlp.com (Postfix) with ESMTPS id A6B47140372; Fri, 28 Nov 2025 06:57:08 +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:57:07 +0000 To: CC: , , , , , , , , , Subject: [RFC PATCH 3/7] hw/cxl: Change Extent add/remove APIs for lazy memory backend. Date: Thu, 27 Nov 2025 22:55:21 +0000 Message-ID: <20251127225526.700-4-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: 1764284242630019200 Content-Type: text/plain; charset="utf-8" Add extra information in each extent about fix memory window and memory backend, because extent might be backed by different memory backends, thus such information must be stored in the extent object. Consequently, APIs should be changes to support extra members. Signed-off-by: Alireza Sanaee --- hw/cxl/cxl-host.c | 2 ++ hw/cxl/cxl-mailbox-utils.c | 42 ++++++++++++++++++++++++------------- hw/mem/cxl_type3.c | 23 +++++++++++++++----- include/hw/cxl/cxl_device.h | 17 ++++++++++++--- 4 files changed, 61 insertions(+), 23 deletions(-) diff --git a/hw/cxl/cxl-host.c b/hw/cxl/cxl-host.c index 3a563af3bc..7c8fde4646 100644 --- a/hw/cxl/cxl-host.c +++ b/hw/cxl/cxl-host.c @@ -365,6 +365,8 @@ static int cxl_fmws_direct_passthrough(Object *obj, voi= d *opaque) return 0; } =20 + ct3d->dc.fw =3D fw; + if (state->commit) { MemoryRegion *mr =3D NULL; uint64_t vmr_size =3D 0, pmr_size =3D 0; diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 68c7cc9891..ae723c03ec 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -2840,10 +2840,13 @@ CXLDCRegion *cxl_find_dc_region(CXLType3Dev *ct3d, = uint64_t dpa, uint64_t len) } =20 void cxl_insert_extent_to_extent_list(CXLDCExtentList *list, + 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) { CXLDCExtent *extent; =20 @@ -2871,17 +2874,20 @@ void cxl_remove_extent_from_extent_list(CXLDCExtent= List *list, * Return value: the extent group where the extent is inserted. */ CXLDCExtentGroup *cxl_insert_extent_to_extent_group(CXLDCExtentGroup *grou= p, + HostMemoryBackend *hos= t_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 =3D 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; } =20 @@ -3062,7 +3068,9 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struc= t cxl_cmd *cmd, dpa =3D in->updated_entries[i].start_dpa; len =3D in->updated_entries[i].len; =20 - 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 +=3D 1; ct3d->dc.nr_extents_accepted +=3D 1; ct3_set_region_block_backed(ct3d, dpa, len); @@ -3089,8 +3097,9 @@ static uint32_t copy_extent_list(CXLDCExtentList *dst, } =20 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_s= eq, + ent->rid); cnt++; } return cnt; @@ -3144,15 +3153,17 @@ static CXLRetCode cxl_dc_extent_release_dry_run(CXL= Type3Dev *ct3d, cnt_delta--; =20 if (len1) { - cxl_insert_extent_to_extent_list(updated_list, - ent_start_dpa, - len1, NULL, 0); + cxl_insert_extent_to_extent_list(updated_list, NUL= L, + NULL, ent_start_d= pa, + len1, NULL, 0, + ent->rid); cnt_delta++; } if (len2) { - cxl_insert_extent_to_extent_list(updated_list, - dpa + len, - len2, NULL, 0); + cxl_insert_extent_to_extent_list(updated_list, NUL= L, + NULL, dpa + len, + len2, NULL, 0, + ent->rid); cnt_delta++; } =20 @@ -3624,9 +3635,10 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struc= t cxl_cmd *cmd, for (i =3D 0; i < in->ext_count; i++) { CXLDCExtentRaw *ext =3D &in->extents[i]; =20 - group =3D cxl_insert_extent_to_extent_group(group, ext->st= art_dpa, + group =3D cxl_insert_extent_to_extent_group(group, NULL, N= ULL, + ext->start_dpa, ext->len, ext->t= ag, - ext->shared_seq); + ext->shared_seq,= 0); } =20 cxl_extent_group_list_insert_tail(&ct3d->dc.extents_pending, g= roup); diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 690b3ab658..ef1c1cbaef 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -2132,11 +2132,24 @@ static void qmp_cxl_process_dynamic_capacity_prescr= iptive(const char *path, memcpy(extents[i].tag, &uuid.data, 0x10); extents[i].shared_seq =3D 0; if (type =3D=3D DC_EVENT_ADD_CAPACITY) { - group =3D cxl_insert_extent_to_extent_group(group, - extents[i].start_dpa, - extents[i].len, - extents[i].tag, - extents[i].shared_se= q); + if (!dcd->dc.total_capacity_cmd) { + group =3D cxl_insert_extent_to_extent_group(group, + NULL, NULL, + extents[i].start= _dpa, + extents[i].len, + extents[i].tag, + extents[i].share= d_seq, + rid); + } else { + group =3D 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].share= d_seq, + rid); + } } =20 list =3D list->next; diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index bfd1a97e03..fe0c44e8d7 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -10,6 +10,7 @@ #ifndef CXL_DEVICE_H #define CXL_DEVICE_H =20 +#include "hw/cxl/cxl.h" #include "hw/cxl/cxl_component.h" #include "hw/pci/pci_device.h" #include "hw/register.h" @@ -515,11 +516,14 @@ typedef struct CXLDCExtentRaw { } QEMU_PACKED CXLDCExtentRaw; =20 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; =20 QTAILQ_ENTRY(CXLDCExtent) node; } CXLDCExtent; @@ -628,6 +632,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. @@ -711,18 +716,24 @@ CXLDCRegion *cxl_find_dc_region(CXLType3Dev *ct3d, ui= nt64_t dpa, uint64_t len); =20 void cxl_remove_extent_from_extent_list(CXLDCExtentList *list, CXLDCExtent *extent); -void cxl_insert_extent_to_extent_list(CXLDCExtentList *list, uint64_t dpa, +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); 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 *grou= p, + HostMemoryBackend *hos= t_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); --=20 2.43.0 From nobody Sat Nov 29 10:19:14 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=1764284276; cv=none; d=zohomail.com; s=zohoarc; b=ihjusNzPNQpq9ZK2b39qa15uOQHa5InRbMIsKR71kK9XrpA1AnPv5IB6/Lym7JojDJ4P3XOvyeBxj+K4LkBYKGdGCB4+lVjR9W5BeCdu/ZYCgUVKmmvZD12GR4f05HdfJchgwtTte+43OHzhalv6ZL1VBhTix+lXCFGWWAjaXLA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764284276; 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=KiBsOz7yOLFHFVfugKvKb/RrJUiC+66l+V164qptD98=; b=Lt4C6aH/Npyw4ibybckvdk2hx2hS4eeWD5AQ0KqmmPLwLem0tAwWv3KWvu3LaMeeUe8Y7YWvB96PCzv0xxIRL7yBAg9P3DFOFDbQ231dzCJUALdXvlno3IWGvx40XlxgsHe7jzzJuukK2rsk3lekPRp48faz7iADc6o0s9j26o0= 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 1764284276357859.2585809853673; Thu, 27 Nov 2025 14:57:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOkvq-0003mo-Jv; Thu, 27 Nov 2025 17:57:46 -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 1vOkvp-0003ma-JQ for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:57:45 -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 1vOkvn-0001ZW-Sz for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:57:45 -0500 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4dHWyY2RGbzHnGcc; Fri, 28 Nov 2025 06:56:53 +0800 (CST) Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207]) by mail.maildlp.com (Postfix) with ESMTPS id A852F1402F1; Fri, 28 Nov 2025 06:57:42 +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:57:41 +0000 To: CC: , , , , , , , , , Subject: [RFC PATCH 4/7] hw/cxl: Map lazy memory backend after host acceptance Date: Thu, 27 Nov 2025 22:55:22 +0000 Message-ID: <20251127225526.700-5-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: 1764284276700019200 Content-Type: text/plain; charset="utf-8" Map relevant memory backend when host accepted an extent. Signed-off-by: Alireza Sanaee --- 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(C= XLType3Dev *ct3d, return CXL_MBOX_SUCCESS; } =20 +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 =3D QTAILQ_FIRST(list); + + QTAILQ_FOREACH_SAFE(ent, &group->list, node, ent_next) { + if (ent->start_dpa =3D=3D start_dpa && ent->len =3D=3D len) { + *fw =3D ent->fw; + *hmb =3D ent->hm; + memcpy(tag, ent->tag, 0x10); + *rid =3D 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 stru= ct cxl_cmd *cmd, CXLUpdateDCExtentListInPl *in =3D (void *)payload_in; CXLType3Dev *ct3d =3D CXL_TYPE3(cci->d); CXLDCExtentList *extent_list =3D &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; =20 if (len_in < sizeof(*in)) { @@ -3065,12 +3093,52 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const str= uct cxl_cmd *cmd, } =20 for (i =3D 0; i < in->num_entries_updated; i++) { + bool found; + MemoryRegion *mr; + dpa =3D in->updated_entries[i].start_dpa; len =3D in->updated_entries[i].len; =20 - cxl_insert_extent_to_extent_list(extent_list, NULL, - NULL, dpa, len, - NULL, 0, 0); + if (ct3d->dc.total_capacity_cmd) { + found =3D cxl_extent_find_extent_detail( + &ct3d->dc.extents_pending, dpa, len, tag, &hmb_dc, &fw, &r= id); + + /* + * This only occurs when host accepts an extent where device d= oes + * not know anything about it. + */ + if (!found) { + qemu_log("Could not find the extent detail for DPA 0x%" PR= Ix64 + " 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 =3D 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 +=3D 1; ct3d->dc.nr_extents_accepted +=3D 1; ct3_set_region_block_backed(ct3d, dpa, len); --=20 2.43.0 From nobody Sat Nov 29 10:19:14 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=1764284306; cv=none; d=zohomail.com; s=zohoarc; b=GhZD4Vo0cf4H6Z5CQJJemOfk4KkBAzHhajpwPRBiGLlH+vi5GgJo9eb4QCxJxoPqoVRJtKmDNPeL2KME3K0dLF+3FaW+32rd6e6/t4Q/4NBb8vAchzF1R0pB6I0EjF4JFvNal26Rl/NEx1FdLD8nQLIAKgliNji6QEZkGoD0vic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764284306; 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=2+75VMdILjkKzsi0XiHtZYtbHRdb23XmWJbMhKLtBMc=; b=hTUdVHtAqtP94hb0U55dH1g43C+A99W3TwXB+2brpjN80oMf8EdD0gT17JYbs5bY5pCDvT2C4+tzZyySJQqdtodHyLT0Cau+Ah+M/9NBh9VxxJwJW/cQBH4Pps0XtdR+mZJfFkpDW+4qWpUZxZcFyzW64PI7EX+cka5VZAi0awo= 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 1764284306723918.0836428607884; Thu, 27 Nov 2025 14:58:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOkwN-0004GK-SG; Thu, 27 Nov 2025 17:58:19 -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 1vOkwM-0004Ew-5j for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:58:18 -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 1vOkwK-0001oK-8y for qemu-devel@nongnu.org; Thu, 27 Nov 2025 17:58:17 -0500 Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4dHWz94vzKzHnGcc; Fri, 28 Nov 2025 06:57:25 +0800 (CST) Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207]) by mail.maildlp.com (Postfix) with ESMTPS id 0814F1400D4; Fri, 28 Nov 2025 06:58:15 +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:14 +0000 To: CC: , , , , , , , , , Subject: [RFC PATCH 5/7] hw/cxl: Add performant direct mapping for extents Date: Thu, 27 Nov 2025 22:55:23 +0000 Message-ID: <20251127225526.700-6-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: 1764284309376019200 Content-Type: text/plain; charset="utf-8" Add alias direct mapping into the fixed memory window. Signed-off-by: Alireza Sanaee --- hw/cxl/cxl-host.c | 4 ++ hw/cxl/cxl-mailbox-utils.c | 73 +++++++++++++++++++++++++++++-------- hw/mem/cxl_type3.c | 6 ++- include/hw/cxl/cxl_device.h | 25 +++++++++++-- 4 files changed, 87 insertions(+), 21 deletions(-) diff --git a/hw/cxl/cxl-host.c b/hw/cxl/cxl-host.c index 7c8fde4646..3b327be68c 100644 --- a/hw/cxl/cxl-host.c +++ b/hw/cxl/cxl-host.c @@ -362,10 +362,14 @@ static int cxl_fmws_direct_passthrough(Object *obj, v= oid *opaque) fw =3D CXL_FMW(obj); =20 if (!cfmws_is_not_interleaved(fw, state->decoder_base)) { + ct3d->direct_mr_enabled =3D false; return 0; } + ct3d->direct_mr_enabled =3D true; =20 ct3d->dc.fw =3D fw; + ct3d->dc.dc_decoder_window.base =3D state->decoder_base; + ct3d->dc.dc_decoder_window.size =3D state->decoder_size; =20 if (state->commit) { MemoryRegion *mr =3D NULL; diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index b785553225..15114a5314 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -2846,13 +2846,19 @@ void cxl_insert_extent_to_extent_list(CXLDCExtentLi= st *list, uint64_t len, uint8_t *tag, uint16_t shared_seq, - int rid) + int rid, + uint64_t offset) { CXLDCExtent *extent; =20 extent =3D g_new0(CXLDCExtent, 1); extent->start_dpa =3D dpa; extent->len =3D len; + extent->offset =3D offset; + extent->shared_seq =3D shared_seq; + extent->hm =3D host_mem; + extent->fw =3D fw; + extent->rid =3D rid; if (tag) { memcpy(extent->tag, tag, 0x10); } @@ -2880,14 +2886,15 @@ 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) { 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); + tag, shared_seq, rid, offset); return group; } =20 @@ -2985,7 +2992,8 @@ static bool cxl_extent_find_extent_detail(CXLDCExtent= GroupList *list, uint8_t *tag, HostMemoryBackend **hmb, struct CXLFixedWindow **fw, - int *rid) + int *rid, + uint64_t *offset) { CXLDCExtent *ent, *ent_next; CXLDCExtentGroup *group =3D QTAILQ_FIRST(list); @@ -2996,6 +3004,7 @@ static bool cxl_extent_find_extent_detail(CXLDCExtent= GroupList *list, *hmb =3D ent->hm; memcpy(tag, ent->tag, 0x10); *rid =3D ent->rid; + *offset =3D ent->offset; return true; } } @@ -3057,7 +3066,7 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struc= t cxl_cmd *cmd, HostMemoryBackend *hmb_dc; uint8_t tag[0x10]; uint32_t i, num; - uint64_t dpa, len; + uint64_t dpa, len, offset; int rid; CXLRetCode ret; =20 @@ -3100,16 +3109,25 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const str= uct cxl_cmd *cmd, len =3D in->updated_entries[i].len; =20 if (ct3d->dc.total_capacity_cmd) { + int mr_idx =3D ct3d->dc.cur_direct_region_idx; found =3D cxl_extent_find_extent_detail( - &ct3d->dc.extents_pending, dpa, len, tag, &hmb_dc, &fw, &r= id); + &ct3d->dc.extents_pending, dpa, len, tag, &hmb_dc, &fw, &r= id, + &offset); =20 /* * This only occurs when host accepts an extent where device d= oes * not know anything about it. */ if (!found) { - qemu_log("Could not find the extent detail for DPA 0x%" PR= Ix64 - " LEN 0x%" PRIx64 "\n", + qemu_log("could not find the extent detail for dpa 0x%" PR= Ix64 + " len 0x%" PRIx64 "\n", + dpa, len); + return CXL_MBOX_INVALID_PA; + } + + if (!hmb_dc) { + qemu_log("Mapping host memory backend for dpa 0x%" PRIx64 + " len 0x%" PRIx64 "\n", dpa, len); return CXL_MBOX_INVALID_PA; } @@ -3123,6 +3141,7 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const struc= t cxl_cmd *cmd, } =20 mr =3D host_memory_backend_get_memory(hmb_dc); + if (!mr) { qemu_log("Could not get memory region from host memory " "backend\n"); @@ -3132,11 +3151,32 @@ static CXLRetCode cmd_dcd_add_dyn_cap_rsp(const str= uct cxl_cmd *cmd, memory_region_set_nonvolatile(mr, false); memory_region_set_enabled(mr, true); host_memory_backend_set_mapped(hmb_dc, true); + + if (ct3d->direct_mr_enabled) { + g_autofree char *direct_mapping_name =3D + g_strdup_printf("cxl-direct-mapping-%d", mr_idx); + int region_offset =3D dpa - ct3d->dc.regions[rid].base; + MemoryRegion *dr_dc_mr =3D &ct3d->dc.dc_direct_mr[mr_idx]; + memory_region_init_alias(dr_dc_mr, OBJECT(ct3d), + direct_mapping_name, mr, region_o= ffset, + ct3d->dc.dc_decoder_window.size); + memory_region_add_subregion(&fw->mr, + ct3d->dc.dc_decoder_window.bas= e - + fw->base + offset, + dr_dc_mr); + /* + * for now assuming 4 extents and 4 direct mapping memory + * regions. + */ + ct3d->dc.cur_direct_region_idx =3D + (ct3d->dc.cur_direct_region_idx + 1) % 4; + } + cxl_insert_extent_to_extent_list(extent_list, hmb_dc, fw, dpa,= len, - NULL, 0, rid); + tag, 0, rid, offset); } else { cxl_insert_extent_to_extent_list(extent_list, NULL, NULL, dpa,= len, - NULL, 0, -1); + NULL, 0, -1, -1); } =20 ct3d->dc.total_extent_count +=3D 1; @@ -3167,7 +3207,7 @@ 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->rid, ent->offset); cnt++; } return cnt; @@ -3223,15 +3263,15 @@ static CXLRetCode cxl_dc_extent_release_dry_run(CXL= Type3Dev *ct3d, if (len1) { cxl_insert_extent_to_extent_list(updated_list, NUL= L, NULL, ent_start_d= pa, - len1, NULL, 0, - ent->rid); + len1, ent->tag, 0, + ent->rid, ent->of= fset); cnt_delta++; } if (len2) { cxl_insert_extent_to_extent_list(updated_list, NUL= L, NULL, dpa + len, - len2, NULL, 0, - ent->rid); + len2, ent->tag, 0, + ent->rid, ent->of= fset); cnt_delta++; } =20 @@ -3706,7 +3746,8 @@ static CXLRetCode cmd_fm_initiate_dc_add(const struct= cxl_cmd *cmd, group =3D cxl_insert_extent_to_extent_group(group, NULL, N= ULL, ext->start_dpa, ext->len, ext->t= ag, - ext->shared_seq,= 0); + ext->shared_seq,= 0, + -1); } =20 cxl_extent_group_list_insert_tail(&ct3d->dc.extents_pending, g= roup); diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index ef1c1cbaef..e3093f63a3 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -2139,7 +2139,8 @@ static void qmp_cxl_process_dynamic_capacity_prescrip= tive(const char *path, extents[i].len, extents[i].tag, extents[i].share= d_seq, - rid); + rid, + offset); } else { group =3D cxl_insert_extent_to_extent_group(group, dcd->dc.host_dc, @@ -2148,7 +2149,8 @@ static void qmp_cxl_process_dynamic_capacity_prescrip= tive(const char *path, extents[i].len, extents[i].tag, extents[i].share= d_seq, - rid); + rid, + offset); } } =20 diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index fe0c44e8d7..1a521df881 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -524,6 +524,7 @@ typedef struct CXLDCExtent { uint16_t shared_seq; uint8_t rsvd[0x6]; int rid; + uint64_t offset; =20 QTAILQ_ENTRY(CXLDCExtent) node; } CXLDCExtent; @@ -589,6 +590,7 @@ struct CXLType3Dev { =20 /* State */ MemoryRegion direct_mr[CXL_HDM_DECODER_COUNT]; + bool direct_mr_enabled; AddressSpace hostvmem_as; AddressSpace hostpmem_as; CXLComponentState cxl_cstate; @@ -633,6 +635,14 @@ struct CXLType3Dev { HostMemoryBackend *host_dc; AddressSpace host_dc_as; struct CXLFixedWindow *fw; + int cur_direct_region_idx; + /* + * 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. @@ -647,6 +657,11 @@ struct CXLType3Dev { =20 uint8_t num_regions; /* 0-8 regions */ CXLDCRegion regions[DCD_MAX_NUM_REGION]; + /* + * Assume 4 now but many possible, each region is one alias an ext= ent + * to allow performance translation in KVM. + */ + MemoryRegion dc_direct_mr[4]; } dc; =20 struct CXLSanitizeInfo *media_op_sanitize; @@ -720,8 +735,11 @@ 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); + uint64_t len, + uint8_t *tag, + uint16_t shared_seq, + 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, @@ -733,7 +751,8 @@ CXLDCExtentGroup *cxl_insert_extent_to_extent_group(CXL= DCExtentGroup *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); --=20 2.43.0 From nobody Sat Nov 29 10:19:14 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 From nobody Sat Nov 29 10:19:14 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