Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2860375rdb; Tue, 12 Sep 2023 14:39:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQ3+joEIFZr8QKxfuJv/fMns9KVxNlQGCY7AiPDHQlXomtJrC6yp5ReawEe8SmgHlFwvCc X-Received: by 2002:a17:902:d512:b0:1c0:bf60:ba4f with SMTP id b18-20020a170902d51200b001c0bf60ba4fmr1027945plg.4.1694554782339; Tue, 12 Sep 2023 14:39:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1694554782; cv=pass; d=google.com; s=arc-20160816; b=KR7d1GbF0MBEJWg8wJE5gmiw92tBUm9WdNq7cRNZhuY9zkhs1gTjB5CczEPsu+HSt3 GdrTfTpYHe+25oEAuuL2IGeZ8VddNRvpfow1SBSd25ph1qAKOrqSq3d9WyP6HaBvAFEK bM8V3yHdJKgdxKV0i9CN4E8r3ayPlLql4KIvOerDMkCuwjWv+bfje6OeVjU/dcUH4SIX 46hTIGuPiMJFoeqOMWmkGgXX+caVt15mqH7XN5hzv0XP5THWeFMjCHLhqSoq/c/QmKpD iqO840TRXEX+M3KSwIVlVUmEXDkiMOgq8VWnxxJwuBTxlU/wqT6NAIPNHiYRpQzuEC+0 0B8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9ApYXayR3INDzXVSk48cqn+dnUTPh1DTOtDvSZn0b3M=; fh=OYX0w70bKWLTZnZNUmTcUjb/vh12yoS1IlKGBW8yXc0=; b=a0EY1ki1k4b/UlXCsVHxQEygsYdIFu2ir9UO+lrSLdfN40kAwm9dSdOqblSrBLq9o3 aC4kgY2mY+rYXZXw1KNIrPzKbbGcKLFw+TuDI6mVeuKIv38jfLzMztgOJPsQgkbodNBQ 6GtR2wfEWr5JQYJj1hy0dIFx+SP5M2VnVxp4GWijmqIcTd6bom1/82ltyq+3v45dTj0F kG8BYlOjWIT/sNayhATDMYUpOzz9NohQlvNMFEogY542k+7XiE+XNZmVHGrOVKnKBgYR p2qZ1+hg3Zjb4tegDT2DWZGnx9XnisULMPcbEmt9jureJ/1rMqqjPoZteewhjf2PfZ+N YFtQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Dy7ElXEC; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id jy15-20020a17090342cf00b001bbc0ca8650si8396812plb.370.2023.09.12.14.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 14:39:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Dy7ElXEC; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 37A0885140C3; Tue, 12 Sep 2023 06:03:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235451AbjILNDB (ORCPT + 99 others); Tue, 12 Sep 2023 09:03:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235450AbjILNCo (ORCPT ); Tue, 12 Sep 2023 09:02:44 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2045.outbound.protection.outlook.com [40.107.220.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7205B1731; Tue, 12 Sep 2023 06:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RTrf3Ut3Lm0GCBRdNrDLC9WZhfnX18JtfLYuKgXyo/Z2+nmYOy10L68fuEzx5YDqXnqGmxFChI2JIomcxPWFKXnV+KLUDKsddtTw9IeARacxQc8DY/TtyZI13655TWAR+piHZ9AQilntfzYS9ktJO5KVjjnw+vpuKhqk2iRNThrCOyXGipu2w4Rle1ZlIupHW0U0RjIQR48BtnzXeqCzTR4xml06sRwPwgIb39eyxrN5QfLRX9Jf06KOR7WBPcsrAnPv+HweIdA6jq+82X21OzpJFkEsasXL6B/zSGjPX9FYneFsBrmEgJHVqIqnmpZa2puIsUU64ajEWQGSsBPGpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9ApYXayR3INDzXVSk48cqn+dnUTPh1DTOtDvSZn0b3M=; b=Pk2jAkiscR+ciqLHAaToqsTew+FPIJyiONkiPaFoR+P6NYc8/dIg5D9ZkxWTX0hdFagw69RS3uSS5hCMJi9Ae0kUlbKerpLrwrLMUqXV92LYOpgKMWpJ2KdDKNqArTtIq9TM+DIJDDb0s+w/c+cv5b/m+Beq5vU5Ty8nvmK+uU2mFzO1AIAGcE9jol51xy8GhaUcH6hF3nUF/aJy/mR6JkcOKlTHWnpTU2nYdgGnnUG9HU3S4/H+KOuzprH8jFszHpOBFrNsaRzrkmG9CO2+9q+l69yg0LKQ4NFr+OdWKtlxIS6s94R8nHbM1vGBMoTwxFnvI+xj2Sa1gt97pivIIA== 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 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=9ApYXayR3INDzXVSk48cqn+dnUTPh1DTOtDvSZn0b3M=; b=Dy7ElXECN86CQCBPV/eX92G1++ohVlxgJk7gI2+kvVWE8+6wo8IDe+Zqsbam7LXi9BJxXxAqmZyhHoMbuVrHMaCIpsmNXCgt4uGn7mGdGMucoXedLJ/Y8pQlINC4IVns89x73s2LHH3QogL3FrOaCsx7FnFpY3SM5x5lUc4yk9k3Re/cd0t3FMtUK1PCwIoqGeP3fCPdOPnM7QzFZBDRdN5GLhxczxjyEQzpBYE+ED8XT2A0tqS+FlcpRA3ueOILvwFB8p1o+XRP3bjQfVOOARJEGSLKdGY8uduBPU4pte4SlKb2F0OrJ/6i6oVsQAdQAUEVXwLnQ+EFl8zjkxZ6EA== Received: from MW4PR04CA0312.namprd04.prod.outlook.com (2603:10b6:303:82::17) by DM6PR12MB4863.namprd12.prod.outlook.com (2603:10b6:5:1b9::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.35; Tue, 12 Sep 2023 13:02:22 +0000 Received: from CO1PEPF000042A7.namprd03.prod.outlook.com (2603:10b6:303:82:cafe::9a) by MW4PR04CA0312.outlook.office365.com (2603:10b6:303:82::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.36 via Frontend Transport; Tue, 12 Sep 2023 13:02:22 +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 CO1PEPF000042A7.mail.protection.outlook.com (10.167.243.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.17 via Frontend Transport; Tue, 12 Sep 2023 13:02:22 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 12 Sep 2023 06:02:03 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 12 Sep 2023 06:02:03 -0700 Received: from c-237-113-220-225.mtl.labs.mlnx (10.127.8.12) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 12 Sep 2023 06:02:00 -0700 From: Dragos Tatulea To: Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Si-Wei Liu , "Michael S . Tsirkin" , Saeed Mahameed , , CC: Dragos Tatulea , Parav Pandit , Xuan Zhuo , Subject: [PATCH 05/16] vdpa/mlx5: Decouple cvq iotlb handling from hw mapping code Date: Tue, 12 Sep 2023 16:01:15 +0300 Message-ID: <20230912130132.561193-6-dtatulea@nvidia.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230912130132.561193-1-dtatulea@nvidia.com> References: <20230912130132.561193-1-dtatulea@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042A7:EE_|DM6PR12MB4863:EE_ X-MS-Office365-Filtering-Correlation-Id: 55ea6259-4357-432b-6106-08dbb39080d1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tPahj+bNomyuyNCXlQTvLODAh00KlT7qKCMgYXCNa7flTLIsLIUEfq5MrWd/IYZ/DtKih00C+lnjKWDHaeWzF7k6uMngbQ4BfNaDV0ymZowV6EgtB+hvmofyD3FTwOVXnjKM+JhTD7eBMsY0Z9Q9GyU9ZliThKkhFJ47EkNKCokuRHKmg88wQ8fUM7Tz/jlZle0Pu4BbNq991M4asGEHkGhIT3kpGHv+heTSrcVRtyO30CMXEyOaVkgG1nCq1EFM8CwzE+tSH9yfEcK8133VKnvJVHklRG7mno/kc3EO8AZ15d5Tlpb2HdJAU15Pj6vBojoZOFhjzlO3NjEo9ZK8Byj+zNq5t6tifBriOcot2PsGrUUKOL+bmXO8a29qdC+eEr987PwLzpRHsDCX+77Vt+aBPZZ31GoaAFWcBp+5hoAOQ5x8c7cuvjk7jkzcTz1O/mnX0mwUw9mnJjXpIDkJSE2fJYmvHVMl7GK1GWEJuSQXICs4+mi9xIYnFmNzpS2YE+RAZwsCmhXdBlARW/loJzBqr4+TW9Mw0UUI4F/8d+3834cgq4e9QbYyXEwlyw18QxcTriODdpi4BNA20KX3ty1zta8GnBCiN3Wz9Bf/cFIPMvuFkCp6uLMdJHhre/cI5IW15MywHHXNKnDfc/8ySMLtwKuymxioe2BnpkmBkseraAhKnZwon6z/UQRufKyWqWCM+/X+HrzUGMf8m/0yAe2BYX2TONGAGeq9hbXhQlA= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(136003)(346002)(396003)(376002)(82310400011)(186009)(1800799009)(451199024)(40470700004)(36840700001)(46966006)(4326008)(40480700001)(8676002)(8936002)(36756003)(26005)(40460700003)(6666004)(7636003)(356005)(86362001)(5660300002)(82740400003)(2906002)(36860700001)(47076005)(336012)(426003)(70586007)(83380400001)(70206006)(110136005)(41300700001)(2616005)(1076003)(478600001)(54906003)(316002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2023 13:02:22.0143 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 55ea6259-4357-432b-6106-08dbb39080d1 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: CO1PEPF000042A7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4863 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 06:03:04 -0700 (PDT) The handling of the cvq iotlb is currently coupled with the creation and destruction of the hardware mkeys (mr). This patch moves cvq iotlb handling into its own function and shifts it to a scope that is not related to mr handling. As cvq handling is just a prune_iotlb + dup_iotlb cycle, put it all in the same "update" function. Finally, the destruction path is handled by directly pruning the iotlb. After this move is done the ASID mr code can be collapsed into a single function. Signed-off-by: Dragos Tatulea --- drivers/vdpa/mlx5/core/mlx5_vdpa.h | 3 ++ drivers/vdpa/mlx5/core/mr.c | 57 +++++++++++------------------- drivers/vdpa/mlx5/net/mlx5_vnet.c | 7 ++-- 3 files changed, 28 insertions(+), 39 deletions(-) diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h index 3748f027cfe9..554899a80241 100644 --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h @@ -120,6 +120,9 @@ int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, unsigned int asid); void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev); void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsigned int asid); +int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev, + struct vhost_iotlb *iotlb, + unsigned int asid); int mlx5_vdpa_create_dma_mr(struct mlx5_vdpa_dev *mvdev); #define mlx5_vdpa_warn(__dev, format, ...) \ diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/core/mr.c index 7bd0883b8b25..fcb6ae32e9ed 100644 --- a/drivers/vdpa/mlx5/core/mr.c +++ b/drivers/vdpa/mlx5/core/mr.c @@ -489,14 +489,6 @@ static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr } } -static void _mlx5_vdpa_destroy_cvq_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid) -{ - if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) - return; - - prune_iotlb(mvdev); -} - static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid) { struct mlx5_vdpa_mr *mr = &mvdev->mr; @@ -522,25 +514,14 @@ void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsigned int asid) mutex_lock(&mr->mkey_mtx); _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); - _mlx5_vdpa_destroy_cvq_mr(mvdev, asid); mutex_unlock(&mr->mkey_mtx); } void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev) { - mlx5_vdpa_destroy_mr_asid(mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP]); mlx5_vdpa_destroy_mr_asid(mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]); -} - -static int _mlx5_vdpa_create_cvq_mr(struct mlx5_vdpa_dev *mvdev, - struct vhost_iotlb *iotlb, - unsigned int asid) -{ - if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) - return 0; - - return dup_iotlb(mvdev, iotlb); + prune_iotlb(mvdev); } static int _mlx5_vdpa_create_dvq_mr(struct mlx5_vdpa_dev *mvdev, @@ -572,22 +553,7 @@ static int _mlx5_vdpa_create_dvq_mr(struct mlx5_vdpa_dev *mvdev, static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, unsigned int asid) { - int err; - - err = _mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid); - if (err) - return err; - - err = _mlx5_vdpa_create_cvq_mr(mvdev, iotlb, asid); - if (err) - goto out_err; - - return 0; - -out_err: - _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); - - return err; + return _mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid); } int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, @@ -620,7 +586,24 @@ int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *io return err; } +int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev, + struct vhost_iotlb *iotlb, + unsigned int asid) +{ + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) + return 0; + + prune_iotlb(mvdev); + return dup_iotlb(mvdev, iotlb); +} + int mlx5_vdpa_create_dma_mr(struct mlx5_vdpa_dev *mvdev) { - return mlx5_vdpa_create_mr(mvdev, NULL, 0); + int err; + + err = mlx5_vdpa_create_mr(mvdev, NULL, 0); + if (err) + return err; + + return mlx5_vdpa_update_cvq_iotlb(mvdev, NULL, 0); } diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index d34c19b4e139..061d8f7a661a 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -2884,10 +2884,13 @@ static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, return err; } - if (change_map) + if (change_map) { err = mlx5_vdpa_change_map(mvdev, iotlb, asid); + if (err) + return err; + } - return err; + return mlx5_vdpa_update_cvq_iotlb(mvdev, iotlb, asid); } static int mlx5_vdpa_set_map(struct vdpa_device *vdev, unsigned int asid, -- 2.41.0