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 A595BA056F for ; Wed, 16 Nov 2022 18:35:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 96691410D3; Wed, 16 Nov 2022 18:35:33 +0100 (CET) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by mails.dpdk.org (Postfix) with ESMTP id 40DAC40DFB; Wed, 16 Nov 2022 18:35:30 +0100 (CET) Received: from frapeml100007.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4NC97F2cP1z67Q6Z; Thu, 17 Nov 2022 01:30:49 +0800 (CST) Received: from frapeml500007.china.huawei.com (7.182.85.172) by frapeml100007.china.huawei.com (7.182.85.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 16 Nov 2022 18:35:29 +0100 Received: from frapeml500007.china.huawei.com ([7.182.85.172]) by frapeml500007.china.huawei.com ([7.182.85.172]) with mapi id 15.01.2375.031; Wed, 16 Nov 2022 18:35:29 +0100 From: Konstantin Ananyev To: Luc Pelletier , "grive@u256.net" CC: "dev@dpdk.org" , Konstantin Ananyev , "stable@dpdk.org" Subject: RE: [PATCH] failsafe: fix segfault on hotplug event Thread-Topic: [PATCH] failsafe: fix segfault on hotplug event Thread-Index: AQHY9SprVcNNgKa3LUC7cpmW1Gqcra5B0XAQ Date: Wed, 16 Nov 2022 17:35:29 +0000 Message-ID: References: <20221110163410.12734-1-lucp.at.work@gmail.com> In-Reply-To: <20221110163410.12734-1-lucp.at.work@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.206.138.42] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CFilter-Loop: Reflected 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 =20 > 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. >=20 > Following commit 7a0935239b, 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. >=20 > 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. >=20 > To fix the problem, the failsafe PMD code was changed to update the > function pointers in the rte_eth_fp_ops array when a hotplug event > occurs. =20 It is not recommended way to update rte_eth_fp_ops[] contents directly. There are eth_dev_fp_ops_setup()/ eth_dev_fp_ops_reset() that supposed to be used for that. About the fix itself - while it might help till some extent, I think it will not remove the problem completely. There still remain a race-condition between rte_eth_rx_burst() and failsafe= _eth_rmv_event_callback(). Right now DPDK doesn't support switching PMD fast-ops functions (or updatin= g rxq/txq data) on the fly. =20 > Fixes: 7a0935239b ("ethdev: make fast-path functions to use new flat arra= y") > Cc: Konstantin Ananyev > Cc: stable@dpdk.org >=20 > Signed-off-by: Luc Pelletier > --- > drivers/net/failsafe/failsafe_rxtx.c | 9 +++++++++ > 1 file changed, 9 insertions(+) >=20 > diff --git a/drivers/net/failsafe/failsafe_rxtx.c b/drivers/net/failsafe/= failsafe_rxtx.c > index fe67293299..34d59dfbb1 100644 > --- a/drivers/net/failsafe/failsafe_rxtx.c > +++ b/drivers/net/failsafe/failsafe_rxtx.c > @@ -5,6 +5,7 @@ >=20 > #include > #include > +#include > #include > #include >=20 > @@ -44,9 +45,13 @@ failsafe_set_burst_fn(struct rte_eth_dev *dev, int for= ce_safe) > DEBUG("Using safe RX bursts%s", > (force_safe ? " (forced)" : "")); > dev->rx_pkt_burst =3D &failsafe_rx_burst; > + rte_eth_fp_ops[dev->data->port_id].rx_pkt_burst =3D > + &failsafe_rx_burst; > } else if (!need_safe && safe_set) { > DEBUG("Using fast RX bursts"); > dev->rx_pkt_burst =3D &failsafe_rx_burst_fast; > + rte_eth_fp_ops[dev->data->port_id].rx_pkt_burst =3D > + &failsafe_rx_burst_fast; > } > need_safe =3D force_safe || fs_tx_unsafe(TX_SUBDEV(dev)); > safe_set =3D (dev->tx_pkt_burst =3D=3D &failsafe_tx_burst); > @@ -54,9 +59,13 @@ failsafe_set_burst_fn(struct rte_eth_dev *dev, int for= ce_safe) > DEBUG("Using safe TX bursts%s", > (force_safe ? " (forced)" : "")); > dev->tx_pkt_burst =3D &failsafe_tx_burst; > + rte_eth_fp_ops[dev->data->port_id].tx_pkt_burst =3D > + &failsafe_tx_burst; > } else if (!need_safe && safe_set) { > DEBUG("Using fast TX bursts"); > dev->tx_pkt_burst =3D &failsafe_tx_burst_fast; > + rte_eth_fp_ops[dev->data->port_id].tx_pkt_burst =3D > + &failsafe_tx_burst_fast; > } > rte_wmb(); > } > -- > 2.25.1