[PATCH v2 1/3] HV: Add the emulation of CPUID with 0x16 leaf


Zhao, Yakui
 

The CPUID with 0x16 leaf can report the CPU khz and it is faster. And this
mechanism is widely used in Linux kernel.(native_calibrate_cpu).
As this is not supported on APL, currently sos adds the cpu_khz callback
in pv_cpu_ops to read the cpu frequency. This is quite hack.
(In fact HV leverages the cpuid with 0x40000010 leaf).
If it is emulated, the sos and guest os can use the cpuid to obtain the
corresponding cpu_khz. Then the cpu_khz in pv_cpu_ops can be removed.

V2: Simple the logic of adding unsupported cpuid level entry after the
CPUID 0x16 is emulated. Initialize the vcpuid_entry explicitly with zero
for the unsupported cpuid.

Signed-off-by: Zhao Yakui <yakui.zhao@...>
---
hypervisor/arch/x86/cpuid.c | 53 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/hypervisor/arch/x86/cpuid.c b/hypervisor/arch/x86/cpuid.c
index 18ebfcc..6d53a30 100644
--- a/hypervisor/arch/x86/cpuid.c
+++ b/hypervisor/arch/x86/cpuid.c
@@ -119,6 +119,21 @@ static void init_vcpuid_entry(__unused struct vm *vm,
entry->ecx = 0U;
entry->edx = 0U;
break;
+ case 0x16U:
+ if (boot_cpu_data.cpuid_level >= 0x16U) {
+ /* call the cpuid when 0x16 is supported */
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ } else {
+ /* Use the tsc to derive the emulated 0x16U cpuid. */
+ entry->eax = (uint32_t) (tsc_khz / 1000U);
+ entry->ebx = entry->eax;
+ /* Bus frequency: hard coded to 100M */
+ entry->ecx = 100U;
+ entry->edx = 0U;
+ }
+ break;

/*
* Leaf 0x40000000
@@ -158,9 +173,36 @@ static void init_vcpuid_entry(__unused struct vm *vm,
break;

default:
- cpuid_subleaf(leaf, subleaf,
- &entry->eax, &entry->ebx,
- &entry->ecx, &entry->edx);
+ if (leaf >= 0x80000000U) {
+ /* unsupported extended cpuid level */
+ if (leaf > boot_cpu_data.extended_cpuid_level) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ }
+ } else if (leaf >= 0x40000000U) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ /* unsupported cpuid level */
+ if (leaf > boot_cpu_data.cpuid_level) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ }
+ }
break;
}
}
@@ -173,6 +215,11 @@ int set_vcpuid_entries(struct vm *vm)
uint32_t i, j;

init_vcpuid_entry(vm, 0U, 0U, 0U, &entry);
+ if (boot_cpu_data.cpuid_level < 0x16U) {
+ /* The cpuid with zero leaf returns the max level.
+ * Emulate that the 0x16U is supported */
+ entry.eax = 0x16U;
+ }
result = set_vcpuid_entry(vm, &entry);
if (result != 0) {
return result;
--
2.7.4


Eddie Dong
 

Hi Yakui:
With this patch, in case the physical processor support less than 0x15 subleaves, we have to quit the execution, please add this logic in hardware_detect_support.

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...] On Behalf Of Zhao, Yakui
Sent: Friday, August 10, 2018 2:44 PM
To: acrn-dev@...
Cc: Zhao, Yakui <yakui.zhao@...>
Subject: [acrn-dev] [PATCH v2 1/3] HV: Add the emulation of CPUID with
0x16 leaf

The CPUID with 0x16 leaf can report the CPU khz and it is faster. And this
mechanism is widely used in Linux kernel.(native_calibrate_cpu).
As this is not supported on APL, currently sos adds the cpu_khz callback in
pv_cpu_ops to read the cpu frequency. This is quite hack.
(In fact HV leverages the cpuid with 0x40000010 leaf).
If it is emulated, the sos and guest os can use the cpuid to obtain the
corresponding cpu_khz. Then the cpu_khz in pv_cpu_ops can be removed.

V2: Simple the logic of adding unsupported cpuid level entry after the CPUID
0x16 is emulated. Initialize the vcpuid_entry explicitly with zero for the
unsupported cpuid.

Signed-off-by: Zhao Yakui <yakui.zhao@...>
---
hypervisor/arch/x86/cpuid.c | 53
++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/hypervisor/arch/x86/cpuid.c b/hypervisor/arch/x86/cpuid.c index
18ebfcc..6d53a30 100644
--- a/hypervisor/arch/x86/cpuid.c
+++ b/hypervisor/arch/x86/cpuid.c
@@ -119,6 +119,21 @@ static void init_vcpuid_entry(__unused struct vm
*vm,
entry->ecx = 0U;
entry->edx = 0U;
break;
+ case 0x16U:
+ if (boot_cpu_data.cpuid_level >= 0x16U) {
+ /* call the cpuid when 0x16 is supported */
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ } else {
+ /* Use the tsc to derive the emulated 0x16U cpuid. */
+ entry->eax = (uint32_t) (tsc_khz / 1000U);
+ entry->ebx = entry->eax;
+ /* Bus frequency: hard coded to 100M */
+ entry->ecx = 100U;
+ entry->edx = 0U;
+ }
+ break;

/*
* Leaf 0x40000000
@@ -158,9 +173,36 @@ static void init_vcpuid_entry(__unused struct vm
*vm,
break;

default:
- cpuid_subleaf(leaf, subleaf,
- &entry->eax, &entry->ebx,
- &entry->ecx, &entry->edx);
+ if (leaf >= 0x80000000U) {
+ /* unsupported extended cpuid level */
+ if (leaf > boot_cpu_data.extended_cpuid_level) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ }
+ } else if (leaf >= 0x40000000U) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ /* unsupported cpuid level */
+ if (leaf > boot_cpu_data.cpuid_level) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ }
+ }
This part is for the added subleaf. Can we merge the condition check part (since the processing part is same)?

BTW, why we need to process leaf 0x40000000U here? This is same with before..

break;
}
}
@@ -173,6 +215,11 @@ int set_vcpuid_entries(struct vm *vm)
uint32_t i, j;

init_vcpuid_entry(vm, 0U, 0U, 0U, &entry);
+ if (boot_cpu_data.cpuid_level < 0x16U) {
+ /* The cpuid with zero leaf returns the max level.
+ * Emulate that the 0x16U is supported */
+ entry.eax = 0x16U;
+ }
result = set_vcpuid_entry(vm, &entry);
if (result != 0) {
return result;
--
2.7.4



Zhao, Yakui
 

-----Original Message-----
From: Dong, Eddie
Sent: Friday, August 10, 2018 3:36 PM
To: acrn-dev@...
Cc: Zhao, Yakui <yakui.zhao@...>
Subject: RE: [acrn-dev] [PATCH v2 1/3] HV: Add the emulation of CPUID with
0x16 leaf

Hi Yakui:
With this patch, in case the physical processor support less than 0x15
subleaves, we have to quit the execution, please add this logic in
hardware_detect_support.
Sure. I will try to add the check in hardware_detect_support.

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...] On Behalf Of Zhao, Yakui
Sent: Friday, August 10, 2018 2:44 PM
To: acrn-dev@...
Cc: Zhao, Yakui <yakui.zhao@...>
Subject: [acrn-dev] [PATCH v2 1/3] HV: Add the emulation of CPUID with
0x16 leaf

The CPUID with 0x16 leaf can report the CPU khz and it is faster. And
this mechanism is widely used in Linux kernel.(native_calibrate_cpu).
As this is not supported on APL, currently sos adds the cpu_khz
callback in pv_cpu_ops to read the cpu frequency. This is quite hack.
(In fact HV leverages the cpuid with 0x40000010 leaf).
If it is emulated, the sos and guest os can use the cpuid to obtain
the corresponding cpu_khz. Then the cpu_khz in pv_cpu_ops can be
removed.

V2: Simple the logic of adding unsupported cpuid level entry after the
CPUID
0x16 is emulated. Initialize the vcpuid_entry explicitly with zero for
the unsupported cpuid.

