Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp433867lqp; Mon, 10 Jun 2024 08:25:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeUBGBipgIcy85cSrtUYdjUNLQp08aIT+eM+CdCjdW8WHonvBZDStwiyQkR1FXUPdynqhidE5bC+C6bNt6CvcyIdZiNBd7PvQzBnj79Q== X-Google-Smtp-Source: AGHT+IFZXColG+IWVpMyIJ03520YIvN7M0kXBir5x6My4AvfCWSJhHdsftyHOkUXaA6H/PtRlChU X-Received: by 2002:a05:6122:3695:b0:4e4:e749:32a2 with SMTP id 71dfb90a1353d-4eb55df138emr9425117e0c.7.1718033109042; Mon, 10 Jun 2024 08:25:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718033109; cv=pass; d=google.com; s=arc-20160816; b=WiA0PScTI27sVmC5IpZwQvxndNAjdhtFvacyN+ZPDHJxasossRG6z4+YSr3RQXd706 4YWm8CUsWl94zlLM4rFuzshvcG+Ysyz/HHR9vTKRpmTRq41aqN7Pl5O66Ounlf6uVVoY s2r+RlMDOGdLs33UCob41Yoq8fNC2nToiuu32enyL3JaNJRJaInuEGjxeXQWbjwJ3H7N 1vPmxYUgO8gXVYuVLdLhpFcmbDkr2BARN6zPp8ppsmNmN4gWjOV8fNXt0SkX6gzqf0yy ckLM8NqkuJ1NRLYWOW80Cm7OAZhJxqzX8B63I1P9pV88IzpuZY/DzY4xVZP2XDZX5zyK q9tQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=KKiu4qnDEEkxgkcxXe30X1MKX2KLMdPF1td6NPZnAM8=; fh=vBPXHW0Mxn0D/zbjTTdHy6QR/roNCsIx5NUEvqlgI/Q=; b=b62Xjo+btBLF1jSrqF+42xexaCHKW9sNOnjXVIlLqrfEkYRF964NhPRk5t9YcwM4at 6SUZYZGreJmXJzdOltcd3ZnayERsFD+03nirxRfL9Br/BgLXWA/EWiUkgNbPCg41RiES jBpf+zfwjPpWnuRLCNOT5fTzCaPJ7IIFjvBqfEJieVp2WXgOGA8sbz2x/ZyXlnGTMln1 aid/IMK6mIiwpVxpd+tgSYz0oZrUz3Dy4JKBAM36XUqRmVsLG6QzD5OKo4B3fwXhXW1O EFqlsA/1dxeCBfciHgXeNDngzQHSuMI6mN2tChPbU5fyDqSByldGfoJvfHurFon0FqDN v2+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=sw2F+lfM; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-208470-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208470-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 71dfb90a1353d-4eb5d7d5c2fsi1206313e0c.33.2024.06.10.08.25.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 08:25:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208470-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=@linux.dev header.s=key1 header.b=sw2F+lfM; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-208470-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208470-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 AD4471C203F7 for ; Mon, 10 Jun 2024 15:25:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9941A14A4E2; Mon, 10 Jun 2024 15:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="sw2F+lfM" Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (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 00DA713FD9C; Mon, 10 Jun 2024 15:19:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032767; cv=none; b=HtaYEtZDCK8TXclgBphgBvYyg7pG9w0elwD2j8taTRtTTVlcrCg/Ugfzqr956pLFbOu9TbGFhrTSLGe013JpEhRZz1QfI5yarrA96/l5PsgxnyutVuhJOPF87cln0WK2/Gxb9jkhf6sonY3YVx3qShVZ/LNsT/MMNZ3QOk7wwaM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032767; c=relaxed/simple; bh=+urT2uxejbnWTGWDhjERLm4pJwmoHG+HNqLAz7qV5P4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=mG9ZP3CX451MD2l90YM80KoUcxC6VJ020Th7KxBGJAQrvQi84x1q84gMYWlg+sK440uoSJpVDPEkWHGQB+dXO6k3tctwlcuIyQ8OMhod6FRUcipf7tWZKnl1AFgA5SyBBDtqKVKSVmH0jpwEdrWYhLbRfamheQlxS9Lj1mY59gk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=sw2F+lfM; arc=none smtp.client-ip=95.215.58.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: oak.zeng@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1718032762; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KKiu4qnDEEkxgkcxXe30X1MKX2KLMdPF1td6NPZnAM8=; b=sw2F+lfMZ3l8HawNA7kIWr3pK0lq7HnmPavMpWgUr7rU+1zbON9Ti/U85ptK/5XBbcEv87 2BodlutKmiORSPlAcNIHof0xq71ZHIZgGYywZy2ISSYXzwGQnEez1TFWDIydAKJWuRKGOx OIYVeRO8ue/E5ZniP4Jy+Ay+5ChRqPo= X-Envelope-To: jgg@ziepe.ca X-Envelope-To: leon@kernel.org X-Envelope-To: hch@lst.de X-Envelope-To: robin.murphy@arm.com X-Envelope-To: m.szyprowski@samsung.com X-Envelope-To: joro@8bytes.org X-Envelope-To: will@kernel.org X-Envelope-To: chaitanyak@nvidia.com X-Envelope-To: matthew.brost@intel.com X-Envelope-To: thomas.hellstrom@intel.com X-Envelope-To: corbet@lwn.net X-Envelope-To: axboe@kernel.dk X-Envelope-To: kbusch@kernel.org X-Envelope-To: sagi@grimberg.me X-Envelope-To: yishaih@nvidia.com X-Envelope-To: shameerali.kolothum.thodi@huawei.com X-Envelope-To: kevin.tian@intel.com X-Envelope-To: alex.williamson@redhat.com X-Envelope-To: jglisse@redhat.com X-Envelope-To: akpm@linux-foundation.org X-Envelope-To: linux-doc@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: linux-block@vger.kernel.org X-Envelope-To: linux-rdma@vger.kernel.org X-Envelope-To: iommu@lists.linux.dev X-Envelope-To: linux-nvme@lists.infradead.org X-Envelope-To: kvm@vger.kernel.org X-Envelope-To: linux-mm@kvack.org X-Envelope-To: bvanassche@acm.org X-Envelope-To: damien.lemoal@opensource.wdc.com X-Envelope-To: amir73il@gmail.com X-Envelope-To: josef@toxicpanda.com X-Envelope-To: martin.petersen@oracle.com X-Envelope-To: daniel@iogearbox.net X-Envelope-To: dan.j.williams@intel.com X-Envelope-To: jack@suse.com X-Envelope-To: leonro@nvidia.com X-Envelope-To: krishnaiah.bommu@intel.com X-Envelope-To: himal.prasad.ghimiray@intel.com Message-ID: Date: Mon, 10 Jun 2024 17:19:16 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [RFC RESEND 00/16] Split IOMMU DMA mapping operation to two steps To: "Zeng, Oak" , Jason Gunthorpe 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 , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , 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" , Leon Romanovsky , "Bommu, Krishnaiah" , "Ghimiray, Himal Prasad" References: <20240503164239.GB901876@ziepe.ca> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Zhu Yanjun In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 10.06.24 17:12, 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. > > Did you test the new API in RDMA subsystem? Or this RFC series was just some untested codes sending out to get people's design feedback? 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. Hi, Zeng I have tested this patch series. And a patch about NVMe will cause some call trace. But if you revert this patch about NVMe, the whole patches can work well. You can develop your patches based on this patch series. It seems that "some agreements can not be reached" about NVMe. So NVMe patch can not work well. I do not delve into this NVMe patch. Zhu Yanjun > > 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 -- Best Regards, Yanjun.Zhu