RISC-V: KVM: Forward SBI experimental and vendor extensions
authorAnup Patel <anup.patel@wdc.com>
Fri, 26 Nov 2021 05:18:41 +0000 (10:48 +0530)
committerAnup Patel <anup@brainfault.org>
Thu, 6 Jan 2022 09:44:33 +0000 (15:14 +0530)
The SBI experimental extension space is for temporary (or experimental)
stuff whereas SBI vendor extension space is for hardware vendor specific
stuff. Both these SBI extension spaces won't be standardized by the SBI
specification so let's blindly forward such SBI calls to the userspace.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-and-tested-by: Atish Patra <atishp@rivosinc.com>
arch/riscv/kvm/vcpu_sbi.c
arch/riscv/kvm/vcpu_sbi_base.c

index f62d25bc97339a9df8d0aedc9a23d520ea1d90a7..78aa3db76225de5c82a7dcdc8903a166b5892e05 100644 (file)
@@ -46,6 +46,8 @@ extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_time;
 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_ipi;
 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence;
 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm;
+extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental;
+extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor;
 
 static const struct kvm_vcpu_sbi_extension *sbi_ext[] = {
        &vcpu_sbi_ext_v01,
@@ -54,6 +56,8 @@ static const struct kvm_vcpu_sbi_extension *sbi_ext[] = {
        &vcpu_sbi_ext_ipi,
        &vcpu_sbi_ext_rfence,
        &vcpu_sbi_ext_hsm,
+       &vcpu_sbi_ext_experimental,
+       &vcpu_sbi_ext_vendor,
 };
 
 void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run)
index d1ec08fe7289b1366474bc1e4c3587b0b195f30f..4ecf377f483b866bfa4c09144fda662efd6de5f4 100644 (file)
@@ -70,3 +70,30 @@ const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_base = {
        .extid_end = SBI_EXT_BASE,
        .handler = kvm_sbi_ext_base_handler,
 };
+
+static int kvm_sbi_ext_forward_handler(struct kvm_vcpu *vcpu,
+                                       struct kvm_run *run,
+                                       unsigned long *out_val,
+                                       struct kvm_cpu_trap *utrap,
+                                       bool *exit)
+{
+       /*
+        * Both SBI experimental and vendor extensions are
+        * unconditionally forwarded to userspace.
+        */
+       kvm_riscv_vcpu_sbi_forward(vcpu, run);
+       *exit = true;
+       return 0;
+}
+
+const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental = {
+       .extid_start = SBI_EXT_EXPERIMENTAL_START,
+       .extid_end = SBI_EXT_EXPERIMENTAL_END,
+       .handler = kvm_sbi_ext_forward_handler,
+};
+
+const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor = {
+       .extid_start = SBI_EXT_VENDOR_START,
+       .extid_end = SBI_EXT_VENDOR_END,
+       .handler = kvm_sbi_ext_forward_handler,
+};