Skip to content

Commit d808f0b

Browse files
committed
RISC-V: KVM: Forward SEED CSR access to user space
The SEED CSR access from VS/VU mode (guest) will always trap to HS-mode (KVM) when Zkr extension is available to the Guest/VM. Forward this CSR access to KVM user space so that it can be emulated based on the method chosen by VMM. Fixes: f370b4e ("RISC-V: KVM: Allow scalar crypto extensions for Guest/VM") Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent d0b94bc commit d808f0b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

arch/riscv/kvm/vcpu_insn.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <linux/bitops.h>
88
#include <linux/kvm_host.h>
99

10+
#include <asm/cpufeature.h>
11+
1012
#define INSN_OPCODE_MASK 0x007c
1113
#define INSN_OPCODE_SHIFT 2
1214
#define INSN_OPCODE_SYSTEM 28
@@ -213,9 +215,20 @@ struct csr_func {
213215
unsigned long wr_mask);
214216
};
215217

218+
static int seed_csr_rmw(struct kvm_vcpu *vcpu, unsigned int csr_num,
219+
unsigned long *val, unsigned long new_val,
220+
unsigned long wr_mask)
221+
{
222+
if (!riscv_isa_extension_available(vcpu->arch.isa, ZKR))
223+
return KVM_INSN_ILLEGAL_TRAP;
224+
225+
return KVM_INSN_EXIT_TO_USER_SPACE;
226+
}
227+
216228
static const struct csr_func csr_funcs[] = {
217229
KVM_RISCV_VCPU_AIA_CSR_FUNCS
218230
KVM_RISCV_VCPU_HPMCOUNTER_CSR_FUNCS
231+
{ .base = CSR_SEED, .count = 1, .func = seed_csr_rmw },
219232
};
220233

221234
/**

0 commit comments

Comments
 (0)