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=W/vO0+WI; 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 9A35B5A026F for ; Wed, 15 Jan 2025 23:33:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736980390; 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=OX/hNulWoPqgModLbdb4cM+y0pmQT8/S+fyzDirpymI=; b=W/vO0+WIvmoQcLaoHCQLe/ms1u3WK/IwBX8V/szp16GvJFXCFHOWQcmUi3W1t7roDGi9/B aV1YUxe5DuhLbRNc1q/XWDV/QkKbrZCBYwhlu5epWDWQuT/wbVLCLQ9afpqqpdLrvh/RNV oMypRfaqapyP6wZp+kzwHbmCt1AOdPE= 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-532-gd8zSkZmPSauY3InzZ6SRw-1; Wed, 15 Jan 2025 17:33:09 -0500 X-MC-Unique: gd8zSkZmPSauY3InzZ6SRw-1 X-Mimecast-MFC-AGG-ID: gd8zSkZmPSauY3InzZ6SRw Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4359206e1e4so1330445e9.2 for ; Wed, 15 Jan 2025 14:33:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736980386; x=1737585186; 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=OX/hNulWoPqgModLbdb4cM+y0pmQT8/S+fyzDirpymI=; b=ih4myWVKSh9Z2J27RiTjomzrP8I8aNedkQn+WXFzCo7EaiRYTOwbO6ySaF58YCBq9O hYd3pK8zEMPUP8JY1C9lBmqmLA/bmWusgjrRB100RsJScLhKjeSyO7IluTHVGs8jbZg/ Ec+NyUoli761gl8mZQzQ+yZXoEKusVqBTC5ZmKiaJjEd58og8qshBc+rqjuuFShSSgpR 442df3syABRtaLFO1w816reogJPbKAvzaSCyUxB3hQUBrjXF6yD+/xO25Xwx2u0lE1EP nBrr/Etn+a7jFxlrkasCHfJ5NAAZxccoxUkkxTK97K0uZAdoCCY2kJrnlUvlewKtKblL miYg== X-Gm-Message-State: AOJu0YyhD+QDdQdgEA4juOEXJvL++7tIR1fa+W9aCsJXmZTX0lQK/5ny dtzfoQEyHF1tiaI7lSV7CT+a+s0uP/rLaf/3eeAUNZju9FUfYLfWsIvgd5jN2QBiS3765yBXpe4 Hau9ahv32G50rUvZuTSBIKA3x6AFfr/0rU4toZr4+gYaTCLRXAUuWE4EJvkAqt4Srm2zJx81CwF 7NFIuVclHS7kJG+N6NzWW4lEE9u3PLodL5 X-Gm-Gg: ASbGncttYSLLs0ZJpEmP6GN4Q83dRDBAk+y8Hgs+geulqkaT4l/QlASkIubNgl3S5lw LYASQNQN4mKdo0jiZFkteMM+GdLGhP2Bi+vuHSxS1THx9LpCrIqsoEtNNIvacQvzHSmMfHImEvy 19lZLK6VieDcGysKh0hUyO03bJRYPmSyARRTI8o/W9Xm/JfAXxSa/J7EJow3NYob8W1hBC4iFuy 09ZIJu72/cmdR6TE3dqcFi06+bx4z1vNn/kOZ7v8PZHl6kjeyqb+7qs3DS2clajOQys X-Received: by 2002:a05:600c:a0a:b0:434:a04d:1670 with SMTP id 5b1f17b1804b1-436e25548e3mr197308465e9.0.1736980386310; Wed, 15 Jan 2025 14:33:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPRT1v/+J8ziFFepvGk7R0Y5P26Mostg/RvuGkXdi924Cr6lmgWJVjrpsJV0xxpGVV3BFqOg== X-Received: by 2002:a05:600c:a0a:b0:434:a04d:1670 with SMTP id 5b1f17b1804b1-436e25548e3mr197308295e9.0.1736980385899; Wed, 15 Jan 2025 14:33:05 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a8e38ef6asm19175486f8f.60.2025.01.15.14.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 14:33:05 -0800 (PST) Date: Wed, 15 Jan 2025 23:33:02 +0100 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH] vhost_user: fix multibuffer from linux Message-ID: <20250115233302.23b24862@elisabeth> In-Reply-To: <20250115162230.813861-1-lvivier@redhat.com> References: <20250115162230.813861-1-lvivier@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-MFC-PROC-ID: mZcMxpMDH0AJepAt7xUkOYmE-czpYUjPcZBCUQGZmyY_1736980388 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 6LZZMRD6FBDZNWOHKY2RSKEHNNG6E3N7 X-Message-ID-Hash: 6LZZMRD6FBDZNWOHKY2RSKEHNNG6E3N7 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, 15 Jan 2025 17:22:30 +0100 Laurent Vivier wrote: > Under some conditions, linux can provide several buffers > in the same element (multiple entries in the iovec array). > > I didn't identify what changed between the kernel guest that > provides one buffer and the one that provides several > (doesn't seem to be a kernel change or a configuration change). Perhaps memory pressure, or different page accounting between kernels? > Fix the following assert: > > ASSERTION FAILED in virtqueue_map_desc (virtio.c:402): num_sg < max_num_sg > > What I can see is the buffer can be splitted in two iovecs: > - vnet header > - packet data > > This change manages this special case but the real fix will be to allow > tap_add_packet() to manage iovec array. > > Signed-off-by: Laurent Vivier Applied. I just wonder, if it makes sense as a follow-up: > --- > vu_common.c | 28 ++++++++++++++++++++++------ > 1 file changed, 22 insertions(+), 6 deletions(-) > > diff --git a/vu_common.c b/vu_common.c > index 6d365bea5fe2..431fba6be0c0 100644 > --- a/vu_common.c > +++ b/vu_common.c > @@ -18,6 +18,8 @@ > #include "pcap.h" > #include "vu_common.h" > > +#define VU_MAX_TX_BUFFER_NB 2 > + > /** > * vu_packet_check_range() - Check if a given memory zone is contained in > * a mapped guest memory region > @@ -168,10 +170,15 @@ static void vu_handle_tx(struct vu_dev *vdev, int index, > > count = 0; > out_sg_count = 0; > - while (count < VIRTQUEUE_MAX_SIZE) { > + while (count < VIRTQUEUE_MAX_SIZE && > + out_sg_count + VU_MAX_TX_BUFFER_NB <= VIRTQUEUE_MAX_SIZE) { > int ret; > > - vu_set_element(&elem[count], &out_sg[out_sg_count], NULL); > + elem[count].out_num = VU_MAX_TX_BUFFER_NB; > + elem[count].out_sg = &out_sg[out_sg_count]; > + elem[count].in_num = 0; > + elem[count].in_sg = NULL; > + > ret = vu_queue_pop(vdev, vq, &elem[count]); > if (ret < 0) > break; > @@ -181,11 +188,20 @@ static void vu_handle_tx(struct vu_dev *vdev, int index, > warn("virtio-net transmit queue contains no out buffers"); > break; > } > - ASSERT(elem[count].out_num == 1); > + if (elem[count].out_num == 1) { > + tap_add_packet(vdev->context, > + elem[count].out_sg[0].iov_len - hdrlen, > + (char *)elem[count].out_sg[0].iov_base + > + hdrlen); > + } else { > + /* vnet header can be in a separate iovec */ > + ASSERT(elem[count].out_num == 2); I suppose we don't have strong guarantees about this. What about discarding the packet with a debug() message, at least until we have a more elegant solution, if this happens? For UDP and ICMP, that's the best thing we can do. For TCP, we could just discard a part of it, and the peer would tell our guest, but it's surely not practical to look into the packet here, so dropping it altogether would look reasonable. > + ASSERT(elem[count].out_sg[0].iov_len == (size_t)hdrlen); And similarly here (with an err() message), even though there's probably an issue in the hypervisor if this happens, but it doesn't mean we're doomed. > + tap_add_packet(vdev->context, > + elem[count].out_sg[1].iov_len, > + (char *)elem[count].out_sg[1].iov_base); > + } > > - tap_add_packet(vdev->context, > - elem[count].out_sg[0].iov_len - hdrlen, > - (char *)elem[count].out_sg[0].iov_base + hdrlen); > count++; > } > tap_handler(vdev->context, now); -- Stefano