20 Jul, 2012

1 commit

  • This patch changes virtio-scsi to use a new virtio_driver->scan() callback
    so that scsi_scan_host() can be properly invoked once virtio_dev_probe() has
    set add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK) to signal active virtio-ring
    operation, instead of from within virtscsi_probe().

    This fixes a bug where SCSI LUN scanning for both virtio-scsi-raw and
    virtio-scsi/tcm_vhost setups was happening before VIRTIO_CONFIG_S_DRIVER_OK
    had been set, causing VIRTIO_SCSI_S_BAD_TARGET to occur. This fixes a bug
    with virtio-scsi/tcm_vhost where LUN scan was not detecting LUNs.

    Tested with virtio-scsi-raw + virtio-scsi/tcm_vhost w/ IBLOCK on 3.5-rc2 code.

    Signed-off-by: Nicholas Bellinger
    Acked-by: Paolo Bonzini
    Signed-off-by: James Bottomley

    Nicholas Bellinger
     

09 Jul, 2012

1 commit

  • Since ee7cd8981e15bcb365fc762afe3fc47b8242f630 '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: Michael S. Tsirkin
    Signed-off-by: Rusty Russell (removed unused var)

    Michael S. Tsirkin
     

22 May, 2012

4 commits


17 May, 2012

1 commit

  • When the balloon module is removed, we deflate the balloon, reclaiming
    all the pages that were given to the host. However, we don't update the
    config values for the new balloon size, resulting in the host showing
    outdated balloon values.

    The size update is done after each leak and fill operation, only the
    module removal case was left out.

    Signed-off-by: Amit Shah
    Signed-off-by: Michael S. Tsirkin

    Amit Shah
     

15 Apr, 2012

2 commits

  • As reported by David Gibson, current code handles PAGE_SIZE != 4k
    completely wrong which can lead to guest memory corruption errors:

    - page_to_balloon_pfn is wrong: e.g. on system with 64K page size
    it gives the same pfn value for 16 different pages.

    - we also need to convert back to linux pfns when we free.

    - for each linux page we need to tell host about multiple balloon
    pages, but code only adds one pfn to the array.

    This patch fixes all that, tested with a 64k ppc64 kernel.

    Reported-by: David Gibson
    Tested-by: David Gibson
    Signed-off-by: Michael S. Tsirkin

    Michael S. Tsirkin
     
  • Although virtio config space fields are usually in guest-native endian,
    the spec for the virtio balloon device explicitly states that both fields
    in its config space are little-endian.

    However, the current virtio_balloon driver does not have a suitable endian
    swap for the 'num_pages' field, although it does have one for the 'actual'
    field. This patch corrects the bug, adding sparse annotation while we're
    at it.

    Signed-off-by: David Gibson
    Signed-off-by: Michael S. Tsirkin

    David Gibson
     

31 Mar, 2012

5 commits


29 Mar, 2012

1 commit


01 Mar, 2012

1 commit

  • commit e562966dbaf49e7804097cd991e5d3a8934fc148 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: Amit Shah
    Signed-off-by: Rusty Russell

    Amit Shah
     

28 Jan, 2012

2 commits

  • Use virtio_mb() to make sure the available index to be exposed before
    checking the the avail event. Otherwise we may get stale value of
    avail event in guest and never kick the host after.

    Note: this fixes a bug introduced by ee7cd8981e15bcb365fc762afe3fc47b8242f630.

    Signed-off-by: Jason Wang
    Acked-by: Michael S. Tsirkin
    Signed-off-by: Rusty Russell
    Cc: stable@kernel.org

    Jason Wang
     
  • Note: this fixes a bug introduced recently in
    7b21e34fd1c272e3a8c3846168f2f6287a4cd72b.

    Signed-off-by: Jason Wang
    Acked-by: Michael S. Tsirkin
    Signed-off-by: Rusty Russell

    Jason Wang
     

12 Jan, 2012

12 commits

  • 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: Amit Shah
    Signed-off-by: Rusty Russell

    Amit Shah
     
  • The probe and PM restore functions will share this code.

    Signed-off-by: Amit Shah
    Signed-off-by: Rusty Russell

    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: Amit Shah
    Signed-off-by: Rusty Russell

    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: Amit Shah
    Signed-off-by: Rusty Russell

    Amit Shah
     
  • 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: Rusty Russell

    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: Rusty Russell

    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: Rusty Russell

    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: Rusty Russell

    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: Rusty Russell
    Reviewed-by: Christoph Hellwig

    Rusty Russell
     
  • The old documentation is left over from when we used a structure with
    strategy pointers.

    And move the documentation to the C file as per kernel practice.
    Though I disagree...

    Signed-off-by: Rusty Russell
    Reviewed-by: Christoph Hellwig

    Rusty Russell
     
  • Trivial changes to remove forgotten junk, format comments, and correct names.

    Cc: Rusty Russell
    Cc: "Michael S. Tsirkin"
    Cc: virtualization@lists.linux-foundation.org
    Signed-off-by: Sasha Levin
    Signed-off-by: Rusty Russell

    Sasha Levin
     
  • We were cheating with our barriers; using the smp ones rather than the
    real device ones. That was fine, until rpmsg came along, which is
    used to talk to a real device (a non-SMP CPU).

    Unfortunately, just putting back the real barriers (reverting
    d57ed95d) causes a performance regression on virtio-pci. In
    particular, Amos reports netbench's TCP_RR over virtio_net CPU
    utilization increased up to 35% while throughput went down by up to
    14%.

    By comparison, this branch is in the noise.

    Reference: https://lkml.org/lkml/2011/12/11/22

    Signed-off-by: Rusty Russell

    Rusty Russell
     

03 Dec, 2011

1 commit


24 Nov, 2011

3 commits

  • virtio pci device reset actually just does an I/O
    write, which in PCI is really posted, that is it
    can complete on CPU before the device has received it.

    Further, interrupts might have been pending on
    another CPU, so device callback might get invoked after reset.

    This conflicts with how drivers use reset, which is typically:
    reset
    unregister
    a callback running after reset completed can race with
    unregister, potentially leading to use after free bugs.

    Fix by flushing out the write, and flushing pending interrupts.

    This assumes that device is never reset from
    its vq/config callbacks, or in parallel with being
    added/removed, document this assumption.

    Signed-off-by: Michael S. Tsirkin
    Signed-off-by: Rusty Russell

    Michael S. Tsirkin
     
  • Guest features selector spelling mistake.

    Cc: Pawel Moll
    Cc: Rusty Russell
    Cc: virtualization@lists.linux-foundation.org
    Signed-off-by: Sasha Levin
    Signed-off-by: Rusty Russell

    Sasha Levin
     
  • Fix this compile error on s390:

    CC [M] drivers/virtio/virtio_mmio.o
    drivers/virtio/virtio_mmio.c: In function 'vm_get_features':
    drivers/virtio/virtio_mmio.c:107:2: error: implicit declaration of function 'writel'

    Cc: Christian Borntraeger
    Signed-off-by: Heiko Carstens
    Acked-by: Pawel Moll
    Signed-off-by: Rusty Russell

    Heiko Carstens
     

22 Nov, 2011

1 commit


17 Nov, 2011

1 commit


14 Nov, 2011

1 commit

  • Commit 31a3ddda166cda86d2b5111e09ba4bda5239fae6 introduced
    a use after free in virtio-pci. The main issue is
    that the release method signals removal of the virtio device,
    while remove signals removal of the pci device.

    For example, on driver removal or hot-unplug,
    virtio_pci_release_dev is called before virtio_pci_remove.
    We then might get a crash as virtio_pci_remove tries to use the
    device freed by virtio_pci_release_dev.

    We allocate/free all resources together with the
    pci device, so we can leave the release method empty.

    Signed-off-by: Michael S. Tsirkin
    Acked-by: Amit Shah
    Signed-off-by: Rusty Russell
    Cc: stable@kernel.org

    Michael S. Tsirkin
     

07 Nov, 2011

1 commit

  • * 'modsplit-Oct31_2011' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg/linux: (230 commits)
    Revert "tracing: Include module.h in define_trace.h"
    irq: don't put module.h into irq.h for tracking irqgen modules.
    bluetooth: macroize two small inlines to avoid module.h
    ip_vs.h: fix implicit use of module_get/module_put from module.h
    nf_conntrack.h: fix up fallout from implicit moduleparam.h presence
    include: replace linux/module.h with "struct module" wherever possible
    include: convert various register fcns to macros to avoid include chaining
    crypto.h: remove unused crypto_tfm_alg_modname() inline
    uwb.h: fix implicit use of asm/page.h for PAGE_SIZE
    pm_runtime.h: explicitly requires notifier.h
    linux/dmaengine.h: fix implicit use of bitmap.h and asm/page.h
    miscdevice.h: fix up implicit use of lists and types
    stop_machine.h: fix implicit use of smp.h for smp_processor_id
    of: fix implicit use of errno.h in include/linux/of.h
    of_platform.h: delete needless include
    acpi: remove module.h include from platform/aclinux.h
    miscdevice.h: delete unnecessary inclusion of module.h
    device_cgroup.h: delete needless include
    net: sch_generic remove redundant use of
    net: inet_timewait_sock doesnt need
    ...

    Fix up trivial conflicts (other header files, and removal of the ab3550 mfd driver) in
    - drivers/media/dvb/frontends/dibx000_common.c
    - drivers/media/video/{mt9m111.c,ov6650.c}
    - drivers/mfd/ab3550-core.c
    - include/linux/dmaengine.h

    Linus Torvalds
     

02 Nov, 2011

2 commits

  • This patch, based on virtio PCI driver, adds support for memory
    mapped (platform) virtio device. This should allow environments
    like qemu to use virtio-based block & network devices even on
    platforms without PCI support.

    One can define and register a platform device which resources
    will describe memory mapped control registers and "mailbox"
    interrupt. Such device can be also instantiated using the Device
    Tree node with compatible property equal "virtio,mmio".

    Cc: Anthony Liguori
    Cc: Michael S.Tsirkin
    Signed-off-by: Pawel Moll
    Signed-off-by: Rusty Russell

    Pawel Moll
     
  • For the MSI but non-per_vq_vector case, the config/change vq
    also gets added to the list of vqs that need to process the
    MSI interrupt. This is not needed as config has it's own
    handler (vp_config_changed). In any case, vring_interrupt()
    finds nothing needs to be done on this vq.

    I tested this patch by testing the "Fallback:" and "Finally
    fall back" cases in vp_find_vqs(). Please review.

    Signed-off-by: Krishna Kumar
    Acked-by: Michael S. Tsirkin
    Signed-off-by: Rusty Russell

    Krishna Kumar