From patchwork Fri Nov 8 18:49:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 178924 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3122560ilf; Fri, 8 Nov 2019 10:53:03 -0800 (PST) X-Google-Smtp-Source: APXvYqxMXIqt8uZgC2FD+F6LAHmzrlaUR1Nk0ilY6V7xNYCFAQOr9C28FtHEM5X/EawVZbWTs8HZ X-Received: by 2002:aa7:c894:: with SMTP id p20mr12350650eds.145.1573239183034; Fri, 08 Nov 2019 10:53:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573239183; cv=none; d=google.com; s=arc-20160816; b=AYofmah2+l+DuWWgOAWOtbCLrY31knHifEUmZrFCGb4Yn6KsQh9HMVb4aP2DovWtwW 4esDER+TCKoaBVmFZO1x81hwf9I6Mfexsiv126W7e8DZgGA3iFgIfUFcQM66CPDNmzEh /rmkJ0qVfYkle27P5em1rDEtvDSnpPNrVIMI0Qtff4HEMoYtrNnDA5hAdm0ijNL5TpQ7 FRKNB7luhkjGlc45vsBTOsJDdGpOyWOgRNPJaCSSB4oF+Z4757fI43391fHxztsGTBdm f1QFrGm/RbZgGoWpMlWHUKgHi8RsEcRvkIfwiqqHzdh0h3PdX6khNhbhaUfcHBLrtbam Bv7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xgj/Fq4glfHtilUXxR5cJzjHVhHRmlW56KjP8gC6VC8=; b=bI6FtBT2DadzhqPnexeeeJrWRdoXJPvi/X7C2ax9632dmmX/ySDxu2jrq9ffOU0AOV yWOHHMNLDcFyJdzCTISGRJ/sV+/nLQ54moBNeNvMeEEX6Sgnyp8yB3nFlU4tD5UzvMrd dkx3dfo3/XyyOH1lxJmkdQMzY6jrVgeMgwmbomwozNP3lYo62VKA/rux5YV0if4RIGsU 5sD0lFCuT8oiv6tacQY7EA7ICH5HcW79mr8MmbpNZ7HXn13azdzz04K9BDe3Iz4EaxwV HM7q5+RzX4DjFIvGe9YHEV4monOt7FZtDbWmXb4dkXjiHdWJkMRShBYmLejDo4NZlTuB E7ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yf3OodHr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p48si4984962eda.80.2019.11.08.10.53.02; Fri, 08 Nov 2019 10:53:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yf3OodHr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732040AbfKHSxA (ORCPT + 26 others); Fri, 8 Nov 2019 13:53:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:49400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731956AbfKHSw5 (ORCPT ); Fri, 8 Nov 2019 13:52:57 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A71C9218AE; Fri, 8 Nov 2019 18:52:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239176; bh=bnqnoiQvoBRI+CacKWPbzl9Bx0OGbwcI9MPPmbbRMrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yf3OodHrNGGcngxP+Pp1gUcdX1v69YNRzb0DP+PTLmKSBbkiXpRxWbPz6SVqQs4qA IYHiaOagXDAdxkKqAhH/Py53/9Dm/UKhhscx6fAy3eukfADVtftGVe9c0wwgVOiQyw IR2BRWeNrBVp8mHlnezZEOBJa13LcEjqaJZyiWmg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Lorenzo Pieralisi , Jens Wiklander , Russell King , Ard Biesheuvel Subject: [PATCH 4.4 25/75] ARM: 8478/2: arm/arm64: add arm-smccc Date: Fri, 8 Nov 2019 19:49:42 +0100 Message-Id: <20191108174732.203467155@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174708.135680837@linuxfoundation.org> References: <20191108174708.135680837@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Wiklander Commit 98dd64f34f47ce19b388d9015f767f48393a81eb upstream. Adds helpers to do SMC and HVC based on ARM SMC Calling Convention. CONFIG_HAVE_ARM_SMCCC is enabled for architectures that may support the SMC or HVC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform. This patch doesn't provide an implementation of the declared functions. Later patches will bring in implementations and set CONFIG_HAVE_ARM_SMCCC for ARM and ARM64 respectively. Reviewed-by: Lorenzo Pieralisi Signed-off-by: Jens Wiklander Signed-off-by: Russell King Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/Kconfig | 3 + include/linux/arm-smccc.h | 104 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -174,6 +174,9 @@ config QCOM_SCM_64 def_bool y depends on QCOM_SCM && ARM64 +config HAVE_ARM_SMCCC + bool + source "drivers/firmware/broadcom/Kconfig" source "drivers/firmware/google/Kconfig" source "drivers/firmware/efi/Kconfig" --- /dev/null +++ b/include/linux/arm-smccc.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2015, Linaro Limited + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ +#ifndef __LINUX_ARM_SMCCC_H +#define __LINUX_ARM_SMCCC_H + +#include +#include + +/* + * This file provides common defines for ARM SMC Calling Convention as + * specified in + * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html + */ + +#define ARM_SMCCC_STD_CALL 0 +#define ARM_SMCCC_FAST_CALL 1 +#define ARM_SMCCC_TYPE_SHIFT 31 + +#define ARM_SMCCC_SMC_32 0 +#define ARM_SMCCC_SMC_64 1 +#define ARM_SMCCC_CALL_CONV_SHIFT 30 + +#define ARM_SMCCC_OWNER_MASK 0x3F +#define ARM_SMCCC_OWNER_SHIFT 24 + +#define ARM_SMCCC_FUNC_MASK 0xFFFF + +#define ARM_SMCCC_IS_FAST_CALL(smc_val) \ + ((smc_val) & (ARM_SMCCC_FAST_CALL << ARM_SMCCC_TYPE_SHIFT)) +#define ARM_SMCCC_IS_64(smc_val) \ + ((smc_val) & (ARM_SMCCC_SMC_64 << ARM_SMCCC_CALL_CONV_SHIFT)) +#define ARM_SMCCC_FUNC_NUM(smc_val) ((smc_val) & ARM_SMCCC_FUNC_MASK) +#define ARM_SMCCC_OWNER_NUM(smc_val) \ + (((smc_val) >> ARM_SMCCC_OWNER_SHIFT) & ARM_SMCCC_OWNER_MASK) + +#define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \ + (((type) << ARM_SMCCC_TYPE_SHIFT) | \ + ((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \ + (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \ + ((func_num) & ARM_SMCCC_FUNC_MASK)) + +#define ARM_SMCCC_OWNER_ARCH 0 +#define ARM_SMCCC_OWNER_CPU 1 +#define ARM_SMCCC_OWNER_SIP 2 +#define ARM_SMCCC_OWNER_OEM 3 +#define ARM_SMCCC_OWNER_STANDARD 4 +#define ARM_SMCCC_OWNER_TRUSTED_APP 48 +#define ARM_SMCCC_OWNER_TRUSTED_APP_END 49 +#define ARM_SMCCC_OWNER_TRUSTED_OS 50 +#define ARM_SMCCC_OWNER_TRUSTED_OS_END 63 + +/** + * struct arm_smccc_res - Result from SMC/HVC call + * @a0-a3 result values from registers 0 to 3 + */ +struct arm_smccc_res { + unsigned long a0; + unsigned long a1; + unsigned long a2; + unsigned long a3; +}; + +/** + * arm_smccc_smc() - make SMC calls + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 3 + * + * This function is used to make SMC calls following SMC Calling Convention. + * The content of the supplied param are copied to registers 0 to 7 prior + * to the SMC instruction. The return values are updated with the content + * from register 0 to 3 on return from the SMC instruction. + */ +asmlinkage void arm_smccc_smc(unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, unsigned long a4, + unsigned long a5, unsigned long a6, unsigned long a7, + struct arm_smccc_res *res); + +/** + * arm_smccc_hvc() - make HVC calls + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 3 + * + * This function is used to make HVC calls following SMC Calling + * Convention. The content of the supplied param are copied to registers 0 + * to 7 prior to the HVC instruction. The return values are updated with + * the content from register 0 to 3 on return from the HVC instruction. + */ +asmlinkage void arm_smccc_hvc(unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, unsigned long a4, + unsigned long a5, unsigned long a6, unsigned long a7, + struct arm_smccc_res *res); + +#endif /*__LINUX_ARM_SMCCC_H*/ From patchwork Fri Nov 8 18:49:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 178926 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3122774ilf; Fri, 8 Nov 2019 10:53:14 -0800 (PST) X-Google-Smtp-Source: APXvYqxFKC8ZllF7H8mI9Gqniqe+GL1sfAT/W3KH1Tlo8e/jrMosvT7KGh9tsbGYkJzuYScp1IOs X-Received: by 2002:a17:906:e82:: with SMTP id p2mr10125550ejf.237.1573239194148; Fri, 08 Nov 2019 10:53:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573239194; cv=none; d=google.com; s=arc-20160816; b=YHmytWDK4PGreT+1X2/xaF8IPh5YblDti7Rn2Sye8C3H/trLsUpQyG/BxbG0cjEMMN F+DdaV7QgRQgK4EdLi2sGYzCROf01/+A6Z24Fgn/SZ6Cxp3xqz+mQ0hO5Qj8ReA4VKAd g6quYedu5G3RFV+G3YFYwbNTyjA99Iv5fneMCtCWS0209H2cNfH1MM5erkqHt7Xj8+LU rJEwYVy9VSIRJk1ZwVzBOusII7/L/AU7azFn4CGOkOVLPl38H5rj21AxYweKwz3Fn0nW M2kQpOIEXDUHaQW27Y3l5PXLYV+rcJbTgXSeHlpwxbXGi3b+uDjmmuoC4aFXC9/S/zwd IqDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qG36bQp5nYiB2OcC2lEgSuFJulAB/Da7R1nzYax5qn8=; b=cBCdMWyA46HIPa7ZcDxPV/ZcscMDaewNY++W1UnuCZ0NHQ7ZSUXui3ec2ISvz4wdSq PnBuRdDF17EXfgLAry+QLFJq2K74N5QVuHmq4jufXpwGJ3i4lwHSHXt/Qxbl0U/JRETO j/0tHZgD8yrGHotLX8rJ0C3m5KTNNZQOMBpcZtfsoMtJKFmscgXKpQPcdnXddwNXEYXc Mc7MaboS7zS1CYbNevvoRjwKSnEcJBz6yZ5GqlIC55JE9bA642Xtr8g/zkq7paAM8VoI DldAchbgIanf0otbfM5Cv9s1SvzNGUrwXxAMASCaBgQ3fbolEoaU7VxoRT1wpOr3jf/C e+ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zXb5zw2P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q14si4370605eju.84.2019.11.08.10.53.13; Fri, 08 Nov 2019 10:53:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zXb5zw2P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732138AbfKHSxG (ORCPT + 26 others); Fri, 8 Nov 2019 13:53:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:49526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732062AbfKHSxD (ORCPT ); Fri, 8 Nov 2019 13:53:03 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8AE272178F; Fri, 8 Nov 2019 18:53:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239182; bh=okz7moNdWPsmJ7K4RPpIrtFBDE6a6Bdn6WehFWWNr2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zXb5zw2PxSpVgEFh3Ky2OLpMycobHhCREQiC0jI5QlpIK8zOfac9qfFO4Q+E4QZDj fmmLj1nwXDWOSElE8vYzGI+LfeCqfdoYFCbR74Te+jbfVKLb4AcmOZxO9qceb8GL2M LGyZV2CaUiCchflJuxxouqyQKhuRYxoo8kAO+7vk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Will Deacon , Jens Wiklander , Russell King , Ard Biesheuvel Subject: [PATCH 4.4 27/75] ARM: 8480/2: arm64: add implementation for arm-smccc Date: Fri, 8 Nov 2019 19:49:44 +0100 Message-Id: <20191108174734.422472400@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174708.135680837@linuxfoundation.org> References: <20191108174708.135680837@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Wiklander Commit 14457459f9ca2ff8521686168ea179edc3a56a44 upstream. Adds implementation for arm-smccc and enables CONFIG_HAVE_SMCCC. Acked-by: Will Deacon Signed-off-by: Jens Wiklander Signed-off-by: Russell King Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- arch/arm64/Kconfig | 1 arch/arm64/kernel/Makefile | 2 - arch/arm64/kernel/arm64ksyms.c | 5 ++++ arch/arm64/kernel/asm-offsets.c | 3 ++ arch/arm64/kernel/smccc-call.S | 43 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -92,6 +92,7 @@ config ARM64 select SPARSE_IRQ select SYSCTL_EXCEPTION_TRACE select HAVE_CONTEXT_TRACKING + select HAVE_ARM_SMCCC help ARM 64-bit (AArch64) Linux support. --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -17,7 +17,7 @@ arm64-obj-y := debug-monitors.o entry.o hyp-stub.o psci.o psci-call.o cpu_ops.o insn.o \ return_address.o cpuinfo.o cpu_errata.o \ cpufeature.o alternative.o cacheinfo.o \ - smp.o smp_spin_table.o topology.o + smp.o smp_spin_table.o topology.o smccc-call.o extra-$(CONFIG_EFI) := efi-entry.o --- a/arch/arm64/kernel/arm64ksyms.c +++ b/arch/arm64/kernel/arm64ksyms.c @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -68,3 +69,7 @@ EXPORT_SYMBOL(test_and_change_bit); #ifdef CONFIG_FUNCTION_TRACER EXPORT_SYMBOL(_mcount); #endif + + /* arm-smccc */ +EXPORT_SYMBOL(arm_smccc_smc); +EXPORT_SYMBOL(arm_smccc_hvc); --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -28,6 +28,7 @@ #include #include #include +#include int main(void) { @@ -162,5 +163,7 @@ int main(void) DEFINE(SLEEP_SAVE_SP_PHYS, offsetof(struct sleep_save_sp, save_ptr_stash_phys)); DEFINE(SLEEP_SAVE_SP_VIRT, offsetof(struct sleep_save_sp, save_ptr_stash)); #endif + DEFINE(ARM_SMCCC_RES_X0_OFFS, offsetof(struct arm_smccc_res, a0)); + DEFINE(ARM_SMCCC_RES_X2_OFFS, offsetof(struct arm_smccc_res, a2)); return 0; } --- /dev/null +++ b/arch/arm64/kernel/smccc-call.S @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, Linaro Limited + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License Version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ +#include +#include + + .macro SMCCC instr + .cfi_startproc + \instr #0 + ldr x4, [sp] + stp x0, x1, [x4, #ARM_SMCCC_RES_X0_OFFS] + stp x2, x3, [x4, #ARM_SMCCC_RES_X2_OFFS] + ret + .cfi_endproc + .endm + +/* + * void arm_smccc_smc(unsigned long a0, unsigned long a1, unsigned long a2, + * unsigned long a3, unsigned long a4, unsigned long a5, + * unsigned long a6, unsigned long a7, struct arm_smccc_res *res) + */ +ENTRY(arm_smccc_smc) + SMCCC smc +ENDPROC(arm_smccc_smc) + +/* + * void arm_smccc_hvc(unsigned long a0, unsigned long a1, unsigned long a2, + * unsigned long a3, unsigned long a4, unsigned long a5, + * unsigned long a6, unsigned long a7, struct arm_smccc_res *res) + */ +ENTRY(arm_smccc_hvc) + SMCCC hvc +ENDPROC(arm_smccc_hvc) From patchwork Fri Nov 8 18:49:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 178927 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3122783ilf; Fri, 8 Nov 2019 10:53:14 -0800 (PST) X-Google-Smtp-Source: APXvYqxdIXNEcyRel0AOhqY/eNDgPpVEObB3jzxyoDAYNNzLJfPq74VnnC7p675MKV00fA7f7E2u X-Received: by 2002:a17:906:b30c:: with SMTP id n12mr10101812ejz.96.1573239194554; Fri, 08 Nov 2019 10:53:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573239194; cv=none; d=google.com; s=arc-20160816; b=Tj3LdsccI15hfBdvzhJ/elYtlyloMviEgTsAKAeV0DFWBytsAn5dxJu/2N69MWmmKo 0wm8FKO3fvs2wKmUK4p7WojLrTrj0xKJjVer0Oqs10r+6+Vnsk2m6Fac5OWay3uxB2Dz BcBKim3vxQHvM25mYmuN1zsVnI3yCd9LCrIYWZuFkQsW69yPfJdfs7cdK1B/XfhRl3D4 KDuYT+rvWLwKmmNKeGvCuGl925rhidWkNRJPzbThpsXyQR7aJ8YtXwaSQ+oO71D4KPG9 RYcOWHQMBihDIFIlkco12ll/mjT7G9vykCsV3kGBC70bF6G4bagIo36DTBnmyLnQlK+z sZ6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=U4gMcribqagKlvEhqa2szZu6o7emPItkXvuksaCMiF8=; b=HoV2rBOg2AcPzetcOP8BZswjT2kEaEsHaUlKrguuL8mYd5r1QduIMSYi8MqoL8A8nE 8/clJBf1znE0u0NYtDQM+KXXLvTZSuGfvv+Ph6EpTxVE/LX/yjTeov0XdIiGkavY9UBI fjZ8mG7111VtXIp3dZE9EP6OBBZ42qw5477YgQvB92tTrZGO3eouSsEIZ6ybeIEMG/+Z PYnX4geLd1p9xw5r7TbZUui+SiU7x24ouIBXmJFMYx2v5r+Hcj4bcdW3T0FR1Bf7wDB0 vi65+Jj/WtwqpcZysnNlSz7qkNLvClDQ7fprerHb/E1n1gI2gejaDyRUypwZm7H1lIx4 mrQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EaIdB8DT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q14si4370605eju.84.2019.11.08.10.53.14; Fri, 08 Nov 2019 10:53:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EaIdB8DT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732175AbfKHSxH (ORCPT + 26 others); Fri, 8 Nov 2019 13:53:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:49604 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732122AbfKHSxG (ORCPT ); Fri, 8 Nov 2019 13:53:06 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BAF82218AE; Fri, 8 Nov 2019 18:53:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239185; bh=mitT5kRyjgMuE0b5izVQvm5gdxxVv1WzGuiqzYb/5G0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EaIdB8DT2kK+bN/aDU4A4aOhiKwivzfAF201OdLlVkuDc2JDTP4zRpEbOAH8y75oi KmFauhCSHzMzXOVOw4tBG/AJohtqoPprQUmCInS/2llSDuJBKbcwQF1qyqfrMGXaEN sHM5xy3zK9VbjNKr6Nrya1I1DW3PGxWnsfZ77dAI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Jens Wiklander , Russell King , Ard Biesheuvel Subject: [PATCH 4.4 28/75] ARM: 8481/2: drivers: psci: replace psci firmware calls Date: Fri, 8 Nov 2019 19:49:45 +0100 Message-Id: <20191108174735.588889968@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174708.135680837@linuxfoundation.org> References: <20191108174708.135680837@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Wiklander Commit e679660dbb8347f275fe5d83a5dd59c1fb6c8e63 upstream. Switch to use a generic interface for issuing SMC/HVC based on ARM SMC Calling Convention. Removes now the now unused psci-call.S. Acked-by: Will Deacon Reviewed-by: Mark Rutland Tested-by: Mark Rutland Acked-by: Lorenzo Pieralisi Tested-by: Lorenzo Pieralisi Signed-off-by: Jens Wiklander Signed-off-by: Russell King Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- arch/arm/Kconfig | 2 +- arch/arm/kernel/Makefile | 1 - arch/arm/kernel/psci-call.S | 31 ------------------------------- arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/psci-call.S | 28 ---------------------------- drivers/firmware/psci.c | 23 +++++++++++++++++++++-- 6 files changed, 23 insertions(+), 64 deletions(-) --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1482,7 +1482,7 @@ config HOTPLUG_CPU config ARM_PSCI bool "Support for the ARM Power State Coordination Interface (PSCI)" - depends on CPU_V7 + depends on HAVE_ARM_SMCCC select ARM_PSCI_FW help Say Y here if you want Linux to communicate with system firmware --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile @@ -87,7 +87,6 @@ obj-$(CONFIG_EARLY_PRINTK) += early_prin obj-$(CONFIG_ARM_VIRT_EXT) += hyp-stub.o ifeq ($(CONFIG_ARM_PSCI),y) -obj-y += psci-call.o obj-$(CONFIG_SMP) += psci_smp.o endif --- a/arch/arm/kernel/psci-call.S +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Copyright (C) 2015 ARM Limited - * - * Author: Mark Rutland - */ - -#include - -#include -#include - -/* int __invoke_psci_fn_hvc(u32 function_id, u32 arg0, u32 arg1, u32 arg2) */ -ENTRY(__invoke_psci_fn_hvc) - __HVC(0) - bx lr -ENDPROC(__invoke_psci_fn_hvc) - -/* int __invoke_psci_fn_smc(u32 function_id, u32 arg0, u32 arg1, u32 arg2) */ -ENTRY(__invoke_psci_fn_smc) - __SMC(0) - bx lr -ENDPROC(__invoke_psci_fn_smc) --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -14,7 +14,7 @@ CFLAGS_REMOVE_return_address.o = -pg arm64-obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ entry-fpsimd.o process.o ptrace.o setup.o signal.o \ sys.o stacktrace.o time.o traps.o io.o vdso.o \ - hyp-stub.o psci.o psci-call.o cpu_ops.o insn.o \ + hyp-stub.o psci.o cpu_ops.o insn.o \ return_address.o cpuinfo.o cpu_errata.o \ cpufeature.o alternative.o cacheinfo.o \ smp.o smp_spin_table.o topology.o smccc-call.o --- a/arch/arm64/kernel/psci-call.S +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * Copyright (C) 2015 ARM Limited - * - * Author: Will Deacon - */ - -#include - -/* int __invoke_psci_fn_hvc(u64 function_id, u64 arg0, u64 arg1, u64 arg2) */ -ENTRY(__invoke_psci_fn_hvc) - hvc #0 - ret -ENDPROC(__invoke_psci_fn_hvc) - -/* int __invoke_psci_fn_smc(u64 function_id, u64 arg0, u64 arg1, u64 arg2) */ -ENTRY(__invoke_psci_fn_smc) - smc #0 - ret -ENDPROC(__invoke_psci_fn_smc) --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -13,6 +13,7 @@ #define pr_fmt(fmt) "psci: " fmt +#include #include #include #include @@ -58,8 +59,6 @@ struct psci_operations psci_ops; typedef unsigned long (psci_fn)(unsigned long, unsigned long, unsigned long, unsigned long); -asmlinkage psci_fn __invoke_psci_fn_hvc; -asmlinkage psci_fn __invoke_psci_fn_smc; static psci_fn *invoke_psci_fn; enum psci_function { @@ -107,6 +106,26 @@ 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) +{ + struct arm_smccc_res res; + + arm_smccc_hvc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res); + return res.a0; +} + +static unsigned long __invoke_psci_fn_smc(unsigned long function_id, + unsigned long arg0, unsigned long arg1, + unsigned long arg2) +{ + struct arm_smccc_res res; + + arm_smccc_smc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res); + return res.a0; +} + static int psci_to_linux_errno(int errno) { switch (errno) { From patchwork Fri Nov 8 18:49:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 178930 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3123034ilf; Fri, 8 Nov 2019 10:53:30 -0800 (PST) X-Google-Smtp-Source: APXvYqxvdzIp4Ik3S6YuKKP12t2hgJ4S4EyuSrhku/iKG07Q6nHmfXwogek9d62mNjXJZp4TA9z1 X-Received: by 2002:aa7:c716:: with SMTP id i22mr12029166edq.237.1573239210725; Fri, 08 Nov 2019 10:53:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573239210; cv=none; d=google.com; s=arc-20160816; b=n3hxZj4psODdlRPR3Sr1jTIsQOY9nXmVtj9P79etGJT0K0s0Su2rj/gVLLwZ7ZPx4R LJP4Z1IbIaR7OD1/dHZhu4/VanAhXDEiwQHPLgZQGPRouqNuS/NQPKiaqPyqKT/ixzZU 8w7K2K8CGS2m6BmK5k8mbBKTwLqq2svM4BW7ARa2lsDoTik/Nks1Lze6lqKTMRKol46/ XoRfoEdzoQEapeCZn0XZuUx5MMnF1HzwAZtR+/fJB7tHbXZda3iSyogMWeWt6euNwVyy GQJV3/NNGkty/Hs/U9qSFM+8mNCAkvA+cl9aU1zP5EWwA3zQi36O1EV8+xts/GyFX7E0 UTDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vwObMO21ygZ8YzmZgROTPtNfS02+cAaBZA+K18y9pbs=; b=o8X20Q9wdlLrcDltleYfPJvUVZUpcbNp0XTOPSNWZkv6FGC/9cBBVXzX1fCeHoPTke NENzhoazYk+9drRN6PVLx0uvv9hYxLxyI85Xa3Lmq2VxmKmP6Ybgd8K7JAi+VOLeo6Bv oqpkI1pEIW0GsTT1VxLUf0O/Y8ExSPMJ74ZyctDWCUPgJDTLmzAgWkkOp3xRzVv46RMs sEsguJOAXP2zialWbPvafNMcecjWKikoN9shuaK2iXSiSZSq0AzjppxaEDk6ifB1za3K VU53OOxGhYZlngYCmYF4u4gjdVGhJp2TqWDKqyMouOkDAJY2cP7exlfqxbGTrLKZp/Rq XW1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RNznpc9k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t17si4617768ejg.44.2019.11.08.10.53.30; Fri, 08 Nov 2019 10:53:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RNznpc9k; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732364AbfKHSx3 (ORCPT + 26 others); Fri, 8 Nov 2019 13:53:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:50036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732330AbfKHSx0 (ORCPT ); Fri, 8 Nov 2019 13:53:26 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C412C21D7E; Fri, 8 Nov 2019 18:53:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239205; bh=KKlZJcdyhqlpd3ZchIkEbH2IObcSf15DEVJq/PrKNuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RNznpc9kP/kcjMjzBiSl1CTLGNHJic/m3gfV1A70sPao7YXMymBQijGZoktVsh9K+ anhvNCFfNfkZjOJxkrJVQtxi4tOpcJeSMnzvRXyKd65ZMOKFUNa5mv8Y22PHayYcd4 kGV+xuQdiE48/CIPVppDtXVqGSV0pVIwRZHplBOg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Lorenzo Pieralisi , Robin Murphy , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Greg Hackmann , Ard Biesheuvel , Mark Rutland Subject: [PATCH 4.4 34/75] firmware/psci: Expose SMCCC version through psci_ops Date: Fri, 8 Nov 2019 19:49:51 +0100 Message-Id: <20191108174743.129720226@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174708.135680837@linuxfoundation.org> References: <20191108174708.135680837@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit e78eef554a912ef6c1e0bbf97619dafbeae3339f upstream. Since PSCI 1.0 allows the SMCCC version to be (indirectly) probed, let's do that at boot time, and expose the version of the calling convention as part of the psci_ops structure. Acked-by: Lorenzo Pieralisi Reviewed-by: Robin Murphy Tested-by: Ard Biesheuvel Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Mark Rutland [v4.9 backport] Tested-by: Greg Hackmann Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/psci.c | 27 +++++++++++++++++++++++++++ include/linux/psci.h | 6 ++++++ 2 files changed, 33 insertions(+) --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -57,6 +57,7 @@ bool psci_tos_resident_on(int cpu) struct psci_operations psci_ops = { .conduit = PSCI_CONDUIT_NONE, + .smccc_version = SMCCC_VERSION_1_0, }; typedef unsigned long (psci_fn)(unsigned long, unsigned long, @@ -339,6 +340,31 @@ static void __init psci_init_migrate(voi pr_info("Trusted OS resident on physical CPU 0x%lx\n", cpuid); } +static void __init psci_init_smccc(void) +{ + u32 ver = ARM_SMCCC_VERSION_1_0; + int feature; + + feature = psci_features(ARM_SMCCC_VERSION_FUNC_ID); + + if (feature != PSCI_RET_NOT_SUPPORTED) { + u32 ret; + ret = invoke_psci_fn(ARM_SMCCC_VERSION_FUNC_ID, 0, 0, 0); + if (ret == ARM_SMCCC_VERSION_1_1) { + psci_ops.smccc_version = SMCCC_VERSION_1_1; + ver = ret; + } + } + + /* + * Conveniently, the SMCCC and PSCI versions are encoded the + * same way. No, this isn't accidental. + */ + pr_info("SMC Calling Convention v%d.%d\n", + PSCI_VERSION_MAJOR(ver), PSCI_VERSION_MINOR(ver)); + +} + static void __init psci_0_2_set_functions(void) { pr_info("Using standard PSCI v0.2 function IDs\n"); @@ -385,6 +411,7 @@ static int __init psci_probe(void) psci_init_migrate(); if (PSCI_VERSION_MAJOR(ver) >= 1) { + psci_init_smccc(); psci_init_cpu_suspend(); psci_init_system_suspend(); } --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -30,6 +30,11 @@ enum psci_conduit { PSCI_CONDUIT_HVC, }; +enum smccc_version { + SMCCC_VERSION_1_0, + SMCCC_VERSION_1_1, +}; + struct psci_operations { int (*cpu_suspend)(u32 state, unsigned long entry_point); int (*cpu_off)(u32 state); @@ -39,6 +44,7 @@ struct psci_operations { unsigned long lowest_affinity_level); int (*migrate_info_type)(void); enum psci_conduit conduit; + enum smccc_version smccc_version; }; extern struct psci_operations psci_ops; From patchwork Fri Nov 8 18:49:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 178931 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3123115ilf; Fri, 8 Nov 2019 10:53:35 -0800 (PST) X-Google-Smtp-Source: APXvYqz3bWkFsyizOWopN2x5QC7srEEpWjlOYd1ioClq0E6xd/0c+YLQEDwko3sVAbGqSkCxwBNv X-Received: by 2002:a05:6402:1692:: with SMTP id a18mr12044411edv.297.1573239215404; Fri, 08 Nov 2019 10:53:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573239215; cv=none; d=google.com; s=arc-20160816; b=c8KYlog/4caFzGHndiZvbwnYOewms9wxmvx8KWnF+mfrgIHpDp+HYr9/0PHKVAEA9r WH9Bu2tEXd4UZ+Z+0w6rBH4Lx5Hk85rG7V4OLzzWyyUBBkRMy0AwA3tu5HUfYpVa4Z6Z S7zoMapgF8gjmhhwqWcOjBJJmW8xiRnDniy9wM1PKFCAgyMmroy26qNSGAi3HH3v8wc4 d+ey4s19ycuqM2HdjHlmLzJ0M/beI+9oPSqUArUzKk3lHz2ZyXmnE+nrWS8foa5h7D7P ZivQxJY3Cz9SFWx06UqP9PTCAfevohvz1MG67IIDFZX7cpfrynoLQhg7O0NUAoLMAUwN AuIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=a30r/Z+PJStDnk+pqhGFZMx8w3NTLfsflNrI7Sj5+hc=; b=mhmc5AO6KC9JhX0EgfjZF/F82LYjdCdseF4Zvs3cHmVyTL6WFMQG1WKU0VXwFIY8dv st2RLUA3nZ5trAkmnOzoQ8bIgKxqb+qEDVRrcS7wOpEiMQBNT3KiKT/yipmocR7iU3Lo ra/KHW1oRB25Gvt9Hw5N7I7Y+8uazUmJTmEZnSxSnoYhjwU9slCa+mC4zDH9YzbnpcIT D4QADSBcDPJLDw64Tz+BRwFITsqzmfq1KA6c+DT5deQlIfZ7fJeWh9rg25i7SzS4lhJ9 h3gPIp9Ho5BEpPBZKZaq3OvCepJx5A+6gDXq5bs/JoTC/xJRh08psvwiXBXN1l/Xc9Ey dDLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zXKwNwBG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d6si5306393eda.262.2019.11.08.10.53.35; Fri, 08 Nov 2019 10:53:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zXKwNwBG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732426AbfKHSxd (ORCPT + 26 others); Fri, 8 Nov 2019 13:53:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:50140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732341AbfKHSx3 (ORCPT ); Fri, 8 Nov 2019 13:53:29 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 128B3218AE; Fri, 8 Nov 2019 18:53:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239208; bh=5q8MdXl36BTYt1/zFIU1xr7uiq22NFrK9WPUMpYkyg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zXKwNwBG+CZ7/p032AlPwQ0E6MGBcUyM3Vtq7DUrbPzN+PvlKpbRz/A2rD7OhKi67 O99fWLmo28k/qTPkBKFZ4mbVHL8vCKoOMq0O1FUy98A371UW0wPV8vTFx8XYUBjwQ4 v8+i9D3ZzMAgUQS+oJsj0FQDZFLYC2mh8IaQ4Lvc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Ard Biesheuvel , Robin Murphy , Marc Zyngier , Catalin Marinas , Greg Hackmann , Ard Biesheuvel , Mark Rutland Subject: [PATCH 4.4 35/75] arm/arm64: smccc: Make function identifiers an unsigned quantity Date: Fri, 8 Nov 2019 19:49:52 +0100 Message-Id: <20191108174744.434421656@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174708.135680837@linuxfoundation.org> References: <20191108174708.135680837@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit ded4c39e93f3b72968fdb79baba27f3b83dad34c upstream. Function identifiers are a 32bit, unsigned quantity. But we never tell so to the compiler, resulting in the following: 4ac: b26187e0 mov x0, #0xffffffff80000001 We thus rely on the firmware narrowing it for us, which is not always a reasonable expectation. Cc: stable@vger.kernel.org Reported-by: Ard Biesheuvel Acked-by: Ard Biesheuvel Reviewed-by: Robin Murphy Tested-by: Ard Biesheuvel Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Mark Rutland [v4.9 backport] Tested-by: Greg Hackmann Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- include/linux/arm-smccc.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -14,14 +14,16 @@ #ifndef __LINUX_ARM_SMCCC_H #define __LINUX_ARM_SMCCC_H +#include + /* * This file provides common defines for ARM SMC Calling Convention as * specified in * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html */ -#define ARM_SMCCC_STD_CALL 0 -#define ARM_SMCCC_FAST_CALL 1 +#define ARM_SMCCC_STD_CALL _AC(0,U) +#define ARM_SMCCC_FAST_CALL _AC(1,U) #define ARM_SMCCC_TYPE_SHIFT 31 #define ARM_SMCCC_SMC_32 0 From patchwork Fri Nov 8 18:49:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 178935 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3125580ilf; Fri, 8 Nov 2019 10:55:58 -0800 (PST) X-Google-Smtp-Source: APXvYqzcjsBNLZR5BeQpLEF7JkzM2ncn++lDW4mElJTW92y0UF1z8KkaaGVqiECum8RGWMy3kLLt X-Received: by 2002:a17:906:670c:: with SMTP id a12mr10225180ejp.273.1573239358286; Fri, 08 Nov 2019 10:55:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573239358; cv=none; d=google.com; s=arc-20160816; b=IoPwfMOhOw7ICEkpor9yoj7/AmexCLvt0sEh2B0nfkob+H+GBI93Wj/GVoTFohGZwK xsamPaAdMzt1pL8K4uPFvLSZYhIHo7HnZjuJMynMS7Hicavrw+X94OZycJTC+M9x7gOn ddMv9uKrNzprNoLJNSeUywiu8YNnsPpZ8vF5Iomc48JCQmBsOtPyzfHUIPCW/C0QFb0V rTQj5WEjndb6YmIyeHObfmz1pST7jvvCqkf/OX796GQ4ExXUQD046XYeLNLBkRlj0AsA twMj0HgL/dgjatQOawELol/02OUwlLGdSqmZXx22YL5DflGwdRCrDCu5DIsqZrPkpfpj VJ+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7vWDddm7p+GFbFY6Plp2bSQZzTZk5yljyFoUNiSat3c=; b=LCnNKjlblN/brqdk/Tc1zikV3ofZTDRNZrzriWHu+UO02yJBVCFksM2+NsZYl6h6TK bBemYybx3AJO7KdM7/kCIInAOS3Lei8t7kAN37DSI3RETaMNoIy4c2o15anfs4LCvtOt la9hWw88YVZFKT5QoMXADA84/+WVhAiOHfF9EDorC18wklfP+SypqGRwghlz3tDMLjRH 9cWLFyWD6aTb5A+0R4XW70F2lwLzmDj0I8a4S33+6D0OuUiYPLe8ba0qcGhJZLyqkQBq kB0jHuAW6p80ANHU407w+LK6pLaKP9qiKmIVj58luAm4X0ll5S6hugHOaDXuJ/OT1Hli Y+aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ONptGQM1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f29si4567661ejj.110.2019.11.08.10.55.58; Fri, 08 Nov 2019 10:55:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ONptGQM1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387856AbfKHSz4 (ORCPT + 26 others); Fri, 8 Nov 2019 13:55:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:53224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730810AbfKHSzv (ORCPT ); Fri, 8 Nov 2019 13:55:51 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 966FA21D7F; Fri, 8 Nov 2019 18:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239345; bh=VEGzoeTLT8lvGWnWPd25boqWXP9L00aDYn7nZXOnfPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ONptGQM18LRqrTZyrDbioTJ+F2Q76jNihm3hFNMw1ZtGh/bRQ4+s7uYsUq19j7FG1 fODF9CJKovevWhmIH53hyABquHKmQO/XJZ2VL5sJgBqtrsoUh+1yzWd3b8EnraAVGh rjlpKKH0uOxlx2/93t2kGc6NWUo4YjAvZ0BXixKE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Robin Murphy , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Greg Hackmann , Ard Biesheuvel , Mark Rutland Subject: [PATCH 4.4 36/75] arm/arm64: smccc: Implement SMCCC v1.1 inline primitive Date: Fri, 8 Nov 2019 19:49:53 +0100 Message-Id: <20191108174745.026583460@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174708.135680837@linuxfoundation.org> References: <20191108174708.135680837@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit f2d3b2e8759a5833df6f022e42df2d581e6d843c upstream. One of the major improvement of SMCCC v1.1 is that it only clobbers the first 4 registers, both on 32 and 64bit. This means that it becomes very easy to provide an inline version of the SMC call primitive, and avoid performing a function call to stash the registers that would otherwise be clobbered by SMCCC v1.0. Reviewed-by: Robin Murphy Tested-by: Ard Biesheuvel Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Mark Rutland [v4.9 backport] Tested-by: Greg Hackmann Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- include/linux/arm-smccc.h | 141 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -123,5 +123,146 @@ asmlinkage void arm_smccc_hvc(unsigned l unsigned long a5, unsigned long a6, unsigned long a7, struct arm_smccc_res *res); +/* SMCCC v1.1 implementation madness follows */ +#ifdef CONFIG_ARM64 + +#define SMCCC_SMC_INST "smc #0" +#define SMCCC_HVC_INST "hvc #0" + +#elif defined(CONFIG_ARM) +#include +#include + +#define SMCCC_SMC_INST __SMC(0) +#define SMCCC_HVC_INST __HVC(0) + +#endif + +#define ___count_args(_0, _1, _2, _3, _4, _5, _6, _7, _8, x, ...) x + +#define __count_args(...) \ + ___count_args(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0) + +#define __constraint_write_0 \ + "+r" (r0), "=&r" (r1), "=&r" (r2), "=&r" (r3) +#define __constraint_write_1 \ + "+r" (r0), "+r" (r1), "=&r" (r2), "=&r" (r3) +#define __constraint_write_2 \ + "+r" (r0), "+r" (r1), "+r" (r2), "=&r" (r3) +#define __constraint_write_3 \ + "+r" (r0), "+r" (r1), "+r" (r2), "+r" (r3) +#define __constraint_write_4 __constraint_write_3 +#define __constraint_write_5 __constraint_write_4 +#define __constraint_write_6 __constraint_write_5 +#define __constraint_write_7 __constraint_write_6 + +#define __constraint_read_0 +#define __constraint_read_1 +#define __constraint_read_2 +#define __constraint_read_3 +#define __constraint_read_4 "r" (r4) +#define __constraint_read_5 __constraint_read_4, "r" (r5) +#define __constraint_read_6 __constraint_read_5, "r" (r6) +#define __constraint_read_7 __constraint_read_6, "r" (r7) + +#define __declare_arg_0(a0, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register unsigned long r1 asm("r1"); \ + register unsigned long r2 asm("r2"); \ + register unsigned long r3 asm("r3") + +#define __declare_arg_1(a0, a1, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register unsigned long r2 asm("r2"); \ + register unsigned long r3 asm("r3") + +#define __declare_arg_2(a0, a1, a2, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register typeof(a2) r2 asm("r2") = a2; \ + register unsigned long r3 asm("r3") + +#define __declare_arg_3(a0, a1, a2, a3, res) \ + struct arm_smccc_res *___res = res; \ + register u32 r0 asm("r0") = a0; \ + register typeof(a1) r1 asm("r1") = a1; \ + register typeof(a2) r2 asm("r2") = a2; \ + register typeof(a3) r3 asm("r3") = a3 + +#define __declare_arg_4(a0, a1, a2, a3, a4, res) \ + __declare_arg_3(a0, a1, a2, a3, res); \ + register typeof(a4) r4 asm("r4") = a4 + +#define __declare_arg_5(a0, a1, a2, a3, a4, a5, res) \ + __declare_arg_4(a0, a1, a2, a3, a4, res); \ + register typeof(a5) r5 asm("r5") = a5 + +#define __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res) \ + __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ + register typeof(a6) r6 asm("r6") = a6 + +#define __declare_arg_7(a0, a1, a2, a3, a4, a5, a6, a7, res) \ + __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ + register typeof(a7) r7 asm("r7") = a7 + +#define ___declare_args(count, ...) __declare_arg_ ## count(__VA_ARGS__) +#define __declare_args(count, ...) ___declare_args(count, __VA_ARGS__) + +#define ___constraints(count) \ + : __constraint_write_ ## count \ + : __constraint_read_ ## count \ + : "memory" +#define __constraints(count) ___constraints(count) + +/* + * We have an output list that is not necessarily used, and GCC feels + * entitled to optimise the whole sequence away. "volatile" is what + * makes it stick. + */ +#define __arm_smccc_1_1(inst, ...) \ + do { \ + __declare_args(__count_args(__VA_ARGS__), __VA_ARGS__); \ + asm volatile(inst "\n" \ + __constraints(__count_args(__VA_ARGS__))); \ + if (___res) \ + *___res = (typeof(*___res)){r0, r1, r2, r3}; \ + } while (0) + +/* + * arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call + * + * This is a variadic macro taking one to eight source arguments, and + * an optional return structure. + * + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 3 + * + * This macro is used to make SMC calls following SMC Calling Convention v1.1. + * The content of the supplied param are copied to registers 0 to 7 prior + * to the SMC instruction. The return values are updated with the content + * from register 0 to 3 on return from the SMC instruction if not NULL. + */ +#define arm_smccc_1_1_smc(...) __arm_smccc_1_1(SMCCC_SMC_INST, __VA_ARGS__) + +/* + * arm_smccc_1_1_hvc() - make an SMCCC v1.1 compliant HVC call + * + * This is a variadic macro taking one to eight source arguments, and + * an optional return structure. + * + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 3 + * + * This macro is used to make HVC calls following SMC Calling Convention v1.1. + * The content of the supplied param are copied to registers 0 to 7 prior + * to the HVC instruction. The return values are updated with the content + * from register 0 to 3 on return from the HVC instruction if not NULL. + */ +#define arm_smccc_1_1_hvc(...) __arm_smccc_1_1(SMCCC_HVC_INST, __VA_ARGS__) + #endif /*__ASSEMBLY__*/ #endif /*__LINUX_ARM_SMCCC_H*/ From patchwork Fri Nov 8 18:49:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 178932 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3123746ilf; Fri, 8 Nov 2019 10:54:08 -0800 (PST) X-Google-Smtp-Source: APXvYqyM90mSp6LuExsRFRUzSUOoIn5NrLFsoFqM2GKMp02WDGJM1A5elbgmvmq1a94KBSYbc++L X-Received: by 2002:a50:c408:: with SMTP id v8mr12048195edf.140.1573239248466; Fri, 08 Nov 2019 10:54:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573239248; cv=none; d=google.com; s=arc-20160816; b=jP2WICS2+lN0v8pJxpInrXu1NVXE0bPAOBwDgtXFUN2OGv/mXZO0dWZjoXtckzyzel tu7D/6LACgKEwSIpb+rBSTb7i4h3kwRHsAWJQPhzWKUCzfFjmlAl9QOMzAxtnpI3L8PY ozeCAdGkoEQD1/APrEOMWoJkoK5YAMALICTLsifIpb/F7y10kUT0DKEgWp/t8xs+7/5X zHKOzBGgZUn4PZwn5ES6g/legM90HG0vT3LgrBOIYqDTnbIyhZc9SHE6orgwzvWwRJC5 k/CykcQN3llj5Ydrj3bzpPJR5oz0w2l3pJ8X4+cM8VCPnIukNfgs492omXCjcKj4CJFg 7yTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=15L82Ggq27i5PPDzX6TCnbNPkLspZctQlAisSrnLIy8=; b=JE96iPhKgj3YaxXC8NgSbFO0IFE9tl6TnuVTPF4Qmpa6a+BMXtwfU9x5eaw3oROJnF br7HtKwiAtxLEeToRW8MgIbXWpCvB81jK+9dd07tQY4MeQZBMXhWOyBREzax6sNj2BgW EZVHl14CVNRhUlShaWRi4+JOUpBj27z1dThMA2lEbW1iOnhRv66lj8zQJdhd360gpS03 Yv2Wpc68XrfJQx4fa00RDJXzv9P+0lo1c9dPoG5Vi3VijAaqJqvCH3iiT3JElOOw3HXd yZkBUfF3q8l0GNfqNGgkE/AlzECY/xKPXwFLmcjESkSSixKVqVF0UAYKppYXsTiBZJmg CzTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Cbxcuntc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si5594037edc.1.2019.11.08.10.54.08; Fri, 08 Nov 2019 10:54:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Cbxcuntc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732695AbfKHSxy (ORCPT + 26 others); Fri, 8 Nov 2019 13:53:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:50720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732666AbfKHSxw (ORCPT ); Fri, 8 Nov 2019 13:53:52 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 58980222CF; Fri, 8 Nov 2019 18:53:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239231; bh=HoAwLUVebhRyUIJxWgNCYwzotcFZ2Jz19CSj3Fnu+us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CbxcuntcDh+Zvq2eIJizV3oW0dUZaU9oaXFBTVv8Wo6yf4wTR4/1gxKz3bR26TanS bjBV9XGOyfx83UHqcTk1dWArSkgTTfIrhcUGLIonMEf6oDKuYoESH2nX7sM4q/Meby +8RTcbMHEvCousGkL19sF66/0FjpriwFkuYUcxzk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Will Deacon , Mark Rutland , Marc Zyngier , Catalin Marinas , Ard Biesheuvel Subject: [PATCH 4.4 37/75] arm/arm64: smccc: Add SMCCC-specific return codes Date: Fri, 8 Nov 2019 19:49:54 +0100 Message-Id: <20191108174745.750485322@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174708.135680837@linuxfoundation.org> References: <20191108174708.135680837@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit eff0e9e1078ea7dc1d794dc50e31baef984c46d7 upstream. We've so far used the PSCI return codes for SMCCC because they were extremely similar. But with the new ARM DEN 0070A specification, "NOT_REQUIRED" (-2) is clashing with PSCI's "PSCI_RET_INVALID_PARAMS". Let's bite the bullet and add SMCCC specific return codes. Users can be repainted as and when required. Acked-by: Will Deacon Reviewed-by: Mark Rutland Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Marc Zyngier Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- include/linux/arm-smccc.h | 5 +++++ 1 file changed, 5 insertions(+) --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -264,5 +264,10 @@ asmlinkage void arm_smccc_hvc(unsigned l */ #define arm_smccc_1_1_hvc(...) __arm_smccc_1_1(SMCCC_HVC_INST, __VA_ARGS__) +/* Return codes defined in ARM DEN 0070A */ +#define SMCCC_RET_SUCCESS 0 +#define SMCCC_RET_NOT_SUPPORTED -1 +#define SMCCC_RET_NOT_REQUIRED -2 + #endif /*__ASSEMBLY__*/ #endif /*__LINUX_ARM_SMCCC_H*/ From patchwork Fri Nov 8 18:49:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 178934 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3124677ilf; Fri, 8 Nov 2019 10:55:05 -0800 (PST) X-Google-Smtp-Source: APXvYqwxx9MQKbE/QBFWazL0eO8/1GG/+0uvNBZmLCAyy8R6aOu4ER7IoFiH8PgV21mHlqP7X4Vt X-Received: by 2002:a17:906:af62:: with SMTP id os2mr10577333ejb.105.1573239305222; Fri, 08 Nov 2019 10:55:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573239305; cv=none; d=google.com; s=arc-20160816; b=cxF5sN56IpNBg/gxZE8kv1IyWVHz9J1rQVEeWW8WIojGB8RiDpICT9gdYIJoywdFw+ xiNVB6Oq4ELo7awX/hRj/m2Tfhd9WHMa5RIuQNG3ker+ju7VVm5YRy529Oxy/g5JaoNz 0Xvl/2/lGEW4mD+/xo2IAKxCjiQY/U/BxNXPccU8ln5euVrwQvnzIExUZdMHb5T8JPhD sJArJMxM+UqvNXChCnw311JPWEiXkWwzb1gDFSiM6blBAnIb4FhWTWTXdyJi+s2jQCVA xN4GbTl/AfLTHrmjxh+eK+KqSe6i11ipbP2sVpXyUIdtXDO2x1qLTFWtB0bF9J0ZjnmS sNLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gSBGVfQePv8UjeG0E2j0TAPNGtgonG74qB7cY5ZCHUg=; b=p23cVzrqoawgpLazS95tfuddRTz/zrWwWf9orS/jXj30mn0g/k5tl8f1I54epVa5ZR W/p3CnEBzqK4oLtjbW+1tzrw9WVMIQ2ubGDebtjKPhUO2xQl1bR6MFTJK7XLlb6+lGBa b+2/sA0NAky7kL3/ezUs9XGSjNyOGYVsJiPncTjmNtejM1nDB48WeTlYWIxa3yg+EnG2 m3zLSDy8fkhQiW5MCezgdaVoo7kWlZHsmjDDgGu7QqQWRl/9Dsj5VnSpLd4Rgwv1APRf Ya4U9BZ2wZ6oHyHpYUmuBtOSU6EhkVI8XE6dTf+ogcesoGy3HV52RNicsmNBOFDBbsXB lM0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TrH8nYf6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w20si5319462edc.397.2019.11.08.10.55.04; Fri, 08 Nov 2019 10:55:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TrH8nYf6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733207AbfKHSy7 (ORCPT + 26 others); Fri, 8 Nov 2019 13:54:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:52088 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733176AbfKHSy5 (ORCPT ); Fri, 8 Nov 2019 13:54:57 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 474AA20865; Fri, 8 Nov 2019 18:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239295; bh=XCmyTQ+12MfTtmsUotGI91wLqCMwUYde/6dmLNHaGFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TrH8nYf6MD9IarerlEVXM8MCJHfLxfnegni5pGkoW7TtD9KbWaeRSlIIcpehaNjdB ayk7JsbafxDzkpyxlPquhugnkScS7nPBCs6KGv5mhVACE71wTzQzlQWNzelFg56IQW CnKgrV7BTTCvWkEfAfxRtDkPxbzLL3fhuaJsK1RU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Julien Grall , Marc Zyngier , Will Deacon , Sasha Levin , Ard Biesheuvel Subject: [PATCH 4.4 39/75] arm/arm64: smccc-1.1: Handle function result as parameters Date: Fri, 8 Nov 2019 19:49:56 +0100 Message-Id: <20191108174747.367090509@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174708.135680837@linuxfoundation.org> References: <20191108174708.135680837@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier [ Upstream commit 755a8bf5579d22eb5636685c516d8dede799e27b ] If someone has the silly idea to write something along those lines: extern u64 foo(void); void bar(struct arm_smccc_res *res) { arm_smccc_1_1_smc(0xbad, foo(), res); } they are in for a surprise, as this gets compiled as: 0000000000000588 : 588: a9be7bfd stp x29, x30, [sp, #-32]! 58c: 910003fd mov x29, sp 590: f9000bf3 str x19, [sp, #16] 594: aa0003f3 mov x19, x0 598: aa1e03e0 mov x0, x30 59c: 94000000 bl 0 <_mcount> 5a0: 94000000 bl 0 5a4: aa0003e1 mov x1, x0 5a8: d4000003 smc #0x0 5ac: b4000073 cbz x19, 5b8 5b0: a9000660 stp x0, x1, [x19] 5b4: a9010e62 stp x2, x3, [x19, #16] 5b8: f9400bf3 ldr x19, [sp, #16] 5bc: a8c27bfd ldp x29, x30, [sp], #32 5c0: d65f03c0 ret 5c4: d503201f nop The call to foo "overwrites" the x0 register for the return value, and we end up calling the wrong secure service. A solution is to evaluate all the parameters before assigning anything to specific registers, leading to the expected result: 0000000000000588 : 588: a9be7bfd stp x29, x30, [sp, #-32]! 58c: 910003fd mov x29, sp 590: f9000bf3 str x19, [sp, #16] 594: aa0003f3 mov x19, x0 598: aa1e03e0 mov x0, x30 59c: 94000000 bl 0 <_mcount> 5a0: 94000000 bl 0 5a4: aa0003e1 mov x1, x0 5a8: d28175a0 mov x0, #0xbad 5ac: d4000003 smc #0x0 5b0: b4000073 cbz x19, 5bc 5b4: a9000660 stp x0, x1, [x19] 5b8: a9010e62 stp x2, x3, [x19, #16] 5bc: f9400bf3 ldr x19, [sp, #16] 5c0: a8c27bfd ldp x29, x30, [sp], #32 5c4: d65f03c0 ret Reported-by: Julien Grall Signed-off-by: Marc Zyngier Signed-off-by: Will Deacon Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- include/linux/arm-smccc.h | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -173,41 +173,51 @@ asmlinkage void arm_smccc_hvc(unsigned l register unsigned long r3 asm("r3") #define __declare_arg_1(a0, a1, res) \ + typeof(a1) __a1 = a1; \ struct arm_smccc_res *___res = res; \ register unsigned long r0 asm("r0") = (u32)a0; \ - register unsigned long r1 asm("r1") = a1; \ + register unsigned long r1 asm("r1") = __a1; \ register unsigned long r2 asm("r2"); \ register unsigned long r3 asm("r3") #define __declare_arg_2(a0, a1, a2, res) \ + typeof(a1) __a1 = a1; \ + typeof(a2) __a2 = a2; \ struct arm_smccc_res *___res = res; \ register unsigned long r0 asm("r0") = (u32)a0; \ - register unsigned long r1 asm("r1") = a1; \ - register unsigned long r2 asm("r2") = a2; \ + register unsigned long r1 asm("r1") = __a1; \ + register unsigned long r2 asm("r2") = __a2; \ register unsigned long r3 asm("r3") #define __declare_arg_3(a0, a1, a2, a3, res) \ + typeof(a1) __a1 = a1; \ + typeof(a2) __a2 = a2; \ + typeof(a3) __a3 = a3; \ struct arm_smccc_res *___res = res; \ register unsigned long r0 asm("r0") = (u32)a0; \ - register unsigned long r1 asm("r1") = a1; \ - register unsigned long r2 asm("r2") = a2; \ - register unsigned long r3 asm("r3") = a3 + register unsigned long r1 asm("r1") = __a1; \ + register unsigned long r2 asm("r2") = __a2; \ + register unsigned long r3 asm("r3") = __a3 #define __declare_arg_4(a0, a1, a2, a3, a4, res) \ + typeof(a4) __a4 = a4; \ __declare_arg_3(a0, a1, a2, a3, res); \ - register typeof(a4) r4 asm("r4") = a4 + register unsigned long r4 asm("r4") = __a4 #define __declare_arg_5(a0, a1, a2, a3, a4, a5, res) \ + typeof(a5) __a5 = a5; \ __declare_arg_4(a0, a1, a2, a3, a4, res); \ - register typeof(a5) r5 asm("r5") = a5 + register unsigned long r5 asm("r5") = __a5 #define __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res) \ + typeof(a6) __a6 = a6; \ __declare_arg_5(a0, a1, a2, a3, a4, a5, res); \ - register typeof(a6) r6 asm("r6") = a6 + register unsigned long r6 asm("r6") = __a6 #define __declare_arg_7(a0, a1, a2, a3, a4, a5, a6, a7, res) \ + typeof(a7) __a7 = a7; \ __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res); \ - register typeof(a7) r7 asm("r7") = a7 + register unsigned long r7 asm("r7") = __a7 #define ___declare_args(count, ...) __declare_arg_ ## count(__VA_ARGS__) #define __declare_args(count, ...) ___declare_args(count, __VA_ARGS__)