From patchwork Tue Mar 18 20:04:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 14021508 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 BCFCC1DC9BA for ; Tue, 18 Mar 2025 20:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328322; cv=none; b=XIrKoZJGcpTwxY9TCfY8a2/dIBv5fgktJ/0qAI5tpBImXYBgxMMQ9g6Z4ZxJt32IkBG5FhF3lb0TwRJssodNwUPHMv2JRE3/8qsJKW5nhhzXAOz3q3VlHoyXVW0XMegBGXCAx88ozeWoSYPgo3qDCxUhspTE4Vwa0NT/xXviBdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328322; c=relaxed/simple; bh=Rkkm5bbeS//M3rYAjHlDLinhHjL45pJ9oUu2SwinxMg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q3DQwhOXu4hjkgO6NDBseo0tm5+ShoW/DV8JD++YxdT6Jf+U6y/c5zpC4izD0Mia6ht3XvwQW7N55O0LL4KGo0GoghzAoh71UpT1Y2TZsUUWnUDdLr6F88Pf+X856hWmCKVMQsLa81Iwfv6qZ5eZHdG72A4uvTqAvR1K4JnV/7E= 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=mHssNSZk; arc=none smtp.client-ip=198.175.65.16 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="mHssNSZk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742328321; x=1773864321; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rkkm5bbeS//M3rYAjHlDLinhHjL45pJ9oUu2SwinxMg=; b=mHssNSZkfEFjBcovhgc+KVbRGPRnbLv7TwsQTiE8L8Djzv/A8Khej20s 7nZbsymgw2BIjpbpjOs1U8ycINhoEKtRtI5YsFwYZn89n3YMUnhAKJ0UW 04Wr66Txzpau/KjKrbKaM1ItPQkWxjjjoccjjlEG68E38ZoEMo3mZ9+lI voGAKE87lW6bHMHiHWlU4qKWcjWQVdfP7K9rkTQFeHHK8K81S3OEXpcOp UcEV3gRmVMv2OLCuJ0YnNqPF60emaMbRktPErmVFdB3E+ZdrHNMRWGwj0 Czdp2ZWO3o+lZpAvehE2SIqzPagtlqwZ9YlF/Fx6vluhcFxOfccbgqCRT w==; X-CSE-ConnectionGUID: jFZy9FFeQwCITB3Ct0ck8Q== X-CSE-MsgGUID: wrQTpz8QTEeHadOm2PR6Bg== X-IronPort-AV: E=McAfee;i="6700,10204,11377"; a="43593009" X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="43593009" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 13:05:19 -0700 X-CSE-ConnectionGUID: V0LKrlPZSSGTRt2ZEumgpw== X-CSE-MsgGUID: HE3HtwHrT92tVOkX2vOobg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="153363123" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by fmviesa001.fm.intel.com with ESMTP; 18 Mar 2025 13:05:18 -0700 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, andrew+netdev@lunn.ch, netdev@vger.kernel.org Cc: Przemek Kitszel , anthony.l.nguyen@intel.com, konrad.knitter@intel.com, horms@kernel.org, kees@kernel.org, jirislaby@kernel.org, Qiuxu Zhuo , Michal Swiatkowski , Sunitha Mekala Subject: [PATCH net 1/9] ice: health.c: fix compilation on gcc 7.5 Date: Tue, 18 Mar 2025 13:04:45 -0700 Message-ID: <20250318200511.2958251-2-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250318200511.2958251-1-anthony.l.nguyen@intel.com> References: <20250318200511.2958251-1-anthony.l.nguyen@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 From: Przemek Kitszel GCC 7 is not as good as GCC 8+ in telling what is a compile-time const, and thus could be used for static storage. Fortunately keeping strings as const arrays is enough to make old gcc happy. Excerpt from the report: My GCC is: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0. CC [M] drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.o drivers/net/ethernet/intel/ice/devlink/health.c:35:3: error: initializer element is not constant ice_common_port_solutions, {ice_port_number_label}}, ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/net/ethernet/intel/ice/devlink/health.c:35:3: note: (near initialization for 'ice_health_status_lookup[0].solution') drivers/net/ethernet/intel/ice/devlink/health.c:35:31: error: initializer element is not constant ice_common_port_solutions, {ice_port_number_label}}, ^~~~~~~~~~~~~~~~~~~~~ drivers/net/ethernet/intel/ice/devlink/health.c:35:31: note: (near initialization for 'ice_health_status_lookup[0].data_label[0]') drivers/net/ethernet/intel/ice/devlink/health.c:37:46: error: initializer element is not constant "Change or replace the module or cable.", {ice_port_number_label}}, ^~~~~~~~~~~~~~~~~~~~~ drivers/net/ethernet/intel/ice/devlink/health.c:37:46: note: (near initialization for 'ice_health_status_lookup[1].data_label[0]') drivers/net/ethernet/intel/ice/devlink/health.c:39:3: error: initializer element is not constant ice_common_port_solutions, {ice_port_number_label}}, ^~~~~~~~~~~~~~~~~~~~~~~~~ Fixes: 85d6164ec56d ("ice: add fw and port health reporters") Reported-by: Qiuxu Zhuo Closes: https://lore.kernel.org/netdev/CY8PR11MB7134BF7A46D71E50D25FA7A989F72@CY8PR11MB7134.namprd11.prod.outlook.com Reviewed-by: Michal Swiatkowski Suggested-by: Simon Horman Signed-off-by: Przemek Kitszel Reviewed-by: Simon Horman Tested-by: Sunitha Mekala (A Contingent worker at Intel) Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/devlink/health.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/devlink/health.c b/drivers/net/ethernet/intel/ice/devlink/health.c index ea40f7941259..19c3d37aa768 100644 --- a/drivers/net/ethernet/intel/ice/devlink/health.c +++ b/drivers/net/ethernet/intel/ice/devlink/health.c @@ -25,10 +25,10 @@ struct ice_health_status { * The below lookup requires to be sorted by code. */ -static const char *const ice_common_port_solutions = +static const char ice_common_port_solutions[] = "Check your cable connection. Change or replace the module or cable. Manually set speed and duplex."; -static const char *const ice_port_number_label = "Port Number"; -static const char *const ice_update_nvm_solution = "Update to the latest NVM image."; +static const char ice_port_number_label[] = "Port Number"; +static const char ice_update_nvm_solution[] = "Update to the latest NVM image."; static const struct ice_health_status ice_health_status_lookup[] = { {ICE_AQC_HEALTH_STATUS_ERR_UNKNOWN_MOD_STRICT, "An unsupported module was detected.", From patchwork Tue Mar 18 20:04:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 14021510 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 760551DE4FE for ; Tue, 18 Mar 2025 20:05:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328324; cv=none; b=Mm+KWx2/xUuIINYwvcy320K2yNdnmD3CUvnzEIV1ycjjUrqQYiKYeMelQMCJSa+uRLs6Refk7Ij7R8jTiRfTYLg3HECFpHp9nWrf/+H6i/mbbu1tGUBW9LAZ7UdivIW12UNC1IU0KT7J8qjX+wKVfA3YOWsENZCEAahKWEFAxzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328324; c=relaxed/simple; bh=b6ApvI6CbYczUAGudmRUo/uw6X9KZRnk2rxj0Acg4ZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EAHT0Jo2pBSslulbybl6UlMbCEutSRF4E0C1cKaTd3gcWlvJQc/fNk+mWpWLMlG0wuauPisAse4lYUJmchfgMB54U7iRgPFdpZ5K5iO9Wq5q6BiT1imS0/3Q/yO1iKDM0rT1Ye2qmvgYkIyO7B3ukhCC+RL/8wp05knf6l2pFdI= 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=YiWsC0T7; arc=none smtp.client-ip=198.175.65.16 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="YiWsC0T7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742328323; x=1773864323; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b6ApvI6CbYczUAGudmRUo/uw6X9KZRnk2rxj0Acg4ZI=; b=YiWsC0T74G8w/02Cq9CPGkTOrJretEyB8vb4EMYcoMVpaE77XpWDmX+z hyqsOqaKGayNon/ss/vLPxjW7BlFXCSZkDMWVXl6bX5xGIIzxUts3pzU2 mm9LZbw5NbT676+DlvFEIRNusFXyQnahHWFN0sZo8ScoVTyWQVyTcVO5h OSaxAekNTZs7wVrd/W6jqOZd3bNJvVK7B8CeVKRHS7Dn8M/0G03O2XiG3 0mBV1R7wfAzzTlmo5VrX9xrBt/vw7yVo4OizZgYFPaaVqS18Ba4Ztr6r2 bnDKj1E792TH4TSW5f/A61DACPrsl3osN/hYS8x/tWkqCBHsVl6zhLxfU A==; X-CSE-ConnectionGUID: YYU+BRFDQyqbc4E5M4VqbA== X-CSE-MsgGUID: LxjYlG6MRKKjQ60vViNoVA== X-IronPort-AV: E=McAfee;i="6700,10204,11377"; a="43593016" X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="43593016" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 13:05:20 -0700 X-CSE-ConnectionGUID: CJXvswzdS+CuYKZCRLOXOw== X-CSE-MsgGUID: f6T8k14JQd6eIUbBIkVYTQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="153363128" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by fmviesa001.fm.intel.com with ESMTP; 18 Mar 2025 13:05:18 -0700 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, andrew+netdev@lunn.ch, netdev@vger.kernel.org Cc: Karol Kolacinski , anthony.l.nguyen@intel.com, arkadiusz.kubalewski@intel.com, przemyslaw.kitszel@intel.com, richardcochran@gmail.com, horms@kernel.org, Jacob Keller , Rinitha S Subject: [PATCH net 2/9] ice: ensure periodic output start time is in the future Date: Tue, 18 Mar 2025 13:04:46 -0700 Message-ID: <20250318200511.2958251-3-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250318200511.2958251-1-anthony.l.nguyen@intel.com> References: <20250318200511.2958251-1-anthony.l.nguyen@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 From: Karol Kolacinski On E800 series hardware, if the start time for a periodic output signal is programmed into GLTSYN_TGT_H and GLTSYN_TGT_L registers, the hardware logic locks up and the periodic output signal never starts. Any future attempt to reprogram the clock function is futile as the hardware will not reset until a power on. The ice_ptp_cfg_perout function has logic to prevent this, as it checks if the requested start time is in the past. If so, a new start time is calculated by rounding up. Since commit d755a7e129a5 ("ice: Cache perout/extts requests and check flags"), the rounding is done to the nearest multiple of the clock period, rather than to a full second. This is more accurate, since it ensures the signal matches the user request precisely. Unfortunately, there is a race condition with this rounding logic. If the current time is close to the multiple of the period, we could calculate a target time that is extremely soon. It takes time for the software to program the registers, during which time this requested start time could become a start time in the past. If that happens, the periodic output signal will lock up. For large enough periods, or for the logic prior to the mentioned commit, this is unlikely. However, with the new logic rounding to the period and with a small enough period, this becomes inevitable. For example, attempting to enable a 10MHz signal requires a period of 100 nanoseconds. This means in the *best* case, we have 99 nanoseconds to program the clock output. This is essentially impossible, and thus such a small period practically guarantees that the clock output function will lock up. To fix this, add some slop to the clock time used to check if the start time is in the past. Because it is not critical that output signals start immediately, but it *is* critical that we do not brick the function, 0.5 seconds is selected. This does mean that any requested output will be delayed by at least 0.5 seconds. This slop is applied before rounding, so that we always round up to the nearest multiple of the period that is at least 0.5 seconds in the future, ensuring a minimum of 0.5 seconds to program the clock output registers. Finally, to ensure that the hardware registers programming the clock output complete in a timely manner, add a write flush to the end of ice_ptp_write_perout. This ensures we don't risk any issue with PCIe transaction batching. Strictly speaking, this fixes a race condition all the way back at the initial implementation of periodic output programming, as it is theoretically possible to trigger this bug even on the old logic when always rounding to a full second. However, the window is narrow, and the code has been refactored heavily since then, making a direct backport not apply cleanly. Fixes: d755a7e129a5 ("ice: Cache perout/extts requests and check flags") Signed-off-by: Karol Kolacinski Signed-off-by: Jacob Keller Tested-by: Rinitha S (A Contingent worker at Intel) Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_ptp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c index e26320ce52ca..a99e0fbd0b8b 100644 --- a/drivers/net/ethernet/intel/ice/ice_ptp.c +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c @@ -1783,6 +1783,7 @@ static int ice_ptp_write_perout(struct ice_hw *hw, unsigned int chan, 8 + chan + (tmr_idx * 4)); wr32(hw, GLGEN_GPIO_CTL(gpio_pin), val); + ice_flush(hw); return 0; } @@ -1843,9 +1844,10 @@ static int ice_ptp_cfg_perout(struct ice_pf *pf, struct ptp_perout_request *rq, div64_u64_rem(start, period, &phase); /* If we have only phase or start time is in the past, start the timer - * at the next multiple of period, maintaining phase. + * at the next multiple of period, maintaining phase at least 0.5 second + * from now, so we have time to write it to HW. */ - clk = ice_ptp_read_src_clk_reg(pf, NULL); + clk = ice_ptp_read_src_clk_reg(pf, NULL) + NSEC_PER_MSEC * 500; if (rq->flags & PTP_PEROUT_PHASE || start <= clk - prop_delay_ns) start = div64_u64(clk + period - 1, period) * period + phase; From patchwork Tue Mar 18 20:04:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 14021511 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 99DBD1EB5CC for ; Tue, 18 Mar 2025 20:05:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328324; cv=none; b=r87+LmFT2XgLkHDEhGAF8pB7q72fgzgGrvJr4a8uVWQYMM8jc7Cc4cU0CXjhUkOPs3vIj53UIft/IKaz37Dnd+Z8KSJq0RV2FzYlY8bHR18nJXQHCvqIGysEXqPFCXNJPDWHZbPSWn59Hy+6hnvW8fycrNLJQOwD0JAXvmIu2LQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328324; c=relaxed/simple; bh=LQ3jlFn5IMM1Awz4zvpFlXKmE1yu8eUwg73WfX3ZTEU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D93Mm+u8Ynnczmt0RNsDWytktmwD5x6y7knFqqNDBKkxML9kv2KzLNv48ZMSXn4MQyniW62GtxkRyXtvxjtQZ8maA/lRUgBmKsuLMKg6P4+csZlCYX2MYL0pvHpr1OKP0KeRiwVbS+xI/EWerQXsa5CMhGIARR1Sk4SqBkmZkss= 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=IteYFDFT; arc=none smtp.client-ip=198.175.65.16 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="IteYFDFT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742328323; x=1773864323; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LQ3jlFn5IMM1Awz4zvpFlXKmE1yu8eUwg73WfX3ZTEU=; b=IteYFDFTZVKmMX3E90OrxYfwO62ZJ7gtTJOMGvuoaim4urw4ouDmOL07 C4+QL5+RHL0PXVgCY0pd0eB/4Oka2z+nIAi1BO/JQTYoBRvCKsmW7Wh4Z G9LFH3n8PFovlnfVOdubEyCtDRB4JKOQ7dWbl00Ie/DeZkl2s5BK0ixC6 uBMpRnDaEPL/R7B50n3slPImz59kLPG83fODCWULiHy/OQZGNIHUsFPJi 1nwIQK4AoM9L8cnC8mZ0deNLw+ONnBvPW39AFi+6NAhihat19Yrsc/rl+ wm9xQ80R7MNaiIrgRRso79ne3yWq54tokHBBFCM+ztP2fC4tDC07DePMF Q==; X-CSE-ConnectionGUID: LS6/wUA7TeCStgxM+kLG4A== X-CSE-MsgGUID: 87I/QNtWTgGqyHKz5f40wQ== X-IronPort-AV: E=McAfee;i="6700,10204,11377"; a="43593026" X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="43593026" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 13:05:20 -0700 X-CSE-ConnectionGUID: uiW6y5ZmRQSQJx8K+n5hCA== X-CSE-MsgGUID: gHewBR69QdCO+pyxtHZ5zg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="153363132" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by fmviesa001.fm.intel.com with ESMTP; 18 Mar 2025 13:05:19 -0700 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, andrew+netdev@lunn.ch, netdev@vger.kernel.org Cc: Jesse Brandeburg , anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com, kernel-team@cloudflare.com, leon@kernel.org, Dave Ertman , Aleksandr Loktionov , Rinitha S Subject: [PATCH net 3/9] ice: fix reservation of resources for RDMA when disabled Date: Tue, 18 Mar 2025 13:04:47 -0700 Message-ID: <20250318200511.2958251-4-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250318200511.2958251-1-anthony.l.nguyen@intel.com> References: <20250318200511.2958251-1-anthony.l.nguyen@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 From: Jesse Brandeburg If the CONFIG_INFINIBAND_IRDMA symbol is not enabled as a module or a built-in, then don't let the driver reserve resources for RDMA. The result of this change is a large savings in resources for older kernels, and a cleaner driver configuration for the IRDMA=n case for old and new kernels. Implement this by avoiding enabling the RDMA capability when scanning hardware capabilities. Note: Loading the out-of-tree irdma driver in connection to the in-kernel ice driver, is not supported, and should not be attempted, especially when disabling IRDMA in the kernel config. Fixes: d25a0fc41c1f ("ice: Initialize RDMA support") Signed-off-by: Jesse Brandeburg Acked-by: Dave Ertman Reviewed-by: Aleksandr Loktionov Tested-by: Rinitha S (A Contingent worker at Intel) Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_common.c b/drivers/net/ethernet/intel/ice/ice_common.c index 7a2a2e8da8fa..1e801300310e 100644 --- a/drivers/net/ethernet/intel/ice/ice_common.c +++ b/drivers/net/ethernet/intel/ice/ice_common.c @@ -2271,7 +2271,8 @@ ice_parse_common_caps(struct ice_hw *hw, struct ice_hw_common_caps *caps, caps->nvm_unified_update); break; case ICE_AQC_CAPS_RDMA: - caps->rdma = (number == 1); + if (IS_ENABLED(CONFIG_INFINIBAND_IRDMA)) + caps->rdma = (number == 1); ice_debug(hw, ICE_DBG_INIT, "%s: rdma = %d\n", prefix, caps->rdma); break; case ICE_AQC_CAPS_MAX_MTU: From patchwork Tue Mar 18 20:04:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 14021512 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 187CD20468F for ; Tue, 18 Mar 2025 20:05:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328325; cv=none; b=sn8PwAHGhFOAbaopj2ktH4R/UG9d46ZYjB0JKG/knCyC4tqe1QtoYx1RpFZet1GU8GdLA84PSESfBIYoyUx/mr7uI80tpoTm9iba1tJ9x8eoem2Smm9kIcxKjQTXfP1Hj9neffwGYBFT33SkP4oOJ8MpUWXt0ihy6dYoPGeH0vg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328325; c=relaxed/simple; bh=1WqwqIOGWYmr7zEri+X5r+ddtzpl2wbOreTgxZ3AHas=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VOg9vZJ1QkVnpWuTjGpzvjm51lxm0GM43j6Mr8gttPdH1l67xsY3mMWFUFl3kgJz4ZrYHZJpjzki35fBflBbvJvJlfmwr4jf0I+xNPkOQAbDBesEDfaF0NPKTR0VWr/IFQOSJOpJHZQFd8odfUAQIlqli7LU+g+pQlpWVUZPw34= 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=Wu8ddNeE; arc=none smtp.client-ip=198.175.65.16 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="Wu8ddNeE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742328324; x=1773864324; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1WqwqIOGWYmr7zEri+X5r+ddtzpl2wbOreTgxZ3AHas=; b=Wu8ddNeEuZZRXRF53LfImmPIybkSUR5l2Ex1Z393iRFv3zCXAz4tZect eaPKF797jvFfxMPvRK6Vj1zHF1f3ggEl6xmVfyBhx2Itn2txnjM87rr6k omM+CZo4UBTbYsSb5QaWbmY2yjFtP30uhmbNCsm/fi0HkmH2+ZEBFrb2T LsmW7/8objjQQyXiKg4rYeLxB8x3hosRRDIwlMyKQL3cHjrDMOVzF/tqd euGj99dsTD7Yhidq6DQ7pwTz6YXclU9x/4m1OdON6nLpDr7aMKWRz0k1j joDZgVPZEpZ5YNKOIzLTMgWeWBA2lkpiM18mvFY9KQ4t27GuxHEBwiOs9 A==; X-CSE-ConnectionGUID: jJstnkf7To69b/znMEHbPQ== X-CSE-MsgGUID: Pd3RIdiKR9O9gdQNzT8Qkw== X-IronPort-AV: E=McAfee;i="6700,10204,11377"; a="43593034" X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="43593034" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 13:05:20 -0700 X-CSE-ConnectionGUID: 7CGTMaGiQhaBlunkCi/R0w== X-CSE-MsgGUID: 3v/9n1HMRrO2oO+cmWXGzg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="153363137" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by fmviesa001.fm.intel.com with ESMTP; 18 Mar 2025 13:05:19 -0700 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, andrew+netdev@lunn.ch, netdev@vger.kernel.org Cc: Jan Glaza , anthony.l.nguyen@intel.com, Jedrzej Jagielski , Simon Horman , Martyna Szapar-Mudlaw , Rafal Romanowski Subject: [PATCH net 4/9] virtchnl: make proto and filter action count unsigned Date: Tue, 18 Mar 2025 13:04:48 -0700 Message-ID: <20250318200511.2958251-5-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250318200511.2958251-1-anthony.l.nguyen@intel.com> References: <20250318200511.2958251-1-anthony.l.nguyen@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 From: Jan Glaza The count field in virtchnl_proto_hdrs and virtchnl_filter_action_set should never be negative while still being valid. Changing it from int to u32 ensures proper handling of values in virtchnl messages in driverrs and prevents unintended behavior. In its current signed form, a negative count does not trigger an error in ice driver but instead results in it being treated as 0. This can lead to unexpected outcomes when processing messages. By using u32, any invalid values will correctly trigger -EINVAL, making error detection more robust. Fixes: 1f7ea1cd6a374 ("ice: Enable FDIR Configure for AVF") Reviewed-by: Jedrzej Jagielski Reviewed-by: Simon Horman Signed-off-by: Jan Glaza Signed-off-by: Martyna Szapar-Mudlaw Tested-by: Rafal Romanowski Signed-off-by: Tony Nguyen --- include/linux/avf/virtchnl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/avf/virtchnl.h b/include/linux/avf/virtchnl.h index 13a11f3c09b8..aca06f300f83 100644 --- a/include/linux/avf/virtchnl.h +++ b/include/linux/avf/virtchnl.h @@ -1283,7 +1283,7 @@ struct virtchnl_proto_hdrs { * 2 - from the second inner layer * .... **/ - int count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */ + u32 count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */ union { struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS]; @@ -1335,7 +1335,7 @@ VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_filter_action); struct virtchnl_filter_action_set { /* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */ - int count; + u32 count; struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS]; }; From patchwork Tue Mar 18 20:04:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 14021513 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 411EF212F98 for ; Tue, 18 Mar 2025 20:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328325; cv=none; b=Lj3Bzf5/SlthP2QbBQW+QhtsQv7sMhaGxZjef3V36/AnmhjeR769DndO3zpVaTjWNSgmlGxJ0RCeiHUkbsV//fDArofhDLcB9j2Efi4zr05CQ0tNBlQ5MI/opF6o2LOp+fV6KVX1qYQmMKS1LkquLF9xuAHsJKXJaNxZxoTHSrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328325; c=relaxed/simple; bh=PjBx/l71FMUid7XFJ8z+egNc3YEaqeIkqY9zLKseRPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nb8ZT/EIYYvQtUfUxglqfsrqGpn9xpHLM2RSo6brhfNvvjyD6Zeomkea0+KLu7nVNnKyXoxZgUVzZh0ZJH+hSi2weMPLqK/N6OZnzy/wGa321hvreRHivyBwHzz1QywHID/NRluCj4ZJjqZDUXnYsbE1YvAiaKliIruKkOJVYwM= 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=WtFiZgu1; arc=none smtp.client-ip=198.175.65.16 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="WtFiZgu1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742328325; x=1773864325; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PjBx/l71FMUid7XFJ8z+egNc3YEaqeIkqY9zLKseRPI=; b=WtFiZgu1yTu80gKlfv+CkQSo1k7b4hEtYZHDCpCOlSN1D2mZxyG/hKLV //N2MrLVfPmPwd6Rv8cwSH3QT4DDR+TIS7AwvmdHP9NZOTMvk6or5LGdZ EpvqaVDx2EKrmeomx4fQXrq/cWuk/zx0bXhcHemOa6YeZoWfQI5VeE/IR iNTrgKxMkf89Rx2gIOQemHQXyl/IqPsjcqNvWvsPjslPx6sqynTvMoLLS wgyRJJPWIrVHtLndwN+eUeuhzAHrsIvLc4L0GhbVIeYk2uq1mSuH7qqck 2G7y4l6UKUpZ28vpEimuLUrl9TdQdSQyZKxbpi4caBl+rZHQpg8KsAJQI g==; X-CSE-ConnectionGUID: mOmGxxNmSAWva0W4XSWYvw== X-CSE-MsgGUID: rLGfMAacTQC33BxhsA5cvw== X-IronPort-AV: E=McAfee;i="6700,10204,11377"; a="43593046" X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="43593046" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 13:05:21 -0700 X-CSE-ConnectionGUID: 4K3tOHz+TRGAE99JwKpOoA== X-CSE-MsgGUID: 9gpZhmfqQUWdHCo4yLRB1g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="153363147" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by fmviesa001.fm.intel.com with ESMTP; 18 Mar 2025 13:05:20 -0700 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, andrew+netdev@lunn.ch, netdev@vger.kernel.org Cc: Jan Glaza , anthony.l.nguyen@intel.com, Aleksandr Loktionov , Jedrzej Jagielski , Simon Horman , Martyna Szapar-Mudlaw , Rafal Romanowski Subject: [PATCH net 5/9] ice: stop truncating queue ids when checking Date: Tue, 18 Mar 2025 13:04:49 -0700 Message-ID: <20250318200511.2958251-6-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250318200511.2958251-1-anthony.l.nguyen@intel.com> References: <20250318200511.2958251-1-anthony.l.nguyen@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 From: Jan Glaza Queue IDs can be up to 4096, fix invalid check to stop truncating IDs to 8 bits. Fixes: bf93bf791cec8 ("ice: introduce ice_virtchnl.c and ice_virtchnl.h") Reviewed-by: Aleksandr Loktionov Reviewed-by: Jedrzej Jagielski Reviewed-by: Simon Horman Signed-off-by: Jan Glaza Signed-off-by: Martyna Szapar-Mudlaw Tested-by: Rafal Romanowski Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_virtchnl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c index ff4ad788d96a..346aee373ccd 100644 --- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c +++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c @@ -562,7 +562,7 @@ bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id) * * check for the valid queue ID */ -static bool ice_vc_isvalid_q_id(struct ice_vsi *vsi, u8 qid) +static bool ice_vc_isvalid_q_id(struct ice_vsi *vsi, u16 qid) { /* allocated Tx and Rx queues should be always equal for VF VSI */ return qid < vsi->alloc_txq; From patchwork Tue Mar 18 20:04:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 14021517 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 A1040213227 for ; Tue, 18 Mar 2025 20:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328329; cv=none; b=MzPvbBg6DGQbV2EzC7DPbm8oGPNS0wtpnViXaMTN3Olg4ZzGjwYpj0sDk3aFh7tuQaeocAhjzzT33hKd+axbfTpnCzm18TdKOcPHWzPLh5v8O1lahCD+ph3ffqhZpeQYcrTHSbDeKL64FuZjsItabPuTWBtYG1u/SDTYiBk51o8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328329; c=relaxed/simple; bh=EuZ2mOFCRP/rGVath4UQsx9IGgcsqSgyBOwf8/ki7ck=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tc0WU+mFi6NFv33UqZtxNjGU0Gbqp2pKJuCtiTwinxtaAD+EyHusr4XYLEuDANvtVVVLM4U2CjFgRVTVBB9OKLfNtAAVGlmSqJkZj/h0skX6NRMkD4vI29BJh5NfVu4ENpRiUv1W6lSfytladoXPTkz/4Fbb8VWP6HY9ydOBlPc= 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=dgQDRsHp; arc=none smtp.client-ip=198.175.65.16 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="dgQDRsHp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742328325; x=1773864325; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EuZ2mOFCRP/rGVath4UQsx9IGgcsqSgyBOwf8/ki7ck=; b=dgQDRsHpKv+R6SuRN4GiCtss5RXJFmsmAQ0E88EYTbN8Kdk1nAc5QLKX qS8B2rMW9dNjOT0unGuocgu9kVhWXnHJwPzZMDm+3YQ3WDtU6JRpOuNGA Qh8WNCpZOk5A51ZWVO80nXRr+iVgtojzEiTToifvmcg06OFY2B/5Xrr/S eI9BFLn6a4LIjC2b1OAzR8O1X+iqLq13MPvU8WekmC/HAqExQlSW1P9zu /eWqUJzmuJHFLkurEl0n+Wuug236TfmBMx1jZubsdc8cGFaa3UJABwvL6 TJndDEGkQktynBDYIx1mE60lAQNh8xtREhvCBAfPf8A6QL5i5br28Dm3+ g==; X-CSE-ConnectionGUID: tUjqKDQNRIus0PAI/MslVw== X-CSE-MsgGUID: gponosPVTfKiKjxR4cwfyg== X-IronPort-AV: E=McAfee;i="6700,10204,11377"; a="43593055" X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="43593055" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 13:05:22 -0700 X-CSE-ConnectionGUID: dutpkPZ/S9moRlFKzNmTng== X-CSE-MsgGUID: r5119TVoSPaXBrshfMCB/g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="153363153" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by fmviesa001.fm.intel.com with ESMTP; 18 Mar 2025 13:05:21 -0700 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, andrew+netdev@lunn.ch, netdev@vger.kernel.org Cc: Jan Glaza , anthony.l.nguyen@intel.com, jiri@resnulli.us, Jedrzej Jagielski , Simon Horman , Martyna Szapar-Mudlaw , Rafal Romanowski Subject: [PATCH net 6/9] ice: validate queue quanta parameters to prevent OOB access Date: Tue, 18 Mar 2025 13:04:50 -0700 Message-ID: <20250318200511.2958251-7-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250318200511.2958251-1-anthony.l.nguyen@intel.com> References: <20250318200511.2958251-1-anthony.l.nguyen@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 From: Jan Glaza Add queue wraparound prevention in quanta configuration. Ensure end_qid does not overflow by validating start_qid and num_queues. Fixes: 015307754a19 ("ice: Support VF queue rate limit and quanta size configuration") Reviewed-by: Jedrzej Jagielski Reviewed-by: Simon Horman Signed-off-by: Jan Glaza Signed-off-by: Martyna Szapar-Mudlaw Tested-by: Rafal Romanowski Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_virtchnl.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c index 346aee373ccd..df13f5110168 100644 --- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c +++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c @@ -1900,13 +1900,21 @@ static int ice_vc_cfg_q_bw(struct ice_vf *vf, u8 *msg) */ static int ice_vc_cfg_q_quanta(struct ice_vf *vf, u8 *msg) { + u16 quanta_prof_id, quanta_size, start_qid, num_queues, end_qid, i; enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS; - u16 quanta_prof_id, quanta_size, start_qid, end_qid, i; struct virtchnl_quanta_cfg *qquanta = (struct virtchnl_quanta_cfg *)msg; struct ice_vsi *vsi; int ret; + start_qid = qquanta->queue_select.start_queue_id; + num_queues = qquanta->queue_select.num_queues; + + if (check_add_overflow(start_qid, num_queues, &end_qid)) { + v_ret = VIRTCHNL_STATUS_ERR_PARAM; + goto err; + } + if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) { v_ret = VIRTCHNL_STATUS_ERR_PARAM; goto err; @@ -1918,8 +1926,6 @@ static int ice_vc_cfg_q_quanta(struct ice_vf *vf, u8 *msg) goto err; } - end_qid = qquanta->queue_select.start_queue_id + - qquanta->queue_select.num_queues; if (end_qid > ICE_MAX_RSS_QS_PER_VF || end_qid > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) { dev_err(ice_pf_to_dev(vf->pf), "VF-%d trying to configure more than allocated number of queues: %d\n", @@ -1948,7 +1954,6 @@ static int ice_vc_cfg_q_quanta(struct ice_vf *vf, u8 *msg) goto err; } - start_qid = qquanta->queue_select.start_queue_id; for (i = start_qid; i < end_qid; i++) vsi->tx_rings[i]->quanta_prof_id = quanta_prof_id; From patchwork Tue Mar 18 20:04:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 14021514 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 194C62135AD for ; Tue, 18 Mar 2025 20:05:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328326; cv=none; b=UDg+VJcZJxa9GlF0OPKQleg4dqS24aiVQtw0swY9xLbaMsqlDJODO9f6J6VxWEWWQ23G5kZ2y+5bp/DJC++IxStdrV0+gGZprXgPz/aS73o04BaGNHZUVZOrfd4F3mt9vTyY2AKPHrNcQA0z5IfqLtE4QBpFKfX0uwtrXyl6S6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328326; c=relaxed/simple; bh=JE91QTRS9s/PJnY8bLhmfV8ebey4gflG/1BZ7/jTCW0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E9PJzwh2tTnfhgWTW7Iy/+5sxHbFTUyFgaoDmOOeY9tAjoDfXw/v+kOrevzu8DwdZ3e5NVRx2AeBueeqkoO/ylqNz2gn5D5XuqGNBL4ddV40RCRTCG4o7hAxsp4IPNS2cnrkxiGkeqY9I3kBxlseDE++ot7kRVNPHIG38lKFw/g= 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=DMKIPOcR; arc=none smtp.client-ip=198.175.65.16 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="DMKIPOcR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742328326; x=1773864326; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JE91QTRS9s/PJnY8bLhmfV8ebey4gflG/1BZ7/jTCW0=; b=DMKIPOcRzgCJ9JT+EjctEjl5lakj8duDdLyQWtxyH0hBqUiOOb7zKQ+W mo+IRi+GfFrpyqhphh3W7NV6S7PW2kJnvUL4TeLrhpybIc9jge3g/VeP8 Ib7F41ZFsU8s4J/cXbj93cqHnEJJwauPO+oArdnZ913RiR54hcsdzzn6v b3kJebjUVYc64g+yajxh8VFMLmBXqEfluURZXGmimxuxheYp5OHmGuM2i InIITjiXt7+NfgQux2ZA+zqMRQeD3vnX+DNKmJm03hkUCSTFQmyM90DXo noKlVQhPmMVOrE/DkMvP1rX4XNf1+J0JfGV4tQvPvTW0z3XLWlJFSAEO5 w==; X-CSE-ConnectionGUID: wcQfon7URpOK50v0D6gDhw== X-CSE-MsgGUID: rcTZObCXTMa/1MlM32Tn8Q== X-IronPort-AV: E=McAfee;i="6700,10204,11377"; a="43593065" X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="43593065" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 13:05:22 -0700 X-CSE-ConnectionGUID: nA8tBwQgTnagsrFySHIrYw== X-CSE-MsgGUID: lK+EjGbqQ8eitlL52w7jfQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="153363158" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by fmviesa001.fm.intel.com with ESMTP; 18 Mar 2025 13:05:21 -0700 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, andrew+netdev@lunn.ch, netdev@vger.kernel.org Cc: Lukasz Czapnik , anthony.l.nguyen@intel.com, jiri@resnulli.us, Jedrzej Jagielski , Simon Horman , Martyna Szapar-Mudlaw , Rafal Romanowski Subject: [PATCH net 7/9] ice: fix input validation for virtchnl BW Date: Tue, 18 Mar 2025 13:04:51 -0700 Message-ID: <20250318200511.2958251-8-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250318200511.2958251-1-anthony.l.nguyen@intel.com> References: <20250318200511.2958251-1-anthony.l.nguyen@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 From: Lukasz Czapnik Add missing validation of tc and queue id values sent by a VF in ice_vc_cfg_q_bw(). Additionally fixed logged value in the warning message, where max_tx_rate was incorrectly referenced instead of min_tx_rate. Also correct error handling in this function by properly exiting when invalid configuration is detected. Fixes: 015307754a19 ("ice: Support VF queue rate limit and quanta size configuration") Reviewed-by: Jedrzej Jagielski Reviewed-by: Simon Horman Signed-off-by: Lukasz Czapnik Co-developed-by: Martyna Szapar-Mudlaw Signed-off-by: Martyna Szapar-Mudlaw Tested-by: Rafal Romanowski Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/ice/ice_virtchnl.c | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c index df13f5110168..1af51469f070 100644 --- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c +++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c @@ -1862,15 +1862,33 @@ static int ice_vc_cfg_q_bw(struct ice_vf *vf, u8 *msg) for (i = 0; i < qbw->num_queues; i++) { if (qbw->cfg[i].shaper.peak != 0 && vf->max_tx_rate != 0 && - qbw->cfg[i].shaper.peak > vf->max_tx_rate) + qbw->cfg[i].shaper.peak > vf->max_tx_rate) { dev_warn(ice_pf_to_dev(vf->pf), "The maximum queue %d rate limit configuration may not take effect because the maximum TX rate for VF-%d is %d\n", qbw->cfg[i].queue_id, vf->vf_id, vf->max_tx_rate); + v_ret = VIRTCHNL_STATUS_ERR_PARAM; + goto err; + } if (qbw->cfg[i].shaper.committed != 0 && vf->min_tx_rate != 0 && - qbw->cfg[i].shaper.committed < vf->min_tx_rate) + qbw->cfg[i].shaper.committed < vf->min_tx_rate) { dev_warn(ice_pf_to_dev(vf->pf), "The minimum queue %d rate limit configuration may not take effect because the minimum TX rate for VF-%d is %d\n", qbw->cfg[i].queue_id, vf->vf_id, - vf->max_tx_rate); + vf->min_tx_rate); + v_ret = VIRTCHNL_STATUS_ERR_PARAM; + goto err; + } + if (qbw->cfg[i].queue_id > vf->num_vf_qs) { + dev_warn(ice_pf_to_dev(vf->pf), "VF-%d trying to configure invalid queue_id\n", + vf->vf_id); + v_ret = VIRTCHNL_STATUS_ERR_PARAM; + goto err; + } + if (qbw->cfg[i].tc >= ICE_MAX_TRAFFIC_CLASS) { + dev_warn(ice_pf_to_dev(vf->pf), "VF-%d trying to configure a traffic class higher than allowed\n", + vf->vf_id); + v_ret = VIRTCHNL_STATUS_ERR_PARAM; + goto err; + } } for (i = 0; i < qbw->num_queues; i++) { From patchwork Tue Mar 18 20:04:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 14021515 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 BE9982139AC for ; Tue, 18 Mar 2025 20:05:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328327; cv=none; b=qCrXhUC/qvqL0Ug/45FmUroaCMhZpqTuzqzb6ETEU8UC/DIyMt8B3q/q9z6mxCxhsqQhbDFEtsRtShcFNdfSntmOUD7dRqWmFOcCvEbeujKQEyCNa0mKT8IAbnEqCst5BkTlhTCiuKvmS0tN0c9hXJfrIiKFLKhsTnWNOjU/N40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328327; c=relaxed/simple; bh=QXoCQ4KeDDpNKZbXJWuDrsuf6m/+SyL0NPSYb0gyuCw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QsTmAo4yFcT4LUDMaA3p8YHdg5FTU3ZarBsyZeMa0xSrq592ooMz8ZrNC/69jrADLOwQOlAc0+0U9f0JBgfWNZ621dcKOMZAF2ha6QJe5xRs4rQfoCEemkyuQS1aPMGCw+CCbhZ22TFmavW1H2lzS6gP+J6G7FkT5nD04XBI7Jo= 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=iFenCfie; arc=none smtp.client-ip=198.175.65.16 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="iFenCfie" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742328326; x=1773864326; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QXoCQ4KeDDpNKZbXJWuDrsuf6m/+SyL0NPSYb0gyuCw=; b=iFenCfielIlf57oFkwq4p7UPgjUCp08bFQoeaFskMPUUcTW4IFlOjOPq qJGrxwI0MObDsbh4kQmDZlY2WPVtfDWLXJfsOL3DHphW4Ah2X8+CaoE9m ZdxaRkF8iTqaEOpyngrPUUs7+jXfOJxQWR0G8T2u5X8Jp+UEJSWPFGGhy vpwlyTZvUlZqkQZ7x0HKl2rXHmiaA/++8fKR6eaTCbY8JBrj2eFJQZaPQ gagQxUuRSSkWRvX78ktqpZBbPX7DmvhpSdGf0mtdYhxahCyev0peVkRAA /e/RofeKglJ5ADytF5tIxT6/t8hGlXnreSOkw0gA2tN3XwoLgpnE1lTZZ Q==; X-CSE-ConnectionGUID: 19lTjNPCQ+mihkrIvKczqw== X-CSE-MsgGUID: bVn4zvCYTii1TEfy5qVF5g== X-IronPort-AV: E=McAfee;i="6700,10204,11377"; a="43593074" X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="43593074" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 13:05:23 -0700 X-CSE-ConnectionGUID: 1ihvsMspR6qk26c4sy53+A== X-CSE-MsgGUID: t0FDG6QhSiCEG6ESDxxLaA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="153363164" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by fmviesa001.fm.intel.com with ESMTP; 18 Mar 2025 13:05:22 -0700 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, andrew+netdev@lunn.ch, netdev@vger.kernel.org Cc: Mateusz Polchlopek , anthony.l.nguyen@intel.com, horms@kernel.org, Przemek Kitszel , Martyna Szapar-Mudlaw , Rafal Romanowski Subject: [PATCH net 8/9] ice: fix using untrusted value of pkt_len in ice_vc_fdir_parse_raw() Date: Tue, 18 Mar 2025 13:04:52 -0700 Message-ID: <20250318200511.2958251-9-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250318200511.2958251-1-anthony.l.nguyen@intel.com> References: <20250318200511.2958251-1-anthony.l.nguyen@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 From: Mateusz Polchlopek Fix using the untrusted value of proto->raw.pkt_len in function ice_vc_fdir_parse_raw() by verifying if it does not exceed the VIRTCHNL_MAX_SIZE_RAW_PACKET value. Fixes: 99f419df8a5c ("ice: enable FDIR filters from raw binary patterns for VFs") Reviewed-by: Przemek Kitszel Signed-off-by: Mateusz Polchlopek Signed-off-by: Martyna Szapar-Mudlaw Tested-by: Rafal Romanowski Signed-off-by: Tony Nguyen --- .../ethernet/intel/ice/ice_virtchnl_fdir.c | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c b/drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c index 14e3f0f89c78..9be4bd717512 100644 --- a/drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +++ b/drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c @@ -832,21 +832,27 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto, struct virtchnl_fdir_fltr_conf *conf) { - u8 *pkt_buf, *msk_buf __free(kfree); + u8 *pkt_buf, *msk_buf __free(kfree) = NULL; struct ice_parser_result rslt; struct ice_pf *pf = vf->pf; + u16 pkt_len, udp_port = 0; struct ice_parser *psr; int status = -ENOMEM; struct ice_hw *hw; - u16 udp_port = 0; - pkt_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL); - msk_buf = kzalloc(proto->raw.pkt_len, GFP_KERNEL); + pkt_len = proto->raw.pkt_len; + + if (!pkt_len || pkt_len > VIRTCHNL_MAX_SIZE_RAW_PACKET) + return -EINVAL; + + pkt_buf = kzalloc(pkt_len, GFP_KERNEL); + msk_buf = kzalloc(pkt_len, GFP_KERNEL); + if (!pkt_buf || !msk_buf) goto err_mem_alloc; - memcpy(pkt_buf, proto->raw.spec, proto->raw.pkt_len); - memcpy(msk_buf, proto->raw.mask, proto->raw.pkt_len); + memcpy(pkt_buf, proto->raw.spec, pkt_len); + memcpy(msk_buf, proto->raw.mask, pkt_len); hw = &pf->hw; @@ -862,7 +868,7 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf, if (ice_get_open_tunnel_port(hw, &udp_port, TNL_VXLAN)) ice_parser_vxlan_tunnel_set(psr, udp_port, true); - status = ice_parser_run(psr, pkt_buf, proto->raw.pkt_len, &rslt); + status = ice_parser_run(psr, pkt_buf, pkt_len, &rslt); if (status) goto err_parser_destroy; @@ -876,7 +882,7 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf, } status = ice_parser_profile_init(&rslt, pkt_buf, msk_buf, - proto->raw.pkt_len, ICE_BLK_FD, + pkt_len, ICE_BLK_FD, conf->prof); if (status) goto err_parser_profile_init; @@ -885,7 +891,7 @@ ice_vc_fdir_parse_raw(struct ice_vf *vf, ice_parser_profile_dump(hw, conf->prof); /* Store raw flow info into @conf */ - conf->pkt_len = proto->raw.pkt_len; + conf->pkt_len = pkt_len; conf->pkt_buf = pkt_buf; conf->parser_ena = true; From patchwork Tue Mar 18 20:04:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 14021516 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 B33CE2139D8 for ; Tue, 18 Mar 2025 20:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328328; cv=none; b=tSjG5TYl0fC+ck+RuxAgjBKArFz9nAlPVLBDZvjaw0FIeTjRu3a/ZkWOHWPV0z54mXp5LdO7VOve+ytQMejYeqlMAu/1aBplgtaIDh38h+Y6Wur1SGV7KeI+1xtlQwsvizavSWyjRwIjGMggBag7Kun6CcEoPLPuuMmVXFccN5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742328328; c=relaxed/simple; bh=3yaUMTyiDdA4jWRLhO6/l6GfsPCVWc9gKQxFrd72O4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HXN8JyHCuHKOF3KEE/4bY/dmFI2wiptfCgRMXBq2iFS32uLGps+rL/yV6ixhoHw6tWtCDYr6vIjtIc6EVfrn7DbYLch9ylT2KsIg+p2H7mv15aC0IzTd1BqJ7LsH9IV8G/SY+iI7BDgRhMbzetW2nwQj5DzYM4PGdmK0lss/Dqw= 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=V5raQX96; arc=none smtp.client-ip=198.175.65.16 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="V5raQX96" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742328327; x=1773864327; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3yaUMTyiDdA4jWRLhO6/l6GfsPCVWc9gKQxFrd72O4A=; b=V5raQX96HdjU9zT0zwxUjDiCrOtfGfCaJJZL3tqPDZsbQV3/o55ug+Cd eC0WTkOvnoIyCc/tpqMNVoICsZwE/GSM8xND7i+INfqYRLZdqow1yKWEt 44WXMdkw2PrBVuk01PshExT/89+fStZeR1wUJBZzgwhiTMBeEf++Tjuqp wcg0U51JCKSCdr47d3ZwkDRB+lFE62nNQIi+tGBbklpyHCmV189WT7B1V nuko7H3IJmOCBUDsE6cM060DRCOhQTbW2emZooC97fdc2i8+Jr1Bo8h+Z qnfzP/YVfAtj2IW7eACiPWjaWafuWu1hND9uCqNNTO+iR+G5l/VrqOj51 g==; X-CSE-ConnectionGUID: Ui7xPPnCR1S76bi8hR4Rzg== X-CSE-MsgGUID: Ymrmhj6bQFKIl1q9W7U4YA== X-IronPort-AV: E=McAfee;i="6700,10204,11377"; a="43593080" X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="43593080" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2025 13:05:23 -0700 X-CSE-ConnectionGUID: O8EH/kTNSGqZZFBH82uW/A== X-CSE-MsgGUID: 3bXQ/Pt6SQeS5jdBnmEIuw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,257,1736841600"; d="scan'208";a="153363167" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by fmviesa001.fm.intel.com with ESMTP; 18 Mar 2025 13:05:22 -0700 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, andrew+netdev@lunn.ch, netdev@vger.kernel.org Cc: Emil Tantilov , anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com, willemb@google.com, decot@google.com, horms@kernel.org, Samuel Salin Subject: [PATCH net 9/9] idpf: check error for register_netdev() on init Date: Tue, 18 Mar 2025 13:04:53 -0700 Message-ID: <20250318200511.2958251-10-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250318200511.2958251-1-anthony.l.nguyen@intel.com> References: <20250318200511.2958251-1-anthony.l.nguyen@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 From: Emil Tantilov Current init logic ignores the error code from register_netdev(), which will cause WARN_ON() on attempt to unregister it, if there was one, and there is no info for the user that the creation of the netdev failed. WARNING: CPU: 89 PID: 6902 at net/core/dev.c:11512 unregister_netdevice_many_notify+0x211/0x1a10 ... [ 3707.563641] unregister_netdev+0x1c/0x30 [ 3707.563656] idpf_vport_dealloc+0x5cf/0xce0 [idpf] [ 3707.563684] idpf_deinit_task+0xef/0x160 [idpf] [ 3707.563712] idpf_vc_core_deinit+0x84/0x320 [idpf] [ 3707.563739] idpf_remove+0xbf/0x780 [idpf] [ 3707.563769] pci_device_remove+0xab/0x1e0 [ 3707.563786] device_release_driver_internal+0x371/0x530 [ 3707.563803] driver_detach+0xbf/0x180 [ 3707.563816] bus_remove_driver+0x11b/0x2a0 [ 3707.563829] pci_unregister_driver+0x2a/0x250 Introduce an error check and log the vport number and error code. On removal make sure to check VPORT_REG_NETDEV flag prior to calling unregister and free on the netdev. Add local variables for idx, vport_config and netdev for readability. Fixes: 0fe45467a104 ("idpf: add create vport and netdev configuration") Suggested-by: Tony Nguyen Signed-off-by: Emil Tantilov Reviewed-by: Simon Horman Tested-by: Samuel Salin Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/idpf/idpf_lib.c | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c b/drivers/net/ethernet/intel/idpf/idpf_lib.c index a3d6b8f198a8..a055a47449f1 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_lib.c +++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c @@ -927,15 +927,19 @@ static int idpf_stop(struct net_device *netdev) static void idpf_decfg_netdev(struct idpf_vport *vport) { struct idpf_adapter *adapter = vport->adapter; + u16 idx = vport->idx; kfree(vport->rx_ptype_lkup); vport->rx_ptype_lkup = NULL; - unregister_netdev(vport->netdev); - free_netdev(vport->netdev); + if (test_and_clear_bit(IDPF_VPORT_REG_NETDEV, + adapter->vport_config[idx]->flags)) { + unregister_netdev(vport->netdev); + free_netdev(vport->netdev); + } vport->netdev = NULL; - adapter->netdevs[vport->idx] = NULL; + adapter->netdevs[idx] = NULL; } /** @@ -1536,13 +1540,22 @@ void idpf_init_task(struct work_struct *work) } for (index = 0; index < adapter->max_vports; index++) { - if (adapter->netdevs[index] && - !test_bit(IDPF_VPORT_REG_NETDEV, - adapter->vport_config[index]->flags)) { - register_netdev(adapter->netdevs[index]); - set_bit(IDPF_VPORT_REG_NETDEV, - adapter->vport_config[index]->flags); + struct net_device *netdev = adapter->netdevs[index]; + struct idpf_vport_config *vport_config; + + vport_config = adapter->vport_config[index]; + + if (!netdev || + test_bit(IDPF_VPORT_REG_NETDEV, vport_config->flags)) + continue; + + err = register_netdev(netdev); + if (err) { + dev_err(&pdev->dev, "failed to register netdev for vport %d: %pe\n", + index, ERR_PTR(err)); + continue; } + set_bit(IDPF_VPORT_REG_NETDEV, vport_config->flags); } /* As all the required vports are created, clear the reset flag