]> git.baikalelectronics.ru Git - kernel.git/commit
net: initialize init_net earlier
authorEric Dumazet <edumazet@google.com>
Sat, 5 Feb 2022 17:01:25 +0000 (09:01 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sun, 6 Feb 2022 11:04:29 +0000 (11:04 +0000)
commiteb13dc48d99a9c7fe5ce2fbcbcde4e015a80b753
tree922fc1902a069d21c6e214944b75513459ff4522
parent88cbac46816793cbdf9023bc8914efb552af4b84
net: initialize init_net earlier

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]

a884524cecfd ("netns: do not call pernet ops for not yet set up init_net namespace")
99d76929bfcc ("net: Initialise init_net.count to 1")
6e78dfe42455 ("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>
include/net/net_namespace.h
init/main.c
net/core/dev.c
net/core/net_namespace.c