From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gaetan.rivet@6wind.com>
Received: from mail-wr0-f176.google.com (mail-wr0-f176.google.com
 [209.85.128.176]) by dpdk.org (Postfix) with ESMTP id 280D57CBE
 for <dev@dpdk.org>; Wed, 26 Jul 2017 15:36:12 +0200 (CEST)
Received: by mail-wr0-f176.google.com with SMTP id v105so101485478wrb.0
 for <dev@dpdk.org>; Wed, 26 Jul 2017 06:36:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=6wind-com.20150623.gappssmtp.com; s=20150623;
 h=from:to:cc:subject:date:message-id:in-reply-to:references
 :in-reply-to:references;
 bh=TEJrvxjRhOp5taG9yHcK589pjnW0R56+ll4kQdNewdM=;
 b=K3GHQe+GgtdRlo+s0YjLSBlsWYNXvnfnD/kwvHjfQN50zA+FT+7q1mJzlaWKSyOStZ
 PJxFlUXRfuIvF14m0iZgHXUZp++dgsNwju8c42l6yg1tUOZx5chDohoyWsWxn1ROkCKQ
 wTwsNuDtagrOBY6YrytGTJEYYNeSRipcdANwKefEb25oNYchwftR1YKabsBaxzJZwqj7
 th+RJEtvjalPbc7QQAooF3vdTmCgqFOkRFduJLZIklpuNV0wtF8zZYdEuJZK8QQBlK6S
 aabP2sZXjUHSNlOGCBuwVKoBl8rvCEqZRVhzc6987ALPA9/2Whr+DdBFuo55ouXVfGtD
 x8/Q==
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:in-reply-to:references;
 bh=TEJrvxjRhOp5taG9yHcK589pjnW0R56+ll4kQdNewdM=;
 b=XtyQxe68Y2wwhaD4gPH6FKy7b+4qOdKtyn9n/yd3aOTVGkrAXpREtOYwyBbxiQAzFT
 funx1KL/I328EqefLdS3CXlpS+Q2nuP2CvLDwxzVQePHOSz9mtt14ZHq4oq7kx93Hvni
 JZRSl/ZnnauI5NZbaM2cGv8BxevXDWh0nLsIXL5D23zHvgEmv4x6LchiV70MKm2VYJ2g
 i8jzsmbehF9Jtg8095fLyLQWXG19YsxqGB4ixxJQlOm6+JdXG8AuH7lwUYjZwem2wRsG
 98e6T4XNSpIgU/7Pbyjloh1hxI/sr6bZQOM75dT33CsTaFfyFkZHWPeulZylhqyQyhkb
 tE6w==
X-Gm-Message-State: AIVw113PPnjDDmSKJw7WCw2K7u12kUpkOrNd3RpgmwhwogdktEqWk1W0
 xuR5v6YoGR5E+oMDM8o=
X-Received: by 10.223.141.146 with SMTP id o18mr872480wrb.215.1501076171215;
 Wed, 26 Jul 2017 06:36:11 -0700 (PDT)
Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com.
 [62.23.145.78])
 by smtp.gmail.com with ESMTPSA id c13sm3144707wrc.7.2017.07.26.06.36.09
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Wed, 26 Jul 2017 06:36:10 -0700 (PDT)
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Gaetan Rivet <gaetan.rivet@6wind.com>,
	stable@dpdk.org
Date: Wed, 26 Jul 2017 15:35:52 +0200
Message-Id: <c7aa5b19140a4ba2f6286e4e39dd2b7dd6061aa4.1501076035.git.gaetan.rivet@6wind.com>
X-Mailer: git-send-email 2.1.4
In-Reply-To: <cover.1501076035.git.gaetan.rivet@6wind.com>
References: <cover.1501075226.git.gaetan.rivet@6wind.com>
 <cover.1501076035.git.gaetan.rivet@6wind.com>
In-Reply-To: <cover.1501076035.git.gaetan.rivet@6wind.com>
References: <cover.1501076035.git.gaetan.rivet@6wind.com>
Subject: [dpdk-dev] [PATCH v2 1/6] ethdev: fix device state on detach
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 26 Jul 2017 13:36:12 -0000

The device state should be handled by the ether layer when possible.
Applications should not have to do it.

Not setting the state to UNUSED will make the port_id of the device
valid for all ether API functions, usually resulting in segfault.

Fixes: 284c908cc588 ("app/testpmd: request device removal interrupt")
Cc: stable@dpdk.org

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 app/test-pmd/testpmd.c        | 1 -
 lib/librte_ether/rte_ethdev.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index e754d12..9142218 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -1836,7 +1836,6 @@ rmv_event_callback(void *arg)
 	close_port(port_id);
 	printf("removing device %s\n", dev->device->name);
 	rte_eal_dev_detach(dev->device);
-	dev->state = RTE_ETH_DEV_UNUSED;
 }
 
 /* This function is used by the interrupt thread */
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index d4ebb1b..8c365ed 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -453,6 +453,7 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
 	if (ret < 0)
 		goto err;
 
+	rte_eth_devices[port_id].state = RTE_ETH_DEV_UNUSED;
 	return 0;
 
 err:
-- 
2.1.4