From patchwork Thu Oct 27 14:58:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1695446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=iElqqfZZ; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MypkB4hbKz23lD for ; Fri, 28 Oct 2022 01:59:46 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oo4M6-0004fb-6N; Thu, 27 Oct 2022 14:59:38 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oo4M3-0004fA-Mf for kernel-team@lists.ubuntu.com; Thu, 27 Oct 2022 14:59:35 +0000 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id DA6D9423FF for ; Thu, 27 Oct 2022 14:59:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1666882774; bh=Cnw5CuF1VeEahpKtJSCodpJrNX5pTeGMQ+fsy2D5PO8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iElqqfZZpszss+5m8Yxsdk5kP5ujyasmP3WWwFTGwbArs+RvylH8Ggd58wdtGQ4n8 srAKNnNCEgVPNV9HroByLXBKq0vY6oGSb+g4QsSDVAsH7GXp6JQvqYZ2pB3STaegQT WHIKUeRnfXfCDCLVFA0GA1lxF5pk0nZ38vJ/u+v9pp0tM4PhYiwNZ8p8F2/FRRbyRX H/2j3SMk3qCYA0PWUnAyOEvUNhV871Nsgiz1kWHNFw412u5vBewe6rbKVyTI/mFj9m cyd1gSRnsxbLrMPtIjTntobiEPNmMnDWmLWdbvrf+TGv53GsjQY/pfFI0fX+yITJM3 33h9DxxsfT6hg== Received: by mail-pl1-f198.google.com with SMTP id x18-20020a170902ec9200b001869f20da7eso1203585plg.10 for ; Thu, 27 Oct 2022 07:59:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cnw5CuF1VeEahpKtJSCodpJrNX5pTeGMQ+fsy2D5PO8=; b=FpGV7aNNWbKM9CFdzWN8OPzxWDiO0T2Mq4U3kyzxaXI8Fv2fJn16acCS1tQBjZzhBk HHLNJDoI6XERJNRfWLPd6rMTYZ0GnrSGF5JQ9FMkwc6fuFbmaR310wZpZmiP8BfNEYPA HHJAUlllCzesaCIsdW4y86p3d7t2McK4PYkYJpEtkk8Zwgwjq7VBf/01lmdVqiquXCmt urVuAiYdvVFDicVnUgIJxJ/SRJXONecw47pilAwoPgLcjxHAAsJ6VNAgjtfATYBAy0s/ 6N2RURPFwzL+HZ2R7950V5JJVcD63on3ZGbH5ADEmnipqCJX3NvFF61qBYYjUO36FnZL U/jg== X-Gm-Message-State: ACrzQf1a0veuoqG9jNtG3K0tKDHYpg0im7miggnJKK7WdxZc46ffyI4Z 1C+XvfjUyEJZz1wxN52lMi7qyir3qHfs55aw6L7G9zLfxCkZLEjh25bRvbHS7+wE2ZRhBLEhpiE 4hNTN7FZacigsAf4YEedo4uXoo6l+p6KiO+rGY/5mcQ== X-Received: by 2002:a17:90b:4f4d:b0:20d:2225:4275 with SMTP id pj13-20020a17090b4f4d00b0020d22254275mr10880776pjb.191.1666882773138; Thu, 27 Oct 2022 07:59:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM64f7fOKDoPfEx88LuEjklXfkKLkvGkBJw6gN3OBFra1pbY6kgbDBsbK6Jjw0sMSSHsF5g7Hw== X-Received: by 2002:a17:90b:4f4d:b0:20d:2225:4275 with SMTP id pj13-20020a17090b4f4d00b0020d22254275mr10880754pjb.191.1666882772896; Thu, 27 Oct 2022 07:59:32 -0700 (PDT) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id b3-20020a170902650300b00186a6b63525sm1298841plk.120.2022.10.27.07.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 07:59:32 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH][kinetic linux-azure] hv_netvsc: Fix race between VF offering and VF association message from host Date: Thu, 27 Oct 2022 08:58:50 -0600 Message-Id: <20221027145850.41806-4-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221027145850.41806-1-tim.gardner@canonical.com> References: <20221027145850.41806-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Gaurav Kohli BugLink: https://bugs.launchpad.net/bugs/1994974 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 (cherry picked from commit bf28cb8811b5f6eb74d5ec39b019cb40de3fedb3 linux-5.19.y) Signed-off-by: Tim Gardner --- 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(-) diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h index 25b38a374e3c..dd5919ec408b 100644 --- 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; diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 6e42cb03e226..456db7c28a34 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -1580,6 +1580,10 @@ static void netvsc_send_vf(struct net_device *ndev, 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"); diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index 15ebd5426604..8113ac17ab70 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -2313,6 +2313,18 @@ static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev) } + /* 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_device *vf_netdev, unsigned long event) 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 net_device *vf_netdev) 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 *dev, 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);