@@ -55,7 +55,7 @@ DECLARE_KVM_NVHE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt);
5555
5656static bool vgic_present , kvm_arm_initialised ;
5757
58- static DEFINE_PER_CPU (unsigned char , kvm_arm_hardware_enabled );
58+ static DEFINE_PER_CPU (unsigned char , kvm_hyp_initialized );
5959DEFINE_STATIC_KEY_FALSE (userspace_irqchip_in_use );
6060
6161bool is_kvm_arm_initialised (void )
@@ -1864,18 +1864,24 @@ static void cpu_hyp_reinit(void)
18641864 cpu_hyp_init_features ();
18651865}
18661866
1867- static void _kvm_arch_hardware_enable (void * discard )
1867+ static void cpu_hyp_init (void * discard )
18681868{
1869- if (!__this_cpu_read (kvm_arm_hardware_enabled )) {
1869+ if (!__this_cpu_read (kvm_hyp_initialized )) {
18701870 cpu_hyp_reinit ();
1871- __this_cpu_write (kvm_arm_hardware_enabled , 1 );
1871+ __this_cpu_write (kvm_hyp_initialized , 1 );
18721872 }
18731873}
18741874
1875- int kvm_arch_hardware_enable (void )
1875+ static void cpu_hyp_uninit (void * discard )
18761876{
1877- int was_enabled ;
1877+ if (__this_cpu_read (kvm_hyp_initialized )) {
1878+ cpu_hyp_reset ();
1879+ __this_cpu_write (kvm_hyp_initialized , 0 );
1880+ }
1881+ }
18781882
1883+ int kvm_arch_hardware_enable (void )
1884+ {
18791885 /*
18801886 * Most calls to this function are made with migration
18811887 * disabled, but not with preemption disabled. The former is
@@ -1884,36 +1890,23 @@ int kvm_arch_hardware_enable(void)
18841890 */
18851891 preempt_disable ();
18861892
1887- was_enabled = __this_cpu_read (kvm_arm_hardware_enabled );
1888- _kvm_arch_hardware_enable (NULL );
1893+ cpu_hyp_init (NULL );
18891894
1890- if (!was_enabled ) {
1891- kvm_vgic_cpu_up ();
1892- kvm_timer_cpu_up ();
1893- }
1895+ kvm_vgic_cpu_up ();
1896+ kvm_timer_cpu_up ();
18941897
18951898 preempt_enable ();
18961899
18971900 return 0 ;
18981901}
18991902
1900- static void _kvm_arch_hardware_disable (void * discard )
1901- {
1902- if (__this_cpu_read (kvm_arm_hardware_enabled )) {
1903- cpu_hyp_reset ();
1904- __this_cpu_write (kvm_arm_hardware_enabled , 0 );
1905- }
1906- }
1907-
19081903void kvm_arch_hardware_disable (void )
19091904{
1910- if (__this_cpu_read (kvm_arm_hardware_enabled )) {
1911- kvm_timer_cpu_down ();
1912- kvm_vgic_cpu_down ();
1913- }
1905+ kvm_timer_cpu_down ();
1906+ kvm_vgic_cpu_down ();
19141907
19151908 if (!is_protected_kvm_enabled ())
1916- _kvm_arch_hardware_disable (NULL );
1909+ cpu_hyp_uninit (NULL );
19171910}
19181911
19191912#ifdef CONFIG_CPU_PM
@@ -1922,25 +1915,25 @@ static int hyp_init_cpu_pm_notifier(struct notifier_block *self,
19221915 void * v )
19231916{
19241917 /*
1925- * kvm_arm_hardware_enabled is left with its old value over
1918+ * kvm_hyp_initialized is left with its old value over
19261919 * PM_ENTER->PM_EXIT. It is used to indicate PM_EXIT should
19271920 * re-enable hyp.
19281921 */
19291922 switch (cmd ) {
19301923 case CPU_PM_ENTER :
1931- if (__this_cpu_read (kvm_arm_hardware_enabled ))
1924+ if (__this_cpu_read (kvm_hyp_initialized ))
19321925 /*
1933- * don't update kvm_arm_hardware_enabled here
1934- * so that the hardware will be re-enabled
1926+ * don't update kvm_hyp_initialized here
1927+ * so that the hyp will be re-enabled
19351928 * when we resume. See below.
19361929 */
19371930 cpu_hyp_reset ();
19381931
19391932 return NOTIFY_OK ;
19401933 case CPU_PM_ENTER_FAILED :
19411934 case CPU_PM_EXIT :
1942- if (__this_cpu_read (kvm_arm_hardware_enabled ))
1943- /* The hardware was enabled before suspend. */
1935+ if (__this_cpu_read (kvm_hyp_initialized ))
1936+ /* The hyp was enabled before suspend. */
19441937 cpu_hyp_reinit ();
19451938
19461939 return NOTIFY_OK ;
@@ -2021,7 +2014,7 @@ static int __init init_subsystems(void)
20212014 /*
20222015 * Enable hardware so that subsystem initialisation can access EL2.
20232016 */
2024- on_each_cpu (_kvm_arch_hardware_enable , NULL , 1 );
2017+ on_each_cpu (cpu_hyp_init , NULL , 1 );
20252018
20262019 /*
20272020 * Register CPU lower-power notifier
@@ -2059,7 +2052,7 @@ static int __init init_subsystems(void)
20592052 hyp_cpu_pm_exit ();
20602053
20612054 if (err || !is_protected_kvm_enabled ())
2062- on_each_cpu (_kvm_arch_hardware_disable , NULL , 1 );
2055+ on_each_cpu (cpu_hyp_uninit , NULL , 1 );
20632056
20642057 return err ;
20652058}
@@ -2097,7 +2090,7 @@ static int __init do_pkvm_init(u32 hyp_va_bits)
20972090 * The stub hypercalls are now disabled, so set our local flag to
20982091 * prevent a later re-init attempt in kvm_arch_hardware_enable().
20992092 */
2100- __this_cpu_write (kvm_arm_hardware_enabled , 1 );
2093+ __this_cpu_write (kvm_hyp_initialized , 1 );
21012094 preempt_enable ();
21022095
21032096 return ret ;
0 commit comments