Skip to content

[PW_SID:1125685] RISC-V: KVM: fix vcpu vector context handling#2261

Closed
linux-riscv-bot wants to merge 3 commits into
workflow__riscv__fixesfrom
pw1125685
Closed

[PW_SID:1125685] RISC-V: KVM: fix vcpu vector context handling#2261
linux-riscv-bot wants to merge 3 commits into
workflow__riscv__fixesfrom
pw1125685

Conversation

@linux-riscv-bot

Copy link
Copy Markdown

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

Linux RISC-V bot and others added 3 commits July 11, 2026 01:54
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>
@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 142.20 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1446.38 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1721.83 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 26.83 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.84 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.80 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 88.32 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
kdoc
Desc: Detects for kdoc errors
Duration: 0.84 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
module-param
Desc: Detect module_param changes
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v1,1/2] riscv: vector: refactor riscv_v_start_kernel_context"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.32 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 142.46 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 2393.75 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 3073.98 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 26.47 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 28.00 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.96 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 88.29 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
kdoc
Desc: Detects for kdoc errors
Duration: 0.94 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
module-param
Desc: Detect module_param changes
Duration: 0.27 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.29 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v1,2/2] RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.32 seconds
Result: PASS

@linux-riscv-bot
linux-riscv-bot force-pushed the workflow__riscv__fixes branch 3 times, most recently from f54dc6c to f61148d Compare July 15, 2026 03:51
@linux-riscv-bot
linux-riscv-bot deleted the pw1125685 branch July 15, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants