From patchwork Fri Nov 11 04:30:28 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: 18455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp536418wru; Thu, 10 Nov 2022 20:35:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf5CmKZeNPQoHztmL8DPafcrNlfKp724yCuFHP7Lsecrax34qOnLaI6vgtsXgWWMIgE0Y1lp X-Received: by 2002:a17:907:8b0d:b0:78d:857d:b4a8 with SMTP id sz13-20020a1709078b0d00b0078d857db4a8mr468976ejc.495.1668141301425; Thu, 10 Nov 2022 20:35:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668141301; cv=none; d=google.com; s=arc-20160816; b=HvQOk+TYK+dFtQXCmjBZJ8e9LKX92KCV4b/JSvpqL1TYFP3dCneu+8CoZYb1iVuDrv t6l8sXg4uAsL7DswELWeoPVrTdyYrrqhbU8jdX4jEfaOrh6B6WbktiXgyA0kpOO5qTz/ kxHWaZl2euz/MZpSaTskA2kGBhcMmDZT+Z671Ns7fx8aMkDVk9cULdwpExuxdk78zNWd mdbuSNUKx6XQFwfn/MK9WtSe6QcfUcsK/cm2ie3DowrDKZYWAfbC6HnxqjDjNUEnfA+m 3faid+BKVeRHrhB1NogrzL1P5eOtEDJpJXU40Kxl2E6jMcLVZYAF9RBPtKB3taJG/iK6 OsTw== 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=YDhoYW+eXCKjvdTLBizlFrYt3TOUamkuYfdivtZaMMk=; b=1I+oiMnDtzTckxwhX0A0y90mn2QPj8rf5xubgSw7qEejApI8Mi3gt30Wfd1WxnY86B y38YLHjDrP4kByrXL3lAa+E09Kfb8/BD5/P1FtJGlJmN9LeoBEXLY7+Mon5daE0c/9dm v3jdvLfWX3nOqbrHLzeV43OKZVI3yn2AYfmNcDWYUEQXJ2Td/G7OxryY4bIcwzC2WvjX Sbz1VmMvS13mx+xOX+B7A5HUVYmnY8eT97k9b9AH2b2xQKKPeB1DsSzBUB6OXPS+9NFh 99nFLCPYS/WMWS3lhcFXmHQqP8T7oqQu5VHlnJ6T4sC8BBWwy8vfIB9tZb6fhg1t+BgT elLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fujitsu.com header.s=170520fj header.b=hVgtHvu6; 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 dt6-20020a170907728600b0078200f886bbsi1192595ejc.361.2022.11.10.20.34.14; Thu, 10 Nov 2022 20:35:01 -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=hVgtHvu6; 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 S232645AbiKKEbH (ORCPT + 99 others); Thu, 10 Nov 2022 23:31:07 -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 S232511AbiKKEbA (ORCPT ); Thu, 10 Nov 2022 23:31:00 -0500 Received: from mail1.bemta34.messagelabs.com (mail1.bemta34.messagelabs.com [195.245.231.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 339FB68AD9; Thu, 10 Nov 2022 20:30:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1668141056; i=@fujitsu.com; bh=YDhoYW+eXCKjvdTLBizlFrYt3TOUamkuYfdivtZaMMk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hVgtHvu6W1bvlIX3kfc2RL3uBP9LP032+foxXnX+egnZEj99xx+ylI7Dh5btleSmC 6wCjdm4bLdzk5bH5wcEAOecZNVXE1Tlh0Lt9B3942wrP0LPBhBjrUCgAeuBfEYgSpr 6e6FQa796VAW3anwijJyMc4lFmxvJsCKPGa3XYLx47Nwd8XkRnx96k2u81wvwvR5Jt UfQV+o/L7Ysh3vg8FeojYdbeML2dbWUz0oGURpib8REx2x1LJDT9MUmbU3pRZEQQYX 3ctWpHM0iM7flJMbXldi0EtpVbiPRqz7fAYnUObDyKAwx6Lc2CTRUa91J8gjmRFyuD +S9Rfye8kcJkA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrGIsWRWlGSWpSXmKPExsViZ8ORqPv/fG6 ywcXjKhYzZ5xgtJjyaymzxeVdc9gsnh3qZbE4f6yf3YHVY+esu+wem1Z1snl83iTnsfXzbZYA lijWzLyk/IoE1ozmybOYCx7wVix7up+pgXE7dxcjF4eQwBZGicfHNjN2MXICOcuZJP6uC4NIH GCUWLv3DFiCTUBD4l7LTTBbRKCTUWJbaxqIzSzgJrHpzWx2EFtYwFaiZ845MJtFQFVi79lXTF 2MHBy8Ao4SX96Xg4QlBBQkpjx8zwxicwo4SSy/84UNYq+jxKmZd1hAbF4BQYmTM5+wQIyXkDj 44gUzyBgJASWJmd3xEGMqJGbNamOCsNUkrp7bxDyBUXAWku5ZSLoXMDKtYjQrTi0qSy3SNTTU SyrKTM8oyU3MzNFLrNJN1Est1S1PLS7RNdJLLC/WSy0u1iuuzE3OSdHLSy3ZxAgM/pRitYAdj B+X/dE7xCjJwaQkyrvPJjdZiC8pP6UyI7E4I76oNCe1+BCjDAeHkgSv3lmgnGBRanpqRVpmDj ASYdISHDxKIrzC24HSvMUFibnFmekQqVOMilLivFbA+BUSAElklObBtcGi/xKjrJQwLyMDA4M QT0FqUW5mCar8K0ZxDkYlYd64c0BTeDLzSuCmvwJazAS02C41C2RxSSJCSqqBqZjpbv6Dna8m JFmGz4lqnSgrppl+r9Nw6jLVjWvDjuYu8OOOO1epVMjvJFrZmX+I8UZrbWXGmXDVF8yHfK/7n nkceNQ7Y0PEkkX+v1cdjmWNnvxiwZODWy1PtnHca1nCaSX2del1hdRHKRMf/NklorU1SKJ6Ee +cbdObhKbn/uGecUax6fGDczFqZk8zXYoubjPbW55kveCL4+Izk/OrLmtbpUqtSepKTtM0cPn BEFV4eIaDY3NgH8esI2ff9y/Vlt6eIPpDiutZu7S54uHeTEWRJXs0AufybbxccHPBtdDjnuHc HBoPt3CaNQn+cJtkULwkNXJjK3ux9NZofle1eSv/umREvq0/8dlZ/PNTJZbijERDLeai4kQAy sR8P3kDAAA= X-Env-Sender: lizhijian@fujitsu.com X-Msg-Ref: server-17.tower-571.messagelabs.com!1668141055!691429!1 X-Originating-IP: [62.60.8.97] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.100.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 19201 invoked from network); 11 Nov 2022 04:30:55 -0000 Received: from unknown (HELO n03ukasimr01.n03.fujitsu.local) (62.60.8.97) by server-17.tower-571.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Nov 2022 04:30:55 -0000 Received: from n03ukasimr01.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTP id 4711D1001A1; Fri, 11 Nov 2022 04:30:55 +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 n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTPS id 3A8BD10019F; Fri, 11 Nov 2022 04:30:55 +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:52 +0000 From: Li Zhijian To: Zhu Yanjun , Jason Gunthorpe , "Leon Romanovsky" , CC: , Li Zhijian Subject: [for-next PATCH 3/5] RDMA/rxe: iova_to_vaddr cleanup Date: Fri, 11 Nov 2022 04:30:28 +0000 Message-ID: <1668141030-2-4-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?1749172933210267848?= X-GMAIL-MSGID: =?utf-8?q?1749172933210267848?= No functional change, do cleanup for refactoring it easily later. Signed-off-by: Li Zhijian --- drivers/infiniband/sw/rxe/rxe_mr.c | 37 ++++++++++++++---------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index cf3ce8d293b3..a4e786b657b7 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -246,41 +246,38 @@ static void lookup_iova(struct rxe_mr *mr, u64 iova, int *m_out, int *n_out, } } -void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length) +static void *__iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length) { size_t offset; int m, n; - void *addr; + lookup_iova(mr, iova, &m, &n, &offset); + + if (offset + length > mr->ibmr.page_size) { + pr_warn("crosses page boundary\n"); + return NULL; + } + + return (void *)(uintptr_t)mr->map[m]->buf[n].addr + offset; +} + +void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length) +{ if (mr->state != RXE_MR_STATE_VALID) { pr_warn("mr not in valid state\n"); - addr = NULL; - goto out; + return NULL; } if (!mr->map) { - addr = (void *)(uintptr_t)iova; - goto out; + return (void *)(uintptr_t)iova; } if (mr_check_range(mr, iova, length)) { pr_warn("range violation\n"); - addr = NULL; - goto out; - } - - lookup_iova(mr, iova, &m, &n, &offset); - - if (offset + length > mr->ibmr.page_size) { - pr_warn("crosses page boundary\n"); - addr = NULL; - goto out; + return NULL; } - addr = (void *)(uintptr_t)mr->map[m]->buf[n].addr + offset; - -out: - return addr; + return __iova_to_vaddr(mr, iova, length); } /* copy data from a range (vaddr, vaddr+length-1) to or from