02 Aug, 2016

1 commit

  • The interaction between virtio and IOMMUs is messy.

    On most systems with virtio, physical addresses match bus addresses,
    and it doesn't particularly matter which one we use to program
    the device.

    On some systems, including Xen and any system with a physical device
    that speaks virtio behind a physical IOMMU, we must program the IOMMU
    for virtio DMA to work at all.

    On other systems, including SPARC and PPC64, virtio-pci devices are
    enumerated as though they are behind an IOMMU, but the virtio host
    ignores the IOMMU, so we must either pretend that the IOMMU isn't
    there or somehow map everything as the identity.

    Add a feature bit to detect that quirk: VIRTIO_F_IOMMU_PLATFORM.

    Any device with this feature bit set to 0 needs a quirk and has to be
    passed physical addresses (as opposed to bus addresses) even though
    the device is behind an IOMMU.

    Note: it has to be a per-device quirk because for example, there could
    be a mix of passed-through and virtual virtio devices. As another
    example, some devices could be implemented by an out of process
    hypervisor backend (in case of qemu vhost, or vhost-user) and so support
    for an IOMMU needs to be coded up separately.

    It would be cleanest to handle this in IOMMU core code, but that needs
    per-device DMA ops. While we are waiting for that to be implemented, use
    a work-around in virtio core.

    Note: a "noiommu" feature is a quirk - add a wrapper to make
    that clear.

    Signed-off-by: Michael S. Tsirkin

    Michael S. Tsirkin
     

13 Jan, 2016

1 commit

  • checkpatch.pl wants arrays of strings declared as follows:

    static const char * const names[] = { "vq-1", "vq-2", "vq-3" };

    Currently the find_vqs() function takes a const char *names[] argument
    so passing checkpatch.pl's const char * const names[] results in a
    compiler error due to losing the second const.

    This patch adjusts the find_vqs() prototype and updates all virtio
    transports. This makes it possible for virtio_balloon.c, virtio_input.c,
    virtgpu_kms.c, and virtio_rpmsg_bus.c to use the checkpatch.pl-friendly
    type.

    Signed-off-by: Stefan Hajnoczi
    Signed-off-by: Michael S. Tsirkin
    Acked-by: Bjorn Andersson

    Stefan Hajnoczi
     

01 Jun, 2015

2 commits

  • The current memory accessors logic is:
    - little endian if little_endian
    - native endian (i.e. no byteswap) if !little_endian

    If we want to fully support cross-endian vhost, we also need to be
    able to convert to big endian.

    Instead of changing the little_endian argument to some 3-value enum, this
    patch changes the logic to:
    - little endian if little_endian
    - big endian if !little_endian

    The native endian case is handled by all users with a trivial helper. This
    patch doesn't change any functionality, nor it does add overhead.

    Signed-off-by: Greg Kurz

    Signed-off-by: Michael S. Tsirkin
    Reviewed-by: Cornelia Huck
    Reviewed-by: David Gibson

    Greg Kurz
     
  • Signed-off-by: Greg Kurz

    Signed-off-by: Michael S. Tsirkin
    Acked-by: Cornelia Huck
    Reviewed-by: David Gibson

    Greg Kurz
     

01 Apr, 2015

2 commits

  • "virtio: core support for config generation"
    fixed reading up 64 bit values, adding generation
    checks for such reads.

    By mistake, it left an explicit get call in place
    as well. the result is that the value is read twice,
    the first result is discarded.

    Not a big deal since this only happens with virtio
    blk and only on boot ATM, so performance isn't
    affected, but let's clean it up.

    Signed-off-by: Michael S. Tsirkin
    Reviewed-by: Cornelia Huck
    Signed-off-by: Rusty Russell

    Michael S. Tsirkin
     
  • This simply reorders functions in virtio_config
    so width access wrapper helpers are all together.
    Drops an extra empty line while we are at it.

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

    Michael S. Tsirkin
     

15 Dec, 2014

1 commit

  • virtio 1.0 spec says:

    Drivers MUST NOT assume reads from fields greater than 32 bits wide are
    atomic, nor are reads from multiple fields: drivers SHOULD read device
    configuration space fields like so:
    u32 before, after;
    do {
    before = get_config_generation(device);
    // read config entry/entries.
    after = get_config_generation(device);
    } while (after != before);

    Do exactly this, for transports that support it.

    Signed-off-by: Michael S. Tsirkin

    Michael S. Tsirkin
     

12 Dec, 2014

1 commit

  • virtio_cread_bytes is implemented incorrectly in case length happens to
    be 2,4 or 8 bytes: transports and devices will assume it's an integer
    value that has to be converted to LE format.

    Let's just do multiple 1-byte reads: this also makes life easier
    for transports who only need to implement 1,2,4 and 8 byte reads.

    Signed-off-by: Michael S. Tsirkin

    Michael S. Tsirkin
     

09 Dec, 2014

