public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Ammar Yasser <aerosound161@gmail.com>
To: passt-dev@passt.top
Cc: eperezma@redhat.com, Ammar Yasser <aerosound161@gmail.com>
Subject: [RFC v3 3/8] conf: Add context fields, epoll types and the --vhost flag to pasta
Date: Sun,  2 Aug 2026 13:21:50 +0000	[thread overview]
Message-ID: <20260802132155.870796-4-aerosound161@gmail.com> (raw)
In-Reply-To: <20260802132155.870796-1-aerosound161@gmail.com>

The --vhost controls whether or no to use vhost acceleration for pasta.
The EPOLL_TYPE_VHOST_CALL means that kernel wants to notify us about
data it has written. EPOLL_TYPE_VHOST_ERROR means the kernel encountered
an internal error on vhost and wants to notify us that something went
wrong.

Add the fd_vhost field on the context which will carry the file
descriptor of the device and will indicate that the setup was
successful. The vq field contains the kick, call and err file
descriptors for both queues.

Also add vhost (mark if vhost acceleration was requested) and
virtio_features field.

Signed-off-by: Ammar Yasser <aerosound161@gmail.com>
---
 conf.c       |  6 ++++++
 epoll_type.h |  4 ++++
 passt.c      |  3 +++
 passt.h      | 15 +++++++++++++++
 4 files changed, 28 insertions(+)

diff --git a/conf.c b/conf.c
index faf2681..c31546e 100644
--- a/conf.c
+++ b/conf.c
@@ -736,6 +736,7 @@ pasta_opts:
 		"    default: auto\n"
 		"  --host-lo-to-ns-lo	Translate host-loopback forwards to\n"
 		"			namespace loopback\n"
+		"  --vhost\t\tUse vhost-kernel acceleration\n"
 		"  --userns NSPATH 	Target user namespace to join\n"
 		"  --netns PATH|NAME	Target network namespace to join\n"
 		"  --netns-only		Don't join existing user namespace\n"
@@ -766,6 +767,7 @@ enum passt_modes conf_mode(int argc, char *argv[])
 	int vhost_user = 0;
 	const struct option optvu[] = {
 		{"vhost-user",	no_argument,		&vhost_user,	1 },
+		{"vhost",	no_argument,		NULL,		0 },
 		{ 0 },
 	};
 	char argv0[PATH_MAX], *basearg0;
@@ -1309,6 +1311,7 @@ void conf(struct ctx *c, int argc, char **argv)
 		{"ipv4-only",	no_argument,		NULL,		'4' },
 		{"ipv6-only",	no_argument,		NULL,		'6' },
 		{"one-off",	no_argument,		NULL,		'1' },
+		{"vhost",	no_argument,		&c->vhost,	1 },
 		{"tcp-ports",	required_argument,	NULL,		't' },
 		{"udp-ports",	required_argument,	NULL,		'u' },
 		{"tcp-ns",	required_argument,	NULL,		'T' },
@@ -1838,6 +1841,9 @@ void conf(struct ctx *c, int argc, char **argv)
 			die("--no-copy-addrs needs --config-net");
 	}
 
