linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mingwei Zhang <mizhang@google.com>
To: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Cc: David Matlack <dmatlack@google.com>,
	Jim Mattson <jmattson@google.com>,
	 Maxim Levitsky <mlevitsk@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	 Paolo Bonzini <pbonzini@redhat.com>,
	Vladimir Davydov <vdavydov.dev@gmail.com>,
	linux-mm@kvack.org,  Sean Christopherson <seanjc@google.com>
Subject: Re: The root cause of failure of access_tracking_perf_test in a nested guest
Date: Tue, 4 Oct 2022 11:52:26 -0700	[thread overview]
Message-ID: <CAL715WLvb7H3T-WqL7QKLBKP6Q_+ma=sXZQJXt0bXzkLstpWVQ@mail.gmail.com> (raw)
In-Reply-To: <d9036fdc-1fd5-f5bd-1afa-7b7243f681c0@redhat.com>

On Mon, Sep 26, 2022 at 1:50 AM Emanuele Giuseppe Esposito
<eesposit@redhat.com> wrote:
>
>
>
> Am 23/09/2022 um 22:28 schrieb David Matlack:
> > On Fri, Sep 23, 2022 at 12:25:00PM -0700, Jim Mattson wrote:
> >> On Fri, Sep 23, 2022 at 3:16 AM Maxim Levitsky <mlevitsk@redhat.com> wrote:
> >>>
> >>> Because of this, when the guest clears the accessed bit in its nested EPT entries, KVM doesn't
> >>> notice/intercept it and corresponding EPT sptes remain the same, thus later the guest access to
> >>> the memory is not intercepted and because of this doesn't turn back
> >>> the accessed bit in the guest EPT tables.
> >>
> >> Does the guest execute an INVEPT after clearing the accessed bit?
> >
> > No, that's the problem. In L1, access_tracking_perf_test is using
> > page_idle to mark guest memory as idle, which results in clear_young()
> > notifiers being sent to KVM clear access bits. clear_young() is
> > explicitly allowed to omit flushes, so KVM happily obliges.
> >
> >       /*
> >        * clear_young is a lightweight version of clear_flush_young. Like the
> >        * latter, it is supposed to test-and-clear the young/accessed bitflag
> >        * in the secondary pte, but it may omit flushing the secondary tlb.
> >        */
> >       int (*clear_young)(struct mmu_notifier *subscription,
> >                          struct mm_struct *mm,
> >                          unsigned long start,
> >                          unsigned long end);
> >
> > We could modify page_idle so that KVM performs TLB flushes. For example,
> > add a mechanism for userspace to trigger a TLB flush. Or change
> > page_idle to use clear_flush_young() (although that would be incredibly
> > expensive since page_idle only allows clearing one pfn at a time). But
> > I'm not sure creating a new userspace API just for this test is really
> > worth it, especially with multigen LRU coming soon.

Can we add an operation that causes KVM to flush guest TLB explicitly?
For instance, we can use any operation that causes a change in
EPT/NPT, which would invoke an explicit TLB flush.  E.g., enabling
dirty logging will do the job. Alternatively, adding a memslot for the
guest, letting the guest touch it and then removing it at host level
will also flush the TLB. I believe the both should be architecturally
neutral and the latter seems more stable.

In any case, would an explicit TLB suffice in this case? I think this
will cause the zapping of PTEs in L0 EPT/NPT.

Thanks.
-Mingwei


      reply	other threads:[~2022-10-04 18:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23 10:16 The root cause of failure of access_tracking_perf_test in a nested guest Maxim Levitsky
2022-09-23 11:57 ` Emanuele Giuseppe Esposito
2022-09-23 17:30 ` David Matlack
2022-09-23 19:25 ` Jim Mattson
2022-09-23 20:28   ` David Matlack
2022-09-26  8:50     ` Emanuele Giuseppe Esposito
2022-10-04 18:52       ` Mingwei Zhang [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='CAL715WLvb7H3T-WqL7QKLBKP6Q_+ma=sXZQJXt0bXzkLstpWVQ@mail.gmail.com' \
    --to=mizhang@google.com \
    --cc=dmatlack@google.com \
    --cc=eesposit@redhat.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vdavydov.dev@gmail.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;
as well as URLs for NNTP newsgroup(s).