Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: x86@kernel.org, tglx@linutronix.de,
	xen-devel@lists.xenproject.org, boris.ostrovsky@oracle.com,
	mingo@redhat.com, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, hpa@zytor.com
Subject: Re: [PATCH] x86/xen: zero MSR_IA32_SPEC_CTRL before suspend
Date: Wed, 11 Apr 2018 09:08:12 +0200	[thread overview]
Message-ID: <6b59ac31-7e90-1c18-2467-d7d294da6e5b@suse.com> (raw)
In-Reply-To: <5AA8F00302000078001B15EE@suse.com>

On 14/03/18 09:48, Jan Beulich wrote:
>>>> On 26.02.18 at 15:08, <jgross@suse.com> wrote:
>> @@ -35,6 +40,9 @@ void xen_arch_post_suspend(int cancelled)
>>  
>>  static void xen_vcpu_notify_restore(void *data)
>>  {
>> +	if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL))
>> +		wrmsrl(MSR_IA32_SPEC_CTRL, this_cpu_read(spec_ctrl));
>> +
>>  	/* Boot processor notified via generic timekeeping_resume() */
>>  	if (smp_processor_id() == 0)
>>  		return;
>> @@ -44,7 +52,15 @@ static void xen_vcpu_notify_restore(void *data)
>>  
>>  static void xen_vcpu_notify_suspend(void *data)
>>  {
>> +	u64 tmp;
>> +
>>  	tick_suspend_local();
>> +
>> +	if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
>> +		rdmsrl(MSR_IA32_SPEC_CTRL, tmp);
>> +		this_cpu_write(spec_ctrl, tmp);
>> +		wrmsrl(MSR_IA32_SPEC_CTRL, 0);
>> +	}
>>  }
> 
> While investigating ways how to do something similar on our old,
> non-pvops kernels I've started wondering if this solution is actually
> correct in all cases. Of course discussing this is complicated by the
> fact that the change there might be a conflict with hasn't landed
> in Linus'es tree yet (see e.g.
> https://patchwork.kernel.org/patch/10153843/ for an upstream
> submission; I haven't been able to find any discussion on that
> patch or why it isn't upstream yet), but we have it in our various
> branches. The potential problem I'm seeing is with the clearing
> and re-setting of SPEC_CTRL around CPUs going idle. While the
> active CPU could have preemption disabled (if that isn't the case
> already), the passive CPUs are - afaict - neither under full control
> of drivers/xen/manage.c:do_suspend() nor excluded yet from
> any further scheduling activity. Hence with code like this (taken
> from one of our branches)
> 
> static void mwait_idle(void)
> {
> 	if (!current_set_polling_and_test()) {
> 		trace_cpu_idle_rcuidle(1, smp_processor_id());
> 		if (this_cpu_has(X86_BUG_CLFLUSH_MONITOR)) {
> 			smp_mb(); /* quirk */
> 			clflush((void *)&current_thread_info()->flags);
> 			smp_mb(); /* quirk */
> 		}
> 
> 		x86_disable_ibrs();
> 
> 		__monitor((void *)&current_thread_info()->flags, 0, 0);
> 		if (!need_resched())
> 			__sti_mwait(0, 0);
> 		else
> 			local_irq_enable();
> 
> 		x86_enable_ibrs();
> 		...
> 
> the MSR might get set to non-zero again after having been
> cleared by the code your patch adds. I therefore think that the
> only race free solution would be to do the clearing from
> stop-machine context. But maybe I'm overlooking something.

Currently and with the above mentioned patch there is no problem: Xen pv
guests always use default_idle(), so mwait_idle() eventually playing
with MSR_IA32_SPEC_CTRL won't affect us.

In order to ensure that won't change in future default_idle() should
never modify MSR_IA32_SPEC_CTRL. In case something like that would be
required we should rather add another idle function doing that.


Juergen

  parent reply	other threads:[~2018-04-11  7:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-26 14:08 [PATCH] x86/xen: zero MSR_IA32_SPEC_CTRL before suspend Juergen Gross
2018-02-26 16:17 ` Jan Beulich
2018-03-14  8:48 ` Jan Beulich
     [not found] ` <5AA8F00302000078001B15EE@suse.com>
2018-04-11  7:08   ` Juergen Gross [this message]
2018-04-11  9:15     ` Jan Beulich
2018-04-11 11:53       ` [Xen-devel] " Ingo Molnar
2018-04-11 11:58         ` Jan Beulich
2018-04-12  7:32           ` Ingo Molnar
2018-04-12  7:53             ` Jan Beulich
2018-04-12  8:08               ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6b59ac31-7e90-1c18-2467-d7d294da6e5b@suse.com \
    --to=jgross@suse.com \
    --cc=JBeulich@suse.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox