From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B22532D45E for ; Wed, 21 Jan 2026 16:02:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769011325; cv=none; b=uwFGtJzEKgvJ+0tM0j/7z15kMynMPSkDPGE5skn2bPik0GFx0Ua0JQkLlzr9MDFpJCNGvDwabC4VBErzQ96JVDqDuOrV65k/g5VZAauT77HK4eH0tIlZnj6sbzlYWel3UsFdtyewzGKrExLE5uD/vliIZ5ytidjdpZp1d06jcdA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769011325; c=relaxed/simple; bh=ALN3BZ1h37bw87fH1I2phtqMuOjkp7pNGMZRlYvqJKU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MZzXwIKTpMP1CoN451RpPtG/j1RZaWe4UogN3oSKj6CjI0Sarmi0uhyNIbbsbPGS5z90BHnabsnfwBAAbMqJxOXgXx34AN+786dDPrHO4WhpwyGkEheNOZ9ewRvM5PuhvPGzogZtNAof919zpnB5oVP2tOEYX7AqDCrjvpVfiak= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=X16z7tde; arc=none smtp.client-ip=209.85.219.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="X16z7tde" Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-894724bc5cbso8692086d6.1 for ; Wed, 21 Jan 2026 08:02:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1769011321; x=1769616121; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=Xk50a3DJCYgVIrcCVz4YsPwnwCkWAaxm0jVyWa00IrY=; b=X16z7tdesWZLkENeMRiLL/WJp/rLoVbX6D1QijflhBe2/uBAkosgAPRfAv/W7cqdyA KWgQbhpfbakzuXL6TirYWlRPb4bf98HlnLsiyycryZ/jHAa8qNDAnw9fNCUjnhWODe8K th7OJzwQkEASI74aTvsVXB5mra5Zt+IbjNXlClsxfH0YVrqRDyBbda/JxxaBlRIBLR3V uMsd06s0fudVLyCV3K53Kx2gf18pY+syyrW7kIL1YCK3RmYhKOqcVx4HDa1rACuI8l7c V9a71IgVHlZSBI6lMe63D2SglDMJ4stYBA/RntH6Bk8NEUsOIWj+3+sHYonBxXQeqsfA yN5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769011321; x=1769616121; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Xk50a3DJCYgVIrcCVz4YsPwnwCkWAaxm0jVyWa00IrY=; b=heWhyPsKNpnGw23lML+ozlRO/oKVo5HwAEeK08cRliP8+MY+B79xCZqPVDH6XWkfrW QkB28ThJTcPXThVMWf2oGmXY8BEzzarR3ksV6fxBxXBuhUHGs9MdCXmmfsSUAvy/11nR VRshV5eomSzR5kbfMKTVHZcGrgbV+s9wncKUr7QvYkZaQD1MbiLGeOJKuJ4DeRb1jmq+ sjK2KYfW83mcKBasKtMHCembJK1J14jJ7yqTrPz6SQpge0D08euBQ+yFs4uNkZgG0/eo HKl+l/qof+M4D4ufOpTZ69c7tpenhRLZ/3FXtgt5y9UmZAJ2YbaXy3348N3o1F366PGh mVNQ== X-Forwarded-Encrypted: i=1; AJvYcCXZ1o9ZNVjWrPnRrSIMIs01pMAU1vlYKgs6NbHKrv9RSHNzbTtGS8d1FGa3AgwKkjcOZKLR+Gt6V0+W9qQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxbS4QA9lOLfQzzViRFveYE/V0F3uHeTWtJKemWxqVjR/VZds6d iLMF/5YJUrwUL0THG2XgfeOG/trypX+2OMKqMLHK86OnGKAvu+FN1i4jLPBrfNqbH3g= X-Gm-Gg: AZuq6aI4eOemonkLZC/1ZUR4tLXu+MX8GYvy1VL5Q/NYdqeDpFgxBz9KGv6WM6RuMCr trUKLE5RhFBDrTZhIrGMtDrArVNixoX8l2P904hOFzsXmzwc5UCTSk8NkyHshFJOZ7ND0JT0pXt idPlyhHyVfjS9nkE3T6WhwXKPlYVdOxFYRLa5GKYPqGMn6ZHtF95UNOlOVXz/KFHlUYFqoz99yx twEON+QJ1xX2OzMtc3atG3ZiYePHLgxNiaXiUQYOZb5k57VXD5LMkHIU5onHLFAm+9I4SnG8AAi 1zx5yo+jZe99TiWw+L4egKGBtTG4aYxHT/o2kACXu614cInxa+D8on3nV9M/Tbc3R+MWS/S4Tbq OPrT8Pwm/7RfuvBJKlIXUp85uyFS44w4zJj3wqT/a1mT0DRSjtQx/E2pwJ3c68DEwrLWlsLQS7d CBKtQm+ov80PmYdR+rw1PqIGRApIAavniJoIHVWlSoFnO2iMeEzfR6julaGH7OnJEfqStkdWUD5 NA/1g== X-Received: by 2002:ad4:5c4d:0:b0:88a:3861:9131 with SMTP id 6a1803df08f44-893982737e8mr294508076d6.34.1769011302558; Wed, 21 Jan 2026 08:01:42 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8946e3aee12sm27692726d6.39.2026.01.21.08.01.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jan 2026 08:01:41 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1viaeK-00000006Es6-2jLq; Wed, 21 Jan 2026 12:01:40 -0400 Date: Wed, 21 Jan 2026 12:01:40 -0400 From: Jason Gunthorpe To: Christian =?utf-8?B?S8O2bmln?= Cc: Leon Romanovsky , Sumit Semwal , Alex Deucher , David Airlie , Simona Vetter , Gerd Hoffmann , Dmitry Osipenko , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Lucas De Marchi , Thomas =?utf-8?Q?Hellstr=C3=B6m?= , Rodrigo Vivi , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Felix Kuehling , Alex Williamson , Ankit Agrawal , Vivek Kasireddy , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux.dev, intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, kvm@vger.kernel.org Subject: Re: [PATCH v3 6/7] vfio: Wait for dma-buf invalidation to complete Message-ID: <20260121160140.GF961572@ziepe.ca> References: <20260120-dmabuf-revoke-v3-0-b7e0b07b8214@nvidia.com> <20260120-dmabuf-revoke-v3-6-b7e0b07b8214@nvidia.com> <20260121133146.GY961572@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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Jan 21, 2026 at 04:28:17PM +0100, Christian König wrote: > On 1/21/26 14:31, Jason Gunthorpe wrote: > > On Wed, Jan 21, 2026 at 10:20:51AM +0100, Christian König wrote: > >> On 1/20/26 15:07, Leon Romanovsky wrote: > >>> From: Leon Romanovsky > >>> > >>> dma-buf invalidation is performed asynchronously by hardware, so VFIO must > >>> wait until all affected objects have been fully invalidated. > >>> > >>> Fixes: 5d74781ebc86 ("vfio/pci: Add dma-buf export support for MMIO regions") > >>> Signed-off-by: Leon Romanovsky > >> > >> Reviewed-by: Christian König > >> > >> Please also keep in mind that the while this wait for all fences for > >> correctness you also need to keep the mapping valid until > >> dma_buf_unmap_attachment() was called. > > > > Can you elaborate on this more? > > > > I think what we want for dma_buf_attach_revocable() is the strong > > guarentee that the importer stops doing all access to the memory once > > this sequence is completed and the exporter can rely on it. I don't > > think this works any other way. > > > > This is already true for dynamic move capable importers, right? > > Not quite, no. :( It is kind of shocking to hear these APIs work like this with such a loose lifetime definition. Leon can you include some of these detail in the new comments? > >> In other words you can only redirect the DMA-addresses previously > >> given out into nirvana (or a dummy memory or similar), but you still > >> need to avoid re-using them for something else. > > > > Does any driver do this? If you unload/reload a GPU driver it is > > going to re-use the addresses handed out? > > I never fully read through all the source code, but if I'm not > completely mistaken that is enforced for all GPU drivers through the > DMA-buf and DRM layer lifetime handling and I think even in other in > kernel frameworks like V4L, alsa etc... > What roughly happens is that each DMA-buf mapping through a couple > of hoops keeps a reference on the device, so even after a hotplug > event the device can only fully go away after all housekeeping > structures are destroyed and buffers freed. A simple reference on the device means nothing for these kinds of questions. It does not stop unloading and reloading a driver. Obviously if the driver is loaded fresh it will reallocate. To do what you are saying the DRM drivers would have to block during driver remove until all unmaps happen. > Background is that a lot of device still make reads even after you > have invalidated a mapping, but then discard the result. And they also don't insert fences to conclude that? > So when you don't have same grace period you end up with PCI AER, > warnings from IOMMU, random accesses to PCI BARs which just happen > to be in the old location of something etc... Yes, definitely. It is very important to have a definitive point in the API where all accesses stop. While "read but discard" seems harmless on the surface, there are corner cases where it is not OK. Am I understanding right that these devices must finish their reads before doing unmap? > I would rather like to keep that semantics even for forcefully > shootdowns since it proved to be rather reliable. We can investigate making unmap the barrier point if this is the case. Jason