From patchwork Wed Oct 12 18:21:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 1689269 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=YCbfvvum; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mngx43RXzz23jn for ; Thu, 13 Oct 2022 05:22:30 +1100 (AEDT) Received: from localhost ([::1]:38122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oigN9-0002CP-A4 for incoming@patchwork.ozlabs.org; Wed, 12 Oct 2022 14:22:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oigML-00025p-M5 for qemu-devel@nongnu.org; Wed, 12 Oct 2022 14:21:37 -0400 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]:42629) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oigMJ-0001xl-1l for qemu-devel@nongnu.org; Wed, 12 Oct 2022 14:21:36 -0400 Received: by mail-qk1-x731.google.com with SMTP id j21so8801539qkk.9 for ; Wed, 12 Oct 2022 11:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q1SK3FmyWNNpw6G4y43Kwb7gIJPzDAfBnVuIve7TjDc=; b=YCbfvvumKlZ3foogMftBxTqiz4dPxgz30svC9SU0NS8mga4dYKAfJTb+RuVmV7x9l5 EMnzDTHQLU3is/d0Nh1I4e9twSKKTKtcOg2vEGCnVYivy4MMLN30QkDx4CaU6j2VeNv1 jEm6Kc125d1gpgdBqpb3T7S9iJd38mjBJ5weV5G7WoE7Hixwv3wy9zyA0vdikrB+lfZQ aIon6dWDR21EPs7cEQsHFMQuL1YpE9wQEtBL2VQd9y+DMp74uQHg73coBv9Brbq1EFDZ VWQS/lw5h9EepMFt2A2oGLYZUfoCVhapE11JDbKC+IXUiv6TzXFk+o9FoDk6MYn05ZFI 1yVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q1SK3FmyWNNpw6G4y43Kwb7gIJPzDAfBnVuIve7TjDc=; b=3pm1+CiOJ6Ko/DHEnl5FBYnMRwHzfm5eh9fZOX+psoSqbNr6pryVghGb3p7tnFjHR9 o2knXkcMc4Ws4jiQ6M8+/mqxCW3cNbROO1qGDrfK05v6P3hbk0tcFvIBr+znLwc475Ps yY6739nDn7efJVEQmdx76a00dFZIb/xUZfJZ5ZX/an5A41ALyo31lETL+lG/2ACiTxNS 5SHl4IgvzoJ/WRP2e2xHA3h2rKP+ieezprStnnKJL1HuvMfueYJ9vYmKSAHV5R19dF6H 98l8VFueFEkeORgqkalsCGzLYig6kIQqegtxzy8pmkgrOapAD1gpOiBlA1+pvVvxBHvH Pelw== X-Gm-Message-State: ACrzQf0oh2X3yk9HmZFJY/PHGqJNeSVTqAs2EgbDy/gRURNfMbV9X/JC GCOyQtNIrUsc+bp2ry8KfA== X-Google-Smtp-Source: AMsMyM4YgSMLUbbpvKx+iRy1VddHfrj7AbV9No4p/XrQY1dXhetAOW5p0z+bSKc/w0picxbfmeZkJg== X-Received: by 2002:a05:620a:460c:b0:6ce:43e4:4e57 with SMTP id br12-20020a05620a460c00b006ce43e44e57mr21474633qkb.778.1665598894116; Wed, 12 Oct 2022 11:21:34 -0700 (PDT) Received: from fedora.mshome.net (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id bq40-20020a05620a46a800b006ee9d734479sm920228qkb.33.2022.10.12.11.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 11:21:33 -0700 (PDT) From: Gregory Price X-Google-Original-From: Gregory Price To: jonathan.cameron@huawei.com Cc: qemu-devel@nongnu.org, linux-cxl@vger.kernel.org, alison.schofield@intel.com, dave@stgolabs.net, a.manzanares@samsung.com, bwidawsk@kernel.org, gregory.price@memverge.com, mst@redhat.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com Subject: [PATCH 1/5] hw/mem/cxl_type3: fix checkpatch errors Date: Wed, 12 Oct 2022 14:21:16 -0400 Message-Id: <20221012182120.174142-2-gregory.price@memverge.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221012182120.174142-1-gregory.price@memverge.com> References: <20221007152156.24883-5-Jonathan.Cameron@huawei.com> <20221012182120.174142-1-gregory.price@memverge.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::731; envelope-from=gourry.memverge@gmail.com; helo=mail-qk1-x731.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This fixes checkpatch errors in the prior commit. Signed-off-by: Gregory Price --- hw/mem/cxl_type3.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 3fa5d70662..94bc439d89 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -56,9 +56,11 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, len++; /* For now, no memory side cache, plausiblish numbers */ - dslbis_nonvolatile = g_malloc(sizeof(*dslbis_nonvolatile) * dslbis_nonvolatile_num); - if (!dslbis_nonvolatile) + dslbis_nonvolatile = + g_malloc(sizeof(*dslbis_nonvolatile) * dslbis_nonvolatile_num); + if (!dslbis_nonvolatile) { return -ENOMEM; + } dslbis_nonvolatile[0] = (CDATDslbis) { .header = { @@ -85,7 +87,7 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, .entry[0] = 25, /* 250ns */ }; len++; - + dslbis_nonvolatile[2] = (CDATDslbis) { .header = { .type = CDAT_TYPE_DSLBIS, @@ -123,7 +125,8 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, .length = sizeof(*dsemts_nonvolatile), }, .DSMAS_handle = nonvolatile_dsmad, - .EFI_memory_type_attr = 2, /* Reserved - the non volatile from DSMAS matters */ + /* Reserved - the non volatile from DSMAS matters */ + .EFI_memory_type_attr = 2, .DPA_offset = 0, .DPA_length = int128_get64(mr->size), }; @@ -136,7 +139,7 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, (*cdat_table)[i++] = g_steal_pointer(&dsmas_nonvolatile); } if (dslbis_nonvolatile) { - CDATDslbis *dslbis = g_steal_pointer(&dslbis_nonvolatile); + CDATDslbis *dslbis = g_steal_pointer(&dslbis_nonvolatile); int j; for (j = 0; j < dslbis_nonvolatile_num; j++) { @@ -146,7 +149,7 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, if (dsemts_nonvolatile) { (*cdat_table)[i++] = g_steal_pointer(&dsemts_nonvolatile); } - + return len; } From patchwork Wed Oct 12 18:21:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 1689272 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=HUtZZy4Y; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mnh0N5tdmz23jX for ; Thu, 13 Oct 2022 05:25:24 +1100 (AEDT) Received: from localhost ([::1]:56620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oigPy-0006ML-Mh for incoming@patchwork.ozlabs.org; Wed, 12 Oct 2022 14:25:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oigMP-0002Fq-HL for qemu-devel@nongnu.org; Wed, 12 Oct 2022 14:21:41 -0400 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]:36850) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oigMK-0001y6-Ck for qemu-devel@nongnu.org; Wed, 12 Oct 2022 14:21:41 -0400 Received: by mail-qk1-x741.google.com with SMTP id f8so3596526qkg.3 for ; Wed, 12 Oct 2022 11:21:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IktacSVymJ4XPCZWnpI70Qh+XpMKAyrOqOuaVfZ+z7M=; b=HUtZZy4YLvJmCpi4B9LSnmhnuAcZIx3YxOg8+glBpEoRFKMbdTEAzLPoADuTODqkxs d8MHJq7yZnOnh89QqA8rKcYYlhbm8HgFIXAPPQ8b5AYGPjBpY6tlrumHM1WuTq5KDitv nGV0oFEt3aH4Dn2Pg3rXZLHn2VdvuewYalojXdAq3e5ZOL0s2F1y6w/2rWNY77Shpb69 c+yOXfSAGFrlYegQ0Jek5Ru1X62FY65RPlY8qoJ2tkd+W5DZbRZiyjnUp3ehQhJbCtNf etpHuSmY1UkhhdBvP2N6oUJV4n5xMCf4r3VidBGvDTZvHWO7iBEzVc3fxqE60CU24jFG KDCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IktacSVymJ4XPCZWnpI70Qh+XpMKAyrOqOuaVfZ+z7M=; b=B+h2RI2I8y9K1+RNNQX7yH6O29fIJeEVhdPak4xeoWZYqJp6+SvSD9VheAVRKICube /yh9yuc3He/6J+1FtvbuE6TZ4Pa+Wte28Yt53QmgbCvbQG9iuga1xi6FxchlECs6TEbP Q1UrRy/U29dulFAZ/1srsBrNQu974eUVcaNr1buOh0+7G1KybqczwduEWv5qi6AO2+iX 4qyWCgkrUB6bUUov5+Jo15X4zdfU7x3SzVyP0LqDzR2TltlvcKoJx4w6d5XwQ5xqB13o eX1QcwXVkXjZYBwC33PTEhUDHx48hrXmqj+bzQiUeL5+aemzy2l/qRF0Gk6nRbNS8+Em jCRw== X-Gm-Message-State: ACrzQf0xE0ccBoJR2knUm3BUmU0hZkCSGKVAWPmywh/2qeAlnKGhFs/t 1desnT9WsKFYyV0mrc1sXqi32GkJXA== X-Google-Smtp-Source: AMsMyM7A4eoyN5KwTtSExyVRSKfjjEUI0Mvu7mnNU+2q9jNGEXRo6WDFrbnysRtbs7Al87blAXeluQ== X-Received: by 2002:a05:620a:4694:b0:6ee:b286:281a with SMTP id bq20-20020a05620a469400b006eeb286281amr311258qkb.455.1665598895491; Wed, 12 Oct 2022 11:21:35 -0700 (PDT) Received: from fedora.mshome.net (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id bq40-20020a05620a46a800b006ee9d734479sm920228qkb.33.2022.10.12.11.21.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 11:21:35 -0700 (PDT) From: Gregory Price X-Google-Original-From: Gregory Price To: jonathan.cameron@huawei.com Cc: qemu-devel@nongnu.org, linux-cxl@vger.kernel.org, alison.schofield@intel.com, dave@stgolabs.net, a.manzanares@samsung.com, bwidawsk@kernel.org, gregory.price@memverge.com, mst@redhat.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com Subject: [PATCH 2/5] hw/mem/cxl_type3: Pull validation checks ahead of functional code Date: Wed, 12 Oct 2022 14:21:17 -0400 Message-Id: <20221012182120.174142-3-gregory.price@memverge.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221012182120.174142-1-gregory.price@memverge.com> References: <20221007152156.24883-5-Jonathan.Cameron@huawei.com> <20221012182120.174142-1-gregory.price@memverge.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::741; envelope-from=gourry.memverge@gmail.com; helo=mail-qk1-x741.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" For style - pulling these validations ahead flattens the code. Signed-off-by: Gregory Price --- hw/mem/cxl_type3.c | 193 ++++++++++++++++++++++----------------------- 1 file changed, 96 insertions(+), 97 deletions(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 94bc439d89..43b2b9e041 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -32,107 +32,106 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, int dslbis_nonvolatile_num = 4; MemoryRegion *mr; + if (!ct3d->hostmem) { + return len; + } + + mr = host_memory_backend_get_memory(ct3d->hostmem); + if (!mr) { + return -EINVAL; + } + /* Non volatile aspects */ - if (ct3d->hostmem) { - dsmas_nonvolatile = g_malloc(sizeof(*dsmas_nonvolatile)); - if (!dsmas_nonvolatile) { - return -ENOMEM; - } - nonvolatile_dsmad = next_dsmad_handle++; - mr = host_memory_backend_get_memory(ct3d->hostmem); - if (!mr) { - return -EINVAL; - } - *dsmas_nonvolatile = (CDATDsmas) { - .header = { - .type = CDAT_TYPE_DSMAS, - .length = sizeof(*dsmas_nonvolatile), - }, - .DSMADhandle = nonvolatile_dsmad, - .flags = CDAT_DSMAS_FLAG_NV, - .DPA_base = 0, - .DPA_length = int128_get64(mr->size), - }; - len++; - - /* For now, no memory side cache, plausiblish numbers */ - dslbis_nonvolatile = - g_malloc(sizeof(*dslbis_nonvolatile) * dslbis_nonvolatile_num); - if (!dslbis_nonvolatile) { - return -ENOMEM; - } + dsmas_nonvolatile = g_malloc(sizeof(*dsmas_nonvolatile)); + if (!dsmas_nonvolatile) { + return -ENOMEM; + } + nonvolatile_dsmad = next_dsmad_handle++; + *dsmas_nonvolatile = (CDATDsmas) { + .header = { + .type = CDAT_TYPE_DSMAS, + .length = sizeof(*dsmas_nonvolatile), + }, + .DSMADhandle = nonvolatile_dsmad, + .flags = CDAT_DSMAS_FLAG_NV, + .DPA_base = 0, + .DPA_length = int128_get64(mr->size), + }; + len++; - dslbis_nonvolatile[0] = (CDATDslbis) { - .header = { - .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile), - }, - .handle = nonvolatile_dsmad, - .flags = HMAT_LB_MEM_MEMORY, - .data_type = HMAT_LB_DATA_READ_LATENCY, - .entry_base_unit = 10000, /* 10ns base */ - .entry[0] = 15, /* 150ns */ - }; - len++; - - dslbis_nonvolatile[1] = (CDATDslbis) { - .header = { - .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile), - }, - .handle = nonvolatile_dsmad, - .flags = HMAT_LB_MEM_MEMORY, - .data_type = HMAT_LB_DATA_WRITE_LATENCY, - .entry_base_unit = 10000, - .entry[0] = 25, /* 250ns */ - }; - len++; - - dslbis_nonvolatile[2] = (CDATDslbis) { - .header = { - .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile), - }, - .handle = nonvolatile_dsmad, - .flags = HMAT_LB_MEM_MEMORY, - .data_type = HMAT_LB_DATA_READ_BANDWIDTH, - .entry_base_unit = 1000, /* GB/s */ - .entry[0] = 16, - }; - len++; - - dslbis_nonvolatile[3] = (CDATDslbis) { - .header = { - .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile), - }, - .handle = nonvolatile_dsmad, - .flags = HMAT_LB_MEM_MEMORY, - .data_type = HMAT_LB_DATA_WRITE_BANDWIDTH, - .entry_base_unit = 1000, /* GB/s */ - .entry[0] = 16, - }; - len++; - - mr = host_memory_backend_get_memory(ct3d->hostmem); - if (!mr) { - return -EINVAL; - } - dsemts_nonvolatile = g_malloc(sizeof(*dsemts_nonvolatile)); - *dsemts_nonvolatile = (CDATDsemts) { - .header = { - .type = CDAT_TYPE_DSEMTS, - .length = sizeof(*dsemts_nonvolatile), - }, - .DSMAS_handle = nonvolatile_dsmad, - /* Reserved - the non volatile from DSMAS matters */ - .EFI_memory_type_attr = 2, - .DPA_offset = 0, - .DPA_length = int128_get64(mr->size), - }; - len++; + /* For now, no memory side cache, plausiblish numbers */ + dslbis_nonvolatile = + g_malloc(sizeof(*dslbis_nonvolatile) * dslbis_nonvolatile_num); + if (!dslbis_nonvolatile) { + return -ENOMEM; } + dslbis_nonvolatile[0] = (CDATDslbis) { + .header = { + .type = CDAT_TYPE_DSLBIS, + .length = sizeof(*dslbis_nonvolatile), + }, + .handle = nonvolatile_dsmad, + .flags = HMAT_LB_MEM_MEMORY, + .data_type = HMAT_LB_DATA_READ_LATENCY, + .entry_base_unit = 10000, /* 10ns base */ + .entry[0] = 15, /* 150ns */ + }; + len++; + + dslbis_nonvolatile[1] = (CDATDslbis) { + .header = { + .type = CDAT_TYPE_DSLBIS, + .length = sizeof(*dslbis_nonvolatile), + }, + .handle = nonvolatile_dsmad, + .flags = HMAT_LB_MEM_MEMORY, + .data_type = HMAT_LB_DATA_WRITE_LATENCY, + .entry_base_unit = 10000, + .entry[0] = 25, /* 250ns */ + }; + len++; + + dslbis_nonvolatile[2] = (CDATDslbis) { + .header = { + .type = CDAT_TYPE_DSLBIS, + .length = sizeof(*dslbis_nonvolatile), + }, + .handle = nonvolatile_dsmad, + .flags = HMAT_LB_MEM_MEMORY, + .data_type = HMAT_LB_DATA_READ_BANDWIDTH, + .entry_base_unit = 1000, /* GB/s */ + .entry[0] = 16, + }; + len++; + + dslbis_nonvolatile[3] = (CDATDslbis) { + .header = { + .type = CDAT_TYPE_DSLBIS, + .length = sizeof(*dslbis_nonvolatile), + }, + .handle = nonvolatile_dsmad, + .flags = HMAT_LB_MEM_MEMORY, + .data_type = HMAT_LB_DATA_WRITE_BANDWIDTH, + .entry_base_unit = 1000, /* GB/s */ + .entry[0] = 16, + }; + len++; + + dsemts_nonvolatile = g_malloc(sizeof(*dsemts_nonvolatile)); + *dsemts_nonvolatile = (CDATDsemts) { + .header = { + .type = CDAT_TYPE_DSEMTS, + .length = sizeof(*dsemts_nonvolatile), + }, + .DSMAS_handle = nonvolatile_dsmad, + /* Reserved - the non volatile from DSMAS matters */ + .EFI_memory_type_attr = 2, + .DPA_offset = 0, + .DPA_length = int128_get64(mr->size), + }; + len++; + *cdat_table = g_malloc0(len * sizeof(*cdat_table)); /* Header always at start of structure */ if (dsmas_nonvolatile) { From patchwork Wed Oct 12 18:21:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 1689273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=jKIGYrw9; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mnh3H4f3Sz23jX for ; Thu, 13 Oct 2022 05:27:53 +1100 (AEDT) Received: from localhost ([::1]:43706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oigSL-0000VT-VC for incoming@patchwork.ozlabs.org; Wed, 12 Oct 2022 14:27:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oigMR-0002Iy-09 for qemu-devel@nongnu.org; Wed, 12 Oct 2022 14:21:43 -0400 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]:43567) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oigML-0001yJ-Jq for qemu-devel@nongnu.org; Wed, 12 Oct 2022 14:21:42 -0400 Received: by mail-qt1-x841.google.com with SMTP id a24so3163919qto.10 for ; Wed, 12 Oct 2022 11:21:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T/OIjGnZ8Z2MlKUjHTeqka/I/IZvDfiB0NY+oyfcc4s=; b=jKIGYrw9yB2dtHKLpXQrIULA63v2EbPdg4/UeDYYJM4iD3Gveqcqjp23FRmJWV2kqg t2GCMtaj8F6cbrdKMyYV7Ppszlob1SJw0HPbZ5IzfaGW0KnV5teIc5lH8BsrXNrRlEwq qAaJAvULCZAdI0alRR08sii1LGbUv6z6yEHbgiGQPhJ3XjTSNjC021EJW/AKbR1Q0kTh tH1c/OiDND6rGM8cqwEq7uyIX/vZZygIGFDLLcjwZS9mNFrvw17Zt36kUxvb55sz+rHK rGqOwZt5zbCVdjlvao3LpCQZ6NNO1n3ECYK1x7fWzoEOpqiiE0K2vVqEq+DdbDioO4g5 fxeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T/OIjGnZ8Z2MlKUjHTeqka/I/IZvDfiB0NY+oyfcc4s=; b=6ZeEuKjJ3RaBOtxJ4qQ20o1wbUNlFUuvaQ6XsRPGa31PD48RL6eLAAD8KLGDusOM67 822NzDAFbGUpomGnqyCopO4a59KzwFr5euu1AjCM0NztDyCpsReGHscA07heNorLZ6i0 KV77EFCGuj9DMicDiimzkGQSIEdeFhKZU17LRGlvzXpaVtY8InWUZAM+rCEePQl/U1J9 eoeOAFic/ovS0Xb3yNW3tQQRhGXhwDiySWNtr6En7IoH4yZc28HQKjZP2rnRJuUoC8zo madw757B4s7i8apyPW94QyNUsfgZ9NHDT+abvBB6OR9HT5upqIAb6C3gcK7n4/4xc95t /AZw== X-Gm-Message-State: ACrzQf3WDyBdktf2ZnrRBQCZiPqKTf9dKkr1HgaJyR5A84WZeB1op8f+ uu3zMqBaWpUIeyeImq8M/Q== X-Google-Smtp-Source: AMsMyM70tX7LUk3Ti1w2k4JsuhkpWUrgqefoViSwtPtKQUHP1tZJA7Us4c8XwVj7uBL0qfIauHtgEg== X-Received: by 2002:a05:622a:1754:b0:39c:c5ab:9bdf with SMTP id l20-20020a05622a175400b0039cc5ab9bdfmr2549651qtk.618.1665598896712; Wed, 12 Oct 2022 11:21:36 -0700 (PDT) Received: from fedora.mshome.net (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id bq40-20020a05620a46a800b006ee9d734479sm920228qkb.33.2022.10.12.11.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 11:21:36 -0700 (PDT) From: Gregory Price X-Google-Original-From: Gregory Price To: jonathan.cameron@huawei.com Cc: qemu-devel@nongnu.org, linux-cxl@vger.kernel.org, alison.schofield@intel.com, dave@stgolabs.net, a.manzanares@samsung.com, bwidawsk@kernel.org, gregory.price@memverge.com, mst@redhat.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com Subject: [PATCH 3/5] hw/mem/cxl_type3: CDAT pre-allocate and check resources prior to work Date: Wed, 12 Oct 2022 14:21:18 -0400 Message-Id: <20221012182120.174142-4-gregory.price@memverge.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221012182120.174142-1-gregory.price@memverge.com> References: <20221007152156.24883-5-Jonathan.Cameron@huawei.com> <20221012182120.174142-1-gregory.price@memverge.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::841; envelope-from=gourry.memverge@gmail.com; helo=mail-qt1-x841.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Makes the size of the allocated cdat table static (6 entries), flattens the code, and reduces the number of exit conditions Signed-off-by: Gregory Price --- hw/mem/cxl_type3.c | 52 ++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 43b2b9e041..0e0ea70387 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -17,6 +17,7 @@ #include "hw/pci/msix.h" #define DWORD_BYTE 4 +#define CT3_CDAT_SUBTABLE_SIZE 6 static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, void *priv) @@ -25,7 +26,6 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, g_autofree CDATDslbis *dslbis_nonvolatile = NULL; g_autofree CDATDsemts *dsemts_nonvolatile = NULL; CXLType3Dev *ct3d = priv; - int len = 0; int i = 0; int next_dsmad_handle = 0; int nonvolatile_dsmad = -1; @@ -33,7 +33,7 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, MemoryRegion *mr; if (!ct3d->hostmem) { - return len; + return 0; } mr = host_memory_backend_get_memory(ct3d->hostmem); @@ -41,11 +41,22 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, return -EINVAL; } + *cdat_table = g_malloc0(CT3_CDAT_SUBTABLE_SIZE * sizeof(*cdat_table)); + if (!*cdat_table) { + return -ENOMEM; + } + /* Non volatile aspects */ dsmas_nonvolatile = g_malloc(sizeof(*dsmas_nonvolatile)); - if (!dsmas_nonvolatile) { + dslbis_nonvolatile = + g_malloc(sizeof(*dslbis_nonvolatile) * dslbis_nonvolatile_num); + dsemts_nonvolatile = g_malloc(sizeof(*dsemts_nonvolatile)); + if (!dsmas_nonvolatile || !dslbis_nonvolatile || !dsemts_nonvolatile) { + g_free(*cdat_table); + *cdat_table = NULL; return -ENOMEM; } + nonvolatile_dsmad = next_dsmad_handle++; *dsmas_nonvolatile = (CDATDsmas) { .header = { @@ -57,15 +68,8 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, .DPA_base = 0, .DPA_length = int128_get64(mr->size), }; - len++; /* For now, no memory side cache, plausiblish numbers */ - dslbis_nonvolatile = - g_malloc(sizeof(*dslbis_nonvolatile) * dslbis_nonvolatile_num); - if (!dslbis_nonvolatile) { - return -ENOMEM; - } - dslbis_nonvolatile[0] = (CDATDslbis) { .header = { .type = CDAT_TYPE_DSLBIS, @@ -77,7 +81,6 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, .entry_base_unit = 10000, /* 10ns base */ .entry[0] = 15, /* 150ns */ }; - len++; dslbis_nonvolatile[1] = (CDATDslbis) { .header = { @@ -90,7 +93,6 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, .entry_base_unit = 10000, .entry[0] = 25, /* 250ns */ }; - len++; dslbis_nonvolatile[2] = (CDATDslbis) { .header = { @@ -103,7 +105,6 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, .entry_base_unit = 1000, /* GB/s */ .entry[0] = 16, }; - len++; dslbis_nonvolatile[3] = (CDATDslbis) { .header = { @@ -116,9 +117,7 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, .entry_base_unit = 1000, /* GB/s */ .entry[0] = 16, }; - len++; - dsemts_nonvolatile = g_malloc(sizeof(*dsemts_nonvolatile)); *dsemts_nonvolatile = (CDATDsemts) { .header = { .type = CDAT_TYPE_DSEMTS, @@ -130,26 +129,19 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, .DPA_offset = 0, .DPA_length = int128_get64(mr->size), }; - len++; - *cdat_table = g_malloc0(len * sizeof(*cdat_table)); /* Header always at start of structure */ - if (dsmas_nonvolatile) { - (*cdat_table)[i++] = g_steal_pointer(&dsmas_nonvolatile); - } - if (dslbis_nonvolatile) { - CDATDslbis *dslbis = g_steal_pointer(&dslbis_nonvolatile); - int j; + (*cdat_table)[i++] = g_steal_pointer(&dsmas_nonvolatile); - for (j = 0; j < dslbis_nonvolatile_num; j++) { - (*cdat_table)[i++] = (CDATSubHeader *)&dslbis[j]; - } - } - if (dsemts_nonvolatile) { - (*cdat_table)[i++] = g_steal_pointer(&dsemts_nonvolatile); + CDATDslbis *dslbis = g_steal_pointer(&dslbis_nonvolatile); + int j; + for (j = 0; j < dslbis_nonvolatile_num; j++) { + (*cdat_table)[i++] = (CDATSubHeader *)&dslbis[j]; } - return len; + (*cdat_table)[i++] = g_steal_pointer(&dsemts_nonvolatile); + + return CT3_CDAT_SUBTABLE_SIZE; } static void ct3_free_cdat_table(CDATSubHeader **cdat_table, int num, void *priv) From patchwork Wed Oct 12 18:21:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 1689276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=dFpKglfK; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mnh5X0pVXz23jX for ; Thu, 13 Oct 2022 05:29:52 +1100 (AEDT) Received: from localhost ([::1]:57696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oigUI-0004Ah-1b for incoming@patchwork.ozlabs.org; Wed, 12 Oct 2022 14:29:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oigMS-0002Lg-3C for qemu-devel@nongnu.org; Wed, 12 Oct 2022 14:21:44 -0400 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]:41659) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oigMM-0001yQ-OP for qemu-devel@nongnu.org; Wed, 12 Oct 2022 14:21:43 -0400 Received: by mail-qk1-x743.google.com with SMTP id o22so10610194qkl.8 for ; Wed, 12 Oct 2022 11:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bNKsnJI2O2Dvzfe8afK4oFdeHHBtIjx3W5QyApq77ec=; b=dFpKglfKpZgSGu7YqXw/Ag0jwAUHtRW93owL6zO7NjuoojiXdvfmN+7+YWQSnul9zq VtMYjXjyRfKJPMiY3TywWuzR13g8Zt88PtWMN19b7fsEEfY1d+oh6IDPqJJrKmC/F858 3Uib2CFKQRpACJEaXYj1Cmz008jFHxc5nWWg9frcFbSR0ymIneKR1VfuyDKCNwITu2Br VK6ahx3TM/PvuJ7+ToNIE6qWEj2BvyEgUn49eEQXuHykKaQRwcdcVUK2YdfBuF4+eCGE R7M14gdAjWAMFHSpftqqRZRVtOBMRQ7lLBJq03fQkNuZbRFRkKAOOTv7JsLaX3TNsOIl Lk8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bNKsnJI2O2Dvzfe8afK4oFdeHHBtIjx3W5QyApq77ec=; b=gL9WfKETAGeMRY5UYTETDnqSIoW+WVOphisx04HA8tiKrRs+YswxVcVEGUlpShNKtm Fa8B+Erfn7TNAktWoNvMbWtSLP2FEfTKORlEw31mb+IsO1LXqAYKIIdYF9iDfk30YGJ/ VNlWd5bxHH+dFxY66N1j/z2XCM5BMp3HZNeMoVpb3WeYCLGEXVgMMf+701INLjiqzzTK yXmCo2OrOeJmuG0gJjL7e/9cQ5zkVdJojCkEDnd+S5W6wALIdgrCYesc2+Qdmr5yMVKN BEC0e09Fy7D48vbY3JNnDrjxBCsYTxER5WNfD/JVM3l897igrpoRL8mCOa6B+0Cs2apJ bdJA== X-Gm-Message-State: ACrzQf3GgSx3rBVR57DqcMHSXSiB2EMUQQ2Bhm6H0q1IcqzznGv34f6Z 9Cv8HflOZMfUZhGdE9HoTQ== X-Google-Smtp-Source: AMsMyM7+lhEQBxC97aEvdrQqrRerFiBAjiYwBTHqxEF4uz6F3dwF2OA0MtzQne8RDkUnC1TVG9SOsA== X-Received: by 2002:a05:620a:1e5:b0:6ed:1061:5c6b with SMTP id x5-20020a05620a01e500b006ed10615c6bmr11550573qkn.34.1665598897918; Wed, 12 Oct 2022 11:21:37 -0700 (PDT) Received: from fedora.mshome.net (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id bq40-20020a05620a46a800b006ee9d734479sm920228qkb.33.2022.10.12.11.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 11:21:37 -0700 (PDT) From: Gregory Price X-Google-Original-From: Gregory Price To: jonathan.cameron@huawei.com Cc: qemu-devel@nongnu.org, linux-cxl@vger.kernel.org, alison.schofield@intel.com, dave@stgolabs.net, a.manzanares@samsung.com, bwidawsk@kernel.org, gregory.price@memverge.com, mst@redhat.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com Subject: [PATCH 4/5] hw/mem/cxl_type3: Change the CDAT allocation/free strategy Date: Wed, 12 Oct 2022 14:21:19 -0400 Message-Id: <20221012182120.174142-5-gregory.price@memverge.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221012182120.174142-1-gregory.price@memverge.com> References: <20221007152156.24883-5-Jonathan.Cameron@huawei.com> <20221012182120.174142-1-gregory.price@memverge.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::743; envelope-from=gourry.memverge@gmail.com; helo=mail-qk1-x743.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The existing code allocates a subtable for SLBIS entries, uses a local variable to avoid a g_autofree footgun, and the cleanup code causes heap corruption. Rather than allocate a table, explicitly allocate each individual entry and make the sub-table size static. Signed-off-by: Gregory Price --- hw/mem/cxl_type3.c | 49 ++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 0e0ea70387..220b9f09a9 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -23,13 +23,14 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, void *priv) { g_autofree CDATDsmas *dsmas_nonvolatile = NULL; - g_autofree CDATDslbis *dslbis_nonvolatile = NULL; + g_autofree CDATDslbis *dslbis_nonvolatile1 = NULL; + g_autofree CDATDslbis *dslbis_nonvolatile2 = NULL; + g_autofree CDATDslbis *dslbis_nonvolatile3 = NULL; + g_autofree CDATDslbis *dslbis_nonvolatile4 = NULL; g_autofree CDATDsemts *dsemts_nonvolatile = NULL; CXLType3Dev *ct3d = priv; - int i = 0; int next_dsmad_handle = 0; int nonvolatile_dsmad = -1; - int dslbis_nonvolatile_num = 4; MemoryRegion *mr; if (!ct3d->hostmem) { @@ -48,10 +49,15 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, /* Non volatile aspects */ dsmas_nonvolatile = g_malloc(sizeof(*dsmas_nonvolatile)); - dslbis_nonvolatile = - g_malloc(sizeof(*dslbis_nonvolatile) * dslbis_nonvolatile_num); + dslbis_nonvolatile1 = g_malloc(sizeof(*dslbis_nonvolatile1)); + dslbis_nonvolatile2 = g_malloc(sizeof(*dslbis_nonvolatile2)); + dslbis_nonvolatile3 = g_malloc(sizeof(*dslbis_nonvolatile3)); + dslbis_nonvolatile4 = g_malloc(sizeof(*dslbis_nonvolatile4)); dsemts_nonvolatile = g_malloc(sizeof(*dsemts_nonvolatile)); - if (!dsmas_nonvolatile || !dslbis_nonvolatile || !dsemts_nonvolatile) { + + if (!dsmas_nonvolatile || !dsemts_nonvolatile || + !dslbis_nonvolatile1 || !dslbis_nonvolatile2 || + !dslbis_nonvolatile3 || !dslbis_nonvolatile4) { g_free(*cdat_table); *cdat_table = NULL; return -ENOMEM; @@ -70,10 +76,10 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, }; /* For now, no memory side cache, plausiblish numbers */ - dslbis_nonvolatile[0] = (CDATDslbis) { + *dslbis_nonvolatile1 = (CDATDslbis) { .header = { .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile), + .length = sizeof(*dslbis_nonvolatile1), }, .handle = nonvolatile_dsmad, .flags = HMAT_LB_MEM_MEMORY, @@ -82,10 +88,10 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, .entry[0] = 15, /* 150ns */ }; - dslbis_nonvolatile[1] = (CDATDslbis) { + *dslbis_nonvolatile2 = (CDATDslbis) { .header = { .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile), + .length = sizeof(*dslbis_nonvolatile2), }, .handle = nonvolatile_dsmad, .flags = HMAT_LB_MEM_MEMORY, @@ -94,10 +100,10 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, .entry[0] = 25, /* 250ns */ }; - dslbis_nonvolatile[2] = (CDATDslbis) { + *dslbis_nonvolatile3 = (CDATDslbis) { .header = { .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile), + .length = sizeof(*dslbis_nonvolatile3), }, .handle = nonvolatile_dsmad, .flags = HMAT_LB_MEM_MEMORY, @@ -106,10 +112,10 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, .entry[0] = 16, }; - dslbis_nonvolatile[3] = (CDATDslbis) { + *dslbis_nonvolatile4 = (CDATDslbis) { .header = { .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile), + .length = sizeof(*dslbis_nonvolatile4), }, .handle = nonvolatile_dsmad, .flags = HMAT_LB_MEM_MEMORY, @@ -131,15 +137,12 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, }; /* Header always at start of structure */ - (*cdat_table)[i++] = g_steal_pointer(&dsmas_nonvolatile); - - CDATDslbis *dslbis = g_steal_pointer(&dslbis_nonvolatile); - int j; - for (j = 0; j < dslbis_nonvolatile_num; j++) { - (*cdat_table)[i++] = (CDATSubHeader *)&dslbis[j]; - } - - (*cdat_table)[i++] = g_steal_pointer(&dsemts_nonvolatile); + (*cdat_table)[0] = g_steal_pointer(&dsmas_nonvolatile); + (*cdat_table)[1] = (CDATSubHeader *)g_steal_pointer(&dslbis_nonvolatile1); + (*cdat_table)[2] = (CDATSubHeader *)g_steal_pointer(&dslbis_nonvolatile2); + (*cdat_table)[3] = (CDATSubHeader *)g_steal_pointer(&dslbis_nonvolatile3); + (*cdat_table)[4] = (CDATSubHeader *)g_steal_pointer(&dslbis_nonvolatile4); + (*cdat_table)[5] = g_steal_pointer(&dsemts_nonvolatile); return CT3_CDAT_SUBTABLE_SIZE; } From patchwork Wed Oct 12 18:21:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 1689271 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=RhNDsoH0; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mngxr1kd5z23jn for ; Thu, 13 Oct 2022 05:23:12 +1100 (AEDT) Received: from localhost ([::1]:59476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oigNp-0002Qt-OY for incoming@patchwork.ozlabs.org; Wed, 12 Oct 2022 14:23:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oigMR-0002Jl-AE for qemu-devel@nongnu.org; Wed, 12 Oct 2022 14:21:43 -0400 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]:36852) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oigMP-0001yV-5L for qemu-devel@nongnu.org; Wed, 12 Oct 2022 14:21:42 -0400 Received: by mail-qk1-x743.google.com with SMTP id f8so3596642qkg.3 for ; Wed, 12 Oct 2022 11:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AwYRwJUmb/ECwSOs8mOpcTqevLQDineADYqXRuc0klU=; b=RhNDsoH0/3AmCc0nN1MsZMs353OL2dxTcLWgkajs7Y+F7ND0WwDkXgvxCw+xb1/IdW PnDiO0tOBro8/VDNoNOeqoCCkqCSLaG7oxPIPpZVVt/WBy2GMRLfjnF7B9bzb2PPzLxs UD/uxS8FLD4ECzzgo62yrTHv4EozkWZznhzrrTy3R2CbDHiaAAnX3jywcWesXyPv8+kl 969x1PtgWeqKdczaEDZI8PoeHZbc/K48SPtX4kM2OQVF7f32gM3BAPNZVOustZU3CPvq VqRTap6Fe5HWAm/91HvpgqNdTZn43uG2uHuokztxfFwkeAUt6FK1Rp4z3LyjvFr7qdLy NOHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AwYRwJUmb/ECwSOs8mOpcTqevLQDineADYqXRuc0klU=; b=WXSfz3fGINoL69ZC4UmUWK4LO+YZmbwH3CThG3cOq7SeTkFPAlVcmLmSCoCwRozkr1 a6RAJlZaKNgUtupq8qDHp3Nv8GEE2YGv09LWl7yJQuDUs8cFOTng4kr5RW6TRwdzWf1V h+Ms990FR+kfpfPCIGCctoKZSam9dJLmQCWgx4KBUeys16mmuFghnH2fdJBf/yLd6xn0 9PWrYyVb5kCS4k54wn5IpdWII/H5r/PXe/91WahtKUToja5BgsGOlOA9Re9OqcxdkJbu a7SmjxGE40NYZORq2uBFj30ipbMX7VNVfZ9tDg2QP5KpzyVcDG+pqD6M6W05Z3MeibHJ Mv2A== X-Gm-Message-State: ACrzQf06FcVsq0VIcELouhM+KRxY6P8EKvdQ+zu0yEog4Fm5M1kIXn5N t373yhmSSAlmnu59YIIfSg== X-Google-Smtp-Source: AMsMyM7lYSTJ9D9LN2djFtz0k3yhYzKbW6MSVPKNTKwxtp9ZebLEkF8G6/Oo1vmWDAvi6mkdvKyzKw== X-Received: by 2002:a05:620a:4081:b0:6ee:80ab:25b6 with SMTP id f1-20020a05620a408100b006ee80ab25b6mr6675429qko.517.1665598899339; Wed, 12 Oct 2022 11:21:39 -0700 (PDT) Received: from fedora.mshome.net (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id bq40-20020a05620a46a800b006ee9d734479sm920228qkb.33.2022.10.12.11.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 11:21:39 -0700 (PDT) From: Gregory Price X-Google-Original-From: Gregory Price To: jonathan.cameron@huawei.com Cc: qemu-devel@nongnu.org, linux-cxl@vger.kernel.org, alison.schofield@intel.com, dave@stgolabs.net, a.manzanares@samsung.com, bwidawsk@kernel.org, gregory.price@memverge.com, mst@redhat.com, hchkuo@avery-design.com.tw, cbrowy@avery-design.com, ira.weiny@intel.com Subject: [PATCH 5/5] hw/mem/cxl_type3: Refactor CDAT sub-table entry initialization into a function Date: Wed, 12 Oct 2022 14:21:20 -0400 Message-Id: <20221012182120.174142-6-gregory.price@memverge.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221012182120.174142-1-gregory.price@memverge.com> References: <20221007152156.24883-5-Jonathan.Cameron@huawei.com> <20221012182120.174142-1-gregory.price@memverge.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::743; envelope-from=gourry.memverge@gmail.com; helo=mail-qk1-x743.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The CDAT can contain multiple entries for multiple memory regions, this will allow us to re-use the initialization code when volatile memory region support is added. Signed-off-by: Gregory Price --- hw/mem/cxl_type3.c | 137 ++++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 65 deletions(-) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 220b9f09a9..3c5485abd0 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -19,117 +19,93 @@ #define DWORD_BYTE 4 #define CT3_CDAT_SUBTABLE_SIZE 6 -static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, - void *priv) +static int ct3_build_cdat_subtable(CDATSubHeader **cdat_table, + MemoryRegion *mr, int dsmad_handle) { - g_autofree CDATDsmas *dsmas_nonvolatile = NULL; - g_autofree CDATDslbis *dslbis_nonvolatile1 = NULL; - g_autofree CDATDslbis *dslbis_nonvolatile2 = NULL; - g_autofree CDATDslbis *dslbis_nonvolatile3 = NULL; - g_autofree CDATDslbis *dslbis_nonvolatile4 = NULL; - g_autofree CDATDsemts *dsemts_nonvolatile = NULL; - CXLType3Dev *ct3d = priv; - int next_dsmad_handle = 0; - int nonvolatile_dsmad = -1; - MemoryRegion *mr; - - if (!ct3d->hostmem) { - return 0; - } - - mr = host_memory_backend_get_memory(ct3d->hostmem); - if (!mr) { - return -EINVAL; - } - - *cdat_table = g_malloc0(CT3_CDAT_SUBTABLE_SIZE * sizeof(*cdat_table)); - if (!*cdat_table) { - return -ENOMEM; - } - - /* Non volatile aspects */ - dsmas_nonvolatile = g_malloc(sizeof(*dsmas_nonvolatile)); - dslbis_nonvolatile1 = g_malloc(sizeof(*dslbis_nonvolatile1)); - dslbis_nonvolatile2 = g_malloc(sizeof(*dslbis_nonvolatile2)); - dslbis_nonvolatile3 = g_malloc(sizeof(*dslbis_nonvolatile3)); - dslbis_nonvolatile4 = g_malloc(sizeof(*dslbis_nonvolatile4)); - dsemts_nonvolatile = g_malloc(sizeof(*dsemts_nonvolatile)); - - if (!dsmas_nonvolatile || !dsemts_nonvolatile || - !dslbis_nonvolatile1 || !dslbis_nonvolatile2 || - !dslbis_nonvolatile3 || !dslbis_nonvolatile4) { - g_free(*cdat_table); - *cdat_table = NULL; + g_autofree CDATDsmas *dsmas = NULL; + g_autofree CDATDslbis *dslbis1 = NULL; + g_autofree CDATDslbis *dslbis2 = NULL; + g_autofree CDATDslbis *dslbis3 = NULL; + g_autofree CDATDslbis *dslbis4 = NULL; + g_autofree CDATDsemts *dsemts = NULL; + + dsmas = g_malloc(sizeof(*dsmas)); + dslbis1 = g_malloc(sizeof(*dslbis1)); + dslbis2 = g_malloc(sizeof(*dslbis2)); + dslbis3 = g_malloc(sizeof(*dslbis3)); + dslbis4 = g_malloc(sizeof(*dslbis4)); + dsemts = g_malloc(sizeof(*dsemts)); + + if (!dsmas || !dslbis1 || !dslbis2 || !dslbis3 || !dslbis4 || !dsemts) { return -ENOMEM; } - nonvolatile_dsmad = next_dsmad_handle++; - *dsmas_nonvolatile = (CDATDsmas) { + *dsmas = (CDATDsmas) { .header = { .type = CDAT_TYPE_DSMAS, - .length = sizeof(*dsmas_nonvolatile), + .length = sizeof(*dsmas), }, - .DSMADhandle = nonvolatile_dsmad, + .DSMADhandle = dsmad_handle, .flags = CDAT_DSMAS_FLAG_NV, .DPA_base = 0, .DPA_length = int128_get64(mr->size), }; /* For now, no memory side cache, plausiblish numbers */ - *dslbis_nonvolatile1 = (CDATDslbis) { + *dslbis1 = (CDATDslbis) { .header = { .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile1), + .length = sizeof(*dslbis1), }, - .handle = nonvolatile_dsmad, + .handle = dsmad_handle, .flags = HMAT_LB_MEM_MEMORY, .data_type = HMAT_LB_DATA_READ_LATENCY, .entry_base_unit = 10000, /* 10ns base */ .entry[0] = 15, /* 150ns */ }; - *dslbis_nonvolatile2 = (CDATDslbis) { + *dslbis2 = (CDATDslbis) { .header = { .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile2), + .length = sizeof(*dslbis2), }, - .handle = nonvolatile_dsmad, + .handle = dsmad_handle, .flags = HMAT_LB_MEM_MEMORY, .data_type = HMAT_LB_DATA_WRITE_LATENCY, .entry_base_unit = 10000, .entry[0] = 25, /* 250ns */ }; - *dslbis_nonvolatile3 = (CDATDslbis) { + *dslbis3 = (CDATDslbis) { .header = { .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile3), + .length = sizeof(*dslbis3), }, - .handle = nonvolatile_dsmad, + .handle = dsmad_handle, .flags = HMAT_LB_MEM_MEMORY, .data_type = HMAT_LB_DATA_READ_BANDWIDTH, .entry_base_unit = 1000, /* GB/s */ .entry[0] = 16, }; - *dslbis_nonvolatile4 = (CDATDslbis) { + *dslbis4 = (CDATDslbis) { .header = { .type = CDAT_TYPE_DSLBIS, - .length = sizeof(*dslbis_nonvolatile4), + .length = sizeof(*dslbis4), }, - .handle = nonvolatile_dsmad, + .handle = dsmad_handle, .flags = HMAT_LB_MEM_MEMORY, .data_type = HMAT_LB_DATA_WRITE_BANDWIDTH, .entry_base_unit = 1000, /* GB/s */ .entry[0] = 16, }; - *dsemts_nonvolatile = (CDATDsemts) { + *dsemts = (CDATDsemts) { .header = { .type = CDAT_TYPE_DSEMTS, - .length = sizeof(*dsemts_nonvolatile), + .length = sizeof(*dsemts), }, - .DSMAS_handle = nonvolatile_dsmad, + .DSMAS_handle = dsmad_handle, /* Reserved - the non volatile from DSMAS matters */ .EFI_memory_type_attr = 2, .DPA_offset = 0, @@ -137,16 +113,47 @@ static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, }; /* Header always at start of structure */ - (*cdat_table)[0] = g_steal_pointer(&dsmas_nonvolatile); - (*cdat_table)[1] = (CDATSubHeader *)g_steal_pointer(&dslbis_nonvolatile1); - (*cdat_table)[2] = (CDATSubHeader *)g_steal_pointer(&dslbis_nonvolatile2); - (*cdat_table)[3] = (CDATSubHeader *)g_steal_pointer(&dslbis_nonvolatile3); - (*cdat_table)[4] = (CDATSubHeader *)g_steal_pointer(&dslbis_nonvolatile4); - (*cdat_table)[5] = g_steal_pointer(&dsemts_nonvolatile); + cdat_table[0] = g_steal_pointer(&dsmas); + cdat_table[1] = (CDATSubHeader *)g_steal_pointer(&dslbis1); + cdat_table[2] = (CDATSubHeader *)g_steal_pointer(&dslbis2); + cdat_table[3] = (CDATSubHeader *)g_steal_pointer(&dslbis3); + cdat_table[4] = (CDATSubHeader *)g_steal_pointer(&dslbis4); + cdat_table[5] = g_steal_pointer(&dsemts); return CT3_CDAT_SUBTABLE_SIZE; } +static int ct3_build_cdat_table(CDATSubHeader ***cdat_table, + void *priv) +{ + CXLType3Dev *ct3d = priv; + MemoryRegion *mr; + int ret = 0; + + if (!ct3d->hostmem) { + return 0; + } + + mr = host_memory_backend_get_memory(ct3d->hostmem); + if (!mr) { + return -EINVAL; + } + + *cdat_table = g_malloc0(CT3_CDAT_SUBTABLE_SIZE * sizeof(*cdat_table)); + if (!*cdat_table) { + return -ENOMEM; + } + + /* Non volatile aspects */ + ret = ct3_build_cdat_subtable(*cdat_table, mr, 0); + if (ret < 0) { + g_free(*cdat_table); + *cdat_table = NULL; + } + + return ret; +} + static void ct3_free_cdat_table(CDATSubHeader **cdat_table, int num, void *priv) { int i;