Skip to contentSkip to conversation

x86/hyperv: Remove unregister syscore call from hyperv cleanup

PATCH Superseded Gaurav Kohli 2 participants 5 messages Nov 24, 2022 – Nov 25, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hyperv: Remove unregister syscore call from hyperv cleanup

Hyperv cleanup codes comes under panic path where preemption and irq is already disabled. So calling of unregister_syscore_ops which has mutex from hyperv cleanup might schedule out the thread and never comes back.

To prevent the same remove unwanted unregister_syscore_ops function call.

arch/x86/hyperv/hv_init.c +6 -1
index f49bc3ec76e6..c050de69dfde 100644
@@ -537,7 +537,12 @@ void hyperv_cleanup(void)
 	union hv_x64_msr_hypercall_contents hypercall_msr;
 	union hv_reference_tsc_msr tsc_msr;
 
-	unregister_syscore_ops(&hv_syscore_ops);
+	/*
+	 * Avoid unregister_syscore_ops(&hv_syscore_ops) from cleanup code,
+	 * as this is only called in crash path where irq and preemption disabled.
+	 * If we add this, there is a chance that this get scheduled out due to mutex
+	 * in unregister_syscore_ops and never comes back.
+	 */
 
 	/* Reset our OS id */
 	wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 1 line · Gaurav Kohli

Hyperv cleanup codes comes under panic path where preemption and irq

Please use "Hyper-V" throughout.

Quoted 3 lines

is already disabled. So calling of unregister_syscore_ops which has mutex from hyperv cleanup might schedule out the thread and never comes back.

While on paper this looks problematic -- have you seen this issue triggered in real life?

This looks to be only triggered when there is another thread already holding the mutex, which seems rather rare in the life cycle of the machine?

Quoted 9 lines

To prevent the same remove unwanted unregister_syscore_ops function call.

arch/x86/hyperv/hv_init.c +0 -0
index f49bc3ec76e6..c050de69dfde 100644

arch/x86/hyperv/hv_init.c void hyperv_cleanup(void) · line 545

Quoted 10 lines
arch/x86/hyperv/hv_init.c +6 -1
@@ -537,7 +537,12 @@ void hyperv_cleanup(void)
 	union hv_x64_msr_hypercall_contents hypercall_msr;
 	union hv_reference_tsc_msr tsc_msr;
 
-	unregister_syscore_ops(&hv_syscore_ops);
+	/*
+	 * Avoid unregister_syscore_ops(&hv_syscore_ops) from cleanup code,
+	 * as this is only called in crash path where irq and preemption disabled.
+	 * If we add this, there is a chance that this get scheduled out due to mutex
+	 * in unregister_syscore_ops and never comes back.
+	 */

There is no need to document things we don't do, right?

Quoted 6 lines
arch/x86/hyperv/hv_init.c +0 -0
 	/* Reset our OS id */
 	wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
Signature · 1 line
2.17.1
#2 lore raw
Quoted 3 lines · Wei Liu
Quoted 1 line · Gaurav Kohli

Hyperv cleanup codes comes under panic path where preemption and irq

Please use "Hyper-V" throughout.

Thanks for the comment, sure will do on v2.

Quoted 10 lines
Quoted 4 lines

is already disabled. So calling of unregister_syscore_ops which has mutex from hyperv cleanup might schedule out the thread and never comes back.

While on paper this looks problematic -- have you seen this issue triggered in real life?

This looks to be only triggered when there is another thread already holding the mutex, which seems rather rare in the life cycle of the machine?

Earlier we also suspected the same that someone was holding the lock, but actually there

was no owner of lock and it got scheduled out due to might sleep code in mutex_lock.

Looks like where voluntary preemption config is on, there it is getting scheduled out in might sleep.

But there is no need of unregister_syscore_ops as this is in crash path only, So removing the same.

Quoted 13 lines
Quoted 13 lines

To prevent the same remove unwanted unregister_syscore_ops function call.

