Skip to content

Commit e29f579

Browse files
danielhbavpatel
authored andcommitted
RISC-V: KVM: do not EOPNOTSUPP in set_one_reg() zicbo(m|z)
zicbom_block_size and zicboz_block_size have a peculiar API: they can be read via get_one_reg() but any write will return a EOPNOTSUPP. It makes sense to return a 'not supported' error since both values can't be changed, but as far as userspace goes they're regs that are throwing the same EOPNOTSUPP error even if they were read beforehand via get_one_reg(), even if the same read value is being written back. EOPNOTSUPP is also returned even if ZICBOM/ZICBOZ aren't enabled in the host. Change both to work more like their counterparts in get_one_reg() and return -ENOENT if their respective extensions aren't available. After that, check if the userspace is written a valid value (i.e. the host value). Throw an -EINVAL if that's not case, let it slide otherwise. This allows both regs to be read/written by userspace in a 'lazy' manner, as long as the userspace doesn't change the reg vals. Suggested-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent a044ef7 commit e29f579

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

arch/riscv/kvm/vcpu_onereg.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,17 @@ static int kvm_riscv_vcpu_set_reg_config(struct kvm_vcpu *vcpu,
216216
}
217217
break;
218218
case KVM_REG_RISCV_CONFIG_REG(zicbom_block_size):
219-
return -EOPNOTSUPP;
219+
if (!riscv_isa_extension_available(vcpu->arch.isa, ZICBOM))
220+
return -ENOENT;
221+
if (reg_val != riscv_cbom_block_size)
222+
return -EINVAL;
223+
break;
220224
case KVM_REG_RISCV_CONFIG_REG(zicboz_block_size):
221-
return -EOPNOTSUPP;
225+
if (!riscv_isa_extension_available(vcpu->arch.isa, ZICBOZ))
226+
return -ENOENT;
227+
if (reg_val != riscv_cboz_block_size)
228+
return -EINVAL;
229+
break;
222230
case KVM_REG_RISCV_CONFIG_REG(mvendorid):
223231
if (!vcpu->arch.ran_atleast_once)
224232
vcpu->arch.mvendorid = reg_val;

0 commit comments

Comments
 (0)