From patchwork Thu Jan 26 15:08:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 48744 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp323858wrn; Thu, 26 Jan 2023 07:16:25 -0800 (PST) X-Google-Smtp-Source: AK7set/nAlQRPujPUvRcBzUI1q49sx4FSxav2xRnJBdUqI3sJZ4fsL42EMXyUNwlAyzgFnVE8Nyj X-Received: by 2002:a05:6402:378:b0:4a0:e442:5df8 with SMTP id s24-20020a056402037800b004a0e4425df8mr1474687edw.18.1674746185629; Thu, 26 Jan 2023 07:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674746185; cv=none; d=google.com; s=arc-20160816; b=RPQ49S3pECilKNLstFMsWK0Jk5YLEnGo4IEQ6y2AihFzZ0QncuEaBvJv7zQOFEtQ8k ND6yUEX5mySm5ZmsdXn9e9Ix1chfUejgNDhKvUiXJDWJF3VeZ7koXMcqAjgDoypczaSB JQz+RN/c8UQ6xHEBEpHHbauH7rkSY4sbANLGGHo1K3imAAzteFyjBrtuZvV+ERKxMwWV p2I62VY/2DiBnmOuhsJn8Lzy4SCZtD9eFp7k9TDuVFloxZ1x8jrGOQtTg6zk1a2s46ST j8HSI3e4ieHxTVWK0FdusPzHa1sXXHwCRnKlbtJ6FAG/cTk2384vMOQc8ZId9eNJFXOq ViKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=pyTrMe3jhurI/BaMPEZBtDxCzUP65k9hfIEEnQDx/dc=; b=Akfow5+cnFtZpPxjmuNR7sg8AnXn2rOBzzaAOj7x07kXXSjEScsl5/jTMRWAga25/k /tkyRpQrU2we+Voxz27tDZlJSm/2X0xDhDPCOQx38rBgoXhEVOjQPH4uYW3OzR95tGBb EOCLnKXh0N0GnDMBXLlQdtGie+YkHAQ27zLvMpwuc2RwYhR+Ky9CvAKsn4VCiIYumDEi YjbqFyBbTWIAZiwKLFtgfyLJlbFDrBMprUtTdx2p+LiWw6Uab/5QyJf9xux0P096qjtP H/2Lb12HJXlXdanIzH5a+wGJjCXyG5cJI7ld1at+pyuIOKCBSU2e/NvU+XlUupWil+lB PrJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=SCwG+pI8; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020a05640240d200b0049e75f3f624si2521399edb.0.2023.01.26.07.16.02; Thu, 26 Jan 2023 07:16:25 -0800 (PST) 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=@infradead.org header.s=casper.20170209 header.b=SCwG+pI8; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232235AbjAZPPp (ORCPT + 99 others); Thu, 26 Jan 2023 10:15:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231994AbjAZPPj (ORCPT ); Thu, 26 Jan 2023 10:15:39 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46B38A270; Thu, 26 Jan 2023 07:15:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=pyTrMe3jhurI/BaMPEZBtDxCzUP65k9hfIEEnQDx/dc=; b=SCwG+pI8dtXiXs5fHX2T03qFh2 FxmbB75QLDwxETIRu7SzBr44AIZPxkRheMoOz2leFrDzr7pCwCg96bSIE3YZ7ixOkCI8zeqUnWkeq yhMxx9kJ12vTPTX4yd9cZWPhKEpliYGXUXd6AlvngD7wny+Xocx/BBzCKGB02L8jbUewkukPrldTL g0wdXPHGwND+vSctF5py0h78sDcQ35z39TocjSH26Z2JWyeJTe/zQGOWfraVT7GlVvrLoKlJbnwgL m4iNuVXSYpt6iRhgxyWU6g7BLDonTQNB8dyyViN6YqjQXpJ44ZGL9o+Q8XtceVirkr/I2Ed3hkxap O+p80HNA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pL3xn-006qUE-F4; Thu, 26 Jan 2023 15:14:56 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 298AA300657; Thu, 26 Jan 2023 16:14:53 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 0AE0D2084C4A9; Thu, 26 Jan 2023 16:14:53 +0100 (CET) Message-ID: <20230126151323.349423061@infradead.org> User-Agent: quilt/0.66 Date: Thu, 26 Jan 2023 16:08:30 +0100 From: Peter Zijlstra To: mingo@kernel.org Cc: will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, mark.rutland@arm.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, jgross@suse.com, srivatsa@csail.mit.edu, amakhalov@vmware.com, pv-drivers@vmware.com, wanpengli@tencent.com, vkuznets@redhat.com, boris.ostrovsky@oracle.com, rafael@kernel.org, daniel.lezcano@linaro.org, lpieralisi@kernel.org, frederic@kernel.org, paulmck@kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, longman@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-pm@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 1/9] drivers: firmware: psci: Dont instrument suspend code References: <20230126150829.087606759@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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?1756098656384891138?= X-GMAIL-MSGID: =?utf-8?q?1756098656384891138?= From: Mark Rutland The PSCI suspend code is currently instrumentable, which is not safe as instrumentation (e.g. ftrace) may try to make use of RCU during idle periods when RCU is not watching. To fix this we need to ensure that psci_suspend_finisher() and anything it calls are not instrumented. We can do this fairly simply by marking psci_suspend_finisher() and the psci*_cpu_suspend() functions as noinstr, and the underlying helper functions as __always_inline. When CONFIG_DEBUG_VIRTUAL=y, __pa_symbol() can expand to an out-of-line instrumented function, so we must use __pa_symbol_nodebug() within psci_suspend_finisher(). The raw SMCCC invocation functions are written in assembly, and are not subject to compiler instrumentation. Signed-off-by: Mark Rutland Signed-off-by: Peter Zijlstra (Intel) --- drivers/firmware/psci/psci.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -108,9 +108,10 @@ bool psci_power_state_is_valid(u32 state return !(state & ~valid_mask); } -static unsigned long __invoke_psci_fn_hvc(unsigned long function_id, - unsigned long arg0, unsigned long arg1, - unsigned long arg2) +static __always_inline unsigned long +__invoke_psci_fn_hvc(unsigned long function_id, + unsigned long arg0, unsigned long arg1, + unsigned long arg2) { struct arm_smccc_res res; @@ -118,9 +119,10 @@ static unsigned long __invoke_psci_fn_hv return res.a0; } -static unsigned long __invoke_psci_fn_smc(unsigned long function_id, - unsigned long arg0, unsigned long arg1, - unsigned long arg2) +static __always_inline unsigned long +__invoke_psci_fn_smc(unsigned long function_id, + unsigned long arg0, unsigned long arg1, + unsigned long arg2) { struct arm_smccc_res res; @@ -128,7 +130,7 @@ static unsigned long __invoke_psci_fn_sm return res.a0; } -static int psci_to_linux_errno(int errno) +static __always_inline int psci_to_linux_errno(int errno) { switch (errno) { case PSCI_RET_SUCCESS: @@ -169,7 +171,8 @@ int psci_set_osi_mode(bool enable) return psci_to_linux_errno(err); } -static int __psci_cpu_suspend(u32 fn, u32 state, unsigned long entry_point) +static __always_inline int +__psci_cpu_suspend(u32 fn, u32 state, unsigned long entry_point) { int err; @@ -177,13 +180,15 @@ static int __psci_cpu_suspend(u32 fn, u3 return psci_to_linux_errno(err); } -static int psci_0_1_cpu_suspend(u32 state, unsigned long entry_point) +static __always_inline int +psci_0_1_cpu_suspend(u32 state, unsigned long entry_point) { return __psci_cpu_suspend(psci_0_1_function_ids.cpu_suspend, state, entry_point); } -static int psci_0_2_cpu_suspend(u32 state, unsigned long entry_point) +static __always_inline int +psci_0_2_cpu_suspend(u32 state, unsigned long entry_point) { return __psci_cpu_suspend(PSCI_FN_NATIVE(0_2, CPU_SUSPEND), state, entry_point); @@ -447,10 +452,12 @@ late_initcall(psci_debugfs_init) #endif #ifdef CONFIG_CPU_IDLE -static int psci_suspend_finisher(unsigned long state) +static noinstr int psci_suspend_finisher(unsigned long state) { u32 power_state = state; - phys_addr_t pa_cpu_resume = __pa_symbol(cpu_resume); + phys_addr_t pa_cpu_resume; + + pa_cpu_resume = __pa_symbol_nodebug((unsigned long)cpu_resume); return psci_ops.cpu_suspend(power_state, pa_cpu_resume); }