Re: [PATCH v8] kvm: make vcpu life cycle separated from kvm instance

From: Liu ping fan
Date: Tue Feb 07 2012 - 01:13:32 EST


2012/2/7 Takuya Yoshikawa <yoshikawa.takuya@xxxxxxxxxxxxx>:
> (2012/02/07 11:34), Liu Ping Fan wrote:
>
>> Â static int kvm_vcpu_release(struct inode *inode, struct file *filp)
>
> Is this a hot path?
> If no, do you really need to pre-allocate the space for the next vcpus?
>
No, it is not a hot path, I will try your way in next version.

>> Â {
>> + Â Â int i;
>> Â Â Â struct kvm_vcpu *vcpu = filp->private_data;
>> + Â Â struct kvm *kvm = vcpu->kvm;
>> + Â Â struct kvm_vcpu *vcpus_next;
>> + Â Â filp->private_data = NULL;
>> +
>> + Â Â for (i = 0; i< Âatomic_read(&kvm->online_vcpus); i++) {
>> + Â Â Â Â Â Â if (vcpu == kvm->vcpus+i)
>> + Â Â Â Â Â Â Â Â Â Â break;
>> + Â Â }
>> + Â Â mutex_lock(&kvm->lock);
>> + Â Â vcpus_next = Âkvm->vcpus_array +
>> + Â Â Â Â Â Â ((kvm->vcpus - kvm->vcpus_array) ? 0 : KVM_MAX_VCPUS);
>> +
>> + Â Â memset(vcpus_next, 0, KVM_MAX_VCPUS*sizeof(struct kvm_vcpu *));
>> + Â Â memcpy(vcpus_next, kvm->vcpus, i*sizeof(struct kvm_vcpu *));
>> + Â Â memcpy(vcpus_next+i, kvm->vcpus+i+1,
>> + Â Â Â Â Â Â (atomic_read(&kvm->online_vcpus)-i)*sizeof(struct kvm_vcpu *));
>> + Â Â atomic_dec(&kvm->online_vcpus);
>> + Â Â /* Removed vcpu can not be seen from vcpus[] */
>
> This comment is confusing.
>
I mean after assigning pointer, vcpu which to be removed can not be
seen from vcpus[]. I will fix this comment.
>> + Â Â rcu_assign_pointer(kvm->vcpus, vcpus_next);
>> + Â Â mutex_unlock(&kvm->lock);
>> +
>> + Â Â synchronize_rcu();
>>
>> - Â Â kvm_put_kvm(vcpu->kvm);
>> + Â Â /* vcpu is out of list,drop it safely */
>
> Ditto.
>
> Do you mean something like
> "now that there is no reader of it we can safely free this" ?
>
Yes, that is exactly what I mean

Thanks and regards,
ping fan

> (Please do not trust me: ÂI am not a native English speaker as you know.)
>
>> + Â Â kvm_vcpu_destruct(vcpu);
>> Â Â Â return 0;
>> Â }
>
>
> Â Â Â ÂTakuya
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/