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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6870C2BB1D for ; Tue, 14 Apr 2020 23:58:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7DEB5206D9 for ; Tue, 14 Apr 2020 23:58:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7DEB5206D9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 07DFF8E0003; Tue, 14 Apr 2020 19:58:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 02EA28E0001; Tue, 14 Apr 2020 19:58:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E86AD8E0003; Tue, 14 Apr 2020 19:58:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id CDDF28E0001 for ; Tue, 14 Apr 2020 19:58:19 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 945068245571 for ; Tue, 14 Apr 2020 23:58:19 +0000 (UTC) X-FDA: 76708127118.24.hair16_65b8c4211a53b X-HE-Tag: hair16_65b8c4211a53b X-Filterd-Recvd-Size: 5704 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Apr 2020 23:58:18 +0000 (UTC) IronPort-SDR: PqvHT76kdck3ZGTzmqjOzXGpx+CN6a2rjSau7U4VJOuEgpJFX0s08RbcEK/BthP6Od5SPTNsX4 Wk8nrSpyl09g== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2020 16:58:17 -0700 IronPort-SDR: l0qAgHwbuOXV33ALd5qh72FLM5o0yf8G9M77cvY7XCrrZ9mTRRUtjnTgwOLQrCPB2gZmYCPSig KR8URPWVNhEQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,384,1580803200"; d="scan'208";a="453732307" Received: from vverma7-mobl4.lm.intel.com ([10.251.131.109]) by fmsmga005.fm.intel.com with ESMTP; 14 Apr 2020 16:58:17 -0700 From: Vishal Verma To: Cc: , Vishal Verma , David Hildenbrand , Dan Williams , Dave Hansen Subject: [PATCH v3] mm/memory_hotplug: refrain from adding memory into an impossible node Date: Tue, 14 Apr 2020 17:58:12 -0600 Message-Id: <20200414235812.6158-1-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 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: A misbehaving qemu created a situation where the ACPI SRAT table advertised one fewer proximity domains than intended. The NFIT table did describe all the expected proximity domains. This caused the device dax driver to assign an impossible target_node to the device, and when hotplugged as system memory, this would fail with the following signature: [ +0.001627] BUG: kernel NULL pointer dereference, address: 0000000000= 000088 [ +0.001331] #PF: supervisor read access in kernel mode [ +0.000975] #PF: error_code(0x0000) - not-present page [ +0.000976] PGD 80000001767d4067 P4D 80000001767d4067 PUD 10e0c4067 P= MD 0 [ +0.001338] Oops: 0000 [#1] SMP PTI [ +0.000676] CPU: 4 PID: 22737 Comm: kswapd3 Tainted: G O = 5.6.0-rc5 #9 [ +0.001457] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 [ +0.001990] RIP: 0010:prepare_kswapd_sleep+0x7c/0xc0 [ +0.000780] Code: 89 df e8 87 fd ff ff 89 c2 31 c0 84 d2 74 e6 0f 1f = 44 00 00 48 8b 05 fb af 7a 01 48 63 93 88 1d 01 00 48 = 8b 84 d0 20 0f 00 00 <48> 3b 98 88 00 00 00 75 28 f0 80 a0 80 00 00 00 fe f0 80 a3 38 20 [ +0.002877] RSP: 0018:ffffc900017a3e78 EFLAGS: 00010202 [ +0.000805] RAX: 0000000000000000 RBX: ffff8881209e0000 RCX: 00000000= 00000000 [ +0.001115] RDX: 0000000000000003 RSI: 0000000000000000 RDI: ffff8881= 209e0e80 [ +0.001098] RBP: 0000000000000000 R08: 0000000000000000 R09: 00000000= 00008000 [ +0.001092] R10: 0000000000000000 R11: 0000000000000003 R12: 00000000= 00000003 [ +0.001092] R13: 0000000000000003 R14: 0000000000000000 R15: ffffc900= 017a3ec8 [ +0.001091] FS: 0000000000000000(0000) GS:ffff888318c00000(0000) knl= GS:0000000000000000 [ +0.001275] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ +0.000882] CR2: 0000000000000088 CR3: 0000000120b50002 CR4: 00000000= 001606e0 [ +0.001095] Call Trace: [ +0.000388] kswapd+0x103/0x520 [ +0.000494] ? finish_wait+0x80/0x80 [ +0.000547] ? balance_pgdat+0x5a0/0x5a0 [ +0.000607] kthread+0x120/0x140 [ +0.000508] ? kthread_create_on_node+0x60/0x60 [ +0.000706] ret_from_fork+0x3a/0x50 Add a check in the add_memory path to ensure that the node to which we are adding memory is in the node_possible_map Cc: David Hildenbrand Cc: Dan Williams Cc: Dave Hansen Signed-off-by: Vishal Verma --- mm/memory_hotplug.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) v2: - Centralize the check in the add_memory path (David) - Instead of failing, add the memory to a nearby node, while warning (and tainting) to call out attention to the firmware bug (Dan) v3: - Fix the CONFIG_NUMA=3Dn case, and use node 0 as the final fallback (Dan= ) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 0a54ffac8c68..536a809d6ebb 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -980,6 +980,30 @@ static int check_hotplug_memory_range(u64 start, u64= size) return 0; } =20 +/* + * Check that the node provided for adding memory was valid. + * If not, find the nearest valid node and add the memory there while + * tainting the kernel and displaying a warning to bring attention to th= e + * underlying firmware problem. + * Return nid if valid, or an adjusted node number that can be used inst= ead + * if the original nid was not valid + */ +static int check_hotplug_node(int nid) +{ + int alt_nid; + + if (node_possible(nid)) + return nid; + + alt_nid =3D numa_map_to_online_node(nid); + if (alt_nid =3D=3D NUMA_NO_NODE) + alt_nid =3D first_online_node; + WARN_TAINT(1, TAINT_FIRMWARE_WORKAROUND, + "node %d expected, but was absent from the node_possible_map, using= %d instead\n", + nid, alt_nid); + return alt_nid; +} + static int online_memory_block(struct memory_block *mem, void *arg) { return device_online(&mem->dev); @@ -1005,6 +1029,10 @@ int __ref add_memory_resource(int nid, struct reso= urce *res) if (ret) return ret; =20 + nid =3D check_hotplug_node(nid); + if (nid < 0) + return -ENXIO; + mem_hotplug_begin(); =20 /* --=20 2.21.1