RISC-V: KVM: do not EOPNOTSUPP in set_one_reg() zicbo(m|z)
authorDaniel Henrique Barboza <dbarboza@ventanamicro.com>
Thu, 3 Aug 2023 16:32:55 +0000 (13:32 -0300)
committerAnup Patel <anup@brainfault.org>
Tue, 8 Aug 2023 11:55:47 +0000 (17:25 +0530)
commite29f57911d61bcbbe442c72933c606225d3d4d68
treef92d17b04f78de32ffc62d10a0319af01e1af025
parenta044ef71043ebc23903f657fd51b10783d34918b
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>
arch/riscv/kvm/vcpu_onereg.c