From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eRgZh4t+; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 8E9325A004C for ; Tue, 03 Sep 2024 21:25:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725391542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4jOKeU8JPB4ZrIziBvWu555c10ZxEQHW0+1eDTLeZis=; b=eRgZh4t+AGrbxLM+A8JPx+sKrkKAYQkFvwVD21XnWQkyNRmRQRt9mFPJU/AiKSsOoCduSS SOj/AqDl6ShB/B6RQ7MyngroEOTVYwuurPib3vRTSOxpeW8Re0jUs90hxcA7eWBwZThF0y 4WFxQfFa43GTSD6cKOxJ32YRUTMOiLU= Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-440-FLn2HKmiMWGVpAh9eoVHUw-1; Tue, 03 Sep 2024 15:25:41 -0400 X-MC-Unique: FLn2HKmiMWGVpAh9eoVHUw-1 Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2053f4938c7so33213235ad.2 for ; Tue, 03 Sep 2024 12:25:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725391540; x=1725996340; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4jOKeU8JPB4ZrIziBvWu555c10ZxEQHW0+1eDTLeZis=; b=lNEO1JFvDdj3fG98GynS/2flRfyvqbV000f22P89BXIwP+5arzdkulsrSh7Rru9nCl A2nYtFZctm0G7obSHoVNtNv92oO3yHgW8Nf4Kd66XQu5DUiYA8+zt7JJxnsIi8Vtw+nw 1XsK6RDMTdLdpoBDhlmPciRwGqoL8No8+xrTTKbiQdDzUIr5xdAzA5AR0xvptFkjChao aCjwjUqcRaiOwTkksYWkm4XX3tiBemt2mDhB4cGO9FYb/v0KuY0hZfpJUSS2pDW4ntgf 2cdtSE5SolHDoVnBlTb5FZu38PXORxb/RMmHmIxe9mPzVQYDvNCtON1BRBtzHnhOwhQw ZqFA== X-Gm-Message-State: AOJu0YzrGTK8NupP2dRiYBAJ0uoNmTwUOI3NGoTmH3gWpqyks6fzSbUk T5n4F/Bq0S/cUV7mi6BtN86WCMYgeFPVm1r4M65fvDXppFGi9RSiXFNQJ6WT8MiVu+JulHHc1yR d4cPc5Q3bcXyXqxlBxkNyGzwGJ0jZCtcohhwtSKlCtZ1NMcofLTqRyOGXUw== X-Received: by 2002:a17:902:f686:b0:205:7574:3b87 with SMTP id d9443c01a7336-20575743c5fmr72860355ad.15.1725391540030; Tue, 03 Sep 2024 12:25:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1Stjyqb2uQcSw7ALXit8UdVUukljZCWoYr2BoXv9mDa7zFpbpmbhD8fcstWSfjNJcGgbOgQ== X-Received: by 2002:a17:902:f686:b0:205:7574:3b87 with SMTP id d9443c01a7336-20575743c5fmr72860145ad.15.1725391539530; Tue, 03 Sep 2024 12:25:39 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206aea6898dsm1851215ad.284.2024.09.03.12.25.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 12:25:38 -0700 (PDT) Date: Tue, 3 Sep 2024 21:25:35 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 1/6] tap: Split out handling of EPOLLIN events Message-ID: <20240903212535.5c66fb90@elisabeth> In-Reply-To: <20240903120235.1688429-2-david@gibson.dropbear.id.au> References: <20240903120235.1688429-1-david@gibson.dropbear.id.au> <20240903120235.1688429-2-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: KPGCXLMSIQX3BULPLEGVDJL6RGTUBPT2 X-Message-ID-Hash: KPGCXLMSIQX3BULPLEGVDJL6RGTUBPT2 X-MailFrom: sbrivio@redhat.com 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: On Tue, 3 Sep 2024 22:02:30 +1000 David Gibson wrote: > Currently, tap_handler_pas{st,ta}() check for EPOLLRDHUP, EPOLLHUP and > EPOLLERR events, then assume anything left is EPOLLIN. We have some future > cases that may want to also handle EPOLLOUT, so in preparation explicitly > handle EPOLLIN, moving the logic to a subfunction. > > Signed-off-by: David Gibson > --- > tap.c | 50 ++++++++++++++++++++++++++++++++++++-------------- > 1 file changed, 36 insertions(+), 14 deletions(-) > > diff --git a/tap.c b/tap.c > index 852d8376..14c88871 100644 > --- a/tap.c > +++ b/tap.c > @@ -982,24 +982,17 @@ static void tap_sock_reset(struct ctx *c) > } > > /** > - * tap_handler_passt() - Packet handler for AF_UNIX file descriptor > + * tap_passt_input() - Handler for new data on the socket to qemu > * @c: Execution context > - * @events: epoll events > * @now: Current timestamp > */ > -void tap_handler_passt(struct ctx *c, uint32_t events, > - const struct timespec *now) > +static void tap_passt_input(struct ctx *c, const struct timespec *now) > { > static const char *partial_frame; > static ssize_t partial_len = 0; > ssize_t n; > char *p; > > - if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) { > - tap_sock_reset(c); > - return; > - } > - > tap_flush_pools(); > > if (partial_len) { > @@ -1052,20 +1045,33 @@ void tap_handler_passt(struct ctx *c, uint32_t events, > } > > /** > - * tap_handler_pasta() - Packet handler for /dev/net/tun file descriptor > + * tap_handler_passt() - Event handler for AF_UNIX file descriptor > * @c: Execution context > * @events: epoll events > * @now: Current timestamp > */ > -void tap_handler_pasta(struct ctx *c, uint32_t events, > +void tap_handler_passt(struct ctx *c, uint32_t events, > const struct timespec *now) > +{ > + if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) { > + tap_sock_reset(c); > + return; > + } > + > + if (events & EPOLLIN) > + tap_passt_input(c, now); > +} > + > +/** > + * tap_passt_input() - Handler for new data on the socket to qemu tap_pasta_input(), QEMU (we could just call it hypervisor, given that libkrun/krun also use this path). > + * @c: Execution context > + * @now: Current timestamp > + */ > +static void tap_pasta_input(struct ctx *c, const struct timespec *now) > { > ssize_t n, len; > int ret; > > - if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) > - die("Disconnect event on /dev/net/tun device, exiting"); > - > redo: > n = 0; > > @@ -1102,6 +1108,22 @@ restart: > die("Error on tap device, exiting"); > } > > +/** > + * tap_handler_pasta() - Packet handler for /dev/net/tun file descriptor > + * @c: Execution context > + * @events: epoll events > + * @now: Current timestamp > + */ > +void tap_handler_pasta(struct ctx *c, uint32_t events, > + const struct timespec *now) > +{ > + if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) > + die("Disconnect event on /dev/net/tun device, exiting"); > + > + if (events & EPOLLIN) > + tap_pasta_input(c, now); > +} > + > /** > * tap_sock_unix_open() - Create and bind AF_UNIX socket > * @sock_path: Socket path. If empty, set on return (UNIX_SOCK_PATH as prefix) -- Stefano