Skip to content

Commit a56abee

Browse files
lifeixwenlingz
authored andcommitted
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 <fei1.li@intel.com>
1 parent 58d2a41 commit a56abee

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

hypervisor/arch/x86/guest/vcpuid.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
#include <hypervisor.h>
88

9-
static inline struct vcpuid_entry *find_vcpuid_entry(const struct acrn_vcpu *vcpu,
10-
uint32_t leaf_arg, uint32_t subleaf)
9+
static inline struct vcpuid_entry *local_find_vcpuid_entry(const struct acrn_vcpu *vcpu,
10+
uint32_t leaf, uint32_t subleaf)
1111
{
1212
uint32_t i = 0U, nr, half;
1313
struct vcpuid_entry *entry = NULL;
1414
struct acrn_vm *vm = vcpu->vm;
15-
uint32_t leaf = leaf_arg;
1615

1716
nr = vm->vcpuid_entry_nr;
1817
half = nr >> 1U;
@@ -38,8 +37,19 @@ static inline struct vcpuid_entry *find_vcpuid_entry(const struct acrn_vcpu *vcp
3837
}
3938
}
4039

40+
return entry;
41+
}
42+
43+
static inline struct vcpuid_entry *find_vcpuid_entry(const struct acrn_vcpu *vcpu,
44+
uint32_t leaf_arg, uint32_t subleaf)
45+
{
46+
struct vcpuid_entry *entry;
47+
uint32_t leaf = leaf_arg;
48+
49+
entry = local_find_vcpuid_entry(vcpu, leaf, subleaf);
4150
if (entry == NULL) {
4251
uint32_t limit;
52+
struct acrn_vm *vm = vcpu->vm;
4353

4454
if ((leaf & 0x80000000U) != 0U) {
4555
limit = vm->vcpuid_xlevel;
@@ -55,7 +65,7 @@ static inline struct vcpuid_entry *find_vcpuid_entry(const struct acrn_vcpu *vcp
5565
* CPUID)
5666
*/
5767
leaf = vm->vcpuid_level;
58-
return find_vcpuid_entry(vcpu, leaf, subleaf);
68+
entry = local_find_vcpuid_entry(vcpu, leaf, subleaf);
5969
}
6070

6171
}

0 commit comments

Comments
 (0)