From 61874d3c0663504f83d93a4701627a5949160a0f Mon Sep 17 00:00:00 2001 From: Lu Qiuwen Date: Wed, 7 Aug 2019 16:24:22 +0800 Subject: [PATCH] net/fm10k: fix stats crash in multi-process The ops pointers in fm10k_stats_get() are set up from primary process, when secondary process calls these ops pointers, a segment fault will happen. Fixes: 7223d200c227 ("fm10k: add base driver") Cc: stable@dpdk.org Signed-off-by: Lu Qiuwen Acked-by: Xiao Wang Reviewed-by: Xiaolong Ye --- drivers/net/fm10k/base/fm10k_api.c | 20 ++++++++++++++++---- drivers/net/fm10k/base/fm10k_pf.c | 4 ++-- drivers/net/fm10k/base/fm10k_pf.h | 6 ++++++ drivers/net/fm10k/base/fm10k_vf.c | 4 ++-- drivers/net/fm10k/base/fm10k_vf.h | 5 +++++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/net/fm10k/base/fm10k_api.c b/drivers/net/fm10k/base/fm10k_api.c index 7802a1c38b..dfb50a10d1 100644 --- a/drivers/net/fm10k/base/fm10k_api.c +++ b/drivers/net/fm10k/base/fm10k_api.c @@ -205,8 +205,14 @@ s32 fm10k_read_mac_addr(struct fm10k_hw *hw) * */ void fm10k_update_hw_stats(struct fm10k_hw *hw, struct fm10k_hw_stats *stats) { - if (hw->mac.ops.update_hw_stats) - hw->mac.ops.update_hw_stats(hw, stats); + switch (hw->mac.type) { + case fm10k_mac_pf: + return fm10k_update_hw_stats_pf(hw, stats); + case fm10k_mac_vf: + return fm10k_update_hw_stats_vf(hw, stats); + default: + break; + } } /** @@ -217,8 +223,14 @@ void fm10k_update_hw_stats(struct fm10k_hw *hw, struct fm10k_hw_stats *stats) * */ void fm10k_rebind_hw_stats(struct fm10k_hw *hw, struct fm10k_hw_stats *stats) { - if (hw->mac.ops.rebind_hw_stats) - hw->mac.ops.rebind_hw_stats(hw, stats); + switch (hw->mac.type) { + case fm10k_mac_pf: + return fm10k_rebind_hw_stats_pf(hw, stats); + case fm10k_mac_vf: + return fm10k_rebind_hw_stats_vf(hw, stats); + default: + break; + } } /** diff --git a/drivers/net/fm10k/base/fm10k_pf.c b/drivers/net/fm10k/base/fm10k_pf.c index 3efe98cf4b..439dd224de 100644 --- a/drivers/net/fm10k/base/fm10k_pf.c +++ b/drivers/net/fm10k/base/fm10k_pf.c @@ -1482,7 +1482,7 @@ const struct fm10k_msg_data fm10k_iov_msg_data_pf[] = { * This function collects and aggregates global and per queue hardware * statistics. **/ -STATIC void fm10k_update_hw_stats_pf(struct fm10k_hw *hw, +void fm10k_update_hw_stats_pf(struct fm10k_hw *hw, struct fm10k_hw_stats *stats) { u32 timeout, ur, ca, um, xec, vlan_drop, loopback_drop, nodesc_drop; @@ -1555,7 +1555,7 @@ STATIC void fm10k_update_hw_stats_pf(struct fm10k_hw *hw, * This function resets the base for global and per queue hardware * statistics. **/ -STATIC void fm10k_rebind_hw_stats_pf(struct fm10k_hw *hw, +void fm10k_rebind_hw_stats_pf(struct fm10k_hw *hw, struct fm10k_hw_stats *stats) { DEBUGFUNC("fm10k_rebind_hw_stats_pf"); diff --git a/drivers/net/fm10k/base/fm10k_pf.h b/drivers/net/fm10k/base/fm10k_pf.h index a3c6133b7a..1c2e9994dc 100644 --- a/drivers/net/fm10k/base/fm10k_pf.h +++ b/drivers/net/fm10k/base/fm10k_pf.h @@ -155,4 +155,10 @@ extern const struct fm10k_msg_data fm10k_iov_msg_data_pf[]; #endif s32 fm10k_init_ops_pf(struct fm10k_hw *hw); + +void fm10k_update_hw_stats_pf(struct fm10k_hw *hw, + struct fm10k_hw_stats *stats); + +void fm10k_rebind_hw_stats_pf(struct fm10k_hw *hw, + struct fm10k_hw_stats *stats); #endif /* _FM10K_PF_H */ diff --git a/drivers/net/fm10k/base/fm10k_vf.c b/drivers/net/fm10k/base/fm10k_vf.c index d4e095bc00..6809c3cfd7 100644 --- a/drivers/net/fm10k/base/fm10k_vf.c +++ b/drivers/net/fm10k/base/fm10k_vf.c @@ -497,7 +497,7 @@ const struct fm10k_tlv_attr fm10k_1588_msg_attr[] = { * * This function collects and aggregates per queue hardware statistics. **/ -STATIC void fm10k_update_hw_stats_vf(struct fm10k_hw *hw, +void fm10k_update_hw_stats_vf(struct fm10k_hw *hw, struct fm10k_hw_stats *stats) { DEBUGFUNC("fm10k_update_hw_stats_vf"); @@ -512,7 +512,7 @@ STATIC void fm10k_update_hw_stats_vf(struct fm10k_hw *hw, * * This function resets the base for queue hardware statistics. **/ -STATIC void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw, +void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw, struct fm10k_hw_stats *stats) { DEBUGFUNC("fm10k_rebind_hw_stats_vf"); diff --git a/drivers/net/fm10k/base/fm10k_vf.h b/drivers/net/fm10k/base/fm10k_vf.h index 071fed2286..c90880df14 100644 --- a/drivers/net/fm10k/base/fm10k_vf.h +++ b/drivers/net/fm10k/base/fm10k_vf.h @@ -60,4 +60,9 @@ extern const struct fm10k_tlv_attr fm10k_1588_msg_attr[]; FM10K_MSG_HANDLER(FM10K_VF_MSG_ID_1588, fm10k_1588_msg_attr, func) s32 fm10k_init_ops_vf(struct fm10k_hw *hw); + +void fm10k_update_hw_stats_vf(struct fm10k_hw *hw, + struct fm10k_hw_stats *stats); +void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw, + struct fm10k_hw_stats *stats); #endif /* _FM10K_VF_H */ -- 2.20.1