From patchwork Thu Sep 21 20:00:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 9964783 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 846456020C for ; Thu, 21 Sep 2017 20:03:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 753A7205A4 for ; Thu, 21 Sep 2017 20:03:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6879929698; Thu, 21 Sep 2017 20:03:27 +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 42129205A4 for ; Thu, 21 Sep 2017 20:03:26 +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 1dv7ef-0007bF-Um; Thu, 21 Sep 2017 20:01:01 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dv7ed-0007ZX-Ts for xen-devel@lists.xen.org; Thu, 21 Sep 2017 20:01:00 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id F6/09-03454-B7A14C95; Thu, 21 Sep 2017 20:00:59 +0000 X-Brightmail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uk@epam.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1506024057!58391291!1 X-Originating-IP: [104.47.1.43] 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 22697 invoked from network); 21 Sep 2017 20:00:57 -0000 Received: from mail-ve1eur01on0043.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (104.47.1.43) by server-2.tower-27.messagelabs.com with AES256-SHA256 encrypted SMTP; 21 Sep 2017 20:00:57 -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=G09761cjvbqPevhtrSoTtyON8eLj3rICUxJtbGM723g=; b=CR3g2d82uAR7dS7U7tkOCzUKssjHl219/8s0cIZfr0PNS663m9sUoLKYlMrzV/wd5+6EjYUqIll3rLkU9yVZslkt2hpAo/5FuV+lpegXH0ROujlXK7d8ewzreYamtv3jWWVS1nLW2hUY2NoqBr8Xe7x9yw1TEubTNrSbIKstLuY= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.56) by DB6PR0301MB2136.eurprd03.prod.outlook.com (2603:10a6:4:46::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.56.11; Thu, 21 Sep 2017 20:00:54 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Thu, 21 Sep 2017 23:00:51 +0300 From: Volodymyr Babchuk To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 23:00:00 +0300 Message-Id: <1506024004-8615-7-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506024004-8615-1-git-send-email-volodymyr_babchuk@epam.com> References: <1506024004-8615-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.56] X-ClientProxiedBy: DB6PR1001CA0006.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:b7::16) To DB6PR0301MB2136.eurprd03.prod.outlook.com (2603:10a6:4:46::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 874bcd8f-d064-405f-23be-08d5012b7824 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:DB6PR0301MB2136; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0301MB2136; 3:qWMKWmwOOgfrsgUPZndckCZFfgu35YR2MmVbma6xz8ZiSIpAONi5+WX6ROJc6yFNuJAPeIdShsKJej/nbQGJFeGs+hgb7BneUGdexWIBZu2SRQLm+Nz4zM2X7pHllzrg2PHaVTdJM+TVw3Ul+TV1KGUNeqpovWnlViyK05v8YF6NNZJbIC2e/V1Dduj+HB5uMLb/aDmefITC9kALjy2LPHHL2jHNQhjMrK0E6qjJsZzQFJBMGu9CYFQ0lNjxIb+T; 25:aKaz8z5RtzYRusCfCrCHqZkDuL9/8n/1le9cLtn2hmf5OopEgyS0uDCBz7pQhxhclV+0rBtbOq76viaNgjmqZ6FOHUFMkfhCX9VrKTkLLXsKQhMuErzj79CaCClwWPZHdtVWT3s5Y6gZEDUh/6cB3iXd7hYXnoYuqdH/whg6W8+TYXBAqnBE9RANW3GEKsR+tuNdbc1udBjb3CynXozfsYtIzQe/wtBsbUmU7MF6VcuTrO5TN2lA1/fkxAbVhl58gDtcTqrm7yEPgmxUcdvGnTlvfCVwk5RDLTd6Po+epbtGV0CjUAaaF22/xMNxKTTVu1vvVWS9rKB5NDgYEpIpoQ==; 31:t2zqHPW7OcC5vmO6FhzwWw4hijniVb+82k12cEpm5akwxUfU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change-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)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(6041248)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123560025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR0301MB2136; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR0301MB2136; X-Forefront-PRVS: 04371797A5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(376002)(346002)(199003)(189002)(86362001)(81156014)(50466002)(50226002)(81166006)(122856001)(2906002)(66066001)(16586007)(478600001)(7736002)(8676002)(36756003)(72206003)(305945005)(5003940100001)(50986999)(7350300001)(48376002)(97736004)(101416001)(68736007)(76176999)(316002)(53936002)(189998001)(80792005)(6666003)(33646002)(4326008)(106356001)(8656003)(47776003)(54906003)(5660300001)(2351001)(42186006)(8666007)(7416002)(6916009)(2950100002)(2361001)(3846002)(105586002)(6116002)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0301MB2136; 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; DB6PR0301MB2136; 23:aU450ww3OVJqltllAbCALbiFavuqnwSv3kaY8XX?= =?us-ascii?Q?AggLwRIPpo+sbfCAu8VZfZ19M46Mdtog8CoaxOIOQV2WMH6MLpb3TC8ULaFC?= =?us-ascii?Q?xF0077K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i2C/foSE3lWtjYLYewEnXUWDuTeuxMcanPdMh4soorVjs7DNuShoHVYareBRvux7GQxAQbH+z/n9gDIS2NJUbSnmTFqSXYYoFXcAucuruTg5fbubsNWT8IZY0ZdAz8rEcd0WNrP8qC4k7PikcmI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2017 20:00:54.4899 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0301MB2136 Cc: "Edgar E . Iglesias" , Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Volodymyr Babchuk Subject: [Xen-devel] [PATCH v6 06/10] 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 --- * Added helepers fill_revision() and fill_function_call_count() * Renamed fill_uuid() to fill_uid() (because ARM SCCC uses term UID) * All helpers return bool * All this changes makes call handling more uniform * Fixed alignment for XEN_SMCCC_UID XEN_DEFINE_UUID (damn emacs tries to insert tabs ever when it was told not to do so) --- 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 17bff98..ede21fd 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -52,6 +52,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 431dff9..8397188 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -2174,23 +2174,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 f88cbf6..6efd1c5 100644 --- a/xen/include/asm-arm/traps.h +++ b/xen/include/asm-arm/traps.h @@ -31,6 +31,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 + */