Skip to content

Commit 0d071fa

Browse files
paulburtonralfbaechle
authored andcommitted
MIPS: Indicate FP mode in sigcontext sc_used_math
The sc_used_math field of struct sigcontext & its variants has traditionally been used as a boolean value indicating only whether or not floating point context is saved within the sigcontext. With various supported FP modes & the ability to switch between them this information will no longer be enough to decode the meaning of the data stored in the sc_fpregs fields of struct sigcontext. To make that possible 3 bits are defined within sc_used_math: - Bit 0 (USED_FP) represents whether FP was used, essentially providing the boolean flag which sc_used_math as a whole provided previously. - Bit 1 (USED_FR1) provides the value of the Status.FR bit at the time the FP context was saved. - Bit 2 (USED_HYBRID_FPRS) indicates whether the FP context was saved under the hybrid FPR scheme. Essentially, when set the odd singles are located in bits 63:32 of the preceding even indexed sc_fpregs element. Any userland that tests whether the sc_used_math field is zero or non-zero will continue to function as expected. Having said that, I could not find any userland which uses the sc_used_math field at all. [ralf@linux-mips.org: Fixed rejects.] Signed-off-by: Paul Burton <paul.burton@imgtec.com> Cc: linux-mips@linux-mips.org Cc: Guenter Roeck <linux@roeck-us.net> Cc: Matthew Fortune <matthew.fortune@imgtec.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: linux-kernel@vger.kernel.org Cc: Richard Weinberger <richard@nod.at> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Maciej W. Rozycki <macro@codesourcery.com> Patchwork: https://patchwork.linux-mips.org/patch/10794/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 6a24432 commit 0d071fa

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎arch/mips/include/uapi/asm/sigcontext.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
#include <linux/types.h>
1313
#include <asm/sgidefs.h>
1414

15+
/* scalar FP context was used */
16+
#define USED_FP (1 << 0)
17+
18+
/* the value of Status.FR when context was saved */
19+
#define USED_FR1 (1 << 1)
20+
21+
/* FR=1, but with odd singles in bits 63:32 of preceding even double */
22+
#define USED_HYBRID_FPRS (1 << 2)
23+
1524
#if _MIPS_SIM == _MIPS_SIM_ABI32
1625

1726
/*

‎arch/mips/kernel/signal.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,16 @@ int protected_save_fp_context(void __user *sc)
133133
unsigned int used;
134134
int err;
135135

136-
used = !!used_math();
136+
used = used_math() ? USED_FP : 0;
137+
if (used) {
138+
if (!test_thread_flag(TIF_32BIT_FPREGS))
139+
used |= USED_FR1;
140+
if (test_thread_flag(TIF_HYBRID_FPREGS))
141+
used |= USED_HYBRID_FPRS;
142+
}
143+
137144
err = __put_user(used, used_math);
138-
if (err || !used)
145+
if (err || !(used & USED_FP))
139146
return err;
140147

141148
/*
@@ -177,13 +184,13 @@ int protected_restore_fp_context(void __user *sc)
177184
int err, sig, tmp __maybe_unused;
178185

179186
err = __get_user(used, used_math);
180-
conditional_used_math(used);
187+
conditional_used_math(used & USED_FP);
181188

182189
/*
183190
* The signal handler may have used FPU; give it up if the program
184191
* doesn't want it following sigreturn.
185192
*/
186-
if (err || !used) {
193+
if (err || !(used & USED_FP)) {
187194
lose_fpu(0);
188195
return err;
189196
}

0 commit comments

Comments
 (0)