Re: [PATCH v5 12/19] KVM: Move memslot deletion to helper function

From: Sean Christopherson
Date: Fri Feb 07 2020 - 13:07:23 EST


On Fri, Feb 07, 2020 at 09:59:12AM -0800, Sean Christopherson wrote:
> On Thu, Feb 06, 2020 at 11:51:16AM -0500, Peter Xu wrote:
> > /*
> > * Make a full copy of the old memslot, the pointer will become stale
> > * when the memslots are re-sorted by update_memslots() in
> > * kvm_delete_memslot(), while to make the kvm_free_memslot() work as
> > * expected later on, we still need the cached memory slot.
> > */
>
> As above, it's more subtle than just the kvm_delete_memslot() case.
>
> /*
> * Make a full copy of the old memslot, the pointer will become stale
> * when the memslots are re-sorted by update_memslots() when deleting
> * or moving a memslot, and additional modifications to the old memslot
> * need to be made after calling update_memslots().
> */

Actually, that's not quite correct, as the same is true for all memslot
updates, and we still query @old after update_memslots() for CREATE and
FLAGS. This is better.

/*
* Make a full copy of the old memslot, the pointer will become stale
* when the memslots are re-sorted by update_memslots(), and the old
* memslot needs to be referenced after calling update_memslots(), e.g.
* to free its resources and for arch specific behavior.
*/