From patchwork Fri Nov 3 09:55:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhijian X-Patchwork-Id: 13444436 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9256DC4167D for ; Fri, 3 Nov 2023 09:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347536AbjKCJ4M (ORCPT ); Fri, 3 Nov 2023 05:56:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347502AbjKCJ4K (ORCPT ); Fri, 3 Nov 2023 05:56:10 -0400 Received: from esa10.hc1455-7.c3s2.iphmx.com (esa10.hc1455-7.c3s2.iphmx.com [139.138.36.225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B3FAD6D; Fri, 3 Nov 2023 02:56:02 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="126169479" X-IronPort-AV: E=Sophos;i="6.03,273,1694703600"; d="scan'208";a="126169479" Received: from unknown (HELO oym-r3.gw.nic.fujitsu.com) ([210.162.30.91]) by esa10.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 18:56:00 +0900 Received: from oym-m4.gw.nic.fujitsu.com (oym-nat-oym-m4.gw.nic.fujitsu.com [192.168.87.61]) by oym-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id 44DB1D6475; Fri, 3 Nov 2023 18:55:58 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by oym-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 35AB1D52C1; Fri, 3 Nov 2023 18:55:57 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id BA5C51EB1D5; Fri, 3 Nov 2023 18:55:56 +0900 (JST) Received: from FNSTPC.g08.fujitsu.local (unknown [10.167.226.45]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 3779B1A0072; Fri, 3 Nov 2023 17:55:56 +0800 (CST) From: Li Zhijian To: zyjzyj2000@gmail.com, jgg@ziepe.ca, leon@kernel.org, linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rpearsonhpe@gmail.com, matsuda-daisuke@fujitsu.com, bvanassche@acm.org, yi.zhang@redhat.com, Li Zhijian Subject: [PATCH RFC V2 1/6] RDMA/rxe: RDMA/rxe: don't allow registering !PAGE_SIZE mr Date: Fri, 3 Nov 2023 17:55:44 +0800 Message-ID: <20231103095549.490744-2-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231103095549.490744-1-lizhijian@fujitsu.com> References: <20231103095549.490744-1-lizhijian@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-27974.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-27974.006 X-TMASE-Result: 10--4.672600-10.000000 X-TMASE-MatchedRID: rDfjNDBkNcOMCPk/lvFUOt9JA2lmQRNU2FA7wK9mP9cRt1EvyOXA0dyQ dWCH/YgKQZCd2iT0MflsOacVUHP+r+W5YZxMb7aKGqSG/c50XgOaDC/RGGCVV5LFwf1lbHnIgK6 qCGa1Z9fDzSde0I1kYIAy6p60ZV62G2i4y8P2xXndB/CxWTRRu+rAZ8KTspSzxtaprLqF3ntFDM BLjwF3v4FTBTx0LGJ0Spt5K+Tfxbm4lv7CWjd+M51xKvhXp79eP+XouMjD7/vMOuUN/hZxXilzw 1xveMciIcmnZRhVxyrE4HwnSlEuHInEpJmLAFfpC1FNc6oqYVV+3BndfXUhXQ== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org rxe_set_page() only store one PAGE_SIZE page by the step of page_size. when page_size != PAGE_SIZE, we cannot restore the address with wrong index and page_offset. Let's take a look how current the xarray is being used. 0. offset = iova & (page_size -1); // offset is less than page_size but may not PAGE_SIZE 1. index = (iova - mr.iova) >> page_shift; 2. page = xa_load(&mr->page_list, index); 3. page_va = kmap_local_page(page) // map one page only, that means only memory [page_va, page_va + PAGE_SIZE) is valid for this mapping. 4. memcpy(addr, page_va + offset, bytes); - when page_size > PAGE_SIZE, the offset could be beyond PAGE_SIZE, then page_va + offset may be invalid. - when page_size < PAGE_SIZE, the offset may get lost. Note that this patch will break some ULPs that try to register 4K MR when PAGE_SIZE is not 4K. SRP and nvme over RXE is known to be impacted. Signed-off-by: Li Zhijian --- --- drivers/infiniband/sw/rxe/rxe_mr.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index f54042e9aeb2..3755e530e6dc 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -234,6 +234,12 @@ int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sgl, struct rxe_mr *mr = to_rmr(ibmr); unsigned int page_size = mr_page_size(mr); + if (page_size != PAGE_SIZE) { + rxe_err_mr(mr, "Unsupport mr page size %x, expect PAGE_SIZE(%lx)\n", + page_size, PAGE_SIZE); + return -EINVAL; + } + mr->nbuf = 0; mr->page_shift = ilog2(page_size); mr->page_mask = ~((u64)page_size - 1); From patchwork Fri Nov 3 09:55:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhijian X-Patchwork-Id: 13444437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12F23C001B0 for ; Fri, 3 Nov 2023 09:56:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347580AbjKCJ4R (ORCPT ); Fri, 3 Nov 2023 05:56:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347605AbjKCJ4P (ORCPT ); Fri, 3 Nov 2023 05:56:15 -0400 Received: from esa2.hc1455-7.c3s2.iphmx.com (esa2.hc1455-7.c3s2.iphmx.com [207.54.90.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FE40D70; Fri, 3 Nov 2023 02:56:02 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="138469456" X-IronPort-AV: E=Sophos;i="6.03,273,1694703600"; d="scan'208";a="138469456" Received: from unknown (HELO yto-r4.gw.nic.fujitsu.com) ([218.44.52.220]) by esa2.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 18:56:01 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 762B7D3EAC; Fri, 3 Nov 2023 18:55:58 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id A9C5AC4A16; Fri, 3 Nov 2023 18:55:57 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id 348F9E36BA; Fri, 3 Nov 2023 18:55:57 +0900 (JST) Received: from FNSTPC.g08.fujitsu.local (unknown [10.167.226.45]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 9ABBE1A006F; Fri, 3 Nov 2023 17:55:56 +0800 (CST) From: Li Zhijian To: zyjzyj2000@gmail.com, jgg@ziepe.ca, leon@kernel.org, linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rpearsonhpe@gmail.com, matsuda-daisuke@fujitsu.com, bvanassche@acm.org, yi.zhang@redhat.com, Li Zhijian Subject: [PATCH RFC V2 2/6] RDMA/rxe: set RXE_PAGE_SIZE_CAP to PAGE_SIZE Date: Fri, 3 Nov 2023 17:55:45 +0800 Message-ID: <20231103095549.490744-3-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231103095549.490744-1-lizhijian@fujitsu.com> References: <20231103095549.490744-1-lizhijian@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-27974.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-27974.006 X-TMASE-Result: 10--5.753700-10.000000 X-TMASE-MatchedRID: S8AxUE03d7BTorztX3wKRAmyVrMCuJ9SwTlc9CcHMZerwqxtE531VCzy bVqWyY2ND+LZhHM9RwrRpRbL7Yjxh7QIlEvYJcRNfa4B0jQGGeoogaQhRNNEvpsoi2XrUn/J8m+ hzBStanvIM9mETCO70yAHAopEd76veDyIM8J5kE2z4CsjXTAQJnU5kupDVrVP2Pzvl4G8qgDM1X RxVNdnKQ== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org RXE_PAGE_SIZE_CAP means the MR page size supported by RXE. However in current RXE implementation, only PAGE_SIZE MR works well. So change it to PAGE_SIZE only. ULPs such as SRP calculating the page size according to this attribute get worked again with this change. Signed-off-by: Li Zhijian --- drivers/infiniband/sw/rxe/rxe_param.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/sw/rxe/rxe_param.h b/drivers/infiniband/sw/rxe/rxe_param.h index d2f57ead78ad..b1cf1e1c0ce1 100644 --- a/drivers/infiniband/sw/rxe/rxe_param.h +++ b/drivers/infiniband/sw/rxe/rxe_param.h @@ -38,7 +38,7 @@ static inline enum ib_mtu eth_mtu_int_to_enum(int mtu) /* default/initial rxe device parameter settings */ enum rxe_device_param { RXE_MAX_MR_SIZE = -1ull, - RXE_PAGE_SIZE_CAP = 0xfffff000, + RXE_PAGE_SIZE_CAP = PAGE_SIZE, RXE_MAX_QP_WR = DEFAULT_MAX_VALUE, RXE_DEVICE_CAP_FLAGS = IB_DEVICE_BAD_PKEY_CNTR | IB_DEVICE_BAD_QKEY_CNTR From patchwork Fri Nov 3 09:55:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhijian X-Patchwork-Id: 13444438 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24273C0018A for ; Fri, 3 Nov 2023 09:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347491AbjKCJ4N (ORCPT ); Fri, 3 Nov 2023 05:56:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347526AbjKCJ4M (ORCPT ); Fri, 3 Nov 2023 05:56:12 -0400 Received: from esa12.hc1455-7.c3s2.iphmx.com (esa12.hc1455-7.c3s2.iphmx.com [139.138.37.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7485D77; Fri, 3 Nov 2023 02:56:03 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="117864670" X-IronPort-AV: E=Sophos;i="6.03,273,1694703600"; d="scan'208";a="117864670" Received: from unknown (HELO oym-r3.gw.nic.fujitsu.com) ([210.162.30.91]) by esa12.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 18:56:00 +0900 Received: from oym-m4.gw.nic.fujitsu.com (oym-nat-oym-m4.gw.nic.fujitsu.com [192.168.87.61]) by oym-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id D783ED6475; Fri, 3 Nov 2023 18:55:58 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by oym-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 0EFF8D5D15; Fri, 3 Nov 2023 18:55:58 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id A4D3B200501B1; Fri, 3 Nov 2023 18:55:57 +0900 (JST) Received: from FNSTPC.g08.fujitsu.local (unknown [10.167.226.45]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 15FD81A0072; Fri, 3 Nov 2023 17:55:57 +0800 (CST) From: Li Zhijian To: zyjzyj2000@gmail.com, jgg@ziepe.ca, leon@kernel.org, linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rpearsonhpe@gmail.com, matsuda-daisuke@fujitsu.com, bvanassche@acm.org, yi.zhang@redhat.com, Li Zhijian Subject: [PATCH RFC V2 3/6] RDMA/rxe: remove unused rxe_mr.page_shift Date: Fri, 3 Nov 2023 17:55:46 +0800 Message-ID: <20231103095549.490744-4-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231103095549.490744-1-lizhijian@fujitsu.com> References: <20231103095549.490744-1-lizhijian@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-27974.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-27974.006 X-TMASE-Result: 10--2.244700-10.000000 X-TMASE-MatchedRID: 6q73Zcfo6Jq1UOlz1sLXchF4zyLyne+ATJDl9FKHbrlCw17cr3HRB+K5 fhRxt1aA92kNXgH07FbsbC/Vw6Dhkx8TzIzimOwP/hxxPCwzUoPEQdG7H66TyHEqm8QYBtMOZsY Fy96KWWKZqgH/izpwuaKHvyV1Zkh/LCZafsjE5s7ah7Q7AITJYLpgs6aeGU9hk8OVAzuAhGHiC9 thELD2+yGkZFGhX/A+W4wbpXTb5DJKKve1kh3RY37qSWrndbmQn0bOriG5BVc= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org it's assigned but never used. Signed-off-by: Li Zhijian --- drivers/infiniband/sw/rxe/rxe_mr.c | 1 - drivers/infiniband/sw/rxe/rxe_verbs.h | 1 - 2 files changed, 2 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index 3755e530e6dc..bbfedcd8d2cb 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -243,7 +243,6 @@ int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sgl, mr->nbuf = 0; mr->page_shift = ilog2(page_size); mr->page_mask = ~((u64)page_size - 1); - mr->page_offset = mr->ibmr.iova & (page_size - 1); return ib_sg_to_pages(ibmr, sgl, sg_nents, sg_offset, rxe_set_page); } diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h index ccb9d19ffe8a..11647e976282 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.h +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h @@ -309,7 +309,6 @@ struct rxe_mr { int access; atomic_t num_mw; - unsigned int page_offset; unsigned int page_shift; u64 page_mask; From patchwork Fri Nov 3 09:55:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhijian X-Patchwork-Id: 13444445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B7C3C4332F for ; Fri, 3 Nov 2023 09:57:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347478AbjKCJ55 (ORCPT ); Fri, 3 Nov 2023 05:57:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347425AbjKCJ54 (ORCPT ); Fri, 3 Nov 2023 05:57:56 -0400 X-Greylist: delayed 64 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 03 Nov 2023 02:57:09 PDT Received: from esa5.hc1455-7.c3s2.iphmx.com (esa5.hc1455-7.c3s2.iphmx.com [68.232.139.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38BE719BC; Fri, 3 Nov 2023 02:57:08 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="137953602" X-IronPort-AV: E=Sophos;i="6.03,273,1694703600"; d="scan'208";a="137953602" Received: from unknown (HELO yto-r4.gw.nic.fujitsu.com) ([218.44.52.220]) by esa5.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 18:56:02 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 5147ED3EAC; Fri, 3 Nov 2023 18:55:59 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 817E7C8BFE; Fri, 3 Nov 2023 18:55:58 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id 15438E5E53; Fri, 3 Nov 2023 18:55:58 +0900 (JST) Received: from FNSTPC.g08.fujitsu.local (unknown [10.167.226.45]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 83B731A006F; Fri, 3 Nov 2023 17:55:57 +0800 (CST) From: Li Zhijian To: zyjzyj2000@gmail.com, jgg@ziepe.ca, leon@kernel.org, linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rpearsonhpe@gmail.com, matsuda-daisuke@fujitsu.com, bvanassche@acm.org, yi.zhang@redhat.com, Li Zhijian Subject: [PATCH RFC V2 4/6] RDMA/rxe: Use PAGE_SIZE and PAGE_SHIFT to extract address from page_list Date: Fri, 3 Nov 2023 17:55:47 +0800 Message-ID: <20231103095549.490744-5-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231103095549.490744-1-lizhijian@fujitsu.com> References: <20231103095549.490744-1-lizhijian@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-27974.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-27974.006 X-TMASE-Result: 10--5.509000-10.000000 X-TMASE-MatchedRID: VULvqRy0JHoHl9LdO3B7p4Olbll4OMtkyiKgKtIyB4qe38zXnNg9Q2ZY /RdXrUKNkAkq19PK0vC12HagvbwDji/7QU2czuUNA9lly13c/gFb4dXBMpIkhqoDeu6wu7bqE0o 8W+GU3zCqyptwK2nPv7Qj8USEuwVGZSqIGAn5t/jknMSTG9lH+MZiegX8JN5lmyiLZetSf8mfop 0ytGwvXiq2rl3dzGQ1dQgZJSoREhTm9DV/P8jWkbzOOaYWQHGCZ3g1SwoJbflW8/kkz9GZ0g== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org As we said in previous commit, page_list only stores PAGE_SIZE page, so when we extract an address from the page_list, we should use PAGE_SIZE and PAGE_SHIFT instead of the ibmr.page_size. Signed-off-by: Li Zhijian --- drivers/infiniband/sw/rxe/rxe_mr.c | 42 +++++++++------------------ drivers/infiniband/sw/rxe/rxe_verbs.h | 5 ---- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index bbfedcd8d2cb..d39c02f0c51e 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -72,16 +72,6 @@ void rxe_mr_init_dma(int access, struct rxe_mr *mr) mr->ibmr.type = IB_MR_TYPE_DMA; } -static unsigned long rxe_mr_iova_to_index(struct rxe_mr *mr, u64 iova) -{ - return (iova >> mr->page_shift) - (mr->ibmr.iova >> mr->page_shift); -} - -static unsigned long rxe_mr_iova_to_page_offset(struct rxe_mr *mr, u64 iova) -{ - return iova & (mr_page_size(mr) - 1); -} - static bool is_pmem_page(struct page *pg) { unsigned long paddr = page_to_phys(pg); @@ -232,17 +222,16 @@ int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sgl, int sg_nents, unsigned int *sg_offset) { struct rxe_mr *mr = to_rmr(ibmr); - unsigned int page_size = mr_page_size(mr); - if (page_size != PAGE_SIZE) { + if (ibmr->page_size != PAGE_SIZE) { rxe_err_mr(mr, "Unsupport mr page size %x, expect PAGE_SIZE(%lx)\n", - page_size, PAGE_SIZE); + ibmr->page_size, PAGE_SIZE); return -EINVAL; } mr->nbuf = 0; - mr->page_shift = ilog2(page_size); - mr->page_mask = ~((u64)page_size - 1); + mr->page_shift = PAGE_SHIFT; + mr->page_mask = PAGE_MASK; return ib_sg_to_pages(ibmr, sgl, sg_nents, sg_offset, rxe_set_page); } @@ -250,8 +239,8 @@ int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sgl, static int rxe_mr_copy_xarray(struct rxe_mr *mr, u64 iova, void *addr, unsigned int length, enum rxe_mr_copy_dir dir) { - unsigned int page_offset = rxe_mr_iova_to_page_offset(mr, iova); - unsigned long index = rxe_mr_iova_to_index(mr, iova); + unsigned int page_offset = iova & (PAGE_SIZE - 1); + unsigned long index = (iova - mr->ibmr.iova) >> PAGE_SHIFT; unsigned int bytes; struct page *page; void *va; @@ -261,8 +250,7 @@ static int rxe_mr_copy_xarray(struct rxe_mr *mr, u64 iova, void *addr, if (!page) return -EFAULT; - bytes = min_t(unsigned int, length, - mr_page_size(mr) - page_offset); + bytes = min_t(unsigned int, length, PAGE_SIZE - page_offset); va = kmap_local_page(page); if (dir == RXE_FROM_MR_OBJ) memcpy(addr, va + page_offset, bytes); @@ -450,14 +438,12 @@ int rxe_flush_pmem_iova(struct rxe_mr *mr, u64 iova, unsigned int length) return err; while (length > 0) { - index = rxe_mr_iova_to_index(mr, iova); + index = (iova - mr->ibmr.iova) >> PAGE_SHIFT; page = xa_load(&mr->page_list, index); - page_offset = rxe_mr_iova_to_page_offset(mr, iova); + page_offset = iova & (PAGE_SIZE - 1); if (!page) return -EFAULT; - bytes = min_t(unsigned int, length, - mr_page_size(mr) - page_offset); - + bytes = min_t(unsigned int, length, PAGE_SIZE - page_offset); va = kmap_local_page(page); arch_wb_cache_pmem(va + page_offset, bytes); kunmap_local(va); @@ -498,8 +484,8 @@ int rxe_mr_do_atomic_op(struct rxe_mr *mr, u64 iova, int opcode, rxe_dbg_mr(mr, "iova out of range"); return RESPST_ERR_RKEY_VIOLATION; } - page_offset = rxe_mr_iova_to_page_offset(mr, iova); - index = rxe_mr_iova_to_index(mr, iova); + page_offset = iova & (PAGE_SIZE - 1); + index = (iova - mr->ibmr.iova) >> PAGE_SHIFT; page = xa_load(&mr->page_list, index); if (!page) return RESPST_ERR_RKEY_VIOLATION; @@ -556,8 +542,8 @@ int rxe_mr_do_atomic_write(struct rxe_mr *mr, u64 iova, u64 value) rxe_dbg_mr(mr, "iova out of range"); return RESPST_ERR_RKEY_VIOLATION; } - page_offset = rxe_mr_iova_to_page_offset(mr, iova); - index = rxe_mr_iova_to_index(mr, iova); + page_offset = iova & (PAGE_SIZE - 1); + index = (iova - mr->ibmr.iova) >> PAGE_SHIFT; page = xa_load(&mr->page_list, index); if (!page) return RESPST_ERR_RKEY_VIOLATION; diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h index 11647e976282..ccc75f8c0985 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.h +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h @@ -318,11 +318,6 @@ struct rxe_mr { struct xarray page_list; }; -static inline unsigned int mr_page_size(struct rxe_mr *mr) -{ - return mr ? mr->ibmr.page_size : PAGE_SIZE; -} - enum rxe_mw_state { RXE_MW_STATE_INVALID = RXE_MR_STATE_INVALID, RXE_MW_STATE_FREE = RXE_MR_STATE_FREE, From patchwork Fri Nov 3 09:55:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhijian X-Patchwork-Id: 13444439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5A67C4167B for ; Fri, 3 Nov 2023 09:56:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347671AbjKCJ41 (ORCPT ); Fri, 3 Nov 2023 05:56:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347655AbjKCJ4S (ORCPT ); Fri, 3 Nov 2023 05:56:18 -0400 Received: from esa1.hc1455-7.c3s2.iphmx.com (esa1.hc1455-7.c3s2.iphmx.com [207.54.90.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47B6D10C4; Fri, 3 Nov 2023 02:56:04 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="138283629" X-IronPort-AV: E=Sophos;i="6.03,273,1694703600"; d="scan'208";a="138283629" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa1.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 18:56:02 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id C0533D6186; Fri, 3 Nov 2023 18:55:59 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 0C0FEC4A00; Fri, 3 Nov 2023 18:55:59 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id 8905F2005019A; Fri, 3 Nov 2023 18:55:58 +0900 (JST) Received: from FNSTPC.g08.fujitsu.local (unknown [10.167.226.45]) by edo.cn.fujitsu.com (Postfix) with ESMTP id E97941A0072; Fri, 3 Nov 2023 17:55:57 +0800 (CST) From: Li Zhijian To: zyjzyj2000@gmail.com, jgg@ziepe.ca, leon@kernel.org, linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rpearsonhpe@gmail.com, matsuda-daisuke@fujitsu.com, bvanassche@acm.org, yi.zhang@redhat.com, Li Zhijian Subject: [PATCH RFC V2 5/6] RDMA/rxe: cleanup rxe_mr.{page_size,page_shift} Date: Fri, 3 Nov 2023 17:55:48 +0800 Message-ID: <20231103095549.490744-6-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231103095549.490744-1-lizhijian@fujitsu.com> References: <20231103095549.490744-1-lizhijian@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-27974.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-27974.006 X-TMASE-Result: 10--2.085100-10.000000 X-TMASE-MatchedRID: 4vuDYoAhWgkEAXVIFoPmpMfIK2dgWYWGCZa9cSpBObnAuQ0xDMaXkH4q tYI9sRE/lTJXKqh1ne2XNWQa4uM6kJcFdomgH0lnFEUknJ/kEl5lVdRvgpNpe/oLR4+zsDTtuVf c976pNypHlescvaZnOWnt3jHkT+4bhPISvaLQ542U/6gnt9otdY9p61D8mgeNW27Gp3VFEiCpMY 9k1M7dHstkdSYjBYPP5H+vESxOZUGGk+xUaqdMDwHEKwHwYevbwUSxXh+jiUgkww/gwY7hMA== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org This 2 elements were believed to be designed for extracting address from the page_list before. But now we use PAGE_SIZE and PAGE_SHIFT directly, so we can drop it. Signed-off-by: Li Zhijian --- drivers/infiniband/sw/rxe/rxe_mr.c | 4 ---- drivers/infiniband/sw/rxe/rxe_verbs.h | 3 --- 2 files changed, 7 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index d39c02f0c51e..a038133e1322 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -59,8 +59,6 @@ static void rxe_mr_init(int access, struct rxe_mr *mr) mr->access = access; mr->ibmr.page_size = PAGE_SIZE; - mr->page_mask = PAGE_MASK; - mr->page_shift = PAGE_SHIFT; mr->state = RXE_MR_STATE_INVALID; } @@ -230,8 +228,6 @@ int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sgl, } mr->nbuf = 0; - mr->page_shift = PAGE_SHIFT; - mr->page_mask = PAGE_MASK; return ib_sg_to_pages(ibmr, sgl, sg_nents, sg_offset, rxe_set_page); } diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h index ccc75f8c0985..ef813560b0ab 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.h +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h @@ -309,9 +309,6 @@ struct rxe_mr { int access; atomic_t num_mw; - unsigned int page_shift; - u64 page_mask; - u32 num_buf; u32 nbuf; From patchwork Fri Nov 3 09:55:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhijian X-Patchwork-Id: 13444446 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECA15C4332F for ; Fri, 3 Nov 2023 09:58:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347549AbjKCJ62 (ORCPT ); Fri, 3 Nov 2023 05:58:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347612AbjKCJ61 (ORCPT ); Fri, 3 Nov 2023 05:58:27 -0400 Received: from esa5.hc1455-7.c3s2.iphmx.com (esa5.hc1455-7.c3s2.iphmx.com [68.232.139.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4119D71; Fri, 3 Nov 2023 02:57:55 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="137953603" X-IronPort-AV: E=Sophos;i="6.03,273,1694703600"; d="scan'208";a="137953603" Received: from unknown (HELO oym-r4.gw.nic.fujitsu.com) ([210.162.30.92]) by esa5.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 18:56:03 +0900 Received: from oym-m1.gw.nic.fujitsu.com (oym-nat-oym-m1.gw.nic.fujitsu.com [192.168.87.58]) by oym-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 31184D9D8F; Fri, 3 Nov 2023 18:56:00 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by oym-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 5CBB5D88D6; Fri, 3 Nov 2023 18:55:59 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id DB3F4200501B0; Fri, 3 Nov 2023 18:55:58 +0900 (JST) Received: from FNSTPC.g08.fujitsu.local (unknown [10.167.226.45]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 597851A006F; Fri, 3 Nov 2023 17:55:58 +0800 (CST) From: Li Zhijian To: zyjzyj2000@gmail.com, jgg@ziepe.ca, leon@kernel.org, linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rpearsonhpe@gmail.com, matsuda-daisuke@fujitsu.com, bvanassche@acm.org, yi.zhang@redhat.com, Li Zhijian Subject: [PATCH RFC V2 6/6] RDMA/rxe: Support PAGE_SIZE aligned MR Date: Fri, 3 Nov 2023 17:55:49 +0800 Message-ID: <20231103095549.490744-7-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231103095549.490744-1-lizhijian@fujitsu.com> References: <20231103095549.490744-1-lizhijian@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-27974.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-27974.006 X-TMASE-Result: 10--3.626700-10.000000 X-TMASE-MatchedRID: uf8KE2NGjd9Bt63ZJXZ1oU7nLUqYrlslFIuBIWrdOePfUZT83lbkEFI6 c0LB6zRTgnKDgRN2gHJJNhitn2ZCFKimPM07Al9SnXdphQTSK/IO4jfa+nI3P5soi2XrUn/Jn6K dMrRsL14qtq5d3cxkNUZzh5+urigLQuzJLcC9/jgLiXnACqUA9wm53Cjx6YN5yPyw704COky5J1 x/8WkKqRoeB7ARQTeWvE7sDZ3+mHhXOEE2otkM4RiKAP5Y7TkhFcUQf3Yp/ridO0/GUi4gFb0fO PzpgdcEKeJ/HkAZ8Is= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org In order to support PAGE_SIZE aligned MR, rxe_map_mr_sg() should be able to split a large buffer to N * page entry into the xarray page_list. Signed-off-by: Li Zhijian --- drivers/infiniband/sw/rxe/rxe_mr.c | 39 +++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index a038133e1322..3761740af986 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -193,9 +193,8 @@ int rxe_mr_init_fast(int max_pages, struct rxe_mr *mr) return err; } -static int rxe_set_page(struct ib_mr *ibmr, u64 dma_addr) +static int rxe_store_page(struct rxe_mr *mr, u64 dma_addr) { - struct rxe_mr *mr = to_rmr(ibmr); struct page *page = ib_virt_dma_to_page(dma_addr); bool persistent = !!(mr->access & IB_ACCESS_FLUSH_PERSISTENT); int err; @@ -216,20 +215,48 @@ static int rxe_set_page(struct ib_mr *ibmr, u64 dma_addr) return 0; } +static int rxe_set_page(struct ib_mr *base_mr, u64 buf_addr) +{ + return 0; +} + int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sgl, - int sg_nents, unsigned int *sg_offset) + int sg_nents, unsigned int *sg_offset_p) { struct rxe_mr *mr = to_rmr(ibmr); + struct scatterlist *sg; + unsigned int sg_offset = sg_offset_p ? *sg_offset_p : 0; + int i; - if (ibmr->page_size != PAGE_SIZE) { - rxe_err_mr(mr, "Unsupport mr page size %x, expect PAGE_SIZE(%lx)\n", + if (!IS_ALIGNED(ibmr->page_size, PAGE_SIZE)) { + rxe_err_mr(mr, "Misaligned page size %x, expect PAGE_SIZE(%lx) aligned\n", ibmr->page_size, PAGE_SIZE); return -EINVAL; } mr->nbuf = 0; - return ib_sg_to_pages(ibmr, sgl, sg_nents, sg_offset, rxe_set_page); + for_each_sg(sgl, sg, sg_nents, i) { + u64 dma_addr = sg_dma_address(sg) + sg_offset; + unsigned int dma_len = sg_dma_len(sg) - sg_offset; + u64 end_dma_addr = dma_addr + dma_len; + u64 page_addr = dma_addr & PAGE_MASK; + + if (sg_dma_len(sg) == 0) { + rxe_dbg_mr(mr, "empty SGE\n"); + return -EINVAL; + } + do { + int ret = rxe_store_page(mr, page_addr); + if (ret) + return ret; + + page_addr += PAGE_SIZE; + } while (page_addr < end_dma_addr); + sg_offset = 0; + } + + return ib_sg_to_pages(ibmr, sgl, sg_nents, sg_offset_p, rxe_set_page); } static int rxe_mr_copy_xarray(struct rxe_mr *mr, u64 iova, void *addr,