From patchwork Thu Sep 8 20:54:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Guralnik X-Patchwork-Id: 12970657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E8B9C54EE9 for ; Thu, 8 Sep 2022 20:55:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229918AbiIHUzD (ORCPT ); Thu, 8 Sep 2022 16:55:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbiIHUys (ORCPT ); Thu, 8 Sep 2022 16:54:48 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73BBD2AE31 for ; Thu, 8 Sep 2022 13:54:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eP0Aj/IjSrZcJtZNtTzbwzLvl/wLS77RdSJ3W4vFIdGmdOrAeP5w2+dQjIZr8LtSZ2Vykk35bWod7P/5ZqTUrdZP45BfB25JsEEWxv4JxeA3HssZnxqfvMgdBreHfJtnxuB3DSZ50Glsc2OBfukavsNmmg2yQ9PdDTxHAQUbefJY7eMrU8QmPIyGv3IvxIVGZl1hjOtzXdAXhTqkBYe4qkg+VdQ1gzbAmMn+p19MeAtCM48XfV6UpXrFEao33lDvpIy5cP2x9SOTtFNuh7Y1bO6Nvm27kN0zDg5b242ETfiHY2jl8uUyDnsSMW32mG+fPDjL4aQ6+FHbSnGk4jZq0Q== 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=UhMaAAD7rYszdI14wqYtl66nULy2WvdHxs6BcbK+RC0=; b=I05+9hUNaf6dLc9WaRY8iOomfXjlJdCaB+Fz2avp+T8UFdTrEPsZW7//5Vd7aR+Bu20nxovO+axwm4UDJuhW63jMj9hDKN++q1dECsdXi9IgFrCjOnurGF3q2wEyKzniUg5va6xJ0XpGW/guF1C2EYPWqfbSw0iT+FSe3xtg6BGg3k2k2gVXoEHbj6ETrrh1WdXiS/Ss//ix/+XY4caFT7xgl5d0r5m5FKk8Te4izIxMqBQoMHLDdIEgG/g/4nPrSNMvG9DRr8kTRZhcg7yceWURNGv00fvEFVqJVbyFUQ8bKpK50mh0Sn5g+nLLyJxXBpnDZrzv3mJV0V2+TdFLbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=vger.kernel.org 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=UhMaAAD7rYszdI14wqYtl66nULy2WvdHxs6BcbK+RC0=; b=fous6R00vgs1TXgGWZ5dKcLgKVPQ1ivCWLt9bdlbqBw88rthnFExQMc8a/7Q7WFrDKLAeIBTXeDQRj3EcvypdeJhqHfQz0nD5ZdCG5l0yrUSc0lg1+fwd0tiqyLLtfmtX5tsmaP7CNDFLR3gOBy7MtPv6C9FKR/9193lthbct2ruUHbR/ZF/QFUuO8/Zb84LfKtgrwgPrwAHgnH/dH8TRKDPTIOIoo7WIfPaupWygsrnYW+ruJrE2VcO4RG7t2tmBucd3GdjfWDvncwlBRjYwtz1sGKWv7KacQKRxaMJJnR7tPJDk1ogwbLg4rY6T5O9auuIBCwndJ2FFUZPCk73OQ== Received: from CY5PR17CA0020.namprd17.prod.outlook.com (2603:10b6:930:17::32) by BL1PR12MB5109.namprd12.prod.outlook.com (2603:10b6:208:309::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.12; Thu, 8 Sep 2022 20:54:45 +0000 Received: from CY4PEPF0000B8E8.namprd05.prod.outlook.com (2603:10b6:930:17:cafe::f3) by CY5PR17CA0020.outlook.office365.com (2603:10b6:930:17::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.19 via Frontend Transport; Thu, 8 Sep 2022 20:54:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by CY4PEPF0000B8E8.mail.protection.outlook.com (10.167.241.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5612.10 via Frontend Transport; Thu, 8 Sep 2022 20:54:45 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Thu, 8 Sep 2022 20:54:44 +0000 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.986.29; Thu, 8 Sep 2022 13:54:44 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 8 Sep 2022 13:54:41 -0700 From: Michael Guralnik To: , CC: , , , Aharon Landau , Michael Guralnik Subject: [PATCH rdma-next 1/8] RDMA/mlx5: Don't keep umrable 'page_shift' in cache entries Date: Thu, 8 Sep 2022 23:54:14 +0300 Message-ID: <20220908205421.210048-2-michaelgur@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220908205421.210048-1-michaelgur@nvidia.com> References: <20220908205421.210048-1-michaelgur@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000B8E8:EE_|BL1PR12MB5109:EE_ X-MS-Office365-Filtering-Correlation-Id: d02bfcae-e15d-4dbf-93da-08da91dc5c49 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TU0WH1MoehUOBOOI1LJff+KAtLipGhIo/jvI8h7f2qGlFjHa1h2tGvVk8mAxN+fxnJwwmzgOLz3hwcbm+tc2/8p4/5N+GXU7EEolsTctZUu8WHezYp4MkFsStDQRPqaet4SrsDsbiYQ5zCO5ONWK1F50hlcCGWoCWSRTlxiHG96cnNB84QwecJWyERC8Lt7AUqYJKtC5uZKggfJrzwBishKsox4vTRVZx22qnej/6IT+LdKYXtE66aKP/FaZaZGh9AXC2uJw6Sm2lDZmsm04Seqa8zdTnyqULb9PSAwvbZ8rGPB7u2/T+vmuGdsQFZlpTmWBkXT9V1CEQ+tIFnvR8GDIRVgtPxBtMyBOYECZPYlEXOkmGnN0yybjLoH3gsnebGatdPwD7VwG1/QonfS9EWTbS8NnayA8jWCreOvknnb+63K5KuokjIjjOdrTgTPekUL5mVGWQGcltxUUwswqgvUWQ6Mv8PTAKlnaDqd46TQI0pH51wIGHyP2AJOvjCm8Hisd8LQ7b+IqACJk/40S9IYLQuUuT+7QIGSp3RY4W5WVU8/NUOR/HmKSNvMWWAm0kvHOKq/WppkDdYxUWnh+dYG2GZUImsdkguXS+nvZXXqezDW8VHmxaDWIYmR7mu32/v1ZVzlWjhxFRC6kOZm/qnkdl6I8SOTe6wVvbJAqKu6q8rwhyHkbhD3P3jtxIIB6tFmm+oQSyQU1iCfG+I7CtcnSKc1Te7WJrE4o9ctqWx/kkBap35/vhJX3WQ9bZWPZ31mH2A/n26Dbn+ugJDbXSABiuk6uls3ib7ArZV9rtu4= X-Forefront-Antispam-Report: CIP:12.22.5.236;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(396003)(376002)(136003)(346002)(39860400002)(46966006)(36840700001)(40470700004)(26005)(8676002)(70586007)(7696005)(4326008)(478600001)(70206006)(83380400001)(5660300002)(336012)(186003)(40460700003)(2906002)(6666004)(107886003)(1076003)(426003)(47076005)(2616005)(8936002)(86362001)(40480700001)(41300700001)(36756003)(82310400005)(81166007)(82740400003)(316002)(54906003)(6636002)(36860700001)(110136005)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2022 20:54:45.2098 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d02bfcae-e15d-4dbf-93da-08da91dc5c49 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.236];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000B8E8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5109 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Aharon Landau Page size can be changed using UMR. Therefore, don't treat it as a cache entry property. Removing it from struct mlx5_cache_ent. All cache mkeys will be created with default PAGE_SHIFT, and updated with the needed page_shift using UMR when passing them to a user. Signed-off-by: Aharon Landau Reviewed-by: Michael Guralnik --- drivers/infiniband/hw/mlx5/mlx5_ib.h | 1 - drivers/infiniband/hw/mlx5/mr.c | 3 +-- drivers/infiniband/hw/mlx5/odp.c | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h index 2e2ad3918385..d260132d8f45 100644 --- a/drivers/infiniband/hw/mlx5/mlx5_ib.h +++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h @@ -734,7 +734,6 @@ struct mlx5_cache_ent { char name[4]; u32 order; u32 access_mode; - u32 page; unsigned int ndescs; u8 disabled:1; diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c index bfec9bc3cdd8..d8bdba0056a1 100644 --- a/drivers/infiniband/hw/mlx5/mr.c +++ b/drivers/infiniband/hw/mlx5/mr.c @@ -297,7 +297,7 @@ static void set_cache_mkc(struct mlx5_cache_ent *ent, void *mkc) MLX5_SET(mkc, mkc, translations_octword_size, get_mkc_octo_size(ent->access_mode, ent->ndescs)); - MLX5_SET(mkc, mkc, log_page_size, ent->page); + MLX5_SET(mkc, mkc, log_page_size, PAGE_SHIFT); } /* Asynchronously schedule new MRs to be populated in the cache. */ @@ -765,7 +765,6 @@ int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) if (ent->order > mkey_cache_max_order(dev)) continue; - ent->page = PAGE_SHIFT; ent->ndescs = 1 << ent->order; ent->access_mode = MLX5_MKC_ACCESS_MODE_MTT; if ((dev->mdev->profile.mask & MLX5_PROF_MASK_MR_CACHE) && diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c index bc97958818bb..e9a29adef7dc 100644 --- a/drivers/infiniband/hw/mlx5/odp.c +++ b/drivers/infiniband/hw/mlx5/odp.c @@ -1595,14 +1595,12 @@ void mlx5_odp_init_mkey_cache_entry(struct mlx5_cache_ent *ent) switch (ent->order - 2) { case MLX5_IMR_MTT_CACHE_ENTRY: - ent->page = PAGE_SHIFT; ent->ndescs = MLX5_IMR_MTT_ENTRIES; ent->access_mode = MLX5_MKC_ACCESS_MODE_MTT; ent->limit = 0; break; case MLX5_IMR_KSM_CACHE_ENTRY: - ent->page = MLX5_KSM_PAGE_SHIFT; ent->ndescs = mlx5_imr_ksm_entries; ent->access_mode = MLX5_MKC_ACCESS_MODE_KSM; ent->limit = 0; From patchwork Thu Sep 8 20:54:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Guralnik X-Patchwork-Id: 12970658 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63BD2C38145 for ; Thu, 8 Sep 2022 20:55:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229921AbiIHUzE (ORCPT ); Thu, 8 Sep 2022 16:55:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbiIHUyw (ORCPT ); Thu, 8 Sep 2022 16:54:52 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2085.outbound.protection.outlook.com [40.107.220.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07FC0402FB for ; Thu, 8 Sep 2022 13:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DOy7RajHUn6LYKTMcoK6wNRF+anUbGvZm5TazH5dzY90sKp9CxzwLv9Yz4i9ShKRaeX3Lz8sNYIN1AKEJfnkVYTrIz97SvUchoU/BadKu+JoFLYG+f210rt4WTo0SNQ8rvddBgEMgJ2VuwZiRmzkVK2GQMwFNmBROP1xLUqAu9Dn29KRfl2xNPR4aT4Wp3GYwFVyNzoPc8ja/SvOot9NZ2vp+CJ4/K1pk77aN+DI/BhU95L2TTzHvMmoqe/FrsN/H72wrnjX3Bz433MjGHpbtjr3z3CYbUCO/aJa2EcMIG5ARVNsBTOSBJyFCdkNMYzjBe6ZNrj6ceMi9dvGAS/rkw== 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=LkxKrHqOtrKcVsqu4nUFtoevAkrxm+76jOkJBUeX49k=; b=jOdh7t9HM7bsZ5irE2WxPYR+hKbIDRxd+nDD2HurHhVPxtzxZFYSs0FCZH1bESNQHIadHm7SNet81Jnegm7jpPgw75aF2QfdD2YG6ZOZqF1UnIbCCZ5XKzcIR34wLl1vJwyBQB/S30w8AF1wnp/13EmfRPxfaJRWcNuvpH45KT0ynMD87wEwLG3LHCaztixmU8Wfqj9TKxoSu9HboYj34CNw1UcEYP93Sc9QZ/QexjNsSPSZ2AAHXrFrWXHQuYxoLisl8cleoFd/RK5v98E3iVO8Ai5pyA2h1mcyvredxqwnF9nqjmDHl5rGHEnJpGJx5H/1U1OQBAGnWVIf0Gr6ew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=vger.kernel.org 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=LkxKrHqOtrKcVsqu4nUFtoevAkrxm+76jOkJBUeX49k=; b=Lv0htTngherzCM4WGKzXRue0OXagvebH6t4e6qIsPP4w94duXQgIHl8+7jBvsRlUOBhK7Ma74OIC0GO2B7KB9jweinWjEyv7gRRqWMu7i+l0GTOSkeadgw7m2JvUNVX9KDDZjEGkRxZAci2LztyxXeWwSPTMsJAWFYzlHUaGTZrgk+DjUotInaxcYqSaHbRxZCrPOug71K4U7trZ0pg43ZT8V/rz0b9g0NR2mj/y0/4ZyQb6c8sMVUBHqF/EuHxc9p1TVulLeaJ3tC3UIUuMMCQIgaVapOyv0iR6HjhRRSPsu1rHW5KJ+Noahky5trIHd0rI9WfYrDrqiB3qaYkufA== Received: from BN9PR03CA0359.namprd03.prod.outlook.com (2603:10b6:408:f6::34) by CY5PR12MB6453.namprd12.prod.outlook.com (2603:10b6:930:37::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Thu, 8 Sep 2022 20:54:48 +0000 Received: from BN8NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::85) by BN9PR03CA0359.outlook.office365.com (2603:10b6:408:f6::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.14 via Frontend Transport; Thu, 8 Sep 2022 20:54:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) 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 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT013.mail.protection.outlook.com (10.13.176.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5612.13 via Frontend Transport; Thu, 8 Sep 2022 20:54:48 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Thu, 8 Sep 2022 20:54:47 +0000 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.986.29; Thu, 8 Sep 2022 13:54:46 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 8 Sep 2022 13:54:44 -0700 From: Michael Guralnik To: , CC: , , , Aharon Landau , Michael Guralnik Subject: [PATCH rdma-next 2/8] RDMA/mlx5: Generalize mlx5_cache_cache_mr() to fit all cacheable mkeys Date: Thu, 8 Sep 2022 23:54:15 +0300 Message-ID: <20220908205421.210048-3-michaelgur@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220908205421.210048-1-michaelgur@nvidia.com> References: <20220908205421.210048-1-michaelgur@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT013:EE_|CY5PR12MB6453:EE_ X-MS-Office365-Filtering-Correlation-Id: fb1fa2c9-17a9-4a64-67fd-08da91dc5e1f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ec1DvvcrXroWXtS1Q2FD5Ql4qKpiXt911VG6CSpkshX0FJr8aWJFuXjslzOwFhKBwGj4ycrhDBBwgY4X/OaN7nmZyWJu9vmy4914QqWHhnry04mxDsogbJnoHbfkuM1d3kNnjkuP/xFhRw9svlcHU+16n6OaVxIUdVUTEcrkTKDCMHlX9s0ZbdQRzewx5ZqcELjg5uBe7I/gmoNHRByaBmvW8nylNAMPtxvADbXKHRNBQOD3JvA/kYHWvf1HWYXJiA5+lX5DEwvmtPcFsyru/+hGEIU2ZcU5C+f9hwTd9SHtGVXX+YZuEJSGUoupwngtqN72RIKYDrgMHz13wPO4BRfjZ1FG20mYDlWp4E4KSQ4JPuRoFk1SVrrbIOUc6VjXv37aqQXUlkOK7ME1RecXYM/yCf5mwNTRQHjaOuGEuROwEXv0V+hpND+agvTvwLxKJVMAEn+Yz2FLA1qsmEl53ks8uJ3d42hMgbqSU2upKv/ePihVuX5u5evBVEUFO6uoVV6OsLITv3oWCQuodSkCvxPEa6b2v006wW5l30Yar/9wjKKxH11OMfVQRIXu6UQdD0OUj6lFraC3uM4Wehp8bT8Q6C9N53KM7Mh2ZSHhdNIIxdYcQ5LBVWDIeERgDJNfsts7EkGXPMuW5vZ1ab+a+FIfhZpEgyn2dXQeaLMa96uZP0rAHfkEGF7reg/WuUUFUrUJ8Ki+jer6IpuFEzn5MNjy5fp0MtHk3v53HWhXCj3SqMYV75DIaVvsP18AS8LVmZWVB/B3T4bAMA69ryGatNWJuLFRqk+RgA5yXbp6DvY= X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(396003)(39860400002)(346002)(376002)(136003)(40470700004)(46966006)(36840700001)(40460700003)(41300700001)(70206006)(478600001)(4326008)(8676002)(110136005)(6636002)(316002)(70586007)(54906003)(86362001)(47076005)(107886003)(83380400001)(36860700001)(82740400003)(1076003)(81166007)(6666004)(2616005)(26005)(336012)(426003)(186003)(356005)(7696005)(36756003)(2906002)(8936002)(82310400005)(40480700001)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2022 20:54:48.1795 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fb1fa2c9-17a9-4a64-67fd-08da91dc5e1f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6453 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Aharon Landau All the mkeys that can use UMR, can be cached. Instead of using reg_create() for mkeys that are not available in the cache, generalize mlx5_cache_cache_mr() to fit all cacheable mkeys. When a specific mkey request can not be satisfied by the available cache mkeys, synchronously create an mkey with the requested properties. On the following patches, I will introduce a mechanism to cache all cacheable mkeys upon dereging the MR. Signed-off-by: Aharon Landau Reviewed-by: Michael Guralnik --- drivers/infiniband/hw/mlx5/mlx5_ib.h | 6 +- drivers/infiniband/hw/mlx5/mr.c | 146 +++++++++++++++------------ drivers/infiniband/hw/mlx5/odp.c | 9 +- 3 files changed, 87 insertions(+), 74 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h index d260132d8f45..cb8006b854e0 100644 --- a/drivers/infiniband/hw/mlx5/mlx5_ib.h +++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h @@ -1312,9 +1312,9 @@ int mlx5_ib_get_cqe_size(struct ib_cq *ibcq); int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev); int mlx5_mkey_cache_cleanup(struct mlx5_ib_dev *dev); -struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, - struct mlx5_cache_ent *ent, - int access_flags); +struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, u8 access_mode, + unsigned int access_flags, + unsigned int ndescs); int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask, struct ib_mr_status *mr_status); diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c index d8bdba0056a1..b8529f73b306 100644 --- a/drivers/infiniband/hw/mlx5/mr.c +++ b/drivers/infiniband/hw/mlx5/mr.c @@ -287,16 +287,18 @@ static int get_mkc_octo_size(unsigned int access_mode, unsigned int ndescs) return ret; } -static void set_cache_mkc(struct mlx5_cache_ent *ent, void *mkc) +static void set_cache_mkc(struct mlx5_ib_dev *dev, u8 access_mode, + unsigned int access_flags, unsigned int ndescs, + void *mkc) { - set_mkc_access_pd_addr_fields(mkc, 0, 0, ent->dev->umrc.pd); + set_mkc_access_pd_addr_fields(mkc, access_flags, 0, dev->umrc.pd); MLX5_SET(mkc, mkc, free, 1); MLX5_SET(mkc, mkc, umr_en, 1); - MLX5_SET(mkc, mkc, access_mode_1_0, ent->access_mode & 0x3); - MLX5_SET(mkc, mkc, access_mode_4_2, (ent->access_mode >> 2) & 0x7); + MLX5_SET(mkc, mkc, access_mode_1_0, access_mode & 0x3); + MLX5_SET(mkc, mkc, access_mode_4_2, (access_mode >> 2) & 0x7); MLX5_SET(mkc, mkc, translations_octword_size, - get_mkc_octo_size(ent->access_mode, ent->ndescs)); + get_mkc_octo_size(access_mode, ndescs)); MLX5_SET(mkc, mkc, log_page_size, PAGE_SHIFT); } @@ -315,7 +317,7 @@ static int add_keys(struct mlx5_cache_ent *ent, unsigned int num) return -ENOMEM; mkc = MLX5_ADDR_OF(create_mkey_in, async_create->in, memory_key_mkey_entry); - set_cache_mkc(ent, mkc); + set_cache_mkc(ent->dev, ent->access_mode, 0, ent->ndescs, mkc); async_create->ent = ent; err = push_mkey(ent, true, NULL); @@ -340,8 +342,10 @@ static int add_keys(struct mlx5_cache_ent *ent, unsigned int num) return err; } -/* Synchronously create a MR in the cache */ -static int create_cache_mkey(struct mlx5_cache_ent *ent, u32 *mkey) +/* Synchronously create a cacheable mkey */ +static int create_cache_mkey(struct mlx5_ib_dev *dev, u8 access_mode, + unsigned int access_flags, unsigned int ndescs, + struct mlx5_ib_mkey *mkey) { size_t inlen = MLX5_ST_SZ_BYTES(create_mkey_in); void *mkc; @@ -352,14 +356,9 @@ static int create_cache_mkey(struct mlx5_cache_ent *ent, u32 *mkey) if (!in) return -ENOMEM; mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry); - set_cache_mkc(ent, mkc); - - err = mlx5_core_create_mkey(ent->dev->mdev, mkey, in, inlen); - if (err) - goto free_in; + set_cache_mkc(dev, access_mode, access_flags, ndescs, mkc); - WRITE_ONCE(ent->dev->cache.last_add, jiffies); -free_in: + err = mlx5_ib_create_mkey(dev, mkey, in, inlen); kfree(in); return err; } @@ -637,41 +636,80 @@ static void delayed_cache_work_func(struct work_struct *work) __cache_work_func(ent); } -struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, - struct mlx5_cache_ent *ent, - int access_flags) +static bool mlx5_ent_get_mkey(struct mlx5_cache_ent *ent, struct mlx5_ib_mr *mr) { - struct mlx5_ib_mr *mr; - int err; + xa_lock_irq(&ent->mkeys); + if (!ent->stored) { + queue_adjust_cache_locked(ent); + ent->miss++; + xa_unlock_irq(&ent->mkeys); + return false; + } + + mr->mmkey.key = pop_stored_mkey(ent); + mr->mmkey.ndescs = ent->ndescs; + mr->mmkey.cache_ent = ent; + queue_adjust_cache_locked(ent); + ent->in_use++; + xa_unlock_irq(&ent->mkeys); + return true; +} + +static struct mlx5_cache_ent *mkey_cache_ent_from_order(struct mlx5_ib_dev *dev, + unsigned int order) +{ + struct mlx5_mkey_cache *cache = &dev->cache; + + if (order < cache->ent[0].order) + return &cache->ent[0]; + order = order - cache->ent[0].order; + if (order > MKEY_CACHE_LAST_STD_ENTRY) + return NULL; + return &cache->ent[order]; +} + +static bool mlx5_cache_get_mkey(struct mlx5_ib_dev *dev, u8 access_mode, + u8 access_flags, unsigned int ndescs, + struct mlx5_ib_mr *mr) +{ + struct mlx5_cache_ent *ent; if (!mlx5r_umr_can_reconfig(dev, 0, access_flags)) - return ERR_PTR(-EOPNOTSUPP); + return false; + + if (access_mode == MLX5_MKC_ACCESS_MODE_KSM) + ent = &dev->cache.ent[MLX5_IMR_KSM_CACHE_ENTRY]; + + ent = mkey_cache_ent_from_order(dev, order_base_2(ndescs)); + if (!ent) + return false; + + return mlx5_ent_get_mkey(ent, mr); +} + +struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, u8 access_mode, + unsigned int access_flags, + unsigned int ndescs) +{ + struct mlx5_ib_mr *mr; + int err; mr = kzalloc(sizeof(*mr), GFP_KERNEL); if (!mr) return ERR_PTR(-ENOMEM); - xa_lock_irq(&ent->mkeys); - ent->in_use++; - - if (!ent->stored) { - queue_adjust_cache_locked(ent); - ent->miss++; - xa_unlock_irq(&ent->mkeys); - err = create_cache_mkey(ent, &mr->mmkey.key); + if (!mlx5_cache_get_mkey(dev, access_mode, access_flags, ndescs, mr)) { + /* + * Didn't find an mkey in cache. + * Create an mkey with the exact needed size. + */ + err = create_cache_mkey(dev, access_mode, access_flags, ndescs, + &mr->mmkey); if (err) { - xa_lock_irq(&ent->mkeys); - ent->in_use--; - xa_unlock_irq(&ent->mkeys); kfree(mr); return ERR_PTR(err); } - } else { - mr->mmkey.key = pop_stored_mkey(ent); - queue_adjust_cache_locked(ent); - xa_unlock_irq(&ent->mkeys); } - mr->mmkey.cache_ent = ent; mr->mmkey.type = MLX5_MKEY_MR; init_waitqueue_head(&mr->mmkey.wait); return mr; @@ -876,19 +914,6 @@ static int mkey_cache_max_order(struct mlx5_ib_dev *dev) return MLX5_MAX_UMR_SHIFT; } -static struct mlx5_cache_ent *mkey_cache_ent_from_order(struct mlx5_ib_dev *dev, - unsigned int order) -{ - struct mlx5_mkey_cache *cache = &dev->cache; - - if (order < cache->ent[0].order) - return &cache->ent[0]; - order = order - cache->ent[0].order; - if (order > MKEY_CACHE_LAST_STD_ENTRY) - return NULL; - return &cache->ent[order]; -} - static void set_mr_fields(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr, u64 length, int access_flags, u64 iova) { @@ -916,9 +941,8 @@ static struct mlx5_ib_mr *alloc_cacheable_mr(struct ib_pd *pd, int access_flags) { struct mlx5_ib_dev *dev = to_mdev(pd->device); - struct mlx5_cache_ent *ent; + unsigned int page_size, ndescs; struct mlx5_ib_mr *mr; - unsigned int page_size; if (umem->is_dmabuf) page_size = mlx5_umem_dmabuf_default_pgsz(umem, iova); @@ -927,21 +951,11 @@ static struct mlx5_ib_mr *alloc_cacheable_mr(struct ib_pd *pd, 0, iova); if (WARN_ON(!page_size)) return ERR_PTR(-EINVAL); - ent = mkey_cache_ent_from_order( - dev, order_base_2(ib_umem_num_dma_blocks(umem, page_size))); - /* - * Matches access in alloc_cache_mr(). If the MR can't come from the - * cache then synchronously create an uncached one. - */ - if (!ent || ent->limit == 0 || - !mlx5r_umr_can_reconfig(dev, 0, access_flags)) { - mutex_lock(&dev->slow_path_mutex); - mr = reg_create(pd, umem, iova, access_flags, page_size, false); - mutex_unlock(&dev->slow_path_mutex); - return mr; - } - mr = mlx5_mr_cache_alloc(dev, ent, access_flags); + ndescs = ib_umem_num_dma_blocks(umem, page_size); + + mr = mlx5_mr_cache_alloc(dev, MLX5_MKC_ACCESS_MODE_MTT, + access_flags, ndescs); if (IS_ERR(mr)) return mr; diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c index e9a29adef7dc..f7c9eeaa8e79 100644 --- a/drivers/infiniband/hw/mlx5/odp.c +++ b/drivers/infiniband/hw/mlx5/odp.c @@ -418,8 +418,8 @@ static struct mlx5_ib_mr *implicit_get_child_mr(struct mlx5_ib_mr *imr, if (IS_ERR(odp)) return ERR_CAST(odp); - mr = mlx5_mr_cache_alloc(dev, &dev->cache.ent[MLX5_IMR_MTT_CACHE_ENTRY], - imr->access_flags); + mr = mlx5_mr_cache_alloc(dev, MLX5_MKC_ACCESS_MODE_MTT, + imr->access_flags, MLX5_IMR_MTT_ENTRIES); if (IS_ERR(mr)) { ib_umem_odp_release(odp); return mr; @@ -493,9 +493,8 @@ struct mlx5_ib_mr *mlx5_ib_alloc_implicit_mr(struct mlx5_ib_pd *pd, if (IS_ERR(umem_odp)) return ERR_CAST(umem_odp); - imr = mlx5_mr_cache_alloc(dev, - &dev->cache.ent[MLX5_IMR_KSM_CACHE_ENTRY], - access_flags); + imr = mlx5_mr_cache_alloc(dev, MLX5_MKC_ACCESS_MODE_KSM, access_flags, + mlx5_imr_ksm_entries); if (IS_ERR(imr)) { ib_umem_odp_release(umem_odp); return imr; From patchwork Thu Sep 8 20:54:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Guralnik X-Patchwork-Id: 12970660 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74AEAC54EE9 for ; Thu, 8 Sep 2022 20:55:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229734AbiIHUzJ (ORCPT ); Thu, 8 Sep 2022 16:55:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbiIHUzF (ORCPT ); Thu, 8 Sep 2022 16:55:05 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2064.outbound.protection.outlook.com [40.107.96.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E88604F396 for ; Thu, 8 Sep 2022 13:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FiTlaLiDO2r05yS3r/FM43AKbSwLIEXYnbqbcQE/ZIW6bRAInYBDg5QMOXPtYVNww2GlZzJmbHXzagnAal//f5WpeMZu7RcAQg4LhJFJ+3xe7mMP4EyOAvX2oQCxWedenm9I4QySGgOWoNM88GjPJlfLr1RboXRfOmhOWXBDEd93apkIzC+MB6qyiB+JhImTzfH9tXbtEA1LbOaDCmuFxwOzedOe6lvMCdukTKa7+PytuoT67jGwiISretw0UQchOLPTYC6jmBnz5Ld+CrjZSHV+8Y5CzA9MalneGUhy1PK1Cyy9NPqBkSsWVvLeIzvN5WF+kgnhymZ2pDLqYRSumw== 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=VX8kxUEwlDeUpquLyPtvZ2Rh6UnGCoQYp5VxivZnEt8=; b=Cgs4wHLcjYhz/gKfVmsGZ/fBB/yCYRfMjTbi0ZsL6Fw21po3GsGQ1UeW9/loC727AgCDexB8z7rFipuiwCTk/ocTxqD6T39QNpb5+oSQEveWCWpYEet3r3e+naRwf3K+K6d4GnzG+EzjUHNa9HruJv00s5nzRZkdNnTFc2NWhX0r5gi/k5EPr66tljYnN6ia4C92e08CpmBe0duItnmagw66KxD6P4vxJfiAObYkpOc00LZRUQnakpn4R6Z/gDMbx8n7cE5sgDgoRzbRtVVpzx0GWGRCydWKeKeDJPJSrbEnLcGs4Wkj/2KXHmopJeSDULw8zNbeymm05PPXstiXYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=vger.kernel.org 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=VX8kxUEwlDeUpquLyPtvZ2Rh6UnGCoQYp5VxivZnEt8=; b=WHnYsaAS9Fj3nVeMudP5Ax0JNIGPD4CYnH1wnia8un6mpeFn2fDTfVyDhO4wmBuj8z43lgtiL2TF7QOTS+bbXZfshtgsWIHu3KDTBj7/NsHsQJOS9KAkpn4UiDFTmrrDeOERLY0Mm65NNJa9ddVD87Kx6Zrt6e7bOQ5QvSMgRVGJzlSh/pcjkc5uvIr22HzUrNanh/MM1Xqq+ElrsUGwE0lDJWWhHklqzpVepgyVOKyTPE67eO1FwqQ2gbpXb4K+fmWZKQowfrYVmuuHqJ3YsGQvd814ZtLKaNS4c9vvb7lLGFOfm40uhgHwzIk7TibbGTSjmHvWR6hze1evVjkUbQ== Received: from CY5PR16CA0020.namprd16.prod.outlook.com (2603:10b6:930:10::16) by PH7PR12MB6693.namprd12.prod.outlook.com (2603:10b6:510:1b0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Thu, 8 Sep 2022 20:54:55 +0000 Received: from CY4PEPF0000B8EA.namprd05.prod.outlook.com (2603:10b6:930:10:cafe::60) by CY5PR16CA0020.outlook.office365.com (2603:10b6:930:10::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.19 via Frontend Transport; Thu, 8 Sep 2022 20:54:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by CY4PEPF0000B8EA.mail.protection.outlook.com (10.167.241.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5612.10 via Frontend Transport; Thu, 8 Sep 2022 20:54:52 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Thu, 8 Sep 2022 20:54:49 +0000 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.986.29; Thu, 8 Sep 2022 13:54:49 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 8 Sep 2022 13:54:47 -0700 From: Michael Guralnik To: , CC: , , , Aharon Landau , Michael Guralnik Subject: [PATCH rdma-next 3/8] RDMA/mlx5: Remove explicit ODP cache entry Date: Thu, 8 Sep 2022 23:54:16 +0300 Message-ID: <20220908205421.210048-4-michaelgur@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220908205421.210048-1-michaelgur@nvidia.com> References: <20220908205421.210048-1-michaelgur@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000B8EA:EE_|PH7PR12MB6693:EE_ X-MS-Office365-Filtering-Correlation-Id: 33db76de-49c9-4469-a641-08da91dc6092 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lAbuuThOZxz2d8Ie7Jg3aLT3rMWaZXN/Oo9l2OVTdY/xF9nygV2+035WLbgkOjY5tpg8QofFVG0qGYL7LDEV1Ma1Cmw4RGErDzpZlazCkN1HHcZWpcm1r2twKiQzsYJwGnJp9EIJlyoL7j7w68ssCgIgjXs0RqIjOIX/n2k7FmWq7TrX198Mibrlqi8hKB/gIOrgDJK0zceib2dmOPlXA0vRIAHAga6nKR6GsRnybKbazY1+BD/oDc1oSrKMS6cKgX3ivXfd8l8Y79FKw17HA5wsWKOEk6ed0pj6008VxAKaQcDDzkh8AwyU74/Oj7x9CJHAXR+usN0Yg48sxBZN7kFZBnIYfZcnHxl6QwycRiM+VoRvdqsnlF3pNxEYisXrPYaLpCODNJDNilOQQz2YvthbTGGWXf6w8hldfb9hsVaiTgcWNHe6JPkOvsYZv+WsmNFP2/oqiVy9738dfbhEhDV1CdmiYgwbC3JpIHJ+/upZRV/t1DT/U1zNYBrx6AOWlqJ76pqyNxFX202NQjCN9WkdjO2lqVrevokL9i2QdWd86uoMl9fH9vWGaGeml/IgKS5SXGKXLlLegWatcvm2m7EMNfgrezJ0SGaaMQ2E410VYzo0EIbs/fCXsEav5OrgSmjY2HbUhvtUzZ+0InTPp+hu74/YvY/au1tQAlGAGQZYPhc8QVKjjD3eekbgE1vrsLh0y72g0zVy5Md2m41sra3WxVMbcOR9MnHROgnunzL0jeal9FWqjgQ/NN6sgqzNSZfTwEkBnh5/PdUpvxvMFXQEzARrtz7/grM2u57QVlTn4Tl1khN4JfOQ/2NNuWY3 X-Forefront-Antispam-Report: CIP:12.22.5.236;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(136003)(396003)(376002)(346002)(46966006)(40470700004)(36840700001)(40460700003)(5660300002)(4326008)(8676002)(47076005)(107886003)(8936002)(70206006)(6636002)(316002)(41300700001)(54906003)(6666004)(36756003)(478600001)(70586007)(110136005)(356005)(26005)(86362001)(2906002)(7696005)(186003)(82740400003)(426003)(1076003)(82310400005)(83380400001)(36860700001)(336012)(2616005)(81166007)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2022 20:54:52.0246 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 33db76de-49c9-4469-a641-08da91dc6092 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.236];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000B8EA.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6693 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Aharon Landau Explicit ODP mkey doesn't have unique properties. There is no need to devote to it a special entry. Removing it. Signed-off-by: Aharon Landau Reviewed-by: Michael Guralnik --- drivers/infiniband/hw/mlx5/odp.c | 16 ++-------------- include/linux/mlx5/driver.h | 1 - 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c index f7c9eeaa8e79..137143da5959 100644 --- a/drivers/infiniband/hw/mlx5/odp.c +++ b/drivers/infiniband/hw/mlx5/odp.c @@ -1591,20 +1591,8 @@ void mlx5_odp_init_mkey_cache_entry(struct mlx5_cache_ent *ent) { if (!(ent->dev->odp_caps.general_caps & IB_ODP_SUPPORT_IMPLICIT)) return; - - switch (ent->order - 2) { - case MLX5_IMR_MTT_CACHE_ENTRY: - ent->ndescs = MLX5_IMR_MTT_ENTRIES; - ent->access_mode = MLX5_MKC_ACCESS_MODE_MTT; - ent->limit = 0; - break; - - case MLX5_IMR_KSM_CACHE_ENTRY: - ent->ndescs = mlx5_imr_ksm_entries; - ent->access_mode = MLX5_MKC_ACCESS_MODE_KSM; - ent->limit = 0; - break; - } + ent->ndescs = mlx5_imr_ksm_entries; + ent->access_mode = MLX5_MKC_ACCESS_MODE_KSM; } static const struct ib_device_ops mlx5_ib_dev_odp_ops = { diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index 9ccfd9dd0d0f..0f3a96df3377 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -734,7 +734,6 @@ enum { enum { MKEY_CACHE_LAST_STD_ENTRY = 20, - MLX5_IMR_MTT_CACHE_ENTRY, MLX5_IMR_KSM_CACHE_ENTRY, MAX_MKEY_CACHE_ENTRIES }; From patchwork Thu Sep 8 20:54:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Guralnik X-Patchwork-Id: 12970659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E34F1C6FA82 for ; Thu, 8 Sep 2022 20:55:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbiIHUzH (ORCPT ); Thu, 8 Sep 2022 16:55:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbiIHUy5 (ORCPT ); Thu, 8 Sep 2022 16:54:57 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2082.outbound.protection.outlook.com [40.107.95.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E87E4DB54 for ; Thu, 8 Sep 2022 13:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oMcPLoMayApWR31P/cYzLE+90ug0CdlJRlPSPX3tEH1eMCassPcFjVRvvpXyEHUNQ08fGMNzl/NnqNPfq5b0AIhad9JDZVpugJYDPzHI3t0GU3FDQL3AQpvAe4LZ47TxKg0H/XaqiV0JpxYEHIW4r/M7ugdVjpyRv+R+W7wjuoe2QHvE9NkAOvivZpYpFpvWW/CJ9GzJbXi3ljOaasHLicC+S9AO+NmzRqi350a/KdLj9MSNZVkSBp3Q/uko3/xDJ9oPmsoEfr+KczRZW3OoRAFvwJD8urYIba0OLTHUH2ZmSJfPkzZ1Q55wRKrT0STGW+y8+1BtiqUFKWtaH7QzDg== 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=zFVwuAC07SL+VYyBVnItsK+1LKspgtV4dNl6EMG2CMM=; b=QRnGRAeg88L/v6zWf4xIsCBfvr5hYtw9rwgMP2d3tIxbPOOwES0fQfD/Cy2wt3E4iIgq99hHd2Bq8HSlUqtF3N/dktYo+Fm3MYs3+rONsazjFhdhG32qce/flzOJns+cziorco1HnQBSAME4sGFGTU3wWgwl4hHMplHLicIJ97LdJaDNw7IwZkYXRL8HEe1aSfzI3Zm8OGw0gf5x2C8fkpEQBlNbjb6bLk+dlusBtKac9wfaQZwgzLOfCXOVDI4spdJLU51+VW2LaPtZDp8YRHcBjYCgzkALcHUmt2ZRF3grvY/mNtph3l8rQp0p10ILcP6sdHWmh9/CfiNfCuax0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=vger.kernel.org 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=zFVwuAC07SL+VYyBVnItsK+1LKspgtV4dNl6EMG2CMM=; b=Eks+FzfrU6d3qsj9tu+dZ8GQ0wgLcx2U7QSdJjzyUAtocyT8wLt0PizNzixAh9Wa37A2cdBOvhpDIXn9KULs36vwBgF2xRZAJEaSNhhbUHrAVdAbU7DU6zbr7nc4i4BEysNZ4gPt0c04g/kZrwArCDYKtX+3TUYmE8WbCT+D46ZhqF1qI4jSD/190e4ZjJG5v+HbHpBgsGbC2MbHimCSxKx2I+8nBsm4r2MUsWK5h0o+SKoXCjquDTuX4ekw/IvaVz4ZhQGoYmfm2cemZZwQrxbcadg5alPU2uIPgm9tvF5JbST3u2Y8y2zRRTft9rUtDgdea3xauQbxZhAP47wUUA== Received: from BN9P221CA0017.NAMP221.PROD.OUTLOOK.COM (2603:10b6:408:10a::8) by CH0PR12MB5154.namprd12.prod.outlook.com (2603:10b6:610:b9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.16; Thu, 8 Sep 2022 20:54:53 +0000 Received: from BN8NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10a:cafe::b7) by BN9P221CA0017.outlook.office365.com (2603:10b6:408:10a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.18 via Frontend Transport; Thu, 8 Sep 2022 20:54:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by BN8NAM11FT064.mail.protection.outlook.com (10.13.176.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5612.13 via Frontend Transport; Thu, 8 Sep 2022 20:54:53 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Thu, 8 Sep 2022 20:54:52 +0000 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.986.29; Thu, 8 Sep 2022 13:54:51 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 8 Sep 2022 13:54:49 -0700 From: Michael Guralnik To: , CC: , , , Aharon Landau , Michael Guralnik Subject: [PATCH rdma-next 4/8] RDMA/mlx5: Allow rereg all the mkeys that can load pas with UMR Date: Thu, 8 Sep 2022 23:54:17 +0300 Message-ID: <20220908205421.210048-5-michaelgur@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220908205421.210048-1-michaelgur@nvidia.com> References: <20220908205421.210048-1-michaelgur@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT064:EE_|CH0PR12MB5154:EE_ X-MS-Office365-Filtering-Correlation-Id: ee871d96-f7ca-4cf7-58b1-08da91dc6131 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SnJRY1+cXC/LQ3knZyPM0PafaSjCVJ7w+OAUvsaYVxuifVnEt03WaUfRAQn6VWC5Lo1EqzeFkmhw8EHrv0bMQu/W8WYO86m4itgI1ClJ9z+NC1nyC6VfzsWn5yK6ZH0wl9es7z33KCmm8G0gDiw74MCNORGX9lSGhJiyMBWeoZ6o2V91DAPUawgTOuvKhgIfknkc9jRV4l9rWEAj2iX1BNgLhFPCUKGCbCS7HCumgpl+g8mjgTMNbl+vtoBOnfjjO6L/jGPAQffT+BFtXZppiuyf2j1nX3dVN5NJ6GqmlCcxdzCaLS0iDsN1cX60p6bnYjMItH4lshnh3Hipro8ejUQXJqMx3u9NicL40HrNOEemTRbiQ4X+oYn5yxisQ030af8ly5rf5zOHJ2NOnzxu29yoktHeBNvd6Ce4KVXVXDpcQYO11kqhq68hIktiSDCXktSe0v1WNUXFTa1zol5s5oJH3r6ak4TV/YbGHJaJyTFVLnPAjWVEo0bSjWG4bUQmMnRJ0lE1GyhqVL8wJ0kZWTY0TFG91K87qX1WUhXz3s6HPl6A7J1jIT5lE9GPPveqgl4mkuQh6/9Sgq30j6NClpNmS3NM8Lphd//gW54N43p1Px8t3COvdkbz/U+vOCzmqnrOVK+j+3WMqnivBUDCUKTopfzmz6AqA2zhLbDD18EcMExy87YssP9ydfV4Yf3UZvup7IvMLk00Qy1OZzwjryBIog3mBBtqq/OHPRb+XT8oDrplTDcxUjDkXgGsVoFTBHxDyqia/VEcORhaj5w4La4xp05cqqj2f4vr5iGC0fTAuOPZkx3MLC1glN+DkDLc X-Forefront-Antispam-Report: CIP:12.22.5.235;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(396003)(346002)(136003)(376002)(39860400002)(36840700001)(46966006)(40470700004)(8676002)(82310400005)(40480700001)(70586007)(70206006)(86362001)(4326008)(2616005)(82740400003)(6636002)(336012)(1076003)(8936002)(5660300002)(40460700003)(54906003)(316002)(110136005)(36756003)(2906002)(426003)(7696005)(356005)(36860700001)(41300700001)(26005)(478600001)(107886003)(81166007)(6666004)(186003)(47076005)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2022 20:54:53.4084 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ee871d96-f7ca-4cf7-58b1-08da91dc6131 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.235];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5154 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Aharon Landau Keep track of the mkey size of all cacheable mkeys, and by this allow to rereg them. Signed-off-by: Aharon Landau Reviewed-by: Michael Guralnik --- drivers/infiniband/hw/mlx5/mr.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c index b8529f73b306..ea8634cafa9c 100644 --- a/drivers/infiniband/hw/mlx5/mr.c +++ b/drivers/infiniband/hw/mlx5/mr.c @@ -709,6 +709,7 @@ struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, u8 access_mode, kfree(mr); return ERR_PTR(err); } + mr->mmkey.ndescs = ndescs; } mr->mmkey.type = MLX5_MKEY_MR; init_waitqueue_head(&mr->mmkey.wait); @@ -1372,9 +1373,6 @@ static bool can_use_umr_rereg_pas(struct mlx5_ib_mr *mr, { struct mlx5_ib_dev *dev = to_mdev(mr->ibmr.device); - /* We only track the allocated sizes of MRs from the cache */ - if (!mr->mmkey.cache_ent) - return false; if (!mlx5r_umr_can_load_pas(dev, new_umem->length)) return false; @@ -1382,8 +1380,7 @@ static bool can_use_umr_rereg_pas(struct mlx5_ib_mr *mr, mlx5_umem_find_best_pgsz(new_umem, mkc, log_page_size, 0, iova); if (WARN_ON(!*page_size)) return false; - return (1ULL << mr->mmkey.cache_ent->order) >= - ib_umem_num_dma_blocks(new_umem, *page_size); + return mr->mmkey.ndescs >= ib_umem_num_dma_blocks(new_umem, *page_size); } static int umr_rereg_pas(struct mlx5_ib_mr *mr, struct ib_pd *pd, From patchwork Thu Sep 8 20:54:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Guralnik X-Patchwork-Id: 12970661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5453C38145 for ; Thu, 8 Sep 2022 20:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbiIHUzS (ORCPT ); Thu, 8 Sep 2022 16:55:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229899AbiIHUzL (ORCPT ); Thu, 8 Sep 2022 16:55:11 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3921501B2 for ; Thu, 8 Sep 2022 13:54:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CY5oPKw4FDeKGKsJNmtF97W88DDfiL0RFEmYxsuh/96O5Fk3yv18dIHUG6OabfYibT2isfLmlvQllaZvOD6VM7pruMei29MZf+lrTgBxyVtTGy9OWQpbw8V5KfblPLah1kW0pnrDFhehbE1GZUzhlXuZTh2zVV0qRqohqyCWIFhWyySoCgpTiDMxGiGlNZCs0fS1yyei/2nJQd+LXQQSIjzG5zeOh2scRnuThnjezYhVaR2juwX43c9bau/0xiSrGktC86rTB50tQmqJArLFZK5AqHKLnGP/WfVnM7lKqhH6QVeN4RmQyBz1z6KmSNEWZXI8so7mwEHVNkchgy8+Lw== 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=BUKUjwZpYf8tVKLjYGvULc3L3VJYe+CeBScW1KffA7Q=; b=RNwku7Tc3z7Kslx+XgcX+YdQXo4mSZKv7iWAAUcJjV0npQ1Oo1p+cHGcAIF54Ys/RypNzlLFVG4l5rPdwoRmulFuYyqSbWmUnw7kcyq6FaUCmKzLNHqY0AUUh1AI8JYTIHNsF49B91+u/j5W7v0+NE1KP/TwZHqEwL9yFt8x1VYOHJDUvNVWFTSE0ZbzwpJILb0gVVoJI0u1Nx+N2zxpjgZod1554VL5H+6Gxn3DvA1EeHzq/CcCF3etRxfyALGg6iZxGbZ+im8iPrYuHMpe3f6+/VwqoXh/Bobd9g3UegcQTR+kcxFdEaXl0grkJmMn0iyrZtT/a4r0GiUxMdc11g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=vger.kernel.org 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=BUKUjwZpYf8tVKLjYGvULc3L3VJYe+CeBScW1KffA7Q=; b=CAlVdkrW3i6/dqtFEbCcpdDZAO60j7XKJG1crwRmMxq06nYwjPqScbZv99lcuswBF+/LoISEx2Qwafb8CtbWL1QcMo5bzGHSZeAVEK1FpikiCCAtadR3rUDsgMPMBQutzQWX36Y85YrJPlNqaK9rXUglkVqBWxfD5WIq+ZO7lxYIs+GXzQQLi1NMEmsGKFxiwu49A55KbeSmI2rSMZ5v16N50pEcvuG1TGWLPaRziSGDjopBWw9mfNvU32I9OAiJFH6zT0Z16Hbz/rbsRwYMy2u30td3gLyWp6LlB0y6o9GV379ppwjly6ByCDZhC7Dn13RQb0u9Zni5sCLmDgPs1w== Received: from BN9PR03CA0070.namprd03.prod.outlook.com (2603:10b6:408:fc::15) by DM4PR12MB5277.namprd12.prod.outlook.com (2603:10b6:5:390::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.14; Thu, 8 Sep 2022 20:54:57 +0000 Received: from BN8NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fc:cafe::37) by BN9PR03CA0070.outlook.office365.com (2603:10b6:408:fc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.15 via Frontend Transport; Thu, 8 Sep 2022 20:54:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by BN8NAM11FT060.mail.protection.outlook.com (10.13.177.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5612.13 via Frontend Transport; Thu, 8 Sep 2022 20:54:56 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Thu, 8 Sep 2022 20:54:55 +0000 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.986.29; Thu, 8 Sep 2022 13:54:54 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 8 Sep 2022 13:54:52 -0700 From: Michael Guralnik To: , CC: , , , Aharon Landau , Michael Guralnik Subject: [PATCH rdma-next 5/8] RDMA/mlx5: Introduce mlx5r_cache_rb_key Date: Thu, 8 Sep 2022 23:54:18 +0300 Message-ID: <20220908205421.210048-6-michaelgur@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220908205421.210048-1-michaelgur@nvidia.com> References: <20220908205421.210048-1-michaelgur@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT060:EE_|DM4PR12MB5277:EE_ X-MS-Office365-Filtering-Correlation-Id: 71e00798-48a1-4c0e-eff9-08da91dc62cf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KfXcFPu40c0pas5mfYrP3Z/lvXUVNAmNBnA202R775u1PjMfQcBNCyPGF+LGKTdcpGaoSJROuCfNIGos30oJJhwDtULfeMr2ilShjNjOH0KrZ+25W+8Q8d9zN8k0Jcw3rymjljRqeY5va18XeJKq42PLhCcdwmLIczUvLpakvhPFK6V2RY2WpZIG7E3oTIa9xmsRhQvL0xESy713SsHepCmR6s47+OnRG/gzAWKJHCAencTGFNSMXC4bLmASMCmX+5b2P5urYd0mWHIVYRKB4A5ZdFIprf1Yf/kkOgv4xA/KfkGEAJrKsajqa+ztGXzNNhPE3zoBudirVXgYJ6tQ40NGWUUCXJg0bTFKy/RIf3qfhqEdZEuWkGJxISSqZ/fXCAafo9j/S+vlVTyHLAOau6ogWOXqg6eZm81CR3kzasMr0uw/njFNf7vo/2Dm0rhLTg0zWveIOSPlLTgtFJPS7Bw114bHoEIIb+FYVhRA+5H2oIhRPY6BdbRpjZjXVXzstVDGOtgCF1XRbKTb1UBTC9UDzsQiZB4nX3cYnzaFOIgQgHDIHNMiv+MxJVb55s7d/vzc/eOqRXSaZyMq1dLUO4J4Dz1RdrPZcFcgKvPONhJdjQuAAxpinU8hKEO1TAAIVqAGvCFsSlJB5fIBDja5RQG0r/oSJ61PIEwi1oxscfI2bG7rxnUstqxekX1txDnfWnIY7U+4rpOmECran3sCEGGAR/LcK7Zadjs3MXvQ8L0QmRnk1CT21WuKRqgR99t8ca0fH77TJyQ1xfvNyPsxL7RMhDYdtnjnw779taP//S08DhrY9lsW5lWySXkEmrpv X-Forefront-Antispam-Report: CIP:12.22.5.235;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(136003)(346002)(39860400002)(376002)(396003)(36840700001)(46966006)(40470700004)(36860700001)(5660300002)(8936002)(81166007)(2906002)(356005)(40460700003)(82740400003)(41300700001)(336012)(478600001)(26005)(6666004)(82310400005)(7696005)(6636002)(110136005)(316002)(54906003)(107886003)(70586007)(70206006)(83380400001)(40480700001)(4326008)(8676002)(2616005)(1076003)(426003)(186003)(47076005)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2022 20:54:56.0473 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 71e00798-48a1-4c0e-eff9-08da91dc62cf X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.235];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5277 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Aharon Landau In the next patch, I will change the cache structure to an RB tree. Introducing the key of the tree. The key is the mkey properties that UMR operations can't modify. Using this key to define the cache entries and to search and create cache mkeys. Signed-off-by: Aharon Landau Reviewed-by: Michael Guralnik --- drivers/infiniband/hw/mlx5/mlx5_ib.h | 14 +++++- drivers/infiniband/hw/mlx5/mr.c | 73 +++++++++++++++++++--------- drivers/infiniband/hw/mlx5/odp.c | 8 ++- 3 files changed, 69 insertions(+), 26 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h index cb8006b854e0..5b57b2a24b47 100644 --- a/drivers/infiniband/hw/mlx5/mlx5_ib.h +++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h @@ -613,6 +613,16 @@ enum mlx5_mkey_type { MLX5_MKEY_INDIRECT_DEVX, }; +struct mlx5r_cache_rb_key { + unsigned int access_mode; + unsigned int access_flags; + /* + * keep ndescs as the last member so entries with about the same ndescs + * will be close in the tree + */ + unsigned int ndescs; +}; + struct mlx5_ib_mkey { u32 key; enum mlx5_mkey_type type; @@ -731,10 +741,10 @@ struct mlx5_cache_ent { unsigned long stored; unsigned long reserved; + struct mlx5r_cache_rb_key rb_key; + char name[4]; u32 order; - u32 access_mode; - unsigned int ndescs; u8 disabled:1; u8 fill_to_high_water:1; diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c index ea8634cafa9c..bb3d5a766cb8 100644 --- a/drivers/infiniband/hw/mlx5/mr.c +++ b/drivers/infiniband/hw/mlx5/mr.c @@ -287,18 +287,18 @@ static int get_mkc_octo_size(unsigned int access_mode, unsigned int ndescs) return ret; } -static void set_cache_mkc(struct mlx5_ib_dev *dev, u8 access_mode, - unsigned int access_flags, unsigned int ndescs, - void *mkc) +static void set_cache_mkc(struct mlx5_ib_dev *dev, + struct mlx5r_cache_rb_key rb_key, void *mkc) { - set_mkc_access_pd_addr_fields(mkc, access_flags, 0, dev->umrc.pd); + set_mkc_access_pd_addr_fields(mkc, rb_key.access_flags, 0, + dev->umrc.pd); MLX5_SET(mkc, mkc, free, 1); MLX5_SET(mkc, mkc, umr_en, 1); - MLX5_SET(mkc, mkc, access_mode_1_0, access_mode & 0x3); - MLX5_SET(mkc, mkc, access_mode_4_2, (access_mode >> 2) & 0x7); + MLX5_SET(mkc, mkc, access_mode_1_0, rb_key.access_mode & 0x3); + MLX5_SET(mkc, mkc, access_mode_4_2, (rb_key.access_mode >> 2) & 0x7); MLX5_SET(mkc, mkc, translations_octword_size, - get_mkc_octo_size(access_mode, ndescs)); + get_mkc_octo_size(rb_key.access_mode, rb_key.ndescs)); MLX5_SET(mkc, mkc, log_page_size, PAGE_SHIFT); } @@ -317,7 +317,7 @@ static int add_keys(struct mlx5_cache_ent *ent, unsigned int num) return -ENOMEM; mkc = MLX5_ADDR_OF(create_mkey_in, async_create->in, memory_key_mkey_entry); - set_cache_mkc(ent->dev, ent->access_mode, 0, ent->ndescs, mkc); + set_cache_mkc(ent->dev, ent->rb_key, mkc); async_create->ent = ent; err = push_mkey(ent, true, NULL); @@ -343,8 +343,8 @@ static int add_keys(struct mlx5_cache_ent *ent, unsigned int num) } /* Synchronously create a cacheable mkey */ -static int create_cache_mkey(struct mlx5_ib_dev *dev, u8 access_mode, - unsigned int access_flags, unsigned int ndescs, +static int create_cache_mkey(struct mlx5_ib_dev *dev, + struct mlx5r_cache_rb_key rb_key, struct mlx5_ib_mkey *mkey) { size_t inlen = MLX5_ST_SZ_BYTES(create_mkey_in); @@ -356,7 +356,7 @@ static int create_cache_mkey(struct mlx5_ib_dev *dev, u8 access_mode, if (!in) return -ENOMEM; mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry); - set_cache_mkc(dev, access_mode, access_flags, ndescs, mkc); + set_cache_mkc(dev, rb_key, mkc); err = mlx5_ib_create_mkey(dev, mkey, in, inlen); kfree(in); @@ -647,7 +647,7 @@ static bool mlx5_ent_get_mkey(struct mlx5_cache_ent *ent, struct mlx5_ib_mr *mr) } mr->mmkey.key = pop_stored_mkey(ent); - mr->mmkey.ndescs = ent->ndescs; + mr->mmkey.ndescs = ent->rb_key.ndescs; mr->mmkey.cache_ent = ent; queue_adjust_cache_locked(ent); ent->in_use++; @@ -668,29 +668,57 @@ static struct mlx5_cache_ent *mkey_cache_ent_from_order(struct mlx5_ib_dev *dev, return &cache->ent[order]; } -static bool mlx5_cache_get_mkey(struct mlx5_ib_dev *dev, u8 access_mode, - u8 access_flags, unsigned int ndescs, +static bool mlx5_cache_get_mkey(struct mlx5_ib_dev *dev, + struct mlx5r_cache_rb_key rb_key, struct mlx5_ib_mr *mr) { struct mlx5_cache_ent *ent; - if (!mlx5r_umr_can_reconfig(dev, 0, access_flags)) + if (!mlx5r_umr_can_reconfig(dev, 0, rb_key.access_flags)) return false; - if (access_mode == MLX5_MKC_ACCESS_MODE_KSM) + if (rb_key.access_mode == MLX5_MKC_ACCESS_MODE_KSM) ent = &dev->cache.ent[MLX5_IMR_KSM_CACHE_ENTRY]; - ent = mkey_cache_ent_from_order(dev, order_base_2(ndescs)); + ent = mkey_cache_ent_from_order(dev, order_base_2(rb_key.ndescs)); if (!ent) return false; return mlx5_ent_get_mkey(ent, mr); } +static int get_uchangeable_access_flags(struct mlx5_ib_dev *dev, + int access_flags) +{ + int ret = 0; + + if ((access_flags & IB_ACCESS_REMOTE_ATOMIC) && + MLX5_CAP_GEN(dev->mdev, atomic) && + MLX5_CAP_GEN(dev->mdev, umr_modify_atomic_disabled)) + ret |= IB_ACCESS_REMOTE_ATOMIC; + + if ((access_flags & IB_ACCESS_RELAXED_ORDERING) && + MLX5_CAP_GEN(dev->mdev, relaxed_ordering_write) && + !MLX5_CAP_GEN(dev->mdev, relaxed_ordering_write_umr)) + ret |= IB_ACCESS_RELAXED_ORDERING; + + if ((access_flags & IB_ACCESS_RELAXED_ORDERING) && + MLX5_CAP_GEN(dev->mdev, relaxed_ordering_read) && + !MLX5_CAP_GEN(dev->mdev, relaxed_ordering_read_umr)) + ret |= IB_ACCESS_RELAXED_ORDERING; + + return ret; +} + struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, u8 access_mode, unsigned int access_flags, unsigned int ndescs) { + struct mlx5r_cache_rb_key rb_key = { + .access_mode = access_mode, + .access_flags = get_uchangeable_access_flags(dev, access_flags), + .ndescs = ndescs + }; struct mlx5_ib_mr *mr; int err; @@ -698,13 +726,12 @@ struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, u8 access_mode, if (!mr) return ERR_PTR(-ENOMEM); - if (!mlx5_cache_get_mkey(dev, access_mode, access_flags, ndescs, mr)) { + if (!mlx5_cache_get_mkey(dev, rb_key, mr)) { /* * Didn't find an mkey in cache. * Create an mkey with the exact needed size. */ - err = create_cache_mkey(dev, access_mode, access_flags, ndescs, - &mr->mmkey); + err = create_cache_mkey(dev, rb_key, &mr->mmkey); if (err) { kfree(mr); return ERR_PTR(err); @@ -774,6 +801,8 @@ static void delay_time_func(struct timer_list *t) int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) { + struct mlx5r_cache_rb_key rb_key = { .access_mode = + MLX5_MKC_ACCESS_MODE_MTT }; struct mlx5_mkey_cache *cache = &dev->cache; struct mlx5_cache_ent *ent; int i; @@ -804,8 +833,8 @@ int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) if (ent->order > mkey_cache_max_order(dev)) continue; - ent->ndescs = 1 << ent->order; - ent->access_mode = MLX5_MKC_ACCESS_MODE_MTT; + rb_key.ndescs = 1 << ent->order; + ent->rb_key = rb_key; if ((dev->mdev->profile.mask & MLX5_PROF_MASK_MR_CACHE) && !dev->is_rep && mlx5_core_is_pf(dev->mdev) && mlx5r_umr_can_load_pas(dev, 0)) diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c index 137143da5959..90339edddfed 100644 --- a/drivers/infiniband/hw/mlx5/odp.c +++ b/drivers/infiniband/hw/mlx5/odp.c @@ -1589,10 +1589,14 @@ mlx5_ib_odp_destroy_eq(struct mlx5_ib_dev *dev, struct mlx5_ib_pf_eq *eq) void mlx5_odp_init_mkey_cache_entry(struct mlx5_cache_ent *ent) { + struct mlx5r_cache_rb_key rb_key = { + .access_mode = MLX5_MKC_ACCESS_MODE_KSM, + .ndescs = mlx5_imr_ksm_entries + }; + if (!(ent->dev->odp_caps.general_caps & IB_ODP_SUPPORT_IMPLICIT)) return; - ent->ndescs = mlx5_imr_ksm_entries; - ent->access_mode = MLX5_MKC_ACCESS_MODE_KSM; + ent->rb_key = rb_key; } static const struct ib_device_ops mlx5_ib_dev_odp_ops = { From patchwork Thu Sep 8 20:54:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Guralnik X-Patchwork-Id: 12970662 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16F12C54EE9 for ; Thu, 8 Sep 2022 20:55:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229970AbiIHUzU (ORCPT ); Thu, 8 Sep 2022 16:55:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbiIHUzO (ORCPT ); Thu, 8 Sep 2022 16:55:14 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2073.outbound.protection.outlook.com [40.107.93.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3688354CAB for ; Thu, 8 Sep 2022 13:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mnNLNQlFLlNfuhagZyFmWTrO8WyRNZqZwoomn5vw2W/4zU/vQRMYosbdnEfxf9XMlCZIQG42Zd9aTk9vhaEC6V7L0iC6zwe46J/MIPBKbIU8tADr/j4SgdE395aQabLKDV8wBe3Coq64Rf/lj4jV3jRc3ClrBne1+J60bA8F1DpJzmVZmTh3gtKZpufV0blncxy2TaGqMZsyYK4PTbnLiXdybCJlENmUYhQ7rWyRTRTpy4AYA/izrHXhx6VxTDPSmO4PnMPcxIIXBGPriAKwXbHl6054enVpWhWPQrf+vaLCtheoYxF0W7i0OEGLvXl5ZLNaDcTHJOx5mKV4++YXsA== 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=rPJaqAD33bFzb1aTKAJo2Lp0/CM4i4GMU5+eSHRbml0=; b=RulGiHWKxI8jyb6aQXLyQbkZsjJork6XK94p0f6hmO7FuJgBFMXXUpKZpiD8/yhvf4bhjy4U3ruCEEx56gN/fVZF3RE9/BTZkIDzDn7LMAwcdj/4zRaW5i4IkLKV83AP6Sf6q7jYfe+G9SfM1jY7FiJCqxmMV4FD0Se0bX7cGYg7Yckz/1pJDPTcWnmW1wNbz8auJY4iiOkkNUmbh7t1jsM6SsweA0fj1edj84dKXXGBqBXkIxSRWjkbr+Z149CjURkOS6ABmDCmD7X1IIGbBApXN/EiO2yGNxsDMpyStIZr16DJH0qMZLFlsadZi/gTOGCrpvF14qkPsAEdqa4bow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=vger.kernel.org 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=rPJaqAD33bFzb1aTKAJo2Lp0/CM4i4GMU5+eSHRbml0=; b=QYhfyPFAJsMuNqowQcNE8XMJhhtPVfgqEVyz0iACVNjd8CDpOGT1BXGyNJuNYDrwTknv1NTDaN4DY+/LgFdv6p5oJbz3cQfmXUPZBeVO6MDqWFm59o6RBuibyLqUq+hfgjL1gzlFQxqB8pnm+mo0GnF07V+/vwwQ4OnR2gPYowlSqSbBT82FOjrAktI7szAienw67aBhjUXSQLsyxR7/0ZsAkIAvwvWjMoCkIkghJ75MS5H609CZ2MoFMagDDsHSt4fDXNgs8gdJG9dv6q4YyHIcHy2vw36NIydBfL490dZxLpP+Dufy7Y6VCLKnEdnPZMsgyAEWNBAl4NjBFM7prw== Received: from BN9PR03CA0203.namprd03.prod.outlook.com (2603:10b6:408:f9::28) by DM4PR12MB5721.namprd12.prod.outlook.com (2603:10b6:8:5c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.18; Thu, 8 Sep 2022 20:54:59 +0000 Received: from BL02EPF0000C403.namprd05.prod.outlook.com (2603:10b6:408:f9:cafe::ec) by BN9PR03CA0203.outlook.office365.com (2603:10b6:408:f9::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.19 via Frontend Transport; Thu, 8 Sep 2022 20:54:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by BL02EPF0000C403.mail.protection.outlook.com (10.167.241.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5612.10 via Frontend Transport; Thu, 8 Sep 2022 20:54:58 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Thu, 8 Sep 2022 20:54:58 +0000 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.986.29; Thu, 8 Sep 2022 13:54:57 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 8 Sep 2022 13:54:55 -0700 From: Michael Guralnik To: , CC: , , , Aharon Landau , Michael Guralnik Subject: [PATCH rdma-next 6/8] RDMA/mlx5: Change the cache structure to an RB-tree Date: Thu, 8 Sep 2022 23:54:19 +0300 Message-ID: <20220908205421.210048-7-michaelgur@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220908205421.210048-1-michaelgur@nvidia.com> References: <20220908205421.210048-1-michaelgur@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0000C403:EE_|DM4PR12MB5721:EE_ X-MS-Office365-Filtering-Correlation-Id: 41643f33-f6d5-48d6-6159-08da91dc6461 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b9+iG43m5Q/4XcWjjwoLkRXNQBzR+dFmDL1InppbLbSEvD+HPSNZ97nFqI+YI1WLcecXgdyZnA3eovsyZsFhSp2cGElEx2FvM2dVk5QG2FmK15Re4PI/Vi9e4Ic+KGxagQFdNXbzLkARVbxmHervlG2Uy+2U7aEEoZXUq8e+4hhyjQ3o/4PoMqNUjAgyfHasVgBrVy75RXKLoTw1gR/Y73Of7/sC+RqMzJNHZI2/rM3NX7H5ioDQyGJ7m/eO+5rd7ZI5pj8XpworwOOx9wC1vIuIs4N+bhx1FXYABk/f6F86X52fGSZRwjcLMCx/rt3+JIYM5PKH/aud59CJbUh8jJmdJwnhreYduHMARep94AJueHNFlmOUVDLvnfxyLg1Lbckaq9Jn8oNZ6aak28FNO548yFrGEtexk1VuSpcwXtZQO/I+MA4I89T1Fkj2QndvdsbKVyhDEANRQSikNqQECXWg9aSRiFZC+vzKwtciN39mG8vZlUicw0mNIkyFaq0i9gEBcHzLsKlEoSerfXWm7mockkRQyo+dOkfcnsEK3Sngw6Zq9JTwiU6gJ//xv6/pYmd5mRxZmQQPTIYOR4LhR4YdOeH1oRejiGrkv+nIv6qd/R0ERtgBHugQPy1ku+I1RxIa4NqrJtii6JBtCsddke1uUteFxJkhKijIfnYcrAW9dUtbb13ACTzay8LHlH54aE+CrCiGBC/ntGTNogSjPrVukJC5HAlzPSVtpA1ZZUzRjTFXOAr6H2z/sdNmwiHBhKe7/9qhQBjvU4DiVypA8k8FBuAsJdJHSbRG+tVP1ZU= X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(136003)(396003)(346002)(39860400002)(376002)(36840700001)(40470700004)(46966006)(40460700003)(41300700001)(82310400005)(107886003)(8676002)(40480700001)(83380400001)(110136005)(54906003)(7696005)(6666004)(6636002)(316002)(26005)(36756003)(478600001)(8936002)(30864003)(86362001)(5660300002)(2906002)(4326008)(81166007)(70586007)(356005)(70206006)(82740400003)(2616005)(36860700001)(336012)(47076005)(426003)(186003)(1076003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2022 20:54:58.7095 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41643f33-f6d5-48d6-6159-08da91dc6461 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0000C403.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5721 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Aharon Landau Currently, the cache structure is a static linear array. Therefore, its size is limited to the number of entries in it and is not expandable on run-time. The entries are dedicated to mkeys of size 2^x and no access_flags. Mkeys with different properties are not cacheable. In this patch, we change the cache structure to an RB-tree. By this, we enable caching all user mkeys that can use umr. Signed-off-by: Aharon Landau Reviewed-by: Michael Guralnik --- drivers/infiniband/hw/mlx5/mlx5_ib.h | 17 +- drivers/infiniband/hw/mlx5/mr.c | 293 +++++++++++++++++++-------- drivers/infiniband/hw/mlx5/odp.c | 9 +- 3 files changed, 223 insertions(+), 96 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h index 5b57b2a24b47..7fd3b47190b1 100644 --- a/drivers/infiniband/hw/mlx5/mlx5_ib.h +++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h @@ -741,10 +741,10 @@ struct mlx5_cache_ent { unsigned long stored; unsigned long reserved; + struct rb_node node; struct mlx5r_cache_rb_key rb_key; char name[4]; - u32 order; u8 disabled:1; u8 fill_to_high_water:1; @@ -775,8 +775,9 @@ struct mlx5r_async_create_mkey { struct mlx5_mkey_cache { struct workqueue_struct *wq; - struct mlx5_cache_ent ent[MAX_MKEY_CACHE_ENTRIES]; - struct dentry *root; + struct rb_root rb_root; + struct mutex rb_lock; + struct dentry *fs_root; unsigned long last_add; }; @@ -1321,6 +1322,8 @@ void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num); int mlx5_ib_get_cqe_size(struct ib_cq *ibcq); int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev); int mlx5_mkey_cache_cleanup(struct mlx5_ib_dev *dev); +struct mlx5_cache_ent *mlx5r_cache_create_ent(struct mlx5_ib_dev *dev, + struct mlx5r_cache_rb_key rb_key); struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, u8 access_mode, unsigned int access_flags, @@ -1348,7 +1351,7 @@ int mlx5r_odp_create_eq(struct mlx5_ib_dev *dev, struct mlx5_ib_pf_eq *eq); void mlx5_ib_odp_cleanup_one(struct mlx5_ib_dev *ibdev); int __init mlx5_ib_odp_init(void); void mlx5_ib_odp_cleanup(void); -void mlx5_odp_init_mkey_cache_entry(struct mlx5_cache_ent *ent); +struct mlx5_cache_ent *mlx5_odp_init_mkey_cache_entry(struct mlx5_ib_dev *dev); void mlx5_odp_populate_xlt(void *xlt, size_t idx, size_t nentries, struct mlx5_ib_mr *mr, int flags); @@ -1367,7 +1370,11 @@ static inline int mlx5r_odp_create_eq(struct mlx5_ib_dev *dev, static inline void mlx5_ib_odp_cleanup_one(struct mlx5_ib_dev *ibdev) {} static inline int mlx5_ib_odp_init(void) { return 0; } static inline void mlx5_ib_odp_cleanup(void) {} -static inline void mlx5_odp_init_mkey_cache_entry(struct mlx5_cache_ent *ent) {} +static inline struct mlx5_cache_ent * +mlx5_odp_init_mkey_cache_entry(struct mlx5_ib_dev *dev) +{ + return NULL; +} static inline void mlx5_odp_populate_xlt(void *xlt, size_t idx, size_t nentries, struct mlx5_ib_mr *mr, int flags) {} diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c index bb3d5a766cb8..6977d0cbbe6f 100644 --- a/drivers/infiniband/hw/mlx5/mr.c +++ b/drivers/infiniband/hw/mlx5/mr.c @@ -514,18 +514,22 @@ static const struct file_operations limit_fops = { static bool someone_adding(struct mlx5_mkey_cache *cache) { - unsigned int i; - - for (i = 0; i < MAX_MKEY_CACHE_ENTRIES; i++) { - struct mlx5_cache_ent *ent = &cache->ent[i]; - bool ret; + struct mlx5_cache_ent *ent; + struct rb_node *node; + bool ret; + mutex_lock(&cache->rb_lock); + for (node = rb_first(&cache->rb_root); node; node = rb_next(node)) { + ent = rb_entry(node, struct mlx5_cache_ent, node); xa_lock_irq(&ent->mkeys); ret = ent->stored < ent->limit; xa_unlock_irq(&ent->mkeys); - if (ret) + if (ret) { + mutex_unlock(&cache->rb_lock); return true; + } } + mutex_unlock(&cache->rb_lock); return false; } @@ -589,8 +593,8 @@ static void __cache_work_func(struct mlx5_cache_ent *ent) if (err != -EAGAIN) { mlx5_ib_warn( dev, - "command failed order %d, err %d\n", - ent->order, err); + "command failed order %s, err %d\n", + ent->name, err); queue_delayed_work(cache->wq, &ent->dwork, msecs_to_jiffies(1000)); } @@ -636,6 +640,72 @@ static void delayed_cache_work_func(struct work_struct *work) __cache_work_func(ent); } +static int mlx5_cache_ent_insert(struct mlx5_mkey_cache *cache, + struct mlx5_cache_ent *ent) +{ + struct rb_node **new = &cache->rb_root.rb_node, *parent = NULL; + struct mlx5_cache_ent *cur; + int cmp; + + mutex_lock(&cache->rb_lock); + /* Figure out where to put new node */ + while (*new) { + cur = rb_entry(*new, struct mlx5_cache_ent, node); + parent = *new; + cmp = memcmp(&ent->rb_key, &cur->rb_key, + sizeof(struct mlx5r_cache_rb_key)); + if (cmp < 0) + new = &((*new)->rb_left); + if (cmp > 0) + new = &((*new)->rb_right); + if (cmp == 0) { + mutex_unlock(&cache->rb_lock); + return -EEXIST; + } + } + + /* Add new node and rebalance tree. */ + rb_link_node(&ent->node, parent, new); + rb_insert_color(&ent->node, &cache->rb_root); + + mutex_unlock(&cache->rb_lock); + return 0; +} + +static struct rb_node * +mlx5_cache_find_smallest_ent(struct mlx5_mkey_cache *cache, + struct mlx5r_cache_rb_key rb_key) +{ + struct rb_node *node = cache->rb_root.rb_node; + struct mlx5_cache_ent *cur, *smallest = NULL; + int cmp; + + /* + * Find the smallest ent with ent.rb_key >= rb_key. + */ + while (node) { + cur = rb_entry(node, struct mlx5_cache_ent, node); + + cmp = memcmp(&rb_key, &cur->rb_key, + sizeof(struct mlx5r_cache_rb_key)); + if (cmp < 0) { + /* cur.rb_key > rb_key */ + smallest = cur; + node = node->rb_left; + } + if (cmp > 0) + node = node->rb_right; + if (cmp == 0) + return &cur->node; + } + + return (smallest && + smallest->rb_key.access_mode == rb_key.access_mode && + smallest->rb_key.access_flags == rb_key.access_flags) ? + &smallest->node : + NULL; +} + static bool mlx5_ent_get_mkey(struct mlx5_cache_ent *ent, struct mlx5_ib_mr *mr) { xa_lock_irq(&ent->mkeys); @@ -655,36 +725,41 @@ static bool mlx5_ent_get_mkey(struct mlx5_cache_ent *ent, struct mlx5_ib_mr *mr) return true; } -static struct mlx5_cache_ent *mkey_cache_ent_from_order(struct mlx5_ib_dev *dev, - unsigned int order) -{ - struct mlx5_mkey_cache *cache = &dev->cache; - - if (order < cache->ent[0].order) - return &cache->ent[0]; - order = order - cache->ent[0].order; - if (order > MKEY_CACHE_LAST_STD_ENTRY) - return NULL; - return &cache->ent[order]; -} - static bool mlx5_cache_get_mkey(struct mlx5_ib_dev *dev, struct mlx5r_cache_rb_key rb_key, struct mlx5_ib_mr *mr) { + struct mlx5_mkey_cache *cache = &dev->cache; + unsigned int order, upper_bound; struct mlx5_cache_ent *ent; + struct rb_node *node; - if (!mlx5r_umr_can_reconfig(dev, 0, rb_key.access_flags)) - return false; + order = order_base_2(rb_key.ndescs) > 2 ? + order_base_2(rb_key.ndescs) : 2; + upper_bound = 1 << order; + + /* + * Find the smallest node within the range with available mkeys. + */ + mutex_lock(&cache->rb_lock); + node = mlx5_cache_find_smallest_ent(cache, rb_key); + while (node) { + ent = rb_entry(node, struct mlx5_cache_ent, node); + if (ent->rb_key.access_mode != rb_key.access_mode || + ent->rb_key.access_flags != rb_key.access_flags || + ent->rb_key.ndescs > upper_bound) + break; - if (rb_key.access_mode == MLX5_MKC_ACCESS_MODE_KSM) - ent = &dev->cache.ent[MLX5_IMR_KSM_CACHE_ENTRY]; + if (mlx5_ent_get_mkey(ent, mr)) { + mutex_unlock(&cache->rb_lock); + return true; + } - ent = mkey_cache_ent_from_order(dev, order_base_2(rb_key.ndescs)); - if (!ent) - return false; + node = rb_next(node); + } + mutex_unlock(&cache->rb_lock); - return mlx5_ent_get_mkey(ent, mr); + return false; } static int get_uchangeable_access_flags(struct mlx5_ib_dev *dev, @@ -743,10 +818,8 @@ struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, u8 access_mode, return mr; } -static void clean_keys(struct mlx5_ib_dev *dev, int c) +static void clean_keys(struct mlx5_ib_dev *dev, struct mlx5_cache_ent *ent) { - struct mlx5_mkey_cache *cache = &dev->cache; - struct mlx5_cache_ent *ent = &cache->ent[c]; u32 mkey; cancel_delayed_work(&ent->dwork); @@ -765,26 +838,19 @@ static void mlx5_mkey_cache_debugfs_cleanup(struct mlx5_ib_dev *dev) if (!mlx5_debugfs_root || dev->is_rep) return; - debugfs_remove_recursive(dev->cache.root); - dev->cache.root = NULL; + debugfs_remove_recursive(dev->cache.fs_root); + dev->cache.fs_root = NULL; } -static void mlx5_mkey_cache_debugfs_init(struct mlx5_ib_dev *dev) +static void mlx5_cache_ent_debugfs_init(struct mlx5_ib_dev *dev, + struct mlx5_cache_ent *ent, int order) { struct mlx5_mkey_cache *cache = &dev->cache; - struct mlx5_cache_ent *ent; struct dentry *dir; - int i; - if (!mlx5_debugfs_root || dev->is_rep) - return; - - cache->root = debugfs_create_dir("mr_cache", mlx5_debugfs_get_dev_root(dev->mdev)); - - for (i = 0; i < MAX_MKEY_CACHE_ENTRIES; i++) { - ent = &cache->ent[i]; - sprintf(ent->name, "%d", ent->order); - dir = debugfs_create_dir(ent->name, cache->root); + if (cache->fs_root) { + sprintf(ent->name, "%d", order); + dir = debugfs_create_dir(ent->name, cache->fs_root); debugfs_create_file("size", 0600, dir, ent, &size_fops); debugfs_create_file("limit", 0600, dir, ent, &limit_fops); debugfs_create_ulong("cur", 0400, dir, &ent->stored); @@ -799,68 +865,114 @@ static void delay_time_func(struct timer_list *t) WRITE_ONCE(dev->fill_delay, 0); } -int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) +struct mlx5_cache_ent *mlx5r_cache_create_ent(struct mlx5_ib_dev *dev, + struct mlx5r_cache_rb_key rb_key) +{ + struct mlx5_cache_ent *ent; + int ret; + + ent = kzalloc(sizeof(*ent), GFP_KERNEL); + if (!ent) + return ERR_PTR(-ENOMEM); + + xa_init_flags(&ent->mkeys, XA_FLAGS_LOCK_IRQ); + ent->rb_key = rb_key; + ent->dev = dev; + + INIT_DELAYED_WORK(&ent->dwork, delayed_cache_work_func); + + ret = mlx5_cache_ent_insert(&dev->cache, ent); + if (ret) { + kfree(ent); + return ERR_PTR(ret); + } + return ent; +} + +static int mlx5_cache_init_default_entries(struct mlx5_ib_dev *dev) { struct mlx5r_cache_rb_key rb_key = { .access_mode = MLX5_MKC_ACCESS_MODE_MTT }; struct mlx5_mkey_cache *cache = &dev->cache; + bool can_use_cache, need_cache; struct mlx5_cache_ent *ent; - int i; + int order; + + if (mlx5_debugfs_root && !dev->is_rep) + cache->fs_root = debugfs_create_dir( + "mr_cache", mlx5_debugfs_get_dev_root(dev->mdev)); + + can_use_cache = !dev->is_rep && mlx5r_umr_can_load_pas(dev, 0); + need_cache = (dev->mdev->profile.mask & MLX5_PROF_MASK_MR_CACHE) && + mlx5_core_is_pf(dev->mdev); + + for (order = 2; order <= MKEY_CACHE_LAST_STD_ENTRY + 2; order++) { + rb_key.ndescs = 1 << order; + ent = mlx5r_cache_create_ent(dev, rb_key); + if (IS_ERR(ent)) + return PTR_ERR(ent); + + mlx5_cache_ent_debugfs_init(dev, ent, order); + + if (can_use_cache && need_cache && + order <= mkey_cache_max_order(dev)) { + ent->limit = + dev->mdev->profile.mr_cache[order - 2].limit; + xa_lock_irq(&ent->mkeys); + queue_adjust_cache_locked(ent); + xa_unlock_irq(&ent->mkeys); + } + } + + ent = mlx5_odp_init_mkey_cache_entry(dev); + if (ent) { + if (IS_ERR(ent)) + return PTR_ERR(ent); + + mlx5_cache_ent_debugfs_init(dev, ent, + MLX5_IMR_KSM_CACHE_ENTRY + 2); + } + + return 0; +} + +int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) +{ + int err; mutex_init(&dev->slow_path_mutex); - cache->wq = alloc_ordered_workqueue("mkey_cache", WQ_MEM_RECLAIM); - if (!cache->wq) { + mutex_init(&dev->cache.rb_lock); + dev->cache.rb_root = RB_ROOT; + dev->cache.wq = alloc_ordered_workqueue("mkey_cache", WQ_MEM_RECLAIM); + if (!dev->cache.wq) { mlx5_ib_warn(dev, "failed to create work queue\n"); return -ENOMEM; } mlx5_cmd_init_async_ctx(dev->mdev, &dev->async_ctx); timer_setup(&dev->delay_timer, delay_time_func, 0); - for (i = 0; i < MAX_MKEY_CACHE_ENTRIES; i++) { - ent = &cache->ent[i]; - xa_init_flags(&ent->mkeys, XA_FLAGS_LOCK_IRQ); - ent->order = i + 2; - ent->dev = dev; - ent->limit = 0; - - INIT_DELAYED_WORK(&ent->dwork, delayed_cache_work_func); - - if (i > MKEY_CACHE_LAST_STD_ENTRY) { - mlx5_odp_init_mkey_cache_entry(ent); - continue; - } - - if (ent->order > mkey_cache_max_order(dev)) - continue; - - rb_key.ndescs = 1 << ent->order; - ent->rb_key = rb_key; - if ((dev->mdev->profile.mask & MLX5_PROF_MASK_MR_CACHE) && - !dev->is_rep && mlx5_core_is_pf(dev->mdev) && - mlx5r_umr_can_load_pas(dev, 0)) - ent->limit = dev->mdev->profile.mr_cache[i].limit; - else - ent->limit = 0; - xa_lock_irq(&ent->mkeys); - queue_adjust_cache_locked(ent); - xa_unlock_irq(&ent->mkeys); - } - - mlx5_mkey_cache_debugfs_init(dev); + err = mlx5_cache_init_default_entries(dev); + if (err) + goto err; return 0; +err: + mlx5_mkey_cache_cleanup(dev); + return err; } int mlx5_mkey_cache_cleanup(struct mlx5_ib_dev *dev) { - unsigned int i; + struct rb_root *root = &dev->cache.rb_root; + struct mlx5_cache_ent *ent; + struct rb_node *node; if (!dev->cache.wq) return 0; - for (i = 0; i < MAX_MKEY_CACHE_ENTRIES; i++) { - struct mlx5_cache_ent *ent = &dev->cache.ent[i]; - + mutex_lock(&dev->cache.rb_lock); + for (node = rb_first(root); node; node = rb_next(node)) { + ent = rb_entry(node, struct mlx5_cache_ent, node); xa_lock_irq(&ent->mkeys); ent->disabled = true; xa_unlock_irq(&ent->mkeys); @@ -870,8 +982,15 @@ int mlx5_mkey_cache_cleanup(struct mlx5_ib_dev *dev) mlx5_mkey_cache_debugfs_cleanup(dev); mlx5_cmd_cleanup_async_ctx(&dev->async_ctx); - for (i = 0; i < MAX_MKEY_CACHE_ENTRIES; i++) - clean_keys(dev, i); + node = rb_first(root); + while (node) { + ent = rb_entry(node, struct mlx5_cache_ent, node); + node = rb_next(node); + clean_keys(dev, ent); + rb_erase(&ent->node, root); + kfree(ent); + } + mutex_unlock(&dev->cache.rb_lock); destroy_workqueue(dev->cache.wq); del_timer_sync(&dev->delay_timer); diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c index 90339edddfed..b29ec4e0d8ff 100644 --- a/drivers/infiniband/hw/mlx5/odp.c +++ b/drivers/infiniband/hw/mlx5/odp.c @@ -1587,16 +1587,17 @@ mlx5_ib_odp_destroy_eq(struct mlx5_ib_dev *dev, struct mlx5_ib_pf_eq *eq) return err; } -void mlx5_odp_init_mkey_cache_entry(struct mlx5_cache_ent *ent) +struct mlx5_cache_ent *mlx5_odp_init_mkey_cache_entry(struct mlx5_ib_dev *dev) { struct mlx5r_cache_rb_key rb_key = { .access_mode = MLX5_MKC_ACCESS_MODE_KSM, .ndescs = mlx5_imr_ksm_entries }; - if (!(ent->dev->odp_caps.general_caps & IB_ODP_SUPPORT_IMPLICIT)) - return; - ent->rb_key = rb_key; + if (!(dev->odp_caps.general_caps & IB_ODP_SUPPORT_IMPLICIT)) + return NULL; + + return mlx5r_cache_create_ent(dev, rb_key); } static const struct ib_device_ops mlx5_ib_dev_odp_ops = { From patchwork Thu Sep 8 20:54:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Guralnik X-Patchwork-Id: 12970663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 273F1C38145 for ; Thu, 8 Sep 2022 20:55:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229962AbiIHUz2 (ORCPT ); Thu, 8 Sep 2022 16:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbiIHUzR (ORCPT ); Thu, 8 Sep 2022 16:55:17 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2051.outbound.protection.outlook.com [40.107.244.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5714E5E655 for ; Thu, 8 Sep 2022 13:55:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dwtOinlDrop3Z+OQ8TjmYrsUD50fuOmDo3jvwpT5knOtDKmeIBwUzEowoQXx3URjShwfxCf3oK6PGzE1Tg2GHGbdsP5VVt2rRlDemPM+NjCl1SdJ9hrPzM8KXeygqPyRYCrnaemAmiZqXox5/O9KF8VaQwYhuGEZ764YHh6UCQ1DyejYCPg1XEr9GrjcJ9FS82d1wZuCo9x3Or9Y0MrdqxELNiBfxkGOyD/GqQVhzcuOm+wcA2JsaHWSjeYegBi6GfS01xaws0giwuPEHU5wBdvjAFVXNzA0QrkV/Pk+wruz9cvMedZn8WevBFYtBKFiHVTCKGPIUZwO9748my8YbA== 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=Xb1OaGtKE3ekaaE0pwbFZ52Odtqi8OkU4PGJdyJLmRI=; b=mylrnoot6wyVUS1F9smjGpmCbeznGK/Ve/lp5yc404FlnSU90P4kkxMW0lpMLoa5lWNnlXjM7HzbQDdu43vIEoicEeiR/q9QThon6UYNh7dFhS/ZZr+prt/dnBdqr7uS+GuNNpzAvwRTCZYBA9l81x2YGRGRgUX1QBw5rVj17PkWFGrSdFiAU6KdEs4pcy8ebf2t3N2vYku5gH+XwYX9NJFk31TU1sGYYVOJt9cFvgMpQArDwvJzxf7nS+cuTbq43LeYlI3EKs6lP+Ju0h1Q/NbxXE+o6Ln6aoZ6EfBz+MgGx1OBC/sesslnbUKejuCjUQnByMcRTTu97rvYaxtyBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=vger.kernel.org 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=Xb1OaGtKE3ekaaE0pwbFZ52Odtqi8OkU4PGJdyJLmRI=; b=dxajTsNOQoormsEGl2LfCnSdPYMIE8M0H701l79buSIOVL2LyjwuoHthLUN86bnktOpuO4SeiV1p+M88Ttunlpo0dbc9KkIiPtLa9Soft8m2yZ9FkXqzrlDogVT5CDHIwu/IylRoKi8CeR2huYCsXNLNr8qkHEgyGI1tKRI4gBG7F7oTBjNJv/9XXL9zOGNX18jwHcORcR/u4S5q9tBQGdFoiNhj8bsINoYrTejSzhBNqeWiABfS3VleoZZDFEtXoLWa8Y5nUIE5TtTg3IBhUnf0YgkU7UiZtIwPYpKIob2HsUCpYcC/RuScLyodxMkv7/mj3fzZJG80mcbsIevMkg== Received: from BN1PR13CA0009.namprd13.prod.outlook.com (2603:10b6:408:e2::14) by CH3PR12MB7548.namprd12.prod.outlook.com (2603:10b6:610:144::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.18; Thu, 8 Sep 2022 20:55:02 +0000 Received: from BN8NAM11FT024.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e2:cafe::27) by BN1PR13CA0009.outlook.office365.com (2603:10b6:408:e2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.19 via Frontend Transport; Thu, 8 Sep 2022 20:55:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) 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 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT024.mail.protection.outlook.com (10.13.177.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5612.13 via Frontend Transport; Thu, 8 Sep 2022 20:55:01 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Thu, 8 Sep 2022 20:55:00 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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.29; Thu, 8 Sep 2022 13:54:59 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 8 Sep 2022 13:54:57 -0700 From: Michael Guralnik To: , CC: , , , Aharon Landau , Michael Guralnik Subject: [PATCH rdma-next 7/8] RDMA/mlx5: Cache all user cacheable mkeys on dereg MR flow Date: Thu, 8 Sep 2022 23:54:20 +0300 Message-ID: <20220908205421.210048-8-michaelgur@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220908205421.210048-1-michaelgur@nvidia.com> References: <20220908205421.210048-1-michaelgur@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT024:EE_|CH3PR12MB7548:EE_ X-MS-Office365-Filtering-Correlation-Id: ecfc9ba8-d0f9-4b29-99f7-08da91dc662c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XcFNcizkaNFIABd4V0t4nqLz7ga9cajlcQPjFZhw90zkeBLlwGZSx5gpiO4OO9XK+PciwV2CtLT2fuZGaHs5HM1zMDieC7udRdrSVjAgmVI6TzffMYYe7iB89RhdYoBWx5aqskElQeWMylp5uTsar50QcLMbI3d4vuM95kXgApgo3IcTbDoCf+KliYvlV7VPfeGwSGnR/6Cet2ZUa7tjLgbXBxQQFXmubDmAh7u3SW56P7OCCxwDSw3joex+K6JmSvK2jaGwB+pES4NTchqARdHYTqaDcP+GOMuSfr5f3R9r59mhEOTltOQcVLt2YyNevzsV8dKPoUIIwpaqGKz8XmlgaZiF+/Ihh0jjvDmy7HH7Ey+A2un2Ze7mgzyAiJGBA2d1N12YYJ1w0Hk8lVZ5+6AutcPsq9fJZ8Jd/qJI6PdawzyNVOlFgtaUeUnXc8mwtaY9tPzL/+6qiXB+QDlGSYOXWAKsHa/m0pu+LGzEjsQ7ZA4IY/z1LKNfTLPBNdAk9Ex40E93YS8jp8A4Fi+UWKIZuJPMIhtzSzDEqRfHVm6ZDkraiQuv8TB1nVK5Nib9xcbwCL/dTYWsw4S6ampXJH0QMOVKQHaYUYzgrVFLlUxsndSCMYwtJciOpsUCbsB5++CAmADlfn1WP6iOHM+kfpP3FdCbvVTAV2YNOjj63X9CXrUFxS9wIcFI/idkw/GrKoMlRTQjPF9+zl+X1401uNObWKvJcQZTAMra4uTy12raCKWSZUAf0vVXaQfBiOHApwRQWwyJ62ieD4XxrOa2DBRTApg7q5inVdQtDHL19STheGBkKIOc6b7AXrxyZWwl X-Forefront-Antispam-Report: CIP:12.22.5.234;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(376002)(136003)(346002)(396003)(39860400002)(46966006)(40470700004)(36840700001)(6666004)(47076005)(82310400005)(426003)(36756003)(26005)(7696005)(336012)(82740400003)(1076003)(107886003)(5660300002)(186003)(83380400001)(36860700001)(2906002)(2616005)(8936002)(4326008)(70206006)(70586007)(8676002)(41300700001)(40480700001)(478600001)(40460700003)(81166007)(356005)(6636002)(110136005)(54906003)(316002)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2022 20:55:01.7347 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ecfc9ba8-d0f9-4b29-99f7-08da91dc662c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT024.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7548 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Aharon Landau Currently, when dereging an MR, if the mkey doesn't belong to a cache entry, it will be destroyed. As a result, the restart of applications with many non-cached mkeys is not efficient since all the mkeys are destroyed and then recreated. This process takes a long time (for 100,000 MRs, it is ~20 seconds for dereg and ~28 seconds for re-reg). To shorten the restart runtime, insert all cacheable mkeys to the cache. If there is no fitting entry to the mkey properties, create a temporary entry that fits it. After a predetermined timeout, the cache entries will shrink to the initial high limit. The mkeys will still be in the cache when consuming them again after an application restart. Therefore, the registration will be much faster (for 100,000 MRs, it is ~4 seconds for dereg and ~5 seconds for re-reg). The temporary cache entries created to store the non-cache mkeys are not exposed through sysfs like the default cache entries. Signed-off-by: Aharon Landau Reviewed-by: Michael Guralnik --- drivers/infiniband/hw/mlx5/mlx5_ib.h | 2 ++ drivers/infiniband/hw/mlx5/mr.c | 48 +++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h index 7fd3b47190b1..109e3d666264 100644 --- a/drivers/infiniband/hw/mlx5/mlx5_ib.h +++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h @@ -629,6 +629,8 @@ struct mlx5_ib_mkey { unsigned int ndescs; struct wait_queue_head wait; refcount_t usecount; + /* User Mkey must hold either a cache_key or a cache_ent. */ + struct mlx5r_cache_rb_key rb_key; struct mlx5_cache_ent *cache_ent; }; diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c index 6977d0cbbe6f..1e7b3c2d71a7 100644 --- a/drivers/infiniband/hw/mlx5/mr.c +++ b/drivers/infiniband/hw/mlx5/mr.c @@ -812,6 +812,7 @@ struct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev, u8 access_mode, return ERR_PTR(err); } mr->mmkey.ndescs = ndescs; + mr->mmkey.rb_key = rb_key; } mr->mmkey.type = MLX5_MKEY_MR; init_waitqueue_head(&mr->mmkey.wait); @@ -1723,6 +1724,42 @@ mlx5_free_priv_descs(struct mlx5_ib_mr *mr) } } +static int cache_ent_find_and_store(struct mlx5_ib_dev *dev, + struct mlx5_ib_mr *mr) +{ + struct mlx5_mkey_cache *cache = &dev->cache; + struct mlx5_cache_ent *ent; + struct rb_node *node; + + if (mr->mmkey.cache_ent) { + xa_lock_irq(&mr->mmkey.cache_ent->mkeys); + mr->mmkey.cache_ent->in_use--; + xa_unlock_irq(&mr->mmkey.cache_ent->mkeys); + goto end; + } + + mutex_lock(&cache->rb_lock); + node = mlx5_cache_find_smallest_ent(&dev->cache, mr->mmkey.rb_key); + mutex_unlock(&cache->rb_lock); + if (node) { + ent = rb_entry(node, struct mlx5_cache_ent, node); + if (ent->rb_key.ndescs == mr->mmkey.rb_key.ndescs) { + mr->mmkey.cache_ent = ent; + goto end; + } + } + + ent = mlx5r_cache_create_ent(dev, mr->mmkey.rb_key); + if (IS_ERR(ent)) + return PTR_ERR(ent); + + mr->mmkey.cache_ent = ent; + +end: + return push_mkey(mr->mmkey.cache_ent, false, + xa_mk_value(mr->mmkey.key)); +} + int mlx5_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata) { struct mlx5_ib_mr *mr = to_mmr(ibmr); @@ -1768,16 +1805,11 @@ int mlx5_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata) } /* Stop DMA */ - if (mr->mmkey.cache_ent) { - xa_lock_irq(&mr->mmkey.cache_ent->mkeys); - mr->mmkey.cache_ent->in_use--; - xa_unlock_irq(&mr->mmkey.cache_ent->mkeys); - + if (mr->umem && mlx5r_umr_can_load_pas(dev, mr->umem->length)) if (mlx5r_umr_revoke_mr(mr) || - push_mkey(mr->mmkey.cache_ent, false, - xa_mk_value(mr->mmkey.key))) + cache_ent_find_and_store(dev, mr)) mr->mmkey.cache_ent = NULL; - } + if (!mr->mmkey.cache_ent) { rc = destroy_mkey(to_mdev(mr->ibmr.device), mr); if (rc) From patchwork Thu Sep 8 20:54:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Guralnik X-Patchwork-Id: 12970664 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B05AC54EE9 for ; Thu, 8 Sep 2022 20:55:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229529AbiIHUzl (ORCPT ); Thu, 8 Sep 2022 16:55:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229979AbiIHUzW (ORCPT ); Thu, 8 Sep 2022 16:55:22 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2083.outbound.protection.outlook.com [40.107.101.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C897572862 for ; Thu, 8 Sep 2022 13:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MjO3NepJPdsb51w5M+rOLGOh7LBTsotR7CuCgbh2tKse0+oDUlSfrHlrLSSWzC9vnOD9jMybG24FIekV6GHOrZxzwr1vIrwg2e+Zr6DZ0VNf0dnKCq0pz1QyrdijUi+U+cHai4mtkn0oOjSsDsW42+uFgC4cS3uAToJZn52vFwcJYzVczR6naTn8GpXFI7nh736jg6EHCyaDlY0cTdzHfok9oXCCz0iNMIhDqscQ807o1UT0C7k0uUAX8nMok6+lrWt/aldoT1H8f6pfwBOSjtfD3OfbrBhadtgVMkLQUMVcxYVHPCnRAYNVey1OGTSleNkZNDD6Pu5eu56h2wquLA== 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=6KNQ1eJUQu0VzRVZ3xgODWrtzEFaGEthXTorONP/6Vs=; b=NV5B8SqxLVzKiC/7wA281Hkmo8lqPi1bA2XqcaP+CJBK3Pzvz/DaB523yWBPXtxXUeb6Ih6X6otfegmOUad6Lqv/zkCU1ViQGI4BWnJ07FqN7slLZAn0B2X94r2GnbnQ7Gww74EyxQCRn0nEb/X/LfEy5YWyXo99aB0bMLgjejYbXcvO56jt8ojZSkq1nk0eiZv9Yk1yTI0kYP4nG7IQ5CtLleU3GOTs2VNFaZptTz3aazBIn4GfNPH5mGWI9dC/h0apjk+U3Dqr6M5vz/XLSornckzrxSq14f/9h5nk+m2iQZPJtMPXadLVFKq6fXaA7+NHyX+NhObLiXXAEBAC1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=vger.kernel.org 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=6KNQ1eJUQu0VzRVZ3xgODWrtzEFaGEthXTorONP/6Vs=; b=aV7oTgY/uPEt2DmGCtPSlQru2/vMueThspAzfeDT+SI0Hu8MkMdD4Zcv9AZUBPdQ6jozZBZ+GmR++W+cuYHcLD7RdqF+3TmdUenO+KspYv6xW4iekKIK11CroNegwtT9MzYBxyUk0F/A6QvKu5jirL/BCjuSGi5HhEqDFh6TeNRIak/53LFqzh+n6PRgMu7psb8cVnIkQJTs98rqeKQ/xfHCpPQmDmxLYA+yVNljaw7doaEAHMbq8rqBVFINfVFBmXvLYSqoQHXEkrwLqUzXBkXQxVHSb4KibIPoTVFm9/53WPbhtpMVCJz7SVyCZ+2Kdwht+mo1yl2PpHD3SfGVug== Received: from MN2PR19CA0057.namprd19.prod.outlook.com (2603:10b6:208:19b::34) by CY8PR12MB7636.namprd12.prod.outlook.com (2603:10b6:930:9f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.15; Thu, 8 Sep 2022 20:55:07 +0000 Received: from BL02EPF0000C406.namprd05.prod.outlook.com (2603:10b6:208:19b:cafe::5d) by MN2PR19CA0057.outlook.office365.com (2603:10b6:208:19b::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.19 via Frontend Transport; Thu, 8 Sep 2022 20:55:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by BL02EPF0000C406.mail.protection.outlook.com (10.167.241.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5612.11 via Frontend Transport; Thu, 8 Sep 2022 20:55:06 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Thu, 8 Sep 2022 20:55:03 +0000 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.986.29; Thu, 8 Sep 2022 13:55:02 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Thu, 8 Sep 2022 13:55:00 -0700 From: Michael Guralnik To: , CC: , , , Aharon Landau , Michael Guralnik Subject: [PATCH rdma-next 8/8] RDMA/mlx5: Add work to remove temporary entries from the cache Date: Thu, 8 Sep 2022 23:54:21 +0300 Message-ID: <20220908205421.210048-9-michaelgur@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220908205421.210048-1-michaelgur@nvidia.com> References: <20220908205421.210048-1-michaelgur@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0000C406:EE_|CY8PR12MB7636:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e3d3930-380d-4f48-97cf-08da91dc693c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ywDq0h6vIC4/Db3gR8cESqVQHBwpeEYjG+c6KkrcllCq6QjYknqmA9QTQS/2GhtSnWGykwMI+svom4ZZR+3O2vJ8L9agtvmAMkfI28o1tHVDJpgzOgreD+Jg7bAJnqlh+pgN0OWMhRoWTMLsKVDzAOdqYhbf8bFVC/bl4R3+lyaHIwWzlT7hHZ/7V8w+nchmar2fM5nKJPkb23LoxUj/oNbcycjpiNpr3NIj7UxoQrwbzPki7wdhL3RdpSPBy8SW3Hpa0U8UAhj9ExYM3Ww641/jyFM1fr2Xis98z9TxL1hF6+MnQth0neMz5yITsZ5c94Hngmqaf8ZFz1Dnwi3V+vHWgARuhUYORPbZHxfB7KN02JJ8h1NVA/emn2ejCLRIMWMo3R6BQpnJ97NPvskeFqemwP/OVFWlH0JnDIQ5pKClVYnZ5xGGS7/rtlJkreplXHGs9T6ihYV2XELjatlQmzgLL6zVe6Bnt6IG0MvYwdKs/2JYWCAdBxB6tN6/xkZ+V8VLYE84QkQGkCmBk6qb5YKedwQbtjU6D1316KdsE18fBECiKln+QOhABiub+b2Akb+El3V1LlKQQZ/g7Mr6n5i6w1R3cR08SrowaRZ/TEAUp7uuCVnmkKX7Is50/sqI0l3iyxBSUjRofchbObqSqvXhuWD+lEvFhnXb3thFFOFptnamlTj9AIEOC8cV0TJrXHhsR2Znm9kBXHiE5hBjj5RtP8H/+c3gyKZd/ZlPLiMi6eONe+f02kGOdBuiUTkNEdRcwJ8MgSggzPzTJOU+WFum18MtsTApUFbqkAe1+wruoJyGkIVB9HPXd+SGW+m1 X-Forefront-Antispam-Report: CIP:12.22.5.238;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:InfoNoRecords;CAT:NONE;SFS:(13230016)(4636009)(136003)(376002)(346002)(39860400002)(396003)(46966006)(40470700004)(36840700001)(426003)(2616005)(1076003)(8936002)(40480700001)(5660300002)(186003)(7696005)(36756003)(478600001)(86362001)(47076005)(107886003)(336012)(26005)(6666004)(41300700001)(110136005)(81166007)(36860700001)(356005)(83380400001)(8676002)(82740400003)(54906003)(316002)(4326008)(70206006)(2906002)(82310400005)(40460700003)(70586007)(6636002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2022 20:55:06.8882 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e3d3930-380d-4f48-97cf-08da91dc693c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.238];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0000C406.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7636 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Aharon Landau The non-cache mkeys are stored in the cache only to shorten restarting application time. Don't store them longer than needed. Configure cache entries that store non-cache MR as temporary entries. If 30 seconds have passed and no user reclaimed the temporarily cached mkeys, an asynchronous work will destroy the mkeys and the temporary entries. When allocating an mkey from a temporary entry, don't keep a pointer to the entry, as it might be destroyed. Signed-off-by: Aharon Landau Reviewed-by: Michael Guralnik --- drivers/infiniband/hw/mlx5/mlx5_ib.h | 2 + drivers/infiniband/hw/mlx5/mr.c | 95 ++++++++++++++++++++++++---- 2 files changed, 83 insertions(+), 14 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h index 109e3d666264..c1e1e3be6e84 100644 --- a/drivers/infiniband/hw/mlx5/mlx5_ib.h +++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h @@ -748,6 +748,7 @@ struct mlx5_cache_ent { char name[4]; + u8 is_tmp:1; u8 disabled:1; u8 fill_to_high_water:1; @@ -781,6 +782,7 @@ struct mlx5_mkey_cache { struct mutex rb_lock; struct dentry *fs_root; unsigned long last_add; + struct delayed_work remove_ent_dwork; }; struct mlx5_ib_port_resources { diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c index 1e7b3c2d71a7..c5100b5dcf30 100644 --- a/drivers/infiniband/hw/mlx5/mr.c +++ b/drivers/infiniband/hw/mlx5/mr.c @@ -141,18 +141,16 @@ static void create_mkey_warn(struct mlx5_ib_dev *dev, int status, void *out) } -static int push_mkey(struct mlx5_cache_ent *ent, bool limit_pendings, - void *to_store) +static int push_mkey_locked(struct mlx5_cache_ent *ent, bool limit_pendings, + void *to_store) { XA_STATE(xas, &ent->mkeys, 0); void *curr; - xa_lock_irq(&ent->mkeys); if (limit_pendings && - (ent->reserved - ent->stored) > MAX_PENDING_REG_MR) { - xa_unlock_irq(&ent->mkeys); + (ent->reserved - ent->stored) > MAX_PENDING_REG_MR) return -EAGAIN; - } + while (1) { /* * This is cmpxchg (NULL, XA_ZERO_ENTRY) however this version @@ -191,6 +189,7 @@ static int push_mkey(struct mlx5_cache_ent *ent, bool limit_pendings, break; xa_lock_irq(&ent->mkeys); } + xa_lock_irq(&ent->mkeys); if (xas_error(&xas)) return xas_error(&xas); if (WARN_ON(curr)) @@ -198,6 +197,17 @@ static int push_mkey(struct mlx5_cache_ent *ent, bool limit_pendings, return 0; } +static int push_mkey(struct mlx5_cache_ent *ent, bool limit_pendings, + void *to_store) +{ + int ret; + + xa_lock_irq(&ent->mkeys); + ret = push_mkey_locked(ent, limit_pendings, to_store); + xa_unlock_irq(&ent->mkeys); + return ret; +} + static void undo_push_reserve_mkey(struct mlx5_cache_ent *ent) { void *old; @@ -542,7 +552,7 @@ static void queue_adjust_cache_locked(struct mlx5_cache_ent *ent) { lockdep_assert_held(&ent->mkeys.xa_lock); - if (ent->disabled || READ_ONCE(ent->dev->fill_delay)) + if (ent->disabled || READ_ONCE(ent->dev->fill_delay) || ent->is_tmp) return; if (ent->stored < ent->limit) { ent->fill_to_high_water = true; @@ -718,9 +728,18 @@ static bool mlx5_ent_get_mkey(struct mlx5_cache_ent *ent, struct mlx5_ib_mr *mr) mr->mmkey.key = pop_stored_mkey(ent); mr->mmkey.ndescs = ent->rb_key.ndescs; - mr->mmkey.cache_ent = ent; - queue_adjust_cache_locked(ent); - ent->in_use++; + if (!ent->is_tmp) { + mr->mmkey.cache_ent = ent; + queue_adjust_cache_locked(ent); + ent->in_use++; + + } else { + mr->mmkey.rb_key = ent->rb_key; + mod_delayed_work(ent->dev->cache.wq, + &ent->dev->cache.remove_ent_dwork, + msecs_to_jiffies(30 * 1000)); + } + xa_unlock_irq(&ent->mkeys); return true; } @@ -890,6 +909,38 @@ struct mlx5_cache_ent *mlx5r_cache_create_ent(struct mlx5_ib_dev *dev, return ent; } +static void remove_ent_work_func(struct work_struct *work) +{ + struct mlx5_mkey_cache *cache; + struct mlx5_cache_ent *ent; + struct rb_node *cur; + + cache = container_of(work, struct mlx5_mkey_cache, + remove_ent_dwork.work); + mutex_lock(&cache->rb_lock); + cur = rb_last(&cache->rb_root); + while (cur) { + ent = rb_entry(cur, struct mlx5_cache_ent, node); + cur = rb_prev(cur); + mutex_unlock(&cache->rb_lock); + + xa_lock_irq(&ent->mkeys); + if (!ent->is_tmp) { + xa_unlock_irq(&ent->mkeys); + mutex_lock(&cache->rb_lock); + continue; + } + ent->disabled = true; + xa_unlock_irq(&ent->mkeys); + + clean_keys(ent->dev, ent); + mutex_lock(&cache->rb_lock); + rb_erase(&ent->node, &cache->rb_root); + kfree(ent); + } + mutex_unlock(&cache->rb_lock); +} + static int mlx5_cache_init_default_entries(struct mlx5_ib_dev *dev) { struct mlx5r_cache_rb_key rb_key = { .access_mode = @@ -944,6 +995,7 @@ int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev) mutex_init(&dev->slow_path_mutex); mutex_init(&dev->cache.rb_lock); dev->cache.rb_root = RB_ROOT; + INIT_DELAYED_WORK(&dev->cache.remove_ent_dwork, remove_ent_work_func); dev->cache.wq = alloc_ordered_workqueue("mkey_cache", WQ_MEM_RECLAIM); if (!dev->cache.wq) { mlx5_ib_warn(dev, "failed to create work queue\n"); @@ -971,6 +1023,7 @@ int mlx5_mkey_cache_cleanup(struct mlx5_ib_dev *dev) if (!dev->cache.wq) return 0; + cancel_delayed_work_sync(&dev->cache.remove_ent_dwork); mutex_lock(&dev->cache.rb_lock); for (node = rb_first(root); node; node = rb_next(node)) { ent = rb_entry(node, struct mlx5_cache_ent, node); @@ -1730,34 +1783,48 @@ static int cache_ent_find_and_store(struct mlx5_ib_dev *dev, struct mlx5_mkey_cache *cache = &dev->cache; struct mlx5_cache_ent *ent; struct rb_node *node; + int ret; if (mr->mmkey.cache_ent) { xa_lock_irq(&mr->mmkey.cache_ent->mkeys); mr->mmkey.cache_ent->in_use--; - xa_unlock_irq(&mr->mmkey.cache_ent->mkeys); goto end; } mutex_lock(&cache->rb_lock); + mod_delayed_work(cache->wq, &cache->remove_ent_dwork, + msecs_to_jiffies(30 * 1000)); node = mlx5_cache_find_smallest_ent(&dev->cache, mr->mmkey.rb_key); - mutex_unlock(&cache->rb_lock); if (node) { ent = rb_entry(node, struct mlx5_cache_ent, node); if (ent->rb_key.ndescs == mr->mmkey.rb_key.ndescs) { + if (ent->disabled) { + mutex_unlock(&cache->rb_lock); + return -EOPNOTSUPP; + } + mr->mmkey.cache_ent = ent; + xa_lock_irq(&mr->mmkey.cache_ent->mkeys); + mutex_unlock(&cache->rb_lock); goto end; } } + mutex_unlock(&cache->rb_lock); ent = mlx5r_cache_create_ent(dev, mr->mmkey.rb_key); if (IS_ERR(ent)) return PTR_ERR(ent); mr->mmkey.cache_ent = ent; + xa_lock_irq(&mr->mmkey.cache_ent->mkeys); + ent->is_tmp = true; end: - return push_mkey(mr->mmkey.cache_ent, false, - xa_mk_value(mr->mmkey.key)); + ret = push_mkey_locked(mr->mmkey.cache_ent, false, + xa_mk_value(mr->mmkey.key)); + xa_unlock_irq(&mr->mmkey.cache_ent->mkeys); + return ret; + } int mlx5_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)