On 12/18/24 20:10, Markus Lavin wrote:
Sorry but I don't quite follow. Which callbacks are we talking about?
Are you saying that it is fine to call pci_dma_read/pci_dma_write/
msix_notify from a thread without acquiring any particular lock in advance?
Depending on how exactly your code is being called, it may be that the
BQL is taken already. Even if not, DMA is fine without acquiring any
lock; MSIs are also DMA. The DMA operations will take the BQL for you
if needed.
However:
1) it may make sense for interrupts to go through an eventfd file
descriptor (see kvm_virtio_pci_vq_vector_use,
kvm_virtio_pci_vq_vector_release, kvm_virtio_pci_irqfd_use,
kvm_virtio_pci_irqfd_release) instead of using msix_notify. If you're
using KVM, the write to the file descriptor will go straight to the
kernel, bypassing the DMA emulation.
2) note that INTX, which is toggled by pci_set_irq(), needs the big QEMU
lock.
Paolo
Thanks,
Markus
------------------------------------------------------------------------
*From:* John Levon <[email protected]>
*Sent:* Wednesday, December 18, 2024 6:28 PM
*To:* Markus Lavin <[email protected]>
*Cc:* [email protected] <[email protected]>
*Subject:* Re: Use of BQL from thread in PCIe device
[You don't often get email from [email protected]. Learn why this
is important at https://aka.ms/LearnAboutSenderIdentification <https://
aka.ms/LearnAboutSenderIdentification> ]
On Wed, Dec 18, 2024 at 04:19:47PM +0000, Markus Lavin wrote:
> Hi,
>
> I think that I might have misunderstood something fundamental about
the BQL
> (or possibly Qemu in general).
>
> I have a custom PCIe device that connects to an outside simulation
environment
> using Unix domain sockets. To deal with bus-mastering from this outside
> environment I have a thread created with qemu_thread_create listening
to the
> socket.
>
> If I get a read/write/interrupt request over the socket then the
thread should
> perform a pci_dma_read/pci_dma_write/msix_notify. Since this is
called from
> the threads context I assumed I should first grab the BQL. Issuing a
bql_lock
> from the thread however hangs Qemu.
>
> Is my thinking flawed?
The BQL will be already taken for these callbacks higher up in the stack
I believe.
regards
john
if