Skip to contentSkip to conversation

generic TEE subsystem

RFC PATCH Superseded Jens Wiklander 1 participant 3 messages Apr 30, 2015

Subsystems (3)

v2 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#0 lore raw

v2 cover generic TEE subsystem

Hi,

This patch set introduces a generic TEE subsystem. The TEE subsystem will be able 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 banking applications, Digital Rights Management (DRM), or specific secure solutions.

This TEE subsystem can serve a TEE driver for a Global Platform compliant TEE, but it's not limited to only Global Platform TEEs. One reason why I'm doing this to be able to get an OP-TEE (https://github.com/OP-TEE/optee_os)
driver upstream.

The first patch brings in the generic TEE subsystem which helps when writing a driver for a specific TEE, for example, OP-TEE.

The second patch is an OP-TEE driver which uses the subsystem to do its work.

Javier is also working on a driver for another TEE so we will soon have at least two TEE drivers under the TEE subsystem.

Questions:
* Where should we put this in the tree? I'm proposing drivers/tee Another place could be drivers/firmware/tee. I don't have a strong opinion on either place.

* What should we have in the .compatible field in FDT for the OP-TEE driver? I'm proposing "optee,optee-tz" as OP-TEE doesn't really have a vendor. OP-TEE isn't limited to TrustZone, it can run in other environments too so "optee-tz" could be a way of keeping different options apart. I need advice here.

* Who will maintain this? I'm willing to do it together with Javier.

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 at lists.linaro.org (archive at
https://lists.linaro.org/pipermail/tee-dev/) with people from other companies, including Valentin Manea <[email protected]>, Emmanuel MICHEL <[email protected]>,
Jean-michel DELORME <[email protected]>,
and Joakim Bech <[email protected]>. Our main concern has been to agree on something that is generic enough to support many different TEEs while still keeping the interface together.

Open issues from last review:
* Comment from Arnd Bergmann on many empty dma-buf callbacks:
I haven't planned fill in more in those functions for this patch set. Fixing those empty bma-buf callbacks requires changes in dma-buf, can we take that outside this patch set?

* There has been some concerns about TEE_IOC_CMD, hopefully the OP-TEE driver will make the purpose more clear now.

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

Regards,
Jens

Jens Wiklander (2):
tee: generic TEE subsystem
tee: add OP-TEE driver

 Documentation/ioctl/ioctl-number.txt |   1 +
 drivers/Kconfig                      |   2 +
 drivers/Makefile                     |   1 +
 drivers/tee/Kconfig                  |  18 ++
 drivers/tee/Makefile                 |   4 +
 drivers/tee/optee/Kconfig            |  19 ++
 drivers/tee/optee/Makefile           |  13 +
 drivers/tee/optee/call.c             | 294 ++++++++++++++++++++
 drivers/tee/optee/core.c             | 509 ++++++++++++++++++++++++++++++++++
 drivers/tee/optee/optee_private.h    | 138 ++++++++++
 drivers/tee/optee/optee_smc.h        | 510 +++++++++++++++++++++++++++++++++++
 drivers/tee/optee/rpc.c              | 282 +++++++++++++++++++
 drivers/tee/optee/smc_a32.S          |  30 +++
 drivers/tee/optee/smc_a64.S          |  37 +++
 drivers/tee/optee/supp.c             | 327 ++++++++++++++++++++++
 drivers/tee/tee.c                    | 340 +++++++++++++++++++++++
 drivers/tee/tee_private.h            |  74 +++++
 drivers/tee/tee_shm.c                | 321 ++++++++++++++++++++++
 drivers/tee/tee_shm_pool.c           | 246 +++++++++++++++++
 include/linux/tee_drv.h              | 281 +++++++++++++++++++
 include/uapi/linux/optee_msg.h       | 368 +++++++++++++++++++++++++
 include/uapi/linux/tee.h             | 118 ++++++++
 22 files changed, 3933 insertions(+)
 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_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/smc_a32.S
 create mode 100644 drivers/tee/optee/smc_a64.S
 create mode 100644 drivers/tee/optee/supp.c
 create mode 100644 drivers/tee/tee.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/optee_msg.h
 create mode 100644 include/uapi/linux/tee.h
Signature · 1 line
1.9.1
#1 lore raw

RFC PATCH v2 1/2 tee: generic TEE subsystem

Initial patch for generic TEE subsystem.
This subsystem provides:
* Registration/un-registration of TEE drivers.
* Shared memory between normal world and secure world.
* Ioctl interface for interaction with user space.

A TEE (Trusted Execution Environment) driver is a driver that interfaces with a trusted OS running in some secure environment, for example, TrustZone on ARM cpus, or a separate secure co-processor etc.

To avoid putting unnecessary restrictions on the TEE driver and the trusted OS the TEE_IOC_CMD passes an opaque buffer to the TEE driver to facilitate a communication channel between user space and the trusted OS.

The TEE subsystem can serve a TEE driver for a Global Platform compliant TEE, but it's not limited to only Global Platform TEEs.

This patch builds on other similar implementations trying to solve the same problem:
* "optee_linuxdriver" by among others
Jean-michel DELORME<[email protected]> and Emmanuel MICHEL <[email protected]>
* "Generic TrustZone Driver" by Javier Gonz?lez <[email protected]>

---
 Documentation/ioctl/ioctl-number.txt |   1 +
 drivers/Kconfig                      |   2 +
 drivers/Makefile                     |   1 +
 drivers/tee/Kconfig                  |   8 +
 drivers/tee/Makefile                 |   3 +
 drivers/tee/tee.c                    | 340 +++++++++++++++++++++++++++++++++++
 drivers/tee/tee_private.h            |  74 ++++++++
 drivers/tee/tee_shm.c                | 321 +++++++++++++++++++++++++++++++++
 drivers/tee/tee_shm_pool.c           | 246 +++++++++++++++++++++++++
 include/linux/tee_drv.h              | 281 +++++++++++++++++++++++++++++
 include/uapi/linux/tee.h             | 118 ++++++++++++
 11 files changed, 1395 insertions(+)
 create mode 100644 drivers/tee/Kconfig
 create mode 100644 drivers/tee/Makefile
 create mode 100644 drivers/tee/tee.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
Documentation/ioctl/ioctl-number.txt +1 -0
index 8136e1f..a04afd5 100644
@@ -301,6 +301,7 @@ Code  Seq#(hex)	Include File		Comments
 0xA3	80-8F	Port ACL		in development:
 					<mailto:[email protected]>
 0xA3	90-9F	linux/dtlk.h
+0xA4	00-1F	uapi/linux/tee.h	Generic TEE subsystem
 0xAB	00-1F	linux/nbd.h
 0xAC	00-1F	linux/raw.h
 0xAD	00	Netfilter device	in development:
drivers/Kconfig +2 -0
index c0cc96b..7510f69 100644
@@ -182,4 +182,6 @@ source "drivers/thunderbolt/Kconfig"
 
 source "drivers/android/Kconfig"
 
+source "drivers/tee/Kconfig"
+
 endmenu
drivers/Makefile +1 -0
index 527a6da..0d24e70 100644
@@ -165,3 +165,4 @@ obj-$(CONFIG_RAS)		+= ras/
 obj-$(CONFIG_THUNDERBOLT)	+= thunderbolt/
 obj-$(CONFIG_CORESIGHT)		+= coresight/
 obj-$(CONFIG_ANDROID)		+= android/
+obj-$(CONFIG_TEE)		+= tee/
drivers/tee/Kconfig new file +8 -0
new file mode 100644
index 0000000..64a8cd7
@@ -0,0 +1,8 @@
+# Generic Trusted Execution Environment Configuration
+config TEE
+	bool "Trusted Execution Environment support"
+	default n
+	select DMA_SHARED_BUFFER
+	help
+	  This implements a generic interface towards a Trusted Execution
+	  Environment (TEE).
drivers/tee/Makefile new file +3 -0
new file mode 100644
index 0000000..60d2dab
@@ -0,0 +1,3 @@
+obj-y += tee.o
+obj-y += tee_shm.o
+obj-y += tee_shm_pool.o
drivers/tee/tee.c new file +340 -0

340 lines not on this page · raw message

drivers/tee/tee_private.h new file +74 -0

74 lines not on this page · raw message

drivers/tee/tee_shm.c new file +321 -0

321 lines not on this page · raw message

drivers/tee/tee_shm_pool.c new file +246 -0

246 lines not on this page · raw message

include/linux/tee_drv.h new file +281 -0

281 lines not on this page · raw message

include/uapi/linux/tee.h new file +118 -0

118 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

RFC PATCH v2 2/2 tee: add OP-TEE driver

In reply to Jens Wiklander

Adds a OP-TEE driver which also can be compiled as a loadable module.

* Targets ARM and ARM64
* Supports using reserved memory from OP-TEE as shared memory
* CMA as shared memory is optional and only tried if OP-TEE doesn't supply a reserved shared memory region
* Probes OP-TEE version using SMCs
* Accepts requests on privileged and unprivileged device
* Uses OPTEE message protocol version 2

---
 drivers/tee/Kconfig               |  10 +
 drivers/tee/Makefile              |   1 +
 drivers/tee/optee/Kconfig         |  19 ++
 drivers/tee/optee/Makefile        |  13 +
 drivers/tee/optee/call.c          | 294 ++++++++++++++++++++++
 drivers/tee/optee/core.c          | 509 +++++++++++++++++++++++++++++++++++++
 drivers/tee/optee/optee_private.h | 138 +++++++++++
 drivers/tee/optee/optee_smc.h     | 510 ++++++++++++++++++++++++++++++++++++++
 drivers/tee/optee/rpc.c           | 282 +++++++++++++++++++++
 drivers/tee/optee/smc_a32.S       |  30 +++
 drivers/tee/optee/smc_a64.S       |  37 +++
 drivers/tee/optee/supp.c          | 327 ++++++++++++++++++++++++
 include/uapi/linux/optee_msg.h    | 368 +++++++++++++++++++++++++++
 13 files changed, 2538 insertions(+)
 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_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/smc_a32.S
 create mode 100644 drivers/tee/optee/smc_a64.S
 create mode 100644 drivers/tee/optee/supp.c
 create mode 100644 include/uapi/linux/optee_msg.h
drivers/tee/Kconfig +10 -0
index 64a8cd7..b269276 100644
@@ -6,3 +6,13 @@ config TEE
 	help
 	  This implements a generic interface towards a Trusted Execution
 	  Environment (TEE).
+
+if TEE
+
+menu "TEE drivers"
+
+source "drivers/tee/optee/Kconfig"
+
+endmenu
+
+endif
drivers/tee/Makefile +1 -0
index 60d2dab..53f3c76 100644
@@ -1,3 +1,4 @@
 obj-y += tee.o
 obj-y += tee_shm.o
 obj-y += tee_shm_pool.o
+obj-$(CONFIG_OPTEE) += optee/
drivers/tee/optee/Kconfig new file +19 -0
new file mode 100644
index 0000000..3faa855
@@ -0,0 +1,19 @@
+# OP-TEE Trusted Execution Environment Configuration
+config OPTEE
+	tristate "OP-TEE"
+	default n
+	depends on ARM || ARM64
+	help
+	  This implements the OP-TEE Trusted Execution Environment (TEE)
+	  driver.
+
+if OPTEE
+menu "OP-TEE options"
+config OPTEE_USE_CMA
+	bool "Use CMA"
+	default n
+	select DMA_CMA
+	help
+	  Configures OP-TEE driver to use CMA for shared memory allocations.
+endmenu
+endif
drivers/tee/optee/Makefile new file +13 -0
new file mode 100644
index 0000000..096651d
@@ -0,0 +1,13 @@
+obj-$(CONFIG_OPTEE) += optee.o
+optee-objs += core.o
+optee-objs += call.o
+ifdef CONFIG_ARM
+plus_sec := $(call as-instr,.arch_extension sec,+sec)
+AFLAGS_smc_a32.o := -Wa,-march=armv7-a$(plus_sec)
+optee-objs += smc_a32.o
+endif
+ifdef CONFIG_ARM64
+optee-objs += smc_a64.o
+endif
+optee-objs += rpc.o
+optee-objs += supp.o
drivers/tee/optee/call.c new file +294 -0

294 lines not on this page · raw message

drivers/tee/optee/core.c new file +509 -0

509 lines not on this page · raw message

drivers/tee/optee/optee_private.h new file +138 -0

138 lines not on this page · raw message

drivers/tee/optee/optee_smc.h new file +510 -0

510 lines not on this page · raw message

drivers/tee/optee/rpc.c new file +282 -0

282 lines not on this page · raw message

drivers/tee/optee/smc_a32.S new file +30 -0
new file mode 100644
index 0000000..30fe0e5
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * 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.
+ *
+ */
+#include <linux/linkage.h>
+
+	.text
+	.balign 4
+	.code 32
+
+	/* void optee_smc(struct optee_smc_param *param); */
+	.globl	optee_smc
+ENTRY(optee_smc)
+	push	{r4-r8, lr}
+	mov	r8, r0
+	ldm	r8, {r0-r7}
+.arch_extension sec
+	smc	#0
+	stm	r8, {r0-r7}
+	pop	{r4-r8, pc}
+ENDPROC(optee_smc)
drivers/tee/optee/smc_a64.S new file +37 -0
new file mode 100644
index 0000000..458a138
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * 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 <linux/linkage.h>
+
+	.text
+
+#define SMC_PARAM_W0_OFFS	0
+#define SMC_PARAM_W2_OFFS	8
+#define SMC_PARAM_W4_OFFS	16
+#define SMC_PARAM_W6_OFFS	24
+
+	/* void optee_smc(struct smc_param *param); */
+	.globl	optee_smc
+ENTRY(optee_smc)
+	stp	x28, x30, [sp, #-16]!
+	mov	x28, x0
+	ldp	w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+	ldp	w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+	ldp	w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+	ldp	w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+	smc	#0
+	stp	w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+	stp	w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+	ldp	x28, x30, [sp], #16
+	ret
+ENDPROC(optee_smc)
drivers/tee/optee/supp.c new file +327 -0

327 lines not on this page · raw message

include/uapi/linux/optee_msg.h new file +368 -0

368 lines not on this page · raw message

Signature · 1 line
1.9.1