From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 D0B3113AD4 for ; Mon, 10 Jul 2023 16:46:13 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 550D11AC for ; Mon, 10 Jul 2023 09:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689007571; x=1720543571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wItcQxj7Ijk7cTyaZ4TeC0LPNSYoy4/N1fS7CIIRWEA=; b=EfGYA0081pHhaeXI5fVSbB7y1WeoNL50RQVAwEggIqSupUqGEKCIhNiE m3m8gO0p1dlsLyzGZmpQu4K9r0J8z8lO6NW6Xjumg9KIWN6q1zvn1fmME SHU4PKQSrV0Q+CfN1hn/FtxMEs41ZKlElab84IXLRR4cN1Ha5bAWg9iXY fmLOsMJ+DJfRQEHEWmIQsyk3JmkDNLR4ebH10FkdykhzlYoYsm5T1cxxD SZRy2jjEMNwR9kYBE+h1U/+vSOcBJ+MP/tT53oqvFgMUdDbaT8IxrrwSc wwiheULsU8G4kjfHb6PCk2kvQ/dJSvG3VIbe8ykWhwAP+Xysg5ndiZ2AZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10767"; a="349198575" X-IronPort-AV: E=Sophos;i="6.01,195,1684825200"; d="scan'208";a="349198575" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2023 09:46:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10767"; a="720755272" X-IronPort-AV: E=Sophos;i="6.01,195,1684825200"; d="scan'208";a="720755272" Received: from anguy11-upstream.jf.intel.com ([10.166.9.133]) by orsmga002.jf.intel.com with ESMTP; 10 Jul 2023 09:46:08 -0700 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, netdev@vger.kernel.org Cc: Ivan Vecera , anthony.l.nguyen@intel.com, Ma Yuying , Simon Horman , Rafal Romanowski Subject: [PATCH net-next 2/2] i40e: Wait for pending VF reset in VF set callbacks Date: Mon, 10 Jul 2023 09:40:30 -0700 Message-Id: <20230710164030.2821326-3-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230710164030.2821326-1-anthony.l.nguyen@intel.com> References: <20230710164030.2821326-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net From: Ivan Vecera Commit 028daf80117376 ("i40e: Fix attach VF to VM issue") fixed a race between i40e_ndo_set_vf_mac() and i40e_reset_vf() during an attachment of VF device to VM. This issue is not related to setting MAC address only but also VLAN assignment to particular VF because the newer libvirt sets configured MAC address as well as an optional VLAN. The same behavior is also for i40e's .ndo_set_vf_rate and .ndo_set_vf_spoofchk where the callbacks just check if the VF was initialized but not wait for the finish of pending reset. Reproducer: [root@host ~]# virsh attach-interface guest hostdev --managed 0000:02:02.0 --mac 52:54:00:b4:aa:bb error: Failed to attach interface error: Cannot set interface MAC/vlanid to 52:54:00:b4:aa:bb/0 for ifname enp2s0f0 vf 0: Resource temporarily unavailable Fix this issue by using i40e_check_vf_init_timeout() helper to check whether a reset of particular VF was finished in i40e's .ndo_set_vf_vlan, .ndo_set_vf_rate and .ndo_set_vf_spoofchk callbacks. Tested-by: Ma Yuying Signed-off-by: Ivan Vecera Reviewed-by: Simon Horman Tested-by: Rafal Romanowski Signed-off-by: Tony Nguyen --- .../net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c index b84b6b675fa7..4741ba14ab27 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c @@ -4466,13 +4466,11 @@ int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, int vf_id, } vf = &pf->vf[vf_id]; - vsi = pf->vsi[vf->lan_vsi_idx]; - if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) { - dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n", - vf_id); + if (!i40e_check_vf_init_timeout(vf)) { ret = -EAGAIN; goto error_pvid; } + vsi = pf->vsi[vf->lan_vsi_idx]; if (le16_to_cpu(vsi->info.pvid) == vlanprio) /* duplicate request, so just return success */ @@ -4616,13 +4614,11 @@ int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate, } vf = &pf->vf[vf_id]; - vsi = pf->vsi[vf->lan_vsi_idx]; - if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) { - dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n", - vf_id); + if (!i40e_check_vf_init_timeout(vf)) { ret = -EAGAIN; goto error; } + vsi = pf->vsi[vf->lan_vsi_idx]; ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate); if (ret) @@ -4789,9 +4785,7 @@ int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable) } vf = &(pf->vf[vf_id]); - if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) { - dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n", - vf_id); + if (!i40e_check_vf_init_timeout(vf)) { ret = -EAGAIN; goto out; } -- 2.38.1