Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1088372ybt; Wed, 1 Jul 2020 18:35:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh6RxNmrkYef3FGX7+iY2chYYezJA2x6vjmVsfH2HgANU+0vgI8F794DD3p0a5bgzwYPJL X-Received: by 2002:a17:906:2641:: with SMTP id i1mr18430919ejc.380.1593653756976; Wed, 01 Jul 2020 18:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593653756; cv=none; d=google.com; s=arc-20160816; b=pbzBi5vLHCbMM87i8Se/yCPkcpxXLE5wp/7LD/rWbAOSK8SFOfPOiHAHpl9EqN/aMa pjnWu9095B6rCTpj2aptHbfAjTir+aBMsvtLDNFqpW/JAJArsHMBhe6CqnzOHVzjkQuH rzSZnnRcAgF0KkvGtLDrno9uAZgoiQLrwLMG173cB/A7wxEHuAbgTJNSdBqi0ucFMn7x McSAc7Etf4s47oGViS3LDoV8SCRGv7pSxzy6YLgNOdkDl0cPhNx/viJUBvc+MF34YkfA 9foerXyQxRzr7HynCURVHVGkOqt9/b17OaPTwXLnkv/Uzd/kRnpE6WW/DnxW3Ze7as6/ fJ6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TDHUgR9kRV+kB0WWyFNjXVxtvQIRj1Z8UmEsYVmA7r0=; b=MW8KE9yQVuAODYnAaD4I3lzc49e/RzdGcSGJo092v8kj6h323599wW6kuhyjsNnUVG 2x/Qe0P5RlD4YaX1e18n6k6hHdIJeuvwaeGaBiE2RAcl32adB7QMt9tM0WMzIVSU1g1x UycM/IC0XOinnZraQBypYSy3GHVXBQqOMbNdlI3IkiUEeVNrySB4KVh8B5u866/qnchu HXYDY/G0hVzgG396/8CweRVXPTtuMznm08GiszMJAl6s1lqXplubW4EsxYs6Csmd9bvY 4ScsGo1y1V46N2PXVuItJzIkMjqmtHkogE23mkOYnMhW11NylbTp8TlRz3QLw+K9vXR3 kJuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="yGr/jOHa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k25si4844921ejv.672.2020.07.01.18.35.34; Wed, 01 Jul 2020 18:35:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="yGr/jOHa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729451AbgGBBfZ (ORCPT + 99 others); Wed, 1 Jul 2020 21:35:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:54016 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728350AbgGBBX2 (ORCPT ); Wed, 1 Jul 2020 21:23:28 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7AF722082F; Thu, 2 Jul 2020 01:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593653007; bh=ORPv43D/MfkF8nCaY6eTl41d5n0TRntKOvuBRXLyLPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yGr/jOHaa4V4iXHdx+2xpuIBRNH9nH6Z2TnK7EVMwcMohISwxkp1J35C551ykpU09 d3L44dcp4ZG0/TRGV/EPxFSI2fdHfg8oBqpm+6BADN/EYcqfilIU6mCP1QPnsyQP8W zQ6soI1ix7wvYuChq+ly8QXlnHVC6jJ4xjb2FnnA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ciara Loftus , Andrew Bowers , Jeff Kirsher , Sasha Levin , 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 Message-Id: <20200702012202.2700645-26-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200702012202.2700645-1-sashal@kernel.org> References: <20200702012202.2700645-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ciara Loftus [ 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 Tested-by: Andrew Bowers Signed-off-by: Jeff Kirsher Signed-off-by: Sasha Levin --- 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