From nobody Fri Apr 3 01:25:55 2026 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=1774464263; cv=none; d=zohomail.com; s=zohoarc; b=W+vlOUfVGtX4k4PW2kpyLz7j7LCbUqXessPK2Vs0jmJtdkXdHMilNf1IE3njrtiK0UwJ4xtz24/5uFnt2qPAVZQCugbNrV1GCUu3l+/WCpZqzrvngsNI6oegKW6Xw60GIkJ4flqwJYb3KV15Vv0/CAVgLvElzn57K9pp05t+DCA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774464263; 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=h9TbjHYYgC2QwQLSbj5EeHZfdaCvzceOMYGOaKMvWbk=; b=CFwXF+cVlemz63QCuUasWN9SWWLBQEfxEH9Ht2XFRkKDmGsg9CuVDMvwenJC7eKp+Eep0MOwoT8NNZ9YBPB24hitmMj8Rsg78j+spfxo5ZRzpxGoB0MuHrtfAvbg2Yrzp2Ci7NfWG5IypRh6y2F6nXY6Ciho0mWqfljzwHnzoJY= 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 177446426381843.01571181380996; Wed, 25 Mar 2026 11:44:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5TCi-00026k-Kq; Wed, 25 Mar 2026 14:43:44 -0400 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 1w5TCg-00026X-CZ for qemu-devel@nongnu.org; Wed, 25 Mar 2026 14:43:42 -0400 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 1w5TCe-0005u5-E6 for qemu-devel@nongnu.org; Wed, 25 Mar 2026 14:43:42 -0400 Received: from mail.maildlp.com (unknown [172.18.224.83]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4fgwlB5KS0zHnGhl; Thu, 26 Mar 2026 02:43:02 +0800 (CST) Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207]) by mail.maildlp.com (Postfix) with ESMTPS id 8F53240086; Thu, 26 Mar 2026 02:43:38 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.66.203) 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; Wed, 25 Mar 2026 18:43:37 +0000 To: CC: , , , , , , , , , , , , Subject: [PATCH 1/9] hw/mem: Add tag support to generic host memory backends Date: Wed, 25 Mar 2026 18:42:49 +0000 Message-ID: <20260325184259.366-2-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.51.0.windows.2 In-Reply-To: <20260325184259.366-1-alireza.sanaee@huawei.com> References: <20260325184259.366-1-alireza.sanaee@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.47.66.203] X-ClientProxiedBy: lhrpeml500011.china.huawei.com (7.191.174.215) 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Alireza Sanaee From: Alireza Sanaee via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1774464266809154100 Content-Type: text/plain; charset="utf-8" Add a string tag property to HostMemoryBackend so that backends can be identified by a user-assigned name at runtime. Expose the property through QOM and add a host_memory_backend_find_by_tag() helper that walks the object tree to locate a backend by its tag. This is used by the following CXL patches to resolve a named backend for a pending DC extent and attach it to the accepted extent when the host acknowledges the add request. Signed-off-by: Alireza Sanaee --- backends/hostmem.c | 72 ++++++++++++++++++++++++++++++++++++++++ include/system/hostmem.h | 2 ++ qapi/qom.json | 3 ++ tests/qtest/qom-test.c | 8 +++-- 4 files changed, 83 insertions(+), 2 deletions(-) diff --git a/backends/hostmem.c b/backends/hostmem.c index 15d4365b69..270cae9569 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -47,6 +47,50 @@ host_memory_backend_get_name(HostMemoryBackend *backend) return object_get_canonical_path(OBJECT(backend)); } =20 +typedef struct HostMemoryBackendTagSearch { + const char *tag; + HostMemoryBackend *backend; +} HostMemoryBackendTagSearch; + +static int host_memory_backend_find_by_tag_cb(Object *obj, void *opaque) +{ + HostMemoryBackendTagSearch *ctx =3D opaque; + HostMemoryBackend *backend; + + if (!object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) { + return 0; + } + + backend =3D MEMORY_BACKEND(obj); + if (!backend->tag) { + return 0; + } + + if (strcmp(backend->tag, ctx->tag) =3D=3D 0) { + ctx->backend =3D backend; + return 1; + } + + return 0; +} + +HostMemoryBackend *host_memory_backend_find_by_tag(const char *tag) +{ + HostMemoryBackendTagSearch ctx =3D { + .tag =3D tag, + .backend =3D NULL, + }; + + if (!tag) { + return NULL; + } + + object_child_foreach_recursive(object_get_objects_root(), + host_memory_backend_find_by_tag_cb, &ct= x); + + return ctx.backend; +} + static void host_memory_backend_get_size(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -460,6 +504,22 @@ static void host_memory_backend_set_share(Object *o, b= ool value, Error **errp) backend->share =3D value; } =20 +static void +host_memory_backend_set_tag(Object *obj, const char *value, Error **errp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); + + g_free(backend->tag); + backend->tag =3D g_strdup(value); +} + +static char *host_memory_backend_get_tag(Object *obj, Error **errp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); + + return g_strdup(backend->tag); +} + #ifdef CONFIG_LINUX static bool host_memory_backend_get_reserve(Object *o, Error **errp) { @@ -501,6 +561,13 @@ host_memory_backend_set_use_canonical_path(Object *obj= , bool value, backend->use_canonical_path =3D value; } =20 +static void host_memory_backend_finalize(Object *obj) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); + + g_free(backend->tag); +} + static void host_memory_backend_class_init(ObjectClass *oc, const void *data) { @@ -557,6 +624,10 @@ host_memory_backend_class_init(ObjectClass *oc, const = void *data) host_memory_backend_get_share, host_memory_backend_set_share); object_class_property_set_description(oc, "share", "Mark the memory as private to QEMU or shared"); + object_class_property_add_str(oc, "tag", + host_memory_backend_get_tag, host_memory_backend_set_tag); + object_class_property_set_description(oc, "tag", + "A user-defined tag to identify this memory backend"); #ifdef CONFIG_LINUX object_class_property_add_bool(oc, "reserve", host_memory_backend_get_reserve, host_memory_backend_set_reserve); @@ -586,6 +657,7 @@ static const TypeInfo host_memory_backend_info =3D { .class_init =3D host_memory_backend_class_init, .instance_size =3D sizeof(HostMemoryBackend), .instance_init =3D host_memory_backend_init, + .instance_finalize =3D host_memory_backend_finalize, .instance_post_init =3D host_memory_backend_post_init, .interfaces =3D (const InterfaceInfo[]) { { TYPE_USER_CREATABLE }, diff --git a/include/system/hostmem.h b/include/system/hostmem.h index 88fa791ac7..a02e173d48 100644 --- a/include/system/hostmem.h +++ b/include/system/hostmem.h @@ -81,12 +81,14 @@ struct HostMemoryBackend { ThreadContext *prealloc_context; DECLARE_BITMAP(host_nodes, MAX_NODES + 1); HostMemPolicy policy; + char *tag; =20 MemoryRegion mr; }; =20 bool host_memory_backend_mr_inited(HostMemoryBackend *backend); MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend); +HostMemoryBackend *host_memory_backend_find_by_tag(const char *tag); =20 void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mappe= d); bool host_memory_backend_is_mapped(HostMemoryBackend *backend); diff --git a/qapi/qom.json b/qapi/qom.json index c653248f85..e6feeb324a 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -658,6 +658,8 @@ # @reserve: if true, reserve swap space (or huge pages) if applicable # (default: true) (since 6.1) # +# @tag: user-defined memory backend tag (since 11.1) +# # @size: size of the memory region in bytes # # @x-use-canonical-path-for-ramblock-id: if true, the canonical path @@ -683,6 +685,7 @@ '*prealloc-context': 'str', '*share': 'bool', '*reserve': 'bool', + '*tag': 'str', 'size': 'size', '*x-use-canonical-path-for-ramblock-id': 'bool' } } =20 diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c index 6421f2d9d9..3109b47cca 100644 --- a/tests/qtest/qom-test.c +++ b/tests/qtest/qom-test.c @@ -17,6 +17,7 @@ =20 #define RAM_NAME "node0" #define RAM_SIZE 65536 +#define RAM_TAG "ramtag0" =20 static int verbosity_level; =20 @@ -59,6 +60,8 @@ static void test_list_get_value(QTestState *qts) =20 } else if (!strcmp(prop_name, "size")) { g_assert_cmpint(qdict_get_int(prop, "value"), =3D=3D, RAM_SIZE= ); + } else if (!strcmp(prop_name, "tag")) { + g_assert_cmpstr(qdict_get_str(prop, "value"), =3D=3D, RAM_TAG); } } } @@ -195,8 +198,9 @@ static void test_machine(gconstpointer data) QTestState *qts; g_autoptr(QList) paths =3D qlist_new(); =20 - qts =3D qtest_initf("-machine %s -object memory-backend-ram,id=3D%s,si= ze=3D%d", - machine, RAM_NAME, RAM_SIZE); + qts =3D qtest_initf("-machine %s -object memory-backend-ram,id=3D%s,si= ze=3D%d" + ",tag=3D%s", + machine, RAM_NAME, RAM_SIZE, RAM_TAG); =20 if (g_test_slow()) { /* Make sure we can get the machine class properties: */ --=20 2.50.1 (Apple Git-155)