From patchwork Wed Sep 2 00:43:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749597 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 116BB739 for ; Wed, 2 Sep 2020 00:43:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E20A3206F0 for ; Wed, 2 Sep 2020 00:43:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="Y7cZtCMW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726521AbgIBAnt (ORCPT ); Tue, 1 Sep 2020 20:43:49 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:19887 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726064AbgIBAnq (ORCPT ); Tue, 1 Sep 2020 20:43:46 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 01 Sep 2020 17:43:00 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:46 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:43:46 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:45 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AEtQZtk+EPEhYfR4Dv5DbT7dJG+u6uLsteiG7JVPCiIEv/OTrKYFchbCdjvJMbyDDrySLaTVJnA8rwOGPe+HDE2bbXtb3rsCpme+AoYbrHceIEIYef/GDGOjqAvUEjYubDJ39fHLLlWO5twujD0RIb8iPxrffYu5LmQDGqtvVJ7IyqR0L3/6bwO8ZJ7gtwkicRunvBuDjJwV0cmPn82lg4wb0KWiLRzgd7t9CTKivc2uXnj0kFRHVR1YZzTzUYE8iV9k27Af5Gmj78amNToSz5rl7UZN89odRjIFnH6YqVyHW0ytUPjL9IZJ42FjU7WSZ8CBTyl/Ht/1rjcQD4QlNg== 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-SenderADCheck; bh=4SVsiczsrf7qHCLOm8C6KAquXodR9O0JPdkh5DFRqhs=; b=Bku4rONN81kVFISRo/0+2x52YgZ9ms5nETmMppM+5n68OmxewEUBB3JYHUvG2IcZtZ/9BFW2iCXyiyErzKyjzLOz+6U3ote+6Cp4qe+ngld6wjgVz0kBDRNCOs23PMUADPY3foamjUqxEEZ6ecyHRBMXZrGnolavpKUQQXTjsmdQz8dkzYI3OGyCkt/f81lme2XjoD3MY53INg3eKoJO1zSibFUR+cpqr1xruztg1uP9GWQsLz5SIyQY99vigV11Xl6wDSn35LOoZ5c3mKyV9qxLORWQSiBhlc9RtE8EzIFodT8xop26DSqhC/j/yyGV4DlnC+GJUu6FkdC+U8apQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:44 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:44 +0000 From: Jason Gunthorpe To: Doug Ledford , CC: Shiraz Saleem Subject: [PATCH 01/14] RDMA/umem: Fix ib_umem_find_best_pgsz() for mappings that cross a page boundary Date: Tue, 1 Sep 2020 21:43:29 -0300 Message-ID: <1-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR19CA0035.namprd19.prod.outlook.com (2603:10b6:208:178::48) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by MN2PR19CA0035.namprd19.prod.outlook.com (2603:10b6:208:178::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 2 Sep 2020 00:43:44 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsI-005P0s-SW; Tue, 01 Sep 2020 21:43:42 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f6aad2ac-8260-4078-9ce0-08d84ed93eb7 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2512; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: donNGCbHORN1QA+8KI2nuvScPeH5WtlbtZt/t1x76z/yvl0h8qTp2/QdMc0riNM9o5EnazxHflP/nfTaSulJbEm9ZDjJaMuoYnfF3GUHEcQNC5NiRAOsXBFkTd6vnoXMxin28QGKOfTbjptsbnJsnSCefvA7FnHaGYuuKqfzI05yzP5pKbCtxXP7/JbtO7TMC9jVMWqjCJwyNnYzaN3X71N09jV6dQxUqD2LQFIIVFH8VxaVND1V08svxXILUjrBbAvySwkT+crG8sFn8eqneKdN/a1TUgEJoY7FE/M3vKvzC25gXEZbPLAnvS7L7D1wwOHq+B4BZV04VRLeasv1n0m08yoc3ml9sUaJOFhsqQbVj6JjSlLLihmMeT/XfKUr X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(6666004)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(2906002)(36756003)(4326008)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 46k4HoHIODhFYCvU3mlrz+uguErA1FVQaI9lNwjwI5IjZBxXRzsqHyS5eCqMxpfS9+vxiz2Ad2JJskS7aLwHPtg72Ga7bIWr1r63uBShqO+dQxo90yyMfVpCi3jJu/3eg1h87fbTtoDXcXSbARaAXRlKOPvmWTHWY8SYhRLpFW06ATlGbWCzFavrJodrTm2RpltYAj+b31LLUhiL8mJ0lKXKZRpkYe9+cN9Z3uVjudHKZXkLVPlktRDLQlNkNCuY6DdQ8ReQN4YqL/nXV8PcBf1hoevLBeef/ORwH3/bYFGSFpSYeocXATh+jCQHuDI8o+wGwz4BF0ET22c7UJfkBhmKh7p+30qURv3uKxy1XM6aHA7WKFtanYTtTYoREGGgKr+ZoHg0fGBBkQeEUJDUJII6h02BQA6cqlm9e06fc5DHwHazpTotI3RdZlEIhw+EkoUfz855t9uXxdBIUwwoVcCofEcif7iY8hIyRGgjhWpLPHaMfPbFux/WGrDPoR2JiR1GN8JRwLyPNUW0q/VuWE4VhgSdCuT07r+snKX9Saf50a2UuYiQXiTwnC6xpLrwGHST3QDtkF2nqC2pCr6SS2uxAlyDKdzVj8Lci0u52NvEdpfIlxFTK2ogmL/Ih4WIGFzDQcyTjrKq/RwtfxtKOQ== X-MS-Exchange-CrossTenant-Network-Message-Id: f6aad2ac-8260-4078-9ce0-08d84ed93eb7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:44.3253 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EWcAbNlWwhSZFWATjOio5riWPLz7o9ndU01TDNSs/1cWrFaKiDLypY2hOyZj4KfS X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007380; bh=aajdUvGG+xx/rYkiEYkiq6w44LO6MPnf4GzKdUfmbG4=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:CC: Subject:Date:Message-ID:In-Reply-To:References: Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy: MIME-Version:X-MS-Exchange-MessageSentRepresentingType: X-Originating-IP:X-MS-PublicTrafficType: X-MS-Office365-Filtering-Correlation-Id:X-MS-TrafficTypeDiagnostic: X-Microsoft-Antispam-PRVS:X-MS-Oob-TLC-OOBClassifiers: X-MS-Exchange-SenderADCheck:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=Y7cZtCMW5sgKiOA2EQpAs3QLoBpotGBL9koQKnn3+ibB5zjYevrlRIT05jJXme0DO iO1SSsuK8zA6GQVIBfzFWCxhjssjyLQVSTJFDaKdW7GCvRLfeyRbyxrRRLK1naT4Qj PkF646evRIIbOeAgKQ/R6qBYN3CYvcviJinT9ryO3Ba5xG6DlrDA1V93aH63k6ZK6n d2VwdSIwzV/WkHZhbOAfUOM67or/C5ZJLeATi5fDHXP0XHrIHH5Z+CbsxGQ6ebtCyR NiAK82CmOVr68ROsPEy6v7d5savDY+oIlAWq4TWGUSffN4wZGS1KVaZ2S1Yg5IeC21 avlHWR7YZr/TA== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org It is possible for a single SGL to span an aligned boundary, eg if the SGL is 61440 -> 90112 Then the length is 28672, which currently limits the block size to 32k. With a 32k page size the two covering blocks will be: 32768->65536 and 65536->98304 However, the correct answer is a 128K block size which will span the whole 28672 bytes in a single block. Instead of limiting based on length figure out which high IOVA bits don't change between the start and end addresses. That is the highest useful page size. Fixes: 4a35339958f1 ("RDMA/umem: Add API to find best driver supported page size in an MR") Signed-off-by: Jason Gunthorpe Reviewed-by: Leon Romanovsky Reviewed-by: Shiraz Saleem --- drivers/infiniband/core/umem.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index 831bff8d52e547..120e98403c345d 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -156,8 +156,14 @@ unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem, return 0; va = virt; - /* max page size not to exceed MR length */ - mask = roundup_pow_of_two(umem->length); + /* The best result is the smallest page size that results in the minimum + * number of required pages. Compute the largest page size that could + * work based on VA address bits that don't change. + */ + mask = pgsz_bitmap & + GENMASK(BITS_PER_LONG - 1, + bits_per((umem->length - 1 + umem->address) ^ + umem->address)); /* offset into first SGL */ pgoff = umem->address & ~PAGE_MASK; From patchwork Wed Sep 2 00:43:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749611 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C58B739 for ; Wed, 2 Sep 2020 00:44:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0ED0C206F0 for ; Wed, 2 Sep 2020 00:44:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="YVswzPeO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726064AbgIBAn7 (ORCPT ); Tue, 1 Sep 2020 20:43:59 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:4730 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726107AbgIBAnz (ORCPT ); Tue, 1 Sep 2020 20:43:55 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 01 Sep 2020 17:43:36 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:50 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:43:50 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:47 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mgVPOlUsG2zyqgO5X1IAsHvlqR5Ab3WK5U3kIcTj2FJx08qEBtcJRvOdBkHIFh6YbhP1bDriugEjV+S62ig3elr4K1hC2042CQ1woZuv2u8Rpi46LolR4IAZ8ViuYhR//h3+6G9iJQRo8RD7+MfP8F66520zCC0ncbwqKjEbtyPfBKHicOJuuF0XytsWnUDrkf9dUfZydJbl9lFAX4EAhPEzS4SvI3h227Vzj5v4nwnWY6hFx6F4H3gMV5tBMgAwSRoaP5tx7cwuYDFsAPu+UdTzzI+Q6hHgMVzsdIM3sA8JqB1W4IeDcxlIxZzZLHbhgIisyH6QcORYpcV0wrCJAw== 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-SenderADCheck; bh=XTgkhrMQltTW0THSS3ThQVETG4k+1r5/RWd66yIhIZ8=; b=RDIlfaa8JzeSb8ye2VG5YqpvvqaqfgQNpGWIIJgZ+cucswU+gpSwOpknCSjAfFAlPa8D5mLKaKW57vhc1bXJhbNKoPdUUtb4S5/ERXlG/CNS3RhQPbErScIifTjUmEqnrRS6eELx6/zKbV1ijnl6OFsXFGKmioXtSNWIrvnLPx+WdXWXhaeXzqZ3oYqa6az+DmT68FuAlno8fdD1TC9uR6oaHQtDOVDpVgccMkU44+oNBD2vg+UzJ6F++LS3N68UuqpbwL4IlYh+zeMRvbq4glaNFk0McUN5WrGi+7uHkuu/LhMRrgKLV8iW4xaajemCfRcmJldusirsbrpbvi2ygQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:46 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:46 +0000 From: Jason Gunthorpe To: Doug Ledford , CC: Shiraz Saleem Subject: [PATCH 02/14] RDMA/umem: Prevent small pages from being returned by ib_umem_find_best_pgsz() Date: Tue, 1 Sep 2020 21:43:30 -0300 Message-ID: <2-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR22CA0028.namprd22.prod.outlook.com (2603:10b6:208:238::33) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by MN2PR22CA0028.namprd22.prod.outlook.com (2603:10b6:208:238::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15 via Frontend Transport; Wed, 2 Sep 2020 00:43:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsI-005P0w-Ta; Tue, 01 Sep 2020 21:43:42 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 05d26dc2-0e47-4d3a-4bd1-08d84ed93fa4 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:660; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RIwqHciu+NVLgbN5ntOGk48wpDXo7Jrtp152gCDiVfAwpIAThPgrIWhI2XM/sNCzmCzXTLQjY9Clo9g4pm0hxzvb/Pw4pKFldIh8VNJpr+YMU28uMv7DMGpMNa8eVTzhU9QqJT5xbiQR/XUa6E4QiHKl+EOKXiYIDeSV/4IIQp2Yk0j2bB78R/tJW4Ugn5wq3X052cz33JTTvnLgds8ouxZVSwuOEas4AnQqLfXEEsBJzUbar+cXtZLZJccVAUyehev6G82LHmTUVX010FpaC9jNfTugJWxooJRawtON+SgxdE/Mhnp48EVkPT8sxrf9f/86fIJT7ML8+Qi3K1VKbj7zuB9sBJDY63BYK8eVEK5Q+qqeSl9QzaCNUxuV0jC8 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(6666004)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(2906002)(36756003)(4326008)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: XoHYx3rgFgJigu0Js9sCxm6/3rif9EwTz9LkPSiDrFcTvvIOXo0lPZdEzUKQ6d08rtqKR0X+4qM0jDTvU0fBth8YjkUbuqSS6lGcqQjmZoojYIEfZQ4CJLTwiovjwFw2UHV28bJEhsXDcEzr/R7fEds45HUz0rtJGtH5jl9RFYRjRmKULtU/H2G3YiRj14Mpr4Q69BW4n/19x+tgpI95khqWjQ3LSGxycvYgr/EXSrG1gb7BPWidQfNuopI1fRU1pmDpVJ4jSQ9EAaawMmqbWR9kjm/FmvzVwtpcj5qgSTbEWKZnElYQl9Ox2KDuTBthYXaB14XdXVgJrF8iMzoolFEsogInimN/ngALogt/FBQHZ5RGRUgf6Re824B53JgTulCqLLEziL81H8JxrmFD3sboQtAYbRXuNxvaIM+xuVmw+pESvZAWlU+tcE3FRsNrtHKnDjrmR9UvKnj91BRBTSjJuzA91PIxmKsfqyAhGHE8kK6WqF6tUqMIxma0pyDvRYhOxfHIB4oBteNge57igc1cfY4nCxuG6LFzeOfsrggjWYun21P4KzSfxfKEofGAFmAFOVYZ8Inq2rPrvNlC0jhIMpjZyKv9owFDtFC2OcgdPe8S4qxxeUY1LOdDLkEKU2i3PwIUJo3fdeE1qflvNA== X-MS-Exchange-CrossTenant-Network-Message-Id: 05d26dc2-0e47-4d3a-4bd1-08d84ed93fa4 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:45.7695 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kRKLCnWJLalpM/4//IZs7vwHF0KF+WdRnzIpAsgOAuNmH4ifInsgXwqiekovFoU5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007416; bh=QvG1lJVILdwqSee3muynQ49ud7q7spIZ6ACPgDyYbUM=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:CC: Subject:Date:Message-ID:In-Reply-To:References: Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy: MIME-Version:X-MS-Exchange-MessageSentRepresentingType: X-Originating-IP:X-MS-PublicTrafficType: X-MS-Office365-Filtering-Correlation-Id:X-MS-TrafficTypeDiagnostic: X-Microsoft-Antispam-PRVS:X-MS-Oob-TLC-OOBClassifiers: X-MS-Exchange-SenderADCheck:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=YVswzPeOLTV3ESEc0lCTGobFESj3an/Zwjfk7HfDp5AJOIgcwUsYko+wv41+Irfqf ijLLbJqWUQZfk8PWqH49RrT9VQJnccQZYAOe+SxVMUKFnNImJLc3kRib7AtF4fCqgg TZ7Ydnfk6/tpuQpLze4GnjGwAPHiJNIjJ7MpIiTRy/phazO+B19IHAwB4GgZ3Se3+r hGBqbKktHZrfyiOBMphh8cXlh2krafC6CGw5XvyXTUn68/1mwYPjp8Vrks9n0u99Lg XMakPuqRzs5oiTewB7tqG4mUK9mFFjEsd7mcLGhTUD3HuTdpFKbqp+/BIaMWh9cyiy iB5o1wuK9DPHQ== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org rdma_for_each_block() makes assumptions about how the SGL is constructed that don't work if the block size is below the page size used to to build the SGL. The rules for umem SGL construction require that the SG's all be PAGE_SIZE aligned and we don't encode the actual byte offset of the VA range inside the SGL using offset and length. So rdma_for_each_block() has no idea where the actual starting/ending point is to compute the first/last block boundary if the starting address should be within a SGL. Fixing the SGL construction turns out to be really hard, and will be the subject of other patches. For now block smaller pages. Fixes: 4a35339958f1 ("RDMA/umem: Add API to find best driver supported page size in an MR") Signed-off-by: Jason Gunthorpe Reviewed-by: Leon Romanovsky Reviewed-by: Shiraz Saleem --- drivers/infiniband/core/umem.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index 120e98403c345d..7b5bc969e55630 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -151,6 +151,12 @@ unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem, dma_addr_t mask; int i; + /* rdma_for_each_block() has a bug if the page size is smaller than the + * page size used to build the umem. For now prevent smaller page sizes + * from being returned. + */ + pgsz_bitmap &= GENMASK(BITS_PER_LONG - 1, PAGE_SHIFT); + /* At minimum, drivers must support PAGE_SIZE or smaller */ if (WARN_ON(!(pgsz_bitmap & GENMASK(PAGE_SHIFT, 0)))) return 0; From patchwork Wed Sep 2 00:43:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749599 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C95A109B for ; Wed, 2 Sep 2020 00:43:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 140FF20707 for ; Wed, 2 Sep 2020 00:43:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="DqNwUr79" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726419AbgIBAnx (ORCPT ); Tue, 1 Sep 2020 20:43:53 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:19888 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726107AbgIBAnq (ORCPT ); Tue, 1 Sep 2020 20:43:46 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 01 Sep 2020 17:43:00 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:46 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:43:46 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:46 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z82hgzF2ztkRdhaReFxllq2WgXrleSjRXbj+qL6Ec+E8/0ofLT5/6gkZWOGzF5dVNt5Mb3nvd3cAWoefSiAaoMvK81NmQLKyFHWohCACyuseHPJAdj/wI1yvVdF5N61Bx5Qwmp3VNmzDUllV7cK9tJlXpz0itu1mbr1SOAhqPCQDrMEow8dTNHfalS81CANfsmMWvqk69JumuweQkmnF+rQwg+drUdzX+sl9urqSqCfU5hRWipXGXnxJOyVbDv9SYisG6XB8KL1WHTFxQRixGBlU1UizSxpt3DXuq9Owp8ZF8eedf7lbKuTemnynj5POCNztsGnT6Wym4gqJk3kUfQ== 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-SenderADCheck; bh=3oZx494bcUptm+8SBfS0m9Hp3++gQQQJ0HyKzifNBSU=; b=L1r1rBikzstPsR0M2nY3noYyL55U5tLJ6BSVTwfxJvvOF8jJytR7+sU7hxCtKMOAGuCDpOzkusy1LfjrT7+/HirbdY32tMw8qsScNQ1pnKmrJ+GW78GyfPPrqNUCn1e6SUmFpU6toKS2ThWBotCBahLB/ZZ3R/h4kNAE0BPBRE5mZGBXz6UWlYN5yVkDBmYFBryhXvJJEGtU6lUHJYybaDhNdttAohnkcalI5xzWXbLqn1AoYshRh842td5aTpkQ5iaA7Hxfeb0X/yGYHeshIt0lCH/NdY/thQvQBf1sijByFaqXehVUCFkRzkiusPBXLOPUh5caT/NW232UyNJQfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:45 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:44 +0000 From: Jason Gunthorpe To: Doug Ledford , Subject: [PATCH 03/14] RDMA/umem: Use simpler logic for ib_umem_find_best_pgsz() Date: Tue, 1 Sep 2020 21:43:31 -0300 Message-ID: <3-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0019.namprd18.prod.outlook.com (2603:10b6:208:23c::24) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by MN2PR18CA0019.namprd18.prod.outlook.com (2603:10b6:208:23c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 2 Sep 2020 00:43:44 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsI-005P10-Ux; Tue, 01 Sep 2020 21:43:42 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cc408ff5-d820-4f81-cf80-08d84ed93ecc X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b8HLRjuQS7JyN9Ss0Wa9eeX38SLUr6e3fMRshucLO7tzWzEmSaXrM7tyHxWyVLu1ZDvS4wcWMDDJDSSy3zR+mv7cJcTVjKgKqeajJbxgr/MxQiNubqxygelI+wu/k7VLwX24YJYQ6I/Ar3kuDBu/0dYA+E2LSHbx4ANrqBZ64wwKtIIreDiGkM8W4qdFarg8MVLfhd4gNU57I1Nt+Ev1M50iqTs29Ltfi3/PK7au1NZ3rU/t193awvDYa8wqe1CeUUlCWhUqn/CJBSy3ND3v6uQbHZDOClyw43GtsDydWoqoijIDx2Nx8QrN9dGc2tFwqhFTJcVwi8gsbDXnvprVgvS8lPp+PkYzxl1qljpiOfwMhM0OB/GaARFErzzpst4C X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(6666004)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(2906002)(36756003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: gkx3OH+4j0wDopxTc6k8AfqB4ziWKenaHBPfn7WGviT3fOvl1Ie1olT1cshptcUkitAPLPKl07Q2FU1Skj9Ha+25Cw+ELewLy7PF4LFfMQr7OlFFQ+IkC8eMKG0877fsFno4ZlYWQuBqV19rAiJHwTgNw0hnPE2ciUDpz845sl797ASc3TrlQpOkx5a9Lgy25aOH0FZarZB/5d4Me6QIGKew6DiHHaBouvbNbm8v167qlIcuNfyUlsxR/w/g+oUgaZR8vxY5dJhaFdZvNJwENS8gX0ekJxVoo5Qyum+K4Pmaup2sV3vKMIXnojLr6Wk4AZPYSx09WqlQSO2rQ57r6OhCx2EolHGH4kD0as9ZryEe0Sg6ONKIWdi99z1rDXXJ06LF8/VTWk79rFar82/52F5kYk1CkMti+4nqIWl/mq63FxkkkKgNp2vHtuTJdL4qmJHnktYn12jEmBzmfD7bXHiwdd7JdGNdV9zoGfPnY0C/vXmtuMe0szLOR+FHr3mArfwsXJT8d1l4ZCiAwD9dkQ8e5QipLRW1ScrkamKjErDu0SI9euKPuAId9JbaRxnxekL90iP7spPmBfSZHv4PvZOsYcgm1Hvlc3YxoKWDBmgNiawRduUjw1ZlbRGi1Y3jPeURK2xHcsExdsHLub5HNw== X-MS-Exchange-CrossTenant-Network-Message-Id: cc408ff5-d820-4f81-cf80-08d84ed93ecc X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:44.3703 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DgCb2KFefiIWs4kd+jbqBLx8T1/NDs/boxk7lQChKYwbq39j6dwcyV8s1YHdLlgz X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007380; bh=81iPYS51s8fO36/zSQrQCIuLrSqY+nAkovNZ78JaQJc=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:Subject: Date:Message-ID:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType:X-Originating-IP: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id: X-MS-TrafficTypeDiagnostic:X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers:X-MS-Exchange-SenderADCheck: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report:X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=DqNwUr79jP2AWAEWrEn0Y5XMVHlEoMR5zIfSzB81+47RqnW2VHCt/YEOeAgq1nQL2 v3nu60dVRqrG8ZgZkkGgA8iZXb30ZZrE+aNWPvJKBmzFdkuCwrn4accmm/iXEsUzUm +BUd/hSpzrn97IGVQFNrLJRPIcvqwu/1nlJgDAfL/DZEyJqk6HIePBKzjIPvVZBxe1 OuuSEDflFlRsssA6iEp94/RzefdEufx9HKFVCX3367kzVKuvYe42fFL6G7a9+BetyJ UMLhKRXoTJFwdSlQ/FjE10gfwWJXiWpb2uzNx8GOxTZGuMXuOCpKSS2kGfHN5d11jh RCp+Baol3OtuQ== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The calculation in rdma_find_pg_bit() is fairly complicated, and the function is never called anywhere else. Inline a simpler version into ib_umem_find_best_pgsz() Signed-off-by: Jason Gunthorpe --- drivers/infiniband/core/umem.c | 11 ++++++++--- include/rdma/ib_verbs.h | 24 ------------------------ 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index 7b5bc969e55630..f02e34cac59581 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include "uverbs.h" @@ -146,7 +147,6 @@ unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem, unsigned long virt) { struct scatterlist *sg; - unsigned int best_pg_bit; unsigned long va, pgoff; dma_addr_t mask; int i; @@ -187,9 +187,14 @@ unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem, mask |= va; pgoff = 0; } - best_pg_bit = rdma_find_pg_bit(mask, pgsz_bitmap); - return BIT_ULL(best_pg_bit); + /* The mask accumulates 1's in each position where the VA and physical + * address differ, thus the length of trailing 0 is the largest page + * size that can pass the VA through to the physical. + */ + if (mask) + pgsz_bitmap &= GENMASK(count_trailing_zeros(mask), 0); + return rounddown_pow_of_two(pgsz_bitmap); } EXPORT_SYMBOL(ib_umem_find_best_pgsz); diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index c868609a4ffaed..5dcbbb77cadb4f 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -3340,30 +3340,6 @@ static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num) return rdma_protocol_iwarp(dev, port_num); } -/** - * rdma_find_pg_bit - Find page bit given address and HW supported page sizes - * - * @addr: address - * @pgsz_bitmap: bitmap of HW supported page sizes - */ -static inline unsigned int rdma_find_pg_bit(unsigned long addr, - unsigned long pgsz_bitmap) -{ - unsigned long align; - unsigned long pgsz; - - align = addr & -addr; - - /* Find page bit such that addr is aligned to the highest supported - * HW page size - */ - pgsz = pgsz_bitmap & ~(-align << 1); - if (!pgsz) - return __ffs(pgsz_bitmap); - - return __fls(pgsz); -} - /** * rdma_core_cap_opa_port - Return whether the RDMA Port is OPA or not. * @device: Device From patchwork Wed Sep 2 00:43:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749615 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4795739 for ; Wed, 2 Sep 2020 00:44:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C76C020707 for ; Wed, 2 Sep 2020 00:44:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="X6QzbQvU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726400AbgIBAoH (ORCPT ); Tue, 1 Sep 2020 20:44:07 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:4744 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726794AbgIBAoA (ORCPT ); Tue, 1 Sep 2020 20:44:00 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 01 Sep 2020 17:43:44 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:58 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 01 Sep 2020 17:43:58 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:46 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R55j42qEoaLL6717sxaAK41J39cosUAIiG34VyBHPJvwLPchUWmf5WfEIyzKNc4rPNEvDGAyK5RC4kIMYrpzp76KosertfmYYccwItpewt4W9bCMEq2VqNCZfCJkL5f/84kqTLyJWZBJy6L22e429RgVQUP3cV/iJY/6+0EQmLMpWLswZa20e0hIE0SRpayq0OG2qcoq8G5sHP4oDI5DHVlVaNqTkiM+sZ5WhcLh2Oa0g7w+pgAxwdUn9eD9041KmnkzIyDKm90qVBGcKE0TGUwTVYg/e/KPDF6yhqk1N6Toh9ivMNaZd0SxsHUjGF1ISzwb1uPW/SW+rFjSaz2weg== 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-SenderADCheck; bh=ugEiHByo2YYyO5mKFfIDBSjXEXoPtQ7E+bIuhnvhThE=; b=YoHR3NOmge6ghYePRK7KEY2So4mv0Y3+p9wAgKlkRpGmi8+VFYyplcKRCfTSpxLuvmrUPJ+34111rz9rSRbrQir9s/kyd4TJWDhlYOasoJ81R4/9JSMjMUMNIUQeTEXgheGpnfvZyUKIRpE9KrBXCCfhgRJjh1npHql3fqBuiQxuUuo91NGDMh1SZDEJ6hPt6532TFCrFKiywd42k3aDE3UHcKfUiyEdJ9zv+Y9qgjZ5KMYmunS3L1NalweNahuft0xyNYdcMOTwXfNbnopZgj/d4QKm6jC9MoICqQqLhwyYqJjdETuq9IkYiXS7xQrH7385BuKiWx4/pf9P9ZrSrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: broadcom.com; dkim=none (message not signed) header.d=none;broadcom.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:45 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:45 +0000 From: Jason Gunthorpe To: Devesh Sharma , Doug Ledford , Faisal Latif , Gal Pressman , "Wei Hu(Xavier)" , , Weihang Li , Miguel Ojeda , Naresh Kumar PBS , Lijun Ou , Selvin Xavier , Shiraz Saleem , "Yossi Leybovich" , Somnath Kotur , Sriharsha Basavapatna Subject: [PATCH 04/14] RDMA/umem: Add rdma_umem_for_each_dma_block() Date: Tue, 1 Sep 2020 21:43:32 -0300 Message-ID: <4-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0030.namprd18.prod.outlook.com (2603:10b6:208:23c::35) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by MN2PR18CA0030.namprd18.prod.outlook.com (2603:10b6:208:23c::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 2 Sep 2020 00:43:44 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsI-005P15-W8; Tue, 01 Sep 2020 21:43:43 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 60186838-11a6-4ede-dbba-08d84ed93ed8 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1060; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZKSibm56RPgdV9mxFBt2oK8S0YXbMDkofKc0WgwymR2OipFJaYsCDTAPln+VNt95bEl+D7b0mByahF840DyzGQdlsGNZWWrVRYNNk8dewyeAWyB+Oe0cBPKD69xqQrOnskB1OF+mOyHnQFaInRkUAbTAER2gCKX4FTPJrXZvZGcoVxOLfa6evRGTmAkb3ktdRx7i69yi0q3VuDRybTvDVFW+2sgSPwL083jRiGjuXLE0+I1AP3A1G1K+V+QoIkboT4XSjVVtUHC3hQdsfH8Mpe15Ca9VHriRpxTyiaF3KOd08f0rKHrFgOQtJGO/0S8J+cfFUuwmpDtYmMSTBVicFdfU9gDFHGUnwTen8tQtrpmgINrUuU7355Yg2xtbvKI3 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(6666004)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(110136005)(2906002)(36756003)(5660300002)(7416002)(4216001)(921003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: DeY0ajBNUSqf4hnR2lSOjZLewZSa5lthyKZUWeXfhoL80om8ya9u7jgBu1liKD7hr9Muu0H16xmB3kcqX+EaSgklGDFiaQvJ6136Ggq65v8NJiDe7KeAjK990CiXSuoxZ1km88y4DXF7ij+Jg449q13zbNTAd88qw5/jja10xdR8AjSIpC/ic1USYcekF+N2HhSUNOkMNrHzbspPjQkAANeA4e/AJQNIzN01PTxQYkw0B45d0pvuzP9PtxEFoBKjI3mhVH1M7mdBUiL/DjfY9jl99fjJ+xTbqgM6hUSb9KUt19j2jS8iOYRCwY+Iy2l4lSZpoGY362IjdwNqBGKi+SZcEtmDq+ZFzK64lh49ZEbZ7IRNPisXIZyx9Hi5nwb1Lr4UhgkC1c7ZHgK+VUNgxXCBRUwBB/MWLPuMRQl53M5I722J9Qb5xq9JT6dVhk0cElfMqLVrHxXEbLhmn8AOW20qwPHbiNjkMN9QDk66KOTRyjO7ZLbjkjfUBPATa3tYrqhhoQK0TP17rl83uFErjvmiPxliK05XAWBNvVYrDxf2Ey3WSVZuN+4LmNqt5xd8qCjXi3MRgNBzYA/GYDuMkR8UybDf/956LBbUvQ1bfTsoBSqUleULpf7G6DYvi5wlb3PwPTC/G6Gh+DnsRs+iGw== X-MS-Exchange-CrossTenant-Network-Message-Id: 60186838-11a6-4ede-dbba-08d84ed93ed8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:44.5692 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pHLcvNCV8KGjI6btDkWbH8fWQ6f32HFxdmhMkzctq8559orxJyKvOhr4LuAvuFQo X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007424; bh=5ygfN42oEPydMocRVNOqhxPwuxzxUrHo5qejxS12HEg=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:Subject: Date:Message-ID:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType:X-Originating-IP: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id: X-MS-TrafficTypeDiagnostic:X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers:X-MS-Exchange-SenderADCheck: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report:X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=X6QzbQvUtten/lh+/K5ElUQM+0gOYRCzTxHmIWmAD07DUKM4wwfCraJifLQAxeIhY 8Z5Ibf1bVzm2p4HWfrDypZh6tD1bdYiLIaZrUrz+iCMOB5q0p4g2p+tMB1bboe3hZz bbQEDbNKKlEMrOgd2YbACt19rUcW8mT+F5w+9EHSJSg0CvDQIZ5z7eUpDhby1JWAeT nmDCkd6XRPnJ5fB1v+JMevEt42VFmpNkRRm5M0qaoJzndKm4AbBLo+eCBNBArc3CFK shks94r/qXvUfcEhBKIea7Ailu3mwpjK9tBI5mKvWd1+pooqdpSBOrvJZg8OxylBj1 5QCQ3Mj7e7iuA== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org This helper does the same as rdma_for_each_block(), except it works on a umem. This simplifies most of the call sites. Signed-off-by: Jason Gunthorpe Acked-by: Miguel Ojeda Acked-by: Shiraz Saleem --- .clang-format | 1 + drivers/infiniband/hw/bnxt_re/ib_verbs.c | 2 +- drivers/infiniband/hw/efa/efa_verbs.c | 3 +-- drivers/infiniband/hw/hns/hns_roce_alloc.c | 3 +-- drivers/infiniband/hw/i40iw/i40iw_verbs.c | 3 +-- include/rdma/ib_umem.h | 20 ++++++++++++++++++++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.clang-format b/.clang-format index a0a96088c74f49..311ef2c61a1bdf 100644 --- a/.clang-format +++ b/.clang-format @@ -415,6 +415,7 @@ ForEachMacros: - 'rbtree_postorder_for_each_entry_safe' - 'rdma_for_each_block' - 'rdma_for_each_port' + - 'rdma_umem_for_each_dma_block' - 'resource_list_for_each_entry' - 'resource_list_for_each_entry_safe' - 'rhl_for_each_entry_rcu' diff --git a/drivers/infiniband/hw/bnxt_re/ib_verbs.c b/drivers/infiniband/hw/bnxt_re/ib_verbs.c index 5ee272d27aaade..9e26e651730cb3 100644 --- a/drivers/infiniband/hw/bnxt_re/ib_verbs.c +++ b/drivers/infiniband/hw/bnxt_re/ib_verbs.c @@ -3783,7 +3783,7 @@ static int fill_umem_pbl_tbl(struct ib_umem *umem, u64 *pbl_tbl_orig, u64 page_size = BIT_ULL(page_shift); struct ib_block_iter biter; - rdma_for_each_block(umem->sg_head.sgl, &biter, umem->nmap, page_size) + rdma_umem_for_each_dma_block(umem, &biter, page_size) *pbl_tbl++ = rdma_block_iter_dma_address(&biter); return pbl_tbl - pbl_tbl_orig; diff --git a/drivers/infiniband/hw/efa/efa_verbs.c b/drivers/infiniband/hw/efa/efa_verbs.c index de9a22f0fcc218..d85c63a5021a70 100644 --- a/drivers/infiniband/hw/efa/efa_verbs.c +++ b/drivers/infiniband/hw/efa/efa_verbs.c @@ -1142,8 +1142,7 @@ static int umem_to_page_list(struct efa_dev *dev, ibdev_dbg(&dev->ibdev, "hp_cnt[%u], pages_in_hp[%u]\n", hp_cnt, pages_in_hp); - rdma_for_each_block(umem->sg_head.sgl, &biter, umem->nmap, - BIT(hp_shift)) + rdma_umem_for_each_dma_block(umem, &biter, BIT(hp_shift)) page_list[hp_idx++] = rdma_block_iter_dma_address(&biter); return 0; diff --git a/drivers/infiniband/hw/hns/hns_roce_alloc.c b/drivers/infiniband/hw/hns/hns_roce_alloc.c index a522cb2d29eabc..a6b23dec1adcf6 100644 --- a/drivers/infiniband/hw/hns/hns_roce_alloc.c +++ b/drivers/infiniband/hw/hns/hns_roce_alloc.c @@ -268,8 +268,7 @@ int hns_roce_get_umem_bufs(struct hns_roce_dev *hr_dev, dma_addr_t *bufs, } /* convert system page cnt to hw page cnt */ - rdma_for_each_block(umem->sg_head.sgl, &biter, umem->nmap, - 1 << page_shift) { + rdma_umem_for_each_dma_block(umem, &biter, 1 << page_shift) { addr = rdma_block_iter_dma_address(&biter); if (idx >= start) { bufs[total++] = addr; diff --git a/drivers/infiniband/hw/i40iw/i40iw_verbs.c b/drivers/infiniband/hw/i40iw/i40iw_verbs.c index b51339328a51ef..beb611b157bc8d 100644 --- a/drivers/infiniband/hw/i40iw/i40iw_verbs.c +++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c @@ -1320,8 +1320,7 @@ static void i40iw_copy_user_pgaddrs(struct i40iw_mr *iwmr, if (iwmr->type == IW_MEMREG_TYPE_QP) iwpbl->qp_mr.sq_page = sg_page(region->sg_head.sgl); - rdma_for_each_block(region->sg_head.sgl, &biter, region->nmap, - iwmr->page_size) { + rdma_umem_for_each_dma_block(region, &biter, iwmr->page_size) { *pbl = rdma_block_iter_dma_address(&biter); pbl = i40iw_next_pbl_addr(pbl, &pinfo, &idx); } diff --git a/include/rdma/ib_umem.h b/include/rdma/ib_umem.h index 07a764eb692eed..b880512ba95f16 100644 --- a/include/rdma/ib_umem.h +++ b/include/rdma/ib_umem.h @@ -40,6 +40,26 @@ static inline size_t ib_umem_num_pages(struct ib_umem *umem) PAGE_SHIFT; } +static inline void __rdma_umem_block_iter_start(struct ib_block_iter *biter, + struct ib_umem *umem, + unsigned long pgsz) +{ + __rdma_block_iter_start(biter, umem->sg_head.sgl, umem->nmap, pgsz); +} + +/** + * rdma_umem_for_each_dma_block - iterate over contiguous DMA blocks of the umem + * @umem: umem to iterate over + * @pgsz: Page size to split the list into + * + * pgsz must be <= PAGE_SIZE or computed by ib_umem_find_best_pgsz(). The + * returned DMA blocks will be aligned to pgsz and span the range: + * ALIGN_DOWN(umem->address, pgsz) to ALIGN(umem->address + umem->length, pgsz) + */ +#define rdma_umem_for_each_dma_block(umem, biter, pgsz) \ + for (__rdma_umem_block_iter_start(biter, umem, pgsz); \ + __rdma_block_iter_next(biter);) + #ifdef CONFIG_INFINIBAND_USER_MEM struct ib_umem *ib_umem_get(struct ib_device *device, unsigned long addr, From patchwork Wed Sep 2 00:43:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749619 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E5FA6109B for ; Wed, 2 Sep 2020 00:44:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7B5520707 for ; Wed, 2 Sep 2020 00:44:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="CYLAG87g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726794AbgIBAoN (ORCPT ); Tue, 1 Sep 2020 20:44:13 -0400 Received: from nat-hk.nvidia.com ([203.18.50.4]:51207 "EHLO nat-hk.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbgIBAoH (ORCPT ); Tue, 1 Sep 2020 20:44:07 -0400 Received: from hkpgpgate101.nvidia.com (Not Verified[10.18.92.100]) by nat-hk.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 02 Sep 2020 08:43:59 +0800 Received: from HKMAIL104.nvidia.com ([10.18.16.13]) by hkpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:59 -0700 X-PGP-Universal: processed; by hkpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:43:59 -0700 Received: from HKMAIL101.nvidia.com (10.18.16.10) by HKMAIL104.nvidia.com (10.18.16.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:57 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.176) by HKMAIL101.nvidia.com (10.18.16.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fnjWO3WNRdWXzc/omjoRtBGuV6skaKa1MTrsX8OrDj3+cr6eIyaTjXfDDzmgQMsZ+zYzMBWiyAKBT008VQszL+6s1Bs0ru9VzSmzolBKOalydlJ160/HVu+w97SjuFwRjZbooZLigcaxf066peQdSzC5+b9pSLrLMNC+wliXBpU5LIFXisiSmkvfRX9CuhhH5Sf70haauCk37rNon+88Ps23XX81U2nfQ09iLLhq1JIUufsWO3m116J8OCFpVtcc9nC04bVXqv7asvSeKvTPjkUqYwdnN/iAlhNxuBeyDttYXf3Suui3y3eNf7Qf5nsvAxxKvx6JexwZ8zuiOEGrVg== 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-SenderADCheck; bh=xW0VYGSVThf84oKF/6nm80GT9yWZZ06eVYiLNvsdpfI=; b=l1nch8Rf7Qu0g1BGMnRPAh6qVZUSWyjif5XXxOKgMCmbyHYaFPScfUrEw1z+npVkpZPzWdXPidpHWugpGMSWPJFbDGVCJ9/eZarCJ5GKxxLqO8KXA5PMS/l2c3oguyX4R7Qb7X9lSfpYFqeZ16RLmhtGZHnAwPO8IzO2M2TMQYIEkD7npknw/zPTVI21Xgy69D8+U3XbSB9+P1Jpsg1okLs9HDrPP3BxY2W+yDSV1iiLn3MKk9lbUOyEUHDb9p30HF95DAtlBmnIeArtttO5hUSC9085vFDUdD3mT3qs0RAsw4mbdJIG3B5YLuehGJIKrEa2eGYVAo7jd7U+BtUauw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: vmware.com; dkim=none (message not signed) header.d=none;vmware.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:55 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:55 +0000 From: Jason Gunthorpe To: Adit Ranadive , Potnuri Bharat Teja , Devesh Sharma , "Doug Ledford" , , "VMware PV-Drivers" , Selvin Xavier Subject: [PATCH 05/14] RDMA/umem: Replace for_each_sg_dma_page with rdma_umem_for_each_dma_block Date: Tue, 1 Sep 2020 21:43:33 -0300 Message-ID: <5-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0006.namprd15.prod.outlook.com (2603:10b6:207:17::19) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by BL0PR1501CA0006.namprd15.prod.outlook.com (2603:10b6:207:17::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15 via Frontend Transport; Wed, 2 Sep 2020 00:43:54 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsJ-005P18-1R; Tue, 01 Sep 2020 21:43:43 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e49a49a7-8990-427e-f8ca-08d84ed94534 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lJ/12yiNX5vR+lg2WuuWnu0CZJHPnrbz4bwdQoX+ZzVxflipY+IpxLbVbYkY2yXbW380icD4muxGZCTCx0OLtf8oGlUEw9EFlBTGCcaKftXsNSlvZnpGN1oqlwqb+ajjomYZuoDqJ+u2oMJ3L3LwCB+6WDD6z95aGJogRkyHvZpm0Dnh0n3r2ynX2c5WsgkbSjNfpD9GHSl1hQbSXZleBWd70TnIIpUzkWgiILFYzzUk9oMH5eZ0gRqsY3Qebc1geP0QJ51uELq0EkYuB49G7Nt96QGFbUne08W99zRmyFYM9eH7NGu4nsn6uQxfr5GB1zKOlpK9gcVqmRKwXDtbU6uEeomcC4z2WaAMxwAzR/fYEdprw/mFIDq6ymP4hlQP X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(6666004)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(110136005)(2906002)(36756003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: DsyfWl6hQqABhlsLIT4nHyl6J9FDrEWNpjyvl02sOuasEK1zJC9Cg/ndk1ll8iEWDfb6PiNPfb6NA7n1CVGR4H9eY8kST9DJ8puZshdIIlYrBj27rN/f7M2ZVSPeLI5zqDR1eZSYzHUotNyQVNXH10zE/osdiiJgNA/jU4Mkz+ujonVSdVjF6l1ndXN3PE/HMG1ArxyAV+8+hKnoYm3xDmCIxqyPmpVdVA0r5xiZt1P97ndXfqY1bdZ2fwIALDw9PRSzIRR6Oeja6tGSL/rbXYYooYvjk2Z8Bn5FvUrm7FBisM07YrKSlPYKqdkFtJhuCDGCDKiomU6xpLpU22YaJ31lCWB3mW4pwnB4xKGEIxhX/eff1rCcLKROMVnXDIDQ/mB9/WCuMgKe+HiqEpeObUIrPqf/sdqW5aQqU0L1rgOftsP2Yp5lo6S3ANMcMsoSCyI7u3sgzRdB91L1+LX3pmPgL/og/fda+LPDSKj36wCPaabpI/Nu6B/8nXN8tI1iTUScUftP/TU024IsnDeG1Dx9TA5gQQccY+mxrAF1/wB9DHJ8HYCh6miyHVWxp3i/34T/5B+M1+CUS5JJJ/VWWNeCngoiVKXS7yhXt9SZyrTzud0kh2bRezYtz/HjJ1NefPpNRxzZe0/9q8gkfWKovg== X-MS-Exchange-CrossTenant-Network-Message-Id: e49a49a7-8990-427e-f8ca-08d84ed94534 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:55.0693 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6VmCb4IXn6OKCIj9z5wW28+6TKJaXOWPmRjWrbssT/GxGuFR71BHzSpSqiSIkUJY X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007439; bh=bmUtxrzFMiAf2jFyxtS+c0Tdfq8lu2dqe86kmaH/5Pg=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:Subject: Date:Message-ID:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType:X-Originating-IP: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id: X-MS-TrafficTypeDiagnostic:X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers:X-MS-Exchange-SenderADCheck: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report:X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=CYLAG87gFkHDbBNvxDk+vd0Dl6Pjg2D/AbyKHd54g3KvxhfupvIFjGb6y7cl5Nfoe H4eiLqb7yZFMw/NJnCzuTSPdwIrP8dlBXkzKAyu+r5e+M7XnGjDx9qTxb9/jgVX17y KilELsVzmLIcIRoopYVG/tYXmgZQW6lqfH7+At+h7w4DwKsk63Rkf4rS6VK3GNojZC b6cfK3n/3LKDtdriLk9KoITFkGNJOOmonxDJikcwintcsCeYquuiUZCFu6+bAKrMR9 F9HKjB3+gRW1JdoVJPUOa9Dvnh7ybGozab8sTmekkmm4nEoz8ven/Q8ByFCTeqULHp 5AJGvP2/CmnsA== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Generally drivers should be using this core helper to split up the umem into DMA pages. These drivers are all probably wrong in some way to pass PAGE_SIZE in as the HW page size. Either the driver doesn't support other page sizes and it should use 4096, or the driver does support other page sizes and should use ib_umem_find_best_pgsz() to select the best HW pages size of the HW supported set. The only case it could be correct is if the HW has a global setting for PAGE_SIZE set at driver initialization time. Signed-off-by: Jason Gunthorpe --- drivers/infiniband/hw/cxgb4/mem.c | 6 +++--- drivers/infiniband/hw/mthca/mthca_provider.c | 6 +++--- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 7 +++---- drivers/infiniband/hw/vmw_pvrdma/pvrdma_misc.c | 9 ++++----- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c index 73936c3341b77c..82afdb1987eff6 100644 --- a/drivers/infiniband/hw/cxgb4/mem.c +++ b/drivers/infiniband/hw/cxgb4/mem.c @@ -510,7 +510,7 @@ struct ib_mr *c4iw_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, __be64 *pages; int shift, n, i; int err = -ENOMEM; - struct sg_dma_page_iter sg_iter; + struct ib_block_iter biter; struct c4iw_dev *rhp; struct c4iw_pd *php; struct c4iw_mr *mhp; @@ -561,8 +561,8 @@ struct ib_mr *c4iw_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, i = n = 0; - for_each_sg_dma_page(mhp->umem->sg_head.sgl, &sg_iter, mhp->umem->nmap, 0) { - pages[i++] = cpu_to_be64(sg_page_iter_dma_address(&sg_iter)); + rdma_umem_for_each_dma_block(mhp->umem, &biter, 1 << shift) { + pages[i++] = cpu_to_be64(rdma_block_iter_dma_address(&biter)); if (i == PAGE_SIZE / sizeof(*pages)) { err = write_pbl(&mhp->rhp->rdev, pages, mhp->attr.pbl_addr + (n << 3), i, diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c index 9fa2f9164a47b6..317e67ad915fe8 100644 --- a/drivers/infiniband/hw/mthca/mthca_provider.c +++ b/drivers/infiniband/hw/mthca/mthca_provider.c @@ -846,7 +846,7 @@ static struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, u64 virt, int acc, struct ib_udata *udata) { struct mthca_dev *dev = to_mdev(pd->device); - struct sg_dma_page_iter sg_iter; + struct ib_block_iter biter; struct mthca_ucontext *context = rdma_udata_to_drv_context( udata, struct mthca_ucontext, ibucontext); struct mthca_mr *mr; @@ -895,8 +895,8 @@ static struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, write_mtt_size = min(mthca_write_mtt_size(dev), (int) (PAGE_SIZE / sizeof *pages)); - for_each_sg_dma_page(mr->umem->sg_head.sgl, &sg_iter, mr->umem->nmap, 0) { - pages[i++] = sg_page_iter_dma_address(&sg_iter); + rdma_umem_for_each_dma_block(mr->umem, &biter, PAGE_SIZE) { + pages[i++] = rdma_block_iter_dma_address(&biter); /* * Be friendly to write_mtt and pass it chunks diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c index c1751c9a0f625c..933b297de2ba86 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c @@ -814,9 +814,8 @@ static void build_user_pbes(struct ocrdma_dev *dev, struct ocrdma_mr *mr, u32 num_pbes) { struct ocrdma_pbe *pbe; - struct sg_dma_page_iter sg_iter; + struct ib_block_iter biter; struct ocrdma_pbl *pbl_tbl = mr->hwmr.pbl_table; - struct ib_umem *umem = mr->umem; int pbe_cnt, total_num_pbes = 0; u64 pg_addr; @@ -826,9 +825,9 @@ static void build_user_pbes(struct ocrdma_dev *dev, struct ocrdma_mr *mr, pbe = (struct ocrdma_pbe *)pbl_tbl->va; pbe_cnt = 0; - for_each_sg_dma_page (umem->sg_head.sgl, &sg_iter, umem->nmap, 0) { + rdma_umem_for_each_dma_block (mr->umem, &biter, PAGE_SIZE) { /* store the page address in pbe */ - pg_addr = sg_page_iter_dma_address(&sg_iter); + pg_addr = rdma_block_iter_dma_address(&biter); pbe->pa_lo = cpu_to_le32(pg_addr); pbe->pa_hi = cpu_to_le32(upper_32_bits(pg_addr)); pbe_cnt += 1; diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_misc.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_misc.c index 7944c58ded0e59..ba43ad07898c2b 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_misc.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_misc.c @@ -182,17 +182,16 @@ int pvrdma_page_dir_insert_dma(struct pvrdma_page_dir *pdir, u64 idx, int pvrdma_page_dir_insert_umem(struct pvrdma_page_dir *pdir, struct ib_umem *umem, u64 offset) { + struct ib_block_iter biter; u64 i = offset; int ret = 0; - struct sg_dma_page_iter sg_iter; if (offset >= pdir->npages) return -EINVAL; - for_each_sg_dma_page(umem->sg_head.sgl, &sg_iter, umem->nmap, 0) { - dma_addr_t addr = sg_page_iter_dma_address(&sg_iter); - - ret = pvrdma_page_dir_insert_dma(pdir, i, addr); + rdma_umem_for_each_dma_block (umem, &biter, PAGE_SIZE) { + ret = pvrdma_page_dir_insert_dma( + pdir, i, rdma_block_iter_dma_address(&biter)); if (ret) goto exit; From patchwork Wed Sep 2 00:43:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749603 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C0CE739 for ; Wed, 2 Sep 2020 00:43:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E99520707 for ; Wed, 2 Sep 2020 00:43:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="Wa53oifZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726174AbgIBAn4 (ORCPT ); Tue, 1 Sep 2020 20:43:56 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:4707 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbgIBAns (ORCPT ); Tue, 1 Sep 2020 20:43:48 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 01 Sep 2020 17:43:34 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:48 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:43:48 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:48 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gyz/tGau79X0hf3y+LbAucssnxMWf65bNIGH9+9+hJEh+1rQpov83W39BO2Ru7M4iv355Kf/8dKH945aIrMZvvTf1xevYgvn1fpTRNGrypCVla4pkS9IA3WStzjeIelGaCix0hGF/K9ThV4gKdmsTuAefOCnNBJ7dKU4cDI1Lma5NbBei2N3xMgBR4myTgCVEQo2KjykCzedVM1Jt9+mx/zqBBA+51gBbZwpAllGyiIGZOgV4uZU1QlmSHDJvxF6X72UuRd2dBKnoGalR4d4v17koLiN1fIL3zDnGk0oI5m1zaft1Zr60cqiuFwvUKJU4oTomAGHZemDMUQzyY6nIQ== 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-SenderADCheck; bh=tx3M/j0Xy5uioDT34gKd7Ab7+O0m486goEuDpaauLyg=; b=WDmmQhdORwav18Bs6bVU/JjElSWSQBcnI2+0CLeFgyNEYBXaDiStnD9w+Y5ZHSvxG1IU27+71RPOpyc3sLp3bzmD6NRzMpkhuX5KSh4AHzUiwb+7yE+C9wJ3+TlZKN6MYQFOF4FAZBL3BlnU6iDgZvL0m+RHUHs5JENO1MjzXl0voowBAJs2FSxaUFq5hEoT8ENVs5hBnhtGwzfeFg1XTwDKZW1Zc2mIMpomLn9+WPE7ft074qfKveg46r6N9mCRGDKuw5/l4mePbD/t5xarTJYAu4GM20X8HDrnMi4q2nnu+awpgZToBLPIZOpGfvxkvaJEEL+5+RGC6ytAEDuRwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: vmware.com; dkim=none (message not signed) header.d=none;vmware.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:47 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:47 +0000 From: Jason Gunthorpe To: Adit Ranadive , Potnuri Bharat Teja , Doug Ledford , Leon Romanovsky , , VMware PV-Drivers Subject: [PATCH 06/14] RDMA/umem: Split ib_umem_num_pages() into ib_umem_num_dma_blocks() Date: Tue, 1 Sep 2020 21:43:34 -0300 Message-ID: <6-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR19CA0002.namprd19.prod.outlook.com (2603:10b6:208:178::15) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by MN2PR19CA0002.namprd19.prod.outlook.com (2603:10b6:208:178::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15 via Frontend Transport; Wed, 2 Sep 2020 00:43:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsJ-005P1D-2R; Tue, 01 Sep 2020 21:43:43 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fce499e9-84a7-43d0-f43a-08d84ed93fb0 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2201; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZlQeGFE2aK2pLyDw/WlV+bWjHxd/zh6faoiyOH5VYe8oTRyYMoHGdjyE1/Gqv82fZoCMN4H1MSU4ZpkMDBWNpFTz7RHnBqeT6swW+ENDV9LJGesnu4qROq4yzx5yXfUXTm64vwFX5j3g9Ol4p+JetK0ju1QrfQJrfLhJfwDl591UoE9L4VGwSDMIin8/1scg7WgyrU7AMuYyagS7zogqPMnAnorZfSGUeOWZAuctQgNnkrBA6D6BsyDzxOr06YHWpqPVs7YGEQMr/NE2qqpFbFSIzKiWj/Vil7w6+uKf83PNGR1iuJ9zgKlzFg1znGcBJcZvjRFOC1mZjxcXc540x6bvWgiPTM4KXOhfwD3/swqPgsdL+N0V0EIdmgI1yyI1 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(6666004)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(110136005)(2906002)(36756003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 8Z0X+sR5PjR8m19RbOGoPOsBxpJSZ/8mZI403qh07NP5ech/x++xGAoYQCrWQXjwMcbX/kaKhtt4TNXg8nJZxFiZuevN+xrfGWmnBkMuRhNJKZZ/m+ZtzOKuPByEdoC+b4h1HZ3yCPwJsu6o9AjlPQRnepa9AL99Nt+GTJ0WBe0PiWvbSWf0GO9sqEqvm/1ZE5MAe6fNQ6bNi55KJFHQUnQY3hx38eizAmWuKEuVHFScXRBenMOMVnybYt/msu1C2tkYrFLxhr0yrC1aCLtJVaXq0h9g33s5Ly6SRXQoDhmOgUkV+ZfEq18mnUe91JlMzekEZoWn/FBPxBKC3COMc8uj0p749YYA7M+AlkGC6KuXUqGHNhmrBEfXORXItlOaHDUYI62PK34ttePcy5uvJ2xH3p66/R8QPqmNyH5p4sYOf+voMcuyEpfh3r+ew6kzS9qe50ot5nu/SS/LYjJ8psSzBH1y11R0E0YHUG6fwBIpBZnb/Oep8lNl69eO3v+SYD+rRHlnarCkvcr4EazzdcK9TORCVhHijo35xdrPI1PeccU/h08I/37qFbV6QEkxhH+S/iz3P3TByhpMHrEPaPc/VSa2qrAcy4/s9MtAmLbf3KeZIKbTMouRLx8eGP6zbeE7LfRKwoUw3SObV4zsWQ== X-MS-Exchange-CrossTenant-Network-Message-Id: fce499e9-84a7-43d0-f43a-08d84ed93fb0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:45.8815 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NjIwspBbvc1/aXg1CjXus2LMnKjhWgT+sJUOmATrq8+btcYPujeegE/1Uk/v5Kx7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007414; bh=uB1fNw7qR1Z2HDM4vBJ3VFVOXD0LLIgILn7I9HjxzCY=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:Subject: Date:Message-ID:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType:X-Originating-IP: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id: X-MS-TrafficTypeDiagnostic:X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers:X-MS-Exchange-SenderADCheck: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report:X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=Wa53oifZCBOVTys/WU0A+GMkmH3hcnVqhDFib5CYfYNNmlushpF8mGLeYXYpJBipr GLxtt9htKVSXNjizPYvKJCAdf/yvhKexynmCL+Tp85/BRyJC8m1DeO1bo8CCQEte1K h6hwfRSz+K2allacydX/PfZ/HbutRPA9x+Gyd9VVInFtX5C36bDUQH6ALy33jYPrBM jLnzd+NIqZRE0nJw1BTTStoaRrcs8GyQoqpiR434kd7sprLx1FGvj206HkiuNjLugZ Obd66T2D7gD1MJjmFWDzff3xN+H3CkiSaFgWNoegcSRAtx1uaDvnBefHcykqjmvPf7 t17Lqmr6GW91w== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org ib_num_pages() should only be used by things working with the SGL in CPU pages directly. Drivers building DMA lists should use the new ib_num_dma_blocks() which returns the number of blocks rdma_umem_for_each_block() will return. Signed-off-by: Jason Gunthorpe --- drivers/infiniband/hw/cxgb4/mem.c | 2 +- drivers/infiniband/hw/mlx5/mem.c | 5 +++-- drivers/infiniband/hw/mthca/mthca_provider.c | 2 +- drivers/infiniband/hw/vmw_pvrdma/pvrdma_mr.c | 2 +- include/rdma/ib_umem.h | 14 +++++++++++--- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c index 82afdb1987eff6..22c8f5745047db 100644 --- a/drivers/infiniband/hw/cxgb4/mem.c +++ b/drivers/infiniband/hw/cxgb4/mem.c @@ -548,7 +548,7 @@ struct ib_mr *c4iw_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, shift = PAGE_SHIFT; - n = ib_umem_num_pages(mhp->umem); + n = ib_umem_num_dma_blocks(mhp->umem, 1 << shift); err = alloc_pbl(mhp, n); if (err) goto err_umem_release; diff --git a/drivers/infiniband/hw/mlx5/mem.c b/drivers/infiniband/hw/mlx5/mem.c index c19ec9fd8a63c3..5641dbda72ff66 100644 --- a/drivers/infiniband/hw/mlx5/mem.c +++ b/drivers/infiniband/hw/mlx5/mem.c @@ -169,8 +169,9 @@ void mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem, int page_shift, __be64 *pas, int access_flags) { return __mlx5_ib_populate_pas(dev, umem, page_shift, 0, - ib_umem_num_pages(umem), pas, - access_flags); + ib_umem_num_dma_blocks(umem, + 1 << page_shift), + pas, access_flags); } int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset) { diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c index 317e67ad915fe8..b785fb9a2634ff 100644 --- a/drivers/infiniband/hw/mthca/mthca_provider.c +++ b/drivers/infiniband/hw/mthca/mthca_provider.c @@ -877,7 +877,7 @@ static struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, goto err; } - n = ib_umem_num_pages(mr->umem); + n = ib_umem_num_dma_blocks(mr->umem, PAGE_SIZE); mr->mtt = mthca_alloc_mtt(dev, n); if (IS_ERR(mr->mtt)) { diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_mr.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_mr.c index 91f0957e611543..e80848bfb3bdbf 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_mr.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_mr.c @@ -133,7 +133,7 @@ struct ib_mr *pvrdma_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, return ERR_CAST(umem); } - npages = ib_umem_num_pages(umem); + npages = ib_umem_num_dma_blocks(umem, PAGE_SIZE); if (npages < 0 || npages > PVRDMA_PAGE_DIR_MAX_PAGES) { dev_warn(&dev->pdev->dev, "overflow %d pages in mem region\n", npages); diff --git a/include/rdma/ib_umem.h b/include/rdma/ib_umem.h index b880512ba95f16..ba3b9be0d8c56a 100644 --- a/include/rdma/ib_umem.h +++ b/include/rdma/ib_umem.h @@ -33,11 +33,17 @@ static inline int ib_umem_offset(struct ib_umem *umem) return umem->address & ~PAGE_MASK; } +static inline size_t ib_umem_num_dma_blocks(struct ib_umem *umem, + unsigned long pgsz) +{ + return (ALIGN(umem->address + umem->length, pgsz) - + ALIGN_DOWN(umem->address, pgsz)) / + pgsz; +} + static inline size_t ib_umem_num_pages(struct ib_umem *umem) { - return (ALIGN(umem->address + umem->length, PAGE_SIZE) - - ALIGN_DOWN(umem->address, PAGE_SIZE)) >> - PAGE_SHIFT; + return ib_umem_num_dma_blocks(umem, PAGE_SIZE); } static inline void __rdma_umem_block_iter_start(struct ib_block_iter *biter, @@ -55,6 +61,8 @@ static inline void __rdma_umem_block_iter_start(struct ib_block_iter *biter, * pgsz must be <= PAGE_SIZE or computed by ib_umem_find_best_pgsz(). The * returned DMA blocks will be aligned to pgsz and span the range: * ALIGN_DOWN(umem->address, pgsz) to ALIGN(umem->address + umem->length, pgsz) + * + * Performs exactly ib_umem_num_dma_blocks() iterations. */ #define rdma_umem_for_each_dma_block(umem, biter, pgsz) \ for (__rdma_umem_block_iter_start(biter, umem, pgsz); \ From patchwork Wed Sep 2 00:43:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749613 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C86E739 for ; Wed, 2 Sep 2020 00:44:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BD6720707 for ; Wed, 2 Sep 2020 00:44:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="W7IdbSmm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726892AbgIBAoG (ORCPT ); Tue, 1 Sep 2020 20:44:06 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:4731 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbgIBAn4 (ORCPT ); Tue, 1 Sep 2020 20:43:56 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 01 Sep 2020 17:43:36 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:50 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:43:50 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:48 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b48v7oHBai1Ul3xqPYHS1aQTYqMM94d/plLEgSHJqZdjcJN5cRlntpubjBzpd+s9I5XpdvJJHcchtpGywQp5uA5LFAToJrLRtpO0PePjird53RO3A3kKB8Qr663v4Hjlv6F//WU6/AggR0OORaRtW8NGSg3Z1SL1gI2JgmscrRNddan53XzJW2T0uA4fvMx5nDBejb/AT9f6cVGRd4ExWPWaQPvBL06WzBlHLBdsCDwhgaxF8eQ4cIF7TYtaOkhmKOU5Tvcx3cSW6WoddVrroJTMLoGtUFOqVpGdm1t1LVHer6uAjpozo7DlYxkXg4RU7hlRdHUufvLcUdLJVE02RA== 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-SenderADCheck; bh=6jUvCXx+Iuwl5XIrrKSahRj8d1etFUYM3AfjOZigSdg=; b=KSpnbSeN0uis0mTanbGP4J5AT+hvnZgrwYwe57eEFtQM/7A4bbVn9q0/w4gDfioVicLpqxgiiUfSTPWWGmc62kQm1C1JPvbp/PUDa1qgp1uTyS4IVVPim6WIpO+/nmHNK2AMFu/pL0yuRenBYoFQ82pHi/UYM4GmiczvUDaNqHV8xKAvDEn5F1alfC689PA8CthVcrJOZXukYFDkbkpxPBbotD0p9HxN4oE28oNkx461wxt09ZTQwRPWnHKVoJWZ7LLrLKecm3tudkB6h3PcMI36+GGidb/HDoQuhd/r2UqJDTr94yLvBF+EMu8RPg9kfcluFQWC2QcVLKpiTr+UbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: marvell.com; dkim=none (message not signed) header.d=none;marvell.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:47 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:47 +0000 From: Jason Gunthorpe To: Ariel Elior , Doug Ledford , , Michal Kalderon Subject: [PATCH 07/14] RDMA/qedr: Use rdma_umem_for_each_dma_block() instead of open-coding Date: Tue, 1 Sep 2020 21:43:35 -0300 Message-ID: <7-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0007.namprd18.prod.outlook.com (2603:10b6:208:23c::12) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by MN2PR18CA0007.namprd18.prod.outlook.com (2603:10b6:208:23c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 2 Sep 2020 00:43:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsJ-005P1G-3E; Tue, 01 Sep 2020 21:43:43 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: be0fb61b-6530-4b03-3443-08d84ed93fc0 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2399; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 99A//UN9kkcZ8fJGaKgU/xzUP4Xu8dGxWtVAPQohUWpWPBjxLhKpy4T7R8U5/NAeFVA+lz819wBhWNTNBMeg0BpyYRY+2ADjByXIZFizkUVNNlFQ3vP4dH6DFFFYWSPI0anD9vtUVF/iVLu/sRzGAGkxUQp+GuQZw6PsgbGKC4g6n5Dm6ueuWuumcXP+U0AdnJfFzjqZhGqbBFXeiN3U/6WjDHcGWk6hrXmG91awfZdZoDhM1DLbZDXd0gYzbebjryUhBHFoKUl7l//E25XM2ziawpFPC6JjtDqIXDK1Hoq8vrHav7Ksn1Tnz7FaB+Dq/1KFm5NIks4L6Clzq4Vq8LlYHGmQxAfeD+U8Akd+zHuBE4GCbPXIV2EmeKuevSLl X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(6666004)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(110136005)(2906002)(36756003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: YFpY32uLWKnnAXJti6DnCvQF03M2ESjCTMi6lQp42JZj1/u+5reWX+cnlWx1dQpO0zIl8Tpiy1n2LIiuo9XVeSmQkZeNT8fM7QFPZtvq3LGb/CySBMwa7JygYc8swvY17bgcFS27DL9LgTXReDMvP7Xh2aBsRA5BZ6uDFYeIZZ7qrdMi2gxn1TswyDS0GWFi2PedOePtAjjAy+nEBFXHmHQZu26r70A62MUQ89p5BepZ0RVIhJOzp8l4BTJR5pAM4ytjz70apkPUgb9eLkDPaaTFAEh51vGO5te6RieWXGQCpkNjoXAya0dpWMXyw4m7/exFJfA+eMUwiWLK7uIupVgmL+kl36ICPGjDXlPoBzqNzjDPXdUyqhQ6Fk6PFu5f3yBRfqySqHZSzd3FsxJYXP12OhJ1FCgXGVBx1j3d6jNyIZYLQlLZMNZ3T+Z/qdakPxIDD4Yn6aYgHWTTXnMRHKlnVxCVpZsEvcT/n9gYypUvTOoGwEdN7rNyAiPAdSCDZ6Kr02I3JqTKTMhRKN+z1o9zHUvIntY5xYTsI3iNaGVZmcPAyh3vpaqunySPfzMexzQDWv1PobPNoTOq4MwmyAWZdBHJtZqmPEh9gJ/my0GXEs7sasMOofdm+CTtXY/YGmD0hpn9s2PwVXPZhZq5Bg== X-MS-Exchange-CrossTenant-Network-Message-Id: be0fb61b-6530-4b03-3443-08d84ed93fc0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:45.9904 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7jkcPVel4eG8Vi+a/KfraJ/ZP3PSEK97GWAHFA2/MRcHcaBp8lF3KoVSB6yPWCQB X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007416; bh=YavJfwtlVVWmDXVat2JsqU5c0OFnfgYgc3/yCx+fJtA=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:Subject: Date:Message-ID:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType:X-Originating-IP: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id: X-MS-TrafficTypeDiagnostic:X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers:X-MS-Exchange-SenderADCheck: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report:X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=W7IdbSmm1vvsFqL+3CDdfpXZ3lKsRVp73E2dlSNIpv7ENzgZ4HoMb+V2zT7OH6HAV 4nV1tgof1lalL2LWHsHWN+Ywj9eRmry9wFPYuelU+svc7/rN5SphmaMyZeVgHaPCv+ EmBgHkP+v0G5giGTmf7qDc78byJWtTg7r+BzaBWX0hRW5WjsOJYIEC4MK/nWQ1r6mv XRsOXMDNr+gHKvh+SlVvW+uLgzctaOh6yr8ObDPioIZNnQ0P9/CQGNyMViCgXp3Xm4 gnM+AIC6jMCXVJXPH6lqu6MNLg6Rs6wxVm4Ok672zFtE/XIK+YRIY4BRlwVQGVOUqq yIXolcoRNJ3Jg== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org This loop is splitting the DMA SGL into pg_shift sized pages, use the core code for this directly. Signed-off-by: Jason Gunthorpe Acked-by: Michal KalderonĀ  --- drivers/infiniband/hw/qedr/verbs.c | 41 ++++++++++++------------------ 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c index b49bef94637e50..cbb49168d9f7ed 100644 --- a/drivers/infiniband/hw/qedr/verbs.c +++ b/drivers/infiniband/hw/qedr/verbs.c @@ -600,11 +600,9 @@ static void qedr_populate_pbls(struct qedr_dev *dev, struct ib_umem *umem, struct qedr_pbl_info *pbl_info, u32 pg_shift) { int pbe_cnt, total_num_pbes = 0; - u32 fw_pg_cnt, fw_pg_per_umem_pg; struct qedr_pbl *pbl_tbl; - struct sg_dma_page_iter sg_iter; + struct ib_block_iter biter; struct regpair *pbe; - u64 pg_addr; if (!pbl_info->num_pbes) return; @@ -625,32 +623,25 @@ static void qedr_populate_pbls(struct qedr_dev *dev, struct ib_umem *umem, pbe_cnt = 0; - fw_pg_per_umem_pg = BIT(PAGE_SHIFT - pg_shift); + rdma_umem_for_each_dma_block (umem, &biter, BIT(pg_shift)) { + u64 pg_addr = rdma_block_iter_dma_address(&biter); - for_each_sg_dma_page (umem->sg_head.sgl, &sg_iter, umem->nmap, 0) { - pg_addr = sg_page_iter_dma_address(&sg_iter); - for (fw_pg_cnt = 0; fw_pg_cnt < fw_pg_per_umem_pg;) { - pbe->lo = cpu_to_le32(pg_addr); - pbe->hi = cpu_to_le32(upper_32_bits(pg_addr)); + pbe->lo = cpu_to_le32(pg_addr); + pbe->hi = cpu_to_le32(upper_32_bits(pg_addr)); - pg_addr += BIT(pg_shift); - pbe_cnt++; - total_num_pbes++; - pbe++; + pbe_cnt++; + total_num_pbes++; + pbe++; - if (total_num_pbes == pbl_info->num_pbes) - return; + if (total_num_pbes == pbl_info->num_pbes) + return; - /* If the given pbl is full storing the pbes, - * move to next pbl. - */ - if (pbe_cnt == (pbl_info->pbl_size / sizeof(u64))) { - pbl_tbl++; - pbe = (struct regpair *)pbl_tbl->va; - pbe_cnt = 0; - } - - fw_pg_cnt++; + /* If the given pbl is full storing the pbes, move to next pbl. + */ + if (pbe_cnt == (pbl_info->pbl_size / sizeof(u64))) { + pbl_tbl++; + pbe = (struct regpair *)pbl_tbl->va; + pbe_cnt = 0; } } } From patchwork Wed Sep 2 00:43:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749617 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E943109B for ; Wed, 2 Sep 2020 00:44:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB7562071B for ; Wed, 2 Sep 2020 00:44:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="GQSrw27q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726623AbgIBAoG (ORCPT ); Tue, 1 Sep 2020 20:44:06 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:4735 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbgIBAn6 (ORCPT ); Tue, 1 Sep 2020 20:43:58 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 01 Sep 2020 17:43:36 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:50 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:43:50 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:47 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a0TPgMGGpqXIF4K64wEMp9hnBPVFK99ADeONYY45F92NeKNwbSx93PieYFB37CPZIx2mVF2NahyfqLsq0UpGBn6S4hjoDhXPN5ewyMbmaOcVBtEmps/qk3qYtj9laTXEfew+8oSx5RbT9QckoMa55UFQJwJDAi9I6tQTF4I7zQycvUzmSJT8Mz98OjYN7XKhn+GymMIMq8wCCa3XV+W0xmYT3mGXtQ01msijSDhsJ10PBGi6J/bcwA6jo9I1zPRre4fwY/LMRRkkCkC8CxKI4G6c0qaIw7u9koRwp2IPaESXq8lACi176jrBX/1pMlDBCMpFjrZ6yJP7TPiwAjz9LA== 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-SenderADCheck; bh=hhmfE/HiS+k2qms0Kvgb64G5sK4eBYV1UYXzls1MxUM=; b=dqWBTG+yNqPIP5PGoaqRAJYqjUkJDEX8btSEm59sZ2x4/0LowTaZRdZwMWAxlKUIXZ0tJSgdI7FjukER1Y6hguT5f98v9IsxRYD/1QPA8nLNqi7Huqtvhw2ifZDuiED2h0AzXCbKmfQHt6ocCbMpEVSqdgZZeDMRSAhbUU8iNhLhJ8GhzAItDq7OSQK3ILoQ8LepDww/QirdZaalSDfKaiZ/ksj2wt8Ef4kPhckjo2/Q0drbNxXQK/mb1uuaFETtije5lKAMNOwciexKskS69bvnhllt6KZNViPjJ64aWYMipqVmSBUl2jxL9sCeUI6Z5mKn+qBkz1FBVWksk54BTQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: marvell.com; dkim=none (message not signed) header.d=none;marvell.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:46 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:46 +0000 From: Jason Gunthorpe To: Ariel Elior , Doug Ledford , , Michal Kalderon Subject: [PATCH 08/14] RDMA/qedr: Use ib_umem_num_dma_blocks() instead of ib_umem_page_count() Date: Tue, 1 Sep 2020 21:43:36 -0300 Message-ID: <8-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR19CA0031.namprd19.prod.outlook.com (2603:10b6:208:178::44) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by MN2PR19CA0031.namprd19.prod.outlook.com (2603:10b6:208:178::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 2 Sep 2020 00:43:44 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsJ-005P1K-4G; Tue, 01 Sep 2020 21:43:43 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2636fcc0-d32c-4962-3b58-08d84ed93f17 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 215R+ooY/yQNPcpfMbVpt5WN16tu+04mpYpC3RmhnOqz3hTadbEeTXUsb1w7gVE1I93w/ZyALZxE1PhGudN2vAxsYM0PcID0xhczLYbt5+G2slS+Hq7TbhIo2MZGEYrWANiLqzs6pX8bCKQ/KYJeyBVhp0kiWaMd2aF1Hod83LammfgiTvzm5dU11xPIVsn4O8G1jwIdj5zRuHVfgVvHIRKczFGSU01Phj/ZsiWeEJtTR17SIZqAynD3PuPl/Cl5EsllBrmz7TnKIdZ24lMo1vUdwspCKmd3Ygf03qh+rwy1mIYnbAzNUUUfzYYNqc8MxrmMCNrmRE2hqP/qZ34mH/isZOKJl0nxt80A3DtIHPI/eCB5facgu4AUq6Z12gEb X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(6666004)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(110136005)(2906002)(36756003)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: v4o/CQogpfF1Z7VWSPRpvjsWlrTGgWID5UjRWNKtw5Z4fDFUeCuzya8bnm61ixAzn3WyWjQqjLK3R7tSRp9Nftqkdl0SwncoZc9JOqabzqfiSfupdl+7E9ug2lFOyKAd7F5Ps8iQ14g4tdVVdSM9Ii+yQsizzD9r3k4ptaM139/vajcA27EWjhPRvdUU7AQs+5QaEew13fHTZE2gVmQ4onCBZrZfxBbix2xdIOqwdR6TNL69v46PsdN47KEa8tzAj8XL81vp2rh9yMEWq8hPQq0VfpRkBg57Hd2TZSTO+rqOoVkL7tArGWAh++wWc/CS+EYfUK9yOGC2g13TjqEN51Ri+kDUTRd+Ea5ABO9LN6q4DuVaEI/w/USiBhwO9bV1sH5rbIIPmdlPRax/BMT3ihYtMs5/P73o7UJdvGxqXjgLSyVtiYfoGUrqt20KIztjENMKDy4vcXIfck6WsVsJYDniIODEJOLBwnHDbNzp8NuebOr+Us59yL17LSI0IoaH3o8JjqA6djDz4uIqeeudJxQmxZH+OwaNCnju9c2ghofA9PDdEjRycLeOhUSJMZgkOnE6rDG9EDNAvVT/gkXeCSJYOBxUvgzJYUQ+tLpPMqkBljCGSsys6GIo0el9FP3+eXUiLyasY4oRTspHkNbo3A== X-MS-Exchange-CrossTenant-Network-Message-Id: 2636fcc0-d32c-4962-3b58-08d84ed93f17 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:44.9530 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2WxrYFrvb5G0ffEl4exlTDMKIR7PW1ArONGqT7wzp7Wu9hk6K/VH5Y1ifw6F6t8+ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007416; bh=5dbYUNX/ew0HqNUaPH6y7tSfRdzYx58LKfzpkcEocVU=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:Subject: Date:Message-ID:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType:X-Originating-IP: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id: X-MS-TrafficTypeDiagnostic:X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers:X-MS-Exchange-SenderADCheck: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report:X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=GQSrw27qW1ge0kAlWE/fZkjRUKpljvBTmaQUQScc6lsl6m9A7OfqcFmIL/n3pLHyo 9RmXOYwYumFBnNcB/apY4JRFWdtPgWKOBgbxy5NB9HtapKNrPGOXo9UgwORrgCBSOF hoUs2ZdwW5G/562m34A2LWMkEJKaL/8Zireqbbtm64vdsZfqlWVg0+gT1HcJMM537+ 6CPpBPxvlSxSycq3BGATXOk0nx1u52BSuUyjD9WGPud+zxVCPnZ93G8r2oGZywRYDt q0mAtl/Yvswe85IhbdLZCBAFQJaKzDL/ewPj72HQVATPZDaf1HmfCzt4cyxeAm4Zg6 JvFRNnM1PZ/YQ== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The length of the list populated by qedr_populate_pbls() should be calculated using ib_umem_num_blocks() with the same size/shift passed to qedr_populate_pbls(). Signed-off-by: Jason Gunthorpe Acked-by: Michal KalderonĀ  --- drivers/infiniband/hw/qedr/verbs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c index cbb49168d9f7ed..278b48443aedba 100644 --- a/drivers/infiniband/hw/qedr/verbs.c +++ b/drivers/infiniband/hw/qedr/verbs.c @@ -783,9 +783,7 @@ static inline int qedr_init_user_queue(struct ib_udata *udata, return PTR_ERR(q->umem); } - fw_pages = ib_umem_page_count(q->umem) << - (PAGE_SHIFT - FW_PAGE_SHIFT); - + fw_pages = ib_umem_num_dma_blocks(q->umem, 1 << FW_PAGE_SHIFT); rc = qedr_prepare_pbl_tbl(dev, &q->pbl_info, fw_pages, 0); if (rc) goto err0; @@ -2852,7 +2850,8 @@ struct ib_mr *qedr_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 len, goto err0; } - rc = init_mr_info(dev, &mr->info, ib_umem_page_count(mr->umem), 1); + rc = init_mr_info(dev, &mr->info, + ib_umem_num_dma_blocks(mr->umem, PAGE_SIZE), 1); if (rc) goto err1; From patchwork Wed Sep 2 00:43:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749621 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1EE6314E5 for ; Wed, 2 Sep 2020 00:44:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0701B20707 for ; Wed, 2 Sep 2020 00:44:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="QOHVsEu7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbgIBAoP (ORCPT ); Tue, 1 Sep 2020 20:44:15 -0400 Received: from nat-hk.nvidia.com ([203.18.50.4]:21279 "EHLO nat-hk.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726871AbgIBAoI (ORCPT ); Tue, 1 Sep 2020 20:44:08 -0400 Received: from hkpgpgate102.nvidia.com (Not Verified[10.18.92.77]) by nat-hk.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 02 Sep 2020 08:44:00 +0800 Received: from HKMAIL101.nvidia.com ([10.18.16.10]) by hkpgpgate102.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:44:00 -0700 X-PGP-Universal: processed; by hkpgpgate102.nvidia.com on Tue, 01 Sep 2020 17:44:00 -0700 Received: from HKMAIL102.nvidia.com (10.18.16.11) by HKMAIL101.nvidia.com (10.18.16.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:51 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.172) by HKMAIL102.nvidia.com (10.18.16.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j3CiSSlMJOU9lw2hdTM3pjXggZ41kNIcP+1yErLvFfYIFRzPFbgBK+tuTg07NTvotGY7NnTK93QRvoou4zKQc50/Kj015PaH3Ca0hUNOhNi3cSt02t7P0w+w6PGokxx9pAsFCHwKfYcMWsDIxHYgKfwBRm2L9pOTkPikZJbCThf3efU7Baau+8yh13WEbssfqOZ3WyMa2l97OFFhEoOmRxxGYr+zDKKj5FNIloMHAsakqhu85FYeiHB+kMKtdUfZOY1bgWapx7TyssiWLwGC69WcBsJEkOPo/muGfw+EwZa/I1ROly83o2VCitC4V0cZRR3KYcYdvD6W0XXRnkTnDw== 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-SenderADCheck; bh=JwsKr5yJdCimpvp9StmwtDJ73QT8/wb6944NazKIqN8=; b=NaNH3euGj/WatN/VtKwfeeMbMhrQKWFhQ3n9NLN/pF4tp/nF4Wxjw9v91fHWrDyJkCDwhvqpPOsN7afZNKYjTAKVYEdNP0pShlAlMu5S7EOLhVkztdvzU7rMJNoss+kudgUCqGljojyUCU6hiOwB9VjuErUuHt412iNCpFaYDknU50qTxdA1VJmy7yoOrDgyKWLipGrjkO6CRhoW8JXjVN/rqL1B9DBC+VNSNF16ueUK5+Y7AOvtKfE51U1ftkIcYczY/nciiBPGbu1p74bc8+bkU8RwYqQYRuvTKj546QchqYp44m37XIA/4P8OvaBJ/PTUJNHRclz5aJvlGYdXhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: broadcom.com; dkim=none (message not signed) header.d=none;broadcom.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:49 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:49 +0000 From: Jason Gunthorpe To: Devesh Sharma , Doug Ledford , , Naresh Kumar PBS , Somnath Kotur , Sriharsha Basavapatna CC: Selvin Xavier , Shiraz Saleem Subject: [PATCH 09/14] RDMA/bnxt: Do not use ib_umem_page_count() or ib_umem_num_pages() Date: Tue, 1 Sep 2020 21:43:37 -0300 Message-ID: <9-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0011.namprd18.prod.outlook.com (2603:10b6:208:23c::16) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by MN2PR18CA0011.namprd18.prod.outlook.com (2603:10b6:208:23c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15 via Frontend Transport; Wed, 2 Sep 2020 00:43:47 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsJ-005P1P-64; Tue, 01 Sep 2020 21:43:43 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: df552eb6-5d89-4970-47a5-08d84ed940a3 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2150; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZTqgPMwCkZLopde8UAZ7QBVz7tiiWq7LVkodGuvvJtnpGvtvI65t2AowKkY1g/ODXD+nHU4vh8dh7B9LOsZ0RYHZ6pbbq7Z1rhca+gkWb67CXniyDJMayby0MR6XPC9iycqAJWpDAj8OyxmFV6/UjDXW81ytAOtBsZLpI8HbcAgfuWzu6wWD3dDb6O8LYWUozNeYVykp1DpPKe5tEbYigyge4zYYx1eMQG4FNK7Js4N/2uKGZaFcGlrUiB5C0BHLqMTJCE90zB4JdtQxrNIUWDwMWmtmJs2uphMSYjvoM/uT1Gu27h3lDdNxjb52nrMREJE2Fca2iXoWQwc+edF6qBHxIvHF4Vka9/Hqko6PuIh3G7knk6jdi+tayLD+8O4a X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(6666004)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(110136005)(2906002)(54906003)(36756003)(4326008)(5660300002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: SqIF7QMxufmkkYipSDiwHyRXkwroJRBqQk57v23OMpvJ8fbcx98HFIGLwafFRY2l5f1xNlmVwRmjZIe+BAJ++ZTUePogKzj0HdT0tkgv15pUGwfll57BdUNx9aECoJf6rl5qWbFTm7EWMC1KP9/Xs9Hy1SiKUcLXGdAJByJKyVobdm7m1iHkNqdX4tZY0ElZvcVJRX54wvRLuB7MVmOoGDcttrgwqMgEZdh5/ruI5SjbNBBN6jgsM3E7kQI8MOmrf0HtQG97gevmSquQSIiuPhjzvACcwugKjI1gIT127hPe/EdhBDrqGPMNRxbeba4bLVN2jaGGQzAF8UL9tU9NR1BIVlNiqOdhzAWe3aQdC4LZmoSJLsvlUrw8mTUhQhTLgD3z+XdDNIvC+hXA+fOyNTqAYMiFy9zUhA1fB05tQhXV4FCJjr1R/gE/pOBfpr0Inmfv6gQC6K3/mLETKL3JLxxy2dGrLt8bt7xV84TspECP+9wUFkz9Jo/D35GJzMOzut5ZZfZXVQ6qyJiIEtCuas4roKgaeTOdTvBva/JwL42iCLaqnW/Cja914bbnkz5keCA4J85mM08JQeWVeB9+sDaSMmovHcfB5bwXaQ79dk6jiMY89tGQv2IEoUy4mBFMo5ztqIo4wujONsVHPzqWRw== X-MS-Exchange-CrossTenant-Network-Message-Id: df552eb6-5d89-4970-47a5-08d84ed940a3 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:47.5455 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: J/CGxDnViD7Gn8Aei70/lvWlIlWXhbpXlk7oNH6ABr6d3MHY3xkzEZJjqKWLKEro X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007440; bh=HclRIbqfnASPpb6kI/3pJO1qsQuptuMPRSl66ThNGMQ=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:CC: Subject:Date:Message-ID:In-Reply-To:References: Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy: MIME-Version:X-MS-Exchange-MessageSentRepresentingType: X-Originating-IP:X-MS-PublicTrafficType: X-MS-Office365-Filtering-Correlation-Id:X-MS-TrafficTypeDiagnostic: X-Microsoft-Antispam-PRVS:X-MS-Oob-TLC-OOBClassifiers: X-MS-Exchange-SenderADCheck:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=QOHVsEu77KmQi442S6JIjPIngd6pr68EnZWsFVi4JuxP5lgp7r/r+2QCCfumLAITF Q564f3ZdnNXcX8TuVXbEXNVi9+W3P5v+wPYdOSwpbVfX78Efhl6y5MRVlt5Hnv623B 6obZgkb2yj/wrGp+d6cDC4pN5x87xN7VRWSddK4eVDRkeE6TyvZ+c552QHWTGqGTq9 iMLpVfppqwcQXEOZv2xMKXpmKZVAF1EyZ1y0ngGGLN4e6mmAaEYDZuUzAkI2NfRW40 yD5W5BEH4mwfURyo9VGtcp2CL9WIS3sSUmpfDd0EJ8cp4GyZF7NpbJV14gnBhkFe6a jp42hDQFFoDbQ== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org ib_umem_page_count() returns the number of 4k entries required for a DMA map, but bnxt_re already computes a variable page size. The correct API to determine the size of the page table array is ib_umem_num_dma_blocks(). Fix the overallocation of the page array in fill_umem_pbl_tbl() when working with larger page sizes by using the right function. Lightly re-organize this function to make it clearer. Replace the other calls to ib_umem_num_pages(). Fixes: d85582517e91 ("RDMA/bnxt_re: Use core helpers to get aligned DMA address") Signed-off-by: Jason Gunthorpe Acked-by: Selvin Xavier --- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 70 ++++++++---------------- 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/drivers/infiniband/hw/bnxt_re/ib_verbs.c b/drivers/infiniband/hw/bnxt_re/ib_verbs.c index 9e26e651730cb3..9dbf9ab5a4c8db 100644 --- a/drivers/infiniband/hw/bnxt_re/ib_verbs.c +++ b/drivers/infiniband/hw/bnxt_re/ib_verbs.c @@ -939,7 +939,7 @@ static int bnxt_re_init_user_qp(struct bnxt_re_dev *rdev, struct bnxt_re_pd *pd, qp->sumem = umem; qplib_qp->sq.sg_info.sghead = umem->sg_head.sgl; - qplib_qp->sq.sg_info.npages = ib_umem_num_pages(umem); + qplib_qp->sq.sg_info.npages = ib_umem_num_dma_blocks(umem, PAGE_SIZE); qplib_qp->sq.sg_info.nmap = umem->nmap; qplib_qp->sq.sg_info.pgsize = PAGE_SIZE; qplib_qp->sq.sg_info.pgshft = PAGE_SHIFT; @@ -954,7 +954,8 @@ static int bnxt_re_init_user_qp(struct bnxt_re_dev *rdev, struct bnxt_re_pd *pd, goto rqfail; qp->rumem = umem; qplib_qp->rq.sg_info.sghead = umem->sg_head.sgl; - qplib_qp->rq.sg_info.npages = ib_umem_num_pages(umem); + qplib_qp->rq.sg_info.npages = + ib_umem_num_dma_blocks(umem, PAGE_SIZE); qplib_qp->rq.sg_info.nmap = umem->nmap; qplib_qp->rq.sg_info.pgsize = PAGE_SIZE; qplib_qp->rq.sg_info.pgshft = PAGE_SHIFT; @@ -1609,7 +1610,7 @@ static int bnxt_re_init_user_srq(struct bnxt_re_dev *rdev, srq->umem = umem; qplib_srq->sg_info.sghead = umem->sg_head.sgl; - qplib_srq->sg_info.npages = ib_umem_num_pages(umem); + qplib_srq->sg_info.npages = ib_umem_num_dma_blocks(umem, PAGE_SIZE); qplib_srq->sg_info.nmap = umem->nmap; qplib_srq->sg_info.pgsize = PAGE_SIZE; qplib_srq->sg_info.pgshft = PAGE_SHIFT; @@ -2861,7 +2862,8 @@ int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, goto fail; } cq->qplib_cq.sg_info.sghead = cq->umem->sg_head.sgl; - cq->qplib_cq.sg_info.npages = ib_umem_num_pages(cq->umem); + cq->qplib_cq.sg_info.npages = + ib_umem_num_dma_blocks(cq->umem, PAGE_SIZE); cq->qplib_cq.sg_info.nmap = cq->umem->nmap; cq->qplib_cq.dpi = &uctx->dpi; } else { @@ -3759,23 +3761,6 @@ int bnxt_re_dealloc_mw(struct ib_mw *ib_mw) return rc; } -static int bnxt_re_page_size_ok(int page_shift) -{ - switch (page_shift) { - case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_4K: - case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_8K: - case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_64K: - case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_2M: - case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_256K: - case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_1M: - case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_4M: - case CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_PG_1G: - return 1; - default: - return 0; - } -} - static int fill_umem_pbl_tbl(struct ib_umem *umem, u64 *pbl_tbl_orig, int page_shift) { @@ -3799,7 +3784,8 @@ struct ib_mr *bnxt_re_reg_user_mr(struct ib_pd *ib_pd, u64 start, u64 length, struct bnxt_re_mr *mr; struct ib_umem *umem; u64 *pbl_tbl = NULL; - int umem_pgs, page_shift, rc; + unsigned long page_size; + int umem_pgs, rc; if (length > BNXT_RE_MAX_MR_SIZE) { ibdev_err(&rdev->ibdev, "MR Size: %lld > Max supported:%lld\n", @@ -3833,42 +3819,34 @@ struct ib_mr *bnxt_re_reg_user_mr(struct ib_pd *ib_pd, u64 start, u64 length, mr->ib_umem = umem; mr->qplib_mr.va = virt_addr; - umem_pgs = ib_umem_page_count(umem); - if (!umem_pgs) { - ibdev_err(&rdev->ibdev, "umem is invalid!"); - rc = -EINVAL; - goto free_umem; - } - mr->qplib_mr.total_size = length; - - pbl_tbl = kcalloc(umem_pgs, sizeof(u64 *), GFP_KERNEL); - if (!pbl_tbl) { - rc = -ENOMEM; - goto free_umem; - } - - page_shift = __ffs(ib_umem_find_best_pgsz(umem, - BNXT_RE_PAGE_SIZE_4K | BNXT_RE_PAGE_SIZE_2M, - virt_addr)); - - if (!bnxt_re_page_size_ok(page_shift)) { + page_size = ib_umem_find_best_pgsz( + umem, BNXT_RE_PAGE_SIZE_4K | BNXT_RE_PAGE_SIZE_2M, virt_addr); + if (!page_size) { ibdev_err(&rdev->ibdev, "umem page size unsupported!"); rc = -EFAULT; - goto fail; + goto free_umem; } + mr->qplib_mr.total_size = length; - if (page_shift == BNXT_RE_PAGE_SHIFT_4K && + if (page_size == BNXT_RE_PAGE_SIZE_4K && length > BNXT_RE_MAX_MR_SIZE_LOW) { ibdev_err(&rdev->ibdev, "Requested MR Sz:%llu Max sup:%llu", length, (u64)BNXT_RE_MAX_MR_SIZE_LOW); rc = -EINVAL; - goto fail; + goto free_umem; + } + + umem_pgs = ib_umem_num_dma_blocks(umem, page_size); + pbl_tbl = kcalloc(umem_pgs, sizeof(u64 *), GFP_KERNEL); + if (!pbl_tbl) { + rc = -ENOMEM; + goto free_umem; } /* Map umem buf ptrs to the PBL */ - umem_pgs = fill_umem_pbl_tbl(umem, pbl_tbl, page_shift); + umem_pgs = fill_umem_pbl_tbl(umem, pbl_tbl, order_base_2(page_size)); rc = bnxt_qplib_reg_mr(&rdev->qplib_res, &mr->qplib_mr, pbl_tbl, - umem_pgs, false, 1 << page_shift); + umem_pgs, false, page_size); if (rc) { ibdev_err(&rdev->ibdev, "Failed to register user MR"); goto fail; From patchwork Wed Sep 2 00:43:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749609 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 492BE109B for ; Wed, 2 Sep 2020 00:44:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CF5420707 for ; Wed, 2 Sep 2020 00:44:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="AaioOkZ+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726622AbgIBAn7 (ORCPT ); Tue, 1 Sep 2020 20:43:59 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:5450 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726064AbgIBAnw (ORCPT ); Tue, 1 Sep 2020 20:43:52 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 01 Sep 2020 17:41:44 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:51 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:43:51 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:47 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=npwNYgl+X4sPv3CaXbK4T6D52mg+MEhL4qlGvcc30MjEixwD79iwFH7kNfl+jrFlsBAn9HYXULKM0Cv4STOAzOW83JgJZ3eB9LMGzleax4rxaz9ru5fEp5JcoihiPjXGD/t0igBrrp2zEmfTcxhzPnlNF2KRxRVYAgbuoXNqZ0O9zETfCxEeUJeHCrsmlWnk9AVNYpySvhgIey3AQ3nasCj5XaWP7LFIaOUIvR2v85en2IrEjazw3JqYgW/MbfxlAtIBCYWRroz86R450j9FGZ/UZUMgvCjH9bYHw5kSdKCyoLtgEwK0ANWo9c/YImH5hbvfoM2tbIKPaDJ5hV/NtQ== 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-SenderADCheck; bh=9DaW4fMlu+pQfCvGTkMLYrO8NO+aT6iia6vs1aHUbXw=; b=bXx0ZHjTWQNpYo0qOG4ihiiabLWKKZjkraYhJ5eUv8Z2q0EntgNk2okULsmTKmVGTGAdwdox9JoAGRnfcFmo417kyYkPV0TdZiB0ntTQh89WHOwXhATaJpd2V48LRSw4eoQK585Mf/UfY2E2rf0Ln7RFcRdPUlnBdYMSI7GmKr7YJvvKyEdE+Il/gtLbli/d2qfWcIWftLOmYstl90NOjXsxQlMOHLRf0ICncenIDt+icKSgvnmx8QMGpNLzPMFEnWj48MzhrMoKwBIR8to9r3IfG2vDl4kcZA64GSQzM2jtlCi/xyPD16bdeP4fTMXkfPA37DovHwyWQuNbN4z+LA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:46 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:46 +0000 From: Jason Gunthorpe To: Doug Ledford , "Wei Hu(Xavier)" , , Weihang Li , Lijun Ou Subject: [PATCH 10/14] RDMA/hns: Use ib_umem_num_dma_blocks() instead of opencoding Date: Tue, 1 Sep 2020 21:43:38 -0300 Message-ID: <10-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.20 via Frontend Transport; Wed, 2 Sep 2020 00:43:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsJ-005P1S-7a; Tue, 01 Sep 2020 21:43:43 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 060b2b2f-57c1-4e67-599f-08d84ed93f58 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6OXIFfnfjmr5I7g3tyaWO6wmtTbFzLze7RrGjtEjr0iBVOHaiT5mJEPjG93HxlhMDBFfb6SJ9G5kQ6aDobJR9hdBVd3xmIwYXouPJAYnlVR4CVkvJBPg6ZLaagPtaNztGxP/Ga+dYjsz2axAQV9D8v/H1Re0xlq7Pft5ghMntaf0QBDsghbo36lNtZeERbihwOBlLNQrZZQNPNDuPEAurDlKzT5AB3iQBsdgG2hugvuuhiNKnCOAj+C36VWpsvc64kTb5pdiUfntillskgu7XWhA+xJRRsav07DOxY/Fdr1P9cKJGetI4LskYchBrH8UztKS87xzHxHeMAD905qlMg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(6666004)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(110136005)(2906002)(36756003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: UG7Scm29awM+1k0EY6Jf5cdHSG+iU2DP3WCzfHRkZ+MMyzZnL77TfnXsYE7Dkk9Xit56HzHy6ldGwRVfEFaM8eOc7lHEeSIuZkpXe+zsdiJDjyXQSODtEmkh/jsCuUrFLY5QPJ3u+SS/f+QNCHuKn9n/NlXH+ldJMUD24k69c1LoXi80QpyG9T1KXiR4rEoanVbyYuWPLmyELfUhv/zE2Jl3R0kSKxB8LqxVEEAP8ubQEwoDwmKzRMsM3FtjQ7KpbDlFXOEK/WrUSDD/zT4cPrMQ+e/ZsrDfXbyHa6G4Z4OFW+rFP6qzizee/cT+Kq69eztsIaB66Q6JaHqUh6wk+NO1ii3iNIyOaqmJJergrXJjkbjfbbjjJprLzE7hLaJ8ExZtye5NBrv3//1hfMI4LiV1iVEAdPYumVjguxfRDJsM7YNf+vDJ92wOouw3Og/ygkaiQlqqXQSQxKriGYu+NJ+PFAkPryPJYWpjdlvlVmlIAR4mYfm/Ef2VzA5/Et/XiSxp/h38LWXl5/LFnlTiBY6ojQkgjLPxwO2p1o/3DhAS96wshKJN/NXgTepUuouXR3WfBlpOy0pbBT6uGM71p1Z1abcaiQgdRKxv64FmJZRp5y2HMcD76skSGcl6FPLiiqt/piD05md57iSxiN+tfg== X-MS-Exchange-CrossTenant-Network-Message-Id: 060b2b2f-57c1-4e67-599f-08d84ed93f58 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:45.2568 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /8iB6jPPzLfOy0qI2Yvn14fN6TDzDUP8MJCuQaITJKEUT4NUABJuC8xeM83Xge59 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007304; bh=Y0rbSpvE2utNEz97wF2kX2sNXyfdDN0RCk6d2kyvxEY=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:Subject: Date:Message-ID:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType:X-Originating-IP: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id: X-MS-TrafficTypeDiagnostic:X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers:X-MS-Exchange-SenderADCheck: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report:X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=AaioOkZ+tCYc7/PGvL2+M0N2Gusyj8OGYvNt7Za2KlvrjpJmhDmkATFYp9FBWnNkL hjggi6K9GVcf8+RZQFJaQF1SAmVO8HVvLV0WvQHUx3BmCh0lqAiH6OjaZYByEyxmoF Mut2I4jyk5uErwArfhRWgtEU2R9GZJNuYFt+lluDIlULPoOaKGt54HH/zHZwG411Bj Sow8Y7iLhPR/bZlUF2lG5ESg5Yxs1sMTolEUEMDF2BI4SpUa3iQ7guE3yl3h4iCAqx Q9NLHBzPELJ5ArRNPxCJa246kCzlYrD2HBfZ8BQXIr8wFFknssApFbrtaZlplkQDYa wgPYU8POXwCRg== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org mtr_umem_page_count() does the same thing, replace it with the core code. Also, ib_umem_find_best_pgsz() should always be called to check that the umem meets the page_size requirement. If there is a limited set of page_sizes that work it the pgsz_bitmap should be set to that set. 0 is a failure and the umem cannot be used. Lightly tidy the control flow to implement this flow properly. Signed-off-by: Jason Gunthorpe --- drivers/infiniband/hw/hns/hns_roce_mr.c | 49 ++++++++++--------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c index e5df3884b41dda..16699f6bb03a51 100644 --- a/drivers/infiniband/hw/hns/hns_roce_mr.c +++ b/drivers/infiniband/hw/hns/hns_roce_mr.c @@ -707,19 +707,6 @@ static inline size_t mtr_bufs_size(struct hns_roce_buf_attr *attr) return size; } -static inline int mtr_umem_page_count(struct ib_umem *umem, - unsigned int page_shift) -{ - int count = ib_umem_page_count(umem); - - if (page_shift >= PAGE_SHIFT) - count >>= page_shift - PAGE_SHIFT; - else - count <<= PAGE_SHIFT - page_shift; - - return count; -} - static inline size_t mtr_kmem_direct_size(bool is_direct, size_t alloc_size, unsigned int page_shift) { @@ -767,12 +754,10 @@ static int mtr_alloc_bufs(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, struct ib_udata *udata, unsigned long user_addr) { struct ib_device *ibdev = &hr_dev->ib_dev; - unsigned int max_pg_shift = buf_attr->page_shift; - unsigned int best_pg_shift = 0; + unsigned int best_pg_shift; int all_pg_count = 0; size_t direct_size; size_t total_size; - unsigned long tmp; int ret = 0; total_size = mtr_bufs_size(buf_attr); @@ -782,6 +767,9 @@ static int mtr_alloc_bufs(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, } if (udata) { + unsigned long pgsz_bitmap; + unsigned long page_size; + mtr->kmem = NULL; mtr->umem = ib_umem_get(ibdev, user_addr, total_size, buf_attr->user_access); @@ -790,15 +778,17 @@ static int mtr_alloc_bufs(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, PTR_ERR(mtr->umem)); return -ENOMEM; } - if (buf_attr->fixed_page) { - best_pg_shift = max_pg_shift; - } else { - tmp = GENMASK(max_pg_shift, 0); - ret = ib_umem_find_best_pgsz(mtr->umem, tmp, user_addr); - best_pg_shift = (ret <= PAGE_SIZE) ? - PAGE_SHIFT : ilog2(ret); - } - all_pg_count = mtr_umem_page_count(mtr->umem, best_pg_shift); + if (buf_attr->fixed_page) + pgsz_bitmap = 1 << buf_attr->page_shift; + else + pgsz_bitmap = GENMASK(buf_attr->page_shift, PAGE_SHIFT); + + page_size = ib_umem_find_best_pgsz(mtr->umem, pgsz_bitmap, + user_addr); + if (!page_size) + return -EINVAL; + best_pg_shift = order_base_2(page_size); + all_pg_count = ib_umem_num_dma_blocks(mtr->umem, page_size); ret = 0; } else { mtr->umem = NULL; @@ -808,16 +798,15 @@ static int mtr_alloc_bufs(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr, return -ENOMEM; } direct_size = mtr_kmem_direct_size(is_direct, total_size, - max_pg_shift); + buf_attr->page_shift); ret = hns_roce_buf_alloc(hr_dev, total_size, direct_size, - mtr->kmem, max_pg_shift); + mtr->kmem, buf_attr->page_shift); if (ret) { ibdev_err(ibdev, "Failed to alloc kmem, ret %d\n", ret); goto err_alloc_mem; - } else { - best_pg_shift = max_pg_shift; - all_pg_count = mtr->kmem->npages; } + best_pg_shift = buf_attr->page_shift; + all_pg_count = mtr->kmem->npages; } /* must bigger than minimum hardware page shift */ From patchwork Wed Sep 2 00:43:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749607 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 987F4739 for ; Wed, 2 Sep 2020 00:43:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 738F320707 for ; Wed, 2 Sep 2020 00:43:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="RIAe0BuZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726489AbgIBAn6 (ORCPT ); Tue, 1 Sep 2020 20:43:58 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:4716 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726622AbgIBAnu (ORCPT ); Tue, 1 Sep 2020 20:43:50 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 01 Sep 2020 17:43:36 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:50 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:43:50 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:49 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DQx4p0FXrKLHpsNfBJcEyPD9rWVisSE/rMTHOV847omWIygO5TN2DFdDOVDyDk53RpEpN5erOwbQNNk6djKw7zX0aU98Wusg/O53d6hMlM16YF0T0kX5HfGK0o4nDPR7uKikyT9cOMkPqsiUHi/SG+1JEwdiuAjIIR2Rpv37lf+HSchXHBRgciJUWWtjjHxQucE/o7Y9j0vy3S7cnfAtSW9ZofcGR/VI0W7rSF9A9d2xczaWuOtkPcK3dJvyHxzAoGzrYBCXIfB+zCbr46OoGw5OqhyvF4uvRn7skmmJUE/AhfzeWyEANubv1m1xym11q5jzcB3+NgKp8knzipuoww== 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-SenderADCheck; bh=I06pZmKJMjk8aO8cjmg3Cal0vlqXJMN5VF3cvapwauU=; b=PxPU2W2TdhrW3+gCqfr6822JgGeeCw34TY+tpdhmGWQHV6nnl1LqXu/qEZIDpbD86lNi/Nq01IBW5Ffy7OIXRZenC8JNoI92lrZUhYgl/BJiokzS9N4UTv46CMMEuAii82XYIRmiCjrnIo0JdgE+QJ4fuA9/REV/2XhVUVnVtIFeZ1gRrCVlIfVOjB9dxYP1ZzA+h//f8eeYkN8/G/z3clhCOawWOcd0jrtyTzbGZsQOah7BZ4TUc3Vd2l+/0/LyXJefdo08vajG9BUOZNT9mUXDtdRum7FVwalqLVONy9kq6/b+iU34JDRy+rXcUHshxgMFDHBziYkxk1x28STl9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: broadcom.com; dkim=none (message not signed) header.d=none;broadcom.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:48 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:48 +0000 From: Jason Gunthorpe To: Devesh Sharma , Doug Ledford , , Selvin Xavier Subject: [PATCH 11/14] RDMA/ocrdma: Use ib_umem_num_dma_blocks() instead of ib_umem_page_count() Date: Tue, 1 Sep 2020 21:43:39 -0300 Message-ID: <11-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR19CA0026.namprd19.prod.outlook.com (2603:10b6:208:178::39) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by MN2PR19CA0026.namprd19.prod.outlook.com (2603:10b6:208:178::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.20 via Frontend Transport; Wed, 2 Sep 2020 00:43:46 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsJ-005P1W-8V; Tue, 01 Sep 2020 21:43:43 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 320e5f57-e265-4fe3-05ee-08d84ed9402c X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ygbVhNaeHZi08IMAINT1DBgCLykPtQN1Mb7ml6b17bn0uitJ5L876O13lsGLP+/odVfxU9GZr9oNS15v4yEXXAZ/zfsuBxboIc/Z31/2NvU1jI96jxKwclj2oAoPps+bm1u2BMdq8J+UwIRfne2ePs/Ofs/76SgejYZxMwbe3TeB9reXY+hAC59HOA+cdeJd9McgZu0EESIgx6LayMxxRTWHz/Ub/TCh/lYzO0k5ft0Nhu0MlDHjDqhpJt/NNBVzRGFJ93tkTkOBvJ6K3JDE7wCF5Yc0VSMVNOeyjcq6WLTcdbV0Ef/oUBaLxjKn/eMyK4bN40fWdzvYIkbN7SyI4w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(6666004)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(110136005)(2906002)(36756003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: QPSnC8yH0gn4IZ4+AzyKAKLcHKso9Mrhl0MCkvf0Jvneg3jFZnIWODa1FH6HWnxxXahHWTuG0uFLNNpyOJt4J5/7UJN8HD/sdAUiyCm4jk9kiYcQP6XAFlDO7X+DKr7JWKzqzgL06oNFW5YeWxz75fQrPY082bQlgZPyrp92N+rdXgJmptZxD0nJN4LUkTmhjaJWLHy3EnO884mJpBo6hrLXN8GSVNuUzl/bRlv89jmOpTvZ8QnWxgZ0iDxQUrSl7DexM2muWqB+C6frIbx8KPZWhNfK8AVUt2amNXX26PphEflr1zPI22ENEqXLePgVyCqxdlghMIK2RWxcypvvQTq6uTg22aEtuDDiRitCSmz27suho0Nv4Qe5ncMwF/IiV/SIjt+NfpeZD2+TlGN0dMD2XMPYM/N+4YB9khDJW8Dvd308KYoPL/PUEiRfPVCUxSFCfGLuALEWUs1uSyNxKKTZXJ3lDIV0J7lzYq0eL26gE/Pe1RQ2K2hjZmqjmKRD9T9DvUs6xvV7vzqW23XlbEfBIWx/6NNjyiWCV6V6fLKwrj4g6bdcT5uEVMbTWKVfNfmPZ5KndEehqvN7WTP4GoOzOixfXOsi+++VEdv5npN7iZYvuZYSCBvNF+43tO/7yPxLWo4cMs3LEr9tMh12TQ== X-MS-Exchange-CrossTenant-Network-Message-Id: 320e5f57-e265-4fe3-05ee-08d84ed9402c X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:46.6440 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 99vjZEbaSAedefXYqowqTbCfO+xVd/ojz7zOY4WbQBvLc/6246tQDobKirLLw2um X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007416; bh=TX4gBUTPsysUkIr4WJSznIJcI3otuK3NY0secWOa/Yk=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:Subject: Date:Message-ID:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType:X-Originating-IP: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id: X-MS-TrafficTypeDiagnostic:X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers:X-MS-Exchange-SenderADCheck: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report:X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=RIAe0BuZcdHz5/pMqyCh0bFYryEBZt4v2ClYo73Boo4uz4kioN56wfJvRWsnM+1ik 1zI3LRzWWOj1uP9HCGf4ALLm8F82zR4BJ0WxtCXauSqvEQAIOdR+WvNRyzqCHYvHHo qVUM+rCxClx0ZSDeuwd0s/vWbH3Cv8Xc2DZ8tFZ90OqM7jEWpMWCMOJYPCTEd01Pg/ lROAxCewevPOaYHKHn2vESR3WwHs8pRhgCFf0FTkBG520NOuCTBOpMwGtrcpXqRA+W 3KxGTmzHJK03CDK1NCgjYZteNcFGwJ75Ji1ZAGw7ckMAS3xt1eLRQbRKEs6cwerlob GnDgn3TCyBR9g== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org This driver always uses a DMA array made up of PAGE_SIZE elements, so just use ib_umem_num_blocks(). Since rdma_for_each_dma_block() always iterates exactly ib_umem_num_dma_blocks() there is no need for the early exit check in build_user_pbes(), delete it. Signed-off-by: Jason Gunthorpe --- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c index 933b297de2ba86..1fb8da6d613674 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c @@ -810,13 +810,12 @@ static int ocrdma_build_pbl_tbl(struct ocrdma_dev *dev, struct ocrdma_hw_mr *mr) return status; } -static void build_user_pbes(struct ocrdma_dev *dev, struct ocrdma_mr *mr, - u32 num_pbes) +static void build_user_pbes(struct ocrdma_dev *dev, struct ocrdma_mr *mr) { struct ocrdma_pbe *pbe; struct ib_block_iter biter; struct ocrdma_pbl *pbl_tbl = mr->hwmr.pbl_table; - int pbe_cnt, total_num_pbes = 0; + int pbe_cnt; u64 pg_addr; if (!mr->hwmr.num_pbes) @@ -831,13 +830,8 @@ static void build_user_pbes(struct ocrdma_dev *dev, struct ocrdma_mr *mr, pbe->pa_lo = cpu_to_le32(pg_addr); pbe->pa_hi = cpu_to_le32(upper_32_bits(pg_addr)); pbe_cnt += 1; - total_num_pbes += 1; pbe++; - /* if done building pbes, issue the mbx cmd. */ - if (total_num_pbes == num_pbes) - return; - /* if the given pbl is full storing the pbes, * move to next pbl. */ @@ -856,7 +850,6 @@ struct ib_mr *ocrdma_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 len, struct ocrdma_dev *dev = get_ocrdma_dev(ibpd->device); struct ocrdma_mr *mr; struct ocrdma_pd *pd; - u32 num_pbes; pd = get_ocrdma_pd(ibpd); @@ -871,8 +864,8 @@ struct ib_mr *ocrdma_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 len, status = -EFAULT; goto umem_err; } - num_pbes = ib_umem_page_count(mr->umem); - status = ocrdma_get_pbl_info(dev, mr, num_pbes); + status = ocrdma_get_pbl_info( + dev, mr, ib_umem_num_dma_blocks(mr->umem, PAGE_SIZE)); if (status) goto umem_err; @@ -888,7 +881,7 @@ struct ib_mr *ocrdma_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 len, status = ocrdma_build_pbl_tbl(dev, &mr->hwmr); if (status) goto umem_err; - build_user_pbes(dev, mr, num_pbes); + build_user_pbes(dev, mr); status = ocrdma_reg_mr(dev, &mr->hwmr, pd->id, acc); if (status) goto mbx_err; From patchwork Wed Sep 2 00:43:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749605 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E942109B for ; Wed, 2 Sep 2020 00:43:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6215620707 for ; Wed, 2 Sep 2020 00:43:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="rqUrFau+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726312AbgIBAn5 (ORCPT ); Tue, 1 Sep 2020 20:43:57 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:19894 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726489AbgIBAnt (ORCPT ); Tue, 1 Sep 2020 20:43:49 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 01 Sep 2020 17:43:02 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:49 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:43:49 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:48 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SJB719uaebYCw8BqkNjQIpOQDaWfsCKZRw2BbYqLpcufIU/HR4r1AmJ60aLBG0UwDTkeLYKFwIXvWSq7BOaNOr2CyzuWRt7nqGY5r7gDkHG3L0G1qbxVEm24HplcLa4BT7/ZgsksgzqowhhCXqHaUyL7LxlKwy7W7NxVWT2Zi1z5pzVO5laDxplE+ne3jHGn+QxBcZSERyocjUe19Fn23gruj5OZwFgAx4LDJOIu66JA/BMTpoUpR8+J2X2s0X+UVNXx6imrKCpDej1tLACdOIur7JQcATNZ5ZGlQCYG28vcIrhbBi+4/J3bWS7/IsjCmucLTC1cqZS1IBRigFyI7Q== 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-SenderADCheck; bh=+Dn++izHGouDs5Cs8xCtu2rE36czqn7AL0Zwc4kUV6Q=; b=mAYupNPErL9llU0Y/RCC+eQfHtWLKRdd+QNg3MedcH1vI9XI6J3uxvuvV4MqBgogQYZJDxLseLNenS2ydnt6k0iAf1UiU32PsU9yTzaxMijqKJJ3BOFWUqdLKTqThzh4fuQsNrvO2HQLFrlLLnHYNUfo8dO0AqjE5eYkpIR0I/QVIXLm02Zy3aprZz92etvThI+o1WDcx6v5OoV5OoWIB2JS6BHhkEIxYUdAgkGguw5eojR9nzRky1Vv6bVcprkwPmSkzAczRknU+gvnMcm0j5iNUcONeGaerFIYTi+unrZRZsR4q1B4BvchdDx4UMmUuft/zRd8RFrXUhW3GUuIkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: vmware.com; dkim=none (message not signed) header.d=none;vmware.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:48 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:48 +0000 From: Jason Gunthorpe To: Adit Ranadive , Doug Ledford , , VMware PV-Drivers Subject: [PATCH 12/14] RDMA/pvrdma: Use ib_umem_num_dma_blocks() instead of ib_umem_page_count() Date: Tue, 1 Sep 2020 21:43:40 -0300 Message-ID: <12-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR19CA0026.namprd19.prod.outlook.com (2603:10b6:208:178::39) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by MN2PR19CA0026.namprd19.prod.outlook.com (2603:10b6:208:178::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.20 via Frontend Transport; Wed, 2 Sep 2020 00:43:46 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsJ-005P1a-9a; Tue, 01 Sep 2020 21:43:43 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: da4c6a26-172b-47e8-0ee4-08d84ed94028 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ECI74tg8ievgWd37HMYEh95trdkOYVuXaxvikoyKluPGs2gQOYD3NJCfq5wj+k62dfRLykMPvUlxTMBwPvCN3Q1a0JberMsqP1g5FanWoP69prxdp/36WKZu30nrDjqkBnGRWxjHcb+2YGnHq8JxdXqRsns8IzdeCj0Qhheq44M6n5QWnfq9jFLHOPBzZisoUQBIBHgW53312Vyr9So87KDuJiBIRl+RFogn3J8EGS3Wa9TEQga1Dc9BKbTe+wppKt0qq5gsXWTgYIlUNdjLWffqi5vxhf6uPsqNxfc4flvzwe5GttXd03APo5Yo5qe3zZ7J7U6HCfJ3M/5FVXmATw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(110136005)(2906002)(36756003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 7PeZbFNMMVm5eFJAJY3qnb0CqYpFl8VFVsjBZUw69SaBXveNjp4H6sDvrKcWoKaG0e8dOVzh1lF09BxUlI2L0m/lRT3X2h25y5Yl+b+zZwJB0y6gVyeHv86UJsil4dXwJBZRRKX4W/camEMEGJxuQd+jBbr5VOavx3yOak7L59YDsKX5DG9hZyY6iWgqQ+VqELczLEVZYmErYmnBdb+bu98ipNDR8642AT5QAVLwMG6F9bEGPZZiEieGWDn+WSbIrvk/MlY/C8/o6lqV6ZLsVWNs6hSNLNoKsGVhlJzlVmrQEjCkhIhiLflTrPaqekH5kewXKTi+VTYb92zkDLsFKtcu+buPNVLP/J7c9Qhoggdra0UxnVaZKC40dmR7miX0NDoPOMjW6iGdVp1mFAwR+scBSVIRY0WSnwiavP9JospvOP9uY6CWIdap0toyLOCWdgFVYuphwmOBC601aLkzU5uEVSN/uA+csmQ20HaQZNUh/ubjQDcaN0VQ4abzrog1rF5b+OKNBRu7LSk1UgZ6bF0BtJoeRtxzVIcSAKIhNwuOdIA4O+QWAlhsahJnsWLRdkZB7Zh0F2Ax0ALIAARSs184UFK2vTcx/h8HnSDvfW+MRuVoFaSd1CoWVmjkzMPX69SRiSKstniqnGg7qfkcsw== X-MS-Exchange-CrossTenant-Network-Message-Id: da4c6a26-172b-47e8-0ee4-08d84ed94028 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:46.6210 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cqqDTTA9ULrTTmeq0EBBtu3fEDKF59J13chUUnl2AuV099t6u1vzoL5EV1XA1MCN X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007382; bh=JZvu/USViSfOQ9PQd/NNfFOW1LUbomcaYRCUiZt1Dm4=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:Subject: Date:Message-ID:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType:X-Originating-IP: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id: X-MS-TrafficTypeDiagnostic:X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers:X-MS-Exchange-SenderADCheck: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report:X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=rqUrFau+iEt10cBSiWVJ6YVBxmjStcL3dhwV3ylWG52e1NWYzfuc8jnqoQwNk71jp pSIW/+lkmCmsysi+u4xIu+Xfvl38/hwd8psW6UIoWq3URsKRZGBre9U04u24MkHZI7 t0d4qO99juMEOGTp5HXcS/l5ADXPHWRLDs55GvwC3Cfv2JrrboaF6RDySZ705h2fEa CCK1rM965vJxRtMHfsrPpFEiQnV1XKEkHwCLM0j7z6vFn35bWOnY8bLNhpEdv5Z946 LI3MWk3YaliqsdqgZEp5jAUfFeAlLXFYnkzXtI4PFrd73XDKbN/Gr9KKY/O35kCZEH X5CIF67/YJ4TA== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org This driver always uses PAGE_SIZE. Signed-off-by: Jason Gunthorpe --- drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c | 2 +- drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c | 6 ++++-- drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c index 01cd122a8b692f..ad7dfababf1fe1 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_cq.c @@ -142,7 +142,7 @@ int pvrdma_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, goto err_cq; } - npages = ib_umem_page_count(cq->umem); + npages = ib_umem_num_dma_blocks(cq->umem, PAGE_SIZE); } else { /* One extra page for shared ring state */ npages = 1 + (entries * sizeof(struct pvrdma_cqe) + diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c index 9a8f2a9507be07..8a385acf6f0c42 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c @@ -298,9 +298,11 @@ struct ib_qp *pvrdma_create_qp(struct ib_pd *pd, goto err_qp; } - qp->npages_send = ib_umem_page_count(qp->sumem); + qp->npages_send = + ib_umem_num_dma_blocks(qp->sumem, PAGE_SIZE); if (!is_srq) - qp->npages_recv = ib_umem_page_count(qp->rumem); + qp->npages_recv = ib_umem_num_dma_blocks( + qp->rumem, PAGE_SIZE); else qp->npages_recv = 0; qp->npages = qp->npages_send + qp->npages_recv; diff --git a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c index f60a8e81bddddb..6fd843cff21e70 100644 --- a/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c +++ b/drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c @@ -152,7 +152,7 @@ int pvrdma_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init_attr, goto err_srq; } - srq->npages = ib_umem_page_count(srq->umem); + srq->npages = ib_umem_num_dma_blocks(srq->umem, PAGE_SIZE); if (srq->npages < 0 || srq->npages > PVRDMA_PAGE_DIR_MAX_PAGES) { dev_warn(&dev->pdev->dev, From patchwork Wed Sep 2 00:43:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749601 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FA7A109B for ; Wed, 2 Sep 2020 00:43:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8125220707 for ; Wed, 2 Sep 2020 00:43:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="E8OJTYEE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726226AbgIBAnz (ORCPT ); Tue, 1 Sep 2020 20:43:55 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:4702 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726174AbgIBAnr (ORCPT ); Tue, 1 Sep 2020 20:43:47 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 01 Sep 2020 17:43:33 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:43:47 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:43:47 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:46 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A6EAMY4YbcRoIdycxTkBaxA/XPAKmNxmJdl4Mn9G8OSxi9VkXpMBI1eJ6u7BPY/IMhIAzOKJjGvbBQYMsz+3FfALRM7hA33kQnEvZ42P/t7s26nXXBU/Sl/KYhXC/zGdDKlUAr6bVztx/BAE4dI0+50NTyyqQupyarkuJoCmgS15NfiWwEwh7cCw/NRcs/imAB2szoWIzUJyPAWC1W/3BCugRPKv5jXXyP5bW+gESkz0lXK/IfNWjiT0fQwOmbL7D6VMUDSpvnVM3H4hxgaS2Hj0m7dCURFfbpJuaboBl2fOYbkdYg2b5ulzW9ZWs3q1TCTt8vR3sdQQ2gsobHMFgQ== 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-SenderADCheck; bh=GWlwu5h/Hpbzo+YuKOPphOqPYXKBsn6BeIKELN7PbAw=; b=WjZ0X8inVwp9MFOr+j3UlyaBRSSH6I06yufjSXFUbY86uU5XQJcnFqPw2gYp5GzniZJURt8C3dN0EOQbsqzcRIXgCLW1PwaUd0PBdTQ/pvBeSFTCLH0vzlOfUsTub1b6NQQMQc29IPDe1o4Rrm2JciRVuq5SALwnzqtbD3j9PKa5ychsIPiFzYRQch6hguttATYsJd9Jzdvx5pRua5rBVJKlxB8ckevVNAKCKMi2q5lNMrQNEBXFbiOP4yijyxOaXgn1zdJXUybu6EJ1LaVkGJwIry+TSnurIYR5ySB7/aMGKMQH28scEPTYK6tvTtOyySWGOGty4TmKLjer3nCYUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:45 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:45 +0000 From: Jason Gunthorpe To: Doug Ledford , , Yishai Hadas Subject: [PATCH 13/14] RDMA/mlx5: Use ib_umem_num_dma_blocks() Date: Tue, 1 Sep 2020 21:43:41 -0300 Message-ID: <13-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0036.namprd15.prod.outlook.com (2603:10b6:207:17::49) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by BL0PR1501CA0036.namprd15.prod.outlook.com (2603:10b6:207:17::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 2 Sep 2020 00:43:44 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsJ-005P1e-AM; Tue, 01 Sep 2020 21:43:43 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5aee878e-298b-418c-080d-08d84ed93f0b X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1051; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mjf25/BhJq2BJzZUyCpNZgIGKS1xl2gu/C3q+G7nNovFkPdZu8x8/qPha51nLvX3tuenGwyDnfhdI/Xj7mPiLik8YM8KdI8UKRhXmew2iktnyLG3vApuw92JM2/88Ip66msOgYjYw16++W3zEGT/fIVXslD7T2xNLk4E1ZBEDo+7baCjOR8/GGpZOHZ5jA5LeJzhIXNAknwlOgfa1nOQa0JpfDcq4cISxU3sVGoxuLw23bN8aZuUZ8zhv5J7qfRTd8xuxrB9GECAQ1YEXNvEV4SKOSxDE7qwwCLSxHyUazyeuO80/iSiUrNJ6Gze4nk7QGbkO6ot4NOIJ+klHQojKQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(110136005)(2906002)(6636002)(36756003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: +uAsEtpZO00RxYkTlWpGGLc/qR2k07TH6/FGV0ZdvAFM/T6ia4CCYVkDgeHivpNUpl4wK/Vs6iIxk1YyUKr9nEX4aCdi5KiAnoM/BzJdda1VLnAnyncY8Ir5gJMz8aDEIBSm24DmGRoGDDD2vi7lU5OH5NpmsZb0FacJHTyaM3+T2wE5c9Y5BBUkPSmwwWragdsAJJk6mGS4UD+EtWV0uo44Jo2ODKWZlpmSeCVknyw0jIKCQ9ym+9Jb1P9B92dIzGdx3rP/5N6xHwycIIOj6tr/N8KN8SSvNgXrKThZJrCY6anv0tpvk7NOX+fs5LJ+utUBABTLTbEziExAD/x67jCzrBfTZ2O//5xMCDOFYy8WYGSZcwWsEdxk3KbWoKrCgpBRcav6PcF9454abXEtHRmTAPX98FwSkVzEkNE6SYVXQcCxz0h3DvX1OUDpclRLxYDyd+EhR0mwQEvc2Suqe68IpercVOlPiKym61sKgCsJwQugnqGbe9tQoFfBEBg4RSQNlkWo0kpO/zO2dljaOmJtYLsSZ3RCFv5R+YRcHKfYP6ldvUItEvVhB2czLEq9f1fRQp/bw310yhEP5pupbev577rVz1S8LfCrJVpd77gmPQRuU48Yy9CQAFUmeqd5ehd+AXc6JwiXMUAH0/TFMA== X-MS-Exchange-CrossTenant-Network-Message-Id: 5aee878e-298b-418c-080d-08d84ed93f0b X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:44.9380 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ev+h5TvDEA9G4sXz2JRARduKOsFRSWlLD+qopAHHDDg17VPjCGTsP+67U2WUvcCV X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007413; bh=w+DN43GNbyoUX+NTByLvYb4kdbJ93uF8IMUQLU6AW2w=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:Subject: Date:Message-ID:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType:X-Originating-IP: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id: X-MS-TrafficTypeDiagnostic:X-MS-Exchange-Transport-Forked: X-Microsoft-Antispam-PRVS:X-MS-Oob-TLC-OOBClassifiers: X-MS-Exchange-SenderADCheck:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=E8OJTYEE/nzK4B8+exFtQhfttjgX+K/P7trqbzBej5VbRdpk/NnGQRv+ZoQni5XKD xnGqHUmp+ujsDem6C0SkUuDgv1xAh3o5XOnWsEjZ2h9ACIjCH2E9rjyhWL1K759MyJ ZZCsDakJfyV9cyqgfYQxQy3D9+2XAwQ8h83Ltrgslj8Fulcq8y0h5WQl5lIYL39cue DbmOwCI9TPQoa9AAY2rdc6gyx0kmM3n7xYM1tBj9Y+i0qzQjmioa4CtDq/6q38P0YJ EPwLEp/iKh8IKjA57ILpRMYa/szMsdo44p1KttkDIvTphEhRDdaH9gvwIH9MbhJiiQ ghyR7BHcXSPSg== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org For the calls linked to mlx4_ib_umem_calc_optimal_mtt_size() compute the number of DMA pages directly based on the returned page_shift. This was just being used as a weird default if the algorithm hits the lower limit. All other places are just using it with PAGE_SIZE. As this is the last call site, remove ib_umem_num_pages(). Signed-off-by: Jason Gunthorpe --- drivers/infiniband/core/umem.c | 12 ------------ drivers/infiniband/hw/mlx4/cq.c | 8 ++++---- drivers/infiniband/hw/mlx4/mlx4_ib.h | 3 +-- drivers/infiniband/hw/mlx4/mr.c | 14 ++++++-------- drivers/infiniband/hw/mlx4/qp.c | 17 +++++++++-------- drivers/infiniband/hw/mlx4/srq.c | 5 +++-- include/rdma/ib_umem.h | 2 -- 7 files changed, 23 insertions(+), 38 deletions(-) diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index f02e34cac59581..49d6ddc37b6fde 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -346,18 +346,6 @@ void ib_umem_release(struct ib_umem *umem) } EXPORT_SYMBOL(ib_umem_release); -int ib_umem_page_count(struct ib_umem *umem) -{ - int i, n = 0; - struct scatterlist *sg; - - for_each_sg(umem->sg_head.sgl, sg, umem->nmap, i) - n += sg_dma_len(sg) >> PAGE_SHIFT; - - return n; -} -EXPORT_SYMBOL(ib_umem_page_count); - /* * Copy from the given ib_umem's pages to the given buffer. * diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c index 8a3436994f8097..3de97f428dc63b 100644 --- a/drivers/infiniband/hw/mlx4/cq.c +++ b/drivers/infiniband/hw/mlx4/cq.c @@ -142,16 +142,16 @@ static int mlx4_ib_get_cq_umem(struct mlx4_ib_dev *dev, struct ib_udata *udata, int err; int cqe_size = dev->dev->caps.cqe_size; int shift; - int n; *umem = ib_umem_get(&dev->ib_dev, buf_addr, cqe * cqe_size, IB_ACCESS_LOCAL_WRITE); if (IS_ERR(*umem)) return PTR_ERR(*umem); - n = ib_umem_page_count(*umem); - shift = mlx4_ib_umem_calc_optimal_mtt_size(*umem, 0, &n); - err = mlx4_mtt_init(dev->dev, n, shift, &buf->mtt); + shift = mlx4_ib_umem_calc_optimal_mtt_size(*umem, 0); + err = mlx4_mtt_init(dev->dev, + ib_umem_num_dma_blocks(*umem, 1UL << shift), shift, + &buf->mtt); if (err) goto err_buf; diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h index bcac8fc5031766..660955a11914e7 100644 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h @@ -905,7 +905,6 @@ struct ib_rwq_ind_table struct ib_rwq_ind_table_init_attr *init_attr, struct ib_udata *udata); int mlx4_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table); -int mlx4_ib_umem_calc_optimal_mtt_size(struct ib_umem *umem, u64 start_va, - int *num_of_mtts); +int mlx4_ib_umem_calc_optimal_mtt_size(struct ib_umem *umem, u64 start_va); #endif /* MLX4_IB_H */ diff --git a/drivers/infiniband/hw/mlx4/mr.c b/drivers/infiniband/hw/mlx4/mr.c index 1d5ef0de12c950..19b2d3fbe81e03 100644 --- a/drivers/infiniband/hw/mlx4/mr.c +++ b/drivers/infiniband/hw/mlx4/mr.c @@ -254,8 +254,7 @@ int mlx4_ib_umem_write_mtt(struct mlx4_ib_dev *dev, struct mlx4_mtt *mtt, * middle already handled as part of mtt shift calculation for both their start * & end addresses. */ -int mlx4_ib_umem_calc_optimal_mtt_size(struct ib_umem *umem, u64 start_va, - int *num_of_mtts) +int mlx4_ib_umem_calc_optimal_mtt_size(struct ib_umem *umem, u64 start_va) { u64 block_shift = MLX4_MAX_MTT_SHIFT; u64 min_shift = PAGE_SHIFT; @@ -353,7 +352,6 @@ int mlx4_ib_umem_calc_optimal_mtt_size(struct ib_umem *umem, u64 start_va, pr_warn("misaligned total length detected (%llu, %llu)!", total_len, block_shift); - *num_of_mtts = total_len >> block_shift; end: if (block_shift < min_shift) { /* @@ -409,7 +407,6 @@ struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, struct mlx4_ib_mr *mr; int shift; int err; - int n; mr = kzalloc(sizeof(*mr), GFP_KERNEL); if (!mr) @@ -421,11 +418,12 @@ struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, goto err_free; } - n = ib_umem_page_count(mr->umem); - shift = mlx4_ib_umem_calc_optimal_mtt_size(mr->umem, start, &n); + shift = mlx4_ib_umem_calc_optimal_mtt_size(mr->umem, start); err = mlx4_mr_alloc(dev->dev, to_mpd(pd)->pdn, virt_addr, length, - convert_access(access_flags), n, shift, &mr->mmr); + convert_access(access_flags), + ib_umem_num_dma_blocks(mr->umem, 1UL << shift), + shift, &mr->mmr); if (err) goto err_umem; @@ -511,7 +509,7 @@ int mlx4_ib_rereg_user_mr(struct ib_mr *mr, int flags, mmr->umem = NULL; goto release_mpt_entry; } - n = ib_umem_page_count(mmr->umem); + n = ib_umem_num_dma_blocks(mmr->umem, PAGE_SIZE); shift = PAGE_SHIFT; err = mlx4_mr_rereg_mem_write(dev->dev, &mmr->mmr, diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c index 2975f350b9fd10..3113d9ca112771 100644 --- a/drivers/infiniband/hw/mlx4/qp.c +++ b/drivers/infiniband/hw/mlx4/qp.c @@ -869,7 +869,6 @@ static int create_rq(struct ib_pd *pd, struct ib_qp_init_attr *init_attr, struct mlx4_ib_create_wq wq; size_t copy_len; int shift; - int n; qp->mlx4_ib_qp_type = MLX4_IB_QPT_RAW_PACKET; @@ -922,9 +921,10 @@ static int create_rq(struct ib_pd *pd, struct ib_qp_init_attr *init_attr, goto err; } - n = ib_umem_page_count(qp->umem); - shift = mlx4_ib_umem_calc_optimal_mtt_size(qp->umem, 0, &n); - err = mlx4_mtt_init(dev->dev, n, shift, &qp->mtt); + shift = mlx4_ib_umem_calc_optimal_mtt_size(qp->umem, 0); + err = mlx4_mtt_init(dev->dev, + ib_umem_num_dma_blocks(qp->umem, 1UL << shift), + shift, &qp->mtt); if (err) goto err_buf; @@ -1077,7 +1077,6 @@ static int create_qp_common(struct ib_pd *pd, struct ib_qp_init_attr *init_attr, struct mlx4_ib_create_qp ucmd; size_t copy_len; int shift; - int n; copy_len = sizeof(struct mlx4_ib_create_qp); @@ -1117,9 +1116,11 @@ static int create_qp_common(struct ib_pd *pd, struct ib_qp_init_attr *init_attr, goto err; } - n = ib_umem_page_count(qp->umem); - shift = mlx4_ib_umem_calc_optimal_mtt_size(qp->umem, 0, &n); - err = mlx4_mtt_init(dev->dev, n, shift, &qp->mtt); + shift = mlx4_ib_umem_calc_optimal_mtt_size(qp->umem, 0); + err = mlx4_mtt_init(dev->dev, + ib_umem_num_dma_blocks(qp->umem, + 1UL << shift), + shift, &qp->mtt); if (err) goto err_buf; diff --git a/drivers/infiniband/hw/mlx4/srq.c b/drivers/infiniband/hw/mlx4/srq.c index 8f9d5035142d33..108b2d0118d064 100644 --- a/drivers/infiniband/hw/mlx4/srq.c +++ b/drivers/infiniband/hw/mlx4/srq.c @@ -115,8 +115,9 @@ int mlx4_ib_create_srq(struct ib_srq *ib_srq, if (IS_ERR(srq->umem)) return PTR_ERR(srq->umem); - err = mlx4_mtt_init(dev->dev, ib_umem_page_count(srq->umem), - PAGE_SHIFT, &srq->mtt); + err = mlx4_mtt_init( + dev->dev, ib_umem_num_dma_blocks(srq->umem, PAGE_SIZE), + PAGE_SHIFT, &srq->mtt); if (err) goto err_buf; diff --git a/include/rdma/ib_umem.h b/include/rdma/ib_umem.h index ba3b9be0d8c56a..4bac6e29f030c2 100644 --- a/include/rdma/ib_umem.h +++ b/include/rdma/ib_umem.h @@ -73,7 +73,6 @@ static inline void __rdma_umem_block_iter_start(struct ib_block_iter *biter, struct ib_umem *ib_umem_get(struct ib_device *device, unsigned long addr, size_t size, int access); void ib_umem_release(struct ib_umem *umem); -int ib_umem_page_count(struct ib_umem *umem); int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset, size_t length); unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem, @@ -91,7 +90,6 @@ static inline struct ib_umem *ib_umem_get(struct ib_device *device, return ERR_PTR(-EINVAL); } static inline void ib_umem_release(struct ib_umem *umem) { } -static inline int ib_umem_page_count(struct ib_umem *umem) { return 0; } static inline int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset, size_t length) { return -EINVAL; From patchwork Wed Sep 2 00:43:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11749623 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9EE32739 for ; Wed, 2 Sep 2020 00:44:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E02820707 for ; Wed, 2 Sep 2020 00:44:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="c1D1VKlr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726814AbgIBAoP (ORCPT ); Tue, 1 Sep 2020 20:44:15 -0400 Received: from nat-hk.nvidia.com ([203.18.50.4]:14272 "EHLO nat-hk.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726107AbgIBAoI (ORCPT ); Tue, 1 Sep 2020 20:44:08 -0400 Received: from hkpgpgate101.nvidia.com (Not Verified[10.18.92.77]) by nat-hk.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 02 Sep 2020 08:44:04 +0800 Received: from HKMAIL103.nvidia.com ([10.18.16.12]) by hkpgpgate101.nvidia.com (PGP Universal service); Tue, 01 Sep 2020 17:44:04 -0700 X-PGP-Universal: processed; by hkpgpgate101.nvidia.com on Tue, 01 Sep 2020 17:44:04 -0700 Received: from HKMAIL102.nvidia.com (10.18.16.11) by HKMAIL103.nvidia.com (10.18.16.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 2 Sep 2020 00:43:50 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.172) by HKMAIL102.nvidia.com (10.18.16.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 2 Sep 2020 00:43:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YwW3xPUktR709nNg7UvmtEhtlTtdg1gDSm5dJ62OJGHL+oWJRZb6cRu3+61HjKGlFcosgl1Vk9rIZab8SIPqlZLNoVyR4Hpl0MvncMaHu+RCNriGKwNR5AbILoKhGMRRgKzyTZEqfjj8VHXf9bjtJrpQwBTwh7IndfZNBtoRVYcAaVMgAcpQ0i9E8pCoioXKYsVvbCD1Qfbz8FAdT/gqWFgJdYHMB3hrLxlPAGzEPudIItJLCFKz6KgbJy+AYe2xzJcAuI/Vp9rG9t5GAh0IsHwOHAS1LbzVi9nTi8jTslLcX9ciqT30Gupkn6x/hfE4a5WdrLmD81A7/NLb7JcuxA== 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-SenderADCheck; bh=1xd7J3ytyr84NpsCDV99kItcCsLrl1/4KM+yHHz1ysk=; b=f3//d5DW6ccAAtXHDMOoL+FeaYQ7QKZ9CmH5ZOEV9VvvcOd8TMKjWDzvkU+vgUHNfOzsxxmPFayUepJ0C1xnVntL7gPxIF4YOT6uWVk1OlLHX+4GMykfshIkOUThuR4Zz3+XkhJ5227ymjaf2S56XiXW20YRIujL+7RgcUCq5UlLr74iUSrVOWZaIU+HO1ihGVLxWiDqwlo3Kq0DusCrGrOndIECeyCOmUUyv7IQLtJwsja/mHJIqfXcyry6zJUuY2Qx712lx9TKVz6Y5lJdAXGZsjqN9trBHzdrp4/DaZoDXZ8Sd62Gd8DYqBFBm17+ZuaslF9Td/79WTwiGbjoyQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none Authentication-Results: marvell.com; dkim=none (message not signed) header.d=none;marvell.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.23; Wed, 2 Sep 2020 00:43:48 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::2d79:7f96:6406:6c76%3]) with mapi id 15.20.3326.025; Wed, 2 Sep 2020 00:43:48 +0000 From: Jason Gunthorpe To: Ariel Elior , Dennis Dalessandro , Devesh Sharma , Doug Ledford , , "Mike Marciniszyn" , Michal Kalderon , Selvin Xavier , "Zhu Yanjun" Subject: [PATCH 14/14] RDMA/umem: Rename ib_umem_offset() to ib_umem_dma_offset() Date: Tue, 1 Sep 2020 21:43:42 -0300 Message-ID: <14-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> In-Reply-To: <0-v1-00f59ce24f1f+19f50-umem_1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0029.namprd15.prod.outlook.com (2603:10b6:207:17::42) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by BL0PR1501CA0029.namprd15.prod.outlook.com (2603:10b6:207:17::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Wed, 2 Sep 2020 00:43:47 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kDGsJ-005P1j-C7; Tue, 01 Sep 2020 21:43:43 -0300 X-Originating-IP: [156.34.48.30] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 75e07d74-a39a-4dcb-cf48-08d84ed94092 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1148; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CIKfdwoIq3PEaOCSDP5uDVnr957b23NvBIcFlBFLJ5iBsQr4P/7tbYPGlStKUl1tEqG7yxaAZ6ehOHpjEBBURVWTFPW7iMaxaEpZt72V3JOoj5zU9pEUrJJ5w3MtsATgG13D72VSPgPWASjULglyFDNd5LAHqrdeir8k+3fPl5hPbQLu+IFotvizjmwHuW8TMbeWNJHd0k7FIyZ0di07/QvT/+6QkAccENoYb3tGpVCRGfaQuU9g2wwkADucil/Acad4GyeqwwAfkoFx8O7+bsoXmgy5OJ9tyYzFc+74uJMBOhXJjdEfac+89eSXqboGeWekATDEhPGyrbuwqnzLsg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(396003)(346002)(136003)(366004)(8936002)(26005)(86362001)(426003)(8676002)(9746002)(9786002)(2616005)(186003)(83380400001)(66556008)(66476007)(316002)(478600001)(66946007)(110136005)(2906002)(6636002)(36756003)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: +qccY3+lReE1M6DacgFifRHQNl15Lrt/e81ozHR+3I9oGQ7WF0vl4oy9nHhSqrWa9r1k+jeD5DlAdfRTNb9pOiWo4oUQ3oizxdsJqUir+90N1CD7F+fImMHMDJCW3c+71Xom46DKOCJGGJmekWe//DuKPZykXPtANoXeIfsmfV5KgaG//etrQykoVK2Z+qO/YXO2R1r/0lH2fIHsyVweCV5BoZYRTbXL/qLMDOV1qmBpZDHyXueMZPsMfLYj9N8LL1zy2r1hSUqPAVRnN0eCXF7oFgm+CsytddyDBxrDthL6rgb1MqI5DiasyaeTN7FZQNWiPc2+lzWKvEatgPa3Wzs7sGCnYcAhwwIT12fGHz9WIPN0OXVXg1y1RpTiNJNQALeWwoFAa8TJs+HcKanpepQHNnKC6e8MVX0VNp5SaTeTANG1UC5xTqE8ipAujZLxeoQ/0fip5OEAFnETdsXSFsdkkyN831K2QVumJQ8FsA7SCSduxtJZAc9Xb5xoeC234wYYU1X4FJARohX0g5o1i5mmX7oPSL+3Dtky/1LYpw13+aMjl5n/9EnI5vo2MlpOnMDI51p8iwl7kZG/kTJmtGj5t4RsEqkBQCUR6oAamQ41kiw8cHQutoMepJQbtaDqhc1uMnbtV+gD6y4f2bPRyw== X-MS-Exchange-CrossTenant-Network-Message-Id: 75e07d74-a39a-4dcb-cf48-08d84ed94092 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 00:43:47.3556 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YoDSswzwDa6ieCtpC19m56M0aCKGHexN727/ZDsZYqMIJoqC12MRpqk6fsrhAOab X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1599007444; bh=2Sluy/UhJJF7J5SkPmaAkVXOV8+mAhplUY9Fa74y4NU=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:Authentication-Results:From:To:Subject: Date:Message-ID:In-Reply-To:References:Content-Transfer-Encoding: Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-Exchange-MessageSentRepresentingType:X-Originating-IP: X-MS-PublicTrafficType:X-MS-Office365-Filtering-Correlation-Id: X-MS-TrafficTypeDiagnostic:X-MS-Exchange-Transport-Forked: X-Microsoft-Antispam-PRVS:X-MS-Oob-TLC-OOBClassifiers: X-MS-Exchange-SenderADCheck:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource: X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; b=c1D1VKlr8H9jfjWPUe0Ej36ZyrZ4poONSmWryMbjL1+kyip+fVXI0OekF6a0/X4LN aE1MLs/zJ/3Ypj11KG2HZmzhvyd2S+sPwtgESxvvvYn35MPrOWweqSi71irMzfp5F6 7fOYJ0Jt+9Y/dd7oqGiUEkrwhXPe6LPg/c/wiJPr6u9fQ8eLGgt1b5HtU4xy8X5poQ ffDJLe/leAg4+dHER6iD4Q7Icj0GtvRzGhdHyn/DbHIvhPVT6CtheHcF0oRnAna7hm lroBr41CwY8x8yJvyzQMYS2NhfBSPciN7o9/fXkXGctESbPQUZogQFdfYSTHUQMxvU 7Rv03CTL/SoPA== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org This function should be used to get the offset from the first DMA block. The few places using this without a DMA iterator are calling it to work around the lack of setting sgl->offset when the umem is created. Signed-off-by: Jason Gunthorpe Acked-by: Michal KalderonĀ  --- drivers/infiniband/core/umem.c | 2 +- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 2 +- drivers/infiniband/hw/qedr/verbs.c | 2 +- drivers/infiniband/sw/rdmavt/mr.c | 2 +- drivers/infiniband/sw/rxe/rxe_mr.c | 2 +- include/rdma/ib_umem.h | 9 ++++++--- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index 49d6ddc37b6fde..c840115b8c0945 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -369,7 +369,7 @@ int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset, } ret = sg_pcopy_to_buffer(umem->sg_head.sgl, umem->sg_nents, dst, length, - offset + ib_umem_offset(umem)); + offset + ib_umem_dma_offset(umem, PAGE_SIZE)); if (ret < 0) return ret; diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c index 1fb8da6d613674..f22532fbc364fe 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c @@ -870,7 +870,7 @@ struct ib_mr *ocrdma_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 len, goto umem_err; mr->hwmr.pbe_size = PAGE_SIZE; - mr->hwmr.fbo = ib_umem_offset(mr->umem); + mr->hwmr.fbo = ib_umem_dma_offset(mr->umem, PAGE_SIZE); mr->hwmr.va = usr_addr; mr->hwmr.len = len; mr->hwmr.remote_wr = (acc & IB_ACCESS_REMOTE_WRITE) ? 1 : 0; diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c index 278b48443aedba..daac742e71044d 100644 --- a/drivers/infiniband/hw/qedr/verbs.c +++ b/drivers/infiniband/hw/qedr/verbs.c @@ -2878,7 +2878,7 @@ struct ib_mr *qedr_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 len, mr->hw_mr.pbl_two_level = mr->info.pbl_info.two_layered; mr->hw_mr.pbl_page_size_log = ilog2(mr->info.pbl_info.pbl_size); mr->hw_mr.page_size_log = PAGE_SHIFT; - mr->hw_mr.fbo = ib_umem_offset(mr->umem); + mr->hw_mr.fbo = ib_umem_dma_offset(mr->umem, PAGE_SIZE); mr->hw_mr.length = len; mr->hw_mr.vaddr = usr_addr; mr->hw_mr.zbva = false; diff --git a/drivers/infiniband/sw/rdmavt/mr.c b/drivers/infiniband/sw/rdmavt/mr.c index 2f7c25fea44a9d..04f7dc0ce9e44d 100644 --- a/drivers/infiniband/sw/rdmavt/mr.c +++ b/drivers/infiniband/sw/rdmavt/mr.c @@ -404,7 +404,7 @@ struct ib_mr *rvt_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, mr->mr.user_base = start; mr->mr.iova = virt_addr; mr->mr.length = length; - mr->mr.offset = ib_umem_offset(umem); + mr->mr.offset = ib_umem_dma_offset(umem, PAGE_SIZE); mr->mr.access_flags = mr_access_flags; mr->umem = umem; diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index 708e2dff5eaa70..8f60dc9dee8658 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -196,7 +196,7 @@ int rxe_mem_init_user(struct rxe_pd *pd, u64 start, mem->length = length; mem->iova = iova; mem->va = start; - mem->offset = ib_umem_offset(umem); + mem->offset = ib_umem_dma_offset(umem, PAGE_SIZE); mem->state = RXE_MEM_STATE_VALID; mem->type = RXE_MEM_TYPE_MR; diff --git a/include/rdma/ib_umem.h b/include/rdma/ib_umem.h index 4bac6e29f030c2..5e709b2c251644 100644 --- a/include/rdma/ib_umem.h +++ b/include/rdma/ib_umem.h @@ -27,10 +27,13 @@ struct ib_umem { unsigned int sg_nents; }; -/* Returns the offset of the umem start relative to the first page. */ -static inline int ib_umem_offset(struct ib_umem *umem) +/* + * Returns the offset of the umem start relative to the first DMA block returned + * by rdma_umem_for_each_dma_block(). + */ +static inline int ib_umem_dma_offset(struct ib_umem *umem, unsigned long pgsz) { - return umem->address & ~PAGE_MASK; + return umem->address & (pgsz - 1); } static inline size_t ib_umem_num_dma_blocks(struct ib_umem *umem,