Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Inochi Amaoto" <inochiama@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v6 6/8] RISC-V: KVM: Delegate SPELP bit to VS/VU mode if landing pad is enabled.
Date: Mon, 13 Jul 2026 01:17:54 +0000	[thread overview]
Message-ID: <20260713011755.266211F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260713010302.303278-7-inochiama@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The guest's Expected Landing Pad (ELP) state is not exposed to the KVM userspace API, causing silent loss of Forward-Edge CFI protection across live migrations.
- [High] KVM fails to initialize ENVCFG_LPE and ENVCFG_SSE in vcpu->arch.cfg.henvcfg when the Zicfilp/Zicfiss extensions are enabled, rendering the SPELP trap redirection dead code and silently disabling guest CFI protections.
--

--- Patch [6]: [PATCH v6 6/8] RISC-V: KVM: Delegate SPELP bit to VS/VU mode if landing pad is enabled. ---
commit bd73a6254729060ad92677fe490d23fc4aea31a6
Author: Inochi Amaoto <inochiama@gmail.com>

RISC-V: KVM: Delegate SPELP bit to VS/VU mode if landing pad is enabled.

This commit delegates the SPELP bit from the Zicfilp extension to VS/VU
mode when landing pad support is enabled. It clears and updates the guest
SSTATUS.SPELP bit during trap redirection based on the guest context.

> diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c
> --- a/arch/riscv/kvm/vcpu_exit.c
> +++ b/arch/riscv/kvm/vcpu_exit.c

[ ... ]

> @@ -154,6 +154,13 @@ void kvm_riscv_vcpu_trap_redirect(struct kvm_vcpu *vcpu,
>  	/* Clear Guest SSTATUS.SIE bit */
>  	vsstatus &= ~SR_SIE;
>  
> +	/* Change Guest SSTATUS.SPELP bit */
> +	if (vcpu->arch.cfg.henvcfg & ENVCFG_LPE) {

[Severity: High]
Will this condition ever be true? Looking at the vCPU initialization
code in kvm_riscv_vcpu_config_ran_once(), it appears KVM does not currently
set ENVCFG_LPE or ENVCFG_SSE in henvcfg when the Zicfilp or Zicfiss
extensions are available.

If ENVCFG_LPE is never initialized, this block becomes dead code, and writes
to the guest's SENVCFG CSR for landing pads would be silently ignored by the
hardware. Should the HENVCFG setup be added to
kvm_riscv_vcpu_config_ran_once() so the guest can successfully enable
CFI protections?

> +		vsstatus &= ~SR_SPELP;
> +		vsstatus |= vcpu->arch.guest_context.sstatus & SR_SPELP;
> +		vcpu->arch.guest_context.sstatus &= ~SR_SPELP;

[Severity: High]
Does this new SPELP state need to be exposed to userspace to prevent
losing the landing pad state across live migrations?

When a guest traps to the hypervisor, the hardware saves the active ELP
state, which KVM now stores in vcpu->arch.guest_context.sstatus. However,
when userspace reads the core registers during migration:

arch/riscv/kvm/vcpu_onereg.c:kvm_riscv_vcpu_get_reg_core() {
        ...
        else if (reg_num == KVM_REG_RISCV_CORE_REG(mode))
                reg_val = (cntx->sstatus & SR_SPP) ?
                                KVM_RISCV_MODE_S : KVM_RISCV_MODE_U;
        ...
}

The SPELP bit is not extracted, meaning the VMM cannot save or restore
the guest's ELP state. If a migration occurs immediately after an indirect
branch in the guest, would resuming on the destination node with ELP=0
silently bypass the Zicfilp CFI hardware check?

> +	}
> +
>  	/* Update Guest SSTATUS */
>  	ncsr_write(CSR_VSSTATUS, vsstatus);
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260713010302.303278-1-inochiama@gmail.com?part=6

  reply	other threads:[~2026-07-13  1:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13  1:02 [PATCH v6 0/8] RISC-V: KVM: Add Svadu/Zicfiss/Zicfilp FWFT support Inochi Amaoto
2026-07-13  1:02 ` [PATCH v6 1/8] RISC-V: KVM: Add support for Svadu FWFT features Inochi Amaoto
2026-07-13  1:02 ` [PATCH v6 2/8] KVM: riscv: selftests: add Svadu FWFT extension to get-reg-list test Inochi Amaoto
2026-07-13  1:02 ` [PATCH v6 3/8] RISC-V: KVM: Allow Zicfiss/Zicfilp extensions for Guest/VM Inochi Amaoto
2026-07-13  1:17   ` sashiko-bot
2026-07-13  1:02 ` [PATCH v6 4/8] RISC-V: KVM: Add ssp context save/restore Inochi Amaoto
2026-07-13  1:20   ` sashiko-bot
2026-07-13  1:02 ` [PATCH v6 5/8] RISC-V: KVM: Handle software-check exits for VCPU Inochi Amaoto
2026-07-13  1:02 ` [PATCH v6 6/8] RISC-V: KVM: Delegate SPELP bit to VS/VU mode if landing pad is enabled Inochi Amaoto
2026-07-13  1:17   ` sashiko-bot [this message]
2026-07-13  1:03 ` [PATCH v6 7/8] RISC-V: KVM: Add support for control-flow integrity FWFT features Inochi Amaoto
2026-07-13  1:03 ` [PATCH v6 8/8] KVM: riscv: selftests: add Zicfiss/Zicfilp extension to get-reg-list test Inochi Amaoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260713011755.266211F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=inochiama@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox