Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3243115imc; Wed, 13 Mar 2019 12:32:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkI8N87+LmndRuj9rQJJsZiT582PK64aHJtWRseuYbAbKd2YZiKrh3jNxfwI1TB821RgNS X-Received: by 2002:aa7:9141:: with SMTP id 1mr45242283pfi.38.1552505532322; Wed, 13 Mar 2019 12:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552505532; cv=none; d=google.com; s=arc-20160816; b=A7BzVLdr8unhAI4aWafp7Inr2vjLoFZAgiwk6vOdwPK29BqHESuzaidlVK7SaJg9Th N7eg8Gk4XnjZYYBAj0fU+SflrWojKmoUsVyN2pDHJu/IlV+Pd/zs6u3VMs1b7KQFtvtx BdKp6f3mgDnJpveIlpT1/h9ga4lVpMhKNnVzRfs95fsdU/FKW8oIpEGz4ntymM2sU9D+ EeBCyH+IpBqN6EI9boYDlP3OXGm3yfvQP/YtM7mUr6R3NfBMgWtuXSxzngqHqu3+bJ5o 6mCkBXiiQkFkCCPb6egdjw1xPemWLXmp6awoyw5rWuWV+hvQqWXb/8Ln/dwl2dSkU/S+ ciIg== 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=ZCaaTSnkE3jolwKqmypQlxNTJgIxmEVZAH85a1nqDTs=; b=J/QLaoetWOznuQJnQp45H5hibsUunDAYAhVXpgH9gUa7i6R+q0I4lK+ZsrOzu2JviT 7ewntGTvcOpG3LEzK/rMRDW9+WcgGgHe5vTJhgA2nqwS7Y5wmOVg1ZIzWpgiW/5EC9kp qg1sXacJH4W5K8P7b41kh8+321D9bB03i9RVk/MCDYzLCKGZVZLgPfsqFYHIzocUXBDr kSWB4heIoZHs4wjxaTj7pR4OeHug7dynxhPEfy0oOaMBW2DESvKJsIPc7AfJuEbXMgb1 gkAHjb/aJlgwyakgRDDdg9tL/58CuI5ak8JYrjOEWyhJPx7/Z6OMphS3833v0oMnaE54 J+xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uS9OwW+9; 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 d23si11431904pfm.181.2019.03.13.12.31.56; Wed, 13 Mar 2019 12:32:12 -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=uS9OwW+9; 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 S1727636AbfCMTMA (ORCPT + 99 others); Wed, 13 Mar 2019 15:12:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:42622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727611AbfCMTL5 (ORCPT ); Wed, 13 Mar 2019 15:11:57 -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 56EB12173C; Wed, 13 Mar 2019 19:11:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552504316; bh=pIxf4BS8JJGwfL9mjosrFoChjL0yXeHt9nthO0IPsuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uS9OwW+9V9r9RZylHY7b3GZIv5pRM1IqevB1FhtZwS8dtsmE+51PUGPulDHZjdv8P 3KtY7ofYSnJOs+RHSzVUzz/i+MXTnt+JE0bf/nhJHOBeo6jMheyeF+S6v6JIDMvi+W mtaXJuOuuxU4nnmjfY1SCiLIdnvKNcCOb9ou49gI= 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 42/60] ixgbe: fix potential RX buffer starvation for AF_XDP Date: Wed, 13 Mar 2019 15:10:03 -0400 Message-Id: <20190313191021.158171-42-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 4a9b32f30f805ca596d76605903a48eab58e0b88 ] 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: d0bcacd0a130 ("ixgbe: 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/ixgbe/ixgbe_main.c | 12 +++++++++++- drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 12 ++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c index aed1890514d6..8c47451f17f1 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c @@ -10207,6 +10207,7 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog) int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; struct ixgbe_adapter *adapter = netdev_priv(dev); struct bpf_prog *old_prog; + bool need_reset; if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) return -EINVAL; @@ -10229,9 +10230,10 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog) return -ENOMEM; old_prog = xchg(&adapter->xdp_prog, prog); + need_reset = (!!prog != !!old_prog); /* If transitioning XDP modes reconfigure rings */ - if (!!prog != !!old_prog) { + if (need_reset) { int err = ixgbe_setup_tc(dev, adapter->hw_tcs); if (err) { @@ -10247,6 +10249,14 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog) 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 < adapter->num_rx_queues; i++) + if (adapter->xdp_ring[i]->xsk_umem) + (void)ixgbe_xsk_async_xmit(adapter->netdev, i); + return 0; } diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c index 65c3e2c979d4..654ae92342ea 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c @@ -144,11 +144,19 @@ static int ixgbe_xsk_umem_enable(struct ixgbe_adapter *adapter, ixgbe_txrx_ring_disable(adapter, qid); err = ixgbe_add_xsk_umem(adapter, umem, qid); + if (err) + return err; - if (if_running) + if (if_running) { ixgbe_txrx_ring_enable(adapter, qid); - return err; + /* Kick start the NAPI context so that receiving will start */ + err = ixgbe_xsk_async_xmit(adapter->netdev, qid); + if (err) + return err; + } + + return 0; } static int ixgbe_xsk_umem_disable(struct ixgbe_adapter *adapter, u16 qid) -- 2.19.1