From patchwork Fri Jul 12 06:42:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 13731321 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 BBA8AC2BD09 for ; Fri, 12 Jul 2024 06:47:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F8806B0099; Fri, 12 Jul 2024 02:47:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A85F6B009A; Fri, 12 Jul 2024 02:47:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A16B6B009B; Fri, 12 Jul 2024 02:47:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1AF126B0099 for ; Fri, 12 Jul 2024 02:47:29 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C437114093A for ; Fri, 12 Jul 2024 06:47:28 +0000 (UTC) X-FDA: 82330169376.16.49FEA0F Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf28.hostedemail.com (Postfix) with ESMTP id 5AB63C000E for ; Fri, 12 Jul 2024 06:47:24 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720766829; 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: references; bh=Gz48Fs60JKJPmaEB6/CbHZ4uKd9HjRJSW8+UI/ZoGuo=; b=cVpmUtOTfaesM2XRcgFUQJGqqQELZxPb/NuQXW2hMYh377Wt5z0GXhP7ITd31z2CN5o2Dc JBLiR41JPo/2XXjk/KGJzFJdnwGQTFNeRlqodk3BE1kIMJF22GS6AirZ3F4WXGI89Tno5o XzUumTEf39cseI0YbGt6N3zVHk2u+2s= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720766829; a=rsa-sha256; cv=none; b=8j5YqQ2a5YnPnt31uivyzCDS78Q3Yk5MaiF+8KqQmMH3jm3J+M0QR3EADb3AQo9sNgP+MF LGtw7/uZaldg2mviAEjyej3nv6sSqfiXMnEEXSSOv53amwCs1T8mG0uXI+53DS6h1A/2xC lpojHnSRr7ohQRQwOydCDBI/tWbMqG0= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WL28W35mqzwX7S; Fri, 12 Jul 2024 14:42:35 +0800 (CST) Received: from kwepemd200019.china.huawei.com (unknown [7.221.188.193]) by mail.maildlp.com (Postfix) with ESMTPS id 8A2441403D1; Fri, 12 Jul 2024 14:47:20 +0800 (CST) Received: from huawei.com (10.173.127.72) by kwepemd200019.china.huawei.com (7.221.188.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 12 Jul 2024 14:47:19 +0800 From: Miaohe Lin To: CC: , , , Subject: [PATCH] mm/memory-failure: fix VM_BUG_ON_PAGE(PagePoisoned(page)) when unpoison memory Date: Fri, 12 Jul 2024 14:42:49 +0800 Message-ID: <20240712064249.3882707-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [10.173.127.72] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd200019.china.huawei.com (7.221.188.193) X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 5AB63C000E X-Stat-Signature: m7k6adoffcny435nom175qfkqwtqfsdp X-Rspam-User: X-HE-Tag: 1720766844-499002 X-HE-Meta: U2FsdGVkX18AovKyd2M6GSKl03tLFPwhLI1Y58k2YDpppt5iZc1oCsOmo6bpSweGW8amnm1WwNP1H+b/m2HbD5sXRwXHjKE+LCrpmh5hJeicPyVFtukiXO+ViPiCyINvIQcjthgAUxabYFMnrP9Eq0PZmjPjPk3ZzUxz2qZ41hMez7yAJ64rLwbEEw5CuMBkihC7UX6THuzRcuOZ9DSBInO1FETBUivVNrer67Ziu7A7AgcQ2oFwsITorUFLpx37298vQBfbo42+TWYh0Ql7yGzA4Uyx6PI7vvEP/0vU7u4zQxjJqKqGBGUqPwBHyLk81a8Blddlx9ge8oBPdtdfr/qB+0w5hm5yAHvv6UNIkUpIa05zlj2JEz0eMc/EXSYx5zAzp5eYQG+PWL3UCQeFTgMnHb8H1Si01Uz1OSJd6LDkU41HWLXq7UQ+3u/zDpGIDb0GCLi/zO3m9Hu2Kl5urHAp72pagE5TvaB6v0Mt2hjKk/ExePZdxFvF5c7AeZwyrw2DIVjKbXWbj3ElxqvT89/sy79NGUUYbIUI1nDjbrE4pP4TnjhsEofvhHAXmPDhSArFOhQXGaGd7b36iPgH+8iKdvD4xoqcMdL/qQAaj4g2ghEz61er6pNUH2cBuk2B2K7x+E7KaGKiPL4z//zET88eOIE5vLMxmvl4IJPZFSaJhwi3T69e9zsfzpVXnneU4+yrzyAOJritE41wPZ1WrD5Z47dxIQvKNcHm5b8Sbo+AqzHT0l6iKXwcPOH3q5cNUuUtQ82qXyOel/AiwzrTg2FayVVbzRP2cg6Kul8QxgmnnfWfhL3FdvZJoH5xjdfkDAQpohVQCXrtsXlfzhZICc6KvrJ4YdFV0DoE0hG9JQ8ef/huaoh6vmYT+HMuQ0VpuS7R4BOQcHeYjk0RGMUyIDM+xDVROkQE3Sz3Bfwk1cmLs65A5nlLQmfdEcUQGBEZiPZFtaR97KAGO2a1f3d SeVcrjoG cstFs31k8R3cfbgDfst5HeyCU8BDQrM6cAuUT2FSZXsa5ARDMDdJ41ol316zmD16H4w1xZHid4z43xgX2ep0FiI8d7M6CZILo78gzEjDJv6krp2YVQVdxGsOVBpDNeSFx7nJLu/Dgy6NfoEjXl/JN+AOzifEKuNHHLXTzWJuZt89Uro3lRGAziVhDGj2iwfPD/GwIoWlFNH8h73eR/SFCY8sz47Hfkg7222qMmaFh8YTN1gh5HzpBzMF1MFpc0RUDeapR4doo3Mm6sQ8= 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: List-Subscribe: List-Unsubscribe: When I did memory failure tests recently, below panic occurs: page dumped because: VM_BUG_ON_PAGE(PagePoisoned(page)) kernel BUG at include/linux/page-flags.h:616! Oops: invalid opcode: 0000 [#1] PREEMPT SMP NOPTI CPU: 3 PID: 720 Comm: bash Not tainted 6.10.0-rc1-00195-g148743902568 #40 RIP: 0010:unpoison_memory+0x2f3/0x590 RSP: 0018:ffffa57fc8787d60 EFLAGS: 00000246 RAX: 0000000000000037 RBX: 0000000000000009 RCX: ffff9be25fcdc9c8 RDX: 0000000000000000 RSI: 0000000000000027 RDI: ffff9be25fcdc9c0 RBP: 0000000000300000 R08: ffffffffb4956f88 R09: 0000000000009ffb R10: 0000000000000284 R11: ffffffffb4926fa0 R12: ffffe6b00c000000 R13: ffff9bdb453dfd00 R14: 0000000000000000 R15: fffffffffffffffe FS: 00007f08f04e4740(0000) GS:ffff9be25fcc0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000564787a30410 CR3: 000000010d4e2000 CR4: 00000000000006f0 Call Trace: unpoison_memory+0x2f3/0x590 simple_attr_write_xsigned.constprop.0.isra.0+0xb3/0x110 debugfs_attr_write+0x42/0x60 full_proxy_write+0x5b/0x80 vfs_write+0xd5/0x540 ksys_write+0x64/0xe0 do_syscall_64+0xb9/0x1d0 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f08f0314887 RSP: 002b:00007ffece710078 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 0000000000000009 RCX: 00007f08f0314887 RDX: 0000000000000009 RSI: 0000564787a30410 RDI: 0000000000000001 RBP: 0000564787a30410 R08: 000000000000fefe R09: 000000007fffffff R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000009 R13: 00007f08f041b780 R14: 00007f08f0417600 R15: 00007f08f0416a00 Modules linked in: hwpoison_inject ---[ end trace 0000000000000000 ]--- RIP: 0010:unpoison_memory+0x2f3/0x590 RSP: 0018:ffffa57fc8787d60 EFLAGS: 00000246 RAX: 0000000000000037 RBX: 0000000000000009 RCX: ffff9be25fcdc9c8 RDX: 0000000000000000 RSI: 0000000000000027 RDI: ffff9be25fcdc9c0 RBP: 0000000000300000 R08: ffffffffb4956f88 R09: 0000000000009ffb R10: 0000000000000284 R11: ffffffffb4926fa0 R12: ffffe6b00c000000 R13: ffff9bdb453dfd00 R14: 0000000000000000 R15: fffffffffffffffe FS: 00007f08f04e4740(0000) GS:ffff9be25fcc0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000564787a30410 CR3: 000000010d4e2000 CR4: 00000000000006f0 Kernel panic - not syncing: Fatal exception Kernel Offset: 0x31c00000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff) ---[ end Kernel panic - not syncing: Fatal exception ]--- The root cause is that unpoison_memory() tries to check the PG_HWPoison flags of an uninitialized page. So VM_BUG_ON_PAGE(PagePoisoned(page)) is triggered. This can be reproduced by below steps: 1.Offline memory block: echo offline > /sys/devices/system/memory/memory12/state 2.Get offlined memory pfn: page-types -b n -rlN 3.Write pfn to unpoison-pfn echo > /sys/kernel/debug/hwpoison/unpoison-pfn Signed-off-by: Miaohe Lin --- mm/memory-failure.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 581d3e5c9117..8c765329829f 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2564,6 +2564,13 @@ int unpoison_memory(unsigned long pfn) goto unlock_mutex; } + if (PagePoisoned(p)) { + unpoison_pr_info("%#lx: page is uninitialized\n", + pfn, &unpoison_rs); + ret = -EOPNOTSUPP; + goto unlock_mutex; + } + if (!PageHWPoison(p)) { unpoison_pr_info("%#lx: page was already unpoisoned\n", pfn, &unpoison_rs);