[LTP] [PATCH 04/10] KVM: Implement helper functions for setting x86 control registers
Martin Doucha
mdoucha@suse.cz
Tue Jan 21 17:44:18 CET 2025
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
testcases/kernel/kvm/include/kvm_x86.h | 3 +++
testcases/kernel/kvm/lib_x86.c | 27 ++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/testcases/kernel/kvm/include/kvm_x86.h b/testcases/kernel/kvm/include/kvm_x86.h
index c782a64ec..296dc3859 100644
--- a/testcases/kernel/kvm/include/kvm_x86.h
+++ b/testcases/kernel/kvm/include/kvm_x86.h
@@ -221,6 +221,9 @@ unsigned int kvm_create_stack_descriptor(struct segment_descriptor *table,
void kvm_get_cpuid(unsigned int eax, unsigned int ecx, struct kvm_cpuid *buf);
void kvm_read_cregs(struct kvm_cregs *buf);
void kvm_read_sregs(struct kvm_sregs *buf);
+void kvm_set_cr0(unsigned long val);
+void kvm_set_cr3(unsigned long val);
+void kvm_set_cr4(unsigned long val);
uint64_t kvm_rdmsr(unsigned int msr);
void kvm_wrmsr(unsigned int msr, uint64_t value);
diff --git a/testcases/kernel/kvm/lib_x86.c b/testcases/kernel/kvm/lib_x86.c
index 8db3abd3f..266d7195c 100644
--- a/testcases/kernel/kvm/lib_x86.c
+++ b/testcases/kernel/kvm/lib_x86.c
@@ -214,6 +214,33 @@ void kvm_get_cpuid(unsigned int eax, unsigned int ecx, struct kvm_cpuid *buf)
);
}
+void kvm_set_cr0(unsigned long val)
+{
+ asm (
+ "mov %0, %%cr0\n"
+ :
+ : "r" (val)
+ );
+}
+
+void kvm_set_cr3(unsigned long val)
+{
+ asm (
+ "mov %0, %%cr3\n"
+ :
+ : "r" (val)
+ );
+}
+
+void kvm_set_cr4(unsigned long val)
+{
+ asm (
+ "mov %0, %%cr4\n"
+ :
+ : "r" (val)
+ );
+}
+
uint64_t kvm_rdmsr(unsigned int msr)
{
unsigned int ret_lo, ret_hi;
--
2.47.0
More information about the ltp
mailing list