Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp467468lqp; Mon, 10 Jun 2024 09:18:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeYVX+JQnzLOm5FBtCgnYYHRUtZ8LK0Vij45uIG3UD7WPwUhwYiGAQkNnez+txiXznOwIv1pLMpVqKxqkodNr7BqUktHGLaFBTae1CLQ== X-Google-Smtp-Source: AGHT+IGvB1bZB7JgItK80u8azeN/Gw/sae1P8JCESHtZDRKX+BtcgvmnCZUK4uhW5VwGlLa1LGL0 X-Received: by 2002:a05:622a:1aa0:b0:440:5dab:8a5a with SMTP id d75a77b69052e-4405dab8fa4mr68911451cf.31.1718036328790; Mon, 10 Jun 2024 09:18:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718036328; cv=pass; d=google.com; s=arc-20160816; b=mVRrHe2uYkt4JSwhIOo7KekgUodgsdlPHtXhVocm38CxouiAdO9Ms9SK7jxRSHp9AK EqZ3oit2wFkXsBl10W0klBOI1ai+UbYiZJQUzG73fJRpejGvSjNSRfJ16R4YNUEcOLJo CmVuyMqDSlyq0EnaAVG6hZdrfX8Fu8sod32cD+rZm/oeTwhOw0gnSCWZODHbXzUF5vx+ XWoOpWSlRmuyNox5o8PHpWDfISITHxybWfhniJp+aCtIXxsz1RJUN+YrZaTXyhMVWUoR XhkyN3BTB6A6OCrBTfiB8Af8VzskhYiALPALtVmk4aP/r/RFNLJvQKbT/0waosqolocw kjlw== 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=MZNAwitC0c5tHXIBqT6sv+PXfqUESdg/lRJ7EWEoqJo=; fh=3UoOG683VS7Fhntxc7hv+2/ARXlqbRoosARFB55v8e0=; b=cS6TsU4/Qd/hz4mHh6ylpbs56T2UpkDS5kuyQzAJVUc++QRy/Y3p9uoKJFwErwDxEz dhQkcsypSyc14YBSnoe7mw6RZ7nV5JGxPrzjIsWYBRpkNH4mACA5CMP9IgxBNXQgCO5U HAdszP7WDfliWE7oLLYODd2bOJi7tBWQVS0pFzOBBVKHy/BlUVxQZuEBFe/2U1RNhc7i iQAyCHuqDo4HOExXbJ9HOG/5x99QuHhzL8Hi6nf90IyQ6/CkmwdrSvVTjgz17wDPlQ7r JkiUNK+x2ggJuC8iuS4Wy9c65EXYQYTFnC7Z6hjlJdgOuNCkQx1N7YNbsrKHarga5ium zYPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=txBNSTf1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-208539-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208539-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. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-44038b8a8b8si112397901cf.779.2024.06.10.09.18.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 09:18:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208539-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=txBNSTf1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-208539-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208539-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 74A3B1C212C3 for ; Mon, 10 Jun 2024 16:18:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ABE54143864; Mon, 10 Jun 2024 16:18:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="txBNSTf1" 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 6DD7C81754; Mon, 10 Jun 2024 16:18:31 +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=1718036311; cv=none; b=Hpx/d+XIxJIJnoHKvEItSCOMNlZgHu+5Bj6VjwGMF6uL22mwQH8m+IxD2USJHuVEm0QRTTsbrFaFiglPVMsDzfzGXDmh9sxAPWdNKlrMnOnDceEFjvgKrV0TNrX9XXRw4xc7nHS0d8OZqsyPwxxo3RIqBMNnM0FG+CTTnqT4MbI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718036311; c=relaxed/simple; bh=uZtlK/h+IV89qKq/D7HEEGiIqU3n+5uR+aMUW6bSTYI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=h/X3C/8uf1aNsfF0tFg64gVY3KVSVlLsifbWJkTOcVd5fwa5wPVm4y1M1sZCGz2uF2kvnNj5WlVosE0leE5wtvv2F9ndrHSVUnxQqFHnlXNEGQczE0UXXu4pnPHFeudCIE0LI9es+epw0rhZ9zFMIo1vMNBmlDsncgd7R2xslqw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=txBNSTf1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 270DCC2BBFC; Mon, 10 Jun 2024 16:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718036311; bh=uZtlK/h+IV89qKq/D7HEEGiIqU3n+5uR+aMUW6bSTYI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=txBNSTf1+1t4Xc9gPPh5vQRc5XfFN8nPv3Ro8SB/Yq/j5yEFp8jrN0I+5Vvp5KhOC 31eIcQtv4gSFNYkJWu5tiUYcRsGWbQIFh2b2tiBQYfLYxsJieRJiOTdFhWwTvQJF/M fUzjRO+rL2bVJQVsXagyKG+uCYHiF1TBWgw463NfDzmu1rm2XEkNCph2ZdlBvKMPM0 Gr/XbPplhRTbNTmuXHWyp/dAQvRpoJf5jrDLG/1hP72FEcChZfoVi0qm5BQFx6ewcw vpY5DbRGJh+Zpb2hIoVs4KxbjfSUVKLSS1z59lmFu0jrgvvdpMja9j94fZRFY7GnNT znfhgKqB0z4zQ== Date: Mon, 10 Jun 2024 19:18:26 +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: <20240610161826.GA4966@unreal> References: <20240503164239.GB901876@ziepe.ca> 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 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