From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 516C61E34; Fri, 20 Jul 2018 13:44:56 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jul 2018 04:44:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,378,1526367600"; d="scan'208";a="66171144" Received: from silpixa00399752.ir.intel.com (HELO silpixa00399752.ger.corp.intel.com) ([10.237.222.212]) by FMSMGA003.fm.intel.com with ESMTP; 20 Jul 2018 04:44:36 -0700 From: Ferruh Yigit To: "John W. Linville" , Declan Doherty , Chas Williams , Hemant Agrawal , Shreyansh Jain , Gaetan Rivet , Tetsuya Mukawa , Santosh Shukla , Jerin Jacob , Keith Wiles , Maxime Coquelin , Tiwei Bie , Zhihong Wang , Thomas Monjalon , Andrew Rybchenko Cc: dev@dpdk.org, Ferruh Yigit , stable@dpdk.org Date: Fri, 20 Jul 2018 13:44:21 +0100 Message-Id: <20180720124421.71277-1-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180719164556.93162-1-ferruh.yigit@intel.com> References: <20180719164556.93162-1-ferruh.yigit@intel.com> Subject: [dpdk-dev] [PATCH v2] drivers/net: fix segfault in secondary process 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: , X-List-Received-Date: Fri, 20 Jul 2018 11:44:57 -0000 Calling rte_eth_dev_info_get() on secondary process cause a crash because eth_dev->device is not set properly. Adding a helper function rte_eth_vdev_secondary_probe() that initializes eth_dev fields properly. Fixes: ee27edbe0c10 ("drivers/net: share vdev data to secondary process") Cc: stable@dpdk.org Reported-by: Vipin Varghese Signed-off-by: Ferruh Yigit --- v2: * Added rte_eth_vdev_secondary_probe * Updated dpaa * More update on octeontx --- drivers/net/af_packet/rte_eth_af_packet.c | 5 +---- drivers/net/bonding/rte_eth_bond_pmd.c | 6 ++---- drivers/net/dpaa/dpaa_ethdev.c | 2 ++ drivers/net/failsafe/failsafe.c | 6 ++---- drivers/net/kni/rte_eth_kni.c | 6 ++---- drivers/net/null/rte_eth_null.c | 7 ++----- drivers/net/octeontx/octeontx_ethdev.c | 9 +++++---- drivers/net/pcap/rte_eth_pcap.c | 6 ++---- drivers/net/tap/rte_eth_tap.c | 8 ++------ drivers/net/vhost/rte_eth_vhost.c | 5 +---- lib/librte_ethdev/rte_ethdev_vdev.h | 17 +++++++++++++++++ 11 files changed, 38 insertions(+), 39 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index ce1e31aa4..548aee09e 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -929,14 +929,11 @@ rte_pmd_af_packet_probe(struct rte_vdev_device *dev) if (rte_eal_process_type() == RTE_PROC_SECONDARY && strlen(rte_vdev_device_args(dev)) == 0) { - eth_dev = rte_eth_dev_attach_secondary(name); + eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops); if (!eth_dev) { PMD_LOG(ERR, "Failed to probe %s", name); return -1; } - /* TODO: request info from primary to set up Rx and Tx */ - eth_dev->dev_ops = &ops; - rte_eth_dev_probing_finish(eth_dev); return 0; } diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c index fc4d4fd97..d155c7ac2 100644 --- a/drivers/net/bonding/rte_eth_bond_pmd.c +++ b/drivers/net/bonding/rte_eth_bond_pmd.c @@ -3177,14 +3177,12 @@ bond_probe(struct rte_vdev_device *dev) if (rte_eal_process_type() == RTE_PROC_SECONDARY && strlen(rte_vdev_device_args(dev)) == 0) { - eth_dev = rte_eth_dev_attach_secondary(name); + eth_dev = rte_eth_vdev_secondary_probe(dev, name, + &default_dev_ops); if (!eth_dev) { RTE_BOND_LOG(ERR, "Failed to probe %s", name); return -1; } - /* TODO: request info from primary to set up Rx and Tx */ - eth_dev->dev_ops = &default_dev_ops; - rte_eth_dev_probing_finish(eth_dev); return 0; } diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c index 5c0aafb3c..7a950ac04 100644 --- a/drivers/net/dpaa/dpaa_ethdev.c +++ b/drivers/net/dpaa/dpaa_ethdev.c @@ -1389,6 +1389,8 @@ rte_dpaa_probe(struct rte_dpaa_driver *dpaa_drv, eth_dev = rte_eth_dev_attach_secondary(dpaa_dev->name); if (!eth_dev) return -ENOMEM; + eth_dev->device = &dpaa_dev->device; + eth_dev->dev_ops = &dpaa_devops; rte_eth_dev_probing_finish(eth_dev); return 0; } diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c index 7f89486d4..0278deb33 100644 --- a/drivers/net/failsafe/failsafe.c +++ b/drivers/net/failsafe/failsafe.c @@ -321,14 +321,12 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev) if (rte_eal_process_type() == RTE_PROC_SECONDARY && strlen(rte_vdev_device_args(vdev)) == 0) { - eth_dev = rte_eth_dev_attach_secondary(name); + eth_dev = rte_eth_vdev_secondary_probe(vdev, name, + &failsafe_ops); if (!eth_dev) { ERROR("Failed to probe %s", name); return -1; } - /* TODO: request info from primary to set up Rx and Tx */ - eth_dev->dev_ops = &failsafe_ops; - rte_eth_dev_probing_finish(eth_dev); return 0; } diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c index b038fbf1a..3e653d729 100644 --- a/drivers/net/kni/rte_eth_kni.c +++ b/drivers/net/kni/rte_eth_kni.c @@ -413,14 +413,12 @@ eth_kni_probe(struct rte_vdev_device *vdev) if (rte_eal_process_type() == RTE_PROC_SECONDARY && strlen(params) == 0) { - eth_dev = rte_eth_dev_attach_secondary(name); + eth_dev = rte_eth_vdev_secondary_probe(vdev, name, + ð_kni_ops); if (!eth_dev) { PMD_LOG(ERR, "Failed to probe %s", name); return -1; } - /* TODO: request info from primary to set up Rx and Tx */ - eth_dev->dev_ops = ð_kni_ops; - rte_eth_dev_probing_finish(eth_dev); return 0; } diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c index d85d25f7e..46ee494f6 100644 --- a/drivers/net/null/rte_eth_null.c +++ b/drivers/net/null/rte_eth_null.c @@ -616,15 +616,12 @@ rte_pmd_null_probe(struct rte_vdev_device *dev) PMD_LOG(INFO, "Initializing pmd_null for %s", name); if (rte_eal_process_type() == RTE_PROC_SECONDARY && - strlen(params) == 0) { - eth_dev = rte_eth_dev_attach_secondary(name); + strlen(params) == 0) { + eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops); if (!eth_dev) { PMD_LOG(ERR, "Failed to probe %s", name); return -1; } - /* TODO: request info from primary to set up Rx and Tx */ - eth_dev->dev_ops = &ops; - rte_eth_dev_probing_finish(eth_dev); return 0; } diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c index 21e5e4fca..ad96b152d 100644 --- a/drivers/net/octeontx/octeontx_ethdev.c +++ b/drivers/net/octeontx/octeontx_ethdev.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "octeontx_ethdev.h" #include "octeontx_rxtx.h" @@ -1015,6 +1016,8 @@ octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev, if (eth_dev == NULL) return -ENODEV; + eth_dev->dev_ops = &octeontx_dev_ops; + eth_dev->device = &dev->device; eth_dev->tx_pkt_burst = octeontx_xmit_pkts; eth_dev->rx_pkt_burst = octeontx_recv_pkts; rte_eth_dev_probing_finish(eth_dev); @@ -1176,14 +1179,12 @@ octeontx_probe(struct rte_vdev_device *dev) if (rte_eal_process_type() == RTE_PROC_SECONDARY && strlen(rte_vdev_device_args(dev)) == 0) { - eth_dev = rte_eth_dev_attach_secondary(dev_name); + eth_dev = rte_eth_vdev_secondary_probe(dev, dev_name, + &octeontx_dev_ops); if (!eth_dev) { RTE_LOG(ERR, PMD, "Failed to probe %s\n", dev_name); return -1; } - /* TODO: request info from primary to set up Rx and Tx */ - eth_dev->dev_ops = &octeontx_dev_ops; - rte_eth_dev_probing_finish(eth_dev); return 0; } diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c index 6779f97c1..d714c4be7 100644 --- a/drivers/net/pcap/rte_eth_pcap.c +++ b/drivers/net/pcap/rte_eth_pcap.c @@ -1010,14 +1010,12 @@ pmd_pcap_probe(struct rte_vdev_device *dev) if (rte_eal_process_type() == RTE_PROC_SECONDARY && strlen(rte_vdev_device_args(dev)) == 0) { - eth_dev = rte_eth_dev_attach_secondary(name); + eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops); if (!eth_dev) { PMD_LOG(ERR, "Failed to probe %s", name); return -1; } - /* TODO: request info from primary to set up Rx and Tx */ - eth_dev->dev_ops = &ops; - rte_eth_dev_probing_finish(eth_dev); + return 0; return 0; } diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 22ba872ed..e17d8955d 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -1925,12 +1925,11 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) if (rte_eal_process_type() == RTE_PROC_SECONDARY && strlen(params) == 0) { - eth_dev = rte_eth_dev_attach_secondary(name); + eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops); if (!eth_dev) { TAP_LOG(ERR, "Failed to probe %s", name); return -1; } - eth_dev->dev_ops = &ops; return 0; } @@ -1993,14 +1992,11 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) if (rte_eal_process_type() == RTE_PROC_SECONDARY && strlen(params) == 0) { - eth_dev = rte_eth_dev_attach_secondary(name); + eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops); if (!eth_dev) { TAP_LOG(ERR, "Failed to probe %s", name); return -1; } - /* TODO: request info from primary to set up Rx and Tx */ - eth_dev->dev_ops = &ops; - rte_eth_dev_probing_finish(eth_dev); return 0; } diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index 47b33456c..c4d8decd0 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -1347,14 +1347,11 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev) if (rte_eal_process_type() == RTE_PROC_SECONDARY && strlen(rte_vdev_device_args(dev)) == 0) { - eth_dev = rte_eth_dev_attach_secondary(name); + eth_dev = rte_eth_vdev_secondary_probe(dev, name, &ops); if (!eth_dev) { VHOST_LOG(ERR, "Failed to probe %s\n", name); return -1; } - /* TODO: request info from primary to set up Rx and Tx */ - eth_dev->dev_ops = &ops; - rte_eth_dev_probing_finish(eth_dev); return 0; } diff --git a/lib/librte_ethdev/rte_ethdev_vdev.h b/lib/librte_ethdev/rte_ethdev_vdev.h index 259feda3f..6092f6e71 100644 --- a/lib/librte_ethdev/rte_ethdev_vdev.h +++ b/lib/librte_ethdev/rte_ethdev_vdev.h @@ -81,4 +81,21 @@ rte_eth_vdev_allocate(struct rte_vdev_device *dev, size_t private_data_size) return eth_dev; } +static inline struct rte_eth_dev * +rte_eth_vdev_secondary_probe(struct rte_vdev_device *vdev, + const char *name, const struct eth_dev_ops *ops) +{ + struct rte_eth_dev *eth_dev; + + eth_dev = rte_eth_dev_attach_secondary(name); + if (!eth_dev) + return NULL; + + /* TODO: request info from primary to set up Rx and Tx */ + eth_dev->dev_ops = ops; + eth_dev->device = &vdev->device; + rte_eth_dev_probing_finish(eth_dev); + return eth_dev; +} + #endif /* _RTE_ETHDEV_VDEV_H_ */ -- 2.17.1