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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 970D3C433FE for ; Tue, 2 Nov 2021 11:02:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 45A9960C41 for ; Tue, 2 Nov 2021 11:02:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 45A9960C41 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A075C6B00B9; Tue, 2 Nov 2021 07:02:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9912594000A; Tue, 2 Nov 2021 07:02:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80AFE940009; Tue, 2 Nov 2021 07:02:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0118.hostedemail.com [216.40.44.118]) by kanga.kvack.org (Postfix) with ESMTP id 6AE446B00B9 for ; Tue, 2 Nov 2021 07:02:05 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1CCD154735 for ; Tue, 2 Nov 2021 11:02:05 +0000 (UTC) X-FDA: 78763700610.27.C7FD3FC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 2EC175099FDA for ; Tue, 2 Nov 2021 11:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635850863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yPuvfc021Apc8nEN/ZWlC8IBwOSwrXQgsH2pNayQZNU=; b=X3VbyZ8HR5RoxC+yIXtdVM+UvYRXH+y4rV22oOxjwK/93gwE3SFDqKS/osPWn7zrnXqFT3 k6iXHIWMcN4n20fqs7IT+GBwhDHThcwfYSzibtrVhBb68L9kU6vcmBi3alA6GeLNxYsowb yT9KUddL7k++hM1QyqNI1WW446Yj22k= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-141-cmhZPYf7O6qUZet9FpXtUQ-1; Tue, 02 Nov 2021 07:01:00 -0400 X-MC-Unique: cmhZPYf7O6qUZet9FpXtUQ-1 Received: by mail-wm1-f71.google.com with SMTP id m13-20020a05600c3b0d00b00332f48bef41so713039wms.7 for ; Tue, 02 Nov 2021 04:01:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=yPuvfc021Apc8nEN/ZWlC8IBwOSwrXQgsH2pNayQZNU=; b=uQ+eCg1ax9hWsV5yH6XhjvsM322c/ssP63b0rfhP3Ypn5Eo8tGcU5vIKUstwmziJy+ xsZDeapk2i2Fw4NIEjhYSV8YOEeZD4qJAmomjsWd+gBPjrvqqg5DtSWWwsquz7iQ6dDZ wq0gzvcotVKKFUz6haJpWb/c2mlyprvr6YZXiQP9mXimVjJuxgz/umi4Z3ZiO0TUMFc+ iXDM0Jfl2GaLtSXlKT/UOEG8Hgu4R+cNYAW0mBsDDfQB1E8BDiCi3Dj27hf64WaP87SO XceYzmOe8KzqndFFGLNvQIrbZJYD+Obn1ytSgMfbz3xpqr8e3BJBU2IxOKR/yiNDEJWG Rt+w== X-Gm-Message-State: AOAM533S1Gc2ZSNMhLyEnTeUtb6wNI1m0fIp4FVGcYdq+Xt7H2Y43rWW SUclC/4huqTb+CPjThGbzN4Yllpmrg1Zevk+iUkzHJBs25KUXau59D3TQKyctdE2lDvpwLvYK1A SAtp22NUCxus= X-Received: by 2002:a05:600c:210d:: with SMTP id u13mr5946515wml.82.1635850858974; Tue, 02 Nov 2021 04:00:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCOtg2Gm13Yy+uIpzsEFzMnGdZBMoaq+xd83sWDYqRGCHbXXbMnnvj3csbxCrlKqVyco3Eyw== X-Received: by 2002:a05:600c:210d:: with SMTP id u13mr5946483wml.82.1635850858716; Tue, 02 Nov 2021 04:00:58 -0700 (PDT) Received: from [192.168.3.132] (p5b0c6810.dip0.t-ipconnect.de. [91.12.104.16]) by smtp.gmail.com with ESMTPSA id m36sm964644wms.25.2021.11.02.04.00.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Nov 2021 04:00:58 -0700 (PDT) Message-ID: Date: Tue, 2 Nov 2021 12:00:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 To: Alexey Makhalov Cc: Michal Hocko , "linux-mm@kvack.org" , Andrew Morton , "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" , Oscar Salvador References: <20211101201312.11589-1-amakhalov@vmware.com> <7136c959-63ff-b866-b8e4-f311e0454492@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH] mm: fix panic in __alloc_pages In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2EC175099FDA Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=X3VbyZ8H; spf=none (imf05.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: j9afhxdz3ebdx8yf8nwp4gsfxzwoj3a3 X-HE-Tag: 1635850848-897465 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 02.11.21 11:34, Alexey Makhalov wrote: >=20 >>>>> In add_memory_resource() we hotplug the new node if required and se= t it >>>>> online. Memory might get onlined later, via online_pages(). >>>> >>>> You are correct. In case of memory hot add, it is true. But in case = of adding >>>> CPU with memoryless node, try_node_online() will be called only duri= ng CPU >>>> onlining, see cpu_up(). >>>> >>>> Is there any reason why try_online_node() resides in cpu_up() and no= t in add_cpu()? >>>> I think it would be correct to online node during the CPU hot add to= align with >>>> memory hot add. >>> >>> I am not familiar with cpu hotplug, but this doesn't seem to be anyth= ing >>> new so how come this became problem only now? >> >> So IIUC, the issue is that we have a node >> >> a) That has no memory >> b) That is offline >> >> This node will get onlined when onlining the CPU as Alexey says. Yet w= e >> have some code that stumbles over the node and goes ahead trying to us= e >> the pgdat -- that code is broken. >=20 > You are correct. >=20 >> >> >> If we take a look at build_zonelists() we indeed skip any >> !node_online(node). Any other code should do the same. If the node is >> not online, it shall be ignored because we might not even have a pgdat >> yet -- see hotadd_new_pgdat(). Without node_online(), the pgdat might = be >> stale or non-existant. >=20 > Agree, alloc_pages_node() should also do the same. Not exactly to skip = the node, > but to fallback to another node if !node_online(node). > alloc_pages_node() can also be hit while onlining the node, creating ch= icken-egg > problem, see below Right, the issue is also a bit involved when calling alloc_pages_node() on an offline NID. See below. >=20 >> >> >> The node onlining logic when onlining a CPU sounds bogus as well: Let'= s >> take a look at try_offline_node(). It checks that: >> 1) That no memory is *present* >> 2) That no CPU is *present* >> >> We should online the node when adding the CPU ("present"), not when >> onlining the CPU. >=20 > Possible. > Assuming try_online_node was moved under add_cpu(), let=E2=80=99s > take look on this call stack: > add_cpu() > try_online_node() > __try_online_node() > hotadd_new_pgdat() > At line 1190 we'll have a problem: > 1183 pgdat =3D NODE_DATA(nid); > 1184 if (!pgdat) { > 1185 pgdat =3D arch_alloc_nodedata(nid); > 1186 if (!pgdat) > 1187 return NULL; > 1188 > 1189 pgdat->per_cpu_nodestats =3D > 1190 alloc_percpu(struct per_cpu_nodestat); > 1191 arch_refresh_nodedata(nid, pgdat); >=20 > alloc_percpu() will go for all possible CPUs and will eventually end up > calling alloc_pages_node() trying to use subject nid for corresponding = CPU > hitting the same state #2 problem as NODE_DATA(nid) is still NULL and n= id > is not yet online. Right, we will end up calling pcpu_alloc_pages()->alloc_pages_node() for each possible CPU. We use cpu_to_node() to come up with the NID. I can only assume that we usually don't get an offline NID for an offline CPU, but instead either NODE=3D0 or NODE=3DNUMA_NO_NODE, because = ... alloc_pages_node()->__alloc_pages_node() will: VM_WARN_ON((gfp_mask & __GFP_THISNODE) && !node_online(nid)); BUT: prepare_alloc_pages() ac->zonelist =3D node_zonelist(preferred_nid, gfp_mask); should similarly fail. when de-referencing NULL. --=20 Thanks, David / dhildenb