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=202508 header.b=o0Tswt7B; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 81C775A0278 for ; Mon, 15 Sep 2025 04:11:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1757902258; bh=1XEjwmqWlTfeGL4KHjj5PT08DO5VgyhkdFnAPtqf+fA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=o0Tswt7BSKmLMd1Evntr9dvHVMrRI+f4EQHJlJ6oIDLLa1brXfnVRyBVBDEv5IAg2 b65B4+neEVmtDLwyGnuSwKzPKgQAa2gCXXxiD93ukaJLGMqM1m1KjZoNVaWgRI2Srj EoCHS6+LeUVb2U0bY/3MhDbXDGIO21Im8VL2DvWGYiakO9IYDqOg+eWIzqhsIfy239 /53ZDFTk54/3ARdv7nuEq1q7UCFqSr34Xukt4tEHTYa3rEF8Es4XaX2sYSCEAzowbf jv34Y5GGALx07ZPc/h6m5hV9o8xj725yI6y/Yn19CXu5Lq23L8c/s2NfFh99cEabx9 jfS4Y9RMp3FiA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4cQ7mf3NDCz4w9Q; Mon, 15 Sep 2025 12:10:58 +1000 (AEST) Date: Mon, 15 Sep 2025 11:59:29 +1000 From: David Gibson To: Yumei Huang Subject: Re: [PATCH v2] tap: Drop frames if no client connected Message-ID: References: <20250912081705.20796-1-yuhuang@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="e4WHEab9lJtH7chx" Content-Disposition: inline In-Reply-To: <20250912081705.20796-1-yuhuang@redhat.com> Message-ID-Hash: 357KXR36TEYWESMFU6TFCOVKKM5GJW73 X-Message-ID-Hash: 357KXR36TEYWESMFU6TFCOVKKM5GJW73 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, sbrivio@redhat.com, lvivier@redhat.com 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: --e4WHEab9lJtH7chx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Sep 12, 2025 at 04:17:05PM +0800, Yumei Huang wrote: > If no client is attached, discard outgoing frames and report them as > sent. Without this we will get an EBADF in either writev() (pasta) or > sendmsg() (passt). That's basically harmless, but a bit ugly. > Explicitly catching this case results in behaviour that's probably a > bit clearer to debug if we hit it. >=20 > There are several different approaches we can take here. Here's some > reasoning as David explained: >=20 > * Don't listen() until the tap connection is ready >=20 > - It's not clear that the host rejecting the connection is better > than the host accepting, then the connection stalling until the > guest is ready. > - Would require substantial rework because we currently listen() as > we parse the command line and don't store the information we'd need > to do it later. >=20 > * Don't accept() until the tap connection is ready >=20 > - To the peer, will behave basically the same as this patch - the > host will complete the TCP handshake, then the connection will stall > until the guest is ready. > - More work to implement, because essentially every sock-side handler > has to check fd_tap and abort early >=20 > * Drop packets in tap_send_frames(), but return 0 >=20 > - To the peer, would behave basically the same > - Would make the TCP code do a bunch of busy work attempting to > resend, probably to no avail > - Handling of errors returned by tap_send_frames() is on the basis > that it's probably a transient fault (buffer full) and we want to > resend very soon. That approach doesn't make sense for a missing > guest. >=20 > Suggested-by: David Gibson > Signed-off-by: Yumei Huang Reviewed-by: David Gibson > --- > tap.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) >=20 > diff --git a/tap.c b/tap.c > index 7ba6399..2e371b3 100644 > --- a/tap.c > +++ b/tap.c > @@ -507,13 +507,16 @@ static size_t tap_send_frames_passt(const struct ct= x *c, > * @iov must have total length @bufs_per_frame * @nframes, with each set= of > * @bufs_per_frame contiguous buffers representing a single frame. > * > - * Return: number of frames actually sent > + * Return: number of frames actually sent, or accounted as sent I don't think it's worth a respin, but this might be better phrased as: "number of frames actually sent, or silently dropped" > */ > size_t tap_send_frames(const struct ctx *c, const struct iovec *iov, > size_t bufs_per_frame, size_t nframes) > { > size_t m; > =20 > + if (c->fd_tap =3D=3D -1) > + return nframes; > + > if (!nframes) > return 0; > =20 > --=20 > 2.47.0 >=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 --e4WHEab9lJtH7chx Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmjHcu8ACgkQzQJF27ox 2GcHUg//UF3Z0fa2AGk0TzbX/kYTh3xfIFy3zKDmQO58UOExVGQzlj5xhlhBYP2l joqO7z/Tcl5s+t2/c8WYsyD9BM7YwgmVfvpePygJ1PIARmo1r5MDlQ+fssOI6Ytn cPAnWHCvrt9ziuFrQHUwoB1WVfir5k6dPdcd7T8+4SXoWz7AU8ol3YNaR2R6A6Aa YB295vP7oPdPBiqkLvjbAOTCfdqSdY/aQFoStfCWUImOMwVIWH2pVkNJ5YEcEmUo 3evaQpc+humVoWaCwuk9VtQmkYv4c9I1N3YRNkhwgtQaHnMSCKns1DoipCLgQ9g+ n0A8ElFV2JKu8B15uRXgfJZc1gMysm8mYJWqqZBxet+WNLCSn/Lb9Hkq3HmSp7qH EEUkBqg/3zdyypovywF1D74PIXIGi0D1C6lrVDdxW02z03GdpBhFOhDSMlpRRXTq ukzfobhoc+iDTWfPqVnW6yJCfEBVHC5N/eSWElVmxveu/q4nxTfcixFFTuSc5e/F D+R6CF9BxmfPVhjZt2bOz+J8GgGGKseBd8SqfcDOsEbO4qT2tQ6hOeCm5XY9+2hn Ce6U8O1QNf/yQ9uVqF1NCPzFgjZB8udeTwl37DJgyY0xXYQGW5/2FC00tcK5joC8 XhGDnk8YBDSVC2JZNbJCHgJ+WKZI321YO30PBJJf2DXEcSUKTGE= =IvXE -----END PGP SIGNATURE----- --e4WHEab9lJtH7chx--