Skip to contentSkip to conversation

RISC-V: KVM: Delegate illegal instruction fault to VS mode

PATCH In review Xu Lu 2 participants 2 messages Jul 14, 2025 – Jul 16, 2025

Subsystems (3)
lore
Share & tools
lore

Xu Lu

author
#0 lore raw

PATCH v4 1/1 RISC-V: KVM: Delegate illegal instruction fault to VS mode

Delegate illegal instruction fault to VS mode by default to avoid such exceptions being trapped to HS and redirected back to VS.

The delegation of illegal instruction fault is particularly important to guest applications that use vector instructions frequently. In such cases, an illegal instruction fault will be raised when guest user thread uses vector instruction the first time and then guest kernel will enable user thread to execute following vector instructions.

The fw pmu event counter remains undeleted so that guest can still query illegal instruction events via sbi call. Guest will only see zero count on illegal instruction faults and know 'firmware' has delegated it.

---
 arch/riscv/include/asm/kvm_host.h | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/include/asm/kvm_host.h +1 -0
index 85cfebc32e4cf..3f6b9270f366a 100644
@@ -44,6 +44,7 @@
 #define KVM_REQ_STEAL_UPDATE		KVM_ARCH_REQ(6)
 
 #define KVM_HEDELEG_DEFAULT		(BIT(EXC_INST_MISALIGNED) | \
+					 BIT(EXC_INST_ILLEGAL)     | \
 					 BIT(EXC_BREAKPOINT)      | \
 					 BIT(EXC_SYSCALL)         | \
 					 BIT(EXC_INST_PAGE_FAULT) | \
Signature · 1 line
2.20.1
maintainer Reviewed-by on v4 1/1
#1 lore raw
Quoted 10 lines · Xu Lu

Delegate illegal instruction fault to VS mode by default to avoid such exceptions being trapped to HS and redirected back to VS.

The delegation of illegal instruction fault is particularly important to guest applications that use vector instructions frequently. In such cases, an illegal instruction fault will be raised when guest user thread uses vector instruction the first time and then guest kernel will enable user thread to execute following vector instructions.

Quoted 5 lines

The fw pmu event counter remains undeleted so that guest can still query illegal instruction events via sbi call. Guest will only see zero count on illegal instruction faults and know 'firmware' has delegated it.

LGTM.

Queued this patch for Linux-6.17

Thanks,
Anup

Quoted 19 lines
---
 arch/riscv/include/asm/kvm_host.h | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/include/asm/kvm_host.h +1 -1
index 85cfebc32e4cf..3f6b9270f366a 100644
@@ -44,6 +44,7 @@
 #define KVM_REQ_STEAL_UPDATE           KVM_ARCH_REQ(6)
 
 #define KVM_HEDELEG_DEFAULT            (BIT(EXC_INST_MISALIGNED) | \
+                                        BIT(EXC_INST_ILLEGAL)     | \
                                         BIT(EXC_BREAKPOINT)      | \
                                         BIT(EXC_SYSCALL)         | \
                                         BIT(EXC_INST_PAGE_FAULT) | \
--

2.20.1