Skip to content

Commit

Permalink
KVM: PPC: Clean up redundant kvm_run parameters in assembly
Browse files Browse the repository at this point in the history
In the current kvm version, 'kvm_run' has been included in the 'kvm_vcpu'
structure. For historical reasons, many kvm-related function parameters
retain the 'kvm_run' and 'kvm_vcpu' parameters at the same time. This
patch does a unified cleanup of these remaining redundant parameters.

[[email protected] - Fixed places that were missed in book3s_interrupts.S]

Signed-off-by: Tianjia Zhang <[email protected]>
Signed-off-by: Paul Mackerras <[email protected]>
  • Loading branch information
uudiin authored and paulusmack committed Jul 23, 2020
1 parent 1508c22 commit 7ec21d9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 50 deletions.
2 changes: 1 addition & 1 deletion arch/powerpc/include/asm/kvm_ppc.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ enum xlate_readwrite {
};

extern int kvmppc_vcpu_run(struct kvm_vcpu *vcpu);
extern int __kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu);
extern int __kvmppc_vcpu_run(struct kvm_vcpu *vcpu);
extern void kvmppc_handler_highmem(void);

extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu);
Expand Down
56 changes: 27 additions & 29 deletions arch/powerpc/kvm/book3s_interrupts.S
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
****************************************************************************/

/* Registers:
* r3: kvm_run pointer
* r4: vcpu pointer
* r3: vcpu pointer
*/
_GLOBAL(__kvmppc_vcpu_run)

Expand All @@ -68,8 +67,8 @@ kvm_start_entry:
/* Save host state to the stack */
PPC_STLU r1, -SWITCH_FRAME_SIZE(r1)

/* Save r3 (kvm_run) and r4 (vcpu) */
SAVE_2GPRS(3, r1)
/* Save r3 (vcpu) */
SAVE_GPR(3, r1)

/* Save non-volatile registers (r14 - r31) */
SAVE_NVGPRS(r1)
Expand All @@ -82,47 +81,46 @@ kvm_start_entry:
PPC_STL r0, _LINK(r1)

/* Load non-volatile guest state from the vcpu */
VCPU_LOAD_NVGPRS(r4)
VCPU_LOAD_NVGPRS(r3)

kvm_start_lightweight:
/* Copy registers into shadow vcpu so we can access them in real mode */
mr r3, r4
bl FUNC(kvmppc_copy_to_svcpu)
nop
REST_GPR(4, r1)
REST_GPR(3, r1)

#ifdef CONFIG_PPC_BOOK3S_64
/* Get the dcbz32 flag */
PPC_LL r3, VCPU_HFLAGS(r4)
rldicl r3, r3, 0, 63 /* r3 &= 1 */
stb r3, HSTATE_RESTORE_HID5(r13)
PPC_LL r0, VCPU_HFLAGS(r3)
rldicl r0, r0, 0, 63 /* r3 &= 1 */
stb r0, HSTATE_RESTORE_HID5(r13)

/* Load up guest SPRG3 value, since it's user readable */
lwz r3, VCPU_SHAREDBE(r4)
cmpwi r3, 0
ld r5, VCPU_SHARED(r4)
lbz r4, VCPU_SHAREDBE(r3)
cmpwi r4, 0
ld r5, VCPU_SHARED(r3)
beq sprg3_little_endian
sprg3_big_endian:
#ifdef __BIG_ENDIAN__
ld r3, VCPU_SHARED_SPRG3(r5)
ld r4, VCPU_SHARED_SPRG3(r5)
#else
addi r5, r5, VCPU_SHARED_SPRG3
ldbrx r3, 0, r5
ldbrx r4, 0, r5
#endif
b after_sprg3_load
sprg3_little_endian:
#ifdef __LITTLE_ENDIAN__
ld r3, VCPU_SHARED_SPRG3(r5)
ld r4, VCPU_SHARED_SPRG3(r5)
#else
addi r5, r5, VCPU_SHARED_SPRG3
ldbrx r3, 0, r5
ldbrx r4, 0, r5
#endif

