Skip to content

Commit 03a929f

Browse files
author
Alex Shi
committed
Merge remote-tracking branch 'origin/v4.4/topic/optee-lsk-mainline' into linux-linaro-lsk-v4.4
Conflicts: compatiable issues in arch/arm64/kernel/arm64ksyms.c arch/arm64/kernel/asm-offsets.c arch/arm64/kvm/hyp/fpsimd.S drivers/firmware/psci.c
2 parents 267aa95 + 6cffde3 commit 03a929f

30 files changed

Lines changed: 5174 additions & 27 deletions

Documentation/00-INDEX

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ sysrq.txt
435435
- info on the magic SysRq key.
436436
target/
437437
- directory with info on generating TCM v4 fabric .ko modules
438+
tee.txt
439+
- info on the TEE subsystem and drivers
438440
this_cpu_ops.txt
439441
- List rationale behind and the way to use this_cpu operations.
440442
thermal/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
OP-TEE Device Tree Bindings
2+
3+
OP-TEE is a piece of software using hardware features to provide a Trusted
4+
Execution Environment. The security can be provided with ARM TrustZone, but
5+
also by virtualization or a separate chip.
6+
7+
We're using "linaro" as the first part of the compatible property for
8+
the reference implementation maintained by Linaro.
9+
10+
* OP-TEE based on ARM TrustZone required properties:
11+
12+
- compatible : should contain "linaro,optee-tz"
13+
14+
- method : The method of calling the OP-TEE Trusted OS. Permitted
15+
values are:
16+
17+
"smc" : SMC #0, with the register assignments specified
18+
in drivers/tee/optee/optee_smc.h
19+
20+
"hvc" : HVC #0, with the register assignments specified
21+
in drivers/tee/optee/optee_smc.h
22+
23+
24+
25+
Example:
26+
firmware {
27+
optee {
28+
compatible = "linaro,optee-tz";
29+
method = "smc";
30+
};
31+
};

Documentation/devicetree/bindings/vendor-prefixes.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ lacie LaCie
127127
lantiq Lantiq Semiconductor
128128
lenovo Lenovo Group Ltd.
129129
lg LG Corporation
130+
licheepi Lichee Pi
131+
linaro Linaro Limited
130132
linux Linux-specific binding
131133
lsi LSI Corp. (LSI Logic)
132134
lltc Linear Technology Corporation

Documentation/ioctl/ioctl-number.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ Code Seq#(hex) Include File Comments
307307
0xA3 80-8F Port ACL in development:
308308
<mailto:tlewis@mindspring.com>
309309
0xA3 90-9F linux/dtlk.h
310+
0xA4 00-1F uapi/linux/tee.h Generic TEE subsystem
310311
0xAA 00-3F linux/uapi/linux/userfaultfd.h
311312
0xAB 00-1F linux/nbd.h
312313
0xAC 00-1F linux/raw.h

