From patchwork Tue Jan 31 14:22:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 50895 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2780116wrn; Tue, 31 Jan 2023 06:27:43 -0800 (PST) X-Google-Smtp-Source: AK7set+UvIm7d9Lom/R0P1OA3/yG8jn+paO8Qvnh15+SoC+dEOEw010Rlr6Y0ttbejX4xfgWqDDS X-Received: by 2002:a17:907:2bd9:b0:888:a0eb:c5d8 with SMTP id gv25-20020a1709072bd900b00888a0ebc5d8mr2944360ejc.28.1675175262972; Tue, 31 Jan 2023 06:27:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675175262; cv=none; d=google.com; s=arc-20160816; b=q4gJ7lDV1wFW5oOtwkZidgvipcH7uZkJjHe5TK+rVtCa0zAEbkMelAHXEORpwQ1LSz i1BsbZLFjfMsIvLmzv1H83Xkd/cyZ4y5y2hZDLTZawi1UlHzxoEEEreE5nRppQtJ1cKG AwbcAPJl4SRQrsR7fNVHioyC48V66rJoEun+3Q3qn3rgfQL5ethjXPluwx0ZN8pa9Apa vtlYr6dWBuvXxMTR3Tr2I5HGh88f9L0mALYnqQ3XaEjc4vd/Hw4q0vz1lChT6P4Gjpe6 ilgfC0Xr04YC4425wfTASJ+3BDF8g7jJtIzzSqoPBCnIqhOG3242MtuhvBmAfVUlDXeK u4vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=oIK6h1KtCD8rcXT0b011MAZsKo8KXw2KFk2eTEW6GPs=; b=eYz9Qe129zLFpVoc3hH7PP0uCmIbav4lRCDrgZVHqFduPSqieWB4+/CTm2jptFR6Bb w12KZsYaO95pGiS5JJrtsNnMkF0rT6jmqy+/AffqvDsfYpHSfBxDffgZgom4ct1MWVRi dW4L4pfiNKV4C6BZV6hbdECuLYwPMcU8to1HvrqD2rZiJvxeXDhZMcLGzXV3YgBMo5XY 0gikqqf7f37auAfbFxvqcATYJhFq65uxKnINkSln/RQioWOU55p6ag1Gw+lUB707YXiO R6CmtGKeNX5XxhWnlLkmI33tjdgBv61tWWudbXthH2tyRPltnSD6evu3wCPpYfNUeTI1 9lgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=slof44rc; dkim=neutral (no key) header.i=@linutronix.de header.b=QxZJbH+U; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iy8-20020a170907818800b0087bd629e9dcsi14366332ejc.173.2023.01.31.06.27.14; Tue, 31 Jan 2023 06:27:42 -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=@linutronix.de header.s=2020 header.b=slof44rc; dkim=neutral (no key) header.i=@linutronix.de header.b=QxZJbH+U; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231215AbjAaOXB (ORCPT + 99 others); Tue, 31 Jan 2023 09:23:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231891AbjAaOWc (ORCPT ); Tue, 31 Jan 2023 09:22:32 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 068B8227BE; Tue, 31 Jan 2023 06:22:31 -0800 (PST) Date: Tue, 31 Jan 2023 14:22:28 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1675174949; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oIK6h1KtCD8rcXT0b011MAZsKo8KXw2KFk2eTEW6GPs=; b=slof44rc3eWWU/WuZj9MtjapNPbZRcBfswkwWAQ623al5j/rJ/Tc/ZREOyau2E6Uv+nScV 0RUcbTDqyNz4MKYkwDq+NNWzOubZ9EeXBv9r2Fy5R55ZcPStThTi4WSD0b+xX4ATxDDhfa rCDh6MQDo06QXmKfpIJ7MdoYzbXheYsSQ6K32cp3YkeBNehMLbMyLAsGS1QW9jm/tHG5Z1 uJj5dAO9GXuXsqMu4sRmFHj1iLwYI5rBXl27jVAmXJ+xTTP5uqlwgtJvFN6Gdn3F9gw2er nF1NBMCqoM7EFBztPMDhT1OYN5naVAiq5grftq1dE6Hdidp1GtB7nIpF30n/kQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1675174949; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oIK6h1KtCD8rcXT0b011MAZsKo8KXw2KFk2eTEW6GPs=; b=QxZJbH+U1SzLTgoCsa3Guo8aqcARSQP0zUr7TqQoAeJ3g2rqdLHecbM2d28wIYGPVTDNHL rnBccCzxgqxlurDA== From: "tip-bot2 for Mark Rutland" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] cpuidle: drivers: firmware: psci: Dont instrument suspend code Cc: Mark Rutland , "Peter Zijlstra (Intel)" , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230126151323.349423061@infradead.org> References: <20230126151323.349423061@infradead.org> MIME-Version: 1.0 Message-ID: <167517494867.4906.2717215016942079366.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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_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?1756548576407954936?= X-GMAIL-MSGID: =?utf-8?q?1756548576407954936?= The following commit has been merged into the sched/core branch of tip: Commit-ID: 393e2ea30aec634b37004d401863428e120d5e1b Gitweb: https://git.kernel.org/tip/393e2ea30aec634b37004d401863428e120d5e1b Author: Mark Rutland AuthorDate: Thu, 26 Jan 2023 16:08:30 +01:00 Committer: Ingo Molnar CommitterDate: Tue, 31 Jan 2023 15:01:45 +01:00 cpuidle: drivers: firmware: psci: Dont instrument suspend code 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) Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20230126151323.349423061@infradead.org --- drivers/firmware/psci/psci.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index aef76d8..29619f4 100644 --- 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_hvc(unsigned long function_id, 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_smc(unsigned long function_id, 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, u32 state, unsigned long entry_point) 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); @@ -450,10 +455,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); }