Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:4.13 commit in: /
Date: Wed, 27 Sep 2017 16:44:50
Message-Id: 1506530676.6480b3fa1da27836df3f2d330135e093e74e79a0.mpagano@gentoo
1 commit: 6480b3fa1da27836df3f2d330135e093e74e79a0
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Wed Sep 27 16:44:36 2017 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Wed Sep 27 16:44:36 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=6480b3fa
7
8 Linux patch 4.13.4
9
10 0000_README | 4 +
11 1003_linux-4.13.4.patch | 5143 +++++++++++++++++++++++++++++++++++++++++++++++
12 2 files changed, 5147 insertions(+)
13
14 diff --git a/0000_README b/0000_README
15 index 70f03ff..aee01b0 100644
16 --- a/0000_README
17 +++ b/0000_README
18 @@ -55,6 +55,10 @@ Patch: 1002_linux-4.13.3.patch
19 From: http://www.kernel.org
20 Desc: Linux 4.13.3
21
22 +Patch: 1003_linux-4.13.4.patch
23 +From: http://www.kernel.org
24 +Desc: Linux 4.13.4
25 +
26 Patch: 1500_XATTR_USER_PREFIX.patch
27 From: https://bugs.gentoo.org/show_bug.cgi?id=470644
28 Desc: Support for namespace user.pax.* on tmpfs.
29
30 diff --git a/1003_linux-4.13.4.patch b/1003_linux-4.13.4.patch
31 new file mode 100644
32 index 0000000..b118fe3
33 --- /dev/null
34 +++ b/1003_linux-4.13.4.patch
35 @@ -0,0 +1,5143 @@
36 +diff --git a/Documentation/dev-tools/gdb-kernel-debugging.rst b/Documentation/dev-tools/gdb-kernel-debugging.rst
37 +index 5e93c9bc6619..19df79286f00 100644
38 +--- a/Documentation/dev-tools/gdb-kernel-debugging.rst
39 ++++ b/Documentation/dev-tools/gdb-kernel-debugging.rst
40 +@@ -31,11 +31,13 @@ Setup
41 + CONFIG_DEBUG_INFO_REDUCED off. If your architecture supports
42 + CONFIG_FRAME_POINTER, keep it enabled.
43 +
44 +-- Install that kernel on the guest.
45 ++- Install that kernel on the guest, turn off KASLR if necessary by adding
46 ++ "nokaslr" to the kernel command line.
47 + Alternatively, QEMU allows to boot the kernel directly using -kernel,
48 + -append, -initrd command line switches. This is generally only useful if
49 + you do not depend on modules. See QEMU documentation for more details on
50 +- this mode.
51 ++ this mode. In this case, you should build the kernel with
52 ++ CONFIG_RANDOMIZE_BASE disabled if the architecture supports KASLR.
53 +
54 + - Enable the gdb stub of QEMU/KVM, either
55 +
56 +diff --git a/Makefile b/Makefile
57 +index 0f31ef4aea7b..159901979dec 100644
58 +--- a/Makefile
59 ++++ b/Makefile
60 +@@ -1,6 +1,6 @@
61 + VERSION = 4
62 + PATCHLEVEL = 13
63 +-SUBLEVEL = 3
64 ++SUBLEVEL = 4
65 + EXTRAVERSION =
66 + NAME = Fearless Coyote
67 +
68 +diff --git a/arch/arc/kernel/entry.S b/arch/arc/kernel/entry.S
69 +index 1eea99beecc3..85d9ea4a0acc 100644
70 +--- a/arch/arc/kernel/entry.S
71 ++++ b/arch/arc/kernel/entry.S
72 +@@ -92,6 +92,12 @@ ENTRY(EV_MachineCheck)
73 + lr r0, [efa]
74 + mov r1, sp
75 +
76 ++ ; hardware auto-disables MMU, re-enable it to allow kernel vaddr
77 ++ ; access for say stack unwinding of modules for crash dumps
78 ++ lr r3, [ARC_REG_PID]
79 ++ or r3, r3, MMU_ENABLE
80 ++ sr r3, [ARC_REG_PID]
81 ++
82 + lsr r3, r2, 8
83 + bmsk r3, r3, 7
84 + brne r3, ECR_C_MCHK_DUP_TLB, 1f
85 +diff --git a/arch/arc/mm/tlb.c b/arch/arc/mm/tlb.c
86 +index b181f3ee38aa..ac81502055f8 100644
87 +--- a/arch/arc/mm/tlb.c
88 ++++ b/arch/arc/mm/tlb.c
89 +@@ -908,9 +908,6 @@ void do_tlb_overlap_fault(unsigned long cause, unsigned long address,
90 +
91 + local_irq_save(flags);
92 +
93 +- /* re-enable the MMU */
94 +- write_aux_reg(ARC_REG_PID, MMU_ENABLE | read_aux_reg(ARC_REG_PID));
95 +-
96 + /* loop thru all sets of TLB */
97 + for (set = 0; set < mmu->sets; set++) {
98 +
99 +diff --git a/arch/mips/math-emu/dp_fmax.c b/arch/mips/math-emu/dp_fmax.c
100 +index fd71b8daaaf2..5bec64f2884e 100644
101 +--- a/arch/mips/math-emu/dp_fmax.c
102 ++++ b/arch/mips/math-emu/dp_fmax.c
103 +@@ -47,14 +47,26 @@ union ieee754dp ieee754dp_fmax(union ieee754dp x, union ieee754dp y)
104 + case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
105 + return ieee754dp_nanxcpt(x);
106 +
107 +- /* numbers are preferred to NaNs */
108 ++ /*
109 ++ * Quiet NaN handling
110 ++ */
111 ++
112 ++ /*
113 ++ * The case of both inputs quiet NaNs
114 ++ */
115 ++ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
116 ++ return x;
117 ++
118 ++ /*
119 ++ * The cases of exactly one input quiet NaN (numbers
120 ++ * are here preferred as returned values to NaNs)
121 ++ */
122 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
123 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
124 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
125 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
126 + return x;
127 +
128 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
129 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
130 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
131 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
132 +@@ -80,9 +92,7 @@ union ieee754dp ieee754dp_fmax(union ieee754dp x, union ieee754dp y)
133 + return ys ? x : y;
134 +
135 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
136 +- if (xs == ys)
137 +- return x;
138 +- return ieee754dp_zero(1);
139 ++ return ieee754dp_zero(xs & ys);
140 +
141 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
142 + DPDNORMX;
143 +@@ -106,16 +116,32 @@ union ieee754dp ieee754dp_fmax(union ieee754dp x, union ieee754dp y)
144 + else if (xs < ys)
145 + return x;
146 +
147 +- /* Compare exponent */
148 +- if (xe > ye)
149 +- return x;
150 +- else if (xe < ye)
151 +- return y;
152 ++ /* Signs of inputs are equal, let's compare exponents */
153 ++ if (xs == 0) {
154 ++ /* Inputs are both positive */
155 ++ if (xe > ye)
156 ++ return x;
157 ++ else if (xe < ye)
158 ++ return y;
159 ++ } else {
160 ++ /* Inputs are both negative */
161 ++ if (xe > ye)
162 ++ return y;
163 ++ else if (xe < ye)
164 ++ return x;
165 ++ }
166 +
167 +- /* Compare mantissa */
168 ++ /* Signs and exponents of inputs are equal, let's compare mantissas */
169 ++ if (xs == 0) {
170 ++ /* Inputs are both positive, with equal signs and exponents */
171 ++ if (xm <= ym)
172 ++ return y;
173 ++ return x;
174 ++ }
175 ++ /* Inputs are both negative, with equal signs and exponents */
176 + if (xm <= ym)
177 +- return y;
178 +- return x;
179 ++ return x;
180 ++ return y;
181 + }
182 +
183 + union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
184 +@@ -147,14 +173,26 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
185 + case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
186 + return ieee754dp_nanxcpt(x);
187 +
188 +- /* numbers are preferred to NaNs */
189 ++ /*
190 ++ * Quiet NaN handling
191 ++ */
192 ++
193 ++ /*
194 ++ * The case of both inputs quiet NaNs
195 ++ */
196 ++ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
197 ++ return x;
198 ++
199 ++ /*
200 ++ * The cases of exactly one input quiet NaN (numbers
201 ++ * are here preferred as returned values to NaNs)
202 ++ */
203 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
204 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
205 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
206 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
207 + return x;
208 +
209 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
210 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
211 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
212 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
213 +@@ -164,6 +202,9 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
214 + /*
215 + * Infinity and zero handling
216 + */
217 ++ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
218 ++ return ieee754dp_inf(xs & ys);
219 ++
220 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
221 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
222 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
223 +@@ -171,7 +212,6 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
224 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
225 + return x;
226 +
227 +- case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
228 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
229 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
230 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
231 +@@ -180,9 +220,7 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
232 + return y;
233 +
234 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
235 +- if (xs == ys)
236 +- return x;
237 +- return ieee754dp_zero(1);
238 ++ return ieee754dp_zero(xs & ys);
239 +
240 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
241 + DPDNORMX;
242 +@@ -207,7 +245,11 @@ union ieee754dp ieee754dp_fmaxa(union ieee754dp x, union ieee754dp y)
243 + return y;
244 +
245 + /* Compare mantissa */
246 +- if (xm <= ym)
247 ++ if (xm < ym)
248 + return y;
249 +- return x;
250 ++ else if (xm > ym)
251 ++ return x;
252 ++ else if (xs == 0)
253 ++ return x;
254 ++ return y;
255 + }
256 +diff --git a/arch/mips/math-emu/dp_fmin.c b/arch/mips/math-emu/dp_fmin.c
257 +index c1072b0dfb95..a287b23818d8 100644
258 +--- a/arch/mips/math-emu/dp_fmin.c
259 ++++ b/arch/mips/math-emu/dp_fmin.c
260 +@@ -47,14 +47,26 @@ union ieee754dp ieee754dp_fmin(union ieee754dp x, union ieee754dp y)
261 + case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
262 + return ieee754dp_nanxcpt(x);
263 +
264 +- /* numbers are preferred to NaNs */
265 ++ /*
266 ++ * Quiet NaN handling
267 ++ */
268 ++
269 ++ /*
270 ++ * The case of both inputs quiet NaNs
271 ++ */
272 ++ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
273 ++ return x;
274 ++
275 ++ /*
276 ++ * The cases of exactly one input quiet NaN (numbers
277 ++ * are here preferred as returned values to NaNs)
278 ++ */
279 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
280 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
281 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
282 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
283 + return x;
284 +
285 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
286 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
287 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
288 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
289 +@@ -80,9 +92,7 @@ union ieee754dp ieee754dp_fmin(union ieee754dp x, union ieee754dp y)
290 + return ys ? y : x;
291 +
292 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
293 +- if (xs == ys)
294 +- return x;
295 +- return ieee754dp_zero(1);
296 ++ return ieee754dp_zero(xs | ys);
297 +
298 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
299 + DPDNORMX;
300 +@@ -106,16 +116,32 @@ union ieee754dp ieee754dp_fmin(union ieee754dp x, union ieee754dp y)
301 + else if (xs < ys)
302 + return y;
303 +
304 +- /* Compare exponent */
305 +- if (xe > ye)
306 +- return y;
307 +- else if (xe < ye)
308 +- return x;
309 ++ /* Signs of inputs are the same, let's compare exponents */
310 ++ if (xs == 0) {
311 ++ /* Inputs are both positive */
312 ++ if (xe > ye)
313 ++ return y;
314 ++ else if (xe < ye)
315 ++ return x;
316 ++ } else {
317 ++ /* Inputs are both negative */
318 ++ if (xe > ye)
319 ++ return x;
320 ++ else if (xe < ye)
321 ++ return y;
322 ++ }
323 +
324 +- /* Compare mantissa */
325 ++ /* Signs and exponents of inputs are equal, let's compare mantissas */
326 ++ if (xs == 0) {
327 ++ /* Inputs are both positive, with equal signs and exponents */
328 ++ if (xm <= ym)
329 ++ return x;
330 ++ return y;
331 ++ }
332 ++ /* Inputs are both negative, with equal signs and exponents */
333 + if (xm <= ym)
334 +- return x;
335 +- return y;
336 ++ return y;
337 ++ return x;
338 + }
339 +
340 + union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
341 +@@ -147,14 +173,26 @@ union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
342 + case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
343 + return ieee754dp_nanxcpt(x);
344 +
345 +- /* numbers are preferred to NaNs */
346 ++ /*
347 ++ * Quiet NaN handling
348 ++ */
349 ++
350 ++ /*
351 ++ * The case of both inputs quiet NaNs
352 ++ */
353 ++ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
354 ++ return x;
355 ++
356 ++ /*
357 ++ * The cases of exactly one input quiet NaN (numbers
358 ++ * are here preferred as returned values to NaNs)
359 ++ */
360 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
361 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
362 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
363 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
364 + return x;
365 +
366 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
367 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
368 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
369 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
370 +@@ -164,25 +202,25 @@ union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
371 + /*
372 + * Infinity and zero handling
373 + */
374 ++ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
375 ++ return ieee754dp_inf(xs | ys);
376 ++
377 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
378 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
379 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
380 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
381 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
382 +- return x;
383 ++ return y;
384 +
385 +- case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
386 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
387 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
388 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
389 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
390 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
391 +- return y;
392 ++ return x;
393 +
394 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
395 +- if (xs == ys)
396 +- return x;
397 +- return ieee754dp_zero(1);
398 ++ return ieee754dp_zero(xs | ys);
399 +
400 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
401 + DPDNORMX;
402 +@@ -207,7 +245,11 @@ union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
403 + return x;
404 +
405 + /* Compare mantissa */
406 +- if (xm <= ym)
407 ++ if (xm < ym)
408 ++ return x;
409 ++ else if (xm > ym)
410 ++ return y;
411 ++ else if (xs == 1)
412 + return x;
413 + return y;
414 + }
415 +diff --git a/arch/mips/math-emu/dp_maddf.c b/arch/mips/math-emu/dp_maddf.c
416 +index caa62f20a888..e0d9be5fbf4c 100644
417 +--- a/arch/mips/math-emu/dp_maddf.c
418 ++++ b/arch/mips/math-emu/dp_maddf.c
419 +@@ -14,22 +14,45 @@
420 +
421 + #include "ieee754dp.h"
422 +
423 +-enum maddf_flags {
424 +- maddf_negate_product = 1 << 0,
425 +-};
426 ++
427 ++/* 128 bits shift right logical with rounding. */
428 ++void srl128(u64 *hptr, u64 *lptr, int count)
429 ++{
430 ++ u64 low;
431 ++
432 ++ if (count >= 128) {
433 ++ *lptr = *hptr != 0 || *lptr != 0;
434 ++ *hptr = 0;
435 ++ } else if (count >= 64) {
436 ++ if (count == 64) {
437 ++ *lptr = *hptr | (*lptr != 0);
438 ++ } else {
439 ++ low = *lptr;
440 ++ *lptr = *hptr >> (count - 64);
441 ++ *lptr |= (*hptr << (128 - count)) != 0 || low != 0;
442 ++ }
443 ++ *hptr = 0;
444 ++ } else {
445 ++ low = *lptr;
446 ++ *lptr = low >> count | *hptr << (64 - count);
447 ++ *lptr |= (low << (64 - count)) != 0;
448 ++ *hptr = *hptr >> count;
449 ++ }
450 ++}
451 +
452 + static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
453 + union ieee754dp y, enum maddf_flags flags)
454 + {
455 + int re;
456 + int rs;
457 +- u64 rm;
458 + unsigned lxm;
459 + unsigned hxm;
460 + unsigned lym;
461 + unsigned hym;
462 + u64 lrm;
463 + u64 hrm;
464 ++ u64 lzm;
465 ++ u64 hzm;
466 + u64 t;
467 + u64 at;
468 + int s;
469 +@@ -48,52 +71,34 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
470 +
471 + ieee754_clearcx();
472 +
473 +- switch (zc) {
474 +- case IEEE754_CLASS_SNAN:
475 +- ieee754_setcx(IEEE754_INVALID_OPERATION);
476 ++ /*
477 ++ * Handle the cases when at least one of x, y or z is a NaN.
478 ++ * Order of precedence is sNaN, qNaN and z, x, y.
479 ++ */
480 ++ if (zc == IEEE754_CLASS_SNAN)
481 + return ieee754dp_nanxcpt(z);
482 +- case IEEE754_CLASS_DNORM:
483 +- DPDNORMZ;
484 +- /* QNAN and ZERO cases are handled separately below */
485 +- }
486 +-
487 +- switch (CLPAIR(xc, yc)) {
488 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
489 +- case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
490 +- case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
491 +- case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
492 +- case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
493 +- return ieee754dp_nanxcpt(y);
494 +-
495 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
496 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
497 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
498 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
499 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
500 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
501 ++ if (xc == IEEE754_CLASS_SNAN)
502 + return ieee754dp_nanxcpt(x);
503 +-
504 +- case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
505 +- case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
506 +- case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
507 +- case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
508 ++ if (yc == IEEE754_CLASS_SNAN)
509 ++ return ieee754dp_nanxcpt(y);
510 ++ if (zc == IEEE754_CLASS_QNAN)
511 ++ return z;
512 ++ if (xc == IEEE754_CLASS_QNAN)
513 ++ return x;
514 ++ if (yc == IEEE754_CLASS_QNAN)
515 + return y;
516 +
517 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
518 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
519 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
520 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
521 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
522 +- return x;
523 ++ if (zc == IEEE754_CLASS_DNORM)
524 ++ DPDNORMZ;
525 ++ /* ZERO z cases are handled separately below */
526 +
527 ++ switch (CLPAIR(xc, yc)) {
528 +
529 + /*
530 + * Infinity handling
531 + */
532 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
533 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
534 +- if (zc == IEEE754_CLASS_QNAN)
535 +- return z;
536 + ieee754_setcx(IEEE754_INVALID_OPERATION);
537 + return ieee754dp_indef();
538 +
539 +@@ -102,9 +107,27 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
540 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
541 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
542 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
543 +- if (zc == IEEE754_CLASS_QNAN)
544 +- return z;
545 +- return ieee754dp_inf(xs ^ ys);
546 ++ if ((zc == IEEE754_CLASS_INF) &&
547 ++ ((!(flags & MADDF_NEGATE_PRODUCT) && (zs != (xs ^ ys))) ||
548 ++ ((flags & MADDF_NEGATE_PRODUCT) && (zs == (xs ^ ys))))) {
549 ++ /*
550 ++ * Cases of addition of infinities with opposite signs
551 ++ * or subtraction of infinities with same signs.
552 ++ */
553 ++ ieee754_setcx(IEEE754_INVALID_OPERATION);
554 ++ return ieee754dp_indef();
555 ++ }
556 ++ /*
557 ++ * z is here either not an infinity, or an infinity having the
558 ++ * same sign as product (x*y) (in case of MADDF.D instruction)
559 ++ * or product -(x*y) (in MSUBF.D case). The result must be an
560 ++ * infinity, and its sign is determined only by the value of
561 ++ * (flags & MADDF_NEGATE_PRODUCT) and the signs of x and y.
562 ++ */
563 ++ if (flags & MADDF_NEGATE_PRODUCT)
564 ++ return ieee754dp_inf(1 ^ (xs ^ ys));
565 ++ else
566 ++ return ieee754dp_inf(xs ^ ys);
567 +
568 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
569 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
570 +@@ -113,32 +136,42 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
571 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
572 + if (zc == IEEE754_CLASS_INF)
573 + return ieee754dp_inf(zs);
574 +- /* Multiplication is 0 so just return z */
575 ++ if (zc == IEEE754_CLASS_ZERO) {
576 ++ /* Handle cases +0 + (-0) and similar ones. */
577 ++ if ((!(flags & MADDF_NEGATE_PRODUCT)
578 ++ && (zs == (xs ^ ys))) ||
579 ++ ((flags & MADDF_NEGATE_PRODUCT)
580 ++ && (zs != (xs ^ ys))))
581 ++ /*
582 ++ * Cases of addition of zeros of equal signs
583 ++ * or subtraction of zeroes of opposite signs.
584 ++ * The sign of the resulting zero is in any
585 ++ * such case determined only by the sign of z.
586 ++ */
587 ++ return z;
588 ++
589 ++ return ieee754dp_zero(ieee754_csr.rm == FPU_CSR_RD);
590 ++ }
591 ++ /* x*y is here 0, and z is not 0, so just return z */
592 + return z;
593 +
594 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
595 + DPDNORMX;
596 +
597 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
598 +- if (zc == IEEE754_CLASS_QNAN)
599 +- return z;
600 +- else if (zc == IEEE754_CLASS_INF)
601 ++ if (zc == IEEE754_CLASS_INF)
602 + return ieee754dp_inf(zs);
603 + DPDNORMY;
604 + break;
605 +
606 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
607 +- if (zc == IEEE754_CLASS_QNAN)
608 +- return z;
609 +- else if (zc == IEEE754_CLASS_INF)
610 ++ if (zc == IEEE754_CLASS_INF)
611 + return ieee754dp_inf(zs);
612 + DPDNORMX;
613 + break;
614 +
615 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
616 +- if (zc == IEEE754_CLASS_QNAN)
617 +- return z;
618 +- else if (zc == IEEE754_CLASS_INF)
619 ++ if (zc == IEEE754_CLASS_INF)
620 + return ieee754dp_inf(zs);
621 + /* fall through to real computations */
622 + }
623 +@@ -157,7 +190,7 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
624 +
625 + re = xe + ye;
626 + rs = xs ^ ys;
627 +- if (flags & maddf_negate_product)
628 ++ if (flags & MADDF_NEGATE_PRODUCT)
629 + rs ^= 1;
630 +
631 + /* shunt to top of word */
632 +@@ -165,7 +198,7 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
633 + ym <<= 64 - (DP_FBITS + 1);
634 +
635 + /*
636 +- * Multiply 64 bits xm, ym to give high 64 bits rm with stickness.
637 ++ * Multiply 64 bits xm and ym to give 128 bits result in hrm:lrm.
638 + */
639 +
640 + /* 32 * 32 => 64 */
641 +@@ -195,81 +228,110 @@ static union ieee754dp _dp_maddf(union ieee754dp z, union ieee754dp x,
642 +
643 + hrm = hrm + (t >> 32);
644 +
645 +- rm = hrm | (lrm != 0);
646 +-
647 +- /*
648 +- * Sticky shift down to normal rounding precision.
649 +- */
650 +- if ((s64) rm < 0) {
651 +- rm = (rm >> (64 - (DP_FBITS + 1 + 3))) |
652 +- ((rm << (DP_FBITS + 1 + 3)) != 0);
653 ++ /* Put explicit bit at bit 126 if necessary */
654 ++ if ((int64_t)hrm < 0) {
655 ++ lrm = (hrm << 63) | (lrm >> 1);
656 ++ hrm = hrm >> 1;
657 + re++;
658 +- } else {
659 +- rm = (rm >> (64 - (DP_FBITS + 1 + 3 + 1))) |
660 +- ((rm << (DP_FBITS + 1 + 3 + 1)) != 0);
661 + }
662 +- assert(rm & (DP_HIDDEN_BIT << 3));
663 +
664 +- if (zc == IEEE754_CLASS_ZERO)
665 +- return ieee754dp_format(rs, re, rm);
666 ++ assert(hrm & (1 << 62));
667 +
668 +- /* And now the addition */
669 +- assert(zm & DP_HIDDEN_BIT);
670 ++ if (zc == IEEE754_CLASS_ZERO) {
671 ++ /*
672 ++ * Move explicit bit from bit 126 to bit 55 since the
673 ++ * ieee754dp_format code expects the mantissa to be
674 ++ * 56 bits wide (53 + 3 rounding bits).
675 ++ */
676 ++ srl128(&hrm, &lrm, (126 - 55));
677 ++ return ieee754dp_format(rs, re, lrm);
678 ++ }
679 +
680 +- /*
681 +- * Provide guard,round and stick bit space.
682 +- */
683 +- zm <<= 3;
684 ++ /* Move explicit bit from bit 52 to bit 126 */
685 ++ lzm = 0;
686 ++ hzm = zm << 10;
687 ++ assert(hzm & (1 << 62));
688 +
689 ++ /* Make the exponents the same */
690 + if (ze > re) {
691 + /*
692 + * Have to shift y fraction right to align.
693 + */
694 + s = ze - re;
695 +- rm = XDPSRS(rm, s);
696 ++ srl128(&hrm, &lrm, s);
697 + re += s;
698 + } else if (re > ze) {
699 + /*
700 + * Have to shift x fraction right to align.
701 + */
702 + s = re - ze;
703 +- zm = XDPSRS(zm, s);
704 ++ srl128(&hzm, &lzm, s);
705 + ze += s;
706 + }
707 + assert(ze == re);
708 + assert(ze <= DP_EMAX);
709 +
710 ++ /* Do the addition */
711 + if (zs == rs) {
712 + /*
713 +- * Generate 28 bit result of adding two 27 bit numbers
714 +- * leaving result in xm, xs and xe.
715 ++ * Generate 128 bit result by adding two 127 bit numbers
716 ++ * leaving result in hzm:lzm, zs and ze.
717 + */
718 +- zm = zm + rm;
719 +-
720 +- if (zm >> (DP_FBITS + 1 + 3)) { /* carry out */
721 +- zm = XDPSRS1(zm);
722 ++ hzm = hzm + hrm + (lzm > (lzm + lrm));
723 ++ lzm = lzm + lrm;
724 ++ if ((int64_t)hzm < 0) { /* carry out */
725 ++ srl128(&hzm, &lzm, 1);
726 + ze++;
727 + }
728 + } else {
729 +- if (zm >= rm) {
730 +- zm = zm - rm;
731 ++ if (hzm > hrm || (hzm == hrm && lzm >= lrm)) {
732 ++ hzm = hzm - hrm - (lzm < lrm);
733 ++ lzm = lzm - lrm;
734 + } else {
735 +- zm = rm - zm;
736 ++ hzm = hrm - hzm - (lrm < lzm);
737 ++ lzm = lrm - lzm;
738 + zs = rs;
739 + }
740 +- if (zm == 0)
741 ++ if (lzm == 0 && hzm == 0)
742 + return ieee754dp_zero(ieee754_csr.rm == FPU_CSR_RD);
743 +
744 + /*
745 +- * Normalize to rounding precision.
746 ++ * Put explicit bit at bit 126 if necessary.
747 + */
748 +- while ((zm >> (DP_FBITS + 3)) == 0) {
749 +- zm <<= 1;
750 +- ze--;
751 ++ if (hzm == 0) {
752 ++ /* left shift by 63 or 64 bits */
753 ++ if ((int64_t)lzm < 0) {
754 ++ /* MSB of lzm is the explicit bit */
755 ++ hzm = lzm >> 1;
756 ++ lzm = lzm << 63;
757 ++ ze -= 63;
758 ++ } else {
759 ++ hzm = lzm;
760 ++ lzm = 0;
761 ++ ze -= 64;
762 ++ }
763 ++ }
764 ++
765 ++ t = 0;
766 ++ while ((hzm >> (62 - t)) == 0)
767 ++ t++;
768 ++
769 ++ assert(t <= 62);
770 ++ if (t) {
771 ++ hzm = hzm << t | lzm >> (64 - t);
772 ++ lzm = lzm << t;
773 ++ ze -= t;
774 + }
775 + }
776 +
777 +- return ieee754dp_format(zs, ze, zm);
778 ++ /*
779 ++ * Move explicit bit from bit 126 to bit 55 since the
780 ++ * ieee754dp_format code expects the mantissa to be
781 ++ * 56 bits wide (53 + 3 rounding bits).
782 ++ */
783 ++ srl128(&hzm, &lzm, (126 - 55));
784 ++
785 ++ return ieee754dp_format(zs, ze, lzm);
786 + }
787 +
788 + union ieee754dp ieee754dp_maddf(union ieee754dp z, union ieee754dp x,
789 +@@ -281,5 +343,5 @@ union ieee754dp ieee754dp_maddf(union ieee754dp z, union ieee754dp x,
790 + union ieee754dp ieee754dp_msubf(union ieee754dp z, union ieee754dp x,
791 + union ieee754dp y)
792 + {
793 +- return _dp_maddf(z, x, y, maddf_negate_product);
794 ++ return _dp_maddf(z, x, y, MADDF_NEGATE_PRODUCT);
795 + }
796 +diff --git a/arch/mips/math-emu/ieee754int.h b/arch/mips/math-emu/ieee754int.h
797 +index 8bc2f6963324..dd2071f430e0 100644
798 +--- a/arch/mips/math-emu/ieee754int.h
799 ++++ b/arch/mips/math-emu/ieee754int.h
800 +@@ -26,6 +26,10 @@
801 +
802 + #define CLPAIR(x, y) ((x)*6+(y))
803 +
804 ++enum maddf_flags {
805 ++ MADDF_NEGATE_PRODUCT = 1 << 0,
806 ++};
807 ++
808 + static inline void ieee754_clearcx(void)
809 + {
810 + ieee754_csr.cx = 0;
811 +diff --git a/arch/mips/math-emu/ieee754sp.h b/arch/mips/math-emu/ieee754sp.h
812 +index 8476067075fe..0f63e4202cff 100644
813 +--- a/arch/mips/math-emu/ieee754sp.h
814 ++++ b/arch/mips/math-emu/ieee754sp.h
815 +@@ -45,6 +45,10 @@ static inline int ieee754sp_finite(union ieee754sp x)
816 + return SPBEXP(x) != SP_EMAX + 1 + SP_EBIAS;
817 + }
818 +
819 ++/* 64 bit right shift with rounding */
820 ++#define XSPSRS64(v, rs) \
821 ++ (((rs) >= 64) ? ((v) != 0) : ((v) >> (rs)) | ((v) << (64-(rs)) != 0))
822 ++
823 + /* 3bit extended single precision sticky right shift */
824 + #define XSPSRS(v, rs) \
825 + ((rs > (SP_FBITS+3))?1:((v) >> (rs)) | ((v) << (32-(rs)) != 0))
826 +diff --git a/arch/mips/math-emu/sp_fmax.c b/arch/mips/math-emu/sp_fmax.c
827 +index 4d000844e48e..74a5a00d2f22 100644
828 +--- a/arch/mips/math-emu/sp_fmax.c
829 ++++ b/arch/mips/math-emu/sp_fmax.c
830 +@@ -47,14 +47,26 @@ union ieee754sp ieee754sp_fmax(union ieee754sp x, union ieee754sp y)
831 + case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
832 + return ieee754sp_nanxcpt(x);
833 +
834 +- /* numbers are preferred to NaNs */
835 ++ /*
836 ++ * Quiet NaN handling
837 ++ */
838 ++
839 ++ /*
840 ++ * The case of both inputs quiet NaNs
841 ++ */
842 ++ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
843 ++ return x;
844 ++
845 ++ /*
846 ++ * The cases of exactly one input quiet NaN (numbers
847 ++ * are here preferred as returned values to NaNs)
848 ++ */
849 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
850 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
851 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
852 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
853 + return x;
854 +
855 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
856 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
857 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
858 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
859 +@@ -80,9 +92,7 @@ union ieee754sp ieee754sp_fmax(union ieee754sp x, union ieee754sp y)
860 + return ys ? x : y;
861 +
862 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
863 +- if (xs == ys)
864 +- return x;
865 +- return ieee754sp_zero(1);
866 ++ return ieee754sp_zero(xs & ys);
867 +
868 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
869 + SPDNORMX;
870 +@@ -106,16 +116,32 @@ union ieee754sp ieee754sp_fmax(union ieee754sp x, union ieee754sp y)
871 + else if (xs < ys)
872 + return x;
873 +
874 +- /* Compare exponent */
875 +- if (xe > ye)
876 +- return x;
877 +- else if (xe < ye)
878 +- return y;
879 ++ /* Signs of inputs are equal, let's compare exponents */
880 ++ if (xs == 0) {
881 ++ /* Inputs are both positive */
882 ++ if (xe > ye)
883 ++ return x;
884 ++ else if (xe < ye)
885 ++ return y;
886 ++ } else {
887 ++ /* Inputs are both negative */
888 ++ if (xe > ye)
889 ++ return y;
890 ++ else if (xe < ye)
891 ++ return x;
892 ++ }
893 +
894 +- /* Compare mantissa */
895 ++ /* Signs and exponents of inputs are equal, let's compare mantissas */
896 ++ if (xs == 0) {
897 ++ /* Inputs are both positive, with equal signs and exponents */
898 ++ if (xm <= ym)
899 ++ return y;
900 ++ return x;
901 ++ }
902 ++ /* Inputs are both negative, with equal signs and exponents */
903 + if (xm <= ym)
904 +- return y;
905 +- return x;
906 ++ return x;
907 ++ return y;
908 + }
909 +
910 + union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
911 +@@ -147,14 +173,26 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
912 + case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
913 + return ieee754sp_nanxcpt(x);
914 +
915 +- /* numbers are preferred to NaNs */
916 ++ /*
917 ++ * Quiet NaN handling
918 ++ */
919 ++
920 ++ /*
921 ++ * The case of both inputs quiet NaNs
922 ++ */
923 ++ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
924 ++ return x;
925 ++
926 ++ /*
927 ++ * The cases of exactly one input quiet NaN (numbers
928 ++ * are here preferred as returned values to NaNs)
929 ++ */
930 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
931 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
932 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
933 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
934 + return x;
935 +
936 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
937 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
938 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
939 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
940 +@@ -164,6 +202,9 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
941 + /*
942 + * Infinity and zero handling
943 + */
944 ++ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
945 ++ return ieee754sp_inf(xs & ys);
946 ++
947 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
948 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
949 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
950 +@@ -171,7 +212,6 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
951 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
952 + return x;
953 +
954 +- case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
955 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
956 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
957 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
958 +@@ -180,9 +220,7 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
959 + return y;
960 +
961 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
962 +- if (xs == ys)
963 +- return x;
964 +- return ieee754sp_zero(1);
965 ++ return ieee754sp_zero(xs & ys);
966 +
967 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
968 + SPDNORMX;
969 +@@ -207,7 +245,11 @@ union ieee754sp ieee754sp_fmaxa(union ieee754sp x, union ieee754sp y)
970 + return y;
971 +
972 + /* Compare mantissa */
973 +- if (xm <= ym)
974 ++ if (xm < ym)
975 + return y;
976 +- return x;
977 ++ else if (xm > ym)
978 ++ return x;
979 ++ else if (xs == 0)
980 ++ return x;
981 ++ return y;
982 + }
983 +diff --git a/arch/mips/math-emu/sp_fmin.c b/arch/mips/math-emu/sp_fmin.c
984 +index 4eb1bb9e9dec..c51385f46b09 100644
985 +--- a/arch/mips/math-emu/sp_fmin.c
986 ++++ b/arch/mips/math-emu/sp_fmin.c
987 +@@ -47,14 +47,26 @@ union ieee754sp ieee754sp_fmin(union ieee754sp x, union ieee754sp y)
988 + case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
989 + return ieee754sp_nanxcpt(x);
990 +
991 +- /* numbers are preferred to NaNs */
992 ++ /*
993 ++ * Quiet NaN handling
994 ++ */
995 ++
996 ++ /*
997 ++ * The case of both inputs quiet NaNs
998 ++ */
999 ++ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
1000 ++ return x;
1001 ++
1002 ++ /*
1003 ++ * The cases of exactly one input quiet NaN (numbers
1004 ++ * are here preferred as returned values to NaNs)
1005 ++ */
1006 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
1007 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
1008 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
1009 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
1010 + return x;
1011 +
1012 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
1013 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
1014 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
1015 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
1016 +@@ -80,9 +92,7 @@ union ieee754sp ieee754sp_fmin(union ieee754sp x, union ieee754sp y)
1017 + return ys ? y : x;
1018 +
1019 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
1020 +- if (xs == ys)
1021 +- return x;
1022 +- return ieee754sp_zero(1);
1023 ++ return ieee754sp_zero(xs | ys);
1024 +
1025 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
1026 + SPDNORMX;
1027 +@@ -106,16 +116,32 @@ union ieee754sp ieee754sp_fmin(union ieee754sp x, union ieee754sp y)
1028 + else if (xs < ys)
1029 + return y;
1030 +
1031 +- /* Compare exponent */
1032 +- if (xe > ye)
1033 +- return y;
1034 +- else if (xe < ye)
1035 +- return x;
1036 ++ /* Signs of inputs are the same, let's compare exponents */
1037 ++ if (xs == 0) {
1038 ++ /* Inputs are both positive */
1039 ++ if (xe > ye)
1040 ++ return y;
1041 ++ else if (xe < ye)
1042 ++ return x;
1043 ++ } else {
1044 ++ /* Inputs are both negative */
1045 ++ if (xe > ye)
1046 ++ return x;
1047 ++ else if (xe < ye)
1048 ++ return y;
1049 ++ }
1050 +
1051 +- /* Compare mantissa */
1052 ++ /* Signs and exponents of inputs are equal, let's compare mantissas */
1053 ++ if (xs == 0) {
1054 ++ /* Inputs are both positive, with equal signs and exponents */
1055 ++ if (xm <= ym)
1056 ++ return x;
1057 ++ return y;
1058 ++ }
1059 ++ /* Inputs are both negative, with equal signs and exponents */
1060 + if (xm <= ym)
1061 +- return x;
1062 +- return y;
1063 ++ return y;
1064 ++ return x;
1065 + }
1066 +
1067 + union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y)
1068 +@@ -147,14 +173,26 @@ union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y)
1069 + case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
1070 + return ieee754sp_nanxcpt(x);
1071 +
1072 +- /* numbers are preferred to NaNs */
1073 ++ /*
1074 ++ * Quiet NaN handling
1075 ++ */
1076 ++
1077 ++ /*
1078 ++ * The case of both inputs quiet NaNs
1079 ++ */
1080 ++ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
1081 ++ return x;
1082 ++
1083 ++ /*
1084 ++ * The cases of exactly one input quiet NaN (numbers
1085 ++ * are here preferred as returned values to NaNs)
1086 ++ */
1087 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
1088 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
1089 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
1090 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
1091 + return x;
1092 +
1093 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
1094 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
1095 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
1096 + case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
1097 +@@ -164,25 +202,25 @@ union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y)
1098 + /*
1099 + * Infinity and zero handling
1100 + */
1101 ++ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
1102 ++ return ieee754sp_inf(xs | ys);
1103 ++
1104 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
1105 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
1106 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
1107 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
1108 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
1109 +- return x;
1110 ++ return y;
1111 +
1112 +- case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
1113 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
1114 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
1115 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
1116 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
1117 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
1118 +- return y;
1119 ++ return x;
1120 +
1121 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
1122 +- if (xs == ys)
1123 +- return x;
1124 +- return ieee754sp_zero(1);
1125 ++ return ieee754sp_zero(xs | ys);
1126 +
1127 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
1128 + SPDNORMX;
1129 +@@ -207,7 +245,11 @@ union ieee754sp ieee754sp_fmina(union ieee754sp x, union ieee754sp y)
1130 + return x;
1131 +
1132 + /* Compare mantissa */
1133 +- if (xm <= ym)
1134 ++ if (xm < ym)
1135 ++ return x;
1136 ++ else if (xm > ym)
1137 ++ return y;
1138 ++ else if (xs == 1)
1139 + return x;
1140 + return y;
1141 + }
1142 +diff --git a/arch/mips/math-emu/sp_maddf.c b/arch/mips/math-emu/sp_maddf.c
1143 +index c91d5e5d9b5f..7195fe785d81 100644
1144 +--- a/arch/mips/math-emu/sp_maddf.c
1145 ++++ b/arch/mips/math-emu/sp_maddf.c
1146 +@@ -14,9 +14,6 @@
1147 +
1148 + #include "ieee754sp.h"
1149 +
1150 +-enum maddf_flags {
1151 +- maddf_negate_product = 1 << 0,
1152 +-};
1153 +
1154 + static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1155 + union ieee754sp y, enum maddf_flags flags)
1156 +@@ -24,14 +21,8 @@ static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1157 + int re;
1158 + int rs;
1159 + unsigned rm;
1160 +- unsigned short lxm;
1161 +- unsigned short hxm;
1162 +- unsigned short lym;
1163 +- unsigned short hym;
1164 +- unsigned lrm;
1165 +- unsigned hrm;
1166 +- unsigned t;
1167 +- unsigned at;
1168 ++ uint64_t rm64;
1169 ++ uint64_t zm64;
1170 + int s;
1171 +
1172 + COMPXSP;
1173 +@@ -48,51 +39,35 @@ static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1174 +
1175 + ieee754_clearcx();
1176 +
1177 +- switch (zc) {
1178 +- case IEEE754_CLASS_SNAN:
1179 +- ieee754_setcx(IEEE754_INVALID_OPERATION);
1180 ++ /*
1181 ++ * Handle the cases when at least one of x, y or z is a NaN.
1182 ++ * Order of precedence is sNaN, qNaN and z, x, y.
1183 ++ */
1184 ++ if (zc == IEEE754_CLASS_SNAN)
1185 + return ieee754sp_nanxcpt(z);
1186 +- case IEEE754_CLASS_DNORM:
1187 +- SPDNORMZ;
1188 +- /* QNAN and ZERO cases are handled separately below */
1189 +- }
1190 +-
1191 +- switch (CLPAIR(xc, yc)) {
1192 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
1193 +- case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
1194 +- case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
1195 +- case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
1196 +- case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
1197 ++ if (xc == IEEE754_CLASS_SNAN)
1198 ++ return ieee754sp_nanxcpt(x);
1199 ++ if (yc == IEEE754_CLASS_SNAN)
1200 + return ieee754sp_nanxcpt(y);
1201 ++ if (zc == IEEE754_CLASS_QNAN)
1202 ++ return z;
1203 ++ if (xc == IEEE754_CLASS_QNAN)
1204 ++ return x;
1205 ++ if (yc == IEEE754_CLASS_QNAN)
1206 ++ return y;
1207 +
1208 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
1209 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
1210 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
1211 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
1212 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
1213 +- case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
1214 +- return ieee754sp_nanxcpt(x);
1215 ++ if (zc == IEEE754_CLASS_DNORM)
1216 ++ SPDNORMZ;
1217 ++ /* ZERO z cases are handled separately below */
1218 +
1219 +- case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
1220 +- case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
1221 +- case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
1222 +- case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
1223 +- return y;
1224 ++ switch (CLPAIR(xc, yc)) {
1225 +
1226 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
1227 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
1228 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
1229 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
1230 +- case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
1231 +- return x;
1232 +
1233 + /*
1234 + * Infinity handling
1235 + */
1236 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
1237 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
1238 +- if (zc == IEEE754_CLASS_QNAN)
1239 +- return z;
1240 + ieee754_setcx(IEEE754_INVALID_OPERATION);
1241 + return ieee754sp_indef();
1242 +
1243 +@@ -101,9 +76,27 @@ static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1244 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
1245 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
1246 + case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
1247 +- if (zc == IEEE754_CLASS_QNAN)
1248 +- return z;
1249 +- return ieee754sp_inf(xs ^ ys);
1250 ++ if ((zc == IEEE754_CLASS_INF) &&
1251 ++ ((!(flags & MADDF_NEGATE_PRODUCT) && (zs != (xs ^ ys))) ||
1252 ++ ((flags & MADDF_NEGATE_PRODUCT) && (zs == (xs ^ ys))))) {
1253 ++ /*
1254 ++ * Cases of addition of infinities with opposite signs
1255 ++ * or subtraction of infinities with same signs.
1256 ++ */
1257 ++ ieee754_setcx(IEEE754_INVALID_OPERATION);
1258 ++ return ieee754sp_indef();
1259 ++ }
1260 ++ /*
1261 ++ * z is here either not an infinity, or an infinity having the
1262 ++ * same sign as product (x*y) (in case of MADDF.D instruction)
1263 ++ * or product -(x*y) (in MSUBF.D case). The result must be an
1264 ++ * infinity, and its sign is determined only by the value of
1265 ++ * (flags & MADDF_NEGATE_PRODUCT) and the signs of x and y.
1266 ++ */
1267 ++ if (flags & MADDF_NEGATE_PRODUCT)
1268 ++ return ieee754sp_inf(1 ^ (xs ^ ys));
1269 ++ else
1270 ++ return ieee754sp_inf(xs ^ ys);
1271 +
1272 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
1273 + case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
1274 +@@ -112,32 +105,42 @@ static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1275 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
1276 + if (zc == IEEE754_CLASS_INF)
1277 + return ieee754sp_inf(zs);
1278 +- /* Multiplication is 0 so just return z */
1279 ++ if (zc == IEEE754_CLASS_ZERO) {
1280 ++ /* Handle cases +0 + (-0) and similar ones. */
1281 ++ if ((!(flags & MADDF_NEGATE_PRODUCT)
1282 ++ && (zs == (xs ^ ys))) ||
1283 ++ ((flags & MADDF_NEGATE_PRODUCT)
1284 ++ && (zs != (xs ^ ys))))
1285 ++ /*
1286 ++ * Cases of addition of zeros of equal signs
1287 ++ * or subtraction of zeroes of opposite signs.
1288 ++ * The sign of the resulting zero is in any
1289 ++ * such case determined only by the sign of z.
1290 ++ */
1291 ++ return z;
1292 ++
1293 ++ return ieee754sp_zero(ieee754_csr.rm == FPU_CSR_RD);
1294 ++ }
1295 ++ /* x*y is here 0, and z is not 0, so just return z */
1296 + return z;
1297 +
1298 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
1299 + SPDNORMX;
1300 +
1301 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
1302 +- if (zc == IEEE754_CLASS_QNAN)
1303 +- return z;
1304 +- else if (zc == IEEE754_CLASS_INF)
1305 ++ if (zc == IEEE754_CLASS_INF)
1306 + return ieee754sp_inf(zs);
1307 + SPDNORMY;
1308 + break;
1309 +
1310 + case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
1311 +- if (zc == IEEE754_CLASS_QNAN)
1312 +- return z;
1313 +- else if (zc == IEEE754_CLASS_INF)
1314 ++ if (zc == IEEE754_CLASS_INF)
1315 + return ieee754sp_inf(zs);
1316 + SPDNORMX;
1317 + break;
1318 +
1319 + case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
1320 +- if (zc == IEEE754_CLASS_QNAN)
1321 +- return z;
1322 +- else if (zc == IEEE754_CLASS_INF)
1323 ++ if (zc == IEEE754_CLASS_INF)
1324 + return ieee754sp_inf(zs);
1325 + /* fall through to real computations */
1326 + }
1327 +@@ -158,111 +161,93 @@ static union ieee754sp _sp_maddf(union ieee754sp z, union ieee754sp x,
1328 +
1329 + re = xe + ye;
1330 + rs = xs ^ ys;
1331 +- if (flags & maddf_negate_product)
1332 ++ if (flags & MADDF_NEGATE_PRODUCT)
1333 + rs ^= 1;
1334 +
1335 +- /* shunt to top of word */
1336 +- xm <<= 32 - (SP_FBITS + 1);
1337 +- ym <<= 32 - (SP_FBITS + 1);
1338 +-
1339 +- /*
1340 +- * Multiply 32 bits xm, ym to give high 32 bits rm with stickness.
1341 +- */
1342 +- lxm = xm & 0xffff;
1343 +- hxm = xm >> 16;
1344 +- lym = ym & 0xffff;
1345 +- hym = ym >> 16;
1346 +-
1347 +- lrm = lxm * lym; /* 16 * 16 => 32 */
1348 +- hrm = hxm * hym; /* 16 * 16 => 32 */
1349 +-
1350 +- t = lxm * hym; /* 16 * 16 => 32 */
1351 +- at = lrm + (t << 16);
1352 +- hrm += at < lrm;
1353 +- lrm = at;
1354 +- hrm = hrm + (t >> 16);
1355 ++ /* Multiple 24 bit xm and ym to give 48 bit results */
1356 ++ rm64 = (uint64_t)xm * ym;
1357 +
1358 +- t = hxm * lym; /* 16 * 16 => 32 */
1359 +- at = lrm + (t << 16);
1360 +- hrm += at < lrm;
1361 +- lrm = at;
1362 +- hrm = hrm + (t >> 16);
1363 ++ /* Shunt to top of word */
1364 ++ rm64 = rm64 << 16;
1365 +
1366 +- rm = hrm | (lrm != 0);
1367 +-
1368 +- /*
1369 +- * Sticky shift down to normal rounding precision.
1370 +- */
1371 +- if ((int) rm < 0) {
1372 +- rm = (rm >> (32 - (SP_FBITS + 1 + 3))) |
1373 +- ((rm << (SP_FBITS + 1 + 3)) != 0);
1374 ++ /* Put explicit bit at bit 62 if necessary */
1375 ++ if ((int64_t) rm64 < 0) {
1376 ++ rm64 = rm64 >> 1;
1377 + re++;
1378 +- } else {
1379 +- rm = (rm >> (32 - (SP_FBITS + 1 + 3 + 1))) |
1380 +- ((rm << (SP_FBITS + 1 + 3 + 1)) != 0);
1381 + }
1382 +- assert(rm & (SP_HIDDEN_BIT << 3));
1383 +-
1384 +- if (zc == IEEE754_CLASS_ZERO)
1385 +- return ieee754sp_format(rs, re, rm);
1386 +
1387 +- /* And now the addition */
1388 ++ assert(rm64 & (1 << 62));
1389 +
1390 +- assert(zm & SP_HIDDEN_BIT);
1391 ++ if (zc == IEEE754_CLASS_ZERO) {
1392 ++ /*
1393 ++ * Move explicit bit from bit 62 to bit 26 since the
1394 ++ * ieee754sp_format code expects the mantissa to be
1395 ++ * 27 bits wide (24 + 3 rounding bits).
1396 ++ */
1397 ++ rm = XSPSRS64(rm64, (62 - 26));
1398 ++ return ieee754sp_format(rs, re, rm);
1399 ++ }
1400 +
1401 +- /*
1402 +- * Provide guard,round and stick bit space.
1403 +- */
1404 +- zm <<= 3;
1405 ++ /* Move explicit bit from bit 23 to bit 62 */
1406 ++ zm64 = (uint64_t)zm << (62 - 23);
1407 ++ assert(zm64 & (1 << 62));
1408 +
1409 ++ /* Make the exponents the same */
1410 + if (ze > re) {
1411 + /*
1412 + * Have to shift r fraction right to align.
1413 + */
1414 + s = ze - re;
1415 +- rm = XSPSRS(rm, s);
1416 ++ rm64 = XSPSRS64(rm64, s);
1417 + re += s;
1418 + } else if (re > ze) {
1419 + /*
1420 + * Have to shift z fraction right to align.
1421 + */
1422 + s = re - ze;
1423 +- zm = XSPSRS(zm, s);
1424 ++ zm64 = XSPSRS64(zm64, s);
1425 + ze += s;
1426 + }
1427 + assert(ze == re);
1428 + assert(ze <= SP_EMAX);
1429 +
1430 ++ /* Do the addition */
1431 + if (zs == rs) {
1432 + /*
1433 +- * Generate 28 bit result of adding two 27 bit numbers
1434 +- * leaving result in zm, zs and ze.
1435 ++ * Generate 64 bit result by adding two 63 bit numbers
1436 ++ * leaving result in zm64, zs and ze.
1437 + */
1438 +- zm = zm + rm;
1439 +-
1440 +- if (zm >> (SP_FBITS + 1 + 3)) { /* carry out */
1441 +- zm = XSPSRS1(zm);
1442 ++ zm64 = zm64 + rm64;
1443 ++ if ((int64_t)zm64 < 0) { /* carry out */
1444 ++ zm64 = XSPSRS1(zm64);
1445 + ze++;
1446 + }
1447 + } else {
1448 +- if (zm >= rm) {
1449 +- zm = zm - rm;
1450 ++ if (zm64 >= rm64) {
1451 ++ zm64 = zm64 - rm64;
1452 + } else {
1453 +- zm = rm - zm;
1454 ++ zm64 = rm64 - zm64;
1455 + zs = rs;
1456 + }
1457 +- if (zm == 0)
1458 ++ if (zm64 == 0)
1459 + return ieee754sp_zero(ieee754_csr.rm == FPU_CSR_RD);
1460 +
1461 + /*
1462 +- * Normalize in extended single precision
1463 ++ * Put explicit bit at bit 62 if necessary.
1464 + */
1465 +- while ((zm >> (SP_MBITS + 3)) == 0) {
1466 +- zm <<= 1;
1467 ++ while ((zm64 >> 62) == 0) {
1468 ++ zm64 <<= 1;
1469 + ze--;
1470 + }
1471 +-
1472 + }
1473 ++
1474 ++ /*
1475 ++ * Move explicit bit from bit 62 to bit 26 since the
1476 ++ * ieee754sp_format code expects the mantissa to be
1477 ++ * 27 bits wide (24 + 3 rounding bits).
1478 ++ */
1479 ++ zm = XSPSRS64(zm64, (62 - 26));
1480 ++
1481 + return ieee754sp_format(zs, ze, zm);
1482 + }
1483 +
1484 +@@ -275,5 +260,5 @@ union ieee754sp ieee754sp_maddf(union ieee754sp z, union ieee754sp x,
1485 + union ieee754sp ieee754sp_msubf(union ieee754sp z, union ieee754sp x,
1486 + union ieee754sp y)
1487 + {
1488 +- return _sp_maddf(z, x, y, maddf_negate_product);
1489 ++ return _sp_maddf(z, x, y, MADDF_NEGATE_PRODUCT);
1490 + }
1491 +diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c
1492 +index ec7a8b099dd9..fd3c1fcc73eb 100644
1493 +--- a/arch/powerpc/kernel/align.c
1494 ++++ b/arch/powerpc/kernel/align.c
1495 +@@ -235,6 +235,28 @@ static int emulate_dcbz(struct pt_regs *regs, unsigned char __user *addr)
1496 +
1497 + #define SWIZ_PTR(p) ((unsigned char __user *)((p) ^ swiz))
1498 +
1499 ++#define __get_user_or_set_dar(_regs, _dest, _addr) \
1500 ++ ({ \
1501 ++ int rc = 0; \
1502 ++ typeof(_addr) __addr = (_addr); \
1503 ++ if (__get_user_inatomic(_dest, __addr)) { \
1504 ++ _regs->dar = (unsigned long)__addr; \
1505 ++ rc = -EFAULT; \
1506 ++ } \
1507 ++ rc; \
1508 ++ })
1509 ++
1510 ++#define __put_user_or_set_dar(_regs, _src, _addr) \
1511 ++ ({ \
1512 ++ int rc = 0; \
1513 ++ typeof(_addr) __addr = (_addr); \
1514 ++ if (__put_user_inatomic(_src, __addr)) { \
1515 ++ _regs->dar = (unsigned long)__addr; \
1516 ++ rc = -EFAULT; \
1517 ++ } \
1518 ++ rc; \
1519 ++ })
1520 ++
1521 + static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr,
1522 + unsigned int reg, unsigned int nb,
1523 + unsigned int flags, unsigned int instr,
1524 +@@ -263,9 +285,10 @@ static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr,
1525 + } else {
1526 + unsigned long pc = regs->nip ^ (swiz & 4);
1527 +
1528 +- if (__get_user_inatomic(instr,
1529 +- (unsigned int __user *)pc))
1530 ++ if (__get_user_or_set_dar(regs, instr,
1531 ++ (unsigned int __user *)pc))
1532 + return -EFAULT;
1533 ++
1534 + if (swiz == 0 && (flags & SW))
1535 + instr = cpu_to_le32(instr);
1536 + nb = (instr >> 11) & 0x1f;
1537 +@@ -309,31 +332,31 @@ static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr,
1538 + ((nb0 + 3) / 4) * sizeof(unsigned long));
1539 +
1540 + for (i = 0; i < nb; ++i, ++p)
1541 +- if (__get_user_inatomic(REG_BYTE(rptr, i ^ bswiz),
1542 +- SWIZ_PTR(p)))
1543 ++ if (__get_user_or_set_dar(regs, REG_BYTE(rptr, i ^ bswiz),
1544 ++ SWIZ_PTR(p)))
1545 + return -EFAULT;
1546 + if (nb0 > 0) {
1547 + rptr = &regs->gpr[0];
1548 + addr += nb;
1549 + for (i = 0; i < nb0; ++i, ++p)
1550 +- if (__get_user_inatomic(REG_BYTE(rptr,
1551 +- i ^ bswiz),
1552 +- SWIZ_PTR(p)))
1553 ++ if (__get_user_or_set_dar(regs,
1554 ++ REG_BYTE(rptr, i ^ bswiz),
1555 ++ SWIZ_PTR(p)))
1556 + return -EFAULT;
1557 + }
1558 +
1559 + } else {
1560 + for (i = 0; i < nb; ++i, ++p)
1561 +- if (__put_user_inatomic(REG_BYTE(rptr, i ^ bswiz),
1562 +- SWIZ_PTR(p)))
1563 ++ if (__put_user_or_set_dar(regs, REG_BYTE(rptr, i ^ bswiz),
1564 ++ SWIZ_PTR(p)))
1565 + return -EFAULT;
1566 + if (nb0 > 0) {
1567 + rptr = &regs->gpr[0];
1568 + addr += nb;
1569 + for (i = 0; i < nb0; ++i, ++p)
1570 +- if (__put_user_inatomic(REG_BYTE(rptr,
1571 +- i ^ bswiz),
1572 +- SWIZ_PTR(p)))
1573 ++ if (__put_user_or_set_dar(regs,
1574 ++ REG_BYTE(rptr, i ^ bswiz),
1575 ++ SWIZ_PTR(p)))
1576 + return -EFAULT;
1577 + }
1578 + }
1579 +@@ -345,29 +368,32 @@ static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr,
1580 + * Only POWER6 has these instructions, and it does true little-endian,
1581 + * so we don't need the address swizzling.
1582 + */
1583 +-static int emulate_fp_pair(unsigned char __user *addr, unsigned int reg,
1584 +- unsigned int flags)
1585 ++static int emulate_fp_pair(struct pt_regs *regs, unsigned char __user *addr,
1586 ++ unsigned int reg, unsigned int flags)
1587 + {
1588 + char *ptr0 = (char *) &current->thread.TS_FPR(reg);
1589 + char *ptr1 = (char *) &current->thread.TS_FPR(reg+1);
1590 +- int i, ret, sw = 0;
1591 ++ int i, sw = 0;
1592 +
1593 + if (reg & 1)
1594 + return 0; /* invalid form: FRS/FRT must be even */
1595 + if (flags & SW)
1596 + sw = 7;
1597 +- ret = 0;
1598 ++
1599 + for (i = 0; i < 8; ++i) {
1600 + if (!(flags & ST)) {
1601 +- ret |= __get_user(ptr0[i^sw], addr + i);
1602 +- ret |= __get_user(ptr1[i^sw], addr + i + 8);
1603 ++ if (__get_user_or_set_dar(regs, ptr0[i^sw], addr + i))
1604 ++ return -EFAULT;
1605 ++ if (__get_user_or_set_dar(regs, ptr1[i^sw], addr + i + 8))
1606 ++ return -EFAULT;
1607 + } else {
1608 +- ret |= __put_user(ptr0[i^sw], addr + i);
1609 +- ret |= __put_user(ptr1[i^sw], addr + i + 8);
1610 ++ if (__put_user_or_set_dar(regs, ptr0[i^sw], addr + i))
1611 ++ return -EFAULT;
1612 ++ if (__put_user_or_set_dar(regs, ptr1[i^sw], addr + i + 8))
1613 ++ return -EFAULT;
1614 + }
1615 + }
1616 +- if (ret)
1617 +- return -EFAULT;
1618 ++
1619 + return 1; /* exception handled and fixed up */
1620 + }
1621 +
1622 +@@ -377,24 +403,27 @@ static int emulate_lq_stq(struct pt_regs *regs, unsigned char __user *addr,
1623 + {
1624 + char *ptr0 = (char *)&regs->gpr[reg];
1625 + char *ptr1 = (char *)&regs->gpr[reg+1];
1626 +- int i, ret, sw = 0;
1627 ++ int i, sw = 0;
1628 +
1629 + if (reg & 1)
1630 + return 0; /* invalid form: GPR must be even */
1631 + if (flags & SW)
1632 + sw = 7;
1633 +- ret = 0;
1634 ++
1635 + for (i = 0; i < 8; ++i) {
1636 + if (!(flags & ST)) {
1637 +- ret |= __get_user(ptr0[i^sw], addr + i);
1638 +- ret |= __get_user(ptr1[i^sw], addr + i + 8);
1639 ++ if (__get_user_or_set_dar(regs, ptr0[i^sw], addr + i))
1640 ++ return -EFAULT;
1641 ++ if (__get_user_or_set_dar(regs, ptr1[i^sw], addr + i + 8))
1642 ++ return -EFAULT;
1643 + } else {
1644 +- ret |= __put_user(ptr0[i^sw], addr + i);
1645 +- ret |= __put_user(ptr1[i^sw], addr + i + 8);
1646 ++ if (__put_user_or_set_dar(regs, ptr0[i^sw], addr + i))
1647 ++ return -EFAULT;
1648 ++ if (__put_user_or_set_dar(regs, ptr1[i^sw], addr + i + 8))
1649 ++ return -EFAULT;
1650 + }
1651 + }
1652 +- if (ret)
1653 +- return -EFAULT;
1654 ++
1655 + return 1; /* exception handled and fixed up */
1656 + }
1657 + #endif /* CONFIG_PPC64 */
1658 +@@ -687,9 +716,14 @@ static int emulate_vsx(unsigned char __user *addr, unsigned int reg,
1659 + for (j = 0; j < length; j += elsize) {
1660 + for (i = 0; i < elsize; ++i) {
1661 + if (flags & ST)
1662 +- ret |= __put_user(ptr[i^sw], addr + i);
1663 ++ ret = __put_user_or_set_dar(regs, ptr[i^sw],
1664 ++ addr + i);
1665 + else
1666 +- ret |= __get_user(ptr[i^sw], addr + i);
1667 ++ ret = __get_user_or_set_dar(regs, ptr[i^sw],
1668 ++ addr + i);
1669 ++
1670 ++ if (ret)
1671 ++ return ret;
1672 + }
1673 + ptr += elsize;
1674 + #ifdef __LITTLE_ENDIAN__
1675 +@@ -739,7 +773,7 @@ int fix_alignment(struct pt_regs *regs)
1676 + unsigned int dsisr;
1677 + unsigned char __user *addr;
1678 + unsigned long p, swiz;
1679 +- int ret, i;
1680 ++ int i;
1681 + union data {
1682 + u64 ll;
1683 + double dd;
1684 +@@ -936,7 +970,7 @@ int fix_alignment(struct pt_regs *regs)
1685 + if (flags & F) {
1686 + /* Special case for 16-byte FP loads and stores */
1687 + PPC_WARN_ALIGNMENT(fp_pair, regs);
1688 +- return emulate_fp_pair(addr, reg, flags);
1689 ++ return emulate_fp_pair(regs, addr, reg, flags);
1690 + } else {
1691 + #ifdef CONFIG_PPC64
1692 + /* Special case for 16-byte loads and stores */
1693 +@@ -966,15 +1000,12 @@ int fix_alignment(struct pt_regs *regs)
1694 + }
1695 +
1696 + data.ll = 0;
1697 +- ret = 0;
1698 + p = (unsigned long)addr;
1699 +
1700 + for (i = 0; i < nb; i++)
1701 +- ret |= __get_user_inatomic(data.v[start + i],
1702 +- SWIZ_PTR(p++));
1703 +-
1704 +- if (unlikely(ret))
1705 +- return -EFAULT;
1706 ++ if (__get_user_or_set_dar(regs, data.v[start + i],
1707 ++ SWIZ_PTR(p++)))
1708 ++ return -EFAULT;
1709 +
1710 + } else if (flags & F) {
1711 + data.ll = current->thread.TS_FPR(reg);
1712 +@@ -1046,15 +1077,13 @@ int fix_alignment(struct pt_regs *regs)
1713 + break;
1714 + }
1715 +
1716 +- ret = 0;
1717 + p = (unsigned long)addr;
1718 +
1719 + for (i = 0; i < nb; i++)
1720 +- ret |= __put_user_inatomic(data.v[start + i],
1721 +- SWIZ_PTR(p++));
1722 ++ if (__put_user_or_set_dar(regs, data.v[start + i],
1723 ++ SWIZ_PTR(p++)))
1724 ++ return -EFAULT;
1725 +
1726 +- if (unlikely(ret))
1727 +- return -EFAULT;
1728 + } else if (flags & F)
1729 + current->thread.TS_FPR(reg) = data.ll;
1730 + else
1731 +diff --git a/arch/powerpc/platforms/powernv/npu-dma.c b/arch/powerpc/platforms/powernv/npu-dma.c
1732 +index 4c7b8591f737..2cb6cbea4b3b 100644
1733 +--- a/arch/powerpc/platforms/powernv/npu-dma.c
1734 ++++ b/arch/powerpc/platforms/powernv/npu-dma.c
1735 +@@ -545,6 +545,12 @@ static void mmio_invalidate(struct npu_context *npu_context, int va,
1736 + struct mmio_atsd_reg mmio_atsd_reg[NV_MAX_NPUS];
1737 + unsigned long pid = npu_context->mm->context.id;
1738 +
1739 ++ /*
1740 ++ * Unfortunately the nest mmu does not support flushing specific
1741 ++ * addresses so we have to flush the whole mm.
1742 ++ */
1743 ++ flush_tlb_mm(npu_context->mm);
1744 ++
1745 + /*
1746 + * Loop over all the NPUs this process is active on and launch
1747 + * an invalidate.
1748 +@@ -576,12 +582,6 @@ static void mmio_invalidate(struct npu_context *npu_context, int va,
1749 + }
1750 + }
1751 +
1752 +- /*
1753 +- * Unfortunately the nest mmu does not support flushing specific
1754 +- * addresses so we have to flush the whole mm.
1755 +- */
1756 +- flush_tlb_mm(npu_context->mm);
1757 +-
1758 + mmio_invalidate_wait(mmio_atsd_reg, flush);
1759 + if (flush)
1760 + /* Wait for the flush to complete */
1761 +diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
1762 +index ca9b2f4aaa22..bf2f43f7ac6a 100644
1763 +--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
1764 ++++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
1765 +@@ -817,6 +817,9 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add, struct property *prop)
1766 + return -EINVAL;
1767 +
1768 + for (i = 0; i < num_lmbs && lmbs_to_add != lmbs_added; i++) {
1769 ++ if (lmbs[i].flags & DRCONF_MEM_ASSIGNED)
1770 ++ continue;
1771 ++
1772 + rc = dlpar_acquire_drc(lmbs[i].drc_index);
1773 + if (rc)
1774 + continue;
1775 +@@ -859,6 +862,7 @@ static int dlpar_memory_add_by_count(u32 lmbs_to_add, struct property *prop)
1776 + lmbs[i].base_addr, lmbs[i].drc_index);
1777 + lmbs[i].reserved = 0;
1778 + }
1779 ++ rc = 0;
1780 + }
1781 +
1782 + return rc;
1783 +diff --git a/arch/s390/include/asm/mmu.h b/arch/s390/include/asm/mmu.h
1784 +index bd6f30304518..3525fe6e7e4c 100644
1785 +--- a/arch/s390/include/asm/mmu.h
1786 ++++ b/arch/s390/include/asm/mmu.h
1787 +@@ -5,6 +5,7 @@
1788 + #include <linux/errno.h>
1789 +
1790 + typedef struct {
1791 ++ spinlock_t lock;
1792 + cpumask_t cpu_attach_mask;
1793 + atomic_t flush_count;
1794 + unsigned int flush_mm;
1795 +@@ -27,6 +28,7 @@ typedef struct {
1796 + } mm_context_t;
1797 +
1798 + #define INIT_MM_CONTEXT(name) \
1799 ++ .context.lock = __SPIN_LOCK_UNLOCKED(name.context.lock), \
1800 + .context.pgtable_lock = \
1801 + __SPIN_LOCK_UNLOCKED(name.context.pgtable_lock), \
1802 + .context.pgtable_list = LIST_HEAD_INIT(name.context.pgtable_list), \
1803 +diff --git a/arch/s390/include/asm/mmu_context.h b/arch/s390/include/asm/mmu_context.h
1804 +index 24bc41622a98..ebfb2f248ae9 100644
1805 +--- a/arch/s390/include/asm/mmu_context.h
1806 ++++ b/arch/s390/include/asm/mmu_context.h
1807 +@@ -16,6 +16,7 @@
1808 + static inline int init_new_context(struct task_struct *tsk,
1809 + struct mm_struct *mm)
1810 + {
1811 ++ spin_lock_init(&mm->context.lock);
1812 + spin_lock_init(&mm->context.pgtable_lock);
1813 + INIT_LIST_HEAD(&mm->context.pgtable_list);
1814 + spin_lock_init(&mm->context.gmap_lock);
1815 +@@ -102,7 +103,6 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
1816 + if (prev == next)
1817 + return;
1818 + cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
1819 +- cpumask_set_cpu(cpu, mm_cpumask(next));
1820 + /* Clear old ASCE by loading the kernel ASCE. */
1821 + __ctl_load(S390_lowcore.kernel_asce, 1, 1);
1822 + __ctl_load(S390_lowcore.kernel_asce, 7, 7);
1823 +@@ -120,9 +120,8 @@ static inline void finish_arch_post_lock_switch(void)
1824 + preempt_disable();
1825 + while (atomic_read(&mm->context.flush_count))
1826 + cpu_relax();
1827 +-
1828 +- if (mm->context.flush_mm)
1829 +- __tlb_flush_mm(mm);
1830 ++ cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
1831 ++ __tlb_flush_mm_lazy(mm);
1832 + preempt_enable();
1833 + }
1834 + set_fs(current->thread.mm_segment);
1835 +@@ -135,6 +134,7 @@ static inline void activate_mm(struct mm_struct *prev,
1836 + struct mm_struct *next)
1837 + {
1838 + switch_mm(prev, next, current);
1839 ++ cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
1840 + set_user_asce(next);
1841 + }
1842 +
1843 +diff --git a/arch/s390/include/asm/tlbflush.h b/arch/s390/include/asm/tlbflush.h
1844 +index 39846100682a..eed927aeb08f 100644
1845 +--- a/arch/s390/include/asm/tlbflush.h
1846 ++++ b/arch/s390/include/asm/tlbflush.h
1847 +@@ -43,23 +43,6 @@ static inline void __tlb_flush_global(void)
1848 + * Flush TLB entries for a specific mm on all CPUs (in case gmap is used
1849 + * this implicates multiple ASCEs!).
1850 + */
1851 +-static inline void __tlb_flush_full(struct mm_struct *mm)
1852 +-{
1853 +- preempt_disable();
1854 +- atomic_inc(&mm->context.flush_count);
1855 +- if (cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id()))) {
1856 +- /* Local TLB flush */
1857 +- __tlb_flush_local();
1858 +- } else {
1859 +- /* Global TLB flush */
1860 +- __tlb_flush_global();
1861 +- /* Reset TLB flush mask */
1862 +- cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
1863 +- }
1864 +- atomic_dec(&mm->context.flush_count);
1865 +- preempt_enable();
1866 +-}
1867 +-
1868 + static inline void __tlb_flush_mm(struct mm_struct *mm)
1869 + {
1870 + unsigned long gmap_asce;
1871 +@@ -71,16 +54,18 @@ static inline void __tlb_flush_mm(struct mm_struct *mm)
1872 + */
1873 + preempt_disable();
1874 + atomic_inc(&mm->context.flush_count);
1875 ++ /* Reset TLB flush mask */
1876 ++ cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
1877 ++ barrier();
1878 + gmap_asce = READ_ONCE(mm->context.gmap_asce);
1879 + if (MACHINE_HAS_IDTE && gmap_asce != -1UL) {
1880 + if (gmap_asce)
1881 + __tlb_flush_idte(gmap_asce);
1882 + __tlb_flush_idte(mm->context.asce);
1883 + } else {
1884 +- __tlb_flush_full(mm);
1885 ++ /* Global TLB flush */
1886 ++ __tlb_flush_global();
1887 + }
1888 +- /* Reset TLB flush mask */
1889 +- cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
1890 + atomic_dec(&mm->context.flush_count);
1891 + preempt_enable();
1892 + }
1893 +@@ -94,7 +79,6 @@ static inline void __tlb_flush_kernel(void)
1894 + }
1895 + #else
1896 + #define __tlb_flush_global() __tlb_flush_local()
1897 +-#define __tlb_flush_full(mm) __tlb_flush_local()
1898 +
1899 + /*
1900 + * Flush TLB entries for a specific ASCE on all CPUs.
1901 +@@ -112,10 +96,12 @@ static inline void __tlb_flush_kernel(void)
1902 +
1903 + static inline void __tlb_flush_mm_lazy(struct mm_struct * mm)
1904 + {
1905 ++ spin_lock(&mm->context.lock);
1906 + if (mm->context.flush_mm) {
1907 +- __tlb_flush_mm(mm);
1908 + mm->context.flush_mm = 0;
1909 ++ __tlb_flush_mm(mm);
1910 + }
1911 ++ spin_unlock(&mm->context.lock);
1912 + }
1913 +
1914 + /*
1915 +diff --git a/block/blk-core.c b/block/blk-core.c
1916 +index dbecbf4a64e0..658f67309602 100644
1917 +--- a/block/blk-core.c
1918 ++++ b/block/blk-core.c
1919 +@@ -280,7 +280,7 @@ EXPORT_SYMBOL(blk_start_queue_async);
1920 + void blk_start_queue(struct request_queue *q)
1921 + {
1922 + lockdep_assert_held(q->queue_lock);
1923 +- WARN_ON(!irqs_disabled());
1924 ++ WARN_ON(!in_interrupt() && !irqs_disabled());
1925 + WARN_ON_ONCE(q->mq_ops);
1926 +
1927 + queue_flag_clear(QUEUE_FLAG_STOPPED, q);
1928 +@@ -2330,7 +2330,12 @@ blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *
1929 + if (q->mq_ops) {
1930 + if (blk_queue_io_stat(q))
1931 + blk_account_io_start(rq, true);
1932 +- blk_mq_sched_insert_request(rq, false, true, false, false);
1933 ++ /*
1934 ++ * Since we have a scheduler attached on the top device,
1935 ++ * bypass a potential scheduler on the bottom device for
1936 ++ * insert.
1937 ++ */
1938 ++ blk_mq_request_bypass_insert(rq);
1939 + return BLK_STS_OK;
1940 + }
1941 +
1942 +diff --git a/block/blk-mq.c b/block/blk-mq.c
1943 +index 4603b115e234..e0523eb8eee1 100644
1944 +--- a/block/blk-mq.c
1945 ++++ b/block/blk-mq.c
1946 +@@ -1357,6 +1357,22 @@ void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
1947 + blk_mq_hctx_mark_pending(hctx, ctx);
1948 + }
1949 +
1950 ++/*
1951 ++ * Should only be used carefully, when the caller knows we want to
1952 ++ * bypass a potential IO scheduler on the target device.
1953 ++ */
1954 ++void blk_mq_request_bypass_insert(struct request *rq)
1955 ++{
1956 ++ struct blk_mq_ctx *ctx = rq->mq_ctx;
1957 ++ struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(rq->q, ctx->cpu);
1958 ++
1959 ++ spin_lock(&hctx->lock);
1960 ++ list_add_tail(&rq->queuelist, &hctx->dispatch);
1961 ++ spin_unlock(&hctx->lock);
1962 ++
1963 ++ blk_mq_run_hw_queue(hctx, false);
1964 ++}
1965 ++
1966 + void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
1967 + struct list_head *list)
1968 +
1969 +diff --git a/block/blk-mq.h b/block/blk-mq.h
1970 +index 60b01c0309bc..f64747914560 100644
1971 +--- a/block/blk-mq.h
1972 ++++ b/block/blk-mq.h
1973 +@@ -54,6 +54,7 @@ int blk_mq_alloc_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags,
1974 + */
1975 + void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
1976 + bool at_head);
1977 ++void blk_mq_request_bypass_insert(struct request *rq);
1978 + void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
1979 + struct list_head *list);
1980 +
1981 +diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
1982 +index 903605dbc1a5..76b875c69a95 100644
1983 +--- a/crypto/algif_skcipher.c
1984 ++++ b/crypto/algif_skcipher.c
1985 +@@ -144,8 +144,10 @@ static int skcipher_alloc_sgl(struct sock *sk)
1986 + sg_init_table(sgl->sg, MAX_SGL_ENTS + 1);
1987 + sgl->cur = 0;
1988 +
1989 +- if (sg)
1990 ++ if (sg) {
1991 + sg_chain(sg, MAX_SGL_ENTS + 1, sgl->sg);
1992 ++ sg_unmark_end(sg + (MAX_SGL_ENTS - 1));
1993 ++ }
1994 +
1995 + list_add_tail(&sgl->list, &ctx->tsgl);
1996 + }
1997 +diff --git a/crypto/scompress.c b/crypto/scompress.c
1998 +index ae1d3cf209e4..0b40d991d65f 100644
1999 +--- a/crypto/scompress.c
2000 ++++ b/crypto/scompress.c
2001 +@@ -211,9 +211,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
2002 + scratch_dst, &req->dlen, *ctx);
2003 + if (!ret) {
2004 + if (!req->dst) {
2005 +- req->dst = crypto_scomp_sg_alloc(req->dlen,
2006 +- req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
2007 +- GFP_KERNEL : GFP_ATOMIC);
2008 ++ req->dst = crypto_scomp_sg_alloc(req->dlen, GFP_ATOMIC);
2009 + if (!req->dst)
2010 + goto out;
2011 + }
2012 +diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
2013 +index d0368682bd43..153f20ce318b 100644
2014 +--- a/drivers/block/skd_main.c
2015 ++++ b/drivers/block/skd_main.c
2016 +@@ -2160,6 +2160,9 @@ static void skd_send_fitmsg(struct skd_device *skdev,
2017 + */
2018 + qcmd |= FIT_QCMD_MSGSIZE_64;
2019 +
2020 ++ /* Make sure skd_msg_buf is written before the doorbell is triggered. */
2021 ++ smp_wmb();
2022 ++
2023 + SKD_WRITEQ(skdev, qcmd, FIT_Q_COMMAND);
2024 + }
2025 +
2026 +@@ -2202,6 +2205,9 @@ static void skd_send_special_fitmsg(struct skd_device *skdev,
2027 + qcmd = skspcl->mb_dma_address;
2028 + qcmd |= FIT_QCMD_QID_NORMAL + FIT_QCMD_MSGSIZE_128;
2029 +
2030 ++ /* Make sure skd_msg_buf is written before the doorbell is triggered. */
2031 ++ smp_wmb();
2032 ++
2033 + SKD_WRITEQ(skdev, qcmd, FIT_Q_COMMAND);
2034 + }
2035 +
2036 +@@ -4539,15 +4545,16 @@ static void skd_free_disk(struct skd_device *skdev)
2037 + {
2038 + struct gendisk *disk = skdev->disk;
2039 +
2040 +- if (disk != NULL) {
2041 +- struct request_queue *q = disk->queue;
2042 ++ if (disk && (disk->flags & GENHD_FL_UP))
2043 ++ del_gendisk(disk);
2044 +
2045 +- if (disk->flags & GENHD_FL_UP)
2046 +- del_gendisk(disk);
2047 +- if (q)
2048 +- blk_cleanup_queue(q);
2049 +- put_disk(disk);
2050 ++ if (skdev->queue) {
2051 ++ blk_cleanup_queue(skdev->queue);
2052 ++ skdev->queue = NULL;
2053 ++ disk->queue = NULL;
2054 + }
2055 ++
2056 ++ put_disk(disk);
2057 + skdev->disk = NULL;
2058 + }
2059 +
2060 +diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg_qi.c
2061 +index 3425f2d9a2a1..fe0185ceac16 100644
2062 +--- a/drivers/crypto/caam/caamalg_qi.c
2063 ++++ b/drivers/crypto/caam/caamalg_qi.c
2064 +@@ -776,9 +776,9 @@ static void ablkcipher_done(struct caam_drv_req *drv_req, u32 status)
2065 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2066 + struct caam_ctx *caam_ctx = crypto_ablkcipher_ctx(ablkcipher);
2067 + struct device *qidev = caam_ctx->qidev;
2068 +-#ifdef DEBUG
2069 + int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
2070 +
2071 ++#ifdef DEBUG
2072 + dev_err(qidev, "%s %d: status 0x%x\n", __func__, __LINE__, status);
2073 + #endif
2074 +
2075 +@@ -799,6 +799,13 @@ static void ablkcipher_done(struct caam_drv_req *drv_req, u32 status)
2076 + ablkcipher_unmap(qidev, edesc, req);
2077 + qi_cache_free(edesc);
2078 +
2079 ++ /*
2080 ++ * The crypto API expects us to set the IV (req->info) to the last
2081 ++ * ciphertext block. This is used e.g. by the CTS mode.
2082 ++ */
2083 ++ scatterwalk_map_and_copy(req->info, req->dst, req->nbytes - ivsize,
2084 ++ ivsize, 0);
2085 ++
2086 + ablkcipher_request_complete(req, status);
2087 + }
2088 +
2089 +@@ -1968,7 +1975,7 @@ static struct caam_aead_alg driver_aeads[] = {
2090 + .cra_name = "echainiv(authenc(hmac(sha256),"
2091 + "cbc(des)))",
2092 + .cra_driver_name = "echainiv-authenc-"
2093 +- "hmac-sha256-cbc-desi-"
2094 ++ "hmac-sha256-cbc-des-"
2095 + "caam-qi",
2096 + .cra_blocksize = DES_BLOCK_SIZE,
2097 + },
2098 +diff --git a/drivers/crypto/ccp/ccp-crypto-aes-xts.c b/drivers/crypto/ccp/ccp-crypto-aes-xts.c
2099 +index 58a4244b4752..3f26a415ef44 100644
2100 +--- a/drivers/crypto/ccp/ccp-crypto-aes-xts.c
2101 ++++ b/drivers/crypto/ccp/ccp-crypto-aes-xts.c
2102 +@@ -1,8 +1,9 @@
2103 + /*
2104 + * AMD Cryptographic Coprocessor (CCP) AES XTS crypto API support
2105 + *
2106 +- * Copyright (C) 2013 Advanced Micro Devices, Inc.
2107 ++ * Copyright (C) 2013,2017 Advanced Micro Devices, Inc.
2108 + *
2109 ++ * Author: Gary R Hook <gary.hook@×××.com>
2110 + * Author: Tom Lendacky <thomas.lendacky@×××.com>
2111 + *
2112 + * This program is free software; you can redistribute it and/or modify
2113 +@@ -164,6 +165,7 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req,
2114 + memset(&rctx->cmd, 0, sizeof(rctx->cmd));
2115 + INIT_LIST_HEAD(&rctx->cmd.entry);
2116 + rctx->cmd.engine = CCP_ENGINE_XTS_AES_128;
2117 ++ rctx->cmd.u.xts.type = CCP_AES_TYPE_128;
2118 + rctx->cmd.u.xts.action = (encrypt) ? CCP_AES_ACTION_ENCRYPT
2119 + : CCP_AES_ACTION_DECRYPT;
2120 + rctx->cmd.u.xts.unit_size = unit_size;
2121 +diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
2122 +index b10d2d2075cb..9bc134a4ebf0 100644
2123 +--- a/drivers/crypto/ccp/ccp-dev-v5.c
2124 ++++ b/drivers/crypto/ccp/ccp-dev-v5.c
2125 +@@ -145,6 +145,7 @@ union ccp_function {
2126 + #define CCP_AES_MODE(p) ((p)->aes.mode)
2127 + #define CCP_AES_TYPE(p) ((p)->aes.type)
2128 + #define CCP_XTS_SIZE(p) ((p)->aes_xts.size)
2129 ++#define CCP_XTS_TYPE(p) ((p)->aes_xts.type)
2130 + #define CCP_XTS_ENCRYPT(p) ((p)->aes_xts.encrypt)
2131 + #define CCP_DES3_SIZE(p) ((p)->des3.size)
2132 + #define CCP_DES3_ENCRYPT(p) ((p)->des3.encrypt)
2133 +@@ -344,6 +345,7 @@ static int ccp5_perform_xts_aes(struct ccp_op *op)
2134 + CCP5_CMD_PROT(&desc) = 0;
2135 +
2136 + function.raw = 0;
2137 ++ CCP_XTS_TYPE(&function) = op->u.xts.type;
2138 + CCP_XTS_ENCRYPT(&function) = op->u.xts.action;
2139 + CCP_XTS_SIZE(&function) = op->u.xts.unit_size;
2140 + CCP5_CMD_FUNCTION(&desc) = function.raw;
2141 +diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
2142 +index a70154ac7405..7b8370e9c42e 100644
2143 +--- a/drivers/crypto/ccp/ccp-dev.h
2144 ++++ b/drivers/crypto/ccp/ccp-dev.h
2145 +@@ -192,6 +192,7 @@
2146 + #define CCP_AES_CTX_SB_COUNT 1
2147 +
2148 + #define CCP_XTS_AES_KEY_SB_COUNT 1
2149 ++#define CCP5_XTS_AES_KEY_SB_COUNT 2
2150 + #define CCP_XTS_AES_CTX_SB_COUNT 1
2151 +
2152 + #define CCP_DES3_KEY_SB_COUNT 1
2153 +@@ -497,6 +498,7 @@ struct ccp_aes_op {
2154 + };
2155 +
2156 + struct ccp_xts_aes_op {
2157 ++ enum ccp_aes_type type;
2158 + enum ccp_aes_action action;
2159 + enum ccp_xts_aes_unit_size unit_size;
2160 + };
2161 +diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
2162 +index c0dfdacbdff5..f3542aede519 100644
2163 +--- a/drivers/crypto/ccp/ccp-ops.c
2164 ++++ b/drivers/crypto/ccp/ccp-ops.c
2165 +@@ -1038,6 +1038,8 @@ static int ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q,
2166 + struct ccp_op op;
2167 + unsigned int unit_size, dm_offset;
2168 + bool in_place = false;
2169 ++ unsigned int sb_count;
2170 ++ enum ccp_aes_type aestype;
2171 + int ret;
2172 +
2173 + switch (xts->unit_size) {
2174 +@@ -1061,7 +1063,9 @@ static int ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q,
2175 + return -EINVAL;
2176 + }
2177 +
2178 +- if (xts->key_len != AES_KEYSIZE_128)
2179 ++ if (xts->key_len == AES_KEYSIZE_128)
2180 ++ aestype = CCP_AES_TYPE_128;
2181 ++ else
2182 + return -EINVAL;
2183 +
2184 + if (!xts->final && (xts->src_len & (AES_BLOCK_SIZE - 1)))
2185 +@@ -1083,23 +1087,44 @@ static int ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q,
2186 + op.sb_key = cmd_q->sb_key;
2187 + op.sb_ctx = cmd_q->sb_ctx;
2188 + op.init = 1;
2189 ++ op.u.xts.type = aestype;
2190 + op.u.xts.action = xts->action;
2191 + op.u.xts.unit_size = xts->unit_size;
2192 +
2193 +- /* All supported key sizes fit in a single (32-byte) SB entry
2194 +- * and must be in little endian format. Use the 256-bit byte
2195 +- * swap passthru option to convert from big endian to little
2196 +- * endian.
2197 ++ /* A version 3 device only supports 128-bit keys, which fits into a
2198 ++ * single SB entry. A version 5 device uses a 512-bit vector, so two
2199 ++ * SB entries.
2200 + */
2201 ++ if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0))
2202 ++ sb_count = CCP_XTS_AES_KEY_SB_COUNT;
2203 ++ else
2204 ++ sb_count = CCP5_XTS_AES_KEY_SB_COUNT;
2205 + ret = ccp_init_dm_workarea(&key, cmd_q,
2206 +- CCP_XTS_AES_KEY_SB_COUNT * CCP_SB_BYTES,
2207 ++ sb_count * CCP_SB_BYTES,
2208 + DMA_TO_DEVICE);
2209 + if (ret)
2210 + return ret;
2211 +
2212 +- dm_offset = CCP_SB_BYTES - AES_KEYSIZE_128;
2213 +- ccp_set_dm_area(&key, dm_offset, xts->key, 0, xts->key_len);
2214 +- ccp_set_dm_area(&key, 0, xts->key, dm_offset, xts->key_len);
2215 ++ if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0)) {
2216 ++ /* All supported key sizes must be in little endian format.
2217 ++ * Use the 256-bit byte swap passthru option to convert from
2218 ++ * big endian to little endian.
2219 ++ */
2220 ++ dm_offset = CCP_SB_BYTES - AES_KEYSIZE_128;
2221 ++ ccp_set_dm_area(&key, dm_offset, xts->key, 0, xts->key_len);
2222 ++ ccp_set_dm_area(&key, 0, xts->key, xts->key_len, xts->key_len);
2223 ++ } else {
2224 ++ /* Version 5 CCPs use a 512-bit space for the key: each portion
2225 ++ * occupies 256 bits, or one entire slot, and is zero-padded.
2226 ++ */
2227 ++ unsigned int pad;
2228 ++
2229 ++ dm_offset = CCP_SB_BYTES;
2230 ++ pad = dm_offset - xts->key_len;
2231 ++ ccp_set_dm_area(&key, pad, xts->key, 0, xts->key_len);
2232 ++ ccp_set_dm_area(&key, dm_offset + pad, xts->key, xts->key_len,
2233 ++ xts->key_len);
2234 ++ }
2235 + ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
2236 + CCP_PASSTHRU_BYTESWAP_256BIT);
2237 + if (ret) {
2238 +diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
2239 +index dea04871b50d..a1c4ee818614 100644
2240 +--- a/drivers/devfreq/devfreq.c
2241 ++++ b/drivers/devfreq/devfreq.c
2242 +@@ -564,7 +564,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
2243 + err = device_register(&devfreq->dev);
2244 + if (err) {
2245 + mutex_unlock(&devfreq->lock);
2246 +- goto err_out;
2247 ++ goto err_dev;
2248 + }
2249 +
2250 + devfreq->trans_table = devm_kzalloc(&devfreq->dev,
2251 +@@ -610,6 +610,9 @@ struct devfreq *devfreq_add_device(struct device *dev,
2252 + mutex_unlock(&devfreq_list_lock);
2253 +
2254 + device_unregister(&devfreq->dev);
2255 ++err_dev:
2256 ++ if (devfreq)
2257 ++ kfree(devfreq);
2258 + err_out:
2259 + return ERR_PTR(err);
2260 + }
2261 +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
2262 +index 4083be61b328..6417febe18b9 100644
2263 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
2264 ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
2265 +@@ -95,9 +95,8 @@ int psp_wait_for(struct psp_context *psp, uint32_t reg_index,
2266 + int i;
2267 + struct amdgpu_device *adev = psp->adev;
2268 +
2269 +- val = RREG32(reg_index);
2270 +-
2271 + for (i = 0; i < adev->usec_timeout; i++) {
2272 ++ val = RREG32(reg_index);
2273 + if (check_changed) {
2274 + if (val != reg_val)
2275 + return 0;
2276 +diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c b/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c
2277 +index c98d77d0c8f8..6f80ad8f588b 100644
2278 +--- a/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c
2279 ++++ b/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c
2280 +@@ -237,11 +237,9 @@ int psp_v3_1_bootloader_load_sos(struct psp_context *psp)
2281 +
2282 + /* there might be handshake issue with hardware which needs delay */
2283 + mdelay(20);
2284 +-#if 0
2285 + ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, mmMP0_SMN_C2PMSG_81),
2286 + RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81),
2287 + 0, true);
2288 +-#endif
2289 +
2290 + return ret;
2291 + }
2292 +diff --git a/drivers/infiniband/hw/hfi1/init.c b/drivers/infiniband/hw/hfi1/init.c
2293 +index 4a11d4da4c92..ff30b34c8984 100644
2294 +--- a/drivers/infiniband/hw/hfi1/init.c
2295 ++++ b/drivers/infiniband/hw/hfi1/init.c
2296 +@@ -483,7 +483,6 @@ void hfi1_init_pportdata(struct pci_dev *pdev, struct hfi1_pportdata *ppd,
2297 +
2298 + ppd->pkeys[default_pkey_idx] = DEFAULT_P_KEY;
2299 + ppd->part_enforce |= HFI1_PART_ENFORCE_IN;
2300 +- ppd->part_enforce |= HFI1_PART_ENFORCE_OUT;
2301 +
2302 + if (loopback) {
2303 + hfi1_early_err(&pdev->dev,
2304 +diff --git a/drivers/infiniband/hw/hfi1/rc.c b/drivers/infiniband/hw/hfi1/rc.c
2305 +index 1080778a1f7c..0c73fb0c2c1b 100644
2306 +--- a/drivers/infiniband/hw/hfi1/rc.c
2307 ++++ b/drivers/infiniband/hw/hfi1/rc.c
2308 +@@ -425,7 +425,7 @@ int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
2309 + case IB_WR_RDMA_WRITE:
2310 + if (newreq && !(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
2311 + qp->s_lsn++;
2312 +- /* FALLTHROUGH */
2313 ++ goto no_flow_control;
2314 + case IB_WR_RDMA_WRITE_WITH_IMM:
2315 + /* If no credit, return. */
2316 + if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
2317 +@@ -433,6 +433,7 @@ int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
2318 + qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
2319 + goto bail;
2320 + }
2321 ++no_flow_control:
2322 + put_ib_reth_vaddr(
2323 + wqe->rdma_wr.remote_addr,
2324 + &ohdr->u.rc.reth);
2325 +diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
2326 +index 2c40a2e989d2..a0eb2f96179a 100644
2327 +--- a/drivers/infiniband/hw/mlx5/mr.c
2328 ++++ b/drivers/infiniband/hw/mlx5/mr.c
2329 +@@ -48,6 +48,7 @@ enum {
2330 + #define MLX5_UMR_ALIGN 2048
2331 +
2332 + static int clean_mr(struct mlx5_ib_mr *mr);
2333 ++static int max_umr_order(struct mlx5_ib_dev *dev);
2334 + static int use_umr(struct mlx5_ib_dev *dev, int order);
2335 + static int unreg_umr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr);
2336 +
2337 +@@ -491,16 +492,18 @@ static struct mlx5_ib_mr *alloc_cached_mr(struct mlx5_ib_dev *dev, int order)
2338 + struct mlx5_mr_cache *cache = &dev->cache;
2339 + struct mlx5_ib_mr *mr = NULL;
2340 + struct mlx5_cache_ent *ent;
2341 ++ int last_umr_cache_entry;
2342 + int c;
2343 + int i;
2344 +
2345 + c = order2idx(dev, order);
2346 +- if (c < 0 || c > MAX_UMR_CACHE_ENTRY) {
2347 ++ last_umr_cache_entry = order2idx(dev, max_umr_order(dev));
2348 ++ if (c < 0 || c > last_umr_cache_entry) {
2349 + mlx5_ib_warn(dev, "order %d, cache index %d\n", order, c);
2350 + return NULL;
2351 + }
2352 +
2353 +- for (i = c; i < MAX_UMR_CACHE_ENTRY; i++) {
2354 ++ for (i = c; i <= last_umr_cache_entry; i++) {
2355 + ent = &cache->ent[i];
2356 +
2357 + mlx5_ib_dbg(dev, "order %d, cache index %d\n", ent->order, i);
2358 +@@ -816,11 +819,16 @@ static int get_octo_len(u64 addr, u64 len, int page_size)
2359 + return (npages + 1) / 2;
2360 + }
2361 +
2362 +-static int use_umr(struct mlx5_ib_dev *dev, int order)
2363 ++static int max_umr_order(struct mlx5_ib_dev *dev)
2364 + {
2365 + if (MLX5_CAP_GEN(dev->mdev, umr_extended_translation_offset))
2366 +- return order <= MAX_UMR_CACHE_ENTRY + 2;
2367 +- return order <= MLX5_MAX_UMR_SHIFT;
2368 ++ return MAX_UMR_CACHE_ENTRY + 2;
2369 ++ return MLX5_MAX_UMR_SHIFT;
2370 ++}
2371 ++
2372 ++static int use_umr(struct mlx5_ib_dev *dev, int order)
2373 ++{
2374 ++ return order <= max_umr_order(dev);
2375 + }
2376 +
2377 + static int mr_umem_get(struct ib_pd *pd, u64 start, u64 length,
2378 +diff --git a/drivers/infiniband/hw/qib/qib_rc.c b/drivers/infiniband/hw/qib/qib_rc.c
2379 +index 4ddbcac5eabe..e9a91736b12d 100644
2380 +--- a/drivers/infiniband/hw/qib/qib_rc.c
2381 ++++ b/drivers/infiniband/hw/qib/qib_rc.c
2382 +@@ -348,7 +348,7 @@ int qib_make_rc_req(struct rvt_qp *qp, unsigned long *flags)
2383 + case IB_WR_RDMA_WRITE:
2384 + if (newreq && !(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
2385 + qp->s_lsn++;
2386 +- /* FALLTHROUGH */
2387 ++ goto no_flow_control;
2388 + case IB_WR_RDMA_WRITE_WITH_IMM:
2389 + /* If no credit, return. */
2390 + if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
2391 +@@ -356,7 +356,7 @@ int qib_make_rc_req(struct rvt_qp *qp, unsigned long *flags)
2392 + qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
2393 + goto bail;
2394 + }
2395 +-
2396 ++no_flow_control:
2397 + ohdr->u.rc.reth.vaddr =
2398 + cpu_to_be64(wqe->rdma_wr.remote_addr);
2399 + ohdr->u.rc.reth.rkey =
2400 +diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
2401 +index ca0e19ae7a90..f6d0c8f51613 100644
2402 +--- a/drivers/input/joystick/xpad.c
2403 ++++ b/drivers/input/joystick/xpad.c
2404 +@@ -1764,10 +1764,12 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
2405 + struct usb_endpoint_descriptor *ep =
2406 + &intf->cur_altsetting->endpoint[i].desc;
2407 +
2408 +- if (usb_endpoint_dir_in(ep))
2409 +- ep_irq_in = ep;
2410 +- else
2411 +- ep_irq_out = ep;
2412 ++ if (usb_endpoint_xfer_int(ep)) {
2413 ++ if (usb_endpoint_dir_in(ep))
2414 ++ ep_irq_in = ep;
2415 ++ else
2416 ++ ep_irq_out = ep;
2417 ++ }
2418 + }
2419 +
2420 + if (!ep_irq_in || !ep_irq_out) {
2421 +diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
2422 +index f932a83b4990..9125ad017eda 100644
2423 +--- a/drivers/input/serio/i8042-x86ia64io.h
2424 ++++ b/drivers/input/serio/i8042-x86ia64io.h
2425 +@@ -839,6 +839,13 @@ static const struct dmi_system_id __initconst i8042_dmi_kbdreset_table[] = {
2426 + DMI_MATCH(DMI_PRODUCT_NAME, "P34"),
2427 + },
2428 + },
2429 ++ {
2430 ++ /* Gigabyte P57 - Elantech touchpad */
2431 ++ .matches = {
2432 ++ DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"),
2433 ++ DMI_MATCH(DMI_PRODUCT_NAME, "P57"),
2434 ++ },
2435 ++ },
2436 + {
2437 + /* Schenker XMG C504 - Elantech touchpad */
2438 + .matches = {
2439 +diff --git a/drivers/mailbox/bcm-flexrm-mailbox.c b/drivers/mailbox/bcm-flexrm-mailbox.c
2440 +index da67882caa7b..0e298ed42ae0 100644
2441 +--- a/drivers/mailbox/bcm-flexrm-mailbox.c
2442 ++++ b/drivers/mailbox/bcm-flexrm-mailbox.c
2443 +@@ -95,7 +95,7 @@
2444 +
2445 + /* Register RING_CMPL_START_ADDR fields */
2446 + #define CMPL_START_ADDR_VALUE(pa) \
2447 +- ((u32)((((u64)(pa)) >> RING_CMPL_ALIGN_ORDER) & 0x03ffffff))
2448 ++ ((u32)((((u64)(pa)) >> RING_CMPL_ALIGN_ORDER) & 0x07ffffff))
2449 +
2450 + /* Register RING_CONTROL fields */
2451 + #define CONTROL_MASK_DISABLE_CONTROL 12
2452 +diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
2453 +index dee542fff68e..2ed9bd231d84 100644
2454 +--- a/drivers/md/bcache/bcache.h
2455 ++++ b/drivers/md/bcache/bcache.h
2456 +@@ -333,6 +333,7 @@ struct cached_dev {
2457 + /* Limit number of writeback bios in flight */
2458 + struct semaphore in_flight;
2459 + struct task_struct *writeback_thread;
2460 ++ struct workqueue_struct *writeback_write_wq;
2461 +
2462 + struct keybuf writeback_keys;
2463 +
2464 +diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
2465 +index 019b3df9f1c6..4b413db99276 100644
2466 +--- a/drivers/md/bcache/request.c
2467 ++++ b/drivers/md/bcache/request.c
2468 +@@ -196,12 +196,12 @@ static void bch_data_insert_start(struct closure *cl)
2469 + struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
2470 + struct bio *bio = op->bio, *n;
2471 +
2472 +- if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0)
2473 +- wake_up_gc(op->c);
2474 +-
2475 + if (op->bypass)
2476 + return bch_data_invalidate(cl);
2477 +
2478 ++ if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0)
2479 ++ wake_up_gc(op->c);
2480 ++
2481 + /*
2482 + * Journal writes are marked REQ_PREFLUSH; if the original write was a
2483 + * flush, it'll wait on the journal write.
2484 +@@ -400,12 +400,6 @@ static bool check_should_bypass(struct cached_dev *dc, struct bio *bio)
2485 + if (!congested && !dc->sequential_cutoff)
2486 + goto rescale;
2487 +
2488 +- if (!congested &&
2489 +- mode == CACHE_MODE_WRITEBACK &&
2490 +- op_is_write(bio->bi_opf) &&
2491 +- op_is_sync(bio->bi_opf))
2492 +- goto rescale;
2493 +-
2494 + spin_lock(&dc->io_lock);
2495 +
2496 + hlist_for_each_entry(i, iohash(dc, bio->bi_iter.bi_sector), hash)
2497 +diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
2498 +index 8352fad765f6..046fc5bddf54 100644
2499 +--- a/drivers/md/bcache/super.c
2500 ++++ b/drivers/md/bcache/super.c
2501 +@@ -1026,7 +1026,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c)
2502 + }
2503 +
2504 + if (BDEV_STATE(&dc->sb) == BDEV_STATE_DIRTY) {
2505 +- bch_sectors_dirty_init(dc);
2506 ++ bch_sectors_dirty_init(&dc->disk);
2507 + atomic_set(&dc->has_dirty, 1);
2508 + atomic_inc(&dc->count);
2509 + bch_writeback_queue(dc);
2510 +@@ -1059,6 +1059,8 @@ static void cached_dev_free(struct closure *cl)
2511 + cancel_delayed_work_sync(&dc->writeback_rate_update);
2512 + if (!IS_ERR_OR_NULL(dc->writeback_thread))
2513 + kthread_stop(dc->writeback_thread);
2514 ++ if (dc->writeback_write_wq)
2515 ++ destroy_workqueue(dc->writeback_write_wq);
2516 +
2517 + mutex_lock(&bch_register_lock);
2518 +
2519 +@@ -1228,6 +1230,7 @@ static int flash_dev_run(struct cache_set *c, struct uuid_entry *u)
2520 + goto err;
2521 +
2522 + bcache_device_attach(d, c, u - c->uuids);
2523 ++ bch_sectors_dirty_init(d);
2524 + bch_flash_dev_request_init(d);
2525 + add_disk(d->disk);
2526 +
2527 +@@ -1964,6 +1967,8 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
2528 + else
2529 + err = "device busy";
2530 + mutex_unlock(&bch_register_lock);
2531 ++ if (!IS_ERR(bdev))
2532 ++ bdput(bdev);
2533 + if (attr == &ksysfs_register_quiet)
2534 + goto out;
2535 + }
2536 +diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
2537 +index f90f13616980..ab2f8ce1e3bc 100644
2538 +--- a/drivers/md/bcache/sysfs.c
2539 ++++ b/drivers/md/bcache/sysfs.c
2540 +@@ -192,7 +192,7 @@ STORE(__cached_dev)
2541 + {
2542 + struct cached_dev *dc = container_of(kobj, struct cached_dev,
2543 + disk.kobj);
2544 +- unsigned v = size;
2545 ++ ssize_t v = size;
2546 + struct cache_set *c;
2547 + struct kobj_uevent_env *env;
2548 +
2549 +@@ -227,7 +227,7 @@ STORE(__cached_dev)
2550 + bch_cached_dev_run(dc);
2551 +
2552 + if (attr == &sysfs_cache_mode) {
2553 +- ssize_t v = bch_read_string_list(buf, bch_cache_modes + 1);
2554 ++ v = bch_read_string_list(buf, bch_cache_modes + 1);
2555 +
2556 + if (v < 0)
2557 + return v;
2558 +diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c
2559 +index 8c3a938f4bf0..176d3c2ef5f5 100644
2560 +--- a/drivers/md/bcache/util.c
2561 ++++ b/drivers/md/bcache/util.c
2562 +@@ -74,24 +74,44 @@ STRTO_H(strtouint, unsigned int)
2563 + STRTO_H(strtoll, long long)
2564 + STRTO_H(strtoull, unsigned long long)
2565 +
2566 ++/**
2567 ++ * bch_hprint() - formats @v to human readable string for sysfs.
2568 ++ *
2569 ++ * @v - signed 64 bit integer
2570 ++ * @buf - the (at least 8 byte) buffer to format the result into.
2571 ++ *
2572 ++ * Returns the number of bytes used by format.
2573 ++ */
2574 + ssize_t bch_hprint(char *buf, int64_t v)
2575 + {
2576 + static const char units[] = "?kMGTPEZY";
2577 +- char dec[4] = "";
2578 +- int u, t = 0;
2579 +-
2580 +- for (u = 0; v >= 1024 || v <= -1024; u++) {
2581 +- t = v & ~(~0 << 10);
2582 +- v >>= 10;
2583 +- }
2584 +-
2585 +- if (!u)
2586 +- return sprintf(buf, "%llu", v);
2587 +-
2588 +- if (v < 100 && v > -100)
2589 +- snprintf(dec, sizeof(dec), ".%i", t / 100);
2590 +-
2591 +- return sprintf(buf, "%lli%s%c", v, dec, units[u]);
2592 ++ int u = 0, t;
2593 ++
2594 ++ uint64_t q;
2595 ++
2596 ++ if (v < 0)
2597 ++ q = -v;
2598 ++ else
2599 ++ q = v;
2600 ++
2601 ++ /* For as long as the number is more than 3 digits, but at least
2602 ++ * once, shift right / divide by 1024. Keep the remainder for
2603 ++ * a digit after the decimal point.
2604 ++ */
2605 ++ do {
2606 ++ u++;
2607 ++
2608 ++ t = q & ~(~0 << 10);
2609 ++ q >>= 10;
2610 ++ } while (q >= 1000);
2611 ++
2612 ++ if (v < 0)
2613 ++ /* '-', up to 3 digits, '.', 1 digit, 1 character, null;
2614 ++ * yields 8 bytes.
2615 ++ */
2616 ++ return sprintf(buf, "-%llu.%i%c", q, t * 10 / 1024, units[u]);
2617 ++ else
2618 ++ return sprintf(buf, "%llu.%i%c", q, t * 10 / 1024, units[u]);
2619 + }
2620 +
2621 + ssize_t bch_snprint_string_list(char *buf, size_t size, const char * const list[],
2622 +diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
2623 +index 42c66e76f05e..a635d6ac7fde 100644
2624 +--- a/drivers/md/bcache/writeback.c
2625 ++++ b/drivers/md/bcache/writeback.c
2626 +@@ -21,7 +21,8 @@
2627 + static void __update_writeback_rate(struct cached_dev *dc)
2628 + {
2629 + struct cache_set *c = dc->disk.c;
2630 +- uint64_t cache_sectors = c->nbuckets * c->sb.bucket_size;
2631 ++ uint64_t cache_sectors = c->nbuckets * c->sb.bucket_size -
2632 ++ bcache_flash_devs_sectors_dirty(c);
2633 + uint64_t cache_dirty_target =
2634 + div_u64(cache_sectors * dc->writeback_percent, 100);
2635 +
2636 +@@ -186,7 +187,7 @@ static void write_dirty(struct closure *cl)
2637 +
2638 + closure_bio_submit(&io->bio, cl);
2639 +
2640 +- continue_at(cl, write_dirty_finish, system_wq);
2641 ++ continue_at(cl, write_dirty_finish, io->dc->writeback_write_wq);
2642 + }
2643 +
2644 + static void read_dirty_endio(struct bio *bio)
2645 +@@ -206,7 +207,7 @@ static void read_dirty_submit(struct closure *cl)
2646 +
2647 + closure_bio_submit(&io->bio, cl);
2648 +
2649 +- continue_at(cl, write_dirty, system_wq);
2650 ++ continue_at(cl, write_dirty, io->dc->writeback_write_wq);
2651 + }
2652 +
2653 + static void read_dirty(struct cached_dev *dc)
2654 +@@ -482,17 +483,17 @@ static int sectors_dirty_init_fn(struct btree_op *_op, struct btree *b,
2655 + return MAP_CONTINUE;
2656 + }
2657 +
2658 +-void bch_sectors_dirty_init(struct cached_dev *dc)
2659 ++void bch_sectors_dirty_init(struct bcache_device *d)
2660 + {
2661 + struct sectors_dirty_init op;
2662 +
2663 + bch_btree_op_init(&op.op, -1);
2664 +- op.inode = dc->disk.id;
2665 ++ op.inode = d->id;
2666 +
2667 +- bch_btree_map_keys(&op.op, dc->disk.c, &KEY(op.inode, 0, 0),
2668 ++ bch_btree_map_keys(&op.op, d->c, &KEY(op.inode, 0, 0),
2669 + sectors_dirty_init_fn, 0);
2670 +
2671 +- dc->disk.sectors_dirty_last = bcache_dev_sectors_dirty(&dc->disk);
2672 ++ d->sectors_dirty_last = bcache_dev_sectors_dirty(d);
2673 + }
2674 +
2675 + void bch_cached_dev_writeback_init(struct cached_dev *dc)
2676 +@@ -516,6 +517,11 @@ void bch_cached_dev_writeback_init(struct cached_dev *dc)
2677 +
2678 + int bch_cached_dev_writeback_start(struct cached_dev *dc)
2679 + {
2680 ++ dc->writeback_write_wq = alloc_workqueue("bcache_writeback_wq",
2681 ++ WQ_MEM_RECLAIM, 0);
2682 ++ if (!dc->writeback_write_wq)
2683 ++ return -ENOMEM;
2684 ++
2685 + dc->writeback_thread = kthread_create(bch_writeback_thread, dc,
2686 + "bcache_writeback");
2687 + if (IS_ERR(dc->writeback_thread))
2688 +diff --git a/drivers/md/bcache/writeback.h b/drivers/md/bcache/writeback.h
2689 +index 629bd1a502fd..e35421d20d2e 100644
2690 +--- a/drivers/md/bcache/writeback.h
2691 ++++ b/drivers/md/bcache/writeback.h
2692 +@@ -14,6 +14,25 @@ static inline uint64_t bcache_dev_sectors_dirty(struct bcache_device *d)
2693 + return ret;
2694 + }
2695 +
2696 ++static inline uint64_t bcache_flash_devs_sectors_dirty(struct cache_set *c)
2697 ++{
2698 ++ uint64_t i, ret = 0;
2699 ++
2700 ++ mutex_lock(&bch_register_lock);
2701 ++
2702 ++ for (i = 0; i < c->nr_uuids; i++) {
2703 ++ struct bcache_device *d = c->devices[i];
2704 ++
2705 ++ if (!d || !UUID_FLASH_ONLY(&c->uuids[i]))
2706 ++ continue;
2707 ++ ret += bcache_dev_sectors_dirty(d);
2708 ++ }
2709 ++
2710 ++ mutex_unlock(&bch_register_lock);
2711 ++
2712 ++ return ret;
2713 ++}
2714 ++
2715 + static inline unsigned offset_to_stripe(struct bcache_device *d,
2716 + uint64_t offset)
2717 + {
2718 +@@ -84,7 +103,7 @@ static inline void bch_writeback_add(struct cached_dev *dc)
2719 +
2720 + void bcache_dev_sectors_dirty_add(struct cache_set *, unsigned, uint64_t, int);
2721 +
2722 +-void bch_sectors_dirty_init(struct cached_dev *dc);
2723 ++void bch_sectors_dirty_init(struct bcache_device *);
2724 + void bch_cached_dev_writeback_init(struct cached_dev *);
2725 + int bch_cached_dev_writeback_start(struct cached_dev *);
2726 +
2727 +diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
2728 +index 40f3cd7eab0f..d2121637b4ab 100644
2729 +--- a/drivers/md/bitmap.c
2730 ++++ b/drivers/md/bitmap.c
2731 +@@ -625,7 +625,7 @@ static int bitmap_read_sb(struct bitmap *bitmap)
2732 + err = read_sb_page(bitmap->mddev,
2733 + offset,
2734 + sb_page,
2735 +- 0, sizeof(bitmap_super_t));
2736 ++ 0, PAGE_SIZE);
2737 + }
2738 + if (err)
2739 + return err;
2740 +@@ -2058,6 +2058,11 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
2741 + long pages;
2742 + struct bitmap_page *new_bp;
2743 +
2744 ++ if (bitmap->storage.file && !init) {
2745 ++ pr_info("md: cannot resize file-based bitmap\n");
2746 ++ return -EINVAL;
2747 ++ }
2748 ++
2749 + if (chunksize == 0) {
2750 + /* If there is enough space, leave the chunk size unchanged,
2751 + * else increase by factor of two until there is enough space.
2752 +@@ -2118,7 +2123,7 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
2753 + if (store.sb_page && bitmap->storage.sb_page)
2754 + memcpy(page_address(store.sb_page),
2755 + page_address(bitmap->storage.sb_page),
2756 +- sizeof(bitmap_super_t));
2757 ++ PAGE_SIZE);
2758 + bitmap_file_unmap(&bitmap->storage);
2759 + bitmap->storage = store;
2760 +
2761 +diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
2762 +index 78de7ddf5081..3df28f2f9b38 100644
2763 +--- a/drivers/media/i2c/adv7180.c
2764 ++++ b/drivers/media/i2c/adv7180.c
2765 +@@ -1402,6 +1402,8 @@ static int adv7180_remove(struct i2c_client *client)
2766 +
2767 + static const struct i2c_device_id adv7180_id[] = {
2768 + { "adv7180", (kernel_ulong_t)&adv7180_info },
2769 ++ { "adv7180cp", (kernel_ulong_t)&adv7180_info },
2770 ++ { "adv7180st", (kernel_ulong_t)&adv7180_info },
2771 + { "adv7182", (kernel_ulong_t)&adv7182_info },
2772 + { "adv7280", (kernel_ulong_t)&adv7280_info },
2773 + { "adv7280-m", (kernel_ulong_t)&adv7280_m_info },
2774 +diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c
2775 +index 5f4434c0a8f1..2d6187904552 100644
2776 +--- a/drivers/media/platform/qcom/venus/helpers.c
2777 ++++ b/drivers/media/platform/qcom/venus/helpers.c
2778 +@@ -243,7 +243,7 @@ static void return_buf_error(struct venus_inst *inst,
2779 + if (vbuf->vb2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
2780 + v4l2_m2m_src_buf_remove_by_buf(m2m_ctx, vbuf);
2781 + else
2782 +- v4l2_m2m_src_buf_remove_by_buf(m2m_ctx, vbuf);
2783 ++ v4l2_m2m_dst_buf_remove_by_buf(m2m_ctx, vbuf);
2784 +
2785 + v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR);
2786 + }
2787 +diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
2788 +index db1e7b70c998..9080e39ea391 100644
2789 +--- a/drivers/media/rc/lirc_dev.c
2790 ++++ b/drivers/media/rc/lirc_dev.c
2791 +@@ -59,6 +59,8 @@ static void lirc_release(struct device *ld)
2792 + {
2793 + struct irctl *ir = container_of(ld, struct irctl, dev);
2794 +
2795 ++ put_device(ir->dev.parent);
2796 ++
2797 + if (ir->buf_internal) {
2798 + lirc_buffer_free(ir->buf);
2799 + kfree(ir->buf);
2800 +@@ -218,6 +220,8 @@ int lirc_register_driver(struct lirc_driver *d)
2801 +
2802 + mutex_unlock(&lirc_dev_lock);
2803 +
2804 ++ get_device(ir->dev.parent);
2805 ++
2806 + dev_info(ir->d.dev, "lirc_dev: driver %s registered at minor = %d\n",
2807 + ir->d.name, ir->d.minor);
2808 +
2809 +diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
2810 +index c2ee6e39fd0c..20397aba6849 100644
2811 +--- a/drivers/media/usb/uvc/uvc_ctrl.c
2812 ++++ b/drivers/media/usb/uvc/uvc_ctrl.c
2813 +@@ -2002,6 +2002,13 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
2814 + goto done;
2815 + }
2816 +
2817 ++ /* Validate the user-provided bit-size and offset */
2818 ++ if (mapping->size > 32 ||
2819 ++ mapping->offset + mapping->size > ctrl->info.size * 8) {
2820 ++ ret = -EINVAL;
2821 ++ goto done;
2822 ++ }
2823 ++
2824 + list_for_each_entry(map, &ctrl->info.mappings, list) {
2825 + if (mapping->id == map->id) {
2826 + uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', "
2827 +diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
2828 +index 6f52970f8b54..0c14e995667c 100644
2829 +--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
2830 ++++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
2831 +@@ -796,7 +796,8 @@ static int put_v4l2_event32(struct v4l2_event *kp, struct v4l2_event32 __user *u
2832 + copy_to_user(&up->u, &kp->u, sizeof(kp->u)) ||
2833 + put_user(kp->pending, &up->pending) ||
2834 + put_user(kp->sequence, &up->sequence) ||
2835 +- compat_put_timespec(&kp->timestamp, &up->timestamp) ||
2836 ++ put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
2837 ++ put_user(kp->timestamp.tv_nsec, &up->timestamp.tv_nsec) ||
2838 + put_user(kp->id, &up->id) ||
2839 + copy_to_user(up->reserved, kp->reserved, 8 * sizeof(__u32)))
2840 + return -EFAULT;
2841 +diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
2842 +index 1a138c83f877..a0c44d16bf30 100644
2843 +--- a/drivers/misc/cxl/api.c
2844 ++++ b/drivers/misc/cxl/api.c
2845 +@@ -336,6 +336,10 @@ int cxl_start_context(struct cxl_context *ctx, u64 wed,
2846 + mmput(ctx->mm);
2847 + }
2848 +
2849 ++ /*
2850 ++ * Increment driver use count. Enables global TLBIs for hash
2851 ++ * and callbacks to handle the segment table
2852 ++ */
2853 + cxl_ctx_get();
2854 +
2855 + if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) {
2856 +diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
2857 +index 0761271d68c5..4bfad9f6dc9f 100644
2858 +--- a/drivers/misc/cxl/file.c
2859 ++++ b/drivers/misc/cxl/file.c
2860 +@@ -95,7 +95,6 @@ static int __afu_open(struct inode *inode, struct file *file, bool master)
2861 +
2862 + pr_devel("afu_open pe: %i\n", ctx->pe);
2863 + file->private_data = ctx;
2864 +- cxl_ctx_get();
2865 +
2866 + /* indicate success */
2867 + rc = 0;
2868 +@@ -225,6 +224,12 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
2869 + if (ctx->mm)
2870 + mmput(ctx->mm);
2871 +
2872 ++ /*
2873 ++ * Increment driver use count. Enables global TLBIs for hash
2874 ++ * and callbacks to handle the segment table
2875 ++ */
2876 ++ cxl_ctx_get();
2877 ++
2878 + trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr);
2879 +
2880 + if ((rc = cxl_ops->attach_process(ctx, false, work.work_element_descriptor,
2881 +@@ -233,6 +238,7 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
2882 + cxl_adapter_context_put(ctx->afu->adapter);
2883 + put_pid(ctx->pid);
2884 + ctx->pid = NULL;
2885 ++ cxl_ctx_put();
2886 + cxl_context_mm_count_put(ctx);
2887 + goto out;
2888 + }
2889 +diff --git a/drivers/net/wireless/ath/wcn36xx/main.c b/drivers/net/wireless/ath/wcn36xx/main.c
2890 +index 517a315e259b..35bd50bcbbd5 100644
2891 +--- a/drivers/net/wireless/ath/wcn36xx/main.c
2892 ++++ b/drivers/net/wireless/ath/wcn36xx/main.c
2893 +@@ -372,6 +372,8 @@ static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed)
2894 +
2895 + wcn36xx_dbg(WCN36XX_DBG_MAC, "mac config changed 0x%08x\n", changed);
2896 +
2897 ++ mutex_lock(&wcn->conf_mutex);
2898 ++
2899 + if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2900 + int ch = WCN36XX_HW_CHANNEL(wcn);
2901 + wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_config channel switch=%d\n",
2902 +@@ -382,6 +384,8 @@ static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed)
2903 + }
2904 + }
2905 +
2906 ++ mutex_unlock(&wcn->conf_mutex);
2907 ++
2908 + return 0;
2909 + }
2910 +
2911 +@@ -396,6 +400,8 @@ static void wcn36xx_configure_filter(struct ieee80211_hw *hw,
2912 +
2913 + wcn36xx_dbg(WCN36XX_DBG_MAC, "mac configure filter\n");
2914 +
2915 ++ mutex_lock(&wcn->conf_mutex);
2916 ++
2917 + *total &= FIF_ALLMULTI;
2918 +
2919 + fp = (void *)(unsigned long)multicast;
2920 +@@ -408,6 +414,8 @@ static void wcn36xx_configure_filter(struct ieee80211_hw *hw,
2921 + else if (NL80211_IFTYPE_STATION == vif->type && tmp->sta_assoc)
2922 + wcn36xx_smd_set_mc_list(wcn, vif, fp);
2923 + }
2924 ++
2925 ++ mutex_unlock(&wcn->conf_mutex);
2926 + kfree(fp);
2927 + }
2928 +
2929 +@@ -471,6 +479,8 @@ static int wcn36xx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2930 + key_conf->key,
2931 + key_conf->keylen);
2932 +
2933 ++ mutex_lock(&wcn->conf_mutex);
2934 ++
2935 + switch (key_conf->cipher) {
2936 + case WLAN_CIPHER_SUITE_WEP40:
2937 + vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
2938 +@@ -565,6 +575,8 @@ static int wcn36xx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2939 + }
2940 +
2941 + out:
2942 ++ mutex_unlock(&wcn->conf_mutex);
2943 ++
2944 + return ret;
2945 + }
2946 +
2947 +@@ -725,6 +737,8 @@ static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw,
2948 + wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss info changed vif %p changed 0x%08x\n",
2949 + vif, changed);
2950 +
2951 ++ mutex_lock(&wcn->conf_mutex);
2952 ++
2953 + if (changed & BSS_CHANGED_BEACON_INFO) {
2954 + wcn36xx_dbg(WCN36XX_DBG_MAC,
2955 + "mac bss changed dtim period %d\n",
2956 +@@ -787,7 +801,13 @@ static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw,
2957 + bss_conf->aid);
2958 +
2959 + vif_priv->sta_assoc = true;
2960 +- rcu_read_lock();
2961 ++
2962 ++ /*
2963 ++ * Holding conf_mutex ensures mutal exclusion with
2964 ++ * wcn36xx_sta_remove() and as such ensures that sta
2965 ++ * won't be freed while we're operating on it. As such
2966 ++ * we do not need to hold the rcu_read_lock().
2967 ++ */
2968 + sta = ieee80211_find_sta(vif, bss_conf->bssid);
2969 + if (!sta) {
2970 + wcn36xx_err("sta %pM is not found\n",
2971 +@@ -811,7 +831,6 @@ static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw,
2972 + * place where AID is available.
2973 + */
2974 + wcn36xx_smd_config_sta(wcn, vif, sta);
2975 +- rcu_read_unlock();
2976 + } else {
2977 + wcn36xx_dbg(WCN36XX_DBG_MAC,
2978 + "disassociated bss %pM vif %pM AID=%d\n",
2979 +@@ -873,6 +892,9 @@ static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw,
2980 + }
2981 + }
2982 + out:
2983 ++
2984 ++ mutex_unlock(&wcn->conf_mutex);
2985 ++
2986 + return;
2987 + }
2988 +
2989 +@@ -882,7 +904,10 @@ static int wcn36xx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2990 + struct wcn36xx *wcn = hw->priv;
2991 + wcn36xx_dbg(WCN36XX_DBG_MAC, "mac set RTS threshold %d\n", value);
2992 +
2993 ++ mutex_lock(&wcn->conf_mutex);
2994 + wcn36xx_smd_update_cfg(wcn, WCN36XX_HAL_CFG_RTS_THRESHOLD, value);
2995 ++ mutex_unlock(&wcn->conf_mutex);
2996 ++
2997 + return 0;
2998 + }
2999 +
3000 +@@ -893,8 +918,12 @@ static void wcn36xx_remove_interface(struct ieee80211_hw *hw,
3001 + struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
3002 + wcn36xx_dbg(WCN36XX_DBG_MAC, "mac remove interface vif %p\n", vif);
3003 +
3004 ++ mutex_lock(&wcn->conf_mutex);
3005 ++
3006 + list_del(&vif_priv->list);
3007 + wcn36xx_smd_delete_sta_self(wcn, vif->addr);
3008 ++
3009 ++ mutex_unlock(&wcn->conf_mutex);
3010 + }
3011 +
3012 + static int wcn36xx_add_interface(struct ieee80211_hw *hw,
3013 +@@ -915,9 +944,13 @@ static int wcn36xx_add_interface(struct ieee80211_hw *hw,
3014 + return -EOPNOTSUPP;
3015 + }
3016 +
3017 ++ mutex_lock(&wcn->conf_mutex);
3018 ++
3019 + list_add(&vif_priv->list, &wcn->vif_list);
3020 + wcn36xx_smd_add_sta_self(wcn, vif);
3021 +
3022 ++ mutex_unlock(&wcn->conf_mutex);
3023 ++
3024 + return 0;
3025 + }
3026 +
3027 +@@ -930,6 +963,8 @@ static int wcn36xx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3028 + wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta add vif %p sta %pM\n",
3029 + vif, sta->addr);
3030 +
3031 ++ mutex_lock(&wcn->conf_mutex);
3032 ++
3033 + spin_lock_init(&sta_priv->ampdu_lock);
3034 + sta_priv->vif = vif_priv;
3035 + /*
3036 +@@ -941,6 +976,9 @@ static int wcn36xx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3037 + sta_priv->aid = sta->aid;
3038 + wcn36xx_smd_config_sta(wcn, vif, sta);
3039 + }
3040 ++
3041 ++ mutex_unlock(&wcn->conf_mutex);
3042 ++
3043 + return 0;
3044 + }
3045 +
3046 +@@ -954,8 +992,13 @@ static int wcn36xx_sta_remove(struct ieee80211_hw *hw,
3047 + wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta remove vif %p sta %pM index %d\n",
3048 + vif, sta->addr, sta_priv->sta_index);
3049 +
3050 ++ mutex_lock(&wcn->conf_mutex);
3051 ++
3052 + wcn36xx_smd_delete_sta(wcn, sta_priv->sta_index);
3053 + sta_priv->vif = NULL;
3054 ++
3055 ++ mutex_unlock(&wcn->conf_mutex);
3056 ++
3057 + return 0;
3058 + }
3059 +
3060 +@@ -999,6 +1042,8 @@ static int wcn36xx_ampdu_action(struct ieee80211_hw *hw,
3061 + wcn36xx_dbg(WCN36XX_DBG_MAC, "mac ampdu action action %d tid %d\n",
3062 + action, tid);
3063 +
3064 ++ mutex_lock(&wcn->conf_mutex);
3065 ++
3066 + switch (action) {
3067 + case IEEE80211_AMPDU_RX_START:
3068 + sta_priv->tid = tid;
3069 +@@ -1038,6 +1083,8 @@ static int wcn36xx_ampdu_action(struct ieee80211_hw *hw,
3070 + wcn36xx_err("Unknown AMPDU action\n");
3071 + }
3072 +
3073 ++ mutex_unlock(&wcn->conf_mutex);
3074 ++
3075 + return 0;
3076 + }
3077 +
3078 +@@ -1216,6 +1263,7 @@ static int wcn36xx_probe(struct platform_device *pdev)
3079 + wcn = hw->priv;
3080 + wcn->hw = hw;
3081 + wcn->dev = &pdev->dev;
3082 ++ mutex_init(&wcn->conf_mutex);
3083 + mutex_init(&wcn->hal_mutex);
3084 + mutex_init(&wcn->scan_lock);
3085 +
3086 +diff --git a/drivers/net/wireless/ath/wcn36xx/wcn36xx.h b/drivers/net/wireless/ath/wcn36xx/wcn36xx.h
3087 +index b52b4da9a967..6aefba4c0cda 100644
3088 +--- a/drivers/net/wireless/ath/wcn36xx/wcn36xx.h
3089 ++++ b/drivers/net/wireless/ath/wcn36xx/wcn36xx.h
3090 +@@ -202,6 +202,9 @@ struct wcn36xx {
3091 + struct qcom_smem_state *tx_rings_empty_state;
3092 + unsigned tx_rings_empty_state_bit;
3093 +
3094 ++ /* prevents concurrent FW reconfiguration */
3095 ++ struct mutex conf_mutex;
3096 ++
3097 + /*
3098 + * smd_buf must be protected with smd_mutex to garantee
3099 + * that all messages are sent one after another
3100 +diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
3101 +index 3ee6767392b6..d25bad052d78 100644
3102 +--- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
3103 ++++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
3104 +@@ -79,6 +79,7 @@
3105 + /* NVM offsets (in words) definitions */
3106 + enum wkp_nvm_offsets {
3107 + /* NVM HW-Section offset (in words) definitions */
3108 ++ SUBSYSTEM_ID = 0x0A,
3109 + HW_ADDR = 0x15,
3110 +
3111 + /* NVM SW-Section offset (in words) definitions */
3112 +@@ -254,13 +255,12 @@ static u32 iwl_get_channel_flags(u8 ch_num, int ch_idx, bool is_5ghz,
3113 + static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
3114 + struct iwl_nvm_data *data,
3115 + const __le16 * const nvm_ch_flags,
3116 +- bool lar_supported)
3117 ++ bool lar_supported, bool no_wide_in_5ghz)
3118 + {
3119 + int ch_idx;
3120 + int n_channels = 0;
3121 + struct ieee80211_channel *channel;
3122 + u16 ch_flags;
3123 +- bool is_5ghz;
3124 + int num_of_ch, num_2ghz_channels;
3125 + const u8 *nvm_chan;
3126 +
3127 +@@ -275,12 +275,20 @@ static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
3128 + }
3129 +
3130 + for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
3131 ++ bool is_5ghz = (ch_idx >= num_2ghz_channels);
3132 ++
3133 + ch_flags = __le16_to_cpup(nvm_ch_flags + ch_idx);
3134 +
3135 +- if (ch_idx >= num_2ghz_channels &&
3136 +- !data->sku_cap_band_52GHz_enable)
3137 ++ if (is_5ghz && !data->sku_cap_band_52GHz_enable)
3138 + continue;
3139 +
3140 ++ /* workaround to disable wide channels in 5GHz */
3141 ++ if (no_wide_in_5ghz && is_5ghz) {
3142 ++ ch_flags &= ~(NVM_CHANNEL_40MHZ |
3143 ++ NVM_CHANNEL_80MHZ |
3144 ++ NVM_CHANNEL_160MHZ);
3145 ++ }
3146 ++
3147 + if (ch_flags & NVM_CHANNEL_160MHZ)
3148 + data->vht160_supported = true;
3149 +
3150 +@@ -303,8 +311,8 @@ static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
3151 + n_channels++;
3152 +
3153 + channel->hw_value = nvm_chan[ch_idx];
3154 +- channel->band = (ch_idx < num_2ghz_channels) ?
3155 +- NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
3156 ++ channel->band = is_5ghz ?
3157 ++ NL80211_BAND_5GHZ : NL80211_BAND_2GHZ;
3158 + channel->center_freq =
3159 + ieee80211_channel_to_frequency(
3160 + channel->hw_value, channel->band);
3161 +@@ -316,7 +324,6 @@ static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
3162 + * is not used in mvm, and is used for backwards compatibility
3163 + */
3164 + channel->max_power = IWL_DEFAULT_MAX_TX_POWER;
3165 +- is_5ghz = channel->band == NL80211_BAND_5GHZ;
3166 +
3167 + /* don't put limitations in case we're using LAR */
3168 + if (!lar_supported)
3169 +@@ -432,14 +439,15 @@ static void iwl_init_vht_hw_capab(const struct iwl_cfg *cfg,
3170 +
3171 + void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg,
3172 + struct iwl_nvm_data *data, const __le16 *nvm_ch_flags,
3173 +- u8 tx_chains, u8 rx_chains, bool lar_supported)
3174 ++ u8 tx_chains, u8 rx_chains, bool lar_supported,
3175 ++ bool no_wide_in_5ghz)
3176 + {
3177 + int n_channels;
3178 + int n_used = 0;
3179 + struct ieee80211_supported_band *sband;
3180 +
3181 + n_channels = iwl_init_channel_map(dev, cfg, data, nvm_ch_flags,
3182 +- lar_supported);
3183 ++ lar_supported, no_wide_in_5ghz);
3184 + sband = &data->bands[NL80211_BAND_2GHZ];
3185 + sband->band = NL80211_BAND_2GHZ;
3186 + sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS];
3187 +@@ -645,6 +653,39 @@ static int iwl_set_hw_address(struct iwl_trans *trans,
3188 + return 0;
3189 + }
3190 +
3191 ++static bool
3192 ++iwl_nvm_no_wide_in_5ghz(struct device *dev, const struct iwl_cfg *cfg,
3193 ++ const __le16 *nvm_hw)
3194 ++{
3195 ++ /*
3196 ++ * Workaround a bug in Indonesia SKUs where the regulatory in
3197 ++ * some 7000-family OTPs erroneously allow wide channels in
3198 ++ * 5GHz. To check for Indonesia, we take the SKU value from
3199 ++ * bits 1-4 in the subsystem ID and check if it is either 5 or
3200 ++ * 9. In those cases, we need to force-disable wide channels
3201 ++ * in 5GHz otherwise the FW will throw a sysassert when we try
3202 ++ * to use them.
3203 ++ */
3204 ++ if (cfg->device_family == IWL_DEVICE_FAMILY_7000) {
3205 ++ /*
3206 ++ * Unlike the other sections in the NVM, the hw
3207 ++ * section uses big-endian.
3208 ++ */
3209 ++ u16 subsystem_id = be16_to_cpup((const __be16 *)nvm_hw
3210 ++ + SUBSYSTEM_ID);
3211 ++ u8 sku = (subsystem_id & 0x1e) >> 1;
3212 ++
3213 ++ if (sku == 5 || sku == 9) {
3214 ++ IWL_DEBUG_EEPROM(dev,
3215 ++ "disabling wide channels in 5GHz (0x%0x %d)\n",
3216 ++ subsystem_id, sku);
3217 ++ return true;
3218 ++ }
3219 ++ }
3220 ++
3221 ++ return false;
3222 ++}
3223 ++
3224 + struct iwl_nvm_data *
3225 + iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
3226 + const __le16 *nvm_hw, const __le16 *nvm_sw,
3227 +@@ -655,6 +696,7 @@ iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
3228 + struct device *dev = trans->dev;
3229 + struct iwl_nvm_data *data;
3230 + bool lar_enabled;
3231 ++ bool no_wide_in_5ghz = iwl_nvm_no_wide_in_5ghz(dev, cfg, nvm_hw);
3232 + u32 sku, radio_cfg;
3233 + u16 lar_config;
3234 + const __le16 *ch_section;
3235 +@@ -725,7 +767,7 @@ iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
3236 + }
3237 +
3238 + iwl_init_sbands(dev, cfg, data, ch_section, tx_chains, rx_chains,
3239 +- lar_fw_supported && lar_enabled);
3240 ++ lar_fw_supported && lar_enabled, no_wide_in_5ghz);
3241 + data->calib_version = 255;
3242 +
3243 + return data;
3244 +diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h
3245 +index 3fd6506a02ab..50d9b3eaa4f8 100644
3246 +--- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h
3247 ++++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h
3248 +@@ -93,7 +93,8 @@ void iwl_set_hw_address_from_csr(struct iwl_trans *trans,
3249 + */
3250 + void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg,
3251 + struct iwl_nvm_data *data, const __le16 *nvm_ch_flags,
3252 +- u8 tx_chains, u8 rx_chains, bool lar_supported);
3253 ++ u8 tx_chains, u8 rx_chains, bool lar_supported,
3254 ++ bool no_wide_in_5ghz);
3255 +
3256 + /**
3257 + * iwl_parse_mcc_info - parse MCC (mobile country code) info coming from FW
3258 +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c b/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c
3259 +index dac7e542a190..4de565cec747 100644
3260 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c
3261 ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c
3262 +@@ -628,7 +628,8 @@ int iwl_mvm_nvm_get_from_fw(struct iwl_mvm *mvm)
3263 + rsp->regulatory.channel_profile,
3264 + mvm->nvm_data->valid_tx_ant & mvm->fw->valid_tx_ant,
3265 + mvm->nvm_data->valid_rx_ant & mvm->fw->valid_rx_ant,
3266 +- rsp->regulatory.lar_enabled && lar_fw_supported);
3267 ++ rsp->regulatory.lar_enabled && lar_fw_supported,
3268 ++ false);
3269 +
3270 + iwl_free_resp(&hcmd);
3271 + return 0;
3272 +diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
3273 +index 026830a138ae..e5d5ce9e3010 100644
3274 +--- a/drivers/pci/hotplug/pciehp_hpc.c
3275 ++++ b/drivers/pci/hotplug/pciehp_hpc.c
3276 +@@ -586,6 +586,14 @@ static irqreturn_t pciehp_isr(int irq, void *dev_id)
3277 + events = status & (PCI_EXP_SLTSTA_ABP | PCI_EXP_SLTSTA_PFD |
3278 + PCI_EXP_SLTSTA_PDC | PCI_EXP_SLTSTA_CC |
3279 + PCI_EXP_SLTSTA_DLLSC);
3280 ++
3281 ++ /*
3282 ++ * If we've already reported a power fault, don't report it again
3283 ++ * until we've done something to handle it.
3284 ++ */
3285 ++ if (ctrl->power_fault_detected)
3286 ++ events &= ~PCI_EXP_SLTSTA_PFD;
3287 ++
3288 + if (!events)
3289 + return IRQ_NONE;
3290 +
3291 +diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c
3292 +index de0ea474fb73..e5824c7b7b6b 100644
3293 +--- a/drivers/pci/hotplug/shpchp_hpc.c
3294 ++++ b/drivers/pci/hotplug/shpchp_hpc.c
3295 +@@ -1062,6 +1062,8 @@ int shpc_init(struct controller *ctrl, struct pci_dev *pdev)
3296 + if (rc) {
3297 + ctrl_info(ctrl, "Can't get msi for the hotplug controller\n");
3298 + ctrl_info(ctrl, "Use INTx for the hotplug controller\n");
3299 ++ } else {
3300 ++ pci_set_master(pdev);
3301 + }
3302 +
3303 + rc = request_irq(ctrl->pci_dev->irq, shpc_isr, IRQF_SHARED,
3304 +diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
3305 +index e6779d4352a2..7c30fd986560 100644
3306 +--- a/drivers/pinctrl/pinctrl-amd.c
3307 ++++ b/drivers/pinctrl/pinctrl-amd.c
3308 +@@ -36,6 +36,7 @@
3309 + #include <linux/pinctrl/pinconf.h>
3310 + #include <linux/pinctrl/pinconf-generic.h>
3311 +
3312 ++#include "core.h"
3313 + #include "pinctrl-utils.h"
3314 + #include "pinctrl-amd.h"
3315 +
3316 +@@ -725,6 +726,69 @@ static const struct pinconf_ops amd_pinconf_ops = {
3317 + .pin_config_group_set = amd_pinconf_group_set,
3318 + };
3319 +
3320 ++#ifdef CONFIG_PM_SLEEP
3321 ++static bool amd_gpio_should_save(struct amd_gpio *gpio_dev, unsigned int pin)
3322 ++{
3323 ++ const struct pin_desc *pd = pin_desc_get(gpio_dev->pctrl, pin);
3324 ++
3325 ++ if (!pd)
3326 ++ return false;
3327 ++
3328 ++ /*
3329 ++ * Only restore the pin if it is actually in use by the kernel (or
3330 ++ * by userspace).
3331 ++ */
3332 ++ if (pd->mux_owner || pd->gpio_owner ||
3333 ++ gpiochip_line_is_irq(&gpio_dev->gc, pin))
3334 ++ return true;
3335 ++
3336 ++ return false;
3337 ++}
3338 ++
3339 ++int amd_gpio_suspend(struct device *dev)
3340 ++{
3341 ++ struct platform_device *pdev = to_platform_device(dev);
3342 ++ struct amd_gpio *gpio_dev = platform_get_drvdata(pdev);
3343 ++ struct pinctrl_desc *desc = gpio_dev->pctrl->desc;
3344 ++ int i;
3345 ++
3346 ++ for (i = 0; i < desc->npins; i++) {
3347 ++ int pin = desc->pins[i].number;
3348 ++
3349 ++ if (!amd_gpio_should_save(gpio_dev, pin))
3350 ++ continue;
3351 ++
3352 ++ gpio_dev->saved_regs[i] = readl(gpio_dev->base + pin*4);
3353 ++ }
3354 ++
3355 ++ return 0;
3356 ++}
3357 ++
3358 ++int amd_gpio_resume(struct device *dev)
3359 ++{
3360 ++ struct platform_device *pdev = to_platform_device(dev);
3361 ++ struct amd_gpio *gpio_dev = platform_get_drvdata(pdev);
3362 ++ struct pinctrl_desc *desc = gpio_dev->pctrl->desc;
3363 ++ int i;
3364 ++
3365 ++ for (i = 0; i < desc->npins; i++) {
3366 ++ int pin = desc->pins[i].number;
3367 ++
3368 ++ if (!amd_gpio_should_save(gpio_dev, pin))
3369 ++ continue;
3370 ++
3371 ++ writel(gpio_dev->saved_regs[i], gpio_dev->base + pin*4);
3372 ++ }
3373 ++
3374 ++ return 0;
3375 ++}
3376 ++
3377 ++static const struct dev_pm_ops amd_gpio_pm_ops = {
3378 ++ SET_LATE_SYSTEM_SLEEP_PM_OPS(amd_gpio_suspend,
3379 ++ amd_gpio_resume)
3380 ++};
3381 ++#endif
3382 ++
3383 + static struct pinctrl_desc amd_pinctrl_desc = {
3384 + .pins = kerncz_pins,
3385 + .npins = ARRAY_SIZE(kerncz_pins),
3386 +@@ -764,6 +828,14 @@ static int amd_gpio_probe(struct platform_device *pdev)
3387 + return -EINVAL;
3388 + }
3389 +
3390 ++#ifdef CONFIG_PM_SLEEP
3391 ++ gpio_dev->saved_regs = devm_kcalloc(&pdev->dev, amd_pinctrl_desc.npins,
3392 ++ sizeof(*gpio_dev->saved_regs),
3393 ++ GFP_KERNEL);
3394 ++ if (!gpio_dev->saved_regs)
3395 ++ return -ENOMEM;
3396 ++#endif
3397 ++
3398 + gpio_dev->pdev = pdev;
3399 + gpio_dev->gc.direction_input = amd_gpio_direction_input;
3400 + gpio_dev->gc.direction_output = amd_gpio_direction_output;
3401 +@@ -853,6 +925,9 @@ static struct platform_driver amd_gpio_driver = {
3402 + .driver = {
3403 + .name = "amd_gpio",
3404 + .acpi_match_table = ACPI_PTR(amd_gpio_acpi_match),
3405 ++#ifdef CONFIG_PM_SLEEP
3406 ++ .pm = &amd_gpio_pm_ops,
3407 ++#endif
3408 + },
3409 + .probe = amd_gpio_probe,
3410 + .remove = amd_gpio_remove,
3411 +diff --git a/drivers/pinctrl/pinctrl-amd.h b/drivers/pinctrl/pinctrl-amd.h
3412 +index 5b1cb965c767..8fa453a59da5 100644
3413 +--- a/drivers/pinctrl/pinctrl-amd.h
3414 ++++ b/drivers/pinctrl/pinctrl-amd.h
3415 +@@ -97,6 +97,7 @@ struct amd_gpio {
3416 + unsigned int hwbank_num;
3417 + struct resource *res;
3418 + struct platform_device *pdev;
3419 ++ u32 *saved_regs;
3420 + };
3421 +
3422 + /* KERNCZ configuration*/
3423 +diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.c b/drivers/pinctrl/samsung/pinctrl-exynos.c
3424 +index 731530a9ce38..9ab8faf528a6 100644
3425 +--- a/drivers/pinctrl/samsung/pinctrl-exynos.c
3426 ++++ b/drivers/pinctrl/samsung/pinctrl-exynos.c
3427 +@@ -174,10 +174,10 @@ static int exynos_irq_request_resources(struct irq_data *irqd)
3428 +
3429 + spin_lock_irqsave(&bank->slock, flags);
3430 +
3431 +- con = readl(bank->eint_base + reg_con);
3432 ++ con = readl(bank->pctl_base + reg_con);
3433 + con &= ~(mask << shift);
3434 + con |= EXYNOS_EINT_FUNC << shift;
3435 +- writel(con, bank->eint_base + reg_con);
3436 ++ writel(con, bank->pctl_base + reg_con);
3437 +
3438 + spin_unlock_irqrestore(&bank->slock, flags);
3439 +
3440 +@@ -202,10 +202,10 @@ static void exynos_irq_release_resources(struct irq_data *irqd)
3441 +
3442 + spin_lock_irqsave(&bank->slock, flags);
3443 +
3444 +- con = readl(bank->eint_base + reg_con);
3445 ++ con = readl(bank->pctl_base + reg_con);
3446 + con &= ~(mask << shift);
3447 + con |= FUNC_INPUT << shift;
3448 +- writel(con, bank->eint_base + reg_con);
3449 ++ writel(con, bank->pctl_base + reg_con);
3450 +
3451 + spin_unlock_irqrestore(&bank->slock, flags);
3452 +
3453 +diff --git a/drivers/pinctrl/samsung/pinctrl-s3c24xx.c b/drivers/pinctrl/samsung/pinctrl-s3c24xx.c
3454 +index 49774851e84a..edf27264b603 100644
3455 +--- a/drivers/pinctrl/samsung/pinctrl-s3c24xx.c
3456 ++++ b/drivers/pinctrl/samsung/pinctrl-s3c24xx.c
3457 +@@ -151,7 +151,7 @@ static void s3c24xx_eint_set_function(struct samsung_pinctrl_drv_data *d,
3458 + u32 val;
3459 +
3460 + /* Make sure that pin is configured as interrupt */
3461 +- reg = bank->pctl_base + bank->pctl_offset;
3462 ++ reg = d->virt_base + bank->pctl_offset;
3463 + shift = pin * bank_type->fld_width[PINCFG_TYPE_FUNC];
3464 + mask = (1 << bank_type->fld_width[PINCFG_TYPE_FUNC]) - 1;
3465 +
3466 +@@ -184,7 +184,7 @@ static int s3c24xx_eint_type(struct irq_data *data, unsigned int type)
3467 + s3c24xx_eint_set_handler(data, type);
3468 +
3469 + /* Set up interrupt trigger */
3470 +- reg = bank->eint_base + EINT_REG(index);
3471 ++ reg = d->virt_base + EINT_REG(index);
3472 + shift = EINT_OFFS(index);
3473 +
3474 + val = readl(reg);
3475 +@@ -259,29 +259,32 @@ static void s3c2410_demux_eint0_3(struct irq_desc *desc)
3476 + static void s3c2412_eint0_3_ack(struct irq_data *data)
3477 + {
3478 + struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data);
3479 ++ struct samsung_pinctrl_drv_data *d = bank->drvdata;
3480 +
3481 + unsigned long bitval = 1UL << data->hwirq;
3482 +- writel(bitval, bank->eint_base + EINTPEND_REG);
3483 ++ writel(bitval, d->virt_base + EINTPEND_REG);
3484 + }
3485 +
3486 + static void s3c2412_eint0_3_mask(struct irq_data *data)
3487 + {
3488 + struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data);
3489 ++ struct samsung_pinctrl_drv_data *d = bank->drvdata;
3490 + unsigned long mask;
3491 +
3492 +- mask = readl(bank->eint_base + EINTMASK_REG);
3493 ++ mask = readl(d->virt_base + EINTMASK_REG);
3494 + mask |= (1UL << data->hwirq);
3495 +- writel(mask, bank->eint_base + EINTMASK_REG);
3496 ++ writel(mask, d->virt_base + EINTMASK_REG);
3497 + }
3498 +
3499 + static void s3c2412_eint0_3_unmask(struct irq_data *data)
3500 + {
3501 + struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data);
3502 ++ struct samsung_pinctrl_drv_data *d = bank->drvdata;
3503 + unsigned long mask;
3504 +
3505 +- mask = readl(bank->eint_base + EINTMASK_REG);
3506 ++ mask = readl(d->virt_base + EINTMASK_REG);
3507 + mask &= ~(1UL << data->hwirq);
3508 +- writel(mask, bank->eint_base + EINTMASK_REG);
3509 ++ writel(mask, d->virt_base + EINTMASK_REG);
3510 + }
3511 +
3512 + static struct irq_chip s3c2412_eint0_3_chip = {
3513 +@@ -316,31 +319,34 @@ static void s3c2412_demux_eint0_3(struct irq_desc *desc)
3514 + static void s3c24xx_eint_ack(struct irq_data *data)
3515 + {
3516 + struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data);
3517 ++ struct samsung_pinctrl_drv_data *d = bank->drvdata;
3518 + unsigned char index = bank->eint_offset + data->hwirq;
3519 +
3520 +- writel(1UL << index, bank->eint_base + EINTPEND_REG);
3521 ++ writel(1UL << index, d->virt_base + EINTPEND_REG);
3522 + }
3523 +
3524 + static void s3c24xx_eint_mask(struct irq_data *data)
3525 + {
3526 + struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data);
3527 ++ struct samsung_pinctrl_drv_data *d = bank->drvdata;
3528 + unsigned char index = bank->eint_offset + data->hwirq;
3529 + unsigned long mask;
3530 +
3531 +- mask = readl(bank->eint_base + EINTMASK_REG);
3532 ++ mask = readl(d->virt_base + EINTMASK_REG);
3533 + mask |= (1UL << index);
3534 +- writel(mask, bank->eint_base + EINTMASK_REG);
3535 ++ writel(mask, d->virt_base + EINTMASK_REG);
3536 + }
3537 +
3538 + static void s3c24xx_eint_unmask(struct irq_data *data)
3539 + {
3540 + struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data);
3541 ++ struct samsung_pinctrl_drv_data *d = bank->drvdata;
3542 + unsigned char index = bank->eint_offset + data->hwirq;
3543 + unsigned long mask;
3544 +
3545 +- mask = readl(bank->eint_base + EINTMASK_REG);
3546 ++ mask = readl(d->virt_base + EINTMASK_REG);
3547 + mask &= ~(1UL << index);
3548 +- writel(mask, bank->eint_base + EINTMASK_REG);
3549 ++ writel(mask, d->virt_base + EINTMASK_REG);
3550 + }
3551 +
3552 + static struct irq_chip s3c24xx_eint_chip = {
3553 +@@ -356,14 +362,13 @@ static inline void s3c24xx_demux_eint(struct irq_desc *desc,
3554 + {
3555 + struct s3c24xx_eint_data *data = irq_desc_get_handler_data(desc);
3556 + struct irq_chip *chip = irq_desc_get_chip(desc);
3557 +- struct irq_data *irqd = irq_desc_get_irq_data(desc);
3558 +- struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
3559 ++ struct samsung_pinctrl_drv_data *d = data->drvdata;
3560 + unsigned int pend, mask;
3561 +
3562 + chained_irq_enter(chip, desc);
3563 +
3564 +- pend = readl(bank->eint_base + EINTPEND_REG);
3565 +- mask = readl(bank->eint_base + EINTMASK_REG);
3566 ++ pend = readl(d->virt_base + EINTPEND_REG);
3567 ++ mask = readl(d->virt_base + EINTMASK_REG);
3568 +
3569 + pend &= ~mask;
3570 + pend &= range;
3571 +diff --git a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
3572 +index 4a88d7446e87..e63663b32907 100644
3573 +--- a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
3574 ++++ b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c
3575 +@@ -280,7 +280,7 @@ static void s3c64xx_irq_set_function(struct samsung_pinctrl_drv_data *d,
3576 + u32 val;
3577 +
3578 + /* Make sure that pin is configured as interrupt */
3579 +- reg = bank->pctl_base + bank->pctl_offset;
3580 ++ reg = d->virt_base + bank->pctl_offset;
3581 + shift = pin;
3582 + if (bank_type->fld_width[PINCFG_TYPE_FUNC] * shift >= 32) {
3583 + /* 4-bit bank type with 2 con regs */
3584 +@@ -308,8 +308,9 @@ static void s3c64xx_irq_set_function(struct samsung_pinctrl_drv_data *d,
3585 + static inline void s3c64xx_gpio_irq_set_mask(struct irq_data *irqd, bool mask)
3586 + {
3587 + struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
3588 ++ struct samsung_pinctrl_drv_data *d = bank->drvdata;
3589 + unsigned char index = EINT_OFFS(bank->eint_offset) + irqd->hwirq;
3590 +- void __iomem *reg = bank->eint_base + EINTMASK_REG(bank->eint_offset);
3591 ++ void __iomem *reg = d->virt_base + EINTMASK_REG(bank->eint_offset);
3592 + u32 val;
3593 +
3594 + val = readl(reg);
3595 +@@ -333,8 +334,9 @@ static void s3c64xx_gpio_irq_mask(struct irq_data *irqd)
3596 + static void s3c64xx_gpio_irq_ack(struct irq_data *irqd)
3597 + {
3598 + struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
3599 ++ struct samsung_pinctrl_drv_data *d = bank->drvdata;
3600 + unsigned char index = EINT_OFFS(bank->eint_offset) + irqd->hwirq;
3601 +- void __iomem *reg = bank->eint_base + EINTPEND_REG(bank->eint_offset);
3602 ++ void __iomem *reg = d->virt_base + EINTPEND_REG(bank->eint_offset);
3603 +
3604 + writel(1 << index, reg);
3605 + }
3606 +@@ -357,7 +359,7 @@ static int s3c64xx_gpio_irq_set_type(struct irq_data *irqd, unsigned int type)
3607 + s3c64xx_irq_set_handler(irqd, type);
3608 +
3609 + /* Set up interrupt trigger */
3610 +- reg = bank->eint_base + EINTCON_REG(bank->eint_offset);
3611 ++ reg = d->virt_base + EINTCON_REG(bank->eint_offset);
3612 + shift = EINT_OFFS(bank->eint_offset) + irqd->hwirq;
3613 + shift = 4 * (shift / 4); /* 4 EINTs per trigger selector */
3614 +
3615 +@@ -409,8 +411,7 @@ static void s3c64xx_eint_gpio_irq(struct irq_desc *desc)
3616 + {
3617 + struct irq_chip *chip = irq_desc_get_chip(desc);
3618 + struct s3c64xx_eint_gpio_data *data = irq_desc_get_handler_data(desc);
3619 +- struct irq_data *irqd = irq_desc_get_irq_data(desc);
3620 +- struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
3621 ++ struct samsung_pinctrl_drv_data *drvdata = data->drvdata;
3622 +
3623 + chained_irq_enter(chip, desc);
3624 +
3625 +@@ -420,7 +421,7 @@ static void s3c64xx_eint_gpio_irq(struct irq_desc *desc)
3626 + unsigned int pin;
3627 + unsigned int virq;
3628 +
3629 +- svc = readl(bank->eint_base + SERVICE_REG);
3630 ++ svc = readl(drvdata->virt_base + SERVICE_REG);
3631 + group = SVC_GROUP(svc);
3632 + pin = svc & SVC_NUM_MASK;
3633 +
3634 +@@ -515,15 +516,15 @@ static inline void s3c64xx_eint0_irq_set_mask(struct irq_data *irqd, bool mask)
3635 + {
3636 + struct s3c64xx_eint0_domain_data *ddata =
3637 + irq_data_get_irq_chip_data(irqd);
3638 +- struct samsung_pin_bank *bank = ddata->bank;
3639 ++ struct samsung_pinctrl_drv_data *d = ddata->bank->drvdata;
3640 + u32 val;
3641 +
3642 +- val = readl(bank->eint_base + EINT0MASK_REG);
3643 ++ val = readl(d->virt_base + EINT0MASK_REG);
3644 + if (mask)
3645 + val |= 1 << ddata->eints[irqd->hwirq];
3646 + else
3647 + val &= ~(1 << ddata->eints[irqd->hwirq]);
3648 +- writel(val, bank->eint_base + EINT0MASK_REG);
3649 ++ writel(val, d->virt_base + EINT0MASK_REG);
3650 + }
3651 +
3652 + static void s3c64xx_eint0_irq_unmask(struct irq_data *irqd)
3653 +@@ -540,10 +541,10 @@ static void s3c64xx_eint0_irq_ack(struct irq_data *irqd)
3654 + {
3655 + struct s3c64xx_eint0_domain_data *ddata =
3656 + irq_data_get_irq_chip_data(irqd);
3657 +- struct samsung_pin_bank *bank = ddata->bank;
3658 ++ struct samsung_pinctrl_drv_data *d = ddata->bank->drvdata;
3659 +
3660 + writel(1 << ddata->eints[irqd->hwirq],
3661 +- bank->eint_base + EINT0PEND_REG);
3662 ++ d->virt_base + EINT0PEND_REG);
3663 + }
3664 +
3665 + static int s3c64xx_eint0_irq_set_type(struct irq_data *irqd, unsigned int type)
3666 +@@ -551,7 +552,7 @@ static int s3c64xx_eint0_irq_set_type(struct irq_data *irqd, unsigned int type)
3667 + struct s3c64xx_eint0_domain_data *ddata =
3668 + irq_data_get_irq_chip_data(irqd);
3669 + struct samsung_pin_bank *bank = ddata->bank;
3670 +- struct samsung_pinctrl_drv_data *d = ddata->bank->drvdata;
3671 ++ struct samsung_pinctrl_drv_data *d = bank->drvdata;
3672 + void __iomem *reg;
3673 + int trigger;
3674 + u8 shift;
3675 +@@ -566,7 +567,7 @@ static int s3c64xx_eint0_irq_set_type(struct irq_data *irqd, unsigned int type)
3676 + s3c64xx_irq_set_handler(irqd, type);
3677 +
3678 + /* Set up interrupt trigger */
3679 +- reg = bank->eint_base + EINT0CON0_REG;
3680 ++ reg = d->virt_base + EINT0CON0_REG;
3681 + shift = ddata->eints[irqd->hwirq];
3682 + if (shift >= EINT_MAX_PER_REG) {
3683 + reg += 4;
3684 +@@ -598,19 +599,14 @@ static struct irq_chip s3c64xx_eint0_irq_chip = {
3685 + static inline void s3c64xx_irq_demux_eint(struct irq_desc *desc, u32 range)
3686 + {
3687 + struct irq_chip *chip = irq_desc_get_chip(desc);
3688 +- struct irq_data *irqd = irq_desc_get_irq_data(desc);
3689 +- struct s3c64xx_eint0_domain_data *ddata =
3690 +- irq_data_get_irq_chip_data(irqd);
3691 +- struct samsung_pin_bank *bank = ddata->bank;
3692 +-
3693 + struct s3c64xx_eint0_data *data = irq_desc_get_handler_data(desc);
3694 +-
3695 ++ struct samsung_pinctrl_drv_data *drvdata = data->drvdata;
3696 + unsigned int pend, mask;
3697 +
3698 + chained_irq_enter(chip, desc);
3699 +
3700 +- pend = readl(bank->eint_base + EINT0PEND_REG);
3701 +- mask = readl(bank->eint_base + EINT0MASK_REG);
3702 ++ pend = readl(drvdata->virt_base + EINT0PEND_REG);
3703 ++ mask = readl(drvdata->virt_base + EINT0MASK_REG);
3704 +
3705 + pend = pend & range & ~mask;
3706 + pend &= range;
3707 +diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
3708 +index f542642eed8d..61bbd54e35ba 100644
3709 +--- a/drivers/pinctrl/samsung/pinctrl-samsung.c
3710 ++++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
3711 +@@ -1013,6 +1013,12 @@ samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
3712 + bank->eint_base = virt_base[0];
3713 + bank->pctl_base = virt_base[bdata->pctl_res_idx];
3714 + }
3715 ++ /*
3716 ++ * Legacy platforms should provide only one resource with IO memory.
3717 ++ * Store it as virt_base because legacy driver needs to access it
3718 ++ * through samsung_pinctrl_drv_data.
3719 ++ */
3720 ++ d->virt_base = virt_base[0];
3721 +
3722 + for_each_child_of_node(node, np) {
3723 + if (!of_find_property(np, "gpio-controller", NULL))
3724 +diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.h b/drivers/pinctrl/samsung/pinctrl-samsung.h
3725 +index 515a61035e54..61c4cab0ad24 100644
3726 +--- a/drivers/pinctrl/samsung/pinctrl-samsung.h
3727 ++++ b/drivers/pinctrl/samsung/pinctrl-samsung.h
3728 +@@ -247,6 +247,10 @@ struct samsung_pin_ctrl {
3729 + /**
3730 + * struct samsung_pinctrl_drv_data: wrapper for holding driver data together.
3731 + * @node: global list node
3732 ++ * @virt_base: register base address of the controller; this will be equal
3733 ++ * to each bank samsung_pin_bank->pctl_base and used on legacy
3734 ++ * platforms (like S3C24XX or S3C64XX) which has to access the base
3735 ++ * through samsung_pinctrl_drv_data, not samsung_pin_bank).
3736 + * @dev: device instance representing the controller.
3737 + * @irq: interrpt number used by the controller to notify gpio interrupts.
3738 + * @ctrl: pin controller instance managed by the driver.
3739 +@@ -262,6 +266,7 @@ struct samsung_pin_ctrl {
3740 + */
3741 + struct samsung_pinctrl_drv_data {
3742 + struct list_head node;
3743 ++ void __iomem *virt_base;
3744 + struct device *dev;
3745 + int irq;
3746 +
3747 +diff --git a/drivers/regulator/cpcap-regulator.c b/drivers/regulator/cpcap-regulator.c
3748 +index cc98aceed1c1..ce1cab320f6f 100644
3749 +--- a/drivers/regulator/cpcap-regulator.c
3750 ++++ b/drivers/regulator/cpcap-regulator.c
3751 +@@ -77,6 +77,8 @@
3752 + #define CPCAP_BIT_VAUDIO_MODE0 BIT(1)
3753 + #define CPCAP_BIT_V_AUDIO_EN BIT(0)
3754 +
3755 ++#define CPCAP_BIT_AUDIO_NORMAL_MODE 0x00
3756 ++
3757 + /*
3758 + * Off mode configuration bit. Used currently only by SW5 on omap4. There's
3759 + * the following comment in Motorola Linux kernel tree for it:
3760 +@@ -217,7 +219,7 @@ static unsigned int cpcap_regulator_get_mode(struct regulator_dev *rdev)
3761 +
3762 + regmap_read(rdev->regmap, rdev->desc->enable_reg, &value);
3763 +
3764 +- if (!(value & CPCAP_BIT_AUDIO_LOW_PWR))
3765 ++ if (value & CPCAP_BIT_AUDIO_LOW_PWR)
3766 + return REGULATOR_MODE_STANDBY;
3767 +
3768 + return REGULATOR_MODE_NORMAL;
3769 +@@ -230,10 +232,10 @@ static int cpcap_regulator_set_mode(struct regulator_dev *rdev,
3770 +
3771 + switch (mode) {
3772 + case REGULATOR_MODE_NORMAL:
3773 +- value = CPCAP_BIT_AUDIO_LOW_PWR;
3774 ++ value = CPCAP_BIT_AUDIO_NORMAL_MODE;
3775 + break;
3776 + case REGULATOR_MODE_STANDBY:
3777 +- value = 0;
3778 ++ value = CPCAP_BIT_AUDIO_LOW_PWR;
3779 + break;
3780 + default:
3781 + return -EINVAL;
3782 +diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c
3783 +index d5bf36ec8a75..34367d172961 100644
3784 +--- a/drivers/s390/scsi/zfcp_dbf.c
3785 ++++ b/drivers/s390/scsi/zfcp_dbf.c
3786 +@@ -3,7 +3,7 @@
3787 + *
3788 + * Debug traces for zfcp.
3789 + *
3790 +- * Copyright IBM Corp. 2002, 2016
3791 ++ * Copyright IBM Corp. 2002, 2017
3792 + */
3793 +
3794 + #define KMSG_COMPONENT "zfcp"
3795 +@@ -447,6 +447,7 @@ static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag,
3796 + struct fc_ct_hdr *reqh = sg_virt(ct_els->req);
3797 + struct fc_ns_gid_ft *reqn = (struct fc_ns_gid_ft *)(reqh + 1);
3798 + struct scatterlist *resp_entry = ct_els->resp;
3799 ++ struct fc_ct_hdr *resph;
3800 + struct fc_gpn_ft_resp *acc;
3801 + int max_entries, x, last = 0;
3802 +
3803 +@@ -473,6 +474,13 @@ static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag,
3804 + return len; /* not GPN_FT response so do not cap */
3805 +
3806 + acc = sg_virt(resp_entry);
3807 ++
3808 ++ /* cap all but accept CT responses to at least the CT header */
3809 ++ resph = (struct fc_ct_hdr *)acc;
3810 ++ if ((ct_els->status) ||
3811 ++ (resph->ct_cmd != cpu_to_be16(FC_FS_ACC)))
3812 ++ return max(FC_CT_HDR_LEN, ZFCP_DBF_SAN_MAX_PAYLOAD);
3813 ++
3814 + max_entries = (reqh->ct_mr_size * 4 / sizeof(struct fc_gpn_ft_resp))
3815 + + 1 /* zfcp_fc_scan_ports: bytes correct, entries off-by-one
3816 + * to account for header as 1st pseudo "entry" */;
3817 +@@ -555,8 +563,8 @@ void zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *sc,
3818 + rec->scsi_retries = sc->retries;
3819 + rec->scsi_allowed = sc->allowed;
3820 + rec->scsi_id = sc->device->id;
3821 +- /* struct zfcp_dbf_scsi needs to be updated to handle 64bit LUNs */
3822 + rec->scsi_lun = (u32)sc->device->lun;
3823 ++ rec->scsi_lun_64_hi = (u32)(sc->device->lun >> 32);
3824 + rec->host_scribble = (unsigned long)sc->host_scribble;
3825 +
3826 + memcpy(rec->scsi_opcode, sc->cmnd,
3827 +@@ -564,19 +572,32 @@ void zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *sc,
3828 +
3829 + if (fsf) {
3830 + rec->fsf_req_id = fsf->req_id;
3831 ++ rec->pl_len = FCP_RESP_WITH_EXT;
3832 + fcp_rsp = (struct fcp_resp_with_ext *)
3833 + &(fsf->qtcb->bottom.io.fcp_rsp);
3834 ++ /* mandatory parts of FCP_RSP IU in this SCSI record */
3835 + memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT);
3836 + if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) {
3837 + fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
3838 + rec->fcp_rsp_info = fcp_rsp_info->rsp_code;
3839 ++ rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_rsp_len);
3840 + }
3841 + if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
3842 +- rec->pl_len = min((u16)SCSI_SENSE_BUFFERSIZE,
3843 +- (u16)ZFCP_DBF_PAY_MAX_REC);
3844 +- zfcp_dbf_pl_write(dbf, sc->sense_buffer, rec->pl_len,
3845 +- "fcp_sns", fsf->req_id);
3846 ++ rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_sns_len);
3847 + }
3848 ++ /* complete FCP_RSP IU in associated PAYload record
3849 ++ * but only if there are optional parts
3850 ++ */
3851 ++ if (fcp_rsp->resp.fr_flags != 0)
3852 ++ zfcp_dbf_pl_write(
3853 ++ dbf, fcp_rsp,
3854 ++ /* at least one full PAY record
3855 ++ * but not beyond hardware response field
3856 ++ */
3857 ++ min_t(u16, max_t(u16, rec->pl_len,
3858 ++ ZFCP_DBF_PAY_MAX_REC),
3859 ++ FSF_FCP_RSP_SIZE),
3860 ++ "fcp_riu", fsf->req_id);
3861 + }
3862 +
3863 + debug_event(dbf->scsi, level, rec, sizeof(*rec));
3864 +diff --git a/drivers/s390/scsi/zfcp_dbf.h b/drivers/s390/scsi/zfcp_dbf.h
3865 +index db186d44cfaf..b60667c145fd 100644
3866 +--- a/drivers/s390/scsi/zfcp_dbf.h
3867 ++++ b/drivers/s390/scsi/zfcp_dbf.h
3868 +@@ -2,7 +2,7 @@
3869 + * zfcp device driver
3870 + * debug feature declarations
3871 + *
3872 +- * Copyright IBM Corp. 2008, 2016
3873 ++ * Copyright IBM Corp. 2008, 2017
3874 + */
3875 +
3876 + #ifndef ZFCP_DBF_H
3877 +@@ -204,7 +204,7 @@ enum zfcp_dbf_scsi_id {
3878 + * @id: unique number of recovery record type
3879 + * @tag: identifier string specifying the location of initiation
3880 + * @scsi_id: scsi device id
3881 +- * @scsi_lun: scsi device logical unit number
3882 ++ * @scsi_lun: scsi device logical unit number, low part of 64 bit, old 32 bit
3883 + * @scsi_result: scsi result
3884 + * @scsi_retries: current retry number of scsi request
3885 + * @scsi_allowed: allowed retries
3886 +@@ -214,6 +214,7 @@ enum zfcp_dbf_scsi_id {
3887 + * @host_scribble: LLD specific data attached to SCSI request
3888 + * @pl_len: length of paload stored as zfcp_dbf_pay
3889 + * @fsf_rsp: response for fsf request
3890 ++ * @scsi_lun_64_hi: scsi device logical unit number, high part of 64 bit
3891 + */
3892 + struct zfcp_dbf_scsi {
3893 + u8 id;
3894 +@@ -230,6 +231,7 @@ struct zfcp_dbf_scsi {
3895 + u64 host_scribble;
3896 + u16 pl_len;
3897 + struct fcp_resp_with_ext fcp_rsp;
3898 ++ u32 scsi_lun_64_hi;
3899 + } __packed;
3900 +
3901 + /**
3902 +@@ -323,7 +325,11 @@ void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
3903 + {
3904 + struct fsf_qtcb *qtcb = req->qtcb;
3905 +
3906 +- if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
3907 ++ if (unlikely(req->status & (ZFCP_STATUS_FSFREQ_DISMISSED |
3908 ++ ZFCP_STATUS_FSFREQ_ERROR))) {
3909 ++ zfcp_dbf_hba_fsf_resp("fs_rerr", 3, req);
3910 ++
3911 ++ } else if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
3912 + (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
3913 + zfcp_dbf_hba_fsf_resp("fs_perr", 1, req);
3914 +
3915 +@@ -401,7 +407,8 @@ void zfcp_dbf_scsi_abort(char *tag, struct scsi_cmnd *scmd,
3916 + * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
3917 + */
3918 + static inline
3919 +-void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag)
3920 ++void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag,
3921 ++ struct zfcp_fsf_req *fsf_req)
3922 + {
3923 + char tmp_tag[ZFCP_DBF_TAG_LEN];
3924 +
3925 +@@ -411,7 +418,7 @@ void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag)
3926 + memcpy(tmp_tag, "lr_", 3);
3927 +
3928 + memcpy(&tmp_tag[3], tag, 4);
3929 +- _zfcp_dbf_scsi(tmp_tag, 1, scmnd, NULL);
3930 ++ _zfcp_dbf_scsi(tmp_tag, 1, scmnd, fsf_req);
3931 + }
3932 +
3933 + /**
3934 +diff --git a/drivers/s390/scsi/zfcp_fc.h b/drivers/s390/scsi/zfcp_fc.h
3935 +index df2b541c8287..a2275825186f 100644
3936 +--- a/drivers/s390/scsi/zfcp_fc.h
3937 ++++ b/drivers/s390/scsi/zfcp_fc.h
3938 +@@ -4,7 +4,7 @@
3939 + * Fibre Channel related definitions and inline functions for the zfcp
3940 + * device driver
3941 + *
3942 +- * Copyright IBM Corp. 2009
3943 ++ * Copyright IBM Corp. 2009, 2017
3944 + */
3945 +
3946 + #ifndef ZFCP_FC_H
3947 +@@ -279,6 +279,10 @@ void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
3948 + !(rsp_flags & FCP_SNS_LEN_VAL) &&
3949 + fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
3950 + set_host_byte(scsi, DID_ERROR);
3951 ++ } else if (unlikely(rsp_flags & FCP_RESID_OVER)) {
3952 ++ /* FCP_DL was not sufficient for SCSI data length */
3953 ++ if (fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
3954 ++ set_host_byte(scsi, DID_ERROR);
3955 + }
3956 + }
3957 +
3958 +diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
3959 +index 27ff38f839fc..1964391db904 100644
3960 +--- a/drivers/s390/scsi/zfcp_fsf.c
3961 ++++ b/drivers/s390/scsi/zfcp_fsf.c
3962 +@@ -928,8 +928,8 @@ static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
3963 +
3964 + switch (header->fsf_status) {
3965 + case FSF_GOOD:
3966 +- zfcp_dbf_san_res("fsscth2", req);
3967 + ct->status = 0;
3968 ++ zfcp_dbf_san_res("fsscth2", req);
3969 + break;
3970 + case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3971 + zfcp_fsf_class_not_supp(req);
3972 +@@ -1109,8 +1109,8 @@ static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
3973 +
3974 + switch (header->fsf_status) {
3975 + case FSF_GOOD:
3976 +- zfcp_dbf_san_res("fsselh1", req);
3977 + send_els->status = 0;
3978 ++ zfcp_dbf_san_res("fsselh1", req);
3979 + break;
3980 + case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3981 + zfcp_fsf_class_not_supp(req);
3982 +@@ -2258,7 +2258,8 @@ int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
3983 + fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
3984 + zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
3985 +
3986 +- if (scsi_prot_sg_count(scsi_cmnd)) {
3987 ++ if ((scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) &&
3988 ++ scsi_prot_sg_count(scsi_cmnd)) {
3989 + zfcp_qdio_set_data_div(qdio, &req->qdio_req,
3990 + scsi_prot_sg_count(scsi_cmnd));
3991 + retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
3992 +diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
3993 +index 0678cf714c0e..a1eeeaaa0fca 100644
3994 +--- a/drivers/s390/scsi/zfcp_scsi.c
3995 ++++ b/drivers/s390/scsi/zfcp_scsi.c
3996 +@@ -3,7 +3,7 @@
3997 + *
3998 + * Interface to Linux SCSI midlayer.
3999 + *
4000 +- * Copyright IBM Corp. 2002, 2016
4001 ++ * Copyright IBM Corp. 2002, 2017
4002 + */
4003 +
4004 + #define KMSG_COMPONENT "zfcp"
4005 +@@ -273,25 +273,29 @@ static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags)
4006 +
4007 + zfcp_erp_wait(adapter);
4008 + ret = fc_block_scsi_eh(scpnt);
4009 +- if (ret)
4010 ++ if (ret) {
4011 ++ zfcp_dbf_scsi_devreset("fiof", scpnt, tm_flags, NULL);
4012 + return ret;
4013 ++ }
4014 +
4015 + if (!(atomic_read(&adapter->status) &
4016 + ZFCP_STATUS_COMMON_RUNNING)) {
4017 +- zfcp_dbf_scsi_devreset("nres", scpnt, tm_flags);
4018 ++ zfcp_dbf_scsi_devreset("nres", scpnt, tm_flags, NULL);
4019 + return SUCCESS;
4020 + }
4021 + }
4022 +- if (!fsf_req)
4023 ++ if (!fsf_req) {
4024 ++ zfcp_dbf_scsi_devreset("reqf", scpnt, tm_flags, NULL);
4025 + return FAILED;
4026 ++ }
4027 +
4028 + wait_for_completion(&fsf_req->completion);
4029 +
4030 + if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
4031 +- zfcp_dbf_scsi_devreset("fail", scpnt, tm_flags);
4032 ++ zfcp_dbf_scsi_devreset("fail", scpnt, tm_flags, fsf_req);
4033 + retval = FAILED;
4034 + } else {
4035 +- zfcp_dbf_scsi_devreset("okay", scpnt, tm_flags);
4036 ++ zfcp_dbf_scsi_devreset("okay", scpnt, tm_flags, fsf_req);
4037 + zfcp_scsi_forget_cmnds(zfcp_sdev, tm_flags);
4038 + }
4039 +
4040 +diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
4041 +index a1a2c71e1626..b051d97af468 100644
4042 +--- a/drivers/scsi/aacraid/aachba.c
4043 ++++ b/drivers/scsi/aacraid/aachba.c
4044 +@@ -594,6 +594,7 @@ static int aac_get_container_name(struct scsi_cmnd * scsicmd)
4045 +
4046 + aac_fib_init(cmd_fibcontext);
4047 + dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
4048 ++ scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4049 +
4050 + dinfo->command = cpu_to_le32(VM_ContainerConfig);
4051 + dinfo->type = cpu_to_le32(CT_READ_NAME);
4052 +@@ -611,10 +612,8 @@ static int aac_get_container_name(struct scsi_cmnd * scsicmd)
4053 + /*
4054 + * Check that the command queued to the controller
4055 + */
4056 +- if (status == -EINPROGRESS) {
4057 +- scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4058 ++ if (status == -EINPROGRESS)
4059 + return 0;
4060 +- }
4061 +
4062 + printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
4063 + aac_fib_complete(cmd_fibcontext);
4064 +@@ -725,6 +724,7 @@ static void _aac_probe_container1(void * context, struct fib * fibptr)
4065 +
4066 + dinfo->count = cpu_to_le32(scmd_id(scsicmd));
4067 + dinfo->type = cpu_to_le32(FT_FILESYS);
4068 ++ scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4069 +
4070 + status = aac_fib_send(ContainerCommand,
4071 + fibptr,
4072 +@@ -736,9 +736,7 @@ static void _aac_probe_container1(void * context, struct fib * fibptr)
4073 + /*
4074 + * Check that the command queued to the controller
4075 + */
4076 +- if (status == -EINPROGRESS)
4077 +- scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4078 +- else if (status < 0) {
4079 ++ if (status < 0 && status != -EINPROGRESS) {
4080 + /* Inherit results from VM_NameServe, if any */
4081 + dresp->status = cpu_to_le32(ST_OK);
4082 + _aac_probe_container2(context, fibptr);
4083 +@@ -766,6 +764,7 @@ static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(stru
4084 + dinfo->count = cpu_to_le32(scmd_id(scsicmd));
4085 + dinfo->type = cpu_to_le32(FT_FILESYS);
4086 + scsicmd->SCp.ptr = (char *)callback;
4087 ++ scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4088 +
4089 + status = aac_fib_send(ContainerCommand,
4090 + fibptr,
4091 +@@ -777,10 +776,9 @@ static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(stru
4092 + /*
4093 + * Check that the command queued to the controller
4094 + */
4095 +- if (status == -EINPROGRESS) {
4096 +- scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4097 ++ if (status == -EINPROGRESS)
4098 + return 0;
4099 +- }
4100 ++
4101 + if (status < 0) {
4102 + scsicmd->SCp.ptr = NULL;
4103 + aac_fib_complete(fibptr);
4104 +@@ -1126,6 +1124,7 @@ static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
4105 + dinfo->command = cpu_to_le32(VM_ContainerConfig);
4106 + dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
4107 + dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
4108 ++ scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4109 +
4110 + status = aac_fib_send(ContainerCommand,
4111 + cmd_fibcontext,
4112 +@@ -1138,10 +1137,8 @@ static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
4113 + /*
4114 + * Check that the command queued to the controller
4115 + */
4116 +- if (status == -EINPROGRESS) {
4117 +- scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4118 ++ if (status == -EINPROGRESS)
4119 + return 0;
4120 +- }
4121 +
4122 + printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
4123 + aac_fib_complete(cmd_fibcontext);
4124 +@@ -2335,16 +2332,14 @@ static int aac_read(struct scsi_cmnd * scsicmd)
4125 + * Alocate and initialize a Fib
4126 + */
4127 + cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
4128 +-
4129 ++ scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4130 + status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
4131 +
4132 + /*
4133 + * Check that the command queued to the controller
4134 + */
4135 +- if (status == -EINPROGRESS) {
4136 +- scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4137 ++ if (status == -EINPROGRESS)
4138 + return 0;
4139 +- }
4140 +
4141 + printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
4142 + /*
4143 +@@ -2429,16 +2424,14 @@ static int aac_write(struct scsi_cmnd * scsicmd)
4144 + * Allocate and initialize a Fib then setup a BlockWrite command
4145 + */
4146 + cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
4147 +-
4148 ++ scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4149 + status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
4150 +
4151 + /*
4152 + * Check that the command queued to the controller
4153 + */
4154 +- if (status == -EINPROGRESS) {
4155 +- scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4156 ++ if (status == -EINPROGRESS)
4157 + return 0;
4158 +- }
4159 +
4160 + printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
4161 + /*
4162 +@@ -2588,6 +2581,7 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd)
4163 + synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
4164 + synchronizecmd->count =
4165 + cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
4166 ++ scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4167 +
4168 + /*
4169 + * Now send the Fib to the adapter
4170 +@@ -2603,10 +2597,8 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd)
4171 + /*
4172 + * Check that the command queued to the controller
4173 + */
4174 +- if (status == -EINPROGRESS) {
4175 +- scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4176 ++ if (status == -EINPROGRESS)
4177 + return 0;
4178 +- }
4179 +
4180 + printk(KERN_WARNING
4181 + "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
4182 +@@ -2666,6 +2658,7 @@ static int aac_start_stop(struct scsi_cmnd *scsicmd)
4183 + pmcmd->cid = cpu_to_le32(sdev_id(sdev));
4184 + pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
4185 + cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
4186 ++ scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4187 +
4188 + /*
4189 + * Now send the Fib to the adapter
4190 +@@ -2681,10 +2674,8 @@ static int aac_start_stop(struct scsi_cmnd *scsicmd)
4191 + /*
4192 + * Check that the command queued to the controller
4193 + */
4194 +- if (status == -EINPROGRESS) {
4195 +- scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4196 ++ if (status == -EINPROGRESS)
4197 + return 0;
4198 +- }
4199 +
4200 + aac_fib_complete(cmd_fibcontext);
4201 + aac_fib_free(cmd_fibcontext);
4202 +@@ -3692,16 +3683,14 @@ static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
4203 + * Allocate and initialize a Fib then setup a BlockWrite command
4204 + */
4205 + cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
4206 +-
4207 ++ scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4208 + status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
4209 +
4210 + /*
4211 + * Check that the command queued to the controller
4212 + */
4213 +- if (status == -EINPROGRESS) {
4214 +- scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4215 ++ if (status == -EINPROGRESS)
4216 + return 0;
4217 +- }
4218 +
4219 + printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
4220 + aac_fib_complete(cmd_fibcontext);
4221 +@@ -3739,15 +3728,14 @@ static int aac_send_hba_fib(struct scsi_cmnd *scsicmd)
4222 + if (!cmd_fibcontext)
4223 + return -1;
4224 +
4225 ++ scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4226 + status = aac_adapter_hba(cmd_fibcontext, scsicmd);
4227 +
4228 + /*
4229 + * Check that the command queued to the controller
4230 + */
4231 +- if (status == -EINPROGRESS) {
4232 +- scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
4233 ++ if (status == -EINPROGRESS)
4234 + return 0;
4235 +- }
4236 +
4237 + pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
4238 + status);
4239 +diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
4240 +index 71c4746341ea..3ee4ea79f81a 100644
4241 +--- a/drivers/scsi/megaraid/megaraid_sas_base.c
4242 ++++ b/drivers/scsi/megaraid/megaraid_sas_base.c
4243 +@@ -1995,9 +1995,12 @@ static void megasas_complete_outstanding_ioctls(struct megasas_instance *instanc
4244 + if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) {
4245 + cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
4246 + if (cmd_mfi->sync_cmd &&
4247 +- cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT)
4248 ++ (cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT)) {
4249 ++ cmd_mfi->frame->hdr.cmd_status =
4250 ++ MFI_STAT_WRONG_STATE;
4251 + megasas_complete_cmd(instance,
4252 + cmd_mfi, DID_OK);
4253 ++ }
4254 + }
4255 + }
4256 + } else {
4257 +@@ -5478,7 +5481,8 @@ static int megasas_init_fw(struct megasas_instance *instance)
4258 + instance->throttlequeuedepth =
4259 + MEGASAS_THROTTLE_QUEUE_DEPTH;
4260 +
4261 +- if (resetwaittime > MEGASAS_RESET_WAIT_TIME)
4262 ++ if ((resetwaittime < 1) ||
4263 ++ (resetwaittime > MEGASAS_RESET_WAIT_TIME))
4264 + resetwaittime = MEGASAS_RESET_WAIT_TIME;
4265 +
4266 + if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT))
4267 +@@ -5649,6 +5653,14 @@ megasas_register_aen(struct megasas_instance *instance, u32 seq_num,
4268 + prev_aen.word =
4269 + le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]);
4270 +
4271 ++ if ((curr_aen.members.class < MFI_EVT_CLASS_DEBUG) ||
4272 ++ (curr_aen.members.class > MFI_EVT_CLASS_DEAD)) {
4273 ++ dev_info(&instance->pdev->dev,
4274 ++ "%s %d out of range class %d send by application\n",
4275 ++ __func__, __LINE__, curr_aen.members.class);
4276 ++ return 0;
4277 ++ }
4278 ++
4279 + /*
4280 + * A class whose enum value is smaller is inclusive of all
4281 + * higher values. If a PROGRESS (= -1) was previously
4282 +diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
4283 +index 985510628f56..8152962f152d 100644
4284 +--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
4285 ++++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
4286 +@@ -3287,7 +3287,7 @@ build_mpt_mfi_pass_thru(struct megasas_instance *instance,
4287 + mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
4288 + MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
4289 +
4290 +- mpi25_ieee_chain->Length = cpu_to_le32(instance->max_chain_frame_sz);
4291 ++ mpi25_ieee_chain->Length = cpu_to_le32(instance->mfi_frame_size);
4292 + }
4293 +
4294 + /**
4295 +diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
4296 +index 2c3783684815..85e7bae4a7ef 100644
4297 +--- a/drivers/scsi/qedi/qedi_main.c
4298 ++++ b/drivers/scsi/qedi/qedi_main.c
4299 +@@ -1575,7 +1575,7 @@ struct qedi_cmd *qedi_get_cmd_from_tid(struct qedi_ctx *qedi, u32 tid)
4300 + {
4301 + struct qedi_cmd *cmd = NULL;
4302 +
4303 +- if (tid > MAX_ISCSI_TASK_ENTRIES)
4304 ++ if (tid >= MAX_ISCSI_TASK_ENTRIES)
4305 + return NULL;
4306 +
4307 + cmd = qedi->itt_map[tid].p_cmd;
4308 +diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
4309 +index 08a1feb3a195..8c6ff1682fb1 100644
4310 +--- a/drivers/scsi/qla2xxx/qla_attr.c
4311 ++++ b/drivers/scsi/qla2xxx/qla_attr.c
4312 +@@ -318,6 +318,8 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
4313 + return -EINVAL;
4314 + if (start > ha->optrom_size)
4315 + return -EINVAL;
4316 ++ if (size > ha->optrom_size - start)
4317 ++ size = ha->optrom_size - start;
4318 +
4319 + mutex_lock(&ha->optrom_mutex);
4320 + switch (val) {
4321 +@@ -343,8 +345,7 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
4322 + }
4323 +
4324 + ha->optrom_region_start = start;
4325 +- ha->optrom_region_size = start + size > ha->optrom_size ?
4326 +- ha->optrom_size - start : size;
4327 ++ ha->optrom_region_size = start + size;
4328 +
4329 + ha->optrom_state = QLA_SREADING;
4330 + ha->optrom_buffer = vmalloc(ha->optrom_region_size);
4331 +@@ -417,8 +418,7 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
4332 + }
4333 +
4334 + ha->optrom_region_start = start;
4335 +- ha->optrom_region_size = start + size > ha->optrom_size ?
4336 +- ha->optrom_size - start : size;
4337 ++ ha->optrom_region_size = start + size;
4338 +
4339 + ha->optrom_state = QLA_SWRITING;
4340 + ha->optrom_buffer = vmalloc(ha->optrom_region_size);
4341 +diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
4342 +index b323a7c71eda..0ec250993e93 100644
4343 +--- a/drivers/scsi/qla2xxx/qla_gs.c
4344 ++++ b/drivers/scsi/qla2xxx/qla_gs.c
4345 +@@ -3080,7 +3080,7 @@ int qla24xx_async_gpsc(scsi_qla_host_t *vha, fc_port_t *fcport)
4346 + GPSC_RSP_SIZE);
4347 +
4348 + /* GPSC req */
4349 +- memcpy(ct_req->req.gpsc.port_name, fcport->port_name,
4350 ++ memcpy(ct_req->req.gpsc.port_name, fcport->fabric_port_name,
4351 + WWN_SIZE);
4352 +
4353 + sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
4354 +diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
4355 +index 072ad1aa5505..8f83571afc7b 100644
4356 +--- a/drivers/scsi/qla2xxx/qla_init.c
4357 ++++ b/drivers/scsi/qla2xxx/qla_init.c
4358 +@@ -7804,6 +7804,7 @@ struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
4359 + ha->queue_pair_map[qpair_id] = qpair;
4360 + qpair->id = qpair_id;
4361 + qpair->vp_idx = vp_idx;
4362 ++ qpair->fw_started = ha->flags.fw_started;
4363 + INIT_LIST_HEAD(&qpair->hints_list);
4364 + qpair->chip_reset = ha->base_qpair->chip_reset;
4365 + qpair->enable_class_2 = ha->base_qpair->enable_class_2;
4366 +diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
4367 +index 7b3b702ef622..ec2c398f5663 100644
4368 +--- a/drivers/scsi/qla2xxx/qla_isr.c
4369 ++++ b/drivers/scsi/qla2xxx/qla_isr.c
4370 +@@ -3429,7 +3429,7 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
4371 + }
4372 +
4373 + /* Enable MSI-X vector for response queue update for queue 0 */
4374 +- if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
4375 ++ if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
4376 + if (ha->msixbase && ha->mqiobase &&
4377 + (ha->max_rsp_queues > 1 || ha->max_req_queues > 1 ||
4378 + ql2xmqsupport))
4379 +diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
4380 +index 7c6d1a404011..1f1a81c6eaa9 100644
4381 +--- a/drivers/scsi/qla2xxx/qla_mbx.c
4382 ++++ b/drivers/scsi/qla2xxx/qla_mbx.c
4383 +@@ -54,6 +54,7 @@ static struct rom_cmd {
4384 + { MBC_GET_MEM_OFFLOAD_CNTRL_STAT },
4385 + { MBC_GET_RETRY_COUNT },
4386 + { MBC_TRACE_CONTROL },
4387 ++ { MBC_INITIALIZE_MULTIQ },
4388 + };
4389 +
4390 + static int is_rom_cmd(uint16_t cmd)
4391 +@@ -3689,7 +3690,7 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
4392 + if (qla_ini_mode_enabled(vha) &&
4393 + ha->flags.fawwpn_enabled &&
4394 + (rptid_entry->u.f1.flags &
4395 +- VP_FLAGS_NAME_VALID)) {
4396 ++ BIT_6)) {
4397 + memcpy(vha->port_name,
4398 + rptid_entry->u.f1.port_name,
4399 + WWN_SIZE);
4400 +diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
4401 +index f0605cd196fb..3089094b48fa 100644
4402 +--- a/drivers/scsi/qla2xxx/qla_mid.c
4403 ++++ b/drivers/scsi/qla2xxx/qla_mid.c
4404 +@@ -74,7 +74,7 @@ qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
4405 + * ensures no active vp_list traversal while the vport is removed
4406 + * from the queue)
4407 + */
4408 +- wait_event_timeout(vha->vref_waitq, atomic_read(&vha->vref_count),
4409 ++ wait_event_timeout(vha->vref_waitq, !atomic_read(&vha->vref_count),
4410 + 10*HZ);
4411 +
4412 + spin_lock_irqsave(&ha->vport_slock, flags);
4413 +diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
4414 +index e101cd3043b9..4e2a64773060 100644
4415 +--- a/drivers/scsi/qla2xxx/qla_target.c
4416 ++++ b/drivers/scsi/qla2xxx/qla_target.c
4417 +@@ -6796,7 +6796,7 @@ qlt_probe_one_stage1(struct scsi_qla_host *base_vha, struct qla_hw_data *ha)
4418 + if (!QLA_TGT_MODE_ENABLED())
4419 + return;
4420 +
4421 +- if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
4422 ++ if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
4423 + ISP_ATIO_Q_IN(base_vha) = &ha->mqiobase->isp25mq.atio_q_in;
4424 + ISP_ATIO_Q_OUT(base_vha) = &ha->mqiobase->isp25mq.atio_q_out;
4425 + } else {
4426 +diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
4427 +index aad6ebb51735..1a9de8419997 100644
4428 +--- a/drivers/scsi/sg.c
4429 ++++ b/drivers/scsi/sg.c
4430 +@@ -828,6 +828,39 @@ static int max_sectors_bytes(struct request_queue *q)
4431 + return max_sectors << 9;
4432 + }
4433 +
4434 ++static void
4435 ++sg_fill_request_table(Sg_fd *sfp, sg_req_info_t *rinfo)
4436 ++{
4437 ++ Sg_request *srp;
4438 ++ int val;
4439 ++ unsigned int ms;
4440 ++
4441 ++ val = 0;
4442 ++ list_for_each_entry(srp, &sfp->rq_list, entry) {
4443 ++ if (val > SG_MAX_QUEUE)
4444 ++ break;
4445 ++ rinfo[val].req_state = srp->done + 1;
4446 ++ rinfo[val].problem =
4447 ++ srp->header.masked_status &
4448 ++ srp->header.host_status &
4449 ++ srp->header.driver_status;
4450 ++ if (srp->done)
4451 ++ rinfo[val].duration =
4452 ++ srp->header.duration;
4453 ++ else {
4454 ++ ms = jiffies_to_msecs(jiffies);
4455 ++ rinfo[val].duration =
4456 ++ (ms > srp->header.duration) ?
4457 ++ (ms - srp->header.duration) : 0;
4458 ++ }
4459 ++ rinfo[val].orphan = srp->orphan;
4460 ++ rinfo[val].sg_io_owned = srp->sg_io_owned;
4461 ++ rinfo[val].pack_id = srp->header.pack_id;
4462 ++ rinfo[val].usr_ptr = srp->header.usr_ptr;
4463 ++ val++;
4464 ++ }
4465 ++}
4466 ++
4467 + static long
4468 + sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
4469 + {
4470 +@@ -1012,38 +1045,13 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
4471 + return -EFAULT;
4472 + else {
4473 + sg_req_info_t *rinfo;
4474 +- unsigned int ms;
4475 +
4476 +- rinfo = kmalloc(SZ_SG_REQ_INFO * SG_MAX_QUEUE,
4477 +- GFP_KERNEL);
4478 ++ rinfo = kzalloc(SZ_SG_REQ_INFO * SG_MAX_QUEUE,
4479 ++ GFP_KERNEL);
4480 + if (!rinfo)
4481 + return -ENOMEM;
4482 + read_lock_irqsave(&sfp->rq_list_lock, iflags);
4483 +- val = 0;
4484 +- list_for_each_entry(srp, &sfp->rq_list, entry) {
4485 +- if (val >= SG_MAX_QUEUE)
4486 +- break;
4487 +- memset(&rinfo[val], 0, SZ_SG_REQ_INFO);
4488 +- rinfo[val].req_state = srp->done + 1;
4489 +- rinfo[val].problem =
4490 +- srp->header.masked_status &
4491 +- srp->header.host_status &
4492 +- srp->header.driver_status;
4493 +- if (srp->done)
4494 +- rinfo[val].duration =
4495 +- srp->header.duration;
4496 +- else {
4497 +- ms = jiffies_to_msecs(jiffies);
4498 +- rinfo[val].duration =
4499 +- (ms > srp->header.duration) ?
4500 +- (ms - srp->header.duration) : 0;
4501 +- }
4502 +- rinfo[val].orphan = srp->orphan;
4503 +- rinfo[val].sg_io_owned = srp->sg_io_owned;
4504 +- rinfo[val].pack_id = srp->header.pack_id;
4505 +- rinfo[val].usr_ptr = srp->header.usr_ptr;
4506 +- val++;
4507 +- }
4508 ++ sg_fill_request_table(sfp, rinfo);
4509 + read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
4510 + result = __copy_to_user(p, rinfo,
4511 + SZ_SG_REQ_INFO * SG_MAX_QUEUE);
4512 +diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
4513 +index 3cc8d67783a1..5e7200f05873 100644
4514 +--- a/drivers/scsi/storvsc_drv.c
4515 ++++ b/drivers/scsi/storvsc_drv.c
4516 +@@ -1640,6 +1640,8 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
4517 + put_cpu();
4518 +
4519 + if (ret == -EAGAIN) {
4520 ++ if (payload_sz > sizeof(cmd_request->mpb))
4521 ++ kfree(payload);
4522 + /* no more space */
4523 + return SCSI_MLQUEUE_DEVICE_BUSY;
4524 + }
4525 +diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
4526 +index 4e7a4e9dcf4d..f8eba1c5412f 100644
4527 +--- a/drivers/tty/tty_buffer.c
4528 ++++ b/drivers/tty/tty_buffer.c
4529 +@@ -361,6 +361,32 @@ int tty_insert_flip_string_flags(struct tty_port *port,
4530 + }
4531 + EXPORT_SYMBOL(tty_insert_flip_string_flags);
4532 +
4533 ++/**
4534 ++ * __tty_insert_flip_char - Add one character to the tty buffer
4535 ++ * @port: tty port
4536 ++ * @ch: character
4537 ++ * @flag: flag byte
4538 ++ *
4539 ++ * Queue a single byte to the tty buffering, with an optional flag.
4540 ++ * This is the slow path of tty_insert_flip_char.
4541 ++ */
4542 ++int __tty_insert_flip_char(struct tty_port *port, unsigned char ch, char flag)
4543 ++{
4544 ++ struct tty_buffer *tb;
4545 ++ int flags = (flag == TTY_NORMAL) ? TTYB_NORMAL : 0;
4546 ++
4547 ++ if (!__tty_buffer_request_room(port, 1, flags))
4548 ++ return 0;
4549 ++
4550 ++ tb = port->buf.tail;
4551 ++ if (~tb->flags & TTYB_NORMAL)
4552 ++ *flag_buf_ptr(tb, tb->used) = flag;
4553 ++ *char_buf_ptr(tb, tb->used++) = ch;
4554 ++
4555 ++ return 1;
4556 ++}
4557 ++EXPORT_SYMBOL(__tty_insert_flip_char);
4558 ++
4559 + /**
4560 + * tty_schedule_flip - push characters to ldisc
4561 + * @port: tty port to push from
4562 +diff --git a/fs/ext4/file.c b/fs/ext4/file.c
4563 +index 0d7cf0cc9b87..86ea1d92839a 100644
4564 +--- a/fs/ext4/file.c
4565 ++++ b/fs/ext4/file.c
4566 +@@ -595,7 +595,7 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)
4567 + inode_lock(inode);
4568 +
4569 + isize = i_size_read(inode);
4570 +- if (offset >= isize) {
4571 ++ if (offset < 0 || offset >= isize) {
4572 + inode_unlock(inode);
4573 + return -ENXIO;
4574 + }
4575 +@@ -658,7 +658,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)
4576 + inode_lock(inode);
4577 +
4578 + isize = i_size_read(inode);
4579 +- if (offset >= isize) {
4580 ++ if (offset < 0 || offset >= isize) {
4581 + inode_unlock(inode);
4582 + return -ENXIO;
4583 + }
4584 +diff --git a/fs/ext4/super.c b/fs/ext4/super.c
4585 +index d61a70e2193a..c9e7be58756b 100644
4586 +--- a/fs/ext4/super.c
4587 ++++ b/fs/ext4/super.c
4588 +@@ -2404,6 +2404,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
4589 + unsigned int s_flags = sb->s_flags;
4590 + int ret, nr_orphans = 0, nr_truncates = 0;
4591 + #ifdef CONFIG_QUOTA
4592 ++ int quota_update = 0;
4593 + int i;
4594 + #endif
4595 + if (!es->s_last_orphan) {
4596 +@@ -2442,14 +2443,32 @@ static void ext4_orphan_cleanup(struct super_block *sb,
4597 + #ifdef CONFIG_QUOTA
4598 + /* Needed for iput() to work correctly and not trash data */
4599 + sb->s_flags |= MS_ACTIVE;
4600 +- /* Turn on quotas so that they are updated correctly */
4601 ++
4602 ++ /*
4603 ++ * Turn on quotas which were not enabled for read-only mounts if
4604 ++ * filesystem has quota feature, so that they are updated correctly.
4605 ++ */
4606 ++ if (ext4_has_feature_quota(sb) && (s_flags & MS_RDONLY)) {
4607 ++ int ret = ext4_enable_quotas(sb);
4608 ++
4609 ++ if (!ret)
4610 ++ quota_update = 1;
4611 ++ else
4612 ++ ext4_msg(sb, KERN_ERR,
4613 ++ "Cannot turn on quotas: error %d", ret);
4614 ++ }
4615 ++
4616 ++ /* Turn on journaled quotas used for old sytle */
4617 + for (i = 0; i < EXT4_MAXQUOTAS; i++) {
4618 + if (EXT4_SB(sb)->s_qf_names[i]) {
4619 + int ret = ext4_quota_on_mount(sb, i);
4620 +- if (ret < 0)
4621 ++
4622 ++ if (!ret)
4623 ++ quota_update = 1;
4624 ++ else
4625 + ext4_msg(sb, KERN_ERR,
4626 + "Cannot turn on journaled "
4627 +- "quota: error %d", ret);
4628 ++ "quota: type %d: error %d", i, ret);
4629 + }
4630 + }
4631 + #endif
4632 +@@ -2510,10 +2529,12 @@ static void ext4_orphan_cleanup(struct super_block *sb,
4633 + ext4_msg(sb, KERN_INFO, "%d truncate%s cleaned up",
4634 + PLURAL(nr_truncates));
4635 + #ifdef CONFIG_QUOTA
4636 +- /* Turn quotas off */
4637 +- for (i = 0; i < EXT4_MAXQUOTAS; i++) {
4638 +- if (sb_dqopt(sb)->files[i])
4639 +- dquot_quota_off(sb, i);
4640 ++ /* Turn off quotas if they were enabled for orphan cleanup */
4641 ++ if (quota_update) {
4642 ++ for (i = 0; i < EXT4_MAXQUOTAS; i++) {
4643 ++ if (sb_dqopt(sb)->files[i])
4644 ++ dquot_quota_off(sb, i);
4645 ++ }
4646 + }
4647 + #endif
4648 + sb->s_flags = s_flags; /* Restore MS_RDONLY status */
4649 +@@ -5512,6 +5533,9 @@ static int ext4_enable_quotas(struct super_block *sb)
4650 + DQUOT_USAGE_ENABLED |
4651 + (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0));
4652 + if (err) {
4653 ++ for (type--; type >= 0; type--)
4654 ++ dquot_quota_off(sb, type);
4655 ++
4656 + ext4_warning(sb,
4657 + "Failed to enable quota tracking "
4658 + "(type=%d, err=%d). Please run "
4659 +diff --git a/fs/orangefs/acl.c b/fs/orangefs/acl.c
4660 +index 7a3754488312..9409aac232f7 100644
4661 +--- a/fs/orangefs/acl.c
4662 ++++ b/fs/orangefs/acl.c
4663 +@@ -61,9 +61,9 @@ struct posix_acl *orangefs_get_acl(struct inode *inode, int type)
4664 + return acl;
4665 + }
4666 +
4667 +-int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
4668 ++static int __orangefs_set_acl(struct inode *inode, struct posix_acl *acl,
4669 ++ int type)
4670 + {
4671 +- struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
4672 + int error = 0;
4673 + void *value = NULL;
4674 + size_t size = 0;
4675 +@@ -72,22 +72,6 @@ int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
4676 + switch (type) {
4677 + case ACL_TYPE_ACCESS:
4678 + name = XATTR_NAME_POSIX_ACL_ACCESS;
4679 +- if (acl) {
4680 +- umode_t mode;
4681 +-
4682 +- error = posix_acl_update_mode(inode, &mode, &acl);
4683 +- if (error) {
4684 +- gossip_err("%s: posix_acl_update_mode err: %d\n",
4685 +- __func__,
4686 +- error);
4687 +- return error;
4688 +- }
4689 +-
4690 +- if (inode->i_mode != mode)
4691 +- SetModeFlag(orangefs_inode);
4692 +- inode->i_mode = mode;
4693 +- mark_inode_dirty_sync(inode);
4694 +- }
4695 + break;
4696 + case ACL_TYPE_DEFAULT:
4697 + name = XATTR_NAME_POSIX_ACL_DEFAULT;
4698 +@@ -132,6 +116,29 @@ int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
4699 + return error;
4700 + }
4701 +
4702 ++int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
4703 ++{
4704 ++ int error;
4705 ++
4706 ++ if (type == ACL_TYPE_ACCESS && acl) {
4707 ++ umode_t mode;
4708 ++
4709 ++ error = posix_acl_update_mode(inode, &mode, &acl);
4710 ++ if (error) {
4711 ++ gossip_err("%s: posix_acl_update_mode err: %d\n",
4712 ++ __func__,
4713 ++ error);
4714 ++ return error;
4715 ++ }
4716 ++
4717 ++ if (inode->i_mode != mode)
4718 ++ SetModeFlag(ORANGEFS_I(inode));
4719 ++ inode->i_mode = mode;
4720 ++ mark_inode_dirty_sync(inode);
4721 ++ }
4722 ++ return __orangefs_set_acl(inode, acl, type);
4723 ++}
4724 ++
4725 + int orangefs_init_acl(struct inode *inode, struct inode *dir)
4726 + {
4727 + struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
4728 +@@ -146,13 +153,14 @@ int orangefs_init_acl(struct inode *inode, struct inode *dir)
4729 + return error;
4730 +
4731 + if (default_acl) {
4732 +- error = orangefs_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
4733 ++ error = __orangefs_set_acl(inode, default_acl,
4734 ++ ACL_TYPE_DEFAULT);
4735 + posix_acl_release(default_acl);
4736 + }
4737 +
4738 + if (acl) {
4739 + if (!error)
4740 +- error = orangefs_set_acl(inode, acl, ACL_TYPE_ACCESS);
4741 ++ error = __orangefs_set_acl(inode, acl, ACL_TYPE_ACCESS);
4742 + posix_acl_release(acl);
4743 + }
4744 +
4745 +diff --git a/include/linux/ccp.h b/include/linux/ccp.h
4746 +index 3285c944194a..ab693c3afd0d 100644
4747 +--- a/include/linux/ccp.h
4748 ++++ b/include/linux/ccp.h
4749 +@@ -1,7 +1,7 @@
4750 + /*
4751 + * AMD Cryptographic Coprocessor (CCP) driver
4752 + *
4753 +- * Copyright (C) 2013,2016 Advanced Micro Devices, Inc.
4754 ++ * Copyright (C) 2013,2017 Advanced Micro Devices, Inc.
4755 + *
4756 + * Author: Tom Lendacky <thomas.lendacky@×××.com>
4757 + * Author: Gary R Hook <gary.hook@×××.com>
4758 +@@ -231,6 +231,7 @@ enum ccp_xts_aes_unit_size {
4759 + * AES operation the new IV overwrites the old IV.
4760 + */
4761 + struct ccp_xts_aes_engine {
4762 ++ enum ccp_aes_type type;
4763 + enum ccp_aes_action action;
4764 + enum ccp_xts_aes_unit_size unit_size;
4765 +
4766 +diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
4767 +index 898cfe2eeb42..bc46e729fdde 100644
4768 +--- a/include/linux/cpuset.h
4769 ++++ b/include/linux/cpuset.h
4770 +@@ -57,7 +57,9 @@ static inline void cpuset_dec(void)
4771 +
4772 + extern int cpuset_init(void);
4773 + extern void cpuset_init_smp(void);
4774 ++extern void cpuset_force_rebuild(void);
4775 + extern void cpuset_update_active_cpus(void);
4776 ++extern void cpuset_wait_for_hotplug(void);
4777 + extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
4778 + extern void cpuset_cpus_allowed_fallback(struct task_struct *p);
4779 + extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
4780 +@@ -170,11 +172,15 @@ static inline bool cpusets_enabled(void) { return false; }
4781 + static inline int cpuset_init(void) { return 0; }
4782 + static inline void cpuset_init_smp(void) {}
4783 +
4784 ++static inline void cpuset_force_rebuild(void) { }
4785 ++
4786 + static inline void cpuset_update_active_cpus(void)
4787 + {
4788 + partition_sched_domains(1, NULL, NULL);
4789 + }
4790 +
4791 ++static inline void cpuset_wait_for_hotplug(void) { }
4792 ++
4793 + static inline void cpuset_cpus_allowed(struct task_struct *p,
4794 + struct cpumask *mask)
4795 + {
4796 +diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
4797 +index 6383115e9d2c..2e028854bac7 100644
4798 +--- a/include/linux/ftrace.h
4799 ++++ b/include/linux/ftrace.h
4800 +@@ -307,7 +307,7 @@ DECLARE_PER_CPU(int, disable_stack_tracer);
4801 + static inline void stack_tracer_disable(void)
4802 + {
4803 + /* Preemption or interupts must be disabled */
4804 +- if (IS_ENABLED(CONFIG_PREEMPT_DEBUG))
4805 ++ if (IS_ENABLED(CONFIG_DEBUG_PREEMPT))
4806 + WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
4807 + this_cpu_inc(disable_stack_tracer);
4808 + }
4809 +@@ -320,7 +320,7 @@ static inline void stack_tracer_disable(void)
4810 + */
4811 + static inline void stack_tracer_enable(void)
4812 + {
4813 +- if (IS_ENABLED(CONFIG_PREEMPT_DEBUG))
4814 ++ if (IS_ENABLED(CONFIG_DEBUG_PREEMPT))
4815 + WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
4816 + this_cpu_dec(disable_stack_tracer);
4817 + }
4818 +diff --git a/include/linux/tty_flip.h b/include/linux/tty_flip.h
4819 +index c28dd523f96e..d43837f2ce3a 100644
4820 +--- a/include/linux/tty_flip.h
4821 ++++ b/include/linux/tty_flip.h
4822 +@@ -12,6 +12,7 @@ extern int tty_prepare_flip_string(struct tty_port *port,
4823 + unsigned char **chars, size_t size);
4824 + extern void tty_flip_buffer_push(struct tty_port *port);
4825 + void tty_schedule_flip(struct tty_port *port);
4826 ++int __tty_insert_flip_char(struct tty_port *port, unsigned char ch, char flag);
4827 +
4828 + static inline int tty_insert_flip_char(struct tty_port *port,
4829 + unsigned char ch, char flag)
4830 +@@ -26,7 +27,7 @@ static inline int tty_insert_flip_char(struct tty_port *port,
4831 + *char_buf_ptr(tb, tb->used++) = ch;
4832 + return 1;
4833 + }
4834 +- return tty_insert_flip_string_flags(port, &ch, &flag, 1);
4835 ++ return __tty_insert_flip_char(port, ch, flag);
4836 + }
4837 +
4838 + static inline int tty_insert_flip_string(struct tty_port *port,
4839 +diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
4840 +index acdd6f915a8d..20ef8e6ec2db 100644
4841 +--- a/include/linux/uaccess.h
4842 ++++ b/include/linux/uaccess.h
4843 +@@ -156,7 +156,7 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4844 + }
4845 + #ifdef CONFIG_COMPAT
4846 + static __always_inline unsigned long __must_check
4847 +-copy_in_user(void __user *to, const void *from, unsigned long n)
4848 ++copy_in_user(void __user *to, const void __user *from, unsigned long n)
4849 + {
4850 + might_fault();
4851 + if (access_ok(VERIFY_WRITE, to, n) && access_ok(VERIFY_READ, from, n))
4852 +diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
4853 +index 87a1213dd326..e8cb34193433 100644
4854 +--- a/kernel/cgroup/cpuset.c
4855 ++++ b/kernel/cgroup/cpuset.c
4856 +@@ -2260,6 +2260,13 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs)
4857 + mutex_unlock(&cpuset_mutex);
4858 + }
4859 +
4860 ++static bool force_rebuild;
4861 ++
4862 ++void cpuset_force_rebuild(void)
4863 ++{
4864 ++ force_rebuild = true;
4865 ++}
4866 ++
4867 + /**
4868 + * cpuset_hotplug_workfn - handle CPU/memory hotunplug for a cpuset
4869 + *
4870 +@@ -2334,8 +2341,10 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
4871 + }
4872 +
4873 + /* rebuild sched domains if cpus_allowed has changed */
4874 +- if (cpus_updated)
4875 ++ if (cpus_updated || force_rebuild) {
4876 ++ force_rebuild = false;
4877 + rebuild_sched_domains();
4878 ++ }
4879 + }
4880 +
4881 + void cpuset_update_active_cpus(void)
4882 +@@ -2354,6 +2363,11 @@ void cpuset_update_active_cpus(void)
4883 + schedule_work(&cpuset_hotplug_work);
4884 + }
4885 +
4886 ++void cpuset_wait_for_hotplug(void)
4887 ++{
4888 ++ flush_work(&cpuset_hotplug_work);
4889 ++}
4890 ++
4891 + /*
4892 + * Keep top_cpuset.mems_allowed tracking node_states[N_MEMORY].
4893 + * Call this routine anytime after node_states[N_MEMORY] changes.
4894 +diff --git a/kernel/cpu.c b/kernel/cpu.c
4895 +index eee033134262..a88c29ab09be 100644
4896 +--- a/kernel/cpu.c
4897 ++++ b/kernel/cpu.c
4898 +@@ -1252,7 +1252,17 @@ static int cpuhp_store_callbacks(enum cpuhp_state state, const char *name,
4899 + struct cpuhp_step *sp;
4900 + int ret = 0;
4901 +
4902 +- if (state == CPUHP_AP_ONLINE_DYN || state == CPUHP_BP_PREPARE_DYN) {
4903 ++ /*
4904 ++ * If name is NULL, then the state gets removed.
4905 ++ *
4906 ++ * CPUHP_AP_ONLINE_DYN and CPUHP_BP_PREPARE_DYN are handed out on
4907 ++ * the first allocation from these dynamic ranges, so the removal
4908 ++ * would trigger a new allocation and clear the wrong (already
4909 ++ * empty) state, leaving the callbacks of the to be cleared state
4910 ++ * dangling, which causes wreckage on the next hotplug operation.
4911 ++ */
4912 ++ if (name && (state == CPUHP_AP_ONLINE_DYN ||
4913 ++ state == CPUHP_BP_PREPARE_DYN)) {
4914 + ret = cpuhp_reserve_state(state);
4915 + if (ret < 0)
4916 + return ret;
4917 +diff --git a/kernel/power/process.c b/kernel/power/process.c
4918 +index 78672d324a6e..50f25cb370c6 100644
4919 +--- a/kernel/power/process.c
4920 ++++ b/kernel/power/process.c
4921 +@@ -20,8 +20,9 @@
4922 + #include <linux/workqueue.h>
4923 + #include <linux/kmod.h>
4924 + #include <trace/events/power.h>
4925 ++#include <linux/cpuset.h>
4926 +
4927 +-/*
4928 ++/*
4929 + * Timeout for stopping processes
4930 + */
4931 + unsigned int __read_mostly freeze_timeout_msecs = 20 * MSEC_PER_SEC;
4932 +@@ -202,6 +203,8 @@ void thaw_processes(void)
4933 + __usermodehelper_set_disable_depth(UMH_FREEZING);
4934 + thaw_workqueues();
4935 +
4936 ++ cpuset_wait_for_hotplug();
4937 ++
4938 + read_lock(&tasklist_lock);
4939 + for_each_process_thread(g, p) {
4940 + /* No other threads should have PF_SUSPEND_TASK set */
4941 +diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
4942 +index d0ca524bf042..258a9abee0b0 100644
4943 +--- a/kernel/rcu/srcutree.c
4944 ++++ b/kernel/rcu/srcutree.c
4945 +@@ -896,6 +896,15 @@ static void __synchronize_srcu(struct srcu_struct *sp, bool do_norm)
4946 + __call_srcu(sp, &rcu.head, wakeme_after_rcu, do_norm);
4947 + wait_for_completion(&rcu.completion);
4948 + destroy_rcu_head_on_stack(&rcu.head);
4949 ++
4950 ++ /*
4951 ++ * Make sure that later code is ordered after the SRCU grace
4952 ++ * period. This pairs with the raw_spin_lock_irq_rcu_node()
4953 ++ * in srcu_invoke_callbacks(). Unlike Tree RCU, this is needed
4954 ++ * because the current CPU might have been totally uninvolved with
4955 ++ * (and thus unordered against) that grace period.
4956 ++ */
4957 ++ smp_mb();
4958 + }
4959 +
4960 + /**
4961 +diff --git a/kernel/sched/core.c b/kernel/sched/core.c
4962 +index 0869b20fba81..99326c370c9c 100644
4963 +--- a/kernel/sched/core.c
4964 ++++ b/kernel/sched/core.c
4965 +@@ -5538,16 +5538,15 @@ static void cpuset_cpu_active(void)
4966 + * operation in the resume sequence, just build a single sched
4967 + * domain, ignoring cpusets.
4968 + */
4969 +- num_cpus_frozen--;
4970 +- if (likely(num_cpus_frozen)) {
4971 +- partition_sched_domains(1, NULL, NULL);
4972 ++ partition_sched_domains(1, NULL, NULL);
4973 ++ if (--num_cpus_frozen)
4974 + return;
4975 +- }
4976 + /*
4977 + * This is the last CPU online operation. So fall through and
4978 + * restore the original sched domains by considering the
4979 + * cpuset configurations.
4980 + */
4981 ++ cpuset_force_rebuild();
4982 + }
4983 + cpuset_update_active_cpus();
4984 + }
4985 +diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
4986 +index 96cea88fa00f..725819569fa7 100644
4987 +--- a/kernel/trace/ftrace.c
4988 ++++ b/kernel/trace/ftrace.c
4989 +@@ -2828,13 +2828,14 @@ static int ftrace_shutdown(struct ftrace_ops *ops, int command)
4990 +
4991 + if (!command || !ftrace_enabled) {
4992 + /*
4993 +- * If these are per_cpu ops, they still need their
4994 +- * per_cpu field freed. Since, function tracing is
4995 ++ * If these are dynamic or per_cpu ops, they still
4996 ++ * need their data freed. Since, function tracing is
4997 + * not currently active, we can just free them
4998 + * without synchronizing all CPUs.
4999 + */
5000 +- if (ops->flags & FTRACE_OPS_FL_PER_CPU)
5001 +- per_cpu_ops_free(ops);
5002 ++ if (ops->flags & (FTRACE_OPS_FL_DYNAMIC | FTRACE_OPS_FL_PER_CPU))
5003 ++ goto free_ops;
5004 ++
5005 + return 0;
5006 + }
5007 +
5008 +@@ -2900,6 +2901,7 @@ static int ftrace_shutdown(struct ftrace_ops *ops, int command)
5009 + if (IS_ENABLED(CONFIG_PREEMPT))
5010 + synchronize_rcu_tasks();
5011 +
5012 ++ free_ops:
5013 + arch_ftrace_trampoline_free(ops);
5014 +
5015 + if (ops->flags & FTRACE_OPS_FL_PER_CPU)
5016 +diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
5017 +index 44004d8aa3b3..5efb4b63174e 100644
5018 +--- a/kernel/trace/trace.c
5019 ++++ b/kernel/trace/trace.c
5020 +@@ -2799,11 +2799,17 @@ static char *get_trace_buf(void)
5021 + if (!buffer || buffer->nesting >= 4)
5022 + return NULL;
5023 +
5024 +- return &buffer->buffer[buffer->nesting++][0];
5025 ++ buffer->nesting++;
5026 ++
5027 ++ /* Interrupts must see nesting incremented before we use the buffer */
5028 ++ barrier();
5029 ++ return &buffer->buffer[buffer->nesting][0];
5030 + }
5031 +
5032 + static void put_trace_buf(void)
5033 + {
5034 ++ /* Don't let the decrement of nesting leak before this */
5035 ++ barrier();
5036 + this_cpu_dec(trace_percpu_buffer->nesting);
5037 + }
5038 +
5039 +@@ -6220,7 +6226,7 @@ static int tracing_set_clock(struct trace_array *tr, const char *clockstr)
5040 + tracing_reset_online_cpus(&tr->trace_buffer);
5041 +
5042 + #ifdef CONFIG_TRACER_MAX_TRACE
5043 +- if (tr->flags & TRACE_ARRAY_FL_GLOBAL && tr->max_buffer.buffer)
5044 ++ if (tr->max_buffer.buffer)
5045 + ring_buffer_set_clock(tr->max_buffer.buffer, trace_clocks[i].func);
5046 + tracing_reset_online_cpus(&tr->max_buffer);
5047 + #endif
5048 +diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
5049 +index 36132f9280e6..51a6e09a7410 100644
5050 +--- a/kernel/trace/trace_events.c
5051 ++++ b/kernel/trace/trace_events.c
5052 +@@ -406,7 +406,7 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
5053 +
5054 + if (file->flags & EVENT_FILE_FL_RECORDED_TGID) {
5055 + tracing_stop_tgid_record();
5056 +- clear_bit(EVENT_FILE_FL_RECORDED_CMD_BIT, &file->flags);
5057 ++ clear_bit(EVENT_FILE_FL_RECORDED_TGID_BIT, &file->flags);
5058 + }
5059 +
5060 + call->class->reg(call, TRACE_REG_UNREGISTER, file);
5061 +diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c
5062 +index cb917cebae29..b17ec642793b 100644
5063 +--- a/kernel/trace/trace_selftest.c
5064 ++++ b/kernel/trace/trace_selftest.c
5065 +@@ -273,7 +273,7 @@ static int trace_selftest_ops(struct trace_array *tr, int cnt)
5066 + goto out_free;
5067 + if (cnt > 1) {
5068 + if (trace_selftest_test_global_cnt == 0)
5069 +- goto out;
5070 ++ goto out_free;
5071 + }
5072 + if (trace_selftest_test_dyn_cnt == 0)
5073 + goto out_free;
5074 +diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
5075 +index 9979f46c81dc..51390febd5e3 100644
5076 +--- a/net/netfilter/nf_conntrack_core.c
5077 ++++ b/net/netfilter/nf_conntrack_core.c
5078 +@@ -96,19 +96,26 @@ static struct conntrack_gc_work conntrack_gc_work;
5079 +
5080 + void nf_conntrack_lock(spinlock_t *lock) __acquires(lock)
5081 + {
5082 ++ /* 1) Acquire the lock */
5083 + spin_lock(lock);
5084 +- while (unlikely(nf_conntrack_locks_all)) {
5085 +- spin_unlock(lock);
5086 +
5087 +- /*
5088 +- * Order the 'nf_conntrack_locks_all' load vs. the
5089 +- * spin_unlock_wait() loads below, to ensure
5090 +- * that 'nf_conntrack_locks_all_lock' is indeed held:
5091 +- */
5092 +- smp_rmb(); /* spin_lock(&nf_conntrack_locks_all_lock) */
5093 +- spin_unlock_wait(&nf_conntrack_locks_all_lock);
5094 +- spin_lock(lock);
5095 +- }
5096 ++ /* 2) read nf_conntrack_locks_all, with ACQUIRE semantics
5097 ++ * It pairs with the smp_store_release() in nf_conntrack_all_unlock()
5098 ++ */
5099 ++ if (likely(smp_load_acquire(&nf_conntrack_locks_all) == false))
5100 ++ return;
5101 ++
5102 ++ /* fast path failed, unlock */
5103 ++ spin_unlock(lock);
5104 ++
5105 ++ /* Slow path 1) get global lock */
5106 ++ spin_lock(&nf_conntrack_locks_all_lock);
5107 ++
5108 ++ /* Slow path 2) get the lock we want */
5109 ++ spin_lock(lock);
5110 ++
5111 ++ /* Slow path 3) release the global lock */
5112 ++ spin_unlock(&nf_conntrack_locks_all_lock);
5113 + }
5114 + EXPORT_SYMBOL_GPL(nf_conntrack_lock);
5115 +
5116 +@@ -149,28 +156,27 @@ static void nf_conntrack_all_lock(void)
5117 + int i;
5118 +
5119 + spin_lock(&nf_conntrack_locks_all_lock);
5120 +- nf_conntrack_locks_all = true;
5121 +
5122 +- /*
5123 +- * Order the above store of 'nf_conntrack_locks_all' against
5124 +- * the spin_unlock_wait() loads below, such that if
5125 +- * nf_conntrack_lock() observes 'nf_conntrack_locks_all'
5126 +- * we must observe nf_conntrack_locks[] held:
5127 +- */
5128 +- smp_mb(); /* spin_lock(&nf_conntrack_locks_all_lock) */
5129 ++ nf_conntrack_locks_all = true;
5130 +
5131 + for (i = 0; i < CONNTRACK_LOCKS; i++) {
5132 +- spin_unlock_wait(&nf_conntrack_locks[i]);
5133 ++ spin_lock(&nf_conntrack_locks[i]);
5134 ++
5135 ++ /* This spin_unlock provides the "release" to ensure that
5136 ++ * nf_conntrack_locks_all==true is visible to everyone that
5137 ++ * acquired spin_lock(&nf_conntrack_locks[]).
5138 ++ */
5139 ++ spin_unlock(&nf_conntrack_locks[i]);
5140 + }
5141 + }
5142 +
5143 + static void nf_conntrack_all_unlock(void)
5144 + {
5145 +- /*
5146 +- * All prior stores must be complete before we clear
5147 ++ /* All prior stores must be complete before we clear
5148 + * 'nf_conntrack_locks_all'. Otherwise nf_conntrack_lock()
5149 + * might observe the false value but not the entire
5150 +- * critical section:
5151 ++ * critical section.
5152 ++ * It pairs with the smp_load_acquire() in nf_conntrack_lock()
5153 + */
5154 + smp_store_release(&nf_conntrack_locks_all, false);
5155 + spin_unlock(&nf_conntrack_locks_all_lock);
5156 +diff --git a/sound/core/seq_device.c b/sound/core/seq_device.c
5157 +index c4acf17e9f5e..e40a2cba5002 100644
5158 +--- a/sound/core/seq_device.c
5159 ++++ b/sound/core/seq_device.c
5160 +@@ -148,8 +148,10 @@ void snd_seq_device_load_drivers(void)
5161 + flush_work(&autoload_work);
5162 + }
5163 + EXPORT_SYMBOL(snd_seq_device_load_drivers);
5164 ++#define cancel_autoload_drivers() cancel_work_sync(&autoload_work)
5165 + #else
5166 + #define queue_autoload_drivers() /* NOP */
5167 ++#define cancel_autoload_drivers() /* NOP */
5168 + #endif
5169 +
5170 + /*
5171 +@@ -159,6 +161,7 @@ static int snd_seq_device_dev_free(struct snd_device *device)
5172 + {
5173 + struct snd_seq_device *dev = device->device_data;
5174 +
5175 ++ cancel_autoload_drivers();
5176 + put_device(&dev->dev);
5177 + return 0;
5178 + }