Commit 976a702a authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

tcp: handle tcp_net_metrics_init() order-5 memory allocation failures

order-5 allocations can fail with current kernels, we should
try vmalloc() as well.
Reported-by: default avatarJulien Tinnes <jln@google.com>
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6fc4adca
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/bootmem.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -9,6 +8,7 @@ ...@@ -9,6 +8,7 @@
#include <linux/tcp.h> #include <linux/tcp.h>
#include <linux/hash.h> #include <linux/hash.h>
#include <linux/tcp_metrics.h> #include <linux/tcp_metrics.h>
#include <linux/vmalloc.h>
#include <net/inet_connection_sock.h> #include <net/inet_connection_sock.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
...@@ -1034,7 +1034,10 @@ static int __net_init tcp_net_metrics_init(struct net *net) ...@@ -1034,7 +1034,10 @@ static int __net_init tcp_net_metrics_init(struct net *net)
net->ipv4.tcp_metrics_hash_log = order_base_2(slots); net->ipv4.tcp_metrics_hash_log = order_base_2(slots);
size = sizeof(struct tcpm_hash_bucket) << net->ipv4.tcp_metrics_hash_log; size = sizeof(struct tcpm_hash_bucket) << net->ipv4.tcp_metrics_hash_log;
net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL); net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
if (!net->ipv4.tcp_metrics_hash)
net->ipv4.tcp_metrics_hash = vzalloc(size);
if (!net->ipv4.tcp_metrics_hash) if (!net->ipv4.tcp_metrics_hash)
return -ENOMEM; return -ENOMEM;
...@@ -1055,7 +1058,10 @@ static void __net_exit tcp_net_metrics_exit(struct net *net) ...@@ -1055,7 +1058,10 @@ static void __net_exit tcp_net_metrics_exit(struct net *net)
tm = next; tm = next;
} }
} }
kfree(net->ipv4.tcp_metrics_hash); if (is_vmalloc_addr(net->ipv4.tcp_metrics_hash))
vfree(net->ipv4.tcp_metrics_hash);
else
kfree(net->ipv4.tcp_metrics_hash);
} }
static __net_initdata struct pernet_operations tcp_net_metrics_ops = { static __net_initdata struct pernet_operations tcp_net_metrics_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment