qemu: conditionally active task isolation If task isolation is configured, active it on the CPU execution loop. Higher level management software is supposed to configure task isolation. Signed-off-by: Marcelo Tosatti diff --git a/cpus-common.c b/cpus-common.c index 6e73d3e58d..b394bf0bd7 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -225,9 +225,11 @@ void end_exclusive(void) qemu_mutex_unlock(&qemu_cpu_list_lock); } -/* Wait for exclusive ops to finish, and begin cpu execution. */ void cpu_exec_start(CPUState *cpu) { + qemu_activate_task_isolation(); + + /* Wait for exclusive ops to finish, and begin cpu execution. */ qatomic_set(&cpu->running, true); /* Write cpu->running before reading pending_cpus. */ diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index ba15be9c56..649154d11c 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -686,6 +686,14 @@ char *qemu_get_host_name(Error **errp); */ size_t qemu_get_host_physmem(void); +/** + * qemu_activate_task_isolation: + * + * Enable task isolation, if available, before executing the CPU. + * + */ +int qemu_activate_task_isolation(void); + /* * Toggle write/execute on the pages marked MAP_JIT * for the current thread. diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 36820fec16..54cc66c786 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -43,6 +43,8 @@ #ifdef CONFIG_LINUX #include +#include +#include #endif #ifdef __FreeBSD__ @@ -866,3 +868,24 @@ size_t qemu_get_host_physmem(void) #endif return 0; } + +int qemu_activate_task_isolation(void) +{ +#if defined(__linux__) +#ifdef PR_ISOL_CFG_GET + unsigned long long fmask; + + ret = prctl(PR_ISOL_CFG_GET, I_CFG_FEAT, 0, &fmask, 0); + + if (ret != -1 && fmask != 0) { + ret = prctl(PR_ISOL_ACTIVATE_SET, &fmask, 0, 0, 0); + if (ret == -1) { + perror("prctl PR_ISOL_ACTIVATE_SET"); + return ret; + } + } + return ret; +#endif +#endif + return 0; +} diff --git a/util/oslib-win32.c b/util/oslib-win32.c index f68b8012bb..1c684d82c7 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -842,3 +842,8 @@ size_t qemu_get_host_physmem(void) } return 0; } + +int qemu_activate_task_isolation(void) +{ + return 0; +}