From: sashiko-bot@kernel.org
To: "Andy Chiu" <tchiu@tenstorrent.com>
Cc: linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH v4 2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off
Date: Sat, 25 Jul 2026 00:37:50 +0000 [thread overview]
Message-ID: <20260725003751.2A2961F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260725001749.2579274-3-tchiu@tenstorrent.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Removing the `!irqs_disabled()` check from `may_use_simd()` exposes KVM guest vector state to corruption and leakage by hardirqs.
--
--- Patch [2]: [PATCH v4 2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off ---
commit db1e5a6ad1a80d124f168f9dae7f399f6eec4f67
Author: Andy Chiu <tchiu@tenstorrent.com>
riscv: vector: allow non-preemptible kernel-mode vector with IRQs off
This commit upgrades get/put_cpu_vector_context to allow safe execution under
both IRQ off and regular process context, similar to arm64/fpsimd. It also
exports these symbols for the KVM module to call.
> diff --git a/arch/riscv/include/asm/simd.h b/arch/riscv/include/asm/simd.h
> index adb50f3ec2057..f176a8072c625 100644
> --- a/arch/riscv/include/asm/simd.h
> +++ b/arch/riscv/include/asm/simd.h
[ ... ]
> @@ -36,20 +36,10 @@ static __must_check inline bool may_use_simd(void)
> /*
> * Nesting is achieved in preempt_v by spreading the control for
> * preemptible and non-preemptible kernel-mode Vector into two fields.
> - * Always try to match with preempt_v if kernel V-context exists. Then,
> - * fallback to check non preempt_v if nesting happens, or if the config
> - * is not set.
> + * Only non-preempt_v can nest on top of preempt_v, if non-preempt_v is
> + * unavailable, then preempt_v is not allowed.
> */
> - if (IS_ENABLED(CONFIG_RISCV_ISA_V_PREEMPTIVE) && current->thread.kernel_vstate.datap) {
> - if (!riscv_preempt_v_started(current))
> - return true;
> - }
> - /*
> - * Non-preemptible kernel-mode Vector temporarily disables bh. So we
> - * must not return true on irq_disabled(). Otherwise we would fail the
> - * lockdep check calling local_bh_enable()
> - */
> - return !irqs_disabled() && !(riscv_v_flags() & RISCV_KERNEL_MODE_V);
> + return !(riscv_v_flags() & RISCV_KERNEL_MODE_V);
[Severity: High]
Does removing the !irqs_disabled() check here expose KVM guest vector state
to corruption and leakage by hardirqs?
If KVM loads guest vector state into CPU registers during kvm_arch_vcpu_load(),
and a hardirq using vector instructions fires while running KVM code,
may_use_simd() will now return true.
Would kernel_vector_begin() then save the CPU hardware registers (which contain
KVM guest data) into the host task's current->thread.vstate, followed by the
hardirq clobbering the CPU registers with its own vector operations?
If this happens, when the hardirq returns KVM would resume with corrupted
vector state, and the host task (e.g., QEMU) could receive the leaked guest
state.
While this series exports KVM symbols to potentially let KVM set
RISCV_KERNEL_MODE_V to protect the state, are the actual KVM patches to set
this flag missing from this series, leaving the tree vulnerable in the interim?
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260725001749.2579274-1-tchiu@tenstorrent.com?part=2
next prev parent reply other threads:[~2026-07-25 0:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 0:17 [PATCH v4 0/3] RISC-V: KVM: fix vcpu vector context handling Andy Chiu
2026-07-25 0:17 ` Andy Chiu
2026-07-25 0:17 ` Andy Chiu
2026-07-25 0:17 ` [PATCH v4 1/3] riscv: vector: refactor riscv_v_start_kernel_context Andy Chiu
2026-07-25 0:17 ` Andy Chiu
2026-07-25 0:17 ` [PATCH v4 2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off Andy Chiu
2026-07-25 0:17 ` Andy Chiu
2026-07-25 0:17 ` Andy Chiu
2026-07-25 0:37 ` sashiko-bot [this message]
2026-07-25 0:17 ` [PATCH v4 3/3] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector Andy Chiu
2026-07-25 0:17 ` Andy Chiu
2026-07-25 0:17 ` Andy Chiu
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=20260725003751.2A2961F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tchiu@tenstorrent.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.