From patchwork Wed Aug 21 11:40:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13771272 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2057.outbound.protection.outlook.com [40.107.236.57]) (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 A20A11AD5E0; Wed, 21 Aug 2024 11:41:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240512; cv=fail; b=JUu+TVEJKm2D+RRaoD+RdeKX1CN0ih1uOCBEfnvAD0fYkCTQC5u4JmpL9ziUflyTEjQU+cxvjWKjvDps1P4ZPNuxFdOOGYEqeweH8gl7o2p+4N0cD/BlUaq39Vvk4cu877qWey4pJRYpDLv0t3QgLs5F5tWI3AG7VQuWQWMBPQg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240512; c=relaxed/simple; bh=vW10WZF5MYGMs0QCG6/61hYkcEo15kU1sq/jtACT8I8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lHt9HRF+ZnsdxssFCorIGtrZRzHMCfehrnQaURFb7iedjJf8yRxBW4CDmSktBhxYFW2MixSb/AOCjit8E8Ws13YSpG55qRPOW9oCXduWqyIaO9o81SWUKx9n5oDEkD+ObSJAWTEMXdy0GlF3YgUXNjN1ozgLnY61r72221fUHdI= 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=kUJU3281; arc=fail smtp.client-ip=40.107.236.57 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="kUJU3281" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WO1Jk9DwycZyBieLjzjcQJO6qZ4nvCF8/6tH/8L4zynpdjI7GDk9p2H+HMc2e8AMoxoYaNyQAk4wJXdrOvtX0zpdI2NDaCt3/mLrvf9lSmp4KmQVDfnzFoKSqqyOddX0qzGqj9kP4dXOGpdEkuIFY2TaeUr1pqRhzed4HOQVD5mCKtRB+0/R2u8jYP+zQf+V0lw1Rgv4wpkbGJ8hNYbwmAHstGCw8j7p7Ac5/jpDkYWxKlHChlgzUO8bb4oSXHFnke5eBvZz6E8HSUGUwvoNsNmtNUJX8EwxQjA+O+TPH3YQj+of2poLRIydn3naMmh6UHagIQhlOSVHNZanNhm3Zw== 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=NUmxljcY0nXbocmKXhfYEAF1cC/flvePS47w5mj4bkU=; b=mIid6YJMPyg2xfQ6/vbQ8Bq5wr9MswfCrxEXPSlVAZKboDvcOwI14ymVE/sTTiR5T5elPmi8bh2EExdTsmE2+r0Ymikcg7G/gpxBFTCA6L9teAibZwi87yLtsr2AyQDk3L5/w55fyVeRQlw2ZVNfM+Hf/4K7iz+Av2w4YWw64dw6R0F3Fg7UQXNHO+gGvV4LGnnWS8FBrrp0Ho3iC6YUPafB67TrjBNNuZqv7yhEZ1ohRO4wD31oAeQiewTla+SgEHkrG9M4CLMWIaOckUnRtfKgcen58GETTWcKhy/mEv4X8yqWAdEUU9i6ibHGJB+owWhwfl8FFFW4jgZ2e0H8Wg== 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=NUmxljcY0nXbocmKXhfYEAF1cC/flvePS47w5mj4bkU=; b=kUJU3281c2SXBtTBVqzJ9abEPMKCOOFi7Rdmb5hcAFf1iO5EMz/RlhWvH8yaYfxh5pT0EFz76nvw7mUAB5JsvlGhVqL3HIEgnK3j1Rjg60gtLtL61AHynaX5VEIFZtK14Zpan0vRPHa0tMIiTl7MZiDXtsxZww6Xg68QPhqZAJGrhjAHwuSGC/17eeJOMbqJzCNzahGNm97UX/qFmNfF1FFzrigzmUjA64B5KYxFf6pqttArh1beDyAPFVTfGnskjQzbVlYaqxIvM/Onv7W/85ZbvOZ52InihCocKYKGSA5QrfmrpksS86PdmNStPd5xHzfM3ffcic/jXXW2/tdIiQ== Received: from BN0PR04CA0154.namprd04.prod.outlook.com (2603:10b6:408:eb::9) by MW5PR12MB5597.namprd12.prod.outlook.com (2603:10b6:303:192::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Wed, 21 Aug 2024 11:41:45 +0000 Received: from BN3PEPF0000B372.namprd21.prod.outlook.com (2603:10b6:408:eb:cafe::79) by BN0PR04CA0154.outlook.office365.com (2603:10b6:408:eb::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21 via Frontend Transport; Wed, 21 Aug 2024 11:41:45 +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 BN3PEPF0000B372.mail.protection.outlook.com (10.167.243.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.4 via Frontend Transport; Wed, 21 Aug 2024 11:41:45 +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; Wed, 21 Aug 2024 04:41:31 -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; Wed, 21 Aug 2024 04:41:31 -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; Wed, 21 Aug 2024 04:41:28 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , , "Gal Pressman" CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo , Cosmin Ratiu Subject: [PATCH vhost 1/7] vdpa/mlx5: Create direct MKEYs in parallel Date: Wed, 21 Aug 2024 14:40:55 +0300 Message-ID: <20240821114100.2261167-3-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240821114100.2261167-2-dtatulea@nvidia.com> References: <20240821114100.2261167-2-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: BN3PEPF0000B372:EE_|MW5PR12MB5597:EE_ X-MS-Office365-Filtering-Correlation-Id: a8047278-16c4-4aff-6b62-08dcc1d63c34 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: jogTeoIDMRUvOayuGyqRY3KD48oF6C07EKpWnaO+0hMe0U4T9Fl10E19it3y13lIjEl1nBZAAYoQxiFUQKoGH3RTVbNX96k1TbeEmQntv1HSjuDQKKCXt+77CcPAAPaTpI5ZOv+kyoBd6vHphfqrGYSDUWszAS2G8LEFxkBUtuv9G5MHZgCaF1ZpHQU7T6yTW4BTCzXLVr7AyKs4NuIES3EhjGhP9mhZnmi0C1ZLT3H/7x8JT2B+pYofwFzx2+wG7NXJh7UoEaeNmqBLcEK0+6Nkzwt/V5j6S6ibzAy6S5Z9O0vG5utTPN+kxRqAyH/AgF6ppNnBNi14e/EFQSkt4qS/HBIUeEp4Sh+Ge+w5Qu6/PAr4W5RK6CihZ45XjJ3Xp75pREXqsoJMVeGI10xQEH+BZRppkIALWb9sxIGpi8A36dKFKGPnzcBQH4jrGK92joAYypr9c8YSN8kF7RrQtE7HXhKGE7JGuPY1Jk/IZ5DlfopexBWhW3BKa9tXg1rqs5RdOG3dcdj9QqJ5z5Pqjzfvqo7ZgWy7x7z3Uu2eqHQfbSvFr5HX9GtI6fQL09J/jIyzPjvfMk0yRGjB1A2J4QcFDhmjHw9ms852D0nox+1+L/wrTDlCQI3/X6C4uRIAcW1gs57gWhy1ciWBM9VsbuxDAXIFKljJFH8D+3jBCj1MB0n5Q8Ohqeb0nkX9QO+Vvc8jmfSsFovwgRFnynu7Gpq76dALg6OivUVleqE8DkAhmp5crylVYQKQpZRftT7yIJ9nMTpee05ZThidZBV1lQe6VEH2byyrBNsFIAVbeIfZTxxfoMms9YpJbB8fklZkR6mEFIKDHxUsO1gJ1Cly8VmS1IciRzOq0z/TLp0eBwCytwbOorf8wea5IjxPXitz+Oub8nowd8ToTTotzaJNa/x5a/6Cd+XuKvDporlEARlen1Tvm1KM2eBzq4445kwjU7K3FuemV6wYnjuPbsw2ajkZFqs7ZdFSaO2cWXttMTV68zyNMBbFOcKMVA5xdidmkqpvCUJC2bYtHoWuMbTcBX0+wNhkzVRyEtNtw1f7xVIBwDMn/9RKZLjyr3T49uxy39W1NQYMWsPLzxmqZFOJWgFp8Ujmey7/DSe6qmcIWJ+HEGk3c4ZC43Fp/twMDKxsovU8y/bzdUfCGD/PExCitcW183SpsBy29kQ+JfVY3mG7wtwjNnF3IdQ3MAI2N6cbsa9PudH+A4XHuwRN9Ry7v0vBt1zz+UNDgjY53b/+Rcjxm9X+ynfOseIu3nZhUk5cB7/X3t5y+u6JhdlMGMSk49RSxoYtJWPv5Zkxn0xKKpQupp7+98Grw/AzMrkDayVVsqWMvtd7DntIKTV786QESPKE9oj0AI+ZYCJ1C9XONOjwWZrmVpds/ooU7Eg8iATfHAAFTfRP9RdxkN9vzFTa/HpF9aOP/icRJF/IY1NjsHCUb3CpxIIBKGvsgUswuuhb 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)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2024 11:41:45.4967 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a8047278-16c4-4aff-6b62-08dcc1d63c34 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: BN3PEPF0000B372.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR12MB5597 Use the async interface to issue MTT MKEY creation. Extra care is taken at the allocation of FW input commands due to the MTT tables having variable sizes depending on MR. The indirect MKEY is still created synchronously at the end as the direct MKEYs need to be filled in. This makes create_user_mr() 3-5x faster, depending on the size of the MR. Signed-off-by: Dragos Tatulea Reviewed-by: Cosmin Ratiu --- drivers/vdpa/mlx5/core/mr.c | 118 +++++++++++++++++++++++++++++------- 1 file changed, 96 insertions(+), 22 deletions(-) diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index 4758914ccf86..66e6a15f823f 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -49,17 +49,18 @@ static void populate_mtts(struct mlx5_vdpa_direct_mr *mr, __be64 *mtt) } } -static int create_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr *mr) +struct mlx5_create_mkey_mem { + u8 out[MLX5_ST_SZ_BYTES(create_mkey_out)]; + u8 in[MLX5_ST_SZ_BYTES(create_mkey_in)]; + DECLARE_FLEX_ARRAY(__be64, mtt); +}; + +static void fill_create_direct_mr(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_direct_mr *mr, + struct mlx5_create_mkey_mem *mem) { - int inlen; + void *in = &mem->in; void *mkc; - void *in; - int err; - - inlen = MLX5_ST_SZ_BYTES(create_mkey_in) + roundup(MLX5_ST_SZ_BYTES(mtt) * mr->nsg, 16); - in = kvzalloc(inlen, GFP_KERNEL); - if (!in) - return -ENOMEM; MLX5_SET(create_mkey_in, in, uid, mvdev->res.uid); mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry); @@ -76,18 +77,25 @@ static int create_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct MLX5_SET(create_mkey_in, in, translations_octword_actual_size, get_octo_len(mr->end - mr->start, mr->log_size)); populate_mtts(mr, MLX5_ADDR_OF(create_mkey_in, in, klm_pas_mtt)); - err = mlx5_vdpa_create_mkey(mvdev, &mr->mr, in, inlen); - kvfree(in); - if (err) { - mlx5_vdpa_warn(mvdev, "Failed to create direct MR\n"); - return err; - } - return 0; + MLX5_SET(create_mkey_in, in, opcode, MLX5_CMD_OP_CREATE_MKEY); + MLX5_SET(create_mkey_in, in, uid, mvdev->res.uid); +} + +static void create_direct_mr_end(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_direct_mr *mr, + struct mlx5_create_mkey_mem *mem) +{ + u32 mkey_index = MLX5_GET(create_mkey_out, mem->out, mkey_index); + + mr->mr = mlx5_idx_to_mkey(mkey_index); } static void destroy_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr *mr) { + if (!mr->mr) + return; + mlx5_vdpa_destroy_mkey(mvdev, mr->mr); } @@ -179,6 +187,74 @@ static int klm_byte_size(int nklms) return 16 * ALIGN(nklms, 4); } +static int create_direct_keys(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) +{ + struct mlx5_vdpa_async_cmd *cmds = NULL; + struct mlx5_vdpa_direct_mr *dmr; + int err = 0; + int i = 0; + + cmds = kvcalloc(mr->num_directs, sizeof(*cmds), GFP_KERNEL); + if (!cmds) + return -ENOMEM; + + list_for_each_entry(dmr, &mr->head, list) { + struct mlx5_create_mkey_mem *cmd_mem; + int mttlen, mttcount; + + mttlen = roundup(MLX5_ST_SZ_BYTES(mtt) * dmr->nsg, 16); + mttcount = mttlen / sizeof(cmd_mem->mtt[0]); + cmd_mem = kvcalloc(1, struct_size(cmd_mem, mtt, mttcount), GFP_KERNEL); + if (!cmd_mem) { + err = -ENOMEM; + goto done; + } + + cmds[i].out = cmd_mem->out; + cmds[i].outlen = sizeof(cmd_mem->out); + cmds[i].in = cmd_mem->in; + cmds[i].inlen = struct_size(cmd_mem, mtt, mttcount); + + fill_create_direct_mr(mvdev, dmr, cmd_mem); + + i++; + } + + err = mlx5_vdpa_exec_async_cmds(mvdev, cmds, mr->num_directs); + if (err) { + + mlx5_vdpa_err(mvdev, "error issuing MTT mkey creation for direct mrs: %d\n", err); + goto done; + } + + i = 0; + list_for_each_entry(dmr, &mr->head, list) { + struct mlx5_vdpa_async_cmd *cmd = &cmds[i++]; + struct mlx5_create_mkey_mem *cmd_mem; + + cmd_mem = container_of(cmd->out, struct mlx5_create_mkey_mem, out); + + if (!cmd->err) { + create_direct_mr_end(mvdev, dmr, cmd_mem); + } else { + err = err ? err : cmd->err; + mlx5_vdpa_err(mvdev, "error creating MTT mkey [0x%llx, 0x%llx]: %d\n", + dmr->start, dmr->end, cmd->err); + } + } + +done: + for (i = i-1; i >= 0; i--) { + struct mlx5_create_mkey_mem *cmd_mem; + + cmd_mem = container_of(cmds[i].out, struct mlx5_create_mkey_mem, out); + kvfree(cmd_mem); + } + + kvfree(cmds); + return err; +} + static int create_indirect_key(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) { int inlen; @@ -279,14 +355,8 @@ static int map_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr goto err_map; } - err = create_direct_mr(mvdev, mr); - if (err) - goto err_direct; - return 0; -err_direct: - dma_unmap_sg_attrs(dma, mr->sg_head.sgl, mr->nsg, DMA_BIDIRECTIONAL, 0); err_map: sg_free_table(&mr->sg_head); return err; @@ -401,6 +471,10 @@ static int create_user_mr(struct mlx5_vdpa_dev *mvdev, if (err) goto err_chain; + err = create_direct_keys(mvdev, mr); + if (err) + goto err_chain; + /* Create the memory key that defines the guests's address space. This * memory key refers to the direct keys that contain the MTT * translations From patchwork Wed Aug 21 11:40: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: 13771274 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) (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 26CA01AF4D2; Wed, 21 Aug 2024 11:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240518; cv=fail; b=gcE/zALQ/cMw1hNMAgBoBsE6qbci+zcuomUtnY9/3q/0I07GL8Xft/E9XdWrwOGD+9F5DrDHM0ZDLPPUCMW1y/d6lQ7gKlTn8FSvXDgCtObeWHTFFCrcfOpnfw6t5KbJVI0BCViEQCPSHXXH+dESzTIr4kdSalX5Kju0M21oOX4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240518; c=relaxed/simple; bh=7I1TGKYW04eaVAa1LUFTHVzvQtPOy+WP3Rr6YKxUN7c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NRvShSY9XSlLFRFPTwwCPUu4pZ1tpgfCfsnj9fs0E09ZO4ESS+1IBsvKGscEn6ajNthJomnm4TKsqGQshdtooZDtYGrQZ6pnoJ++aVzQchPFnfPSs6l9dppYUpGKl3BprR6gMgiUNPBzkNWIhjUvGt2Nx6P0f2ZrxRWhxZJtzCY= 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=rnYHQEp7; arc=fail smtp.client-ip=40.107.236.41 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="rnYHQEp7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jJHI/Mxau3EUyqI3LyCgxqd/xsbnMTB376e/z0vkLqT5FZV2eU7FnasNyn2NbAUs2Rr619pVlzJUZh7dW4ROldPXBA6d1LSix/DCykOPT8ze9Zqs/oaIqcVKX1aHWL919A2duVbkZcJPJgPKuFgjGJ2U9DqRuDYq4uBPqfFv+2hWfcjFj87E3zfQ9joGQrf4lpICAV2QEavBhfBhqbLpPWvJRwRTGc02CP98jWjbE/lUrkrwYghhiI0OPyhhVuZxtKIvceRSkGcHsu/G3pCGJs9TTWptFGGTXGB/ruU9jywKBr3bTiuFVQB0RSHvTJhS+oja8QEfsUhS+lEdBumEHQ== 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=aal0rUukt5H+w8BsXsq9Qi8Qn6hcdXkHNTWV31qp6lg=; b=uXElq+rA330y5rwJIvSkL6bm9IAt7FXzifCopuWtpOZ+ytd9t5iqHoxITzwb2v1VYh+xtg64/19eq1vEhzo/ZLzeg3zubzJeq3RG4YLIN4NxEF+RWstDhti4ZByYFmATYCSp9fld1rxGjqeup+aGnGATU3+lvWtIW8YMAI7b8JytJKOdlCNSY1edgRlVbxad3U6MjGH+uFgrRrBp/PRfZgqQsJ8IVKvMaYRXs7xcIaOJGE1AnTaWLoGVORmcPJzwffmUX60M6CBqaqGD5Mz3Iena3SZdTbl/UxER97vmAfqgK+dQxe0A9xJgONK5KtLykbvfNYDG2gebFj/HRCXzyA== 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=aal0rUukt5H+w8BsXsq9Qi8Qn6hcdXkHNTWV31qp6lg=; b=rnYHQEp7NPc816mI2tSjDulSrEe4rpWJiZVCvNifnIS7jtLMOoFLiew9TfqOrFo7zhqtLxbHGGSWCbCfCLNWCxyN01+8zgMP1Dt3rUqLkZi2NaAZMwnjE0II5hMlo+7ki+jNQSFif+9l1UY3UhFDAb2gSfHIu3nO6XonMXwuAjxbXrKlblOxG72avJX7F/xoFjDqZrQKqLBqKIt/sH+4FHVzIg7SDZm3M4z3BnOBhAinihECBkNcuK8c+yZr6U8gIWHtLxTTzZ2WCBldd9AVFf7vtMzcfAttZjc8lAmrjf4ihk6/fIQ/KQnZlXi6QTOldBKwUwYRNRPot5XXN0CISQ== Received: from BN9PR03CA0353.namprd03.prod.outlook.com (2603:10b6:408:f6::28) by SA3PR12MB8802.namprd12.prod.outlook.com (2603:10b6:806:314::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Wed, 21 Aug 2024 11:41:51 +0000 Received: from BN3PEPF0000B373.namprd21.prod.outlook.com (2603:10b6:408:f6:cafe::f) by BN9PR03CA0353.outlook.office365.com (2603:10b6:408:f6::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.25 via Frontend Transport; Wed, 21 Aug 2024 11:41:51 +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 BN3PEPF0000B373.mail.protection.outlook.com (10.167.243.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.4 via Frontend Transport; Wed, 21 Aug 2024 11:41:51 +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; Wed, 21 Aug 2024 04:41:35 -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; Wed, 21 Aug 2024 04:41:35 -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; Wed, 21 Aug 2024 04:41:32 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , , "Gal Pressman" CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo , Cosmin Ratiu Subject: [PATCH vhost 2/7] vdpa/mlx5: Delete direct MKEYs in parallel Date: Wed, 21 Aug 2024 14:40:56 +0300 Message-ID: <20240821114100.2261167-4-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240821114100.2261167-2-dtatulea@nvidia.com> References: <20240821114100.2261167-2-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: BN3PEPF0000B373:EE_|SA3PR12MB8802:EE_ X-MS-Office365-Filtering-Correlation-Id: e426b2b9-deda-4f79-ec88-08dcc1d63f7f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: jHDjipdrFWpnRDun5/zhXy3kDuqJBmUcvOTZG2IBy0vqabsA55MPsHLslVfZxBvFR1Us7zUc3hx9IED74yX9+6DSoCJXInFT7I56IUWBHdEcCYD3vwIF1nvIFXWPxzJqMPT/kb7JFGZ8ypzC1kPV31asz++Vao1tLhf6kknDk1+4tWTjyviHSXv7te373vnWnmqGb+o9ldxkynC8X/w8ZGXJSLmnFd6nC7RX60VzcJgMpUfIWQ2hVzJkIw7sFNaw/5c+QElUvWrkdcA08ItMqryFZYOQxrIDEJqQXB13SlyFpV1oWMSITL2+U3RfFbIKflESfdGA1r9B5Hc4yqCM3r9JwOlNeZS7whP84Tx/ZxDStfAa+Uspa4PTMJaeBvwJiNg4bA9c4Xvo1tItwXeUSypM/ZKB26gF96W0AAJbPzhGzf6E+UbeMusZnj5ryiy+jHeWI92RhI08Re+UG5cc3AXMGxGO0yVMGdqhWlg7VX5MBp6n236bFPG4Z270EEOSS3dvifOGrMdiGz2BKu0lGJEa6OWpivCi+EsT8X+7mv/TNRJ/ynof5QQOafgD0WOMq+fuTS8q4uLwbmoiL8TqldGWmqVu9H22Q3A6fNumavCXzSyg4NQjatmovl4Shwapdgn97js+ZkEqjCzQ6iI2GAguG8flR0ziTxf4Ljq5zdgV2y575kJJuqGvsng2OBN1xIqkU5i9dL+L4EEuZDBR+eSIU2zVTVugLwDoMOd18slMZueOsdd2HgdcSmYz8VP04BbpzG9hxD9EVILnlqBHK4qn366dMNb9LdTpRlAhYjnOxY8bKaHXiSOASzQVpzoIXdu42TXuv98hoBXwDts5d2iI2iyMOdyCf6/CrH91tNCbPEO8EmwlwtEwUs1BURpIZEIdRWG5ptn4Lo4mVzs3UVFuQQvT4jugYJ6Xo519RpDpQ9yliN5lZfmM9aK6XNRzK142sd/F0rDtkwha4plzLOyn3Y4netugCPUHu3t/rePuPH2VHmr0HKgnMPvXF5tvYV+FjRCTcNDzxQx0answwSi8SIiwfGIeBDjfjj6hyl8aWahcokH0/MGIBJWXWHyGlAidWHRdPKq8KEeSBhu7NqfFXOMfHn+4UrJseJAi/3wvbAxCT4HK0PhIU0NCLG+nLj+k0M2K9hGTXYPtwKd+69tQf/BYUaiNG1nsUcEVApPDBymEK4BT3Fe+VJ6YfpgjCndCaTr/TMNYMIGni1StlaiJFqhswh7PdpB0xeCFBYzN28LF4PEBc7a1ItvjkcFg4vkWW3O3wTsG2qMmEmK41hdjVuqtIK5ERK7i5S3uUyKY1Vl6WeO14byhxuG590i5zN02RVX6r7Uug4cX1bNAcBX47uS/adxeH+cCeum0GB3qaXC1ZmjO0Ep157LFUyam5LwNYvqZRU+X92eHVvXSeXgXkx/l3Mu7hlMJmOyTAH+gFeVYdZV5brP8JzZJNtQY 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)(82310400026)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2024 11:41:51.0246 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e426b2b9-deda-4f79-ec88-08dcc1d63f7f 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: BN3PEPF0000B373.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB8802 Use the async interface to issue MTT MKEY deletion. This makes destroy_user_mr() on average 8x times faster. This number is also dependent on the size of the MR being deleted. Signed-off-by: Dragos Tatulea Reviewed-by: Cosmin Ratiu Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/core/mr.c | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index 66e6a15f823f..8cedf2969991 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -55,6 +55,11 @@ struct mlx5_create_mkey_mem { DECLARE_FLEX_ARRAY(__be64, mtt); }; +struct mlx5_destroy_mkey_mem { + u8 out[MLX5_ST_SZ_BYTES(destroy_mkey_out)]; + u8 in[MLX5_ST_SZ_BYTES(destroy_mkey_in)]; +}; + static void fill_create_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr *mr, struct mlx5_create_mkey_mem *mem) @@ -91,6 +96,17 @@ static void create_direct_mr_end(struct mlx5_vdpa_dev *mvdev, mr->mr = mlx5_idx_to_mkey(mkey_index); } +static void fill_destroy_direct_mr(struct mlx5_vdpa_dev *mvdev, + struct mlx5_vdpa_direct_mr *mr, + struct mlx5_destroy_mkey_mem *mem) +{ + void *in = &mem->in; + + MLX5_SET(destroy_mkey_in, in, uid, mvdev->res.uid); + MLX5_SET(destroy_mkey_in, in, opcode, MLX5_CMD_OP_DESTROY_MKEY); + MLX5_SET(destroy_mkey_in, in, mkey_index, mlx5_mkey_to_idx(mr->mr)); +} + static void destroy_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr *mr) { if (!mr->mr) @@ -255,6 +271,55 @@ static int create_direct_keys(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr * return err; } +static int destroy_direct_keys(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) +{ + struct mlx5_destroy_mkey_mem *cmd_mem; + struct mlx5_vdpa_async_cmd *cmds; + struct mlx5_vdpa_direct_mr *dmr; + int err = 0; + int i = 0; + + cmds = kvcalloc(mr->num_directs, sizeof(*cmds), GFP_KERNEL); + cmd_mem = kvcalloc(mr->num_directs, sizeof(*cmd_mem), GFP_KERNEL); + if (!cmds || !cmd_mem) { + err = -ENOMEM; + goto done; + } + + list_for_each_entry(dmr, &mr->head, list) { + cmds[i].out = cmd_mem[i].out; + cmds[i].outlen = sizeof(cmd_mem[i].out); + cmds[i].in = cmd_mem[i].in; + cmds[i].inlen = sizeof(cmd_mem[i].in); + fill_destroy_direct_mr(mvdev, dmr, &cmd_mem[i]); + i++; + } + + err = mlx5_vdpa_exec_async_cmds(mvdev, cmds, mr->num_directs); + if (err) { + + mlx5_vdpa_err(mvdev, "error issuing MTT mkey deletion for direct mrs: %d\n", err); + goto done; + } + + i = 0; + list_for_each_entry(dmr, &mr->head, list) { + struct mlx5_vdpa_async_cmd *cmd = &cmds[i++]; + + dmr->mr = 0; + if (cmd->err) { + err = err ? err : cmd->err; + mlx5_vdpa_err(mvdev, "error deleting MTT mkey [0x%llx, 0x%llx]: %d\n", + dmr->start, dmr->end, cmd->err); + } + } + +done: + kvfree(cmd_mem); + kvfree(cmds); + return err; +} + static int create_indirect_key(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) { int inlen; @@ -563,6 +628,7 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr struct mlx5_vdpa_direct_mr *n; destroy_indirect_key(mvdev, mr); + destroy_direct_keys(mvdev, mr); list_for_each_entry_safe_reverse(dmr, n, &mr->head, list) { list_del_init(&dmr->list); unmap_direct_mr(mvdev, dmr); From patchwork Wed Aug 21 11:40:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13771273 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2088.outbound.protection.outlook.com [40.107.236.88]) (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 BB15B1AF4C6; Wed, 21 Aug 2024 11:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240518; cv=fail; b=umBAnSv1Icc37OWUZkTze+9Bm0Td0o0ewRrVny8R1rMVsZBhU17SCNIsIuMp60kkbEHWK3eQx0wzejCmUfRcbWdOeA+W7/np40xvmcUiNF8066RmjCnBdHfsfbrc5jQ5qFCU8VSlguwysvgITN78yYb8x6IFjE0YL1R6Gi/SEWI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240518; c=relaxed/simple; bh=B99iV/82iKQbHub91kQZzVytCTtsTt+PrPW0hbjqZ2o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Clv1QuPAe6dlqQ1f3fuzaDAqy4F4t0Z08B5mwiF/Ze8HDMOsIIF9LWLv/v/IkdKf0VJDPsD3cp6GaYyvOWR7bi6bYnm2Fxyt8/zh4FxegvElcUImo6r4aOgbJjOPkquMAqGfGE3MrMfDN277wu0PtaxmM72tr2vnEY2KfpUlLH8= 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=IfEni7b+; arc=fail smtp.client-ip=40.107.236.88 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="IfEni7b+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Mfb2ShL6f10lUO4Ss+ALfzBK8LiiftKTbYeL/e4Tny1Am86hqIddoJ0odqj7nPiFUPjkFExFejHu5XkuCrsryQSocYQjrhDDpUir1N9vXmudS3TcTLgvQrlKVO+YRZxdQbRIM3N3xCKR/lENZW5uGuX3iH8svaTZNakZdKuyFqXhdoBEcB4W9EaqtLdqVNJe4q/6d9jnJiLZOVlquTgmJfS6rOjHJzsiRF7W2IaQwQs3Oh8FrtO2U1o9KckZQybjx1+3zOKoZR700YF+hhB3zjudpfaKkCE/nJmRgUIKqz46wJqA5gkXdCwQV6nEjc5Xk+JfN+6yLkZ6wSXvSzJtxQ== 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=T4d+PTjaMFkC4xdZw3JnzT0oM8Mh0RfDqURheqd+GKE=; b=quEPLw2RLS1OAxyiXaoFqZuOx1sSi3GQdw65/bOy4OrU3BBVza8BwixVBYxbzScgHoFc7f5tqYaBYiRV94GIMZrGbWYcErNjq7qjSaExN7Dh+qRMEuARjqHiHhFXw29uNWM+CwQeRQZp3PlJX3B+e7BI165Am8uA+DVU20XCNwm/DWS6dwy+oYi/Rr321uj4ROI9KvW4NoblMpuco82EErlRC4ov+nBR7azXoZmIJVmS1LKfFiZdvXps5gjYY5GZZxl6trVTNf1xXJ92bYnq7p45aYfeLfNDfkPCjA6QZR5i2RaQdltMlelI6Sm6FJPaUjkNaxe8N3QxEOaFi2KBVQ== 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=T4d+PTjaMFkC4xdZw3JnzT0oM8Mh0RfDqURheqd+GKE=; b=IfEni7b+OSSa/cRnLDxvZ8kGb7QOP2fPdP64IewXlirrixLfjbgimr2qMspnvJHYnoDYlY/RCobQ/i2dh+AT5fhcLSv8ba6TqWxiTNE4w45LOF5gLnjIhuUvX89AzbEn4dBz4Sdwe0zht22ypXZI1lKnFWuXAN2WrUbb82fMlX+dKU/FE2/SX8FjRuB+3yQYQivhcZ2o8LqpGR+sk8fcsKzRAOQploO6BWZ9vIQYUEDVnN7VGFW6i2fWdA3oeBz4btVYVpl8BvNiw7fcJN0Uf0noVVE7PR+60faI2ot4r/xuiwqPG6hHQc1cqfiYw8s/5KHRR/KPN6nIMRl+xlGsWg== Received: from MW4PR03CA0310.namprd03.prod.outlook.com (2603:10b6:303:dd::15) by CY8PR12MB8314.namprd12.prod.outlook.com (2603:10b6:930:7b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.25; Wed, 21 Aug 2024 11:41:52 +0000 Received: from CO1PEPF000044EE.namprd05.prod.outlook.com (2603:10b6:303:dd:cafe::99) by MW4PR03CA0310.outlook.office365.com (2603:10b6:303:dd::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21 via Frontend Transport; Wed, 21 Aug 2024 11:41:51 +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 CO1PEPF000044EE.mail.protection.outlook.com (10.167.241.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11 via Frontend Transport; Wed, 21 Aug 2024 11:41:51 +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; Wed, 21 Aug 2024 04:41:39 -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; Wed, 21 Aug 2024 04:41:38 -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; Wed, 21 Aug 2024 04:41:35 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , , "Gal Pressman" CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo , Cosmin Ratiu Subject: [PATCH vhost 3/7] vdpa/mlx5: Rename function Date: Wed, 21 Aug 2024 14:40:57 +0300 Message-ID: <20240821114100.2261167-5-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240821114100.2261167-2-dtatulea@nvidia.com> References: <20240821114100.2261167-2-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: CO1PEPF000044EE:EE_|CY8PR12MB8314:EE_ X-MS-Office365-Filtering-Correlation-Id: d5e2a10b-b1b8-448a-c9d3-08dcc1d63fd4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: 0gLKV2FaWiEcmqeHxgHYXU7Jotedi8NTFe3gpQcAZLTg89Hz2Sz1/9SE8DUPtHc2EbL2YkIPBEH/ic9QjZBva83iITTBn7tjPJKljMOM0I/hzkmaavRtQ7mlmmZuUzPsb1fjUGh2V7mADYWDTXavSY3qOZmTfn78TJ862CFBtlAFxfls5ijt4oC4LsPMhkNFtvGK3dcI6hHReELycd2KLr5tX2+O63FzNuU9BjfXlpj2gKBVra7RdI0y0FOP24bZjk/BDFMxTr1SzM4fU5ayEBBUztyPNtbkzBG+56Tkf0Q9L02NaKMTRB/pfOCWfPysxiOBJnO72yXE+/z1mGVS7uHS5BY+A4tSeUnw9JZi57BCyi/gyul2ZhmutnlK9JJh1/806YJMI+ZbwNCjewc6hpy19d8DO31nJmICrp8tdStkajWlGJ1a+kKRvgtC02+dRby/FnDbw5KVtUvHpXBzP0VxV0RJfPqVNiw3IGJvyp92GVX2bTvi8948tcpydl+IK9MrOKxkdHO2eNVV8CeXSXvQJMj4rE7fOVPDQ2MVHJVkEr38Y7MEiEvf/b9mNvkh4U6/2NUVPgvza8cGbNijm3NbsbqsIDsXa14oZNHVo3ONwQATNB7EBYs4ZrN0Uj4XPeDJQwVpKwzpyHt8uGRoPVX0b31wdlAmk3A05Ih1YwTTSLEjNs3LHrvoe+o8MiYOMVpncaPxo4jkxvHhigJFDCpbAVY2ZxEmVjx+BkuWyFEJnUh3EIQkRFRet5ykmv7v6D0nDSoBUMjD0O4X2qjd2mni6yz4KXKxGwB0vHq2C3CsCn808fxAeqhjdeNJQDR+j4pWTYZJv9sBY1LiEea44GZzvuY3lcTvV/NRhfDTR750Fvz2cYqaaNSjWTUjUifuvYd3nELsoUToqi+cIUorZkcY7wuzNERulcpbGE1X4kKAOubQEr3Q3fRCX10sP/ZTKdHDUUKhjnGkKAt+uIByFDe9JHiXTqNyUCLiYGDwf6tZcjo5NVK/5rWWWRNFGbz/ZqSSQs0VcqKFf0MqS87K6s/wEZCrnXsKASztlYLRQZ+g57Xt5bHj7roCbbiwJXWyFM5N8pLOpiKpyRsF5M/91+rFzamemJoY31al0mF0Q0A0oEN8JZUJ9/PAlPywe5sxBGa1YO84uGHIKHPTRggnvoM71mdSvCazfJ4/MBqtV5sUfLL7aofAboejZoeUehZsMzH07MQ3flUk4ZTqhQST//oFhi/KQCbIs3zZNFXtoYey9qnXQauds+MI/IJTPAiD9UYcJxHZc5f8DQny76W+cljD7przUSb6Ae7EsSzciwMtdq5ryMhbaB95gNy9hcVPir4ijBRVg8JohdltHWvegPD+dUjniOyQvKZu9Rtta3CI92xBc6fcrJ1trMxMts0LN/HwlT0ZrQwdUsbCIqEc13URe9XyUQ42mC25P+vKH8QJyOseJKFNFND+SWjuQ6jB 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)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2024 11:41:51.6902 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d5e2a10b-b1b8-448a-c9d3-08dcc1d63fd4 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: CO1PEPF000044EE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8314 A followup patch will use this name for something else. Signed-off-by: Dragos Tatulea Reviewed-by: Cosmin Ratiu --- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 2 +- drivers/vdpa/mlx5/core/mr.c | 2 +- drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h index 24fa00afb24f..4d217d18239c 100644 --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h @@ -135,7 +135,7 @@ int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, u32 *mkey, u32 *in, int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey); struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb); -void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev); +void mlx5_vdpa_clean_mrs(struct mlx5_vdpa_dev *mvdev); void mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr); void mlx5_vdpa_put_mr(struct mlx5_vdpa_dev *mvdev, diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index 8cedf2969991..149edea09c8f 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -719,7 +719,7 @@ static void mlx5_vdpa_show_mr_leaks(struct mlx5_vdpa_dev *mvdev) } -void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev) +void mlx5_vdpa_clean_mrs(struct mlx5_vdpa_dev *mvdev) { for (int i = 0; i < MLX5_VDPA_NUM_AS; i++) mlx5_vdpa_update_mr(mvdev, NULL, i); diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 822092eccb32..cf2b77ebc72b 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -3223,7 +3223,7 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status) err_driver: unregister_link_notifier(ndev); err_setup: - mlx5_vdpa_destroy_mr_resources(&ndev->mvdev); + mlx5_vdpa_clean_mrs(&ndev->mvdev); ndev->mvdev.status |= VIRTIO_CONFIG_S_FAILED; err_clear: up_write(&ndev->reslock); @@ -3275,7 +3275,7 @@ static int mlx5_vdpa_compat_reset(struct vdpa_device *vdev, u32 flags) } if (flags & VDPA_RESET_F_CLEAN_MAP) - mlx5_vdpa_destroy_mr_resources(&ndev->mvdev); + mlx5_vdpa_clean_mrs(&ndev->mvdev); ndev->mvdev.status = 0; ndev->mvdev.suspended = false; ndev->cur_num_vqs = MLX5V_DEFAULT_VQ_COUNT; @@ -3433,7 +3433,7 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev) ndev = to_mlx5_vdpa_ndev(mvdev); free_fixed_resources(ndev); - mlx5_vdpa_destroy_mr_resources(mvdev); + mlx5_vdpa_clean_mrs(mvdev); if (!is_zero_ether_addr(ndev->config.mac)) { pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev)); mlx5_mpfs_del_mac(pfmdev, ndev->config.mac); @@ -4008,7 +4008,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, err_res2: free_fixed_resources(ndev); err_mr: - mlx5_vdpa_destroy_mr_resources(mvdev); + mlx5_vdpa_clean_mrs(mvdev); err_res: mlx5_vdpa_free_resources(&ndev->mvdev); err_mpfs: From patchwork Wed Aug 21 11:40: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: 13771275 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2053.outbound.protection.outlook.com [40.107.244.53]) (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 D30E71B1D64; Wed, 21 Aug 2024 11:42:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240524; cv=fail; b=fXxL+d4RSVzKw1/y3Fzky+XiPUBtYda6uDM83lVgXVevY6Enap0NyFN0qIx87U/XaCo3M5RfJEg4mrAZCpxr1Lhb/jTT0TyaSY4PYPlLWoiUUfpl51AxCBALFsfdTDqXvgPqneuk3v5TPV8o+KWHcfTNaCUOSFuwoIxwzqRc1xQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240524; c=relaxed/simple; bh=8IMf4Sex1IUf18nsEg7339WEtdRcI2DWTUMuWmug1vA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UAv/zUdc9E5gMQP5tHjYiv9v+Dq7+wPEqASirVPR0+gMudqj8oQB+SCC/arReJ7xF4a8Y/Re3LWXrISMNIVCu5OrAcVQp+haSLYzanesuL6h3Ai/oIuoBGM/TnwByC1weMregWbmOMsrcjFTjGoZnVd1P9dWOrR7mJjXtJufs4M= 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=poMIRyW0; arc=fail smtp.client-ip=40.107.244.53 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="poMIRyW0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iJNjmLb/3tI7dhyOwwTcYtUgNYUl/gjj4aovb2E/Ku7tQzycHWLbGyDDIxAXGMHOPClprHdxfDFlkkvqFV0srmGPTlOtbGfNITKxbZseWBWn6uyuaVquXnxp4BQHQFfye7lJvim55FqVsAYC7nQOZeTYcetO0lagOF3fuexFNvmub6B9JuD8o9G8Zz1OgxFg+1tK8WtReueSKQ/VTbm703A2dNTh7ff9xOepS8d1fR/IU/4rw49l5LuVpg4LAcWpg1DnagPif9n3RPwtcYRJl1vqvsgSCACiorD7V8vqK5UTl9L6O75FljgQ4g8kLyNh510sQAtMt3p/Gjx0uAuyiA== 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=dezIsVnCW5rqORGKntVGu1gn2mFX2ipsFBXuwgM+QMc=; b=xvlyAdTFChlH3pXQI0b6iaWLRoF71yTU+kys+rLGBkCrSVr7aSJoFCxR2tWQpd9Bvt4GLhZsB3XcZ5d84tQqJwweM721r51+nYwcZ6oPkSVuBdkVWu9Z0a/7BvVkrb3xhSn0xG+21igxU50gmP6zn6W3yvvhFmFqTNp4i2U2H86GPhoxRlnil+BHwlYlwg4/T112rnlUk4TaJLPhlafOmvJMFhboI7qOjtTaMQUX3PaoYABUqDIX0WaPfK/ItaekLMGPTXY64xg2hkFE0rXM9cXQkxaWzIGzOY2vB5+9ogPGKk9GfdniIpi1O1u4pr1jcgu+WcdmgrUqwg3c2ck75w== 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=dezIsVnCW5rqORGKntVGu1gn2mFX2ipsFBXuwgM+QMc=; b=poMIRyW0SFW1ADu1eOcc/JAQUmLDPbNB0e4XysoF4xpFZE/yKYmxvoHI+VXMcfC2CnR9F+39hBwobi6F7fWvtNid6I6NNqfr3un5sLAE/6RHeHWhpoWfO1BbHRN4e1x8vn/atGYxnAaCsuFFzys3Q41CGDGY3B2SG5fo9PH9695qzByogimPAMZYUK7IEalIREP640AtbHDDL00SBGwpAq01Iudy81KvaccmwurhN8fDbv63nWQqtkxDapvsOugL6xHxnQM981fsr/7oqohVjO3TVnauVgVCmfJqj74Qa01DQsFwxdqox9EN5GOhXfpHwBvhc8u7GrMWifXe3viAAQ== Received: from BN9PR03CA0349.namprd03.prod.outlook.com (2603:10b6:408:f6::24) by LV3PR12MB9353.namprd12.prod.outlook.com (2603:10b6:408:21b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Wed, 21 Aug 2024 11:41:58 +0000 Received: from BN3PEPF0000B373.namprd21.prod.outlook.com (2603:10b6:408:f6:cafe::ad) by BN9PR03CA0349.outlook.office365.com (2603:10b6:408:f6::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.19 via Frontend Transport; Wed, 21 Aug 2024 11:41: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 BN3PEPF0000B373.mail.protection.outlook.com (10.167.243.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.4 via Frontend Transport; Wed, 21 Aug 2024 11:41:58 +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; Wed, 21 Aug 2024 04:41:42 -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; Wed, 21 Aug 2024 04:41:42 -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; Wed, 21 Aug 2024 04:41:39 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , , "Gal Pressman" CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo , Cosmin Ratiu Subject: [PATCH vhost 4/7] vdpa/mlx5: Extract mr members in own resource struct Date: Wed, 21 Aug 2024 14:40:58 +0300 Message-ID: <20240821114100.2261167-6-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240821114100.2261167-2-dtatulea@nvidia.com> References: <20240821114100.2261167-2-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: BN3PEPF0000B373:EE_|LV3PR12MB9353:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a47666d-1f04-40fc-043a-08dcc1d64409 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: 8V+axgNGAZpHfxHG+2BzycacDQ1RxHeA5dFqeaJXd2AV3P0d9f6JgZFepBJUsRRmJcxVAczORCXmtw0SOsYbqLAfz14Xto616RpEHJsBPqVUkcqgicanUmRoI98FuUWIlfDrStjIZ1o/0SSxPdpwXdP1FVVE0trvd/Om26ICwO7KZrVBiZLHFJvBV19uwL/lxOrAgHvh6+YfzI1iat9x/eWBELczvj4t2MXIqXrQQ+ZBzgP2G075UMJtZ4fRsM0aFFswyYSf4miE8Rpxfi/OdTWr4pjeO9WpoHzzh/Nr5qEGmt6V9dHlqStpS0ZQeaPGvh1yXkmQSjoiSW9uw46ZagKvsz36uvIewBq1t/WlxwhtxYThJIKE4IWXu0fXF9dktQwfnoLFyFjYzyeVg3D4vew6eqaUwwHANoAuM4pZq4J1v0mhRKlTzEMDnTGSQeLU2LR9kAyryyAzbSAnGb6HMRO9dMalUIMWmqGUHyKXJHbofLjIB9vxA/JXwIYe+Bjtc7us6qTVSIL8tn2K2GsCdEBwBQDOh8ikyQ0LGWhmqNh2wVCP9twibRc4NTwJuLkIgj3/d0oOJOKpxns4pgoY80WcjdP+8RAWTywDM3F4g0TVXjVm+p+osA6fsxjUcuvG/DfhhbRy4l8DtLJczJEoftyMV0NuJ4MToHO/HTLQRUCqNN6iOC890hAHql2DJvxrrMvr44IvSOXLVXUUh17jC7W7eMZlIeseWBOuZiace20lOC2KkB/Wgy6RKeimKU5Ht+lCowkTX41CSHjI8iX2F6+7uoFlBzlCLvs+Oz7l9ZOPkRolm4Db5tpUHztTVPJlTEuzmJVgGCqJiG3VhOu+wNKgiCPnPIHZApCKg3C9WKRkKTIKKXtZNEf7SQRwz69sQPWL4A44H9Kwyj79jhiRu5ecR0T4PgHjIMC9034IxIRFlHGIJa72FHKkDN0leJP7w8uivACCdG0i3IgN54WvW82ZrTwnUjLFjZ5aa/NaXPnLXHgrUGSw9UNqSBBD/wkWluhteHLK/8HY8O/QPwsshGWL9xCHH2XfyrzHq7i7G+WLkDxEfeJpZYDrBjEfkyEoqyiAALuQihiNhUfbVQfeQ2/8WHOi/fByd4Za6n6gTc9z2TRuTtz8qjXBkskKZlagOZ2AA5Rp8I+nnRy884n7HaWs1veHyJ8fe80Wpd+u/L/CPUOG3SWKsJ0b3iYv0tTTqLvXIBw8JYwZgMWwfMwLxPP+FAtqEleFyoi8g4uZMt8cetQ8+QylTs+xVSCG48txxAUMQEX14WIOYeYULvqwHGx6Nv3Vjo9Pit5ux4mjiPtHUdFc2wq168g9Gwty/FOwFsbqX3ZZ9HHzxyxddhAEQ7r5u0KAMCq6ITimJxMbe7Ej8P4Iyj4HsDIAVLAYtFfE4GqJHlTkATMa3pEom+3QgOtoq3UJG4rmF77b+oERkEGi5q4CmAWJKlkMTyHiz3Fs 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)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2024 11:41:58.6340 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a47666d-1f04-40fc-043a-08dcc1d64409 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: BN3PEPF0000B373.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9353 Group all mapping related resources into their own structure. Upcoming patches will add more members in this new structure. Signed-off-by: Dragos Tatulea Reviewed-by: Cosmin Ratiu Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 13 ++++++----- drivers/vdpa/mlx5/core/mr.c | 30 ++++++++++++------------- drivers/vdpa/mlx5/core/resources.c | 6 ++--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 36 +++++++++++++++--------------- 4 files changed, 44 insertions(+), 41 deletions(-) diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h index 4d217d18239c..5ae6deea2a8a 100644 --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h @@ -83,10 +83,18 @@ enum { MLX5_VDPA_NUM_AS = 2 }; +struct mlx5_vdpa_mr_resources { + struct mlx5_vdpa_mr *mr[MLX5_VDPA_NUM_AS]; + unsigned int group2asid[MLX5_VDPA_NUMVQ_GROUPS]; + struct list_head mr_list_head; + struct mutex mr_mtx; +}; + struct mlx5_vdpa_dev { struct vdpa_device vdev; struct mlx5_core_dev *mdev; struct mlx5_vdpa_resources res; + struct mlx5_vdpa_mr_resources mres; u64 mlx_features; u64 actual_features; @@ -95,13 +103,8 @@ struct mlx5_vdpa_dev { u16 max_idx; u32 generation; - struct mlx5_vdpa_mr *mr[MLX5_VDPA_NUM_AS]; - struct list_head mr_list_head; - /* serialize mr access */ - struct mutex mr_mtx; struct mlx5_control_vq cvq; struct workqueue_struct *wq; - unsigned int group2asid[MLX5_VDPA_NUMVQ_GROUPS]; bool suspended; struct mlx5_async_ctx async_ctx; diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index 149edea09c8f..2c8660e5c0de 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -666,9 +666,9 @@ static void _mlx5_vdpa_put_mr(struct mlx5_vdpa_dev *mvdev, void mlx5_vdpa_put_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) { - mutex_lock(&mvdev->mr_mtx); + mutex_lock(&mvdev->mres.mr_mtx); _mlx5_vdpa_put_mr(mvdev, mr); - mutex_unlock(&mvdev->mr_mtx); + mutex_unlock(&mvdev->mres.mr_mtx); } static void _mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev, @@ -683,39 +683,39 @@ static void _mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev, void mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) { - mutex_lock(&mvdev->mr_mtx); + mutex_lock(&mvdev->mres.mr_mtx); _mlx5_vdpa_get_mr(mvdev, mr); - mutex_unlock(&mvdev->mr_mtx); + mutex_unlock(&mvdev->mres.mr_mtx); } void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *new_mr, unsigned int asid) { - struct mlx5_vdpa_mr *old_mr = mvdev->mr[asid]; + struct mlx5_vdpa_mr *old_mr = mvdev->mres.mr[asid]; - mutex_lock(&mvdev->mr_mtx); + mutex_lock(&mvdev->mres.mr_mtx); _mlx5_vdpa_put_mr(mvdev, old_mr); - mvdev->mr[asid] = new_mr; + mvdev->mres.mr[asid] = new_mr; - mutex_unlock(&mvdev->mr_mtx); + mutex_unlock(&mvdev->mres.mr_mtx); } static void mlx5_vdpa_show_mr_leaks(struct mlx5_vdpa_dev *mvdev) { struct mlx5_vdpa_mr *mr; - mutex_lock(&mvdev->mr_mtx); + mutex_lock(&mvdev->mres.mr_mtx); - list_for_each_entry(mr, &mvdev->mr_list_head, mr_list) { + list_for_each_entry(mr, &mvdev->mres.mr_list_head, mr_list) { mlx5_vdpa_warn(mvdev, "mkey still alive after resource delete: " "mr: %p, mkey: 0x%x, refcount: %u\n", mr, mr->mkey, refcount_read(&mr->refcount)); } - mutex_unlock(&mvdev->mr_mtx); + mutex_unlock(&mvdev->mres.mr_mtx); } @@ -753,7 +753,7 @@ static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, if (err) goto err_iotlb; - list_add_tail(&mr->mr_list, &mvdev->mr_list_head); + list_add_tail(&mr->mr_list, &mvdev->mres.mr_list_head); return 0; @@ -779,9 +779,9 @@ struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, if (!mr) return ERR_PTR(-ENOMEM); - mutex_lock(&mvdev->mr_mtx); + mutex_lock(&mvdev->mres.mr_mtx); err = _mlx5_vdpa_create_mr(mvdev, mr, iotlb); - mutex_unlock(&mvdev->mr_mtx); + mutex_unlock(&mvdev->mres.mr_mtx); if (err) goto out_err; @@ -801,7 +801,7 @@ int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev, { int err; - if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) + if (mvdev->mres.group2asid[MLX5_VDPA_CVQ_GROUP] != asid) return 0; spin_lock(&mvdev->cvq.iommu_lock); diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c index 22ea32fe007b..3e3b3049cb08 100644 --- a/drivers/vdpa/mlx5/core/resources.c +++ b/drivers/vdpa/mlx5/core/resources.c @@ -256,7 +256,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev) mlx5_vdpa_warn(mvdev, "resources already allocated\n"); return -EINVAL; } - mutex_init(&mvdev->mr_mtx); + mutex_init(&mvdev->mres.mr_mtx); res->uar = mlx5_get_uars_page(mdev); if (IS_ERR(res->uar)) { err = PTR_ERR(res->uar); @@ -301,7 +301,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev) err_uctx: mlx5_put_uars_page(mdev, res->uar); err_uars: - mutex_destroy(&mvdev->mr_mtx); + mutex_destroy(&mvdev->mres.mr_mtx); return err; } @@ -318,7 +318,7 @@ void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev) dealloc_pd(mvdev, res->pdn, res->uid); destroy_uctx(mvdev, res->uid); mlx5_put_uars_page(mvdev->mdev, res->uar); - mutex_destroy(&mvdev->mr_mtx); + mutex_destroy(&mvdev->mres.mr_mtx); res->valid = false; } diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index cf2b77ebc72b..3e55a7f1afcd 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -941,11 +941,11 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, MLX5_SET64(virtio_q, vq_ctx, used_addr, mvq->device_addr); MLX5_SET64(virtio_q, vq_ctx, available_addr, mvq->driver_addr); - vq_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]]; + vq_mr = mvdev->mres.mr[mvdev->mres.group2asid[MLX5_VDPA_DATAVQ_GROUP]]; if (vq_mr) MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, vq_mr->mkey); - vq_desc_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]]; + vq_desc_mr = mvdev->mres.mr[mvdev->mres.group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]]; if (vq_desc_mr && MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, desc_group_mkey_supported)) MLX5_SET(virtio_q, vq_ctx, desc_group_mkey, vq_desc_mr->mkey); @@ -953,11 +953,11 @@ static int create_virtqueue(struct mlx5_vdpa_net *ndev, /* If there is no mr update, make sure that the existing ones are set * modify to ready. */ - vq_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]]; + vq_mr = mvdev->mres.mr[mvdev->mres.group2asid[MLX5_VDPA_DATAVQ_GROUP]]; if (vq_mr) mvq->modified_fields |= MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY; - vq_desc_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]]; + vq_desc_mr = mvdev->mres.mr[mvdev->mres.group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]]; if (vq_desc_mr) mvq->modified_fields |= MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY; } @@ -1354,7 +1354,7 @@ static void fill_modify_virtqueue_cmd(struct mlx5_vdpa_net *ndev, } if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_VIRTIO_Q_MKEY) { - vq_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]]; + vq_mr = mvdev->mres.mr[mvdev->mres.group2asid[MLX5_VDPA_DATAVQ_GROUP]]; if (vq_mr) MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, vq_mr->mkey); @@ -1363,7 +1363,7 @@ static void fill_modify_virtqueue_cmd(struct mlx5_vdpa_net *ndev, } if (mvq->modified_fields & MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY) { - desc_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]]; + desc_mr = mvdev->mres.mr[mvdev->mres.group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]]; if (desc_mr && MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, desc_group_mkey_supported)) MLX5_SET(virtio_q, vq_ctx, desc_group_mkey, desc_mr->mkey); @@ -1381,8 +1381,8 @@ static void modify_virtqueue_end(struct mlx5_vdpa_net *ndev, 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]; + unsigned int asid = mvdev->mres.group2asid[MLX5_VDPA_DATAVQ_GROUP]; + struct mlx5_vdpa_mr *vq_mr = mvdev->mres.mr[asid]; mlx5_vdpa_put_mr(mvdev, mvq->vq_mr); mlx5_vdpa_get_mr(mvdev, vq_mr); @@ -1390,8 +1390,8 @@ static void modify_virtqueue_end(struct mlx5_vdpa_net *ndev, } 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]; + unsigned int asid = mvdev->mres.group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]; + struct mlx5_vdpa_mr *desc_mr = mvdev->mres.mr[asid]; mlx5_vdpa_put_mr(mvdev, mvq->desc_mr); mlx5_vdpa_get_mr(mvdev, desc_mr); @@ -3235,7 +3235,7 @@ static void init_group_to_asid_map(struct mlx5_vdpa_dev *mvdev) /* default mapping all groups are mapped to asid 0 */ for (i = 0; i < MLX5_VDPA_NUMVQ_GROUPS; i++) - mvdev->group2asid[i] = 0; + mvdev->mres.group2asid[i] = 0; } static bool needs_vqs_reset(const struct mlx5_vdpa_dev *mvdev) @@ -3353,7 +3353,7 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, new_mr = NULL; } - if (!mvdev->mr[asid]) { + if (!mvdev->mres.mr[asid]) { mlx5_vdpa_update_mr(mvdev, new_mr, asid); } else { err = mlx5_vdpa_change_map(mvdev, new_mr, asid); @@ -3637,12 +3637,12 @@ static int mlx5_set_group_asid(struct vdpa_device *vdev, u32 group, if (group >= MLX5_VDPA_NUMVQ_GROUPS) return -EINVAL; - mvdev->group2asid[group] = asid; + mvdev->mres.group2asid[group] = asid; - mutex_lock(&mvdev->mr_mtx); - if (group == MLX5_VDPA_CVQ_GROUP && mvdev->mr[asid]) - err = mlx5_vdpa_update_cvq_iotlb(mvdev, mvdev->mr[asid]->iotlb, asid); - mutex_unlock(&mvdev->mr_mtx); + mutex_lock(&mvdev->mres.mr_mtx); + if (group == MLX5_VDPA_CVQ_GROUP && mvdev->mres.mr[asid]) + err = mlx5_vdpa_update_cvq_iotlb(mvdev, mvdev->mres.mr[asid]->iotlb, asid); + mutex_unlock(&mvdev->mres.mr_mtx); return err; } @@ -3962,7 +3962,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, if (err) goto err_mpfs; - INIT_LIST_HEAD(&mvdev->mr_list_head); + INIT_LIST_HEAD(&mvdev->mres.mr_list_head); if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { err = mlx5_vdpa_create_dma_mr(mvdev); From patchwork Wed Aug 21 11:40: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: 13771277 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2085.outbound.protection.outlook.com [40.107.220.85]) (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 BE01B1B3B2E; Wed, 21 Aug 2024 11:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240529; cv=fail; b=F9KoUkYZBrsZ4/S+GY6DL7q1bx3FJ1Xi4vj1YWC1Fxg845aK/aMitzNL/TbkT51EKWLtO2HdIB1cvQODE3Vo1eD9ow+OaDqMlXdeRPzxjEzH0WGU/vmqmArPvRaDhB8EYxHyuo5bcNOeV8VX/GAoJA2T+wIaeRUx2+d186j+2zU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240529; c=relaxed/simple; bh=4urm2+xcIRqLKwfdspf4ZmxKI84/zfqAObIZJDJGjgE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RQvBDaOpgKr1J2SvEdKWDKp0/pO33zNhY/xwBLrq9hYgmyOUQT9Wm5TLt/3yCVxXM7DMiLZBkMPqt3EjBrbkqRUcCG41SQbc89sY0KYdwDRNygbse2slJCzWYyz+2F9ZzE83Ztal/ncFP8fuQtQRWqJRvu2f+jZ3zvohmWSKKfo= 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=TkMH2Iqf; arc=fail smtp.client-ip=40.107.220.85 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="TkMH2Iqf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oU0qX8OHjaM6iRjFtrdaRDRbUfCpYih+GFRkQQ8PuovIeXvLe4ikQQNDBTznAp+EZMi3sP9bw83nX4g2zNdezShSXKGmQFMhWFNf4d4CAj3qXQn/Tdvk4qHOstWHb82ADNPzfy/oaTKyAlrL8Qzs3b8v3canKG8YuPmEb0FIRm03C7LL1JhoHfRPosfBn3Ysl8YHAV5zxZZobJiWf5OsJtFN3FiM/gEj+Mh0kWzxpoLKpyLHlYFdm3cPx/mJt+aRDdaJZP1GSaLsmZm7BzWYBZmSVqpnP+BBGlGlnj0pebC32ZzKTOWAPd5hVxqFjxs4868vQj+YVSW6leTY4oybNw== 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=7EhGLrQKQnd7+m/Rm1T92MW0R30h1AOUmHsPkIzt9k4=; b=V1/7WtR6WDTIAa+zF0RWrxWX7GIBFhv/52qDcSAWLfyzAHMsigRdfClyJNXCVOK3rJyrV/fqwG8m62zVRjPrrl0reR9yn7jjQkaD9vmiM2uHEfXTW7Fj2awKOzwJTmkn+j9MGOM4lrr1mM13Qv3epvpaD3igqQbAiy4sm+o4IKL0H6PYjoljUiy4WixfRFy5VxH8L+IIvXOyTZHworA5oTnwifWnlDh6j54WXsLbzo8M7KSNcwxdvdfQ1s1yP+3xEdGthOo1kP5gxrImy21EEXZEi/q/W+doe5zFhYUypWbCgFhLmEYLC/7lAEa2i0qBsQYqzv9eZ3W4lyTaA7AanQ== 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=7EhGLrQKQnd7+m/Rm1T92MW0R30h1AOUmHsPkIzt9k4=; b=TkMH2Iqfi5sq3CLk0SQl9g5rQMgDIosD8k5eYkNOVbplTIPjW3nuCQLR8JU5rTKn1/E1RBhqT9B2SPJ1HFeI2T6xpRQK2xzFe4w7Ty/3Q7NcpaQKHmY76V5Fq4XAlDRafZR/VLR2YHzvYbimKafirLR4qQIaZyYGs2Llr9iowtWBxoyxQLtFbVGJde2uDHVGKpSYngACziJG+goNH/bnzj0ql02ZWSGUmCGUK7U9M8y8Ej1giVQk8os8DuQcKyKJil9G0UqqGfjjZS/NpA3r5FxMBWByxpcHURkujs4sAdW1aX7O3jbXflEJ8VPa7P7+w+Nnr6z8e2miiWGVpI98GQ== Received: from BN9PR03CA0276.namprd03.prod.outlook.com (2603:10b6:408:f5::11) by DM6PR12MB4218.namprd12.prod.outlook.com (2603:10b6:5:21b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.18; Wed, 21 Aug 2024 11:42:01 +0000 Received: from BN3PEPF0000B36F.namprd21.prod.outlook.com (2603:10b6:408:f5:cafe::82) by BN9PR03CA0276.outlook.office365.com (2603:10b6:408:f5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.17 via Frontend Transport; Wed, 21 Aug 2024 11:42:01 +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 BN3PEPF0000B36F.mail.protection.outlook.com (10.167.243.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.4 via Frontend Transport; Wed, 21 Aug 2024 11:42:01 +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; Wed, 21 Aug 2024 04:41:46 -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; Wed, 21 Aug 2024 04:41:46 -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; Wed, 21 Aug 2024 04:41:42 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , , "Gal Pressman" CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo , Cosmin Ratiu Subject: [PATCH vhost 5/7] vdpa/mlx5: Rename mr_mtx -> lock Date: Wed, 21 Aug 2024 14:40:59 +0300 Message-ID: <20240821114100.2261167-7-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240821114100.2261167-2-dtatulea@nvidia.com> References: <20240821114100.2261167-2-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: BN3PEPF0000B36F:EE_|DM6PR12MB4218:EE_ X-MS-Office365-Filtering-Correlation-Id: 3770dfd0-6188-4f48-a978-08dcc1d645c5 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: ocSnc3ou8O4M712szjSqjNeduHmSX4mSh6QkcUJ79ZChTiYL1MQxHTjLxwqSeD8SX4xYGuMUxik9NHYlGB66YTyWDUmZeGWWmIiAD1BLtsFf0oj6EPZ80YHYxeUFSloF48gDTB2HpSzoPrb0kuZIO1J05vqqnoZZokMZZ18xo7Ka1GMusamoDR4shrtVZB7Ua7bmqVIlH5nG7LeH/tAn25i4Q33q0mUMEY7s+E518UWNUrekejhRwk3c4xH3xl/jBCWU/IwBE8XyB/BvKEQawDcOWSez76Tqfx0mPdPLqTK4ETW6o1n5SuY4qIk0IpYeSIfdPw8ek/HChm+a4Z2dSVBNzGiZ1Y/FnKi7SBad1OVDFCB7O8BuewPpZuxYrawJUnJ7ifjhaQJIEhLyKC702r59HoO+qYP4Kb7Unb8WRo2GYJ/mX2fkyGzuJs3a8YPWq5RwJUnKBxbOD096tx/E6t6yJ71BxTuaY1BUqG/cQPxO5TA/vVdeTMjxmAJlC6duv6RVLMouHBAjt/cYKhISnnbUNhB0O7ojuChJ+qKztPGF/xAexLiSDkD+V91JDFbZgpa/PJbXT3Xgvf338TQ89P0ZNr85sH8/ToUTcZroBKIxw8vWVlHQherPhMkjHjxHi4MHSkrDF67OjUVmfbgg8dJRjf+H8D17PzASpi+21TN6wvZqeBoHfEH5W/GlilzxB2hQeY1LFUaMJhwa5NV1bcMk+xxFlENfkyaZK/qo/HhiQ8SLvJL8FSLN/CEorBWW8BIpt/njz31vzDvWde1BnXq4GcAXJJdDzf8R1IElZovjQ0Hc79DW39tnuQqv8VnrHZgAryo0xh9nfvAxhc3CfcI8eh1WusPt5n1+sN5MJprImJtFK8LTz4/yU53SMFbFiTu9Emy0YVGAoTSH+MFuUe4weE0C5ETIi3nxVaL8bsu4jHPtswkcqSSpWyqS1OxLpEoDKcg6T4cDvv3gZ9GbsybMlI3vXJPi1izZGe6F1rstL6Zz5V90r+Jd8X5CHW7NDHRNVMjFgoT/de452fQtZeXib1GjSI8WoAUhnow8riBkIWZw2Ufvv6rewHcTsmtLbzC6cCgvUoojXzyFAaNSm+yck16CjJDpYZ6djZu3LVkLjk91vnFAPSwMHdgDkAhe8PibbwxrrquQXqHKCYSenUGgMgdqch/OQUixsrYJbzNhxPsDCC1PMLm//rQBCmuQxGF1h164KSx2UTqEAsB6ZPTVDB7/NsP5Pj9gk7CEd/Hy+ZqD5pyjgiV6FOeYxARBuWNs8CSTAjVMh9tgZeyN7Ta0j55Knv4ycQQ6WyOLNc0amvRWzoy+EDA3ECFIxobE56oN+Xp11ZTCne3Byi9DQ6VtRzpvf03O3EkyLkb70ywKf5bBA8nOg5c1Bh4Z/mUWiiisyeqt1m1RTRJaUjttQtrrwncZ8PRQDRw0z/Rfs3ZGs3K7OIuBiD30fO09ybYp 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)(82310400026)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2024 11:42:01.5480 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3770dfd0-6188-4f48-a978-08dcc1d645c5 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: BN3PEPF0000B36F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4218 Now that the mr resources have their own namespace in the struct, give the lock a clearer name. Signed-off-by: Dragos Tatulea Reviewed-by: Cosmin Ratiu Acked-by: Eugenio Pérez --- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 2 +- drivers/vdpa/mlx5/core/mr.c | 20 ++++++++++---------- drivers/vdpa/mlx5/core/resources.c | 6 +++--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h index 5ae6deea2a8a..89b564cecddf 100644 --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h @@ -87,7 +87,7 @@ struct mlx5_vdpa_mr_resources { struct mlx5_vdpa_mr *mr[MLX5_VDPA_NUM_AS]; unsigned int group2asid[MLX5_VDPA_NUMVQ_GROUPS]; struct list_head mr_list_head; - struct mutex mr_mtx; + struct mutex lock; }; struct mlx5_vdpa_dev { diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index 2c8660e5c0de..f20f2a8a701d 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -666,9 +666,9 @@ static void _mlx5_vdpa_put_mr(struct mlx5_vdpa_dev *mvdev, void mlx5_vdpa_put_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) { - mutex_lock(&mvdev->mres.mr_mtx); + mutex_lock(&mvdev->mres.lock); _mlx5_vdpa_put_mr(mvdev, mr); - mutex_unlock(&mvdev->mres.mr_mtx); + mutex_unlock(&mvdev->mres.lock); } static void _mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev, @@ -683,9 +683,9 @@ static void _mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev, void mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) { - mutex_lock(&mvdev->mres.mr_mtx); + mutex_lock(&mvdev->mres.lock); _mlx5_vdpa_get_mr(mvdev, mr); - mutex_unlock(&mvdev->mres.mr_mtx); + mutex_unlock(&mvdev->mres.lock); } void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev, @@ -694,19 +694,19 @@ void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev, { struct mlx5_vdpa_mr *old_mr = mvdev->mres.mr[asid]; - mutex_lock(&mvdev->mres.mr_mtx); + mutex_lock(&mvdev->mres.lock); _mlx5_vdpa_put_mr(mvdev, old_mr); mvdev->mres.mr[asid] = new_mr; - mutex_unlock(&mvdev->mres.mr_mtx); + mutex_unlock(&mvdev->mres.lock); } static void mlx5_vdpa_show_mr_leaks(struct mlx5_vdpa_dev *mvdev) { struct mlx5_vdpa_mr *mr; - mutex_lock(&mvdev->mres.mr_mtx); + mutex_lock(&mvdev->mres.lock); list_for_each_entry(mr, &mvdev->mres.mr_list_head, mr_list) { @@ -715,7 +715,7 @@ static void mlx5_vdpa_show_mr_leaks(struct mlx5_vdpa_dev *mvdev) mr, mr->mkey, refcount_read(&mr->refcount)); } - mutex_unlock(&mvdev->mres.mr_mtx); + mutex_unlock(&mvdev->mres.lock); } @@ -779,9 +779,9 @@ struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, if (!mr) return ERR_PTR(-ENOMEM); - mutex_lock(&mvdev->mres.mr_mtx); + mutex_lock(&mvdev->mres.lock); err = _mlx5_vdpa_create_mr(mvdev, mr, iotlb); - mutex_unlock(&mvdev->mres.mr_mtx); + mutex_unlock(&mvdev->mres.lock); if (err) goto out_err; diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c index 3e3b3049cb08..fe2ca3458f6c 100644 --- a/drivers/vdpa/mlx5/core/resources.c +++ b/drivers/vdpa/mlx5/core/resources.c @@ -256,7 +256,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev) mlx5_vdpa_warn(mvdev, "resources already allocated\n"); return -EINVAL; } - mutex_init(&mvdev->mres.mr_mtx); + mutex_init(&mvdev->mres.lock); res->uar = mlx5_get_uars_page(mdev); if (IS_ERR(res->uar)) { err = PTR_ERR(res->uar); @@ -301,7 +301,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev) err_uctx: mlx5_put_uars_page(mdev, res->uar); err_uars: - mutex_destroy(&mvdev->mres.mr_mtx); + mutex_destroy(&mvdev->mres.lock); return err; } @@ -318,7 +318,7 @@ void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev) dealloc_pd(mvdev, res->pdn, res->uid); destroy_uctx(mvdev, res->uid); mlx5_put_uars_page(mvdev->mdev, res->uar); - mutex_destroy(&mvdev->mres.mr_mtx); + mutex_destroy(&mvdev->mres.lock); res->valid = false; } diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 3e55a7f1afcd..8a51c492a62a 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -3639,10 +3639,10 @@ static int mlx5_set_group_asid(struct vdpa_device *vdev, u32 group, mvdev->mres.group2asid[group] = asid; - mutex_lock(&mvdev->mres.mr_mtx); + mutex_lock(&mvdev->mres.lock); if (group == MLX5_VDPA_CVQ_GROUP && mvdev->mres.mr[asid]) err = mlx5_vdpa_update_cvq_iotlb(mvdev, mvdev->mres.mr[asid]->iotlb, asid); - mutex_unlock(&mvdev->mres.mr_mtx); + mutex_unlock(&mvdev->mres.lock); return err; } From patchwork Wed Aug 21 11:41:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13771276 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2074.outbound.protection.outlook.com [40.107.223.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 5A8621B253B; Wed, 21 Aug 2024 11:42:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240526; cv=fail; b=PiGWGvC2/oK+p9YfZWKiPy91Q609Z4rrxNnWe+Pdf33fKxNHnnSstcyfOW0tJrpbOmOBD6sws9uVwWnXx4rPN8mYztCkioVmG6R3dE7lFAIqp8wH++2igwQdpxFQCdFJDFXvgWtMRnrJdr+ajGiWNJDDfDlaFTkLWh7bLVt6Rb8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240526; c=relaxed/simple; bh=U1sIKMc8LQ66Bv9U0BivUu/LigTPV1lCnvbmZ5mId1s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=asHdVvFnphCXGBsZb4R+UmpTQIw3tadAyMvgCRelQGJtaeSbF2SI1DiCnv6RmmkNpSwPh5cvAsU6fNQkm+0SUXJWu8Q8D7nB7kga+y2BatKvbf1CgZh03kVnCU7Q3DIm8/5Z+VYxYw6khunOE65VN61gjuOxKPi4Sr+Obazs7NU= 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=cQSvW1Ts; arc=fail smtp.client-ip=40.107.223.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="cQSvW1Ts" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ssPpJjtj5NLp7JESL+mH6SFcCPzqtC6cHMlOxUPWj81lTsm8RSFdsKrB/MjU9ZMb2M9+Ri4l6k6W7+35jUVe6qnbgylr3rZOXaC302Grx5T4jawXenTtedydL1XzjpLz0he4icF0/XML9pcaTjYIjvvlHo0Q0ey/i/bzuAngrnThL9TtAL24CgdfXMM8YoRlvrfgx3kPR+GeF/pjhrFcf/+Gwa8Akdcfxc1LTbv/YHEPmcfc8IL0I4t6bQ/RDg1BOqRzHj4lMq5o5p4KXydHAUyEVhPJDXS7ER6hyQttAHlGndDWfVHaWn4LpZ+VnNM4IjdgX/Wqw3UEgWNv2Cfp7g== 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=/JzMx+i+G96tUwYKskpjpgDVQD+c8DXAXzYPTNkTEbA=; b=lDlkkxljuHJdKT169W+FiI1eUSSo9OB2kZl2B4Pjmn3mmiKdzizqvZXDHzoElnM5XlHPOJsCH6OXqcJpQ/xJeHArUMG9EQNbTCKSyUv3Ff2fdN9VPM81l2Bqcwc6kXqwD9Lv53n/xLPamWCwFG7M5xAC+WSIpqdWS9fmXgBZB+zfYCguziQAmr6uDvIAGfVvf3Tr+mu59pznpOROUzQHPzJ1sx6rCJYDueMQDzrPQpDwROq3l7ddlnQD48PW+kUfdHPD0m4Cd5+E0OHzy3nksNqjQVjKLr3TzXo5I5DFcayzSycaXHyxsUTwaTqyV+djSv65mycpaayoQI7ZUxBYEA== 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=/JzMx+i+G96tUwYKskpjpgDVQD+c8DXAXzYPTNkTEbA=; b=cQSvW1TsxT+aRXH9bpbVnyHBLXt7vanWtP/aU1n7ozSqk+LVqzOz3pUiIKxJkXuYU7G2PnTU3ekZaWKb4IR4F0IaXd3q40Aai7QR0/Ojeks53d9aDY8kF4rea/6t+POAJf1P5bWbJ7vKRZjHpsqGWQxh8q2OtM2HJWRc2Vn0u7ApPDPwXmu59a8BLp36fLZAz2lDU9AON8t+9ryiIDNua02u6Fkowz2EF3prsuvuL+pHy1oN8HGHYheBC0D7NXtEXtWSsUShCIaZ89EGryJ2+/DMFC5GguXsK2lDdT1Dpj+tKJQNnqf2pf6VeVAt/d9TgM9c67bZphY5xQ1uGT9QQQ== Received: from SJ0PR03CA0367.namprd03.prod.outlook.com (2603:10b6:a03:3a1::12) by CY5PR12MB6369.namprd12.prod.outlook.com (2603:10b6:930:21::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.16; Wed, 21 Aug 2024 11:42:01 +0000 Received: from CO1PEPF000044F0.namprd05.prod.outlook.com (2603:10b6:a03:3a1:cafe::fc) by SJ0PR03CA0367.outlook.office365.com (2603:10b6:a03:3a1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.16 via Frontend Transport; Wed, 21 Aug 2024 11:42:01 +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 CO1PEPF000044F0.mail.protection.outlook.com (10.167.241.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11 via Frontend Transport; Wed, 21 Aug 2024 11:42:01 +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; Wed, 21 Aug 2024 04:41:50 -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; Wed, 21 Aug 2024 04:41: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; Wed, 21 Aug 2024 04:41:46 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , , "Gal Pressman" CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo , Cosmin Ratiu Subject: [PATCH vhost 6/7] vdpa/mlx5: Introduce init/destroy for MR resources Date: Wed, 21 Aug 2024 14:41:00 +0300 Message-ID: <20240821114100.2261167-8-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240821114100.2261167-2-dtatulea@nvidia.com> References: <20240821114100.2261167-2-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: CO1PEPF000044F0:EE_|CY5PR12MB6369:EE_ X-MS-Office365-Filtering-Correlation-Id: 50e2cb66-15f4-4837-073d-08dcc1d6456a 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: 9xpQevqBwpwT+XW6kbywSKoTw8YSKDTwkLlyHT/G27dUhYtD9OPIiU9tOZKOgwAtfRyJvbaCuxPzev5RM0ME5+WSGbaDgCbzaWbQrSnmE1XdG/dFB07XelBfQ9/Mch4cDbr9lcEU002ikPoFQuIEbeRZKd9aqxbcS87kDtjQUn4oMhiLWpX+QqOktm77uFHw2tKt4ZxTDuqSOzFXXdRdQn+j7NEOSY+qbMIYFcvOawKAHmHGZUgT1OjK9tLZlQbn4m1KoTXqXYY6z3ZeUc6JuA8a32q8D8+bPpj/nLXdXep9rebGd3cG57GkV+jxpNptqyKa/4YfQkko1W9IIFi05qhuNU0MnYa7GOVzeldb1G3J2nZWWuIElvNvTISlGGKx5N595EgWr8+oWV2FaVrOwGsprmDZuAuJwpWzRTpUFR0QLykN/ybf7RPouIxfTRpZlPoQFf1+6VHmS7CII9jMNJhTxU9AGW1R/iAsWw6y19G2E9cKjBIBehqLt3XvSqhV5e6qXAhbpwvbmsvrAR40QRQIfo4WCudN4C53FUaMhjNO7r8jyBRs8D9RunmgSefid8WrFD6gzGEjhJs4cUfE70S+OytQlJgjmFtyxG7p7ALTQsfYRZ92fMz084u5UF+I/c2FH8bYz4CmsNpyjsveSHl1kJchlwuY8k/513JOoQcbgkk/5cezf+UFeJvMEFlpW8kaCCRqPLCAontsDfKi9N6w/IwgmoMmUAqBjuuJpPS/Y2/PEmFPwG6aFUc8ZXzATjYqq0C7lmLUtYLO37xjPn8OVQhm+dIMVdhrRaEiaQCPN2Dy4W0NH9MQUzOSUa1Hq8L+sX3ixwa8Y5o2O0uMI71ThJeIM0zEh/GHQlw+v97d0DYy5+ls5Ge5+AJ+fwAgA8eqW8VggSmwhOSdAoAOc1+W4Ucxbu0rAT+tikIzG3yYxg/uvlPuESsMcXjvz4Fpg+X5jakGysTO0hXsaO070YK1weVXRfHGcaE3Sk2GufQ/Okg15g015PQbPR3Bnalnoa0IuMsQyXkq2C2WKmShZZepstR0K4Nnzipmei60mq1NnlV0U0/gnHhh02CyxwIae3NbVBagbOKByY0y5psYDdIw7vqpy+IE5pc6n5z3M2NK6phFpLJKXanWXXzZXDzbm9ZpbGNHgPpYQXYJwZGf3XrgaT2QAbQ8mEM4FXNM8gGaztcgebxQFtLbYo55zGO9wSGl5L2QMpebz9OhJkS+CMj6K50hUnwTlcv3+6K2KIhpJYCss1JS6870FbR1ZMeaHvLOjjeHtAgjTShx4knzX9G2IGFTJ5NRwUoYq7pymQUU/HT6y4Sy/i7/qxEhD7gYBvG1prDQlfsFNmFzj264OwSU4028eCz+ysT5HddKBoj//MMxn1LoUFvtqg7/kvqSlpjw++LsG1OzR6rzV9Oo2WLAyjQaR+tbJ9cbAkE1+lWf3QfhpnzQNK2mF/u8w4Lk 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: 21 Aug 2024 11:42:01.0568 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 50e2cb66-15f4-4837-073d-08dcc1d6456a 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: CO1PEPF000044F0.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6369 There's currently not a lot of action happening during the init/destroy of MR resources. But more will be added in the upcoming patches. Signed-off-by: Dragos Tatulea Reviewed-by: Cosmin Ratiu --- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 2 ++ drivers/vdpa/mlx5/core/mr.c | 17 +++++++++++++++++ drivers/vdpa/mlx5/core/resources.c | 3 --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 10 ++++++++-- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h index 89b564cecddf..c3e17bc888e8 100644 --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h @@ -138,6 +138,8 @@ int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, u32 *mkey, u32 *in, int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey); struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb); +int mlx5_vdpa_init_mr_resources(struct mlx5_vdpa_dev *mvdev); +void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev); void mlx5_vdpa_clean_mrs(struct mlx5_vdpa_dev *mvdev); void mlx5_vdpa_get_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr); diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index f20f2a8a701d..ec75f165f832 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -843,3 +843,20 @@ int mlx5_vdpa_reset_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid) return 0; } + +int mlx5_vdpa_init_mr_resources(struct mlx5_vdpa_dev *mvdev) +{ + struct mlx5_vdpa_mr_resources *mres = &mvdev->mres; + + INIT_LIST_HEAD(&mres->mr_list_head); + mutex_init(&mres->lock); + + return 0; +} + +void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev) +{ + struct mlx5_vdpa_mr_resources *mres = &mvdev->mres; + + mutex_destroy(&mres->lock); +} diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c index fe2ca3458f6c..aeae31d0cefa 100644 --- a/drivers/vdpa/mlx5/core/resources.c +++ b/drivers/vdpa/mlx5/core/resources.c @@ -256,7 +256,6 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev) mlx5_vdpa_warn(mvdev, "resources already allocated\n"); return -EINVAL; } - mutex_init(&mvdev->mres.lock); res->uar = mlx5_get_uars_page(mdev); if (IS_ERR(res->uar)) { err = PTR_ERR(res->uar); @@ -301,7 +300,6 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev) err_uctx: mlx5_put_uars_page(mdev, res->uar); err_uars: - mutex_destroy(&mvdev->mres.lock); return err; } @@ -318,7 +316,6 @@ void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev) dealloc_pd(mvdev, res->pdn, res->uid); destroy_uctx(mvdev, res->uid); mlx5_put_uars_page(mvdev->mdev, res->uar); - mutex_destroy(&mvdev->mres.lock); res->valid = false; } diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 8a51c492a62a..1cadcb05a5c7 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -3434,6 +3434,7 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev) free_fixed_resources(ndev); mlx5_vdpa_clean_mrs(mvdev); + mlx5_vdpa_destroy_mr_resources(&ndev->mvdev); if (!is_zero_ether_addr(ndev->config.mac)) { pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev)); mlx5_mpfs_del_mac(pfmdev, ndev->config.mac); @@ -3962,12 +3963,15 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, if (err) goto err_mpfs; - INIT_LIST_HEAD(&mvdev->mres.mr_list_head); + err = mlx5_vdpa_init_mr_resources(mvdev); + if (err) + goto err_res; + if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { err = mlx5_vdpa_create_dma_mr(mvdev); if (err) - goto err_res; + goto err_mr_res; } err = alloc_fixed_resources(ndev); @@ -4009,6 +4013,8 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, free_fixed_resources(ndev); err_mr: mlx5_vdpa_clean_mrs(mvdev); +err_mr_res: + mlx5_vdpa_destroy_mr_resources(mvdev); err_res: mlx5_vdpa_free_resources(&ndev->mvdev); err_mpfs: From patchwork Wed Aug 21 11:41:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragos Tatulea X-Patchwork-Id: 13771278 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2048.outbound.protection.outlook.com [40.107.243.48]) (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 9DD801B5EB4; Wed, 21 Aug 2024 11:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240536; cv=fail; b=CmLhkqSj0OuF7RzW9NEFs5L1+Jg8zf0gKrZr6U49lBrMFFUU8aCHTX5D+eTnFNNQtGvxVQZIljeUrgt593OIeyJZQ2Xu8NeqhLNezZ0kr6Tvr229Iv0WPHcTuukRJj9FIrtYJSdamcmxzpfDFJhm/FRojUCyKHFdUQLG9rOh8PQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724240536; c=relaxed/simple; bh=5uGpCs1fWERSSPpGQIGuNCPxX/YeG+aOuuHcltw749k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r9yHQxNqPy5VTM3v28tcMZfWWtLqdsmkVReQm1waCugB8S9tshR82wzhEp39/huB7kuHmPOaK7x0eEdPQwEoHt6fzi399XHLAKVG0Bik/I7ZNpEMIV93+5i6sMEF5/rkJO+0eMmHhfYzqj9ifMHT5ez8NUfQzWiuIx2WZLNj/Zk= 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=RMRECfKC; arc=fail smtp.client-ip=40.107.243.48 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="RMRECfKC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=m2wZ5e7c2blVbZArdKMn8nL/i5OUcQbZ4m1wWGSNxwPkOqMZgZW95oqked0nBGQpkDWEndsVjWf62AQkoAZ+qkrISNz3C/thTpn27iTUtN1eaxhfT6CV+G0xIc2kU4yrGqCy7Ucww+OSDolrlABdBqqhJa75H3Ro29R61tvToRHY1gyOZIIq/4F9WwceTifhUIdWgTjCIvVFBa+lVvy82GTgDvGtxWzpE9+B2N0QsRn8b1923lO2flhaIsQLVv44gNIfFIV3y9CWnZEu+UrXUvgfClXSfRJOmbp8ZhdTHEZA3oPghrbEyE1Ef4y9/KjtgU88kIZsyUIm7Tmf3qhuHw== 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=MpRZbz6kEMX2/5Kzufx6uJYes/rX50gatEiwGsclbvI=; b=ib9SyHPRe7RMRuaAMWMFR8YPFVPG5XjSy7Z3zg9P2Qs+sU+omXpPDV8Mk5DOg02HA1h0Djz5Wm8NLiZPL31FoDKNrfgADe81h30942w/unrtyw+2uFHerTjh1ZLOTjtt3eICCT/Sh8DKbnFAqHJktKCaMXoDDub0xT1VNTUuJxnpKTixJPB2EIYz7nNbPh6wgeMyQ/RPawoSiJuIwJoirysJlHVtfh7A7oAir2xSZWfu31/ndkiDJXdn5kfEG6NK10z7Bo94gWYcHxG5pNLyHXMXye9wNqgdwBbixvMol2st504A0MuiE90KzrR72PQEQQz/Vzp28WHgBPhBUJQa4Q== 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=MpRZbz6kEMX2/5Kzufx6uJYes/rX50gatEiwGsclbvI=; b=RMRECfKC3hNWHA9qak76YUaxB4HM7zH9Wp80m0J2vgWsBorRP+f74YIXAjR+ZOWvaQ1zbX0Mt+rfSxQWdb9GOYfPVcoOVhKm5df206UMP0Uis+jIVfww1GPz14oVVMDJGLnOXAGiy8i2zqWlpfGMx1q6g05Pt5Ht1mDmqB+9mp53ph5etOnV2ixQalLL0dtC6waBJVqF0jueAaiBLkqYmAnYwLAPdWKlgAn354hyEz+8hnBstinaIcvTCdyl1uA1KG9cBMY7ArZqyg+c+a7yvbyqU7xAXYhR5hZP1oibahgR0Q3w0TQhWTS49dtZfseZxQBYTUhDbZVnMjmBTIhJcA== Received: from BN9PR03CA0274.namprd03.prod.outlook.com (2603:10b6:408:f5::9) by MN0PR12MB6245.namprd12.prod.outlook.com (2603:10b6:208:3c3::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Wed, 21 Aug 2024 11:42:07 +0000 Received: from BN3PEPF0000B36F.namprd21.prod.outlook.com (2603:10b6:408:f5:cafe::2b) by BN9PR03CA0274.outlook.office365.com (2603:10b6:408:f5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.25 via Frontend Transport; Wed, 21 Aug 2024 11:42:07 +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 BN3PEPF0000B36F.mail.protection.outlook.com (10.167.243.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.4 via Frontend Transport; Wed, 21 Aug 2024 11:42:06 +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; Wed, 21 Aug 2024 04:41:53 -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; Wed, 21 Aug 2024 04:41: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; Wed, 21 Aug 2024 04:41:50 -0700 From: Dragos Tatulea To: "Michael S . Tsirkin" , Jason Wang , Eugenio Perez Martin , Si-Wei Liu , , "Gal Pressman" CC: Dragos Tatulea , , , Parav Pandit , Xuan Zhuo , Cosmin Ratiu Subject: [PATCH vhost 7/7] vdpa/mlx5: Postpone MR deletion Date: Wed, 21 Aug 2024 14:41:01 +0300 Message-ID: <20240821114100.2261167-9-dtatulea@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240821114100.2261167-2-dtatulea@nvidia.com> References: <20240821114100.2261167-2-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: BN3PEPF0000B36F:EE_|MN0PR12MB6245:EE_ X-MS-Office365-Filtering-Correlation-Id: 132edc63-0aef-4e83-0de0-08dcc1d648f5 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: xR/D4CgvNhFXQpF+KT+2wJDWhV6Np/PfngUBtxzOlfRNCGmirAgCuhkaEfUGUrMYzH5MOq1pO3YNIeSrneFSmk9PomHxvqZFsUvQr2hp3MBUR0Q+GgBk/FXfU0fQSrYprFbEviwAF5QDP/HQaaRw3XLQrWI4nJWEOOqTqp4LSCd0evETeJzGAHjjZI19K3l5995K0ElkGe4ZC+oZrH1fODinQYc45cBAbKaVCfeUrQRNNB/NxH3wyJM0jdD7QWIAzFkI+jE2TX6dJ3daaLUduDbg7wd5mjsHHe4ISEE1mriSttD0jZOHGiv3ZcrT/a6AEPTXKiIFESe3PixZSpulceZ5kBbpWyoYshq2zwFOxQziv1lG6q/mXcR5WOsxbvmKfoACXN5eHRgtjza9NhlWYUp4FrFaNFvwgo4NMjNrhQ4w2fwmnNMubz2EW4lqeZVB3DYacmEfUyscuXSjRTLgKG7/kqnx1LDt2rOm0ITsKWcy9hjkGTwRZhAcUD1gDlMQmhRAsSW8l8wGjpoaK0TJ6Pu3Jn4dJdcVAVoguAm2bCGJU9MLPpr5HjAhsG2CCeYpviNLP63BwKmEyZ4g7dXpHRHjNGXVeQLBnag8jvBwaX8o1ChA++OUNyUG71mid9QEm480kFHocgpnptcgMkAPzqmGy6Z20NHoHRX3B2ct1+yHLR31BFFjGtH8qfKG3GHrCThpk0uolkdijNtoTavPD7VKJNLwKhoTIseTN/HF/Wp/nD0EwyW7znPFEBA2lclNTXczh1vD9IgaU+0a3vyHHiQUAOHOzCiZlHHLIInOUJUCpDraHB2ktzDxyZQkRCj7cr1JosE8K9egwfR3HCMbjy2xTlZftChHKCCjpGp3ao5qqi2xZzKNF3YdvyljuShRGVfY4z5YcYIJ1JNG5Hoo4uyhETJpVNMmyiFaQ0sk6U/rvmh2a9zSACa6Dvt7XczuESQnlSPQxP6DLQm7K1BagOWh+yWYEZOQaW+ECYJf4jl6KObmz8DdP3IFZhUb2lz3dw5NZ/DsLlypan3JIOT7eeQjIF43nR0BO7gMBkzQmcvZs+B8/nJFrAtrYNAugVbEAYWQSiD58r0Cu28DN158IC0Zyyx+cgr1Ue50ZL5KBh96dMShakt+JIRVhL08WsOQRZPSx2To3oN96Dakj4QUl73z/fjPwNjQr4vBec6H87zlKhgpQdqjTs1joGJcD/SFaT8odc5NW5v2yGvuVQvIGp1zgZTqCt5MAennDUCimL78yQVP7mPiaVhGXM5uaAU55DgI+IEPqhnb+65bFQKAAA0PTe6CjzOSkeUiqlnQzMmqgrObx+P3MSgKv7x2VXaNKELFI2P3cGJ7ePUVnvDFaF6+R72Gutm6hVZ8TtQFfpuTxTbImAHjNxB49+QkBUBKpugUksl/DVkClE0S0VY+h2CugHafnNQFQsun4b3Rq8BZxfvdZXRgQG8nl2iP/jfE 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)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2024 11:42:06.8918 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 132edc63-0aef-4e83-0de0-08dcc1d648f5 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: BN3PEPF0000B36F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6245 Currently, when a new MR is set up, the old MR is deleted. MR deletion is about 30-40% the time of MR creation. As deleting the old MR is not important for the process of setting up the new MR, this operation can be postponed. This series adds a workqueue that does MR garbage collection at a later point. If the MR lock is taken, the handler will back off and reschedule. The exception during shutdown: then the handler must not postpone the work. Note that this is only a speculative optimization: if there is some mapping operation that is triggered while the garbage collector handler has the lock taken, this operation it will have to wait for the handler to finish. Signed-off-by: Dragos Tatulea Reviewed-by: Cosmin Ratiu --- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 10 ++++++ drivers/vdpa/mlx5/core/mr.c | 51 ++++++++++++++++++++++++++++-- drivers/vdpa/mlx5/net/mlx5_vnet.c | 3 +- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h index c3e17bc888e8..2cedf7e2dbc4 100644 --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h @@ -86,8 +86,18 @@ enum { struct mlx5_vdpa_mr_resources { struct mlx5_vdpa_mr *mr[MLX5_VDPA_NUM_AS]; unsigned int group2asid[MLX5_VDPA_NUMVQ_GROUPS]; + + /* Pre-deletion mr list */ struct list_head mr_list_head; + + /* Deferred mr list */ + struct list_head mr_gc_list_head; + struct workqueue_struct *wq_gc; + struct delayed_work gc_dwork_ent; + struct mutex lock; + + atomic_t shutdown; }; struct mlx5_vdpa_dev { diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index ec75f165f832..43fce6b39cf2 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -653,14 +653,46 @@ static void _mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_ kfree(mr); } +#define MLX5_VDPA_MR_GC_TRIGGER_MS 2000 + +static void mlx5_vdpa_mr_gc_handler(struct work_struct *work) +{ + struct mlx5_vdpa_mr_resources *mres; + struct mlx5_vdpa_mr *mr, *tmp; + struct mlx5_vdpa_dev *mvdev; + + mres = container_of(work, struct mlx5_vdpa_mr_resources, gc_dwork_ent.work); + + if (atomic_read(&mres->shutdown)) { + mutex_lock(&mres->lock); + } else if (!mutex_trylock(&mres->lock)) { + queue_delayed_work(mres->wq_gc, &mres->gc_dwork_ent, + msecs_to_jiffies(MLX5_VDPA_MR_GC_TRIGGER_MS)); + return; + } + + mvdev = container_of(mres, struct mlx5_vdpa_dev, mres); + + list_for_each_entry_safe(mr, tmp, &mres->mr_gc_list_head, mr_list) { + _mlx5_vdpa_destroy_mr(mvdev, mr); + } + + mutex_unlock(&mres->lock); +} + static void _mlx5_vdpa_put_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) { + struct mlx5_vdpa_mr_resources *mres = &mvdev->mres; + if (!mr) return; - if (refcount_dec_and_test(&mr->refcount)) - _mlx5_vdpa_destroy_mr(mvdev, mr); + if (refcount_dec_and_test(&mr->refcount)) { + list_move_tail(&mr->mr_list, &mres->mr_gc_list_head); + queue_delayed_work(mres->wq_gc, &mres->gc_dwork_ent, + msecs_to_jiffies(MLX5_VDPA_MR_GC_TRIGGER_MS)); + } } void mlx5_vdpa_put_mr(struct mlx5_vdpa_dev *mvdev, @@ -848,9 +880,17 @@ int mlx5_vdpa_init_mr_resources(struct mlx5_vdpa_dev *mvdev) { struct mlx5_vdpa_mr_resources *mres = &mvdev->mres; - INIT_LIST_HEAD(&mres->mr_list_head); + mres->wq_gc = create_singlethread_workqueue("mlx5_vdpa_mr_gc"); + if (!mres->wq_gc) + return -ENOMEM; + + INIT_DELAYED_WORK(&mres->gc_dwork_ent, mlx5_vdpa_mr_gc_handler); + mutex_init(&mres->lock); + INIT_LIST_HEAD(&mres->mr_list_head); + INIT_LIST_HEAD(&mres->mr_gc_list_head); + return 0; } @@ -858,5 +898,10 @@ void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev) { struct mlx5_vdpa_mr_resources *mres = &mvdev->mres; + atomic_set(&mres->shutdown, 1); + + flush_delayed_work(&mres->gc_dwork_ent); + destroy_workqueue(mres->wq_gc); + mres->wq_gc = NULL; mutex_destroy(&mres->lock); } diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 1cadcb05a5c7..ee9482ef51e6 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -3435,6 +3435,8 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev) free_fixed_resources(ndev); mlx5_vdpa_clean_mrs(mvdev); mlx5_vdpa_destroy_mr_resources(&ndev->mvdev); + mlx5_cmd_cleanup_async_ctx(&mvdev->async_ctx); + if (!is_zero_ether_addr(ndev->config.mac)) { pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev)); mlx5_mpfs_del_mac(pfmdev, ndev->config.mac); @@ -4044,7 +4046,6 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * destroy_workqueue(wq); mgtdev->ndev = NULL; - mlx5_cmd_cleanup_async_ctx(&mvdev->async_ctx); } static const struct vdpa_mgmtdev_ops mdev_ops = {