[LTP] [PATCH 7/9] KVM: Add VMSAVE/VMLOAD functions to x86 SVM library

Martin Doucha mdoucha@suse.cz
Tue Apr 30 14:22:03 CEST 2024


Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 testcases/kernel/kvm/include/kvm_x86_svm.h |  6 ++++++
 testcases/kernel/kvm/kvm_svm02.c           | 12 ++----------
 testcases/kernel/kvm/lib_x86.c             | 18 ++++++++++++++++++
 3 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/kvm/include/kvm_x86_svm.h b/testcases/kernel/kvm/include/kvm_x86_svm.h
index b4b1b80e2..73563ed2d 100644
--- a/testcases/kernel/kvm/include/kvm_x86_svm.h
+++ b/testcases/kernel/kvm/include/kvm_x86_svm.h
@@ -163,4 +163,10 @@ struct kvm_svm_vcpu *kvm_create_svm_vcpu(int (*guest_main)(void),
 
 void kvm_svm_vmrun(struct kvm_svm_vcpu *cpu);
 
+/* Load FS, GS, TR and LDTR state from vmsave_buf */
+void kvm_svm_vmload(struct kvm_vmcb *buf);
+
+/* Save current FS, GS, TR and LDTR state to vmsave_buf */
+void kvm_svm_vmsave(struct kvm_vmcb *buf);
+
 #endif /* KVM_X86_SVM_H_ */
diff --git a/testcases/kernel/kvm/kvm_svm02.c b/testcases/kernel/kvm/kvm_svm02.c
index f72fb3812..6914fdcba 100644
--- a/testcases/kernel/kvm/kvm_svm02.c
+++ b/testcases/kernel/kvm/kvm_svm02.c
@@ -33,22 +33,14 @@ static void *vmsave_buf;
 /* Load FS, GS, TR and LDTR state from vmsave_buf */
 static int guest_vmload(void)
 {
-	asm (
-		"vmload %0\n"
-		:
-		: "a" (vmsave_buf)
-	);
+	kvm_svm_vmload(vmsave_buf);
 	return 0;
 }
 
 /* Save current FS, GS, TR and LDTR state to vmsave_buf */
 static int guest_vmsave(void)
 {
-	asm (
-		"vmsave %0\n"
-		:
-		: "a" (vmsave_buf)
-	);
+	kvm_svm_vmsave(vmsave_buf);
 	return 0;
 }
 
diff --git a/testcases/kernel/kvm/lib_x86.c b/testcases/kernel/kvm/lib_x86.c
index 1c0e629c3..8db3abd3f 100644
--- a/testcases/kernel/kvm/lib_x86.c
+++ b/testcases/kernel/kvm/lib_x86.c
@@ -393,3 +393,21 @@ struct kvm_svm_vcpu *kvm_create_svm_vcpu(int (*guest_main)(void),
 	ret->vmcb = vmcb;
 	return ret;
 }
+
+void kvm_svm_vmload(struct kvm_vmcb *buf)
+{
+	asm (
+		"vmload %0\n"
+		:
+		: "a" (buf)
+	);
+}
+
+void kvm_svm_vmsave(struct kvm_vmcb *buf)
+{
+	asm (
+		"vmsave %0\n"
+		:
+		: "a" (buf)
+	);
+}
-- 
2.44.0



More information about the ltp mailing list