From nobody Tue Nov 26 22:33:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass(p=reject dis=none) header.from=nvidia.com ARC-Seal: i=2; a=rsa-sha256; t=1703480267; cv=pass; d=zohomail.com; s=zohoarc; b=ncReNDQcFGLGEotvh4VEbiKPpnJ1nJK+fCn93NXQ0JhR+O4K+hwxbxbelSmNrlpOq2eBjlCpXjSz3oQkNBgSLTMp8o4Cmow7DDDBTo6VaJtJrsSMLDwMfgHkJSjzZekVWzgh0KudJqC/nnVMpCpsOERa9Mv1/Vbyd+9KW1+8Q18= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703480267; h=Content-Type: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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gXeJPm6PlSkTN/xUNdpKvL1M9GFbiIOBBz9u5WLRC8I=; b=ZWv3AlxYETZnLDjyrWwL9N15LRdSioXV9dkEv2G1cnYAADf4qDWk7rxROKpwqD3H1a+3dthQv5w0BbeJPuHtBTl5/F3HIyXN1M+XhyaQUkCtXTTECFm4VErCuCrMp7TDkJW99Z5AlRXOmI6TFX5ctmElES0petM31dXh80+aBDI= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1703480267245635.4570218823586; Sun, 24 Dec 2023 20:57:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rHd19-0007wX-PZ; Sun, 24 Dec 2023 23:56:43 -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 1rHd17-0007vL-Ts; Sun, 24 Dec 2023 23:56:41 -0500 Received: from mail-sn1nam02on2060e.outbound.protection.outlook.com ([2a01:111:f400:7ea9::60e] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rHd12-0001iO-3o; Sun, 24 Dec 2023 23:56:41 -0500 Received: from BL1PR13CA0199.namprd13.prod.outlook.com (2603:10b6:208:2be::24) by CH0PR12MB5107.namprd12.prod.outlook.com (2603:10b6:610:be::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.26; Mon, 25 Dec 2023 04:56:26 +0000 Received: from BL02EPF0001A0FB.namprd03.prod.outlook.com (2603:10b6:208:2be:cafe::d1) by BL1PR13CA0199.outlook.office365.com (2603:10b6:208:2be::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.16 via Frontend Transport; Mon, 25 Dec 2023 04:56:26 +0000 Received: from mail.nvidia.com (216.228.118.232) by BL02EPF0001A0FB.mail.protection.outlook.com (10.167.242.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.14 via Frontend Transport; Mon, 25 Dec 2023 04:56:26 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 24 Dec 2023 20:56:20 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 24 Dec 2023 20:56:19 -0800 Received: from sgarnayak-dt.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41 via Frontend Transport; Sun, 24 Dec 2023 20:56:13 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FBfTzHOj1ll8u4DiuB8SN2nCNcZ0VdIAg22fU0l0l7dOqIayEc2P+IIFx3KxJt3fXyvEe8QV/iLi0hXUiBDxKrrNskdYzpg0RIwud2dVOUX4ED76GHMbZc2LUX37kmKS1cQQgHXFWHefAZzc5OtxfvhnMyx/+ZOx7s0Hy2/mNHa406Rt2GdpxRVf5uWRM+hpS7mRKjLK0WD1lcPUYKHnMGpokXBCVcSof4dC1cloQpj0NTzuX4iikl5wAVE5e7BgQ7wDrgxc2muhLgjTsAFPAI2Dy7fQS3KUtPL34UsS1i8PmYheBJFMrHA2XqNVPGZDne5fXGChnv5DPuycmeGvfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gXeJPm6PlSkTN/xUNdpKvL1M9GFbiIOBBz9u5WLRC8I=; b=Jn9a+AoOaJ3QQIjsInoLQCufhFrwkhvgACzIkO8VnrEnTXF46PXgXNuNxcEIVKOXrjqmUv76GV46brP0so5mwzZ/KwwkNIsVuPnqtfsYsg1mwxtiXFhmEHbT75PlqmxSA+Jk9rF/sHPVqrIRzDXk/qatBxHX8wiezXXR6Lt4HOpJop6AIQbIetQlL8FL5vEtQMWuB3wpEFvm+f1OJAaPpV9eU/yc3o2iuDUyN85P/9llHgjMCJhBLX1mmGwdHbkgJdzJiRKoX2oDyrxoHbtb4MYNJ6WkcWN4CHzD3ebNfaNyx3+0xXoMBEtEL368ZqWw4qsQcOZDtvPf9zrpa4voDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gXeJPm6PlSkTN/xUNdpKvL1M9GFbiIOBBz9u5WLRC8I=; b=Jo1cNcNAlasiVXRaDRZ0Q4XAurUT7UvbDF4Rz5nLsNQisZA6+kqcYs3/mRCVpjRV0Oz+EQSirveVUMN3DUFxjAexKqySssUaBfn9cIlXjfIUAN2slbT6WguwHWfR5icQrvJ1mNvI7yXbMOjsX4Yep2HCP/vflZ1iaI2F/y6XKqlRdDYL9c35QLlmIafCjfOgv+Fmz+CMzUjw3yUtyWTWpgPgI8lTRRN+nF+ZsIx89GjPX9xTbmAjPzsU0gBlJ1zvrwgxsSMFZSpV94EWoqnhDG6g70dtUgGRbBznvZNUTnWjjpq7ED32WFhvnfBIn0sDyJxM16yNwidHb2kQlk8viQ== X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; 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 (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C From: To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Subject: [PATCH v6 1/2] qom: new object to associate device to numa node Date: Mon, 25 Dec 2023 10:26:02 +0530 Message-ID: <20231225045603.7654-2-ankita@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231225045603.7654-1-ankita@nvidia.com> References: <20231225045603.7654-1-ankita@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0FB:EE_|CH0PR12MB5107:EE_ X-MS-Office365-Filtering-Correlation-Id: 89812a94-6ba0-4fdb-818c-08dc0505d985 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K9gApDOlZ30M7ML3jXIRLyvKpgOruqoEttvJ3QAKm9a+hHuGzGiZJxxVlaQqu3dHhdT/E8605q0VPDLWcTkrK3xc9jgMiRHQkpmMRtr0Jkt0Z0ZCZeCn93IsO46IBMaqDOizFapPuGKTmBXjqcWZVBlNP14myjg6yuPGHI/U8emU3UoJ1jsKTkFAcSc6QsOOlGd+n5EasTbhfRt8j+LdUhpHpRbvcJgNQKNmd4Jc7cyCzzF3KYY0gQ+SZGGDqQqD102cCLMJxqwzH7nFY0KFxe+MhBo0ts5KvqA01b3APgEMoNtMfxn3OF+NFHeze5EvW1UXK4tziYRWa5aasNUIdg1Co19qrtYcMUFyDaYSOFqK7vauMnYiL1yejh2Q7Np/79a8w6lYnlEWyRSNvSYJTrfaaBLBxvhEOev/rYS8O7NXajGbJjNBvOwMFqFLXL8BrCmCAA579CWTMYRzo5H/93DMJFqKKoUQACjcb4ecCoENvAirmNMhO1EKbTgcl/YkkBrAL4dqyQz6iDpbv1RysEbQbuzRnz/Ovf5e1tYBaNHTtvGT1DuUS9J4/XltnhXgD/pEv2UPyoaKflA2RUeLl19rzTBlcKsmvcSfpw6paBZ0vH/VAdr2SGIhnIOLpaf1SJFvxQ0ShCb6cp5UZu+uSl+w3Vwaf1aIKMQV+kymK8ZXKxTzbF8+tBb4zddJSYmc33RNE8A8ZSnSdwJnjJMllT4gxSwQiim5BYzPU0X0z0vdkv+2Ao+kBjkqnkLvpzIJ5J6hxjckaVmPrTEhelTwrADBQncoIVVjsW4O3UrginY= X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(346002)(376002)(136003)(396003)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(82310400011)(40470700004)(46966006)(36840700001)(1076003)(26005)(7696005)(2616005)(83380400001)(336012)(426003)(86362001)(8936002)(40480700001)(316002)(54906003)(70206006)(8676002)(70586007)(4326008)(6666004)(110136005)(966005)(478600001)(7636003)(82740400003)(921011)(47076005)(36860700001)(356005)(40460700003)(7416002)(2876002)(41300700001)(5660300002)(36756003)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Dec 2023 04:56:26.0273 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89812a94-6ba0-4fdb-818c-08dc0505d985 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A0FB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5107 Received-SPF: softfail client-ip=2a01:111:f400:7ea9::60e; envelope-from=ankita@nvidia.com; helo=NAM02-SN1-obe.outbound.protection.outlook.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.594, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FORGED_SPF_HELO=2.979, SPF_HELO_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @Nvidia.com) X-ZM-MESSAGEID: 1703480268094100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ankit Agrawal NVIDIA GPU's support MIG (Mult-Instance GPUs) feature [1], which allows partitioning of the GPU device resources (including device memory) into several (upto 8) isolated instances. Each of the partitioned memory needs a dedicated NUMA node to operate. The partitions are not fixed and they can be created/deleted at runtime. Unfortunately Linux OS does not provide a means to dynamically create/destr= oy NUMA nodes and such feature implementation is not expected to be trivial. T= he nodes that OS discovers at the boot time while parsing SRAT remains fixed. = So we utilize the Generic Initiator Affinity structures that allows association between nodes and devices. Multiple GI structures per BDF is possible, allowing creation of multiple nodes by exposing unique PXM in each of these structures. Introduce a new acpi-generic-initiator object to allow host admin provide t= he device and the corresponding NUMA nodes. Qemu maintain this association and use this object to build the requisite GI Affinity Structure. On a multi device system, each device supporting the features needs a unique acpi-generic-initiator object with its own set of NUMA nodes associated to = it. An admin can provide the range of nodes through a uint16 array host-nodes and link it to a device by providing its id. Currently, only PCI device is supported. The following sample creates 8 nodes per PCI device for a VM with 2 PCI devices and link them to the respecitve PCI device using acpi-generic-initiator objects: -numa node,nodeid=3D2 -numa node,nodeid=3D3 -numa node,nodeid=3D4 \ -numa node,nodeid=3D5 -numa node,nodeid=3D6 -numa node,nodeid=3D7 \ -numa node,nodeid=3D8 -numa node,nodeid=3D9 \ -device vfio-pci-nohotplug,host=3D0009:01:00.0,bus=3Dpcie.0,addr=3D04.0,rom= bar=3D0,id=3Ddev0 \ -object acpi-generic-initiator,id=3Dgi0,pci-dev=3Ddev0,host-nodes=3D2-9 \ -numa node,nodeid=3D10 -numa node,nodeid=3D11 -numa node,nodeid=3D12 \ -numa node,nodeid=3D13 -numa node,nodeid=3D14 -numa node,nodeid=3D15 \ -numa node,nodeid=3D16 -numa node,nodeid=3D17 \ -device vfio-pci-nohotplug,host=3D0009:01:01.0,bus=3Dpcie.0,addr=3D05.0,rom= bar=3D0,id=3Ddev1 \ -object acpi-generic-initiator,id=3Dgi1,pci-dev=3Ddev1,host-nodes=3D10-17 \ [1] https://www.nvidia.com/en-in/technologies/multi-instance-gpu Signed-off-by: Ankit Agrawal --- hw/acpi/acpi-generic-initiator.c | 70 ++++++++++++++++++++++++ hw/acpi/meson.build | 1 + include/hw/acpi/acpi-generic-initiator.h | 27 +++++++++ qapi/qom.json | 17 ++++++ 4 files changed, 115 insertions(+) create mode 100644 hw/acpi/acpi-generic-initiator.c create mode 100644 include/hw/acpi/acpi-generic-initiator.h diff --git a/hw/acpi/acpi-generic-initiator.c b/hw/acpi/acpi-generic-initia= tor.c new file mode 100644 index 0000000000..e05e28e962 --- /dev/null +++ b/hw/acpi/acpi-generic-initiator.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved + */ + +#include "qemu/osdep.h" +#include "hw/acpi/acpi-generic-initiator.h" +#include "hw/pci/pci_device.h" +#include "qapi/error.h" +#include "qapi/qapi-builtin-visit.h" +#include "qapi/visitor.h" +#include "qemu/error-report.h" + +OBJECT_DEFINE_TYPE_WITH_INTERFACES(AcpiGenericInitiator, acpi_generic_init= iator, + ACPI_GENERIC_INITIATOR, OBJECT, + { TYPE_USER_CREATABLE }, + { NULL }) + +OBJECT_DECLARE_SIMPLE_TYPE(AcpiGenericInitiator, ACPI_GENERIC_INITIATOR) + +static void acpi_generic_initiator_init(Object *obj) +{ + AcpiGenericInitiator *gi =3D ACPI_GENERIC_INITIATOR(obj); + bitmap_zero(gi->host_nodes, MAX_NODES); + gi->pci_dev =3D NULL; +} + +static void acpi_generic_initiator_finalize(Object *obj) +{ + AcpiGenericInitiator *gi =3D ACPI_GENERIC_INITIATOR(obj); + + g_free(gi->pci_dev); +} + +static void acpi_generic_initiator_set_pci_device(Object *obj, const char = *val, + Error **errp) +{ + AcpiGenericInitiator *gi =3D ACPI_GENERIC_INITIATOR(obj); + + gi->pci_dev =3D g_strdup(val); +} + +static void +acpi_generic_initiator_set_host_nodes(Object *obj, Visitor *v, const char = *name, + void *opaque, Error **errp) +{ + AcpiGenericInitiator *gi =3D ACPI_GENERIC_INITIATOR(obj); + uint16List *l =3D NULL, *host_nodes =3D NULL; + + visit_type_uint16List(v, name, &host_nodes, errp); + + for (l =3D host_nodes; l; l =3D l->next) { + if (l->value >=3D MAX_NODES) { + error_setg(errp, "Invalid host-nodes value: %d", l->value); + break; + } else { + bitmap_set(gi->host_nodes, l->value, 1); + } + } + + qapi_free_uint16List(host_nodes); +} + +static void acpi_generic_initiator_class_init(ObjectClass *oc, void *data) +{ + object_class_property_add_str(oc, "pci-dev", NULL, + acpi_generic_initiator_set_pci_device); + object_class_property_add(oc, "host-nodes", "int", NULL, + acpi_generic_initiator_set_host_nodes, NULL, NULL); +} diff --git a/hw/acpi/meson.build b/hw/acpi/meson.build index fc1b952379..2268589519 100644 --- a/hw/acpi/meson.build +++ b/hw/acpi/meson.build @@ -1,5 +1,6 @@ acpi_ss =3D ss.source_set() acpi_ss.add(files( + 'acpi-generic-initiator.c', 'acpi_interface.c', 'aml-build.c', 'bios-linker-loader.c', diff --git a/include/hw/acpi/acpi-generic-initiator.h b/include/hw/acpi/acp= i-generic-initiator.h new file mode 100644 index 0000000000..9643b81951 --- /dev/null +++ b/include/hw/acpi/acpi-generic-initiator.h @@ -0,0 +1,27 @@ +#ifndef ACPI_GENERIC_INITIATOR_H +#define ACPI_GENERIC_INITIATOR_H + +#include "hw/mem/pc-dimm.h" +#include "hw/acpi/bios-linker-loader.h" +#include "hw/acpi/aml-build.h" +#include "sysemu/numa.h" +#include "qemu/uuid.h" +#include "qom/object.h" +#include "qom/object_interfaces.h" + +#define TYPE_ACPI_GENERIC_INITIATOR "acpi-generic-initiator" + +typedef struct AcpiGenericInitiator { + /* private */ + Object parent; + + /* public */ + char *pci_dev; + DECLARE_BITMAP(host_nodes, MAX_NODES); +} AcpiGenericInitiator; + +typedef struct AcpiGenericInitiatorClass { + ObjectClass parent_class; +} AcpiGenericInitiatorClass; + +#endif diff --git a/qapi/qom.json b/qapi/qom.json index c53ef978ff..7b33d4a53c 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -794,6 +794,21 @@ { 'struct': 'VfioUserServerProperties', 'data': { 'socket': 'SocketAddress', 'device': 'str' } } =20 +## +# @AcpiGenericInitiatorProperties: +# +# Properties for acpi-generic-initiator objects. +# +# @pci-dev: PCI device ID to be associated with the node +# +# @host-nodes: numa node list associated with the PCI device. +# +# Since: 9.0 +## +{ 'struct': 'AcpiGenericInitiatorProperties', + 'data': { 'pci-dev': 'str', + 'host-nodes': ['uint16'] } } + ## # @RngProperties: # @@ -911,6 +926,7 @@ ## { 'enum': 'ObjectType', 'data': [ + 'acpi-generic-initiator', 'authz-list', 'authz-listfile', 'authz-pam', @@ -981,6 +997,7 @@ 'id': 'str' }, 'discriminator': 'qom-type', 'data': { + 'acpi-generic-initiator': 'AcpiGenericInitiatorProperties', 'authz-list': 'AuthZListProperties', 'authz-listfile': 'AuthZListFileProperties', 'authz-pam': 'AuthZPAMProperties', --=20 2.34.1 From nobody Tue Nov 26 22:33:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass(p=reject dis=none) header.from=nvidia.com ARC-Seal: i=2; a=rsa-sha256; t=1703480267; cv=pass; d=zohomail.com; s=zohoarc; b=cS+FS5FbdLZ+PdndzGISWxcnrEtGcm17obsWBC5fItUMHCbq/k1h38Gy0ITMjMkKLvTrp/1ABt8eMBWKGxaKwu3fYL3P+K8G37JkfqgwqkxHOKl0/3AqRRT3Nr224ejmncM48VVWvHUF2nbUixEVgRtZr5WjVd7u/JkXri/ygOQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703480267; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ppHRw6F1lKoe0jGXdQeGMr+pvtqCEpp0ReueG1+t/zc=; b=drmCQQNzOZ94e0ShOymDSLZgYAvORhSZzunh7Y9Jxn20WpSg0YpGnxb81WVzbhOMoo7dPU0mOrHl2VJamZBIx6BFiLNfWaiYp+Afujm6THYaSYK6AHn9QGXqmYTdO0JwLR52Gy8SWjngboBrSvG5m/27UgCRadVXsZdXAELmEko= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1703480267291950.7072788076739; Sun, 24 Dec 2023 20:57:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rHd1B-0007x6-Ae; Sun, 24 Dec 2023 23:56:45 -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 1rHd19-0007wT-Kr; Sun, 24 Dec 2023 23:56:43 -0500 Received: from mail-co1nam11on20601.outbound.protection.outlook.com ([2a01:111:f403:2416::601] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rHd12-0001k2-Gv; Sun, 24 Dec 2023 23:56:43 -0500 Received: from BL1PR13CA0208.namprd13.prod.outlook.com (2603:10b6:208:2be::33) by DS7PR12MB5863.namprd12.prod.outlook.com (2603:10b6:8:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.26; Mon, 25 Dec 2023 04:56:30 +0000 Received: from BL02EPF0001A0FB.namprd03.prod.outlook.com (2603:10b6:208:2be:cafe::f5) by BL1PR13CA0208.outlook.office365.com (2603:10b6:208:2be::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.16 via Frontend Transport; Mon, 25 Dec 2023 04:56:30 +0000 Received: from mail.nvidia.com (216.228.118.232) by BL02EPF0001A0FB.mail.protection.outlook.com (10.167.242.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.14 via Frontend Transport; Mon, 25 Dec 2023 04:56:30 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 24 Dec 2023 20:56:27 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 24 Dec 2023 20:56:27 -0800 Received: from sgarnayak-dt.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41 via Frontend Transport; Sun, 24 Dec 2023 20:56:20 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LCxt2zCPwoHl61rVho88ZIZvRg+YJhZvY2w49N/zYXibdnITo8RSfGCJhusR14dTK33X0GRwU+sfWQjqovv4k0GZs3V98dxOP0YpE9QD7oqsIGxIdJOXoyrEP0oCBSKeeWcy0mk6Imcaed83j8IyMql0KWj4mKby2kg6Lf9WzAJJwNYybVyLDYwtxR6y/10T3udkoPzEE71GKmNA8W5ifgr5ibHAt/NYdXG5K+qZGd9O0tvIxRj3ZYiBK0YpA4Kw9SDG3K7iHwz4efwBKWE30ojz1QYay5gx3TdJsuOPmu7tAmbYkCUKkLdDkDNcw2UnItZzbC0kG3oRZdaFr6tGsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ppHRw6F1lKoe0jGXdQeGMr+pvtqCEpp0ReueG1+t/zc=; b=TOAke8U99S1Hn8Cx7gk8Zg8ZGeNiOQadau2CdQNtG3qf3GNsUdInVFHrC++RrpB005HaX60XXJrrGxxzmljZrxW5urHbu9DWZtE0aXct8PqtywSMEb5yA/GV0meeB9UGq8e1rZuwzKgJcqUtbBmFepFuDfrCCywbycK9i7qiv4RZ+R+2iycjHuNZ0tfRfpnr3fi6CBhQrl6y8MYJcFwnkcI1E3wecMt0WriRMdxBIyovfVmG3hu45mHCTf6ZUJI+FEMB9JwJwYkDpxj68xpXEW3n93rkXln1SLopz3c7g+VZgt+uFwskPI2onW2yvM5qUgtZCL058KJ1VZynwQAtqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ppHRw6F1lKoe0jGXdQeGMr+pvtqCEpp0ReueG1+t/zc=; b=SWu/ZZH5feYpiBFdI9QPSK0PDA9XEp7qbM2kLxvAOUkrUWbHODt4jXdvhNlAGJaDUhtnx2H3dt5YhzHx7K3oZHqdimY7Oa7XtXLK070fjGDfzvBVmY5WmY7wgUr3vy676O/0KF/fgiyRU0EcGlVwX6BE6ACyDHJ5sxz0FFXxUZPrkSao3EQJIJ/sU+f11v9pVrxSjKte8qG4nHAXZzCvfh2lCSIwjG20BlZ+IMLutRS9fJOGCapasnrT/wpvjjOfr/9UqdyMzhz9mV4b9/I5oXDJEW6GtZ1BWEBr/cBxwDrOwMhytd9GcteHiZORIOrBOwTcX3QMprAzb5XIgc2kEg== X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; 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 (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C From: To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Subject: [PATCH v6 2/2] hw/acpi: Implement the SRAT GI affinity structure Date: Mon, 25 Dec 2023 10:26:03 +0530 Message-ID: <20231225045603.7654-3-ankita@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231225045603.7654-1-ankita@nvidia.com> References: <20231225045603.7654-1-ankita@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0FB:EE_|DS7PR12MB5863:EE_ X-MS-Office365-Filtering-Correlation-Id: d9d8bdbe-cf18-458d-c59a-08dc0505dbf3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1c4TakaMzy9SJAINo3H13VYfMrCReYMtuTxzNcNttv1yPLZGEug5krBGHZJ0w589Moh8R9DNk7IiZUIAybCOKcIaW++LsGH6YEcfqqcqKACfsFYpeRbiX6SYlbdzEILCNtaFJsqjNbsobC2zYxFByoBHPBMPW9BjhbTSBwjkrqcm8SbvbzB16Ao6uutttqHFch9xbPzWI53+s6LPZJ9VX2fJbUY436ee2Dd/IlstGW/w5Sfi3CCEiyQ8JJbIdo88hHJkbyT6d1SpIQlHTkHOMotMW2U74W9vZj/T2SVPk8Ww8sFviohg0GoA2tXSJV4ihGHnWrQ+SwEhng2GOqRTAiFgAfNj+QjIaEc8vlF43V6qBN16ulKDAveTHyXT7F71Z2Lhkc7dR8mrTwpx/UJlFDrV5XbPJkcQ7qYg2I6d/voqzZm91oHemuGRlVzSO6HasKTVJxW0Gyf2ZLnUSXdJEZmJkvuLQZ6v/ahXNsc3X8kqdj8F6BzX9oQd5KLs+byexZZgHQ/TxMrI4JHNOO0h3sy085Gi2JfVoRXmqJUshKhjwp1SzIwtp81kRVLr4BCx/Tzm82eXpgSNlqw/dXItqZ3e8yy9bonBXMDQPE3jvJj/KRJhyxjmTF2jbT80gsbAaa/kgkrYhKlG98EfTN+dus9zEZTxybkVJJ7lUu6IAsVU8bYh/AD77iteizOs1z4Sj18thsDB8IzbnSIgucRIWc8SB13oEZRQPW1lHOuzvyuLRNFNx/zkzkyBq0mT14PGjC+UxrvDKmjK4dGpgJ7j/g== X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(376002)(136003)(396003)(346002)(230922051799003)(1800799012)(64100799003)(451199024)(82310400011)(186009)(40470700004)(46966006)(36840700001)(7636003)(82740400003)(356005)(36756003)(40460700003)(921011)(86362001)(40480700001)(1076003)(26005)(2616005)(7696005)(8676002)(8936002)(316002)(6666004)(478600001)(426003)(54906003)(336012)(110136005)(36860700001)(47076005)(70206006)(70586007)(41300700001)(2876002)(2906002)(4326008)(7416002)(5660300002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Dec 2023 04:56:30.1054 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d9d8bdbe-cf18-458d-c59a-08dc0505dbf3 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A0FB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5863 Received-SPF: softfail client-ip=2a01:111:f403:2416::601; envelope-from=ankita@nvidia.com; helo=NAM11-CO1-obe.outbound.protection.outlook.com X-Spam_score_int: -46 X-Spam_score: -4.7 X-Spam_bar: ---- X-Spam_report: (-4.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.594, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @Nvidia.com) X-ZM-MESSAGEID: 1703480268088100001 From: Ankit Agrawal ACPI spec provides a scheme to associate "Generic Initiators" [1] (e.g. heterogeneous processors and accelerators, GPUs, and I/O devices with integrated compute or DMA engines GPUs) with Proximity Domains. This is achieved using Generic Initiator Affinity Structure in SRAT. During bootup, Linux kernel parse the ACPI SRAT to determine the PXM ids and create a NUMA node for each unique PXM ID encountered. Qemu currently do not implement these structures while building SRAT. Add GI structures while building VM ACPI SRAT. The association between devices and nodes are stored using acpi-generic-initiator object. Lookup presence of all such objects and use them to build these structures. The structure needs a PCI device handle [2] that consists of the device BDF. The vfio-pci device corresponding to the acpi-generic-initiator object is located to determine the BDF. [1] ACPI Spec 6.3, Section 5.2.16.6 [2] ACPI Spec 6.3, Table 5.80 Signed-off-by: Ankit Agrawal --- hw/acpi/acpi-generic-initiator.c | 99 ++++++++++++++++++++++++ hw/arm/virt-acpi-build.c | 3 + include/hw/acpi/acpi-generic-initiator.h | 26 +++++++ 3 files changed, 128 insertions(+) diff --git a/hw/acpi/acpi-generic-initiator.c b/hw/acpi/acpi-generic-initia= tor.c index e05e28e962..fa5235f2bb 100644 --- a/hw/acpi/acpi-generic-initiator.c +++ b/hw/acpi/acpi-generic-initiator.c @@ -68,3 +68,102 @@ static void acpi_generic_initiator_class_init(ObjectCla= ss *oc, void *data) object_class_property_add(oc, "host-nodes", "int", NULL, acpi_generic_initiator_set_host_nodes, NULL, NULL); } + +static int acpi_generic_initiator_list(Object *obj, void *opaque) +{ + GSList **list =3D opaque; + + if (object_dynamic_cast(obj, TYPE_ACPI_GENERIC_INITIATOR)) { + *list =3D g_slist_append(*list, ACPI_GENERIC_INITIATOR(obj)); + } + + object_child_foreach(obj, acpi_generic_initiator_list, opaque); + return 0; +} + +/* + * Identify Generic Initiator objects and link them into the list which is + * returned to the caller. + * + * Note: it is the caller's responsibility to free the list to avoid + * memory leak. + */ +static GSList *acpi_generic_initiator_get_list(void) +{ + GSList *list =3D NULL; + + object_child_foreach(object_get_root(), + acpi_generic_initiator_list, &list); + return list; +} + +/* + * ACPI 6.3: + * Table 5-78 Generic Initiator Affinity Structure + */ +static void +build_srat_generic_pci_initiator_affinity(GArray *table_data, int node, + PCIDeviceHandle *handle) +{ + uint8_t index; + + build_append_int_noprefix(table_data, 5, 1); /* Type */ + build_append_int_noprefix(table_data, 32, 1); /* Length */ + build_append_int_noprefix(table_data, 0, 1); /* Reserved */ + build_append_int_noprefix(table_data, 1, 1); /* Device Handle Type: P= CI */ + build_append_int_noprefix(table_data, node, 4); /* Proximity Domain */ + + /* Device Handle - PCI */ + build_append_int_noprefix(table_data, handle->segment, 2); + build_append_int_noprefix(table_data, handle->bdf, 2); + for (index =3D 0; index < 12; index++) { + build_append_int_noprefix(table_data, 0, 1); + } + + build_append_int_noprefix(table_data, GEN_AFFINITY_ENABLED, 4); /* Fla= gs */ + build_append_int_noprefix(table_data, 0, 4); /* Reserved */ +} + +void build_srat_generic_pci_initiator(GArray *table_data) +{ + GSList *gi_list, *list =3D acpi_generic_initiator_get_list(); + AcpiGenericInitiator *gi; + + for (gi_list =3D list; gi_list; gi_list =3D gi_list->next) { + Object *o; + uint16_t node; + PCIDevice *pci_dev; + bool node_specified =3D false; + + gi =3D gi_list->data; + + o =3D object_resolve_path_type(gi->pci_dev, TYPE_PCI_DEVICE, NULL); + if (!o) { + error_printf("Specified device must be a PCI device.\n"); + exit(1); + } + pci_dev =3D PCI_DEVICE(o); + + for (node =3D 0; (node =3D find_next_bit(gi->host_nodes, + MAX_NODES, node)) !=3D MAX_NODES; node++) + { + PCIDeviceHandle dev_handle; + dev_handle.segment =3D 0; + dev_handle.bdf =3D PCI_BUILD_BDF(pci_bus_num(pci_get_bus(pci_d= ev)), + pci_dev->devfn); + build_srat_generic_pci_initiator_affinity(table_data, + node, &dev_handle); + node_specified =3D true; + } + + if (!node_specified) { + error_report("Generic Initiator device 0:%x:%x.%x has no assoc= iated" + " NUMA node.", pci_bus_num(pci_get_bus(pci_dev)), + PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn= )); + error_printf("Specify NUMA node with -host-nodes option.\n"); + exit(1); + } + } + + g_slist_free(list); +} diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 8bc35a483c..00d77327e0 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -58,6 +58,7 @@ #include "migration/vmstate.h" #include "hw/acpi/ghes.h" #include "hw/acpi/viot.h" +#include "hw/acpi/acpi-generic-initiator.h" =20 #define ARM_SPI_BASE 32 =20 @@ -558,6 +559,8 @@ build_srat(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) } } =20 + build_srat_generic_pci_initiator(table_data); + if (ms->nvdimms_state->is_enabled) { nvdimm_build_srat(table_data); } diff --git a/include/hw/acpi/acpi-generic-initiator.h b/include/hw/acpi/acp= i-generic-initiator.h index 9643b81951..76efd5d3f0 100644 --- a/include/hw/acpi/acpi-generic-initiator.h +++ b/include/hw/acpi/acpi-generic-initiator.h @@ -24,4 +24,30 @@ typedef struct AcpiGenericInitiatorClass { ObjectClass parent_class; } AcpiGenericInitiatorClass; =20 +/* + * ACPI 6.3: + * Table 5-81 Flags =E2=80=93 Generic Initiator Affinity Structure + */ +typedef enum { + GEN_AFFINITY_ENABLED =3D (1 << 0), /* + * If clear, the OSPM ignores the con= tents + * of the Generic Initiator/Port Affi= nity + * Structure. This allows system firm= ware + * to populate the SRAT with a static + * number of structures, but only ena= ble + * them as necessary. + */ +} GenericAffinityFlags; + +/* + * ACPI 6.3: + * Table 5-80 Device Handle - PCI + */ +typedef struct PCIDeviceHandle { + uint16_t segment; + uint16_t bdf; +} PCIDeviceHandle; + +void build_srat_generic_pci_initiator(GArray *table_data); + #endif --=20 2.34.1