qemu-usb: use bounce buffer to access DMA memory

The former implemention assumed that the guest physical memory is
mapped continously. This, however, is not true. Writing larger
files to an USB stick with a Windows 10 guest would therefore lead
to data corruption.

The current implementation uses a bounce buffer to copy the data
to and from the guest physical memory and leaves dealing with the
memory mappings entirely up to the VMM.

Fixes #4017.
This commit is contained in:
Josef Söntgen
2021-02-12 12:55:44 +01:00
committed by Norman Feske
parent 23620942bf
commit b51ae104c2
3 changed files with 74 additions and 13 deletions

View File

@ -57,6 +57,8 @@ namespace Qemu {
*/
struct Pci_device
{
enum class Dma_direction { IN = 0, OUT = 1, };
/**
* Raise interrupt
*
@ -65,8 +67,8 @@ namespace Qemu {
virtual void raise_interrupt(int assert) = 0;
virtual int read_dma(addr_t addr, void *buf, size_t size) = 0;
virtual int write_dma(addr_t addr, void const *buf, size_t size) = 0;
virtual void *map_dma(addr_t base, size_t size) = 0;
virtual void unmap_dma(void *addr, size_t size) = 0;
virtual void *map_dma(addr_t base, size_t size, Dma_direction dir) = 0;
virtual void unmap_dma(void *addr, size_t size, Dma_direction dir) = 0;
};