Commit graph android_kernel_sony_sdm845/drivers/tee/optee
Message SHA1
UPSTREAM: optee: add writeback to valid memory type
Only in smp systems the cache policy is setup as write alloc, in
single cpu systems the cache policy is set as writeback and it is
normal memory, so, it should pass the is_normal_memory check in the
share memory registration.

Add the right condition to make it work in no smp systems.

Fixes: cdbcf83d29c1 ("tee: optee: check type of registered shared memory")
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 853735e404244f5496cdb6188c5ed9a0f9627ee6)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I51048c263982850c46b639d12b1bf25604d5dd15

Rui Miguel Silva   authored and   Greg Kroah-Hartman   commited 2022-02-21 16:30:33 +01:00
6e3cd2a7be
BACKPORT: tee: optee: check type of registered shared memory
Checks the memory type of the pages to be registered as shared memory.
Only normal cached memory is allowed.

Change-Id: I319740ef448e7d7ce31efd2b5456972da192fce3
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit cdbcf83d29c1bf2aaa65260e74beaac1bcdc231c)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Jens Wiklander   authored and   Victor Chong   commited 2018-02-21 15:40:43 +00:00
61d36598e6
BACKPORT: tee: add start argument to shm_register callback
Adds a start argument to the shm_register callback to allow the callback
to check memory type of the passed pages.

