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 D5781C43334 for ; Wed, 15 Jun 2022 05:23:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 242D96B0071; Wed, 15 Jun 2022 01:23:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F24E6B0072; Wed, 15 Jun 2022 01:23:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 070C46B0073; Wed, 15 Jun 2022 01:23:12 -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 E9A416B0071 for ; Wed, 15 Jun 2022 01:23:11 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BD4AB61459 for ; Wed, 15 Jun 2022 05:23:11 +0000 (UTC) X-FDA: 79579326582.08.7994111 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf13.hostedemail.com (Postfix) with ESMTP id 7173C20086 for ; Wed, 15 Jun 2022 05:23:09 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id q12-20020a17090a304c00b001e2d4fb0eb4so1032947pjl.4 for ; Tue, 14 Jun 2022 22:23:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=1XTpGpbLP2Rfbx5oE6YvEnXck8EpVNE1acwrhRYTBi8=; b=AGuVTxIjaj3k53pbeqm9fWysRJAAeTp2x2TE3eJ6jP3M3gR9LVB8p9s+A3fCn0d96R lJo3kAQWL/3K5Nl+TWyJxbaDmpIYfPqNbunBIC5Fo9fbJjtRQx40lsWBwI4DE1KoZM34 3CvZc2OdSc054+AHeonC7gxaOu84rfnXlIvRJn4pCPMGAdUMqJCOBkYX2bxjYkintjcv 1c3ELWeJwXW4doaXAeVGGd1o6wJoZIJup3MiCcirEnAXuC+lHr4gVVsJTa8CfDKt3Sb8 U/ftymiuYueRXnXcT+a3/Gz6PuqawsBVkS/2cqy1Tr9NUw4u6OKmxhDWYfPoIjlmN95c I6HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=1XTpGpbLP2Rfbx5oE6YvEnXck8EpVNE1acwrhRYTBi8=; b=L6kWmhBu0ZpXwWW+8ZrNwP5tOhmQUeIlbcIP5OJzTkZGHhVaowWTvP9QPrl1Hvs5uR YaSxxsvSfjmAhieLcKqAxBBsCyILkfyxIR0VNcsCidMwjGP3RMNcFDymH3I8JD6CBIzI QoDTlGETC9YmUvkJOPDFR/gegsjqAKHN6SFWCqHgjys1P9D5awdABFqcXo7iGt6jMqPc 2Ld1ZoXOebExH9p9qPSr5sufQhgVnQVy1xcSenN2IxnRzLlKp00/OVaN4iN1krukiEYq bzUDODUqfLGxB3zL8ZFn7IXZ9Ln5ASlacZUARTDfxOUtrNa5qSTUNd9TOAv8Gc10ol6d I5jA== X-Gm-Message-State: AJIora89iH2YhYD0itGeBlWCJ5xhUBuGdKouo3MHlMnQuV8o3T5u/iAh F0UWmWhwkwzFMyh4tIuoeVtIWA== X-Google-Smtp-Source: AGRyM1v1on/vuL9R+Vkh2fWepoQk1Ag03qfJahaVVz5B0gwP5XLLHldO8dqAZZ+RSyApzzSRkGYW7g== X-Received: by 2002:a17:90b:3904:b0:1ea:d976:aff7 with SMTP id ob4-20020a17090b390400b001ead976aff7mr620443pjb.4.1655270587963; Tue, 14 Jun 2022 22:23:07 -0700 (PDT) Received: from [10.76.15.169] ([61.120.150.70]) by smtp.gmail.com with ESMTPSA id b7-20020a1709027e0700b001635a8f9dfdsm573680plm.26.2022.06.14.22.23.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jun 2022 22:23:07 -0700 (PDT) Message-ID: Date: Wed, 15 Jun 2022 13:18:23 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: Re: [PATCH v5 1/1] mm/memory-failure: disable unpoison once hw error happens Content-Language: en-US To: Oscar Salvador Cc: naoya.horiguchi@nec.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@redhat.com, linmiaohe@huawei.com, gregkh@linuxfoundation.org References: <20220615020005.246295-1-pizhenwei@bytedance.com> <20220615020005.246295-2-pizhenwei@bytedance.com> From: zhenwei pi In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655270591; a=rsa-sha256; cv=none; b=2nJta8slH9Sah019yUelaHfCQ6C/s03o7tpvVVyreKVBuwTelvLxuagWMUIYvQC+bOlTLY TffeOFZJxjuN8vsn4hiP/KQeorD4ct7qVVfp7zOySPyY58r/191NPbQHtxvRvKxwqILrdR wndUrHBpcXiKQFtqkZAEE0uOl5sFHtA= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=AGuVTxIj; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of pizhenwei@bytedance.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=pizhenwei@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655270591; 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=1XTpGpbLP2Rfbx5oE6YvEnXck8EpVNE1acwrhRYTBi8=; b=GUDqndCCnJIMKV2UYJm9606EyfbVi6PnhXGGqtMbQoLqMXjp4WG1eWXJuxxTwOe9eqS+aH pvnb4QHaW23O2ALeCmZz9wtkGk6P7EflqpErLt+ePJZH5380kg/zfR6RvD1v3jo1PxgJEr Oy1MSX5hnUjVc9E66XDJDIygw4HPPmQ= X-Rspamd-Queue-Id: 7173C20086 X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=AGuVTxIj; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of pizhenwei@bytedance.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=pizhenwei@bytedance.com X-Rspamd-Server: rspam06 X-Stat-Signature: u5arid5b9pr3c8tbt6quxsqhzm4873x1 X-HE-Tag: 1655270589-996262 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 6/15/22 12:23, Oscar Salvador wrote: > On Wed, Jun 15, 2022 at 10:00:05AM +0800, zhenwei pi wrote: >> 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. >> >> Suggested by David&Naoya, disable unpoison mechanism when a real HW error >> happens 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 >> >> 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 >> --- > ... > ... >> diff --git a/mm/memory-failure.c b/mm/memory-failure.c >> index b85661cbdc4a..385b5e99bfc1 100644 >> --- a/mm/memory-failure.c >> +++ b/mm/memory-failure.c >> @@ -69,6 +69,8 @@ int sysctl_memory_failure_recovery __read_mostly = 1; >> >> atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0); >> >> +static bool hw_memory_failure; >> + >> static bool __page_handle_poison(struct page *page) >> { >> int ret; >> @@ -1768,6 +1770,9 @@ int memory_failure(unsigned long pfn, int flags) >> >> mutex_lock(&mf_mutex); >> >> + if (!(flags & MF_SW_SIMULATED)) >> + hw_memory_failure = true; >> + >> p = pfn_to_online_page(pfn); >> if (!p) { >> res = arch_memory_failure(pfn, flags); >> @@ -2103,6 +2108,13 @@ int unpoison_memory(unsigned long pfn) >> >> mutex_lock(&mf_mutex); >> >> + if (hw_memory_failure) { >> + unpoison_pr_info("Unpoison: Disabled after HW memory failure %#lx\n", >> + pfn, &unpoison_rs); >> + ret = -EOPNOTSUPP; >> + goto unlock_mutex; >> + } > > If we disable this, I would move this at the beginning of the function. > We do not really care whether the pfn is valid or getting the head of > the page, etc. > So, unless I'm missing something, this should be enough? > Hi, Because memory_failure() may be called by hardware error randomly, hw_memory_failure should be protected by mf_mutex to avoid this case: int unpoison_memory(unsigned long pfn) { ... if (hw_memory_failure) { } ... --> memory_failure() happens, and mark hw_memory_failure as true mutex_lock(&mf_mutex); } > diff --git a/mm/memory-failure.c b/mm/memory-failure.c > index 385b5e99bfc1..ece15f07dee7 100644 > --- a/mm/memory-failure.c > +++ b/mm/memory-failure.c > @@ -2100,6 +2100,12 @@ int unpoison_memory(unsigned long pfn) > static DEFINE_RATELIMIT_STATE(unpoison_rs, DEFAULT_RATELIMIT_INTERVAL, > DEFAULT_RATELIMIT_BURST); > > + if (hw_memory_failure) { > + unpoison_pr_info("Unpoison: Disabled after HW memory failure\n", > + &unpoison_rs); > + ret -EOPNOTSUPP; > + } > + > if (!pfn_valid(pfn)) > return -ENXIO; > > -- zhenwei pi