From patchwork Mon Jun 17 15:07: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: 13700923 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2043.outbound.protection.outlook.com [40.107.236.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 645671741D2; Mon, 17 Jun 2024 15:09:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718636975; cv=fail; b=FkyGP9GlcYLLLVc5yjR7WJKglvEG5ZafgXCPHHRwWFqBVYd9702bJFsrB5LIx+CmzwABGpnhpadvWUPVucRcA5PT1OUnQCC8NMmDvdWN+kaqYyZOamTrHYD/eRnAtvrFhdHj9HAe0U8MhrGftijqU1uV2JteRa7R9zWgN8sAE7Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718636975; c=relaxed/simple; bh=+VBdGMxn/rBdO2GAbI92QfqGAXTZEbLJD3LmtxOBV04=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=puUjoCel63BUlCsdedObajZsxZeH42k9v2KNZZj244CzPRrJRndfOo/DX00szDc2uZ7n9v8PJCbuZxAYI662pFlhzWeyN0/JL+sqT6Xm+lAieWrUURi73MFGXwucsWuRwogmn1Rf7iz62Gjjx1Cgz241uJkXxxrY+mQzgZp3mzk= 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=s2O88Rms; arc=fail smtp.client-ip=40.107.236.43 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="s2O88Rms" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hs+0iCsaArkZSPQiPcLCF6bagQU/mn0yzbdQcekHjS2jArtm5pH0uOD5sYW2P78Z+mg7/laQ8pktfkc4h7962nPufI0MlZDnId74qfpknidsGT2f2KlUBOn+crUHdR/YjMz5J00io4ByalPVFVfRlKI2dtfpiZCsd3Jw2Tdvrsoq4xLDvjRqGWZD4eOhjtTVoEExIbYbhx+LMnqim1XnR8OjryG2Ou7Q6YvHLmnOFKXWlFKg/3aW3WctHDto2b9mZI7/eZHPerbfFOET1BMtsot9xflOXrxz9Mw4onGvW0MdvCEPfc7oXfxZXwYhcMKmIQLJCpEb0It9VZzk7uShfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ARe1GYtbXbk/p6QVycKLEeBPZAEGn+VV6msIbmlUYAo=; b=O9gxYzlXwBni/CrDFGwnoeczUyvdcA/lXUf9/F2iRvgLny9j1whRH8rnBtoPgKekf7Un5jkKwiIVVvuEVr6A3Fbdqz0Ws8vYOO5psjMPby0HTpiXsC2Uua6YT7e7BnOoP7N9xBvj7XZNZ1wN3enZ5QlAFjwkCfM7iKp7VX68UQsgTLzO1GispoP36Ill+HDSR7n3LFGeHIh7cKTB1/Nii3n3MSb2aJ9k5xl4Ods0DmGI7yy985inJs1TPlnU5nFPc3sXYo+wwQMvjWw6cLslXdzjTmztX1CuqccuH8rF/GTJ3npQL1PxOzkKTY3RAp3lV4bc+4IZZDNWy6sgRwvL9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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=ARe1GYtbXbk/p6QVycKLEeBPZAEGn+VV6msIbmlUYAo=; b=s2O88Rmsctj1iqLweTye7XvYbXjKKM1eC/Dnd2b1JQ6A4BTh5Hn6L+Qos6POXY5ZH5DYx3l7PqN40HtThOOOebN7Tni37SY2CyE7ZFTBdJesXnyMImBGXUHwVOYxIjXzd2mW5x0GGzaLCpYjuOnm7KS0PmU2L4cnzG5+Hg9tv4R7ed9AcDieG7GrESq8q5DrM5KZqD/M7il3j3vSG41INUVUoFvR70x5YGbUxw2uvmJ6+42LC58Fu0Nn121DsOgseMMwmU17VNH6Fkc2KH/zGRULLdReF+PJaDqdSoYZ0JJhPSYPwncV6KOkkHJYQjY41IhwkMWkNk4GFY67AqTSMg== Received: from SJ0PR05CA0065.namprd05.prod.outlook.com (2603:10b6:a03:332::10) by SA0PR12MB4464.namprd12.prod.outlook.com (2603:10b6:806:9f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30; Mon, 17 Jun 2024 15:09:30 +0000 Received: from SJ1PEPF00002310.namprd03.prod.outlook.com (2603:10b6:a03:332:cafe::f3) by SJ0PR05CA0065.outlook.office365.com (2603:10b6:a03:332::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30 via Frontend Transport; Mon, 17 Jun 2024 15:09:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SJ1PEPF00002310.mail.protection.outlook.com (10.167.242.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Mon, 17 Jun 2024 15:09:29 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 17 Jun 2024 08:09:14 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 17 Jun 2024 08:09:14 -0700 Received: from dev-l-177.mtl.labs.mlnx (10.127.8.11) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 17 Jun 2024 08:09:10 -0700 From: Dragos Tatulea Date: Mon, 17 Jun 2024 18:07:56 +0300 Subject: [PATCH vhost 22/23] vdpa/mlx5: Don't reset VQs more than necessary Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <20240617-stage-vdpa-vq-precreate-v1-22-8c0483f0ca2a@nvidia.com> References: <20240617-stage-vdpa-vq-precreate-v1-0-8c0483f0ca2a@nvidia.com> In-Reply-To: <20240617-stage-vdpa-vq-precreate-v1-0-8c0483f0ca2a@nvidia.com> To: "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , Saeed Mahameed , Leon Romanovsky , Tariq Toukan , Si-Wei Liu CC: , , , , Dragos Tatulea , Cosmin Ratiu X-Mailer: b4 0.13.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00002310:EE_|SA0PR12MB4464:EE_ X-MS-Office365-Filtering-Correlation-Id: bbeef19e-ced2-490c-0601-08dc8edf7c84 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|1800799021|376011|7416011|36860700010|82310400023; X-Microsoft-Antispam-Message-Info: =?utf-8?q?5CV6Itl7oCuvEjAXGhRL5j6jspCJbOO?= =?utf-8?q?Viz5iaDxeGj54+CZ+ZqOa/IagQe8I45PoEiA2Kwmgm1Wld52B851yTV+FuuvQ5lEk?= =?utf-8?q?4sLyEEpVwWW9RYw2DHmD+gVvAjkVIThgL5E7v/6YkdfXZWLgLbJYStCP3JfGIZk45?= =?utf-8?q?cTxv9Dly3USjbC8xvWorKTuLOpGH9OXhlN3ywMaVmeQ5kSfLqmCxU3zgB1M/+4w8k?= =?utf-8?q?zU+1FkDbgu4MNvSEVG5bWD2A5RWVhbK0kzO9i9I9RV0uPvs1BD0MgNddHYHL6HxwU?= =?utf-8?q?2PPjMpPxTUd4xct2TGdoTwOkxRxPBsiQbvbS18eSv/FHxRtCdW3XVjXrvfTZLtfe6?= =?utf-8?q?3JpMWT4sNozTSnhmueAJ3vbY+zjiFIohcafbPUGfkPEeWBD+w72MRvUfnMO0L7ltM?= =?utf-8?q?IS0yOdgdcr29ZFA7BFW+J34vR/iXbjGBkv20DsjFRxpGeKaj9Jl2W080R1Ah6QhU8?= =?utf-8?q?WMAJpOcFJF1PbRpYnv3FSg46MPR8l4jBBKsswkOga+Wi2b/8COdkcuTS1cZZ4VNLd?= =?ut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en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230037)(1800799021)(376011)(7416011)(36860700010)(82310400023);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2024 15:09:29.7489 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bbeef19e-ced2-490c-0601-08dc8edf7c84 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00002310.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4464 The vdpa device can be reset many times in sequence without any significant state changes in between. Previously this was not a problem: VQs were torn down only on first reset. But after VQ pre-creation was introduced, each reset will delete and re-create the hardware VQs and their associated resources. To solve this problem, avoid resetting hardware VQs if the VQs are still in a blank state. Signed-off-by: Dragos Tatulea Reviewed-by: Cosmin Ratiu Acked-by: Eugenio PĂ©rez --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index d80d6b47da61..1a5ee0d2b47f 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -3134,18 +3134,41 @@ static void init_group_to_asid_map(struct mlx5_vdpa_dev *mvdev) mvdev->group2asid[i] = 0; } +static bool needs_vqs_reset(const struct mlx5_vdpa_dev *mvdev) +{ + struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); + struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[0]; + + if (mvdev->status & VIRTIO_CONFIG_S_DRIVER_OK) + return true; + + if (mvq->fw_state != MLX5_VIRTIO_NET_Q_OBJECT_STATE_INIT) + return true; + + return mvq->modified_fields & ( + MLX5_VIRTQ_MODIFY_MASK_STATE | + MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_ADDRS | + MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_AVAIL_IDX | + MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_USED_IDX + ); +} + static int mlx5_vdpa_compat_reset(struct vdpa_device *vdev, u32 flags) { struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); + bool vq_reset; print_status(mvdev, 0, true); mlx5_vdpa_info(mvdev, "performing device reset\n"); down_write(&ndev->reslock); unregister_link_notifier(ndev); - teardown_vq_resources(ndev); - init_mvqs(ndev); + vq_reset = needs_vqs_reset(mvdev); + if (vq_reset) { + teardown_vq_resources(ndev); + init_mvqs(ndev); + } if (flags & VDPA_RESET_F_CLEAN_MAP) mlx5_vdpa_destroy_mr_resources(&ndev->mvdev); @@ -3165,7 +3188,8 @@ static int mlx5_vdpa_compat_reset(struct vdpa_device *vdev, u32 flags) if (mlx5_vdpa_create_dma_mr(mvdev)) mlx5_vdpa_warn(mvdev, "create MR failed\n"); } - setup_vq_resources(ndev, false); + if (vq_reset) + setup_vq_resources(ndev, false); up_write(&ndev->reslock); return 0;