From patchwork Wed Mar 12 11:28:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14013386 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 724C6C28B2F for ; Wed, 12 Mar 2025 11:29:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0ED8F280003; Wed, 12 Mar 2025 07:29:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 026FD280001; 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 D7397280005; Wed, 12 Mar 2025 07:29:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B8178280001 for ; Wed, 12 Mar 2025 07:29:01 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BCF251CA0F8 for ; Wed, 12 Mar 2025 11:29:02 +0000 (UTC) X-FDA: 83212677324.03.C3FAF8B Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by imf19.hostedemail.com (Postfix) with ESMTP id AE6261A0009 for ; Wed, 12 Mar 2025 11:29:00 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=XiiHiyJS; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf19.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.97 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=AUMQz289DVfB1HOjnYjRuz7kksOO8gSIt6kM1fblJUxVmLbpdk7EkOOzbCup9m2uiyY8JU N0plMFqVQOXiY71hprQwH/jb7OeSI4QjPEcQGrTDKywos05H83/EgBCx0X2VCkmiSNnmJO 1J0ngIwGMEtNATNs7JSIyYrQ8EDRUiE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=XiiHiyJS; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf19.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.97 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=vDfxkI5giWrkXyBcohVPuoNEY+c5llJuxem0Ij3I5bc=; b=VbEPy6rkYE4pfI5rCxAzjV96CnPx5fV5o2rgy+LZXw4SDztLvBYQq7DnIKTjwC5BHlmBxp QqkpKDfLl44fo9TL7E934w1gK4WZc//oOMJ/ja/72lfcI/h4QI52u5IxQ6bdoAlwBzlFgE jJwUHCYbONUo+OiUxMhm6hddunEIy5o= 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=vDfxkI5giWrkXyBcohVPuoNEY+c5llJuxem0Ij3I5bc=; b=XiiHiyJSasEU+6GzgSOkMpeqxWs8aKhkUP8/a8RZW/3/EgoAXmRQnEuNEjj4zWl2BU3Po6pZLFvc1yc7SsKvCKX+h6k7EM0nA663hA1OJetrB4DapwAbB2sQTtZHYCHlsBT9DUQViNu3/Jkl8fIuK4NNajH2O3WtstZodvhrlzo= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WRCdv11_1741778934 cluster:ay36) by smtp.aliyun-inc.com; Wed, 12 Mar 2025 19:28:54 +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 1/3] x86/mce: Use is_copy_from_user() to determine copy-from-user context Date: Wed, 12 Mar 2025 19:28:50 +0800 Message-ID: <20250312112852.82415-2-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-Stat-Signature: pysojb86xfuh9id9phtyshhgiswyy1xz X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: AE6261A0009 X-Rspam-User: X-HE-Tag: 1741778940-605070 X-HE-Meta: U2FsdGVkX1+z/Yv54BrJYLIHzYdo/732F0dpXlt1i9wltDrUdzrF91pdvd2HYUTLxRCksOg2Arf37TPc0qmgB0zqn5Apuip3ShX3tDDErw10t+spSoXiuilkvO0lta/XdzFcq2Bqqrx/5SAZdHQqMwl2icYdsebSkIyD0O2d+LR94Xsd8x2ndrhy5PsZLHHpxeOcDZSW1UUXvoq6KX9+iZa7vKfAUSj0U7rxcZsZqBvPokqe/2ApNc7v+We1mPzcwWYt9Z8msqC990qzPDvZAjFzk1x91/G6mtBASA+L6NtGyh2xDn6QopFyiLkYSlMe/PorpboAtLOubeHoPjFMSNIM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eD5aKpkZ1YAXr3Nhq+WJSlaGaMuOW2KY= 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: List-Subscribe: List-Unsubscribe: Commit 4c132d1d844a ("x86/futex: Remove .fixup usage") introduced a new extable fixup type, EX_TYPE_EFAULT_REG, and commit 4c132d1d844a ("x86/futex: Remove .fixup usage") updated the extable fixup type for copy-from-user operations, changing it from EX_TYPE_UACCESS to EX_TYPE_EFAULT_REG. The error context for copy-from-user operations no longer functions as an in-kernel recovery context. Consequently, the error context for copy-from-user operations no longer functions as an in-kernel recovery context, resulting in kernel panics with the message: "Machine check: Data load in unrecoverable area of kernel." To address this, it is crucial to identify if an error context involves a read operation from user memory. The function is_copy_from_user() can be utilized to determine: - the current operation is copy - when reading user memory When these conditions are met, is_copy_from_user() will return true, confirming that it is indeed a direct copy from user memory. This check is essential for correctly handling the context of errors in these operations without relying on the extable fixup types that previously allowed for in-kernel recovery. So, use is_copy_from_user() to determine if a context is copy user directly. Fixes: 4c132d1d844a ("x86/futex: Remove .fixup usage") Suggested-by: Peter Zijlstra Signed-off-by: Shuai Xue Acked-by: Borislav Petkov (AMD) Tested-by: Tony Luck Cc: stable@vger.kernel.org --- arch/x86/kernel/cpu/mce/severity.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/severity.c b/arch/x86/kernel/cpu/mce/severity.c index dac4d64dfb2a..2235a7477436 100644 --- a/arch/x86/kernel/cpu/mce/severity.c +++ b/arch/x86/kernel/cpu/mce/severity.c @@ -300,13 +300,12 @@ static noinstr int error_context(struct mce *m, struct pt_regs *regs) copy_user = is_copy_from_user(regs); instrumentation_end(); - switch (fixup_type) { - case EX_TYPE_UACCESS: - if (!copy_user) - return IN_KERNEL; - m->kflags |= MCE_IN_KERNEL_COPYIN; - fallthrough; + if (copy_user) { + m->kflags |= MCE_IN_KERNEL_COPYIN | MCE_IN_KERNEL_RECOV; + return IN_KERNEL_RECOV; + } + switch (fixup_type) { case EX_TYPE_FAULT_MCE_SAFE: case EX_TYPE_DEFAULT_MCE_SAFE: m->kflags |= MCE_IN_KERNEL_RECOV; 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/gS1B1YzzQrEXSmwj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h3EVUnEYgCnkjvw9MQ6fZ7tq4Ad4mKfe4XWVJq4AmMGARbmC1+scZiRXVqCyKKBNyhgtL7xNVkKb1yozLKDveUBzGJTvZ+iZT38Ou8O8n9MZrfP8VnHNyJzz+EHugkNOklXkcT63b4PLN7K4LiaaR6dx2XIKprWw= 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; } /* From patchwork Wed Mar 12 11:28:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14013387 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 8B9CDC28B2F for ; Wed, 12 Mar 2025 11:29:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9458C280005; Wed, 12 Mar 2025 07:29:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F8B5280001; Wed, 12 Mar 2025 07:29:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77198280005; Wed, 12 Mar 2025 07:29:03 -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 5A619280001 for ; Wed, 12 Mar 2025 07:29:03 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5AE31140F87 for ; Wed, 12 Mar 2025 11:29:04 +0000 (UTC) X-FDA: 83212677408.05.A1B367A Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf17.hostedemail.com (Postfix) with ESMTP id 4401040002 for ; Wed, 12 Mar 2025 11:29:01 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=l+osHe5E; spf=pass (imf17.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=xueshuai@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741778942; 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=R4Y2pmrTYmO5bH57hWQGBotlkwzT7/jOJNJhq77FZVM=; b=r5lgg2QoMGobm3Vyf2n6+NaZdj94Ml0IQnrVPY436ELgi6n3lP6rqRsRc+bei0kFMgyexC Q5at7uJ9F794lvu0aBO2EjSiJMFEeVdQq4NV8yR1+Bl6dpzPZwGXEWxtVg8InsRDZ5Sdx4 QWg3nS6hQa0ubqxy5hfJICxxicqhKPE= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=l+osHe5E; spf=pass (imf17.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=xueshuai@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741778942; a=rsa-sha256; cv=none; b=HDs5uYjKQKdC0LBr9QRl0otGSavDpBAf4pxlOSsD3ySlCbsUg3/vt9gXG4hrze84WNHy+E nsnpHFE2XlIn5d/XKZTG0ou0bKws/9EQ1ykczNIE/eynDCs8UCoB9LAV790M53YbUSr3my lrXDVp4rLEB1E33vpGLQOGkrA2a/r+E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1741778937; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=R4Y2pmrTYmO5bH57hWQGBotlkwzT7/jOJNJhq77FZVM=; b=l+osHe5E+0x5kCoyi8YGZ0mXf1/uREkuaJcqA2kJcZ5Ho4EG/+9mToEviln35roYuyOtXNX14tzoodWdO0KLWOIacPW1zbAj9E0clrUZO08pV6DRXtMKOLPQpO7QV0xsYjV4VnA2Kjpf0DEPs3qVJytouyUCre3xXii1wz9tsr4= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WRCdv1i_1741778935 cluster:ay36) by smtp.aliyun-inc.com; Wed, 12 Mar 2025 19:28:56 +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 3/3] mm: memory-failure: Enhance comments for return value of memory_failure() Date: Wed, 12 Mar 2025 19:28:52 +0800 Message-ID: <20250312112852.82415-4-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: 4401040002 X-Rspamd-Server: rspam03 X-Stat-Signature: gn5wxq4nqi47m5zxcq7363qscmadssdz X-HE-Tag: 1741778941-90141 X-HE-Meta: U2FsdGVkX1+Fh6Cs6/U/UzuOaWxTGgYLL6zsnQ1gpmc28ggMDWQFjfNbMeXl7w9Ze4/z1NhdXkPgbwPNbcWdyVtPp0CXB7b9PgJRzMQsUanX4kHKKSHRcMeb3nLZYd86Ry9YYRMwajAmuMrMg0Fn3WoLRh+jjOe8Yzq/lDsis052+0w6x0Fhax9fglnI/XNJug5yxHMOEW97UD+aT7z9yuP9FGQ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dT0ouahnLEMgARDh75IvEw8/45mPQtW5XZVwpn13+YI5yPmY7uuEI4Du93qgeusu/s7eQv9kHfzXcq6o3vJIF8eaIoQ+EO004fQ80l1o/yZBiamDLcyymbq1wnj+3ePUYaiD1n5hC2VoACyJQT4AaGzrDU6GhqG8vWoq1tTYQGolw== 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: List-Subscribe: List-Unsubscribe: The comments for the return value of memory_failure are not complete, supplement the comments. 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 Tested-by: Tony Luck --- mm/memory-failure.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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) {