From: Haifeng Xu <haifeng.xu@shopee.com>
To: Michal Hocko <mhocko@suse.com>
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()
Date: Fri, 16 Jun 2023 16:47:17 +0800 [thread overview]
Message-ID: <69cea432-f784-a734-f93e-50b0f897767c@shopee.com> (raw)
In-Reply-To: <ZIrLLmb+o77Wy2sY@dhcp22.suse.cz>
On 2023/6/15 16:26, Michal Hocko wrote:
> 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?
>
The memory request is too small and It's unlikely to fail during early init.
If it fails, I think the system won't work.
> Is this patch motivated by a code reading or is there any actual
> practical upside of handling the error here?
>
There is no real world problem, just from code review.
>> Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
>> ---
>> 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
>
prev parent reply other threads:[~2023-06-16 8:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-15 7:32 Haifeng Xu
2023-06-15 8:26 ` Michal Hocko
2023-06-16 8:47 ` Haifeng Xu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=69cea432-f784-a734-f93e-50b0f897767c@shopee.com \
--to=haifeng.xu@shopee.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeelb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox