Linux-HyperV Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] x86/hyperv: Properly suspend/resume reenlightenment notifications
@ 2020-05-12 16:01 Vitaly Kuznetsov
  2020-05-12 21:03 ` Dexuan Cui
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Vitaly Kuznetsov @ 2020-05-12 16:01 UTC (permalink / raw)
  To: linux-hyperv
  Cc: Wei Liu, x86, linux-kernel, kvm, Michael Kelley, Dexuan Cui, Tianyu Lan

Errors during hibernation with reenlightenment notifications enabled were
reported:

 [   51.730435] PM: hibernation entry
 [   51.737435] PM: Syncing filesystems ...
 ...
 [   54.102216] Disabling non-boot CPUs ...
 [   54.106633] smpboot: CPU 1 is now offline
 [   54.110006] unchecked MSR access error: WRMSR to 0x40000106 (tried to
     write 0x47c72780000100ee) at rIP: 0xffffffff90062f24
     native_write_msr+0x4/0x20)
 [   54.110006] Call Trace:
 [   54.110006]  hv_cpu_die+0xd9/0xf0
 ...

Normally, hv_cpu_die() just reassigns reenlightenment notifications to some
other CPU when the CPU receiving them goes offline. Upon hibernation, there
is no other CPU which is still online so cpumask_any_but(cpu_online_mask)
returns >= nr_cpu_ids and using it as hv_vp_index index is incorrect.
Disable the feature when cpumask_any_but() fails.

Also, as we now disable reenlightenment notifications upon hibernation we
need to restore them on resume. Check if hv_reenlightenment_cb was
previously set and restore from hv_resume().

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/hyperv/hv_init.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index fd51bac11b46..acf76b466db6 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -226,10 +226,18 @@ static int hv_cpu_die(unsigned int cpu)
 
 	rdmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
 	if (re_ctrl.target_vp == hv_vp_index[cpu]) {
-		/* Reassign to some other online CPU */
+		/*
+		 * Reassign reenlightenment notifications to some other online
+		 * CPU or just disable the feature if there are no online CPUs
+		 * left (happens on hibernation).
+		 */
 		new_cpu = cpumask_any_but(cpu_online_mask, cpu);
 
-		re_ctrl.target_vp = hv_vp_index[new_cpu];
+		if (new_cpu < nr_cpu_ids)
+			re_ctrl.target_vp = hv_vp_index[new_cpu];
+		else
+			re_ctrl.enabled = 0;
+
 		wrmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
 	}
 
@@ -293,6 +301,13 @@ static void hv_resume(void)
 
 	hv_hypercall_pg = hv_hypercall_pg_saved;
 	hv_hypercall_pg_saved = NULL;
+
+	/*
+	 * Reenlightenment notifications are disabled by hv_cpu_die(0),
+	 * reenable them here if hv_reenlightenment_cb was previously set.
+	 */
+	if (hv_reenlightenment_cb)
+		set_hv_tscchange_cb(hv_reenlightenment_cb);
 }
 
 /* Note: when the ops are called, only CPU0 is online and IRQs are disabled. */
-- 
2.25.4


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] x86/hyperv: Properly suspend/resume reenlightenment notifications
  2020-05-12 16:01 [PATCH] x86/hyperv: Properly suspend/resume reenlightenment notifications Vitaly Kuznetsov
@ 2020-05-12 21:03 ` Dexuan Cui
  2020-05-13 13:35 ` Tianyu Lan
  2020-05-13 15:01 ` Wei Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Dexuan Cui @ 2020-05-12 21:03 UTC (permalink / raw)
  To: vkuznets, linux-hyperv
  Cc: Wei Liu, x86, linux-kernel, kvm, Michael Kelley, Tianyu Lan

