On Wed, Jul 09, 2025 at 07:47:39PM +0200, Eugenio Pérez wrote: > In case the kernel needs to signal an error. > > Signed-off-by: Eugenio Pérez Reviewed-by: David Gibson > --- > RFC v2: Add TODO (David) > > Signed-off-by: Eugenio Pérez > --- > epoll_type.h | 2 ++ > passt.c | 5 +++++ > passt.h | 1 + > tap.c | 16 ++++++++++++++++ > 4 files changed, 24 insertions(+) > > diff --git a/epoll_type.h b/epoll_type.h > index 0371c14..93c4701 100644 > --- a/epoll_type.h > +++ b/epoll_type.h > @@ -46,6 +46,8 @@ enum epoll_type { > EPOLL_TYPE_REPAIR, > /* vhost-kernel call socket */ > EPOLL_TYPE_VHOST_CALL, > + /* vhost-kernel error socket */ > + EPOLL_TYPE_VHOST_ERROR, > > EPOLL_NUM_TYPES, > }; > diff --git a/passt.c b/passt.c > index 0f2659c..d839f5a 100644 > --- a/passt.c > +++ b/passt.c > @@ -80,6 +80,7 @@ char *epoll_type_str[] = { > [EPOLL_TYPE_REPAIR_LISTEN] = "TCP_REPAIR helper listening socket", > [EPOLL_TYPE_REPAIR] = "TCP_REPAIR helper socket", > [EPOLL_TYPE_VHOST_CALL] = "vhost-kernel call socket", > + [EPOLL_TYPE_VHOST_ERROR] = "vhost-kernel error socket", > }; > static_assert(ARRAY_SIZE(epoll_type_str) == EPOLL_NUM_TYPES, > "epoll_type_str[] doesn't match enum epoll_type"); > @@ -362,6 +363,10 @@ loop: > case EPOLL_TYPE_VHOST_CALL: > tap_vhost_input(&c, ref, &now); > break; > + case EPOLL_TYPE_VHOST_ERROR: > + /* TODO re-initialize vhost */ > + die("Error on vhost-kernel socket"); > + break; > default: > /* Can't happen */ > ASSERT(0); > diff --git a/passt.h b/passt.h > index 7bb86c4..0066145 100644 > --- a/passt.h > +++ b/passt.h > @@ -303,6 +303,7 @@ struct ctx { > struct { > int kick_fd; > int call_fd; > + int err_fd; > } vq[2]; > > int no_dns; > diff --git a/tap.c b/tap.c > index e4a3822..0c49e6d 100644 > --- a/tap.c > +++ b/tap.c > @@ -1598,6 +1598,22 @@ static int tap_ns_tun(void *arg) > die_perror("Failed to add call eventfd to epoll"); > } > c->vq[i].call_fd = file.fd; > + > + file.fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); > + if (file.fd < 0) > + die_perror("Failed to create error eventfd"); > + > + rc = ioctl(vhost_fd, VHOST_SET_VRING_ERR, &file); > + if (rc < 0) > + die_perror( > + "VHOST_SET_VRING_ERR ioctl on /dev/vhost-net failed"); > + > + ref.type = EPOLL_TYPE_VHOST_ERROR, ref.fd = file.fd; > + ev.data.u64 = ref.u64; > + rc = epoll_ctl(c->epollfd, EPOLL_CTL_ADD, ref.fd, &ev); > + if (rc < 0) > + die_perror("Failed to add error eventfd to epoll"); > + c->vq[i].err_fd = file.fd; > } > > /* -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson