From patchwork Tue Feb 11 06:01:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13969440 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A8DD1E98E0; Tue, 11 Feb 2025 06:02:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739253736; cv=none; b=J/CZD8kFk/04HgCD7UTzlFOGGFw+m9/GRSwBYTft6VPOE/E/QnEMtz+/yxjctyQ6oQdmGXaetZEwmAbAuBaLL3DMAuzHuEbIzaEPqcuvgwRdnj9q1aGsBIpsE5vAzpsvtNY5T8Fu/OwESIbp6x19zGfMT+W4DskSeNL9CqmCXAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739253736; c=relaxed/simple; bh=81q/DV3sv7VktlDJT+CNqXu1nzzdokAh44tOdxj2jyk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e86C1BdT8UiuBfKNOeqHm90tgs7bxdNR74ePKX8/REtrXLzxBV6jmGAC7x8cn5KHU3Iy9fHVaejHnvfyH2tDMOkvGJ+DyNzM7xM2Avm3uSfQOXHxY3VTKa9QmvnyTXAK+ZGCs+uBW5PdmpEcAnQGVTMjTPB4uvAoLIkdlT/Ki90= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=SWOQVs3U; arc=none smtp.client-ip=115.124.30.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="SWOQVs3U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739253725; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=v4nYqPoOVXQKgJH/YSunWnnMJy+4Q4FHZPFcfZOd/Xs=; b=SWOQVs3UO/UVmOpGPp6I+vbXqV7/yE/iU/AU301VgZhUg7QRGPr+FD+paHllSyiaiPyLGVpV915xW44/MdH21RyBO+atRmkiXNaLZOb1cVw1Fm5B2Tiwn3kjm7vAA7Az5FHsstl8662GT/of8twB4F4gpqFqyCk5t3uauRBpUok= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPFiSHq_1739253722 cluster:ay36) by smtp.aliyun-inc.com; Tue, 11 Feb 2025 14:02:03 +0800 From: Shuai Xue To: tony.luck@intel.com, bp@alien8.de, nao.horiguchi@gmail.com Cc: tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linmiaohe@huawei.com, akpm@linux-foundation.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, baolin.wang@linux.alibaba.com, tianruidong@linux.alibaba.com Subject: [PATCH v1 1/4] x86/mce: Collect error message for severities below MCE_PANIC_SEVERITY Date: Tue, 11 Feb 2025 14:01:57 +0800 Message-ID: <20250211060200.33845-2-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250211060200.33845-1-xueshuai@linux.alibaba.com> References: <20250211060200.33845-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-edac@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, mce_no_way_out() only collects error messages when the error severity is equal to `MCE_PANIC_SEVERITY`. To improve diagnostics, modify the behavior to also collect error messages when the severity is less than `MCE_PANIC_SEVERITY`. Signed-off-by: Shuai Xue --- arch/x86/kernel/cpu/mce/core.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 0dc00c9894c7..2919a077cd66 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -925,11 +925,12 @@ static __always_inline void quirk_zen_ifu(int bank, struct mce *m, struct pt_reg * Do a quick check if any of the events requires a panic. * This decides if we keep the events around or clear them. */ -static __always_inline int mce_no_way_out(struct mce_hw_err *err, char **msg, unsigned long *validp, - struct pt_regs *regs) +static __always_inline bool mce_no_way_out(struct mce_hw_err *err, char **msg, + unsigned long *validp, + struct pt_regs *regs) { struct mce *m = &err->m; - char *tmp = *msg; + char *tmp = *msg, cur_sev = MCE_NO_SEVERITY, sev; int i; for (i = 0; i < this_cpu_read(mce_num_banks); i++) { @@ -945,13 +946,17 @@ static __always_inline int mce_no_way_out(struct mce_hw_err *err, char **msg, un quirk_zen_ifu(i, m, regs); m->bank = i; - if (mce_severity(m, regs, &tmp, true) >= MCE_PANIC_SEVERITY) { + sev = mce_severity(m, regs, &tmp, true); + if (sev >= cur_sev) { mce_read_aux(err, i); *msg = tmp; - return 1; + cur_sev = sev; } + + if (cur_sev == MCE_PANIC_SEVERITY) + return true; } - return 0; + return false; } /* From patchwork Tue Feb 11 06:01:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13969437 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4360E26BD98; Tue, 11 Feb 2025 06:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739253731; cv=none; b=lMMS4+Ja9GPeICUsMOh90UrYdAGKlhHxcONwBd/ZSwU9b1T77oVArf9/nOvsu3R3WuCCdS3VP1bWiXZ5SKoDXTn3SptCR+N7adz1dksfexvWKOKLqT8izs1MQaf/PwUPcEOq25LUNND+UKlKqnfbysSLVKNQ3kNX91AFpPrFBDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739253731; c=relaxed/simple; bh=9TlBQFKfgo8qm9vvVdscR3v2j2Y9oifJALzQb7jwKBM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GhYvSUDc7nD6sfKivz4yF+rg2vrSIDE9yUB03Ty1+UDOMXLS3f/GV/XzJ0GIpEKXH3fr9l0jPA7qUjne1M9wWefWG+zTAaX/skOuUngQ+Lg2fIgYioUVBbla1lX5M/MRGJlMlbSDxxoq4C9OW2xPw5l1pXQmhzaqJz0roWyLA90= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=sPAB7Qcp; arc=none smtp.client-ip=115.124.30.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="sPAB7Qcp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739253726; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=tlo8q8j4Pp6YSO9Kcn8UqITwpqL/bxjMQZvrf+MMEtk=; b=sPAB7QcpRbwxVaM08+jD4tRIeDfIyOhBCHLXsmCt4x9+58IR5Gb4iEUWOmjlJ6RM1HhRrZ0P7p5QoiUaFqELWljdnO6ISDJGYB4V28EH85rBz+iRVFDdTyB6SUsWOP2yf9mQpz+Oz5w2YTWyUstXmTrVENpZhRAoL4MEfWO1qXI= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPFiSI3_1739253723 cluster:ay36) by smtp.aliyun-inc.com; Tue, 11 Feb 2025 14:02:04 +0800 From: Shuai Xue To: tony.luck@intel.com, bp@alien8.de, nao.horiguchi@gmail.com Cc: tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linmiaohe@huawei.com, akpm@linux-foundation.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, baolin.wang@linux.alibaba.com, tianruidong@linux.alibaba.com Subject: [PATCH v1 2/4] x86/mce: dump error msg from severities Date: Tue, 11 Feb 2025 14:01:58 +0800 Message-ID: <20250211060200.33845-3-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250211060200.33845-1-xueshuai@linux.alibaba.com> References: <20250211060200.33845-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-edac@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The message in severities is useful for identifying the type of MCE that has occurred; dump it if it is valid. Signed-off-by: Shuai Xue --- arch/x86/kernel/cpu/mce/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 2919a077cd66..c1319db45b0a 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -1456,6 +1456,8 @@ static void queue_task_work(struct mce_hw_err *err, char *msg, void (*func)(stru if (count > 1) return; + if (msg) + pr_err("%s\n", msg); task_work_add(current, ¤t->mce_kill_me, TWA_RESUME); } From patchwork Tue Feb 11 06:01:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13969438 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 543961D5CD9; Tue, 11 Feb 2025 06:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739253731; cv=none; b=lbG7mzYbF6LgnnuPMJzANiu+Wk3AC/kk+e9p6PnuX8e1KOVzR5V+/jxRYftp3+s6ZoA4qndWXxKukkp1xGC4oKB3fG5yU17HDUzN4x7HdYH/+SbVLLWN+0RBWrhDHyWKISxMS2oUSp98hSLlUGbzsjLUF7/XJ4jCr0A+X+iWRU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739253731; c=relaxed/simple; bh=/cLBrEIhLQ3n08yvWEKwzxH0hYx0q6II9tU6JMD/8f0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nlrqxFnvMz4a4hHxmhmV5bHOy2QLqHln/AXE6yxGzwdm98NYMRGgeRYRZpXlFATITS3Hpm6szT+CSkt+kMAv7Dbx4pZBIBDetsyhVHKcwJUfFzoDRCZYaGwM9YVjxxvNoW5WaaxIJXrGGipBUP7nT1iAEgd4OFjOCpV0Is5KNj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=IBv4NDd/; arc=none smtp.client-ip=115.124.30.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="IBv4NDd/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739253726; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=hfmiBx8OqSwf83Pjl+Ndh5ksVZvALy8DLh1zZo/PfR0=; b=IBv4NDd/IZMNMZ3ebccSd1/tyOAXFlXZDmAtA2WvCQZYNW4tKXLSJ5lkWDkS4cbqE1Ae/SxDxrEdbvjjTV2j3qobKEjyQZTG+2IAmWPJsxj4sHQmnPcn2tYg2rh4vJlLZ1oOriBra4dc2u1+FSaRsVZ6rsOhDwjwwBWjbT26BXU= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPFiSIJ_1739253724 cluster:ay36) by smtp.aliyun-inc.com; Tue, 11 Feb 2025 14:02:05 +0800 From: Shuai Xue To: tony.luck@intel.com, bp@alien8.de, nao.horiguchi@gmail.com Cc: tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linmiaohe@huawei.com, akpm@linux-foundation.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, baolin.wang@linux.alibaba.com, tianruidong@linux.alibaba.com Subject: [PATCH v1 3/4] x86/mce: add EX_TYPE_EFAULT_REG as in-kernel recovery context to fix copy-from-user operations regression Date: Tue, 11 Feb 2025 14:01:59 +0800 Message-ID: <20250211060200.33845-4-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250211060200.33845-1-xueshuai@linux.alibaba.com> References: <20250211060200.33845-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-edac@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Commit 4c132d1d844a ("x86/futex: Remove .fixup usage") introduced a new extable fixup type, EX_TYPE_EFAULT_REG, and later patches updated the extable fixup type for copy-from-user operations, changing it from EX_TYPE_UACCESS to EX_TYPE_EFAULT_REG. Specifically, commit 99641e094d6c ("x86/uaccess: Remove .fixup usage") altered the extable fixup type for the get_user family, while commit 4c132d1d844a ("x86/futex: Remove .fixup usage") addressed the futex operations. This change inadvertently caused a regression where the error context for some copy-from-user operations no longer functions as an in-kernel recovery context, leading to kernel panics with the message: "Machine check: Data load in unrecoverable area of kernel." To fix the regression, add EX_TYPE_EFAULT_REG as a in-kernel recovery context for copy-from-user operations. Signed-off-by: Shuai Xue --- arch/x86/kernel/cpu/mce/severity.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/severity.c b/arch/x86/kernel/cpu/mce/severity.c index dac4d64dfb2a..14c2d71c3ce1 100644 --- a/arch/x86/kernel/cpu/mce/severity.c +++ b/arch/x86/kernel/cpu/mce/severity.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "internal.h" @@ -285,7 +286,8 @@ static bool is_copy_from_user(struct pt_regs *regs) */ static noinstr int error_context(struct mce *m, struct pt_regs *regs) { - int fixup_type; + const struct exception_table_entry *e; + int fixup_type, imm; bool copy_user; if ((m->cs & 3) == 3) @@ -294,9 +296,14 @@ static noinstr int error_context(struct mce *m, struct pt_regs *regs) if (!mc_recoverable(m->mcgstatus)) return IN_KERNEL; + e = search_exception_tables(m->ip); + if (!e) + return IN_KERNEL; + /* Allow instrumentation around external facilities usage. */ instrumentation_begin(); - fixup_type = ex_get_fixup_type(m->ip); + fixup_type = FIELD_GET(EX_DATA_TYPE_MASK, e->data); + imm = FIELD_GET(EX_DATA_IMM_MASK, e->data); copy_user = is_copy_from_user(regs); instrumentation_end(); @@ -304,9 +311,13 @@ static noinstr int error_context(struct mce *m, struct pt_regs *regs) case EX_TYPE_UACCESS: if (!copy_user) return IN_KERNEL; - m->kflags |= MCE_IN_KERNEL_COPYIN; - fallthrough; - + m->kflags |= MCE_IN_KERNEL_COPYIN | MCE_IN_KERNEL_RECOV; + return IN_KERNEL_RECOV; + case EX_TYPE_IMM_REG: + if (!copy_user || imm != -EFAULT) + return IN_KERNEL; + m->kflags |= MCE_IN_KERNEL_COPYIN | MCE_IN_KERNEL_RECOV; + return IN_KERNEL_RECOV; case EX_TYPE_FAULT_MCE_SAFE: case EX_TYPE_DEFAULT_MCE_SAFE: m->kflags |= MCE_IN_KERNEL_RECOV; From patchwork Tue Feb 11 06:02:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13969441 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E7451E3DF2; Tue, 11 Feb 2025 06:02:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739253738; cv=none; b=gSl8hjIosr+5N6Wq+ENB1VID7TSf6uKIbuaZTsJaZ2q/ky8VdZTBG3ERCVxQt9nW4MEHmfAx9cR2aW3kROyL7DotwzNXhaQddfBwkU8jlJrVbLxOWw85cTGfCAaAueBDrzSaUOmz4bURIhD87lAhlUNwbhXWT+a2yRmnqxTYYRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739253738; c=relaxed/simple; bh=RkIOq+yMW57uuxCtNKxSE7c7bKxX+2UwZSbM+XjszGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=khf9868FYz7vokscSTlh5z4lFDLSEMYQuKgfu8LzfnSBb9n+1vgLaPfl+mHWRyHHsuIQnET4IzSqIBe56zuBaekWRm6x/RFTeK64P7FF8IYy9R9erzNyRzYQuZvx5xb8tq/fAxnsjDdzQ5mO5qZhzTWO0nozCZvoskZCDxVmwI4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=pWuOqqTL; arc=none smtp.client-ip=115.124.30.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="pWuOqqTL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739253727; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=uL5qJeKW+ivS15GzFIfPM3QlAABBDaL6EotBeml3uRU=; b=pWuOqqTLy78Zhjw0Cvkhlq60/WwPDcNap6kOvYitKOtRY5MZ43yQRmrTwKr4EKD8Yp9rAnh9DBFF4qwFxhfNHvRhbNoURCvg4ZwdxKqJcSpV5VrZ5xtaKkg/P8fwZnmuWyHj7eOt1xxM1P5i/E9Mq1E7/c/UI2FcqHPPpvmNR7g= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPFiSIs_1739253725 cluster:ay36) by smtp.aliyun-inc.com; Tue, 11 Feb 2025 14:02:06 +0800 From: Shuai Xue To: tony.luck@intel.com, bp@alien8.de, nao.horiguchi@gmail.com Cc: tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linmiaohe@huawei.com, akpm@linux-foundation.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, baolin.wang@linux.alibaba.com, tianruidong@linux.alibaba.com Subject: [PATCH v1 4/4] mm/hwpoison: Fix incorrect "not recovered" report for recovered clean pages Date: Tue, 11 Feb 2025 14:02:00 +0800 Message-ID: <20250211060200.33845-5-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250211060200.33845-1-xueshuai@linux.alibaba.com> References: <20250211060200.33845-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-edac@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. 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; } /*