mirror of https://github.com/torvalds/linux.git
KVM: RISC-V: refactor sbi reset request
The same code is used twice and SBI reset sets only two variables. Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Radim Krčmář <rkrcmar@ventanamicro.com> Link: https://lore.kernel.org/r/20250403112522.1566629-5-rkrcmar@ventanamicro.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
parent
9ffecf0414
commit
a1c66842f1
|
|
@ -55,6 +55,8 @@ void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run);
|
|||
void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
|
||||
struct kvm_run *run,
|
||||
u32 type, u64 flags);
|
||||
void kvm_riscv_vcpu_sbi_request_reset(struct kvm_vcpu *vcpu,
|
||||
unsigned long pc, unsigned long a1);
|
||||
int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
|
||||
int kvm_riscv_vcpu_set_reg_sbi_ext(struct kvm_vcpu *vcpu,
|
||||
const struct kvm_one_reg *reg);
|
||||
|
|
|
|||
|
|
@ -156,6 +156,18 @@ void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
|
|||
run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
|
||||
}
|
||||
|
||||
void kvm_riscv_vcpu_sbi_request_reset(struct kvm_vcpu *vcpu,
|
||||
unsigned long pc, unsigned long a1)
|
||||
{
|
||||
spin_lock(&vcpu->arch.reset_cntx_lock);
|
||||
vcpu->arch.guest_reset_context.sepc = pc;
|
||||
vcpu->arch.guest_reset_context.a0 = vcpu->vcpu_id;
|
||||
vcpu->arch.guest_reset_context.a1 = a1;
|
||||
spin_unlock(&vcpu->arch.reset_cntx_lock);
|
||||
|
||||
kvm_make_request(KVM_REQ_VCPU_RESET, vcpu);
|
||||
}
|
||||
|
||||
int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run)
|
||||
{
|
||||
struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
static int kvm_sbi_hsm_vcpu_start(struct kvm_vcpu *vcpu)
|
||||
{
|
||||
struct kvm_cpu_context *reset_cntx;
|
||||
struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
|
||||
struct kvm_vcpu *target_vcpu;
|
||||
unsigned long target_vcpuid = cp->a0;
|
||||
|
|
@ -32,17 +31,7 @@ static int kvm_sbi_hsm_vcpu_start(struct kvm_vcpu *vcpu)
|
|||
goto out;
|
||||
}
|
||||
|
||||
spin_lock(&target_vcpu->arch.reset_cntx_lock);
|
||||
reset_cntx = &target_vcpu->arch.guest_reset_context;
|
||||
/* start address */
|
||||
reset_cntx->sepc = cp->a1;
|
||||
/* target vcpu id to start */
|
||||
reset_cntx->a0 = target_vcpuid;
|
||||
/* private data passed from kernel */
|
||||
reset_cntx->a1 = cp->a2;
|
||||
spin_unlock(&target_vcpu->arch.reset_cntx_lock);
|
||||
|
||||
kvm_make_request(KVM_REQ_VCPU_RESET, target_vcpu);
|
||||
kvm_riscv_vcpu_sbi_request_reset(target_vcpu, cp->a1, cp->a2);
|
||||
|
||||
__kvm_riscv_vcpu_power_on(target_vcpu);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ static int kvm_sbi_ext_susp_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
|
|||
struct kvm_vcpu_sbi_return *retdata)
|
||||
{
|
||||
struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
|
||||
struct kvm_cpu_context *reset_cntx;
|
||||
unsigned long funcid = cp->a6;
|
||||
unsigned long hva, i;
|
||||
struct kvm_vcpu *tmp;
|
||||
|
|
@ -45,14 +44,7 @@ static int kvm_sbi_ext_susp_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
|
|||
}
|
||||
}
|
||||
|
||||
spin_lock(&vcpu->arch.reset_cntx_lock);
|
||||
reset_cntx = &vcpu->arch.guest_reset_context;
|
||||
reset_cntx->sepc = cp->a1;
|
||||
reset_cntx->a0 = vcpu->vcpu_id;
|
||||
reset_cntx->a1 = cp->a2;
|
||||
spin_unlock(&vcpu->arch.reset_cntx_lock);
|
||||
|
||||
kvm_make_request(KVM_REQ_VCPU_RESET, vcpu);
|
||||
kvm_riscv_vcpu_sbi_request_reset(vcpu, cp->a1, cp->a2);
|
||||
|
||||
/* userspace provides the suspend implementation */
|
||||
kvm_riscv_vcpu_sbi_forward(vcpu, run);
|
||||
|
|
|
|||
Loading…
Reference in New Issue