All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@suse.de>
To: speck@linutronix.de
Subject: [MODERATED] Re: [patch 04/11] [PATCH v2 04/10] Linux Patch #4
Date: Fri, 20 Apr 2018 18:15:33 +0200	[thread overview]
Message-ID: <20180420161533.GK13977@pd.tnic> (raw)
In-Reply-To: <20180420022613.057637144@localhost.localdomain>

On Thu, Apr 19, 2018 at 10:25:44PM -0400, speck for konrad.wilk_at_oracle.com wrote:
> KVM/SVM/VMX/x86/spectre_v2: Support the combination of guest IBRS and ours.
> 
> A guest may modify the SPEC_CTRL MSR from the value used by the
> kernel. Since we don't use IBRS, this means a value of zero
> is what we need in the host.
> 
> But the 336996-Speculative-Execution-Side-Channel-Mitigations.pdf
> refers to the other bits as reserved so we should respect the
> boot time SPEC_CTRL value and use that.
> 
> This allows us to deal with future extensions to the SPEC_CTRL
> interface if any at all.
> 
> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> ---
> v2: New patch
> ---
>  arch/x86/kvm/svm.c | 6 +++---
>  arch/x86/kvm/vmx.c | 6 +++---
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index be9c839e2c89..f666b4c21559 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -5401,7 +5401,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
>  	 * is no need to worry about the conditional branch over the wrmsr
>  	 * being speculatively taken.
>  	 */
> -	if (svm->spec_ctrl)
> +	if (svm->spec_ctrl || need_spec_ctrl_acc())
>  		native_wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);

Instead of those silly set/clear helpers, why not do this:

	if (svm->spec_ctrl)
		x86_enable_ibrs();

and hide in x86_enable_ibrs() all that logic of checking
x86_spec_ctrl_base and writing the MSR and whatever else we will need in
the future?

This way you don't need to export helper functions any bit defines
around the place - just the enable/disable functions which hide the
whole logic?

>  	asm volatile (
> @@ -5514,8 +5514,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
>  	if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)))
>  		svm->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL);
>  
> -	if (svm->spec_ctrl)
> -		native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
> +	if (svm->spec_ctrl || need_spec_ctrl_acc())
> +		native_wrmsrl(MSR_IA32_SPEC_CTRL, clear_spec_ctrl(SPEC_CTRL_IBRS));

Same here:

	if (svm->spec_ctrl)
		x86_disable_ibrs();

And so on...

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

  reply	other threads:[~2018-04-20 16:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-20  2:25 [MODERATED] [patch 04/11] [PATCH v2 04/10] Linux Patch #4 konrad.wilk
2018-04-20 16:15 ` Borislav Petkov [this message]
2018-04-20 16:39   ` [MODERATED] " Konrad Rzeszutek Wilk
2018-04-20 17:03     ` Borislav Petkov
2018-04-20 17:17       ` Konrad Rzeszutek Wilk
2018-04-22  5:57         ` Jon Masters
2018-04-20 17:06     ` Jon Masters

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=20180420161533.GK13977@pd.tnic \
    --to=bp@suse.de \
    --cc=speck@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.