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=G0NZlmHY; 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 36D845A0283 for ; Mon, 26 May 2025 16:21:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269311; 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=V6bIVTlEIjndv9vYn5crpjNhPB5D/7A0+XMOIVLnQcs=; b=G0NZlmHY3UtlSOP2O0YsLShK9ffGT2LFsO7QpDS09GMCkSV2U85Lm4H3yOrKLRjxwJDjxI 8Mv+wOUQdFulOgG1z8JZAxUlUnq/sQJMCX2+3pW7QGfB8tWIW6lIH4M9Rm64rDjQL5xQA/ 7qAkY1iW+6SZT3XxHhFT7W+nqAWu1vE= 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-596-i-7M0de0MBazKYOcZnZakw-1; Mon, 26 May 2025 10:21:50 -0400 X-MC-Unique: i-7M0de0MBazKYOcZnZakw-1 X-Mimecast-MFC-AGG-ID: i-7M0de0MBazKYOcZnZakw_1748269309 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43cf5196c25so13549555e9.0 for ; Mon, 26 May 2025 07:21:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269308; x=1748874108; 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=V6bIVTlEIjndv9vYn5crpjNhPB5D/7A0+XMOIVLnQcs=; b=C598AByAibIrbaFiVYawcZIWKuwwHGU9X+6+9su6zHJX9JmWO+HwoeaQGj6u1tNXa3 2OWbcfWzzXdWRK6Mz9KqGia1Xit3aZVHwnkY8ayckPf59LTZa6jAi60qy8CglRceD11R 2QCtZIyCUWJug01yGM/kNnNbW4i6dNm0f0NbdlZLx70hDBZwVbvWp4cwfX4N+DkhSvck RTu2txqHV/yVh75GznbN58qS4jX09Fnaqp/JUIu7UMwPUMZAThEbJqtwvD8oZT8nKYGf qNrWsYpJr+ILULPFw+CNTU+Os8Ms1LQ1ZTxS2UNghXSXv9DbMJ2hbSvFi9XXDB7C9pAv 9I2Q== X-Gm-Message-State: AOJu0Yyyh48bM9DxUNp9RGBmXzlMBT/VG4HCnYxcqMZ4dG8AOi8qJM4T aNgfQUFHISx6vaEzXrend0M6NM7j/Fff2lx0nJoKMf3jmq31EU54l1vCDx5ySNdmziBMLcUycIW 1HYpetFVzPcKq3/FdQPYO3R+DUBIOWb4t41SvWUY5OCO/avy6DXJWwpz8ITXzC5lGR+6ZoivYUF 9h5CkbYs7lBPvWOUVqICibFghB7Ex3ORzESDSJ X-Gm-Gg: ASbGncsqsSdZQLgr145adEcWGFTfJwC1vWr4STN2LRUYsYgLYQZAW25/Mmk99rZ294g fJJPya8Mx3B62GOAGD9grGDz/6ceuDFyu/BKLE1C25TFYvAFxwkzCwFOFvgE5lenguFob4AjSnf bdVB6VIZY/vMBuAXwSHKPLhvEFjWD8X1Zt6VCMj1pL4ZpnkACQ1iNrdM3KjfDEYMqIYNWXiXMqI Lnh4sDWR6mBYKd9M7AW3XWDzHn+FKDNRbkyCMLWcG9S0xWPOK8rA+UqWHA4fu2o0GqlnsfJu5Jm HHuAJFrKC8NgqSAZZ4AbA7UceMgzQCCmccvLjeSa X-Received: by 2002:a5d:64c4:0:b0:3a4:d53d:be21 with SMTP id ffacd0b85a97d-3a4d53dbeebmr4715429f8f.20.1748269308495; Mon, 26 May 2025 07:21:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFe6vudK70GjeSIoKphT4MD+quRvKHPEzsWdcrWY+DHLUdRWJOnQ7hsQFjoakcXopZBYJAUuA== X-Received: by 2002:a5d:64c4:0:b0:3a4:d53d:be21 with SMTP id ffacd0b85a97d-3a4d53dbeebmr4715397f8f.20.1748269307982; Mon, 26 May 2025 07:21:47 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4d9982c96sm2876648f8f.64.2025.05.26.07.21.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:21:47 -0700 (PDT) Date: Mon, 26 May 2025 16:21:46 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v5 29/29] packet: use buf to store iovec array Message-ID: <20250526162146.52d68c66@elisabeth> In-Reply-To: <20250417165136.2688884-30-lvivier@redhat.com> References: <20250417165136.2688884-1-lvivier@redhat.com> <20250417165136.2688884-30-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: JGYD6ET5pDub6744RIy-dJ_jXpZy8k_FFXs0Q6uBU98_1748269309 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 7X7ZZKH2M7LF3VQAYTKTY7L5ZEFKTKO5 X-Message-ID-Hash: 7X7ZZKH2M7LF3VQAYTKTY7L5ZEFKTKO5 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 Thu, 17 Apr 2025 18:51:36 +0200 Laurent Vivier wrote: > When we use vhost-user we don't use the memory buffer > of the pool to store the packet, so we can use it to > store iovec array that points to the memory provided > by vhost-user. > > Signed-off-by: Laurent Vivier > --- > packet.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 147 insertions(+), 16 deletions(-) > > diff --git a/packet.c b/packet.c > index 0a2ad28d3d25..ccd98ff3aa36 100644 > --- a/packet.c > +++ b/packet.c > @@ -84,6 +84,121 @@ bool pool_full(const struct pool *p) > return p->count >= p->size; > } > > +/** > + * packet_iov_max_cnt() - Return the maximum number of iovec we can store I'd say "iovecs" (same just below in this same comment). > + * @p: Pointer to packet pool > + * > + * Return: the maximum number of iovec we can store in the memory of > + * the pool buffer > + */ > +static size_t packet_iov_max_cnt(const struct pool *p) > +{ > + return p->buf_size / sizeof(struct iovec); > +} > + > +/** > + * packet_iov_idx() - For a given packet index, return the iovec index and > + * the number of iovec entry of the packet > + * @p: Pointer to packet pool > + * @idx: Index of packet descriptor in pool > + * @iov_cnt: Pointer to store the number of the iovec entry of the packet > + * @func: For tracing: name of calling function > + * @line: For tracing: caller line of function call > + * > + * Return: the iovec index for the given packet index, @iov_cnt is set > + * to the number of the iovec entry of the packet > + */ > +static int packet_iov_idx(const struct pool *p, size_t idx, size_t *iov_cnt, > + const char *func, int line) > +{ > + size_t iov_idx, max = packet_iov_max_cnt(p); > + > + iov_idx = (size_t)p->pkt[idx].iov_base; > + *iov_cnt = p->pkt[idx].iov_len; > + > + ASSERT_WITH_MSG(iov_idx + *iov_cnt <= max, > + "Corrupt iov entry: (%zu, %zu), max: %zu, %s:%i", > + iov_idx, *iov_cnt, max, func, line); > + > + return iov_idx; > +} > + > +/** > + * packet_iov_next_idx() - Give the the next available iovec index > + * @p: Pointer to packet pool > + * @idx: Index of packet descriptor in pool > + * @func: For tracing: name of calling function > + * @line: For tracing: caller line of function call > + * > + * Return: the next available iovec index > + */ > +static size_t packet_iov_next_idx(const struct pool *p, size_t idx, > + const char *func, int line) > +{ > + size_t iov_idx, iov_cnt; > + > + if (idx == 0) > + return 0; I'm a bit lost here. Why is 0 a special value now? > + > + iov_idx = packet_iov_idx(p, idx - 1, &iov_cnt, func, line); > + > + return iov_idx + iov_cnt; > +} > + > +/** > + * packet_iov_data() - For a given packet index, provide the iovec array > + * @p: Pointer to packet pool > + * @idx: Index of packet descriptor in pool > + * @data: iov_tail to store iovec array and count > + * (offset is always set to 0) > + * @func: For tracing: name of calling function > + * @line: For tracing: caller line of function call > + */ > +static void packet_iov_data(const struct pool *p, size_t idx, > + struct iov_tail *data, > + const char *func, int line) > +{ > + struct iovec *iov = (struct iovec *)p->buf; > + size_t iov_idx, iov_cnt; > + > + iov_idx = packet_iov_idx(p, idx, &iov_cnt, func, line); > + > + data->iov = &iov[iov_idx]; > + data->cnt = iov_cnt; > + data->off = 0; > +} > + > +/** > + * packet_iov_check_range() - Check if iovec array is valid for a pool > + * @p: Pointer to packet pool > + * @data: iov_tail that stores the iovec array to check > + * @func: For tracing: name of calling function > + * @line: For tracing: caller line of function call > + * > + * Return: 0 if the range is valid, -1 otherwise > + */ > +static int packet_iov_check_range(const struct pool *p, > + const struct iov_tail *data, > + const char *func, int line) > +{ > + size_t offset, i; > + > + offset = data->off; > + for (i = 0; i < data->cnt; i++) { > + int ret; > + > + ret = packet_check_range(p, > + (char *)data->iov[i].iov_base + offset, > + data->iov[i].iov_len - offset, > + func, line); Nit: the usual argument alignment would be nice to have. -- Stefano