From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 14839A0C4E for ; Mon, 8 Nov 2021 18:21:58 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6AEFB4113C; Mon, 8 Nov 2021 18:21:56 +0100 (CET) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2085.outbound.protection.outlook.com [40.107.244.85]) by mails.dpdk.org (Postfix) with ESMTP id 814894111F; Mon, 8 Nov 2021 18:21:54 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CYj5REEfcw191yShMvMNC7nbRNllBazwZJpNLhGmabrywxtUTWxFnc7gTXHEQ+i/T2SVrNvIFKR+O6NaPduPOf3eJfkdt/T3POFtZS+rF1SDtN4biqwSBfqq/Ojlm75OV7XHSR8YNFZnaowzem+2ZQxpeg3z4PXn2WXFTj4Dy2NBL3jrimKZESmDXUDCy9XCbNvptYVGh1+6vWZQM6va+rxsZquYTaloBonUDkHrFXbWG7XiS8mdU6u0Pm9a3rYV0jX13hwkI/TORUrl9K7FVoYuvHNiwXCHvp0bHYNFdAf2cTaMRyWH06Qu2S8vTBa9h/b7djTmeOWDFqWAAaW1ww== 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=6m373ZFLWx9CPerY0RKgubxuUkLitv2bcuJh4c50KV0=; b=NMMkPVoZoHc2rD4qzB+VknkBsmyQ2jGUJjHECg5IAJ59xxlJ+NGineDW6nJL+kZC7Wa08DazS5rVmq/ADhxE5m2rkZYCLzE2xSOjbfxzTGhc1nML2nmiwvKsl9H64q42vdKxYIFWeEUr+WTaQlyAQmyaACR7hfORFaMus0qSqgJakQJD3/JTZppA1DnpTu/DErgIbFCME9pZwq0BOj/K3GsLUzDXF7k/66fJPEv2OxTXE7J7JhPgF6vXO8Sqt7RSBRu8m/smPlVTbazsn4+bpsGp5KzrsifXOvpFsLgrkKQjv8JOOMg6naZ/jtxjFvzYdK8gQJPtY1P51GStGc2Prw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine 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=6m373ZFLWx9CPerY0RKgubxuUkLitv2bcuJh4c50KV0=; b=W86RKEL7Q76VF/g3jlfRaJeXkw5gvYB+a4QeBgV1aiS+h7iy6Hw6tWEK1bb7eVQY/aEzoe2TOZ+hQQ4xB7VoWZnd9FlOEu0883VkcgwxRYXPzr8X1aCBpp/hUBD0gwvRtKCbpO+TSSW8PBL+QogHyOXHSk86OfrX5hqUp5SREYzdUL5g6zKjotXEdRSw9rNm7gE2FiM6hc09yrvufNX89oB17HRiElm4HLM98tSJpap6GT7eZq3efa3pkUzw/cZd5IcdjG6aj3a7sViymoesuyIyGCqZUIt3SfoDOrThAb6tHMlTLJ/Bhh4K2zPIX0sRcOBRQ3Wp80i8+Ji3dXP5lQ== Received: from BN9PR03CA0284.namprd03.prod.outlook.com (2603:10b6:408:f5::19) by MW3PR12MB4505.namprd12.prod.outlook.com (2603:10b6:303:5a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11; Mon, 8 Nov 2021 17:21:52 +0000 Received: from BN8NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f5:cafe::bf) by BN9PR03CA0284.outlook.office365.com (2603:10b6:408:f5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Mon, 8 Nov 2021 17:21:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT054.mail.protection.outlook.com (10.13.177.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4669.10 via Frontend Transport; Mon, 8 Nov 2021 17:21:51 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 8 Nov 2021 17:21:37 +0000 From: Matan Azrad To: Viacheslav Ovsiienko CC: , Thomas Monjalon , , Michael Baum Date: Mon, 8 Nov 2021 19:21:10 +0200 Message-ID: <20211108172113.2241853-3-matan@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211108172113.2241853-1-matan@nvidia.com> References: <20211107152919.2158802-1-matan@nvidia.com> <20211108172113.2241853-1-matan@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5f642dd9-629e-4384-a3fd-08d9a2dc4110 X-MS-TrafficTypeDiagnostic: MW3PR12MB4505: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bLmQgaoQdD315EYKoDzf1UIAncYg0/t+hoCLn0002d9DHFKOADrYXbTeKaC46vbQo9H6rlWdU75AfaqtJX2DItO35YqFh2JDGDIrw2xHlcEh8vec3/ycUcofCGdCl7O8XuH8GtQ1/h7P+e9msvyFoZQiRa/3HU+HFPPbAp3zxBFaiI8QByIziPPbemJpjLaCXNygtrmDx4IsYAGwcc9paxvUqenuUZXs5rBfsO2ENG5UEyeWAl98mRpsfzoerOwMonsJEkzG8oRas2w3q6rLzk5k9C8CZHOsnmNLSGZCi6lDEBYQTbiVp6Zn7R+FBqt3y/NwYB3XQPMgzlA+9wWNGB29mClOZjj0uwsr+DdC1uM0wG3LBQ/pVS9i5rXED5E9+3ETOvi1g28Snnch1qVXuOL8/yZ7DNN0CN+o9GYDrbQePrO9ylj1eWxWs2Q5bp/8IBjfKvV2GTVla8Cf3LKW9Y5EUvz+QEk+kYzH0BxYFRuo2vXQv/ZvfDJvtKNMP85Za2Q8NG7dZrIpOMFc2EPa9AcfOLUaRIVWpVAYa+7StBWUsDE7z6jD8CBWPMa5yyEeGTRQHieCcVUGE9h4OnMg6hy5ckznJ7cnP5Tp9atQ6w/JMtBWSGDxu1wfdq267Jd7uXnf4e+9JZuy5cGxn9Ym+qpSw54wyPNu6mP+fFg8CcOEArkNOEPnw8MC12HSlaZwU0erGiELaVjTc0jpvfnFfA== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(2906002)(186003)(47076005)(16526019)(26005)(336012)(37006003)(36906005)(6636002)(2616005)(107886003)(36756003)(36860700001)(4326008)(82310400003)(54906003)(426003)(5660300002)(316002)(70206006)(86362001)(55016002)(70586007)(356005)(1076003)(6286002)(508600001)(7696005)(83380400001)(6862004)(8676002)(8936002)(6666004)(7636003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2021 17:21:51.5031 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5f642dd9-629e-4384-a3fd-08d9a2dc4110 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4505 Subject: [dpdk-stable] [PATCH v2 2/5] common/mlx5: add wrapped MR create API X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" The mlx5 PMD uses the kernel mlx5 driver to map physical memory to the HW. Using the Verbs API ibv_reg_mr, a mkey can be created for that. In this case, the mkey is signed on the user ID of the kernel driver. Using the DevX API, a mkey also can be created, but it should point an umem object (represents the specific buffer mapping) created by the kernel. In this case, the mkey is signed on the user ID of the process DevX context. In FW DevX control commands which get mkey as a parameter, there is a security check on the user ID and Verbs mkeys are rejected. Unfortunately, also when using DevX mkey, there is an error in the FW command on umem validation because the umem is not designed to be used for any mkey parameters. As a workaround to the kernel driver/FW issue, it is needed to use a wrapped MR, which is an indirect mkey(created by the DevX API) pointing to direct mkey created by the kernel for any DevX command uses an MR. Add an API to create and destroy this wrapped MR. Fixes: 5382d28c2110 ("net/mlx5: accelerate DV flow counter transactions") Fixes: 9d39e57f21ac ("vdpa/mlx5: support live migration") Cc: stable@dpdk.org Signed-off-by: Michael Baum Signed-off-by: Matan Azrad --- drivers/common/mlx5/linux/mlx5_common_os.c | 56 ++++++++++++++++++++ drivers/common/mlx5/mlx5_common.h | 18 +++++++ drivers/common/mlx5/version.map | 3 ++ drivers/common/mlx5/windows/mlx5_common_os.c | 40 ++++++++++++++ 4 files changed, 117 insertions(+) diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c index b516564b79..0d3e24e04e 100644 --- a/drivers/common/mlx5/linux/mlx5_common_os.c +++ b/drivers/common/mlx5/linux/mlx5_common_os.c @@ -744,3 +744,59 @@ mlx5_get_device_guid(const struct rte_pci_addr *dev, uint8_t *guid, size_t len) fclose(id_file); return ret; } + +/* + * Create direct mkey using the kernel ibv_reg_mr API and wrap it with a new + * indirect mkey created by the DevX API. + * This mkey should be used for DevX commands requesting mkey as a parameter. + */ +int +mlx5_os_wrapped_mkey_create(void *ctx, void *pd, uint32_t pdn, void *addr, + size_t length, struct mlx5_pmd_wrapped_mr *pmd_mr) +{ + struct mlx5_klm klm = { + .byte_count = length, + .address = (uintptr_t)addr, + }; + struct mlx5_devx_mkey_attr mkey_attr = { + .pd = pdn, + .klm_array = &klm, + .klm_num = 1, + }; + struct mlx5_devx_obj *mkey; + struct ibv_mr *ibv_mr = mlx5_glue->reg_mr(pd, addr, length, + IBV_ACCESS_LOCAL_WRITE | + (haswell_broadwell_cpu ? 0 : + IBV_ACCESS_RELAXED_ORDERING)); + + if (!ibv_mr) { + rte_errno = errno; + return -rte_errno; + } + klm.mkey = ibv_mr->lkey; + mkey_attr.addr = (uintptr_t)addr; + mkey_attr.size = length; + mkey = mlx5_devx_cmd_mkey_create(ctx, &mkey_attr); + if (!mkey) { + claim_zero(mlx5_glue->dereg_mr(ibv_mr)); + return -rte_errno; + } + pmd_mr->addr = addr; + pmd_mr->len = length; + pmd_mr->obj = (void *)ibv_mr; + pmd_mr->imkey = mkey; + pmd_mr->lkey = mkey->id; + return 0; +} + +void +mlx5_os_wrapped_mkey_destroy(struct mlx5_pmd_wrapped_mr *pmd_mr) +{ + if (!pmd_mr) + return; + if (pmd_mr->imkey) + claim_zero(mlx5_devx_cmd_destroy(pmd_mr->imkey)); + if (pmd_mr->obj) + claim_zero(mlx5_glue->dereg_mr(pmd_mr->obj)); + memset(pmd_mr, 0, sizeof(*pmd_mr)); +} diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h index 744c6a72b3..62109a671a 100644 --- a/drivers/common/mlx5/mlx5_common.h +++ b/drivers/common/mlx5/mlx5_common.h @@ -429,4 +429,22 @@ mlx5_mr_mb2mr(struct mlx5_common_device *cdev, struct mlx5_mp_id *mp_id, int mlx5_os_open_device(struct mlx5_common_device *cdev, uint32_t classes); int mlx5_os_pd_create(struct mlx5_common_device *cdev); +/* mlx5 PMD wrapped MR struct. */ +struct mlx5_pmd_wrapped_mr { + uint32_t lkey; + void *addr; + size_t len; + void *obj; /* verbs mr object or devx umem object. */ + void *imkey; /* DevX indirect mkey object. */ +}; + +__rte_internal +int +mlx5_os_wrapped_mkey_create(void *ctx, void *pd, uint32_t pdn, void *addr, + size_t length, struct mlx5_pmd_wrapped_mr *pmd_mr); + +__rte_internal +void +mlx5_os_wrapped_mkey_destroy(struct mlx5_pmd_wrapped_mr *pmd_mr); + #endif /* RTE_PMD_MLX5_COMMON_H_ */ diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map index 6e17a7b8b8..28d685a7c6 100644 --- a/drivers/common/mlx5/version.map +++ b/drivers/common/mlx5/version.map @@ -133,6 +133,9 @@ INTERNAL { mlx5_os_umem_dereg; mlx5_os_umem_reg; + mlx5_os_wrapped_mkey_create; + mlx5_os_wrapped_mkey_destroy; + mlx5_realloc; mlx5_translate_port_name; # WINDOWS_NO_EXPORT diff --git a/drivers/common/mlx5/windows/mlx5_common_os.c b/drivers/common/mlx5/windows/mlx5_common_os.c index ea478d7395..0d03344343 100644 --- a/drivers/common/mlx5/windows/mlx5_common_os.c +++ b/drivers/common/mlx5/windows/mlx5_common_os.c @@ -390,3 +390,43 @@ mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb) *reg_mr_cb = mlx5_os_reg_mr; *dereg_mr_cb = mlx5_os_dereg_mr; } + +/* + * In Windows, no need to wrap the MR, no known issue for it in kernel. + * Use the regular function to create direct MR. + */ +int +mlx5_os_wrapped_mkey_create(void *ctx, void *pd, uint32_t pdn, void *addr, + size_t length, struct mlx5_pmd_wrapped_mr *wpmd_mr) +{ + struct mlx5_pmd_mr pmd_mr = {0}; + int ret = mlx5_os_reg_mr(pd, addr, length, &pmd_mr); + + (void)pdn; + (void)ctx; + if (ret != 0) + return -1; + wpmd_mr->addr = addr; + wpmd_mr->len = length; + wpmd_mr->obj = pmd_mr.obj; + wpmd_mr->imkey = pmd_mr.mkey; + wpmd_mr->lkey = pmd_mr.mkey->id; + return 0; +} + +void +mlx5_os_wrapped_mkey_destroy(struct mlx5_pmd_wrapped_mr *wpmd_mr) +{ + struct mlx5_pmd_mr pmd_mr; + + if (!wpmd_mr) + return; + pmd_mr.addr = wpmd_mr->addr; + pmd_mr.len = wpmd_mr->len; + pmd_mr.obj = wpmd_mr->obj; + pmd_mr.mkey = wpmd_mr->imkey; + pmd_mr.lkey = wpmd_mr->lkey; + mlx5_os_dereg_mr(&pmd_mr); + memset(wpmd_mr, 0, sizeof(*wpmd_mr)); +} + -- 2.25.1