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 2F0B64624E for ; Mon, 17 Feb 2025 18:06:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 21FEC402AB; Mon, 17 Feb 2025 18:06:11 +0100 (CET) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by mails.dpdk.org (Postfix) with ESMTP id EB244402C6 for ; Mon, 17 Feb 2025 18:06:09 +0100 (CET) Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-38f2c4382d1so1824770f8f.0 for ; Mon, 17 Feb 2025 09:06:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739811969; x=1740416769; 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=bT9lUknDWe6vEMw+vZcvO9F6fqoAs0CtrvyoZRlN7LI=; b=Gh1SULle2dYTjWumsPlbAesaX3E3KEZ4zPyZcnGu5+g3l1aIkg/3kdvr90UrmRs0HY rlFR0ORVSmQrqWeUpJpy9N99eACAM7TKtokdYXBXMIQ6pOOVR3THZW5iLO1IAFFogV9Z s+rhGdbOGgBRkOA/m/jZ+9DAL5CYmFCA4BFbsc+EUbtpwYd6PLbRdSJyYl4mCIWOA5l/ ngTprYFxgQ57Y4yVbkJ8aeUb5otFTfk+84B93MOeuIrB3kVyGDCDh2L/AyOSqVB1HyIc TMda6KtBG4qbpAFXimA4dsGPHPVKgjvJXvCqG/xRr1G/zzdRlhOmwxhwWblUz8QvbmoD Gikg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739811969; x=1740416769; 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=bT9lUknDWe6vEMw+vZcvO9F6fqoAs0CtrvyoZRlN7LI=; b=dJg0M5ykXDb/jXpXDROYtLYCJC1wYGTxhuW0m6JroNPqLENme5xVUAdG4RHJcBprsd V6HAVwaJ4qdcK4j1vUSn7gw8WaQVUE/qzGavmbdyLFSXxOggYSigUqnbPimKhPwlwCSw 2CWavbDm1JDmTCkvaKG+18n9IRnmR/uYSa4h0MmfOMHrXpKT4nUeOpC/4v0Vsfhsifcb Pfl9dMA9JV6DUQv00VhT7Y9Qa3a5G7W/vmlyn9JhWYU5onjd9zWMB9vn0TaIfuaADbh9 k9iV58YODTgePP2EmF5JmvMiVI5lmFnN7fbrwPqo+7r6mKZZ/9imOPST/gc1CcF3mWYJ hNUg== X-Gm-Message-State: AOJu0Yxw4NNrIw2q70PdzaD1zeiccXNGCJo3ASe7EEaGQ2xg6LNxa0/j ndSrqQVvzi416Eggn1eRdx3JMibK8lEOhDS7aoGCVewbZKYewrfj X-Gm-Gg: ASbGncuo45fA3nYOSS1cBR1Ibb8mYqB9uFc8SKOhx1yi7+d6ssWljEhmJQ+mgyiOxjZ F3BeaUtdbS2Nd0usq2Ki2TBHIfVanLR4C4DMco74YGL/321JvFZFc9tDaF879pZyjQn0m7maGWx zjib+JtK+mAYxRWSNxyrQjNR5upRCe+RObU7O7yjS5z83lxKFclHf5WlklgwhpPNr7EWLGUNer2 2JV09um+JE3v1saVo6gb9BpGVAX1aLiF8M0TnFOaO8WZUG1wTKdr6tmjhvSsTcSWPSejg6IDvpY QMzFD8Z4Oz8SqPzd3WV5yQ== X-Google-Smtp-Source: AGHT+IFM4QF+JT0fUmmShFwluxEsrG2KnCfJ/Zc5eE+09VyRA1iQ6qsA8AqoqEVK74gJR6b12TB99A== X-Received: by 2002:a05:6000:1fae:b0:38f:3aae:830b with SMTP id ffacd0b85a97d-38f3aafb43bmr7648932f8f.26.1739811969174; Mon, 17 Feb 2025 09:06:09 -0800 (PST) Received: from localhost ([2a01:4b00:d036:ae00:f83c:95e7:29fd:a997]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38f259f7fe6sm12543174f8f.86.2025.02.17.09.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 09:06:08 -0800 (PST) From: luca.boccassi@gmail.com To: Tudor Cornea Cc: dpdk stable Subject: patch 'net/af_packet: fix socket close on device stop' has been queued to stable release 22.11.8 Date: Mon, 17 Feb 2025 17:03:57 +0000 Message-ID: <20250217170456.1068278-24-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250217170456.1068278-1-luca.boccassi@gmail.com> References: <20250217170456.1068278-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.8 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/19/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/bluca/dpdk-stable This queued commit can be viewed at: https://github.com/bluca/dpdk-stable/commit/9c3d54e8aa2e8e66bbc5326028e0776631a42411 Thanks. Luca Boccassi --- >From 9c3d54e8aa2e8e66bbc5326028e0776631a42411 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 6b7b16f348..0b059bfd0b 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -332,27 +332,12 @@ static int 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; } @@ -447,6 +432,7 @@ eth_dev_close(struct rte_eth_dev *dev) struct pmd_internals *internals; struct tpacket_req *req; unsigned int q; + int sockfd; if (rte_eal_process_type() != RTE_PROC_PRIMARY) return 0; @@ -457,6 +443,20 @@ eth_dev_close(struct rte_eth_dev *dev) internals = dev->data->dev_private; 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); rte_free(internals->rx_queue[q].rd); -- 2.47.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2025-02-17 16:13:17.717898277 +0000 +++ 0024-net-af_packet-fix-socket-close-on-device-stop.patch 2025-02-17 16:13:16.806441593 +0000 @@ -1 +1 @@ -From 872e846f6bb31afbdd508903380cf05a3d313a3a Mon Sep 17 00:00:00 2001 +From 9c3d54e8aa2e8e66bbc5326028e0776631a42411 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 6b7b16f348..0b059bfd0b 100644 @@ -88 +89 @@ -@@ -363,27 +363,12 @@ static int +@@ -332,27 +332,12 @@ static int @@ -116 +117 @@ -@@ -510,6 +495,7 @@ eth_dev_close(struct rte_eth_dev *dev) +@@ -447,6 +432,7 @@ eth_dev_close(struct rte_eth_dev *dev) @@ -124 +125 @@ -@@ -520,6 +506,20 @@ eth_dev_close(struct rte_eth_dev *dev) +@@ -457,6 +443,20 @@ eth_dev_close(struct rte_eth_dev *dev)