From patchwork Tue May 21 19:39:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Keller X-Patchwork-Id: 13669688 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 0344C4DA0C for ; Tue, 21 May 2024 19:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716320400; cv=none; b=iHswCWdjP7+PCgOORUqKEHWLFHPOBbi+YRYrspCMOYmlD8R5P09/JVaSNOo9qb8Tz2KxCDOeWDoZDZwgZeT5S0Sr7RozDCGVFQnjth0eiwBNL/FoKs6ROlKQdgvsKaMQGwY8hPWsil0As12QBlznzP4NBzcwA3ScdCfnq/I9WIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716320400; c=relaxed/simple; bh=WLcFovuUYrlRPU5G5ejcHssvsTh1bsZFa3pLbqJw4XQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X3xfS1Ymoj25YYa1ztk03tZ2IzDWASHpGMjct4xk0ALoz2Ezk7dsSkbFsXop558yN1NqBbzrVVFqO1KI4Rv5lmLHsTfSowkx3uEoFtgPkW+T5NdxsxKFhtBJhFzEpq/0qJu/+rIqpAVC+cOk3Xr2en1NPoJAVk0FRIDF8F5dad8= 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=U1J26NTp; arc=none smtp.client-ip=198.175.65.9 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="U1J26NTp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716320399; x=1747856399; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=WLcFovuUYrlRPU5G5ejcHssvsTh1bsZFa3pLbqJw4XQ=; b=U1J26NTpuaAs00l4R6PPzwfyUsqU7WnCHuP5TAwBnYKrAyMzqmpuGWfO jBP4WzHBfmMw4dv4Dg+AxtK1AfMT75sc0ImQu2+i/jTLcLpMzQzHdk7gq OiKwKiMcIFvD+g7/yVG0A16bXCF+WR8+QN+tO9Mxu9Id16ORochPNNqje XGo+utfRckB0If+TNRpjW7H9v02yjKsMY5Jz6uEN0F/oFZpDYmGGA6Er6 eOG5IWCEvgIB1J50g4H1hIJJfM3S/Mt5LM7CuDvi/3Sp6s7NEC6+ftxEQ SpH/zE8k4hvO0Lom/qV5HjSYRmUQmyebofU8Cly8xs4d/ymXe6JWi8nnF A==; X-CSE-ConnectionGUID: k9Y2Zc4nRRWbn1UgEIzFxQ== X-CSE-MsgGUID: gf86ttIlQyaNPCc4hwYgMw== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="35049757" X-IronPort-AV: E=Sophos;i="6.08,178,1712646000"; d="scan'208";a="35049757" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 12:39:56 -0700 X-CSE-ConnectionGUID: dVNvaOhyQP+8ai8q2lSK4g== X-CSE-MsgGUID: Ubx05yYPSCCu1m/szvGjAA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,178,1712646000"; d="scan'208";a="33462478" Received: from jekeller-desk.amr.corp.intel.com ([10.166.241.1]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 12:39:57 -0700 From: Jacob Keller Date: Tue, 21 May 2024 12:39:53 -0700 Subject: [PATCH net v2 1/2] ice: Interpret .set_channels() input differently Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240521-iwl-net-2024-05-14-set-channels-fixes-v2-1-7aa39e2e99f1@intel.com> References: <20240521-iwl-net-2024-05-14-set-channels-fixes-v2-0-7aa39e2e99f1@intel.com> In-Reply-To: <20240521-iwl-net-2024-05-14-set-channels-fixes-v2-0-7aa39e2e99f1@intel.com> To: David Miller , Jakub Kicinski , netdev Cc: Jacob Keller , Larysa Zaremba , Michal Swiatkowski , Chandan Kumar Rout , Pucha Himasekhar Reddy , Maciej Fijalkowski X-Mailer: b4 0.13.0 X-Patchwork-Delegate: kuba@kernel.org From: Larysa Zaremba A bug occurs because a safety check guarding AF_XDP-related queues in ethnl_set_channels(), does not trigger. This happens, because kernel and ice driver interpret the ethtool command differently. How the bug occurs: 1. ethtool -l -> combined: 40 2. Attach AF_XDP to queue 30 3. ethtool -L rx 15 tx 15 combined number is not specified, so command becomes {rx_count = 15, tx_count = 15, combined_count = 40}. 4. ethnl_set_channels checks, if there are any AF_XDP of queues from the new (combined_count + rx_count) to the old one, so from 55 to 40, check does not trigger. 5. ice interprets `rx 15 tx 15` as 15 combined channels and deletes the queue that AF_XDP is attached to. Interpret the command in a way that is more consistent with ethtool manual [0] (--show-channels and --set-channels). Considering that in the ice driver only the difference between RX and TX queues forms dedicated channels, change the correct way to set number of channels to: ethtool -L combined 10 /* For symmetric queues */ ethtool -L combined 8 tx 2 rx 0 /* For asymmetric queues */ [0] https://man7.org/linux/man-pages/man8/ethtool.8.html Fixes: 87324e747fde ("ice: Implement ethtool ops for channels") Reviewed-by: Michal Swiatkowski Signed-off-by: Larysa Zaremba Tested-by: Chandan Kumar Rout Tested-by: Pucha Himasekhar Reddy Acked-by: Maciej Fijalkowski Signed-off-by: Jacob Keller --- Changes since V2 - Remove the unnecessary check for combined_count. --- drivers/net/ethernet/intel/ice/ice_ethtool.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c index 78b833b3e1d7..62c8205fceba 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c @@ -3593,7 +3593,6 @@ static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch) struct ice_pf *pf = vsi->back; int new_rx = 0, new_tx = 0; bool locked = false; - u32 curr_combined; int ret = 0; /* do not support changing channels in Safe Mode */ @@ -3615,22 +3614,8 @@ static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch) return -EOPNOTSUPP; } - curr_combined = ice_get_combined_cnt(vsi); - - /* these checks are for cases where user didn't specify a particular - * value on cmd line but we get non-zero value anyway via - * get_channels(); look at ethtool.c in ethtool repository (the user - * space part), particularly, do_schannels() routine - */ - if (ch->rx_count == vsi->num_rxq - curr_combined) - ch->rx_count = 0; - if (ch->tx_count == vsi->num_txq - curr_combined) - ch->tx_count = 0; - if (ch->combined_count == curr_combined) - ch->combined_count = 0; - - if (!(ch->combined_count || (ch->rx_count && ch->tx_count))) { - netdev_err(dev, "Please specify at least 1 Rx and 1 Tx channel\n"); + if (ch->rx_count && ch->tx_count) { + netdev_err(dev, "Dedicated RX or TX channels cannot be used simultaneously\n"); return -EINVAL; } From patchwork Tue May 21 19:39:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Keller X-Patchwork-Id: 13669689 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 6BC9214884F for ; Tue, 21 May 2024 19:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716320401; cv=none; b=P9/8KcrOKd8tcgkV5s8aT6k62csxBXx0zpvoRhC1mr+odr8JqlxjIGRA8UFeWTL6GIyaQtCGl7GKmUxzRfEVgvdmarjL6nA4Va9YDVsqzT8ZdMFGjFNQu0CWfj7UQlpnhBOD0RvBAcfN5NpCf5h/lpHczQIRD3kCLQVBhKYS+PM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716320401; c=relaxed/simple; bh=/awOTccWQ0TJJdl01vhIbrzasMGO9q1zGJQkyvByLNQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XtjLfdpWgeTYF7NuuQf2CAdClOO38cMQpGQEtV64BKB0/yZLPT5B2dCqI799GfAjLgOnA6ajYXu4/gUHGbRb/8NgyHjzLVQ2Ii2vgrlZeA8ok9Vs2WJpamyvFA4RN2Gz5v9LeG8Hlp5rD4e13TzEBwZ0wNUULnZo+mPzXJqEEaQ= 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=LjtL5iGQ; arc=none smtp.client-ip=198.175.65.9 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="LjtL5iGQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716320399; x=1747856399; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=/awOTccWQ0TJJdl01vhIbrzasMGO9q1zGJQkyvByLNQ=; b=LjtL5iGQ/Bx3jNuE9w506FMKJENqDAmHvs27hL0PXAHscc6XEsUw7/5d 8FYW1fV4q2B6p6U8m8kR6TWayOBG9Ip9Eg9YFtxy8ZSOBlFyluJXVmUf/ BqZjH4IPefvn1hgvWeIy6DnEl+1wsye5qXOyOlw/6+xJPd2U6rBp2UvUx 87GTV3Pz/KFXmBFNEq0Q0L83Q1WyeWekwDb7q3FU8v675rISNlcLJZsdK dFDNLEdpY8P5Yg5Vh5Dh73wrPAKaAsahcH1qE14mIlkteojvL/j0+eulU yy/+FYeicfYuN7ynLaVgl6BIfvO5hANrYqMKO74qALMP6tqB23/cyafuY g==; X-CSE-ConnectionGUID: SvMOb981RJedUIw75nO6uw== X-CSE-MsgGUID: BeAK8h4MRCa5KJDraP3uJA== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="35049760" X-IronPort-AV: E=Sophos;i="6.08,178,1712646000"; d="scan'208";a="35049760" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 12:39:56 -0700 X-CSE-ConnectionGUID: TaEzahDvTBi3GWxBuTzIFA== X-CSE-MsgGUID: VZ8mlbYlTQa05ucsbnDnng== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,178,1712646000"; d="scan'208";a="33462480" Received: from jekeller-desk.amr.corp.intel.com ([10.166.241.1]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 12:39:57 -0700 From: Jacob Keller Date: Tue, 21 May 2024 12:39:54 -0700 Subject: [PATCH net v2 2/2] idpf: Interpret .set_channels() input differently Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240521-iwl-net-2024-05-14-set-channels-fixes-v2-2-7aa39e2e99f1@intel.com> References: <20240521-iwl-net-2024-05-14-set-channels-fixes-v2-0-7aa39e2e99f1@intel.com> In-Reply-To: <20240521-iwl-net-2024-05-14-set-channels-fixes-v2-0-7aa39e2e99f1@intel.com> To: David Miller , Jakub Kicinski , netdev Cc: Jacob Keller , Larysa Zaremba , Przemek Kitszel , Igor Bagnucki , Krishneil Singh , Simon Horman X-Mailer: b4 0.13.0 X-Patchwork-Delegate: kuba@kernel.org From: Larysa Zaremba Unlike ice, idpf does not check, if user has requested at least 1 combined channel. Instead, it relies on a check in the core code. Unfortunately, the check does not trigger for us because of the hacky .set_channels() interpretation logic that is not consistent with the core code. This naturally leads to user being able to trigger a crash with an invalid input. This is how: 1. ethtool -l -> combined: 40 2. ethtool -L rx 0 tx 0 combined number is not specified, so command becomes {rx_count = 0, tx_count = 0, combined_count = 40}. 3. ethnl_set_channels checks, if there is at least 1 RX and 1 TX channel, comparing (combined_count + rx_count) and (combined_count + tx_count) to zero. Obviously, (40 + 0) is greater than zero, so the core code deems the input OK. 4. idpf interprets `rx 0 tx 0` as 0 channels and tries to proceed with such configuration. The issue has to be solved fundamentally, as current logic is also known to cause AF_XDP problems in ice [0]. Interpret the command in a way that is more consistent with ethtool manual [1] (--show-channels and --set-channels) and new ice logic. Considering that in the idpf driver only the difference between RX and TX queues forms dedicated channels, change the correct way to set number of channels to: ethtool -L combined 10 /* For symmetric queues */ ethtool -L combined 8 tx 2 rx 0 /* For asymmetric queues */ [0] https://lore.kernel.org/netdev/20240418095857.2827-1-larysa.zaremba@intel.com/ [1] https://man7.org/linux/man-pages/man8/ethtool.8.html Fixes: 02cbfba1add5 ("idpf: add ethtool callbacks") Reviewed-by: Przemek Kitszel Reviewed-by: Igor Bagnucki Signed-off-by: Larysa Zaremba Tested-by: Krishneil Singh Reviewed-by: Simon Horman Signed-off-by: Jacob Keller --- drivers/net/ethernet/intel/idpf/idpf_ethtool.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf_ethtool.c b/drivers/net/ethernet/intel/idpf/idpf_ethtool.c index 6972d728431c..1885ba618981 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_ethtool.c +++ b/drivers/net/ethernet/intel/idpf/idpf_ethtool.c @@ -222,14 +222,19 @@ static int idpf_set_channels(struct net_device *netdev, struct ethtool_channels *ch) { struct idpf_vport_config *vport_config; - u16 combined, num_txq, num_rxq; unsigned int num_req_tx_q; unsigned int num_req_rx_q; struct idpf_vport *vport; + u16 num_txq, num_rxq; struct device *dev; int err = 0; u16 idx; + if (ch->rx_count && ch->tx_count) { + netdev_err(netdev, "Dedicated RX or TX channels cannot be used simultaneously\n"); + return -EINVAL; + } + idpf_vport_ctrl_lock(netdev); vport = idpf_netdev_to_vport(netdev); @@ -239,20 +244,6 @@ static int idpf_set_channels(struct net_device *netdev, num_txq = vport_config->user_config.num_req_tx_qs; num_rxq = vport_config->user_config.num_req_rx_qs; - combined = min(num_txq, num_rxq); - - /* these checks are for cases where user didn't specify a particular - * value on cmd line but we get non-zero value anyway via - * get_channels(); look at ethtool.c in ethtool repository (the user - * space part), particularly, do_schannels() routine - */ - if (ch->combined_count == combined) - ch->combined_count = 0; - if (ch->combined_count && ch->rx_count == num_rxq - combined) - ch->rx_count = 0; - if (ch->combined_count && ch->tx_count == num_txq - combined) - ch->tx_count = 0; - num_req_tx_q = ch->combined_count + ch->tx_count; num_req_rx_q = ch->combined_count + ch->rx_count;