Skip to content
  • Pavel Dovgaluk's avatar
    5fb0a6b5
    icount: make dma reads deterministic · 5fb0a6b5
    Pavel Dovgaluk authored
    Windows guest sometimes makes DMA requests with overlapping
    target addresses. This leads to the following structure of iov for
    the block driver:
    
    addr size1
    addr size2
    addr size3
    
    It means that three adjacent disk blocks should be read into the same
    memory buffer. Windows does not expects anything from these bytes
    (should it be data from the first block, or the last one, or some mix),
    but uses them somehow. It leads to non-determinism of the guest execution,
    because block driver does not preserve any order of reading.
    
    This situation was discusses in the mailing list at least twice:
    https://lists.gnu.org/archive/html/qemu-devel/2010-09/msg01996.html
    https://lists.gnu.org/archive/html/qemu-devel/2020-02/msg05185.html
    
    
    
    This patch makes such disk reads deterministic in icount mode.
    It splits the whole request into several parts. Parts may overlap,
    but SGs inside one part do not overlap.
    Parts that are processed later overwrite the prior ones in case
    of overlapping.
    
    Examples for different SG part sequences:
    
    1)
    A1 1000
    A2 1000
    A1 1000
    A3 1000
    ->
    One request is split into two.
    A1 1000
    A2 1000
    --
    A1 1000
    A3 1000
    
    2)
    A1 800
    A2 1000
    A1 1000
    ->
    A1 800
    A2 1000
    --
    A1 1000
    
    Signed-off-by: default avatarPavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
    Message-Id: <159117972206.12193.12939621311413561779.stgit@pasha-ThinkPad-X280>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    5fb0a6b5
    icount: make dma reads deterministic
    Pavel Dovgaluk authored
    Windows guest sometimes makes DMA requests with overlapping
    target addresses. This leads to the following structure of iov for
    the block driver:
    
    addr size1
    addr size2
    addr size3
    
    It means that three adjacent disk blocks should be read into the same
    memory buffer. Windows does not expects anything from these bytes
    (should it be data from the first block, or the last one, or some mix),
    but uses them somehow. It leads to non-determinism of the guest execution,
    because block driver does not preserve any order of reading.
    
    This situation was discusses in the mailing list at least twice:
    https://lists.gnu.org/archive/html/qemu-devel/2010-09/msg01996.html
    https://lists.gnu.org/archive/html/qemu-devel/2020-02/msg05185.html
    
    
    
    This patch makes such disk reads deterministic in icount mode.
    It splits the whole request into several parts. Parts may overlap,
    but SGs inside one part do not overlap.
    Parts that are processed later overwrite the prior ones in case
    of overlapping.
    
    Examples for different SG part sequences:
    
    1)
    A1 1000
    A2 1000
    A1 1000
    A3 1000
    ->
    One request is split into two.
    A1 1000
    A2 1000
    --
    A1 1000
    A3 1000
    
    2)
    A1 800
    A2 1000
    A1 1000
    ->
    A1 800
    A2 1000
    --
    A1 1000
    
    Signed-off-by: default avatarPavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
    Message-Id: <159117972206.12193.12939621311413561779.stgit@pasha-ThinkPad-X280>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Loading