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=Rr0t8g2N; 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 A05275A004C for ; Tue, 03 Sep 2024 21:25:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725391549; 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=jw8zPS3XFHnMlKL1sCkzWKPTDtQOs2HJLdESuricS88=; b=Rr0t8g2NBCUpDMPZ4DgpvZrCjloR+dpLIzNIFJUWRtRhjpw0guLpGG6MJ5DgQ1f3nniQgH VhWHXhxxNIhhTSst8WFHqfBteX02TxoMSHI9zEEqs+cNj4NOhPH5UjbOSiHqSEn/vCPfz6 YKFZqXcSLfnh3h1o1YpPe79SCtpac70= Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-213-XXyogpjUMwu3RXGUnwHf7Q-1; Tue, 03 Sep 2024 15:25:48 -0400 X-MC-Unique: XXyogpjUMwu3RXGUnwHf7Q-1 Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-7cf5c296887so4725139a12.3 for ; Tue, 03 Sep 2024 12:25:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725391546; x=1725996346; 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=jw8zPS3XFHnMlKL1sCkzWKPTDtQOs2HJLdESuricS88=; b=jH8eBXeKApKRnSFClvNdbMdljZFPXtXFjoLkKqLc6SFcj5DzxU6NvgMn4DOwSfpjyd dHhEwZOpgospztU2iOkeDKzHw9RaPFAmOehjrkElOKSHBQZkLZ40kkYLTLSmiCPyQk7Y 9JCyUTQsvFNB6t8TrKab9R5uC/eQBteu89tZXB/h+XJsOxrzawW3xiJweFJLrr4gxD/B j2fBIzyi3v9W1aMVm4XeWb99c9atzHKiNEyPh2QVqJf4efdZrpzUX7n+Tu4jbJazd+pI KZcfiY3nt2ogBNBDKpUdt7bm7LmDctZ1eZT6V5hXiA6gThHO6/vNBvGcpcAJSH1i49P4 SvKw== X-Gm-Message-State: AOJu0Yw3mWn5hvjJ02h/ae3fpwhs/DgHJEoQuMYX2OEjJawmD8EuHq9P s6AwEN3hpi7vCNwKazr1sSYYvMvCC1cfFFNESQE/jED9ntOyLa2dVTHqVUYGIFxLTt2pxEj1vcE cU3MGNrZkT8ACOp9WkCv0tVwJ2l4GJI3ii5qDvFB7UgfWKEo9ZQk8XNZ+6Q== X-Received: by 2002:a05:6a20:d70f:b0:1c8:fe09:f8cd with SMTP id adf61e73a8af0-1cce10147famr18129552637.24.1725391546544; Tue, 03 Sep 2024 12:25:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyGF2W74USYlJrJbVHAvLSXIKlYOQr6d2c54PI0zwkPG7m0cuqnVTK2sKQPXFmbLanFVpObw== X-Received: by 2002:a05:6a20:d70f:b0:1c8:fe09:f8cd with SMTP id adf61e73a8af0-1cce10147famr18129529637.24.1725391546113; Tue, 03 Sep 2024 12:25:46 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7177859974fsm228059b3a.149.2024.09.03.12.25.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 12:25:45 -0700 (PDT) Date: Tue, 3 Sep 2024 21:25:42 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 3/6] tap: Restructure in tap_pasta_input() Message-ID: <20240903212542.4934f5a6@elisabeth> In-Reply-To: <20240903120235.1688429-4-david@gibson.dropbear.id.au> References: <20240903120235.1688429-1-david@gibson.dropbear.id.au> <20240903120235.1688429-4-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: KLTKNRDD6O5EG4TZHX6JPZSBU6ROMEOR X-Message-ID-Hash: KLTKNRDD6O5EG4TZHX6JPZSBU6ROMEOR 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:32 +1000 David Gibson wrote: > tap_pasta_input() has a rather confusing structure, using two gotos. > Remove these by restructuring the function to have the main loop condition > based on filling our buffer space, with errors or running out of data > treated as the exception, rather than the other way around. This allows > us to handle the EINTR which triggered the 'restart' goto with a continue. > > The outer 'redo' was triggered if we completely filled our buffer, to flush > it and do another pass. This one is unnecessary since we don't (yet) use > EPOLLET on the tap device: if there's still more data we'll get another > event and re-enter the loop. > > Along the way handle a couple of extra edge cases: > - Check for EWOULDBLOCK as well as EAGAIN for the benefit of any future > ports where those might not have the same value > - Detect EOF on the tap device and exit in that case > > Signed-off-by: David Gibson > --- > tap.c | 42 +++++++++++++++++------------------------- > 1 file changed, 17 insertions(+), 25 deletions(-) > > diff --git a/tap.c b/tap.c > index 9ee59faa..71742748 100644 > --- a/tap.c > +++ b/tap.c > @@ -1073,42 +1073,34 @@ void tap_handler_passt(struct ctx *c, uint32_t events, > static void tap_pasta_input(struct ctx *c, const struct timespec *now) > { > ssize_t n, len; > - int ret; > - > -redo: > - n = 0; > > tap_flush_pools(); > -restart: > - while ((len = read(c->fd_tap, pkt_buf + n, TAP_BUF_BYTES - n)) > 0) { > > - if (len < (ssize_t)sizeof(struct ethhdr) || > - len > (ssize_t)ETH_MAX_MTU) { > - n += len; > - continue; > + for (n = 0; n < (ssize_t)TAP_BUF_BYTES; n += len) { > + len = read(c->fd_tap, pkt_buf + n, TAP_BUF_BYTES - n); > + > + if (len <= 0) { > + if (errno == EINTR) { You might be checking errno when read() returns 0, in which case it's not set. I guess you should zero out errno before read() if you want to keep this, or, alternatively, directly handle len == 0 here. > + len = 0; > + continue; > + } > + break; > } > > + /* Ignore frames of bad length */ > + if (len < (ssize_t)sizeof(struct ethhdr) || > + len > (ssize_t)ETH_MAX_MTU) > + continue; > > tap_add_packet(c, len, pkt_buf + n); > - > - if ((n += len) == TAP_BUF_BYTES) > - break; > } > > - if (len < 0 && errno == EINTR) > - goto restart; > - > - ret = errno; > + if (len < 0 && errno != EAGAIN && errno != EWOULDBLOCK) > + die("Error on tap device, exiting"); > + else if (len == 0) > + die("EOF on tap device, exiting"); > > tap_handler(c, now); > - > - if (len > 0 || ret == EAGAIN) > - return; > - > - if (n == TAP_BUF_BYTES) > - goto redo; > - > - die("Error on tap device, exiting"); > } > > /** -- Stefano