From: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
To: Liu Ping Fan <kernelfans@gmail.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
avi@redhat.com, aliguori@us.ibm.com, gleb@redhat.com,
mtosatti@redhat.com, jan.kiszka@web.de
Subject: Re: [PATCH v4] kvm: make vcpu life cycle separated from kvm instance
Date: Thu, 15 Dec 2011 13:33:19 +0800 [thread overview]
Message-ID: <4EE9869F.4070702@linux.vnet.ibm.com> (raw)
In-Reply-To: <1323923328-917-1-git-send-email-kernelfans@gmail.com>
On 12/15/2011 12:28 PM, Liu Ping Fan wrote:
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -1833,11 +1833,12 @@ static void kvm_mmu_put_page(struct kvm_mmu_page *sp, u64 *parent_pte)
>
> static void kvm_mmu_reset_last_pte_updated(struct kvm *kvm)
> {
> - int i;
> struct kvm_vcpu *vcpu;
>
> - kvm_for_each_vcpu(i, vcpu, kvm)
> + rcu_read_lock();
> + kvm_for_each_vcpu(vcpu, kvm)
> vcpu->arch.last_pte_updated = NULL;
> + rcu_read_unlock();
> }
>
I am sure that you should rebase it on the current kvm tree.
> static void kvm_mmu_unlink_parents(struct kvm *kvm, struct kvm_mmu_page *sp)
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index c38efd7..acaa154 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1830,11 +1830,13 @@ static int get_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
>
> switch (msr) {
> case HV_X64_MSR_VP_INDEX: {
> - int r;
> + int r = 0;
> struct kvm_vcpu *v;
> - kvm_for_each_vcpu(r, v, vcpu->kvm)
> + kvm_for_each_vcpu(v, vcpu->kvm) {
> if (v == vcpu)
> data = r;
> + r++;
> + }
Do not need rcu_lock?
> +struct kvm_vcpu *kvm_vcpu_get(struct kvm_vcpu *vcpu);
> +void kvm_vcpu_put(struct kvm_vcpu *vcpu);
> +void kvm_arch_vcpu_zap(struct work_struct *work);
> +
> +#define kvm_for_each_vcpu(vcpu, kvm) \
> + list_for_each_entry_rcu(vcpu, &kvm->vcpus, list)
>
> -#define kvm_for_each_vcpu(idx, vcpup, kvm) \
> - for (idx = 0; \
> - idx < atomic_read(&kvm->online_vcpus) && \
> - (vcpup = kvm_get_vcpu(kvm, idx)) != NULL; \
> - idx++)
> +#define kvm_for_each_vcpu_continue(vcpu, kvm) \
> + list_for_each_entry_continue_rcu(vcpu, &kvm->vcpus, list)
>
Where is it used?
> +struct kvm_vcpu *kvm_vcpu_get(struct kvm_vcpu *vcpu)
> +{
> + if (vcpu == NULL)
> + return NULL;
> + if (atomic_add_unless(&vcpu->refcount, 1, 0))
Why do not use atomic_inc()?
Also, i think a memory barrier is needed after increasing refcount.
> - kvm->vcpus[atomic_read(&kvm->online_vcpus)] = vcpu;
> + /*Protected by kvm->lock*/
> + list_add_rcu(&vcpu->list, &kvm->vcpus);
> +
> smp_wmb();
This barrier can also be removed.
> atomic_inc(&kvm->online_vcpus);
>
> #ifdef CONFIG_KVM_APIC_ARCHITECTURE
> if (kvm->bsp_vcpu_id == id)
> - kvm->bsp_vcpu = vcpu;
> + kvm->bsp_vcpu = kvm_vcpu_get(vcpu);
> #endif
> mutex_unlock(&kvm->lock);
> return r;
> @@ -2593,13 +2667,15 @@ static int vcpu_stat_get(void *_offset, u64 *val)
> unsigned offset = (long)_offset;
> struct kvm *kvm;
> struct kvm_vcpu *vcpu;
> - int i;
>
> *val = 0;
> raw_spin_lock(&kvm_lock);
> - list_for_each_entry(kvm, &vm_list, vm_list)
> - kvm_for_each_vcpu(i, vcpu, kvm)
> + list_for_each_entry(kvm, &vm_list, vm_list) {
> + rcu_read_lock();
> + kvm_for_each_vcpu(vcpu, kvm)
> *val += *(u32 *)((void *)vcpu + offset);
> + rcu_read_unlock();
> + }
>
> raw_spin_unlock(&kvm_lock);
> return 0;
> @@ -2765,7 +2841,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
> kvm_preempt_ops.sched_out = kvm_sched_out;
>
> kvm_init_debug();
> -
You don not change anything, please do not touch this line.
next prev parent reply other threads:[~2011-12-15 5:33 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-25 2:35 [PATCH 0] A series patches for kvm&qemu to enable vcpu destruction in kvm Liu Ping Fan
2011-11-25 2:35 ` [PATCH 1/2] kvm: make vcpu life cycle separated from kvm instance Liu Ping Fan
2011-11-27 10:36 ` Avi Kivity
2011-12-02 6:26 ` [PATCH] " Liu Ping Fan
2011-12-02 18:26 ` Jan Kiszka
2011-12-04 11:53 ` Liu ping fan
2011-12-04 12:10 ` Gleb Natapov
2011-12-05 5:39 ` Liu ping fan
2011-12-05 8:41 ` Gleb Natapov
2011-12-06 6:54 ` Liu ping fan
2011-12-06 8:14 ` Gleb Natapov
2011-12-04 10:23 ` Avi Kivity
2011-12-05 5:29 ` Liu ping fan
2011-12-05 9:30 ` Avi Kivity
2011-12-05 9:42 ` Gleb Natapov
2011-12-05 9:58 ` Avi Kivity
2011-12-05 10:18 ` Gleb Natapov
2011-12-05 10:22 ` Avi Kivity
2011-12-05 10:40 ` Gleb Natapov
2011-12-09 5:23 ` [PATCH V2] " Liu Ping Fan
2011-12-09 14:23 ` Gleb Natapov
2011-12-12 2:41 ` [PATCH v3] " Liu Ping Fan
2011-12-12 12:54 ` Gleb Natapov
2011-12-13 9:29 ` Liu ping fan
2011-12-13 9:47 ` Gleb Natapov
2011-12-13 11:36 ` Marcelo Tosatti
2011-12-13 11:54 ` Gleb Natapov
2011-12-15 3:21 ` Liu ping fan
2011-12-15 4:28 ` [PATCH v4] " Liu Ping Fan
2011-12-15 5:33 ` Xiao Guangrong [this message]
2011-12-15 6:53 ` Liu ping fan
2011-12-15 8:25 ` Xiao Guangrong
2011-12-15 8:57 ` Xiao Guangrong
2011-12-15 6:48 ` Takuya Yoshikawa
2011-12-16 9:38 ` Marcelo Tosatti
2011-12-17 3:57 ` Liu ping fan
2011-12-19 1:16 ` Takuya Yoshikawa
2011-12-15 9:10 ` Gleb Natapov
2011-12-16 7:50 ` Liu ping fan
2011-12-15 8:33 ` [PATCH v3] " Gleb Natapov
2011-12-15 9:06 ` Liu ping fan
2011-12-15 9:08 ` Gleb Natapov
2011-12-17 3:19 ` [PATCH v5] " Liu Ping Fan
2011-12-26 11:09 ` Gleb Natapov
2011-12-26 11:17 ` Avi Kivity
2011-12-26 11:21 ` Gleb Natapov
2011-12-27 7:53 ` Liu ping fan
2011-12-27 8:38 ` [PATCH v6] " Liu Ping Fan
2011-12-27 11:22 ` Takuya Yoshikawa
2011-12-28 6:54 ` Liu ping fan
2011-12-28 9:53 ` Avi Kivity
2011-12-29 14:03 ` Liu ping fan
2011-12-29 14:31 ` Avi Kivity
2012-01-05 9:35 ` Liu ping fan
2011-12-28 10:29 ` Takuya Yoshikawa
2011-12-28 9:53 ` Avi Kivity
2011-12-28 9:54 ` Avi Kivity
2011-12-28 10:19 ` Takuya Yoshikawa
2011-12-28 10:28 ` Avi Kivity
2012-01-07 2:55 ` [PATCH v7] " Liu Ping Fan
2012-01-12 12:37 ` Avi Kivity
2012-01-15 13:17 ` Liu ping fan
2012-01-15 13:37 ` Avi Kivity
2011-11-25 17:54 ` [PATCH 0] A series patches for kvm&qemu to enable vcpu destruction in kvm Jan Kiszka
2011-11-27 3:07 ` Liu ping fan
2011-11-27 2:42 ` [PATCH 2/2] kvm: exit to userspace with reason KVM_EXIT_VCPU_DEAD Liu Ping Fan
2011-11-27 10:36 ` Avi Kivity
2011-11-27 10:50 ` Gleb Natapov
2011-11-28 7:16 ` [Qemu-devel] " Liu ping fan
2011-11-28 8:46 ` Gleb Natapov
2011-11-27 2:45 ` [PATCH 1/5] QEMU Add cpu_phyid_to_cpu() to map cpu phyid to CPUState Liu Ping Fan
2011-11-27 2:45 ` [PATCH 2/5] QEMU Add cpu_free() to support arch related CPUState release Liu Ping Fan
2011-11-27 2:45 ` [PATCH 3/5] QEMU Introduce a pci device "cpustate" to get CPU_DEAD event in guest Liu Ping Fan
2011-11-27 10:56 ` Gleb Natapov
2011-11-27 2:45 ` [PATCH 4/5] QEMU Release vcpu and finally exit vcpu thread safely Liu Ping Fan
2011-11-27 2:45 ` [PATCH 5/5] QEMU tmp patches for linux-header files Liu Ping Fan
2011-11-27 2:47 ` [PATCH] virtio: add a pci driver to notify host the CPU_DEAD event Liu Ping Fan
2011-11-27 11:10 ` Gleb Natapov
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=4EE9869F.4070702@linux.vnet.ibm.com \
--to=xiaoguangrong@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=avi@redhat.com \
--cc=gleb@redhat.com \
--cc=jan.kiszka@web.de \
--cc=kernelfans@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).