From patchwork Fri Dec 15 14:01:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13494486 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2086.outbound.protection.outlook.com [40.107.92.86]) (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 E0ABF31A60; Fri, 15 Dec 2023 14:02:19 +0000 (UTC) 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="TfJmdQuW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oJNtR2g13HatLfOlwHeHobJbnBvmC8CKD8v7BxjXiwhPFdaetRaCtXXpqsp1KEuUc7hRCKxw3lm6x+TCQIdSndZGZKfPkOnPXJ+FuCgsa6HrbqZV2ytPPvpu5NR8P4hqr2yx6hzbBZDjt1Zz4CdbkLRVpiORUmjoeZuz+IzWYHu//16C4Ab6UmPEF0Itr5IofSZSnTPIymWCl/z4gVgWLlCWGP6kbNEilRHcg/FN/5DndMHzbSvbiXG7ZPbfh/qvwBzpwuW4lQxi4FSftepuCtL7KvXjG8FveIagtr/O5h5FNmD/n/OvpJ5q4IoIYdBwiuVt2UhhaNwUS0WeDjeaqA== 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=yfHOQCLFJHnJBlBhyduPWB5HBqN4yk6hN4g/bB/sNgw=; b=JOrsbCBB7I7h80gtf6ZBaZ0IfMjn3kBY1D3j3ux5wSzwhkwt+gYhdJ4GgE8YHhx25M6cLIIxmMPMzRR7Dktwytc+7ahJdcv7+6VFsax76BNxke/zVMdm1AYoAK/oqFTO7+R6YxVWA8fn8OwmecJ7eGTeIKTokroBcP/J3nfpgAfASc3EzAGwPmWaYWt6mDFSHQbcSp3JJyuf8P2EdxHyytkTBqzWw4rghpOcdLZzgKVgjHPmqsX7pnGOm0BJu0k180fcf4Q25PhnhsowSG6tZ4qr32vrDckyxKtDsfupK3rODmNslzmPZ4TNRtiDIT9Gbm2zEgn6hM/IYCByPPIFWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.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=yfHOQCLFJHnJBlBhyduPWB5HBqN4yk6hN4g/bB/sNgw=; b=TfJmdQuW8DP5Xn3po+kBLAYDssI1RJ/RKM/vKEUe2QEXDmCKAncesTl8X2R0rwBEaZsfK7AQmOyYI0cYzHMN3xj62zx5ezCYx41bz5yKbYWYdT6YVkmN42/8aSjKSr1T/O5eg2I/hzmNB8S2ZCpA/PTyCd6xMdXDFufAIFLazhQVeOxbXb7RlVFZzMpnwQPRxq0jHycJWK9tZzSV0vF6OgOO8l5gPH9ubP6XeyWdhC5H+TGK1VAlCkWndDxfEhgChomCaLWTWxxFo+f/GtZpgroJD0BZSR95d+HrvlPsOBm0ftLFgpnvzqSYmU21Ad9Mxrcoegr7uHqSvNfis2FksA== Received: from DS7PR03CA0185.namprd03.prod.outlook.com (2603:10b6:5:3b6::10) by IA1PR12MB7661.namprd12.prod.outlook.com (2603:10b6:208:426::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.28; Fri, 15 Dec 2023 14:02:17 +0000 Received: from CY4PEPF0000EDD4.namprd03.prod.outlook.com (2603:10b6:5:3b6:cafe::8d) by DS7PR03CA0185.outlook.office365.com (2603:10b6:5:3b6::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31 via Frontend Transport; Fri, 15 Dec 2023 14:02:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000EDD4.mail.protection.outlook.com (10.167.241.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.14 via Frontend Transport; Fri, 15 Dec 2023 14:02:16 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:01:59 -0800 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:01:59 -0800 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Fri, 15 Dec 2023 06:01:56 -0800 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , Gal Pressman CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo Subject: [PATCH mlx5-vhost v3 1/6] vdpa/mlx5: Expose resumable vq capability Date: Fri, 15 Dec 2023 16:01:41 +0200 Message-ID: <20231215140146.95816-2-dtatulea@nvidia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215140146.95816-1-dtatulea@nvidia.com> References: <20231215140146.95816-1-dtatulea@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: CY4PEPF0000EDD4:EE_|IA1PR12MB7661:EE_ X-MS-Office365-Filtering-Correlation-Id: 4b7372a3-5f66-48f8-ba4c-08dbfd767270 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wkJ6lVnStwZAM0uGmCztfdTgQuyGlXmeIIekbiRqr8+e7lrKm6tVLmCpGPW0bXJSks6GI7PjGcQTy8n7hP2PWac5VrpvFpkzbsg7aZULv+uO1L/6bLpvaIQGekTdlizF7L+9fgXJ8Hk6KkOXgBW0zHQSdBVktoabQFKwOfuHgSAptRZH3nYoIwiAzUvtf3fSYKgpyVizrbtABqfzMxSOGZ6+Krbcx+j+k9RuO03xO0s/2LI7FyzmwitqUnh09uZZKu/sLDW/3fS/vxmwTajhFsyFklO9C4vYP/JskLVkLLftCIfXVWshRzH8yXLZKEhS/NIT1w49TEsvBl53uZl0WCz8ZLDEE2OoMn0iQp+38RLXWeBvScCyIig75mVnVPCuMFH4fPrpHG2AieHQXgX/K0ro1ymXhcpxQzH0zNRvUuC8mvKRCYEkCS4maznK3QrCghqeczTeUEraqFVUDi5QvJwBIyYDFmwt01BMKD/lwnnOo2un+A32NqrHbz2TvQ7RifKwCocIxnmVqFeNmByb0mTPEsQg5TvhADmAu80lzwWGif6wAYKfYZLJUeVnbHh2wPEaQEBXN5DQVUdQ8ALlXl2+BDpF+1lZAqnWYzaXuZNU3J2dHskOzSZz67aSjH2oqC98DTgeWW55qL90YwSl1CB3q2SoDdsvXshgHp8Pc/xbbgB+wqfuT8tAvWJ3q84uuNSoQnvsXzmzFnrFWQWSZHjNRY1c4npARerMdJWMR4DiBqXcHho+TL+mxeNSYNaU X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(346002)(39860400002)(396003)(136003)(376002)(230922051799003)(1800799012)(186009)(64100799003)(451199024)(82310400011)(46966006)(36840700001)(40470700004)(5660300002)(40480700001)(478600001)(6666004)(54906003)(82740400003)(4744005)(2906002)(1076003)(66574015)(2616005)(26005)(86362001)(426003)(336012)(36756003)(70206006)(70586007)(316002)(6636002)(110136005)(40460700003)(4326008)(8676002)(8936002)(7636003)(356005)(41300700001)(47076005)(83380400001)(36860700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 14:02:16.9609 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b7372a3-5f66-48f8-ba4c-08dbfd767270 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7661 Necessary for checking if resumable vqs are supported by the hardware. Actual support will be added in a downstream patch. Reviewed-by: Gal Pressman Acked-by: Eugenio Pérez Signed-off-by: Dragos Tatulea --- include/linux/mlx5/mlx5_ifc.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h index 6f3631425f38..9eaceaf6bcb0 100644 --- a/include/linux/mlx5/mlx5_ifc.h +++ b/include/linux/mlx5/mlx5_ifc.h @@ -1236,7 +1236,8 @@ struct mlx5_ifc_virtio_emulation_cap_bits { u8 reserved_at_c0[0x13]; u8 desc_group_mkey_supported[0x1]; - u8 reserved_at_d4[0xc]; + u8 freeze_to_rdy_supported[0x1]; + u8 reserved_at_d5[0xb]; u8 reserved_at_e0[0x20]; From patchwork Fri Dec 15 14:01:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13494487 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2043.outbound.protection.outlook.com [40.107.96.43]) (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 6845931A6E; Fri, 15 Dec 2023 14:02:21 +0000 (UTC) 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="Sl57bRPD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QRG5KDQaVIMV8wIRcZy5zxscgOrW1ilPyFbDVlpIIzQyssibabkUEQOOYVHPHwGWIXy0ZUCx3fUdWn2GQaIEA7ByQKlFvs5IN4QDwdvXmX0YUbf6YJRQu4au839He5Zb9evVTZJI+0L43Dx6Gl27hFl0dYaN09u4HrW/B3pI/F3tKvzaKLLzYG1iD1hgop99etmO8uIktcS1p/M4Jti6ContxrhHTPu+gCV2JKRsuvWGsMA6FWP/YdqqwZ18OM021PakZ3H2X9YI7CJNIGEfOusH3lQ90n2YJKIq8j7vd7odJv6i6EHd3ZsY3J4zXh5vqJsqOJWqzStzk22daIZwdg== 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=2TylNfpW+6Q9SObHOV4Gz2YDSDSlijQBPCRfcODsmnw=; b=BSIONikxP6+uJPfJjOKyXpE7JdDm0uHz347wW9DVwV6IauuAsg6ySSnKzYdjpYGnnoUg95xzjTNI/N8z8IdlRaCMLVPiJRLNr4mzv6xedGYsfc/wWvZUXcPP9+RRBkl08RZ2SZiUWk0dJWwIivFbGuvkDv62VjVym68Ib8e88AyTJyqlFj2AML4QjH4OdnhQmFRI0qryAd/dZMUS13exBAZmHxDWQUqt4+usMiQ8D5G2Bcs3r8g7c5Cr6nOgSq7SCFVU61+P9zcLZ2dD5J1VGTcDAtyltmz7v2aqJa4KL5rWLtxT59AthgWQvliF/cS8GLPID5hv+hYNvNmmX6ZwzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=2TylNfpW+6Q9SObHOV4Gz2YDSDSlijQBPCRfcODsmnw=; b=Sl57bRPDtA2DhLbHFnUT1pVK4+qh2T/CMQdOY3iTwjjEc4K7ERgHck3lzX7w8ZMjjKAdPWwxlVUDNhHAVOE6KQfFULqR88FZJvLQg8xQeqabGK8i/eGPaHQtIKMaASmI9MIfIX1c0xoqQNTMyt4guyOXwap30yikASggcx/MpmbcOuI0fHgogLbeWf2U1BBFyPbHFB3dcrT4clK7piBroKb8C2xBMqu69h11aUhfDC7tXlroqkIu7wx2YrRmuK+fFCZi0r/eTe64Ne9afHGTJSZUrLi4L0ObQP/U1wspqyavwOfZS25QSLbYiZFzSNb3+w1IFGQ6l0YKpus+6hIzyw== Received: from MW4PR03CA0066.namprd03.prod.outlook.com (2603:10b6:303:b6::11) by BL0PR12MB4882.namprd12.prod.outlook.com (2603:10b6:208:1c3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.30; Fri, 15 Dec 2023 14:02:18 +0000 Received: from CO1PEPF000044F6.namprd21.prod.outlook.com (2603:10b6:303:b6:cafe::50) by MW4PR03CA0066.outlook.office365.com (2603:10b6:303:b6::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31 via Frontend Transport; Fri, 15 Dec 2023 14:02:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1PEPF000044F6.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.7 via Frontend Transport; Fri, 15 Dec 2023 14:02:18 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:02:03 -0800 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:02:02 -0800 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Fri, 15 Dec 2023 06:01:59 -0800 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , Gal Pressman CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo Subject: [PATCH vhost v3 2/6] vdpa/mlx5: Allow modifying multiple vq fields in one modify command Date: Fri, 15 Dec 2023 16:01:42 +0200 Message-ID: <20231215140146.95816-3-dtatulea@nvidia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215140146.95816-1-dtatulea@nvidia.com> References: <20231215140146.95816-1-dtatulea@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: CO1PEPF000044F6:EE_|BL0PR12MB4882:EE_ X-MS-Office365-Filtering-Correlation-Id: 632488e5-0448-4309-928c-08dbfd76734a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SiaGfGF7BsKy3s+OhtLvkncrFj/v7qpWuHVIdUpiyeLUhvayeiOslYQ7Ml0pv2KThLwkebR7uOxAAEht96dtOEMOVrkcAgm6gC24xAt1izF7bN/RmCBe8CS4npM8SsjV2hn82DMfMVCL5P69DVGhkmWcuMlWpmtEkta5NT/nn722nZR2IBTfJ4u3NobdPgj3S26DwzRzewe2VB0fpAILWoEpsF7eGwa1sohIUdTA/T2oDTdblbpzIXWQxdlF9x9EBxCk80tIxN04Opk5ROfzRUKvGjODlF9khSLgqrLUKKA9poxh4fzVvymX6hfOSnYsVyXWEloAkrmiVAaMgvoKe11SWibH2eUWxBpGkfI2MNx+BEAjdB+rPWgN4EIA6tjjxfXU5AszlY3bmClofoKcC0w1ZsL6+zCRJErCABxANI6JtkZZvOud8XPm/3WXESFcFuFXIYbYI5t+BpyIEK+zFQuXVEjmp+JzyUT4dIQk5hWT7aT1wTfYOyV9afpvlRFD5u2g5FLtK/DeVV76X3MRzOg0m3r3vraYgEDg2y0nOlOckb3GhgfHyaGcqL/8X49+Gzlhkl+cXM47Oi0g3lkvOUId5kVqkWHPmWr3qMDrISWdJMcvkOXBz+BOqx4ABKaQemsgOnFmcPFBq8SjNhVXbgjtGojg6EswkR+tVm2yAO3kKWft5Ro3QwiG+nz2kOdW79W7kALOJxMth5F/afv2wnsBLKLQiY0uz9F1l1wbyFzrRh9Y7+a9FEyM/wWV+PkB X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(346002)(396003)(39860400002)(376002)(136003)(230922051799003)(451199024)(186009)(82310400011)(64100799003)(1800799012)(40470700004)(36840700001)(46966006)(40480700001)(66899024)(478600001)(40460700003)(6666004)(8676002)(4326008)(8936002)(47076005)(2616005)(426003)(336012)(110136005)(70206006)(316002)(83380400001)(6636002)(70586007)(54906003)(26005)(5660300002)(1076003)(82740400003)(7636003)(36756003)(356005)(2906002)(86362001)(36860700001)(41300700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 14:02:18.3104 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 632488e5-0448-4309-928c-08dbfd76734a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044F6.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4882 Add a bitmask variable that tracks hw vq field changes that are supposed to be modified on next hw vq change command. This will be useful to set multiple vq fields when resuming the vq. Reviewed-by: Gal Pressman Signed-off-by: Dragos Tatulea --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 48 +++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 26ba7da6b410..1e08a8805640 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -120,6 +120,9 @@ struct mlx5_vdpa_virtqueue { u16 avail_idx; u16 used_idx; int fw_state; + + u64 modified_fields; + struct msi_map map; /* keep last in the struct */ @@ -1181,7 +1184,19 @@ static bool is_valid_state_change(int oldstate, int newstate) } } -static int modify_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq, int state) +static bool modifiable_virtqueue_fields(struct mlx5_vdpa_virtqueue *mvq) +{ + /* Only state is always modifiable */ + if (mvq->modified_fields & ~MLX5_VIRTQ_MODIFY_MASK_STATE) + return mvq->fw_state == MLX5_VIRTIO_NET_Q_OBJECT_STATE_INIT || + mvq->fw_state == MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND; + + return true; +} + +static int modify_virtqueue(struct mlx5_vdpa_net *ndev, + struct mlx5_vdpa_virtqueue *mvq, + int state) { int inlen = MLX5_ST_SZ_BYTES(modify_virtio_net_q_in); u32 out[MLX5_ST_SZ_DW(modify_virtio_net_q_out)] = {}; @@ -1193,6 +1208,9 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtque if (mvq->fw_state == MLX5_VIRTIO_NET_Q_OBJECT_NONE) return 0; + if (!modifiable_virtqueue_fields(mvq)) + return -EINVAL; + if (!is_valid_state_change(mvq->fw_state, state)) return -EINVAL; @@ -1208,17 +1226,28 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtque MLX5_SET(general_obj_in_cmd_hdr, cmd_hdr, uid, ndev->mvdev.res.uid); obj_context = MLX5_ADDR_OF(modify_virtio_net_q_in, in, obj_context); - MLX5_SET64(virtio_net_q_object, obj_context, modify_field_select, - MLX5_VIRTQ_MODIFY_MASK_STATE); - MLX5_SET(virtio_net_q_object, obj_context, state, state); + if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_STATE) + MLX5_SET(virtio_net_q_object, obj_context, state, state); + + MLX5_SET64(virtio_net_q_object, obj_context, modify_field_select, mvq->modified_fields); err = mlx5_cmd_exec(ndev->mvdev.mdev, in, inlen, out, sizeof(out)); kfree(in); if (!err) mvq->fw_state = state; + mvq->modified_fields = 0; + return err; } +static int modify_virtqueue_state(struct mlx5_vdpa_net *ndev, + struct mlx5_vdpa_virtqueue *mvq, + unsigned int state) +{ + mvq->modified_fields |= MLX5_VIRTQ_MODIFY_MASK_STATE; + return modify_virtqueue(ndev, mvq, state); +} + static int counter_set_alloc(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) { u32 in[MLX5_ST_SZ_DW(create_virtio_q_counters_in)] = {}; @@ -1347,7 +1376,7 @@ static int setup_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) goto err_vq; if (mvq->ready) { - err = modify_virtqueue(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY); + err = modify_virtqueue_state(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY); if (err) { mlx5_vdpa_warn(&ndev->mvdev, "failed to modify to ready vq idx %d(%d)\n", idx, err); @@ -1382,7 +1411,7 @@ static void suspend_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *m if (mvq->fw_state != MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY) return; - if (modify_virtqueue(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND)) + if (modify_virtqueue_state(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND)) mlx5_vdpa_warn(&ndev->mvdev, "modify to suspend failed\n"); if (query_virtqueue(ndev, mvq, &attr)) { @@ -1407,6 +1436,7 @@ static void teardown_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue * return; suspend_vq(ndev, mvq); + mvq->modified_fields = 0; destroy_virtqueue(ndev, mvq); dealloc_vector(ndev, mvq); counter_set_dealloc(ndev, mvq); @@ -2207,7 +2237,7 @@ static void mlx5_vdpa_set_vq_ready(struct vdpa_device *vdev, u16 idx, bool ready if (!ready) { suspend_vq(ndev, mvq); } else { - err = modify_virtqueue(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY); + err = modify_virtqueue_state(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY); if (err) { mlx5_vdpa_warn(mvdev, "modify VQ %d to ready failed (%d)\n", idx, err); ready = false; @@ -2804,8 +2834,10 @@ static void clear_vqs_ready(struct mlx5_vdpa_net *ndev) { int i; - for (i = 0; i < ndev->mvdev.max_vqs; i++) + for (i = 0; i < ndev->mvdev.max_vqs; i++) { ndev->vqs[i].ready = false; + ndev->vqs[i].modified_fields = 0; + } ndev->mvdev.cvq.ready = false; } From patchwork Fri Dec 15 14:01:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13494512 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2052.outbound.protection.outlook.com [40.107.92.52]) (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 DA68135884; Fri, 15 Dec 2023 14:02:26 +0000 (UTC) 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="It42GM0c" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fknp4VgVobpX36TRR63RGj/cgRDBrMDBM8fA7eqmjHtDIBIGkPQ9w+liG0LYrjM70AKmsYHAh4Q7FnuQpizgWtCwOEu9jXd6e4RHtg5ZJg1OeGfj3i9AaotFUKLlwTdZ6nCkq8X+pA7lXEXBpBCvjqU8Eyf9NBns275YrkZfcxnv3avggRJZy5XC6BCDADOlvtUO2wU4wFCE5AfK+l6qK0DuNBec2dQKgeoCefpDuO5xBXHzxXz3QJsY+RsfttqmvCRM6dlovf6Es0HooULUUMlZnNf38QgPqOG+/l6FpgKAIApg1zb3OUadFZ0EQqXHXb8es8RsHrfmPVVFt9PY9A== 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=pWpOeWI+R1cb4FK6LjTB81MteAujPvP3wVhkPCOcOb0=; b=K5nO+3dIfD74pDv0iPRfPKNsP0bRqGC+wEkocce0lbUJNFT0Q2qzvS4MBjemEu3Iw6lZE9Yir7vzRgvhHQohvg/bmAM2PoQ5hqOw6+ZVqE7tViD21NGra92xI190q/7PNFrRz5RLW6M3VxeFLbppe6lDYz2gHp5lvHEMR4SDeARvJS/XhygZ9qYfZob0HA119vf6lXKVQ335gXfP1UrE+dCr9tz2hNUWX5FDlBGFwV3X8Ift27OQkZ3hQweBxs2J3PKXeWIkk8LJNKZ74846Hc1w9uTb+1qxBzl3GBcoLWvLAFPVUpmY4ZHzHrgOJO0DpGQ58wRZLQkuJULn2lf2Hg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=pWpOeWI+R1cb4FK6LjTB81MteAujPvP3wVhkPCOcOb0=; b=It42GM0cf80XSmMezeVXbsJIYeFfKTV5PBP50+wUlrES8SdH5KPRfWG6rymgEhsFjWR9+MMMMBHmnk86kSl+B7SsZnCsKqCPDE1WF5m5rVVBgOvePSmJaNnKLfEz9tsDPV/LHHVPO4V+cEeCuXs5eXfbFpRYV/82bhSZwxxqVWH4yPcaaUxuIN1+sBsNvNiivl9hBKRWpY0Fq25/koWgZLNbXpwS7XvuDXYh2sOPieGa/Ql4XOypAKZ+4b+l3eVPFAulCEntL9jJ9yKyO2Mld4eUs8/Ebam8L5RpCQpl9dohq02MvTbv81zzHuCjtKkFkS889BENPxwzR8Z1bIAHCg== Received: from MW4PR03CA0281.namprd03.prod.outlook.com (2603:10b6:303:b5::16) by IA0PR12MB7601.namprd12.prod.outlook.com (2603:10b6:208:43b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.28; Fri, 15 Dec 2023 14:02:21 +0000 Received: from CO1PEPF000044FC.namprd21.prod.outlook.com (2603:10b6:303:b5:cafe::e7) by MW4PR03CA0281.outlook.office365.com (2603:10b6:303:b5::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31 via Frontend Transport; Fri, 15 Dec 2023 14:02:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1PEPF000044FC.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.7 via Frontend Transport; Fri, 15 Dec 2023 14:02:20 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:02:06 -0800 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:02:06 -0800 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Fri, 15 Dec 2023 06:02:03 -0800 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , Gal Pressman CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo Subject: [PATCH vhost v3 3/6] vdpa/mlx5: Introduce per vq and device resume Date: Fri, 15 Dec 2023 16:01:43 +0200 Message-ID: <20231215140146.95816-4-dtatulea@nvidia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215140146.95816-1-dtatulea@nvidia.com> References: <20231215140146.95816-1-dtatulea@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: CO1PEPF000044FC:EE_|IA0PR12MB7601:EE_ X-MS-Office365-Filtering-Correlation-Id: 170d9b8c-2690-40fc-e621-08dbfd76749c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KvDpnAfGQhiEbdkNYI67O/SNlKc42Lwipc3mQBRLdW5q2kWsPmBmCck2v1K+9E0oJwmLqyDhf8JcHGvbD5f+hS/Pxe1dsWjT6MdEDvs1RhySKTOctHSxVpRN689wrWnOmo/A1V8Zho4F4OJS8AlQgFW9AHst1MWytlPZNLJvuLbIT0zKuq4+i1kmx2t3RyJlGiMmWtAH1sr04JDZcAd76Vdv09Awj3tqBjC0SxOTGdP7x3cbfpBqC4pp6b1mEfkL2i5ZtTVAxTmanShsQ1FKzIWWsDJ5lq7EEADdsSmXOl8qOIPyLlrrsM/aGnOdXBNmt4uUXjHvB7CzS0d/F3LocsaxfM9Z8QQDtbaxN2Tg6UioSIJFzaO+LrDH2uER1GYOBpU3aejf0YzHpo+Du8TNIYkpFsOmJ2ohDZojXr4U4vQT90LX62nWawiIQw1uDkZcTbRNvKCiNfaLBCWkn1YVjw2PGwlFsIAm/CZmGhxolFV04Z/WfXQfu5Y0JRkGveq73ZnJogqgd6qSsqaj8WJh4faXUar/46ecVFV9wyGQO74aDmIYgajz6fl9Y0t3B7WkBYNhp183+qkAnF0DA8idmYuQhoFuZb6RUP/abtPZP9ApZYL/X7cTRHt4pPacvHST8Y/j5W6dg5mLgj6V9CHL5U1BDuaFJa+B9xZSi4cHVppUiwciKqwQ7/JrE3nWFtZzst3LvqFoKrSwFdfrjBWrI6rxebUZS8WzUJV9n4CbAx1RTJltt+zEWwo0Jp7kh5N9 X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(396003)(136003)(376002)(39860400002)(346002)(230922051799003)(451199024)(64100799003)(1800799012)(186009)(82310400011)(40470700004)(46966006)(36840700001)(47076005)(8676002)(8936002)(4326008)(83380400001)(40460700003)(54906003)(6636002)(316002)(36756003)(356005)(7636003)(41300700001)(82740400003)(2906002)(86362001)(26005)(5660300002)(70206006)(40480700001)(1076003)(2616005)(478600001)(36860700001)(6666004)(336012)(426003)(66574015)(110136005)(70586007);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 14:02:20.6527 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 170d9b8c-2690-40fc-e621-08dbfd76749c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044FC.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7601 Implement vdpa vq and device resume if capability detected. Add support for suspend -> ready state change. Reviewed-by: Gal Pressman Acked-by: Eugenio Pérez Signed-off-by: Dragos Tatulea --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 69 +++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 1e08a8805640..f8f088cced50 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1170,7 +1170,12 @@ static int query_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueu return err; } -static bool is_valid_state_change(int oldstate, int newstate) +static bool is_resumable(struct mlx5_vdpa_net *ndev) +{ + return ndev->mvdev.vdev.config->resume; +} + +static bool is_valid_state_change(int oldstate, int newstate, bool resumable) { switch (oldstate) { case MLX5_VIRTIO_NET_Q_OBJECT_STATE_INIT: @@ -1178,6 +1183,7 @@ static bool is_valid_state_change(int oldstate, int newstate) case MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY: return newstate == MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND; case MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND: + return resumable ? newstate == MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY : false; case MLX5_VIRTIO_NET_Q_OBJECT_STATE_ERR: default: return false; @@ -1200,6 +1206,7 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, { int inlen = MLX5_ST_SZ_BYTES(modify_virtio_net_q_in); u32 out[MLX5_ST_SZ_DW(modify_virtio_net_q_out)] = {}; + bool state_change = false; void *obj_context; void *cmd_hdr; void *in; @@ -1211,9 +1218,6 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, if (!modifiable_virtqueue_fields(mvq)) return -EINVAL; - if (!is_valid_state_change(mvq->fw_state, state)) - return -EINVAL; - in = kzalloc(inlen, GFP_KERNEL); if (!in) return -ENOMEM; @@ -1226,17 +1230,29 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, MLX5_SET(general_obj_in_cmd_hdr, cmd_hdr, uid, ndev->mvdev.res.uid); obj_context = MLX5_ADDR_OF(modify_virtio_net_q_in, in, obj_context); - if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_STATE) + + if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_STATE) { + if (!is_valid_state_change(mvq->fw_state, state, is_resumable(ndev))) { + err = -EINVAL; + goto done; + } + MLX5_SET(virtio_net_q_object, obj_context, state, state); + state_change = true; + } MLX5_SET64(virtio_net_q_object, obj_context, modify_field_select, mvq->modified_fields); err = mlx5_cmd_exec(ndev->mvdev.mdev, in, inlen, out, sizeof(out)); - kfree(in); - if (!err) + if (err) + goto done; + + if (state_change) mvq->fw_state = state; mvq->modified_fields = 0; +done: + kfree(in); return err; } @@ -1430,6 +1446,24 @@ static void suspend_vqs(struct mlx5_vdpa_net *ndev) suspend_vq(ndev, &ndev->vqs[i]); } +static void resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) +{ + if (!mvq->initialized || !is_resumable(ndev)) + return; + + if (mvq->fw_state != MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND) + return; + + if (modify_virtqueue_state(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY)) + mlx5_vdpa_warn(&ndev->mvdev, "modify to resume failed for vq %u\n", mvq->index); +} + +static void resume_vqs(struct mlx5_vdpa_net *ndev) +{ + for (int i = 0; i < ndev->mvdev.max_vqs; i++) + resume_vq(ndev, &ndev->vqs[i]); +} + static void teardown_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) { if (!mvq->initialized) @@ -3261,6 +3295,23 @@ static int mlx5_vdpa_suspend(struct vdpa_device *vdev) return 0; } +static int mlx5_vdpa_resume(struct vdpa_device *vdev) +{ + struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); + struct mlx5_vdpa_net *ndev; + + ndev = to_mlx5_vdpa_ndev(mvdev); + + mlx5_vdpa_info(mvdev, "resuming device\n"); + + down_write(&ndev->reslock); + mvdev->suspended = false; + resume_vqs(ndev); + register_link_notifier(ndev); + up_write(&ndev->reslock); + return 0; +} + static int mlx5_set_group_asid(struct vdpa_device *vdev, u32 group, unsigned int asid) { @@ -3317,6 +3368,7 @@ static const struct vdpa_config_ops mlx5_vdpa_ops = { .get_vq_dma_dev = mlx5_get_vq_dma_dev, .free = mlx5_vdpa_free, .suspend = mlx5_vdpa_suspend, + .resume = mlx5_vdpa_resume, /* Op disabled if not supported. */ }; static int query_mtu(struct mlx5_core_dev *mdev, u16 *mtu) @@ -3688,6 +3740,9 @@ static int mlx5v_probe(struct auxiliary_device *adev, if (!MLX5_CAP_DEV_VDPA_EMULATION(mdev, desc_group_mkey_supported)) mgtdev->vdpa_ops.get_vq_desc_group = NULL; + if (!MLX5_CAP_DEV_VDPA_EMULATION(mdev, freeze_to_rdy_supported)) + mgtdev->vdpa_ops.resume = NULL; + err = vdpa_mgmtdev_register(&mgtdev->mgtdev); if (err) goto reg_err; From patchwork Fri Dec 15 14:01:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13494514 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2051.outbound.protection.outlook.com [40.107.237.51]) (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 6AA7635F03; Fri, 15 Dec 2023 14:02:30 +0000 (UTC) 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="m8ST4cMn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VI+Pgvg9qJkKn3MyUdEoP2dv8Rn8GQfnbR1RvUG0DBO8s5wAODQ3r17foqxM6LJSu9sPyJm6wkAukhwRXe8O8pOHZ6KTT7GmSDG9Ts5jp2nRQs98fzRSqacbtPSLXU32k0Cfa0oinMuXAy466Gbh0fnraTG+Chv58gN+070faKqcS+g1yt9KXsjVyrtXm+uEbveteMecxiaTGihz42MPnKZT/GKTbJtpPovsKMqcLXZnEb+V6ssZjXoUt6M4n1YU+TvNRqvNn1GNFVMEQ/xBWqRNvQxuNEolEPcZxc73Wft/WWbA4uo00AMvsgGe6V7PTUgubhLOkHTHxDK0jsZadw== 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=z/RPprGigKEvLPsDUA9HGlOzP1Vcg6FVBTRieXdpHO8=; b=T2//tTucw+6LDsnlmrvlzWSmizPhiUBGAmLp7A3+F56tZi+qSmQqQKZ8m4foHMMWIFJ29qGczaxtPjhgB+/m2CIuvFkXT5y3t7vDp2u7kPnB1BXuUlpRE92/QkqgEyyrPO5FzP8+ZoUnZJAv2cEidaLnjUN72GVRTqlVAqkCIKW64LyD9rhPuT+gDzsptp1Q5WH8Zswgv9rnpIRoRmEK/N9s+/Ir2sJMS25sqIUl7FJmZFQSEwq2QuKhy8UvFBYgtXk/7eMDuz9er4WQl0KplJD/Kml/t3kSSMu8AyjC5pMhHOhbL6RJMf8iQGyxO5agAnmk9vNvRPU+gPyaQse9Mg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=z/RPprGigKEvLPsDUA9HGlOzP1Vcg6FVBTRieXdpHO8=; b=m8ST4cMn4x8prFHVPoTk18G5KweOnXDqo4fsRMSaqRcuS9Zi7apLkOyXj2vewerg9pmQRayfaqtVf5eJIMg/Mk1v9IFw31oF3UR5jvBUFgkLZxL1Jr4R/rCWEnKWQdCrm5srHTttEOmo2nhWY8V9GXCARJ35XZFHU0+AC509dAcjB+Ey+WNvJSzGPYF+qj82DiLs5P8wFS7uMrurEcxfhz5D8U3Pv8jenXxntBWxK5dC8gUEnHBY6ycL1ZvLv1PktXcUGyGWI+b3brCiRB9yTTpXlUTtFJQYFU1kntGL6ZGZtVot61LDdiUTgJLI1aSPR7erx8mXuVP1nYUIWrSYAw== Received: from MW4PR03CA0070.namprd03.prod.outlook.com (2603:10b6:303:b6::15) by SN7PR12MB8820.namprd12.prod.outlook.com (2603:10b6:806:341::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.28; Fri, 15 Dec 2023 14:02:24 +0000 Received: from CO1PEPF000044F6.namprd21.prod.outlook.com (2603:10b6:303:b6:cafe::83) by MW4PR03CA0070.outlook.office365.com (2603:10b6:303:b6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.32 via Frontend Transport; Fri, 15 Dec 2023 14:02:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1PEPF000044F6.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.7 via Frontend Transport; Fri, 15 Dec 2023 14:02:23 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:02:10 -0800 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:02:10 -0800 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Fri, 15 Dec 2023 06:02:07 -0800 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , Gal Pressman CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo Subject: [PATCH vhost v3 4/6] vdpa/mlx5: Use vq suspend/resume during .set_map Date: Fri, 15 Dec 2023 16:01:44 +0200 Message-ID: <20231215140146.95816-5-dtatulea@nvidia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215140146.95816-1-dtatulea@nvidia.com> References: <20231215140146.95816-1-dtatulea@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: CO1PEPF000044F6:EE_|SN7PR12MB8820:EE_ X-MS-Office365-Filtering-Correlation-Id: 39065171-2217-4f62-447f-08dbfd767688 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Mb2mkI4izN1DK8fidftjXkpzL9mcbJUEdUF8jdbWes1J1EN2J2bAG7vYFbZcAqX70nL/9xrP/MAn7hwul/5NE2eWdT+Swl0fBy45mo1+WcFMDrU5AcBPJPH7ZRoCg7sFLlwHhQJuQ+6F15p80suv4v4Rt4EN+fV+wCpol4El6YIYU96sFkh+QRyU+znODBd0wuiJVjbxNScE69rEdQ4YTcMHZ4iWNztBzUoMDEvqw4xRcSRGQf0NE8kqkOmlNWzOvnSxSOiiOuUY3r2XRiWNQmbnU+RdPw5ttOjyZDy/8LF9QMBeG7A2SRTDiH5pQSx5EA8Hgm0/ZN05XqY3YH4kzSOsJAogvApvwff8kieUzbggzvfUovMxlTN4X7SFmT083mfFtGiYCDhHtRMALvUnBCnumbr24Ue064DB7wKe/wV4OiunJ2OBIiTvQqljGdAfYjnMgK58CRij2oVwQzZswmdXDNIrvIwFY9BrALfpeD+klr/C8GPRR57Ouz2w7tcryTQu2Dvc1qubHqhX9+IES0eun5w038X0E//ZDR2ubCl6F/8CwFXrFYp9cdGSMfZhlrgsZ3Hgx7Osj77PS3+iQpTrFzbgHiJySFXkPfKGoJ0v4nXhTiSPCoypyaSNYX3QO20tDBsaCHKT26pVtc0envxN++iNrRlqdY8BtcznSPDnNlLVp//D1tCF1BHu1TRtTHBtY8FKt5fqlsEqRCk3gvdzCStWaovJsDOGdQ/6JYwQbIc38DmFhIwKLfCXtEW1Lic0AOkjeu1++bQJD5ShFw== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(396003)(376002)(346002)(136003)(39860400002)(230922051799003)(82310400011)(451199024)(1800799012)(64100799003)(186009)(36840700001)(46966006)(40470700004)(40460700003)(2616005)(1076003)(426003)(26005)(336012)(6666004)(83380400001)(15650500001)(36860700001)(47076005)(5660300002)(6636002)(4326008)(8676002)(8936002)(54906003)(41300700001)(2906002)(478600001)(316002)(110136005)(70586007)(70206006)(82740400003)(86362001)(36756003)(356005)(7636003)(66574015)(40480700001)(142923001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 14:02:23.8729 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 39065171-2217-4f62-447f-08dbfd767688 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044F6.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8820 Instead of tearing down and setting up vq resources, use vq suspend/resume during .set_map to speed things up a bit. The vq mr is updated with the new mapping while the vqs are suspended. If the device doesn't support resumable vqs, do the old teardown and setup dance. Reviewed-by: Gal Pressman Acked-by: Eugenio Pérez Signed-off-by: Dragos Tatulea --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 48 +++++++++++++++++++++++++----- include/linux/mlx5/mlx5_ifc_vdpa.h | 1 + 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index f8f088cced50..d5883c554333 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1206,9 +1206,11 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, { int inlen = MLX5_ST_SZ_BYTES(modify_virtio_net_q_in); u32 out[MLX5_ST_SZ_DW(modify_virtio_net_q_out)] = {}; + struct mlx5_vdpa_dev *mvdev = &ndev->mvdev; bool state_change = false; void *obj_context; void *cmd_hdr; + void *vq_ctx; void *in; int err; @@ -1230,6 +1232,7 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, MLX5_SET(general_obj_in_cmd_hdr, cmd_hdr, uid, ndev->mvdev.res.uid); obj_context = MLX5_ADDR_OF(modify_virtio_net_q_in, in, obj_context); + vq_ctx = MLX5_ADDR_OF(virtio_net_q_object, obj_context, virtio_q_context); if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_STATE) { if (!is_valid_state_change(mvq->fw_state, state, is_resumable(ndev))) { @@ -1241,6 +1244,24 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, state_change = true; } + if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY) { + struct mlx5_vdpa_mr *mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]]; + + if (mr) + MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, mr->mkey); + else + mvq->modified_fields &= ~MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY; + } + + if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY) { + struct mlx5_vdpa_mr *mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]]; + + if (mr && MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, desc_group_mkey_supported)) + MLX5_SET(virtio_q, vq_ctx, desc_group_mkey, mr->mkey); + else + mvq->modified_fields &= ~MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY; + } + MLX5_SET64(virtio_net_q_object, obj_context, modify_field_select, mvq->modified_fields); err = mlx5_cmd_exec(ndev->mvdev.mdev, in, inlen, out, sizeof(out)); if (err) @@ -2767,24 +2788,35 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev, unsigned int asid) { struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); + bool teardown = !is_resumable(ndev); int err; suspend_vqs(ndev); - err = save_channels_info(ndev); - if (err) - return err; + if (teardown) { + err = save_channels_info(ndev); + if (err) + return err; - teardown_driver(ndev); + teardown_driver(ndev); + } mlx5_vdpa_update_mr(mvdev, new_mr, asid); + for (int i = 0; i < ndev->cur_num_vqs; i++) + ndev->vqs[i].modified_fields |= MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY | + MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY; + if (!(mvdev->status & VIRTIO_CONFIG_S_DRIVER_OK) || mvdev->suspended) return 0; - restore_channels_info(ndev); - err = setup_driver(mvdev); - if (err) - return err; + if (teardown) { + restore_channels_info(ndev); + err = setup_driver(mvdev); + if (err) + return err; + } + + resume_vqs(ndev); return 0; } diff --git a/include/linux/mlx5/mlx5_ifc_vdpa.h b/include/linux/mlx5/mlx5_ifc_vdpa.h index b86d51a855f6..8cbc2592d0f1 100644 --- a/include/linux/mlx5/mlx5_ifc_vdpa.h +++ b/include/linux/mlx5/mlx5_ifc_vdpa.h @@ -145,6 +145,7 @@ enum { MLX5_VIRTQ_MODIFY_MASK_STATE = (u64)1 << 0, MLX5_VIRTQ_MODIFY_MASK_DIRTY_BITMAP_PARAMS = (u64)1 << 3, MLX5_VIRTQ_MODIFY_MASK_DIRTY_BITMAP_DUMP_ENABLE = (u64)1 << 4, + MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY = (u64)1 << 11, MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY = (u64)1 << 14, }; From patchwork Fri Dec 15 14:01:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13494513 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2040.outbound.protection.outlook.com [40.107.220.40]) (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 D229F358B4; Fri, 15 Dec 2023 14:02:28 +0000 (UTC) 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="G2YiH9LO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LePkPbGBgnf1hc/g4K4R2D1I3N+KK50BBAnyRRx2uMNxpDBpTmWdJceYhvrODqlszF+93RqJzeoXXdKph2ErN7gb7dnwZbQmwPS30342Q0Mga2FFDhpNnHgW2+M0sSQEQi5P6u54nlbszPO4FwE+D53uRhpMZbUGuWfFI/eCTd396v6chEyPPn7K4sCS9cSTcRwYpERWz5gvm40QyVuhYZlH2crbnzTHrxGUGOMijjOZxPEi+FgN+RQI36mys66lp9mGT6T+w/vARQNMpDRiZQbnYpKFWID0Y/3qZlntLhsfp5F6Mpc27NUi4waIyymUxTZ0SMa/1u+ykP4F5JeOIg== 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=Imd95NVOb0WyUcAorgggfZuy+9KsIAF5FVX6Zde8bIQ=; b=ix7TYj1Q5qPv4z5IvkOTPy2liWDVUPxSRUUqUw/LJiK+i8zv0k8DRvDrl2SrUybwdQ/KDe48TKVPc97PImOmDlpeOqOGdaIjeHrYkktu2HiNWvc4jGCqYzbZWbkwEKjFQWVmdeEgNE36HB1dcTQpqOie2UaU8Bjg5WJQP87rAFlLKRMq7H+2Wd2nzl+sOKzeBq9P89byONck+Z7zNrKlsCEqCSqBIWiAq7cT+JdAmD2/o7cZXJaCNTNs4QLWRw5KryJg6xviXH3+HQCjg/4JBwKoPFPmjitI/CkjUQP+qZgBHo5h7o4UFovkJvciV+/juS9MW8unZvrhyvufFI4Ksw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.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=Imd95NVOb0WyUcAorgggfZuy+9KsIAF5FVX6Zde8bIQ=; b=G2YiH9LOYieZUwJ4tkjvbrwjyuxMq3BqNKBw874R4ppMgmviTtNCTYBhHsTtBdco233wE0tDhNMoM/c6suNOAmfwN/ccWfldtk2vg5B2OYHf7eFnmqDgB+N+Vv8ptfkZ1Jc7F+u0yA/23yVka9xaah0dZtN9gm91bov4CTSoGIfLV4jTMfgL4M+rYWhiY0qSTAr4iu9YL6/5PPL3Pr0DnANKUOsRIg9YZyWT3res7ymSuWygTqhiRBarfrdkaUgOO52y8/bYoySpARvD5ITmtBhDu4kWZNaqN5M4IZbuGplHsIzORuO20IJe6Shn575dG7YHI5O5MTT0lmC2TA4I5w== Received: from MW4PR03CA0293.namprd03.prod.outlook.com (2603:10b6:303:b5::28) by MW6PR12MB8959.namprd12.prod.outlook.com (2603:10b6:303:23c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.28; Fri, 15 Dec 2023 14:02:26 +0000 Received: from CO1PEPF000044FC.namprd21.prod.outlook.com (2603:10b6:303:b5:cafe::2c) by MW4PR03CA0293.outlook.office365.com (2603:10b6:303:b5::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31 via Frontend Transport; Fri, 15 Dec 2023 14:02:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1PEPF000044FC.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.7 via Frontend Transport; Fri, 15 Dec 2023 14:02:26 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:02:14 -0800 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:02:13 -0800 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Fri, 15 Dec 2023 06:02:10 -0800 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , Gal Pressman CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo Subject: [PATCH vhost v3 5/6] vdpa/mlx5: Introduce reference counting to mrs Date: Fri, 15 Dec 2023 16:01:45 +0200 Message-ID: <20231215140146.95816-6-dtatulea@nvidia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215140146.95816-1-dtatulea@nvidia.com> References: <20231215140146.95816-1-dtatulea@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: CO1PEPF000044FC:EE_|MW6PR12MB8959:EE_ X-MS-Office365-Filtering-Correlation-Id: 20d4cfb8-d4d7-4d1c-6e26-08dbfd7677f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oqKdiIp7bM9XMZ7A50kq5OgH57HHZgkY/Js5uZtBF5nzoY83GTgouSxokCYWEcAf4pfQLGfjmsUT/G7RM9s/M2vxT7RvwP5NuhWiUU9Gf4nR1GNpNVwjEUAwvKYCOZDiXqqs8cqXjgh+Vt+Lp/woqg1Q2Qbq8cmS7UU8ZDJoZI7QG2mtxvJPJ7DuOg6kfdragAkRugS4N2ap3EW+NhMEniSgAlJ9OKWT9vSVLKoDJOXde9d/Fqq+pbvA/wwPtVr4OfKvgzvpRaG9Nib6f9ehTERzIbuwuoAepTFH71fgURz56J2HWPY9vbLPCT7dk1n60E9RQA4jT99JpZM66KQqmjymw4l6SiwWPpV7Bkifsarv5UEHEck5k0rXR7h7r5Nee622wCZxeNkVaI5too0U1DHA98dLXQXTL4O8J1zJbZNqeDij/KhI9o+4FIBL8UYwkQfmIg/Yrjb/0pB3XtqkSPhdVvLnSZtv6w0fvWoY//KzM+WN/ihX5qsIqDQkiV+sS49/lkcf9OdVRA6WOqYIlHmCh1Md1eca1ZAxDuOAsBH4cIOLdcRlBchL89PS9TTCLn6yZthy8jksqSOWCIgSCQ/jbBo4av60VrIrdg36aaTOLfQOylV2z76ZQj+Ul+ps6J1OM8DfU9vnhcFbkEN3uau3MrW1MzzeeBo5DfOIatLq6Jy1MV56ATgtoV7ryQzMA/1TtJWZSbcHdG+L98vNfhavs9+agJCoGJy0FXaCXhUjG856uK49/wtAnSNTbKp2 X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(396003)(376002)(39860400002)(346002)(136003)(230922051799003)(64100799003)(1800799012)(82310400011)(451199024)(186009)(40470700004)(46966006)(36840700001)(5660300002)(2616005)(1076003)(26005)(47076005)(336012)(426003)(66574015)(36860700001)(83380400001)(2906002)(478600001)(316002)(54906003)(6636002)(36756003)(110136005)(41300700001)(70206006)(70586007)(4326008)(8676002)(8936002)(6666004)(40460700003)(40480700001)(82740400003)(86362001)(356005)(7636003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 14:02:26.2464 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 20d4cfb8-d4d7-4d1c-6e26-08dbfd7677f2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044FC.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8959 Deleting the old mr during mr update (.set_map) and then modifying the vqs with the new mr is not a good flow for firmware. The firmware expects that mkeys are deleted after there are no more vqs referencing them. Introduce reference counting for mrs to fix this. It is the only way to make sure that mkeys are not in use by vqs. An mr reference is taken when the mr is associated to the mr asid table and when the mr is linked to the vq on create/modify. The reference is released when the mkey is unlinked from the vq (trough modify/destroy) and from the mr asid table. To make things consistent, get rid of mlx5_vdpa_destroy_mr and use get/put semantics everywhere. Reviewed-by: Gal Pressman Acked-by: Eugenio Pérez Signed-off-by: Dragos Tatulea --- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 8 +++-- drivers/vdpa/mlx5/core/mr.c | 50 ++++++++++++++++++++---------- drivers/vdpa/mlx5/net/mlx5_vnet.c | 45 ++++++++++++++++++++++----- 3 files changed, 78 insertions(+), 25 deletions(-) diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h index 84547d998bcf..1a0d27b6e09a 100644 --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h @@ -35,6 +35,8 @@ struct mlx5_vdpa_mr { struct vhost_iotlb *iotlb; bool user_mr; + + refcount_t refcount; }; struct mlx5_vdpa_resources { @@ -118,8 +120,10 @@ int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey); struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb); void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev); -void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, - struct mlx5_vdpa_mr *mr); +void mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_mr *mr); +void mlx5_vdpa_put_mr(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_mr *mr); void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr, unsigned int asid); diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index 2197c46e563a..c7dc8914354a 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -498,32 +498,52 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr static void _mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) { + if (WARN_ON(!mr)) + return; + if (mr->user_mr) destroy_user_mr(mvdev, mr); else destroy_dma_mr(mvdev, mr); vhost_iotlb_free(mr->iotlb); + + kfree(mr); } -void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, - struct mlx5_vdpa_mr *mr) +static void _mlx5_vdpa_put_mr(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_mr *mr) { if (!mr) return; + if (refcount_dec_and_test(&mr->refcount)) + _mlx5_vdpa_destroy_mr(mvdev, mr); +} + +void mlx5_vdpa_put_mr(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_mr *mr) +{ mutex_lock(&mvdev->mr_mtx); + _mlx5_vdpa_put_mr(mvdev, mr); + mutex_unlock(&mvdev->mr_mtx); +} - _mlx5_vdpa_destroy_mr(mvdev, mr); +static void _mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_mr *mr) +{ + if (!mr) + return; - for (int i = 0; i < MLX5_VDPA_NUM_AS; i++) { - if (mvdev->mr[i] == mr) - mvdev->mr[i] = NULL; - } + refcount_inc(&mr->refcount); +} +void mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_mr *mr) +{ + mutex_lock(&mvdev->mr_mtx); + _mlx5_vdpa_get_mr(mvdev, mr); mutex_unlock(&mvdev->mr_mtx); - - kfree(mr); } void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev, @@ -534,20 +554,16 @@ void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev, mutex_lock(&mvdev->mr_mtx); + _mlx5_vdpa_put_mr(mvdev, old_mr); mvdev->mr[asid] = new_mr; - if (old_mr) { - _mlx5_vdpa_destroy_mr(mvdev, old_mr); - kfree(old_mr); - } mutex_unlock(&mvdev->mr_mtx); - } void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev) { for (int i = 0; i < MLX5_VDPA_NUM_AS; i++) - mlx5_vdpa_destroy_mr(mvdev, mvdev->mr[i]); + mlx5_vdpa_update_mr(mvdev, NULL, i); prune_iotlb(mvdev->cvq.iotlb); } @@ -607,6 +623,8 @@ struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, if (err) goto out_err; + refcount_set(&mr->refcount, 1); + return mr; out_err: @@ -651,7 +669,7 @@ int mlx5_vdpa_reset_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid) if (asid >= MLX5_VDPA_NUM_AS) return -EINVAL; - mlx5_vdpa_destroy_mr(mvdev, mvdev->mr[asid]); + mlx5_vdpa_update_mr(mvdev, NULL, asid); if (asid == 0 && MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { if (mlx5_vdpa_create_dma_mr(mvdev)) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index d5883c554333..0df82e4d13f4 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -123,6 +123,9 @@ struct mlx5_vdpa_virtqueue { u64 modified_fields; + struct mlx5_vdpa_mr *vq_mr; + struct mlx5_vdpa_mr *desc_mr; + struct msi_map map; /* keep last in the struct */ @@ -946,6 +949,14 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtque kfree(in); mvq->virtq_id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id); + mlx5_vdpa_get_mr(mvdev, vq_mr); + mvq->vq_mr = vq_mr; + + if (vq_desc_mr && MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, desc_group_mkey_supported)) { + mlx5_vdpa_get_mr(mvdev, vq_desc_mr); + mvq->desc_mr = vq_desc_mr; + } + return 0; err_cmd: @@ -972,6 +983,12 @@ static void destroy_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtq } mvq->fw_state = MLX5_VIRTIO_NET_Q_OBJECT_NONE; umems_destroy(ndev, mvq); + + mlx5_vdpa_put_mr(&ndev->mvdev, mvq->vq_mr); + mvq->vq_mr = NULL; + + mlx5_vdpa_put_mr(&ndev->mvdev, mvq->desc_mr); + mvq->desc_mr = NULL; } static u32 get_rqpn(struct mlx5_vdpa_virtqueue *mvq, bool fw) @@ -1207,6 +1224,8 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, int inlen = MLX5_ST_SZ_BYTES(modify_virtio_net_q_in); u32 out[MLX5_ST_SZ_DW(modify_virtio_net_q_out)] = {}; struct mlx5_vdpa_dev *mvdev = &ndev->mvdev; + struct mlx5_vdpa_mr *desc_mr = NULL; + struct mlx5_vdpa_mr *vq_mr = NULL; bool state_change = false; void *obj_context; void *cmd_hdr; @@ -1245,19 +1264,19 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, } if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY) { - struct mlx5_vdpa_mr *mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]]; + vq_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]]; - if (mr) - MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, mr->mkey); + if (vq_mr) + MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, vq_mr->mkey); else mvq->modified_fields &= ~MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY; } if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY) { - struct mlx5_vdpa_mr *mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]]; + desc_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]]; - if (mr && MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, desc_group_mkey_supported)) - MLX5_SET(virtio_q, vq_ctx, desc_group_mkey, mr->mkey); + if (desc_mr && MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, desc_group_mkey_supported)) + MLX5_SET(virtio_q, vq_ctx, desc_group_mkey, desc_mr->mkey); else mvq->modified_fields &= ~MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY; } @@ -1270,6 +1289,18 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, if (state_change) mvq->fw_state = state; + if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY) { + mlx5_vdpa_put_mr(mvdev, mvq->vq_mr); + mlx5_vdpa_get_mr(mvdev, vq_mr); + mvq->vq_mr = vq_mr; + } + + if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY) { + mlx5_vdpa_put_mr(mvdev, mvq->desc_mr); + mlx5_vdpa_get_mr(mvdev, desc_mr); + mvq->desc_mr = desc_mr; + } + mvq->modified_fields = 0; done: @@ -3080,7 +3111,7 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, return mlx5_vdpa_update_cvq_iotlb(mvdev, iotlb, asid); out_err: - mlx5_vdpa_destroy_mr(mvdev, new_mr); + mlx5_vdpa_put_mr(mvdev, new_mr); return err; } From patchwork Fri Dec 15 14:01:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13494515 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2089.outbound.protection.outlook.com [40.107.100.89]) (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 874133EA83; Fri, 15 Dec 2023 14:02:40 +0000 (UTC) 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="dyN5JGxF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cXWzqydgXSDt5+tKH3xPvmTbeNiOIShCu2O7faypghniqc1tJryYFTGrzBkk2u1IHM6aA2Z9x00C8rdzI4wU4+oxP5887m6GicBovltkzvXjwkgBXqmdydA98i3YYyDlVacLSXWW8PP2qsm7ZjzizAi8lahLEUsHbdKz7HzgEzXUAkVY1cnBADLeBFjxMGDjRGeDb7hAca3GqZLEzNwTrOSQtL1HLeJ0FfTAtCHk52hNt4Qfuv7u3dJ7hz0PGuorLuEdy7G6DjgsvT/+2l77NrgC2ZN/QfCAJxQWeLQuTV3Gc9yPOhWWNZnynNxDbOEwd1446v2eNAC3ouscTbAVnQ== 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=nCkDUWSVBbPDHMGVxZ/kQ/O3FYpPFUjYdtgplbmD6Uo=; b=ngaN7Dq8f+PkYcj1S23p9Lo1R0LKPgc9ZtWS+PD0Ba7pyRJQkLbmMMVoSpTaeP+auH1YclmMwEPvqJ9EtG3e2jyykXOvpApa4JIMNE5+t0AFBSwKhM2FOwwTswtiOcKybOm26WmJUA/UkGJqdOE8s35DWM2U4eH6qwTltHTGodMsD0OKZb5EmLmeE+MU1NL/e7ptnABU5CcTEK9N9YCJ4GJJFBk6gQqZHvs79rPwR5CsjI+nrI+CmpCQzX7Fi4ibpaDWhFk3ESlv8a5UQVJJtfIAZy1HEoQLWSpmle1rRNCvsxLNIwQdvptC5SbYjwotbKDklfJDbwP6nK7C826s7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.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=nCkDUWSVBbPDHMGVxZ/kQ/O3FYpPFUjYdtgplbmD6Uo=; b=dyN5JGxFllxDknEvZzmMyoP70ap9DwRd/TAEWADJuNP0cNgRLB1Kd6XhvZWE9xW9Yy/tQei2X0p59IM1BLxY3+UeY4mdr9cuURV0x7MV3lejPB+AqYHW/8mrcVsJSlA2WrvijDS0gxX7WOoxOfyoyA731EqOQnUVwrn6a5kqa7LFX59KoXK5t3qZVjGzA6N1muCt0LMig8gNlpDQgFQGgwRAGEjNPOvRw3/I6BAHV1CD7xYZnGKGnoNLzA9ndvlIksVgKZNWkXmdTCI8EnGTp7ky/ilXOfQF+Y3K76t+dj8YtD2Pa4BCEkFVTu1hKBm7Qye7fszZHa/mlFo1ek7DZg== Received: from DM6PR11CA0007.namprd11.prod.outlook.com (2603:10b6:5:190::20) by SA0PR12MB4509.namprd12.prod.outlook.com (2603:10b6:806:9e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31; Fri, 15 Dec 2023 14:02:37 +0000 Received: from CY4PEPF0000EDD6.namprd03.prod.outlook.com (2603:10b6:5:190:cafe::6) by DM6PR11CA0007.outlook.office365.com (2603:10b6:5:190::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31 via Frontend Transport; Fri, 15 Dec 2023 14:02:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000EDD6.mail.protection.outlook.com (10.167.241.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.14 via Frontend Transport; Fri, 15 Dec 2023 14:02:36 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:02:17 -0800 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 15 Dec 2023 06:02:17 -0800 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Fri, 15 Dec 2023 06:02:14 -0800 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , Gal Pressman CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo Subject: [PATCH vhost v3 6/6] vdpa/mlx5: Add mkey leak detection Date: Fri, 15 Dec 2023 16:01:46 +0200 Message-ID: <20231215140146.95816-7-dtatulea@nvidia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215140146.95816-1-dtatulea@nvidia.com> References: <20231215140146.95816-1-dtatulea@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: CY4PEPF0000EDD6:EE_|SA0PR12MB4509:EE_ X-MS-Office365-Filtering-Correlation-Id: 26b1cacc-f9af-4db3-c419-08dbfd767e47 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dUbJnda7EaM6vJarQQp9MA0aAeVY4ql/JEBNq8PVkkpCKPMydK5Cdhkj6EnDmomIHprFCQc1tj1hOJDQHwHvGisTbFe9sfnM3Ajh01adtGCc+1FgiRyB5yy+/T/kHeQZi/OGtZ4gZYycXU1zHAMM6qj1bckrtgMFaQ5EcOqaKfoEMEBrthAGz47Q/q85AMxHssGfXmmPsqwefmcvipYzgX7FyfXFJeGaQN1/3Et/lQVp7CgEIgGCd1b0jw2dN6yCPhXybMe8S5R20HvEaj6NVIUbE9rT5vUnm8WciRMigioq9rRgEBG2s2r7N/WEC1LFgpZoAsFNzLMDO/6hTJZ8xwbJOUq1VCMbg+EabQ6OR20/kUDUZC9kGwmO53x9YfJ4HOKHpFnFgPrN25or2b+hq8s3tCIp/MaI/aeheqfCqYWVa/kMzZIjFgtYgG6WGiafquMlotxUMUf1IeHtujAoRZQLuQMTl599Hf34by/TdVAP8pNjZ3jTXi6mRA+M9PHhZLM3UZMI0glWHd5BPXi4TmUSf8+KHVCvuj7pgszObIHRIqeyyMFco0rYuL+1xQX6lokuoWot8+q2e8oiQK62Fhhd1ZIXJVowj4psQ1IjlLVP9jqc9HhDv22A7gTkzPXWIaH4zZR4rwevexvAoT0AP1cjToROtmxdeqQy/337iMnTd1tCseCBNAEJA7z+5uG822GRd2lGJ3kf85k12poooHVchSnVqiONTPrbXBlNgYKYajjMzqDa0jXFEn4KjOF+yjlEofiZzOG1yC8uTChdnM5EEiKc00OknWHR+e1igH3QdcbhH0+n2DzftfaFN9XffylscB5nWTawGbKxMNHAGw== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(396003)(376002)(346002)(136003)(230273577357003)(230173577357003)(230922051799003)(1800799012)(186009)(64100799003)(82310400011)(451199024)(46966006)(40470700004)(36840700001)(40480700001)(40460700003)(36860700001)(47076005)(356005)(82740400003)(2906002)(36756003)(5660300002)(83380400001)(336012)(6666004)(66574015)(426003)(7636003)(1076003)(26005)(2616005)(478600001)(54906003)(70206006)(70586007)(41300700001)(86362001)(110136005)(4326008)(8676002)(8936002)(6636002)(316002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 14:02:36.8251 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 26b1cacc-f9af-4db3-c419-08dbfd767e47 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4509 Track allocated mrs in a list and show warning when leaks are detected on device free or reset. Reviewed-by: Gal Pressman Acked-by: Eugenio Pérez Signed-off-by: Dragos Tatulea --- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 2 ++ drivers/vdpa/mlx5/core/mr.c | 23 +++++++++++++++++++++++ drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 ++ 3 files changed, 27 insertions(+) diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h index 1a0d27b6e09a..50aac8fe57ef 100644 --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h @@ -37,6 +37,7 @@ struct mlx5_vdpa_mr { bool user_mr; refcount_t refcount; + struct list_head mr_list; }; struct mlx5_vdpa_resources { @@ -95,6 +96,7 @@ struct mlx5_vdpa_dev { u32 generation; struct mlx5_vdpa_mr *mr[MLX5_VDPA_NUM_AS]; + struct list_head mr_list_head; /* serialize mr access */ struct mutex mr_mtx; struct mlx5_control_vq cvq; diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index c7dc8914354a..4758914ccf86 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -508,6 +508,8 @@ static void _mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_ vhost_iotlb_free(mr->iotlb); + list_del(&mr->mr_list); + kfree(mr); } @@ -560,12 +562,31 @@ void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev, mutex_unlock(&mvdev->mr_mtx); } +static void mlx5_vdpa_show_mr_leaks(struct mlx5_vdpa_dev *mvdev) +{ + struct mlx5_vdpa_mr *mr; + + mutex_lock(&mvdev->mr_mtx); + + list_for_each_entry(mr, &mvdev->mr_list_head, mr_list) { + + mlx5_vdpa_warn(mvdev, "mkey still alive after resource delete: " + "mr: %p, mkey: 0x%x, refcount: %u\n", + mr, mr->mkey, refcount_read(&mr->refcount)); + } + + mutex_unlock(&mvdev->mr_mtx); + +} + void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev) { for (int i = 0; i < MLX5_VDPA_NUM_AS; i++) mlx5_vdpa_update_mr(mvdev, NULL, i); prune_iotlb(mvdev->cvq.iotlb); + + mlx5_vdpa_show_mr_leaks(mvdev); } static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, @@ -592,6 +613,8 @@ static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, if (err) goto err_iotlb; + list_add_tail(&mr->mr_list, &mvdev->mr_list_head); + return 0; err_iotlb: diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 0df82e4d13f4..88b633682e18 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -3707,6 +3707,8 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, if (err) goto err_mpfs; + INIT_LIST_HEAD(&mvdev->mr_list_head); + if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { err = mlx5_vdpa_create_dma_mr(mvdev); if (err)