From patchwork Mon Feb 17 06:33:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13977156 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) (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 7533D18DB3A; Mon, 17 Feb 2025 06:33:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774026; cv=none; b=U7E0blsUJJa7W/evERex1NM880TlEEOIQq1nkAsAZjiwHB8TveYAbke7CmyRthm3B1Vb5s8U7kDo1gKKPw76dmjNTeUXjnoSGwzeaCUL5JDebc2a9ljuFmzrVsWB7xa5dBFn33BSZJF1DAM0pCcXs+uHQcuKeCdbltNUQ5/d1dM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774026; c=relaxed/simple; bh=JVi9V1ouofmF0HqLDOVRpPch6QSkFiRqXWt6uPNOFvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MZCC2ATl3raqqnO9dUVCa1gsH07COmAinoHEGrGMwaVcqxpke1ytk96VYqbYTTwbzwkxPpkKaeWtgoJyJLVhv0t39CKbN/MpCEr7931cxnz6vV1at/rV6aUIPDmqRdyVYeRVAGWtcJHo8cJLEhtmDR7dvuWqctjLMTy5Dly5iEE= 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=FlvGBTqh; arc=none smtp.client-ip=115.124.30.132 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="FlvGBTqh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739774020; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=C//AWNBmkoQxyk9EmxC2ITDqwThmL3f05NW0jHto79U=; b=FlvGBTqh6c9aFIDwnAtQaUDwxcIzWCEpU0Ryver0NEwZDfggbH0YPUZInCtpm2MUoc33F/x83R//Rzszv0S22curvnB+dRnFaXR1l9nVS1Fs30O3eD50gdm4VbWHswdrSzpbBf8qSXw+Wi6IMXuLOBI3bfss65oreJua855kFxE= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPb1mOT_1739774017 cluster:ay36) by smtp.aliyun-inc.com; Mon, 17 Feb 2025 14:33:38 +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, peterz@infradead.org, 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 Subject: [PATCH v2 1/5] x86/mce: Collect error message for severities below MCE_PANIC_SEVERITY Date: Mon, 17 Feb 2025 14:33:31 +0800 Message-ID: <20250217063335.22257-2-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250217063335.22257-1-xueshuai@linux.alibaba.com> References: <20250217063335.22257-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..f2e730d4acc5 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -925,12 +925,13 @@ 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; - int i; + int i, cur_sev = MCE_NO_SEVERITY, sev; for (i = 0; i < this_cpu_read(mce_num_banks); i++) { m->status = mce_rdmsrl(mca_msr_reg(i, MCA_STATUS)); @@ -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 Mon Feb 17 06:33:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13977157 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (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 7B35614D2A0; Mon, 17 Feb 2025 06:33:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774026; cv=none; b=jIIKCkVyDZwEoxQc+zNtoZ1gkU7j8rUxD5r624Jn2jwl+VMJbilIF9Sxs8AUujd86n/SPC/+/1x+FF6DBPhXgnZNdvnDsAqjNEj2Bd0MX9tShmQlM9iztww5loJCZ3CpOhrnkZkxiZhTq61DW6Y6OaZZIoXghIcu/N4Kgq1J8Is= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774026; c=relaxed/simple; bh=gQS7lE6aR1pvIvgjR1Y3fZI8Acds0U8IcKCYS4/p84k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NJ8VKlKr/Q+6McimzZ7o2etO6mkf1BM18xSuEPnQkELrreSWt6nzpHd9kGEa0fe5xexfilh6OChoy5TfiJQRNj4iDYT/dLJeMdHjKeBDARJPbklWHHPaNoXHodK/scby/90Xr0+TWk/g9aGRiNIyy6c4EeQgPWSqvgmlktyQkbo= 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=G/FjIkAH; arc=none smtp.client-ip=115.124.30.113 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="G/FjIkAH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739774021; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=bq0U27NFG8TdcE9f/ikRqDiyjfIWEAdUTwz5YbwhJro=; b=G/FjIkAHdtoE4pIMsp/BLl7mYccI1HS8ALP0uEgJvmh2GTePuty86DKWN5yDqBDKG+RR9CFlSdkM75GJZTq6kw4mDciVxhrHM3MO7j8RGoXCyn9P9WYQ53CRN4QNzqMckmFGwUmqYt2DV4ldOTa3ytLAOEmHJ3tfElhkGKs/sf8= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPb1mPM_1739774018 cluster:ay36) by smtp.aliyun-inc.com; Mon, 17 Feb 2025 14:33:39 +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, peterz@infradead.org, 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 Subject: [PATCH v2 2/5] x86/mce: dump error msg from severities Date: Mon, 17 Feb 2025 14:33:32 +0800 Message-ID: <20250217063335.22257-3-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250217063335.22257-1-xueshuai@linux.alibaba.com> References: <20250217063335.22257-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 f2e730d4acc5..c1b945dbccdf 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 Mon Feb 17 06:33:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13977158 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (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 27E8917BB35; Mon, 17 Feb 2025 06:33:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774027; cv=none; b=QkvkkoWC4tBpfgBGLvc7QvNOLZgwzZ88oQhnxcXEDEBI+YfoIZzVgo1EBEmmyj6rs1pJWe/gajaPijSFmJyGdnfkGmXPirnWDUEVW859TfWpFqWg99TPcb9kYlLXsuXQ9OZhCAY9MJSY06yRSw37J4g8MRrLPb2twJQiyCoNoV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774027; c=relaxed/simple; bh=P/M1Ieu6akgZJqbuDK2tDFNnLXRTcQzmj/Hk9rvHtAA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BZvRDiDxH3xB9Z0iKLubuKoeQDzafbbiBlmdnAwsZsV+AtQ9ltBCsUeOUjymLmkZSCDCZY3AhTojHcUEkMfHdSJTslj8ZSCjDSe6L9Pe/8LhBQcy6K+zYYpwTrHP9W0sePChDjJLD21tArAN77cL6sMB2YOwm142zTwi8e1Zyio= 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=ceuTCBZS; arc=none smtp.client-ip=115.124.30.113 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="ceuTCBZS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739774022; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=nVZg/Xi0EFgJwO78HVQQzmH5TmzN10gdAW21xjQG3r4=; b=ceuTCBZSvIcvKrK8/rvcF6MEAimkrZA/RXC5ONxzaRWFXxn5kctpxXX/oJz6KfYXH0PzHolPRxkt9F64OKdrQ5yyiNd+cBK41i6azKYcdHNFeXQsCcm0dGUM0TIEkaRyC0OfBvH8LPujGxNJjsfSpeSPoXzKfsrECP76Er8CbqM= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPb1mQ2_1739774019 cluster:ay36) by smtp.aliyun-inc.com; Mon, 17 Feb 2025 14:33:40 +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, peterz@infradead.org, 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 Subject: [PATCH v2 3/5] x86/mce: add EX_TYPE_EFAULT_REG as in-kernel recovery context to fix copy-from-user operations regression Date: Mon, 17 Feb 2025 14:33:33 +0800 Message-ID: <20250217063335.22257-4-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250217063335.22257-1-xueshuai@linux.alibaba.com> References: <20250217063335.22257-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 Fixes: 4c132d1d844a ("x86/futex: Remove .fixup usage") Cc: stable@vger.kernel.org --- 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 Mon Feb 17 06:33:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13977159 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (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 A1ED218BC1D; Mon, 17 Feb 2025 06:33:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774028; cv=none; b=gfumYF96HjqSIHXUJdBXlYKd3Y+HsjLb3JwLdk77x6gm6iWLptr6xgeM/pEfMR5QQgAz3k2BjWS1wup/tvBuotSRg+tlypBsxHI+96YCODjDtefTW0Czwnrx9H5LXvaAz3RUNb7Coe/Kc4i/s53L+6+tVvtG9aElhwy6hqTve3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774028; c=relaxed/simple; bh=tyeqZc+X0WuP8uiwjOV0n9F+Fr+cwMxePx3EJVi8JHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jEd+XihoGJg1ZSjLXxXGwSr8cv5RUKkGKn3j0X39OviTVnblfFUblsNBL1AOMfe1xFwPVEnPPAwhWHWNmEy49lPG6CqVFuhz1TUOg6+LhJbBFkuSmftOAUDRWeWtNjcMRCb0FJhUHJatbxj0P5EUm8LQ3dYMqvrOsXkJ79VKmCo= 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=CUttw4BX; arc=none smtp.client-ip=115.124.30.100 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="CUttw4BX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739774023; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=vvMi8bcBgppidelzMl/TigrL5YZhFRFfYcEROd+lYRc=; b=CUttw4BX2Tfeg8MVmM77B3AvtOGqbsysc202/jGw7+0lMGAs/ut0QlyEP+jfnWrmeztmtBTNvagnKqNgGnBzTxKM7/NIUykck9+jpTI8dzoxLVa61qXmKOV+Znyronry3e/R5qs2SxKm3uDc1UGQbABKeSOCumXvsy1iiuqTyPQ= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPb1mQP_1739774021 cluster:ay36) by smtp.aliyun-inc.com; Mon, 17 Feb 2025 14:33:41 +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, peterz@infradead.org, 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 Subject: [PATCH v2 4/5] mm/hwpoison: Fix incorrect "not recovered" report for recovered clean pages Date: Mon, 17 Feb 2025 14:33:34 +0800 Message-ID: <20250217063335.22257-5-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250217063335.22257-1-xueshuai@linux.alibaba.com> References: <20250217063335.22257-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. 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. Fixes: 046545a661af ("mm/hwpoison: fix error page recovered but reported "not recovered"") Signed-off-by: Shuai Xue 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; } /* From patchwork Mon Feb 17 06:33:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13977160 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (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 93CE019047A; Mon, 17 Feb 2025 06:33:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774029; cv=none; b=cuGicNt+3t/wvYEpelXrc4Tpv29XwOJbgNMQUTCGBPaDkNGkDzuPj95qIHbOu+j58ZbfVR6sgbkZBMo7BnVN8B/SAyKg5QeAc3re3TRYOYXJSPPpnM6ExsKU/7jTeO9+uhDV85qShPwQ8PDmcyoYg3x7imB43dm4JvOP2EuQiUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774029; c=relaxed/simple; bh=XfWvdGo8JigBXRfzGH+PwrHhrntmXaWle3GN74VrVSc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hbNawDibdTR6OEm1HpxdzmVINvdxq2ydLXm+2V+pZyYUJsBQp1zXS8xKwKm1mSUncydbZKuaSwjPddFMTnAc53w4PWdX+mozaiCnNhY/RhJPD+ryM3J5elSZzd3xu1v0pSC/KpmTqu5OTPgsnWy927TZCtSWb96BySzCl0n6v7Y= 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=WSjrr6uD; arc=none smtp.client-ip=115.124.30.131 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="WSjrr6uD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739774024; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=2HAfRf79L/SPv5Q+bga3YvpNIcG3LqJbC8lB0lpSzQc=; b=WSjrr6uDIeBpDzPLGd+hZDrC1F6HOTHsOniX4O9MlXYAHQK0NukIXxdeHPEFi15ZVZMVxvfwIqA/zOvie7RzO3K4qSAm4oPCfZyfkO/bjsYgeaDMY0Oj9c0aJ3OpV8w/ui6gJVVxzMgcbfQSwQL/2kDCnKPB8lFmzuMBGsozaWg= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WPb1mQt_1739774022 cluster:ay36) by smtp.aliyun-inc.com; Mon, 17 Feb 2025 14:33:43 +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, peterz@infradead.org, 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 Subject: [PATCH v2 5/5] mm: memory-failure: move return value documentation to function declaration Date: Mon, 17 Feb 2025 14:33:35 +0800 Message-ID: <20250217063335.22257-6-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250217063335.22257-1-xueshuai@linux.alibaba.com> References: <20250217063335.22257-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 Part of return value comments for memory_failure() were originally documented at the call site. Move those comments to the function declaration to improve code readability and to provide developers with immediate access to function usage and return information. Signed-off-by: Shuai Xue Reviewed-by: Jarkko Sakkinen Reviewed-by: Jonathan Cameron Reviewed-by: Yazen Ghannam Reviewed-by: Jane Chu Acked-by: Miaohe Lin --- arch/x86/kernel/cpu/mce/core.c | 7 ------- mm/memory-failure.c | 10 +++++++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index c1b945dbccdf..c81695f320bc 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -1403,13 +1403,6 @@ static void kill_me_maybe(struct callback_head *cb) return; } - /* - * -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, - * - * In both cases, no further processing is required. - */ if (ret == -EHWPOISON || ret == -EOPNOTSUPP) return; diff --git a/mm/memory-failure.c b/mm/memory-failure.c index b037952565be..8649849bcdb4 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2216,9 +2216,13 @@ static void kill_procs_now(struct page *p, unsigned long pfn, int flags, * Must run in process context (e.g. a work queue) with interrupts * enabled and no spinlocks held. * - * Return: 0 for successfully handled the memory error, - * -EOPNOTSUPP for hwpoison_filter() filtered the error event, - * < 0(except -EOPNOTSUPP) on failure. + * Return: + * 0 - success, + * -ENXIO - memory not managed by the kernel + * -EOPNOTSUPP - hwpoison_filter() filtered the error event, + * -EHWPOISON - the page was already poisoned, potentially + * kill process, + * other negative values - failure. */ int memory_failure(unsigned long pfn, int flags) {