Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp334282lqs; Tue, 5 Mar 2024 03:37:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWll9x0tELQoVedXAXJ4l2hGgX5fZaKlZNhxwbH6LhN0Lohl57QETUu3BSpVTxXypPj65/lmdx59/L62nsjcHmyFs8wtqsamxOfjPyb2w== X-Google-Smtp-Source: AGHT+IHk9A3s3y8iIoj+VhjlCmxjVHLkFXZZJbzHAO+bUYbdrV8p01COrvj57AE4uk4/Qh0OAbSX X-Received: by 2002:a05:6a20:9587:b0:1a1:48df:e19a with SMTP id iu7-20020a056a20958700b001a148dfe19amr1753677pzb.35.1709638643397; Tue, 05 Mar 2024 03:37:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709638643; cv=pass; d=google.com; s=arc-20160816; b=hVsRSMP9elHrU52OqH894nDvdC4JJr945UCckttPJDnIqT3MC7UDvjbpoXTl/RwFW7 9VnfvUe2dDF3Nz1z0LfnIsbPqkooajXz8gpEB1LVOe0P63nTeb9ybFJakviy38AREa5R oMlUEmlpIxRPGjVit+QMI2RK+dfvpbwOt99mK7pkZxPf1mTDCtURCLy3lTWczIotwv7C 5ymzCRBRKdsdUAzSovY4rDM4+gn5Gn+CoR9yeFIa+xvRnkCDa6aZdccgtNcmAj/EjTxp LX0OlacDs4BhnIkrZcFlQrgH7xqWXx4aPFCVVKMcVdP85xEfanZs/91R8j9lP+Ztu0dp OF9Q== 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=zYSEuAz/VcQQ9oYOdYsxLecJdgLxoOHzBKYScKbWY7E=; fh=q7c0K0LtlTicAt6eDmJJJM50IJoKBwH/AvPNHUILEIs=; b=YVpxf9XbEyCE4KM+Wndz8BtHjSdqfpHJAwhrrzZASi4YYhgi+9edOOkzHFaF70dM2x 7Tr7iEVFJf+LAyWX1xqLy1N7CAJR0KGTa+kdm6Y9JTPumh76QtB/8nts3rgVmZzmZ30q igJn8eWOdEvukqYMiU5yu7dNb3229G1DOwGbNWzOm+NDyRg98AOEGhaSkz0PbwbCzs/y 734+tsTD2rTHglnRYwwOJOh2K0YQM4jy9WPsujQT4U0blaXcrbKOYjG6k4pNt69mJD18 gVf7Y9TaNGZblEGeObox1Pullo0yh7mG+kIqbM+4Zo+iTXiCQETg+d8qPzq3kvN0OFBv 87iQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=caYziKGN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-92245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r2-20020a635142000000b005d8e1dc1df8si9857999pgl.705.2024.03.05.03.37.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 03:37:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-92245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=caYziKGN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-92245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92245-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 91C9AB24FB2 for ; Tue, 5 Mar 2024 11:22:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03ED157327; Tue, 5 Mar 2024 11:19:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="caYziKGN" 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 15B4157308; Tue, 5 Mar 2024 11:19:22 +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=1709637563; cv=none; b=T/LcYuKaCDToooEoiq4b3qqGGwkexnZlp68JYLJEvHdtd86biJRU8FF4/GI9yrQNguatGALSutzdYhqV8a3xp0nNoDJXjGVoHSXVIkLbUbbsnJsC5krhCSR8wF193yHLD5HPAMTGPMA4KGlSyHXbcDoeW+baQkdl6eGzLx/f2PA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709637563; c=relaxed/simple; bh=E8ahaIx2eHfPJk0G81HhbupoEvLGKO0ealmbIxFQ2TY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gq5u7H2qAj1A3zfeVkXXLRbRwZdL91E0AdU87VAUj2qQH3UAN9a4bTdvziFgyP0KgnbBoGWXqo+aw9+HV3B2HkYdlqBfkPAFcsgicR4SkvzQPUg5ZwINPGKUc7kS21vxIDCm+PqoV783mgxvCyMXvF32fX8joZD3LPafDTEgAYU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=caYziKGN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFF43C433F1; Tue, 5 Mar 2024 11:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709637562; bh=E8ahaIx2eHfPJk0G81HhbupoEvLGKO0ealmbIxFQ2TY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=caYziKGN4nQ6kN+9eq9OdBuTlgubm0Pb0jxPUg1nvKbDYZ7pFGIzeYrAmlE6IxeVv 746C+LqlVHPQ4dDcVQlVgnA2EHmFaCDoMqB8C5Q3zAXCesOehVRaHHoJvjmHc8io+k obH2BT5XHaaCbjd0RRi0CnpJ0GsTLZmOM8Vs7UUadTlXpFB9Su+dS65MTkhFtRA1TV uwDMsDHNaOVKiuMmBctORC3dngSDNkvdEz9cizg0F/CI1eZqzIjMskfyTBmd3Z/pDN Z1OLKXLVUURP5juEVvIRb6GwritonO9eAzr+ppm65LjXs9YffyvBUxqeu9hjdFCa+0 wMe/HvMTuqPEQ== From: Leon Romanovsky To: Christoph Hellwig , Robin Murphy , Marek Szyprowski , Joerg Roedel , Will Deacon , Jason Gunthorpe , Chaitanya Kulkarni Cc: Leon Romanovsky , Jonathan Corbet , Jens Axboe , Keith Busch , Sagi Grimberg , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Andrew Morton , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, linux-nvme@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, Bart Van Assche , Damien Le Moal , Amir Goldstein , "josef@toxicpanda.com" , "Martin K. Petersen" , "daniel@iogearbox.net" , Dan Williams , "jack@suse.com" , Zhu Yanjun Subject: [RFC RESEND 07/16] RDMA/umem: Preallocate and cache IOVA for UMEM ODP Date: Tue, 5 Mar 2024 13:18:38 +0200 Message-ID: <47cc27fbaf9f4bd19edbcaac380bdd9684c5d12f.1709635535.git.leon@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Leon Romanovsky As a preparation to provide two step interface to map pages, preallocate IOVA when UMEM is initialized. Signed-off-by: Leon Romanovsky --- drivers/infiniband/core/umem_odp.c | 16 +++++++++++++++- include/rdma/ib_umem_odp.h | 1 + include/rdma/ib_verbs.h | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c index e9fa22d31c23..f69d1233dc82 100644 --- a/drivers/infiniband/core/umem_odp.c +++ b/drivers/infiniband/core/umem_odp.c @@ -50,6 +50,7 @@ static inline int ib_init_umem_odp(struct ib_umem_odp *umem_odp, const struct mmu_interval_notifier_ops *ops) { + struct ib_device *dev = umem_odp->umem.ibdev; int ret; umem_odp->umem.is_odp = 1; @@ -87,15 +88,25 @@ static inline int ib_init_umem_odp(struct ib_umem_odp *umem_odp, goto out_pfn_list; } + umem_odp->iova.dev = dev->dma_device; + umem_odp->iova.size = end - start; + umem_odp->iova.dir = DMA_BIDIRECTIONAL; + ret = ib_dma_alloc_iova(dev, &umem_odp->iova); + if (ret) + goto out_dma_list; + + ret = mmu_interval_notifier_insert(&umem_odp->notifier, umem_odp->umem.owning_mm, start, end - start, ops); if (ret) - goto out_dma_list; + goto out_free_iova; } return 0; +out_free_iova: + ib_dma_free_iova(dev, &umem_odp->iova); out_dma_list: kvfree(umem_odp->dma_list); out_pfn_list: @@ -262,6 +273,8 @@ EXPORT_SYMBOL(ib_umem_odp_get); void ib_umem_odp_release(struct ib_umem_odp *umem_odp) { + struct ib_device *dev = umem_odp->umem.ibdev; + /* * Ensure that no more pages are mapped in the umem. * @@ -274,6 +287,7 @@ void ib_umem_odp_release(struct ib_umem_odp *umem_odp) ib_umem_end(umem_odp)); mutex_unlock(&umem_odp->umem_mutex); mmu_interval_notifier_remove(&umem_odp->notifier); + ib_dma_free_iova(dev, &umem_odp->iova); kvfree(umem_odp->dma_list); kvfree(umem_odp->pfn_list); } diff --git a/include/rdma/ib_umem_odp.h b/include/rdma/ib_umem_odp.h index 0844c1d05ac6..bb2d7f2a5b04 100644 --- a/include/rdma/ib_umem_odp.h +++ b/include/rdma/ib_umem_odp.h @@ -23,6 +23,7 @@ struct ib_umem_odp { * See ODP_READ_ALLOWED_BIT and ODP_WRITE_ALLOWED_BIT. */ dma_addr_t *dma_list; + struct dma_iova_attrs iova; /* * The umem_mutex protects the page_list and dma_list fields of an ODP * umem, allowing only a single thread to map/unmap pages. The mutex diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index b7b6b58dd348..e71fa19187cc 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -4077,6 +4077,24 @@ static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr) return dma_mapping_error(dev->dma_device, dma_addr); } +static inline int ib_dma_alloc_iova(struct ib_device *dev, + struct dma_iova_attrs *iova) +{ + if (ib_uses_virt_dma(dev)) + return 0; + + return dma_alloc_iova(iova); +} + +static inline void ib_dma_free_iova(struct ib_device *dev, + struct dma_iova_attrs *iova) +{ + if (ib_uses_virt_dma(dev)) + return; + + dma_free_iova(iova); +} + /** * ib_dma_map_single - Map a kernel virtual address to DMA address * @dev: The device for which the dma_addr is to be created -- 2.44.0