From patchwork Fri Jan 28 02:35:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "humin (Q)" X-Patchwork-Id: 106654 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id ADE42A00C4; Fri, 28 Jan 2022 03:35:10 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 42F194277B; Fri, 28 Jan 2022 03:35:10 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id F075C40141 for ; Fri, 28 Jan 2022 03:35:08 +0100 (CET) Received: from dggeme756-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4JlM3W2bsvzbkC8; Fri, 28 Jan 2022 10:34:15 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggeme756-chm.china.huawei.com (10.3.19.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.21; Fri, 28 Jan 2022 10:35:06 +0800 From: "Min Hu (Connor)" To: CC: , , Subject: [PATCH] app/testpmd: fix bonding mode set Date: Fri, 28 Jan 2022 10:35:19 +0800 Message-ID: <20220128023519.10027-1-humin29@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggeme756-chm.china.huawei.com (10.3.19.102) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org when start testpmd, and type command like this, it will lead to Segmentation fault, like: testpmd> create bonded device 4 0 testpmd> add bonding slave 0 2 testpmd> add bonding slave 1 2 testpmd> port start 2 testpmd> set bonding mode 0 2 testpmd> quit Stopping port 0... Stopping ports... ... Bye... Segmentation fault The reason to the bug is that rte timer do not be cancelled when quit. That is, in 'bond_ethdev_start', resources are allocated according to different bonding mode. In 'bond_ethdev_stop', resources are free by the corresponding mode. For example, 'bond_ethdev_start' start bond_mode_8023ad_ext_periodic_cb timer for bonding mode 4. and 'bond_ethdev_stop' cancel the timer only when the current bonding mode is 4. If the bonding mode is changed, and directly quit the process, the timer will still on, and freed memory will be accessed, then segmentation fault. 'bonding mode'changed means resources changed, reallocate resources for different mode should be done, that is, device should be restarted. Fixes: 2950a769315e ("bond: testpmd support") Cc: stable@dpdk.org Signed-off-by: Min Hu (Connor) Tested-by: Ferruh Yigit --- app/test-pmd/cmdline.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index e626b1c7d9..2c47ab0f18 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -5915,6 +5915,19 @@ static void cmd_set_bonding_mode_parsed(void *parsed_result, { struct cmd_set_bonding_mode_result *res = parsed_result; portid_t port_id = res->port_id; + struct rte_port *port = &ports[port_id]; + + /* + * Bonding mode changed means resources of device changed, like whether + * started rte timer or not. Device should be restarted when resources + * of device changed. + */ + if (port->port_status != RTE_PORT_STOPPED) { + fprintf(stderr, + "\t Error: Can't config bonding mode when port %d is not stopped\n", + port_id); + return; + } /* Set the bonding mode for the relevant port. */ if (0 != rte_eth_bond_mode_set(port_id, res->value))