Re: [PATCH v4 13/26] KVM: Add arch hook when VM is added/deleted

From: Chao Gao
Date: Fri Sep 09 2022 - 02:08:27 EST


On Thu, Sep 08, 2022 at 04:25:29PM -0700, isaku.yamahata@xxxxxxxxx wrote:
>+__weak int kvm_arch_post_init_vm(struct kvm *kvm)

int __weak

>+{
>+ return 0;
>+}
>+
> /*
> * Called after the VM is otherwise initialized, but just before adding it to
> * the vm_list.
> */
>-__weak int kvm_arch_post_init_vm(struct kvm *kvm)
>+__weak int kvm_arch_add_vm(struct kvm *kvm, int usage_count)
>+{
>+ return kvm_arch_post_init_vm(kvm);
>+}
>+
>+__weak int kvm_arch_del_vm(int usage_count)

ditto

>+static void kvm_del_vm(void)
>+{
>+ cpus_read_lock();
>+ mutex_lock(&kvm_lock);
>+ kvm_arch_del_vm(kvm_usage_count);
>+ mutex_unlock(&kvm_lock);
>+ cpus_read_unlock();

kvm_arch_del_vm() is an empty function now. I don't understand why
cpus_read_lock() is needed. Maybe add the lock when you fill up
kvm_arch_del_vm().