All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH RFC v2 3/4] Break dependency between vcpu index in vcpus array and vcpu_id.
Date: Tue, 26 May 2009 11:55:03 +0300	[thread overview]
Message-ID: <20090526085503.GP3948@redhat.com> (raw)
In-Reply-To: <4A1BA979.4010808@redhat.com>

On Tue, May 26, 2009 at 11:34:01AM +0300, Avi Kivity wrote:
> Gleb Natapov wrote:
>> Archs are free to use vcpu_id as they see fit. For x86 it is used as
>> vcpu's apic id.
>>
>>   
>
> You need a KVM_CAP to inform userspace that the vcpu id has changed meaning.
>
Will add.

>>  inline int kvm_is_mmio_pfn(pfn_t pfn)
>>  {
>>  	if (pfn_valid(pfn)) {
>> @@ -1713,15 +1708,12 @@ static int create_vcpu_fd(struct kvm_vcpu *vcpu)
>>  /*
>>   * Creates some virtual cpus.  Good luck creating more than one.
>>   */
>> -static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n)
>> +static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
>>  {
>>  	int r;
>>  	struct kvm_vcpu *vcpu;
>>  -	if (!valid_vcpu(n))
>> -		return -EINVAL;
>> -
>> -	vcpu = kvm_arch_vcpu_create(kvm, n);
>> +	vcpu = kvm_arch_vcpu_create(kvm, id);
>>  	if (IS_ERR(vcpu))
>>  		return PTR_ERR(vcpu);
>>  @@ -1732,25 +1724,36 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm 
>> *kvm, int n)
>>  		return r;
>>   	mutex_lock(&kvm->lock);
>> -	if (kvm->vcpus[n]) {
>> -		r = -EEXIST;
>> +	if (atomic_read(&kvm->online_vcpus) == KVM_MAX_VCPUS) {
>> +		r = -EINVAL;
>>  		goto vcpu_destroy;
>>  	}
>> -	kvm->vcpus[n] = vcpu;
>> -	if (n == 0)
>> -		kvm->bsp_vcpu = vcpu;
>> -	mutex_unlock(&kvm->lock);
>> +
>> +	for (r = 0; r < atomic_read(&kvm->online_vcpus); r++)
>> +		if (kvm->vcpus[r]->vcpu_id == id) {
>> +			r = -EEXIST;
>> +			goto vcpu_destroy;
>> +		}
>> +
>> +	BUG_ON(kvm->vcpus[atomic_read(&kvm->online_vcpus)]);
>>   	/* Now it's all set up, let userspace reach it */
>>  	kvm_get_kvm(kvm);
>>  	r = create_vcpu_fd(vcpu);
>> -	if (r < 0)
>> -		goto unlink;
>> +	if (r < 0) {
>> +		kvm_put_kvm(kvm);
>> +		goto vcpu_destroy;
>> +	}
>> +
>> +	kvm->vcpus[atomic_read(&kvm->online_vcpus)] = vcpu;
>> +	smp_wmb();
>> +	atomic_inc(&kvm->online_vcpus);
>> +
>> +	if (id == 0)
>> +		kvm->bsp_vcpu = vcpu;
>> +	mutex_unlock(&kvm->lock);
>>  	return r;
>>  -unlink:
>> -	mutex_lock(&kvm->lock);
>> -	kvm->vcpus[n] = NULL;
>>  vcpu_destroy:
>>  	mutex_unlock(&kvm->lock);
>>  	kvm_arch_vcpu_destroy(vcpu);
>>   
>
> Don't the vcpu ioctls need to be updated?  They get the vcpu id as a  
> parameter.
>
Are you sure they do? vcpu ioctls are issued on vcpu fd, no need to pass
vcpu id as a parameter.

--
			Gleb.

  reply	other threads:[~2009-05-26  8:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-25 15:50 [PATCH RFC v2 0/4] decouple vcpu index from apic id Gleb Natapov
2009-05-25 15:50 ` [PATCH RFC v2 1/4] Introduce kvm_vcpu_is_bsp() function Gleb Natapov
2009-05-25 20:46   ` Marcelo Tosatti
2009-05-26  6:12     ` Gleb Natapov
2009-05-25 15:50 ` [PATCH RFC v2 2/4] Use pointer to vcpu instead of vcpu_id in timer code Gleb Natapov
2009-05-26  8:30   ` Avi Kivity
2009-05-26  8:52     ` Gleb Natapov
2009-05-25 15:50 ` [PATCH RFC v2 3/4] Break dependency between vcpu index in vcpus array and vcpu_id Gleb Natapov
2009-05-26  8:34   ` Avi Kivity
2009-05-26  8:55     ` Gleb Natapov [this message]
2009-05-26  8:57       ` Avi Kivity
2009-05-25 15:50 ` [PATCH RFC v2 4/4] Use macro to iterate over vcpus Gleb Natapov
2009-05-26  8:18   ` Avi Kivity
2009-05-26  8:37     ` Gleb Natapov
2009-05-26  8:56       ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090526085503.GP3948@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.