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=TbiLVh8B; 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 778DE5A0625 for ; Thu, 11 Dec 2025 16:27:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765466875; 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=ML3wa2EWJgEOnrJ/mUgLqFVGJXv2ESmhMlueDxHrWV4=; b=TbiLVh8Bezw/6z46HnviiDSIfUR0+O1u0/hOQ2wvf+upW+qy1qAXnOhYV4h88Zi74R5u7n 1Yo5GISA19BPIVZa2CbHEhuQXxxqSU+K2PmD1dOd1MG2H/91fA1DmZUbzBmG8JGJpcJ+PT iUpHhvj5qkW+wkyMRyWw8dsEONBtL6E= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-523-tt4itxy2NRqNvUEWL9mefA-1; Thu, 11 Dec 2025 10:27:52 -0500 X-MC-Unique: tt4itxy2NRqNvUEWL9mefA-1 X-Mimecast-MFC-AGG-ID: tt4itxy2NRqNvUEWL9mefA_1765466872 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-42f9ece3849so173059f8f.1 for ; Thu, 11 Dec 2025 07:27:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765466871; x=1766071671; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ML3wa2EWJgEOnrJ/mUgLqFVGJXv2ESmhMlueDxHrWV4=; b=xRS4Yb3SHbSK8PheKaL+OTWyl8zs/u5cfTzcyWRgqvoc5cLP09hWVYvqfQXzjcV+rX snEA37cN3Rpwkh9iR6BqWcfQCTYg6LDNmI5q5T0zErcQumtCuD69NDlZBucuhp8/Q/S0 hTkIlDYe3bUhxWxAAkSciTo/Xnyem5UEesYGFqIjjkUlguz9RWu6JfSj0JzYr5yKGrOO H3Z5dfznE4AZ255lFBXM/wTIqI7vyQ8gkq8ta1AeYBy84adzvS1cgwb+Cb6JHw1hJ2Eq eizvWQeJrAMyw/x6rlfVofj+NZ2h1I5Lqv3hH41Kg2p9FEz5yX54ha5cr+Ow9H2cQGk3 j/qA== X-Gm-Message-State: AOJu0YxY3W0Njl0V15e2bCB4F6bMXIFquflOo0gtHqB9lZtBmb7ixB7u M/iaANxEgNhFfHelDrfjQSZy+6XFihtf7CnJooMetwLuFAxNmQPJ7+0JQC9Um43rk2A2E5GG7jc TBYIpOGUZanH55zYf4BXow2vXhW1Aul9g+6E4Ah5K6NSN7IsqSbU3vHgUDKwNoOXbSdc1qNTt+z lyJKFiWylby2ZeWnieQkLg6lH7ac2y/NLwVosx X-Gm-Gg: AY/fxX6hdSUi48qWwFAzFC1M+sVRgV+eQmgNXVXLw4dNER2X1yi/NEL1svaAX17yQMG fxiHTwGRi96oLkU8SbcjhH6U9iSV4Qv80KSyxMq/D+ArZpkIpUk21oAPmAQCWy/FCXKJCfZxZUk wFIHD08GRUzmx1iMRYHBKSK7PyszztvRDLwPLikhMY41GCVqE3dkveFzaG+herob8CGE/44oSBs VFk5hV4XuMiky1OQEfa5vB0n1aYzZu+Im6Q32/y9mQRD/bIsWVmNxQwTe1fyUrPSOmovUVjDtc5 +XUFaKFVcP3Y8BmkAaUSNg3R8L9JizBWee2Bylt/N1FZOdPG77UcFOYToeEJo6iXN1mYqOkQ//M rOqyYRR+X50epigmxX0XhYCQTCdmH7lo21Udt5Q== X-Received: by 2002:a05:6000:2384:b0:42f:8816:6e52 with SMTP id ffacd0b85a97d-42fa3b10c9emr7197378f8f.60.1765466870599; Thu, 11 Dec 2025 07:27:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGp2eRa7l022LbAP2Bt7PkA8XUlO5yyKnaIoT40mPTmOMzSHrYecji9KW1Op7S4sRozqftggw== X-Received: by 2002:a05:6000:2384:b0:42f:8816:6e52 with SMTP id ffacd0b85a97d-42fa3b10c9emr7197346f8f.60.1765466869964; Thu, 11 Dec 2025 07:27:49 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42fa8a70394sm6527947f8f.14.2025.12.11.07.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 07:27:49 -0800 (PST) Date: Thu, 11 Dec 2025 16:27:36 +0100 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v3 4/6] vhost-user: Add queue pair parameter throughout the network stack Message-ID: <20251211162736.55e25d36@elisabeth> In-Reply-To: References: <20251203185435.582096-1-lvivier@redhat.com> <20251203185435.582096-5-lvivier@redhat.com> <20251211080144.72d9577f@elisabeth> <85c1c222-dbd6-410d-96e3-9b000795919f@redhat.com> <20251211131618.1b5dac57@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: 2rBu_vuNpfGNoyaHQLxvjEguUlvyyDvVNeK18NoQCAE_1765466872 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: EO57YUOOLAVBBAQPLTH2UBOPATM4ILWA X-Message-ID-Hash: EO57YUOOLAVBBAQPLTH2UBOPATM4ILWA 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, 11 Dec 2025 14:26:01 +0100 Laurent Vivier wrote: > On 12/11/25 13:16, Stefano Brivio wrote: > > On Thu, 11 Dec 2025 09:48:42 +0100 > > Laurent Vivier wrote: > > > >> On 12/11/25 08:01, Stefano Brivio wrote: > >>> On Wed, 3 Dec 2025 19:54:32 +0100 > >>> Laurent Vivier wrote: > >>> > >>>> diff --git a/vu_common.c b/vu_common.c > >>>> index b13b7c308fd8..80d9a30f6f71 100644 > >>>> --- a/vu_common.c > >>>> +++ b/vu_common.c > >>>> @@ -196,11 +196,11 @@ static void vu_handle_tx(struct vu_dev *vdev, int index, > >>>> > >>>> data = IOV_TAIL(elem[count].out_sg, elem[count].out_num, 0); > >>>> if (IOV_DROP_HEADER(&data, struct virtio_net_hdr_mrg_rxbuf)) > >>>> - tap_add_packet(vdev->context, &data, now); > >>>> + tap_add_packet(vdev->context, 0, &data, now); > >>>> > >>>> count++; > >>>> } > >>>> - tap_handler(vdev->context, now); > >>>> + tap_handler(vdev->context, 0, now); > >>>> > >>>> if (count) { > >>>> int i; > >>>> @@ -235,23 +235,26 @@ void vu_kick_cb(struct vu_dev *vdev, union epoll_ref ref, > >>>> } > >>>> > >>>> /** > >>>> - * vu_send_single() - Send a buffer to the front-end using the RX virtqueue > >>>> + * vu_send_single() - Send a buffer to the front-end using a specified virtqueue > >>>> * @c: execution context > >>>> + * @qpair: Queue pair on which to send the buffer > >>>> * @buf: address of the buffer > >>>> * @size: size of the buffer > >>>> * > >>>> * Return: number of bytes sent, -1 if there is an error > >>>> */ > >>>> -int vu_send_single(const struct ctx *c, const void *buf, size_t size) > >>>> +int vu_send_single(const struct ctx *c, unsigned int qpair, const void *buf, size_t size) > >>>> { > >>>> struct vu_dev *vdev = c->vdev; > >>>> - struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; > >>>> struct vu_virtq_element elem[VIRTQUEUE_MAX_SIZE]; > >>>> struct iovec in_sg[VIRTQUEUE_MAX_SIZE]; > >>>> + struct vu_virtq *vq; > >>>> size_t total; > >>>> int elem_cnt; > >>>> int i; > >>>> > >>>> + vq = &vdev->vq[qpair << 1]; > >>> > >>> << 1 instead of * 2 is a bit surprising here, for a few seconds I > >>> thought you swapped qpair and 1. > >>> > >>> Then I started thinking that somebody is likely to mix up (probably not > >>> you) indices of RX and TX queues at some point. So... what about some > >>> macros, say (let's see if I got it right this time): > >>> > >>> #define VHOST_SEND_QUEUE(pair) ((pair) * 2) > >>> #define VHOST_RECV_QUEUE(pair) (pair) > >> > >> I will. David had the same comment. > > > > Uh, wait, I must have missed it. Do you have a Message-ID? I'm afraid I > > must have missed some emails here but I don't see them in archives > > either... > > Message-ID: aRF1_Qj6uxf1ndiA@zatzit Ah, yes, I read that, but I didn't relate it to this topic as it was just about the direction / naming. I see now. > >> TX and RX are from the point of view of guest, it's > >> not obvious when we read passt code. > > > > Right, yes, for me neither, I always get confused. That's why I thought > > we could make the RX vhost-user queue become "SEND" in passt's code, > > but: > > > >> I would prefer as David proposed to use, i.e. FROMGUEST and TOGUEST: > >> > >> #define VHOST_FROM_GUEST(qpair) ((qpair) * 2 + 1) > >> #define VHOST_TO_GUEST(qpair) ((qpair) * 2) > > > > ...this is even clearer. It misses the QUEUE though. Does > > VHOST_QUEUE_{FROM,TO}_GUEST fit where you use it? Otherwise I guess VQ > > together with FROM / TO should be clear enough. > > > >>> and: > >>> > >>> #define VHOST_QUEUE_PAIR(q) ((q) % 2) ? (q) : (q) / 2) > >> > >> I don't undestand the purpose of this one. > > > > To get the pair number from a queue number. You're doing something like > > that (I guess?) in 5/6, vu_handle_tx(): > > > > + tap_flush_pools(index / 2); > > > > + tap_add_packet(vdev->context, index / 2, &data, now); > > > > + tap_handler(vdev->context, index / 2, now); > > > > but now that I see your definition for VHOST_FROM_GUEST() above, and > > that the purpose wasn't clear to you, I guess it should be: > > > > #define VHOST_PAIR_FROM_QUEUE(q) (((q) % 2) ? ((q) - 1 / 2) : ((q) / 2)) > > > > Why not simply: > > #define VHOST_PAIR_FROM_QUEUE(q) (q / 2) > > QUEUES 0,1 -> QP 0 > QUEUES 2,3 -> QP 1 Ah, right, of course. Don't forget the parentheses around 'q'. > > ...or maybe it's not needed? I'm not sure. > > > >>> > >>> ...are they correct? A short description or "Theory of operation" > >>> section somewhere with a recap of how queue indices are used would be > >>> nice to have. > >>> > >>> And maybe also something explaining that 0 that's now appearing in > >>> argument lists: > >>> > >>> #define VHOST_NO_QUEUE 0 > >> > >> It's not really NO_QUEUE, it's default queue pair, the queue pair 0 > > > > Hmm but for non-vhost-user usages then it's not a queue, right? Well, > For non vhost usage we can say there is only one queue. > > > whatever, as long as we have a definition for it... or maybe we could > > have VHOST_QUEUE_DEFAULT and NO_VHOST_QUEUE or VHOST_NO_QUEUE all being > > 0? > > > > Perhaps we could instead use a generic naming: > > QPAIR_DEFAULT > QUEUE_FROM_GUEST(qpair) > QUEUE_TO_GUEST(qpair) ...but for non vhost-user we would have QUEUE_FROM_GUEST(QPAIR_DEFAULT) evaluating to 1 which isn't correct I guess? In general it looks reasonable to me, I would just like to make sure we avoid passing around a '0' in the non-vhost-user case which would look rather obscure. -- Stefano