From patchwork Sat May 11 03:28:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 13662260 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 87134C04FFE for ; Sat, 11 May 2024 03:31:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF7B06B0150; Fri, 10 May 2024 23:31:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA7436B0151; Fri, 10 May 2024 23:31:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6F166B0152; Fri, 10 May 2024 23:31:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A94AD6B0150 for ; Fri, 10 May 2024 23:31:05 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 579A9A0F7D for ; Sat, 11 May 2024 03:31:05 +0000 (UTC) X-FDA: 82104688890.27.66EB779 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf15.hostedemail.com (Postfix) with ESMTP id 4DFAFA0002 for ; Sat, 11 May 2024 03:31:01 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715398263; 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=6AXroSad2vBLZOVWV4iowYvebZ9fXHoNZViuF9LsHpg=; b=jCB6icrzW/dFxmLwcSqJRYTICz3DnnjHQ+hc1arqF9KKERZ7YR+D9Qp0xc9LQ6p8FU1wjp 7bnqURSP2SQWZmwq/2xIXRVpS50S03ORvYqpzeUUqA87HhQ9pg2S2io7lyBkDd5GxdKHXm j52E2UFwMsTqvnbg9nrQFfEsuhnpXwU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715398263; a=rsa-sha256; cv=none; b=FwmnTM9frSaUWdoYslZSKm9WVQ3ZoiEqm6uoM+eNdJLcGq7JJKf2ZUL+UvS8HnVTob0O8K j6wUBQSCOC0UC5TYjG8BTE6JEXC0/Mg0oL0ODYaV+JjrBYVjLHIh0ML/DcuvFbJrJYbNIV i/SGRCjuUCuppRzzb6MYrT0d1W+6HOM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Vbrm64nmTz1S4sJ; Sat, 11 May 2024 11:27:34 +0800 (CST) Received: from canpemm500002.china.huawei.com (unknown [7.192.104.244]) by mail.maildlp.com (Postfix) with ESMTPS id F1CB518007F; Sat, 11 May 2024 11:30:57 +0800 (CST) Received: from huawei.com (10.173.135.154) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Sat, 11 May 2024 11:30:57 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH] mm/huge_memory: mark huge_zero_folio reserved Date: Sat, 11 May 2024 11:28:01 +0800 Message-ID: <20240511032801.1295023-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [10.173.135.154] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-Stat-Signature: k1uxt5jdgzdbucb6kzwqaeke3jtuxpzy X-Rspamd-Queue-Id: 4DFAFA0002 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1715398261-934818 X-HE-Meta: U2FsdGVkX1+Ba6ijfdhXTC8cCs6Cp6tmxFbr3ll9Ah5WDVuGJRQY1TZA1w9mIaOAXqkzRHV7HOsjCvK1hNiHJqRVtBx3iZ0x9ChVtL6x5tFJXQeq1Vr25P4jK0n+REvHKSzMst/M/zBti/nqS9fgl5DPsYvnPor0uAYratEfnB7tsjSjErobY54zwVsjF7W384ZBE9HuyEG144wq37QSML31qUtWqQAPhmtiDqBKMX2ICLDE6jjqYD/e14rH3/pFougF6FGwNnHW/QX7LGlWgCdS/WiBW7PdI549FPtsy2gTtw+3MEn4jGIn14tFXfhc/WtkWqH6Up2FxzCV2yNEwES2NRO+Jor0OyeJG9CrSR7+NlGz4R0Ia3+oNLQvCgOeTQlzreGkMLBTbjK0DfqIsMgDpf4E/wawkzMjdKMPo0hkZROjallU4lTyuiDdU09rGgyjQhLF0F8wgCxgUqOO8Otu7gkDwkWhcCu5Y69S7CSXU8UacR70JUOLBaOESSwubfuDNEehjUvQ0P0ZLVGU2E8Q7yYbPqGwv2O1w0x2+wSzabdy3q8HR+vMZWVewCeflipU11wE4rYIa1861uEGR6SvtPuVdu13lPYksLJLErPsaU7wco3XmvFtpdvjKO2BCt8F1J9HUQED7rGOpT+psCIg9M3cn2PODhXU+hJwA/YNYIdBnShqVfP6HgpYrKG9AxfFkZrTm8DOlE0PhutEyCasKs10wJnecR0uhxCITBwRio/7Zq8rgNbftFOOgCXmrt3bZPRJoaE3YoVmbRhWMQnhGydex2Rhh+3oxU0ifpa/cgA1mAeOpYX/iAVqNMUQdkq1vvMdL2BtrWJtD1jnizVTtV6OYwMcfNsM99xij4Z2VZf3ZAk07OVNg3RPg8MAqJl25h+celx8ZkCUDCGCFC56Idw+Aua48D2BuZX0389nRehh725MTSdokZesVGRdTaHJd8EajMsD+zZMKyQ J5CBvmfI 9xlfuvrvypbq9GwidCrXmOVQ8roJinWCmh/d+bQMKIehJnnzRDJum6x9TCLuu9BEyUMrsvmisl3mLR1CLUkAUfvvzAruxaT+1punCm/JCVTDp1UHuHwJHiQCu5488645Bo4aCDA6rHkw+KRR67uMlhUWU+ORRHDU0pArupbbYnfSuNt46AT6bq5QSfgeHU5+Z6kvMTfEfPzc8sE6hUY2zNXOOTQB7e3qA5iJHIRuPemWtr3rTP/1gs7eFcxR75BAYydN6VgV4C67DmKrJM7ThUcg/7hObbg3hK+wQEhHGiPcKT52Y3C0BO0fDFC5e4Pe2ddAA 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: kernel BUG at include/linux/mm.h:1135! invalid opcode: 0000 [#1] PREEMPT SMP NOPTI CPU: 9 PID: 137 Comm: kswapd1 Not tainted 6.9.0-rc4-00491-gd5ce28f156fe-dirty #14 RIP: 0010:shrink_huge_zero_page_scan+0x168/0x1a0 RSP: 0018:ffff9933c6c57bd0 EFLAGS: 00000246 RAX: 000000000000003e RBX: 0000000000000000 RCX: ffff88f61fc5c9c8 RDX: 0000000000000000 RSI: 0000000000000027 RDI: ffff88f61fc5c9c0 RBP: ffffcd7c446b0000 R08: ffffffff9a9405f0 R09: 0000000000005492 R10: 00000000000030ea R11: ffffffff9a9405f0 R12: 0000000000000000 R13: 0000000000000000 R14: 0000000000000000 R15: ffff88e703c4ac00 FS: 0000000000000000(0000) GS:ffff88f61fc40000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055f4da6e9878 CR3: 0000000c71048000 CR4: 00000000000006f0 Call Trace: do_shrink_slab+0x14f/0x6a0 shrink_slab+0xca/0x8c0 shrink_node+0x2d0/0x7d0 balance_pgdat+0x33a/0x720 kswapd+0x1f3/0x410 kthread+0xd5/0x100 ret_from_fork+0x2f/0x50 ret_from_fork_asm+0x1a/0x30 Modules linked in: mce_inject hwpoison_inject ---[ end trace 0000000000000000 ]--- RIP: 0010:shrink_huge_zero_page_scan+0x168/0x1a0 RSP: 0018:ffff9933c6c57bd0 EFLAGS: 00000246 RAX: 000000000000003e RBX: 0000000000000000 RCX: ffff88f61fc5c9c8 RDX: 0000000000000000 RSI: 0000000000000027 RDI: ffff88f61fc5c9c0 RBP: ffffcd7c446b0000 R08: ffffffff9a9405f0 R09: 0000000000005492 R10: 00000000000030ea R11: ffffffff9a9405f0 R12: 0000000000000000 R13: 0000000000000000 R14: 0000000000000000 R15: ffff88e703c4ac00 FS: 0000000000000000(0000) GS:ffff88f61fc40000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055f4da6e9878 CR3: 0000000c71048000 CR4: 00000000000006f0 The root cause is that HWPoison flag will be set for huge_zero_folio without increasing the folio refcnt. But then unpoison_memory() will decrease the folio refcnt unexpectly as it appears like a successfully hwpoisoned folio leading to VM_BUG_ON_PAGE(page_ref_count(page) == 0) when releasing huge_zero_folio. Fix this issue by marking huge_zero_folio reserved. So unpoison_memory() will skip this page. This will make it consistent with ZERO_PAGE case too. Fixes: 478d134e9506 ("mm/huge_memory: do not overkill when splitting huge_zero_page") Signed-off-by: Miaohe Lin Cc: --- mm/huge_memory.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 317de2afd371..d508ff793145 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -212,6 +212,7 @@ static bool get_huge_zero_page(void) folio_put(zero_folio); goto retry; } + __folio_set_reserved(zero_folio); WRITE_ONCE(huge_zero_pfn, folio_pfn(zero_folio)); /* We take additional reference here. It will be put back by shrinker */ @@ -264,6 +265,7 @@ static unsigned long shrink_huge_zero_page_scan(struct shrinker *shrink, struct folio *zero_folio = xchg(&huge_zero_folio, NULL); BUG_ON(zero_folio == NULL); WRITE_ONCE(huge_zero_pfn, ~0UL); + __folio_clear_reserved(zero_folio); folio_put(zero_folio); return HPAGE_PMD_NR; }