Skip to content
  • Greg Kurz's avatar
    170a6794
    vhost: Don't special case vq->used_phys in vhost_get_log_size() · 170a6794
    Greg Kurz authored
    The first loop in vhost_get_log_size() computes the size of the dirty log
    bitmap so that it allows to track changes in the entire guest memory, in
    terms of GPA.
    
    When not using a vIOMMU, the address of the vring's used structure,
    vq->used_phys, is a GPA. It is thus already covered by the first loop.
    
    When using a vIOMMU, vq->used_phys is a GIOVA that will be translated
    to an HVA when the vhost backend needs to update the used structure. It
    will log the corresponding GPAs into the bitmap but it certainly won't
    log the GIOVA.
    
    So in any case, vq->used_phys shouldn't be explicitly used to size the
    bitmap. Drop the second loop.
    
    This fixes a crash of the source when migrating a guest using in-kernel
    vhost-net and iommu_platform=on on POWER, because DMA regions are put
    over 0x800000000000000ULL. The resulting insanely huge log size causes
    g_malloc0() to abort.
    
    BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1879349
    
    
    Signed-off-by: default avatarGreg Kurz <groug@kaod.org>
    Message-Id: <160208823418.29027.15172801181796272300.stgit@bahia.lan>
    Acked-by: default avatarJason Wang <jasowang@redhat.com>
    Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
    Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
    170a6794
    vhost: Don't special case vq->used_phys in vhost_get_log_size()
    Greg Kurz authored
    The first loop in vhost_get_log_size() computes the size of the dirty log
    bitmap so that it allows to track changes in the entire guest memory, in
    terms of GPA.
    
    When not using a vIOMMU, the address of the vring's used structure,
    vq->used_phys, is a GPA. It is thus already covered by the first loop.
    
    When using a vIOMMU, vq->used_phys is a GIOVA that will be translated
    to an HVA when the vhost backend needs to update the used structure. It
    will log the corresponding GPAs into the bitmap but it certainly won't
    log the GIOVA.
    
    So in any case, vq->used_phys shouldn't be explicitly used to size the
    bitmap. Drop the second loop.
    
    This fixes a crash of the source when migrating a guest using in-kernel
    vhost-net and iommu_platform=on on POWER, because DMA regions are put
    over 0x800000000000000ULL. The resulting insanely huge log size causes
    g_malloc0() to abort.
    
    BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1879349
    
    
    Signed-off-by: default avatarGreg Kurz <groug@kaod.org>
    Message-Id: <160208823418.29027.15172801181796272300.stgit@bahia.lan>
    Acked-by: default avatarJason Wang <jasowang@redhat.com>
    Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
    Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Loading