Magellan Linux

Contents of /trunk/kernel-alx-legacy/patches-4.9/0151-4.9.52-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3608 - (show annotations) (download)
Fri Aug 14 07:34:29 2020 UTC (3 years, 8 months ago) by niro
File size: 123220 byte(s)
-added kerenl-alx-legacy pkg
1 diff --git a/Makefile b/Makefile
2 index b48aebbe187f..c53de1e38c6a 100644
3 --- a/Makefile
4 +++ b/Makefile
5 @@ -1,6 +1,6 @@
6 VERSION = 4
7 PATCHLEVEL = 9
8 -SUBLEVEL = 51
9 +SUBLEVEL = 52
10 EXTRAVERSION =
11 NAME = Roaring Lionus
12
13 diff --git a/arch/arc/kernel/entry.S b/arch/arc/kernel/entry.S
14 index 1eea99beecc3..85d9ea4a0acc 100644
15 --- a/arch/arc/kernel/entry.S
16 +++ b/arch/arc/kernel/entry.S
17 @@ -92,6 +92,12 @@ ENTRY(EV_MachineCheck)
18 lr r0, [efa]
19 mov r1, sp
20
21 + ; hardware auto-disables MMU, re-enable it to allow kernel vaddr
22 + ; access for say stack unwinding of modules for crash dumps
23 + lr r3, [ARC_REG_PID]
24 + or r3, r3, MMU_ENABLE
25 + sr r3, [ARC_REG_PID]
26 +
27 lsr r3, r2, 8
28 bmsk r3, r3, 7
29 brne r3, ECR_C_MCHK_DUP_TLB, 1f
30 diff --git a/arch/arc/mm/tlb.c b/arch/arc/mm/tlb.c
31 index bdb295e09160..a4dc881da277 100644
32 --- a/arch/arc/mm/tlb.c
33 +++ b/arch/arc/mm/tlb.c
34 @@ -896,9 +896,6 @@ void do_tlb_overlap_fault(unsigned long cause, unsigned long address,
35
36 local_irq_save(flags);
37
38 - /* re-enable the MMU */
39 - write_aux_reg(ARC_REG_PID, MMU_ENABLE | read_aux_reg(ARC_REG_PID));
40 -
41 /* loop thru all sets of TLB */
42 for (set = 0; set < mmu->sets; set++) {
43
44 diff --git a/arch/mips/math-emu/dp_fmax.c b/arch/mips/math-emu/dp_fmax.c
45 index fd71b8daaaf2..5bec64f2884e 100644
46 --- a/arch/mips/math-emu/dp_fmax.c
47 +++ b/arch/mips/math-emu/dp_fmax.c
48 @@ -47,14 +47,26 @@ union ieee754dp ieee754dp_fmax(union ieee754dp x, union ieee754dp y)
49 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
50 return ieee754dp_nanxcpt(x);
51
52 - /* numbers are preferred to NaNs */
53 + /*
54 + * Quiet NaN handling
55 + */
56 +
57 + /*
58 + * The case of both inputs quiet NaNs
59 + */
60 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
61 + return x;
62 +
63 + /*
64 + * The cases of exactly one input quiet NaN (numbers
65 + * are here preferred as returned values to NaNs)
66 + */
67 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
68 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
69 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
70 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
71 return x;
72
73 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
74 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
75 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
76 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
77 @@ -80,9 +92,7 @@ union ieee754dp ieee754dp_fmax(union ieee754dp x, union ieee754dp y)
78 return ys ? x : y;
79
80 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
81 - if (xs == ys)
82 - return x;
83 - return ieee754dp_zero(1);
84 + return ieee754dp_zero(xs & ys);
85
86 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
87 DPDNORMX;
88 @@ -106,16 +116,32 @@ union ieee754dp ieee754dp_fmax(union ieee754dp x, union ieee754dp y)
89 else if (xs < ys)
90 return x;
91
92 - /* Compare exponent */
93 - if (xe > ye)
94 - return x;
95 - else if (xe < ye)
96 - return y;
97 + /* Signs of inputs are equal, let's compare exponents */
98 + if (xs == 0) {
99 + /* Inputs are both positive */
100 + if (xe > ye)
101 + return x;
102 + else if (xe < ye)
103 + return y;
104 + } else {
105 + /* Inputs are both negative */
106 + if (xe > ye)
107 + return y;
108 + else if (xe < ye)
109 + return x;
110 + }
111
112 - /* Compare mantissa */
113 + /* Signs and exponents of inputs are equal, let's compare mantissas */
114 + if (xs == 0) {
115 + /* Inputs are both positive, with equal signs and exponents */
116 + if (xm <= ym)
117 + return y;
118 + return x;
119 + }
120 + /* Inputs are both negative, with equal signs and exponents */
121 if (xm <= ym)
122 - return y;
123 - return x;
124 + return x;
125 + return y;
126 }
127
128 union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
129 @@ -147,14 +173,26 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
130 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
131 return ieee754dp_nanxcpt(x);
132
133 - /* numbers are preferred to NaNs */
134 + /*
135 + * Quiet NaN handling
136 + */
137 +
138 + /*
139 + * The case of both inputs quiet NaNs
140 + */
141 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
142 + return x;
143 +
144 + /*
145 + * The cases of exactly one input quiet NaN (numbers
146 + * are here preferred as returned values to NaNs)
147 + */
148 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
149 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
150 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
151 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
152 return x;
153
154 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
155 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
156 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
157 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
158 @@ -164,6 +202,9 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
159 /*
160 * Infinity and zero handling
161 */
162 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
163 + return ieee754dp_inf(xs & ys);
164 +
165 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
166 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
167 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
168 @@ -171,7 +212,6 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
169 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
170 return x;
171
172 - case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
173 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
174 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
175 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
176 @@ -180,9 +220,7 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
177 return y;
178
179 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
180 - if (xs == ys)
181 - return x;
182 - return ieee754dp_zero(1);
183 + return ieee754dp_zero(xs & ys);
184
185 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
186 DPDNORMX;
187 @@ -207,7 +245,11 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
188 return y;
189
190 /* Compare mantissa */
191 - if (xm <= ym)
192 + if (xm < ym)
193 return y;
194 - return x;
195 + else if (xm > ym)
196 + return x;
197 + else if (xs == 0)
198 + return x;
199 + return y;
200 }
201 diff --git a/arch/mips/math-emu/dp_fmin.c b/arch/mips/math-emu/dp_fmin.c
202 index c1072b0dfb95..a287b23818d8 100644
203 --- a/arch/mips/math-emu/dp_fmin.c
204 +++ b/arch/mips/math-emu/dp_fmin.c
205 @@ -47,14 +47,26 @@ union ieee754dp ieee754dp_fmin(union ieee754dp x, union ieee754dp y)
206 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
207 return ieee754dp_nanxcpt(x);
208
209 - /* numbers are preferred to NaNs */
210 + /*
211 + * Quiet NaN handling
212 + */
213 +
214 + /*
215 + * The case of both inputs quiet NaNs
216 + */
217 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
218 + return x;
219 +
220 + /*
221 + * The cases of exactly one input quiet NaN (numbers
222 + * are here preferred as returned values to NaNs)
223 + */
224 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
225 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
226 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
227 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
228 return x;
229
230 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
231 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
232 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
233 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
234 @@ -80,9 +92,7 @@ union ieee754dp ieee754dp_fmin(union ieee754dp x, union ieee754dp y)
235 return ys ? y : x;
236
237 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
238 - if (xs == ys)
239 - return x;
240 - return ieee754dp_zero(1);
241 + return ieee754dp_zero(xs | ys);
242
243 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
244 DPDNORMX;
245 @@ -106,16 +116,32 @@ union ieee754dp ieee754dp_fmin(union ieee754dp x, union ieee754dp y)
246 else if (xs < ys)
247 return y;
248
249 - /* Compare exponent */
250 - if (xe > ye)
251 - return y;
252 - else if (xe < ye)
253 - return x;
254 + /* Signs of inputs are the same, let's compare exponents */
255 + if (xs == 0) {
256 + /* Inputs are both positive */
257 + if (xe > ye)
258 + return y;
259 + else if (xe < ye)
260 + return x;
261 + } else {
262 + /* Inputs are both negative */
263 + if (xe > ye)
264 + return x;
265 + else if (xe < ye)
266 + return y;
267 + }
268
269 - /* Compare mantissa */
270 + /* Signs and exponents of inputs are equal, let's compare mantissas */
271 + if (xs == 0) {
272 + /* Inputs are both positive, with equal signs and exponents */
273 + if (xm <= ym)
274 + return x;
275 + return y;
276 + }
277 + /* Inputs are both negative, with equal signs and exponents */
278 if (xm <= ym)
279 - return x;
280 - return y;
281 + return y;
282 + return x;
283 }
284
285 union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
286 @@ -147,14 +173,26 @@ union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
287 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
288 return ieee754dp_nanxcpt(x);
289
290 - /* numbers are preferred to NaNs */
291 + /*
292 + * Quiet NaN handling
293 + */
294 +
295 + /*
296 + * The case of both inputs quiet NaNs
297 + */
298 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
299 + return x;
300 +
301 + /*
302 + * The cases of exactly one input quiet NaN (numbers
303 + * are here preferred as returned values to NaNs)
304 + */
305 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
306 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
307 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
308 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
309 return x;
310
311 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
312 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
313 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
314 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
315 @@ -164,25 +202,25 @@ union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
316 /*
317 * Infinity and zero handling
318 */
319 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
320 + return ieee754dp_inf(xs | ys);
321 +
322 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
323 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
324 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
325 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
326 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
327 - return x;
328 + return y;
329
330 - case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
331 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
332 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
333 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
334 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
335 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
336 - return y;
337 + return x;
338
339 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
340 - if (xs == ys)
341 - return x;
342 - return ieee754dp_zero(1);
343 + return ieee754dp_zero(xs | ys);
344
345 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
346 DPDNORMX;
347 @@ -207,7 +245,11 @@ union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
348 return x;
349
350 /* Compare mantissa */
351 - if (xm <= ym)
352 + if (xm < ym)
353 + return x;
354 + else if (xm > ym)
355 + return y;
356 + else if (xs == 1)
357 return x;
358 return y;
359 }
360 diff --git a/arch/mips/math-emu/dp_maddf.c b/arch/mips/math-emu/dp_maddf.c
361 index 4a2d03c72959..e0d9be5fbf4c 100644
362 --- a/arch/mips/math-emu/dp_maddf.c
363 +++ b/arch/mips/math-emu/dp_maddf.c
364 @@ -14,22 +14,45 @@
365
366 #include "ieee754dp.h"
367
368 -enum maddf_flags {
369 - maddf_negate_product = 1 << 0,
370 -};
371 +
372 +/* 128 bits shift right logical with rounding. */
373 +void srl128(u64 *hptr, u64 *lptr, int count)
374 +{
375 + u64 low;
376 +
377 + if (count >= 128) {
378 + *lptr = *hptr != 0 || *lptr != 0;
379 + *hptr = 0;
380 + } else if (count >= 64) {
381 + if (count == 64) {
382 + *lptr = *hptr | (*lptr != 0);
383 + } else {
384 + low = *lptr;
385 + *lptr = *hptr >> (count - 64);
386 + *lptr |= (*hptr << (128 - count)) != 0 || low != 0;
387 + }
388 + *hptr = 0;
389 + } else {
390 + low = *lptr;
391 + *lptr = low >> count | *hptr << (64 - count);
392 + *lptr |= (low << (64 - count)) != 0;
393 + *hptr = *hptr >> count;
394 + }
395 +}
396
397 static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
398 union ieee754dp y, enum maddf_flags flags)
399 {
400 int re;
401 int rs;
402 - u64 rm;
403 unsigned lxm;
404 unsigned hxm;
405 unsigned lym;
406 unsigned hym;
407 u64 lrm;
408 u64 hrm;
409 + u64 lzm;
410 + u64 hzm;
411 u64 t;
412 u64 at;
413 int s;
414 @@ -48,52 +71,34 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
415
416 ieee754_clearcx();
417
418 - switch (zc) {
419 - case IEEE754_CLASS_SNAN:
420 - ieee754_setcx(IEEE754_INVALID_OPERATION);
421 + /*
422 + * Handle the cases when at least one of x, y or z is a NaN.
423 + * Order of precedence is sNaN, qNaN and z, x, y.
424 + */
425 + if (zc == IEEE754_CLASS_SNAN)
426 return ieee754dp_nanxcpt(z);
427 - case IEEE754_CLASS_DNORM:
428 - DPDNORMZ;
429 - /* QNAN is handled separately below */
430 - }
431 -
432 - switch (CLPAIR(xc, yc)) {
433 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
434 - case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
435 - case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
436 - case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
437 - case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
438 - return ieee754dp_nanxcpt(y);
439 -
440 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
441 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
442 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
443 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
444 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
445 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
446 + if (xc == IEEE754_CLASS_SNAN)
447 return ieee754dp_nanxcpt(x);
448 -
449 - case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
450 - case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
451 - case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
452 - case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
453 + if (yc == IEEE754_CLASS_SNAN)
454 + return ieee754dp_nanxcpt(y);
455 + if (zc == IEEE754_CLASS_QNAN)
456 + return z;
457 + if (xc == IEEE754_CLASS_QNAN)
458 + return x;
459 + if (yc == IEEE754_CLASS_QNAN)
460 return y;
461
462 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
463 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
464 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
465 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
466 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
467 - return x;
468 + if (zc == IEEE754_CLASS_DNORM)
469 + DPDNORMZ;
470 + /* ZERO z cases are handled separately below */
471
472 + switch (CLPAIR(xc, yc)) {
473
474 /*
475 * Infinity handling
476 */
477 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
478 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
479 - if (zc == IEEE754_CLASS_QNAN)
480 - return z;
481 ieee754_setcx(IEEE754_INVALID_OPERATION);
482 return ieee754dp_indef();
483
484 @@ -102,9 +107,27 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
485 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
486 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
487 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
488 - if (zc == IEEE754_CLASS_QNAN)
489 - return z;
490 - return ieee754dp_inf(xs ^ ys);
491 + if ((zc == IEEE754_CLASS_INF) &&
492 + ((!(flags & MADDF_NEGATE_PRODUCT) && (zs != (xs ^ ys))) ||
493 + ((flags & MADDF_NEGATE_PRODUCT) && (zs == (xs ^ ys))))) {
494 + /*
495 + * Cases of addition of infinities with opposite signs
496 + * or subtraction of infinities with same signs.
497 + */
498 + ieee754_setcx(IEEE754_INVALID_OPERATION);
499 + return ieee754dp_indef();
500 + }
501 + /*
502 + * z is here either not an infinity, or an infinity having the
503 + * same sign as product (x*y) (in case of MADDF.D instruction)
504 + * or product -(x*y) (in MSUBF.D case). The result must be an
505 + * infinity, and its sign is determined only by the value of
506 + * (flags & MADDF_NEGATE_PRODUCT) and the signs of x and y.
507 + */
508 + if (flags & MADDF_NEGATE_PRODUCT)
509 + return ieee754dp_inf(1 ^ (xs ^ ys));
510 + else
511 + return ieee754dp_inf(xs ^ ys);
512
513 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
514 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
515 @@ -113,32 +136,42 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
516 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
517 if (zc == IEEE754_CLASS_INF)
518 return ieee754dp_inf(zs);
519 - /* Multiplication is 0 so just return z */
520 + if (zc == IEEE754_CLASS_ZERO) {
521 + /* Handle cases +0 + (-0) and similar ones. */
522 + if ((!(flags & MADDF_NEGATE_PRODUCT)
523 + && (zs == (xs ^ ys))) ||
524 + ((flags & MADDF_NEGATE_PRODUCT)
525 + && (zs != (xs ^ ys))))
526 + /*
527 + * Cases of addition of zeros of equal signs
528 + * or subtraction of zeroes of opposite signs.
529 + * The sign of the resulting zero is in any
530 + * such case determined only by the sign of z.
531 + */
532 + return z;
533 +
534 + return ieee754dp_zero(ieee754_csr.rm == FPU_CSR_RD);
535 + }
536 + /* x*y is here 0, and z is not 0, so just return z */
537 return z;
538
539 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
540 DPDNORMX;
541
542 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
543 - if (zc == IEEE754_CLASS_QNAN)
544 - return z;
545 - else if (zc == IEEE754_CLASS_INF)
546 + if (zc == IEEE754_CLASS_INF)
547 return ieee754dp_inf(zs);
548 DPDNORMY;
549 break;
550
551 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
552 - if (zc == IEEE754_CLASS_QNAN)
553 - return z;
554 - else if (zc == IEEE754_CLASS_INF)
555 + if (zc == IEEE754_CLASS_INF)
556 return ieee754dp_inf(zs);
557 DPDNORMX;
558 break;
559
560 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
561 - if (zc == IEEE754_CLASS_QNAN)
562 - return z;
563 - else if (zc == IEEE754_CLASS_INF)
564 + if (zc == IEEE754_CLASS_INF)
565 return ieee754dp_inf(zs);
566 /* fall through to real computations */
567 }
568 @@ -157,7 +190,7 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
569
570 re = xe + ye;
571 rs = xs ^ ys;
572 - if (flags & maddf_negate_product)
573 + if (flags & MADDF_NEGATE_PRODUCT)
574 rs ^= 1;
575
576 /* shunt to top of word */
577 @@ -165,7 +198,7 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
578 ym <<= 64 - (DP_FBITS + 1);
579
580 /*
581 - * Multiply 64 bits xm, ym to give high 64 bits rm with stickness.
582 + * Multiply 64 bits xm and ym to give 128 bits result in hrm:lrm.
583 */
584
585 /* 32 * 32 => 64 */
586 @@ -195,78 +228,110 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
587
588 hrm = hrm + (t >> 32);
589
590 - rm = hrm | (lrm != 0);
591 -
592 - /*
593 - * Sticky shift down to normal rounding precision.
594 - */
595 - if ((s64) rm < 0) {
596 - rm = (rm >> (64 - (DP_FBITS + 1 + 3))) |
597 - ((rm << (DP_FBITS + 1 + 3)) != 0);
598 + /* Put explicit bit at bit 126 if necessary */
599 + if ((int64_t)hrm < 0) {
600 + lrm = (hrm << 63) | (lrm >> 1);
601 + hrm = hrm >> 1;
602 re++;
603 - } else {
604 - rm = (rm >> (64 - (DP_FBITS + 1 + 3 + 1))) |
605 - ((rm << (DP_FBITS + 1 + 3 + 1)) != 0);
606 }
607 - assert(rm & (DP_HIDDEN_BIT << 3));
608
609 - /* And now the addition */
610 - assert(zm & DP_HIDDEN_BIT);
611 + assert(hrm & (1 << 62));
612
613 - /*
614 - * Provide guard,round and stick bit space.
615 - */
616 - zm <<= 3;
617 + if (zc == IEEE754_CLASS_ZERO) {
618 + /*
619 + * Move explicit bit from bit 126 to bit 55 since the
620 + * ieee754dp_format code expects the mantissa to be
621 + * 56 bits wide (53 + 3 rounding bits).
622 + */
623 + srl128(&hrm, &lrm, (126 - 55));
624 + return ieee754dp_format(rs, re, lrm);
625 + }
626 +
627 + /* Move explicit bit from bit 52 to bit 126 */
628 + lzm = 0;
629 + hzm = zm << 10;
630 + assert(hzm & (1 << 62));
631
632 + /* Make the exponents the same */
633 if (ze > re) {
634 /*
635 * Have to shift y fraction right to align.
636 */
637 s = ze - re;
638 - rm = XDPSRS(rm, s);
639 + srl128(&hrm, &lrm, s);
640 re += s;
641 } else if (re > ze) {
642 /*
643 * Have to shift x fraction right to align.
644 */
645 s = re - ze;
646 - zm = XDPSRS(zm, s);
647 + srl128(&hzm, &lzm, s);
648 ze += s;
649 }
650 assert(ze == re);
651 assert(ze <= DP_EMAX);
652
653 + /* Do the addition */
654 if (zs == rs) {
655 /*
656 - * Generate 28 bit result of adding two 27 bit numbers
657 - * leaving result in xm, xs and xe.
658 + * Generate 128 bit result by adding two 127 bit numbers
659 + * leaving result in hzm:lzm, zs and ze.
660 */
661 - zm = zm + rm;
662 -
663 - if (zm >> (DP_FBITS + 1 + 3)) { /* carry out */
664 - zm = XDPSRS1(zm);
665 + hzm = hzm + hrm + (lzm > (lzm + lrm));
666 + lzm = lzm + lrm;
667 + if ((int64_t)hzm < 0) { /* carry out */
668 + srl128(&hzm, &lzm, 1);
669 ze++;
670 }
671 } else {
672 - if (zm >= rm) {
673 - zm = zm - rm;
674 + if (hzm > hrm || (hzm == hrm && lzm >= lrm)) {
675 + hzm = hzm - hrm - (lzm < lrm);
676 + lzm = lzm - lrm;
677 } else {
678 - zm = rm - zm;
679 + hzm = hrm - hzm - (lrm < lzm);
680 + lzm = lrm - lzm;
681 zs = rs;
682 }
683 - if (zm == 0)
684 + if (lzm == 0 && hzm == 0)
685 return ieee754dp_zero(ieee754_csr.rm == FPU_CSR_RD);
686
687 /*
688 - * Normalize to rounding precision.
689 + * Put explicit bit at bit 126 if necessary.
690 */
691 - while ((zm >> (DP_FBITS + 3)) == 0) {
692 - zm <<= 1;
693 - ze--;
694 + if (hzm == 0) {
695 + /* left shift by 63 or 64 bits */
696 + if ((int64_t)lzm < 0) {
697 + /* MSB of lzm is the explicit bit */
698 + hzm = lzm >> 1;
699 + lzm = lzm << 63;
700 + ze -= 63;
701 + } else {
702 + hzm = lzm;
703 + lzm = 0;
704 + ze -= 64;
705 + }
706 + }
707 +
708 + t = 0;
709 + while ((hzm >> (62 - t)) == 0)
710 + t++;
711 +
712 + assert(t <= 62);
713 + if (t) {
714 + hzm = hzm << t | lzm >> (64 - t);
715 + lzm = lzm << t;
716 + ze -= t;
717 }
718 }
719
720 - return ieee754dp_format(zs, ze, zm);
721 + /*
722 + * Move explicit bit from bit 126 to bit 55 since the
723 + * ieee754dp_format code expects the mantissa to be
724 + * 56 bits wide (53 + 3 rounding bits).
725 + */
726 + srl128(&hzm, &lzm, (126 - 55));
727 +
728 + return ieee754dp_format(zs, ze, lzm);
729 }
730
731 union ieee754dp ieee754dp_maddf(union ieee754dp z, union ieee754dp x,
732 @@ -278,5 +343,5 @@ union ieee754dp ieee754dp_maddf(union ieee754dp z, union ieee754dp x,
733 union ieee754dp ieee754dp_msubf(union ieee754dp z, union ieee754dp x,
734 union ieee754dp y)
735 {
736 - return _dp_maddf(z, x, y, maddf_negate_product);
737 + return _dp_maddf(z, x, y, MADDF_NEGATE_PRODUCT);
738 }
739 diff --git a/arch/mips/math-emu/ieee754int.h b/arch/mips/math-emu/ieee754int.h
740 index 8bc2f6963324..dd2071f430e0 100644
741 --- a/arch/mips/math-emu/ieee754int.h
742 +++ b/arch/mips/math-emu/ieee754int.h
743 @@ -26,6 +26,10 @@
744
745 #define CLPAIR(x, y) ((x)*6+(y))
746
747 +enum maddf_flags {
748 + MADDF_NEGATE_PRODUCT = 1 << 0,
749 +};
750 +
751 static inline void ieee754_clearcx(void)
752 {
753 ieee754_csr.cx = 0;
754 diff --git a/arch/mips/math-emu/ieee754sp.h b/arch/mips/math-emu/ieee754sp.h
755 index 8476067075fe..0f63e4202cff 100644
756 --- a/arch/mips/math-emu/ieee754sp.h
757 +++ b/arch/mips/math-emu/ieee754sp.h
758 @@ -45,6 +45,10 @@ static inline int ieee754sp_finite(union ieee754sp x)
759 return SPBEXP(x) != SP_EMAX + 1 + SP_EBIAS;
760 }
761
762 +/* 64 bit right shift with rounding */
763 +#define XSPSRS64(v, rs) \
764 + (((rs) >= 64) ? ((v) != 0) : ((v) >> (rs)) | ((v) << (64-(rs)) != 0))
765 +
766 /* 3bit extended single precision sticky right shift */
767 #define XSPSRS(v, rs) \
768 ((rs > (SP_FBITS+3))?1:((v) >> (rs)) | ((v) << (32-(rs)) != 0))
769 diff --git a/arch/mips/math-emu/sp_fmax.c b/arch/mips/math-emu/sp_fmax.c
770 index 4d000844e48e..74a5a00d2f22 100644
771 --- a/arch/mips/math-emu/sp_fmax.c
772 +++ b/arch/mips/math-emu/sp_fmax.c
773 @@ -47,14 +47,26 @@ union ieee754sp ieee754sp_fmax(union ieee754sp x, union ieee754sp y)
774 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
775 return ieee754sp_nanxcpt(x);
776
777 - /* numbers are preferred to NaNs */
778 + /*
779 + * Quiet NaN handling
780 + */
781 +
782 + /*
783 + * The case of both inputs quiet NaNs
784 + */
785 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
786 + return x;
787 +
788 + /*
789 + * The cases of exactly one input quiet NaN (numbers
790 + * are here preferred as returned values to NaNs)
791 + */
792 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
793 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
794 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
795 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
796 return x;
797
798 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
799 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
800 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
801 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
802 @@ -80,9 +92,7 @@ union ieee754sp ieee754sp_fmax(union ieee754sp x, union ieee754sp y)
803 return ys ? x : y;
804
805 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
806 - if (xs == ys)
807 - return x;
808 - return ieee754sp_zero(1);
809 + return ieee754sp_zero(xs & ys);
810
811 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
812 SPDNORMX;
813 @@ -106,16 +116,32 @@ union ieee754sp ieee754sp_fmax(union ieee754sp x, union ieee754sp y)
814 else if (xs < ys)
815 return x;
816
817 - /* Compare exponent */
818 - if (xe > ye)
819 - return x;
820 - else if (xe < ye)
821 - return y;
822 + /* Signs of inputs are equal, let's compare exponents */
823 + if (xs == 0) {
824 + /* Inputs are both positive */
825 + if (xe > ye)
826 + return x;
827 + else if (xe < ye)
828 + return y;
829 + } else {
830 + /* Inputs are both negative */
831 + if (xe > ye)
832 + return y;
833 + else if (xe < ye)
834 + return x;
835 + }
836
837 - /* Compare mantissa */
838 + /* Signs and exponents of inputs are equal, let's compare mantissas */
839 + if (xs == 0) {
840 + /* Inputs are both positive, with equal signs and exponents */
841 + if (xm <= ym)
842 + return y;
843 + return x;
844 + }
845 + /* Inputs are both negative, with equal signs and exponents */
846 if (xm <= ym)
847 - return y;
848 - return x;
849 + return x;
850 + return y;
851 }
852
853 union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
854 @@ -147,14 +173,26 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
855 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
856 return ieee754sp_nanxcpt(x);
857
858 - /* numbers are preferred to NaNs */
859 + /*
860 + * Quiet NaN handling
861 + */
862 +
863 + /*
864 + * The case of both inputs quiet NaNs
865 + */
866 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
867 + return x;
868 +
869 + /*
870 + * The cases of exactly one input quiet NaN (numbers
871 + * are here preferred as returned values to NaNs)
872 + */
873 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
874 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
875 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
876 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
877 return x;
878
879 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
880 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
881 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
882 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
883 @@ -164,6 +202,9 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
884 /*
885 * Infinity and zero handling
886 */
887 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
888 + return ieee754sp_inf(xs & ys);
889 +
890 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
891 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
892 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
893 @@ -171,7 +212,6 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
894 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
895 return x;
896
897 - case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
898 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
899 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
900 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
901 @@ -180,9 +220,7 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
902 return y;
903
904 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
905 - if (xs == ys)
906 - return x;
907 - return ieee754sp_zero(1);
908 + return ieee754sp_zero(xs & ys);
909
910 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
911 SPDNORMX;
912 @@ -207,7 +245,11 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
913 return y;
914
915 /* Compare mantissa */
916 - if (xm <= ym)
917 + if (xm < ym)
918 return y;
919 - return x;
920 + else if (xm > ym)
921 + return x;
922 + else if (xs == 0)
923 + return x;
924 + return y;
925 }
926 diff --git a/arch/mips/math-emu/sp_fmin.c b/arch/mips/math-emu/sp_fmin.c
927 index 4eb1bb9e9dec..c51385f46b09 100644
928 --- a/arch/mips/math-emu/sp_fmin.c
929 +++ b/arch/mips/math-emu/sp_fmin.c
930 @@ -47,14 +47,26 @@ union ieee754sp ieee754sp_fmin(union ieee754sp x, union ieee754sp y)
931 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
932 return ieee754sp_nanxcpt(x);
933
934 - /* numbers are preferred to NaNs */
935 + /*
936 + * Quiet NaN handling
937 + */
938 +
939 + /*
940 + * The case of both inputs quiet NaNs
941 + */
942 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
943 + return x;
944 +
945 + /*
946 + * The cases of exactly one input quiet NaN (numbers
947 + * are here preferred as returned values to NaNs)
948 + */
949 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
950 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
951 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
952 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
953 return x;
954
955 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
956 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
957 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
958 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
959 @@ -80,9 +92,7 @@ union ieee754sp ieee754sp_fmin(union ieee754sp x, union ieee754sp y)
960 return ys ? y : x;
961
962 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
963 - if (xs == ys)
964 - return x;
965 - return ieee754sp_zero(1);
966 + return ieee754sp_zero(xs | ys);
967
968 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
969 SPDNORMX;
970 @@ -106,16 +116,32 @@ union ieee754sp ieee754sp_fmin(union ieee754sp x, union ieee754sp y)
971 else if (xs < ys)
972 return y;
973
974 - /* Compare exponent */
975 - if (xe > ye)
976 - return y;
977 - else if (xe < ye)
978 - return x;
979 + /* Signs of inputs are the same, let's compare exponents */
980 + if (xs == 0) {
981 + /* Inputs are both positive */
982 + if (xe > ye)
983 + return y;
984 + else if (xe < ye)
985 + return x;
986 + } else {
987 + /* Inputs are both negative */
988 + if (xe > ye)
989 + return x;
990 + else if (xe < ye)
991 + return y;
992 + }
993
994 - /* Compare mantissa */
995 + /* Signs and exponents of inputs are equal, let's compare mantissas */
996 + if (xs == 0) {
997 + /* Inputs are both positive, with equal signs and exponents */
998 + if (xm <= ym)
999 + return x;
1000 + return y;
1001 + }
1002 + /* Inputs are both negative, with equal signs and exponents */
1003 if (xm <= ym)
1004 - return x;
1005 - return y;
1006 + return y;
1007 + return x;
1008 }
1009
1010 union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y)
1011 @@ -147,14 +173,26 @@ union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y)
1012 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
1013 return ieee754sp_nanxcpt(x);
1014
1015 - /* numbers are preferred to NaNs */
1016 + /*
1017 + * Quiet NaN handling
1018 + */
1019 +
1020 + /*
1021 + * The case of both inputs quiet NaNs
1022 + */
1023 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
1024 + return x;
1025 +
1026 + /*
1027 + * The cases of exactly one input quiet NaN (numbers
1028 + * are here preferred as returned values to NaNs)
1029 + */
1030 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
1031 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
1032 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
1033 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
1034 return x;
1035
1036 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
1037 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
1038 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
1039 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
1040 @@ -164,25 +202,25 @@ union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y)
1041 /*
1042 * Infinity and zero handling
1043 */
1044 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
1045 + return ieee754sp_inf(xs | ys);
1046 +
1047 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
1048 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
1049 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
1050 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
1051 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
1052 - return x;
1053 + return y;
1054
1055 - case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
1056 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
1057 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
1058 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
1059 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
1060 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
1061 - return y;
1062 + return x;
1063
1064 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
1065 - if (xs == ys)
1066 - return x;
1067 - return ieee754sp_zero(1);
1068 + return ieee754sp_zero(xs | ys);
1069
1070 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
1071 SPDNORMX;
1072 @@ -207,7 +245,11 @@ union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y)
1073 return x;
1074
1075 /* Compare mantissa */
1076 - if (xm <= ym)
1077 + if (xm < ym)
1078 + return x;
1079 + else if (xm > ym)
1080 + return y;
1081 + else if (xs == 1)
1082 return x;
1083 return y;
1084 }
1085 diff --git a/arch/mips/math-emu/sp_maddf.c b/arch/mips/math-emu/sp_maddf.c
1086 index a8cd8b4f235e..7195fe785d81 100644
1087 --- a/arch/mips/math-emu/sp_maddf.c
1088 +++ b/arch/mips/math-emu/sp_maddf.c
1089 @@ -14,9 +14,6 @@
1090
1091 #include "ieee754sp.h"
1092
1093 -enum maddf_flags {
1094 - maddf_negate_product = 1 << 0,
1095 -};
1096
1097 static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1098 union ieee754sp y, enum maddf_flags flags)
1099 @@ -24,14 +21,8 @@ static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1100 int re;
1101 int rs;
1102 unsigned rm;
1103 - unsigned short lxm;
1104 - unsigned short hxm;
1105 - unsigned short lym;
1106 - unsigned short hym;
1107 - unsigned lrm;
1108 - unsigned hrm;
1109 - unsigned t;
1110 - unsigned at;
1111 + uint64_t rm64;
1112 + uint64_t zm64;
1113 int s;
1114
1115 COMPXSP;
1116 @@ -48,51 +39,35 @@ static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1117
1118 ieee754_clearcx();
1119
1120 - switch (zc) {
1121 - case IEEE754_CLASS_SNAN:
1122 - ieee754_setcx(IEEE754_INVALID_OPERATION);
1123 + /*
1124 + * Handle the cases when at least one of x, y or z is a NaN.
1125 + * Order of precedence is sNaN, qNaN and z, x, y.
1126 + */
1127 + if (zc == IEEE754_CLASS_SNAN)
1128 return ieee754sp_nanxcpt(z);
1129 - case IEEE754_CLASS_DNORM:
1130 - SPDNORMZ;
1131 - /* QNAN is handled separately below */
1132 - }
1133 -
1134 - switch (CLPAIR(xc, yc)) {
1135 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
1136 - case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
1137 - case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
1138 - case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
1139 - case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
1140 + if (xc == IEEE754_CLASS_SNAN)
1141 + return ieee754sp_nanxcpt(x);
1142 + if (yc == IEEE754_CLASS_SNAN)
1143 return ieee754sp_nanxcpt(y);
1144 + if (zc == IEEE754_CLASS_QNAN)
1145 + return z;
1146 + if (xc == IEEE754_CLASS_QNAN)
1147 + return x;
1148 + if (yc == IEEE754_CLASS_QNAN)
1149 + return y;
1150
1151 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
1152 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
1153 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
1154 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
1155 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
1156 - case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
1157 - return ieee754sp_nanxcpt(x);
1158 + if (zc == IEEE754_CLASS_DNORM)
1159 + SPDNORMZ;
1160 + /* ZERO z cases are handled separately below */
1161
1162 - case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
1163 - case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
1164 - case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
1165 - case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
1166 - return y;
1167 + switch (CLPAIR(xc, yc)) {
1168
1169 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
1170 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
1171 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
1172 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
1173 - case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
1174 - return x;
1175
1176 /*
1177 * Infinity handling
1178 */
1179 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
1180 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
1181 - if (zc == IEEE754_CLASS_QNAN)
1182 - return z;
1183 ieee754_setcx(IEEE754_INVALID_OPERATION);
1184 return ieee754sp_indef();
1185
1186 @@ -101,9 +76,27 @@ static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1187 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
1188 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
1189 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
1190 - if (zc == IEEE754_CLASS_QNAN)
1191 - return z;
1192 - return ieee754sp_inf(xs ^ ys);
1193 + if ((zc == IEEE754_CLASS_INF) &&
1194 + ((!(flags & MADDF_NEGATE_PRODUCT) && (zs != (xs ^ ys))) ||
1195 + ((flags & MADDF_NEGATE_PRODUCT) && (zs == (xs ^ ys))))) {
1196 + /*
1197 + * Cases of addition of infinities with opposite signs
1198 + * or subtraction of infinities with same signs.
1199 + */
1200 + ieee754_setcx(IEEE754_INVALID_OPERATION);
1201 + return ieee754sp_indef();
1202 + }
1203 + /*
1204 + * z is here either not an infinity, or an infinity having the
1205 + * same sign as product (x*y) (in case of MADDF.D instruction)
1206 + * or product -(x*y) (in MSUBF.D case). The result must be an
1207 + * infinity, and its sign is determined only by the value of
1208 + * (flags & MADDF_NEGATE_PRODUCT) and the signs of x and y.
1209 + */
1210 + if (flags & MADDF_NEGATE_PRODUCT)
1211 + return ieee754sp_inf(1 ^ (xs ^ ys));
1212 + else
1213 + return ieee754sp_inf(xs ^ ys);
1214
1215 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
1216 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
1217 @@ -112,32 +105,42 @@ static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1218 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
1219 if (zc == IEEE754_CLASS_INF)
1220 return ieee754sp_inf(zs);
1221 - /* Multiplication is 0 so just return z */
1222 + if (zc == IEEE754_CLASS_ZERO) {
1223 + /* Handle cases +0 + (-0) and similar ones. */
1224 + if ((!(flags & MADDF_NEGATE_PRODUCT)
1225 + && (zs == (xs ^ ys))) ||
1226 + ((flags & MADDF_NEGATE_PRODUCT)
1227 + && (zs != (xs ^ ys))))
1228 + /*
1229 + * Cases of addition of zeros of equal signs
1230 + * or subtraction of zeroes of opposite signs.
1231 + * The sign of the resulting zero is in any
1232 + * such case determined only by the sign of z.
1233 + */
1234 + return z;
1235 +
1236 + return ieee754sp_zero(ieee754_csr.rm == FPU_CSR_RD);
1237 + }
1238 + /* x*y is here 0, and z is not 0, so just return z */
1239 return z;
1240
1241 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
1242 SPDNORMX;
1243
1244 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
1245 - if (zc == IEEE754_CLASS_QNAN)
1246 - return z;
1247 - else if (zc == IEEE754_CLASS_INF)
1248 + if (zc == IEEE754_CLASS_INF)
1249 return ieee754sp_inf(zs);
1250 SPDNORMY;
1251 break;
1252
1253 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
1254 - if (zc == IEEE754_CLASS_QNAN)
1255 - return z;
1256 - else if (zc == IEEE754_CLASS_INF)
1257 + if (zc == IEEE754_CLASS_INF)
1258 return ieee754sp_inf(zs);
1259 SPDNORMX;
1260 break;
1261
1262 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
1263 - if (zc == IEEE754_CLASS_QNAN)
1264 - return z;
1265 - else if (zc == IEEE754_CLASS_INF)
1266 + if (zc == IEEE754_CLASS_INF)
1267 return ieee754sp_inf(zs);
1268 /* fall through to real computations */
1269 }
1270 @@ -158,108 +161,93 @@ static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1271
1272 re = xe + ye;
1273 rs = xs ^ ys;
1274 - if (flags & maddf_negate_product)
1275 + if (flags & MADDF_NEGATE_PRODUCT)
1276 rs ^= 1;
1277
1278 - /* shunt to top of word */
1279 - xm <<= 32 - (SP_FBITS + 1);
1280 - ym <<= 32 - (SP_FBITS + 1);
1281 -
1282 - /*
1283 - * Multiply 32 bits xm, ym to give high 32 bits rm with stickness.
1284 - */
1285 - lxm = xm & 0xffff;
1286 - hxm = xm >> 16;
1287 - lym = ym & 0xffff;
1288 - hym = ym >> 16;
1289 -
1290 - lrm = lxm * lym; /* 16 * 16 => 32 */
1291 - hrm = hxm * hym; /* 16 * 16 => 32 */
1292 + /* Multiple 24 bit xm and ym to give 48 bit results */
1293 + rm64 = (uint64_t)xm * ym;
1294
1295 - t = lxm * hym; /* 16 * 16 => 32 */
1296 - at = lrm + (t << 16);
1297 - hrm += at < lrm;
1298 - lrm = at;
1299 - hrm = hrm + (t >> 16);
1300 + /* Shunt to top of word */
1301 + rm64 = rm64 << 16;
1302
1303 - t = hxm * lym; /* 16 * 16 => 32 */
1304 - at = lrm + (t << 16);
1305 - hrm += at < lrm;
1306 - lrm = at;
1307 - hrm = hrm + (t >> 16);
1308 -
1309 - rm = hrm | (lrm != 0);
1310 -
1311 - /*
1312 - * Sticky shift down to normal rounding precision.
1313 - */
1314 - if ((int) rm < 0) {
1315 - rm = (rm >> (32 - (SP_FBITS + 1 + 3))) |
1316 - ((rm << (SP_FBITS + 1 + 3)) != 0);
1317 + /* Put explicit bit at bit 62 if necessary */
1318 + if ((int64_t) rm64 < 0) {
1319 + rm64 = rm64 >> 1;
1320 re++;
1321 - } else {
1322 - rm = (rm >> (32 - (SP_FBITS + 1 + 3 + 1))) |
1323 - ((rm << (SP_FBITS + 1 + 3 + 1)) != 0);
1324 }
1325 - assert(rm & (SP_HIDDEN_BIT << 3));
1326
1327 - /* And now the addition */
1328 + assert(rm64 & (1 << 62));
1329
1330 - assert(zm & SP_HIDDEN_BIT);
1331 + if (zc == IEEE754_CLASS_ZERO) {
1332 + /*
1333 + * Move explicit bit from bit 62 to bit 26 since the
1334 + * ieee754sp_format code expects the mantissa to be
1335 + * 27 bits wide (24 + 3 rounding bits).
1336 + */
1337 + rm = XSPSRS64(rm64, (62 - 26));
1338 + return ieee754sp_format(rs, re, rm);
1339 + }
1340
1341 - /*
1342 - * Provide guard,round and stick bit space.
1343 - */
1344 - zm <<= 3;
1345 + /* Move explicit bit from bit 23 to bit 62 */
1346 + zm64 = (uint64_t)zm << (62 - 23);
1347 + assert(zm64 & (1 << 62));
1348
1349 + /* Make the exponents the same */
1350 if (ze > re) {
1351 /*
1352 * Have to shift r fraction right to align.
1353 */
1354 s = ze - re;
1355 - rm = XSPSRS(rm, s);
1356 + rm64 = XSPSRS64(rm64, s);
1357 re += s;
1358 } else if (re > ze) {
1359 /*
1360 * Have to shift z fraction right to align.
1361 */
1362 s = re - ze;
1363 - zm = XSPSRS(zm, s);
1364 + zm64 = XSPSRS64(zm64, s);
1365 ze += s;
1366 }
1367 assert(ze == re);
1368 assert(ze <= SP_EMAX);
1369
1370 + /* Do the addition */
1371 if (zs == rs) {
1372 /*
1373 - * Generate 28 bit result of adding two 27 bit numbers
1374 - * leaving result in zm, zs and ze.
1375 + * Generate 64 bit result by adding two 63 bit numbers
1376 + * leaving result in zm64, zs and ze.
1377 */
1378 - zm = zm + rm;
1379 -
1380 - if (zm >> (SP_FBITS + 1 + 3)) { /* carry out */
1381 - zm = XSPSRS1(zm);
1382 + zm64 = zm64 + rm64;
1383 + if ((int64_t)zm64 < 0) { /* carry out */
1384 + zm64 = XSPSRS1(zm64);
1385 ze++;
1386 }
1387 } else {
1388 - if (zm >= rm) {
1389 - zm = zm - rm;
1390 + if (zm64 >= rm64) {
1391 + zm64 = zm64 - rm64;
1392 } else {
1393 - zm = rm - zm;
1394 + zm64 = rm64 - zm64;
1395 zs = rs;
1396 }
1397 - if (zm == 0)
1398 + if (zm64 == 0)
1399 return ieee754sp_zero(ieee754_csr.rm == FPU_CSR_RD);
1400
1401 /*
1402 - * Normalize in extended single precision
1403 + * Put explicit bit at bit 62 if necessary.
1404 */
1405 - while ((zm >> (SP_MBITS + 3)) == 0) {
1406 - zm <<= 1;
1407 + while ((zm64 >> 62) == 0) {
1408 + zm64 <<= 1;
1409 ze--;
1410 }
1411 -
1412 }
1413 +
1414 + /*
1415 + * Move explicit bit from bit 62 to bit 26 since the
1416 + * ieee754sp_format code expects the mantissa to be
1417 + * 27 bits wide (24 + 3 rounding bits).
1418 + */
1419 + zm = XSPSRS64(zm64, (62 - 26));
1420 +
1421 return ieee754sp_format(zs, ze, zm);
1422 }
1423
1424 @@ -272,5 +260,5 @@ union ieee754sp ieee754sp_maddf(union ieee754sp z, union ieee754sp x,
1425 union ieee754sp ieee754sp_msubf(union ieee754sp z, union ieee754sp x,
1426 union ieee754sp y)
1427 {
1428 - return _sp_maddf(z, x, y, maddf_negate_product);
1429 + return _sp_maddf(z, x, y, MADDF_NEGATE_PRODUCT);
1430 }
1431 diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c
1432 index b2da7c8baed7..292458b694fb 100644
1433 --- a/arch/powerpc/kernel/align.c
1434 +++ b/arch/powerpc/kernel/align.c
1435 @@ -235,6 +235,28 @@ static int emulate_dcbz(struct pt_regs *regs, unsigned char __user *addr)
1436
1437 #define SWIZ_PTR(p) ((unsigned char __user *)((p) ^ swiz))
1438
1439 +#define __get_user_or_set_dar(_regs, _dest, _addr) \
1440 + ({ \
1441 + int rc = 0; \
1442 + typeof(_addr) __addr = (_addr); \
1443 + if (__get_user_inatomic(_dest, __addr)) { \
1444 + _regs->dar = (unsigned long)__addr; \
1445 + rc = -EFAULT; \
1446 + } \
1447 + rc; \
1448 + })
1449 +
1450 +#define __put_user_or_set_dar(_regs, _src, _addr) \
1451 + ({ \
1452 + int rc = 0; \
1453 + typeof(_addr) __addr = (_addr); \
1454 + if (__put_user_inatomic(_src, __addr)) { \
1455 + _regs->dar = (unsigned long)__addr; \
1456 + rc = -EFAULT; \
1457 + } \
1458 + rc; \
1459 + })
1460 +
1461 static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr,
1462 unsigned int reg, unsigned int nb,
1463 unsigned int flags, unsigned int instr,
1464 @@ -263,9 +285,10 @@ static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr,
1465 } else {
1466 unsigned long pc = regs->nip ^ (swiz & 4);
1467
1468 - if (__get_user_inatomic(instr,
1469 - (unsigned int __user *)pc))
1470 + if (__get_user_or_set_dar(regs, instr,
1471 + (unsigned int __user *)pc))
1472 return -EFAULT;
1473 +
1474 if (swiz == 0 && (flags & SW))
1475 instr = cpu_to_le32(instr);
1476 nb = (instr >> 11) & 0x1f;
1477 @@ -309,31 +332,31 @@ static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr,
1478 ((nb0 + 3) / 4) * sizeof(unsigned long));
1479
1480 for (i = 0; i < nb; ++i, ++p)
1481 - if (__get_user_inatomic(REG_BYTE(rptr, i ^ bswiz),
1482 - SWIZ_PTR(p)))
1483 + if (__get_user_or_set_dar(regs, REG_BYTE(rptr, i ^ bswiz),
1484 + SWIZ_PTR(p)))
1485 return -EFAULT;
1486 if (nb0 > 0) {
1487 rptr = &regs->gpr[0];
1488 addr += nb;
1489 for (i = 0; i < nb0; ++i, ++p)
1490 - if (__get_user_inatomic(REG_BYTE(rptr,
1491 - i ^ bswiz),
1492 - SWIZ_PTR(p)))
1493 + if (__get_user_or_set_dar(regs,
1494 + REG_BYTE(rptr, i ^ bswiz),
1495 + SWIZ_PTR(p)))
1496 return -EFAULT;
1497 }
1498
1499 } else {
1500 for (i = 0; i < nb; ++i, ++p)
1501 - if (__put_user_inatomic(REG_BYTE(rptr, i ^ bswiz),
1502 - SWIZ_PTR(p)))
1503 + if (__put_user_or_set_dar(regs, REG_BYTE(rptr, i ^ bswiz),
1504 + SWIZ_PTR(p)))
1505 return -EFAULT;
1506 if (nb0 > 0) {
1507 rptr = &regs->gpr[0];
1508 addr += nb;
1509 for (i = 0; i < nb0; ++i, ++p)
1510 - if (__put_user_inatomic(REG_BYTE(rptr,
1511 - i ^ bswiz),
1512 - SWIZ_PTR(p)))
1513 + if (__put_user_or_set_dar(regs,
1514 + REG_BYTE(rptr, i ^ bswiz),
1515 + SWIZ_PTR(p)))
1516 return -EFAULT;
1517 }
1518 }
1519 @@ -345,29 +368,32 @@ static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr,
1520 * Only POWER6 has these instructions, and it does true little-endian,
1521 * so we don't need the address swizzling.
1522 */
1523 -static int emulate_fp_pair(unsigned char __user *addr, unsigned int reg,
1524 - unsigned int flags)
1525 +static int emulate_fp_pair(struct pt_regs *regs, unsigned char __user *addr,
1526 + unsigned int reg, unsigned int flags)
1527 {
1528 char *ptr0 = (char *) &current->thread.TS_FPR(reg);
1529 char *ptr1 = (char *) &current->thread.TS_FPR(reg+1);
1530 - int i, ret, sw = 0;
1531 + int i, sw = 0;
1532
1533 if (reg & 1)
1534 return 0; /* invalid form: FRS/FRT must be even */
1535 if (flags & SW)
1536 sw = 7;
1537 - ret = 0;
1538 +
1539 for (i = 0; i < 8; ++i) {
1540 if (!(flags & ST)) {
1541 - ret |= __get_user(ptr0[i^sw], addr + i);
1542 - ret |= __get_user(ptr1[i^sw], addr + i + 8);
1543 + if (__get_user_or_set_dar(regs, ptr0[i^sw], addr + i))
1544 + return -EFAULT;
1545 + if (__get_user_or_set_dar(regs, ptr1[i^sw], addr + i + 8))
1546 + return -EFAULT;
1547 } else {
1548 - ret |= __put_user(ptr0[i^sw], addr + i);
1549 - ret |= __put_user(ptr1[i^sw], addr + i + 8);
1550 + if (__put_user_or_set_dar(regs, ptr0[i^sw], addr + i))
1551 + return -EFAULT;
1552 + if (__put_user_or_set_dar(regs, ptr1[i^sw], addr + i + 8))
1553 + return -EFAULT;
1554 }
1555 }
1556 - if (ret)
1557 - return -EFAULT;
1558 +
1559 return 1; /* exception handled and fixed up */
1560 }
1561
1562 @@ -377,24 +403,27 @@ static int emulate_lq_stq(struct pt_regs *regs, unsigned char __user *addr,
1563 {
1564 char *ptr0 = (char *)&regs->gpr[reg];
1565 char *ptr1 = (char *)&regs->gpr[reg+1];
1566 - int i, ret, sw = 0;
1567 + int i, sw = 0;
1568
1569 if (reg & 1)
1570 return 0; /* invalid form: GPR must be even */
1571 if (flags & SW)
1572 sw = 7;
1573 - ret = 0;
1574 +
1575 for (i = 0; i < 8; ++i) {
1576 if (!(flags & ST)) {
1577 - ret |= __get_user(ptr0[i^sw], addr + i);
1578 - ret |= __get_user(ptr1[i^sw], addr + i + 8);
1579 + if (__get_user_or_set_dar(regs, ptr0[i^sw], addr + i))
1580 + return -EFAULT;
1581 + if (__get_user_or_set_dar(regs, ptr1[i^sw], addr + i + 8))
1582 + return -EFAULT;
1583 } else {
1584 - ret |= __put_user(ptr0[i^sw], addr + i);
1585 - ret |= __put_user(ptr1[i^sw], addr + i + 8);
1586 + if (__put_user_or_set_dar(regs, ptr0[i^sw], addr + i))
1587 + return -EFAULT;
1588 + if (__put_user_or_set_dar(regs, ptr1[i^sw], addr + i + 8))
1589 + return -EFAULT;
1590 }
1591 }
1592 - if (ret)
1593 - return -EFAULT;
1594 +
1595 return 1; /* exception handled and fixed up */
1596 }
1597 #endif /* CONFIG_PPC64 */
1598 @@ -687,9 +716,14 @@ static int emulate_vsx(unsigned char __user *addr, unsigned int reg,
1599 for (j = 0; j < length; j += elsize) {
1600 for (i = 0; i < elsize; ++i) {
1601 if (flags & ST)
1602 - ret |= __put_user(ptr[i^sw], addr + i);
1603 + ret = __put_user_or_set_dar(regs, ptr[i^sw],
1604 + addr + i);
1605 else
1606 - ret |= __get_user(ptr[i^sw], addr + i);
1607 + ret = __get_user_or_set_dar(regs, ptr[i^sw],
1608 + addr + i);
1609 +
1610 + if (ret)
1611 + return ret;
1612 }
1613 ptr += elsize;
1614 #ifdef __LITTLE_ENDIAN__
1615 @@ -739,7 +773,7 @@ int fix_alignment(struct pt_regs *regs)
1616 unsigned int dsisr;
1617 unsigned char __user *addr;
1618 unsigned long p, swiz;
1619 - int ret, i;
1620 + int i;
1621 union data {
1622 u64 ll;
1623 double dd;
1624 @@ -936,7 +970,7 @@ int fix_alignment(struct pt_regs *regs)
1625 if (flags & F) {
1626 /* Special case for 16-byte FP loads and stores */
1627 PPC_WARN_ALIGNMENT(fp_pair, regs);
1628 - return emulate_fp_pair(addr, reg, flags);
1629 + return emulate_fp_pair(regs, addr, reg, flags);
1630 } else {
1631 #ifdef CONFIG_PPC64
1632 /* Special case for 16-byte loads and stores */
1633 @@ -966,15 +1000,12 @@ int fix_alignment(struct pt_regs *regs)
1634 }
1635
1636 data.ll = 0;
1637 - ret = 0;
1638 p = (unsigned long)addr;
1639
1640 for (i = 0; i < nb; i++)
1641 - ret |= __get_user_inatomic(data.v[start + i],
1642 - SWIZ_PTR(p++));
1643 -
1644 - if (unlikely(ret))
1645 - return -EFAULT;
1646 + if (__get_user_or_set_dar(regs, data.v[start + i],
1647 + SWIZ_PTR(p++)))
1648 + return -EFAULT;
1649
1650 } else if (flags & F) {
1651 data.ll = current->thread.TS_FPR(reg);
1652 @@ -1046,15 +1077,13 @@ int fix_alignment(struct pt_regs *regs)
1653 break;
1654 }
1655
1656 - ret = 0;
1657 p = (unsigned long)addr;
1658
1659 for (i = 0; i < nb; i++)
1660 - ret |= __put_user_inatomic(data.v[start + i],
1661 - SWIZ_PTR(p++));
1662 + if (__put_user_or_set_dar(regs, data.v[start + i],
1663 + SWIZ_PTR(p++)))
1664 + return -EFAULT;
1665
1666 - if (unlikely(ret))
1667 - return -EFAULT;
1668 } else if (flags & F)
1669 current->thread.TS_FPR(reg) = data.ll;
1670 else
1671 diff --git a/arch/s390/include/asm/mmu.h b/arch/s390/include/asm/mmu.h
1672 index bea785d7f853..af85d6b12028 100644
1673 --- a/arch/s390/include/asm/mmu.h
1674 +++ b/arch/s390/include/asm/mmu.h
1675 @@ -5,6 +5,7 @@
1676 #include <linux/errno.h>
1677
1678 typedef struct {
1679 + spinlock_t lock;
1680 cpumask_t cpu_attach_mask;
1681 atomic_t flush_count;
1682 unsigned int flush_mm;
1683 @@ -25,6 +26,7 @@ typedef struct {
1684 } mm_context_t;
1685
1686 #define INIT_MM_CONTEXT(name) \
1687 + .context.lock = __SPIN_LOCK_UNLOCKED(name.context.lock), \
1688 .context.pgtable_lock = \
1689 __SPIN_LOCK_UNLOCKED(name.context.pgtable_lock), \
1690 .context.pgtable_list = LIST_HEAD_INIT(name.context.pgtable_list), \
1691 diff --git a/arch/s390/include/asm/mmu_context.h b/arch/s390/include/asm/mmu_context.h
1692 index 515fea5a3fc4..f65a708ac395 100644
1693 --- a/arch/s390/include/asm/mmu_context.h
1694 +++ b/arch/s390/include/asm/mmu_context.h
1695 @@ -15,6 +15,7 @@
1696 static inline int init_new_context(struct task_struct *tsk,
1697 struct mm_struct *mm)
1698 {
1699 + spin_lock_init(&mm->context.lock);
1700 spin_lock_init(&mm->context.pgtable_lock);
1701 INIT_LIST_HEAD(&mm->context.pgtable_list);
1702 spin_lock_init(&mm->context.gmap_lock);
1703 @@ -93,7 +94,6 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
1704 if (prev == next)
1705 return;
1706 cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
1707 - cpumask_set_cpu(cpu, mm_cpumask(next));
1708 /* Clear old ASCE by loading the kernel ASCE. */
1709 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
1710 __ctl_load(S390_lowcore.kernel_asce, 7, 7);
1711 @@ -111,9 +111,8 @@ static inline void finish_arch_post_lock_switch(void)
1712 preempt_disable();
1713 while (atomic_read(&mm->context.flush_count))
1714 cpu_relax();
1715 -
1716 - if (mm->context.flush_mm)
1717 - __tlb_flush_mm(mm);
1718 + cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
1719 + __tlb_flush_mm_lazy(mm);
1720 preempt_enable();
1721 }
1722 set_fs(current->thread.mm_segment);
1723 @@ -126,6 +125,7 @@ static inline void activate_mm(struct mm_struct *prev,
1724 struct mm_struct *next)
1725 {
1726 switch_mm(prev, next, current);
1727 + cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
1728 set_user_asce(next);
1729 }
1730
1731 diff --git a/arch/s390/include/asm/tlbflush.h b/arch/s390/include/asm/tlbflush.h
1732 index 39846100682a..eed927aeb08f 100644
1733 --- a/arch/s390/include/asm/tlbflush.h
1734 +++ b/arch/s390/include/asm/tlbflush.h
1735 @@ -43,23 +43,6 @@ static inline void __tlb_flush_global(void)
1736 * Flush TLB entries for a specific mm on all CPUs (in case gmap is used
1737 * this implicates multiple ASCEs!).
1738 */
1739 -static inline void __tlb_flush_full(struct mm_struct *mm)
1740 -{
1741 - preempt_disable();
1742 - atomic_inc(&mm->context.flush_count);
1743 - if (cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id()))) {
1744 - /* Local TLB flush */
1745 - __tlb_flush_local();
1746 - } else {
1747 - /* Global TLB flush */
1748 - __tlb_flush_global();
1749 - /* Reset TLB flush mask */
1750 - cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
1751 - }
1752 - atomic_dec(&mm->context.flush_count);
1753 - preempt_enable();
1754 -}
1755 -
1756 static inline void __tlb_flush_mm(struct mm_struct *mm)
1757 {
1758 unsigned long gmap_asce;
1759 @@ -71,16 +54,18 @@ static inline void __tlb_flush_mm(struct mm_struct *mm)
1760 */
1761 preempt_disable();
1762 atomic_inc(&mm->context.flush_count);
1763 + /* Reset TLB flush mask */
1764 + cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
1765 + barrier();
1766 gmap_asce = READ_ONCE(mm->context.gmap_asce);
1767 if (MACHINE_HAS_IDTE && gmap_asce != -1UL) {
1768 if (gmap_asce)
1769 __tlb_flush_idte(gmap_asce);
1770 __tlb_flush_idte(mm->context.asce);
1771 } else {
1772 - __tlb_flush_full(mm);
1773 + /* Global TLB flush */
1774 + __tlb_flush_global();
1775 }
1776 - /* Reset TLB flush mask */
1777 - cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
1778 atomic_dec(&mm->context.flush_count);
1779 preempt_enable();
1780 }
1781 @@ -94,7 +79,6 @@ static inline void __tlb_flush_kernel(void)
1782 }
1783 #else
1784 #define __tlb_flush_global() __tlb_flush_local()
1785 -#define __tlb_flush_full(mm) __tlb_flush_local()
1786
1787 /*
1788 * Flush TLB entries for a specific ASCE on all CPUs.
1789 @@ -112,10 +96,12 @@ static inline void __tlb_flush_kernel(void)
1790
1791 static inline void __tlb_flush_mm_lazy(struct mm_struct * mm)
1792 {
1793 + spin_lock(&mm->context.lock);
1794 if (mm->context.flush_mm) {
1795 - __tlb_flush_mm(mm);
1796 mm->context.flush_mm = 0;
1797 + __tlb_flush_mm(mm);
1798 }
1799 + spin_unlock(&mm->context.lock);
1800 }
1801
1802 /*
1803 diff --git a/block/blk-core.c b/block/blk-core.c
1804 index d1f2801ce836..95379fc83805 100644
1805 --- a/block/blk-core.c
1806 +++ b/block/blk-core.c
1807 @@ -233,7 +233,7 @@ EXPORT_SYMBOL(blk_start_queue_async);
1808 **/
1809 void blk_start_queue(struct request_queue *q)
1810 {
1811 - WARN_ON(!irqs_disabled());
1812 + WARN_ON(!in_interrupt() && !irqs_disabled());
1813
1814 queue_flag_clear(QUEUE_FLAG_STOPPED, q);
1815 __blk_run_queue(q);
1816 diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
1817 index 45af0fe00f33..aaf2f810d170 100644
1818 --- a/crypto/algif_skcipher.c
1819 +++ b/crypto/algif_skcipher.c
1820 @@ -143,8 +143,10 @@ static int skcipher_alloc_sgl(struct sock *sk)
1821 sg_init_table(sgl->sg, MAX_SGL_ENTS + 1);
1822 sgl->cur = 0;
1823
1824 - if (sg)
1825 + if (sg) {
1826 sg_chain(sg, MAX_SGL_ENTS + 1, sgl->sg);
1827 + sg_unmark_end(sg + (MAX_SGL_ENTS - 1));
1828 + }
1829
1830 list_add_tail(&sgl->list, &ctx->tsgl);
1831 }
1832 diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
1833 index 3822eae102db..6f78cea75103 100644
1834 --- a/drivers/block/skd_main.c
1835 +++ b/drivers/block/skd_main.c
1836 @@ -2163,6 +2163,9 @@ static void skd_send_fitmsg(struct skd_device *skdev,
1837 */
1838 qcmd |= FIT_QCMD_MSGSIZE_64;
1839
1840 + /* Make sure skd_msg_buf is written before the doorbell is triggered. */
1841 + smp_wmb();
1842 +
1843 SKD_WRITEQ(skdev, qcmd, FIT_Q_COMMAND);
1844
1845 }
1846 @@ -2209,6 +2212,9 @@ static void skd_send_special_fitmsg(struct skd_device *skdev,
1847 qcmd = skspcl->mb_dma_address;
1848 qcmd |= FIT_QCMD_QID_NORMAL + FIT_QCMD_MSGSIZE_128;
1849
1850 + /* Make sure skd_msg_buf is written before the doorbell is triggered. */
1851 + smp_wmb();
1852 +
1853 SKD_WRITEQ(skdev, qcmd, FIT_Q_COMMAND);
1854 }
1855
1856 @@ -4622,15 +4628,16 @@ static void skd_free_disk(struct skd_device *skdev)
1857 {
1858 struct gendisk *disk = skdev->disk;
1859
1860 - if (disk != NULL) {
1861 - struct request_queue *q = disk->queue;
1862 + if (disk && (disk->flags & GENHD_FL_UP))
1863 + del_gendisk(disk);
1864
1865 - if (disk->flags & GENHD_FL_UP)
1866 - del_gendisk(disk);
1867 - if (q)
1868 - blk_cleanup_queue(q);
1869 - put_disk(disk);
1870 + if (skdev->queue) {
1871 + blk_cleanup_queue(skdev->queue);
1872 + skdev->queue = NULL;
1873 + disk->queue = NULL;
1874 }
1875 +
1876 + put_disk(disk);
1877 skdev->disk = NULL;
1878 }
1879
1880 diff --git a/drivers/crypto/ccp/ccp-crypto-aes-xts.c b/drivers/crypto/ccp/ccp-crypto-aes-xts.c
1881 index 58a4244b4752..3f26a415ef44 100644
1882 --- a/drivers/crypto/ccp/ccp-crypto-aes-xts.c
1883 +++ b/drivers/crypto/ccp/ccp-crypto-aes-xts.c
1884 @@ -1,8 +1,9 @@
1885 /*
1886 * AMD Cryptographic Coprocessor (CCP) AES XTS crypto API support
1887 *
1888 - * Copyright (C) 2013 Advanced Micro Devices, Inc.
1889 + * Copyright (C) 2013,2017 Advanced Micro Devices, Inc.
1890 *
1891 + * Author: Gary R Hook <gary.hook@amd.com>
1892 * Author: Tom Lendacky <thomas.lendacky@amd.com>
1893 *
1894 * This program is free software; you can redistribute it and/or modify
1895 @@ -164,6 +165,7 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req,
1896 memset(&rctx->cmd, 0, sizeof(rctx->cmd));
1897 INIT_LIST_HEAD(&rctx->cmd.entry);
1898 rctx->cmd.engine = CCP_ENGINE_XTS_AES_128;
1899 + rctx->cmd.u.xts.type = CCP_AES_TYPE_128;
1900 rctx->cmd.u.xts.action = (encrypt) ? CCP_AES_ACTION_ENCRYPT
1901 : CCP_AES_ACTION_DECRYPT;
1902 rctx->cmd.u.xts.unit_size = unit_size;
1903 diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
1904 index 2c0ce5f605b3..17b19a68e269 100644
1905 --- a/drivers/crypto/ccp/ccp-dev-v5.c
1906 +++ b/drivers/crypto/ccp/ccp-dev-v5.c
1907 @@ -131,6 +131,7 @@ union ccp_function {
1908 #define CCP_AES_MODE(p) ((p)->aes.mode)
1909 #define CCP_AES_TYPE(p) ((p)->aes.type)
1910 #define CCP_XTS_SIZE(p) ((p)->aes_xts.size)
1911 +#define CCP_XTS_TYPE(p) ((p)->aes_xts.type)
1912 #define CCP_XTS_ENCRYPT(p) ((p)->aes_xts.encrypt)
1913 #define CCP_SHA_TYPE(p) ((p)->sha.type)
1914 #define CCP_RSA_SIZE(p) ((p)->rsa.size)
1915 @@ -318,6 +319,7 @@ static int ccp5_perform_xts_aes(struct ccp_op *op)
1916 CCP5_CMD_PROT(&desc) = 0;
1917
1918 function.raw = 0;
1919 + CCP_XTS_TYPE(&function) = op->u.xts.type;
1920 CCP_XTS_ENCRYPT(&function) = op->u.xts.action;
1921 CCP_XTS_SIZE(&function) = op->u.xts.unit_size;
1922 CCP5_CMD_FUNCTION(&desc) = function.raw;
1923 diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
1924 index 8ac7ae17e1f4..e23c36c7691c 100644
1925 --- a/drivers/crypto/ccp/ccp-dev.h
1926 +++ b/drivers/crypto/ccp/ccp-dev.h
1927 @@ -187,6 +187,7 @@
1928 #define CCP_AES_CTX_SB_COUNT 1
1929
1930 #define CCP_XTS_AES_KEY_SB_COUNT 1
1931 +#define CCP5_XTS_AES_KEY_SB_COUNT 2
1932 #define CCP_XTS_AES_CTX_SB_COUNT 1
1933
1934 #define CCP_SHA_SB_COUNT 1
1935 @@ -472,6 +473,7 @@ struct ccp_aes_op {
1936 };
1937
1938 struct ccp_xts_aes_op {
1939 + enum ccp_aes_type type;
1940 enum ccp_aes_action action;
1941 enum ccp_xts_aes_unit_size unit_size;
1942 };
1943 diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
1944 index 50fae4442801..64deb006c3be 100644
1945 --- a/drivers/crypto/ccp/ccp-ops.c
1946 +++ b/drivers/crypto/ccp/ccp-ops.c
1947 @@ -779,6 +779,8 @@ static int ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q,
1948 struct ccp_op op;
1949 unsigned int unit_size, dm_offset;
1950 bool in_place = false;
1951 + unsigned int sb_count;
1952 + enum ccp_aes_type aestype;
1953 int ret;
1954
1955 switch (xts->unit_size) {
1956 @@ -802,7 +804,9 @@ static int ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q,
1957 return -EINVAL;
1958 }
1959
1960 - if (xts->key_len != AES_KEYSIZE_128)
1961 + if (xts->key_len == AES_KEYSIZE_128)
1962 + aestype = CCP_AES_TYPE_128;
1963 + else
1964 return -EINVAL;
1965
1966 if (!xts->final && (xts->src_len & (AES_BLOCK_SIZE - 1)))
1967 @@ -824,23 +828,44 @@ static int ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q,
1968 op.sb_key = cmd_q->sb_key;
1969 op.sb_ctx = cmd_q->sb_ctx;
1970 op.init = 1;
1971 + op.u.xts.type = aestype;
1972 op.u.xts.action = xts->action;
1973 op.u.xts.unit_size = xts->unit_size;
1974
1975 - /* All supported key sizes fit in a single (32-byte) SB entry
1976 - * and must be in little endian format. Use the 256-bit byte
1977 - * swap passthru option to convert from big endian to little
1978 - * endian.
1979 + /* A version 3 device only supports 128-bit keys, which fits into a
1980 + * single SB entry. A version 5 device uses a 512-bit vector, so two
1981 + * SB entries.
1982 */
1983 + if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0))
1984 + sb_count = CCP_XTS_AES_KEY_SB_COUNT;
1985 + else
1986 + sb_count = CCP5_XTS_AES_KEY_SB_COUNT;
1987 ret = ccp_init_dm_workarea(&key, cmd_q,
1988 - CCP_XTS_AES_KEY_SB_COUNT * CCP_SB_BYTES,
1989 + sb_count * CCP_SB_BYTES,
1990 DMA_TO_DEVICE);
1991 if (ret)
1992 return ret;
1993
1994 - dm_offset = CCP_SB_BYTES - AES_KEYSIZE_128;
1995 - ccp_set_dm_area(&key, dm_offset, xts->key, 0, xts->key_len);
1996 - ccp_set_dm_area(&key, 0, xts->key, dm_offset, xts->key_len);
1997 + if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0)) {
1998 + /* All supported key sizes must be in little endian format.
1999 + * Use the 256-bit byte swap passthru option to convert from
2000 + * big endian to little endian.
2001 + */
2002 + dm_offset = CCP_SB_BYTES - AES_KEYSIZE_128;
2003 + ccp_set_dm_area(&key, dm_offset, xts->key, 0, xts->key_len);
2004 + ccp_set_dm_area(&key, 0, xts->key, xts->key_len, xts->key_len);
2005 + } else {
2006 + /* Version 5 CCPs use a 512-bit space for the key: each portion
2007 + * occupies 256 bits, or one entire slot, and is zero-padded.
2008 + */
2009 + unsigned int pad;
2010 +
2011 + dm_offset = CCP_SB_BYTES;
2012 + pad = dm_offset - xts->key_len;
2013 + ccp_set_dm_area(&key, pad, xts->key, 0, xts->key_len);
2014 + ccp_set_dm_area(&key, dm_offset + pad, xts->key, xts->key_len,
2015 + xts->key_len);
2016 + }
2017 ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
2018 CCP_PASSTHRU_BYTESWAP_256BIT);
2019 if (ret) {
2020 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
2021 index 7309c0824887..a2449d77af07 100644
2022 --- a/drivers/devfreq/devfreq.c
2023 +++ b/drivers/devfreq/devfreq.c
2024 @@ -574,7 +574,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
2025 err = device_register(&devfreq->dev);
2026 if (err) {
2027 mutex_unlock(&devfreq->lock);
2028 - goto err_out;
2029 + goto err_dev;
2030 }
2031
2032 devfreq->trans_table = devm_kzalloc(&devfreq->dev, sizeof(unsigned int) *
2033 @@ -618,6 +618,9 @@ struct devfreq *devfreq_add_device(struct device *dev,
2034 mutex_unlock(&devfreq_list_lock);
2035
2036 device_unregister(&devfreq->dev);
2037 +err_dev:
2038 + if (devfreq)
2039 + kfree(devfreq);
2040 err_out:
2041 return ERR_PTR(err);
2042 }
2043 diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c b/drivers/gpu/drm/sun4i/sun4i_drv.c
2044 index c3b21865443e..1feec34ca9dd 100644
2045 --- a/drivers/gpu/drm/sun4i/sun4i_drv.c
2046 +++ b/drivers/gpu/drm/sun4i/sun4i_drv.c
2047 @@ -47,6 +47,13 @@ static void sun4i_drv_disable_vblank(struct drm_device *drm, unsigned int pipe)
2048 sun4i_tcon_enable_vblank(tcon, false);
2049 }
2050
2051 +static void sun4i_drv_lastclose(struct drm_device *dev)
2052 +{
2053 + struct sun4i_drv *drv = dev->dev_private;
2054 +
2055 + drm_fbdev_cma_restore_mode(drv->fbdev);
2056 +}
2057 +
2058 static const struct file_operations sun4i_drv_fops = {
2059 .owner = THIS_MODULE,
2060 .open = drm_open,
2061 @@ -65,6 +72,7 @@ static struct drm_driver sun4i_drv_driver = {
2062 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_ATOMIC,
2063
2064 /* Generic Operations */
2065 + .lastclose = sun4i_drv_lastclose,
2066 .fops = &sun4i_drv_fops,
2067 .name = "sun4i-drm",
2068 .desc = "Allwinner sun4i Display Engine",
2069 diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
2070 index 63e82f8e8308..fb4ce0394ac7 100644
2071 --- a/drivers/infiniband/core/addr.c
2072 +++ b/drivers/infiniband/core/addr.c
2073 @@ -446,15 +446,10 @@ static int addr6_resolve(struct sockaddr_in6 *src_in,
2074
2075 ret = ipv6_stub->ipv6_dst_lookup(addr->net, NULL, &dst, &fl6);
2076 if (ret < 0)
2077 - goto put;
2078 + return ret;
2079
2080 rt = (struct rt6_info *)dst;
2081 - if (ipv6_addr_any(&fl6.saddr)) {
2082 - ret = ipv6_dev_get_saddr(addr->net, ip6_dst_idev(dst)->dev,
2083 - &fl6.daddr, 0, &fl6.saddr);
2084 - if (ret)
2085 - goto put;
2086 -
2087 + if (ipv6_addr_any(&src_in->sin6_addr)) {
2088 src_in->sin6_family = AF_INET6;
2089 src_in->sin6_addr = fl6.saddr;
2090 }
2091 @@ -471,9 +466,6 @@ static int addr6_resolve(struct sockaddr_in6 *src_in,
2092
2093 *pdst = dst;
2094 return 0;
2095 -put:
2096 - dst_release(dst);
2097 - return ret;
2098 }
2099 #else
2100 static int addr6_resolve(struct sockaddr_in6 *src_in,
2101 diff --git a/drivers/infiniband/hw/hfi1/rc.c b/drivers/infiniband/hw/hfi1/rc.c
2102 index 4bd5b5caa243..613074e963bb 100644
2103 --- a/drivers/infiniband/hw/hfi1/rc.c
2104 +++ b/drivers/infiniband/hw/hfi1/rc.c
2105 @@ -551,7 +551,7 @@ int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
2106 case IB_WR_RDMA_WRITE:
2107 if (newreq && !(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
2108 qp->s_lsn++;
2109 - /* FALLTHROUGH */
2110 + goto no_flow_control;
2111 case IB_WR_RDMA_WRITE_WITH_IMM:
2112 /* If no credit, return. */
2113 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
2114 @@ -559,6 +559,7 @@ int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
2115 qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
2116 goto bail;
2117 }
2118 +no_flow_control:
2119 put_ib_reth_vaddr(
2120 wqe->rdma_wr.remote_addr,
2121 &ohdr->u.rc.reth);
2122 diff --git a/drivers/infiniband/hw/qib/qib_rc.c b/drivers/infiniband/hw/qib/qib_rc.c
2123 index f3fe787c9426..c1523f9a3c12 100644
2124 --- a/drivers/infiniband/hw/qib/qib_rc.c
2125 +++ b/drivers/infiniband/hw/qib/qib_rc.c
2126 @@ -357,7 +357,7 @@ int qib_make_rc_req(struct rvt_qp *qp, unsigned long *flags)
2127 case IB_WR_RDMA_WRITE:
2128 if (newreq && !(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
2129 qp->s_lsn++;
2130 - /* FALLTHROUGH */
2131 + goto no_flow_control;
2132 case IB_WR_RDMA_WRITE_WITH_IMM:
2133 /* If no credit, return. */
2134 if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
2135 @@ -365,7 +365,7 @@ int qib_make_rc_req(struct rvt_qp *qp, unsigned long *flags)
2136 qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
2137 goto bail;
2138 }
2139 -
2140 +no_flow_control:
2141 ohdr->u.rc.reth.vaddr =
2142 cpu_to_be64(wqe->rdma_wr.remote_addr);
2143 ohdr->u.rc.reth.rkey =
2144 diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
2145 index 5be14ad29d46..dbf09836ff30 100644
2146 --- a/drivers/input/serio/i8042-x86ia64io.h
2147 +++ b/drivers/input/serio/i8042-x86ia64io.h
2148 @@ -904,6 +904,13 @@ static const struct dmi_system_id __initconst i8042_dmi_kbdreset_table[] = {
2149 DMI_MATCH(DMI_PRODUCT_NAME, "P34"),
2150 },
2151 },
2152 + {
2153 + /* Gigabyte P57 - Elantech touchpad */
2154 + .matches = {
2155 + DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"),
2156 + DMI_MATCH(DMI_PRODUCT_NAME, "P57"),
2157 + },
2158 + },
2159 {
2160 /* Schenker XMG C504 - Elantech touchpad */
2161 .matches = {
2162 diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
2163 index c3ea03c9a1a8..02619cabda8b 100644
2164 --- a/drivers/md/bcache/bcache.h
2165 +++ b/drivers/md/bcache/bcache.h
2166 @@ -333,6 +333,7 @@ struct cached_dev {
2167 /* Limit number of writeback bios in flight */
2168 struct semaphore in_flight;
2169 struct task_struct *writeback_thread;
2170 + struct workqueue_struct *writeback_write_wq;
2171
2172 struct keybuf writeback_keys;
2173
2174 diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
2175 index a37c1776f2e3..e0f1c6d534fe 100644
2176 --- a/drivers/md/bcache/request.c
2177 +++ b/drivers/md/bcache/request.c
2178 @@ -196,12 +196,12 @@ static void bch_data_insert_start(struct closure *cl)
2179 struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
2180 struct bio *bio = op->bio, *n;
2181
2182 - if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0)
2183 - wake_up_gc(op->c);
2184 -
2185 if (op->bypass)
2186 return bch_data_invalidate(cl);
2187
2188 + if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0)
2189 + wake_up_gc(op->c);
2190 +
2191 /*
2192 * Journal writes are marked REQ_PREFLUSH; if the original write was a
2193 * flush, it'll wait on the journal write.
2194 diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
2195 index 66669c8f4161..f4557f558b24 100644
2196 --- a/drivers/md/bcache/super.c
2197 +++ b/drivers/md/bcache/super.c
2198 @@ -1025,7 +1025,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c)
2199 }
2200
2201 if (BDEV_STATE(&dc->sb) == BDEV_STATE_DIRTY) {
2202 - bch_sectors_dirty_init(dc);
2203 + bch_sectors_dirty_init(&dc->disk);
2204 atomic_set(&dc->has_dirty, 1);
2205 atomic_inc(&dc->count);
2206 bch_writeback_queue(dc);
2207 @@ -1058,6 +1058,8 @@ static void cached_dev_free(struct closure *cl)
2208 cancel_delayed_work_sync(&dc->writeback_rate_update);
2209 if (!IS_ERR_OR_NULL(dc->writeback_thread))
2210 kthread_stop(dc->writeback_thread);
2211 + if (dc->writeback_write_wq)
2212 + destroy_workqueue(dc->writeback_write_wq);
2213
2214 mutex_lock(&bch_register_lock);
2215
2216 @@ -1229,6 +1231,7 @@ static int flash_dev_run(struct cache_set *c, struct uuid_entry *u)
2217 goto err;
2218
2219 bcache_device_attach(d, c, u - c->uuids);
2220 + bch_sectors_dirty_init(d);
2221 bch_flash_dev_request_init(d);
2222 add_disk(d->disk);
2223
2224 @@ -1967,6 +1970,8 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
2225 else
2226 err = "device busy";
2227 mutex_unlock(&bch_register_lock);
2228 + if (!IS_ERR(bdev))
2229 + bdput(bdev);
2230 if (attr == &ksysfs_register_quiet)
2231 goto out;
2232 }
2233 diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
2234 index b3ff57d61dde..4fbb5532f24c 100644
2235 --- a/drivers/md/bcache/sysfs.c
2236 +++ b/drivers/md/bcache/sysfs.c
2237 @@ -191,7 +191,7 @@ STORE(__cached_dev)
2238 {
2239 struct cached_dev *dc = container_of(kobj, struct cached_dev,
2240 disk.kobj);
2241 - unsigned v = size;
2242 + ssize_t v = size;
2243 struct cache_set *c;
2244 struct kobj_uevent_env *env;
2245
2246 @@ -226,7 +226,7 @@ STORE(__cached_dev)
2247 bch_cached_dev_run(dc);
2248
2249 if (attr == &sysfs_cache_mode) {
2250 - ssize_t v = bch_read_string_list(buf, bch_cache_modes + 1);
2251 + v = bch_read_string_list(buf, bch_cache_modes + 1);
2252
2253 if (v < 0)
2254 return v;
2255 diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c
2256 index dde6172f3f10..eb70f6894f05 100644
2257 --- a/drivers/md/bcache/util.c
2258 +++ b/drivers/md/bcache/util.c
2259 @@ -73,24 +73,44 @@ STRTO_H(strtouint, unsigned int)
2260 STRTO_H(strtoll, long long)
2261 STRTO_H(strtoull, unsigned long long)
2262
2263 +/**
2264 + * bch_hprint() - formats @v to human readable string for sysfs.
2265 + *
2266 + * @v - signed 64 bit integer
2267 + * @buf - the (at least 8 byte) buffer to format the result into.
2268 + *
2269 + * Returns the number of bytes used by format.
2270 + */
2271 ssize_t bch_hprint(char *buf, int64_t v)
2272 {
2273 static const char units[] = "?kMGTPEZY";
2274 - char dec[4] = "";
2275 - int u, t = 0;
2276 -
2277 - for (u = 0; v >= 1024 || v <= -1024; u++) {
2278 - t = v & ~(~0 << 10);
2279 - v >>= 10;
2280 - }
2281 -
2282 - if (!u)
2283 - return sprintf(buf, "%llu", v);
2284 -
2285 - if (v < 100 && v > -100)
2286 - snprintf(dec, sizeof(dec), ".%i", t / 100);
2287 -
2288 - return sprintf(buf, "%lli%s%c", v, dec, units[u]);
2289 + int u = 0, t;
2290 +
2291 + uint64_t q;
2292 +
2293 + if (v < 0)
2294 + q = -v;
2295 + else
2296 + q = v;
2297 +
2298 + /* For as long as the number is more than 3 digits, but at least
2299 + * once, shift right / divide by 1024. Keep the remainder for
2300 + * a digit after the decimal point.
2301 + */
2302 + do {
2303 + u++;
2304 +
2305 + t = q & ~(~0 << 10);
2306 + q >>= 10;
2307 + } while (q >= 1000);
2308 +
2309 + if (v < 0)
2310 + /* '-', up to 3 digits, '.', 1 digit, 1 character, null;
2311 + * yields 8 bytes.
2312 + */
2313 + return sprintf(buf, "-%llu.%i%c", q, t * 10 / 1024, units[u]);
2314 + else
2315 + return sprintf(buf, "%llu.%i%c", q, t * 10 / 1024, units[u]);
2316 }
2317
2318 ssize_t bch_snprint_string_list(char *buf, size_t size, const char * const list[],
2319 diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
2320 index e51644e503a5..4ce2b19fe120 100644
2321 --- a/drivers/md/bcache/writeback.c
2322 +++ b/drivers/md/bcache/writeback.c
2323 @@ -20,7 +20,8 @@
2324 static void __update_writeback_rate(struct cached_dev *dc)
2325 {
2326 struct cache_set *c = dc->disk.c;
2327 - uint64_t cache_sectors = c->nbuckets * c->sb.bucket_size;
2328 + uint64_t cache_sectors = c->nbuckets * c->sb.bucket_size -
2329 + bcache_flash_devs_sectors_dirty(c);
2330 uint64_t cache_dirty_target =
2331 div_u64(cache_sectors * dc->writeback_percent, 100);
2332
2333 @@ -186,7 +187,7 @@ static void write_dirty(struct closure *cl)
2334
2335 closure_bio_submit(&io->bio, cl);
2336
2337 - continue_at(cl, write_dirty_finish, system_wq);
2338 + continue_at(cl, write_dirty_finish, io->dc->writeback_write_wq);
2339 }
2340
2341 static void read_dirty_endio(struct bio *bio)
2342 @@ -206,7 +207,7 @@ static void read_dirty_submit(struct closure *cl)
2343
2344 closure_bio_submit(&io->bio, cl);
2345
2346 - continue_at(cl, write_dirty, system_wq);
2347 + continue_at(cl, write_dirty, io->dc->writeback_write_wq);
2348 }
2349
2350 static void read_dirty(struct cached_dev *dc)
2351 @@ -482,17 +483,17 @@ static int sectors_dirty_init_fn(struct btree_op *_op, struct btree *b,
2352 return MAP_CONTINUE;
2353 }
2354
2355 -void bch_sectors_dirty_init(struct cached_dev *dc)
2356 +void bch_sectors_dirty_init(struct bcache_device *d)
2357 {
2358 struct sectors_dirty_init op;
2359
2360 bch_btree_op_init(&op.op, -1);
2361 - op.inode = dc->disk.id;
2362 + op.inode = d->id;
2363
2364 - bch_btree_map_keys(&op.op, dc->disk.c, &KEY(op.inode, 0, 0),
2365 + bch_btree_map_keys(&op.op, d->c, &KEY(op.inode, 0, 0),
2366 sectors_dirty_init_fn, 0);
2367
2368 - dc->disk.sectors_dirty_last = bcache_dev_sectors_dirty(&dc->disk);
2369 + d->sectors_dirty_last = bcache_dev_sectors_dirty(d);
2370 }
2371
2372 void bch_cached_dev_writeback_init(struct cached_dev *dc)
2373 @@ -516,6 +517,11 @@ void bch_cached_dev_writeback_init(struct cached_dev *dc)
2374
2375 int bch_cached_dev_writeback_start(struct cached_dev *dc)
2376 {
2377 + dc->writeback_write_wq = alloc_workqueue("bcache_writeback_wq",
2378 + WQ_MEM_RECLAIM, 0);
2379 + if (!dc->writeback_write_wq)
2380 + return -ENOMEM;
2381 +
2382 dc->writeback_thread = kthread_create(bch_writeback_thread, dc,
2383 "bcache_writeback");
2384 if (IS_ERR(dc->writeback_thread))
2385 diff --git a/drivers/md/bcache/writeback.h b/drivers/md/bcache/writeback.h
2386 index 301eaf565167..cdf8d253209e 100644
2387 --- a/drivers/md/bcache/writeback.h
2388 +++ b/drivers/md/bcache/writeback.h
2389 @@ -14,6 +14,25 @@ static inline uint64_t bcache_dev_sectors_dirty(struct bcache_device *d)
2390 return ret;
2391 }
2392
2393 +static inline uint64_t bcache_flash_devs_sectors_dirty(struct cache_set *c)
2394 +{
2395 + uint64_t i, ret = 0;
2396 +
2397 + mutex_lock(&bch_register_lock);
2398 +
2399 + for (i = 0; i < c->nr_uuids; i++) {
2400 + struct bcache_device *d = c->devices[i];
2401 +
2402 + if (!d || !UUID_FLASH_ONLY(&c->uuids[i]))
2403 + continue;
2404 + ret += bcache_dev_sectors_dirty(d);
2405 + }
2406 +
2407 + mutex_unlock(&bch_register_lock);
2408 +
2409 + return ret;
2410 +}
2411 +
2412 static inline unsigned offset_to_stripe(struct bcache_device *d,
2413 uint64_t offset)
2414 {
2415 @@ -85,7 +104,7 @@ static inline void bch_writeback_add(struct cached_dev *dc)
2416
2417 void bcache_dev_sectors_dirty_add(struct cache_set *, unsigned, uint64_t, int);
2418
2419 -void bch_sectors_dirty_init(struct cached_dev *dc);
2420 +void bch_sectors_dirty_init(struct bcache_device *);
2421 void bch_cached_dev_writeback_init(struct cached_dev *);
2422 int bch_cached_dev_writeback_start(struct cached_dev *);
2423
2424 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
2425 index 2d826927a3bf..fb02c3979bf4 100644
2426 --- a/drivers/md/bitmap.c
2427 +++ b/drivers/md/bitmap.c
2428 @@ -1992,6 +1992,11 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
2429 long pages;
2430 struct bitmap_page *new_bp;
2431
2432 + if (bitmap->storage.file && !init) {
2433 + pr_info("md: cannot resize file-based bitmap\n");
2434 + return -EINVAL;
2435 + }
2436 +
2437 if (chunksize == 0) {
2438 /* If there is enough space, leave the chunk size unchanged,
2439 * else increase by factor of two until there is enough space.
2440 diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
2441 index c2ee6e39fd0c..20397aba6849 100644
2442 --- a/drivers/media/usb/uvc/uvc_ctrl.c
2443 +++ b/drivers/media/usb/uvc/uvc_ctrl.c
2444 @@ -2002,6 +2002,13 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
2445 goto done;
2446 }
2447
2448 + /* Validate the user-provided bit-size and offset */
2449 + if (mapping->size > 32 ||
2450 + mapping->offset + mapping->size > ctrl->info.size * 8) {
2451 + ret = -EINVAL;
2452 + goto done;
2453 + }
2454 +
2455 list_for_each_entry(map, &ctrl->info.mappings, list) {
2456 if (mapping->id == map->id) {
2457 uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', "
2458 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
2459 index bacecbd68a6d..dc51dd86377d 100644
2460 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
2461 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
2462 @@ -773,7 +773,8 @@ static int put_v4l2_event32(struct v4l2_event *kp, struct v4l2_event32 __user *u
2463 copy_to_user(&up->u, &kp->u, sizeof(kp->u)) ||
2464 put_user(kp->pending, &up->pending) ||
2465 put_user(kp->sequence, &up->sequence) ||
2466 - compat_put_timespec(&kp->timestamp, &up->timestamp) ||
2467 + put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
2468 + put_user(kp->timestamp.tv_nsec, &up->timestamp.tv_nsec) ||
2469 put_user(kp->id, &up->id) ||
2470 copy_to_user(up->reserved, kp->reserved, 8 * sizeof(__u32)))
2471 return -EFAULT;
2472 diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
2473 index b57fc6d6e28a..d08dfc8b9ba9 100644
2474 --- a/drivers/pci/hotplug/pciehp_hpc.c
2475 +++ b/drivers/pci/hotplug/pciehp_hpc.c
2476 @@ -586,6 +586,14 @@ static irqreturn_t pciehp_isr(int irq, void *dev_id)
2477 events = status & (PCI_EXP_SLTSTA_ABP | PCI_EXP_SLTSTA_PFD |
2478 PCI_EXP_SLTSTA_PDC | PCI_EXP_SLTSTA_CC |
2479 PCI_EXP_SLTSTA_DLLSC);
2480 +
2481 + /*
2482 + * If we've already reported a power fault, don't report it again
2483 + * until we've done something to handle it.
2484 + */
2485 + if (ctrl->power_fault_detected)
2486 + events &= ~PCI_EXP_SLTSTA_PFD;
2487 +
2488 if (!events)
2489 return IRQ_NONE;
2490
2491 diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c
2492 index de0ea474fb73..e5824c7b7b6b 100644
2493 --- a/drivers/pci/hotplug/shpchp_hpc.c
2494 +++ b/drivers/pci/hotplug/shpchp_hpc.c
2495 @@ -1062,6 +1062,8 @@ int shpc_init(struct controller *ctrl, struct pci_dev *pdev)
2496 if (rc) {
2497 ctrl_info(ctrl, "Can't get msi for the hotplug controller\n");
2498 ctrl_info(ctrl, "Use INTx for the hotplug controller\n");
2499 + } else {
2500 + pci_set_master(pdev);
2501 }
2502
2503 rc = request_irq(ctrl->pci_dev->irq, shpc_isr, IRQF_SHARED,
2504 diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
2505 index c9a146948192..a5b7bd3c9bac 100644
2506 --- a/drivers/pinctrl/pinctrl-amd.c
2507 +++ b/drivers/pinctrl/pinctrl-amd.c
2508 @@ -32,6 +32,7 @@
2509 #include <linux/pinctrl/pinconf.h>
2510 #include <linux/pinctrl/pinconf-generic.h>
2511
2512 +#include "core.h"
2513 #include "pinctrl-utils.h"
2514 #include "pinctrl-amd.h"
2515
2516 @@ -712,6 +713,69 @@ static const struct pinconf_ops amd_pinconf_ops = {
2517 .pin_config_group_set = amd_pinconf_group_set,
2518 };
2519
2520 +#ifdef CONFIG_PM_SLEEP
2521 +static bool amd_gpio_should_save(struct amd_gpio *gpio_dev, unsigned int pin)
2522 +{
2523 + const struct pin_desc *pd = pin_desc_get(gpio_dev->pctrl, pin);
2524 +
2525 + if (!pd)
2526 + return false;
2527 +
2528 + /*
2529 + * Only restore the pin if it is actually in use by the kernel (or
2530 + * by userspace).
2531 + */
2532 + if (pd->mux_owner || pd->gpio_owner ||
2533 + gpiochip_line_is_irq(&gpio_dev->gc, pin))
2534 + return true;
2535 +
2536 + return false;
2537 +}
2538 +
2539 +int amd_gpio_suspend(struct device *dev)
2540 +{
2541 + struct platform_device *pdev = to_platform_device(dev);
2542 + struct amd_gpio *gpio_dev = platform_get_drvdata(pdev);
2543 + struct pinctrl_desc *desc = gpio_dev->pctrl->desc;
2544 + int i;
2545 +
2546 + for (i = 0; i < desc->npins; i++) {
2547 + int pin = desc->pins[i].number;
2548 +
2549 + if (!amd_gpio_should_save(gpio_dev, pin))
2550 + continue;
2551 +
2552 + gpio_dev->saved_regs[i] = readl(gpio_dev->base + pin*4);
2553 + }
2554 +
2555 + return 0;
2556 +}
2557 +
2558 +int amd_gpio_resume(struct device *dev)
2559 +{
2560 + struct platform_device *pdev = to_platform_device(dev);
2561 + struct amd_gpio *gpio_dev = platform_get_drvdata(pdev);
2562 + struct pinctrl_desc *desc = gpio_dev->pctrl->desc;
2563 + int i;
2564 +
2565 + for (i = 0; i < desc->npins; i++) {
2566 + int pin = desc->pins[i].number;
2567 +
2568 + if (!amd_gpio_should_save(gpio_dev, pin))
2569 + continue;
2570 +
2571 + writel(gpio_dev->saved_regs[i], gpio_dev->base + pin*4);
2572 + }
2573 +
2574 + return 0;
2575 +}
2576 +
2577 +static const struct dev_pm_ops amd_gpio_pm_ops = {
2578 + SET_LATE_SYSTEM_SLEEP_PM_OPS(amd_gpio_suspend,
2579 + amd_gpio_resume)
2580 +};
2581 +#endif
2582 +
2583 static struct pinctrl_desc amd_pinctrl_desc = {
2584 .pins = kerncz_pins,
2585 .npins = ARRAY_SIZE(kerncz_pins),
2586 @@ -751,6 +815,14 @@ static int amd_gpio_probe(struct platform_device *pdev)
2587 return -EINVAL;
2588 }
2589
2590 +#ifdef CONFIG_PM_SLEEP
2591 + gpio_dev->saved_regs = devm_kcalloc(&pdev->dev, amd_pinctrl_desc.npins,
2592 + sizeof(*gpio_dev->saved_regs),
2593 + GFP_KERNEL);
2594 + if (!gpio_dev->saved_regs)
2595 + return -ENOMEM;
2596 +#endif
2597 +
2598 gpio_dev->pdev = pdev;
2599 gpio_dev->gc.direction_input = amd_gpio_direction_input;
2600 gpio_dev->gc.direction_output = amd_gpio_direction_output;
2601 @@ -839,6 +911,9 @@ static struct platform_driver amd_gpio_driver = {
2602 .driver = {
2603 .name = "amd_gpio",
2604 .acpi_match_table = ACPI_PTR(amd_gpio_acpi_match),
2605 +#ifdef CONFIG_PM_SLEEP
2606 + .pm = &amd_gpio_pm_ops,
2607 +#endif
2608 },
2609 .probe = amd_gpio_probe,
2610 .remove = amd_gpio_remove,
2611 diff --git a/drivers/pinctrl/pinctrl-amd.h b/drivers/pinctrl/pinctrl-amd.h
2612 index 7bfea47dbb47..e8bbb20779d0 100644
2613 --- a/drivers/pinctrl/pinctrl-amd.h
2614 +++ b/drivers/pinctrl/pinctrl-amd.h
2615 @@ -95,6 +95,7 @@ struct amd_gpio {
2616 struct gpio_chip gc;
2617 struct resource *res;
2618 struct platform_device *pdev;
2619 + u32 *saved_regs;
2620 };
2621
2622 /* KERNCZ configuration*/
2623 diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c
2624 index d5bf36ec8a75..34367d172961 100644
2625 --- a/drivers/s390/scsi/zfcp_dbf.c
2626 +++ b/drivers/s390/scsi/zfcp_dbf.c
2627 @@ -3,7 +3,7 @@
2628 *
2629 * Debug traces for zfcp.
2630 *
2631 - * Copyright IBM Corp. 2002, 2016
2632 + * Copyright IBM Corp. 2002, 2017
2633 */
2634
2635 #define KMSG_COMPONENT "zfcp"
2636 @@ -447,6 +447,7 @@ static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag,
2637 struct fc_ct_hdr *reqh = sg_virt(ct_els->req);
2638 struct fc_ns_gid_ft *reqn = (struct fc_ns_gid_ft *)(reqh + 1);
2639 struct scatterlist *resp_entry = ct_els->resp;
2640 + struct fc_ct_hdr *resph;
2641 struct fc_gpn_ft_resp *acc;
2642 int max_entries, x, last = 0;
2643
2644 @@ -473,6 +474,13 @@ static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag,
2645 return len; /* not GPN_FT response so do not cap */
2646
2647 acc = sg_virt(resp_entry);
2648 +
2649 + /* cap all but accept CT responses to at least the CT header */
2650 + resph = (struct fc_ct_hdr *)acc;
2651 + if ((ct_els->status) ||
2652 + (resph->ct_cmd != cpu_to_be16(FC_FS_ACC)))
2653 + return max(FC_CT_HDR_LEN, ZFCP_DBF_SAN_MAX_PAYLOAD);
2654 +
2655 max_entries = (reqh->ct_mr_size * 4 / sizeof(struct fc_gpn_ft_resp))
2656 + 1 /* zfcp_fc_scan_ports: bytes correct, entries off-by-one
2657 * to account for header as 1st pseudo "entry" */;
2658 @@ -555,8 +563,8 @@ void zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *sc,
2659 rec->scsi_retries = sc->retries;
2660 rec->scsi_allowed = sc->allowed;
2661 rec->scsi_id = sc->device->id;
2662 - /* struct zfcp_dbf_scsi needs to be updated to handle 64bit LUNs */
2663 rec->scsi_lun = (u32)sc->device->lun;
2664 + rec->scsi_lun_64_hi = (u32)(sc->device->lun >> 32);
2665 rec->host_scribble = (unsigned long)sc->host_scribble;
2666
2667 memcpy(rec->scsi_opcode, sc->cmnd,
2668 @@ -564,19 +572,32 @@ void zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *sc,
2669
2670 if (fsf) {
2671 rec->fsf_req_id = fsf->req_id;
2672 + rec->pl_len = FCP_RESP_WITH_EXT;
2673 fcp_rsp = (struct fcp_resp_with_ext *)
2674 &(fsf->qtcb->bottom.io.fcp_rsp);
2675 + /* mandatory parts of FCP_RSP IU in this SCSI record */
2676 memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT);
2677 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) {
2678 fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2679 rec->fcp_rsp_info = fcp_rsp_info->rsp_code;
2680 + rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_rsp_len);
2681 }
2682 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
2683 - rec->pl_len = min((u16)SCSI_SENSE_BUFFERSIZE,
2684 - (u16)ZFCP_DBF_PAY_MAX_REC);
2685 - zfcp_dbf_pl_write(dbf, sc->sense_buffer, rec->pl_len,
2686 - "fcp_sns", fsf->req_id);
2687 + rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_sns_len);
2688 }
2689 + /* complete FCP_RSP IU in associated PAYload record
2690 + * but only if there are optional parts
2691 + */
2692 + if (fcp_rsp->resp.fr_flags != 0)
2693 + zfcp_dbf_pl_write(
2694 + dbf, fcp_rsp,
2695 + /* at least one full PAY record
2696 + * but not beyond hardware response field
2697 + */
2698 + min_t(u16, max_t(u16, rec->pl_len,
2699 + ZFCP_DBF_PAY_MAX_REC),
2700 + FSF_FCP_RSP_SIZE),
2701 + "fcp_riu", fsf->req_id);
2702 }
2703
2704 debug_event(dbf->scsi, level, rec, sizeof(*rec));
2705 diff --git a/drivers/s390/scsi/zfcp_dbf.h b/drivers/s390/scsi/zfcp_dbf.h
2706 index db186d44cfaf..b60667c145fd 100644
2707 --- a/drivers/s390/scsi/zfcp_dbf.h
2708 +++ b/drivers/s390/scsi/zfcp_dbf.h
2709 @@ -2,7 +2,7 @@
2710 * zfcp device driver
2711 * debug feature declarations
2712 *
2713 - * Copyright IBM Corp. 2008, 2016
2714 + * Copyright IBM Corp. 2008, 2017
2715 */
2716
2717 #ifndef ZFCP_DBF_H
2718 @@ -204,7 +204,7 @@ enum zfcp_dbf_scsi_id {
2719 * @id: unique number of recovery record type
2720 * @tag: identifier string specifying the location of initiation
2721 * @scsi_id: scsi device id
2722 - * @scsi_lun: scsi device logical unit number
2723 + * @scsi_lun: scsi device logical unit number, low part of 64 bit, old 32 bit
2724 * @scsi_result: scsi result
2725 * @scsi_retries: current retry number of scsi request
2726 * @scsi_allowed: allowed retries
2727 @@ -214,6 +214,7 @@ enum zfcp_dbf_scsi_id {
2728 * @host_scribble: LLD specific data attached to SCSI request
2729 * @pl_len: length of paload stored as zfcp_dbf_pay
2730 * @fsf_rsp: response for fsf request
2731 + * @scsi_lun_64_hi: scsi device logical unit number, high part of 64 bit
2732 */
2733 struct zfcp_dbf_scsi {
2734 u8 id;
2735 @@ -230,6 +231,7 @@ struct zfcp_dbf_scsi {
2736 u64 host_scribble;
2737 u16 pl_len;
2738 struct fcp_resp_with_ext fcp_rsp;
2739 + u32 scsi_lun_64_hi;
2740 } __packed;
2741
2742 /**
2743 @@ -323,7 +325,11 @@ void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
2744 {
2745 struct fsf_qtcb *qtcb = req->qtcb;
2746
2747 - if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
2748 + if (unlikely(req->status & (ZFCP_STATUS_FSFREQ_DISMISSED |
2749 + ZFCP_STATUS_FSFREQ_ERROR))) {
2750 + zfcp_dbf_hba_fsf_resp("fs_rerr", 3, req);
2751 +
2752 + } else if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
2753 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
2754 zfcp_dbf_hba_fsf_resp("fs_perr", 1, req);
2755
2756 @@ -401,7 +407,8 @@ void zfcp_dbf_scsi_abort(char *tag, struct scsi_cmnd *scmd,
2757 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
2758 */
2759 static inline
2760 -void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag)
2761 +void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag,
2762 + struct zfcp_fsf_req *fsf_req)
2763 {
2764 char tmp_tag[ZFCP_DBF_TAG_LEN];
2765
2766 @@ -411,7 +418,7 @@ void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag)
2767 memcpy(tmp_tag, "lr_", 3);
2768
2769 memcpy(&tmp_tag[3], tag, 4);
2770 - _zfcp_dbf_scsi(tmp_tag, 1, scmnd, NULL);
2771 + _zfcp_dbf_scsi(tmp_tag, 1, scmnd, fsf_req);
2772 }
2773
2774 /**
2775 diff --git a/drivers/s390/scsi/zfcp_fc.h b/drivers/s390/scsi/zfcp_fc.h
2776 index df2b541c8287..a2275825186f 100644
2777 --- a/drivers/s390/scsi/zfcp_fc.h
2778 +++ b/drivers/s390/scsi/zfcp_fc.h
2779 @@ -4,7 +4,7 @@
2780 * Fibre Channel related definitions and inline functions for the zfcp
2781 * device driver
2782 *
2783 - * Copyright IBM Corp. 2009
2784 + * Copyright IBM Corp. 2009, 2017
2785 */
2786
2787 #ifndef ZFCP_FC_H
2788 @@ -279,6 +279,10 @@ void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
2789 !(rsp_flags & FCP_SNS_LEN_VAL) &&
2790 fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
2791 set_host_byte(scsi, DID_ERROR);
2792 + } else if (unlikely(rsp_flags & FCP_RESID_OVER)) {
2793 + /* FCP_DL was not sufficient for SCSI data length */
2794 + if (fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
2795 + set_host_byte(scsi, DID_ERROR);
2796 }
2797 }
2798
2799 diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
2800 index 27ff38f839fc..1964391db904 100644
2801 --- a/drivers/s390/scsi/zfcp_fsf.c
2802 +++ b/drivers/s390/scsi/zfcp_fsf.c
2803 @@ -928,8 +928,8 @@ static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
2804
2805 switch (header->fsf_status) {
2806 case FSF_GOOD:
2807 - zfcp_dbf_san_res("fsscth2", req);
2808 ct->status = 0;
2809 + zfcp_dbf_san_res("fsscth2", req);
2810 break;
2811 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2812 zfcp_fsf_class_not_supp(req);
2813 @@ -1109,8 +1109,8 @@ static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
2814
2815 switch (header->fsf_status) {
2816 case FSF_GOOD:
2817 - zfcp_dbf_san_res("fsselh1", req);
2818 send_els->status = 0;
2819 + zfcp_dbf_san_res("fsselh1", req);
2820 break;
2821 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2822 zfcp_fsf_class_not_supp(req);
2823 @@ -2258,7 +2258,8 @@ int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
2824 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2825 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
2826
2827 - if (scsi_prot_sg_count(scsi_cmnd)) {
2828 + if ((scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) &&
2829 + scsi_prot_sg_count(scsi_cmnd)) {
2830 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2831 scsi_prot_sg_count(scsi_cmnd));
2832 retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2833 diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
2834 index 07ffdbb5107f..9bd9b9a29dfc 100644
2835 --- a/drivers/s390/scsi/zfcp_scsi.c
2836 +++ b/drivers/s390/scsi/zfcp_scsi.c
2837 @@ -3,7 +3,7 @@
2838 *
2839 * Interface to Linux SCSI midlayer.
2840 *
2841 - * Copyright IBM Corp. 2002, 2016
2842 + * Copyright IBM Corp. 2002, 2017
2843 */
2844
2845 #define KMSG_COMPONENT "zfcp"
2846 @@ -273,25 +273,29 @@ static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags)
2847
2848 zfcp_erp_wait(adapter);
2849 ret = fc_block_scsi_eh(scpnt);
2850 - if (ret)
2851 + if (ret) {
2852 + zfcp_dbf_scsi_devreset("fiof", scpnt, tm_flags, NULL);
2853 return ret;
2854 + }
2855
2856 if (!(atomic_read(&adapter->status) &
2857 ZFCP_STATUS_COMMON_RUNNING)) {
2858 - zfcp_dbf_scsi_devreset("nres", scpnt, tm_flags);
2859 + zfcp_dbf_scsi_devreset("nres", scpnt, tm_flags, NULL);
2860 return SUCCESS;
2861 }
2862 }
2863 - if (!fsf_req)
2864 + if (!fsf_req) {
2865 + zfcp_dbf_scsi_devreset("reqf", scpnt, tm_flags, NULL);
2866 return FAILED;
2867 + }
2868
2869 wait_for_completion(&fsf_req->completion);
2870
2871 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
2872 - zfcp_dbf_scsi_devreset("fail", scpnt, tm_flags);
2873 + zfcp_dbf_scsi_devreset("fail", scpnt, tm_flags, fsf_req);
2874 retval = FAILED;
2875 } else {
2876 - zfcp_dbf_scsi_devreset("okay", scpnt, tm_flags);
2877 + zfcp_dbf_scsi_devreset("okay", scpnt, tm_flags, fsf_req);
2878 zfcp_scsi_forget_cmnds(zfcp_sdev, tm_flags);
2879 }
2880
2881 diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
2882 index d8b1fbd4c8aa..35cbd36f8d3b 100644
2883 --- a/drivers/scsi/megaraid/megaraid_sas_base.c
2884 +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
2885 @@ -1901,9 +1901,12 @@ static void megasas_complete_outstanding_ioctls(struct megasas_instance *instanc
2886 if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) {
2887 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
2888 if (cmd_mfi->sync_cmd &&
2889 - cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT)
2890 + (cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT)) {
2891 + cmd_mfi->frame->hdr.cmd_status =
2892 + MFI_STAT_WRONG_STATE;
2893 megasas_complete_cmd(instance,
2894 cmd_mfi, DID_OK);
2895 + }
2896 }
2897 }
2898 } else {
2899 @@ -5290,7 +5293,8 @@ static int megasas_init_fw(struct megasas_instance *instance)
2900 instance->throttlequeuedepth =
2901 MEGASAS_THROTTLE_QUEUE_DEPTH;
2902
2903 - if (resetwaittime > MEGASAS_RESET_WAIT_TIME)
2904 + if ((resetwaittime < 1) ||
2905 + (resetwaittime > MEGASAS_RESET_WAIT_TIME))
2906 resetwaittime = MEGASAS_RESET_WAIT_TIME;
2907
2908 if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT))
2909 @@ -5459,6 +5463,14 @@ megasas_register_aen(struct megasas_instance *instance, u32 seq_num,
2910 prev_aen.word =
2911 le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]);
2912
2913 + if ((curr_aen.members.class < MFI_EVT_CLASS_DEBUG) ||
2914 + (curr_aen.members.class > MFI_EVT_CLASS_DEAD)) {
2915 + dev_info(&instance->pdev->dev,
2916 + "%s %d out of range class %d send by application\n",
2917 + __func__, __LINE__, curr_aen.members.class);
2918 + return 0;
2919 + }
2920 +
2921 /*
2922 * A class whose enum value is smaller is inclusive of all
2923 * higher values. If a PROGRESS (= -1) was previously
2924 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
2925 index 8c4641b518b5..9a34afcb1c4c 100644
2926 --- a/drivers/scsi/qla2xxx/qla_attr.c
2927 +++ b/drivers/scsi/qla2xxx/qla_attr.c
2928 @@ -318,6 +318,8 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
2929 return -EINVAL;
2930 if (start > ha->optrom_size)
2931 return -EINVAL;
2932 + if (size > ha->optrom_size - start)
2933 + size = ha->optrom_size - start;
2934
2935 mutex_lock(&ha->optrom_mutex);
2936 switch (val) {
2937 @@ -343,8 +345,7 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
2938 }
2939
2940 ha->optrom_region_start = start;
2941 - ha->optrom_region_size = start + size > ha->optrom_size ?
2942 - ha->optrom_size - start : size;
2943 + ha->optrom_region_size = start + size;
2944
2945 ha->optrom_state = QLA_SREADING;
2946 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
2947 @@ -417,8 +418,7 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
2948 }
2949
2950 ha->optrom_region_start = start;
2951 - ha->optrom_region_size = start + size > ha->optrom_size ?
2952 - ha->optrom_size - start : size;
2953 + ha->optrom_region_size = start + size;
2954
2955 ha->optrom_state = QLA_SWRITING;
2956 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
2957 diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
2958 index 3dfb54abc874..f8ae70476b3a 100644
2959 --- a/drivers/scsi/qla2xxx/qla_mid.c
2960 +++ b/drivers/scsi/qla2xxx/qla_mid.c
2961 @@ -74,7 +74,7 @@ qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
2962 * ensures no active vp_list traversal while the vport is removed
2963 * from the queue)
2964 */
2965 - wait_event_timeout(vha->vref_waitq, atomic_read(&vha->vref_count),
2966 + wait_event_timeout(vha->vref_waitq, !atomic_read(&vha->vref_count),
2967 10*HZ);
2968
2969 spin_lock_irqsave(&ha->vport_slock, flags);
2970 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
2971 index 9236a13d5d2a..02dfbc1373e3 100644
2972 --- a/drivers/scsi/sg.c
2973 +++ b/drivers/scsi/sg.c
2974 @@ -122,7 +122,7 @@ struct sg_device; /* forward declarations */
2975 struct sg_fd;
2976
2977 typedef struct sg_request { /* SG_MAX_QUEUE requests outstanding per file */
2978 - struct sg_request *nextrp; /* NULL -> tail request (slist) */
2979 + struct list_head entry; /* list entry */
2980 struct sg_fd *parentfp; /* NULL -> not in use */
2981 Sg_scatter_hold data; /* hold buffer, perhaps scatter list */
2982 sg_io_hdr_t header; /* scsi command+info, see <scsi/sg.h> */
2983 @@ -146,8 +146,7 @@ typedef struct sg_fd { /* holds the state of a file descriptor */
2984 int timeout; /* defaults to SG_DEFAULT_TIMEOUT */
2985 int timeout_user; /* defaults to SG_DEFAULT_TIMEOUT_USER */
2986 Sg_scatter_hold reserve; /* buffer held for this file descriptor */
2987 - unsigned save_scat_len; /* original length of trunc. scat. element */
2988 - Sg_request *headrp; /* head of request slist, NULL->empty */
2989 + struct list_head rq_list; /* head of request list */
2990 struct fasync_struct *async_qp; /* used by asynchronous notification */
2991 Sg_request req_arr[SG_MAX_QUEUE]; /* used as singly-linked list */
2992 char low_dma; /* as in parent but possibly overridden to 1 */
2993 @@ -829,6 +828,39 @@ static int max_sectors_bytes(struct request_queue *q)
2994 return max_sectors << 9;
2995 }
2996
2997 +static void
2998 +sg_fill_request_table(Sg_fd *sfp, sg_req_info_t *rinfo)
2999 +{
3000 + Sg_request *srp;
3001 + int val;
3002 + unsigned int ms;
3003 +
3004 + val = 0;
3005 + list_for_each_entry(srp, &sfp->rq_list, entry) {
3006 + if (val > SG_MAX_QUEUE)
3007 + break;
3008 + rinfo[val].req_state = srp->done + 1;
3009 + rinfo[val].problem =
3010 + srp->header.masked_status &
3011 + srp->header.host_status &
3012 + srp->header.driver_status;
3013 + if (srp->done)
3014 + rinfo[val].duration =
3015 + srp->header.duration;
3016 + else {
3017 + ms = jiffies_to_msecs(jiffies);
3018 + rinfo[val].duration =
3019 + (ms > srp->header.duration) ?
3020 + (ms - srp->header.duration) : 0;
3021 + }
3022 + rinfo[val].orphan = srp->orphan;
3023 + rinfo[val].sg_io_owned = srp->sg_io_owned;
3024 + rinfo[val].pack_id = srp->header.pack_id;
3025 + rinfo[val].usr_ptr = srp->header.usr_ptr;
3026 + val++;
3027 + }
3028 +}
3029 +
3030 static long
3031 sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
3032 {
3033 @@ -941,7 +973,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
3034 if (!access_ok(VERIFY_WRITE, ip, sizeof (int)))
3035 return -EFAULT;
3036 read_lock_irqsave(&sfp->rq_list_lock, iflags);
3037 - for (srp = sfp->headrp; srp; srp = srp->nextrp) {
3038 + list_for_each_entry(srp, &sfp->rq_list, entry) {
3039 if ((1 == srp->done) && (!srp->sg_io_owned)) {
3040 read_unlock_irqrestore(&sfp->rq_list_lock,
3041 iflags);
3042 @@ -954,7 +986,8 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
3043 return 0;
3044 case SG_GET_NUM_WAITING:
3045 read_lock_irqsave(&sfp->rq_list_lock, iflags);
3046 - for (val = 0, srp = sfp->headrp; srp; srp = srp->nextrp) {
3047 + val = 0;
3048 + list_for_each_entry(srp, &sfp->rq_list, entry) {
3049 if ((1 == srp->done) && (!srp->sg_io_owned))
3050 ++val;
3051 }
3052 @@ -1022,42 +1055,15 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
3053 return -EFAULT;
3054 else {
3055 sg_req_info_t *rinfo;
3056 - unsigned int ms;
3057
3058 - rinfo = kmalloc(SZ_SG_REQ_INFO * SG_MAX_QUEUE,
3059 - GFP_KERNEL);
3060 + rinfo = kzalloc(SZ_SG_REQ_INFO * SG_MAX_QUEUE,
3061 + GFP_KERNEL);
3062 if (!rinfo)
3063 return -ENOMEM;
3064 read_lock_irqsave(&sfp->rq_list_lock, iflags);
3065 - for (srp = sfp->headrp, val = 0; val < SG_MAX_QUEUE;
3066 - ++val, srp = srp ? srp->nextrp : srp) {
3067 - memset(&rinfo[val], 0, SZ_SG_REQ_INFO);
3068 - if (srp) {
3069 - rinfo[val].req_state = srp->done + 1;
3070 - rinfo[val].problem =
3071 - srp->header.masked_status &
3072 - srp->header.host_status &
3073 - srp->header.driver_status;
3074 - if (srp->done)
3075 - rinfo[val].duration =
3076 - srp->header.duration;
3077 - else {
3078 - ms = jiffies_to_msecs(jiffies);
3079 - rinfo[val].duration =
3080 - (ms > srp->header.duration) ?
3081 - (ms - srp->header.duration) : 0;
3082 - }
3083 - rinfo[val].orphan = srp->orphan;
3084 - rinfo[val].sg_io_owned =
3085 - srp->sg_io_owned;
3086 - rinfo[val].pack_id =
3087 - srp->header.pack_id;
3088 - rinfo[val].usr_ptr =
3089 - srp->header.usr_ptr;
3090 - }
3091 - }
3092 + sg_fill_request_table(sfp, rinfo);
3093 read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
3094 - result = __copy_to_user(p, rinfo,
3095 + result = __copy_to_user(p, rinfo,
3096 SZ_SG_REQ_INFO * SG_MAX_QUEUE);
3097 result = result ? -EFAULT : 0;
3098 kfree(rinfo);
3099 @@ -1163,7 +1169,7 @@ sg_poll(struct file *filp, poll_table * wait)
3100 return POLLERR;
3101 poll_wait(filp, &sfp->read_wait, wait);
3102 read_lock_irqsave(&sfp->rq_list_lock, iflags);
3103 - for (srp = sfp->headrp; srp; srp = srp->nextrp) {
3104 + list_for_each_entry(srp, &sfp->rq_list, entry) {
3105 /* if any read waiting, flag it */
3106 if ((0 == res) && (1 == srp->done) && (!srp->sg_io_owned))
3107 res = POLLIN | POLLRDNORM;
3108 @@ -2049,7 +2055,6 @@ sg_unlink_reserve(Sg_fd * sfp, Sg_request * srp)
3109 req_schp->pages = NULL;
3110 req_schp->page_order = 0;
3111 req_schp->sglist_len = 0;
3112 - sfp->save_scat_len = 0;
3113 srp->res_used = 0;
3114 /* Called without mutex lock to avoid deadlock */
3115 sfp->res_in_use = 0;
3116 @@ -2062,7 +2067,7 @@ sg_get_rq_mark(Sg_fd * sfp, int pack_id)
3117 unsigned long iflags;
3118
3119 write_lock_irqsave(&sfp->rq_list_lock, iflags);
3120 - for (resp = sfp->headrp; resp; resp = resp->nextrp) {
3121 + list_for_each_entry(resp, &sfp->rq_list, entry) {
3122 /* look for requests that are ready + not SG_IO owned */
3123 if ((1 == resp->done) && (!resp->sg_io_owned) &&
3124 ((-1 == pack_id) || (resp->header.pack_id == pack_id))) {
3125 @@ -2080,70 +2085,45 @@ sg_add_request(Sg_fd * sfp)
3126 {
3127 int k;
3128 unsigned long iflags;
3129 - Sg_request *resp;
3130 Sg_request *rp = sfp->req_arr;
3131
3132 write_lock_irqsave(&sfp->rq_list_lock, iflags);
3133 - resp = sfp->headrp;
3134 - if (!resp) {
3135 - memset(rp, 0, sizeof (Sg_request));
3136 - rp->parentfp = sfp;
3137 - resp = rp;
3138 - sfp->headrp = resp;
3139 - } else {
3140 - if (0 == sfp->cmd_q)
3141 - resp = NULL; /* command queuing disallowed */
3142 - else {
3143 - for (k = 0; k < SG_MAX_QUEUE; ++k, ++rp) {
3144 - if (!rp->parentfp)
3145 - break;
3146 - }
3147 - if (k < SG_MAX_QUEUE) {
3148 - memset(rp, 0, sizeof (Sg_request));
3149 - rp->parentfp = sfp;
3150 - while (resp->nextrp)
3151 - resp = resp->nextrp;
3152 - resp->nextrp = rp;
3153 - resp = rp;
3154 - } else
3155 - resp = NULL;
3156 + if (!list_empty(&sfp->rq_list)) {
3157 + if (!sfp->cmd_q)
3158 + goto out_unlock;
3159 +
3160 + for (k = 0; k < SG_MAX_QUEUE; ++k, ++rp) {
3161 + if (!rp->parentfp)
3162 + break;
3163 }
3164 + if (k >= SG_MAX_QUEUE)
3165 + goto out_unlock;
3166 }
3167 - if (resp) {
3168 - resp->nextrp = NULL;
3169 - resp->header.duration = jiffies_to_msecs(jiffies);
3170 - }
3171 + memset(rp, 0, sizeof (Sg_request));
3172 + rp->parentfp = sfp;
3173 + rp->header.duration = jiffies_to_msecs(jiffies);
3174 + list_add_tail(&rp->entry, &sfp->rq_list);
3175 write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
3176 - return resp;
3177 + return rp;
3178 +out_unlock:
3179 + write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
3180 + return NULL;
3181 }
3182
3183 /* Return of 1 for found; 0 for not found */
3184 static int
3185 sg_remove_request(Sg_fd * sfp, Sg_request * srp)
3186 {
3187 - Sg_request *prev_rp;
3188 - Sg_request *rp;
3189 unsigned long iflags;
3190 int res = 0;
3191
3192 - if ((!sfp) || (!srp) || (!sfp->headrp))
3193 + if (!sfp || !srp || list_empty(&sfp->rq_list))
3194 return res;
3195 write_lock_irqsave(&sfp->rq_list_lock, iflags);
3196 - prev_rp = sfp->headrp;
3197 - if (srp == prev_rp) {
3198 - sfp->headrp = prev_rp->nextrp;
3199 - prev_rp->parentfp = NULL;
3200 + if (!list_empty(&srp->entry)) {
3201 + list_del(&srp->entry);
3202 + srp->parentfp = NULL;
3203 res = 1;
3204 - } else {
3205 - while ((rp = prev_rp->nextrp)) {
3206 - if (srp == rp) {
3207 - prev_rp->nextrp = rp->nextrp;
3208 - rp->parentfp = NULL;
3209 - res = 1;
3210 - break;
3211 - }
3212 - prev_rp = rp;
3213 - }
3214 }
3215 write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
3216 return res;
3217 @@ -2162,7 +2142,7 @@ sg_add_sfp(Sg_device * sdp)
3218
3219 init_waitqueue_head(&sfp->read_wait);
3220 rwlock_init(&sfp->rq_list_lock);
3221 -
3222 + INIT_LIST_HEAD(&sfp->rq_list);
3223 kref_init(&sfp->f_ref);
3224 mutex_init(&sfp->f_mutex);
3225 sfp->timeout = SG_DEFAULT_TIMEOUT;
3226 @@ -2203,10 +2183,13 @@ sg_remove_sfp_usercontext(struct work_struct *work)
3227 {
3228 struct sg_fd *sfp = container_of(work, struct sg_fd, ew.work);
3229 struct sg_device *sdp = sfp->parentdp;
3230 + Sg_request *srp;
3231
3232 /* Cleanup any responses which were never read(). */
3233 - while (sfp->headrp)
3234 - sg_finish_rem_req(sfp->headrp);
3235 + while (!list_empty(&sfp->rq_list)) {
3236 + srp = list_first_entry(&sfp->rq_list, Sg_request, entry);
3237 + sg_finish_rem_req(srp);
3238 + }
3239
3240 if (sfp->reserve.bufflen > 0) {
3241 SCSI_LOG_TIMEOUT(6, sg_printk(KERN_INFO, sdp,
3242 @@ -2609,7 +2592,7 @@ static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v)
3243 /* must be called while holding sg_index_lock */
3244 static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp)
3245 {
3246 - int k, m, new_interface, blen, usg;
3247 + int k, new_interface, blen, usg;
3248 Sg_request *srp;
3249 Sg_fd *fp;
3250 const sg_io_hdr_t *hp;
3251 @@ -2629,13 +2612,11 @@ static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp)
3252 seq_printf(s, " cmd_q=%d f_packid=%d k_orphan=%d closed=0\n",
3253 (int) fp->cmd_q, (int) fp->force_packid,
3254 (int) fp->keep_orphan);
3255 - for (m = 0, srp = fp->headrp;
3256 - srp != NULL;
3257 - ++m, srp = srp->nextrp) {
3258 + list_for_each_entry(srp, &fp->rq_list, entry) {
3259 hp = &srp->header;
3260 new_interface = (hp->interface_id == '\0') ? 0 : 1;
3261 if (srp->res_used) {
3262 - if (new_interface &&
3263 + if (new_interface &&
3264 (SG_FLAG_MMAP_IO & hp->flags))
3265 cp = " mmap>> ";
3266 else
3267 @@ -2666,7 +2647,7 @@ static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp)
3268 seq_printf(s, "ms sgat=%d op=0x%02x\n", usg,
3269 (int) srp->data.cmd_opcode);
3270 }
3271 - if (0 == m)
3272 + if (list_empty(&fp->rq_list))
3273 seq_puts(s, " No requests active\n");
3274 read_unlock(&fp->rq_list_lock);
3275 }
3276 diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
3277 index c5ab1b0037fc..2bf96d33428a 100644
3278 --- a/drivers/scsi/storvsc_drv.c
3279 +++ b/drivers/scsi/storvsc_drv.c
3280 @@ -1559,6 +1559,8 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
3281 ret = storvsc_do_io(dev, cmd_request);
3282
3283 if (ret == -EAGAIN) {
3284 + if (payload_sz > sizeof(cmd_request->mpb))
3285 + kfree(payload);
3286 /* no more space */
3287 return SCSI_MLQUEUE_DEVICE_BUSY;
3288 }
3289 diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
3290 index aa80dc94ddc2..c220c2c0893f 100644
3291 --- a/drivers/tty/tty_buffer.c
3292 +++ b/drivers/tty/tty_buffer.c
3293 @@ -361,6 +361,32 @@ int tty_insert_flip_string_flags(struct tty_port *port,
3294 }
3295 EXPORT_SYMBOL(tty_insert_flip_string_flags);
3296
3297 +/**
3298 + * __tty_insert_flip_char - Add one character to the tty buffer
3299 + * @port: tty port
3300 + * @ch: character
3301 + * @flag: flag byte
3302 + *
3303 + * Queue a single byte to the tty buffering, with an optional flag.
3304 + * This is the slow path of tty_insert_flip_char.
3305 + */
3306 +int __tty_insert_flip_char(struct tty_port *port, unsigned char ch, char flag)
3307 +{
3308 + struct tty_buffer *tb;
3309 + int flags = (flag == TTY_NORMAL) ? TTYB_NORMAL : 0;
3310 +
3311 + if (!__tty_buffer_request_room(port, 1, flags))
3312 + return 0;
3313 +
3314 + tb = port->buf.tail;
3315 + if (~tb->flags & TTYB_NORMAL)
3316 + *flag_buf_ptr(tb, tb->used) = flag;
3317 + *char_buf_ptr(tb, tb->used++) = ch;
3318 +
3319 + return 1;
3320 +}
3321 +EXPORT_SYMBOL(__tty_insert_flip_char);
3322 +
3323 /**
3324 * tty_schedule_flip - push characters to ldisc
3325 * @port: tty port to push from
3326 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
3327 index 5fa9ba1de429..f72535e1898f 100644
3328 --- a/fs/ext4/super.c
3329 +++ b/fs/ext4/super.c
3330 @@ -2334,6 +2334,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
3331 unsigned int s_flags = sb->s_flags;
3332 int nr_orphans = 0, nr_truncates = 0;
3333 #ifdef CONFIG_QUOTA
3334 + int quota_update = 0;
3335 int i;
3336 #endif
3337 if (!es->s_last_orphan) {
3338 @@ -2372,14 +2373,32 @@ static void ext4_orphan_cleanup(struct super_block *sb,
3339 #ifdef CONFIG_QUOTA
3340 /* Needed for iput() to work correctly and not trash data */
3341 sb->s_flags |= MS_ACTIVE;
3342 - /* Turn on quotas so that they are updated correctly */
3343 +
3344 + /*
3345 + * Turn on quotas which were not enabled for read-only mounts if
3346 + * filesystem has quota feature, so that they are updated correctly.
3347 + */
3348 + if (ext4_has_feature_quota(sb) && (s_flags & MS_RDONLY)) {
3349 + int ret = ext4_enable_quotas(sb);
3350 +
3351 + if (!ret)
3352 + quota_update = 1;
3353 + else
3354 + ext4_msg(sb, KERN_ERR,
3355 + "Cannot turn on quotas: error %d", ret);
3356 + }
3357 +
3358 + /* Turn on journaled quotas used for old sytle */
3359 for (i = 0; i < EXT4_MAXQUOTAS; i++) {
3360 if (EXT4_SB(sb)->s_qf_names[i]) {
3361 int ret = ext4_quota_on_mount(sb, i);
3362 - if (ret < 0)
3363 +
3364 + if (!ret)
3365 + quota_update = 1;
3366 + else
3367 ext4_msg(sb, KERN_ERR,
3368 "Cannot turn on journaled "
3369 - "quota: error %d", ret);
3370 + "quota: type %d: error %d", i, ret);
3371 }
3372 }
3373 #endif
3374 @@ -2438,10 +2457,12 @@ static void ext4_orphan_cleanup(struct super_block *sb,
3375 ext4_msg(sb, KERN_INFO, "%d truncate%s cleaned up",
3376 PLURAL(nr_truncates));
3377 #ifdef CONFIG_QUOTA
3378 - /* Turn quotas off */
3379 - for (i = 0; i < EXT4_MAXQUOTAS; i++) {
3380 - if (sb_dqopt(sb)->files[i])
3381 - dquot_quota_off(sb, i);
3382 + /* Turn off quotas if they were enabled for orphan cleanup */
3383 + if (quota_update) {
3384 + for (i = 0; i < EXT4_MAXQUOTAS; i++) {
3385 + if (sb_dqopt(sb)->files[i])
3386 + dquot_quota_off(sb, i);
3387 + }
3388 }
3389 #endif
3390 sb->s_flags = s_flags; /* Restore MS_RDONLY status */
3391 @@ -5365,6 +5386,9 @@ static int ext4_enable_quotas(struct super_block *sb)
3392 DQUOT_USAGE_ENABLED |
3393 (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0));
3394 if (err) {
3395 + for (type--; type >= 0; type--)
3396 + dquot_quota_off(sb, type);
3397 +
3398 ext4_warning(sb,
3399 "Failed to enable quota tracking "
3400 "(type=%d, err=%d). Please run "
3401 diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
3402 index 0a2115084c3f..582bfee40345 100644
3403 --- a/fs/nfs/callback.c
3404 +++ b/fs/nfs/callback.c
3405 @@ -75,7 +75,10 @@ nfs4_callback_svc(void *vrqstp)
3406
3407 set_freezable();
3408
3409 - while (!kthread_should_stop()) {
3410 + while (!kthread_freezable_should_stop(NULL)) {
3411 +
3412 + if (signal_pending(current))
3413 + flush_signals(current);
3414 /*
3415 * Listen for a request on the socket
3416 */
3417 @@ -84,6 +87,8 @@ nfs4_callback_svc(void *vrqstp)
3418 continue;
3419 svc_process(rqstp);
3420 }
3421 + svc_exit_thread(rqstp);
3422 + module_put_and_exit(0);
3423 return 0;
3424 }
3425
3426 @@ -102,9 +107,10 @@ nfs41_callback_svc(void *vrqstp)
3427
3428 set_freezable();
3429
3430 - while (!kthread_should_stop()) {
3431 - if (try_to_freeze())
3432 - continue;
3433 + while (!kthread_freezable_should_stop(NULL)) {
3434 +
3435 + if (signal_pending(current))
3436 + flush_signals(current);
3437
3438 prepare_to_wait(&serv->sv_cb_waitq, &wq, TASK_INTERRUPTIBLE);
3439 spin_lock_bh(&serv->sv_cb_lock);
3440 @@ -120,11 +126,13 @@ nfs41_callback_svc(void *vrqstp)
3441 error);
3442 } else {
3443 spin_unlock_bh(&serv->sv_cb_lock);
3444 - schedule();
3445 + if (!kthread_should_stop())
3446 + schedule();
3447 finish_wait(&serv->sv_cb_waitq, &wq);
3448 }
3449 - flush_signals(current);
3450 }
3451 + svc_exit_thread(rqstp);
3452 + module_put_and_exit(0);
3453 return 0;
3454 }
3455
3456 @@ -220,14 +228,14 @@ static int nfs_callback_up_net(int minorversion, struct svc_serv *serv,
3457 static struct svc_serv_ops nfs40_cb_sv_ops = {
3458 .svo_function = nfs4_callback_svc,
3459 .svo_enqueue_xprt = svc_xprt_do_enqueue,
3460 - .svo_setup = svc_set_num_threads,
3461 + .svo_setup = svc_set_num_threads_sync,
3462 .svo_module = THIS_MODULE,
3463 };
3464 #if defined(CONFIG_NFS_V4_1)
3465 static struct svc_serv_ops nfs41_cb_sv_ops = {
3466 .svo_function = nfs41_callback_svc,
3467 .svo_enqueue_xprt = svc_xprt_do_enqueue,
3468 - .svo_setup = svc_set_num_threads,
3469 + .svo_setup = svc_set_num_threads_sync,
3470 .svo_module = THIS_MODULE,
3471 };
3472
3473 diff --git a/fs/orangefs/acl.c b/fs/orangefs/acl.c
3474 index 7a3754488312..9409aac232f7 100644
3475 --- a/fs/orangefs/acl.c
3476 +++ b/fs/orangefs/acl.c
3477 @@ -61,9 +61,9 @@ struct posix_acl *orangefs_get_acl(struct inode *inode, int type)
3478 return acl;
3479 }
3480
3481 -int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
3482 +static int __orangefs_set_acl(struct inode *inode, struct posix_acl *acl,
3483 + int type)
3484 {
3485 - struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
3486 int error = 0;
3487 void *value = NULL;
3488 size_t size = 0;
3489 @@ -72,22 +72,6 @@ int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
3490 switch (type) {
3491 case ACL_TYPE_ACCESS:
3492 name = XATTR_NAME_POSIX_ACL_ACCESS;
3493 - if (acl) {
3494 - umode_t mode;
3495 -
3496 - error = posix_acl_update_mode(inode, &mode, &acl);
3497 - if (error) {
3498 - gossip_err("%s: posix_acl_update_mode err: %d\n",
3499 - __func__,
3500 - error);
3501 - return error;
3502 - }
3503 -
3504 - if (inode->i_mode != mode)
3505 - SetModeFlag(orangefs_inode);
3506 - inode->i_mode = mode;
3507 - mark_inode_dirty_sync(inode);
3508 - }
3509 break;
3510 case ACL_TYPE_DEFAULT:
3511 name = XATTR_NAME_POSIX_ACL_DEFAULT;
3512 @@ -132,6 +116,29 @@ int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
3513 return error;
3514 }
3515
3516 +int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
3517 +{
3518 + int error;
3519 +
3520 + if (type == ACL_TYPE_ACCESS && acl) {
3521 + umode_t mode;
3522 +
3523 + error = posix_acl_update_mode(inode, &mode, &acl);
3524 + if (error) {
3525 + gossip_err("%s: posix_acl_update_mode err: %d\n",
3526 + __func__,
3527 + error);
3528 + return error;
3529 + }
3530 +
3531 + if (inode->i_mode != mode)
3532 + SetModeFlag(ORANGEFS_I(inode));
3533 + inode->i_mode = mode;
3534 + mark_inode_dirty_sync(inode);
3535 + }
3536 + return __orangefs_set_acl(inode, acl, type);
3537 +}
3538 +
3539 int orangefs_init_acl(struct inode *inode, struct inode *dir)
3540 {
3541 struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
3542 @@ -146,13 +153,14 @@ int orangefs_init_acl(struct inode *inode, struct inode *dir)
3543 return error;
3544
3545 if (default_acl) {
3546 - error = orangefs_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
3547 + error = __orangefs_set_acl(inode, default_acl,
3548 + ACL_TYPE_DEFAULT);
3549 posix_acl_release(default_acl);
3550 }
3551
3552 if (acl) {
3553 if (!error)
3554 - error = orangefs_set_acl(inode, acl, ACL_TYPE_ACCESS);
3555 + error = __orangefs_set_acl(inode, acl, ACL_TYPE_ACCESS);
3556 posix_acl_release(acl);
3557 }
3558
3559 diff --git a/include/linux/ccp.h b/include/linux/ccp.h
3560 index edc5d04b9632..1cfe5ef3060b 100644
3561 --- a/include/linux/ccp.h
3562 +++ b/include/linux/ccp.h
3563 @@ -1,7 +1,7 @@
3564 /*
3565 * AMD Cryptographic Coprocessor (CCP) driver
3566 *
3567 - * Copyright (C) 2013,2016 Advanced Micro Devices, Inc.
3568 + * Copyright (C) 2013,2017 Advanced Micro Devices, Inc.
3569 *
3570 * Author: Tom Lendacky <thomas.lendacky@amd.com>
3571 * Author: Gary R Hook <gary.hook@amd.com>
3572 @@ -222,6 +222,7 @@ enum ccp_xts_aes_unit_size {
3573 * AES operation the new IV overwrites the old IV.
3574 */
3575 struct ccp_xts_aes_engine {
3576 + enum ccp_aes_type type;
3577 enum ccp_aes_action action;
3578 enum ccp_xts_aes_unit_size unit_size;
3579
3580 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
3581 index 7321ae933867..102c84dcc11a 100644
3582 --- a/include/linux/sunrpc/svc.h
3583 +++ b/include/linux/sunrpc/svc.h
3584 @@ -470,6 +470,7 @@ void svc_pool_map_put(void);
3585 struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int,
3586 struct svc_serv_ops *);
3587 int svc_set_num_threads(struct svc_serv *, struct svc_pool *, int);
3588 +int svc_set_num_threads_sync(struct svc_serv *, struct svc_pool *, int);
3589 int svc_pool_stats_open(struct svc_serv *serv, struct file *file);
3590 void svc_destroy(struct svc_serv *);
3591 void svc_shutdown_net(struct svc_serv *, struct net *);
3592 diff --git a/include/linux/tty_flip.h b/include/linux/tty_flip.h
3593 index c28dd523f96e..d43837f2ce3a 100644
3594 --- a/include/linux/tty_flip.h
3595 +++ b/include/linux/tty_flip.h
3596 @@ -12,6 +12,7 @@ extern int tty_prepare_flip_string(struct tty_port *port,
3597 unsigned char **chars, size_t size);
3598 extern void tty_flip_buffer_push(struct tty_port *port);
3599 void tty_schedule_flip(struct tty_port *port);
3600 +int __tty_insert_flip_char(struct tty_port *port, unsigned char ch, char flag);
3601
3602 static inline int tty_insert_flip_char(struct tty_port *port,
3603 unsigned char ch, char flag)
3604 @@ -26,7 +27,7 @@ static inline int tty_insert_flip_char(struct tty_port *port,
3605 *char_buf_ptr(tb, tb->used++) = ch;
3606 return 1;
3607 }
3608 - return tty_insert_flip_string_flags(port, &ch, &flag, 1);
3609 + return __tty_insert_flip_char(port, ch, flag);
3610 }
3611
3612 static inline int tty_insert_flip_string(struct tty_port *port,
3613 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
3614 index 6e432ed7d0fe..53ed8ae5de1c 100644
3615 --- a/kernel/trace/ftrace.c
3616 +++ b/kernel/trace/ftrace.c
3617 @@ -2747,13 +2747,14 @@ static int ftrace_shutdown(struct ftrace_ops *ops, int command)
3618
3619 if (!command || !ftrace_enabled) {
3620 /*
3621 - * If these are per_cpu ops, they still need their
3622 - * per_cpu field freed. Since, function tracing is
3623 + * If these are dynamic or per_cpu ops, they still
3624 + * need their data freed. Since, function tracing is
3625 * not currently active, we can just free them
3626 * without synchronizing all CPUs.
3627 */
3628 - if (ops->flags & FTRACE_OPS_FL_PER_CPU)
3629 - per_cpu_ops_free(ops);
3630 + if (ops->flags & (FTRACE_OPS_FL_DYNAMIC | FTRACE_OPS_FL_PER_CPU))
3631 + goto free_ops;
3632 +
3633 return 0;
3634 }
3635
3636 @@ -2808,6 +2809,7 @@ static int ftrace_shutdown(struct ftrace_ops *ops, int command)
3637 if (ops->flags & (FTRACE_OPS_FL_DYNAMIC | FTRACE_OPS_FL_PER_CPU)) {
3638 schedule_on_each_cpu(ftrace_sync);
3639
3640 + free_ops:
3641 arch_ftrace_trampoline_free(ops);
3642
3643 if (ops->flags & FTRACE_OPS_FL_PER_CPU)
3644 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
3645 index 7379f735a9f4..f95bf81529f5 100644
3646 --- a/kernel/trace/trace.c
3647 +++ b/kernel/trace/trace.c
3648 @@ -2369,11 +2369,17 @@ static char *get_trace_buf(void)
3649 if (!buffer || buffer->nesting >= 4)
3650 return NULL;
3651
3652 - return &buffer->buffer[buffer->nesting++][0];
3653 + buffer->nesting++;
3654 +
3655 + /* Interrupts must see nesting incremented before we use the buffer */
3656 + barrier();
3657 + return &buffer->buffer[buffer->nesting][0];
3658 }
3659
3660 static void put_trace_buf(void)
3661 {
3662 + /* Don't let the decrement of nesting leak before this */
3663 + barrier();
3664 this_cpu_dec(trace_percpu_buffer->nesting);
3665 }
3666
3667 @@ -5658,7 +5664,7 @@ static int tracing_set_clock(struct trace_array *tr, const char *clockstr)
3668 tracing_reset_online_cpus(&tr->trace_buffer);
3669
3670 #ifdef CONFIG_TRACER_MAX_TRACE
3671 - if (tr->flags & TRACE_ARRAY_FL_GLOBAL && tr->max_buffer.buffer)
3672 + if (tr->max_buffer.buffer)
3673 ring_buffer_set_clock(tr->max_buffer.buffer, trace_clocks[i].func);
3674 tracing_reset_online_cpus(&tr->max_buffer);
3675 #endif
3676 diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c
3677 index b0f86ea77881..ca70d11b8aa7 100644
3678 --- a/kernel/trace/trace_selftest.c
3679 +++ b/kernel/trace/trace_selftest.c
3680 @@ -272,7 +272,7 @@ static int trace_selftest_ops(struct trace_array *tr, int cnt)
3681 goto out_free;
3682 if (cnt > 1) {
3683 if (trace_selftest_test_global_cnt == 0)
3684 - goto out;
3685 + goto out_free;
3686 }
3687 if (trace_selftest_test_dyn_cnt == 0)
3688 goto out_free;
3689 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
3690 index 2abf8d5f0ad4..7064aae8ded7 100644
3691 --- a/mm/page_alloc.c
3692 +++ b/mm/page_alloc.c
3693 @@ -2100,13 +2100,25 @@ static void unreserve_highatomic_pageblock(const struct alloc_context *ac)
3694 continue;
3695
3696 /*
3697 - * It should never happen but changes to locking could
3698 - * inadvertently allow a per-cpu drain to add pages
3699 - * to MIGRATE_HIGHATOMIC while unreserving so be safe
3700 - * and watch for underflows.
3701 + * In page freeing path, migratetype change is racy so
3702 + * we can counter several free pages in a pageblock
3703 + * in this loop althoug we changed the pageblock type
3704 + * from highatomic to ac->migratetype. So we should
3705 + * adjust the count once.
3706 */
3707 - zone->nr_reserved_highatomic -= min(pageblock_nr_pages,
3708 - zone->nr_reserved_highatomic);
3709 + if (get_pageblock_migratetype(page) ==
3710 + MIGRATE_HIGHATOMIC) {
3711 + /*
3712 + * It should never happen but changes to
3713 + * locking could inadvertently allow a per-cpu
3714 + * drain to add pages to MIGRATE_HIGHATOMIC
3715 + * while unreserving so be safe and watch for
3716 + * underflows.
3717 + */
3718 + zone->nr_reserved_highatomic -= min(
3719 + pageblock_nr_pages,
3720 + zone->nr_reserved_highatomic);
3721 + }
3722
3723 /*
3724 * Convert to ac->migratetype and avoid the normal
3725 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
3726 index 6bd150882ba4..ed9ce7c63252 100644
3727 --- a/net/netfilter/nf_conntrack_core.c
3728 +++ b/net/netfilter/nf_conntrack_core.c
3729 @@ -95,19 +95,26 @@ static struct conntrack_gc_work conntrack_gc_work;
3730
3731 void nf_conntrack_lock(spinlock_t *lock) __acquires(lock)
3732 {
3733 + /* 1) Acquire the lock */
3734 spin_lock(lock);
3735 - while (unlikely(nf_conntrack_locks_all)) {
3736 - spin_unlock(lock);
3737
3738 - /*
3739 - * Order the 'nf_conntrack_locks_all' load vs. the
3740 - * spin_unlock_wait() loads below, to ensure
3741 - * that 'nf_conntrack_locks_all_lock' is indeed held:
3742 - */
3743 - smp_rmb(); /* spin_lock(&nf_conntrack_locks_all_lock) */
3744 - spin_unlock_wait(&nf_conntrack_locks_all_lock);
3745 - spin_lock(lock);
3746 - }
3747 + /* 2) read nf_conntrack_locks_all, with ACQUIRE semantics
3748 + * It pairs with the smp_store_release() in nf_conntrack_all_unlock()
3749 + */
3750 + if (likely(smp_load_acquire(&nf_conntrack_locks_all) == false))
3751 + return;
3752 +
3753 + /* fast path failed, unlock */
3754 + spin_unlock(lock);
3755 +
3756 + /* Slow path 1) get global lock */
3757 + spin_lock(&nf_conntrack_locks_all_lock);
3758 +
3759 + /* Slow path 2) get the lock we want */
3760 + spin_lock(lock);
3761 +
3762 + /* Slow path 3) release the global lock */
3763 + spin_unlock(&nf_conntrack_locks_all_lock);
3764 }
3765 EXPORT_SYMBOL_GPL(nf_conntrack_lock);
3766
3767 @@ -148,28 +155,27 @@ static void nf_conntrack_all_lock(void)
3768 int i;
3769
3770 spin_lock(&nf_conntrack_locks_all_lock);
3771 - nf_conntrack_locks_all = true;
3772
3773 - /*
3774 - * Order the above store of 'nf_conntrack_locks_all' against
3775 - * the spin_unlock_wait() loads below, such that if
3776 - * nf_conntrack_lock() observes 'nf_conntrack_locks_all'
3777 - * we must observe nf_conntrack_locks[] held:
3778 - */
3779 - smp_mb(); /* spin_lock(&nf_conntrack_locks_all_lock) */
3780 + nf_conntrack_locks_all = true;
3781
3782 for (i = 0; i < CONNTRACK_LOCKS; i++) {
3783 - spin_unlock_wait(&nf_conntrack_locks[i]);
3784 + spin_lock(&nf_conntrack_locks[i]);
3785 +
3786 + /* This spin_unlock provides the "release" to ensure that
3787 + * nf_conntrack_locks_all==true is visible to everyone that
3788 + * acquired spin_lock(&nf_conntrack_locks[]).
3789 + */
3790 + spin_unlock(&nf_conntrack_locks[i]);
3791 }
3792 }
3793
3794 static void nf_conntrack_all_unlock(void)
3795 {
3796 - /*
3797 - * All prior stores must be complete before we clear
3798 + /* All prior stores must be complete before we clear
3799 * 'nf_conntrack_locks_all'. Otherwise nf_conntrack_lock()
3800 * might observe the false value but not the entire
3801 - * critical section:
3802 + * critical section.
3803 + * It pairs with the smp_load_acquire() in nf_conntrack_lock()
3804 */
3805 smp_store_release(&nf_conntrack_locks_all, false);
3806 spin_unlock(&nf_conntrack_locks_all_lock);
3807 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
3808 index 75f290bddca1..272c34551979 100644
3809 --- a/net/sunrpc/svc.c
3810 +++ b/net/sunrpc/svc.c
3811 @@ -702,59 +702,32 @@ choose_victim(struct svc_serv *serv, struct svc_pool *pool, unsigned int *state)
3812 return task;
3813 }
3814
3815 -/*
3816 - * Create or destroy enough new threads to make the number
3817 - * of threads the given number. If `pool' is non-NULL, applies
3818 - * only to threads in that pool, otherwise round-robins between
3819 - * all pools. Caller must ensure that mutual exclusion between this and
3820 - * server startup or shutdown.
3821 - *
3822 - * Destroying threads relies on the service threads filling in
3823 - * rqstp->rq_task, which only the nfs ones do. Assumes the serv
3824 - * has been created using svc_create_pooled().
3825 - *
3826 - * Based on code that used to be in nfsd_svc() but tweaked
3827 - * to be pool-aware.
3828 - */
3829 -int
3830 -svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
3831 +/* create new threads */
3832 +static int
3833 +svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
3834 {
3835 struct svc_rqst *rqstp;
3836 struct task_struct *task;
3837 struct svc_pool *chosen_pool;
3838 - int error = 0;
3839 unsigned int state = serv->sv_nrthreads-1;
3840 int node;
3841
3842 - if (pool == NULL) {
3843 - /* The -1 assumes caller has done a svc_get() */
3844 - nrservs -= (serv->sv_nrthreads-1);
3845 - } else {
3846 - spin_lock_bh(&pool->sp_lock);
3847 - nrservs -= pool->sp_nrthreads;
3848 - spin_unlock_bh(&pool->sp_lock);
3849 - }
3850 -
3851 - /* create new threads */
3852 - while (nrservs > 0) {
3853 + do {
3854 nrservs--;
3855 chosen_pool = choose_pool(serv, pool, &state);
3856
3857 node = svc_pool_map_get_node(chosen_pool->sp_id);
3858 rqstp = svc_prepare_thread(serv, chosen_pool, node);
3859 - if (IS_ERR(rqstp)) {
3860 - error = PTR_ERR(rqstp);
3861 - break;
3862 - }
3863 + if (IS_ERR(rqstp))
3864 + return PTR_ERR(rqstp);
3865
3866 __module_get(serv->sv_ops->svo_module);
3867 task = kthread_create_on_node(serv->sv_ops->svo_function, rqstp,
3868 node, "%s", serv->sv_name);
3869 if (IS_ERR(task)) {
3870 - error = PTR_ERR(task);
3871 module_put(serv->sv_ops->svo_module);
3872 svc_exit_thread(rqstp);
3873 - break;
3874 + return PTR_ERR(task);
3875 }
3876
3877 rqstp->rq_task = task;
3878 @@ -763,18 +736,103 @@ svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
3879
3880 svc_sock_update_bufs(serv);
3881 wake_up_process(task);
3882 - }
3883 + } while (nrservs > 0);
3884 +
3885 + return 0;
3886 +}
3887 +
3888 +
3889 +/* destroy old threads */
3890 +static int
3891 +svc_signal_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
3892 +{
3893 + struct task_struct *task;
3894 + unsigned int state = serv->sv_nrthreads-1;
3895 +
3896 /* destroy old threads */
3897 - while (nrservs < 0 &&
3898 - (task = choose_victim(serv, pool, &state)) != NULL) {
3899 + do {
3900 + task = choose_victim(serv, pool, &state);
3901 + if (task == NULL)
3902 + break;
3903 send_sig(SIGINT, task, 1);
3904 nrservs++;
3905 + } while (nrservs < 0);
3906 +
3907 + return 0;
3908 +}
3909 +
3910 +/*
3911 + * Create or destroy enough new threads to make the number
3912 + * of threads the given number. If `pool' is non-NULL, applies
3913 + * only to threads in that pool, otherwise round-robins between
3914 + * all pools. Caller must ensure that mutual exclusion between this and
3915 + * server startup or shutdown.
3916 + *
3917 + * Destroying threads relies on the service threads filling in
3918 + * rqstp->rq_task, which only the nfs ones do. Assumes the serv
3919 + * has been created using svc_create_pooled().
3920 + *
3921 + * Based on code that used to be in nfsd_svc() but tweaked
3922 + * to be pool-aware.
3923 + */
3924 +int
3925 +svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
3926 +{
3927 + if (pool == NULL) {
3928 + /* The -1 assumes caller has done a svc_get() */
3929 + nrservs -= (serv->sv_nrthreads-1);
3930 + } else {
3931 + spin_lock_bh(&pool->sp_lock);
3932 + nrservs -= pool->sp_nrthreads;
3933 + spin_unlock_bh(&pool->sp_lock);
3934 }
3935
3936 - return error;
3937 + if (nrservs > 0)
3938 + return svc_start_kthreads(serv, pool, nrservs);
3939 + if (nrservs < 0)
3940 + return svc_signal_kthreads(serv, pool, nrservs);
3941 + return 0;
3942 }
3943 EXPORT_SYMBOL_GPL(svc_set_num_threads);
3944
3945 +/* destroy old threads */
3946 +static int
3947 +svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
3948 +{
3949 + struct task_struct *task;
3950 + unsigned int state = serv->sv_nrthreads-1;
3951 +
3952 + /* destroy old threads */
3953 + do {
3954 + task = choose_victim(serv, pool, &state);
3955 + if (task == NULL)
3956 + break;
3957 + kthread_stop(task);
3958 + nrservs++;
3959 + } while (nrservs < 0);
3960 + return 0;
3961 +}
3962 +
3963 +int
3964 +svc_set_num_threads_sync(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
3965 +{
3966 + if (pool == NULL) {
3967 + /* The -1 assumes caller has done a svc_get() */
3968 + nrservs -= (serv->sv_nrthreads-1);
3969 + } else {
3970 + spin_lock_bh(&pool->sp_lock);
3971 + nrservs -= pool->sp_nrthreads;
3972 + spin_unlock_bh(&pool->sp_lock);
3973 + }
3974 +
3975 + if (nrservs > 0)
3976 + return svc_start_kthreads(serv, pool, nrservs);
3977 + if (nrservs < 0)
3978 + return svc_stop_kthreads(serv, pool, nrservs);
3979 + return 0;
3980 +}
3981 +EXPORT_SYMBOL_GPL(svc_set_num_threads_sync);
3982 +
3983 /*
3984 * Called from a server thread as it's exiting. Caller must hold the "service
3985 * mutex" for the service.