+	if (c->vhost && c->mode != MODE_PASTA)
+		die("--vhost is only available in pasta mode");
+
 	if (c->mode == MODE_PASTA && c->splice_only) {
 		if (c->no_splice)
 			die("--splice-only is incompatible with --no-splice");
diff --git a/epoll_type.h b/epoll_type.h
index 061325a..e3206d1 100644
--- a/epoll_type.h
+++ b/epoll_type.h
@@ -50,6 +50,10 @@ enum epoll_type {
 	EPOLL_TYPE_CONF_LISTEN,
 	/* Configuration socket */
 	EPOLL_TYPE_CONF,
+	/* 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 5054551..865b331 100644
--- a/passt.c
+++ b/passt.c
@@ -65,6 +65,7 @@ char pkt_buf[PKT_BUF_BYTES]	__attribute__ ((aligned(PAGE_SIZE)));
 struct ctx passt_ctx = {
 	.pidfile_fd		= -1,
 	.fd_tap			= -1,
+	.fd_vhost 		= -1,
 	.fd_tap_listen		= -1,
 	.fd_control_listen	= -1,
 	.fd_repair_listen	= -1,
@@ -92,6 +93,8 @@ char *epoll_type_str[] = {
 	[EPOLL_TYPE_NL_NEIGH]		= "netlink neighbour notifier socket",
 	[EPOLL_TYPE_CONF_LISTEN]	= "configuration listening socket",
 	[EPOLL_TYPE_CONF]		= "configuration 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");
diff --git a/passt.h b/passt.h
index 51ccd4f..c729316 100644
--- a/passt.h
+++ b/passt.h
@@ -183,8 +183,11 @@ struct ip6_ctx {
  * @fd_repair_listen:	File descriptor for listening TCP_REPAIR socket, if any
  * @fd_repair:		Connected AF_UNIX socket for TCP_REPAIR helper
  * @our_tap_mac:	Pasta/passt's MAC on the tap link
+ * @fd_vhost:		File descriptor for /dev/vhost-net, set on vhost setup
  * @guest_mac:		MAC address of guest or namespace, seen or configured
  * @hash_secret:	128-bit secret for siphash functions
+ * @virtio_features:	Negotiated virtio feature bits
+ * @vhost:		Enable vhost-kernel acceleration for pasta
  * @ifi4:		Template interface for IPv4, -1: none, 0: IPv4 disabled
  * @ip4:		IPv4 configuration
  * @dns_search:		DNS search list
@@ -202,6 +205,8 @@ struct ip6_ctx {
  * @no_udp:		Disable UDP operation
  * @udp:		Context for UDP protocol handler
  * @no_icmp:		Disable ICMP operation
+ * @vq:		Per-virtqueue eventfd descriptors for vhost-kernel
+ *		([0] is RX, [1] is TX; each holds kick_fd, call_fd, err_fd)
  * @mtu:		MTU passed via DHCP/NDP
  * @no_dns:		Do not source/use DNS servers for any purpose
  * @no_dns_search:	Do not source/use domain search lists for any purpose
@@ -258,11 +263,14 @@ struct ctx {
 	int fd_control;
 	int fd_repair_listen;
 	int fd_repair;
+
+	int fd_vhost;
 	unsigned char our_tap_mac[ETH_ALEN];
 	unsigned char guest_mac[ETH_ALEN];
 	uint16_t mtu;
 
 	uint64_t hash_secret[2];
+	uint64_t virtio_features;
 
 	int ifi4;
 	struct ip4_ctx ip4;
@@ -288,6 +296,12 @@ struct ctx {
 	struct udp_ctx udp;
 	int no_icmp;
 
+	struct {
+		int kick_fd;
+		int call_fd;
+		int err_fd;
+	} vq[2];
+
 	int no_dns;
 	int no_dns_search;
 	int no_dhcp_dns;
@@ -300,6 +314,7 @@ struct ctx {
 	int splice_only;
 	int host_lo_to_ns_lo;
 	int freebind;
+	int vhost;
 	bool chroot_fallback;
 
 	int low_wmem;
-- 
2.34.1


  parent reply	other threads:[~2026-08-02 13:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02 13:21 [RFC v3 0/8] Add vhost-net kernel support " Ammar Yasser
2026-08-02 13:21 ` [RFC v3 1/8] tap: Move the tap_hdr file to a separate file Ammar Yasser
2026-08-02 13:21 ` [RFC v3 2/8] udp,tcp: Make protocol specific buffers public Ammar Yasser
2026-08-02 13:21 ` Ammar Yasser [this message]
2026-08-02 13:21 ` [RFC v3 4/8] virtio: Define the pasta vhost interface Ammar Yasser
2026-08-02 13:21 ` [RFC v3 5/8] virtio: Implement the pasta vhost functions Ammar Yasser
2026-08-02 13:21 ` [RFC v3 6/8] virtio: Implement pasta vhost acceleration guest->pasta path Ammar Yasser
2026-08-02 13:21 ` [RFC v3 7/8] pasta: Implement pasta vhost TX (pasta->guest) prerequisites Ammar Yasser
2026-08-02 13:21 ` [RFC v3 8/8] tap: Implement pasta vhost TX Ammar Yasser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260802132155.870796-4-aerosound161@gmail.com \
    --to=aerosound161@gmail.com \
    --cc=eperezma@redhat.com \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).