From nobody Sat Nov 29 10:48:41 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=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