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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A0B2C38145 for ; Wed, 7 Sep 2022 10:26:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAAD46B0072; Wed, 7 Sep 2022 06:26:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5A476B0073; Wed, 7 Sep 2022 06:26:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B22BF8D0001; Wed, 7 Sep 2022 06:26:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A345E6B0072 for ; Wed, 7 Sep 2022 06:26:23 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7F8FE1411D4 for ; Wed, 7 Sep 2022 10:26:23 +0000 (UTC) X-FDA: 79884909846.21.7DE37B7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 1ECC11C0099 for ; Wed, 7 Sep 2022 10:26:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662546382; 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=yLtK9gADFIOZKUnl5o7hTp+qHtdv+VdMxXkdfcFgn6E=; b=LNSfHZdQmoQSwnPLKAG0SUFDuVRui1sLA+AiX+W6II9QCpMs4uvt7P7/9vciRVlSTJqj+U YuFQXZEiWgC7QTIwFQ9dGqe/6A31/VH778yj6Hb3vSOaVsf9FbwOqppWA7gkRVNZNAQg4L mB7Q2X/qkMqSfBa+LQW2Hjk2TADLxPA= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-237-SOxKxrZJPFmaQL31UVMB6g-1; Wed, 07 Sep 2022 06:26:21 -0400 X-MC-Unique: SOxKxrZJPFmaQL31UVMB6g-1 Received: by mail-wm1-f71.google.com with SMTP id r83-20020a1c4456000000b003a7b679981cso10048392wma.6 for ; Wed, 07 Sep 2022 03:26:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date; bh=yLtK9gADFIOZKUnl5o7hTp+qHtdv+VdMxXkdfcFgn6E=; b=epbIEYhKGZEBVjY2zVYo3PftG5vpJvEklw9CtHMoBngOBQYlU9Wzp4N9rCoVAIgGts VpOp6afLjRHT2SzjnXaAIibkMLcW7wCnCbmvYmO7QPVHKDiz2xZ40ihlP85qiUnVtX3b G6nXRuGOWzQhYloJoMbqr4JB6vQ/9DAn6E5YcEexMaN1VBvKVthOInzqJVaBhtX7jmkQ Fy+tZFbnuxOUAon2l5FpJQp7OH+bfxP4iQIf5Ffst/OhHUFcbp/jJnW5goGsQ5zlJv4u y5fSeWjgcJ7QHlN+0K/vB3BKnFkCMF7VCg3qy1oQTimbR61n6i/45NjvFbUNFcjwLDA9 tC6A== X-Gm-Message-State: ACgBeo1n2ThZD7n94N3nn3pT5/rnGGXQd6q+IKNa34Yzs9izucQTMhuf ZIj5sfI+/RdhK6tOpjtUtAmLUxC2oLB8QjXry6+58rcNaiIcNJ8U77rZaOmVlmyHY2fsnJcjKIm nmU7+vOsryec= X-Received: by 2002:a05:600c:254:b0:3a5:a401:a1e2 with SMTP id 20-20020a05600c025400b003a5a401a1e2mr15623455wmj.14.1662546380415; Wed, 07 Sep 2022 03:26:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR7JKP3JEHlr+dcJH5V4WWPmkb7q0POiQM1BaK0zAngS6oDZCqT29wa/+teKrmYb94LK4A5Tpw== X-Received: by 2002:a05:600c:254:b0:3a5:a401:a1e2 with SMTP id 20-20020a05600c025400b003a5a401a1e2mr15623435wmj.14.1662546380096; Wed, 07 Sep 2022 03:26:20 -0700 (PDT) Received: from ?IPV6:2003:d8:2f0d:ba00:c951:31d7:b2b0:8ba0? (p200300d82f0dba00c95131d7b2b08ba0.dip0.t-ipconnect.de. [2003:d8:2f0d:ba00:c951:31d7:b2b0:8ba0]) by smtp.gmail.com with ESMTPSA id l6-20020a05600c4f0600b003a3170a7af9sm20032954wmq.4.2022.09.07.03.26.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Sep 2022 03:26:19 -0700 (PDT) Message-ID: Date: Wed, 7 Sep 2022 12:26:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [BUG report] kernel NULL pointer dereference in split_huge_page with offlined memory block From: David Hildenbrand To: Naoya Horiguchi , linux-mm@kvack.org Cc: Andrew Morton , Muchun Song , Miaohe Lin , Matthew Wilcox , Michal Hocko , Yang Shi , Naoya Horiguchi References: <20220907100855.GA2894785@ik1-406-35019.vs.sakura.ne.jp> <1481ce19-0a64-d1dc-4d89-4db71d6f7eb3@redhat.com> Organization: Red Hat In-Reply-To: <1481ce19-0a64-d1dc-4d89-4db71d6f7eb3@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662546383; h=from:from:sender: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:dkim-signature; bh=yLtK9gADFIOZKUnl5o7hTp+qHtdv+VdMxXkdfcFgn6E=; b=o3SsPk0q9hujHwoohf6yEe8MjRQt9IWnxss1RyxQmacD7BeLtINv3Phj60O6xUBsNa7DjQ jY/IlYH9VSxcCNMT6WL6uMspuCSDS9VoOApCufDtrPANwMRw74rb/W+AGP8bqE1ELd/M2Z lOfaXo9faxkvZrA0Noo2x0KcVXcgNTY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LNSfHZdQ; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662546383; a=rsa-sha256; cv=none; b=3JBe4wQnXRbSbP4WRoxJX0JxDB/tMAGa9StS+ngiWUkuY2dTnJhypqRWg+cYwoPdG1v8AP YpVEIT5K6N6TlcifCK/VZatpVQXhhmtMxJ3DupEB+UPddch9gwSyftk83v25BSW03FYef4 q432smuAL/497gRJoYgBM2Mk81TsGNc= X-Stat-Signature: 4ay6yuhtxwu8jh6yyuke63dihbtdnf1i X-Rspamd-Queue-Id: 1ECC11C0099 X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LNSfHZdQ; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam09 X-HE-Tag: 1662546382-733236 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 07.09.22 12:23, David Hildenbrand wrote: > On 07.09.22 12:08, Naoya Horiguchi wrote: >> Hi MM folks, > > Hi, > >> >> When I'm testing memory hotremove with various settings, I found the following >> NULL-pointer dereference. It reproduces easily with the folloing steps: >> >> $ echo offline > /sys/devices/system/memory/memoryN/state >> $ echo 1 > /sys/kernel/debug/split_huge_pages >> > > That's weird, I don't immediately see how both features are related here, especially because it seems to fail quite early in split_huge_pages_write(). > > I was able to trigger it here as well, though, and I get on my kernel with debug options enabled: > > [526045.808737] page:00000000467f4890 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x121c000 > [526045.818306] flags: 0x17fffc00000000(node=0|zone=2|lastcpupid=0x1ffff) > [526045.824842] raw: 0017fffc00000000 0000000000000000 dead000000000122 0000000000000000 > [526045.832676] raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000 > [526045.840498] page dumped because: unmovable page > [526056.362715] page:000000007d7ab72e is uninitialized and poisoned > [526056.362720] page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) > [526056.374837] ------------[ cut here ]------------ > [526056.379544] kernel BUG at include/linux/mm.h:1248! > [526056.384429] invalid opcode: 0000 [#1] PREEMPT SMP PTI > [526056.389570] CPU: 16 PID: 20964 Comm: bash Tainted: G I 6.0.0-rc3-foll-numa+ #41 > [526056.398347] Hardware name: Dell Inc. PowerEdge R740/0923K0, BIOS 2.11.2 004/21/2021 > [526056.406087] RIP: 0010:split_huge_pages_write+0xcf4/0xe30 > [526056.411495] Code: f9 ff ff 48 c7 c6 88 8e 4e a7 48 c7 c7 f8 0b a8 a7 e8 20 1c 3d 00 e9 54 f6 ff ff 48 c7 c6 38 06 4c a7 4c 89 e7 e8 5c 4a f7 ff <0f> 0b 48 8b 7c 24 08 be 02 00 00 00 e8 bb 6c 36 00 e9 11 f5 ff ff > [526056.430325] RSP: 0018:ffffae50e757fb40 EFLAGS: 00010292 > [526056.435639] RAX: 0000000000000034 RBX: 0000000002d00000 RCX: 0000000000000000 > [526056.442858] RDX: 0000000000000001 RSI: ffffffffa751a839 RDI: 00000000ffffffff > [526056.450077] RBP: 0000000000013937 R08: 0000000000000000 R09: ffffae50e757fa08 > [526056.457296] R10: 0000000000000003 R11: ffffffffa793c768 R12: fffff00eb4000000 > [526056.464514] R13: ffffae50e757fb7a R14: 000fffffffffffff R15: fffff00eb4000000 > [526056.471733] FS: 00007fe35addf740(0000) GS:ffff8b71dc000000(0000) knlGS:0000000000000000 > [526056.479906] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > [526056.485738] CR2: 000055e87e606358 CR3: 00000004f5b46004 CR4: 00000000007706e0 > [526056.492957] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > [526056.500176] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > [526056.507396] PKRU: 55555554 > [526056.510196] Call Trace: > [526056.512734] > [526056.514929] ? simple_setattr+0x40/0x60 > [526056.518859] ? vfs_mkobj+0x1b0/0x1c0 > [526056.522529] ? path_openat+0xb2e/0x1360 > [526056.526456] ? do_filp_open+0xa1/0x130 > [526056.530296] full_proxy_write+0x50/0x80 > [526056.534229] vfs_write+0xd7/0x3e0 > [526056.537635] ? fpregs_assert_state_consistent+0x22/0x50 > [526056.542955] ? exit_to_user_mode_prepare+0x3c/0x1d0 > [526056.547929] ? syscall_exit_to_user_mode+0x17/0x40 > [526056.552808] ksys_write+0x53/0xd0 > [526056.556215] do_syscall_64+0x58/0x80 > [526056.559879] ? exit_to_user_mode_prepare+0x3c/0x1d0 > [526056.564846] ? syscall_exit_to_user_mode+0x17/0x40 > [526056.569726] ? do_syscall_64+0x67/0x80 > [526056.573563] ? do_syscall_64+0x67/0x80 > [526056.577404] ? do_syscall_64+0x67/0x80 > [526056.581244] ? syscall_exit_to_user_mode+0x17/0x40 > [526056.586120] ? do_syscall_64+0x67/0x80 > [526056.589961] ? do_syscall_64+0x67/0x80 > [526056.593801] ? do_syscall_64+0x67/0x80 > [526056.597641] entry_SYSCALL_64_after_hwframe+0x63/0xcd > [526056.602779] RIP: 0033:0x7fe35ab01c17 > [526056.606446] Code: 0f 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b7 0f 1f 00 f3 0f 1e fa 64 8b 04 25 18 00 00 00 85 c0 75 10 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 51 c3 48 83 ec 28 48 89 54 24 18 48 89 74 24 > [526056.625277] RSP: 002b:00007ffc1863c8d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 > [526056.632929] RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007fe35ab01c17 > [526056.640147] RDX: 0000000000000002 RSI: 000055e87e7009a0 RDI: 0000000000000001 > [526056.647366] RBP: 000055e87e7009a0 R08: 0000000000000000 R09: 0000000000000073 > [526056.654586] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000002 > [526056.661805] R13: 00007fe35abf8780 R14: 0000000000000002 R15: 00007fe35abf39e0 > [526056.669028] > > > Looks like there is a page_to_nid() done in an offline memmap, which is wrong. > > Usually, this indicates that a pfn_to_online_page() is missing in a PFN walker. > And indeed, something like the following might do the trick: diff --git a/mm/huge_memory.c b/mm/huge_memory.c index e9414ee57c5b..f42bb51e023a 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2894,11 +2894,9 @@ static void split_huge_pages_all(void) max_zone_pfn = zone_end_pfn(zone); for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++) { int nr_pages; - if (!pfn_valid(pfn)) - continue; - page = pfn_to_page(pfn); - if (!get_page_unless_zero(page)) + page = pfn_to_online_page(pfn); + if (!page || !get_page_unless_zero(page)) continue; if (zone != page_zone(page)) -- Thanks, David / dhildenb