Skip to content

Commit ff030fd

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: PPC: Move kvm_vcpu_init() invocation to common code
Move the kvm_cpu_{un}init() calls to common PPC code as an intermediate step towards removing kvm_cpu_{un}init() altogether. No functional change intended. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 4dbf6fe commit ff030fd

File tree

8 files changed

+29
-55
lines changed

8 files changed

+29
-55
lines changed

arch/powerpc/include/asm/kvm_ppc.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ extern int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr,
119119
enum xlate_instdata xlid, enum xlate_readwrite xlrw,
120120
struct kvmppc_pte *pte);
121121

122-
extern int kvmppc_core_vcpu_create(struct kvm *kvm, struct kvm_vcpu *vcpu,
123-
unsigned int id);
122+
extern int kvmppc_core_vcpu_create(struct kvm_vcpu *vcpu);
124123
extern void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu);
125124
extern int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu);
126125
extern int kvmppc_core_check_processor_compat(void);
@@ -274,8 +273,7 @@ struct kvmppc_ops {
274273
void (*inject_interrupt)(struct kvm_vcpu *vcpu, int vec, u64 srr1_flags);
275274
void (*set_msr)(struct kvm_vcpu *vcpu, u64 msr);
276275
int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu);
277-
int (*vcpu_create)(struct kvm *kvm, struct kvm_vcpu *vcpu,
278-
unsigned int id);
276+
int (*vcpu_create)(struct kvm_vcpu *vcpu);
279277
void (*vcpu_free)(struct kvm_vcpu *vcpu);
280278
int (*check_requests)(struct kvm_vcpu *vcpu);
281279
int (*get_dirty_log)(struct kvm *kvm, struct kvm_dirty_log *log);

arch/powerpc/kvm/book3s.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,9 @@ void kvmppc_decrementer_func(struct kvm_vcpu *vcpu)
789789
kvm_vcpu_kick(vcpu);
790790
}
791791

792-
int kvmppc_core_vcpu_create(struct kvm *kvm, struct kvm_vcpu *vcpu,
793-
unsigned int id)
792+
int kvmppc_core_vcpu_create(struct kvm_vcpu *vcpu)
794793
{
795-
return kvm->arch.kvm_ops->vcpu_create(kvm, vcpu, id);
794+
return vcpu->kvm->arch.kvm_ops->vcpu_create(vcpu);
796795
}
797796

798797
void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)

arch/powerpc/kvm/book3s_hv.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,16 +2271,16 @@ static void debugfs_vcpu_init(struct kvm_vcpu *vcpu, unsigned int id)
22712271
}
22722272
#endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
22732273

