From patchwork Sat Oct 22 07:18:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7139 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1087401wrr; Sat, 22 Oct 2022 00:36:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4qQquTO6FHlQ+UtTTsW+HbBasxDTdY8l2ylTK3t/w3cjJ9bD/PpGmOkcgCviLHI6STCPYM X-Received: by 2002:a05:6402:2211:b0:461:5d0a:6678 with SMTP id cq17-20020a056402221100b004615d0a6678mr4721062edb.378.1666424177072; Sat, 22 Oct 2022 00:36:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424177; cv=none; d=google.com; s=arc-20160816; b=0++qIY7OiKIWMTTwtlrBi6YPXN+pxtid3G+rLWXKYoaytWy05bRGXZsY8aM2Xl5a4/ WgsLpqR6lA5L43k2/0EaW1/lsl6XD3uVROhQP0h7Vi28aelxJ3XUJ6I8k1cBjFS1bcHs fHb9f1sWkj7203Dwp+eUWTWxF9pjyo68/4YJB/YQffxC36AxgplUj93VWr/b4xC91OFj +eqrhl27t56iis8ZEA1FoKombTGd3thPJdvwQ4rsU9PSYof9v2BpNAcvuwXcBF3pWH0B hKptpbyPpmRRLvCP5ZeNLdATmce9Zde3CUgUvNcC6Y18b9JGxdWC/kq3/e3LBCnRFZ97 JoBQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hk6-20020a170906c9c600b0077497671e2asi20963552ejb.406.2022.10.22.00.35.53; Sat, 22 Oct 2022 00:36:17 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747372397965487065?= X-GMAIL-MSGID: =?utf-8?q?1747372397965487065?= 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);