From patchwork Thu Jun 27 09:39:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Baechle X-Patchwork-Id: 2790921 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8B4D49F245 for ; Thu, 27 Jun 2013 09:40:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 34FD9202E6 for ; Thu, 27 Jun 2013 09:40:07 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 730AE202C4 for ; Thu, 27 Jun 2013 09:40:05 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Us8gL-0006te-Kn; Thu, 27 Jun 2013 09:40:01 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Us8gJ-0003V3-36; Thu, 27 Jun 2013 09:39:59 +0000 Received: from marvin.linux-mips.org ([78.24.191.183] helo=git.linux-mips.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Us8gE-0003UQ-UX for linux-arm-kernel@lists.infradead.org; Thu, 27 Jun 2013 09:39:56 +0000 Received: from localhost.localdomain ([127.0.0.1]:51818 "EHLO linux-mips.org" rhost-flags-OK-OK-OK-FAIL) by eddie.linux-mips.org with ESMTP id S6824786Ab3F0JjfjzLFy (ORCPT ); Thu, 27 Jun 2013 11:39:35 +0200 Received: from scotty.linux-mips.net (localhost.localdomain [127.0.0.1]) by scotty.linux-mips.net (8.14.5/8.14.4) with ESMTP id r5R9dORn000547; Thu, 27 Jun 2013 11:39:24 +0200 Received: (from ralf@localhost) by scotty.linux-mips.net (8.14.5/8.14.5/Submit) id r5R9dH9S000546; Thu, 27 Jun 2013 11:39:17 +0200 Date: Thu, 27 Jun 2013 11:39:17 +0200 From: Ralf Baechle To: Veli-Pekka Peltola Subject: Re: [PATCH v2] mm: module_alloc: check if size is 0 Message-ID: <20130627093917.GQ7171@linux-mips.org> References: <1330631119-10059-1-git-send-email-veli-pekka.peltola@bluegiga.com> <1331125768-25454-1-git-send-email-veli-pekka.peltola@bluegiga.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1331125768-25454-1-git-send-email-veli-pekka.peltola@bluegiga.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130627_053955_271256_22388AD0 X-CRM114-Status: GOOD ( 25.07 ) X-Spam-Score: -3.2 (---) Cc: linux-mips@linux-mips.org, Rusty Russell , Russell King , Peter Zijlstra , x86@kernel.org, linux-kernel@vger.kernel.org, Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Andrew Morton , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Warming up an ancient thread because the discussion seems to have just stalled at some point and I still have this patch bitrotting in patchwork. The original thread can be found at: http://www.linux-mips.org/archives/linux-mips/2012-03/msg00006.html http://www.linux-mips.org/archives/linux-mips/2012-03/msg00028.html On Wed, Mar 07, 2012 at 03:09:28PM +0200, Veli-Pekka Peltola wrote: > After commit de7d2b567d040e3b67fe7121945982f14343213d (mm/vmalloc.c: report > more vmalloc failures) users will get a warning if vmalloc_node_range() is > called with size 0. This happens if module's init size equals to 0. This > patch changes ARM, MIPS and x86 module_alloc() to return NULL before calling > vmalloc_node_range() that would also return NULL and print a warning. > > Signed-off-by: Veli-Pekka Peltola > Cc: Russell King > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: "H. Peter Anvin" > Cc: x86@kernel.org > --- > I found this with ARM but after checking out various implementations of > module_alloc() I thought it would be better to fix all at once. > > One way to replicate the warning: > compile kernel with CONFIG_KALLSYMS=n > insmod a module without init, I used usb-common.ko I didn't try to reproduce the issue but the code in question doesn't seem to have changed so the issue should still persist. Imho de7d2b567d040e3b67fe7121945982f14343213d [mm/vmalloc.c: report more vmalloc failures] is overly strict in that it also reports zero-sized allocations. I consider such allocations stupid but legitimiate and often better preferrable over having to scatter checks for zero size all over place. So maybe something like below patch? Thanks, Ralf --- Signed-off-by: Ralf Baechle mm/vmalloc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d365724..e58ca10 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1679,7 +1679,10 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, unsigned long real_size = size; size = PAGE_ALIGN(size); - if (!size || (size >> PAGE_SHIFT) > totalram_pages) + if (unlikely(!size)) + return NULL; + + if ((size >> PAGE_SHIFT) > totalram_pages) goto fail; area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST, @@ -1711,6 +1714,7 @@ fail: warn_alloc_failed(gfp_mask, 0, "vmalloc: allocation failure: %lu bytes\n", real_size); + return NULL; }