Skip to contentSkip to conversation

RISC-V: KVM: Fix builds without CONFIG_RISCV_ISA_V

PATCH In review slack up 3 participants 3 messages Oct 21 – Nov 13

Subsystems (4)
lore
Share & tools
lore

slack up

author
#0 lore raw

PATCH 1/1 RISC-V: KVM: Fix builds without CONFIG_RISCV_ISA_V

From: Xiaochun Yu <[email protected]>

Commit b5060a4aa33d ("RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector") made the KVM vCPU load and put paths call get_cpu_vector_context() and put_cpu_vector_context() unconditionally. It also added an unconditional call to __kvm_riscv_vector_restore() on the guest entry path.

The no-op definitions of the first two helpers live in <asm/vector.h>, but <asm/kvm_vcpu_vector.h> includes that header only when CONFIG_RISCV_ISA_V is enabled. The KVM header also does not provide a no-op __kvm_riscv_vector_restore() in its disabled branch. As a result, a KVM build without CONFIG_RISCV_ISA_V fails with missing helper declarations.

Include <asm/vector.h> unconditionally to reuse its existing no-op helpers, and provide the missing KVM restore stub when Vector support is disabled. This does not change the Vector-enabled path.

Fixes b5060a4aa33d ("RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector")

---
This single patch fixes a build regression when KVM is enabled without the RISC-V Vector extension.

Tested on base a804c5742bff (Torvalds master):

- CONFIG_RISCV_ISA_V=n, CONFIG_KVM=m: full Image modules build passed.
- CONFIG_RISCV_ISA_V=y, CONFIG_KVM=m: vcpu.o and vcpu_vector.o rebuilt.

---
 arch/riscv/include/asm/kvm_vcpu_vector.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/riscv/include/asm/kvm_vcpu_vector.h +5 -1
index 6371d5ea5392..ebc619ed67dd 100644
@@ -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 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: a804c5742bff224d4cb4d25dd383554d598be32b
change-id: 20261021-ospp-c1-b4-submit-e22dc09faf5a

Best regards,

Signature · 1 line
slack up <[email protected]>
Tested-by on v1 1/1
#1 lore raw
Quoted 22 lines · slack up

From: Xiaochun Yu <[email protected]>

Commit b5060a4aa33d ("RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector") made the KVM vCPU load and put paths call get_cpu_vector_context() and put_cpu_vector_context() unconditionally. It also added an unconditional call to __kvm_riscv_vector_restore() on the guest entry path.

The no-op definitions of the first two helpers live in <asm/vector.h>, but <asm/kvm_vcpu_vector.h> includes that header only when CONFIG_RISCV_ISA_V is enabled. The KVM header also does not provide a no-op __kvm_riscv_vector_restore() in its disabled branch. As a result, a KVM build without CONFIG_RISCV_ISA_V fails with missing helper declarations.

Include <asm/vector.h> unconditionally to reuse its existing no-op helpers, and provide the missing KVM restore stub when Vector support is disabled. This does not change the Vector-enabled path.

Fixes b5060a4aa33d ("RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector")
Quoted 8 lines

---
This single patch fixes a build regression when KVM is enabled without the RISC-V Vector extension.

Tested on base a804c5742bff (Torvalds master):

- CONFIG_RISCV_ISA_V=n, CONFIG_KVM=m: full Image modules build passed.
- CONFIG_RISCV_ISA_V=y, CONFIG_KVM=m: vcpu.o and vcpu_vector.o rebuilt.

Tested on commit a804c5742bff with gcc 16.2.1 and clang 23.1.3:

CONFIG_RISCV_ISA_V=n, CONFIG_KVM=m: full Image + modules build passes (before the patch: 3 implicit-declaration errors with gcc, 5 with clang)

Quoted 36 lines
---
 arch/riscv/include/asm/kvm_vcpu_vector.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/riscv/include/asm/kvm_vcpu_vector.h +5 -2
index 6371d5ea5392..ebc619ed67dd 100644
@@ -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 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: a804c5742bff224d4cb4d25dd383554d598be32b
change-id: 20261021-ospp-c1-b4-submit-e22dc09faf5a

Best regards,

maintainer
#2 lore raw
In reply to slack up
Quoted 16 lines · slack up

From: Xiaochun Yu <[email protected]>

Commit b5060a4aa33d ("RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector") made the KVM vCPU load and put paths call get_cpu_vector_context() and put_cpu_vector_context() unconditionally. It also added an unconditional call to __kvm_riscv_vector_restore() on the guest entry path.

The no-op definitions of the first two helpers live in <asm/vector.h>, but <asm/kvm_vcpu_vector.h> includes that header only when CONFIG_RISCV_ISA_V is enabled. The KVM header also does not provide a no-op __kvm_riscv_vector_restore() in its disabled branch. As a result, a KVM build without CONFIG_RISCV_ISA_V fails with missing helper declarations.

Quoted 7 lines

Include <asm/vector.h> unconditionally to reuse its existing no-op helpers, and provide the missing KVM restore stub when Vector support is disabled. This does not change the Vector-enabled path.

Fixes b5060a4aa33d ("RISC-V: KVM: fix vcpu vector context handling for kernel-mode vector")

A similar fix from Zhanpeng Zhang is already merged.
https://lore.kernel.org/r/[email protected]

Regards,
Anup

Quoted 47 lines

---
This single patch fixes a build regression when KVM is enabled without the RISC-V Vector extension.

Tested on base a804c5742bff (Torvalds master):

- CONFIG_RISCV_ISA_V=n, CONFIG_KVM=m: full Image modules build passed.
- CONFIG_RISCV_ISA_V=y, CONFIG_KVM=m: vcpu.o and vcpu_vector.o rebuilt.

---
 arch/riscv/include/asm/kvm_vcpu_vector.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/riscv/include/asm/kvm_vcpu_vector.h +5 -2
index 6371d5ea5392..ebc619ed67dd 100644
@@ -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 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: a804c5742bff224d4cb4d25dd383554d598be32b
change-id: 20261021-ospp-c1-b4-submit-e22dc09faf5a

Best regards,
--
slack up <[email protected]>