Skip to content

Commit f6d5826

Browse files
committed
KVM: SVM: retrieve VMCB from assembly
Continue moving accesses to struct vcpu_svm to vmenter.S. Reducing the number of arguments limits the chance of mistakes due to different registers used for argument passing in 32- and 64-bit ABIs; pushing the VMCB argument and almost immediately popping it into a different register looks pretty weird. 32-bit ABI is not a concern for __svm_sev_es_vcpu_run() which is 64-bit only; however, it will soon need @SVM to save/restore SPEC_CTRL so stay consistent with __svm_vcpu_run() and let them share the same prototype. No functional change intended. Cc: stable@vger.kernel.org Fixes: a149180 ("x86: Add magic AMD return-thunk") Reviewed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent f7ef280 commit f6d5826

4 files changed

Lines changed: 16 additions & 15 deletions

File tree

arch/x86/kvm/kvm-asm-offsets.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ static void __used common(void)
1515
if (IS_ENABLED(CONFIG_KVM_AMD)) {
1616
BLANK();
1717
OFFSET(SVM_vcpu_arch_regs, vcpu_svm, vcpu.arch.regs);
18+
OFFSET(SVM_current_vmcb, vcpu_svm, current_vmcb);
19+
OFFSET(KVM_VMCB_pa, kvm_vmcb_info, pa);
1820
}
1921

2022
if (IS_ENABLED(CONFIG_KVM_INTEL)) {

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3914,12 +3914,11 @@ static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
39143914
static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
39153915
{
39163916
struct vcpu_svm *svm = to_svm(vcpu);
3917-
unsigned long vmcb_pa = svm->current_vmcb->pa;
39183917

39193918
guest_state_enter_irqoff();
39203919

39213920
if (sev_es_guest(vcpu->kvm)) {
3922-
__svm_sev_es_vcpu_run(vmcb_pa);
3921+
__svm_sev_es_vcpu_run(svm);
39233922
} else {
39243923
struct svm_cpu_data *sd = per_cpu(svm_data, vcpu->cpu);
39253924

@@ -3930,7 +3929,7 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu)
39303929
* vmcb02 when switching vmcbs for nested virtualization.
39313930
*/
39323931
vmload(svm->vmcb01.pa);
3933-
__svm_vcpu_run(vmcb_pa, svm);
3932+
__svm_vcpu_run(svm);
39343933
vmsave(svm->vmcb01.pa);
39353934

39363935
vmload(__sme_page_pa(sd->save_area));

arch/x86/kvm/svm/svm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ void sev_es_unmap_ghcb(struct vcpu_svm *svm);
683683

684684
/* vmenter.S */
685685

686-
void __svm_sev_es_vcpu_run(unsigned long vmcb_pa);
687-
void __svm_vcpu_run(unsigned long vmcb_pa, struct vcpu_svm *svm);
686+
void __svm_sev_es_vcpu_run(struct vcpu_svm *svm);
687+
void __svm_vcpu_run(struct vcpu_svm *svm);
688688

689689
#endif

arch/x86/kvm/svm/vmenter.S

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
/**
3434
* __svm_vcpu_run - Run a vCPU via a transition to SVM guest mode
35-
* @vmcb_pa: unsigned long
3635
* @svm: struct vcpu_svm *
3736
*/
3837
SYM_FUNC_START(__svm_vcpu_run)
@@ -49,16 +48,16 @@ SYM_FUNC_START(__svm_vcpu_run)
4948
push %_ASM_BX
5049

5150
/* Save @svm. */
52-
push %_ASM_ARG2
53-
54-
/* Save @vmcb. */
5551
push %_ASM_ARG1
5652

53+
.ifnc _ASM_ARG1, _ASM_DI
5754
/* Move @svm to RDI. */
58-
mov %_ASM_ARG2, %_ASM_DI
55+
mov %_ASM_ARG1, %_ASM_DI
56+
.endif
5957

60-
/* "POP" @vmcb to RAX. */
61-
pop %_ASM_AX
58+
/* Get svm->current_vmcb->pa into RAX. */
59+
mov SVM_current_vmcb(%_ASM_DI), %_ASM_AX
60+
mov KVM_VMCB_pa(%_ASM_AX), %_ASM_AX
6261

6362
/* Load guest registers. */
6463
mov VCPU_RCX(%_ASM_DI), %_ASM_CX
@@ -170,7 +169,7 @@ SYM_FUNC_END(__svm_vcpu_run)
170169

171170
/**
172171
* __svm_sev_es_vcpu_run - Run a SEV-ES vCPU via a transition to SVM guest mode
173-
* @vmcb_pa: unsigned long
172+
* @svm: struct vcpu_svm *
174173
*/
175174
SYM_FUNC_START(__svm_sev_es_vcpu_run)
176175
push %_ASM_BP
@@ -185,8 +184,9 @@ SYM_FUNC_START(__svm_sev_es_vcpu_run)
185184
#endif
186185
push %_ASM_BX
187186

188-
/* Move @vmcb to RAX. */
189-
mov %_ASM_ARG1, %_ASM_AX
187+
/* Get svm->current_vmcb->pa into RAX. */
188+
mov SVM_current_vmcb(%_ASM_ARG1), %_ASM_AX
189+
mov KVM_VMCB_pa(%_ASM_AX), %_ASM_AX
190190

191191
/* Enter guest mode */
192192
sti

0 commit comments

Comments
 (0)