Page MenuHomeFreeBSD

[PowerPC] Fix VSX context handling
ClosedPublic

Authored by bdragon on Feb 4 2020, 5:54 AM.

Details

Summary

In rS356767, memcpy/memmove/bcopy optimizations were added to libc to improve performance.

This exposed an existing kernel issue in VSX handling. The PSL_VSX flag was not being excluded from the psl_userstatic set, which meant that any thread that used these and then called swapcontext(3) would get an EINVAL error.

While here, add some comments to try and explain psl_userstatic / psl_userset / psl_userset32 better, as well as add a better comment for the r344123 fix.

Test Plan

This issue can be seen in the libthr tests kill_test:simple, sigmask_test:respected_while_running, and swapcontext_test:swapcontext1, as well as in rust.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

ah, misread IRC, it was luporl who jhibbits was asking regarding debugging rust.

Nice, thanks for debugging this issue and documenting psl_userstatic / psl_userset.

sys/powerpc/aim/aim_machdep.c
258 ↗(On Diff #67758)

s/requried/required/

This revision is now accepted and ready to land.Feb 4 2020, 12:44 PM

Adding Renato Riolino, as he is investigating failing PowerPC tests and this fixes some of them.

Rust has started to build and cargo didn't crash (it crashed before right at the start) so I guess it's ok to commit, but I'll try to build all the ports that failed because of this bug to be sure (rust, openjdk8, openjdk11, ghc).

pkubaj requested changes to this revision.Feb 4 2020, 1:44 PM

Hm, no, it's not ok:

db> bt
Tracing pid 64293 tid 101836 td 0xc0000000bfb13560
0xe0000000f142c530: at vpanic+0x208
0xe0000000f142c5e0: at panic+0x40
0xe0000000f142c610: at trap+0x123c
0xe0000000f142c750: at powerpc_interrupt+0x1b8
0xe0000000f142c7e0: user VSX trap by 0x804347f1c: srr1=0x900000000200d032
            r1=0x3fffffffddffa980 cr=0x44c00082 xer=0 ctr=0x16 r2=0x804364378 frame=0xe0000000f142c810
db> show panic
panic: VSX already enabled for thread
This revision now requires changes to proceed.Feb 4 2020, 1:44 PM
sys/powerpc/powerpc/exec_machdep.c
501–502 ↗(On Diff #67758)

@pkubaj, maybe this change fixes the issue you're seeing:
tf->srr1 &= ~(PSL_FP | PSL_VSX);
pcb->pcb_flags &= ~(PCB_FPU | PCB_VSX);

sys/powerpc/powerpc/exec_machdep.c
501–502 ↗(On Diff #67758)

I *almost* went for doing that to start with, but I figured there might be a reason for the change to be FP only.

Given the kernel crash, it looks like we should definitely be doing ~(PSL_FP | PSL_VEC | PSL_VSX)

Fix typos.

Always disable VSX when disabling FP.

For now looks good, but rust is still building, and then I'll also test openjdk8, openjdk11 and ghc.

This revision is now accepted and ready to land.Feb 4 2020, 8:38 PM
This revision was automatically updated to reflect the committed changes.