Change-Id: Ic6062db0cfc7485adae4df949e87577f9d13e4d5
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 95ffe4ca43877eea176d7e95aa0d38bbdc3d2903)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Jens Wiklander   authored and   Victor Chong   commited 2018-02-21 15:40:43 +00:00
ce42b2400a
BACKPORT: tee: optee: fix header dependencies
The optee driver includes the header files in an unusual order,
with asm/pgtable.h before the linux/*.h headers. For some reason
this seems to trigger a build failure:

drivers/tee/optee/call.c: In function 'optee_fill_pages_list':
include/asm-generic/memory_model.h:64:14: error: implicit declaration of function 'page_to_section'; did you mean '__nr_to_section'? [-Werror=implicit-function-declaration]
  int __sec = page_to_section(__pg);   \
drivers/tee/optee/call.c:494:15: note: in expansion of macro 'page_to_phys'
  optee_page = page_to_phys(*pages) +

Let's just include linux/mm.h, which will then get the other
header implicitly.

Change-Id: I89668d35f8a9a8e27e77045e1f91934bb3d8cded
Fixes: 3bb48ba5cd60 ("tee: optee: add page list manipulation functions")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
(cherry picked from commit f681e08f671a8e68b085ba66190b8661deab4d85)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Arnd Bergmann   authored and   Victor Chong   commited 2018-02-21 15:40:43 +00:00
451b1b7584
BACKPORT: tee: optee: enable dynamic SHM support
Previous patches added various features that are needed for dynamic SHM.
Dynamic SHM allows Normal World to share any buffers with OP-TEE.
While original design suggested to use pre-allocated region (usually of
1M to 2M of size), this new approach allows to use all non-secure RAM for
command buffers, RPC allocations and TA parameters.

This patch checks capability OPTEE_SMC_SEC_CAP_DYNAMIC_SHM. If it was set
by OP-TEE, then kernel part of OP-TEE will use kernel page allocator
to allocate command buffers. Also it will set TEE_GEN_CAP_REG_MEM
capability to tell userspace that it supports shared memory registration.

Change-Id: I02b0a57e8c16d1905883b35511decb7426e76960
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit f58e236c9d665ad0af99c908de4a9b6f07e74dda)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Volodymyr Babchuk   authored and   Victor Chong   commited 2018-02-21 15:40:43 +00:00
1e046f0c0d
BACKPORT: tee: optee: add optee-specific shared pool implementation
This is simple pool that uses kernel page allocator. This pool can be
used in case OP-TEE supports dynamic shared memory.

Change-Id: Idd0b512ef577b38f61dabca60b86becf09a746cc
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit abd135ba215c05ca84f9809e6047db25fc28b835)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Volodymyr Babchuk   authored and   Victor Chong   commited 2018-02-21 15:40:43 +00:00
8d919d7106
BACKPORT: tee: optee: store OP-TEE capabilities in private data
Those capabilities will be used in subsequent patches.

Change-Id: I296269714687d346c7beaf30fa400d74c81e717a
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit d885cc5e0759fc19badadddb60a64344b551469b)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Volodymyr Babchuk   authored and   Victor Chong   commited 2018-02-21 15:40:43 +00:00
8fecf08ca8
BACKPORT: tee: optee: add registered buffers handling into RPC calls
With latest changes to OP-TEE we can use any buffers as a shared memory.
Thus, it is possible for supplicant to provide part of own memory
when OP-TEE asks to allocate a shared buffer.

This patch adds support for such feature into RPC handling code.
Now when OP-TEE asks supplicant to allocate shared buffer, supplicant
can use TEE_IOC_SHM_REGISTER to provide such buffer. RPC handler is
aware of this, so it will pass list of allocated pages to OP-TEE.

Change-Id: If7b7812ab4255ed3c1915ae16eafd5556947b936
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
[jw: fix parenthesis alignment in free_pages_list()]
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 53a107c812de3dd74707458aa751eb457718ff9e)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Volodymyr Babchuk   authored and   Victor Chong   commited 2018-02-21 15:40:43 +00:00
ca453513d2
BACKPORT: tee: optee: add registered shared parameters handling
Now, when client applications can register own shared buffers in OP-TEE,
we need to extend ABI for parameter passing to/from OP-TEE.

So, if OP-TEE core detects that parameter belongs to registered shared
memory, it will use corresponding parameter attribute.

Change-Id: I52b6b3a0092aac238b232b6d24668bbe3f3015e2
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 64cf9d8a672e770fed85a65b5c6767fc0aa1473b)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Volodymyr Babchuk   authored and   Victor Chong   commited 2018-02-21 15:40:42 +00:00
7ec482be02
BACKPORT: tee: optee: add shared buffer registration functions
This change adds ops for shm_(un)register functions in tee interface.
Client application can use these functions to (un)register an own shared
buffer in OP-TEE address space. This allows zero copy data sharing between
Normal and Secure Worlds.

Please note that while those functions were added to optee code,
it does not report to userspace that those functions are available.
OP-TEE code does not set TEE_GEN_CAP_REG_MEM flag. This flag will be
enabled only after all other features of dynamic shared memory will be
implemented in subsequent patches. Of course user can ignore presence of
TEE_GEN_CAP_REG_MEM flag and try do call those functions. This is okay,
driver will register shared buffer in OP-TEE, but any attempts to use
this shared buffer will fail.

Change-Id: I918fd93ff2a5e8a371f6e7fd81f45bbfaed69315
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 06ca79179c4e00efe53cfe43456f1586f944f04f)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Volodymyr Babchuk   authored and   Victor Chong   commited 2018-02-21 15:40:42 +00:00
88be5b8bb8
BACKPORT: tee: optee: add page list manipulation functions
These functions will be used to pass information about shared
buffers to OP-TEE. ABI between Linux and OP-TEE is defined
in optee_msg.h and optee_smc.h.

optee_msg.h defines OPTEE_MSG_ATTR_NONCONTIG attribute
for shared memory references and describes how such references
should be passed. Note that it uses 64-bit page addresses even
on 32 bit systems. This is done to support LPAE and to unify
interface.

Change-Id: I9285315d48979e75c54021163f3e8c7a2772db55
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
[jw: replacing uint64_t with u64 in optee_fill_pages_list()]
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 3bb48ba5cd60f9685aa8f1ccd9b14a72e237c13f)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Volodymyr Babchuk   authored and   Victor Chong   commited 2018-02-21 15:40:42 +00:00
9cba6e753a
BACKPORT: tee: optee: Update protocol definitions
There were changes in REE<->OP-TEE ABI recently.
Now ABI allows us to pass non-contiguous memory buffers as list of
pages to OP-TEE. This can be achieved by using new parameter attribute
OPTEE_MSG_ATTR_NONCONTIG.

OP-TEE also is able to use all non-secure RAM for shared buffers. This
new capability is enabled with OPTEE_SMC_SEC_CAP_DYNAMIC_SHM flag.

This patch adds necessary definitions to the protocol definition files at
Linux side.

Change-Id: I9a1dbe642b4e6bf5544a579f80abb940b59723ab
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit de5c6dfc43daa59feb824505f80fe4591f8f8f85)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Volodymyr Babchuk   authored and   Victor Chong   commited 2018-02-21 15:40:42 +00:00
f442bb9bb1
BACKPORT: optee: support asynchronous supplicant requests
Adds support for asynchronous supplicant requests, meaning that the
supplicant can process several requests in parallel or block in a
request for some time.

Change-Id: Ifa77c329d33f6884fc7a64b3594be2b33def492c
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Tested-by: Etienne Carriere <etienne.carriere@linaro.org> (b2260 pager=y/n)
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 1647a5ac175490d7dac2e74532e85b6197fc74e9)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Jens Wiklander   authored and   Victor Chong   commited 2018-02-21 15:40:42 +00:00
ad675fa04a
BACKPORT: tee: add TEE_IOCTL_PARAM_ATTR_META
Adds TEE_IOCTL_PARAM_ATTR_META which can be used to indicate meta
parameters when communicating with user space. These meta parameters can
be used by supplicant support multiple parallel requests at a time.

Change-Id: Ie866c6119b8125c08b892b7a1a1929832b2f162c
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit f2aa97240c84b8f258710e297ba60048bd9c153e)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Jens Wiklander   authored and   Victor Chong   commited 2018-02-21 15:40:42 +00:00
67f68799f4
BACKPORT: optee: fix invalid of_node_put() in optee_driver_init()
The first node supplied to of_find_matching_node() has its reference
counter decreased as part of call to that function. In optee_driver_init()
after calling of_find_matching_node() it's invalid to call of_node_put() on
the supplied node again.

So remove the invalid call to of_node_put().

Change-Id: I09d0dafa710a9ef7f3550e751b06b10197c9701a
Reported-by: Alex Shi <alex.shi@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit f044113113dd95ba73916bde10e804d3cdfa2662)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Jens Wiklander   authored and   Victor Chong   commited 2018-01-12 16:44:40 +00:00
8e170a589b
BACKPORT: tee: optee: sync with new naming of interrupts
In the latest changes of optee_os, the interrupts' names are
changed to "native" and "foreign" interrupts.

Change-Id: I5d1c2e05e9556b4805e24ac3aca1486dcdb5414b
Signed-off-by: David Wang <david.wang@arm.com>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 39e6519a3f135b143dee4d4fb5ac0438e75454e2)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

David Wang   authored and   Victor Chong   commited 2018-01-12 16:44:40 +00:00
4d04685019
BACKPORT: tee: optee: interruptible RPC sleep
Prior to this patch RPC sleep was uninterruptible since msleep() is
uninterruptible. Change to use msleep_interruptible() instead.

Change-Id: I34b7ff2fe1aaac1ca41ee595bd49dd451d99b9d7
Signed-off-by: Tiger Yu <tigeryu99@hotmail.com>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit a9980e947ec97297e03d2332d6beff06f5131a98)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

tiger-yu99   authored and   Victor Chong   commited 2018-01-12 16:44:40 +00:00
a75ed92172
BACKPORT: tee: optee: add const to tee_driver_ops and tee_desc structures
Add const to tee_desc structures as they are only passed as an argument
to the function tee_device_alloc. This argument is of type const, so
declare these structures as const too.
Add const to tee_driver_ops structures as they are only stored in the
ops field of a tee_desc structure. This field is of type const, so
declare these structure types as const.

Change-Id: I9ffb39b85321a45fff5dae71915c4d851f4cc7ac
Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 96e72ddeec4546fda0e194298c2ee39e394a3ab7)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Bhumika Goyal   authored and   Victor Chong   commited 2018-01-12 16:44:40 +00:00
7b22a54e30
BACKPORT: tee: optee: fix uninitialized symbol 'parg'
Fixes the static checker warning in optee_release().
error: uninitialized symbol 'parg'.

Change-Id: I7b183f3b128b3ec6f2154195901a20bd6cf0a838
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit efb14036bd7f8914f721e1e82891d4ba617cc784)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Jens Wiklander   authored and   Victor Chong   commited 2018-01-12 16:44:40 +00:00
14edc414ca
BACKPORT: tee: add OP-TEE driver
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
* Probes OP-TEE version using SMCs
* Accepts requests on privileged and unprivileged device
* Uses OPTEE message protocol version 2 to communicate with secure world

Change-Id: Id9fc5fda759496a28855c6968fe09f4f4767a63d
Acked-by: Andreas Dannenberg <dannenberg@ti.com>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey)
Tested-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> (RCAR H3)
Tested-by: Scott Branden <scott.branden@broadcom.com>
Reviewed-by: Javier González <javier@javigon.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
(cherry picked from commit 4fb0a5eb364d239722e745c02aef0dbd4e0f1ad2)
Signed-off-by: Victor Chong <victor.chong@linaro.org>

Jens Wiklander   authored and   Victor Chong   commited 2017-12-05 14:00:44 +00:00
18ebb2fac7