git: e51ed89897da - main - bhyve/aarch64: Handle unknown exceptions

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Tue, 15 Oct 2024 17:25:17 UTC
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=e51ed89897da9b940bb4399427aec398dae96fba

commit e51ed89897da9b940bb4399427aec398dae96fba
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2024-10-14 14:39:29 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2024-10-15 17:24:42 +0000

    bhyve/aarch64: Handle unknown exceptions
    
    When an exception class is unhandled by the kernel we handle it in
    userspace by exiting the process. Rather than exiting raise an unknown
    reason exception in the guest. The guest can then handle the exception
    as it wishes.
    
    Reviewed by:    markj
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D46511
---
 usr.sbin/bhyve/aarch64/vmexit.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/usr.sbin/bhyve/aarch64/vmexit.c b/usr.sbin/bhyve/aarch64/vmexit.c
index e1a9509d5d12..9ecf25c04e41 100644
--- a/usr.sbin/bhyve/aarch64/vmexit.c
+++ b/usr.sbin/bhyve/aarch64/vmexit.c
@@ -263,15 +263,15 @@ vmexit_smccc(struct vmctx *ctx, struct vcpu *vcpu, struct vm_run *vmrun)
 }
 
 static int
-vmexit_hyp(struct vmctx *ctx __unused, struct vcpu *vcpu __unused,
-    struct vm_run *vmrun)
+vmexit_hyp(struct vmctx *ctx __unused, struct vcpu *vcpu, struct vm_run *vmrun)
 {
-	struct vm_exit *vme;
+	/* Raise an unknown reason exception */
+	if (vm_inject_exception(vcpu,
+	    (EXCP_UNKNOWN << ESR_ELx_EC_SHIFT) | ESR_ELx_IL,
+	    vmrun->vm_exit->u.hyp.far_el2) != 0)
+		return (VMEXIT_ABORT);
 
-	vme = vmrun->vm_exit;
-	printf("unhandled exception: esr %#lx, far %#lx\n",
-	    vme->u.hyp.esr_el2, vme->u.hyp.far_el2);
-	return (VMEXIT_ABORT);
+	return (VMEXIT_CONTINUE);
 }
 
 static int