Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3243017imc; Wed, 13 Mar 2019 12:32:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHw6ZUu/Od/j4eDwrE5f5Lp8a4IafH/OboVY8ieYgqK5yqUZEJzHJJh+HPI0/ulZYmdDU6 X-Received: by 2002:a63:e813:: with SMTP id s19mr40876861pgh.12.1552505524459; Wed, 13 Mar 2019 12:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552505524; cv=none; d=google.com; s=arc-20160816; b=eu0dnGEhVtX8KdEASEpFn2yKXOrnLoR+vV/x906tszKnDulTPnj4hCLfS7H+xHt99o 2jEXSiTFMcjYuGfaw5pKBiE4QK8leQBGe6ncfIlP08WWTWPS84OXgfgN5K3Q5lN6qr8n B/5xATY1/POTwLz8hYemKuib1WTDNYZTHmeZqExJWKOmW4z1LARaQDOjHVHub0JE/Ikg dL5v/ETLwER9gRrWskLR1bXxDg1oq/7+jcrmLizvBRFwyE5dt3IBrUV5VtIK2yxyz4YB pFT4sZWmHBbwQRkgPhO+SWCr0rSYc9J0/S3CrX+fAGmMzIdsjBGGB7XHadkS/yeUp/nw QPhA== 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=igP6izJF0oZeQbr11cnl6opKhr7+nhSzCBKEGQUQPqw=; b=LYS26PgsT7riOEWAebpc88J/51g0xd67KDXklhM64GwuFdi4+iYXophBw7njPWGi+W qLfQVNw9pbDBzMBjlbNTRSbTSrJi17kZsU1AOkOJ59fSlhTyGYj2oSdsYhcrdYhaaP4u u1UMLoKUb9uC7lyB92opvCr96eHUJjQ/jHKmM/aO6M5Ti6bJNkNDPcb1zW7ygBv31uvz nU1W+89axglg/U8HPk8qP5r4ZymBC2DVt5SuX5Wfe+BBznMDRn46Gd4AHT1Zjru/0dZl aDZuRZE3T/7BzI23/uti6nI8Im/LVQElqmJ3b0/ZncsLjakQGnUjth2NrjaXMlK+RSxi JDZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hNek0vww; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id 64si8501371plk.279.2019.03.13.12.31.47; Wed, 13 Mar 2019 12:32:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hNek0vww; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728175AbfCMTa4 (ORCPT + 99 others); Wed, 13 Mar 2019 15:30:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:42840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727673AbfCMTMO (ORCPT ); Wed, 13 Mar 2019 15:12:14 -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 B8944218A3; Wed, 13 Mar 2019 19:12:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552504332; bh=h2MFCwwsmU3xjvucEjhoBHxfSnw3tolqy0wBMXmZddQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hNek0vwwgLWm07JbJSmDpEae8yLjzYtbL1wjhkSKYcBeMMORosHjXWoQxN7F56CFV BRgxf43IGPfr8mEem+UR8a3EodaWWc+VDi5S4EsGdVxWhJRyb2PL8qoQVuE+j0Hr/k B2dS8cGI6Ah3FIqk4O7ECnFsPkDYLTXWNvL8d0nM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Jeff Kirsher , Sasha Levin , netdev@vger.kernel.org, xdp-newbies@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 4.20 46/60] i40e: fix XDP_REDIRECT/XDP xmit ring cleanup race Date: Wed, 13 Mar 2019 15:10:07 -0400 Message-Id: <20190313191021.158171-46-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190313191021.158171-1-sashal@kernel.org> References: <20190313191021.158171-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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: Björn Töpel [ Upstream commit 59eb2a884f5380011179acc4662fc2cc2d850454 ] When the driver clears the XDP xmit ring due to re-configuration or teardown, in-progress ndo_xdp_xmit must be taken into consideration. The ndo_xdp_xmit function is typically called from a NAPI context that the driver does not control. Therefore, we must be careful not to clear the XDP ring, while the call is on-going. This patch adds a synchronize_rcu() to wait for napi(s) (preempt-disable regions and softirqs), prior clearing the queue. Further, the __I40E_CONFIG_BUSY flag is checked in the ndo_xdp_xmit implementation to avoid touching the XDP xmit queue during re-configuration. Fixes: d9314c474d4f ("i40e: add support for XDP_REDIRECT") Fixes: 123cecd427b6 ("i40e: added queue pair disable/enable functions") Reported-by: Maciej Fijalkowski Signed-off-by: Björn Töpel Signed-off-by: Jeff Kirsher Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/i40e/i40e_main.c | 14 ++++++++++++-- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 89a072b5ce6c..393647153857 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -6729,8 +6729,13 @@ void i40e_down(struct i40e_vsi *vsi) for (i = 0; i < vsi->num_queue_pairs; i++) { i40e_clean_tx_ring(vsi->tx_rings[i]); - if (i40e_enabled_xdp_vsi(vsi)) + if (i40e_enabled_xdp_vsi(vsi)) { + /* Make sure that in-progress ndo_xdp_xmit + * calls are completed. + */ + synchronize_rcu(); i40e_clean_tx_ring(vsi->xdp_rings[i]); + } i40e_clean_rx_ring(vsi->rx_rings[i]); } @@ -11966,8 +11971,13 @@ static void i40e_queue_pair_reset_stats(struct i40e_vsi *vsi, int queue_pair) static void i40e_queue_pair_clean_rings(struct i40e_vsi *vsi, int queue_pair) { i40e_clean_tx_ring(vsi->tx_rings[queue_pair]); - if (i40e_enabled_xdp_vsi(vsi)) + if (i40e_enabled_xdp_vsi(vsi)) { + /* Make sure that in-progress ndo_xdp_xmit calls are + * completed. + */ + synchronize_rcu(); i40e_clean_tx_ring(vsi->xdp_rings[queue_pair]); + } i40e_clean_rx_ring(vsi->rx_rings[queue_pair]); } diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c index d0a95424ce58..48a0d8a53895 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c @@ -3708,6 +3708,7 @@ int i40e_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames, struct i40e_netdev_priv *np = netdev_priv(dev); unsigned int queue_index = smp_processor_id(); struct i40e_vsi *vsi = np->vsi; + struct i40e_pf *pf = vsi->back; struct i40e_ring *xdp_ring; int drops = 0; int i; @@ -3715,7 +3716,8 @@ int i40e_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames, if (test_bit(__I40E_VSI_DOWN, vsi->state)) return -ENETDOWN; - if (!i40e_enabled_xdp_vsi(vsi) || queue_index >= vsi->num_queue_pairs) + if (!i40e_enabled_xdp_vsi(vsi) || queue_index >= vsi->num_queue_pairs || + test_bit(__I40E_CONFIG_BUSY, pf->state)) return -ENXIO; if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) -- 2.19.1