Skip to content

Commit fa53082

Browse files
author
Pascal Brand
committed
Internal API extension on Cache Operations
Following extensions are introduced: - TEE_CacheClean() - TEE_CacheFlush() - TEE_CacheInvalidate() Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Tested-by: Pascal Brand <pascal.brand@linaro.org> (STM platform) Signed-off-by: Pascal Brand <pascal.brand@st.com>
1 parent db5f4ae commit fa53082

File tree

14 files changed

+170
-8
lines changed

14 files changed

+170
-8
lines changed

core/arch/arm32/kernel/tee_ta_manager.c

+52-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
#include <kernel/tee_kta_trace.h>
6262
#include <kernel/trace_ta.h>
6363

64-
65-
/* Use this invalid ID for a static TA, since
64+
/*
65+
* Use this invalid ID for a static TA, since
6666
* session is not needed for calling static TA.
6767
*/
6868
#define TEE_SESSION_ID_STATIC_TA 0xFFFFFFFF
@@ -698,7 +698,7 @@ static TEE_Result tee_ta_param_pa2va(struct tee_ta_session *sess,
698698
case TEE_PARAM_TYPE_MEMREF_OUTPUT:
699699
case TEE_PARAM_TYPE_MEMREF_INOUT:
700700
if (core_pa2va
701-
((uint32_t) param->params[n].memref.buffer, &va))
701+
((uint32_t)param->params[n].memref.buffer, &va))
702702
return TEE_ERROR_BAD_PARAMETERS;
703703
param->params[n].memref.buffer = va;
704704
break;
@@ -711,7 +711,6 @@ static TEE_Result tee_ta_param_pa2va(struct tee_ta_session *sess,
711711
return TEE_SUCCESS;
712712
}
713713

