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 AA18C46211 for ; Thu, 13 Feb 2025 11:01:53 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9E36B42EFA; Thu, 13 Feb 2025 11:01:53 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 4BBAD42EEC for ; Thu, 13 Feb 2025 11:01:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739440911; 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=r3Cggprk4MoYvXxEKRSbfjXBrFW6GqyO5y4UhJJzRmw=; b=V6CjzCPzO6e2tnx5y7yUqX6vS/QfsyGbFMI6/nV/TO3KDqd+WzEJixJ3LlTWBG0k9xRS37 e4TeJ3G9BV7ze1/UKYNmzYfrf7u7a2LBI3e1DtVJAUdavQUq7oqFy6An74NkWHV6SBcJ/y CxJlPpYNxaJUdBwIZOLIVTjONFyAioQ= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-5YtCmnyvMjSOs2Mrz1MeRg-1; Thu, 13 Feb 2025 05:01:49 -0500 X-MC-Unique: 5YtCmnyvMjSOs2Mrz1MeRg-1 X-Mimecast-MFC-AGG-ID: 5YtCmnyvMjSOs2Mrz1MeRg Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1CFF71800373; Thu, 13 Feb 2025 10:01:49 +0000 (UTC) Received: from rh.Home (unknown [10.45.224.21]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D34871800360; Thu, 13 Feb 2025 10:01:47 +0000 (UTC) From: Kevin Traynor To: Tudor Cornea Cc: dpdk stable Subject: patch 'net/af_packet: fix socket close on device stop' has been queued to stable release 24.11.2 Date: Thu, 13 Feb 2025 09:58:22 +0000 Message-ID: <20250213095933.362078-55-ktraynor@redhat.com> In-Reply-To: <20250213095933.362078-1-ktraynor@redhat.com> References: <20250213095933.362078-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: z8Layji7bcNcDKACWbUyMdJXiUTNy29pwp_oUKjlsIM_1739440909 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 24.11.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 02/17/25. 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/kevintraynor/dpdk-stable This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable/commit/685ac1bd0c5605629c3a7012307eb8d4151b6564 Thanks. Kevin --- >From 685ac1bd0c5605629c3a7012307eb8d4151b6564 Mon Sep 17 00:00:00 2001 From: Tudor Cornea Date: Tue, 4 Feb 2025 18:45:08 +0200 Subject: [PATCH] net/af_packet: fix socket close on device stop [ upstream commit 872e846f6bb31afbdd508903380cf05a3d313a3a ] Currently, if we call rte_eth_dev_stop(), the sockets are closed. If we attempt to start the port again, socket related operations will not work correctly. This can be alleviated by closing the socket at the same place in which we currently free the memory, in eth_dev_close(). If an application calls rte_eth_dev_stop() on a port managed by the af_packet PMD, the port becomes unusable. This is in contrast with ports managed by other drivers (e.g virtio). I also managed to reproduce the issue using testpmd. sudo ip link add test-veth0 type veth peer name test-veth1 sudo ip link set test-veth0 up sudo ip link set test-veth1 up AF_PACKET_ARGS=\ "blocksz=4096,framesz=2048,framecnt=512,qpairs=1,qdisc_bypass=0" sudo ./dpdk-testpmd \ -l 0-3 \ -m 1024 \ --no-huge \ --no-shconf \ --no-pci \ --vdev=net_af_packet0,iface=test-veth0,${AF_PACKET_ARGS} \ --vdev=net_af_packet1,iface=test-veth1,${AF_PACKET_ARGS} \ -- \ -i testpmd> start tx_first Forwarding will start, and we will see traffic on the interfaces. testpmd> stop testpmd> port stop 0 Stopping ports... Checking link statuses... Done testpmd> port stop 1 Stopping ports... Checking link statuses... Done testpmd> port start 0 AFPACKET: eth_dev_macaddr_set(): receive socket not found Port 0: CA:65:81:63:81:B2 Checking link statuses... Done testpmd> port start 1 AFPACKET: eth_dev_macaddr_set(): receive socket not found Port 1: CA:12:D0:BE:93:3F Checking link statuses... Done testpmd> start tx_first When we start forwarding again, we can see that there is no traffic on the interfaces. This does not happen when testing with other PMD drivers (e.g virtio). With the patch, the port should re-initialize correctly. testpmd> port start 0 Port 0: CA:65:81:63:81:B2 Checking link statuses... Done Fixes: 364e08f2bbc0 ("af_packet: add PMD for AF_PACKET-based virtual devices") Signed-off-by: Tudor Cornea --- drivers/net/af_packet/rte_eth_af_packet.c | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index ceb8d9356a..efae15a493 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -358,25 +358,10 @@ eth_dev_stop(struct rte_eth_dev *dev) { unsigned i; - int sockfd; struct pmd_internals *internals = dev->data->dev_private; for (i = 0; i < internals->nb_queues; i++) { - sockfd = internals->rx_queue[i].sockfd; - if (sockfd != -1) - close(sockfd); - - /* Prevent use after free in case tx fd == rx fd */ - if (sockfd != internals->tx_queue[i].sockfd) { - sockfd = internals->tx_queue[i].sockfd; - if (sockfd != -1) - close(sockfd); - } - - internals->rx_queue[i].sockfd = -1; - internals->tx_queue[i].sockfd = -1; dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED; dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED; } - dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN; return 0; @@ -475,4 +460,5 @@ eth_dev_close(struct rte_eth_dev *dev) struct tpacket_req *req; unsigned int q; + int sockfd; if (rte_eal_process_type() != RTE_PROC_PRIMARY) @@ -485,4 +471,18 @@ eth_dev_close(struct rte_eth_dev *dev) req = &internals->req; for (q = 0; q < internals->nb_queues; q++) { + sockfd = internals->rx_queue[q].sockfd; + if (sockfd != -1) + close(sockfd); + + /* Prevent use after free in case tx fd == rx fd */ + if (sockfd != internals->tx_queue[q].sockfd) { + sockfd = internals->tx_queue[q].sockfd; + if (sockfd != -1) + close(sockfd); + } + + internals->rx_queue[q].sockfd = -1; + internals->tx_queue[q].sockfd = -1; + munmap(internals->rx_queue[q].map, 2 * req->tp_block_size * req->tp_block_nr); -- 2.48.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2025-02-12 17:29:40.370960153 +0000 +++ 0055-net-af_packet-fix-socket-close-on-device-stop.patch 2025-02-12 17:29:34.361945995 +0000 @@ -1 +1 @@ -From 872e846f6bb31afbdd508903380cf05a3d313a3a Mon Sep 17 00:00:00 2001 +From 685ac1bd0c5605629c3a7012307eb8d4151b6564 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 872e846f6bb31afbdd508903380cf05a3d313a3a ] + @@ -77 +78,0 @@ -Cc: stable@dpdk.org @@ -85 +86 @@ -index 7fcd27ee0c..ab34285ed9 100644 +index ceb8d9356a..efae15a493 100644 @@ -88 +89 @@ -@@ -364,25 +364,10 @@ eth_dev_stop(struct rte_eth_dev *dev) +@@ -358,25 +358,10 @@ eth_dev_stop(struct rte_eth_dev *dev) @@ -114 +115 @@ -@@ -511,4 +496,5 @@ eth_dev_close(struct rte_eth_dev *dev) +@@ -475,4 +460,5 @@ eth_dev_close(struct rte_eth_dev *dev) @@ -120 +121 @@ -@@ -521,4 +507,18 @@ eth_dev_close(struct rte_eth_dev *dev) +@@ -485,4 +471,18 @@ eth_dev_close(struct rte_eth_dev *dev)