virtio: introduce virtio_map
commit8059feee004111534c4c0652e2f0715e9b4e0754
authorMichael S. Tsirkin <mst@redhat.com>
Tue, 27 Oct 2015 08:01:44 +0000 (27 10:01 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 29 Oct 2015 09:05:24 +0000 (29 11:05 +0200)
tree2da88fa4471492aa2abdb8e83915c5a8cda29b1f
parent9d4ec9370a36f8a564e1ba05519328c0bd60da13
virtio: introduce virtio_map

virtio_map_sg currently fails if one of the entries it's mapping is
contigious in GPA but not HVA address space.  Introduce virtio_map which
handles this by splitting sg entries.

This new API generally turns out to be a good idea since it's harder to
misuse: at least in one case the existing one was used incorrectly.

This will still fail if there's no space left in the sg, but luckily max
queue size in use is currently 256, while max sg size is 1024, so we
should be OK even is all entries happen to cross a single DIMM boundary.

Won't work well with very small DIMM sizes, unfortunately:
e.g. this will fail with 4K DIMMs where a single
request might span a large number of DIMMs.

Let's hope these are uncommon - at least we are not breaking things.

Note: virtio-scsi calls virtio_map_sg on data loaded from network, and
validates input, asserting on failure.  Copy the validating code here -
it will be dropped from virtio-scsi in a follow-up patch.

Reported-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
hw/virtio/virtio.c
include/hw/virtio/virtio.h