Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1368577imu; Fri, 21 Dec 2018 18:55:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN5+Tea9/jZBmJkV/3EQ6Nda4IJOPnK5SOOSrw9XbFClc7IsFI1XQxHLuQmEKSdc0Oqt30Y4 X-Received: by 2002:a62:5444:: with SMTP id i65mr5136512pfb.193.1545447303199; Fri, 21 Dec 2018 18:55:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545447303; cv=none; d=google.com; s=arc-20160816; b=WqIgbMvWx53+GY1lRbO4B2RUcx7+9Lu8CSVkhDMtXuQmXoBH0LT57ndQy5HrrzmyRo RldCJDotqU4ZsOJmO39EK2YbM8crZyNJ+aQGpH9bWyKQmBMMwMxJAxIrj+7aOB/fxL82 gCyu9R1S7BgOh6H2g0NuSAlcoIAJwpxkJwYaC+bKQfg8ZVuEFecsO3tox5XHIwEUsL8l DMrdaiTzq2StpdiCcfO7r5JuAd8B67e+pzV0ZijmEHWbwhUxA/3wEPnTngsRw+yQtk71 Of7fG6CzHllKP+hpmnlJWxVAIr6ZPIJxk+Scz0oEUgQ4q4kiRfnsPehUeUnanzWFZ+9m o0Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=B/WKMvlISftakBPK2/9YwZNjtA96klgNZ7V3HSWm/2k=; b=smGIHkJWNmi41QPddmVolNhHV6RVOCg3DxaNrS2KkPSmkIU1trCJK6fSBdLvHnM33x 9DoZUibTSuDNW5b1An3ky8adKVVIuIk6wWrIxX0QK4cYzfOrNFA6U3oDRWdzcka36//d dk9wBn+y88AdB5aM3KQn+FUWTzEASdyCgmLDCDEC85F/IqE8UKHkSR4zaU/BuozEemtk Y5B2RHITkupuGYU8mwWE2NseQtMkUF5Wp9Fxq/1e8xc94OZ2MoHqyX4ztp37N8qehn1p 142J1Oa2PmxaQtTp4nnjyQvFc3NwH4vSOxh9/jJuXvfIQ+AxLoq9adflhaEeriklT49x oPpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si23598729plk.61.2018.12.21.18.54.14; Fri, 21 Dec 2018 18:55:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732186AbeLUPxv (ORCPT + 99 others); Fri, 21 Dec 2018 10:53:51 -0500 Received: from mx2.suse.de ([195.135.220.15]:37060 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725845AbeLUPxv (ORCPT ); Fri, 21 Dec 2018 10:53:51 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id F244EACA2; Fri, 21 Dec 2018 15:53:48 +0000 (UTC) Date: Fri, 21 Dec 2018 16:53:47 +0100 From: Michal Hocko To: Nicholas Mc Guire Cc: Andrew Morton , Chintan Pandya , Andrey Ryabinin , Arun KS , Joe Perches , "Luis R. Rodriguez" , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC] mm: vmalloc: do not allow kzalloc to fail Message-ID: <20181221155347.GF6410@dhcp22.suse.cz> References: <1545337437-673-1-git-send-email-hofrat@osadl.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1545337437-673-1-git-send-email-hofrat@osadl.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 20-12-18 21:23:57, Nicholas Mc Guire wrote: > 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 ? Is there an actual problem you are trying to solve? GFP_NOWAIT| __GFP_NOFAIL is a terrible idea. If this is an early allocation then what would break this allocation out of the loop? There is nothing to reclaim, there is nothing to kill. The allocation failure check would be nice but what can you do except for BUG_ON? > Signed-off-by: Nicholas Mc Guire > Fixes 43ebdac42f16 ("vmalloc: use kzalloc() instead of alloc_bootmem()") So no, this is definitely not the right thing to do. Nacked-by: Michal Hocko > --- > > 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 > -- Michal Hocko SUSE Labs