From patchwork Fri Nov 10 14:38:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haiyang Zhang X-Patchwork-Id: 13452457 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 D11A31BDDD; Fri, 10 Nov 2023 14:39:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=microsoft.com header.i=@microsoft.com header.b="LLvhFbRy" Received: from BN3PR00CU001.outbound.protection.outlook.com (mail-eastus2azon11020002.outbound.protection.outlook.com [52.101.56.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D31873975E; Fri, 10 Nov 2023 06:39:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iaR1d/k18CYtw7/fzuk6Zi1Y+t4bOuqikXHo77aRlck437lXtOCTyk6G8CdUz70esR+mjagV3IU0qGC9aCsJ7IgCXVW/fZK/RADzBat52HaBvOnposHUDYZnoUs33P6gmjwylPxp1YsT5hE+QcrlHYWnc2fZY5OZPgImXsX/6121QKZ9VVQTW2sN2JLLNRRC/9XJgwJ3lDOw5y6ldN1hZxqfYmiuZN2KJTGTCLhl0Cz/hl+p1CBLghu+m52EwrtVIzjdM4QwbGnQAf6CR0GJ2xZMmbVEpTQvTi5v1A4U4e8MmGvtTEW4DHx0leT6broR9cpJYzUQuYl/VVGXvDGWHQ== 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=Xe++ibFiuQQjO/itnQrjqTAOEXIHZT5Eg//BH+X0DzY=; b=G2uerAFzQ7baH335lYj92cZdbbmazvbniV5eXzvZW/C05vPWpJ0ShVmzPKLvvC09QtjdmNsUb7t6H5VeJNu4k4CrSHGT6YyzqVZeoX0nvKHuo+IT+5P4ld2JgUT2jpDmvARBtwaKIyAyq+sxlLH/4oxtftmSRMJe7KDWsvewB+dlpy25nNq2wYex5Zao6x+ibqBbRlhQPazEvwvAsG+ogz5zXR/D8c5+FY9zYQKFg+zeIrt9NxHmwPQl/v5Dd/VptcIk0MqQTv/WQHRDufRorAnXxo5zI/cqwKuz61zB0nFEsDegnj7iyD6TIhvdHB2OG4LVo3bemK+lqg9o1O6sGQ== 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=Xe++ibFiuQQjO/itnQrjqTAOEXIHZT5Eg//BH+X0DzY=; b=LLvhFbRyC99Va82NcJjLQLc4OSEvaI52QSt6QB+P2ZQfSIvIy0OywmBNzyLm73M+BktX9/R6eLR0W2A3e+enW6G7m6VTGYZ0U57V1KqkcRHX0Y01p0X9F6PEIS/L04d5Zw2Vwy0SktjEcNT79L3bPfNrk5pZ5LAXy4v14Aw+mA0= 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:26 +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:26 +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, stable@vger.kernel.org Subject: [PATCH net,v4, 1/3] hv_netvsc: fix race of netvsc and VF register_netdevice Date: Fri, 10 Nov 2023 06:38:58 -0800 Message-Id: <1699627140-28003-2-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: cc3a8098-358f-4815-f2ac-08dbe1fad6f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gM9Lv75ycNlE0AHGA+NP026F6XO0F2Vmkl6BbFDutYT2PThfHE5los3GRF+cNFZySHV6BYvrD7dIZnesvG7q9p0x2paSm9w8mWyCaMz+4FKxgOVs0q9+lIngedsm7xTenl1fxD3hHi5xcV3Y0+x4Al1lZQaT78WDRuGlB5b5t9ZVQ82jI0YX0nSjLeMomfDicobjuEjybhw21xw4/oOP03QprtHeaSCOxDHZIjjvKZjZ1Bhsz+3HsnyFFU+llX5FUKnWzChzjZSF0PgFs2mzffy3xTf5c4ZLKe7EbtSg9AvmISzyeYtCaCeOKhAg0KbvTz36UOJ9hjPez+3XO7HO74GYOelXPva8Tu2/Z/Gs2GJ8VqJuvJbuKitVYCF+5wmCNoUYNIFLiZFiUDFGTDvy08S+19PInhCW/NYTi1QjfoCuxfZq5STArGbhcMxlE+3VOqF9ztfD1d8J8DEAoq/RI6LLSNgUqgOcMf/DMSAOM3ifT0orH0DplytCZVheFycY6C+lMnnN09cIbZRolVWE8IBZFPI8BpeJe4xvrl7nvyk12e3SeHXAh48sPLGmlg1oPxA1Y3L2cr8t9Hc/iCt4borW+hDED2G0JLoJLedrluEelGrAtoqlmHJn+20y3HJP6pxylbTQ5bdmSeXA6nAwL78VLfcWzIqob2HSBfSCjaQ= 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)(66899024)(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: yu2nayHS3qLZuatBNP8jAb7Q1gFLrZz1Gwz4JjsD5QBB0JNMvp4a2R7pgh0Py6WPzpwcNIMIn46IRpylg6gje8xgQtZW7q4VQjc8mIfiTDsFDHEoCd7Q6SbjKwRdYbp7vVXKxFAXashygBe7I3EGArA0HZEUayNsRxSiC2yyOY1dRv1PC3JTgRsMSyAm7b5/mf3oMvZaHg8M+5DidCuAwk3bFSvqokxg+nBg5GCnLNxGscqoXY5qeZJob2dKkdaJJCauzc/ETsATyTHr0Rkm3odxaWY9GyHgQQnf1rc8cq0x+Fb72rl+jmMFC/DD6x9YCbmcPUT2AldmfDpyx7S77q34vyD9wgxkzcBUUb6rusduItXbxJ4ppFE30DIk12BB3EIkoCVHSIszREjPvm8P3D+163pAdQA4iECE2rIcYANnSMGWVudPFYQJQ/cELP6RCsfZlPUib1evDmzDfjY3veqrLSHPE8t3QFq1dnLJPboLgSH+MIcjfkdy4K5Zp2yXKYlQICDSqVKCi7xa5TX3uRTcbOpVQK1A3qsoINrtYsZSwGQEBJV1j5tPJ5/BgwVtqFNoa/2h2v/SQ9ClJwbzj+Tjrxd9sIgo6VlA9gRZjckxWU1tfmTmRZSlLG7gKFZgf7GQz8033L+Jrt1LCEwrJ6q5oNAD629N7ATZUH3J+YtkzUtj1PVprQef3EZeKIBKlMBF4+f41zzWv4J5+27AATIPuDqZ3CjAksBbv5DBR7NF+b7vnnLFie12osYMBZmdZOMHugWF8Q4HCnV6k7OWmZj/AtBRGNXC7wnZXmShfUqUwZVEal/Yq0o8YQ1+uAZiSU+JlXPyyZRKVkZiLQhExwuiTEfj7Ug01SnwLlQqz30xNSZ6RsOVmAeL5gcbK6a42qTelOElkoz0GSiT7Q+oi2E4KWRTSwwM/58UbXOtUNrGheVJU7i1QXEGh0ZbcqZASKhgvJ9DsmuXFV7a+HhVwN9lm/VsA5zPV6EPNHHmpfG7mct78mXTyAKC++Y0EnKnjSEZBPb7QNdEDFdSYNgN1H6jjIPbonwfwS81o1DYScsZ29PFRC2XOXi+E4st5LHsYq8cWxuTfWvfdqRPT29/ZAsBD54ely3l3tpYgZzCKsNxkPuvRFp2GtSKoDItlQ0+Hy31GnoQeejzRyFs88Ijz0CklC3GpZ3i/NgH+/PMD/eNquOdOHpCLRVTKKQ2z01Quo0UHa/Y3smhjX/6kzxPfWBzlY0OZ5dZjbziaigwuzeiF5eFdeZ9SGbWzcNhDi09fghiCeqWhh67vHgjNkbDx3m56ou1n2QEM0ks5xUREjv5uzQgMull7nD2/fKKHKNwCgFflaJCyI6eP/ynpd96C1UYjD18ivQr1/9kWSbyQaa+6HebRHUJL6VfjEsu0eL9lgASbfImj833mtJ5bOkEan8zbnJ5hNcoHd6ds6x3yZAu39Yc2XJQdFl/0W/+WepAxW4qnglXQOpIj2EH1Vc4damG7R7XveVZ9BzJ1/HyNyiq0jiv7GGx/QtxfMjBcNkj+Ogg/y2XkWpyvPmNGpgTPwGhArKGomhucuxKJt+7WtWW4Qh28DeUhjKNwHg2xImj X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc3a8098-358f-4815-f2ac-08dbe1fad6f2 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:26.8487 (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: UpFkPYvzkwMQ1N6iSAzibbClMWa+3TgOwDGczEhxBZ6Pr1JYoRJwdLpbQNHi2Ov43FDO+X7bTui/lD1CXpMm6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1348 X-Patchwork-Delegate: kuba@kernel.org The rtnl lock also needs to be held before rndis_filter_device_add() which advertises nvsp_2_vsc_capability / sriov bit, and triggers VF NIC offering and registering. If VF NIC finished register_netdev() earlier it may cause name based config failure. To fix this issue, move the call to rtnl_lock() before rndis_filter_device_add(), so VF will be registered later than netvsc / synthetic NIC, and gets a name numbered (ethX) after netvsc. Cc: stable@vger.kernel.org Fixes: e04e7a7bbd4b ("hv_netvsc: Fix a deadlock by getting rtnl lock earlier in netvsc_probe()") Reported-by: Dexuan Cui Signed-off-by: Haiyang Zhang Reviewed-by: Wojciech Drewek Reviewed-by: Simon Horman Reviewed-by: Dexuan Cui --- v3: Divide it into two patches, suggested by Jakub Kicinski. v2: Fix rtnl_unlock() in error handling as found by Wojciech Drewek. --- drivers/net/hyperv/netvsc_drv.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index 3ba3c8fb28a5..5e528a76f5f5 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -2531,15 +2531,6 @@ static int netvsc_probe(struct hv_device *dev, goto devinfo_failed; } - nvdev = rndis_filter_device_add(dev, device_info); - if (IS_ERR(nvdev)) { - ret = PTR_ERR(nvdev); - netdev_err(net, "unable to add netvsc device (ret %d)\n", ret); - goto rndis_failed; - } - - eth_hw_addr_set(net, device_info->mac_adr); - /* We must get rtnl lock before scheduling nvdev->subchan_work, * otherwise netvsc_subchan_work() can get rtnl lock first and wait * all subchannels to show up, but that may not happen because @@ -2547,9 +2538,23 @@ static int netvsc_probe(struct hv_device *dev, * -> ... -> device_add() -> ... -> __device_attach() can't get * the device lock, so all the subchannels can't be processed -- * finally netvsc_subchan_work() hangs forever. + * + * The rtnl lock also needs to be held before rndis_filter_device_add() + * which advertises nvsp_2_vsc_capability / sriov bit, and triggers + * VF NIC offering and registering. If VF NIC finished register_netdev() + * earlier it may cause name based config failure. */ rtnl_lock(); + nvdev = rndis_filter_device_add(dev, device_info); + if (IS_ERR(nvdev)) { + ret = PTR_ERR(nvdev); + netdev_err(net, "unable to add netvsc device (ret %d)\n", ret); + goto rndis_failed; + } + + eth_hw_addr_set(net, device_info->mac_adr); + if (nvdev->num_chn > 1) schedule_work(&nvdev->subchan_work); @@ -2586,9 +2591,9 @@ static int netvsc_probe(struct hv_device *dev, return 0; register_failed: - rtnl_unlock(); rndis_filter_device_remove(dev, nvdev); rndis_failed: + rtnl_unlock(); netvsc_devinfo_put(device_info); devinfo_failed: free_percpu(net_device_ctx->vf_stats); From patchwork Fri Nov 10 14:38:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haiyang Zhang X-Patchwork-Id: 13452458 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 453711B277; Fri, 10 Nov 2023 14:39:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=microsoft.com header.i=@microsoft.com header.b="Nzq++K5Y" Received: from BN3PR00CU001.outbound.protection.outlook.com (mail-eastus2azon11020002.outbound.protection.outlook.com [52.101.56.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EA8A3975F; Fri, 10 Nov 2023 06:39:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QwO+lHJ3PylyOuc7ihJWzMVunuFFNAjsqA38/lmVBmo9I0jrm60vZsdiMXVnDyrCJud1uhQJgKfGbQr5zv6GKLZ7FdieDjejoATLDjGHLaRseGRBM2uPukF0AJfKf4czBXP/ILQwklJFDxVDI5jB4JcWopjvai2wfFBNXzghHTTfLE4WvqvX3ee6Szh1arfrHZjE4P1olSKcQq4I18seydo3KZvDzxq4k9e0NVzBwDqnnZhoLlO0kePvaNI9VLJM//f2fIZcC9mIcnngeMkWjL8q2NA2MhzUU/SQjoCF0aJ9cj2tpUXrJhKyHpd8p9yF45IMI9LST352Jfgsf3cpow== 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=MZ/Z+wZqXzBp0DmrZmn2klOzTh3oa47/EOBDXfmzt1Y=; b=EOB7v76JV3y/Ewb/02Mp6dCz/6gjTA1YZ+Eij4kpIMKjvPNh+LAF08vEiTxy84cnQaWwtJiaWQbeFVMg8XEgGF9QqCsJD7sj03sIuWIygnZs57WF/Wt84T7rZSAFIc9QdPc6nypBZVxRHiEo3HD2E9ej6kCzEbR1JmnUVr5IP5qTHV+Rky+vOw0Up9bHopVDeShHeXR351RrM3SGUzyqm6LViRS55nPr7/v3Y8rqgobEzE5rAG2ob9kdTFJ8jwisbd+1xLK/G536SHAbFfL4oyOAWaKYce7qxEU5WJKsiihBPbX2tQiL7BcjxDo/0j8l1b4zwYeFsUm0DHrzHAZL4A== 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=MZ/Z+wZqXzBp0DmrZmn2klOzTh3oa47/EOBDXfmzt1Y=; b=Nzq++K5Y2YmvEjsyKzZxDbKzgMedypRPx8avkomGqEoddKc+mii50qABq8lRUtmdYP/9f73jEOoVg5PJy7zt1uuE6cQ8tUX9AIClFryrHnWi6qWD3h9YTz4NG803/OTqc0SuLqFbIRYTVQ72TIU/8ynRXieKfNDhEqObzjL3Y80= 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:29 +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:29 +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, stable@vger.kernel.org Subject: [PATCH net,v4, 2/3] hv_netvsc: Fix race of register_netdevice_notifier and VF register Date: Fri, 10 Nov 2023 06:38:59 -0800 Message-Id: <1699627140-28003-3-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: 6f2ba22a-8a5e-478e-1943-08dbe1fad8b8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IpbeJD3bZWjKPjdgeh91nOV6PqF3nXp4P4WzSLK9u7PmB4T/x1JbikSYV9grIMLQ9Hu6K76Oi/8hD5C0CDwzmIC8aH4cOvOfELXq3xxFM1JA1NaxlDJ3PFMYM/ll2C6nlvn2VnhwvOVRBvkGPE3xXzUATLH7dVaYe8tQYeyfNkbb9DxCRy/G3qZUz3BoqkPfJSZh3VlXQAeWkZzOOuOQRwrB9t6TR46aPpMVGbuYEqh0oozWftniG/R2xGlrTWb0z2rbKIe//1+n8PuvBXclag+DzRuH4p20ZB+2ks7ZahwAQE4MNRkyhWO9WOKjcm5mCqwl6v4zslENMes6HnR9+ApL5DMoP2FLr21jswjA1wV62KknqBPyHCe+7boYKh3Jf6O+oo5NqRw43QPWGkg5Ooo/Ej/LionO/gx6M3j4y0Lki8dRhJwszjNc6JFnWOMYoQ3bLOflK60jyLy28b/5f+TYJ8q5EkLFUCmCEt2Zd3kGO69Qv7kH5kOXgDUkL00m3UeUGr8CYNAWe9MQ9fnXu5kTqhIWpuMWPUYhuCqalf4W62q4meZj54ZeJHFC/z3QEmEjEaB+Ec+ZcIUWmJEcDh+6QOoR7x4qs7Hi55KwNVbgExm7LYhK/3Dy5UVPqjbyCoFjIJBgwpvHs4+Y4Vwa7JPV2fF2jUlBVotVhM+2e70= 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: E9uTL8kewewVCYNtuSL4H5rIqxKjJZ+dr9pn/aGQ0Ma+ZnAMIkjQ61Ws6EEdhXTAJazAS15K3RtMw2MDsMJBmXcvlP6iJxASHKvhdUg6nUy0TvGBxJm+YGqthhw6br9FK70icWSdvY8xvjYvRrou4oNFKD3KVnGMFCvhTLltPcvZHXG/avmcuhh1QLmVS8soM1CdnOrKmWlDm7JV4n0Bf/b4+ndzvnKFSoXum7N0q/dNQDkdvRyZ5fmKtkaPCI9kbVmGW/WHCBipmSTVF3TjwQH9fxhm2SU1embW/gJ1TbsnmcsMqcuh02HCDl0uYRkvhSV5Yuz918VIElVt8lm0z15YvbKToTevhR51zAHe7yrBfLxASL+u7wdYU3M1IF7FQQKnO6dYoW8wozPQ+QxIgk/3n8zmmvD1Zqz2lXYoVg4ZOpjSeTS77Vxg+KHxQyE159Ln54www7KHO+pPgywd721JWAzuOYyudD9cDbJqK6T7/vPqpLD1LImbQ5kMmV7JINWdAVl47tyrag2dDUvCZ3iWaGy6B+x0xGqFt1HWJWPm6hC70OyGff/TzYK7ij9cEyEx6QcuJUsXzJbsbvmnnpCtTgFyj5rd9vAAewQC1mMyeXBDLAOLJNRWzPTW0l6yVyEy9tX7ysFD3CHLJs1mJzYrE53HoO0Ntx1+g6nd+wGvpzmRGYzjLuvHLIqLlnNbP1e7pKC/Z7LUPIWS49z8xUfb8gKGAcDd72Ekucglz4IdfxpMr58UvTaAB/UQRmqFUzJGrzLDCKuL5zeGZHhNDhA8tn1ea+i9EmX77E420rfNu2Drs16nQGo70JDF7GZaJmVabORSwcrQ93ZWoU9tcb/EntOP30J9Z34+LV48bXL+LGF/kekuzo7frnb0frI896sH/2+K/Z1SPX+JxI0PqWHzUUNCwFbN+or2N+bhmEwUrt2U4Y4JTIMNrwIoeq0x2E/yHovaYkGVL9QY/TWrrCtNnfwIQLZhKANL1zpicf/uYlTfKbSJVGLRsRCTbKjDL5JTq+fi76KgaKLne/S0Zj0puzbOmyxCtsu9ORpH6oZqQi9OSIPdaK4NN83SsD8smHn6hlm0SXjqBAgxD1n908THOFNh5td4F9sY9GMte4FQp+lcfFxrdcpiOAoY/HbVdyfeaI5p13ZL4xr4QDQ7uZXR/7jP4eQomXQHzrYc7yrN9F8YKdza5CtyLWHLvEtfY5vIoBbCPQW345uwgBkPnVa6SnBGegqSlfr1Sfb7nrAEDi7RBvMv5qkQt77YoI4LPb067ZiCFtXVi6l0NgTpwdCAHXjsf1PJc6chU9AnZWmEVXh0teg7UQCDEHe+hkl2B7+fQUFAosC8M64KBLHtZ4R16UuWGm+V4UuLflQhtftIppv8O2hLTgFImi5qnNgM74ASFKfMj1MKhUeytq9Dx5iwWpTgBlfP1jgaqBc0m8uKDyl+Y+aPENzK6dSOMVKbvAIm+1C/AzITQbdH0983dohIdjfYjKxVTqKQkcVdQW1OgDKA4MoaJGsKm1fW+4hKTeigDJnF9wIlFtn2E1RfsWv/rgc9ZS7+v2OQ/Y7Dm8IjLvjyA7eDFDHWYLEedpfA X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f2ba22a-8a5e-478e-1943-08dbe1fad8b8 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:29.8239 (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: tQyXCxpPKyTASCGI1NMSKqSmRpXN5f19NIVwxUkv+eruTLN5Qt5AOu8dJSbL0lEtkJ9J7TnLaBKkwwU46Kj13w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1348 X-Patchwork-Delegate: kuba@kernel.org If VF NIC is registered earlier, NETDEV_REGISTER event is replayed, but NETDEV_POST_INIT is not. Move register_netdevice_notifier() earlier, so the call back function is set before probing. Cc: stable@vger.kernel.org Fixes: e04e7a7bbd4b ("hv_netvsc: Fix a deadlock by getting rtnl lock earlier in netvsc_probe()") Reported-by: Dexuan Cui Signed-off-by: Haiyang Zhang Reviewed-by: Wojciech Drewek Reviewed-by: Dexuan Cui --- v3: Divide it into two patches, suggested by Jakub Kicinski. v2: Fix rtnl_unlock() in error handling as found by Wojciech Drewek. --- drivers/net/hyperv/netvsc_drv.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index 5e528a76f5f5..1d1491da303b 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -2793,11 +2793,14 @@ static int __init netvsc_drv_init(void) } netvsc_ring_bytes = ring_size * PAGE_SIZE; + register_netdevice_notifier(&netvsc_netdev_notifier); + ret = vmbus_driver_register(&netvsc_drv); - if (ret) + if (ret) { + unregister_netdevice_notifier(&netvsc_netdev_notifier); return ret; + } - register_netdevice_notifier(&netvsc_netdev_notifier); return 0; } 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/mMIP8Pj8j0n9gkhd2Sx70lQO/SkZjNJ519112iBNXDIH7RAcJG7rQsnifuKWdegVrJXd1RdUWznklUs2AU61hmUx+GQH6BE026UWq4sbvw7qpAnzkkJxXuyr6T0XkdUyN/A5FkfvL1bCCY/w2AsqtQIdpk+desjw70FCMwJ5fI7K3LoAc8GlBBHIJ2drD3AwYPdWrNK2jGYPBKHkW5B+H4cwKdttueFd5kmSCAADHX5aTVJgOOlSMuhajxvyY9y/QefEfrolpDlIFDbnlDQq0EI1wJwrcnJARi/WcHckKZHZtKmBmqyHqfDpIUZD6p/nvLre0BNMtM6PSa4kWAH6ytrOJRlPJ1HHfW7+KZcr5YlE26WvEjDtUgOGTrCzLBEER9/CMLjLuilCLBqN2FrjQD5nL6i5ZRrNOZEwZSI5dIwabYG30k7hY8bBFPOdgQ2LMGWV6LDMS/cJ7H02rR5VH7WoDDixkPu5ltiz2iaCxLAJqQ6EVd0OiYiMcWy9wbTRUlKAQC5dLpAelg/yeoIydJ6NFbhJBISX63r3d4MRhYRnbvhWydKcxLf2vqVzEjoPESgn7UIYQccGxqD/WtXfgXadWcoBGwPFTAvewyuniGHFTdzRfswkTwzflDYaj7Wag85jq9h/g4vxoYmUQd3/U3RaaI1NjYk5St0ilGPa83pcEvxz2/YnW0h1Gg5AHfWZPlINO7YAvp02DF8xXTe2PVg29ucZqCPpUcfVY4ap1A36Sr6BZPmQRYsYwULJ6JcRAz9VcqraVV2B9o0g/Q07SF/xma/cLsi4yRcamw8rgiwuitq04kmyAzOvt459I9dwfViOFpWEwDZAI4E7uqAzCRRz5avDFZl9YMKuKMaQRyhkyVj+X9z9ttU/JP0cUiwLNG/5iusEFJBeTpJWxc/hdNrQTaReWJppCvhnTBiyi5X1kLj6ukNborK5WiERVW8IpQcXgTmXixLX9ZEydf0gml77vWXYqI3a/MAURdXFSWsSKlZ4ENP3VSx1WdsSHfiwS6llEKe1I8gmqACPMeVwesq5uFHkU681wcEdr62V6E//zYljSge5d3LfUylphcU2k8PRRFIHvb/O9Q0RvlJBBqWL6uVystNzLY9ZOEfCULiSEzxJsWBIvbWFuat67Rpsts5ToZHOC73cIkqQ8SgbUhOacNhixiXlvGTZAfUhPO1o2XJYPeZWzAWU5DSDUAzf29Jf/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: