Re: [PATCH] KVM: avoid unnecessary synchronize_rcu

Christian Borntraeger
2014-08-25T08:24:52Z

On 19/08/14 16:45, Christian Borntraeger wrote:
> We dont have to wait for a grace period if there is no oldpid that
> we are going to free. putpid also checks for NULL, so this patch
> only fences synchronize_rcu.
>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
> virt/kvm/kvm_main.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 33712fb..39b1603 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -129,7 +129,8 @@ int vcpu_load(struct kvm_vcpu *vcpu)
> struct pid *oldpid = vcpu->pid;
> struct pid *newpid = get_task_pid(current, PIDTYPE_PID);
> rcu_assign_pointer(vcpu->pid, newpid);
> - synchronize_rcu();
> + if (oldpid)
> + synchronize_rcu();
> put_pid(oldpid);
> }
> cpu = get_cpu();
>

Ping.
That variant should be enough for us for future QEMUs. David has prepared some patches in QEMU that makes the other problems go away (mostly) which are currently under internal review/test.
Let me know if you want to have the put_pid inside the if as well (or feel free to fix up yourself code and patch description).

Thanks

Christian