Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3243283imc; Wed, 13 Mar 2019 12:32:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqzf7/zxdRcKUaoGvsv7VYjRdAYk22Gel7BCXm6t7frVxXWpDLwpRlruk25jKAZS8GQ3/N/I X-Received: by 2002:a62:20d2:: with SMTP id m79mr46621781pfj.135.1552505548337; Wed, 13 Mar 2019 12:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552505548; cv=none; d=google.com; s=arc-20160816; b=L1j76GZlJ39B77TD/FRDlwYBVcuIYRdYq+rxSh9QtfDg8BluvumJp1eNyiHHjCeRwZ TPS7eOOjDiDiu6isQKtpQPvnhuCMfOnm+qOUZtApxrhBxU2WTpzw1aw78gs4b/D4pHP2 20M04C7cEwEzHFGNnbnfZB/6ST/P045uxJ2ZtiF3yQzjAoPnv/H9M3vatqyhRdsi9Ohp 4CWpWuDneyop4VsUKYOTFBAzK/OpmrCe45Udg74mjdD8Ys0M0RWSasgXBJdfSa5xSo55 M33XN7SgrhidOFeuEq4JMyb14sUbn0swAu1eYA5XF4bT9txo0O3P89eMZcq0oMdE9b5K fCJg== 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=TIZTS48AOy20JYjgisLD1OXVRZqVCE2/rgCBwwjlIlY=; b=SuIc2vdA6SE0KmnbAJrSVVLPlyaPeKlrNY2aRkQKAHDdDr4NnNPnT2jpybaPUOCQYb erP7b7A5meMCEy/u+9CDtMPkez0/YO5sxQvuUjkKEr7PlJahTH4gF/gC276FuysyRL4C hkkQPPJADzf/KTWzaND66ob3XJ9cVdIy8lW97Ht0gJN0KtsCBmlmdfQ9arlCkA7Clof0 BX6hhpa95FOngbBOlIK6iPzW7so3TGLmWGf7hpmS8UDZS0hJdr4vDhqpF+fAlUmb5QoM ZMIoiip/L56sl2hEyzz6F6B+ocqEmSbVNyIl356cdoA/Yuz7RV6hOhmYUnqiN2yZpJyG fLIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=E0s8jvZf; 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 s194si10674829pgs.47.2019.03.13.12.32.12; Wed, 13 Mar 2019 12:32:28 -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=E0s8jvZf; 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 S1727617AbfCMTL5 (ORCPT + 99 others); Wed, 13 Mar 2019 15:11:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:42568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726861AbfCMTLz (ORCPT ); Wed, 13 Mar 2019 15:11:55 -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 4D0D12177E; Wed, 13 Mar 2019 19:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552504313; bh=eNXktylvWmCU1EFMqKLUXUs7PPiqVnFP3akKb2o7mNw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E0s8jvZfKRtV2R2kwZOyFoG73VqQA1fC9b/OYO8Z6BI3x0VATucOtFN3eoU8B6bhw VIic99xyGEogo6wUSN21tT0xt5I5oalH8NLg61PiimhMs/iL8kwJKEfHLZrd0QF2O2 uRDlcdLNB6+JoEiam6Z5qFS2eUMqVaJM9UXxzNWU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Magnus Karlsson , Jeff Kirsher , Sasha Levin , netdev@vger.kernel.org, xdp-newbies@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 4.20 41/60] i40e: fix potential RX buffer starvation for AF_XDP Date: Wed, 13 Mar 2019 15:10:02 -0400 Message-Id: <20190313191021.158171-41-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 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: Magnus Karlsson [ Upstream commit 14ffeb52f3693ae0b674e59453452a2365ae9fd9 ] When the RX rings are created they are also populated with buffers so that packets can be received. Usually these are kernel buffers, but for AF_XDP in zero-copy mode, these are user-space buffers and in this case the application might not have sent down any buffers to the driver at this point. And if no buffers are allocated at ring creation time, no packets can be received and no interrupts will be generated so the NAPI poll function that allocates buffers to the rings will never get executed. To rectify this, we kick the NAPI context of any queue with an attached AF_XDP zero-copy socket in two places in the code. Once after an XDP program has loaded and once after the umem is registered. This take care of both cases: XDP program gets loaded first then AF_XDP socket is created, and the reverse, AF_XDP socket is created first, then XDP program is loaded. Fixes: 0a714186d3c0 ("i40e: add AF_XDP zero-copy Rx support") Signed-off-by: Magnus Karlsson Tested-by: Andrew Bowers Signed-off-by: Jeff Kirsher Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/i40e/i40e_main.c | 13 ++++++++++++- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index f97c3d5ab884..89a072b5ce6c 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -3290,8 +3290,11 @@ static int i40e_configure_rx_ring(struct i40e_ring *ring) i40e_alloc_rx_buffers_zc(ring, I40E_DESC_UNUSED(ring)) : !i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); if (!ok) { + /* Log this in case the user has forgotten to give the kernel + * any buffers, even later in the application. + */ dev_info(&vsi->back->pdev->dev, - "Failed allocate some buffers on %sRx ring %d (pf_q %d)\n", + "Failed to allocate some buffers on %sRx ring %d (pf_q %d)\n", ring->xsk_umem ? "UMEM enabled " : "", ring->queue_index, pf_q); } @@ -11895,6 +11898,14 @@ static int i40e_xdp_setup(struct i40e_vsi *vsi, if (old_prog) bpf_prog_put(old_prog); + /* Kick start the NAPI context if there is an AF_XDP socket open + * on that queue id. This so that receiving will start. + */ + if (need_reset && prog) + for (i = 0; i < vsi->num_queue_pairs; i++) + if (vsi->xdp_rings[i]->xsk_umem) + (void)i40e_xsk_async_xmit(vsi->netdev, i); + return 0; } diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c index 870cf654e436..3827f16e6923 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c @@ -183,6 +183,11 @@ static int i40e_xsk_umem_enable(struct i40e_vsi *vsi, struct xdp_umem *umem, err = i40e_queue_pair_enable(vsi, qid); if (err) return err; + + /* Kick start the NAPI context so that receiving will start */ + err = i40e_xsk_async_xmit(vsi->netdev, qid); + if (err) + return err; } return 0; -- 2.19.1