All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Jan Kiszka <jan.kiszka@web.de>
Cc: Jason Baron <jbaron@redhat.com>,
	qemu-devel@nongnu.org, kvm@vger.kernel.org, mst@redhat.com
Subject: Re: [PATCH] kvm: deassign irqs in reset path
Date: Fri, 30 Mar 2012 15:09:11 -0600	[thread overview]
Message-ID: <1333141751.29235.31.camel@ul30vt> (raw)
In-Reply-To: <4F7618FC.7040807@web.de>

On Fri, 2012-03-30 at 22:35 +0200, Jan Kiszka wrote:
> On 2012-03-30 22:31, Jason Baron wrote:
> > On Fri, Mar 30, 2012 at 10:18:31PM +0200, Jan Kiszka wrote:
> >>>>> The root cause of the problem is that the 'reset_assigned_device()' code
> >>>>> first writes a 0 to the command register. Then, when qemu subsequently does
> >>>>> a kvm_deassign_irq() (called by assign_irq(), in the system_reset path),
> >>>>> the kernel ends up calling '__msix_mask_irq()', which performs a write to
> >>>>> the memory mapped msi vector space. Since, we've explicitly told the device
> >>>>> to disallow mmio access (via the 0 write to the command register), we end
> >>>>> up with the above 'Unsupported Request'.
> >>>>>
> >>>>> The fix here is to first call kvm_deassign_irq(), before doing the reset,
> >>>>
> >>>> s/fix/workaround/. This is a kernel bug if userspace can crash the
> >>>> system like this, no? Let's fix the kernel first and then look at what
> >>>> needs to be changed here.
> >>>>
> >>>> Jan
> >>>>
> >>>
> >>> But don't I need special privalege to run the device assignment bits?
> >>
> >> Yes, but even that might be moderated by a management component like
> >> libvirt.
> >>
> >>> For example, this crash is precipitated by a write of '0' to the pci
> >>> device config register from userspace. Surely, not every is allowed to
> >>> do that write. So it seems to me, that this patch is in keeping with the
> >>> current model of how things work.
> >>
> >> No user should needlessly be able to crash the host by issuing valid
> >> commands in a special order.
> >>
> >> Jan
> >>
> > 
> > Right, but as I see device-assign.c, we are essentially programming the
> > pci device directly from userspace. Put another way, the kernel could
> > crash the system if it programmed a pci device in the wrong order. So I
> > don't see how this is different. But maybe I'm misunderstanding the
> > model here?
> 
> The model is that the KVM device assignment subsystem in the kernel (or
> vfio in the future) + the IOMMU confine what userspace (not the qemu
> guest) can do with the device and prevent that any harm is caused to the
> system. There might be practical holes in this model, but this is still
> what we are striving for.

Jan,

It's possible to cause this same crash w/o device assignment involved.
Use setpci to zero the command register, then set smp_affinity on the
device using MSI-X.  It's the right thing to do for qemu reset to return
device interrupts to a known state, even if it does just happen to be a
workaround for this problem.  Given that we're using a generic interface
for config space, I'm not sure how practical it is to start arbitrarily
picking certain things as bad and making them inaccessible (there are
plenty of targets in PCI config space on x86).  Thanks,

Alex

WARNING: multiple messages have this Message-ID (diff)
From: Alex Williamson <alex.williamson@redhat.com>
To: Jan Kiszka <jan.kiszka@web.de>
Cc: Jason Baron <jbaron@redhat.com>,
	qemu-devel@nongnu.org, kvm@vger.kernel.org, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH] kvm: deassign irqs in reset path
Date: Fri, 30 Mar 2012 15:09:11 -0600	[thread overview]
Message-ID: <1333141751.29235.31.camel@ul30vt> (raw)
In-Reply-To: <4F7618FC.7040807@web.de>

