From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none 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=bi9xOjNb; 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 ESMTP id 7AB1C5A004E for ; Thu, 12 Sep 2024 15:40:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726148445; 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=HJsukaCFKK3t1S2GZGNRI6C+evZZwpQFSdWda5NkfaU=; b=bi9xOjNbyzzoj7TAcHBQvvoEv0m0w/cdD9z5WcS1yuhtPjgmx9+t8zoyjhkDvnB+Ap1SwP 2ERzqtL6IGI9ycNO/JxXdNxtcvX5RDySaPEMHFwHinOxc94u8Ut+AbrFmZ7PtzWVUYTkjl HgyIo6VeUJmLWxmk/CGfKgLO60CXrL4= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-475-M236YLlCN4mKjnFJG3EZug-1; Thu, 12 Sep 2024 09:40:44 -0400 X-MC-Unique: M236YLlCN4mKjnFJG3EZug-1 Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-72c1d0fafb3so836281a12.2 for ; Thu, 12 Sep 2024 06:40:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726148441; x=1726753241; 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=HJsukaCFKK3t1S2GZGNRI6C+evZZwpQFSdWda5NkfaU=; b=e1nLRdBpl1uX/3NmR6/RauSIGCu8GoOwHINDM4TPz/ZT8GM7a/MZZLWgGSJNXUTc1b rrPYAkACHRmzsqAGSA70aKm4exi2AW+xTwtdkTS6/zNEQykK8sktMRN2Zasy1+0TlhJY aqdx9qZ075skWutCiDzQKUZJ2Ndl6HAp1//H4GEvk9/BGjCy3MAC+PJa06ldOL4g8gX4 1RyZmAr9DBJmtR9Sl4/b2ceuVlLHDQNBz+UhKMGWb2O/FVaJkM9kFxKOzHBj/Zv/giIK GfL0u2UF2YZBXr4Oum0Tm4BzKBysdP4Q25MjMY35ASSAwISXRhkS8N0mW0C1fZfyH4oQ hmBQ== X-Gm-Message-State: AOJu0YwhIb2p6NGPV6DbkMT+dHaxXsqo+s13aX9iY0qAVBen3qn2MC4/ dyWsqJPhnZLDKOv+rA3VwGuw5Fp2SV0ZiTwKkH2vLTiC2Tv6gFFvmOPo1XJoPSrxUe+6nI9Xe4h wosmY4wCKLlYmltKMTrjZ2Bs/ZucB5k2WFH6+hFtbNFV1bCiYUBjc89LtGbMC2yX7CUZyPsvtJq omaXY43AMZSvTLJYtBYA483YerUGNXS4V+ X-Received: by 2002:a05:6a21:3a41:b0:1cf:5b31:313a with SMTP id adf61e73a8af0-1cf75c7e923mr4003783637.1.1726148440726; Thu, 12 Sep 2024 06:40:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5G9/pWqYOVrf30j1M58fjm/joLC7ry2/QhjLFpB3RS5ApY7g7YwpGKltH2+SmlMKdns6BUg== X-Received: by 2002:a05:6a21:3a41:b0:1cf:5b31:313a with SMTP id adf61e73a8af0-1cf75c7e923mr4003734637.1.1726148439979; Thu, 12 Sep 2024 06:40:39 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-719090c72f9sm4598325b3a.196.2024.09.12.06.40.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 06:40:38 -0700 (PDT) Date: Thu, 12 Sep 2024 15:40:35 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v4 3/4] vhost-user: introduce vhost-user API Message-ID: <20240912154035.78de6334@elisabeth> In-Reply-To: <2a0d56e9-9c7d-4f22-bc61-4177d69032ae@redhat.com> References: <20240906160455.2088854-1-lvivier@redhat.com> <20240906160455.2088854-4-lvivier@redhat.com> <20240910174735.1e80713c@elisabeth> <2a0d56e9-9c7d-4f22-bc61-4177d69032ae@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: JXNFK3GUEGGDIVILEFPEPL7JHTR3M5LS X-Message-ID-Hash: JXNFK3GUEGGDIVILEFPEPL7JHTR3M5LS 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, 12 Sep 2024 14:41:53 +0200 Laurent Vivier wrote: > On 10/09/2024 17:47, Stefano Brivio wrote: > > Nits and a couple of questions only: > > > > On Fri, 6 Sep 2024 18:04:48 +0200 > > Laurent Vivier wrote: > > > >> Add vhost_user.c and vhost_user.h that define the functions needed > >> to implement vhost-user backend. > >> > >> Signed-off-by: Laurent Vivier > >> --- > >> Makefile | 4 +- > >> iov.c | 1 - > >> vhost_user.c | 1265 ++++++++++++++++++++++++++++++++++++++++++++++++++ > >> vhost_user.h | 203 ++++++++ > >> virtio.c | 5 - > >> virtio.h | 2 +- > >> 6 files changed, 1471 insertions(+), 9 deletions(-) > >> create mode 100644 vhost_user.c > >> create mode 100644 vhost_user.h > ... > >> diff --git a/vhost_user.c b/vhost_user.c > >> new file mode 100644 > >> index 000000000000..6008a8adc967 > >> --- /dev/null > >> +++ b/vhost_user.c > ... > >> +/** > >> + * vu_wait_queue() - wait for new free entries in the virtqueue > >> + * @vq: virtqueue to wait on > >> + */ > >> +static int vu_wait_queue(const struct vu_virtq *vq) > >> +{ > >> + eventfd_t kick_data; > >> + ssize_t rc; > >> + int status; > >> + > >> + /* wait for the kernel to put new entries in the queue */ > >> + status = fcntl(vq->kick_fd, F_GETFL); > >> + if (status == -1) > >> + return -1; > > > > Same as on v3 (I see you changed this below, but not here): if you > > don't use status later, you can omit storing it. > > We need status with F_SETFL below: Oops, sorry, of course! > >> + > >> + if (fcntl(vq->kick_fd, F_SETFL, status & ~O_NONBLOCK)) > >> + return -1; > >> + > >> + rc = eventfd_read(vq->kick_fd, &kick_data); > >> + > >> + if (fcntl(vq->kick_fd, F_SETFL, status)) > >> + return -1; > >> + > >> + if (rc == -1) > >> + return -1; > >> + > >> + return 0; > >> +} > ... > >> +/** > >> + * vu_handle_tx() - Receive data from the TX virtqueue > >> + * @vdev: vhost-user device > >> + * @index: index of the virtqueue > >> + * @now: Current timestamp > >> + */ > >> +static void vu_handle_tx(struct vu_dev *vdev, int index, > >> + const struct timespec *now) > >> +{ > >> + struct vu_virtq_element elem[VIRTQUEUE_MAX_SIZE]; > >> + struct iovec out_sg[VIRTQUEUE_MAX_SIZE]; > >> + struct vu_virtq *vq = &vdev->vq[index]; > >> + int hdrlen = vdev->hdrlen; > >> + int out_sg_count; > >> + int count; > >> + > > > > Excess newline (same as v3). > > Done. > > > > >> + > >> + if (!VHOST_USER_IS_QUEUE_TX(index)) { > >> + debug("vhost-user: index %d is not a TX queue", index); > >> + return; > >> + } > >> + > >> + tap_flush_pools(); > >> + > >> + count = 0; > >> + out_sg_count = 0; > >> + while (count < VIRTQUEUE_MAX_SIZE) { > > > > So, I see that this is limited to 1024 iterations now (it was limited > > also earlier, but I didn't realise that). > > > > If we loop at most VIRTQUEUE_MAX_SIZE times, that means, I guess, that > > while we're popping elements, the queue can't be written to, correct? > > No, I think the queue can be read and write at the same time. > > > Or it can be written to, but we'll get an additional kick after > > vu_queue_notify() if that happens? > > I could check the protocol and the code, but I think it should work like that. Well, okay, it should be obvious enough. -- Stefano