1. 30 5月, 2008 2 次提交
    • R
      virtio: virtio_pci should not set bus_id. · 5610bd15
      Rusty Russell 提交于
      The common virtio code sets the bus_id, overriding anything virtio_pci
      sets anyway.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      Cc: Christian Borntraeger <borntraeger@de.ibm.com>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Carsten Otte <cotte@de.ibm.com>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Chris Lalancette <clalance@redhat.com>
      Cc: Anthony Liguori <anthony@codemonkey.ws>
      5610bd15
    • R
      virtio: bus_id for devices should contain 'virtio' · 2ad3cfba
      Rusty Russell 提交于
      Chris Lalancette <clalance@redhat.com> points out that virtio.c sets all device
      names to '0', '1', etc, which looks silly in /proc/interrupts.  We change this
      from '%d' to 'virtio%d'.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      Cc: Christian Borntraeger <borntraeger@de.ibm.com>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Carsten Otte <cotte@de.ibm.com>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Chris Lalancette <clalance@redhat.com>
      Cc: Anthony Liguori <anthony@codemonkey.ws>
      2ad3cfba
  2. 02 5月, 2008 4 次提交
    • R
      virtio: explicit advertisement of driver features · c45a6816
      Rusty Russell 提交于
      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: NRusty Russell <rusty@rustcorp.com.au>
      c45a6816
    • R
      virtio: change config to guest endian. · 72e61eb4
      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: NRusty Russell <rusty@rustcorp.com.au>
      72e61eb4
    • H
      virtio: fix sparse return void-valued expression warnings · 597d56e4
      Harvey Harrison 提交于
      drivers/virtio/virtio_pci.c:148:2: warning: returning void-valued expression
      drivers/virtio/virtio_pci.c:155:2: warning: returning void-valued expression
      Signed-off-by: NHarvey Harrison <harvey.harrison@gmail.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      597d56e4
    • R
      virtio: ignore corrupted virtqueues rather than spinning. · 5ef82752
      Rusty Russell 提交于
      A corrupt virtqueue (caused by the other end screwing up) can have
      strange results such as a driver spinning: just bail when we try to
      get a buffer from a known-broken queue.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      5ef82752
  3. 08 4月, 2008 1 次提交
    • R
      virtio: remove overzealous BUG_ON. · 2557a933
      Rusty Russell 提交于
      The 'disable_cb' callback is designed as an optimization to tell the host
      we don't need callbacks now.  As it is not reliable, the debug check is
      overzealous: it can happen on two CPUs at the same time.  Document this.
      
      Even if it were reliable, the virtio_net driver doesn't disable
      callbacks on transmit so the START_USE/END_USE debugging reentrance
      protection can be easily tripped even on UP.
      
      Thanks to Balaji Rao for the bug report and testing.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      CC: Balaji Rao <balajirrao@gmail.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      2557a933
  4. 31 3月, 2008 1 次提交
  5. 28 3月, 2008 1 次提交
  6. 17 3月, 2008 3 次提交
    • C
      virtio: fix race in enable_cb · 4265f161
      Christian Borntraeger 提交于
      There is a race in virtio_net, dealing with disabling/enabling the callback.
      I saw the following oops:
      
      kernel BUG at /space/kvm/drivers/virtio/virtio_ring.c:218!
      illegal operation: 0001 [#1] SMP
      Modules linked in: sunrpc dm_mod
      CPU: 2 Not tainted 2.6.25-rc1zlive-host-10623-gd358142-dirty #99
      Process swapper (pid: 0, task: 000000000f85a610, ksp: 000000000f873c60)
      Krnl PSW : 0404300180000000 00000000002b81a6 (vring_disable_cb+0x16/0x20)
                 R:0 T:1 IO:0 EX:0 Key:0 M:1 W:0 P:0 AS:0 CC:3 PM:0 EA:3
      Krnl GPRS: 0000000000000001 0000000000000001 0000000010005800 0000000000000001
                 000000000f3a0900 000000000f85a610 0000000000000000 0000000000000000
                 0000000000000000 000000000f870000 0000000000000000 0000000000001237
                 000000000f3a0920 000000000010ff74 00000000002846f6 000000000fa0bcd8
      Krnl Code: 00000000002b819a: a7110001           tmll    %r1,1
                 00000000002b819e: a7840004           brc     8,2b81a6
                 00000000002b81a2: a7f40001           brc     15,2b81a4
                >00000000002b81a6: a51b0001           oill    %r1,1
                 00000000002b81aa: 40102000           sth     %r1,0(%r2)
                 00000000002b81ae: 07fe               bcr     15,%r14
                 00000000002b81b0: eb7ff0380024       stmg    %r7,%r15,56(%r15)
                 00000000002b81b6: a7f13e00           tmll    %r15,15872
      Call Trace:
      ([<000000000fa0bcd0>] 0xfa0bcd0)
       [<00000000002b8350>] vring_interrupt+0x5c/0x6c
       [<000000000010ab08>] do_extint+0xb8/0xf0
       [<0000000000110716>] ext_no_vtime+0x16/0x1a
       [<0000000000107e72>] cpu_idle+0x1c2/0x1e0
      
      The problem can be triggered with a high amount of host->guest traffic.
      I think its the following race:
      
      poll says netif_rx_complete
      poll calls enable_cb
      enable_cb opens the interrupt mask
      a new packet comes, an interrupt is triggered----\
      enable_cb sees that there is more work           |
      enable_cb disables the interrupt                 |
             .                                         V
             .                            interrupt is delivered
             .                            skb_recv_done does atomic napi test, ok
       some waiting                       disable_cb is called->check fails->bang!
             .
      poll would do napi check
      poll would do disable_cb
      
      The fix is to let enable_cb not disable the interrupt again, but expect the
      caller to do the cleanup if it returns false. In that case, the interrupt is
      only disabled, if the napi test_set_bit was successful.
      Signed-off-by: NChristian Borntraeger <borntraeger@de.ibm.com>
      Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (cleaned up doco)
      4265f161
    • R
      virtio: handle > 2 billion page balloon targets · bdc1681c
      Rusty Russell 提交于
      If the host asks for a huge target towards_target() can overflow, and
      we up oops as we try to release more pages than we have.  The simple
      fix is to use a 64-bit value.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      bdc1681c
    • A
      virtio: Use spin_lock_irqsave/restore for virtio-pci · 27ebe308
      Anthony Liguori 提交于
      virtio-pci acquires its spin lock in an interrupt context so it's necessary
      to use spin_lock_irqsave/restore variants.  This patch fixes guest SMP when
      using virtio devices in KVM.
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      27ebe308
  7. 07 2月, 2008 2 次提交
  8. 04 2月, 2008 10 次提交
    • R
      virtio: balloon driver · 6b35e407
      Rusty Russell 提交于
      After discussions with Anthony Liguori, it seems that the virtio
      balloon can be made even simpler.  Here's my attempt.
      
      The device configuration tells the driver how much memory it should
      take from the guest (ie. balloon size).  The guest feeds the page
      numbers it has taken via one virtqueue.
      
      A second virtqueue feeds the page numbers the driver wants back: if
      the device has the VIRTIO_BALLOON_F_MUST_TELL_HOST bit, then this
      queue is compulsory, otherwise it's advisory (and the guest can simply
      fault the pages back in).
      
      This driver can be enhanced later to deflate the balloon via a
      shrinker, oom callback or we could even go for a complete set of
      in-guest regulators.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      6b35e407
    • A
      virtio: Use PCI revision field to indicate virtio PCI ABI version · 55a7c066
      Anthony Liguori 提交于
      As Avi pointed out, as we continue to massage the virtio PCI ABI, we can make
      things a little more friendly to users by utilizing the PCI revision field to
      indicate which version of the ABI we're using.  This is a hard ABI version
      and incrementing it will cause the guest driver to break.
      
      This is the necessary changes to virtio_pci to support this.
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      55a7c066
    • A
      virtio: PCI device · 3343660d
      Anthony Liguori 提交于
      This is a PCI device that implements a transport for virtio.  It allows virtio
      devices to be used by QEMU based VMMs like KVM or Xen.
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      3343660d
    • R
      virtio: Allow virtio to be modular and used by modules · c6fd4701
      Rusty Russell 提交于
      This is needed for the virtio PCI device to be compiled as a module.
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      c6fd4701
    • R
      virtio: Use the sg_phys convenience function. · 15f9c890
      Rusty Russell 提交于
      Simple cleanup.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      15f9c890
    • R
      virtio: handle interrupts after callbacks turned off · 81a8deab
      Rusty Russell 提交于
      Anthony Liguori found double interrupt suppression in the virtio_net
      driver, triggered by two skb_recv_done's in a row.  This is because
      virtio_ring's interrupt suppression is a best-effort optimization: it
      contains no synchronization so the host can miss it and still send
      interrupts.
      
      But it's certainly nicer for virtio users if calling disable_cb
      actually disables callbacks, so we check for the race in the interrupt
      routine.
      
      Note: SMP guests might require syncronization here, but since
      disable_cb is actually called from interrupt context, there has to be
      some form of synchronization before the next same interrupt handler is
      called (Linux guarantees that the same device's irq handler will never
      run simultanously on multiple CPUs).
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      81a8deab
    • R
      virtio: reset function · 6e5aa7ef
      Rusty Russell 提交于
      A reset function solves three problems:
      
      1) It allows us to renegotiate features, eg. if we want to upgrade a
         guest driver without rebooting the guest.
      
      2) It gives us a clean way of shutting down virtqueues: after a reset,
         we know that the buffers won't be used by the host, and
      
      3) It helps the guest recover from messed-up drivers.
      
      So we remove the ->shutdown hook, and the only way we now remove
      feature bits is via reset.
      
      We leave it to the driver to do the reset before it deletes queues:
      the balloon driver, for example, needs to chat to the host in its
      remove function.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      6e5aa7ef
    • R
      virtio: clarify NO_NOTIFY flag usage · 426e3e0a
      Rusty Russell 提交于
      The other side (host) can set the NO_NOTIFY flag as an optimization,
      to say "no need to kick me when you add things".  Make it clear that
      this is advisory only; especially that we should always notify when
      the ring is full.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      426e3e0a
    • R
      virtio: explicit enable_cb/disable_cb rather than callback return. · 18445c4d
      Rusty Russell 提交于
      It seems that virtio_net wants to disable callbacks (interrupts) before
      calling netif_rx_schedule(), so we can't use the return value to do so.
      
      Rename "restart" to "cb_enable" and introduce "cb_disable" hook: callback
      now returns void, rather than a boolean.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      18445c4d
    • R
      virtio: simplify config mechanism. · a586d4f6
      Rusty Russell 提交于
      Previously we used a type/len pair within the config space, but this
      seems overkill.  We now simply define a structure which represents the
      layout in the config space: the config space can now only be extended
      at the end.
      
      The main driver-visible changes:
      1) We indicate what fields are present with an explicit feature bit.
      2) Virtqueues are explicitly numbered, and not in the config space.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      a586d4f6
  9. 19 11月, 2007 1 次提交
  10. 12 11月, 2007 2 次提交
    • R
      virtio: Force use of power-of-two for descriptor ring sizes · 42b36cc0
      Rusty Russell 提交于
      The virtio descriptor rings of size N-1 were nicely set up to be
      aligned to an N-byte boundary.  But as Anthony Liguori points out, the
      free-running indices used by virtio require that the sizes be a power
      of 2, otherwise we get problems on wrap (demonstrated with lguest).
      
      So we replace the clever "2^n-1" scheme with a simple "align to page
      boundary" scheme: this means that all virtio rings take at least two
      pages, but it's safer than guessing cache alignment.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      42b36cc0
    • A
      virtio: Fix used_idx wrap-around · 1bc4953e
      Anthony Liguori 提交于
      The more_used() function compares the vq->vring.used->idx with last_used_idx.
      Since vq->vring.used->idx is a 16-bit integer, and last_used_idx is an
      unsigned int, this results in unpredictable behavior when vq->vring.used->idx
      wraps around.
      
      This patch corrects this by changing last_used_idx to the correct type.
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      1bc4953e
  11. 23 10月, 2007 3 次提交
    • R
      Virtio helper routines for a descriptor ringbuffer implementation · 0a8a69dd
      Rusty Russell 提交于
      These helper routines supply most of the virtqueue_ops for hypervisors
      which want to use a ring for virtio.  Unlike the previous lguest
      implementation:
      
      1) The rings are variable sized (2^n-1 elements).
      2) They have an unfortunate limit of 65535 bytes per sg element.
      3) The page numbers are always 64 bit (PAE anyone?)
      4) They no longer place used[] on a separate page, just a separate
         cacheline.
      5) We do a modulo on a variable.  We could be tricky if we cared.
      6) Interrupts and notifies are suppressed using flags within the rings.
      
      Users need only get the ring pages and provide a notify hook (KVM
      wants the guest to allocate the rings, lguest does it sanely).
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      Cc: Dor Laor <dor.laor@qumranet.com>
      0a8a69dd
    • R
      Module autoprobing support for virtio drivers. · b01d9f28
      Rusty Russell 提交于
      This adds the logic to convert the virtio ids into module aliases, and
      includes a modalias entry in sysfs and the env var to make probing work.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      b01d9f28
    • R
      Virtio interface · ec3d41c4
      Rusty Russell 提交于
      This attempts to implement a "virtual I/O" layer which should allow
      common drivers to be efficiently used across most virtual I/O
      mechanisms.  It will no-doubt need further enhancement.
      
      The virtio drivers add buffers to virtio queues; as the buffers are consumed
      the driver "interrupt" callbacks are invoked.
      
      There is also a generic implementation of config space which drivers can query
      to get setup information from the host.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      Cc: Dor Laor <dor.laor@qumranet.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      ec3d41c4