Re: [PATCH v3 12/21] KVM: X86: Implement ring-based dirty memory tracking

From: Peter Xu
Date: Wed Jan 15 2020 - 10:21:03 EST


On Wed, Jan 15, 2020 at 01:50:08AM -0500, Michael S. Tsirkin wrote:
> On Tue, Jan 14, 2020 at 03:01:34PM -0500, Peter Xu wrote:
> > On Thu, Jan 09, 2020 at 02:35:46PM -0500, Michael S. Tsirkin wrote:
> > > ``void flush_dcache_page(struct page *page)``
> > >
> > > Any time the kernel writes to a page cache page, _OR_
> > > the kernel is about to read from a page cache page and
> > > user space shared/writable mappings of this page potentially
> > > exist, this routine is called.

[1]

> > >
> > >
> > > > Also, I believe this is the similar question that Jason has asked in
> > > > V2. Sorry I should mention this earlier, but I didn't address that in
> > > > this series because if we need to do so we probably need to do it
> > > > kvm-wise, rather than only in this series.
> > >
> > > You need to document these things.
> > >
> > > > I feel like it's missing
> > > > probably only because all existing KVM supported archs do not have
> > > > virtual-tagged caches as you mentioned.
> > >
> > > But is that a fact? ARM has such a variety of CPUs,
> > > I can't really tell. Did you research this to make sure?
> > >
> > > > If so, I would prefer if you
> > > > can allow me to ignore that issue until KVM starts to support such an
> > > > arch.
> > >
> > > Document limitations pls. Don't ignore them.
> >
> > Hi, Michael,
> >
> > I failed to find a good place to document about flush_dcache_page()
> > for KVM. Could you give me a suggestion?
>
> Maybe where the field is introduced. I posted the suggestions to the
> relevant patch.

(will reply there)

>
> > And I don't know about whether there's any ARM hosts that requires
> > flush_dcache_page(). I think not, because again I didn't see any
> > caller of flush_dcache_page() in KVM code yet. Otherwise I think we
> > should at least call it before the kernel reading kvm_run or after
> > publishing data to kvm_run.
>
> But is kvm run ever accessed while VCPU is running on another CPU?
> I always assumed no but maybe I'm missing something?

IMHO we need to call it even if it's running on the same CPU - please
refer to [1] above, there's no restriction on which CPU the code is
running on. I think it makes sense, especially the systems for
virtually-tagged caches because even if the memory accesses happened
on the same CPU, the virtual addresses to access the same page could
still be different when accessed from kernel/userspace.

Thanks,

--
Peter Xu