Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp48520rdh; Wed, 25 Oct 2023 15:51:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2e9lEli8w/1N7S+N10jFqHFUKh52XOV6yC6+wg6qV03hYYFwCrwJbULRHWe+uoMvFK2X9 X-Received: by 2002:a05:6808:144b:b0:3b2:e520:dfab with SMTP id x11-20020a056808144b00b003b2e520dfabmr19811490oiv.44.1698274270025; Wed, 25 Oct 2023 15:51:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698274269; cv=none; d=google.com; s=arc-20160816; b=Xz1ApjlMpTg2c0GYQ7w388kXoYAP3J7HOYOpJH162l5lrBXGoo4eV8y2CozZhcL6nk wL17NpC1YDDBhidEZxLGEigUv+9yNKurLkvP+kPCUEAhVQnvNjTlZH42b1GUOoo4Cwf4 fuLOKH8j96xGW1SuPjRASZPAKtepqiDvfRPIsfZbz9xrUkawIqJS1tmESlYadcP7cNpM xiswysA0a7uT/fXx6TqSfzP3MB324mj7Vruc5Z9cIga8Kp3gpgT8IkhKlh9STiSMUHEC XBfmRlEbvVSowoA4F9MXB5JnIN3L4B+EOg6J4N9Yd+QLx4Ridx9eXuYWypW7V+g/wAFs TDFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=4zQSWnZRUjjGv8tDmJQi574JQo3zw9n1/Nch+18x6iQ=; fh=P6TARALwZTF07Q6Vnm94s5bkQKVA62dB3/y3cuHSbmM=; b=YbYwfQZDkEBJaRfSGAOmktOhycNlTOCvCejw9CTFURabo0WHZ/WxDI7GuUGcodPXvl cZAC1IIskhNlDf3Mo0O9Tk/JgY9opsrrVOT5QLJr5xRudEgTNQyGYZ5UWGYO3Yfqu4Ef satGRr5rk5zZbwsRu2dMK7rbV63AQPknzy5BG+bcLmFOT2bXJZtkNJY37cyL+1OctvLC /ybe40IYqPf7+Q1JZDhsdoElelHzixzQui/ZyIbq9UIJWbByY+tvZMFuRkf6H8hEtdYq 6wFqb3tTRidVNZQBbOj8pug2Id9WycoDjr+qt3vvVLaEkobNXPw4jtqxwxYnyGXGzz5X iD0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxonhyperv.com header.s=default header.b="o/+Wfe6u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxonhyperv.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id t2-20020a254602000000b00d85215d6519si10636625yba.595.2023.10.25.15.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 15:51:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxonhyperv.com header.s=default header.b="o/+Wfe6u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxonhyperv.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id DB2C48135BF5; Wed, 25 Oct 2023 15:51:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229877AbjJYWu6 (ORCPT + 99 others); Wed, 25 Oct 2023 18:50:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjJYWu4 (ORCPT ); Wed, 25 Oct 2023 18:50:56 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0BF0DBB; Wed, 25 Oct 2023 15:50:55 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1004) id 9138220B74C1; Wed, 25 Oct 2023 15:50:54 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9138220B74C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxonhyperv.com; s=default; t=1698274254; bh=4zQSWnZRUjjGv8tDmJQi574JQo3zw9n1/Nch+18x6iQ=; h=From:To:Cc:Subject:Date:From; b=o/+Wfe6uwOpezfWcHV78m4CysvZKlOLyu7LWMxmOKjDOAbAn/XtW3q5u0NCsNMV6h 29Ez6cGI5WpUOMosYNV+7FDyvqYPSwDFOILomAMzBHxOJOcgD3lRPHH58muaIFf7Dj eUtxB3DiGe3Qtl2NAYZGuZYTBUCBSAolBZuq5Oqw= From: longli@linuxonhyperv.com To: "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-rdma@vger.kernel.org, Long Li Subject: [PATCH] hv_netvsc: Mark VF as slave before exposing it to user-mode Date: Wed, 25 Oct 2023 15:50:50 -0700 Message-Id: <1698274250-653-1-git-send-email-longli@linuxonhyperv.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Wed, 25 Oct 2023 15:51:07 -0700 (PDT) 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. Signed-off-by: Long Li --- drivers/net/hyperv/netvsc_drv.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index ec77fb9dcf89..045777a4971d 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); @@ -2320,11 +2317,9 @@ static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev) */ 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,7 +2327,7 @@ static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev) return NULL; } -static int netvsc_register_vf(struct net_device *vf_netdev) +static int netvsc_register_vf(struct net_device *vf_netdev, unsigned long event) { struct net_device_context *net_device_ctx; struct netvsc_device *netvsc_dev; @@ -2347,6 +2342,12 @@ static int netvsc_register_vf(struct net_device *vf_netdev) if (!ndev) return NOTIFY_DONE; + if (event == NETDEV_POST_INIT) { + /* set slave flag before open to prevent IPv6 addrconf */ + vf_netdev->flags |= IFF_SLAVE; + return NOTIFY_DONE; + } + net_device_ctx = netdev_priv(ndev); netvsc_dev = rtnl_dereference(net_device_ctx->nvdev); if (!netvsc_dev || rtnl_dereference(net_device_ctx->vf_netdev)) @@ -2753,8 +2754,9 @@ static int netvsc_netdev_event(struct notifier_block *this, return NOTIFY_DONE; switch (event) { + case NETDEV_POST_INIT: case NETDEV_REGISTER: - return netvsc_register_vf(event_dev); + return netvsc_register_vf(event_dev, event); case NETDEV_UNREGISTER: return netvsc_unregister_vf(event_dev); case NETDEV_UP: -- 2.34.1