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 82D91C83033 for ; Mon, 30 Jun 2025 17:02:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uWHt7-0002t8-Qf; Mon, 30 Jun 2025 13:01:52 -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 1uWHsh-0002mq-Ju for qemu-devel@nongnu.org; Mon, 30 Jun 2025 13:01:23 -0400 Received: from [185.176.79.56] (helo=frasgout.his.huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uWHsd-000232-Si for qemu-devel@nongnu.org; Mon, 30 Jun 2025 13:01:23 -0400 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4bWC8M08ZRz6M55w; Tue, 1 Jul 2025 01:00:19 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id DD4581400CA; Tue, 1 Jul 2025 01:01:11 +0800 (CST) Received: from localhost (10.122.19.247) 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; Mon, 30 Jun 2025 19:01:11 +0200 Date: Mon, 30 Jun 2025 18:01:10 +0100 To: CC: , , , , , Anisa Su Subject: Re: [QEMU PATCH v4 09/10] cxl-mailbox-utils: 0x5604 - FMAPI Initiate DC Add Message-ID: <20250630180110.0000060d@huawei.com> In-Reply-To: <20250626222743.1766404-10-anisa.su887@gmail.com> References: <20250626222743.1766404-1-anisa.su887@gmail.com> <20250626222743.1766404-10-anisa.su887@gmail.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.122.19.247] X-ClientProxiedBy: lhrpeml500010.china.huawei.com (7.191.174.240) To frapeml500008.china.huawei.com (7.182.85.71) X-Host-Lookup-Failed: Reverse DNS lookup failed for 185.176.79.56 (deferred) Received-SPF: pass client-ip=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.237, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RDNS_NONE=0.793, 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 Thu, 26 Jun 2025 22:23:32 +0000 anisa.su887@gmail.com wrote: > From: Anisa Su > > FM DCD Management command 0x5604 implemented per CXL r3.2 Spec Section 7.6.7.6.5 There are a few long lines in here check patch doesn't like. I tweaked as described inline whilst picking them up. > > Signed-off-by: Anisa Su > --- > hw/cxl/cxl-mailbox-utils.c | 106 ++++++++++++++++++++++++++++++++++++ > hw/mem/cxl_type3.c | 8 +-- > include/hw/cxl/cxl_device.h | 4 ++ > 3 files changed, 114 insertions(+), 4 deletions(-) > > diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c > index 382c41c025..787eeaa7b9 100644 > --- a/hw/cxl/cxl-mailbox-utils.c > +++ b/hw/cxl/cxl-mailbox-utils.c > +/* CXL r3.2 Section 7.6.7.6.5 Initiate Dynamic Capacity Add (Opcode 5604h) */ > +static CXLRetCode cmd_fm_initiate_dc_add(const struct cxl_cmd *cmd, > + uint8_t *payload_in, > + size_t len_in, > + uint8_t *payload_out, > + size_t *len_out, > + CXLCCI *cci) > +{ > + struct { > + uint16_t host_id; > + uint8_t selection_policy; > + uint8_t reg_num; > + uint64_t length; > + uint8_t tag[0x10]; > + uint32_t ext_count; > + CXLDCExtentRaw extents[]; > + } QEMU_PACKED *in = (void *)payload_in; > + CXLType3Dev *ct3d = CXL_TYPE3(cci->d); > + int i, rc; > + > + switch (in->selection_policy) { > + case CXL_EXTENT_SELECTION_POLICY_PRESCRIPTIVE: { > + /* Adding extents exceeds device's extent tracking ability. */ > + if (in->ext_count + ct3d->dc.total_extent_count > > + CXL_NUM_EXTENTS_SUPPORTED) { > + return CXL_MBOX_RESOURCES_EXHAUSTED; > + } > + > + g_autofree CXLUpdateDCExtentListInPl *list = > + g_malloc0(sizeof(*list) + > + in->ext_count * sizeof(*list->updated_entries)); > + > + convert_raw_extents(in->extents, list, in->ext_count); > + rc = cxl_detect_malformed_extent_list(ct3d, list); > + > + for (i = 0; i < in->ext_count; i++) { > + CXLDCExtentRaw ext = in->extents[i]; Using a pointer here avoids copying data for no particular reason. > + /* Check requested extents do not overlap with pending extents. */ This is a touch long. I tweaked to end with ... pending ones. Given we are talking extents that should be clear. > + if (cxl_extent_groups_overlaps_dpa_range(&ct3d->dc.extents_pending, This is the one case I'll leave as it is not nice to wrap it anywhere different. > + ext.start_dpa, ext.len)) { wrapped this > + return CXL_MBOX_INVALID_EXTENT_LIST; > + } > + /* Check requested extents do not overlap with existing extents. */ exiting ones. */ > + if (cxl_extents_overlaps_dpa_range(&ct3d->dc.extents, > + ext.start_dpa, ext.len)) { Wrapped this. > + return CXL_MBOX_INVALID_EXTENT_LIST; > + } > + } > + > + if (rc) { > + return rc; > + } > + > + CXLDCExtentGroup *group = NULL; > + for (i = 0; i < in->ext_count; i++) { Used CXLDCExtentRaw *ext = &in->extents[i]; > + group = cxl_insert_extent_to_extent_group(group, > + in->extents[i].start_dpa, To shorten all these (similar to previous loop) > + in->extents[i].len, > + in->extents[i].tag, > + in->extents[i].shared_seq); > + } > + > + cxl_extent_group_list_insert_tail(&ct3d->dc.extents_pending, group); > + ct3d->dc.total_extent_count += in->ext_count; > + cxl_create_dc_event_records_for_extents(ct3d, > + DC_EVENT_ADD_CAPACITY, > + in->extents, > + in->ext_count); > + > + return CXL_MBOX_SUCCESS; > + } > + default: { > + qemu_log_mask(LOG_UNIMP, > + "CXL extent selection policy not supported.\n"); > + return CXL_MBOX_INVALID_INPUT; > + } > + } > +}