mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 11:50:43 +09:00
cpu_affinity: restore the original cpu affinity correctly [1/1]
PD#SWPL-5595 Problem: set_cpus_allowed_ptr(current, cpu_all_mask) is always errorly called to retore CPU affinity for current task. In some cases, the current may be a bounded kworker thread, and we should not set its CPU affinity to all CPUs Solution: Save the original CPU affinity and restore it Verify: W400 revB Change-Id: I3cd65e79791563af9dacc09639b8645b97979c44 Signed-off-by: Jiamin Ma <jiamin.ma@amlogic.com>
This commit is contained in:
@@ -155,10 +155,12 @@ uint32_t meson_secure_mem_flash_size(void)
|
||||
int32_t meson_secure_mem_ge2d_access(uint32_t msec)
|
||||
{
|
||||
int ret = -1;
|
||||
struct cpumask org_cpumask;
|
||||
|
||||
cpumask_copy(&org_cpumask, ¤t->cpus_allowed);
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
ret = meson_smc_hal_api(TRUSTZONE_HAL_API_MEMCONFIG_GE2D, msec);
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
set_cpus_allowed_ptr(current, &org_cpumask);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -184,15 +186,17 @@ EXPORT_SYMBOL(meson_secure_jtag_apee);
|
||||
int meson_trustzone_efuse(void *arg)
|
||||
{
|
||||
int ret;
|
||||
struct cpumask org_cpumask;
|
||||
|
||||
if (!arg)
|
||||
return -1;
|
||||
|
||||
cpumask_copy(&org_cpumask, ¤t->cpus_allowed);
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
|
||||
ret = meson_smc_hal_api(TRUSTZONE_HAL_API_EFUSE, __pa(arg));
|
||||
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
set_cpus_allowed_ptr(current, &org_cpumask);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -101,12 +101,14 @@ int meson_efuse_fn_smc_query_audioinfo(struct efuse_hal_api_arg *arg)
|
||||
int meson_trustzone_audio_info_get(struct efuse_hal_api_arg *arg)
|
||||
{
|
||||
int ret;
|
||||
struct cpumask org_cpumask;
|
||||
|
||||
if (!arg)
|
||||
return -1;
|
||||
cpumask_copy(&org_cpumask, ¤t->cpus_allowed);
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
ret = meson_efuse_fn_smc_query_audioinfo(arg);
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
set_cpus_allowed_ptr(current, &org_cpumask);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,13 +74,15 @@ static long meson64_efuse_fn_smc(struct efuse_hal_api_arg *arg)
|
||||
int meson64_trustzone_efuse(struct efuse_hal_api_arg *arg)
|
||||
{
|
||||
int ret;
|
||||
struct cpumask org_cpumask;
|
||||
|
||||
if (!arg)
|
||||
return -1;
|
||||
|
||||
cpumask_copy(&org_cpumask, ¤t->cpus_allowed);
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
ret = meson64_efuse_fn_smc(arg);
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
set_cpus_allowed_ptr(current, &org_cpumask);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -122,13 +124,15 @@ unsigned long efuse_aml_sec_boot_check(unsigned long nType,
|
||||
unsigned long efuse_amlogic_set(char *buf, size_t count)
|
||||
{
|
||||
unsigned long ret;
|
||||
struct cpumask org_cpumask;
|
||||
|
||||
cpumask_copy(&org_cpumask, ¤t->cpus_allowed);
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
|
||||
ret = efuse_aml_sec_boot_check(AML_D_P_W_EFUSE_AMLOGIC,
|
||||
(unsigned long)buf, (unsigned long)count, 0);
|
||||
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
set_cpus_allowed_ptr(current, &org_cpumask);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -160,12 +164,14 @@ ssize_t efuse_get_max(void)
|
||||
{
|
||||
struct efuse_hal_api_arg arg;
|
||||
int ret;
|
||||
struct cpumask org_cpumask;
|
||||
|
||||
arg.cmd = EFUSE_HAL_API_USER_MAX;
|
||||
|
||||
cpumask_copy(&org_cpumask, ¤t->cpus_allowed);
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
ret = meson64_trustzone_efuse_get_max(&arg);
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
set_cpus_allowed_ptr(current, &org_cpumask);
|
||||
|
||||
if (ret == 0) {
|
||||
pr_info("ERROR: can not get efuse user max bytes!!!\n");
|
||||
|
||||
@@ -182,7 +182,9 @@ static int aml_jtag_select_tee(struct platform_device *pdev)
|
||||
{
|
||||
struct aml_jtag_dev *jdev = platform_get_drvdata(pdev);
|
||||
uint32_t select = jdev->select;
|
||||
struct cpumask org_cpumask;
|
||||
|
||||
cpumask_copy(&org_cpumask, ¤t->cpus_allowed);
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
pr_info("meson8b select %s\n", select_to_name(jdev->select));
|
||||
switch (select) {
|
||||
@@ -200,7 +202,7 @@ static int aml_jtag_select_tee(struct platform_device *pdev)
|
||||
writel_relaxed(0x0, jdev->base);
|
||||
break;
|
||||
}
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
set_cpus_allowed_ptr(current, &org_cpumask);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -291,6 +293,7 @@ static int aml_jtag_select(struct platform_device *pdev)
|
||||
struct aml_jtag_dev *jdev = platform_get_drvdata(pdev);
|
||||
unsigned int select = jdev->select;
|
||||
unsigned int state = AMLOGIC_JTAG_STATE_OFF;
|
||||
struct cpumask org_cpumask;
|
||||
|
||||
if (select != AMLOGIC_JTAG_DISABLE)
|
||||
state = AMLOGIC_JTAG_STATE_ON;
|
||||
@@ -299,9 +302,10 @@ static int aml_jtag_select(struct platform_device *pdev)
|
||||
select |= jdev->cluster << CLUSTER_BIT;
|
||||
|
||||
pr_info("select %s\n", select_to_name(select));
|
||||
cpumask_copy(&org_cpumask, ¤t->cpus_allowed);
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
aml_set_jtag_state(state, select);
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
set_cpus_allowed_ptr(current, &org_cpumask);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -751,16 +751,22 @@ void jtag_set_state(unsigned int state, unsigned int select)
|
||||
|
||||
void jtag_select_ao(void)
|
||||
{
|
||||
struct cpumask org_cpumask;
|
||||
|
||||
cpumask_copy(&org_cpumask, ¤t->cpus_allowed);
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
jtag_set_state(AMLOGIC_JTAG_STATE_ON, AMLOGIC_JTAG_APAO);
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
set_cpus_allowed_ptr(current, &org_cpumask);
|
||||
}
|
||||
|
||||
void jtag_select_sd(void)
|
||||
{
|
||||
struct cpumask org_cpumask;
|
||||
|
||||
cpumask_copy(&org_cpumask, ¤t->cpus_allowed);
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
jtag_set_state(AMLOGIC_JTAG_STATE_ON, AMLOGIC_JTAG_APEE);
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
set_cpus_allowed_ptr(current, &org_cpumask);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#include <linux/amlogic/tee.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/amlogic/cpu_version.h>
|
||||
#include <asm/cputype.h>
|
||||
|
||||
#define DRIVER_NAME "tee_info"
|
||||
@@ -73,25 +71,12 @@ static int tee_msg_os_revision(uint32_t *major, uint32_t *minor)
|
||||
struct arm_smccc_res smccc;
|
||||
struct tee_smc_calls_revision_result result;
|
||||
} res;
|
||||
long cpu;
|
||||
|
||||
if (get_meson_cpu_version(MESON_CPU_VERSION_LVL_MAJOR)
|
||||
== MESON_CPU_MAJOR_ID_G12B) {
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
cpu = read_cpuid_mpidr();
|
||||
cpu &= 0xfff;
|
||||
if (cpu != 0x0)
|
||||
usleep_range(10, 20);
|
||||
}
|
||||
|
||||
arm_smccc_smc(TEE_SMC_CALL_GET_OS_REVISION,
|
||||
0, 0, 0, 0, 0, 0, 0, &res.smccc);
|
||||
*major = res.result.major;
|
||||
*minor = res.result.minor;
|
||||
|
||||
if (get_meson_cpu_version(MESON_CPU_VERSION_LVL_MAJOR)
|
||||
== MESON_CPU_MAJOR_ID_G12B)
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -101,25 +86,12 @@ static int tee_msg_api_revision(uint32_t *major, uint32_t *minor)
|
||||
struct arm_smccc_res smccc;
|
||||
struct tee_smc_calls_revision_result result;
|
||||
} res;
|
||||
long cpu;
|
||||
|
||||
if (get_meson_cpu_version(MESON_CPU_VERSION_LVL_MAJOR)
|
||||
== MESON_CPU_MAJOR_ID_G12B) {
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
cpu = read_cpuid_mpidr();
|
||||
cpu &= 0xfff;
|
||||
if (cpu != 0x0)
|
||||
usleep_range(10, 20);
|
||||
}
|
||||
|
||||
arm_smccc_smc(TEE_SMC_CALLS_REVISION,
|
||||
0, 0, 0, 0, 0, 0, 0, &res.smccc);
|
||||
*major = res.result.major;
|
||||
*minor = res.result.minor;
|
||||
|
||||
if (get_meson_cpu_version(MESON_CPU_VERSION_LVL_MAJOR)
|
||||
== MESON_CPU_MAJOR_ID_G12B)
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -165,23 +137,10 @@ static CLASS_ATTR(api_version, 0644, tee_api_version_show,
|
||||
static int tee_load_firmware(uint32_t index, uint32_t vdec, bool is_swap)
|
||||
{
|
||||
struct arm_smccc_res res;
|
||||
long cpu;
|
||||
|
||||
if (get_meson_cpu_version(MESON_CPU_VERSION_LVL_MAJOR)
|
||||
== MESON_CPU_MAJOR_ID_G12B) {
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
cpu = read_cpuid_mpidr();
|
||||
cpu &= 0xfff;
|
||||
if (cpu != 0x0)
|
||||
usleep_range(10, 20);
|
||||
}
|
||||
|
||||
arm_smccc_smc(TEE_SMC_LOAD_VIDEO_FW,
|
||||
index, vdec, is_swap, 0, 0, 0, 0, &res);
|
||||
|
||||
if (get_meson_cpu_version(MESON_CPU_VERSION_LVL_MAJOR)
|
||||
== MESON_CPU_MAJOR_ID_G12B)
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
return res.a0;
|
||||
}
|
||||
|
||||
@@ -200,26 +159,12 @@ EXPORT_SYMBOL(tee_load_video_fw_swap);
|
||||
bool tee_enabled(void)
|
||||
{
|
||||
struct arm_smccc_res res;
|
||||
long cpu;
|
||||
if (disable_flag == 1)
|
||||
return false;
|
||||
/*return false;*/ /*disable tee load temporary*/
|
||||
|
||||
if (get_meson_cpu_version(MESON_CPU_VERSION_LVL_MAJOR)
|
||||
== MESON_CPU_MAJOR_ID_G12B) {
|
||||
set_cpus_allowed_ptr(current, cpumask_of(0));
|
||||
cpu = read_cpuid_mpidr();
|
||||
cpu &= 0xfff;
|
||||
if (cpu != 0x0)
|
||||
usleep_range(10, 20);
|
||||
}
|
||||
|
||||
arm_smccc_smc(TEE_SMC_CALLS_UID, 0, 0, 0, 0, 0, 0, 0, &res);
|
||||
|
||||
if (get_meson_cpu_version(MESON_CPU_VERSION_LVL_MAJOR)
|
||||
== MESON_CPU_MAJOR_ID_G12B)
|
||||
set_cpus_allowed_ptr(current, cpu_all_mask);
|
||||
|
||||
if (res.a0 == TEE_MSG_UID_0 && res.a1 == TEE_MSG_UID_1 &&
|
||||
res.a2 == TEE_MSG_UID_2 && res.a3 == TEE_MSG_UID_3)
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user