From patchwork Tue Jan 22 15:44:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10775831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B38713B4 for ; Tue, 22 Jan 2019 15:44:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 290BF26E75 for ; Tue, 22 Jan 2019 15:44:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D5DB2B109; Tue, 22 Jan 2019 15:44:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C97292B0E5 for ; Tue, 22 Jan 2019 15:44:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B78238E0003; Tue, 22 Jan 2019 10:44:20 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AFF1E8E0001; Tue, 22 Jan 2019 10:44:20 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A0368E0003; Tue, 22 Jan 2019 10:44:20 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id 3C84B8E0001 for ; Tue, 22 Jan 2019 10:44:20 -0500 (EST) Received: by mail-ed1-f72.google.com with SMTP id d41so9371561eda.12 for ; Tue, 22 Jan 2019 07:44:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=MuttZfh+QqK6gLCXIDbKC1NM24wpux4b27LtXRtFzvE=; b=YrgQuS77ZNg8u1ba1QsxemUppBBk/MIJlgghxO/+hz4adI5zirt6gFSljU+L1SziUF tqJCLtzn8qkwJ3CRPpSKeqow4hhJC8fSV9+PERUS5Etl9w86/AVIaPbuW0T9u2MnJD/L EffcpvEtxOOREeLnw2LLCWWWdGLda7pLrV2gZXe+1EHXmQJHG89qEUlBTcMUM9LznBUg wi03Xfyp92CkptYqXGtNhq4OLwtcb5/nNLmVJBz7Wlo0L3aocT0PrPk9WLepxHBPXgRT 2yQBFkm3B5qtylE+OGIrEGVTf4PCMcvFA35I3Wdb89+UZXrvywJqNKQpsFLbwyzD+hM4 eTBQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Gm-Message-State: AJcUukdZnw+PKZtYF2DxNgqR7iVblT1HNtApL50EXo7hk1hahGL9UCxx brgjLYUJs3A+MW36ubh8QjYy37l96FMrrLH/bBtglcJ3dHxUN933XAtPT/kgy9i0lPFb6orZu6B XNfELDiacjQ4c5vKXh9xPcVjIAtTH+cnYDb64KKi1bLYtwZcWHQDbzkZsh1NAM0x2Rg== X-Received: by 2002:a50:f415:: with SMTP id r21mr31796713edm.110.1548171859663; Tue, 22 Jan 2019 07:44:19 -0800 (PST) X-Google-Smtp-Source: ALg8bN4G8LZn/tZKlvNOMt4B1ZEaZ2U7Mh8v183x1CXACPKhKLt54cEGJPwSiHbNAh+jpQuFZn7D X-Received: by 2002:a50:f415:: with SMTP id r21mr31796623edm.110.1548171857982; Tue, 22 Jan 2019 07:44:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548171857; cv=none; d=google.com; s=arc-20160816; b=qeXnO/HkhZK8H1YrAyUulvvQAm2JDPM2RwDj1KUP2G9qSH+lfcvB8tStfnkyfIE7kr IhjsOKYW/qoWNLXendY9D107w04+9U2COWPEqOrVydSBU7nUJkNNGCBOZgg/OpN0e7VP /UK8y4eGQHOY5481ju9tw9pU2QE+XQD9lfLLM3GNjsZwZh/jI8xIM/iLgnqXW3oGUGPv tArgRWKhiFb+AvkkeoFQa2MX3pZizp2txtSvC5dsoE2uZxbqKzPVKKoM70fr6u+b2dCj E9xln8xCNTXbtyJG69KEXj9WVH/+vyyc+YmtOMvyhgnKvqVypZHavrtm6/eHZDKMZKet E7TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=MuttZfh+QqK6gLCXIDbKC1NM24wpux4b27LtXRtFzvE=; b=SzW+s3wu0ydpm8BBek6ScKXeomIAQGKLifIwR7rRNkBKDuQjVvpDXGWuMQkRdfIsof wduJ4vs1i58qzXJ2OtA8pZvBMY67oek79nvvYJfKyNsXJY7pRzwSwdUakQ4y43eqXTUn DMfq4kXlrseIdIyQVHnFUXHyQ2GBSQPicCLcj5WEkHZoLAwpwkRR+1hSzjYAw3WbtDWX 7ybPnoDnjfY4VfCVSQwnmH/NPzBgLcjpIG74cpK6e19V9LCb+QqUdGc7+ItbaKjL2lXM v97IcKa4FeLw9EutI9+QyunYnTrpAnonIWdIXsSloU1uXXJZdJgNxK9jP49rzFdh2TDi rHQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from smtp.nue.novell.com (smtp.nue.novell.com. [195.135.221.5]) by mx.google.com with ESMTPS id i55si721651eda.23.2019.01.22.07.44.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 07:44:17 -0800 (PST) Received-SPF: pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) client-ip=195.135.221.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@suse.de designates 195.135.221.5 as permitted sender) smtp.mailfrom=osalvador@suse.de Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 22 Jan 2019 16:44:17 +0100 Received: from d104.suse.de (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (NOT encrypted); Tue, 22 Jan 2019 15:44:13 +0000 From: Oscar Salvador To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, mhocko@suse.com, david@redhat.com, Oscar Salvador Subject: [PATCH] mm,memory_hotplug: Fix scan_movable_pages for gigantic hugepages Date: Tue, 22 Jan 2019 16:44:07 +0100 Message-Id: <20190122154407.18417-1-osalvador@suse.de> X-Mailer: git-send-email 2.13.7 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: X-Virus-Scanned: ClamAV using ClamSMTP This is the same sort of error we saw in [1]. Gigantic hugepages crosses several memblocks, so it can be that the page we get in scan_movable_pages() is a page-tail belonging to a 1G-hugepage. If that happens, page_hstate()->size_to_hstate() will return NULL, and we will blow up in hugepage_migration_supported(). The splat is as follows: kernel: BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 kernel: #PF error: [normal kernel read fault] kernel: PGD 0 P4D 0 kernel: Oops: 0000 [#1] SMP PTI kernel: CPU: 1 PID: 1350 Comm: bash Tainted: G E 5.0.0-rc1-mm1-1-default+ #27 kernel: Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014 kernel: RIP: 0010:__offline_pages+0x6ae/0x900 kernel: Code: 48 c7 c6 d0 3e a4 81 e8 44 c8 ad ff 49 8b 04 24 bf 00 10 00 00 a9 00 00 01 00 74 09 41 0f b6 4c 24 51 48 d3 e7 e8 42 2a c1 ff <8b> 40 08 83 f8 09 0f 84 b0 fc ff ff 83 f8 12 0f 84 a7 fc ff ff 83 kernel: RSP: 0018:ffffc900008e3d20 EFLAGS: 00010246 kernel: RAX: 0000000000000000 RBX: ffffea0000000000 RCX: 0000000000000009 kernel: RDX: ffffffff825c64f0 RSI: 0000000000001000 RDI: 0000000000001000 kernel: RBP: ffffc900008e3d68 R08: 0000000000200000 R09: 00000000000001e4 kernel: R10: 0000000000000058 R11: ffffffff8254a854 R12: ffffea0004200000 kernel: R13: 0000000000108000 R14: 0000000000110000 R15: 0000000000000000 kernel: FS: 00007ff172339b80(0000) GS:ffff88803eb00000(0000) knlGS:0000000000000000 kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 kernel: CR2: 0000000000000008 CR3: 0000000038d78006 CR4: 00000000003606a0 kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 kernel: Call Trace: kernel: ? klist_next+0x79/0xe0 kernel: memory_subsys_offline+0x42/0x60 kernel: device_offline+0x80/0xa0 kernel: state_store+0xab/0xc0 kernel: kernfs_fop_write+0x102/0x180 kernel: __vfs_write+0x26/0x190 kernel: ? set_close_on_exec+0x49/0x70 kernel: vfs_write+0xad/0x1b0 kernel: ksys_write+0x42/0x90 kernel: do_syscall_64+0x5b/0x180 kernel: entry_SYSCALL_64_after_hwframe+0x44/0xa9 kernel: RIP: 0033:0x7ff1719febe4 kernel: Code: 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b7 0f 1f 80 00 00 00 00 8b 05 4a fc 2c 00 48 63 ff 85 c0 75 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 f3 c3 66 90 55 53 48 89 d5 48 89 f3 48 83 kernel: RSP: 002b:00007ffd50b7ddc8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 kernel: RAX: ffffffffffffffda RBX: 0000000000000008 RCX: 00007ff1719febe4 kernel: RDX: 0000000000000008 RSI: 00005556e9216b20 RDI: 0000000000000001 kernel: RBP: 00005556e9216b20 R08: 000000000000000a R09: 0000000000000000 kernel: R10: 000000000000000a R11: 0000000000000246 R12: 0000000000000008 kernel: R13: 0000000000000001 R14: 00007ff171cca720 R15: 0000000000000008 kernel: Modules linked in: af_packet(E) xt_tcpudp(E) ipt_REJECT(E) xt_conntrack(E) nf_conntrack(E) nf_defrag_ipv4(E) ip_set(E) nfnetlink(E) ebtable_nat(E) ebtable_broute(E) bridge(E) stp(E) llc(E) iptable_mangle(E) iptable_raw(E) iptable_security(E) ebtable_filter(E) ebtables(E) iptable_filter(E) ip_tables(E) x_tables(E) kvm_intel(E) kvm(E) irqbypass(E) crct10dif_pclmul(E) crc32_pclmul(E) ghash_clmulni_intel(E) bochs_drm(E) ttm(E) aesni_intel(E) drm_kms_helper(E) aes_x86_64(E) crypto_simd(E) cryptd(E) glue_helper(E) drm(E) virtio_net(E) syscopyarea(E) sysfillrect(E) net_failover(E) sysimgblt(E) pcspkr(E) failover(E) i2c_piix4(E) fb_sys_fops(E) parport_pc(E) parport(E) button(E) btrfs(E) libcrc32c(E) xor(E) zstd_decompress(E) zstd_compress(E) xxhash(E) raid6_pq(E) sd_mod(E) ata_generic(E) ata_piix(E) ahci(E) libahci(E) libata(E) crc32c_intel(E) serio_raw(E) virtio_pci(E) virtio_ring(E) virtio(E) sg(E) scsi_mod(E) autofs4(E) kernel: CR2: 0000000000000008 kernel: ---[ end trace bdb71590872849fb ]--- kernel: RIP: 0010:__offline_pages+0x6ae/0x900 kernel: Code: 48 c7 c6 d0 3e a4 81 e8 44 c8 ad ff 49 8b 04 24 bf 00 10 00 00 a9 00 00 01 00 74 09 41 0f b6 4c 24 51 48 d3 e7 e8 42 2a c1 ff <8b> 40 08 83 f8 09 0f 84 b0 fc ff ff 83 f8 12 0f 84 a7 fc ff ff 83 kernel: RSP: 0018:ffffc900008e3d20 EFLAGS: 00010246 kernel: RAX: 0000000000000000 RBX: ffffea0000000000 RCX: 0000000000000009 kernel: RDX: ffffffff825c64f0 RSI: 0000000000001000 RDI: 0000000000001000 kernel: RBP: ffffc900008e3d68 R08: 0000000000200000 R09: 00000000000001e4 kernel: R10: 0000000000000058 R11: ffffffff8254a854 R12: ffffea0004200000 kernel: R13: 0000000000108000 R14: 0000000000110000 R15: 0000000000000000 kernel: FS: 00007ff172339b80(0000) GS:ffff88803eb00000(0000) knlGS:0000000000000000 kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 kernel: CR2: 0000000000000008 CR3: 0000000038d78006 CR4: 00000000003606a0 kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Fix this by getting the head page and testing against it. [1] https://patchwork.kernel.org/patch/10739963/ Signed-off-by: Oscar Salvador Reviewed-by: Anthony Yznaga Acked-by: Michal Hocko Reviewed-by: David Hildenbrand Signed-off-by: Andrew Morton --- mm/memory_hotplug.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index ec22c86d9f89..25aee4f04a72 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1335,12 +1335,17 @@ static unsigned long scan_movable_pages(unsigned long start, unsigned long end) if (__PageMovable(page)) return pfn; if (PageHuge(page)) { - if (hugepage_migration_supported(page_hstate(page)) && - page_huge_active(page)) + struct page *head = compound_head(page); + + if (hugepage_migration_supported(page_hstate(head)) && + page_huge_active(head)) return pfn; - else - pfn = round_up(pfn + 1, - 1 << compound_order(page)) - 1; + else { + unsigned long skip; + + skip = (1 << compound_order(head)) - (page - head); + pfn += skip - 1; + } } } }