[PATCH] KVM: riscv: Implement kvm_arch_pre_fault_allowed()

Sasha Levin sashal at kernel.org
Thu Oct 22 07:42:16 PDT 2026


Commit caa63620f9e3 ("KVM: Allow architectures to disallow pre-fault")
requires every architecture that selects KVM_GENERIC_PRE_FAULT_MEMORY to
implement kvm_arch_pre_fault_allowed(), and there is no generic default.

Commit e8b32e377951 ("KVM: riscv: Implement KVM_PRE_FAULT_MEMORY") was
written before that hook existed, so it selects the option without
implementing the hook. With both commits in the same tree, riscv builds
with KVM enabled fail to link:

  ld.lld: error: undefined symbol: kvm_arch_pre_fault_allowed
  >>> referenced by kvm_main.c
  >>>               virt/kvm/kvm_main.o:(kvm_vcpu_pre_fault_memory) in archive vmlinux.a

The riscv implementation does not refuse pre-faulting in any state, so
return 0 to keep its current behaviour.

Fixes: e8b32e377951 ("KVM: riscv: Implement KVM_PRE_FAULT_MEMORY")
Signed-off-by: Sasha Levin <sashal at kernel.org>
---
Paolo, this is needed when kvm-riscv-7.4-1 is merged into kvm/next.
Feel free to squash it into the merge instead.

Mark, next-20261022 already fails to link, so linux-next needs this on
top of the kvm-riscv merge.

Build-tested with a riscv tinyconfig plus KVM=y on next-20261022 and on
kvm/next with kvm-riscv-7.4-1 merged. Not runtime tested.

 arch/riscv/kvm/mmu.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
index e8673cfa69668..738d9ee1eac9d 100644
--- a/arch/riscv/kvm/mmu.c
+++ b/arch/riscv/kvm/mmu.c
@@ -754,6 +754,11 @@ int kvm_riscv_mmu_map(struct kvm_vcpu *vcpu, struct kvm_memory_slot *memslot,
 	return ret;
 }
 
+int kvm_arch_pre_fault_allowed(struct kvm_vcpu *vcpu)
+{
+	return 0;
+}
+
 long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
 				    struct kvm_pre_fault_memory *range)
 {
-- 
2.53.0




More information about the linux-riscv mailing list