Signed-off-by: Zhao Yakui <yakui.zhao@...>
---
hypervisor/arch/x86/cpuid.c | 53
++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/hypervisor/arch/x86/cpuid.c b/hypervisor/arch/x86/cpuid.c
index
18ebfcc..6d53a30 100644
--- a/hypervisor/arch/x86/cpuid.c
+++ b/hypervisor/arch/x86/cpuid.c
@@ -119,6 +119,21 @@ static void init_vcpuid_entry(__unused struct vm
*vm,
entry->ecx = 0U;
entry->edx = 0U;
break;
+ case 0x16U:
+ if (boot_cpu_data.cpuid_level >= 0x16U) {
+ /* call the cpuid when 0x16 is supported */
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ } else {
+ /* Use the tsc to derive the emulated 0x16U cpuid. */
+ entry->eax = (uint32_t) (tsc_khz / 1000U);
+ entry->ebx = entry->eax;
+ /* Bus frequency: hard coded to 100M */
+ entry->ecx = 100U;
+ entry->edx = 0U;
+ }
+ break;

/*
* Leaf 0x40000000
@@ -158,9 +173,36 @@ static void init_vcpuid_entry(__unused struct vm
*vm,
break;

default:
- cpuid_subleaf(leaf, subleaf,
- &entry->eax, &entry->ebx,
- &entry->ecx, &entry->edx);
+ if (leaf >= 0x80000000U) {
+ /* unsupported extended cpuid level */
+ if (leaf > boot_cpu_data.extended_cpuid_level) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ }
+ } else if (leaf >= 0x40000000U) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ /* unsupported cpuid level */
+ if (leaf > boot_cpu_data.cpuid_level) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ }
+ }
This part is for the added subleaf. Can we merge the condition check part
(since the processing part is same)?

BTW, why we need to process leaf 0x40000000U here? This is same with
before..

break;
}
}
@@ -173,6 +215,11 @@ int set_vcpuid_entries(struct vm *vm)
uint32_t i, j;

init_vcpuid_entry(vm, 0U, 0U, 0U, &entry);
+ if (boot_cpu_data.cpuid_level < 0x16U) {
+ /* The cpuid with zero leaf returns the max level.
+ * Emulate that the 0x16U is supported */
+ entry.eax = 0x16U;
+ }
result = set_vcpuid_entry(vm, &entry);
if (result != 0) {
return result;
--
2.7.4



Xu, Anthony
 

Hi Yakui,

ACRN doesn't emulate CPUID >=0x80000000U at all.
So for CPUID >=0x80000000U, ACRN just read from hardware in guest_cpuid().
init_vcpuid_entry doesn't need to handle CPUID >=0x80000000U.


Anthony

-----Original Message-----
From: acrn-dev@... [mailto:acrn-dev@...]
On Behalf Of Zhao, Yakui
Sent: Thursday, August 9, 2018 11:44 PM
To: acrn-dev@...
Cc: Zhao, Yakui <yakui.zhao@...>
Subject: [acrn-dev] [PATCH v2 1/3] HV: Add the emulation of CPUID with
0x16 leaf

The CPUID with 0x16 leaf can report the CPU khz and it is faster. And this
mechanism is widely used in Linux kernel.(native_calibrate_cpu).
As this is not supported on APL, currently sos adds the cpu_khz callback
in pv_cpu_ops to read the cpu frequency. This is quite hack.
(In fact HV leverages the cpuid with 0x40000010 leaf).
If it is emulated, the sos and guest os can use the cpuid to obtain the
corresponding cpu_khz. Then the cpu_khz in pv_cpu_ops can be removed.

V2: Simple the logic of adding unsupported cpuid level entry after the
CPUID 0x16 is emulated. Initialize the vcpuid_entry explicitly with zero
for the unsupported cpuid.

Signed-off-by: Zhao Yakui <yakui.zhao@...>
---
hypervisor/arch/x86/cpuid.c | 53
++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/hypervisor/arch/x86/cpuid.c b/hypervisor/arch/x86/cpuid.c
index 18ebfcc..6d53a30 100644
--- a/hypervisor/arch/x86/cpuid.c
+++ b/hypervisor/arch/x86/cpuid.c
@@ -119,6 +119,21 @@ static void init_vcpuid_entry(__unused struct vm
*vm,
entry->ecx = 0U;
entry->edx = 0U;
break;
+ case 0x16U:
+ if (boot_cpu_data.cpuid_level >= 0x16U) {
+ /* call the cpuid when 0x16 is supported */
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ } else {
+ /* Use the tsc to derive the emulated 0x16U cpuid.
*/
+ entry->eax = (uint32_t) (tsc_khz / 1000U);
+ entry->ebx = entry->eax;
+ /* Bus frequency: hard coded to 100M */
+ entry->ecx = 100U;
+ entry->edx = 0U;
+ }
+ break;

/*
* Leaf 0x40000000
@@ -158,9 +173,36 @@ static void init_vcpuid_entry(__unused struct vm
*vm,
break;

default:
- cpuid_subleaf(leaf, subleaf,
- &entry->eax, &entry->ebx,
- &entry->ecx, &entry->edx);
+ if (leaf >= 0x80000000U) {
+ /* unsupported extended cpuid level */
+ if (leaf > boot_cpu_data.extended_cpuid_level) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ }
+ } else if (leaf >= 0x40000000U) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ /* unsupported cpuid level */
+ if (leaf > boot_cpu_data.cpuid_level) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ }
+ }
break;
}
}
@@ -173,6 +215,11 @@ int set_vcpuid_entries(struct vm *vm)
uint32_t i, j;

