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 9F597A00C5 for ; Tue, 29 Nov 2022 16:25:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9620542B8C; Tue, 29 Nov 2022 16:25:28 +0100 (CET) Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by mails.dpdk.org (Postfix) with ESMTP id 02B9940A79; Tue, 29 Nov 2022 16:25:27 +0100 (CET) Received: by mail-qv1-f47.google.com with SMTP id u10so4320190qvp.4; Tue, 29 Nov 2022 07:25:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=x65RBFLYFeugknTlnHkP1QebxJ/q7Kwtp/HyVMorJTQ=; b=o6UvgukpSxLf9LAG9F1RHRvx4d3E0lyczuSoETf1cCFinIsDewWDL2PuqQemWr3wAA 8F+zwBFN+0NUUvn4BKp82A3qVSpeMORex1m2Eo1MgcKeEkZOzkdouTMBExIzqsHqflOF M9C3IamW5e6Xf1ZzyWLassSMkSfGNj8kmt5ZPwdnCzVkbh6a76HiW600ismc5a/mqvp6 TF498lUuJd0YNCShGW3e/7tDuzNdOjytxJKM5FCVoU47sCgvfne4/jjcuwLafZd03j96 CySWn5/ArryNtrE8/MynJLx7hbxuzMyQJC1t/PkLJsCFY/lNjsfizN2TpZu1Gq+a6R9T XqLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=x65RBFLYFeugknTlnHkP1QebxJ/q7Kwtp/HyVMorJTQ=; b=wAvpjXGWoTugkak1kxk+xCY0aY9Kgm9mr37nA4hH/wRM1IQY0wG5SFSTwHpqpCWjk/ gBdvzn4NsROWDU6QB3wvsz0u2ca3akJlm6stOvoNLZzNYfq9FGTPGzOVDimiHFCSr8JI F8vLwbkWz38xklNHY636ptwJc3eP0iaKQx5tWRYQwXQOwI1i98oyb2ktQXLJfyKNQhzz NhvWPCwkUjGf16gpCiB6F1dkmCn2OSAWrzmfXTqQrrFSQKqDH8TcrthXqoqWyF2p81pK 7BDuDgPU343zegG3+OLNPAFQTBgYMqLVnoCjVgLu3zKCeGe81GoYmg4z5CVh7ykvxnip gLhw== X-Gm-Message-State: ANoB5pkbyAU3q2Nr1chR/rduvYmJuB9z70uV3MaMBjOa7pqS5IfKT90h 7XDa4oeSLrwluNljLtTDyl8= X-Google-Smtp-Source: AA0mqf6r9G1CMClwyYlWqdO2fu4Wi688uXn0AESuDvkOEK1FKlSF2mjBeW6WncspfH9/RhJHuxOrHw== X-Received: by 2002:a0c:bf41:0:b0:4c6:23d0:c340 with SMTP id b1-20020a0cbf41000000b004c623d0c340mr34281879qvj.66.1669735527247; Tue, 29 Nov 2022 07:25:27 -0800 (PST) Received: from ubuntu.home (bras-base-hullpq2034w-grc-26-74-12-221-152.dsl.bell.ca. [74.12.221.152]) by smtp.gmail.com with ESMTPSA id r2-20020ae9d602000000b006fb11eee465sm10663412qkk.64.2022.11.29.07.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 07:25:26 -0800 (PST) From: Luc Pelletier To: grive@u256.net Cc: dev@dpdk.org, stephen@networkplumber.org, konstantin.ananyev@huawei.com, Luc Pelletier , stable@dpdk.org Subject: [PATCH v4 1/5] failsafe: fix segfault on hotplug event Date: Tue, 29 Nov 2022 10:25:13 -0500 Message-Id: <20221129152516.4513-2-lucp.at.work@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221110163410.12734-1-lucp.at.work@gmail.com> References: <20221110163410.12734-1-lucp.at.work@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 When the failsafe PMD encounters a hotplug event, it switches its rx/tx functions to "safe" ones that validate the sub-device's rx/tx functions before calling them. It switches the rx/tx functions by changing the function pointers in the rte_eth_dev structure. Following commit 7a0935239b9e, the rx/tx functions of PMDs are no longer called through the function pointers in the rte_eth_dev structure. They are rather called through a flat array named rte_eth_fp_ops. The function pointers in that array are initialized when the devices start and are initialized. When a hotplug event occurs, the function pointers in rte_eth_fp_ops still point to the "unsafe" rx/tx functions in the failsafe PMD since they haven't been updated. This results in a segmentation fault because it ends up using the "unsafe" functions, when the "safe" functions should have been used. To fix the problem, the "unsafe" rx/tx functions were completely removed. The "safe" functions are now always used. Modifying the rx/tx functions on-the-fly is not supported by DPDK, so this is the correct approach and should have very minimal impact on performance. Fixes: 7a0935239b9e ("ethdev: make fast-path functions to use new flat array") Cc: Konstantin Ananyev Cc: stable@dpdk.org Signed-off-by: Luc Pelletier --- drivers/net/failsafe/failsafe_ether.c | 2 - drivers/net/failsafe/failsafe_private.h | 8 --- drivers/net/failsafe/failsafe_rxtx.c | 83 +------------------------ 3 files changed, 1 insertion(+), 92 deletions(-) diff --git a/drivers/net/failsafe/failsafe_ether.c b/drivers/net/failsafe/failsafe_ether.c index 10b90fd837..517126565f 100644 --- a/drivers/net/failsafe/failsafe_ether.c +++ b/drivers/net/failsafe/failsafe_ether.c @@ -595,8 +595,6 @@ failsafe_eth_rmv_event_callback(uint16_t port_id __rte_unused, fs_lock(fs_dev(sdev), 0); /* Switch as soon as possible tx_dev. */ fs_switch_dev(fs_dev(sdev), sdev); - /* Use safe bursts in any case. */ - failsafe_set_burst_fn(fs_dev(sdev), 1); /* * Async removal, the sub-PMD will try to unregister * the callback at the source of the current thread context. diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h index 53a451c1b1..3865f2fc34 100644 --- a/drivers/net/failsafe/failsafe_private.h +++ b/drivers/net/failsafe/failsafe_private.h @@ -208,18 +208,11 @@ int failsafe_hotplug_alarm_cancel(struct rte_eth_dev *dev); /* RX / TX */ -void failsafe_set_burst_fn(struct rte_eth_dev *dev, int force_safe); - uint16_t failsafe_rx_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts); uint16_t failsafe_tx_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts); -uint16_t failsafe_rx_burst_fast(void *rxq, - struct rte_mbuf **rx_pkts, uint16_t nb_pkts); -uint16_t failsafe_tx_burst_fast(void *txq, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts); - /* ARGS */ int failsafe_args_parse(struct rte_eth_dev *dev, const char *params); @@ -487,7 +480,6 @@ fs_switch_dev(struct rte_eth_dev *dev, } else { return; } - failsafe_set_burst_fn(dev, 0); rte_wmb(); } diff --git a/drivers/net/failsafe/failsafe_rxtx.c b/drivers/net/failsafe/failsafe_rxtx.c index fe67293299..707fe60a36 100644 --- a/drivers/net/failsafe/failsafe_rxtx.c +++ b/drivers/net/failsafe/failsafe_rxtx.c @@ -28,39 +28,6 @@ fs_tx_unsafe(struct sub_device *sdev) (sdev->state != DEV_STARTED); } -void -failsafe_set_burst_fn(struct rte_eth_dev *dev, int force_safe) -{ - struct sub_device *sdev; - uint8_t i; - int need_safe; - int safe_set; - - need_safe = force_safe; - FOREACH_SUBDEV(sdev, i, dev) - need_safe |= fs_rx_unsafe(sdev); - safe_set = (dev->rx_pkt_burst == &failsafe_rx_burst); - if (need_safe && !safe_set) { - DEBUG("Using safe RX bursts%s", - (force_safe ? " (forced)" : "")); - dev->rx_pkt_burst = &failsafe_rx_burst; - } else if (!need_safe && safe_set) { - DEBUG("Using fast RX bursts"); - dev->rx_pkt_burst = &failsafe_rx_burst_fast; - } - need_safe = force_safe || fs_tx_unsafe(TX_SUBDEV(dev)); - safe_set = (dev->tx_pkt_burst == &failsafe_tx_burst); - if (need_safe && !safe_set) { - DEBUG("Using safe TX bursts%s", - (force_safe ? " (forced)" : "")); - dev->tx_pkt_burst = &failsafe_tx_burst; - } else if (!need_safe && safe_set) { - DEBUG("Using fast TX bursts"); - dev->tx_pkt_burst = &failsafe_tx_burst_fast; - } - rte_wmb(); -} - /* * Override source port in Rx packets. * @@ -89,7 +56,7 @@ failsafe_rx_burst(void *queue, rxq = queue; sdev = rxq->sdev; do { - if (fs_rx_unsafe(sdev)) { + if (unlikely(fs_rx_unsafe(sdev))) { nb_rx = 0; sdev = sdev->next; continue; @@ -108,34 +75,6 @@ failsafe_rx_burst(void *queue, return nb_rx; } -uint16_t -failsafe_rx_burst_fast(void *queue, - struct rte_mbuf **rx_pkts, - uint16_t nb_pkts) -{ - struct sub_device *sdev; - struct rxq *rxq; - void *sub_rxq; - uint16_t nb_rx; - - rxq = queue; - sdev = rxq->sdev; - do { - RTE_ASSERT(!fs_rx_unsafe(sdev)); - sub_rxq = ETH(sdev)->data->rx_queues[rxq->qid]; - FS_ATOMIC_P(rxq->refcnt[sdev->sid]); - nb_rx = ETH(sdev)-> - rx_pkt_burst(sub_rxq, rx_pkts, nb_pkts); - FS_ATOMIC_V(rxq->refcnt[sdev->sid]); - sdev = sdev->next; - } while (nb_rx == 0 && sdev != rxq->sdev); - rxq->sdev = sdev; - if (nb_rx) - failsafe_rx_set_port(rx_pkts, nb_rx, - rxq->priv->data->port_id); - return nb_rx; -} - uint16_t failsafe_tx_burst(void *queue, struct rte_mbuf **tx_pkts, @@ -156,23 +95,3 @@ failsafe_tx_burst(void *queue, FS_ATOMIC_V(txq->refcnt[sdev->sid]); return nb_tx; } - -uint16_t -failsafe_tx_burst_fast(void *queue, - struct rte_mbuf **tx_pkts, - uint16_t nb_pkts) -{ - struct sub_device *sdev; - struct txq *txq; - void *sub_txq; - uint16_t nb_tx; - - txq = queue; - sdev = TX_SUBDEV(&rte_eth_devices[txq->priv->data->port_id]); - RTE_ASSERT(!fs_tx_unsafe(sdev)); - sub_txq = ETH(sdev)->data->tx_queues[txq->qid]; - FS_ATOMIC_P(txq->refcnt[sdev->sid]); - nb_tx = ETH(sdev)->tx_pkt_burst(sub_txq, tx_pkts, nb_pkts); - FS_ATOMIC_V(txq->refcnt[sdev->sid]); - return nb_tx; -} -- 2.38.1