* [PATCH v3 net] af_unix: Do not call kmemdup() for init_net's sysctl table.
@ 2022-06-27 23:36 Kuniyuki Iwashima
2022-06-29 3:51 ` Jakub Kicinski
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Kuniyuki Iwashima @ 2022-06-27 23:36 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Eric W. Biederman, Pavel Emelyanov, Herbert Xu, Kuniyuki Iwashima,
Kuniyuki Iwashima, netdev
While setting up init_net's sysctl table, we need not duplicate the
global table and can use it directly as ipv4_sysctl_init_net() does.
Unlike IPv4, AF_UNIX does not have a huge sysctl table for now, so it
cannot be a problem, but this patch makes code consistent.
Fixes: 1597fbc0faf8 ("[UNIX]: Make the unix sysctl tables per-namespace")
Acked-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
v3:
* Update changelog
* Fix a bug when we unload unix.ko
v2: https://lore.kernel.org/all/20220626082331.36119-1-kuniyu@amazon.com/
* Fix NULL comparison style by checkpatch.pl
v1: https://lore.kernel.org/all/20220626074454.28944-1-kuniyu@amazon.com/
---
net/unix/sysctl_net_unix.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
index 01d44e2598e2..3f1fdffd6092 100644
--- a/net/unix/sysctl_net_unix.c
+++ b/net/unix/sysctl_net_unix.c
@@ -26,11 +26,16 @@ int __net_init unix_sysctl_register(struct net *net)
{
struct ctl_table *table;
- table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
- if (table == NULL)
- goto err_alloc;
+ if (net_eq(net, &init_net)) {
+ table = unix_table;
+ } else {
+ table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
+ if (!table)
+ goto err_alloc;
+
+ table[0].data = &net->unx.sysctl_max_dgram_qlen;
+ }
- table[0].data = &net->unx.sysctl_max_dgram_qlen;
net->unx.ctl = register_net_sysctl(net, "net/unix", table);
if (net->unx.ctl == NULL)
goto err_reg;
@@ -38,7 +43,8 @@ int __net_init unix_sysctl_register(struct net *net)
return 0;
err_reg:
- kfree(table);
+ if (net_eq(net, &init_net))
+ kfree(table);
err_alloc:
return -ENOMEM;
}
@@ -49,5 +55,6 @@ void unix_sysctl_unregister(struct net *net)
table = net->unx.ctl->ctl_table_arg;
unregister_net_sysctl_table(net->unx.ctl);
- kfree(table);
+ if (!net_eq(net, &init_net))
+ kfree(table);
}
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v3 net] af_unix: Do not call kmemdup() for init_net's sysctl table.
2022-06-27 23:36 [PATCH v3 net] af_unix: Do not call kmemdup() for init_net's sysctl table Kuniyuki Iwashima
@ 2022-06-29 3:51 ` Jakub Kicinski
2022-06-29 3:55 ` Kuniyuki Iwashima
2022-06-29 4:10 ` patchwork-bot+netdevbpf
2022-07-08 16:10 ` Eric Dumazet
2 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2022-06-29 3:51 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Eric W. Biederman,
Pavel Emelyanov, Herbert Xu, Kuniyuki Iwashima, netdev
On Mon, 27 Jun 2022 16:36:27 -0700 Kuniyuki Iwashima wrote:
> While setting up init_net's sysctl table, we need not duplicate the
> global table and can use it directly as ipv4_sysctl_init_net() does.
>
> Unlike IPv4, AF_UNIX does not have a huge sysctl table for now, so it
> cannot be a problem, but this patch makes code consistent.
Thanks for the extra info. It sounds like an optimization, tho.
We save one table's worth of memory. Any objections to applying
this to net-next?
> Fixes: 1597fbc0faf8 ("[UNIX]: Make the unix sysctl tables per-namespace")
> Acked-by: Eric W. Biederman <ebiederm@xmission.com>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v3 net] af_unix: Do not call kmemdup() for init_net's sysctl table.
2022-06-29 3:51 ` Jakub Kicinski
@ 2022-06-29 3:55 ` Kuniyuki Iwashima
0 siblings, 0 replies; 5+ messages in thread
From: Kuniyuki Iwashima @ 2022-06-29 3:55 UTC (permalink / raw)
To: kuba
Cc: davem, ebiederm, edumazet, herbert, kuni1840, kuniyu, netdev,
pabeni, xemul
From: Jakub Kicinski <kuba@kernel.org>
Date: Tue, 28 Jun 2022 20:51:25 -0700
> On Mon, 27 Jun 2022 16:36:27 -0700 Kuniyuki Iwashima wrote:
> > While setting up init_net's sysctl table, we need not duplicate the
> > global table and can use it directly as ipv4_sysctl_init_net() does.
> >
> > Unlike IPv4, AF_UNIX does not have a huge sysctl table for now, so it
> > cannot be a problem, but this patch makes code consistent.
>
> Thanks for the extra info. It sounds like an optimization, tho.
> We save one table's worth of memory. Any objections to applying
> this to net-next?
I'm fine with net-next.
Thank you,
Kuniyuki
> > Fixes: 1597fbc0faf8 ("[UNIX]: Make the unix sysctl tables per-namespace")
> > Acked-by: Eric W. Biederman <ebiederm@xmission.com>
> > Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 net] af_unix: Do not call kmemdup() for init_net's sysctl table.
2022-06-27 23:36 [PATCH v3 net] af_unix: Do not call kmemdup() for init_net's sysctl table Kuniyuki Iwashima
2022-06-29 3:51 ` Jakub Kicinski
@ 2022-06-29 4:10 ` patchwork-bot+netdevbpf
2022-07-08 16:10 ` Eric Dumazet
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-06-29 4:10 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: davem, edumazet, kuba, pabeni, ebiederm, xemul, herbert, kuni1840,
netdev
Hello:
This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 27 Jun 2022 16:36:27 -0700 you wrote:
> While setting up init_net's sysctl table, we need not duplicate the
> global table and can use it directly as ipv4_sysctl_init_net() does.
>
> Unlike IPv4, AF_UNIX does not have a huge sysctl table for now, so it
> cannot be a problem, but this patch makes code consistent.
>
> Fixes: 1597fbc0faf8 ("[UNIX]: Make the unix sysctl tables per-namespace")
> Acked-by: Eric W. Biederman <ebiederm@xmission.com>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
>
> [...]
Here is the summary with links:
- [v3,net] af_unix: Do not call kmemdup() for init_net's sysctl table.
https://git.kernel.org/netdev/net-next/c/849d5aa3a1d8
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v3 net] af_unix: Do not call kmemdup() for init_net's sysctl table.
2022-06-27 23:36 [PATCH v3 net] af_unix: Do not call kmemdup() for init_net's sysctl table Kuniyuki Iwashima
2022-06-29 3:51 ` Jakub Kicinski
2022-06-29 4:10 ` patchwork-bot+netdevbpf
@ 2022-07-08 16:10 ` Eric Dumazet
2 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2022-07-08 16:10 UTC (permalink / raw)
To: Kuniyuki Iwashima, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: Eric W. Biederman, Pavel Emelyanov, Herbert Xu, Kuniyuki Iwashima,
netdev
On 6/28/22 01:36, Kuniyuki Iwashima wrote:
> While setting up init_net's sysctl table, we need not duplicate the
> global table and can use it directly as ipv4_sysctl_init_net() does.
>
> Unlike IPv4, AF_UNIX does not have a huge sysctl table for now, so it
> cannot be a problem, but this patch makes code consistent.
>
> Fixes: 1597fbc0faf8 ("[UNIX]: Make the unix sysctl tables per-namespace")
> Acked-by: Eric W. Biederman <ebiederm@xmission.com>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
> v3:
> * Update changelog
> * Fix a bug when we unload unix.ko
>
> v2: https://lore.kernel.org/all/20220626082331.36119-1-kuniyu@amazon.com/
> * Fix NULL comparison style by checkpatch.pl
>
> v1: https://lore.kernel.org/all/20220626074454.28944-1-kuniyu@amazon.com/
> ---
> net/unix/sysctl_net_unix.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
> index 01d44e2598e2..3f1fdffd6092 100644
> --- a/net/unix/sysctl_net_unix.c
> +++ b/net/unix/sysctl_net_unix.c
> @@ -26,11 +26,16 @@ int __net_init unix_sysctl_register(struct net *net)
> {
> struct ctl_table *table;
>
> - table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
> - if (table == NULL)
> - goto err_alloc;
> + if (net_eq(net, &init_net)) {
> + table = unix_table;
> + } else {
> + table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
> + if (!table)
> + goto err_alloc;
> +
> + table[0].data = &net->unx.sysctl_max_dgram_qlen;
> + }
>
> - table[0].data = &net->unx.sysctl_max_dgram_qlen;
> net->unx.ctl = register_net_sysctl(net, "net/unix", table);
> if (net->unx.ctl == NULL)
> goto err_reg;
> @@ -38,7 +43,8 @@ int __net_init unix_sysctl_register(struct net *net)
> return 0;
>
> err_reg:
> - kfree(table);
> + if (net_eq(net, &init_net))
> + kfree(table);
Inverted test, I guess :/
I will send a fix.
> err_alloc:
> return -ENOMEM;
> }
> @@ -49,5 +55,6 @@ void unix_sysctl_unregister(struct net *net)
>
> table = net->unx.ctl->ctl_table_arg;
> unregister_net_sysctl_table(net->unx.ctl);
> - kfree(table);
> + if (!net_eq(net, &init_net))
> + kfree(table);
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-07-08 16:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-27 23:36 [PATCH v3 net] af_unix: Do not call kmemdup() for init_net's sysctl table Kuniyuki Iwashima
2022-06-29 3:51 ` Jakub Kicinski
2022-06-29 3:55 ` Kuniyuki Iwashima
2022-06-29 4:10 ` patchwork-bot+netdevbpf
2022-07-08 16:10 ` Eric Dumazet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).