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 9D6D3CCA47E for ; Tue, 14 Jun 2022 04:36:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E3B38D020B; Tue, 14 Jun 2022 00:36:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 393368D0207; Tue, 14 Jun 2022 00:36:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25BB58D020B; Tue, 14 Jun 2022 00:36:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 16F1B8D0207 for ; Tue, 14 Jun 2022 00:36:22 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E697860F1E for ; Tue, 14 Jun 2022 04:36:21 +0000 (UTC) X-FDA: 79575579762.17.47443FF Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf21.hostedemail.com (Postfix) with ESMTP id 8D6091C00A2 for ; Tue, 14 Jun 2022 04:36:19 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id bo5so7571918pfb.4 for ; Mon, 13 Jun 2022 21:36:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SXchz2Eq62MMA7Wwy1fJEQQa85RBXUsLGi6XIUd5z/w=; b=Fbk9q6WUm6i0BymMi/Y7fwWYv80c89cVIqZEVaTWFvNpcrKioUsVVQqayGSVanUOha aocQyw1qPeQ0knzVI5hhBwPQDpvYoNZGbZqha3WjGeayqbqwwQc3SxYMJQaq1e9zM5LO EXlYh0l4sckSSMpFhLRd5TY9HbmesvovmoYsGeIoTjOPHrWspOQjp38RzwYUb365UnSV 7oCeF0Jd7hrLpuy4LlDGH3n/PhP031TrIofc3PTlFNp7DBdK4ZypVqnHsLrA5F7hjOo8 sZvT8V9L7qM0NfEL1p2MUnCJZaPwxrEFIHEfbFpmrSxMnYXd1ET5QfkEXtF4ztSqG0is 1qtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SXchz2Eq62MMA7Wwy1fJEQQa85RBXUsLGi6XIUd5z/w=; b=Rk/Pifw2hlTt05HFfnSMHm/cu9whnqTQ2DPpMCAvCUEvou4jGpx3FSPSDigNlhSRTJ nzEvRzKT8K8RAKwyEXdP4GR2Suc258JoyhEm5qG6dZZhgbNqD9sBXXP+FCQwcOLP7iZj mClZ9INJhTuEn87lDfG0PqC5tqOVAtuIWEzXR0Ylf/bjwGOollpuwywQxViMJJQow7G8 /lAdno5IDq6f/YQYZpB+c6Mt3EID4roRjxEsAQxB5MHr8MJ4PWaasEo3EEoOs5UOWp5s KiL2Iu68FFvqq1yr2qCPNUV/NVWbmmPHekjbRGazALj/+seeMm81bg54e9tHfGN9eNYs ZeiA== X-Gm-Message-State: AJIora+jzBTAfdpr/GDdC6KnRrWblZIeZwBDxXEBk6IYMIF1VSvWQFo0 x4KC7rFn79cPh80l561RuQn9NQ== X-Google-Smtp-Source: AGRyM1vTSeRW1BT+lNyZVYYasdUzmAo+GIbXDrYrpv4eRD33/W43mOHhoz3/Bf3q8zf2OscEojpb0Q== X-Received: by 2002:a63:8b42:0:b0:408:a938:289b with SMTP id j63-20020a638b42000000b00408a938289bmr785628pge.201.1655181378431; Mon, 13 Jun 2022 21:36:18 -0700 (PDT) Received: from always-T480.www.tendawifi.com ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id t16-20020a63b250000000b00401a7b4f137sm6469120pgo.41.2022.06.13.21.36.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 21:36:17 -0700 (PDT) From: zhenwei pi To: akpm@linux-foundation.org, naoya.horiguchi@nec.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@redhat.com, linmiaohe@huawei.com, zhenwei pi Subject: [PATCH v4 2/2] mm/memory-failure: disable unpoison once hw error happens Date: Tue, 14 Jun 2022 12:38:30 +0800 Message-Id: <20220614043830.99607-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220614043830.99607-1-pizhenwei@bytedance.com> References: <20220614043830.99607-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655181381; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SXchz2Eq62MMA7Wwy1fJEQQa85RBXUsLGi6XIUd5z/w=; b=JhZBDKXj8gW3S514hBOaQJAHZm+EIYx2sa0IxtwEF1QGWlTy7qKNehw1aadOx70RkhCh1h NhR521rUsLtHq8CLVw7niNGJFKYWEXIqytpwwK/V2VqxCrwQ/ce+5fBkIVcl+g6DF6Oss/ ukKu5DXMa/sx6KVEYUBODWUddyrTNEU= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Fbk9q6WU; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf21.hostedemail.com: domain of pizhenwei@bytedance.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=pizhenwei@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655181381; a=rsa-sha256; cv=none; b=0AvIn/AMMO721//fgQo3+R+ieHQ/cq/kPBsThdV4HQgahzGfBTg1qGtw+MKnZJMxyGZ/Er KC+EuGQ7DoNW2qe8GzWMUcpLx8qaioKtA0eKX53VzhbhjfpYgEXTDpcsWosB68aIVpX19f 5WsMt2B4qk2+busFiojEOgf1eRMtSXg= X-Rspamd-Queue-Id: 8D6091C00A2 X-Rspam-User: X-Stat-Signature: 8gf6k39fy1zdgom66hezdprwsuq18m1h Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Fbk9q6WU; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf21.hostedemail.com: domain of pizhenwei@bytedance.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=pizhenwei@bytedance.com X-Rspamd-Server: rspam04 X-HE-Tag: 1655181379-247836 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: Currently unpoison_memory(unsigned long pfn) is designed for soft poison(hwpoison-inject) only. Since 17fae1294ad9d, the KPTE gets cleared on a x86 platform once hardware memory corrupts. Unpoisoning a hardware corrupted page puts page back buddy only, the kernel has a chance to access the page with *NOT PRESENT* KPTE. This leads BUG during accessing on the corrupted KPTE. Do not allow to unpoison hardware corrupted page in unpoison_memory() to avoid BUG like this: Unpoison: Software-unpoisoned page 0x61234 BUG: unable to handle page fault for address: ffff888061234000 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page PGD 2c01067 P4D 2c01067 PUD 107267063 PMD 10382b063 PTE 800fffff9edcb062 Oops: 0002 [#1] PREEMPT SMP NOPTI CPU: 4 PID: 26551 Comm: stress Kdump: loaded Tainted: G M OE 5.18.0.bm.1-amd64 #7 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) ... RIP: 0010:clear_page_erms+0x7/0x10 Code: ... RSP: 0000:ffffc90001107bc8 EFLAGS: 00010246 RAX: 0000000000000000 RBX: 0000000000000901 RCX: 0000000000001000 RDX: ffffea0001848d00 RSI: ffffea0001848d40 RDI: ffff888061234000 RBP: ffffea0001848d00 R08: 0000000000000901 R09: 0000000000001276 R10: 0000000000000003 R11: 0000000000000000 R12: 0000000000000001 R13: 0000000000000000 R14: 0000000000140dca R15: 0000000000000001 FS: 00007fd8b2333740(0000) GS:ffff88813fd00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff888061234000 CR3: 00000001023d2005 CR4: 0000000000770ee0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: prep_new_page+0x151/0x170 get_page_from_freelist+0xca0/0xe20 ? sysvec_apic_timer_interrupt+0xab/0xc0 ? asm_sysvec_apic_timer_interrupt+0x1b/0x20 __alloc_pages+0x17e/0x340 __folio_alloc+0x17/0x40 vma_alloc_folio+0x84/0x280 __handle_mm_fault+0x8d4/0xeb0 handle_mm_fault+0xd5/0x2a0 do_user_addr_fault+0x1d0/0x680 ? kvm_read_and_reset_apf_flags+0x3b/0x50 exc_page_fault+0x78/0x170 asm_exc_page_fault+0x27/0x30 Suggested by David&Naoya, disable unpoison mechanism when a real HW error happens. Fixes: 847ce401df392 ("HWPOISON: Add unpoisoning support") Fixes: 17fae1294ad9d ("x86/{mce,mm}: Unmap the entire page if the whole page is affected and poisoned") Cc: Naoya Horiguchi Cc: David Hildenbrand Signed-off-by: zhenwei pi --- Documentation/vm/hwpoison.rst | 3 ++- mm/hwpoison-inject.c | 6 ++++++ mm/memory-failure.c | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Documentation/vm/hwpoison.rst b/Documentation/vm/hwpoison.rst index c832a8b192d4..ac439381cad4 100644 --- a/Documentation/vm/hwpoison.rst +++ b/Documentation/vm/hwpoison.rst @@ -120,7 +120,8 @@ Testing unpoison-pfn Software-unpoison page at PFN echoed into this file. This way a page can be reused again. This only works for Linux - injected failures, not for real memory failures. + injected failures, not for real memory failures. Once any hardware + memory failure happens, the feature is disabled. Note these injection interfaces are not stable and might change between kernel versions diff --git a/mm/hwpoison-inject.c b/mm/hwpoison-inject.c index 9e522ecedeef..787d2daf41e8 100644 --- a/mm/hwpoison-inject.c +++ b/mm/hwpoison-inject.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "internal.h" static struct dentry *hwpoison_dir; @@ -65,6 +66,11 @@ static int hwpoison_unpoison(void *data, u64 val) if (!capable(CAP_SYS_ADMIN)) return -EPERM; + if (atomic_read(&hwpoisoned_pages) != atomic_long_read(&num_poisoned_pages)) { + pr_info("Unpoison is disabled after hardware memory failure happened\n"); + return -EOPNOTSUPP; + } + ret = unpoison_memory(val); if (!ret) { atomic_dec(&hwpoisoned_pages); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index b85661cbdc4a..a3e6bd4b5528 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -68,6 +68,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0; int sysctl_memory_failure_recovery __read_mostly = 1; atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0); +EXPORT_SYMBOL_GPL(num_poisoned_pages); static bool __page_handle_poison(struct page *page) { -- 2.20.1