Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1740959rdb; Sun, 19 Nov 2023 08:25:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBoCdgwJaU6PMMnOQb7/XFgJFGW+JAq2razukeTsJ8t2mEaceBh0eNKVkeQ6UDIBIpagV9 X-Received: by 2002:a17:90b:3e85:b0:283:2652:3d20 with SMTP id rj5-20020a17090b3e8500b0028326523d20mr7284802pjb.9.1700411103062; Sun, 19 Nov 2023 08:25:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700411103; cv=pass; d=google.com; s=arc-20160816; b=hx8jumxDDM9tcRke90Vnyfhuu8QIpa4HgYhBBXzV8iAJBe7tODPHhhuxwvKRKiX2JC gmw+UGIzaAa+oR5ODQbt/BPiJfB9hN6tJQPdG6IW20sC3ZN1exVJP+JUebwqd1Dl3QdE VBTxRE6V2/GKBCUZcSCZ06pkN4QLzGc70y/hjJMeeMXnvslEZPiBo9kQ2V7Qu25+39Ic LO+uJTKj0ytqiwjHtYC9+HwKxwpr3U/fmgYUbXtT5nGhvWGlb9eQoydIZFv9PNS3aMdF BBnCHO/uIbzMWLDz8VWAj4eHR0N95mHmJwdKMlix6Ao4WA1qzyY07X82L9Ta3Fu0zTqa 3UKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=H36dzqXp77Rv9GD8GbYy9bgWqPlS9/c9lrb4Eap2q6k=; fh=AdSA+7vedjT7HWihhKRuk4hvcynz+T7ltihogYeRbTU=; b=ITTwyb26E1fSTqGbklL+/u6ysDRACdrw2B2JjmLicmRaHKEQlKscQuiCUc4lYHw6O2 rOIk+kzV3ky+hUJRAECrTpe0AgQLPTK8E6Ous/4tLAVpJHuRsbti2DWTmb1Yz/d9CI1g oM/Y0PZuY1NHNJrezI7BptVjZt3WFC62lDOjEhUz8F1roMFX9JI5QkKsSubuYv1HyfSd ZmWIGmJla9PmVHEQ+BVlrS92u8jNALfp3Dqkms8Qoj6mAGSojyfijhAAiw5gYke+BjvN dDrqnn2Sh/+LnsdM6oWOYWi7NAXqmoGqeI6NordIWbl4zHwHeRkD86E5QbW7KJAUPGZS F6rA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=Ussgyxys; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id j12-20020a17090a318c00b0028024067027si8781638pjb.138.2023.11.19.08.25.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 08:25:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=Ussgyxys; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 7342B8057E72; Sun, 19 Nov 2023 08:25:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231493AbjKSQYu (ORCPT + 99 others); Sun, 19 Nov 2023 11:24:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231449AbjKSQYq (ORCPT ); Sun, 19 Nov 2023 11:24:46 -0500 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-centralusazon11020003.outbound.protection.outlook.com [52.101.61.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 969B3D65; Sun, 19 Nov 2023 08:24:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CftCayIFtNMVWheRGIsF/GEXCR0NbSOBu1imJF2U5RAzxPmqguGMRbObyU5UzUhUGiO193NQFhCssv2rN9hqgARc7MMMUdA8Ey+II7Ld2Tq+yDcAk+Ha6O39knA5/p3K0xD8DAHD/Otom0NLdvH3L5se7unR7Dq4gKlvhy0Yqioo93HGU80oeBTRe7R20d2hazBIUjn/F2HBB2jBA/Ez8JX7LarYu6VCxU59csc0fVfAE6fmGakpq75Px9Qh3iHqGPUWWK9hbd92vpqwKIfd07OI+CMqA5uCXr15qUD9F/0//pcjX05RNIJfL5Pf3Q2XQSsvh7URNX6R2Zae/lrvNQ== 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=H36dzqXp77Rv9GD8GbYy9bgWqPlS9/c9lrb4Eap2q6k=; b=Os3dcVhUfV8Lz3CLM8QMpsLkAzS2vWd4ToRt2j99/NBhnqaKQ1Axhij19qE/vdOz/b2Gpkzfcpe/tHGRTzSUWiaJ/32fs1HohY1o9XHNwIJZTAtFYbaCAgqZ4a3toIUiDozuhYQ/7rBZ082o3y+0XqBVt2Q3dfnSLsxHKvD9gLLICaZ4v1brasmnjTdwp6FiSkvOIVzoMKOBIEXSJ5bmhIvw6NZhOAXEI1Y5+PpieVRiPnC3MI40WiUn/3PRebFU8QJK7t27d3a8Q0tV4s3ldbefR+94Xna8R3yV9irr7X0yMIHBbcxE/Eu5GCcH3yqLcdtT0rO4XuI7n5rUoS0FJA== 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=H36dzqXp77Rv9GD8GbYy9bgWqPlS9/c9lrb4Eap2q6k=; b=UssgyxysRV2r0DB5n2/Vn4MHtZtqCmv4AtsUlGC9eYs+vqUk3Obs+qVIQ1c4npKS3UoZRBkajPR15MngKohKRFR8UAJBUnPSavlpfroXEYFS1uWJMwlxF+R+xcGEtUeF/Lci5mvkdDrmw8Ir7nLIIuFaZgDeVNbQhzsU479znko= 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 BY1PR21MB3893.namprd21.prod.outlook.com (2603:10b6:a03:52d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.8; Sun, 19 Nov 2023 16:24:38 +0000 Received: from BY5PR21MB1443.namprd21.prod.outlook.com ([fe80::d819:9f58:df81:2d20]) by BY5PR21MB1443.namprd21.prod.outlook.com ([fe80::d819:9f58:df81:2d20%3]) with mapi id 15.20.7046.004; Sun, 19 Nov 2023 16:24:38 +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, stephen@networkplumber.org, davem@davemloft.net, linux-kernel@vger.kernel.org, Long Li , stable@vger.kernel.org Subject: [PATCH net,v5, 3/3] hv_netvsc: Mark VF as slave before exposing it to user-mode Date: Sun, 19 Nov 2023 08:23:43 -0800 Message-Id: <1700411023-14317-4-git-send-email-haiyangz@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1700411023-14317-1-git-send-email-haiyangz@microsoft.com> References: <1700411023-14317-1-git-send-email-haiyangz@microsoft.com> Content-Type: text/plain X-ClientProxiedBy: MW4PR03CA0197.namprd03.prod.outlook.com (2603:10b6:303:b8::22) To BY5PR21MB1443.namprd21.prod.outlook.com (2603:10b6:a03:21f::18) MIME-Version: 1.0 Sender: LKML haiyangz X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR21MB1443:EE_|BY1PR21MB3893:EE_ X-MS-Office365-Filtering-Correlation-Id: 052a199d-fd64-4268-ba8f-08dbe91c06d6 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wn6dZBPPh+Ya/TKmAfr7XArVCTZkPLf6dGK1uQKUZ/SnzUd48C2NrYCzKqytMhfrgXV8WEdawigX9SUFuIllAYjRsI2hWV7hyQd35K/KGi3SYUM6fju4lG63JYPdgLnLgf1vzRSPKGKIIpOEupf081wwUkutCLGp2k/NcOFxhapD9kpI++TQJOt6+gBreDviRt/ECWk3NtzDv7kDCrQXMOG7q2zShmYEz0bvgcm98COegvIQLaULUgVuoVGyBd+oFnW2NpJreNvd2UxqAxj0ngub5yd7KE10bM9NCKAWmXGEReYzhYDgmDfOgQauH5IZkdX9LDVS9aRZc6GVGh0dm/nEUzEvfFYdyn7f3HAOaCBb/Ib5Y4AmOG5JAsCoIwn7hfM/TBXR0stzhT4vYmjao7s4U3jyOUlG2iE0wW72lMNzAMXACRf7JtGHW1G03wXRAew3qRdQJhGM35IRqRi+74zAdTE2FUkWMxKKJJQ75SXRgJ7IcMdf7zUg4IzFXP1t+MErdZ9Cw9EIzmJgQaM2lzGc8mvyTXWJohbtylnrOKIyqymTyX2k80v2SE8/1jR8Y0hMYLaZ6V9T+KYeBEor8EVWRUS3hmvx2lQGA/vDkI3qp3I3dgOWtFFwl5TK73GYkGtgQsNz1Ap9KftyqTQyozGySeuap+OfUxlfrpDK4nY= 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)(39860400002)(136003)(346002)(376002)(366004)(396003)(230922051799003)(186009)(1800799012)(451199024)(64100799003)(82960400001)(82950400001)(38100700002)(36756003)(38350700005)(6512007)(7846003)(6506007)(6666004)(52116002)(478600001)(2616005)(6486002)(10290500003)(8936002)(66946007)(66556008)(66476007)(5660300002)(316002)(8676002)(7416002)(26005)(4326008)(83380400001)(41300700001)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?z4XhEWS3AkrtFeiDSR/rWX+tJNwiVrFaNy4Hh2iHoY6nmPyVTJ5vV91EdlLJ?= =?us-ascii?Q?KVVYtkkNhlDZ+erR8aicW12G0+R45PqYixmvKpdd4pLgKk94LEfk7yIGDSwd?= =?us-ascii?Q?QUi5pUsawDmQ1rAj+WcAelQxw35A25ubxptR2XCbM4nuyg9ZDEv5XMJWL3Ls?= =?us-ascii?Q?Epnfdb2AcYI2pi96GbRs76UE9/+wmH5jDN9bD/IO9zfttnGIsr/OxWCJBr5L?= =?us-ascii?Q?Y3pqf9M+5bmeMO1VR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ctbXfz?= =?us-ascii?Q?I8yzi8puE81oyf9lQ2AJlLSQSP/zOGYYyRjcLBNeQMaClWRtOLA3I3KOLL9r?= =?us-ascii?Q?nmwGMBhC7ISzP7ndUGzz5v9tlTOZou6r5tQ47y0q+Yi85iAr70Bm8HWLrDlU?= =?us-ascii?Q?1QaRUZWfZ/vBSeoo7cGhWZkp4Eld24mNhrYry/OcleC+vwJkOiWSfycjfAFz?= =?us-ascii?Q?f1e0HUDdePMNV6LKwvrh51LX1lTVnypqefeEpAny2QS/AOp2vtngRfmjtI2i?= =?us-ascii?Q?Xv237S1gI3nyQdUbrD+AnZ/jspLkLRUCYrCfSw8s20loYVcDLHoI1MyLIQU3?= =?us-ascii?Q?QZfdV/Gn1FP3vaEhWii9hfeL0r1ci4Ayn5XQ3CeqC6yE4oqddvVOW39Psf+S?= =?us-ascii?Q?zNu1rrXbionwxI/wT7yupmJEaNhh1CG8KecC/jDdsfoV52lt/PMyg7SvcJry?= =?us-ascii?Q?MJwi2ms7yXQcglwWQuDHjGuxAWWEXoOAoiaGYfUT?= X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 052a199d-fd64-4268-ba8f-08dbe91c06d6 X-MS-Exchange-CrossTenant-AuthSource: BY5PR21MB1443.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2023 16:24:38.7226 (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: 42R7m6rlyAlBs2jBIrV4Ie3AcfjTOpEqnZ/naK1dhePvnOP32DL5+Z392+TYRj8S6qmVz3dVrC5quW/CHJnpbw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR21MB3893 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 19 Nov 2023 08:25:00 -0800 (PST) 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 --- v5: Change function name netvsc_prepare_slave() to netvsc_prepare_bonding(). 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 b7dfd51f09e6..706ea5263e87 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_bonding(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_bonding(event_dev); case NETDEV_REGISTER: return netvsc_register_vf(event_dev); case NETDEV_UNREGISTER: -- 2.34.1