Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH] RISC-V: KVM: fix the Zicbo[m|z|p] block sizes in GET_ONE_REG
@ 2026-09-24  8:10 Yong-Xuan Wang
  2026-09-24  8:16 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Yong-Xuan Wang @ 2026-09-24  8:10 UTC (permalink / raw)
  To: Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti
  Cc: greentime.hu, vincent.chen, zong.li, Anup Patel, kvm, kvm-riscv,
	linux-riscv, linux-kernel, Yong-Xuan Wang

The kvm_riscv_vcpu_get_reg_config() should return the block size when
the host supports the corresponding extensions.

Fixes: 298276da73ca ("RISC-V: KVM: Zicbo[m|z|p] block sizes should be always present in ONE_REG")
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
---
 arch/riscv/kvm/vcpu_onereg.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c
index 877ba823fc74..f2b125569449 100644
--- a/arch/riscv/kvm/vcpu_onereg.c
+++ b/arch/riscv/kvm/vcpu_onereg.c
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: KVM: fix the Zicbo[m|z|p] block sizes in GET_ONE_REG
  2026-09-24  8:10 [PATCH] RISC-V: KVM: fix the Zicbo[m|z|p] block sizes in GET_ONE_REG Yong-Xuan Wang
@ 2026-09-24  8:16 ` sashiko-bot
  2026-09-24 15:17   ` Yong-Xuan Wang
  0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-09-24  8:16 UTC (permalink / raw)
  To: Yong-Xuan Wang; +Cc: kvm

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 <yongxuan.wang@sifive.com>

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.

> diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c
> index 877ba823fc747..f2b1255694491 100644
> --- a/arch/riscv/kvm/vcpu_onereg.c
> +++ b/arch/riscv/kvm/vcpu_onereg.c
> @@ -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.

>  		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;

[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.

>  		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;

[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.

>  		break;
>  	case KVM_REG_RISCV_CONFIG_REG(mvendorid):
>  		reg_val = vcpu->arch.mvendorid;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260924-kvm_fix_cbosize-v1-1-e57eec1b19cb@sifive.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: KVM: fix the Zicbo[m|z|p] block sizes in GET_ONE_REG
  2026-09-24  8:16 ` sashiko-bot
@ 2026-09-24 15:17   ` Yong-Xuan Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Yong-Xuan Wang @ 2026-09-24 15:17 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: kvm

oh I misunderstood the kvm_riscv_isa_check_host(...), please ignore this patch.


On Thu, Sep 24, 2026 at 4:16 PM <sashiko-bot@kernel.org> wrote:
>
> 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 <yongxuan.wang@sifive.com>
>
> 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.
>
> > diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c
> > index 877ba823fc747..f2b1255694491 100644
> > --- a/arch/riscv/kvm/vcpu_onereg.c
> > +++ b/arch/riscv/kvm/vcpu_onereg.c
> > @@ -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.
>
> >               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;
>
> [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.
>
> >               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;
>
> [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.
>
> >               break;
> >       case KVM_REG_RISCV_CONFIG_REG(mvendorid):
> >               reg_val = vcpu->arch.mvendorid;
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260924-kvm_fix_cbosize-v1-1-e57eec1b19cb@sifive.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-24 15:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-24  8:10 [PATCH] RISC-V: KVM: fix the Zicbo[m|z|p] block sizes in GET_ONE_REG Yong-Xuan Wang
2026-09-24  8:16 ` sashiko-bot
2026-09-24 15:17   ` Yong-Xuan Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox