qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom
@ 2011-04-08 11:33 Stefan Hajnoczi
  2011-04-11  5:07 ` [Qemu-devel] " Amit Shah
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Stefan Hajnoczi @ 2011-04-08 11:33 UTC (permalink / raw)
  To: qemu-devel
  Cc: Amit Shah, Kevin Wolf, Ryan Harper, Christoph Hellwig,
	Markus Armbruster

Amit and I were discussing the pros and cons of using O_EXCL to open
host CD-ROM devices on IRC but this discussion could benefit from more
input.

Linux block devices (like /dev/sr0 CD-ROMs) can be opened with O_EXCL
and only one userspace process will succeed at a time.  This prevents
programs from interfering with each other.  The polling daemons, hald
and udisks, use O_EXCL and mount does too.

Today QEMU does not use O_EXCL and will therefore access host CD-ROMs
while they are in use by other programs.  This also means that
programs can be started on the host while QEMU is already running that
may interfere with the virtual machine's ability to access the CD-ROM
(for example by ejecting it).

Therefore, it sounds reasonable to switch to O_EXCL to prevent
interfering with other programs and to prevent other programs
interfering with QEMU.

On the downside, it will no longer be possible to share a host CD-ROM
between multiple virtual machines or to mount it on host while passing
it through to a guest.  These scenarios are not safe because on of the
clients could eject the device, spoiling the party for everyone else.
However, it is a handy feature for putting installation media into a
machine and installing several guests at the same time.

The other concern I have about using O_EXCL is that we expose
ourselves to race conditions if there is ever a need to re-open the
device.  When QEMU closes its file descriptor another program may be
scheduled to run and open the device with O_EXCL.  Now QEMU will not
be able to open the CD-ROM anymore.  From the guest perspective this
could be at an odd time and we'd have to start failing requests.
Today we do not re-open host CD-ROMs though so this isn't a pressing
problem.

Any thoughts?  Additional pros/cons I've missed?

Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: To O_EXCL or not to O_EXCL open host_cdrom
  2011-04-08 11:33 [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom Stefan Hajnoczi
@ 2011-04-11  5:07 ` Amit Shah
  2011-04-11  8:31   ` Stefan Hajnoczi
  2011-04-11 13:27 ` [Qemu-devel] " Avi Kivity
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Amit Shah @ 2011-04-11  5:07 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Markus Armbruster, Ryan Harper, qemu-devel,
	Christoph Hellwig

On (Fri) 08 Apr 2011 [12:33:27], Stefan Hajnoczi wrote:
> Amit and I were discussing the pros and cons of using O_EXCL to open
> host CD-ROM devices on IRC but this discussion could benefit from more
> input.
> 
> Linux block devices (like /dev/sr0 CD-ROMs) can be opened with O_EXCL
> and only one userspace process will succeed at a time.  This prevents
> programs from interfering with each other.  The polling daemons, hald
> and udisks, use O_EXCL and mount does too.
> 
> Today QEMU does not use O_EXCL and will therefore access host CD-ROMs
> while they are in use by other programs.  This also means that
> programs can be started on the host while QEMU is already running that
> may interfere with the virtual machine's ability to access the CD-ROM
> (for example by ejecting it).
> 
> Therefore, it sounds reasonable to switch to O_EXCL to prevent
> interfering with other programs and to prevent other programs
> interfering with QEMU.
> 
> On the downside, it will no longer be possible to share a host CD-ROM
> between multiple virtual machines or to mount it on host while passing
> it through to a guest.  These scenarios are not safe because on of the
> clients could eject the device, spoiling the party for everyone else.
> However, it is a handy feature for putting installation media into a
> machine and installing several guests at the same time.

I'm of the opinion that it's simply wrong to allow such concurrent
access.  The feature isn't too compelling, and it's really a bug IMO.
We should open O_EXCL and document somewhere about this.  Host CDROM
passthrough is such a niche concept that people should be able to
ensure to stop other services opening CDROMs in exclusive mode.

Also, since we're really cheating other programs that open the CDROM
device O_EXCL by bypassing that requirement, any actions the guest
takes is likely to hamper the host programs using CDROMs -- maybe even
causing guests to exploit security holes in other host programs.

> The other concern I have about using O_EXCL is that we expose
> ourselves to race conditions if there is ever a need to re-open the
> device.  When QEMU closes its file descriptor another program may be
> scheduled to run and open the device with O_EXCL.  Now QEMU will not
> be able to open the CD-ROM anymore.

The admins should really be the ones worrying about this, not QEMU.

		Amit

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] Re: To O_EXCL or not to O_EXCL open host_cdrom
  2011-04-11  5:07 ` [Qemu-devel] " Amit Shah
@ 2011-04-11  8:31   ` Stefan Hajnoczi
  2011-04-11 13:30     ` Avi Kivity
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Hajnoczi @ 2011-04-11  8:31 UTC (permalink / raw)
  To: Amit Shah
  Cc: Kevin Wolf, Markus Armbruster, Ryan Harper, qemu-devel,
	Christoph Hellwig

On Mon, Apr 11, 2011 at 10:37:32AM +0530, Amit Shah wrote:
> On (Fri) 08 Apr 2011 [12:33:27], Stefan Hajnoczi wrote:
> > The other concern I have about using O_EXCL is that we expose
> > ourselves to race conditions if there is ever a need to re-open the
> > device.  When QEMU closes its file descriptor another program may be
> > scheduled to run and open the device with O_EXCL.  Now QEMU will not
> > be able to open the CD-ROM anymore.
> 
> The admins should really be the ones worrying about this, not QEMU.

Think of a desktop use case.  virt-manager lets me pass through the host
CD-ROM today.  Desktops have hald/udisks and you can't expect users to
disable/reenable those services just for QEMU.

Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom
  2011-04-08 11:33 [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom Stefan Hajnoczi
  2011-04-11  5:07 ` [Qemu-devel] " Amit Shah
@ 2011-04-11 13:27 ` Avi Kivity
  2011-04-11 18:19 ` Christoph Hellwig
  2011-04-12  7:52 ` Daniel P. Berrange
  3 siblings, 0 replies; 10+ messages in thread
From: Avi Kivity @ 2011-04-11 13:27 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, qemu-devel, Markus Armbruster, Ryan Harper, Amit Shah,
	Christoph Hellwig

On 04/08/2011 02:33 PM, Stefan Hajnoczi wrote:
> Amit and I were discussing the pros and cons of using O_EXCL to open
> host CD-ROM devices on IRC but this discussion could benefit from more
> input.
>
> Linux block devices (like /dev/sr0 CD-ROMs) can be opened with O_EXCL
> and only one userspace process will succeed at a time.  This prevents
> programs from interfering with each other.  The polling daemons, hald
> and udisks, use O_EXCL and mount does too.
>
> Today QEMU does not use O_EXCL and will therefore access host CD-ROMs
> while they are in use by other programs.  This also means that
> programs can be started on the host while QEMU is already running that
> may interfere with the virtual machine's ability to access the CD-ROM
> (for example by ejecting it).

Also, performance would likely be ruined if the disk wasn't cached 
(likely with a DVD).  CD-ROMs seek very slowly.  It would be even 
funnier if we supported cd-writers.

> Therefore, it sounds reasonable to switch to O_EXCL to prevent
> interfering with other programs and to prevent other programs
> interfering with QEMU.
>
> On the downside, it will no longer be possible to share a host CD-ROM
> between multiple virtual machines or to mount it on host while passing
> it through to a guest.  These scenarios are not safe because on of the
> clients could eject the device, spoiling the party for everyone else.
> However, it is a handy feature for putting installation media into a
> machine and installing several guests at the same time.

You'd probably benefit a lot more by copying the media to disk.

> The other concern I have about using O_EXCL is that we expose
> ourselves to race conditions if there is ever a need to re-open the
> device.  When QEMU closes its file descriptor another program may be
> scheduled to run and open the device with O_EXCL.  Now QEMU will not
> be able to open the CD-ROM anymore.  From the guest perspective this
> could be at an odd time and we'd have to start failing requests.
> Today we do not re-open host CD-ROMs though so this isn't a pressing
> problem.

We really should avoid re-open whenever possible.

The standard response to such questions is "let's add another option", 
but in this case I don't think we should.  Like Amit says, this is a 
niche use case.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] Re: To O_EXCL or not to O_EXCL open host_cdrom
  2011-04-11  8:31   ` Stefan Hajnoczi
@ 2011-04-11 13:30     ` Avi Kivity
  0 siblings, 0 replies; 10+ messages in thread
From: Avi Kivity @ 2011-04-11 13:30 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Markus Armbruster, qemu-devel, Ryan Harper, Amit Shah,
	Christoph Hellwig

On 04/11/2011 11:31 AM, Stefan Hajnoczi wrote:
> On Mon, Apr 11, 2011 at 10:37:32AM +0530, Amit Shah wrote:
> >  On (Fri) 08 Apr 2011 [12:33:27], Stefan Hajnoczi wrote:
> >  >  The other concern I have about using O_EXCL is that we expose
> >  >  ourselves to race conditions if there is ever a need to re-open the
> >  >  device.  When QEMU closes its file descriptor another program may be
> >  >  scheduled to run and open the device with O_EXCL.  Now QEMU will not
> >  >  be able to open the CD-ROM anymore.
> >
> >  The admins should really be the ones worrying about this, not QEMU.
>
> Think of a desktop use case.  virt-manager lets me pass through the host
> CD-ROM today.  Desktops have hald/udisks and you can't expect users to
> disable/reenable those services just for QEMU.

It should be solved at that level then.  If I insert a disc into an 
assigned cd-rom drive, I shouldn't get a file manager or autorun window 
to pop in the host, just the guest.

So: libvirt should inform the rest of the system that it is taking over 
the cd-rom and as far as they're concerned, it no longer exists.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom
  2011-04-08 11:33 [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom Stefan Hajnoczi
  2011-04-11  5:07 ` [Qemu-devel] " Amit Shah
  2011-04-11 13:27 ` [Qemu-devel] " Avi Kivity
@ 2011-04-11 18:19 ` Christoph Hellwig
  2011-04-12  7:52 ` Daniel P. Berrange
  3 siblings, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2011-04-11 18:19 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Amit Shah, Kevin Wolf, Ryan Harper, qemu-devel, Markus Armbruster

On Fri, Apr 08, 2011 at 12:33:27PM +0100, Stefan Hajnoczi wrote:
> Amit and I were discussing the pros and cons of using O_EXCL to open
> host CD-ROM devices on IRC but this discussion could benefit from more
> input.
> 
> Linux block devices (like /dev/sr0 CD-ROMs) can be opened with O_EXCL
> and only one userspace process will succeed at a time.  This prevents
> programs from interfering with each other.  The polling daemons, hald
> and udisks, use O_EXCL and mount does too.
> 
> Today QEMU does not use O_EXCL and will therefore access host CD-ROMs
> while they are in use by other programs.  This also means that
> programs can be started on the host while QEMU is already running that
> may interfere with the virtual machine's ability to access the CD-ROM
> (for example by ejecting it).
> 
> Therefore, it sounds reasonable to switch to O_EXCL to prevent
> interfering with other programs and to prevent other programs
> interfering with QEMU.

This all boils down to whether qemu should allow concurrent access
to image files of all sorts, and there are arguments both ways:

 pro: prevents corruption problems on disk images, notification issues
      on CDROMS, etc
 contra: makes clustering not work

which means we need it configurable.  I'd prefer to have the exclusion
on by default, but people caring for backwards comptibility might argue
the other way around.  Either way it needs to be consistent for both
devices and file images.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom
  2011-04-08 11:33 [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom Stefan Hajnoczi
                   ` (2 preceding siblings ...)
  2011-04-11 18:19 ` Christoph Hellwig
@ 2011-04-12  7:52 ` Daniel P. Berrange
  2011-04-12  8:10   ` Kevin Wolf
  3 siblings, 1 reply; 10+ messages in thread
From: Daniel P. Berrange @ 2011-04-12  7:52 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, qemu-devel, Markus Armbruster, Ryan Harper, Amit Shah,
	Christoph Hellwig

On Fri, Apr 08, 2011 at 12:33:27PM +0100, Stefan Hajnoczi wrote:
> Amit and I were discussing the pros and cons of using O_EXCL to open
> host CD-ROM devices on IRC but this discussion could benefit from more
> input.
> 
> Linux block devices (like /dev/sr0 CD-ROMs) can be opened with O_EXCL
> and only one userspace process will succeed at a time.  This prevents
> programs from interfering with each other.  The polling daemons, hald
> and udisks, use O_EXCL and mount does too.
> 
> Today QEMU does not use O_EXCL and will therefore access host CD-ROMs
> while they are in use by other programs.  This also means that
> programs can be started on the host while QEMU is already running that
> may interfere with the virtual machine's ability to access the CD-ROM
> (for example by ejecting it).
> 
> Therefore, it sounds reasonable to switch to O_EXCL to prevent
> interfering with other programs and to prevent other programs
> interfering with QEMU.
> 
> On the downside, it will no longer be possible to share a host CD-ROM
> between multiple virtual machines or to mount it on host while passing
> it through to a guest.  These scenarios are not safe because on of the
> clients could eject the device, spoiling the party for everyone else.
> However, it is a handy feature for putting installation media into a
> machine and installing several guests at the same time.

Two things strike me here

 - Host CDROM device vs ISO image files have different behaviour
   by default, since they use different internal block drivers.
   If the app wants to share the host CDROM, then perhaps it
   should be force QEMU to access it with the 'raw' block driver
   instead of 'host_cdrom'. Thus "eject" would just result in
   the drive file being closed & filename blanked as for ISOs

 - If the -drive specification has  readonly=on (thus O_RDONLY to
   open(2) call) , I expect QEMU (or the kernel) to forbid the
   "eject" command on the host CDROM. This should prevent two guests
   interfering seriously with each other.

So I think using O_EXCL would be OK, in the case where the block
driver was  host_cdrom and readonly=off.

> The other concern I have about using O_EXCL is that we expose
> ourselves to race conditions if there is ever a need to re-open the
> device.  When QEMU closes its file descriptor another program may be
> scheduled to run and open the device with O_EXCL.  Now QEMU will not
> be able to open the CD-ROM anymore.  From the guest perspective this
> could be at an odd time and we'd have to start failing requests.
> Today we do not re-open host CD-ROMs though so this isn't a pressing
> problem.

Ideally the kernel support would be enhanced such that we don't need to
close & reopen the file, so we can avoid the failure path.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom
  2011-04-12  7:52 ` Daniel P. Berrange
@ 2011-04-12  8:10   ` Kevin Wolf
  2011-04-12  8:19     ` Daniel P. Berrange
  0 siblings, 1 reply; 10+ messages in thread
From: Kevin Wolf @ 2011-04-12  8:10 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: Stefan Hajnoczi, qemu-devel, Markus Armbruster, Ryan Harper,
	Amit Shah, Christoph Hellwig

Am 12.04.2011 09:52, schrieb Daniel P. Berrange:
>  - If the -drive specification has  readonly=on (thus O_RDONLY to
>    open(2) call) , I expect QEMU (or the kernel) to forbid the
>    "eject" command on the host CDROM. This should prevent two guests
>    interfering seriously with each other.
> 
> So I think using O_EXCL would be OK, in the case where the block
> driver was  host_cdrom and readonly=off.

This would overload readonly with a completely unrelated option (should
eject be allowed). Doesn't sound like a great idea.

Kevin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom
  2011-04-12  8:10   ` Kevin Wolf
@ 2011-04-12  8:19     ` Daniel P. Berrange
  2011-04-12  9:14       ` Stefan Hajnoczi
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel P. Berrange @ 2011-04-12  8:19 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: Stefan Hajnoczi, qemu-devel, Markus Armbruster, Ryan Harper,
	Amit Shah, Christoph Hellwig

On Tue, Apr 12, 2011 at 10:10:44AM +0200, Kevin Wolf wrote:
> Am 12.04.2011 09:52, schrieb Daniel P. Berrange:
> >  - If the -drive specification has  readonly=on (thus O_RDONLY to
> >    open(2) call) , I expect QEMU (or the kernel) to forbid the
> >    "eject" command on the host CDROM. This should prevent two guests
> >    interfering seriously with each other.
> > 
> > So I think using O_EXCL would be OK, in the case where the block
> > driver was  host_cdrom and readonly=off.
> 
> This would overload readonly with a completely unrelated option (should
> eject be allowed). Doesn't sound like a great idea.

Use of the "host_cdrom" block driver enables passthrough of
commands to the host device.

Use of "readonly" is what controls whether individual passthrough
commands are actually permitted.

To me, "readonly" means don't allow anything that would impact
another guests view of the file/device. So forbidding 'eject'
is within scope of that IMHO.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom
  2011-04-12  8:19     ` Daniel P. Berrange
@ 2011-04-12  9:14       ` Stefan Hajnoczi
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Hajnoczi @ 2011-04-12  9:14 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: Kevin Wolf, qemu-devel, Markus Armbruster, Ryan Harper, Amit Shah,
	Christoph Hellwig

On Tue, Apr 12, 2011 at 9:19 AM, Daniel P. Berrange <berrange@redhat.com> wrote:
> On Tue, Apr 12, 2011 at 10:10:44AM +0200, Kevin Wolf wrote:
>> Am 12.04.2011 09:52, schrieb Daniel P. Berrange:
>> >  - If the -drive specification has  readonly=on (thus O_RDONLY to
>> >    open(2) call) , I expect QEMU (or the kernel) to forbid the
>> >    "eject" command on the host CDROM. This should prevent two guests
>> >    interfering seriously with each other.
>> >
>> > So I think using O_EXCL would be OK, in the case where the block
>> > driver was  host_cdrom and readonly=off.
>>
>> This would overload readonly with a completely unrelated option (should
>> eject be allowed). Doesn't sound like a great idea.
>
> Use of the "host_cdrom" block driver enables passthrough of
> commands to the host device.
>
> Use of "readonly" is what controls whether individual passthrough
> commands are actually permitted.
>
> To me, "readonly" means don't allow anything that would impact
> another guests view of the file/device. So forbidding 'eject'
> is within scope of that IMHO.

I agree with Kevin here.  You're overloading the option.

Today I doubt readonly will prevent the eject/lock ioctls but I haven't tested.

I'm becoming more convinced now that we should be using O_EXCL.  Like
you say, forcing raw gives us the option to share the device for
reading without allowing the dangerous ioctls.

Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-04-12  9:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-08 11:33 [Qemu-devel] To O_EXCL or not to O_EXCL open host_cdrom Stefan Hajnoczi
2011-04-11  5:07 ` [Qemu-devel] " Amit Shah
2011-04-11  8:31   ` Stefan Hajnoczi
2011-04-11 13:30     ` Avi Kivity
2011-04-11 13:27 ` [Qemu-devel] " Avi Kivity
2011-04-11 18:19 ` Christoph Hellwig
2011-04-12  7:52 ` Daniel P. Berrange
2011-04-12  8:10   ` Kevin Wolf
2011-04-12  8:19     ` Daniel P. Berrange
2011-04-12  9:14       ` Stefan Hajnoczi

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).