6 commits

  • This will make it easy for transports to validate features and return
    failure.

    Signed-off-by: Michael S. Tsirkin

    Michael S. Tsirkin
     
  • We (ab)use virtio conversion functions for device-specific
    config space accesses.

    Based on original patches by Cornelia and Rusty.

    Signed-off-by: Rusty Russell
    Signed-off-by: Cornelia Huck
    Signed-off-by: Michael S. Tsirkin
    Reviewed-by: David Hildenbrand

    Michael S. Tsirkin
     
  • virtio 1.0 makes all memory structures LE, so
    we need APIs to conditionally do a byteswap on BE
    architectures.

    To make it easier to check code statically,
    add virtio specific types for multi-byte integers
    in memory.

    Add low level wrappers that do a byteswap conditionally, these will be
    useful e.g. for vhost. Add high level wrappers that
    query device endian-ness and act accordingly.

    Signed-off-by: Michael S. Tsirkin
    Reviewed-by: Cornelia Huck

    Michael S. Tsirkin
     
  • Change u32 to u64, and use BIT_ULL and 1ULL everywhere.

    Note: transports are unchanged, and only set low 32 bit.
    This guarantees that no transport sets e.g. VERSION_1
    by mistake without proper support.

    Based on patch by Rusty.

    Signed-off-by: Rusty Russell
    Signed-off-by: Cornelia Huck
    Signed-off-by: Michael S. Tsirkin
    Reviewed-by: David Hildenbrand
    Reviewed-by: Cornelia Huck

    Michael S. Tsirkin
     
  • It seemed like a good idea to use bitmap for features
    in struct virtio_device, but it's actually a pain,
    and seems to become even more painful when we get more
    than 32 feature bits. Just change it to a u32 for now.

    Based on patch by Rusty.

    Suggested-by: David Hildenbrand
    Signed-off-by: Rusty Russell
    Signed-off-by: Cornelia Huck
    Signed-off-by: Michael S. Tsirkin
    Reviewed-by: Cornelia Huck

    Michael S. Tsirkin
     
  • Add low level APIs to test/set/clear feature bits.
    For use by transports, to make it easier to
    write code independent of feature bit array format.

    Note: APIs is prefixed with __ and has _bit suffix
    to stress its low level nature. It's for use by transports only:
    drivers should use virtio_has_feature and never need to set/clear
    features.

    Signed-off-by: Michael S. Tsirkin
    Reviewed-by: Cornelia Huck

    Michael S. Tsirkin
     

15 Oct, 2014

1 commit

  • virtio spec 0.9.X requires DRIVER_OK to be set before
    VQs are used, but some drivers use VQs before probe
    function returns.
    Since DRIVER_OK is set after probe, this violates the spec.

    Even though under virtio 1.0 transitional devices support this
    behaviour, we want to make it possible for those early callers to become
    spec compliant and eventually support non-transitional devices.

    Add API for drivers to call before using VQs.

    Sets DRIVER_OK internally.

    Signed-off-by: Michael S. Tsirkin
    Reviewed-by: Cornelia Huck
    Signed-off-by: Rusty Russell

    Michael S. Tsirkin
     

17 Oct, 2013

2 commits


13 Oct, 2012

1 commit


28 Sep, 2012

2 commits

  • virtio network device multiqueue support reserves
    vq 3 for future use (useful both for future extensions and to make it
    pretty - this way receive vqs have even and transmit - odd numbers).
    Make it possible to skip initialization for
    specific vq numbers by specifying NULL for name.
    Document this usage as well as (existing) NULL callback.

    Drivers using this not coded up yet, so I simply tested
    with virtio-pci and verified that this patch does
    not break existing drivers.

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

    Michael S. Tsirkin
     
  • Sometimes, virtio device need to configure irq affinity hint to maximize the
    performance. Instead of just exposing the irq of a virtqueue, this patch
    introduce an API to set the affinity for a virtqueue.

    The api is best-effort, the affinity hint may not be set as expected due to
    platform support, irq sharing or irq type. Currently, only pci method were
    implemented and we set the affinity according to:

    - if device uses INTX, we just ignore the request
    - if device has per vq vector, we force the affinity hint
    - if the virtqueues share MSI, make the affinity OR over all affinities
    requested

    Signed-off-by: Jason Wang
    Signed-off-by: Paolo Bonzini
    Signed-off-by: Rusty Russell

    Jason Wang
     

22 May, 2012

1 commit

  • - Delete "@request_vqs" and "@free_vqs" comments, since
    they are no longer in struct virtio_config_ops.
    - According to the macro below, "@val" should be "@v".

    Signed-off-by: Chen Baozi
    Signed-off-by: Rusty Russell

    Chen Baozi
     

05 Mar, 2012

1 commit

  • If a header file is making use of BUG, BUG_ON, BUILD_BUG_ON, or any
    other BUG variant in a static inline (i.e. not in a #define) then
    that header really should be including and not just
    expecting it to be implicitly present.

    We can make this change risk-free, since if the files using these
    headers didn't have exposure to linux/bug.h already, they would have
    been causing compile failures/warnings.

    Signed-off-by: Paul Gortmaker

    Paul Gortmaker
     

03 Dec, 2011

1 commit


24 Nov, 2011

1 commit

  • 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
     

17 Nov, 2011

1 commit


02 Nov, 2011

1 commit

  • This patch adds virtio_config_val_len() which allows retrieving variable
    length data from the virtio config space only if a specific feature is on.

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

    Sasha Levin
     

30 May, 2011

1 commit

  • It's unclear to me if it's important, but it's obviously causing my
    technical colleages some headaches and I'd hate such imprecision to
    slow virtio adoption.

    I've emailed this to all non-trivial contributors for approval, too.

    Signed-off-by: Rusty Russell
    Acked-by: Grant Likely
    Acked-by: Ryan Harper
    Acked-by: Anthony Liguori
    Acked-by: Eric Van Hensbergen
    Acked-by: john cooper
    Acked-by: Aneesh Kumar K.V
    Acked-by: Christian Borntraeger
    Acked-by: Fernando Luis Vazquez Cao

    Rusty Russell
     

24 Jan, 2011

1 commit


23 Sep, 2009

1 commit

  • gcc permitting variable length arrays makes the current construct used for
    BUILD_BUG_ON() useless, as that doesn't produce any diagnostic if the
    controlling expression isn't really constant. Instead, this patch makes
    it so that a bit field gets used here. Consequently, those uses where the
    condition isn't really constant now also need fixing.

    Note that in the gfp.h, kmemcheck.h, and virtio_config.h cases
    MAYBE_BUILD_BUG_ON() really just serves documentation purposes - even if
    the expression is compile time constant (__builtin_constant_p() yields
    true), the array is still deemed of variable length by gcc, and hence the
    whole expression doesn't have the intended effect.

    [akpm@linux-foundation.org: make arch/sparc/include/asm/vio.h compile]
    [akpm@linux-foundation.org: more nonsensical assertions in tpm.c..]
    Signed-off-by: Jan Beulich
    Cc: Andi Kleen
    Cc: Rusty Russell
    Cc: Catalin Marinas
    Cc: "David S. Miller"
    Cc: Rajiv Andrade
    Cc: Mimi Zohar
    Cc: James Morris
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Beulich
     

30 Jul, 2009

1 commit


12 Jun, 2009

3 commits


25 Jul, 2008

3 commits


30 May, 2008

2 commits

  • virtio allows drivers to suppress callbacks (ie. interrupts) for
    efficiency (no locking, it's just an optimization).

    There's a similar mechanism for the host to suppress notifications
    coming from the guest: in that case, we ignore the suppression if the
    ring is completely full.

    It turns out that life is simpler if the host similarly ignores
    callback suppression when the ring is completely empty: the network
    driver wants to free up old packets in a timely manner, and otherwise
    has to use a timer to poll.

    We have to remove the code which ignores interrupts when the driver
    has disabled them (again, it had no locking and hence was unreliable
    anyway).

    Signed-off-by: Rusty Russell

    Rusty Russell
     
  • Rusty,

    This patch is a prereq for the virtio_blk blocksize patch, please apply it
    first.

    Adding an u32 value to the virtio_blk_config unconvered a small bug the config
    space defintions:
    v is a pointer, to we have to use sizeof(*v) instead of sizeof(v).

    Signed-off-by: Christian Borntraeger
    Signed-off-by: Rusty Russell

    Christian Borntraeger
     

02 May, 2008

2 commits

  • A recent proposed feature addition to the virtio block driver revealed
    some flaws in the API: in particular, we assume that feature
    negotiation is complete once a driver's probe function returns.

    There is nothing in the API to require this, however, and even I
    didn't notice when it was violated.

    So instead, we require the driver to specify what features it supports
    in a table, we can then move the feature negotiation into the virtio
    core. The intersection of device and driver features are presented in
    a new 'features' bitmap in the struct virtio_device.

    Note that this highlights the difference between Linux unsigned-long
    bitmaps where each unsigned long is in native endian, and a
    straight-forward little-endian array of bytes.

    Drivers can still remove feature bits in their probe routine if they
    really have to.

    API changes:
    - dev->config->feature() no longer gets and acks a feature.
    - drivers should advertise their features in the 'feature_table' field
    - use virtio_has_feature() for extra sanity when checking feature bits

    Signed-off-by: Rusty Russell

    Rusty Russell
     
  • A recent proposed feature addition to the virtio block driver revealed
    some flaws in the API, in particular how easy it is to break big
    endian machines.

    The virtio config space was originally chosen to be little-endian,
    because we thought the config might be part of the PCI config space
    for virtio_pci. It's actually a separate mmio region, so that
    argument holds little water; as only x86 is currently using the virtio
    mechanism, we can change this (but must do so now, before the
    impending s390 merge).

    API changes:
    - __virtio_config_val() just becomes a striaght vdev->config_get() call.

    Signed-off-by: Rusty Russell

    Rusty Russell