[PATCH] ACRN:DM: Fix the vhost register kick fd issue.


Long Liu
 

Add the new parameter for register ioevent function, let the vhost
vq and viothread vq can share the register ioevent common API.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/virtio/vhost.c | 2 +-
devicemodel/hw/pci/virtio/virtio.c | 15 ++++-----------
devicemodel/include/virtio.h | 4 ++--
3 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/devicemodel/hw/pci/virtio/vhost.c b/devicemodel/hw/pci/virtio/vhost.c
index 6364170cc..154de4257 100644
--- a/devicemodel/hw/pci/virtio/vhost.c
+++ b/devicemodel/hw/pci/virtio/vhost.c
@@ -196,7 +196,7 @@ vhost_vq_register_eventfd(struct vhost_dev *vdev,
irqfd.flags = ACRN_IRQFD_FLAG_DEASSIGN;
}

- virtio_register_ioeventfd(base, idx, is_register);
+ virtio_register_ioeventfd(base, idx, is_register, vq->kick_fd);
/* register irqfd for notify */
mte = &vdev->base->dev->msix.table[vqi->msix_idx];
msi.msi_addr = mte->addr;
diff --git a/devicemodel/hw/pci/virtio/virtio.c b/devicemodel/hw/pci/virtio/virtio.c
index 598bdbc5f..9b3797ea3 100644
--- a/devicemodel/hw/pci/virtio/virtio.c
+++ b/devicemodel/hw/pci/virtio/virtio.c
@@ -107,10 +107,10 @@ virtio_set_iothread(struct virtio_base *base,
vq->viothrd.iomvt.fd = vq->viothrd.kick_fd;

if (!iothread_add(vq->viothrd.kick_fd, &vq->viothrd.iomvt))
- if (!virtio_register_ioeventfd(base, idx, true))
+ if (!virtio_register_ioeventfd(base, idx, true, vq->viothrd.kick_fd))
vq->viothrd.ioevent_started = true;
} else {
- if (!virtio_register_ioeventfd(base, idx, false))
+ if (!virtio_register_ioeventfd(base, idx, false, vq->viothrd.kick_fd))
if (!iothread_del(vq->viothrd.kick_fd)) {
vq->viothrd.ioevent_started = false;
if (vq->viothrd.kick_fd) {
@@ -1991,20 +1991,14 @@ acrn_parse_virtio_poll_interval(const char *optarg)
return 0;
}

-int virtio_register_ioeventfd(struct virtio_base *base, int idx, bool is_register)
+int virtio_register_ioeventfd(struct virtio_base *base, int idx, bool is_register, int fd)
{
struct acrn_ioeventfd ioeventfd = {0};
- struct virtio_vq_info *vq;
struct pcibar *bar;
int rc = 0;

if (!is_register)
ioeventfd.flags = ACRN_IOEVENTFD_FLAG_DEASSIGN;
- else
- /* Enable ASYNCIO by default. If ASYNCIO is not supported by kernel
- * or hyperviosr, this flag will be ignored.
- */
- ioeventfd.flags = ACRN_IOEVENTFD_FLAG_ASYNCIO;
/* register ioeventfd for kick */
if (base->device_caps & (1UL << VIRTIO_F_VERSION_1)) {
/*
@@ -2040,8 +2034,7 @@ int virtio_register_ioeventfd(struct virtio_base *base, int idx, bool is_registe
ACRN_IOEVENTFD_FLAG_PIO);
}

- vq = &base->queues[idx];
- ioeventfd.fd = vq->viothrd.kick_fd;
+ ioeventfd.fd = fd;
if (is_register)
pr_info("[ioeventfd: %d][0x%lx@%d][flags: 0x%x][data: 0x%lx]\r\n",
ioeventfd.fd, ioeventfd.addr, ioeventfd.len,
diff --git a/devicemodel/include/virtio.h b/devicemodel/include/virtio.h
index 370248bd5..2bceba25c 100644
--- a/devicemodel/include/virtio.h
+++ b/devicemodel/include/virtio.h
@@ -425,7 +425,7 @@ struct virtio_ops {
struct virtio_iothread {
struct virtio_base *base;
int idx;
- int kick_fd;
+ int kick_fd; /**< fd of kick eventfd */
bool ioevent_started;
struct iothread_mevent iomvt;
void (*iothread_run)(void *, struct virtio_vq_info *);
@@ -776,5 +776,5 @@ uint32_t virtio_device_cfg_read(
int virtio_set_modern_pio_bar(
struct virtio_base *base, int barnum);

-int virtio_register_ioeventfd(struct virtio_base *base, int idx, bool is_register);
+int virtio_register_ioeventfd(struct virtio_base *base, int idx, bool is_register, int fd);
#endif /* _VIRTIO_H_ */
--
2.25.1


Conghui Chen
 

Hi Long,

Thanks for your patch, please check my comments.

-----Original Message-----
From: Liu Long <long.liu@...>
Sent: Wednesday, November 16, 2022 5:25 PM
To: Wang, Yu1 <yu1.wang@...>; Chen, Conghui
<conghui.chen@...>; acrn-dev@...
Subject: [PATCH] ACRN:DM: Fix the vhost register kick fd issue.

Add the new parameter for register ioevent function, let the vhost
vq and viothread vq can share the register ioevent common API.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/virtio/vhost.c | 2 +-
devicemodel/hw/pci/virtio/virtio.c | 15 ++++-----------
devicemodel/include/virtio.h | 4 ++--
3 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/devicemodel/hw/pci/virtio/vhost.c
b/devicemodel/hw/pci/virtio/vhost.c
index 6364170cc..154de4257 100644
--- a/devicemodel/hw/pci/virtio/vhost.c
+++ b/devicemodel/hw/pci/virtio/vhost.c
@@ -196,7 +196,7 @@ vhost_vq_register_eventfd(struct vhost_dev *vdev,
irqfd.flags = ACRN_IRQFD_FLAG_DEASSIGN;
}

- virtio_register_ioeventfd(base, idx, is_register);
+ virtio_register_ioeventfd(base, idx, is_register, vq->kick_fd);
/* register irqfd for notify */
mte = &vdev->base->dev->msix.table[vqi->msix_idx];
msi.msi_addr = mte->addr;
diff --git a/devicemodel/hw/pci/virtio/virtio.c
b/devicemodel/hw/pci/virtio/virtio.c
index 598bdbc5f..9b3797ea3 100644
--- a/devicemodel/hw/pci/virtio/virtio.c
+++ b/devicemodel/hw/pci/virtio/virtio.c
@@ -107,10 +107,10 @@ virtio_set_iothread(struct virtio_base *base,
vq->viothrd.iomvt.fd = vq->viothrd.kick_fd;

if (!iothread_add(vq->viothrd.kick_fd, &vq-
viothrd.iomvt))
- if (!virtio_register_ioeventfd(base, idx, true))
+ if (!virtio_register_ioeventfd(base, idx, true,
vq->viothrd.kick_fd))
vq->viothrd.ioevent_started = true;
} else {
- if (!virtio_register_ioeventfd(base, idx, false))
+ if (!virtio_register_ioeventfd(base, idx, false, vq-
viothrd.kick_fd))
if (!iothread_del(vq->viothrd.kick_fd)) {
vq->viothrd.ioevent_started = false;
if (vq->viothrd.kick_fd) {
@@ -1991,20 +1991,14 @@ acrn_parse_virtio_poll_interval(const char
*optarg)
return 0;
}

-int virtio_register_ioeventfd(struct virtio_base *base, int idx, bool is_register)
+int virtio_register_ioeventfd(struct virtio_base *base, int idx, bool
is_register, int fd)
{
struct acrn_ioeventfd ioeventfd = {0};
- struct virtio_vq_info *vq;
struct pcibar *bar;
int rc = 0;

if (!is_register)
ioeventfd.flags = ACRN_IOEVENTFD_FLAG_DEASSIGN;
- else
- /* Enable ASYNCIO by default. If ASYNCIO is not supported
by kernel
- * or hyperviosr, this flag will be ignored.
- */
- ioeventfd.flags = ACRN_IOEVENTFD_FLAG_ASYNCIO;
We need to keep this flag, as it is for ASYNCIO.
But you can add an condition for it:
If (vq->iothread)
ioeventfd.flags = ACRN_IOEVENTFD_FLAG_ASYNCIO;


/* register ioeventfd for kick */
if (base->device_caps & (1UL << VIRTIO_F_VERSION_1)) {
/*
@@ -2040,8 +2034,7 @@ int virtio_register_ioeventfd(struct virtio_base
*base, int idx, bool is_registe
ACRN_IOEVENTFD_FLAG_PIO);
}

- vq = &base->queues[idx];
- ioeventfd.fd = vq->viothrd.kick_fd;
+ ioeventfd.fd = fd;
if (is_register)
pr_info("[ioeventfd: %d][0x%lx@%d][flags: 0x%x][data:
0x%lx]\r\n",
ioeventfd.fd, ioeventfd.addr, ioeventfd.len,
diff --git a/devicemodel/include/virtio.h b/devicemodel/include/virtio.h
index 370248bd5..2bceba25c 100644
--- a/devicemodel/include/virtio.h
+++ b/devicemodel/include/virtio.h
@@ -425,7 +425,7 @@ struct virtio_ops {
struct virtio_iothread {
struct virtio_base *base;
int idx;
- int kick_fd;
+ int kick_fd; /**< fd of kick eventfd */
Is there any typo in this change? /**< ?



bool ioevent_started;
struct iothread_mevent iomvt;
void (*iothread_run)(void *, struct virtio_vq_info *);
@@ -776,5 +776,5 @@ uint32_t virtio_device_cfg_read(
int virtio_set_modern_pio_bar(
struct virtio_base *base, int barnum);

-int virtio_register_ioeventfd(struct virtio_base *base, int idx, bool
is_register);
+int virtio_register_ioeventfd(struct virtio_base *base, int idx, bool
is_register, int fd);
#endif /* _VIRTIO_H_ */
--
2.25.1