On Fri, 2012-03-30 at 22:35 +0200, Jan Kiszka wrote:
> On 2012-03-30 22:31, Jason Baron wrote:
> > On Fri, Mar 30, 2012 at 10:18:31PM +0200, Jan Kiszka wrote:
> >>>>> The root cause of the problem is that the 'reset_assigned_device()' code
> >>>>> first writes a 0 to the command register. Then, when qemu subsequently does
> >>>>> a kvm_deassign_irq() (called by assign_irq(), in the system_reset path),
> >>>>> the kernel ends up calling '__msix_mask_irq()', which performs a write to
> >>>>> the memory mapped msi vector space. Since, we've explicitly told the device
> >>>>> to disallow mmio access (via the 0 write to the command register), we end
> >>>>> up with the above 'Unsupported Request'.
> >>>>>
> >>>>> The fix here is to first call kvm_deassign_irq(), before doing the reset,
> >>>>
> >>>> s/fix/workaround/. This is a kernel bug if userspace can crash the
> >>>> system like this, no? Let's fix the kernel first and then look at what
> >>>> needs to be changed here.
> >>>>
> >>>> Jan
> >>>>
> >>>
> >>> But don't I need special privalege to run the device assignment bits?
> >>
> >> Yes, but even that might be moderated by a management component like
> >> libvirt.
> >>
> >>> For example, this crash is precipitated by a write of '0' to the pci
> >>> device config register from userspace. Surely, not every is allowed to
> >>> do that write. So it seems to me, that this patch is in keeping with the
> >>> current model of how things work.
> >>
> >> No user should needlessly be able to crash the host by issuing valid
> >> commands in a special order.
> >>
> >> Jan
> >>
> > 
> > Right, but as I see device-assign.c, we are essentially programming the
> > pci device directly from userspace. Put another way, the kernel could
> > crash the system if it programmed a pci device in the wrong order. So I
> > don't see how this is different. But maybe I'm misunderstanding the
> > model here?
> 
> The model is that the KVM device assignment subsystem in the kernel (or
> vfio in the future) + the IOMMU confine what userspace (not the qemu
> guest) can do with the device and prevent that any harm is caused to the
> system. There might be practical holes in this model, but this is still
> what we are striving for.

Jan,

It's possible to cause this same crash w/o device assignment involved.
Use setpci to zero the command register, then set smp_affinity on the
device using MSI-X.  It's the right thing to do for qemu reset to return
device interrupts to a known state, even if it does just happen to be a
workaround for this problem.  Given that we're using a generic interface
for config space, I'm not sure how practical it is to start arbitrarily
picking certain things as bad and making them inaccessible (there are
plenty of targets in PCI config space on x86).  Thanks,

Alex

  reply	other threads:[~2012-03-30 21:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-30 19:18 [PATCH] kvm: deassign irqs in reset path Jason Baron
2012-03-30 19:18 ` [Qemu-devel] " Jason Baron
2012-03-30 19:29 ` Jan Kiszka
2012-03-30 19:29   ` [Qemu-devel] " Jan Kiszka
2012-03-30 20:13   ` Jason Baron
2012-03-30 20:13     ` [Qemu-devel] " Jason Baron
2012-03-30 20:18     ` Jan Kiszka
2012-03-30 20:18       ` [Qemu-devel] " Jan Kiszka
2012-03-30 20:31       ` Jason Baron
2012-03-30 20:35         ` Jan Kiszka
2012-03-30 21:09           ` Alex Williamson [this message]
2012-03-30 21:09             ` Alex Williamson
2012-03-30 22:15             ` Jan Kiszka
2012-03-30 22:15               ` [Qemu-devel] " Jan Kiszka
2012-04-01 10:57               ` Michael S. Tsirkin
2012-04-01 10:57                 ` Michael S. Tsirkin
2012-03-31  8:54 ` Jan Kiszka
2012-03-31  8:54   ` [Qemu-devel] " Jan Kiszka

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=1333141751.29235.31.camel@ul30vt \
    --to=alex.williamson@redhat.com \
    --cc=jan.kiszka@web.de \
    --cc=jbaron@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.