@@ -464,7 +464,7 @@ static uint64_t lapic_pt_enabled_pcpu_bitmap(struct acrn_vm *vm)
464
464
465
465
if (is_lapic_pt_configured (vm )) {
466
466
foreach_vcpu (i , vm , vcpu ) {
467
- if (is_lapic_pt_enabled ( vcpu )) {
467
+ if (is_x2apic_enabled ( vcpu_vlapic ( vcpu ) )) {
468
468
bitmap_set_nolock (pcpuid_from_vcpu (vcpu ), & bitmap );
469
469
}
470
470
}
@@ -619,13 +619,53 @@ static bool is_ready_for_system_shutdown(void)
619
619
return ret ;
620
620
}
621
621
622
+ static int32_t offline_lapic_pt_enabled_pcpus (const struct acrn_vm * vm , uint64_t pcpu_mask )
623
+ {
624
+ int32_t ret = 0 ;
625
+ uint16_t i ;
626
+ uint64_t mask = pcpu_mask ;
627
+ const struct acrn_vcpu * vcpu = NULL ;
628
+ uint16_t this_pcpu_id = get_pcpu_id ();
629
+
630
+ if (bitmap_test (this_pcpu_id , & mask )) {
631
+ bitmap_clear_nolock (this_pcpu_id , & mask );
632
+ if (vm -> state == VM_POWERED_OFF ) {
633
+ /*
634
+ * If the current pcpu needs to offline itself,
635
+ * it will be done after shutdown_vm() completes
636
+ * in the idle thread.
637
+ */
638
+ make_pcpu_offline (this_pcpu_id );
639
+ } else {
640
+ /*
641
+ * The current pcpu can't reset itself
642
+ */
643
+ pr_warn ("%s: cannot offline self(%u)" ,
644
+ __func__ , this_pcpu_id );
645
+ ret = - EINVAL ;
646
+ }
647
+ }
648
+
649
+ foreach_vcpu (i , vm , vcpu ) {
650
+ if (bitmap_test (pcpuid_from_vcpu (vcpu ), & mask )) {
651
+ make_pcpu_offline (pcpuid_from_vcpu (vcpu ));
652
+ }
653
+ }
654
+
655
+ wait_pcpus_offline (mask );
656
+ if (!start_pcpus (mask )) {
657
+ pr_fatal ("Failed to start all cpus in mask(0x%lx)" , mask );
658
+ ret = - ETIMEDOUT ;
659
+ }
660
+ return ret ;
661
+ }
662
+
622
663
/*
623
664
* @pre vm != NULL
624
665
*/
625
666
int32_t shutdown_vm (struct acrn_vm * vm )
626
667
{
627
668
uint16_t i ;
628
- uint16_t this_pcpu_id ;
629
669
uint64_t mask ;
630
670
struct acrn_vcpu * vcpu = NULL ;
631
671
struct acrn_vm_config * vm_config = NULL ;
@@ -636,32 +676,14 @@ int32_t shutdown_vm(struct acrn_vm *vm)
636
676
/* Only allow shutdown paused vm */
637
677
if (vm -> state == VM_PAUSED ) {
638
678
vm -> state = VM_POWERED_OFF ;
639
- this_pcpu_id = get_pcpu_id ();
640
- mask = lapic_pt_enabled_pcpu_bitmap (vm );
641
679
642
- /*
643
- * If the current pcpu needs to offline itself,
644
- * it will be done after shutdown_vm() completes
645
- * in the idle thread.
646
- */
647
- if (bitmap_test (this_pcpu_id , & mask )) {
648
- bitmap_clear_nolock (this_pcpu_id , & mask );
649
- make_pcpu_offline (this_pcpu_id );
680
+ mask = lapic_pt_enabled_pcpu_bitmap (vm );
681
+ if (mask != 0UL ) {
682
+ ret = offline_lapic_pt_enabled_pcpus (vm , mask );
650
683
}
651
684
652
685
foreach_vcpu (i , vm , vcpu ) {
653
686
offline_vcpu (vcpu );
654
-
655
- if (bitmap_test (pcpuid_from_vcpu (vcpu ), & mask )) {
656
- make_pcpu_offline (pcpuid_from_vcpu (vcpu ));
657
- }
658
- }
659
-
660
- wait_pcpus_offline (mask );
661
-
662
- if ((mask != 0UL ) && (!start_pcpus (mask ))) {
663
- pr_fatal ("Failed to start all cpus in mask(0x%lx)" , mask );
664
- ret = - ETIMEDOUT ;
665
687
}
666
688
667
689
vm_config = get_vm_config (vm -> vm_id );
@@ -716,38 +738,18 @@ void start_vm(struct acrn_vm *vm)
716
738
int32_t reset_vm (struct acrn_vm * vm )
717
739
{
718
740
uint16_t i ;
719
- uint16_t this_pcpu_id ;
720
741
uint64_t mask ;
721
742
struct acrn_vcpu * vcpu = NULL ;
722
743
int32_t ret = 0 ;
723
744
724
745
if (vm -> state == VM_PAUSED ) {
725
- this_pcpu_id = get_pcpu_id ();
726
746
mask = lapic_pt_enabled_pcpu_bitmap (vm );
727
-
728
- /*
729
- * The current pcpu can't reset itself
730
- */
731
- if (bitmap_test (this_pcpu_id , & mask )) {
732
- pr_warn ("%s: cannot offline self(%u)" ,
733
- __func__ , this_pcpu_id );
734
- bitmap_clear_nolock (this_pcpu_id , & mask );
735
- ret = - EINVAL ;
747
+ if (mask != 0UL ) {
748
+ ret = offline_lapic_pt_enabled_pcpus (vm , mask );
736
749
}
737
750
738
751
foreach_vcpu (i , vm , vcpu ) {
739
752
reset_vcpu (vcpu , COLD_RESET );
740
-
741
- if (bitmap_test (pcpuid_from_vcpu (vcpu ), & mask )) {
742
- make_pcpu_offline (pcpuid_from_vcpu (vcpu ));
743
- }
744
- }
745
-
746
- wait_pcpus_offline (mask );
747
-
748
- if ((mask != 0UL ) && (!start_pcpus (mask ))) {
749
- pr_fatal ("Failed to start all cpus in mask(0x%lx)" , mask );
750
- ret = - ETIMEDOUT ;
751
753
}
752
754
753
755
/*
0 commit comments