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=Tvmgb+Sr; 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 E6A395A0282 for ; Fri, 18 Jul 2025 20:45:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752864342; 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=o0tJE7JlFfzBcz27AFXiGxNy4C49XG0YpPNoYlVr9Nc=; b=Tvmgb+Sr28G0Q3s4w5MNMoZ+kci0fIyHyRjQF11kMC4R3jxYArSN5EsaAUztvNJa54ooCh aTbiEYcM4d8Ah5AkdQjO/2WYQj2ugf00DcsYniOnu0cs77GxjhQGDZBtloRQhk5US6vpBx 0IBKaXwUXegnJgCCAPxGVXbAYAyFid0= 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-390-78JHfSQUOtuMJCY6JfHdOw-1; Fri, 18 Jul 2025 14:45:40 -0400 X-MC-Unique: 78JHfSQUOtuMJCY6JfHdOw-1 X-Mimecast-MFC-AGG-ID: 78JHfSQUOtuMJCY6JfHdOw_1752864339 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4561dbbcc7eso8807975e9.2 for ; Fri, 18 Jul 2025 11:45:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752864338; x=1753469138; 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=o0tJE7JlFfzBcz27AFXiGxNy4C49XG0YpPNoYlVr9Nc=; b=LgPR65Ihi+MqSYKcViiMGEYzGyd4lkGilxhCsvVK+71YF2aTXgX7QiUCm5JDRzT+dY g4j38HzP6ICf8+R7XGbIrSxz2gKQysRTZNoFPHEsl9/RzC4nM7mPzF3UD+VSPLVbHU7f nZqVr8kfCKby6X7tm6WN7L1JqV8o3ykOuzJotAsqzqArNF6rbTa93/haoj5Mhmo39nEj 0LKNCiZsOG5DpfOJDnCSn7+yc028L/qj4qYBgyS37YHn/BUGZvGs+3iWz657Vgn+Cm4h jCHK2YuEASmuhY6Kv7fssl1M6gLqk4mFZmxyW03fgRhNj/Yr7jJYog0MjGIEMgqTDCVH vtWw== X-Gm-Message-State: AOJu0YzR34cMGDaiz49nOD7DSK1cudxd+qQns2PayqltPcRKosN0kTpi 7i9zgpJnMib1weZ3Ki+OJ6DFkvN3eRSyQwTQQxGiOTEwXgo//LiDmgjyOGcaAkx4o8EUdTq6wwi 13IsldttsL78TUdlYsU2IXkULTDm1GtEO+Dw4OZW52z6DKsaG9yhpioqJ++g6MufFRAGVMfGmsA uNYBsgH9vzXa5zUospIjZj8TZJ6O6AkJOEcGhx X-Gm-Gg: ASbGncsZgf/kc1IqjN+RPcIyizHrs6k3R7OGRg/a4Bdy7b4HngfEB0Fzb5g1nfr3sJo eDOKF6CkahJKPFd5eBPDxRkZvgnwxdDcO7PYjb8lkeZgkhwr9IYqzhOOvxQuuc3IKw5Fxz9WomO cggZR5s9qcy8/9CpMDYiqUO+nzJsQ7rLFmd2jfhD1JeHdPp0u8CJKL7RfuOzG1faX0GQDNBVywh fQxpieUQjkZzn4oonWEus2ocM2ZWJJtbyUFDDj30tCIcQ8aQie2/0CvoialWV/iyPpoHhxD7zwx c2NQg7X95dYZOdC4azS84vpkJgcWealh3xbFJp3mwifZZkhtZyN1CPBz0TZqzwlDi6fU X-Received: by 2002:a05:600c:a305:b0:453:8bc7:5e53 with SMTP id 5b1f17b1804b1-4562e853505mr101779085e9.0.1752864338521; Fri, 18 Jul 2025 11:45:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHIZfHl4IdDixvJkSIfCU8OXYKB0vAbvQLGcn781Knht2LnhPKWqpmBM7kgIqiZ3XfEr2Mc1A== X-Received: by 2002:a05:600c:a305:b0:453:8bc7:5e53 with SMTP id 5b1f17b1804b1-4562e853505mr101778875e9.0.1752864337977; Fri, 18 Jul 2025 11:45:37 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b61ca4d7fasm2581852f8f.69.2025.07.18.11.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jul 2025 11:45:37 -0700 (PDT) Date: Fri, 18 Jul 2025 20:45:36 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v7 31/31] packet: use buf to store iovec array Message-ID: <20250718204536.33ba94c0@elisabeth> In-Reply-To: <20250623110635.1478625-32-lvivier@redhat.com> References: <20250623110635.1478625-1-lvivier@redhat.com> <20250623110635.1478625-32-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: HcUcvLmgXPWyFIHOm_EdaSofui7-SsBXiCe5UO7pZRg_1752864339 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: FSPIUHMJUG6VUB3LDJAGF2VVZO4JHBYA X-Message-ID-Hash: FSPIUHMJUG6VUB3LDJAGF2VVZO4JHBYA 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, 23 Jun 2025 13:06:35 +0200 Laurent Vivier wrote: > In vhost-user mode, where `pool->buf` doesn't store packet data directly, > this patch repurposes it to hold the `struct iovec` array describing > a scattered packet. This enables pools to manage true scatter-gather > descriptors, with iovecs pointing to guest memory. > > `p->pkt[idx].iov_base` is now an index into this `pool->buf` iovec array, > and `p->pkt[idx].iov_len` is the count of iovecs. `packet_add_do` uses > `iov_tail_slice` to store these iovec descriptors from an input iov_tail > into `pool->buf`. `packet_data_do` reconstructs the iov_tail for a > packet by pointing to this stored array of iovecs. > > Signed-off-by: Laurent Vivier > --- > packet.c | 164 +++++++++++++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 148 insertions(+), 16 deletions(-) > > diff --git a/packet.c b/packet.c > index fd3b6db57c30..8dbe00af12c6 100644 > --- a/packet.c > +++ b/packet.c > @@ -84,6 +84,122 @@ bool pool_full(const struct pool *p) > return p->count >= p->size; > } > > +/** > + * packet_iov_max_cnt() - Return the maximum number of iovec entries we can > + * store > + * @p: Pointer to packet pool > + * > + * Return: the maximum number of iovec entries 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 I'm taking the liberty to fix this comment while applying ("Get the next available iovec index"). -- Stefano