Skip to content

Commit a1c6684

Browse files
radimkrcmaravpatel
authored andcommitted
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>
1 parent 9ffecf0 commit a1c6684

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

arch/riscv/include/asm/kvm_vcpu_sbi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run);
5555
void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
5656
struct kvm_run *run,
5757
u32 type, u64 flags);
58+
void kvm_riscv_vcpu_sbi_request_reset(struct kvm_vcpu *vcpu,
59+
unsigned long pc, unsigned long a1);
5860
int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
5961
int kvm_riscv_vcpu_set_reg_sbi_ext(struct kvm_vcpu *vcpu,
6062
const struct kvm_one_reg *reg);

arch/riscv/kvm/vcpu_sbi.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
156156
run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
157157
}
158158

159+
void kvm_riscv_vcpu_sbi_request_reset(struct kvm_vcpu *vcpu,
160+
unsigned long pc, unsigned long a1)
161+
{
162+
spin_lock(&vcpu->arch.reset_cntx_lock);
163+
vcpu->arch.guest_reset_context.sepc = pc;
164+
vcpu->arch.guest_reset_context.a0 = vcpu->vcpu_id;
165+
vcpu->arch.guest_reset_context.a1 = a1;
166+
spin_unlock(&vcpu->arch.reset_cntx_lock);
167+
168+
kvm_make_request(KVM_REQ_VCPU_RESET, vcpu);
169+
}
170+
159171
int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run)
160172
{
161173
struct kvm_cpu_context *cp = &vcpu->arch.guest_context;

arch/riscv/kvm/vcpu_sbi_hsm.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
static int kvm_sbi_hsm_vcpu_start(struct kvm_vcpu *vcpu)
1717
{
18-
struct kvm_cpu_context *reset_cntx;
1918
struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
2019
struct kvm_vcpu *target_vcpu;
2120
unsigned long target_vcpuid = cp->a0;
@@ -32,17 +31,7 @@ static int kvm_sbi_hsm_vcpu_start(struct kvm_vcpu *vcpu)
3231
goto out;
3332
}
3433

35-
spin_lock(&target_vcpu->arch.reset_cntx_lock);
36-
reset_cntx = &target_vcpu->arch.guest_reset_context;
37-
/* start address */
38-
reset_cntx->sepc = cp->a1;
39-
/* target vcpu id to start */
40-
reset_cntx->a0 = target_vcpuid;
41-
/* private data passed from kernel */
42-
reset_cntx->a1 = cp->a2;
43-
spin_unlock(&target_vcpu->arch.reset_cntx_lock);
44-
45-
kvm_make_request(KVM_REQ_VCPU_RESET, target_vcpu);
34+
kvm_riscv_vcpu_sbi_request_reset(target_vcpu, cp->a1, cp->a2);
4635

4736
__kvm_riscv_vcpu_power_on(target_vcpu);
4837

arch/riscv/kvm/vcpu_sbi_system.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ static int kvm_sbi_ext_susp_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
1313
struct kvm_vcpu_sbi_return *retdata)
1414
{
1515
struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
16-
struct kvm_cpu_context *reset_cntx;
1716
unsigned long funcid = cp->a6;
1817
unsigned long hva, i;
1918
struct kvm_vcpu *tmp;
@@ -45,14 +44,7 @@ static int kvm_sbi_ext_susp_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
4544
}
4645
}
4746

48-
spin_lock(&vcpu->arch.reset_cntx_lock);
49-
reset_cntx = &vcpu->arch.guest_reset_context;
50-
reset_cntx->sepc = cp->a1;
51-
reset_cntx->a0 = vcpu->vcpu_id;
52-
reset_cntx->a1 = cp->a2;
53-
spin_unlock(&vcpu->arch.reset_cntx_lock);
54-
55-
kvm_make_request(KVM_REQ_VCPU_RESET, vcpu);
47+
kvm_riscv_vcpu_sbi_request_reset(vcpu, cp->a1, cp->a2);
5648

5749
/* userspace provides the suspend implementation */
5850
kvm_riscv_vcpu_sbi_forward(vcpu, run);

0 commit comments

Comments
 (0)