From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0153743C60 for ; Thu, 7 Mar 2024 02:35:03 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EEF1242EEA; Thu, 7 Mar 2024 02:35:02 +0100 (CET) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by mails.dpdk.org (Postfix) with ESMTP id 5163B42EE3 for ; Thu, 7 Mar 2024 02:35:00 +0100 (CET) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-412a9e9c776so9197565e9.0 for ; Wed, 06 Mar 2024 17:35:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709775300; x=1710380100; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PRfEwr/8OCShwxY8TPXBQmfGfj2TUYJLqxs6w+7q8zQ=; b=RK1B5jkQiIj5c2GVUYlFzDqTCaA8VelcWslKkbGcpSjei72rf1dsggWcqPqCi1h1Qh vR/ziN3p2eV9yPrwltw/gnLeA1e58fy2xvP8LJF7w4jjNkaQxYMy1Sjr8elq1z9bsPit t3bb0gVl/OEub2fbhC11XQ0FhFMVR7VNzIJCkUL1rmqTu4drVrpZ9Bh3HGjK67P22z2l gj/p0yo/ixtUVTcjSH7IJZNQ9yN5OQ7DrC5gHyJ4bU4ihIzrP3z3tXgDDxeIArHEufot bxzPLM+YjIDNIrv45s3l6Zw7+EURBuKT/IB2OV2a2yReYFE3RJJwymwG5yIwlE9i3KM8 U9mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709775300; x=1710380100; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PRfEwr/8OCShwxY8TPXBQmfGfj2TUYJLqxs6w+7q8zQ=; b=L1941XRb8eq6R5sUxkPq/Rw7jlsPxCCI085EPsekRIO/GrmlrH1Wj5wYcgsL3U/eYi X1XgKGd/KZo9PBC3cYjG3HrzT6o3LwvuiGC+58Gi849k5c/wTODJGrGP67mWVbTEYfkr IiGeAokGhK9BMkNrB60A/lh28Gh5V7rNty2bVLaFDf03bo2bB19oAaWWpwA4Kg9d3UGT gO6HSvNZSIL2JRHEGF19IWr3yefuGKlFL+JFe1yAQ2zxbqf2w3M15GzjVk1UaA3FTLGE O6oV/YZ8e6O9XJ2SABgmW9ywo0EMgR0SUx5g5Xp7bgADUx3+petIP6XHrNCXamaIY4zx 1O4w== X-Forwarded-Encrypted: i=1; AJvYcCVV/ofD5eNIPo/cx4U7QjOFItGVMnU8+AuTUbbDIj44NCvUnVBx+kbYkPcXSrgHfuIbgG1yJSUwJGgQJIGceNQ= X-Gm-Message-State: AOJu0Yywg0KpgZebRdBwy3bGjYaj91bpyzrMDtRGfMfszkzMwM8Y1Dgo WsMJl61PTE3pwmdIUlPcUV6V39g+EJCrNaVhqM7tTjdrkIx48lOtVrxFXJRw X-Google-Smtp-Source: AGHT+IHvydHxmHCv9o6pP+vdbZ2BaCrOfXtMpD94ijG76OJNXjvzeoNVinffZTEHcRP52ntVq8c8jg== X-Received: by 2002:adf:a384:0:b0:33e:5970:e045 with SMTP id l4-20020adfa384000000b0033e5970e045mr30700wrb.21.1709775299966; Wed, 06 Mar 2024 17:34:59 -0800 (PST) Received: from localhost ([137.220.120.171]) by smtp.gmail.com with ESMTPSA id co14-20020a0560000a0e00b0033e3ce48ba1sm9914961wrb.16.2024.03.06.17.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 17:34:59 -0800 (PST) From: luca.boccassi@gmail.com To: Maxime Coquelin Cc: David Marchand , dpdk stable Subject: patch 'vhost: fix memory leak in Virtio Tx split path' has been queued to stable release 22.11.5 Date: Thu, 7 Mar 2024 01:31:05 +0000 Message-Id: <20240307013159.1735343-48-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240307013159.1735343-1-luca.boccassi@gmail.com> References: <20240307013159.1735343-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 22.11.5 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 03/09/24. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/bluca/dpdk-stable This queued commit can be viewed at: https://github.com/bluca/dpdk-stable/commit/86389c2bd716fa26a08e279f4de4dd940f08a63e Thanks. Luca Boccassi --- >From 86389c2bd716fa26a08e279f4de4dd940f08a63e Mon Sep 17 00:00:00 2001 From: Maxime Coquelin Date: Wed, 31 Jan 2024 20:53:08 +0100 Subject: [PATCH] vhost: fix memory leak in Virtio Tx split path [ upstream commit 7746fba831509fdb4c528266d0b38a89566e01e5 ] When vIOMMU is enabled, rte_vhost_dequeue_burst() can return early because of IOTLB misses. Such IOTLB misses are especially frequent when a Virtio device is bound to a kernel driver in guest. This patch fixes a mbuf leak occurring in this case. Fixes: 242695f6122a ("vhost: allocate and free packets in bulk in Tx split") Signed-off-by: Maxime Coquelin Signed-off-by: David Marchand Reviewed-by: David Marchand --- lib/vhost/virtio_net.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 26f184f8b2..3061275753 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -2862,7 +2862,6 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, { uint16_t i; uint16_t avail_entries; - uint16_t dropped = 0; static bool allocerr_warned; /* @@ -2901,11 +2900,8 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, update_shadow_used_ring_split(vq, head_idx, 0); - if (unlikely(buf_len <= dev->vhost_hlen)) { - dropped += 1; - i++; + if (unlikely(buf_len <= dev->vhost_hlen)) break; - } buf_len -= dev->vhost_hlen; @@ -2922,8 +2918,6 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, buf_len, mbuf_pool->name); allocerr_warned = true; } - dropped += 1; - i++; break; } @@ -2934,27 +2928,21 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, VHOST_LOG_DATA(dev->ifname, ERR, "failed to copy desc to mbuf.\n"); allocerr_warned = true; } - dropped += 1; - i++; break; } - } - if (dropped) - rte_pktmbuf_free_bulk(&pkts[i - 1], count - i + 1); + if (unlikely(count != i)) + rte_pktmbuf_free_bulk(&pkts[i], count - i); - vq->last_avail_idx += i; - - do_data_copy_dequeue(vq); - if (unlikely(i < count)) - vq->shadow_used_idx = i; if (likely(vq->shadow_used_idx)) { + vq->last_avail_idx += vq->shadow_used_idx; + do_data_copy_dequeue(vq); flush_shadow_used_ring_split(dev, vq); vhost_vring_call_split(dev, vq); } - return (i - dropped); + return i; } __rte_noinline -- 2.39.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-03-07 01:05:39.020793922 +0000 +++ 0048-vhost-fix-memory-leak-in-Virtio-Tx-split-path.patch 2024-03-07 01:05:34.790939846 +0000 @@ -1 +1 @@ -From 7746fba831509fdb4c528266d0b38a89566e01e5 Mon Sep 17 00:00:00 2001 +From 86389c2bd716fa26a08e279f4de4dd940f08a63e Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 7746fba831509fdb4c528266d0b38a89566e01e5 ] + @@ -14 +15,0 @@ -Cc: stable@dpdk.org @@ -24 +25 @@ -index c738b7edc9..9951842b9f 100644 +index 26f184f8b2..3061275753 100644 @@ -27 +28 @@ -@@ -3104,7 +3104,6 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, +@@ -2862,7 +2862,6 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, @@ -35 +36 @@ -@@ -3143,11 +3142,8 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, +@@ -2901,11 +2900,8 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, @@ -48 +49 @@ -@@ -3164,8 +3160,6 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, +@@ -2922,8 +2918,6 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, @@ -57,2 +58,2 @@ -@@ -3176,27 +3170,21 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, - VHOST_DATA_LOG(dev->ifname, ERR, "failed to copy desc to mbuf."); +@@ -2934,27 +2928,21 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, + VHOST_LOG_DATA(dev->ifname, ERR, "failed to copy desc to mbuf.\n");