]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/2.6.32.17/math-emu-correct-test-for-downshifting-fraction-in-_fp_from_int.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 2.6.32.17 / math-emu-correct-test-for-downshifting-fraction-in-_fp_from_int.patch
CommitLineData
a0402406
GKH
1From f8324e20f8289dffc646d64366332e05eaacab25 Mon Sep 17 00:00:00 2001
2From: Mikael Pettersson <mikpe@it.uu.se>
3Date: Tue, 20 Jul 2010 18:45:14 -0700
4Subject: math-emu: correct test for downshifting fraction in _FP_FROM_INT()
5
6From: Mikael Pettersson <mikpe@it.uu.se>
7
8commit f8324e20f8289dffc646d64366332e05eaacab25 upstream.
9
10The kernel's math-emu code contains a macro _FP_FROM_INT() which is
11used to convert an integer to a raw normalized floating-point value.
12It does this basically in three steps:
13
141. Compute the exponent from the number of leading zero bits.
152. Downshift large fractions to put the MSB in the right position
16 for normalized fractions.
173. Upshift small fractions to put the MSB in the right position.
18
19There is an boundary error in step 2, causing a fraction with its
20MSB exactly one bit above the normalized MSB position to not be
21downshifted. This results in a non-normalized raw float, which when
22packed becomes a massively inaccurate representation for that input.
23
24The impact of this depends on a number of arch-specific factors,
25but it is known to have broken emulation of FXTOD instructions
26on UltraSPARC III, which was originally reported as GCC bug 44631
27<http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44631>.
28
29Any arch which uses math-emu to emulate conversions from integers to
30same-size floats may be affected.
31
32The fix is simple: the exponent comparison used to determine if the
33fraction should be downshifted must be "<=" not "<".
34
35I'm sending a kernel module to test this as a reply to this message.
36There are also SPARC user-space test cases in the GCC bug entry.
37
38Signed-off-by: Mikael Pettersson <mikpe@it.uu.se>
39Signed-off-by: David S. Miller <davem@davemloft.net>
40Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
41
42---
43 include/math-emu/op-common.h | 2 +-
44 1 file changed, 1 insertion(+), 1 deletion(-)
45
46--- a/include/math-emu/op-common.h
47+++ b/include/math-emu/op-common.h
48@@ -799,7 +799,7 @@ do { \
49 X##_e -= (_FP_W_TYPE_SIZE - rsize); \
50 X##_e = rsize - X##_e - 1; \
51 \
52- if (_FP_FRACBITS_##fs < rsize && _FP_WFRACBITS_##fs < X##_e) \
53+ if (_FP_FRACBITS_##fs < rsize && _FP_WFRACBITS_##fs <= X##_e) \
54 __FP_FRAC_SRS_1(ur_, (X##_e - _FP_WFRACBITS_##fs + 1), rsize);\
55 _FP_FRAC_DISASSEMBLE_##wc(X, ur_, rsize); \
56 if ((_FP_WFRACBITS_##fs - X##_e - 1) > 0) \