Message ID | 20220909104506.738478-8-eesposit@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | kvm: implement atomic memslot updates | expand |
On 9/9/22 12:45, Emanuele Giuseppe Esposito wrote: > /* > - * if change is DELETE or MOVE, invalid is in active memslots > - * and old in inactive, so replace old with new. > + * if change is DELETE or MOVE, invalid is in both active and inactive > + * memslot list. This means that we don't need old anymore, and > + * we should replace invalid with new. > */ > - kvm_replace_memslot(kvm, batch->old, batch->new); > + if (batch->change == KVM_MR_DELETE || batch->change == KVM_MR_MOVE) > + kvm_replace_memslot(kvm, batch->invalid, batch->new); > + else > + kvm_replace_memslot(kvm, batch->old, batch->new); This is also kvm_replace_memslot(kvm, batch->invalid ?: batch->old, batch->new); with no need to look at batch->change. Paolo
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 6b73615891f0..31e46f9a06fa 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1830,6 +1830,7 @@ static int kvm_prepare_memslot(struct kvm *kvm, } batch->invalid = invalid_slot; kvm_invalidate_memslot(kvm, old, invalid_slot); + kvm_replace_memslot(kvm, old, invalid_slot); } r = kvm_prepare_memory_region(kvm, batch); @@ -1900,10 +1901,14 @@ static int kvm_set_memslot(struct kvm *kvm, return r; /* - * if change is DELETE or MOVE, invalid is in active memslots - * and old in inactive, so replace old with new. + * if change is DELETE or MOVE, invalid is in both active and inactive + * memslot list. This means that we don't need old anymore, and + * we should replace invalid with new. */ - kvm_replace_memslot(kvm, batch->old, batch->new); + if (batch->change == KVM_MR_DELETE || batch->change == KVM_MR_MOVE) + kvm_replace_memslot(kvm, batch->invalid, batch->new); + else + kvm_replace_memslot(kvm, batch->old, batch->new); /* either old or invalid is the same, since invalid is old's copy */ as_id = kvm_memslots_get_as_id(batch->old, batch->new);
In preparation for atomic memslot updates, make sure the invalid memslot is also replacing the old one in the inactive list. This implies that once we want to insert the new slot for a MOVE, or simply delete the existing one for a DELETE, we need to remove the "invalid" slot, not the "old" one. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> --- virt/kvm/kvm_main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)