From a56abee9ff4523a3fa9904ff6f6dba5f29b7204f Mon Sep 17 00:00:00 2001 From: "Li, Fei1" Date: Thu, 20 Dec 2018 17:55:35 +0800 Subject: [PATCH] hv: coding style: refine find_vcpuid_entry 1) add local_find_vcpuid_entry to find whether a cpuid leaf exist in vcpuid cache entries. 2) find_vcpuid_entry will return the found entry if local_find_vcpuid_entry return is not null. Otherwise, call local_find_vcpuid_entry again when necessary. In this case, there could eliminate recursion in find_vcpuid_entry. Tracked-On: #861 Signed-off-by: Li, Fei1 --- hypervisor/arch/x86/guest/vcpuid.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/hypervisor/arch/x86/guest/vcpuid.c b/hypervisor/arch/x86/guest/vcpuid.c index 5a6b0c0dc..e98a1a512 100644 --- a/hypervisor/arch/x86/guest/vcpuid.c +++ b/hypervisor/arch/x86/guest/vcpuid.c @@ -6,13 +6,12 @@ #include -static inline struct vcpuid_entry *find_vcpuid_entry(const struct acrn_vcpu *vcpu, - uint32_t leaf_arg, uint32_t subleaf) +static inline struct vcpuid_entry *local_find_vcpuid_entry(const struct acrn_vcpu *vcpu, + uint32_t leaf, uint32_t subleaf) { uint32_t i = 0U, nr, half; struct vcpuid_entry *entry = NULL; struct acrn_vm *vm = vcpu->vm; - uint32_t leaf = leaf_arg; nr = vm->vcpuid_entry_nr; half = nr >> 1U; @@ -38,8 +37,19 @@ static inline struct vcpuid_entry *find_vcpuid_entry(const struct acrn_vcpu *vcp } } + return entry; +} + +static inline struct vcpuid_entry *find_vcpuid_entry(const struct acrn_vcpu *vcpu, + uint32_t leaf_arg, uint32_t subleaf) +{ + struct vcpuid_entry *entry; + uint32_t leaf = leaf_arg; + + entry = local_find_vcpuid_entry(vcpu, leaf, subleaf); if (entry == NULL) { uint32_t limit; + struct acrn_vm *vm = vcpu->vm; if ((leaf & 0x80000000U) != 0U) { limit = vm->vcpuid_xlevel; @@ -55,7 +65,7 @@ static inline struct vcpuid_entry *find_vcpuid_entry(const struct acrn_vcpu *vcp * CPUID) */ leaf = vm->vcpuid_level; - return find_vcpuid_entry(vcpu, leaf, subleaf); + entry = local_find_vcpuid_entry(vcpu, leaf, subleaf); } }