From patchwork Fri Nov 10 14:39:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haiyang Zhang X-Patchwork-Id: 13452459 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42C01199B4; Fri, 10 Nov 2023 14:39:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=microsoft.com header.i=@microsoft.com header.b="gP1rma3f" Received: from BN3PR00CU001.outbound.protection.outlook.com (mail-eastus2azon11020003.outbound.protection.outlook.com [52.101.56.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2201F3975D; Fri, 10 Nov 2023 06:39:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CSyK47w5LLqSu9Gb28a/eMj0Y7mM0uHUwiqzPXpkI5W0p1MS0eGdjqZa7BgI3Pcp+2xktif1ULVVMZSITIQbujm0+6T5Yqm2QGbP+Q38AL+P59Y2RqTsOnE/4s6FkvhNWt2J4cIRWshEEslKBWCW1b/5hK9g/hU4aAT4IFeFh5/nhuqLo2d19A3gQmIF2xVgnOXXpYgkmE00FhULm0Z/Rfo6VggnpODa1jQZJriTBe3cEeL1bPCS3kdtcq28yE3DAW6xUlxM773VjRm3l+VZzRaKpvUI9U800aF7y0SQyexHH2yps8cx7eQjGzSFgUUdhV5kjVgklQhf+S8NCUtU/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JCRRg/i0SpPvQc4DkIDkZh5NQFxErxwLXb4YeAX5DIc=; b=Y2g9q2Rz5R5QppdAXsH+v2oKiLpb2X2oRWiErql3fSYlQlz9gVeZldE1O8GJ5ROuntvlWzA2I2SjNW4IVUl1Wdx/Dwk2Bni8CruZNMdcJ4xwGqAwDHpVkLZCotpT5WqY6AdVkzvNN8f2SM1UJFBpE48gWssH8GXVIll9UN5CYL0+f/MomKjqzMSfk0dRnehphsb3rntAvl4WToOnJEcQewbMkJa2wEfasnJRJbE44ta8OVysJ9bV34BHyN0A2CdZmvxFQzhvALTI2hTHL52uDMFf3nmuAF/QCzBm6Euq92y3MWLjqD1ZUQ7E0mecZNa2u6Ux4NM/CtHKXMAabC3N0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JCRRg/i0SpPvQc4DkIDkZh5NQFxErxwLXb4YeAX5DIc=; b=gP1rma3f2KNPrkcdK2ofL4qXDywxUjKvp6TpegCkUfR2auBufcF709wWWNj0LoVNhjANmj3r5SvBUphAnBqdxtcpJS2IsVFI551LwtV8McfpHRtW8A1gsFKRnn/opIU8pzKdYQIRoQstDYh6JuRT1IlaqziE2xELkRouKVq3czo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BY5PR21MB1443.namprd21.prod.outlook.com (2603:10b6:a03:21f::18) by BL0PR2101MB1348.namprd21.prod.outlook.com (2603:10b6:208:92::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.10; Fri, 10 Nov 2023 14:39:34 +0000 Received: from BY5PR21MB1443.namprd21.prod.outlook.com ([fe80::2f77:8844:9c3f:58c8]) by BY5PR21MB1443.namprd21.prod.outlook.com ([fe80::2f77:8844:9c3f:58c8%4]) with mapi id 15.20.7002.008; Fri, 10 Nov 2023 14:39:34 +0000 From: Haiyang Zhang To: linux-hyperv@vger.kernel.org, netdev@vger.kernel.org Cc: haiyangz@microsoft.com, kys@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, linux-kernel@vger.kernel.org, Long Li , stable@vger.kernel.org Subject: [PATCH net,v4, 3/3] hv_netvsc: Mark VF as slave before exposing it to user-mode Date: Fri, 10 Nov 2023 06:39:00 -0800 Message-Id: <1699627140-28003-4-git-send-email-haiyangz@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1699627140-28003-1-git-send-email-haiyangz@microsoft.com> References: <1699627140-28003-1-git-send-email-haiyangz@microsoft.com> X-ClientProxiedBy: MW4PR04CA0052.namprd04.prod.outlook.com (2603:10b6:303:6a::27) To BY5PR21MB1443.namprd21.prod.outlook.com (2603:10b6:a03:21f::18) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Sender: LKML haiyangz X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR21MB1443:EE_|BL0PR2101MB1348:EE_ X-MS-Office365-Filtering-Correlation-Id: ff3c4eb0-d1e0-48c6-9601-08dbe1fadb8b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mhFjun1plhrGXaw96Y0Gtjd0UpsFKQBDX5fFlUH9uy9tw3cx+mFumjCGCfN3UFM7JkE5+gmKvdx2OgFcMF1DRo1/N9diFucUfxqjcUCvenyWaiN8YbSmfLhjkuJkt2cRRlVgNK7x5VOxQaaYbQnputvMUy45qTnhW5dsMMuunHwpCVtkONCLwW0pbUyH6T3BL1YIfew8SoalsmM6K/8zMZ3A/Q/MKB157jNJaQ1PMyHlmG7XSB+0WbTy7LhIHLTv8ciKr9dXdht+xsPLNcxF8nDwy68de1gOgarEQqwwd7w2yxGeFWwSwx+7QcUzJhS7GDtib+JpOP/MuTIkivZZCsA3wKeu40now5FiAE43RKhoUsY3XlPKercn1ENbi5OobBAvuSfHNdTJHEiUBUdtqaZ9rfNT0R1XNSXwvLvfGRaDwAJDGsTMDPp99VjOCVWMTjoBUp3PVZy8sIzrRpmNNx55beA7fReIz1ldErOhEzyxnwfjmDV1AD1Fjefck20ZAkrpZiY/4Fi4O02BOEfAR3KdvQNTokCJmKwRyqBADrTQ+/ngcK4USWQ4zlWYkuGkHIitq7de70+rFzHUXMgDApwDVFnHvUbhhOXSx6FgkHTW7Az6QfSzb1bfyYCfKsx8igtIeNoI7n56a77PCK0OvpyihDqka1/pWqpmnH++V9E= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR21MB1443.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(396003)(136003)(346002)(376002)(39860400002)(230922051799003)(64100799003)(186009)(451199024)(1800799009)(83380400001)(4326008)(38350700005)(2616005)(82960400001)(26005)(66946007)(316002)(66476007)(66556008)(41300700001)(2906002)(8676002)(8936002)(5660300002)(6666004)(6506007)(7846003)(52116002)(36756003)(6512007)(10290500003)(478600001)(6486002)(82950400001)(38100700002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zrdAP94ts8W3PxHQ6CWrujOxQIQ2lSiN6+6obGB/KuDQ25QRxyLnlVzBndV2sQ+T1SCaumEqsRAq4mAbM2hTkI4sR4+X8skNd5YrsB50r2WspBHhC/wcZ7j8hKlR7WYCtVCF5jnxSNDpRUz9NLReSc9p/mMIP8Pj8j0n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0RvlJBBqWL6uVystNzLY9ZOEfCULiSEzxJsWBIvbWFuat67Rpsts5ToZHOC73cIkqQ8SgbUhOacNhixiXlvGTZAfUhPO1o2XJYPeZWzAWU5DSDUAzf29Jf/yLn2+YPSTBAaN+/Utu/lj1RSTASp6URs9bTl0Nv+OPX3OgXTZsfQFPo4nVPdldC6fXMxxyhZUcaZcKVnFMXAAlbmjGCupwobBiFKEHPznXzGbe4DUA1vNr6FE6mC8hoGzS9vojaCSTeU9OXRWLrPSdJjC7mztP6nGgNEAw4n47l2liHihgYrPrlucSx+NjT5GCrQfSuVsEUdJudhtMr/Y88EOlHWpkd7ew X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff3c4eb0-d1e0-48c6-9601-08dbe1fadb8b X-MS-Exchange-CrossTenant-AuthSource: BY5PR21MB1443.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2023 14:39:34.5582 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7YG1Ou8Pdb7nNpIXYQmlcbfW3PK2co2xNTofAHI4QZcETnWqiQP3LcQ0ya/mCj+0l8q5cPOp3jRDeXUkj/kYxw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1348 X-Patchwork-Delegate: kuba@kernel.org From: Long Li When a VF is being exposed form the kernel, it should be marked as "slave" before exposing to the user-mode. The VF is not usable without netvsc running as master. The user-mode should never see a VF without the "slave" flag. This commit moves the code of setting the slave flag to the time before VF is exposed to user-mode. Cc: stable@vger.kernel.org Fixes: 0c195567a8f6 ("netvsc: transparent VF management") Signed-off-by: Long Li Signed-off-by: Haiyang Zhang --- v4: Add comments in get_netvsc_byslot() explaining the need to check dev_addr v2: Use a new function to handle NETDEV_POST_INIT. --- drivers/net/hyperv/netvsc_drv.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index 1d1491da303b..52dbf1de7347 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -2206,9 +2206,6 @@ static int netvsc_vf_join(struct net_device *vf_netdev, goto upper_link_failed; } - /* set slave flag before open to prevent IPv6 addrconf */ - vf_netdev->flags |= IFF_SLAVE; - schedule_delayed_work(&ndev_ctx->vf_takeover, VF_TAKEOVER_INT); call_netdevice_notifiers(NETDEV_JOIN, vf_netdev); @@ -2315,16 +2312,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 + /* Fallback path to check synthetic vf with help of mac addr. + * Because this function can be called before vf_netdev is + * initialized (NETDEV_POST_INIT) when its perm_addr has not been copied + * from dev_addr, also try to match to its dev_addr. + * Note: On Hyper-V and Azure, it's not possible to set a MAC address + * on a VF that matches to the MAC of a unrelated NETVSC device. */ 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"); + if (ether_addr_equal(vf_netdev->perm_addr, ndev->perm_addr) || + ether_addr_equal(vf_netdev->dev_addr, ndev->perm_addr)) return ndev; - } } netdev_notice(vf_netdev, @@ -2332,6 +2331,19 @@ static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev) return NULL; } +static int netvsc_prepare_slave(struct net_device *vf_netdev) +{ + struct net_device *ndev; + + ndev = get_netvsc_byslot(vf_netdev); + if (!ndev) + return NOTIFY_DONE; + + /* set slave flag before open to prevent IPv6 addrconf */ + vf_netdev->flags |= IFF_SLAVE; + return NOTIFY_DONE; +} + static int netvsc_register_vf(struct net_device *vf_netdev) { struct net_device_context *net_device_ctx; @@ -2758,6 +2770,8 @@ static int netvsc_netdev_event(struct notifier_block *this, return NOTIFY_DONE; switch (event) { + case NETDEV_POST_INIT: + return netvsc_prepare_slave(event_dev); case NETDEV_REGISTER: return netvsc_register_vf(event_dev); case NETDEV_UNREGISTER: