From patchwork Sun Oct 6 10:27:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankit Agrawal X-Patchwork-Id: 13823744 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2076.outbound.protection.outlook.com [40.107.223.76]) (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 D3530175D5D; Sun, 6 Oct 2024 10:27:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728210472; cv=fail; b=OWhkZbvBmf3b9mZzF9eGbO+8hz2+K/HbZWdfyC2ktxYfYHj26uZXR2nNi5O7w9yv7GT6SVQlNDLt5P5qVPfnpupSKwYaf2gfdBSPeOd6K7sHznGmUmJSPUh8i4+cVubni2TIKS/OUlsO6LaS7eZH1irgAvanNC4aV58LCTXeZA8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728210472; c=relaxed/simple; bh=BSMFMO9m+ZXmyobPZF2qsXOOTgj7FmQ4v+jIfLX8roI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ACfbQzlWkNsR4jHmnoPVqCZwZhzLYfg/3P4SziSp1KE26TpdUy3lnvi7pF4NnBfoG0kcTWsAXP8ES4dUjs1p7yWkgu1gyP0zvqougFRnBgwPUuecP4LuETt2dQVsL1EAVbANuWmMfVhLY+IZweO6kz5MmQNPgui1BPwwfGgCIdM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=l3NvyuY0; arc=fail smtp.client-ip=40.107.223.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="l3NvyuY0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WS2jAFkApRwj7n75Ts9kr7iis263dmn/ocbChO2Z7LO+MVLU2HmxzQQtQCKe1poZ81KV4BwS7mn/IFH3cMxxPBIqXHegHRFo/pxbdaAoPKB2dYgPgTfpVbIjwYzxIBKQdSxEEMI8EMK2uO0WXHeRLAFTB0MVjtWr7V/KSUPrv07jzNxoZHP5xsEFhJV4MkLzI8Wti1src+eHV5SgZT30MeYAlfVDK7xhS+fNTy/BT1mbGkkSdYsWhcNvaxaTxpimp9qZ1u25XLe3mJA61oHqq/TPCoZKKmdGCAu9mK0qKIueicZfTSuVV72qUg3KWeGpc2XiXBJsT3o+0uYLv1ym0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=d7bPqviz6+5cqd0rKLMG/BRUCaOeRJ6OrYm2s36h5tM=; b=d1YREzKHedUFtcaYjNXGi9VTHxQoj19V7y50mK83b6y8+UYH0sK30UInIS/uGbs+UfkJbWYF1uAWuZg6nXbcGOcKAqssvcyBaIy0oMmbGclVhELmBL17A6MmGolhwvD7QWN5rgMzKVgZP8xLWh6/v1FUUqFb70nPC8AlcwBfvGbstsxuUGcvG4Uao1lb2MZwLVq8txjKaZNe3WjAgp0PUT5D4FhA23+AYyAhCbjsZ0LV26PqRCMowlU4msoNSiRjKCzWcBLKPgA7P7TmpmlKz370DqVUpaaxrMOBIHaByXlE2Vp3gXMr0fQtMXj3UpOEOf09PXncWSkjqgP06JPdHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=intel.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=d7bPqviz6+5cqd0rKLMG/BRUCaOeRJ6OrYm2s36h5tM=; b=l3NvyuY0Nb/FGHkck6a1rpuydjmbJMtwAUnRw9+O9JHmo6fJVl8AQFEx77iCCXkP3bTRVbjWVqMT0Ci6NbSdhHoPyqRnap1gEbCaZ/10pIkmetZqaqBgcYhJrrtEYqQFv6qgmNI9kDScu7QUHVR1o0z9W/eDBirIBjkZ+l9i0pVhl6mD1kokJ3+pozJjCx5YS8WEDFjO0YkGrpO+5QkehdPeC723W+kfybjZTkV2jxKgEET0jjzJQniOBJsCJZhTNAkN+YXFvl14ioMvVX+8+MgRRmeHcsYJpznfu9Ai1yq1ozrV/KAHxZiFGfChFnHD7UMenqWRQ8qVNG6eaHDHKQ== Received: from MN2PR10CA0028.namprd10.prod.outlook.com (2603:10b6:208:120::41) by DM4PR12MB5722.namprd12.prod.outlook.com (2603:10b6:8:5d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.20; Sun, 6 Oct 2024 10:27:45 +0000 Received: from BL6PEPF0001AB74.namprd02.prod.outlook.com (2603:10b6:208:120:cafe::46) by MN2PR10CA0028.outlook.office365.com (2603:10b6:208:120::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.20 via Frontend Transport; Sun, 6 Oct 2024 10:27:45 +0000 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 (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 Received: from mail.nvidia.com (216.228.118.232) by BL6PEPF0001AB74.mail.protection.outlook.com (10.167.242.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Sun, 6 Oct 2024 10:27:45 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) 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.1544.4; Sun, 6 Oct 2024 03:27:41 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 6 Oct 2024 03:27:40 -0700 Received: from localhost.nvidia.com (10.127.8.11) 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.1544.4 via Frontend Transport; Sun, 6 Oct 2024 03:27:40 -0700 From: To: , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH v1 1/3] vfio/nvgrace-gpu: Read dvsec register to determine need for uncached resmem Date: Sun, 6 Oct 2024 10:27:20 +0000 Message-ID: <20241006102722.3991-2-ankita@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241006102722.3991-1-ankita@nvidia.com> References: <20241006102722.3991-1-ankita@nvidia.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB74:EE_|DM4PR12MB5722:EE_ X-MS-Office365-Filtering-Correlation-Id: 6211f000-147b-4f91-da83-08dce5f1848e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: IKCEIgik4Pd2erOqslnXAq/sqT4uaaVq4Rb+OML/Xu4+sWly7wR/SbwoQBoCuIYG9PA+4keC2DCe535DvCAGBPxxjb8AkKb9kzdUFqqpciwfF0uePXX8dX1WeVkWlTJGN0dk7yvUxQN+c77FH9aSUKTjaBCpcvO5VgNKyFNIzs1/nHN8BtVcRD63kzG/uhhAiSoMIj+fusSZKhgT+8F/VpFIBFCJObEzMECeoG578YjCqbkKGItmW7orX9wLr6l0a4/4fUgyfD28+SGhFbtmFv0k0BVjCk6DmAppdLjUwMtmrH6Ob6nm/lEArpIKWu9EjMeJgbSvFcxCEJSwrEhpeOtzEMeCWUUk/svPDBYhQEUAVj/IuP9pwDX4QtQTNSRpM1HcI1vqYfC9LglfZ6glhsaESbSA22Nkl5KDySdr7HQBvI3wKFbO/O3YtRRvfCcYntfTRa7pYjwqq+MucCioC6hUYIGFXBj0By30XBwZ/3p/EPGtiwQ3vEHxOLwsswy0Epy0WRCEE5QwhSl/riaiH3p5lDN83hSdGNqmAXeC1NgRkdqRXDP9y7wmLv7K5uzVodN1iVQfsvxsG2yoi0fOGbEs5C803uznIct9BfUHtUkAhQWyoHZF3HuanhViqiA6yl8Ub/3h33PieuaKEI5UzigX1RWPWkqJmQ7awMdspnS5MpIWp9nfZ191+57nplBxwnypPCsL63Fxj9Gl8as7bBEISyeNL3+EItKkVCGLPbY3pNq73XqQFSmERQy2954BTLJARCd+KqVIP+flScya5TguUIVyYzDge6F8T5sGyb5TFfEaDQehkgzHYLPL5pQrFLlvn4cTp7DFO92Ir8h+LNsJpv7lJhy/K5sJ7W0aaFJ/gLcPHmtpcuxSzYZJBjVtk0NSGt4dwECoNeKbvPm2oj/FGzZjFPPWVuBCJsaouWn3hrRaHIuHZzDc8x+5Nk/LwB5AYxJpx1RAIFwia+TxovCC9pENuBoyLrDr0URNu/hPXyf0oD+Diy6efHeiUEe9DYum7mTcl/Y8ZTki1rTxhWroanV4nc6Lj0bOkERefdf7deSlPAd7azpk9RJiaxkszFCoc3id1ccps+kL/CPx7TxU19fie/9UY4mOFmd1qC050ElAPZQjtUPJbbLyWonKYZ0s0EJDQE71BqsS0pPwjbe3DW+SnqBy79tSNlRfuexQqxO9mZKYbt+QcJwtLrDRmX+uTzoaPQhMjnwSf1vB3W5Of2Ihf7UfYIHWy0E213C1Lyi+W3R3Ml445PU5YI0cOscMoYds56C8yyRt/w4AlYLcgHlWv4Ygq/R9jMZaMDnpJVCcikj1Et0yb8HKe3vfZTkN/ebUX62oEJDJ2weKEga9D0DMFs5TA2EVzkoXb9M1sDkKoNUsWZbXNqa8woFf 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:(13230040)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Oct 2024 10:27:45.1570 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6211f000-147b-4f91-da83-08dce5f1848e 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: BL6PEPF0001AB74.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5722 From: Ankit Agrawal NVIDIA's recently introduced Grace Blackwell (GB) Superchip is a continuation with the Grace Hopper (GH) superchip that provides a cache coherent access to CPU and GPU to each other's memory with an internal proprietary chip-to-chip cache coherent interconnect. There is a HW defect on GH systems to support the Multi-Instance GPU (MIG) feature [1] that necessiated the presence of a 1G region with uncached mapping carved out from the device memory. The 1G region is shown as a fake BAR (comprising region 2 and 3) to workaround the issue. This is fixed on the GB systems. The presence of the fix for the HW defect is communicated by the device firmware through the DVSEC PCI config register with ID 3. The module reads this to take a different codepath on GB vs GH. Scan through the DVSEC registers to identify the correct one and use it to determine the presence of the fix. Save the value in the device's nvgrace_gpu_pci_core_device structure. Link: https://www.nvidia.com/en-in/technologies/multi-instance-gpu/ [1] Signed-off-by: Ankit Agrawal --- drivers/vfio/pci/nvgrace-gpu/main.c | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c b/drivers/vfio/pci/nvgrace-gpu/main.c index a7fd018aa548..c23db6eaf979 100644 --- a/drivers/vfio/pci/nvgrace-gpu/main.c +++ b/drivers/vfio/pci/nvgrace-gpu/main.c @@ -23,6 +23,11 @@ /* A hardwired and constant ABI value between the GPU FW and VFIO driver. */ #define MEMBLK_SIZE SZ_512M +#define DVSEC_BITMAP_OFFSET 0xA +#define MIG_SUPPORTED_WITH_CACHED_RESMEM BIT(0) + +#define GPU_CAP_DVSEC_REGISTER 3 + /* * The state of the two device memory region - resmem and usemem - is * saved as struct mem_region. @@ -46,6 +51,7 @@ struct nvgrace_gpu_pci_core_device { struct mem_region resmem; /* Lock to control device memory kernel mapping */ struct mutex remap_lock; + bool has_mig_hw_bug_fix; }; static void nvgrace_gpu_init_fake_bar_emu_regs(struct vfio_device *core_vdev) @@ -812,6 +818,26 @@ nvgrace_gpu_init_nvdev_struct(struct pci_dev *pdev, return ret; } +static bool nvgrace_gpu_has_mig_hw_bug_fix(struct pci_dev *pdev) +{ + int pcie_dvsec; + u16 dvsec_ctrl16; + + pcie_dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_NVIDIA, + GPU_CAP_DVSEC_REGISTER); + + if (pcie_dvsec) { + pci_read_config_word(pdev, + pcie_dvsec + DVSEC_BITMAP_OFFSET, + &dvsec_ctrl16); + + if (dvsec_ctrl16 & MIG_SUPPORTED_WITH_CACHED_RESMEM) + return true; + } + + return false; +} + static int nvgrace_gpu_probe(struct pci_dev *pdev, const struct pci_device_id *id) { @@ -832,6 +858,8 @@ static int nvgrace_gpu_probe(struct pci_dev *pdev, dev_set_drvdata(&pdev->dev, &nvdev->core_device); if (ops == &nvgrace_gpu_pci_ops) { + nvdev->has_mig_hw_bug_fix = nvgrace_gpu_has_mig_hw_bug_fix(pdev); + /* * Device memory properties are identified in the host ACPI * table. Set the nvgrace_gpu_pci_core_device structure. @@ -866,6 +894,8 @@ static const struct pci_device_id nvgrace_gpu_vfio_pci_table[] = { { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_NVIDIA, 0x2342) }, /* GH200 480GB */ { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_NVIDIA, 0x2345) }, + /* GB200 SKU */ + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_NVIDIA, 0x2941) }, {} }; From patchwork Sun Oct 6 10:27:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankit Agrawal X-Patchwork-Id: 13823743 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2067.outbound.protection.outlook.com [40.107.236.67]) (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 25D2416EB5D; Sun, 6 Oct 2024 10:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728210469; cv=fail; b=sI8Rkewj1TQqKekWlzt80L3NedBDfiqjrJ6w+b89kiGAGsjDTFl7ZHHXP5lawY+8NH3BUVDCDOvR2MhOCpsEGcK5CBzHl8Xs91Tt3F1QAP/HxmH2Z+ppetxy2yi9HUSEAM/DWa5jOkubPmeBaeQN2GyAc5GS4okGt0tC6xJiXog= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728210469; c=relaxed/simple; bh=8l9bMb+ZaqTAYNwmZK/0UButZ1yNPiE1HVdgIhOuvYQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ABVXGrHnN81nPkfdmAXl+bIb25BD8mzAoY+pf+wleS1qJYvg+AIyzJrgaQFIsve6LuTqKKNxTiaP0esqGrvI6U/RLctFjhFKt/QM4T1xyfaIukoMyGjgommxp8w91qsCEQiV9YsOe9WVro91qEgqh3ai0ucboYGUmTbRb7G3Noc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=ei1IO+el; arc=fail smtp.client-ip=40.107.236.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ei1IO+el" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oURZuD4BOGPnUjSJpmIqaBB8K6aOFRbvrhxwMQsJryoGNWeSRM5uii9YU3cykGdzgHmdXi6AKTTCnx+kvSGxpNDyGpZdmFqjxwlHo4NkjyTmRYZUSFrhv7ZKFjDbzwWJqgeO2k6XZNvRsAhFN20FuFC5MFIagkoxoDo59EcMnvo6+Cjzen26nmvcpTcSG6YVUfJ8vbdskFqBKfyGgDgKIK9etPZxQ7w3Uryns2F61nQENNB1tipbiYdyRCBV9TmyP3QCm95GfCMe3u+VjXi53xE6eiEluy1ARHSyj4RNwfGPegn63+VDlOFsiWYbfIAIrojRlW0Vh+loKa1yD0NCmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=/4NHjFxo4NHjN1iioXvOlLG6qZsThEK9b4DV/Jv8adE=; b=huoOHyQWuzy3CALYDBA9m81GsVBmfblyU6sIKkRhY+f5fV03EfmkE1qFMtrD706AS0G/fxMG+jG0UuTyPoPJXGfEuAT9FrbkjT69/im4HK2mSN3/0ryPkBIKTxBJBYy71xE5IBgdSVTfblJjMmuBetOGETYRs3b33UM9CYwahEckVU4LGhmmUP00Uiy3uy+TIf/K3qyfUq//iep5ufBFl4i+TKLdoPMDY7J0y6tqOt60eRLEIAFoUiS+qhpB6piCe54OL5BPAaJFfp8Pxp4YdNWd+yHKK59SweDmYx7JfmRRYu/Ykdt36dDRzz2MsVk5t6jFYKKUaFTDIJO6WPzUxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=intel.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=/4NHjFxo4NHjN1iioXvOlLG6qZsThEK9b4DV/Jv8adE=; b=ei1IO+elPOgrVD9olkP50nK00gR4zp8BzrnmtqbgKVAZY2iTZrjBhznEk443CJh9+r8n7s5yOf6X+Ay7uy3ejomHGnNdPseG54BVp1zqBOLkRoXpUKcyVGUUV0jOKMJ7wxnpO7kfh7+TNb6smsB6YqEMkwrC+xLenFg+Yiy039oeAxJXhLHwMhCHhVpDgisHbvRtC1Q8w8hS6ISiOU9LOuS/JJFqonixUxR7V+UtgCbSaog9eRMhKjyDT7zBnMt8LqxGs8DSdwxac/ELOHgjj8ru6yiNlvsBFEGRQnv2TnpKoeseRfN8+jkBK4aHtRXT0xzt0Jksq+jFD07ptMlfzA== Received: from BYAPR05CA0035.namprd05.prod.outlook.com (2603:10b6:a03:c0::48) by IA0PR12MB8694.namprd12.prod.outlook.com (2603:10b6:208:488::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.20; Sun, 6 Oct 2024 10:27:43 +0000 Received: from SJ1PEPF00001CE3.namprd05.prod.outlook.com (2603:10b6:a03:c0:cafe::6f) by BYAPR05CA0035.outlook.office365.com (2603:10b6:a03:c0::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.12 via Frontend Transport; Sun, 6 Oct 2024 10:27:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SJ1PEPF00001CE3.mail.protection.outlook.com (10.167.242.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Sun, 6 Oct 2024 10:27:43 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 6 Oct 2024 03:27:42 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 6 Oct 2024 03:27:41 -0700 Received: from localhost.nvidia.com (10.127.8.11) 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.1544.4 via Frontend Transport; Sun, 6 Oct 2024 03:27:41 -0700 From: To: , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH v1 2/3] vfio/nvgrace-gpu: Expose the blackwell device PF BAR1 to the VM Date: Sun, 6 Oct 2024 10:27:21 +0000 Message-ID: <20241006102722.3991-3-ankita@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241006102722.3991-1-ankita@nvidia.com> References: <20241006102722.3991-1-ankita@nvidia.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE3:EE_|IA0PR12MB8694:EE_ X-MS-Office365-Filtering-Correlation-Id: ec67c07b-9e28-4594-b6ea-08dce5f1833f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: cOHptfGqwol7YgZnPHv8xEtBsCC2sqBbCn/E+OLrs1yw9JDDme6llqCZRlWuJySI7CN5NIE/V4IyGnHK/uLQdkHtpXIfFsbOLmk/YYT054YpgyNuUlGNz9hnMcjbOumGDBGCpU0/PLP8QU9WwQhV37O4aeQQUdGVNLfdg3gO/LVYWdQBsnLYdSM5wK90cdt/EJxCp3ktxsJqvgJwK2Y58OP8oj/ThPbKLmzrMXQZHrgVKCYy5/sDz6hEzMs9Wp78HiC2QwCqE3vuQYP3M4IpCoiuiizD5GPp8rdQ9h4dcVepAks038Uew+6ofE3UO5ZqLOXmVuMkeUMeQh9BApgXb1lMLLYu6vFCLnjbg5UPF7n7FU1JYZqcqCfCD1VSAh3CMCJ06FfmuQqzeZHI1uCiuBpm9/wCVrNMi4T+Tk5FcFPK1B1v5CDgZGRU7hyx9HvttDYyoVnB/46qV4IKL7AZgGiZGk1Cv0/0EfUIs5YVILk5vc2HggDdokNZRrLT9aKG8Zz1M8W/+LxRbBRP8D8W7cKx3Ml0os/Er2wZ7mvY3uTWdNBQg4cmY7zEfRKvWxvDX0kv2c/LQOgV6V7i0NGz9avIq0JMEZznmDE0DvPS8C662kfxKmtpm415bMVbedb/s56HWW/EsXKrx2GLM9hdE0Mnq5aqc3trBnLHSZkiit9S+9tFwaJsYPHzqbyojFWGi23JPjVALUs+1goJM+i/BDmjnHP1gsqIfDEBWODJ3fKlHhQ4lMW61OYEpFerJNNnTk+SxfnUS22NDBCokOvqR0KacVjvEFMsfFawByQTmUvrjKacOc0Ly6GirQMoaQdw/9c57LegVbosOGu99c/xwIYpMnoCscinHFHrAMjDFMzUaUNJmjMrPZvQX9aQZDFfulxmsYN2uEzLcdvMHQGbca1kYh07zW8cB5ZZkdprvXknO+qfUq1e7M6Z5rmuy4Do+cF5y82is75dzi9szhREhZPoTEuJio1XzGzNf1yY6PkwaJIvxWEvIQ2c2oUH5xkAT7WLTlTmHZFjGLWBAG9JpuEwH9wWg0ecGJqI4LI4XApMz58heFkgsFAHeSniBFlx4oHEVnrzKlaya+R+lVx+ogHPSV3Ls2uM4yWMC0r3+BML4gfe8/UXzuxTF/2hLaV4LMKKu/MyXaMuXqs12KxvggFPjsW3en56r/q8D748aUTk46U5tBMm0ASZbZ7VxokvOZBKUQJVUpxuz/n6xzYZIt/1Re0XXDicLF221FzGOQW+mkT0zC4p/WHNtH96PDFvRfyRdL2vbnFNyvdF/1ICCOi+C9g2VQZ07rV373IPDOTqLNV8yhOS0TdcQ4Gl8kPYTikBHwchuGtgTHnJZHjooxCSPdwd8cR5BMXlbgba/R4idodc2ZcoTUQVKofXx8ve X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Oct 2024 10:27:43.1012 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ec67c07b-9e28-4594-b6ea-08dce5f1833f 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.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE3.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8694 From: Ankit Agrawal There is a HW defect on Grace Hopper (GH) to support the Multi-Instance GPU (MIG) feature [1] that necessiated the presence of a 1G region carved out from the device memory and mapped as uncached. The 1G region is shown as a fake BAR (comprising region 2 and 3) to workaround the issue. The Grace Blackwell systems (GB) differ from GH systems in the following aspects: 1. The aforementioned HW defect is fixed on GB systems. 2. There is a usable BAR1 (region 2 and 3) on GB systems for the GPUdirect RDMA feature [2]. This patch accommodate those GB changes by showing the 64b physical device BAR1 (region2 and 3) to the VM instead of the fake one. This takes care of both the differences. Moreover, the entire device memory is exposed on GB as cacheable to the VM as there is no carveout required. Link: https://www.nvidia.com/en-in/technologies/multi-instance-gpu/ [1] Link: https://docs.nvidia.com/cuda/gpudirect-rdma/ [2] Signed-off-by: Ankit Agrawal --- drivers/vfio/pci/nvgrace-gpu/main.c | 32 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c b/drivers/vfio/pci/nvgrace-gpu/main.c index c23db6eaf979..e3a7eceb6228 100644 --- a/drivers/vfio/pci/nvgrace-gpu/main.c +++ b/drivers/vfio/pci/nvgrace-gpu/main.c @@ -72,7 +72,7 @@ nvgrace_gpu_memregion(int index, if (index == USEMEM_REGION_INDEX) return &nvdev->usemem; - if (index == RESMEM_REGION_INDEX) + if (!nvdev->has_mig_hw_bug_fix && index == RESMEM_REGION_INDEX) return &nvdev->resmem; return NULL; @@ -715,6 +715,16 @@ static const struct vfio_device_ops nvgrace_gpu_pci_core_ops = { .detach_ioas = vfio_iommufd_physical_detach_ioas, }; +static void +nvgrace_gpu_init_nvdev_struct(struct pci_dev *pdev, + struct nvgrace_gpu_pci_core_device *nvdev, + u64 memphys, u64 memlength) +{ + nvdev->usemem.memphys = memphys; + nvdev->usemem.memlength = memlength; + nvdev->usemem.bar_size = roundup_pow_of_two(nvdev->usemem.memlength); +} + static int nvgrace_gpu_fetch_memory_property(struct pci_dev *pdev, u64 *pmemphys, u64 *pmemlength) @@ -752,9 +762,9 @@ nvgrace_gpu_fetch_memory_property(struct pci_dev *pdev, } static int -nvgrace_gpu_init_nvdev_struct(struct pci_dev *pdev, - struct nvgrace_gpu_pci_core_device *nvdev, - u64 memphys, u64 memlength) +nvgrace_gpu_nvdev_struct_workaround(struct pci_dev *pdev, + struct nvgrace_gpu_pci_core_device *nvdev, + u64 memphys, u64 memlength) { int ret = 0; @@ -864,10 +874,16 @@ static int nvgrace_gpu_probe(struct pci_dev *pdev, * Device memory properties are identified in the host ACPI * table. Set the nvgrace_gpu_pci_core_device structure. */ - ret = nvgrace_gpu_init_nvdev_struct(pdev, nvdev, - memphys, memlength); - if (ret) - goto out_put_vdev; + if (nvdev->has_mig_hw_bug_fix) { + nvgrace_gpu_init_nvdev_struct(pdev, nvdev, + memphys, memlength); + } else { + ret = nvgrace_gpu_nvdev_struct_workaround(pdev, nvdev, + memphys, + memlength); + if (ret) + goto out_put_vdev; + } } ret = vfio_pci_core_register_device(&nvdev->core_device); From patchwork Sun Oct 6 10:27:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankit Agrawal X-Patchwork-Id: 13823745 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2080.outbound.protection.outlook.com [40.107.237.80]) (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 C316217921D; Sun, 6 Oct 2024 10:27:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728210481; cv=fail; b=neL9yXpH5F6CROdn2hnt0SaKZOwvDiK12mUAoB7mkueo8Ycpxdha29tNb0Zp3ZlkLwMZMgn+o6UIi8x+ZXX7HaGm44Z1BBvfK+9eW56c20QKZwcwiWU8pPb72CyRFVLm2/oRz803rkCUPlEmfHT+fLB7n3GfAApWbWULIC35jQg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728210481; c=relaxed/simple; bh=XF5lDtBot0P4pWLf8DwKRI0uudKWxdf3zzws7FUVYEc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mtlxl4MMGtU0qdMEDm6/0ZUn3vu7gx43ME770jxh55+b/jm6GxfuL6Mg890lJPXiiZTuJazOb4kHaUzzMqLcPivgSbMlLrdQYgHB1CZ4s56UbvHW7TlpcJeTYVHOocHjsp22KRj9qm25JTFp/664kAyle39kCo0gEpUMmiI1tfs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=rhHji62F; arc=fail smtp.client-ip=40.107.237.80 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="rhHji62F" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jZx8cu6c2sxl2Gfu4Alryrg5Yim4MTXHhnC14YTgzKdm08fqAccoj09O+wuN85oyM+7/eqYV+ZEaaT4x98FAL9yg+pVRtDBlGhSyYFR6Ks78M4DZusqxur6SLJ90RpLhfnPnuUxtmPMstJhxD/GYjMWFAxA2jaZjO3HzTIEfIlF6xrJPPTpDn6VTdV74YdtoUqj36Wru9r6B3XjgtfQ29md3SSOMl0pEPGFERwQNMcRKKOVdA+AoFAkJDV5O505mBW/0Vrz6HWzKWgSY5uNkj3H9bgzQjDHe3NqzHsRumE7e24QkJ0nfAVh7oyLu31G0jHHRnYfb9s5PFm8iPDbv3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=a4mE10onXOhqVJ/p2RjSiijJfYNSPjekABgGum3zBSM=; b=d3IzvxQAQw979nsR84IKwZjLIHFpfpTAX1ZyTFernBP8H3pAvBOmogzgmUwQA8NZ4Z5M+nwTmhhLu6R/pV8ub7Ge3qgLrfK+sGrof5x6bwHv2Tg55FIFFE9yrtiZtDeG3QLBKSEgB442GO4q7lgw9pDUVT4NIjErcACLbbFKsAQGj4GsE6J3we8OoOErxnidcVu0GjXJN7CMND1sXGRdMFMncJvSed797dtUmWzoZidZVfo7VnVpIpaTYsyfOPaNBzZa6TTZVVkyly3vKQzMGophaBljPoNBhp8AXlY7ys9+YhX3Bed1N0fskkAHlFODvB3G1LWDdLVknq1VufIwYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=intel.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=a4mE10onXOhqVJ/p2RjSiijJfYNSPjekABgGum3zBSM=; b=rhHji62F0DT/TlVqBDgkbDgaHo1VQFsnRcCHMiEyPUZ7b/c+uGPbp5tW+GvYcB1GxXM003j8yUWtxVHPLyCCztX6TxTEysu6mRUfMaqRFtznehqM1Sd4XSFJpuEd1iYBy+1PjiKMSo+mHsG9qS+SHPlhCFqfVHPZUJk2eY16712rTMmkcYDz60HXL02Ioiha+1rnv7imPx+8Mv1CYQbYJ1ft+ELZfliCMuVbDJOY6SinmZK4+Iq3+h8S2VmvQesSVbewOU4OK+wvcGC88I5kgrIhueRfeTTLlq/dVz0dG6CNBY32+CeJb1dR1S054eGfq4VfTuzXML5uzUy57s4dmQ== Received: from MN2PR10CA0005.namprd10.prod.outlook.com (2603:10b6:208:120::18) by CY5PR12MB6107.namprd12.prod.outlook.com (2603:10b6:930:28::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.20; Sun, 6 Oct 2024 10:27:50 +0000 Received: from BL6PEPF0001AB74.namprd02.prod.outlook.com (2603:10b6:208:120:cafe::15) by MN2PR10CA0005.outlook.office365.com (2603:10b6:208:120::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.20 via Frontend Transport; Sun, 6 Oct 2024 10:27:50 +0000 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 (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 Received: from mail.nvidia.com (216.228.118.232) by BL6PEPF0001AB74.mail.protection.outlook.com (10.167.242.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Sun, 6 Oct 2024 10:27:50 +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.1544.4; Sun, 6 Oct 2024 03:27:43 -0700 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.1544.4; Sun, 6 Oct 2024 03:27:43 -0700 Received: from localhost.nvidia.com (10.127.8.11) 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.1544.4 via Frontend Transport; Sun, 6 Oct 2024 03:27:43 -0700 From: To: , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH v1 3/3] vfio/nvgrace-gpu: Check the HBM training and C2C link status Date: Sun, 6 Oct 2024 10:27:22 +0000 Message-ID: <20241006102722.3991-4-ankita@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241006102722.3991-1-ankita@nvidia.com> References: <20241006102722.3991-1-ankita@nvidia.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB74:EE_|CY5PR12MB6107:EE_ X-MS-Office365-Filtering-Correlation-Id: 0aee605c-9baa-42d4-5800-08dce5f18793 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: VnTe1ftYKl+8XEB0J76i86qrWkg7SFkC+uKSbDYP7cHpYuqdUDu+AIo0dM3a8RhF2jW/fgUe4RgyLbrj5/iy35S4phvmM5ve0s7jms5yhaIk002wfZRQHuXUeIbAVBSWUgGmcP+jkQWUo/+nqOmLYFzTua0pkOsRnoUwv60b3/yg3AvkyRK9Xpw7X60cQuYbmIC6nypVoG7eiy4pC7xPgWJrZTAd9MZOAOnnKJ3PFhUvcCGEg2QMIQFGLERrE5k3UXgJeqYpB5Bzq3kvl5X+7AQOdmZexjCFTiAsP3fdCoztxmdy7x2Gyj+hVC7U8yKnazgMBg+HgXjzXkURQtMyWMZoOyK+uv69rDsN4eHuOHvtWkIo0p7gV/97xQQRIhqNCRrMS2odPlZUGFdOIwu9rgRCtY9PQvzhjG0udsvUrzrrXYcGzYA2YK02VWRIqdZcllRQuEvqZHVbkn4F8zQTnLTdHLMAb7blCuZIzjdRYcOmAoBhQDeGHKp7Q5P5zF2LAvtWH8lKRiDCZJ7cGCxPN+cnDgKH0l32Apf1gvhUxV/HuHIAceX50inO2+CZTAZbIkevwva6ET2g4C0pL3EyKzaH0C/ra76tISVuRfEZt2h2X+RSPwMwhTUVPm6bGQwrzOd/PLQcT/RQy8N/+ul5QJdGNuCLocxzBnuYQnFCdeTMSM+lz9dlE4HxvKT/t4FgRVaeBGQKx3RyxsCjiSNFs9rI+ZuuzDDB+ZcInBYP5jVfJQeq+UBNTJTD30Rfd7Xa/ahpebxVo3KlTsrM+sIcR+UHkRU5TDhuE4eqgs4P4Ro3zZAzzNO4vbjWKZvkzqjl8+6xvq6zVBEgny1zHHfuCMrmeIw+GlohO9KVVCMNtHl4XKcUpTp2wDpgcPNuBxNYKAcnRlQ0xmBCjiuQy8KpmGUG1O3YzGUfPFZ6A06hlTh6iC/RyG4thW1CkfvUJTpstcpPJ/SHaDpPsClCrPogKRoUNJqtzwKRL3sSvHEddHE4oIY3lCD/Aky1N877fnHt4VhKvSdA74l4u2vwdQ3aEX4601nvK8Pht4V/63bU4Vg8VekuZ6zrjsv6cW3zWqG8M18SlHuakAEQALK5TsKtrccZg40TUWPSbxoXPRnX3sqX9YtIumEgjRYo8Ltnqqfg4faBB/VTMutm2H/Y7rOb0LlVc7AGTbhhPX4XzLlN5is77S/Nnwh8ygNPos9q18LTWTdtqNZfYiZXVrfeP7eOK2L/3YKe/yVAseKOaDlFhKCm6LZfk+xgkqcp5YxQ8LR+OJwI377OjoD5vQESr2pNUWT2+W/4rKVrln7PGQJFRf5YcItIJmAjxaePomADIuDvapLMam19KenX+1Fgd4E1voUOCD2JC8H91Td5EWiaoak= 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:(13230040)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Oct 2024 10:27:50.2196 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0aee605c-9baa-42d4-5800-08dce5f18793 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: BL6PEPF0001AB74.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6107 From: Ankit Agrawal In contrast to Grace Hopper systems, the HBM training has been moved out of the UEFI on the Grace Blackwell systems. This reduces the system bootup time significantly. The onus of checking whether the HBM training has completed thus falls on the module. The HBM training status can be determined from a BAR0 register. Similarly, another BAR0 register exposes the status of the CPU-GPU chip-to-chip (C2C) cache coherent interconnect. Based on testing, 30s is determined to be sufficient to ensure initialization completion on all the Grace based systems. Thus poll these register and check for 30s. If the HBM training is not complete or if the C2C link is not ready, fail the probe. While the time is not required on Grace Hopper systems, it is beneficial to make the check to ensure the device is in an expected state. Hence keeping it generalized to both the generations. Signed-off-by: Ankit Agrawal --- drivers/vfio/pci/nvgrace-gpu/main.c | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c b/drivers/vfio/pci/nvgrace-gpu/main.c index e3a7eceb6228..5736d8f8caa3 100644 --- a/drivers/vfio/pci/nvgrace-gpu/main.c +++ b/drivers/vfio/pci/nvgrace-gpu/main.c @@ -5,6 +5,7 @@ #include #include +#include /* * The device memory usable to the workloads running in the VM is cached @@ -28,6 +29,13 @@ #define GPU_CAP_DVSEC_REGISTER 3 +#define C2C_LINK_BAR0_OFFSET 0x1498 +#define HBM_TRAINING_BAR0_OFFSET 0x200BC +#define STATUS_READY 0xFF + +#define POLL_QUANTUM_MS 1000 +#define POLL_TIMEOUT_MS (30 * 1000) + /* * The state of the two device memory region - resmem and usemem - is * saved as struct mem_region. @@ -848,6 +856,47 @@ static bool nvgrace_gpu_has_mig_hw_bug_fix(struct pci_dev *pdev) return false; } +/* + * To reduce the system bootup time, the HBM training has + * been moved out of the UEFI on the Grace-Blackwell systems. + * + * The onus of checking whether the HBM training has completed + * thus falls on the module. The HBM training status can be + * determined from a BAR0 register. + * + * Similarly, another BAR0 register exposes the status of the + * CPU-GPU chip-to-chip (C2C) cache coherent interconnect. + * + * Poll these register and check for 30s. If the HBM training is + * not complete or if the C2C link is not ready, fail the probe. + * + * While the wait is not required on Grace Hopper systems, it + * is beneficial to make the check to ensure the device is in an + * expected state. + */ +static int nvgrace_gpu_check_device_status(struct pci_dev *pdev) +{ + void __iomem *io; + int time_elasped; + + io = pci_iomap(pdev, 0, ~0UL); + if (!io) + return -ENOMEM; + + for (time_elasped = 0; time_elasped < POLL_TIMEOUT_MS; + time_elasped += POLL_QUANTUM_MS) { + if ((ioread32(io + C2C_LINK_BAR0_OFFSET) == STATUS_READY) && + (ioread32(io + HBM_TRAINING_BAR0_OFFSET) == STATUS_READY)) { + pci_iounmap(pdev, io); + return 0; + } + msleep(POLL_QUANTUM_MS); + } + + pci_iounmap(pdev, io); + return -ENODEV; +} + static int nvgrace_gpu_probe(struct pci_dev *pdev, const struct pci_device_id *id) { @@ -856,6 +905,10 @@ static int nvgrace_gpu_probe(struct pci_dev *pdev, u64 memphys, memlength; int ret; + ret = nvgrace_gpu_check_device_status(pdev); + if (ret) + return ret; + ret = nvgrace_gpu_fetch_memory_property(pdev, &memphys, &memlength); if (!ret) ops = &nvgrace_gpu_pci_ops;