1. 28 6月, 2012 6 次提交
    • D
      iommu: Make sglists and dma_bdrv helpers use new universal DMA helpers · c65bcef3
      David Gibson 提交于
      dma-helpers.c contains a number of helper functions for doing
      scatter/gather DMA, and various block device related DMA.  Currently,
      these directly access guest memory using cpu_physical_memory_*(),
      assuming no IOMMU translation.
      
      This patch updates this code to use the new universal DMA helper
      functions.  qemu_sglist_init() now takes a DMAContext * to describe
      the DMA address space in which the scatter/gather will take place.
      
      We minimally update the callers qemu_sglist_init() to pass NULL
      (i.e. no translation, same as current behaviour).  Some of those
      callers should pass something else in some cases to allow proper IOMMU
      translation in future, but that will be fixed in later patches.
      
      Cc: Kevin Wolf <kwolf@redhat.com>
      Cc: Michael S. Tsirkin <mst@redhat.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Signed-off-by: NBenjamin Herrenschmidt <benh@kernel.crashing.org>
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      c65bcef3
    • D
      usb-ohci: Use universal DMA helper functions · 9ac6a217
      David Gibson 提交于
      The OHCI device emulation can provide both PCI and SysBus OHCI
      implementations.  Because of this, it was not previously converted to
      use the PCI DMA helper functions.
      
      This patch converts it to use the new universal DMA helper functions.
      In the PCI case, it obtains its DMAContext from pci_dma_context(), in
      the SysBus case, it uses NULL - i.e. assumes for now that there will
      be no IOMMU translation for a SysBus OHCI.
      
      Cc: Gerd Hoffmann <kraxel@redhat.com>
      Cc: Michael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Signed-off-by: NBenjamin Herrenschmidt <benh@kernel.crashing.org>
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      9ac6a217
    • D
      iommu: Add universal DMA helper functions · d86a77f8
      David Gibson 提交于
      Not that long ago, every device implementation using DMA directly
      accessed guest memory using cpu_physical_memory_*().  This meant that
      adding support for a guest visible IOMMU would require changing every
      one of these devices to go through IOMMU translation.
      
      Shortly before qemu 1.0, I made a start on fixing this by providing
      helper functions for PCI DMA.  These are currently just stubs which
      call the direct access functions, but mean that an IOMMU can be
      implemented in one place, rather than for every PCI device.
      
      Clearly, this doesn't help for non PCI devices, which could also be
      IOMMU translated on some platforms.  It is also problematic for the
      devices which have both PCI and non-PCI version (e.g. OHCI, AHCI) - we
      cannot use the the pci_dma_*() functions, because they assume the
      presence of a PCIDevice, but we don't want to have to check between
      pci_dma_*() and cpu_physical_memory_*() every time we do a DMA in the
      device code.
      
      This patch makes the first step on addressing both these problems, by
      introducing new (stub) dma helper functions which can be used for any
      DMA capable device.
      
      These dma functions take a DMAContext *, a new (currently empty)
      variable describing the DMA address space in which the operation is to
      take place.  NULL indicates untranslated DMA directly into guest
      physical address space.  The intention is that in future non-NULL
      values will given information about any necessary IOMMU translation.
      
      DMA using devices must obtain a DMAContext (or, potentially, contexts)
      from their bus or platform.  For now this patch just converts the PCI
      wrappers to be implemented in terms of the universal wrappers,
      converting other drivers can take place over time.
      
      Cc: Michael S. Tsirkin <mst@redhat.com>
      Cc: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
      Cc: Richard Henderson <rth@twiddle.net>
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Signed-off-by: NBenjamin Herrenschmidt <benh@kernel.crashing.org>
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      d86a77f8
    • D
      Better support for dma_addr_t variables · 8292f75a
      David Gibson 提交于
      A while back, we introduced the dma_addr_t type, which is supposed to
      be used for bus visible memory addresses.  At present, this is an
      alias for target_phys_addr_t, but this will change when we eventually
      add support for guest visible IOMMUs.
      
      There are some instances of target_phys_addr_t in the code now which
      should really be dma_addr_t, but can't be trivially converted due to
      missing features which this patch corrects.
      
       * We add DMA_ADDR_BITS analagous to TARGET_PHYS_ADDR_BITS.  This is
         important where we need to make a compile-time (#if) based on the
         size of dma_addr_t.
      
       * We add a new helper macro to create device properties which take a
         dma_addr_t, currently an alias to DEFINE_PROP_TADDR().
      Signed-off-by: NDavid Gibson <david@gibson.dropbear.id.au>
      Signed-off-by: NBenjamin Herrenschmidt <benh@kernel.crashing.org>
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      8292f75a
    • J
      rtl8139: validate rx ring before receiving packets · fcce6fd2
      Jason Wang 提交于
      Commit ff71f2e8 prevent the possible
      crash during initialization of linux driver by checking the operating
      mode.This seems too strict as:
      
      - the real card could still work in mode other than normal
      - some buggy driver who does not set correct opmode after eeprom
       access
      
      So, considering rx ring address were reset to zero (which could be
      safely trated as an address not intened to DMA to), in order to
      both letting old guest work and preventing the unexpected DMA to
      guest, we can forbid packet receiving when rx ring address is zero.
      Tested-by: NAvi Kivity <avi@redhat.com>
      Signed-off-by: NJason Wang <jasowang@redhat.com>
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      fcce6fd2
    • A
      qdev: fix use-after-free in the error path of qdev_init_nofail · 7de3abe5
      Anthony Liguori 提交于
      From Markus:
      
      Before:
      
          $ qemu-system-x86_64 -display none -drive if=ide
          qemu-system-x86_64: Device needs media, but drive is empty
          qemu-system-x86_64: Initialization of device ide-hd failed
          [Exit 1 ]
      
      After:
      
          $ qemu-system-x86_64 -display none -drive if=ide
          qemu-system-x86_64: Device needs media, but drive is empty
          Segmentation fault (core dumped)
          [Exit 139 (SIGSEGV)]
      
      This error always existed as qdev_init() frees the object.  But QOM
      goes a bit further and purposefully sets the class pointer to NULL to
      help find use-after-free.  It worked :-)
      
      Cc: Andreas Faerber <afaerber@suse.de>
      Reported-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      7de3abe5
  2. 24 6月, 2012 28 次提交
  3. 22 6月, 2012 6 次提交