Skip to content

Commit 48e2feb

Browse files
zcxGGmuavpatel
authored andcommitted
RISC-V: KVM: Provide UAPI for Zicbop block size
We're about to allow guests to use the Zicbop extension. KVM userspace needs to know the cache block size in order to properly advertise it to the guest. Provide a virtual config register for userspace to get it with the GET_ONE_REG API, but setting it cannot be supported, so disallow SET_ONE_REG. Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn> Reviewed-by: Nutty Liu <nutty.liu@hotmail.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Link: https://lore.kernel.org/r/befd8403cd76d7adb97231ac993eaeb86bf2582c.1754646071.git.zhouquan@iscas.ac.cn Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent eca26ea commit 48e2feb

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

arch/riscv/include/uapi/asm/kvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct kvm_riscv_config {
5656
unsigned long mimpid;
5757
unsigned long zicboz_block_size;
5858
unsigned long satp_mode;
59+
unsigned long zicbop_block_size;
5960
};
6061

6162
/* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */

arch/riscv/kvm/vcpu_onereg.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu,
285285
return -ENOENT;
286286
reg_val = riscv_cboz_block_size;
287287
break;
288+
case KVM_REG_RISCV_CONFIG_REG(zicbop_block_size):
289+
if (!riscv_isa_extension_available(NULL, ZICBOP))
290+
return -ENOENT;
291+
reg_val = riscv_cbop_block_size;
292+
break;
288293
case KVM_REG_RISCV_CONFIG_REG(mvendorid):
289294
reg_val = vcpu->arch.mvendorid;
290295
break;
@@ -376,6 +381,12 @@ static int kvm_riscv_vcpu_set_reg_config(struct kvm_vcpu *vcpu,
376381
if (reg_val != riscv_cboz_block_size)
377382
return -EINVAL;
378383
break;
384+
case KVM_REG_RISCV_CONFIG_REG(zicbop_block_size):
385+
if (!riscv_isa_extension_available(NULL, ZICBOP))
386+
return -ENOENT;
387+
if (reg_val != riscv_cbop_block_size)
388+
return -EINVAL;
389+
break;
379390
case KVM_REG_RISCV_CONFIG_REG(mvendorid):
380391
if (reg_val == vcpu->arch.mvendorid)
381392
break;
@@ -821,6 +832,9 @@ static int copy_config_reg_indices(const struct kvm_vcpu *vcpu,
821832
else if (i == KVM_REG_RISCV_CONFIG_REG(zicboz_block_size) &&
822833
!riscv_isa_extension_available(NULL, ZICBOZ))
823834
continue;
835+
else if (i == KVM_REG_RISCV_CONFIG_REG(zicbop_block_size) &&
836+
!riscv_isa_extension_available(NULL, ZICBOP))
837+
continue;
824838

825839
size = IS_ENABLED(CONFIG_32BIT) ? KVM_REG_SIZE_U32 : KVM_REG_SIZE_U64;
826840
reg = KVM_REG_RISCV | size | KVM_REG_RISCV_CONFIG | i;

0 commit comments

Comments
 (0)