kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacob Xu <jacobhxu@google.com>
To: kvm@vger.kernel.org
Subject: tlb_flush stat on Intel/AMD
Date: Mon, 20 Jul 2020 12:08:05 -0700	[thread overview]
Message-ID: <CAJ5mJ6i-SoZO+F+Xz5OqK7BE7z7eLvE1hC=KX1ABwdnTw-QZuA@mail.gmail.com> (raw)

Hi all,

I wrote a kvm selftest to enter a 1-vcpu guest VM running a nop in one
thread and check the VM's debugfs entry for # of tlb flushes while
that was running. Installing the latest upstream kernel and running
this on an intel host showed a tlb_flush count of 30, while running it
on an amd host shows the tlb_flush count at 0.

Do we have an inconsistency between Intel and AMD in how VCPU_STAT is
incremented?

From browsing the code, we see that the stat only gets incremented in
the kvm_ wrappers of the x86_ops functions tlb_flush_all,
tlb_flush_current, and tlb_flush_guest. These wrappers are only called
via the KVM request api (referred to as deferred flushes in some other
threads), and there other instances of calling the x86_ops tlb_flush
methods directly (immediate flush).

It looks like most of the tlb flush calls are deferred, but there are
a few instances using the immediate flush where it's not counted
(kvm_mmu_load, svm_set_cr4, vmx_set_apic_access_page,
nested_prepare_vmcb_control). Is there a guideline on when to
deferred/immediate tlb_flush?

Could this be a cause for the lower tlb_flush stat seen on an AMD
host? Or perhaps there's another reason for the difference due to the
(too) simple selftest?

In the case of svm_tlb_flush, it seems like the tlb flush is deferred
anyway since the response to setting a tlb flush control bit in the
VMCB is not acted upon until entering the guest. So it seems we could
count tlb flushes on svm more easily by incrementing the counter by
checking the control bit before KVM_RUN. Though perhaps there's
another case we'd like to count as tlb flush when the guest switches
ASID (where would we track this?).

Would switching to this alternative for incrementing tlb_flush stat in
svm be much different than what we do right now?

Thanks,

Jacob

             reply	other threads:[~2020-07-20 19:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-20 19:08 Jacob Xu [this message]
2020-07-21 20:16 ` tlb_flush stat on Intel/AMD Sean Christopherson
2020-07-28 18:07   ` Jacob Xu

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='CAJ5mJ6i-SoZO+F+Xz5OqK7BE7z7eLvE1hC=KX1ABwdnTw-QZuA@mail.gmail.com' \
    --to=jacobhxu@google.com \
    --cc=kvm@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).