From 0c87e75a8efc269f29c851e369e7f8698a87a41d Mon Sep 17 00:00:00 2001 From: Zhang Zhijie Date: Tue, 20 Oct 2015 14:38:43 +0800 Subject: [PATCH] OP-TEE: build optee_linuxdriver into kernel Change-Id: I4cacc3b0670643ab02af592549de988f11c378df Signed-off-by: Zhang Zhijie --- security/Kconfig | 1 + security/Makefile | 1 + security/optee_linuxdriver/armtz/Makefile | 4 +- security/optee_linuxdriver/armtz/tee_tz_drv.c | 59 ++++++++++++++++++- security/optee_linuxdriver/core/Makefile | 4 +- security/optee_linuxdriver/core/tee_core.c | 9 +-- security/optee_linuxdriver/core/tee_session.c | 1 + security/optee_linuxdriver/core/tee_shm.c | 2 +- 8 files changed, 73 insertions(+), 8 deletions(-) diff --git a/security/Kconfig b/security/Kconfig index 20a4e219f59b..c6ec32ab5612 100644 --- a/security/Kconfig +++ b/security/Kconfig @@ -123,6 +123,7 @@ source security/tomoyo/Kconfig source security/apparmor/Kconfig source security/yama/Kconfig source security/tlk_driver/Kconfig +source security/optee_linuxdriver/Kconfig source security/integrity/Kconfig diff --git a/security/Makefile b/security/Makefile index fa723812ad85..39dbfa587995 100644 --- a/security/Makefile +++ b/security/Makefile @@ -30,3 +30,4 @@ subdir-$(CONFIG_INTEGRITY) += integrity obj-$(CONFIG_INTEGRITY) += integrity/built-in.o obj-y += tlk_driver/ +obj-y += optee_linuxdriver/ diff --git a/security/optee_linuxdriver/armtz/Makefile b/security/optee_linuxdriver/armtz/Makefile index af2b10cfd8eb..5e6987ba62df 100644 --- a/security/optee_linuxdriver/armtz/Makefile +++ b/security/optee_linuxdriver/armtz/Makefile @@ -7,6 +7,8 @@ CFG_TEE_DRV_DEBUGFS?=0 CFG_TEE_CORE_LOG_LEVEL?=2 CFG_TEE_TA_LOG_LEVEL?=2 +M ?= security/optee_linuxdriver + ccflags-y+=-Werror ccflags-y+=-I$(M)/include/arm_common ccflags-y+=-I$(M)/include/linux @@ -17,7 +19,7 @@ ccflags-y+=-DCFG_TEE_DRV_DEBUGFS=${CFG_TEE_DRV_DEBUGFS} ccflags-y+=-DCFG_TEE_CORE_LOG_LEVEL=${CFG_TEE_CORE_LOG_LEVEL} ccflags-y+=-DCFG_TEE_TA_LOG_LEVEL=${CFG_TEE_TA_LOG_LEVEL} -obj-m += optee_armtz.o +obj-y += optee_armtz.o optee_armtz-objs:= \ tee_tz_drv.o \ diff --git a/security/optee_linuxdriver/armtz/tee_tz_drv.c b/security/optee_linuxdriver/armtz/tee_tz_drv.c index 6541b02e646f..70e7c5bb1198 100644 --- a/security/optee_linuxdriver/armtz/tee_tz_drv.c +++ b/security/optee_linuxdriver/armtz/tee_tz_drv.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -36,6 +37,8 @@ #include "tee_tz_priv.h" #include "handle.h" +#define SWITCH_CPU0_DEBUG + #define _TEE_TZ_NAME "armtz" #define DEV (ptee->tee->dev) @@ -64,6 +67,40 @@ static struct handle_db shm_handle_db = HANDLE_DB_INITIALIZER; /******************************************************************* * Calling TEE *******************************************************************/ +#ifdef CONFIG_SMP +static void switch_cpumask_to_cpu0(cpumask_t *saved_cpu_mask) +{ + long ret; + cpumask_t local_cpu_mask = CPU_MASK_NONE; + pr_info("switch_cpumask_to_cpu cpu0\n"); + cpu_set(0, local_cpu_mask); + cpumask_copy(saved_cpu_mask, tsk_cpus_allowed(current)); + ret = sched_setaffinity(0, &local_cpu_mask); + if (ret) + pr_err("sched_setaffinity #1 -> 0x%lX", ret); +} + +static void restore_cpumask(cpumask_t *saved_cpu_mask) +{ + long ret; + pr_info("restore_cpumask cpu0\n"); + ret = sched_setaffinity(0, saved_cpu_mask); + if (ret) + pr_err("sched_setaffinity #2 -> 0x%lX", ret); +} +#else +static inline void switch_cpumask_to_cpu0(void) {}; +static inline void restore_cpumask(void) {}; +#endif +static int tee_smc_call_switchcpu0(struct smc_param *param) +{ + cpumask_t saved_cpu_mask; + + switch_cpumask_to_cpu0(&saved_cpu_mask); + tee_smc_call(param); + restore_cpumask(&saved_cpu_mask); + return 0; +} static void e_lock_teez(struct tee_tz *ptee) { @@ -407,7 +444,11 @@ static void call_tee(struct tee_tz *ptee, while (true) { param.a0 = funcid; +#ifdef SWITCH_CPU0_DEBUG + tee_smc_call_switchcpu0(¶m); +#else tee_smc_call(¶m); +#endif ret = param.a0; if (ret == TEESMC_RETURN_EBUSY) { @@ -988,7 +1029,11 @@ static int register_outercache_mutex(struct tee_tz *ptee, bool reg) memset(¶m, 0, sizeof(param)); param.a0 = TEESMC32_ST_FASTCALL_L2CC_MUTEX; param.a1 = TEESMC_ST_L2CC_MUTEX_GET_ADDR; +#ifdef SWITCH_CPU0_DEBUG + tee_smc_call_switchcpu0(¶m); +#else tee_smc_call(¶m); +#endif if (param.a0 != TEESMC_RETURN_OK) { dev_warn(DEV, "no TZ l2cc mutex service supported\n"); @@ -1013,7 +1058,11 @@ static int register_outercache_mutex(struct tee_tz *ptee, bool reg) memset(¶m, 0, sizeof(param)); param.a0 = TEESMC32_ST_FASTCALL_L2CC_MUTEX; param.a1 = TEESMC_ST_L2CC_MUTEX_ENABLE; +#ifdef SWITCH_CPU0_DEBUG + tee_smc_call_switchcpu0(¶m); +#else tee_smc_call(¶m); +#endif if (param.a0 != TEESMC_RETURN_OK) { @@ -1027,7 +1076,11 @@ out: memset(¶m, 0, sizeof(param)); param.a0 = TEESMC32_ST_FASTCALL_L2CC_MUTEX; param.a1 = TEESMC_ST_L2CC_MUTEX_DISABLE; +#ifdef SWITCH_CPU0_DEBUG + tee_smc_call_switchcpu0(¶m); +#else tee_smc_call(¶m); +#endif outer_tz_mutex(NULL); if (vaddr) iounmap(vaddr); @@ -1053,7 +1106,11 @@ static int configure_shm(struct tee_tz *ptee) mutex_lock(&ptee->mutex); param.a0 = TEESMC32_ST_FASTCALL_GET_SHM_CONFIG; +#ifdef SWITCH_CPU0_DEBUG + tee_smc_call_switchcpu0(¶m); +#else tee_smc_call(¶m); +#endif mutex_unlock(&ptee->mutex); if (param.a0 != TEESMC_RETURN_OK) { @@ -1160,7 +1217,7 @@ static int tz_stop(struct tee *tee) /******************************************************************************/ -const struct tee_ops tee_fops = { +static const struct tee_ops tee_fops = { .type = "tz", .owner = THIS_MODULE, .start = tz_start, diff --git a/security/optee_linuxdriver/core/Makefile b/security/optee_linuxdriver/core/Makefile index 86cde19c607f..8219201852b7 100644 --- a/security/optee_linuxdriver/core/Makefile +++ b/security/optee_linuxdriver/core/Makefile @@ -8,6 +8,8 @@ CFG_TEE_DRV_DEBUGFS?=0 CFG_TEE_CORE_LOG_LEVEL?=2 CFG_TEE_TA_LOG_LEVEL?=2 +M ?= security/optee_linuxdriver + ccflags-y+=-Werror ccflags-y+=-I$(M)/include/linux ccflags-y+=-I$(M)/include @@ -16,7 +18,7 @@ ccflags-y+=-DCFG_TEE_DRV_DEBUGFS=${CFG_TEE_DRV_DEBUGFS} ccflags-y+=-DCFG_TEE_CORE_LOG_LEVEL=${CFG_TEE_CORE_LOG_LEVEL} ccflags-y+=-DCFG_TEE_TA_LOG_LEVEL=${CFG_TEE_TA_LOG_LEVEL} -obj-m += optee.o +obj-y += optee.o optee-objs:= \ tee_core.o \ diff --git a/security/optee_linuxdriver/core/tee_core.c b/security/optee_linuxdriver/core/tee_core.c index d337e39f56c9..8ef8ade7a3b5 100644 --- a/security/optee_linuxdriver/core/tee_core.c +++ b/security/optee_linuxdriver/core/tee_core.c @@ -39,7 +39,7 @@ #define _TEE_CORE_FW_VER "1:0.1" -static char *_tee_supp_app_name = "tee-supplicant"; +static char *_tee_supp_app_name = "tee_supplicant"; /* Store the class misc reference */ static struct class *misc_class; @@ -397,13 +397,14 @@ static long tee_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return ret; } -const struct file_operations tee_fops = { +static const struct file_operations tee_file_fops = { .owner = THIS_MODULE, .read = tee_supp_read, .write = tee_supp_write, .open = tee_ctx_open, .release = tee_ctx_release, - .unlocked_ioctl = tee_ioctl + .unlocked_ioctl = tee_ioctl, + .compat_ioctl = tee_ioctl }; static void tee_plt_device_release(struct device *dev) @@ -441,7 +442,7 @@ struct tee *tee_core_alloc(struct device *dev, char *name, int id, tee->miscdev.parent = dev; tee->miscdev.minor = MISC_DYNAMIC_MINOR; tee->miscdev.name = tee->name; - tee->miscdev.fops = &tee_fops; + tee->miscdev.fops = &tee_file_fops; mutex_init(&tee->lock); atomic_set(&tee->refcount, 0); diff --git a/security/optee_linuxdriver/core/tee_session.c b/security/optee_linuxdriver/core/tee_session.c index 32391afef073..e90725582cfc 100644 --- a/security/optee_linuxdriver/core/tee_session.c +++ b/security/optee_linuxdriver/core/tee_session.c @@ -360,6 +360,7 @@ static int tee_session_release(struct inode *inode, struct file *filp) const struct file_operations tee_session_fops = { .owner = THIS_MODULE, .unlocked_ioctl = tee_session_ioctl, + .compat_ioctl = tee_session_ioctl, .release = tee_session_release, }; diff --git a/security/optee_linuxdriver/core/tee_shm.c b/security/optee_linuxdriver/core/tee_shm.c index 10d11af06a15..ccc560c2594f 100644 --- a/security/optee_linuxdriver/core/tee_shm.c +++ b/security/optee_linuxdriver/core/tee_shm.c @@ -372,7 +372,7 @@ static int export_buf(struct tee *tee, struct tee_shm *shm, int *export) dmabuf = dma_buf_export(&exp_info); #else dmabuf = dma_buf_export(shm, &_tee_shm_dma_buf_ops, shm->size_alloc, - O_RDWR, 0); + O_RDWR); #endif if (IS_ERR_OR_NULL(dmabuf)) { dev_err(_DEV(tee), "%s: dmabuf: couldn't export buffer (%ld)\n", -- 2.34.1