linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] mm: vmalloc: do not allow kzalloc to fail
@ 2018-12-20 20:23 Nicholas Mc Guire
  2018-12-21 15:53 ` Michal Hocko
  2018-12-21 21:58 ` David Rientjes
  0 siblings, 2 replies; 11+ messages in thread
From: Nicholas Mc Guire @ 2018-12-20 20:23 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Chintan Pandya, Michal Hocko, Andrey Ryabinin, Arun KS,
	Joe Perches, Luis R. Rodriguez, linux-mm, linux-kernel,
	Nicholas Mc Guire

While this is in a very early stage of the system boot and if memory
were exhausted the system has a more serious problem anyway - but still
the kzalloc here seems unsafe. Looking at the history it was previously
switched from alloc_bootmem() to kzalloc() using GFP_NOWAIT flag but
there never seems to have been a check for NULL return. So if this is
expected to never fail should it not be using | __GFP_NOFAIL here ?
Or put differently - what is the rational for GFP_NOWAIT to be safe here ?

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Fixes 43ebdac42f16 ("vmalloc: use kzalloc() instead of alloc_bootmem()")
---

Problem was found by an experimental coccinelle script

Patch was only compile tested for x86_64_defconfig

Patch is against v4.20-rc7 (localversion-next next-20181220)

 mm/vmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 871e41c..1c118d7 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1258,7 +1258,7 @@ void __init vmalloc_init(void)
 
 	/* Import existing vmlist entries. */
 	for (tmp = vmlist; tmp; tmp = tmp->next) {
-		va = kzalloc(sizeof(struct vmap_area), GFP_NOWAIT);
+		va = kzalloc(sizeof(*va), GFP_NOWAIT | __GFP_NOFAIL);
 		va->flags = VM_VM_AREA;
 		va->va_start = (unsigned long)tmp->addr;
 		va->va_end = va->va_start + tmp->size;
-- 
2.1.4

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-12-24 11:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-20 20:23 [PATCH RFC] mm: vmalloc: do not allow kzalloc to fail Nicholas Mc Guire
2018-12-21 15:53 ` Michal Hocko
2018-12-21 21:58 ` David Rientjes
2018-12-21 21:58   ` David Rientjes
2018-12-22  8:04   ` Nicholas Mc Guire
2018-12-22  8:04     ` Nicholas Mc Guire
2018-12-24  8:10     ` Michal Hocko
2018-12-24  9:38       ` Nicholas Mc Guire
2018-12-24  9:38         ` Nicholas Mc Guire
2018-12-24 11:58         ` Nicholas Mc Guire
2018-12-24 11:58           ` Nicholas Mc Guire

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox