Re: [RFC -v4 PATCH 3/3] kvm: use yield_to instead of sleep in kvm_vcpu_on_spin
From: Avi Kivity
Date: Thu Jan 13 2011 - 08:17:25 EST
On 01/13/2011 07:27 AM, Rik van Riel wrote:
Instead of sleeping in kvm_vcpu_on_spin, which can cause gigantic
slowdowns of certain workloads, we instead use yield_to to hand
the rest of our timeslice to another vcpu in the same KVM guest.
+ for (pass = 0; pass< 2&& !yielded; pass++) {
+ kvm_for_each_vcpu(i, vcpu, kvm) {
+ struct task_struct *task = vcpu->task;
+ if (!pass&& i< last_boosted_vcpu) {
+ i = last_boosted_vcpu;
+ continue;
+ } else if (pass&& i> last_boosted_vcpu)
+ break;
+ if (vcpu == me)
+ continue;
+ if (!task)
+ continue;
+ if (waitqueue_active(&vcpu->wq))
+ continue;
Suppose the vcpu exits at this point, and its task terminates.
+ if (task->flags& PF_VCPU)
+ continue;
Here you dereference freed memory.
+ kvm->last_boosted_vcpu = i;
+ yielded = 1;
+ yield_to(task, 1);
And here you do unimaginable things to that freed memory.
I think the first patch needs some reference counting... I'd move it to
the outermost KVM_RUN loop to reduce the performance impact.
+ break;
+ }
+ }
}
EXPORT_SYMBOL_GPL(kvm_vcpu_on_spin);
--
error compiling committee.c: too many arguments to function
--
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/