[PATCH 2/4] hv: remove pstate/cstate support for VMs that share pCPU


Zhou, Wu
 

Only when the a post-launched VM is not sharing pCPUs and no RTVM
is setup in the scenario, the pCPU’s pstate/cstate can be
passed-though to the VM.

The VM_PX_CX_CAPABILITY macro is generated by config_tools, this
patch simply use it to determine whether a VM can have pstate/cstate.
If it is negative, the px_cnt and cx_cnt will be zero. The dm will
also get 0 for px_cnt and cx_cnt on hypercall, and the VM will get
no pstate/cstate.

Signed-off-by: Zhou, Wu <wu.zhou@...>
---
hypervisor/arch/x86/guest/pm.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hypervisor/arch/x86/guest/pm.c b/hypervisor/arch/x86/guest/pm.c
index 9771dda72..acf12bbcb 100644
--- a/hypervisor/arch/x86/guest/pm.c
+++ b/hypervisor/arch/x86/guest/pm.c
@@ -59,7 +59,8 @@ static void vm_setup_cpu_px(struct acrn_vm *vm)
vm->pm.px_cnt = 0U;
(void)memset(vm->pm.px_data, 0U, MAX_PSTATE * sizeof(struct acrn_pstate_data));

- if ((pm_state_info->px_cnt != 0U) && (pm_state_info->px_data != NULL)) {
+ if ((pm_state_info->px_cnt != 0U) && (pm_state_info->px_data != NULL) &&
+ (((1UL << vm->vm_id) & VM_PX_CX_CAPABILITY) != 0)) {
ASSERT((pm_state_info->px_cnt <= MAX_PSTATE), "failed to setup cpu px");

vm->pm.px_cnt = pm_state_info->px_cnt;
@@ -76,7 +77,8 @@ static void vm_setup_cpu_cx(struct acrn_vm *vm)
vm->pm.cx_cnt = 0U;
(void)memset(vm->pm.cx_data, 0U, MAX_CSTATE * sizeof(struct acrn_cstate_data));

- if ((pm_state_info->cx_cnt != 0U) && (pm_state_info->cx_data != NULL)) {
+ if ((pm_state_info->cx_cnt != 0U) && (pm_state_info->cx_data != NULL) &&
+ (((1UL << vm->vm_id) & VM_PX_CX_CAPABILITY) != 0)) {
ASSERT((pm_state_info->cx_cnt <= MAX_CX_ENTRY), "failed to setup cpu cx");

vm->pm.cx_cnt = pm_state_info->cx_cnt;
--
2.17.1


Xu, Anthony
 

Can config tools generate a flag in vm_config for PX_CX?

Anthony

-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On Behalf Of Zhou, Wu
Sent: Tuesday, November 16, 2021 12:47 AM
To: acrn-dev@...
Subject: [acrn-dev] [PATCH 2/4] hv: remove pstate/cstate support for VMs that share pCPU

Only when the a post-launched VM is not sharing pCPUs and no RTVM
is setup in the scenario, the pCPU’s pstate/cstate can be
passed-though to the VM.

The VM_PX_CX_CAPABILITY macro is generated by config_tools, this
patch simply use it to determine whether a VM can have pstate/cstate.
If it is negative, the px_cnt and cx_cnt will be zero. The dm will
also get 0 for px_cnt and cx_cnt on hypercall, and the VM will get
no pstate/cstate.

Signed-off-by: Zhou, Wu <wu.zhou@...>
---
hypervisor/arch/x86/guest/pm.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hypervisor/arch/x86/guest/pm.c b/hypervisor/arch/x86/guest/pm.c
index 9771dda72..acf12bbcb 100644
--- a/hypervisor/arch/x86/guest/pm.c
+++ b/hypervisor/arch/x86/guest/pm.c
@@ -59,7 +59,8 @@ static void vm_setup_cpu_px(struct acrn_vm *vm)
vm->pm.px_cnt = 0U;
(void)memset(vm->pm.px_data, 0U, MAX_PSTATE * sizeof(struct acrn_pstate_data));

- if ((pm_state_info->px_cnt != 0U) && (pm_state_info->px_data != NULL)) {
+ if ((pm_state_info->px_cnt != 0U) && (pm_state_info->px_data != NULL) &&
+ (((1UL << vm->vm_id) & VM_PX_CX_CAPABILITY) != 0)) {
ASSERT((pm_state_info->px_cnt <= MAX_PSTATE), "failed to setup cpu px");

vm->pm.px_cnt = pm_state_info->px_cnt;
@@ -76,7 +77,8 @@ static void vm_setup_cpu_cx(struct acrn_vm *vm)
vm->pm.cx_cnt = 0U;
(void)memset(vm->pm.cx_data, 0U, MAX_CSTATE * sizeof(struct acrn_cstate_data));

- if ((pm_state_info->cx_cnt != 0U) && (pm_state_info->cx_data != NULL)) {
+ if ((pm_state_info->cx_cnt != 0U) && (pm_state_info->cx_data != NULL) &&
+ (((1UL << vm->vm_id) & VM_PX_CX_CAPABILITY) != 0)) {
ASSERT((pm_state_info->cx_cnt <= MAX_CX_ENTRY), "failed to setup cpu cx");

vm->pm.cx_cnt = pm_state_info->cx_cnt;
--
2.17.1





Xu, Anthony
 

Like VM flag in acrn-hypervisor/hypervisor/include/public/acrn_common.h

Anthony

-----Original Message-----
From: Xu, Anthony
Sent: Tuesday, November 16, 2021 3:07 PM
To: acrn-dev@...
Subject: RE: [acrn-dev] [PATCH 2/4] hv: remove pstate/cstate support for VMs that share pCPU

Can config tools generate a flag in vm_config for PX_CX?

Anthony

-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On Behalf Of Zhou, Wu
Sent: Tuesday, November 16, 2021 12:47 AM
To: acrn-dev@...
Subject: [acrn-dev] [PATCH 2/4] hv: remove pstate/cstate support for VMs that share pCPU

Only when the a post-launched VM is not sharing pCPUs and no RTVM
is setup in the scenario, the pCPU’s pstate/cstate can be
passed-though to the VM.

The VM_PX_CX_CAPABILITY macro is generated by config_tools, this
patch simply use it to determine whether a VM can have pstate/cstate.
If it is negative, the px_cnt and cx_cnt will be zero. The dm will
also get 0 for px_cnt and cx_cnt on hypercall, and the VM will get
no pstate/cstate.

Signed-off-by: Zhou, Wu <wu.zhou@...>
---
hypervisor/arch/x86/guest/pm.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hypervisor/arch/x86/guest/pm.c b/hypervisor/arch/x86/guest/pm.c
index 9771dda72..acf12bbcb 100644
--- a/hypervisor/arch/x86/guest/pm.c
+++ b/hypervisor/arch/x86/guest/pm.c
@@ -59,7 +59,8 @@ static void vm_setup_cpu_px(struct acrn_vm *vm)
vm->pm.px_cnt = 0U;
(void)memset(vm->pm.px_data, 0U, MAX_PSTATE * sizeof(struct acrn_pstate_data));

- if ((pm_state_info->px_cnt != 0U) && (pm_state_info->px_data != NULL)) {
+ if ((pm_state_info->px_cnt != 0U) && (pm_state_info->px_data != NULL) &&
+ (((1UL << vm->vm_id) & VM_PX_CX_CAPABILITY) != 0)) {
ASSERT((pm_state_info->px_cnt <= MAX_PSTATE), "failed to setup cpu px");

vm->pm.px_cnt = pm_state_info->px_cnt;
@@ -76,7 +77,8 @@ static void vm_setup_cpu_cx(struct acrn_vm *vm)
vm->pm.cx_cnt = 0U;
(void)memset(vm->pm.cx_data, 0U, MAX_CSTATE * sizeof(struct acrn_cstate_data));

- if ((pm_state_info->cx_cnt != 0U) && (pm_state_info->cx_data != NULL)) {
+ if ((pm_state_info->cx_cnt != 0U) && (pm_state_info->cx_data != NULL) &&
+ (((1UL << vm->vm_id) & VM_PX_CX_CAPABILITY) != 0)) {
ASSERT((pm_state_info->cx_cnt <= MAX_CX_ENTRY), "failed to setup cpu cx");

vm->pm.cx_cnt = pm_state_info->cx_cnt;
--
2.17.1





Eddie Dong
 

-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On
Behalf Of Zhou, Wu
Sent: Tuesday, November 16, 2021 4:47 PM
To: acrn-dev@...
Subject: [acrn-dev] [PATCH 2/4] hv: remove pstate/cstate support for VMs
that share pCPU

Only when the a post-launched VM is not sharing pCPUs and no RTVM is
setup in the scenario, the pCPU’s pstate/cstate can be passed-though to the
VM.

The VM_PX_CX_CAPABILITY macro is generated by config_tools, this patch
Using per VM bit inside the MACRO is not good.

Or to use a bit in guest_flags, plus a global MACRO to indicate whether RTVM is configured or not?

simply use it to determine whether a VM can have pstate/cstate.
If it is negative, the px_cnt and cx_cnt will be zero. The dm will also get 0 for
px_cnt and cx_cnt on hypercall, and the VM will get no pstate/cstate.

Signed-off-by: Zhou, Wu <wu.zhou@...>
---
hypervisor/arch/x86/guest/pm.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hypervisor/arch/x86/guest/pm.c
b/hypervisor/arch/x86/guest/pm.c index 9771dda72..acf12bbcb 100644
--- a/hypervisor/arch/x86/guest/pm.c
+++ b/hypervisor/arch/x86/guest/pm.c
@@ -59,7 +59,8 @@ static void vm_setup_cpu_px(struct acrn_vm *vm)
vm->pm.px_cnt = 0U;
(void)memset(vm->pm.px_data, 0U, MAX_PSTATE * sizeof(struct
acrn_pstate_data));

- if ((pm_state_info->px_cnt != 0U) && (pm_state_info->px_data != NULL))
{
+ if ((pm_state_info->px_cnt != 0U) && (pm_state_info->px_data != NULL)
&&
+ (((1UL << vm->vm_id) & VM_PX_CX_CAPABILITY) != 0)) {
ASSERT((pm_state_info->px_cnt <= MAX_PSTATE), "failed to setup
cpu px");

vm->pm.px_cnt = pm_state_info->px_cnt; @@ -76,7 +77,8 @@
static void vm_setup_cpu_cx(struct acrn_vm *vm)
vm->pm.cx_cnt = 0U;
(void)memset(vm->pm.cx_data, 0U, MAX_CSTATE * sizeof(struct
acrn_cstate_data));

- if ((pm_state_info->cx_cnt != 0U) && (pm_state_info->cx_data != NULL))
{
+ if ((pm_state_info->cx_cnt != 0U) && (pm_state_info->cx_data != NULL)
&&
+ (((1UL << vm->vm_id) & VM_PX_CX_CAPABILITY) != 0)) {
ASSERT((pm_state_info->cx_cnt <= MAX_CX_ENTRY), "failed to
setup cpu cx");

vm->pm.cx_cnt = pm_state_info->cx_cnt;
--
2.17.1