Commit 38d9a4ac authored by Atish Patra's avatar Atish Patra Committed by Anup Patel

RISC-V: KVM: Restrict the extensions that can be disabled

Currently, the config isa register allows us to disable all allowed
single letter ISA extensions. It shouldn't be the case as vmm shouldn't
be able to disable base extensions (imac).

These extensions should always be enabled as long as they are enabled
in the host ISA.
Signed-off-by: default avatarAtish Patra <atishp@rivosinc.com>
Signed-off-by: default avatarAnup Patel <anup@brainfault.org>
Fixes: 92ad8200 ("RISC-V: KVM: Implement
KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls")
parent 3ab75a79
...@@ -38,12 +38,16 @@ const struct kvm_stats_header kvm_vcpu_stats_header = { ...@@ -38,12 +38,16 @@ const struct kvm_stats_header kvm_vcpu_stats_header = {
sizeof(kvm_vcpu_stats_desc), sizeof(kvm_vcpu_stats_desc),
}; };
#define KVM_RISCV_ISA_ALLOWED (riscv_isa_extension_mask(a) | \ #define KVM_RISCV_ISA_DISABLE_ALLOWED (riscv_isa_extension_mask(d) | \
riscv_isa_extension_mask(c) | \ riscv_isa_extension_mask(f))
riscv_isa_extension_mask(d) | \
riscv_isa_extension_mask(f) | \ #define KVM_RISCV_ISA_DISABLE_NOT_ALLOWED (riscv_isa_extension_mask(a) | \
riscv_isa_extension_mask(i) | \ riscv_isa_extension_mask(c) | \
riscv_isa_extension_mask(m)) riscv_isa_extension_mask(i) | \
riscv_isa_extension_mask(m))
#define KVM_RISCV_ISA_ALLOWED (KVM_RISCV_ISA_DISABLE_ALLOWED | \
KVM_RISCV_ISA_DISABLE_NOT_ALLOWED)
static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu) static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu)
{ {
...@@ -217,7 +221,8 @@ static int kvm_riscv_vcpu_set_reg_config(struct kvm_vcpu *vcpu, ...@@ -217,7 +221,8 @@ static int kvm_riscv_vcpu_set_reg_config(struct kvm_vcpu *vcpu,
switch (reg_num) { switch (reg_num) {
case KVM_REG_RISCV_CONFIG_REG(isa): case KVM_REG_RISCV_CONFIG_REG(isa):
if (!vcpu->arch.ran_atleast_once) { if (!vcpu->arch.ran_atleast_once) {
vcpu->arch.isa = reg_val; /* Ignore the disable request for these extensions */
vcpu->arch.isa = reg_val | KVM_RISCV_ISA_DISABLE_NOT_ALLOWED;
vcpu->arch.isa &= riscv_isa_extension_base(NULL); vcpu->arch.isa &= riscv_isa_extension_base(NULL);
vcpu->arch.isa &= KVM_RISCV_ISA_ALLOWED; vcpu->arch.isa &= KVM_RISCV_ISA_ALLOWED;
kvm_riscv_vcpu_fp_reset(vcpu); kvm_riscv_vcpu_fp_reset(vcpu);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment