Skip to content

Commit

Permalink
KVM: Pass kvm_init()'s opaque param to additional arch funcs
Browse files Browse the repository at this point in the history
Pass @opaque to kvm_arch_hardware_setup() and
kvm_arch_check_processor_compat() to allow architecture specific code to
reference @opaque without having to stash it away in a temporary global
variable.  This will enable x86 to separate its vendor specific callback
ops, which are passed via @opaque, into "init" and "runtime" ops without
having to stash away the "init" ops.

No functional change intended.

Reviewed-by: Cornelia Huck <[email protected]>
Tested-by: Cornelia Huck <[email protected]> #s390
Acked-by: Marc Zyngier <[email protected]>
Signed-off-by: Sean Christopherson <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Vitaly Kuznetsov <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
Sean Christopherson authored and bonzini committed Mar 31, 2020
1 parent 4f4af84 commit b990408
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions arch/mips/kvm/mips.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ void kvm_arch_hardware_disable(void)
kvm_mips_callbacks->hardware_disable();
}

int kvm_arch_hardware_setup(void)
int kvm_arch_hardware_setup(void *opaque)
{
return 0;
}

int kvm_arch_check_processor_compat(void)
int kvm_arch_check_processor_compat(void *opaque)
{
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/kvm/powerpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,12 @@ int kvm_arch_hardware_enable(void)
return 0;
}

int kvm_arch_hardware_setup(void)
int kvm_arch_hardware_setup(void *opaque)
{
return 0;
}

int kvm_arch_check_processor_compat(void)
int kvm_arch_check_processor_compat(void *opaque)
{
return kvmppc_core_check_processor_compat();
}
Expand Down
4 changes: 2 additions & 2 deletions arch/s390/kvm/kvm-s390.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ int kvm_arch_hardware_enable(void)
return 0;
}

int kvm_arch_check_processor_compat(void)
int kvm_arch_check_processor_compat(void *opaque)
{
return 0;
}
Expand Down Expand Up @@ -302,7 +302,7 @@ static struct notifier_block kvm_clock_notifier = {
.notifier_call = kvm_clock_sync,
};

int kvm_arch_hardware_setup(void)
int kvm_arch_hardware_setup(void *opaque)
{
gmap_notifier.notifier_call = kvm_gmap_notifier;
gmap_register_pte_notifier(&gmap_notifier);
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -9626,7 +9626,7 @@ void kvm_arch_hardware_disable(void)
drop_user_return_notifiers();
}

int kvm_arch_hardware_setup(void)
int kvm_arch_hardware_setup(void *opaque)
{
int r;

Expand Down Expand Up @@ -9667,7 +9667,7 @@ void kvm_arch_hardware_unsetup(void)
kvm_x86_ops->hardware_unsetup();
}

int kvm_arch_check_processor_compat(void)
int kvm_arch_check_processor_compat(void *opaque)
{
struct cpuinfo_x86 *c = &cpu_data(smp_processor_id());

Expand Down
4 changes: 2 additions & 2 deletions include/linux/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,9 @@ void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu);

int kvm_arch_hardware_enable(void);
void kvm_arch_hardware_disable(void);
int kvm_arch_hardware_setup(void);
int kvm_arch_hardware_setup(void *opaque);
void kvm_arch_hardware_unsetup(void);
int kvm_arch_check_processor_compat(void);
int kvm_arch_check_processor_compat(void *opaque);
int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu);
int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu);
Expand Down
4 changes: 2 additions & 2 deletions virt/kvm/arm/arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE;
}

int kvm_arch_hardware_setup(void)
int kvm_arch_hardware_setup(void *opaque)
{
return 0;
}

int kvm_arch_check_processor_compat(void)
int kvm_arch_check_processor_compat(void *opaque)
{
return 0;
}
Expand Down
18 changes: 14 additions & 4 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4648,14 +4648,22 @@ struct kvm_vcpu * __percpu *kvm_get_running_vcpus(void)
return &kvm_running_vcpu;
}

static void check_processor_compat(void *rtn)
struct kvm_cpu_compat_check {
void *opaque;
int *ret;
};

static void check_processor_compat(void *data)
{
*(int *)rtn = kvm_arch_check_processor_compat();
struct kvm_cpu_compat_check *c = data;

*c->ret = kvm_arch_check_processor_compat(c->opaque);
}

int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
struct module *module)
{
struct kvm_cpu_compat_check c;
int r;
int cpu;

Expand All @@ -4679,12 +4687,14 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
goto out_free_0;
}

r = kvm_arch_hardware_setup();
r = kvm_arch_hardware_setup(opaque);
if (r < 0)
goto out_free_1;

c.ret = &r;
c.opaque = opaque;
for_each_online_cpu(cpu) {
smp_call_function_single(cpu, check_processor_compat, &r, 1);
smp_call_function_single(cpu, check_processor_compat, &c, 1);
if (r < 0)
goto out_free_2;
}
Expand Down

0 comments on commit b990408

Please sign in to comment.