From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27ABDEB64DC for ; Thu, 15 Jun 2023 08:26:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240435AbjFOI00 (ORCPT ); Thu, 15 Jun 2023 04:26:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231288AbjFOI0Y (ORCPT ); Thu, 15 Jun 2023 04:26:24 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2CDE1A3; Thu, 15 Jun 2023 01:26:23 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8080D223EB; Thu, 15 Jun 2023 08:26:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1686817582; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kF+hByK4Y76JqlJkiSCw3idVqJKv+Bhlb9OYXECSA6o=; b=Oi4Rr4D7LwzZKXtZXhTOqPefALupc8O9w/CwxHH5AgGPnY3ErZvy9xW+Ziw24qxE8SdmYh FXRzzAYYdOOuSL3vasWHumh5F/H9BINWWmQKBiaMYzbqAxtmLNhgW2CVeBAFivdKknMnRb UnCzHpZFD3YrqLYxeUYH3gDniCrGbJg= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 74A8413467; Thu, 15 Jun 2023 08:26:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +Fb0Gy7LimT7LwAAMHmgww (envelope-from ); Thu, 15 Jun 2023 08:26:22 +0000 Date: Thu, 15 Jun 2023 10:26:22 +0200 From: Michal Hocko To: Haifeng Xu Cc: roman.gushchin@linux.dev, hannes@cmpxchg.org, shakeelb@google.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] mm/memcontrol: add check for allocation failure in mem_cgroup_init() Message-ID: References: <20230615073226.1343-2-haifeng.xu@shopee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230615073226.1343-2-haifeng.xu@shopee.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 15-06-23 07:32:26, Haifeng Xu wrote: > If mem_cgroup_init() fails to allocate mem_cgroup_tree_per_node, we > should not try to initilaize it. Add check for this case to avoid > potential NULL pointer dereference. Technically yes and it seems that all users of soft_limit_tree.rb_tree_per_node correctly check for NULL so this would be graceful failure handling. At least superficially because the feature itself would be semi-broken when used. But more practically this is a 24B allocation and if we fail to allocate that early during the boot we are screwed anyway. Would such a system have any chance to boot all the way to userspace? Woul any userspace actually work? Is this patch motivated by a code reading or is there any actual practical upside of handling the error here? > Signed-off-by: Haifeng Xu > --- > mm/memcontrol.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index c73c5fb33f65..7ebf64e48b25 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -7422,6 +7422,8 @@ static int __init mem_cgroup_init(void) > struct mem_cgroup_tree_per_node *rtpn; > > rtpn = kzalloc_node(sizeof(*rtpn), GFP_KERNEL, node); > + if (!rtpn) > + continue; > > rtpn->rb_root = RB_ROOT; > rtpn->rb_rightmost = NULL; > -- > 2.25.1 -- Michal Hocko SUSE Labs