• S
    virtio: add missing region cache init in virtio_load() · 874adf45
    Stefan Hajnoczi 提交于
    Commit 97cd965c ("virtio: use
    VRingMemoryRegionCaches for avail and used rings") switched to a memory
    region cache to avoid repeated map/unmap operations.
    
    The virtio_load() process is a little tricky because vring addresses are
    serialized in two separate places.  VIRTIO 1.0 devices serialize desc
    and then a subsection with used and avail.  Legacy devices only
    serialize desc.
    
    Live migration of VIRTIO 1.0 devices fails on the destination host with:
    
      VQ 0 size 0x80 < last_avail_idx 0x12f8 - used_idx 0x0
      Failed to load virtio-blk:virtio
      error while loading state for instance 0x0 of device '0000:00:04.0/virtio-blk'
    
    This happens because the memory region cache is only initialized after
    desc is loaded and not after the used and avail subsection is loaded.
    If the guest chose memory addresses that don't match the legacy ring
    layout then the wrong guest memory location is accessed.
    
    Wait until all ring addresses are known before trying to initialize the
    region cache.  Also clarify the incomplete comment about VIRTIO-1 ring
    address subsection.
    
    Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
    Cc: Paolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
    Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
    Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
    Reviewed-by: NCornelia Huck <cornelia.huck@de.ibm.com>
    Tested-by: NEric Auger <eric.auger@redhat.com>
    874adf45
virtio.c 71.9 KB