From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by dpdk.org (Postfix) with ESMTP id A8440F3E for ; Mon, 30 Apr 2018 16:42:35 +0200 (CEST) Received: by mail-wr0-f196.google.com with SMTP id v5-v6so8285728wrf.9 for ; Mon, 30 Apr 2018 07:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hxgZakMOLCSVYarvoeJg/YppYPhg2LpBT2MGb3/lF0s=; b=TAl4EX0CIDKXz/hjuQr/Z9OZi/uuD7N5BpKqiMOmg3jevdSB26drmzipblPWrn9a+r uw7yWdkH9nU8c6OY9m/XJsrk6AgLoPBdZri7lAwS7UJtgBP5M0VPkAdXYd7WgjVxlxEF PLcb1pI7zHCdrROT+VAc80U9JrVkc2bk5W99IkcCyPDU7Fv/zIW+tENnae9wT5K3sg3o ezKjH1G2VbMO+WwZVFrt5kepazZsJnJ+FeR+r9l0XlYGTIQRIJAfjeqRSqa8x/Pra8Hi 1zngaWKR1oiqfp8OlloNSFiaX9lGlXIPbjhtYwgpCZx/SCogH6TJ7DAEkCsTNlmttto3 F1iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hxgZakMOLCSVYarvoeJg/YppYPhg2LpBT2MGb3/lF0s=; b=qhBpvsB8L/+/u35igDgEsLA8q3zDXpXNaSCkeNyTc8zk6B2h4iVnzzZFsB+I5bxGGk DEpSzQWA36XqVoeXmGeGaXjk9GikeEteQZ5NxGZGhzBvJ3vFqQYNjHDE2sxw/+OdgCEC gKy9GP/XgOb5nNflibV3uLs0nVCFoY51NQvcZPZnsRJGGs4lHZybTixDuC2uW4n0z86M SDu9Mybk+ksAlFwTuNvqgFmcZHDyH9sJqopL+EPD1Aoo4EOBQXpEjXslAuzaU2f+E/if cgqmp6o5zP3sdG5KfYc+eKUKqJV4vOXp+Cz93okCMhdXCu1ZvbUWEOU4e/v4q7FQLhcS 3y4w== X-Gm-Message-State: ALQs6tBJJBKH0hcWs9yX5zo7xEkaUPEPOI3c63hDSu2zTptfDbfVdsSG nw8Ikxq476kgxngPXucqNlQ= X-Google-Smtp-Source: AB8JxZoPeVgrsxFa0KZsaSCABygoDnboO+T3m64eGdB8gMll/kT0eS1Cq7rYGvw3YHtauCRreOn4jQ== X-Received: by 2002:adf:b78b:: with SMTP id s11-v6mr3644253wre.247.1525099355314; Mon, 30 Apr 2018 07:42:35 -0700 (PDT) Received: from localhost ([2a00:23c5:be9a:5200:ce4c:82c0:d567:ecbb]) by smtp.gmail.com with ESMTPSA id d125sm5165320wmd.24.2018.04.30.07.42.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Apr 2018 07:42:34 -0700 (PDT) From: luca.boccassi@gmail.com To: Junjie Chen Cc: Zhiyong Yang , Maxime Coquelin , dpdk stable Date: Mon, 30 Apr 2018 15:40:21 +0100 Message-Id: <20180430144223.18657-6-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180430144223.18657-1-luca.boccassi@gmail.com> References: <20180430140606.4615-80-luca.boccassi@gmail.com> <20180430144223.18657-1-luca.boccassi@gmail.com> Subject: [dpdk-stable] patch 'net/vhost: fix crash when creating vdev dynamically' has been queued to stable release 18.02.2 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Apr 2018 14:42:35 -0000 Hi, FYI, your patch has been queued to stable release 18.02.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 05/02/18. So please shout if anyone has objections. Thanks. Luca Boccassi --- >>From ebab27f620c6bbd7fe725487dbb165a96251bd36 Mon Sep 17 00:00:00 2001 From: Junjie Chen Date: Fri, 30 Mar 2018 14:58:31 +0800 Subject: [PATCH] net/vhost: fix crash when creating vdev dynamically [ upstream commit 30a701a53737a0b6f7953412cc3b3d36c1d49122 ] When creating vdev dynamically, vhost pmd driver starts directly without checking TX/RX queues are ready or not, and thus causes segmentation fault when vhost library accesses queues. This patch adds a flag to check whether queues are setup or not, and adds queues setup into dev_start function to allow user to start them after setting up. Fixes: aed0b12930b3 ("net/vhost: fix socket file deleted on stop") Signed-off-by: Junjie Chen Tested-by: Zhiyong Yang Reviewed-by: Maxime Coquelin --- drivers/net/vhost/rte_eth_vhost.c | 69 ++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 3aae01c39..11b607650 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -117,6 +117,7 @@ struct pmd_internal { char *dev_name; char *iface_name; uint16_t max_queues; + uint16_t vid; rte_atomic32_t started; }; @@ -527,8 +528,10 @@ update_queuing_status(struct rte_eth_dev *dev) unsigned int i; int allow_queuing = 1; - if (rte_atomic32_read(&internal->started) == 0 || - rte_atomic32_read(&internal->dev_attached) == 0) + if (rte_atomic32_read(&internal->dev_attached) == 0) + return; + + if (rte_atomic32_read(&internal->started) == 0) allow_queuing = 0; /* Wait until rx/tx_pkt_burst stops accessing vhost device */ @@ -551,13 +554,36 @@ update_queuing_status(struct rte_eth_dev *dev) } } +static void +queue_setup(struct rte_eth_dev *eth_dev, struct pmd_internal *internal) +{ + struct vhost_queue *vq; + int i; + + for (i = 0; i < eth_dev->data->nb_rx_queues; i++) { + vq = eth_dev->data->rx_queues[i]; + if (!vq) + continue; + vq->vid = internal->vid; + vq->internal = internal; + vq->port = eth_dev->data->port_id; + } + for (i = 0; i < eth_dev->data->nb_tx_queues; i++) { + vq = eth_dev->data->tx_queues[i]; + if (!vq) + continue; + vq->vid = internal->vid; + vq->internal = internal; + vq->port = eth_dev->data->port_id; + } +} + static int new_device(int vid) { struct rte_eth_dev *eth_dev; struct internal_list *list; struct pmd_internal *internal; - struct vhost_queue *vq; unsigned i; char ifname[PATH_MAX]; #ifdef RTE_LIBRTE_VHOST_NUMA @@ -580,21 +606,13 @@ new_device(int vid) eth_dev->data->numa_node = newnode; #endif - for (i = 0; i < eth_dev->data->nb_rx_queues; i++) { - vq = eth_dev->data->rx_queues[i]; - if (vq == NULL) - continue; - vq->vid = vid; - vq->internal = internal; - vq->port = eth_dev->data->port_id; - } - for (i = 0; i < eth_dev->data->nb_tx_queues; i++) { - vq = eth_dev->data->tx_queues[i]; - if (vq == NULL) - continue; - vq->vid = vid; - vq->internal = internal; - vq->port = eth_dev->data->port_id; + internal->vid = vid; + if (eth_dev->data->rx_queues && eth_dev->data->tx_queues) { + queue_setup(eth_dev, internal); + rte_atomic32_set(&internal->dev_attached, 1); + } else { + RTE_LOG(INFO, PMD, "RX/TX queues have not setup yet\n"); + rte_atomic32_set(&internal->dev_attached, 0); } for (i = 0; i < rte_vhost_get_vring_num(vid); i++) @@ -604,7 +622,6 @@ new_device(int vid) eth_dev->data->dev_link.link_status = ETH_LINK_UP; - rte_atomic32_set(&internal->dev_attached, 1); update_queuing_status(eth_dev); RTE_LOG(INFO, PMD, "Vhost device %d created\n", vid); @@ -634,8 +651,9 @@ destroy_device(int vid) eth_dev = list->eth_dev; internal = eth_dev->data->dev_private; + rte_atomic32_set(&internal->started, 0); + update_queuing_status(eth_dev); rte_atomic32_set(&internal->dev_attached, 0); - update_queuing_status(eth_dev); eth_dev->data->dev_link.link_status = ETH_LINK_DOWN; @@ -770,12 +788,17 @@ rte_eth_vhost_get_vid_from_port_id(uint16_t port_id) } static int -eth_dev_start(struct rte_eth_dev *dev) +eth_dev_start(struct rte_eth_dev *eth_dev) { - struct pmd_internal *internal = dev->data->dev_private; + struct pmd_internal *internal = eth_dev->data->dev_private; + + if (unlikely(rte_atomic32_read(&internal->dev_attached) == 0)) { + queue_setup(eth_dev, internal); + rte_atomic32_set(&internal->dev_attached, 1); + } rte_atomic32_set(&internal->started, 1); - update_queuing_status(dev); + update_queuing_status(eth_dev); return 0; } -- 2.14.2