From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E5F51E570E for ; Tue, 3 Dec 2024 17:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733246615; cv=none; b=itt7Vfl7A/+AFZMmGogF4K5nmpAwcld68ryoqBOgxnUYilGtmNHZ1R/T51a0Ii6XL7ShXOqHwy+9uhrNFii/dsnHbLOWEH6Uakj3IaaY0OzjijEEpr02RXS+VlSEOB6mdTHNUi+4YeHRFRDrAHdpBYHQJQCczDZlWr3PejqmeHU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733246615; c=relaxed/simple; bh=z39UDX9o1V2XcbH7aMI26HFWfz696/DSBf8+//1ZCE0=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uFGEDlX14ZHFUw9I/4m7CVLobsKhlzcbbGd2Z4VrIHsdX9+/PxpyIJMZvLJTiqbNe7px0sH8gPN8uSQVbxzRQf0ayb87c6UOA5iRIqMtqaCOEwYFerp4cicpDmGQxHMALXI2hnUiI9SGcv7zlIMWfyeQgFuOE7DYl7lFXdTwOt4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Y2nVD1RF9z6K9Db; Wed, 4 Dec 2024 01:20:36 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 89BE41401F4; Wed, 4 Dec 2024 01:23:30 +0800 (CST) Received: from localhost (10.203.177.66) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 3 Dec 2024 18:23:30 +0100 Date: Tue, 3 Dec 2024 17:23:28 +0000 From: Jonathan Cameron To: Hongjian Fan CC: , , Subject: Re: [PATCH] hw/mem: support zero memory size CXL device Message-ID: <20241203172328.00001a00@huawei.com> In-Reply-To: <20241202230310.1531219-1-hongjian.fan@seagate.com> References: <20241202230310.1531219-1-hongjian.fan@seagate.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml500009.china.huawei.com (7.191.174.84) To frapeml500008.china.huawei.com (7.182.85.71) On Mon, 2 Dec 2024 17:03:11 -0600 Hongjian Fan wrote: > According to CXL 3.1 specification, 8.1.3.8 DVSEC CXL Range Registers "A CXL.mem-capable device is permitted to report zero memory size." > This patch will allow a CXL type3 device to be initialized with zero memory size, when there is no memory device property provided ( neither volatile, persistent, nor dynamic region). Wrap at less than 75 chars. I'm curious. Why do you want to emulate such a device? There are many things the CXL spec allows that we don't emulate. I'd normally count this as just another one of those. Jonathan > > Signed-off-by: Hongjian Fan > --- > hw/mem/cxl_type3.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c > index 5cf754b38f..35caa186ca 100644 > --- a/hw/mem/cxl_type3.c > +++ b/hw/mem/cxl_type3.c > @@ -159,7 +159,12 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, void *priv) > int len = 0; > > if (!ct3d->hostpmem && !ct3d->hostvmem && !ct3d->dc.num_regions) { > - return 0; > + // zero memory size device. Build one entry with size 0 Comment syntax /* */ > + table = g_malloc0(CT3_CDAT_NUM_ENTRIES * sizeof(*table)); > + ct3_build_cdat_entries_for_mr(&(table[0]), dsmad_handle++, > + 0, false, false, 0); > + *cdat_table = g_steal_pointer(&table); > + return CT3_CDAT_NUM_ENTRIES; > } > > if (ct3d->hostvmem) { > @@ -712,8 +717,11 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) > > if (!ct3d->hostmem && !ct3d->hostvmem && !ct3d->hostpmem > && !ct3d->dc.num_regions) { > - error_setg(errp, "at least one memdev property must be set"); > - return false; > + // no memdev property provided. Default to zero memory size device > + ct3d->cxl_dstate.pmem_size = 0; > + ct3d->cxl_dstate.vmem_size = 0; > + ct3d->cxl_dstate.static_mem_size = 0; > + return true; > } else if (ct3d->hostmem && ct3d->hostpmem) { > error_setg(errp, "[memdev] cannot be used with new " > "[persistent-memdev] property"); From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37B48E74AC6 for ; Tue, 3 Dec 2024 17:24:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIWcm-0006XU-9Y; Tue, 03 Dec 2024 12:23:48 -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 1tIWck-0006Wq-28 for qemu-devel@nongnu.org; Tue, 03 Dec 2024 12:23:46 -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 1tIWcf-0001K2-Oj for qemu-devel@nongnu.org; Tue, 03 Dec 2024 12:23:45 -0500 Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Y2nVD1RF9z6K9Db; Wed, 4 Dec 2024 01:20:36 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 89BE41401F4; Wed, 4 Dec 2024 01:23:30 +0800 (CST) Received: from localhost (10.203.177.66) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 3 Dec 2024 18:23:30 +0100 Date: Tue, 3 Dec 2024 17:23:28 +0000 To: Hongjian Fan CC: , , Subject: Re: [PATCH] hw/mem: support zero memory size CXL device Message-ID: <20241203172328.00001a00@huawei.com> In-Reply-To: <20241202230310.1531219-1-hongjian.fan@seagate.com> References: <20241202230310.1531219-1-hongjian.fan@seagate.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.203.177.66] X-ClientProxiedBy: lhrpeml500009.china.huawei.com (7.191.174.84) To frapeml500008.china.huawei.com (7.182.85.71) Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@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_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On Mon, 2 Dec 2024 17:03:11 -0600 Hongjian Fan wrote: > According to CXL 3.1 specification, 8.1.3.8 DVSEC CXL Range Registers "A CXL.mem-capable device is permitted to report zero memory size." > This patch will allow a CXL type3 device to be initialized with zero memory size, when there is no memory device property provided ( neither volatile, persistent, nor dynamic region). Wrap at less than 75 chars. I'm curious. Why do you want to emulate such a device? There are many things the CXL spec allows that we don't emulate. I'd normally count this as just another one of those. Jonathan > > Signed-off-by: Hongjian Fan > --- > hw/mem/cxl_type3.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c > index 5cf754b38f..35caa186ca 100644 > --- a/hw/mem/cxl_type3.c > +++ b/hw/mem/cxl_type3.c > @@ -159,7 +159,12 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, void *priv) > int len = 0; > > if (!ct3d->hostpmem && !ct3d->hostvmem && !ct3d->dc.num_regions) { > - return 0; > + // zero memory size device. Build one entry with size 0 Comment syntax /* */ > + table = g_malloc0(CT3_CDAT_NUM_ENTRIES * sizeof(*table)); > + ct3_build_cdat_entries_for_mr(&(table[0]), dsmad_handle++, > + 0, false, false, 0); > + *cdat_table = g_steal_pointer(&table); > + return CT3_CDAT_NUM_ENTRIES; > } > > if (ct3d->hostvmem) { > @@ -712,8 +717,11 @@ static bool cxl_setup_memory(CXLType3Dev *ct3d, Error **errp) > > if (!ct3d->hostmem && !ct3d->hostvmem && !ct3d->hostpmem > && !ct3d->dc.num_regions) { > - error_setg(errp, "at least one memdev property must be set"); > - return false; > + // no memdev property provided. Default to zero memory size device > + ct3d->cxl_dstate.pmem_size = 0; > + ct3d->cxl_dstate.vmem_size = 0; > + ct3d->cxl_dstate.static_mem_size = 0; > + return true; > } else if (ct3d->hostmem && ct3d->hostpmem) { > error_setg(errp, "[memdev] cannot be used with new " > "[persistent-memdev] property");