[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170130094940.13546-10-mhocko@kernel.org>
Date: Mon, 30 Jan 2017 10:49:40 +0100
From: Michal Hocko <mhocko@...nel.org>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: Vlastimil Babka <vbabka@...e.cz>,
David Rientjes <rientjes@...gle.com>,
Mel Gorman <mgorman@...e.de>,
Johannes Weiner <hannes@...xchg.org>,
Al Viro <viro@...iv.linux.org.uk>, <linux-mm@...ck.org>,
LKML <linux-kernel@...r.kernel.org>,
Michal Hocko <mhocko@...e.com>,
Alexei Starovoitov <ast@...nel.org>,
Andrey Konovalov <andreyknvl@...gle.com>,
Marcelo Ricardo Leitner <marcelo.leitner@...il.com>,
Pablo Neira Ayuso <pablo@...filter.org>
Subject: [PATCH 9/9] net, bpf: use kvzalloc helper
From: Michal Hocko <mhocko@...e.com>
both bpf_map_area_alloc and xt_alloc_table_info try really hard to
play nicely with large memory requests which can be triggered from
the userspace (by an admin). See 5bad87348c70 ("netfilter: x_tables:
avoid warn and OOM killer on vmalloc call") resp. d407bd25a204 ("bpf:
don't trigger OOM killer under pressure with map alloc").
The current allocation pattern strongly resembles kvmalloc helper except
for one thing __GFP_NORETRY is not used for the vmalloc fallback. The
main reason why kvmalloc doesn't really support __GFP_NORETRY is
because vmalloc doesn't support this flag properly and it is far from
straightforward to make it understand it because there are some hard
coded GFP_KERNEL allocation deep in the call chains. This patch simply
replaces the open coded variants with kvmalloc and puts a note to
push on MM people to support __GFP_NORETRY in kvmalloc it this turns out
to be really needed along with OOM report pointing at vmalloc.
If there is an immediate need and no full support yet then
kvmalloc(size, gfp | __GFP_NORETRY)
will work as good as __vmalloc(gfp | __GFP_NORETRY) - in other words it
might trigger the OOM in some cases.
Cc: Alexei Starovoitov <ast@...nel.org>
Cc: Andrey Konovalov <andreyknvl@...gle.com>
Cc: Marcelo Ricardo Leitner <marcelo.leitner@...il.com>
Cc: Pablo Neira Ayuso <pablo@...filter.org>
Acked-by: Daniel Borkmann <daniel@...earbox.net>
Signed-off-by: Michal Hocko <mhocko@...e.com>
---
kernel/bpf/syscall.c | 19 +++++--------------
net/netfilter/x_tables.c | 16 ++++++----------
2 files changed, 11 insertions(+), 24 deletions(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 08a4d287226b..3d38c7a51e1a 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -54,21 +54,12 @@ void bpf_register_map_type(struct bpf_map_type_list *tl)
void *bpf_map_area_alloc(size_t size)
{
- /* We definitely need __GFP_NORETRY, so OOM killer doesn't
- * trigger under memory pressure as we really just want to
- * fail instead.
+ /*
+ * FIXME: we would really like to not trigger the OOM killer and rather
+ * fail instead. This is not supported right now. Please nag MM people
+ * if these OOM start bothering people.
*/
- const gfp_t flags = __GFP_NOWARN | __GFP_NORETRY | __GFP_ZERO;
- void *area;
-
- if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) {
- area = kmalloc(size, GFP_USER | flags);
- if (area != NULL)
- return area;
- }
-
- return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | flags,
- PAGE_KERNEL);
+ return kvzalloc(size, GFP_USER);
}
void bpf_map_area_free(void *area)
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index d529989f5791..ba8ba633da72 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -995,16 +995,12 @@ struct xt_table_info *xt_alloc_table_info(unsigned int size)
if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > totalram_pages)
return NULL;
- if (sz <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER))
- info = kmalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY);
- if (!info) {
- info = __vmalloc(sz, GFP_KERNEL | __GFP_NOWARN |
- __GFP_NORETRY | __GFP_HIGHMEM,
- PAGE_KERNEL);
- if (!info)
- return NULL;
- }
- memset(info, 0, sizeof(*info));
+ /*
+ * FIXME: we would really like to not trigger the OOM killer and rather
+ * fail instead. This is not supported right now. Please nag MM people
+ * if these OOM start bothering people.
+ */
+ info = kvzalloc(sz, GFP_KERNEL);
info->size = size;
return info;
}
--
2.11.0
Powered by blists - more mailing lists