The insn-eval x86 selftest lib uses kernel-internal macros savesegment and rdmsrq, which are typically defined in kernel headers like and . These headers are not available in the userspace build environment for selftests, leading to build failures. Fix this by providing local definitions for the missing symbols and replacing with the functional equivalent definitions available to the selftest. Signed-off-by: Neeraj Upadhyay --- tools/testing/selftests/kvm/lib/x86/insn-eval.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86/insn-eval.c b/tools/testing/selftests/kvm/lib/x86/insn-eval.c index bb7845500f3c..fb393aaf9f7f 100644 --- a/tools/testing/selftests/kvm/lib/x86/insn-eval.c +++ b/tools/testing/selftests/kvm/lib/x86/insn-eval.c @@ -18,6 +18,9 @@ #undef pr_fmt #define pr_fmt(fmt) "insn: " fmt +#define savesegment(seg, value) \ + asm("mov %%" #seg ",%0":"=r" (value) : : "memory") + enum reg_type { REG_TYPE_RM = 0, REG_TYPE_REG, @@ -25,6 +28,11 @@ enum reg_type { REG_TYPE_BASE, }; +static __always_inline int user_mode(struct pt_regs *regs) +{ + return !!(regs->cs & 3); +} + /* * is_string_insn() - Determine if instruction is a string instruction * @insn: Instruction containing the opcode to inspect @@ -528,16 +536,16 @@ unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx) */ if (seg_reg_idx == INAT_SEG_REG_FS) { - rdmsrq(MSR_FS_BASE, base); + base = rdmsr(MSR_FS_BASE); } else if (seg_reg_idx == INAT_SEG_REG_GS) { /* * swapgs was called at the kernel entry point. Thus, * MSR_KERNEL_GS_BASE will have the user-space GS base. */ if (user_mode(regs)) - rdmsrq(MSR_KERNEL_GS_BASE, base); + base = rdmsr(MSR_KERNEL_GS_BASE); else - rdmsrq(MSR_GS_BASE, base); + base = rdmsr(MSR_GS_BASE); } else { base = 0; } -- 2.34.1