From patchwork Wed Oct 19 08:21:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4510 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp202809wrs; Wed, 19 Oct 2022 01:41:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6qT4nkl9y+CmpMO69piSAD8v9Uw3hIeA59ytYQlSxHGHGyDZ21+CbnpBuzOzEkPCQcl9Gu X-Received: by 2002:a05:6402:528a:b0:454:8613:6560 with SMTP id en10-20020a056402528a00b0045486136560mr6626325edb.252.1666168890017; Wed, 19 Oct 2022 01:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666168890; cv=none; d=google.com; s=arc-20160816; b=NYzjyc6B1ID4dIBnV9+0T/YGkkIenrnG7r3cen0yYL6ErynLAW+xi6RZccjosDsR/g ByI3TRPYF6Wgs6bcEDnRLVyMWQyMLweu38E2a27RFA4tN8pjHpB0GkGcYcOX0n0FF00H JuXnvTzGB+hmd8e4pr+Au2Il9WmF/nljO82+4Z9Galc8XDkt6qqgN6d93kMadRwjJ71u MJKbeHb1mMBL6I2t5LPe5tlLir9XXg4xao2F+2k/sWJcoUjftAXDXZIbWKgG1Gx5XBqn /QKQ9uvmxmayKLcCDLTr+SK2iO6y7if5S6r5tbZRbF8EHd0SfMErteiQyCzzK/PkFe8h YAlg== 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=ViwfkJVp/bBWqSIM7og+2GH6HPf5QHAVLdfcVcH2By+K0AjGGVkblNG1bihBZOrrPo MAIAi3Xik54qra4gQislEN6YaufqocjOrpLILD4i/C1WrQ/ymaD5lTZkKGNKF6ITcaOP Vff85wWRW/PnnZHDRpPJhgbjgn0XWSfnNP06a0eSXFAShttAErltlRy86TtKFsfqL05e UnIo933wV3LjG0vKWKtQNWrP8HPO0WUJDziu2/HaK1V/7UsabngtaZvxR3IcKBGgi5ba G4TPKotl/4upGwe8BOG3yJvQ9XLtwZ9FUXIhmIfie4O3GzJwdvnv0oBzbS4oJyS6zl1V vitg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cQASiP97; 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 y15-20020a056402440f00b00459f6b0fa96si17024763eda.355.2022.10.19.01.41.04; Wed, 19 Oct 2022 01:41:30 -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=cQASiP97; 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 S230227AbiJSIkf (ORCPT + 99 others); Wed, 19 Oct 2022 04:40:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230338AbiJSIjn (ORCPT ); Wed, 19 Oct 2022 04:39:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E26E80BC7; Wed, 19 Oct 2022 01:38:51 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 0FAD7617DE; Wed, 19 Oct 2022 08:38:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21637C433B5; Wed, 19 Oct 2022 08:38:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168688; bh=db2V0LRd+meO9yClRgIgT7wRDLvS+JUnwgMu5rf4fkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cQASiP97V/tf6i+Ead1dv2+jVbs+QEccLO0vKDNE8C6KpGS8A9x27qZU0S3/9DDRn qddxBHcNokTGrX5LOxGn4g8/ATgxULY3iU4CFA9+W/ysYST7AbStMCYo98uJ3NP77Y pJdBS4JSgdNge18LGaenGnOsbXg8ALf8SlZ4JZVQ= 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 6.0 021/862] hv_netvsc: Fix race between VF offering and VF association message from host Date: Wed, 19 Oct 2022 10:21:48 +0200 Message-Id: <20221019083250.943069438@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747104709878372198?= X-GMAIL-MSGID: =?utf-8?q?1747104709878372198?= 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);