From patchwork Fri Jan 17 15:18:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Fijalkowski X-Patchwork-Id: 13943443 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8BA319ADA4 for ; Fri, 17 Jan 2025 15:19:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737127165; cv=none; b=sI9yClxba/u+bu/RQFj+qsi4FZECN07O3YJYfFzV+J8isVMRaPG76/FbBioEjUtS47bkEV39YQhbuGGua8Jtcy+kl5Z6+T0OVSzY7YGPM64958MDSn+ugTYg3KZtt8CrEhXEy8ezeJD+dTS6i32FxhrZQZtzGnjGF0cDmm3aQpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737127165; c=relaxed/simple; bh=pXZSZ+TgLF8TssBvRmeh5b/o1fsmuwuJIZalOf+X/G0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ac7Ve1YAub1p3qJeIvsQlB8HweY6iLhPx34D2E6Wj798SqXVlqAhOf4PyFIKlkv5Fxoz7NSpy1kv80yBGRUytavoaCifPBtmaP0ybAsRpdMRXlifQRb1/gjjiNsg2i9wbb/aT5wgfFLgibz8HRe8ls0HPA9wyj0passS79nLpwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=eIo8bYr4; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="eIo8bYr4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1737127164; x=1768663164; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pXZSZ+TgLF8TssBvRmeh5b/o1fsmuwuJIZalOf+X/G0=; b=eIo8bYr4kIenLpxZVZwB9FeuySFrkoVfitmgLdUBJFnMWXlo9Dd5LpQL ABhLz2jPZ+hjeblJh9DfozUlNJidFQU3dpre1fMrp8J7Cl/JTk+Ke8KVq mhnNnBaNusrLEfpGknjowH6PZ9gOvWqavBVbJ/VdIFD4zO+ph5rMe+CZe qG98BS1eaQh5C+Ydtrp3cVnZpPaOFp52eRWFuldCkutd3dfHP9VtJ9hZA RZATPSAGfbgQEnIN2XT9SW+gn+IljhWUx/XsswBY5TCa/ROsPvaxx4m0E P/uH0Xt6RPrC96YhSJTS2zNtNv06aZSJ5DGI8Vq/F4BAjB786HD/r1ZUO w==; X-CSE-ConnectionGUID: GZMi+bkCSQSkE9hDVaY6Eg== X-CSE-MsgGUID: uOPl3sUnT1WBy6MiT1hDzA== X-IronPort-AV: E=McAfee;i="6700,10204,11318"; a="37798411" X-IronPort-AV: E=Sophos;i="6.13,212,1732608000"; d="scan'208";a="37798411" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2025 07:19:23 -0800 X-CSE-ConnectionGUID: f/O63y89S/OEPIMjy8wdXw== X-CSE-MsgGUID: lONvAQeWSqirQFUYjTvpuw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,212,1732608000"; d="scan'208";a="136664383" Received: from boxer.igk.intel.com ([10.102.20.173]) by orviesa002.jf.intel.com with ESMTP; 17 Jan 2025 07:19:20 -0800 From: Maciej Fijalkowski To: intel-wired-lan@lists.osuosl.org Cc: netdev@vger.kernel.org, anthony.l.nguyen@intel.com, magnus.karlsson@intel.com, jacob.e.keller@intel.com, xudu@redhat.com, mschmidt@redhat.com, jmaxwell@redhat.com, poros@redhat.com, przemyslaw.kitszel@intel.com, Maciej Fijalkowski Subject: [PATCH v2 intel-net 2/3] ice: gather page_count()'s of each frag right before XDP prog call Date: Fri, 17 Jan 2025 16:18:59 +0100 Message-Id: <20250117151900.525509-3-maciej.fijalkowski@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250117151900.525509-1-maciej.fijalkowski@intel.com> References: <20250117151900.525509-1-maciej.fijalkowski@intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org If we store the pgcnt on few fragments while being in the middle of gathering the whole frame and we stumbled upon DD bit not being set, we terminate the NAPI Rx processing loop and come back later on. Then on next NAPI execution we work on previously stored pgcnt. Imagine that second half of page was used actively by networking stack and by the time we came back, stack is not busy with this page anymore and decremented the refcnt. The page reuse algorithm in this case should be good to reuse the page but given the old refcnt it will not do so and attempt to release the page via page_frag_cache_drain() with pagecnt_bias used as an arg. This in turn will result in negative refcnt on struct page, which was initially observed by Xu Du. Therefore, move the page count storage from ice_get_rx_buf() to a place where we are sure that whole frame has been collected, but before calling XDP program as it internally can also change the page count of fragments belonging to xdp_buff. Fixes: ac0753391195 ("ice: Store page count inside ice_rx_buf") Reported-and-tested-by: Xu Du Reviewed-by: Przemek Kitszel Co-developed-by: Jacob Keller Signed-off-by: Jacob Keller Signed-off-by: Maciej Fijalkowski --- drivers/net/ethernet/intel/ice/ice_txrx.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_txrx.c b/drivers/net/ethernet/intel/ice/ice_txrx.c index f2134ad57ead..9aa53ad2d8f2 100644 --- a/drivers/net/ethernet/intel/ice/ice_txrx.c +++ b/drivers/net/ethernet/intel/ice/ice_txrx.c @@ -924,7 +924,6 @@ ice_get_rx_buf(struct ice_rx_ring *rx_ring, const unsigned int size, struct ice_rx_buf *rx_buf; rx_buf = &rx_ring->rx_buf[ntc]; - rx_buf->pgcnt = page_count(rx_buf->page); prefetchw(rx_buf->page); if (!size) @@ -940,6 +939,22 @@ ice_get_rx_buf(struct ice_rx_ring *rx_ring, const unsigned int size, return rx_buf; } +static void ice_get_pgcnts(struct ice_rx_ring *rx_ring) +{ + u32 nr_frags = rx_ring->nr_frags + 1; + u32 idx = rx_ring->first_desc; + struct ice_rx_buf *rx_buf; + u32 cnt = rx_ring->count; + + for (int i = 0; i < nr_frags; i++) { + rx_buf = &rx_ring->rx_buf[idx]; + rx_buf->pgcnt = page_count(rx_buf->page); + + if (++idx == cnt) + idx = 0; + } +} + /** * ice_build_skb - Build skb around an existing buffer * @rx_ring: Rx descriptor ring to transact packets on @@ -1230,6 +1245,7 @@ int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget) if (ice_is_non_eop(rx_ring, rx_desc)) continue; + ice_get_pgcnts(rx_ring); ice_run_xdp(rx_ring, xdp, xdp_prog, xdp_ring, rx_buf, rx_desc); if (rx_buf->act == ICE_XDP_PASS) goto construct_skb;