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().
Signed-off-by: Aqib Faruqui aqibaf@amazon.com --- tools/testing/selftests/kvm/include/x86/processor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/testing/selftests/kvm/include/x86/processor.h index 3f93d1b4f..8edf48b5a 100644 --- a/tools/testing/selftests/kvm/include/x86/processor.h +++ b/tools/testing/selftests/kvm/include/x86/processor.h @@ -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)
On Fri, Aug 29, 2025, Aqib Faruqui wrote:
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 seanjc@google.com AuthorDate: Tue Aug 30 23:15:51 2022 +0000 Commit: Paolo Bonzini pbonzini@redhat.com 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.
Signed-off-by: Sean Christopherson seanjc@google.com Link: https://lore.kernel.org/r/20220830231614.3580124-5-seanjc@google.com Signed-off-by: Paolo Bonzini pbonzini@redhat.com
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 418a069ab0d7..a7ae08e68582 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -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);
linux-kselftest-mirror@lists.linaro.org