lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250923050942.206116-17-Neeraj.Upadhyay@amd.com>
Date: Tue, 23 Sep 2025 10:39:23 +0530
From: Neeraj Upadhyay <Neeraj.Upadhyay@....com>
To: <kvm@...r.kernel.org>, <seanjc@...gle.com>, <pbonzini@...hat.com>
CC: <linux-kernel@...r.kernel.org>, <Thomas.Lendacky@....com>,
	<nikunj@....com>, <Santosh.Shukla@....com>, <Vasant.Hegde@....com>,
	<Suravee.Suthikulpanit@....com>, <bp@...en8.de>, <David.Kaplan@....com>,
	<huibo.wang@....com>, <naveen.rao@....com>, <pgonda@...gle.com>,
	<linux-kselftest@...r.kernel.org>, <shuah@...nel.org>, <tiala@...rosoft.com>
Subject: [RFC PATCH v2 16/35] KVM: selftests: Fix missing definitions in x86 instruction decoder

The insn-eval x86 selftest lib uses kernel-internal macros savesegment and
rdmsrq, which are typically defined in kernel headers like <asm/segment.h>
and <asm/msr.h>. 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 <Neeraj.Upadhyay@....com>
---
 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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