> From: Vitaly Kuznetsov <vkuznets@redhat.com>
> Sent: Tuesday, May 12, 2020 9:02 AM
> To: linux-hyperv@vger.kernel.org
> Cc: Wei Liu <wei.liu@kernel.org>; x86@kernel.org;
> linux-kernel@vger.kernel.org; kvm@vger.kernel.org; Michael Kelley
> <mikelley@microsoft.com>; Dexuan Cui <decui@microsoft.com>; Tianyu Lan
> <Tianyu.Lan@microsoft.com>
> Subject: [PATCH] x86/hyperv: Properly suspend/resume reenlightenment
> notifications
> 
> Errors during hibernation with reenlightenment notifications enabled were
> reported:
> 
>  [   51.730435] PM: hibernation entry
>  [   51.737435] PM: Syncing filesystems ...
>  ...
>  [   54.102216] Disabling non-boot CPUs ...
>  [   54.106633] smpboot: CPU 1 is now offline
>  [   54.110006] unchecked MSR access error: WRMSR to 0x40000106 (tried
> to
>      write 0x47c72780000100ee) at rIP: 0xffffffff90062f24
>      native_write_msr+0x4/0x20)
>  [   54.110006] Call Trace:
>  [   54.110006]  hv_cpu_die+0xd9/0xf0
>  ...
> 
> Normally, hv_cpu_die() just reassigns reenlightenment notifications to some
> other CPU when the CPU receiving them goes offline. Upon hibernation, there
> is no other CPU which is still online so cpumask_any_but(cpu_online_mask)
> returns >= nr_cpu_ids and using it as hv_vp_index index is incorrect.
> Disable the feature when cpumask_any_but() fails.
> 
> Also, as we now disable reenlightenment notifications upon hibernation we
> need to restore them on resume. Check if hv_reenlightenment_cb was
> previously set and restore from hv_resume().
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---

Looks good to me. Thanks!

Reviewed-by: Dexuan Cui <decui@microsoft.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/hyperv: Properly suspend/resume reenlightenment notifications
  2020-05-12 16:01 [PATCH] x86/hyperv: Properly suspend/resume reenlightenment notifications Vitaly Kuznetsov
  2020-05-12 21:03 ` Dexuan Cui
@ 2020-05-13 13:35 ` Tianyu Lan
  2020-05-13 15:01 ` Wei Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Tianyu Lan @ 2020-05-13 13:35 UTC (permalink / raw)
  To: Vitaly Kuznetsov, linux-hyperv
  Cc: Wei Liu, x86, linux-kernel, kvm, Michael Kelley, Dexuan Cui, Tianyu Lan

On 5/13/2020 12:01 AM, Vitaly Kuznetsov wrote:
> Errors during hibernation with reenlightenment notifications enabled were
> reported:
> 
>   [   51.730435] PM: hibernation entry
>   [   51.737435] PM: Syncing filesystems ...
>   ...
>   [   54.102216] Disabling non-boot CPUs ...
>   [   54.106633] smpboot: CPU 1 is now offline
>   [   54.110006] unchecked MSR access error: WRMSR to 0x40000106 (tried to
>       write 0x47c72780000100ee) at rIP: 0xffffffff90062f24
>       native_write_msr+0x4/0x20)
>   [   54.110006] Call Trace:
>   [   54.110006]  hv_cpu_die+0xd9/0xf0
>   ...
> 
> Normally, hv_cpu_die() just reassigns reenlightenment notifications to some
> other CPU when the CPU receiving them goes offline. Upon hibernation, there
> is no other CPU which is still online so cpumask_any_but(cpu_online_mask)
> returns >= nr_cpu_ids and using it as hv_vp_index index is incorrect.
> Disable the feature when cpumask_any_but() fails.
> 
> Also, as we now disable reenlightenment notifications upon hibernation we
> need to restore them on resume. Check if hv_reenlightenment_cb was
> previously set and restore from hv_resume().
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>   arch/x86/hyperv/hv_init.c | 19 +++++++++++++++++--
>   1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> index fd51bac11b46..acf76b466db6 100644
> --- a/arch/x86/hyperv/hv_init.c
> +++ b/arch/x86/hyperv/hv_init.c
> @@ -226,10 +226,18 @@ static int hv_cpu_die(unsigned int cpu)
>   
>   	rdmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
>   	if (re_ctrl.target_vp == hv_vp_index[cpu]) {
> -		/* Reassign to some other online CPU */
> +		/*
> +		 * Reassign reenlightenment notifications to some other online
> +		 * CPU or just disable the feature if there are no online CPUs
> +		 * left (happens on hibernation).
> +		 */
>   		new_cpu = cpumask_any_but(cpu_online_mask, cpu);
>   
> -		re_ctrl.target_vp = hv_vp_index[new_cpu];
> +		if (new_cpu < nr_cpu_ids)
> +			re_ctrl.target_vp = hv_vp_index[new_cpu];
> +		else
> +			re_ctrl.enabled = 0;
> +
>   		wrmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
>   	}
>   
> @@ -293,6 +301,13 @@ static void hv_resume(void)
>   
>   	hv_hypercall_pg = hv_hypercall_pg_saved;
>   	hv_hypercall_pg_saved = NULL;
> +
> +	/*
> +	 * Reenlightenment notifications are disabled by hv_cpu_die(0),
> +	 * reenable them here if hv_reenlightenment_cb was previously set.
> +	 */
> +	if (hv_reenlightenment_cb)
> +		set_hv_tscchange_cb(hv_reenlightenment_cb);
>   }
>   
>   /* Note: when the ops are called, only CPU0 is online and IRQs are disabled. */
> 

Reviewed-by: Tianyu Lan <Tianyu.Lan@microsoft.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/hyperv: Properly suspend/resume reenlightenment notifications
  2020-05-12 16:01 [PATCH] x86/hyperv: Properly suspend/resume reenlightenment notifications Vitaly Kuznetsov
  2020-05-12 21:03 ` Dexuan Cui
  2020-05-13 13:35 ` Tianyu Lan
@ 2020-05-13 15:01 ` Wei Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Wei Liu @ 2020-05-13 15:01 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: linux-hyperv, Wei Liu, x86, linux-kernel, kvm, Michael Kelley,
	Dexuan Cui, Tianyu Lan

