Thread (11 messages) 11 messages, 3 authors, 2016-09-16

Re: [PATCH v3 3/3] x86,arch_prctl Add ARCH_[GET|SET]_CPUID for controlling the CPUID instruction

From: Kyle Huey <hidden>
Date: 2016-09-16 05:30:09
Also in: linux-fsdevel, lkml

On Thu, Sep 15, 2016 at 5:07 PM, Andy Lutomirski [off-list ref] wrote:
On Thu, Sep 15, 2016 at 4:33 PM, Kyle Huey [off-list ref] wrote:
quoted
+int get_cpuid_mode(unsigned long adr)
+{
+       unsigned int val;
+
+       if (test_thread_flag(TIF_NOCPUID))
+               val = ARCH_CPUID_SIGSEGV;
+       else
+               val = ARCH_CPUID_ENABLE;
+
+       return put_user(val, (unsigned int __user *)adr);
+}
Can we just do:

if (arg2 != 0)
  return -EINVAL;
else
 return test_thread_flag(TIF_NOCPUID) ? ARCH_CPUID_SIGSEGBV : ARCH_CPUID_ENABLE;
We could.  I copied the pattern of PR_GET_TSC here, but I don't feel
strongly about it.
quoted
diff --git a/tools/testing/selftests/x86/cpuid-fault.c b/tools/testing/selftests/x86/cpuid-fault.c
new file mode 100644
index 0000000..a9f3f68
--- /dev/null
+++ b/tools/testing/selftests/x86/cpuid-fault.c
@@ -0,0 +1,234 @@
+
+/*
+ * Tests for arch_prctl(ARCH_GET_CPUID, ...) / prctl(ARCH_SET_CPUID, ...)
+ *
+ * Basic test to test behaviour of ARCH_GET_CPUID and ARCH_SET_CPUID
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <inttypes.h>
+#include <cpuid.h>
+#include <errno.h>
+#include <sys/wait.h>
+
+#include <sys/prctl.h>
+#include <linux/prctl.h>
+
+const char *cpuid_names[] = {
+       [0] = "[not set]",
Is 0 even possible?
Only if the call fails.

- Kyle
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help