virtio/pci: Use the correct eventfd for vhost notification

Legacy virtio drivers write to the I/O port BAR, and the modern virtio
device uses the MMIO BAR. Since vhost can only listen on one ioeventfd,
select the one that the guest will use.

Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
Link: https://lore.kernel.org/r/20220701142434.75170-5-jean-philippe.brucker@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
diff --git a/virtio/pci.c b/virtio/pci.c
index c02534a..320865c 100644
--- a/virtio/pci.c
+++ b/virtio/pci.c
@@ -83,7 +83,7 @@
 	u16 port_addr = virtio_pci__port_addr(vpci);
 	off_t offset = vpci->doorbell_offset;
 	int r, flags = 0;
-	int fd;
+	int pio_fd, mmio_fd;
 
 	vpci->ioeventfds[vq] = (struct virtio_pci_ioevent_param) {
 		.vdev		= vdev,
@@ -107,7 +107,7 @@
 	/* ioport */
 	ioevent.io_addr	= port_addr + offset;
 	ioevent.io_len	= sizeof(u16);
-	ioevent.fd	= fd = eventfd(0, 0);
+	ioevent.fd	= pio_fd = eventfd(0, 0);
 	r = ioeventfd__add_event(&ioevent, flags | IOEVENTFD_FLAG_PIO);
 	if (r)
 		return r;
@@ -115,13 +115,14 @@
 	/* mmio */
 	ioevent.io_addr	= mmio_addr + offset;
 	ioevent.io_len	= sizeof(u16);
-	ioevent.fd	= eventfd(0, 0);
+	ioevent.fd	= mmio_fd = eventfd(0, 0);
 	r = ioeventfd__add_event(&ioevent, flags);
 	if (r)
 		goto free_ioport_evt;
 
 	if (vdev->ops->notify_vq_eventfd)
-		vdev->ops->notify_vq_eventfd(kvm, vpci->dev, vq, fd);
+		vdev->ops->notify_vq_eventfd(kvm, vpci->dev, vq,
+					     vdev->legacy ? pio_fd : mmio_fd);
 	return 0;
 
 free_ioport_evt: