From patchwork Mon Dec 18 06:45:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 13496265 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 CFBEFC46CD2 for ; Mon, 18 Dec 2023 06:45:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6773D8D0007; Mon, 18 Dec 2023 01:45:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 629338D0001; Mon, 18 Dec 2023 01:45:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F07A8D0007; Mon, 18 Dec 2023 01:45:43 -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 3EB1A8D0001 for ; Mon, 18 Dec 2023 01:45:43 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 160321608CF for ; Mon, 18 Dec 2023 06:45:43 +0000 (UTC) X-FDA: 81579003366.18.86F8D78 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf22.hostedemail.com (Postfix) with ESMTP id 11212C000F for ; Mon, 18 Dec 2023 06:45:40 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=xueshuai@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702881941; 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; bh=1zS9Da9CAyaj/s3gA9c/mCNMBK7GU5h51xos1juqGpY=; b=VUeEmjQp4tTWAxIY+D6+zpT3wUYWpGBF5bqfwkiIEpBvqr3Xk7CYiH8QzlnuzHor5A2K9P Z5RU84Veg0VW4uNRVdifhQDFJEsB2slYnKLsvPpH6NQGCUhomYyZCwwIdKDChImsOTZ2Y3 5xubpuzlKuKUjkw+GIfZwKGt2UmjzRs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702881941; a=rsa-sha256; cv=none; b=bSIsOqDL9UTxmRg6A88ggpEwmAfqpnC4B/5m8pVPuBPvWMabqmoTN5LEA9gjYP74FWDx8r oESYz7tWLTlOSX7a3c9QxmNUF7yVCZqlFfGjwdOSgVCquXE/K0FIugAsFaCoq0pON8vUAT OnMqPGrLaSw4szKuWuGgPyfqNqdLuc8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=xueshuai@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=xueshuai@linux.alibaba.com;NM=1;PH=DS;RN=35;SR=0;TI=SMTPD_---0VygHb04_1702881934; Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0VygHb04_1702881934) by smtp.aliyun-inc.com; Mon, 18 Dec 2023 14:45:35 +0800 From: Shuai Xue To: 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, gregkh@linuxfoundation.org, will@kernel.org, jarkko@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, acpica-devel@lists.linuxfoundation.org, stable@vger.kernel.org, x86@kernel.org, xueshuai@linux.alibaba.com, justin.he@arm.com, ardb@kernel.org, ying.huang@intel.com, ashish.kalra@amd.com, baolin.wang@linux.alibaba.com, tglx@linutronix.de, mingo@redhat.com, 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 Subject: [PATCH v10 4/4] ACPI: APEI: handle synchronous exceptions in task work Date: Mon, 18 Dec 2023 14:45:21 +0800 Message-Id: <20231218064521.37324-5-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221027042445.60108-1-xueshuai@linux.alibaba.com> References: <20221027042445.60108-1-xueshuai@linux.alibaba.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 11212C000F X-Rspam-User: X-Stat-Signature: tnetruum6eqsn4b6uw8b79jtz7r4knqu X-Rspamd-Server: rspam03 X-HE-Tag: 1702881940-973109 X-HE-Meta: U2FsdGVkX19S+8qtnIndUKke1UHPMJqEBi5fS+78JydpZHDoEg3C9hNYHoCpWiF4eaS3eXjZ56oHLb0IxUZpma/lIl3uXy1rTYv8DVnpFAwSSURdwodfs8j5cphQxppVugXqZxq1OHPROp8Ak6Se1fDTCEnNl+2W56c5h+yAYcPSUPuZXKM5xTjLLc5JEQyjKdyGWOX9jqEin2ALVanty6hiIgOCP2ei0SXCflsgDbGMmNkYlLxg/kDewgABBj4NsVZTu7fe7X54BepGqZn2Q6LQnN97oMxGYxnsY3tq48QpCvz4rpaLuVCQJtk7MOXsm0yDHOIAVC7YJIlP2kOGqlsDC3AD/h6+iiW/BMhS00jmhx3GErKMbFD4JphVbxVpq0QCjUNSG3iNnNJaCcTrx7+pekosIUAbzisRGt5ly72nbSd3964BsEem9pnkv/F8RYj7Scc0crByv2Wo1RcswTXGQ1j4Lh5vTbSGIHMjJf05mEARJvK4Q900jNngjMV5BvQW8zCbk6uCrcTW1irTrghotn/KxgCsrzjRixxOpRVl0ZCsvmxeT407dBunbL5dnbPC/MxXy4lVkXKoHFi/oLGD3LHWa49QAqcLzqxDiTm2gPikuwxKEM3HYT7QdOTXy8Ytgo8bLsuODzE6YEsY5zr9/JRBHBaNasOjcWbZl/zpjCwHN5/PdG2yIJGdoK78STAfeREWADn/Te/ou/q7mRcNvLtzHgY/S3dH6LGhZaV5BmaGeNJSiR+LM+6hXFYuMXfjs+ZAVel5chnV39Ts+J3WR3xOkQ2ggAv1D6nKlxhaDNIC1PhD0ndAGVxrVq7m1QTj/cy1Uj3naKBo5ht3sxKkOGxb81ZL7OO0LHF2cZRrjv93PGCElB277Wib61wHHXCvH/HAIAjhoKSYA8egKTeL+ci0WJ7nAff4pT+CuLow1QyCkHJj/7HjcL5OwI0NAO3dDsYjt0snjBJTY4g lR2HuwAk DVkQysHip5Ja5r+gnUWugmyRpRIq5gKiq1yVVaB7fSAqyRhzaYonEFpmNvG+EomX0Y7f0lp6LGpmN5w+rt6YINqGG5ZnF7zTw2egZRDQm05VEd0wqvNaRhZnqXYVjA4h1KSmDLBOFxCkwmWs= 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: Hardware errors could be signaled by asynchronous interrupt, e.g. when an error is detected by a background scrubber, or signaled by synchronous exception, e.g. when a CPU tries to access a poisoned cache line. Both synchronous and asynchronous error are queued as a memory_failure() work and handled by a dedicated kthread in workqueue. However, the memory failure recovery sends SIBUS with wrong BUS_MCEERR_AO si_code for synchronous errors in early kill mode, even MF_ACTION_REQUIRED is set. The main problem is that the memory failure work is handled in kthread context but not the user-space process which is accessing the corrupt memory location, so it will send SIGBUS with BUS_MCEERR_AO si_code to the user-space process instead of BUS_MCEERR_AR in kill_proc(). To this end, queue memory_failure() as a task_work so that the current context in memory_failure() is exactly belongs to the process consuming poison data and it will send SIBBUS with proper si_code. 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 | 77 +++++++++++++++++++++++----------------- include/acpi/ghes.h | 3 -- mm/memory-failure.c | 13 ------- 3 files changed, 44 insertions(+), 49 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index f832ffc5a88d..a6b4907cfe47 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -464,28 +464,41 @@ 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 sync_task_work - for synchronous RAS event + * + * @twork: callback_head for task work + * @pfn: page frame number of corrupted page + * @flags: fine tune action taken + * + * Structure to pass task work to be handled before + * ret_to_user via task_work_add(). */ -static void ghes_kick_task_work(struct callback_head *head) +struct sync_task_work { + struct callback_head twork; + u64 pfn; + int flags; +}; + +static void memory_failure_cb(struct callback_head *twork) { - struct acpi_hest_generic_status *estatus; - struct ghes_estatus_node *estatus_node; - u32 node_len; + int ret; + struct sync_task_work *twcb = + container_of(twork, struct sync_task_work, twork); - estatus_node = container_of(head, struct ghes_estatus_node, task_work); - if (IS_ENABLED(CONFIG_ACPI_APEI_MEMORY_FAILURE)) - memory_failure_queue_kick(estatus_node->task_work_cpu); + ret = memory_failure(twcb->pfn, twcb->flags); + gen_pool_free(ghes_estatus_pool, (unsigned long)twcb, sizeof(*twcb)); - estatus = GHES_ESTATUS_FROM_NODE(estatus_node); - node_len = GHES_ESTATUS_NODE_LEN(cper_estatus_len(estatus)); - gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node, node_len); + if (!ret || ret == -EHWPOISON || ret == -EOPNOTSUPP) + return; + + pr_err("Sending SIGBUS to current task due to memory error not recovered"); + force_sig(SIGBUS); } static bool ghes_do_memory_failure(u64 physical_addr, int flags) { unsigned long pfn; + struct sync_task_work *twcb; if (!IS_ENABLED(CONFIG_ACPI_APEI_MEMORY_FAILURE)) return false; @@ -498,6 +511,18 @@ static bool ghes_do_memory_failure(u64 physical_addr, int flags) return false; } + if (flags == MF_ACTION_REQUIRED && current->mm) { + twcb = (void *)gen_pool_alloc(ghes_estatus_pool, sizeof(*twcb)); + if (!twcb) + return false; + + twcb->pfn = pfn; + twcb->flags = flags; + init_task_work(&twcb->twork, memory_failure_cb); + task_work_add(current, &twcb->twork, TWA_RESUME); + return true; + } + memory_failure_queue(pfn, flags); return true; } @@ -673,7 +698,7 @@ static void ghes_defer_non_standard_event(struct acpi_hest_generic_data *gdata, schedule_work(&entry->work); } -static bool ghes_do_proc(struct ghes *ghes, +static void ghes_do_proc(struct ghes *ghes, const struct acpi_hest_generic_status *estatus) { int sev, sec_sev; @@ -725,8 +750,6 @@ static bool ghes_do_proc(struct ghes *ghes, pr_err("Sending SIGBUS to current task due to memory error not recovered"); force_sig(SIGBUS); } - - return queued; } static void __ghes_print_estatus(const char *pfx, @@ -1028,9 +1051,7 @@ static void ghes_proc_in_irq(struct irq_work *irq_work) struct ghes_estatus_node *estatus_node; struct acpi_hest_generic *generic; struct acpi_hest_generic_status *estatus; - bool task_work_pending; u32 len, node_len; - int ret; llnode = llist_del_all(&ghes_estatus_llist); /* @@ -1045,25 +1066,16 @@ static void ghes_proc_in_irq(struct irq_work *irq_work) estatus = GHES_ESTATUS_FROM_NODE(estatus_node); len = cper_estatus_len(estatus); node_len = GHES_ESTATUS_NODE_LEN(len); - task_work_pending = ghes_do_proc(estatus_node->ghes, estatus); + + ghes_do_proc(estatus_node->ghes, estatus); + if (!ghes_estatus_cached(estatus)) { generic = estatus_node->generic; if (ghes_print_estatus(NULL, generic, estatus)) ghes_estatus_cache_add(generic, estatus); } - - if (task_work_pending && current->mm) { - estatus_node->task_work.func = ghes_kick_task_work; - estatus_node->task_work_cpu = smp_processor_id(); - ret = task_work_add(current, &estatus_node->task_work, - TWA_RESUME); - if (ret) - estatus_node->task_work.func = NULL; - } - - if (!estatus_node->task_work.func) - gen_pool_free(ghes_estatus_pool, - (unsigned long)estatus_node, node_len); + gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node, + node_len); llnode = next; } @@ -1124,7 +1136,6 @@ static int ghes_in_nmi_queue_one_entry(struct ghes *ghes, estatus_node->ghes = ghes; estatus_node->generic = ghes->generic; - estatus_node->task_work.func = NULL; estatus = GHES_ESTATUS_FROM_NODE(estatus_node); if (__ghes_read_estatus(estatus, buf_paddr, fixmap_idx, len)) { diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index be1dd4c1a917..ebd21b05fe6e 100644 --- a/include/acpi/ghes.h +++ b/include/acpi/ghes.h @@ -35,9 +35,6 @@ struct ghes_estatus_node { struct llist_node llnode; struct acpi_hest_generic *generic; struct ghes *ghes; - - int task_work_cpu; - struct callback_head task_work; }; struct ghes_estatus_cache { diff --git a/mm/memory-failure.c b/mm/memory-failure.c index bd3dcafdfa4a..6bff57444928 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2451,19 +2451,6 @@ static void memory_failure_work_func(struct work_struct *work) } } -/* - * Process memory_failure work queued on the specified CPU. - * Used to avoid return-to-userspace racing with the memory_failure workqueue. - */ -void memory_failure_queue_kick(int cpu) -{ - struct memory_failure_cpu *mf_cpu; - - mf_cpu = &per_cpu(memory_failure_cpu, cpu); - cancel_work_sync(&mf_cpu->work); - memory_failure_work_func(&mf_cpu->work); -} - static int __init memory_failure_init(void) { struct memory_failure_cpu *mf_cpu;