Skip to content

[PW_SID:1127876] RISC-V: KVM: fix vcpu vector context handling#2288

Open
linux-riscv-bot wants to merge 5 commits into
workflow__riscv__fixesfrom
pw1127876
Open

[PW_SID:1127876] RISC-V: KVM: fix vcpu vector context handling#2288
linux-riscv-bot wants to merge 5 commits into
workflow__riscv__fixesfrom
pw1127876

Conversation

@linux-riscv-bot

Copy link
Copy Markdown

PR for series 1127876 applied to workflow__riscv__fixes

Name: RISC-V: KVM: fix vcpu vector context handling
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1127876
Version: 2

Paul Sherman and others added 5 commits July 14, 2026 19:39
setup_smp() calls set_cpu_possible() for CPUs 1..nr_cpu_ids-1 but
never for CPU 0 (the boot CPU). x86 handles this via
init_cpu_possible(cpumask_of(0)); RISC-V has no equivalent.

Without CPU 0 in cpu_possible_mask, rcu_init_one()'s
for_each_possible_cpu() loop skips it, leaving rdp->mynode=NULL.
rcutree_prepare_cpu() then dereferences NULL and hangs.

Exposed on Sophgo SG2042 (64-hart, 4-NUMA) with Linux 7.2-rc3.

Cc: stable@vger.kernel.org
Fixes: a4166ae ("riscv: Deduplicate code in setup_smp()")
Signed-off-by: Paul Sherman <shermanpauldylan@gmail.com>
Link: https://patch.msgid.link/20260714223301.5265-1-shermanpauldylan@gmail.com
Signed-off-by: Paul Walmsley <pjw@kernel.org>
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>
Similar to commit 7137a20 ("arm64/fpsimd: Permit kernel mode NEON
with IRQs off"), we are upgrading get/put_cpu_vector_context such that
kvm_arch_vcpu_load/put can be safely called under both irq off and
regular process context.

Also, export both symbols so kvm module can call into it.

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: "[v2,1/3] riscv: vector: refactor riscv_v_start_kernel_context"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 119.54 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] 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: 1423.54 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] 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: 1741.19 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: vector: refactor riscv_v_start_kernel_context"
kdoc
Desc: Detects for kdoc errors
Duration: 0.74 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: vector: refactor riscv_v_start_kernel_context"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 119.81 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1444.24 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1850.72 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 20.31 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 21.79 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.82 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 82.22 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
kdoc
Desc: Detects for kdoc errors
Duration: 0.75 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] 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: 2575.36 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] 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: 3130.58 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] 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: 20.49 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] 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: 22.14 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] 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.25 seconds
Result: PASS

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

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

@linux-riscv-bot

Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] 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.28 seconds
Result: PASS

@linux-riscv-bot
linux-riscv-bot force-pushed the workflow__riscv__fixes branch 4 times, most recently from 60e0882 to 36eafdd Compare July 21, 2026 01:54
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