mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	kvm <kvm@vger.kernel.org>, Paolo Bonzini <pbonzini@redhat.com>,
	Radim Kr??m???? <rkrcmar@redhat.com>,
	Wanpeng Li <wanpeng.li@hotmail.com>
Subject: Re: [PATCH v4 2/4] KVM: X86: Add paravirt remote TLB flush
Date: Mon, 13 Nov 2017 11:46:34 +0100	[thread overview]
Message-ID: <20171113104634.62cmjalnj73scfnl@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <CANRm+Cw0x4dFUrvCYFeeCHRibd--0ZVmEcr-4aoKiMiOh9TKUA@mail.gmail.com>

On Mon, Nov 13, 2017 at 04:26:57PM +0800, Wanpeng Li wrote:
> 2017-11-13 16:04 GMT+08:00 Peter Zijlstra <peterz@infradead.org>:

> > So if at this point a vCPU gets preempted we'll still spin-wait for it,
> > which is sub-optimal.
> >
> > I think we can come up with something to get around that 'problem' if
> > indeed it is a problem. But we can easily do that as follow up patches.
> > Just let me know if you think its worth spending more time on.
> 
> You can post your idea, it is always smart. :) Then we can evaluate
> the complexity and gains.

I'm not sure I have a fully baked idea just yet, but the general idea
would be something like:

 - switch (back) to a dedicated TLB invalidate IPI

 - introduce KVM_VCPU_IPI_PENDING

 - change flush_tlb_others() into something like:

   for_each_cpu(cpu, flushmask) {
	 src = &per_cpu(steal_time, cpu);
	 state = READ_ONCE(src->preempted);
	 do {
		 if (state & KVM_VCPU_PREEMPTED) {
			 if (try_cmpxchg(&src->preempted, &state,
						 state | KVM_VCPU_SHOULD_FLUSH)) {
				 __cpumask_clear_cpu(cpu, flushmask);
				 break;
			 }
		 }
	 } while (!try_cmpxchg(&src->preempted, &state,
				 state | KVM_VCPU_IPI_PENDING));
   }

   apic->send_IPI_mask(flushmask, CALL_TLB_VECTOR);

   for_each_cpu(cpu, flushmask) {
	 src = &per_cpu(steal_time, cpu);
	 smp_cond_load_acquire(&src->preempted, !(VAL & KVM_VCPU_IPI_PENDING);
   }


 - have the TLB invalidate handler do something like:

   state = READ_ONCE(src->preempted);
   if (!(state & KVM_VCPU_IPI_PENDING))
	   return;

   local_flush_tlb();

   do {
   } while (!try_cmpxchg(&src->preempted, &state,
			 state & ~KVM_VCPU_IPI_PENDING));

 - then at VMEXIT time do something like:

   state = READ_ONCE(src->preempted);
   do {
	if (!(state & KVM_VCPU_IPI_PENDING))
		break;
   } while (!try_cmpxchg(&src->preempted, state,
			 (state & ~KVM_VCPU_IPI_PENDING) |
			 KVM_VCPU_SHOULD_FLUSH));

   and clear any possible pending TLB_VECTOR in the guest state to avoid
   raising that IPI spuriously on enter again.


This way the preemption will clear the IPI_PENDING and the
flush_others() wait loop will terminate.

  reply	other threads:[~2017-11-13 10:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-13  0:33 [PATCH v4 0/4] KVM: X86: Paravirt " Wanpeng Li
2017-11-13  0:33 ` [PATCH v4 1/4] KVM: X86: Add vCPU running/preempted state Wanpeng Li
2017-11-14 16:45   ` David Hildenbrand
2017-11-14 17:03     ` Peter Zijlstra
2017-11-14 17:04       ` Paolo Bonzini
2017-11-13  0:33 ` [PATCH v4 2/4] KVM: X86: Add paravirt remote TLB flush Wanpeng Li
2017-11-13  7:59   ` Peter Zijlstra
2017-11-13  8:12     ` Wanpeng Li
2017-11-13  8:04   ` Peter Zijlstra
2017-11-13  8:26     ` Wanpeng Li
2017-11-13 10:46       ` Peter Zijlstra [this message]
2017-11-13 13:02         ` Peter Zijlstra
2017-11-14  6:10           ` Wanpeng Li
2017-11-14  7:35             ` Peter Zijlstra
2017-11-14  6:28         ` Wanpeng Li
2017-11-14  7:56           ` Peter Zijlstra
2017-11-13  0:33 ` [PATCH v4 3/4] KVM: X86: introduce invalidate_gpa argument to tlb flush Wanpeng Li
2017-11-13  0:33 ` [PATCH v4 4/4] KVM: X86: Add flush_on_enter before guest enter Wanpeng Li

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=20171113104634.62cmjalnj73scfnl@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=wanpeng.li@hotmail.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

all inboxes | Powered by JetHome®