From patchwork Wed Dec 28 21:10:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chas Williams X-Patchwork-Id: 18624 X-Patchwork-Delegate: yuanhan.liu@linux.intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id D8D0637A8; Wed, 28 Dec 2016 22:11:10 +0100 (CET) Received: from mx0a-000f0801.pphosted.com (mx0b-000f0801.pphosted.com [67.231.152.113]) by dpdk.org (Postfix) with ESMTP id 252B93777 for ; Wed, 28 Dec 2016 22:11:08 +0100 (CET) Received: from pps.filterd (m0048192.ppops.net [127.0.0.1]) by mx0b-000f0801.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uBSL3jbp010349; Wed, 28 Dec 2016 13:11:08 -0800 Received: from brmwp-exmb11.corp.brocade.com ([208.47.132.227]) by mx0b-000f0801.pphosted.com with ESMTP id 27hs67tcuq-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 28 Dec 2016 13:11:08 -0800 Received: from confsjhq2-2-001.brocade.com (10.252.139.5) by BRMWP-EXMB11.corp.brocade.com (172.16.59.77) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Wed, 28 Dec 2016 14:11:02 -0700 From: "Charles (Chas) Williams" To: CC: , , Wen Chiu Date: Wed, 28 Dec 2016 16:10:51 -0500 Message-ID: <1482959452-18486-1-git-send-email-ciwillia@brocade.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-ClientProxiedBy: hq1wp-excas11.corp.brocade.com (10.70.36.102) To BRMWP-EXMB11.corp.brocade.com (172.16.59.77) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-12-28_16:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1612280283 Subject: [dpdk-dev] [PATCH 1/2] vhost: reference count fix for nb_started_ports X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Wen Chiu Only increment and decrement nb_started_ports on the first and last device start and stop. Otherwise, nb_started_ports can become negative if a device is stopped multiple times. Fixes: ee584e9710b9 ("vhost: add driver on top of the library") Signed-off-by: Wen Chiu Reviewed-by: Chas Williams --- drivers/net/vhost/rte_eth_vhost.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 60b0f51..ba559ff 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -782,11 +782,11 @@ eth_dev_start(struct rte_eth_dev *dev) internal->flags); if (ret) return ret; - } - /* We need only one message handling thread */ - if (rte_atomic16_add_return(&nb_started_ports, 1) == 1) - ret = vhost_driver_session_start(); + /* We need only one message handling thread */ + if (rte_atomic16_add_return(&nb_started_ports, 1) == 1) + ret = vhost_driver_session_start(); + } return ret; } @@ -796,11 +796,12 @@ eth_dev_stop(struct rte_eth_dev *dev) { struct pmd_internal *internal = dev->data->dev_private; - if (rte_atomic16_cmpset(&internal->once, 1, 0)) + if (rte_atomic16_cmpset(&internal->once, 1, 0)) { rte_vhost_driver_unregister(internal->iface_name); - if (rte_atomic16_sub_return(&nb_started_ports, 1) == 0) - vhost_driver_session_stop(); + if (rte_atomic16_sub_return(&nb_started_ports, 1) == 0) + vhost_driver_session_stop(); + } } static int