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 C89C3C02198 for ; Thu, 13 Feb 2025 03:20:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 255846B0089; Wed, 12 Feb 2025 22:20:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 205D56B008A; Wed, 12 Feb 2025 22:20:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A7126B008C; Wed, 12 Feb 2025 22:20:14 -0500 (EST) 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 DF2B56B0089 for ; Wed, 12 Feb 2025 22:20:13 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 441E71202C6 for ; Thu, 13 Feb 2025 03:20:13 +0000 (UTC) X-FDA: 83113467906.02.ADCF205 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf01.hostedemail.com (Postfix) with ESMTP id D5FD340006 for ; Thu, 13 Feb 2025 03:20:09 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 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=1739416811; 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; bh=AXtyYZC7X2AxNrem+yHnETYRMJgUhsOP0CTq9rqKf7U=; b=dxNYbeeq2kxs1O6UyoFXBclg1UNexJArlpM7i87HlJV2uDAkvzFsuFRiMtYtHeJpMQRZ8Z AlUCLjy5JiJKf/KCEQxj9rlr5jSM0TDKD6KbCVMRuQ1LIgzFpOoralzRBIVxe0Nvc5q8nv iofjWGc8y6SAdF8gRsAmdBw5e5O+aX8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739416811; a=rsa-sha256; cv=none; b=Ze26rEHFolQ7ZsbPNTqhqiCC1VsOLOhsEWRs1mZksr9dxBG6gFb8B15yubB5/a5WyWLyJn ncb0udVmda/xiZRnRc1W2r3chGVNPgvXwjzr9NN7XaD1WUFXT3d8Eppwc3qutHFvPkVog6 iPldjuwCzkt/8Odk8qPKrlKOOPM3WBs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4YtgM41krqzkXPf; Thu, 13 Feb 2025 11:16:32 +0800 (CST) Received: from kwepemd200019.china.huawei.com (unknown [7.221.188.193]) by mail.maildlp.com (Postfix) with ESMTPS id 8C2E31800DB; Thu, 13 Feb 2025 11:20:05 +0800 (CST) Received: from [10.173.127.72] (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; Thu, 13 Feb 2025 11:20:04 +0800 Subject: Re: [PATCH v1 4/4] mm/hwpoison: Fix incorrect "not recovered" report for recovered clean pages To: Shuai Xue CC: , , , , , , , , , , , , , "nao.horiguchi@gmail.com" References: <20250211060200.33845-1-xueshuai@linux.alibaba.com> <20250211060200.33845-5-xueshuai@linux.alibaba.com> <5f116840-60df-c6d9-d7ff-dcf1dce7773f@huawei.com> <3820329d-20e3-49ee-a329-aac7393c6df3@linux.alibaba.com> From: Miaohe Lin Message-ID: <23251c74-cc50-012c-409f-c45117b52b16@huawei.com> Date: Thu, 13 Feb 2025 11:20:03 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <3820329d-20e3-49ee-a329-aac7393c6df3@linux.alibaba.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.173.127.72] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemd200019.china.huawei.com (7.221.188.193) X-Rspam-User: X-Rspamd-Queue-Id: D5FD340006 X-Rspamd-Server: rspam07 X-Stat-Signature: iyjbnrw6y4wkiod8ar5daujyqcw7taks X-HE-Tag: 1739416809-814269 X-HE-Meta: U2FsdGVkX18GqJ6RpKKeqn64r5pfj4nEIKWwzPWv0q0ualoonkWUtwyxroKSJPV7625nRKsVJDN6SVRMzXaqQNd/I9uut/p0Rzps2C4Xqu000xCcFIztDjTSCADX7qNM+5KrpRY1uyQtyKK8lowupt+5L7By62TOrMeZiG1aM4ChrjE/u0XZy+nYh0aykmCXLFX3BVNqXXRY15E0MN61GcPMg/9O8bQcDg5mqw4A508yuzlWjzVa6der1a3bUer+JD5pcE/xUWJT19HgtcGa4JCnm24s/s1ZYyoBTSUFAsIuz834hsY+DiEhK3I7eZXtu7pX7CuZ4aHNJWQY6IC6B7m4taED6JTjhWqk3mWKHqmbVSgVaaPWQRddTNGauoAJyZnCXgfyufDzrJ8x9i7vwtiI0bfAoSyRZHQdO9oZFuMLRkvzXHBy5UruyOFESjOZi2G+4xGdxdj/KA84+8+CuYi6pDXSjOnl8PZZVFVlu17FBmZG0SZ3gpzQLrcQ69gslbfklMGj0+6QrZp02+Ew+SoSwk6gWVzgngnNApAO1eRBq23cHacr0A60vr1RoQCEytlCDejV2E6+f/Ba0NkdqNhudesZ8lnYIKWhXUMZkNZnuW5NdqfogPahq8ziWjvA2AJKfwflkxu96yq2cvtttf63FLvADUY0X7bJtzzLuauptksIZVWQ5PJTBNxME54ZjhZWdyDfZPT5tNn1C8tqLYM9JH2Cg0iWSsDNtuZfC7Qv8jfn2mHr3Gf/+tSyyu0ywf0zIiDiuMi2quHqD6nOJA3lpl/T+MI/VXNhVKYJcJMNsVfQu315DBISZzO6pHePO+YMBs3imz8HeJE4SAVOQNaXdLh6S6ITlwKVu9PqJGkXjxHQaKFb628vQgYpdu7WvBEFFUtvq1Rp6esuO2TmIXPo7vs7By4gjb1Z5HxUHP4aYWJgwqiM2oHpJ8DTbCa9n0Zw30BTMmwzb4FLE+k hqK3vGXj vxSeuMRfDjOot+rQ5T6QtodC0xWmFKCx6xgLnUwQpTWcVq9Y4PE4+o9tCTuSSFOtNRdJP0yeatt+H+VjvOn1I+k0VZklbkSLel38uXrCJPjCPSmcDYRaKnlL0fd2DUM4vty6v7M+RwgZHqbRVGO7F5bk/48k7x1k57RMXtLLE1rMSZqu89gTKtftA0IK9FTYR/olFyOKe3p4x1u7gYIsP92HXsN2Z3+2yOtzWYWFMMwhiOcaV88VlGG1o2hoSco95Tq4fChynyHDSQCpdoXSjHGVl8C3uDhsNswZ3CAc7fHGZ+gPecN3gN9Zgug== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000319, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2025/2/12 21:55, Shuai Xue wrote: > > > 在 2025/2/12 16:09, Miaohe Lin 写道: >> On 2025/2/11 14:02, Shuai Xue wrote: >>> When an uncorrected memory error is consumed there is a race between >>> the CMCI from the memory controller reporting an uncorrected error >>> with a UCNA signature, and the core reporting and SRAR signature >>> machine check when the data is about to be consumed. >>> >>> If the CMCI wins that race, the page is marked poisoned when >>> uc_decode_notifier() calls memory_failure(). For dirty pages, >>> memory_failure() invokes try_to_unmap() with the TTU_HWPOISON flag, >>> converting the PTE to a hwpoison entry. However, for clean pages, the >>> TTU_HWPOISON flag is cleared, leaving the PTE unchanged and not converted >>> to a hwpoison entry. Consequently, for an unmapped dirty page, the PTE is >>> marked as a hwpoison entry allowing kill_accessing_process() to: >>> >>> - call walk_page_range() and return 1 >>> - call kill_proc() to make sure a SIGBUS is sent >>> - return -EHWPOISON to indicate that SIGBUS is already sent to the process >>>    and kill_me_maybe() doesn't have to send it again. >>> >>> Conversely, for clean pages where PTE entries are not marked as hwpoison, >>> kill_accessing_process() returns -EFAULT, causing kill_me_maybe() to send a >>> SIGBUS. >>> >>> Console log looks like this: >>> >>>      Memory failure: 0x827ca68: corrupted page was clean: dropped without side effects >>>      Memory failure: 0x827ca68: recovery action for clean LRU page: Recovered >>>      Memory failure: 0x827ca68: already hardware poisoned >>>      mce: Memory error not recovered >>> >>> To fix it, return -EHWPOISON if no hwpoison PTE entry is found, preventing >>> an unnecessary SIGBUS. >> >> Thanks for your patch. >> >>> >>> Fixes: 046545a661af ("mm/hwpoison: fix error page recovered but reported "not recovered"") >>> Signed-off-by: Shuai Xue >>> --- >>>   mm/memory-failure.c | 5 ++--- >>>   1 file changed, 2 insertions(+), 3 deletions(-) >>> >>> diff --git a/mm/memory-failure.c b/mm/memory-failure.c >>> index 995a15eb67e2..f9a6b136a6f0 100644 >>> --- a/mm/memory-failure.c >>> +++ b/mm/memory-failure.c >>> @@ -883,10 +883,9 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn, >>>                     (void *)&priv); >>>       if (ret == 1 && priv.tk.addr) >>>           kill_proc(&priv.tk, pfn, flags); >>> -    else >>> -        ret = 0; >>>       mmap_read_unlock(p->mm); >>> -    return ret > 0 ? -EHWPOISON : -EFAULT; >>> + >>> +    return ret >= 0 ? -EHWPOISON : -EFAULT; >> >> IIUC, kill_accessing_process() is supposed to return -EHWPOISON to notify that SIGBUS is already >> sent to the process and kill_me_maybe() doesn't have to send it again. But with your change, >> kill_accessing_process() will return -EHWPOISON even if SIGBUS is not sent. Does this break >> the semantics of -EHWPOISON? > > Yes, from the comment of kill_me_maybe(), > >      * -EHWPOISON from memory_failure() means that it already sent SIGBUS >      * to the current process with the proper error info, >      * -EOPNOTSUPP means hwpoison_filter() filtered the error event, > > this patch break the comment. > > But the defination of EHWPOISON is quite different from the comment. > >  #define EHWPOISON    133    /* Memory page has hardware error */ > > As for this issue, returning 0 or EHWPOISON can both prevent a SIGBUS signal > from being sent in kill_me_maybe(). > > Which way do you prefer? > >> >> BTW I scanned the code of walk_page_range(). It seems with implementation of hwpoison_walk_ops >> walk_page_range() will only return 0 or 1, i.e. always >= 0. So kill_accessing_process() will always >> return -EHWPOISON if this patch is applied. >> >> Correct me if I miss something. > > Yes, you are right. Let's count the cases one by one: > > 1. clean page: try_to_remap(!TTU_HWPOISON), walk_page_range() will return 0 and Do you mean try_to_unmap? > we should not send sigbus in kill_me_maybe(). > > 2. dirty page: > 2.1 MCE wins race >           CMCI:w/o Action Require         MCE: w/ Action Require >                                       TestSetPageHWPoison >       TestSetPageHWPoison >       return -EHWPOISON >                                       try_to_unmap(TTU_HWPOISON) >                                       kill_proc in hwpoison_user_mappings() > > If MCE wins the race, because the flag of memory_fialure() called by CMCI is > not set as MF_ACTION_REQUIRED, everything goes well, kill_proc() will send > SIGBUS in hwpoison_user_mappings(). > > 2.2 CMCI win >           CMCI:w/o Action Require         MCE: w/ Action Require >     TestSetPageHWPoison >     try_to_unmap(TTU_HWPOISON) >                                        walk_page_range() return 1 due to hwpoison PTE entry >                                        kill_proc in kill_accessing_process() > > If the CMCI wins the race, we need to kill the process in > kill_accessing_process(). And if try_to_remap() success, everything goes well, > kill_proc() will send SIGBUS in kill_accessing_process(). > > But if try_to_remap() fails, the PTE entry will not be marked as hwpoison, and > walk_page_range() return 0 as case 1 clean page, NO SIGBUS will be sent. If try_to_unmap() fails, the PTE entry will still point to the dirty page. Then in check_hwpoisoned_entry(), we will have pfn == poisoned_pfn. So walk_page_range() will return 1 in this case. Or am I miss something? > > In summary, hwpoison_walk_ops cannot distinguish between try_to_unmap failing > and causing the PTE entry not to be set to hwpoison, and a clean page that > originally does not have the PTE entry set to hwpoison. Is it possible current process is not the one accessing the hwpoisoned page? E.g. memory_failure is deferred and called from kworker context or something like that. If it's possible, this is another scene needs to be considered. Thanks. .