Skip to content

Commit 91c1408

Browse files
KaigeFuwenlingz
authored andcommitted
HV: Reset physical core of lapic_pt vm when shutdown
The physical core of lapic_pt vm should be reset for security and correctness when shutdown the vm. Tracked-On: #2991 Signed-off-by: Kaige Fu <kaige.fu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent e52917f commit 91c1408

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ bool start_cpus(uint64_t mask)
332332
return ((pcpu_active_bitmap & mask) == mask);
333333
}
334334

335+
void wait_pcpus_offline(uint64_t mask)
336+
{
337+
uint32_t timeout;
338+
339+
timeout = CPU_DOWN_TIMEOUT * 1000U;
340+
while (((pcpu_active_bitmap & mask) != 0UL) && (timeout != 0U)) {
341+
udelay(10U);
342+
timeout -= 10U;
343+
}
344+
}
345+
335346
void stop_cpus(void)
336347
{
337348
uint16_t pcpu_id, expected_up;
@@ -390,13 +401,14 @@ void cpu_dead(void)
390401
int32_t halt = 1;
391402
uint16_t pcpu_id = get_cpu_id();
392403

393-
if (bitmap_test_and_clear_lock(pcpu_id, &pcpu_active_bitmap)) {
404+
if (bitmap_test(pcpu_id, &pcpu_active_bitmap)) {
394405
/* clean up native stuff */
395406
vmx_off();
396407
cache_flush_invalidate_all();
397408

398409
/* Set state to show CPU is dead */
399410
cpu_set_current_state(pcpu_id, PCPU_STATE_DEAD);
411+
bitmap_clear_nolock(pcpu_id, &pcpu_active_bitmap);
400412

401413
/* Halt the CPU */
402414
do {

hypervisor/arch/x86/guest/vm.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,10 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_
456456
int32_t shutdown_vm(struct acrn_vm *vm)
457457
{
458458
uint16_t i;
459+
uint64_t mask = 0UL;
459460
struct acrn_vcpu *vcpu = NULL;
460461
struct acrn_vm_config *vm_config = NULL;
461-
int32_t ret;
462+
int32_t ret = 0;
462463

463464
pause_vm(vm);
464465

@@ -469,6 +470,18 @@ int32_t shutdown_vm(struct acrn_vm *vm)
469470
foreach_vcpu(i, vm, vcpu) {
470471
reset_vcpu(vcpu);
471472
offline_vcpu(vcpu);
473+
474+
if (is_lapic_pt(vm)) {
475+
bitmap_set_nolock(vcpu->pcpu_id, &mask);
476+
make_pcpu_offline(vcpu->pcpu_id);
477+
}
478+
}
479+
480+
wait_pcpus_offline(mask);
481+
482+
if (is_lapic_pt(vm) && !start_cpus(mask)) {
483+
pr_fatal("Failed to start all cpus in mask(0x%llx)", mask);
484+
ret = -ETIMEDOUT;
472485
}
473486

474487
vm_config = get_vm_config(vm->vm_id);

hypervisor/include/arch/x86/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ void load_cpu_state_data(void);
260260
void init_cpu_pre(uint16_t pcpu_id_args);
261261
void init_cpu_post(uint16_t pcpu_id);
262262
bool start_cpus(uint64_t mask);
263+
void wait_pcpus_offline(uint64_t mask);
263264
void stop_cpus(void);
264265
void wait_sync_change(uint64_t *sync, uint64_t wake_sync);
265266

hypervisor/include/lib/errno.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@
2323
#define ENODEV 19
2424
/** Indicates that argument is not valid. */
2525
#define EINVAL 22
26+
/** Indicates that timeout occurs. */
27+
#define ETIMEDOUT 110
2628

2729
#endif /* ERRNO_H */

0 commit comments

Comments
 (0)