Documentation/tee.txt

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
TEE subsystem
2+
This document describes the TEE subsystem in Linux.
3+
4+
A TEE (Trusted Execution Environment) is a trusted OS running in some
5+
secure environment, for example, TrustZone on ARM CPUs, or a separate
6+
secure co-processor etc. A TEE driver handles the details needed to
7+
communicate with the TEE.
8+
9+
This subsystem deals with:
10+
11+
- Registration of TEE drivers
12+
13+
- Managing shared memory between Linux and the TEE
14+
15+
- Providing a generic API to the TEE
16+
17+
The TEE interface
18+
=================
19+
20+
include/uapi/linux/tee.h defines the generic interface to a TEE.
21+
22+
User space (the client) connects to the driver by opening /dev/tee[0-9]* or
23+
/dev/teepriv[0-9]*.
24+
25+
- TEE_IOC_SHM_ALLOC allocates shared memory and returns a file descriptor
26+
which user space can mmap. When user space doesn't need the file
27+
descriptor any more, it should be closed. When shared memory isn't needed
28+
any longer it should be unmapped with munmap() to allow the reuse of
29+
memory.
30+
31+
- TEE_IOC_VERSION lets user space know which TEE this driver handles and
32+
the its capabilities.
33+
34+
- TEE_IOC_OPEN_SESSION opens a new session to a Trusted Application.
35+
36+
- TEE_IOC_INVOKE invokes a function in a Trusted Application.
37+
38+
- TEE_IOC_CANCEL may cancel an ongoing TEE_IOC_OPEN_SESSION or TEE_IOC_INVOKE.
39+
40+
- TEE_IOC_CLOSE_SESSION closes a session to a Trusted Application.
41+
42+
There are two classes of clients, normal clients and supplicants. The latter is
43+
a helper process for the TEE to access resources in Linux, for example file
44+
system access. A normal client opens /dev/tee[0-9]* and a supplicant opens
45+
/dev/teepriv[0-9].
46+
47+
Much of the communication between clients and the TEE is opaque to the
48+
driver. The main job for the driver is to receive requests from the
49+
clients, forward them to the TEE and send back the results. In the case of
50+
supplicants the communication goes in the other direction, the TEE sends
51+
requests to the supplicant which then sends back the result.
52+
53+
OP-TEE driver
54+
=============
55+
56+
The OP-TEE driver handles OP-TEE [1] based TEEs. Currently it is only the ARM
57+
TrustZone based OP-TEE solution that is supported.
58+
59+
Lowest level of communication with OP-TEE builds on ARM SMC Calling
60+
Convention (SMCCC) [2], which is the foundation for OP-TEE's SMC interface
61+
[3] used internally by the driver. Stacked on top of that is OP-TEE Message
62+
Protocol [4].
63+
64+
OP-TEE SMC interface provides the basic functions required by SMCCC and some
65+
additional functions specific for OP-TEE. The most interesting functions are:
66+
67+
- OPTEE_SMC_FUNCID_CALLS_UID (part of SMCCC) returns the version information
68+
which is then returned by TEE_IOC_VERSION
69+
70+
- OPTEE_SMC_CALL_GET_OS_UUID returns the particular OP-TEE implementation, used
71+
to tell, for instance, a TrustZone OP-TEE apart from an OP-TEE running on a
72+
separate secure co-processor.
73+
74+
- OPTEE_SMC_CALL_WITH_ARG drives the OP-TEE message protocol
75+
76+
- OPTEE_SMC_GET_SHM_CONFIG lets the driver and OP-TEE agree on which memory
77+
range to used for shared memory between Linux and OP-TEE.
78+
79+
The GlobalPlatform TEE Client API [5] is implemented on top of the generic
80+
TEE API.
81+
82+
Picture of the relationship between the different components in the
83+
OP-TEE architecture.
84+
85+
User space Kernel Secure world
86+
~~~~~~~~~~ ~~~~~~ ~~~~~~~~~~~~
87+
+--------+ +-------------+
88+
| Client | | Trusted |
89+
+--------+ | Application |
90+
/\ +-------------+
91+
|| +----------+ /\
92+
|| |tee- | ||
93+
|| |supplicant| \/
94+
|| +----------+ +-------------+
95+
\/ /\ | TEE Internal|
96+
+-------+ || | API |
97+
+ TEE | || +--------+--------+ +-------------+
98+
| Client| || | TEE | OP-TEE | | OP-TEE |
99+
| API | \/ | subsys | driver | | Trusted OS |
100+
+-------+----------------+----+-------+----+-----------+-------------+
101+
| Generic TEE API | | OP-TEE MSG |
102+
| IOCTL (TEE_IOC_*) | | SMCCC (OPTEE_SMC_CALL_*) |
103+
+-----------------------------+ +------------------------------+
104+
105+
RPC (Remote Procedure Call) are requests from secure world to kernel driver
106+
or tee-supplicant. An RPC is identified by a special range of SMCCC return
107+
values from OPTEE_SMC_CALL_WITH_ARG. RPC messages which are intended for the
108+
kernel are handled by the kernel driver. Other RPC messages will be forwarded to
109+
tee-supplicant without further involvement of the driver, except switching
110+
shared memory buffer representation.
111+
112+
References:
113+
[1] https://github.com/OP-TEE/optee_os
114+
[2] http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
115+
[3] drivers/tee/optee/optee_smc.h
116+
[4] drivers/tee/optee/optee_msg.h
117+
[5] http://www.globalplatform.org/specificationsdevice.asp look for
118+
"TEE Client API Specification v1.0" and click download.

