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=f0/J8+tR; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 195F55A0262 for ; Tue, 03 Sep 2024 21:25:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725391558; 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=zpID6lY7QuwmLX4YcrbWW5FAY7/P2QiKfNd6dSgy4pU=; b=f0/J8+tRnHLAjZzFIi5GWU83iazODkq7U6IUF6oFWakiItvvBqeCr+TB64FyKJJdOzxXLh c8gZa+zcJiwDJ00P87xgJW6MwqxZ+4uUQQbuNxHLnR9tGdTJNC5FPpQtmuBDCYEvoqiCvR VmEmvbG0w23sfj4TV6eIMs8Y9m+cMrA= Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-zjLzDPt5N2Gtj_JnzaInSg-1; Tue, 03 Sep 2024 15:25:56 -0400 X-MC-Unique: zjLzDPt5N2Gtj_JnzaInSg-1 Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-7141ab07fddso4495374b3a.0 for ; Tue, 03 Sep 2024 12:25:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725391554; x=1725996354; 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=zpID6lY7QuwmLX4YcrbWW5FAY7/P2QiKfNd6dSgy4pU=; b=sCB2C9CQBoTin+WWQRPwRUsQmxO6KkqOTWTwjdDeSeTGzUeBnkb1DY2u+MBIhbhCca BFi+OkCtqtpMgB+sJWBY9x81SbhFUBeIpBqjBfZP+XLycoVTMxCYv9FtIo5OwHzLDLeG tRo9vDCHZ7sOVMaHzU87evSWzC3/YJh8FxIvl0/gBgOrrGOlpCiQPl19fLvdUIoNqEcK L2WZLaCH+t7WLfcpQiTDFEO7snPAt1q0M5Yrni5Yjjar6D66zUgZTAf+4+hdrKqj0dB7 7/hWZUZNVhpTxf+XqbRtb9u5UMPPAk5ZsdWQovfJ7smUulBJgRNWGRAblxMtMNryCyAI qvQg== X-Gm-Message-State: AOJu0Ywh9BIK8C8zmMnmkvfWTPYnJYAFi26gIaWWGDkNZhCs2ak+AZuP SuwIA94qBoAIVA28A7agcUOrNfBXivAz5bfQc7sxmozz0AVxQJ2hXrmpxpErkGQWcsmzMasbjJB ex1p2QU6e06+0UOL+NGqiSk06KN+aKfRXBl4lR+rzBybuVdrvaF7Ylw6H0Q== X-Received: by 2002:a05:6a20:9f4b:b0:1c4:9d96:50c8 with SMTP id adf61e73a8af0-1cce1016174mr15615254637.29.1725391554544; Tue, 03 Sep 2024 12:25:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAnfEDSfSphMg9zUctNWhh5eophwGABDly9v9zjsqTf24VWEaQEA63tXg01dsr1ZX3Aj8hSw== X-Received: by 2002:a05:6a20:9f4b:b0:1c4:9d96:50c8 with SMTP id adf61e73a8af0-1cce1016174mr15615239637.29.1725391554122; Tue, 03 Sep 2024 12:25:54 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71778543570sm237769b3a.94.2024.09.03.12.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 12:25:53 -0700 (PDT) Date: Tue, 3 Sep 2024 21:25:50 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 5/6] tap: Re-introduce EPOLLET for tap connections Message-ID: <20240903212550.05900f14@elisabeth> In-Reply-To: <20240903120235.1688429-6-david@gibson.dropbear.id.au> References: <20240903120235.1688429-1-david@gibson.dropbear.id.au> <20240903120235.1688429-6-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: QAK5OOZ7G2PZJSNXO3NT3DXIFCXQTZLQ X-Message-ID-Hash: QAK5OOZ7G2PZJSNXO3NT3DXIFCXQTZLQ 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:34 +1000 David Gibson wrote: > 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. It didn't actually cause any issue according to your commit message for 4684f603446b itself. > 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. > > Signed-off-by: David Gibson > --- > tap.c | 28 +++++++++++++++++++--------- > 1 file changed, 19 insertions(+), 9 deletions(-) > > 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 otherwise > */ > -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 = 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; > } > > p = 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; > } > > 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 = p; > > tap_handler(c, now); > + > + return true; > } > > /** > @@ -1062,15 +1066,18 @@ void tap_handler_passt(struct ctx *c, uint32_t events, > } > > if (events & EPOLLIN) > - tap_passt_input(c, now); > + while (tap_passt_input(c, now)) > + ; Nit (same below): use curly brackets for multi-line block. Or just use: while (tap_passt_input(c, now)); > } > > /** > * 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 otherwise > */ > -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; > > @@ -1101,6 +1108,8 @@ static void tap_pasta_input(struct ctx *c, const struct timespec *now) > die("EOF on tap device, exiting"); > > tap_handler(c, now); > + > + return len > 0; > } > > /** > @@ -1116,7 +1125,8 @@ void tap_handler_pasta(struct ctx *c, uint32_t events, > die("Disconnect event on /dev/net/tun device, exiting"); > > if (events & EPOLLIN) > - tap_pasta_input(c, now); > + while (tap_pasta_input(c, now)) > + ; > } > > /** > @@ -1250,7 +1260,7 @@ void tap_listen_handler(struct ctx *c, uint32_t events) > trace("tap: failed to set SO_SNDBUF to %i", v); > > ref.fd = c->fd_tap; > - ev.events = EPOLLIN | EPOLLRDHUP; > + ev.events = EPOLLIN | EPOLLRDHUP | EPOLLET; > ev.data.u64 = 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); > > ref.fd = c->fd_tap; > - ev.events = EPOLLIN | EPOLLRDHUP; > + ev.events = EPOLLIN | EPOLLRDHUP | EPOLLET; > ev.data.u64 = 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 = EPOLL_TYPE_TAP_PASTA; > > - ev.events = EPOLLIN | EPOLLRDHUP; > + ev.events = EPOLLIN | EPOLLRDHUP | EPOLLET; > ev.data.u64 = ref.u64; > epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); > return; -- Stefano