Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3927251rwi; Sat, 22 Oct 2022 02:21:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6KHykM6mrcEXKvxHLa1nloELB+U7MFj/nkCZ4rI1eFNjQryXbgan4I5SF9f4Bav2HytSGo X-Received: by 2002:a63:2ac9:0:b0:457:24a2:6fa7 with SMTP id q192-20020a632ac9000000b0045724a26fa7mr19335446pgq.484.1666430489908; Sat, 22 Oct 2022 02:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666430489; cv=none; d=google.com; s=arc-20160816; b=qs1NxHy69Io5IMt6IHteUwsh6HCvqfniKBDA5osSblafjX5Re6J1NMxoUyVvy5xQ8N Y9UVfSPsaVbbt5HNx2wrI94C5xZK87jdy2VCBIcMUDWhkIOq7TI8Bfv/pE9/yaKpwTPi 08yPHF8LHxKr0LCMV2yYA5mgqhex1J2IopT+JFtDtr4Z3vm/1CLLX6riCzHRRNX6sTht /wmu9dGhHwcFjeTLzGv+TXFNqp+4hU1lFbQMFRAEBDRMXjfv1HsFIHnlTJbLou3bVnTE 5zqyd8MVwJNCs+6lwFJuF9tT9Av4UGZaJuwtl5U8SY19FMFNSrMkbz4NkQ47uVf8bVCe DcEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=beT7UKZDXTZh/bPrJqdNaL8Bv0op8oPEPbElUbwPhjU=; b=rvtdIqRYxmLaGn2V0e5dzG/vNWFxbIDQCzy6y4QyWxNX06AxZaViW0LZP95wn1LDSw prlwyOdqS3La+YgO2y90Regn2T+D4fnN9rYbOQyFng3kiellD/vWL4iVcT+Eu+0qwdbF Ho3JJvyu5CtKNlc7trtg/mIg/0O8vj5yXDhIxoecCTmFiWwtjpUTWEdsrQE8xk1fcNts 7NPEjUMR40BeALRwe79yHGe6kW1B1UZy2ABBT5oTcDTm+0EGxl/kg5RlzgMnzxymBj7b loLYOthseHC3XMtGm+Sp4XJbQKgA1koJ6aqbMbdl6b7pOFbTJVqYjEHv1MhHdTF6T7nN 2QeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SXp/g9iT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cp8-20020a056a00348800b00565de49c23dsi23983293pfb.105.2022.10.22.02.21.18; Sat, 22 Oct 2022 02:21:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SXp/g9iT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230170AbiJVHe6 (ORCPT + 99 others); Sat, 22 Oct 2022 03:34:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbiJVHed (ORCPT ); Sat, 22 Oct 2022 03:34:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2929A1F9EE; Sat, 22 Oct 2022 00:34:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 44DD0B82DF1; Sat, 22 Oct 2022 07:34:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 823A4C433D7; Sat, 22 Oct 2022 07:34:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424062; bh=db2V0LRd+meO9yClRgIgT7wRDLvS+JUnwgMu5rf4fkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SXp/g9iTCFVDx4JNibCKgs2SU12FS8J/uqnSNbPf6v2PmArNZiUmhQSHRPCgLSLz4 gCU5G98+HHWVgGJteqxqPtzbNywhAMrQmbSni96ADL82To4BJiGd8KgykPfTijlHDR cg3bSARydyIZz1EbuEkQmORsEd5d5EDkLlR3w7co= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Haiyang Zhang , Gaurav Kohli , "David S. Miller" Subject: [PATCH 5.19 016/717] hv_netvsc: Fix race between VF offering and VF association message from host Date: Sat, 22 Oct 2022 09:18:15 +0200 Message-Id: <20221022072417.934407805@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gaurav Kohli commit 365e1ececb2905f94cc10a5817c5b644a32a3ae2 upstream. During vm boot, there might be possibility that vf registration call comes before the vf association from host to vm. And this might break netvsc vf path, To prevent the same block vf registration until vf bind message comes from host. Cc: stable@vger.kernel.org Fixes: 00d7ddba11436 ("hv_netvsc: pair VF based on serial number") Reviewed-by: Haiyang Zhang Signed-off-by: Gaurav Kohli Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/hyperv/hyperv_net.h | 3 ++- drivers/net/hyperv/netvsc.c | 4 ++++ drivers/net/hyperv/netvsc_drv.c | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) --- a/drivers/net/hyperv/hyperv_net.h +++ b/drivers/net/hyperv/hyperv_net.h @@ -1051,7 +1051,8 @@ struct net_device_context { u32 vf_alloc; /* Serial number of the VF to team with */ u32 vf_serial; - + /* completion variable to confirm vf association */ + struct completion vf_add; /* Is the current data path through the VF NIC? */ bool data_path_is_vf; --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -1580,6 +1580,10 @@ static void netvsc_send_vf(struct net_de net_device_ctx->vf_alloc = nvmsg->msg.v4_msg.vf_assoc.allocated; net_device_ctx->vf_serial = nvmsg->msg.v4_msg.vf_assoc.serial; + + if (net_device_ctx->vf_alloc) + complete(&net_device_ctx->vf_add); + netdev_info(ndev, "VF slot %u %s\n", net_device_ctx->vf_serial, net_device_ctx->vf_alloc ? "added" : "removed"); --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -2313,6 +2313,18 @@ static struct net_device *get_netvsc_bys } + /* Fallback path to check synthetic vf with + * help of mac addr + */ + list_for_each_entry(ndev_ctx, &netvsc_dev_list, list) { + ndev = hv_get_drvdata(ndev_ctx->device_ctx); + if (ether_addr_equal(vf_netdev->perm_addr, ndev->perm_addr)) { + netdev_notice(vf_netdev, + "falling back to mac addr based matching\n"); + return ndev; + } + } + netdev_notice(vf_netdev, "no netdev found for vf serial:%u\n", serial); return NULL; @@ -2409,6 +2421,11 @@ static int netvsc_vf_changed(struct net_ if (net_device_ctx->data_path_is_vf == vf_is_up) return NOTIFY_OK; + if (vf_is_up && !net_device_ctx->vf_alloc) { + netdev_info(ndev, "Waiting for the VF association from host\n"); + wait_for_completion(&net_device_ctx->vf_add); + } + ret = netvsc_switch_datapath(ndev, vf_is_up); if (ret) { @@ -2440,6 +2457,7 @@ static int netvsc_unregister_vf(struct n netvsc_vf_setxdp(vf_netdev, NULL); + reinit_completion(&net_device_ctx->vf_add); netdev_rx_handler_unregister(vf_netdev); netdev_upper_dev_unlink(vf_netdev, ndev); RCU_INIT_POINTER(net_device_ctx->vf_netdev, NULL); @@ -2479,6 +2497,7 @@ static int netvsc_probe(struct hv_device INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change); + init_completion(&net_device_ctx->vf_add); spin_lock_init(&net_device_ctx->lock); INIT_LIST_HEAD(&net_device_ctx->reconfig_events); INIT_DELAYED_WORK(&net_device_ctx->vf_takeover, netvsc_vf_setup);