From nobody Mon Nov 23 04:34:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793016932; cv=none; d=zohomail.com; s=zohoarc; b=SuaFOHBeuUAjqxqS5UW5Mtz+Lj6NBshQoEB3x7e4sXp3Q70uLz2aE5a0bPXi/RXwxNEW1uSanDAGfwEfateEzpPUuflr7qJmx3DfasW8yRafaoXxBZub6PW9GZZzjh6hoXJYINbPfdPUqIpALe1pijjk9W2xw3Ar8QTRKDaXzNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793016932; h=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:Sender:Subject:Subject:To:To:Message-Id; bh=r5EGX5+LQaQtlMCbBWF8zZymFVj0pm4lFgNDqVpYpvk=; b=bDAOs5FRmZsJVGiE8ncyX7nTFzgdOBkaF+TczFKoZY1guhfPe3Nag5jCynj1N9uYUjKnZmQQoTKrxnaVWP5fpv+QQZH2Y00AIXg39R5RMp98DHa4ptm5mRv55+chmQBXjPk0NSp/VIekgxub8PbPLSfiXyio66NwWs/lBtAsiz8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179301693217979.30958906312185; Mon, 26 Oct 2026 05:15:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLJbS-0002Y9-6n; Mon, 26 Oct 2026 08:15:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHP8-0002kq-UY for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:12 -0400 Received: from esa7.hc1455-7.c3s2.iphmx.com ([139.138.61.252]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHP7-00080e-2F for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:10 -0400 Received: from gmgwnl01.global.fujitsu.com ([52.143.17.124]) by esa7.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2026 18:54:07 +0900 Received: from az2nlsmgm1.o.css.fujitsu.com (unknown [10.150.26.203]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by gmgwnl01.global.fujitsu.com (Postfix) with ESMTPS id 453B41C000CF for ; Mon, 26 Oct 2026 09:54:07 +0000 (UTC) Received: from m3003.s.css.fujitsu.com (unknown [10.128.233.114]) by az2nlsmgm1.o.css.fujitsu.com (Postfix) with ESMTP id AD3C9C00420 for ; Mon, 26 Oct 2026 09:54:06 +0000 (UTC) Received: from tanjiro.soft.fujitsu.com (unknown [10.118.236.61]) by m3003.s.css.fujitsu.com (Postfix) with ESMTP id 75DB92069EA7; Mon, 26 Oct 2026 18:54:05 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1793008449; x=1824544449; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U6hnYornSWU43U02GU6HnS0UKYROmnqdzpVcvZQfMTM=; b=V4FhHKuNUpZnfxpWwfHjv03XWkAz5Hbfg/H4dJ/nUuRuDLnKXBY3HsqR U445KestR//uSwxx30S8OOrzqfT53LU5TsqVLfj+LsCRuIoy4j4p3k3Mj oSzIC4djGNIw+D4pZT4/noNsyJYm22fPJP2jXV8qqN6sSfGDbRbSk/De7 tYlWS+TITId6lyM8tWgOFrCVfXIAg/dgDEX6M+y28+PPJlIpTy+xTG+gn tUtJ7gSQswOOgRZjfCLXvwlT/ynvAw8ZWFfx8aWFTlKxDIjOJwVSV0VrR OsR0HhI2GtBu8nYLq917WQES0O/N8IJVkrVkTmFJIIsIsW/pTCHgSBoTg g==; X-CSE-ConnectionGUID: bAPuUB8CS0ORLCj39yeXTA== X-CSE-MsgGUID: uKPf1mmzTHyZGB7trHwzLQ== X-IronPort-AV: E=McAfee;i="6800,10657,11946"; a="238359875" X-IronPort-AV: E=Sophos;i="6.27,179,1786978800"; d="scan'208";a="238359875" To: qemu-devel@nongnu.org Cc: Yukiya Takaki , Anisa Su , Jonathan Cameron , Junjie Cao , linux-cxl@vger.kernel.org, "Wolski, Tomasz" , lizhijian@fujitsu.com, y-goto@fujitsu.com, yukiya.takaki@gmail.com Subject: [PATCH RFC 1/7] QEMU/hw/cxl: add program-hdm-decoder option for CXL Type 3 devices Date: Mon, 26 Oct 2026 19:03:22 +0900 Message-ID: <9c6f4c19cd72085432734ed6c427201f853d2bab.1793003983.git.fj2110jc@fujitsu.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=139.138.61.252; envelope-from=fj2110jc@fujitsu.com; helo=esa7.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 26 Oct 2026 08:14:56 -0400 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: Yukiya Takaki From: Yukiya Takaki via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793016934920158500 Content-Type: text/plain; charset="utf-8" Introduce a `program-hdm-decoder` property for CXL Type 3 devices. When this property is enabled, QEMU will program the HDM decoder so that the guest can automatically create CXL regions for Type 3 memory at boot. The property is a boolean and is exposed as `program-hdm-decoder` on the `cxl-type3` device. It defaults to `false`, so existing configurations are not affected unless the user explicitly enables it. Co-developed-by: Li Zhijian Signed-off-by: Yukiya Takaki --- hw/mem/cxl_type3.c | 2 ++ include/hw/cxl/cxl_device.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index a04dc74ecc..b65ddd264d 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1360,6 +1360,8 @@ static const Property ct3_props[] =3D { DEFINE_PROP_LINK("lsa", CXLType3Dev, lsa, TYPE_MEMORY_BACKEND, HostMemoryBackend *), DEFINE_PROP_UINT64("sn", CXLType3Dev, sn, UI64_NULL), + DEFINE_PROP_BOOL("program-hdm-decoder", CXLType3Dev, + program_hdm_decoder, false), DEFINE_PROP_STRING("cdat", CXLType3Dev, cxl_cstate.cdat.filename), DEFINE_PROP_UINT8("num-dc-regions", CXLType3Dev, dc.num_regions, 0), DEFINE_PROP_LINK("volatile-dc-memdev", CXLType3Dev, dc.host_dc, diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index ba551fa5f9..a2c830d181 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -777,6 +777,8 @@ struct CXLType3Dev { /* BI flows */ bool hdmdb; =20 + bool program_hdm_decoder; + struct dynamic_capacity { HostMemoryBackend *host_dc; AddressSpace host_dc_as; --=20 2.52.0 From nobody Mon Nov 23 04:34:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793017029; cv=none; d=zohomail.com; s=zohoarc; b=nMIPsFtCmfQoOjfm8pffAySUr7gEu0o/b8rXtQPT8JP3uiWj2IpBDz92HGGSAcUJmNFok9uzKI2TJubE3Q80SaCxNNidAfZgBAgaTgHM7SsbGOw5MyI48P7iiYasTnea6eVYp9l3PUusf0802e8DiKLlvyst5I5PVXecHrqmPyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793017029; 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:Sender:Subject:Subject:To:To:Message-Id; bh=5/PjjFpHJMQNFkm0jVvsAlbbMUQRzR9dvMRBcBXQjOw=; b=mX3Yy2Bi0ETkd24Lkx7cBAmMJ6pTv6W6yg1J49qsXTT2/iA/19YHMjVpXZA5+JYAcls/3N8/LHIjBVwLEsnaNO5nGPek25nhXE1Hz9Kl9/dphKrU6S6Lpe27tSkGaqH8zuT9VTG4oGisF1TxIO2AIPdHc4uW5x6r6edzY7SQKGM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793017029779933.8455251725039; Mon, 26 Oct 2026 05:17:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLJbP-0002Sn-TE; Mon, 26 Oct 2026 08:15:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPB-0002lz-T2 for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:15 -0400 Received: from esa2.hc1455-7.c3s2.iphmx.com ([207.54.90.48]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPA-00080m-3m for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:13 -0400 Received: from gmgwuk01.global.fujitsu.com ([172.187.114.235]) by esa2.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2026 18:54:16 +0900 Received: from az2uksmgm4.o.css.fujitsu.com (unknown [10.151.22.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by gmgwuk01.global.fujitsu.com (Postfix) with ESMTPS id B14111C1C700 for ; Mon, 26 Oct 2026 09:54:09 +0000 (UTC) Received: from m3003.s.css.fujitsu.com (unknown [10.128.233.114]) by az2uksmgm4.o.css.fujitsu.com (Postfix) with ESMTP id 2744814003A9 for ; Mon, 26 Oct 2026 09:54:09 +0000 (UTC) Received: from tanjiro.soft.fujitsu.com (unknown [10.118.236.61]) by m3003.s.css.fujitsu.com (Postfix) with ESMTP id E8F7A202EBDE; Mon, 26 Oct 2026 18:54:07 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1793008458; x=1824544458; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Zq89hgzs7m9+iM8Br2P62CYeN5DC4Ml4L5UACTlprZ4=; b=esb9FSl2FiVBv9bi9BtJdSdmifZlGy3LOeScy4G7U4p+6ykME18nhyHI wyyBbzr+FGUU1zT0CRMz23Mei/DDqXqQWCPA36Uk6HmmxOTJ+Cn0hpXhp XQU7Jd1lv7O98hDcIIWBMbjzFzPy1mB+J8maSJlK17MgbMoV235/UgFTO 9+4Iix0+kZ6j4WGZHxwWpwwqxmibjVHtHDTXGiBa/NkHIHul3CtHR8RAs JhaUMOS8oOns4184X4/cJi+ZY/TtUdfAaPmjFhBXw3U1lXPViHPXRyDx9 221SCyCynZNQ6mevepMrZ3JA7gBVdsRpfoss/72D4uYsLrqX0sqOy8Rhf A==; X-CSE-ConnectionGUID: 9S1GTztWQOCIcYFBFYZ8pQ== X-CSE-MsgGUID: QS+0TY4dQiWlZLwG43rcoA== X-IronPort-AV: E=McAfee;i="6800,10657,11946"; a="259472557" X-IronPort-AV: E=Sophos;i="6.27,179,1786978800"; d="scan'208";a="259472557" To: qemu-devel@nongnu.org Cc: Yukiya Takaki , Anisa Su , Jonathan Cameron , Junjie Cao , linux-cxl@vger.kernel.org, "Wolski, Tomasz" , lizhijian@fujitsu.com, y-goto@fujitsu.com, yukiya.takaki@gmail.com Subject: [PATCH RFC 2/7] QEMU/hw/cxl:add HPA offset tracking for CXL Type 3 devices Date: Mon, 26 Oct 2026 19:03:23 +0900 Message-ID: <6172d168ed84f0b968661e7bf41dad01526d9d0a.1793003983.git.fj2110jc@fujitsu.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=207.54.90.48; envelope-from=fj2110jc@fujitsu.com; helo=esa2.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 26 Oct 2026 08:14:57 -0400 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: Yukiya Takaki From: Yukiya Takaki via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793017031152158500 E820, SRAT and HDM decoder programming in this series all need per=E2=80=91= device host physical address (HPA) information for CXL Type 3 memory. Today, CXLType3Dev does not expose this in a convenient way. This patch adds minimal state to CXLHost and CXLType3Dev, plus a helper to walk from a Type 3 device back to its host, so that each CXL Type 3 device can be assigned a stable HPA offset within the CFMW window and an index that later code can rely on when building firmware tables and regions. Co-developed-by: Li Zhijian Signed-off-by: Yukiya Takaki --- hw/mem/cxl_type3.c | 37 +++++++++++++++++++++++++++++++++++++ include/hw/cxl/cxl.h | 2 ++ include/hw/cxl/cxl_device.h | 2 ++ 3 files changed, 41 insertions(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index b65ddd264d..d08a4255c9 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -732,9 +732,39 @@ static void cxl_destroy_dc_regions(CXLType3Dev *ct3d) } } =20 + +static CXLHost *ct3d_to_cxl_pxb(DeviceState *dev) +{ + BusState *bus =3D dev->parent_bus; + + DeviceState *cxl_rp_dev =3D NULL; + if (bus && bus->parent) { + cxl_rp_dev =3D bus->parent; + } + assert(cxl_rp_dev); + + DeviceState *cxl_host_dev =3D NULL; + if (cxl_rp_dev) { + BusState *rp_bus =3D cxl_rp_dev->parent_bus; + if (rp_bus && rp_bus->parent) { + cxl_host_dev =3D rp_bus->parent; + } + } + assert(cxl_host_dev); + + if (cxl_host_dev && + object_dynamic_cast(OBJECT(cxl_host_dev), TYPE_PXB_CXL_HOST)) { + CXLHost *host =3D PXB_CXL_HOST(cxl_host_dev); + return host; + } + + return NULL; +} + static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) { DeviceState *ds =3D DEVICE(ct3d); + CXLHost *host =3D ct3d_to_cxl_pxb(ds); =20 if (!ct3d->hostmem && !ct3d->hostvmem && !ct3d->hostpmem && !ct3d->dc.num_regions) { @@ -816,6 +846,13 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error = **errp) g_free(p_name); } =20 + if (ct3d->program_hdm_decoder) { + ct3d->hpa_offset =3D host->unused_hpa_offset; + ct3d->idx =3D host->unused_dev_num; + host->unused_hpa_offset +=3D ct3d->cxl_dstate.static_mem_size; + host->unused_dev_num++; + } + ct3d->dc.total_capacity =3D 0; if (ct3d->dc.num_regions > 0) { MemoryRegion *dc_mr; diff --git a/include/hw/cxl/cxl.h b/include/hw/cxl/cxl.h index 7cf3dc622c..b8b3071f81 100644 --- a/include/hw/cxl/cxl.h +++ b/include/hw/cxl/cxl.h @@ -67,6 +67,8 @@ struct CXLHost { =20 CXLComponentState cxl_cstate; bool passthrough; + hwaddr unused_hpa_offset; + int unused_dev_num; }; =20 #define TYPE_PXB_CXL_HOST "pxb-cxl-host" diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index a2c830d181..c3a729f8c5 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -778,6 +778,8 @@ struct CXLType3Dev { bool hdmdb; =20 bool program_hdm_decoder; + hwaddr hpa_offset; + int idx; =20 struct dynamic_capacity { HostMemoryBackend *host_dc; --=20 2.52.0 From nobody Mon Nov 23 04:34:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793016914; cv=none; d=zohomail.com; s=zohoarc; b=UiE1y/BVdKnHfo4pF4h2mP9+ORmoQlX/TY4ptv/Ps9shxW7OiQXxAIAqhFqkEbSQHSlgYgj8oDbLlD31JVEpNoG+I5R2raz/6vgwh/kO5AFkgzg490hsRZ27wK9CXhzV4ctDT/+yhGVNCoYMbRL9ZAc+2frQ+bviIGE+rdgHbrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793016914; 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:Sender:Subject:Subject:To:To:Message-Id; bh=rmht22CGrxfL4vYhIbCQTiNGlGP2TjapHUWtXZPfvLk=; b=Wmz46SnkEP39CMkiBU0gACmGzh6c5TMvLVa1AecEOOMh5q3d8SONzFE0/XEwuVe7OGsYDUz1lhhiEy4fNUQ2T86XvOEAmCgF0nzeWfQpGmgcnp1GAdAe9iozX4FL+Kw35Ai9Iz01AuchsR+Pc/cIpqK3JBIVyu4zkPve4MDSQd4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793016913979799.8039117180922; Mon, 26 Oct 2026 05:15:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLJbQ-0002V3-MU; Mon, 26 Oct 2026 08:15:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPC-0002mG-WB for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:16 -0400 Received: from esa2.hc1455-7.c3s2.iphmx.com ([207.54.90.48]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPB-000815-7D for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:14 -0400 Received: from gmgwnl01.global.fujitsu.com ([52.143.17.124]) by esa2.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2026 18:54:18 +0900 Received: from az2nlsmgm2.o.css.fujitsu.com (unknown [10.150.26.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by gmgwnl01.global.fujitsu.com (Postfix) with ESMTPS id 88DFC1C000CF for ; Mon, 26 Oct 2026 09:54:11 +0000 (UTC) Received: from m3003.s.css.fujitsu.com (unknown [10.128.233.114]) by az2nlsmgm2.o.css.fujitsu.com (Postfix) with ESMTP id 020571C002F9 for ; Mon, 26 Oct 2026 09:54:11 +0000 (UTC) Received: from tanjiro.soft.fujitsu.com (unknown [10.118.236.61]) by m3003.s.css.fujitsu.com (Postfix) with ESMTP id C1B00202EBDE; Mon, 26 Oct 2026 18:54:09 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1793008460; x=1824544460; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/tmmNQTc1uXtVHQp9ghXgdfmfuVHFU+fKjxTNRMw6H4=; b=OfPivGXHA2Uvn6Q2rgVeo5ckstTudBy3RRXwByzBlE0VsMqPoArEG7WQ YFYz9tkG3lJijEK33XKkhiuma4sWp/sDO1J7y0ZDOobTltZh/rdId31ae N0HaXqK5Dvc0Pq9mb93Qp1Q0DuCQ0RpBVWI3up11ORaaOsGsl/GoG7pnl H/KhW6y1Z72y2E0JdTskPTTkT8JoEP56pcDg6OmpVBFnKMqIlo1uIeYz1 HSFqqSFyTw/7PRdrCmSqAEoHUbso43K9fn9hSDQGOUtlP/vp1n8SNOaGt U7PW/uB23kLbS4v0P1O8NX9pkATRRSCb4JzWrkIZXGoFa7FD+Fg1YNuHb Q==; X-CSE-ConnectionGUID: 98wudPVoTD2htf5jAz2kaw== X-CSE-MsgGUID: XS+iyBYqR7m43XdgYXlt3g== X-IronPort-AV: E=McAfee;i="6800,10657,11946"; a="259472559" X-IronPort-AV: E=Sophos;i="6.27,179,1786978800"; d="scan'208";a="259472559" To: qemu-devel@nongnu.org Cc: Yukiya Takaki , Anisa Su , Jonathan Cameron , Junjie Cao , linux-cxl@vger.kernel.org, "Wolski, Tomasz" , lizhijian@fujitsu.com, y-goto@fujitsu.com, yukiya.takaki@gmail.com Subject: [PATCH RFC 3/7] QEMU: hw/cxl: add helper to get HPA range for CXL Type 3 Date: Mon, 26 Oct 2026 19:03:24 +0900 Message-ID: <22b52860497f643217fb52f029d87ebd8a6e6492.1793003983.git.fj2110jc@fujitsu.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=207.54.90.48; envelope-from=fj2110jc@fujitsu.com; helo=esa2.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 26 Oct 2026 08:14:57 -0400 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: Yukiya Takaki From: Yukiya Takaki via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793016917241158500 The previously added `hpa_offset` on CXLType3Dev records the offset of a device within its CFMW window, but there is no simple helper to obtain the full host physical address (HPA) range for a given Type 3 device. This patch adds `ct3_type3_get_hpm_range()`, which returns the HPA base and size for a CXLType3Dev by combining the CFMW base, the per=E2=80=91device o= ffset and the device size. The helper is declared in the header so that other code can use it when building tables and regions. Co-developed-by: Li Zhijian Signed-off-by: Yukiya Takaki --- hw/mem/cxl_type3.c | 40 +++++++++++++++++++++++++++++++++++++ include/hw/cxl/cxl_device.h | 1 + 2 files changed, 41 insertions(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index d08a4255c9..811f8e247d 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1358,6 +1358,46 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr hos= t_addr, uint64_t data, return address_space_write(as, dpa_offset, attrs, &data, size); } =20 +static uint64_t c3t_addr_size(DeviceState *dev) +{ + CXLType3Dev *ct3d =3D CXL_TYPE3(dev); + MemoryRegion *vmr =3D host_memory_backend_get_memory(ct3d->hostvmem); + + return memory_region_size(vmr); +} + +static uint64_t c3t_hpa_base(DeviceState *dev) +{ + GSList *cfmws_list, *iter; + + cfmws_list =3D cxl_fmws_get_all_sorted(); + for (iter =3D cfmws_list; iter; iter =3D iter->next) { + struct CXLFixedWindow *fw; + + if (!object_dynamic_cast(iter->data, TYPE_CXL_FMW)) { + continue; + } + fw =3D CXL_FMW(iter->data); + + PXBCXLDev *pxb =3D fw->target_hbs[0]; + if (ct3d_to_cxl_pxb(dev) !=3D pxb->cxl_host_bridge) { + continue; + } + + g_slist_free(cfmws_list); + return fw->base; + } + g_slist_free(cfmws_list); + + return 0; +} + +void ct3_type3_get_hpm_range(CXLType3Dev *dev, uint64_t *base, uint64_t *s= ize) +{ + *base =3D c3t_hpa_base(DEVICE(dev)) + dev->hpa_offset; + *size =3D c3t_addr_size(DEVICE(dev)); +} + static void ct3d_reset(DeviceState *dev) { CXLType3Dev *ct3d =3D CXL_TYPE3(dev); diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index c3a729f8c5..07654f4b62 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -878,6 +878,7 @@ void ct3_clear_region_block_backed(CXLType3Dev *ct3d, u= int64_t dpa, uint64_t len); bool ct3_test_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa, uint64_t len); +void ct3_type3_get_hpm_range(CXLType3Dev *dev, uint64_t *base, uint64_t *s= ize); void cxl_assign_event_header(CXLEventRecordHdr *hdr, const QemuUUID *uuid, uint32_t flags, uint8_t length, uint64_t timestamp, --=20 2.52.0 From nobody Mon Nov 23 04:34:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793016950; cv=none; d=zohomail.com; s=zohoarc; b=VcIEQlcaRM7PQ9K4H/WUt3QQz83cHJSLyKJ83U0mV4YFDP68CzR98H/gn/BeHb/e1ZNFFCgor97AvUKi3yFErPgRBBk4lPU40vI/w6ywXBqC+XlJErOGz5+eC2wtraTcxIyd4wk7xOhgRTaHPnzJU1KPByxUndklqsrz5L6fPnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793016950; 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:Sender:Subject:Subject:To:To:Message-Id; bh=oIV57EJWTOMtrl0TA07o16PQYh/OKipP1ACFbkkxDuk=; b=VawbFF7hVuG1QQW5XX4D4yqnRB4kTtxvkc5V2q7BoL0Il9Vsh/GR1gdBSzMYLy4U64CXaYTHHB40lzxWZE9WnmmqNsz47fYg0t0FzaXTxsZ/d0tIC1YtjqDbxdg3G42hbv/x6Unl/Uh9CMZaP51aP8ve1gEtWdgVEbLwYWyYtfc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793016950233487.72231717145667; Mon, 26 Oct 2026 05:15:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLJbT-0002ef-Vj; Mon, 26 Oct 2026 08:15:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPF-0002mh-4Z for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:18 -0400 Received: from esa8.hc1455-7.c3s2.iphmx.com ([139.138.61.253]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPD-00080Z-2C for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:16 -0400 Received: from gmgwuk01.global.fujitsu.com ([172.187.114.235]) by esa8.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2026 18:54:14 +0900 Received: from az2uksmgm2.o.css.fujitsu.com (unknown [10.151.22.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by gmgwuk01.global.fujitsu.com (Postfix) with ESMTPS id 39ECDC01AED for ; Mon, 26 Oct 2026 09:54:14 +0000 (UTC) Received: from m3003.s.css.fujitsu.com (unknown [10.128.233.114]) by az2uksmgm2.o.css.fujitsu.com (Postfix) with ESMTP id 9FA4C1800276 for ; Mon, 26 Oct 2026 09:54:13 +0000 (UTC) Received: from tanjiro.soft.fujitsu.com (unknown [10.118.236.61]) by m3003.s.css.fujitsu.com (Postfix) with ESMTP id 63690202EBDE; Mon, 26 Oct 2026 18:54:12 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1793008455; x=1824544455; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RYV8jtdiDIttht3TRaM0y5nY4jvIepG6G6eTEjUpCEU=; b=O13mroCb2bN3qHprTmvJdK8JMjNtKuXnDjB5UHwXDjxnCaiH7qTMNJEI nhURbfn2RqpVmFWTX4kvJvUo9TyQk4ChoKDlbNaPPTrr0E/8XjrVH/90p UUAO19MO3bnKz9NJyPgSlDgIU58IyGH2EYfn4AKooOHZVnFK+zKdlcj0f pDPlsYpZHIhfUGBL/4LDGQOOLGDJHblon8tWeOKzvbj4rQUqYYucvuTHx dlSZeXlCSYwvtnvo76bOCzceUsMLJIyIneeFW1mAfRkZRVvA6ulHr91/4 m/s822CtjvREMCu6Hwzyqh+3f+toID3d+L9H10Z8zN55UejcL+DSdQeOF Q==; X-CSE-ConnectionGUID: m+RKfld6Tkqetn64k/YGGw== X-CSE-MsgGUID: ulL2bKh9Q0exQrnwGV3hmA== X-IronPort-AV: E=McAfee;i="6800,10657,11946"; a="247435609" X-IronPort-AV: E=Sophos;i="6.27,179,1786978800"; d="scan'208";a="247435609" To: qemu-devel@nongnu.org Cc: Yukiya Takaki , "Michael S. Tsirkin" , Anisa Su , Jonathan Cameron , Junjie Cao , linux-cxl@vger.kernel.org, "Wolski, Tomasz" , lizhijian@fujitsu.com, y-goto@fujitsu.com, yukiya.takaki@gmail.com Subject: [PATCH RFC 4/7] =?UTF-8?q?QEMU/hw/cxl:=20auto=E2=80=91program=20H?= =?UTF-8?q?DM=20decoders=20for=20CXL=20Type=203?= Date: Mon, 26 Oct 2026 19:03:25 +0900 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=139.138.61.253; envelope-from=fj2110jc@fujitsu.com; helo=esa8.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 26 Oct 2026 08:14:57 -0400 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: Yukiya Takaki From: Yukiya Takaki via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793016951251158500 On some real systems, firmware programs the HDM decoders on both the endpoint and the CXL host bridge so that the OS can discover CXL memory ranges at boot and the CXL driver can automatically create regions. This patch adds helpers to program the HDM decoders in QEMU using the per=E2=80=91device HPA range from `ct3_type3_get_hpm_range()`, and wires th= em into the CXL Type 3 reset path. When `program_hdm_decoder` is enabled, both the endpoint and host=E2=80=91bridge HDM decoders are configured so th= at the guest sees the same kind of automatically assigned CXL regions as on real hardware. The reset hold phase processes child devices before their parents. Consequently, the Type 3 reset handler programs the host bridge decoder before the pxb-cxl reset handler runs. Calling cxl_component_register_init_common() from the pxb-cxl reset handler would then clear the component register block and erase the decoder configuration that was just programmed. When the affected HPA ranges are advertised through E820 and SRAT, which will be added in the following patches, Linux attempts to use them as system memory. Without a valid host bridge decoder, accesses to these ranges cannot be routed to the Type 3 devices. This corrupts kernel memory-management data and eventually causes a kernel panic. Initialize the common host bridge component registers when the PXB is realized instead. Keep the reset handler limited to the topology-dependent HDM capability setup so that the automatically programmed decoder settings are not overwritten. Co-developed-by: Li Zhijian Signed-off-by: Yukiya Takaki --- hw/mem/cxl_type3.c | 98 +++++++++++++++++++++++++++++ hw/pci-bridge/pci_expander_bridge.c | 13 +++- 2 files changed, 109 insertions(+), 2 deletions(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 811f8e247d..60e4c0e20f 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -19,6 +19,9 @@ #include "hw/pci/pci.h" #include "hw/core/qdev-properties.h" #include "hw/core/qdev-properties-system.h" +#include "hw/pci/pci_bridge.h" +#include "hw/pci/pcie_port.h" +#include "hw/cxl/cxl_host.h" #include "qapi/error.h" #include "qemu/log.h" #include "qemu/module.h" @@ -1358,6 +1361,59 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr hos= t_addr, uint64_t data, return address_space_write(as, dpa_offset, attrs, &data, size); } =20 +static void __update_hdm_decoder_n(uint32_t *cache_mem, int which, + uint32_t ctrl, uint64_t base, + uint64_t size) +{ + int hdm_inc =3D R_CXL_HDM_DECODER1_BASE_LO - R_CXL_HDM_DECODER0_BASE_L= O; + + stl_le_p(cache_mem + R_CXL_HDM_DECODER0_BASE_LO + which * hdm_inc, + base & 0xffffffff); + stl_le_p(cache_mem + R_CXL_HDM_DECODER0_BASE_HI + which * hdm_inc, + base >> 32); + stl_le_p(cache_mem + R_CXL_HDM_DECODER0_SIZE_LO + which * hdm_inc, + size & 0xffffffff); + stl_le_p(cache_mem + R_CXL_HDM_DECODER0_SIZE_HI + which * hdm_inc, + size >> 32); + stl_le_p(cache_mem + R_CXL_HDM_DECODER0_CTRL + which * hdm_inc, ctrl); +} + +static void update_hdm_decoder_endpoint(uint32_t *cache_mem, int which, + uint32_t ctrl, uint64_t base, + uint64_t size) +{ + return __update_hdm_decoder_n(cache_mem, which, ctrl, base, size); +} + +static void update_hdm_decoder_pxb(uint32_t *cache_mem, int which, + uint64_t tl, uint32_t ctrl, + uint64_t base, uint64_t size) +{ + int hdm_inc =3D R_CXL_HDM_DECODER1_BASE_LO - R_CXL_HDM_DECODER0_BASE_L= O; + + stl_le_p(cache_mem + + R_CXL_HDM_DECODER0_TARGET_LIST_LO + which * hdm_inc, + tl & 0xffffffff); + stl_le_p(cache_mem + + R_CXL_HDM_DECODER0_TARGET_LIST_HI + which * hdm_inc, + tl >> 32); + + __update_hdm_decoder_n(cache_mem, which, ctrl, base, size); +} + +static uint8_t ct3d_root_port_number(DeviceState *dev) +{ + BusState *bus =3D dev->parent_bus; + DeviceState *rp_dev; + + assert(bus); + rp_dev =3D bus->parent; + assert(rp_dev); + assert(object_dynamic_cast(OBJECT(rp_dev), TYPE_PCIE_ROOT_PORT)); + + return PCIE_PORT(rp_dev)->port; +} + static uint64_t c3t_addr_size(DeviceState *dev) { CXLType3Dev *ct3d =3D CXL_TYPE3(dev); @@ -1398,6 +1454,42 @@ void ct3_type3_get_hpm_range(CXLType3Dev *dev, uint6= 4_t *base, uint64_t *size) *size =3D c3t_addr_size(DEVICE(dev)); } =20 +static void program_pxb_hdm_decoder(DeviceState *dev) +{ + CXLHost *cxl =3D ct3d_to_cxl_pxb(dev); + CXLType3Dev *ct3d =3D CXL_TYPE3(dev); + int hdm_num =3D ct3d->idx; + int order =3D ct3d_root_port_number(dev); + assert(cxl); + uint64_t base, size; + ct3_type3_get_hpm_range(ct3d, &base, &size); + + CXLComponentState *cxl_cstate =3D &cxl->cxl_cstate; + uint32_t *cache_mem =3D cxl_cstate->crb.cache_mem_registers; + + uint32_t ctrl =3D R_CXL_HDM_DECODER0_CTRL_COMMIT_MASK | + R_CXL_HDM_DECODER0_CTRL_COMMITTED_MASK | + R_CXL_HDM_DECODER0_CTRL_TYPE_MASK; + + update_hdm_decoder_pxb(cache_mem, hdm_num, order, ctrl, base, size); +} + +static void program_hdm_decoder(DeviceState *dev) +{ + CXLType3Dev *ct3d =3D CXL_TYPE3(dev); + uint64_t base, size; + ComponentRegisters *cregs =3D &ct3d->cxl_cstate.crb; + uint32_t *cache_mem =3D cregs->cache_mem_registers; + + ct3_type3_get_hpm_range(ct3d, &base, &size); + + uint32_t ctrl =3D R_CXL_HDM_DECODER0_CTRL_COMMIT_MASK | + R_CXL_HDM_DECODER0_CTRL_COMMITTED_MASK | + R_CXL_HDM_DECODER0_CTRL_TYPE_MASK; + + update_hdm_decoder_endpoint(cache_mem, 0, ctrl, base, size); +} + static void ct3d_reset(DeviceState *dev) { CXLType3Dev *ct3d =3D CXL_TYPE3(dev); @@ -1408,6 +1500,12 @@ static void ct3d_reset(DeviceState *dev) ct3d->flitmode); cxl_component_register_init_common(reg_state, write_msk, CXL2_TYPE3_DEVICE, ct3d->hdmdb); + + if (ct3d->program_hdm_decoder) { + program_hdm_decoder(dev); + program_pxb_hdm_decoder(dev); + } + cxl_device_register_init_t3(ct3d, CXL_T3_MSIX_MBOX); =20 /* diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expand= er_bridge.c index 40ffbc4e08..e8fd7343d1 100644 --- a/hw/pci-bridge/pci_expander_bridge.c +++ b/hw/pci-bridge/pci_expander_bridge.c @@ -297,16 +297,24 @@ static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin) return pin - PCI_SLOT(pxb->devfn); } =20 +static void pxb_cxl_dev_init(DeviceState *dev) +{ + CXLHost *cxl =3D PXB_CXL_DEV(dev)->cxl_host_bridge; + CXLComponentState *cxl_cstate =3D &cxl->cxl_cstate; + uint32_t *reg_state =3D cxl_cstate->crb.cache_mem_registers; + uint32_t *write_msk =3D cxl_cstate->crb.cache_mem_regs_write_mask; + + cxl_component_register_init_common(reg_state, write_msk, CXL2_RC, fals= e); +} + static void pxb_cxl_dev_reset(DeviceState *dev) { CXLHost *cxl =3D PXB_CXL_DEV(dev)->cxl_host_bridge; CXLComponentState *cxl_cstate =3D &cxl->cxl_cstate; PCIHostState *hb =3D PCI_HOST_BRIDGE(cxl); uint32_t *reg_state =3D cxl_cstate->crb.cache_mem_registers; - uint32_t *write_msk =3D cxl_cstate->crb.cache_mem_regs_write_mask; int dsp_count =3D 0; =20 - cxl_component_register_init_common(reg_state, write_msk, CXL2_RC, fals= e); /* * The CXL specification allows for host bridges with no HDM decoders * if they only have a single root port. @@ -507,6 +515,7 @@ static void pxb_cxl_dev_realize(PCIDevice *dev, Error *= *errp) if (!pxb_dev_realize_common(dev, CXL, errp)) { return; } + pxb_cxl_dev_init(DEVICE(dev)); pxb_cxl_dev_reset(DEVICE(dev)); } =20 --=20 2.52.0 From nobody Mon Nov 23 04:34:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793017031; cv=none; d=zohomail.com; s=zohoarc; b=TD9+Nq73oKqv6f67JWOalyYv0dkRomEROJBeN3zOy5+ouFimVFJOyzq1Texp82gKrfldrUnoIECaDu/F0qHOCPdXmSFW3ZuKWpuNLdgbnYC14RCPL3VkaiikJ7+9FAAtKYhCWYWkmDXoNbEc1KaN5millSoBI1JWxcg2pzKT75s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793017031; h=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:Sender:Subject:Subject:To:To:Message-Id; bh=ekbeFNQZH2lTXrOWvMGo8eYksN7lsrG6Xfp33htCj7Q=; b=YSmqclJA081r4fQV2vBjwli7c3vswCkiJ3exSqa87ydZlUVb3ZRzptb806E6UPDbMN803hOl6dXo6ecUdaSp/6T45SXuSk+MjNOEA3ORFm2wX10xh7/NOmnu4FTm1fMGHGYD98F0UY4tsX+aQDKIpvW25ro7kGv0VoKUe/pUf/8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793017031841280.5660299969285; Mon, 26 Oct 2026 05:17:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLJbP-0002Ri-N5; Mon, 26 Oct 2026 08:14:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPI-0002nC-NZ; Mon, 26 Oct 2026 05:54:22 -0400 Received: from esa12.hc1455-7.c3s2.iphmx.com ([139.138.37.100]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPG-00081b-9A; Mon, 26 Oct 2026 05:54:20 -0400 Received: from gmgwuk01.global.fujitsu.com ([172.187.114.235]) by esa12.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2026 18:54:16 +0900 Received: from az2uksmgm2.o.css.fujitsu.com (unknown [10.151.22.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by gmgwuk01.global.fujitsu.com (Postfix) with ESMTPS id 42C77C020DB; Mon, 26 Oct 2026 09:54:16 +0000 (UTC) Received: from m3003.s.css.fujitsu.com (unknown [10.128.233.114]) by az2uksmgm2.o.css.fujitsu.com (Postfix) with ESMTP id AF66E18002D1; Mon, 26 Oct 2026 09:54:15 +0000 (UTC) Received: from tanjiro.soft.fujitsu.com (unknown [10.118.236.61]) by m3003.s.css.fujitsu.com (Postfix) with ESMTP id 61058202EBDE; Mon, 26 Oct 2026 18:54:14 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1793008458; x=1824544458; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6z8lEk1AeWECdTspXda6U7FgVtrO8TNGfV5ZPDt7sUE=; b=TWwughNa3fiPeP0I6RdeF01SUvzfY7TPkThFpmvWHBgZe1JKku8h2JLT 9M4Z8NkESVr+TpjFgtDv08J2Xl3ikAUJEx41jvfVq/lwMQffhaXUM3WOW CtVD1AJw6BXzO3FjtwDO6bjoj7SppgnjnTO78ulMRl6nHCwpUjkM7vPlR tfH30ZnX6JUH44ENp8yh6I35Y0yVYoiu/Sx0sSbfDQZAcib6ztu74jO11 r4WIa4+xIMUpF+pA0BvTBtdktBvhHBtQoY07fs7xZKQhbxedtisA8VqAL jPRabqCTXkpaSCS1L1eXrddrykncTWOJhkr87lEzC68aweMdxRE8mql7g A==; X-CSE-ConnectionGUID: FVXmPABPR8mvVJCrm3pRWA== X-CSE-MsgGUID: aT+7mxdtSIuv2Bzyh8W67g== X-IronPort-AV: E=McAfee;i="6800,10657,11946"; a="237204752" X-IronPort-AV: E=Sophos;i="6.27,179,1786978800"; d="scan'208";a="237204752" To: qemu-devel@nongnu.org Cc: Yukiya Takaki , "Michael S. Tsirkin" , Anisa Su , Jonathan Cameron , Junjie Cao , Paolo Bonzini , Peter Maydell , Richard Henderson , linux-cxl@vger.kernel.org, qemu-arm@nongnu.org, "Wolski, Tomasz" , lizhijian@fujitsu.com, y-goto@fujitsu.com, yukiya.takaki@gmail.com Subject: [PATCH RFC 5/7] QEMU/hw/cxl: expose CXL Type 3 ranges as E820_SOFT_RESERVED on x86 Date: Mon, 26 Oct 2026 19:03:26 +0900 Message-ID: <06c1447e554c2b353c029d0e0c0ef6dd38c46e41.1793003983.git.fj2110jc@fujitsu.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=139.138.37.100; envelope-from=fj2110jc@fujitsu.com; helo=esa12.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 26 Oct 2026 08:14:57 -0400 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: Yukiya Takaki From: Yukiya Takaki via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793017032837158500 Content-Type: text/plain; charset="utf-8" On real systems, CXL Type 3 memory is exposed to the OS via the E820 table as E820_SOFT_RESERVED, so the kernel can treat it as a dedicated reserved range rather than normal RAM. This patch adds a small helper and a recursive walker so that, on x86, the HPA ranges assigned to CXL Type 3 devices are added to the E820 table as E820_SOFT_RESERVED when `program_hdm_decoder` is enabled. An ARM stub is also added as a placeholder for future support. Signed-off-by: Yukiya Takaki --- hw/arm/cxl.c | 10 ++++++++++ hw/arm/meson.build | 2 ++ hw/cxl/cxl-host.c | 25 +++++++++++++++++++++++++ hw/i386/cxl.c | 11 +++++++++++ hw/i386/meson.build | 1 + hw/i386/pc.c | 1 + include/hw/cxl/cxl_host.h | 2 ++ 7 files changed, 52 insertions(+) create mode 100644 hw/arm/cxl.c create mode 100644 hw/i386/cxl.c diff --git a/hw/arm/cxl.c b/hw/arm/cxl.c new file mode 100644 index 0000000000..1cbcf2d8e5 --- /dev/null +++ b/hw/arm/cxl.c @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" +#include "exec/hwaddr.h" +#include "hw/cxl/cxl_host.h" + +void cxl_c3_add_memory_map(hwaddr base, hwaddr size) +{ + /* TODO: Implement memory map addition for CXL Type 3 on ARM */ +} diff --git a/hw/arm/meson.build b/hw/arm/meson.build index bcc068de04..2a4f09fbef 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -116,6 +116,8 @@ arm_common_ss.add(when: ['CONFIG_AXIADO_EVK', 'TARGET_A= ARCH64'], if_true: files( 'ax3000-boards.c', 'ax3000-evk.c')) =20 +arm_common_ss.add(when: 'CONFIG_CXL', if_true: files('cxl.c')) + arm_common_ss.add(files('boot.c')) =20 hw_common_arch +=3D {'arm': arm_common_ss} diff --git a/hw/cxl/cxl-host.c b/hw/cxl/cxl-host.c index e279ce5fe3..1967c9a9c3 100644 --- a/hw/cxl/cxl-host.c +++ b/hw/cxl/cxl-host.c @@ -689,12 +689,37 @@ static int cxl_fmws_mmio_map(Object *obj, void *opaqu= e) return 0; } =20 +static int cxl_c3_mmio_map(Object *obj, void *opaque) +{ + uint64_t base, size; + CXLType3Dev *c3d; + + if (!object_dynamic_cast(obj, TYPE_CXL_TYPE3)) { + return 0; + } + c3d =3D CXL_TYPE3(obj); + + if (!c3d->program_hdm_decoder) { + return 0; + } + + ct3_type3_get_hpm_range(c3d, &base, &size); + cxl_c3_add_memory_map(base, size); + + return 0; +} + void cxl_fmws_update_mmio(void) { /* Ordering is not required for this */ object_child_foreach_recursive(object_get_root(), cxl_fmws_mmio_map, N= ULL); } =20 +void cxl_c3_update_mmio(void) +{ + object_child_foreach_recursive(object_get_root(), cxl_c3_mmio_map, NUL= L); +} + hwaddr cxl_fmws_set_memmap(hwaddr base, hwaddr max_addr) { GSList *cfmws_list, *iter; diff --git a/hw/i386/cxl.c b/hw/i386/cxl.c new file mode 100644 index 0000000000..02dbe4d3f0 --- /dev/null +++ b/hw/i386/cxl.c @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" +#include "exec/hwaddr.h" +#include "hw/cxl/cxl_host.h" +#include "hw/i386/e820_memory_layout.h" + +void cxl_c3_add_memory_map(hwaddr base, hwaddr size) +{ + e820_add_entry(base, size, E820_SOFT_RESERVED); +} diff --git a/hw/i386/meson.build b/hw/i386/meson.build index e16930c431..b212b3f6fa 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -24,6 +24,7 @@ i386_ss.add(when: 'CONFIG_VTD', if_true: files('intel_iom= mu.c')) i386_ss.add(when: 'CONFIG_VTD_ACCEL', if_true: files('intel_iommu_accel.c'= )) i386_ss.add(when: 'CONFIG_SGX', if_true: files('sgx-epc.c','sgx.c'), if_false: files('sgx-stub.c')) +i386_ss.add(when: 'CONFIG_CXL', if_true: files('cxl.c')) if have_hmp stub_ss.add(files('sgx-hmp-stub.c')) endif diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2d8c87b0e3..f843629543 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -534,6 +534,7 @@ void pc_machine_done(Notifier *notifier, void *data) =20 if (pcms->cxl_devices_state.is_enabled) { cxl_fmws_link_targets(&error_fatal); + cxl_c3_update_mmio(); } =20 /* set the number of CPUs */ diff --git a/include/hw/cxl/cxl_host.h b/include/hw/cxl/cxl_host.h index 21619bb748..6c142a5b89 100644 --- a/include/hw/cxl/cxl_host.h +++ b/include/hw/cxl/cxl_host.h @@ -18,6 +18,8 @@ void cxl_fmws_link_targets(Error **errp); void cxl_hook_up_pxb_registers(PCIBus *bus, CXLState *state, Error **errp); hwaddr cxl_fmws_set_memmap(hwaddr base, hwaddr max_addr); void cxl_fmws_update_mmio(void); +void cxl_c3_update_mmio(void); +void cxl_c3_add_memory_map(hwaddr base, hwaddr size); GSList *cxl_fmws_get_all_sorted(void); =20 extern const MemoryRegionOps cfmws_ops; --=20 2.52.0 From nobody Mon Nov 23 04:34:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793016959; cv=none; d=zohomail.com; s=zohoarc; b=my5k9WcnV5mUixtKumv0BaNj2lMwM5IsnH0zB1Bc9IVCcT4LL2stR5a1zUparrDv/UYWdNc/gWQXQ1wG2Jw0IQUdO7ReGBD0hctQ5An0E0+HR1qgY341+0lXbI79/fwIT8SdxEi7x1WrPH/l+T7Xf0Vr1zcassD/CRD9xtuMzWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793016959; h=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:Sender:Subject:Subject:To:To:Message-Id; bh=lmVQfXYIzgB6L0ACcyKETNWaJF23xJdhHwPP0NjJAVw=; b=WtKMEn3V+7AhpwdO8WuPfBsr2RJfVBpn4xEH56YMwA2IN+8vIx6WVlXOUFdt9DgAcYErMlqwQo06YtwMAaj1sm6UpJyZffkF+U6dEyhlhXGIW3/u3nftQI+tk4fADrA88O5Ll/dsN9actpPKMLXY8JGHsISbPuM94EoQ3iLkRk4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793016959197387.3247844090748; Mon, 26 Oct 2026 05:15:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLJbO-0002MQ-93; Mon, 26 Oct 2026 08:14:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPK-0002nI-Je for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:25 -0400 Received: from esa3.hc1455-7.c3s2.iphmx.com ([207.54.90.49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPH-00081p-Vp for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:21 -0400 Received: from gmgwuk01.global.fujitsu.com ([172.187.114.235]) by esa3.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2026 18:54:20 +0900 Received: from az2uksmgm2.o.css.fujitsu.com (unknown [10.151.22.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by gmgwuk01.global.fujitsu.com (Postfix) with ESMTPS id 55488820732 for ; Mon, 26 Oct 2026 09:54:18 +0000 (UTC) Received: from m3003.s.css.fujitsu.com (unknown [10.128.233.114]) by az2uksmgm2.o.css.fujitsu.com (Postfix) with ESMTP id BBB6B180025B for ; Mon, 26 Oct 2026 09:54:17 +0000 (UTC) Received: from tanjiro.soft.fujitsu.com (unknown [10.118.236.61]) by m3003.s.css.fujitsu.com (Postfix) with ESMTP id 78101202EBDE; Mon, 26 Oct 2026 18:54:16 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1793008461; x=1824544461; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zik1LQCP4muzbLl4LIyGNKML35lWt8i7n3q+ukChy+c=; b=sKzCggFM8qn7Bf4QWevbFDeKQS9IilWBWRHBeDA8KbcziqdXmW+PZGjQ ri03T+7SEDWJKwJRP86E4a3bhfcaS4s5/0sf9bHBPkQgkrTxHBBqngIeX oPtVxmzloyyHHByrwgJZz9gNjjUm/PxVVBKirTvShHlT6yV0y+DDTE+wC 3HTCc/mNMUGicP1TXa+o9DvSM2dijBqBZ21SPC9CWnBAXL/fKACKZGIRQ CEFav5BlzXDIdIiIF18v9N+2zM/JuuFcT4DBqnthLrn8C5pB2UCf8+iue tyFQfWsOD+9guEiAfagBD/yisAmK/op1oRQKRzi5qF6UqQ26jJclexFCG w==; X-CSE-ConnectionGUID: 1BSE75S9TaqsUPDLIemF1Q== X-CSE-MsgGUID: 5ByKEOAxQgKsghCHXl9zdQ== X-IronPort-AV: E=McAfee;i="6800,10657,11946"; a="259392330" X-IronPort-AV: E=Sophos;i="6.27,179,1786978800"; d="scan'208";a="259392330" To: qemu-devel@nongnu.org Cc: Yukiya Takaki , "Michael S. Tsirkin" , Anisa Su , Jonathan Cameron , Junjie Cao , Paolo Bonzini , Richard Henderson , linux-cxl@vger.kernel.org, "Wolski, Tomasz" , lizhijian@fujitsu.com, y-goto@fujitsu.com, yukiya.takaki@gmail.com Subject: [PATCH RFC 6/7] QEMU/hw/cxl: Create NUMA nodes for CXL Type 3 memory Date: Mon, 26 Oct 2026 19:03:27 +0900 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=207.54.90.49; envelope-from=fj2110jc@fujitsu.com; helo=esa3.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 26 Oct 2026 08:14:57 -0400 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: Yukiya Takaki From: Yukiya Takaki via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793016961458158500 Content-Type: text/plain; charset="utf-8" On the actual hardware, CXL memory is exposed to the OS as a "Memory Only N= ode." This allows the OS to recognize that accessing CXL memory takes time. As a preliminary step, a function was created to automatically add a NUMA n= ode for each instance of CXL memory. This function generates one NUMA node per instance of CXL memory. This function is executed when program_hdm_decoder is set. Signed-off-by: Yukiya Takaki --- hw/cxl/cxl-host.c | 38 +++++++++++++++++++++++++++++++++++++ hw/i386/pc.c | 1 + include/hw/cxl/cxl_device.h | 1 + include/hw/cxl/cxl_host.h | 1 + 4 files changed, 41 insertions(+) diff --git a/hw/cxl/cxl-host.c b/hw/cxl/cxl-host.c index 1967c9a9c3..ba321841dc 100644 --- a/hw/cxl/cxl-host.c +++ b/hw/cxl/cxl-host.c @@ -720,6 +720,44 @@ void cxl_c3_update_mmio(void) object_child_foreach_recursive(object_get_root(), cxl_c3_mmio_map, NUL= L); } =20 +static int setup_cxl_numa_node_inner(Object *obj, void *opaque) +{ + MachineState *machine =3D opaque; + DeviceState *dev; + CXLType3Dev *c3d; + int node_id; + + if (!object_dynamic_cast(obj, TYPE_CXL_TYPE3)) { + return 0; + } + + dev =3D DEVICE(obj); + c3d =3D CXL_TYPE3(dev); + node_id =3D machine->numa_state->num_nodes; + + if (!c3d->program_hdm_decoder) { + return 0; + } + + NumaOptions option =3D { + .type =3D NUMA_OPTIONS_TYPE_NODE, + .u.node =3D { + .has_nodeid =3D true, + .nodeid =3D node_id, + }, + }; + + set_numa_options(machine, &option, &error_fatal); + c3d->node =3D node_id; + return 0; +} + +void setup_cxl_numa_node(MachineState *machine) +{ + object_child_foreach_recursive(object_get_root(), + setup_cxl_numa_node_inner, machine); +} + hwaddr cxl_fmws_set_memmap(hwaddr base, hwaddr max_addr) { GSList *cfmws_list, *iter; diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f843629543..b1d1f03468 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -534,6 +534,7 @@ void pc_machine_done(Notifier *notifier, void *data) =20 if (pcms->cxl_devices_state.is_enabled) { cxl_fmws_link_targets(&error_fatal); + setup_cxl_numa_node(MACHINE(pcms)); cxl_c3_update_mmio(); } =20 diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 07654f4b62..9001aacf0e 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -780,6 +780,7 @@ struct CXLType3Dev { bool program_hdm_decoder; hwaddr hpa_offset; int idx; + int node; =20 struct dynamic_capacity { HostMemoryBackend *host_dc; diff --git a/include/hw/cxl/cxl_host.h b/include/hw/cxl/cxl_host.h index 6c142a5b89..70285328c4 100644 --- a/include/hw/cxl/cxl_host.h +++ b/include/hw/cxl/cxl_host.h @@ -19,6 +19,7 @@ void cxl_hook_up_pxb_registers(PCIBus *bus, CXLState *sta= te, Error **errp); hwaddr cxl_fmws_set_memmap(hwaddr base, hwaddr max_addr); void cxl_fmws_update_mmio(void); void cxl_c3_update_mmio(void); +void setup_cxl_numa_node(MachineState *machine); void cxl_c3_add_memory_map(hwaddr base, hwaddr size); GSList *cxl_fmws_get_all_sorted(void); =20 --=20 2.52.0 From nobody Mon Nov 23 04:34:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1793016933; cv=none; d=zohomail.com; s=zohoarc; b=KxOY8XaziE3ND1CSAzzwm9ZBTo0vpOSsHXFg927Pqw5aPxMdiuWg2R2FzmK2UBMnsWsn7pM37iXaMM2c5ULMiPDdyZaFANcj7XYC1hpL0NxYd25auHmhg+ffUQlkBZsA99loMJftG6PFSs7hOlIDj4c8PDIVjf8m5SGDj4xo2cM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793016933; 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:Sender:Subject:Subject:To:To:Message-Id; bh=rP/4fQ8hd2oNMpmNP0n8I+V4OuGa+s6U0Wk5jbeAOMI=; b=QFQw1cPMvv9wsTKtdWhhxKxM8lbtOxkEd0mulpuENnSZLsfA89ji7d8kZqtMDXyfJLC/c4Tb15QK4jcWM7hn22/+52xoPHPASN/RSb4U6fshlup16GVH5FgzmtWTkcUCGtzqVTFgRFCqbWU07mS9DGevcqycfm+IB0MBiibNnm0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@fujitsu.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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793016933230212.8905008310444; Mon, 26 Oct 2026 05:15:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLJbT-0002dP-J8; Mon, 26 Oct 2026 08:15:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPM-0002nW-JI for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:26 -0400 Received: from esa5.hc1455-7.c3s2.iphmx.com ([68.232.139.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLHPK-000820-CO for qemu-devel@nongnu.org; Mon, 26 Oct 2026 05:54:24 -0400 Received: from gmgwnl01.global.fujitsu.com ([52.143.17.124]) by esa5.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2026 18:54:20 +0900 Received: from az2nlsmgm1.o.css.fujitsu.com (unknown [10.150.26.203]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by gmgwnl01.global.fujitsu.com (Postfix) with ESMTPS id 3C7A442A327 for ; Mon, 26 Oct 2026 09:54:20 +0000 (UTC) Received: from m3003.s.css.fujitsu.com (unknown [10.128.233.114]) by az2nlsmgm1.o.css.fujitsu.com (Postfix) with ESMTP id AA145C00218 for ; Mon, 26 Oct 2026 09:54:19 +0000 (UTC) Received: from tanjiro.soft.fujitsu.com (unknown [10.118.236.61]) by m3003.s.css.fujitsu.com (Postfix) with ESMTP id 742A3202EBDE; Mon, 26 Oct 2026 18:54:18 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1793008462; x=1824544462; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kLKxlm+BQ650xZa4ALIBpQz5RtaIkt0udZ+BW/aSd4Q=; b=ieZXiHY9W3Ys2WvPzahCrOgI0GJWHLr6HlMWis2fx6k7oUXLM6YjduGm 6WiksBZJ9uVpHM83o8Z0scA3JJFub+4KFa1b43GcYzudyxBncu5wGdE7W WdHdhMh2+WMaVYIqMZD/rzf4xjrrv/2VRmooGF7Bx/S8YEvWccsO41uac k6d+WbCO2ypr92uhdhsGVC6nlXxQpsdJjS5oJ+SUKbMfIUpaN6UMcy4cQ aUjkXLlGK2jF4hijQ7oelJiWX5HZf+9EqC30TrjNBZ228dpp1VCs4Uf6O 4qGGu1z5mYDKaoJfW3wACSFNGS9kCXDP5G/XtlNHv280inyzrmq5R+2zL w==; X-CSE-ConnectionGUID: ihdYMzWRQmWamebMUIoS3Q== X-CSE-MsgGUID: afVnxItOR32wjl1AnEGrPw== X-IronPort-AV: E=McAfee;i="6800,10657,11946"; a="257684911" X-IronPort-AV: E=Sophos;i="6.27,179,1786978800"; d="scan'208";a="257684911" To: qemu-devel@nongnu.org Cc: Yukiya Takaki , "Michael S. Tsirkin" , Ani Sinha , Igor Mammedov , Paolo Bonzini , Richard Henderson , "Wolski, Tomasz" , lizhijian@fujitsu.com, y-goto@fujitsu.com, yukiya.takaki@gmail.com Subject: [PATCH RFC 7/7] add CXL Type 3 memory ranges to SRAT Date: Mon, 26 Oct 2026 19:03:28 +0900 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=68.232.139.130; envelope-from=fj2110jc@fujitsu.com; helo=esa5.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 26 Oct 2026 08:14:57 -0400 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: Yukiya Takaki From: Yukiya Takaki via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1793016934928158500 On Linux, the kernel first checks E820_SOFT_RESERVED ranges, and when multiple CXL Type 3 devices share a contiguous HPA range those ranges tend to be merged into a single region. In that case, the CXL driver cannot reliably initialize per=E2=80=91device regions based on E820 alone. To let the OS distinguish CXL Type 3 memory from normal RAM and associate it with the =E2=80=9Cmemory only=E2=80=9D NUMA nodes created earlier, SRAT = needs entries for the host physical address ranges assigned to CXL Type 3 devices. This patch adds a helper that walks CXL Type 3 devices, obtains their HPA ranges via `ct3_type3_get_hpm_range()`, and emits SRAT memory affinity entries using the NUMA node IDs stored on each device. This runs only when CXL is enabled and `program_hdm_decoder` is set. Signed-off-by: Yukiya Takaki --- hw/acpi/cxl_type3.c | 30 ++++++++++++++++++++++++++++++ hw/acpi/meson.build | 1 + hw/i386/acpi-build.c | 7 +++++++ include/hw/mem/cxl_type3.h | 8 ++++++++ 4 files changed, 46 insertions(+) create mode 100644 hw/acpi/cxl_type3.c create mode 100644 include/hw/mem/cxl_type3.h diff --git a/hw/acpi/cxl_type3.c b/hw/acpi/cxl_type3.c new file mode 100644 index 0000000000..4cad270257 --- /dev/null +++ b/hw/acpi/cxl_type3.c @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" + +#include "hw/acpi/aml-build.h" +#include "hw/cxl/cxl_device.h" +#include "hw/mem/cxl_type3.h" + +int cxl_type3_build_srat(Object *obj, void *opaque) +{ + GArray *table_data =3D opaque; + DeviceState *dev; + CXLType3Dev *c3d; + uint64_t addr, size; + if (!object_dynamic_cast(obj, TYPE_CXL_TYPE3)) { + return 0; + } + dev =3D DEVICE(obj); + c3d =3D CXL_TYPE3(dev); + + if (!c3d->program_hdm_decoder) { + return 0; + } + + ct3_type3_get_hpm_range(c3d, &addr, &size); + + build_srat_memory(table_data, addr, size, c3d->node, + MEM_AFFINITY_ENABLED | MEM_AFFINITY_HOTPLUGGABLE); + return 0; +} diff --git a/hw/acpi/meson.build b/hw/acpi/meson.build index 09ad488a04..b1def538bd 100644 --- a/hw/acpi/meson.build +++ b/hw/acpi/meson.build @@ -13,6 +13,7 @@ acpi_ss.add(when: 'CONFIG_ACPI_NVDIMM', if_true: files('n= vdimm.c')) stub_ss.add(files('acpi-nvdimm-stub.c')) acpi_ss.add(when: 'CONFIG_ACPI_PCI', if_true: files('pci.c')) acpi_ss.add(when: 'CONFIG_ACPI_CXL', if_true: files('cxl.c')) +acpi_ss.add(when: 'CONFIG_CXL_MEM_DEVICE', if_true: files('cxl_type3.c')) stub_ss.add(files('cxl-stub.c')) acpi_ss.add(when: 'CONFIG_ACPI_VMGENID', if_true: files('vmgenid.c')) acpi_ss.add(when: 'CONFIG_ACPI_VMCLOCK', if_true: files('vmclock.c')) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 6d7308b4e4..2f607f3ec9 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -51,6 +51,7 @@ #include "hw/rtc/mc146818rtc_regs.h" #include "migration/vmstate.h" #include "hw/mem/memory-device.h" +#include "hw/mem/cxl_type3.h" #include "hw/mem/nvdimm.h" #include "hw/mem/sp-mem.h" #include "system/numa.h" @@ -1460,6 +1461,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, Ma= chineState *machine) uint64_t mem_len, mem_base, next_base; MachineClass *mc =3D MACHINE_GET_CLASS(machine); X86MachineState *x86ms =3D X86_MACHINE(machine); + PCMachineState *pcms =3D PC_MACHINE(machine); const CPUArchIdList *apic_ids =3D mc->possible_cpu_arch_ids(machine); int nb_numa_nodes =3D machine->numa_state->num_nodes; NodeInfo *numa_info =3D machine->numa_state->nodes; @@ -1584,6 +1586,11 @@ build_srat(GArray *table_data, BIOSLinker *linker, M= achineState *machine) build_srat_device_memory(table_data, machine); } =20 + if (pcms->cxl_devices_state.is_enabled) { + object_child_foreach_recursive(object_get_root(), + cxl_type3_build_srat, table_data); + } + acpi_table_end(linker, &table); } =20 diff --git a/include/hw/mem/cxl_type3.h b/include/hw/mem/cxl_type3.h new file mode 100644 index 0000000000..15a204d66a --- /dev/null +++ b/include/hw/mem/cxl_type3.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef QEMU_CXL_TYPE3_H +#define QEMU_CXL_TYPE3_H + +int cxl_type3_build_srat(Object *obj, void *opaque); + +#endif --=20 2.52.0