From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202408 header.b=MRwEEH1P; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 04F8F5A0262 for ; Wed, 04 Sep 2024 04:25:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1725416717; bh=yYZizgTJ28fAUkMv9/HwuXC2dbobg8rNYsQtWiPsLdM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MRwEEH1P66bn3Mb3+TPITbymR+9Kql90CM/q8OBIMr7IARxNBf0svaq6iIEa8OlBH dIa2nxthQbwbcBxtANL5eY816OC9R2T4h/dvaThCj8BgFjz+qilCiNKnfSQy2BdKjb aSHXsXhOpyCvonKDz/jlpaDETPGZzjaHbMAu9aaVgLSRiejUYPh9tCFP1n7gR+cRj/ dPPoejrj0ZaVY5CcFwo5EJKI8zcWqzxWL5Goytje74BR+5xhbNQLFXPk6o/XfIZ6je cG4SLZdVogMMrQD7iJLXmpQNH4tQFtSwJtK8wef0l2hntvBKmKp94VgLfwT4C1DcxN m6R7Rn5C+Hvqg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Wz5tj29jZz4xGl; Wed, 4 Sep 2024 12:25:17 +1000 (AEST) Date: Wed, 4 Sep 2024 11:36:20 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 5/6] tap: Re-introduce EPOLLET for tap connections Message-ID: References: <20240903120235.1688429-1-david@gibson.dropbear.id.au> <20240903120235.1688429-6-david@gibson.dropbear.id.au> <20240903212550.05900f14@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="3NYaJlPCLuavlrNZ" Content-Disposition: inline In-Reply-To: <20240903212550.05900f14@elisabeth> Message-ID-Hash: LLXFNCKEKCJ6I5FXHD2ROJAQIYSROR2M X-Message-ID-Hash: LLXFNCKEKCJ6I5FXHD2ROJAQIYSROR2M X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --3NYaJlPCLuavlrNZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 03, 2024 at 09:25:50PM +0200, Stefano Brivio wrote: > On Tue, 3 Sep 2024 22:02:34 +1000 > David Gibson wrote: >=20 > > Since 4684f603446b ("tap: Don't use EPOLLET on Qemu sockets") we've only > > used level-triggered events for the tap device. Prior to that we used = it > > inconsistently which caused some problems. >=20 > It didn't actually cause any issue according to your commit message for > 4684f603446b itself. I've reworded this. >=20 > > We want to add support for EPOLLOUT events on the tap connection, and > > without EPOLLET that would require toggling EPOLLOUT on and off, which = is > > awkward. So, re-introduce EPOLLET, but now use it uniformly for all tap > > modes. The main change this requires is making sure on EPOLLIN we loop > > until all there's no more data to process. > >=20 > > Signed-off-by: David Gibson > > --- > > tap.c | 28 +++++++++++++++++++--------- > > 1 file changed, 19 insertions(+), 9 deletions(-) > >=20 > > diff --git a/tap.c b/tap.c > > index 2fbcef04..d7d3fc19 100644 > > --- a/tap.c > > +++ b/tap.c > > @@ -985,8 +985,10 @@ static void tap_sock_reset(struct ctx *c) > > * tap_passt_input() - Handler for new data on the socket to qemu > > * @c: Execution context > > * @now: Current timestamp > > + * > > + * Return: true if there may be additional data to read, false otherwi= se > > */ > > -static void tap_passt_input(struct ctx *c, const struct timespec *now) > > +static bool tap_passt_input(struct ctx *c, const struct timespec *now) > > { > > static const char *partial_frame; > > static ssize_t partial_len =3D 0; > > @@ -1013,7 +1015,7 @@ static void tap_passt_input(struct ctx *c, const = struct timespec *now) > > err_perror("Receive error on guest connection, reset"); > > tap_sock_reset(c); > > } > > - return; > > + return false; > > } > > =20 > > p =3D pkt_buf; > > @@ -1025,7 +1027,7 @@ static void tap_passt_input(struct ctx *c, const = struct timespec *now) > > if (l2len < sizeof(struct ethhdr) || l2len > ETH_MAX_MTU) { > > err("Bad frame size from guest, resetting connection"); > > tap_sock_reset(c); > > - return; > > + return false; > > } > > =20 > > if (l2len + sizeof(uint32_t) > (size_t)n) > > @@ -1045,6 +1047,8 @@ static void tap_passt_input(struct ctx *c, const = struct timespec *now) > > partial_frame =3D p; > > =20 > > tap_handler(c, now); > > + > > + return true; > > } > > =20 > > /** > > @@ -1062,15 +1066,18 @@ void tap_handler_passt(struct ctx *c, uint32_t = events, > > } > > =20 > > if (events & EPOLLIN) > > - tap_passt_input(c, now); > > + while (tap_passt_input(c, now)) > > + ; >=20 > Nit (same below): use curly brackets for multi-line block. Or just use: >=20 > while (tap_passt_input(c, now)); Fixed. > > } > > =20 > > /** > > * tap_passt_input() - Handler for new data on the socket to qemu > > * @c: Execution context > > * @now: Current timestamp > > + * > > + * Return: true if there may be additional data to read, false otherwi= se > > */ > > -static void tap_pasta_input(struct ctx *c, const struct timespec *now) > > +static bool tap_pasta_input(struct ctx *c, const struct timespec *now) > > { > > ssize_t n, len; > > =20 > > @@ -1101,6 +1108,8 @@ static void tap_pasta_input(struct ctx *c, const = struct timespec *now) > > die("EOF on tap device, exiting"); > > =20 > > tap_handler(c, now); > > + > > + return len > 0; > > } > > =20 > > /** > > @@ -1116,7 +1125,8 @@ void tap_handler_pasta(struct ctx *c, uint32_t ev= ents, > > die("Disconnect event on /dev/net/tun device, exiting"); > > =20 > > if (events & EPOLLIN) > > - tap_pasta_input(c, now); > > + while (tap_pasta_input(c, now)) > > + ; > > } > > =20 > > /** > > @@ -1250,7 +1260,7 @@ void tap_listen_handler(struct ctx *c, uint32_t e= vents) > > trace("tap: failed to set SO_SNDBUF to %i", v); > > =20 > > ref.fd =3D c->fd_tap; > > - ev.events =3D EPOLLIN | EPOLLRDHUP; > > + ev.events =3D EPOLLIN | EPOLLRDHUP | EPOLLET; > > ev.data.u64 =3D ref.u64; > > epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); > > } > > @@ -1306,7 +1316,7 @@ static void tap_sock_tun_init(struct ctx *c) > > pasta_ns_conf(c); > > =20 > > ref.fd =3D c->fd_tap; > > - ev.events =3D EPOLLIN | EPOLLRDHUP; > > + ev.events =3D EPOLLIN | EPOLLRDHUP | EPOLLET; > > ev.data.u64 =3D ref.u64; > > epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); > > } > > @@ -1339,7 +1349,7 @@ void tap_sock_init(struct ctx *c) > > else > > ref.type =3D EPOLL_TYPE_TAP_PASTA; > > =20 > > - ev.events =3D EPOLLIN | EPOLLRDHUP; > > + ev.events =3D EPOLLIN | EPOLLRDHUP | EPOLLET; > > ev.data.u64 =3D ref.u64; > > epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); > > return; >=20 --=20 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 --3NYaJlPCLuavlrNZ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmbXuZMACgkQzQJF27ox 2GfeKQ//XH3ji6x7iNfIvLx/FaiSHaZCOITFWYfqjn9UbmlC6dx3A571vVlJnyX4 5OHpzuYQPl9Z0zPv5Lu/trKo2kbB6xJz6FjOzGhSRDdBAcmd5z72ncRc0MVdZj2j C3ZqbgCZz1XWvks9bj5ybl+iXJs2plaMWVUSnSMOthrSHkjdIUbPGSX31hvHyyzm mxFjxUY7IRQKcz4s/+XIdagDp1VgMPOY3n3yLbswnX3eghzwIMXtugTOSGpn4gw0 QoYmJDjIuV6M5nUOHvaBxEfpEV1ZIqdEYHwTWbP1TP/Y651s6B4yvi72VcMyhSSN DySMsDrh3xXNVdQyjG6GIfF6vCv5BdRJPWXMky2z9X0WQ5gf+Fm02GmLFSl/knEZ KESsyMuaxJ3PJH2PGwVdeFF4/lQwkiamzW8c6C2y/6+hqZaGsF6LU2aMi6mdLMyh sI9Ri1v4XWshMPVzDdrUl0/oZwLohbaDS4kV/ljbFtpe4U7b2f4HOTp3wzSvjQ29 MP1K/WHlfwgL/2RUeca3hww92iELzol33cSWSWvYBN8J/PQ7yydbhVQfYJDBT/e/ A+jQw3XqImHnhmVhFOTuurMYQtEeLRgKVtdnNu6L6aC4OftxC+fYdVtlIARyDJLA YcCcV4RxGCehcUJuHM7pOtvLZ4A0quwNoKYr9c6t2kZxZ+foPho= =JztJ -----END PGP SIGNATURE----- --3NYaJlPCLuavlrNZ--