Re: [PATCH v4 03/17] x86/mpx, x86/insn: Relocate insn util functions to a new insn-kernel

2017-02-23 Thread Ricardo Neri
On Thu, 2017-02-23 at 18:54 +0800, kbuild test robot wrote:
> >> arch/x86/lib/insn-eval.c:106:21: error: static declaration of
> 'insn_get_addr_ref' follows non-static declaration
> static void __user *insn_get_addr_ref(struct insn *insn, struct
> pt_regs *regs)
> ^
>In file included from arch/x86/lib/insn-eval.c:10:0:
>arch/x86/include/asm/insn-eval.h:14:14: note: previous declaration
> of 'insn_get_addr_ref' was here
> void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs
> *regs);
>  ^
>arch/x86/lib/insn-eval.c:106:21: warning: 'insn_get_addr_ref'
> defined but not used [-Wunused-function]
> static void __user *insn_get_addr_ref(struct insn *insn, struct
> pt_regs *regs)
> ^
> 
> vim +/insn_get_addr_ref +106 arch/x86/lib/insn-eval.c

Uh! This escaped my tests after many rebases. I will correct it.

Thanks and BR,
Ricardo

--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 03/17] x86/mpx, x86/insn: Relocate insn util functions to a new insn-kernel

2017-02-23 Thread kbuild test robot
Hi Ricardo,

[auto build test ERROR on tip/auto-latest]
[also build test ERROR on v4.10 next-20170223]
[cannot apply to tip/x86/core]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Ricardo-Neri/x86-Enable-User-Mode-Instruction-Prevention/20170223-145356
config: x86_64-randconfig-ne0-02231751 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

Note: the 
linux-review/Ricardo-Neri/x86-Enable-User-Mode-Instruction-Prevention/20170223-145356
 HEAD 34056233e7c134c8c4c6d8308592d2e0aed67f1b builds fine.
  It only hurts bisectibility.

All errors (new ones prefixed by >>):

>> arch/x86/lib/insn-eval.c:106:21: error: static declaration of 
>> 'insn_get_addr_ref' follows non-static declaration
static void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs 
*regs)
^
   In file included from arch/x86/lib/insn-eval.c:10:0:
   arch/x86/include/asm/insn-eval.h:14:14: note: previous declaration of 
'insn_get_addr_ref' was here
void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs);
 ^
   arch/x86/lib/insn-eval.c:106:21: warning: 'insn_get_addr_ref' defined but 
not used [-Wunused-function]
static void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs 
*regs)
^

vim +/insn_get_addr_ref +106 arch/x86/lib/insn-eval.c

   100  
   101  /*
   102   * return the address being referenced be instruction
   103   * for rm=3 returning the content of the rm reg
   104   * for rm!=3 calculates the address using SIB and Disp
   105   */
 > 106  static void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs 
 > *regs)
   107  {
   108  unsigned long addr, base, indx;
   109  int addr_offset, base_offset, indx_offset;

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH v4 03/17] x86/mpx, x86/insn: Relocate insn util functions to a new insn-kernel

2017-02-22 Thread Ricardo Neri
Other kernel submodules can benefit from using the utility functions
defined in mpx.c to obtain the addresses and values of operands contained
in the general purpose registers. An instance of this is the emulation code
used for instructions protected by the Intel User-Mode Instruction
Prevention feature.

Thus, these functions are relocated to a new insn-eval.c file. The reason
to not relocate these utilities into insn.c is that the latter solely
analyses instructions given by a struct insn without any knowledge of the
meaning of the values of instruction operands. This new utility insn-
eval.c aims to be used to resolve effective and linear addresses based on
the contents of the instruction operands as well as the contents of the
struct pt_regs.

These utilities come with a separate header. This is to avoid taking insn.c
out of sync from the instructions decoders under tools/obj and tools/perf.
This also avoids adding cumbersome #ifdef's for the #include'd files
required to decode instructions in a kernel context.

Functions are simply relocated. There are not functional or indentation
changes.