after_sprg3_load:
mtspr SPRN_SPRG3, r3
mtspr SPRN_SPRG3, r4
#endif /* CONFIG_PPC_BOOK3S_64 */

PPC_LL r4, VCPU_SHADOW_MSR(r4) /* get shadow_msr */
PPC_LL r4, VCPU_SHADOW_MSR(r3) /* get shadow_msr */

/* Jump to segment patching handler and into our guest */
bl FUNC(kvmppc_entry_trampoline)
Expand All @@ -146,7 +144,7 @@ after_sprg3_load:
*
*/

PPC_LL r3, GPR4(r1) /* vcpu pointer */
PPC_LL r3, GPR3(r1) /* vcpu pointer */

/*
* kvmppc_copy_from_svcpu can clobber volatile registers, save
Expand All @@ -169,7 +167,7 @@ after_sprg3_load:
#endif /* CONFIG_PPC_BOOK3S_64 */

/* R7 = vcpu */
PPC_LL r7, GPR4(r1)
PPC_LL r7, GPR3(r1)

PPC_STL r14, VCPU_GPR(R14)(r7)
PPC_STL r15, VCPU_GPR(R15)(r7)
Expand All @@ -190,11 +188,11 @@ after_sprg3_load:
PPC_STL r30, VCPU_GPR(R30)(r7)
PPC_STL r31, VCPU_GPR(R31)(r7)

/* Pass the exit number as 3rd argument to kvmppc_handle_exit */
lwz r5, VCPU_TRAP(r7)
/* Pass the exit number as 2nd argument to kvmppc_handle_exit */
lwz r4, VCPU_TRAP(r7)

/* Restore r3 (kvm_run) and r4 (vcpu) */
REST_2GPRS(3, r1)
/* Restore r3 (vcpu) */
REST_GPR(3, r1)
bl FUNC(kvmppc_handle_exit_pr)

/* If RESUME_GUEST, get back in the loop */
Expand Down Expand Up @@ -223,19 +221,19 @@ kvm_loop_heavyweight:
PPC_LL r4, _LINK(r1)
PPC_STL r4, (PPC_LR_STKOFF + SWITCH_FRAME_SIZE)(r1)

/* Load vcpu and cpu_run */
REST_2GPRS(3, r1)
/* Load vcpu */
REST_GPR(3, r1)

/* Load non-volatile guest state from the vcpu */
VCPU_LOAD_NVGPRS(r4)
VCPU_LOAD_NVGPRS(r3)

/* Jump back into the beginning of this function */
b kvm_start_lightweight

kvm_loop_lightweight:

/* We'll need the vcpu pointer */
REST_GPR(4, r1)
REST_GPR(3, r1)

/* Jump back into the beginning of this function */
b kvm_start_lightweight
9 changes: 4 additions & 5 deletions arch/powerpc/kvm/book3s_pr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,9 +1151,9 @@ static int kvmppc_exit_pr_progint(struct kvm_vcpu *vcpu, unsigned int exit_nr)
return r;
}

