From patchwork Mon Aug 21 20:27:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9913699 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 32E92602A0 for ; Mon, 21 Aug 2017 20:31:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2574328809 for ; Mon, 21 Aug 2017 20:31:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1061F28800; Mon, 21 Aug 2017 20:31:31 +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 9CDA9287F4 for ; Mon, 21 Aug 2017 20:31:29 +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 1djtK6-0003tF-Hv; Mon, 21 Aug 2017 20:29:22 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1djtK5-0003sT-2H for xen-devel@lists.xen.org; Mon, 21 Aug 2017 20:29:21 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id 0B/C0-03406-0A24B995; Mon, 21 Aug 2017 20:29:20 +0000 X-Br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Msg-Ref: server-16.tower-27.messagelabs.com!1503347358!112454574!1 X-Originating-IP: [104.47.1.42] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 37900 invoked from network); 21 Aug 2017 20:29:18 -0000 Received: from mail-ve1eur01on0042.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (104.47.1.42) by server-16.tower-27.messagelabs.com with AES256-SHA256 encrypted SMTP; 21 Aug 2017 20:29:18 -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=HKR/e0CeottULvysdPVJ/m/IgmQlJUXT5lzD/vhPb+Y=; b=LQFUspRhY2J1cbIdTrwiaXEg7gTu1FOUL01un9UnaB/+GO/KLWrPzUtx235jRjroPzuXdNQQDM9VmfJt7jG4sBq1WiAWgXmDCn79W6JWPglyF4jFWue0QgSp1oJ+bZ9MqmRerOy7E5trOp5qpQZ+zuW8vbfaJgylHE0cUmMS5Zs= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.58) by HE1PR0301MB2139.eurprd03.prod.outlook.com (2603:10a6:3:21::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1362.18; Mon, 21 Aug 2017 20:29:15 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Mon, 21 Aug 2017 23:29:11 +0300 From: Volodymyr Babchuk To: xen-devel@lists.xen.org Date: Mon, 21 Aug 2017 23:27:50 +0300 Message-Id: <1503347275-13039-7-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503347275-13039-1-git-send-email-volodymyr_babchuk@epam.com> References: <1503347275-13039-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.58] X-ClientProxiedBy: AM4PR05CA0024.eurprd05.prod.outlook.com (2603:10a6:205::37) To HE1PR0301MB2139.eurprd03.prod.outlook.com (2603:10a6:3:21::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4e4d4057-37df-4c14-9ba9-08d4e8d34b06 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:HE1PR0301MB2139; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0301MB2139; 3:KUqJ5ARVJBq68I39+XBqm0oUSR86Xizj4QPFarRx9Cs1tJ4J+QaaptPdbiVdALi43ovnxmlSMpeWfyFOgIRTFRT/5qUafdPutRVkQ4RKVFS3ZOJIWR3szBMoXFOGrHkrrBPdZGUiEU8Acd/cGl0xA2+5yIKTyoFod/xdBlvIkuoAgLjZbp6IFvri16Q0rbyLyjKEUOIgKWBthtYVlbVmXVdfqneHcPOcA5DJh0uCjYbBkmSXH9bgjoweFs7U32N8; 25:P9DAAYCVwC21AyNeScnYTVIxpY5yT+ic3vs4ftx73s3Gysa/HHKkLYxm1cC+ByF5MoBTuYCmKWvxbYKQy0xSRZcXvcRV6iTmguI0ZsoEV3ESUsOVgji78cVy0/le7plFDFFVIeVY+bb5wxZ9lgRYS3asArmWe1HEz1pz455BbB7zpXEpD0JhtYi9wOk1V4zhLbZC05oOqxIScjtmVFR8XOpHNEzT6heWsWCMoDv1qpTlZXCEGECS/ggHzfd1QGxC9GrjyWwTvGmDCv5tefOlgI0n8DPGESdCtmiZtJ/24bD7++uXDQf8qMNlKwFcqRoOTgax+jFT6xzE00YF6ZHSDw==; 31:q0IEqEDIZJVd+ITySeu8VEQJH3IgolazOcXS5ziWi7ZJTvnPFxIL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XaSm8= X-Exchange-Antispam-Report-Test: UriScan:(4114951738403); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(6041248)(20161123555025)(20161123564025)(20161123562025)(20161123560025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:HE1PR0301MB2139; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:HE1PR0301MB2139; X-Forefront-PRVS: 040655413E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6009001)(199003)(189002)(72206003)(2906002)(2950100002)(42186005)(5003940100001)(54906002)(6916009)(8666007)(50226002)(101416001)(105586002)(2361001)(53936002)(122856001)(106356001)(76176999)(97736004)(2351001)(50986999)(5660300001)(33646002)(68736007)(48376002)(110136004)(478600001)(7350300001)(8656003)(86362001)(36756003)(47776003)(6116002)(3846002)(66066001)(81156014)(305945005)(107886003)(80792005)(8676002)(189998001)(50466002)(4326008)(6666003)(81166006)(7736002)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0301MB2139; 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; HE1PR0301MB2139; 23:OrJzXMDWXHXAg5HiLCrH8Tf82i1gv+RpiYpMRJN?= =?us-ascii?Q?k3yaf+551IIo2wnXvXBjaqzgPn2R9CoK3kcSJk2Ga3LSFnn0sjhJr78falqp?= =?us-ascii?Q?o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luO7W8yX8AByw8yTK1Y1V6J0Xi0Z3nv8W3a7OXW8RIg+jDdsGhrBJvgKz0sMVB+mjWGT1fVprvv+phrbkPk4KQ/MY4AoxknUPC2EdbZkM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2017 20:29:15.4769 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0301MB2139 Cc: "Edgar E . Iglesias" , Julien Grall , Stefano Stabellini , Volodymyr Babchuk Subject: [Xen-devel] [PATCH v4 06/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 --- * Reworked UUID handling (due to new UUID type definition) * Renamed vsmc_handle_call() to vsmccc_handle_call() to emphasis that it handles both SMC and HVC * Added comment for inject_undef_exception() usage * Used HSR_XXC_IMM_MASK insted of 0xFF * Added full stops to comments --- xen/arch/arm/Makefile | 1 + xen/arch/arm/traps.c | 18 +---- xen/arch/arm/vsmc.c | 160 ++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/vsmc.h | 30 +++++++ xen/include/public/arch-arm/smc.h | 58 ++++++++++++++ 5 files changed, 250 insertions(+), 17 deletions(-) create mode 100644 xen/arch/arm/vsmc.c create mode 100644 xen/include/asm-arm/vsmc.h create mode 100644 xen/include/public/arch-arm/smc.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index de00c5e..3d7dde9 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_HAS_GICV3) += vgic-v3.o obj-$(CONFIG_HAS_ITS) += vgic-v3-its.o obj-y += vm_event.o obj-y += vtimer.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 82cd2b1..4141a89 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include "decode.h" @@ -2155,23 +2156,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..0a81294 --- /dev/null +++ b/xen/arch/arm/vsmc.c @@ -0,0 +1,160 @@ +/* + * 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 +#include + +/* Number of functions currently supported by Hypervisor Service. */ +#define XEN_SMCCC_FUNCTION_COUNT 3 + +static void fill_uuid(struct cpu_user_regs *regs, const xen_uuid_t u) +{ +#define FILL_UUID(n) \ + set_user_reg(regs, n, (register_t) u[n * 4 + 0] << 24 | \ + u[n * 4 + 1] << 16 | \ + u[n * 4 + 2] << 8 | \ + u[n * 4 + 3] << 0 ) + + FILL_UUID(0); + FILL_UUID(1); + FILL_UUID(2); + FILL_UUID(3); +#undef FILL_UUID +} + +/* SMCCC interface for hypervisor. Tell about itself. */ +static bool handle_hypervisor(struct cpu_user_regs *regs) +{ + static const xen_uuid_t xen_uuid = XEN_SMCCC_UID; + switch ( ARM_SMCCC_FUNC_NUM(get_user_reg(regs, 0)) ) + { + case ARM_SMCCC_FUNC_CALL_COUNT: + set_user_reg(regs, 0, XEN_SMCCC_FUNCTION_COUNT); + return true; + case ARM_SMCCC_FUNC_CALL_UID: + fill_uuid(regs, xen_uuid); + return true; + case ARM_SMCCC_FUNC_CALL_REVISION: + set_user_reg(regs, 0, XEN_SMCCC_MAJOR_REVISION); + set_user_reg(regs, 1, XEN_SMCCC_MINOR_REVISION); + return true; + } + 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 unkown). + */ +static bool vsmccc_handle_call(struct cpu_user_regs *regs) +{ + bool handled = false; + const union hsr hsr = { .bits = regs->hsr }; + + /* + * 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 ( ARM_SMCCC_IS_64(get_user_reg(regs, 0)) && + is_32bit_domain(current->domain) ) + { + set_user_reg(regs, 0, ARM_SMCCC_ERR_UNKNOWN_FUNCTION); + return true; + } + + switch ( ARM_SMCCC_OWNER_NUM(get_user_reg(regs, 0)) ) + { + case ARM_SMCCC_OWNER_HYPERVISOR: + handled = handle_hypervisor(regs); + break; + } + + if ( !handled ) + { + gprintk(XENLOG_INFO, "Unhandled SMC/HVC: %08"PRIregister"\n", + get_user_reg(regs, 0)); + /* Inform caller that function is not supported. */ + set_user_reg(regs, 0, ARM_SMCCC_ERR_UNKNOWN_FUNCTION); + } + + return true; +} + +/* This function will be called from traps.c. */ +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 compatbile (i.e. 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/vsmc.h b/xen/include/asm-arm/vsmc.h new file mode 100644 index 0000000..31aaa55 --- /dev/null +++ b/xen/include/asm-arm/vsmc.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017, EPAM Systems + * + * 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 __ASM_ARM_VSMC_H__ +#define __ASM_ARM_VSMC_H__ + +#include + +void do_trap_smc(struct cpu_user_regs *regs, const union hsr hsr); + +#endif /* __ASM_ARM_VSMC_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End:b + */ diff --git a/xen/include/public/arch-arm/smc.h b/xen/include/public/arch-arm/smc.h new file mode 100644 index 0000000..3d3cd90 --- /dev/null +++ b/xen/include/public/arch-arm/smc.h @@ -0,0 +1,58 @@ +/* + * smc.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_SMC_H__ +#define __XEN_PUBLIC_ARCH_ARM_SMC_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_SMC_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End:b + */