Re: [PATCH v2 2/2] HV: Reset physical core of lapic_pt vm when shutdown


Kaige Fu
 

On 04-09 Tue 17:02, Yin, Fengwei wrote:
On 4/10/2019 12:50 AM, Kaige Fu wrote:
On 04-09 Tue 16:51, Yin, Fengwei wrote:
On 4/10/2019 12:44 AM, Kaige Fu wrote:
The physical core of lapic_pt vm should be reset for security and correctness when
shutdown the vm.

Signed-off-by: Kaige Fu <kaige.fu@...>
---
hypervisor/arch/x86/cpu.c | 2 +-
hypervisor/arch/x86/guest/vm.c | 8 ++++++++
hypervisor/include/arch/x86/cpu.h | 1 +
3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c
index 1a4966e8..b46cae4d 100644
--- a/hypervisor/arch/x86/cpu.c
+++ b/hypervisor/arch/x86/cpu.c
@@ -259,7 +259,7 @@ static uint16_t get_cpu_id_from_lapic_id(uint32_t lapic_id)
return pcpu_id;
}
-static void start_cpu(uint16_t pcpu_id)
+void start_cpu(uint16_t pcpu_id)
{
uint32_t timeout;
diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c
index cbc70785..4c24f573 100644
--- a/hypervisor/arch/x86/guest/vm.c
+++ b/hypervisor/arch/x86/guest/vm.c
@@ -496,6 +496,14 @@ int32_t shutdown_vm(struct acrn_vm *vm)
For lapic_pt vm, this function is called in SOS pCPU (hypercall from
DM). Right?
Yes.
Then, we need to check some flags in HV (like check the guest VM
shutdown flag) instead of invoke make pcpu_offline/start_cpu directly
here. It's to make sure the RTVM is in a state that we could do these
operations for its vcpu. Or we already check the flag in advance?
Actually, we already check it before.

/* Only allow shutdown paused vm */
if (vm->state == VM_PAUSED) {

...

/* All pcpu of lapic_pt vm should be reset for security and correctness */
if (is_lapic_pt(vm)) {
make_pcpu_offline(vcpu->pcpu_id);
start_cpu(vcpu->pcpu_id);
} else {
/* No other state currently, do nothing */
}
}


We can only pause vm (set its state as VM_PAUSED) when the RTVM is trying to poweroff by itself.
So it is safe here to reset the pcpu.

Regards
Yin, Fengwei

Regards
Yin, Fengwei

foreach_vcpu(i, vm, vcpu) {
reset_vcpu(vcpu);
offline_vcpu(vcpu);
+
+ /* All pcpu of lapic_pt vm should be reset for security and correctness */
+ if (is_lapic_pt(vm)) {
+ make_pcpu_offline(vcpu->pcpu_id);
+ start_cpu(vcpu->pcpu_id);
+ } else {
+ /* No other state currently, do nothing */
+ }
}
ptdev_release_all_entries(vm);
diff --git a/hypervisor/include/arch/x86/cpu.h b/hypervisor/include/arch/x86/cpu.h
index 13c2fd9e..5eca144f 100644
--- a/hypervisor/include/arch/x86/cpu.h
+++ b/hypervisor/include/arch/x86/cpu.h
@@ -259,6 +259,7 @@ void trampoline_start16(void);
void load_cpu_state_data(void);
void init_cpu_pre(uint16_t pcpu_id_args);
void init_cpu_post(uint16_t pcpu_id);
+void start_cpu(uint16_t pcpu_id);
void start_cpus(void);
void stop_cpus(void);
void wait_sync_change(uint64_t *sync, uint64_t wake_sync);





Join acrn-dev@lists.projectacrn.org to automatically receive all group messages.