arch/x86/hyperv/hv_init.c +0 -0
index f49bc3ec76e6..c050de69dfde 100644
@@ -537,7 +537,12 @@ void hyperv_cleanup(void)
  	union hv_x64_msr_hypercall_contents hypercall_msr;
  	union hv_reference_tsc_msr tsc_msr;
 
Quoted 8 lines

arch/x86/hyperv/hv_init.c void hyperv_cleanup(void) · line 545

Quoted 7 lines
arch/x86/hyperv/hv_init.c +6 -1
-	unregister_syscore_ops(&hv_syscore_ops);
+	/*
+	 * Avoid unregister_syscore_ops(&hv_syscore_ops) from cleanup code,
+	 * as this is only called in crash path where irq and preemption disabled.
+	 * If we add this, there is a chance that this get scheduled out due to mutex
+	 * in unregister_syscore_ops and never comes back.
+	 */

There is no need to document things we don't do, right?

Yes, we have added so to avoid the same in future.

Quoted 7 lines
Quoted 7 lines
arch/x86/hyperv/hv_init.c +0 -0
  	/* Reset our OS id */
  	wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
Signature · 1 line
2.17.1
maintainer
#3 lore raw
Quoted 18 lines · Gaurav Kohli
Quoted 3 lines · Wei Liu
Quoted 1 line · Gaurav Kohli

Hyperv cleanup codes comes under panic path where preemption and irq

Please use "Hyper-V" throughout.

Thanks for the comment, sure will do on v2.

Quoted 10 lines
Quoted 4 lines

is already disabled. So calling of unregister_syscore_ops which has mutex from hyperv cleanup might schedule out the thread and never comes back.

While on paper this looks problematic -- have you seen this issue triggered in real life?

This looks to be only triggered when there is another thread already holding the mutex, which seems rather rare in the life cycle of the machine?

Quoted 8 lines

Earlier we also suspected the same that someone was holding the lock, but actually there

was no owner of lock and it got scheduled out due to might sleep code in mutex_lock.

Looks like where voluntary preemption config is on, there it is getting scheduled out in might sleep.

If there is only one CPU online and the mutex is free, then rescheduling will not have any adverse effect, right? Does it not get scheduled on the only available CPU and make further progress?

Quoted 3 lines

But there is no need of unregister_syscore_ops as this is in crash path only, So removing the same.

I'm not against removing it, but the reasoning left in the commit message and comment should reflect what happens.

Thanks,
Wei.

#4 lore raw
Quoted 19 lines · Wei Liu
Quoted 18 lines · Gaurav Kohli
Quoted 3 lines · Wei Liu
Quoted 1 line · Gaurav Kohli

Hyperv cleanup codes comes under panic path where preemption and irq

Please use "Hyper-V" throughout.

Thanks for the comment, sure will do on v2.

Quoted 9 lines
Quoted 3 lines

is already disabled. So calling of unregister_syscore_ops which has mutex from hyperv cleanup might schedule out the thread and never comes back.

While on paper this looks problematic -- have you seen this issue triggered in real life?

This looks to be only triggered when there is another thread already holding the mutex, which seems rather rare in the life cycle of the machine?

Earlier we also suspected the same that someone was holding the lock, but actually there

Quoted 8 lines
Quoted 5 lines

was no owner of lock and it got scheduled out due to might sleep code in mutex_lock.

Looks like where voluntary preemption config is on, there it is getting scheduled out in might sleep.

If there is only one CPU online and the mutex is free, then rescheduling will not have any adverse effect, right? Does it not get scheduled on the only available CPU and make further progress?

As this is in panic path where preemption and irq is disabled, so looks like it is not able

to schedule back to this cpu once scheduled out.

Quoted 4 lines
Quoted 2 lines

But there is no need of unregister_syscore_ops as this is in crash path only, So removing the same.

I'm not against removing it, but the reasoning left in the commit message and comment should reflect what happens.

thanks, will update the comment.

Quoted 3 lines

Thanks,
Wei.