Skip to contentSkip to conversation

KVM: selftests: Fix force_emulation_prefix parameter type mismatch

PATCH In review Aqib Faruqui 2 participants 2 messages Aug 29, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: selftests: Fix force_emulation_prefix parameter type mismatch

Fix kvm_is_forced_enabled() to use get_kvm_param_bool() instead of get_kvm_param_integer() when reading the "force_emulation_prefix" kernel module parameter.

The force_emulation_prefix parameter is a boolean that accepts Y/N values, but the function was incorrectly trying to parse it as an integer using strtol().

---
 tools/testing/selftests/kvm/include/x86/processor.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/include/x86/processor.h +1 -1
index 3f93d1b4f..8edf48b5a 100644
@@ -1323,7 +1323,7 @@ static inline bool kvm_is_pmu_enabled(void)
 
 static inline bool kvm_is_forced_emulation_enabled(void)
 {
-	return !!get_kvm_param_integer("force_emulation_prefix");
+	return get_kvm_param_bool("force_emulation_prefix");
 }
 
 static inline bool kvm_is_unrestricted_guest_enabled(void)
Signature · 1 line
2.47.3
#1 lore raw
Quoted 7 lines · Aqib Faruqui

Fix kvm_is_forced_enabled() to use get_kvm_param_bool() instead of get_kvm_param_integer() when reading the "force_emulation_prefix" kernel module parameter.

The force_emulation_prefix parameter is a boolean that accepts Y/N values, but the function was incorrectly trying to parse it as an integer using strtol().

Nope, it's been an int since commit:

commit d500e1ed3dc873818277e109ccf6407118669236

Author:     Sean Christopherson <[email protected]>
AuthorDate: Tue Aug 30 23:15:51 2022 +0000
Commit:     Paolo Bonzini <[email protected]>
CommitDate: Mon Sep 26 12:03:04 2022 -0400

KVM: x86: Allow clearing RFLAGS.RF on forced emulation to test code #DBs

Extend force_emulation_prefix to an 'int' and use bit 1 as a flag to indicate that KVM should clear RFLAGS.RF before emulating, e.g. to allow tests to force emulation of code breakpoints in conjunction with MOV/POP SS blocking, which is impossible without KVM intervention as VMX unconditionally sets RFLAGS.RF on intercepted #UD.

Make the behavior controllable so that tests can also test RFLAGS.RF=1 (again in conjunction with code #DBs).

Note, clearing RFLAGS.RF won't create an infinite #DB loop as the guest's IRET from the #DB handler will return to the instruction and not the prefix, i.e. the restart won't force emulation.

Opportunistically convert the permissions to the preferred octal format.

arch/x86/kvm/x86.c +7 -2
index 418a069ab0d7..a7ae08e68582 100644
@@ -173,8 +173,13 @@ bool __read_mostly enable_vmware_backdoor = false;
 module_param(enable_vmware_backdoor, bool, S_IRUGO);
 EXPORT_SYMBOL_GPL(enable_vmware_backdoor);
 
-static bool __read_mostly force_emulation_prefix = false;
-module_param(force_emulation_prefix, bool, S_IRUGO);
+/*
+ * Flags to manipulate forced emulation behavior (any non-zero value will
+ * enable forced emulation).
+ */
+#define KVM_FEP_CLEAR_RFLAGS_RF        BIT(1)
+static int __read_mostly force_emulation_prefix;
+module_param(force_emulation_prefix, int, 0444);