Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1893280lql; Wed, 13 Mar 2024 11:02:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX6om3+6/AlqwERfkHPmxU5V5XQEUUfroryYy7NbtJrvKpflryCL/MGU/+Aqmeee52xcPW7xVM1En22vmFoAxoiZWfeUC556NZeYvgE0g== X-Google-Smtp-Source: AGHT+IH+3vMivoAkMxusbccEfbzDLSelmEVy5zDSqa+yaMc6UAmptoPooafHd0Jo1PpMdQYlM6cR X-Received: by 2002:a50:cd02:0:b0:567:2a22:6e86 with SMTP id z2-20020a50cd02000000b005672a226e86mr9946889edi.22.1710352978592; Wed, 13 Mar 2024 11:02:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710352978; cv=pass; d=google.com; s=arc-20160816; b=Ws12UfRs/sabwgtquWhGPy2rfaA6sc/9y2on1WdnHfcIfhswgox1+LbUoXVwT6I3F1 p15CGC8x67yt/yGWemIUZxlC4PGFmphnvmawimSTxwQBhg1mc6DMR1Al+aAPFFhOIpSS PFC7McyTiZ6Ib8Z7me2lf4zshBz6AanK80YtK6haTgM+JQSy05Pw1EJqK1MaEtX9ybU0 C1ed0vHNREh+e17tYSqTOyoFhe2pBo3byjZloiYp/B/Bv4zzkwEqiOuYVWII1s2BAJE9 9ozSpfT5n3LFw35jVA8DIkw3RqvT5KVsPt+Wpyky40yS6lXhPnXGcvyBn351rPPnhGal Pz7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uY4yxNPVSz+zpgXTS41E0iBq7Hl/gpbsXoV97tsVmKc=; fh=PYDHYSjaccfTWijtfMSRpqXqBhIeuGpaN1uze8tf0h0=; b=DNZDAreS7CNDwVk4I1V44iILRtZtKn397SO8d422j/yVMwoSDejkvijmqsuf3QqAOO H9+K0kqHUtgIj9zd2sJMlTZDnubFz2VqMY8bbFSmn5juNdyT7vnes3iu/tycZowYX4Pe jql2xzuxjGSe7hAyWFOAXodvKP81LEidwQwBJbNK/N3B+5JzM015PmxIOZHaVoSpV2Uc Xp9jBmVKcPgfzBbR8Z8DFuf0rEsuiEoq6VpRhaiJE8XbMZjC/8wj6MOtb86TwNLI3h/T 6Va/gWP0z71EeaNH7zMRQnvPqwv1m7ctNgk1dzn+UOkBWxhs0iemqQPuI8rH+8q45+mr +aUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K+CkS2TP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-102083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n10-20020a50934a000000b005682c245250si4604328eda.13.2024.03.13.11.02.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 11:02:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K+CkS2TP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-102083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E50131F29B95 for ; Wed, 13 Mar 2024 17:53:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 504381649AD; Wed, 13 Mar 2024 16:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="K+CkS2TP" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 344A0161B54; Wed, 13 Mar 2024 16:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348466; cv=none; b=gO6BW76OzZtOWG4Ld7eU0mBa34p2hQe0MN7E4/Wz/ZAiuLwKpm+k0eduv9I1Ww+WcDH27TNEFoXRGrssHbBEN92FgxSduyv8f+CEuO+1KUSPavYeUTXFlTyJL/x4xnoKz5qIwolbfQ4U5MShybX8FXdBfd5Onskd3/Jbj6BJ1gk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348466; c=relaxed/simple; bh=SO10NYY2rFlZKfrtasX2qxmzBJJJrpWGsfzvhZ2o1io=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZJR5ZfP/TO9TYpq0Y4RvPwy5XfyM92jR8dNvWtLeOLvXoxakbsPJNGjs0dCzwMRPMlfqYpkGYnuukwnMS1VrDP0hEChjIrhdCNwthWMS6kzWJYX1yoGzSCnQyh1EPHhGfqAOvnWzMH9+dc7BoNzUpt298w/MIahDlbxVe5Sxlu0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K+CkS2TP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3D1BC43399; Wed, 13 Mar 2024 16:47:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348466; bh=SO10NYY2rFlZKfrtasX2qxmzBJJJrpWGsfzvhZ2o1io=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K+CkS2TPZ9JPHWgHn5BLP/xPgNprVbd51+vQInnCgLeEj7uP8PhAW66evqV4UjHFD UmV92idviCYxNDS4VJ8g1OnOR52Zj9KKrBtOWdPMTN7OVtIE15huj80VYjRuGWIjtY eAErdLdTeQtGhH/E8mi2hyNyPoUQPVMEtCmMqJsEuwpY5fi2D90gZ57/lBvNovQkFd RLutZhGroWRVhT8S2fAv0qp4aQPQQjW3CirhX1ZPcHQHeBSnLxyOjMUdf85e3h2Lq9 9rutn7gnT8Y7uQ7mdaZ7AJJSgjqpusLBbZoEdGmPjMYG6wicZJgYz1+E+xZQxrlWHJ tHgzgf666I+HQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Shradha Gupta , Dexuan Cui , Haiyang Zhang , "David S . Miller" , Sasha Levin Subject: [PATCH 5.10 57/73] hv_netvsc: Register VF in netvsc_probe if NET_DEVICE_REGISTER missed Date: Wed, 13 Mar 2024 12:46:24 -0400 Message-ID: <20240313164640.616049-58-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313164640.616049-1-sashal@kernel.org> References: <20240313164640.616049-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.213-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.10.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.10.213-rc1 X-KernelTest-Deadline: 2024-03-15T16:46+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Shradha Gupta [ Upstream commit 9cae43da9867412f8bd09aee5c8a8dc5e8dc3dc2 ] If hv_netvsc driver is unloaded and reloaded, the NET_DEVICE_REGISTER handler cannot perform VF register successfully as the register call is received before netvsc_probe is finished. This is because we register register_netdevice_notifier() very early( even before vmbus_driver_register()). To fix this, we try to register each such matching VF( if it is visible as a netdevice) at the end of netvsc_probe. Cc: stable@vger.kernel.org Fixes: 85520856466e ("hv_netvsc: Fix race of register_netdevice_notifier and VF register") Suggested-by: Dexuan Cui Signed-off-by: Shradha Gupta Reviewed-by: Haiyang Zhang Reviewed-by: Dexuan Cui Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/hyperv/netvsc_drv.c | 82 +++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 20 deletions(-) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index e8efcc6a0b05a..0fc0f9cb3f34b 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -44,6 +44,10 @@ #define LINKCHANGE_INT (2 * HZ) #define VF_TAKEOVER_INT (HZ / 10) +/* Macros to define the context of vf registration */ +#define VF_REG_IN_PROBE 1 +#define VF_REG_IN_NOTIFIER 2 + static unsigned int ring_size __ro_after_init = 128; module_param(ring_size, uint, 0444); MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); @@ -2194,7 +2198,7 @@ static rx_handler_result_t netvsc_vf_handle_frame(struct sk_buff **pskb) } static int netvsc_vf_join(struct net_device *vf_netdev, - struct net_device *ndev) + struct net_device *ndev, int context) { struct net_device_context *ndev_ctx = netdev_priv(ndev); int ret; @@ -2217,7 +2221,11 @@ static int netvsc_vf_join(struct net_device *vf_netdev, goto upper_link_failed; } - schedule_delayed_work(&ndev_ctx->vf_takeover, VF_TAKEOVER_INT); + /* If this registration is called from probe context vf_takeover + * is taken care of later in probe itself. + */ + if (context == VF_REG_IN_NOTIFIER) + schedule_delayed_work(&ndev_ctx->vf_takeover, VF_TAKEOVER_INT); call_netdevice_notifiers(NETDEV_JOIN, vf_netdev); @@ -2355,7 +2363,7 @@ static int netvsc_prepare_bonding(struct net_device *vf_netdev) return NOTIFY_DONE; } -static int netvsc_register_vf(struct net_device *vf_netdev) +static int netvsc_register_vf(struct net_device *vf_netdev, int context) { struct net_device_context *net_device_ctx; struct netvsc_device *netvsc_dev; @@ -2395,7 +2403,7 @@ static int netvsc_register_vf(struct net_device *vf_netdev) netdev_info(ndev, "VF registering: %s\n", vf_netdev->name); - if (netvsc_vf_join(vf_netdev, ndev) != 0) + if (netvsc_vf_join(vf_netdev, ndev, context) != 0) return NOTIFY_DONE; dev_hold(vf_netdev); @@ -2479,10 +2487,31 @@ static int netvsc_unregister_vf(struct net_device *vf_netdev) return NOTIFY_OK; } +static int check_dev_is_matching_vf(struct net_device *event_ndev) +{ + /* Skip NetVSC interfaces */ + if (event_ndev->netdev_ops == &device_ops) + return -ENODEV; + + /* Avoid non-Ethernet type devices */ + if (event_ndev->type != ARPHRD_ETHER) + return -ENODEV; + + /* Avoid Vlan dev with same MAC registering as VF */ + if (is_vlan_dev(event_ndev)) + return -ENODEV; + + /* Avoid Bonding master dev with same MAC registering as VF */ + if (netif_is_bond_master(event_ndev)) + return -ENODEV; + + return 0; +} + static int netvsc_probe(struct hv_device *dev, const struct hv_vmbus_device_id *dev_id) { - struct net_device *net = NULL; + struct net_device *net = NULL, *vf_netdev; struct net_device_context *net_device_ctx; struct netvsc_device_info *device_info = NULL; struct netvsc_device *nvdev; @@ -2590,6 +2619,30 @@ static int netvsc_probe(struct hv_device *dev, } list_add(&net_device_ctx->list, &netvsc_dev_list); + + /* When the hv_netvsc driver is unloaded and reloaded, the + * NET_DEVICE_REGISTER for the vf device is replayed before probe + * is complete. This is because register_netdevice_notifier() gets + * registered before vmbus_driver_register() so that callback func + * is set before probe and we don't miss events like NETDEV_POST_INIT + * So, in this section we try to register the matching vf device that + * is present as a netdevice, knowing that its register call is not + * processed in the netvsc_netdev_notifier(as probing is progress and + * get_netvsc_byslot fails). + */ + for_each_netdev(dev_net(net), vf_netdev) { + ret = check_dev_is_matching_vf(vf_netdev); + if (ret != 0) + continue; + + if (net != get_netvsc_byslot(vf_netdev)) + continue; + + netvsc_prepare_bonding(vf_netdev); + netvsc_register_vf(vf_netdev, VF_REG_IN_PROBE); + __netvsc_vf_setup(net, vf_netdev); + break; + } rtnl_unlock(); netvsc_devinfo_put(device_info); @@ -2746,28 +2799,17 @@ static int netvsc_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { struct net_device *event_dev = netdev_notifier_info_to_dev(ptr); + int ret = 0; - /* Skip our own events */ - if (event_dev->netdev_ops == &device_ops) - return NOTIFY_DONE; - - /* Avoid non-Ethernet type devices */ - if (event_dev->type != ARPHRD_ETHER) - return NOTIFY_DONE; - - /* Avoid Vlan dev with same MAC registering as VF */ - if (is_vlan_dev(event_dev)) - return NOTIFY_DONE; - - /* Avoid Bonding master dev with same MAC registering as VF */ - if (netif_is_bond_master(event_dev)) + ret = check_dev_is_matching_vf(event_dev); + if (ret != 0) return NOTIFY_DONE; switch (event) { case NETDEV_POST_INIT: return netvsc_prepare_bonding(event_dev); case NETDEV_REGISTER: - return netvsc_register_vf(event_dev); + return netvsc_register_vf(event_dev, VF_REG_IN_NOTIFIER); case NETDEV_UNREGISTER: return netvsc_unregister_vf(event_dev); case NETDEV_UP: -- 2.43.0