Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp474554pxj; Thu, 20 May 2021 13:51:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKzQQXYfdjg3ZkzSVCtnJ4rVOR8M2p5SB8kgWGhcFknk3wseUjW6gM1aALScAKpj5Dyat6 X-Received: by 2002:a6b:f212:: with SMTP id q18mr7682282ioh.131.1621543895817; Thu, 20 May 2021 13:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621543895; cv=none; d=google.com; s=arc-20160816; b=sGVs9M+AxLXkgYKRsfWziHGKp3mcjIFp9I2k9lIZTirSgcY/+VFReeaOPWy6IEYrYA /vkbBx6xflXkC/vyeGA4VQfh7OzZyAZ9Ve3FTOpmaooEv4YqkD1g/X3jfdbgpdoCq6bq 9XY0GJ9mokKNtF90EdYbcn5vdLL8cHDon3/6D9cV+Gq9KuLUdOVBlWzR4hGKudFSiqgC QzHbKJEJI/X+GkOC7e3aCV/CwpWEDZ5nWR75aBDIy7dpVZDOfXiZFWO2+S+J5zDrXByK hyYYuLZOI04W8fCORJrrPPosrmyAoBRFnsJru/BALMi7vHYJtgTsCaHPEGjRpdtxh6or JXtA== 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=3QyMko01GDfzF0jkTkCS/y7McvpPSBYjVjqImGYo7mg=; b=DF5K/eLylURIkjTTOmtpuTje/+YB6Ct+pZUkuOhGvacG3A0gpGtV+I1wjTj4B7H1pM hfILbjguXq4NPWZuD85QkpFahj1wkk59Xp19ZO9uHteYsEekJyLQ5r83g7MBfQdtj9uT 2qecM8PnxACrtGC5x5M9CJC4IBbPbj6ZGHN1blO9DByB0vySaQWuO+Loj3pGdq8A8uNP ZpRxm2Zwxcc0MFsLXpDmxopkOnWr5sUCVMiilqb7FR+RfPwUYTr0QrQl5c3QwAMnBuQx xF9kTIn9I8smseeGSBLGTrGJVMzY2IzJMqKrVPAvC6+jHCwc+aVie+KgQtwhvdWMGLZ4 /sLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Kixcwfqx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si3427845iow.22.2021.05.20.13.51.22; Thu, 20 May 2021 13:51:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Kixcwfqx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S239462AbhETK70 (ORCPT + 99 others); Thu, 20 May 2021 06:59:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:42382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237627AbhETKmS (ORCPT ); Thu, 20 May 2021 06:42:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3503861C8F; Thu, 20 May 2021 09:56:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504580; bh=1v/fpX5itMTgskpq10ESQ6Qgjin0r7MipspUBob+ipM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KixcwfqxLkt6Him+/00qkPILt2hEMqbZIJeeeCRD43jDwMANiTWedqPUmMyt5zWnY IGVNKsXgzkfAcsZYeMKenZdFxqOrng40qLi33M93LsjWZR8bKBxi/x5rGjRSyuYHna XWxdQ3tA55jdBR4432UuOlXNTgLfsyvAkZ0Phe5c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "louis.wang" , Russell King , Sasha Levin Subject: [PATCH 4.14 309/323] ARM: 9066/1: ftrace: pause/unpause function graph tracer in cpu_suspend() Date: Thu, 20 May 2021 11:23:21 +0200 Message-Id: <20210520092130.822065788@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 d08099269e35..e126386fb78a 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 @@ -26,6 +27,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 @@ -33,6 +41,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(); @@ -46,7 +57,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