From patchwork Thu Oct 27 14:58:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1695449 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=azt7E5Yk; 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 4MypkG5M3Gz20S2 for ; Fri, 28 Oct 2022 01:59:50 +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 1oo4MB-0004kI-WB; Thu, 27 Oct 2022 14:59:44 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oo4M1-0004ez-VF for kernel-team@lists.ubuntu.com; Thu, 27 Oct 2022 14:59:33 +0000 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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-1.canonical.com (Postfix) with ESMTPS id 5F1FD412D2 for ; Thu, 27 Oct 2022 14:59:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1666882773; bh=lBQ91/v1sW7Q5dP7gEfqyextTfIdRcnJk6CKKfyMICA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=azt7E5YkZIg+yMhbm/iE/sZdewuvMNCsund16pOmwoat5XKWG6IYhqWblhwmh5usw 0UwEQoS1YHvBB7aM6Y4z4wBF9Pbce/sgevpea8J9HfSDxHKGbayEKR9FZKDzZCI4sT DSgFsx5wzJsVgKO3N5vyUg4pzGZXeVCnrcWbmCisHydFMMx85vr5+a8VjS774EkY7I 8o6fLnTYtD2lFgYebshUPT1FgRZYVFIoKqNRujroSmcPZbOHaujoCiDdcJlWrP60hS oGKu194dZkGD++Ldayi1xqi8Z4MVhP/jwzb8u4ZbVwUWINP0duXtgrV5Sw0cO1EWol /GKsS55FnVXWw== Received: by mail-pl1-f197.google.com with SMTP id j7-20020a170902da8700b0018540711393so1181962plx.18 for ; Thu, 27 Oct 2022 07:59:33 -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=lBQ91/v1sW7Q5dP7gEfqyextTfIdRcnJk6CKKfyMICA=; b=oDVfGrBduWvlYEK+hj80wa0JxNYpzzsl7eIUUtwlBfPcF37Ot8jyIOfRmJv0N2YjvH /c+4wsg4wMDMWyNKMVnaWddF7ohPL4EhbCJc+PhMP/l/5jrnyj7fSKfxJ9oBnRV/j/og Z3U6Pzw3IA7FnKVg2+EURJNiKoTKof/uJKcIFR/NOYXNVNbX0vZZ/Pk1qOLHuXglyIo+ 4kv1OPjCYsuraKPRG9SEwDjV2UH3Le5QKZ+IcAzsXJW/oK9dnTwk13Bmv0OPg9coDRda wCQ5qLWF4e7LpIHWD2xeWwvjTQbvG86iZ/EG4GLlJMZN1iXEMcDFm7nABFcR8R2NC4Gd Y8Jg== X-Gm-Message-State: ACrzQf0PBX6ssIKIX4r0fa9PWr7Czn4ZoW/rx+Ri0Fn3sHZXfecwbJeb x08DLYnnAWk+7szME3Ci4infTZIC88RH4H8fnYQNNYuIcMlIxlyeEIcp/t6kYLBfwClsZXQYktK bcrgvtdsp2AuthfGlm329DXL395egG5HZq5UMFJOLZg== X-Received: by 2002:a17:90a:588a:b0:212:fa50:7dec with SMTP id j10-20020a17090a588a00b00212fa507decmr10742481pji.190.1666882771682; Thu, 27 Oct 2022 07:59:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4WPmXXZPlinMn8frr1hCrY3p1XuYMwcsyHqZllHqAjqQyS4eaMn5H+iRqIny63ZglRrDnuGQ== X-Received: by 2002:a17:90a:588a:b0:212:fa50:7dec with SMTP id j10-20020a17090a588a00b00212fa507decmr10742453pji.190.1666882771381; Thu, 27 Oct 2022 07:59:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 07:59:30 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH][focal linux-azure] hv_netvsc: Fix race between VF offering and VF association message from host Date: Thu, 27 Oct 2022 08:58:48 -0600 Message-Id: <20221027145850.41806-2-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 (backported from commit 15993e9a9b12487192cbf7eebf838676e05895d5 linux-5.15.y) [rtg - conflict resolution] Signed-off-by: Tim Gardner --- drivers/net/hyperv/hyperv_net.h | 2 ++ drivers/net/hyperv/netvsc.c | 4 ++++ drivers/net/hyperv/netvsc_drv.c | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h index 44889c1763b6..0329e9737439 100644 --- a/drivers/net/hyperv/hyperv_net.h +++ b/drivers/net/hyperv/hyperv_net.h @@ -975,6 +975,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; /* Used to temporarily save the config info across hibernation */ struct netvsc_device_info *saved_netvsc_dev_info; diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index def2adb5217f..a97067f92dd3 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -1230,6 +1230,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 c2d752d29898..bb36c5de0db6 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -2289,6 +2289,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; @@ -2366,6 +2378,11 @@ static int netvsc_vf_changed(struct net_device *vf_netdev) if (!netvsc_dev) return NOTIFY_DONE; + 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); + } + netvsc_switch_datapath(ndev, vf_is_up); netdev_info(ndev, "Data path switched %s VF: %s\n", vf_is_up ? "to" : "from", vf_netdev->name); @@ -2389,6 +2406,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); @@ -2426,6 +2444,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);