From patchwork Fri Aug 26 09:56:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 12955806 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3BFBECAAA3 for ; Fri, 26 Aug 2022 09:56:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245230AbiHZJ4a (ORCPT ); Fri, 26 Aug 2022 05:56:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343606AbiHZJ4V (ORCPT ); Fri, 26 Aug 2022 05:56:21 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5DF16F576 for ; Fri, 26 Aug 2022 02:56:19 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id r4so1447295edi.8 for ; Fri, 26 Aug 2022 02:56:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=VmzhV/ezSnvm4gL0tOSe/SBf3LXvGBx6QmleyHvvzqM=; b=di/mKF4/Aqk4vP4wxwvjqBC/nfcx39SifNToqtv4Ycjf9n0P2NBXylUe/59EdggY1d Hy1IwmIZteQOrwe5wo/vKlB2/CVx11SwsM9NsU5OfU4/wHiCqWSyybSZiRvMGqHo4Iu9 /Wxjce5jYDye3quXsQ9EcKSIGgbRaIYrNv2HMBlwDCM16bQj4yuY0yMiL+08lpvJN7WC bw25wIoa+LxB5hIATJv/8aksicbWQ8Z+X0TDxn55FIckQdLyy+qd/koMg68X8uxEJMnZ Jjk94Gk123JqEG5n4HQlBVWnXN8w+QyRV6zrauZamjZy9ObuskahWTnxdPQrFIF+9QTg sLTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=VmzhV/ezSnvm4gL0tOSe/SBf3LXvGBx6QmleyHvvzqM=; b=RaSDQ5e/iNPvSem6cPIlgoWVMXJVTE94a1myufs+CGbmP5vINTPzCm4pdjOHY/BIuJ 8tag8oRL2nM7ktUnicdYkbv5uPL0Lluj/x5d+1ZmXMIo7DQcQHiOfiG+4BOVgzzUhan4 qZCJr8Wx1KfMY/zX2OiDO6X9M11encNn6hMJQYoS7UBGJGH2MGUYQL8w/Q40hui1YUuY vi1eeSu8oxypquc8OMmKU+zErIXa4c/JerSNOWb9+HrDsIEmRrX8AqENTDq/ryrZNiFf /O0C5F0gY9NNJ3/w/SRBqInl5OCCCHfFwu9O7tTgp5D68uR9ZivwfZjpQ30M1bF3iX8E 3C5Q== X-Gm-Message-State: ACgBeo2Jk1IEXMBKdpoqt+993rnPgxD4t+n3wGX8HydxHMztt7sP1DGD 93sPqUhqHodYD4kM/CTwWSDAdw== X-Google-Smtp-Source: AA6agR4xZ/14nOsJNAugRCdiJqIASeZoRGxteR+jzRB3ElL4JkCO4jxYsE+Lj6arkreupBYHiTrENA== X-Received: by 2002:a05:6402:19:b0:447:901f:6b28 with SMTP id d25-20020a056402001900b00447901f6b28mr6051188edu.392.1661507778188; Fri, 26 Aug 2022 02:56:18 -0700 (PDT) Received: from lb02065.fritz.box ([2001:9e8:140d:2300:3a17:fa67:2b0b:b905]) by smtp.gmail.com with ESMTPSA id 1-20020a170906218100b007081282cbd8sm694826eju.76.2022.08.26.02.56.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 02:56:17 -0700 (PDT) From: Jack Wang To: jgg@ziepe.ca, leon@kernel.org, linux-rdma@vger.kernel.org Cc: Christophe JAILLET , Kees Cook , =?utf-8?q?H=C3=A5kon_Bugge?= , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] infiniband/mthca: Fix dma_map_sg error check Date: Fri, 26 Aug 2022 11:56:14 +0200 Message-Id: <20220826095615.74328-2-jinpu.wang@ionos.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826095615.74328-1-jinpu.wang@ionos.com> References: <20220826095615.74328-1-jinpu.wang@ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org dma_map_sg return 0 on error, in case of error set EIO as return code. Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: Christophe JAILLET Cc: Kees Cook Cc: "HÃ¥kon Bugge" Cc: linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org Fixes: 56483ec1b702 ("[PATCH] IB uverbs: add mthca user doorbell record support") Signed-off-by: Jack Wang Reviewed-by: Kees Cook --- drivers/infiniband/hw/mthca/mthca_memfree.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c index f2734a5c5f26..44fd5fdf64d5 100644 --- a/drivers/infiniband/hw/mthca/mthca_memfree.c +++ b/drivers/infiniband/hw/mthca/mthca_memfree.c @@ -189,7 +189,7 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages, chunk->npages, DMA_BIDIRECTIONAL); - if (chunk->nsg <= 0) + if (!chunk->nsg) goto fail; } @@ -208,7 +208,7 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages, chunk->nsg = dma_map_sg(&dev->pdev->dev, chunk->mem, chunk->npages, DMA_BIDIRECTIONAL); - if (chunk->nsg <= 0) + if (!chunk->nsg) goto fail; } @@ -482,8 +482,9 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar, ret = dma_map_sg(&dev->pdev->dev, &db_tab->page[i].mem, 1, DMA_TO_DEVICE); - if (ret < 0) { + if (!ret) { unpin_user_page(pages[0]); + ret = -EIO; goto out; } From patchwork Fri Aug 26 09:56:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 12955807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CABC4ECAAD8 for ; Fri, 26 Aug 2022 09:56:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245413AbiHZJ4a (ORCPT ); Fri, 26 Aug 2022 05:56:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343619AbiHZJ4W (ORCPT ); Fri, 26 Aug 2022 05:56:22 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F5A671701 for ; Fri, 26 Aug 2022 02:56:20 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id c93so1462896edf.5 for ; Fri, 26 Aug 2022 02:56:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=1OtudCFdOB5S7Toxd4SmAHP6iPCLN05Aag/oasSZDWA=; b=efRIhw++dqp6QLx+Q2w7pAGcxcUmskniao0oki8SgvSPc86uO3IxEmNXglFS27j2hT RjEQ67PugOZynFe2rpz3UzfqWJ0v2ZwHgr+0eikZqwn0GOwBYhYQCLhPEqnpk/nguZW8 Nkm/+lfEmSW/2+O1vFtUk+ySCwL1lYhaMmmsQhy01RZv2EHUC5ca99S/MlH+vfqvzpxG GGRzGM7pL1YnQJfEXSDoua7tkRY32VMkU9HPN/kpTpkt6jgdXzmufev6Ju9bcd+I1UUF 9bVKtRTcZi1cFiXdAZt3gDhO0hGEUxvCSuZsrGl32rZPw5QWQCEWnKNgP8u4sd+1PgBJ 5l6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=1OtudCFdOB5S7Toxd4SmAHP6iPCLN05Aag/oasSZDWA=; b=axmcH0DHtliyeQO3whvJo86peX7YoeD0rxcd8DFV4t42D6iZ5kgPtOfuB0iHArYoIk gSEHYGZypJwPTMG+l+jOzgV4kiLNdjyT8JK/HUvCbYH3n7Y0tO2o0RcFBoSPBwedsHv6 iCJLxoKELY8z/2iwYAiDnLP4209h+y3OFsfiF/3LL04aF4pS4MTBDkbeNnxo4jlnRgtp b2rIJZ6XgpEZPL8eqlm/Y/1InuUgntMMZGPLR0nuj7Fwlp2d7eP1Fnk6ABe8DJYVVZQM D21MVnR0xKS+aLHtRGP70cFYZCpVtBQgqZWZqL9y0BIpYHnQbPVvyapWlklKh6fFZnpi SNpQ== X-Gm-Message-State: ACgBeo0glh2d99fdO1Q4Rw11IXgQNdFQJdlmGQzUdOF27W2DspVXF0EY JE8ra0Ccr6xkz1Bo+9t0HP+Ekw== X-Google-Smtp-Source: AA6agR7Yqqg3A4Dbj2cSfbf06U2Z2J4BviHFEZdFKdknQy2IT0JEZsM/AVORLCAC3t51Cb+lLoMWeA== X-Received: by 2002:a05:6402:1943:b0:443:5ffb:b04e with SMTP id f3-20020a056402194300b004435ffbb04emr6139295edz.230.1661507779210; Fri, 26 Aug 2022 02:56:19 -0700 (PDT) Received: from lb02065.fritz.box ([2001:9e8:140d:2300:3a17:fa67:2b0b:b905]) by smtp.gmail.com with ESMTPSA id 1-20020a170906218100b007081282cbd8sm694826eju.76.2022.08.26.02.56.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 02:56:18 -0700 (PDT) From: Jack Wang To: jgg@ziepe.ca, leon@kernel.org, linux-rdma@vger.kernel.org Cc: Christoph Hellwig , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] RDMA: dma-mapping: Return an unsigned int from ib_dma_map_sg{,_attrs} Date: Fri, 26 Aug 2022 11:56:15 +0200 Message-Id: <20220826095615.74328-3-jinpu.wang@ionos.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826095615.74328-1-jinpu.wang@ionos.com> References: <20220826095615.74328-1-jinpu.wang@ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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(-) diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index d275db195f1a..72489294391d 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -2721,7 +2721,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops) EXPORT_SYMBOL(ib_set_device_ops); #ifdef CONFIG_INFINIBAND_VIRT_DMA -int ib_dma_virt_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents) +unsigned int ib_dma_virt_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents) { struct scatterlist *s; int i; diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 975d6e9efbcb..49256bf8cbf5 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -4101,8 +4101,8 @@ static inline void ib_dma_unmap_page(struct ib_device *dev, dma_unmap_page(dev->dma_device, addr, size, direction); } -int ib_dma_virt_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents); -static inline int ib_dma_map_sg_attrs(struct ib_device *dev, +unsigned int ib_dma_virt_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents); +static inline unsigned int ib_dma_map_sg_attrs(struct ib_device *dev, struct scatterlist *sg, int nents, enum dma_data_direction direction, unsigned long dma_attrs) @@ -4163,7 +4163,7 @@ static inline void ib_dma_unmap_sgtable_attrs(struct ib_device *dev, * @nents: The number of scatter/gather entries * @direction: The direction of the DMA */ -static inline int ib_dma_map_sg(struct ib_device *dev, +static inline unsigned int ib_dma_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents, enum dma_data_direction direction) {