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 X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B664C43600 for ; Wed, 12 May 2021 19:49:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08D7F61434 for ; Wed, 12 May 2021 19:48:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382282AbhELTns (ORCPT ); Wed, 12 May 2021 15:43:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:51270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352466AbhELSDV (ORCPT ); Wed, 12 May 2021 14:03:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 55B226143C; Wed, 12 May 2021 18:02:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620842533; bh=yqMLfotVbNItvdbOfb7M6PEWkfq6V0J505sB7+R7PRo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B4ZvsWS+CXd0UIsgq9dZII9z6CWviLTkCgyfACMBdu3ZQ9lzJAVzBg3DZ6kDVRC3m Guwpd/NO1wlybB/ynwCoLX0CZ8WmVpq1v+VVUgTqrzW0UZSIh3l1Cc5iHzWgHY2EXm QIaxfzdr6Qms+fGBQYM6uTG059FKTa8pHy2XY0Wn1hwmt/DAwc1IFMM0cqDWbwfEWU jZA+TxmIWJYUKTHX9F6YmfMZF9+++pBLMbZLQi5Q4kDWIZeGgs4julEoiE8ROwJ/Na s4at9x5OwJqwEJZ6EHWydTm2H5BngqzkRWDVJxUGzwLMWTXocSmLyw2IMGMhtmKmEW 3LtKyiz3vyPnw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "louis.wang" , Russell King , Sasha Levin , linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.11 04/35] ARM: 9066/1: ftrace: pause/unpause function graph tracer in cpu_suspend() Date: Wed, 12 May 2021 14:01:34 -0400 Message-Id: <20210512180206.664536-4-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210512180206.664536-1-sashal@kernel.org> References: <20210512180206.664536-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "louis.wang" [ Upstream commit 8252ca87c7a2111502ee13994956f8c309faad7f ] Enabling function_graph tracer on ARM causes kernel panic, because the function graph tracer updates the "return address" of a function in order to insert a trace callback on function exit, it saves the function's original return address in a return trace stack, but cpu_suspend() may not return through the normal return path. cpu_suspend() will resume directly via the cpu_resume path, but the return trace stack has been set-up by the subfunctions of cpu_suspend(), which makes the "return address" inconsistent with cpu_suspend(). This patch refers to Commit de818bd4522c40ea02a81b387d2fa86f989c9623 ("arm64: kernel: pause/unpause function graph tracer in cpu_suspend()"), fixes the issue by pausing/resuming the function graph tracer on the thread executing cpu_suspend(), so that the function graph tracer state is kept consistent across functions that enter power down states and never return by effectively disabling graph tracer while they are executing. Signed-off-by: louis.wang Signed-off-by: Russell King Signed-off-by: Sasha Levin --- arch/arm/kernel/suspend.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/arm/kernel/suspend.c b/arch/arm/kernel/suspend.c index 24bd20564be7..43f0a3ebf390 100644 --- a/arch/arm/kernel/suspend.c +++ b/arch/arm/kernel/suspend.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include #include @@ -25,6 +26,13 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) if (!idmap_pgd) return -EINVAL; + /* + * Function graph tracer state gets incosistent when the kernel + * calls functions that never return (aka suspend finishers) hence + * disable graph tracing during their execution. + */ + pause_graph_tracing(); + /* * Provide a temporary page table with an identity mapping for * the MMU-enable code, required for resuming. On successful @@ -32,6 +40,9 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) * back to the correct page tables. */ ret = __cpu_suspend(arg, fn, __mpidr); + + unpause_graph_tracing(); + if (ret == 0) { cpu_switch_mm(mm->pgd, mm); local_flush_bp_all(); @@ -45,7 +56,13 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) { u32 __mpidr = cpu_logical_map(smp_processor_id()); - return __cpu_suspend(arg, fn, __mpidr); + int ret; + + pause_graph_tracing(); + ret = __cpu_suspend(arg, fn, __mpidr); + unpause_graph_tracing(); + + return ret; } #define idmap_pgd NULL #endif -- 2.30.2 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 X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 701BDC433B4 for ; Wed, 12 May 2021 18:05:47 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BC02661943 for ; Wed, 12 May 2021 18:05:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC02661943 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6hkVWWMVPadk1HOa9b31gBSDfzVoWdOHpk1eHWj9no0=; b=B7ZOlSWcxCp9QsKN2KRkz4Ogu IMI6T/wqBALpS6X4pgP4VCxUsJEjnq0hSPiCTjEOLa9aOpgnUqaIZ4DAHzuLkBxpnyIHVhjWxUYzg P8NcrKZXlvbtsQ1/OYJZqgbFA/VJKodDVH4MPlKmXaJy/Fhp+phf7xSMuPTGjiMmnvtFfOoGM+HPu 8nnnJwTsSF7If4NxfdVmyH+Tgl8nvPquoihtjGPItt/eKl1Kesfn0K/4XjSCkQoJhLcOLU8R6IwSH t9aFPybG6vfDdkTXex9JOloDhGLJUNND1phD2FLy+4dF2wBVh0CChQ999qQN9oFzLSYB7Z9ZP+tFD fOsps0Mhg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgtCN-003Vvk-VZ; Wed, 12 May 2021 18:03:08 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgtBY-003Vd8-8P for linux-arm-kernel@desiato.infradead.org; Wed, 12 May 2021 18:02:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=EIQU3JsShXjd35eU9IzMWi8Bq6nLU0aajg0lH2XthL0=; b=rrUOZw3Ph/SCdG+RGPP1hKCssi QnnbBSkx3GHHlISRb51ZacVqgUiHeTQ5Yjwo4nn8hEaubTjifs/fxZRxTw8LW7t/W9tPVVlDEQTW2 496XujkQvAp0m9NEkEHLB3NF6lEceWA/sBDwze9/HVlm28wERarkdwEXyIFQgfjDl4qiSCWfT1YyJ sMGTexotJ32W1ivn9DUyrvYLMp7xjwVPXj/22r21NEmVBklt8DPM3B/EAAUwfGBt1Auh+htWQQN8A x27cwDHJaotn+RJrVfZWrfknTpk98SoptsYR9dq3KTuHCSMsUFM8mDg4678HBNRGxKzd5zOP0kM8Y 2ICeoJrg==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgtBV-00AfoF-JB for linux-arm-kernel@lists.infradead.org; Wed, 12 May 2021 18:02:15 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 55B226143C; Wed, 12 May 2021 18:02:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620842533; bh=yqMLfotVbNItvdbOfb7M6PEWkfq6V0J505sB7+R7PRo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B4ZvsWS+CXd0UIsgq9dZII9z6CWviLTkCgyfACMBdu3ZQ9lzJAVzBg3DZ6kDVRC3m Guwpd/NO1wlybB/ynwCoLX0CZ8WmVpq1v+VVUgTqrzW0UZSIh3l1Cc5iHzWgHY2EXm QIaxfzdr6Qms+fGBQYM6uTG059FKTa8pHy2XY0Wn1hwmt/DAwc1IFMM0cqDWbwfEWU jZA+TxmIWJYUKTHX9F6YmfMZF9+++pBLMbZLQi5Q4kDWIZeGgs4julEoiE8ROwJ/Na s4at9x5OwJqwEJZ6EHWydTm2H5BngqzkRWDVJxUGzwLMWTXocSmLyw2IMGMhtmKmEW 3LtKyiz3vyPnw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "louis.wang" , Russell King , Sasha Levin , linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.11 04/35] ARM: 9066/1: ftrace: pause/unpause function graph tracer in cpu_suspend() Date: Wed, 12 May 2021 14:01:34 -0400 Message-Id: <20210512180206.664536-4-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210512180206.664536-1-sashal@kernel.org> References: <20210512180206.664536-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210512_110213_702702_21DEE506 X-CRM114-Status: GOOD ( 16.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "louis.wang" [ Upstream commit 8252ca87c7a2111502ee13994956f8c309faad7f ] Enabling function_graph tracer on ARM causes kernel panic, because the function graph tracer updates the "return address" of a function in order to insert a trace callback on function exit, it saves the function's original return address in a return trace stack, but cpu_suspend() may not return through the normal return path. cpu_suspend() will resume directly via the cpu_resume path, but the return trace stack has been set-up by the subfunctions of cpu_suspend(), which makes the "return address" inconsistent with cpu_suspend(). This patch refers to Commit de818bd4522c40ea02a81b387d2fa86f989c9623 ("arm64: kernel: pause/unpause function graph tracer in cpu_suspend()"), fixes the issue by pausing/resuming the function graph tracer on the thread executing cpu_suspend(), so that the function graph tracer state is kept consistent across functions that enter power down states and never return by effectively disabling graph tracer while they are executing. Signed-off-by: louis.wang Signed-off-by: Russell King Signed-off-by: Sasha Levin --- arch/arm/kernel/suspend.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/arch/arm/kernel/suspend.c b/arch/arm/kernel/suspend.c index 24bd20564be7..43f0a3ebf390 100644 --- a/arch/arm/kernel/suspend.c +++ b/arch/arm/kernel/suspend.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include #include @@ -25,6 +26,13 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) if (!idmap_pgd) return -EINVAL; + /* + * Function graph tracer state gets incosistent when the kernel + * calls functions that never return (aka suspend finishers) hence + * disable graph tracing during their execution. + */ + pause_graph_tracing(); + /* * Provide a temporary page table with an identity mapping for * the MMU-enable code, required for resuming. On successful @@ -32,6 +40,9 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) * back to the correct page tables. */ ret = __cpu_suspend(arg, fn, __mpidr); + + unpause_graph_tracing(); + if (ret == 0) { cpu_switch_mm(mm->pgd, mm); local_flush_bp_all(); @@ -45,7 +56,13 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) { u32 __mpidr = cpu_logical_map(smp_processor_id()); - return __cpu_suspend(arg, fn, __mpidr); + int ret; + + pause_graph_tracing(); + ret = __cpu_suspend(arg, fn, __mpidr); + unpause_graph_tracing(); + + return ret; } #define idmap_pgd NULL #endif -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel