Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8379020rwb; Wed, 23 Nov 2022 21:16:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf4vNRNVvISl7+F0mSB+xU1IJXBq2d+aBSwklbe8IoUqmO6M6wuWvR78x11fmmwahRBJHIMn X-Received: by 2002:a05:6402:240b:b0:469:9667:704c with SMTP id t11-20020a056402240b00b004699667704cmr16187285eda.318.1669266994507; Wed, 23 Nov 2022 21:16:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669266994; cv=none; d=google.com; s=arc-20160816; b=QzWFJhK3O2hqke5ih1X9UCI79aRwnEtvdI1GPHHc3dgEgiSsbXGLLwIJM+xLuCagmZ 5vDgxhDc/n4CIg+HuFoDoq0Ef5pMAFccok/mssYYINGSlKSHqWk2S16rIDPCtheHDmmZ AAKsz6LDeJmUA1fLBt6Y9ciR+5ooe2Qi3Pyjn55sVQB5ZdBhYL8PT4KL2djQyu4VkZPv qpVKdtc4Ks0hqfQAVRLzrheHTOtEuwTjtrB4hIone8kKqVEy4ausrr0w1WsPJLlEZPMJ QNS0z+C4+EnNEiIR1181Q7XAyP4JhjIt1NTiKgERqauVAa4lpXpgPV9ldabJZvqCHJ+c R0Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ARI/pAXuozIsa/5PtEK9I/KIIipzW+PxI1+kaLb328A=; b=dxgoxyjmaOKN8xIuFaNq9dxXcbl2UJMqtzpMk4JTYludMDHI/MreAvA1Mtu5taNf4s DgWByHpLEOQ/wFr4GbLEpbCXlgjU3Dh03nT/HEhb9GrGhWSSvjqIK110ZcMgQQ96qdIo noT3+Urnrkmu3silVqYOAvhRlqrnGDGLMGUXQqCCkSnChtwFLr1y2wGZVsvN7Af7c9Nv Io92iaQPSkq9dnSxjOvcAcg/SaRjXZjz+nwrhgLZ9kcKJIiPzlzcFmnHyT0IpBJpn8Sa y1pW1KRCo8cyEZ5pdIyMvB6TouxQBl0uDBWOc4PPoJmjZtMiB3emPXcTR7BpYNneqoLM N//Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=H5CAv9Z+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb12-20020a1709076d8c00b0078d1faeb619si40432ejc.777.2022.11.23.21.16.13; Wed, 23 Nov 2022 21:16:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=H5CAv9Z+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229739AbiKXEZh (ORCPT + 88 others); Wed, 23 Nov 2022 23:25:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbiKXEZc (ORCPT ); Wed, 23 Nov 2022 23:25:32 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C73CEC9ABD for ; Wed, 23 Nov 2022 20:25:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ARI/pAXuozIsa/5PtEK9I/KIIipzW+PxI1+kaLb328A=; b=H5CAv9Z+wnZ7BI/YJrxryjfUU7 7QsrwnB7u9Q6yO4cSgpIr+fDqGaQucxq518AmWN4Bf6uFMS6itdqHHNgE/swvOg9WSPFmE2K+Ea8V VAXznQ20BSkS2GlGDhp3rhvvJOdUyUmwiBr4VnfOQzPdO4GXaOyLcFOgJseW+vO5K/601WEHOowKM b9UNOzc5DNCcolnwEzH397znXt+WPDDtEAa2URoA/hFfNyml03dQQyKwRcjkuRsolhSFae5Okx6oF PjJDdhCfUG4oFz+yAj0+DGS6RhB9ey4myZqe3GEJCJ+GrLUKdcvMeyf0Q2QMuz03gpJwICR9OSlPJ YPZ7Gc5g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oy3nh-008NCq-Ea; Thu, 24 Nov 2022 04:25:25 +0000 Date: Thu, 24 Nov 2022 04:25:25 +0000 From: Matthew Wilcox To: Jiasheng Jiang Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/vmalloc: Add check for KMEM_CACHE Message-ID: References: <20221124040226.17953-1-jiasheng@iscas.ac.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221124040226.17953-1-jiasheng@iscas.ac.cn> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 24, 2022 at 12:02:26PM +0800, Jiasheng Jiang wrote: > As KMEM_CACHE may return NULL pointer, it should > be better to check the return value in order to > avoid NULL pointer dereference in kmem_cache_zalloc. You've made the code more complex. And for what? If that call fails, the system will not boot under any circumstances. NAK this patch, and any more like it. > Fixes: 68ad4a330433 ("mm/vmalloc.c: keep track of free blocks for vmap allocation") > Signed-off-by: Jiasheng Jiang > --- > mm/vmalloc.c | 18 ++++++++++-------- > 1 file changed, 10 insertions(+), 8 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index ccaa461998f3..df3e59f614cc 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -2426,15 +2426,17 @@ void __init vmalloc_init(void) > } > > /* Import existing vmlist entries. */ > - for (tmp = vmlist; tmp; tmp = tmp->next) { > - va = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT); > - if (WARN_ON_ONCE(!va)) > - continue; > + if (!WARN_ON_ONCE(!vmap_area_cachep)) { > + for (tmp = vmlist; tmp; tmp = tmp->next) { > + va = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT); > + if (WARN_ON_ONCE(!va)) > + continue; > > - va->va_start = (unsigned long)tmp->addr; > - va->va_end = va->va_start + tmp->size; > - va->vm = tmp; > - insert_vmap_area(va, &vmap_area_root, &vmap_area_list); > + va->va_start = (unsigned long)tmp->addr; > + va->va_end = va->va_start + tmp->size; > + va->vm = tmp; > + insert_vmap_area(va, &vmap_area_root, &vmap_area_list); > + } > } > > /* > -- > 2.25.1 > >