* device hotplug & file handles
@ 2020-05-07 14:49 Gerd Hoffmann
2020-05-07 16:18 ` Peter Krempa
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2020-05-07 14:49 UTC (permalink / raw)
To: libvir-list, qemu-devel
Hi,
For usb device pass-through (aka -device usb-host) it would be very
useful to pass file handles from libvirt to qemu. The workflow would
change from ...
(1) libvirt enables access to /dev/usb/$bus/$dev
(2) libvirt passes $bus + $dev (using hostbus + hostaddr properties)
to qemu.
(3) qemu opens /dev/usb/$bus/$dev
... to ...
(1) libvirt opens /dev/usb/$bus/$dev
(2) libvirt passes filehandle to qemu.
Question is how can we pass the file descriptor best? My idea would be
to simply add an fd property to usb-host:
* Coldplug would be "-device usb-host,fd=<nr>" (cmd line).
* Hotplug would be "device_add usb-host,fd=<getfd-name>" (monitor).
Will that work from libvirt point of view?
Or does anyone have an better idea?
thanks,
Gerd
PS: background: https://bugzilla.redhat.com/show_bug.cgi?id=1595525
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: device hotplug & file handles
2020-05-07 14:49 device hotplug & file handles Gerd Hoffmann
@ 2020-05-07 16:18 ` Peter Krempa
2020-05-07 17:05 ` Eric Blake
2020-05-11 10:20 ` Michal Privoznik
2 siblings, 0 replies; 4+ messages in thread
From: Peter Krempa @ 2020-05-07 16:18 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: libvir-list, qemu-devel
On Thu, May 07, 2020 at 16:49:14 +0200, Gerd Hoffmann wrote:
> Hi,
>
> For usb device pass-through (aka -device usb-host) it would be very
> useful to pass file handles from libvirt to qemu. The workflow would
> change from ...
>
> (1) libvirt enables access to /dev/usb/$bus/$dev
> (2) libvirt passes $bus + $dev (using hostbus + hostaddr properties)
> to qemu.
> (3) qemu opens /dev/usb/$bus/$dev
>
> ... to ...
>
> (1) libvirt opens /dev/usb/$bus/$dev
> (2) libvirt passes filehandle to qemu.
>
> Question is how can we pass the file descriptor best? My idea would be
> to simply add an fd property to usb-host:
>
> * Coldplug would be "-device usb-host,fd=<nr>" (cmd line).
> * Hotplug would be "device_add usb-host,fd=<getfd-name>" (monitor).
We have prior art for both approaches so it's fine.
>
> Will that work from libvirt point of view?
Sure! Just please make sure that the new approach is detectable somehow.
Either via device-list-properties or query-qmp-schema.
> Or does anyone have an better idea?
>
> thanks,
> Gerd
>
> PS: background: https://bugzilla.redhat.com/show_bug.cgi?id=1595525
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: device hotplug & file handles
2020-05-07 14:49 device hotplug & file handles Gerd Hoffmann
2020-05-07 16:18 ` Peter Krempa
@ 2020-05-07 17:05 ` Eric Blake
2020-05-11 10:20 ` Michal Privoznik
2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2020-05-07 17:05 UTC (permalink / raw)
To: Gerd Hoffmann, libvir-list, qemu-devel
On 5/7/20 9:49 AM, Gerd Hoffmann wrote:
> Hi,
>
> For usb device pass-through (aka -device usb-host) it would be very
> useful to pass file handles from libvirt to qemu. The workflow would
> change from ...
>
> (1) libvirt enables access to /dev/usb/$bus/$dev
> (2) libvirt passes $bus + $dev (using hostbus + hostaddr properties)
> to qemu.
> (3) qemu opens /dev/usb/$bus/$dev
>
> ... to ...
>
> (1) libvirt opens /dev/usb/$bus/$dev
> (2) libvirt passes filehandle to qemu.
>
> Question is how can we pass the file descriptor best? My idea would be
> to simply add an fd property to usb-host:
>
> * Coldplug would be "-device usb-host,fd=<nr>" (cmd line).
> * Hotplug would be "device_add usb-host,fd=<getfd-name>" (monitor).
>
> Will that work from libvirt point of view?
> Or does anyone have an better idea?
Qemu already has -add-fd (both a CLI version, and a QMP version when a
Unix socket can pass fds), at which point any existing interface that
uses qemu_open() will understand the magic syntax /dev/fdset/NNN to
refer to the existing fd previously passed in via -add-fd. Libvirt is
already able to use this feature for some cases (for example, see
src/qemu/qemu_command.c:qemuBuildChrChardevFileStr). So all that
remains is making sure -device usb-host uses qemu_open(), and if it
didn't already do so, also making sure libvirt can find a way to
introspect when usb-host started supporting fdset usage.
Or put another way, let's use the generic fd mechanism that qemu already
supports, rather than inventing yet another syntax.
>
> thanks,
> Gerd
>
> PS: background: https://bugzilla.redhat.com/show_bug.cgi?id=1595525
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: device hotplug & file handles
2020-05-07 14:49 device hotplug & file handles Gerd Hoffmann
2020-05-07 16:18 ` Peter Krempa
2020-05-07 17:05 ` Eric Blake
@ 2020-05-11 10:20 ` Michal Privoznik
2 siblings, 0 replies; 4+ messages in thread
From: Michal Privoznik @ 2020-05-11 10:20 UTC (permalink / raw)
To: Gerd Hoffmann, libvir-list, qemu-devel
On 5/7/20 4:49 PM, Gerd Hoffmann wrote:
> Hi,
>
> For usb device pass-through (aka -device usb-host) it would be very
> useful to pass file handles from libvirt to qemu. The workflow would
> change from ...
>
> (1) libvirt enables access to /dev/usb/$bus/$dev
> (2) libvirt passes $bus + $dev (using hostbus + hostaddr properties)
> to qemu.
> (3) qemu opens /dev/usb/$bus/$dev
>
> ... to ...
>
> (1) libvirt opens /dev/usb/$bus/$dev
> (2) libvirt passes filehandle to qemu.
>
> Question is how can we pass the file descriptor best? My idea would be
> to simply add an fd property to usb-host:
>
> * Coldplug would be "-device usb-host,fd=<nr>" (cmd line).
> * Hotplug would be "device_add usb-host,fd=<getfd-name>" (monitor).
>
> Will that work from libvirt point of view?
> Or does anyone have an better idea?
>
> thanks,
> Gerd
>
> PS: background: https://bugzilla.redhat.com/show_bug.cgi?id=1595525
>
I don't have a better idea, but a little background on why libvirt even
invented private /dev in the first place. The reason was that
occasionally, when udev ran its rules it would overwrite the security
labels on /dev nodes set by libvirt and thus denying access to QEMU. See:
https://bugzilla.redhat.com/show_bug.cgi?id=1354251
Now, I think there is the same risk with what you are proposing. This
isn't problem for DAC where permissions are checked during open(), but
it may be a problem for SELinux where each individual operation with the
FD is inspected.
Having said that, I am not against this approach, in fact I'm in favour
of it. Let's hope that people learned that having udev overwriting
seclabels is a bad idea and the bug won't appear again.
Michal
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-05-11 10:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07 14:49 device hotplug & file handles Gerd Hoffmann
2020-05-07 16:18 ` Peter Krempa
2020-05-07 17:05 ` Eric Blake
2020-05-11 10:20 ` Michal Privoznik
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).