RISC-V: KVM: fix the Zicbo[m|z|p] block sizes in GET_ONE_REG
Subsystems (3)
PATCH 1/1 RISC-V: KVM: fix the Zicbo[m|z|p] block sizes in GET_ONE_REG
The kvm_riscv_vcpu_get_reg_config() should return the block size when the host supports the corresponding extensions.
--- arch/riscv/kvm/vcpu_onereg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/riscv/kvm/vcpu_onereg.c +3 -3
@@ -50,13 +50,13 @@ static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, reg_val = vcpu->arch.isa[0 ] &KVM_RISCV_BASE_ISA_MASK ;break ;case KVM_REG_RISCV_CONFIG_REG (zicbom_block_size): - reg_val = (kvm_riscv_isa_check_host (ZICBOM )) ?0 : riscv_cbom_block_size; + reg_val = (kvm_riscv_isa_check_host (ZICBOM )) ? riscv_cbom_block_size :0 ;break ;case KVM_REG_RISCV_CONFIG_REG (zicboz_block_size): - reg_val = (kvm_riscv_isa_check_host (ZICBOZ )) ?0 : riscv_cboz_block_size; + reg_val = (kvm_riscv_isa_check_host (ZICBOZ )) ? riscv_cboz_block_size :0 ;break ;case KVM_REG_RISCV_CONFIG_REG (zicbop_block_size): - reg_val = (kvm_riscv_isa_check_host (ZICBOP )) ?0 : riscv_cbop_block_size; + reg_val = (kvm_riscv_isa_check_host (ZICBOP )) ? riscv_cbop_block_size :0 ;break ;case KVM_REG_RISCV_CONFIG_REG (mvendorid): reg_val = vcpu->arch.mvendorid;
---
base-commit: b5060a4aa33d7d78a8c1837ab08ef0c81ea96650
change-id: 20260924-kvm_fix_cbosize-1bf2cdd282cb
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] kvm: riscv: reversed logic in GET_ONE_REG for Zicbo block sizes --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kvm: riscv: reversed logic in GET_ONE_REG for Zicbo block sizes
--
commit 66e4542b7a02ac3b1e7a491baa6d04283e1ccc3a
Author: Yong-Xuan Wang <[email protected]>
RISC-V: KVM: fix the Zicbo[m|z|p] block sizes in GET_ONE_REG
This commit modifies the ternary operator logic used to determine the Zicbo block sizes reported to KVM userspace via GET_ONE_REG. It changes the previous behavior to return the block size or 0 based on host extension support.
arch/riscv/kvm/vcpu_onereg.c static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, · line 53
Quoted 10 lines
arch/riscv/kvm/vcpu_onereg.c +1
-1@@ -50,13 +50,13 @@ static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, reg_val = vcpu->arch.isa[0 ] &KVM_RISCV_BASE_ISA_MASK ;break ;case KVM_REG_RISCV_CONFIG_REG (zicbom_block_size): - reg_val = (kvm_riscv_isa_check_host (ZICBOM )) ?0 : riscv_cbom_block_size; + reg_val = (kvm_riscv_isa_check_host (ZICBOM )) ? riscv_cbom_block_size :0 ;
[Severity: High]
Does this change reverse the intended logic and cause a regression in the KVM userspace ABI?
Looking at kvm_riscv_vcpu_get_reg_config() in arch/riscv/kvm/vcpu_onereg.c, kvm_riscv_isa_check_host() returns 0 on success (supported) and -ENOENT on failure.
Because 0 evaluates to false in C, the updated ternary operator returns 0 when the extension is supported, and the block size when unsupported (-ENOENT evaluates to true).
This causes KVM userspace to receive a 0 block size for supported extensions, which can prevent VMs from starting or cause guest crashes when performing cache operations.
arch/riscv/kvm/vcpu_onereg.c static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, · line 56
Quoted 4 lines
arch/riscv/kvm/vcpu_onereg.c +1
-1break ;case KVM_REG_RISCV_CONFIG_REG (zicboz_block_size): - reg_val = (kvm_riscv_isa_check_host (ZICBOZ )) ?0 : riscv_cboz_block_size; + reg_val = (kvm_riscv_isa_check_host (ZICBOZ )) ? riscv_cboz_block_size :0 ;
[Severity: High]
Is this subject to the same logic reversal as above?
In kvm_riscv_vcpu_get_reg_config(), the ternary operator for the ZICBOZ extension similarly returns 0 when the host extension is supported.
arch/riscv/kvm/vcpu_onereg.c static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, · line 59
Quoted 4 lines
arch/riscv/kvm/vcpu_onereg.c +1
-1break ;case KVM_REG_RISCV_CONFIG_REG (zicbop_block_size): - reg_val = (kvm_riscv_isa_check_host (ZICBOP )) ?0 : riscv_cbop_block_size; + reg_val = (kvm_riscv_isa_check_host (ZICBOP )) ? riscv_cbop_block_size :0 ;
[Severity: High]
Does this also share the same logic reversal?
For the ZICBOP extension in kvm_riscv_vcpu_get_reg_config(), the ternary operator evaluates to 0 when the host supports the extension.
Quoted 3 lines
arch/riscv/kvm/vcpu_onereg.c +0
-0break ;case KVM_REG_RISCV_CONFIG_REG (mvendorid): reg_val = vcpu->arch.mvendorid;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
oh I misunderstood the kvm_riscv_isa_check_host(...), please ignore this patch.
Quoted 70 lines · On Thu, Sep 24, 2026 at 4:16 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kvm: riscv: reversed logic inGET_ONE_REGfor Zicbo block sizes
--commit
66e4542b7a02ac3b1e7a491baa6d04283e1ccc3a
Author: Yong-Xuan Wang <[email protected]>RISC-V: KVM: fix the Zicbo[m|z|p] block sizes in
GET_ONE_REGThis commit modifies the ternary operator logic used to determine the Zicbo block sizes reported to KVM userspace via
GET_ONE_REG. It changes the previous behavior to return the block size or 0 based on host extension support.arch/riscv/kvm/vcpu_onereg.c static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, · line 53
Quoted 10 lines
arch/riscv/kvm/vcpu_onereg.c +1
-1@@ -50,13 +50,13 @@ static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, reg_val = vcpu->arch.isa[0 ] &KVM_RISCV_BASE_ISA_MASK ;break ;case KVM_REG_RISCV_CONFIG_REG (zicbom_block_size): - reg_val = (kvm_riscv_isa_check_host (ZICBOM )) ?0 : riscv_cbom_block_size; + reg_val = (kvm_riscv_isa_check_host (ZICBOM )) ? riscv_cbom_block_size :0 ;[Severity: High]
Does this change reverse the intended logic and cause a regression in the KVM userspace ABI?Looking at
kvm_riscv_vcpu_get_reg_config()inarch/riscv/kvm/vcpu_onereg.c,kvm_riscv_isa_check_host()returns 0 on success (supported) and-ENOENTon failure.Because 0 evaluates to false in C, the updated ternary operator returns 0 when the extension is supported, and the block size when unsupported (
-ENOENTevaluates to true).This causes KVM userspace to receive a 0 block size for supported extensions, which can prevent VMs from starting or cause guest crashes when performing cache operations.
arch/riscv/kvm/vcpu_onereg.c static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, · line 56
Quoted 4 lines
arch/riscv/kvm/vcpu_onereg.c +1
-1break ;case KVM_REG_RISCV_CONFIG_REG (zicboz_block_size): - reg_val = (kvm_riscv_isa_check_host (ZICBOZ )) ?0 : riscv_cboz_block_size; + reg_val = (kvm_riscv_isa_check_host (ZICBOZ )) ? riscv_cboz_block_size :0 ;[Severity: High]
Is this subject to the same logic reversal as above?In
kvm_riscv_vcpu_get_reg_config(), the ternary operator for the ZICBOZ extension similarly returns 0 when the host extension is supported.arch/riscv/kvm/vcpu_onereg.c static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, · line 59
Quoted 4 lines
arch/riscv/kvm/vcpu_onereg.c +1
-1break ;case KVM_REG_RISCV_CONFIG_REG (zicbop_block_size): - reg_val = (kvm_riscv_isa_check_host (ZICBOP )) ?0 : riscv_cbop_block_size; + reg_val = (kvm_riscv_isa_check_host (ZICBOP )) ? riscv_cbop_block_size :0 ;[Severity: High]
Does this also share the same logic reversal?For the ZICBOP extension in
kvm_riscv_vcpu_get_reg_config(), the ternary operator evaluates to 0 when the host supports the extension.arch/riscv/kvm/vcpu_onereg.c static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, · line 62
Quoted 3 lines
arch/riscv/kvm/vcpu_onereg.c +0
-0break ;case KVM_REG_RISCV_CONFIG_REG (mvendorid): reg_val = vcpu->arch.mvendorid;--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1