MAINTAINERS

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7939,6 +7939,11 @@ F: arch/*/oprofile/
79397939
F: drivers/oprofile/
79407940
F: include/linux/oprofile.h
79417941

7942+
OP-TEE DRIVER
7943+
M: Jens Wiklander <jens.wiklander@linaro.org>
7944+
S: Maintained
7945+
F: drivers/tee/optee/
7946+
79427947
ORACLE CLUSTER FILESYSTEM 2 (OCFS2)
79437948
M: Mark Fasheh <mfasheh@suse.com>
79447949
M: Joel Becker <jlbec@evilplan.org>
@@ -9366,6 +9371,14 @@ F: drivers/hwtracing/stm/
93669371
F: include/linux/stm.h
93679372
F: include/uapi/linux/stm.h
93689373

9374+
TEE SUBSYSTEM
9375+
M: Jens Wiklander <jens.wiklander@linaro.org>
9376+
S: Maintained
9377+
F: include/linux/tee_drv.h
9378+
F: include/uapi/linux/tee.h
9379+
F: drivers/tee/
9380+
F: Documentation/tee.txt
9381+
93699382
THUNDERBOLT DRIVER
93709383
M: Andreas Noever <andreas.noever@gmail.com>
93719384
S: Maintained

drivers/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,6 @@ source "drivers/hwtracing/intel_th/Kconfig"
198198

199199
source "drivers/fpga/Kconfig"
200200

201+
source "drivers/tee/Kconfig"
202+
201203
endmenu

drivers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,4 @@ obj-$(CONFIG_STM) += hwtracing/stm/
173173
obj-$(CONFIG_ANDROID) += android/
174174
obj-$(CONFIG_NVMEM) += nvmem/
175175
obj-$(CONFIG_FPGA) += fpga/
176+
obj-$(CONFIG_TEE) += tee/

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,11 +3475,6 @@ static inline uint32_t i915_vgacntrl_reg(struct drm_device *dev)
34753475
return VGACNTRL;
34763476
}
34773477

3478-
static inline void __user *to_user_ptr(u64 address)
3479-
{
3480-
return (void __user *)(uintptr_t)address;
3481-
}
3482-
34833478
static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
34843479
{
34853480
unsigned long j = msecs_to_jiffies(m);

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ i915_gem_phys_pwrite(struct drm_i915_gem_object *obj,
324324
{
325325
struct drm_device *dev = obj->base.dev;
326326
void *vaddr = obj->phys_handle->vaddr + args->offset;
327-
char __user *user_data = to_user_ptr(args->data_ptr);
327+
char __user *user_data = u64_to_user_ptr(args->data_ptr);
328328
int ret = 0;
329329

330330
/* We manually control the domain here and pretend that it
@@ -605,7 +605,7 @@ i915_gem_shmem_pread(struct drm_device *dev,
605605
int needs_clflush = 0;
606606
struct sg_page_iter sg_iter;
607607

608-
user_data = to_user_ptr(args->data_ptr);
608+
user_data = u64_to_user_ptr(args->data_ptr);
609609
remain = args->size;
610610

611611
obj_do_bit17_swizzling = i915_gem_object_needs_bit17_swizzle(obj);
@@ -692,7 +692,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
692692
return 0;
693693

694694
if (!access_ok(VERIFY_WRITE,
695-
to_user_ptr(args->data_ptr),
695+
u64_to_user_ptr(args->data_ptr),
696696
args->size))
697697
return -EFAULT;
698698

@@ -783,7 +783,7 @@ i915_gem_gtt_pwrite_fast(struct drm_device *dev,
783783
if (ret)
784784
goto out_unpin;
785785

786-
user_data = to_user_ptr(args->data_ptr);
786+
user_data = u64_to_user_ptr(args->data_ptr);
787787
remain = args->size;
788788

789789
offset = i915_gem_obj_ggtt_offset(obj) + args->offset;
@@ -907,7 +907,7 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
907907
int needs_clflush_before = 0;
908908
struct sg_page_iter sg_iter;
909909

910-
user_data = to_user_ptr(args->data_ptr);
910+
user_data = u64_to_user_ptr(args->data_ptr);
911911
remain = args->size;
912912

913913
obj_do_bit17_swizzling = i915_gem_object_needs_bit17_swizzle(obj);
@@ -1036,12 +1036,12 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
10361036
return 0;
10371037

10381038
if (!access_ok(VERIFY_READ,
1039-
to_user_ptr(args->data_ptr),
1039+
u64_to_user_ptr(args->data_ptr),
10401040
args->size))
10411041
return -EFAULT;
10421042

10431043
if (likely(!i915.prefault_disable)) {
1044-
ret = fault_in_multipages_readable(to_user_ptr(args->data_ptr),
1044+
ret = fault_in_multipages_readable(u64_to_user_ptr(args->data_ptr),
10451045
args->size);
10461046
if (ret)
10471047
return -EFAULT;

0 commit comments

Comments
 (0)