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

From: Peter Xu
Date: Tue Jan 21 2020 - 03:29:44 EST


On Mon, Jan 20, 2020 at 02:47:46AM -0500, Michael S. Tsirkin wrote:
> On Mon, Jan 20, 2020 at 03:29:15PM +0800, Peter Xu wrote:
> > On Sun, Jan 19, 2020 at 05:12:35AM -0500, Michael S. Tsirkin wrote:
> > > On Sun, Jan 19, 2020 at 10:09:53AM +0100, Paolo Bonzini wrote:
> > > > On 09/01/20 20:15, Peter Xu wrote:
> > > > > Regarding dropping the indices: I feel like it can be done, though we
> > > > > probably need two extra bits for each GFN entry, for example:
> > > > >
> > > > > - Bit 0 of the GFN address to show whether this is a valid publish
> > > > > of dirty gfn
> > > > >
> > > > > - Bit 1 of the GFN address to show whether this is collected by the
> > > > > user
> > > >
> > > > We can use bit 62 and 63 of the GFN.
> > >
> > > If we are short on bits we can just use 1 bit. E.g. set if
> > > userspace has collected the GFN.
> >
> > I'm still unsure whether we can use only one bit for this. Say,
> > otherwise how does the userspace knows the entry is valid? For
> > example, the entry with all zeros ({.slot = 0, gfn = 0}) could be
> > recognized as a valid dirty page on slot 0 gfn 0, even if it's
> > actually an unused entry.
>
> So I guess the reverse: valid entry has bit set, userspace sets it to
> 0 when it collects it?

Right, this seems to work.

Thanks,

--
Peter Xu