Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2398483lqp; Sun, 24 Mar 2024 17:47:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXT+oJJb7T+wTUJ9yDoJZJB/mWj+WgbvRKoxTYPLdBpu78sUbDcGNqVjYR3ivaPKXftdzhyXuijJcygJ1+NIozMm0DRQNUGHHu4k7YbWQ== X-Google-Smtp-Source: AGHT+IHZh1vq0A/ldBGKFBy/et54TSUukD77Xke0TGFmzt4hrgTvX486v2t4T5Z7NUaNCp0936By X-Received: by 2002:a05:620a:4e8:b0:789:eccd:cb4e with SMTP id b8-20020a05620a04e800b00789eccdcb4emr5818839qkh.36.1711327655579; Sun, 24 Mar 2024 17:47:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711327655; cv=pass; d=google.com; s=arc-20160816; b=a51t9AfigBhReor9Tya8uWfVUKP1QzrbrMuUR2GvYpUyqqNhG1tVlAFlIrFkq9ne0a LVQd2DyLvMOr2UVAm+cs5jFgIkrvl2VzqiwShXWCDDs9lo96LNwKPH4rxtErrDLMB8YV 8u6Zj4UoxDGWmu9+GQcZvT18n1I5aCGNYPW1P4PSDS0CH0RjHkDRhUFGcJ7JnPRKFtA1 RTHrlBwTm7qZiC+Jxn6hndOvan2BNNjmyZb0vPoqeZAbvIeTTWNsf4uiFyZfGuNEbWa+ sxioJ1K0tAXUPICudVhYHMluivC9JcbufNqF+BNWwL7L2EB7qVbGxY+aJIU5JEyKmPuz qThw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vJQ67AokslxfqyGDlCJJp8aP70AcarWKqnsGUs+EKaw=; fh=oJnwsA2Y+4W1zx1g5Lcp/6icMGis5iIjoXML358XwWg=; b=bRLAXa1d2RHwInedNwA574Q13aldDk3zlWSHaefyA5NeLGtzJAdctMUZ7xCw+pg0Yq tJ/GFo0zqBfLqHbIjV9tRpFXa5xX7q95tG/UA44Yj4BhnxebRxoCkGs06lPYIwRRYx97 XPyKQ4KwhaEjnvFnJUQCUSaEf21TnhkocYlBmtHwtOnXBezE+jdFbpE+bY2t+wiDIjsm eXRfTbgqRkT7hzGSnyPfwzb8MkdHXC2ehDquWG7GJvzVMgPUr6CAvwOrD7+Hw6OypKIg 2VS1+a0o5IlXNKUEWNQhVm3MDEPdgpkwGX7gouo9zEbSGM32dONO2OnaxxyXteA+5mGw aPTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kHIa8154; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113480-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113480-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id cx13-20020a05620a51cd00b00789e7ef11f9si4489248qkb.586.2024.03.24.17.47.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:47:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113480-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kHIa8154; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113480-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113480-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 38E9B1C23D45 for ; Mon, 25 Mar 2024 00:47:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A1901B4C06; Sun, 24 Mar 2024 22:44:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kHIa8154" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5864B13CFAD; Sun, 24 Mar 2024 22:44:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320281; cv=none; b=h5Zc/J2nf6wsbaNVClC3SpnBmO5FlFdL3QH2vh90R9+dpHiBqjPGDTFG9as9OgzniJRDQtzJd0MaCaN8FRW8tCxiGkySTcTW9XUR+PGaOKaoDvdfSqQdyHHMjkRdXXvr4vFCfPatVhbGTUk9hnA07I0KbDJDumbnAdAIMlkmn98= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320281; c=relaxed/simple; bh=yjLYgT5qBCA+qUBcthLTka4Zl8Zq8SMNFOCI+pGEgHA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kgPatP+0EJdo5O0Iwsb7shAZHiV+TuxYBjWeyFP5UcWxY7iFU/Grx09jI1etdBAd3Bx/xSFZQICaa0jAomruh1fDIHqrvM2EEq7VczHZEAORTLV5UBookfV3uS0iz3mxNvRYf3lGn1Iluzx1SGO0a2CL1Khk43obWVWaN+ZWMfo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kHIa8154; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27177C43394; Sun, 24 Mar 2024 22:44:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320281; bh=yjLYgT5qBCA+qUBcthLTka4Zl8Zq8SMNFOCI+pGEgHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kHIa8154sFPH0ED9r8XzRjziYIIRwZSskvTIqp8xxd6BbkfPUzcbqO0y21G0Xkb38 X6PQAmgTv2tYklbkiwhbpX/HUX2LEcSHtAavXTsszPC9zZldptT4b/DDsh5FKXuy/g efha8XhspHr2PsdyQtD/7GHGP7yjEDxqQW+nO2Ii2dsT6z8lebTRR6pFNcv4XzOc3o Je71JkaLF/IxzLbyXAwh9GVLhgTxqhMS0Oyj5ZS0yVjtT683vAW0HyLNqG6iOqnzHf x75xEb9BXb+b4g94Dw/cPpOI3dTVGxXHP2apjfsJpdzuOqdw4VqfMePcrnw9irMYTU oWsL9CNcRE97w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Konstantin Taranov , Zhu Yanjun , Leon Romanovsky , Sasha Levin Subject: [PATCH 6.8 589/715] RDMA/mana_ib: Use virtual address in dma regions for MRs Date: Sun, 24 Mar 2024 18:32:48 -0400 Message-ID: <20240324223455.1342824-590-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Konstantin Taranov [ Upstream commit 2d5c00815778ec4f4e0a84e405e3e157b7815db1 ] Introduce mana_ib_create_dma_region() to create dma regions with iova for MRs. It allows creating MRs with any page offset. Previously, only page-aligned addresses worked. For dma regions that must have a zero dma offset (e.g., for queues), mana_ib_create_zero_offset_dma_region() is added. To get the zero offset, ib_umem_find_best_pgoff() is used with zero pgoff_bitmask. Fixes: 0266a177631d ("RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter") Signed-off-by: Konstantin Taranov Link: https://lore.kernel.org/r/1709560361-26393-3-git-send-email-kotaranov@linux.microsoft.com Reviewed-by: Zhu Yanjun Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/hw/mana/cq.c | 4 +-- drivers/infiniband/hw/mana/main.c | 40 +++++++++++++++++++++------- drivers/infiniband/hw/mana/mana_ib.h | 7 +++-- drivers/infiniband/hw/mana/mr.c | 4 +-- drivers/infiniband/hw/mana/qp.c | 6 ++--- drivers/infiniband/hw/mana/wq.c | 4 +-- 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/cq.c index 83d20c3f048df..4a71e678d09c1 100644 --- a/drivers/infiniband/hw/mana/cq.c +++ b/drivers/infiniband/hw/mana/cq.c @@ -48,7 +48,7 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, return err; } - err = mana_ib_gd_create_dma_region(mdev, cq->umem, &cq->gdma_region); + err = mana_ib_create_zero_offset_dma_region(mdev, cq->umem, &cq->gdma_region); if (err) { ibdev_dbg(ibdev, "Failed to create dma region for create cq, %d\n", @@ -57,7 +57,7 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, } ibdev_dbg(ibdev, - "mana_ib_gd_create_dma_region ret %d gdma_region 0x%llx\n", + "create_dma_region ret %d gdma_region 0x%llx\n", err, cq->gdma_region); /* diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c index dd570832d61ea..71e33feee61bb 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -301,8 +301,8 @@ mana_ib_gd_add_dma_region(struct mana_ib_dev *dev, struct gdma_context *gc, return 0; } -int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, - mana_handle_t *gdma_region) +static int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, + mana_handle_t *gdma_region, unsigned long page_sz) { struct gdma_dma_region_add_pages_req *add_req = NULL; size_t num_pages_processed = 0, num_pages_to_handle; @@ -314,7 +314,6 @@ int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, size_t max_pgs_create_cmd; struct gdma_context *gc; size_t num_pages_total; - unsigned long page_sz; unsigned int tail = 0; u64 *page_addr_list; void *request_buf; @@ -323,12 +322,6 @@ int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, gc = mdev_to_gc(dev); hwc = gc->hwc.driver_data; - /* Hardware requires dma region to align to chosen page size */ - page_sz = ib_umem_find_best_pgsz(umem, PAGE_SZ_BM, 0); - if (!page_sz) { - ibdev_dbg(&dev->ib_dev, "failed to find page size.\n"); - return -ENOMEM; - } num_pages_total = ib_umem_num_dma_blocks(umem, page_sz); max_pgs_create_cmd = @@ -414,6 +407,35 @@ int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, return err; } +int mana_ib_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, + mana_handle_t *gdma_region, u64 virt) +{ + unsigned long page_sz; + + page_sz = ib_umem_find_best_pgsz(umem, PAGE_SZ_BM, virt); + if (!page_sz) { + ibdev_dbg(&dev->ib_dev, "Failed to find page size.\n"); + return -EINVAL; + } + + return mana_ib_gd_create_dma_region(dev, umem, gdma_region, page_sz); +} + +int mana_ib_create_zero_offset_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, + mana_handle_t *gdma_region) +{ + unsigned long page_sz; + + /* Hardware requires dma region to align to chosen page size */ + page_sz = ib_umem_find_best_pgoff(umem, PAGE_SZ_BM, 0); + if (!page_sz) { + ibdev_dbg(&dev->ib_dev, "Failed to find page size.\n"); + return -EINVAL; + } + + return mana_ib_gd_create_dma_region(dev, umem, gdma_region, page_sz); +} + int mana_ib_gd_destroy_dma_region(struct mana_ib_dev *dev, u64 gdma_region) { struct gdma_context *gc = mdev_to_gc(dev); diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/mana/mana_ib.h index 6a03ae645c012..f83390eebb7d7 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -160,8 +160,11 @@ static inline struct net_device *mana_ib_get_netdev(struct ib_device *ibdev, u32 int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq); -int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, - mana_handle_t *gdma_region); +int mana_ib_create_zero_offset_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, + mana_handle_t *gdma_region); + +int mana_ib_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, + mana_handle_t *gdma_region, u64 virt); int mana_ib_gd_destroy_dma_region(struct mana_ib_dev *dev, mana_handle_t gdma_region); diff --git a/drivers/infiniband/hw/mana/mr.c b/drivers/infiniband/hw/mana/mr.c index ee4d4f83467c8..b70b13484f097 100644 --- a/drivers/infiniband/hw/mana/mr.c +++ b/drivers/infiniband/hw/mana/mr.c @@ -127,7 +127,7 @@ struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 length, goto err_free; } - err = mana_ib_gd_create_dma_region(dev, mr->umem, &dma_region_handle); + err = mana_ib_create_dma_region(dev, mr->umem, &dma_region_handle, iova); if (err) { ibdev_dbg(ibdev, "Failed create dma region for user-mr, %d\n", err); @@ -135,7 +135,7 @@ struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 length, } ibdev_dbg(ibdev, - "mana_ib_gd_create_dma_region ret %d gdma_region %llx\n", err, + "create_dma_region ret %d gdma_region %llx\n", err, dma_region_handle); mr_params.pd_handle = pd->pd_handle; diff --git a/drivers/infiniband/hw/mana/qp.c b/drivers/infiniband/hw/mana/qp.c index 5d4c05dcd0032..6e7627745c957 100644 --- a/drivers/infiniband/hw/mana/qp.c +++ b/drivers/infiniband/hw/mana/qp.c @@ -357,8 +357,8 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd, } qp->sq_umem = umem; - err = mana_ib_gd_create_dma_region(mdev, qp->sq_umem, - &qp->sq_gdma_region); + err = mana_ib_create_zero_offset_dma_region(mdev, qp->sq_umem, + &qp->sq_gdma_region); if (err) { ibdev_dbg(&mdev->ib_dev, "Failed to create dma region for create qp-raw, %d\n", @@ -367,7 +367,7 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd, } ibdev_dbg(&mdev->ib_dev, - "mana_ib_gd_create_dma_region ret %d gdma_region 0x%llx\n", + "create_dma_region ret %d gdma_region 0x%llx\n", err, qp->sq_gdma_region); /* Create a WQ on the same port handle used by the Ethernet */ diff --git a/drivers/infiniband/hw/mana/wq.c b/drivers/infiniband/hw/mana/wq.c index 372d361510e0c..7c9c699625734 100644 --- a/drivers/infiniband/hw/mana/wq.c +++ b/drivers/infiniband/hw/mana/wq.c @@ -46,7 +46,7 @@ struct ib_wq *mana_ib_create_wq(struct ib_pd *pd, wq->wq_buf_size = ucmd.wq_buf_size; wq->rx_object = INVALID_MANA_HANDLE; - err = mana_ib_gd_create_dma_region(mdev, wq->umem, &wq->gdma_region); + err = mana_ib_create_zero_offset_dma_region(mdev, wq->umem, &wq->gdma_region); if (err) { ibdev_dbg(&mdev->ib_dev, "Failed to create dma region for create wq, %d\n", @@ -55,7 +55,7 @@ struct ib_wq *mana_ib_create_wq(struct ib_pd *pd, } ibdev_dbg(&mdev->ib_dev, - "mana_ib_gd_create_dma_region ret %d gdma_region 0x%llx\n", + "create_dma_region ret %d gdma_region 0x%llx\n", err, wq->gdma_region); /* WQ ID is returned at wq_create time, doesn't know the value yet */ -- 2.43.0