714-
715714
static void tee_ta_set_invoke_timeout(struct tee_ta_session *sess,
716715
uint32_t cancel_req_to)
717716
{
@@ -1542,6 +1541,55 @@ TEE_Result tee_ta_verify_session_pointer(struct tee_ta_session *sess,
15421541
return TEE_ERROR_BAD_PARAMETERS;
15431542
}
15441543

1544+
/*
1545+
* tee_uta_cache_operation - dynamic cache clean/inval request from a TA
1546+
*/
1547+
#ifdef CFG_CACHE_API
1548+
TEE_Result tee_uta_cache_operation(struct tee_ta_session *sess,
1549+
enum utee_cache_operation op,
1550+
void *va, size_t len)
1551+
{
1552+
TEE_Result ret;
1553+
paddr_t pa = 0;
1554+
int l1op, l2op;
1555+
1556+
if ((sess->ctx->flags & TA_FLAG_CACHE_MAINTENANCE) == 0)
1557+
return TEE_ERROR_NOT_SUPPORTED;
1558+
1559+
ret = tee_mmu_check_access_rights(sess->ctx,
1560+
TEE_MEMORY_ACCESS_WRITE, (tee_uaddr_t)va, len);
1561+
if (ret != TEE_SUCCESS)
1562+
return TEE_ERROR_ACCESS_DENIED;
1563+
1564+
ret = tee_mmu_user_va2pa(sess->ctx, va, &pa);
1565+
if (ret != TEE_SUCCESS)
1566+
return TEE_ERROR_ACCESS_DENIED;
1567+
1568+
switch (op) {
1569+
case TEE_CACHEFLUSH:
1570+
l1op = DCACHE_AREA_CLEAN_INV;
1571+
l2op = L2CACHE_AREA_CLEAN_INV;
1572+
break;
1573+
case TEE_CACHECLEAN:
1574+
l1op = DCACHE_AREA_CLEAN;
1575+
l2op = L2CACHE_AREA_CLEAN;
1576+
break;
1577+
case TEE_CACHEINVALIDATE:
1578+
l1op = DCACHE_INVALIDATE;
1579+
l2op = L2CACHE_INVALIDATE;
1580+
break;
1581+
default:
1582+
return TEE_ERROR_NOT_SUPPORTED;
1583+
}
1584+
1585+
ret = cache_maintenance_l1(l1op, va, len);
1586+
if (ret != TEE_SUCCESS)
1587+
return ret;
1588+
1589+
return cache_maintenance_l2(l2op, pa, len);
1590+
}
1591+
#endif
1592+
15451593
/*
15461594
* dump_state - Display TA state as an error log.
15471595
*/

core/arch/arm32/plat-stm/conf.mk

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ core-platform-subdirs += \
1414
libutil_with_isoc := y
1515
WITH_PL310 := y
1616
WITH_SECURE_TIME_SOURCE_REE := y
17+
CFG_CACHE_API := y
1718

1819
include mk/config.mk
1920
include $(platform-dir)/system_config.in

core/arch/arm32/tee/arch_svc.c

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ static const tee_svc_func tee_svc_syscall_table[] = {
112112
(tee_svc_func)tee_svc_se_channel_get_select_resp,
113113
(tee_svc_func)tee_svc_se_channel_transmit,
114114
(tee_svc_func)tee_svc_se_channel_close,
115+
(tee_svc_func)tee_svc_cache_operation,
115116
};
116117

117118
void tee_svc_handler(struct thread_svc_regs *regs)

core/include/kernel/tee_misc.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ uint32_t tee_hs2b(uint8_t *hs, uint8_t *b, uint32_t hslen, uint32_t blen);
5454
*
5555
* core_is_buffer_inside() - return true if buffer is inside memory area
5656
* core_is_buffer_outside() - return true if buffer is outside area
57-
* core_is_buffer_over() - return true if buffer overlaps area
58-
57+
* core_is_buffer_intersect() - return true if buffer overlaps area
58+
*
5959
* Warning: core_is_buffer_inside(x,x,x,x)==false does NOT mean
6060
* core_is_buffer_outside(x,x,x,x)==true.
6161
*

core/include/kernel/tee_ta_manager.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "tee_ta.h"
3636
#include <kernel/kta_types.h>
3737
#include "tee_ta_manager_unpg.h"
38+
#include "utee_types.h"
3839

3940
/*-----------------------------------------------------------------------------
4041
* Initializes virtual memory management by reserving virtual memory for
@@ -101,8 +102,13 @@ TEE_Result tee_ta_verify_session_pointer(struct tee_ta_session *sess,
101102
*open_sessions);
102103

103104
int tee_ta_set_trace_level(int level);
104-
105105
void tee_ta_dump_current(void);
106106
void tee_ta_dump_all(void);
107107

108+
#ifdef CFG_CACHE_API
109+
TEE_Result tee_uta_cache_operation(struct tee_ta_session *s,
110+
enum utee_cache_operation op,
111+
void *va, size_t len);
112+
#endif
113+
108114
#endif

core/include/tee/tee_svc.h

+7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ TEE_Result tee_svc_wait(uint32_t timeout);
8787
TEE_Result tee_svc_get_time(enum utee_time_category cat, TEE_Time *time);
8888
TEE_Result tee_svc_set_ta_time(const TEE_Time *time);
8989

90+
#ifdef CFG_CACHE_API
91+
TEE_Result tee_svc_cache_operation(void *va, size_t len,
92+
enum utee_cache_operation op);
93+
#else
94+
#define tee_svc_cache_operation tee_svc_not_supported
95+
#endif
96+
9097
void tee_svc_trace_syscall(int num);
9198

9299

core/tee/tee_svc.c

+18
Original file line numberDiff line numberDiff line change
@@ -825,3 +825,21 @@ TEE_Result tee_svc_set_ta_time(const TEE_Time *mytime)
825825

826826
return tee_time_set_ta_time((const void *)&s->ctx->head->uuid, &t);
827827
}
828+
829+
#ifdef CFG_CACHE_API
830+
TEE_Result tee_svc_cache_operation(void *va, size_t len,
831+
enum utee_cache_operation op)
832+
{
833+
TEE_Result res;
834+
struct tee_ta_session *s = NULL;
835+
836+
res = tee_ta_get_current_session(&s);
837+
if (res != TEE_SUCCESS)
838+
return res;
839+
840+
if ((s->ctx->flags & TA_FLAG_CACHE_MAINTENANCE) == 0)
841+
return TEE_ERROR_NOT_SUPPORTED;
842+
843+
return tee_uta_cache_operation(s, op, va, len);
844+
}
845+
#endif
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# General Extensions to the GlobalPlatform TEE Internal API
2+
3+
This document describes the OP-TEE extensions introduced with respect to the GlobalPlatform TEE API Specifications v1.0.
4+
5+
Specific extensions documentation are part of:
6+
* Cryptographic Extensions
7+
* [Concatenation Key Derivation](crypto_concat_kdf.md)
8+
* [HMAC Key Derivation](crypto_hkdf.md)
9+
* [Public-Key Key Derivation](crypto_pbkdf2.md)
10+
11+
12+
# Cache Maintenance Support
13+
Following functions have been introduced in order to operate with cache:
14+
15+
TEE_Result TEE_CacheClean(char *buf, size_t len);
16+
TEE_Result TEE_CacheFlush(char *buf, size_t len);
17+
TEE_Result TEE_CacheInvalidate(char *buf, size_t len);
18+
19+
These functions are available to any Trusted Application defined with the flag TA_FLAG_CACHE_MAINTENANCE sets on. When not set, each function returns the error code TEE_ERROR_NOT_SUPPORTED.
20+
21+
Within these extensions, a Trusted Application is able to operate on the data cache, with the following specification:
22+
23+
Function | Description
24+
:---------------------|:----------
25+
TEE_CacheClean() | Write back to memory any dirty data cache lines. The line is marked as not dirty. The valid bit is unchanged
26+
TEE_CacheFlush() | Purges any valid data cache lines. Any dirty cache lines are first written back to memory, then the cache line is invalidated.
27+
TEE_CacheInvalidate() | Invalidate any valid data cache lines. Any dirty line are not written back to memory.
28+
29+
In the following 2 cases, the error code TEE_ERROR_ACCESS_DENIED is returned:
30+
* the memory range has not the write access, that is TEE_MEMORY_ACCESS_WRITE is not set.
31+
* the memory is not a User Space memory

lib/libutee/arch/arm32/utee_syscalls_asm.S

+2
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,5 @@
216216

217217
UTEE_SYSCALL utee_se_channel_close, \
218218
TEE_SCN_SE_CHANNEL_CLOSE, 1
219+
220+
UTEE_SYSCALL utee_cache_operation, TEE_SCN_CACHE_OPERATION, 3

lib/libutee/include/tee_internal_api_extensions.h

+18
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
/* trace support */
3232
#include <trace.h>
3333
#include <stdio.h>
34+
#include <tee_api_types.h>
3435

3536
/*
3637
* User mem module
@@ -41,4 +42,21 @@ size_t tee_user_mem_check_heap(void);
4142
/* Hint implementation defines */
4243
#define TEE_USER_MEM_HINT_NO_FILL_ZERO 0x80000000
4344

45+
/*
46+
* Cache maintenance support (TA requires the CACHE_MAINTENANCE property)
47+
*
48+
* TEE_CacheClean() Write back to memory any dirty data cache lines. The line
49+
* is marked as not dirty. The valid bit is unchanged.
50+
*
51+
* TEE_CacheFlush() Purges any valid data cache lines. Any dirty cache lines
52+
* are first written back to memory, then the cache line is
53+
* invalidated.
54+
*
55+
* TEE_CacheInvalidate() Invalidate any valid data cache lines. Any dirty line
56+
* are not written back to memory.
57+
*/
58+
TEE_Result TEE_CacheClean(char *buf, size_t len);
59+
TEE_Result TEE_CacheFlush(char *buf, size_t len);
60+
TEE_Result TEE_CacheInvalidate(char *buf, size_t len);
61+
4462
#endif

lib/libutee/include/tee_syscall_numbers.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@
9999
#define TEE_SCN_SE_CHANNEL_GET_SELECT_RESP 68
100100
#define TEE_SCN_SE_CHANNEL_TRANSMIT 69
101101
#define TEE_SCN_SE_CHANNEL_CLOSE 70
102+
#define TEE_SCN_CACHE_OPERATION 71
102103

103-
#define TEE_SCN_MAX 70
104+
#define TEE_SCN_MAX 71
104105

105106
/* Maximum number of allowed arguments for a syscall */
106107
#define TEE_SVC_MAX_ARGS 10

lib/libutee/include/utee_syscalls.h

+3
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,7 @@ TEE_Result utee_se_channel_transmit(TEE_SEChannelHandle c,
229229

230230
TEE_Result utee_se_channel_close(TEE_SEChannelHandle c);
231231

232+
TEE_Result utee_cache_operation(void *va, size_t l,
233+
enum utee_cache_operation op);
234+
232235
#endif /* UTEE_SYSCALLS_H */

lib/libutee/include/utee_types.h

+11
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,15 @@ enum utee_time_category {
4444
UTEE_TIME_CAT_REE
4545
};
4646

47+
/*
48+
* Cache operation types.
49+
* Used when extensions TEE_CacheClean() / TEE_CacheFlush() /
50+
* TEE_CacheInvalidate() are used
51+
*/
52+
enum utee_cache_operation {
53+
TEE_CACHECLEAN = 0,
54+
TEE_CACHEFLUSH,
55+
TEE_CACHEINVALIDATE,
56+
};
57+
4758
#endif /* UTEE_TYPES_H */

lib/libutee/tee_api.c

+15
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,18 @@ void TEE_Free(void *buffer)
221221
{
222222
tee_user_mem_free(buffer);
223223
}
224+
225+
/* Cache maintenance support (TA requires the CACHE_MAINTENANCE property) */
226+
TEE_Result TEE_CacheClean(char *buf, size_t len)
227+
{
228+
return utee_cache_operation(buf, len, TEE_CACHECLEAN);
229+
}
230+
TEE_Result TEE_CacheFlush(char *buf, size_t len)
231+
{
232+
return utee_cache_operation(buf, len, TEE_CACHEFLUSH);
233+
}
234+
235+
TEE_Result TEE_CacheInvalidate(char *buf, size_t len)
236+
{
237+
return utee_cache_operation(buf, len, TEE_CACHEINVALIDATE);
238+
}

0 commit comments

Comments
 (0)