examples/vhost: fix memory leak on forwarding packets.

Message ID 20210817171320.647414-1-wenwux.ma@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series examples/vhost: fix memory leak on forwarding packets. |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/iol-intel-Functional success Functional Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing fail Testing issues
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Ma, WenwuX Aug. 17, 2021, 5:13 p.m. UTC
  In function virtio_tx_local(), when the device receiving the packet
is the same as the device to which the packet is forwarded,
or the device is removed, we return but not free the packet,
it will cause a memory leak.

Fixes: 4796ad63ba1f ("examples/vhost: import userspace vhost application")
Cc: stable@dpdk.org

Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
---
 examples/vhost/main.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Jiang, Cheng1 Aug. 17, 2021, 5:26 a.m. UTC | #1
Acked-by: Cheng Jiang <cheng1.jiang@intel.com>




> -----Original Message-----
> From: Ma, WenwuX <wenwux.ma@intel.com>
> Sent: Wednesday, August 18, 2021 1:13 AM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>;
> Jiang, Cheng1 <cheng1.jiang@intel.com>; Hu, Jiayu <jiayu.hu@intel.com>;
> Ma, WenwuX <wenwux.ma@intel.com>; stable@dpdk.org
> Subject: [PATCH] examples/vhost: fix memory leak on forwarding packets.
> 
> In function virtio_tx_local(), when the device receiving the packet is the
> same as the device to which the packet is forwarded, or the device is
> removed, we return but not free the packet, it will cause a memory leak.
> 
> Fixes: 4796ad63ba1f ("examples/vhost: import userspace vhost application")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
> ---
>  examples/vhost/main.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/examples/vhost/main.c b/examples/vhost/main.c index
> bc3d71c898..07fd90ec64 100644
> --- a/examples/vhost/main.c
> +++ b/examples/vhost/main.c
> @@ -965,6 +965,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct
> rte_mbuf *m)
>  		return -1;
> 
>  	if (vdev->vid == dst_vdev->vid) {
> +		rte_pktmbuf_free(m);
>  		RTE_LOG_DP(DEBUG, VHOST_DATA,
>  			"(%d) TX: src and dst MAC is same. Dropping
> packet.\n",
>  			vdev->vid);
> @@ -975,6 +976,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct
> rte_mbuf *m)
>  		"(%d) TX: MAC address is local\n", dst_vdev->vid);
> 
>  	if (unlikely(dst_vdev->remove)) {
> +		rte_pktmbuf_free(m);
>  		RTE_LOG_DP(DEBUG, VHOST_DATA,
>  			"(%d) device is marked for removal\n", dst_vdev-
> >vid);
>  		return 0;
> --
> 2.25.1
  
Hu, Jiayu Aug. 17, 2021, 7:12 a.m. UTC | #2
Reviewed-by: Jiayu Hu <jiayu.hu@intel.com>

> -----Original Message-----
> From: Jiang, Cheng1 <cheng1.jiang@intel.com>
> Sent: Tuesday, August 17, 2021 1:26 PM
> To: Ma, WenwuX <wenwux.ma@intel.com>; dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>; Hu,
> Jiayu <jiayu.hu@intel.com>; stable@dpdk.org
> Subject: RE: [PATCH] examples/vhost: fix memory leak on forwarding packets.
> 
> Acked-by: Cheng Jiang <cheng1.jiang@intel.com>
> 
> 
> 
> 
> > -----Original Message-----
> > From: Ma, WenwuX <wenwux.ma@intel.com>
> > Sent: Wednesday, August 18, 2021 1:13 AM
> > To: dev@dpdk.org
> > Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>;
> > Jiang, Cheng1 <cheng1.jiang@intel.com>; Hu, Jiayu
> > <jiayu.hu@intel.com>; Ma, WenwuX <wenwux.ma@intel.com>;
> > stable@dpdk.org
> > Subject: [PATCH] examples/vhost: fix memory leak on forwarding packets.
> >
> > In function virtio_tx_local(), when the device receiving the packet is
> > the same as the device to which the packet is forwarded, or the device
> > is removed, we return but not free the packet, it will cause a memory leak.
> >
> > Fixes: 4796ad63ba1f ("examples/vhost: import userspace vhost
> > application")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
> > ---
> >  examples/vhost/main.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/examples/vhost/main.c b/examples/vhost/main.c index
> > bc3d71c898..07fd90ec64 100644
> > --- a/examples/vhost/main.c
> > +++ b/examples/vhost/main.c
> > @@ -965,6 +965,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct
> > rte_mbuf *m)
> >  		return -1;
> >
> >  	if (vdev->vid == dst_vdev->vid) {
> > +		rte_pktmbuf_free(m);
> >  		RTE_LOG_DP(DEBUG, VHOST_DATA,
> >  			"(%d) TX: src and dst MAC is same. Dropping
> packet.\n",
> >  			vdev->vid);
> > @@ -975,6 +976,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct
> > rte_mbuf *m)
> >  		"(%d) TX: MAC address is local\n", dst_vdev->vid);
> >
> >  	if (unlikely(dst_vdev->remove)) {
> > +		rte_pktmbuf_free(m);
> >  		RTE_LOG_DP(DEBUG, VHOST_DATA,
> >  			"(%d) device is marked for removal\n", dst_vdev-
> > >vid);
> >  		return 0;
> > --
> > 2.25.1
>
  
Chenbo Xia Aug. 26, 2021, 11:47 a.m. UTC | #3
> -----Original Message-----
> From: Ma, WenwuX <wenwux.ma@intel.com>
> Sent: Wednesday, August 18, 2021 1:13 AM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>; Jiang,
> Cheng1 <cheng1.jiang@intel.com>; Hu, Jiayu <jiayu.hu@intel.com>; Ma, WenwuX
> <wenwux.ma@intel.com>; stable@dpdk.org
> Subject: [PATCH] examples/vhost: fix memory leak on forwarding packets.

Should delete '.' in the title when applying.

With this fixed:

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>

> 
> In function virtio_tx_local(), when the device receiving the packet
> is the same as the device to which the packet is forwarded,
> or the device is removed, we return but not free the packet,
> it will cause a memory leak.
> 
> Fixes: 4796ad63ba1f ("examples/vhost: import userspace vhost application")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
> ---
>  examples/vhost/main.c | 2 ++
>  1 file changed, 2 insertions(+)
  

Patch

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index bc3d71c898..07fd90ec64 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -965,6 +965,7 @@  virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 		return -1;
 
 	if (vdev->vid == dst_vdev->vid) {
+		rte_pktmbuf_free(m);
 		RTE_LOG_DP(DEBUG, VHOST_DATA,
 			"(%d) TX: src and dst MAC is same. Dropping packet.\n",
 			vdev->vid);
@@ -975,6 +976,7 @@  virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 		"(%d) TX: MAC address is local\n", dst_vdev->vid);
 
 	if (unlikely(dst_vdev->remove)) {
+		rte_pktmbuf_free(m);
 		RTE_LOG_DP(DEBUG, VHOST_DATA,
 			"(%d) device is marked for removal\n", dst_vdev->vid);
 		return 0;