From patchwork Tue Oct 10 15:52:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9996665 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 68D2360216 for ; Tue, 10 Oct 2017 16:00:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4161E2866F for ; Tue, 10 Oct 2017 16:00:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26BE228698; Tue, 10 Oct 2017 16:00:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1EDCC28696 for ; Tue, 10 Oct 2017 16:00:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e1wuY-0003TT-Nv; Tue, 10 Oct 2017 15:57:38 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e1wuX-0003T1-Ky for xen-devel@lists.xen.org; Tue, 10 Oct 2017 15:57:37 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id 9F/14-07499-0FDECD95; Tue, 10 Oct 2017 15:57:36 +0000 X-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volodymyr_Babchuk@epam.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1507651054!68539642!1 X-Originating-IP: [40.107.2.82] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5296 invoked from network); 10 Oct 2017 15:57:34 -0000 Received: from mail-eopbgr20082.outbound.protection.outlook.com (HELO EUR02-VE1-obe.outbound.protection.outlook.com) (40.107.2.82) by server-5.tower-21.messagelabs.com with AES256-SHA256 encrypted SMTP; 10 Oct 2017 15:57:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=EPAM.onmicrosoft.com; s=selector1-epam-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=c6IRox0KDvafOILngAQMt83HLKbOBZ365zwUuGOdyRY=; b=Y7ktkggMMNtr8IaCmPj355BpB+n2bzSw6fqEWoaUoE+p34d04RNk/lYjn6SM+daIPf29NCI7WyqVdPHlaiSQ1Z/2BsMzlhkvS176YizXxBYFGHwxd/Dk7wjhLu4ZwzlQXimjyuC/54UyAayxk5oU7HLc0zuzz3LpTFs0LfBbcvw= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.56) by VI1PR0301MB2142.eurprd03.prod.outlook.com (2603:10a6:800:26::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Tue, 10 Oct 2017 15:57:30 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Tue, 10 Oct 2017 18:57:26 +0300 From: Volodymyr Babchuk To: xen-devel@lists.xen.org Date: Tue, 10 Oct 2017 18:52:47 +0300 Message-Id: <1507650771-16631-8-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507650771-16631-1-git-send-email-volodymyr_babchuk@epam.com> References: <1507650771-16631-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.56] X-ClientProxiedBy: DB6PR1001CA0043.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:55::29) To VI1PR0301MB2142.eurprd03.prod.outlook.com (2603:10a6:800:26::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd5bcfb5-91f0-4262-3b20-08d50ff79d98 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:VI1PR0301MB2142; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0301MB2142; 3:UfzZ3ALfHpNniiC+ZmdeK6tD4xRapRv9wYZJMf6I1770r+Sg5pmUEJudsU4hnEWV36JG8D3pvPNnfRW3Tg8xJyuixL+2bc/Afoocqig2ZUBj+IDoc4p+ytgQk18C03u1mJWdEbaUDDPjzPKczWeEJiWAfbSDXpjIIGagvp8eV0eY4mfapJ3vSiXm/MvqIgxeiq3VJz8vQWCYt9GJpb9j615wKcEwx0UUZbbunpZc73AJ91x9fIqdkGpMMU7G7iSb; 25:cDEpIJrsdkexWjBfWH67R4VuAX+ban+u1LK5nUHwlebkxaXg83mq6X6u1T/zi0jv7w5Py3CqbRtHRCVli5yOdsUOEP1yL12I8wO0D0Du8ifMdonwAugSfYFYfApnJuvKGQAC8S7N7S6IqTq22Ruy71VP9+7Oq23/+JvDeb8hk1AD9Gv2tnQ4TXKCl/Dy891RbodRzJ4gAKfkVb1RevUK0ZQfC4O6j1UJ4oTjfVyG76/1Jp3ovVfR7SvMk+rUMnW+uY3H4wHIeYOhKj4jm+TOfTPpEug21IWceIfZDI/7QM7wgYwXOMrnRlbkH8XYrBM7RVeFdEDOh8tQO0rAYAmbsA==; 31:7BEaoR5sd1bgu9Zt1Df2JF7ab4wCBy/bMFWT/mPAj/KnyzecH6aovBorN6E/omRbKJFcM05LlLweu34PZOC4RZqQp/unCONgHx0PLlH2aiukvkN8LlC+Hn+s2S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864354917)(4114951738403); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(20161123558100)(20161123564025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR0301MB2142; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR0301MB2142; X-Forefront-PRVS: 04569283F9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(346002)(199003)(189002)(33646002)(105586002)(2361001)(47776003)(4326008)(7416002)(50986999)(5003940100001)(76176999)(50226002)(305945005)(8656003)(7736002)(8666007)(5660300001)(478600001)(101416001)(8676002)(42186006)(16586007)(122856001)(53936002)(54906003)(36756003)(68736007)(189998001)(97736004)(50466002)(81156014)(81166006)(106356001)(80792005)(6116002)(316002)(2906002)(86362001)(3846002)(6666003)(2950100002)(72206003)(48376002)(6916009)(8936002)(66066001)(2351001)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0301MB2142; H:EPUAKYIW2556.kyiv.epam.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: epam.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0301MB2142; 23:4I2gpq6Qb13BQac46/9DRdOGsYaTx56GC9FNlEx?= =?us-ascii?Q?mKwhIkqYGbjFIvS7f5pRtNYvUu0ExR+KZzY8JFHlIUA0IQkmKVphJXjwAhc8?= =?us-ascii?Q?2Eukvsay2Vjm+VMIb4A9odUsCaymkiN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9p6Zkr7mU+Z8U2jNzNrBR/2dtq2hWMVQ6Caq0szYg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2017 15:57:30.5162 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0301MB2142 Cc: "Edgar E . Iglesias" , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Volodymyr Babchuk Subject: [Xen-devel] [PATCH v8 07/11] arm: smccc: handle SMCs according to SMCCC X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP SMCCC (SMC Call Convention) describes how to handle both HVCs and SMCs. SMCCC states that both HVC and SMC are valid conduits to call to different firmware functions. Thus, for example, PSCI calls can be made both by SMC or HVC. Also SMCCC defines function number coding for such calls. Besides functional calls there are query calls, which allows underling OS determine version, UUID and number of functions provided by service provider. This patch adds new file `vsmc.c`, which handles both generic SMCs and HVC according to SMCCC. At this moment it implements only one service: Standard Hypervisor Service. At this time Standard Hypervisor Service only supports query calls, so caller can ask about hypervisor UID and determine that it is XEN running. This change allows more generic handling for SMCs and HVCs and it can be easily extended to support new services and functions. But, before SMC is forwarded to standard SMCCC handler, it can be routed to a domain monitor, if one is installed. Signed-off-by: Volodymyr Babchuk Reviewed-by: Oleksandr Andrushchenko Reviewed-by: Oleksandr Tyshchenko Acked-by: Julien Grall --- xen/arch/arm/Makefile | 1 + xen/arch/arm/traps.c | 17 ---- xen/arch/arm/vsmc.c | 191 ++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/traps.h | 3 + xen/include/public/arch-arm/smccc.h | 58 +++++++++++ 5 files changed, 253 insertions(+), 17 deletions(-) create mode 100644 xen/arch/arm/vsmc.c create mode 100644 xen/include/public/arch-arm/smccc.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 424580b..30a2a65 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_HAS_ITS) += vgic-v3-its.o obj-y += vm_event.o obj-y += vtimer.o obj-$(CONFIG_SBSA_VUART_CONSOLE) += vpl011.o +obj-y += vsmc.o obj-y += vpsci.o obj-y += vuart.o diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 5b91e6c..6ea0090 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -2195,23 +2195,6 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, inject_dabt_exception(regs, info.gva, hsr.len); } -static void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr) -{ - int rc = 0; - - if ( !check_conditional_instr(regs, hsr) ) - { - advance_pc(regs, hsr); - return; - } - - if ( current->domain->arch.monitor.privileged_call_enabled ) - rc = monitor_smc(); - - if ( rc != 1 ) - inject_undef_exception(regs, hsr); -} - static void enter_hypervisor_head(struct cpu_user_regs *regs) { if ( guest_mode(regs) ) diff --git a/xen/arch/arm/vsmc.c b/xen/arch/arm/vsmc.c new file mode 100644 index 0000000..38df821 --- /dev/null +++ b/xen/arch/arm/vsmc.c @@ -0,0 +1,191 @@ +/* + * xen/arch/arm/vsmc.c + * + * Generic handler for SMC and HVC calls according to + * ARM SMC calling convention + * + * 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 +#include +#include +#include +#include +#include + +/* Number of functions currently supported by Hypervisor Service. */ +#define XEN_SMCCC_FUNCTION_COUNT 3 + +static bool fill_uid(struct cpu_user_regs *regs, xen_uuid_t uuid) +{ + int n; + + /* + * UID is returned in registers r0..r3, four bytes per register, + * first byte is stored in low-order bits of a register. + * (ARM DEN 0028B page 14) + */ + for (n = 0; n < 4; n++) + { + const uint8_t *bytes = uuid.a + n * 4; + uint32_t r; + + r = bytes[0]; + r |= bytes[1] << 8; + r |= bytes[2] << 16; + r |= bytes[3] << 24; + + set_user_reg(regs, n, r); + } + + return true; +} + +static bool fill_revision(struct cpu_user_regs *regs, uint32_t major, + uint32_t minor) +{ + /* + * Revision is returned in registers r0 and r1. + * r0 stores major part of the version + * r1 stores minor part of the version + * (ARM DEN 0028B page 15) + */ + set_user_reg(regs, 0, major); + set_user_reg(regs, 1, minor); + + return true; +} + +static bool fill_function_call_count(struct cpu_user_regs *regs, uint32_t cnt) +{ + /* + * Function call count is retuned as any other return value in register r0 + * (ARM DEN 0028B page 17) + */ + set_user_reg(regs, 0, cnt); + + return true; +} + +/* SMCCC interface for hypervisor. Tell about itself. */ +static bool handle_hypervisor(struct cpu_user_regs *regs) +{ + switch ( smccc_get_fn(get_user_reg(regs, 0)) ) + { + case ARM_SMCCC_FUNC_CALL_COUNT: + return fill_function_call_count(regs, XEN_SMCCC_FUNCTION_COUNT); + case ARM_SMCCC_FUNC_CALL_UID: + return fill_uid(regs, XEN_SMCCC_UID); + case ARM_SMCCC_FUNC_CALL_REVISION: + return fill_revision(regs, XEN_SMCCC_MAJOR_REVISION, + XEN_SMCCC_MINOR_REVISION); + default: + return false; + } +} + +/* + * vsmccc_handle_call() - handle SMC/HVC call according to ARM SMCCC. + * returns true if that was valid SMCCC call (even if function number + * was unknown). + */ +static bool vsmccc_handle_call(struct cpu_user_regs *regs) +{ + bool handled = false; + const union hsr hsr = { .bits = regs->hsr }; + register_t funcid = get_user_reg(regs, 0); + + /* + * Check immediate value for HVC32, HVC64 and SMC64. + * It is not so easy to check immediate value for SMC32, + * because it is not stored in HSR.ISS field. To get immediate + * value we need to disassemble instruction at current pc, which + * is expensive. So we will assume that it is 0x0. + */ + switch ( hsr.ec ) + { + case HSR_EC_HVC32: + case HSR_EC_HVC64: + case HSR_EC_SMC64: + if ( (hsr.iss & HSR_XXC_IMM_MASK) != 0) + return false; + break; + case HSR_EC_SMC32: + break; + default: + return false; + } + + /* 64 bit calls are allowed only from 64 bit domains. */ + if ( smccc_is_conv_64(funcid) && is_32bit_domain(current->domain) ) + { + set_user_reg(regs, 0, ARM_SMCCC_ERR_UNKNOWN_FUNCTION); + return true; + } + + switch ( smccc_get_owner(funcid) ) + { + case ARM_SMCCC_OWNER_HYPERVISOR: + handled = handle_hypervisor(regs); + break; + } + + if ( !handled ) + { + gprintk(XENLOG_INFO, "Unhandled SMC/HVC: %08"PRIregister"\n", funcid); + + /* Inform caller that function is not supported. */ + set_user_reg(regs, 0, ARM_SMCCC_ERR_UNKNOWN_FUNCTION); + } + + return true; +} + +void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr) +{ + int rc = 0; + + if ( !check_conditional_instr(regs, hsr) ) + { + advance_pc(regs, hsr); + return; + } + + /* If monitor is enabled, let it handle the call. */ + if ( current->domain->arch.monitor.privileged_call_enabled ) + rc = monitor_smc(); + + if ( rc == 1 ) + return; + + /* + * Use standard routines to handle the call. + * vsmccc_handle_call() will return false if this call is not + * SMCCC compatible (e.g. immediate value != 0). As it is not + * compatible, we can't be sure that guest will understand + * ARM_SMCCC_ERR_UNKNOWN_FUNCTION. + */ + if ( vsmccc_handle_call(regs) ) + advance_pc(regs, hsr); + else + inject_undef_exception(regs, hsr); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-arm/traps.h b/xen/include/asm-arm/traps.h index 7508af8..325c15f 100644 --- a/xen/include/asm-arm/traps.h +++ b/xen/include/asm-arm/traps.h @@ -35,6 +35,9 @@ void do_cp14_64(struct cpu_user_regs *regs, const union hsr hsr); void do_cp14_dbg(struct cpu_user_regs *regs, const union hsr hsr); void do_cp(struct cpu_user_regs *regs, const union hsr hsr); +/* SMCCC handling */ +void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr); + #endif /* __ASM_ARM_TRAPS__ */ /* * Local variables: diff --git a/xen/include/public/arch-arm/smccc.h b/xen/include/public/arch-arm/smccc.h new file mode 100644 index 0000000..2bee5b3 --- /dev/null +++ b/xen/include/public/arch-arm/smccc.h @@ -0,0 +1,58 @@ +/* + * smccc.h + * + * SMC/HVC interface in accordance with SMC Calling Convention. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Copyright 2017 (C) EPAM Systems + */ + +#ifndef __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ +#define __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ + +#include "public/xen.h" + +/* + * Hypervisor Service version. + * + * We can't use XEN version here, because of SMCCC requirements: + * Major revision should change every time SMC/HVC function is removed. + * Minor revision should change every time SMC/HVC function is added. + * So, it is SMCCC protocol revision code, not XEN version. + * + * Those values are subjected to change, when interface will be extended. + */ +#define XEN_SMCCC_MAJOR_REVISION 0 +#define XEN_SMCCC_MINOR_REVISION 1 + +/* Hypervisor Service UID. Randomly generated with uuidgen. */ +#define XEN_SMCCC_UID XEN_DEFINE_UUID(0xa71812dc, 0xc698, 0x4369, 0x9acf, \ + 0x79, 0xd1, 0x8d, 0xde, 0xe6, 0x67) + +#endif /* __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End:b + */