net: initialize init_net earlier
[ Upstream commit 9c1be1935fb68b2413796cdc03d019b8cf35ab51 ]
While testing a patch that will follow later
("net: add netns refcount tracker to struct nsproxy")
I found that devtmpfs_init() was called before init_net
was initialized.
This is a bug, because devtmpfs_setup() calls
ksys_unshare(CLONE_NEWNS);
This has the effect of increasing init_net refcount,
which will be later overwritten to 1, as part of setup_net(&init_net)
We had too many prior patches [1] trying to work around the root cause.
Really, make sure init_net is in BSS section, and that net_ns_init()
is called earlier at boot time.
Note that another patch ("vfs: add netns refcount tracker
to struct fs_context") also will need net_ns_init() being called
before vfs_caches_init()
As a bonus, this patch saves around 4KB in .data section.
[1]
f8c46cb390 ("netns: do not call pernet ops for not yet set up init_net namespace")
b5082df801 ("net: Initialise init_net.count to 1")
734b65417b ("net: Statically initialize init_net.dev_base_head")
v2: fixed a build error reported by kernel build bots (CONFIG_NET=n)
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
4790998fdd
commit
9c1ace066f
@@ -11378,8 +11378,7 @@ static int __net_init netdev_init(struct net *net)
|
||||
BUILD_BUG_ON(GRO_HASH_BUCKETS >
|
||||
8 * sizeof_field(struct napi_struct, gro_bitmask));
|
||||
|
||||
if (net != &init_net)
|
||||
INIT_LIST_HEAD(&net->dev_base_head);
|
||||
INIT_LIST_HEAD(&net->dev_base_head);
|
||||
|
||||
net->dev_name_head = netdev_create_hash();
|
||||
if (net->dev_name_head == NULL)
|
||||
|
||||
Reference in New Issue
Block a user