init_vcpuid_entry(vm, 0U, 0U, 0U, &entry);
+ if (boot_cpu_data.cpuid_level < 0x16U) {
+ /* The cpuid with zero leaf returns the max level.
+ * Emulate that the 0x16U is supported */
+ entry.eax = 0x16U;
+ }
result = set_vcpuid_entry(vm, &entry);
if (result != 0) {
return result;
--
2.7.4



Zhao, Yakui
 

-----Original Message-----
From: Xu, Anthony
Sent: Saturday, August 11, 2018 5:47 AM
To: acrn-dev@...
Cc: Zhao, Yakui <yakui.zhao@...>
Subject: RE: [acrn-dev] [PATCH v2 1/3] HV: Add the emulation of CPUID with
0x16 leaf

Hi Yakui,

ACRN doesn't emulate CPUID >=0x80000000U at all.
So for CPUID >=0x80000000U, ACRN just read from hardware in guest_cpuid().
init_vcpuid_entry doesn't need to handle CPUID >=0x80000000U.
After Eddie's suggestion is followed to add the limit check(>=0x15 CPUID), the mentioned check is not needed any more.

I keep them so that the init_vcpuid_entry still can return the zero entry for the out-of-range CPUID input.

If you think that the check is redundant, I can remove them.



Anthony



-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...]
On Behalf Of Zhao, Yakui
Sent: Thursday, August 9, 2018 11:44 PM
To: acrn-dev@...
Cc: Zhao, Yakui <yakui.zhao@...>
Subject: [acrn-dev] [PATCH v2 1/3] HV: Add the emulation of CPUID with
0x16 leaf

The CPUID with 0x16 leaf can report the CPU khz and it is faster. And
this mechanism is widely used in Linux kernel.(native_calibrate_cpu).
As this is not supported on APL, currently sos adds the cpu_khz
callback in pv_cpu_ops to read the cpu frequency. This is quite hack.
(In fact HV leverages the cpuid with 0x40000010 leaf).
If it is emulated, the sos and guest os can use the cpuid to obtain
the corresponding cpu_khz. Then the cpu_khz in pv_cpu_ops can be
removed.

V2: Simple the logic of adding unsupported cpuid level entry after the
CPUID 0x16 is emulated. Initialize the vcpuid_entry explicitly with
zero for the unsupported cpuid.

Signed-off-by: Zhao Yakui <yakui.zhao@...>
---
hypervisor/arch/x86/cpuid.c | 53
++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/hypervisor/arch/x86/cpuid.c b/hypervisor/arch/x86/cpuid.c
index 18ebfcc..6d53a30 100644
--- a/hypervisor/arch/x86/cpuid.c
+++ b/hypervisor/arch/x86/cpuid.c
@@ -119,6 +119,21 @@ static void init_vcpuid_entry(__unused struct vm
*vm,
entry->ecx = 0U;
entry->edx = 0U;
break;
+ case 0x16U:
+ if (boot_cpu_data.cpuid_level >= 0x16U) {
+ /* call the cpuid when 0x16 is supported */
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ } else {
+ /* Use the tsc to derive the emulated 0x16U cpuid.
*/
+ entry->eax = (uint32_t) (tsc_khz / 1000U);
+ entry->ebx = entry->eax;
+ /* Bus frequency: hard coded to 100M */
+ entry->ecx = 100U;
+ entry->edx = 0U;
+ }
+ break;

/*
* Leaf 0x40000000
@@ -158,9 +173,36 @@ static void init_vcpuid_entry(__unused struct vm
*vm,
break;

default:
- cpuid_subleaf(leaf, subleaf,
- &entry->eax, &entry->ebx,
- &entry->ecx, &entry->edx);
+ if (leaf >= 0x80000000U) {
+ /* unsupported extended cpuid level */
+ if (leaf > boot_cpu_data.extended_cpuid_level) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ }
+ } else if (leaf >= 0x40000000U) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ /* unsupported cpuid level */
+ if (leaf > boot_cpu_data.cpuid_level) {
+ entry->eax = 0U;
+ entry->ebx = 0U;
+ entry->ecx = 0U;
+ entry->edx = 0U;
+ } else {
+ cpuid_subleaf(leaf, subleaf,
+ &entry->eax, &entry->ebx,
+ &entry->ecx, &entry->edx);
+ }
+ }
break;
}
}
@@ -173,6 +215,11 @@ int set_vcpuid_entries(struct vm *vm)
uint32_t i, j;

