From patchwork Wed Oct 15 14:13:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 38783 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B423A20973 for ; Wed, 15 Oct 2014 14:15:07 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id hi2sf909115wib.9 for ; Wed, 15 Oct 2014 07:15:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:cc:subject :precedence:list-id:list-unsubscribe:list-post:list-help :list-subscribe:mime-version:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive :content-type:content-transfer-encoding; bh=fu0wr5D/voHO1Pqa69fwYrPHDk+Tz6FcyTcg3RslLAU=; b=FGTemcz6gqHt/+Vuh1zGFCe1thq50n1QNr3j40TWn+IBiZAvGLX6duiGNwkuy/JpE2 eJNIA6SbateRaUFDNZJFvbRpRXGIxVtjVBb394K/tEs/7FecZINs9wkegATOfqbQjti0 rJmG0oLhA/54/7RsxLrpcF5nepiqGakrMpMWvcKHDPxqW2iJnI/l8AmiSBSt23Jw6XWe nZXvsS9ex6X+UyZXTT3AkpGSQT27XfJypxlj9cEsTMdYIyYOOwMQZrWZgW9aRtV1YjLU xksLz/L4BkyRog7DPV3bkLdQdftEW7YxJma8ER2D+Co4r3c3LPIOIEtUkiHlHsDhz9bn 8eoQ== X-Gm-Message-State: ALoCoQlBUN7VR6YXu2lraOEFlPWpWBm432v+9raDyuKWWzbdFOvHnQrTLSj+ERSqP4YEE/2Wz7Rm X-Received: by 10.152.4.165 with SMTP id l5mr1774921lal.4.1413382506900; Wed, 15 Oct 2014 07:15:06 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.13 with SMTP id bc13ls67662lab.21.gmail; Wed, 15 Oct 2014 07:15:06 -0700 (PDT) X-Received: by 10.112.73.35 with SMTP id i3mr12605611lbv.75.1413382506754; Wed, 15 Oct 2014 07:15:06 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com [209.85.215.49]) by mx.google.com with ESMTPS id t18si30666282laz.81.2014.10.15.07.15.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Oct 2014 07:15:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id q1so1119384lam.8 for ; Wed, 15 Oct 2014 07:15:06 -0700 (PDT) X-Received: by 10.112.130.41 with SMTP id ob9mr12408821lbb.74.1413382506521; Wed, 15 Oct 2014 07:15:06 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp605446lbz; Wed, 15 Oct 2014 07:15:05 -0700 (PDT) X-Received: by 10.140.35.85 with SMTP id m79mr18927087qgm.81.1413382504754; Wed, 15 Oct 2014 07:15:04 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id j10si34985829qao.105.2014.10.15.07.15.04 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 15 Oct 2014 07:15:04 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XePKO-0002FG-FJ; Wed, 15 Oct 2014 14:13:24 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XePKM-0002FB-I9 for xen-devel@lists.xenproject.org; Wed, 15 Oct 2014 14:13:22 +0000 Received: from [85.158.143.35] by server-2.bemta-4.messagelabs.com id 92/A0-10419-1018E345; Wed, 15 Oct 2014 14:13:21 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-7.tower-21.messagelabs.com!1413382401!13140495!1 X-Originating-IP: [74.125.82.44] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.12.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31916 invoked from network); 15 Oct 2014 14:13:21 -0000 Received: from mail-wg0-f44.google.com (HELO mail-wg0-f44.google.com) (74.125.82.44) by server-7.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 15 Oct 2014 14:13:21 -0000 Received: by mail-wg0-f44.google.com with SMTP id y10so1460618wgg.15 for ; Wed, 15 Oct 2014 07:13:20 -0700 (PDT) X-Received: by 10.180.207.72 with SMTP id lu8mr12477963wic.2.1413382400726; Wed, 15 Oct 2014 07:13:20 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id ew4sm11201760wid.19.2014.10.15.07.13.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Oct 2014 07:13:20 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 15 Oct 2014 15:13:12 +0100 Message-Id: <1413382392-27897-1-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 Cc: ian.campbell@citrix.com, Julien Grall , tim@xen.org, stefano.stabellini@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v4 for 4.5] arm32: fix build after 063188f4b3 X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: "xen: arm: Add support for the Exynos secure firmware" introduced code assuming that exynos_smc() would get called with arguments in certain registers. While the "noinline" attribute guarantees the function to not get inlined, it does not guarantee that all arguments arrive in the assumed registers: gcc's interprocedural analysis can result in clone functions to be created where some of the incoming arguments (commonly when they have constant values) get replaced by putting in place the respective values inside the clone. Xen contains in multiple place of this SMC function: consolidate the function in a single place and write it in assembly. Signed-off-by: Julien Grall Reported-by: Jan Beulich --- This is a fix for Xen 4.5 to compile the hypervisor with GCC 4.9.1, used by Fedora & co. Changes in v4: - Drop helper for different number of arguments - Drop the stay do_smc prototype Changes in v3: - Introduce macros assembly helper - Consolidate the SMC code in a single assembly file - Rename do_scm into call_smc and create helper for different number of argument - Rebase on top of PSCI v0.2 host support Changes in v2: - Write the SMC call in assembly - Consolidate the code in a single place --- xen/arch/arm/Makefile | 1 + xen/arch/arm/platforms/exynos5.c | 15 +-------------- xen/arch/arm/platforms/seattle.c | 12 ++---------- xen/arch/arm/psci.c | 34 ++++------------------------------ xen/arch/arm/smc.S | 21 +++++++++++++++++++++ xen/include/asm-arm/arm32/macros.h | 8 ++++++++ xen/include/asm-arm/macros.h | 16 ++++++++++++++++ xen/include/asm-arm/processor.h | 3 +++ 8 files changed, 56 insertions(+), 54 deletions(-) create mode 100644 xen/arch/arm/smc.S create mode 100644 xen/include/asm-arm/arm32/macros.h create mode 100644 xen/include/asm-arm/macros.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 9a25290..41aba2e 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -37,6 +37,7 @@ obj-y += hvm.o obj-y += device.o obj-y += decode.o obj-y += processor.o +obj-y += smc.o #obj-bin-y += ....o diff --git a/xen/arch/arm/platforms/exynos5.c b/xen/arch/arm/platforms/exynos5.c index ac556cb..79e3a5f 100644 --- a/xen/arch/arm/platforms/exynos5.c +++ b/xen/arch/arm/platforms/exynos5.c @@ -37,19 +37,6 @@ static bool_t secure_firmware; #define SMC_CMD_CPU1BOOT (-4) -static noinline void exynos_smc(register_t function_id, register_t arg0, - register_t arg1, register_t arg2) -{ - asm volatile( - __asmeq("%0", "r0") - __asmeq("%1", "r1") - __asmeq("%2", "r2") - __asmeq("%3", "r3") - "smc #0" - : - : "r" (function_id), "r" (arg0), "r" (arg1), "r" (arg2)); -} - static int exynos5_init_time(void) { uint32_t reg; @@ -263,7 +250,7 @@ static int exynos5_cpu_up(int cpu) iounmap(power); if ( secure_firmware ) - exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0); + call_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0); return cpu_up_send_sgi(cpu); } diff --git a/xen/arch/arm/platforms/seattle.c b/xen/arch/arm/platforms/seattle.c index edfc391..6cc5362 100644 --- a/xen/arch/arm/platforms/seattle.c +++ b/xen/arch/arm/platforms/seattle.c @@ -31,22 +31,14 @@ static const char * const seattle_dt_compat[] __initconst = * This is temporary until full PSCI-0.2 is supported. * Then, these function will be removed. */ -static noinline void seattle_smc_psci(register_t func_id) -{ - asm volatile( - "smc #0" - : "+r" (func_id) - :); -} - static void seattle_system_reset(void) { - seattle_smc_psci(PSCI_0_2_FN_SYSTEM_RESET); + call_smc(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0); } static void seattle_system_off(void) { - seattle_smc_psci(PSCI_0_2_FN_SYSTEM_OFF); + call_smc(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0); } PLATFORM_START(seattle, "SEATTLE") diff --git a/xen/arch/arm/psci.c b/xen/arch/arm/psci.c index 604ff4c..4066309 100644 --- a/xen/arch/arm/psci.c +++ b/xen/arch/arm/psci.c @@ -25,49 +25,23 @@ uint32_t psci_ver; -#ifdef CONFIG_ARM_32 -#define REG_PREFIX "r" -#else -#define REG_PREFIX "x" -#endif - -static noinline int __invoke_psci_fn_smc(register_t function_id, - register_t arg0, - register_t arg1, - register_t arg2) -{ - asm volatile( - __asmeq("%0", REG_PREFIX"0") - __asmeq("%1", REG_PREFIX"1") - __asmeq("%2", REG_PREFIX"2") - __asmeq("%3", REG_PREFIX"3") - "smc #0" - : "+r" (function_id) - : "r" (arg0), "r" (arg1), "r" (arg2)); - - return function_id; -} - -#undef REG_PREFIX - static uint32_t psci_cpu_on_nr; int call_psci_cpu_on(int cpu) { - return __invoke_psci_fn_smc(psci_cpu_on_nr, - cpu_logical_map(cpu), __pa(init_secondary), 0); + return call_smc(psci_cpu_on_nr, cpu_logical_map(cpu), __pa(init_secondary), 0); } void call_psci_system_off(void) { if ( psci_ver > XEN_PSCI_V_0_1 ) - __invoke_psci_fn_smc(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0); + call_smc(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0); } void call_psci_system_reset(void) { if ( psci_ver > XEN_PSCI_V_0_1 ) - __invoke_psci_fn_smc(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0); + call_smc(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0); } int __init psci_is_smc_method(const struct dt_device_node *psci) @@ -134,7 +108,7 @@ int __init psci_init_0_2(void) if ( ret ) return -EINVAL; - psci_ver = __invoke_psci_fn_smc(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0); + psci_ver = call_smc(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0); if ( psci_ver != XEN_PSCI_V_0_2 ) { diff --git a/xen/arch/arm/smc.S b/xen/arch/arm/smc.S new file mode 100644 index 0000000..b8f1822 --- /dev/null +++ b/xen/arch/arm/smc.S @@ -0,0 +1,21 @@ +/* + * xen/arch/arm/smc.S + * + * Wrapper for Secure Monitors Calls + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + +ENTRY(call_smc) + smc #0 + ret diff --git a/xen/include/asm-arm/arm32/macros.h b/xen/include/asm-arm/arm32/macros.h new file mode 100644 index 0000000..a4e20aa --- /dev/null +++ b/xen/include/asm-arm/arm32/macros.h @@ -0,0 +1,8 @@ +#ifndef __ASM_ARM_ARM32_MACROS_H +#define __ASM_ARM_ARM32_MACROS_H + + .macro ret + mov pc, lr + .endm + +#endif /* __ASM_ARM_ARM32_MACROS_H */ diff --git a/xen/include/asm-arm/macros.h b/xen/include/asm-arm/macros.h new file mode 100644 index 0000000..f92f905 --- /dev/null +++ b/xen/include/asm-arm/macros.h @@ -0,0 +1,16 @@ +#ifndef __ASM_MACROS_H +#define __ASM_MACROS_H + +#ifndef __ASSEMBLY__ +# error "This file should only be included in assembly file" +#endif + +#if defined (CONFIG_ARM_32) +# include +#elif defined(CONFIG_ARM_64) +/* Not specific ARM64 macros for now */ +#else +# error "unknown ARM variant" +#endif + +#endif /* __ASM_ARM_MACROS_H */ diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h index e719c26..b7ef817 100644 --- a/xen/include/asm-arm/processor.h +++ b/xen/include/asm-arm/processor.h @@ -614,6 +614,9 @@ void vcpu_regs_hyp_to_user(const struct vcpu *vcpu, void vcpu_regs_user_to_hyp(struct vcpu *vcpu, const struct vcpu_guest_core_regs *regs); +int call_smc(register_t function_id, register_t arg0, register_t arg1, + register_t arg2); + #endif /* __ASSEMBLY__ */ #endif /* __ASM_ARM_PROCESSOR_H */ /*