dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Simon Ser <contact@emersion.fr>
Cc: "Greg KH" <greg@kroah.com>,
	"Christian König" <christian.koenig@amd.com>,
	dri-devel@lists.freedesktop.org,
	"Jason Ekstrand" <jason.ekstrand@collabora.com>
Subject: Re: [PATCH v4] dma-buf: Add a capabilities directory
Date: Thu, 2 Jun 2022 08:47:56 +0200	[thread overview]
Message-ID: <CAKMK7uEYncnjbwq6fQMNB_5tupMASrAFEadPg9xBS3ykNgNk4A@mail.gmail.com> (raw)
In-Reply-To: <CtTIPo68VAvDRUp7-QFc0m-2SnikPFd0QpdogNj2xueFfyQKa3DQqiw3Meqtsu8vQgEuKX_-MPKbe7jQdf49-Y3z2TAYbajUrC5GKF0Dolk=@emersion.fr>

On Thu, 2 Jun 2022 at 08:34, Simon Ser <contact@emersion.fr> wrote:
>
> On Thursday, June 2nd, 2022 at 08:25, Greg KH <greg@kroah.com> wrote:
>
> > On Thu, Jun 02, 2022 at 06:17:31AM +0000, Simon Ser wrote:
> >
> > > On Thursday, June 2nd, 2022 at 07:40, Greg KH greg@kroah.com wrote:
> > >
> > > > On Wed, Jun 01, 2022 at 04:13:14PM +0000, Simon Ser wrote:
> > > >
> > > > > To discover support for new DMA-BUF IOCTLs, user-space has no
> > > > > choice but to try to perform the IOCTL on an existing DMA-BUF.
> > > >
> > > > Which is correct and how all kernel features work (sorry I missed the
> > > > main goal of this patch earlier and focused only on the sysfs stuff).
> > > >
> > > > > However, user-space may want to figure out whether or not the
> > > > > IOCTL is available before it has a DMA-BUF at hand, e.g. at
> > > > > initialization time in a Wayland compositor.
> > > >
> > > > Why not just do the ioctl in a test way? That's how we determine kernel
> > > > features, we do not poke around in sysfs to determine what is, or is
> > > > not, present at runtime.
> > > >
> > > > > Add a /sys/kernel/dmabuf/caps directory which allows the DMA-BUF
> > > > > subsystem to advertise supported features. Add a
> > > > > sync_file_import_export entry which indicates that importing and
> > > > > exporting sync_files from/to DMA-BUFs is supported.
> > > >
> > > > No, sorry, this is not a sustainable thing to do for all kernel features
> > > > over time. Please just do the ioctl and go from there. sysfs is not
> > > > for advertising what is and is not enabled/present in a kernel with
> > > > regards to functionality or capabilities of the system.
> > > >
> > > > If sysfs were to export this type of thing, it would have to do it for
> > > > everything, not just some random tiny thing of one kernel driver.
> > >
> > > I'd argue that DMA-BUF is a special case here.
> >
> > So this is special and unique just like everything else? :)
> >
> > > To check whether the import/export IOCTLs are available, user-space
> > > needs a DMA-BUF to try to perform the IOCTL. To get a DMA-BUF,
> > > user-space needs to enumerate GPUs, pick one at random, load GBM or
> > > Vulkan, use that heavy-weight API to allocate a "fake" buffer on the
> > > GPU, export that buffer into a DMA-BUF, try the IOCTL, then teardown
> > > all of this. There is no other way.
> > >
> > > This sounds like a roundabout way to answer the simple question "is the
> > > IOCTL available?". Do you have another suggestion to address this
> > > problem?
> >
> > What does userspace do differently if the ioctl is present or not?
>
> Globally enable a synchronization API for Wayland clients, for instance
> in the case of a Wayland compositor.
>
> > And why is this somehow more special than of the tens of thousands of
> > other ioctl calls where you have to do exactly the same thing you list
> > above to determine if it is present or not?
>
> For other IOCTLs it's not as complicated to obtain a FD to do the test
> with.

Two expand on this:

- compositor opens the drm render /dev node
- compositor initializes the opengl or vulkan userspace driver on top of that
- compositor asks that userspace driver to allocate some buffer, which
can be pretty expensive
- compositor asks the userspace driver to export that buffer into a dma-buf
- compositor can finally do the test ioctl, realizes support isn't
there and tosses the entire thing

read() on a sysfs file is so much more reasonable it's not even funny.

Plan B we discussed is to add a getparam to signify this to the drm
ioctl interface, but that has the design problem that a feature in the
dma-buf subsystem is announced in a totally different subsystem (ok
same maintainers), and if that ever gets out of sync your userspace
breaks. So really no good.

So if sysfs also isn't the right approach, and the getparam ioctl on
drm is defo worse, what is the right approach? Ideally without setting
up the entire userspace render driver and doing some expensive-ish
(depending upon driver at least) buffer allocations just to check for
a feature.

Note that some compositors want to gate their "should I use vk for
rendering and expose some additional features to client" decision on
this, so setting up the wrong renderer just to test whether that would
work is not a very great approach.

Also the last time we added a feature to dma-buf was in 3.17, so I
guess everyone just hardcodes nowadays that all dma-buf features are
present. Which isn't great, and that's why we're trying to fix here.

> > And how have you specifically tied this sysfs to the ioctl so that if it
> > changes or is ported elsewhere, that sysfs attribute will also know to
> > be added?
>
> What do you mean by "ported elsewhere"?
>
> > You already have shipping kernels today without this attribute, you
> > can't go back in time and add the attribute to those kernels just to
> > reflect the ioctl being present or not, so you have to handle this case
> > in userspace today, making this not needed at all. Do you want to have
> > two test cases in your userspace code, one that does "is the sysfs file
> > there? No, ok, let's see if we are on an older kernel without it, yet
> > the ioctl is present..." When really you can just do "let's see if the
> > ioctl is present" logic as you already do that today.
>
> The IOCTL has not been shipped yet.

To expand, Jason Ekstrand wrote the ioctl itself and Simon here the
better discovery code. It should probably have been sent out as a
joint patch series or something, but neither has been merged yet so
there is no problem.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

  reply	other threads:[~2022-06-02  6:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01 16:13 [PATCH v4] dma-buf: Add a capabilities directory Simon Ser
2022-06-01 16:51 ` Christian König
2022-06-01 18:05 ` Jason Ekstrand
2022-06-02  5:40 ` Greg KH
2022-06-02  6:17   ` Simon Ser
2022-06-02  6:25     ` Greg KH
2022-06-02  6:34       ` Simon Ser
2022-06-02  6:47         ` Daniel Vetter [this message]
2022-06-06 15:10           ` Robin Murphy
2022-06-06 15:22             ` Greg KH
2022-06-06 15:44               ` Robin Murphy
2022-06-07 10:36           ` Brian Starkey
2022-06-07 10:55           ` Greg KH
2022-06-07 14:52             ` Jason Ekstrand
2022-06-07 16:01               ` Greg KH
2022-06-08 15:15                 ` Daniel Vetter

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=CAKMK7uEYncnjbwq6fQMNB_5tupMASrAFEadPg9xBS3ykNgNk4A@mail.gmail.com \
    --to=daniel.vetter@ffwll.ch \
    --cc=christian.koenig@amd.com \
    --cc=contact@emersion.fr \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=greg@kroah.com \
    --cc=jason.ekstrand@collabora.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).