Re: [RFC PATCH 9/9] kvm_main.c: handle atomic memslot update

Paolo Bonzini
2022-09-28T17:29:32Z

On 9/9/22 12:45, Emanuele Giuseppe Esposito wrote:
> @@ -1782,7 +1782,8 @@ static void kvm_update_flags_memslot(struct kvm *kvm,
>
> /*
> * Takes kvm->slots_arch_lock, and releases it only if
> - * invalid_slot allocation or kvm_prepare_memory_region failed.
> + * invalid_slot allocation, kvm_prepare_memory_region failed
> + * or batch->is_move_delete is true.
> */

This _is_ getting out of hand, though. :) It is not clear to me why you
need to do multiple swaps. If you did a single swap, you could do all
the allocations of invalid slots in a separate loop, called with
slots_arch_lock taken and not released until the final swap. In other
words, something like

mutex_lock(&kvm->slots_arch_lock);
r = create_invalid_slots();
if (r < 0)
return r;

replace_old_slots();

// also handles abort on failure
prepare_memory_regions();
if (r < 0)
return r;
swap();
finish_memslots();

where each function is little more than a loop over the corresponding
function called by KVM_SET_MEMORY_REGION.

Paolo