[PW_SID:1125685] RISC-V: KVM: fix vcpu vector context handling#2261
[PW_SID:1125685] RISC-V: KVM: fix vcpu vector context handling#2261linux-riscv-bot wants to merge 3 commits into
Conversation
Refactor riscv_v_start_kernel_context() to drop `is_nested` variable and simplify the logic. This introduces no functional change and works as a preparatory patch for the kernel-mode vector fix. Signed-off-by: Andy Chiu <tchiu@tenstorrent.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Running vector workloads like perf + mcf on KVM can result in an
unexpected termination due to a vtype corruption. This happens because
the kernel-mode vector (KMV) misattributes the guest's vcpu context as
the user's context and source from a wrong status.VS.
The simplified call chain that results in this problem is shown as
follow:
__riscv_sys_ioctl()
kvm_arch_vcpu_ioctl_run()
kvm_riscv_vcpu_exit()
kvm_riscv_vcpu_sbi_ecall()
kvm_riscv_vcpu_pmu_ctr_stop()
kvm_vcpu_write_guest()
__copy_to_user()
enter_vector_usercopy()
kernel_vector_begin()
kernel_vector_begin() should use the sstatus.VS from guest's vcpu
context instead of task_pt_reg(current). Also, it should not save
guest's v-reg into the user's context memory.
To resolve this, the vcpu context must be correctly saved when KMV is
serving a guest. However, invoking KVM functions directly from generic
RISC-V architecture code introduces a reverse dependency, breaking
builds when KVM is configured as N or M.
Address this by registering an RCU-protected callback for context
flushing. KVM registers this callback at module initialization and
unregisters it on exit. When KMV starts a kernel context, it can now
safely flush the vector context via the callback.
Fixes: ecd2ada ("riscv: Add support for kernel mode vector")
Signed-off-by: Andy Chiu <tchiu@tenstorrent.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
|
Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector" |
f54dc6c to
f61148d
Compare
PR for series 1125685 applied to workflow__riscv__fixes
Name: RISC-V: KVM: fix vcpu vector context handling
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1125685
Version: 1