From patchwork Wed Mar 12 11:28:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14013385 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 444ACC28B28 for ; Wed, 12 Mar 2025 11:29:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDE06280004; Wed, 12 Mar 2025 07:29:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C449C280003; Wed, 12 Mar 2025 07:29:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD8C3280003; Wed, 12 Mar 2025 07:29:01 -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 8BB26280001 for ; Wed, 12 Mar 2025 07:29:01 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 89E1856506 for ; Wed, 12 Mar 2025 11:29:02 +0000 (UTC) X-FDA: 83212677324.24.70F661B Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf25.hostedemail.com (Postfix) with ESMTP id 15FEEA000B for ; Wed, 12 Mar 2025 11:28:59 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=STvDxyyY; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf25.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=xueshuai@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741778941; a=rsa-sha256; cv=none; b=LzQbAzTgm280zFYMQpP6pnDtowGDmSD1TsDOsa1kyMY31XcqW697uhp/DdZ73MhKmQGpHz qoRD3k7Ov+x0v+bBnNURv0B6WBOZWnflaM2YuU3gZ7rDb2IMi2itF+WeIIMbSaZpzBN4O2 PWb3WiKOUoEaXW5/iC/2iEEE50FLCNA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=STvDxyyY; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf25.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=xueshuai@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741778941; 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=bbkn64ghX0689OXQU9V6jOFRXnCMdCl48Q1ObBbcJ48=; b=QM8lzCcBTeOv5h28+oQEIcnBkmOyRW+tMCkxlZtyoD8iPFk8BrZ/9Y8Iesavr6nG7SzZIL PI4pYaVgP+8ONKV3RWaO+hDXnAqpYM80K1fj69KCBvI8Il8dvzIwYoB4zShlAeV//kY9EU e8pPq6ro0xEABzcvOdhWzMRvFmTVK2I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1741778936; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=bbkn64ghX0689OXQU9V6jOFRXnCMdCl48Q1ObBbcJ48=; b=STvDxyyY3wBLz4kQrPjVfBdBJI3JcaPVQ+gphdjMbdrfKw/DL0ORswqFMASKcfsP+yj6lrKOLGoRY8PzOm1N48pIaMb3Bq75Y231JF0P78GwnTI2Z5KEI8gmHnK5SGdOok0nQK6DS4foKFaezUAB+EOUWOpni/3R0QFTUmcejLA= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WRCdv1J_1741778935 cluster:ay36) by smtp.aliyun-inc.com; Wed, 12 Mar 2025 19:28:55 +0800 From: Shuai Xue To: akpm@linux-foundation.org, linmiaohe@huawei.com, nao.horiguchi@gmail.com Cc: tony.luck@intel.com, bp@alien8.de, peterz@infradead.org, catalin.marinas@arm.com, yazen.ghannam@amd.com, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, jpoimboe@kernel.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, baolin.wang@linux.alibaba.com, tianruidong@linux.alibaba.com, xueshuai@linux.alibaba.com Subject: [PATCH v4 2/3] mm/hwpoison: Do not send SIGBUS to processes with recovered clean pages Date: Wed, 12 Mar 2025 19:28:51 +0800 Message-ID: <20250312112852.82415-3-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250312112852.82415-1-xueshuai@linux.alibaba.com> References: <20250312112852.82415-1-xueshuai@linux.alibaba.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 15FEEA000B X-Stat-Signature: ygt7gwnieat8n9abowz3eto5ic3fk16o X-Rspamd-Server: rspam06 X-HE-Tag: 1741778939-95676 X-HE-Meta: U2FsdGVkX19VCa8uyNKNUkZQBQCttl+uL0V+0j+9BDwgEveI2HTFjBZNy0PXubBFy2sWOm1NWvwmVNdfS6ts4hBcXuHmp+HhJXXNruirTKK0uTJRK2IpIHNcN1umJtOs9+isqlaIjIR4HOXxUj9oAP3ID/9iprwn5oB/j1+0xlmzEuVe0UQi/gS1B1YzzQrEXSmwjpkztgd/PG8Zoa3w+SEQl7RabRuNpu6AFfhSNwFqbfVOziD/Y9gwgi66AZsylSJ088NH6/+M69imPfhIF/iWfGZcDCaTQHxjlViI0yD7slW+o52yeBuD1Yj1LFoRoM4l8iXYFUfJ6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kcT63b4PLN7K4LiaaR6dx2XIKprWw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000195, 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 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. - Background: why *UN*corrected errors tied to *C*MCI in Intel platform [1] Prior to Icelake memory controllers reported patrol scrub events that detected a previously unseen uncorrected error in memory by signaling a broadcast machine check with an SRAO (Software Recoverable Action Optional) signature in the machine check bank. This was overkill because it's not an urgent problem that no core is on the verge of consuming that bad data. It's also found that multi SRAO UCE may cause nested MCE interrupts and finally become an IERR. Hence, Intel downgrades the machine check bank signature of patrol scrub from SRAO to UCNA (Uncorrected, No Action required), and signal changed to #CMCI. Just to add to the confusion, Linux does take an action (in uc_decode_notifier()) to try to offline the page despite the UC*NA* signature name. - Background: why #CMCI and #MCE race when poison is consuming in Intel platform [1] Having decided that CMCI/UCNA is the best action for patrol scrub errors, the memory controller uses it for reads too. But the memory controller is executing asynchronously from the core, and can't tell the difference between a "real" read and a speculative read. So it will do CMCI/UCNA if an error is found in any read. Thus: 1) Core is clever and thinks address A is needed soon, issues a speculative read. 2) Core finds it is going to use address A soon after sending the read request 3) The CMCI from the memory controller is in a race with MCE from the core that will soon try to retire the load from address A. Quite often (because speculation has got better) the CMCI from the memory controller is delivered before the core is committed to the instruction reading address A, so the interrupt is taken, and Linux offlines the page (marking it as poison). - Why user process is killed for instr case Commit 046545a661af ("mm/hwpoison: fix error page recovered but reported "not recovered"") tries to fix noise message "Memory error not recovered" and skips duplicate SIGBUSs due to the race. But it also introduced a bug that kill_accessing_process() return -EHWPOISON for instr case, as result, kill_me_maybe() send a SIGBUS to user process. 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. As a result, kill_accessing_process(): - call walk_page_range() and return 1 regardless of whether try_to_unmap() succeeds or fails, - 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. However, for clean pages, the TTU_HWPOISON flag is cleared, leaving the PTE unchanged and not converted to a hwpoison entry. 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 0 for "corrupted page was clean", preventing an unnecessary SIGBUS to user process. [1] https://lore.kernel.org/lkml/20250217063335.22257-1-xueshuai@linux.alibaba.com/T/#mba94f1305b3009dd340ce4114d3221fe810d1871 Fixes: 046545a661af ("mm/hwpoison: fix error page recovered but reported "not recovered"") Signed-off-by: Shuai Xue Tested-by: Tony Luck Acked-by: Miaohe Lin Cc: stable@vger.kernel.org --- mm/memory-failure.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 995a15eb67e2..b037952565be 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -881,12 +881,17 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn, mmap_read_lock(p->mm); ret = walk_page_range(p->mm, 0, TASK_SIZE, &hwpoison_walk_ops, (void *)&priv); + /* + * ret = 1 when CMCI wins, regardless of whether try_to_unmap() + * succeeds or fails, then kill the process with SIGBUS. + * ret = 0 when poison page is a clean page and it's dropped, no + * SIGBUS is needed. + */ 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 : 0; } /*