From patchwork Wed Oct 11 19:01:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 10000363 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 D69B2602BF for ; Wed, 11 Oct 2017 19:04:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C03E028B25 for ; Wed, 11 Oct 2017 19:04:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B512D28B26; Wed, 11 Oct 2017 19:04:13 +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 28FF028B23 for ; Wed, 11 Oct 2017 19:04:13 +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 1e2MGi-0000Wz-5Z; Wed, 11 Oct 2017 19:02:12 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2MGg-0000WW-Kz for xen-devel@lists.xen.org; Wed, 11 Oct 2017 19:02:10 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id BD/1D-07499-1BA6ED95; Wed, 11 Oct 2017 19:02:09 +0000 X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msg-Ref: server-10.tower-21.messagelabs.com!1507748528!70107063!1 X-Originating-IP: [104.47.2.43] 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 22705 invoked from network); 11 Oct 2017 19:02:09 -0000 Received: from mail-db5eur01on0043.outbound.protection.outlook.com (HELO EUR01-DB5-obe.outbound.protection.outlook.com) (104.47.2.43) by server-10.tower-21.messagelabs.com with AES256-SHA256 encrypted SMTP; 11 Oct 2017 19:02:09 -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=fhEwZerbKobxyBGid1tMDItW94r50fq9ayBNb30NU4A=; b=TFDa+AWzIuyriyYbLsa7XPv8NTzjg43y8CAvhONdZGLPDC2p8N7csnFCXa1xkzdaON/mCvessjbWXPrJY+kNhp//xN81pvtFNf/CeAyVvaOHFxBxJyZs1mQtdzIWdDUYGGajdWyeT8Ce+abAvsHv2JZ0QPpvX3lI8A0cBgGQPgc= Received: from EPUAKYIW2556.kyiv.epam.com (85.223.209.56) by DB6PR0301MB2133.eurprd03.prod.outlook.com (2603:10a6:4:46::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Wed, 11 Oct 2017 19:02:06 +0000 Received: by EPUAKYIW2556.kyiv.epam.com (sSMTP sendmail emulation); Wed, 11 Oct 2017 22:02:01 +0300 From: Volodymyr Babchuk To: Stefano Stabellini , Julien Grall , xen-devel@lists.xen.org Date: Wed, 11 Oct 2017 22:01:24 +0300 Message-Id: <1507748484-16871-5-git-send-email-volodymyr_babchuk@epam.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507748484-16871-1-git-send-email-volodymyr_babchuk@epam.com> References: <1507748484-16871-1-git-send-email-volodymyr_babchuk@epam.com> MIME-Version: 1.0 X-Originating-IP: [85.223.209.56] X-ClientProxiedBy: VI1P18901CA0015.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::25) To DB6PR0301MB2133.eurprd03.prod.outlook.com (2603:10a6:4:46::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8320f6de-9fba-4896-570a-08d510da9153 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:DB6PR0301MB2133; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0301MB2133; 3:PUuTCjrSMQxAmNna8UDYX9wMrxsnGOETJj4nKA0I3jhlJccvlwlMQDGZvVSzKMBJ09afntfpzLS09p1N3hJUeeDKT3oWKbcD4SZaSCK/RSOfdCUgiduGQnxCM4XCyMoOG3aP0dCVNm2ybdE2Byjc/1kj0XiPZF0dp4ZJ12Po+VoAcXu7oBgb6rRCmCjeMt5APrmhMpXjWh8r0ZEgruwdJIED0puV8npCVv7/DUB8yNUt6n7t9F9xbb4lPsIKNWV5; 25:StuLKfZ1dLoejCNZYEoewYBK3rQJsbOlzSnJkGg3ktw7V94McUA4M2n8jWIsiM6Wwqj8g9cCHnx/KeTOaTVfT3GtQOihzsy0qcMDB0SCQoT9j6GGxmSGlNQb4OVUEmugZa/G77JaO1dsWdNYY6udF+wuLgeaBdAxGOBF+Gtld+Cl2OdWgeKf6vazBbtjXVlc2oUqR177Js7KMiQRiJo+i03jGR3C9ist09VYG9FDMiGGymldGjjN80Fk9llyxbV+VxFMHyVNO/ejyXJTMsvw94FXb+LThw2d8KqjdqTNfEQsJYPnJBeHD4t/dR3c9FSDD6qsmtmkrMBFEURw31fmtQ==; 31:S4cZ/y9ee7m70sb8hOz1/pO9i3RYYZXAFCxrkeLf5SScEAO8+WpF72KOWmgfeVStRr5Y4R/eVbLh54+JlOQhIitsoHE/Jschwax5zaaBEBgkPwACne4kKtNXW6XCDUhLXVhsE9x6ltSyfE7VJ1HCsBzzWlg/da91tQjvNji4T9aQRf/dQJArLRr/bSjLQifrwZ76zJXHtcko6hwkhYDkQ3Bbr9dw6h7u8KAek93qR0A= X-MS-TrafficTypeDiagnostic: DB6PR0301MB2133: X-Microsoft-Exchange-Diagnostics: 1; DB6PR0301MB2133; 20:QVioekarWjofnSJYmMjJ3dWe8a6rOjwgpRcX5EI+PKLNbu9VVUKfzGOOfJZTJVkmBP2CvYvX8ExJyjpnq+gfs/qBi0qRMnE//pi+nywvmCgdxvh2FBQ6Wvcj85uK1kNdpXeLxWOnMdM8k8ZIhMGyM/yQCqjlMWa4RpKgTgDLdfP8P2eZVgWz6WDBkJFjkIeQWcbEl4m+GAf3iH8Ynm9UbmyacfID+f6zz2c26iwfT0cziJ6PeGK3ix0z79xxGChvR3AV0dV4l2vvSEST2o7Ouu31QR/clQCly78GLGNf70auiz9pTZxrkNpkSONryHoqCZXJ6B5+lYoNoJlBSftms1sJd/Vhch+0CNiO/lefcc5AGn1RSuOFVI8BsV/WVICINNB7PmRHfGHr7WI0C5DvYgMJvvW69X2Akx0hZqtKPWTTArW5zXi1MtcmARqZQJhF3BhyEhAlXIyQjbBKlA/yM8jkpb9Z6SmBjpgWHLMdwayT2LNYTZflV18qlD1vvNdt; 4:Krmxen84dbnMaBzRbLAO8qW2N1I/ZLTYaIv99uWUYzn2OEg/7HjJwn6pxld4H1Ec1BVh8pog5ylEUXF9B92M8jP4N9QNgRtqI1e2FNCGxB33MCGSun3pCYg7b3zJVVkvBOWN6XU3bBUxIvP/fahWxyqfy3b1qSVxnBpVvcf923Sl3j5SHivqdSypeJtypY4ROnqdROvJUZ67Vm/p8igORnHQ4OCLOuKPzLBlbK0UuYdQX7MvdpzQn3bSE7KsTWWuXzDKt7OucQEE33whfsfkzSjhliGJUdKk+kG3Efcl4DM= 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)(2401047)(5005006)(8121501046)(100000703101)(100105400095)(10201501046)(3002001)(93006095)(93001095)(6041248)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123555025)(20161123564025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR0301MB2133; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR0301MB2133; X-Forefront-PRVS: 0457F11EAF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(189002)(199003)(66066001)(122856001)(2906002)(50986999)(2950100002)(47776003)(106356001)(305945005)(5003940100001)(105586002)(101416001)(7736002)(8676002)(76176999)(81156014)(33646002)(4326008)(8936002)(81166006)(86362001)(189998001)(36756003)(80792005)(68736007)(97736004)(3846002)(72206003)(16586007)(48376002)(42186006)(54906003)(478600001)(6666003)(316002)(6116002)(50466002)(110136005)(5660300001)(50226002)(53936002)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0301MB2133; H:EPUAKYIW2556.kyiv.epam.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; DB6PR0301MB2133; 23:og8Hh7rxTUvtRzWtLuF7iVTuDfE01ZwmhUG9AkP?= =?us-ascii?Q?vr6xYjbgGlcxTDxX2L74OzEBITbNsWQhGnUrjoVnSut5CqPLiw1QLbpFQBjk?= =?us-ascii?Q?ZsyQbxd9wRVlXR7E7LP9lmVnItq1UL0V2ZT8srJuLkCjcZ0/7DWnNYmCke2E?= =?us-ascii?Q?VqmZ+o4u0iagjLDIbb1uypTTzaSYC5vhVLjyOYkLhhRiS7FA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BylNm4M8Bab8u8L95kj8Tby45ZWqJI9VeT+w=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0301MB2133; 6:wMQNZ29z0jeaULYUgZpJ/y0E1azv/WXmbHQP4PPclQ9orNbSgmslCgMXFSxFzBG5On1O35fz46ikZdKmZpumJYLU+O/JdOHdBn1IbVfTS4WJl4tssPMFfHudXKMlGmFR3LqW1u7VVafyVeqT3Ii0Qvxy4ZmCBTQZDMa+ccWzEfUcDNgtF9ePzmsbxVPGVgmCbmDGL84n6ODnS2/Xns7p0gz8teuJBM0bIOrms+zwrUixyyCA/m2JSWGdOOMsgnQS+PIv7A85nTx/luJoFx3DQdccIAf+m3oLodpzn8VbcZCBjdd/aYFM4UZK1IQsMqQlxMV5hJzfISa5Ndf5j/4xTA==; 5:ttrFTVqwnipko0uWIPyHdvb8+kcAvOdKJvvyyaG3mfJ5S3GCYrgCI7MOcEJ5EvauHqmpeKz8eagmssnppauLHfYCy3Mt9Z4WEttTZyFSsUEpMOh4AXCd65HX+AY5dlW0lALc62opIDsSak/kT0NUUw==; 24:ZZIr/k0PSMkGMU32ielyUlhcNqyIi4t8Oa0zwCDQDVvSjEfb9lVl4c1zG3OXc86zaUDWojQ/XhLcuHunSdwy1/c0AY/uxfiFMhD3ldhZ16c=; 7:XWrb3s7XdJodSI9S1UXs42CYOw66yl/flvUL5xuri6VxeUPzSnE22lS9r+XYyvZbOX7cFr0QN3fOxRxjUW+6+F+vOfDviTNLHgz7lVgeY0DgNAd7OZ72nBylKH7AARfC4olFo7tHp8CoZvduOpPnZd+mB2OdZjEmrJ0a9+CNfvnkSslGd8qt9IgQ8bd9k/dtEFCtaigKhECXAocWLa9z94DNBke4MjXxoM3J7c5zjhQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2017 19:02:06.3772 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0301MB2133 Cc: Volodymyr Babchuk , Jens Wiklander Subject: [Xen-devel] [RFC 4/4] arm: tee: add basic OP-TEE mediator 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 Add basic OP-TEE mediator as an example how TEE mediator framework works. Currently it support only calls from Dom0. Calls from other guests will be declined. It maps OP-TEE static shared memory region into Dom0 address space, so Dom0 is the only domain which can work with older versions of OP-TEE. Also it alters SMC requests by\ adding domain id to request. OP-TEE can use this information to track requesters. Albeit being in early development stages, this mediator already can be used on systems where only Dom0 interacts with OP-TEE. It was tested on RCAR Salvator-M3 board. Signed-off-by: Volodymyr Babchuk --- xen/arch/arm/tee/Kconfig | 4 ++ xen/arch/arm/tee/Makefile | 1 + xen/arch/arm/tee/optee.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 xen/arch/arm/tee/optee.c diff --git a/xen/arch/arm/tee/Kconfig b/xen/arch/arm/tee/Kconfig index e69de29..7c6b5c6 100644 --- a/xen/arch/arm/tee/Kconfig +++ b/xen/arch/arm/tee/Kconfig @@ -0,0 +1,4 @@ +config ARM_OPTEE + bool "Enable OP-TEE mediator" + default n + depends on ARM_TEE diff --git a/xen/arch/arm/tee/Makefile b/xen/arch/arm/tee/Makefile index c54d479..9d93b42 100644 --- a/xen/arch/arm/tee/Makefile +++ b/xen/arch/arm/tee/Makefile @@ -1 +1,2 @@ obj-y += tee.o +obj-$(CONFIG_ARM_OPTEE) += optee.o diff --git a/xen/arch/arm/tee/optee.c b/xen/arch/arm/tee/optee.c new file mode 100644 index 0000000..0220691 --- /dev/null +++ b/xen/arch/arm/tee/optee.c @@ -0,0 +1,178 @@ +/* + * xen/arch/arm/tee/optee.c + * + * OP-TEE mediator + * + * Volodymyr Babchuk + * Copyright (c) 2017 EPAM Systems. + * + * 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 "optee_msg.h" +#include "optee_smc.h" + +/* + * OP-TEE violates SMCCC when it defines own UID. So we need + * to place bytes in correct order. + */ +#define OPTEE_UID (xen_uuid_t){{ \ + (uint8_t)(OPTEE_MSG_UID_0 >> 0), (uint8_t)(OPTEE_MSG_UID_0 >> 8), \ + (uint8_t)(OPTEE_MSG_UID_0 >> 16), (uint8_t)(OPTEE_MSG_UID_0 >> 24), \ + (uint8_t)(OPTEE_MSG_UID_1 >> 0), (uint8_t)(OPTEE_MSG_UID_1 >> 8), \ + (uint8_t)(OPTEE_MSG_UID_1 >> 16), (uint8_t)(OPTEE_MSG_UID_1 >> 24), \ + (uint8_t)(OPTEE_MSG_UID_2 >> 0), (uint8_t)(OPTEE_MSG_UID_2 >> 8), \ + (uint8_t)(OPTEE_MSG_UID_2 >> 16), (uint8_t)(OPTEE_MSG_UID_2 >> 24), \ + (uint8_t)(OPTEE_MSG_UID_3 >> 0), (uint8_t)(OPTEE_MSG_UID_3 >> 8), \ + (uint8_t)(OPTEE_MSG_UID_3 >> 16), (uint8_t)(OPTEE_MSG_UID_3 >> 24), \ + }} + +static int optee_init(void) +{ + printk("OP-TEE mediator init done\n"); + return 0; +} + +static void optee_domain_create(struct domain *d) +{ + /* + * Do nothing at this time. + * In the future this function will notify that new VM is started. + */ +} + +static void optee_domain_destroy(struct domain *d) +{ + /* + * Do nothing at this time. + * In the future this function will notify that VM is being destroyed. + */ +} + +static bool forward_call(struct cpu_user_regs *regs) +{ + register_t resp[4]; + + call_smccc_smc(get_user_reg(regs, 0), + get_user_reg(regs, 1), + get_user_reg(regs, 2), + get_user_reg(regs, 3), + get_user_reg(regs, 4), + get_user_reg(regs, 5), + get_user_reg(regs, 6), + /* VM id 0 is reserved for hypervisor itself */ + current->domain->domain_id +1, + resp); + + set_user_reg(regs, 0, resp[0]); + set_user_reg(regs, 1, resp[1]); + set_user_reg(regs, 2, resp[2]); + set_user_reg(regs, 3, resp[3]); + + return true; +} + +static bool handle_get_shm_config(struct cpu_user_regs *regs) +{ + paddr_t shm_start; + size_t shm_size; + int rc; + + printk("handle_get_shm_config\n"); + /* Give all static SHM region to the Dom0 */ + if ( current->domain->domain_id != 0 ) + return false; + + forward_call(regs); + + /* Return error back to the guest */ + if ( get_user_reg(regs, 0) != OPTEE_SMC_RETURN_OK) + return true; + + shm_start = get_user_reg(regs, 1); + shm_size = get_user_reg(regs, 2); + + /* Dom0 is mapped 1:1 */ + rc = map_regions_p2mt(current->domain, gaddr_to_gfn(shm_start), + shm_size / PAGE_SIZE, + maddr_to_mfn(shm_start), + p2m_ram_rw); + if ( rc < 0 ) + { + gprintk(XENLOG_INFO, "OP-TEE: Can't map static shm for Dom0: %d", rc); + set_user_reg(regs, 0, OPTEE_SMC_RETURN_ENOTAVAIL); + } + + return true; +} + +static bool handle_exchange_capabilities(struct cpu_user_regs *regs) +{ + forward_call(regs); + + printk("handle_exchange_capabilities\n"); + /* Return error back to the guest */ + if ( get_user_reg(regs, 0) != OPTEE_SMC_RETURN_OK) + return true; + + /* Don't allow guests to work without dynamic SHM */ + if (current->domain->domain_id != 0 && + !(get_user_reg(regs, 1) & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) ) + set_user_reg(regs, 0, OPTEE_SMC_RETURN_ENOTAVAIL); + return true; +} + +static bool optee_handle_smc(struct cpu_user_regs *regs) +{ + /* At this time we support only calls from Dom0. */ + if ( current->domain->domain_id != 0 ) + return false; + + switch ( get_user_reg(regs, 0) ) + { + case OPTEE_SMC_GET_SHM_CONFIG: + return handle_get_shm_config(regs); + case OPTEE_SMC_EXCHANGE_CAPABILITIES: + return handle_exchange_capabilities(regs); + default: + return forward_call(regs); + } + return true; +} + +static void optee_remove(void) +{ +} + +static const struct tee_mediator_ops optee_ops = +{ + .init = optee_init, + .domain_create = optee_domain_create, + .domain_destroy = optee_domain_destroy, + .handle_smc = optee_handle_smc, + .remove = optee_remove, +}; + +REGISTER_TEE_MEDIATOR(optee, "OP-TEE", OPTEE_UID, &optee_ops); + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */