Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3988528rwe; Tue, 30 Aug 2022 02:32:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR6WfSWx9N3o2USz3Nivuy1u7nYpEh3gNyQrhpXUJM1neKfjwlyU4nKki967r5+S/mU8ZUYy X-Received: by 2002:a17:907:d91:b0:741:771f:1d11 with SMTP id go17-20020a1709070d9100b00741771f1d11mr7310397ejc.588.1661851953122; Tue, 30 Aug 2022 02:32:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661851953; cv=none; d=google.com; s=arc-20160816; b=l9rofh1BdHoN+UHbW3ID9rgzs9nSSvkU0KEWm6m9xAn262AQv+Ar4attzhNsqL/kTi UNEy4t+KsENJFKz5C8LCqpOWhpZktOYXVTyBbrKZXOaU0IeC/IJHxy9zQc/5Kh6PLToV 9+hwWpx4kAK9YNpiuiFefpnYDV5xTS1W6grf2f41F/VIehnlupJ6c3BrPeaIsNGipOJZ hyPlx7tUGLbhakd2h+V7mwXwjbQBFCC/ybr+RuSo00rWpKelHqP4EbhO+AO45SJvOjPy NnvZfT37ED0cCivstOFsDi6nmqPi45Gh274BYEwGzQ7jujxELwHMwrR1lJLtlric9r3E x51A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=mpUjxCyEhTu/Vrrq9HCqiAy81B12JY5DlQuis+EGEOg=; b=GNunodDMfcxo2LG7tub3vw+lkv80Cx33WPHQ5GZrpvKdOFVJdrxqskmRPMww5SO+VV YIJyQc1HsPTh4pHO+1odsUD9webbhLI0aWz9nI+wSxVOFwYCFipfcK+mZbVPg8+SYtuX 2Wjm0QsqRSofId41uSZ00cudOJAnG67Ig149DMacZSvIWOgry9H8jH6uCBX4DUvkye0N GNUWYXATlBrPvf53X4ZQy1esNe8AgtuxPqcJDTgPfmXR/N8Zis+uO7antd3rnCJdVrWW QMylpXdy+qHmPoxjNJROC77xywjjyKdI28nKh9pSlwC3iik5K3Cnohbkk5ekYd9/eDKt HlRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=MDr2bJ1C; 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=ionos.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc40-20020a1709071c2800b00732f83f9a17si8105166ejc.349.2022.08.30.02.31.57; Tue, 30 Aug 2022 02:32:33 -0700 (PDT) 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=@ionos.com header.s=google header.b=MDr2bJ1C; 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=ionos.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230336AbiH3IYG (ORCPT + 99 others); Tue, 30 Aug 2022 04:24:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230043AbiH3IYE (ORCPT ); Tue, 30 Aug 2022 04:24:04 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F49AA3D7D for ; Tue, 30 Aug 2022 01:23:58 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id z2so13201407edc.1 for ; Tue, 30 Aug 2022 01:23:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=mpUjxCyEhTu/Vrrq9HCqiAy81B12JY5DlQuis+EGEOg=; b=MDr2bJ1CbyLXhYi6zppIC7UWXfFIzwkollCWgwln4IgA0QGnokbrwiqTjaik/eXYT9 856bLTwXjSTvgsZOi1zwOozPmQGGUO8jttiPMpqItLONYPV6Gf1i9AI4yKBtft7O6KSd eeewRUA9tWENYiQQQG8IW9a9At0QYj40f6CwI3oJXONZJ6zlGydjZgeE7x9x11QPvn4q U217l+gOHGobaL3lsuuhaopvPvBy0qVDXkItHchyYo49aA96dw2zPrtjUDa/5APi8ggX LnsjfhjkDuedFoFBpVYjqqGOgiR4LqxThE+p7Gl1hAg3vNNb28fOQS7bNaZh/eDNad73 DF3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=mpUjxCyEhTu/Vrrq9HCqiAy81B12JY5DlQuis+EGEOg=; b=V+2ZnN8tVRQepe9cf917Yo42lX4AlwGWiPXxFLn9pHXdmi0SXd2utdoZre7QPiSQjf Pos1v2WpU6J5DyVjCk+VQ3s53QThli3nkMEjxdrhsluA+YVCvZm+8z6rAQ2RRHMdGMTW wQ9+ee0+iSvuvAqjZci3RDk8qMfBxc3LbmTypHc9T+Q30BoVVVI742J9Y96pKlOwrm3h FK2Mct0ilArNWmC0RoB4J3Pk7lYzfx0RY4uHzw3sB2bp4zyXXOt9AaK25mcEJf94z2U7 I7EXPQCgNnHCc3mK/57gRy3CeRhZRZOnCQg4j1RqTa+IvIWuKajQrbkk1aU0pbZj53J/ DvUQ== X-Gm-Message-State: ACgBeo084OtHMkFjozpWSu/UkzKbUBwQelZflAPgQuh+2Yu8ubY05zX8 YU9gv6ZkT10ARKYB0lTWjPZg3Ic4cqoqJg5MfnW3nCItHB1/PQ== X-Received: by 2002:a05:6402:42d3:b0:435:2c49:313d with SMTP id i19-20020a05640242d300b004352c49313dmr19348314edc.86.1661847836877; Tue, 30 Aug 2022 01:23:56 -0700 (PDT) MIME-Version: 1.0 References: <20220826095615.74328-1-jinpu.wang@ionos.com> <20220826095615.74328-3-jinpu.wang@ionos.com> In-Reply-To: From: Jinpu Wang Date: Tue, 30 Aug 2022 10:23:46 +0200 Message-ID: Subject: Re: [PATCH 2/2] RDMA: dma-mapping: Return an unsigned int from ib_dma_map_sg{,_attrs} To: Leon Romanovsky Cc: Christoph Hellwig , jgg@ziepe.ca, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Tue, Aug 30, 2022 at 10:01 AM Leon Romanovsky wrote: > > On Mon, Aug 29, 2022 at 03:19:14PM +0200, Jinpu Wang wrote: > > On Mon, Aug 29, 2022 at 2:06 PM Leon Romanovsky wrote: > > > > > > On Mon, Aug 29, 2022 at 11:40:40AM +0200, Jinpu Wang wrote: > > > > On Sun, Aug 28, 2022 at 1:09 PM Leon Romanovsky wrote: > > > > > > > > > > On Fri, Aug 26, 2022 at 11:56:15AM +0200, Jack Wang wrote: > > > > > > Following 2a047e0662ae ("dma-mapping: return an unsigned int from dma_map_sg{,_attrs}") > > > > > > change the return value of ib_dma_map_sg{,attrs} to unsigned int. > > > > > > > > > > > > Cc: Jason Gunthorpe > > > > > > Cc: Leon Romanovsky > > > > > > Cc: Christoph Hellwig > > > > > > Cc: linux-rdma@vger.kernel.org > > > > > > Cc: linux-kernel@vger.kernel.org > > > > > > > > > > > > Signed-off-by: Jack Wang > > > > > > --- > > > > > > drivers/infiniband/core/device.c | 2 +- > > > > > > include/rdma/ib_verbs.h | 6 +++--- > > > > > > 2 files changed, 4 insertions(+), 4 deletions(-) > > > > > > > > > > You forgot to change ib_dma_map_sgtable_attrs() and various > > > > > ib_dma_map_sg*() callers. > > > > No, they are different. > > > > ib_dma_map_sgtable_attrs and dma_map_sgtable return negative on errors. > > > > > > It is not the point. You changed ib_dma_virt_map_sg() to be unsigned, > > > so now the following lines are not correct: > > > > > > 4138 int nents; > > > 4139 > > > 4140 if (ib_uses_virt_dma(dev)) { > > > 4141 nents = ib_dma_virt_map_sg(dev, sgt->sgl, sgt->orig_nents); > > > > > > "int nents" should be changed to "unsigned int". > > > > > > Thanks > > ok, I can do it. > > just to check if we are on the same page: > > For all the callers of ib_dma_map_sg, would it be better to fix it > > one patch per driver or do it in a single bigger patch. > > I feel it's better to do it per driver, and there are drivers from > > different subsystems e.g. nvme/rds/etc. > > I don't know, everything here looks not nice to me. > > After commit 2a047e0662ae ("dma-mapping: return an unsigned int from dma_map_sg{,_attrs}"), > all callers left in limbo state where they expect that dma_map_sg{,_attrs} will return > upto INT_MAX. However now, the API can return upto UINT_MAX, which is not the case now > due to internal implementation of dma_map_sg_*(), but can be changed any second. > > Can we simply revert that commit and restore the "int" return type? > I don't see any benefit in having "unsigned int" if compiler doesn't enforce it. I feel different, the dma_map_sg api since the kernel 2.x, is documented in DMA-API.txt[1]: " int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, enum dma_data_direction direction) Returns: the number of physical segments mapped (this may be shorter than passed in if some elements of the scatter/gather list are physically or virtually adjacent and an IOMMU maps them with a single entry). Please note that the sg cannot be mapped again if it has been mapped once. The mapping process is allowed to destroy information in the sg. As with the other mapping interfaces, dma_map_sg can fail. When it does, 0 is returned and a driver must take appropriate action. It is critical that the driver do something, in the case of a block driver aborting the request or even oopsing is better than doing nothing and corrupting the filesystem. " It seems the return range for dma_map_sg never returns a negative value. I think it's just the API should have been defined to return "unsigned int" IMHO. We should update the documentation in the Documentation there too. in core-api/dma-api.rst [1] https://elixir.bootlin.com/linux/v2.6.39.4/source/Documentation/DMA-API.txt > > Thanks > > > > > Thx! > > > > > > > > > > > > > > > > > Thanks > > > > Thanks!