Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7104323rwi; Mon, 24 Oct 2022 09:52:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6HxmDtIDDoTOgf85JUQM8l6y1Lpl/IWZc8ZCgHjJ/Fe7caui4uJp2+LxcPOlo6p3k3aF1A X-Received: by 2002:a17:907:a47:b0:79e:56dc:5373 with SMTP id be7-20020a1709070a4700b0079e56dc5373mr13995195ejc.148.1666630330351; Mon, 24 Oct 2022 09:52:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666630330; cv=none; d=google.com; s=arc-20160816; b=xl0gXOqraz5bUWkqLzi+aH2cObckcyq8B6s5QfPSjc7MeAI47NjStJadUnLNWIiF/6 a9lGO77ufAM52PauXL0d6VcofqJFw3RhuqmSctm4d9Yqd2djM4qezJCcbG0QHWO7B9Fd tPyywTmiwqkeJvb1tQoB8dyPOTuA0u81MdV8Pt0rP7I+V/8D9d58kidfrhXSK+cac9eB SM1UiY6a6DaBybPIBaIOBiqk8DE1Wk7vr0V3G6/Xxx/WG4sX7Adeb+ImLbbpZgK3XkGc wcYQv8Z1tHQQ1bjdhCIb4Xk48E+cTkjLfPMWVDniqWT8PjTYAZVrXrrsj63rmw8QsOoK qTTg== 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=oxbuns6ONrTHpbDztTsehlu+X1ZtB+ScfMHRHROQmjY=; b=URqwgSHaTMDSxTDoxVgXXHclgkABFOD8Cn6vx0WtRt09iO5rLox/VRR4nhdeVqktHj Xfz05RHSyS7AX73aZ6CVqRyDPFT6LbvJR3eAzCk4U8+B7APyAJBd4FkXViywsB4zNiZk coJxAAufHeFI4/NafaCi6s9KaYyQ6s2SD6Is+A5Yp/y1LaTpC1InO4PjsruGksk7GzS9 9KRPQtO6O3HWUNShxgAa/wyPQcsGJmElkLsA06FEjEP57/ShcCd6NAVIc2lZvtJQbMUv J6LMXx+FS0LA0WKe/PcNjFEm8DMBhZ5L5SaEuGfNrqjrB+b82M8nhyiwXhveXnjp5gtF Fcag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=syWCJtXD; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cr2-20020a170906d54200b007763cc7093csi216440ejc.884.2022.10.24.09.51.45; Mon, 24 Oct 2022 09:52:10 -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=syWCJtXD; 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 S231271AbiJXQZR (ORCPT + 99 others); Mon, 24 Oct 2022 12:25:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234420AbiJXQYC (ORCPT ); Mon, 24 Oct 2022 12:24:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CBC9520AE; Mon, 24 Oct 2022 08:10:26 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 28A9D612CF; Mon, 24 Oct 2022 12:51:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1160FC433D7; Mon, 24 Oct 2022 12:51:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615907; bh=NzbueaQcuk2FdlPwZr7pqmGv2JFm/mcawP9WGsFFSKs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=syWCJtXDtiyEv9HVKDDRR8uuuqFHG9P1l/Fclvw7cjLPu2HQWqzoSayeeg1NYXVi0 IKBnkh/qJ9o8sVw6ZbEkkiiZ0TgGa5Mtio1GCyIJpe319sGOkw4HRKA9RPqzTnm0lF mj0JHFjgot2oWJSRuWXBDNrQyLyycu0JpGapjvV4= 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.15 396/530] ACPI: APEI: do not add task_work to kernel thread to avoid memory leak Date: Mon, 24 Oct 2022 13:32:20 +0200 Message-Id: <20221024113103.012975062@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 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 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 06b0184fa912..d490670f8d55 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, -- 2.35.1