Skip to content

Commit 5fed84a

Browse files
Andrew Jonesavpatel
authored andcommitted
RISC-V: KVM: Add SBI STA extension skeleton
Add the files and functions needed to support the SBI STA (steal-time accounting) extension. In the next patches we'll complete the functions to fully enable SBI STA support. Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Atish Patra <atishp@rivosinc.com> Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent fdf68ac commit 5fed84a

5 files changed

Lines changed: 54 additions & 0 deletions

File tree

arch/riscv/include/asm/kvm_vcpu_sbi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence;
7676
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst;
7777
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm;
7878
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_dbcn;
79+
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta;
7980
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental;
8081
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor;
8182

arch/riscv/include/uapi/asm/kvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ enum KVM_RISCV_SBI_EXT_ID {
157157
KVM_RISCV_SBI_EXT_EXPERIMENTAL,
158158
KVM_RISCV_SBI_EXT_VENDOR,
159159
KVM_RISCV_SBI_EXT_DBCN,
160+
KVM_RISCV_SBI_EXT_STA,
160161
KVM_RISCV_SBI_EXT_MAX,
161162
};
162163

arch/riscv/kvm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ kvm-$(CONFIG_RISCV_SBI_V01) += vcpu_sbi_v01.o
2626
kvm-y += vcpu_sbi_base.o
2727
kvm-y += vcpu_sbi_replace.o
2828
kvm-y += vcpu_sbi_hsm.o
29+
kvm-y += vcpu_sbi_sta.o
2930
kvm-y += vcpu_timer.o
3031
kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_pmu.o vcpu_sbi_pmu.o
3132
kvm-y += aia.o

arch/riscv/kvm/vcpu_sbi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ static const struct kvm_riscv_sbi_extension_entry sbi_ext[] = {
7070
.ext_idx = KVM_RISCV_SBI_EXT_DBCN,
7171
.ext_ptr = &vcpu_sbi_ext_dbcn,
7272
},
73+
{
74+
.ext_idx = KVM_RISCV_SBI_EXT_STA,
75+
.ext_ptr = &vcpu_sbi_ext_sta,
76+
},
7377
{
7478
.ext_idx = KVM_RISCV_SBI_EXT_EXPERIMENTAL,
7579
.ext_ptr = &vcpu_sbi_ext_experimental,

arch/riscv/kvm/vcpu_sbi_sta.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2023 Ventana Micro Systems Inc.
4+
*/
5+
6+
#include <linux/kvm_host.h>
7+
8+
#include <asm/kvm_vcpu_sbi.h>
9+
#include <asm/sbi.h>
10+
11+
static int kvm_sbi_sta_steal_time_set_shmem(struct kvm_vcpu *vcpu)
12+
{
13+
return SBI_ERR_FAILURE;
14+
}
15+
16+
static int kvm_sbi_ext_sta_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
17+
struct kvm_vcpu_sbi_return *retdata)
18+
{
19+
struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
20+
unsigned long funcid = cp->a6;
21+
int ret;
22+
23+
switch (funcid) {
24+
case SBI_EXT_STA_STEAL_TIME_SET_SHMEM:
25+
ret = kvm_sbi_sta_steal_time_set_shmem(vcpu);
26+
break;
27+
default:
28+
ret = SBI_ERR_NOT_SUPPORTED;
29+
break;
30+
}
31+
32+
retdata->err_val = ret;
33+
34+
return 0;
35+
}
36+
37+
static unsigned long kvm_sbi_ext_sta_probe(struct kvm_vcpu *vcpu)
38+
{
39+
return 0;
40+
}
41+
42+
const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta = {
43+
.extid_start = SBI_EXT_STA,
44+
.extid_end = SBI_EXT_STA,
45+
.handler = kvm_sbi_ext_sta_handler,
46+
.probe = kvm_sbi_ext_sta_probe,
47+
};

0 commit comments

Comments
 (0)