lkml.org 
[lkml]   [2016]   [Sep]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v5 6/6] x86/arch_prctl Add ARCH_[GET|SET]_CPUID
On Wed, Sep 21, 2016 at 11:58 AM, Kyle Huey <me@kylehuey.com> wrote:
> Intel supports faulting on the CPUID instruction beginning with Ivy Bridge.
> When enabled, the processor will fault on attempts to execute the CPUID
> instruction with CPL>0. Exposing this feature to userspace will allow a
> ptracer to trap and emulate the CPUID instruction.
>
> When supported, this feature is controlled by toggling bit 0 of
> MSR_MISC_FEATURES_ENABLES. It is documented in detail in Section 2.3.2 of
> http://www.intel.com/content/dam/www/public/us/en/documents/application-notes/virtualization-technology-flexmigration-application-note.pdf
>

> + if (!test_and_set_thread_flag(TIF_NOCPUID))
> + /*
> + * Must flip the CPU state synchronously with
> + * TIF_NOCPUID in the current running context.
> + */
> + switch_cpuid_faulting(true);

If statements with multiple indented lines should have braces in my
book. See, for example, "goto fail".


static?

> +int set_cpuid_mode(struct task_struct *task, unsigned long val)

static?

> + * Called immediately after a successful exec.
> + */
> +void arch_post_exec(void)
> +{
> + /* If cpuid was previously disabled for this task, re-enable it. */
> + if (test_thread_flag(TIF_NOCPUID))
> + enable_cpuid();
> +}

> diff --git a/fs/exec.c b/fs/exec.c
> index 6fcfb3f..0272b7e 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -1287,6 +1287,7 @@ void setup_new_exec(struct linux_binprm * bprm)
> else
> set_dumpable(current->mm, suid_dumpable);
>
> + arch_post_exec();

Let's call this arch_setup_new_exec().

> perf_event_exec();
> __set_task_comm(current, kbasename(bprm->filename), true);
>
> diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
> index 2b5b10e..22a3f61 100644
> --- a/include/linux/thread_info.h
> +++ b/include/linux/thread_info.h
> @@ -130,6 +130,10 @@ static inline void check_object_size(const void *ptr, unsigned long n,
> { }
> #endif /* CONFIG_HARDENED_USERCOPY */
>
> +#ifndef arch_post_exec
> +static inline void arch_post_exec(void) {}
> +#endif
> +

thread_info.h is a weird place for this IMO. Admittedly, elf.h isn't
a whole lot better.

\
 
 \ /
  Last update: 2016-09-23 00:23    [W:0.250 / U:0.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site