KVM: Extract core of kvm_flush_remote_tlbs/kvm_reload_remote_mmus
Avi said: > Wow, code duplication from Rusty. Things must be bad. Something about glass houses comes to mind. But instead, a patch. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Avi Kivity <avi@redhat.com>
This commit is contained in:
parent
3d3aab1b97
commit
498468961e
@ -552,10 +552,11 @@ static void ack_flush(void *_completed)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvm_flush_remote_tlbs(struct kvm *kvm)
|
static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
|
||||||
{
|
{
|
||||||
int i, cpu, me;
|
int i, cpu, me;
|
||||||
cpumask_t cpus;
|
cpumask_t cpus;
|
||||||
|
bool called = false;
|
||||||
struct kvm_vcpu *vcpu;
|
struct kvm_vcpu *vcpu;
|
||||||
|
|
||||||
me = get_cpu();
|
me = get_cpu();
|
||||||
@ -564,46 +565,31 @@ void kvm_flush_remote_tlbs(struct kvm *kvm)
|
|||||||
vcpu = kvm->vcpus[i];
|
vcpu = kvm->vcpus[i];
|
||||||
if (!vcpu)
|
if (!vcpu)
|
||||||
continue;
|
continue;
|
||||||
if (test_and_set_bit(KVM_REQ_TLB_FLUSH, &vcpu->requests))
|
if (test_and_set_bit(req, &vcpu->requests))
|
||||||
continue;
|
continue;
|
||||||
cpu = vcpu->cpu;
|
cpu = vcpu->cpu;
|
||||||
if (cpu != -1 && cpu != me)
|
if (cpu != -1 && cpu != me)
|
||||||
cpu_set(cpu, cpus);
|
cpu_set(cpu, cpus);
|
||||||
}
|
}
|
||||||
if (cpus_empty(cpus))
|
if (!cpus_empty(cpus)) {
|
||||||
goto out;
|
smp_call_function_mask(cpus, ack_flush, NULL, 1);
|
||||||
++kvm->stat.remote_tlb_flush;
|
called = true;
|
||||||
smp_call_function_mask(cpus, ack_flush, NULL, 1);
|
}
|
||||||
out:
|
|
||||||
put_cpu();
|
put_cpu();
|
||||||
|
return called;
|
||||||
|
}
|
||||||
|
|
||||||
|
void kvm_flush_remote_tlbs(struct kvm *kvm)
|
||||||
|
{
|
||||||
|
if (make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH))
|
||||||
|
++kvm->stat.remote_tlb_flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvm_reload_remote_mmus(struct kvm *kvm)
|
void kvm_reload_remote_mmus(struct kvm *kvm)
|
||||||
{
|
{
|
||||||
int i, cpu, me;
|
make_all_cpus_request(kvm, KVM_REQ_MMU_RELOAD);
|
||||||
cpumask_t cpus;
|
|
||||||
struct kvm_vcpu *vcpu;
|
|
||||||
|
|
||||||
me = get_cpu();
|
|
||||||
cpus_clear(cpus);
|
|
||||||
for (i = 0; i < KVM_MAX_VCPUS; ++i) {
|
|
||||||
vcpu = kvm->vcpus[i];
|
|
||||||
if (!vcpu)
|
|
||||||
continue;
|
|
||||||
if (test_and_set_bit(KVM_REQ_MMU_RELOAD, &vcpu->requests))
|
|
||||||
continue;
|
|
||||||
cpu = vcpu->cpu;
|
|
||||||
if (cpu != -1 && cpu != me)
|
|
||||||
cpu_set(cpu, cpus);
|
|
||||||
}
|
|
||||||
if (cpus_empty(cpus))
|
|
||||||
goto out;
|
|
||||||
smp_call_function_mask(cpus, ack_flush, NULL, 1);
|
|
||||||
out:
|
|
||||||
put_cpu();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id)
|
int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id)
|
||||||
{
|
{
|
||||||
struct page *page;
|
struct page *page;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user