Skip to content

Commit 27700e7

Browse files
mdouchapevik
authored andcommitted
KVM: Add VMSAVE/VMLOAD functions to x86 SVM library
Link: https://lore.kernel.org/ltp/[email protected]/ Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Martin Doucha <[email protected]>
1 parent e93dc21 commit 27700e7

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

testcases/kernel/kvm/include/kvm_x86_svm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,10 @@ struct kvm_svm_vcpu *kvm_create_svm_vcpu(int (*guest_main)(void),
163163

164164
void kvm_svm_vmrun(struct kvm_svm_vcpu *cpu);
165165

166+
/* Load FS, GS, TR and LDTR state from vmsave_buf */
167+
void kvm_svm_vmload(struct kvm_vmcb *buf);
168+
169+
/* Save current FS, GS, TR and LDTR state to vmsave_buf */
170+
void kvm_svm_vmsave(struct kvm_vmcb *buf);
171+
166172
#endif /* KVM_X86_SVM_H_ */

testcases/kernel/kvm/kvm_svm02.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,14 @@ static void *vmsave_buf;
3333
/* Load FS, GS, TR and LDTR state from vmsave_buf */
3434
static int guest_vmload(void)
3535
{
36-
asm (
37-
"vmload %0\n"
38-
:
39-
: "a" (vmsave_buf)
40-
);
36+
kvm_svm_vmload(vmsave_buf);
4137
return 0;
4238
}
4339

4440
/* Save current FS, GS, TR and LDTR state to vmsave_buf */
4541
static int guest_vmsave(void)
4642
{
47-
asm (
48-
"vmsave %0\n"
49-
:
50-
: "a" (vmsave_buf)
51-
);
43+
kvm_svm_vmsave(vmsave_buf);
5244
return 0;
5345
}
5446

testcases/kernel/kvm/lib_x86.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,21 @@ struct kvm_svm_vcpu *kvm_create_svm_vcpu(int (*guest_main)(void),
393393
ret->vmcb = vmcb;
394394
return ret;
395395
}
396+
397+
void kvm_svm_vmload(struct kvm_vmcb *buf)
398+
{
399+
asm (
400+
"vmload %0\n"
401+
:
402+
: "a" (buf)
403+
);
404+
}
405+
406+
void kvm_svm_vmsave(struct kvm_vmcb *buf)
407+
{
408+
asm (
409+
"vmsave %0\n"
410+
:
411+
: "a" (buf)
412+
);
413+
}

0 commit comments

Comments
 (0)