git: 16caf6a11ec2 - stable/14 - powerpc: Add Hypervisor Facility Unavailable handling

From: Justin Hibbits <jhibbits_at_FreeBSD.org>
Date: Fri, 28 Mar 2025 02:32:29 UTC
The branch stable/14 has been updated by jhibbits:

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

commit 16caf6a11ec25d705514e31920c2a3d1bde0fb04
Author:     Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2025-03-19 22:22:32 +0000
Commit:     Justin Hibbits <jhibbits@FreeBSD.org>
CommitDate: 2025-03-28 02:32:19 +0000

    powerpc: Add Hypervisor Facility Unavailable handling
    
    Treat Hypervisor Facility Unavailable as an illegal instruction in user
    space.  This way programs that use facilities like transactional memory,
    which will never be supported as it has been removed from the ISA, will
    not crash the kernel.
    
    Tested by:      pkubaj
    MFC after:      1 week
    
    (cherry picked from commit 0b663e0cee89dedf5b070ff4e839d5ad95061535)
---
 sys/powerpc/aim/aim_machdep.c | 1 +
 sys/powerpc/powerpc/trap.c    | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/sys/powerpc/aim/aim_machdep.c b/sys/powerpc/aim/aim_machdep.c
index b439905441d3..814c679ff47e 100644
--- a/sys/powerpc/aim/aim_machdep.c
+++ b/sys/powerpc/aim/aim_machdep.c
@@ -417,6 +417,7 @@ aim_cpu_init(vm_offset_t toc)
 	bcopy(&hypertrapcode, (void *)(EXC_HEA + trap_offset), trapsize);
 	bcopy(&hypertrapcode, (void *)(EXC_HMI + trap_offset), trapsize);
 	bcopy(&hypertrapcode, (void *)(EXC_HVI + trap_offset), trapsize);
+	bcopy(&hypertrapcode, (void *)(EXC_HFAC + trap_offset), trapsize);
 	bcopy(&hypertrapcode, (void *)(EXC_SOFT_PATCH + trap_offset), trapsize);
 	#endif
 
diff --git a/sys/powerpc/powerpc/trap.c b/sys/powerpc/powerpc/trap.c
index 7f1a267f5cf2..dae1228c30fa 100644
--- a/sys/powerpc/powerpc/trap.c
+++ b/sys/powerpc/powerpc/trap.c
@@ -139,6 +139,7 @@ static struct powerpc_exception powerpc_exceptions[] = {
 	{ EXC_VEC,	"altivec unavailable" },
 	{ EXC_VSX,	"vsx unavailable" },
 	{ EXC_FAC,	"facility unavailable" },
+	{ EXC_HFAC,	"hypervisor facility unavailable" },
 	{ EXC_ITMISS,	"instruction tlb miss" },
 	{ EXC_DLMISS,	"data load tlb miss" },
 	{ EXC_DSMISS,	"data store tlb miss" },
@@ -148,6 +149,7 @@ static struct powerpc_exception powerpc_exceptions[] = {
 	{ EXC_THRM,	"thermal management" },
 	{ EXC_RUNMODETRC,	"run mode/trace" },
 	{ EXC_SOFT_PATCH, "soft patch exception" },
+	{ EXC_HVI,	"hypervisor virtualization" },
 	{ EXC_LAST,	NULL }
 };
 
@@ -352,6 +354,7 @@ trap(struct trapframe *frame)
 			mtspr(SPR_FSCR, fscr & ~FSCR_IC_MASK);
 			break;
 		case EXC_HEA:
+		case EXC_HFAC:
 			sig = SIGILL;
 			ucode =	ILL_ILLOPC;
 			break;