Received: by 2002:ac8:4f8f:0:b0:429:955e:b7c6 with SMTP id j15csp3615qtw; Tue, 16 Jan 2024 12:59:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsYuGQmtg4WUd05J+6+W3faM7drhxabE8hTz2KOyuNy4NqWRgQ5v/pT0U3kEwveZyHr1HG X-Received: by 2002:a17:906:b241:b0:a2d:468c:3845 with SMTP id ce1-20020a170906b24100b00a2d468c3845mr5672940ejb.35.1705438768657; Tue, 16 Jan 2024 12:59:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705438768; cv=pass; d=google.com; s=arc-20160816; b=dhWAAo5rgWqbFhhSP5VM4OYg6trbUsQvJxRWDrglB2fmln0Pc+X14/LlPNzvCX7Qrh cjckZ3Wq8ON2BJYArNKYFq7BdZvSioH9KjdjvQXZZX9NrWircgTHkjuXuryAEgnXQrEs i5MHa1TBKrdErAyQQvYKmJ6OW4d2HOYY7eBjUtlGse8kpsinfU4lSQ97aMHXfHk5Ifcn A31Oz2IlWCedIlWHi16BSfujbhjG2cWAa70cFBXE4KUme7zxoG3Qhd+nVpgbzfFaahlm VCxw496of0xqOx1SW8zJ6ii8SXgrBIpIy27XDUc/el/iV3Oe+iulvfYq8b3vIZXi9z9W Sg7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=C6X/ykVAWkbHzmAUtlbp9i96BUCy8Y02OOKdX1ARbBg=; fh=oj52NPWlsAjujXo6JsNvqTIo8fMvuaYF4RlgIRVd4Ao=; b=XDGDZjc1vRasadqLLiiRtraIFclrGTUx9DfAXrUXrFfIPrBotfEcKOUNsfk/fhK9dZ A6ehXUXDPFxamn+oo6gRM198tHAImmYpsapNN1CjIHPX3eM/aYHupNuwleu9rAZm3qfs DzBMlQwaK+jLbF4C3q9V2NorW7Fadzf14CduUpzCMZ/EHckrCKUKUll3UVGoMvKNIN81 jKro2oQZUNMbYkc3dFH3bQHTufrLzj7dSkIbNj7QgJGtHYPElzVE/KWvqs1PtJ/9geqB Ir3OUkmqux3kUzQl+BXMGU72AC34bWHvS2SmpNvj1Rve1jHoeuWtE5L+ao32IfddH8lA u1YA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="sW/P09Y3"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-28013-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28013-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id op19-20020a170906bcf300b00a2cb9f93255si4121015ejb.668.2024.01.16.12.59.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 12:59:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28013-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="sW/P09Y3"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-28013-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28013-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3E0A11F263ED for ; Tue, 16 Jan 2024 20:59:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF0605C5F4; Tue, 16 Jan 2024 19:53:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sW/P09Y3" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E544628E1F; Tue, 16 Jan 2024 19:53:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705434836; cv=none; b=WPmkMZcopHKO5LyzEPJYpVsGJNncGuDr3t7v8lGYRcLOhRMX9vAtu6kAlftqJ9HvzRt+TCq5xDeZTiNca9P+NWrB3SCnc7IwUXfoxv1vdimy0Rx1vY6U5aYfCfbKPoGlY2YVG9DFVBL3cXNIP+bOfgYVltmJ5JAE28U3dLMRcd4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705434836; c=relaxed/simple; bh=0EhPbzugpHhhjXKz7HNRPo85aLkvcRSu83dyfdZVnwY=; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version:X-stable: X-Patchwork-Hint:X-stable-base:Content-Transfer-Encoding; b=q3EUT2uxBex204kDImjT0b+2QpdbRf//PHM/sVkO2aAAvfcfO7IiE6ECsvNd1aiPT//gMXVa12jwMkmuDDAIdVnKHeqcJuOMP5+OrMfEXry2JwLNHmSc8PAEsdZ5o27/KKcUVENYDKFeYbXkI/xxkEbg3tm/Eb2HBUgDlAfSkTc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sW/P09Y3; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0457C433C7; Tue, 16 Jan 2024 19:53:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705434835; bh=0EhPbzugpHhhjXKz7HNRPo85aLkvcRSu83dyfdZVnwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sW/P09Y3J6QDBXpJqvYT0Pw2zyOoLC6FQx7zQzenA4MriAHplOzvNXn7eXk9Z9Lgc xbtES1ggo2kt4igLKs9gLZxHNBo9VTsxRBC7XkLe6N6SiQQbMe8NJwCBKujlhbLHtd OLAELp9/W/PE+LKsQqH3ZNQFriqGyubxy7lmJ+Vg8kdPCNeetnpsOvp5cyc/tFAavX SvvJIShFq8KjTy5+7ICrErs3UG5qz3AvcRTHeQKLQvMFCY1I7KSSzxzEA5c+7ApLKD 0gVyX9jtwsUHw8MXxj+p9mV7sWVMBuWNLRdaKnU09Izopik8/JKLI6UN+0wMxdHg9K +3HbuAb2cauXA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrii Staikov , Aleksandr Loktionov , Jan Sokolowski , Wojciech Drewek , Przemek Kitszel , Rafal Romanowski , Tony Nguyen , Sasha Levin , jesse.brandeburg@intel.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 6.6 101/104] i40e: Fix VF disable behavior to block all traffic Date: Tue, 16 Jan 2024 14:47:07 -0500 Message-ID: <20240116194908.253437-101-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116194908.253437-1-sashal@kernel.org> References: <20240116194908.253437-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.12 Content-Transfer-Encoding: 8bit From: Andrii Staikov [ Upstream commit 31deb12e85c35ddd2c037f0107d05d8674cab2c0 ] Currently, if a VF is disabled using the 'ip link set dev $ETHX vf $VF_NUM state disable' command, the VF is still able to receive traffic. Fix the behavior of the 'ip link set dev $ETHX vf $VF_NUM state disable' to completely shutdown the VF's queues making it entirely disabled and not able to receive or send any traffic. Modify the behavior of the 'ip link set $ETHX vf $VF_NUM state enable' command to make a VF do reinitialization bringing the queues back up. Co-developed-by: Aleksandr Loktionov Signed-off-by: Aleksandr Loktionov Reviewed-by: Jan Sokolowski Reviewed-by: Wojciech Drewek Reviewed-by: Przemek Kitszel Signed-off-by: Andrii Staikov Tested-by: Rafal Romanowski Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- .../ethernet/intel/i40e/i40e_virtchnl_pf.c | 32 +++++++++++++++++++ .../ethernet/intel/i40e/i40e_virtchnl_pf.h | 1 + 2 files changed, 33 insertions(+) diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c index 4441b00297f4..0f8ee90b27e7 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c @@ -2579,6 +2579,14 @@ static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg) int aq_ret = 0; int i; + if (vf->is_disabled_from_host) { + aq_ret = -EPERM; + dev_info(&pf->pdev->dev, + "Admin has disabled VF %d, will not enable queues\n", + vf->vf_id); + goto error_param; + } + if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) { aq_ret = -EINVAL; goto error_param; @@ -4706,9 +4714,12 @@ int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link) struct i40e_link_status *ls = &pf->hw.phy.link_info; struct virtchnl_pf_event pfe; struct i40e_hw *hw = &pf->hw; + struct i40e_vsi *vsi; + unsigned long q_map; struct i40e_vf *vf; int abs_vf_id; int ret = 0; + int tmp; if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) { dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n"); @@ -4731,17 +4742,38 @@ int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link) switch (link) { case IFLA_VF_LINK_STATE_AUTO: vf->link_forced = false; + vf->is_disabled_from_host = false; + /* reset needed to reinit VF resources */ + i40e_vc_reset_vf(vf, true); i40e_set_vf_link_state(vf, &pfe, ls); break; case IFLA_VF_LINK_STATE_ENABLE: vf->link_forced = true; vf->link_up = true; + vf->is_disabled_from_host = false; + /* reset needed to reinit VF resources */ + i40e_vc_reset_vf(vf, true); i40e_set_vf_link_state(vf, &pfe, ls); break; case IFLA_VF_LINK_STATE_DISABLE: vf->link_forced = true; vf->link_up = false; i40e_set_vf_link_state(vf, &pfe, ls); + + vsi = pf->vsi[vf->lan_vsi_idx]; + q_map = BIT(vsi->num_queue_pairs) - 1; + + vf->is_disabled_from_host = true; + + /* Try to stop both Tx&Rx rings even if one of the calls fails + * to ensure we stop the rings even in case of errors. + * If any of them returns with an error then the first + * error that occurred will be returned. + */ + tmp = i40e_ctrl_vf_tx_rings(vsi, q_map, false); + ret = i40e_ctrl_vf_rx_rings(vsi, q_map, false); + + ret = tmp ? tmp : ret; break; default: ret = -EINVAL; diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h index 895b8feb2567..9fc1a143a494 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h @@ -98,6 +98,7 @@ struct i40e_vf { bool link_forced; bool link_up; /* only valid if VF link is forced */ bool spoofchk; + bool is_disabled_from_host; /* PF ctrl of VF enable/disable */ u16 num_vlan; /* ADq related variables */ -- 2.43.0