int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
unsigned int exit_nr)
int kvmppc_handle_exit_pr(struct kvm_vcpu *vcpu, unsigned int exit_nr)
{
struct kvm_run *run = vcpu->run;
int r = RESUME_HOST;
int s;

Expand Down Expand Up @@ -1826,15 +1826,14 @@ static void kvmppc_core_vcpu_free_pr(struct kvm_vcpu *vcpu)

static int kvmppc_vcpu_run_pr(struct kvm_vcpu *vcpu)
{
struct kvm_run *run = vcpu->run;
int ret;
#ifdef CONFIG_ALTIVEC
unsigned long uninitialized_var(vrsave);
#endif

/* Check if we can run the vcpu at all */
if (!vcpu->arch.sane) {
run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
ret = -EINVAL;
goto out;
}
Expand All @@ -1861,7 +1860,7 @@ static int kvmppc_vcpu_run_pr(struct kvm_vcpu *vcpu)

kvmppc_fix_ee_before_entry();

ret = __kvmppc_vcpu_run(run, vcpu);
ret = __kvmppc_vcpu_run(vcpu);

kvmppc_clear_debug(vcpu);

Expand Down
9 changes: 4 additions & 5 deletions arch/powerpc/kvm/booke.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,12 +731,11 @@ int kvmppc_core_check_requests(struct kvm_vcpu *vcpu)

int kvmppc_vcpu_run(struct kvm_vcpu *vcpu)
{
struct kvm_run *run = vcpu->run;
int ret, s;
struct debug_reg debug;

if (!vcpu->arch.sane) {
run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
return -EINVAL;
}

Expand Down Expand Up @@ -778,7 +777,7 @@ int kvmppc_vcpu_run(struct kvm_vcpu *vcpu)
vcpu->arch.pgdir = vcpu->kvm->mm->pgd;
kvmppc_fix_ee_before_entry();

ret = __kvmppc_vcpu_run(run, vcpu);
ret = __kvmppc_vcpu_run(vcpu);

/* No need for guest_exit. It's done in handle_exit.
We also get here with interrupts enabled. */
Expand Down Expand Up @@ -982,9 +981,9 @@ static int kvmppc_resume_inst_load(struct kvm_vcpu *vcpu,
*
* Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
*/
int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
unsigned int exit_nr)
int kvmppc_handle_exit(struct kvm_vcpu *vcpu, unsigned int exit_nr)
{
struct kvm_run *run = vcpu->run;
int r = RESUME_HOST;
int s;
int idx;
Expand Down
9 changes: 4 additions & 5 deletions arch/powerpc/kvm/booke_interrupts.S
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ _GLOBAL(kvmppc_resume_host)
/* Switch to kernel stack and jump to handler. */
LOAD_REG_ADDR(r3, kvmppc_handle_exit)
mtctr r3
lwz r3, HOST_RUN(r1)
mr r3, r4
lwz r2, HOST_R2(r1)
mr r14, r4 /* Save vcpu pointer. */

Expand Down Expand Up @@ -337,15 +337,14 @@ heavyweight_exit:


/* Registers:
* r3: kvm_run pointer
* r4: vcpu pointer
* r3: vcpu pointer
*/
_GLOBAL(__kvmppc_vcpu_run)
stwu r1, -HOST_STACK_SIZE(r1)
stw r1, VCPU_HOST_STACK(r4) /* Save stack pointer to vcpu. */
stw r1, VCPU_HOST_STACK(r3) /* Save stack pointer to vcpu. */

/* Save host state to stack. */
stw r3, HOST_RUN(r1)
mr r4, r3
mflr r3
stw r3, HOST_STACK_LR(r1)
mfcr r5
Expand Down
10 changes: 5 additions & 5 deletions arch/powerpc/kvm/bookehv_interrupts.S
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,10 @@ _GLOBAL(kvmppc_resume_host)
#endif

/* Switch to kernel stack and jump to handler. */
PPC_LL r3, HOST_RUN(r1)
mr r3, r4
mr r5, r14 /* intno */
mr r14, r4 /* Save vcpu pointer. */
mr r4, r5
bl kvmppc_handle_exit

/* Restore vcpu pointer and the nonvolatiles we used. */
Expand Down Expand Up @@ -525,15 +526,14 @@ heavyweight_exit:
blr

/* Registers:
* r3: kvm_run pointer
* r4: vcpu pointer
* r3: vcpu pointer
*/
_GLOBAL(__kvmppc_vcpu_run)
stwu r1, -HOST_STACK_SIZE(r1)
PPC_STL r1, VCPU_HOST_STACK(r4) /* Save stack pointer to vcpu. */
PPC_STL r1, VCPU_HOST_STACK(r3) /* Save stack pointer to vcpu. */

/* Save host state to stack. */
PPC_STL r3, HOST_RUN(r1)
mr r4, r3
mflr r3
mfcr r5
PPC_STL r3, HOST_STACK_LR(r1)
Expand Down

0 comments on commit 7ec21d9

Please sign in to comment.