From patchwork Sat Oct 22 07:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7666 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1108165wrr; Sat, 22 Oct 2022 01:43:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Ge68lHHdbSafJsUSsCv0+pwphwtWhgsILQQE8ZGxiG4SyUGBWj8ewB3q10PoQ9IFYfW92 X-Received: by 2002:a50:9519:0:b0:45f:ca89:cf9a with SMTP id u25-20020a509519000000b0045fca89cf9amr12958618eda.248.1666428218287; Sat, 22 Oct 2022 01:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428218; cv=none; d=google.com; s=arc-20160816; b=L3RyweZpzAOjCs45nTOJMIzt63mRd3PeZMo3KhtcN30L8/KfdfmLVtzxgCxUl/0Vy8 Xojogf5lehbWktgqC3J6uwa5Qiacf/mojFw3a/JeoAvMCIBa3WjbkEde070t7UWmy57O xbYagvzOrnrppemZV+myPsrEj8R6A0//69V0lr9TJ2m87i7b9aQPLlZoh+rZTXRTyHmq YygdanZjgIcCi1k0jHIR4YL2szjNHtsuj5m/4sLRYHmPlG2vtoRlFfUZfAJfbMxO3JjE ORkWxGs0ZLKVb3kUXbFv81Rg6TIItFiOjQvIOztHRE0eChMEhu3U78lStqpzXBWKXnf6 TaUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Hvs4hgilptgO+/i38adUEuP5+Rgjnez5emDoQYy+TTc=; b=PIYIVGFelmBjm9Rkmz+xfIMllAGGuf4AoKeO+PLyDd6iJq79REMe9C7Rb78Z/XgoCB sl47HYSprA8u/E4/oWxzN7vO0YwftnIUZZcJJhegzcUGsUOYnXI56dzhzzRPcyMrz/X2 EyE6T1zKkoN8SCDSQ5tdeXtodgnVNCXIQfDIc67lqDHtWjJzf7TrLpYxR0VF/TGtW685 ioUjaSUrfgQ+FEvYV21XSSjCPjxnFBI4Q1KcurLt06X7M0NLlV+hbArOQT9PnuQFDNrD rLfrscnvsRrJxLpGWjzb0WsYvacShOZIYe75VwcNxjQ3i8VYacIzEBv+iw7HUwKHadWM fECQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uCD8WB7+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m22-20020aa7c2d6000000b0044e9fd71b82si18852530edp.280.2022.10.22.01.43.14; Sat, 22 Oct 2022 01:43:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uCD8WB7+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232424AbiJVImb (ORCPT + 99 others); Sat, 22 Oct 2022 04:42:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234831AbiJVIkV (ORCPT ); Sat, 22 Oct 2022 04:40:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B7121E3915; Sat, 22 Oct 2022 01:06:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C3776B82E1A; Sat, 22 Oct 2022 07:59:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12D2CC433C1; Sat, 22 Oct 2022 07:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425539; bh=gQ9uhgSJYlR3is3lDutdEcOjJQsBHpKOa3lCfgM3yUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uCD8WB7+fqOK3GrNJdwitp5+d3QVNS42LNaXx6LEn0pN4J3lUkrfIFB/VUIL0fvf2 ZEl/NaG5Z2cdZ7IjEHEiJIFk/u0EgzfyIhYNYPRyrDtSQd0cl0F6aKPGHDR2Tiq9Sy iBjRwy/EcAIfg68Zapur010yXAqrYgGKJIriMhEQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuai Xue , Tony Luck , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.19 535/717] ACPI: APEI: do not add task_work to kernel thread to avoid memory leak Date: Sat, 22 Oct 2022 09:26:54 +0200 Message-Id: <20221022072521.984264440@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747376635022417402?= X-GMAIL-MSGID: =?utf-8?q?1747376635022417402?= From: Shuai Xue [ Upstream commit 415fed694fe11395df56e05022d6e7cee1d39dd3 ] If an error is detected as a result of user-space process accessing a corrupt memory location, the CPU may take an abort. Then the platform firmware reports kernel via NMI like notifications, e.g. NOTIFY_SEA, NOTIFY_SOFTWARE_DELEGATED, etc. For NMI like notifications, commit 7f17b4a121d0 ("ACPI: APEI: Kick the memory_failure() queue for synchronous errors") keep track of whether memory_failure() work was queued, and make task_work pending to flush out the queue so that the work is processed before return to user-space. The code use init_mm to check whether the error occurs in user space: if (current->mm != &init_mm) The condition is always true, becase _nobody_ ever has "init_mm" as a real VM any more. In addition to abort, errors can also be signaled as asynchronous exceptions, such as interrupt and SError. In such case, the interrupted current process could be any kind of thread. When a kernel thread is interrupted, the work ghes_kick_task_work deferred to task_work will never be processed because entry_handler returns to call ret_to_kernel() instead of ret_to_user(). Consequently, the estatus_node alloced from ghes_estatus_pool in ghes_in_nmi_queue_one_entry() will not be freed. After around 200 allocations in our platform, the ghes_estatus_pool will run of memory and ghes_in_nmi_queue_one_entry() returns ENOMEM. As a result, the event failed to be processed. sdei: event 805 on CPU 113 failed with error: -2 Finally, a lot of unhandled events may cause platform firmware to exceed some threshold and reboot. The condition should generally just do if (current->mm) as described in active_mm.rst documentation. Then if an asynchronous error is detected when a kernel thread is running, (e.g. when detected by a background scrubber), do not add task_work to it as the original patch intends to do. Fixes: 7f17b4a121d0 ("ACPI: APEI: Kick the memory_failure() queue for synchronous errors") Signed-off-by: Shuai Xue Reviewed-by: Tony Luck Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/acpi/apei/ghes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index d91ad378c00d..80ad530583c9 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -985,7 +985,7 @@ static void ghes_proc_in_irq(struct irq_work *irq_work) ghes_estatus_cache_add(generic, estatus); } - if (task_work_pending && current->mm != &init_mm) { + 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,