From patchwork Fri Dec 4 00:04:17 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: 7764301 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B2D8BBEEE1 for ; Fri, 4 Dec 2015 00:04:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8C2C9205BC for ; Fri, 4 Dec 2015 00:04:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 69942205B4 for ; Fri, 4 Dec 2015 00:04:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752137AbbLDAEX (ORCPT ); Thu, 3 Dec 2015 19:04:23 -0500 Received: from mail-by2on0070.outbound.protection.outlook.com ([207.46.100.70]:53184 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751983AbbLDAEW (ORCPT ); Thu, 3 Dec 2015 19:04:22 -0500 Received: from BN1PR0201MB0818.namprd02.prod.outlook.com (10.160.170.150) by BN1PR0201MB0850.namprd02.prod.outlook.com (10.160.170.17) with Microsoft SMTP Server (TLS) id 15.1.331.20; Fri, 4 Dec 2015 00:04:20 +0000 Received: from BY2PR02CA0115.namprd02.prod.outlook.com (10.163.44.169) by BN1PR0201MB0818.namprd02.prod.outlook.com (10.160.170.150) with Microsoft SMTP Server (TLS) id 15.1.331.20; Fri, 4 Dec 2015 00:04:19 +0000 Received: from BY2FFO11FD048.protection.gbl (2a01:111:f400:7c0c::163) by BY2PR02CA0115.outlook.office365.com (2a01:111:e400:5261::41) with Microsoft SMTP Server (TLS) id 15.1.337.19 via Frontend Transport; Fri, 4 Dec 2015 00:04:18 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=sandisk.com; infradead.org; dkim=none (message not signed) header.d=none;infradead.org; 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 BY2FFO11FD048.mail.protection.outlook.com (10.1.15.176) with Microsoft SMTP Server id 15.1.337.8 via Frontend Transport; Fri, 4 Dec 2015 00:04:18 +0000 Received: from MILHUBIP04.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id E0.D0.32178.288D0665; Thu, 3 Dec 2015 16:04:18 -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; Thu, 3 Dec 2015 16:04:18 -0800 X-AuditID: ac160a69-f79f76d000007db2-28-5660d88219f4 Received: from [10.60.52.33] ( [10.177.8.100]) by milsmgip12.sandisk.com (Symantec Messaging Gateway) with SMTP id B1.11.17166.288D0665; Thu, 3 Dec 2015 16:04:18 -0800 (PST) Subject: Re: [PATCH 5/6] IB core: Fix ib_sg_to_pages() To: Christoph Hellwig References: <565DE3EC.2070002@sandisk.com> <565DE49D.4020102@sandisk.com> <565DE7D0.4080408@dev.mellanox.co.il> <565DF0A5.6040102@sandisk.com> <565EBA78.3050201@dev.mellanox.co.il> <565FA75E.7010100@sandisk.com> <20151203091806.GB21893@infradead.org> CC: Sagi Grimberg , Doug Ledford , Sebastian Parschauer , "linux-rdma@vger.kernel.org" From: Bart Van Assche Message-ID: <5660D881.7020801@sandisk.com> Date: Thu, 3 Dec 2015 16:04:17 -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: <20151203091806.GB21893@infradead.org> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeLIzCtJLcpLzFFi42JZI8azSLfpRkKYweabQhYvz39gtTg9YRGT xbNDvSwWr48/ZbI4eZvfgdVj+oxNrB6bV2h5/Pnzmdnj/b6rbB6fN8kFsEZx2aSk5mSWpRbp 2yVwZaxr/8lSMEGm4sy92+wNjI9Euxg5OSQETCQO7N/BDGGLSVy4t56ti5GLQ0jgBKPE7mWr GCGc7YwSM9t6mGE65r7bwgyR2MQocae7lwkkISxgJnFp2R82EFtEQFPi1vJ2qKIGJomzDz6B zWUWOM0o8eDkaxaQKjYBI4lv72eC2bwCWhJftx4FW8EioCIxtfkeWFxUIEJi4oQGVogaQYmT M5+AxTkFjCXurnwDZjMLGEgcWTSHFcKWl9j+dg7YZgmBg6wSm6b9YARJCAmoS5xcMp9pAqPI LCSzZiHpn4WkfwEj8ypGsdzMnOLc9NQCQyO94sS8lMzibL3k/NxNjODI4crcwbhikvkhRgEO RiUeXoZNCWFCrIllxZW5hxglOJiVRHj/7AYK8aYkVlalFuXHF5XmpBYfYpTmYFES57VuUQsT EkhPLEnNTk0tSC2CyTJxcEo1MCZOOWbD1DzPo1tuieOHIJFfVhc95sfsniXjesnxQfHXhZwu vi6/q07/qn9TuPvB8dbAkDvXny3gsPHbE5tSffi1wlSdtkDhmGnzmacdWepUsP1l/p9ZX/ju /jC9Ny3+n8ve1941li+qZwudK236d5BllaFxUUBNwoszmw7EB6t/rtGf++aI9H4lluKMREMt 5qLiRABs8B2hmAIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFJMWRmVeSWpSXmKPExsXCtZEjRbfpRkKYwftTLBYvz39gtTg9YRGT xbNDvSwWr48/ZbI4eZvfgdVj+oxNrB6bV2h5/Pnzmdnj/b6rbB6fN8kFsEZx2aSk5mSWpRbp 2yVwZaxr/8lSMEGm4sy92+wNjI9Euxg5OSQETCTmvtvCDGGLSVy4t56ti5GLQ0hgA6PE3sXX WEASwgJmEpeW/WEDsUUENCVuLW9nhihqYJI4++ATWAezwGlGiaZ7+8Cq2ASMJL69nwnWzSug JfF161GwFSwCKhJTm++BxUUFIiQmTmhghagRlDg58wlYnFPAWOLuyjdgNrOAnsSO679YIWx5 ie1v5zBPYOSfhaRlFpKyWUjKFjAyr2IUy83MKc5NzywwNNIrTsxLySzO1kvOz93ECA5dzqgd jNcnmh9iZOLglGpglF8Y4PAw/Mb6jvv2br39bR9mXuIx1Km5uOB//AW3T/wrbbN75Xgvc0+3 PcYVt+tet/4Fk/tJ81Uz91puLdyT94C7YcNRHzE3dt33egKHTT7svf8o73rggTfCXjUv3hQF ND6rYFqo+DmAyftX6IRfLy99dXt8s+yObUKb7YItsyNkIiatOyx4V4mlOCPRUIu5qDgRAIkW iVQNAgAA X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD048; 1:lDahHKClWqL/iR14siGIVRvLYA/w56Z7tdRBO/1aCpOohdUlAkALJQpGSddbUEAcDbaCFW7V8JwIEwWgPRrAMnAr9mvuBCZZOaAkDec6nyDphCcRIhM4g7CQnsIdxEhGwDUuOnP9Xc1Qd3vq49HT/VV3htxaOMwVx/5NW8sW1gpOjvZcmPpPiVUstCopEwJUibj5vU9Rnx9BB2nq8n55i+OP3UmVTPzwyTvm2CgN3oP02IpLWTxC7faySNe4rQf562qcSzt2Ms0lh88vqAVBS9p17EgyvIPH9akZcen7LvdC56FbsmTIuAIlmPO78VCUEE2bqH2UaR3Bejy6AF0a+nZiVZSvEZsqkaYsAfagwml2LOy9VSUtFhILqQCAznEG X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(479174004)(189002)(377454003)(199003)(24454002)(93886004)(106466001)(54356999)(83506001)(5008740100001)(97736004)(4001350100001)(86362001)(64126003)(33656002)(50466002)(586003)(77096005)(65816999)(92566002)(23746002)(87266999)(230700001)(87936001)(76176999)(11100500001)(110136002)(189998001)(81156007)(5001960100002)(65956001)(19580405001)(1220700001)(2950100001)(65806001)(36756003)(50986999)(80316001)(19580395003)(47776003)(1096002)(69596002)(59896002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR0201MB0818; H:milsmgep12.sandisk.com; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0201MB0818; 2:4T18N5pDjQCxHXthBtvwXrvCT1X73Q/Hy0qis7SoTV5hUoH4Lsbye7hGG21f6flHKOEDhvOrK71SOKT8bWWHoGa2D9mmv5rAwgukdYmgCOdwLqdO6vY9xb4qQzia/OArr7oNDOLiv37t6+buwKxRHQ==; 3:rBZ9MyjawLkWv/IrEh0qbPwbO6DsQjYPuhXu8kO0uD6VEZR3Alk4Ig7BCtK9I967QNisdSjcKH5wwa6I07iiYiFcDijzWVjtXwEYX4sjHnmOBEPBPDFoNP4imOVeFFUtMTo/jTuuCs4lk4t/KW39sozpJiVa6j+TEp1iEqNNYNbsyv6Yy9jUIJFIW3d7JTvrSkE5Oqu6N/QAxUb9QAmJS5ORahcJRI2JR4HCK0reP5uU+d/Nt0iUO3YpnnKE3m0rD0vTgFxi29r3BQ69B84/wA==; 25:iKLgnAe7dx6mKZDrRBf/VYIR1BWNz1WMy3E+kZfz8jAB6aURy6x2ZMbkcBUUGPRfEuIT2fGwJ3EQRHDqGaB/4KVHPMRyJJnXzQ92JEfERbJRqrgm2q+byOSEpoAjfhPTkhV2HD7mjjV7opupg8Ne7e5ohxtXUFwKBGGLoEZR+sglMKZmK1K2PO4B2EcVbhs0ze5aMIFMksGlSXgK2PmSh4PN5PXPFaA/GPIGlfJK8lj4yAoo4pGiR/MSIsbjtKZGtzyI5qI3BBDtoDhefDFHhw== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501001); SRVR:BN1PR0201MB0818; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0201MB0818; 20:AsraiRQZqPT6szbJIsWYQmLOAarCustZYIVkV2lXjp5UI3PjRr4Ohl6gRNAsXiM3ANQ4qOkkplo1QJifhWwmadj1isG3STueZR9lE+nfBxCOxqWy1oQyia/CydsRxq9zZM06UcT0r+FNCRqExVyxiqbkFIMl9IuEQHBikgJpEOBKj3VLp6pQc2qyWvZqLtgtmE1hS9E4Kv4mOuVyqn80SmexlVF9CgeXBbjJ8cO1VWl1VJLA4wK5XnZ7+uPbo9nar9VmDIy8fUAtWlP+zbCK0FiRQWqZQJprpcKjgfCLK1UyepNt+kQt6Ct9+jk0CnteCN49mvEnmxl93WrdvhyLUHNdUR4JH+i50x9qDnvqCANeTRIrA+MxLWF7h9CVLtgjYg6Ij+tCY1KyySrkdpVH//lgROIVzvr/pTn80NVxPn6InDxv6lvPs1m1UaHT2gFihmJBcG6vSicGvUw7jmVj0L+x9TXxS5UMytpHp7zs2WefpBF57TCYZP/WT9BUA/CI; 4:UyVfb9kYtaPPzftBoJYkTucal3pLSaAKVukucbeOZ5xShkL7Ygk3e4Z6QzDAq8fVhd2VzB2gzkSa5KBbaylmagMwZFdpAEhJcmctff+1TfGBMSnAYJC2o37ACky41wukZnznAd20i4YhsQfdJMIAxZuLihj0UWD98d3LiO2C7sKizwFF/SBE+UdgIAub1Mpt1dPiVZ0yfdziKJyuxkzYDuYt1CZnqw/W7I5t1f1zwWzPskjYZxWryJusB1t2baXbkkFrAjjHP/N6n2DzEvgvuY+Kd1ezEk+O1FXoyb8toQKM7TJUZ2ddcsU60elnTnyc/pRHkH9PpDsZvsV/TymHgaP76j4okhLpJ+uS/gvTnOfEXuhQBoANkzZ3B74Y5HAT X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(10201501046)(3002001); SRVR:BN1PR0201MB0818; BCL:0; PCL:0; RULEID:; SRVR:BN1PR0201MB0818; X-Forefront-PRVS: 07807C55DC X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1; BN1PR0201MB0818; 23:+ZB55S8RANI4WeJAVoZnov17kWOVs7UGRmo?= =?Windows-1252?Q?mU3L+qBmxrSqA4mc8VgGOt8sRUgc1xpl8uQ29Rkg+A6ydF5/CCNSjxxU?= =?Windows-1252?Q?bee4nKKQSHGhY95Sga8Gkwno6La74SoU1Cyxa1XnpNzV1UXS6JxJuLSr?= =?Windows-1252?Q?tdQhMjGj81uuhumiNftLJl7wP2m+C5KxBxM66R11rIujiVkqFkDowGV2?= =?Windows-1252?Q?7rFOYNSdBUJxQcCLps0cK0ASEa1GA2KxxI9R8+p8V+xqSF3BW7LOhdDR?= =?Windows-1252?Q?KoY5HvlX7G6JREvZ1QiVXHjGkBRFl3mR5JSZ5Jcq39WRBCY4k2FVDk18?= =?Windows-1252?Q?K/yrV0sUik4got2P3Xid2pUIyzJW9l2Rct2fW9IA1OpSzFUuYy/tOtmV?= =?Windows-1252?Q?NPt6aAO7+wbgR6LdEd2eAvmrOAUMnofikAJHKozUPd0f6JMdhgFnXTfH?= =?Windows-1252?Q?5G0vDzTanxVog1dq4YMR8T3tSb/Y1qOTb27J1VNxLSMHAbApOdzlhlOu?= =?Windows-1252?Q?v/2vUEHfgn8Eq4Pqg1lobN2M8A0pUbbi9SPcKX4dd+JdTTC+/Y8dyafA?= =?Windows-1252?Q?kc+liWcdTiQLgaM7iOa3f8gNblPeosDQ+kNMcSnV3t19/fuON0rHvRnp?= =?Windows-1252?Q?m+6Rs9nl6ZLCZtgZledARfO8Nhr9/mwxb2iihJUH24AkkDrZRjqCsEfd?= =?Windows-1252?Q?FAWoMlZEbD+FcQBpRKnxofbvIkuh4/QTYXwLxPnk3NcEdku94Pl2JrBi?= =?Windows-1252?Q?dAZwikYBI6YLp4Va7SSrP7/CPTKml618LsVHGYQSTXxEbq6mXJEhwc24?= =?Windows-1252?Q?6+EgW/+2nmJygU/mObXH5DpkYnkU/ERcRnyPC62QBa9Znc4gLUrgagWh?= =?Windows-1252?Q?VdThLzs5/njKxrb09yrFPTid4P3hZLjuQTi2MQs8dckLMJhqvjzPuoKX?= =?Windows-1252?Q?IcN7m3jDcxFl/wxZnSDWju0gGZFcr2kgWitM5QrMvn0lA1IzhC9M9e81?= =?Windows-1252?Q?L2lJYXVgxuOy2Atol5MhIWLU7t2X5uXIPp2f8up9IA5xpdfqp9hdn1Wa?= =?Windows-1252?Q?04R9P+NlbCBjdHN15J3gDNMxKtnpwbYpAA9iXSkzxZNODLT+d7Y+Lvhy?= =?Windows-1252?Q?VFOOy04UtQBYGUnTBCkNj4HBQLBdAN6PPM/AeWOtFsm948qI2QwQbLuH?= =?Windows-1252?Q?y83bovdLQjK6zZ2sqhwq9nBpSd2yhkzLnBZKbNkmgZ9ogpBaQh2PVFUJ?= =?Windows-1252?Q?QQ4GVR8UA0HqBFMyCOSpeTHxPHyw0uglU99faXX34Kth6dZF2KGyMGWA?= =?Windows-1252?Q?hk+QH?= X-Microsoft-Exchange-Diagnostics: 1; BN1PR0201MB0818; 5:sFQX9y59cUQG0o2WeLqJ74iLR7XyAfZIx/7Qu/QiXoHq5KTWks5K0dUFPOO4uW8/KGK0vhUr1ORmrSVx+lvK7ArydVVRwuIx6B2uXKtAiLYiqNufF9utzShwOWATkE6xGEB/j7LtzhugJAYXFE3YNg==; 24:re4CM0amwv3svrLg4XwJBaWLVaBwTq/PSND+sE2a8yLygrdehK1/A2zjfiGBfujqlmi9GssBNg+iBmvIXYsS7ciNg+FTPuGsoNFmw8Zf5lI=; 20:eyBLK9KSdfOr3OflSKtuG1Eeom1sPpsi8Y3/+U+nItErZiOWo/eNaHGsyijD5A47GMNwNmGZpb95g0/VUUJZP4Ssup5asxLw07d8pZJkLU4MswT+EznTbzIBP0P1qyHckDVJi7rkNcASQLo/UqpxqipYdgYSGC/GBEiXhWmTVSmQSRapDxhck4gIqHG9Y3Mx/sFK9M0zwq6ub57TRKW88jILsGk3Paoa0rbLMCyZe+KEG/I1xbTCl/xXR0RDl2Uh SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2015 00:04:18.4157 (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: BN1PR0201MB0818 X-Microsoft-Exchange-Diagnostics: 1; BN1PR0201MB0850; 2:Zut/R2Z5MF5yWl0102qauyxgBiPHe/F7LnpSYnPoR8d91xXjqQIy4NcRMZuiA6lhDtG+lOxTxzXOv7fbZWHEldQUb/g1yTFqxEHrfJiNlh5cgkhOXERAe0Nh7LptXsyj+b8Ic0+zva1+nohfFOReew==; 23:mflZvIO+YNacJUTYp5gM4f9ryQJxmNQo/7dUIBMPsIzvhovGcF6xjhCLr24KHRJKL8cX6zejMwXSBl6GxX4wa7ZjzIaGfI1l40YJy0XVQEXYTzEMiLCvb7GfUByOlHNtt8qsSN/wOuvC/ZFNo+w1KPj7L4m/ZmtxhEp15ZmopLxGj+ci+InWt/wCYW00w4gs X-OriginatorOrg: sandisk.com 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 On 12/03/2015 01:18 AM, Christoph Hellwig wrote: > The patch looks good to me, but while we touch this area, how about > throwing in a few cosmetic fixes as well? How about the patch below ? In that version of the ib_sg_to_pages() fix these concerns have been addressed and additionally to more bugs have been fixed. ------------ [PATCH] IB core: Fix ib_sg_to_pages() Fix the code for detecting gaps. 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. In the code for coalescing contiguous elements, ensure that mr->length is correct and that last_page_addr is up-to-date. 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 Reviewed-by: Sagi Grimberg Reviewed-by: Christoph Hellwig --- drivers/infiniband/core/verbs.c | 43 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index 043a60e..545906d 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -1516,7 +1516,7 @@ EXPORT_SYMBOL(ib_map_mr_sg); * @sg_nents: number of entries in sg * @set_page: driver page assignment function pointer * - * Core service helper for drivers to covert the largest + * Core service helper for drivers to convert the largest * prefix of given sg list to a page vector. The sg list * prefix converted is the prefix that meet the requirements * of ib_map_mr_sg. @@ -1533,7 +1533,7 @@ int ib_sg_to_pages(struct ib_mr *mr, 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,27 +1544,29 @@ 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; - } + /* + * For the second and later elements, check whether either the + * end of element i-1 or the start of element i is not aligned + * on a page boundary. + */ + if (i && (last_page_off != 0 || page_addr != dma_addr)) { + /* Stop mapping if there is a gap. */ + if (last_end_dma_addr != dma_addr) + break; + + /* + * Coalesce this element with the last. If it is small + * enough just update mr->length. Otherwise start + * mapping from the next page. + */ + goto next_page; } do { - if (unlikely(set_page(mr, page_addr))) - goto done; + ret = set_page(mr, page_addr); + if (unlikely(ret < 0)) + return i ? : ret; +next_page: page_addr += mr->page_size; } while (page_addr < end_dma_addr); @@ -1574,7 +1576,6 @@ int ib_sg_to_pages(struct ib_mr *mr, last_page_off = end_dma_addr & ~page_mask; } -done: return i; } EXPORT_SYMBOL(ib_sg_to_pages);