mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 14:53:54 -06:00
softmmu: Support concurrent bounce buffers
When DMA memory can't be directly accessed, as is the case when running the device model in a separate process without shareable DMA file descriptors, bounce buffering is used. It is not uncommon for device models to request mapping of several DMA regions at the same time. Examples include: * net devices, e.g. when transmitting a packet that is split across several TX descriptors (observed with igb) * USB host controllers, when handling a packet with multiple data TRBs (observed with xhci) Previously, qemu only provided a single bounce buffer per AddressSpace and would fail DMA map requests while the buffer was already in use. In turn, this would cause DMA failures that ultimately manifest as hardware errors from the guest perspective. This change allocates DMA bounce buffers dynamically instead of supporting only a single buffer. Thus, multiple DMA mappings work correctly also when RAM can't be mmap()-ed. The total bounce buffer allocation size is limited individually for each AddressSpace. The default limit is 4096 bytes, matching the previous maximum buffer size. A new x-max-bounce-buffer-size parameter is provided to configure the limit for PCI devices. Signed-off-by: Mattias Nissler <mnissler@rivosinc.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Acked-by: Peter Xu <peterx@redhat.com> Link: https://lore.kernel.org/r/20240819135455.2957406-1-mnissler@rivosinc.com Signed-off-by: Peter Xu <peterx@redhat.com>
This commit is contained in:
parent
f2aee60305
commit
637b0aa139
5 changed files with 75 additions and 35 deletions
|
@ -1084,13 +1084,7 @@ typedef struct AddressSpaceMapClient {
|
|||
QLIST_ENTRY(AddressSpaceMapClient) link;
|
||||
} AddressSpaceMapClient;
|
||||
|
||||
typedef struct {
|
||||
MemoryRegion *mr;
|
||||
void *buffer;
|
||||
hwaddr addr;
|
||||
hwaddr len;
|
||||
bool in_use;
|
||||
} BounceBuffer;
|
||||
#define DEFAULT_MAX_BOUNCE_BUFFER_SIZE (4096)
|
||||
|
||||
/**
|
||||
* struct AddressSpace: describes a mapping of addresses to #MemoryRegion objects
|
||||
|
@ -1110,8 +1104,10 @@ struct AddressSpace {
|
|||
QTAILQ_HEAD(, MemoryListener) listeners;
|
||||
QTAILQ_ENTRY(AddressSpace) address_spaces_link;
|
||||
|
||||
/* Bounce buffer to use for this address space. */
|
||||
BounceBuffer bounce;
|
||||
/* Maximum DMA bounce buffer size used for indirect memory map requests */
|
||||
size_t max_bounce_buffer_size;
|
||||
/* Total size of bounce buffers currently allocated, atomically accessed */
|
||||
size_t bounce_buffer_size;
|
||||
/* List of callbacks to invoke when buffers free up */
|
||||
QemuMutex map_client_list_lock;
|
||||
QLIST_HEAD(, AddressSpaceMapClient) map_client_list;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue