From patchwork Thu Dec 3 02:22:22 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: 7755281 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 22B44BEEE1 for ; Thu, 3 Dec 2015 02:22:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 20694204D8 for ; Thu, 3 Dec 2015 02:22:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1268D204D5 for ; Thu, 3 Dec 2015 02:22:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758102AbbLCCW3 (ORCPT ); Wed, 2 Dec 2015 21:22:29 -0500 Received: from mail-bn1on0075.outbound.protection.outlook.com ([157.56.110.75]:32317 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757927AbbLCCW1 (ORCPT ); Wed, 2 Dec 2015 21:22:27 -0500 Received: from BLUPR02CA037.namprd02.prod.outlook.com (10.160.23.155) by BL2PR02MB289.namprd02.prod.outlook.com (10.141.90.143) with Microsoft SMTP Server (TLS) id 15.1.331.20; Thu, 3 Dec 2015 02:22:24 +0000 Received: from BN1BFFO11FD036.protection.gbl (2a01:111:f400:7c10::1:182) by BLUPR02CA037.outlook.office365.com (2a01:111:e400:8ad::27) with Microsoft SMTP Server (TLS) id 15.1.331.20 via Frontend Transport; Thu, 3 Dec 2015 02:22:24 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=sandisk.com; redhat.com; dkim=none (message not signed) header.d=none;redhat.com; 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 BN1BFFO11FD036.mail.protection.outlook.com (10.58.144.99) with Microsoft SMTP Server id 15.1.337.8 via Frontend Transport; Thu, 3 Dec 2015 02:22:23 +0000 Received: from MILHUBIP03.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id B2.6D.32178.F57AF565; Wed, 2 Dec 2015 18:22:23 -0800 (PST) Received: from milsmgip12.sandisk.com (10.177.8.100) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.248.2; Wed, 2 Dec 2015 18:22:23 -0800 X-AuditID: ac160a69-f79f76d000007db2-65-565fa75f3b0a Received: from [10.60.52.33] ( [10.177.8.100]) by milsmgip12.sandisk.com (Symantec Messaging Gateway) with SMTP id B1.C7.17166.E57AF565; Wed, 2 Dec 2015 18:22:23 -0800 (PST) From: Bart Van Assche Subject: Re: [PATCH 5/6] IB core: Fix ib_sg_to_pages() To: Sagi Grimberg , Doug Ledford 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> CC: Christoph Hellwig , Sebastian Parschauer , "linux-rdma@vger.kernel.org" Message-ID: <565FA75E.7010100@sandisk.com> Date: Wed, 2 Dec 2015 18:22:22 -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: <565EBA78.3050201@dev.mellanox.co.il> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeLIzCtJLcpLzFFi42JZI8azSDd+eXyYwanJMhYvz39gtTg9YRGT xbNDvSwWr48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hQnEFhWIkJg4oYEVokZQ4uTMJ2AbOIG2LVg4A6yeWUBd4s+8S1C2 vMT2t3OYJzDyz0LSMgtJ2SwkZQsYmVcxiuVm5hTnpmcWGBrpFSfmpWQWZ+sl5+duYgQHLmfU DsbrE80PMTJxcEo1MO5lWbXo8+pDE1YdWxw/xWDr00PnL//R/LXlrrjmJ77GevfwwGMpBvdK n7dnTpz50Xli9r8rXnM31Kb3pb5fuWbhwxkmbC4rTxzWmXNxzfy9xddK2s427+BOWRZ09tNB cbUuRnG3+MLVynYl5YJyNhvWcHfOYbjSeHLShLmPkqL3NpS0f25Ij2VSYinOSDTUYi4qTgQA esD/pwwCAAA= X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD036; 1:pLeOUYpWIjBJ+UGVZ/X0hAOygvV1MnbViIzzOCZd/D18xslLJ9TH2OLl0KgPcdEhMhL/ZpQJ1u361RKc47Iux8+KEkjORT4YJeUwDVqdzW5IHU1dBjaTmouVqh6GpYPUPAbhzI1GUPSSgyxHt3NlVuFgs7YDFlbAqgqp8tcodL0GLWjGyGNBACMReb304jbd5KrbfgkK45KpnTr2bZ+3bcTfky0eUmvqKvnGDLww1h/XTBDqmVFQEPqoM2bunOj45MOYtoR5zPWOPNp0MKQkVXKNMU4mBzM1z3pfKjjzp67L+afZk769iXdBnkrbYrffIQaa+zXYco03TzTSPfXxYV5x66tWfr7afyBts+6XU10JArqwgW03zQl3TM6uHCsy0q3MIqEiLaqRpb5dNz+vk9CbSe44TJWJPWdo+rAIXXw= X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(189002)(199003)(377454003)(479174004)(24454002)(5001960100002)(5001770100001)(65816999)(4001350100001)(36756003)(65956001)(69596002)(189998001)(23676002)(65806001)(81156007)(586003)(1220700001)(97736004)(5008740100001)(47776003)(11100500001)(86362001)(1096002)(77096005)(83506001)(87266999)(93886004)(59896002)(2950100001)(76176999)(54356999)(561944003)(80316001)(50466002)(33656002)(106466001)(92566002)(64126003)(87936001)(19580405001)(230700001)(19580395003)(50986999); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2PR02MB289; H:milsmgep12.sandisk.com; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2PR02MB289; 2:ZU/QN2eY+ely/WVk3gri2qIAgjZuSwzSAs0P08X/x1lqUyypP+VAus1xrO/ViFw7PBlh81JDbYyz0ZRKG7LC4K5V4XzKUJC+HEnsIJN6CyWPKVa0UQ6EsqmrFy/WderEaOICvW8IAFSrvKqcCS9F2g==; 3:H9GKib2yFDJfdpGppyo7c2VcasLQJeecNgBd+x0nhOGIVc2Yydd0NmuSgSOuaHqPiZbA5h4oxWRrTNsPwRj/iCHeK6WbHdcCKvmbGe1KhjsOWrpJDMfBLdDdoTaCLQGU8l9ZnixxGqwBcfuZxK9QsG1hxjAXoKfIVf8zbc1QXCTueSR+5qzs9vHuMOq9iUCcAL6e2cxZWxZgTFCuQaCtccEaJ3+m8aaJU+sPC7FHAmVnUJUOIqZkl54WnBTAuEb2jLxY6G26vamx/JjGb4OoOg==; 25:Lo86iocG3evkCjvoGEWkUoFS+wZaQkBPNUJQF3Ru3fCC2eJzMH5HcIEPJwawbh6IopvAlCU5MrRJrdzjDo89oBTnTvXHRBMnJZ5IQxSl3/SKRDB0myJlr+EQJB9P4FSPW3w8BRYKz7El+ilA9vM2TptMUvfv1P0JLy/2thpblnb8dmUkW35D4OwQbI5hgPTRIcElvKS5G4vxJUSX0glBQFXxRVKDPbG58kSjNDkTBwAc/0x404V+a1HIOKBU3Nw3 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501001); SRVR:BL2PR02MB289; X-Microsoft-Exchange-Diagnostics: 1; BL2PR02MB289; 20:hHR1iZgM7cwmneaRddsNamF8UGiuq/bZKXxiX2EUdnh0Whug2qzB2t1LwQfwQ08dEezof7nP0K15TGvxYkpgJy3qtS9fFngg2/GiPsVERgVz7SwDUv0eZz9zpimOgc6Nt+5Jc22b/zJsZ+hTL+9bPxCHqg5vLgUN+lE33QKvy9LXykVnAcJfB9J9zKiv9rd2x0mcgarOPttgleuT3J901EGhZihyEeSGZDUpmyiyG4ccuctgvnCC4OSlOFlMATWBqvxuwrLwI0c2GG4kC9O3KD7cAKoGox5y4q0qpCVb24bBs4Dwsp9brKscYXHwU7puIaCwrjIeK4ZZtCFg87ORz7rrNe+ZBJUSqLLOlgmJczv3/HcJ4Ov1pc3cFUjxqDk9r9UDxBDkeRKWNPgrzyap8YsdH9PqUUKHCvXvxk9rmbMMQYcoyr77D2hau7TEjkGgDGfEZeVgwl5I0k62VM+XvZbbJk0RSz9eR9CqYaRBa+oItfnKOmyOjfFjFuiax6sK; 4:DEWL9pmW7/HFEIjCRIuLba22mPPgGftPeDui9hm7q36iOMrXqRQJ0BJDRx1iDrkuSKsdnEjwJ5GbCK/43NOjVbj57VD+Kq1YGM/J+hvv7Dy/UiilgMIFkFNJ3LSykqYs0v+rw5hyFQuoEZu9AEmi22jSr+8s1dlumlSguQ1xnMDeko+80JJL4Gp5a9Wb+rUFquuYqvakrMkDLTD+IH5xH+NZEpessU3ta5qDlCUxvoaGJVpwLJIG9SAhNSYhO00A9A9npdCQ/XEYw9oRJsNGMVmJTXtFY24rA+9gw/DhyB8Sw2ruTRkkVkRb8QdwW4kRe67NK8Ajp7ytc+GUnGL0aTnbjIMUM9CdTqwa2mXO9teehTVH1AyUGGYNMPhquPKV X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(3002001)(10201501046); SRVR:BL2PR02MB289; BCL:0; PCL:0; RULEID:; SRVR:BL2PR02MB289; X-Forefront-PRVS: 077929D941 X-Microsoft-Exchange-Diagnostics: =?utf-8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Hr6xH1GcryWsy6bekXWsyorQikdleCbIbi36jYxmTt7G6BpSesmOoXZKNcK48z4+OoSCpZG+1B+Nqfg==; 24:ifMaDiy8jHAP3zzF4gOQ3hNQVJzMc10lqVXAAcrmrSGwblAAmo13/mnmrEP2K/1L/Cb3x2ijyleHUrR/KPi8JTQbRDCSTHU+iWbcxdqwUYA=; 20:5TySPUQLWjxw0kSknmLIUO7Da7xRU9jl0CJ6VuilBlXuHuRXCzM2P4Mxkh7qQYjv/7hTbTNYJrRE4+/KwsPqfHnkvXx205xLTwysU5dpnoqFei7wrhg62RLCKUTCIcdWYG0Lc+mPbCX35vsMtGieP06rRbXGbtst7W1L2D4EOXMEmvC5gXiaXYt/sZBBLXaMbHomVIWgwESfmuB0Qd9wqchW17quPyLoeJDPgeetykzEJxYSoShRAN7OKuu92rTm SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2015 02:22:23.5189 (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: BL2PR02MB289 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/02/2015 01:31 AM, Sagi Grimberg wrote: > On 01/12/2015 21:10, Bart Van Assche wrote: >> On 12/01/2015 10:32 AM, Sagi Grimberg wrote: >> How ib_sg_to_pages() reports to its caller that mapping the first >> scatterlist element failed is not important to me. I included that >> change in this patch because I noticed that in the upstream SRP >> initiator does not consider ib_map_mr_sg() returning zero as an error. I >> think either ib_sg_to_pages() or ib_map_mr_sg() should be modified such >> that "no pages have been mapped" is handled as a mapping failure. > > I don't either, but the patch introduces inconsistency in a case where > the caller passed sg_nents=0 (which will return 0 and not -errno). > > Would it make better sense to have srp treat 0 return as error? note > that all other ULPs treat return_val != sg_nents as error. Hello Sagi, Hmm ... why would it be unacceptable to return 0 if sg_nents == 0 ? Regarding which component to modify if mapping the first page fails: for almost every kernel function I know a negative return value means failure and a return value >= 0 means success. Hence my proposal to change the return value of the ib_map_mr_sg() function if mapping the first page fails. How about the patch below ? Bart. [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. 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 --- drivers/infiniband/core/verbs.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index 043a60e..1972c50 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,11 +1544,10 @@ 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 (i && (page_addr != dma_addr || last_page_off != 0)) { if (last_end_dma_addr != dma_addr) { /* gap */ - goto done; - + break; } else if (last_page_off + dma_len <= mr->page_size) { /* chunk this fragment with the last */ mr->length += dma_len; @@ -1563,8 +1562,9 @@ int ib_sg_to_pages(struct ib_mr *mr, } do { - if (unlikely(set_page(mr, page_addr))) - goto done; + ret = set_page(mr, page_addr); + if (unlikely(ret < 0)) + return i ? : ret; page_addr += mr->page_size; } while (page_addr < end_dma_addr); @@ -1574,7 +1574,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);