From: Jason Gunthorpe <jgg@nvidia.com>
To: Simona Vetter <simona.vetter@ffwll.ch>
Cc: "Christian König" <christian.koenig@amd.com>,
"Kasireddy, Vivek" <vivek.kasireddy@intel.com>,
"Wei Lin Guay" <wguay@meta.com>,
"Keith Busch" <kbusch@kernel.org>,
"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
"Dag Moxnes" <dagmoxnes@meta.com>,
"Nicolaas Viljoen" <nviljoen@meta.com>,
"Oded Gabbay" <ogabbay@kernel.org>,
"Leon Romanovsky" <leon@kernel.org>,
"Maor Gottlieb" <maorg@nvidia.com>
Subject: Re: [PATCH 0/4] cover-letter: Allow MMIO regions to be exported through dmabuf
Date: Mon, 6 Jan 2025 12:27:57 -0400 [thread overview]
Message-ID: <20250106162757.GH5556@nvidia.com> (raw)
In-Reply-To: <Z3vG9JNOaQMfDZAY@phenom.ffwll.local>
On Mon, Jan 06, 2025 at 01:05:08PM +0100, Simona Vetter wrote:
> On Thu, Jan 02, 2025 at 09:39:51AM -0400, Jason Gunthorpe wrote:
> > On Thu, Dec 19, 2024 at 11:04:54AM +0100, Christian König wrote:
> >
> > > > Based on all the above, I think we can conclude that since dma_buf_put()
> > > > does not directly (or synchronously) call the f_op->release() handler, a
> > > > deadlock is unlikely to occur in the scenario you described.
> >
> > Right, there is no deadlock here, and there is nothing inhernetly
> > wrong with using try_get like this. The locking here is ugly ugly
> > ugly, I forget why, but this was the best I came up with to untangle
> > it without deadlocks or races.
>
> Yeah, imo try_get is perfectly fine pattern. With that sorted my only
> request is to make the try_get specific to the dma_ops, because it only
> works if both ->release and the calling context of try_get follow the same
> rules, which by necessity are exporter specific.
We already know the fd is a dma_ops one because it is on an internal
list and it could not get there otherwise.
The pointer cannot become invalid and freed back to the type safe RCU
while on the list, meaning the try_get is safe as is.
I think Christian's original advice to just open code it is the best
option.
> In full generality as a dma_buf.c interface it's just busted and there's
> no way to make it work, unless we inflict that locking ugliness on
> absolutely every exporter.
I'm not sure about that, the struct file code has special logic to
accommodate the type safe RCU trick. I didn't try to digest it fully,
but I expect there are ways to use it safely without the locking on
release.
> > IIRC it was changed a while back because call chains were getting kind of
> > crazy long with the file release functions and stack overflow was a
> > problem in some cases.
>
> Hm I thought it was also a "oh fuck deadlocks" moment, because usually
> most of the very deep fput calls are for temporary reference and not the
> final one.
That sounds motivating too, but I've also seen cases of being careful
to unlock before fputting things..
Jason
next prev parent reply other threads:[~2025-01-06 16:28 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20241216095429.210792-1-wguay@fb.com>
2024-12-16 9:54 ` [PATCH 1/4] vfio: Add vfio_device_get() Wei Lin Guay
2024-12-16 9:54 ` [PATCH 2/4] dma-buf: Add dma_buf_try_get() Wei Lin Guay
2024-12-16 9:54 ` [PATCH 3/4] vfio/pci: Allow MMIO regions to be exported through dma-buf Wei Lin Guay
2024-12-16 9:54 ` [PATCH 4/4] vfio/pci: Allow export dmabuf without move_notify from importer Wei Lin Guay
2024-12-16 10:21 ` [PATCH 0/4] cover-letter: Allow MMIO regions to be exported through dmabuf Christian König
2024-12-16 16:54 ` Keith Busch
2024-12-17 9:53 ` Christian König
2024-12-17 11:06 ` Wei Lin Guay
[not found] ` <e8759159-b141-410b-be08-aad54eaed41f@amd.com>
2024-12-18 6:16 ` Kasireddy, Vivek
2024-12-18 10:01 ` Christian König
2024-12-19 7:02 ` Kasireddy, Vivek
2024-12-19 10:04 ` Christian König
2025-01-02 13:39 ` Jason Gunthorpe
2025-01-06 12:05 ` Simona Vetter
2025-01-06 16:27 ` Jason Gunthorpe [this message]
2025-01-08 16:48 ` Simona Vetter
2024-12-18 10:44 ` Simona Vetter
[not found] <20241216095920.237117-1-wguay@fb.com>
2024-12-16 17:34 ` Kasireddy, Vivek
2024-12-17 12:19 ` Wei Lin Guay
2024-12-18 7:02 ` Kasireddy, Vivek
[not found] ` <61DF4F0E-D947-436B-9160-A40079DB9085@meta.com>
2025-02-26 7:55 ` Kasireddy, Vivek
2025-02-26 13:38 ` Jason Gunthorpe
2025-02-26 17:59 ` Leon Romanovsky
2025-02-26 18:27 ` Wei Lin Guay
2025-03-04 7:15 ` Kasireddy, Vivek
2025-03-04 14:29 ` Christian König
2025-03-04 14:33 ` Jason Gunthorpe
2025-03-04 14:54 ` Leon Romanovsky
2025-02-26 18:24 ` Wei Lin Guay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250106162757.GH5556@nvidia.com \
--to=jgg@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=christian.koenig@amd.com \
--cc=dagmoxnes@meta.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kbusch@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=maorg@nvidia.com \
--cc=nviljoen@meta.com \
--cc=ogabbay@kernel.org \
--cc=simona.vetter@ffwll.ch \
--cc=vivek.kasireddy@intel.com \
--cc=wguay@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).