From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id BD51EA0679 for ; Tue, 30 Apr 2019 20:12:43 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8DE135A6A; Tue, 30 Apr 2019 20:12:35 +0200 (CEST) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id DC69658FA for ; Tue, 30 Apr 2019 20:12:30 +0200 (CEST) Received: by mail-pf1-f195.google.com with SMTP id v80so2863616pfa.3 for ; Tue, 30 Apr 2019 11:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+Npx3od60mYH++vwE/jnwhQuPa57NeERy/zWuRjkxhc=; b=gzmc8fI2TFBlCrHj95R85gctL9PHvYmPD18QTr0A88mT6wQ30sBB2KcqkgRznTlkht b55I8RTBKjT1pMXw8rEqGL0X0xuZCrAslKtAOUSOMmp2gstejQyaZkzclJ/B3H3nkdWD EaXb8V7MmmTEHakrQWwipLMEBbEPSCCL5we5skXA+c8Qz3l49RywS4mMIUw4IdpopIQD Kzn1qz05My7Jg6mXdhF/3nySwDWIGxvQBNv3mv8VWDh8Cz9JXrY9RZXXRZqa8UmIlrn7 6VAtVtOsbj6xhNwQGaO/1UYFiunXZPpPNT61ZE4AWAqAgAdwq87GHcQGXcCV23sI2QjX m5rA== 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:mime-version:content-transfer-encoding; bh=+Npx3od60mYH++vwE/jnwhQuPa57NeERy/zWuRjkxhc=; b=E6DYffBg0aafDrAvucr0AeY15mqeLm5KwFQEzNbBwiIF7iRIJ44S7LHtVPtOeN0syO gIOpoK2X6qXOU7oTrA1XY2/zckOf9HRkm8s9V0e0G3wVvvhAScs/hXAdA0q+gwbiNVZ9 XtOXLa+xeRJ2ceW9fNaOmxxaasQFOglAj2KRssCgqixvJ44rmZJhNmcgv0dRXBcts/l1 bInJumzhwZKIfTIJhIwJn54GSQwGxJfdY37YMOiuhe+3lnTEFpaa5q00AEOeW7RvV+Hx o+d3hyH0JPzggp11PgPSf+iu4ICZpWRXk6Tb5sQ7HRym/dO0P4Tx6DE5EVEYGqehVtri qr6w== X-Gm-Message-State: APjAAAV8j7QvRHxxcuIeEkQTRBSMPRphWWt1j7WZkC8iA7jHBIh41/+W xS79l8IMDcSRfNv7Y7xfBEZYFjDnFKU= X-Google-Smtp-Source: APXvYqz3TxNyGf4q/lermho+ZwSnLa041qsSIkWrHMhEbv6QRrU2KDR9tiBTG5p9jCUITECUD5O+Qg== X-Received: by 2002:a62:f247:: with SMTP id y7mr9075445pfl.18.1556647949767; Tue, 30 Apr 2019 11:12:29 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id z7sm68660462pgh.81.2019.04.30.11.12.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Apr 2019 11:12:28 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 30 Apr 2019 11:12:17 -0700 Message-Id: <20190430181217.20875-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190430181217.20875-1-stephen@networkplumber.org> References: <20190429203325.10696-1-stephen@networkplumber.org> <20190430181217.20875-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 2/2] net/netvsc: free all queues on close 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" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190430181217.1dxhqD8LvPWQU_0F4knezKoqMcyPSsE2c44uw28vrXI@z> From: Stephen Hemminger When dev_close is called, the netvsc driver will clean up all queues including the primary ring buffer. Signed-off-by: Stephen Hemminger --- v2 - fix logic on close of primary avoid double free if close is called twice drivers/net/netvsc/hn_ethdev.c | 8 ++++-- drivers/net/netvsc/hn_rxtx.c | 46 +++++++++++++++++++++++++++------- drivers/net/netvsc/hn_var.h | 1 + drivers/net/netvsc/hn_vf.c | 11 +++++++- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c index 407ee484935a..553cb06f6e33 100644 --- a/drivers/net/netvsc/hn_ethdev.c +++ b/drivers/net/netvsc/hn_ethdev.c @@ -112,6 +112,9 @@ eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size) eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC; eth_dev->intr_handle = &dev->intr_handle; + /* allow ethdev to remove on close */ + eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE; + return eth_dev; } @@ -632,11 +635,12 @@ hn_dev_stop(struct rte_eth_dev *dev) } static void -hn_dev_close(struct rte_eth_dev *dev __rte_unused) +hn_dev_close(struct rte_eth_dev *dev) { - PMD_INIT_LOG(DEBUG, "close"); + PMD_INIT_FUNC_TRACE(); hn_vf_close(dev); + hn_dev_free_queues(dev); } static const struct eth_dev_ops hn_eth_dev_ops = { diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c index 7856f7e6ec48..7d7b557785fa 100644 --- a/drivers/net/netvsc/hn_rxtx.c +++ b/drivers/net/netvsc/hn_rxtx.c @@ -840,12 +840,9 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev, return error; } -void -hn_dev_rx_queue_release(void *arg) +static void +hn_rx_queue_free(struct hn_rx_queue *rxq, bool keep_primary) { - struct hn_rx_queue *rxq = arg; - - PMD_INIT_FUNC_TRACE(); if (!rxq) return; @@ -857,10 +854,21 @@ hn_dev_rx_queue_release(void *arg) hn_vf_rx_queue_release(rxq->hv, rxq->queue_id); /* Keep primary queue to allow for control operations */ - if (rxq != rxq->hv->primary) { - rte_free(rxq->event_buf); - rte_free(rxq); - } + if (keep_primary && rxq == rxq->hv->primary) + return; + + rte_free(rxq->event_buf); + rte_free(rxq); +} + +void +hn_dev_rx_queue_release(void *arg) +{ + struct hn_rx_queue *rxq = arg; + + PMD_INIT_FUNC_TRACE(); + + hn_rx_queue_free(rxq, true); } int @@ -1440,3 +1448,23 @@ hn_recv_pkts(void *prxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) return nb_rcv; } + +void +hn_dev_free_queues(struct rte_eth_dev *dev) +{ + unsigned int i; + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + struct hn_rx_queue *rxq = dev->data->rx_queues[i]; + + hn_rx_queue_free(rxq, false); + dev->data->rx_queues[i] = NULL; + } + dev->data->nb_rx_queues = 0; + + for (i = 0; i < dev->data->nb_tx_queues; i++) { + hn_dev_tx_queue_release(dev->data->tx_queues[i]); + dev->data->tx_queues[i] = NULL; + } + dev->data->nb_tx_queues = 0; +} diff --git a/drivers/net/netvsc/hn_var.h b/drivers/net/netvsc/hn_var.h index 8383f3246ca4..de885d898e6a 100644 --- a/drivers/net/netvsc/hn_var.h +++ b/drivers/net/netvsc/hn_var.h @@ -173,6 +173,7 @@ int hn_dev_rx_queue_setup(struct rte_eth_dev *dev, const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mp); void hn_dev_rx_queue_release(void *arg); +void hn_dev_free_queues(struct rte_eth_dev *dev); /* Check if VF is attached */ static inline bool diff --git a/drivers/net/netvsc/hn_vf.c b/drivers/net/netvsc/hn_vf.c index 883272ff498c..b980bb8a4d8a 100644 --- a/drivers/net/netvsc/hn_vf.c +++ b/drivers/net/netvsc/hn_vf.c @@ -362,7 +362,16 @@ void hn_vf_reset(struct rte_eth_dev *dev) void hn_vf_close(struct rte_eth_dev *dev) { - VF_ETHDEV_FUNC(dev, rte_eth_dev_close); + struct hn_data *hv = dev->data->dev_private; + uint16_t vf_port; + + rte_spinlock_lock(&hv->vf_lock); + vf_port = hv->vf_port; + if (vf_port != HN_INVALID_PORT) + rte_eth_dev_close(vf_port); + + hv->vf_port = HN_INVALID_PORT; + rte_spinlock_unlock(&hv->vf_lock); } void hn_vf_stats_reset(struct rte_eth_dev *dev) -- 2.20.1