On Tue, May 12, 2020 at 06:01:53PM +0200, Vitaly Kuznetsov wrote:
> Errors during hibernation with reenlightenment notifications enabled were
> reported:
> 
>  [   51.730435] PM: hibernation entry
>  [   51.737435] PM: Syncing filesystems ...
>  ...
>  [   54.102216] Disabling non-boot CPUs ...
>  [   54.106633] smpboot: CPU 1 is now offline
>  [   54.110006] unchecked MSR access error: WRMSR to 0x40000106 (tried to
>      write 0x47c72780000100ee) at rIP: 0xffffffff90062f24
>      native_write_msr+0x4/0x20)
>  [   54.110006] Call Trace:
>  [   54.110006]  hv_cpu_die+0xd9/0xf0
>  ...
> 
> Normally, hv_cpu_die() just reassigns reenlightenment notifications to some
> other CPU when the CPU receiving them goes offline. Upon hibernation, there
> is no other CPU which is still online so cpumask_any_but(cpu_online_mask)
> returns >= nr_cpu_ids and using it as hv_vp_index index is incorrect.
> Disable the feature when cpumask_any_but() fails.
> 
> Also, as we now disable reenlightenment notifications upon hibernation we
> need to restore them on resume. Check if hv_reenlightenment_cb was
> previously set and restore from hv_resume().
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>

Applied to hyperv-fixes.

Thank you all.

Wei.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 16:01 [PATCH] x86/hyperv: Properly suspend/resume reenlightenment notifications Vitaly Kuznetsov
2020-05-12 21:03 ` Dexuan Cui
2020-05-13 13:35 ` Tianyu Lan
2020-05-13 15:01 ` Wei Liu

Linux-HyperV Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hyperv/0 linux-hyperv/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hyperv linux-hyperv/ https://lore.kernel.org/linux-hyperv \
		linux-hyperv@vger.kernel.org
	public-inbox-index linux-hyperv

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hyperv


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git