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=IYSxVfxL; 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 ESMTPS id D453C5A0265 for ; Mon, 11 May 2026 11:08:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490479; 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=Y+YhcZiO+uBWDcWiT8nFioGqj+Gs2A/NmEz1xCh0gDU=; b=IYSxVfxLKE5Vh8eThnKtGl8iGyj/JyEtofieDz4gQC2LgmCjo80ARg/4IgG/+4kG8OMySB KPZU7G5yoBPzm4hhZR8XFWVM4E79VPz8s/ENnnDWR/EQJjmurfuW9BIEAKGtirTS0yfinY EJAnrizHh6FzqFQ1Wzj+3XM2zvM6wZM= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-519-iNFduwx-MBKoKQcCjZOX8w-1; Mon, 11 May 2026 05:07:58 -0400 X-MC-Unique: iNFduwx-MBKoKQcCjZOX8w-1 X-Mimecast-MFC-AGG-ID: iNFduwx-MBKoKQcCjZOX8w_1778490477 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8eaec5f60edso582576885a.2 for ; Mon, 11 May 2026 02:07:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490477; x=1779095277; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Y+YhcZiO+uBWDcWiT8nFioGqj+Gs2A/NmEz1xCh0gDU=; b=bn2ReBwx+1V7Yf9H06d7eH656I4FKkeVRYpBjJX5O/zwB/PtgDxxTaAqJIXF/6jlWN wBu0Au9Z3MA0IcKZkiKJq6OMNV6H+N5uBt5DBd447/6XSw+JBJroUMJ2vSZ3IkZHgIqK p7N17Mhkl7aW6nJtST1/Mf6DE7n6RpWza0LEokHnk/siM+2Nw5bs7BETVF9k+OUz2oXP 5Fq0CScKJn4lXd91W04Sd1wYNsZUphZCH9BsMdS1mYI8R4yb0R56jXF2/ozq5FEO49OZ pMKkqjZUQBDdYqxoVqFY06qRm2LyXeo1V9/TQ/6hwYp1P8BWXnD6Fd0uPLZ731WQ5Sbb O9Ow== X-Forwarded-Encrypted: i=1; AFNElJ+lMWZ5f081AEd+uc/m9v1Zjs2T7Np8GyemE9BGfkybU2oHlWtUaaB6waauMh10Dvd2Z0v9/DFRdLE=@passt.top X-Gm-Message-State: AOJu0Yz9+sUTcaIIfYFwt78UrIgG+iFEiPQKikejZwMGsWxcx0LEKd6E /SKvq7evIxllNUp9u99uA1HCjgsLb7uii6iVmb1136z9dYNMYsE3Pzjnh8WqOkQWbdGUaEbAQ/9 rNKzc8BBzIHxVfGLr6jFsWO5pE+2BX/quk5MVFTPIwAJtoz7WOGYUjg== X-Gm-Gg: Acq92OGTuvqPAb5LUxAIHtvkrYTm887euDXBcf7lHutc2AnyMthRs4rTD7Ne2eLk7dR VSEYkaAfEqFJm/AGumfBeSF6Hv4o6yBM+KtK1O1nqHX77MdsDvK4I9XHePp9FgeGgpGVy407RJg O3UxfCysuT5S1XiJkK+o0umQd6ZvhkoQN/lqrthwAM5CkdBkYgclpA19QeZbbW4yAyFivSSVhrT xHxtfQTFZ21aKI84Y5Gr/sy7Dy47W71ePbEpkXRzzGhP9iip+30IHHIQ9ni2zIsH2vA1FGS81kp 4QopU9hFI4/0bVHDTtSRhaS53d4PUxtPsdgssE/6KCFZAYdn3UmX7/ONQdobGJzeVCxtsBPsZRt 5FlH9diDo2yLaUyH48RqdCE9ThExzjams0bCiP0GPStI9VpzKnYRG0nvHyI2qUsc1KQDCMhcC+y NyywpIAUNTUJSv X-Received: by 2002:a05:620a:7017:b0:8f8:cdd0:df80 with SMTP id af79cd13be357-904d70c2e1amr3383124485a.59.1778490477521; Mon, 11 May 2026 02:07:57 -0700 (PDT) X-Received: by 2002:a05:620a:7017:b0:8f8:cdd0:df80 with SMTP id af79cd13be357-904d70c2e1amr3383120185a.59.1778490476918; Mon, 11 May 2026 02:07:56 -0700 (PDT) Received: from [192.168.2.15] (lnsm4-toronto63-142-116-28-118.internet.virginmobile.ca. [142.116.28.118]) by smtp.gmail.com with ESMTPSA id af79cd13be357-907b966f1b1sm1028834685a.9.2026.05.11.02.07.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 May 2026 02:07:56 -0700 (PDT) Message-ID: <8aad121d-d89e-406b-9cab-f07f4a18d186@redhat.com> Date: Mon, 11 May 2026 05:07:55 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 02/10] iov: Add iov_memcpy() to copy data between iovec arrays To: Laurent Vivier , passt-dev@passt.top References: <20260416155721.3807225-1-lvivier@redhat.com> <20260416155721.3807225-3-lvivier@redhat.com> From: Jon Maloy In-Reply-To: <20260416155721.3807225-3-lvivier@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: KtbhrfgdbtpvgrJeSy2Qppl6142F6Pu65Gqbd3AXMb4_1778490477 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: LX4PZXWXRLXQD4XUWTC2WBTQLHR6KZVQ X-Message-ID-Hash: LX4PZXWXRLXQD4XUWTC2WBTQLHR6KZVQ X-MailFrom: jmaloy@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 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 2026-04-16 11:57, Laurent Vivier wrote: > Add a helper to copy data from a source iovec array to a destination > iovec array, each starting at an arbitrary byte offset, iterating > through both arrays simultaneously and copying in chunks matching the > smaller of the two current segments. > > Signed-off-by: Laurent Vivier > Reviewed-by: David Gibson Reviewed-by: Jon Maloy But see below, > --- > iov.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ > iov.h | 3 +++ > 2 files changed, 55 insertions(+) > > diff --git a/iov.c b/iov.c > index 0188acdf5eba..dabc4f1ceea3 100644 > --- a/iov.c > +++ b/iov.c > @@ -197,6 +197,58 @@ void iov_memset(const struct iovec *iov, size_t iov_cnt, size_t offset, int c, > } > } > > +/** > + * iov_memcpy() - Copy data between two iovec arrays > + * @dst_iov: Destination iovec array > + * @dst_iov_cnt: Number of elements in destination iovec array > + * @dst_offset: Destination offset > + * @src_iov: Source iovec array > + * @src_iov_cnt: Number of elements in source iovec array > + * @offs: Source offset > + * @length: Number of bytes to copy > + * > + * Return: total number of bytes copied > + */ > +/* cppcheck-suppress unusedFunction */ > +size_t iov_memcpy(struct iovec *dst_iov, size_t dst_iov_cnt, size_t dst_offset, > + const struct iovec *src_iov, size_t src_iov_cnt, > + size_t src_offset, size_t length) > +{ > + unsigned int i, j; These could be size_t for consistency with the in parameters. /jon > + size_t total = 0; > + > + i = iov_skip_bytes(src_iov, src_iov_cnt, src_offset, &src_offset); > + j = iov_skip_bytes(dst_iov, dst_iov_cnt, dst_offset, &dst_offset); > + > + /* copying data */ > + while (length && i < src_iov_cnt && j < dst_iov_cnt) { > + size_t n = MIN(dst_iov[j].iov_len - dst_offset, > + src_iov[i].iov_len - src_offset); > + > + if (n > length) > + n = length; > + > + memcpy((char *)dst_iov[j].iov_base + dst_offset, > + (const char *)src_iov[i].iov_base + src_offset, n); > + > + dst_offset += n; > + src_offset += n; > + total += n; > + length -= n; > + > + if (dst_offset == dst_iov[j].iov_len) { > + dst_offset = 0; > + j++; > + } > + if (src_offset == src_iov[i].iov_len) { > + src_offset = 0; > + i++; > + } > + } > + > + return total; > +} > + > /** > * iov_tail_prune() - Remove any unneeded buffers from an IOV tail > * @tail: IO vector tail (modified) > diff --git a/iov.h b/iov.h > index d295d05b3bab..3c63308e554f 100644 > --- a/iov.h > +++ b/iov.h > @@ -32,6 +32,9 @@ size_t iov_size(const struct iovec *iov, size_t iov_cnt); > size_t iov_truncate(struct iovec *iov, size_t iov_cnt, size_t size); > void iov_memset(const struct iovec *iov, size_t iov_cnt, size_t offset, int c, > size_t length); > +size_t iov_memcpy(struct iovec *dst_iov, size_t dst_iov_cnt, size_t dst_offset, > + const struct iovec *src_iov, size_t src_iov_cnt, > + size_t src_offset, size_t length); > > /* > * DOC: Theory of Operation, struct iov_tail