From patchwork Fri Aug 16 09:01:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13765788 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2074.outbound.protection.outlook.com [40.107.236.74]) (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 C46EC13FD84; Fri, 16 Aug 2024 09:02:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798959; cv=fail; b=f4h3VpTfzOoid3AbbpIkceOJYqpQdHGYLbeTOVYKKs7jESeUaGcsWfApZZMRT/s/EYSIKkb00Eh6fydLd+MOJDQrjZfkWZJ/DB4iWPZ/eOXjY/YjtIgwHjdMzWSon63jt/mdDx/mblwqPeDXaZpnNUjgRJkztDFwLUySP+s1f2U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798959; c=relaxed/simple; bh=1aX/5HD1uM1/yrGzz+E9QEV0jPwgKYOms9V3USYM7nk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gGmy4C+LYirvEUprxZxy6xZT+22JG2rg8VjI26xgIWNvIiYO8shln7+qAKoFQwEPrFXnHASCsKd4TkWHUhMZVvDT/cEvUBpAwXjOhYbRALXeG2RT4DCxZxQAKouhGGv+lQDM4oqQ25eSoGo/uuymgFDBcfHNpw+fnhAvkI9GABQ= 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=ui4w3XRO; arc=fail smtp.client-ip=40.107.236.74 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="ui4w3XRO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PvPpmPvUuSQCz1H/uqdwNV6Y7Z4dVP9DWqdE2bsd68ko8P9IYsQUJZmyVAYXb3EXIPiLacGUkDAcHOMit7vz3xcOT/InDZrKMjsINws9HyQY9ADnn+Frrp44EOdhdzlgoh/UusIVdDFIZSrKdag/IhHxeUPtjUpq4aQyj5a3qZ7JdiMhd2oBal2ns591gN6p/vfv29WimIlxRDOLbZ/iTY/VuR3N6aHvr5wyBtDYX04KDq4ocKaPTZ8gsQkAYU+5S5BAgXz7CyIkdFjqXvqFueejQYNRY5fbE5MKCCFkOPu4T/gceO/s361ql666u4ri9gwJqWXZRnBQS4RFMeWy6w== 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=7HNbJZ4G3eSJS2iWpFc9qT1/7GEIi6is5UB2ZOXeayA=; b=tGcS0z9Y0y0SveAM2AWxPoi1inub0zI/EhdW9/WYVcmOi0V5ySMeZfDVgaRMRMJZFX/BF4qpjs4kHXfNsvJSJPrtB9MDgByxARdaWTr6NZp4bC1os6v/omh0cRRCQWP+I44AyzEZe7S3iWc291+4dzwzDlivyPErHY+JNzyrr9b6JP1SspaWf5bUvSEmryWC5IPMg1b5iKVui90KHO0arKDuIUsFw2O4vIoveJeXhTYYzE5Y/j7wA97S0h312HlntgEIYSc+aMZWVxo5F1zVcSMd1jOHk+4yr0jGE8X3J7M9MuIRDIuZO/9GIYC6Y91d+gDSkcjfz2M1CEaamjMzUw== 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=7HNbJZ4G3eSJS2iWpFc9qT1/7GEIi6is5UB2ZOXeayA=; b=ui4w3XROHr4KiZ5UR7u84ysm4PYg2qaWCMcNdoQERudFbBq1KCJlHPVqkBpBn6awn3DnnbZfmAjWE5EYa451wITn7jZbzeYFQrsCnjZdlHQBRnXIf369tIt78t30NPtqKm9Q4mw1mIPAE3STIKuKIz1RmDV7k5LK+bRNsVIuhvpRvGmmW7cjYxDyj4Avv8clNfH2jPIvpcMAbfN074Ea3ZFbqS8evo38pL/w/UelNlMjtEQ4byeayKjIhVAJMOHYzSZvKt+RIYQIKIzG30UIU9WX6iuNXnnCxw7kVEWRW/Y/brYt6IDw2hsdyX9enx0XCi3F22NbIQe6G26sxd94hw== Received: from BN9PR03CA0768.namprd03.prod.outlook.com (2603:10b6:408:13a::23) by CY8PR12MB7414.namprd12.prod.outlook.com (2603:10b6:930:5e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Fri, 16 Aug 2024 09:02:30 +0000 Received: from BN1PEPF00004689.namprd05.prod.outlook.com (2603:10b6:408:13a:cafe::2a) by BN9PR03CA0768.outlook.office365.com (2603:10b6:408:13a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.33 via Frontend Transport; Fri, 16 Aug 2024 09:02:30 +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 BN1PEPF00004689.mail.protection.outlook.com (10.167.243.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Fri, 16 Aug 2024 09:02:29 +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.1544.4; Fri, 16 Aug 2024 02:02:16 -0700 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.1544.4; Fri, 16 Aug 2024 02:02:15 -0700 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.1544.4 via Frontend Transport; Fri, 16 Aug 2024 02:02:12 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , CC: Dragos Tatulea , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Leon Romanovsky , "Tariq Toukan" Subject: [PATCH mlx5-vhost v2 01/10] net/mlx5: Support throttled commands from async API Date: Fri, 16 Aug 2024 12:01:50 +0300 Message-ID: <20240816090159.1967650-2-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240816090159.1967650-1-dtatulea@nvidia.com> References: <20240816090159.1967650-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: BN1PEPF00004689:EE_|CY8PR12MB7414:EE_ X-MS-Office365-Filtering-Correlation-Id: 4556c9cb-f9bd-4fad-2a3e-08dcbdd2288e 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: WaGPe/ydXc4eMoQMNaVC4iQfaptMTFoaWIjPuHLi6F1Ya1pfB1x5ELc9uaRW61sqUoMdqtaTPULWd30SWROfBgghhmX1gHIYzh6OwgPq1rw4iZdPx0zZcybvmiBeqNrXtC0BDM/M8ofTSH31Hqvu6AYHlppbSBevcT6bE19YIU7s8PUbuAerqdUkkg0X9oB61JW/Cy4t1gS72C3fYFQL60oy2J8JibvOPHXVY3Fv1IwscMtQxJd9M5nAxzxSI3ujDzs8ZW65+i/pqOm9XO34ULetxsRtTZcdfuAtOpEViSJT0J5Fc3FtZEsYcSc+GTZtuGfAqtaIODTcf0Jya6VqdI7zeITw6JlNl7wjIDCHaQrG5eNcKnTIH0OhRHYyRWMeW322ErKPH2pmmxgIa9RHvTNXedw3bfNhKQEI9NfJ6mI6hdu3AReTj5KFFl2yXq5gEZy+29USC7UgPDatj43mXYqlzLxLVBxTpY5bbshj7mRsC3FP0tyvVvb1iBdjqr6IQV8NaGFCRChAkSxtnRoUfpdQAK4XqOL+UDQ16UVKQjrpcLvmcQAo9OryMOqtloNnqT9r2oW8WWAtNAcI39tia/DS42plrr4llYITB28tV75ZE2fTuwDKk7UiaGnX7+dvztI9KWi/1qb8UWwsGrBL30VP5VQITNo/YGhHcYXQfaKJGhtahfan/bph+wngzFF87SQkfeKcBMzuNF7raslmy1pLaZF78B2sF/dWjXa0PSt0c0uP3ilgtPRd6Ved7+frV7F4kRYm9TunggZw6IhmNVuZOGN6OtxPCw0mlGpcLAOtM2Lpb1AniAN7Kr6AkR8zBChc4f09PAD8NFogdl6IxtHrECIRbl9TyEfm8P7GKNKLq3+Fyud/bWxaPjjt2OnwT4LEsO8jaS9uh2HAXHGfeEZYp1ef4Uw2+qyE7SfcUFl9WRKoV1UQtxljDb5TWq9iPu2rleBeShU6SeLqO85o1Yrrsuww+Cl5G0rPbSvFCVd9WJxSAXYSEU6eXZzOAhyi5MEgeeS3TLuUtAaUfD8Y8iclMMPvQ+ZUtjr65tpAe/8mCwGF/t8aBv86D2HK1ddq4l2Wa+nOZhTublY4lgNSh5vywccsgSlR5pXL90dT46D3XoTSV8zBsawM22lpOGlijFvfvVk3Z3h75oJCbO490Tw9X9va7xKC0o41CHNADBqf2dH+2LVUct4dVl0kZupaTTH+hR2ennk9/mGJyo4IC37mKOyzC/VX+RUp1NB+TP+pCevJgshZptlRE59y98RmKYQrM0ex6QBa6j2of3Mf6GTj0qCKS0Iy1HPz8QCOPgxP9jNlKpV1EWqYj+VwHJvnox5UyKFCNIx833whGM918SAZ53plsGt0QeUxr3nB95RZLhJfMozmSdSHH1RLR/A+LZpSXh8a8ECblWE1SZWBganTo/S4bkLJ3ew5DyyE9GJLFv+NkxueoachtsZdy96G 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:(13230040)(82310400026)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 09:02:29.8611 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4556c9cb-f9bd-4fad-2a3e-08dcbdd2288e 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: BN1PEPF00004689.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7414 Currently, commands that qualify as throttled can't be used via the async API. That's due to the fact that the throttle semaphore can sleep but the async API can't. This patch allows throttling in the async API by using the tentative variant of the semaphore and upon failure (semaphore at 0) returns EBUSY to signal to the caller that they need to wait for the completion of previously issued commands. Furthermore, make sure that the semaphore is released in the callback. Signed-off-by: Dragos Tatulea Cc: Leon Romanovsky Reviewed-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c index 20768ef2e9d2..f69c977c1569 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c @@ -1882,10 +1882,12 @@ static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out, throttle_op = mlx5_cmd_is_throttle_opcode(opcode); if (throttle_op) { - /* atomic context may not sleep */ - if (callback) - return -EINVAL; - down(&dev->cmd.vars.throttle_sem); + if (callback) { + if (down_trylock(&dev->cmd.vars.throttle_sem)) + return -EBUSY; + } else { + down(&dev->cmd.vars.throttle_sem); + } } pages_queue = is_manage_pages(in); @@ -2091,10 +2093,19 @@ static void mlx5_cmd_exec_cb_handler(int status, void *_work) { struct mlx5_async_work *work = _work; struct mlx5_async_ctx *ctx; + struct mlx5_core_dev *dev; + u16 opcode; ctx = work->ctx; - status = cmd_status_err(ctx->dev, status, work->opcode, work->op_mod, work->out); + dev = ctx->dev; + opcode = work->opcode; + status = cmd_status_err(dev, status, work->opcode, work->op_mod, work->out); work->user_callback(status, work); + /* Can't access "work" from this point on. It could have been freed in + * the callback. + */ + if (mlx5_cmd_is_throttle_opcode(opcode)) + up(&dev->cmd.vars.throttle_sem); if (atomic_dec_and_test(&ctx->num_inflight)) complete(&ctx->inflight_done); } From patchwork Fri Aug 16 09:01:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13765787 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2052.outbound.protection.outlook.com [40.107.93.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 BA98613DBBE; Fri, 16 Aug 2024 09:02:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798956; cv=fail; b=CF1FD8BosYFSuNHCNnK/R0GhoMwcW6+1U66VlTdhoSAauUNgHvlfBbtAv84/GCAdI57ak9pE20Z/nWRxCJAvjp6AvN8tCkjOWtC8Sj7dRB9QCCbJCk82yk6nGHemJBQnarXHAzzvAvJjEoxdzDW/vle9ndtAIIiWESSFZWjw83M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798956; c=relaxed/simple; bh=vBCbdqBQLdsHOKBWDeoIfTmPyba4qU8tIfeM70JLJTo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Lr+L4Ids2JUaGsZgxG+o8VlQ8ByJgWlF1q1gupmIWOc4vaaiU5c4aXqIUBxqxR2l4iA7IGjQ6tAmFeAGT6rQ6/K43OzRhDWRZj/Q4shR3vVwGYGFX8utY7lvXwWQ2TLcXW9oz0xnQFDlbscUo91/3mrfaD9RdPmXpVWYior+fH4= 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=K4L9Fpu8; arc=fail smtp.client-ip=40.107.93.52 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="K4L9Fpu8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PovGSLZ71UwV49tWyk0ChCXAoPXbmx9q0OU8dBhchTIOf1q8zcPFsJC181jz+s6TPSRp4kjqU2nEV0jM1hIhDluQYwjQhY5E6kP7jWsyj5sI0xrb4Zv73krlbLE/Gi+EoXnoTr5mLrlCNFFM+lzUy1lT7jMBzho+q4el4iEHpKWPzRSlS82qXphhfpnI8W+FzfABLleBUHm0qmZiZZK4T6EVvZjbWNwMpE4Yob8+7S4TUH0UtSMWicvNctbYIY1XOsTOFFWMNCa6aafb4Y99po7Bd/7AboCnCWuTi+mH1RO3n4zNy9sCWJoK1ZUUfhGWceM/0E0nKtr5NM5liSd+/A== 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=zRoRYGLiazx0feu6Fm11gTsP+sJWPCsWcl8GKQJ5n28=; b=P/87rpabrQHXCBdeFPEwNMp4bBMNsrdnl3fBtORY8PoA53o0fchaVk1lHcJ7zdUK6wbdXYZvlMwPVsyJIIuldU5DKnfliR62v0k7z4U4P9g6UoAcX0BTT+uFwDfdm7z/msciU0kp9Fecrkav0i+Yrbb8KL3fMW1gyiWwJ8t/8xqW8poisGadb7fbhRcqg8vbhI25i01ifrPpYml0Ll/om+V/WxwpRNM13XRHSaU+yDZ5zEloe5r6DuUjufIOE3jdT8oKoHXq8PkDpsegqok5ppkQ8MldtiFWIUXdq4ghW4AylaLobFNUZcoXPzbX+tW9QrQ5wTIt11+DQquokukoFQ== 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=zRoRYGLiazx0feu6Fm11gTsP+sJWPCsWcl8GKQJ5n28=; b=K4L9Fpu84PkiO0bMXK/WRsxta5qHpzfMT6ObAWv74fRBqM+LzTyISCpXqWvLYoqLOZXhxokRda/YlRNyZ+1pPucZNmdnbkEFTSnji1dSOF/f8+6QoZTaJ5SmJ3WoEPHOV5mkA4g+lwv8cHyepyiqrwp+4jOxn+t6QnRpbcK8Fx2XQ0QN/343YU38alCf54mlyCivHFUJRHpAwf+lW2XU8UIAcQz5l+0uEvWbWe9mZRD1aSK15pE1JaFDWGJEIhvhSTu0avCJZbVW6XYGQIc5awr/jl7G1GcixnQ4sjh7ylGxOxx0Yxde5doLmL5bw7aTzPbuT5AG1x/sxBcOpwwNcw== Received: from DS7PR03CA0119.namprd03.prod.outlook.com (2603:10b6:5:3b7::34) by MW4PR12MB7143.namprd12.prod.outlook.com (2603:10b6:303:222::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.19; Fri, 16 Aug 2024 09:02:31 +0000 Received: from DS3PEPF000099DF.namprd04.prod.outlook.com (2603:10b6:5:3b7:cafe::84) by DS7PR03CA0119.outlook.office365.com (2603:10b6:5:3b7::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.33 via Frontend Transport; Fri, 16 Aug 2024 09:02:31 +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 DS3PEPF000099DF.mail.protection.outlook.com (10.167.17.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Fri, 16 Aug 2024 09:02:31 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.1544.4; Fri, 16 Aug 2024 02:02:20 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 16 Aug 2024 02:02:20 -0700 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.1544.4 via Frontend Transport; Fri, 16 Aug 2024 02:02:16 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , CC: Dragos Tatulea , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Tariq Toukan Subject: [PATCH vhost v2 02/10] vdpa/mlx5: Introduce error logging function Date: Fri, 16 Aug 2024 12:01:51 +0300 Message-ID: <20240816090159.1967650-3-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240816090159.1967650-1-dtatulea@nvidia.com> References: <20240816090159.1967650-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: DS3PEPF000099DF:EE_|MW4PR12MB7143:EE_ X-MS-Office365-Filtering-Correlation-Id: cd25e243-2fb7-443a-1583-08dcbdd2293a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?unKEtCRKou5ZDJ1/+ckq94kCd/tTmxZ?= =?utf-8?q?pWf+Y8fq80egYsYUJYj8FRO8yXWanFwlax0XQUIMsPOt+9jt9Z4qrbUrm8c+eEMN9?= =?utf-8?q?/IM19Oe5RWPZM4VAyTFUU5Om45/V60WLrDFBerJJ3+25kxM8nw+hNgkZXRPA+Pa2p?= =?utf-8?q?uUm9Dpe2948IzFTil+CxpYkH5709TE+pudpUDKJTiSe3Dv8PZfEH2pgfoNHLJ78Pc?= =?utf-8?q?B4uFkB5st1T+do8U5syQwCOaae1TK6ru8kw0AFwSkZGIUHhCE3jDBdBBnhKp7lGHB?= =?utf-8?q?JsL798kA++YuppfcZON+C1Lb2o4jlZnlhHMdF3SJJcMJjVA9ijPqqv2FdG8NwBVhH?= =?utf-8?q?nxOeym3Bx6sLwF8xkS81BT5ROlWLN1ST/qQ9lCwaIvMkT8ZmxF4/7BKNCnUMblfoM?= =?utf-8?q?e0wMKDi1n3VrSt2CzKmWmZeFlMzXDFGKmM7CRTOKoMk3TE63TKxYo8tZqWFFOXYDy?= =?utf-8?q?J/DFyUXq/mvsBT5dJCFOhXk2mnunPGkAshle8v32ONXsr2teH4ghQ8peadJBpqWB1?= =?utf-8?q?5BHBcY3BtjPPWskh6eNLmPGDqR3fwL1BbSoP9yZ6keF80WM8u+AEkLQH4ksfve2jr?= =?utf-8?q?HTbG47rVgZiON+BZ26NBXGA4I9CO5VrAFX2eg4zqlh9KYbvoOOSBmGizZoG3UjeUC?= =?utf-8?q?ZC63IotaIJXy6JwFsfEOMGfeLofWgYtXmZ30Oh+qxZfM+cTETTlEhFkUwEzkD/pKJ?= =?utf-8?q?hT+uAK/on/MXFUywUsGEvLw4sbKBcQKt9PjuWwKerM/A02YinprqVg+qunhNxry5t?= =?utf-8?q?OhxQgJUv9tztwgkJY0YiYRRRe70sWqmMIACJlLIaS7/py+lYYbyy3dDEWC4u8JwES?= =?utf-8?q?PD84lv3tZXqvjtvsRYG33io6wugo3yC+9wqPTBAmx17+0/O2maag1MFpBpi0WgZVX?= =?utf-8?q?ecTcWRtoo2FsDDrUsDPMAGHLz50AHjiTRcaqEAw8rVSEzNbxiruE+NXDdg0mvbK2S?= =?utf-8?q?41EB+Z9/h4X8fFi09NZ9m0Gzpu5+NXEZG+Ch7J/GF4fF7j/C1OfgIapeEhq6CUbcA?= =?utf-8?q?03BkzHs1uv/fdyld4mqdLJax9FuBtg426jmWRG4ibI6n+B9HBOKKaJB9lPduY+iEN?= =?utf-8?q?hFK5iUjY5ja1lEobXO8QEqZSoXzPvzX/zmaCJ7XgXXXumyWNTDMdp9yUnv0YHK3Z+?= =?utf-8?q?jFCZK5X+m5uP8cegBsMWTxQCRevrGQyeG9bR1kodSXKMmcpGIp9YJ8qLdUKfuWFrG?= =?utf-8?q?i5pIpxP2SeRVbk1/jJ3azock6mqhG6D0V8P/yOwUYhDNwydXHvcAtzNw3CBHYIGIs?= =?utf-8?q?z2hPnlU+//FG+J0g9W3gXJdl+dE0sJLwDyzFwtcl2sFmmar+N+/2MAv/1vpbx1Eqf?= =?utf-8?q?fUCyFZo0ca+hpLMYJjSqqHEzRLidoDZrdsY53giGzKMJOsNtm+1wgtlHcV1cEJSZm?= =?utf-8?q?aKbctLy58pS?= 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:(13230040)(1800799024)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 09:02:31.1128 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cd25e243-2fb7-443a-1583-08dcbdd2293a 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: DS3PEPF000099DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7143 mlx5_vdpa_err() was missing. This patch adds it and uses it in the necessary places. Signed-off-by: Dragos Tatulea Reviewed-by: Tariq Toukan Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 5 +++++ drivers/vdpa/mlx5/net/mlx5_vnet.c | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h index 50aac8fe57ef..424d445ebee4 100644 --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h @@ -135,6 +135,11 @@ int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev, int mlx5_vdpa_create_dma_mr(struct mlx5_vdpa_dev *mvdev); int mlx5_vdpa_reset_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid); +#define mlx5_vdpa_err(__dev, format, ...) \ + dev_err((__dev)->mdev->device, "%s:%d:(pid %d) error: " format, __func__, __LINE__, \ + current->pid, ##__VA_ARGS__) + + #define mlx5_vdpa_warn(__dev, format, ...) \ dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__, \ current->pid, ##__VA_ARGS__) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index fa78e8288ebb..12133e5d1285 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1538,13 +1538,13 @@ static int suspend_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mv err = modify_virtqueue_state(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND); if (err) { - mlx5_vdpa_warn(&ndev->mvdev, "modify to suspend failed, err: %d\n", err); + mlx5_vdpa_err(&ndev->mvdev, "modify to suspend failed, err: %d\n", err); return err; } err = query_virtqueue(ndev, mvq, &attr); if (err) { - mlx5_vdpa_warn(&ndev->mvdev, "failed to query virtqueue, err: %d\n", err); + mlx5_vdpa_err(&ndev->mvdev, "failed to query virtqueue, err: %d\n", err); return err; } @@ -1585,7 +1585,7 @@ static int resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq */ err = modify_virtqueue(ndev, mvq, 0); if (err) { - mlx5_vdpa_warn(&ndev->mvdev, + mlx5_vdpa_err(&ndev->mvdev, "modify vq properties failed for vq %u, err: %d\n", mvq->index, err); return err; @@ -1600,15 +1600,15 @@ static int resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq case MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY: return 0; default: - mlx5_vdpa_warn(&ndev->mvdev, "resume vq %u called from bad state %d\n", + mlx5_vdpa_err(&ndev->mvdev, "resume vq %u called from bad state %d\n", mvq->index, mvq->fw_state); return -EINVAL; } err = modify_virtqueue_state(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY); if (err) - mlx5_vdpa_warn(&ndev->mvdev, "modify to resume failed for vq %u, err: %d\n", - mvq->index, err); + mlx5_vdpa_err(&ndev->mvdev, "modify to resume failed for vq %u, err: %d\n", + mvq->index, err); return err; } @@ -2002,13 +2002,13 @@ static int setup_steering(struct mlx5_vdpa_net *ndev) ns = mlx5_get_flow_namespace(ndev->mvdev.mdev, MLX5_FLOW_NAMESPACE_BYPASS); if (!ns) { - mlx5_vdpa_warn(&ndev->mvdev, "failed to get flow namespace\n"); + mlx5_vdpa_err(&ndev->mvdev, "failed to get flow namespace\n"); return -EOPNOTSUPP; } ndev->rxft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr); if (IS_ERR(ndev->rxft)) { - mlx5_vdpa_warn(&ndev->mvdev, "failed to create flow table\n"); + mlx5_vdpa_err(&ndev->mvdev, "failed to create flow table\n"); return PTR_ERR(ndev->rxft); } mlx5_vdpa_add_rx_flow_table(ndev); @@ -2530,7 +2530,7 @@ static int mlx5_vdpa_get_vq_state(struct vdpa_device *vdev, u16 idx, struct vdpa err = query_virtqueue(ndev, mvq, &attr); if (err) { - mlx5_vdpa_warn(mvdev, "failed to query virtqueue\n"); + mlx5_vdpa_err(mvdev, "failed to query virtqueue\n"); return err; } state->split.avail_index = attr.used_index; @@ -3189,7 +3189,7 @@ static int mlx5_vdpa_compat_reset(struct vdpa_device *vdev, u32 flags) if ((flags & VDPA_RESET_F_CLEAN_MAP) && MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { if (mlx5_vdpa_create_dma_mr(mvdev)) - mlx5_vdpa_warn(mvdev, "create MR failed\n"); + mlx5_vdpa_err(mvdev, "create MR failed\n"); } if (vq_reset) setup_vq_resources(ndev, false); @@ -3244,7 +3244,7 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, new_mr = mlx5_vdpa_create_mr(mvdev, iotlb); if (IS_ERR(new_mr)) { err = PTR_ERR(new_mr); - mlx5_vdpa_warn(mvdev, "create map failed(%d)\n", err); + mlx5_vdpa_err(mvdev, "create map failed(%d)\n", err); return err; } } else { @@ -3257,7 +3257,7 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, } else { err = mlx5_vdpa_change_map(mvdev, new_mr, asid); if (err) { - mlx5_vdpa_warn(mvdev, "change map failed(%d)\n", err); + mlx5_vdpa_err(mvdev, "change map failed(%d)\n", err); goto out_err; } } From patchwork Fri Aug 16 09:01:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13765789 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2040.outbound.protection.outlook.com [40.107.94.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 351131422D6; Fri, 16 Aug 2024 09:02:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798960; cv=fail; b=Dz/soKjiPjcniD3UalYvvrlhgC1N4/NtfwqA47cWnx4ofmpllMGmw/mUNxDfFl77OSYQsR/Ik2yGhZieOcgM0jCeeOW0mWxVO+2uCuKzY8XUtKq+AWnZmvOsOihDxUEIiAc672FOo1CpdRmY+z96+1nKeSKqz8K3Ii1sYX3KZDU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798960; c=relaxed/simple; bh=oqa9ogSQcJmTyK2S054y45x8kmGxO9+mUUyiMWlq58M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JvrmVMjxOHrbzow422jEfDckmvMJlVPOSOC/Z74KeM3s9CTIh3XcvRCb2e/lqYuuHmZEBVFzO6xASgHht7Rz6ULFcA/+oeWD1+SzMPZsQGrNor60Qx9YweSAG9ybZmMtHUIH8KkM/1nU3CKr66wjkxEZz2w6Z3oP6Xx+eMZvMW8= 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=OVEOJtrC; arc=fail smtp.client-ip=40.107.94.40 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="OVEOJtrC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LMkkPc7vo9f+J87eH0HDYNIEseX/cisCwR8sulZcYW2kNa6K1hngjI/qpDzJNOR3mMoUtqSBqHyPrq887e5d7WvcjNPqcYDEXsNpcu751niuoUv8I53fLaRWH0g0RDUXa8VEi2TKKgG8pCdfPF1R2YLwWlKhNraZS8EuNTsXk89JfPTdX2TgMSd9kBvvHaVcJVHOaTRDM7z61DW7KkPha2IB9VMqk9lcD9RD+l6UFNN5yX/IAohLqyyFFL9P8OvLSaKnqDEqsZRoiv1gNzibxrxujT+ZBBIyZYB5lx56IYnEV2aaK6BwjqMFJqcWltwtYFa/8dpJxiwm44qz3eua4Q== 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=cif3mJQqYHYaM3UbOWVZFvwomEcqYidBva7Km0ICe/Q=; b=a+LBj/HVzlV+vhMzs4asQUaslB5zIqhJIDHCZ69msVaQEAWIseLTXmL74eSNgPSPS7nVq0zhQZTDgChlCkO9yGSruklGhKFTfXtlE1b+8XKaiI4mCo43z8Eow57CS0Xkapc8wj0afrYfp2RYO2GU4mLV32VeF+oQdPOmqphgleJ8AvpFwhwaenJoR4OMQwqIH6kbxe9MisUzWgJaNKmKyPZ9Qubsj/nrqBl17abTtpdJ5PDyryLevPQs7ZR9kngPYgGC+yVUpkkIQfEO2Lju0+lwGmADjBlA4bukx1SIRzZP5UqfcSFzcVpbDRmtxt3ZSfPbTy7rH5FUCQrJekmgAQ== 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=cif3mJQqYHYaM3UbOWVZFvwomEcqYidBva7Km0ICe/Q=; b=OVEOJtrCUSHL39Ks56aD2FKPTTvHR7TA+qsz36W+hJ/h6ozaZ3jDf0TxMfHDT9j0ipnWGZAOTMFc3j/AtRqlbV1r5C0kfQEZqvOM2gbDbb0jTbS+BTB0J3vuQZgk0lR91z+bb+JA6k3xRh87q3GJuwN7IhD7EJZZhWvcGiADWYoryTWYLj2VYfgbC+0aCXClpYXurPAhvljwpzNoA6ACSLUeK7Y+90oekA459x1PIMZY99Lfj+Nz47dewU/SI9bL+ki515YHwDvBwvMXEx4zDM0M4D5vo1X5KwVU8K5yhHQNHz6xHBLfHHdbgpqO7E20075H/KEGarvRXJUecqwhgw== Received: from DS7PR03CA0110.namprd03.prod.outlook.com (2603:10b6:5:3b7::25) by BL3PR12MB6427.namprd12.prod.outlook.com (2603:10b6:208:3b6::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.19; Fri, 16 Aug 2024 09:02:34 +0000 Received: from DS3PEPF000099DF.namprd04.prod.outlook.com (2603:10b6:5:3b7:cafe::d8) by DS7PR03CA0110.outlook.office365.com (2603:10b6:5:3b7::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.33 via Frontend Transport; Fri, 16 Aug 2024 09:02:34 +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 DS3PEPF000099DF.mail.protection.outlook.com (10.167.17.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Fri, 16 Aug 2024 09:02:33 +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.1544.4; Fri, 16 Aug 2024 02:02:24 -0700 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.1544.4; Fri, 16 Aug 2024 02:02:24 -0700 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.1544.4 via Frontend Transport; Fri, 16 Aug 2024 02:02:20 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , CC: Dragos Tatulea , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Tariq Toukan Subject: [PATCH vhost v2 03/10] vdpa/mlx5: Introduce async fw command wrapper Date: Fri, 16 Aug 2024 12:01:52 +0300 Message-ID: <20240816090159.1967650-4-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240816090159.1967650-1-dtatulea@nvidia.com> References: <20240816090159.1967650-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: DS3PEPF000099DF:EE_|BL3PR12MB6427:EE_ X-MS-Office365-Filtering-Correlation-Id: c0eba58a-0c9f-4a68-dae3-08dcbdd22ae4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: lSD5fIvWNcp5q9+gNnmxqO0jGu0fXYWKES6SG1tNuuDVbo3vQCH7A650X9LOrcNxh5lDw7Y5KGPbARFfu8gbHt+xO6iljPPVReqdgjmgowb35AqSAnAAYOfS122LxNNMvgnYZebNBYr5KRkAe+falQ8Z99uPKypHe01AFLBTaVBc3c/jY6sxnil3S0W5R1AO8fz3kxcvCV8WmuIOolNGyBLhVrFpv2i1XHnMpae5znhNwimDW9p+9oRENfZa+VBda+U8T7ZCPoO3luK2X42RI4FZY0zY2RITR67zbm1bJdm78aS37OW4fspbNBjhutVqseBLlrWGVOTQDelVmWzvsnbRv7jkV9iVzw8NQzp9b2uqgiITejI5LWiHhmHuIN3KiswIisS3AhSSzonIi6COrv1yvF7GybFnqpLdbCZXBKfyuAFtB/I5RzsGJBamGxy6rOY8E3sQDz7uLUghs/03syIgUvZxBT1dX1EQVJD2APiOgJt9hfOyZJIIDRgZygkBe5WShkYo9tq+fs990dJGyvqAUg5MixeGMph77Ef711od2XeOyoN1ZLLFyl0WOtZMVPtAKMMfDTSUjP8WW1LrnHTC/PsZgFM+o/qFyQp3dZo7OXMXyz7Y85pk2BoGFvRy5lvo6ZSd1YTqqoxQia5i+DmPqUpQlIKClYzQzvKhekvavduygwtCcEJAfbkybeJLRH8Xw41X7A9MwKxqobPI23cOm2GFv+ipjC9tv+cKGhvjdH2dq/bEAnx7LR7xndzh/shwPOcQoz3JMsGxhMxfdHfo0SaawM9ELNtK7f2VFfyJWT9XX2+Jagh9wh0EwlrrJ280QaaW7H4WRCjtW5t5Nl3T4LXV7ycuLzj+drS5jAQHV9/V9GbVaZYBNvtSPcqtWNvOwinO4b4SdRYfGVusTNfwOC6PmlBTQSQhTiQsx6PLT8lCztGY2ypC+SxEhY1n6FE3F/kaA/VnZtVdBhv9ZAMa8kiwKz+Xf63wMlVETW0PgxzkumFWjb0dEWwBrWCqjprCpNawyOjArdJeM9Hn5GBvEdvQQgj5NP44pIvlm/4gfX87/ZnXzrxuiDFQr6PwpSh1pFd4hcAOWS/S9EADQkrD+TZghC5LY697erf1Ug53Y+qL2a27kPLOeXk3SeFgEIdt7NRVyRhx/+exxhpQ/iWNVcnELDjZx3RTCG9nGVVjMO8y2gCAq6kaPYpG0atVbemaGVfdo48HVGZrIRu+k1sLAJWPekikWFJqtPV4b0sNZxX+BfY2x+P8SzkaY5oG/r5yE/l/yJBlE/+a6d4ezXq5BnEV2AlqwsCWI20/Y0hqDl9ItkBQfuwYy/+Fvg7Hi7i01ofAvUf9biq6U41bW0eVdaullKY+F1oZoGo7oYv2cZCj/KGVp6PcwE9wQoaHzky6/Sxaxxdp+xZtbQivPtB6TIeP6k4bAsmZOcP1pNeNNFSphPUS18TcSPk9Gwvv 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:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 09:02:33.9097 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c0eba58a-0c9f-4a68-dae3-08dcbdd22ae4 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: DS3PEPF000099DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6427 Introduce a new function mlx5_vdpa_exec_async_cmds() which wraps the mlx5_core async firmware command API in a way that will be used to parallelize certain operation in this driver. The wrapper deals with the case when mlx5_cmd_exec_cb() returns EBUSY due to the command being throttled. Signed-off-by: Dragos Tatulea Reviewed-by: Tariq Toukan Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 15 ++++++ drivers/vdpa/mlx5/core/resources.c | 73 ++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h index 424d445ebee4..b34e9b93d56e 100644 --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h @@ -105,6 +105,18 @@ struct mlx5_vdpa_dev { bool suspended; }; +struct mlx5_vdpa_async_cmd { + int err; + struct mlx5_async_work cb_work; + struct completion cmd_done; + + void *in; + size_t inlen; + + void *out; + size_t outlen; +}; + int mlx5_vdpa_create_tis(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tisn); void mlx5_vdpa_destroy_tis(struct mlx5_vdpa_dev *mvdev, u32 tisn); int mlx5_vdpa_create_rqt(struct mlx5_vdpa_dev *mvdev, void *in, int inlen, u32 *rqtn); @@ -134,6 +146,9 @@ int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev, unsigned int asid); int mlx5_vdpa_create_dma_mr(struct mlx5_vdpa_dev *mvdev); int mlx5_vdpa_reset_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid); +int mlx5_vdpa_exec_async_cmds(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_async_cmd *cmds, + int num_cmds); #define mlx5_vdpa_err(__dev, format, ...) \ dev_err((__dev)->mdev->device, "%s:%d:(pid %d) error: " format, __func__, __LINE__, \ diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c index 5c5a41b64bfc..22ea32fe007b 100644 --- a/drivers/vdpa/mlx5/core/resources.c +++ b/drivers/vdpa/mlx5/core/resources.c @@ -321,3 +321,76 @@ void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev) mutex_destroy(&mvdev->mr_mtx); res->valid = false; } + +static void virtqueue_cmd_callback(int status, struct mlx5_async_work *context) +{ + struct mlx5_vdpa_async_cmd *cmd = + container_of(context, struct mlx5_vdpa_async_cmd, cb_work); + + cmd->err = mlx5_cmd_check(context->ctx->dev, status, cmd->in, cmd->out); + complete(&cmd->cmd_done); +} + +static int issue_async_cmd(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_async_cmd *cmds, + int issued, + int *completed) + +{ + struct mlx5_vdpa_async_cmd *cmd = &cmds[issued]; + int err; + +retry: + err = mlx5_cmd_exec_cb(&mvdev->async_ctx, + cmd->in, cmd->inlen, + cmd->out, cmd->outlen, + virtqueue_cmd_callback, + &cmd->cb_work); + if (err == -EBUSY) { + if (*completed < issued) { + /* Throttled by own commands: wait for oldest completion. */ + wait_for_completion(&cmds[*completed].cmd_done); + (*completed)++; + + goto retry; + } else { + /* Throttled by external commands: switch to sync api. */ + err = mlx5_cmd_exec(mvdev->mdev, + cmd->in, cmd->inlen, + cmd->out, cmd->outlen); + if (!err) + (*completed)++; + } + } + + return err; +} + +int mlx5_vdpa_exec_async_cmds(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_async_cmd *cmds, + int num_cmds) +{ + int completed = 0; + int issued = 0; + int err = 0; + + for (int i = 0; i < num_cmds; i++) + init_completion(&cmds[i].cmd_done); + + while (issued < num_cmds) { + + err = issue_async_cmd(mvdev, cmds, issued, &completed); + if (err) { + mlx5_vdpa_err(mvdev, "error issuing command %d of %d: %d\n", + issued, num_cmds, err); + break; + } + + issued++; + } + + while (completed < issued) + wait_for_completion(&cmds[completed++].cmd_done); + + return err; +} From patchwork Fri Aug 16 09:01:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13765790 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2070.outbound.protection.outlook.com [40.107.212.70]) (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 B565F145FFE; Fri, 16 Aug 2024 09:02:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798971; cv=fail; b=mi227UfNuwunB4zmTWjjAkqe/KfMaObsnGICFskI7LDjGN0JdCEGQ8UPaIz1FfIiLAcfpehbPtGnsytYdiNxSRQEgiy9OeymrpB7Ye3wm8YXW7eUO2HPDzDvkb+WnjX/5bbBKXgrwHSElXC58pJGS/9z4dbidqyB7Rjvn5qEmV0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798971; c=relaxed/simple; bh=rOOyQEt5A0483eq2sWBmVGwOnJCQyKlO28avQYJ5doo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TuBpCMgzAMbNpwndW5cqMDl2uxFvLSW03yHwN9dVWG1eTvZqiHM9uxaAxxdAoAl/gFqf0xlgr0tK9Ku7JYYjNlcKymvqZRB2JBsHu3OckQ7To9Ai79TGSSTfo/DdTF7ZnwMdsY+gHPaze5a3v1YgsuUQaCZ2odTquqWyPgHJlZU= 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=qKxOK18Z; arc=fail smtp.client-ip=40.107.212.70 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="qKxOK18Z" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WpfwC0Xk9xls075qIsYTyBUjpmUHARA4At6OlHKunXk87Spu1ICe0Af6a4IxLCLyjbVc2KOMhHqLj14uGRZcmP/QIEr/ozuciykgvTpT1JkJSmcOtREyiW29ek/O5JPpUUuctE5K9FDXQ2PB15nwmC3NtYgVqunMx0df5uberYEsMO8wM0PJxWpedE2IDmr7ioBM90MKo+rGmZRm4TOtuFJN50ANH3KNom0XoiLGsqdTXr1BX/ui3hl9TBdp24rnnu+QVNeT4lu1zdRKANUzhNyYlad2+qe0RmLUX+89qzIg4IIx3pt21HduoSDKdLg7H6CnIewq33ZKX7estA6bGA== 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=+EYvEhhmxCGT0SxNpePBKSdpiklmOT3hHt52Br7Bdhg=; b=MCGe4W8cB09s7O9ZSMkcV3GcMNpdULrMedXfb4T5Q7VTXmBIW6GC/MUnqLIbG58KOSwbNg1Qr40ZFfgTQm1CzMlQUVLkomHsgdwurvRtNmb+NC+1TKSZvCyB1Ot7cU0/576TkqoZf7Qyl0dJstMNBoIFVJtBSQyiUrGTPxjey4UiI09jRJNTloUdBw8tDa6ihRixPYcdo5AU9M5wsilg83v9kdhJOXDnfsN6wN+y/ZKgqS8/h5g7kvKcGfVLNoGDHZyWrxYHCkgmibhJWPBylC1TvXyRR6LIUF5TSSjBUOKe/8ZLPRJIpSSng0eIPoxUGhDBmQX9koRazXCMKxLHpg== 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=+EYvEhhmxCGT0SxNpePBKSdpiklmOT3hHt52Br7Bdhg=; b=qKxOK18ZkfsBJFRUGAUvOvwFr5laweAw+rTTC2vnCkRHSzx4bu+jin/a66aHcBWWpB4ZPZGqEcFLpFwBJBwFGfLf1CxNwfKuhtf7+QSYDaIo4MLbg+bZNf5cbsOoBhwZMlPefLpvZsYXa8og2M08jZw28h09B4WpUcTDE+bIrAepIHRePMFcoNre0NF6+j4mCJZ3bqsJAiruuoMjNPn/cqzTCXTr9SM1xSGX1OCv29lnI9wA6gFhvXy/7rGgYvet9ryrbDKAPFkNmZt0q00lAfdR452vSw5284WgkQY+ruCQAEfu8CcIS+sdH9Gcq9f8Ti9uqx8HB5POb9yDHmEusw== Received: from BN9PR03CA0779.namprd03.prod.outlook.com (2603:10b6:408:13a::34) by CH3PR12MB8073.namprd12.prod.outlook.com (2603:10b6:610:126::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.19; Fri, 16 Aug 2024 09:02:43 +0000 Received: from BN1PEPF00004689.namprd05.prod.outlook.com (2603:10b6:408:13a:cafe::59) by BN9PR03CA0779.outlook.office365.com (2603:10b6:408:13a::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.33 via Frontend Transport; Fri, 16 Aug 2024 09:02:43 +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 BN1PEPF00004689.mail.protection.outlook.com (10.167.243.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Fri, 16 Aug 2024 09:02:42 +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.1544.4; Fri, 16 Aug 2024 02:02:29 -0700 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.1544.4; Fri, 16 Aug 2024 02:02:28 -0700 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.1544.4 via Frontend Transport; Fri, 16 Aug 2024 02:02:24 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , CC: Dragos Tatulea , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Tariq Toukan Subject: [PATCH vhost v2 04/10] vdpa/mlx5: Use async API for vq query command Date: Fri, 16 Aug 2024 12:01:53 +0300 Message-ID: <20240816090159.1967650-5-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240816090159.1967650-1-dtatulea@nvidia.com> References: <20240816090159.1967650-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: BN1PEPF00004689:EE_|CH3PR12MB8073:EE_ X-MS-Office365-Filtering-Correlation-Id: d417a54c-2c63-41e3-e80d-08dcbdd23060 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: ApkDwYMWGe1fMsUqOTcaXiNxe0LXlFsKwjcrny++VncIJIpdzQquAFx7NZ2Soqx6hD4/EwV2/hjXhDVj/9J6NpwujarSZH4eT08RZJ41sTDxmJAVqyrG1Z+5jBkFEBUZTt2HgUPNjHdNda0YtC2quceARx6sSc97PwiX75CivbSHhA9XgM1mJ1p9dyaNX9LXL+86mzhGSwwNEo9a2KX0gO6xgauJjYkVmVUuWXPVeZmKoBblugk73zaL5TzN/Brpk4I5tqeo6ifmJTTIKJGZdJblaq9X1/rzSQW+ZIi/yzoNiWw3glawLV3A/8gB6nozw2SuUJV15ThR5Vp4esqYic8hFKODq/8hTNKDpa/0mlGHOVQ1Wi1ZXsEPF8NgFBEL2mqruTqa14zr6VFt8tT6SkX+ACNvgUnT6OJ+S7jAwr7px6eqC9AYBQMpy9x7N2LRKuHxZO2sPQtNcuG+bj5EuuwnZSH0FUvggEVw2OcWM8FleCSFFqDcL4lhprVT7PCMUnonEPxKP6qJ0FDD/lFeLPJMuZfWyDRYZ4HlIVXEEmYqaDKYf0pVsgxEtK9PFoFWdpHuq5FMaeOOb2Q7CZjRqcJwzQ0RTHWIYkDglU1wItRjRUPWq2NSGdHQghudfLkeNKaASlIM4OWqe3A5AL/P+nCX3RNyJMZYAdp6UUS49tMfcf/DcczAzW0RWiaSLwGmnvy7GBsl3NxGlAGQiR16kSBrgC4OhDBg9Le0c30Bf9pW3YbU53aWMXLcfkE/wHmDXL/XeEAadnxdh/Mku5Pz+K4lwdrhHluAIJ7TBH9IrbR5a5sxPZqSyyKccY6O93ChBtAR0gPqrkf/tBae2U2pV/vkk9bjHOx38DBcmpaNFTzZS1L8668CQrBjHg5tOtbEuIzowr78llVWsPKmWsFdE5R7kkf6bybVHAeCArRy+GmSVg8mdaqI2DQPwZzzCqLFbUEcZ0bNYzuG/L3eGKzXR8Y+VrxxjsQUmcHvDmuLwoPVuFV0SEPWHyMKZKczZ2/ZfiR1rLPBbXjZ9NU6QzGBndhmqB0C8K2Sr9KL3PQjPzFuNmNzVs6C7uV8NYheW9UX+7Fs/hwKt/WE8zrLWz/wEy8uiQKFyqwHkf1ynBpZiEZpOq5nqQAGUTFbjUIPAQ1By56rhpcUxzawti3DJs8tT1w4bX0Db5zUscJSEGjrcZo5vUs4v6IrHkNCc1pL1jlAZrqVCQF3ybUctW8yNfIr9x20U+XcRoIe2FYJjPrrSxXcYzGQPy41Wl/D5BfmUUc7n8ZSn0pDO9TeVe14b6VxBICfGlTAlh6KgWKMHEGXoGaPAgsl8Uz/UhiY3f0fdlRvw89CucA1+XOfmzWZk6LNMDl2PR/+0OuhoJdAUdRcK5Djr18O0DbxeHS6A2z4eID+XQCpyOt+vqYnNO123JBYZrvzyl41QJva+dnYllQwJu7rYLQtKSay09YOmGRXwLBt 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:(13230040)(376014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 09:02:42.9081 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d417a54c-2c63-41e3-e80d-08dcbdd23060 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: BN1PEPF00004689.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8073 Switch firmware vq query command to be issued via the async API to allow future parallelization. For now the command is still serial but the infrastructure is there to issue commands in parallel, including ratelimiting the number of issued async commands to firmware. A later patch will switch to issuing more commands at a time. Signed-off-by: Dragos Tatulea Reviewed-by: Tariq Toukan Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 2 + drivers/vdpa/mlx5/net/mlx5_vnet.c | 101 ++++++++++++++++++++++------- 2 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 b34e9b93d56e..24fa00afb24f 100644 --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h @@ -103,6 +103,8 @@ struct mlx5_vdpa_dev { struct workqueue_struct *wq; unsigned int group2asid[MLX5_VDPA_NUMVQ_GROUPS]; bool suspended; + + struct mlx5_async_ctx async_ctx; }; struct mlx5_vdpa_async_cmd { diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 12133e5d1285..413b24398ef2 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1184,40 +1184,87 @@ struct mlx5_virtq_attr { u16 used_index; }; -static int query_virtqueue(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq, - struct mlx5_virtq_attr *attr) -{ - int outlen = MLX5_ST_SZ_BYTES(query_virtio_net_q_out); - u32 in[MLX5_ST_SZ_DW(query_virtio_net_q_in)] = {}; - void *out; - void *obj_context; - void *cmd_hdr; - int err; - - out = kzalloc(outlen, GFP_KERNEL); - if (!out) - return -ENOMEM; +struct mlx5_virtqueue_query_mem { + u8 in[MLX5_ST_SZ_BYTES(query_virtio_net_q_in)]; + u8 out[MLX5_ST_SZ_BYTES(query_virtio_net_q_out)]; +}; - cmd_hdr = MLX5_ADDR_OF(query_virtio_net_q_in, in, general_obj_in_cmd_hdr); +static void fill_query_virtqueue_cmd(struct mlx5_vdpa_net *ndev, + struct mlx5_vdpa_virtqueue *mvq, + struct mlx5_virtqueue_query_mem *cmd) +{ + void *cmd_hdr = MLX5_ADDR_OF(query_virtio_net_q_in, cmd->in, general_obj_in_cmd_hdr); MLX5_SET(general_obj_in_cmd_hdr, cmd_hdr, opcode, MLX5_CMD_OP_QUERY_GENERAL_OBJECT); MLX5_SET(general_obj_in_cmd_hdr, cmd_hdr, obj_type, MLX5_OBJ_TYPE_VIRTIO_NET_Q); MLX5_SET(general_obj_in_cmd_hdr, cmd_hdr, obj_id, mvq->virtq_id); MLX5_SET(general_obj_in_cmd_hdr, cmd_hdr, uid, ndev->mvdev.res.uid); - err = mlx5_cmd_exec(ndev->mvdev.mdev, in, sizeof(in), out, outlen); - if (err) - goto err_cmd; +} + +static void query_virtqueue_end(struct mlx5_vdpa_net *ndev, + struct mlx5_virtqueue_query_mem *cmd, + struct mlx5_virtq_attr *attr) +{ + void *obj_context = MLX5_ADDR_OF(query_virtio_net_q_out, cmd->out, obj_context); - obj_context = MLX5_ADDR_OF(query_virtio_net_q_out, out, obj_context); memset(attr, 0, sizeof(*attr)); attr->state = MLX5_GET(virtio_net_q_object, obj_context, state); attr->available_index = MLX5_GET(virtio_net_q_object, obj_context, hw_available_index); attr->used_index = MLX5_GET(virtio_net_q_object, obj_context, hw_used_index); - kfree(out); - return 0; +} -err_cmd: - kfree(out); +static int query_virtqueues(struct mlx5_vdpa_net *ndev, + int start_vq, + int num_vqs, + struct mlx5_virtq_attr *attrs) +{ + struct mlx5_vdpa_dev *mvdev = &ndev->mvdev; + struct mlx5_virtqueue_query_mem *cmd_mem; + struct mlx5_vdpa_async_cmd *cmds; + int err = 0; + + WARN(start_vq + num_vqs > mvdev->max_vqs, "query vq range invalid [%d, %d), max_vqs: %u\n", + start_vq, start_vq + num_vqs, mvdev->max_vqs); + + cmds = kvcalloc(num_vqs, sizeof(*cmds), GFP_KERNEL); + cmd_mem = kvcalloc(num_vqs, sizeof(*cmd_mem), GFP_KERNEL); + if (!cmds || !cmd_mem) { + err = -ENOMEM; + goto done; + } + + for (int i = 0; i < num_vqs; i++) { + cmds[i].in = &cmd_mem[i].in; + cmds[i].inlen = sizeof(cmd_mem[i].in); + cmds[i].out = &cmd_mem[i].out; + cmds[i].outlen = sizeof(cmd_mem[i].out); + fill_query_virtqueue_cmd(ndev, &ndev->vqs[start_vq + i], &cmd_mem[i]); + } + + err = mlx5_vdpa_exec_async_cmds(&ndev->mvdev, cmds, num_vqs); + if (err) { + mlx5_vdpa_err(mvdev, "error issuing query cmd for vq range [%d, %d): %d\n", + start_vq, start_vq + num_vqs, err); + goto done; + } + + for (int i = 0; i < num_vqs; i++) { + struct mlx5_vdpa_async_cmd *cmd = &cmds[i]; + int vq_idx = start_vq + i; + + if (cmd->err) { + mlx5_vdpa_err(mvdev, "query vq %d failed, err: %d\n", vq_idx, err); + if (!err) + err = cmd->err; + continue; + } + + query_virtqueue_end(ndev, &cmd_mem[i], &attrs[i]); + } + +done: + kvfree(cmd_mem); + kvfree(cmds); return err; } @@ -1542,7 +1589,7 @@ static int suspend_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mv return err; } - err = query_virtqueue(ndev, mvq, &attr); + err = query_virtqueues(ndev, mvq->index, 1, &attr); if (err) { mlx5_vdpa_err(&ndev->mvdev, "failed to query virtqueue, err: %d\n", err); return err; @@ -2528,7 +2575,7 @@ static int mlx5_vdpa_get_vq_state(struct vdpa_device *vdev, u16 idx, struct vdpa return 0; } - err = query_virtqueue(ndev, mvq, &attr); + err = query_virtqueues(ndev, mvq->index, 1, &attr); if (err) { mlx5_vdpa_err(mvdev, "failed to query virtqueue\n"); return err; @@ -2879,7 +2926,7 @@ static int save_channel_info(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqu int err; if (mvq->initialized) { - err = query_virtqueue(ndev, mvq, &attr); + err = query_virtqueues(ndev, mvq->index, 1, &attr); if (err) return err; } @@ -3854,6 +3901,8 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, ndev->rqt_size = 1; } + mlx5_cmd_init_async_ctx(mdev, &mvdev->async_ctx); + ndev->mvdev.mlx_features = device_features; mvdev->vdev.dma_dev = &mdev->pdev->dev; err = mlx5_vdpa_alloc_resources(&ndev->mvdev); @@ -3935,6 +3984,8 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * mvdev->wq = NULL; destroy_workqueue(wq); mgtdev->ndev = NULL; + + mlx5_cmd_cleanup_async_ctx(&mvdev->async_ctx); } static const struct vdpa_mgmtdev_ops mdev_ops = { From patchwork Fri Aug 16 09:01:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13765791 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2044.outbound.protection.outlook.com [40.107.92.44]) (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 2897B13D890; Fri, 16 Aug 2024 09:02:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798974; cv=fail; b=BeoqSVGVCJRoWdcA8rncQmqOAH2TxRhIZQjt/nhAMV2rqxs46wEoo6bpWiaM7FcDeIzaRg+NekQFRRuTJpRYWQPte6Dx2E263ehf4R1VtTFiFyBmTqyxkoiA1L9Xop9j33FLupnjGpaqTQC+K0c9fcYoNsCo6jD7vvvbefnBL2A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798974; c=relaxed/simple; bh=l0bbPXQ8k7HmEYHK+4He4JBPX18tCuibNuEJfC6I1kg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WSviC6pmny/A6W3WtHCxwBxCJqt0fkU6uOuefsubs518q0JMi7pe9oFxIyrF04NyH6L0jBjjvoqMoPYhwrXS+ZeAq5KozegghSKsEoQ2Wzlwi/4WEZv7gnFM5P8f00qOONS4Y2C2aMtdxaPXcq02iMPRL2brq+AoyQf56KE+aNE= 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=nrJNB2kF; arc=fail smtp.client-ip=40.107.92.44 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="nrJNB2kF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t1f+v4qxVvKL9u+CeTdlJI1TM7qTzWaaMEAQG4pmqUow3u2ErDSup9fiCD3I7zWY3fBDFul2i9PghZgVA5B9tvA0u1qsKUmj1UU5+QRKjXlmjJ72u/+6dAkou/xsOuzYCm1pAOAC6RPb4IwKRRibJfnoH1O3NAL2D81+fSvEEiDhd7g0twQFAuWNau/aEOKsGKlrB/RRKFtn2xVW8RokGJUFO+HC3aoA0HWWsq1LyHcf4cWFwAZ27M+MAxeqTVrvZ+PsGbAloG0MsuRq49ZZAHtZCy+TMXM0wpVVu/67P0kHSsUYqYoyRnCN4Cx+iik9Uv+2nPxpPaA4zK6o/zFqgA== 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=5o9TuZHTKch4YP+m39/zdLvLSSURuCjUWgDv/TqfOQc=; b=Cvc7Ct5JTzIWsfe2FXLoCsMIm+npKXKkHcdXK4K+MqjKz0ABI/4A50hMlut4DjMW7g0e7ClF7dpMED2mJ5sJEpSpxXF41Az0W7+tye6IJHgr8c5bix7L6HQR2rH36d8XczV0WmhVqHnAjffvPSlX4NFX1e1Q0NBeu2U2BbtdmbC/Kf4Y0PI+ogmzhYj8O0kr5Cfa71DHG2iGDxZv0BF17bkS/r9SoDAVnhHNKQ7oQZ5KxJW5mc+ZX0SqJ/LphhKhRbU4/0JGcLqw9Grqpfyg1xc0DQ8/7bViIxX39o/i5JIBWUh8MhfVdiDlsnbm/m7EL3Fg+5SpesuSALI0H2y7hw== 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=5o9TuZHTKch4YP+m39/zdLvLSSURuCjUWgDv/TqfOQc=; b=nrJNB2kFVluyjOqyJzNMbzaBdXqCp5AOrpHwJfXR1Fk4I4w9hZ4DP14sU/0GRucbfHjZpYNuL8DJIGdMZU8tuoqe61Fu9cWqrPReLkEnJQw7Mq7G99yxnFeLT3qoJnexuA32JRv31YJ7fvjWinFRXDphfkDRD5bnVqUMBe/D5gho+vBC7M8hOrnCYCvnAeyjKwYRIzNLtrv+2ZXMAHRstkRREKUsNIx+9WVk6yholPtG4ImU3QkePzf55hFriHch3g8TwfixKax1VNtXAzFmrCrs/4xOgJBlIQMJibYwy9eJAVf7lKUaAb5AclqDXsFKrON6xBzUG/r5xE0gg7RCEQ== Received: from BN9PR03CA0697.namprd03.prod.outlook.com (2603:10b6:408:ef::12) by LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.18; Fri, 16 Aug 2024 09:02:46 +0000 Received: from BN1PEPF00004688.namprd05.prod.outlook.com (2603:10b6:408:ef:cafe::44) by BN9PR03CA0697.outlook.office365.com (2603:10b6:408:ef::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.33 via Frontend Transport; Fri, 16 Aug 2024 09:02:46 +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 BN1PEPF00004688.mail.protection.outlook.com (10.167.243.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Fri, 16 Aug 2024 09:02:45 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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.1544.4; Fri, 16 Aug 2024 02:02:34 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 16 Aug 2024 02:02:32 -0700 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.1544.4 via Frontend Transport; Fri, 16 Aug 2024 02:02:29 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , CC: Dragos Tatulea , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Tariq Toukan Subject: [PATCH vhost v2 05/10] vdpa/mlx5: Use async API for vq modify commands Date: Fri, 16 Aug 2024 12:01:54 +0300 Message-ID: <20240816090159.1967650-6-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240816090159.1967650-1-dtatulea@nvidia.com> References: <20240816090159.1967650-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: BN1PEPF00004688:EE_|LV2PR12MB5869:EE_ X-MS-Office365-Filtering-Correlation-Id: 67a9ee0b-4e6b-494d-3a33-08dcbdd2321f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: ibE0rWlxvQOWymwVxfXYBld9iJOSOS3wl2XYjJU+eoP5MURFsUn6wgrjdnC2qqrJ6VszZdngYesTWXed/xEdXZReLwyxPT7b0RHln8a4BFBaZ0uoBHcsbTU98WmOoANufAUM3DT7OIYnPLsSLS1VdDQ5+20dcTXnjDi4IZdv6Dbnd4rvjNAzU32rGkd9B5aOikTBU+WlG/eUmXI7cUwwByj0C31g1Dx7LLUf4O+o/0UrWwsLkf+olr1C5zyqhw4bGFLnLbNq5O23f005Rl+OeFA5bnB4Wd0fuJMvoRxB8aY2lIObd9cQWYlvh9L/2qRVTGEJEw0fN9i3KKhtlsKzaNZs0c/stcf8uDkbFTSNfrRQK6aEV52HgGyeFWYBXAvUDboPCdEnij2D/Zm88EuTOU2dOwMLuAzfUodCf2X7mUzOrzICkDzcj+Pz2Czq7WfCUJPBMYW79pT99/A8+1MmgXoaADSL94ywNKGDybe3lbHQf1oASwjBr2ui9V/kMWPaHz0a7OU7nk4UxLr++Q37jtCkjSRMESxgaNq2NqO5yKP2skNQW7O+IldypA7HHKZkDwg/otYG6LPz82BSMTN7epf98VWeLCDAVjQVKAUtxJFeU82BhGhG4acP0/knsKPoaASeqG40DNVLbFRbVynx6mO1ysColtHgIa9H8XkYc2So88SnrFfrv8oF6hJr7wpS7qspQqnOY+qUl1rjnJqAXhQUqe52lM8++lLarQbjSjJDeNqJNMHeFQvx9JDINnD/x5khCu+Wrfl4Y+rNiqfml/QIEKRiZgO9lda7W7JYXp/gc6qSvxX8laIpxrXlTeYBbtTp71e21K4qSQ3UteuRIbkwfcTv1jqfV6hlC4gBXY/GmzK4EO0NopSX35tOCwZ8/iZK2tCgmbCRPLgnAsdOCOzbKEaYKTyv4I0cIu6gj2X05qzepVga0FCGkE/hr25bC5FblhLzzK0E/Ar7cI7LDfzU3Qiji17jciPz52ZcPXkEMuzqA6h0x9c88EMuA9+ERE0VjCA7WdOSkNSnDTb5OUtYOg/wO+onZDmzCzhmbAX8dCwFpZAsqDh9W7NNDhqC1AqsyqTQevkZ3en0v8GHtIC/wQ/C0WbSGhCh+Hvl7gjX9DgIwiGrkQONIlm7xABRbIC9vXPIRlaK8KTbUrhSBHQbi01e9VYHDVx7w8CJXeAWMmC3Dzq2OkmeP2uizhgYfTwuN/fmAfP+Kybt7UnmmjGf2Xcl8BAqIWrP3R8G0GwO8/+iUqWEp/kDCCw09BL/1dPypCU6/kEz8qD4eMzZ5A2EfDSw2EIf6kA+NhNWeAhVaJ6xui1JPa0T7BNvA8aXM588tfjEmyVu9Ycs00daEBZgUX89ysCXOe+fPqM4g7U+y76lMMAbf3ZVtpFh6bInJCGKBXqkrt63Z+GH2JqAyQW6hhs4phz2wpot5to1EkL1w/fJJn8q5pksAMtzlyHj 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:(13230040)(1800799024)(36860700013)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 09:02:45.9113 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 67a9ee0b-4e6b-494d-3a33-08dcbdd2321f 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: BN1PEPF00004688.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5869 Switch firmware vq modify command to be issued via the async API to allow future parallelization. The new refactored function applies the modify on a range of vqs and waits for their execution to complete. For now the command is still used in a serial fashion. A later patch will switch to modifying multiple vqs in parallel. Signed-off-by: Dragos Tatulea Reviewed-by: Tariq Toukan Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 154 ++++++++++++++++++++---------- 1 file changed, 106 insertions(+), 48 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 413b24398ef2..9be7a88d71a7 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1189,6 +1189,11 @@ struct mlx5_virtqueue_query_mem { u8 out[MLX5_ST_SZ_BYTES(query_virtio_net_q_out)]; }; +struct mlx5_virtqueue_modify_mem { + u8 in[MLX5_ST_SZ_BYTES(modify_virtio_net_q_in)]; + u8 out[MLX5_ST_SZ_BYTES(modify_virtio_net_q_out)]; +}; + static void fill_query_virtqueue_cmd(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq, struct mlx5_virtqueue_query_mem *cmd) @@ -1298,51 +1303,30 @@ static bool modifiable_virtqueue_fields(struct mlx5_vdpa_virtqueue *mvq) return true; } -static int modify_virtqueue(struct mlx5_vdpa_net *ndev, - struct mlx5_vdpa_virtqueue *mvq, - int state) +static void fill_modify_virtqueue_cmd(struct mlx5_vdpa_net *ndev, + struct mlx5_vdpa_virtqueue *mvq, + int state, + struct mlx5_virtqueue_modify_mem *cmd) { - 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; void *vq_ctx; - void *in; - int err; - - if (mvq->fw_state == MLX5_VIRTIO_NET_Q_OBJECT_NONE) - return 0; - - if (!modifiable_virtqueue_fields(mvq)) - return -EINVAL; - in = kzalloc(inlen, GFP_KERNEL); - if (!in) - return -ENOMEM; - - cmd_hdr = MLX5_ADDR_OF(modify_virtio_net_q_in, in, general_obj_in_cmd_hdr); + cmd_hdr = MLX5_ADDR_OF(modify_virtio_net_q_in, cmd->in, general_obj_in_cmd_hdr); MLX5_SET(general_obj_in_cmd_hdr, cmd_hdr, opcode, MLX5_CMD_OP_MODIFY_GENERAL_OBJECT); MLX5_SET(general_obj_in_cmd_hdr, cmd_hdr, obj_type, MLX5_OBJ_TYPE_VIRTIO_NET_Q); MLX5_SET(general_obj_in_cmd_hdr, cmd_hdr, obj_id, mvq->virtq_id); 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); + obj_context = MLX5_ADDR_OF(modify_virtio_net_q_in, cmd->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))) { - err = -EINVAL; - goto done; - } - + if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_STATE) MLX5_SET(virtio_net_q_object, obj_context, state, state); - state_change = true; - } if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_ADDRS) { MLX5_SET64(virtio_q, vq_ctx, desc_addr, mvq->desc_addr); @@ -1388,38 +1372,36 @@ static int modify_virtqueue(struct mlx5_vdpa_net *ndev, } 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) - goto done; +} - if (state_change) - mvq->fw_state = state; +static void modify_virtqueue_end(struct mlx5_vdpa_net *ndev, + struct mlx5_vdpa_virtqueue *mvq, + int state) +{ + struct mlx5_vdpa_dev *mvdev = &ndev->mvdev; if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY) { + unsigned int asid = mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]; + struct mlx5_vdpa_mr *vq_mr = mvdev->mr[asid]; + 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) { + unsigned int asid = mvdev->group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]; + struct mlx5_vdpa_mr *desc_mr = mvdev->mr[asid]; + 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: - kfree(in); - return err; -} + if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_STATE) + mvq->fw_state = state; -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); + mvq->modified_fields = 0; } static int counter_set_alloc(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) @@ -1572,6 +1554,82 @@ static int setup_vq(struct mlx5_vdpa_net *ndev, return err; } +static int modify_virtqueues(struct mlx5_vdpa_net *ndev, int start_vq, int num_vqs, int state) +{ + struct mlx5_vdpa_dev *mvdev = &ndev->mvdev; + struct mlx5_virtqueue_modify_mem *cmd_mem; + struct mlx5_vdpa_async_cmd *cmds; + int err = 0; + + WARN(start_vq + num_vqs > mvdev->max_vqs, "modify vq range invalid [%d, %d), max_vqs: %u\n", + start_vq, start_vq + num_vqs, mvdev->max_vqs); + + cmds = kvcalloc(num_vqs, sizeof(*cmds), GFP_KERNEL); + cmd_mem = kvcalloc(num_vqs, sizeof(*cmd_mem), GFP_KERNEL); + if (!cmds || !cmd_mem) { + err = -ENOMEM; + goto done; + } + + for (int i = 0; i < num_vqs; i++) { + struct mlx5_vdpa_async_cmd *cmd = &cmds[i]; + struct mlx5_vdpa_virtqueue *mvq; + int vq_idx = start_vq + i; + + mvq = &ndev->vqs[vq_idx]; + + if (!modifiable_virtqueue_fields(mvq)) { + err = -EINVAL; + goto done; + } + + if (mvq->fw_state != state) { + if (!is_valid_state_change(mvq->fw_state, state, is_resumable(ndev))) { + err = -EINVAL; + goto done; + } + + mvq->modified_fields |= MLX5_VIRTQ_MODIFY_MASK_STATE; + } + + cmd->in = &cmd_mem[i].in; + cmd->inlen = sizeof(cmd_mem[i].in); + cmd->out = &cmd_mem[i].out; + cmd->outlen = sizeof(cmd_mem[i].out); + fill_modify_virtqueue_cmd(ndev, mvq, state, &cmd_mem[i]); + } + + err = mlx5_vdpa_exec_async_cmds(&ndev->mvdev, cmds, num_vqs); + if (err) { + mlx5_vdpa_err(mvdev, "error issuing modify cmd for vq range [%d, %d)\n", + start_vq, start_vq + num_vqs); + goto done; + } + + for (int i = 0; i < num_vqs; i++) { + struct mlx5_vdpa_async_cmd *cmd = &cmds[i]; + struct mlx5_vdpa_virtqueue *mvq; + int vq_idx = start_vq + i; + + mvq = &ndev->vqs[vq_idx]; + + if (cmd->err) { + mlx5_vdpa_err(mvdev, "modify vq %d failed, state: %d -> %d, err: %d\n", + vq_idx, mvq->fw_state, state, err); + if (!err) + err = cmd->err; + continue; + } + + modify_virtqueue_end(ndev, mvq, state); + } + +done: + kvfree(cmd_mem); + kvfree(cmds); + return err; +} + static int suspend_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) { struct mlx5_virtq_attr attr; @@ -1583,7 +1641,7 @@ static int suspend_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mv if (mvq->fw_state != MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY) return 0; - err = modify_virtqueue_state(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND); + err = modify_virtqueues(ndev, mvq->index, 1, MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND); if (err) { mlx5_vdpa_err(&ndev->mvdev, "modify to suspend failed, err: %d\n", err); return err; @@ -1630,7 +1688,7 @@ static int resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq /* Due to a FW quirk we need to modify the VQ fields first then change state. * This should be fixed soon. After that, a single command can be used. */ - err = modify_virtqueue(ndev, mvq, 0); + err = modify_virtqueues(ndev, mvq->index, 1, mvq->fw_state); if (err) { mlx5_vdpa_err(&ndev->mvdev, "modify vq properties failed for vq %u, err: %d\n", @@ -1652,7 +1710,7 @@ static int resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq return -EINVAL; } - err = modify_virtqueue_state(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY); + err = modify_virtqueues(ndev, mvq->index, 1, MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY); if (err) mlx5_vdpa_err(&ndev->mvdev, "modify to resume failed for vq %u, err: %d\n", mvq->index, err); From patchwork Fri Aug 16 09:01:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13765792 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2056.outbound.protection.outlook.com [40.107.95.56]) (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 91816146000; Fri, 16 Aug 2024 09:02:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798975; cv=fail; b=HN8TVVXAaUKZTx6hKzozmlWN56MGRNdnzmRG6Mlm2YaTAHhVpy0iQ0b+ykPi70MIu7iwOVHCg2Z5VKUMhogYZx0bolm0x8ztdnaZaLjkv/Dh8lK41uB/UGiG7RPckYxCKUDos6VpMmFmU/8/nBeKPCRV9zieDBZGGXFbp8NXGNk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798975; c=relaxed/simple; bh=1IZTLS6EWIllixTdyxPdXYqBRm1eXn4pXBNiyA/ISqo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hu0mPkFTNBOlz0rZTGWAhlTvRcnX21XE4R6+c3Bp+6hDKqz9ZEshTiGhYYa1UgAkdugIU6F+SoapjKb8STCrSQvyCAP+4wAGSMdqmjz8cd2eFxm5xZ0ukDB6aWdESpEBoStvBXA3TvJvLlMGeatLTugJeXqu6xnORCpCgnZK/1Q= 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=KtPVMRf+; arc=fail smtp.client-ip=40.107.95.56 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="KtPVMRf+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WU01ZR4pCln/ydfa9IRsP2V92AyPZdRAxuEZXy0lOmb67O7L/JHfODFDG9wiBbdpICoKYhtLHvWAz8HmKoEKnhf3wPQW8S9Wl2cez6fAarbpoPxRxmrfohJRf/uOlyZFM5Fk0h9dL6f/8Vny2pW32C7xOrc0l21DlDtMEfQy4l7gqtk9EO/ISNzWfwvDK0RsCShYxkcZhkpGKIDUx7bGbDXue8Ndmb03ZHztx69213jYoUF9Va+r8gDYVOPUR8EM4dGKieVEp8S3V7Yo3pMcARMsNNR2Z9zBjv9kfPNlr55BE/fCaf6BxBY073lB+DZ43S4E8QpTkdCcPJv16IsNbw== 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=VIAJplQdvJEqiwsRH2lFpllSxV45XeFNw1hDiZBrKFE=; b=C1vlCiyMnZthPocRR4Q7Rk2pXncu0O5IfJckXnDoXLY2n6uSXhmsWa9UxzZiR9Z45tihki4yjccJ8EO++lVe+TVtCG4I6j71mxUeP49MMWrZawhQK8BDYirobVJm7Q1ZyghjiJsofEgmY161huVJMY/KZMDQRjVcGzD2bDgzX118/Bd3wNwSU2SX47bGphLXr73JIX9bfC1Ejj0Q+izRUIy/TujUVL4G/nQzthOm1IIhdG4nBvSl+nayBcH7LCzHgjieM0oX4/rAJQVm5fzIDzaO8YGI+EUHnyO47rF5Hn/+reC/H9h/1+N0vrPaTpvwBZ01qCSTj4OCFa8JdU1bkw== 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=VIAJplQdvJEqiwsRH2lFpllSxV45XeFNw1hDiZBrKFE=; b=KtPVMRf+GPcYOA+omu0HFSuWiBaZCKLjwrVCnTgN52GmkCHQct3zl8+dq+kqyXSIH1VvCE5jhGQjYhxAW/5CCgb8dB+E3phAKKmvl8c4p5Z4tNhheVbodRExIpx3O35BdB6wJKm+Gfgdh2bm6ABZkxiK7P84syFNWydoZreMuTKb5T6ngLr2bW5BsdsszwZairNMVwE1CsUvjZGjGR5NAKqN/XSXzWD2bz8rGJHY82Vr5vpwCtvBdY80r77v3Os9urb2cRh+XiOEajd2MA5NXzHamMkhF9M3fmW067/LjgS7tDxHWmiUxbw+uXqFykmYlDLjqVUIMMUrh9UT9o7ROg== Received: from BN9PR03CA0701.namprd03.prod.outlook.com (2603:10b6:408:ef::16) by MW6PR12MB8900.namprd12.prod.outlook.com (2603:10b6:303:244::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.19; Fri, 16 Aug 2024 09:02:50 +0000 Received: from BN1PEPF00004688.namprd05.prod.outlook.com (2603:10b6:408:ef:cafe::af) by BN9PR03CA0701.outlook.office365.com (2603:10b6:408:ef::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.33 via Frontend Transport; Fri, 16 Aug 2024 09:02:50 +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 BN1PEPF00004688.mail.protection.outlook.com (10.167.243.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Fri, 16 Aug 2024 09:02:50 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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.1544.4; Fri, 16 Aug 2024 02:02:37 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 16 Aug 2024 02:02:36 -0700 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.1544.4 via Frontend Transport; Fri, 16 Aug 2024 02:02:33 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , CC: Dragos Tatulea , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Tariq Toukan Subject: [PATCH vhost v2 06/10] vdpa/mlx5: Parallelize device suspend Date: Fri, 16 Aug 2024 12:01:55 +0300 Message-ID: <20240816090159.1967650-7-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240816090159.1967650-1-dtatulea@nvidia.com> References: <20240816090159.1967650-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: BN1PEPF00004688:EE_|MW6PR12MB8900:EE_ X-MS-Office365-Filtering-Correlation-Id: 1aece55c-94fd-42ab-a74a-08dcbdd23494 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: =?utf-8?q?JM5qZ9Fi9fd4ljAR8GzZFI82Cfg5oOu?= =?utf-8?q?ovHrH7SLgpKN5ENZKrsJtzBlk+vuc9NYGnnNPbwqNCtGjC8IBMO8jpC4m6SG8wnT8?= =?utf-8?q?jItrUm+cFuccr6VmRAh8niOxJ525w012mtpeqPwcLIbWQjIisa6Ej2JHhkKbwNGhw?= =?utf-8?q?nPyCkwKmvV4wwJzdAB6Voeiix/gUEMYbt7uBGzibF5DPVUgMHUwmSHqOoIJ31+EX4?= =?utf-8?q?YosNJ/Z9OfW76lAxklp4oN3PUN6TgBhltcSk7lHhiktwUUvzQ37e+McOsZlUXoE/8?= =?utf-8?q?neworWU/S1wri6L+jLVezf/Ue7ZPRIj9gOP80Apn7JAib4QWZHSuP2DqowmDZohnW?= =?utf-8?q?qz+zd6zqUd14F+3UifedNT5Vg5FI8mi9d4VEToOUsQm5SV02cVus7upAAa0KP3PzH?= =?utf-8?q?mT08J0ctiAWcgjFlppTI3wF6qJZX9vQds2wL52BhiHqhtUX5EhsZwWPCeHnK2jRGJ?= =?utf-8?q?Qz+wMu2qpG3l/OqipLghK2Rp6N9bWoNoDYrLTO6LEJjivMehyC48hWAG9D0ft3Y+W?= =?utf-8?q?cSF9rL5AdtjuUfDyGWdd77aEefKCTcvV3pDXua9GiBQPfGtwSI6BnQ3e4Et2F1qOQ?= =?utf-8?q?hcHlhm1a+jWGZNO/plJjD0i5Qov6lOj08atlp/zHgxS8Buillzkh2PRa1KluWERrx?= =?utf-8?q?RjNt8999US4EcDw17ovtYrYyGiIBAhtYB4vbxv3hGPRxmaGxzsyYmqLjUtqWh5TLM?= =?utf-8?q?cwIKj+gw5Hh9IR8uHyIt2D06rxuj++JLZSd0OWL6FQBbCs/QeAwTPjqgGJXlbcB5q?= =?utf-8?q?qw2X9qlK0hqYESqctLCDPbeTCZlL70AxY0MNI2iuq7P4OsNJONJmx756YyiuaVobT?= =?utf-8?q?ymiLwnOpmPknEgVW47uRP9fxpMX7h8pudPqhL6DIOMbv+GMOJpANclleQLLtnlQz8?= =?utf-8?q?EmWkjSl3GH+jVQIV/HmGcilKqAFeCyglkPXhdx3JM0bSyHG8MohHbi90ZtUNy5YLV?= =?utf-8?q?iixD8J2KxttCPn9/DIB1+NuCyw/normh9K89oRoAQ0LTja9FEpYYCfNIvUF2E2bus?= =?utf-8?q?xI4O8ZWlKlHl7J0H+T8lfRONns7+2d3DSTV92H2ktKJ9w3g+wVS65BTD2NHxDHnO2?= =?utf-8?q?Hv9qCmCt1TAbtFzcEkp6PSPzhbGOJpBtVa9lYIxJJ1QK0+anwSTjpOViBdq5m4aGR?= =?utf-8?q?S3bzgA+rdUf2LNsjBc5/NW0vuU7sVKfdPnzJNWp/qsVy6xXE31RVVK8af8UojMQqC?= =?utf-8?q?PetPJtrBjX7VIrPC/dgqLfQneFiQz0DagGD9Kp2+7efTVuFqxpBSxUBVydcdCEeM2?= =?utf-8?q?gSUsgdY2ZSZhWPDjlYJ9ldV3T30HX2dX4yOgncTMeIqmnUZOQf/mj0xtzY7KqQcps?= =?utf-8?q?k2KkHXgwnP2OklBdkkhWHwbAl/r9brc2PGC5rRM1HCJy4CpDE4/17PukMLXVklgRv?= =?utf-8?q?AHOm2RMO056?= 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:(13230040)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 09:02:50.0206 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1aece55c-94fd-42ab-a74a-08dcbdd23494 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: BN1PEPF00004688.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8900 Currently device suspend works on vqs serially. Building up on previous changes that converted vq operations to the async api, this patch parallelizes the device suspend: 1) Suspend all active vqs parallel. 2) Query suspended vqs in parallel. For 1 vDPA device x 32 VQs (16 VQPs) attached to a large VM (256 GB RAM, 32 CPUs x 2 threads per core), the device suspend time is reduced from ~37 ms to ~13 ms. A later patch will remove the link unregister operation which will make it even faster. Signed-off-by: Dragos Tatulea Reviewed-by: Tariq Toukan Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 56 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 9be7a88d71a7..5fba16c80dbb 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1630,49 +1630,51 @@ static int modify_virtqueues(struct mlx5_vdpa_net *ndev, int start_vq, int num_v return err; } -static int suspend_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) +static int suspend_vqs(struct mlx5_vdpa_net *ndev, int start_vq, int num_vqs) { - struct mlx5_virtq_attr attr; + struct mlx5_vdpa_virtqueue *mvq; + struct mlx5_virtq_attr *attrs; + int vq_idx, i; int err; + if (start_vq >= ndev->cur_num_vqs) + return -EINVAL; + + mvq = &ndev->vqs[start_vq]; if (!mvq->initialized) return 0; if (mvq->fw_state != MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY) return 0; - err = modify_virtqueues(ndev, mvq->index, 1, MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND); - if (err) { - mlx5_vdpa_err(&ndev->mvdev, "modify to suspend failed, err: %d\n", err); - return err; - } - - err = query_virtqueues(ndev, mvq->index, 1, &attr); - if (err) { - mlx5_vdpa_err(&ndev->mvdev, "failed to query virtqueue, err: %d\n", err); + err = modify_virtqueues(ndev, start_vq, num_vqs, MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND); + if (err) return err; - } - - mvq->avail_idx = attr.available_index; - mvq->used_idx = attr.used_index; - - return 0; -} -static int suspend_vqs(struct mlx5_vdpa_net *ndev) -{ - int err = 0; - int i; + attrs = kcalloc(num_vqs, sizeof(struct mlx5_virtq_attr), GFP_KERNEL); + if (!attrs) + return -ENOMEM; - for (i = 0; i < ndev->cur_num_vqs; i++) { - int local_err = suspend_vq(ndev, &ndev->vqs[i]); + err = query_virtqueues(ndev, start_vq, num_vqs, attrs); + if (err) + goto done; - err = local_err ? local_err : err; + for (i = 0, vq_idx = start_vq; i < num_vqs; i++, vq_idx++) { + mvq = &ndev->vqs[vq_idx]; + mvq->avail_idx = attrs[i].available_index; + mvq->used_idx = attrs[i].used_index; } +done: + kfree(attrs); return err; } +static int suspend_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) +{ + return suspend_vqs(ndev, mvq->index, 1); +} + static int resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) { int err; @@ -3053,7 +3055,7 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev, bool teardown = !is_resumable(ndev); int err; - suspend_vqs(ndev); + suspend_vqs(ndev, 0, ndev->cur_num_vqs); if (teardown) { err = save_channels_info(ndev); if (err) @@ -3606,7 +3608,7 @@ static int mlx5_vdpa_suspend(struct vdpa_device *vdev) down_write(&ndev->reslock); unregister_link_notifier(ndev); - err = suspend_vqs(ndev); + err = suspend_vqs(ndev, 0, ndev->cur_num_vqs); mlx5_vdpa_cvq_suspend(mvdev); mvdev->suspended = true; up_write(&ndev->reslock); From patchwork Fri Aug 16 09:01:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13765793 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2072.outbound.protection.outlook.com [40.107.220.72]) (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 A858014C59A; Fri, 16 Aug 2024 09:03:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798983; cv=fail; b=gdOuubGt5itKggvgwGbokbv1VYDM8FCkYU/zhTq7K/STUbcBRAjfIONwifn8GgtSG4VU8chw3++4Ux0Tssp0iHVGcmrPQlcDYXg/+WbaHbugqXJQSKQeEZ5T/HorTWAs2wvm9na0ZNPE4PmLJgpGc0F6uTfFaRgMYq8u4Yv4NoI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798983; c=relaxed/simple; bh=AaojRqciGzZpgysJ+0AjGAE5jNukjY3I6kZx9XT/QlA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Hnj1ZSxZDXCFUm/8MhoROtVqlKJ7vxjCRFF0cjfh8oY9TVS0zgmSVmJjLAZujR4XcIO0J49MX/TS08fNvLxgAaaY24wx5tbB8oLKSs9x6c3i7AIWMKYJhcSgVKkbsU6BoVq7nz0JM5C7FbsOLs2vyropp9A1esAVVKdAWzkOtrk= 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=Io5KtwpY; arc=fail smtp.client-ip=40.107.220.72 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="Io5KtwpY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CUp1R9RztHXIRxCmBdbnnstwWkDffQmD+9PX3WusZ0GBP8PDps9Yvnu+n2u2yeGzUW4sdD2dy70AHhDGP3TJ5f7zQBnnroQPaqiq8IagYSIy9TWcli5feJaQhYTKUqudXiFBiJkh+tpFmNL4phthG5EewefCDsLsuBUp/ZedQs6OhOj0xpgZvkUELvKoiwwd990rBzL5h/sqQUbi0/uHXmo9Od8xTLvYVX16S1m22/3+01bCkeZDXDe2evsPfsl4R83Bgizi9mVLs0u9/DT1o1DawIUxkBUe828euOUFceiJIq8Kt/F6EaN7FcxBT8U0AsmMEsvmsVw8C1P+sylmZw== 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=9/WRppdg9XWVo0cpx8Hq1bCb18U/qC407LW87OYi+Js=; b=hiPxwZSoeA2+pfMoJE+Ao4EB35fhOkCfX0PxdIBHdSB0AGWv+ZI4ldY3nZocFiqE6Ht7fLb7kbbjEjRLYDe1zTXFRjF0tLzr5BQlcjq3IFh4CJHc0FJzfSq9DhxbSh4p0bwzZFkSU+2El3VwPO404mh+WSCoaiH/fRLw36aY1wo9TTyyr6OsZ6Z2yKYF+8xy24raaW+esA+1Q32lSo560UfEFw4efBwqsF7swBNxMRPcH01ZEJm9Sz/wLkY2AMR9oS0v1WSb2O6bXLzjFT+fiXCh8r/9u9BvAsuW1HzbnSipX7DPvKm0qPDpYGmotTBT9gKXN0qjWeWQJcdLFtEI6g== 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=9/WRppdg9XWVo0cpx8Hq1bCb18U/qC407LW87OYi+Js=; b=Io5KtwpYnqOpydlz40nwhNeVEqzmkO502P+0wVv3AtveyxoPBmyHyTSkGW6G8sZ18WQnuCVZfZfQ+ki1KMUpQ6YS0cUY0LOkEO/vq7BKW5eM+oU4oAv/y3vggd0RtOzDuakPRhp1efkokoaYVzG3RVK1uBpAO0dURguOWaf+oylZxHit+0fyCtCKZfBJoENt9FB1wR0sf/3SjI8P9E/fXUKilMejeC7T8Y1OZL+HhOODLTcR+xKwiyfC/2wLMlSEythLVh2zsbFXJEPXaH4ZkYknAQQlsBlQZYzHPV4Ze8SwTMqUTZu0Z/DSvgpEJVuO2OwZDvzLbnX102Th9nzHpg== Received: from BN0PR04CA0110.namprd04.prod.outlook.com (2603:10b6:408:ec::25) by PH0PR12MB7983.namprd12.prod.outlook.com (2603:10b6:510:28e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.19; Fri, 16 Aug 2024 09:02:54 +0000 Received: from BN1PEPF0000468E.namprd05.prod.outlook.com (2603:10b6:408:ec:cafe::43) by BN0PR04CA0110.outlook.office365.com (2603:10b6:408:ec::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.23 via Frontend Transport; Fri, 16 Aug 2024 09:02:54 +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 BN1PEPF0000468E.mail.protection.outlook.com (10.167.243.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Fri, 16 Aug 2024 09:02:53 +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.1544.4; Fri, 16 Aug 2024 02:02:41 -0700 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.1544.4; Fri, 16 Aug 2024 02:02:41 -0700 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.1544.4 via Frontend Transport; Fri, 16 Aug 2024 02:02:37 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , CC: Dragos Tatulea , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Tariq Toukan Subject: [PATCH vhost v2 07/10] vdpa/mlx5: Parallelize device resume Date: Fri, 16 Aug 2024 12:01:56 +0300 Message-ID: <20240816090159.1967650-8-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240816090159.1967650-1-dtatulea@nvidia.com> References: <20240816090159.1967650-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: BN1PEPF0000468E:EE_|PH0PR12MB7983:EE_ X-MS-Office365-Filtering-Correlation-Id: eb613aad-8205-4caa-f76c-08dcbdd236e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?mYMLUyfO092pEbK7hPhch3fPTcIRoEK?= =?utf-8?q?ARiQZ8McFfEuLluHB/7msf5Hbzlm2dcFjvjFXfCKSiMx+H9hkX7i3M2ijTs8cKg6z?= =?utf-8?q?utcVZ0R3MnXhU6kzPxPbrrlaidbwdcgAD04bmNhEqz61a0FVr8Acw+DyWwmi9xcTG?= =?utf-8?q?jAyHvHbwqzjKPTFGgbNl0qga/Zigw+OIHEp0hU73csRMMALD3fj0bJpmgrTBUrIsQ?= =?utf-8?q?f3d7aaiiVboqqm//bHF3/xyzW0sc8FpNhsSI7ETy9xdAcYZbO87tDncIrsOht/cLa?= =?utf-8?q?pX3Y4fyitT2pakO8gE2ACkCWiPqCZFLQAG9pilcjzYupjBQa4Ab9YFO7OrCcK1dEm?= =?utf-8?q?wFiRespvTTrahlsso87Y+V2l0FEsXEWffvrEuEcPxCYdK6aZg852UQ9MVm8+H6muI?= =?utf-8?q?Vav6faJB3OOYigj7Uh9D4CkypxPkM43fcqzP3dBkpz41S3A0RKpgXR8vIt/wm1B9v?= =?utf-8?q?t9/wmpMVDsWgoz3oA41MAYc8tmV/W83EmhXu3v48iVyw5W8qyIivl24AJv35WqTLb?= =?utf-8?q?raxRratGVa4Q4MrF0S3AVhTeATNQbX9/vKdfqWexccGQCzuSq7NJZNGeSzC6KP+9/?= =?utf-8?q?anE+Dmg0xppCiSZBrClKNPzbgKxcHj7KqXQHi/UkLCwiMfaqSltJrKU4wYJoWwCaX?= =?utf-8?q?Fig+oZ5HizMAH8cyGdNAHRfswxJrVBg9PhdzOnet+kKQBF+/0lDyGg3P0ZrYQfGQ+?= =?utf-8?q?YT7eaYbYEdc87V3JDZfrv8RGtaGsbLa49WGuLV+u8yGWRtUJWMlEnygxMw4nRrTBV?= =?utf-8?q?lK5kHNyViqE0eiUpYNYHXLqfZwpk08GKYEg5ChhG05kC4rU9NSlJi/qlUnHh2Z4es?= =?utf-8?q?uhSyPFURA78nCcwubEjv0/t9HuzLzTluyY4a80vMIcK4txVDX25zYGNaXUqNGUi59?= =?utf-8?q?q0no/eOITxtHbUdYf8hqo3PBB+43LrsT5gy/YsJEyuDGpaQgeMMrEa3lrwc/fk7AH?= =?utf-8?q?l1Uhncl/8o9KfqmqUE2hKRMD8RasE3mXcZ0UL7J4drqvKJQd7IdjooweXbJr/R4iY?= =?utf-8?q?kEiTW5nRS7pKQ/pnoK/EyRbMRMsJG35QJ0F+eMyZzO5PRz00vQDRWdqGRQmHd5M84?= =?utf-8?q?zZ+Vyn3U2mBGcUwoaq+NlR/lCmvL8XkcHcyKO1womGAJCbUykaB/lN8MI8+YH5myA?= =?utf-8?q?bvX0KInEOQBK5PecXsagAxICr9QauOtZ8NaNT0FA1dVTkcoIOIZqxt2rphE3kH2H1?= =?utf-8?q?xZuyiuLFzhJ+MubKO3l9cBucgXwphj39NucBSAEk9ayYjO3cPeQRVBkndhGjz7AC7?= =?utf-8?q?0KfCAf45lKx/CzoX+4AyYS35VBdH61oMuNvqDRynRKV9OkwE9mmSY0XBPDO74qBEp?= =?utf-8?q?bHQNsi3seAKITMAOWs8UP0vA4v/hoY+LMcKHutD8+N7MEeXI+GLhdIVdCVc+VdPg2?= =?utf-8?q?qBviExwEXcW?= 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:(13230040)(1800799024)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 09:02:53.8828 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eb613aad-8205-4caa-f76c-08dcbdd236e1 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: BN1PEPF0000468E.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7983 Currently device resume works on vqs serially. Building up on previous changes that converted vq operations to the async api, this patch parallelizes the device resume. For 1 vDPA device x 32 VQs (16 VQPs) attached to a large VM (256 GB RAM, 32 CPUs x 2 threads per core), the device resume time is reduced from ~16 ms to ~4.5 ms. Signed-off-by: Dragos Tatulea Reviewed-by: Tariq Toukan Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 40 +++++++++++-------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 5fba16c80dbb..0773bec917be 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1675,10 +1675,15 @@ static int suspend_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mv return suspend_vqs(ndev, mvq->index, 1); } -static int resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) +static int resume_vqs(struct mlx5_vdpa_net *ndev, int start_vq, int num_vqs) { + struct mlx5_vdpa_virtqueue *mvq; int err; + if (start_vq >= ndev->mvdev.max_vqs) + return -EINVAL; + + mvq = &ndev->vqs[start_vq]; if (!mvq->initialized) return 0; @@ -1690,13 +1695,9 @@ static int resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq /* Due to a FW quirk we need to modify the VQ fields first then change state. * This should be fixed soon. After that, a single command can be used. */ - err = modify_virtqueues(ndev, mvq->index, 1, mvq->fw_state); - if (err) { - mlx5_vdpa_err(&ndev->mvdev, - "modify vq properties failed for vq %u, err: %d\n", - mvq->index, err); + err = modify_virtqueues(ndev, start_vq, num_vqs, mvq->fw_state); + if (err) return err; - } break; case MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND: if (!is_resumable(ndev)) { @@ -1712,25 +1713,12 @@ static int resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq return -EINVAL; } - err = modify_virtqueues(ndev, mvq->index, 1, MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY); - if (err) - mlx5_vdpa_err(&ndev->mvdev, "modify to resume failed for vq %u, err: %d\n", - mvq->index, err); - - return err; + return modify_virtqueues(ndev, start_vq, num_vqs, MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY); } -static int resume_vqs(struct mlx5_vdpa_net *ndev) +static int resume_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) { - int err = 0; - - for (int i = 0; i < ndev->cur_num_vqs; i++) { - int local_err = resume_vq(ndev, &ndev->vqs[i]); - - err = local_err ? local_err : err; - } - - return err; + return resume_vqs(ndev, mvq->index, 1); } static void teardown_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *mvq) @@ -3080,7 +3068,7 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev, return err; } - resume_vqs(ndev); + resume_vqs(ndev, 0, ndev->cur_num_vqs); return 0; } @@ -3204,7 +3192,7 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status) teardown_vq_resources(ndev); if (ndev->setup) { - err = resume_vqs(ndev); + err = resume_vqs(ndev, 0, ndev->cur_num_vqs); if (err) { mlx5_vdpa_warn(mvdev, "failed to resume VQs\n"); goto err_driver; @@ -3628,7 +3616,7 @@ static int mlx5_vdpa_resume(struct vdpa_device *vdev) down_write(&ndev->reslock); mvdev->suspended = false; - err = resume_vqs(ndev); + err = resume_vqs(ndev, 0, ndev->cur_num_vqs); register_link_notifier(ndev); up_write(&ndev->reslock); From patchwork Fri Aug 16 09:01:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13765794 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2060.outbound.protection.outlook.com [40.107.92.60]) (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 C875E13DBBC; Fri, 16 Aug 2024 09:03:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798985; cv=fail; b=EJt3SJM0s1LLudtX27NSvico+gP8bLnet8r1jjPRCOoFavO/TnbzvEK36sBuo/lTGqfqLZQKZAl6zqeul/Pcnr7ZdwqVJ8h7kT61OB4aLqtkfhRLoQA1/p2ZzwcibR9YEfwNiro75oIpY52t7Apxw4llbUfSLPgrQwXHoTymjf0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798985; c=relaxed/simple; bh=OU8XVr7W1x9AxBwFcPSy7J1EHxdyso+fzfxQs6OSfgk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NXhqEkDrwu3CPPXLDjiNEmgVenZ9i5UTlywP6I5iBah0jgg/QFfJnbM4P2ZtaYM41/x2wsz83Q3Lx+JABoZVJCVXlREoCbVr+LkzBEpRt/5SuQ89pqhXxTM+7CvhA6ec0AAkITigo5zB8Jmu/2D14XtkeMW38F7sPQlBKA2q0m8= 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=fwiMMHjP; arc=fail smtp.client-ip=40.107.92.60 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="fwiMMHjP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=op/uVxggXG0adf75UreguWOXs0PZAYYnFQaRjn7LIaYxieH2IQ24SDlyky3mD5JWUmOQccAnOY0XuVBiW0JieR64FPZYIENqrnDdKhLcp2bVEobFBMTT/VD7aVW/3tvf6/nkemYUgY+Bk9P4i050f71vj3+s16PvM+ZYCZ6ctGvXWK7l6zJmkcW3qRCChk1Z5MhY9HMOaX68Sgg066BHFbNDcP8o471PL4aylxIStSa79jTCXENM8B9tDzFhIAGZ2w0YS8I3a5HJqBoJ880MVlAMvUfQ18tteKk6QJeCEt+XDJ3jqtzHB0w4v8KuaMy7moOzsaxWKPUonPtEsaiAgg== 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=TxCNbitpCqlU9s8TkazghQcJ1NdNMSLTLk9+3PbE+eQ=; b=rgCx9fKOtXtSzsaBZBQQQ+0W0gUEtfiq3UNjmYxWN7/Znb39nkiZ3xJcTLuT2mQtngx6YKrP+9NOtvcY+WZBYu/1/UOLOeFJExxNEETxo917pFn56X3PUOsN4Kw51wfjMdRwZvoyD4JNBiso7VIFRlvunoa9AycFUG/BucEtqYq4X+XG/Gho7pJE6GE94FDRcDmSZGtvSiZ3zetDyxAjZL3qcZLfTZJAv3sUZNiz/rXW2uJgQZGyoKBV/BTgxkIcRABtcQhT+9X/blsqrBBCimuIGkfbZyrw6mwM4jyJXN9ygJ5Qc3xDxebGchQXxtfH6c5GbZqs9cnyNllObb5sqQ== 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=TxCNbitpCqlU9s8TkazghQcJ1NdNMSLTLk9+3PbE+eQ=; b=fwiMMHjPiy+qieTZvoIY2lNctdf26vLxlOqEO5qBPsetMJqatn9xeMqOwa4HM5AN2NNeTCmZkI+S0viCjfkAoG90+ZbnzwiXoHKO/5Err9uyz/lxvTIhibvtwXF8VvcZZsc2J+ABcHwZDaV2Tqji9f5AkBpQ06bP/+ZnUurzwLCh0lafh/D/+KZ5ygp3sAbdIpYvnBoFIx91k4PNbRMOsELXnQ4MzJcvtKCZSgioP+0iXxusxFdExjZ4wj8RCB1QyhkMo6M1Tt+9G+nMOWhBZ7WdU4FMqy5ybOV2gTzltwA6bCVx9NXAxgn8o6sJs9zNDaN1TE4WIGgvjm/5XOdbyQ== Received: from CH3P220CA0018.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1e8::24) by SN7PR12MB6888.namprd12.prod.outlook.com (2603:10b6:806:260::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.18; Fri, 16 Aug 2024 09:02:58 +0000 Received: from CH3PEPF00000011.namprd21.prod.outlook.com (2603:10b6:610:1e8:cafe::6e) by CH3P220CA0018.outlook.office365.com (2603:10b6:610:1e8::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.19 via Frontend Transport; Fri, 16 Aug 2024 09:02:58 +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 CH3PEPF00000011.mail.protection.outlook.com (10.167.244.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.4 via Frontend Transport; Fri, 16 Aug 2024 09:02:57 +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.1544.4; Fri, 16 Aug 2024 02:02:45 -0700 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.1544.4; Fri, 16 Aug 2024 02:02:45 -0700 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.1544.4 via Frontend Transport; Fri, 16 Aug 2024 02:02:41 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , CC: Dragos Tatulea , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Tariq Toukan Subject: [PATCH vhost v2 08/10] vdpa/mlx5: Keep notifiers during suspend but ignore Date: Fri, 16 Aug 2024 12:01:57 +0300 Message-ID: <20240816090159.1967650-9-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240816090159.1967650-1-dtatulea@nvidia.com> References: <20240816090159.1967650-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: CH3PEPF00000011:EE_|SN7PR12MB6888:EE_ X-MS-Office365-Filtering-Correlation-Id: 7978d7b4-8e93-49b7-4d7a-08dcbdd23942 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?H1kzvGR2Ln67O3IKaVufqx7/mAMCvQw?= =?utf-8?q?DuFqKthysJQ8xegZ45+U1VX1Wq4oBvQDkKg5kULWxPqQ65KSkgGEsbyFnOTxjVpj8?= =?utf-8?q?T0sKbQBuMq3mhfWlfW283Jwmr/vMWA6BX6aP81JhbNxF6/X19n0MxP59MjZbRvTve?= =?utf-8?q?ZM5CHB9He/FA5b/UsoEMm8vqS7P0Bj5J+qYSsgLNOK2U6A4XREDDkAdil5NWKq8vQ?= =?utf-8?q?y7fjSQtMAKmWi3nIgsWHD1Xk61mQqUuqLChJ5q+gADNH18YKZ0L5TNh9xe/y6ycjO?= =?utf-8?q?oWZ2KKa/pinR4LhC4HJGNhhC34xl0tkP78LvURA0CD8LUyNkHX2+gXAT/rQenAELO?= =?utf-8?q?kfmIbLpJrIlZGaQXStr8Lrbqc8Mc4Eo5te/oZ3vYQFE+E3LaDYoViTg5m7gX8eWZe?= =?utf-8?q?JAkf3qY4oFHcJjqSzuywkM10oyMvYtL58PE190RIi9461oqG2dkLE1/eyrym1fU0V?= =?utf-8?q?OZ21XHwiLJW+yNbAzudrD0gFt7DeuzMerm7T0bDOWZf2t4ioflR/ozmHtwboKht0S?= =?utf-8?q?Sf1MBjP5B4drH6eyJ5MViZllZLamM5/mMW1ISfugMS03gdUD1esiJ9Urop/2WAtcH?= =?utf-8?q?7eGWdMe3Z0uxH1H/ANDSVl3m+hQN+nX37N16A2XP7jR+oO4OQ6fjmayBGvH6O1pKT?= =?utf-8?q?WIfC5iX3np0HscyEwHN0F6rDwKLsE1ySP/9dCYPbWcbnCQGEYSZNfh0p+3RsplRb+?= =?utf-8?q?eAy/Q9hID32x/rOSYfAZO/i1Nw2aAU7QTbVPCyKXYbYvUKfGfPfQccbvKmXSUsJkt?= =?utf-8?q?MMo+2E5CSY/Q8B61nrZUS8drleYs5t/uxU0dug3Z4PiaMMGdrjyaCLoi9vrQpeSgs?= =?utf-8?q?8xKqz9kXsJBvjTMbG9YaMdYpleVlLo5AbpT6WMOxNWH6qMJtWzgX4VMoFsYQn+fBo?= =?utf-8?q?10X1e2R1Of6Qmcv7AH3hoIvaasvv/a8JQJ9DgrCOF+eFVOVUNgHLLYyO1k0eOXRpB?= =?utf-8?q?92m0hxee31/CGYe2UuStX3tHPG6Z3ilVziv0UXPfpsyofEOrV5ulx6rAUrxtYQg14?= =?utf-8?q?6fPRqXmOnc0WTjU+dja8DAfOvZL6p3RdUmD9KWpzCHiVXTmtgaNkkYwGSIvVcXWhb?= =?utf-8?q?hX1VUdiYqr3hm5OFq5/1Apv553izvkPTT4ZhGR0a72UMw3OshuiNLH4zl2YBH4jS4?= =?utf-8?q?ietoRkh8a3XzfpigFWSPizzubbhBVqpoobBwTBLWFlS3/J/thHnxC2R6f9bybI/fh?= =?utf-8?q?66ivw7Ji9PthcmU6S9lShdrc/Ul98wx5A8M8ahUr6DX1CZKqh+mXWlE3F/h4o/buN?= =?utf-8?q?NkG/tyrFsLxOA/brmWhjVtdQTCP6Byte8FiqQ9FCz3f0FTKUDCtWsCfqZlfG+rkp3?= =?utf-8?q?MJcxtYZCFfxX/T9XgWrY/yLnIHIkXNJHQotg6J1lmTFOSB0IjY1YXVuqAQyUnSaUJ?= =?utf-8?q?zwOspTEzx0W?= 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:(13230040)(376014)(36860700013)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 09:02:57.9164 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7978d7b4-8e93-49b7-4d7a-08dcbdd23942 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: CH3PEPF00000011.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6888 Unregistering notifiers is a costly operation. Instead of removing the notifiers during device suspend and adding them back at resume, simply ignore the call when the device is suspended. At resume time call queue_link_work() to make sure that the device state is propagated in case there were changes. For 1 vDPA device x 32 VQs (16 VQPs) attached to a large VM (256 GB RAM, 32 CPUs x 2 threads per core), the device suspend time is reduced from ~13 ms to ~2.5 ms. Signed-off-by: Dragos Tatulea Reviewed-by: Tariq Toukan Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 0773bec917be..65063c507130 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -2850,6 +2850,9 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p struct mlx5_eqe *eqe = param; int ret = NOTIFY_DONE; + if (ndev->mvdev.suspended) + return NOTIFY_DONE; + if (event == MLX5_EVENT_TYPE_PORT_CHANGE) { switch (eqe->sub_type) { case MLX5_PORT_CHANGE_SUBTYPE_DOWN: @@ -3595,7 +3598,6 @@ static int mlx5_vdpa_suspend(struct vdpa_device *vdev) mlx5_vdpa_info(mvdev, "suspending device\n"); down_write(&ndev->reslock); - unregister_link_notifier(ndev); err = suspend_vqs(ndev, 0, ndev->cur_num_vqs); mlx5_vdpa_cvq_suspend(mvdev); mvdev->suspended = true; @@ -3617,7 +3619,7 @@ static int mlx5_vdpa_resume(struct vdpa_device *vdev) down_write(&ndev->reslock); mvdev->suspended = false; err = resume_vqs(ndev, 0, ndev->cur_num_vqs); - register_link_notifier(ndev); + queue_link_work(ndev); up_write(&ndev->reslock); return err; From patchwork Fri Aug 16 09:01:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13765795 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) (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 5AE4814E2CC; Fri, 16 Aug 2024 09:03:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798987; cv=fail; b=nDif/AiolPcfJCM90CiAdh3hv+4owuqyaxvmnci5Zgn5mJCCFgmQaq7fRX1c3bvbxULiundJK7tAIzY/uOfliMwFbgJO3f+sa1vncXDEG7g66t3K+aUplK1Zs8xlpHqs5HPoXdRKO5aqN4s8mGh9pd1CpB2QQZ4jgFkhQIZPGHc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798987; c=relaxed/simple; bh=tHVRznIQYDYzoAY9hjgpWyz0H1mNIttNlf8Odx9u9PI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=frWbn3JqMUgJ/o8jsxDeCCeelb7a8aTPtFOK2I9v+wL2dB5gnwGQ72kEMIG+jwJL6zXCDXip11h5BYqnGuVeHItjEau7AvPE1dRwScweIBqmmq4akFuwGheJRXxYSl+Z0ulaE7/bl7OMTF5WVSQIDxH8+XOSZrnMsu6QMlGYi4w= 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=l2zvYyNM; arc=fail smtp.client-ip=40.107.244.62 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="l2zvYyNM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yqE6E+7BrwwTu2pi3kx8oulEZ6cW8uniBgNQDbfhv3ZZ5trzoXiHQoWvr8IxwSXBJjiAGIoLYjnuG8kOHJroghzcNYAs66uoYFPFxkwLCnItRyR1Ais5xjexITSMoD++2cOd0Am9IUVyrSI/4TzKiTlXWUs1LcxtzOP5yU5vGkZXb0zjighk04gTJXtYAvmfCra3DAZ2zMKfwXDyyZzbV6r9VKmOki1bkaroy+ALJkKopYq9wYM0X61lXX6ugzQQJwvOUT7THqhgSOpPaw0XedSd5h65cmqReXVfSqOpp/ylFhAFkMb13ixBaIvMSeHmuqD8ZTFurBGqPwbvAeaDRg== 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=VLhZSNSFuIMzzAIr7N7eaMqtvHZK/6Wnakhktq+y4MU=; b=ciAwwSgeiUJwl4fOAsIIVB5mq6A4ueszBBMrnV6ZDtUXkGxnGQstgUb58c9hT2XgP8oW0UccWCjVnN/M9Bg45ObgOtSrg53YMEK0Ht8KNtNRHn5A7GjkL/RfzaDevqEZFc8ciOudapnj/vR5VJ5VYZZaWv4HnOBFd9NIu+g+fFPFMnSox7j/5rIt7NDTXudPx8CeOkNnnX6fLs7i90g/BMeEIzTY2ViMCq8I70jZiEJDAJKzpJOKV7ZRUrqzRgsfZKIrhEfwORtCV763Ay0pFH779ANBgwRWo+HICnYgKR+Gh7YoZ6JTyEb4tXc8tIuVMjWL8Nt4S8C+pSe7uqIqvg== 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=VLhZSNSFuIMzzAIr7N7eaMqtvHZK/6Wnakhktq+y4MU=; b=l2zvYyNMe3zUSi4P9IJ6K+I6tKtVx6oECl/ViBYZvSi92isJh4UMjpM83BXZQwbXdUPgUxIpph1xG3f97eXyVj/li0i/+JqqbcPGjA+SB/hVF/I5R12F8q16Il5ak6AOfIeGgJMwnpYn7be3AELOpvDTi/QepsMhHtnpJ2Q4a2TxZNhJk0GwxyCqLtyvNL657S77dhjZZsCeYlrSxShIlQbVsndr33cSjebOooqxNUCqUmjHzCqvkcfSZO6UGvIkQoq7l+jfWIkI81rhUBEpNd2FhB2BhivYvrC5BLyPi0vDN6dDSuAVHHcH5G3V0F9hcSza1O+Pr9+49evN+c23xw== Received: from BN0PR07CA0009.namprd07.prod.outlook.com (2603:10b6:408:141::8) by DS0PR12MB9399.namprd12.prod.outlook.com (2603:10b6:8:1b8::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.19; Fri, 16 Aug 2024 09:03:03 +0000 Received: from BN1PEPF0000468B.namprd05.prod.outlook.com (2603:10b6:408:141:cafe::c7) by BN0PR07CA0009.outlook.office365.com (2603:10b6:408:141::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22 via Frontend Transport; Fri, 16 Aug 2024 09:03:03 +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 BN1PEPF0000468B.mail.protection.outlook.com (10.167.243.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.8 via Frontend Transport; Fri, 16 Aug 2024 09:03:03 +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.1544.4; Fri, 16 Aug 2024 02:02:49 -0700 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.1544.4; Fri, 16 Aug 2024 02:02:49 -0700 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.1544.4 via Frontend Transport; Fri, 16 Aug 2024 02:02:45 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , CC: Dragos Tatulea , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Tariq Toukan Subject: [PATCH vhost v2 09/10] vdpa/mlx5: Small improvement for change_num_qps() Date: Fri, 16 Aug 2024 12:01:58 +0300 Message-ID: <20240816090159.1967650-10-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240816090159.1967650-1-dtatulea@nvidia.com> References: <20240816090159.1967650-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: BN1PEPF0000468B:EE_|DS0PR12MB9399:EE_ X-MS-Office365-Filtering-Correlation-Id: 370a02ea-1f97-490c-35f8-08dcbdd23c73 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: Pa2xMqRrOfk60Hs9kdTChInLvjrHHm0ctg0mH8kZrYGSufJE9fJYzkpZx11PIrObUkAHERqduXiQ2GK8wk1l+cjN6/X8jgpANSSdCrV7lYuJWAGBI+WrUIBUP4mkSa4MTfsq2XqzeWcVNa/NwQURZ29UtVeWlvVnnog7AwTf2Y9k8BmunJzT19MZKFghCOQJ0uVvDSDMMXdxZK5WAv7tnwZJRdk6ERKwtqoUkSvcxKx5vuMYOs1ppSwZx7awuUWz7LcdKPNiwe4zq4OpLqVTqyTCDxWm8j/an6ohhjKToYIxao7cUGMHL1AvpwHRgxX6Ks95NaoLUm2yEeq/Di05FdMgzdwypL+df9YsvtB3KzYGLWlNCB/xMp53rwA6b2v6l2YmMfkKxwi6ENKMJSFD7ZLpl0axHu8S7hCUbvEQcZzszDps9UniJlcpHgPe7kPZg0QZt/CfSEpjD8yJsjvHtgERGTnKy5i9ZUEnErOimQ9aavIvLVTG1SNAUO+yKIbQJnOiZDPtXCZfVm0stef1MGfe8UYOqnRXqRc6ekJH5gdvPfo0f5dQLZnc6ZkY0VeDo8hrmTFmUweW3yAVacPXOzZlFuQOg5KGaT49037DVpgnEHwIEwEKK/G5AGZW7cWRdMm61YQscV/iB/ck0Pl159PROtHIvkgANqbYM4FVDqSXO6mYRdTcUjsfNvSFADQzZX87k6y4oS4Ac+rBhTpavRBPFH5Vuzouyey3kpooyJTM5/g5YnepN2upb5+HR6jRzePOvx+oD2aUweGi5XCegOkngbi6TcEhr8s5DIQjdfkl+QvPeoEiXBy7HVDL06V36LL86h6TJDZm0As+z/z4PdgrcVZMyEcA7IcHlyxX5LBhLAzjaYvoLzNUrbnvLOYi8huDKvblzVoWJaHWINsi2oWWe52WSLT+N+adnyvUb8SrFoxRRXgNh8DUUQA/etTPmKKTlGuOWmUGfMvbdACYmdAtTmMOl4sMZRoB7UASDmCa6IN7VDdFTg0E6hAji/HeolZ4BhrWOwVvQxmH55WthXlfBzl9ydVVSOMVC2bBH12b/MWqx8sciy78bg/FBCULVqKiowr6v61iv0odhnjDx+WeKpSXHVXJyWd8YP1OVSrj6Zq4S1fC2PmR4C8jZagcDlTeOjyE35PuxqNZY6iRAW6vijG2IMJW7Q0yVldZ8/Ygpmp9443JiDMe6R8y+uYTSSwMIPEdVWjWuJj7IxpVVMu1T+Zx7HE5jWsdqnwngT/ROiSjEI68dnZY4elqO6Alvh2Vwt7KHaeDSh+9D8FfzkthUGaOXxUeHZH0GJw+Dm9vn8yz+KWWjlY9oPVSoUjEN2PlaQ2wX03hXmyjY4u2mF6JjYXz3cherIGjzJ/tzw47sE0TUZOt3A5CF1bz0ZGmie+mvGXp/iN9W7AsTWaFCaYhqbWIiRMdzeOAED7dI+xgvCby6QO/RUnniTzCevE3 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:(13230040)(1800799024)(82310400026)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 09:03:03.2233 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 370a02ea-1f97-490c-35f8-08dcbdd23c73 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: BN1PEPF0000468B.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9399 change_num_qps() has a lot of multiplications by 2 to convert the number of VQ pairs to number of VQs. This patch simplifies the code by doing the VQP -> VQ count conversion at the beginning in a variable. Signed-off-by: Dragos Tatulea Reviewed-by: Tariq Toukan Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 65063c507130..d1a01c229110 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -2219,16 +2219,17 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd) static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps) { struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); - int cur_qps = ndev->cur_num_vqs / 2; + int cur_vqs = ndev->cur_num_vqs; + int new_vqs = newqps * 2; int err; int i; - if (cur_qps > newqps) { - err = modify_rqt(ndev, 2 * newqps); + if (cur_vqs > new_vqs) { + err = modify_rqt(ndev, new_vqs); if (err) return err; - for (i = ndev->cur_num_vqs - 1; i >= 2 * newqps; i--) { + for (i = cur_vqs - 1; i >= new_vqs; i--) { struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i]; if (is_resumable(ndev)) @@ -2237,27 +2238,27 @@ static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps) teardown_vq(ndev, mvq); } - ndev->cur_num_vqs = 2 * newqps; + ndev->cur_num_vqs = new_vqs; } else { - ndev->cur_num_vqs = 2 * newqps; - for (i = cur_qps * 2; i < 2 * newqps; i++) { + ndev->cur_num_vqs = new_vqs; + for (i = cur_vqs; i < new_vqs; i++) { struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i]; err = mvq->initialized ? resume_vq(ndev, mvq) : setup_vq(ndev, mvq, true); if (err) goto clean_added; } - err = modify_rqt(ndev, 2 * newqps); + err = modify_rqt(ndev, new_vqs); if (err) goto clean_added; } return 0; clean_added: - for (--i; i >= 2 * cur_qps; --i) + for (--i; i >= cur_vqs; --i) teardown_vq(ndev, &ndev->vqs[i]); - ndev->cur_num_vqs = 2 * cur_qps; + ndev->cur_num_vqs = cur_vqs; return err; } From patchwork Fri Aug 16 09:01:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13765796 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2068.outbound.protection.outlook.com [40.107.236.68]) (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 86D5A1547D8; Fri, 16 Aug 2024 09:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798994; cv=fail; b=TWTYbNVwwhm/fsFlh6zD+OzXS7calcSaFcofpnNXaNtTXka9W2AxNim49lqAOPjB5WsgszvWzB+xTnY6vBIHT+ExGidR2C1MSlGQofwhtHOn35R31hR5/tF17yaxYDRMJ5EbFyiflGiNTXauCQqkp/+bZdRiGfsLcutoHhMwsy0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723798994; c=relaxed/simple; bh=8iNr6oETCoFicQJnO591lyH/KynVecehV6m4rBREg9s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BhZ9RDyKQySn/0zK2omkcmSD3sSoxnbtJXVCOx7xirbz413padzcsG7JhkV7Is1CB2rEV8Av4/rXdx87gajL+yB+cOFeSLgMsg9Y2hUEzy6SYD0Peq/kBs/bqPJ/jECYE5WL1fNS5fzr6dI9eh2wMK1fNgftWyqHxSWcSRWg+/0= 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=dDBqIn6K; arc=fail smtp.client-ip=40.107.236.68 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="dDBqIn6K" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WHGxoH6pzI4wC8SGbZa3nyV5urILfO0rW3/YOpFdjMlP7g247Nrnb1IZ26dSbUKaYQNlZut6guIURHsE9L9yxGDfALm1lUBpuCfNdqImSrqk6XjaR19LorH6XHjcGV2xYpZVYwcjr+Bb0480eMQzjA9CT+i8BsUoJNQNXg+xa2yuYHAIO4/sR1DnQBJ0mvrflckwLyEm/P5qYKXLh5GDPfjdWgTK+FAsys1qVAWVqAmnlShk2P8B+ZA1IySC7srNzyTL7GjytgjCguY+jilWk03Cgj/yvCIfG76mihzYDgaHzP1oJsaJ0rVMPBTiRBdUW8Zg2Bc4bPuMlJ8h2m+O4Q== 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=jLQqQe/ew4Mtp/vETYeLoEGOjYQPOrzAWqP+IY3P30Y=; b=mYZhAdrKmhbxNnAF64ooME5jpnQCzLho7XN4ntpYSGgaTDzAcKFRrL1/OsfCjVCnJRhh3OUctqWAohU14Fgzj6jLwZmYYQEmK7Y/GqALzCD/ueCErYv+484np9GTS90L4oKyVOTGwjrYocgIwJjMwu8OXj84CgNPjEGQ9GBQf42N+S+ZvafHK9lcpEGXmAulUAHJMkuiJvQI8T7RGn/LvHWcNhoAGA1bs48rhD/aaVHEQ6CbwtI7IxfzI29ixUEdRH9bzQZB9trMvlbJXje48rkxJseZn0WbtNolarPajJH2cAdLbvg0x1rQWlsNQRAfBcW/wdM4VfNNLg4/CHXymQ== 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=jLQqQe/ew4Mtp/vETYeLoEGOjYQPOrzAWqP+IY3P30Y=; b=dDBqIn6KqQlzAm5j4KN5R+HhU/XiRtikDseFxAYyr8JzXOwyW87zMwyaJEUDZo0XTn3ZnhReIioUAJFm/2Dg38F5wS8S1/gkjBZb2I1nUEOfp4j1yfL2WhWnyvfNJmenFib/WQ3K5F46g1x8Yk3CDLNbeE6FOZnR2gDCJm8zvOJWUvdqh8PM/DCV6y5ZZ/kWPMQO4lDsV3mS+6GXfuDkaJEmioMsJdMw0FS3EB7hcaCpJjqcDIMQOG0DOsdDWT5ABFcYFgJmGW1cghwLhmLL8xDIEDAKEknAhsRNMp43ztGuxhXWJLXavUE3vWY9CuzzwvQ6x+DbUYjPyHwnVBO8Rw== Received: from CH2PR14CA0048.namprd14.prod.outlook.com (2603:10b6:610:56::28) by DS0PR12MB8295.namprd12.prod.outlook.com (2603:10b6:8:f6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.19; Fri, 16 Aug 2024 09:03:08 +0000 Received: from CH3PEPF00000012.namprd21.prod.outlook.com (2603:10b6:610:56:cafe::9) by CH2PR14CA0048.outlook.office365.com (2603:10b6:610:56::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.23 via Frontend Transport; Fri, 16 Aug 2024 09:03:06 +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 CH3PEPF00000012.mail.protection.outlook.com (10.167.244.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.4 via Frontend Transport; Fri, 16 Aug 2024 09:03:06 +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.1544.4; Fri, 16 Aug 2024 02:02:54 -0700 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.1544.4; Fri, 16 Aug 2024 02:02:53 -0700 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.1544.4 via Frontend Transport; Fri, 16 Aug 2024 02:02:50 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , CC: Dragos Tatulea , Si-Wei Liu , Saeed Mahameed , Leon Romanovsky , , , Gal Pressman , Parav Pandit , Xuan Zhuo , Tariq Toukan Subject: [PATCH vhost v2 10/10] vdpa/mlx5: Parallelize VQ suspend/resume for CVQ MQ command Date: Fri, 16 Aug 2024 12:01:59 +0300 Message-ID: <20240816090159.1967650-11-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240816090159.1967650-1-dtatulea@nvidia.com> References: <20240816090159.1967650-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: CH3PEPF00000012:EE_|DS0PR12MB8295:EE_ X-MS-Office365-Filtering-Correlation-Id: a348103c-3942-4fd2-031c-08dcbdd23e3c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: XqVRv7zUllih83v5uLhCfvPYa5epcKaFAb1Bv19ELOWZhfMIqiGh9+ZMTfEZwcpKFTlPaiXkbCHNnzywyxsy0GsDuzUDzu3gPDYYu75bZJC/Ah0SkJQ1+jOwvRd18g4rdALZvPTG7ZLLfQ4NYG0de7nrshXWv387piA0Hq4pGKS/ihGpE9wC8ZDoteqMSotMuClVkJRvo4nHzg6e9U3mSccTdE8P/Ultf/WATEZCWDUFQe+MwZ0BuzRlOiODShbCRuD2bsbz61c4TaWYvUDLRAYYha1He3AwnazZ/lY+K4Ug4oB3DYHxuQJG2IcyLugJMEv/xsVuvpm174QK13o9zHepNFA41D730Ho3zUDyy4bFDL9oK67KBvMmljpYfjQnyxr8Jjhtdy/mcy3qA28eIVvDrcVCt9BBInLz2t7GewalmNlzikiexpEx1eY0i/a1InwbXov2iMh3IGBkhj90agWu0R89bffz/XHvffdIWnnDaWSZra0f6gijMsbP8olC3ZRh1NghqArpwGaGlwP54E5Ca2HTFDsV3WQFFQsesHSNAWhh40OEOn+0VqLkgt25JEmfvKaM7IJk1oh6HU+5Biw40zm0NemKqBwS13qbeh8GFM2b68sIIA8CqSrPDy1f9n8c4iGg6l9AcSfn66nVKsfQQCAIXTkIklceAPQNBMcoPS3P4VcUD8YP0TgknqKrsaUgBIg/xEjd/MWx3afddit3Sg2w3qIYstuf0RApjRIk583/gdYubCT+559ZRbD4Wvh/onWr3WRoPOzU8KUUkIQM5N/Bbkay5l4VzAuwZvuKn1g2pvlum/Vhe8g+JzXDzxnUmSmzDOWJFJCp0V1+UgobNkyxR2ZyimqQnz2OBP4oLfzvJG+wl/fu+yMggrFudVFEKR13NPZxEac++TuGYd028GlWoGDoXqjLQjFOMN+VJuZRoR0MQpM1gFVNM8l+65Qwz4VfCukZVDPYb8oSjbpEoflQOJSrE3VgpMGOxahqcAiPks+N1bmmxjgkUyKvvWdK2QguDELRjn2eTGXycmSgvc3KdwcgE+J5er5VszrfaOW+97es5Pc95mJMQYqPElyD7IIsL70+uZwr7t4M0qi8juIiaV22g6g96Qo7w7/CMSmPFE8C2jkmLNnEZ8cnqpELZ6bFT56jFZPUHDkhiA6ZoFLksLgXoL3GqbN8t/7BYVN5WdNF8HvHdao7MwilaQSjaAPEXNaSJnXwE3920P1Q6nNVAxPMypUxKd++wz8UfTdZYwzO56KVK421SwBJUujsDHfVZMqTe9nrAB6o4v7c3tbFls7C9gHigCOVpJpanBoXT94/PoPEMtPd3Z3O51CqtWLHa0X/j73gRrNoexSbMbWw+5d6ZUETkp3rA2MVxHpzmgRMIvZeVc5gMZZEwsezDjwK/BNyCSLWnn5/SJFwLCN6kMOU/LRUDqy1V1WVM6SXNplgA3n9ixwyPDda 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:(13230040)(1800799024)(376014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2024 09:03:06.3107 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a348103c-3942-4fd2-031c-08dcbdd23e3c 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: CH3PEPF00000012.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8295 change_num_qps() is still suspending/resuming VQs one by one. This change switches to parallel suspend/resume. When increasing the number of queues the flow has changed a bit for simplicity: the setup_vq() function will always be called before resume_vqs(). If the VQ is initialized, setup_vq() will exit early. If the VQ is not initialized, setup_vq() will create it and resume_vqs() will resume it. Signed-off-by: Dragos Tatulea Reviewed-by: Tariq Toukan Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index d1a01c229110..822092eccb32 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -2229,25 +2229,27 @@ static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps) if (err) return err; - for (i = cur_vqs - 1; i >= new_vqs; i--) { - struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i]; - - if (is_resumable(ndev)) - suspend_vq(ndev, mvq); - else - teardown_vq(ndev, mvq); + if (is_resumable(ndev)) { + suspend_vqs(ndev, new_vqs, cur_vqs - new_vqs); + } else { + for (i = new_vqs; i < cur_vqs; i++) + teardown_vq(ndev, &ndev->vqs[i]); } ndev->cur_num_vqs = new_vqs; } else { ndev->cur_num_vqs = new_vqs; - for (i = cur_vqs; i < new_vqs; i++) { - struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i]; - err = mvq->initialized ? resume_vq(ndev, mvq) : setup_vq(ndev, mvq, true); + for (i = cur_vqs; i < new_vqs; i++) { + err = setup_vq(ndev, &ndev->vqs[i], false); if (err) goto clean_added; } + + err = resume_vqs(ndev, cur_vqs, new_vqs - cur_vqs); + if (err) + goto clean_added; + err = modify_rqt(ndev, new_vqs); if (err) goto clean_added;