diff options
author | Christian Borntraeger <borntraeger@de.ibm.com> | 2014-08-05 10:44:14 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2014-12-04 09:29:13 -0500 |
commit | 7a72f7a140bfd3a5dae73088947010bfdbcf6a40 (patch) | |
tree | bb6f945f4460a39e7d0e6b242ecf656508891c27 /virt/kvm/kvm_main.c | |
parent | eed6e79d7362335967def243cc891179a9c59892 (diff) |
KVM: track pid for VCPU only on KVM_RUN ioctl
We currently track the pid of the task that runs the VCPU in vcpu_load.
If a yield to that VCPU is triggered while the PID of the wrong thread
is active, the wrong thread might receive a yield, but this will most
likely not help the executing thread at all. Instead, if we only track
the pid on the KVM_RUN ioctl, there are two possibilities:
1) the thread that did a non-KVM_RUN ioctl is holding a mutex that
the VCPU thread is waiting for. In this case, the VCPU thread is not
runnable, but we also do not do a wrong yield.
2) the thread that did a non-KVM_RUN ioctl is sleeping, or doing
something that does not block the VCPU thread. In this case, the
VCPU thread can receive the directed yield correctly.
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
CC: Rik van Riel <riel@redhat.com>
CC: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
CC: Michael Mueller <mimu@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'virt/kvm/kvm_main.c')
-rw-r--r-- | virt/kvm/kvm_main.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 2ffee3018a3d..c5c186af823b 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -124,15 +124,6 @@ int vcpu_load(struct kvm_vcpu *vcpu) | |||
124 | 124 | ||
125 | if (mutex_lock_killable(&vcpu->mutex)) | 125 | if (mutex_lock_killable(&vcpu->mutex)) |
126 | return -EINTR; | 126 | return -EINTR; |
127 | if (unlikely(vcpu->pid != current->pids[PIDTYPE_PID].pid)) { | ||
128 | /* The thread running this VCPU changed. */ | ||
129 | struct pid *oldpid = vcpu->pid; | ||
130 | struct pid *newpid = get_task_pid(current, PIDTYPE_PID); | ||
131 | rcu_assign_pointer(vcpu->pid, newpid); | ||
132 | if (oldpid) | ||
133 | synchronize_rcu(); | ||
134 | put_pid(oldpid); | ||
135 | } | ||
136 | cpu = get_cpu(); | 127 | cpu = get_cpu(); |
137 | preempt_notifier_register(&vcpu->preempt_notifier); | 128 | preempt_notifier_register(&vcpu->preempt_notifier); |
138 | kvm_arch_vcpu_load(vcpu, cpu); | 129 | kvm_arch_vcpu_load(vcpu, cpu); |
@@ -2050,6 +2041,15 @@ static long kvm_vcpu_ioctl(struct file *filp, | |||
2050 | r = -EINVAL; | 2041 | r = -EINVAL; |
2051 | if (arg) | 2042 | if (arg) |
2052 | goto out; | 2043 | goto out; |
2044 | if (unlikely(vcpu->pid != current->pids[PIDTYPE_PID].pid)) { | ||
2045 | /* The thread running this VCPU changed. */ | ||
2046 | struct pid *oldpid = vcpu->pid; | ||
2047 | struct pid *newpid = get_task_pid(current, PIDTYPE_PID); | ||
2048 | rcu_assign_pointer(vcpu->pid, newpid); | ||
2049 | if (oldpid) | ||
2050 | synchronize_rcu(); | ||
2051 | put_pid(oldpid); | ||
2052 | } | ||
2053 | r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); | 2053 | r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); |
2054 | trace_kvm_userspace_exit(vcpu->run->exit_reason, r); | 2054 | trace_kvm_userspace_exit(vcpu->run->exit_reason, r); |
2055 | break; | 2055 | break; |