From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine 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=RRzUOmDC; 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 ESMTPS id 16D0E5A0280 for ; Tue, 03 Jun 2025 10:42:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748940148; 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=g1ILEacTmy+PUeMnIRyAQ4aWLaxcTA4oVHNd6v1MpIo=; b=RRzUOmDCOncpE+isXg1XvY/GQonWOAp6UqAKssoaPwe8yJ/MN6ztDnhpI3Jk1ZepK8BrKz 8gBEq3ch32VMlFzs2XlgXN0eA+X1a8pUYyzaUNjZmzzs/53rNp+OBK0LxlIq6cfU3KDQZG MANVTYmaIE8hbWvfmZdpkEmOf6jd+K0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-500-t8BKVTGtPXqhWMV3oBtgAw-1; Tue, 03 Jun 2025 04:42:27 -0400 X-MC-Unique: t8BKVTGtPXqhWMV3oBtgAw-1 X-Mimecast-MFC-AGG-ID: t8BKVTGtPXqhWMV3oBtgAw_1748940146 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-450cb902173so24197205e9.1 for ; Tue, 03 Jun 2025 01:42:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748940146; x=1749544946; 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=g1ILEacTmy+PUeMnIRyAQ4aWLaxcTA4oVHNd6v1MpIo=; b=mIGAElp/+ec6gnXz2qpuWJA15mr88q4S5ha8h15V+lVCPNs5PIfSXC2p/nIp5khnHA JeC3i4znBzR/itPieK0gVCINki2IrsANxHLlHiO8tNLcSD6VDH5KrHYKh0PRmuObt1t/ H3bq+ybNValgmA6Y6+6xVAmFEvQFSzeqL6UYLq8k3AOpGjOxvxOqCnq51O7K7ZkRKRRF /2fgnJ9u0eEtASGR7izZsUxJSTPtIM7wLkQTzchhVPkl4CyG9YbNPLBi3enJOv7O256N aaJwc8UVn8UzN/utk+FjYLJJfFXjicrG898FqCYXXVA+WYDjsWmIRwqjpfoyMmPUxhI9 0Z1g== X-Gm-Message-State: AOJu0YxoNdXyQqFWSjytfCBAH1iS8EHDhSa4jT0Ugrs2SVTf9LpkTrLj IdpK8IM99/FuQrKDqRsoGHms2QDxtL0p4ZnHR2CKvwPtN1DLiRzx9yUGWNq2FtWNaw74QUKx/x+ l8GYfEWvDoe3sTtRVP6TN/fsc/fWLEBT78c9jDLBSiYA2J26dKgh6rQOhffMID7OKk4CsnZgTN2 0hYD2gdUouwVCucfhMgSjo5e5tqUQVIjuh9JF1 X-Gm-Gg: ASbGnctOpz1U0+rl/UlSZrW0/78DnpgwhatlVn9BuwaTwC4PCYcUVstQxG+IaSYG+i5 4YKxJb21F3NzZ3T/R+ypIzixctlueHFroxuw8ekZT881GVIn1LDdb0hkaSlYQB/tdq65nzbWv6K oQ/xb0N414Tj99QNrZ2otsC9nuhJYn6oYnW5YwQ63ZQpNC2qUGLTNUblEFkf6VVW4qNGBodL25l ZSoHA6wq5L3o8nKP33BdRrZ4h4m+ZUwabGKWQorfcOL3q1XaA5uPYFcUURAnjQkSUpNz8o9VTeM zAui2jmlXf03YyW62nZw+EVNK8ySCBMhAQFqGK7C X-Received: by 2002:a05:600c:8b6d:b0:451:df07:d8e0 with SMTP id 5b1f17b1804b1-451e67af2c5mr16695415e9.11.1748940146048; Tue, 03 Jun 2025 01:42:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4xKitGQCriOCt4uLBKC5vev9v9pMvM6b+f8vxZuDyo8GMTyhWq9UOFuzhkau9Zuq75K21PQ== X-Received: by 2002:a05:600c:8b6d:b0:451:df07:d8e0 with SMTP id 5b1f17b1804b1-451e67af2c5mr16695105e9.11.1748940145579; Tue, 03 Jun 2025 01:42:25 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-451e505d40csm15335255e9.0.2025.06.03.01.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jun 2025 01:42:25 -0700 (PDT) Date: Tue, 3 Jun 2025 10:42:23 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v5 03/29] iov: Update IOV_REMOVE_HEADER() and IOV_PEEK_HEADER() Message-ID: <20250603104223.5e773497@elisabeth> In-Reply-To: References: <20250417165136.2688884-1-lvivier@redhat.com> <20250417165136.2688884-4-lvivier@redhat.com> <20250526161918.6fface54@elisabeth> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: jp0QtV1uZTdddetQnnDuMVDbFy3M-gcLPVG114EjfyA_1748940146 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 6TW4PKVCFMX2IJ3NER2ND6OYHXI3LNAF X-Message-ID-Hash: 6TW4PKVCFMX2IJ3NER2ND6OYHXI3LNAF 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 Mon, 2 Jun 2025 17:36:06 +0200 Laurent Vivier wrote: > On 26/05/2025 16:19, Stefano Brivio wrote: > > On Thu, 17 Apr 2025 18:51:10 +0200 > > Laurent Vivier wrote: > > > >> Provide a temporary variable of the wanted type to store > >> the header if the memory in the iovec array is not contiguous. > >> > >> Signed-off-by: Laurent Vivier > >> --- > >> iov.c | 53 ++++++++++++++++++++++++++++++++++++++++++++--------- > >> iov.h | 52 ++++++++++++++++++++++++++++++++++++++-------------- > >> tcp_buf.c | 2 +- > >> 3 files changed, 83 insertions(+), 24 deletions(-) > >> > >> diff --git a/iov.c b/iov.c > >> index 047fcbce7fcd..907cd5339369 100644 > >> --- a/iov.c > >> +++ b/iov.c > >> @@ -108,7 +108,7 @@ size_t iov_from_buf(const struct iovec *iov, size_t iov_cnt, > >> * > >> * Returns: The number of bytes successfully copied. > >> */ > >> -/* cppcheck-suppress unusedFunction */ > >> +/* cppcheck-suppress [staticFunction] */ > >> size_t iov_to_buf(const struct iovec *iov, size_t iov_cnt, > >> size_t offset, void *buf, size_t bytes) > >> { > >> @@ -126,6 +126,7 @@ size_t iov_to_buf(const struct iovec *iov, size_t iov_cnt, > >> /* copying data */ > >> for (copied = 0; copied < bytes && i < iov_cnt; i++) { > >> size_t len = MIN(iov[i].iov_len - offset, bytes - copied); > >> + /* NOLINTNEXTLINE(clang-analyzer-core.NonNullParamChecker) */ > >> memcpy((char *)buf + copied, (char *)iov[i].iov_base + offset, > >> len); > >> copied += len; > >> @@ -260,7 +261,7 @@ bool iov_tail_drop(struct iov_tail *tail, size_t len) > >> } > >> > >> /** > >> - * iov_peek_header_() - Get pointer to a header from an IOV tail > >> + * iov_check_header() - Check if a header can be accessed > >> * @tail: IOV tail to get header from > >> * @len: Length of header to get, in bytes > >> * @align: Required alignment of header, in bytes > >> @@ -271,8 +272,7 @@ bool iov_tail_drop(struct iov_tail *tail, size_t len) > >> * overruns the IO vector, is not contiguous or doesn't have the > >> * requested alignment. > >> */ > >> -/* cppcheck-suppress [staticFunction,unmatchedSuppression] */ > >> -void *iov_peek_header_(struct iov_tail *tail, size_t len, size_t align) > >> +static void *iov_check_header(struct iov_tail *tail, size_t len, size_t align) > >> { > >> char *p; > >> > >> @@ -292,27 +292,62 @@ void *iov_peek_header_(struct iov_tail *tail, size_t len, size_t align) > >> return p; > >> } > >> > >> +/** > >> + * iov_peek_header_() - Get pointer to a header from an IOV tail > >> + * @tail: IOV tail to get header from > >> + * @v: Temporary memory to use if the memory in @tail > >> + * is discontinuous > >> + * @len: Length of header to get, in bytes > >> + * @align: Required alignment of header, in bytes > >> + * > >> + * @tail may be pruned, but will represent the same bytes as before. > >> + * > >> + * Returns: Pointer to the first @len logical bytes of the tail, or to > >> + * a copy if that overruns the IO vector, is not contiguous or > >> + * doesn't have the requested alignment. NULL if that overruns the > >> + * IO vector. > >> + */ > >> +/* cppcheck-suppress [staticFunction,unmatchedSuppression] */ > >> +void *iov_peek_header_(struct iov_tail *tail, void *v, size_t len, size_t align) > >> +{ > >> + char *p = iov_check_header(tail, len, align); > >> + size_t l; > >> + > >> + if (p) > >> + return p; > >> + > >> + l = iov_to_buf(tail->iov, tail->cnt, tail->off, v, len); > > > > This effectively bypasses three checks performed by iov_check_header(), > > that is, if there's nothing left in the iov_tail, if 'len' exceeds it, > > or if it's not aligned, we'll proceed calling iov_to_buf(), whereas we > > should only call it if the buffer is not contiguous, I think. > > > > Perhaps it would make more sense to fail on iov_check_header() failure, > > and take the contiguity check out of it, so that we preserve the early > > return on those failures. > > > > Another alternative might be to call iov_to_buf from the old version of > > iov_peek_header_(), but I guess things would be easier to follow if > > iov_check_header() really indicates failure, instead. > > I think it's correct to make a copy when it's not aligned (because it's related to the > data position in memory, like to be not contiguous). Ah, hmm, right. Well, on one hand, it should never happen anyway, but on the other hand, it's a mistake that could now become harmless with your implementation, so why not... > The only real error case we must manage is if len exceeds the remaining size in the > iov_tail: we check the return value iov_to_buf() for that. There's also the if (!iov_tail_prune(tail)) case, but I guess the same reasoning applies (I haven't checked in detail, though). -- Stefano