[PATCH] RISC-V: KVM: Fix build with vector support disabled

Zhanpeng Zhang zhangzhanpeng.jasper at bytedance.com
Mon Sep 21 19:18:24 PDT 2026


The kernel-mode vector context handling added unconditional calls to
get_cpu_vector_context(), put_cpu_vector_context() and
__kvm_riscv_vector_restore() in vcpu.c. With CONFIG_RISCV_ISA_V=n, these
calls fail to build due to missing declarations.

The get/put helpers already have no-op definitions in asm/vector.h, but
kvm_vcpu_vector.h only includes that header when CONFIG_RISCV_ISA_V is
enabled. Include it unconditionally and provide a no-op implementation
of __kvm_riscv_vector_restore() for the disabled configuration, matching
the other vector context helpers.

The paths that set RISCV_V_VCPU_NEED_RESTORE are compiled out when vector
support is disabled, so the restore stub does not discard any live
vector state. Keep it __always_inline for its noinstr caller. The vector
enabled implementation is unchanged.

Fixes: b5060a4aa33d ("RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector")
Signed-off-by: Zhanpeng Zhang <zhangzhanpeng.jasper at bytedance.com>
---
 arch/riscv/include/asm/kvm_vcpu_vector.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/include/asm/kvm_vcpu_vector.h b/arch/riscv/include/asm/kvm_vcpu_vector.h
index 6371d5ea5392..50d4789b9cac 100644
--- a/arch/riscv/include/asm/kvm_vcpu_vector.h
+++ b/arch/riscv/include/asm/kvm_vcpu_vector.h
@@ -11,9 +11,9 @@
 #define __KVM_VCPU_RISCV_VECTOR_H
 
 #include <linux/types.h>
+#include <asm/vector.h>
 
 #ifdef CONFIG_RISCV_ISA_V
-#include <asm/vector.h>
 #include <asm/kvm_host.h>
 
 static __always_inline void __kvm_riscv_vector_save(struct kvm_cpu_context *context)
@@ -55,6 +55,10 @@ static inline void kvm_riscv_v_exit(void)
 
 struct kvm_cpu_context;
 
+static __always_inline void __kvm_riscv_vector_restore(struct kvm_cpu_context *context)
+{
+}
+
 static inline void kvm_riscv_vcpu_vector_reset(struct kvm_vcpu *vcpu)
 {
 }

base-commit: 93f51579e7df248780214094418f205253383cc5
-- 
2.50.1 (Apple Git-155)




More information about the linux-riscv mailing list