From: Alice Michael <alice.michael@intel.com>
To: intel-wired-lan@osuosl.org
Subject: [Intel-wired-lan] [next PATCH S92 2/9] i40e: always return VEB stat strings
Date: Thu, 17 May 2018 01:08:33 -0700 [thread overview]
Message-ID: <20180517080840.30192-2-alice.michael@intel.com> (raw)
In-Reply-To: <20180517080840.30192-1-alice.michael@intel.com>
From: Jacob Keller <jacob.e.keller@intel.com>
The ethtool API for obtaining device statistics is not intended to allow
runtime changes in the number of statistics reported. It may *appear*
this way, as there is an ability to request the number of stats using
ethtool_get_set_count(). However, it is expected that this must always
return the same value for invocations of the same device.
If we don't satisfy this contract, and allow the number of stats to
change during run time, we could cause invalid memory accesses or report
the stat strings incorrectly. This is because the API for obtaining
stats is to (1) get the size, (2) get the strings and finally (3) get
the stats. Since these are each separate ethtool op commands, it is not
possible to maintain consistency by holding the RTNL lock over the whole
operation. This results in the potential for a race condition to occur
where the size changed between any of the 3 calls.
Avoid this issue by requiring that we always return the same value for
a given device. We can check any values which remain constant for the
life of the device, but must not report different sizes depending on
runtime attributes.
This patch specifically fixes the VEB statistics strings to always be
reported. Other issues will be fixed in future patches.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 52 ++++++++++++--------------
1 file changed, 23 insertions(+), 29 deletions(-)
diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
index 4b78225..5a0e4d4 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
@@ -1541,15 +1541,10 @@ static int i40e_get_stats_count(struct net_device *netdev)
struct i40e_vsi *vsi = np->vsi;
struct i40e_pf *pf = vsi->back;
- if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
- if (pf->lan_veb != I40E_NO_VEB &&
- pf->flags & I40E_FLAG_VEB_STATS_ENABLED)
- return I40E_PF_STATS_LEN(netdev) + I40E_VEB_STATS_TOTAL;
- else
- return I40E_PF_STATS_LEN(netdev);
- } else {
+ if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1)
+ return I40E_PF_STATS_LEN(netdev) + I40E_VEB_STATS_TOTAL;
+ else
return I40E_VSI_STATS_LEN(netdev);
- }
}
static int i40e_get_sset_count(struct net_device *netdev, int sset)
@@ -1640,6 +1635,8 @@ static void i40e_get_ethtool_stats(struct net_device *netdev,
data[i++] = veb->tc_stats.tc_rx_packets[j];
data[i++] = veb->tc_stats.tc_rx_bytes[j];
}
+ } else {
+ i += I40E_VEB_STATS_TOTAL;
}
for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
@@ -1696,27 +1693,24 @@ static void i40e_get_strings(struct net_device *netdev, u32 stringset,
if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
return;
- if ((pf->lan_veb != I40E_NO_VEB) &&
- (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
- for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
- snprintf(p, ETH_GSTRING_LEN, "veb.%s",
- i40e_gstrings_veb_stats[i].stat_string);
- p += ETH_GSTRING_LEN;
- }
- for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
- snprintf(p, ETH_GSTRING_LEN,
- "veb.tc_%d_tx_packets", i);
- p += ETH_GSTRING_LEN;
- snprintf(p, ETH_GSTRING_LEN,
- "veb.tc_%d_tx_bytes", i);
- p += ETH_GSTRING_LEN;
- snprintf(p, ETH_GSTRING_LEN,
- "veb.tc_%d_rx_packets", i);
- p += ETH_GSTRING_LEN;
- snprintf(p, ETH_GSTRING_LEN,
- "veb.tc_%d_rx_bytes", i);
- p += ETH_GSTRING_LEN;
- }
+ for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
+ snprintf(p, ETH_GSTRING_LEN, "veb.%s",
+ i40e_gstrings_veb_stats[i].stat_string);
+ p += ETH_GSTRING_LEN;
+ }
+ for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
+ snprintf(p, ETH_GSTRING_LEN,
+ "veb.tc_%u_tx_packets", i);
+ p += ETH_GSTRING_LEN;
+ snprintf(p, ETH_GSTRING_LEN,
+ "veb.tc_%u_tx_bytes", i);
+ p += ETH_GSTRING_LEN;
+ snprintf(p, ETH_GSTRING_LEN,
+ "veb.tc_%u_rx_packets", i);
+ p += ETH_GSTRING_LEN;
+ snprintf(p, ETH_GSTRING_LEN,
+ "veb.tc_%u_rx_bytes", i);
+ p += ETH_GSTRING_LEN;
}
for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
snprintf(p, ETH_GSTRING_LEN, "port.%s",
--
2.9.5
next prev parent reply other threads:[~2018-05-17 8:08 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-17 8:08 [Intel-wired-lan] [next PATCH S92 1/9] i40e: free skb after clearing lock in ptp_stop Alice Michael
2018-05-17 8:08 ` Alice Michael [this message]
2018-05-17 22:10 ` [Intel-wired-lan] [next PATCH S92 2/9] i40e: always return VEB stat strings Bowers, AndrewX
2018-05-17 8:08 ` [Intel-wired-lan] [next PATCH S92 3/9] i40e: always return all queue " Alice Michael
2018-05-17 22:12 ` Bowers, AndrewX
2018-05-17 8:08 ` [Intel-wired-lan] [next PATCH S92 4/9] i40e: split i40e_get_strings() into smaller functions Alice Michael
2018-05-17 22:12 ` Bowers, AndrewX
2018-05-17 8:08 ` [Intel-wired-lan] [next PATCH S92 5/9] i40e: use WARN_ONCE to replace the commented BUG_ON size check Alice Michael
2018-05-17 22:13 ` Bowers, AndrewX
2018-05-17 8:08 ` [Intel-wired-lan] [next PATCH S92 6/9] i40e: fold prefix strings directly into stat names Alice Michael
2018-05-17 22:13 ` Bowers, AndrewX
2018-05-17 8:08 ` [Intel-wired-lan] [next PATCH S92 7/9] i40e: update data pointer directly when copying to the buffer Alice Michael
2018-05-17 19:13 ` Shannon Nelson
2018-05-17 22:14 ` Bowers, AndrewX
2018-05-17 8:08 ` [Intel-wired-lan] [next PATCH S92 8/9] i40e: add function doc headers for ethtool stats functions Alice Michael
2018-05-17 22:15 ` Bowers, AndrewX
2018-05-17 8:08 ` [Intel-wired-lan] [next PATCH S92 9/9] i40e: use the more traditional 'i' loop variable Alice Michael
2018-05-17 22:15 ` Bowers, AndrewX
2018-05-17 22:10 ` [Intel-wired-lan] [next PATCH S92 1/9] i40e: free skb after clearing lock in ptp_stop Bowers, AndrewX
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180517080840.30192-2-alice.michael@intel.com \
--to=alice.michael@intel.com \
--cc=intel-wired-lan@osuosl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox