From patchwork Wed Oct 25 22:50:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: longli@linuxonhyperv.com X-Patchwork-Id: 158323 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp287180vqb; Wed, 25 Oct 2023 15:51:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHIuoT6I+vlrAoqJggSIKUfGNN+4Yulhk26G1Q0zOBf7F4h3WEJCeYlGpdmjgqattbOKglU X-Received: by 2002:a67:e101:0:b0:452:d9d4:a056 with SMTP id d1-20020a67e101000000b00452d9d4a056mr15111712vsl.26.1698274279656; Wed, 25 Oct 2023 15:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698274279; cv=none; d=google.com; s=arc-20160816; b=DI857O2F7PBOV2V9IvLXD4ZXQXo5/dczE+jrNaH1HocpzU1s1WO+sdaFpDgqOwA3rG dEg612IlW3H8idez9T6W9ky5f6TTeCw6Y/q2F/3BxNP35pyAtUywOghsf5eIDIDpwExG d6oK0K66oSeBKq51xI2F0lVIEtlHlOmBYlNjOOhhPQwxsB0KyQmgtKrkZQ9PXWEb//bR Dp32yY2efywfV0pfKAQq1XgzclA9PMuLJI726oTiANkE0KZaXUFF7vcRkETpt0jo2vsm 2JLREA5ADj5KReWT7WZPawEQNv0nH+enV4SLr9mLivmiz/G2EgJsR259lCZNpJRM3+xc xbwg== 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 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id f206-20020a256ad7000000b00da07d45441dsi2599856ybc.603.2023.10.25.15.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 15:51:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; 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 23.128.96.36 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 0B9C18136BC6; Wed, 25 Oct 2023 15:51:17 -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 S229983AbjJYWu6 (ORCPT + 25 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:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780769651157138088 X-GMAIL-MSGID: 1780769651157138088 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: