From patchwork Fri Nov 11 04:30:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhijian Li (Fujitsu)" X-Patchwork-Id: 18452 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp535961wru; Thu, 10 Nov 2022 20:33:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf432Y89dktPKLF2UmQTBqL02evT6KX49DkDRqtoV691stZVMjdPagstk0dXSFfJICGZF91w X-Received: by 2002:a63:1720:0:b0:46f:f93b:ddc8 with SMTP id x32-20020a631720000000b0046ff93bddc8mr84815pgl.389.1668141220203; Thu, 10 Nov 2022 20:33:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668141220; cv=none; d=google.com; s=arc-20160816; b=PhkUTss1B/D1Shq4a9zI/FjzOYXNeffwIT9MRGRaxaWoQPxvQDndNfPntmFzD/Jays jsm58dah+w/JKl6GKKacI4JrPfmdS9BMxlhTyB4YV3moYBQ2JdOVB7zAoJ24NrjxeP6/ oJ9OMCWrz1oPdDU43+8IdC/oerlxHXf0UNyouE/TQ5F5hcxgRhYXpAdOiL3c7CNCaRZV yKVWTQHVVg2xPk6s9jUchYLiRBr+2PIYQHeYjATC4EaYbiJaIiREbBuDBEv5X8qpN94v 4sZhevdzusBrO7MvQC2LyLZJnQkIEImWOAe2nRRXWIa9nNugZFIAB7W8wiLDW1qDXB5g cYJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=t3W7ccYeAWOB7TN9rQwLcUW5c4OzST5kRuF91e5+TEI=; b=ms3+FOUlNqHljgeG8b/Asg5D/x0+jSrSb15wUbs6qHR2TeHI+mmZw+xRNZAjivenr4 pnuAKS1VMeB+aznByfIG7gsHa7SOe4dn2thPat9lKO6lcE/F9MJyDMQiaYcYLRvnDkT5 LMzgvfT0qGMix9xuxoz4/23PFQ4ZeVVm1ikU6DWQhj8s83/C+fVbaE45zjusEoB8Yd3C NyN374xKczRrXB79sNQL34QBqtrEmCbZL3bsxob6cSKqvQnj3DEPmeo68004a1PyzW5m PZ6rx9f7Rgo8qdkwj0gKAla5gbvaKztpQOcBhUuNYCFGR/dkMY11/5rCVJe8LDzJp54H EZCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fujitsu.com header.s=170520fj header.b=w+eLUlGx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a12-20020a63cd4c000000b00442e77a852dsi1185311pgj.509.2022.11.10.20.33.27; Thu, 10 Nov 2022 20:33:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@fujitsu.com header.s=170520fj header.b=w+eLUlGx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232231AbiKKEbD (ORCPT + 99 others); Thu, 10 Nov 2022 23:31:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232343AbiKKEa7 (ORCPT ); Thu, 10 Nov 2022 23:30:59 -0500 Received: from mail1.bemta34.messagelabs.com (mail1.bemta34.messagelabs.com [195.245.231.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC82F68AE6; Thu, 10 Nov 2022 20:30:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1668141053; i=@fujitsu.com; bh=t3W7ccYeAWOB7TN9rQwLcUW5c4OzST5kRuF91e5+TEI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=w+eLUlGxhp3aQOon3jqrxU1B0Pvb0BSHUPchD8TxSSUUF0t6GUk6cyBM47nhJkanb SFoBFZIA8AZrwRWNUtzLBZygLjyzTkiN32FpF84hzFUXZd/uB9IFbPJ7Yg3N0AiIhN +ul9fkq7sBLYigtcBT3FZbK5BxI7VFBcQ2CIxPBFZ8KNsmA9umBOab6jg1bUqZaz8J ALf8R4vGeUAjL4AzoC+q2baJ6nDkWqoNu9CNCh6i8RWw5MqoeWCnEptrCC2XVxz/C1 HhA6bqXFF57/z66htCiJ/FFeb0ED5vhVG4Xc5/Yjf5xitZ9l0EaJlM6KmGvP5TD1CN wVZqSPxcX0kWQ== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOIsWRWlGSWpSXmKPExsViZ8MxSffP+dx kg+tP1S1mzjjBaDHl11Jmi8u75rBZPDvUy2Jx/lg/uwOrx85Zd9k9Nq3qZPP4vEnOY+vn2ywB LFGsmXlJ+RUJrBlrW34wFfQJVPy8UtrAeJuni5GLQ0hgC6PE/YbjLBDOciaJ419ms0I4Bxgll jx5y97FyMnBJqAhca/lJiOILSLQySixrTUNxGYWcJPY9GY2WI2wQLTE+euzWUBsFgFViROnX7 OB2LwCjhJ3G3Yxg9gSAgoSUx6+B7M5BZwklt/5AlYjBFRzauYdFoh6QYmTM5+wQMyXkDj44gV QPQdQr5LEzO54iDEVErNmtTFB2GoSV89tYp7AKDgLSfcsJN0LGJlWMZoVpxaVpRbpGlroJRVl pmeU5CZm5uglVukm6qWW6panFpfoGukllhfrpRYX6xVX5ibnpOjlpZZsYgSGf0qx+skdjBuW/ dE7xCjJwaQkyrvPJjdZiC8pP6UyI7E4I76oNCe1+BCjDAeHkgSv3lmgnGBRanpqRVpmDjAWYd ISHDxKIrzC24HSvMUFibnFmekQqVOMilLivFbACBYSAElklObBtcHi/xKjrJQwLyMDA4MQT0F qUW5mCar8K0ZxDkYlYd64c0BTeDLzSuCmvwJazAS02C41C2RxSSJCSqqBySVfN4OXib/7kLwc cxvDPO8DwmyfX/84dmp6Zlx88bmFi3feFlj3Lqvv7u/7+yw7ksw7P+aVnHacsuyzz7tZfT0Sz e/Pc+yWi3zy+dCfg39Oaev5fQp+c0m3SeG8vM/i1Pw1/84qhZt5Tyn0LX5jGi5rU7zfm+1Fhk nw3YXt4pP5XF5dWpf0ouvxMxO/NWYzC3J/PKvLcFP+52DXevLLtJkLv64/uyjTNGjzS97+G2/ ktScuFrp3LENCddnTgLM5uzl/dE1hOTizs+cQr+r8lTOqbupcCp8oPmP5Oq0gjjU/NrlsF8lJ 1l5+/8F7i1vn2S4Wp7IKXHTOMP96W3w/z+xHb39yZc5beaXni4lTzEUlluKMREMt5qLiRAA2f es1egMAAA== X-Env-Sender: lizhijian@fujitsu.com X-Msg-Ref: server-20.tower-548.messagelabs.com!1668141052!16817!1 X-Originating-IP: [62.60.8.146] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.100.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9145 invoked from network); 11 Nov 2022 04:30:52 -0000 Received: from unknown (HELO n03ukasimr02.n03.fujitsu.local) (62.60.8.146) by server-20.tower-548.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Nov 2022 04:30:52 -0000 Received: from n03ukasimr02.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr02.n03.fujitsu.local (Postfix) with ESMTP id 56B2C1000D5; Fri, 11 Nov 2022 04:30:52 +0000 (GMT) Received: from R01UKEXCASM126.r01.fujitsu.local (R01UKEXCASM126 [10.183.43.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr02.n03.fujitsu.local (Postfix) with ESMTPS id 49A7A1000C1; Fri, 11 Nov 2022 04:30:52 +0000 (GMT) Received: from bc0da1a9c27e.localdomain (10.167.225.141) by R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 11 Nov 2022 04:30:49 +0000 From: Li Zhijian To: Zhu Yanjun , Jason Gunthorpe , "Leon Romanovsky" , CC: , Li Zhijian Subject: [for-next PATCH 2/5] RDMA/rxe: use iova_to_vaddr to transform iova for rxe_mr_copy Date: Fri, 11 Nov 2022 04:30:27 +0000 Message-ID: <1668141030-2-3-git-send-email-lizhijian@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1668141030-2-1-git-send-email-lizhijian@fujitsu.com> References: <1668141030-2-1-git-send-email-lizhijian@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.225.141] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749172848127649790?= X-GMAIL-MSGID: =?utf-8?q?1749172848127649790?= Make the code more friendly and readable by using iova_to_vaddr() This commit also remove the err1 label in rxe_mr_copy(). Signed-off-by: Li Zhijian --- drivers/infiniband/sw/rxe/rxe_mr.c | 46 +++++++++--------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index f6366a635b92..cf3ce8d293b3 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -289,13 +289,6 @@ void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length) int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length, enum rxe_mr_copy_dir dir) { - int err; - int bytes; - u8 *va; - struct rxe_map **map; - struct rxe_phys_buf *buf; - int m; - int i; size_t offset; if (length == 0) @@ -315,49 +308,36 @@ int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length, WARN_ON_ONCE(!mr->map); - err = mr_check_range(mr, iova, length); - if (err) { - err = -EFAULT; - goto err1; - } - - lookup_iova(mr, iova, &m, &i, &offset); - - map = mr->map + m; - buf = map[0]->buf + i; + if (mr_check_range(mr, iova, length)) + return -EFAULT; + offset = (iova - mr->ibmr.iova + mr->offset) & mr->page_mask; while (length > 0) { - u8 *src, *dest; - - va = (u8 *)(uintptr_t)buf->addr + offset; - src = (dir == RXE_TO_MR_OBJ) ? addr : va; - dest = (dir == RXE_TO_MR_OBJ) ? va : addr; + u8 *src, *dest, *va; + int bytes; bytes = mr->ibmr.page_size - offset; if (bytes > length) bytes = length; + va = iova_to_vaddr(mr, iova, bytes); + if (!va) + return -EFAULT; + + src = (dir == RXE_TO_MR_OBJ) ? addr : va; + dest = (dir == RXE_TO_MR_OBJ) ? va : addr; + memcpy(dest, src, bytes); length -= bytes; addr += bytes; + iova += bytes; offset = 0; - buf++; - i++; - - if (i == RXE_BUF_PER_MAP) { - i = 0; - map++; - buf = map[0]->buf; - } } return 0; - -err1: - return err; } /* copy data in or out of a wqe, i.e. sg list