From patchwork Fri Mar 10 15:11:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 95156 Delivered-To: patches@linaro.org Received: by 10.140.82.71 with SMTP id g65csp93926qgd; Fri, 10 Mar 2017 07:11:54 -0800 (PST) X-Received: by 10.28.136.68 with SMTP id k65mr3071539wmd.48.1489158714189; Fri, 10 Mar 2017 07:11:54 -0800 (PST) Return-Path: Received: from mail-wr0-x230.google.com (mail-wr0-x230.google.com. [2a00:1450:400c:c0c::230]) by mx.google.com with ESMTPS id e68si3207277wmd.117.2017.03.10.07.11.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Mar 2017 07:11:54 -0800 (PST) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 2a00:1450:400c:c0c::230 as permitted sender) client-ip=2a00:1450:400c:c0c::230; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 2a00:1450:400c:c0c::230 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-wr0-x230.google.com with SMTP id g10so66813202wrg.2 for ; Fri, 10 Mar 2017 07:11:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=y9joMVs18FcnttJBuj9Lz2ibKMFHrMaGCaUq9VWqdOo=; b=jpeT8PCCwZrbI9ky7c3bsnB5srqFyXbudwqo8TTZmYy0PNzh/92kpCD+9ezPQ8ATLl UtWAlgDo7Hpn8iDU41hs9mlLYNdv5hsf8IKBGS8REc2X6i2Yqy4n17VIsFRymFGNzDEa JkNDwylpXYqL80dqx55MPwmgZirurcsgRdrug= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=y9joMVs18FcnttJBuj9Lz2ibKMFHrMaGCaUq9VWqdOo=; b=OMyVA2BpkC7p2TdQfYVLATAz295hX4r0/o5OSQGgp02bqL20rYMgpaLyiW+yGLaVWG T2armQqM2A5wrwmAGTjKac680tD2CUMqYrVUSNFOeC2ebQSl+2gJot19iGlh6Z0D56AL 3hkDIzZvuHoP6b4av6RtfKr0Zk8/colS69Xzik9oBVXx+Y721YsEy/aIgYzJtczdServ XV043fqBzwl4LbYM6WrY810Dw0tcF8Mp2iKfXq1+HLOQci/uJlVKGPC2sif81rLjOULm nS26747b6rhbJtXSL14HRS1igUi9CsmpV88BZ8bhkzaKvm0kpEqujXdKKcTRNvPgn1uA p0zQ== X-Gm-Message-State: AMke39nZnfZVh2ozx+fQbugxqXQRuyQz8QkH5ZBPxfhajnwOYuC5C163nQQVy+wLxz2AW8Jmauc= X-Received: by 10.223.177.151 with SMTP id q23mr15806690wra.65.1489158713561; Fri, 10 Mar 2017 07:11:53 -0800 (PST) Return-Path: Received: from jax.c.hoisthospitality.com ([109.74.56.122]) by smtp.gmail.com with ESMTPSA id y6sm13234201wrc.40.2017.03.10.07.11.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 10 Mar 2017 07:11:52 -0800 (PST) From: Jens Wiklander To: Greg Kroah-Hartman , Arnd Bergmann , Olof Johansson , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Al Viro , jean-michel.delorme@st.com, emmanuel.michel@st.com, javier@javigon.com, Jason Gunthorpe , Mark Rutland , Michal Simek , Rob Herring , Will Deacon , Nishanth Menon , "Andrew F . Davis" , broonie@kernel.org, scott.branden@broadcom.com, Loic PALLARDY , Etienne CARRIERE , Benjamin GAIGNARD , Patrice CHOTARD , Christophe PRIOUZEAU , Eric FINCO , Franck ALBESA , Wei Xu , Jens Wiklander Subject: [PATCH v16 0/5] generic TEE subsystem Date: Fri, 10 Mar 2017 16:11:38 +0100 Message-Id: <1489158703-22241-1-git-send-email-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Hi, This patch set introduces a generic TEE subsystem. These patches are used on HiKey in AOSP. It's currently supported by roughly 20 platforms (https://github.com/OP-TEE/optee_os#3-platforms-supported), to name a few, Renesas RCAR H3, Sequitur Labs CoreTEE, Wind River VxWorks etc. The TEE subsystem will contain drivers for various TEE implementations. A TEE (Trusted Execution Environment) is a trusted OS running in some secure environment, for example, TrustZone on ARM CPUs, or a separate secure co-processor etc. Regarding use cases, TrustZone has traditionally been used for offloading secure tasks to the secure world. Examples include: - Secure key handling where the OS may or may not have direct access to key material. - E-commerce and payment technologies. Credentials, credit card numbers etc could be stored in a more secure environment. - Trusted User Interface (TUI) to ensure that no-one can snoop PIN-codes etc. - Secure boot to ensure that loaded binaries haven’t been tampered with. It’s not strictly needed for secure boot, but you could enhance security by leveraging a TEE during boot. - Digital Rights Management (DRM), the studios provides content with different resolution depending on the security of the device. Higher security means higher resolution. A TEE could also be used in existing and new technologies. For example IMA (Integrity Measurement Architecture) which has been in the kernel for quite a while. Today you can enhance security by using a TPM-chip to sign the IMA measurement list. This is something that also has been done in practical systems by leveraging a TEE. Another example could be in 2-factor authentication which is becoming increasingly more important. FIDO (https://fidoalliance.org) for example are using public key cryptography in their 2-factor authentication standard (U2F). With FIDO, a private and public key pair will be generated for every site you visit and the private key should never leave the local device. This is an example where you could use secure storage in a TEE for the private key. Today you will find a quite a few different out of tree implementations of TEE drivers which tends to fragment the TEE ecosystem and development. We think it would be a good idea to have a generic TEE driver integrated in the kernel which would serve as a base for several different TEE solutions, no matter if they are on-chip like TrustZone or if they are on a separate crypto co-processor. To develop this TEE subsystem we have been using the open source TEE called OP-TEE (https://www.op-tee.org/) and therefore this would be the first TEE solution supported by this new subsystem. OP-TEE is a GlobalPlatform compliant TEE, however this TEE subsystem is not limited to only GlobalPlatform TEEs, instead we have tried to design it so that it should work with other TEE solutions also. Since the first version (2015 April) of this patchset we’ve talked about it at Linaro Connect, GlobalPlatform annual TEE conference and last time at Linux Plumbers, so we think there has been both exposure and plenty of time to be able to get involved in this work. "tee: generic TEE subsystem" brings in the generic TEE subsystem which helps when writing a driver for a specific TEE, for example, OP-TEE. "tee: add OP-TEE driver" is an OP-TEE driver which uses the subsystem to do its work. This patch set has been prepared in cooperation with Javier González who proposed "Generic TrustZone Driver in Linux Kernel" patches 28 Nov 2014, https://lwn.net/Articles/623380/ . We've since then changed the scope to TEE instead of TrustZone. We have discussed the design on tee-dev@lists.linaro.org (archive at https://lists.linaro.org/pipermail/tee-dev/) with people from other companies, including Valentin Manea , Emmanuel MICHEL , Jean-michel DELORME , and Joakim Bech . Our main concern has been to agree on something that is generic enough to support many different TEEs while still keeping the interface together. v16: * Rebased on v4.11-rc1 * Fixed the is SMP issue with help from Arnd Bergman * Fixed a missue of IDR * Fixed some typos reported by Stuart Yoder and Benjamin Gaignard * Adding wrappers for arm_smccc_smc() and arm_smccc_hvc() due to recent changes v15: * Rebased on v4.10-rc5 * Addressed review comments from Arnd Bergmann, with these hightligts: - Remove the platform device in OP-TEE driver - Comment on optee call queue wait functions to make it easier to see the purpose - Replace calls to ioremap_cache() with calls to memremap() - Remove OPTEE_MSG_OS_OPTEE_REVISION_*, that aren't used or kept up to date - Extend description of OPTEE_MSG_RPC_CMD_WAIT_QUEUE - Remove OPTEE_MSG_GET_PARAMS instead have a struct optee_msg_param params[] at the end of struct optee_msg_arg - get rid of union in struct tee_ioctl_param - add params[] to struct tee_ioctl_open_session_arg, struct tee_iocl_supp_recv_arg and struct tee_iocl_supp_send_arg * "arm64: dt: hikey: Add optee node" Acked-by: Wei Xu * Tested-by: Scott Branden v14: * Rebased on v4.10-rc4 * Fixed checkpatch warning in OPTEE_SMC_RETURN_IS_RPC() macro v13: * Rebased on v4.9-rc5 * Added Hikey DT patch * Tested-by: Jerome Forissier (HiKey) * Tested-by: Volodymyr Babchuk (RCAR H3) * Tested-by: Andrew F. Davis v12-resend: * Rebased on v4.9-rc2 v12: * Rebased on v4.8-rc5 * Addressed review comments from Andrew F. Davis * Removed Acked-by: Andreas Dannenberg as the mail bounces * Bugfix possible null dereference in error cleanup path of optee_probe(). * Bugfix optee_from_msg_param() when calculating offset of memref into a shared memory object v11: * Rebased on v4.8-rc3 * Addressed review comments from Nishanth Menon * Made the TEE framework available as a loadable module. * Reviewed-by: Javier González * Zeroes shared memory on allocation to avoid information leakage * Links shared memory objects to context to avoid stealing of shared memory object from an unrelated process * Allow RPC interruption if supplicant is unavailable v10: * Rebased on v4.7-rc1 * Addressed private review comments from Nishanth Menon * Optee driver only accepts one supplicant process on the privileged device * Optee driver avoids long delayed releases of shm objects * Added more comments on functions and structs v9: * Rebased on v4.6-rc1 * Acked-by: Andreas Dannenberg * Addressed comments from Al Viro how file descriptors are passed to user space * Addressed comments from Randy Dunlap on documentation * Changed license for include/uapi/linux/tee.h v8: * Rebased on v4.5-rc3 * dt/bindings: add bindings for optee Acked-by: Rob Herring * Fixes build error for X86 * Fixes spell error in "dt/bindings: add bindings for optee" v7: * Rebased on v4.5-rc2 * Moved the ARM SMC Calling Convention support into a separate patch set, which is now merged v6: * Rebased on v4.3-rc7 * Changed smccc interface to let the compiler marshal most of the parameters * Added ARCH64 capability for smccc interface * Changed the PSCI firmware calls (both arm and arm64) to use the new generic smccc interface instead instead of own assembly functions. * Move optee DT bindings to below arm/firmware * Defines method for OP-TEE driver to call secure world in DT, smc or hvc * Exposes implementation id of a TEE driver in sysfs to easily spawn corresponding tee-supplicant when device is ready * Update OP-TEE Message Protocol to better cope with fragmented physical memory * Read time directly from OP-TEE driver instead of forwarding the RPC request to tee-supplicant v5: * Replaced kref reference counting for the device with a size_t instead as the counter is always protected by a mutex v4: * Rebased on 4.1 * Redesigned the synchronization around entry exit of normal SMC * Replaced rwsem on the driver instance with kref and completion since rwsem wasn't intended to be used in this way * Expanded the TEE_IOCTL_PARAM_ATTR_TYPE_MASK to make room for future additional parameter types * Documents TEE subsystem and OP-TEE driver * Replaced TEE_IOC_CMD with TEE_IOC_OPEN_SESSION, TEE_IOC_INVOKE, TEE_IOC_CANCEL and TEE_IOC_CLOSE_SESSION * DT bindings in a separate patch * Assembly parts moved to arch/arm and arch/arm64 respectively, in a separate patch * Redefined/clarified the meaning of OPTEE_SMC_SHM_CACHED * Removed CMA usage to limit the scope of the patch set v3: * Rebased on 4.1-rc3 (dma_buf_export() API change) * A couple of small sparse fixes * Documents bindings for OP-TEE driver * Updated MAINTAINERS v2: * Replaced the stubbed OP-TEE driver with a real OP-TEE driver * Removed most APIs not needed by OP-TEE in current state * Update Documentation/ioctl/ioctl-number.txt with correct path to tee.h * Rename tee_shm_pool_alloc_cma() to tee_shm_pool_alloc() * Moved tee.h into include/uapi/linux/ * Redefined tee.h IOCTL macros to be directly based on _IOR and friends * Removed version info on the API to user space, a data blob which can contain an UUID is left for user space to be able to tell which protocol to use in TEE_IOC_CMD * Changed user space exposed structures to only have types with __ prefix * Dropped THIS_MODULE from tee_fops * Reworked how the driver is registered and ref counted: - moved from using an embedded struct miscdevice to an embedded struct device. - uses an struct rw_semaphore as synchronization for driver detachment - uses alloc/register pattern from TPM Thanks, Jens Jens Wiklander (4): dt/bindings: add bindings for optee tee: generic TEE subsystem tee: add OP-TEE driver Documentation: tee subsystem and op-tee driver Jerome Forissier (1): arm64: dt: hikey: Add optee node Documentation/00-INDEX | 2 + .../bindings/arm/firmware/linaro,optee-tz.txt | 31 + .../devicetree/bindings/vendor-prefixes.txt | 1 + Documentation/ioctl/ioctl-number.txt | 1 + Documentation/tee.txt | 118 +++ MAINTAINERS | 13 + arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts | 7 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/tee/Kconfig | 18 + drivers/tee/Makefile | 5 + drivers/tee/optee/Kconfig | 7 + drivers/tee/optee/Makefile | 5 + drivers/tee/optee/call.c | 444 ++++++++++ drivers/tee/optee/core.c | 622 ++++++++++++++ drivers/tee/optee/optee_msg.h | 418 ++++++++++ drivers/tee/optee/optee_private.h | 183 +++++ drivers/tee/optee/optee_smc.h | 450 +++++++++++ drivers/tee/optee/rpc.c | 396 +++++++++ drivers/tee/optee/supp.c | 273 +++++++ drivers/tee/tee_core.c | 893 +++++++++++++++++++++ drivers/tee/tee_private.h | 129 +++ drivers/tee/tee_shm.c | 358 +++++++++ drivers/tee/tee_shm_pool.c | 156 ++++ include/linux/tee_drv.h | 277 +++++++ include/uapi/linux/tee.h | 346 ++++++++ 26 files changed, 5156 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/firmware/linaro,optee-tz.txt create mode 100644 Documentation/tee.txt create mode 100644 drivers/tee/Kconfig create mode 100644 drivers/tee/Makefile create mode 100644 drivers/tee/optee/Kconfig create mode 100644 drivers/tee/optee/Makefile create mode 100644 drivers/tee/optee/call.c create mode 100644 drivers/tee/optee/core.c create mode 100644 drivers/tee/optee/optee_msg.h create mode 100644 drivers/tee/optee/optee_private.h create mode 100644 drivers/tee/optee/optee_smc.h create mode 100644 drivers/tee/optee/rpc.c create mode 100644 drivers/tee/optee/supp.c create mode 100644 drivers/tee/tee_core.c create mode 100644 drivers/tee/tee_private.h create mode 100644 drivers/tee/tee_shm.c create mode 100644 drivers/tee/tee_shm_pool.c create mode 100644 include/linux/tee_drv.h create mode 100644 include/uapi/linux/tee.h -- 2.7.4