From patchwork Thu Mar 6 02:10:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14003739 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 77380C28B22 for ; Thu, 6 Mar 2025 02:10:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 31E62280003; Wed, 5 Mar 2025 21:10:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C77B280006; Wed, 5 Mar 2025 21:10:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1303A280003; Wed, 5 Mar 2025 21:10:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E45FD280006 for ; Wed, 5 Mar 2025 21:10:39 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6E2C51C80D5 for ; Thu, 6 Mar 2025 02:10:41 +0000 (UTC) X-FDA: 83189497482.08.DEDA8B1 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by imf19.hostedemail.com (Postfix) with ESMTP id 1ED321A0002 for ; Thu, 6 Mar 2025 02:10:38 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=x7IIJBkI; spf=pass (imf19.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.110 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=1741227039; 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=1/JD5Tq5dpzFixCp5vAo+Imjs5Cylkbn9pyvuB+VoBk=; b=XhyUv/IsABsiPof//7APKRqSpmtBU1Fwta3CSWQ3A2LCO7Dp+3SiSjPjpLrajV8nv6ips4 SAb8JwFKv0exWswSRaYkxd/ilnkxnDdbOVsu3dIqfRvgIzM+qed3c/8B8+OKjhjW1BQU+A bN+Z3l+tNm3OlzhDP2TVfh67q1FIgAw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741227039; a=rsa-sha256; cv=none; b=FM0arc4/xB3yZ/StMbfk1T8DreirJ0VotJmJ1oW7L5CdlNgrU0v63tRJG+6ZeASKXZPUEJ LT6EyFMQKc7E/enOEIW8OWqcsP4MB5UksTa8ZcfdmOlXrC8Yb9ZIv3qCAlr4dLGPmNnG9a S6uxzDCd2sATUASOUCzXdEIf8yen4w0= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=x7IIJBkI; spf=pass (imf19.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.110 as permitted sender) smtp.mailfrom=xueshuai@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1741227036; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=1/JD5Tq5dpzFixCp5vAo+Imjs5Cylkbn9pyvuB+VoBk=; b=x7IIJBkI0QNLH/IrNRXcMZgEVnEjmnhgQ/JwLH4KlthuH/wrnc4Sqg0ABt74RZvog9LBevKXkfPYPDXjpoOWXsJ0LLKAZuIFINi9JAssf+WY8kMbKLXqlwAXU5wo9m7WHk05Pn7fqpW0T/xWwZm3x3cwu84hdwBE13mEBS3aWQw= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WQmzy.1_1741227033 cluster:ay36) by smtp.aliyun-inc.com; Thu, 06 Mar 2025 10:10:34 +0800 From: Shuai Xue To: tony.luck@intel.com, bp@alien8.de, peterz@infradead.org, catalin.marinas@arm.com, yazen.ghannam@amd.com, akpm@linux-foundation.org, linmiaohe@huawei.com, nao.horiguchi@gmail.com Cc: 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 Subject: [PATCH v3 1/3] x86/mce: Use is_copy_from_user() to determine copy-from-user context Date: Thu, 6 Mar 2025 10:10:29 +0800 Message-ID: <20250306021031.5538-2-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250306021031.5538-1-xueshuai@linux.alibaba.com> References: <20250306021031.5538-1-xueshuai@linux.alibaba.com> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Stat-Signature: p8xzdgsx95s9rh47ai3u869gpiku8odo X-Rspamd-Queue-Id: 1ED321A0002 X-Rspam-User: X-HE-Tag: 1741227038-725891 X-HE-Meta: U2FsdGVkX1+QARdpcv25mTghXVxPmRuRAIZPUAYOchose6MhOaXSbBue8Sc4hirmgUlJ0Ls/igoqDYJwkDg0Flr4Vccf2cE5IRvU25rad/1aoZGEENIh8dGfzpCqL/aU1CtwstRKNqbdrtYmAiB5dNFZh+934roEfoWc3yNcvMurAPO0xbYAO6Uh3zReg9jCbJX4m8JzBrJ2T1fRaJJl4TKaEja2GO2hTr1Cguc3OIDhAEJ4I77b27D6vY0KtTaxXR4G8nDSEp4fAxEPm+L7TOwHGYgvDZoLKItX78KWebnL5j0BS5WX9u+ZzJbzMj203N60Hnx0+XmSwc8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mNYM6tD1ti3y4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000030, 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." The critical aspect is identifying whether the error context involves a read from user memory. We do not care about the ex-type if we know its a MOV reading from userspace. is_copy_from_user() return true when both of the following conditions are met: - the current instruction is copy - source address is user memory So, use is_copy_from_user() to determin if a context is copy user directly. Fixes: 4c132d1d844a ("x86/futex: Remove .fixup usage") Suggested-by: Peter Zijlstra Cc: stable@vger.kernel.org Signed-off-by: Shuai Xue --- 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..cb021058165f 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_COPYIN; + 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 Thu Mar 6 02:10:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 14003740 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 101EFC19F32 for ; Thu, 6 Mar 2025 02:10:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D17E280007; Wed, 5 Mar 2025 21:10:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3813B280006; Wed, 5 Mar 2025 21:10:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2255E280007; Wed, 5 Mar 2025 21:10:41 -0500 (EST) 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 01ED9280006 for ; Wed, 5 Mar 2025 21:10:40 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 82762160DFB for ; Thu, 6 Mar 2025 02:10:42 +0000 (UTC) X-FDA: 83189497524.12.F1D8934 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by imf25.hostedemail.com (Postfix) with ESMTP id 41F01A0007 for ; Thu, 6 Mar 2025 02:10:39 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=FRwjkhFn; spf=pass (imf25.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.110 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=1741227040; 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=0Z4b4sITWeCYSe6qVPzMI52ddHUIEkqBypCvt4Knc4I=; b=aeOoTV+s4EvmVGQfwNnSSSqmW1FN8gfxqy3O7oqp2pqZ8P8SODrRQyqb2XI90M7hvR0OLr LIqxyQcVLTb4jI9EnspjvnGnOaakIp9aUvNtkDwpbzNGaLrsj7F3Jb5rLczE46jjpAbGk2 dCqllIfGubznFdq/krjS0wHu7ZtlWE4= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=FRwjkhFn; spf=pass (imf25.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.110 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=1741227040; a=rsa-sha256; cv=none; b=O0R5dVhPvk+V42bhMWsrKe91dnh3B3E3z35DC4GGYuqzCe+OOXZTlm5Ut2GGCafkBm4IgT zAz+TOg8LtrIXT2GGuvPJgQKL72KbNEvy4Xu6gxiPCWcVhtT2cW9NW92wxAprEP7+VTuJS EKX9Fg7nhzY28ZWlt7gWrtCzUBbrrW0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1741227037; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=0Z4b4sITWeCYSe6qVPzMI52ddHUIEkqBypCvt4Knc4I=; b=FRwjkhFnaZs109yDiMGdo83IPRWAq6LVt8cwivOJAZHO2i2ucMSl3ZNfTAfe3K9PweT9imIVkUfX2yEEN2rFVYoKnq3CJxN4ZbGo2ihyAgcYu2IzLqsZapFwWSl1sAAan0E2kWL0OOGAmkRfTAByyS6s/VYbOQhbbJaz33h2kKY= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WQmzy.c_1741227035 cluster:ay36) by smtp.aliyun-inc.com; Thu, 06 Mar 2025 10:10:35 +0800 From: Shuai Xue To: tony.luck@intel.com, bp@alien8.de, peterz@infradead.org, catalin.marinas@arm.com, yazen.ghannam@amd.com, akpm@linux-foundation.org, linmiaohe@huawei.com, nao.horiguchi@gmail.com Cc: 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 Subject: [PATCH v3 2/3] mm/hwpoison: Do not send SIGBUS to processes with recovered clean pages Date: Thu, 6 Mar 2025 10:10:30 +0800 Message-ID: <20250306021031.5538-3-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250306021031.5538-1-xueshuai@linux.alibaba.com> References: <20250306021031.5538-1-xueshuai@linux.alibaba.com> MIME-Version: 1.0 X-Stat-Signature: bhgt9uuah8q376jiw74e38gmhyom6jbh X-Rspamd-Queue-Id: 41F01A0007 X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1741227039-40314 X-HE-Meta: U2FsdGVkX1/EfLE2WDXmgbjiV+aNLzpZH4o6Z/RQ4gElIKB+3r1XCa0OYKiK9xBHXi362wXmRKoXf18/bkgA6WMz77eoVMKID5JBGLR7775qP+d5VPim0vKuDR5Au4epO3P8mhihlhMTIvOsp5i4lIeJIqaZD/IO8uKZTNmuZ9qlL2E51LTcCDdURkwx1tacnnrKfk+3jfbmWfhwq8Q9FdiAkPF2psty88zl3w3xBaBlse+sDAGqK1JncwPfv7Bvr6cPLp/2EuZEhtaF/ZWI7Qa2sIkpeO7tKUfCwrC3gz1HdI/tGVDEAhuMWymNYnichPi5Z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amicity=0.001240, 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 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 Thu Mar 6 02:10: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: 14003741 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 CA826C28B22 for ; Thu, 6 Mar 2025 02:10:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5984280008; Wed, 5 Mar 2025 21:10:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B8C88280006; Wed, 5 Mar 2025 21:10:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2D15280008; Wed, 5 Mar 2025 21:10:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7EEFE280006 for ; Wed, 5 Mar 2025 21:10:42 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D4B0C1A0DD4 for ; Thu, 6 Mar 2025 02:10:43 +0000 (UTC) X-FDA: 83189497566.13.90811CF Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf29.hostedemail.com (Postfix) with ESMTP id D679112000E for ; Thu, 6 Mar 2025 02:10:41 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="GATmpJ/z"; spf=pass (imf29.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.132 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=1741227042; 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=zNNjpjby7OEVOGOuCOx/+9vNU60KKs/GI6CHsj1/Iek=; b=eFB7X06qdSWIp84OyprTofdSLAI/YylU5VGD4ZzNdKKKJkvCDihx/hGLQUSU2IPVKJw3OW GrgRL7/kCxwwpjHdUcnZZf0/C3MOSToT0ysQuhUL+EXSA9EOzuTU5NYJncwJeVhU/Mkvbt p2b2aD9kn9ckRhTXLep8OgPfnCsUcBU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="GATmpJ/z"; spf=pass (imf29.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.132 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=1741227042; a=rsa-sha256; cv=none; b=KAhkO71pzFvGCiouRI+bIMaxgSbBe9M/gjtUFdmJG1kpMTxQIDZh+FljPSPgcuFZ82kyDp 2oOlZaLaE93ttOHczlTak5rkKYJsdXBlkFzMdUg0P6v2anrqAyeGj9sKNXXp/stReQzIGz OqksnuqYThAyT6m1zNizL26+dbYyq3w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1741227039; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=zNNjpjby7OEVOGOuCOx/+9vNU60KKs/GI6CHsj1/Iek=; b=GATmpJ/z18XaQ835Tf33p+yR/ngR0R5TiVsrb1U28BN4p6D7CiuNKpKvTseRRmp/hZZTHXBBA9apGHiX1lgvvFcdBe/zLTNjMwxLBP9yW8JX1qd4EYcXFbfEjRHn4/odFHKkSmTvf63HwcBEOrtQrFDq1Mol5x20PCI6rrfdOUo= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WQmzy09_1741227036 cluster:ay36) by smtp.aliyun-inc.com; Thu, 06 Mar 2025 10:10:36 +0800 From: Shuai Xue To: tony.luck@intel.com, bp@alien8.de, peterz@infradead.org, catalin.marinas@arm.com, yazen.ghannam@amd.com, akpm@linux-foundation.org, linmiaohe@huawei.com, nao.horiguchi@gmail.com Cc: 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 Subject: [PATCH v3 3/3] mm: memory-failure: Enhance comments for return value of memory_failure() Date: Thu, 6 Mar 2025 10:10:31 +0800 Message-ID: <20250306021031.5538-4-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20250306021031.5538-1-xueshuai@linux.alibaba.com> References: <20250306021031.5538-1-xueshuai@linux.alibaba.com> MIME-Version: 1.0 X-Stat-Signature: deiwxy5tqk8ziraom4rri5ad9ob1whx6 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: D679112000E X-Rspam-User: X-HE-Tag: 1741227041-484959 X-HE-Meta: U2FsdGVkX1/Jxx6taX0C5qibSqlVMEwwvDLkq3Xst1C6AepcOyO/6Be6kgVsPJcgQylM+bdICv0ph1IgqWBTOfytwjuh58u/RU1+teanCFrSEKHRNMGuDfCpt0sxtthaPRHsyfH9CWxLXWirxw8f+JSTeWoHHWiRGc7QeD0ESaxv7Aodjtz5mXRAJjvtrjd6VUjnCoTLSU1RvwyvQYboVGT/0U25m5vC66B6TiJf6vJZ0dbYKil80jCtCW5S/eM7178jfI8O7Y9h5nAHDE97DEfPoKSm6I3ijysiudD3Gf5lPtD0VZeLqj/Fk3YCFXBoJJb6iijO6D4HAWBr24iYbk2PBudhwP6y0nXPBg91tr83zIf2He0R1WuH+sqCZIsZGEJuj8I9oJhdac5L5qtxIZkNdtR4S8knIYwr5wsabEGPvjEiYdypi314WuBOCDfuE8cPodARqzlc9x8Gd1HIViXQ75FRXJ9QM83AeiHZYozHSaLxnqd0woSixWXspoArWjdHc97M/YaXJokS+GcLSlwmjHXiYQKk16+bYm97raycwCdi5Yj76ugTVTFBhh93ZTfVIRRGdjqUoTttsEaqSgDuN9UX4etaCxMk3pBi/zZl6KC/92a2OIcwinjOunyCthHcG6fVnGpaEV9zdCmQ9Xxb1HNGKAFMcve1XHY5bdSq95XohvX+G20MaZ6Wjg8KEh6NVbTl2WPcJHaR3TcUqI+v01BGbJgDDb5VSEfTJo8Imtu7BUwFbzU/b0j60Ssvdk4ji+3Gsbp4lpH8vL/uguCxlaojxjZs5wrjgeRLma2UWVW/9wa9SbOD2j+vF3Q5VPSJs0czUKVfJ0/r6VmtSjV1ErMzRZm8EHYzpNEex2XcMSLfkAgYiP+ZlTDkEqva2/7xw7LV3Do6Z+oqWUXwbp7TLJZ4HjdhodvCY3s5K3CZzH3jUI9fJdrFTF9wEri1i2mbkSMxjWOvIu5bhwp lujfak3Z b6bFtfPdviWO7/bWZBMiASYMSIyuY6i9RBRn8/aRTvLRzpO5FLAszkBhXbZTlP5AM2bYYUcaCX1eZZDMrEYuO8P99x+LPJ8w2RwzH19hL19AtBpPQtOWv2qM0k7LhZ8lT8JdMdmR7t7z4iw6J66dtSKNj9d5To6xK8Xu/enFsoNUnM2upxPAGfJE7NtmjQFHYx1kFVM68avfh6nwxYGX+Fr1Hyv0USfPh4fXoH3ieOOSjvewhojW3m2OeVomJXLrZZvCCXfnYLGoBCZExq8VYosyXeifLpJQvR9KlDYz4kA+PEvdHNVAtOu3afEdpF4xPK3OQWfa6hrRTiXbMY949tBQBh4nhFS9NAPg/KpyX5s/awvLEQG4kGZZ1PzVbsfXtYhcmYWFfNHitkpcsDrjk7a3zaEfcwBtVaFcn0i2dhVCf3LkgXGU0OtnfJw== 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 --- 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) {