Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1483677 > unrolled thread
| Started by | Kyle Huey <me@kylehuey.com> |
|---|---|
| First post | 2016-09-14 23:10 +0200 |
| Last post | 2016-09-14 23:20 +0200 |
| Articles | 2 — 1 participant |
Back to article view | Back to linux.kernel
[RESEND][PATCH v2] arch_prctl,x86 Add ARCH_[GET|SET]_CPUID for controlling the CPUID instruction Kyle Huey <me@kylehuey.com> - 2016-09-14 23:10 +0200
[PATCH (man-pages)] arch_prctl.2: Note new support on x86-32, ARCH_[GET|SET]_CPUID. Kyle Huey <me@kylehuey.com> - 2016-09-14 23:20 +0200
| From | Kyle Huey <me@kylehuey.com> |
|---|---|
| Date | 2016-09-14 23:10 +0200 |
| Subject | [RESEND][PATCH v2] arch_prctl,x86 Add ARCH_[GET|SET]_CPUID for controlling the CPUID instruction |
| Message-ID | <shpBn-665-19@gated-at.bofh.it> |
(Resending because I screwed up the cover email, sorry about that.)
rr (http://rr-project.org/), a userspace record-and-replay reverse-
execution debugger, would like to trap and emulate the CPUID instruction.
This would allow us to a) mask away certain hardware features that rr does
not support (e.g. RDRAND) and b) enable trace portability across machines
by providing constant results.
4 patches follow, the first 3 to the kernel, and the final patch to man-pages.
The following changes have been made since v1:
Suggested by Borislav Petkov:
- Uses arch_prctl instead of prctl.
- Uses rdmsr_safe.
- Added sample man-pages patch.
- Various functions are renamed, style fixes.
Suggested by Andy Lutomirski:
- Added a cpufeature bit to show up in /proc/cpuinfo.
- Added sane behavior in Xen, by masking away the MSR_PLATFORM_INFO bit
showing support for this feature for now.
- Added a selftest, clarifying the bit is preserved on fork/exec.
The following issues were raised and are not addressed:
Use of cpuid within interrupt handlers: as Linus pointed out, CPUID only
faults at cpl>0, so this is not a concern.
Use a static_key instead of a TIF: I don't believe this solves anything.
There are currently 8 free TIF bits (after this patch), and it's always
possible to move this (or others) later if they are needed. Even if we were
to use a static_key we would still need to maintain state about which tasks
are subject to CPUID faulting and which are not somewhere else.
[toc] | [next] | [standalone]
| From | Kyle Huey <me@kylehuey.com> |
|---|---|
| Date | 2016-09-14 23:20 +0200 |
| Subject | [PATCH (man-pages)] arch_prctl.2: Note new support on x86-32, ARCH_[GET|SET]_CPUID. |
| Message-ID | <shpL3-6a4-21@gated-at.bofh.it> |
| In reply to | #1483677 |
Signed-off-by: Kyle Huey <khuey@kylehuey.com> --- man2/arch_prctl.2 | 73 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/man2/arch_prctl.2 b/man2/arch_prctl.2 index 989d369..c388797 100644 --- a/man2/arch_prctl.2 +++ b/man2/arch_prctl.2 @@ -22,7 +22,7 @@ .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" -.TH ARCH_PRCTL 2 2015-02-21 "Linux" "Linux Programmer's Manual" +.TH ARCH_PRCTL 2 2016-09-14 "Linux" "Linux Programmer's Manual" .SH NAME arch_prctl \- set architecture-specific thread state .SH SYNOPSIS @@ -31,8 +31,8 @@ arch_prctl \- set architecture-specific thread state .br .B #include <sys/prctl.h> .sp -.BI "int arch_prctl(int " code ", unsigned long " addr ); -.BI "int arch_prctl(int " code ", unsigned long *" addr ); +.BI "int arch_prctl(int " code ", unsigned long " arg2 ); +.BI "int arch_prctl(int " code ", unsigned long *" arg2 ); .fi .SH DESCRIPTION The @@ -41,22 +41,47 @@ function sets architecture-specific process or thread state. .I code selects a subfunction and passes argument -.I addr +.I arg2 to it; -.I addr +.I arg2 is interpreted as either an .I "unsigned long" for the "set" operations, or as an .IR "unsigned long\ *" , for the "get" operations. .LP +Subfunctions for both x86-64 and x86-32 are: +.TP +.B ARCH_GET_CPUID " (since Linux 4.X)" +Return the state of the flag determining whether the +.I cpuid +instruction can be executed by the process, in the +.I unsigned long +pointed to by +.IR arg2 . +.TP +.B ARCH_SET_CPUID " (since Linux 4.X)" +Set the state of the flag determining whether the +.I cpuid +instruction can be executed by the process. Pass +.B ARCH_CPUID_ENABLE +in +.I arg2 +to allow it to be executed, or +.B ARCH_CPUID_SIGSEGV +to generate a +.B SIGSEGV +when the process tries to execute the +.I cpuid +instruction. This flag is propagated across fork and exec. +.LP Subfunctions for x86-64 are: .TP .B ARCH_SET_FS Set the 64-bit base for the .I FS register to -.IR addr . +.IR arg2 . .TP .B ARCH_GET_FS Return the 64-bit base value for the @@ -64,13 +89,13 @@ Return the 64-bit base value for the register of the current thread in the .I unsigned long pointed to by -.IR addr . +.IR arg2 . .TP .B ARCH_SET_GS Set the 64-bit base for the .I GS register to -.IR addr . +.IR arg2 . .TP .B ARCH_GET_GS Return the 64-bit base value for the @@ -78,7 +103,7 @@ Return the 64-bit base value for the register of the current thread in the .I unsigned long pointed to by -.IR addr . +.IR arg2 . .SH RETURN VALUE On success, .BR arch_prctl () @@ -87,26 +112,48 @@ returns 0; on error, \-1 is returned, and is set to indicate the error. .SH ERRORS .TP +.B EACCES +.I code +is +.B ARCH_SET_CPUID +and +.I arg2 +is +.B ARCH_CPUID_ENABLE +and cpuid was previously disabled with +.B ARCH_CPUID_SIGSEGV +and the +.I no_new_privs +bit is set on this thread. +.TP .B EFAULT -.I addr +.I arg2 points to an unmapped address or is outside the process address space. .TP .B EINVAL .I code is not a valid subcommand. .TP +.B EINVAL +.I code +is +.B ARCH_SET_CPUID +and +.I cpuid +faulting is not supported on this machine. +.TP .B EPERM -.I addr +.I arg2 is outside the process address space. .\" .SH AUTHOR .\" Man page written by Andi Kleen. .SH CONFORMING TO .BR arch_prctl () -is a Linux/x86-64 extension and should not be used in programs intended +is a Linux/x86 extension and should not be used in programs intended to be portable. .SH NOTES .BR arch_prctl () -is supported only on Linux/x86-64 for 64-bit programs currently. +is supported only on Linux/x86 currently. The 64-bit base changes when a new 32-bit segment selector is loaded. -- 2.7.4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web