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=PECgGEZl; 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 09C025A028D for ; Wed, 11 Jun 2025 14:52:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749646337; 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=eFug0xEuoGguivP/eOJs7GnRsWeGneGd+WAupbW0f50=; b=PECgGEZlJiJWs3MIadHNmf80YsCSkNJE1BzAQ2728a5YiXPhTDyw/EII2UY7U0hITScL7y cp380mF5Fx32DS0nCZubx7MMBBktSqGspygIDxaULWeOnLNPYQEB9sY9HiRI4n5X/btBDT x1LJoDxbhjojdCpthyu/g6qzpWEwFdU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-PeAIeRXGPw2M8aKGfmf6cQ-1; Wed, 11 Jun 2025 08:52:16 -0400 X-MC-Unique: PeAIeRXGPw2M8aKGfmf6cQ-1 X-Mimecast-MFC-AGG-ID: PeAIeRXGPw2M8aKGfmf6cQ_1749646335 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43e9b0fd00cso4816175e9.0 for ; Wed, 11 Jun 2025 05:52:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749646335; x=1750251135; 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=eFug0xEuoGguivP/eOJs7GnRsWeGneGd+WAupbW0f50=; b=IJUAmPke+22rqE7sC22lBo4fAWNY2wwix1CChHFPXh7wOlHUy+AHhq0ue+2ubF6GnB LNYw0Jpj2QkNDmBgUnajcgot3zXgze2rOB9XxDZP31DIFBbbYbIjXi1DKT98k2qWxSzn dCr1DJlhJYVbzZJsANIY2X6x9hPXFIBJNRtZeHvqPXfdFK+MgOj/hrU0GtcZ0ZUjn1hx UGrUgR2ig0LqK5lJWKrTb3HlBaTEA3d96XFoi/wVf9aENJbpYLSporN9WlYYutbhhtfF LKz802NbJiZGkc8eyW6FsrJiYyzMzC2yUh9F21RxK9GJyLdTLfEjTYI7FgplonI9zXRa FSUQ== X-Gm-Message-State: AOJu0Yxl3D6ZKkM90AhoFDyOphtmhJxzFsh0iLbpinFojI2CyvgraXAi jqPJyQWzn+eYsHyy/ig7RY+2oRHuzfNYhVSUB0ftyFfJ+NnQu7r3Zu1CATZ3F3UK55pKIuAE0p8 BipLIkk0PKjl/eRlVMMR2jwnJl4LKOIvFS63v0Uxk9qcTyp5jYgKzrV0bnG/s7JNsKfJzFUOdFm q+rZUSbBZ7TaAH/22cagDtmN51Zh/rHIjq64Cm X-Gm-Gg: ASbGncuIBgG1CPukUGcNuUaBeUWhL4zUnWzXECeXxunoB7xcO29cuTQ6s0VVU7p9q+q VmcfOuLJ69ggrJqY3P3+fQmWaOhijK2qZSXANNxw1JTfp6NRmAs6abYBVmAJo71xuykfchIKG0I C8JdRzc4P9UMAoomFhNk9lVUd+D/bJUElaIunuvEUYSjwdH4j20XxJgRq59eRJGHNc5ctBXEps5 ZmfQbx4x7JLFDm1zhj1fzHYUVVszgu2X5EHhhTsrd+v3qARsgX6G1CELPr//vOqciTkayVjX+WU lFSv0tIs+1k9IWfqFJuz25lopqaPR3jRcBUTy/flKrqUQIvYVhk= X-Received: by 2002:a05:600c:6095:b0:439:5f04:4f8d with SMTP id 5b1f17b1804b1-453241fb4abmr33563955e9.12.1749646335062; Wed, 11 Jun 2025 05:52:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYAbqAjw5mGNtRfffi2wpbOcVozdRz3Zf45SmdGJGfhTOoIWqL3Yc0htJpb+xmdcR0lq6kTw== X-Received: by 2002:a05:600c:6095:b0:439:5f04:4f8d with SMTP id 5b1f17b1804b1-453241fb4abmr33563615e9.12.1749646334526; Wed, 11 Jun 2025 05:52:14 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a53244ed76sm15279777f8f.78.2025.06.11.05.52.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 05:52:14 -0700 (PDT) Date: Wed, 11 Jun 2025 14:52:12 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v6 02/30] iov: Introduce iov_tail_clone() and iov_tail_drop(). Message-ID: <20250611145212.75ed7fe6@elisabeth> In-Reply-To: <20250604130834.3868010-3-lvivier@redhat.com> References: <20250604130834.3868010-1-lvivier@redhat.com> <20250604130834.3868010-3-lvivier@redhat.com> 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: o2xTjQUT7NmfgSycFlJbu1cWIW6llBd3zO2KT0DyXZ8_1749646335 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: NHKZQUFMUG5AV433AA7K5PGCDXYRYC3K X-Message-ID-Hash: NHKZQUFMUG5AV433AA7K5PGCDXYRYC3K 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 Wed, 4 Jun 2025 15:08:06 +0200 Laurent Vivier wrote: > These utilities enhance iov_tail manipulation, useful for > efficient packet processing by enabling iovec array cloning and > header stripping without data copies. > > - iov_tail_drop(): Discards a specified number of bytes from the > beginning of an iov_tail by advancing its internal offset and pruning > consumed elements. > > - iov_tail_clone(): Clone an iov_tail into an iovec array, adjusting the > first iovec entry to remove the iov_tail offset. > > Signed-off-by: Laurent Vivier > --- > iov.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ > iov.h | 3 +++ > 2 files changed, 55 insertions(+) > > diff --git a/iov.c b/iov.c > index 91e87a740f0a..3b89f8126ee7 100644 > --- a/iov.c > +++ b/iov.c > @@ -192,6 +192,21 @@ size_t iov_tail_size(struct iov_tail *tail) > return iov_size(tail->iov, tail->cnt) - tail->off; > } > > +/** > + * iov_tail_drop() - Discard a header from an IOV tail Same as v5: --- On Mon, 26 May 2025 16:19:03 +0200 Stefano Brivio wrote: > Mixing 'header' with 'tail' makes this a bit confusing. Yes, these > vectors are used for headers, but what about calling it simply 'item', > to match the context of this function? --- > + * @tail: IO vector tail > + * @len: length to move the head of the tail > + * > + * Returns: true if the item still contains any bytes, otherwise false Nit: we always use the imperative mood here, and no tabs, "Return: true if...". > + */ > +/* cppcheck-suppress unusedFunction */ > +bool iov_tail_drop(struct iov_tail *tail, size_t len) > +{ > + tail->off = tail->off + len; > + > + return iov_tail_prune(tail); > +} > + > /** > * iov_peek_header_() - Get pointer to a header from an IOV tail > * @tail: IOV tail to get header from > @@ -248,3 +263,40 @@ void *iov_remove_header_(struct iov_tail *tail, size_t len, size_t align) > tail->off = tail->off + len; > return p; > } > + > +/** > + * iov_tail_clone() - Assign iov references referencing a subset of the data Nit (same as for iov_slice() in v5): "iov_tail_clone() - Assign ..." > + * in an iov_tail > + * > + * @dst_iov: Pointer to the destination array of struct iovec describing > + * the scatter/gather I/O vector to copy to. Same as v5: perhaps "...to shallow copy to"? > + * @dst_iov_cnt: Maximum number of elements in the destination iov array. > + * @tail: Pointer to the source iov_tail > + * > + * Returns: The number of elements successfully copied to the destination "referenced from the destination iov array"? Same as above: "Return: the number of..." > + * iov array, a negative value if there is not enough room in the > + * destination iov array > + */ > +/* cppcheck-suppress unusedFunction */ > +ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, > + struct iov_tail *tail) > +{ > + const struct iovec *iov = &tail->iov[0]; > + size_t iov_cnt = tail->cnt; > + size_t offset = tail->off; > + unsigned int i, j; > + > + i = iov_skip_bytes(iov, iov_cnt, offset, &offset); > + > + /* assign iov references referencing a subset of the source one */ Nit: excess whitespace. > + for (j = 0; i < iov_cnt && j < dst_iov_cnt; i++, j++) { > + dst_iov[j].iov_base = (char *)iov[i].iov_base + offset; > + dst_iov[j].iov_len = iov[i].iov_len - offset; > + offset = 0; > + } Nice, this is much less scary than the previous iov_slice(). > + > + if (j == dst_iov_cnt && i != iov_cnt) > + return -1; > + > + return j; > +} > diff --git a/iov.h b/iov.h > index 9855bf0c0c32..11a8567aa183 100644 > --- a/iov.h > +++ b/iov.h > @@ -72,8 +72,11 @@ struct iov_tail { > > bool iov_tail_prune(struct iov_tail *tail); > size_t iov_tail_size(struct iov_tail *tail); > +bool iov_tail_drop(struct iov_tail *tail, size_t len); > void *iov_peek_header_(struct iov_tail *tail, size_t len, size_t align); > void *iov_remove_header_(struct iov_tail *tail, size_t len, size_t align); > +ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, > + struct iov_tail *tail); > > /** > * IOV_PEEK_HEADER() - Get typed pointer to a header from an IOV tail -- Stefano