Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp436552lqp; Tue, 11 Jun 2024 08:39:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUHYwCcAfgcia3pOb3qHYSz8ghdFImxmwCzYPfpf9tJAbhC0/6yJLS3W9GYv1Gvo+RSsncDvPeCPRwidoVk24tTOpOeQZbyutmBtX/xEw== X-Google-Smtp-Source: AGHT+IERJxpWOEb3ioTBCNUby3Ret25rv61wIJmk8dTD/Zr+axMIulEzzVRuDe7osuQbJsjwcflD X-Received: by 2002:a05:6a20:3204:b0:1a9:4055:6dce with SMTP id adf61e73a8af0-1b2f9e1bdc4mr11028960637.58.1718120376961; Tue, 11 Jun 2024 08:39:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718120376; cv=pass; d=google.com; s=arc-20160816; b=mU9Ze9iheosMI9Nax5TZNofk13xv+3YezAyDTfPkjPjXnPlRyyniVRZjbwDyVk1CHb FYqJ6zg1D/xZvAllKKiRefBFvRbuDU+NQ1E1rXX5yb+2tSQYZTv3p6KrRJva19SA7fNb 8Si+ED1sOd0XGNynWu488Ri+bLRtu4t2pOhblq+UC0Eajjb+PhCjNpYxmxp24h5k1aQf UOmoPoEfoy6PD4RhLsElPSDodtpUCuc5xyxIkXsOfxRtslrvMslpzrIpZlM72cJHzeH5 s0KtQ2JhjmAk3e1kJqkbswNzs0n83zCfPWKsyPjRoaT9P0xruBEik8fneL4wa2/SPJoY kG/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=U5eKz+uXHS08rNu2q2pWtoMhiDqRCnMlE/0QAMEdTDw=; fh=3UoOG683VS7Fhntxc7hv+2/ARXlqbRoosARFB55v8e0=; b=Ty/iP113HE9+46g+HTPIgfEgCvNIdfy+jp6GBXaEJiCTE1K5CBObbYqyx3x4fvcZzk 0V/6VajkiiB6TieWjX5ynb16M6Acw61M/qmwH/gViwaJjzCxhiOWi45Mikbp4ZJlHllg 39QyhJ296g0BD2vE673qTVzOzNWVVDF1cMosUW9HMtjmbLRd6XaRa2u3AFBO+VMyZXNS RHulR+SNwFwG2QrxFosY9DlH2eKQ1vHRZvojQA7ZR7XfTi+jqHcGzDdojZSHYg2hWGuU u6cFuTgRfHffolUQ5X1iAkFAOdCd+eeyIla1J28GQLZxAxzy9XjKgv38tkwXvawnvqft CuIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WeVRuVmZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-210166-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210166-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de2760652asi5516214a12.537.2024.06.11.08.39.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 08:39:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210166-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WeVRuVmZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-210166-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210166-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 40962281DD8 for ; Tue, 11 Jun 2024 15:39:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9D1339AFD; Tue, 11 Jun 2024 15:39:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WeVRuVmZ" 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 415D036AF5; Tue, 11 Jun 2024 15:39:10 +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=1718120351; cv=none; b=UgnFzsbLh6ugygmjskKiue+KqsmMpLIY1WmeW41Wo/ITTzLzNO15mKJggt9hk6RJ0O/n3Hbpr/hFOkP1nAJ//CH1XKojVYmapdaHMGthFA/stVmmZH9a8o4AO1KYrce7LmJnO+89x0YpaXMPb6p70Q1P4VVlkeqUyOmJl0hHGQY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718120351; c=relaxed/simple; bh=bbs0nZfYQResOgy6lgmjK0ssfkYQtU/jorgr5vVQcy4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BthZYYjlrwo4QQQsDvdsL/QNQobqBq6bpdNOzgCqi47/N1utTSezulcJCkLxRZVJoHQuImWmsbLBhhc6cR4bjIHpdm1J71hw9CqYPswfJMGpiZozK7uJ49msz/+YRR5rEfJ7orUwFSEO5lbH663tUGuEXY7yGStDvsoZHbPefvs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WeVRuVmZ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1846C4AF50; Tue, 11 Jun 2024 15:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718120350; bh=bbs0nZfYQResOgy6lgmjK0ssfkYQtU/jorgr5vVQcy4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WeVRuVmZNJeBvFynafLllgaQ1sTe/TVDnO5VctQIcUSYQOEU6L/J/vJOIjwNzo3A7 3Dtzy1al9A2/Tr6AlxBQt4JBTgsYowYoL2Bv6Z/KtfTMP8dSDRFtWh0392Fmf3JF2k fKMz6OPHX2kvVcFojWdEXOXyw1HagFioPBsKsg65MLpyRx/2GOiSJx0A+nqbPJbV3u A95bFHYsXOdOXRQyF3QNS9yP76xBy7lpFSCBIR/2jJ1QAeLiUXqF71va2CbrHX8VKl uDjBRTCBn4VAxYQHsvExW6kvFQKq+NKp70xE3plLwPZSkFgB4mIj/paMAwzoxmxS3u c+uVU5d1JvTpg== Date: Tue, 11 Jun 2024 18:39:05 +0300 From: Leon Romanovsky To: "Zeng, Oak" Cc: Jason Gunthorpe , Christoph Hellwig , Robin Murphy , Marek Szyprowski , Joerg Roedel , Will Deacon , Chaitanya Kulkarni , "Brost, Matthew" , "Hellstrom, Thomas" , Jonathan Corbet , Jens Axboe , Keith Busch , Sagi Grimberg , Yishai Hadas , Shameer Kolothum , "Tian, Kevin" , Alex Williamson , =?iso-8859-1?B?Suly9G1l?= Glisse , 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" , "Williams, Dan J" , "jack@suse.com" , Zhu Yanjun , "Bommu, Krishnaiah" , "Ghimiray, Himal Prasad" Subject: Re: [RFC RESEND 00/16] Split IOMMU DMA mapping operation to two steps Message-ID: <20240611153905.GB4966@unreal> References: <20240503164239.GB901876@ziepe.ca> <20240610161826.GA4966@unreal> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, Jun 10, 2024 at 04:40:19PM +0000, Zeng, Oak wrote: > Thanks Leon and Yanjun for the reply! > > Based on the reply, we will continue use the current version for test (as it is tested for vfio and rdma). We will switch to v1 once it is fully tested/reviewed. Sounds good, if v0 fits your need, the v1 will fit it too. From HMM perspective, the change is minimal between them. In v0, I called to dma_link_page() here and now it is called dma_hmm_link_page(). https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git/diff/drivers/infiniband/hw/mlx5/odp.c?h=dma-split-v1&id=a0d719a406133cdc3ef2328dda3ef082a034c45e > > Thanks, > Oak > > > -----Original Message----- > > From: Leon Romanovsky > > Sent: Monday, June 10, 2024 12:18 PM > > To: Zeng, Oak > > Cc: Jason Gunthorpe ; Christoph Hellwig ; Robin > > Murphy ; Marek Szyprowski > > ; Joerg Roedel ; Will > > Deacon ; Chaitanya Kulkarni ; > > Brost, Matthew ; Hellstrom, Thomas > > ; Jonathan Corbet ; Jens > > Axboe ; Keith Busch ; Sagi > > Grimberg ; Yishai Hadas ; > > Shameer Kolothum ; Tian, Kevin > > ; Alex Williamson ; > > J?r?me Glisse ; Andrew Morton > foundation.org>; 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; Williams, Dan J > > ; jack@suse.com; Zhu Yanjun > > ; Bommu, Krishnaiah > > ; Ghimiray, Himal Prasad > > > > Subject: Re: [RFC RESEND 00/16] Split IOMMU DMA mapping operation to > > two steps > > > > On Mon, Jun 10, 2024 at 03:12:25PM +0000, Zeng, Oak wrote: > > > Hi Jason, Leon, > > > > > > I come back to this thread to ask a question. Per the discussion in another > > thread, I have integrated the new dma-mapping API (the first 6 patches of > > this series) to DRM subsystem. The new API seems fit pretty good to our > > purpose, better than scatter-gather dma-mapping. So we want to continue > > work with you to adopt this new API. > > > > Sounds great, thanks for the feedback. > > > > > > > > Did you test the new API in RDMA subsystem? > > > > This version was tested in our regression tests, but there is a chance > > that you are hitting flows that were not relevant for RDMA case. > > > > > Or this RFC series was just some untested codes sending out to get > > people's design feedback? > > > > RFC was fully tested in VFIO and RDMA paths, but not NVMe patch. > > > > > Do you have refined version for us to try? I ask because we are seeing > > some issues but not sure whether it is caused by the new API. We are > > debugging but it would be good to also ask at the same time. > > > > Yes, as an outcome of the feedback in this thread, I implemented a new > > version. Unfortunately, there are some personal matters that are preventing > > from me to send it right away. > > https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux- > > rdma.git/log/?h=dma-split-v1 > > > > There are some differences in the API, but the main idea is the same. > > This version is not fully tested yet. > > > > Thanks > > > > > > > > Cc Himal/Krishna who are also working/testing the new API. > > > > > > Thanks, > > > Oak > > > > > > > -----Original Message----- > > > > From: Jason Gunthorpe > > > > Sent: Friday, May 3, 2024 12:43 PM > > > > To: Zeng, Oak > > > > Cc: leon@kernel.org; Christoph Hellwig ; Robin Murphy > > > > ; Marek Szyprowski > > > > ; Joerg Roedel ; Will > > > > Deacon ; Chaitanya Kulkarni ; > > > > Brost, Matthew ; Hellstrom, Thomas > > > > ; Jonathan Corbet ; > > Jens > > > > Axboe ; Keith Busch ; Sagi > > > > Grimberg ; Yishai Hadas ; > > > > Shameer Kolothum ; Tian, > > Kevin > > > > ; Alex Williamson ; > > > > J?r?me Glisse ; Andrew Morton > > > foundation.org>; 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; Williams, Dan J > > > > ; jack@suse.com; Leon Romanovsky > > > > ; Zhu Yanjun > > > > Subject: Re: [RFC RESEND 00/16] Split IOMMU DMA mapping operation to > > > > two steps > > > > > > > > On Thu, May 02, 2024 at 11:32:55PM +0000, Zeng, Oak wrote: > > > > > > > > > > Instead of teaching DMA to know these specific datatypes, let's > > separate > > > > > > existing DMA mapping routine to two steps and give an option to > > > > advanced > > > > > > callers (subsystems) perform all calculations internally in advance and > > > > > > map pages later when it is needed. > > > > > > > > > > I looked into how this scheme can be applied to DRM subsystem and > > GPU > > > > drivers. > > > > > > > > > > I figured RDMA can apply this scheme because RDMA can calculate the > > > > > iova size. Per my limited knowledge of rdma, user can register a > > > > > memory region (the reg_user_mr vfunc) and memory region's sized is > > > > > used to pre-allocate iova space. And in the RDMA use case, it seems > > > > > the user registered region can be very big, e.g., 512MiB or even GiB > > > > > > > > In RDMA the iova would be linked to the SVA granual we discussed > > > > previously. > > > > > > > > > In GPU driver, we have a few use cases where we need dma-mapping. > > Just > > > > name two: > > > > > > > > > > 1) userptr: it is user malloc'ed/mmap'ed memory and registers to gpu > > > > > (in Intel's driver it is through a vm_bind api, similar to mmap). A > > > > > userptr can be of any random size, depending on user malloc > > > > > size. Today we use dma-map-sg for this use case. The down side of > > > > > our approach is, during userptr invalidation, even if user only > > > > > munmap partially of an userptr, we invalidate the whole userptr from > > > > > gpu page table, because there is no way for us to partially > > > > > dma-unmap the whole sg list. I think we can try your new API in this > > > > > case. The main benefit of the new approach is the partial munmap > > > > > case. > > > > > > > > Yes, this is one of the main things it will improve. > > > > > > > > > We will have to pre-allocate iova for each userptr, and we have many > > > > > userptrs of random size... So we might be not as efficient as RDMA > > > > > case where I assume user register a few big memory regions. > > > > > > > > You are already doing this. dma_map_sg() does exactly the same IOVA > > > > allocation under the covers. > > > > > > > > > 2) system allocator: it is malloc'ed/mmap'ed memory be used for GPU > > > > > program directly, without any other extra driver API call. We call > > > > > this use case system allocator. > > > > > > > > > For system allocator, driver have no knowledge of which virtual > > > > > address range is valid in advance. So when GPU access a > > > > > malloc'ed/mmap'ed address, we have a page fault. We then look up a > > > > > CPU vma which contains the fault address. I guess we can use the CPU > > > > > vma size to allocate the iova space of the same size? > > > > > > > > No. You'd follow what we discussed in the other thread. > > > > > > > > If you do a full SVA then you'd split your MM space into granuals and > > > > when a fault hits a granual you'd allocate the IOVA for the whole > > > > granual. RDMA ODP is using a 512M granual currently. > > > > > > > > If you are doing sub ranges then you'd probably allocate the IOVA for > > > > the well defined sub range (assuming the typical use case isn't huge) > > > > > > > > > But there will be a true difficulty to apply your scheme to this use > > > > > case. It is related to the STICKY flag. As I understand it, the > > > > > sticky flag is designed for driver to mark "this page/pfn has been > > > > > populated, no need to re-populate again", roughly...Unlike userptr > > > > > and RDMA use cases where the backing store of a buffer is always in > > > > > system memory, in the system allocator use case, the backing store > > > > > can be changing b/t system memory and GPU's device private > > > > > memory. Even worse, we have to assume the data migration b/t > > system > > > > > and GPU is dynamic. When data is migrated to GPU, we don't need > > > > > dma-map. And when migration happens to a pfn with STICKY flag, we > > > > > still need to repopulate this pfn. So you can see, it is not easy to > > > > > apply this scheme to this use case. At least I can't see an obvious > > > > > way. > > > > > > > > You are already doing this today, you are keeping the sg list around > > > > until you unmap it. > > > > > > > > Instead of keeping the sg list you'd keep a much smaller datastructure > > > > per-granual. The sticky bit is simply a convient way for ODP to manage > > > > the smaller data structure, you don't have to use it. > > > > > > > > But you do need to keep track of what pages in the granual have been > > > > DMA mapped - sg list was doing this before. This could be a simple > > > > bitmap array matching the granual size. > > > > > > > > Looking (far) forward we may be able to have a "replace" API that > > > > allows installing a new page unconditionally regardless of what is > > > > already there. > > > > > > > > Jason