Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp540194ybg; Sun, 26 Jul 2020 12:41:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiFXmNIe8LasDBBEW+Z0rV3dKiRBByaelfvUReVmju/NF7XdVaHpNJ7lhM+w+srb/gN4OU X-Received: by 2002:a05:6402:14c1:: with SMTP id f1mr19058945edx.342.1595792469073; Sun, 26 Jul 2020 12:41:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595792469; cv=none; d=google.com; s=arc-20160816; b=OapV6LJUhSvN9DZyvYq6j4WwlA63PcOe/P83SxKHIGd9wzR39Yapk7Mr84eyfamwq0 Brxu9bql/pPPlgat/Y8XEnlDyHbx49yIYoULEctfYLAhKmZ6VQbUUsx9n7zE89e5uYxc L7JPKG+PyiRInA8bLir/9dR7usH77YdpWfvn4akn2IPnqDTsFCy4LGwqUMpAIESoCoTQ 7M2mdNfT/YBo32LuGoCYwrUVDBxu8krvdFEEm/hiaVvx67I5VVAGdhUaxEoLXJAVpGQZ 7Wk+3uHA5BM9jr7JyUuuGpiNTQE7w5QBjZNy6kGlV+oFzzUERCISQvO5ArRYrJ8wE2ks v2Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=6m+PTaDWR+jjXlyoHpGvQ2gA8h7ifGI1N8GwbFi/F0s=; b=0fFnLm4WV0zKdn9b12QqQKtXV9DoNiuvkCc066vOpCUY2+C9MFNIIiZ5AV5ZofZwgx FGqEYsZh37kvGeippgipFHoDrlTB4BeSw4hlZ0sMo3EX7VQ5+ISlrlIOcC7lR/NPUcJI 29NHOITrdSVJBN+oWniaSZJSIZ1p85eAVPCq4/en8eqeuOAXAm6JAeyI32n4ba3vMR/i 8o3SYV55YJW9DV7+bPl4nLhj5LW36HuF8wrPmXP7hyePyJNgMqs6KwtPmTSm7pmqt0GC th4018NVxA2A1lAPwfpaMUEi89tpobX4YOBqNeATW5MYXFgO2w6KEb1k9xQag2b04asd MgcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r7si2481978edw.560.2020.07.26.12.40.47; Sun, 26 Jul 2020 12:41:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727883AbgGZTiA (ORCPT + 99 others); Sun, 26 Jul 2020 15:38:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:34678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726244AbgGZTh7 (ORCPT ); Sun, 26 Jul 2020 15:37:59 -0400 Received: from lx-ilial.mea.qualcomm.com (unknown [185.23.60.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AEEB0206D8; Sun, 26 Jul 2020 19:37:56 +0000 (UTC) From: Ilia Lin To: davem@davemloft.net, kuba@kernel.org, jiri@mellanox.com, edumazet@google.com, ap420073@gmail.com, xiyou.wangcong@gmail.com, maximmi@mellanox.com, ilia.lin@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net: dev: Add API to check net_dev readiness Date: Sun, 26 Jul 2020 22:37:54 +0300 Message-Id: <1595792274-28580-1-git-send-email-ilial@codeaurora.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilia Lin Add an API that returns true, if the net_dev_init was already called, and the driver was initialized. Some early drivers, that are initialized during the subsys_initcall may try accessing the net_dev or NAPI APIs before the net_dev_init, and will encounter a kernel bug. This API provides a way to handle this and manage by deferring or by other way. Signed-off-by: Ilia Lin --- include/linux/netdevice.h | 2 ++ net/core/dev.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 98d290c..d17d364 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2600,6 +2600,8 @@ enum netdev_cmd { }; const char *netdev_cmd_to_name(enum netdev_cmd cmd); +bool is_net_dev_initialized(void); + int register_netdevice_notifier(struct notifier_block *nb); int unregister_netdevice_notifier(struct notifier_block *nb); int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb); diff --git a/net/core/dev.c b/net/core/dev.c index 316349f..1b50488 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1793,6 +1793,23 @@ static void call_netdevice_unregister_net_notifiers(struct notifier_block *nb, static int dev_boot_phase = 1; /** + * is_net_dev_initialized - check, whether the net_dev was + * initialized + * + * Returns true, if the net_dev_init was already called, and + * the driver is initialized. + * + * This is useful for early drivers trying to call net_dev and + * NAPI APIs + */ + +bool is_net_dev_initialized(void) +{ + return !(bool)dev_boot_phase; +} +EXPORT_SYMBOL(is_net_dev_initialized); + +/** * register_netdevice_notifier - register a network notifier block * @nb: notifier *