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=Y4q5a/PT; 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 487275A004C for ; Thu, 19 Sep 2024 18:19:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726762772; 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=4gOGRddUGb1r9yV+zprn61HN49KEz1cCBi65wNvW9U0=; b=Y4q5a/PTucI56+vQ6E1EYiNd/StkGvTmgec4D71h3xRlrBmWSlo8JOtn1wKMB3sG1gVZAF Ud9NpEnfeTkJTB5aS/AgfNs9sz0jn2L100klHYP8bphl89TveMjtcHbvIgSI79ZyQhxk5k ii28RBx371EkByyNuMguQ+NqRwDgt7Y= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-OEcULDUbOVe4r6PUOKhFgQ-1; Thu, 19 Sep 2024 12:19:31 -0400 X-MC-Unique: OEcULDUbOVe4r6PUOKhFgQ-1 Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-207464a9b59so17577415ad.3 for ; Thu, 19 Sep 2024 09:19:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726762770; x=1727367570; 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=4gOGRddUGb1r9yV+zprn61HN49KEz1cCBi65wNvW9U0=; b=pDimaurt+y0dwOseCo8VBPB1LL1zJkiQb/lAIBoWPYY7ESJwi6dq7Zas8mXgFyN4uV L+vy2Chj8iHLj40BT+SAc29R8EeLECYCy6Sz3aEQwqwl+z6BnlvoUsdL+yleSywttLgT nEKKN2ceimVCE6PgwYgXNiaXLSMhLWDhGUoO3ilVWxihikfv6I8EUgXhIO02M8niw1RJ leJsM9X1PYbjOY/VoyhrIMq9md9YQyxCxtLUg3idpzd0A9A1qUWoxNAT0vearvp9aFR/ EGtQWiViJASZeDmrF1neYRpsgAjvauq5KK+Drp1yzhFInouKIvqwxrTgOfIXmC2rtFJI d7fg== X-Forwarded-Encrypted: i=1; AJvYcCUShiS21ow50gw+lVuw+zr3BAqatAXFwPDwX7W8pyD3XpmwSwBLjUmJ22BLTdGA8WLw91dUnOD9ALc=@passt.top X-Gm-Message-State: AOJu0YyJCjM5/x62mGgqn8z0QOhIYo0KlN65v4FCctB5dcpR+sSQKGf8 A2NcdNfrFIY63QHd32MCto9Y4zh1WxIXFOcBhe/jwQ/ptW4IHW9G0fIvuyQblf1tJbPpB9TtJpR EpZTjxsFwMFfZD1NPaCTyWsHvSLSC1aZVZmTvJOiMKNw6npi6Ug== X-Received: by 2002:a17:903:2288:b0:205:40cd:9c79 with SMTP id d9443c01a7336-2076e31ecd8mr384805325ad.3.1726762769930; Thu, 19 Sep 2024 09:19:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZ7nmkRpnovH2kodRii0/U4lgjwwsdzORLL7xz6qpsd6vDfInNMnAERVRKzyC7lL0lpqPGgg== X-Received: by 2002:a17:903:2288:b0:205:40cd:9c79 with SMTP id d9443c01a7336-2076e31ecd8mr384804895ad.3.1726762769413; Thu, 19 Sep 2024 09:19:29 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-207946d28b4sm81800655ad.177.2024.09.19.09.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 09:19:28 -0700 (PDT) Date: Thu, 19 Sep 2024 18:19:25 +0200 From: Stefano Brivio To: Markus Armbruster Subject: Re: [PATCH v3 2/2] util: Remove possible quadratic behaviour from write_remainder() Message-ID: <20240919181925.171635b2@elisabeth> In-Reply-To: <87plozsz4d.fsf@pond.sub.org> References: <20240918104406.3050878-1-david@gibson.dropbear.id.au> <20240918104406.3050878-3-david@gibson.dropbear.id.au> <87plozsz4d.fsf@pond.sub.org> 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: EGIT3UE7ARIS6FGTDVTQK7CML4QQGK6K X-Message-ID-Hash: EGIT3UE7ARIS6FGTDVTQK7CML4QQGK6K 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: David Gibson , 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 Thu, 19 Sep 2024 12:42:58 +0200 Markus Armbruster wrote: > David Gibson writes: > > > write_remainder() steps through the buffers in an IO vector writing out > > everything past a certain byte offset. However, on each iteration it > > rescans the buffer from the beginning to find out where we're up to. With > > an unfortunate set of write sizes this could lead to quadratic behaviour. > > > > In an even less likely set of circumstances (total vector length > maximum > > size_t) the 'skip' variable could overflow. This is one factor in a > > longstanding Coverity error we've seen (although I still can't figure out > > the remainder of its complaint). > > > > Rework write_remainder() to always work out our new position in the vector > > relative to our old/current position, rather than starting from the > > beginning each time. As a bonus this seems to fix the Coverity error. > > > > Signed-off-by: David Gibson > > --- > > util.c | 27 +++++++++++++++++---------- > > 1 file changed, 17 insertions(+), 10 deletions(-) > > > > diff --git a/util.c b/util.c > > index 7db7c2e7..87309c51 100644 > > --- a/util.c > > +++ b/util.c > > @@ -597,10 +597,15 @@ int write_all_buf(int fd, const void *buf, size_t len) > > size_t left = len; > > > > while (left) { > > - ssize_t rc = write(fd, p, left); > > + ssize_t rc; > > + > > + do > > + rc = write(fd, p, left); > > + while ((rc < 0) && errno == EINTR); > > > > if (rc < 0) > > return -1; > > + > > p += rc; > > left -= rc; > > } > > Uh, shouldn't this be squashed into PATCH 1? Oh, oops, in theory yes, but while reviewing this I just had a look at the result in util.c, and now it's merged. It's not a big issue I'd say. Thanks for reporting anyway. -- Stefano