From patchwork Tue Jan 19 19:11:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 12030613 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D075DC43381 for ; Tue, 19 Jan 2021 19:41:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7796F230FE for ; Tue, 19 Jan 2021 19:41:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726501AbhASTbu (ORCPT ); Tue, 19 Jan 2021 14:31:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:40782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392241AbhASTMx (ORCPT ); Tue, 19 Jan 2021 14:12:53 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DA17D216FD; Tue, 19 Jan 2021 19:12:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611083533; bh=T9Ergzt8UttH+ZgH2jkWyJf/CzIXN9QAzLK5kPx9jPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=peQvPyvtZbw1LPyGbL4rt3u94R4aicNnS2QpOQXZSQ4+8uFzL/XkGzJATV5N/wGVT k/m8eZb3MmTo5H8PSgjJRuV75n7oHzZ63Pqmv+MFnJIKPWr69ONZ1KRyo//zjDpDOw 7FUeZ073RbQa9jgXzYiWdIG6uYafZFHQx6dqM9N13jOGjJ3ML6FQJOhW8TsI9R1ULb Dhb1ch5AkZg2p//PkRc3mI0ZDiggJ8Kb08WffFHET8OXAgYnwxp4+AEiMEJz/HNIAc ifQj7hnerXUDRP+lGHPsc5G8m1rkSgxzdyIWskc7GRaE9mlsbUNITWOrOJ8XmGVrte 51BXVqgVgEtQw== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, Jakub Kicinski Subject: [PATCH net-next 1/4] net: move net_set_todo inside rollback_registered() Date: Tue, 19 Jan 2021 11:11:55 -0800 Message-Id: <20210119191158.3093099-2-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210119191158.3093099-1-kuba@kernel.org> References: <20210119191158.3093099-1-kuba@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Commit 93ee31f14f6f ("[NET]: Fix free_netdev on register_netdev failure.") moved net_set_todo() outside of rollback_registered() so that rollback_registered() can be used in the failure path of register_netdevice() but without risking a double free. Since commit cf124db566e6 ("net: Fix inconsistent teardown and release of private netdev state."), however, we have a better way of handling that condition, since destructors don't call free_netdev() directly. After the change in commit c269a24ce057 ("net: make free_netdev() more lenient with unregistering devices") we can now move net_set_todo() back. Signed-off-by: Jakub Kicinski --- net/core/dev.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 6b90520a01b1..5f928b51c6b0 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -9546,8 +9546,10 @@ static void rollback_registered_many(struct list_head *head) synchronize_net(); - list_for_each_entry(dev, head, unreg_list) + list_for_each_entry(dev, head, unreg_list) { dev_put(dev); + net_set_todo(dev); + } } static void rollback_registered(struct net_device *dev) @@ -10104,7 +10106,6 @@ int register_netdevice(struct net_device *dev) /* Expect explicit free_netdev() on failure */ dev->needs_free_netdev = false; rollback_registered(dev); - net_set_todo(dev); goto out; } /* @@ -10727,8 +10728,6 @@ void unregister_netdevice_queue(struct net_device *dev, struct list_head *head) list_move_tail(&dev->unreg_list, head); } else { rollback_registered(dev); - /* Finish processing unregister after unlock */ - net_set_todo(dev); } } EXPORT_SYMBOL(unregister_netdevice_queue); @@ -10742,12 +10741,8 @@ EXPORT_SYMBOL(unregister_netdevice_queue); */ void unregister_netdevice_many(struct list_head *head) { - struct net_device *dev; - if (!list_empty(head)) { rollback_registered_many(head); - list_for_each_entry(dev, head, unreg_list) - net_set_todo(dev); list_del(head); } }