1. 18 12月, 2012 1 次提交
  2. 22 10月, 2012 1 次提交
    • W
      virtio: force vring descriptors to be allocated from lowmem · b92b1b89
      Will Deacon 提交于
      Virtio devices may attempt to add descriptors to a virtqueue from atomic
      context using GFP_ATOMIC allocation. This is problematic because such
      allocations can fall outside of the lowmem mapping, causing virt_to_phys
      to report bogus physical addresses which are subsequently passed to
      userspace via the buffers for the virtual device.
      
      This patch masks out __GFP_HIGH and __GFP_HIGHMEM from the requested
      flags when allocating descriptors for a virtqueue. If an atomic
      allocation is requested and later fails, we will return -ENOSPC which
      will be handled by the driver.
      
      Cc: stable@kernel.org
      Cc: Sasha Levin <levinsasha928@gmail.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      b92b1b89
  3. 28 9月, 2012 11 次提交
  4. 20 7月, 2012 1 次提交
  5. 09 7月, 2012 1 次提交
    • M
      virtio-balloon: fix add/get API use · 9c378abc
      Michael S. Tsirkin 提交于
      Since ee7cd898 'virtio: expose added
      descriptors immediately.', in virtio balloon virtqueue_get_buf might
      now run concurrently with virtqueue_kick.  I audited both and this
      seems safe in practice but this is not guaranteed by the API.
      Additionally, a spurious interrupt might in theory make
      virtqueue_get_buf run in parallel with virtqueue_add_buf, which is
      racy.
      
      While we might try to protect against spurious callbacks it's
      easier to fix the driver: balloon seems to be the only one
      (mis)using the API like this, so let's just fix balloon.
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (removed unused var)
      9c378abc
  6. 22 5月, 2012 4 次提交
  7. 17 5月, 2012 1 次提交
  8. 15 4月, 2012 2 次提交
  9. 31 3月, 2012 5 次提交
  10. 29 3月, 2012 1 次提交
  11. 01 3月, 2012 1 次提交
    • A
      virtio: balloon: leak / fill balloon across S4 · 4eb05d56
      Amit Shah 提交于
      commit e562966d added support for S4 to
      the balloon driver.  The freeze function did nothing to free the pages,
      since reclaiming the pages from the host to immediately give them back
      (if S4 was successful) seemed wasteful.  Also, if S4 wasn't successful,
      the guest would have to re-fill the balloon.  On restore, the pages were
      supposed to be marked freed and the free page counters were incremented
      to reflect the balloon was totally deflated.
      
      However, this wasn't done right.  The pages that were earlier taken away
      from the guest during a balloon inflation operation were just shown as
      used pages after a successful restore from S4.  Just a fancy way of
      leaking lots of memory.
      
      Instead of trying that, just leak the balloon on freeze and fill it on
      restore/thaw paths.  This works properly now.  The optimisation to not
      leak can be added later on after a bit of refactoring of the code.
      Signed-off-by: NAmit Shah <amit.shah@redhat.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      4eb05d56
  12. 28 1月, 2012 2 次提交
  13. 12 1月, 2012 9 次提交
    • A
      virtio: balloon: Add freeze, restore handlers to support S4 · e562966d
      Amit Shah 提交于
      Handling balloon hibernate / restore is tricky.  If the balloon was
      inflated before going into the hibernation state, upon resume, the host
      will not have any memory of that.  Any pages that were passed on to the
      host earlier would most likely be invalid, and the host will have to
      re-balloon to the previous value to get in the pre-hibernate state.
      
      So the only sane thing for the guest to do here is to discard all the
      pages that were put in the balloon.  When to discard the pages is the
      next question.
      
      One solution is to deflate the balloon just before writing the image to
      the disk (in the freeze() PM callback).  However, asking for pages from
      the host just to discard them immediately after seems wasteful of
      resources.  Hence, it makes sense to do this by just fudging our
      counters soon after wakeup.  This means we don't deflate the balloon
      before sleep, and also don't put unnecessary pressure on the host.
      
      This also helps in the thaw case: if the freeze fails for whatever
      reason, the balloon should continue to remain in the inflated state.
      This was tested by issuing 'swapoff -a' and trying to go into the S4
      state.  That fails, and the balloon stays inflated, as expected.  Both
      the host and the guest are happy.
      
      Finally, in the restore() callback, we empty the list of pages that were
      previously given off to the host, add the appropriate number of pages to
      the totalram_pages counter, reset the num_pages counter to 0, and
      all is fine.
      
      As a last step, delete the vqs on the freeze callback to prepare for
      hibernation, and re-create them in the restore and thaw callbacks to
      resume normal operation.
      
      The kthread doesn't race with any operations here, since it's frozen
      before the freeze() call and is thawed after the thaw() and restore()
      callbacks, so we're safe with that.
      Signed-off-by: NAmit Shah <amit.shah@redhat.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      e562966d
    • A
      virtio: balloon: Move vq initialization into separate function · be91c33d
      Amit Shah 提交于
      The probe and PM restore functions will share this code.
      Signed-off-by: NAmit Shah <amit.shah@redhat.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      be91c33d
    • A
      virtio: pci: add PM notification handlers for restore, freeze, thaw, poweroff · f0fe6f11
      Amit Shah 提交于
      Handle thaw, restore and freeze notifications from the PM core.  Expose
      these to individual virtio drivers that can quiesce and resume vq
      operations.  For drivers not implementing the thaw() method, use the
      restore method instead.
      
      These functions also save device-specific data so that the device can be
      put in pre-suspend state after resume, and disable and enable the PCI
      device in the freeze and resume functions, respectively.
      Signed-off-by: NAmit Shah <amit.shah@redhat.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      f0fe6f11
    • A
      virtio: pci: switch to new PM API · d0775363
      Amit Shah 提交于
      The older PM API doesn't have a way to get notifications on hibernate
      events.  Switch to the newer one that gives us those notifications.
      Signed-off-by: NAmit Shah <amit.shah@redhat.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      d0775363
    • R
      virtio: add debugging if driver doesn't kick. · e93300b1
      Rusty Russell 提交于
      Under the existing #ifdef DEBUG, check that they don't have more than
      1/10 of a second between an add_buf() and a
      virtqueue_notify()/virtqueue_kick_prepare() call.
      
      We could get false positives on a really busy system, but good for
      development.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      e93300b1
    • R
      virtio: expose added descriptors immediately. · ee7cd898
      Rusty Russell 提交于
      A virtio driver does virtqueue_add_buf() multiple times before finally
      calling virtqueue_kick(); previously we only exposed the added buffers
      in the virtqueue_kick() call.  This means we don't need a memory
      barrier in virtqueue_add_buf(), but it reduces concurrency as the
      device (ie. host) can't see the buffers until the kick.
      
      In the unusual (but now possible) case where a driver does add_buf()
      and get_buf() without doing a kick, we do need to insert one before
      our counter wraps.  Otherwise we could wrap num_added, and later on
      not realize that we have passed the marker where we should have
      kicked.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      ee7cd898
    • R
      virtio: avoid modulus operation. · 3b720b8c
      Rusty Russell 提交于
      Since we know vq->vring.num is a power of 2, modulus is lazy (it's asserted
      in vring_new_virtqueue()).
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      3b720b8c
    • R
      virtio: support unlocked queue kick · 41f0377f
      Rusty Russell 提交于
      Based on patch by Christoph for virtio_blk speedup:
      
      	Split virtqueue_kick to be able to do the actual notification
      	outside the lock protecting the virtqueue.  This patch was
      	originally done by Stefan Hajnoczi, but I can't find the
      	original one anymore and had to recreated it from memory.
      	Pointers to the original or corrections for the commit message
      	are welcome.
      
      Stefan's patch was here:
      
      	https://github.com/stefanha/linux/commit/a6d06644e3a58e57a774e77d7dc34c4a5a2e7496
      	http://www.spinics.net/lists/linux-virtualization/msg14616.html
      
      Third time's the charm!
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      41f0377f
    • R
      virtio: rename virtqueue_add_buf_gfp to virtqueue_add_buf · f96fde41
      Rusty Russell 提交于
      Remove wrapper functions. This makes the allocation type explicit in
      all callers; I used GPF_KERNEL where it seemed obvious, left it at
      GFP_ATOMIC otherwise.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      f96fde41