Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1886356lql; Wed, 13 Mar 2024 10:49:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzVB5PIzN8PRgAbS1GCM8B5s7ClAaFwuykZ9Zwxa6VLgb/kICvJXX3p22Yakn4ovPSsl/+xWu1eNCUhjXgwP5tDfOMvLzHFmyTNfFaGQ== X-Google-Smtp-Source: AGHT+IGbJGuOWMd+p52MUu6uWkBseQhFbaiygZDoNUyaFHLf5wT5b9MgKEf0kqrUe2tzpFsM1Mns X-Received: by 2002:a05:6870:1713:b0:221:46ea:6790 with SMTP id h19-20020a056870171300b0022146ea6790mr5624234oae.56.1710352190529; Wed, 13 Mar 2024 10:49:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710352190; cv=pass; d=google.com; s=arc-20160816; b=lTLikRdbkb+sbx++6GMreaWptro0JmtYl6FA1jIUiqME8pVFoIVu1vwne4F5gytBxO WYZfnNcLOuNzTaZWlLV4Jp7aDfpJtTaTZ3kR9xAejJ6ttLgaeJc3Dol0YCpl1BA10Lj1 JUw0ZLzjmAfl7VIG8JB6xCb5GJ2IhvS9fsy0rsZ4tpZf6LXfOc0nHLZsjSeABsgfWl4n s2OjcrChElL1RouFhi2uGQSlX1rRsnvMjEtgk1wTCwJvX2Bs0Qopy04j9Qx+t05IPxBK GGGoAr6LoMSQHAtclRQLDUNf0I9rlr5XXEUll7a6YB9aHB0ZW2Mc5YNX3xXrWQa37v5G U7PA== 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=1qBDBhfcsqgtHi+kZeH56RQku/WiOx8BArWF5eaMpJE=; fh=PYDHYSjaccfTWijtfMSRpqXqBhIeuGpaN1uze8tf0h0=; b=yvpttRkxUJ3autN5KS1CTtlhxHsUGC22C83Y4/xQHKcdBmfZsD/qDvhjXjmKJEGxuk CeYo961acNFyUId6uSgY/DwC7k4zRSSv7jahSNUouUe5265/5UlqeJMXXkwTcCLAtElt FFq9RgMQeCM3AFsTylbzKIXiNgc77htIQoIlE3j9Zqs7dimL+4M7JsXtpmtbmOm224PI zOaUEM3MgNYnmrSxr1Z0miQmQJvSr/aOWS4IfjzLF8M9vOGPuAoJqqCwRmYa6u6NjA1/ W6BngOVCUqUVN0JZ8OX5VwX/71YWbFnZ6ErKV6pq5d4OJnM33qf1R9IbMBz8AUPapXP6 BM6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RtVgTFMU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101995-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t24-20020a656098000000b005dc81a6b2c9si9485073pgu.666.2024.03.13.10.49.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:49:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RtVgTFMU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101995-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 176AEB246CB for ; Wed, 13 Mar 2024 17:34:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B850314A0AD; Wed, 13 Mar 2024 16:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RtVgTFMU" 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 B205514A088; Wed, 13 Mar 2024 16:43:27 +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=1710348207; cv=none; b=QvHmdkUIdwdYFbffQ+iybO8bhDThBntvlVOWvOy2we5U4vLH/W7gMqFaokmOuwRUxtmg5Rri6G6R1Ls+SBpCdVOvoHbdPnSLMiei4CJPmIerjFljzUy+t73KPWgxK/CYpgOXIgE443/eh1U3Zl0CSQE/cZOfZtpsOOqSJfs+Wo8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348207; c=relaxed/simple; bh=OMRKw+JfNCMJGVklikilPsgcB18UH1vcqNvrL8kA3uc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P652mck84vDCE/pBljwUPONXZByRg1ppC0lsLe/gW8eXdx7U+n6iX1gGP12zUSYQAZJIYK6SBQuE/1w+kyBOzgNP3aEJHrySvVvwbsmOBohHkdvklVAlTqj5liHfRYgTO3f40+QvbuwgDAm+20AsjLPxzBcNV/LM35ruVg4iaac= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RtVgTFMU; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98D12C433C7; Wed, 13 Mar 2024 16:43:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348207; bh=OMRKw+JfNCMJGVklikilPsgcB18UH1vcqNvrL8kA3uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RtVgTFMU9BvHRG3tbMrrecW52x6kohQ7657bTDU/w2NELEptTVsYdGVBiDZFX9wdn 9Oo63dwBViaf+Vxnz9NgLVEymDKkd99W6A6Lczjcp9Vemco8lOE5hmS7QXtb8WGtVN 1FhSZ8obGjnhD0Sz1SW3bPDVhqwEzUr9Ml19xXqPN1oxhcbxU+hJTnunuaGpAKxqm9 0oPTrWjfvMkq3RBPW25rkBL6RqCHVXZshyspJlCD4vkI+NtoZKsb+cZY0VBb3XJA0N xvuRgMtxUGbUyqUQF8zpq3k4bEwiOaG7aW+yswbFOkFTsRcv6jBHSpubMyME7ThTtI 1MmQThKXIjwwA== 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.15 55/76] hv_netvsc: Register VF in netvsc_probe if NET_DEVICE_REGISTER missed Date: Wed, 13 Mar 2024 12:42:02 -0400 Message-ID: <20240313164223.615640-56-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313164223.615640-1-sashal@kernel.org> References: <20240313164223.615640-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.15.152-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.15.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.15.152-rc1 X-KernelTest-Deadline: 2024-03-15T16:42+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 a7d1304466880..804c11cbccff6 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -42,6 +42,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 4K pages)"); @@ -2204,7 +2208,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; @@ -2227,7 +2231,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); @@ -2365,7 +2373,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; @@ -2405,7 +2413,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); @@ -2503,10 +2511,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; @@ -2614,6 +2643,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); @@ -2770,28 +2823,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