From: sashiko-bot@kernel.org
To: "Andy Chiu" <tchiu@tenstorrent.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v5 3/3] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector
Date: Mon, 03 Aug 2026 22:37:41 +0000 [thread overview]
Message-ID: <20260803223742.0C19C1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260803215250.824417-4-tchiu@tenstorrent.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Preemptible kernel-mode vector (KMV) state is corrupted by KVM preempt notifiers when a VCPU thread is preempted.
--
--- Patch [3]: [PATCH v5 3/3] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector ---
commit 077b610f9ed223f15b05bd83c13e358e4b341dc9
Author: Andy Chiu <tchiu@tenstorrent.com>
RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector
This commit registers an RCU-protected callback to flush the vCPU vector
context when kernel-mode vector (KMV) is serving a guest. This prevents
KMV from misattributing the guest's vCPU context as the user's context.
> diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
> --- a/arch/riscv/kvm/vcpu.c
> +++ b/arch/riscv/kvm/vcpu.c
[ ... ]
> @@ -654,9 +656,11 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
> kvm_riscv_vcpu_host_fp_restore(&vcpu->arch.host_context);
>
> kvm_riscv_vcpu_timer_save(vcpu);
> + get_cpu_vector_context();
> kvm_riscv_vcpu_guest_vector_save(&vcpu->arch.guest_context,
> vcpu->arch.isa);
> kvm_riscv_vcpu_host_vector_restore(&vcpu->arch.host_context);
[Severity: High]
This is a pre-existing issue, but does unconditionally restoring the host
vector context here corrupt the kernel-mode vector state if the vCPU thread
is preempted?
If a vCPU thread enters a kernel-mode vector section (like
enter_vector_usercopy() during guest I/O) and is preempted by a page fault,
kvm_sched_out() calls kvm_arch_vcpu_put(). This unconditionally restores the
host (QEMU) vector registers via kvm_riscv_vcpu_host_vector_restore().
When switch_to() subsequently calls __switch_to_vector(), wouldn't it save
this newly clobbered hardware state into the kernel's vector context buffer
(kernel_vstate) instead of the actual kernel vector state?
Could a malicious guest trigger this by supplying an unmapped virtual address
for an I/O operation, forcing a page fault and voluntary preemption during
the vector-optimized copy_to_user()?
> + put_cpu_vector_context();
>
> if (kvm_riscv_nacl_available()) {
> nsh = nacl_shmem();
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260803215250.824417-1-tchiu@tenstorrent.com?part=3
prev parent reply other threads:[~2026-08-03 22:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 21:52 [PATCH v5 0/3] RISC-V: KVM: fix vcpu vector context handling Andy Chiu
2026-08-03 21:52 ` Andy Chiu
2026-08-03 21:52 ` Andy Chiu
2026-08-03 21:52 ` [PATCH v5 1/3] riscv: vector: refactor riscv_v_start_kernel_context Andy Chiu
2026-08-03 21:52 ` Andy Chiu
2026-08-03 21:52 ` [PATCH v5 2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off Andy Chiu
2026-08-03 21:52 ` Andy Chiu
2026-08-03 21:52 ` Andy Chiu
2026-08-03 21:52 ` [PATCH v5 3/3] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector Andy Chiu
2026-08-03 21:52 ` Andy Chiu
2026-08-03 21:52 ` Andy Chiu
2026-08-03 22:37 ` sashiko-bot [this message]
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=20260803223742.0C19C1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--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.