2274-
static int kvmppc_core_vcpu_create_hv(struct kvm *kvm, struct kvm_vcpu *vcpu,
2275-
unsigned int id)
2274+
static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu)
22762275
{
22772276
int err;
22782277
int core;
22792278
struct kvmppc_vcore *vcore;
2279+
struct kvm *kvm;
2280+
unsigned int id;
22802281

2281-
err = kvm_vcpu_init(vcpu, kvm, id);
2282-
if (err)
2283-
return err;
2282+
kvm = vcpu->kvm;
2283+
id = vcpu->vcpu_id;
22842284

22852285
vcpu->arch.shared = &vcpu->arch.shregs;
22862286
#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
@@ -2362,7 +2362,7 @@ static int kvmppc_core_vcpu_create_hv(struct kvm *kvm, struct kvm_vcpu *vcpu,
23622362
mutex_unlock(&kvm->lock);
23632363

23642364
if (!vcore)
2365-
goto uninit_vcpu;
2365+
return err;
23662366

23672367
spin_lock(&vcore->lock);
23682368
++vcore->num_threads;
@@ -2378,10 +2378,6 @@ static int kvmppc_core_vcpu_create_hv(struct kvm *kvm, struct kvm_vcpu *vcpu,
23782378
debugfs_vcpu_init(vcpu, id);
23792379

23802380
return 0;
2381-
2382-
uninit_vcpu:
2383-
kvm_vcpu_uninit(vcpu);
2384-
return err;
23852381
}
23862382

23872383
static int kvmhv_set_smt_mode(struct kvm *kvm, unsigned long smt_mode,
@@ -2435,7 +2431,6 @@ static void kvmppc_core_vcpu_free_hv(struct kvm_vcpu *vcpu)
24352431
unpin_vpa(vcpu->kvm, &vcpu->arch.slb_shadow);
24362432
unpin_vpa(vcpu->kvm, &vcpu->arch.vpa);
24372433
spin_unlock(&vcpu->arch.vpa_update_lock);
2438-
kvm_vcpu_uninit(vcpu);
24392434
}
24402435

24412436
static int kvmppc_core_check_requests_hv(struct kvm_vcpu *vcpu)

arch/powerpc/kvm/book3s_pr.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,22 +1744,17 @@ static int kvmppc_set_one_reg_pr(struct kvm_vcpu *vcpu, u64 id,
17441744
return r;
17451745
}
17461746

1747-
static int kvmppc_core_vcpu_create_pr(struct kvm *kvm, struct kvm_vcpu *vcpu,
1748-
unsigned int id)
1747+
static int kvmppc_core_vcpu_create_pr(struct kvm_vcpu *vcpu)
17491748
{
17501749
struct kvmppc_vcpu_book3s *vcpu_book3s;
17511750
unsigned long p;
17521751
int err;
17531752

1754-
err = kvm_vcpu_init(vcpu, kvm, id);
1755-
if (err)
1756-
return err;
1757-
17581753
err = -ENOMEM;
17591754

17601755
vcpu_book3s = vzalloc(sizeof(struct kvmppc_vcpu_book3s));
17611756
if (!vcpu_book3s)
1762-
goto uninit_vcpu;
1757+
goto out;
17631758
vcpu->arch.book3s = vcpu_book3s;
17641759

17651760
#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
@@ -1814,8 +1809,7 @@ static int kvmppc_core_vcpu_create_pr(struct kvm *kvm, struct kvm_vcpu *vcpu,
18141809
free_vcpu3s:
18151810
#endif
18161811
vfree(vcpu_book3s);
1817-
uninit_vcpu:
1818-
kvm_vcpu_uninit(vcpu);
1812+
out:
18191813
return err;
18201814
}
18211815

@@ -1824,7 +1818,6 @@ static void kvmppc_core_vcpu_free_pr(struct kvm_vcpu *vcpu)
18241818
struct kvmppc_vcpu_book3s *vcpu_book3s = to_book3s(vcpu);
18251819

18261820
free_page((unsigned long)vcpu->arch.shared & PAGE_MASK);
1827-
kvm_vcpu_uninit(vcpu);
18281821
#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
18291822
kfree(vcpu->arch.shadow_vcpu);
18301823
#endif

arch/powerpc/kvm/booke.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,10 +2114,9 @@ int kvmppc_core_init_vm(struct kvm *kvm)
21142114
return kvm->arch.kvm_ops->init_vm(kvm);
21152115
}
21162116

2117-
int kvmppc_core_vcpu_create(struct kvm *kvm, struct kvm_vcpu *vcpu,
2118-
unsigned int id)
2117+
int kvmppc_core_vcpu_create(struct kvm_vcpu *vcpu)
21192118
{
2120-
return kvm->arch.kvm_ops->vcpu_create(kvm, vcpu, id);
2119+
return vcpu->kvm->arch.kvm_ops->vcpu_create(vcpu);
21212120
}
21222121

21232122
void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)

arch/powerpc/kvm/e500.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -433,23 +433,16 @@ static int kvmppc_set_one_reg_e500(struct kvm_vcpu *vcpu, u64 id,
433433
return r;
434434
}
435435

436-
static int kvmppc_core_vcpu_create_e500(struct kvm *kvm, struct kvm_vcpu *vcpu,
437-
unsigned int id)
436+
static int kvmppc_core_vcpu_create_e500(struct kvm_vcpu *vcpu)
438437
{
439438
struct kvmppc_vcpu_e500 *vcpu_e500;
440439
int err;
441440

442441
BUILD_BUG_ON(offsetof(struct kvmppc_vcpu_e500, vcpu) != 0);
443442
vcpu_e500 = to_e500(vcpu);
444443

445-
err = kvm_vcpu_init(vcpu, kvm, id);
446-
if (err)
447-
return err;
448-
449-
if (kvmppc_e500_id_table_alloc(vcpu_e500) == NULL) {
450-
err = -ENOMEM;
451-
goto uninit_vcpu;
452-
}
444+
if (kvmppc_e500_id_table_alloc(vcpu_e500) == NULL)
445+
return -ENOMEM;
453446

454447
err = kvmppc_e500_tlb_init(vcpu_e500);
455448
if (err)
@@ -467,8 +460,6 @@ static int kvmppc_core_vcpu_create_e500(struct kvm *kvm, struct kvm_vcpu *vcpu,
467460
kvmppc_e500_tlb_uninit(vcpu_e500);
468461
uninit_id:
469462
kvmppc_e500_id_table_free(vcpu_e500);
470-
uninit_vcpu:
471-
kvm_vcpu_uninit(vcpu);
472463
return err;
473464
}
474465

@@ -479,7 +470,6 @@ static void kvmppc_core_vcpu_free_e500(struct kvm_vcpu *vcpu)
479470
free_page((unsigned long)vcpu->arch.shared);
480471
kvmppc_e500_tlb_uninit(vcpu_e500);
481472
kvmppc_e500_id_table_free(vcpu_e500);
482-
kvm_vcpu_uninit(vcpu);
483473
}
484474

485475
static int kvmppc_core_init_vm_e500(struct kvm *kvm)

arch/powerpc/kvm/e500mc.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,25 +301,20 @@ static int kvmppc_set_one_reg_e500mc(struct kvm_vcpu *vcpu, u64 id,
301301
return r;
302302
}
303303

304-
static int kvmppc_core_vcpu_create_e500mc(struct kvm *kvm, struct kvm_vcpu *vcpu,
305-
unsigned int id)
304+
static int kvmppc_core_vcpu_create_e500mc(struct kvm_vcpu *vcpu)
306305
{
307306
struct kvmppc_vcpu_e500 *vcpu_e500;
308307
int err;
309308

310309
BUILD_BUG_ON(offsetof(struct kvmppc_vcpu_e500, vcpu) != 0);
311310
vcpu_e500 = to_e500(vcpu);
312311

313-
err = kvm_vcpu_init(vcpu, kvm, id);
314-
if (err)
315-
return err;
316-
317312
/* Invalid PIR value -- this LPID dosn't have valid state on any cpu */
318313
vcpu->arch.oldpir = 0xffffffff;
319314

320315
err = kvmppc_e500_tlb_init(vcpu_e500);
321316
if (err)
322-
goto uninit_vcpu;
317+
return err;
323318

324319
vcpu->arch.shared = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
325320
if (!vcpu->arch.shared) {
@@ -331,8 +326,6 @@ static int kvmppc_core_vcpu_create_e500mc(struct kvm *kvm, struct kvm_vcpu *vcpu
331326

332327
uninit_tlb:
333328
kvmppc_e500_tlb_uninit(vcpu_e500);
334-
uninit_vcpu:
335-
kvm_vcpu_uninit(vcpu);
336329
return err;
337330
}
338331

@@ -342,7 +335,6 @@ static void kvmppc_core_vcpu_free_e500mc(struct kvm_vcpu *vcpu)
342335

343336
free_page((unsigned long)vcpu->arch.shared);
344337
kvmppc_e500_tlb_uninit(vcpu_e500);
345-
kvm_vcpu_uninit(vcpu);
346338
}
347339

348340
static int kvmppc_core_init_vm_e500mc(struct kvm *kvm)

arch/powerpc/kvm/powerpc.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,14 +729,20 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
729729
if (!vcpu)
730730
return ERR_PTR(-ENOMEM);
731731

732-
err = kvmppc_core_vcpu_create(kvm, vcpu, id);
732+
err = kvm_vcpu_init(vcpu, kvm, id);
733733
if (err)
734734
goto free_vcpu;
735735

736+
err = kvmppc_core_vcpu_create(vcpu);
737+
if (err)
738+
goto uninit_vcpu;
739+
736740
vcpu->arch.wqp = &vcpu->wq;
737741
kvmppc_create_vcpu_debugfs(vcpu, id);
738742
return vcpu;
739743

744+
uninit_vcpu:
745+
kvm_vcpu_uninit(vcpu);
740746
free_vcpu:
741747
kmem_cache_free(kvm_vcpu_cache, vcpu);
742748
return ERR_PTR(err);
@@ -770,6 +776,8 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
770776

771777
kvmppc_core_vcpu_free(vcpu);
772778

779+
kvm_vcpu_uninit(vcpu);
780+
773781
kmem_cache_free(kvm_vcpu_cache, vcpu);
774782
}
775783

0 commit comments

Comments
 (0)