public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [RFC PATCH 4/4] KVM: vmx: add support for emulating UMIP
Date: Wed, 13 Jul 2016 22:30:07 +0200	[thread overview]
Message-ID: <20160713203006.GB16130@potion> (raw)
In-Reply-To: <1468351223-3250-5-git-send-email-pbonzini@redhat.com>

2016-07-12 21:20+0200, Paolo Bonzini:
> UMIP (User-Mode Instruction Prevention) is a feature of future
> Intel processors (Cannonlake?) that blocks SLDT, SGDT, STR, SIDT
> and SMSW from user-mode processes.
> 
> On Intel systems it's *almost* possible to emulate it; it slows
> down the instructions when they're executed in ring 0, but they
> are really never executed in practice.  The catch is that SMSW
> doesn't cause a vmexit, and hence SMSW will not fault.
> 
> When UMIP is enabled but not supported by the host, descriptor table
> exits are enabled, and the emulator takes care of injecting a #GP when
> any of SLDT, SGDT, STR, SIDT are encountered.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> @@ -3967,6 +3968,14 @@ static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
>  		(to_vmx(vcpu)->rmode.vm86_active ?
>  		 KVM_RMODE_VM_CR4_ALWAYS_ON : KVM_PMODE_VM_CR4_ALWAYS_ON);
>  
> +	if ((cr4 & X86_CR4_UMIP) && !boot_cpu_has(X86_FEATURE_UMIP)) {
> +		vmcs_set_bits(SECONDARY_VM_EXEC_CONTROL,
> +			      SECONDARY_EXEC_DESC);

If UMIP support is not exposed in CPUID, we ought to #GP(0), because it
is a write to reserved bits.  It could also mean that the vm control is
not supported.

> +		hw_cr4 &= ~X86_CR4_UMIP;
> +	} else
> +		vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL,
> +				SECONDARY_EXEC_DESC);

I think we don't have to do anything when the CPU supports UMIP,

 if (!boot_cpu_has(X86_FEATURE_UMIP) {
   if ((cr4 & X86_CR4_UMIP)) { ... } else ...
 }

And we could then return true in vmx_umip_emulated() when
boot_cpu_has(X86_FEATURE_UMIP).
(Just for self-documentation, because occurrence of X86_FEATURE_UMIP is
 most likely a subset of SECONDARY_EXEC_DESC.)

> @@ -8597,7 +8627,8 @@ static bool vmx_xsaves_supported(void)
>  
>  static bool vmx_umip_emulated(void)
>  {
> -	return false;
> +	return vmcs_config.cpu_based_2nd_exec_ctrl &
> +		SECONDARY_EXEC_DESC;
>  }

  parent reply	other threads:[~2016-07-13 20:30 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-12 19:20 [RFC PATCH 0/4] KVM: Emulate UMIP (or almost do so) Paolo Bonzini
2016-07-12 19:20 ` [RFC PATCH 1/4] x86: add UMIP feature and CR4 bit Paolo Bonzini
2016-07-12 19:20 ` [RFC PATCH 2/4] KVM: x86: emulate sldt and str Paolo Bonzini
2016-07-12 19:20 ` [RFC PATCH 3/4] KVM: x86: add support for emulating UMIP Paolo Bonzini
2016-07-13 20:03   ` Radim Krčmář
2016-07-14  7:00     ` Paolo Bonzini
2016-07-14 12:24       ` Radim Krčmář
2016-07-12 19:20 ` [RFC PATCH 4/4] KVM: vmx: " Paolo Bonzini
2016-07-13  9:21   ` Yang Zhang
2016-07-13  9:35     ` Paolo Bonzini
2016-07-13  9:54       ` Yang Zhang
2016-07-13  9:35     ` Paolo Bonzini
2016-07-13 10:02       ` Yang Zhang
2016-07-13 10:21         ` Paolo Bonzini
2016-07-13 20:30   ` Radim Krčmář [this message]
2016-07-14  8:09     ` Paolo Bonzini
2016-07-14 12:36       ` Radim Krčmář
2016-07-14 12:54         ` Paolo Bonzini
2016-07-31  2:32       ` Wanpeng Li
2016-08-01 15:01         ` Paolo Bonzini
2016-08-02  1:05           ` Wanpeng Li
2016-07-13  8:29 ` [RFC PATCH 0/4] KVM: Emulate UMIP (or almost do so) Yang Zhang
2016-07-13  9:34   ` Paolo Bonzini
2016-12-13  4:03 ` Li, Liang Z
2016-12-13 11:03   ` Paolo Bonzini
2017-03-01  9:04     ` Yu Zhang
2017-03-06 21:07       ` Paolo Bonzini
2017-03-10  8:02       ` Yu Zhang
2017-03-10  8:36         ` Paolo Bonzini
2017-03-10  9:31           ` Yu Zhang
2017-03-10 11:28             ` Yu Zhang
2017-03-10 15:00             ` Paolo Bonzini

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=20160713203006.GB16130@potion \
    --to=rkrcmar@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /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