Skip to content

Commit 6162b37

Browse files
Binbin Wubonzini
authored andcommitted
KVM: x86: Have ____kvm_emulate_hypercall() read the GPRs
Have ____kvm_emulate_hypercall() read the GPRs instead of passing them in via the macro. When emulating KVM hypercalls via TDVMCALL, TDX will marshall registers of TDVMCALL ABI into KVM's x86 registers to match the definition of KVM hypercall ABI _before_ ____kvm_emulate_hypercall() gets called. Therefore, ____kvm_emulate_hypercall() can just read registers internally based on KVM hypercall ABI, and those registers can be removed from the __kvm_emulate_hypercall() macro. Also, op_64_bit can be determined inside ____kvm_emulate_hypercall(), remove it from the __kvm_emulate_hypercall() macro as well. No functional change intended. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Message-ID: <20250222014225.897298-2-binbin.wu@linux.intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 484612f commit 6162b37

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

arch/x86/kvm/x86.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10030,13 +10030,16 @@ static int complete_hypercall_exit(struct kvm_vcpu *vcpu)
1003010030
return kvm_skip_emulated_instruction(vcpu);
1003110031
}
1003210032

10033-
int ____kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr,
10034-
unsigned long a0, unsigned long a1,
10035-
unsigned long a2, unsigned long a3,
10036-
int op_64_bit, int cpl,
10033+
int ____kvm_emulate_hypercall(struct kvm_vcpu *vcpu, int cpl,
1003710034
int (*complete_hypercall)(struct kvm_vcpu *))
1003810035
{
1003910036
unsigned long ret;
10037+
unsigned long nr = kvm_rax_read(vcpu);
10038+
unsigned long a0 = kvm_rbx_read(vcpu);
10039+
unsigned long a1 = kvm_rcx_read(vcpu);
10040+
unsigned long a2 = kvm_rdx_read(vcpu);
10041+
unsigned long a3 = kvm_rsi_read(vcpu);
10042+
int op_64_bit = is_64_bit_hypercall(vcpu);
1004010043

1004110044
++vcpu->stat.hypercalls;
1004210045

@@ -10139,9 +10142,7 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
1013910142
if (kvm_hv_hypercall_enabled(vcpu))
1014010143
return kvm_hv_hypercall(vcpu);
1014110144

10142-
return __kvm_emulate_hypercall(vcpu, rax, rbx, rcx, rdx, rsi,
10143-
is_64_bit_hypercall(vcpu),
10144-
kvm_x86_call(get_cpl)(vcpu),
10145+
return __kvm_emulate_hypercall(vcpu, kvm_x86_call(get_cpl)(vcpu),
1014510146
complete_hypercall_exit);
1014610147
}
1014710148
EXPORT_SYMBOL_GPL(kvm_emulate_hypercall);

arch/x86/kvm/x86.h

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -621,25 +621,17 @@ static inline bool user_exit_on_hypercall(struct kvm *kvm, unsigned long hc_nr)
621621
return kvm->arch.hypercall_exit_enabled & BIT(hc_nr);
622622
}
623623

624-
int ____kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr,
625-
unsigned long a0, unsigned long a1,
626-
unsigned long a2, unsigned long a3,
627-
int op_64_bit, int cpl,
624+
int ____kvm_emulate_hypercall(struct kvm_vcpu *vcpu, int cpl,
628625
int (*complete_hypercall)(struct kvm_vcpu *));
629626

630-
#define __kvm_emulate_hypercall(_vcpu, nr, a0, a1, a2, a3, op_64_bit, cpl, complete_hypercall) \
631-
({ \
632-
int __ret; \
633-
\
634-
__ret = ____kvm_emulate_hypercall(_vcpu, \
635-
kvm_##nr##_read(_vcpu), kvm_##a0##_read(_vcpu), \
636-
kvm_##a1##_read(_vcpu), kvm_##a2##_read(_vcpu), \
637-
kvm_##a3##_read(_vcpu), op_64_bit, cpl, \
638-
complete_hypercall); \
639-
\
640-
if (__ret > 0) \
641-
__ret = complete_hypercall(_vcpu); \
642-
__ret; \
627+
#define __kvm_emulate_hypercall(_vcpu, cpl, complete_hypercall) \
628+
({ \
629+
int __ret; \
630+
__ret = ____kvm_emulate_hypercall(_vcpu, cpl, complete_hypercall); \
631+
\
632+
if (__ret > 0) \
633+
__ret = complete_hypercall(_vcpu); \
634+
__ret; \
643635
})
644636

645637
int kvm_emulate_hypercall(struct kvm_vcpu *vcpu);

0 commit comments

Comments
 (0)