hw/display/reims-graphics-pci: take a command buffer on its doorbell's vCPU

BAR 0's writes now go to rvg_graphics_device_mmio_write_taking. It writes
every register as rvg_graphics_device_mmio_write does. For a DOORBELL write
of a command queue's ring, the library may take the queue's next command
buffer on the writing vCPU, where nothing need be waited for. Its
CB_SUBMITTED is then posted and its interrupt raised there, before the
write returns, with no wait for the queue's thread to wake. That thread
still walks and commits the buffer. Where the take must wait for anything,
the write wakes the queue's thread as before.

The raise on the vCPU writes the vector's irqfd or schedules a BH. Neither
waits for a lock, and the BAR 0 region is lockless, so no BQL is held
across the call. The library raises after it writes the completion ring, on
the same thread, so the guest still takes the interrupt after it sees the
event.

This changes only which thread posts a buffer's CB_SUBMITTED and when, a
change the contract leaves free: the events of each queue keep its order.
This commit is contained in:
Anees Iqbal committed 2026-11-02 05:25:03 -08:00
1 parent 36deb2810d
commit f2c7e2a558
1 file changed
+19 -12
+19 -12
View File
@@ -11,8 +11,11 @@
* - BAR 0: the library's 4 KiB of 32-bit registers, with the MSI-X table
* and PBA from RVG_GRAPHICS_MSIX_OFFSET, and one vector. A guest write of
* RVG_GRAPHICS_DOORBELL_CONTROL to the DOORBELL register is taken by an
* ioeventfd, which the library's control thread polls, so ringing never
* runs the library on the vCPU.
* ioeventfd, which the library's control thread polls, so ringing the
* control ring never runs the library on the vCPU. A write of a command
* queue's ring goes to the library on the vCPU, which may take the queue's
* next command buffer there and post the event that says it is submitted
* (rvg_graphics_device_mmio_write_taking).
* - BAR 2: the library's region, 64-bit and prefetchable, private anonymous
* memory of QEMU's process that the guest maps write-back: the control
* rings below RVG_GRAPHICS_ALLOCATIONS_OFFSET, the guest's allocations
@@ -20,10 +23,11 @@
* logging covers only the allocations, where the guest's scanout lies,
* and the rings' constant writes are never logged.
* - The library's callbacks run on its own threads with none of its locks
* held: scanout_written takes the BQL to read and clear the allocations'
* dirty log. An interrupt is raised by a write of the vector's irqfd,
* where the accelerator injects MSI-X through one (KVM's in-kernel
* irqchip) and MSI-X is enabled, and by a BH otherwise.
* held, and raise_interrupt also on the vCPU, inside that write:
* scanout_written takes the BQL to read and clear the allocations' dirty
* log. An interrupt is raised by a write of the vector's irqfd, where the
* accelerator injects MSI-X through one (KVM's in-kernel irqchip) and
* MSI-X is enabled, and by a BH otherwise; neither waits for a lock.
*
* Under -display none the library opens a window for the display, unless
* REIMS_VGPU_WINDOW is "0", as apple-gfx does: the window keeps the size the
@@ -118,10 +122,11 @@ static void reims_graphics_pci_raise_interrupt(void *opaque)
}
/*
* On the library's threads, never inside a call of ours, after the library's
* write of what the interrupt reports: the irqfd's write follows it on the
* same thread, so the guest takes the interrupt after it sees the write, as
* it does through the BH.
* On the library's threads, or on the vCPU inside a register write
* (rvg_graphics_device_mmio_write_taking, which holds no lock of ours), after
* the library's write of what the interrupt reports: the irqfd's write
* follows it on the same thread, so the guest takes the interrupt after it
* sees the write, as it does through the BH. Neither waits for a lock.
*/
static void reims_graphics_pci_raise_interrupt_cb(void *ctx, uint32_t vector)
{
@@ -544,7 +549,9 @@ static bool reims_graphics_window_wanted(void)
/*
* The vCPU calls the library itself: an access waits at most for the command
* the control thread is taking, which waits for nothing of QEMU's, so it
* needs no BQL.
* needs no BQL. A DOORBELL write of a command queue's ring may take the
* queue's next command buffer on the vCPU and raise the interrupt there,
* waiting for nothing.
*/
static uint64_t reims_graphics_pci_read(void *opaque, hwaddr offset,
unsigned size)
@@ -559,7 +566,7 @@ static void reims_graphics_pci_write(void *opaque, hwaddr offset,
{
ReimsGraphicsPCIState *s = opaque;
rvg_graphics_device_mmio_write(s->device, offset, value);
rvg_graphics_device_mmio_write_taking(s->device, offset, value);
}
static const MemoryRegionOps reims_graphics_pci_ops = {