From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Ciara Loftus <ciara.loftus@intel.com>,
Andrew Bowers <andrewx.bowers@intel.com>,
Jeff Kirsher <jeffrey.t.kirsher@intel.com>,
Sasha Levin <sashal@kernel.org>,
intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
bpf@vger.kernel.org
Subject: [PATCH AUTOSEL 5.7 26/53] i40e: protect ring accesses with READ- and WRITE_ONCE
Date: Wed, 1 Jul 2020 21:21:35 -0400 [thread overview]
Message-ID: <20200702012202.2700645-26-sashal@kernel.org> (raw)
In-Reply-To: <20200702012202.2700645-1-sashal@kernel.org>
From: Ciara Loftus <ciara.loftus@intel.com>
[ Upstream commit d59e267912cd90b0adf33b4659050d831e746317 ]
READ_ONCE should be used when reading rings prior to accessing the
statistics pointer. Introduce this as well as the corresponding WRITE_ONCE
usage when allocating and freeing the rings, to ensure protected access.
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/net/ethernet/intel/i40e/i40e_main.c | 29 ++++++++++++++-------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 2a037ec244b94..80dc5fcb82db7 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -439,11 +439,15 @@ static void i40e_get_netdev_stats_struct(struct net_device *netdev,
i40e_get_netdev_stats_struct_tx(ring, stats);
if (i40e_enabled_xdp_vsi(vsi)) {
- ring++;
+ ring = READ_ONCE(vsi->xdp_rings[i]);
+ if (!ring)
+ continue;
i40e_get_netdev_stats_struct_tx(ring, stats);
}
- ring++;
+ ring = READ_ONCE(vsi->rx_rings[i]);
+ if (!ring)
+ continue;
do {
start = u64_stats_fetch_begin_irq(&ring->syncp);
packets = ring->stats.packets;
@@ -787,6 +791,8 @@ static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
for (q = 0; q < vsi->num_queue_pairs; q++) {
/* locate Tx ring */
p = READ_ONCE(vsi->tx_rings[q]);
+ if (!p)
+ continue;
do {
start = u64_stats_fetch_begin_irq(&p->syncp);
@@ -800,8 +806,11 @@ static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
tx_linearize += p->tx_stats.tx_linearize;
tx_force_wb += p->tx_stats.tx_force_wb;
- /* Rx queue is part of the same block as Tx queue */
- p = &p[1];
+ /* locate Rx ring */
+ p = READ_ONCE(vsi->rx_rings[q]);
+ if (!p)
+ continue;
+
do {
start = u64_stats_fetch_begin_irq(&p->syncp);
packets = p->stats.packets;
@@ -10816,10 +10825,10 @@ static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
if (vsi->tx_rings && vsi->tx_rings[0]) {
for (i = 0; i < vsi->alloc_queue_pairs; i++) {
kfree_rcu(vsi->tx_rings[i], rcu);
- vsi->tx_rings[i] = NULL;
- vsi->rx_rings[i] = NULL;
+ WRITE_ONCE(vsi->tx_rings[i], NULL);
+ WRITE_ONCE(vsi->rx_rings[i], NULL);
if (vsi->xdp_rings)
- vsi->xdp_rings[i] = NULL;
+ WRITE_ONCE(vsi->xdp_rings[i], NULL);
}
}
}
@@ -10853,7 +10862,7 @@ static int i40e_alloc_rings(struct i40e_vsi *vsi)
if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
ring->itr_setting = pf->tx_itr_default;
- vsi->tx_rings[i] = ring++;
+ WRITE_ONCE(vsi->tx_rings[i], ring++);
if (!i40e_enabled_xdp_vsi(vsi))
goto setup_rx;
@@ -10871,7 +10880,7 @@ static int i40e_alloc_rings(struct i40e_vsi *vsi)
ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
set_ring_xdp(ring);
ring->itr_setting = pf->tx_itr_default;
- vsi->xdp_rings[i] = ring++;
+ WRITE_ONCE(vsi->xdp_rings[i], ring++);
setup_rx:
ring->queue_index = i;
@@ -10884,7 +10893,7 @@ static int i40e_alloc_rings(struct i40e_vsi *vsi)
ring->size = 0;
ring->dcb_tc = 0;
ring->itr_setting = pf->rx_itr_default;
- vsi->rx_rings[i] = ring;
+ WRITE_ONCE(vsi->rx_rings[i], ring);
}
return 0;
--
2.25.1
next prev parent reply other threads:[~2020-07-02 1:35 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-02 1:21 [PATCH AUTOSEL 5.7 01/53] soc: ti: omap-prm: use atomic iopoll instead of sleeping one Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 02/53] regmap: fix alignment issue Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 03/53] perf/x86/rapl: Move RAPL support to common x86 code Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 04/53] perf/x86/rapl: Fix RAPL config variable bug Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 05/53] ARM: dts: omap4-droid4: Fix spi configuration and increase rate Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 06/53] drm/ttm: Fix dma_fence refcnt leak in ttm_bo_vm_fault_reserved Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 07/53] drm/ttm: Fix dma_fence refcnt leak when adding move fence Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 08/53] gpu: host1x: Clean up debugfs in error handling path Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 09/53] drm/tegra: hub: Do not enable orphaned window group Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 10/53] gpu: host1x: Detach driver on unregister Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 11/53] btrfs: use kfree() in btrfs_ioctl_get_subvol_info() Sasha Levin
2020-07-02 8:25 ` David Sterba
2020-07-09 22:28 ` Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 12/53] staging: wfx: fix coherency of hif_scan() prototype Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 13/53] drm: mcde: Fix display initialization problem Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 14/53] ASoC: SOF: Intel: add PCI ID for CometLake-S Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 15/53] ASoC: SOF: Intel: add PCI IDs for ICL-H and TGL-H Sasha Levin
2020-07-02 11:18 ` Mark Brown
2020-07-02 15:42 ` Pierre-Louis Bossart
2020-07-02 16:05 ` Mark Brown
2020-07-09 22:29 ` Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 16/53] ASoC: hdac_hda: fix memleak with regmap not freed on remove Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 17/53] net: usb: ax88179_178a: fix packet alignment padding Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 18/53] ALSA: hda: Intel: add missing PCI IDs for ICL-H, TGL-H and EKL Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 19/53] usb: usbtest: fix missing kfree(dev->buf) in usbtest_disconnect Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 20/53] spi: spidev: fix a race between spidev_release and spidev_remove Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 21/53] spi: spidev: fix a potential use-after-free in spidev_release() Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 22/53] net: ethernet: mvneta: Fix Serdes configuration for SoCs without comphy Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 23/53] net: ethernet: mvneta: Add 2500BaseX support " Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 24/53] tg3: driver sleeps indefinitely when EEH errors exceed eeh_max_freezes Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 25/53] ixgbe: protect ring accesses with READ- and WRITE_ONCE Sasha Levin
2020-07-02 1:21 ` Sasha Levin [this message]
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 27/53] ice: protect ring accesses with WRITE_ONCE Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 28/53] ibmvnic: continue to init in CRQ reset returns H_CLOSED Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 29/53] powerpc/kvm/book3s64: Fix kernel crash with nested kvm & DEBUG_VIRTUAL Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 30/53] xprtrdma: Prevent dereferencing r_xprt->rx_ep after it is freed Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 31/53] usbnet: smsc95xx: Fix use-after-free after removal Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 32/53] iommu/vt-d: Don't apply gfx quirks to untrusted devices Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 33/53] drm: panel-orientation-quirks: Add quirk for Asus T101HA panel Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 34/53] drm: panel-orientation-quirks: Use generic orientation-data for Acer S1003 Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 35/53] s390/kasan: fix early pgm check handler execution Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 36/53] s390/debug: avoid kernel warning on too large number of pages Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 37/53] cifs: Fix double add page to memcg when cifs_readpages Sasha Levin
2020-07-02 16:08 ` Pavel Shilovsky
2020-07-09 23:49 ` Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 38/53] drm/sun4i: mixer: Call of_dma_configure if there's an IOMMU Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 39/53] io_uring: fix io_sq_thread no schedule when busy Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 40/53] cifs: update ctime and mtime during truncate Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 41/53] ARM: imx6: add missing put_device() call in imx6q_suspend_init() Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 42/53] scsi: qla2xxx: Fix MPI failure AEN (8200) handling Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 43/53] scsi: mptscsih: Fix read sense data size Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 44/53] usb: dwc3: pci: Fix reference count leak in dwc3_pci_resume_work Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 45/53] arm64: kpti: Add KRYO{3, 4}XX silver CPU cores to kpti safelist Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 46/53] block: release bip in a right way in error path Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 47/53] nvme-rdma: assign completion vector correctly Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 48/53] x86/entry: Increase entry_stack size to a full page Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 49/53] io_uring: fix current->mm NULL dereference on exit Sasha Levin
2020-07-02 1:21 ` [PATCH AUTOSEL 5.7 50/53] arm64: Add KRYO{3,4}XX silver CPU cores to SSB safelist Sasha Levin
2020-07-02 1:22 ` [PATCH AUTOSEL 5.7 51/53] nfs: Fix memory leak of export_path Sasha Levin
2020-07-02 1:22 ` [PATCH AUTOSEL 5.7 52/53] kgdb: Avoid suspicious RCU usage warning Sasha Levin
2020-07-02 1:22 ` [PATCH AUTOSEL 5.7 53/53] sched/core: Check cpus_mask, not cpus_ptr in __set_cpus_allowed_ptr(), to fix mask corruption Sasha Levin
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=20200702012202.2700645-26-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andrewx.bowers@intel.com \
--cc=bpf@vger.kernel.org \
--cc=ciara.loftus@intel.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jeffrey.t.kirsher@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).