net/hinic: fix crash in secondary process

Some apps, such as fstack, will use secondary process to access the
memory of eth_dev_ops, and they want to get the info of dev, but hinic
driver does not initialized it when in secondary process.

Fixes: 66f64dd6dc86 ("net/hinic: fix secondary process")
Cc: stable@dpdk.org

Signed-off-by: Guoyang Zhou <zhouguoyang@huawei.com>
This commit is contained in:
Guoyang Zhou 2021-03-23 21:17:51 +08:00 committed by Ferruh Yigit
parent 19cc526d6c
commit 4c670dfaa4
2 changed files with 13 additions and 17 deletions

View File

@ -171,6 +171,7 @@ static inline u32 readl(const volatile void *addr)
#else
#define CLOCK_TYPE CLOCK_MONOTONIC
#endif
#define HINIC_MUTEX_TIMEOUT 10
static inline unsigned long clock_gettime_ms(void)
{
@ -225,24 +226,14 @@ static inline int hinic_mutex_destroy(pthread_mutex_t *pthreadmutex)
static inline int hinic_mutex_lock(pthread_mutex_t *pthreadmutex)
{
int err;
struct timespec tout;
err = pthread_mutex_lock(pthreadmutex);
if (!err) {
return err;
} else if (err == EOWNERDEAD) {
PMD_DRV_LOG(ERR, "Mutex lock failed. (ErrorNo=%d)", errno);
#if defined(__GLIBC__)
#if __GLIBC_PREREQ(2, 12)
(void)pthread_mutex_consistent(pthreadmutex);
#else
(void)pthread_mutex_consistent_np(pthreadmutex);
#endif
#else
(void)pthread_mutex_consistent(pthreadmutex);
#endif
} else {
PMD_DRV_LOG(ERR, "Mutex lock failed. (ErrorNo=%d)", errno);
}
(void)clock_gettime(CLOCK_TYPE, &tout);
tout.tv_sec += HINIC_MUTEX_TIMEOUT;
err = pthread_mutex_timedlock(pthreadmutex, &tout);
if (err)
PMD_DRV_LOG(ERR, "Mutex lock failed. (ErrorNo=%d)", err);
return err;
}

View File

@ -3063,6 +3063,10 @@ static const struct eth_dev_ops hinic_pmd_vf_ops = {
.flow_ops_get = hinic_dev_flow_ops_get,
};
static const struct eth_dev_ops hinic_dev_sec_ops = {
.dev_infos_get = hinic_dev_infos_get,
};
static int hinic_func_init(struct rte_eth_dev *eth_dev)
{
struct rte_pci_device *pci_dev;
@ -3077,6 +3081,7 @@ static int hinic_func_init(struct rte_eth_dev *eth_dev)
/* EAL is SECONDARY and eth_dev is already created */
if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
eth_dev->dev_ops = &hinic_dev_sec_ops;
PMD_DRV_LOG(INFO, "Initialize %s in secondary process",
eth_dev->data->name);