All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: speck@linutronix.de
Subject: [MODERATED] Re: [PATCH v4 8/8] [PATCH v4 8/8] Linux Patch #8
Date: Thu, 28 Jun 2018 12:40:48 -0400	[thread overview]
Message-ID: <20180628164047.GA3445@char.US.ORACLE.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1806271853470.17787@nanos.tec.linutronix.de>

> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -194,6 +194,14 @@ module_param(ple_window_max, uint, 0444)
>  
>  extern const ulong vmx_return;
>  
> +static DEFINE_STATIC_KEY_FALSE(vmx_l1d_should_flush);
> +
> +enum vmx_l1d_flush_state {
> +	VMENTER_L1D_FLUSH_NEVER,
> +	VMENTER_L1D_FLUSH_COND,
> +	VMENTER_L1D_FLUSH_ALWAYS,
> +};
> +
>  struct kvm_vmx {
>  	struct kvm kvm;
>  
> @@ -2653,38 +2661,10 @@ static void vmx_prepare_guest_switch(str
>  {
>  	vmx_save_host_state(vcpu);
>  
> -	if (!enable_ept || static_cpu_has(X86_FEATURE_HYPERVISOR) ||
> -	    !static_cpu_has(X86_BUG_L1TF)) {
> -		vcpu->arch.flush_cache_req = false;
> -		return;
> -	}
> +	if (static_branch_unlikely(&vmx_l1d_should_flush)) {
> +		bool force = vmentry_l1d_flush == VMENTER_L1D_FLUSH_ALWAYS;
>  
> -	switch (vmentry_l1d_flush) {
> -	case 0:
> -		vcpu->arch.flush_cache_req = false;
> -		break;
> -	case 1:
> -		/*
> -		 * If vmentry_l1d_flush is 1, each vmexit handler is responsible for
> -		 * setting vcpu->arch.vcpu_unconfined.  Currently this happens in the
> -		 * following cases:
> -		 * - vmlaunch/vmresume: we do not want the cache to be cleared by a
> -		 *   nested hypervisor *and* by KVM on bare metal, so we just do it
> -		 *   on every nested entry.  Nested hypervisors do not bother clearing
> -		 *   the cache.
> -		 * - anything that runs the emulator (the slow paths for EPT misconfig
> -		 *   or I/O instruction)
> -		 * - anything that can cause get_user_pages (EPT violation, and again
> -		 *   the slow paths for EPT misconfig or I/O instruction)
> -		 * - anything that can run code outside KVM (external interrupt,
> -		 *   which can run interrupt handlers or irqs; or the sched_in
> -		 *   preempt notifier)
> -		 */
> -		break;
> -	case 2:
> -	default:
> -		vcpu->arch.flush_cache_req = true;
> -		break;
> +		vcpu->arch.flush_cache_req = force;

This ought to be:

		if (force)
			vcpu->arch.flush_cache_req = force;

or perhaps:

		if (vmentry_l1d_flush == VMENTER_L1D_FLUSH_ALWAYS)
			vcpu->arch.flush_cache_req = true;

The problem is that if we are in 'vmentry_l1d_flush=1' we should
not modify vcpu->arch.flush_cache_req as the vcpu_enter_guest does:

7464                                                                                 
7465         vcpu->arch.flush_cache_req = vcpu->arch.vcpu_unconfined;                 <===
7466         kvm_x86_ops->prepare_guest_switch(vcpu);                                
7467         vcpu->arch.vcpu_unconfined = false;                                     
7468         if (vcpu->arch.flush_cache_req)                                         
7469                 vcpu->stat.l1d_flush++;      

Rethinking this, maybe rip the above from vcpu_enter_guest and in this function
will do:

		vcpu->arch.flush_cache_req = (vmentry_l1d_flush == VMENTER_L1D_FLUSH_ALWAYS) ? true : vcpu->arch.vcpu_unconfined;

or so?

Let me try that out.

      reply	other threads:[~2018-06-28 16:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-23 13:54 [MODERATED] [PATCH v4 8/8] [PATCH v4 8/8] Linux Patch #8 konrad.wilk
2018-06-25 14:32 ` [MODERATED] " Paolo Bonzini
2018-06-27 13:05 ` Thomas Gleixner
2018-06-27 14:43   ` [MODERATED] " Konrad Rzeszutek Wilk
2018-06-27 17:00     ` Thomas Gleixner
2018-06-28 16:40       ` Konrad Rzeszutek Wilk [this message]

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=20180628164047.GA3445@char.US.ORACLE.com \
    --to=konrad.wilk@oracle.com \
    --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.