• Paul Burton's avatar
    MIPS: Force CPUs to lose FP context during mode switches · 6b832257
    Paul Burton authored
    Commit 9791554b ("MIPS,prctl: add PR_[GS]ET_FP_MODE prctl options
    for MIPS") added support for the PR_SET_FP_MODE prctl, which allows a
    userland program to modify its FP mode at runtime. This is most notably
    required if dynamic linking leads to the FP mode requirement changing at
    runtime from that indicated in the initial executable's ELF header. In
    order to avoid overhead in the general FP context restore code, it aimed
    to have threads in the process become unable to enable the FPU during a
    mode switch & have the thread calling the prctl syscall wait for all
    other threads in the process to be context switched at least once. Once
    that happens we can know that no thread in the process whose mode will
    be switched has live FP context, and it's safe to perform the mode
    switch. However in the (rare) case of modeswitches occurring in
    multithreaded programs this can lead to indeterminate delays for the
    thread invoking the prctl syscall, and the code monitoring for those
    context switches was woefully inadequate for all but the simplest cases.
    
    Fix this by broadcasting an IPI if other CPUs may have live FP context
    for an affected thread, with a handler causing those CPUs to relinquish
    their FPU ownership. Threads will then be allowed to continue running
    but will stall on the wait_on_atomic_t in enable_restore_fp_context if
    they attempt to use FP again whilst the mode switch is still in
    progress. The end result is less fragile poking at scheduler context
    switch counts & a more expedient completion of the mode switch.
    Signed-off-by: default avatarPaul Burton <paul.burton@imgtec.com>
    Fixes: 9791554b ("MIPS,prctl: add PR_[GS]ET_FP_MODE prctl options for MIPS")
    Reviewed-by: default avatarMaciej W. Rozycki <macro@imgtec.com>
    Cc: Adam Buchbinder <adam.buchbinder@gmail.com>
    Cc: James Hogan <james.hogan@imgtec.com>
    Cc: stable <stable@vger.kernel.org> # v4.0+
    Cc: linux-mips@linux-mips.org
    Cc: linux-kernel@vger.kernel.org
    Patchwork: https://patchwork.linux-mips.org/patch/13145/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
    6b832257
process.c 15.9 KB