From patchwork Tue Dec 1 18:19:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 7739611 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6F1DF9F30B for ; Tue, 1 Dec 2015 18:19:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6774E2065B for ; Tue, 1 Dec 2015 18:19:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 567FF204F6 for ; Tue, 1 Dec 2015 18:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754983AbbLAST2 (ORCPT ); Tue, 1 Dec 2015 13:19:28 -0500 Received: from mail-bn1bon0096.outbound.protection.outlook.com ([157.56.111.96]:18627 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754141AbbLAST1 (ORCPT ); Tue, 1 Dec 2015 13:19:27 -0500 Received: from BLUPR0201CA0007.namprd02.prod.outlook.com (10.163.116.17) by BL2PR02MB291.namprd02.prod.outlook.com (10.141.90.148) with Microsoft SMTP Server (TLS) id 15.1.331.20; Tue, 1 Dec 2015 18:19:25 +0000 Received: from BN1BFFO11FD025.protection.gbl (2a01:111:f400:7c10::1:148) by BLUPR0201CA0007.outlook.office365.com (2a01:111:e400:52e7::17) with Microsoft SMTP Server (TLS) id 15.1.331.20 via Frontend Transport; Tue, 1 Dec 2015 18:19:25 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=sandisk.com; dev.mellanox.co.il; dkim=none (message not signed) header.d=none;dev.mellanox.co.il; dmarc=bestguesspass action=none header.from=sandisk.com; Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.173 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.173; helo=milsmgep12.sandisk.com; Received: from milsmgep12.sandisk.com (63.163.107.173) by BN1BFFO11FD025.mail.protection.outlook.com (10.58.144.88) with Microsoft SMTP Server id 15.1.331.11 via Frontend Transport; Tue, 1 Dec 2015 18:19:24 +0000 Received: from MILHUBIP04.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id 75.7F.32178.BA4ED565; Tue, 1 Dec 2015 10:19:23 -0800 (PST) Received: from milsmgip12.sandisk.com (10.177.8.100) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.248.2; Tue, 1 Dec 2015 10:19:10 -0800 X-AuditID: ac160a69-f79f76d000007db2-7f-565de4ab9453 Received: from [10.60.52.33] ( [10.177.8.100]) by milsmgip12.sandisk.com (Symantec Messaging Gateway) with SMTP id 24.A2.17166.D94ED565; Tue, 1 Dec 2015 10:19:09 -0800 (PST) Subject: [PATCH 5/6] IB core: Fix ib_sg_to_pages() To: Doug Ledford References: <565DE3EC.2070002@sandisk.com> CC: Sagi Grimberg , Christoph Hellwig , Sebastian Parschauer , "linux-rdma@vger.kernel.org" From: Bart Van Assche Message-ID: <565DE49D.4020102@sandisk.com> Date: Tue, 1 Dec 2015 10:19:09 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <565DE3EC.2070002@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkkeLIzCtJLcpLzFFi42JZI8azSHf1k9gwg237TS1env/AanF6wiIm i2eHelksXh9/ymRx8ja/A6vH9BmbWD02r9Dy+PPnM7PH+31X2Tw+b5ILYI3isklJzcksSy3S t0vgyljX+4a5YJlIxYV9og2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G7WC8PtH8 ECMTB6dUA6Noiuben1/Sc3MtzhcqTGhyL/Xj0JT8eyveQ6tmvZCHvLALp8YmJlNOpmnmE6/3 yea9j+nJt41/UGXW5uda/+l6QVSZz6SDB7gztl8+2axZxOjc/T2kw++fywkma+0d6u6npSxT t6pELt/dM+vKl1TdR8tWTlQrWCX1XP51prBweF0fW980JZbijERDLeai4kQAoQwEpAoCAAA= X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD025; 1:3h+bAnrHee0i0a7RYnBLQXzLocrgH7M0HbUJaAZ+ENZ9hRYW5a4EXJVfjlboClFF6lRI1Ff+UAioDAUUSa6E7naf+S71Ct+vYAjAs+UXpEaCjl9Xt0CNBEAfv4jAEfuQvgqSe3MbHMjEuQheW4i4Jl3Kic5Nf9xt8oAUJlD7hsnC9m1MAYBuEqiK6lVouMa6iK6uaa92ncJnfCnbnO7J12BApldP410kbH1nvgeBikmGWVziaXyDxNi0zkmnp2gin+9fINDRcPntTbku4bU4uXwVB8tdBswjJo4x7XE3EtfM+NcVO0RS1F+TiS//KaH0bPWm98NhmB34sGbrM7uugAfvoTspdRP8q8fDZlVUHPu9tnkByYuAamrd6pYT2dB1WCa+40U/eT60PJIFegTC4PLoLOvVzOkJnmGfP24CSHY= X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(199003)(189002)(5008740100001)(33656002)(81156007)(1096002)(1220700001)(110136002)(4001350100001)(64126003)(47776003)(86362001)(87266999)(76176999)(54356999)(65956001)(5001960100002)(230700001)(77096005)(586003)(97736004)(36756003)(2950100001)(106466001)(65816999)(189998001)(19580405001)(65806001)(83506001)(87936001)(59896002)(23676002)(229853001)(50986999)(50466002)(92566002)(80316001)(19580395003)(11100500001)(69596002); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2PR02MB291; H:milsmgep12.sandisk.com; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2PR02MB291; 2:zn6X4s6O9cGkzHce9Wzxd9f82UJA5u56NkhWWEDrN0rDKb5PXv4bEMim82xUrCdyBrOJE1pDQ6ourIujvgjAouA2hJzHtTeLO3VcZQTxsh4cio1wBGmDkyYN28rrAK1MTWSV5WW8eegqQoq6vL5Pow==; 3:Eon6dkinedcV9aYlGjbwOeD2MA4TD/q9nI3qdegsrx0sW0w8NO5loQiPoHYkg46aCUGlCmlSElNTfmm7NW/P9/r/hXvCVF+wrQpbnmuct2HBzSE/oSKgcHWMGAXUIW/EEttUmwk2TQwFeoB0p4DEFm/8f9nK+PD07fq18p/zMToz6HQ1dgn1i28xEYKeUSc/a3AT3d1jbCHz2aLsn8byxb5kpqV83Z6hIhSIIE1Drpu3ZEXs/4mcr3av5VTNef0G3bONhngg4ZCCf9eL+o0EZA==; 25:OnEnq+/G8RZfPYHX20e/aT1QHhiFX98vBznqu4bALxZAYaREnH5hMPG1X5pRFMeQpmq3FfRPM2aI99JBwwah/Ktd+NEwn+5dWKCUxeRNrwp5SeKHZRgbR+KNpT1gSh9zEf9ZWLpACdVyd+PEggPl1bxYILhKbuAyaxIjn8dGs28yhsR3HczMV+hD6MgtY12qLZC+xY5qadHVCqs19eXtCCecJOBtEIE6RGkwznNIAZBijPvzoQ/F5bSa4w1NX58z X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501001); SRVR:BL2PR02MB291; X-Microsoft-Exchange-Diagnostics: 1; BL2PR02MB291; 20:6nExf6T+BTcro1Xf5AFseyfZQa7EGGZlf/rDmm4MXTQBgiySO5K5PBRHRUUyTOuSShbKzVoFvCcbapSDbeRQp/UxFmXoD46KjfgCucyjBZwGdCLEdOeWxLXDXL7ukfCoMYLWn5XRurNsmH0gO40r1YN4c90NjaPP6vHIgQ/ER+A3r5cVtnr+9V6MjmzVloNVRkKQw/XX6rmJLC/UASGZC15XvnxM4SEFvPLpgs0lBxQwCg99ykbd6egGJfmjO1OLN3kRmZY0dcwk7LhQoB+ND9GE0t2usKE0e2GfdLUMZY/1xEEAfjdl2SCvSP4oyajbbgA1h+doVA1qeEiDiRjNOzuqQxlAaXF9ghnFCdBlA7fnBOFyuj6bUAubV5O6mFHCMW3qiVrBtPJNX15Dhp8Ty8xda4ePy2EvH2Zn9GGGt/9NOlw6s6f7Y4y60h2vEM/lFUl6HUQIkAAB540zJ1a51yuqpcRNORDx/DMLQRtPB36qHJ+AqkDJiqnjtGKeJnM2 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(34787635062028)(42932892334569); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(520078)(10201501046)(3002001); SRVR:BL2PR02MB291; BCL:0; PCL:0; RULEID:; SRVR:BL2PR02MB291; X-Microsoft-Exchange-Diagnostics: 1; BL2PR02MB291; 4:p7nq8F/qhtH91GvxtMsuTxB/wKaPJ+l0I03l6K/ZAW/scXnnWR8FyokgjdQicltkrgdvJufq0VmjMiqDYzmyATWIVXmKGX8Qlf9n0ktbQe2NprFXjKVS7O69hWFmkROG6OIjl2kzGFlHpPA/ZcKOPzW8qj3kIsPXeYMQ5MIkvfGPqprr376mzMAtAeCzUGGau/Ci4BvLWUvU7O0TQ+y5qPyU2+w0aE86+lQEYWdYwon2JJ/OKsYv3ymId3S49zevLar9WmdeoDYm4oxlhBH9oMgOou1aZ/ocraU1Mz5m9ju1l43BgQ2Ga+cgNE029B/QsJSCbysRysqcbhjDlAH6kEp7bROY5QpXkrW5oIantIm8PsKXIeb02AAbPJrYsgkriVeMeRSrXYQwHrU87LkSETYaVFqlZlEunBuN+Dp3pdBwrVoVN/BaAoOwPHfCVk5biHGt8gEPmjB61NseCtTvJw== X-Forefront-PRVS: 07778E4001 X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTDJQUjAyTUIyOTE7MjM6Z2xpYmJDZnlrc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AzRr2X1tNue1JzUnDSlC86e33lHWu52EobLPvFUxp6qX27B4pOaXZxXruR4FzBZTDptoIBRMhQ3qLEFZDFdRmnzLxiAdtuuLzYbbr6LsCnttDuih6DDnBXEYDCHgXlHSs1KoxNiaws/cItZxlYZr7c5QM2lJrWymfBi9H0vszYIUSxtLRbcAsQ2zCWF5Uw0Z3n0JDWj06sdJkqXEa7CoG+Gw SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2015 18:19:24.3727 (UTC) X-MS-Exchange-CrossTenant-Id: fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d; Ip=[63.163.107.173]; Helo=[milsmgep12.sandisk.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR02MB291 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix the code for detecting gaps and disable the code for chunking. A gap occurs not only if the second or later scatterlist element is not aligned but also if any scatterlist element other than the last does not end at a page boundary. Disable the code for chunking. Ensure that this function returns a negative error code instead of zero if the first set_page() call fails. Fixes: commit 4c67e2bfc8b7 ("IB/core: Introduce new fast registration API") Reported-by: Christoph Hellwig Signed-off-by: Bart Van Assche Cc: stable # v4.4+ Cc: Sagi Grimberg Cc: Sebastian Parschauer --- drivers/infiniband/core/verbs.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index 043a60e..95836c6 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -1530,10 +1530,9 @@ int ib_sg_to_pages(struct ib_mr *mr, int (*set_page)(struct ib_mr *, u64)) { struct scatterlist *sg; - u64 last_end_dma_addr = 0, last_page_addr = 0; unsigned int last_page_off = 0; u64 page_mask = ~((u64)mr->page_size - 1); - int i; + int i, ret; mr->iova = sg_dma_address(&sgl[0]); mr->length = 0; @@ -1544,37 +1543,21 @@ int ib_sg_to_pages(struct ib_mr *mr, u64 end_dma_addr = dma_addr + dma_len; u64 page_addr = dma_addr & page_mask; - if (i && page_addr != dma_addr) { - if (last_end_dma_addr != dma_addr) { - /* gap */ - goto done; - - } else if (last_page_off + dma_len <= mr->page_size) { - /* chunk this fragment with the last */ - mr->length += dma_len; - last_end_dma_addr += dma_len; - last_page_off += dma_len; - continue; - } else { - /* map starting from the next page */ - page_addr = last_page_addr + mr->page_size; - dma_len -= mr->page_size - last_page_off; - } - } + /* gap */ + if (i && (last_page_off || page_addr != dma_addr)) + break; do { - if (unlikely(set_page(mr, page_addr))) - goto done; + ret = set_page(mr, page_addr); + if (unlikely(ret < 0)) + return i ? i : ret; page_addr += mr->page_size; } while (page_addr < end_dma_addr); mr->length += dma_len; - last_end_dma_addr = end_dma_addr; - last_page_addr = end_dma_addr & page_mask; last_page_off = end_dma_addr & ~page_mask; } -done: return i; } EXPORT_SYMBOL(ib_sg_to_pages);