init_vcpuid_entry(vm, 0U, 0U, 0U, &entry);
+ if (boot_cpu_data.cpuid_level < 0x16U) {
+ /* The cpuid with zero leaf returns the max level.
+ * Emulate that the 0x16U is supported */
+ entry.eax = 0x16U;
+ }
result = set_vcpuid_entry(vm, &entry);
if (result != 0) {
return result;
--
2.7.4



Eddie Dong
 

Hi Yakui,

ACRN doesn't emulate CPUID >=0x80000000U at all.
So for CPUID >=0x80000000U, ACRN just read from hardware in
guest_cpuid().
init_vcpuid_entry doesn't need to handle CPUID >=0x80000000U.
After Eddie's suggestion is followed to add the limit check(>=0x15 CPUID),
the mentioned check is not needed any more.

I keep them so that the init_vcpuid_entry still can return the zero entry for
the out-of-range CPUID input.

If you think that the check is redundant, I can remove them.
If it is physical out of ranger, returning what hardware returns is better than fixed-zero.

We want the code to be slim to save FuSa effort.

Thx Eddie


Zhao, Yakui
 

-----Original Message-----
From: acrn-dev@... [mailto:acrn-dev@...]
On Behalf Of Eddie Dong
Sent: Monday, August 13, 2018 4:04 PM
To: acrn-dev@...; Xu, Anthony <anthony.xu@...>
Subject: Re: [acrn-dev] [PATCH v2 1/3] HV: Add the emulation of CPUID with
0x16 leaf

Hi Yakui,

ACRN doesn't emulate CPUID >=0x80000000U at all.
So for CPUID >=0x80000000U, ACRN just read from hardware in
guest_cpuid().
init_vcpuid_entry doesn't need to handle CPUID >=0x80000000U.
After Eddie's suggestion is followed to add the limit check(>=0x15
CPUID), the mentioned check is not needed any more.

I keep them so that the init_vcpuid_entry still can return the zero
entry for the out-of-range CPUID input.

If you think that the check is redundant, I can remove them.
If it is physical out of ranger, returning what hardware returns is better than
fixed-zero.

We want the code to be slim to save FuSa effort.
OK. I will remove them.


Thx Eddie


Li, Fei1
 

On Mon, Aug 13, 2018 at 10:18:24AM +0000, Zhao, Yakui wrote:


-----Original Message-----
From: acrn-dev@... [mailto:acrn-dev@...]
On Behalf Of Eddie Dong
Sent: Monday, August 13, 2018 4:04 PM
To: acrn-dev@...; Xu, Anthony <anthony.xu@...>
Subject: Re: [acrn-dev] [PATCH v2 1/3] HV: Add the emulation of CPUID with
0x16 leaf

Hi Yakui,

ACRN doesn't emulate CPUID >=0x80000000U at all.
So for CPUID >=0x80000000U, ACRN just read from hardware in
guest_cpuid().
init_vcpuid_entry doesn't need to handle CPUID >=0x80000000U.
After Eddie's suggestion is followed to add the limit check(>=0x15
CPUID), the mentioned check is not needed any more.

I keep them so that the init_vcpuid_entry still can return the zero
entry for the out-of-range CPUID input.

If you think that the check is redundant, I can remove them.
The vcpuid base on these assumption:
(1) if we don't plan to support this feature, we could filter it.
(2) if the leaf greater than the limit (base or enternal), we should return the value in the limit leaf.
(3) If we plan to emulate some feature, like the cpu frequency, we could add an emulate entry for it.
So init_vcpuid_entry only needs to take care the leaf which needs to emulate/fliter/disable
some features. I don't think what you did about leaf over 0x80000000U lie in this scope.
Thanks.
If it is physical out of ranger, returning what hardware returns is better than
fixed-zero.

We want the code to be slim to save FuSa effort.
OK. I will remove them.


Thx Eddie