Cc: Dave Hansen 
Cc: Adam Buchbinder 
Cc: Colin Ian King 
Cc: Lorenzo Stoakes 
Cc: Qiaowei Ren 
Cc: Arnaldo Carvalho de Melo 
Cc: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Kees Cook 
Cc: Thomas Garnier 
Cc: Peter Zijlstra 
Cc: Borislav Petkov 
Cc: Dmitry Vyukov 
Cc: Ravi V. Shankar 
Cc: x...@kernel.org
Signed-off-by: Ricardo Neri 
---
 arch/x86/include/asm/insn-eval.h |  16 
 arch/x86/lib/Makefile|   2 +-
 arch/x86/lib/insn-eval.c | 160 +++
 arch/x86/mm/mpx.c| 152 +
 4 files changed, 179 insertions(+), 151 deletions(-)
 create mode 100644 arch/x86/include/asm/insn-eval.h
 create mode 100644 arch/x86/lib/insn-eval.c

diff --git a/arch/x86/include/asm/insn-eval.h b/arch/x86/include/asm/insn-eval.h
new file mode 100644
index 000..5cab1b1
--- /dev/null
+++ b/arch/x86/include/asm/insn-eval.h
@@ -0,0 +1,16 @@
+#ifndef _ASM_X86_INSN_EVAL_H
+#define _ASM_X86_INSN_EVAL_H
+/*
+ * A collection of utility functions for x86 instruction analysis to be
+ * used in a kernel context. Useful when, for instance, making sense
+ * of the registers indicated by operands.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs);
+
+#endif /* _ASM_X86_INSN_EVAL_H */
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index 34a7413..675d7b0 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -23,7 +23,7 @@ lib-y := delay.o misc.o cmdline.o cpu.o
 lib-y += usercopy_$(BITS).o usercopy.o getuser.o putuser.o
 lib-y += memcpy_$(BITS).o
 lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
-lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o
+lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o insn-eval.o
 lib-$(CONFIG_RANDOMIZE_BASE) += kaslr.o
 
 obj-y += msr.o msr-reg.o msr-reg-export.o hweight.o
diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
new file mode 100644
index 000..2ebfaa4
--- /dev/null
+++ b/arch/x86/lib/insn-eval.c
@@ -0,0 +1,160 @@
+/*
+ * Utility functions for x86 operand and address decoding
+ *
+ * Copyright (C) Intel Corporation 2016
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+
+enum reg_type {
+   REG_TYPE_RM = 0,
+   REG_TYPE_INDEX,
+   REG_TYPE_BASE,
+};
+
+static int get_reg_offset(struct insn *insn, struct pt_regs *regs,
+ enum reg_type type)
+{
+   int regno = 0;
+
+   static const int regoff[] = {
+   offsetof(struct pt_regs, ax),
+   offsetof(struct pt_regs, cx),
+   offsetof(struct pt_regs, dx),
+   offsetof(struct pt_regs, bx),
+   offsetof(struct pt_regs, sp),
+   offsetof(struct pt_regs, bp),
+   offsetof(struct pt_regs, si),
+   offsetof(struct pt_regs, di),
+#ifdef CONFIG_X86_64
+   offsetof(struct pt_regs, r8),
+   offsetof(struct pt_regs, r9),
+   offsetof(struct pt_regs, r10),
+   offsetof(struct pt_regs, r11),
+   offsetof(struct pt_regs, r12),
+   offsetof(struct pt_regs, r13),
+   offsetof(struct pt_regs, r14),
+   offsetof(struct pt_regs, r15),
+#endif
+   };
+   int nr_registers = ARRAY_SIZE(regoff);
+   /*
+* Don't possibly decode a 32-bit instructions as
+* reading a 64-bit-only register.
+*/
+   if (IS_ENABLED(CONFIG_X86_64) && !insn->x86_64)
+   nr_registers -= 8;
+
+   switch (type) {
+   case REG_TYPE_RM:
+   regno = X86_MODRM_RM(insn->modrm.value);
+   if (X86_REX_B(insn->rex_prefix.value))
+   regno += 8;
+   break;
+
+   case REG_TYPE_INDEX:
+   regno = X86_SIB_INDEX(insn->sib.value);
+