From mboxrd@z Thu Jan 1 00:00:00 1970 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 041B1C7882F for ; Fri, 20 Sep 2024 12:15:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D63A6B0082; Fri, 20 Sep 2024 08:15:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35FB66B0083; Fri, 20 Sep 2024 08:15:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2003B6B0085; Fri, 20 Sep 2024 08:15:06 -0400 (EDT) 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 F1D2F6B0082 for ; Fri, 20 Sep 2024 08:15:05 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9F01AC02ED for ; Fri, 20 Sep 2024 12:15:05 +0000 (UTC) X-FDA: 82585010970.30.0646DF1 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by imf26.hostedemail.com (Postfix) with ESMTP id 1498514001E for ; Fri, 20 Sep 2024 12:14:58 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=GeHZPQFj; spf=pass (imf26.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.97 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=1726834388; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iXz1a8wbqLWAyQb93ZIDKPeN5RtD2+gJiC+TI4LF2A4=; b=33eH5pnY1JPELiPnHcEwQ5FASw1yB4zcwRBQWkUzmS24An11NKLqjPAJl8aXC+7wYlqbTM kDLUVE4ugqGZRhhcJRPpxwZd/n5RJ1Hqw+B5GkJ0ax9HQgxNzsuPbHzJu97XlUg8obt6+J gO1J5+W8wfdhvp9roCSP9kfozhjV2Wg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726834388; a=rsa-sha256; cv=none; b=6IMYduox6w2pizmm6PaC5I7+zFugj61Uzey8aakJXENMiT9FOGBZDvcI+AsP9pMUJUevRW TMOv6BX/BsSt5yHggL2oPoAO42muq04Wj0FRsSVSG/NgKDZUvEC58u9Q8E9DiSYWHzngbi EaVCxBeI1VxLBBYcU/pnZCvXGot4dQY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=GeHZPQFj; spf=pass (imf26.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.97 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=1726834489; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=iXz1a8wbqLWAyQb93ZIDKPeN5RtD2+gJiC+TI4LF2A4=; b=GeHZPQFjkoEfrAy+af/hIjo14W86gbNjLZiEAveQuzLzlhuSmXJQCv0yYi9pQWhb4uaNbhu6EMBJNzfm3A12eORezzWqkH5DyfoVMjKMlI9WbRdITzrnQlM8152tVDwW93wGu19jB6YskHSbJ9892+kuqMU4HRn7WR6Mvg5KcNI= Received: from 30.246.161.141(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WFL26p5_1726834485) by smtp.aliyun-inc.com; Fri, 20 Sep 2024 20:14:47 +0800 Message-ID: <0701964b-1c7f-4d41-8b04-e888b3c998ec@linux.alibaba.com> Date: Fri, 20 Sep 2024 20:14:45 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v13 3/3] ACPI: APEI: handle synchronous exceptions in task work To: Jarkko Sakkinen , mark.rutland@arm.com, catalin.marinas@arm.com, mingo@redhat.com, robin.murphy@arm.com, Jonathan.Cameron@Huawei.com, bp@alien8.de, rafael@kernel.org, wangkefeng.wang@huawei.com, tanxiaofei@huawei.com, mawupeng1@huawei.com, tony.luck@intel.com, linmiaohe@huawei.com, naoya.horiguchi@nec.com, james.morse@arm.com, tongtiangen@huawei.com, gregkh@linuxfoundation.org, will@kernel.org Cc: linux-acpi@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, linux-edac@vger.kernel.org, x86@kernel.org, justin.he@arm.com, ardb@kernel.org, ying.huang@intel.com, ashish.kalra@amd.com, baolin.wang@linux.alibaba.com, tglx@linutronix.de, dave.hansen@linux.intel.com, lenb@kernel.org, hpa@zytor.com, robert.moore@intel.com, lvying6@huawei.com, xiexiuqi@huawei.com, zhuo.song@linux.alibaba.com References: <20221027042445.60108-1-xueshuai@linux.alibaba.com> <20240920043027.21907-4-xueshuai@linux.alibaba.com> From: Shuai Xue In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Stat-Signature: 9tgbq7y44eiaxb3iiya3169iekp5nfe6 X-Rspamd-Queue-Id: 1498514001E X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1726834498-509598 X-HE-Meta: U2FsdGVkX1/CNEP6ABr4RLa5kHNMxo/pptIVYz8AL+CqopqDhmwibWoEV2RAzcjpBqZ3jQeYKxOBsEhOMjiglq9/z2L/zcl6B469ohE8f8ninYbwHlyHKtE4njs8xHLGQl8f+6Cv+KTQC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NyYdwrCepi6wa4cnmkOhDtQA9WAe2PlrG9mtGC93hC429EKmRbGcxSKgDgbGKXwtRCAxyYRTBCiAPcmF+/yQwdgZ+XhOA1lBKWLV4X4gVwFjfCs= 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: 在 2024/9/20 19:44, Jarkko Sakkinen 写道: > On Fri Sep 20, 2024 at 7:30 AM EEST, Shuai Xue wrote: >> The memory uncorrected error could be signaled by asynchronous interrupt >> (specifically, SPI in arm64 platform), e.g. when an error is detected by >> a background scrubber, or signaled by synchronous exception >> (specifically, data abort excepction in arm64 platform), e.g. when a CPU >> tries to access a poisoned cache line. Currently, both synchronous and >> asynchronous error use memory_failure_queue() to schedule >> memory_failure() exectute in kworker context. >> >> As a result, when a user-space process is accessing a poisoned data, a >> data abort is taken and the memory_failure() is executed in the kworker >> context: >> >> - will send wrong si_code by SIGBUS signal in early_kill mode, and >> - can not kill the user-space in some cases resulting a synchronous >> error infinite loop >> >> Issue 1: send wrong si_code in early_kill mode >> >> Since commit a70297d22132 ("ACPI: APEI: set memory failure flags as >> MF_ACTION_REQUIRED on synchronous events")', the flag MF_ACTION_REQUIRED >> could be used to determine whether a synchronous exception occurs on >> ARM64 platform. When a synchronous exception is detected, the kernel is >> expected to terminate the current process which has accessed poisoned >> page. This is done by sending a SIGBUS signal with an error code >> BUS_MCEERR_AR, indicating an action-required machine check error on >> read. >> >> However, when kill_proc() is called to terminate the processes who have >> the poisoned page mapped, it sends the incorrect SIGBUS error code >> BUS_MCEERR_AO because the context in which it operates is not the one >> where the error was triggered. >> >> To reproduce this problem: >> >> #sysctl -w vm.memory_failure_early_kill=1 >> vm.memory_failure_early_kill = 1 >> >> # STEP2: inject an UCE error and consume it to trigger a synchronous error >> #einj_mem_uc single >> 0: single vaddr = 0xffffb0d75400 paddr = 4092d55b400 >> injecting ... >> triggering ... >> signal 7 code 5 addr 0xffffb0d75000 >> page not present >> Test passed >> >> The si_code (code 5) from einj_mem_uc indicates that it is BUS_MCEERR_AO >> error and it is not fact. >> >> After this patch: >> >> # STEP1: enable early kill mode >> #sysctl -w vm.memory_failure_early_kill=1 >> vm.memory_failure_early_kill = 1 >> # STEP2: inject an UCE error and consume it to trigger a synchronous error >> #einj_mem_uc single >> 0: single vaddr = 0xffffb0d75400 paddr = 4092d55b400 >> injecting ... >> triggering ... >> signal 7 code 4 addr 0xffffb0d75000 >> page not present >> Test passed >> >> The si_code (code 4) from einj_mem_uc indicates that it is BUS_MCEERR_AR >> error as we expected. >> >> Issue 2: a synchronous error infinite loop >> >> If a user-space process, e.g. devmem, a poisoned page which has been set >> HWPosion flag, kill_accessing_process() is called to send SIGBUS to the >> current processs with error info. Because the memory_failure() is >> executed in the kworker contex, it will just do nothing but return >> EFAULT. So, devmem will access the posioned page and trigger an >> excepction again, resulting in a synchronous error infinite loop. Such >> loop may cause platform firmware to exceed some threshold and reboot >> when Linux could have recovered from this error. >> >> To reproduce this problem: >> >> # STEP 1: inject an UCE error, and kernel will set HWPosion flag for related page >> #einj_mem_uc single >> 0: single vaddr = 0xffffb0d75400 paddr = 4092d55b400 >> injecting ... >> triggering ... >> signal 7 code 4 addr 0xffffb0d75000 >> page not present >> Test passed >> >> # STEP 2: access the same page and it will trigger a synchronous error infinite loop >> devmem 0x4092d55b400 >> >> To fix above two issues, queue memory_failure() as a task_work so that it runs in >> the context of the process that is actually consuming the poisoned data. >> >> Signed-off-by: Shuai Xue >> Tested-by: Ma Wupeng >> Reviewed-by: Kefeng Wang >> Reviewed-by: Xiaofei Tan >> Reviewed-by: Baolin Wang >> --- >> drivers/acpi/apei/ghes.c | 78 +++++++++++++++++++++++----------------- >> include/acpi/ghes.h | 3 -- >> include/linux/mm.h | 1 - >> mm/memory-failure.c | 13 ------- >> 4 files changed, 45 insertions(+), 50 deletions(-) >> >> diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c >> index 93eb11482832..60d8044f14d1 100644 >> --- a/drivers/acpi/apei/ghes.c >> +++ b/drivers/acpi/apei/ghes.c >> @@ -467,28 +467,42 @@ static void ghes_clear_estatus(struct ghes *ghes, >> } >> >> /* >> - * Called as task_work before returning to user-space. >> - * Ensure any queued work has been done before we return to the context that >> - * triggered the notification. >> + * struct task_work - for synchronous RAS event >> + * >> + * @twork: callback_head for task work >> + * @pfn: page frame number of corrupted page >> + * @flags: work control flags >> + * >> + * Structure to pass task work to be handled before >> + * returning to user-space via task_work_add(). >> */ >> -static void ghes_kick_task_work(struct callback_head *head) >> +struct task_work { >> + struct callback_head twork; >> + u64 pfn; >> + int flags; >> +}; > > I'd rename this as ghes_task_work. It is too generic name IMHO, easily > confused with task_work.h definitions. > > BR, Jarkko Agreed, I will rename it in next version. Thank you. Best Regards, Shuai