powerpc: Fix inconsistent Altivec handling in set_mcontext

When support for fpu_kern_enter/fpu_kern_leave was added to powerpc,
set_mcontext was updated to handle Altivec state restoration in the same
way that the FPU state by lazily restoring the context on the first
trap. However the function was not correctly updated to unconditionally
clear the PCB_VEC and PSL_VEC bits from the pcb's flags and srr1
respectively which can sometimes result in a mismatch between a
process's MSR[VEC] state and its pcb_flags.

Fix this by simply clearing the VEC flags unconditionally in
set_mcontext, which is already done for FPU/VSX.

Fixes: a6662c37b6 ("powerpc: Implement fpu_kern_enter/fpu_kern_leave")

Reviewed by:	alfredo
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D42417
This commit is contained in:
Shawn Anastasio 2023-11-03 14:40:18 -03:00 committed by Alfredo Dal'Ava Junior
parent 1f90b4edff
commit 270f75cf34

View file

@ -528,8 +528,8 @@ set_mcontext(struct thread *td, mcontext_t *mcp)
* Additionally, ensure VSX is disabled as well, as it is illegal
* to leave it turned on when FP or VEC are off.
*/
tf->srr1 &= ~(PSL_FP | PSL_VSX);
pcb->pcb_flags &= ~(PCB_FPU | PCB_VSX);
tf->srr1 &= ~(PSL_FP | PSL_VSX | PSL_VEC);
pcb->pcb_flags &= ~(PCB_FPU | PCB_VSX | PCB_VEC);
if (mcp->mc_flags & _MC_FP_VALID) {
/* enable_fpu() will happen lazily on a fault */
@ -550,9 +550,6 @@ set_mcontext(struct thread *td, mcontext_t *mcp)
pcb->pcb_vec.vscr = mcp->mc_vscr;
pcb->pcb_vec.vrsave = mcp->mc_vrsave;
memcpy(pcb->pcb_vec.vr, mcp->mc_avec, sizeof(mcp->mc_avec));
} else {
tf->srr1 &= ~PSL_VEC;
pcb->pcb_flags &= ~PCB_VEC;
}
return (0);