Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:4.14 commit in: /
Date: Tue, 24 Apr 2018 11:27:56
Message-Id: 1524569263.8478a01a7af2952c38d7374630f74cb0959ccc90.mpagano@gentoo
1 commit: 8478a01a7af2952c38d7374630f74cb0959ccc90
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Tue Apr 24 11:27:43 2018 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Tue Apr 24 11:27:43 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=8478a01a
7
8 Linux patch 4.14.36
9
10 0000_README | 4 +
11 1035_linux-4.14.36.patch | 6386 ++++++++++++++++++++++++++++++++++++++++++++++
12 2 files changed, 6390 insertions(+)
13
14 diff --git a/0000_README b/0000_README
15 index 423395e..ff88018 100644
16 --- a/0000_README
17 +++ b/0000_README
18 @@ -183,6 +183,10 @@ Patch: 1034_linux-4.14.35.patch
19 From: http://www.kernel.org
20 Desc: Linux 4.14.35
21
22 +Patch: 1035_linux-4.14.36.patch
23 +From: http://www.kernel.org
24 +Desc: Linux 4.14.36
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/1035_linux-4.14.36.patch b/1035_linux-4.14.36.patch
31 new file mode 100644
32 index 0000000..f66faf7
33 --- /dev/null
34 +++ b/1035_linux-4.14.36.patch
35 @@ -0,0 +1,6386 @@
36 +diff --git a/Makefile b/Makefile
37 +index 995666d5e57b..0a1f941899f4 100644
38 +--- a/Makefile
39 ++++ b/Makefile
40 +@@ -1,7 +1,7 @@
41 + # SPDX-License-Identifier: GPL-2.0
42 + VERSION = 4
43 + PATCHLEVEL = 14
44 +-SUBLEVEL = 35
45 ++SUBLEVEL = 36
46 + EXTRAVERSION =
47 + NAME = Petit Gorille
48 +
49 +diff --git a/arch/arm/boot/dts/at91sam9g25.dtsi b/arch/arm/boot/dts/at91sam9g25.dtsi
50 +index a7da0dd0c98f..0898213f3bb2 100644
51 +--- a/arch/arm/boot/dts/at91sam9g25.dtsi
52 ++++ b/arch/arm/boot/dts/at91sam9g25.dtsi
53 +@@ -21,7 +21,7 @@
54 + atmel,mux-mask = <
55 + /* A B C */
56 + 0xffffffff 0xffe0399f 0xc000001c /* pioA */
57 +- 0x0007ffff 0x8000fe3f 0x00000000 /* pioB */
58 ++ 0x0007ffff 0x00047e3f 0x00000000 /* pioB */
59 + 0x80000000 0x07c0ffff 0xb83fffff /* pioC */
60 + 0x003fffff 0x003f8000 0x00000000 /* pioD */
61 + >;
62 +diff --git a/arch/arm/boot/dts/da850-lego-ev3.dts b/arch/arm/boot/dts/da850-lego-ev3.dts
63 +index 413dbd5d9f64..81942ae83e1f 100644
64 +--- a/arch/arm/boot/dts/da850-lego-ev3.dts
65 ++++ b/arch/arm/boot/dts/da850-lego-ev3.dts
66 +@@ -178,7 +178,7 @@
67 + */
68 + battery {
69 + pinctrl-names = "default";
70 +- pintctrl-0 = <&battery_pins>;
71 ++ pinctrl-0 = <&battery_pins>;
72 + compatible = "lego,ev3-battery";
73 + io-channels = <&adc 4>, <&adc 3>;
74 + io-channel-names = "voltage", "current";
75 +@@ -392,7 +392,7 @@
76 + batt_volt_en {
77 + gpio-hog;
78 + gpios = <6 GPIO_ACTIVE_HIGH>;
79 +- output-low;
80 ++ output-high;
81 + };
82 + };
83 +
84 +diff --git a/arch/arm/boot/dts/exynos5250.dtsi b/arch/arm/boot/dts/exynos5250.dtsi
85 +index 8dbeb873e99c..35b1949a3e3c 100644
86 +--- a/arch/arm/boot/dts/exynos5250.dtsi
87 ++++ b/arch/arm/boot/dts/exynos5250.dtsi
88 +@@ -643,7 +643,7 @@
89 + power-domains = <&pd_gsc>;
90 + clocks = <&clock CLK_GSCL0>;
91 + clock-names = "gscl";
92 +- iommu = <&sysmmu_gsc0>;
93 ++ iommus = <&sysmmu_gsc0>;
94 + };
95 +
96 + gsc_1: gsc@13e10000 {
97 +@@ -653,7 +653,7 @@
98 + power-domains = <&pd_gsc>;
99 + clocks = <&clock CLK_GSCL1>;
100 + clock-names = "gscl";
101 +- iommu = <&sysmmu_gsc1>;
102 ++ iommus = <&sysmmu_gsc1>;
103 + };
104 +
105 + gsc_2: gsc@13e20000 {
106 +@@ -663,7 +663,7 @@
107 + power-domains = <&pd_gsc>;
108 + clocks = <&clock CLK_GSCL2>;
109 + clock-names = "gscl";
110 +- iommu = <&sysmmu_gsc2>;
111 ++ iommus = <&sysmmu_gsc2>;
112 + };
113 +
114 + gsc_3: gsc@13e30000 {
115 +@@ -673,7 +673,7 @@
116 + power-domains = <&pd_gsc>;
117 + clocks = <&clock CLK_GSCL3>;
118 + clock-names = "gscl";
119 +- iommu = <&sysmmu_gsc3>;
120 ++ iommus = <&sysmmu_gsc3>;
121 + };
122 +
123 + hdmi: hdmi@14530000 {
124 +diff --git a/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts b/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
125 +index 7bf5aa2237c9..7de704575aee 100644
126 +--- a/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
127 ++++ b/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
128 +@@ -39,6 +39,24 @@
129 + };
130 + };
131 +
132 ++ reg_3p3v: regulator-3p3v {
133 ++ compatible = "regulator-fixed";
134 ++ regulator-name = "fixed-3.3V";
135 ++ regulator-min-microvolt = <3300000>;
136 ++ regulator-max-microvolt = <3300000>;
137 ++ regulator-boot-on;
138 ++ regulator-always-on;
139 ++ };
140 ++
141 ++ reg_5v: regulator-5v {
142 ++ compatible = "regulator-fixed";
143 ++ regulator-name = "fixed-5V";
144 ++ regulator-min-microvolt = <5000000>;
145 ++ regulator-max-microvolt = <5000000>;
146 ++ regulator-boot-on;
147 ++ regulator-always-on;
148 ++ };
149 ++
150 + gpio_keys {
151 + compatible = "gpio-keys";
152 + pinctrl-names = "default";
153 +@@ -468,12 +486,14 @@
154 + };
155 +
156 + &usb1 {
157 +- vusb33-supply = <&mt6323_vusb_reg>;
158 ++ vusb33-supply = <&reg_3p3v>;
159 ++ vbus-supply = <&reg_5v>;
160 + status = "okay";
161 + };
162 +
163 + &usb2 {
164 +- vusb33-supply = <&mt6323_vusb_reg>;
165 ++ vusb33-supply = <&reg_3p3v>;
166 ++ vbus-supply = <&reg_5v>;
167 + status = "okay";
168 + };
169 +
170 +diff --git a/arch/arm/boot/dts/sama5d4.dtsi b/arch/arm/boot/dts/sama5d4.dtsi
171 +index 2fa36c525957..81b526085097 100644
172 +--- a/arch/arm/boot/dts/sama5d4.dtsi
173 ++++ b/arch/arm/boot/dts/sama5d4.dtsi
174 +@@ -1365,7 +1365,7 @@
175 + pinctrl@fc06a000 {
176 + #address-cells = <1>;
177 + #size-cells = <1>;
178 +- compatible = "atmel,at91sam9x5-pinctrl", "atmel,at91rm9200-pinctrl", "simple-bus";
179 ++ compatible = "atmel,sama5d3-pinctrl", "atmel,at91sam9x5-pinctrl", "simple-bus";
180 + ranges = <0xfc068000 0xfc068000 0x100
181 + 0xfc06a000 0xfc06a000 0x4000>;
182 + /* WARNING: revisit as pin spec has changed */
183 +diff --git a/arch/arm/mach-exynos/pm.c b/arch/arm/mach-exynos/pm.c
184 +index 1a7e5b5d08d8..3dbbf1fffead 100644
185 +--- a/arch/arm/mach-exynos/pm.c
186 ++++ b/arch/arm/mach-exynos/pm.c
187 +@@ -276,11 +276,7 @@ static int exynos_cpu0_enter_aftr(void)
188 + goto fail;
189 +
190 + call_firmware_op(cpu_boot, 1);
191 +-
192 +- if (soc_is_exynos3250())
193 +- dsb_sev();
194 +- else
195 +- arch_send_wakeup_ipi_mask(cpumask_of(1));
196 ++ dsb_sev();
197 + }
198 + }
199 + fail:
200 +diff --git a/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts b/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
201 +index 08b7bb7f5b74..c3c65b06ba76 100644
202 +--- a/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
203 ++++ b/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
204 +@@ -276,7 +276,7 @@
205 + pinctrl-names = "default", "clk-gate";
206 +
207 + bus-width = <8>;
208 +- max-frequency = <200000000>;
209 ++ max-frequency = <100000000>;
210 + non-removable;
211 + disable-wp;
212 + cap-mmc-highspeed;
213 +diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
214 +index b71306947290..06629011a434 100644
215 +--- a/arch/mips/include/asm/uaccess.h
216 ++++ b/arch/mips/include/asm/uaccess.h
217 +@@ -654,6 +654,13 @@ __clear_user(void __user *addr, __kernel_size_t size)
218 + {
219 + __kernel_size_t res;
220 +
221 ++#ifdef CONFIG_CPU_MICROMIPS
222 ++/* micromips memset / bzero also clobbers t7 & t8 */
223 ++#define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$15", "$24", "$31"
224 ++#else
225 ++#define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$31"
226 ++#endif /* CONFIG_CPU_MICROMIPS */
227 ++
228 + if (eva_kernel_access()) {
229 + __asm__ __volatile__(
230 + "move\t$4, %1\n\t"
231 +@@ -663,7 +670,7 @@ __clear_user(void __user *addr, __kernel_size_t size)
232 + "move\t%0, $6"
233 + : "=r" (res)
234 + : "r" (addr), "r" (size)
235 +- : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31");
236 ++ : bzero_clobbers);
237 + } else {
238 + might_fault();
239 + __asm__ __volatile__(
240 +@@ -674,7 +681,7 @@ __clear_user(void __user *addr, __kernel_size_t size)
241 + "move\t%0, $6"
242 + : "=r" (res)
243 + : "r" (addr), "r" (size)
244 +- : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31");
245 ++ : bzero_clobbers);
246 + }
247 +
248 + return res;
249 +diff --git a/arch/mips/lib/memset.S b/arch/mips/lib/memset.S
250 +index a1456664d6c2..f7327979a8f8 100644
251 +--- a/arch/mips/lib/memset.S
252 ++++ b/arch/mips/lib/memset.S
253 +@@ -219,7 +219,7 @@
254 + 1: PTR_ADDIU a0, 1 /* fill bytewise */
255 + R10KCBARRIER(0(ra))
256 + bne t1, a0, 1b
257 +- sb a1, -1(a0)
258 ++ EX(sb, a1, -1(a0), .Lsmall_fixup\@)
259 +
260 + 2: jr ra /* done */
261 + move a2, zero
262 +@@ -252,13 +252,18 @@
263 + PTR_L t0, TI_TASK($28)
264 + andi a2, STORMASK
265 + LONG_L t0, THREAD_BUADDR(t0)
266 +- LONG_ADDU a2, t1
267 ++ LONG_ADDU a2, a0
268 + jr ra
269 + LONG_SUBU a2, t0
270 +
271 + .Llast_fixup\@:
272 + jr ra
273 +- andi v1, a2, STORMASK
274 ++ nop
275 ++
276 ++.Lsmall_fixup\@:
277 ++ PTR_SUBU a2, t1, a0
278 ++ jr ra
279 ++ PTR_ADDIU a2, 1
280 +
281 + .endm
282 +
283 +diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
284 +index 10daa1d56e0a..c7c63959ba91 100644
285 +--- a/arch/powerpc/include/asm/barrier.h
286 ++++ b/arch/powerpc/include/asm/barrier.h
287 +@@ -35,7 +35,8 @@
288 + #define rmb() __asm__ __volatile__ ("sync" : : : "memory")
289 + #define wmb() __asm__ __volatile__ ("sync" : : : "memory")
290 +
291 +-#ifdef __SUBARCH_HAS_LWSYNC
292 ++/* The sub-arch has lwsync */
293 ++#if defined(__powerpc64__) || defined(CONFIG_PPC_E500MC)
294 + # define SMPWMB LWSYNC
295 + #else
296 + # define SMPWMB eieio
297 +diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
298 +index 726c23304a57..8eb3ebca02df 100644
299 +--- a/arch/powerpc/include/asm/opal.h
300 ++++ b/arch/powerpc/include/asm/opal.h
301 +@@ -21,6 +21,9 @@
302 + /* We calculate number of sg entries based on PAGE_SIZE */
303 + #define SG_ENTRIES_PER_NODE ((PAGE_SIZE - 16) / sizeof(struct opal_sg_entry))
304 +
305 ++/* Default time to sleep or delay between OPAL_BUSY/OPAL_BUSY_EVENT loops */
306 ++#define OPAL_BUSY_DELAY_MS 10
307 ++
308 + /* /sys/firmware/opal */
309 + extern struct kobject *opal_kobj;
310 +
311 +diff --git a/arch/powerpc/include/asm/synch.h b/arch/powerpc/include/asm/synch.h
312 +index 63e7f5a1f105..6ec546090ba1 100644
313 +--- a/arch/powerpc/include/asm/synch.h
314 ++++ b/arch/powerpc/include/asm/synch.h
315 +@@ -6,10 +6,6 @@
316 + #include <linux/stringify.h>
317 + #include <asm/feature-fixups.h>
318 +
319 +-#if defined(__powerpc64__) || defined(CONFIG_PPC_E500MC)
320 +-#define __SUBARCH_HAS_LWSYNC
321 +-#endif
322 +-
323 + #ifndef __ASSEMBLY__
324 + extern unsigned int __start___lwsync_fixup, __stop___lwsync_fixup;
325 + extern void do_lwsync_fixups(unsigned long value, void *fixup_start,
326 +diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c b/arch/powerpc/kernel/dt_cpu_ftrs.c
327 +index 7275fed271af..f047ae1b6271 100644
328 +--- a/arch/powerpc/kernel/dt_cpu_ftrs.c
329 ++++ b/arch/powerpc/kernel/dt_cpu_ftrs.c
330 +@@ -86,6 +86,7 @@ static int hv_mode;
331 +
332 + static struct {
333 + u64 lpcr;
334 ++ u64 lpcr_clear;
335 + u64 hfscr;
336 + u64 fscr;
337 + } system_registers;
338 +@@ -115,6 +116,8 @@ static void cpufeatures_flush_tlb(void)
339 +
340 + static void __restore_cpu_cpufeatures(void)
341 + {
342 ++ u64 lpcr;
343 ++
344 + /*
345 + * LPCR is restored by the power on engine already. It can be changed
346 + * after early init e.g., by radix enable, and we have no unified API
347 +@@ -127,8 +130,10 @@ static void __restore_cpu_cpufeatures(void)
348 + * The best we can do to accommodate secondary boot and idle restore
349 + * for now is "or" LPCR with existing.
350 + */
351 +-
352 +- mtspr(SPRN_LPCR, system_registers.lpcr | mfspr(SPRN_LPCR));
353 ++ lpcr = mfspr(SPRN_LPCR);
354 ++ lpcr |= system_registers.lpcr;
355 ++ lpcr &= ~system_registers.lpcr_clear;
356 ++ mtspr(SPRN_LPCR, lpcr);
357 + if (hv_mode) {
358 + mtspr(SPRN_LPID, 0);
359 + mtspr(SPRN_HFSCR, system_registers.hfscr);
360 +@@ -351,8 +356,9 @@ static int __init feat_enable_mmu_hash_v3(struct dt_cpu_feature *f)
361 + {
362 + u64 lpcr;
363 +
364 ++ system_registers.lpcr_clear |= (LPCR_ISL | LPCR_UPRT | LPCR_HR);
365 + lpcr = mfspr(SPRN_LPCR);
366 +- lpcr &= ~LPCR_ISL;
367 ++ lpcr &= ~(LPCR_ISL | LPCR_UPRT | LPCR_HR);
368 + mtspr(SPRN_LPCR, lpcr);
369 +
370 + cur_cpu_spec->mmu_features |= MMU_FTRS_HASH_BASE;
371 +diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c
372 +index 2e8d1b2b5af4..8545a9523b9b 100644
373 +--- a/arch/powerpc/kernel/eeh_pe.c
374 ++++ b/arch/powerpc/kernel/eeh_pe.c
375 +@@ -807,7 +807,8 @@ static void eeh_restore_bridge_bars(struct eeh_dev *edev)
376 + eeh_ops->write_config(pdn, 15*4, 4, edev->config_space[15]);
377 +
378 + /* PCI Command: 0x4 */
379 +- eeh_ops->write_config(pdn, PCI_COMMAND, 4, edev->config_space[1]);
380 ++ eeh_ops->write_config(pdn, PCI_COMMAND, 4, edev->config_space[1] |
381 ++ PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
382 +
383 + /* Check the PCIe link is ready */
384 + eeh_bridge_check_link(edev);
385 +diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
386 +index bebc3007a793..10b46b35c059 100644
387 +--- a/arch/powerpc/kernel/kprobes.c
388 ++++ b/arch/powerpc/kernel/kprobes.c
389 +@@ -457,29 +457,33 @@ static int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
390 + }
391 +
392 + kretprobe_assert(ri, orig_ret_address, trampoline_address);
393 +- regs->nip = orig_ret_address;
394 ++
395 + /*
396 +- * Make LR point to the orig_ret_address.
397 +- * When the 'nop' inside the kretprobe_trampoline
398 +- * is optimized, we can do a 'blr' after executing the
399 +- * detour buffer code.
400 ++ * We get here through one of two paths:
401 ++ * 1. by taking a trap -> kprobe_handler() -> here
402 ++ * 2. by optprobe branch -> optimized_callback() -> opt_pre_handler() -> here
403 ++ *
404 ++ * When going back through (1), we need regs->nip to be setup properly
405 ++ * as it is used to determine the return address from the trap.
406 ++ * For (2), since nip is not honoured with optprobes, we instead setup
407 ++ * the link register properly so that the subsequent 'blr' in
408 ++ * kretprobe_trampoline jumps back to the right instruction.
409 ++ *
410 ++ * For nip, we should set the address to the previous instruction since
411 ++ * we end up emulating it in kprobe_handler(), which increments the nip
412 ++ * again.
413 + */
414 ++ regs->nip = orig_ret_address - 4;
415 + regs->link = orig_ret_address;
416 +
417 +- reset_current_kprobe();
418 + kretprobe_hash_unlock(current, &flags);
419 +- preempt_enable_no_resched();
420 +
421 + hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) {
422 + hlist_del(&ri->hlist);
423 + kfree(ri);
424 + }
425 +- /*
426 +- * By returning a non-zero value, we are telling
427 +- * kprobe_handler() that we don't want the post_handler
428 +- * to run (and have re-enabled preemption)
429 +- */
430 +- return 1;
431 ++
432 ++ return 0;
433 + }
434 + NOKPROBE_SYMBOL(trampoline_probe_handler);
435 +
436 +diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c
437 +index 992c0d258e5d..c66132b145eb 100644
438 +--- a/arch/powerpc/kernel/machine_kexec_file_64.c
439 ++++ b/arch/powerpc/kernel/machine_kexec_file_64.c
440 +@@ -43,7 +43,7 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
441 +
442 + /* We don't support crash kernels yet. */
443 + if (image->type == KEXEC_TYPE_CRASH)
444 +- return -ENOTSUPP;
445 ++ return -EOPNOTSUPP;
446 +
447 + for (i = 0; i < ARRAY_SIZE(kexec_file_loaders); i++) {
448 + fops = kexec_file_loaders[i];
449 +diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c
450 +index a95ea007d654..d0c0b8443dcf 100644
451 +--- a/arch/powerpc/lib/feature-fixups.c
452 ++++ b/arch/powerpc/lib/feature-fixups.c
453 +@@ -55,7 +55,7 @@ static int patch_alt_instruction(unsigned int *src, unsigned int *dest,
454 + unsigned int *target = (unsigned int *)branch_target(src);
455 +
456 + /* Branch within the section doesn't need translating */
457 +- if (target < alt_start || target >= alt_end) {
458 ++ if (target < alt_start || target > alt_end) {
459 + instr = translate_branch(dest, src);
460 + if (!instr)
461 + return 1;
462 +diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
463 +index 67ec2e927253..87687e46b48b 100644
464 +--- a/arch/powerpc/mm/hash_utils_64.c
465 ++++ b/arch/powerpc/mm/hash_utils_64.c
466 +@@ -872,6 +872,12 @@ static void __init htab_initialize(void)
467 + /* Using a hypervisor which owns the htab */
468 + htab_address = NULL;
469 + _SDR1 = 0;
470 ++ /*
471 ++ * On POWER9, we need to do a H_REGISTER_PROC_TBL hcall
472 ++ * to inform the hypervisor that we wish to use the HPT.
473 ++ */
474 ++ if (cpu_has_feature(CPU_FTR_ARCH_300))
475 ++ register_process_table(0, 0, 0);
476 + #ifdef CONFIG_FA_DUMP
477 + /*
478 + * If firmware assisted dump is active firmware preserves
479 +diff --git a/arch/powerpc/platforms/powernv/opal-nvram.c b/arch/powerpc/platforms/powernv/opal-nvram.c
480 +index 9db4398ded5d..1bceb95f422d 100644
481 +--- a/arch/powerpc/platforms/powernv/opal-nvram.c
482 ++++ b/arch/powerpc/platforms/powernv/opal-nvram.c
483 +@@ -11,6 +11,7 @@
484 +
485 + #define DEBUG
486 +
487 ++#include <linux/delay.h>
488 + #include <linux/kernel.h>
489 + #include <linux/init.h>
490 + #include <linux/of.h>
491 +@@ -56,9 +57,17 @@ static ssize_t opal_nvram_write(char *buf, size_t count, loff_t *index)
492 +
493 + while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
494 + rc = opal_write_nvram(__pa(buf), count, off);
495 +- if (rc == OPAL_BUSY_EVENT)
496 ++ if (rc == OPAL_BUSY_EVENT) {
497 ++ msleep(OPAL_BUSY_DELAY_MS);
498 + opal_poll_events(NULL);
499 ++ } else if (rc == OPAL_BUSY) {
500 ++ msleep(OPAL_BUSY_DELAY_MS);
501 ++ }
502 + }
503 ++
504 ++ if (rc)
505 ++ return -EIO;
506 ++
507 + *index += count;
508 + return count;
509 + }
510 +diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c
511 +index 495ba4e7336d..55e97565ed2d 100644
512 +--- a/arch/powerpc/platforms/pseries/lpar.c
513 ++++ b/arch/powerpc/platforms/pseries/lpar.c
514 +@@ -726,15 +726,18 @@ static int pseries_lpar_resize_hpt(unsigned long shift)
515 + return 0;
516 + }
517 +
518 +-/* Actually only used for radix, so far */
519 + static int pseries_lpar_register_process_table(unsigned long base,
520 + unsigned long page_size, unsigned long table_size)
521 + {
522 + long rc;
523 +- unsigned long flags = PROC_TABLE_NEW;
524 ++ unsigned long flags = 0;
525 +
526 ++ if (table_size)
527 ++ flags |= PROC_TABLE_NEW;
528 + if (radix_enabled())
529 + flags |= PROC_TABLE_RADIX | PROC_TABLE_GTSE;
530 ++ else
531 ++ flags |= PROC_TABLE_HPT_SLB;
532 + for (;;) {
533 + rc = plpar_hcall_norets(H_REGISTER_PROC_TBL, flags, base,
534 + page_size, table_size);
535 +@@ -760,6 +763,7 @@ void __init hpte_init_pseries(void)
536 + mmu_hash_ops.flush_hash_range = pSeries_lpar_flush_hash_range;
537 + mmu_hash_ops.hpte_clear_all = pseries_hpte_clear_all;
538 + mmu_hash_ops.hugepage_invalidate = pSeries_lpar_hugepage_invalidate;
539 ++ register_process_table = pseries_lpar_register_process_table;
540 +
541 + if (firmware_has_feature(FW_FEATURE_HPT_RESIZE))
542 + mmu_hash_ops.resize_hpt = pseries_lpar_resize_hpt;
543 +diff --git a/arch/powerpc/sysdev/xive/native.c b/arch/powerpc/sysdev/xive/native.c
544 +index ebc244b08d67..0f89ee557b04 100644
545 +--- a/arch/powerpc/sysdev/xive/native.c
546 ++++ b/arch/powerpc/sysdev/xive/native.c
547 +@@ -388,6 +388,10 @@ static void xive_native_setup_cpu(unsigned int cpu, struct xive_cpu *xc)
548 + if (xive_pool_vps == XIVE_INVALID_VP)
549 + return;
550 +
551 ++ /* Check if pool VP already active, if it is, pull it */
552 ++ if (in_be32(xive_tima + TM_QW2_HV_POOL + TM_WORD2) & TM_QW2W2_VP)
553 ++ in_be64(xive_tima + TM_SPC_PULL_POOL_CTX);
554 ++
555 + /* Enable the pool VP */
556 + vp = xive_pool_vps + cpu;
557 + pr_debug("CPU %d setting up pool VP 0x%x\n", cpu, vp);
558 +diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c
559 +index cf8a2d92467f..45eb5999110b 100644
560 +--- a/arch/s390/hypfs/inode.c
561 ++++ b/arch/s390/hypfs/inode.c
562 +@@ -320,7 +320,7 @@ static void hypfs_kill_super(struct super_block *sb)
563 +
564 + if (sb->s_root)
565 + hypfs_delete_tree(sb->s_root);
566 +- if (sb_info->update_file)
567 ++ if (sb_info && sb_info->update_file)
568 + hypfs_remove(sb_info->update_file);
569 + kfree(sb->s_fs_info);
570 + sb->s_fs_info = NULL;
571 +diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
572 +index 2db18cbbb0ea..c0197097c86e 100644
573 +--- a/arch/um/os-Linux/file.c
574 ++++ b/arch/um/os-Linux/file.c
575 +@@ -12,6 +12,7 @@
576 + #include <sys/mount.h>
577 + #include <sys/socket.h>
578 + #include <sys/stat.h>
579 ++#include <sys/sysmacros.h>
580 + #include <sys/un.h>
581 + #include <sys/types.h>
582 + #include <os.h>
583 +diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c
584 +index a86d7cc2c2d8..bf0acb8aad8b 100644
585 +--- a/arch/um/os-Linux/signal.c
586 ++++ b/arch/um/os-Linux/signal.c
587 +@@ -16,6 +16,7 @@
588 + #include <os.h>
589 + #include <sysdep/mcontext.h>
590 + #include <um_malloc.h>
591 ++#include <sys/ucontext.h>
592 +
593 + void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *) = {
594 + [SIGTRAP] = relay_signal,
595 +@@ -159,7 +160,7 @@ static void (*handlers[_NSIG])(int sig, struct siginfo *si, mcontext_t *mc) = {
596 +
597 + static void hard_handler(int sig, siginfo_t *si, void *p)
598 + {
599 +- struct ucontext *uc = p;
600 ++ ucontext_t *uc = p;
601 + mcontext_t *mc = &uc->uc_mcontext;
602 + unsigned long pending = 1UL << sig;
603 +
604 +diff --git a/arch/x86/um/stub_segv.c b/arch/x86/um/stub_segv.c
605 +index 1518d2805ae8..27361cbb7ca9 100644
606 +--- a/arch/x86/um/stub_segv.c
607 ++++ b/arch/x86/um/stub_segv.c
608 +@@ -6,11 +6,12 @@
609 + #include <sysdep/stub.h>
610 + #include <sysdep/faultinfo.h>
611 + #include <sysdep/mcontext.h>
612 ++#include <sys/ucontext.h>
613 +
614 + void __attribute__ ((__section__ (".__syscall_stub")))
615 + stub_segv_handler(int sig, siginfo_t *info, void *p)
616 + {
617 +- struct ucontext *uc = p;
618 ++ ucontext_t *uc = p;
619 +
620 + GET_FAULTINFO_FROM_MC(*((struct faultinfo *) STUB_DATA),
621 + &uc->uc_mcontext);
622 +diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
623 +index f896c2975545..fcd8789470d1 100644
624 +--- a/arch/x86/xen/enlighten_pv.c
625 ++++ b/arch/x86/xen/enlighten_pv.c
626 +@@ -1258,10 +1258,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
627 + */
628 + __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
629 +
630 +- /* Work out if we support NX */
631 +- get_cpu_cap(&boot_cpu_data);
632 +- x86_configure_nx();
633 +-
634 + /* Get mfn list */
635 + xen_build_dynamic_phys_to_machine();
636 +
637 +@@ -1271,6 +1267,10 @@ asmlinkage __visible void __init xen_start_kernel(void)
638 + */
639 + xen_setup_gdt(0);
640 +
641 ++ /* Work out if we support NX */
642 ++ get_cpu_cap(&boot_cpu_data);
643 ++ x86_configure_nx();
644 ++
645 + xen_init_irq_ops();
646 +
647 + /* Let's presume PV guests always boot on vCPU with id 0. */
648 +diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
649 +index 67a860790560..d56822f58ab1 100644
650 +--- a/drivers/acpi/nfit/core.c
651 ++++ b/drivers/acpi/nfit/core.c
652 +@@ -1022,8 +1022,11 @@ static ssize_t scrub_show(struct device *dev,
653 + if (nd_desc) {
654 + struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
655 +
656 ++ mutex_lock(&acpi_desc->init_mutex);
657 + rc = sprintf(buf, "%d%s", acpi_desc->scrub_count,
658 +- (work_busy(&acpi_desc->work)) ? "+\n" : "\n");
659 ++ work_busy(&acpi_desc->work)
660 ++ && !acpi_desc->cancel ? "+\n" : "\n");
661 ++ mutex_unlock(&acpi_desc->init_mutex);
662 + }
663 + device_unlock(dev);
664 + return rc;
665 +@@ -2313,7 +2316,7 @@ static int acpi_nfit_init_mapping(struct acpi_nfit_desc *acpi_desc,
666 + struct acpi_nfit_system_address *spa = nfit_spa->spa;
667 + struct nd_blk_region_desc *ndbr_desc;
668 + struct nfit_mem *nfit_mem;
669 +- int blk_valid = 0, rc;
670 ++ int rc;
671 +
672 + if (!nvdimm) {
673 + dev_err(acpi_desc->dev, "spa%d dimm: %#x not found\n",
674 +@@ -2333,15 +2336,14 @@ static int acpi_nfit_init_mapping(struct acpi_nfit_desc *acpi_desc,
675 + if (!nfit_mem || !nfit_mem->bdw) {
676 + dev_dbg(acpi_desc->dev, "spa%d %s missing bdw\n",
677 + spa->range_index, nvdimm_name(nvdimm));
678 +- } else {
679 +- mapping->size = nfit_mem->bdw->capacity;
680 +- mapping->start = nfit_mem->bdw->start_address;
681 +- ndr_desc->num_lanes = nfit_mem->bdw->windows;
682 +- blk_valid = 1;
683 ++ break;
684 + }
685 +
686 ++ mapping->size = nfit_mem->bdw->capacity;
687 ++ mapping->start = nfit_mem->bdw->start_address;
688 ++ ndr_desc->num_lanes = nfit_mem->bdw->windows;
689 + ndr_desc->mapping = mapping;
690 +- ndr_desc->num_mappings = blk_valid;
691 ++ ndr_desc->num_mappings = 1;
692 + ndbr_desc = to_blk_region_desc(ndr_desc);
693 + ndbr_desc->enable = acpi_nfit_blk_region_enable;
694 + ndbr_desc->do_io = acpi_desc->blk_do_io;
695 +diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
696 +index 601e5d372887..43587ac680e4 100644
697 +--- a/drivers/acpi/video_detect.c
698 ++++ b/drivers/acpi/video_detect.c
699 +@@ -219,6 +219,15 @@ static const struct dmi_system_id video_detect_dmi_table[] = {
700 + "3570R/370R/470R/450R/510R/4450RV"),
701 + },
702 + },
703 ++ {
704 ++ /* https://bugzilla.redhat.com/show_bug.cgi?id=1557060 */
705 ++ .callback = video_detect_force_video,
706 ++ .ident = "SAMSUNG 670Z5E",
707 ++ .matches = {
708 ++ DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
709 ++ DMI_MATCH(DMI_PRODUCT_NAME, "670Z5E"),
710 ++ },
711 ++ },
712 + {
713 + /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */
714 + .callback = video_detect_force_video,
715 +diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
716 +index b9a779a4a739..efdadd153abe 100644
717 +--- a/drivers/base/regmap/regmap.c
718 ++++ b/drivers/base/regmap/regmap.c
719 +@@ -1739,7 +1739,7 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
720 + return -EINVAL;
721 + if (val_len % map->format.val_bytes)
722 + return -EINVAL;
723 +- if (map->max_raw_write && map->max_raw_write > val_len)
724 ++ if (map->max_raw_write && map->max_raw_write < val_len)
725 + return -E2BIG;
726 +
727 + map->lock(map->lock_arg);
728 +diff --git a/drivers/char/random.c b/drivers/char/random.c
729 +index ea0115cf5fc0..58a2ff7df392 100644
730 +--- a/drivers/char/random.c
731 ++++ b/drivers/char/random.c
732 +@@ -427,8 +427,9 @@ struct crng_state primary_crng = {
733 + * its value (from 0->1->2).
734 + */
735 + static int crng_init = 0;
736 +-#define crng_ready() (likely(crng_init > 0))
737 ++#define crng_ready() (likely(crng_init > 1))
738 + static int crng_init_cnt = 0;
739 ++static unsigned long crng_global_init_time = 0;
740 + #define CRNG_INIT_CNT_THRESH (2*CHACHA20_KEY_SIZE)
741 + static void _extract_crng(struct crng_state *crng,
742 + __u8 out[CHACHA20_BLOCK_SIZE]);
743 +@@ -732,7 +733,7 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
744 +
745 + static int credit_entropy_bits_safe(struct entropy_store *r, int nbits)
746 + {
747 +- const int nbits_max = (int)(~0U >> (ENTROPY_SHIFT + 1));
748 ++ const int nbits_max = r->poolinfo->poolwords * 32;
749 +
750 + if (nbits < 0)
751 + return -EINVAL;
752 +@@ -786,6 +787,10 @@ static void crng_initialize(struct crng_state *crng)
753 + crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
754 + }
755 +
756 ++/*
757 ++ * crng_fast_load() can be called by code in the interrupt service
758 ++ * path. So we can't afford to dilly-dally.
759 ++ */
760 + static int crng_fast_load(const char *cp, size_t len)
761 + {
762 + unsigned long flags;
763 +@@ -793,7 +798,7 @@ static int crng_fast_load(const char *cp, size_t len)
764 +
765 + if (!spin_trylock_irqsave(&primary_crng.lock, flags))
766 + return 0;
767 +- if (crng_ready()) {
768 ++ if (crng_init != 0) {
769 + spin_unlock_irqrestore(&primary_crng.lock, flags);
770 + return 0;
771 + }
772 +@@ -812,6 +817,51 @@ static int crng_fast_load(const char *cp, size_t len)
773 + return 1;
774 + }
775 +
776 ++/*
777 ++ * crng_slow_load() is called by add_device_randomness, which has two
778 ++ * attributes. (1) We can't trust the buffer passed to it is
779 ++ * guaranteed to be unpredictable (so it might not have any entropy at
780 ++ * all), and (2) it doesn't have the performance constraints of
781 ++ * crng_fast_load().
782 ++ *
783 ++ * So we do something more comprehensive which is guaranteed to touch
784 ++ * all of the primary_crng's state, and which uses a LFSR with a
785 ++ * period of 255 as part of the mixing algorithm. Finally, we do
786 ++ * *not* advance crng_init_cnt since buffer we may get may be something
787 ++ * like a fixed DMI table (for example), which might very well be
788 ++ * unique to the machine, but is otherwise unvarying.
789 ++ */
790 ++static int crng_slow_load(const char *cp, size_t len)
791 ++{
792 ++ unsigned long flags;
793 ++ static unsigned char lfsr = 1;
794 ++ unsigned char tmp;
795 ++ unsigned i, max = CHACHA20_KEY_SIZE;
796 ++ const char * src_buf = cp;
797 ++ char * dest_buf = (char *) &primary_crng.state[4];
798 ++
799 ++ if (!spin_trylock_irqsave(&primary_crng.lock, flags))
800 ++ return 0;
801 ++ if (crng_init != 0) {
802 ++ spin_unlock_irqrestore(&primary_crng.lock, flags);
803 ++ return 0;
804 ++ }
805 ++ if (len > max)
806 ++ max = len;
807 ++
808 ++ for (i = 0; i < max ; i++) {
809 ++ tmp = lfsr;
810 ++ lfsr >>= 1;
811 ++ if (tmp & 1)
812 ++ lfsr ^= 0xE1;
813 ++ tmp = dest_buf[i % CHACHA20_KEY_SIZE];
814 ++ dest_buf[i % CHACHA20_KEY_SIZE] ^= src_buf[i % len] ^ lfsr;
815 ++ lfsr += (tmp << 3) | (tmp >> 5);
816 ++ }
817 ++ spin_unlock_irqrestore(&primary_crng.lock, flags);
818 ++ return 1;
819 ++}
820 ++
821 + static void crng_reseed(struct crng_state *crng, struct entropy_store *r)
822 + {
823 + unsigned long flags;
824 +@@ -830,7 +880,7 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r)
825 + _crng_backtrack_protect(&primary_crng, buf.block,
826 + CHACHA20_KEY_SIZE);
827 + }
828 +- spin_lock_irqsave(&primary_crng.lock, flags);
829 ++ spin_lock_irqsave(&crng->lock, flags);
830 + for (i = 0; i < 8; i++) {
831 + unsigned long rv;
832 + if (!arch_get_random_seed_long(&rv) &&
833 +@@ -840,7 +890,7 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r)
834 + }
835 + memzero_explicit(&buf, sizeof(buf));
836 + crng->init_time = jiffies;
837 +- spin_unlock_irqrestore(&primary_crng.lock, flags);
838 ++ spin_unlock_irqrestore(&crng->lock, flags);
839 + if (crng == &primary_crng && crng_init < 2) {
840 + invalidate_batched_entropy();
841 + crng_init = 2;
842 +@@ -855,8 +905,9 @@ static void _extract_crng(struct crng_state *crng,
843 + {
844 + unsigned long v, flags;
845 +
846 +- if (crng_init > 1 &&
847 +- time_after(jiffies, crng->init_time + CRNG_RESEED_INTERVAL))
848 ++ if (crng_ready() &&
849 ++ (time_after(crng_global_init_time, crng->init_time) ||
850 ++ time_after(jiffies, crng->init_time + CRNG_RESEED_INTERVAL)))
851 + crng_reseed(crng, crng == &primary_crng ? &input_pool : NULL);
852 + spin_lock_irqsave(&crng->lock, flags);
853 + if (arch_get_random_long(&v))
854 +@@ -981,10 +1032,8 @@ void add_device_randomness(const void *buf, unsigned int size)
855 + unsigned long time = random_get_entropy() ^ jiffies;
856 + unsigned long flags;
857 +
858 +- if (!crng_ready()) {
859 +- crng_fast_load(buf, size);
860 +- return;
861 +- }
862 ++ if (!crng_ready() && size)
863 ++ crng_slow_load(buf, size);
864 +
865 + trace_add_device_randomness(size, _RET_IP_);
866 + spin_lock_irqsave(&input_pool.lock, flags);
867 +@@ -1141,7 +1190,7 @@ void add_interrupt_randomness(int irq, int irq_flags)
868 + fast_mix(fast_pool);
869 + add_interrupt_bench(cycles);
870 +
871 +- if (!crng_ready()) {
872 ++ if (unlikely(crng_init == 0)) {
873 + if ((fast_pool->count >= 64) &&
874 + crng_fast_load((char *) fast_pool->pool,
875 + sizeof(fast_pool->pool))) {
876 +@@ -1691,6 +1740,7 @@ static int rand_initialize(void)
877 + init_std_data(&input_pool);
878 + init_std_data(&blocking_pool);
879 + crng_initialize(&primary_crng);
880 ++ crng_global_init_time = jiffies;
881 +
882 + #ifdef CONFIG_NUMA
883 + pool = kcalloc(nr_node_ids, sizeof(*pool), GFP_KERNEL|__GFP_NOFAIL);
884 +@@ -1877,6 +1927,14 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
885 + input_pool.entropy_count = 0;
886 + blocking_pool.entropy_count = 0;
887 + return 0;
888 ++ case RNDRESEEDCRNG:
889 ++ if (!capable(CAP_SYS_ADMIN))
890 ++ return -EPERM;
891 ++ if (crng_init < 2)
892 ++ return -ENODATA;
893 ++ crng_reseed(&primary_crng, NULL);
894 ++ crng_global_init_time = jiffies - 1;
895 ++ return 0;
896 + default:
897 + return -EINVAL;
898 + }
899 +@@ -2214,7 +2272,7 @@ void add_hwgenerator_randomness(const char *buffer, size_t count,
900 + {
901 + struct entropy_store *poolp = &input_pool;
902 +
903 +- if (!crng_ready()) {
904 ++ if (unlikely(crng_init == 0)) {
905 + crng_fast_load(buffer, count);
906 + return;
907 + }
908 +diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
909 +index 0f1dc35e7078..1d01a8f77db1 100644
910 +--- a/drivers/char/tpm/tpm-interface.c
911 ++++ b/drivers/char/tpm/tpm-interface.c
912 +@@ -971,6 +971,10 @@ int tpm_do_selftest(struct tpm_chip *chip)
913 + loops = jiffies_to_msecs(duration) / delay_msec;
914 +
915 + rc = tpm_continue_selftest(chip);
916 ++ if (rc == TPM_ERR_INVALID_POSTINIT) {
917 ++ chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED;
918 ++ dev_info(&chip->dev, "TPM not ready (%d)\n", rc);
919 ++ }
920 + /* This may fail if there was no TPM driver during a suspend/resume
921 + * cycle; some may return 10 (BAD_ORDINAL), others 28 (FAILEDSELFTEST)
922 + */
923 +diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
924 +index eec52734d6ac..5f8082d89131 100644
925 +--- a/drivers/clk/bcm/clk-bcm2835.c
926 ++++ b/drivers/clk/bcm/clk-bcm2835.c
927 +@@ -632,9 +632,7 @@ static void bcm2835_pll_off(struct clk_hw *hw)
928 + const struct bcm2835_pll_data *data = pll->data;
929 +
930 + spin_lock(&cprman->regs_lock);
931 +- cprman_write(cprman, data->cm_ctrl_reg,
932 +- cprman_read(cprman, data->cm_ctrl_reg) |
933 +- CM_PLL_ANARST);
934 ++ cprman_write(cprman, data->cm_ctrl_reg, CM_PLL_ANARST);
935 + cprman_write(cprman, data->a2w_ctrl_reg,
936 + cprman_read(cprman, data->a2w_ctrl_reg) |
937 + A2W_PLL_CTRL_PWRDN);
938 +@@ -670,6 +668,10 @@ static int bcm2835_pll_on(struct clk_hw *hw)
939 + cpu_relax();
940 + }
941 +
942 ++ cprman_write(cprman, data->a2w_ctrl_reg,
943 ++ cprman_read(cprman, data->a2w_ctrl_reg) |
944 ++ A2W_PLL_CTRL_PRST_DISABLE);
945 ++
946 + return 0;
947 + }
948 +
949 +diff --git a/drivers/clk/mediatek/clk-mt2701.c b/drivers/clk/mediatek/clk-mt2701.c
950 +index 9598889f972b..ccfe5d30fe10 100644
951 +--- a/drivers/clk/mediatek/clk-mt2701.c
952 ++++ b/drivers/clk/mediatek/clk-mt2701.c
953 +@@ -148,6 +148,7 @@ static const struct mtk_fixed_factor top_fixed_divs[] = {
954 + FACTOR(CLK_TOP_CLK26M_D8, "clk26m_d8", "clk26m", 1, 8),
955 + FACTOR(CLK_TOP_32K_INTERNAL, "32k_internal", "clk26m", 1, 793),
956 + FACTOR(CLK_TOP_32K_EXTERNAL, "32k_external", "rtc32k", 1, 1),
957 ++ FACTOR(CLK_TOP_AXISEL_D4, "axisel_d4", "axi_sel", 1, 4),
958 + };
959 +
960 + static const char * const axi_parents[] = {
961 +@@ -857,13 +858,13 @@ static const struct mtk_gate peri_clks[] = {
962 + GATE_PERI0(CLK_PERI_USB1, "usb1_ck", "usb20_sel", 11),
963 + GATE_PERI0(CLK_PERI_USB0, "usb0_ck", "usb20_sel", 10),
964 + GATE_PERI0(CLK_PERI_PWM, "pwm_ck", "axi_sel", 9),
965 +- GATE_PERI0(CLK_PERI_PWM7, "pwm7_ck", "axi_sel", 8),
966 +- GATE_PERI0(CLK_PERI_PWM6, "pwm6_ck", "axi_sel", 7),
967 +- GATE_PERI0(CLK_PERI_PWM5, "pwm5_ck", "axi_sel", 6),
968 +- GATE_PERI0(CLK_PERI_PWM4, "pwm4_ck", "axi_sel", 5),
969 +- GATE_PERI0(CLK_PERI_PWM3, "pwm3_ck", "axi_sel", 4),
970 +- GATE_PERI0(CLK_PERI_PWM2, "pwm2_ck", "axi_sel", 3),
971 +- GATE_PERI0(CLK_PERI_PWM1, "pwm1_ck", "axi_sel", 2),
972 ++ GATE_PERI0(CLK_PERI_PWM7, "pwm7_ck", "axisel_d4", 8),
973 ++ GATE_PERI0(CLK_PERI_PWM6, "pwm6_ck", "axisel_d4", 7),
974 ++ GATE_PERI0(CLK_PERI_PWM5, "pwm5_ck", "axisel_d4", 6),
975 ++ GATE_PERI0(CLK_PERI_PWM4, "pwm4_ck", "axisel_d4", 5),
976 ++ GATE_PERI0(CLK_PERI_PWM3, "pwm3_ck", "axisel_d4", 4),
977 ++ GATE_PERI0(CLK_PERI_PWM2, "pwm2_ck", "axisel_d4", 3),
978 ++ GATE_PERI0(CLK_PERI_PWM1, "pwm1_ck", "axisel_d4", 2),
979 + GATE_PERI0(CLK_PERI_THERM, "therm_ck", "axi_sel", 1),
980 + GATE_PERI0(CLK_PERI_NFI, "nfi_ck", "nfi2x_sel", 0),
981 +
982 +diff --git a/drivers/clk/mvebu/armada-38x.c b/drivers/clk/mvebu/armada-38x.c
983 +index 394aa6f03f01..9ff4ea63932d 100644
984 +--- a/drivers/clk/mvebu/armada-38x.c
985 ++++ b/drivers/clk/mvebu/armada-38x.c
986 +@@ -46,11 +46,11 @@ static u32 __init armada_38x_get_tclk_freq(void __iomem *sar)
987 + }
988 +
989 + static const u32 armada_38x_cpu_frequencies[] __initconst = {
990 +- 0, 0, 0, 0,
991 +- 1066 * 1000 * 1000, 0, 0, 0,
992 ++ 666 * 1000 * 1000, 0, 800 * 1000 * 1000, 0,
993 ++ 1066 * 1000 * 1000, 0, 1200 * 1000 * 1000, 0,
994 + 1332 * 1000 * 1000, 0, 0, 0,
995 + 1600 * 1000 * 1000, 0, 0, 0,
996 +- 1866 * 1000 * 1000,
997 ++ 1866 * 1000 * 1000, 0, 0, 2000 * 1000 * 1000,
998 + };
999 +
1000 + static u32 __init armada_38x_get_cpu_freq(void __iomem *sar)
1001 +@@ -76,11 +76,11 @@ static const struct coreclk_ratio armada_38x_coreclk_ratios[] __initconst = {
1002 + };
1003 +
1004 + static const int armada_38x_cpu_l2_ratios[32][2] __initconst = {
1005 +- {0, 1}, {0, 1}, {0, 1}, {0, 1},
1006 +- {1, 2}, {0, 1}, {0, 1}, {0, 1},
1007 +- {1, 2}, {0, 1}, {0, 1}, {0, 1},
1008 ++ {1, 2}, {0, 1}, {1, 2}, {0, 1},
1009 ++ {1, 2}, {0, 1}, {1, 2}, {0, 1},
1010 + {1, 2}, {0, 1}, {0, 1}, {0, 1},
1011 + {1, 2}, {0, 1}, {0, 1}, {0, 1},
1012 ++ {1, 2}, {0, 1}, {0, 1}, {1, 2},
1013 + {0, 1}, {0, 1}, {0, 1}, {0, 1},
1014 + {0, 1}, {0, 1}, {0, 1}, {0, 1},
1015 + {0, 1}, {0, 1}, {0, 1}, {0, 1},
1016 +@@ -91,7 +91,7 @@ static const int armada_38x_cpu_ddr_ratios[32][2] __initconst = {
1017 + {1, 2}, {0, 1}, {0, 1}, {0, 1},
1018 + {1, 2}, {0, 1}, {0, 1}, {0, 1},
1019 + {1, 2}, {0, 1}, {0, 1}, {0, 1},
1020 +- {1, 2}, {0, 1}, {0, 1}, {0, 1},
1021 ++ {1, 2}, {0, 1}, {0, 1}, {7, 15},
1022 + {0, 1}, {0, 1}, {0, 1}, {0, 1},
1023 + {0, 1}, {0, 1}, {0, 1}, {0, 1},
1024 + {0, 1}, {0, 1}, {0, 1}, {0, 1},
1025 +diff --git a/drivers/clk/renesas/clk-sh73a0.c b/drivers/clk/renesas/clk-sh73a0.c
1026 +index eea38f6ea77e..3892346c4fcc 100644
1027 +--- a/drivers/clk/renesas/clk-sh73a0.c
1028 ++++ b/drivers/clk/renesas/clk-sh73a0.c
1029 +@@ -46,7 +46,7 @@ struct div4_clk {
1030 + unsigned int shift;
1031 + };
1032 +
1033 +-static struct div4_clk div4_clks[] = {
1034 ++static const struct div4_clk div4_clks[] = {
1035 + { "zg", "pll0", CPG_FRQCRA, 16 },
1036 + { "m3", "pll1", CPG_FRQCRA, 12 },
1037 + { "b", "pll1", CPG_FRQCRA, 8 },
1038 +@@ -79,7 +79,7 @@ sh73a0_cpg_register_clock(struct device_node *np, struct sh73a0_cpg *cpg,
1039 + {
1040 + const struct clk_div_table *table = NULL;
1041 + unsigned int shift, reg, width;
1042 +- const char *parent_name;
1043 ++ const char *parent_name = NULL;
1044 + unsigned int mult = 1;
1045 + unsigned int div = 1;
1046 +
1047 +@@ -135,7 +135,7 @@ sh73a0_cpg_register_clock(struct device_node *np, struct sh73a0_cpg *cpg,
1048 + shift = 24;
1049 + width = 5;
1050 + } else {
1051 +- struct div4_clk *c;
1052 ++ const struct div4_clk *c;
1053 +
1054 + for (c = div4_clks; c->name; c++) {
1055 + if (!strcmp(name, c->name)) {
1056 +diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
1057 +index a1c3025f9df7..dcb1cb9a4572 100644
1058 +--- a/drivers/cpufreq/cppc_cpufreq.c
1059 ++++ b/drivers/cpufreq/cppc_cpufreq.c
1060 +@@ -20,6 +20,7 @@
1061 + #include <linux/cpu.h>
1062 + #include <linux/cpufreq.h>
1063 + #include <linux/dmi.h>
1064 ++#include <linux/time.h>
1065 + #include <linux/vmalloc.h>
1066 +
1067 + #include <asm/unaligned.h>
1068 +@@ -162,6 +163,8 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
1069 + policy->cpuinfo.max_freq = cppc_dmi_max_khz;
1070 +
1071 + policy->cpuinfo.transition_latency = cppc_get_transition_latency(cpu_num);
1072 ++ policy->transition_delay_us = cppc_get_transition_latency(cpu_num) /
1073 ++ NSEC_PER_USEC;
1074 + policy->shared_type = cpu->shared_type;
1075 +
1076 + if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY)
1077 +diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c
1078 +index c00e3923d7d8..94236ec9d410 100644
1079 +--- a/drivers/dma/at_xdmac.c
1080 ++++ b/drivers/dma/at_xdmac.c
1081 +@@ -1471,10 +1471,10 @@ at_xdmac_tx_status(struct dma_chan *chan, dma_cookie_t cookie,
1082 + for (retry = 0; retry < AT_XDMAC_RESIDUE_MAX_RETRIES; retry++) {
1083 + check_nda = at_xdmac_chan_read(atchan, AT_XDMAC_CNDA) & 0xfffffffc;
1084 + rmb();
1085 +- initd = !!(at_xdmac_chan_read(atchan, AT_XDMAC_CC) & AT_XDMAC_CC_INITD);
1086 +- rmb();
1087 + cur_ubc = at_xdmac_chan_read(atchan, AT_XDMAC_CUBC);
1088 + rmb();
1089 ++ initd = !!(at_xdmac_chan_read(atchan, AT_XDMAC_CC) & AT_XDMAC_CC_INITD);
1090 ++ rmb();
1091 + cur_nda = at_xdmac_chan_read(atchan, AT_XDMAC_CNDA) & 0xfffffffc;
1092 + rmb();
1093 +
1094 +diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c
1095 +index 91a0023074af..60baaf693103 100644
1096 +--- a/drivers/extcon/extcon-intel-cht-wc.c
1097 ++++ b/drivers/extcon/extcon-intel-cht-wc.c
1098 +@@ -66,6 +66,8 @@
1099 +
1100 + #define CHT_WC_VBUS_GPIO_CTLO 0x6e2d
1101 + #define CHT_WC_VBUS_GPIO_CTLO_OUTPUT BIT(0)
1102 ++#define CHT_WC_VBUS_GPIO_CTLO_DRV_OD BIT(4)
1103 ++#define CHT_WC_VBUS_GPIO_CTLO_DIR_OUT BIT(5)
1104 +
1105 + enum cht_wc_usb_id {
1106 + USB_ID_OTG,
1107 +@@ -183,14 +185,15 @@ static void cht_wc_extcon_set_5v_boost(struct cht_wc_extcon_data *ext,
1108 + {
1109 + int ret, val;
1110 +
1111 +- val = enable ? CHT_WC_VBUS_GPIO_CTLO_OUTPUT : 0;
1112 +-
1113 + /*
1114 + * The 5V boost converter is enabled through a gpio on the PMIC, since
1115 + * there currently is no gpio driver we access the gpio reg directly.
1116 + */
1117 +- ret = regmap_update_bits(ext->regmap, CHT_WC_VBUS_GPIO_CTLO,
1118 +- CHT_WC_VBUS_GPIO_CTLO_OUTPUT, val);
1119 ++ val = CHT_WC_VBUS_GPIO_CTLO_DRV_OD | CHT_WC_VBUS_GPIO_CTLO_DIR_OUT;
1120 ++ if (enable)
1121 ++ val |= CHT_WC_VBUS_GPIO_CTLO_OUTPUT;
1122 ++
1123 ++ ret = regmap_write(ext->regmap, CHT_WC_VBUS_GPIO_CTLO, val);
1124 + if (ret)
1125 + dev_err(ext->dev, "Error writing Vbus GPIO CTLO: %d\n", ret);
1126 + }
1127 +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
1128 +index c53095b3b0fb..1ae5ae8c45a4 100644
1129 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
1130 ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
1131 +@@ -569,6 +569,7 @@ static const struct amdgpu_px_quirk amdgpu_px_quirk_list[] = {
1132 + { 0x1002, 0x6900, 0x1002, 0x0124, AMDGPU_PX_QUIRK_FORCE_ATPX },
1133 + { 0x1002, 0x6900, 0x1028, 0x0812, AMDGPU_PX_QUIRK_FORCE_ATPX },
1134 + { 0x1002, 0x6900, 0x1028, 0x0813, AMDGPU_PX_QUIRK_FORCE_ATPX },
1135 ++ { 0x1002, 0x67DF, 0x1028, 0x0774, AMDGPU_PX_QUIRK_FORCE_ATPX },
1136 + { 0, 0, 0, 0, 0 },
1137 + };
1138 +
1139 +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
1140 +index 59089e027f4d..92be7f6de197 100644
1141 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
1142 ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
1143 +@@ -233,8 +233,10 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1144 + for (i = 0; i < list->num_entries; i++) {
1145 + unsigned priority = list->array[i].priority;
1146 +
1147 +- list_add_tail(&list->array[i].tv.head,
1148 +- &bucket[priority]);
1149 ++ if (!list->array[i].robj->parent)
1150 ++ list_add_tail(&list->array[i].tv.head,
1151 ++ &bucket[priority]);
1152 ++
1153 + list->array[i].user_pages = NULL;
1154 + }
1155 +
1156 +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
1157 +index b5aa8e6f8e0b..5f892ad6476e 100644
1158 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
1159 ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
1160 +@@ -522,7 +522,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
1161 + INIT_LIST_HEAD(&duplicates);
1162 + amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
1163 +
1164 +- if (p->uf_entry.robj)
1165 ++ if (p->uf_entry.robj && !p->uf_entry.robj->parent)
1166 + list_add(&p->uf_entry.tv.head, &p->validated);
1167 +
1168 + if (need_mmap_lock)
1169 +diff --git a/drivers/gpu/drm/amd/amdgpu/cik_sdma.c b/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
1170 +index f508f4d01e4a..11beef7c595f 100644
1171 +--- a/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
1172 ++++ b/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
1173 +@@ -866,7 +866,7 @@ static void cik_sdma_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1174 + amdgpu_ring_write(ring, addr & 0xfffffffc);
1175 + amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
1176 + amdgpu_ring_write(ring, seq); /* reference */
1177 +- amdgpu_ring_write(ring, 0xfffffff); /* mask */
1178 ++ amdgpu_ring_write(ring, 0xffffffff); /* mask */
1179 + amdgpu_ring_write(ring, (0xfff << 16) | 4); /* retry count, poll interval */
1180 + }
1181 +
1182 +diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c b/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
1183 +index f2d0710258cb..9928473234a6 100644
1184 +--- a/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
1185 ++++ b/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
1186 +@@ -856,7 +856,7 @@ static void sdma_v2_4_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1187 + amdgpu_ring_write(ring, addr & 0xfffffffc);
1188 + amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
1189 + amdgpu_ring_write(ring, seq); /* reference */
1190 +- amdgpu_ring_write(ring, 0xfffffff); /* mask */
1191 ++ amdgpu_ring_write(ring, 0xffffffff); /* mask */
1192 + amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
1193 + SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(4)); /* retry count, poll interval */
1194 + }
1195 +diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
1196 +index b1de44f22824..f5db1fad3f05 100644
1197 +--- a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
1198 ++++ b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
1199 +@@ -1099,7 +1099,7 @@ static void sdma_v3_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1200 + amdgpu_ring_write(ring, addr & 0xfffffffc);
1201 + amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
1202 + amdgpu_ring_write(ring, seq); /* reference */
1203 +- amdgpu_ring_write(ring, 0xfffffff); /* mask */
1204 ++ amdgpu_ring_write(ring, 0xffffffff); /* mask */
1205 + amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
1206 + SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(4)); /* retry count, poll interval */
1207 + }
1208 +diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
1209 +index fd7c72aaafa6..4e5fed7c66bf 100644
1210 +--- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
1211 ++++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
1212 +@@ -1136,7 +1136,7 @@ static void sdma_v4_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1213 + amdgpu_ring_write(ring, addr & 0xfffffffc);
1214 + amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
1215 + amdgpu_ring_write(ring, seq); /* reference */
1216 +- amdgpu_ring_write(ring, 0xfffffff); /* mask */
1217 ++ amdgpu_ring_write(ring, 0xffffffff); /* mask */
1218 + amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
1219 + SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(4)); /* retry count, poll interval */
1220 + }
1221 +diff --git a/drivers/gpu/drm/amd/amdgpu/si.c b/drivers/gpu/drm/amd/amdgpu/si.c
1222 +index 4c178feeb4bd..40520a968eac 100644
1223 +--- a/drivers/gpu/drm/amd/amdgpu/si.c
1224 ++++ b/drivers/gpu/drm/amd/amdgpu/si.c
1225 +@@ -1231,6 +1231,71 @@ static void si_detect_hw_virtualization(struct amdgpu_device *adev)
1226 + adev->virt.caps |= AMDGPU_PASSTHROUGH_MODE;
1227 + }
1228 +
1229 ++static int si_get_pcie_lanes(struct amdgpu_device *adev)
1230 ++{
1231 ++ u32 link_width_cntl;
1232 ++
1233 ++ if (adev->flags & AMD_IS_APU)
1234 ++ return 0;
1235 ++
1236 ++ link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
1237 ++
1238 ++ switch ((link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT) {
1239 ++ case LC_LINK_WIDTH_X1:
1240 ++ return 1;
1241 ++ case LC_LINK_WIDTH_X2:
1242 ++ return 2;
1243 ++ case LC_LINK_WIDTH_X4:
1244 ++ return 4;
1245 ++ case LC_LINK_WIDTH_X8:
1246 ++ return 8;
1247 ++ case LC_LINK_WIDTH_X0:
1248 ++ case LC_LINK_WIDTH_X16:
1249 ++ default:
1250 ++ return 16;
1251 ++ }
1252 ++}
1253 ++
1254 ++static void si_set_pcie_lanes(struct amdgpu_device *adev, int lanes)
1255 ++{
1256 ++ u32 link_width_cntl, mask;
1257 ++
1258 ++ if (adev->flags & AMD_IS_APU)
1259 ++ return;
1260 ++
1261 ++ switch (lanes) {
1262 ++ case 0:
1263 ++ mask = LC_LINK_WIDTH_X0;
1264 ++ break;
1265 ++ case 1:
1266 ++ mask = LC_LINK_WIDTH_X1;
1267 ++ break;
1268 ++ case 2:
1269 ++ mask = LC_LINK_WIDTH_X2;
1270 ++ break;
1271 ++ case 4:
1272 ++ mask = LC_LINK_WIDTH_X4;
1273 ++ break;
1274 ++ case 8:
1275 ++ mask = LC_LINK_WIDTH_X8;
1276 ++ break;
1277 ++ case 16:
1278 ++ mask = LC_LINK_WIDTH_X16;
1279 ++ break;
1280 ++ default:
1281 ++ DRM_ERROR("invalid pcie lane request: %d\n", lanes);
1282 ++ return;
1283 ++ }
1284 ++
1285 ++ link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
1286 ++ link_width_cntl &= ~LC_LINK_WIDTH_MASK;
1287 ++ link_width_cntl |= mask << LC_LINK_WIDTH_SHIFT;
1288 ++ link_width_cntl |= (LC_RECONFIG_NOW |
1289 ++ LC_RECONFIG_ARC_MISSING_ESCAPE);
1290 ++
1291 ++ WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
1292 ++}
1293 ++
1294 + static const struct amdgpu_asic_funcs si_asic_funcs =
1295 + {
1296 + .read_disabled_bios = &si_read_disabled_bios,
1297 +@@ -1241,6 +1306,8 @@ static const struct amdgpu_asic_funcs si_asic_funcs =
1298 + .get_xclk = &si_get_xclk,
1299 + .set_uvd_clocks = &si_set_uvd_clocks,
1300 + .set_vce_clocks = NULL,
1301 ++ .get_pcie_lanes = &si_get_pcie_lanes,
1302 ++ .set_pcie_lanes = &si_set_pcie_lanes,
1303 + .get_config_memsize = &si_get_config_memsize,
1304 + };
1305 +
1306 +diff --git a/drivers/gpu/drm/amd/amdgpu/si_dpm.c b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
1307 +index abb0a2341a41..6f1dea157a77 100644
1308 +--- a/drivers/gpu/drm/amd/amdgpu/si_dpm.c
1309 ++++ b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
1310 +@@ -6374,9 +6374,9 @@ static void si_set_pcie_lane_width_in_smc(struct amdgpu_device *adev,
1311 + {
1312 + u32 lane_width;
1313 + u32 new_lane_width =
1314 +- (amdgpu_new_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT;
1315 ++ ((amdgpu_new_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
1316 + u32 current_lane_width =
1317 +- (amdgpu_current_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT;
1318 ++ ((amdgpu_current_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
1319 +
1320 + if (new_lane_width != current_lane_width) {
1321 + amdgpu_set_pcie_lanes(adev, new_lane_width);
1322 +diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
1323 +index 920c8914cec1..cc70e2470272 100644
1324 +--- a/drivers/gpu/drm/i915/i915_reg.h
1325 ++++ b/drivers/gpu/drm/i915/i915_reg.h
1326 +@@ -6159,6 +6159,12 @@ enum {
1327 + #define _SPATILEOFF (VLV_DISPLAY_BASE + 0x721a4)
1328 + #define _SPACONSTALPHA (VLV_DISPLAY_BASE + 0x721a8)
1329 + #define SP_CONST_ALPHA_ENABLE (1<<31)
1330 ++#define _SPACLRC0 (VLV_DISPLAY_BASE + 0x721d0)
1331 ++#define SP_CONTRAST(x) ((x) << 18) /* u3.6 */
1332 ++#define SP_BRIGHTNESS(x) ((x) & 0xff) /* s8 */
1333 ++#define _SPACLRC1 (VLV_DISPLAY_BASE + 0x721d4)
1334 ++#define SP_SH_SIN(x) (((x) & 0x7ff) << 16) /* s4.7 */
1335 ++#define SP_SH_COS(x) (x) /* u3.7 */
1336 + #define _SPAGAMC (VLV_DISPLAY_BASE + 0x721f4)
1337 +
1338 + #define _SPBCNTR (VLV_DISPLAY_BASE + 0x72280)
1339 +@@ -6172,6 +6178,8 @@ enum {
1340 + #define _SPBKEYMAXVAL (VLV_DISPLAY_BASE + 0x722a0)
1341 + #define _SPBTILEOFF (VLV_DISPLAY_BASE + 0x722a4)
1342 + #define _SPBCONSTALPHA (VLV_DISPLAY_BASE + 0x722a8)
1343 ++#define _SPBCLRC0 (VLV_DISPLAY_BASE + 0x722d0)
1344 ++#define _SPBCLRC1 (VLV_DISPLAY_BASE + 0x722d4)
1345 + #define _SPBGAMC (VLV_DISPLAY_BASE + 0x722f4)
1346 +
1347 + #define _MMIO_VLV_SPR(pipe, plane_id, reg_a, reg_b) \
1348 +@@ -6188,6 +6196,8 @@ enum {
1349 + #define SPKEYMAXVAL(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPAKEYMAXVAL, _SPBKEYMAXVAL)
1350 + #define SPTILEOFF(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPATILEOFF, _SPBTILEOFF)
1351 + #define SPCONSTALPHA(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPACONSTALPHA, _SPBCONSTALPHA)
1352 ++#define SPCLRC0(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPACLRC0, _SPBCLRC0)
1353 ++#define SPCLRC1(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPACLRC1, _SPBCLRC1)
1354 + #define SPGAMC(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPAGAMC, _SPBGAMC)
1355 +
1356 + /*
1357 +diff --git a/drivers/gpu/drm/i915/intel_sprite.c b/drivers/gpu/drm/i915/intel_sprite.c
1358 +index f8ebeb5ffb96..41e31a454604 100644
1359 +--- a/drivers/gpu/drm/i915/intel_sprite.c
1360 ++++ b/drivers/gpu/drm/i915/intel_sprite.c
1361 +@@ -345,44 +345,87 @@ skl_plane_get_hw_state(struct intel_plane *plane)
1362 + }
1363 +
1364 + static void
1365 +-chv_update_csc(struct intel_plane *plane, uint32_t format)
1366 ++chv_update_csc(const struct intel_plane_state *plane_state)
1367 + {
1368 ++ struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1369 + struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1370 ++ const struct drm_framebuffer *fb = plane_state->base.fb;
1371 + enum plane_id plane_id = plane->id;
1372 +
1373 + /* Seems RGB data bypasses the CSC always */
1374 +- if (!format_is_yuv(format))
1375 ++ if (!format_is_yuv(fb->format->format))
1376 + return;
1377 +
1378 + /*
1379 +- * BT.601 limited range YCbCr -> full range RGB
1380 ++ * BT.601 full range YCbCr -> full range RGB
1381 + *
1382 +- * |r| | 6537 4769 0| |cr |
1383 +- * |g| = |-3330 4769 -1605| x |y-64|
1384 +- * |b| | 0 4769 8263| |cb |
1385 ++ * |r| | 5743 4096 0| |cr|
1386 ++ * |g| = |-2925 4096 -1410| x |y |
1387 ++ * |b| | 0 4096 7258| |cb|
1388 + *
1389 +- * Cb and Cr apparently come in as signed already, so no
1390 +- * need for any offset. For Y we need to remove the offset.
1391 ++ * Cb and Cr apparently come in as signed already,
1392 ++ * and we get full range data in on account of CLRC0/1
1393 + */
1394 +- I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
1395 ++ I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
1396 + I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
1397 + I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
1398 +
1399 +- I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(4769) | SPCSC_C0(6537));
1400 +- I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(-3330) | SPCSC_C0(0));
1401 +- I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(-1605) | SPCSC_C0(4769));
1402 +- I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(4769) | SPCSC_C0(0));
1403 +- I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(8263));
1404 ++ I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(4096) | SPCSC_C0(5743));
1405 ++ I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(-2925) | SPCSC_C0(0));
1406 ++ I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(-1410) | SPCSC_C0(4096));
1407 ++ I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(4096) | SPCSC_C0(0));
1408 ++ I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(7258));
1409 +
1410 +- I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(940) | SPCSC_IMIN(64));
1411 +- I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
1412 +- I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
1413 ++ I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(1023) | SPCSC_IMIN(0));
1414 ++ I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
1415 ++ I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
1416 +
1417 + I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
1418 + I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
1419 + I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
1420 + }
1421 +
1422 ++#define SIN_0 0
1423 ++#define COS_0 1
1424 ++
1425 ++static void
1426 ++vlv_update_clrc(const struct intel_plane_state *plane_state)
1427 ++{
1428 ++ struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1429 ++ struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1430 ++ const struct drm_framebuffer *fb = plane_state->base.fb;
1431 ++ enum pipe pipe = plane->pipe;
1432 ++ enum plane_id plane_id = plane->id;
1433 ++ int contrast, brightness, sh_scale, sh_sin, sh_cos;
1434 ++
1435 ++ if (format_is_yuv(fb->format->format)) {
1436 ++ /*
1437 ++ * Expand limited range to full range:
1438 ++ * Contrast is applied first and is used to expand Y range.
1439 ++ * Brightness is applied second and is used to remove the
1440 ++ * offset from Y. Saturation/hue is used to expand CbCr range.
1441 ++ */
1442 ++ contrast = DIV_ROUND_CLOSEST(255 << 6, 235 - 16);
1443 ++ brightness = -DIV_ROUND_CLOSEST(16 * 255, 235 - 16);
1444 ++ sh_scale = DIV_ROUND_CLOSEST(128 << 7, 240 - 128);
1445 ++ sh_sin = SIN_0 * sh_scale;
1446 ++ sh_cos = COS_0 * sh_scale;
1447 ++ } else {
1448 ++ /* Pass-through everything. */
1449 ++ contrast = 1 << 6;
1450 ++ brightness = 0;
1451 ++ sh_scale = 1 << 7;
1452 ++ sh_sin = SIN_0 * sh_scale;
1453 ++ sh_cos = COS_0 * sh_scale;
1454 ++ }
1455 ++
1456 ++ /* FIXME these register are single buffered :( */
1457 ++ I915_WRITE_FW(SPCLRC0(pipe, plane_id),
1458 ++ SP_CONTRAST(contrast) | SP_BRIGHTNESS(brightness));
1459 ++ I915_WRITE_FW(SPCLRC1(pipe, plane_id),
1460 ++ SP_SH_SIN(sh_sin) | SP_SH_COS(sh_cos));
1461 ++}
1462 ++
1463 + static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
1464 + const struct intel_plane_state *plane_state)
1465 + {
1466 +@@ -476,8 +519,10 @@ vlv_update_plane(struct intel_plane *plane,
1467 +
1468 + spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1469 +
1470 ++ vlv_update_clrc(plane_state);
1471 ++
1472 + if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
1473 +- chv_update_csc(plane, fb->format->format);
1474 ++ chv_update_csc(plane_state);
1475 +
1476 + if (key->flags) {
1477 + I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
1478 +diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
1479 +index 32b577c776b9..58488eac8462 100644
1480 +--- a/drivers/gpu/drm/radeon/radeon_device.c
1481 ++++ b/drivers/gpu/drm/radeon/radeon_device.c
1482 +@@ -139,6 +139,10 @@ static struct radeon_px_quirk radeon_px_quirk_list[] = {
1483 + * https://bugs.freedesktop.org/show_bug.cgi?id=101491
1484 + */
1485 + { PCI_VENDOR_ID_ATI, 0x6741, 0x1043, 0x2122, RADEON_PX_QUIRK_DISABLE_PX },
1486 ++ /* Asus K73TK laptop with AMD A6-3420M APU and Radeon 7670m GPU
1487 ++ * https://bugzilla.kernel.org/show_bug.cgi?id=51381#c52
1488 ++ */
1489 ++ { PCI_VENDOR_ID_ATI, 0x6840, 0x1043, 0x2123, RADEON_PX_QUIRK_DISABLE_PX },
1490 + { 0, 0, 0, 0, 0 },
1491 + };
1492 +
1493 +diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c
1494 +index 97a0a639dad9..90d5b41007bf 100644
1495 +--- a/drivers/gpu/drm/radeon/si_dpm.c
1496 ++++ b/drivers/gpu/drm/radeon/si_dpm.c
1497 +@@ -5912,9 +5912,9 @@ static void si_set_pcie_lane_width_in_smc(struct radeon_device *rdev,
1498 + {
1499 + u32 lane_width;
1500 + u32 new_lane_width =
1501 +- (radeon_new_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT;
1502 ++ ((radeon_new_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
1503 + u32 current_lane_width =
1504 +- (radeon_current_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT;
1505 ++ ((radeon_current_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
1506 +
1507 + if (new_lane_width != current_lane_width) {
1508 + radeon_set_pcie_lanes(rdev, new_lane_width);
1509 +diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
1510 +index bf9ed0e63973..f1fa8d5c9b52 100644
1511 +--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
1512 ++++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
1513 +@@ -1413,6 +1413,9 @@ static int vop_initial(struct vop *vop)
1514 + usleep_range(10, 20);
1515 + reset_control_deassert(ahb_rst);
1516 +
1517 ++ VOP_INTR_SET_TYPE(vop, clear, INTR_MASK, 1);
1518 ++ VOP_INTR_SET_TYPE(vop, enable, INTR_MASK, 0);
1519 ++
1520 + memcpy(vop->regsbak, vop->regs, vop->len);
1521 +
1522 + VOP_REG_SET(vop, misc, global_regdone_en, 1);
1523 +@@ -1568,17 +1571,9 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
1524 +
1525 + mutex_init(&vop->vsync_mutex);
1526 +
1527 +- ret = devm_request_irq(dev, vop->irq, vop_isr,
1528 +- IRQF_SHARED, dev_name(dev), vop);
1529 +- if (ret)
1530 +- return ret;
1531 +-
1532 +- /* IRQ is initially disabled; it gets enabled in power_on */
1533 +- disable_irq(vop->irq);
1534 +-
1535 + ret = vop_create_crtc(vop);
1536 + if (ret)
1537 +- goto err_enable_irq;
1538 ++ return ret;
1539 +
1540 + pm_runtime_enable(&pdev->dev);
1541 +
1542 +@@ -1588,13 +1583,19 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
1543 + goto err_disable_pm_runtime;
1544 + }
1545 +
1546 ++ ret = devm_request_irq(dev, vop->irq, vop_isr,
1547 ++ IRQF_SHARED, dev_name(dev), vop);
1548 ++ if (ret)
1549 ++ goto err_disable_pm_runtime;
1550 ++
1551 ++ /* IRQ is initially disabled; it gets enabled in power_on */
1552 ++ disable_irq(vop->irq);
1553 ++
1554 + return 0;
1555 +
1556 + err_disable_pm_runtime:
1557 + pm_runtime_disable(&pdev->dev);
1558 + vop_destroy_crtc(vop);
1559 +-err_enable_irq:
1560 +- enable_irq(vop->irq); /* To balance out the disable_irq above */
1561 + return ret;
1562 + }
1563 +
1564 +diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
1565 +index ca2fbe56635a..672b0be41d44 100644
1566 +--- a/drivers/hid/hid-core.c
1567 ++++ b/drivers/hid/hid-core.c
1568 +@@ -1390,7 +1390,7 @@ u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags)
1569 + * of implement() working on 8 byte chunks
1570 + */
1571 +
1572 +- int len = hid_report_len(report) + 7;
1573 ++ u32 len = hid_report_len(report) + 7;
1574 +
1575 + return kmalloc(len, flags);
1576 + }
1577 +@@ -1455,7 +1455,7 @@ void __hid_request(struct hid_device *hid, struct hid_report *report,
1578 + {
1579 + char *buf;
1580 + int ret;
1581 +- int len;
1582 ++ u32 len;
1583 +
1584 + buf = hid_alloc_report_buf(report, GFP_KERNEL);
1585 + if (!buf)
1586 +@@ -1481,14 +1481,14 @@ void __hid_request(struct hid_device *hid, struct hid_report *report,
1587 + }
1588 + EXPORT_SYMBOL_GPL(__hid_request);
1589 +
1590 +-int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
1591 ++int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size,
1592 + int interrupt)
1593 + {
1594 + struct hid_report_enum *report_enum = hid->report_enum + type;
1595 + struct hid_report *report;
1596 + struct hid_driver *hdrv;
1597 + unsigned int a;
1598 +- int rsize, csize = size;
1599 ++ u32 rsize, csize = size;
1600 + u8 *cdata = data;
1601 + int ret = 0;
1602 +
1603 +@@ -1546,7 +1546,7 @@ EXPORT_SYMBOL_GPL(hid_report_raw_event);
1604 + *
1605 + * This is data entry for lower layers.
1606 + */
1607 +-int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
1608 ++int hid_input_report(struct hid_device *hid, int type, u8 *data, u32 size, int interrupt)
1609 + {
1610 + struct hid_report_enum *report_enum;
1611 + struct hid_driver *hdrv;
1612 +diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
1613 +index 199f6a01fc62..bb984cc9753b 100644
1614 +--- a/drivers/hid/hid-input.c
1615 ++++ b/drivers/hid/hid-input.c
1616 +@@ -387,7 +387,8 @@ static int hidinput_get_battery_property(struct power_supply *psy,
1617 + break;
1618 +
1619 + case POWER_SUPPLY_PROP_CAPACITY:
1620 +- if (dev->battery_report_type == HID_FEATURE_REPORT) {
1621 ++ if (dev->battery_status != HID_BATTERY_REPORTED &&
1622 ++ !dev->battery_avoid_query) {
1623 + value = hidinput_query_battery_capacity(dev);
1624 + if (value < 0)
1625 + return value;
1626 +@@ -403,17 +404,17 @@ static int hidinput_get_battery_property(struct power_supply *psy,
1627 + break;
1628 +
1629 + case POWER_SUPPLY_PROP_STATUS:
1630 +- if (!dev->battery_reported &&
1631 +- dev->battery_report_type == HID_FEATURE_REPORT) {
1632 ++ if (dev->battery_status != HID_BATTERY_REPORTED &&
1633 ++ !dev->battery_avoid_query) {
1634 + value = hidinput_query_battery_capacity(dev);
1635 + if (value < 0)
1636 + return value;
1637 +
1638 + dev->battery_capacity = value;
1639 +- dev->battery_reported = true;
1640 ++ dev->battery_status = HID_BATTERY_QUERIED;
1641 + }
1642 +
1643 +- if (!dev->battery_reported)
1644 ++ if (dev->battery_status == HID_BATTERY_UNKNOWN)
1645 + val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
1646 + else if (dev->battery_capacity == 100)
1647 + val->intval = POWER_SUPPLY_STATUS_FULL;
1648 +@@ -486,6 +487,14 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
1649 + dev->battery_report_type = report_type;
1650 + dev->battery_report_id = field->report->id;
1651 +
1652 ++ /*
1653 ++ * Stylus is normally not connected to the device and thus we
1654 ++ * can't query the device and get meaningful battery strength.
1655 ++ * We have to wait for the device to report it on its own.
1656 ++ */
1657 ++ dev->battery_avoid_query = report_type == HID_INPUT_REPORT &&
1658 ++ field->physical == HID_DG_STYLUS;
1659 ++
1660 + dev->battery = power_supply_register(&dev->dev, psy_desc, &psy_cfg);
1661 + if (IS_ERR(dev->battery)) {
1662 + error = PTR_ERR(dev->battery);
1663 +@@ -530,9 +539,10 @@ static void hidinput_update_battery(struct hid_device *dev, int value)
1664 +
1665 + capacity = hidinput_scale_battery_capacity(dev, value);
1666 +
1667 +- if (!dev->battery_reported || capacity != dev->battery_capacity) {
1668 ++ if (dev->battery_status != HID_BATTERY_REPORTED ||
1669 ++ capacity != dev->battery_capacity) {
1670 + dev->battery_capacity = capacity;
1671 +- dev->battery_reported = true;
1672 ++ dev->battery_status = HID_BATTERY_REPORTED;
1673 + power_supply_changed(dev->battery);
1674 + }
1675 + }
1676 +@@ -1359,7 +1369,8 @@ static void hidinput_led_worker(struct work_struct *work)
1677 + led_work);
1678 + struct hid_field *field;
1679 + struct hid_report *report;
1680 +- int len, ret;
1681 ++ int ret;
1682 ++ u32 len;
1683 + __u8 *buf;
1684 +
1685 + field = hidinput_get_led_field(hid);
1686 +diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
1687 +index 6598501c1ad0..c3b9bd5dba75 100644
1688 +--- a/drivers/hid/hid-multitouch.c
1689 ++++ b/drivers/hid/hid-multitouch.c
1690 +@@ -354,7 +354,8 @@ static const struct attribute_group mt_attribute_group = {
1691 + static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
1692 + {
1693 + struct mt_device *td = hid_get_drvdata(hdev);
1694 +- int ret, size = hid_report_len(report);
1695 ++ int ret;
1696 ++ u32 size = hid_report_len(report);
1697 + u8 *buf;
1698 +
1699 + /*
1700 +@@ -1049,7 +1050,7 @@ static void mt_set_input_mode(struct hid_device *hdev)
1701 + struct hid_report_enum *re;
1702 + struct mt_class *cls = &td->mtclass;
1703 + char *buf;
1704 +- int report_len;
1705 ++ u32 report_len;
1706 +
1707 + if (td->inputmode < 0)
1708 + return;
1709 +diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
1710 +index ef241d66562e..cf5812188c37 100644
1711 +--- a/drivers/hid/hid-rmi.c
1712 ++++ b/drivers/hid/hid-rmi.c
1713 +@@ -89,8 +89,8 @@ struct rmi_data {
1714 + u8 *writeReport;
1715 + u8 *readReport;
1716 +
1717 +- int input_report_size;
1718 +- int output_report_size;
1719 ++ u32 input_report_size;
1720 ++ u32 output_report_size;
1721 +
1722 + unsigned long flags;
1723 +
1724 +diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
1725 +index 5fbe0f81ab2e..01b5a9f01814 100644
1726 +--- a/drivers/hid/hidraw.c
1727 ++++ b/drivers/hid/hidraw.c
1728 +@@ -192,6 +192,11 @@ static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t
1729 + int ret = 0, len;
1730 + unsigned char report_number;
1731 +
1732 ++ if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
1733 ++ ret = -ENODEV;
1734 ++ goto out;
1735 ++ }
1736 ++
1737 + dev = hidraw_table[minor]->hid;
1738 +
1739 + if (!dev->ll_driver->raw_request) {
1740 +diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
1741 +index 9145c2129a96..3535073a9a7d 100644
1742 +--- a/drivers/hid/i2c-hid/i2c-hid.c
1743 ++++ b/drivers/hid/i2c-hid/i2c-hid.c
1744 +@@ -143,10 +143,10 @@ struct i2c_hid {
1745 + * register of the HID
1746 + * descriptor. */
1747 + unsigned int bufsize; /* i2c buffer size */
1748 +- char *inbuf; /* Input buffer */
1749 +- char *rawbuf; /* Raw Input buffer */
1750 +- char *cmdbuf; /* Command buffer */
1751 +- char *argsbuf; /* Command arguments buffer */
1752 ++ u8 *inbuf; /* Input buffer */
1753 ++ u8 *rawbuf; /* Raw Input buffer */
1754 ++ u8 *cmdbuf; /* Command buffer */
1755 ++ u8 *argsbuf; /* Command arguments buffer */
1756 +
1757 + unsigned long flags; /* device flags */
1758 + unsigned long quirks; /* Various quirks */
1759 +@@ -450,7 +450,8 @@ static int i2c_hid_hwreset(struct i2c_client *client)
1760 +
1761 + static void i2c_hid_get_input(struct i2c_hid *ihid)
1762 + {
1763 +- int ret, ret_size;
1764 ++ int ret;
1765 ++ u32 ret_size;
1766 + int size = le16_to_cpu(ihid->hdesc.wMaxInputLength);
1767 +
1768 + if (size > ihid->bufsize)
1769 +@@ -475,7 +476,7 @@ static void i2c_hid_get_input(struct i2c_hid *ihid)
1770 + return;
1771 + }
1772 +
1773 +- if (ret_size > size) {
1774 ++ if ((ret_size > size) || (ret_size <= 2)) {
1775 + dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n",
1776 + __func__, size, ret_size);
1777 + return;
1778 +diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
1779 +index 65f1cfbbe7fe..4c337585479e 100644
1780 +--- a/drivers/hid/wacom_sys.c
1781 ++++ b/drivers/hid/wacom_sys.c
1782 +@@ -115,7 +115,7 @@ static void wacom_feature_mapping(struct hid_device *hdev,
1783 + unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
1784 + u8 *data;
1785 + int ret;
1786 +- int n;
1787 ++ u32 n;
1788 +
1789 + switch (equivalent_usage) {
1790 + case HID_DG_CONTACTMAX:
1791 +@@ -408,7 +408,7 @@ static int wacom_set_device_mode(struct hid_device *hdev,
1792 + u8 *rep_data;
1793 + struct hid_report *r;
1794 + struct hid_report_enum *re;
1795 +- int length;
1796 ++ u32 length;
1797 + int error = -ENOMEM, limit = 0;
1798 +
1799 + if (wacom_wac->mode_report < 0)
1800 +diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
1801 +index 70cbe1e5a3d2..c401b5b63f4c 100644
1802 +--- a/drivers/hid/wacom_wac.c
1803 ++++ b/drivers/hid/wacom_wac.c
1804 +@@ -689,6 +689,45 @@ static int wacom_intuos_get_tool_type(int tool_id)
1805 + return tool_type;
1806 + }
1807 +
1808 ++static void wacom_exit_report(struct wacom_wac *wacom)
1809 ++{
1810 ++ struct input_dev *input = wacom->pen_input;
1811 ++ struct wacom_features *features = &wacom->features;
1812 ++ unsigned char *data = wacom->data;
1813 ++ int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
1814 ++
1815 ++ /*
1816 ++ * Reset all states otherwise we lose the initial states
1817 ++ * when in-prox next time
1818 ++ */
1819 ++ input_report_abs(input, ABS_X, 0);
1820 ++ input_report_abs(input, ABS_Y, 0);
1821 ++ input_report_abs(input, ABS_DISTANCE, 0);
1822 ++ input_report_abs(input, ABS_TILT_X, 0);
1823 ++ input_report_abs(input, ABS_TILT_Y, 0);
1824 ++ if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
1825 ++ input_report_key(input, BTN_LEFT, 0);
1826 ++ input_report_key(input, BTN_MIDDLE, 0);
1827 ++ input_report_key(input, BTN_RIGHT, 0);
1828 ++ input_report_key(input, BTN_SIDE, 0);
1829 ++ input_report_key(input, BTN_EXTRA, 0);
1830 ++ input_report_abs(input, ABS_THROTTLE, 0);
1831 ++ input_report_abs(input, ABS_RZ, 0);
1832 ++ } else {
1833 ++ input_report_abs(input, ABS_PRESSURE, 0);
1834 ++ input_report_key(input, BTN_STYLUS, 0);
1835 ++ input_report_key(input, BTN_STYLUS2, 0);
1836 ++ input_report_key(input, BTN_TOUCH, 0);
1837 ++ input_report_abs(input, ABS_WHEEL, 0);
1838 ++ if (features->type >= INTUOS3S)
1839 ++ input_report_abs(input, ABS_Z, 0);
1840 ++ }
1841 ++ input_report_key(input, wacom->tool[idx], 0);
1842 ++ input_report_abs(input, ABS_MISC, 0); /* reset tool id */
1843 ++ input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
1844 ++ wacom->id[idx] = 0;
1845 ++}
1846 ++
1847 + static int wacom_intuos_inout(struct wacom_wac *wacom)
1848 + {
1849 + struct wacom_features *features = &wacom->features;
1850 +@@ -741,36 +780,7 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
1851 + if (!wacom->id[idx])
1852 + return 1;
1853 +
1854 +- /*
1855 +- * Reset all states otherwise we lose the initial states
1856 +- * when in-prox next time
1857 +- */
1858 +- input_report_abs(input, ABS_X, 0);
1859 +- input_report_abs(input, ABS_Y, 0);
1860 +- input_report_abs(input, ABS_DISTANCE, 0);
1861 +- input_report_abs(input, ABS_TILT_X, 0);
1862 +- input_report_abs(input, ABS_TILT_Y, 0);
1863 +- if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
1864 +- input_report_key(input, BTN_LEFT, 0);
1865 +- input_report_key(input, BTN_MIDDLE, 0);
1866 +- input_report_key(input, BTN_RIGHT, 0);
1867 +- input_report_key(input, BTN_SIDE, 0);
1868 +- input_report_key(input, BTN_EXTRA, 0);
1869 +- input_report_abs(input, ABS_THROTTLE, 0);
1870 +- input_report_abs(input, ABS_RZ, 0);
1871 +- } else {
1872 +- input_report_abs(input, ABS_PRESSURE, 0);
1873 +- input_report_key(input, BTN_STYLUS, 0);
1874 +- input_report_key(input, BTN_STYLUS2, 0);
1875 +- input_report_key(input, BTN_TOUCH, 0);
1876 +- input_report_abs(input, ABS_WHEEL, 0);
1877 +- if (features->type >= INTUOS3S)
1878 +- input_report_abs(input, ABS_Z, 0);
1879 +- }
1880 +- input_report_key(input, wacom->tool[idx], 0);
1881 +- input_report_abs(input, ABS_MISC, 0); /* reset tool id */
1882 +- input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
1883 +- wacom->id[idx] = 0;
1884 ++ wacom_exit_report(wacom);
1885 + return 2;
1886 + }
1887 +
1888 +@@ -1226,6 +1236,12 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
1889 + if (!valid)
1890 + continue;
1891 +
1892 ++ if (!prox) {
1893 ++ wacom->shared->stylus_in_proximity = false;
1894 ++ wacom_exit_report(wacom);
1895 ++ input_sync(pen_input);
1896 ++ return;
1897 ++ }
1898 + if (range) {
1899 + /* Fix rotation alignment: userspace expects zero at left */
1900 + int16_t rotation = (int16_t)get_unaligned_le16(&frame[9]);
1901 +diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
1902 +index 8eac00efadc1..ba8df2fde1b2 100644
1903 +--- a/drivers/i2c/busses/i2c-i801.c
1904 ++++ b/drivers/i2c/busses/i2c-i801.c
1905 +@@ -965,8 +965,6 @@ static void i801_enable_host_notify(struct i2c_adapter *adapter)
1906 + if (!(priv->features & FEATURE_HOST_NOTIFY))
1907 + return;
1908 +
1909 +- priv->original_slvcmd = inb_p(SMBSLVCMD(priv));
1910 +-
1911 + if (!(SMBSLVCMD_HST_NTFY_INTREN & priv->original_slvcmd))
1912 + outb_p(SMBSLVCMD_HST_NTFY_INTREN | priv->original_slvcmd,
1913 + SMBSLVCMD(priv));
1914 +@@ -1614,6 +1612,10 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
1915 + outb_p(inb_p(SMBAUXCTL(priv)) &
1916 + ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
1917 +
1918 ++ /* Remember original Host Notify setting */
1919 ++ if (priv->features & FEATURE_HOST_NOTIFY)
1920 ++ priv->original_slvcmd = inb_p(SMBSLVCMD(priv));
1921 ++
1922 + /* Default timeout in interrupt mode: 200 ms */
1923 + priv->adapter.timeout = HZ / 5;
1924 +
1925 +@@ -1698,6 +1700,15 @@ static void i801_remove(struct pci_dev *dev)
1926 + */
1927 + }
1928 +
1929 ++static void i801_shutdown(struct pci_dev *dev)
1930 ++{
1931 ++ struct i801_priv *priv = pci_get_drvdata(dev);
1932 ++
1933 ++ /* Restore config registers to avoid hard hang on some systems */
1934 ++ i801_disable_host_notify(priv);
1935 ++ pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
1936 ++}
1937 ++
1938 + #ifdef CONFIG_PM
1939 + static int i801_suspend(struct device *dev)
1940 + {
1941 +@@ -1727,6 +1738,7 @@ static struct pci_driver i801_driver = {
1942 + .id_table = i801_ids,
1943 + .probe = i801_probe,
1944 + .remove = i801_remove,
1945 ++ .shutdown = i801_shutdown,
1946 + .driver = {
1947 + .pm = &i801_pm_ops,
1948 + },
1949 +diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
1950 +index d6fa38f8604f..0698d92e2656 100644
1951 +--- a/drivers/infiniband/core/ucma.c
1952 ++++ b/drivers/infiniband/core/ucma.c
1953 +@@ -1241,6 +1241,9 @@ static int ucma_set_ib_path(struct ucma_context *ctx,
1954 + if (!optlen)
1955 + return -EINVAL;
1956 +
1957 ++ if (!ctx->cm_id->device)
1958 ++ return -EINVAL;
1959 ++
1960 + memset(&sa_path, 0, sizeof(sa_path));
1961 +
1962 + sa_path.rec_type = SA_PATH_REC_TYPE_IB;
1963 +diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
1964 +index 6d48d8a93b62..538f1784863a 100644
1965 +--- a/drivers/infiniband/hw/mlx5/mr.c
1966 ++++ b/drivers/infiniband/hw/mlx5/mr.c
1967 +@@ -1220,6 +1220,8 @@ struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
1968 + return ERR_PTR(-EINVAL);
1969 +
1970 + mr = mlx5_ib_alloc_implicit_mr(to_mpd(pd), access_flags);
1971 ++ if (IS_ERR(mr))
1972 ++ return ERR_CAST(mr);
1973 + return &mr->ibmr;
1974 + }
1975 + #endif
1976 +diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
1977 +index afbf701dc9a7..906bacf365d4 100644
1978 +--- a/drivers/infiniband/sw/rxe/rxe_verbs.c
1979 ++++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
1980 +@@ -712,9 +712,8 @@ static int init_send_wqe(struct rxe_qp *qp, struct ib_send_wr *ibwr,
1981 + memcpy(wqe->dma.sge, ibwr->sg_list,
1982 + num_sge * sizeof(struct ib_sge));
1983 +
1984 +- wqe->iova = (mask & WR_ATOMIC_MASK) ?
1985 +- atomic_wr(ibwr)->remote_addr :
1986 +- rdma_wr(ibwr)->remote_addr;
1987 ++ wqe->iova = mask & WR_ATOMIC_MASK ? atomic_wr(ibwr)->remote_addr :
1988 ++ mask & WR_READ_OR_WRITE_MASK ? rdma_wr(ibwr)->remote_addr : 0;
1989 + wqe->mask = mask;
1990 + wqe->dma.length = length;
1991 + wqe->dma.resid = length;
1992 +diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
1993 +index 60d7b493ed2d..299a97b7e17f 100644
1994 +--- a/drivers/infiniband/ulp/srp/ib_srp.c
1995 ++++ b/drivers/infiniband/ulp/srp/ib_srp.c
1996 +@@ -2656,9 +2656,11 @@ static int srp_abort(struct scsi_cmnd *scmnd)
1997 + ret = FAST_IO_FAIL;
1998 + else
1999 + ret = FAILED;
2000 +- srp_free_req(ch, req, scmnd, 0);
2001 +- scmnd->result = DID_ABORT << 16;
2002 +- scmnd->scsi_done(scmnd);
2003 ++ if (ret == SUCCESS) {
2004 ++ srp_free_req(ch, req, scmnd, 0);
2005 ++ scmnd->result = DID_ABORT << 16;
2006 ++ scmnd->scsi_done(scmnd);
2007 ++ }
2008 +
2009 + return ret;
2010 + }
2011 +@@ -3428,12 +3430,10 @@ static ssize_t srp_create_target(struct device *dev,
2012 + num_online_nodes());
2013 + const int ch_end = ((node_idx + 1) * target->ch_count /
2014 + num_online_nodes());
2015 +- const int cv_start = (node_idx * ibdev->num_comp_vectors /
2016 +- num_online_nodes() + target->comp_vector)
2017 +- % ibdev->num_comp_vectors;
2018 +- const int cv_end = ((node_idx + 1) * ibdev->num_comp_vectors /
2019 +- num_online_nodes() + target->comp_vector)
2020 +- % ibdev->num_comp_vectors;
2021 ++ const int cv_start = node_idx * ibdev->num_comp_vectors /
2022 ++ num_online_nodes();
2023 ++ const int cv_end = (node_idx + 1) * ibdev->num_comp_vectors /
2024 ++ num_online_nodes();
2025 + int cpu_idx = 0;
2026 +
2027 + for_each_online_cpu(cpu) {
2028 +diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c
2029 +index 003b4a4d4b78..d7def26ccf79 100644
2030 +--- a/drivers/iommu/intel-svm.c
2031 ++++ b/drivers/iommu/intel-svm.c
2032 +@@ -382,6 +382,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_
2033 + pasid_max - 1, GFP_KERNEL);
2034 + if (ret < 0) {
2035 + kfree(svm);
2036 ++ kfree(sdev);
2037 + goto out;
2038 + }
2039 + svm->pasid = ret;
2040 +diff --git a/drivers/irqchip/irq-gic-common.c b/drivers/irqchip/irq-gic-common.c
2041 +index 9ae71804b5dd..1c2ca8d51a70 100644
2042 +--- a/drivers/irqchip/irq-gic-common.c
2043 ++++ b/drivers/irqchip/irq-gic-common.c
2044 +@@ -21,6 +21,8 @@
2045 +
2046 + #include "irq-gic-common.h"
2047 +
2048 ++static DEFINE_RAW_SPINLOCK(irq_controller_lock);
2049 ++
2050 + static const struct gic_kvm_info *gic_kvm_info;
2051 +
2052 + const struct gic_kvm_info *gic_get_kvm_info(void)
2053 +@@ -52,11 +54,13 @@ int gic_configure_irq(unsigned int irq, unsigned int type,
2054 + u32 confoff = (irq / 16) * 4;
2055 + u32 val, oldval;
2056 + int ret = 0;
2057 ++ unsigned long flags;
2058 +
2059 + /*
2060 + * Read current configuration register, and insert the config
2061 + * for "irq", depending on "type".
2062 + */
2063 ++ raw_spin_lock_irqsave(&irq_controller_lock, flags);
2064 + val = oldval = readl_relaxed(base + GIC_DIST_CONFIG + confoff);
2065 + if (type & IRQ_TYPE_LEVEL_MASK)
2066 + val &= ~confmask;
2067 +@@ -64,8 +68,10 @@ int gic_configure_irq(unsigned int irq, unsigned int type,
2068 + val |= confmask;
2069 +
2070 + /* If the current configuration is the same, then we are done */
2071 +- if (val == oldval)
2072 ++ if (val == oldval) {
2073 ++ raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
2074 + return 0;
2075 ++ }
2076 +
2077 + /*
2078 + * Write back the new configuration, and possibly re-enable
2079 +@@ -83,6 +89,7 @@ int gic_configure_irq(unsigned int irq, unsigned int type,
2080 + pr_warn("GIC: PPI%d is secure or misconfigured\n",
2081 + irq - 16);
2082 + }
2083 ++ raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
2084 +
2085 + if (sync_access)
2086 + sync_access();
2087 +diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
2088 +index 554d60394c06..f575110454b6 100644
2089 +--- a/drivers/md/dm-crypt.c
2090 ++++ b/drivers/md/dm-crypt.c
2091 +@@ -148,6 +148,8 @@ struct crypt_config {
2092 + mempool_t *tag_pool;
2093 + unsigned tag_pool_max_sectors;
2094 +
2095 ++ struct percpu_counter n_allocated_pages;
2096 ++
2097 + struct bio_set *bs;
2098 + struct mutex bio_alloc_lock;
2099 +
2100 +@@ -219,6 +221,12 @@ struct crypt_config {
2101 + #define MAX_TAG_SIZE 480
2102 + #define POOL_ENTRY_SIZE 512
2103 +
2104 ++static DEFINE_SPINLOCK(dm_crypt_clients_lock);
2105 ++static unsigned dm_crypt_clients_n = 0;
2106 ++static volatile unsigned long dm_crypt_pages_per_client;
2107 ++#define DM_CRYPT_MEMORY_PERCENT 2
2108 ++#define DM_CRYPT_MIN_PAGES_PER_CLIENT (BIO_MAX_PAGES * 16)
2109 ++
2110 + static void clone_init(struct dm_crypt_io *, struct bio *);
2111 + static void kcryptd_queue_crypt(struct dm_crypt_io *io);
2112 + static struct scatterlist *crypt_get_sg_data(struct crypt_config *cc,
2113 +@@ -2156,6 +2164,43 @@ static int crypt_wipe_key(struct crypt_config *cc)
2114 + return r;
2115 + }
2116 +
2117 ++static void crypt_calculate_pages_per_client(void)
2118 ++{
2119 ++ unsigned long pages = (totalram_pages - totalhigh_pages) * DM_CRYPT_MEMORY_PERCENT / 100;
2120 ++
2121 ++ if (!dm_crypt_clients_n)
2122 ++ return;
2123 ++
2124 ++ pages /= dm_crypt_clients_n;
2125 ++ if (pages < DM_CRYPT_MIN_PAGES_PER_CLIENT)
2126 ++ pages = DM_CRYPT_MIN_PAGES_PER_CLIENT;
2127 ++ dm_crypt_pages_per_client = pages;
2128 ++}
2129 ++
2130 ++static void *crypt_page_alloc(gfp_t gfp_mask, void *pool_data)
2131 ++{
2132 ++ struct crypt_config *cc = pool_data;
2133 ++ struct page *page;
2134 ++
2135 ++ if (unlikely(percpu_counter_compare(&cc->n_allocated_pages, dm_crypt_pages_per_client) >= 0) &&
2136 ++ likely(gfp_mask & __GFP_NORETRY))
2137 ++ return NULL;
2138 ++
2139 ++ page = alloc_page(gfp_mask);
2140 ++ if (likely(page != NULL))
2141 ++ percpu_counter_add(&cc->n_allocated_pages, 1);
2142 ++
2143 ++ return page;
2144 ++}
2145 ++
2146 ++static void crypt_page_free(void *page, void *pool_data)
2147 ++{
2148 ++ struct crypt_config *cc = pool_data;
2149 ++
2150 ++ __free_page(page);
2151 ++ percpu_counter_sub(&cc->n_allocated_pages, 1);
2152 ++}
2153 ++
2154 + static void crypt_dtr(struct dm_target *ti)
2155 + {
2156 + struct crypt_config *cc = ti->private;
2157 +@@ -2182,6 +2227,10 @@ static void crypt_dtr(struct dm_target *ti)
2158 + mempool_destroy(cc->req_pool);
2159 + mempool_destroy(cc->tag_pool);
2160 +
2161 ++ if (cc->page_pool)
2162 ++ WARN_ON(percpu_counter_sum(&cc->n_allocated_pages) != 0);
2163 ++ percpu_counter_destroy(&cc->n_allocated_pages);
2164 ++
2165 + if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
2166 + cc->iv_gen_ops->dtr(cc);
2167 +
2168 +@@ -2196,6 +2245,12 @@ static void crypt_dtr(struct dm_target *ti)
2169 +
2170 + /* Must zero key material before freeing */
2171 + kzfree(cc);
2172 ++
2173 ++ spin_lock(&dm_crypt_clients_lock);
2174 ++ WARN_ON(!dm_crypt_clients_n);
2175 ++ dm_crypt_clients_n--;
2176 ++ crypt_calculate_pages_per_client();
2177 ++ spin_unlock(&dm_crypt_clients_lock);
2178 + }
2179 +
2180 + static int crypt_ctr_ivmode(struct dm_target *ti, const char *ivmode)
2181 +@@ -2643,6 +2698,15 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
2182 +
2183 + ti->private = cc;
2184 +
2185 ++ spin_lock(&dm_crypt_clients_lock);
2186 ++ dm_crypt_clients_n++;
2187 ++ crypt_calculate_pages_per_client();
2188 ++ spin_unlock(&dm_crypt_clients_lock);
2189 ++
2190 ++ ret = percpu_counter_init(&cc->n_allocated_pages, 0, GFP_KERNEL);
2191 ++ if (ret < 0)
2192 ++ goto bad;
2193 ++
2194 + /* Optional parameters need to be read before cipher constructor */
2195 + if (argc > 5) {
2196 + ret = crypt_ctr_optional(ti, argc - 5, &argv[5]);
2197 +@@ -2697,7 +2761,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
2198 + ALIGN(sizeof(struct dm_crypt_io) + cc->dmreq_start + additional_req_size,
2199 + ARCH_KMALLOC_MINALIGN);
2200 +
2201 +- cc->page_pool = mempool_create_page_pool(BIO_MAX_PAGES, 0);
2202 ++ cc->page_pool = mempool_create(BIO_MAX_PAGES, crypt_page_alloc, crypt_page_free, cc);
2203 + if (!cc->page_pool) {
2204 + ti->error = "Cannot allocate page mempool";
2205 + goto bad;
2206 +diff --git a/drivers/media/platform/vivid/vivid-vid-common.c b/drivers/media/platform/vivid/vivid-vid-common.c
2207 +index f0f423c7ca41..6f6d4df1e8a8 100644
2208 +--- a/drivers/media/platform/vivid/vivid-vid-common.c
2209 ++++ b/drivers/media/platform/vivid/vivid-vid-common.c
2210 +@@ -858,7 +858,8 @@ int vidioc_g_edid(struct file *file, void *_fh,
2211 + return -EINVAL;
2212 + if (edid->start_block + edid->blocks > dev->edid_blocks)
2213 + edid->blocks = dev->edid_blocks - edid->start_block;
2214 +- cec_set_edid_phys_addr(dev->edid, dev->edid_blocks * 128, adap->phys_addr);
2215 ++ if (adap)
2216 ++ cec_set_edid_phys_addr(dev->edid, dev->edid_blocks * 128, adap->phys_addr);
2217 + memcpy(edid->edid, dev->edid + edid->start_block * 128, edid->blocks * 128);
2218 + return 0;
2219 + }
2220 +diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
2221 +index f7f3b4b2c2de..8bd6b2f1af15 100644
2222 +--- a/drivers/media/platform/vsp1/vsp1_wpf.c
2223 ++++ b/drivers/media/platform/vsp1/vsp1_wpf.c
2224 +@@ -452,7 +452,7 @@ static void wpf_configure(struct vsp1_entity *entity,
2225 + : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index);
2226 + }
2227 +
2228 +- if (pipe->bru || pipe->num_inputs > 1)
2229 ++ if (pipe->bru)
2230 + srcrpf |= pipe->bru->type == VSP1_ENTITY_BRU
2231 + ? VI6_WPF_SRCRPF_VIRACT_MST
2232 + : VI6_WPF_SRCRPF_VIRACT2_MST;
2233 +diff --git a/drivers/misc/cxl/cxllib.c b/drivers/misc/cxl/cxllib.c
2234 +index dc9bc1807fdf..562a6803d690 100644
2235 +--- a/drivers/misc/cxl/cxllib.c
2236 ++++ b/drivers/misc/cxl/cxllib.c
2237 +@@ -207,49 +207,74 @@ int cxllib_get_PE_attributes(struct task_struct *task,
2238 + }
2239 + EXPORT_SYMBOL_GPL(cxllib_get_PE_attributes);
2240 +
2241 +-int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags)
2242 ++static int get_vma_info(struct mm_struct *mm, u64 addr,
2243 ++ u64 *vma_start, u64 *vma_end,
2244 ++ unsigned long *page_size)
2245 + {
2246 +- int rc;
2247 +- u64 dar;
2248 + struct vm_area_struct *vma = NULL;
2249 +- unsigned long page_size;
2250 +-
2251 +- if (mm == NULL)
2252 +- return -EFAULT;
2253 ++ int rc = 0;
2254 +
2255 + down_read(&mm->mmap_sem);
2256 +
2257 + vma = find_vma(mm, addr);
2258 + if (!vma) {
2259 +- pr_err("Can't find vma for addr %016llx\n", addr);
2260 + rc = -EFAULT;
2261 + goto out;
2262 + }
2263 +- /* get the size of the pages allocated */
2264 +- page_size = vma_kernel_pagesize(vma);
2265 +-
2266 +- for (dar = (addr & ~(page_size - 1)); dar < (addr + size); dar += page_size) {
2267 +- if (dar < vma->vm_start || dar >= vma->vm_end) {
2268 +- vma = find_vma(mm, addr);
2269 +- if (!vma) {
2270 +- pr_err("Can't find vma for addr %016llx\n", addr);
2271 +- rc = -EFAULT;
2272 +- goto out;
2273 +- }
2274 +- /* get the size of the pages allocated */
2275 +- page_size = vma_kernel_pagesize(vma);
2276 ++ *page_size = vma_kernel_pagesize(vma);
2277 ++ *vma_start = vma->vm_start;
2278 ++ *vma_end = vma->vm_end;
2279 ++out:
2280 ++ up_read(&mm->mmap_sem);
2281 ++ return rc;
2282 ++}
2283 ++
2284 ++int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags)
2285 ++{
2286 ++ int rc;
2287 ++ u64 dar, vma_start, vma_end;
2288 ++ unsigned long page_size;
2289 ++
2290 ++ if (mm == NULL)
2291 ++ return -EFAULT;
2292 ++
2293 ++ /*
2294 ++ * The buffer we have to process can extend over several pages
2295 ++ * and may also cover several VMAs.
2296 ++ * We iterate over all the pages. The page size could vary
2297 ++ * between VMAs.
2298 ++ */
2299 ++ rc = get_vma_info(mm, addr, &vma_start, &vma_end, &page_size);
2300 ++ if (rc)
2301 ++ return rc;
2302 ++
2303 ++ for (dar = (addr & ~(page_size - 1)); dar < (addr + size);
2304 ++ dar += page_size) {
2305 ++ if (dar < vma_start || dar >= vma_end) {
2306 ++ /*
2307 ++ * We don't hold the mm->mmap_sem semaphore
2308 ++ * while iterating, since the semaphore is
2309 ++ * required by one of the lower-level page
2310 ++ * fault processing functions and it could
2311 ++ * create a deadlock.
2312 ++ *
2313 ++ * It means the VMAs can be altered between 2
2314 ++ * loop iterations and we could theoretically
2315 ++ * miss a page (however unlikely). But that's
2316 ++ * not really a problem, as the driver will
2317 ++ * retry access, get another page fault on the
2318 ++ * missing page and call us again.
2319 ++ */
2320 ++ rc = get_vma_info(mm, dar, &vma_start, &vma_end,
2321 ++ &page_size);
2322 ++ if (rc)
2323 ++ return rc;
2324 + }
2325 +
2326 + rc = cxl_handle_mm_fault(mm, flags, dar);
2327 +- if (rc) {
2328 +- pr_err("cxl_handle_mm_fault failed %d", rc);
2329 +- rc = -EFAULT;
2330 +- goto out;
2331 +- }
2332 ++ if (rc)
2333 ++ return -EFAULT;
2334 + }
2335 +- rc = 0;
2336 +-out:
2337 +- up_read(&mm->mmap_sem);
2338 +- return rc;
2339 ++ return 0;
2340 + }
2341 + EXPORT_SYMBOL_GPL(cxllib_handle_fault);
2342 +diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
2343 +index 7db8c7a8d38d..48b67f552afe 100644
2344 +--- a/drivers/mmc/host/jz4740_mmc.c
2345 ++++ b/drivers/mmc/host/jz4740_mmc.c
2346 +@@ -362,9 +362,9 @@ static void jz4740_mmc_set_irq_enabled(struct jz4740_mmc_host *host,
2347 + host->irq_mask &= ~irq;
2348 + else
2349 + host->irq_mask |= irq;
2350 +- spin_unlock_irqrestore(&host->lock, flags);
2351 +
2352 + writew(host->irq_mask, host->base + JZ_REG_MMC_IMASK);
2353 ++ spin_unlock_irqrestore(&host->lock, flags);
2354 + }
2355 +
2356 + static void jz4740_mmc_clock_enable(struct jz4740_mmc_host *host,
2357 +diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
2358 +index 5bedf4b7f0f7..44da037b13ba 100644
2359 +--- a/drivers/mmc/host/sdhci-pci-core.c
2360 ++++ b/drivers/mmc/host/sdhci-pci-core.c
2361 +@@ -1192,7 +1192,7 @@ static void amd_enable_manual_tuning(struct pci_dev *pdev)
2362 + pci_write_config_dword(pdev, AMD_SD_MISC_CONTROL, val);
2363 + }
2364 +
2365 +-static int amd_execute_tuning(struct sdhci_host *host, u32 opcode)
2366 ++static int amd_execute_tuning_hs200(struct sdhci_host *host, u32 opcode)
2367 + {
2368 + struct sdhci_pci_slot *slot = sdhci_priv(host);
2369 + struct pci_dev *pdev = slot->chip->pdev;
2370 +@@ -1231,6 +1231,27 @@ static int amd_execute_tuning(struct sdhci_host *host, u32 opcode)
2371 + return 0;
2372 + }
2373 +
2374 ++static int amd_execute_tuning(struct mmc_host *mmc, u32 opcode)
2375 ++{
2376 ++ struct sdhci_host *host = mmc_priv(mmc);
2377 ++
2378 ++ /* AMD requires custom HS200 tuning */
2379 ++ if (host->timing == MMC_TIMING_MMC_HS200)
2380 ++ return amd_execute_tuning_hs200(host, opcode);
2381 ++
2382 ++ /* Otherwise perform standard SDHCI tuning */
2383 ++ return sdhci_execute_tuning(mmc, opcode);
2384 ++}
2385 ++
2386 ++static int amd_probe_slot(struct sdhci_pci_slot *slot)
2387 ++{
2388 ++ struct mmc_host_ops *ops = &slot->host->mmc_host_ops;
2389 ++
2390 ++ ops->execute_tuning = amd_execute_tuning;
2391 ++
2392 ++ return 0;
2393 ++}
2394 ++
2395 + static int amd_probe(struct sdhci_pci_chip *chip)
2396 + {
2397 + struct pci_dev *smbus_dev;
2398 +@@ -1265,12 +1286,12 @@ static const struct sdhci_ops amd_sdhci_pci_ops = {
2399 + .set_bus_width = sdhci_set_bus_width,
2400 + .reset = sdhci_reset,
2401 + .set_uhs_signaling = sdhci_set_uhs_signaling,
2402 +- .platform_execute_tuning = amd_execute_tuning,
2403 + };
2404 +
2405 + static const struct sdhci_pci_fixes sdhci_amd = {
2406 + .probe = amd_probe,
2407 + .ops = &amd_sdhci_pci_ops,
2408 ++ .probe_slot = amd_probe_slot,
2409 + };
2410 +
2411 + static const struct pci_device_id pci_ids[] = {
2412 +diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c
2413 +index 3a6d49f07e22..de1562f27fdb 100644
2414 +--- a/drivers/mmc/host/tmio_mmc_core.c
2415 ++++ b/drivers/mmc/host/tmio_mmc_core.c
2416 +@@ -911,7 +911,7 @@ static void tmio_mmc_finish_request(struct tmio_mmc_host *host)
2417 + host->check_scc_error(host);
2418 +
2419 + /* If SET_BLOCK_COUNT, continue with main command */
2420 +- if (host->mrq) {
2421 ++ if (host->mrq && !mrq->cmd->error) {
2422 + tmio_process_mrq(host, mrq);
2423 + return;
2424 + }
2425 +diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
2426 +index b1fc28f63882..d0b63bbf46a7 100644
2427 +--- a/drivers/mtd/ubi/block.c
2428 ++++ b/drivers/mtd/ubi/block.c
2429 +@@ -244,7 +244,7 @@ static int ubiblock_open(struct block_device *bdev, fmode_t mode)
2430 + * in any case.
2431 + */
2432 + if (mode & FMODE_WRITE) {
2433 +- ret = -EPERM;
2434 ++ ret = -EROFS;
2435 + goto out_unlock;
2436 + }
2437 +
2438 +diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
2439 +index 842550b5712a..defb1cd8d2e1 100644
2440 +--- a/drivers/mtd/ubi/build.c
2441 ++++ b/drivers/mtd/ubi/build.c
2442 +@@ -845,6 +845,17 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
2443 + return -EINVAL;
2444 + }
2445 +
2446 ++ /*
2447 ++ * Both UBI and UBIFS have been designed for SLC NAND and NOR flashes.
2448 ++ * MLC NAND is different and needs special care, otherwise UBI or UBIFS
2449 ++ * will die soon and you will lose all your data.
2450 ++ */
2451 ++ if (mtd->type == MTD_MLCNANDFLASH) {
2452 ++ pr_err("ubi: refuse attaching mtd%d - MLC NAND is not supported\n",
2453 ++ mtd->index);
2454 ++ return -EINVAL;
2455 ++ }
2456 ++
2457 + if (ubi_num == UBI_DEV_NUM_AUTO) {
2458 + /* Search for an empty slot in the @ubi_devices array */
2459 + for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++)
2460 +diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
2461 +index 4f0bd6b4422a..69dd21679a30 100644
2462 +--- a/drivers/mtd/ubi/fastmap-wl.c
2463 ++++ b/drivers/mtd/ubi/fastmap-wl.c
2464 +@@ -362,7 +362,6 @@ static void ubi_fastmap_close(struct ubi_device *ubi)
2465 + {
2466 + int i;
2467 +
2468 +- flush_work(&ubi->fm_work);
2469 + return_unused_pool_pebs(ubi, &ubi->fm_pool);
2470 + return_unused_pool_pebs(ubi, &ubi->fm_wl_pool);
2471 +
2472 +diff --git a/drivers/net/wireless/intel/iwlwifi/cfg/9000.c b/drivers/net/wireless/intel/iwlwifi/cfg/9000.c
2473 +index c8e7b54a538a..73da5e63a609 100644
2474 +--- a/drivers/net/wireless/intel/iwlwifi/cfg/9000.c
2475 ++++ b/drivers/net/wireless/intel/iwlwifi/cfg/9000.c
2476 +@@ -53,6 +53,7 @@
2477 + #include <linux/stringify.h>
2478 + #include "iwl-config.h"
2479 + #include "iwl-agn-hw.h"
2480 ++#include "fw/file.h"
2481 +
2482 + /* Highest firmware API version supported */
2483 + #define IWL9000_UCODE_API_MAX 34
2484 +@@ -264,6 +265,67 @@ const struct iwl_cfg iwl9560_2ac_cfg_soc = {
2485 + .integrated = true,
2486 + .soc_latency = 5000,
2487 + };
2488 ++
2489 ++const struct iwl_cfg iwl9460_2ac_cfg_shared_clk = {
2490 ++ .name = "Intel(R) Dual Band Wireless AC 9460",
2491 ++ .fw_name_pre = IWL9000A_FW_PRE,
2492 ++ .fw_name_pre_b_or_c_step = IWL9000B_FW_PRE,
2493 ++ .fw_name_pre_rf_next_step = IWL9000RFB_FW_PRE,
2494 ++ IWL_DEVICE_9000,
2495 ++ .ht_params = &iwl9000_ht_params,
2496 ++ .nvm_ver = IWL9000_NVM_VERSION,
2497 ++ .nvm_calib_ver = IWL9000_TX_POWER_VERSION,
2498 ++ .max_ht_ampdu_exponent = IEEE80211_HT_MAX_AMPDU_64K,
2499 ++ .integrated = true,
2500 ++ .soc_latency = 5000,
2501 ++ .extra_phy_cfg_flags = FW_PHY_CFG_SHARED_CLK
2502 ++};
2503 ++
2504 ++const struct iwl_cfg iwl9461_2ac_cfg_shared_clk = {
2505 ++ .name = "Intel(R) Dual Band Wireless AC 9461",
2506 ++ .fw_name_pre = IWL9000A_FW_PRE,
2507 ++ .fw_name_pre_b_or_c_step = IWL9000B_FW_PRE,
2508 ++ .fw_name_pre_rf_next_step = IWL9000RFB_FW_PRE,
2509 ++ IWL_DEVICE_9000,
2510 ++ .ht_params = &iwl9000_ht_params,
2511 ++ .nvm_ver = IWL9000_NVM_VERSION,
2512 ++ .nvm_calib_ver = IWL9000_TX_POWER_VERSION,
2513 ++ .max_ht_ampdu_exponent = IEEE80211_HT_MAX_AMPDU_64K,
2514 ++ .integrated = true,
2515 ++ .soc_latency = 5000,
2516 ++ .extra_phy_cfg_flags = FW_PHY_CFG_SHARED_CLK
2517 ++};
2518 ++
2519 ++const struct iwl_cfg iwl9462_2ac_cfg_shared_clk = {
2520 ++ .name = "Intel(R) Dual Band Wireless AC 9462",
2521 ++ .fw_name_pre = IWL9000A_FW_PRE,
2522 ++ .fw_name_pre_b_or_c_step = IWL9000B_FW_PRE,
2523 ++ .fw_name_pre_rf_next_step = IWL9000RFB_FW_PRE,
2524 ++ IWL_DEVICE_9000,
2525 ++ .ht_params = &iwl9000_ht_params,
2526 ++ .nvm_ver = IWL9000_NVM_VERSION,
2527 ++ .nvm_calib_ver = IWL9000_TX_POWER_VERSION,
2528 ++ .max_ht_ampdu_exponent = IEEE80211_HT_MAX_AMPDU_64K,
2529 ++ .integrated = true,
2530 ++ .soc_latency = 5000,
2531 ++ .extra_phy_cfg_flags = FW_PHY_CFG_SHARED_CLK
2532 ++};
2533 ++
2534 ++const struct iwl_cfg iwl9560_2ac_cfg_shared_clk = {
2535 ++ .name = "Intel(R) Dual Band Wireless AC 9560",
2536 ++ .fw_name_pre = IWL9000A_FW_PRE,
2537 ++ .fw_name_pre_b_or_c_step = IWL9000B_FW_PRE,
2538 ++ .fw_name_pre_rf_next_step = IWL9000RFB_FW_PRE,
2539 ++ IWL_DEVICE_9000,
2540 ++ .ht_params = &iwl9000_ht_params,
2541 ++ .nvm_ver = IWL9000_NVM_VERSION,
2542 ++ .nvm_calib_ver = IWL9000_TX_POWER_VERSION,
2543 ++ .max_ht_ampdu_exponent = IEEE80211_HT_MAX_AMPDU_64K,
2544 ++ .integrated = true,
2545 ++ .soc_latency = 5000,
2546 ++ .extra_phy_cfg_flags = FW_PHY_CFG_SHARED_CLK
2547 ++};
2548 ++
2549 + MODULE_FIRMWARE(IWL9000A_MODULE_FIRMWARE(IWL9000_UCODE_API_MAX));
2550 + MODULE_FIRMWARE(IWL9000B_MODULE_FIRMWARE(IWL9000_UCODE_API_MAX));
2551 + MODULE_FIRMWARE(IWL9000RFB_MODULE_FIRMWARE(IWL9000_UCODE_API_MAX));
2552 +diff --git a/drivers/net/wireless/intel/iwlwifi/fw/file.h b/drivers/net/wireless/intel/iwlwifi/fw/file.h
2553 +index e988e4c371c4..1b3ad8ef0c79 100644
2554 +--- a/drivers/net/wireless/intel/iwlwifi/fw/file.h
2555 ++++ b/drivers/net/wireless/intel/iwlwifi/fw/file.h
2556 +@@ -434,6 +434,7 @@ enum iwl_fw_phy_cfg {
2557 + FW_PHY_CFG_TX_CHAIN = 0xf << FW_PHY_CFG_TX_CHAIN_POS,
2558 + FW_PHY_CFG_RX_CHAIN_POS = 20,
2559 + FW_PHY_CFG_RX_CHAIN = 0xf << FW_PHY_CFG_RX_CHAIN_POS,
2560 ++ FW_PHY_CFG_SHARED_CLK = BIT(31),
2561 + };
2562 +
2563 + #define IWL_UCODE_MAX_CS 1
2564 +diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-config.h b/drivers/net/wireless/intel/iwlwifi/iwl-config.h
2565 +index e226179c32fa..85fe1a928adc 100644
2566 +--- a/drivers/net/wireless/intel/iwlwifi/iwl-config.h
2567 ++++ b/drivers/net/wireless/intel/iwlwifi/iwl-config.h
2568 +@@ -394,6 +394,7 @@ struct iwl_cfg {
2569 + u8 max_vht_ampdu_exponent;
2570 + u8 ucode_api_max;
2571 + u8 ucode_api_min;
2572 ++ u32 extra_phy_cfg_flags;
2573 + };
2574 +
2575 + /*
2576 +@@ -476,6 +477,10 @@ extern const struct iwl_cfg iwl9460_2ac_cfg_soc;
2577 + extern const struct iwl_cfg iwl9461_2ac_cfg_soc;
2578 + extern const struct iwl_cfg iwl9462_2ac_cfg_soc;
2579 + extern const struct iwl_cfg iwl9560_2ac_cfg_soc;
2580 ++extern const struct iwl_cfg iwl9460_2ac_cfg_shared_clk;
2581 ++extern const struct iwl_cfg iwl9461_2ac_cfg_shared_clk;
2582 ++extern const struct iwl_cfg iwl9462_2ac_cfg_shared_clk;
2583 ++extern const struct iwl_cfg iwl9560_2ac_cfg_shared_clk;
2584 + extern const struct iwl_cfg iwla000_2ac_cfg_hr;
2585 + extern const struct iwl_cfg iwla000_2ac_cfg_hr_cdb;
2586 + extern const struct iwl_cfg iwla000_2ac_cfg_jf;
2587 +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
2588 +index 83485493a79a..b71a9d11a50f 100644
2589 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
2590 ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
2591 +@@ -435,6 +435,10 @@ static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
2592 +
2593 + /* Set parameters */
2594 + phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
2595 ++
2596 ++ /* set flags extra PHY configuration flags from the device's cfg */
2597 ++ phy_cfg_cmd.phy_cfg |= cpu_to_le32(mvm->cfg->extra_phy_cfg_flags);
2598 ++
2599 + phy_cfg_cmd.calib_control.event_trigger =
2600 + mvm->fw->default_calib[ucode_type].event_trigger;
2601 + phy_cfg_cmd.calib_control.flow_trigger =
2602 +diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
2603 +index 0f7bd37bf172..9a8605abb00a 100644
2604 +--- a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
2605 ++++ b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
2606 +@@ -8,6 +8,7 @@
2607 + * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved.
2608 + * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
2609 + * Copyright(c) 2016-2017 Intel Deutschland GmbH
2610 ++ * Copyright(c) 2018 Intel Corporation
2611 + *
2612 + * This program is free software; you can redistribute it and/or modify
2613 + * it under the terms of version 2 of the GNU General Public License as
2614 +@@ -36,6 +37,7 @@
2615 + * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
2616 + * All rights reserved.
2617 + * Copyright(c) 2017 Intel Deutschland GmbH
2618 ++ * Copyright(c) 2018 Intel Corporation
2619 + *
2620 + * Redistribution and use in source and binary forms, with or without
2621 + * modification, are permitted provided that the following conditions
2622 +@@ -515,9 +517,9 @@ static const struct pci_device_id iwl_hw_card_ids[] = {
2623 + {IWL_PCI_DEVICE(0x24FD, 0x9074, iwl8265_2ac_cfg)},
2624 +
2625 + /* 9000 Series */
2626 +- {IWL_PCI_DEVICE(0x2526, 0x0000, iwl9260_2ac_cfg)},
2627 + {IWL_PCI_DEVICE(0x2526, 0x0010, iwl9260_2ac_cfg)},
2628 + {IWL_PCI_DEVICE(0x2526, 0x0014, iwl9260_2ac_cfg)},
2629 ++ {IWL_PCI_DEVICE(0x2526, 0x0018, iwl9260_2ac_cfg)},
2630 + {IWL_PCI_DEVICE(0x2526, 0x0030, iwl9560_2ac_cfg)},
2631 + {IWL_PCI_DEVICE(0x2526, 0x0034, iwl9560_2ac_cfg)},
2632 + {IWL_PCI_DEVICE(0x2526, 0x0038, iwl9560_2ac_cfg)},
2633 +@@ -542,11 +544,15 @@ static const struct pci_device_id iwl_hw_card_ids[] = {
2634 + {IWL_PCI_DEVICE(0x2526, 0x1410, iwl9270_2ac_cfg)},
2635 + {IWL_PCI_DEVICE(0x2526, 0x1420, iwl9460_2ac_cfg_soc)},
2636 + {IWL_PCI_DEVICE(0x2526, 0x1610, iwl9270_2ac_cfg)},
2637 ++ {IWL_PCI_DEVICE(0x2526, 0x2030, iwl9560_2ac_cfg_soc)},
2638 ++ {IWL_PCI_DEVICE(0x2526, 0x2034, iwl9560_2ac_cfg_soc)},
2639 + {IWL_PCI_DEVICE(0x2526, 0x4010, iwl9260_2ac_cfg)},
2640 + {IWL_PCI_DEVICE(0x2526, 0x4030, iwl9560_2ac_cfg)},
2641 ++ {IWL_PCI_DEVICE(0x2526, 0x4034, iwl9560_2ac_cfg_soc)},
2642 + {IWL_PCI_DEVICE(0x2526, 0x40A4, iwl9460_2ac_cfg)},
2643 +- {IWL_PCI_DEVICE(0x2526, 0xA014, iwl9260_2ac_cfg)},
2644 ++ {IWL_PCI_DEVICE(0x2526, 0x4234, iwl9560_2ac_cfg_soc)},
2645 + {IWL_PCI_DEVICE(0x2526, 0x42A4, iwl9462_2ac_cfg_soc)},
2646 ++ {IWL_PCI_DEVICE(0x2526, 0xA014, iwl9260_2ac_cfg)},
2647 + {IWL_PCI_DEVICE(0x271B, 0x0010, iwl9160_2ac_cfg)},
2648 + {IWL_PCI_DEVICE(0x271B, 0x0014, iwl9160_2ac_cfg)},
2649 + {IWL_PCI_DEVICE(0x271B, 0x0210, iwl9160_2ac_cfg)},
2650 +@@ -567,38 +573,146 @@ static const struct pci_device_id iwl_hw_card_ids[] = {
2651 + {IWL_PCI_DEVICE(0x2720, 0x0264, iwl9461_2ac_cfg_soc)},
2652 + {IWL_PCI_DEVICE(0x2720, 0x02A0, iwl9462_2ac_cfg_soc)},
2653 + {IWL_PCI_DEVICE(0x2720, 0x02A4, iwl9462_2ac_cfg_soc)},
2654 ++ {IWL_PCI_DEVICE(0x2720, 0x1010, iwl9260_2ac_cfg)},
2655 ++ {IWL_PCI_DEVICE(0x2720, 0x1030, iwl9560_2ac_cfg_soc)},
2656 ++ {IWL_PCI_DEVICE(0x2720, 0x1210, iwl9260_2ac_cfg)},
2657 ++ {IWL_PCI_DEVICE(0x2720, 0x2030, iwl9560_2ac_cfg_soc)},
2658 ++ {IWL_PCI_DEVICE(0x2720, 0x2034, iwl9560_2ac_cfg_soc)},
2659 + {IWL_PCI_DEVICE(0x2720, 0x4030, iwl9560_2ac_cfg)},
2660 ++ {IWL_PCI_DEVICE(0x2720, 0x4034, iwl9560_2ac_cfg_soc)},
2661 + {IWL_PCI_DEVICE(0x2720, 0x40A4, iwl9462_2ac_cfg_soc)},
2662 ++ {IWL_PCI_DEVICE(0x2720, 0x4234, iwl9560_2ac_cfg_soc)},
2663 ++ {IWL_PCI_DEVICE(0x2720, 0x42A4, iwl9462_2ac_cfg_soc)},
2664 ++ {IWL_PCI_DEVICE(0x30DC, 0x0030, iwl9560_2ac_cfg_soc)},
2665 ++ {IWL_PCI_DEVICE(0x30DC, 0x0034, iwl9560_2ac_cfg_soc)},
2666 ++ {IWL_PCI_DEVICE(0x30DC, 0x0038, iwl9560_2ac_cfg_soc)},
2667 ++ {IWL_PCI_DEVICE(0x30DC, 0x003C, iwl9560_2ac_cfg_soc)},
2668 + {IWL_PCI_DEVICE(0x30DC, 0x0060, iwl9460_2ac_cfg_soc)},
2669 + {IWL_PCI_DEVICE(0x30DC, 0x0064, iwl9461_2ac_cfg_soc)},
2670 + {IWL_PCI_DEVICE(0x30DC, 0x00A0, iwl9462_2ac_cfg_soc)},
2671 + {IWL_PCI_DEVICE(0x30DC, 0x00A4, iwl9462_2ac_cfg_soc)},
2672 ++ {IWL_PCI_DEVICE(0x30DC, 0x0230, iwl9560_2ac_cfg_soc)},
2673 ++ {IWL_PCI_DEVICE(0x30DC, 0x0234, iwl9560_2ac_cfg_soc)},
2674 ++ {IWL_PCI_DEVICE(0x30DC, 0x0238, iwl9560_2ac_cfg_soc)},
2675 ++ {IWL_PCI_DEVICE(0x30DC, 0x023C, iwl9560_2ac_cfg_soc)},
2676 + {IWL_PCI_DEVICE(0x30DC, 0x0260, iwl9461_2ac_cfg_soc)},
2677 + {IWL_PCI_DEVICE(0x30DC, 0x0264, iwl9461_2ac_cfg_soc)},
2678 + {IWL_PCI_DEVICE(0x30DC, 0x02A0, iwl9462_2ac_cfg_soc)},
2679 + {IWL_PCI_DEVICE(0x30DC, 0x02A4, iwl9462_2ac_cfg_soc)},
2680 +- {IWL_PCI_DEVICE(0x31DC, 0x0030, iwl9560_2ac_cfg_soc)},
2681 +- {IWL_PCI_DEVICE(0x31DC, 0x0034, iwl9560_2ac_cfg_soc)},
2682 +- {IWL_PCI_DEVICE(0x31DC, 0x0038, iwl9560_2ac_cfg_soc)},
2683 +- {IWL_PCI_DEVICE(0x31DC, 0x003C, iwl9560_2ac_cfg_soc)},
2684 +- {IWL_PCI_DEVICE(0x31DC, 0x0060, iwl9460_2ac_cfg_soc)},
2685 +- {IWL_PCI_DEVICE(0x31DC, 0x0064, iwl9461_2ac_cfg_soc)},
2686 +- {IWL_PCI_DEVICE(0x31DC, 0x00A0, iwl9462_2ac_cfg_soc)},
2687 +- {IWL_PCI_DEVICE(0x31DC, 0x00A4, iwl9462_2ac_cfg_soc)},
2688 +- {IWL_PCI_DEVICE(0x31DC, 0x0230, iwl9560_2ac_cfg_soc)},
2689 +- {IWL_PCI_DEVICE(0x31DC, 0x0234, iwl9560_2ac_cfg_soc)},
2690 +- {IWL_PCI_DEVICE(0x31DC, 0x0238, iwl9560_2ac_cfg_soc)},
2691 +- {IWL_PCI_DEVICE(0x31DC, 0x023C, iwl9560_2ac_cfg_soc)},
2692 +- {IWL_PCI_DEVICE(0x31DC, 0x0260, iwl9461_2ac_cfg_soc)},
2693 +- {IWL_PCI_DEVICE(0x31DC, 0x0264, iwl9461_2ac_cfg_soc)},
2694 +- {IWL_PCI_DEVICE(0x31DC, 0x02A0, iwl9462_2ac_cfg_soc)},
2695 +- {IWL_PCI_DEVICE(0x31DC, 0x02A4, iwl9462_2ac_cfg_soc)},
2696 +- {IWL_PCI_DEVICE(0x31DC, 0x4030, iwl9560_2ac_cfg_soc)},
2697 +- {IWL_PCI_DEVICE(0x31DC, 0x4034, iwl9560_2ac_cfg_soc)},
2698 +- {IWL_PCI_DEVICE(0x31DC, 0x40A4, iwl9462_2ac_cfg_soc)},
2699 ++ {IWL_PCI_DEVICE(0x30DC, 0x1010, iwl9260_2ac_cfg)},
2700 ++ {IWL_PCI_DEVICE(0x30DC, 0x1030, iwl9560_2ac_cfg_soc)},
2701 ++ {IWL_PCI_DEVICE(0x30DC, 0x1210, iwl9260_2ac_cfg)},
2702 ++ {IWL_PCI_DEVICE(0x30DC, 0x2030, iwl9560_2ac_cfg_soc)},
2703 ++ {IWL_PCI_DEVICE(0x30DC, 0x2034, iwl9560_2ac_cfg_soc)},
2704 ++ {IWL_PCI_DEVICE(0x30DC, 0x4030, iwl9560_2ac_cfg_soc)},
2705 ++ {IWL_PCI_DEVICE(0x30DC, 0x4034, iwl9560_2ac_cfg_soc)},
2706 ++ {IWL_PCI_DEVICE(0x30DC, 0x40A4, iwl9462_2ac_cfg_soc)},
2707 ++ {IWL_PCI_DEVICE(0x30DC, 0x4234, iwl9560_2ac_cfg_soc)},
2708 ++ {IWL_PCI_DEVICE(0x30DC, 0x42A4, iwl9462_2ac_cfg_soc)},
2709 ++ {IWL_PCI_DEVICE(0x31DC, 0x0030, iwl9560_2ac_cfg_shared_clk)},
2710 ++ {IWL_PCI_DEVICE(0x31DC, 0x0034, iwl9560_2ac_cfg_shared_clk)},
2711 ++ {IWL_PCI_DEVICE(0x31DC, 0x0038, iwl9560_2ac_cfg_shared_clk)},
2712 ++ {IWL_PCI_DEVICE(0x31DC, 0x003C, iwl9560_2ac_cfg_shared_clk)},
2713 ++ {IWL_PCI_DEVICE(0x31DC, 0x0060, iwl9460_2ac_cfg_shared_clk)},
2714 ++ {IWL_PCI_DEVICE(0x31DC, 0x0064, iwl9461_2ac_cfg_shared_clk)},
2715 ++ {IWL_PCI_DEVICE(0x31DC, 0x00A0, iwl9462_2ac_cfg_shared_clk)},
2716 ++ {IWL_PCI_DEVICE(0x31DC, 0x00A4, iwl9462_2ac_cfg_shared_clk)},
2717 ++ {IWL_PCI_DEVICE(0x31DC, 0x0230, iwl9560_2ac_cfg_shared_clk)},
2718 ++ {IWL_PCI_DEVICE(0x31DC, 0x0234, iwl9560_2ac_cfg_shared_clk)},
2719 ++ {IWL_PCI_DEVICE(0x31DC, 0x0238, iwl9560_2ac_cfg_shared_clk)},
2720 ++ {IWL_PCI_DEVICE(0x31DC, 0x023C, iwl9560_2ac_cfg_shared_clk)},
2721 ++ {IWL_PCI_DEVICE(0x31DC, 0x0260, iwl9461_2ac_cfg_shared_clk)},
2722 ++ {IWL_PCI_DEVICE(0x31DC, 0x0264, iwl9461_2ac_cfg_shared_clk)},
2723 ++ {IWL_PCI_DEVICE(0x31DC, 0x02A0, iwl9462_2ac_cfg_shared_clk)},
2724 ++ {IWL_PCI_DEVICE(0x31DC, 0x02A4, iwl9462_2ac_cfg_shared_clk)},
2725 ++ {IWL_PCI_DEVICE(0x31DC, 0x1010, iwl9260_2ac_cfg)},
2726 ++ {IWL_PCI_DEVICE(0x31DC, 0x1030, iwl9560_2ac_cfg_shared_clk)},
2727 ++ {IWL_PCI_DEVICE(0x31DC, 0x1210, iwl9260_2ac_cfg)},
2728 ++ {IWL_PCI_DEVICE(0x31DC, 0x2030, iwl9560_2ac_cfg_shared_clk)},
2729 ++ {IWL_PCI_DEVICE(0x31DC, 0x2034, iwl9560_2ac_cfg_shared_clk)},
2730 ++ {IWL_PCI_DEVICE(0x31DC, 0x4030, iwl9560_2ac_cfg_shared_clk)},
2731 ++ {IWL_PCI_DEVICE(0x31DC, 0x4034, iwl9560_2ac_cfg_shared_clk)},
2732 ++ {IWL_PCI_DEVICE(0x31DC, 0x40A4, iwl9462_2ac_cfg_shared_clk)},
2733 ++ {IWL_PCI_DEVICE(0x31DC, 0x4234, iwl9560_2ac_cfg_shared_clk)},
2734 ++ {IWL_PCI_DEVICE(0x31DC, 0x42A4, iwl9462_2ac_cfg_shared_clk)},
2735 + {IWL_PCI_DEVICE(0x34F0, 0x0030, iwl9560_2ac_cfg_soc)},
2736 + {IWL_PCI_DEVICE(0x34F0, 0x0034, iwl9560_2ac_cfg_soc)},
2737 ++ {IWL_PCI_DEVICE(0x34F0, 0x0038, iwl9560_2ac_cfg_soc)},
2738 ++ {IWL_PCI_DEVICE(0x34F0, 0x003C, iwl9560_2ac_cfg_soc)},
2739 ++ {IWL_PCI_DEVICE(0x34F0, 0x0060, iwl9461_2ac_cfg_soc)},
2740 ++ {IWL_PCI_DEVICE(0x34F0, 0x0064, iwl9461_2ac_cfg_soc)},
2741 ++ {IWL_PCI_DEVICE(0x34F0, 0x00A0, iwl9462_2ac_cfg_soc)},
2742 ++ {IWL_PCI_DEVICE(0x34F0, 0x00A4, iwl9462_2ac_cfg_soc)},
2743 ++ {IWL_PCI_DEVICE(0x34F0, 0x0230, iwl9560_2ac_cfg_soc)},
2744 ++ {IWL_PCI_DEVICE(0x34F0, 0x0234, iwl9560_2ac_cfg_soc)},
2745 ++ {IWL_PCI_DEVICE(0x34F0, 0x0238, iwl9560_2ac_cfg_soc)},
2746 ++ {IWL_PCI_DEVICE(0x34F0, 0x023C, iwl9560_2ac_cfg_soc)},
2747 ++ {IWL_PCI_DEVICE(0x34F0, 0x0260, iwl9461_2ac_cfg_soc)},
2748 ++ {IWL_PCI_DEVICE(0x34F0, 0x0264, iwl9461_2ac_cfg_soc)},
2749 ++ {IWL_PCI_DEVICE(0x34F0, 0x02A0, iwl9462_2ac_cfg_soc)},
2750 + {IWL_PCI_DEVICE(0x34F0, 0x02A4, iwl9462_2ac_cfg_soc)},
2751 ++ {IWL_PCI_DEVICE(0x34F0, 0x1010, iwl9260_2ac_cfg)},
2752 ++ {IWL_PCI_DEVICE(0x34F0, 0x1030, iwl9560_2ac_cfg_soc)},
2753 ++ {IWL_PCI_DEVICE(0x34F0, 0x1210, iwl9260_2ac_cfg)},
2754 ++ {IWL_PCI_DEVICE(0x34F0, 0x2030, iwl9560_2ac_cfg_soc)},
2755 ++ {IWL_PCI_DEVICE(0x34F0, 0x2034, iwl9560_2ac_cfg_soc)},
2756 ++ {IWL_PCI_DEVICE(0x34F0, 0x4030, iwl9560_2ac_cfg_soc)},
2757 ++ {IWL_PCI_DEVICE(0x34F0, 0x4034, iwl9560_2ac_cfg_soc)},
2758 ++ {IWL_PCI_DEVICE(0x34F0, 0x40A4, iwl9462_2ac_cfg_soc)},
2759 ++ {IWL_PCI_DEVICE(0x34F0, 0x4234, iwl9560_2ac_cfg_soc)},
2760 ++ {IWL_PCI_DEVICE(0x34F0, 0x42A4, iwl9462_2ac_cfg_soc)},
2761 ++ {IWL_PCI_DEVICE(0x3DF0, 0x0030, iwl9560_2ac_cfg_soc)},
2762 ++ {IWL_PCI_DEVICE(0x3DF0, 0x0034, iwl9560_2ac_cfg_soc)},
2763 ++ {IWL_PCI_DEVICE(0x3DF0, 0x0038, iwl9560_2ac_cfg_soc)},
2764 ++ {IWL_PCI_DEVICE(0x3DF0, 0x003C, iwl9560_2ac_cfg_soc)},
2765 ++ {IWL_PCI_DEVICE(0x3DF0, 0x0060, iwl9461_2ac_cfg_soc)},
2766 ++ {IWL_PCI_DEVICE(0x3DF0, 0x0064, iwl9461_2ac_cfg_soc)},
2767 ++ {IWL_PCI_DEVICE(0x3DF0, 0x00A0, iwl9462_2ac_cfg_soc)},
2768 ++ {IWL_PCI_DEVICE(0x3DF0, 0x00A4, iwl9462_2ac_cfg_soc)},
2769 ++ {IWL_PCI_DEVICE(0x3DF0, 0x0230, iwl9560_2ac_cfg_soc)},
2770 ++ {IWL_PCI_DEVICE(0x3DF0, 0x0234, iwl9560_2ac_cfg_soc)},
2771 ++ {IWL_PCI_DEVICE(0x3DF0, 0x0238, iwl9560_2ac_cfg_soc)},
2772 ++ {IWL_PCI_DEVICE(0x3DF0, 0x023C, iwl9560_2ac_cfg_soc)},
2773 ++ {IWL_PCI_DEVICE(0x3DF0, 0x0260, iwl9461_2ac_cfg_soc)},
2774 ++ {IWL_PCI_DEVICE(0x3DF0, 0x0264, iwl9461_2ac_cfg_soc)},
2775 ++ {IWL_PCI_DEVICE(0x3DF0, 0x02A0, iwl9462_2ac_cfg_soc)},
2776 ++ {IWL_PCI_DEVICE(0x3DF0, 0x02A4, iwl9462_2ac_cfg_soc)},
2777 ++ {IWL_PCI_DEVICE(0x3DF0, 0x1010, iwl9260_2ac_cfg)},
2778 ++ {IWL_PCI_DEVICE(0x3DF0, 0x1030, iwl9560_2ac_cfg_soc)},
2779 ++ {IWL_PCI_DEVICE(0x3DF0, 0x1210, iwl9260_2ac_cfg)},
2780 ++ {IWL_PCI_DEVICE(0x3DF0, 0x2030, iwl9560_2ac_cfg_soc)},
2781 ++ {IWL_PCI_DEVICE(0x3DF0, 0x2034, iwl9560_2ac_cfg_soc)},
2782 ++ {IWL_PCI_DEVICE(0x3DF0, 0x4030, iwl9560_2ac_cfg_soc)},
2783 ++ {IWL_PCI_DEVICE(0x3DF0, 0x4034, iwl9560_2ac_cfg_soc)},
2784 ++ {IWL_PCI_DEVICE(0x3DF0, 0x40A4, iwl9462_2ac_cfg_soc)},
2785 ++ {IWL_PCI_DEVICE(0x3DF0, 0x4234, iwl9560_2ac_cfg_soc)},
2786 ++ {IWL_PCI_DEVICE(0x3DF0, 0x42A4, iwl9462_2ac_cfg_soc)},
2787 ++ {IWL_PCI_DEVICE(0x43F0, 0x0030, iwl9560_2ac_cfg_soc)},
2788 ++ {IWL_PCI_DEVICE(0x43F0, 0x0034, iwl9560_2ac_cfg_soc)},
2789 ++ {IWL_PCI_DEVICE(0x43F0, 0x0038, iwl9560_2ac_cfg_soc)},
2790 ++ {IWL_PCI_DEVICE(0x43F0, 0x003C, iwl9560_2ac_cfg_soc)},
2791 ++ {IWL_PCI_DEVICE(0x43F0, 0x0060, iwl9461_2ac_cfg_soc)},
2792 ++ {IWL_PCI_DEVICE(0x43F0, 0x0064, iwl9461_2ac_cfg_soc)},
2793 ++ {IWL_PCI_DEVICE(0x43F0, 0x00A0, iwl9462_2ac_cfg_soc)},
2794 ++ {IWL_PCI_DEVICE(0x43F0, 0x00A4, iwl9462_2ac_cfg_soc)},
2795 ++ {IWL_PCI_DEVICE(0x43F0, 0x0230, iwl9560_2ac_cfg_soc)},
2796 ++ {IWL_PCI_DEVICE(0x43F0, 0x0234, iwl9560_2ac_cfg_soc)},
2797 ++ {IWL_PCI_DEVICE(0x43F0, 0x0238, iwl9560_2ac_cfg_soc)},
2798 ++ {IWL_PCI_DEVICE(0x43F0, 0x023C, iwl9560_2ac_cfg_soc)},
2799 ++ {IWL_PCI_DEVICE(0x43F0, 0x0260, iwl9461_2ac_cfg_soc)},
2800 ++ {IWL_PCI_DEVICE(0x43F0, 0x0264, iwl9461_2ac_cfg_soc)},
2801 ++ {IWL_PCI_DEVICE(0x43F0, 0x02A0, iwl9462_2ac_cfg_soc)},
2802 ++ {IWL_PCI_DEVICE(0x43F0, 0x02A4, iwl9462_2ac_cfg_soc)},
2803 ++ {IWL_PCI_DEVICE(0x43F0, 0x1010, iwl9260_2ac_cfg)},
2804 ++ {IWL_PCI_DEVICE(0x43F0, 0x1030, iwl9560_2ac_cfg_soc)},
2805 ++ {IWL_PCI_DEVICE(0x43F0, 0x1210, iwl9260_2ac_cfg)},
2806 ++ {IWL_PCI_DEVICE(0x43F0, 0x2030, iwl9560_2ac_cfg_soc)},
2807 ++ {IWL_PCI_DEVICE(0x43F0, 0x2034, iwl9560_2ac_cfg_soc)},
2808 ++ {IWL_PCI_DEVICE(0x43F0, 0x4030, iwl9560_2ac_cfg_soc)},
2809 ++ {IWL_PCI_DEVICE(0x43F0, 0x4034, iwl9560_2ac_cfg_soc)},
2810 ++ {IWL_PCI_DEVICE(0x43F0, 0x40A4, iwl9462_2ac_cfg_soc)},
2811 ++ {IWL_PCI_DEVICE(0x43F0, 0x4234, iwl9560_2ac_cfg_soc)},
2812 ++ {IWL_PCI_DEVICE(0x43F0, 0x42A4, iwl9462_2ac_cfg_soc)},
2813 + {IWL_PCI_DEVICE(0x9DF0, 0x0000, iwl9460_2ac_cfg_soc)},
2814 + {IWL_PCI_DEVICE(0x9DF0, 0x0010, iwl9460_2ac_cfg_soc)},
2815 + {IWL_PCI_DEVICE(0x9DF0, 0x0030, iwl9560_2ac_cfg_soc)},
2816 +@@ -624,11 +738,44 @@ static const struct pci_device_id iwl_hw_card_ids[] = {
2817 + {IWL_PCI_DEVICE(0x9DF0, 0x0610, iwl9460_2ac_cfg_soc)},
2818 + {IWL_PCI_DEVICE(0x9DF0, 0x0710, iwl9460_2ac_cfg_soc)},
2819 + {IWL_PCI_DEVICE(0x9DF0, 0x0A10, iwl9460_2ac_cfg_soc)},
2820 ++ {IWL_PCI_DEVICE(0x9DF0, 0x1010, iwl9260_2ac_cfg)},
2821 ++ {IWL_PCI_DEVICE(0x9DF0, 0x1030, iwl9560_2ac_cfg_soc)},
2822 ++ {IWL_PCI_DEVICE(0x9DF0, 0x1210, iwl9260_2ac_cfg)},
2823 + {IWL_PCI_DEVICE(0x9DF0, 0x2010, iwl9460_2ac_cfg_soc)},
2824 ++ {IWL_PCI_DEVICE(0x9DF0, 0x2030, iwl9560_2ac_cfg_soc)},
2825 ++ {IWL_PCI_DEVICE(0x9DF0, 0x2034, iwl9560_2ac_cfg_soc)},
2826 + {IWL_PCI_DEVICE(0x9DF0, 0x2A10, iwl9460_2ac_cfg_soc)},
2827 + {IWL_PCI_DEVICE(0x9DF0, 0x4030, iwl9560_2ac_cfg_soc)},
2828 + {IWL_PCI_DEVICE(0x9DF0, 0x4034, iwl9560_2ac_cfg_soc)},
2829 + {IWL_PCI_DEVICE(0x9DF0, 0x40A4, iwl9462_2ac_cfg_soc)},
2830 ++ {IWL_PCI_DEVICE(0x9DF0, 0x4234, iwl9560_2ac_cfg_soc)},
2831 ++ {IWL_PCI_DEVICE(0x9DF0, 0x42A4, iwl9462_2ac_cfg_soc)},
2832 ++ {IWL_PCI_DEVICE(0xA0F0, 0x0030, iwl9560_2ac_cfg_soc)},
2833 ++ {IWL_PCI_DEVICE(0xA0F0, 0x0034, iwl9560_2ac_cfg_soc)},
2834 ++ {IWL_PCI_DEVICE(0xA0F0, 0x0038, iwl9560_2ac_cfg_soc)},
2835 ++ {IWL_PCI_DEVICE(0xA0F0, 0x003C, iwl9560_2ac_cfg_soc)},
2836 ++ {IWL_PCI_DEVICE(0xA0F0, 0x0060, iwl9461_2ac_cfg_soc)},
2837 ++ {IWL_PCI_DEVICE(0xA0F0, 0x0064, iwl9461_2ac_cfg_soc)},
2838 ++ {IWL_PCI_DEVICE(0xA0F0, 0x00A0, iwl9462_2ac_cfg_soc)},
2839 ++ {IWL_PCI_DEVICE(0xA0F0, 0x00A4, iwl9462_2ac_cfg_soc)},
2840 ++ {IWL_PCI_DEVICE(0xA0F0, 0x0230, iwl9560_2ac_cfg_soc)},
2841 ++ {IWL_PCI_DEVICE(0xA0F0, 0x0234, iwl9560_2ac_cfg_soc)},
2842 ++ {IWL_PCI_DEVICE(0xA0F0, 0x0238, iwl9560_2ac_cfg_soc)},
2843 ++ {IWL_PCI_DEVICE(0xA0F0, 0x023C, iwl9560_2ac_cfg_soc)},
2844 ++ {IWL_PCI_DEVICE(0xA0F0, 0x0260, iwl9461_2ac_cfg_soc)},
2845 ++ {IWL_PCI_DEVICE(0xA0F0, 0x0264, iwl9461_2ac_cfg_soc)},
2846 ++ {IWL_PCI_DEVICE(0xA0F0, 0x02A0, iwl9462_2ac_cfg_soc)},
2847 ++ {IWL_PCI_DEVICE(0xA0F0, 0x02A4, iwl9462_2ac_cfg_soc)},
2848 ++ {IWL_PCI_DEVICE(0xA0F0, 0x1010, iwl9260_2ac_cfg)},
2849 ++ {IWL_PCI_DEVICE(0xA0F0, 0x1030, iwl9560_2ac_cfg_soc)},
2850 ++ {IWL_PCI_DEVICE(0xA0F0, 0x1210, iwl9260_2ac_cfg)},
2851 ++ {IWL_PCI_DEVICE(0xA0F0, 0x2030, iwl9560_2ac_cfg_soc)},
2852 ++ {IWL_PCI_DEVICE(0xA0F0, 0x2034, iwl9560_2ac_cfg_soc)},
2853 ++ {IWL_PCI_DEVICE(0xA0F0, 0x4030, iwl9560_2ac_cfg_soc)},
2854 ++ {IWL_PCI_DEVICE(0xA0F0, 0x4034, iwl9560_2ac_cfg_soc)},
2855 ++ {IWL_PCI_DEVICE(0xA0F0, 0x40A4, iwl9462_2ac_cfg_soc)},
2856 ++ {IWL_PCI_DEVICE(0xA0F0, 0x4234, iwl9560_2ac_cfg_soc)},
2857 ++ {IWL_PCI_DEVICE(0xA0F0, 0x42A4, iwl9462_2ac_cfg_soc)},
2858 + {IWL_PCI_DEVICE(0xA370, 0x0030, iwl9560_2ac_cfg_soc)},
2859 + {IWL_PCI_DEVICE(0xA370, 0x0034, iwl9560_2ac_cfg_soc)},
2860 + {IWL_PCI_DEVICE(0xA370, 0x0038, iwl9560_2ac_cfg_soc)},
2861 +@@ -645,10 +792,16 @@ static const struct pci_device_id iwl_hw_card_ids[] = {
2862 + {IWL_PCI_DEVICE(0xA370, 0x0264, iwl9461_2ac_cfg_soc)},
2863 + {IWL_PCI_DEVICE(0xA370, 0x02A0, iwl9462_2ac_cfg_soc)},
2864 + {IWL_PCI_DEVICE(0xA370, 0x02A4, iwl9462_2ac_cfg_soc)},
2865 ++ {IWL_PCI_DEVICE(0xA370, 0x1010, iwl9260_2ac_cfg)},
2866 + {IWL_PCI_DEVICE(0xA370, 0x1030, iwl9560_2ac_cfg_soc)},
2867 ++ {IWL_PCI_DEVICE(0xA370, 0x1210, iwl9260_2ac_cfg)},
2868 ++ {IWL_PCI_DEVICE(0xA370, 0x2030, iwl9560_2ac_cfg_soc)},
2869 ++ {IWL_PCI_DEVICE(0xA370, 0x2034, iwl9560_2ac_cfg_soc)},
2870 + {IWL_PCI_DEVICE(0xA370, 0x4030, iwl9560_2ac_cfg_soc)},
2871 + {IWL_PCI_DEVICE(0xA370, 0x4034, iwl9560_2ac_cfg_soc)},
2872 + {IWL_PCI_DEVICE(0xA370, 0x40A4, iwl9462_2ac_cfg_soc)},
2873 ++ {IWL_PCI_DEVICE(0xA370, 0x4234, iwl9560_2ac_cfg_soc)},
2874 ++ {IWL_PCI_DEVICE(0xA370, 0x42A4, iwl9462_2ac_cfg_soc)},
2875 +
2876 + /* a000 Series */
2877 + {IWL_PCI_DEVICE(0x2720, 0x0A10, iwla000_2ac_cfg_hr_cdb)},
2878 +diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
2879 +index c980cdbd6e53..a9ba9fe263ca 100644
2880 +--- a/drivers/net/xen-netfront.c
2881 ++++ b/drivers/net/xen-netfront.c
2882 +@@ -2008,7 +2008,10 @@ static void netback_changed(struct xenbus_device *dev,
2883 + case XenbusStateInitialised:
2884 + case XenbusStateReconfiguring:
2885 + case XenbusStateReconfigured:
2886 ++ break;
2887 ++
2888 + case XenbusStateUnknown:
2889 ++ wake_up_all(&module_unload_q);
2890 + break;
2891 +
2892 + case XenbusStateInitWait:
2893 +@@ -2139,7 +2142,9 @@ static int xennet_remove(struct xenbus_device *dev)
2894 + xenbus_switch_state(dev, XenbusStateClosing);
2895 + wait_event(module_unload_q,
2896 + xenbus_read_driver_state(dev->otherend) ==
2897 +- XenbusStateClosing);
2898 ++ XenbusStateClosing ||
2899 ++ xenbus_read_driver_state(dev->otherend) ==
2900 ++ XenbusStateUnknown);
2901 +
2902 + xenbus_switch_state(dev, XenbusStateClosed);
2903 + wait_event(module_unload_q,
2904 +diff --git a/drivers/nvdimm/dimm.c b/drivers/nvdimm/dimm.c
2905 +index 98466d762c8f..0939f064054d 100644
2906 +--- a/drivers/nvdimm/dimm.c
2907 ++++ b/drivers/nvdimm/dimm.c
2908 +@@ -65,9 +65,11 @@ static int nvdimm_probe(struct device *dev)
2909 + ndd->ns_next = nd_label_next_nsindex(ndd->ns_current);
2910 + nd_label_copy(ndd, to_next_namespace_index(ndd),
2911 + to_current_namespace_index(ndd));
2912 +- rc = nd_label_reserve_dpa(ndd);
2913 +- if (ndd->ns_current >= 0)
2914 +- nvdimm_set_aliasing(dev);
2915 ++ if (ndd->ns_current >= 0) {
2916 ++ rc = nd_label_reserve_dpa(ndd);
2917 ++ if (rc == 0)
2918 ++ nvdimm_set_aliasing(dev);
2919 ++ }
2920 + nvdimm_clear_locked(dev);
2921 + nvdimm_bus_unlock(dev);
2922 +
2923 +diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
2924 +index 0af988739a06..228bafa4d322 100644
2925 +--- a/drivers/nvdimm/namespace_devs.c
2926 ++++ b/drivers/nvdimm/namespace_devs.c
2927 +@@ -1926,7 +1926,7 @@ struct device *create_namespace_pmem(struct nd_region *nd_region,
2928 + }
2929 +
2930 + if (i < nd_region->ndr_mappings) {
2931 +- struct nvdimm_drvdata *ndd = to_ndd(&nd_region->mapping[i]);
2932 ++ struct nvdimm *nvdimm = nd_region->mapping[i].nvdimm;
2933 +
2934 + /*
2935 + * Give up if we don't find an instance of a uuid at each
2936 +@@ -1934,7 +1934,7 @@ struct device *create_namespace_pmem(struct nd_region *nd_region,
2937 + * find a dimm with two instances of the same uuid.
2938 + */
2939 + dev_err(&nd_region->dev, "%s missing label for %pUb\n",
2940 +- dev_name(ndd->dev), nd_label->uuid);
2941 ++ nvdimm_name(nvdimm), nd_label->uuid);
2942 + rc = -EINVAL;
2943 + goto err;
2944 + }
2945 +diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
2946 +index 5ed2dcaa8e27..711875afdd70 100644
2947 +--- a/drivers/pci/hotplug/acpiphp_glue.c
2948 ++++ b/drivers/pci/hotplug/acpiphp_glue.c
2949 +@@ -558,6 +558,7 @@ static unsigned int get_slot_status(struct acpiphp_slot *slot)
2950 + {
2951 + unsigned long long sta = 0;
2952 + struct acpiphp_func *func;
2953 ++ u32 dvid;
2954 +
2955 + list_for_each_entry(func, &slot->funcs, sibling) {
2956 + if (func->flags & FUNC_HAS_STA) {
2957 +@@ -568,19 +569,27 @@ static unsigned int get_slot_status(struct acpiphp_slot *slot)
2958 + if (ACPI_SUCCESS(status) && sta)
2959 + break;
2960 + } else {
2961 +- u32 dvid;
2962 +-
2963 +- pci_bus_read_config_dword(slot->bus,
2964 +- PCI_DEVFN(slot->device,
2965 +- func->function),
2966 +- PCI_VENDOR_ID, &dvid);
2967 +- if (dvid != 0xffffffff) {
2968 ++ if (pci_bus_read_dev_vendor_id(slot->bus,
2969 ++ PCI_DEVFN(slot->device, func->function),
2970 ++ &dvid, 0)) {
2971 + sta = ACPI_STA_ALL;
2972 + break;
2973 + }
2974 + }
2975 + }
2976 +
2977 ++ if (!sta) {
2978 ++ /*
2979 ++ * Check for the slot itself since it may be that the
2980 ++ * ACPI slot is a device below PCIe upstream port so in
2981 ++ * that case it may not even be reachable yet.
2982 ++ */
2983 ++ if (pci_bus_read_dev_vendor_id(slot->bus,
2984 ++ PCI_DEVFN(slot->device, 0), &dvid, 0)) {
2985 ++ sta = ACPI_STA_ALL;
2986 ++ }
2987 ++ }
2988 ++
2989 + return (unsigned int)sta;
2990 + }
2991 +
2992 +diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
2993 +index 05fadcc4f9d2..5c5a8af66829 100644
2994 +--- a/drivers/pci/quirks.c
2995 ++++ b/drivers/pci/quirks.c
2996 +@@ -4806,9 +4806,13 @@ static void quirk_no_ext_tags(struct pci_dev *pdev)
2997 +
2998 + pci_walk_bus(bridge->bus, pci_configure_extended_tags, NULL);
2999 + }
3000 ++DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0132, quirk_no_ext_tags);
3001 + DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0140, quirk_no_ext_tags);
3002 ++DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0141, quirk_no_ext_tags);
3003 + DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0142, quirk_no_ext_tags);
3004 + DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0144, quirk_no_ext_tags);
3005 ++DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0420, quirk_no_ext_tags);
3006 ++DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0422, quirk_no_ext_tags);
3007 +
3008 + #ifdef CONFIG_PCI_ATS
3009 + /*
3010 +diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
3011 +index 1161e11fb3cf..afedb8cd1990 100644
3012 +--- a/drivers/phy/allwinner/phy-sun4i-usb.c
3013 ++++ b/drivers/phy/allwinner/phy-sun4i-usb.c
3014 +@@ -410,11 +410,13 @@ static bool sun4i_usb_phy0_poll(struct sun4i_usb_phy_data *data)
3015 + return true;
3016 +
3017 + /*
3018 +- * The A31 companion pmic (axp221) does not generate vbus change
3019 +- * interrupts when the board is driving vbus, so we must poll
3020 ++ * The A31/A23/A33 companion pmics (AXP221/AXP223) do not
3021 ++ * generate vbus change interrupts when the board is driving
3022 ++ * vbus using the N_VBUSEN pin on the pmic, so we must poll
3023 + * when using the pmic for vbus-det _and_ we're driving vbus.
3024 + */
3025 +- if (data->cfg->type == sun6i_a31_phy &&
3026 ++ if ((data->cfg->type == sun6i_a31_phy ||
3027 ++ data->cfg->type == sun8i_a33_phy) &&
3028 + data->vbus_power_supply && data->phys[0].regulator_on)
3029 + return true;
3030 +
3031 +@@ -885,7 +887,7 @@ static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
3032 +
3033 + static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
3034 + .num_phys = 2,
3035 +- .type = sun4i_a10_phy,
3036 ++ .type = sun6i_a31_phy,
3037 + .disc_thresh = 3,
3038 + .phyctl_offset = REG_PHYCTL_A10,
3039 + .dedicated_clocks = true,
3040 +diff --git a/drivers/pwm/pwm-rcar.c b/drivers/pwm/pwm-rcar.c
3041 +index 1c85ecc9e7ac..0fcf94ffad32 100644
3042 +--- a/drivers/pwm/pwm-rcar.c
3043 ++++ b/drivers/pwm/pwm-rcar.c
3044 +@@ -156,8 +156,12 @@ static int rcar_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
3045 + if (div < 0)
3046 + return div;
3047 +
3048 +- /* Let the core driver set pwm->period if disabled and duty_ns == 0 */
3049 +- if (!pwm_is_enabled(pwm) && !duty_ns)
3050 ++ /*
3051 ++ * Let the core driver set pwm->period if disabled and duty_ns == 0.
3052 ++ * But, this driver should prevent to set the new duty_ns if current
3053 ++ * duty_cycle is not set
3054 ++ */
3055 ++ if (!pwm_is_enabled(pwm) && !duty_ns && !pwm->state.duty_cycle)
3056 + return 0;
3057 +
3058 + rcar_pwm_update(rp, RCAR_PWMCR_SYNC, RCAR_PWMCR_SYNC, RCAR_PWMCR);
3059 +diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c
3060 +index e1ce8b1b5090..fb2a8b1e7979 100644
3061 +--- a/drivers/soc/mediatek/mtk-scpsys.c
3062 ++++ b/drivers/soc/mediatek/mtk-scpsys.c
3063 +@@ -892,7 +892,7 @@ static int scpsys_probe(struct platform_device *pdev)
3064 +
3065 + pd_data = &scp->pd_data;
3066 +
3067 +- for (i = 0, sd = soc->subdomains ; i < soc->num_subdomains ; i++) {
3068 ++ for (i = 0, sd = soc->subdomains; i < soc->num_subdomains; i++, sd++) {
3069 + ret = pm_genpd_add_subdomain(pd_data->domains[sd->origin],
3070 + pd_data->domains[sd->subdomain]);
3071 + if (ret && IS_ENABLED(CONFIG_PM))
3072 +diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
3073 +index 669470971023..047875861df1 100644
3074 +--- a/drivers/spi/spi-atmel.c
3075 ++++ b/drivers/spi/spi-atmel.c
3076 +@@ -1489,6 +1489,11 @@ static void atmel_spi_init(struct atmel_spi *as)
3077 + {
3078 + spi_writel(as, CR, SPI_BIT(SWRST));
3079 + spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
3080 ++
3081 ++ /* It is recommended to enable FIFOs first thing after reset */
3082 ++ if (as->fifo_size)
3083 ++ spi_writel(as, CR, SPI_BIT(FIFOEN));
3084 ++
3085 + if (as->caps.has_wdrbt) {
3086 + spi_writel(as, MR, SPI_BIT(WDRBT) | SPI_BIT(MODFDIS)
3087 + | SPI_BIT(MSTR));
3088 +@@ -1499,9 +1504,6 @@ static void atmel_spi_init(struct atmel_spi *as)
3089 + if (as->use_pdc)
3090 + spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
3091 + spi_writel(as, CR, SPI_BIT(SPIEN));
3092 +-
3093 +- if (as->fifo_size)
3094 +- spi_writel(as, CR, SPI_BIT(FIFOEN));
3095 + }
3096 +
3097 + static int atmel_spi_probe(struct platform_device *pdev)
3098 +diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
3099 +index 3ff0ee88c467..84dfef4bd6ae 100644
3100 +--- a/drivers/spi/spi.c
3101 ++++ b/drivers/spi/spi.c
3102 +@@ -779,8 +779,14 @@ static int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
3103 + for (i = 0; i < sgs; i++) {
3104 +
3105 + if (vmalloced_buf || kmap_buf) {
3106 +- min = min_t(size_t,
3107 +- len, desc_len - offset_in_page(buf));
3108 ++ /*
3109 ++ * Next scatterlist entry size is the minimum between
3110 ++ * the desc_len and the remaining buffer length that
3111 ++ * fits in a page.
3112 ++ */
3113 ++ min = min_t(size_t, desc_len,
3114 ++ min_t(size_t, len,
3115 ++ PAGE_SIZE - offset_in_page(buf)));
3116 + if (vmalloced_buf)
3117 + vm_page = vmalloc_to_page(buf);
3118 + else
3119 +@@ -2252,12 +2258,6 @@ void spi_unregister_controller(struct spi_controller *ctlr)
3120 + mutex_lock(&board_lock);
3121 + found = idr_find(&spi_master_idr, id);
3122 + mutex_unlock(&board_lock);
3123 +- if (found != ctlr) {
3124 +- dev_dbg(&ctlr->dev,
3125 +- "attempting to delete unregistered controller [%s]\n",
3126 +- dev_name(&ctlr->dev));
3127 +- return;
3128 +- }
3129 + if (ctlr->queued) {
3130 + if (spi_destroy_queue(ctlr))
3131 + dev_err(&ctlr->dev, "queue remove failed\n");
3132 +@@ -2270,7 +2270,8 @@ void spi_unregister_controller(struct spi_controller *ctlr)
3133 + device_unregister(&ctlr->dev);
3134 + /* free bus id */
3135 + mutex_lock(&board_lock);
3136 +- idr_remove(&spi_master_idr, id);
3137 ++ if (found == ctlr)
3138 ++ idr_remove(&spi_master_idr, id);
3139 + mutex_unlock(&board_lock);
3140 + }
3141 + EXPORT_SYMBOL_GPL(spi_unregister_controller);
3142 +diff --git a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c
3143 +index d8cfed358d55..f1d8cc5a2730 100644
3144 +--- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c
3145 ++++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c
3146 +@@ -1285,7 +1285,10 @@ const struct v4l2_file_operations atomisp_fops = {
3147 + .mmap = atomisp_mmap,
3148 + .unlocked_ioctl = video_ioctl2,
3149 + #ifdef CONFIG_COMPAT
3150 ++ /*
3151 ++ * There are problems with this code. Disable this for now.
3152 + .compat_ioctl32 = atomisp_compat_ioctl32,
3153 ++ */
3154 + #endif
3155 + .poll = atomisp_poll,
3156 + };
3157 +@@ -1297,7 +1300,10 @@ const struct v4l2_file_operations atomisp_file_fops = {
3158 + .mmap = atomisp_file_mmap,
3159 + .unlocked_ioctl = video_ioctl2,
3160 + #ifdef CONFIG_COMPAT
3161 ++ /*
3162 ++ * There are problems with this code. Disable this for now.
3163 + .compat_ioctl32 = atomisp_compat_ioctl32,
3164 ++ */
3165 + #endif
3166 + .poll = atomisp_poll,
3167 + };
3168 +diff --git a/drivers/staging/media/lirc/lirc_zilog.c b/drivers/staging/media/lirc/lirc_zilog.c
3169 +index 71af13bd0ebd..e35e1b2160e3 100644
3170 +--- a/drivers/staging/media/lirc/lirc_zilog.c
3171 ++++ b/drivers/staging/media/lirc/lirc_zilog.c
3172 +@@ -288,7 +288,7 @@ static void release_ir_tx(struct kref *ref)
3173 + struct IR_tx *tx = container_of(ref, struct IR_tx, ref);
3174 + struct IR *ir = tx->ir;
3175 +
3176 +- ir->l.features &= ~LIRC_CAN_SEND_LIRCCODE;
3177 ++ ir->l.features &= ~LIRC_CAN_SEND_PULSE;
3178 + /* Don't put_ir_device(tx->ir) here, so our lock doesn't get freed */
3179 + ir->tx = NULL;
3180 + kfree(tx);
3181 +@@ -1228,6 +1228,7 @@ static unsigned int poll(struct file *filep, poll_table *wait)
3182 +
3183 + dev_dbg(ir->l.dev, "%s result = %s\n", __func__,
3184 + ret ? "POLLIN|POLLRDNORM" : "none");
3185 ++ put_ir_rx(rx, false);
3186 + return ret;
3187 + }
3188 +
3189 +@@ -1267,14 +1268,14 @@ static long ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
3190 + if (!(features & LIRC_CAN_SEND_MASK))
3191 + return -ENOTTY;
3192 +
3193 +- result = put_user(LIRC_MODE_LIRCCODE, uptr);
3194 ++ result = put_user(LIRC_MODE_PULSE, uptr);
3195 + break;
3196 + case LIRC_SET_SEND_MODE:
3197 + if (!(features & LIRC_CAN_SEND_MASK))
3198 + return -ENOTTY;
3199 +
3200 + result = get_user(mode, uptr);
3201 +- if (!result && mode != LIRC_MODE_LIRCCODE)
3202 ++ if (!result && mode != LIRC_MODE_PULSE)
3203 + return -EINVAL;
3204 + break;
3205 + default:
3206 +@@ -1512,7 +1513,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
3207 + kref_init(&tx->ref);
3208 + ir->tx = tx;
3209 +
3210 +- ir->l.features |= LIRC_CAN_SEND_LIRCCODE;
3211 ++ ir->l.features |= LIRC_CAN_SEND_PULSE;
3212 + mutex_init(&tx->client_lock);
3213 + tx->c = client;
3214 + tx->need_boot = 1;
3215 +diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
3216 +index 4798b4b1fd77..41c6154ae856 100644
3217 +--- a/drivers/thermal/imx_thermal.c
3218 ++++ b/drivers/thermal/imx_thermal.c
3219 +@@ -601,6 +601,9 @@ static int imx_thermal_probe(struct platform_device *pdev)
3220 + regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN);
3221 + regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP);
3222 +
3223 ++ data->irq_enabled = true;
3224 ++ data->mode = THERMAL_DEVICE_ENABLED;
3225 ++
3226 + ret = devm_request_threaded_irq(&pdev->dev, data->irq,
3227 + imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread,
3228 + 0, "imx_thermal", data);
3229 +@@ -613,9 +616,6 @@ static int imx_thermal_probe(struct platform_device *pdev)
3230 + return ret;
3231 + }
3232 +
3233 +- data->irq_enabled = true;
3234 +- data->mode = THERMAL_DEVICE_ENABLED;
3235 +-
3236 + return 0;
3237 + }
3238 +
3239 +diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c
3240 +index 53250fc057e1..91830b1bdcaf 100644
3241 +--- a/drivers/thunderbolt/icm.c
3242 ++++ b/drivers/thunderbolt/icm.c
3243 +@@ -539,14 +539,14 @@ static bool icm_ar_is_supported(struct tb *tb)
3244 + static int icm_ar_get_mode(struct tb *tb)
3245 + {
3246 + struct tb_nhi *nhi = tb->nhi;
3247 +- int retries = 5;
3248 ++ int retries = 60;
3249 + u32 val;
3250 +
3251 + do {
3252 + val = ioread32(nhi->iobase + REG_FW_STS);
3253 + if (val & REG_FW_STS_NVM_AUTH_DONE)
3254 + break;
3255 +- msleep(30);
3256 ++ msleep(50);
3257 + } while (--retries);
3258 +
3259 + if (!retries) {
3260 +@@ -720,6 +720,9 @@ static int icm_firmware_reset(struct tb *tb, struct tb_nhi *nhi)
3261 + struct icm *icm = tb_priv(tb);
3262 + u32 val;
3263 +
3264 ++ if (!icm->upstream_port)
3265 ++ return -ENODEV;
3266 ++
3267 + /* Put ARC to wait for CIO reset event to happen */
3268 + val = ioread32(nhi->iobase + REG_FW_STS);
3269 + val |= REG_FW_STS_CIO_RESET_REQ;
3270 +@@ -859,6 +862,9 @@ static int icm_firmware_init(struct tb *tb)
3271 + break;
3272 +
3273 + default:
3274 ++ if (ret < 0)
3275 ++ return ret;
3276 ++
3277 + tb_err(tb, "ICM firmware is in wrong mode: %u\n", ret);
3278 + return -ENODEV;
3279 + }
3280 +diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
3281 +index 05af126a2435..16c607075ede 100644
3282 +--- a/drivers/thunderbolt/nhi.c
3283 ++++ b/drivers/thunderbolt/nhi.c
3284 +@@ -846,6 +846,7 @@ static const struct dev_pm_ops nhi_pm_ops = {
3285 + * we just disable hotplug, the
3286 + * pci-tunnels stay alive.
3287 + */
3288 ++ .thaw_noirq = nhi_resume_noirq,
3289 + .restore_noirq = nhi_resume_noirq,
3290 + .suspend = nhi_suspend,
3291 + .freeze = nhi_suspend,
3292 +diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
3293 +index 3953d17202a8..8bd137109980 100644
3294 +--- a/drivers/thunderbolt/switch.c
3295 ++++ b/drivers/thunderbolt/switch.c
3296 +@@ -716,6 +716,13 @@ static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val)
3297 + if (sw->authorized)
3298 + goto unlock;
3299 +
3300 ++ /*
3301 ++ * Make sure there is no PCIe rescan ongoing when a new PCIe
3302 ++ * tunnel is created. Otherwise the PCIe rescan code might find
3303 ++ * the new tunnel too early.
3304 ++ */
3305 ++ pci_lock_rescan_remove();
3306 ++
3307 + switch (val) {
3308 + /* Approve switch */
3309 + case 1:
3310 +@@ -735,6 +742,8 @@ static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val)
3311 + break;
3312 + }
3313 +
3314 ++ pci_unlock_rescan_remove();
3315 ++
3316 + if (!ret) {
3317 + sw->authorized = val;
3318 + /* Notify status change to the userspace */
3319 +diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
3320 +index faf50df81622..1c70541a1467 100644
3321 +--- a/drivers/tty/n_tty.c
3322 ++++ b/drivers/tty/n_tty.c
3323 +@@ -2182,6 +2182,12 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
3324 + }
3325 + if (tty_hung_up_p(file))
3326 + break;
3327 ++ /*
3328 ++ * Abort readers for ttys which never actually
3329 ++ * get hung up. See __tty_hangup().
3330 ++ */
3331 ++ if (test_bit(TTY_HUPPING, &tty->flags))
3332 ++ break;
3333 + if (!timeout)
3334 + break;
3335 + if (file->f_flags & O_NONBLOCK) {
3336 +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
3337 +index 7e77bd2118ad..52627478ab61 100644
3338 +--- a/drivers/tty/tty_io.c
3339 ++++ b/drivers/tty/tty_io.c
3340 +@@ -585,6 +585,14 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
3341 + return;
3342 + }
3343 +
3344 ++ /*
3345 ++ * Some console devices aren't actually hung up for technical and
3346 ++ * historical reasons, which can lead to indefinite interruptible
3347 ++ * sleep in n_tty_read(). The following explicitly tells
3348 ++ * n_tty_read() to abort readers.
3349 ++ */
3350 ++ set_bit(TTY_HUPPING, &tty->flags);
3351 ++
3352 + /* inuse_filps is protected by the single tty lock,
3353 + this really needs to change if we want to flush the
3354 + workqueue with the lock held */
3355 +@@ -639,6 +647,7 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
3356 + * from the ldisc side, which is now guaranteed.
3357 + */
3358 + set_bit(TTY_HUPPED, &tty->flags);
3359 ++ clear_bit(TTY_HUPPING, &tty->flags);
3360 + tty_unlock(tty);
3361 +
3362 + if (f)
3363 +diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
3364 +index bd3e0c5a6db2..212289c55b6f 100644
3365 +--- a/drivers/usb/core/generic.c
3366 ++++ b/drivers/usb/core/generic.c
3367 +@@ -210,8 +210,13 @@ static int generic_suspend(struct usb_device *udev, pm_message_t msg)
3368 + if (!udev->parent)
3369 + rc = hcd_bus_suspend(udev, msg);
3370 +
3371 +- /* Non-root devices don't need to do anything for FREEZE or PRETHAW */
3372 +- else if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_PRETHAW)
3373 ++ /*
3374 ++ * Non-root USB2 devices don't need to do anything for FREEZE
3375 ++ * or PRETHAW. USB3 devices don't support global suspend and
3376 ++ * needs to be selectively suspended.
3377 ++ */
3378 ++ else if ((msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_PRETHAW)
3379 ++ && (udev->speed < USB_SPEED_SUPER))
3380 + rc = 0;
3381 + else
3382 + rc = usb_port_suspend(udev, msg);
3383 +diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
3384 +index 3219d8157f5b..c3f3f1a89b0f 100644
3385 +--- a/drivers/usb/dwc3/core.c
3386 ++++ b/drivers/usb/dwc3/core.c
3387 +@@ -128,6 +128,9 @@ static void __dwc3_set_mode(struct work_struct *work)
3388 + if (dwc->dr_mode != USB_DR_MODE_OTG)
3389 + return;
3390 +
3391 ++ if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG)
3392 ++ return;
3393 ++
3394 + switch (dwc->current_dr_role) {
3395 + case DWC3_GCTL_PRTCAP_HOST:
3396 + dwc3_host_exit(dwc);
3397 +diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
3398 +index 54343fbd85ee..bc5e91d4fac8 100644
3399 +--- a/drivers/usb/dwc3/dwc3-pci.c
3400 ++++ b/drivers/usb/dwc3/dwc3-pci.c
3401 +@@ -212,7 +212,7 @@ static int dwc3_pci_probe(struct pci_dev *pci,
3402 + ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
3403 + if (ret) {
3404 + dev_err(dev, "couldn't add resources to dwc3 device\n");
3405 +- return ret;
3406 ++ goto err;
3407 + }
3408 +
3409 + dwc->pci = pci;
3410 +diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
3411 +index 0ebdb313bb00..fe75e969f5ac 100644
3412 +--- a/drivers/usb/dwc3/gadget.c
3413 ++++ b/drivers/usb/dwc3/gadget.c
3414 +@@ -174,18 +174,8 @@ static void dwc3_ep_inc_deq(struct dwc3_ep *dep)
3415 + dwc3_ep_inc_trb(&dep->trb_dequeue);
3416 + }
3417 +
3418 +-/**
3419 +- * dwc3_gadget_giveback - call struct usb_request's ->complete callback
3420 +- * @dep: The endpoint to whom the request belongs to
3421 +- * @req: The request we're giving back
3422 +- * @status: completion code for the request
3423 +- *
3424 +- * Must be called with controller's lock held and interrupts disabled. This
3425 +- * function will unmap @req and call its ->complete() callback to notify upper
3426 +- * layers that it has completed.
3427 +- */
3428 +-void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
3429 +- int status)
3430 ++void dwc3_gadget_del_and_unmap_request(struct dwc3_ep *dep,
3431 ++ struct dwc3_request *req, int status)
3432 + {
3433 + struct dwc3 *dwc = dep->dwc;
3434 +
3435 +@@ -198,18 +188,35 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
3436 +
3437 + if (req->trb)
3438 + usb_gadget_unmap_request_by_dev(dwc->sysdev,
3439 +- &req->request, req->direction);
3440 ++ &req->request, req->direction);
3441 +
3442 + req->trb = NULL;
3443 +-
3444 + trace_dwc3_gadget_giveback(req);
3445 +
3446 ++ if (dep->number > 1)
3447 ++ pm_runtime_put(dwc->dev);
3448 ++}
3449 ++
3450 ++/**
3451 ++ * dwc3_gadget_giveback - call struct usb_request's ->complete callback
3452 ++ * @dep: The endpoint to whom the request belongs to
3453 ++ * @req: The request we're giving back
3454 ++ * @status: completion code for the request
3455 ++ *
3456 ++ * Must be called with controller's lock held and interrupts disabled. This
3457 ++ * function will unmap @req and call its ->complete() callback to notify upper
3458 ++ * layers that it has completed.
3459 ++ */
3460 ++void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
3461 ++ int status)
3462 ++{
3463 ++ struct dwc3 *dwc = dep->dwc;
3464 ++
3465 ++ dwc3_gadget_del_and_unmap_request(dep, req, status);
3466 ++
3467 + spin_unlock(&dwc->lock);
3468 + usb_gadget_giveback_request(&dep->endpoint, &req->request);
3469 + spin_lock(&dwc->lock);
3470 +-
3471 +- if (dep->number > 1)
3472 +- pm_runtime_put(dwc->dev);
3473 + }
3474 +
3475 + /**
3476 +@@ -1233,7 +1240,7 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param)
3477 + if (req->trb)
3478 + memset(req->trb, 0, sizeof(struct dwc3_trb));
3479 + dep->queued_requests--;
3480 +- dwc3_gadget_giveback(dep, req, ret);
3481 ++ dwc3_gadget_del_and_unmap_request(dep, req, ret);
3482 + return ret;
3483 + }
3484 +
3485 +diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
3486 +index 5d3d7941d2c2..71cf552b8828 100644
3487 +--- a/drivers/usb/gadget/function/f_midi.c
3488 ++++ b/drivers/usb/gadget/function/f_midi.c
3489 +@@ -405,7 +405,8 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
3490 + if (err) {
3491 + ERROR(midi, "%s: couldn't enqueue request: %d\n",
3492 + midi->out_ep->name, err);
3493 +- free_ep_req(midi->out_ep, req);
3494 ++ if (req->buf != NULL)
3495 ++ free_ep_req(midi->out_ep, req);
3496 + return err;
3497 + }
3498 + }
3499 +diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
3500 +index 7d53a4773d1a..2f03334c6874 100644
3501 +--- a/drivers/usb/gadget/u_f.h
3502 ++++ b/drivers/usb/gadget/u_f.h
3503 +@@ -64,7 +64,9 @@ struct usb_request *alloc_ep_req(struct usb_ep *ep, size_t len);
3504 + /* Frees a usb_request previously allocated by alloc_ep_req() */
3505 + static inline void free_ep_req(struct usb_ep *ep, struct usb_request *req)
3506 + {
3507 ++ WARN_ON(req->buf == NULL);
3508 + kfree(req->buf);
3509 ++ req->buf = NULL;
3510 + usb_ep_free_request(ep, req);
3511 + }
3512 +
3513 +diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
3514 +index 794bb4958383..5bab09294a8a 100644
3515 +--- a/drivers/usb/gadget/udc/core.c
3516 ++++ b/drivers/usb/gadget/udc/core.c
3517 +@@ -249,6 +249,9 @@ EXPORT_SYMBOL_GPL(usb_ep_free_request);
3518 + * arranges to poll once per interval, and the gadget driver usually will
3519 + * have queued some data to transfer at that time.
3520 + *
3521 ++ * Note that @req's ->complete() callback must never be called from
3522 ++ * within usb_ep_queue() as that can create deadlock situations.
3523 ++ *
3524 + * Returns zero, or a negative error code. Endpoints that are not enabled
3525 + * report errors; errors will also be
3526 + * reported when the usb peripheral is disconnected.
3527 +diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
3528 +index 844a309fe895..e85b9c2a4910 100644
3529 +--- a/drivers/usb/musb/musb_gadget_ep0.c
3530 ++++ b/drivers/usb/musb/musb_gadget_ep0.c
3531 +@@ -114,15 +114,19 @@ static int service_tx_status_request(
3532 + }
3533 +
3534 + is_in = epnum & USB_DIR_IN;
3535 +- if (is_in) {
3536 +- epnum &= 0x0f;
3537 ++ epnum &= 0x0f;
3538 ++ if (epnum >= MUSB_C_NUM_EPS) {
3539 ++ handled = -EINVAL;
3540 ++ break;
3541 ++ }
3542 ++
3543 ++ if (is_in)
3544 + ep = &musb->endpoints[epnum].ep_in;
3545 +- } else {
3546 ++ else
3547 + ep = &musb->endpoints[epnum].ep_out;
3548 +- }
3549 + regs = musb->endpoints[epnum].regs;
3550 +
3551 +- if (epnum >= MUSB_C_NUM_EPS || !ep->desc) {
3552 ++ if (!ep->desc) {
3553 + handled = -EINVAL;
3554 + break;
3555 + }
3556 +diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
3557 +index 91335e6de88a..115a36f6f403 100644
3558 +--- a/drivers/vfio/pci/vfio_pci_config.c
3559 ++++ b/drivers/vfio/pci/vfio_pci_config.c
3560 +@@ -808,6 +808,7 @@ static int vfio_exp_config_write(struct vfio_pci_device *vdev, int pos,
3561 + {
3562 + __le16 *ctrl = (__le16 *)(vdev->vconfig + pos -
3563 + offset + PCI_EXP_DEVCTL);
3564 ++ int readrq = le16_to_cpu(*ctrl) & PCI_EXP_DEVCTL_READRQ;
3565 +
3566 + count = vfio_default_config_write(vdev, pos, count, perm, offset, val);
3567 + if (count < 0)
3568 +@@ -833,6 +834,27 @@ static int vfio_exp_config_write(struct vfio_pci_device *vdev, int pos,
3569 + pci_try_reset_function(vdev->pdev);
3570 + }
3571 +
3572 ++ /*
3573 ++ * MPS is virtualized to the user, writes do not change the physical
3574 ++ * register since determining a proper MPS value requires a system wide
3575 ++ * device view. The MRRS is largely independent of MPS, but since the
3576 ++ * user does not have that system-wide view, they might set a safe, but
3577 ++ * inefficiently low value. Here we allow writes through to hardware,
3578 ++ * but we set the floor to the physical device MPS setting, so that
3579 ++ * we can at least use full TLPs, as defined by the MPS value.
3580 ++ *
3581 ++ * NB, if any devices actually depend on an artificially low MRRS
3582 ++ * setting, this will need to be revisited, perhaps with a quirk
3583 ++ * though pcie_set_readrq().
3584 ++ */
3585 ++ if (readrq != (le16_to_cpu(*ctrl) & PCI_EXP_DEVCTL_READRQ)) {
3586 ++ readrq = 128 <<
3587 ++ ((le16_to_cpu(*ctrl) & PCI_EXP_DEVCTL_READRQ) >> 12);
3588 ++ readrq = max(readrq, pcie_get_mps(vdev->pdev));
3589 ++
3590 ++ pcie_set_readrq(vdev->pdev, readrq);
3591 ++ }
3592 ++
3593 + return count;
3594 + }
3595 +
3596 +@@ -851,11 +873,12 @@ static int __init init_pci_cap_exp_perm(struct perm_bits *perm)
3597 + * Allow writes to device control fields, except devctl_phantom,
3598 + * which could confuse IOMMU, MPS, which can break communication
3599 + * with other physical devices, and the ARI bit in devctl2, which
3600 +- * is set at probe time. FLR gets virtualized via our writefn.
3601 ++ * is set at probe time. FLR and MRRS get virtualized via our
3602 ++ * writefn.
3603 + */
3604 + p_setw(perm, PCI_EXP_DEVCTL,
3605 +- PCI_EXP_DEVCTL_BCR_FLR | PCI_EXP_DEVCTL_PAYLOAD,
3606 +- ~PCI_EXP_DEVCTL_PHANTOM);
3607 ++ PCI_EXP_DEVCTL_BCR_FLR | PCI_EXP_DEVCTL_PAYLOAD |
3608 ++ PCI_EXP_DEVCTL_READRQ, ~PCI_EXP_DEVCTL_PHANTOM);
3609 + p_setw(perm, PCI_EXP_DEVCTL2, NO_VIRT, ~PCI_EXP_DEVCTL2_ARI);
3610 + return 0;
3611 + }
3612 +diff --git a/drivers/watchdog/f71808e_wdt.c b/drivers/watchdog/f71808e_wdt.c
3613 +index 8658dba21768..e682bf046e50 100644
3614 +--- a/drivers/watchdog/f71808e_wdt.c
3615 ++++ b/drivers/watchdog/f71808e_wdt.c
3616 +@@ -496,7 +496,7 @@ static bool watchdog_is_running(void)
3617 +
3618 + is_running = (superio_inb(watchdog.sioaddr, SIO_REG_ENABLE) & BIT(0))
3619 + && (superio_inb(watchdog.sioaddr, F71808FG_REG_WDT_CONF)
3620 +- & F71808FG_FLAG_WD_EN);
3621 ++ & BIT(F71808FG_FLAG_WD_EN));
3622 +
3623 + superio_exit(watchdog.sioaddr);
3624 +
3625 +diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
3626 +index 82e8f6edfb48..b12e37f27530 100644
3627 +--- a/fs/autofs4/root.c
3628 ++++ b/fs/autofs4/root.c
3629 +@@ -749,7 +749,7 @@ static int autofs4_dir_mkdir(struct inode *dir,
3630 +
3631 + autofs4_del_active(dentry);
3632 +
3633 +- inode = autofs4_get_inode(dir->i_sb, S_IFDIR | 0555);
3634 ++ inode = autofs4_get_inode(dir->i_sb, S_IFDIR | mode);
3635 + if (!inode)
3636 + return -ENOMEM;
3637 + d_add(dentry, inode);
3638 +diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig
3639 +index d5b2e12b5d02..cb0f1fbe836d 100644
3640 +--- a/fs/cifs/Kconfig
3641 ++++ b/fs/cifs/Kconfig
3642 +@@ -190,6 +190,7 @@ config CIFS_NFSD_EXPORT
3643 + config CIFS_SMB311
3644 + bool "SMB3.1.1 network file system support (Experimental)"
3645 + depends on CIFS
3646 ++ select CRYPTO_SHA512
3647 +
3648 + help
3649 + This enables experimental support for the newest, SMB3.1.1, dialect.
3650 +diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
3651 +index f2b0a7f124da..a6ef088e057b 100644
3652 +--- a/fs/cifs/cifsencrypt.c
3653 ++++ b/fs/cifs/cifsencrypt.c
3654 +@@ -36,37 +36,6 @@
3655 + #include <crypto/skcipher.h>
3656 + #include <crypto/aead.h>
3657 +
3658 +-static int
3659 +-cifs_crypto_shash_md5_allocate(struct TCP_Server_Info *server)
3660 +-{
3661 +- int rc;
3662 +- unsigned int size;
3663 +-
3664 +- if (server->secmech.sdescmd5 != NULL)
3665 +- return 0; /* already allocated */
3666 +-
3667 +- server->secmech.md5 = crypto_alloc_shash("md5", 0, 0);
3668 +- if (IS_ERR(server->secmech.md5)) {
3669 +- cifs_dbg(VFS, "could not allocate crypto md5\n");
3670 +- rc = PTR_ERR(server->secmech.md5);
3671 +- server->secmech.md5 = NULL;
3672 +- return rc;
3673 +- }
3674 +-
3675 +- size = sizeof(struct shash_desc) +
3676 +- crypto_shash_descsize(server->secmech.md5);
3677 +- server->secmech.sdescmd5 = kmalloc(size, GFP_KERNEL);
3678 +- if (!server->secmech.sdescmd5) {
3679 +- crypto_free_shash(server->secmech.md5);
3680 +- server->secmech.md5 = NULL;
3681 +- return -ENOMEM;
3682 +- }
3683 +- server->secmech.sdescmd5->shash.tfm = server->secmech.md5;
3684 +- server->secmech.sdescmd5->shash.flags = 0x0;
3685 +-
3686 +- return 0;
3687 +-}
3688 +-
3689 + int __cifs_calc_signature(struct smb_rqst *rqst,
3690 + struct TCP_Server_Info *server, char *signature,
3691 + struct shash_desc *shash)
3692 +@@ -132,13 +101,10 @@ static int cifs_calc_signature(struct smb_rqst *rqst,
3693 + if (!rqst->rq_iov || !signature || !server)
3694 + return -EINVAL;
3695 +
3696 +- if (!server->secmech.sdescmd5) {
3697 +- rc = cifs_crypto_shash_md5_allocate(server);
3698 +- if (rc) {
3699 +- cifs_dbg(VFS, "%s: Can't alloc md5 crypto\n", __func__);
3700 +- return -1;
3701 +- }
3702 +- }
3703 ++ rc = cifs_alloc_hash("md5", &server->secmech.md5,
3704 ++ &server->secmech.sdescmd5);
3705 ++ if (rc)
3706 ++ return -1;
3707 +
3708 + rc = crypto_shash_init(&server->secmech.sdescmd5->shash);
3709 + if (rc) {
3710 +@@ -663,37 +629,6 @@ CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
3711 + return rc;
3712 + }
3713 +
3714 +-static int crypto_hmacmd5_alloc(struct TCP_Server_Info *server)
3715 +-{
3716 +- int rc;
3717 +- unsigned int size;
3718 +-
3719 +- /* check if already allocated */
3720 +- if (server->secmech.sdeschmacmd5)
3721 +- return 0;
3722 +-
3723 +- server->secmech.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0);
3724 +- if (IS_ERR(server->secmech.hmacmd5)) {
3725 +- cifs_dbg(VFS, "could not allocate crypto hmacmd5\n");
3726 +- rc = PTR_ERR(server->secmech.hmacmd5);
3727 +- server->secmech.hmacmd5 = NULL;
3728 +- return rc;
3729 +- }
3730 +-
3731 +- size = sizeof(struct shash_desc) +
3732 +- crypto_shash_descsize(server->secmech.hmacmd5);
3733 +- server->secmech.sdeschmacmd5 = kmalloc(size, GFP_KERNEL);
3734 +- if (!server->secmech.sdeschmacmd5) {
3735 +- crypto_free_shash(server->secmech.hmacmd5);
3736 +- server->secmech.hmacmd5 = NULL;
3737 +- return -ENOMEM;
3738 +- }
3739 +- server->secmech.sdeschmacmd5->shash.tfm = server->secmech.hmacmd5;
3740 +- server->secmech.sdeschmacmd5->shash.flags = 0x0;
3741 +-
3742 +- return 0;
3743 +-}
3744 +-
3745 + int
3746 + setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
3747 + {
3748 +@@ -757,9 +692,10 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
3749 +
3750 + mutex_lock(&ses->server->srv_mutex);
3751 +
3752 +- rc = crypto_hmacmd5_alloc(ses->server);
3753 ++ rc = cifs_alloc_hash("hmac(md5)",
3754 ++ &ses->server->secmech.hmacmd5,
3755 ++ &ses->server->secmech.sdeschmacmd5);
3756 + if (rc) {
3757 +- cifs_dbg(VFS, "could not crypto alloc hmacmd5 rc %d\n", rc);
3758 + goto unlock;
3759 + }
3760 +
3761 +@@ -893,6 +829,11 @@ cifs_crypto_secmech_release(struct TCP_Server_Info *server)
3762 + server->secmech.md5 = NULL;
3763 + }
3764 +
3765 ++ if (server->secmech.sha512) {
3766 ++ crypto_free_shash(server->secmech.sha512);
3767 ++ server->secmech.sha512 = NULL;
3768 ++ }
3769 ++
3770 + if (server->secmech.hmacmd5) {
3771 + crypto_free_shash(server->secmech.hmacmd5);
3772 + server->secmech.hmacmd5 = NULL;
3773 +@@ -916,4 +857,6 @@ cifs_crypto_secmech_release(struct TCP_Server_Info *server)
3774 + server->secmech.sdeschmacmd5 = NULL;
3775 + kfree(server->secmech.sdescmd5);
3776 + server->secmech.sdescmd5 = NULL;
3777 ++ kfree(server->secmech.sdescsha512);
3778 ++ server->secmech.sdescsha512 = NULL;
3779 + }
3780 +diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
3781 +index 8c8b75d33f31..dbcd2e066066 100644
3782 +--- a/fs/cifs/cifsfs.c
3783 ++++ b/fs/cifs/cifsfs.c
3784 +@@ -1476,6 +1476,7 @@ MODULE_SOFTDEP("pre: nls");
3785 + MODULE_SOFTDEP("pre: aes");
3786 + MODULE_SOFTDEP("pre: cmac");
3787 + MODULE_SOFTDEP("pre: sha256");
3788 ++MODULE_SOFTDEP("pre: sha512");
3789 + MODULE_SOFTDEP("pre: aead2");
3790 + MODULE_SOFTDEP("pre: ccm");
3791 + module_init(init_cifs)
3792 +diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
3793 +index e185b2853eab..33d6eb58ce34 100644
3794 +--- a/fs/cifs/cifsglob.h
3795 ++++ b/fs/cifs/cifsglob.h
3796 +@@ -130,10 +130,12 @@ struct cifs_secmech {
3797 + struct crypto_shash *md5; /* md5 hash function */
3798 + struct crypto_shash *hmacsha256; /* hmac-sha256 hash function */
3799 + struct crypto_shash *cmacaes; /* block-cipher based MAC function */
3800 ++ struct crypto_shash *sha512; /* sha512 hash function */
3801 + struct sdesc *sdeschmacmd5; /* ctxt to generate ntlmv2 hash, CR1 */
3802 + struct sdesc *sdescmd5; /* ctxt to generate cifs/smb signature */
3803 + struct sdesc *sdeschmacsha256; /* ctxt to generate smb2 signature */
3804 + struct sdesc *sdesccmacaes; /* ctxt to generate smb3 signature */
3805 ++ struct sdesc *sdescsha512; /* ctxt to generate smb3.11 signing key */
3806 + struct crypto_aead *ccmaesencrypt; /* smb3 encryption aead */
3807 + struct crypto_aead *ccmaesdecrypt; /* smb3 decryption aead */
3808 + };
3809 +@@ -1449,6 +1451,7 @@ struct dfs_info3_param {
3810 + #define CIFS_FATTR_NEED_REVAL 0x4
3811 + #define CIFS_FATTR_INO_COLLISION 0x8
3812 + #define CIFS_FATTR_UNKNOWN_NLINK 0x10
3813 ++#define CIFS_FATTR_FAKE_ROOT_INO 0x20
3814 +
3815 + struct cifs_fattr {
3816 + u32 cf_flags;
3817 +diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
3818 +index 4143c9dec463..762d513a5087 100644
3819 +--- a/fs/cifs/cifsproto.h
3820 ++++ b/fs/cifs/cifsproto.h
3821 +@@ -538,4 +538,9 @@ enum securityEnum cifs_select_sectype(struct TCP_Server_Info *,
3822 + struct cifs_aio_ctx *cifs_aio_ctx_alloc(void);
3823 + void cifs_aio_ctx_release(struct kref *refcount);
3824 + int setup_aio_ctx_iter(struct cifs_aio_ctx *ctx, struct iov_iter *iter, int rw);
3825 ++
3826 ++int cifs_alloc_hash(const char *name, struct crypto_shash **shash,
3827 ++ struct sdesc **sdesc);
3828 ++void cifs_free_hash(struct crypto_shash **shash, struct sdesc **sdesc);
3829 ++
3830 + #endif /* _CIFSPROTO_H */
3831 +diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
3832 +index 7c732cb44164..0c7b7e2a0919 100644
3833 +--- a/fs/cifs/inode.c
3834 ++++ b/fs/cifs/inode.c
3835 +@@ -707,6 +707,18 @@ cifs_get_file_info(struct file *filp)
3836 + return rc;
3837 + }
3838 +
3839 ++/* Simple function to return a 64 bit hash of string. Rarely called */
3840 ++static __u64 simple_hashstr(const char *str)
3841 ++{
3842 ++ const __u64 hash_mult = 1125899906842597L; /* a big enough prime */
3843 ++ __u64 hash = 0;
3844 ++
3845 ++ while (*str)
3846 ++ hash = (hash + (__u64) *str++) * hash_mult;
3847 ++
3848 ++ return hash;
3849 ++}
3850 ++
3851 + int
3852 + cifs_get_inode_info(struct inode **inode, const char *full_path,
3853 + FILE_ALL_INFO *data, struct super_block *sb, int xid,
3854 +@@ -816,6 +828,14 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
3855 + tmprc);
3856 + fattr.cf_uniqueid = iunique(sb, ROOT_I);
3857 + cifs_autodisable_serverino(cifs_sb);
3858 ++ } else if ((fattr.cf_uniqueid == 0) &&
3859 ++ strlen(full_path) == 0) {
3860 ++ /* some servers ret bad root ino ie 0 */
3861 ++ cifs_dbg(FYI, "Invalid (0) inodenum\n");
3862 ++ fattr.cf_flags |=
3863 ++ CIFS_FATTR_FAKE_ROOT_INO;
3864 ++ fattr.cf_uniqueid =
3865 ++ simple_hashstr(tcon->treeName);
3866 + }
3867 + }
3868 + } else
3869 +@@ -832,6 +852,16 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
3870 + &fattr.cf_uniqueid, data);
3871 + if (tmprc)
3872 + fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid;
3873 ++ else if ((fattr.cf_uniqueid == 0) &&
3874 ++ strlen(full_path) == 0) {
3875 ++ /*
3876 ++ * Reuse existing root inode num since
3877 ++ * inum zero for root causes ls of . and .. to
3878 ++ * not be returned
3879 ++ */
3880 ++ cifs_dbg(FYI, "Srv ret 0 inode num for root\n");
3881 ++ fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid;
3882 ++ }
3883 + } else
3884 + fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid;
3885 + }
3886 +@@ -893,6 +923,9 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
3887 + }
3888 +
3889 + cgii_exit:
3890 ++ if ((*inode) && ((*inode)->i_ino == 0))
3891 ++ cifs_dbg(FYI, "inode number of zero returned\n");
3892 ++
3893 + kfree(buf);
3894 + cifs_put_tlink(tlink);
3895 + return rc;
3896 +diff --git a/fs/cifs/link.c b/fs/cifs/link.c
3897 +index 60b5a11ee11b..889a840172eb 100644
3898 +--- a/fs/cifs/link.c
3899 ++++ b/fs/cifs/link.c
3900 +@@ -50,25 +50,12 @@ static int
3901 + symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
3902 + {
3903 + int rc;
3904 +- unsigned int size;
3905 +- struct crypto_shash *md5;
3906 +- struct sdesc *sdescmd5;
3907 +-
3908 +- md5 = crypto_alloc_shash("md5", 0, 0);
3909 +- if (IS_ERR(md5)) {
3910 +- rc = PTR_ERR(md5);
3911 +- cifs_dbg(VFS, "%s: Crypto md5 allocation error %d\n",
3912 +- __func__, rc);
3913 +- return rc;
3914 +- }
3915 +- size = sizeof(struct shash_desc) + crypto_shash_descsize(md5);
3916 +- sdescmd5 = kmalloc(size, GFP_KERNEL);
3917 +- if (!sdescmd5) {
3918 +- rc = -ENOMEM;
3919 ++ struct crypto_shash *md5 = NULL;
3920 ++ struct sdesc *sdescmd5 = NULL;
3921 ++
3922 ++ rc = cifs_alloc_hash("md5", &md5, &sdescmd5);
3923 ++ if (rc)
3924 + goto symlink_hash_err;
3925 +- }
3926 +- sdescmd5->shash.tfm = md5;
3927 +- sdescmd5->shash.flags = 0x0;
3928 +
3929 + rc = crypto_shash_init(&sdescmd5->shash);
3930 + if (rc) {
3931 +@@ -85,9 +72,7 @@ symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
3932 + cifs_dbg(VFS, "%s: Could not generate md5 hash\n", __func__);
3933 +
3934 + symlink_hash_err:
3935 +- crypto_free_shash(md5);
3936 +- kfree(sdescmd5);
3937 +-
3938 ++ cifs_free_hash(&md5, &sdescmd5);
3939 + return rc;
3940 + }
3941 +
3942 +diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
3943 +index a0dbced4a45c..460084a8eac5 100644
3944 +--- a/fs/cifs/misc.c
3945 ++++ b/fs/cifs/misc.c
3946 +@@ -848,3 +848,57 @@ setup_aio_ctx_iter(struct cifs_aio_ctx *ctx, struct iov_iter *iter, int rw)
3947 + iov_iter_bvec(&ctx->iter, ITER_BVEC | rw, ctx->bv, npages, ctx->len);
3948 + return 0;
3949 + }
3950 ++
3951 ++/**
3952 ++ * cifs_alloc_hash - allocate hash and hash context together
3953 ++ *
3954 ++ * The caller has to make sure @sdesc is initialized to either NULL or
3955 ++ * a valid context. Both can be freed via cifs_free_hash().
3956 ++ */
3957 ++int
3958 ++cifs_alloc_hash(const char *name,
3959 ++ struct crypto_shash **shash, struct sdesc **sdesc)
3960 ++{
3961 ++ int rc = 0;
3962 ++ size_t size;
3963 ++
3964 ++ if (*sdesc != NULL)
3965 ++ return 0;
3966 ++
3967 ++ *shash = crypto_alloc_shash(name, 0, 0);
3968 ++ if (IS_ERR(*shash)) {
3969 ++ cifs_dbg(VFS, "could not allocate crypto %s\n", name);
3970 ++ rc = PTR_ERR(*shash);
3971 ++ *shash = NULL;
3972 ++ *sdesc = NULL;
3973 ++ return rc;
3974 ++ }
3975 ++
3976 ++ size = sizeof(struct shash_desc) + crypto_shash_descsize(*shash);
3977 ++ *sdesc = kmalloc(size, GFP_KERNEL);
3978 ++ if (*sdesc == NULL) {
3979 ++ cifs_dbg(VFS, "no memory left to allocate crypto %s\n", name);
3980 ++ crypto_free_shash(*shash);
3981 ++ *shash = NULL;
3982 ++ return -ENOMEM;
3983 ++ }
3984 ++
3985 ++ (*sdesc)->shash.tfm = *shash;
3986 ++ (*sdesc)->shash.flags = 0x0;
3987 ++ return 0;
3988 ++}
3989 ++
3990 ++/**
3991 ++ * cifs_free_hash - free hash and hash context together
3992 ++ *
3993 ++ * Freeing a NULL hash or context is safe.
3994 ++ */
3995 ++void
3996 ++cifs_free_hash(struct crypto_shash **shash, struct sdesc **sdesc)
3997 ++{
3998 ++ kfree(*sdesc);
3999 ++ *sdesc = NULL;
4000 ++ if (*shash)
4001 ++ crypto_free_shash(*shash);
4002 ++ *shash = NULL;
4003 ++}
4004 +diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
4005 +index bdb963d0ba32..eef875da7c0b 100644
4006 +--- a/fs/cifs/smb2ops.c
4007 ++++ b/fs/cifs/smb2ops.c
4008 +@@ -2060,6 +2060,15 @@ fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, struct smb_rqst *old_rq)
4009 + inc_rfc1001_len(tr_hdr, orig_len);
4010 + }
4011 +
4012 ++/* We can not use the normal sg_set_buf() as we will sometimes pass a
4013 ++ * stack object as buf.
4014 ++ */
4015 ++static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
4016 ++ unsigned int buflen)
4017 ++{
4018 ++ sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
4019 ++}
4020 ++
4021 + static struct scatterlist *
4022 + init_sg(struct smb_rqst *rqst, u8 *sign)
4023 + {
4024 +@@ -2074,16 +2083,16 @@ init_sg(struct smb_rqst *rqst, u8 *sign)
4025 + return NULL;
4026 +
4027 + sg_init_table(sg, sg_len);
4028 +- sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len);
4029 ++ smb2_sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len);
4030 + for (i = 1; i < rqst->rq_nvec; i++)
4031 +- sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base,
4032 ++ smb2_sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base,
4033 + rqst->rq_iov[i].iov_len);
4034 + for (j = 0; i < sg_len - 1; i++, j++) {
4035 + unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz
4036 + : rqst->rq_tailsz;
4037 + sg_set_page(&sg[i], rqst->rq_pages[j], len, 0);
4038 + }
4039 +- sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE);
4040 ++ smb2_sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE);
4041 + return sg;
4042 + }
4043 +
4044 +diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
4045 +index 66af1f8a13cc..49779d952cd5 100644
4046 +--- a/fs/cifs/smb2pdu.c
4047 ++++ b/fs/cifs/smb2pdu.c
4048 +@@ -1773,8 +1773,10 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
4049 + rc = alloc_path_with_tree_prefix(&copy_path, &copy_size,
4050 + &name_len,
4051 + tcon->treeName, path);
4052 +- if (rc)
4053 ++ if (rc) {
4054 ++ cifs_small_buf_release(req);
4055 + return rc;
4056 ++ }
4057 + req->NameLength = cpu_to_le16(name_len * 2);
4058 + uni_path_len = copy_size;
4059 + path = copy_path;
4060 +@@ -1785,8 +1787,10 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
4061 + if (uni_path_len % 8 != 0) {
4062 + copy_size = roundup(uni_path_len, 8);
4063 + copy_path = kzalloc(copy_size, GFP_KERNEL);
4064 +- if (!copy_path)
4065 ++ if (!copy_path) {
4066 ++ cifs_small_buf_release(req);
4067 + return -ENOMEM;
4068 ++ }
4069 + memcpy((char *)copy_path, (const char *)path,
4070 + uni_path_len);
4071 + uni_path_len = copy_size;
4072 +diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h
4073 +index e9ab5227e7a8..6fe4898f6975 100644
4074 +--- a/fs/cifs/smb2proto.h
4075 ++++ b/fs/cifs/smb2proto.h
4076 +@@ -203,4 +203,7 @@ extern int smb3_validate_negotiate(const unsigned int, struct cifs_tcon *);
4077 +
4078 + extern enum securityEnum smb2_select_sectype(struct TCP_Server_Info *,
4079 + enum securityEnum);
4080 ++#ifdef CONFIG_CIFS_SMB311
4081 ++extern int smb311_crypto_shash_allocate(struct TCP_Server_Info *server);
4082 ++#endif
4083 + #endif /* _SMB2PROTO_H */
4084 +diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c
4085 +index 99493946e2f9..bf49cb73b9e6 100644
4086 +--- a/fs/cifs/smb2transport.c
4087 ++++ b/fs/cifs/smb2transport.c
4088 +@@ -43,77 +43,62 @@
4089 + static int
4090 + smb2_crypto_shash_allocate(struct TCP_Server_Info *server)
4091 + {
4092 +- int rc;
4093 +- unsigned int size;
4094 ++ return cifs_alloc_hash("hmac(sha256)",
4095 ++ &server->secmech.hmacsha256,
4096 ++ &server->secmech.sdeschmacsha256);
4097 ++}
4098 +
4099 +- if (server->secmech.sdeschmacsha256 != NULL)
4100 +- return 0; /* already allocated */
4101 ++static int
4102 ++smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
4103 ++{
4104 ++ struct cifs_secmech *p = &server->secmech;
4105 ++ int rc;
4106 +
4107 +- server->secmech.hmacsha256 = crypto_alloc_shash("hmac(sha256)", 0, 0);
4108 +- if (IS_ERR(server->secmech.hmacsha256)) {
4109 +- cifs_dbg(VFS, "could not allocate crypto hmacsha256\n");
4110 +- rc = PTR_ERR(server->secmech.hmacsha256);
4111 +- server->secmech.hmacsha256 = NULL;
4112 +- return rc;
4113 +- }
4114 ++ rc = cifs_alloc_hash("hmac(sha256)",
4115 ++ &p->hmacsha256,
4116 ++ &p->sdeschmacsha256);
4117 ++ if (rc)
4118 ++ goto err;
4119 +
4120 +- size = sizeof(struct shash_desc) +
4121 +- crypto_shash_descsize(server->secmech.hmacsha256);
4122 +- server->secmech.sdeschmacsha256 = kmalloc(size, GFP_KERNEL);
4123 +- if (!server->secmech.sdeschmacsha256) {
4124 +- crypto_free_shash(server->secmech.hmacsha256);
4125 +- server->secmech.hmacsha256 = NULL;
4126 +- return -ENOMEM;
4127 +- }
4128 +- server->secmech.sdeschmacsha256->shash.tfm = server->secmech.hmacsha256;
4129 +- server->secmech.sdeschmacsha256->shash.flags = 0x0;
4130 ++ rc = cifs_alloc_hash("cmac(aes)", &p->cmacaes, &p->sdesccmacaes);
4131 ++ if (rc)
4132 ++ goto err;
4133 +
4134 + return 0;
4135 ++err:
4136 ++ cifs_free_hash(&p->hmacsha256, &p->sdeschmacsha256);
4137 ++ return rc;
4138 + }
4139 +
4140 +-static int
4141 +-smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
4142 ++#ifdef CONFIG_CIFS_SMB311
4143 ++int
4144 ++smb311_crypto_shash_allocate(struct TCP_Server_Info *server)
4145 + {
4146 +- unsigned int size;
4147 +- int rc;
4148 +-
4149 +- if (server->secmech.sdesccmacaes != NULL)
4150 +- return 0; /* already allocated */
4151 ++ struct cifs_secmech *p = &server->secmech;
4152 ++ int rc = 0;
4153 +
4154 +- rc = smb2_crypto_shash_allocate(server);
4155 ++ rc = cifs_alloc_hash("hmac(sha256)",
4156 ++ &p->hmacsha256,
4157 ++ &p->sdeschmacsha256);
4158 + if (rc)
4159 + return rc;
4160 +
4161 +- server->secmech.cmacaes = crypto_alloc_shash("cmac(aes)", 0, 0);
4162 +- if (IS_ERR(server->secmech.cmacaes)) {
4163 +- cifs_dbg(VFS, "could not allocate crypto cmac-aes");
4164 +- kfree(server->secmech.sdeschmacsha256);
4165 +- server->secmech.sdeschmacsha256 = NULL;
4166 +- crypto_free_shash(server->secmech.hmacsha256);
4167 +- server->secmech.hmacsha256 = NULL;
4168 +- rc = PTR_ERR(server->secmech.cmacaes);
4169 +- server->secmech.cmacaes = NULL;
4170 +- return rc;
4171 +- }
4172 ++ rc = cifs_alloc_hash("cmac(aes)", &p->cmacaes, &p->sdesccmacaes);
4173 ++ if (rc)
4174 ++ goto err;
4175 +
4176 +- size = sizeof(struct shash_desc) +
4177 +- crypto_shash_descsize(server->secmech.cmacaes);
4178 +- server->secmech.sdesccmacaes = kmalloc(size, GFP_KERNEL);
4179 +- if (!server->secmech.sdesccmacaes) {
4180 +- cifs_dbg(VFS, "%s: Can't alloc cmacaes\n", __func__);
4181 +- kfree(server->secmech.sdeschmacsha256);
4182 +- server->secmech.sdeschmacsha256 = NULL;
4183 +- crypto_free_shash(server->secmech.hmacsha256);
4184 +- crypto_free_shash(server->secmech.cmacaes);
4185 +- server->secmech.hmacsha256 = NULL;
4186 +- server->secmech.cmacaes = NULL;
4187 +- return -ENOMEM;
4188 +- }
4189 +- server->secmech.sdesccmacaes->shash.tfm = server->secmech.cmacaes;
4190 +- server->secmech.sdesccmacaes->shash.flags = 0x0;
4191 ++ rc = cifs_alloc_hash("sha512", &p->sha512, &p->sdescsha512);
4192 ++ if (rc)
4193 ++ goto err;
4194 +
4195 + return 0;
4196 ++
4197 ++err:
4198 ++ cifs_free_hash(&p->cmacaes, &p->sdesccmacaes);
4199 ++ cifs_free_hash(&p->hmacsha256, &p->sdeschmacsha256);
4200 ++ return rc;
4201 + }
4202 ++#endif
4203 +
4204 + static struct cifs_ses *
4205 + smb2_find_smb_ses_unlocked(struct TCP_Server_Info *server, __u64 ses_id)
4206 +@@ -457,7 +442,7 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
4207 + cifs_dbg(VFS, "%s: Could not init cmac aes\n", __func__);
4208 + return rc;
4209 + }
4210 +-
4211 ++
4212 + rc = __cifs_calc_signature(rqst, server, sigptr,
4213 + &server->secmech.sdesccmacaes->shash);
4214 +
4215 +diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c
4216 +index c12bffefa3c9..a0b80ac651a6 100644
4217 +--- a/fs/cifs/smbencrypt.c
4218 ++++ b/fs/cifs/smbencrypt.c
4219 +@@ -121,25 +121,12 @@ int
4220 + mdfour(unsigned char *md4_hash, unsigned char *link_str, int link_len)
4221 + {
4222 + int rc;
4223 +- unsigned int size;
4224 +- struct crypto_shash *md4;
4225 +- struct sdesc *sdescmd4;
4226 +-
4227 +- md4 = crypto_alloc_shash("md4", 0, 0);
4228 +- if (IS_ERR(md4)) {
4229 +- rc = PTR_ERR(md4);
4230 +- cifs_dbg(VFS, "%s: Crypto md4 allocation error %d\n",
4231 +- __func__, rc);
4232 +- return rc;
4233 +- }
4234 +- size = sizeof(struct shash_desc) + crypto_shash_descsize(md4);
4235 +- sdescmd4 = kmalloc(size, GFP_KERNEL);
4236 +- if (!sdescmd4) {
4237 +- rc = -ENOMEM;
4238 ++ struct crypto_shash *md4 = NULL;
4239 ++ struct sdesc *sdescmd4 = NULL;
4240 ++
4241 ++ rc = cifs_alloc_hash("md4", &md4, &sdescmd4);
4242 ++ if (rc)
4243 + goto mdfour_err;
4244 +- }
4245 +- sdescmd4->shash.tfm = md4;
4246 +- sdescmd4->shash.flags = 0x0;
4247 +
4248 + rc = crypto_shash_init(&sdescmd4->shash);
4249 + if (rc) {
4250 +@@ -156,9 +143,7 @@ mdfour(unsigned char *md4_hash, unsigned char *link_str, int link_len)
4251 + cifs_dbg(VFS, "%s: Could not generate md4 hash\n", __func__);
4252 +
4253 + mdfour_err:
4254 +- crypto_free_shash(md4);
4255 +- kfree(sdescmd4);
4256 +-
4257 ++ cifs_free_hash(&md4, &sdescmd4);
4258 + return rc;
4259 + }
4260 +
4261 +diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
4262 +index d5ddfb96c83c..db5be5e2e6f2 100644
4263 +--- a/fs/ext4/balloc.c
4264 ++++ b/fs/ext4/balloc.c
4265 +@@ -243,8 +243,6 @@ static int ext4_init_block_bitmap(struct super_block *sb,
4266 + */
4267 + ext4_mark_bitmap_end(num_clusters_in_group(sb, block_group),
4268 + sb->s_blocksize * 8, bh->b_data);
4269 +- ext4_block_bitmap_csum_set(sb, block_group, gdp, bh);
4270 +- ext4_group_desc_csum_set(sb, block_group, gdp);
4271 + return 0;
4272 + }
4273 +
4274 +@@ -448,6 +446,7 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
4275 + err = ext4_init_block_bitmap(sb, bh, block_group, desc);
4276 + set_bitmap_uptodate(bh);
4277 + set_buffer_uptodate(bh);
4278 ++ set_buffer_verified(bh);
4279 + ext4_unlock_group(sb, block_group);
4280 + unlock_buffer(bh);
4281 + if (err) {
4282 +diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
4283 +index 2d593201cf7a..7c70b08d104c 100644
4284 +--- a/fs/ext4/ext4_jbd2.c
4285 ++++ b/fs/ext4/ext4_jbd2.c
4286 +@@ -166,13 +166,6 @@ int __ext4_journal_get_write_access(const char *where, unsigned int line,
4287 + might_sleep();
4288 +
4289 + if (ext4_handle_valid(handle)) {
4290 +- struct super_block *sb;
4291 +-
4292 +- sb = handle->h_transaction->t_journal->j_private;
4293 +- if (unlikely(ext4_forced_shutdown(EXT4_SB(sb)))) {
4294 +- jbd2_journal_abort_handle(handle);
4295 +- return -EIO;
4296 +- }
4297 + err = jbd2_journal_get_write_access(handle, bh);
4298 + if (err)
4299 + ext4_journal_abort_handle(where, line, __func__, bh,
4300 +diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
4301 +index 207588dc803e..7ec55dd8db56 100644
4302 +--- a/fs/ext4/ialloc.c
4303 ++++ b/fs/ext4/ialloc.c
4304 +@@ -66,44 +66,6 @@ void ext4_mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
4305 + memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3);
4306 + }
4307 +
4308 +-/* Initializes an uninitialized inode bitmap */
4309 +-static int ext4_init_inode_bitmap(struct super_block *sb,
4310 +- struct buffer_head *bh,
4311 +- ext4_group_t block_group,
4312 +- struct ext4_group_desc *gdp)
4313 +-{
4314 +- struct ext4_group_info *grp;
4315 +- struct ext4_sb_info *sbi = EXT4_SB(sb);
4316 +- J_ASSERT_BH(bh, buffer_locked(bh));
4317 +-
4318 +- /* If checksum is bad mark all blocks and inodes use to prevent
4319 +- * allocation, essentially implementing a per-group read-only flag. */
4320 +- if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) {
4321 +- grp = ext4_get_group_info(sb, block_group);
4322 +- if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
4323 +- percpu_counter_sub(&sbi->s_freeclusters_counter,
4324 +- grp->bb_free);
4325 +- set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state);
4326 +- if (!EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) {
4327 +- int count;
4328 +- count = ext4_free_inodes_count(sb, gdp);
4329 +- percpu_counter_sub(&sbi->s_freeinodes_counter,
4330 +- count);
4331 +- }
4332 +- set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state);
4333 +- return -EFSBADCRC;
4334 +- }
4335 +-
4336 +- memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8);
4337 +- ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), sb->s_blocksize * 8,
4338 +- bh->b_data);
4339 +- ext4_inode_bitmap_csum_set(sb, block_group, gdp, bh,
4340 +- EXT4_INODES_PER_GROUP(sb) / 8);
4341 +- ext4_group_desc_csum_set(sb, block_group, gdp);
4342 +-
4343 +- return 0;
4344 +-}
4345 +-
4346 + void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate)
4347 + {
4348 + if (uptodate) {
4349 +@@ -187,17 +149,14 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
4350 +
4351 + ext4_lock_group(sb, block_group);
4352 + if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {
4353 +- err = ext4_init_inode_bitmap(sb, bh, block_group, desc);
4354 ++ memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8);
4355 ++ ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb),
4356 ++ sb->s_blocksize * 8, bh->b_data);
4357 + set_bitmap_uptodate(bh);
4358 + set_buffer_uptodate(bh);
4359 + set_buffer_verified(bh);
4360 + ext4_unlock_group(sb, block_group);
4361 + unlock_buffer(bh);
4362 +- if (err) {
4363 +- ext4_error(sb, "Failed to init inode bitmap for group "
4364 +- "%u: %d", block_group, err);
4365 +- goto out;
4366 +- }
4367 + return bh;
4368 + }
4369 + ext4_unlock_group(sb, block_group);
4370 +diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
4371 +index 0b9f3f284799..09014c3c4207 100644
4372 +--- a/fs/ext4/inode.c
4373 ++++ b/fs/ext4/inode.c
4374 +@@ -3614,7 +3614,6 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
4375 + {
4376 + struct file *file = iocb->ki_filp;
4377 + struct inode *inode = file->f_mapping->host;
4378 +- struct ext4_inode_info *ei = EXT4_I(inode);
4379 + ssize_t ret;
4380 + loff_t offset = iocb->ki_pos;
4381 + size_t count = iov_iter_count(iter);
4382 +@@ -3638,7 +3637,7 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
4383 + goto out;
4384 + }
4385 + orphan = 1;
4386 +- ei->i_disksize = inode->i_size;
4387 ++ ext4_update_i_disksize(inode, inode->i_size);
4388 + ext4_journal_stop(handle);
4389 + }
4390 +
4391 +@@ -3746,7 +3745,7 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
4392 + if (ret > 0) {
4393 + loff_t end = offset + ret;
4394 + if (end > inode->i_size) {
4395 +- ei->i_disksize = end;
4396 ++ ext4_update_i_disksize(inode, end);
4397 + i_size_write(inode, end);
4398 + /*
4399 + * We're going to return a positive `ret'
4400 +@@ -4686,6 +4685,12 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
4401 + goto bad_inode;
4402 + raw_inode = ext4_raw_inode(&iloc);
4403 +
4404 ++ if ((ino == EXT4_ROOT_INO) && (raw_inode->i_links_count == 0)) {
4405 ++ EXT4_ERROR_INODE(inode, "root inode unallocated");
4406 ++ ret = -EFSCORRUPTED;
4407 ++ goto bad_inode;
4408 ++ }
4409 ++
4410 + if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
4411 + ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize);
4412 + if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
4413 +diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
4414 +index d97f40396765..1eb68e626931 100644
4415 +--- a/fs/ext4/ioctl.c
4416 ++++ b/fs/ext4/ioctl.c
4417 +@@ -493,15 +493,13 @@ static int ext4_shutdown(struct super_block *sb, unsigned long arg)
4418 + set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
4419 + if (sbi->s_journal && !is_journal_aborted(sbi->s_journal)) {
4420 + (void) ext4_force_commit(sb);
4421 +- jbd2_journal_abort(sbi->s_journal, 0);
4422 ++ jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN);
4423 + }
4424 + break;
4425 + case EXT4_GOING_FLAGS_NOLOGFLUSH:
4426 + set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
4427 +- if (sbi->s_journal && !is_journal_aborted(sbi->s_journal)) {
4428 +- msleep(100);
4429 +- jbd2_journal_abort(sbi->s_journal, 0);
4430 +- }
4431 ++ if (sbi->s_journal && !is_journal_aborted(sbi->s_journal))
4432 ++ jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN);
4433 + break;
4434 + default:
4435 + return -EINVAL;
4436 +diff --git a/fs/ext4/super.c b/fs/ext4/super.c
4437 +index 16d247f056e2..3a605c672649 100644
4438 +--- a/fs/ext4/super.c
4439 ++++ b/fs/ext4/super.c
4440 +@@ -2330,6 +2330,8 @@ static int ext4_check_descriptors(struct super_block *sb,
4441 + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
4442 + "Block bitmap for group %u overlaps "
4443 + "superblock", i);
4444 ++ if (!sb_rdonly(sb))
4445 ++ return 0;
4446 + }
4447 + if (block_bitmap < first_block || block_bitmap > last_block) {
4448 + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
4449 +@@ -2342,6 +2344,8 @@ static int ext4_check_descriptors(struct super_block *sb,
4450 + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
4451 + "Inode bitmap for group %u overlaps "
4452 + "superblock", i);
4453 ++ if (!sb_rdonly(sb))
4454 ++ return 0;
4455 + }
4456 + if (inode_bitmap < first_block || inode_bitmap > last_block) {
4457 + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
4458 +@@ -2354,6 +2358,8 @@ static int ext4_check_descriptors(struct super_block *sb,
4459 + ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
4460 + "Inode table for group %u overlaps "
4461 + "superblock", i);
4462 ++ if (!sb_rdonly(sb))
4463 ++ return 0;
4464 + }
4465 + if (inode_table < first_block ||
4466 + inode_table + sbi->s_itb_per_group - 1 > last_block) {
4467 +@@ -3490,15 +3496,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
4468 + }
4469 +
4470 + /* Load the checksum driver */
4471 +- if (ext4_has_feature_metadata_csum(sb) ||
4472 +- ext4_has_feature_ea_inode(sb)) {
4473 +- sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
4474 +- if (IS_ERR(sbi->s_chksum_driver)) {
4475 +- ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
4476 +- ret = PTR_ERR(sbi->s_chksum_driver);
4477 +- sbi->s_chksum_driver = NULL;
4478 +- goto failed_mount;
4479 +- }
4480 ++ sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
4481 ++ if (IS_ERR(sbi->s_chksum_driver)) {
4482 ++ ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
4483 ++ ret = PTR_ERR(sbi->s_chksum_driver);
4484 ++ sbi->s_chksum_driver = NULL;
4485 ++ goto failed_mount;
4486 + }
4487 +
4488 + /* Check superblock checksum */
4489 +diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
4490 +index 218a7ba57819..1718354e6322 100644
4491 +--- a/fs/ext4/xattr.c
4492 ++++ b/fs/ext4/xattr.c
4493 +@@ -194,10 +194,13 @@ ext4_xattr_check_entries(struct ext4_xattr_entry *entry, void *end,
4494 +
4495 + /* Check the values */
4496 + while (!IS_LAST_ENTRY(entry)) {
4497 +- if (entry->e_value_size != 0 &&
4498 +- entry->e_value_inum == 0) {
4499 ++ u32 size = le32_to_cpu(entry->e_value_size);
4500 ++
4501 ++ if (size > EXT4_XATTR_SIZE_MAX)
4502 ++ return -EFSCORRUPTED;
4503 ++
4504 ++ if (size != 0 && entry->e_value_inum == 0) {
4505 + u16 offs = le16_to_cpu(entry->e_value_offs);
4506 +- u32 size = le32_to_cpu(entry->e_value_size);
4507 + void *value;
4508 +
4509 + /*
4510 +@@ -221,25 +224,36 @@ ext4_xattr_check_entries(struct ext4_xattr_entry *entry, void *end,
4511 + }
4512 +
4513 + static inline int
4514 +-ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh)
4515 ++__ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh,
4516 ++ const char *function, unsigned int line)
4517 + {
4518 +- int error;
4519 ++ int error = -EFSCORRUPTED;
4520 +
4521 + if (buffer_verified(bh))
4522 + return 0;
4523 +
4524 + if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
4525 + BHDR(bh)->h_blocks != cpu_to_le32(1))
4526 +- return -EFSCORRUPTED;
4527 ++ goto errout;
4528 ++ error = -EFSBADCRC;
4529 + if (!ext4_xattr_block_csum_verify(inode, bh))
4530 +- return -EFSBADCRC;
4531 ++ goto errout;
4532 + error = ext4_xattr_check_entries(BFIRST(bh), bh->b_data + bh->b_size,
4533 + bh->b_data);
4534 +- if (!error)
4535 ++errout:
4536 ++ if (error)
4537 ++ __ext4_error_inode(inode, function, line, 0,
4538 ++ "corrupted xattr block %llu",
4539 ++ (unsigned long long) bh->b_blocknr);
4540 ++ else
4541 + set_buffer_verified(bh);
4542 + return error;
4543 + }
4544 +
4545 ++#define ext4_xattr_check_block(inode, bh) \
4546 ++ __ext4_xattr_check_block((inode), (bh), __func__, __LINE__)
4547 ++
4548 ++
4549 + static int
4550 + __xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header,
4551 + void *end, const char *function, unsigned int line)
4552 +@@ -261,18 +275,22 @@ __xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header,
4553 + __xattr_check_inode((inode), (header), (end), __func__, __LINE__)
4554 +
4555 + static int
4556 +-ext4_xattr_find_entry(struct ext4_xattr_entry **pentry, int name_index,
4557 +- const char *name, int sorted)
4558 ++xattr_find_entry(struct inode *inode, struct ext4_xattr_entry **pentry,
4559 ++ void *end, int name_index, const char *name, int sorted)
4560 + {
4561 +- struct ext4_xattr_entry *entry;
4562 ++ struct ext4_xattr_entry *entry, *next;
4563 + size_t name_len;
4564 + int cmp = 1;
4565 +
4566 + if (name == NULL)
4567 + return -EINVAL;
4568 + name_len = strlen(name);
4569 +- entry = *pentry;
4570 +- for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
4571 ++ for (entry = *pentry; !IS_LAST_ENTRY(entry); entry = next) {
4572 ++ next = EXT4_XATTR_NEXT(entry);
4573 ++ if ((void *) next >= end) {
4574 ++ EXT4_ERROR_INODE(inode, "corrupted xattr entries");
4575 ++ return -EFSCORRUPTED;
4576 ++ }
4577 + cmp = name_index - entry->e_name_index;
4578 + if (!cmp)
4579 + cmp = name_len - entry->e_name_len;
4580 +@@ -494,6 +512,7 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
4581 + struct buffer_head *bh = NULL;
4582 + struct ext4_xattr_entry *entry;
4583 + size_t size;
4584 ++ void *end;
4585 + int error;
4586 + struct mb_cache *ea_block_cache = EA_BLOCK_CACHE(inode);
4587 +
4588 +@@ -510,20 +529,20 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
4589 + goto cleanup;
4590 + ea_bdebug(bh, "b_count=%d, refcount=%d",
4591 + atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
4592 +- if (ext4_xattr_check_block(inode, bh)) {
4593 +- EXT4_ERROR_INODE(inode, "bad block %llu",
4594 +- EXT4_I(inode)->i_file_acl);
4595 +- error = -EFSCORRUPTED;
4596 ++ error = ext4_xattr_check_block(inode, bh);
4597 ++ if (error)
4598 + goto cleanup;
4599 +- }
4600 + ext4_xattr_block_cache_insert(ea_block_cache, bh);
4601 + entry = BFIRST(bh);
4602 +- error = ext4_xattr_find_entry(&entry, name_index, name, 1);
4603 ++ end = bh->b_data + bh->b_size;
4604 ++ error = xattr_find_entry(inode, &entry, end, name_index, name, 1);
4605 + if (error)
4606 + goto cleanup;
4607 + size = le32_to_cpu(entry->e_value_size);
4608 ++ error = -ERANGE;
4609 ++ if (unlikely(size > EXT4_XATTR_SIZE_MAX))
4610 ++ goto cleanup;
4611 + if (buffer) {
4612 +- error = -ERANGE;
4613 + if (size > buffer_size)
4614 + goto cleanup;
4615 + if (entry->e_value_inum) {
4616 +@@ -532,8 +551,12 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
4617 + if (error)
4618 + goto cleanup;
4619 + } else {
4620 +- memcpy(buffer, bh->b_data +
4621 +- le16_to_cpu(entry->e_value_offs), size);
4622 ++ u16 offset = le16_to_cpu(entry->e_value_offs);
4623 ++ void *p = bh->b_data + offset;
4624 ++
4625 ++ if (unlikely(p + size > end))
4626 ++ goto cleanup;
4627 ++ memcpy(buffer, p, size);
4628 + }
4629 + }
4630 + error = size;
4631 +@@ -567,12 +590,14 @@ ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
4632 + if (error)
4633 + goto cleanup;
4634 + entry = IFIRST(header);
4635 +- error = ext4_xattr_find_entry(&entry, name_index, name, 0);
4636 ++ error = xattr_find_entry(inode, &entry, end, name_index, name, 0);
4637 + if (error)
4638 + goto cleanup;
4639 + size = le32_to_cpu(entry->e_value_size);
4640 ++ error = -ERANGE;
4641 ++ if (unlikely(size > EXT4_XATTR_SIZE_MAX))
4642 ++ goto cleanup;
4643 + if (buffer) {
4644 +- error = -ERANGE;
4645 + if (size > buffer_size)
4646 + goto cleanup;
4647 + if (entry->e_value_inum) {
4648 +@@ -581,8 +606,12 @@ ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
4649 + if (error)
4650 + goto cleanup;
4651 + } else {
4652 +- memcpy(buffer, (void *)IFIRST(header) +
4653 +- le16_to_cpu(entry->e_value_offs), size);
4654 ++ u16 offset = le16_to_cpu(entry->e_value_offs);
4655 ++ void *p = (void *)IFIRST(header) + offset;
4656 ++
4657 ++ if (unlikely(p + size > end))
4658 ++ goto cleanup;
4659 ++ memcpy(buffer, p, size);
4660 + }
4661 + }
4662 + error = size;
4663 +@@ -675,12 +704,9 @@ ext4_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size)
4664 + goto cleanup;
4665 + ea_bdebug(bh, "b_count=%d, refcount=%d",
4666 + atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
4667 +- if (ext4_xattr_check_block(inode, bh)) {
4668 +- EXT4_ERROR_INODE(inode, "bad block %llu",
4669 +- EXT4_I(inode)->i_file_acl);
4670 +- error = -EFSCORRUPTED;
4671 ++ error = ext4_xattr_check_block(inode, bh);
4672 ++ if (error)
4673 + goto cleanup;
4674 +- }
4675 + ext4_xattr_block_cache_insert(EA_BLOCK_CACHE(inode), bh);
4676 + error = ext4_xattr_list_entries(dentry, BFIRST(bh), buffer, buffer_size);
4677 +
4678 +@@ -807,10 +833,9 @@ int ext4_get_inode_usage(struct inode *inode, qsize_t *usage)
4679 + goto out;
4680 + }
4681 +
4682 +- if (ext4_xattr_check_block(inode, bh)) {
4683 +- ret = -EFSCORRUPTED;
4684 ++ ret = ext4_xattr_check_block(inode, bh);
4685 ++ if (ret)
4686 + goto out;
4687 +- }
4688 +
4689 + for (entry = BFIRST(bh); !IS_LAST_ENTRY(entry);
4690 + entry = EXT4_XATTR_NEXT(entry))
4691 +@@ -1792,19 +1817,16 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
4692 + ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
4693 + atomic_read(&(bs->bh->b_count)),
4694 + le32_to_cpu(BHDR(bs->bh)->h_refcount));
4695 +- if (ext4_xattr_check_block(inode, bs->bh)) {
4696 +- EXT4_ERROR_INODE(inode, "bad block %llu",
4697 +- EXT4_I(inode)->i_file_acl);
4698 +- error = -EFSCORRUPTED;
4699 ++ error = ext4_xattr_check_block(inode, bs->bh);
4700 ++ if (error)
4701 + goto cleanup;
4702 +- }
4703 + /* Find the named attribute. */
4704 + bs->s.base = BHDR(bs->bh);
4705 + bs->s.first = BFIRST(bs->bh);
4706 + bs->s.end = bs->bh->b_data + bs->bh->b_size;
4707 + bs->s.here = bs->s.first;
4708 +- error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
4709 +- i->name, 1);
4710 ++ error = xattr_find_entry(inode, &bs->s.here, bs->s.end,
4711 ++ i->name_index, i->name, 1);
4712 + if (error && error != -ENODATA)
4713 + goto cleanup;
4714 + bs->s.not_found = error;
4715 +@@ -2163,8 +2185,8 @@ int ext4_xattr_ibody_find(struct inode *inode, struct ext4_xattr_info *i,
4716 + if (error)
4717 + return error;
4718 + /* Find the named attribute. */
4719 +- error = ext4_xattr_find_entry(&is->s.here, i->name_index,
4720 +- i->name, 0);
4721 ++ error = xattr_find_entry(inode, &is->s.here, is->s.end,
4722 ++ i->name_index, i->name, 0);
4723 + if (error && error != -ENODATA)
4724 + return error;
4725 + is->s.not_found = error;
4726 +@@ -2720,13 +2742,9 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
4727 + error = -EIO;
4728 + if (!bh)
4729 + goto cleanup;
4730 +- if (ext4_xattr_check_block(inode, bh)) {
4731 +- EXT4_ERROR_INODE(inode, "bad block %llu",
4732 +- EXT4_I(inode)->i_file_acl);
4733 +- error = -EFSCORRUPTED;
4734 +- brelse(bh);
4735 ++ error = ext4_xattr_check_block(inode, bh);
4736 ++ if (error)
4737 + goto cleanup;
4738 +- }
4739 + base = BHDR(bh);
4740 + end = bh->b_data + bh->b_size;
4741 + min_offs = end - base;
4742 +@@ -2883,11 +2901,8 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
4743 + goto cleanup;
4744 + }
4745 + error = ext4_xattr_check_block(inode, bh);
4746 +- if (error) {
4747 +- EXT4_ERROR_INODE(inode, "bad block %llu (error %d)",
4748 +- EXT4_I(inode)->i_file_acl, error);
4749 ++ if (error)
4750 + goto cleanup;
4751 +- }
4752 +
4753 + if (ext4_has_feature_ea_inode(inode->i_sb)) {
4754 + for (entry = BFIRST(bh); !IS_LAST_ENTRY(entry);
4755 +diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h
4756 +index f8cc07588ac9..262b9314119f 100644
4757 +--- a/fs/ext4/xattr.h
4758 ++++ b/fs/ext4/xattr.h
4759 +@@ -70,6 +70,17 @@ struct ext4_xattr_entry {
4760 + EXT4_I(inode)->i_extra_isize))
4761 + #define IFIRST(hdr) ((struct ext4_xattr_entry *)((hdr)+1))
4762 +
4763 ++/*
4764 ++ * XATTR_SIZE_MAX is currently 64k, but for the purposes of checking
4765 ++ * for file system consistency errors, we use a somewhat bigger value.
4766 ++ * This allows XATTR_SIZE_MAX to grow in the future, but by using this
4767 ++ * instead of INT_MAX for certain consistency checks, we don't need to
4768 ++ * worry about arithmetic overflows. (Actually XATTR_SIZE_MAX is
4769 ++ * defined in include/uapi/linux/limits.h, so changing it is going
4770 ++ * not going to be trivial....)
4771 ++ */
4772 ++#define EXT4_XATTR_SIZE_MAX (1 << 24)
4773 ++
4774 + /*
4775 + * The minimum size of EA value when you start storing it in an external inode
4776 + * size of block - size of header - size of 1 entry - 4 null bytes
4777 +diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
4778 +index 245c430a2e41..8a7ef9378bf6 100644
4779 +--- a/fs/fs-writeback.c
4780 ++++ b/fs/fs-writeback.c
4781 +@@ -745,11 +745,12 @@ int inode_congested(struct inode *inode, int cong_bits)
4782 + */
4783 + if (inode && inode_to_wb_is_valid(inode)) {
4784 + struct bdi_writeback *wb;
4785 +- bool locked, congested;
4786 ++ struct wb_lock_cookie lock_cookie = {};
4787 ++ bool congested;
4788 +
4789 +- wb = unlocked_inode_to_wb_begin(inode, &locked);
4790 ++ wb = unlocked_inode_to_wb_begin(inode, &lock_cookie);
4791 + congested = wb_congested(wb, cong_bits);
4792 +- unlocked_inode_to_wb_end(inode, locked);
4793 ++ unlocked_inode_to_wb_end(inode, &lock_cookie);
4794 + return congested;
4795 + }
4796 +
4797 +diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
4798 +index 7d5ef3bf3f3e..61d48f0c41a1 100644
4799 +--- a/fs/jbd2/journal.c
4800 ++++ b/fs/jbd2/journal.c
4801 +@@ -961,7 +961,7 @@ int __jbd2_update_log_tail(journal_t *journal, tid_t tid, unsigned long block)
4802 + }
4803 +
4804 + /*
4805 +- * This is a variaon of __jbd2_update_log_tail which checks for validity of
4806 ++ * This is a variation of __jbd2_update_log_tail which checks for validity of
4807 + * provided log tail and locks j_checkpoint_mutex. So it is safe against races
4808 + * with other threads updating log tail.
4809 + */
4810 +@@ -1404,6 +1404,9 @@ int jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid,
4811 + journal_superblock_t *sb = journal->j_superblock;
4812 + int ret;
4813 +
4814 ++ if (is_journal_aborted(journal))
4815 ++ return -EIO;
4816 ++
4817 + BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex));
4818 + jbd_debug(1, "JBD2: updating superblock (start %lu, seq %u)\n",
4819 + tail_block, tail_tid);
4820 +@@ -1470,12 +1473,15 @@ static void jbd2_mark_journal_empty(journal_t *journal, int write_op)
4821 + void jbd2_journal_update_sb_errno(journal_t *journal)
4822 + {
4823 + journal_superblock_t *sb = journal->j_superblock;
4824 ++ int errcode;
4825 +
4826 + read_lock(&journal->j_state_lock);
4827 +- jbd_debug(1, "JBD2: updating superblock error (errno %d)\n",
4828 +- journal->j_errno);
4829 +- sb->s_errno = cpu_to_be32(journal->j_errno);
4830 ++ errcode = journal->j_errno;
4831 + read_unlock(&journal->j_state_lock);
4832 ++ if (errcode == -ESHUTDOWN)
4833 ++ errcode = 0;
4834 ++ jbd_debug(1, "JBD2: updating superblock error (errno %d)\n", errcode);
4835 ++ sb->s_errno = cpu_to_be32(errcode);
4836 +
4837 + jbd2_write_superblock(journal, REQ_SYNC | REQ_FUA);
4838 + }
4839 +@@ -2092,12 +2098,22 @@ void __jbd2_journal_abort_hard(journal_t *journal)
4840 + * but don't do any other IO. */
4841 + static void __journal_abort_soft (journal_t *journal, int errno)
4842 + {
4843 +- if (journal->j_flags & JBD2_ABORT)
4844 +- return;
4845 ++ int old_errno;
4846 +
4847 +- if (!journal->j_errno)
4848 ++ write_lock(&journal->j_state_lock);
4849 ++ old_errno = journal->j_errno;
4850 ++ if (!journal->j_errno || errno == -ESHUTDOWN)
4851 + journal->j_errno = errno;
4852 +
4853 ++ if (journal->j_flags & JBD2_ABORT) {
4854 ++ write_unlock(&journal->j_state_lock);
4855 ++ if (!old_errno && old_errno != -ESHUTDOWN &&
4856 ++ errno == -ESHUTDOWN)
4857 ++ jbd2_journal_update_sb_errno(journal);
4858 ++ return;
4859 ++ }
4860 ++ write_unlock(&journal->j_state_lock);
4861 ++
4862 + __jbd2_journal_abort_hard(journal);
4863 +
4864 + if (errno) {
4865 +diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
4866 +index 153f1c6eb169..33e01de576d2 100644
4867 +--- a/fs/jffs2/super.c
4868 ++++ b/fs/jffs2/super.c
4869 +@@ -342,7 +342,7 @@ static void jffs2_put_super (struct super_block *sb)
4870 + static void jffs2_kill_sb(struct super_block *sb)
4871 + {
4872 + struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
4873 +- if (!sb_rdonly(sb))
4874 ++ if (c && !sb_rdonly(sb))
4875 + jffs2_stop_garbage_collect_thread(c);
4876 + kill_mtd_super(sb);
4877 + kfree(c);
4878 +diff --git a/fs/namespace.c b/fs/namespace.c
4879 +index adae9ffce91d..62b17aff1908 100644
4880 +--- a/fs/namespace.c
4881 ++++ b/fs/namespace.c
4882 +@@ -1089,7 +1089,8 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,
4883 + goto out_free;
4884 + }
4885 +
4886 +- mnt->mnt.mnt_flags = old->mnt.mnt_flags & ~(MNT_WRITE_HOLD|MNT_MARKED);
4887 ++ mnt->mnt.mnt_flags = old->mnt.mnt_flags;
4888 ++ mnt->mnt.mnt_flags &= ~(MNT_WRITE_HOLD|MNT_MARKED|MNT_INTERNAL);
4889 + /* Don't allow unprivileged users to change mount flags */
4890 + if (flag & CL_UNPRIVILEGED) {
4891 + mnt->mnt.mnt_flags |= MNT_LOCK_ATIME;
4892 +diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
4893 +index 3c7053207297..bd520450c37a 100644
4894 +--- a/fs/notify/fanotify/fanotify.c
4895 ++++ b/fs/notify/fanotify/fanotify.c
4896 +@@ -90,7 +90,7 @@ static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark,
4897 + u32 event_mask,
4898 + const void *data, int data_type)
4899 + {
4900 +- __u32 marks_mask, marks_ignored_mask;
4901 ++ __u32 marks_mask = 0, marks_ignored_mask = 0;
4902 + const struct path *path = data;
4903 +
4904 + pr_debug("%s: inode_mark=%p vfsmnt_mark=%p mask=%x data=%p"
4905 +@@ -106,24 +106,20 @@ static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark,
4906 + !d_can_lookup(path->dentry))
4907 + return false;
4908 +
4909 +- if (inode_mark && vfsmnt_mark) {
4910 +- marks_mask = (vfsmnt_mark->mask | inode_mark->mask);
4911 +- marks_ignored_mask = (vfsmnt_mark->ignored_mask | inode_mark->ignored_mask);
4912 +- } else if (inode_mark) {
4913 +- /*
4914 +- * if the event is for a child and this inode doesn't care about
4915 +- * events on the child, don't send it!
4916 +- */
4917 +- if ((event_mask & FS_EVENT_ON_CHILD) &&
4918 +- !(inode_mark->mask & FS_EVENT_ON_CHILD))
4919 +- return false;
4920 +- marks_mask = inode_mark->mask;
4921 +- marks_ignored_mask = inode_mark->ignored_mask;
4922 +- } else if (vfsmnt_mark) {
4923 +- marks_mask = vfsmnt_mark->mask;
4924 +- marks_ignored_mask = vfsmnt_mark->ignored_mask;
4925 +- } else {
4926 +- BUG();
4927 ++ /*
4928 ++ * if the event is for a child and this inode doesn't care about
4929 ++ * events on the child, don't send it!
4930 ++ */
4931 ++ if (inode_mark &&
4932 ++ (!(event_mask & FS_EVENT_ON_CHILD) ||
4933 ++ (inode_mark->mask & FS_EVENT_ON_CHILD))) {
4934 ++ marks_mask |= inode_mark->mask;
4935 ++ marks_ignored_mask |= inode_mark->ignored_mask;
4936 ++ }
4937 ++
4938 ++ if (vfsmnt_mark) {
4939 ++ marks_mask |= vfsmnt_mark->mask;
4940 ++ marks_ignored_mask |= vfsmnt_mark->ignored_mask;
4941 + }
4942 +
4943 + if (d_is_dir(path->dentry) &&
4944 +diff --git a/fs/orangefs/super.c b/fs/orangefs/super.c
4945 +index 47ebd9bfd1a1..1997ce49ab46 100644
4946 +--- a/fs/orangefs/super.c
4947 ++++ b/fs/orangefs/super.c
4948 +@@ -594,6 +594,11 @@ void orangefs_kill_sb(struct super_block *sb)
4949 + /* provided sb cleanup */
4950 + kill_anon_super(sb);
4951 +
4952 ++ if (!ORANGEFS_SB(sb)) {
4953 ++ mutex_lock(&orangefs_request_mutex);
4954 ++ mutex_unlock(&orangefs_request_mutex);
4955 ++ return;
4956 ++ }
4957 + /*
4958 + * issue the unmount to userspace to tell it to remove the
4959 + * dynamic mount info it has for this superblock
4960 +diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
4961 +index 69ff280bdfe8..2be907231375 100644
4962 +--- a/fs/reiserfs/journal.c
4963 ++++ b/fs/reiserfs/journal.c
4964 +@@ -2643,7 +2643,7 @@ static int journal_init_dev(struct super_block *super,
4965 + if (IS_ERR(journal->j_dev_bd)) {
4966 + result = PTR_ERR(journal->j_dev_bd);
4967 + journal->j_dev_bd = NULL;
4968 +- reiserfs_warning(super,
4969 ++ reiserfs_warning(super, "sh-457",
4970 + "journal_init_dev: Cannot open '%s': %i",
4971 + jdev_name, result);
4972 + return result;
4973 +diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
4974 +index 5496b17b959c..e1cd3dcf5a03 100644
4975 +--- a/fs/ubifs/super.c
4976 ++++ b/fs/ubifs/super.c
4977 +@@ -1739,8 +1739,11 @@ static void ubifs_remount_ro(struct ubifs_info *c)
4978 +
4979 + dbg_save_space_info(c);
4980 +
4981 +- for (i = 0; i < c->jhead_cnt; i++)
4982 +- ubifs_wbuf_sync(&c->jheads[i].wbuf);
4983 ++ for (i = 0; i < c->jhead_cnt; i++) {
4984 ++ err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
4985 ++ if (err)
4986 ++ ubifs_ro_mode(c, err);
4987 ++ }
4988 +
4989 + c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY);
4990 + c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS);
4991 +@@ -1806,8 +1809,11 @@ static void ubifs_put_super(struct super_block *sb)
4992 + int err;
4993 +
4994 + /* Synchronize write-buffers */
4995 +- for (i = 0; i < c->jhead_cnt; i++)
4996 +- ubifs_wbuf_sync(&c->jheads[i].wbuf);
4997 ++ for (i = 0; i < c->jhead_cnt; i++) {
4998 ++ err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
4999 ++ if (err)
5000 ++ ubifs_ro_mode(c, err);
5001 ++ }
5002 +
5003 + /*
5004 + * We are being cleanly unmounted which means the
5005 +diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c
5006 +index 695389a4fc23..3a3be23689b3 100644
5007 +--- a/fs/udf/unicode.c
5008 ++++ b/fs/udf/unicode.c
5009 +@@ -28,6 +28,9 @@
5010 +
5011 + #include "udf_sb.h"
5012 +
5013 ++#define SURROGATE_MASK 0xfffff800
5014 ++#define SURROGATE_PAIR 0x0000d800
5015 ++
5016 + static int udf_uni2char_utf8(wchar_t uni,
5017 + unsigned char *out,
5018 + int boundlen)
5019 +@@ -37,6 +40,9 @@ static int udf_uni2char_utf8(wchar_t uni,
5020 + if (boundlen <= 0)
5021 + return -ENAMETOOLONG;
5022 +
5023 ++ if ((uni & SURROGATE_MASK) == SURROGATE_PAIR)
5024 ++ return -EINVAL;
5025 ++
5026 + if (uni < 0x80) {
5027 + out[u_len++] = (unsigned char)uni;
5028 + } else if (uni < 0x800) {
5029 +diff --git a/include/dt-bindings/clock/mt2701-clk.h b/include/dt-bindings/clock/mt2701-clk.h
5030 +index 551f7600ab58..24e93dfcee9f 100644
5031 +--- a/include/dt-bindings/clock/mt2701-clk.h
5032 ++++ b/include/dt-bindings/clock/mt2701-clk.h
5033 +@@ -176,7 +176,8 @@
5034 + #define CLK_TOP_AUD_EXT1 156
5035 + #define CLK_TOP_AUD_EXT2 157
5036 + #define CLK_TOP_NFI1X_PAD 158
5037 +-#define CLK_TOP_NR 159
5038 ++#define CLK_TOP_AXISEL_D4 159
5039 ++#define CLK_TOP_NR 160
5040 +
5041 + /* APMIXEDSYS */
5042 +
5043 +diff --git a/include/linux/backing-dev-defs.h b/include/linux/backing-dev-defs.h
5044 +index fff4cfa0c21d..eac387a3bfef 100644
5045 +--- a/include/linux/backing-dev-defs.h
5046 ++++ b/include/linux/backing-dev-defs.h
5047 +@@ -199,6 +199,11 @@ static inline void set_bdi_congested(struct backing_dev_info *bdi, int sync)
5048 + set_wb_congested(bdi->wb.congested, sync);
5049 + }
5050 +
5051 ++struct wb_lock_cookie {
5052 ++ bool locked;
5053 ++ unsigned long flags;
5054 ++};
5055 ++
5056 + #ifdef CONFIG_CGROUP_WRITEBACK
5057 +
5058 + /**
5059 +diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
5060 +index 16621579a3db..012adec97543 100644
5061 +--- a/include/linux/backing-dev.h
5062 ++++ b/include/linux/backing-dev.h
5063 +@@ -342,7 +342,7 @@ static inline struct bdi_writeback *inode_to_wb(struct inode *inode)
5064 + /**
5065 + * unlocked_inode_to_wb_begin - begin unlocked inode wb access transaction
5066 + * @inode: target inode
5067 +- * @lockedp: temp bool output param, to be passed to the end function
5068 ++ * @cookie: output param, to be passed to the end function
5069 + *
5070 + * The caller wants to access the wb associated with @inode but isn't
5071 + * holding inode->i_lock, mapping->tree_lock or wb->list_lock. This
5072 +@@ -350,12 +350,12 @@ static inline struct bdi_writeback *inode_to_wb(struct inode *inode)
5073 + * association doesn't change until the transaction is finished with
5074 + * unlocked_inode_to_wb_end().
5075 + *
5076 +- * The caller must call unlocked_inode_to_wb_end() with *@lockdep
5077 +- * afterwards and can't sleep during transaction. IRQ may or may not be
5078 +- * disabled on return.
5079 ++ * The caller must call unlocked_inode_to_wb_end() with *@cookie afterwards and
5080 ++ * can't sleep during the transaction. IRQs may or may not be disabled on
5081 ++ * return.
5082 + */
5083 + static inline struct bdi_writeback *
5084 +-unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
5085 ++unlocked_inode_to_wb_begin(struct inode *inode, struct wb_lock_cookie *cookie)
5086 + {
5087 + rcu_read_lock();
5088 +
5089 +@@ -363,10 +363,10 @@ unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
5090 + * Paired with store_release in inode_switch_wb_work_fn() and
5091 + * ensures that we see the new wb if we see cleared I_WB_SWITCH.
5092 + */
5093 +- *lockedp = smp_load_acquire(&inode->i_state) & I_WB_SWITCH;
5094 ++ cookie->locked = smp_load_acquire(&inode->i_state) & I_WB_SWITCH;
5095 +
5096 +- if (unlikely(*lockedp))
5097 +- spin_lock_irq(&inode->i_mapping->tree_lock);
5098 ++ if (unlikely(cookie->locked))
5099 ++ spin_lock_irqsave(&inode->i_mapping->tree_lock, cookie->flags);
5100 +
5101 + /*
5102 + * Protected by either !I_WB_SWITCH + rcu_read_lock() or tree_lock.
5103 +@@ -378,12 +378,13 @@ unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
5104 + /**
5105 + * unlocked_inode_to_wb_end - end inode wb access transaction
5106 + * @inode: target inode
5107 +- * @locked: *@lockedp from unlocked_inode_to_wb_begin()
5108 ++ * @cookie: @cookie from unlocked_inode_to_wb_begin()
5109 + */
5110 +-static inline void unlocked_inode_to_wb_end(struct inode *inode, bool locked)
5111 ++static inline void unlocked_inode_to_wb_end(struct inode *inode,
5112 ++ struct wb_lock_cookie *cookie)
5113 + {
5114 +- if (unlikely(locked))
5115 +- spin_unlock_irq(&inode->i_mapping->tree_lock);
5116 ++ if (unlikely(cookie->locked))
5117 ++ spin_unlock_irqrestore(&inode->i_mapping->tree_lock, cookie->flags);
5118 +
5119 + rcu_read_unlock();
5120 + }
5121 +@@ -430,12 +431,13 @@ static inline struct bdi_writeback *inode_to_wb(struct inode *inode)
5122 + }
5123 +
5124 + static inline struct bdi_writeback *
5125 +-unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
5126 ++unlocked_inode_to_wb_begin(struct inode *inode, struct wb_lock_cookie *cookie)
5127 + {
5128 + return inode_to_wb(inode);
5129 + }
5130 +
5131 +-static inline void unlocked_inode_to_wb_end(struct inode *inode, bool locked)
5132 ++static inline void unlocked_inode_to_wb_end(struct inode *inode,
5133 ++ struct wb_lock_cookie *cookie)
5134 + {
5135 + }
5136 +
5137 +diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
5138 +index 1c8a8a2aedf7..91072b68dc38 100644
5139 +--- a/include/linux/blk_types.h
5140 ++++ b/include/linux/blk_types.h
5141 +@@ -20,8 +20,13 @@ typedef void (bio_end_io_t) (struct bio *);
5142 +
5143 + /*
5144 + * Block error status values. See block/blk-core:blk_errors for the details.
5145 ++ * Alpha cannot write a byte atomically, so we need to use 32-bit value.
5146 + */
5147 ++#if defined(CONFIG_ALPHA) && !defined(__alpha_bwx__)
5148 ++typedef u32 __bitwise blk_status_t;
5149 ++#else
5150 + typedef u8 __bitwise blk_status_t;
5151 ++#endif
5152 + #define BLK_STS_OK 0
5153 + #define BLK_STS_NOTSUPP ((__force blk_status_t)1)
5154 + #define BLK_STS_TIMEOUT ((__force blk_status_t)2)
5155 +diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
5156 +index be3aef6839f6..070f85d92c15 100644
5157 +--- a/include/linux/compiler-clang.h
5158 ++++ b/include/linux/compiler-clang.h
5159 +@@ -17,9 +17,6 @@
5160 + */
5161 + #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
5162 +
5163 +-#define randomized_struct_fields_start struct {
5164 +-#define randomized_struct_fields_end };
5165 +-
5166 + /* Clang doesn't have a way to turn it off per-function, yet. */
5167 + #ifdef __noretpoline
5168 + #undef __noretpoline
5169 +diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
5170 +index a1ffbf25873f..b78b31af36f8 100644
5171 +--- a/include/linux/compiler-gcc.h
5172 ++++ b/include/linux/compiler-gcc.h
5173 +@@ -229,6 +229,9 @@
5174 + #ifdef RANDSTRUCT_PLUGIN
5175 + #define __randomize_layout __attribute__((randomize_layout))
5176 + #define __no_randomize_layout __attribute__((no_randomize_layout))
5177 ++/* This anon struct can add padding, so only enable it under randstruct. */
5178 ++#define randomized_struct_fields_start struct {
5179 ++#define randomized_struct_fields_end } __randomize_layout;
5180 + #endif
5181 +
5182 + #endif /* GCC_VERSION >= 40500 */
5183 +@@ -243,15 +246,6 @@
5184 + */
5185 + #define __visible __attribute__((externally_visible))
5186 +
5187 +-/*
5188 +- * RANDSTRUCT_PLUGIN wants to use an anonymous struct, but it is only
5189 +- * possible since GCC 4.6. To provide as much build testing coverage
5190 +- * as possible, this is used for all GCC 4.6+ builds, and not just on
5191 +- * RANDSTRUCT_PLUGIN builds.
5192 +- */
5193 +-#define randomized_struct_fields_start struct {
5194 +-#define randomized_struct_fields_end } __randomize_layout;
5195 +-
5196 + #endif /* GCC_VERSION >= 40600 */
5197 +
5198 +
5199 +diff --git a/include/linux/hid.h b/include/linux/hid.h
5200 +index ab05a86269dc..06e6e04e6c11 100644
5201 +--- a/include/linux/hid.h
5202 ++++ b/include/linux/hid.h
5203 +@@ -512,6 +512,12 @@ enum hid_type {
5204 + HID_TYPE_USBNONE
5205 + };
5206 +
5207 ++enum hid_battery_status {
5208 ++ HID_BATTERY_UNKNOWN = 0,
5209 ++ HID_BATTERY_QUERIED, /* Kernel explicitly queried battery strength */
5210 ++ HID_BATTERY_REPORTED, /* Device sent unsolicited battery strength report */
5211 ++};
5212 ++
5213 + struct hid_driver;
5214 + struct hid_ll_driver;
5215 +
5216 +@@ -554,7 +560,8 @@ struct hid_device { /* device report descriptor */
5217 + __s32 battery_max;
5218 + __s32 battery_report_type;
5219 + __s32 battery_report_id;
5220 +- bool battery_reported;
5221 ++ enum hid_battery_status battery_status;
5222 ++ bool battery_avoid_query;
5223 + #endif
5224 +
5225 + unsigned int status; /* see STAT flags above */
5226 +@@ -839,7 +846,7 @@ extern int hidinput_connect(struct hid_device *hid, unsigned int force);
5227 + extern void hidinput_disconnect(struct hid_device *);
5228 +
5229 + int hid_set_field(struct hid_field *, unsigned, __s32);
5230 +-int hid_input_report(struct hid_device *, int type, u8 *, int, int);
5231 ++int hid_input_report(struct hid_device *, int type, u8 *, u32, int);
5232 + int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field);
5233 + struct hid_field *hidinput_get_led_field(struct hid_device *hid);
5234 + unsigned int hidinput_count_leds(struct hid_device *hid);
5235 +@@ -1086,13 +1093,13 @@ static inline void hid_hw_wait(struct hid_device *hdev)
5236 + *
5237 + * @report: the report we want to know the length
5238 + */
5239 +-static inline int hid_report_len(struct hid_report *report)
5240 ++static inline u32 hid_report_len(struct hid_report *report)
5241 + {
5242 + /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */
5243 + return ((report->size - 1) >> 3) + 1 + (report->id > 0);
5244 + }
5245 +
5246 +-int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
5247 ++int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size,
5248 + int interrupt);
5249 +
5250 + /* HID quirks API */
5251 +diff --git a/include/linux/hmm.h b/include/linux/hmm.h
5252 +index 96e69979f84d..8198faf16ed6 100644
5253 +--- a/include/linux/hmm.h
5254 ++++ b/include/linux/hmm.h
5255 +@@ -498,23 +498,16 @@ struct hmm_device {
5256 + struct hmm_device *hmm_device_new(void *drvdata);
5257 + void hmm_device_put(struct hmm_device *hmm_device);
5258 + #endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */
5259 +-#endif /* IS_ENABLED(CONFIG_HMM) */
5260 +
5261 + /* Below are for HMM internal use only! Not to be used by device driver! */
5262 +-#if IS_ENABLED(CONFIG_HMM_MIRROR)
5263 + void hmm_mm_destroy(struct mm_struct *mm);
5264 +
5265 + static inline void hmm_mm_init(struct mm_struct *mm)
5266 + {
5267 + mm->hmm = NULL;
5268 + }
5269 +-#else /* IS_ENABLED(CONFIG_HMM_MIRROR) */
5270 +-static inline void hmm_mm_destroy(struct mm_struct *mm) {}
5271 +-static inline void hmm_mm_init(struct mm_struct *mm) {}
5272 +-#endif /* IS_ENABLED(CONFIG_HMM_MIRROR) */
5273 +-
5274 +-
5275 + #else /* IS_ENABLED(CONFIG_HMM) */
5276 + static inline void hmm_mm_destroy(struct mm_struct *mm) {}
5277 + static inline void hmm_mm_init(struct mm_struct *mm) {}
5278 ++#endif /* IS_ENABLED(CONFIG_HMM) */
5279 + #endif /* LINUX_HMM_H */
5280 +diff --git a/include/linux/tty.h b/include/linux/tty.h
5281 +index 0a6c71e0ad01..47f8af22f216 100644
5282 +--- a/include/linux/tty.h
5283 ++++ b/include/linux/tty.h
5284 +@@ -364,6 +364,7 @@ struct tty_file_private {
5285 + #define TTY_PTY_LOCK 16 /* pty private */
5286 + #define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */
5287 + #define TTY_HUPPED 18 /* Post driver->hangup() */
5288 ++#define TTY_HUPPING 19 /* Hangup in progress */
5289 + #define TTY_LDISC_HALTED 22 /* Line discipline is halted */
5290 +
5291 + /* Values for tty->flow_change */
5292 +diff --git a/include/sound/pcm_oss.h b/include/sound/pcm_oss.h
5293 +index 760c969d885d..12bbf8c81112 100644
5294 +--- a/include/sound/pcm_oss.h
5295 ++++ b/include/sound/pcm_oss.h
5296 +@@ -57,6 +57,7 @@ struct snd_pcm_oss_runtime {
5297 + char *buffer; /* vmallocated period */
5298 + size_t buffer_used; /* used length from period buffer */
5299 + struct mutex params_lock;
5300 ++ atomic_t rw_ref; /* concurrent read/write accesses */
5301 + #ifdef CONFIG_SND_PCM_OSS_PLUGINS
5302 + struct snd_pcm_plugin *plugin_first;
5303 + struct snd_pcm_plugin *plugin_last;
5304 +diff --git a/include/uapi/linux/random.h b/include/uapi/linux/random.h
5305 +index c34f4490d025..26ee91300e3e 100644
5306 +--- a/include/uapi/linux/random.h
5307 ++++ b/include/uapi/linux/random.h
5308 +@@ -35,6 +35,9 @@
5309 + /* Clear the entropy pool and associated counters. (Superuser only.) */
5310 + #define RNDCLEARPOOL _IO( 'R', 0x06 )
5311 +
5312 ++/* Reseed CRNG. (Superuser only.) */
5313 ++#define RNDRESEEDCRNG _IO( 'R', 0x07 )
5314 ++
5315 + struct rand_pool_info {
5316 + int entropy_count;
5317 + int buf_size;
5318 +diff --git a/ipc/shm.c b/ipc/shm.c
5319 +index b469e910f887..a9cce632ed48 100644
5320 +--- a/ipc/shm.c
5321 ++++ b/ipc/shm.c
5322 +@@ -203,6 +203,12 @@ static int __shm_open(struct vm_area_struct *vma)
5323 + if (IS_ERR(shp))
5324 + return PTR_ERR(shp);
5325 +
5326 ++ if (shp->shm_file != sfd->file) {
5327 ++ /* ID was reused */
5328 ++ shm_unlock(shp);
5329 ++ return -EINVAL;
5330 ++ }
5331 ++
5332 + shp->shm_atim = ktime_get_real_seconds();
5333 + shp->shm_lprid = task_tgid_vnr(current);
5334 + shp->shm_nattch++;
5335 +@@ -431,8 +437,9 @@ static int shm_mmap(struct file *file, struct vm_area_struct *vma)
5336 + int ret;
5337 +
5338 + /*
5339 +- * In case of remap_file_pages() emulation, the file can represent
5340 +- * removed IPC ID: propogate shm_lock() error to caller.
5341 ++ * In case of remap_file_pages() emulation, the file can represent an
5342 ++ * IPC ID that was removed, and possibly even reused by another shm
5343 ++ * segment already. Propagate this case as an error to caller.
5344 + */
5345 + ret = __shm_open(vma);
5346 + if (ret)
5347 +@@ -456,6 +463,7 @@ static int shm_release(struct inode *ino, struct file *file)
5348 + struct shm_file_data *sfd = shm_file_data(file);
5349 +
5350 + put_ipc_ns(sfd->ns);
5351 ++ fput(sfd->file);
5352 + shm_file_data(file) = NULL;
5353 + kfree(sfd);
5354 + return 0;
5355 +@@ -1391,7 +1399,16 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg,
5356 + file->f_mapping = shp->shm_file->f_mapping;
5357 + sfd->id = shp->shm_perm.id;
5358 + sfd->ns = get_ipc_ns(ns);
5359 +- sfd->file = shp->shm_file;
5360 ++ /*
5361 ++ * We need to take a reference to the real shm file to prevent the
5362 ++ * pointer from becoming stale in cases where the lifetime of the outer
5363 ++ * file extends beyond that of the shm segment. It's not usually
5364 ++ * possible, but it can happen during remap_file_pages() emulation as
5365 ++ * that unmaps the memory, then does ->mmap() via file reference only.
5366 ++ * We'll deny the ->mmap() if the shm segment was since removed, but to
5367 ++ * detect shm ID reuse we need to compare the file pointers.
5368 ++ */
5369 ++ sfd->file = get_file(shp->shm_file);
5370 + sfd->vm_ops = NULL;
5371 +
5372 + err = security_mmap_file(file, prot, flags);
5373 +diff --git a/kernel/resource.c b/kernel/resource.c
5374 +index 9b5f04404152..7ee3dd1ad2af 100644
5375 +--- a/kernel/resource.c
5376 ++++ b/kernel/resource.c
5377 +@@ -633,7 +633,8 @@ static int __find_resource(struct resource *root, struct resource *old,
5378 + alloc.start = constraint->alignf(constraint->alignf_data, &avail,
5379 + size, constraint->align);
5380 + alloc.end = alloc.start + size - 1;
5381 +- if (resource_contains(&avail, &alloc)) {
5382 ++ if (alloc.start <= alloc.end &&
5383 ++ resource_contains(&avail, &alloc)) {
5384 + new->start = alloc.start;
5385 + new->end = alloc.end;
5386 + return 0;
5387 +diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
5388 +index 39c221454186..36f018b15392 100644
5389 +--- a/kernel/trace/ring_buffer.c
5390 ++++ b/kernel/trace/ring_buffer.c
5391 +@@ -1136,6 +1136,11 @@ static int __rb_allocate_pages(long nr_pages, struct list_head *pages, int cpu)
5392 + struct buffer_page *bpage, *tmp;
5393 + long i;
5394 +
5395 ++ /* Check if the available memory is there first */
5396 ++ i = si_mem_available();
5397 ++ if (i < nr_pages)
5398 ++ return -ENOMEM;
5399 ++
5400 + for (i = 0; i < nr_pages; i++) {
5401 + struct page *page;
5402 + /*
5403 +diff --git a/mm/filemap.c b/mm/filemap.c
5404 +index 594d73fef8b4..e2e738cc08b1 100644
5405 +--- a/mm/filemap.c
5406 ++++ b/mm/filemap.c
5407 +@@ -688,7 +688,7 @@ int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask)
5408 + VM_BUG_ON_PAGE(!PageLocked(new), new);
5409 + VM_BUG_ON_PAGE(new->mapping, new);
5410 +
5411 +- error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM);
5412 ++ error = radix_tree_preload(gfp_mask & GFP_RECLAIM_MASK);
5413 + if (!error) {
5414 + struct address_space *mapping = old->mapping;
5415 + void (*freepage)(struct page *);
5416 +@@ -744,7 +744,7 @@ static int __add_to_page_cache_locked(struct page *page,
5417 + return error;
5418 + }
5419 +
5420 +- error = radix_tree_maybe_preload(gfp_mask & ~__GFP_HIGHMEM);
5421 ++ error = radix_tree_maybe_preload(gfp_mask & GFP_RECLAIM_MASK);
5422 + if (error) {
5423 + if (!huge)
5424 + mem_cgroup_cancel_charge(page, memcg, false);
5425 +@@ -1486,8 +1486,7 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
5426 + if (fgp_flags & FGP_ACCESSED)
5427 + __SetPageReferenced(page);
5428 +
5429 +- err = add_to_page_cache_lru(page, mapping, offset,
5430 +- gfp_mask & GFP_RECLAIM_MASK);
5431 ++ err = add_to_page_cache_lru(page, mapping, offset, gfp_mask);
5432 + if (unlikely(err)) {
5433 + put_page(page);
5434 + page = NULL;
5435 +@@ -2275,7 +2274,7 @@ static int page_cache_read(struct file *file, pgoff_t offset, gfp_t gfp_mask)
5436 + if (!page)
5437 + return -ENOMEM;
5438 +
5439 +- ret = add_to_page_cache_lru(page, mapping, offset, gfp_mask & GFP_KERNEL);
5440 ++ ret = add_to_page_cache_lru(page, mapping, offset, gfp_mask);
5441 + if (ret == 0)
5442 + ret = mapping->a_ops->readpage(file, page);
5443 + else if (ret == -EEXIST)
5444 +diff --git a/mm/hmm.c b/mm/hmm.c
5445 +index a88a847bccba..81ff1dbbf8a8 100644
5446 +--- a/mm/hmm.c
5447 ++++ b/mm/hmm.c
5448 +@@ -277,7 +277,8 @@ static int hmm_pfns_bad(unsigned long addr,
5449 + unsigned long end,
5450 + struct mm_walk *walk)
5451 + {
5452 +- struct hmm_range *range = walk->private;
5453 ++ struct hmm_vma_walk *hmm_vma_walk = walk->private;
5454 ++ struct hmm_range *range = hmm_vma_walk->range;
5455 + hmm_pfn_t *pfns = range->pfns;
5456 + unsigned long i;
5457 +
5458 +diff --git a/mm/ksm.c b/mm/ksm.c
5459 +index 6cb60f46cce5..5b6be9eeb095 100644
5460 +--- a/mm/ksm.c
5461 ++++ b/mm/ksm.c
5462 +@@ -1133,6 +1133,13 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
5463 + } else {
5464 + newpte = pte_mkspecial(pfn_pte(page_to_pfn(kpage),
5465 + vma->vm_page_prot));
5466 ++ /*
5467 ++ * We're replacing an anonymous page with a zero page, which is
5468 ++ * not anonymous. We need to do proper accounting otherwise we
5469 ++ * will get wrong values in /proc, and a BUG message in dmesg
5470 ++ * when tearing down the mm.
5471 ++ */
5472 ++ dec_mm_counter(mm, MM_ANONPAGES);
5473 + }
5474 +
5475 + flush_cache_page(vma, addr, pte_pfn(*ptep));
5476 +diff --git a/mm/page-writeback.c b/mm/page-writeback.c
5477 +index 0b9c5cbe8eba..3175ac850a53 100644
5478 +--- a/mm/page-writeback.c
5479 ++++ b/mm/page-writeback.c
5480 +@@ -2518,13 +2518,13 @@ void account_page_redirty(struct page *page)
5481 + if (mapping && mapping_cap_account_dirty(mapping)) {
5482 + struct inode *inode = mapping->host;
5483 + struct bdi_writeback *wb;
5484 +- bool locked;
5485 ++ struct wb_lock_cookie cookie = {};
5486 +
5487 +- wb = unlocked_inode_to_wb_begin(inode, &locked);
5488 ++ wb = unlocked_inode_to_wb_begin(inode, &cookie);
5489 + current->nr_dirtied--;
5490 + dec_node_page_state(page, NR_DIRTIED);
5491 + dec_wb_stat(wb, WB_DIRTIED);
5492 +- unlocked_inode_to_wb_end(inode, locked);
5493 ++ unlocked_inode_to_wb_end(inode, &cookie);
5494 + }
5495 + }
5496 + EXPORT_SYMBOL(account_page_redirty);
5497 +@@ -2630,15 +2630,15 @@ void cancel_dirty_page(struct page *page)
5498 + if (mapping_cap_account_dirty(mapping)) {
5499 + struct inode *inode = mapping->host;
5500 + struct bdi_writeback *wb;
5501 +- bool locked;
5502 ++ struct wb_lock_cookie cookie = {};
5503 +
5504 + lock_page_memcg(page);
5505 +- wb = unlocked_inode_to_wb_begin(inode, &locked);
5506 ++ wb = unlocked_inode_to_wb_begin(inode, &cookie);
5507 +
5508 + if (TestClearPageDirty(page))
5509 + account_page_cleaned(page, mapping, wb);
5510 +
5511 +- unlocked_inode_to_wb_end(inode, locked);
5512 ++ unlocked_inode_to_wb_end(inode, &cookie);
5513 + unlock_page_memcg(page);
5514 + } else {
5515 + ClearPageDirty(page);
5516 +@@ -2670,7 +2670,7 @@ int clear_page_dirty_for_io(struct page *page)
5517 + if (mapping && mapping_cap_account_dirty(mapping)) {
5518 + struct inode *inode = mapping->host;
5519 + struct bdi_writeback *wb;
5520 +- bool locked;
5521 ++ struct wb_lock_cookie cookie = {};
5522 +
5523 + /*
5524 + * Yes, Virginia, this is indeed insane.
5525 +@@ -2707,14 +2707,14 @@ int clear_page_dirty_for_io(struct page *page)
5526 + * always locked coming in here, so we get the desired
5527 + * exclusion.
5528 + */
5529 +- wb = unlocked_inode_to_wb_begin(inode, &locked);
5530 ++ wb = unlocked_inode_to_wb_begin(inode, &cookie);
5531 + if (TestClearPageDirty(page)) {
5532 + dec_lruvec_page_state(page, NR_FILE_DIRTY);
5533 + dec_zone_page_state(page, NR_ZONE_WRITE_PENDING);
5534 + dec_wb_stat(wb, WB_RECLAIMABLE);
5535 + ret = 1;
5536 + }
5537 +- unlocked_inode_to_wb_end(inode, locked);
5538 ++ unlocked_inode_to_wb_end(inode, &cookie);
5539 + return ret;
5540 + }
5541 + return TestClearPageDirty(page);
5542 +diff --git a/mm/slab.c b/mm/slab.c
5543 +index 966839a1ac2c..1bfc3d847a0a 100644
5544 +--- a/mm/slab.c
5545 ++++ b/mm/slab.c
5546 +@@ -4080,7 +4080,8 @@ static void cache_reap(struct work_struct *w)
5547 + next_reap_node();
5548 + out:
5549 + /* Set up the next iteration */
5550 +- schedule_delayed_work(work, round_jiffies_relative(REAPTIMEOUT_AC));
5551 ++ schedule_delayed_work_on(smp_processor_id(), work,
5552 ++ round_jiffies_relative(REAPTIMEOUT_AC));
5553 + }
5554 +
5555 + #ifdef CONFIG_SLABINFO
5556 +diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
5557 +index dbb016434ace..de92fc1fc3be 100644
5558 +--- a/net/dsa/tag_brcm.c
5559 ++++ b/net/dsa/tag_brcm.c
5560 +@@ -121,6 +121,9 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
5561 + if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
5562 + return NULL;
5563 +
5564 ++ if (unlikely(ds->cpu_port_mask & BIT(source_port)))
5565 ++ return NULL;
5566 ++
5567 + /* Remove Broadcom tag and update checksum */
5568 + skb_pull_rcsum(skb, BRCM_TAG_LEN);
5569 +
5570 +diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
5571 +index fbf9ca954773..b3008a9bacf3 100644
5572 +--- a/net/dsa/tag_dsa.c
5573 ++++ b/net/dsa/tag_dsa.c
5574 +@@ -107,6 +107,9 @@ static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
5575 + if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
5576 + return NULL;
5577 +
5578 ++ if (unlikely(ds->cpu_port_mask & BIT(source_port)))
5579 ++ return NULL;
5580 ++
5581 + /*
5582 + * Convert the DSA header to an 802.1q header if the 'tagged'
5583 + * bit in the DSA header is set. If the 'tagged' bit is clear,
5584 +diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
5585 +index 76367ba1b2e2..c86b6d90576d 100644
5586 +--- a/net/dsa/tag_edsa.c
5587 ++++ b/net/dsa/tag_edsa.c
5588 +@@ -120,6 +120,9 @@ static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev,
5589 + if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
5590 + return NULL;
5591 +
5592 ++ if (unlikely(ds->cpu_port_mask & BIT(source_port)))
5593 ++ return NULL;
5594 ++
5595 + /*
5596 + * If the 'tagged' bit is set, convert the DSA tag to a 802.1q
5597 + * tag and delete the ethertype part. If the 'tagged' bit is
5598 +diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
5599 +index 010ca0a336c4..6c894692b9cd 100644
5600 +--- a/net/dsa/tag_ksz.c
5601 ++++ b/net/dsa/tag_ksz.c
5602 +@@ -92,6 +92,9 @@ static struct sk_buff *ksz_rcv(struct sk_buff *skb, struct net_device *dev,
5603 + if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
5604 + return NULL;
5605 +
5606 ++ if (unlikely(ds->cpu_port_mask & BIT(source_port)))
5607 ++ return NULL;
5608 ++
5609 + pskb_trim_rcsum(skb, skb->len - KSZ_EGRESS_TAG_LEN);
5610 +
5611 + skb->dev = ds->ports[source_port].netdev;
5612 +diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
5613 +index 0b9826105e42..2d1603009e16 100644
5614 +--- a/net/dsa/tag_lan9303.c
5615 ++++ b/net/dsa/tag_lan9303.c
5616 +@@ -108,6 +108,9 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev,
5617 + return NULL;
5618 + }
5619 +
5620 ++ if (unlikely(ds->cpu_port_mask & BIT(source_port)))
5621 ++ return NULL;
5622 ++
5623 + if (!ds->ports[source_port].netdev) {
5624 + dev_warn_ratelimited(&dev->dev, "Dropping packet due to invalid netdev or device\n");
5625 + return NULL;
5626 +diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
5627 +index ec8ee5f43255..5c471854412d 100644
5628 +--- a/net/dsa/tag_mtk.c
5629 ++++ b/net/dsa/tag_mtk.c
5630 +@@ -81,6 +81,9 @@ static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev,
5631 + if (!ds->ports[port].netdev)
5632 + return NULL;
5633 +
5634 ++ if (unlikely(ds->cpu_port_mask & BIT(port)))
5635 ++ return NULL;
5636 ++
5637 + skb->dev = ds->ports[port].netdev;
5638 +
5639 + return skb;
5640 +diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
5641 +index 1d4c70711c0f..b8c05f1cf47d 100644
5642 +--- a/net/dsa/tag_qca.c
5643 ++++ b/net/dsa/tag_qca.c
5644 +@@ -104,6 +104,9 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev,
5645 + if (!ds->ports[port].netdev)
5646 + return NULL;
5647 +
5648 ++ if (unlikely(ds->cpu_port_mask & BIT(port)))
5649 ++ return NULL;
5650 ++
5651 + /* Update skb & forward the frame accordingly */
5652 + skb->dev = ds->ports[port].netdev;
5653 +
5654 +diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
5655 +index d2fd4923aa3e..fcc9aa72877d 100644
5656 +--- a/net/dsa/tag_trailer.c
5657 ++++ b/net/dsa/tag_trailer.c
5658 +@@ -76,6 +76,9 @@ static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
5659 + if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
5660 + return NULL;
5661 +
5662 ++ if (unlikely(ds->cpu_port_mask & BIT(source_port)))
5663 ++ return NULL;
5664 ++
5665 + pskb_trim_rcsum(skb, skb->len - 4);
5666 +
5667 + skb->dev = ds->ports[source_port].netdev;
5668 +diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
5669 +index 61a504fb1ae2..34f94052c519 100644
5670 +--- a/net/sunrpc/rpc_pipe.c
5671 ++++ b/net/sunrpc/rpc_pipe.c
5672 +@@ -1375,6 +1375,7 @@ rpc_gssd_dummy_depopulate(struct dentry *pipe_dentry)
5673 + struct dentry *clnt_dir = pipe_dentry->d_parent;
5674 + struct dentry *gssd_dir = clnt_dir->d_parent;
5675 +
5676 ++ dget(pipe_dentry);
5677 + __rpc_rmpipe(d_inode(clnt_dir), pipe_dentry);
5678 + __rpc_depopulate(clnt_dir, gssd_dummy_info_file, 0, 1);
5679 + __rpc_depopulate(gssd_dir, gssd_dummy_clnt_dir, 0, 1);
5680 +diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
5681 +index d6e9a18fd821..b4f954e6d2db 100644
5682 +--- a/sound/core/oss/pcm_oss.c
5683 ++++ b/sound/core/oss/pcm_oss.c
5684 +@@ -823,8 +823,25 @@ static int choose_rate(struct snd_pcm_substream *substream,
5685 + return snd_pcm_hw_param_near(substream, params, SNDRV_PCM_HW_PARAM_RATE, best_rate, NULL);
5686 + }
5687 +
5688 +-static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream,
5689 +- bool trylock)
5690 ++/* parameter locking: returns immediately if tried during streaming */
5691 ++static int lock_params(struct snd_pcm_runtime *runtime)
5692 ++{
5693 ++ if (mutex_lock_interruptible(&runtime->oss.params_lock))
5694 ++ return -ERESTARTSYS;
5695 ++ if (atomic_read(&runtime->oss.rw_ref)) {
5696 ++ mutex_unlock(&runtime->oss.params_lock);
5697 ++ return -EBUSY;
5698 ++ }
5699 ++ return 0;
5700 ++}
5701 ++
5702 ++static void unlock_params(struct snd_pcm_runtime *runtime)
5703 ++{
5704 ++ mutex_unlock(&runtime->oss.params_lock);
5705 ++}
5706 ++
5707 ++/* call with params_lock held */
5708 ++static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
5709 + {
5710 + struct snd_pcm_runtime *runtime = substream->runtime;
5711 + struct snd_pcm_hw_params *params, *sparams;
5712 +@@ -838,11 +855,8 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream,
5713 + const struct snd_mask *sformat_mask;
5714 + struct snd_mask mask;
5715 +
5716 +- if (trylock) {
5717 +- if (!(mutex_trylock(&runtime->oss.params_lock)))
5718 +- return -EAGAIN;
5719 +- } else if (mutex_lock_interruptible(&runtime->oss.params_lock))
5720 +- return -EINTR;
5721 ++ if (!runtime->oss.params)
5722 ++ return 0;
5723 + sw_params = kzalloc(sizeof(*sw_params), GFP_KERNEL);
5724 + params = kmalloc(sizeof(*params), GFP_KERNEL);
5725 + sparams = kmalloc(sizeof(*sparams), GFP_KERNEL);
5726 +@@ -1068,6 +1082,23 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream,
5727 + kfree(sw_params);
5728 + kfree(params);
5729 + kfree(sparams);
5730 ++ return err;
5731 ++}
5732 ++
5733 ++/* this one takes the lock by itself */
5734 ++static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream,
5735 ++ bool trylock)
5736 ++{
5737 ++ struct snd_pcm_runtime *runtime = substream->runtime;
5738 ++ int err;
5739 ++
5740 ++ if (trylock) {
5741 ++ if (!(mutex_trylock(&runtime->oss.params_lock)))
5742 ++ return -EAGAIN;
5743 ++ } else if (mutex_lock_interruptible(&runtime->oss.params_lock))
5744 ++ return -ERESTARTSYS;
5745 ++
5746 ++ err = snd_pcm_oss_change_params_locked(substream);
5747 + mutex_unlock(&runtime->oss.params_lock);
5748 + return err;
5749 + }
5750 +@@ -1096,6 +1127,10 @@ static int snd_pcm_oss_get_active_substream(struct snd_pcm_oss_file *pcm_oss_fil
5751 + return 0;
5752 + }
5753 +
5754 ++/* call with params_lock held */
5755 ++/* NOTE: this always call PREPARE unconditionally no matter whether
5756 ++ * runtime->oss.prepare is set or not
5757 ++ */
5758 + static int snd_pcm_oss_prepare(struct snd_pcm_substream *substream)
5759 + {
5760 + int err;
5761 +@@ -1120,14 +1155,35 @@ static int snd_pcm_oss_make_ready(struct snd_pcm_substream *substream)
5762 + struct snd_pcm_runtime *runtime;
5763 + int err;
5764 +
5765 +- if (substream == NULL)
5766 +- return 0;
5767 + runtime = substream->runtime;
5768 + if (runtime->oss.params) {
5769 + err = snd_pcm_oss_change_params(substream, false);
5770 + if (err < 0)
5771 + return err;
5772 + }
5773 ++ if (runtime->oss.prepare) {
5774 ++ if (mutex_lock_interruptible(&runtime->oss.params_lock))
5775 ++ return -ERESTARTSYS;
5776 ++ err = snd_pcm_oss_prepare(substream);
5777 ++ mutex_unlock(&runtime->oss.params_lock);
5778 ++ if (err < 0)
5779 ++ return err;
5780 ++ }
5781 ++ return 0;
5782 ++}
5783 ++
5784 ++/* call with params_lock held */
5785 ++static int snd_pcm_oss_make_ready_locked(struct snd_pcm_substream *substream)
5786 ++{
5787 ++ struct snd_pcm_runtime *runtime;
5788 ++ int err;
5789 ++
5790 ++ runtime = substream->runtime;
5791 ++ if (runtime->oss.params) {
5792 ++ err = snd_pcm_oss_change_params_locked(substream);
5793 ++ if (err < 0)
5794 ++ return err;
5795 ++ }
5796 + if (runtime->oss.prepare) {
5797 + err = snd_pcm_oss_prepare(substream);
5798 + if (err < 0)
5799 +@@ -1332,13 +1388,15 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
5800 + if (atomic_read(&substream->mmap_count))
5801 + return -ENXIO;
5802 +
5803 +- if ((tmp = snd_pcm_oss_make_ready(substream)) < 0)
5804 +- return tmp;
5805 ++ atomic_inc(&runtime->oss.rw_ref);
5806 + while (bytes > 0) {
5807 + if (mutex_lock_interruptible(&runtime->oss.params_lock)) {
5808 + tmp = -ERESTARTSYS;
5809 + break;
5810 + }
5811 ++ tmp = snd_pcm_oss_make_ready_locked(substream);
5812 ++ if (tmp < 0)
5813 ++ goto err;
5814 + if (bytes < runtime->oss.period_bytes || runtime->oss.buffer_used > 0) {
5815 + tmp = bytes;
5816 + if (tmp + runtime->oss.buffer_used > runtime->oss.period_bytes)
5817 +@@ -1394,6 +1452,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
5818 + }
5819 + tmp = 0;
5820 + }
5821 ++ atomic_dec(&runtime->oss.rw_ref);
5822 + return xfer > 0 ? (snd_pcm_sframes_t)xfer : tmp;
5823 + }
5824 +
5825 +@@ -1439,13 +1498,15 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
5826 + if (atomic_read(&substream->mmap_count))
5827 + return -ENXIO;
5828 +
5829 +- if ((tmp = snd_pcm_oss_make_ready(substream)) < 0)
5830 +- return tmp;
5831 ++ atomic_inc(&runtime->oss.rw_ref);
5832 + while (bytes > 0) {
5833 + if (mutex_lock_interruptible(&runtime->oss.params_lock)) {
5834 + tmp = -ERESTARTSYS;
5835 + break;
5836 + }
5837 ++ tmp = snd_pcm_oss_make_ready_locked(substream);
5838 ++ if (tmp < 0)
5839 ++ goto err;
5840 + if (bytes < runtime->oss.period_bytes || runtime->oss.buffer_used > 0) {
5841 + if (runtime->oss.buffer_used == 0) {
5842 + tmp = snd_pcm_oss_read2(substream, runtime->oss.buffer, runtime->oss.period_bytes, 1);
5843 +@@ -1486,6 +1547,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
5844 + }
5845 + tmp = 0;
5846 + }
5847 ++ atomic_dec(&runtime->oss.rw_ref);
5848 + return xfer > 0 ? (snd_pcm_sframes_t)xfer : tmp;
5849 + }
5850 +
5851 +@@ -1501,10 +1563,12 @@ static int snd_pcm_oss_reset(struct snd_pcm_oss_file *pcm_oss_file)
5852 + continue;
5853 + runtime = substream->runtime;
5854 + snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
5855 ++ mutex_lock(&runtime->oss.params_lock);
5856 + runtime->oss.prepare = 1;
5857 + runtime->oss.buffer_used = 0;
5858 + runtime->oss.prev_hw_ptr_period = 0;
5859 + runtime->oss.period_ptr = 0;
5860 ++ mutex_unlock(&runtime->oss.params_lock);
5861 + }
5862 + return 0;
5863 + }
5864 +@@ -1590,9 +1654,13 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
5865 + goto __direct;
5866 + if ((err = snd_pcm_oss_make_ready(substream)) < 0)
5867 + return err;
5868 ++ atomic_inc(&runtime->oss.rw_ref);
5869 ++ if (mutex_lock_interruptible(&runtime->oss.params_lock)) {
5870 ++ atomic_dec(&runtime->oss.rw_ref);
5871 ++ return -ERESTARTSYS;
5872 ++ }
5873 + format = snd_pcm_oss_format_from(runtime->oss.format);
5874 + width = snd_pcm_format_physical_width(format);
5875 +- mutex_lock(&runtime->oss.params_lock);
5876 + if (runtime->oss.buffer_used > 0) {
5877 + #ifdef OSS_DEBUG
5878 + pcm_dbg(substream->pcm, "sync: buffer_used\n");
5879 +@@ -1602,10 +1670,8 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
5880 + runtime->oss.buffer + runtime->oss.buffer_used,
5881 + size);
5882 + err = snd_pcm_oss_sync1(substream, runtime->oss.period_bytes);
5883 +- if (err < 0) {
5884 +- mutex_unlock(&runtime->oss.params_lock);
5885 +- return err;
5886 +- }
5887 ++ if (err < 0)
5888 ++ goto unlock;
5889 + } else if (runtime->oss.period_ptr > 0) {
5890 + #ifdef OSS_DEBUG
5891 + pcm_dbg(substream->pcm, "sync: period_ptr\n");
5892 +@@ -1615,10 +1681,8 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
5893 + runtime->oss.buffer,
5894 + size * 8 / width);
5895 + err = snd_pcm_oss_sync1(substream, size);
5896 +- if (err < 0) {
5897 +- mutex_unlock(&runtime->oss.params_lock);
5898 +- return err;
5899 +- }
5900 ++ if (err < 0)
5901 ++ goto unlock;
5902 + }
5903 + /*
5904 + * The ALSA's period might be a bit large than OSS one.
5905 +@@ -1632,7 +1696,11 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
5906 + else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
5907 + snd_pcm_lib_writev(substream, NULL, size);
5908 + }
5909 ++unlock:
5910 + mutex_unlock(&runtime->oss.params_lock);
5911 ++ atomic_dec(&runtime->oss.rw_ref);
5912 ++ if (err < 0)
5913 ++ return err;
5914 + /*
5915 + * finish sync: drain the buffer
5916 + */
5917 +@@ -1643,7 +1711,9 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
5918 + substream->f_flags = saved_f_flags;
5919 + if (err < 0)
5920 + return err;
5921 ++ mutex_lock(&runtime->oss.params_lock);
5922 + runtime->oss.prepare = 1;
5923 ++ mutex_unlock(&runtime->oss.params_lock);
5924 + }
5925 +
5926 + substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
5927 +@@ -1654,8 +1724,10 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
5928 + err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
5929 + if (err < 0)
5930 + return err;
5931 ++ mutex_lock(&runtime->oss.params_lock);
5932 + runtime->oss.buffer_used = 0;
5933 + runtime->oss.prepare = 1;
5934 ++ mutex_unlock(&runtime->oss.params_lock);
5935 + }
5936 + return 0;
5937 + }
5938 +@@ -1667,6 +1739,8 @@ static int snd_pcm_oss_set_rate(struct snd_pcm_oss_file *pcm_oss_file, int rate)
5939 + for (idx = 1; idx >= 0; --idx) {
5940 + struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
5941 + struct snd_pcm_runtime *runtime;
5942 ++ int err;
5943 ++
5944 + if (substream == NULL)
5945 + continue;
5946 + runtime = substream->runtime;
5947 +@@ -1674,10 +1748,14 @@ static int snd_pcm_oss_set_rate(struct snd_pcm_oss_file *pcm_oss_file, int rate)
5948 + rate = 1000;
5949 + else if (rate > 192000)
5950 + rate = 192000;
5951 ++ err = lock_params(runtime);
5952 ++ if (err < 0)
5953 ++ return err;
5954 + if (runtime->oss.rate != rate) {
5955 + runtime->oss.params = 1;
5956 + runtime->oss.rate = rate;
5957 + }
5958 ++ unlock_params(runtime);
5959 + }
5960 + return snd_pcm_oss_get_rate(pcm_oss_file);
5961 + }
5962 +@@ -1702,13 +1780,19 @@ static int snd_pcm_oss_set_channels(struct snd_pcm_oss_file *pcm_oss_file, unsig
5963 + for (idx = 1; idx >= 0; --idx) {
5964 + struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
5965 + struct snd_pcm_runtime *runtime;
5966 ++ int err;
5967 ++
5968 + if (substream == NULL)
5969 + continue;
5970 + runtime = substream->runtime;
5971 ++ err = lock_params(runtime);
5972 ++ if (err < 0)
5973 ++ return err;
5974 + if (runtime->oss.channels != channels) {
5975 + runtime->oss.params = 1;
5976 + runtime->oss.channels = channels;
5977 + }
5978 ++ unlock_params(runtime);
5979 + }
5980 + return snd_pcm_oss_get_channels(pcm_oss_file);
5981 + }
5982 +@@ -1781,6 +1865,7 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file)
5983 + static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int format)
5984 + {
5985 + int formats, idx;
5986 ++ int err;
5987 +
5988 + if (format != AFMT_QUERY) {
5989 + formats = snd_pcm_oss_get_formats(pcm_oss_file);
5990 +@@ -1794,10 +1879,14 @@ static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int for
5991 + if (substream == NULL)
5992 + continue;
5993 + runtime = substream->runtime;
5994 ++ err = lock_params(runtime);
5995 ++ if (err < 0)
5996 ++ return err;
5997 + if (runtime->oss.format != format) {
5998 + runtime->oss.params = 1;
5999 + runtime->oss.format = format;
6000 + }
6001 ++ unlock_params(runtime);
6002 + }
6003 + }
6004 + return snd_pcm_oss_get_format(pcm_oss_file);
6005 +@@ -1817,8 +1906,6 @@ static int snd_pcm_oss_set_subdivide1(struct snd_pcm_substream *substream, int s
6006 + {
6007 + struct snd_pcm_runtime *runtime;
6008 +
6009 +- if (substream == NULL)
6010 +- return 0;
6011 + runtime = substream->runtime;
6012 + if (subdivide == 0) {
6013 + subdivide = runtime->oss.subdivision;
6014 +@@ -1842,9 +1929,17 @@ static int snd_pcm_oss_set_subdivide(struct snd_pcm_oss_file *pcm_oss_file, int
6015 +
6016 + for (idx = 1; idx >= 0; --idx) {
6017 + struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
6018 ++ struct snd_pcm_runtime *runtime;
6019 ++
6020 + if (substream == NULL)
6021 + continue;
6022 +- if ((err = snd_pcm_oss_set_subdivide1(substream, subdivide)) < 0)
6023 ++ runtime = substream->runtime;
6024 ++ err = lock_params(runtime);
6025 ++ if (err < 0)
6026 ++ return err;
6027 ++ err = snd_pcm_oss_set_subdivide1(substream, subdivide);
6028 ++ unlock_params(runtime);
6029 ++ if (err < 0)
6030 + return err;
6031 + }
6032 + return err;
6033 +@@ -1854,8 +1949,6 @@ static int snd_pcm_oss_set_fragment1(struct snd_pcm_substream *substream, unsign
6034 + {
6035 + struct snd_pcm_runtime *runtime;
6036 +
6037 +- if (substream == NULL)
6038 +- return 0;
6039 + runtime = substream->runtime;
6040 + if (runtime->oss.subdivision || runtime->oss.fragshift)
6041 + return -EINVAL;
6042 +@@ -1875,9 +1968,17 @@ static int snd_pcm_oss_set_fragment(struct snd_pcm_oss_file *pcm_oss_file, unsig
6043 +
6044 + for (idx = 1; idx >= 0; --idx) {
6045 + struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
6046 ++ struct snd_pcm_runtime *runtime;
6047 ++
6048 + if (substream == NULL)
6049 + continue;
6050 +- if ((err = snd_pcm_oss_set_fragment1(substream, val)) < 0)
6051 ++ runtime = substream->runtime;
6052 ++ err = lock_params(runtime);
6053 ++ if (err < 0)
6054 ++ return err;
6055 ++ err = snd_pcm_oss_set_fragment1(substream, val);
6056 ++ unlock_params(runtime);
6057 ++ if (err < 0)
6058 + return err;
6059 + }
6060 + return err;
6061 +@@ -1961,6 +2062,9 @@ static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int tr
6062 + }
6063 + if (psubstream) {
6064 + runtime = psubstream->runtime;
6065 ++ cmd = 0;
6066 ++ if (mutex_lock_interruptible(&runtime->oss.params_lock))
6067 ++ return -ERESTARTSYS;
6068 + if (trigger & PCM_ENABLE_OUTPUT) {
6069 + if (runtime->oss.trigger)
6070 + goto _skip1;
6071 +@@ -1978,13 +2082,19 @@ static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int tr
6072 + cmd = SNDRV_PCM_IOCTL_DROP;
6073 + runtime->oss.prepare = 1;
6074 + }
6075 +- err = snd_pcm_kernel_ioctl(psubstream, cmd, NULL);
6076 +- if (err < 0)
6077 +- return err;
6078 +- }
6079 + _skip1:
6080 ++ mutex_unlock(&runtime->oss.params_lock);
6081 ++ if (cmd) {
6082 ++ err = snd_pcm_kernel_ioctl(psubstream, cmd, NULL);
6083 ++ if (err < 0)
6084 ++ return err;
6085 ++ }
6086 ++ }
6087 + if (csubstream) {
6088 + runtime = csubstream->runtime;
6089 ++ cmd = 0;
6090 ++ if (mutex_lock_interruptible(&runtime->oss.params_lock))
6091 ++ return -ERESTARTSYS;
6092 + if (trigger & PCM_ENABLE_INPUT) {
6093 + if (runtime->oss.trigger)
6094 + goto _skip2;
6095 +@@ -1999,11 +2109,14 @@ static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int tr
6096 + cmd = SNDRV_PCM_IOCTL_DROP;
6097 + runtime->oss.prepare = 1;
6098 + }
6099 +- err = snd_pcm_kernel_ioctl(csubstream, cmd, NULL);
6100 +- if (err < 0)
6101 +- return err;
6102 +- }
6103 + _skip2:
6104 ++ mutex_unlock(&runtime->oss.params_lock);
6105 ++ if (cmd) {
6106 ++ err = snd_pcm_kernel_ioctl(csubstream, cmd, NULL);
6107 ++ if (err < 0)
6108 ++ return err;
6109 ++ }
6110 ++ }
6111 + return 0;
6112 + }
6113 +
6114 +@@ -2255,6 +2368,7 @@ static void snd_pcm_oss_init_substream(struct snd_pcm_substream *substream,
6115 + runtime->oss.maxfrags = 0;
6116 + runtime->oss.subdivision = 0;
6117 + substream->pcm_release = snd_pcm_oss_release_substream;
6118 ++ atomic_set(&runtime->oss.rw_ref, 0);
6119 + }
6120 +
6121 + static int snd_pcm_oss_release_file(struct snd_pcm_oss_file *pcm_oss_file)
6122 +diff --git a/sound/core/pcm.c b/sound/core/pcm.c
6123 +index 7fea724d093a..e8dc1a5afe66 100644
6124 +--- a/sound/core/pcm.c
6125 ++++ b/sound/core/pcm.c
6126 +@@ -28,6 +28,7 @@
6127 + #include <sound/core.h>
6128 + #include <sound/minors.h>
6129 + #include <sound/pcm.h>
6130 ++#include <sound/timer.h>
6131 + #include <sound/control.h>
6132 + #include <sound/info.h>
6133 +
6134 +@@ -1050,8 +1051,13 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
6135 + snd_free_pages((void*)runtime->control,
6136 + PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)));
6137 + kfree(runtime->hw_constraints.rules);
6138 +- kfree(runtime);
6139 ++ /* Avoid concurrent access to runtime via PCM timer interface */
6140 ++ if (substream->timer)
6141 ++ spin_lock_irq(&substream->timer->lock);
6142 + substream->runtime = NULL;
6143 ++ if (substream->timer)
6144 ++ spin_unlock_irq(&substream->timer->lock);
6145 ++ kfree(runtime);
6146 + put_pid(substream->pid);
6147 + substream->pid = NULL;
6148 + substream->pstr->substream_opened--;
6149 +diff --git a/sound/core/rawmidi_compat.c b/sound/core/rawmidi_compat.c
6150 +index f69764d7cdd7..e30e30ba6e39 100644
6151 +--- a/sound/core/rawmidi_compat.c
6152 ++++ b/sound/core/rawmidi_compat.c
6153 +@@ -36,8 +36,6 @@ static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile,
6154 + struct snd_rawmidi_params params;
6155 + unsigned int val;
6156 +
6157 +- if (rfile->output == NULL)
6158 +- return -EINVAL;
6159 + if (get_user(params.stream, &src->stream) ||
6160 + get_user(params.buffer_size, &src->buffer_size) ||
6161 + get_user(params.avail_min, &src->avail_min) ||
6162 +@@ -46,8 +44,12 @@ static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile,
6163 + params.no_active_sensing = val;
6164 + switch (params.stream) {
6165 + case SNDRV_RAWMIDI_STREAM_OUTPUT:
6166 ++ if (!rfile->output)
6167 ++ return -EINVAL;
6168 + return snd_rawmidi_output_params(rfile->output, &params);
6169 + case SNDRV_RAWMIDI_STREAM_INPUT:
6170 ++ if (!rfile->input)
6171 ++ return -EINVAL;
6172 + return snd_rawmidi_input_params(rfile->input, &params);
6173 + }
6174 + return -EINVAL;
6175 +@@ -67,16 +69,18 @@ static int snd_rawmidi_ioctl_status_compat(struct snd_rawmidi_file *rfile,
6176 + int err;
6177 + struct snd_rawmidi_status status;
6178 +
6179 +- if (rfile->output == NULL)
6180 +- return -EINVAL;
6181 + if (get_user(status.stream, &src->stream))
6182 + return -EFAULT;
6183 +
6184 + switch (status.stream) {
6185 + case SNDRV_RAWMIDI_STREAM_OUTPUT:
6186 ++ if (!rfile->output)
6187 ++ return -EINVAL;
6188 + err = snd_rawmidi_output_status(rfile->output, &status);
6189 + break;
6190 + case SNDRV_RAWMIDI_STREAM_INPUT:
6191 ++ if (!rfile->input)
6192 ++ return -EINVAL;
6193 + err = snd_rawmidi_input_status(rfile->input, &status);
6194 + break;
6195 + default:
6196 +@@ -112,16 +116,18 @@ static int snd_rawmidi_ioctl_status_x32(struct snd_rawmidi_file *rfile,
6197 + int err;
6198 + struct snd_rawmidi_status status;
6199 +
6200 +- if (rfile->output == NULL)
6201 +- return -EINVAL;
6202 + if (get_user(status.stream, &src->stream))
6203 + return -EFAULT;
6204 +
6205 + switch (status.stream) {
6206 + case SNDRV_RAWMIDI_STREAM_OUTPUT:
6207 ++ if (!rfile->output)
6208 ++ return -EINVAL;
6209 + err = snd_rawmidi_output_status(rfile->output, &status);
6210 + break;
6211 + case SNDRV_RAWMIDI_STREAM_INPUT:
6212 ++ if (!rfile->input)
6213 ++ return -EINVAL;
6214 + err = snd_rawmidi_input_status(rfile->input, &status);
6215 + break;
6216 + default:
6217 +diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
6218 +index c507c69029e3..738e1fe90312 100644
6219 +--- a/sound/pci/hda/hda_intel.c
6220 ++++ b/sound/pci/hda/hda_intel.c
6221 +@@ -1645,7 +1645,8 @@ static void azx_check_snoop_available(struct azx *chip)
6222 + */
6223 + u8 val;
6224 + pci_read_config_byte(chip->pci, 0x42, &val);
6225 +- if (!(val & 0x80) && chip->pci->revision == 0x30)
6226 ++ if (!(val & 0x80) && (chip->pci->revision == 0x30 ||
6227 ++ chip->pci->revision == 0x20))
6228 + snoop = false;
6229 + }
6230 +
6231 +diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
6232 +index e44a9758f2eb..b1b28c6928a7 100644
6233 +--- a/sound/pci/hda/patch_realtek.c
6234 ++++ b/sound/pci/hda/patch_realtek.c
6235 +@@ -6225,6 +6225,8 @@ static const struct hda_fixup alc269_fixups[] = {
6236 + { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
6237 + { }
6238 + },
6239 ++ .chained = true,
6240 ++ .chain_id = ALC269_FIXUP_HEADSET_MIC
6241 + },
6242 + };
6243 +
6244 +@@ -6428,6 +6430,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
6245 + SND_PCI_QUIRK(0x17aa, 0x30bb, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
6246 + SND_PCI_QUIRK(0x17aa, 0x30e2, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
6247 + SND_PCI_QUIRK(0x17aa, 0x310c, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
6248 ++ SND_PCI_QUIRK(0x17aa, 0x3138, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
6249 + SND_PCI_QUIRK(0x17aa, 0x313c, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
6250 + SND_PCI_QUIRK(0x17aa, 0x3112, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
6251 + SND_PCI_QUIRK(0x17aa, 0x3902, "Lenovo E50-80", ALC269_FIXUP_DMIC_THINKPAD_ACPI),
6252 +diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c
6253 +index 9b341c23f62b..5e80867d09ef 100644
6254 +--- a/sound/soc/codecs/ssm2602.c
6255 ++++ b/sound/soc/codecs/ssm2602.c
6256 +@@ -54,10 +54,17 @@ struct ssm2602_priv {
6257 + * using 2 wire for device control, so we cache them instead.
6258 + * There is no point in caching the reset register
6259 + */
6260 +-static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = {
6261 +- 0x0097, 0x0097, 0x0079, 0x0079,
6262 +- 0x000a, 0x0008, 0x009f, 0x000a,
6263 +- 0x0000, 0x0000
6264 ++static const struct reg_default ssm2602_reg[SSM2602_CACHEREGNUM] = {
6265 ++ { .reg = 0x00, .def = 0x0097 },
6266 ++ { .reg = 0x01, .def = 0x0097 },
6267 ++ { .reg = 0x02, .def = 0x0079 },
6268 ++ { .reg = 0x03, .def = 0x0079 },
6269 ++ { .reg = 0x04, .def = 0x000a },
6270 ++ { .reg = 0x05, .def = 0x0008 },
6271 ++ { .reg = 0x06, .def = 0x009f },
6272 ++ { .reg = 0x07, .def = 0x000a },
6273 ++ { .reg = 0x08, .def = 0x0000 },
6274 ++ { .reg = 0x09, .def = 0x0000 }
6275 + };
6276 +
6277 +
6278 +@@ -620,8 +627,8 @@ const struct regmap_config ssm2602_regmap_config = {
6279 + .volatile_reg = ssm2602_register_volatile,
6280 +
6281 + .cache_type = REGCACHE_RBTREE,
6282 +- .reg_defaults_raw = ssm2602_reg,
6283 +- .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg),
6284 ++ .reg_defaults = ssm2602_reg,
6285 ++ .num_reg_defaults = ARRAY_SIZE(ssm2602_reg),
6286 + };
6287 + EXPORT_SYMBOL_GPL(ssm2602_regmap_config);
6288 +
6289 +diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
6290 +index 01a50413c66f..782c580b7aa3 100644
6291 +--- a/sound/soc/soc-topology.c
6292 ++++ b/sound/soc/soc-topology.c
6293 +@@ -523,6 +523,7 @@ static void remove_widget(struct snd_soc_component *comp,
6294 + kfree(se->dobj.control.dtexts[j]);
6295 +
6296 + kfree(se);
6297 ++ kfree(w->kcontrol_news[i].name);
6298 + }
6299 + kfree(w->kcontrol_news);
6300 + } else {
6301 +@@ -540,6 +541,7 @@ static void remove_widget(struct snd_soc_component *comp,
6302 + */
6303 + kfree((void *)kcontrol->private_value);
6304 + snd_ctl_remove(card, kcontrol);
6305 ++ kfree(w->kcontrol_news[i].name);
6306 + }
6307 + kfree(w->kcontrol_news);
6308 + }
6309 +@@ -1233,7 +1235,9 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dmixer_create(
6310 + dev_dbg(tplg->dev, " adding DAPM widget mixer control %s at %d\n",
6311 + mc->hdr.name, i);
6312 +
6313 +- kc[i].name = mc->hdr.name;
6314 ++ kc[i].name = kstrdup(mc->hdr.name, GFP_KERNEL);
6315 ++ if (kc[i].name == NULL)
6316 ++ goto err_str;
6317 + kc[i].private_value = (long)sm;
6318 + kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
6319 + kc[i].access = mc->hdr.access;
6320 +@@ -1278,8 +1282,10 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dmixer_create(
6321 + err_str:
6322 + kfree(sm);
6323 + err:
6324 +- for (--i; i >= 0; i--)
6325 ++ for (--i; i >= 0; i--) {
6326 + kfree((void *)kc[i].private_value);
6327 ++ kfree(kc[i].name);
6328 ++ }
6329 + kfree(kc);
6330 + return NULL;
6331 + }
6332 +@@ -1310,7 +1316,9 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_denum_create(
6333 + dev_dbg(tplg->dev, " adding DAPM widget enum control %s\n",
6334 + ec->hdr.name);
6335 +
6336 +- kc[i].name = ec->hdr.name;
6337 ++ kc[i].name = kstrdup(ec->hdr.name, GFP_KERNEL);
6338 ++ if (kc[i].name == NULL)
6339 ++ goto err_se;
6340 + kc[i].private_value = (long)se;
6341 + kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
6342 + kc[i].access = ec->hdr.access;
6343 +@@ -1386,6 +1394,7 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_denum_create(
6344 + kfree(se->dobj.control.dtexts[j]);
6345 +
6346 + kfree(se);
6347 ++ kfree(kc[i].name);
6348 + }
6349 + err:
6350 + kfree(kc);
6351 +@@ -1424,7 +1433,9 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dbytes_create(
6352 + "ASoC: adding bytes kcontrol %s with access 0x%x\n",
6353 + be->hdr.name, be->hdr.access);
6354 +
6355 +- kc[i].name = be->hdr.name;
6356 ++ kc[i].name = kstrdup(be->hdr.name, GFP_KERNEL);
6357 ++ if (kc[i].name == NULL)
6358 ++ goto err;
6359 + kc[i].private_value = (long)sbe;
6360 + kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
6361 + kc[i].access = be->hdr.access;
6362 +@@ -1454,8 +1465,10 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dbytes_create(
6363 + return kc;
6364 +
6365 + err:
6366 +- for (--i; i >= 0; i--)
6367 ++ for (--i; i >= 0; i--) {
6368 + kfree((void *)kc[i].private_value);
6369 ++ kfree(kc[i].name);
6370 ++ }
6371 +
6372 + kfree(kc);
6373 + return NULL;
6374 +diff --git a/sound/usb/line6/midi.c b/sound/usb/line6/midi.c
6375 +index 1d3a23b02d68..b5d62b5f59ba 100644
6376 +--- a/sound/usb/line6/midi.c
6377 ++++ b/sound/usb/line6/midi.c
6378 +@@ -125,7 +125,7 @@ static int send_midi_async(struct usb_line6 *line6, unsigned char *data,
6379 + }
6380 +
6381 + usb_fill_int_urb(urb, line6->usbdev,
6382 +- usb_sndbulkpipe(line6->usbdev,
6383 ++ usb_sndintpipe(line6->usbdev,
6384 + line6->properties->ep_ctrl_w),
6385 + transfer_buffer, length, midi_sent, line6,
6386 + line6->interval);
6387 +diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
6388 +index 59ce2fb49821..5a11f4d3972c 100644
6389 +--- a/virt/kvm/arm/vgic/vgic-its.c
6390 ++++ b/virt/kvm/arm/vgic/vgic-its.c
6391 +@@ -309,21 +309,24 @@ static int vgic_copy_lpi_list(struct kvm_vcpu *vcpu, u32 **intid_ptr)
6392 + struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
6393 + struct vgic_irq *irq;
6394 + u32 *intids;
6395 +- int irq_count = dist->lpi_list_count, i = 0;
6396 ++ int irq_count, i = 0;
6397 +
6398 + /*
6399 +- * We use the current value of the list length, which may change
6400 +- * after the kmalloc. We don't care, because the guest shouldn't
6401 +- * change anything while the command handling is still running,
6402 +- * and in the worst case we would miss a new IRQ, which one wouldn't
6403 +- * expect to be covered by this command anyway.
6404 ++ * There is an obvious race between allocating the array and LPIs
6405 ++ * being mapped/unmapped. If we ended up here as a result of a
6406 ++ * command, we're safe (locks are held, preventing another
6407 ++ * command). If coming from another path (such as enabling LPIs),
6408 ++ * we must be careful not to overrun the array.
6409 + */
6410 ++ irq_count = READ_ONCE(dist->lpi_list_count);
6411 + intids = kmalloc_array(irq_count, sizeof(intids[0]), GFP_KERNEL);
6412 + if (!intids)
6413 + return -ENOMEM;
6414 +
6415 + spin_lock(&dist->lpi_list_lock);
6416 + list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) {
6417 ++ if (i == irq_count)
6418 ++ break;
6419 + /* We don't need to "get" the IRQ, as we hold the list lock. */
6420 + if (irq->target_vcpu != vcpu)
6421 + continue;