Magellan Linux

Contents of /trunk/kernel-magellan/patches-4.16/0103-4.16.4-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3107 - (show annotations) (download)
Wed May 16 14:24:20 2018 UTC (5 years, 11 months ago) by niro
File size: 265968 byte(s)
-linux-4.16.4
1 diff --git a/Makefile b/Makefile
2 index 38df392e45e4..d51175192ac1 100644
3 --- a/Makefile
4 +++ b/Makefile
5 @@ -1,7 +1,7 @@
6 # SPDX-License-Identifier: GPL-2.0
7 VERSION = 4
8 PATCHLEVEL = 16
9 -SUBLEVEL = 3
10 +SUBLEVEL = 4
11 EXTRAVERSION =
12 NAME = Fearless Coyote
13
14 diff --git a/arch/arm/boot/dts/at91sam9g25.dtsi b/arch/arm/boot/dts/at91sam9g25.dtsi
15 index a7da0dd0c98f..0898213f3bb2 100644
16 --- a/arch/arm/boot/dts/at91sam9g25.dtsi
17 +++ b/arch/arm/boot/dts/at91sam9g25.dtsi
18 @@ -21,7 +21,7 @@
19 atmel,mux-mask = <
20 /* A B C */
21 0xffffffff 0xffe0399f 0xc000001c /* pioA */
22 - 0x0007ffff 0x8000fe3f 0x00000000 /* pioB */
23 + 0x0007ffff 0x00047e3f 0x00000000 /* pioB */
24 0x80000000 0x07c0ffff 0xb83fffff /* pioC */
25 0x003fffff 0x003f8000 0x00000000 /* pioD */
26 >;
27 diff --git a/arch/arm/boot/dts/exynos5250.dtsi b/arch/arm/boot/dts/exynos5250.dtsi
28 index 56626d1a4235..cf89385e7888 100644
29 --- a/arch/arm/boot/dts/exynos5250.dtsi
30 +++ b/arch/arm/boot/dts/exynos5250.dtsi
31 @@ -655,7 +655,7 @@
32 power-domains = <&pd_gsc>;
33 clocks = <&clock CLK_GSCL0>;
34 clock-names = "gscl";
35 - iommu = <&sysmmu_gsc0>;
36 + iommus = <&sysmmu_gsc0>;
37 };
38
39 gsc_1: gsc@13e10000 {
40 @@ -665,7 +665,7 @@
41 power-domains = <&pd_gsc>;
42 clocks = <&clock CLK_GSCL1>;
43 clock-names = "gscl";
44 - iommu = <&sysmmu_gsc1>;
45 + iommus = <&sysmmu_gsc1>;
46 };
47
48 gsc_2: gsc@13e20000 {
49 @@ -675,7 +675,7 @@
50 power-domains = <&pd_gsc>;
51 clocks = <&clock CLK_GSCL2>;
52 clock-names = "gscl";
53 - iommu = <&sysmmu_gsc2>;
54 + iommus = <&sysmmu_gsc2>;
55 };
56
57 gsc_3: gsc@13e30000 {
58 @@ -685,7 +685,7 @@
59 power-domains = <&pd_gsc>;
60 clocks = <&clock CLK_GSCL3>;
61 clock-names = "gscl";
62 - iommu = <&sysmmu_gsc3>;
63 + iommus = <&sysmmu_gsc3>;
64 };
65
66 hdmi: hdmi@14530000 {
67 diff --git a/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts b/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
68 index 7bf5aa2237c9..7de704575aee 100644
69 --- a/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
70 +++ b/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts
71 @@ -39,6 +39,24 @@
72 };
73 };
74
75 + reg_3p3v: regulator-3p3v {
76 + compatible = "regulator-fixed";
77 + regulator-name = "fixed-3.3V";
78 + regulator-min-microvolt = <3300000>;
79 + regulator-max-microvolt = <3300000>;
80 + regulator-boot-on;
81 + regulator-always-on;
82 + };
83 +
84 + reg_5v: regulator-5v {
85 + compatible = "regulator-fixed";
86 + regulator-name = "fixed-5V";
87 + regulator-min-microvolt = <5000000>;
88 + regulator-max-microvolt = <5000000>;
89 + regulator-boot-on;
90 + regulator-always-on;
91 + };
92 +
93 gpio_keys {
94 compatible = "gpio-keys";
95 pinctrl-names = "default";
96 @@ -468,12 +486,14 @@
97 };
98
99 &usb1 {
100 - vusb33-supply = <&mt6323_vusb_reg>;
101 + vusb33-supply = <&reg_3p3v>;
102 + vbus-supply = <&reg_5v>;
103 status = "okay";
104 };
105
106 &usb2 {
107 - vusb33-supply = <&mt6323_vusb_reg>;
108 + vusb33-supply = <&reg_3p3v>;
109 + vbus-supply = <&reg_5v>;
110 status = "okay";
111 };
112
113 diff --git a/arch/arm/boot/dts/sama5d4.dtsi b/arch/arm/boot/dts/sama5d4.dtsi
114 index 373b3621b536..c7105096c623 100644
115 --- a/arch/arm/boot/dts/sama5d4.dtsi
116 +++ b/arch/arm/boot/dts/sama5d4.dtsi
117 @@ -1379,7 +1379,7 @@
118 pinctrl@fc06a000 {
119 #address-cells = <1>;
120 #size-cells = <1>;
121 - compatible = "atmel,at91sam9x5-pinctrl", "atmel,at91rm9200-pinctrl", "simple-bus";
122 + compatible = "atmel,sama5d3-pinctrl", "atmel,at91sam9x5-pinctrl", "simple-bus";
123 ranges = <0xfc068000 0xfc068000 0x100
124 0xfc06a000 0xfc06a000 0x4000>;
125 /* WARNING: revisit as pin spec has changed */
126 diff --git a/arch/arm/mach-exynos/pm.c b/arch/arm/mach-exynos/pm.c
127 index dc4346ecf16d..a1055a2b8d54 100644
128 --- a/arch/arm/mach-exynos/pm.c
129 +++ b/arch/arm/mach-exynos/pm.c
130 @@ -271,11 +271,7 @@ static int exynos_cpu0_enter_aftr(void)
131 goto fail;
132
133 call_firmware_op(cpu_boot, 1);
134 -
135 - if (soc_is_exynos3250())
136 - dsb_sev();
137 - else
138 - arch_send_wakeup_ipi_mask(cpumask_of(1));
139 + dsb_sev();
140 }
141 }
142 fail:
143 diff --git a/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts b/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
144 index ee4ada61c59c..93a7830706f5 100644
145 --- a/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
146 +++ b/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
147 @@ -310,7 +310,7 @@
148 pinctrl-names = "default", "clk-gate";
149
150 bus-width = <8>;
151 - max-frequency = <200000000>;
152 + max-frequency = <100000000>;
153 non-removable;
154 disable-wp;
155 cap-mmc-highspeed;
156 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
157 index b71306947290..06629011a434 100644
158 --- a/arch/mips/include/asm/uaccess.h
159 +++ b/arch/mips/include/asm/uaccess.h
160 @@ -654,6 +654,13 @@ __clear_user(void __user *addr, __kernel_size_t size)
161 {
162 __kernel_size_t res;
163
164 +#ifdef CONFIG_CPU_MICROMIPS
165 +/* micromips memset / bzero also clobbers t7 & t8 */
166 +#define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$15", "$24", "$31"
167 +#else
168 +#define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$31"
169 +#endif /* CONFIG_CPU_MICROMIPS */
170 +
171 if (eva_kernel_access()) {
172 __asm__ __volatile__(
173 "move\t$4, %1\n\t"
174 @@ -663,7 +670,7 @@ __clear_user(void __user *addr, __kernel_size_t size)
175 "move\t%0, $6"
176 : "=r" (res)
177 : "r" (addr), "r" (size)
178 - : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31");
179 + : bzero_clobbers);
180 } else {
181 might_fault();
182 __asm__ __volatile__(
183 @@ -674,7 +681,7 @@ __clear_user(void __user *addr, __kernel_size_t size)
184 "move\t%0, $6"
185 : "=r" (res)
186 : "r" (addr), "r" (size)
187 - : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31");
188 + : bzero_clobbers);
189 }
190
191 return res;
192 diff --git a/arch/mips/lib/memset.S b/arch/mips/lib/memset.S
193 index a1456664d6c2..f7327979a8f8 100644
194 --- a/arch/mips/lib/memset.S
195 +++ b/arch/mips/lib/memset.S
196 @@ -219,7 +219,7 @@
197 1: PTR_ADDIU a0, 1 /* fill bytewise */
198 R10KCBARRIER(0(ra))
199 bne t1, a0, 1b
200 - sb a1, -1(a0)
201 + EX(sb, a1, -1(a0), .Lsmall_fixup\@)
202
203 2: jr ra /* done */
204 move a2, zero
205 @@ -252,13 +252,18 @@
206 PTR_L t0, TI_TASK($28)
207 andi a2, STORMASK
208 LONG_L t0, THREAD_BUADDR(t0)
209 - LONG_ADDU a2, t1
210 + LONG_ADDU a2, a0
211 jr ra
212 LONG_SUBU a2, t0
213
214 .Llast_fixup\@:
215 jr ra
216 - andi v1, a2, STORMASK
217 + nop
218 +
219 +.Lsmall_fixup\@:
220 + PTR_SUBU a2, t1, a0
221 + jr ra
222 + PTR_ADDIU a2, 1
223
224 .endm
225
226 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
227 index 10daa1d56e0a..c7c63959ba91 100644
228 --- a/arch/powerpc/include/asm/barrier.h
229 +++ b/arch/powerpc/include/asm/barrier.h
230 @@ -35,7 +35,8 @@
231 #define rmb() __asm__ __volatile__ ("sync" : : : "memory")
232 #define wmb() __asm__ __volatile__ ("sync" : : : "memory")
233
234 -#ifdef __SUBARCH_HAS_LWSYNC
235 +/* The sub-arch has lwsync */
236 +#if defined(__powerpc64__) || defined(CONFIG_PPC_E500MC)
237 # define SMPWMB LWSYNC
238 #else
239 # define SMPWMB eieio
240 diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
241 index 12e70fb58700..fcf3ed5b8b18 100644
242 --- a/arch/powerpc/include/asm/opal.h
243 +++ b/arch/powerpc/include/asm/opal.h
244 @@ -21,6 +21,9 @@
245 /* We calculate number of sg entries based on PAGE_SIZE */
246 #define SG_ENTRIES_PER_NODE ((PAGE_SIZE - 16) / sizeof(struct opal_sg_entry))
247
248 +/* Default time to sleep or delay between OPAL_BUSY/OPAL_BUSY_EVENT loops */
249 +#define OPAL_BUSY_DELAY_MS 10
250 +
251 /* /sys/firmware/opal */
252 extern struct kobject *opal_kobj;
253
254 diff --git a/arch/powerpc/include/asm/synch.h b/arch/powerpc/include/asm/synch.h
255 index 63e7f5a1f105..6ec546090ba1 100644
256 --- a/arch/powerpc/include/asm/synch.h
257 +++ b/arch/powerpc/include/asm/synch.h
258 @@ -6,10 +6,6 @@
259 #include <linux/stringify.h>
260 #include <asm/feature-fixups.h>
261
262 -#if defined(__powerpc64__) || defined(CONFIG_PPC_E500MC)
263 -#define __SUBARCH_HAS_LWSYNC
264 -#endif
265 -
266 #ifndef __ASSEMBLY__
267 extern unsigned int __start___lwsync_fixup, __stop___lwsync_fixup;
268 extern void do_lwsync_fixups(unsigned long value, void *fixup_start,
269 diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c b/arch/powerpc/kernel/dt_cpu_ftrs.c
270 index 8ca5d5b74618..078553a177de 100644
271 --- a/arch/powerpc/kernel/dt_cpu_ftrs.c
272 +++ b/arch/powerpc/kernel/dt_cpu_ftrs.c
273 @@ -84,6 +84,7 @@ static int hv_mode;
274
275 static struct {
276 u64 lpcr;
277 + u64 lpcr_clear;
278 u64 hfscr;
279 u64 fscr;
280 } system_registers;
281 @@ -92,6 +93,8 @@ static void (*init_pmu_registers)(void);
282
283 static void __restore_cpu_cpufeatures(void)
284 {
285 + u64 lpcr;
286 +
287 /*
288 * LPCR is restored by the power on engine already. It can be changed
289 * after early init e.g., by radix enable, and we have no unified API
290 @@ -104,8 +107,10 @@ static void __restore_cpu_cpufeatures(void)
291 * The best we can do to accommodate secondary boot and idle restore
292 * for now is "or" LPCR with existing.
293 */
294 -
295 - mtspr(SPRN_LPCR, system_registers.lpcr | mfspr(SPRN_LPCR));
296 + lpcr = mfspr(SPRN_LPCR);
297 + lpcr |= system_registers.lpcr;
298 + lpcr &= ~system_registers.lpcr_clear;
299 + mtspr(SPRN_LPCR, lpcr);
300 if (hv_mode) {
301 mtspr(SPRN_LPID, 0);
302 mtspr(SPRN_HFSCR, system_registers.hfscr);
303 @@ -325,8 +330,9 @@ static int __init feat_enable_mmu_hash_v3(struct dt_cpu_feature *f)
304 {
305 u64 lpcr;
306
307 + system_registers.lpcr_clear |= (LPCR_ISL | LPCR_UPRT | LPCR_HR);
308 lpcr = mfspr(SPRN_LPCR);
309 - lpcr &= ~LPCR_ISL;
310 + lpcr &= ~(LPCR_ISL | LPCR_UPRT | LPCR_HR);
311 mtspr(SPRN_LPCR, lpcr);
312
313 cur_cpu_spec->mmu_features |= MMU_FTRS_HASH_BASE;
314 @@ -658,6 +664,13 @@ static void __init cpufeatures_setup_start(u32 isa)
315 cur_cpu_spec->cpu_features |= CPU_FTR_ARCH_300;
316 cur_cpu_spec->cpu_user_features2 |= PPC_FEATURE2_ARCH_3_00;
317 }
318 +
319 + /*
320 + * PKEY was not in the initial base or feature node
321 + * specification, but it should become optional in the next
322 + * cpu feature version sequence.
323 + */
324 + cur_cpu_spec->cpu_features |= CPU_FTR_PKEY;
325 }
326
327 static bool __init cpufeatures_process_feature(struct dt_cpu_feature *f)
328 diff --git a/arch/powerpc/kernel/eeh_driver.c b/arch/powerpc/kernel/eeh_driver.c
329 index 0c0b66fc5bfb..295ba833846e 100644
330 --- a/arch/powerpc/kernel/eeh_driver.c
331 +++ b/arch/powerpc/kernel/eeh_driver.c
332 @@ -207,18 +207,18 @@ static void *eeh_report_error(void *data, void *userdata)
333
334 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
335 return NULL;
336 +
337 + device_lock(&dev->dev);
338 dev->error_state = pci_channel_io_frozen;
339
340 driver = eeh_pcid_get(dev);
341 - if (!driver) return NULL;
342 + if (!driver) goto out_no_dev;
343
344 eeh_disable_irq(dev);
345
346 if (!driver->err_handler ||
347 - !driver->err_handler->error_detected) {
348 - eeh_pcid_put(dev);
349 - return NULL;
350 - }
351 + !driver->err_handler->error_detected)
352 + goto out;
353
354 rc = driver->err_handler->error_detected(dev, pci_channel_io_frozen);
355
356 @@ -227,8 +227,12 @@ static void *eeh_report_error(void *data, void *userdata)
357 if (*res == PCI_ERS_RESULT_NONE) *res = rc;
358
359 edev->in_error = true;
360 - eeh_pcid_put(dev);
361 pci_uevent_ers(dev, PCI_ERS_RESULT_NONE);
362 +
363 +out:
364 + eeh_pcid_put(dev);
365 +out_no_dev:
366 + device_unlock(&dev->dev);
367 return NULL;
368 }
369
370 @@ -251,15 +255,14 @@ static void *eeh_report_mmio_enabled(void *data, void *userdata)
371 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
372 return NULL;
373
374 + device_lock(&dev->dev);
375 driver = eeh_pcid_get(dev);
376 - if (!driver) return NULL;
377 + if (!driver) goto out_no_dev;
378
379 if (!driver->err_handler ||
380 !driver->err_handler->mmio_enabled ||
381 - (edev->mode & EEH_DEV_NO_HANDLER)) {
382 - eeh_pcid_put(dev);
383 - return NULL;
384 - }
385 + (edev->mode & EEH_DEV_NO_HANDLER))
386 + goto out;
387
388 rc = driver->err_handler->mmio_enabled(dev);
389
390 @@ -267,7 +270,10 @@ static void *eeh_report_mmio_enabled(void *data, void *userdata)
391 if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
392 if (*res == PCI_ERS_RESULT_NONE) *res = rc;
393
394 +out:
395 eeh_pcid_put(dev);
396 +out_no_dev:
397 + device_unlock(&dev->dev);
398 return NULL;
399 }
400
401 @@ -290,20 +296,20 @@ static void *eeh_report_reset(void *data, void *userdata)
402
403 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
404 return NULL;
405 +
406 + device_lock(&dev->dev);
407 dev->error_state = pci_channel_io_normal;
408
409 driver = eeh_pcid_get(dev);
410 - if (!driver) return NULL;
411 + if (!driver) goto out_no_dev;
412
413 eeh_enable_irq(dev);
414
415 if (!driver->err_handler ||
416 !driver->err_handler->slot_reset ||
417 (edev->mode & EEH_DEV_NO_HANDLER) ||
418 - (!edev->in_error)) {
419 - eeh_pcid_put(dev);
420 - return NULL;
421 - }
422 + (!edev->in_error))
423 + goto out;
424
425 rc = driver->err_handler->slot_reset(dev);
426 if ((*res == PCI_ERS_RESULT_NONE) ||
427 @@ -311,7 +317,10 @@ static void *eeh_report_reset(void *data, void *userdata)
428 if (*res == PCI_ERS_RESULT_DISCONNECT &&
429 rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
430
431 +out:
432 eeh_pcid_put(dev);
433 +out_no_dev:
434 + device_unlock(&dev->dev);
435 return NULL;
436 }
437
438 @@ -362,10 +371,12 @@ static void *eeh_report_resume(void *data, void *userdata)
439
440 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
441 return NULL;
442 +
443 + device_lock(&dev->dev);
444 dev->error_state = pci_channel_io_normal;
445
446 driver = eeh_pcid_get(dev);
447 - if (!driver) return NULL;
448 + if (!driver) goto out_no_dev;
449
450 was_in_error = edev->in_error;
451 edev->in_error = false;
452 @@ -375,18 +386,20 @@ static void *eeh_report_resume(void *data, void *userdata)
453 !driver->err_handler->resume ||
454 (edev->mode & EEH_DEV_NO_HANDLER) || !was_in_error) {
455 edev->mode &= ~EEH_DEV_NO_HANDLER;
456 - eeh_pcid_put(dev);
457 - return NULL;
458 + goto out;
459 }
460
461 driver->err_handler->resume(dev);
462
463 - eeh_pcid_put(dev);
464 pci_uevent_ers(dev, PCI_ERS_RESULT_RECOVERED);
465 +out:
466 + eeh_pcid_put(dev);
467 #ifdef CONFIG_PCI_IOV
468 if (eeh_ops->notify_resume && eeh_dev_to_pdn(edev))
469 eeh_ops->notify_resume(eeh_dev_to_pdn(edev));
470 #endif
471 +out_no_dev:
472 + device_unlock(&dev->dev);
473 return NULL;
474 }
475
476 @@ -406,23 +419,26 @@ static void *eeh_report_failure(void *data, void *userdata)
477
478 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
479 return NULL;
480 +
481 + device_lock(&dev->dev);
482 dev->error_state = pci_channel_io_perm_failure;
483
484 driver = eeh_pcid_get(dev);
485 - if (!driver) return NULL;
486 + if (!driver) goto out_no_dev;
487
488 eeh_disable_irq(dev);
489
490 if (!driver->err_handler ||
491 - !driver->err_handler->error_detected) {
492 - eeh_pcid_put(dev);
493 - return NULL;
494 - }
495 + !driver->err_handler->error_detected)
496 + goto out;
497
498 driver->err_handler->error_detected(dev, pci_channel_io_perm_failure);
499
500 - eeh_pcid_put(dev);
501 pci_uevent_ers(dev, PCI_ERS_RESULT_DISCONNECT);
502 +out:
503 + eeh_pcid_put(dev);
504 +out_no_dev:
505 + device_unlock(&dev->dev);
506 return NULL;
507 }
508
509 diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c
510 index 2d4956e97aa9..ee5a67d57aab 100644
511 --- a/arch/powerpc/kernel/eeh_pe.c
512 +++ b/arch/powerpc/kernel/eeh_pe.c
513 @@ -807,7 +807,8 @@ static void eeh_restore_bridge_bars(struct eeh_dev *edev)
514 eeh_ops->write_config(pdn, 15*4, 4, edev->config_space[15]);
515
516 /* PCI Command: 0x4 */
517 - eeh_ops->write_config(pdn, PCI_COMMAND, 4, edev->config_space[1]);
518 + eeh_ops->write_config(pdn, PCI_COMMAND, 4, edev->config_space[1] |
519 + PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
520
521 /* Check the PCIe link is ready */
522 eeh_bridge_check_link(edev);
523 diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
524 index ca5d5a081e75..e4c5bf33970b 100644
525 --- a/arch/powerpc/kernel/kprobes.c
526 +++ b/arch/powerpc/kernel/kprobes.c
527 @@ -455,29 +455,33 @@ static int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
528 }
529
530 kretprobe_assert(ri, orig_ret_address, trampoline_address);
531 - regs->nip = orig_ret_address;
532 +
533 /*
534 - * Make LR point to the orig_ret_address.
535 - * When the 'nop' inside the kretprobe_trampoline
536 - * is optimized, we can do a 'blr' after executing the
537 - * detour buffer code.
538 + * We get here through one of two paths:
539 + * 1. by taking a trap -> kprobe_handler() -> here
540 + * 2. by optprobe branch -> optimized_callback() -> opt_pre_handler() -> here
541 + *
542 + * When going back through (1), we need regs->nip to be setup properly
543 + * as it is used to determine the return address from the trap.
544 + * For (2), since nip is not honoured with optprobes, we instead setup
545 + * the link register properly so that the subsequent 'blr' in
546 + * kretprobe_trampoline jumps back to the right instruction.
547 + *
548 + * For nip, we should set the address to the previous instruction since
549 + * we end up emulating it in kprobe_handler(), which increments the nip
550 + * again.
551 */
552 + regs->nip = orig_ret_address - 4;
553 regs->link = orig_ret_address;
554
555 - reset_current_kprobe();
556 kretprobe_hash_unlock(current, &flags);
557 - preempt_enable_no_resched();
558
559 hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) {
560 hlist_del(&ri->hlist);
561 kfree(ri);
562 }
563 - /*
564 - * By returning a non-zero value, we are telling
565 - * kprobe_handler() that we don't want the post_handler
566 - * to run (and have re-enabled preemption)
567 - */
568 - return 1;
569 +
570 + return 0;
571 }
572 NOKPROBE_SYMBOL(trampoline_probe_handler);
573
574 diff --git a/arch/powerpc/kernel/machine_kexec_file_64.c b/arch/powerpc/kernel/machine_kexec_file_64.c
575 index e4395f937d63..45e0b7d5f200 100644
576 --- a/arch/powerpc/kernel/machine_kexec_file_64.c
577 +++ b/arch/powerpc/kernel/machine_kexec_file_64.c
578 @@ -43,7 +43,7 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
579
580 /* We don't support crash kernels yet. */
581 if (image->type == KEXEC_TYPE_CRASH)
582 - return -ENOTSUPP;
583 + return -EOPNOTSUPP;
584
585 for (i = 0; i < ARRAY_SIZE(kexec_file_loaders); i++) {
586 fops = kexec_file_loaders[i];
587 diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c
588 index 73697c4e3468..f61ff5a6bddb 100644
589 --- a/arch/powerpc/lib/feature-fixups.c
590 +++ b/arch/powerpc/lib/feature-fixups.c
591 @@ -55,7 +55,7 @@ static int patch_alt_instruction(unsigned int *src, unsigned int *dest,
592 unsigned int *target = (unsigned int *)branch_target(src);
593
594 /* Branch within the section doesn't need translating */
595 - if (target < alt_start || target >= alt_end) {
596 + if (target < alt_start || target > alt_end) {
597 instr = translate_branch(dest, src);
598 if (!instr)
599 return 1;
600 diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
601 index cf290d415dcd..1d388a0e1746 100644
602 --- a/arch/powerpc/mm/hash_utils_64.c
603 +++ b/arch/powerpc/mm/hash_utils_64.c
604 @@ -875,6 +875,12 @@ static void __init htab_initialize(void)
605 /* Using a hypervisor which owns the htab */
606 htab_address = NULL;
607 _SDR1 = 0;
608 + /*
609 + * On POWER9, we need to do a H_REGISTER_PROC_TBL hcall
610 + * to inform the hypervisor that we wish to use the HPT.
611 + */
612 + if (cpu_has_feature(CPU_FTR_ARCH_300))
613 + register_process_table(0, 0, 0);
614 #ifdef CONFIG_FA_DUMP
615 /*
616 * If firmware assisted dump is active firmware preserves
617 diff --git a/arch/powerpc/mm/tlb-radix.c b/arch/powerpc/mm/tlb-radix.c
618 index a07f5372a4bf..9ab051155af3 100644
619 --- a/arch/powerpc/mm/tlb-radix.c
620 +++ b/arch/powerpc/mm/tlb-radix.c
621 @@ -33,13 +33,12 @@ static inline void tlbiel_radix_set_isa300(unsigned int set, unsigned int is,
622 {
623 unsigned long rb;
624 unsigned long rs;
625 - unsigned int r = 1; /* radix format */
626
627 rb = (set << PPC_BITLSHIFT(51)) | (is << PPC_BITLSHIFT(53));
628 rs = ((unsigned long)pid << PPC_BITLSHIFT(31));
629
630 - asm volatile(PPC_TLBIEL(%0, %1, %2, %3, %4)
631 - : : "r"(rb), "r"(rs), "i"(ric), "i"(prs), "r"(r)
632 + asm volatile(PPC_TLBIEL(%0, %1, %2, %3, 1)
633 + : : "r"(rb), "r"(rs), "i"(ric), "i"(prs)
634 : "memory");
635 }
636
637 diff --git a/arch/powerpc/platforms/powernv/opal-nvram.c b/arch/powerpc/platforms/powernv/opal-nvram.c
638 index 9db4398ded5d..1bceb95f422d 100644
639 --- a/arch/powerpc/platforms/powernv/opal-nvram.c
640 +++ b/arch/powerpc/platforms/powernv/opal-nvram.c
641 @@ -11,6 +11,7 @@
642
643 #define DEBUG
644
645 +#include <linux/delay.h>
646 #include <linux/kernel.h>
647 #include <linux/init.h>
648 #include <linux/of.h>
649 @@ -56,9 +57,17 @@ static ssize_t opal_nvram_write(char *buf, size_t count, loff_t *index)
650
651 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
652 rc = opal_write_nvram(__pa(buf), count, off);
653 - if (rc == OPAL_BUSY_EVENT)
654 + if (rc == OPAL_BUSY_EVENT) {
655 + msleep(OPAL_BUSY_DELAY_MS);
656 opal_poll_events(NULL);
657 + } else if (rc == OPAL_BUSY) {
658 + msleep(OPAL_BUSY_DELAY_MS);
659 + }
660 }
661 +
662 + if (rc)
663 + return -EIO;
664 +
665 *index += count;
666 return count;
667 }
668 diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c
669 index 0ee4a469a4ae..d11f3c14c21e 100644
670 --- a/arch/powerpc/platforms/pseries/lpar.c
671 +++ b/arch/powerpc/platforms/pseries/lpar.c
672 @@ -726,15 +726,18 @@ static int pseries_lpar_resize_hpt(unsigned long shift)
673 return 0;
674 }
675
676 -/* Actually only used for radix, so far */
677 static int pseries_lpar_register_process_table(unsigned long base,
678 unsigned long page_size, unsigned long table_size)
679 {
680 long rc;
681 - unsigned long flags = PROC_TABLE_NEW;
682 + unsigned long flags = 0;
683
684 + if (table_size)
685 + flags |= PROC_TABLE_NEW;
686 if (radix_enabled())
687 flags |= PROC_TABLE_RADIX | PROC_TABLE_GTSE;
688 + else
689 + flags |= PROC_TABLE_HPT_SLB;
690 for (;;) {
691 rc = plpar_hcall_norets(H_REGISTER_PROC_TBL, flags, base,
692 page_size, table_size);
693 @@ -760,6 +763,7 @@ void __init hpte_init_pseries(void)
694 mmu_hash_ops.flush_hash_range = pSeries_lpar_flush_hash_range;
695 mmu_hash_ops.hpte_clear_all = pseries_hpte_clear_all;
696 mmu_hash_ops.hugepage_invalidate = pSeries_lpar_hugepage_invalidate;
697 + register_process_table = pseries_lpar_register_process_table;
698
699 if (firmware_has_feature(FW_FEATURE_HPT_RESIZE))
700 mmu_hash_ops.resize_hpt = pseries_lpar_resize_hpt;
701 diff --git a/arch/powerpc/sysdev/xive/native.c b/arch/powerpc/sysdev/xive/native.c
702 index d22aeb0b69e1..b48454be5b98 100644
703 --- a/arch/powerpc/sysdev/xive/native.c
704 +++ b/arch/powerpc/sysdev/xive/native.c
705 @@ -389,6 +389,10 @@ static void xive_native_setup_cpu(unsigned int cpu, struct xive_cpu *xc)
706 if (xive_pool_vps == XIVE_INVALID_VP)
707 return;
708
709 + /* Check if pool VP already active, if it is, pull it */
710 + if (in_be32(xive_tima + TM_QW2_HV_POOL + TM_WORD2) & TM_QW2W2_VP)
711 + in_be64(xive_tima + TM_SPC_PULL_POOL_CTX);
712 +
713 /* Enable the pool VP */
714 vp = xive_pool_vps + cpu;
715 pr_debug("CPU %d setting up pool VP 0x%x\n", cpu, vp);
716 diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
717 index eaee7087886f..6e91e0d422ea 100644
718 --- a/arch/s390/Kconfig
719 +++ b/arch/s390/Kconfig
720 @@ -289,12 +289,12 @@ config MARCH_Z13
721 older machines.
722
723 config MARCH_Z14
724 - bool "IBM z14"
725 + bool "IBM z14 ZR1 and z14"
726 select HAVE_MARCH_Z14_FEATURES
727 help
728 - Select this to enable optimizations for IBM z14 (3906 series).
729 - The kernel will be slightly faster but will not work on older
730 - machines.
731 + Select this to enable optimizations for IBM z14 ZR1 and z14 (3907
732 + and 3906 series). The kernel will be slightly faster but will not
733 + work on older machines.
734
735 endchoice
736
737 diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c
738 index 43bbe63e2992..06b513d192b9 100644
739 --- a/arch/s390/hypfs/inode.c
740 +++ b/arch/s390/hypfs/inode.c
741 @@ -320,7 +320,7 @@ static void hypfs_kill_super(struct super_block *sb)
742
743 if (sb->s_root)
744 hypfs_delete_tree(sb->s_root);
745 - if (sb_info->update_file)
746 + if (sb_info && sb_info->update_file)
747 hypfs_remove(sb_info->update_file);
748 kfree(sb->s_fs_info);
749 sb->s_fs_info = NULL;
750 diff --git a/arch/s390/kernel/perf_cpum_cf_events.c b/arch/s390/kernel/perf_cpum_cf_events.c
751 index c5bc3f209652..5ee27dc9a10c 100644
752 --- a/arch/s390/kernel/perf_cpum_cf_events.c
753 +++ b/arch/s390/kernel/perf_cpum_cf_events.c
754 @@ -583,6 +583,7 @@ __init const struct attribute_group **cpumf_cf_event_group(void)
755 model = cpumcf_z13_pmu_event_attr;
756 break;
757 case 0x3906:
758 + case 0x3907:
759 model = cpumcf_z14_pmu_event_attr;
760 break;
761 default:
762 diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
763 index a6a91f01a17a..ce5ff4c4d435 100644
764 --- a/arch/s390/kernel/setup.c
765 +++ b/arch/s390/kernel/setup.c
766 @@ -819,6 +819,7 @@ static int __init setup_hwcaps(void)
767 strcpy(elf_platform, "z13");
768 break;
769 case 0x3906:
770 + case 0x3907:
771 strcpy(elf_platform, "z14");
772 break;
773 }
774 diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
775 index 2db18cbbb0ea..c0197097c86e 100644
776 --- a/arch/um/os-Linux/file.c
777 +++ b/arch/um/os-Linux/file.c
778 @@ -12,6 +12,7 @@
779 #include <sys/mount.h>
780 #include <sys/socket.h>
781 #include <sys/stat.h>
782 +#include <sys/sysmacros.h>
783 #include <sys/un.h>
784 #include <sys/types.h>
785 #include <os.h>
786 diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c
787 index a86d7cc2c2d8..bf0acb8aad8b 100644
788 --- a/arch/um/os-Linux/signal.c
789 +++ b/arch/um/os-Linux/signal.c
790 @@ -16,6 +16,7 @@
791 #include <os.h>
792 #include <sysdep/mcontext.h>
793 #include <um_malloc.h>
794 +#include <sys/ucontext.h>
795
796 void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *) = {
797 [SIGTRAP] = relay_signal,
798 @@ -159,7 +160,7 @@ static void (*handlers[_NSIG])(int sig, struct siginfo *si, mcontext_t *mc) = {
799
800 static void hard_handler(int sig, siginfo_t *si, void *p)
801 {
802 - struct ucontext *uc = p;
803 + ucontext_t *uc = p;
804 mcontext_t *mc = &uc->uc_mcontext;
805 unsigned long pending = 1UL << sig;
806
807 diff --git a/arch/x86/um/stub_segv.c b/arch/x86/um/stub_segv.c
808 index 1518d2805ae8..27361cbb7ca9 100644
809 --- a/arch/x86/um/stub_segv.c
810 +++ b/arch/x86/um/stub_segv.c
811 @@ -6,11 +6,12 @@
812 #include <sysdep/stub.h>
813 #include <sysdep/faultinfo.h>
814 #include <sysdep/mcontext.h>
815 +#include <sys/ucontext.h>
816
817 void __attribute__ ((__section__ (".__syscall_stub")))
818 stub_segv_handler(int sig, siginfo_t *info, void *p)
819 {
820 - struct ucontext *uc = p;
821 + ucontext_t *uc = p;
822
823 GET_FAULTINFO_FROM_MC(*((struct faultinfo *) STUB_DATA),
824 &uc->uc_mcontext);
825 diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
826 index 3c2c2530737e..c36d23aa6c35 100644
827 --- a/arch/x86/xen/enlighten_pv.c
828 +++ b/arch/x86/xen/enlighten_pv.c
829 @@ -1259,10 +1259,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
830 */
831 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
832
833 - /* Work out if we support NX */
834 - get_cpu_cap(&boot_cpu_data);
835 - x86_configure_nx();
836 -
837 /* Get mfn list */
838 xen_build_dynamic_phys_to_machine();
839
840 @@ -1272,6 +1268,10 @@ asmlinkage __visible void __init xen_start_kernel(void)
841 */
842 xen_setup_gdt(0);
843
844 + /* Work out if we support NX */
845 + get_cpu_cap(&boot_cpu_data);
846 + x86_configure_nx();
847 +
848 xen_init_irq_ops();
849
850 /* Let's presume PV guests always boot on vCPU with id 0. */
851 diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
852 index 9f8f39d49396..984ec6b288df 100644
853 --- a/drivers/acpi/nfit/core.c
854 +++ b/drivers/acpi/nfit/core.c
855 @@ -196,7 +196,7 @@ static int xlat_nvdimm_status(struct nvdimm *nvdimm, void *buf, unsigned int cmd
856 * In the _LSI, _LSR, _LSW case the locked status is
857 * communicated via the read/write commands
858 */
859 - if (nfit_mem->has_lsi)
860 + if (nfit_mem->has_lsr)
861 break;
862
863 if (status >> 16 & ND_CONFIG_LOCKED)
864 @@ -483,7 +483,7 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
865 min_t(u32, 256, in_buf.buffer.length), true);
866
867 /* call the BIOS, prefer the named methods over _DSM if available */
868 - if (nvdimm && cmd == ND_CMD_GET_CONFIG_SIZE && nfit_mem->has_lsi)
869 + if (nvdimm && cmd == ND_CMD_GET_CONFIG_SIZE && nfit_mem->has_lsr)
870 out_obj = acpi_label_info(handle);
871 else if (nvdimm && cmd == ND_CMD_GET_CONFIG_DATA && nfit_mem->has_lsr) {
872 struct nd_cmd_get_config_data_hdr *p = buf;
873 @@ -1250,8 +1250,11 @@ static ssize_t scrub_show(struct device *dev,
874 if (nd_desc) {
875 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
876
877 + mutex_lock(&acpi_desc->init_mutex);
878 rc = sprintf(buf, "%d%s", acpi_desc->scrub_count,
879 - (work_busy(&acpi_desc->work)) ? "+\n" : "\n");
880 + work_busy(&acpi_desc->work)
881 + && !acpi_desc->cancel ? "+\n" : "\n");
882 + mutex_unlock(&acpi_desc->init_mutex);
883 }
884 device_unlock(dev);
885 return rc;
886 @@ -1654,12 +1657,23 @@ static void acpi_nvdimm_notify(acpi_handle handle, u32 event, void *data)
887 device_unlock(dev->parent);
888 }
889
890 +static bool acpi_nvdimm_has_method(struct acpi_device *adev, char *method)
891 +{
892 + acpi_handle handle;
893 + acpi_status status;
894 +
895 + status = acpi_get_handle(adev->handle, method, &handle);
896 +
897 + if (ACPI_SUCCESS(status))
898 + return true;
899 + return false;
900 +}
901 +
902 static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,
903 struct nfit_mem *nfit_mem, u32 device_handle)
904 {
905 struct acpi_device *adev, *adev_dimm;
906 struct device *dev = acpi_desc->dev;
907 - union acpi_object *obj;
908 unsigned long dsm_mask;
909 const guid_t *guid;
910 int i;
911 @@ -1732,25 +1746,15 @@ static int acpi_nfit_add_dimm(struct acpi_nfit_desc *acpi_desc,
912 1ULL << i))
913 set_bit(i, &nfit_mem->dsm_mask);
914
915 - obj = acpi_label_info(adev_dimm->handle);
916 - if (obj) {
917 - ACPI_FREE(obj);
918 - nfit_mem->has_lsi = 1;
919 - dev_dbg(dev, "%s: has _LSI\n", dev_name(&adev_dimm->dev));
920 - }
921 -
922 - obj = acpi_label_read(adev_dimm->handle, 0, 0);
923 - if (obj) {
924 - ACPI_FREE(obj);
925 - nfit_mem->has_lsr = 1;
926 + if (acpi_nvdimm_has_method(adev_dimm, "_LSI")
927 + && acpi_nvdimm_has_method(adev_dimm, "_LSR")) {
928 dev_dbg(dev, "%s: has _LSR\n", dev_name(&adev_dimm->dev));
929 + nfit_mem->has_lsr = true;
930 }
931
932 - obj = acpi_label_write(adev_dimm->handle, 0, 0, NULL);
933 - if (obj) {
934 - ACPI_FREE(obj);
935 - nfit_mem->has_lsw = 1;
936 + if (nfit_mem->has_lsr && acpi_nvdimm_has_method(adev_dimm, "_LSW")) {
937 dev_dbg(dev, "%s: has _LSW\n", dev_name(&adev_dimm->dev));
938 + nfit_mem->has_lsw = true;
939 }
940
941 return 0;
942 @@ -1839,10 +1843,10 @@ static int acpi_nfit_register_dimms(struct acpi_nfit_desc *acpi_desc)
943 cmd_mask |= nfit_mem->dsm_mask & NVDIMM_STANDARD_CMDMASK;
944 }
945
946 - if (nfit_mem->has_lsi)
947 + if (nfit_mem->has_lsr) {
948 set_bit(ND_CMD_GET_CONFIG_SIZE, &cmd_mask);
949 - if (nfit_mem->has_lsr)
950 set_bit(ND_CMD_GET_CONFIG_DATA, &cmd_mask);
951 + }
952 if (nfit_mem->has_lsw)
953 set_bit(ND_CMD_SET_CONFIG_DATA, &cmd_mask);
954
955 @@ -2579,7 +2583,7 @@ static int acpi_nfit_init_mapping(struct acpi_nfit_desc *acpi_desc,
956 struct acpi_nfit_system_address *spa = nfit_spa->spa;
957 struct nd_blk_region_desc *ndbr_desc;
958 struct nfit_mem *nfit_mem;
959 - int blk_valid = 0, rc;
960 + int rc;
961
962 if (!nvdimm) {
963 dev_err(acpi_desc->dev, "spa%d dimm: %#x not found\n",
964 @@ -2599,15 +2603,14 @@ static int acpi_nfit_init_mapping(struct acpi_nfit_desc *acpi_desc,
965 if (!nfit_mem || !nfit_mem->bdw) {
966 dev_dbg(acpi_desc->dev, "spa%d %s missing bdw\n",
967 spa->range_index, nvdimm_name(nvdimm));
968 - } else {
969 - mapping->size = nfit_mem->bdw->capacity;
970 - mapping->start = nfit_mem->bdw->start_address;
971 - ndr_desc->num_lanes = nfit_mem->bdw->windows;
972 - blk_valid = 1;
973 + break;
974 }
975
976 + mapping->size = nfit_mem->bdw->capacity;
977 + mapping->start = nfit_mem->bdw->start_address;
978 + ndr_desc->num_lanes = nfit_mem->bdw->windows;
979 ndr_desc->mapping = mapping;
980 - ndr_desc->num_mappings = blk_valid;
981 + ndr_desc->num_mappings = 1;
982 ndbr_desc = to_blk_region_desc(ndr_desc);
983 ndbr_desc->enable = acpi_nfit_blk_region_enable;
984 ndbr_desc->do_io = acpi_desc->blk_do_io;
985 diff --git a/drivers/acpi/nfit/nfit.h b/drivers/acpi/nfit/nfit.h
986 index 50d36e166d70..ac9c49463731 100644
987 --- a/drivers/acpi/nfit/nfit.h
988 +++ b/drivers/acpi/nfit/nfit.h
989 @@ -171,9 +171,8 @@ struct nfit_mem {
990 struct resource *flush_wpq;
991 unsigned long dsm_mask;
992 int family;
993 - u32 has_lsi:1;
994 - u32 has_lsr:1;
995 - u32 has_lsw:1;
996 + bool has_lsr;
997 + bool has_lsw;
998 };
999
1000 struct acpi_nfit_desc {
1001 diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
1002 index 601e5d372887..43587ac680e4 100644
1003 --- a/drivers/acpi/video_detect.c
1004 +++ b/drivers/acpi/video_detect.c
1005 @@ -219,6 +219,15 @@ static const struct dmi_system_id video_detect_dmi_table[] = {
1006 "3570R/370R/470R/450R/510R/4450RV"),
1007 },
1008 },
1009 + {
1010 + /* https://bugzilla.redhat.com/show_bug.cgi?id=1557060 */
1011 + .callback = video_detect_force_video,
1012 + .ident = "SAMSUNG 670Z5E",
1013 + .matches = {
1014 + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1015 + DMI_MATCH(DMI_PRODUCT_NAME, "670Z5E"),
1016 + },
1017 + },
1018 {
1019 /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */
1020 .callback = video_detect_force_video,
1021 diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
1022 index ee302ccdfbc8..453116fd4362 100644
1023 --- a/drivers/base/regmap/regmap.c
1024 +++ b/drivers/base/regmap/regmap.c
1025 @@ -1831,7 +1831,7 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
1026 return -EINVAL;
1027 if (val_len % map->format.val_bytes)
1028 return -EINVAL;
1029 - if (map->max_raw_write && map->max_raw_write > val_len)
1030 + if (map->max_raw_write && map->max_raw_write < val_len)
1031 return -E2BIG;
1032
1033 map->lock(map->lock_arg);
1034 diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
1035 index 1a81f6b8c2ce..942ac63f0b12 100644
1036 --- a/drivers/bluetooth/hci_bcm.c
1037 +++ b/drivers/bluetooth/hci_bcm.c
1038 @@ -126,6 +126,10 @@ struct bcm_data {
1039 static DEFINE_MUTEX(bcm_device_lock);
1040 static LIST_HEAD(bcm_device_list);
1041
1042 +static int irq_polarity = -1;
1043 +module_param(irq_polarity, int, 0444);
1044 +MODULE_PARM_DESC(irq_polarity, "IRQ polarity 0: active-high 1: active-low");
1045 +
1046 static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
1047 {
1048 if (hu->serdev)
1049 @@ -975,11 +979,17 @@ static int bcm_acpi_probe(struct bcm_device *dev)
1050 }
1051 acpi_dev_free_resource_list(&resources);
1052
1053 - dmi_id = dmi_first_match(bcm_active_low_irq_dmi_table);
1054 - if (dmi_id) {
1055 - dev_warn(dev->dev, "%s: Overwriting IRQ polarity to active low",
1056 - dmi_id->ident);
1057 - dev->irq_active_low = true;
1058 + if (irq_polarity != -1) {
1059 + dev->irq_active_low = irq_polarity;
1060 + dev_warn(dev->dev, "Overwriting IRQ polarity to active %s by module-param\n",
1061 + dev->irq_active_low ? "low" : "high");
1062 + } else {
1063 + dmi_id = dmi_first_match(bcm_active_low_irq_dmi_table);
1064 + if (dmi_id) {
1065 + dev_warn(dev->dev, "%s: Overwriting IRQ polarity to active low",
1066 + dmi_id->ident);
1067 + dev->irq_active_low = true;
1068 + }
1069 }
1070
1071 return 0;
1072 diff --git a/drivers/char/random.c b/drivers/char/random.c
1073 index e5b3d3ba4660..38729baed6ee 100644
1074 --- a/drivers/char/random.c
1075 +++ b/drivers/char/random.c
1076 @@ -427,8 +427,9 @@ struct crng_state primary_crng = {
1077 * its value (from 0->1->2).
1078 */
1079 static int crng_init = 0;
1080 -#define crng_ready() (likely(crng_init > 0))
1081 +#define crng_ready() (likely(crng_init > 1))
1082 static int crng_init_cnt = 0;
1083 +static unsigned long crng_global_init_time = 0;
1084 #define CRNG_INIT_CNT_THRESH (2*CHACHA20_KEY_SIZE)
1085 static void _extract_crng(struct crng_state *crng,
1086 __u32 out[CHACHA20_BLOCK_WORDS]);
1087 @@ -732,7 +733,7 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
1088
1089 static int credit_entropy_bits_safe(struct entropy_store *r, int nbits)
1090 {
1091 - const int nbits_max = (int)(~0U >> (ENTROPY_SHIFT + 1));
1092 + const int nbits_max = r->poolinfo->poolwords * 32;
1093
1094 if (nbits < 0)
1095 return -EINVAL;
1096 @@ -786,6 +787,10 @@ static void crng_initialize(struct crng_state *crng)
1097 crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
1098 }
1099
1100 +/*
1101 + * crng_fast_load() can be called by code in the interrupt service
1102 + * path. So we can't afford to dilly-dally.
1103 + */
1104 static int crng_fast_load(const char *cp, size_t len)
1105 {
1106 unsigned long flags;
1107 @@ -793,7 +798,7 @@ static int crng_fast_load(const char *cp, size_t len)
1108
1109 if (!spin_trylock_irqsave(&primary_crng.lock, flags))
1110 return 0;
1111 - if (crng_ready()) {
1112 + if (crng_init != 0) {
1113 spin_unlock_irqrestore(&primary_crng.lock, flags);
1114 return 0;
1115 }
1116 @@ -812,6 +817,51 @@ static int crng_fast_load(const char *cp, size_t len)
1117 return 1;
1118 }
1119
1120 +/*
1121 + * crng_slow_load() is called by add_device_randomness, which has two
1122 + * attributes. (1) We can't trust the buffer passed to it is
1123 + * guaranteed to be unpredictable (so it might not have any entropy at
1124 + * all), and (2) it doesn't have the performance constraints of
1125 + * crng_fast_load().
1126 + *
1127 + * So we do something more comprehensive which is guaranteed to touch
1128 + * all of the primary_crng's state, and which uses a LFSR with a
1129 + * period of 255 as part of the mixing algorithm. Finally, we do
1130 + * *not* advance crng_init_cnt since buffer we may get may be something
1131 + * like a fixed DMI table (for example), which might very well be
1132 + * unique to the machine, but is otherwise unvarying.
1133 + */
1134 +static int crng_slow_load(const char *cp, size_t len)
1135 +{
1136 + unsigned long flags;
1137 + static unsigned char lfsr = 1;
1138 + unsigned char tmp;
1139 + unsigned i, max = CHACHA20_KEY_SIZE;
1140 + const char * src_buf = cp;
1141 + char * dest_buf = (char *) &primary_crng.state[4];
1142 +
1143 + if (!spin_trylock_irqsave(&primary_crng.lock, flags))
1144 + return 0;
1145 + if (crng_init != 0) {
1146 + spin_unlock_irqrestore(&primary_crng.lock, flags);
1147 + return 0;
1148 + }
1149 + if (len > max)
1150 + max = len;
1151 +
1152 + for (i = 0; i < max ; i++) {
1153 + tmp = lfsr;
1154 + lfsr >>= 1;
1155 + if (tmp & 1)
1156 + lfsr ^= 0xE1;
1157 + tmp = dest_buf[i % CHACHA20_KEY_SIZE];
1158 + dest_buf[i % CHACHA20_KEY_SIZE] ^= src_buf[i % len] ^ lfsr;
1159 + lfsr += (tmp << 3) | (tmp >> 5);
1160 + }
1161 + spin_unlock_irqrestore(&primary_crng.lock, flags);
1162 + return 1;
1163 +}
1164 +
1165 static void crng_reseed(struct crng_state *crng, struct entropy_store *r)
1166 {
1167 unsigned long flags;
1168 @@ -830,7 +880,7 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r)
1169 _crng_backtrack_protect(&primary_crng, buf.block,
1170 CHACHA20_KEY_SIZE);
1171 }
1172 - spin_lock_irqsave(&primary_crng.lock, flags);
1173 + spin_lock_irqsave(&crng->lock, flags);
1174 for (i = 0; i < 8; i++) {
1175 unsigned long rv;
1176 if (!arch_get_random_seed_long(&rv) &&
1177 @@ -840,7 +890,7 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r)
1178 }
1179 memzero_explicit(&buf, sizeof(buf));
1180 crng->init_time = jiffies;
1181 - spin_unlock_irqrestore(&primary_crng.lock, flags);
1182 + spin_unlock_irqrestore(&crng->lock, flags);
1183 if (crng == &primary_crng && crng_init < 2) {
1184 invalidate_batched_entropy();
1185 crng_init = 2;
1186 @@ -855,8 +905,9 @@ static void _extract_crng(struct crng_state *crng,
1187 {
1188 unsigned long v, flags;
1189
1190 - if (crng_init > 1 &&
1191 - time_after(jiffies, crng->init_time + CRNG_RESEED_INTERVAL))
1192 + if (crng_ready() &&
1193 + (time_after(crng_global_init_time, crng->init_time) ||
1194 + time_after(jiffies, crng->init_time + CRNG_RESEED_INTERVAL)))
1195 crng_reseed(crng, crng == &primary_crng ? &input_pool : NULL);
1196 spin_lock_irqsave(&crng->lock, flags);
1197 if (arch_get_random_long(&v))
1198 @@ -981,10 +1032,8 @@ void add_device_randomness(const void *buf, unsigned int size)
1199 unsigned long time = random_get_entropy() ^ jiffies;
1200 unsigned long flags;
1201
1202 - if (!crng_ready()) {
1203 - crng_fast_load(buf, size);
1204 - return;
1205 - }
1206 + if (!crng_ready() && size)
1207 + crng_slow_load(buf, size);
1208
1209 trace_add_device_randomness(size, _RET_IP_);
1210 spin_lock_irqsave(&input_pool.lock, flags);
1211 @@ -1141,7 +1190,7 @@ void add_interrupt_randomness(int irq, int irq_flags)
1212 fast_mix(fast_pool);
1213 add_interrupt_bench(cycles);
1214
1215 - if (!crng_ready()) {
1216 + if (unlikely(crng_init == 0)) {
1217 if ((fast_pool->count >= 64) &&
1218 crng_fast_load((char *) fast_pool->pool,
1219 sizeof(fast_pool->pool))) {
1220 @@ -1691,6 +1740,7 @@ static int rand_initialize(void)
1221 init_std_data(&input_pool);
1222 init_std_data(&blocking_pool);
1223 crng_initialize(&primary_crng);
1224 + crng_global_init_time = jiffies;
1225
1226 #ifdef CONFIG_NUMA
1227 pool = kcalloc(nr_node_ids, sizeof(*pool), GFP_KERNEL|__GFP_NOFAIL);
1228 @@ -1877,6 +1927,14 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
1229 input_pool.entropy_count = 0;
1230 blocking_pool.entropy_count = 0;
1231 return 0;
1232 + case RNDRESEEDCRNG:
1233 + if (!capable(CAP_SYS_ADMIN))
1234 + return -EPERM;
1235 + if (crng_init < 2)
1236 + return -ENODATA;
1237 + crng_reseed(&primary_crng, NULL);
1238 + crng_global_init_time = jiffies - 1;
1239 + return 0;
1240 default:
1241 return -EINVAL;
1242 }
1243 @@ -2214,7 +2272,7 @@ void add_hwgenerator_randomness(const char *buffer, size_t count,
1244 {
1245 struct entropy_store *poolp = &input_pool;
1246
1247 - if (!crng_ready()) {
1248 + if (unlikely(crng_init == 0)) {
1249 crng_fast_load(buffer, count);
1250 return;
1251 }
1252 diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
1253 index 9e80a953d693..248c04090dea 100644
1254 --- a/drivers/char/tpm/tpm-interface.c
1255 +++ b/drivers/char/tpm/tpm-interface.c
1256 @@ -969,6 +969,10 @@ int tpm_do_selftest(struct tpm_chip *chip)
1257 loops = jiffies_to_msecs(duration) / delay_msec;
1258
1259 rc = tpm_continue_selftest(chip);
1260 + if (rc == TPM_ERR_INVALID_POSTINIT) {
1261 + chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED;
1262 + dev_info(&chip->dev, "TPM not ready (%d)\n", rc);
1263 + }
1264 /* This may fail if there was no TPM driver during a suspend/resume
1265 * cycle; some may return 10 (BAD_ORDINAL), others 28 (FAILEDSELFTEST)
1266 */
1267 diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
1268 index a07f6451694a..fa0d5c8611a0 100644
1269 --- a/drivers/clk/bcm/clk-bcm2835.c
1270 +++ b/drivers/clk/bcm/clk-bcm2835.c
1271 @@ -602,9 +602,7 @@ static void bcm2835_pll_off(struct clk_hw *hw)
1272 const struct bcm2835_pll_data *data = pll->data;
1273
1274 spin_lock(&cprman->regs_lock);
1275 - cprman_write(cprman, data->cm_ctrl_reg,
1276 - cprman_read(cprman, data->cm_ctrl_reg) |
1277 - CM_PLL_ANARST);
1278 + cprman_write(cprman, data->cm_ctrl_reg, CM_PLL_ANARST);
1279 cprman_write(cprman, data->a2w_ctrl_reg,
1280 cprman_read(cprman, data->a2w_ctrl_reg) |
1281 A2W_PLL_CTRL_PWRDN);
1282 @@ -640,6 +638,10 @@ static int bcm2835_pll_on(struct clk_hw *hw)
1283 cpu_relax();
1284 }
1285
1286 + cprman_write(cprman, data->a2w_ctrl_reg,
1287 + cprman_read(cprman, data->a2w_ctrl_reg) |
1288 + A2W_PLL_CTRL_PRST_DISABLE);
1289 +
1290 return 0;
1291 }
1292
1293 diff --git a/drivers/clk/mediatek/clk-mt2701.c b/drivers/clk/mediatek/clk-mt2701.c
1294 index 8e7f16fd87c9..deca7527f92f 100644
1295 --- a/drivers/clk/mediatek/clk-mt2701.c
1296 +++ b/drivers/clk/mediatek/clk-mt2701.c
1297 @@ -148,6 +148,7 @@ static const struct mtk_fixed_factor top_fixed_divs[] = {
1298 FACTOR(CLK_TOP_CLK26M_D8, "clk26m_d8", "clk26m", 1, 8),
1299 FACTOR(CLK_TOP_32K_INTERNAL, "32k_internal", "clk26m", 1, 793),
1300 FACTOR(CLK_TOP_32K_EXTERNAL, "32k_external", "rtc32k", 1, 1),
1301 + FACTOR(CLK_TOP_AXISEL_D4, "axisel_d4", "axi_sel", 1, 4),
1302 };
1303
1304 static const char * const axi_parents[] = {
1305 @@ -857,13 +858,13 @@ static const struct mtk_gate peri_clks[] = {
1306 GATE_PERI0(CLK_PERI_USB1, "usb1_ck", "usb20_sel", 11),
1307 GATE_PERI0(CLK_PERI_USB0, "usb0_ck", "usb20_sel", 10),
1308 GATE_PERI0(CLK_PERI_PWM, "pwm_ck", "axi_sel", 9),
1309 - GATE_PERI0(CLK_PERI_PWM7, "pwm7_ck", "axi_sel", 8),
1310 - GATE_PERI0(CLK_PERI_PWM6, "pwm6_ck", "axi_sel", 7),
1311 - GATE_PERI0(CLK_PERI_PWM5, "pwm5_ck", "axi_sel", 6),
1312 - GATE_PERI0(CLK_PERI_PWM4, "pwm4_ck", "axi_sel", 5),
1313 - GATE_PERI0(CLK_PERI_PWM3, "pwm3_ck", "axi_sel", 4),
1314 - GATE_PERI0(CLK_PERI_PWM2, "pwm2_ck", "axi_sel", 3),
1315 - GATE_PERI0(CLK_PERI_PWM1, "pwm1_ck", "axi_sel", 2),
1316 + GATE_PERI0(CLK_PERI_PWM7, "pwm7_ck", "axisel_d4", 8),
1317 + GATE_PERI0(CLK_PERI_PWM6, "pwm6_ck", "axisel_d4", 7),
1318 + GATE_PERI0(CLK_PERI_PWM5, "pwm5_ck", "axisel_d4", 6),
1319 + GATE_PERI0(CLK_PERI_PWM4, "pwm4_ck", "axisel_d4", 5),
1320 + GATE_PERI0(CLK_PERI_PWM3, "pwm3_ck", "axisel_d4", 4),
1321 + GATE_PERI0(CLK_PERI_PWM2, "pwm2_ck", "axisel_d4", 3),
1322 + GATE_PERI0(CLK_PERI_PWM1, "pwm1_ck", "axisel_d4", 2),
1323 GATE_PERI0(CLK_PERI_THERM, "therm_ck", "axi_sel", 1),
1324 GATE_PERI0(CLK_PERI_NFI, "nfi_ck", "nfi2x_sel", 0),
1325
1326 diff --git a/drivers/clk/mvebu/armada-38x.c b/drivers/clk/mvebu/armada-38x.c
1327 index 394aa6f03f01..9ff4ea63932d 100644
1328 --- a/drivers/clk/mvebu/armada-38x.c
1329 +++ b/drivers/clk/mvebu/armada-38x.c
1330 @@ -46,11 +46,11 @@ static u32 __init armada_38x_get_tclk_freq(void __iomem *sar)
1331 }
1332
1333 static const u32 armada_38x_cpu_frequencies[] __initconst = {
1334 - 0, 0, 0, 0,
1335 - 1066 * 1000 * 1000, 0, 0, 0,
1336 + 666 * 1000 * 1000, 0, 800 * 1000 * 1000, 0,
1337 + 1066 * 1000 * 1000, 0, 1200 * 1000 * 1000, 0,
1338 1332 * 1000 * 1000, 0, 0, 0,
1339 1600 * 1000 * 1000, 0, 0, 0,
1340 - 1866 * 1000 * 1000,
1341 + 1866 * 1000 * 1000, 0, 0, 2000 * 1000 * 1000,
1342 };
1343
1344 static u32 __init armada_38x_get_cpu_freq(void __iomem *sar)
1345 @@ -76,11 +76,11 @@ static const struct coreclk_ratio armada_38x_coreclk_ratios[] __initconst = {
1346 };
1347
1348 static const int armada_38x_cpu_l2_ratios[32][2] __initconst = {
1349 - {0, 1}, {0, 1}, {0, 1}, {0, 1},
1350 - {1, 2}, {0, 1}, {0, 1}, {0, 1},
1351 - {1, 2}, {0, 1}, {0, 1}, {0, 1},
1352 + {1, 2}, {0, 1}, {1, 2}, {0, 1},
1353 + {1, 2}, {0, 1}, {1, 2}, {0, 1},
1354 {1, 2}, {0, 1}, {0, 1}, {0, 1},
1355 {1, 2}, {0, 1}, {0, 1}, {0, 1},
1356 + {1, 2}, {0, 1}, {0, 1}, {1, 2},
1357 {0, 1}, {0, 1}, {0, 1}, {0, 1},
1358 {0, 1}, {0, 1}, {0, 1}, {0, 1},
1359 {0, 1}, {0, 1}, {0, 1}, {0, 1},
1360 @@ -91,7 +91,7 @@ static const int armada_38x_cpu_ddr_ratios[32][2] __initconst = {
1361 {1, 2}, {0, 1}, {0, 1}, {0, 1},
1362 {1, 2}, {0, 1}, {0, 1}, {0, 1},
1363 {1, 2}, {0, 1}, {0, 1}, {0, 1},
1364 - {1, 2}, {0, 1}, {0, 1}, {0, 1},
1365 + {1, 2}, {0, 1}, {0, 1}, {7, 15},
1366 {0, 1}, {0, 1}, {0, 1}, {0, 1},
1367 {0, 1}, {0, 1}, {0, 1}, {0, 1},
1368 {0, 1}, {0, 1}, {0, 1}, {0, 1},
1369 diff --git a/drivers/clk/renesas/clk-sh73a0.c b/drivers/clk/renesas/clk-sh73a0.c
1370 index eea38f6ea77e..3892346c4fcc 100644
1371 --- a/drivers/clk/renesas/clk-sh73a0.c
1372 +++ b/drivers/clk/renesas/clk-sh73a0.c
1373 @@ -46,7 +46,7 @@ struct div4_clk {
1374 unsigned int shift;
1375 };
1376
1377 -static struct div4_clk div4_clks[] = {
1378 +static const struct div4_clk div4_clks[] = {
1379 { "zg", "pll0", CPG_FRQCRA, 16 },
1380 { "m3", "pll1", CPG_FRQCRA, 12 },
1381 { "b", "pll1", CPG_FRQCRA, 8 },
1382 @@ -79,7 +79,7 @@ sh73a0_cpg_register_clock(struct device_node *np, struct sh73a0_cpg *cpg,
1383 {
1384 const struct clk_div_table *table = NULL;
1385 unsigned int shift, reg, width;
1386 - const char *parent_name;
1387 + const char *parent_name = NULL;
1388 unsigned int mult = 1;
1389 unsigned int div = 1;
1390
1391 @@ -135,7 +135,7 @@ sh73a0_cpg_register_clock(struct device_node *np, struct sh73a0_cpg *cpg,
1392 shift = 24;
1393 width = 5;
1394 } else {
1395 - struct div4_clk *c;
1396 + const struct div4_clk *c;
1397
1398 for (c = div4_clks; c->name; c++) {
1399 if (!strcmp(name, c->name)) {
1400 diff --git a/drivers/clk/tegra/clk-emc.c b/drivers/clk/tegra/clk-emc.c
1401 index 11a5066e5c27..5234acd30e89 100644
1402 --- a/drivers/clk/tegra/clk-emc.c
1403 +++ b/drivers/clk/tegra/clk-emc.c
1404 @@ -515,7 +515,7 @@ struct clk *tegra_clk_register_emc(void __iomem *base, struct device_node *np,
1405
1406 init.name = "emc";
1407 init.ops = &tegra_clk_emc_ops;
1408 - init.flags = 0;
1409 + init.flags = CLK_IS_CRITICAL;
1410 init.parent_names = emc_parent_clk_names;
1411 init.num_parents = ARRAY_SIZE(emc_parent_clk_names);
1412
1413 diff --git a/drivers/clk/tegra/clk-tegra-periph.c b/drivers/clk/tegra/clk-tegra-periph.c
1414 index c02711927d79..2acba2986bc6 100644
1415 --- a/drivers/clk/tegra/clk-tegra-periph.c
1416 +++ b/drivers/clk/tegra/clk-tegra-periph.c
1417 @@ -830,7 +830,7 @@ static struct tegra_periph_init_data gate_clks[] = {
1418 GATE("xusb_host", "xusb_host_src", 89, 0, tegra_clk_xusb_host, 0),
1419 GATE("xusb_ss", "xusb_ss_src", 156, 0, tegra_clk_xusb_ss, 0),
1420 GATE("xusb_dev", "xusb_dev_src", 95, 0, tegra_clk_xusb_dev, 0),
1421 - GATE("emc", "emc_mux", 57, 0, tegra_clk_emc, CLK_IGNORE_UNUSED),
1422 + GATE("emc", "emc_mux", 57, 0, tegra_clk_emc, CLK_IS_CRITICAL),
1423 GATE("sata_cold", "clk_m", 129, TEGRA_PERIPH_ON_APB, tegra_clk_sata_cold, 0),
1424 GATE("ispa", "isp", 23, 0, tegra_clk_ispa, 0),
1425 GATE("ispb", "isp", 3, 0, tegra_clk_ispb, 0),
1426 diff --git a/drivers/clk/tegra/clk-tegra-super-gen4.c b/drivers/clk/tegra/clk-tegra-super-gen4.c
1427 index 10047107c1dc..89d6b47a27a8 100644
1428 --- a/drivers/clk/tegra/clk-tegra-super-gen4.c
1429 +++ b/drivers/clk/tegra/clk-tegra-super-gen4.c
1430 @@ -125,7 +125,8 @@ static void __init tegra_sclk_init(void __iomem *clk_base,
1431 /* SCLK */
1432 dt_clk = tegra_lookup_dt_id(tegra_clk_sclk, tegra_clks);
1433 if (dt_clk) {
1434 - clk = clk_register_divider(NULL, "sclk", "sclk_mux", 0,
1435 + clk = clk_register_divider(NULL, "sclk", "sclk_mux",
1436 + CLK_IS_CRITICAL,
1437 clk_base + SCLK_DIVIDER, 0, 8,
1438 0, &sysrate_lock);
1439 *dt_clk = clk;
1440 @@ -137,7 +138,8 @@ static void __init tegra_sclk_init(void __iomem *clk_base,
1441 clk = tegra_clk_register_super_mux("sclk",
1442 gen_info->sclk_parents,
1443 gen_info->num_sclk_parents,
1444 - CLK_SET_RATE_PARENT,
1445 + CLK_SET_RATE_PARENT |
1446 + CLK_IS_CRITICAL,
1447 clk_base + SCLK_BURST_POLICY,
1448 0, 4, 0, 0, NULL);
1449 *dt_clk = clk;
1450 @@ -151,7 +153,7 @@ static void __init tegra_sclk_init(void __iomem *clk_base,
1451 clk_base + SYSTEM_CLK_RATE, 4, 2, 0,
1452 &sysrate_lock);
1453 clk = clk_register_gate(NULL, "hclk", "hclk_div",
1454 - CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED,
1455 + CLK_SET_RATE_PARENT | CLK_IS_CRITICAL,
1456 clk_base + SYSTEM_CLK_RATE,
1457 7, CLK_GATE_SET_TO_DISABLE, &sysrate_lock);
1458 *dt_clk = clk;
1459 diff --git a/drivers/clk/tegra/clk-tegra114.c b/drivers/clk/tegra/clk-tegra114.c
1460 index 63087d17c3e2..c3945c683f60 100644
1461 --- a/drivers/clk/tegra/clk-tegra114.c
1462 +++ b/drivers/clk/tegra/clk-tegra114.c
1463 @@ -955,8 +955,7 @@ static void __init tegra114_pll_init(void __iomem *clk_base,
1464
1465 /* PLLM */
1466 clk = tegra_clk_register_pllm("pll_m", "pll_ref", clk_base, pmc,
1467 - CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
1468 - &pll_m_params, NULL);
1469 + CLK_SET_RATE_GATE, &pll_m_params, NULL);
1470 clks[TEGRA114_CLK_PLL_M] = clk;
1471
1472 /* PLLM_OUT1 */
1473 diff --git a/drivers/clk/tegra/clk-tegra124.c b/drivers/clk/tegra/clk-tegra124.c
1474 index e81ea5b11577..230f9a2c1abf 100644
1475 --- a/drivers/clk/tegra/clk-tegra124.c
1476 +++ b/drivers/clk/tegra/clk-tegra124.c
1477 @@ -1089,8 +1089,7 @@ static void __init tegra124_pll_init(void __iomem *clk_base,
1478
1479 /* PLLM */
1480 clk = tegra_clk_register_pllm("pll_m", "pll_ref", clk_base, pmc,
1481 - CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
1482 - &pll_m_params, NULL);
1483 + CLK_SET_RATE_GATE, &pll_m_params, NULL);
1484 clk_register_clkdev(clk, "pll_m", NULL);
1485 clks[TEGRA124_CLK_PLL_M] = clk;
1486
1487 @@ -1099,7 +1098,7 @@ static void __init tegra124_pll_init(void __iomem *clk_base,
1488 clk_base + PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
1489 8, 8, 1, NULL);
1490 clk = tegra_clk_register_pll_out("pll_m_out1", "pll_m_out1_div",
1491 - clk_base + PLLM_OUT, 1, 0, CLK_IGNORE_UNUSED |
1492 + clk_base + PLLM_OUT, 1, 0,
1493 CLK_SET_RATE_PARENT, 0, NULL);
1494 clk_register_clkdev(clk, "pll_m_out1", NULL);
1495 clks[TEGRA124_CLK_PLL_M_OUT1] = clk;
1496 @@ -1272,7 +1271,7 @@ static struct tegra_clk_init_table common_init_table[] __initdata = {
1497 { TEGRA124_CLK_HOST1X, TEGRA124_CLK_PLL_P, 136000000, 1 },
1498 { TEGRA124_CLK_DSIALP, TEGRA124_CLK_PLL_P, 68000000, 0 },
1499 { TEGRA124_CLK_DSIBLP, TEGRA124_CLK_PLL_P, 68000000, 0 },
1500 - { TEGRA124_CLK_SCLK, TEGRA124_CLK_PLL_P_OUT2, 102000000, 1 },
1501 + { TEGRA124_CLK_SCLK, TEGRA124_CLK_PLL_P_OUT2, 102000000, 0 },
1502 { TEGRA124_CLK_DFLL_SOC, TEGRA124_CLK_PLL_P, 51000000, 1 },
1503 { TEGRA124_CLK_DFLL_REF, TEGRA124_CLK_PLL_P, 51000000, 1 },
1504 { TEGRA124_CLK_PLL_C, TEGRA124_CLK_CLK_MAX, 768000000, 0 },
1505 diff --git a/drivers/clk/tegra/clk-tegra20.c b/drivers/clk/tegra/clk-tegra20.c
1506 index cbd5a2e5c569..e3392ca2c2fc 100644
1507 --- a/drivers/clk/tegra/clk-tegra20.c
1508 +++ b/drivers/clk/tegra/clk-tegra20.c
1509 @@ -576,6 +576,7 @@ static struct tegra_clk tegra20_clks[tegra_clk_max] __initdata = {
1510 [tegra_clk_afi] = { .dt_id = TEGRA20_CLK_AFI, .present = true },
1511 [tegra_clk_fuse] = { .dt_id = TEGRA20_CLK_FUSE, .present = true },
1512 [tegra_clk_kfuse] = { .dt_id = TEGRA20_CLK_KFUSE, .present = true },
1513 + [tegra_clk_emc] = { .dt_id = TEGRA20_CLK_EMC, .present = true },
1514 };
1515
1516 static unsigned long tegra20_clk_measure_input_freq(void)
1517 @@ -651,8 +652,7 @@ static void tegra20_pll_init(void)
1518
1519 /* PLLM */
1520 clk = tegra_clk_register_pll("pll_m", "pll_ref", clk_base, NULL,
1521 - CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
1522 - &pll_m_params, NULL);
1523 + CLK_SET_RATE_GATE, &pll_m_params, NULL);
1524 clks[TEGRA20_CLK_PLL_M] = clk;
1525
1526 /* PLLM_OUT1 */
1527 @@ -660,7 +660,7 @@ static void tegra20_pll_init(void)
1528 clk_base + PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
1529 8, 8, 1, NULL);
1530 clk = tegra_clk_register_pll_out("pll_m_out1", "pll_m_out1_div",
1531 - clk_base + PLLM_OUT, 1, 0, CLK_IGNORE_UNUSED |
1532 + clk_base + PLLM_OUT, 1, 0,
1533 CLK_SET_RATE_PARENT, 0, NULL);
1534 clks[TEGRA20_CLK_PLL_M_OUT1] = clk;
1535
1536 @@ -723,7 +723,8 @@ static void tegra20_super_clk_init(void)
1537
1538 /* SCLK */
1539 clk = tegra_clk_register_super_mux("sclk", sclk_parents,
1540 - ARRAY_SIZE(sclk_parents), CLK_SET_RATE_PARENT,
1541 + ARRAY_SIZE(sclk_parents),
1542 + CLK_SET_RATE_PARENT | CLK_IS_CRITICAL,
1543 clk_base + SCLK_BURST_POLICY, 0, 4, 0, 0, NULL);
1544 clks[TEGRA20_CLK_SCLK] = clk;
1545
1546 @@ -814,9 +815,6 @@ static void __init tegra20_periph_clk_init(void)
1547 CLK_SET_RATE_NO_REPARENT,
1548 clk_base + CLK_SOURCE_EMC,
1549 30, 2, 0, &emc_lock);
1550 - clk = tegra_clk_register_periph_gate("emc", "emc_mux", 0, clk_base, 0,
1551 - 57, periph_clk_enb_refcnt);
1552 - clks[TEGRA20_CLK_EMC] = clk;
1553
1554 clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC,
1555 &emc_lock);
1556 @@ -1019,13 +1017,12 @@ static struct tegra_clk_init_table init_table[] __initdata = {
1557 { TEGRA20_CLK_PLL_P_OUT2, TEGRA20_CLK_CLK_MAX, 48000000, 1 },
1558 { TEGRA20_CLK_PLL_P_OUT3, TEGRA20_CLK_CLK_MAX, 72000000, 1 },
1559 { TEGRA20_CLK_PLL_P_OUT4, TEGRA20_CLK_CLK_MAX, 24000000, 1 },
1560 - { TEGRA20_CLK_PLL_C, TEGRA20_CLK_CLK_MAX, 600000000, 1 },
1561 - { TEGRA20_CLK_PLL_C_OUT1, TEGRA20_CLK_CLK_MAX, 216000000, 1 },
1562 - { TEGRA20_CLK_SCLK, TEGRA20_CLK_PLL_C_OUT1, 0, 1 },
1563 - { TEGRA20_CLK_HCLK, TEGRA20_CLK_CLK_MAX, 0, 1 },
1564 - { TEGRA20_CLK_PCLK, TEGRA20_CLK_CLK_MAX, 60000000, 1 },
1565 + { TEGRA20_CLK_PLL_C, TEGRA20_CLK_CLK_MAX, 600000000, 0 },
1566 + { TEGRA20_CLK_PLL_C_OUT1, TEGRA20_CLK_CLK_MAX, 216000000, 0 },
1567 + { TEGRA20_CLK_SCLK, TEGRA20_CLK_PLL_C_OUT1, 0, 0 },
1568 + { TEGRA20_CLK_HCLK, TEGRA20_CLK_CLK_MAX, 0, 0 },
1569 + { TEGRA20_CLK_PCLK, TEGRA20_CLK_CLK_MAX, 60000000, 0 },
1570 { TEGRA20_CLK_CSITE, TEGRA20_CLK_CLK_MAX, 0, 1 },
1571 - { TEGRA20_CLK_EMC, TEGRA20_CLK_CLK_MAX, 0, 1 },
1572 { TEGRA20_CLK_CCLK, TEGRA20_CLK_CLK_MAX, 0, 1 },
1573 { TEGRA20_CLK_UARTA, TEGRA20_CLK_PLL_P, 0, 0 },
1574 { TEGRA20_CLK_UARTB, TEGRA20_CLK_PLL_P, 0, 0 },
1575 diff --git a/drivers/clk/tegra/clk-tegra210.c b/drivers/clk/tegra/clk-tegra210.c
1576 index 9e6260869eb9..25cc6e0905be 100644
1577 --- a/drivers/clk/tegra/clk-tegra210.c
1578 +++ b/drivers/clk/tegra/clk-tegra210.c
1579 @@ -3025,7 +3025,7 @@ static struct tegra_clk_init_table init_table[] __initdata = {
1580 { TEGRA210_CLK_I2S4, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 },
1581 { TEGRA210_CLK_HOST1X, TEGRA210_CLK_PLL_P, 136000000, 1 },
1582 { TEGRA210_CLK_SCLK_MUX, TEGRA210_CLK_PLL_P, 0, 1 },
1583 - { TEGRA210_CLK_SCLK, TEGRA210_CLK_CLK_MAX, 102000000, 1 },
1584 + { TEGRA210_CLK_SCLK, TEGRA210_CLK_CLK_MAX, 102000000, 0 },
1585 { TEGRA210_CLK_DFLL_SOC, TEGRA210_CLK_PLL_P, 51000000, 1 },
1586 { TEGRA210_CLK_DFLL_REF, TEGRA210_CLK_PLL_P, 51000000, 1 },
1587 { TEGRA210_CLK_SBC4, TEGRA210_CLK_PLL_P, 12000000, 1 },
1588 @@ -3040,7 +3040,6 @@ static struct tegra_clk_init_table init_table[] __initdata = {
1589 { TEGRA210_CLK_XUSB_DEV_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 102000000, 0 },
1590 { TEGRA210_CLK_SATA, TEGRA210_CLK_PLL_P, 104000000, 0 },
1591 { TEGRA210_CLK_SATA_OOB, TEGRA210_CLK_PLL_P, 204000000, 0 },
1592 - { TEGRA210_CLK_EMC, TEGRA210_CLK_CLK_MAX, 0, 1 },
1593 { TEGRA210_CLK_MSELECT, TEGRA210_CLK_CLK_MAX, 0, 1 },
1594 { TEGRA210_CLK_CSITE, TEGRA210_CLK_CLK_MAX, 0, 1 },
1595 /* TODO find a way to enable this on-demand */
1596 diff --git a/drivers/clk/tegra/clk-tegra30.c b/drivers/clk/tegra/clk-tegra30.c
1597 index bee84c554932..8428895ad475 100644
1598 --- a/drivers/clk/tegra/clk-tegra30.c
1599 +++ b/drivers/clk/tegra/clk-tegra30.c
1600 @@ -819,6 +819,7 @@ static struct tegra_clk tegra30_clks[tegra_clk_max] __initdata = {
1601 [tegra_clk_pll_a] = { .dt_id = TEGRA30_CLK_PLL_A, .present = true },
1602 [tegra_clk_pll_a_out0] = { .dt_id = TEGRA30_CLK_PLL_A_OUT0, .present = true },
1603 [tegra_clk_cec] = { .dt_id = TEGRA30_CLK_CEC, .present = true },
1604 + [tegra_clk_emc] = { .dt_id = TEGRA30_CLK_EMC, .present = true },
1605 };
1606
1607 static const char *pll_e_parents[] = { "pll_ref", "pll_p" };
1608 @@ -843,8 +844,7 @@ static void __init tegra30_pll_init(void)
1609
1610 /* PLLM */
1611 clk = tegra_clk_register_pll("pll_m", "pll_ref", clk_base, pmc_base,
1612 - CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
1613 - &pll_m_params, NULL);
1614 + CLK_SET_RATE_GATE, &pll_m_params, NULL);
1615 clks[TEGRA30_CLK_PLL_M] = clk;
1616
1617 /* PLLM_OUT1 */
1618 @@ -852,7 +852,7 @@ static void __init tegra30_pll_init(void)
1619 clk_base + PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
1620 8, 8, 1, NULL);
1621 clk = tegra_clk_register_pll_out("pll_m_out1", "pll_m_out1_div",
1622 - clk_base + PLLM_OUT, 1, 0, CLK_IGNORE_UNUSED |
1623 + clk_base + PLLM_OUT, 1, 0,
1624 CLK_SET_RATE_PARENT, 0, NULL);
1625 clks[TEGRA30_CLK_PLL_M_OUT1] = clk;
1626
1627 @@ -990,7 +990,7 @@ static void __init tegra30_super_clk_init(void)
1628 /* SCLK */
1629 clk = tegra_clk_register_super_mux("sclk", sclk_parents,
1630 ARRAY_SIZE(sclk_parents),
1631 - CLK_SET_RATE_PARENT,
1632 + CLK_SET_RATE_PARENT | CLK_IS_CRITICAL,
1633 clk_base + SCLK_BURST_POLICY,
1634 0, 4, 0, 0, NULL);
1635 clks[TEGRA30_CLK_SCLK] = clk;
1636 @@ -1060,9 +1060,6 @@ static void __init tegra30_periph_clk_init(void)
1637 CLK_SET_RATE_NO_REPARENT,
1638 clk_base + CLK_SOURCE_EMC,
1639 30, 2, 0, &emc_lock);
1640 - clk = tegra_clk_register_periph_gate("emc", "emc_mux", 0, clk_base, 0,
1641 - 57, periph_clk_enb_refcnt);
1642 - clks[TEGRA30_CLK_EMC] = clk;
1643
1644 clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC,
1645 &emc_lock);
1646 @@ -1252,10 +1249,7 @@ static struct tegra_clk_init_table init_table[] __initdata = {
1647 { TEGRA30_CLK_SDMMC1, TEGRA30_CLK_PLL_P, 48000000, 0 },
1648 { TEGRA30_CLK_SDMMC2, TEGRA30_CLK_PLL_P, 48000000, 0 },
1649 { TEGRA30_CLK_SDMMC3, TEGRA30_CLK_PLL_P, 48000000, 0 },
1650 - { TEGRA30_CLK_PLL_M, TEGRA30_CLK_CLK_MAX, 0, 1 },
1651 - { TEGRA30_CLK_PCLK, TEGRA30_CLK_CLK_MAX, 0, 1 },
1652 { TEGRA30_CLK_CSITE, TEGRA30_CLK_CLK_MAX, 0, 1 },
1653 - { TEGRA30_CLK_EMC, TEGRA30_CLK_CLK_MAX, 0, 1 },
1654 { TEGRA30_CLK_MSELECT, TEGRA30_CLK_CLK_MAX, 0, 1 },
1655 { TEGRA30_CLK_SBC1, TEGRA30_CLK_PLL_P, 100000000, 0 },
1656 { TEGRA30_CLK_SBC2, TEGRA30_CLK_PLL_P, 100000000, 0 },
1657 diff --git a/drivers/cpufreq/armada-37xx-cpufreq.c b/drivers/cpufreq/armada-37xx-cpufreq.c
1658 index c6ebc88a7d8d..72a2975499db 100644
1659 --- a/drivers/cpufreq/armada-37xx-cpufreq.c
1660 +++ b/drivers/cpufreq/armada-37xx-cpufreq.c
1661 @@ -202,6 +202,7 @@ static int __init armada37xx_cpufreq_driver_init(void)
1662 cur_frequency = clk_get_rate(clk);
1663 if (!cur_frequency) {
1664 dev_err(cpu_dev, "Failed to get clock rate for CPU\n");
1665 + clk_put(clk);
1666 return -EINVAL;
1667 }
1668
1669 @@ -210,6 +211,7 @@ static int __init armada37xx_cpufreq_driver_init(void)
1670 return -EINVAL;
1671
1672 armada37xx_cpufreq_dvfs_setup(nb_pm_base, clk, dvfs->divider);
1673 + clk_put(clk);
1674
1675 for (load_lvl = ARMADA_37XX_DVFS_LOAD_0; load_lvl < LOAD_LEVEL_NR;
1676 load_lvl++) {
1677 diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
1678 index a1c3025f9df7..dcb1cb9a4572 100644
1679 --- a/drivers/cpufreq/cppc_cpufreq.c
1680 +++ b/drivers/cpufreq/cppc_cpufreq.c
1681 @@ -20,6 +20,7 @@
1682 #include <linux/cpu.h>
1683 #include <linux/cpufreq.h>
1684 #include <linux/dmi.h>
1685 +#include <linux/time.h>
1686 #include <linux/vmalloc.h>
1687
1688 #include <asm/unaligned.h>
1689 @@ -162,6 +163,8 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
1690 policy->cpuinfo.max_freq = cppc_dmi_max_khz;
1691
1692 policy->cpuinfo.transition_latency = cppc_get_transition_latency(cpu_num);
1693 + policy->transition_delay_us = cppc_get_transition_latency(cpu_num) /
1694 + NSEC_PER_USEC;
1695 policy->shared_type = cpu->shared_type;
1696
1697 if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY)
1698 diff --git a/drivers/dax/device.c b/drivers/dax/device.c
1699 index 2137dbc29877..383779707404 100644
1700 --- a/drivers/dax/device.c
1701 +++ b/drivers/dax/device.c
1702 @@ -19,6 +19,7 @@
1703 #include <linux/dax.h>
1704 #include <linux/fs.h>
1705 #include <linux/mm.h>
1706 +#include <linux/mman.h>
1707 #include "dax-private.h"
1708 #include "dax.h"
1709
1710 @@ -534,6 +535,7 @@ static const struct file_operations dax_fops = {
1711 .release = dax_release,
1712 .get_unmapped_area = dax_get_unmapped_area,
1713 .mmap = dax_mmap,
1714 + .mmap_supported_flags = MAP_SYNC,
1715 };
1716
1717 static void dev_dax_release(struct device *dev)
1718 diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c
1719 index c00e3923d7d8..94236ec9d410 100644
1720 --- a/drivers/dma/at_xdmac.c
1721 +++ b/drivers/dma/at_xdmac.c
1722 @@ -1471,10 +1471,10 @@ at_xdmac_tx_status(struct dma_chan *chan, dma_cookie_t cookie,
1723 for (retry = 0; retry < AT_XDMAC_RESIDUE_MAX_RETRIES; retry++) {
1724 check_nda = at_xdmac_chan_read(atchan, AT_XDMAC_CNDA) & 0xfffffffc;
1725 rmb();
1726 - initd = !!(at_xdmac_chan_read(atchan, AT_XDMAC_CC) & AT_XDMAC_CC_INITD);
1727 - rmb();
1728 cur_ubc = at_xdmac_chan_read(atchan, AT_XDMAC_CUBC);
1729 rmb();
1730 + initd = !!(at_xdmac_chan_read(atchan, AT_XDMAC_CC) & AT_XDMAC_CC_INITD);
1731 + rmb();
1732 cur_nda = at_xdmac_chan_read(atchan, AT_XDMAC_CNDA) & 0xfffffffc;
1733 rmb();
1734
1735 diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c
1736 index 7c4bc8c44c3f..b7e9ea377d70 100644
1737 --- a/drivers/extcon/extcon-intel-cht-wc.c
1738 +++ b/drivers/extcon/extcon-intel-cht-wc.c
1739 @@ -66,6 +66,8 @@
1740
1741 #define CHT_WC_VBUS_GPIO_CTLO 0x6e2d
1742 #define CHT_WC_VBUS_GPIO_CTLO_OUTPUT BIT(0)
1743 +#define CHT_WC_VBUS_GPIO_CTLO_DRV_OD BIT(4)
1744 +#define CHT_WC_VBUS_GPIO_CTLO_DIR_OUT BIT(5)
1745
1746 enum cht_wc_usb_id {
1747 USB_ID_OTG,
1748 @@ -183,14 +185,15 @@ static void cht_wc_extcon_set_5v_boost(struct cht_wc_extcon_data *ext,
1749 {
1750 int ret, val;
1751
1752 - val = enable ? CHT_WC_VBUS_GPIO_CTLO_OUTPUT : 0;
1753 -
1754 /*
1755 * The 5V boost converter is enabled through a gpio on the PMIC, since
1756 * there currently is no gpio driver we access the gpio reg directly.
1757 */
1758 - ret = regmap_update_bits(ext->regmap, CHT_WC_VBUS_GPIO_CTLO,
1759 - CHT_WC_VBUS_GPIO_CTLO_OUTPUT, val);
1760 + val = CHT_WC_VBUS_GPIO_CTLO_DRV_OD | CHT_WC_VBUS_GPIO_CTLO_DIR_OUT;
1761 + if (enable)
1762 + val |= CHT_WC_VBUS_GPIO_CTLO_OUTPUT;
1763 +
1764 + ret = regmap_write(ext->regmap, CHT_WC_VBUS_GPIO_CTLO, val);
1765 if (ret)
1766 dev_err(ext->dev, "Error writing Vbus GPIO CTLO: %d\n", ret);
1767 }
1768 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
1769 index c53095b3b0fb..1ae5ae8c45a4 100644
1770 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
1771 +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
1772 @@ -569,6 +569,7 @@ static const struct amdgpu_px_quirk amdgpu_px_quirk_list[] = {
1773 { 0x1002, 0x6900, 0x1002, 0x0124, AMDGPU_PX_QUIRK_FORCE_ATPX },
1774 { 0x1002, 0x6900, 0x1028, 0x0812, AMDGPU_PX_QUIRK_FORCE_ATPX },
1775 { 0x1002, 0x6900, 0x1028, 0x0813, AMDGPU_PX_QUIRK_FORCE_ATPX },
1776 + { 0x1002, 0x67DF, 0x1028, 0x0774, AMDGPU_PX_QUIRK_FORCE_ATPX },
1777 { 0, 0, 0, 0, 0 },
1778 };
1779
1780 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
1781 index 59089e027f4d..92be7f6de197 100644
1782 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
1783 +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
1784 @@ -233,8 +233,10 @@ void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1785 for (i = 0; i < list->num_entries; i++) {
1786 unsigned priority = list->array[i].priority;
1787
1788 - list_add_tail(&list->array[i].tv.head,
1789 - &bucket[priority]);
1790 + if (!list->array[i].robj->parent)
1791 + list_add_tail(&list->array[i].tv.head,
1792 + &bucket[priority]);
1793 +
1794 list->array[i].user_pages = NULL;
1795 }
1796
1797 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
1798 index e80fc38141b5..b03b2983de1e 100644
1799 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
1800 +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
1801 @@ -542,7 +542,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
1802 INIT_LIST_HEAD(&duplicates);
1803 amdgpu_vm_get_pd_bo(&fpriv->vm, &p->validated, &p->vm_pd);
1804
1805 - if (p->uf_entry.robj)
1806 + if (p->uf_entry.robj && !p->uf_entry.robj->parent)
1807 list_add(&p->uf_entry.tv.head, &p->validated);
1808
1809 while (1) {
1810 diff --git a/drivers/gpu/drm/amd/amdgpu/cik_sdma.c b/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
1811 index 6e8278e689b1..0066da3e79bb 100644
1812 --- a/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
1813 +++ b/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
1814 @@ -866,7 +866,7 @@ static void cik_sdma_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1815 amdgpu_ring_write(ring, addr & 0xfffffffc);
1816 amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
1817 amdgpu_ring_write(ring, seq); /* reference */
1818 - amdgpu_ring_write(ring, 0xfffffff); /* mask */
1819 + amdgpu_ring_write(ring, 0xffffffff); /* mask */
1820 amdgpu_ring_write(ring, (0xfff << 16) | 4); /* retry count, poll interval */
1821 }
1822
1823 diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c b/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
1824 index d4787ad4d346..bd844edad6b7 100644
1825 --- a/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
1826 +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
1827 @@ -844,7 +844,7 @@ static void sdma_v2_4_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1828 amdgpu_ring_write(ring, addr & 0xfffffffc);
1829 amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
1830 amdgpu_ring_write(ring, seq); /* reference */
1831 - amdgpu_ring_write(ring, 0xfffffff); /* mask */
1832 + amdgpu_ring_write(ring, 0xffffffff); /* mask */
1833 amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
1834 SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(4)); /* retry count, poll interval */
1835 }
1836 diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
1837 index 521978c40537..fa63c564cf91 100644
1838 --- a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
1839 +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
1840 @@ -1110,7 +1110,7 @@ static void sdma_v3_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1841 amdgpu_ring_write(ring, addr & 0xfffffffc);
1842 amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
1843 amdgpu_ring_write(ring, seq); /* reference */
1844 - amdgpu_ring_write(ring, 0xfffffff); /* mask */
1845 + amdgpu_ring_write(ring, 0xffffffff); /* mask */
1846 amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
1847 SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(4)); /* retry count, poll interval */
1848 }
1849 diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
1850 index 91cf95a8c39c..036798b52f67 100644
1851 --- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
1852 +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
1853 @@ -1113,7 +1113,7 @@ static void sdma_v4_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1854 amdgpu_ring_write(ring, addr & 0xfffffffc);
1855 amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
1856 amdgpu_ring_write(ring, seq); /* reference */
1857 - amdgpu_ring_write(ring, 0xfffffff); /* mask */
1858 + amdgpu_ring_write(ring, 0xffffffff); /* mask */
1859 amdgpu_ring_write(ring, SDMA_PKT_POLL_REGMEM_DW5_RETRY_COUNT(0xfff) |
1860 SDMA_PKT_POLL_REGMEM_DW5_INTERVAL(4)); /* retry count, poll interval */
1861 }
1862 diff --git a/drivers/gpu/drm/amd/amdgpu/si.c b/drivers/gpu/drm/amd/amdgpu/si.c
1863 index 2095173aaabf..3598151652d7 100644
1864 --- a/drivers/gpu/drm/amd/amdgpu/si.c
1865 +++ b/drivers/gpu/drm/amd/amdgpu/si.c
1866 @@ -1231,6 +1231,71 @@ static void si_detect_hw_virtualization(struct amdgpu_device *adev)
1867 adev->virt.caps |= AMDGPU_PASSTHROUGH_MODE;
1868 }
1869
1870 +static int si_get_pcie_lanes(struct amdgpu_device *adev)
1871 +{
1872 + u32 link_width_cntl;
1873 +
1874 + if (adev->flags & AMD_IS_APU)
1875 + return 0;
1876 +
1877 + link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
1878 +
1879 + switch ((link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT) {
1880 + case LC_LINK_WIDTH_X1:
1881 + return 1;
1882 + case LC_LINK_WIDTH_X2:
1883 + return 2;
1884 + case LC_LINK_WIDTH_X4:
1885 + return 4;
1886 + case LC_LINK_WIDTH_X8:
1887 + return 8;
1888 + case LC_LINK_WIDTH_X0:
1889 + case LC_LINK_WIDTH_X16:
1890 + default:
1891 + return 16;
1892 + }
1893 +}
1894 +
1895 +static void si_set_pcie_lanes(struct amdgpu_device *adev, int lanes)
1896 +{
1897 + u32 link_width_cntl, mask;
1898 +
1899 + if (adev->flags & AMD_IS_APU)
1900 + return;
1901 +
1902 + switch (lanes) {
1903 + case 0:
1904 + mask = LC_LINK_WIDTH_X0;
1905 + break;
1906 + case 1:
1907 + mask = LC_LINK_WIDTH_X1;
1908 + break;
1909 + case 2:
1910 + mask = LC_LINK_WIDTH_X2;
1911 + break;
1912 + case 4:
1913 + mask = LC_LINK_WIDTH_X4;
1914 + break;
1915 + case 8:
1916 + mask = LC_LINK_WIDTH_X8;
1917 + break;
1918 + case 16:
1919 + mask = LC_LINK_WIDTH_X16;
1920 + break;
1921 + default:
1922 + DRM_ERROR("invalid pcie lane request: %d\n", lanes);
1923 + return;
1924 + }
1925 +
1926 + link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
1927 + link_width_cntl &= ~LC_LINK_WIDTH_MASK;
1928 + link_width_cntl |= mask << LC_LINK_WIDTH_SHIFT;
1929 + link_width_cntl |= (LC_RECONFIG_NOW |
1930 + LC_RECONFIG_ARC_MISSING_ESCAPE);
1931 +
1932 + WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
1933 +}
1934 +
1935 static const struct amdgpu_asic_funcs si_asic_funcs =
1936 {
1937 .read_disabled_bios = &si_read_disabled_bios,
1938 @@ -1241,6 +1306,8 @@ static const struct amdgpu_asic_funcs si_asic_funcs =
1939 .get_xclk = &si_get_xclk,
1940 .set_uvd_clocks = &si_set_uvd_clocks,
1941 .set_vce_clocks = NULL,
1942 + .get_pcie_lanes = &si_get_pcie_lanes,
1943 + .set_pcie_lanes = &si_set_pcie_lanes,
1944 .get_config_memsize = &si_get_config_memsize,
1945 };
1946
1947 diff --git a/drivers/gpu/drm/amd/amdgpu/si_dpm.c b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
1948 index 22f0b7ff3ac9..b1a3ca585ed1 100644
1949 --- a/drivers/gpu/drm/amd/amdgpu/si_dpm.c
1950 +++ b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
1951 @@ -6370,9 +6370,9 @@ static void si_set_pcie_lane_width_in_smc(struct amdgpu_device *adev,
1952 {
1953 u32 lane_width;
1954 u32 new_lane_width =
1955 - (amdgpu_new_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT;
1956 + ((amdgpu_new_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
1957 u32 current_lane_width =
1958 - (amdgpu_current_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT;
1959 + ((amdgpu_current_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
1960
1961 if (new_lane_width != current_lane_width) {
1962 amdgpu_set_pcie_lanes(adev, new_lane_width);
1963 diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
1964 index 63c67346d316..8a6e6fbc78cd 100644
1965 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
1966 +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
1967 @@ -4776,33 +4776,6 @@ static int dm_update_planes_state(struct dc *dc,
1968 return ret;
1969 }
1970
1971 -static int dm_atomic_check_plane_state_fb(struct drm_atomic_state *state,
1972 - struct drm_crtc *crtc)
1973 -{
1974 - struct drm_plane *plane;
1975 - struct drm_crtc_state *crtc_state;
1976 -
1977 - WARN_ON(!drm_atomic_get_new_crtc_state(state, crtc));
1978 -
1979 - drm_for_each_plane_mask(plane, state->dev, crtc->state->plane_mask) {
1980 - struct drm_plane_state *plane_state =
1981 - drm_atomic_get_plane_state(state, plane);
1982 -
1983 - if (IS_ERR(plane_state))
1984 - return -EDEADLK;
1985 -
1986 - crtc_state = drm_atomic_get_crtc_state(plane_state->state, crtc);
1987 - if (IS_ERR(crtc_state))
1988 - return PTR_ERR(crtc_state);
1989 -
1990 - if (crtc->primary == plane && crtc_state->active) {
1991 - if (!plane_state->fb)
1992 - return -EINVAL;
1993 - }
1994 - }
1995 - return 0;
1996 -}
1997 -
1998 static int amdgpu_dm_atomic_check(struct drm_device *dev,
1999 struct drm_atomic_state *state)
2000 {
2001 @@ -4826,10 +4799,6 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
2002 goto fail;
2003
2004 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
2005 - ret = dm_atomic_check_plane_state_fb(state, crtc);
2006 - if (ret)
2007 - goto fail;
2008 -
2009 if (!drm_atomic_crtc_needs_modeset(new_crtc_state) &&
2010 !new_crtc_state->color_mgmt_changed)
2011 continue;
2012 diff --git a/drivers/gpu/drm/amd/display/dc/dce/dce_stream_encoder.c b/drivers/gpu/drm/amd/display/dc/dce/dce_stream_encoder.c
2013 index 83bae207371d..b3c30abcb8f1 100644
2014 --- a/drivers/gpu/drm/amd/display/dc/dce/dce_stream_encoder.c
2015 +++ b/drivers/gpu/drm/amd/display/dc/dce/dce_stream_encoder.c
2016 @@ -736,6 +736,8 @@ static void dce110_stream_encoder_update_hdmi_info_packets(
2017 if (info_frame->avi.valid) {
2018 const uint32_t *content =
2019 (const uint32_t *) &info_frame->avi.sb[0];
2020 + /*we need turn on clock before programming AFMT block*/
2021 + REG_UPDATE(AFMT_CNTL, AFMT_AUDIO_CLOCK_EN, 1);
2022
2023 REG_WRITE(AFMT_AVI_INFO0, content[0]);
2024
2025 diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
2026 index c6197d990818..d35b93f5ecfc 100644
2027 --- a/drivers/gpu/drm/i915/gvt/gvt.h
2028 +++ b/drivers/gpu/drm/i915/gvt/gvt.h
2029 @@ -308,7 +308,10 @@ struct intel_gvt {
2030 wait_queue_head_t service_thread_wq;
2031 unsigned long service_request;
2032
2033 - struct engine_mmio *engine_mmio_list;
2034 + struct {
2035 + struct engine_mmio *mmio;
2036 + int ctx_mmio_count[I915_NUM_ENGINES];
2037 + } engine_mmio_list;
2038
2039 struct dentry *debugfs_root;
2040 };
2041 diff --git a/drivers/gpu/drm/i915/gvt/mmio_context.c b/drivers/gpu/drm/i915/gvt/mmio_context.c
2042 index 152df3d0291e..c44dba338c57 100644
2043 --- a/drivers/gpu/drm/i915/gvt/mmio_context.c
2044 +++ b/drivers/gpu/drm/i915/gvt/mmio_context.c
2045 @@ -50,6 +50,8 @@
2046 #define RING_GFX_MODE(base) _MMIO((base) + 0x29c)
2047 #define VF_GUARDBAND _MMIO(0x83a4)
2048
2049 +#define GEN9_MOCS_SIZE 64
2050 +
2051 /* Raw offset is appened to each line for convenience. */
2052 static struct engine_mmio gen8_engine_mmio_list[] __cacheline_aligned = {
2053 {RCS, GFX_MODE_GEN7, 0xffff, false}, /* 0x229c */
2054 @@ -152,8 +154,8 @@ static struct engine_mmio gen9_engine_mmio_list[] __cacheline_aligned = {
2055
2056 static struct {
2057 bool initialized;
2058 - u32 control_table[I915_NUM_ENGINES][64];
2059 - u32 l3cc_table[32];
2060 + u32 control_table[I915_NUM_ENGINES][GEN9_MOCS_SIZE];
2061 + u32 l3cc_table[GEN9_MOCS_SIZE / 2];
2062 } gen9_render_mocs;
2063
2064 static void load_render_mocs(struct drm_i915_private *dev_priv)
2065 @@ -170,7 +172,7 @@ static void load_render_mocs(struct drm_i915_private *dev_priv)
2066
2067 for (ring_id = 0; ring_id < ARRAY_SIZE(regs); ring_id++) {
2068 offset.reg = regs[ring_id];
2069 - for (i = 0; i < 64; i++) {
2070 + for (i = 0; i < GEN9_MOCS_SIZE; i++) {
2071 gen9_render_mocs.control_table[ring_id][i] =
2072 I915_READ_FW(offset);
2073 offset.reg += 4;
2074 @@ -178,7 +180,7 @@ static void load_render_mocs(struct drm_i915_private *dev_priv)
2075 }
2076
2077 offset.reg = 0xb020;
2078 - for (i = 0; i < 32; i++) {
2079 + for (i = 0; i < GEN9_MOCS_SIZE / 2; i++) {
2080 gen9_render_mocs.l3cc_table[i] =
2081 I915_READ_FW(offset);
2082 offset.reg += 4;
2083 @@ -186,6 +188,153 @@ static void load_render_mocs(struct drm_i915_private *dev_priv)
2084 gen9_render_mocs.initialized = true;
2085 }
2086
2087 +static int
2088 +restore_context_mmio_for_inhibit(struct intel_vgpu *vgpu,
2089 + struct drm_i915_gem_request *req)
2090 +{
2091 + u32 *cs;
2092 + int ret;
2093 + struct engine_mmio *mmio;
2094 + struct intel_gvt *gvt = vgpu->gvt;
2095 + int ring_id = req->engine->id;
2096 + int count = gvt->engine_mmio_list.ctx_mmio_count[ring_id];
2097 +
2098 + if (count == 0)
2099 + return 0;
2100 +
2101 + ret = req->engine->emit_flush(req, EMIT_BARRIER);
2102 + if (ret)
2103 + return ret;
2104 +
2105 + cs = intel_ring_begin(req, count * 2 + 2);
2106 + if (IS_ERR(cs))
2107 + return PTR_ERR(cs);
2108 +
2109 + *cs++ = MI_LOAD_REGISTER_IMM(count);
2110 + for (mmio = gvt->engine_mmio_list.mmio;
2111 + i915_mmio_reg_valid(mmio->reg); mmio++) {
2112 + if (mmio->ring_id != ring_id ||
2113 + !mmio->in_context)
2114 + continue;
2115 +
2116 + *cs++ = i915_mmio_reg_offset(mmio->reg);
2117 + *cs++ = vgpu_vreg_t(vgpu, mmio->reg) |
2118 + (mmio->mask << 16);
2119 + gvt_dbg_core("add lri reg pair 0x%x:0x%x in inhibit ctx, vgpu:%d, rind_id:%d\n",
2120 + *(cs-2), *(cs-1), vgpu->id, ring_id);
2121 + }
2122 +
2123 + *cs++ = MI_NOOP;
2124 + intel_ring_advance(req, cs);
2125 +
2126 + ret = req->engine->emit_flush(req, EMIT_BARRIER);
2127 + if (ret)
2128 + return ret;
2129 +
2130 + return 0;
2131 +}
2132 +
2133 +static int
2134 +restore_render_mocs_control_for_inhibit(struct intel_vgpu *vgpu,
2135 + struct drm_i915_gem_request *req)
2136 +{
2137 + unsigned int index;
2138 + u32 *cs;
2139 +
2140 + cs = intel_ring_begin(req, 2 * GEN9_MOCS_SIZE + 2);
2141 + if (IS_ERR(cs))
2142 + return PTR_ERR(cs);
2143 +
2144 + *cs++ = MI_LOAD_REGISTER_IMM(GEN9_MOCS_SIZE);
2145 +
2146 + for (index = 0; index < GEN9_MOCS_SIZE; index++) {
2147 + *cs++ = i915_mmio_reg_offset(GEN9_GFX_MOCS(index));
2148 + *cs++ = vgpu_vreg_t(vgpu, GEN9_GFX_MOCS(index));
2149 + gvt_dbg_core("add lri reg pair 0x%x:0x%x in inhibit ctx, vgpu:%d, rind_id:%d\n",
2150 + *(cs-2), *(cs-1), vgpu->id, req->engine->id);
2151 +
2152 + }
2153 +
2154 + *cs++ = MI_NOOP;
2155 + intel_ring_advance(req, cs);
2156 +
2157 + return 0;
2158 +}
2159 +
2160 +static int
2161 +restore_render_mocs_l3cc_for_inhibit(struct intel_vgpu *vgpu,
2162 + struct drm_i915_gem_request *req)
2163 +{
2164 + unsigned int index;
2165 + u32 *cs;
2166 +
2167 + cs = intel_ring_begin(req, 2 * GEN9_MOCS_SIZE / 2 + 2);
2168 + if (IS_ERR(cs))
2169 + return PTR_ERR(cs);
2170 +
2171 + *cs++ = MI_LOAD_REGISTER_IMM(GEN9_MOCS_SIZE / 2);
2172 +
2173 + for (index = 0; index < GEN9_MOCS_SIZE / 2; index++) {
2174 + *cs++ = i915_mmio_reg_offset(GEN9_LNCFCMOCS(index));
2175 + *cs++ = vgpu_vreg_t(vgpu, GEN9_LNCFCMOCS(index));
2176 + gvt_dbg_core("add lri reg pair 0x%x:0x%x in inhibit ctx, vgpu:%d, rind_id:%d\n",
2177 + *(cs-2), *(cs-1), vgpu->id, req->engine->id);
2178 +
2179 + }
2180 +
2181 + *cs++ = MI_NOOP;
2182 + intel_ring_advance(req, cs);
2183 +
2184 + return 0;
2185 +}
2186 +
2187 +/*
2188 + * Use lri command to initialize the mmio which is in context state image for
2189 + * inhibit context, it contains tracked engine mmio, render_mocs and
2190 + * render_mocs_l3cc.
2191 + */
2192 +int intel_vgpu_restore_inhibit_context(struct intel_vgpu *vgpu,
2193 + struct drm_i915_gem_request *req)
2194 +{
2195 + int ret;
2196 + u32 *cs;
2197 +
2198 + cs = intel_ring_begin(req, 2);
2199 + if (IS_ERR(cs))
2200 + return PTR_ERR(cs);
2201 +
2202 + *cs++ = MI_ARB_ON_OFF | MI_ARB_DISABLE;
2203 + *cs++ = MI_NOOP;
2204 + intel_ring_advance(req, cs);
2205 +
2206 + ret = restore_context_mmio_for_inhibit(vgpu, req);
2207 + if (ret)
2208 + goto out;
2209 +
2210 + /* no MOCS register in context except render engine */
2211 + if (req->engine->id != RCS)
2212 + goto out;
2213 +
2214 + ret = restore_render_mocs_control_for_inhibit(vgpu, req);
2215 + if (ret)
2216 + goto out;
2217 +
2218 + ret = restore_render_mocs_l3cc_for_inhibit(vgpu, req);
2219 + if (ret)
2220 + goto out;
2221 +
2222 +out:
2223 + cs = intel_ring_begin(req, 2);
2224 + if (IS_ERR(cs))
2225 + return PTR_ERR(cs);
2226 +
2227 + *cs++ = MI_ARB_ON_OFF | MI_ARB_ENABLE;
2228 + *cs++ = MI_NOOP;
2229 + intel_ring_advance(req, cs);
2230 +
2231 + return ret;
2232 +}
2233 +
2234 static void handle_tlb_pending_event(struct intel_vgpu *vgpu, int ring_id)
2235 {
2236 struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv;
2237 @@ -252,11 +401,14 @@ static void switch_mocs(struct intel_vgpu *pre, struct intel_vgpu *next,
2238 if (WARN_ON(ring_id >= ARRAY_SIZE(regs)))
2239 return;
2240
2241 + if (IS_KABYLAKE(dev_priv) && ring_id == RCS)
2242 + return;
2243 +
2244 if (!pre && !gen9_render_mocs.initialized)
2245 load_render_mocs(dev_priv);
2246
2247 offset.reg = regs[ring_id];
2248 - for (i = 0; i < 64; i++) {
2249 + for (i = 0; i < GEN9_MOCS_SIZE; i++) {
2250 if (pre)
2251 old_v = vgpu_vreg_t(pre, offset);
2252 else
2253 @@ -274,7 +426,7 @@ static void switch_mocs(struct intel_vgpu *pre, struct intel_vgpu *next,
2254
2255 if (ring_id == RCS) {
2256 l3_offset.reg = 0xb020;
2257 - for (i = 0; i < 32; i++) {
2258 + for (i = 0; i < GEN9_MOCS_SIZE / 2; i++) {
2259 if (pre)
2260 old_v = vgpu_vreg_t(pre, l3_offset);
2261 else
2262 @@ -294,6 +446,16 @@ static void switch_mocs(struct intel_vgpu *pre, struct intel_vgpu *next,
2263
2264 #define CTX_CONTEXT_CONTROL_VAL 0x03
2265
2266 +bool is_inhibit_context(struct i915_gem_context *ctx, int ring_id)
2267 +{
2268 + u32 *reg_state = ctx->engine[ring_id].lrc_reg_state;
2269 + u32 inhibit_mask =
2270 + _MASKED_BIT_ENABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT);
2271 +
2272 + return inhibit_mask ==
2273 + (reg_state[CTX_CONTEXT_CONTROL_VAL] & inhibit_mask);
2274 +}
2275 +
2276 /* Switch ring mmio values (context). */
2277 static void switch_mmio(struct intel_vgpu *pre,
2278 struct intel_vgpu *next,
2279 @@ -301,9 +463,6 @@ static void switch_mmio(struct intel_vgpu *pre,
2280 {
2281 struct drm_i915_private *dev_priv;
2282 struct intel_vgpu_submission *s;
2283 - u32 *reg_state, ctx_ctrl;
2284 - u32 inhibit_mask =
2285 - _MASKED_BIT_ENABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT);
2286 struct engine_mmio *mmio;
2287 u32 old_v, new_v;
2288
2289 @@ -311,10 +470,18 @@ static void switch_mmio(struct intel_vgpu *pre,
2290 if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
2291 switch_mocs(pre, next, ring_id);
2292
2293 - for (mmio = dev_priv->gvt->engine_mmio_list;
2294 + for (mmio = dev_priv->gvt->engine_mmio_list.mmio;
2295 i915_mmio_reg_valid(mmio->reg); mmio++) {
2296 if (mmio->ring_id != ring_id)
2297 continue;
2298 + /*
2299 + * No need to do save or restore of the mmio which is in context
2300 + * state image on kabylake, it's initialized by lri command and
2301 + * save or restore with context together.
2302 + */
2303 + if (IS_KABYLAKE(dev_priv) && mmio->in_context)
2304 + continue;
2305 +
2306 // save
2307 if (pre) {
2308 vgpu_vreg_t(pre, mmio->reg) = I915_READ_FW(mmio->reg);
2309 @@ -328,16 +495,13 @@ static void switch_mmio(struct intel_vgpu *pre,
2310 // restore
2311 if (next) {
2312 s = &next->submission;
2313 - reg_state =
2314 - s->shadow_ctx->engine[ring_id].lrc_reg_state;
2315 - ctx_ctrl = reg_state[CTX_CONTEXT_CONTROL_VAL];
2316 /*
2317 - * if it is an inhibit context, load in_context mmio
2318 - * into HW by mmio write. If it is not, skip this mmio
2319 - * write.
2320 + * No need to restore the mmio which is in context state
2321 + * image if it's not inhibit context, it will restore
2322 + * itself.
2323 */
2324 if (mmio->in_context &&
2325 - (ctx_ctrl & inhibit_mask) != inhibit_mask)
2326 + !is_inhibit_context(s->shadow_ctx, ring_id))
2327 continue;
2328
2329 if (mmio->mask)
2330 @@ -408,8 +572,16 @@ void intel_gvt_switch_mmio(struct intel_vgpu *pre,
2331 */
2332 void intel_gvt_init_engine_mmio_context(struct intel_gvt *gvt)
2333 {
2334 + struct engine_mmio *mmio;
2335 +
2336 if (IS_SKYLAKE(gvt->dev_priv) || IS_KABYLAKE(gvt->dev_priv))
2337 - gvt->engine_mmio_list = gen9_engine_mmio_list;
2338 + gvt->engine_mmio_list.mmio = gen9_engine_mmio_list;
2339 else
2340 - gvt->engine_mmio_list = gen8_engine_mmio_list;
2341 + gvt->engine_mmio_list.mmio = gen8_engine_mmio_list;
2342 +
2343 + for (mmio = gvt->engine_mmio_list.mmio;
2344 + i915_mmio_reg_valid(mmio->reg); mmio++) {
2345 + if (mmio->in_context)
2346 + gvt->engine_mmio_list.ctx_mmio_count[mmio->ring_id]++;
2347 + }
2348 }
2349 diff --git a/drivers/gpu/drm/i915/gvt/mmio_context.h b/drivers/gpu/drm/i915/gvt/mmio_context.h
2350 index ca2c6a745673..0b1d98536653 100644
2351 --- a/drivers/gpu/drm/i915/gvt/mmio_context.h
2352 +++ b/drivers/gpu/drm/i915/gvt/mmio_context.h
2353 @@ -49,4 +49,9 @@ void intel_gvt_switch_mmio(struct intel_vgpu *pre,
2354
2355 void intel_gvt_init_engine_mmio_context(struct intel_gvt *gvt);
2356
2357 +bool is_inhibit_context(struct i915_gem_context *ctx, int ring_id);
2358 +
2359 +int intel_vgpu_restore_inhibit_context(struct intel_vgpu *vgpu,
2360 + struct drm_i915_gem_request *req);
2361 +
2362 #endif
2363 diff --git a/drivers/gpu/drm/i915/gvt/scheduler.c b/drivers/gpu/drm/i915/gvt/scheduler.c
2364 index d74d6f05c62c..88b7b47695bd 100644
2365 --- a/drivers/gpu/drm/i915/gvt/scheduler.c
2366 +++ b/drivers/gpu/drm/i915/gvt/scheduler.c
2367 @@ -275,6 +275,11 @@ static int copy_workload_to_ring_buffer(struct intel_vgpu_workload *workload)
2368 struct intel_vgpu *vgpu = workload->vgpu;
2369 void *shadow_ring_buffer_va;
2370 u32 *cs;
2371 + struct drm_i915_gem_request *req = workload->req;
2372 +
2373 + if (IS_KABYLAKE(req->i915) &&
2374 + is_inhibit_context(req->ctx, req->engine->id))
2375 + intel_vgpu_restore_inhibit_context(vgpu, req);
2376
2377 /* allocate shadow ring buffer */
2378 cs = intel_ring_begin(workload->req, workload->rb_len / sizeof(u32));
2379 diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
2380 index 2f5209de0391..f1cd4f0ffc62 100644
2381 --- a/drivers/gpu/drm/i915/i915_drv.c
2382 +++ b/drivers/gpu/drm/i915/i915_drv.c
2383 @@ -1599,15 +1599,12 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation)
2384 {
2385 struct drm_i915_private *dev_priv = to_i915(dev);
2386 struct pci_dev *pdev = dev_priv->drm.pdev;
2387 - bool fw_csr;
2388 int ret;
2389
2390 disable_rpm_wakeref_asserts(dev_priv);
2391
2392 intel_display_set_init_power(dev_priv, false);
2393
2394 - fw_csr = !IS_GEN9_LP(dev_priv) && !hibernation &&
2395 - suspend_to_idle(dev_priv) && dev_priv->csr.dmc_payload;
2396 /*
2397 * In case of firmware assisted context save/restore don't manually
2398 * deinit the power domains. This also means the CSR/DMC firmware will
2399 @@ -1615,8 +1612,11 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation)
2400 * also enable deeper system power states that would be blocked if the
2401 * firmware was inactive.
2402 */
2403 - if (!fw_csr)
2404 + if (IS_GEN9_LP(dev_priv) || hibernation || !suspend_to_idle(dev_priv) ||
2405 + dev_priv->csr.dmc_payload == NULL) {
2406 intel_power_domains_suspend(dev_priv);
2407 + dev_priv->power_domains_suspended = true;
2408 + }
2409
2410 ret = 0;
2411 if (IS_GEN9_LP(dev_priv))
2412 @@ -1628,8 +1628,10 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation)
2413
2414 if (ret) {
2415 DRM_ERROR("Suspend complete failed: %d\n", ret);
2416 - if (!fw_csr)
2417 + if (dev_priv->power_domains_suspended) {
2418 intel_power_domains_init_hw(dev_priv, true);
2419 + dev_priv->power_domains_suspended = false;
2420 + }
2421
2422 goto out;
2423 }
2424 @@ -1650,8 +1652,6 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation)
2425 if (!(hibernation && INTEL_GEN(dev_priv) < 6))
2426 pci_set_power_state(pdev, PCI_D3hot);
2427
2428 - dev_priv->suspended_to_idle = suspend_to_idle(dev_priv);
2429 -
2430 out:
2431 enable_rpm_wakeref_asserts(dev_priv);
2432
2433 @@ -1818,8 +1818,7 @@ static int i915_drm_resume_early(struct drm_device *dev)
2434 intel_uncore_resume_early(dev_priv);
2435
2436 if (IS_GEN9_LP(dev_priv)) {
2437 - if (!dev_priv->suspended_to_idle)
2438 - gen9_sanitize_dc_state(dev_priv);
2439 + gen9_sanitize_dc_state(dev_priv);
2440 bxt_disable_dc9(dev_priv);
2441 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
2442 hsw_disable_pc8(dev_priv);
2443 @@ -1827,8 +1826,7 @@ static int i915_drm_resume_early(struct drm_device *dev)
2444
2445 intel_uncore_sanitize(dev_priv);
2446
2447 - if (IS_GEN9_LP(dev_priv) ||
2448 - !(dev_priv->suspended_to_idle && dev_priv->csr.dmc_payload))
2449 + if (dev_priv->power_domains_suspended)
2450 intel_power_domains_init_hw(dev_priv, true);
2451 else
2452 intel_display_set_init_power(dev_priv, true);
2453 @@ -1838,7 +1836,7 @@ static int i915_drm_resume_early(struct drm_device *dev)
2454 enable_rpm_wakeref_asserts(dev_priv);
2455
2456 out:
2457 - dev_priv->suspended_to_idle = false;
2458 + dev_priv->power_domains_suspended = false;
2459
2460 return ret;
2461 }
2462 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
2463 index d307429a5ae0..55c6d9077a8a 100644
2464 --- a/drivers/gpu/drm/i915/i915_drv.h
2465 +++ b/drivers/gpu/drm/i915/i915_drv.h
2466 @@ -2099,7 +2099,7 @@ struct drm_i915_private {
2467 u32 bxt_phy_grc;
2468
2469 u32 suspend_count;
2470 - bool suspended_to_idle;
2471 + bool power_domains_suspended;
2472 struct i915_suspend_saved_registers regfile;
2473 struct vlv_s0ix_state vlv_s0ix_state;
2474
2475 diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
2476 index 33eb0c5b1d32..175d552c8bae 100644
2477 --- a/drivers/gpu/drm/i915/i915_reg.h
2478 +++ b/drivers/gpu/drm/i915/i915_reg.h
2479 @@ -6236,6 +6236,12 @@ enum {
2480 #define _SPATILEOFF (VLV_DISPLAY_BASE + 0x721a4)
2481 #define _SPACONSTALPHA (VLV_DISPLAY_BASE + 0x721a8)
2482 #define SP_CONST_ALPHA_ENABLE (1<<31)
2483 +#define _SPACLRC0 (VLV_DISPLAY_BASE + 0x721d0)
2484 +#define SP_CONTRAST(x) ((x) << 18) /* u3.6 */
2485 +#define SP_BRIGHTNESS(x) ((x) & 0xff) /* s8 */
2486 +#define _SPACLRC1 (VLV_DISPLAY_BASE + 0x721d4)
2487 +#define SP_SH_SIN(x) (((x) & 0x7ff) << 16) /* s4.7 */
2488 +#define SP_SH_COS(x) (x) /* u3.7 */
2489 #define _SPAGAMC (VLV_DISPLAY_BASE + 0x721f4)
2490
2491 #define _SPBCNTR (VLV_DISPLAY_BASE + 0x72280)
2492 @@ -6249,6 +6255,8 @@ enum {
2493 #define _SPBKEYMAXVAL (VLV_DISPLAY_BASE + 0x722a0)
2494 #define _SPBTILEOFF (VLV_DISPLAY_BASE + 0x722a4)
2495 #define _SPBCONSTALPHA (VLV_DISPLAY_BASE + 0x722a8)
2496 +#define _SPBCLRC0 (VLV_DISPLAY_BASE + 0x722d0)
2497 +#define _SPBCLRC1 (VLV_DISPLAY_BASE + 0x722d4)
2498 #define _SPBGAMC (VLV_DISPLAY_BASE + 0x722f4)
2499
2500 #define _MMIO_VLV_SPR(pipe, plane_id, reg_a, reg_b) \
2501 @@ -6265,6 +6273,8 @@ enum {
2502 #define SPKEYMAXVAL(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPAKEYMAXVAL, _SPBKEYMAXVAL)
2503 #define SPTILEOFF(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPATILEOFF, _SPBTILEOFF)
2504 #define SPCONSTALPHA(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPACONSTALPHA, _SPBCONSTALPHA)
2505 +#define SPCLRC0(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPACLRC0, _SPBCLRC0)
2506 +#define SPCLRC1(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPACLRC1, _SPBCLRC1)
2507 #define SPGAMC(pipe, plane_id) _MMIO_VLV_SPR((pipe), (plane_id), _SPAGAMC, _SPBGAMC)
2508
2509 /*
2510 diff --git a/drivers/gpu/drm/i915/intel_sprite.c b/drivers/gpu/drm/i915/intel_sprite.c
2511 index dd485f59eb1d..fb95074a67ff 100644
2512 --- a/drivers/gpu/drm/i915/intel_sprite.c
2513 +++ b/drivers/gpu/drm/i915/intel_sprite.c
2514 @@ -346,44 +346,87 @@ skl_plane_get_hw_state(struct intel_plane *plane)
2515 }
2516
2517 static void
2518 -chv_update_csc(struct intel_plane *plane, uint32_t format)
2519 +chv_update_csc(const struct intel_plane_state *plane_state)
2520 {
2521 + struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2522 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2523 + const struct drm_framebuffer *fb = plane_state->base.fb;
2524 enum plane_id plane_id = plane->id;
2525
2526 /* Seems RGB data bypasses the CSC always */
2527 - if (!format_is_yuv(format))
2528 + if (!format_is_yuv(fb->format->format))
2529 return;
2530
2531 /*
2532 - * BT.601 limited range YCbCr -> full range RGB
2533 + * BT.601 full range YCbCr -> full range RGB
2534 *
2535 - * |r| | 6537 4769 0| |cr |
2536 - * |g| = |-3330 4769 -1605| x |y-64|
2537 - * |b| | 0 4769 8263| |cb |
2538 + * |r| | 5743 4096 0| |cr|
2539 + * |g| = |-2925 4096 -1410| x |y |
2540 + * |b| | 0 4096 7258| |cb|
2541 *
2542 - * Cb and Cr apparently come in as signed already, so no
2543 - * need for any offset. For Y we need to remove the offset.
2544 + * Cb and Cr apparently come in as signed already,
2545 + * and we get full range data in on account of CLRC0/1
2546 */
2547 - I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
2548 + I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
2549 I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
2550 I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
2551
2552 - I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(4769) | SPCSC_C0(6537));
2553 - I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(-3330) | SPCSC_C0(0));
2554 - I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(-1605) | SPCSC_C0(4769));
2555 - I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(4769) | SPCSC_C0(0));
2556 - I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(8263));
2557 + I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(4096) | SPCSC_C0(5743));
2558 + I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(-2925) | SPCSC_C0(0));
2559 + I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(-1410) | SPCSC_C0(4096));
2560 + I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(4096) | SPCSC_C0(0));
2561 + I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(7258));
2562
2563 - I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(940) | SPCSC_IMIN(64));
2564 - I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
2565 - I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
2566 + I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(1023) | SPCSC_IMIN(0));
2567 + I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
2568 + I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
2569
2570 I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
2571 I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
2572 I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
2573 }
2574
2575 +#define SIN_0 0
2576 +#define COS_0 1
2577 +
2578 +static void
2579 +vlv_update_clrc(const struct intel_plane_state *plane_state)
2580 +{
2581 + struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2582 + struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2583 + const struct drm_framebuffer *fb = plane_state->base.fb;
2584 + enum pipe pipe = plane->pipe;
2585 + enum plane_id plane_id = plane->id;
2586 + int contrast, brightness, sh_scale, sh_sin, sh_cos;
2587 +
2588 + if (format_is_yuv(fb->format->format)) {
2589 + /*
2590 + * Expand limited range to full range:
2591 + * Contrast is applied first and is used to expand Y range.
2592 + * Brightness is applied second and is used to remove the
2593 + * offset from Y. Saturation/hue is used to expand CbCr range.
2594 + */
2595 + contrast = DIV_ROUND_CLOSEST(255 << 6, 235 - 16);
2596 + brightness = -DIV_ROUND_CLOSEST(16 * 255, 235 - 16);
2597 + sh_scale = DIV_ROUND_CLOSEST(128 << 7, 240 - 128);
2598 + sh_sin = SIN_0 * sh_scale;
2599 + sh_cos = COS_0 * sh_scale;
2600 + } else {
2601 + /* Pass-through everything. */
2602 + contrast = 1 << 6;
2603 + brightness = 0;
2604 + sh_scale = 1 << 7;
2605 + sh_sin = SIN_0 * sh_scale;
2606 + sh_cos = COS_0 * sh_scale;
2607 + }
2608 +
2609 + /* FIXME these register are single buffered :( */
2610 + I915_WRITE_FW(SPCLRC0(pipe, plane_id),
2611 + SP_CONTRAST(contrast) | SP_BRIGHTNESS(brightness));
2612 + I915_WRITE_FW(SPCLRC1(pipe, plane_id),
2613 + SP_SH_SIN(sh_sin) | SP_SH_COS(sh_cos));
2614 +}
2615 +
2616 static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
2617 const struct intel_plane_state *plane_state)
2618 {
2619 @@ -477,8 +520,10 @@ vlv_update_plane(struct intel_plane *plane,
2620
2621 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
2622
2623 + vlv_update_clrc(plane_state);
2624 +
2625 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
2626 - chv_update_csc(plane, fb->format->format);
2627 + chv_update_csc(plane_state);
2628
2629 if (key->flags) {
2630 I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
2631 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
2632 index 7828a5e10629..0bbc23175d49 100644
2633 --- a/drivers/gpu/drm/radeon/radeon_device.c
2634 +++ b/drivers/gpu/drm/radeon/radeon_device.c
2635 @@ -139,6 +139,10 @@ static struct radeon_px_quirk radeon_px_quirk_list[] = {
2636 * https://bugs.freedesktop.org/show_bug.cgi?id=101491
2637 */
2638 { PCI_VENDOR_ID_ATI, 0x6741, 0x1043, 0x2122, RADEON_PX_QUIRK_DISABLE_PX },
2639 + /* Asus K73TK laptop with AMD A6-3420M APU and Radeon 7670m GPU
2640 + * https://bugzilla.kernel.org/show_bug.cgi?id=51381#c52
2641 + */
2642 + { PCI_VENDOR_ID_ATI, 0x6840, 0x1043, 0x2123, RADEON_PX_QUIRK_DISABLE_PX },
2643 { 0, 0, 0, 0, 0 },
2644 };
2645
2646 diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c
2647 index 97a0a639dad9..90d5b41007bf 100644
2648 --- a/drivers/gpu/drm/radeon/si_dpm.c
2649 +++ b/drivers/gpu/drm/radeon/si_dpm.c
2650 @@ -5912,9 +5912,9 @@ static void si_set_pcie_lane_width_in_smc(struct radeon_device *rdev,
2651 {
2652 u32 lane_width;
2653 u32 new_lane_width =
2654 - (radeon_new_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT;
2655 + ((radeon_new_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
2656 u32 current_lane_width =
2657 - (radeon_current_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT;
2658 + ((radeon_current_state->caps & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
2659
2660 if (new_lane_width != current_lane_width) {
2661 radeon_set_pcie_lanes(rdev, new_lane_width);
2662 diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
2663 index ba7505292b78..7b224e08cbf1 100644
2664 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
2665 +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
2666 @@ -1414,6 +1414,9 @@ static int vop_initial(struct vop *vop)
2667 usleep_range(10, 20);
2668 reset_control_deassert(ahb_rst);
2669
2670 + VOP_INTR_SET_TYPE(vop, clear, INTR_MASK, 1);
2671 + VOP_INTR_SET_TYPE(vop, enable, INTR_MASK, 0);
2672 +
2673 memcpy(vop->regsbak, vop->regs, vop->len);
2674
2675 VOP_REG_SET(vop, misc, global_regdone_en, 1);
2676 @@ -1569,17 +1572,9 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
2677
2678 mutex_init(&vop->vsync_mutex);
2679
2680 - ret = devm_request_irq(dev, vop->irq, vop_isr,
2681 - IRQF_SHARED, dev_name(dev), vop);
2682 - if (ret)
2683 - return ret;
2684 -
2685 - /* IRQ is initially disabled; it gets enabled in power_on */
2686 - disable_irq(vop->irq);
2687 -
2688 ret = vop_create_crtc(vop);
2689 if (ret)
2690 - goto err_enable_irq;
2691 + return ret;
2692
2693 pm_runtime_enable(&pdev->dev);
2694
2695 @@ -1590,13 +1585,19 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
2696 goto err_disable_pm_runtime;
2697 }
2698
2699 + ret = devm_request_irq(dev, vop->irq, vop_isr,
2700 + IRQF_SHARED, dev_name(dev), vop);
2701 + if (ret)
2702 + goto err_disable_pm_runtime;
2703 +
2704 + /* IRQ is initially disabled; it gets enabled in power_on */
2705 + disable_irq(vop->irq);
2706 +
2707 return 0;
2708
2709 err_disable_pm_runtime:
2710 pm_runtime_disable(&pdev->dev);
2711 vop_destroy_crtc(vop);
2712 -err_enable_irq:
2713 - enable_irq(vop->irq); /* To balance out the disable_irq above */
2714 return ret;
2715 }
2716
2717 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
2718 index c2560aae5542..4fc08c38bc0e 100644
2719 --- a/drivers/hid/hid-core.c
2720 +++ b/drivers/hid/hid-core.c
2721 @@ -1365,7 +1365,7 @@ u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags)
2722 * of implement() working on 8 byte chunks
2723 */
2724
2725 - int len = hid_report_len(report) + 7;
2726 + u32 len = hid_report_len(report) + 7;
2727
2728 return kmalloc(len, flags);
2729 }
2730 @@ -1430,7 +1430,7 @@ void __hid_request(struct hid_device *hid, struct hid_report *report,
2731 {
2732 char *buf;
2733 int ret;
2734 - int len;
2735 + u32 len;
2736
2737 buf = hid_alloc_report_buf(report, GFP_KERNEL);
2738 if (!buf)
2739 @@ -1456,14 +1456,14 @@ void __hid_request(struct hid_device *hid, struct hid_report *report,
2740 }
2741 EXPORT_SYMBOL_GPL(__hid_request);
2742
2743 -int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
2744 +int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size,
2745 int interrupt)
2746 {
2747 struct hid_report_enum *report_enum = hid->report_enum + type;
2748 struct hid_report *report;
2749 struct hid_driver *hdrv;
2750 unsigned int a;
2751 - int rsize, csize = size;
2752 + u32 rsize, csize = size;
2753 u8 *cdata = data;
2754 int ret = 0;
2755
2756 @@ -1521,7 +1521,7 @@ EXPORT_SYMBOL_GPL(hid_report_raw_event);
2757 *
2758 * This is data entry for lower layers.
2759 */
2760 -int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
2761 +int hid_input_report(struct hid_device *hid, int type, u8 *data, u32 size, int interrupt)
2762 {
2763 struct hid_report_enum *report_enum;
2764 struct hid_driver *hdrv;
2765 diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
2766 index 9454ac134ce2..c631d2c8988d 100644
2767 --- a/drivers/hid/hid-ids.h
2768 +++ b/drivers/hid/hid-ids.h
2769 @@ -519,6 +519,9 @@
2770 #define I2C_VENDOR_ID_HANTICK 0x0911
2771 #define I2C_PRODUCT_ID_HANTICK_5288 0x5288
2772
2773 +#define I2C_VENDOR_ID_RAYD 0x2386
2774 +#define I2C_PRODUCT_ID_RAYD_3118 0x3118
2775 +
2776 #define USB_VENDOR_ID_HANWANG 0x0b57
2777 #define USB_DEVICE_ID_HANWANG_TABLET_FIRST 0x5000
2778 #define USB_DEVICE_ID_HANWANG_TABLET_LAST 0x8fff
2779 diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
2780 index 04d01b57d94c..0b9e06569bf5 100644
2781 --- a/drivers/hid/hid-input.c
2782 +++ b/drivers/hid/hid-input.c
2783 @@ -387,7 +387,8 @@ static int hidinput_get_battery_property(struct power_supply *psy,
2784 break;
2785
2786 case POWER_SUPPLY_PROP_CAPACITY:
2787 - if (dev->battery_report_type == HID_FEATURE_REPORT) {
2788 + if (dev->battery_status != HID_BATTERY_REPORTED &&
2789 + !dev->battery_avoid_query) {
2790 value = hidinput_query_battery_capacity(dev);
2791 if (value < 0)
2792 return value;
2793 @@ -403,17 +404,17 @@ static int hidinput_get_battery_property(struct power_supply *psy,
2794 break;
2795
2796 case POWER_SUPPLY_PROP_STATUS:
2797 - if (!dev->battery_reported &&
2798 - dev->battery_report_type == HID_FEATURE_REPORT) {
2799 + if (dev->battery_status != HID_BATTERY_REPORTED &&
2800 + !dev->battery_avoid_query) {
2801 value = hidinput_query_battery_capacity(dev);
2802 if (value < 0)
2803 return value;
2804
2805 dev->battery_capacity = value;
2806 - dev->battery_reported = true;
2807 + dev->battery_status = HID_BATTERY_QUERIED;
2808 }
2809
2810 - if (!dev->battery_reported)
2811 + if (dev->battery_status == HID_BATTERY_UNKNOWN)
2812 val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
2813 else if (dev->battery_capacity == 100)
2814 val->intval = POWER_SUPPLY_STATUS_FULL;
2815 @@ -486,6 +487,14 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
2816 dev->battery_report_type = report_type;
2817 dev->battery_report_id = field->report->id;
2818
2819 + /*
2820 + * Stylus is normally not connected to the device and thus we
2821 + * can't query the device and get meaningful battery strength.
2822 + * We have to wait for the device to report it on its own.
2823 + */
2824 + dev->battery_avoid_query = report_type == HID_INPUT_REPORT &&
2825 + field->physical == HID_DG_STYLUS;
2826 +
2827 dev->battery = power_supply_register(&dev->dev, psy_desc, &psy_cfg);
2828 if (IS_ERR(dev->battery)) {
2829 error = PTR_ERR(dev->battery);
2830 @@ -530,9 +539,10 @@ static void hidinput_update_battery(struct hid_device *dev, int value)
2831
2832 capacity = hidinput_scale_battery_capacity(dev, value);
2833
2834 - if (!dev->battery_reported || capacity != dev->battery_capacity) {
2835 + if (dev->battery_status != HID_BATTERY_REPORTED ||
2836 + capacity != dev->battery_capacity) {
2837 dev->battery_capacity = capacity;
2838 - dev->battery_reported = true;
2839 + dev->battery_status = HID_BATTERY_REPORTED;
2840 power_supply_changed(dev->battery);
2841 }
2842 }
2843 @@ -1368,7 +1378,8 @@ static void hidinput_led_worker(struct work_struct *work)
2844 led_work);
2845 struct hid_field *field;
2846 struct hid_report *report;
2847 - int len, ret;
2848 + int ret;
2849 + u32 len;
2850 __u8 *buf;
2851
2852 field = hidinput_get_led_field(hid);
2853 diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
2854 index 3b4739bde05d..2e1736ba2444 100644
2855 --- a/drivers/hid/hid-multitouch.c
2856 +++ b/drivers/hid/hid-multitouch.c
2857 @@ -370,7 +370,8 @@ static const struct attribute_group mt_attribute_group = {
2858 static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
2859 {
2860 struct mt_device *td = hid_get_drvdata(hdev);
2861 - int ret, size = hid_report_len(report);
2862 + int ret;
2863 + u32 size = hid_report_len(report);
2864 u8 *buf;
2865
2866 /*
2867 @@ -1183,7 +1184,7 @@ static void mt_set_input_mode(struct hid_device *hdev)
2868 struct hid_report_enum *re;
2869 struct mt_class *cls = &td->mtclass;
2870 char *buf;
2871 - int report_len;
2872 + u32 report_len;
2873
2874 if (td->inputmode < 0)
2875 return;
2876 diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
2877 index c6c05df3e8d2..9c9362149641 100644
2878 --- a/drivers/hid/hid-rmi.c
2879 +++ b/drivers/hid/hid-rmi.c
2880 @@ -89,8 +89,8 @@ struct rmi_data {
2881 u8 *writeReport;
2882 u8 *readReport;
2883
2884 - int input_report_size;
2885 - int output_report_size;
2886 + u32 input_report_size;
2887 + u32 output_report_size;
2888
2889 unsigned long flags;
2890
2891 diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
2892 index fbfcc8009432..b39844adea47 100644
2893 --- a/drivers/hid/hidraw.c
2894 +++ b/drivers/hid/hidraw.c
2895 @@ -192,6 +192,11 @@ static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t
2896 int ret = 0, len;
2897 unsigned char report_number;
2898
2899 + if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
2900 + ret = -ENODEV;
2901 + goto out;
2902 + }
2903 +
2904 dev = hidraw_table[minor]->hid;
2905
2906 if (!dev->ll_driver->raw_request) {
2907 diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
2908 index 7230243b94d3..fd9f70a8b813 100644
2909 --- a/drivers/hid/i2c-hid/i2c-hid.c
2910 +++ b/drivers/hid/i2c-hid/i2c-hid.c
2911 @@ -47,6 +47,7 @@
2912 /* quirks to control the device */
2913 #define I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV BIT(0)
2914 #define I2C_HID_QUIRK_NO_IRQ_AFTER_RESET BIT(1)
2915 +#define I2C_HID_QUIRK_RESEND_REPORT_DESCR BIT(2)
2916
2917 /* flags */
2918 #define I2C_HID_STARTED 0
2919 @@ -144,10 +145,10 @@ struct i2c_hid {
2920 * register of the HID
2921 * descriptor. */
2922 unsigned int bufsize; /* i2c buffer size */
2923 - char *inbuf; /* Input buffer */
2924 - char *rawbuf; /* Raw Input buffer */
2925 - char *cmdbuf; /* Command buffer */
2926 - char *argsbuf; /* Command arguments buffer */
2927 + u8 *inbuf; /* Input buffer */
2928 + u8 *rawbuf; /* Raw Input buffer */
2929 + u8 *cmdbuf; /* Command buffer */
2930 + u8 *argsbuf; /* Command arguments buffer */
2931
2932 unsigned long flags; /* device flags */
2933 unsigned long quirks; /* Various quirks */
2934 @@ -171,6 +172,8 @@ static const struct i2c_hid_quirks {
2935 I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
2936 { I2C_VENDOR_ID_HANTICK, I2C_PRODUCT_ID_HANTICK_5288,
2937 I2C_HID_QUIRK_NO_IRQ_AFTER_RESET },
2938 + { I2C_VENDOR_ID_RAYD, I2C_PRODUCT_ID_RAYD_3118,
2939 + I2C_HID_QUIRK_RESEND_REPORT_DESCR },
2940 { 0, 0 }
2941 };
2942
2943 @@ -455,7 +458,8 @@ static int i2c_hid_hwreset(struct i2c_client *client)
2944
2945 static void i2c_hid_get_input(struct i2c_hid *ihid)
2946 {
2947 - int ret, ret_size;
2948 + int ret;
2949 + u32 ret_size;
2950 int size = le16_to_cpu(ihid->hdesc.wMaxInputLength);
2951
2952 if (size > ihid->bufsize)
2953 @@ -480,7 +484,7 @@ static void i2c_hid_get_input(struct i2c_hid *ihid)
2954 return;
2955 }
2956
2957 - if (ret_size > size) {
2958 + if ((ret_size > size) || (ret_size <= 2)) {
2959 dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n",
2960 __func__, size, ret_size);
2961 return;
2962 @@ -1219,6 +1223,16 @@ static int i2c_hid_resume(struct device *dev)
2963 if (ret)
2964 return ret;
2965
2966 + /* RAYDIUM device (2386:3118) need to re-send report descr cmd
2967 + * after resume, after this it will be back normal.
2968 + * otherwise it issues too many incomplete reports.
2969 + */
2970 + if (ihid->quirks & I2C_HID_QUIRK_RESEND_REPORT_DESCR) {
2971 + ret = i2c_hid_command(client, &hid_report_descr_cmd, NULL, 0);
2972 + if (ret)
2973 + return ret;
2974 + }
2975 +
2976 if (hid->driver && hid->driver->reset_resume) {
2977 ret = hid->driver->reset_resume(hid);
2978 return ret;
2979 diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
2980 index 409543160af7..b54ef1ffcbec 100644
2981 --- a/drivers/hid/wacom_sys.c
2982 +++ b/drivers/hid/wacom_sys.c
2983 @@ -219,7 +219,7 @@ static void wacom_feature_mapping(struct hid_device *hdev,
2984 unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
2985 u8 *data;
2986 int ret;
2987 - int n;
2988 + u32 n;
2989
2990 switch (equivalent_usage) {
2991 case HID_DG_CONTACTMAX:
2992 @@ -519,7 +519,7 @@ static int wacom_set_device_mode(struct hid_device *hdev,
2993 u8 *rep_data;
2994 struct hid_report *r;
2995 struct hid_report_enum *re;
2996 - int length;
2997 + u32 length;
2998 int error = -ENOMEM, limit = 0;
2999
3000 if (wacom_wac->mode_report < 0)
3001 diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
3002 index 90c38a0523e9..44b2c7b0838c 100644
3003 --- a/drivers/hid/wacom_wac.c
3004 +++ b/drivers/hid/wacom_wac.c
3005 @@ -689,6 +689,45 @@ static int wacom_intuos_get_tool_type(int tool_id)
3006 return tool_type;
3007 }
3008
3009 +static void wacom_exit_report(struct wacom_wac *wacom)
3010 +{
3011 + struct input_dev *input = wacom->pen_input;
3012 + struct wacom_features *features = &wacom->features;
3013 + unsigned char *data = wacom->data;
3014 + int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
3015 +
3016 + /*
3017 + * Reset all states otherwise we lose the initial states
3018 + * when in-prox next time
3019 + */
3020 + input_report_abs(input, ABS_X, 0);
3021 + input_report_abs(input, ABS_Y, 0);
3022 + input_report_abs(input, ABS_DISTANCE, 0);
3023 + input_report_abs(input, ABS_TILT_X, 0);
3024 + input_report_abs(input, ABS_TILT_Y, 0);
3025 + if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
3026 + input_report_key(input, BTN_LEFT, 0);
3027 + input_report_key(input, BTN_MIDDLE, 0);
3028 + input_report_key(input, BTN_RIGHT, 0);
3029 + input_report_key(input, BTN_SIDE, 0);
3030 + input_report_key(input, BTN_EXTRA, 0);
3031 + input_report_abs(input, ABS_THROTTLE, 0);
3032 + input_report_abs(input, ABS_RZ, 0);
3033 + } else {
3034 + input_report_abs(input, ABS_PRESSURE, 0);
3035 + input_report_key(input, BTN_STYLUS, 0);
3036 + input_report_key(input, BTN_STYLUS2, 0);
3037 + input_report_key(input, BTN_TOUCH, 0);
3038 + input_report_abs(input, ABS_WHEEL, 0);
3039 + if (features->type >= INTUOS3S)
3040 + input_report_abs(input, ABS_Z, 0);
3041 + }
3042 + input_report_key(input, wacom->tool[idx], 0);
3043 + input_report_abs(input, ABS_MISC, 0); /* reset tool id */
3044 + input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
3045 + wacom->id[idx] = 0;
3046 +}
3047 +
3048 static int wacom_intuos_inout(struct wacom_wac *wacom)
3049 {
3050 struct wacom_features *features = &wacom->features;
3051 @@ -741,36 +780,7 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
3052 if (!wacom->id[idx])
3053 return 1;
3054
3055 - /*
3056 - * Reset all states otherwise we lose the initial states
3057 - * when in-prox next time
3058 - */
3059 - input_report_abs(input, ABS_X, 0);
3060 - input_report_abs(input, ABS_Y, 0);
3061 - input_report_abs(input, ABS_DISTANCE, 0);
3062 - input_report_abs(input, ABS_TILT_X, 0);
3063 - input_report_abs(input, ABS_TILT_Y, 0);
3064 - if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
3065 - input_report_key(input, BTN_LEFT, 0);
3066 - input_report_key(input, BTN_MIDDLE, 0);
3067 - input_report_key(input, BTN_RIGHT, 0);
3068 - input_report_key(input, BTN_SIDE, 0);
3069 - input_report_key(input, BTN_EXTRA, 0);
3070 - input_report_abs(input, ABS_THROTTLE, 0);
3071 - input_report_abs(input, ABS_RZ, 0);
3072 - } else {
3073 - input_report_abs(input, ABS_PRESSURE, 0);
3074 - input_report_key(input, BTN_STYLUS, 0);
3075 - input_report_key(input, BTN_STYLUS2, 0);
3076 - input_report_key(input, BTN_TOUCH, 0);
3077 - input_report_abs(input, ABS_WHEEL, 0);
3078 - if (features->type >= INTUOS3S)
3079 - input_report_abs(input, ABS_Z, 0);
3080 - }
3081 - input_report_key(input, wacom->tool[idx], 0);
3082 - input_report_abs(input, ABS_MISC, 0); /* reset tool id */
3083 - input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
3084 - wacom->id[idx] = 0;
3085 + wacom_exit_report(wacom);
3086 return 2;
3087 }
3088
3089 @@ -1226,6 +1236,12 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
3090 if (!valid)
3091 continue;
3092
3093 + if (!prox) {
3094 + wacom->shared->stylus_in_proximity = false;
3095 + wacom_exit_report(wacom);
3096 + input_sync(pen_input);
3097 + return;
3098 + }
3099 if (range) {
3100 /* Fix rotation alignment: userspace expects zero at left */
3101 int16_t rotation = (int16_t)get_unaligned_le16(&frame[9]);
3102 diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
3103 index 692b34125866..e0d59e9ff3c6 100644
3104 --- a/drivers/i2c/busses/i2c-i801.c
3105 +++ b/drivers/i2c/busses/i2c-i801.c
3106 @@ -966,8 +966,6 @@ static void i801_enable_host_notify(struct i2c_adapter *adapter)
3107 if (!(priv->features & FEATURE_HOST_NOTIFY))
3108 return;
3109
3110 - priv->original_slvcmd = inb_p(SMBSLVCMD(priv));
3111 -
3112 if (!(SMBSLVCMD_HST_NTFY_INTREN & priv->original_slvcmd))
3113 outb_p(SMBSLVCMD_HST_NTFY_INTREN | priv->original_slvcmd,
3114 SMBSLVCMD(priv));
3115 @@ -1615,6 +1613,10 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
3116 outb_p(inb_p(SMBAUXCTL(priv)) &
3117 ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
3118
3119 + /* Remember original Host Notify setting */
3120 + if (priv->features & FEATURE_HOST_NOTIFY)
3121 + priv->original_slvcmd = inb_p(SMBSLVCMD(priv));
3122 +
3123 /* Default timeout in interrupt mode: 200 ms */
3124 priv->adapter.timeout = HZ / 5;
3125
3126 @@ -1699,6 +1701,15 @@ static void i801_remove(struct pci_dev *dev)
3127 */
3128 }
3129
3130 +static void i801_shutdown(struct pci_dev *dev)
3131 +{
3132 + struct i801_priv *priv = pci_get_drvdata(dev);
3133 +
3134 + /* Restore config registers to avoid hard hang on some systems */
3135 + i801_disable_host_notify(priv);
3136 + pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
3137 +}
3138 +
3139 #ifdef CONFIG_PM
3140 static int i801_suspend(struct device *dev)
3141 {
3142 @@ -1728,6 +1739,7 @@ static struct pci_driver i801_driver = {
3143 .id_table = i801_ids,
3144 .probe = i801_probe,
3145 .remove = i801_remove,
3146 + .shutdown = i801_shutdown,
3147 .driver = {
3148 .pm = &i801_pm_ops,
3149 },
3150 diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
3151 index d933336d7e01..5c21ae237f82 100644
3152 --- a/drivers/infiniband/core/ucma.c
3153 +++ b/drivers/infiniband/core/ucma.c
3154 @@ -1241,6 +1241,9 @@ static int ucma_set_ib_path(struct ucma_context *ctx,
3155 if (!optlen)
3156 return -EINVAL;
3157
3158 + if (!ctx->cm_id->device)
3159 + return -EINVAL;
3160 +
3161 memset(&sa_path, 0, sizeof(sa_path));
3162
3163 sa_path.rec_type = SA_PATH_REC_TYPE_IB;
3164 diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
3165 index 93025d2009b8..c715123742a4 100644
3166 --- a/drivers/infiniband/core/verbs.c
3167 +++ b/drivers/infiniband/core/verbs.c
3168 @@ -2194,7 +2194,14 @@ static void __ib_drain_sq(struct ib_qp *qp)
3169 struct ib_cq *cq = qp->send_cq;
3170 struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR };
3171 struct ib_drain_cqe sdrain;
3172 - struct ib_send_wr swr = {}, *bad_swr;
3173 + struct ib_send_wr *bad_swr;
3174 + struct ib_rdma_wr swr = {
3175 + .wr = {
3176 + .next = NULL,
3177 + { .wr_cqe = &sdrain.cqe, },
3178 + .opcode = IB_WR_RDMA_WRITE,
3179 + },
3180 + };
3181 int ret;
3182
3183 ret = ib_modify_qp(qp, &attr, IB_QP_STATE);
3184 @@ -2203,11 +2210,10 @@ static void __ib_drain_sq(struct ib_qp *qp)
3185 return;
3186 }
3187
3188 - swr.wr_cqe = &sdrain.cqe;
3189 sdrain.cqe.done = ib_drain_qp_done;
3190 init_completion(&sdrain.done);
3191
3192 - ret = ib_post_send(qp, &swr, &bad_swr);
3193 + ret = ib_post_send(qp, &swr.wr, &bad_swr);
3194 if (ret) {
3195 WARN_ONCE(ret, "failed to drain send queue: %d\n", ret);
3196 return;
3197 diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
3198 index 3e0b3f0238d6..6857c61bdee1 100644
3199 --- a/drivers/infiniband/hw/mlx5/mr.c
3200 +++ b/drivers/infiniband/hw/mlx5/mr.c
3201 @@ -1223,6 +1223,8 @@ struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
3202 return ERR_PTR(-EINVAL);
3203
3204 mr = mlx5_ib_alloc_implicit_mr(to_mpd(pd), access_flags);
3205 + if (IS_ERR(mr))
3206 + return ERR_CAST(mr);
3207 return &mr->ibmr;
3208 }
3209 #endif
3210 diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
3211 index f4bab2cd0ec2..45594091353c 100644
3212 --- a/drivers/infiniband/sw/rxe/rxe_verbs.c
3213 +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
3214 @@ -711,9 +711,8 @@ static int init_send_wqe(struct rxe_qp *qp, struct ib_send_wr *ibwr,
3215 memcpy(wqe->dma.sge, ibwr->sg_list,
3216 num_sge * sizeof(struct ib_sge));
3217
3218 - wqe->iova = (mask & WR_ATOMIC_MASK) ?
3219 - atomic_wr(ibwr)->remote_addr :
3220 - rdma_wr(ibwr)->remote_addr;
3221 + wqe->iova = mask & WR_ATOMIC_MASK ? atomic_wr(ibwr)->remote_addr :
3222 + mask & WR_READ_OR_WRITE_MASK ? rdma_wr(ibwr)->remote_addr : 0;
3223 wqe->mask = mask;
3224 wqe->dma.length = length;
3225 wqe->dma.resid = length;
3226 diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
3227 index b48843833d69..4a1a489ce8bb 100644
3228 --- a/drivers/infiniband/ulp/srp/ib_srp.c
3229 +++ b/drivers/infiniband/ulp/srp/ib_srp.c
3230 @@ -2974,9 +2974,11 @@ static int srp_abort(struct scsi_cmnd *scmnd)
3231 ret = FAST_IO_FAIL;
3232 else
3233 ret = FAILED;
3234 - srp_free_req(ch, req, scmnd, 0);
3235 - scmnd->result = DID_ABORT << 16;
3236 - scmnd->scsi_done(scmnd);
3237 + if (ret == SUCCESS) {
3238 + srp_free_req(ch, req, scmnd, 0);
3239 + scmnd->result = DID_ABORT << 16;
3240 + scmnd->scsi_done(scmnd);
3241 + }
3242
3243 return ret;
3244 }
3245 @@ -3871,12 +3873,10 @@ static ssize_t srp_create_target(struct device *dev,
3246 num_online_nodes());
3247 const int ch_end = ((node_idx + 1) * target->ch_count /
3248 num_online_nodes());
3249 - const int cv_start = (node_idx * ibdev->num_comp_vectors /
3250 - num_online_nodes() + target->comp_vector)
3251 - % ibdev->num_comp_vectors;
3252 - const int cv_end = ((node_idx + 1) * ibdev->num_comp_vectors /
3253 - num_online_nodes() + target->comp_vector)
3254 - % ibdev->num_comp_vectors;
3255 + const int cv_start = node_idx * ibdev->num_comp_vectors /
3256 + num_online_nodes();
3257 + const int cv_end = (node_idx + 1) * ibdev->num_comp_vectors /
3258 + num_online_nodes();
3259 int cpu_idx = 0;
3260
3261 for_each_online_cpu(cpu) {
3262 diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
3263 index 0373b7c40902..f1be280e701a 100644
3264 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c
3265 +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
3266 @@ -838,16 +838,20 @@ static int srpt_post_recv(struct srpt_device *sdev, struct srpt_rdma_ch *ch,
3267 */
3268 static int srpt_zerolength_write(struct srpt_rdma_ch *ch)
3269 {
3270 - struct ib_send_wr wr, *bad_wr;
3271 + struct ib_send_wr *bad_wr;
3272 + struct ib_rdma_wr wr = {
3273 + .wr = {
3274 + .next = NULL,
3275 + { .wr_cqe = &ch->zw_cqe, },
3276 + .opcode = IB_WR_RDMA_WRITE,
3277 + .send_flags = IB_SEND_SIGNALED,
3278 + }
3279 + };
3280
3281 pr_debug("%s-%d: queued zerolength write\n", ch->sess_name,
3282 ch->qp->qp_num);
3283
3284 - memset(&wr, 0, sizeof(wr));
3285 - wr.opcode = IB_WR_RDMA_WRITE;
3286 - wr.wr_cqe = &ch->zw_cqe;
3287 - wr.send_flags = IB_SEND_SIGNALED;
3288 - return ib_post_send(ch->qp, &wr, &bad_wr);
3289 + return ib_post_send(ch->qp, &wr.wr, &bad_wr);
3290 }
3291
3292 static void srpt_zerolength_write_done(struct ib_cq *cq, struct ib_wc *wc)
3293 diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c
3294 index 99bc9bd64b9e..9124a625fe83 100644
3295 --- a/drivers/iommu/intel-svm.c
3296 +++ b/drivers/iommu/intel-svm.c
3297 @@ -396,6 +396,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_
3298 pasid_max - 1, GFP_KERNEL);
3299 if (ret < 0) {
3300 kfree(svm);
3301 + kfree(sdev);
3302 goto out;
3303 }
3304 svm->pasid = ret;
3305 diff --git a/drivers/irqchip/irq-gic-common.c b/drivers/irqchip/irq-gic-common.c
3306 index 30017df5b54c..01e673c680cd 100644
3307 --- a/drivers/irqchip/irq-gic-common.c
3308 +++ b/drivers/irqchip/irq-gic-common.c
3309 @@ -21,6 +21,8 @@
3310
3311 #include "irq-gic-common.h"
3312
3313 +static DEFINE_RAW_SPINLOCK(irq_controller_lock);
3314 +
3315 static const struct gic_kvm_info *gic_kvm_info;
3316
3317 const struct gic_kvm_info *gic_get_kvm_info(void)
3318 @@ -53,11 +55,13 @@ int gic_configure_irq(unsigned int irq, unsigned int type,
3319 u32 confoff = (irq / 16) * 4;
3320 u32 val, oldval;
3321 int ret = 0;
3322 + unsigned long flags;
3323
3324 /*
3325 * Read current configuration register, and insert the config
3326 * for "irq", depending on "type".
3327 */
3328 + raw_spin_lock_irqsave(&irq_controller_lock, flags);
3329 val = oldval = readl_relaxed(base + GIC_DIST_CONFIG + confoff);
3330 if (type & IRQ_TYPE_LEVEL_MASK)
3331 val &= ~confmask;
3332 @@ -65,8 +69,10 @@ int gic_configure_irq(unsigned int irq, unsigned int type,
3333 val |= confmask;
3334
3335 /* If the current configuration is the same, then we are done */
3336 - if (val == oldval)
3337 + if (val == oldval) {
3338 + raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
3339 return 0;
3340 + }
3341
3342 /*
3343 * Write back the new configuration, and possibly re-enable
3344 @@ -84,6 +90,7 @@ int gic_configure_irq(unsigned int irq, unsigned int type,
3345 pr_warn("GIC: PPI%d is secure or misconfigured\n",
3346 irq - 16);
3347 }
3348 + raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
3349
3350 if (sync_access)
3351 sync_access();
3352 diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
3353 index 8168f737590e..e7b4a0256949 100644
3354 --- a/drivers/md/dm-crypt.c
3355 +++ b/drivers/md/dm-crypt.c
3356 @@ -148,6 +148,8 @@ struct crypt_config {
3357 mempool_t *tag_pool;
3358 unsigned tag_pool_max_sectors;
3359
3360 + struct percpu_counter n_allocated_pages;
3361 +
3362 struct bio_set *bs;
3363 struct mutex bio_alloc_lock;
3364
3365 @@ -219,6 +221,12 @@ struct crypt_config {
3366 #define MAX_TAG_SIZE 480
3367 #define POOL_ENTRY_SIZE 512
3368
3369 +static DEFINE_SPINLOCK(dm_crypt_clients_lock);
3370 +static unsigned dm_crypt_clients_n = 0;
3371 +static volatile unsigned long dm_crypt_pages_per_client;
3372 +#define DM_CRYPT_MEMORY_PERCENT 2
3373 +#define DM_CRYPT_MIN_PAGES_PER_CLIENT (BIO_MAX_PAGES * 16)
3374 +
3375 static void clone_init(struct dm_crypt_io *, struct bio *);
3376 static void kcryptd_queue_crypt(struct dm_crypt_io *io);
3377 static struct scatterlist *crypt_get_sg_data(struct crypt_config *cc,
3378 @@ -2155,6 +2163,43 @@ static int crypt_wipe_key(struct crypt_config *cc)
3379 return r;
3380 }
3381
3382 +static void crypt_calculate_pages_per_client(void)
3383 +{
3384 + unsigned long pages = (totalram_pages - totalhigh_pages) * DM_CRYPT_MEMORY_PERCENT / 100;
3385 +
3386 + if (!dm_crypt_clients_n)
3387 + return;
3388 +
3389 + pages /= dm_crypt_clients_n;
3390 + if (pages < DM_CRYPT_MIN_PAGES_PER_CLIENT)
3391 + pages = DM_CRYPT_MIN_PAGES_PER_CLIENT;
3392 + dm_crypt_pages_per_client = pages;
3393 +}
3394 +
3395 +static void *crypt_page_alloc(gfp_t gfp_mask, void *pool_data)
3396 +{
3397 + struct crypt_config *cc = pool_data;
3398 + struct page *page;
3399 +
3400 + if (unlikely(percpu_counter_compare(&cc->n_allocated_pages, dm_crypt_pages_per_client) >= 0) &&
3401 + likely(gfp_mask & __GFP_NORETRY))
3402 + return NULL;
3403 +
3404 + page = alloc_page(gfp_mask);
3405 + if (likely(page != NULL))
3406 + percpu_counter_add(&cc->n_allocated_pages, 1);
3407 +
3408 + return page;
3409 +}
3410 +
3411 +static void crypt_page_free(void *page, void *pool_data)
3412 +{
3413 + struct crypt_config *cc = pool_data;
3414 +
3415 + __free_page(page);
3416 + percpu_counter_sub(&cc->n_allocated_pages, 1);
3417 +}
3418 +
3419 static void crypt_dtr(struct dm_target *ti)
3420 {
3421 struct crypt_config *cc = ti->private;
3422 @@ -2181,6 +2226,10 @@ static void crypt_dtr(struct dm_target *ti)
3423 mempool_destroy(cc->req_pool);
3424 mempool_destroy(cc->tag_pool);
3425
3426 + if (cc->page_pool)
3427 + WARN_ON(percpu_counter_sum(&cc->n_allocated_pages) != 0);
3428 + percpu_counter_destroy(&cc->n_allocated_pages);
3429 +
3430 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
3431 cc->iv_gen_ops->dtr(cc);
3432
3433 @@ -2197,6 +2246,12 @@ static void crypt_dtr(struct dm_target *ti)
3434
3435 /* Must zero key material before freeing */
3436 kzfree(cc);
3437 +
3438 + spin_lock(&dm_crypt_clients_lock);
3439 + WARN_ON(!dm_crypt_clients_n);
3440 + dm_crypt_clients_n--;
3441 + crypt_calculate_pages_per_client();
3442 + spin_unlock(&dm_crypt_clients_lock);
3443 }
3444
3445 static int crypt_ctr_ivmode(struct dm_target *ti, const char *ivmode)
3446 @@ -2644,6 +2699,15 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
3447
3448 ti->private = cc;
3449
3450 + spin_lock(&dm_crypt_clients_lock);
3451 + dm_crypt_clients_n++;
3452 + crypt_calculate_pages_per_client();
3453 + spin_unlock(&dm_crypt_clients_lock);
3454 +
3455 + ret = percpu_counter_init(&cc->n_allocated_pages, 0, GFP_KERNEL);
3456 + if (ret < 0)
3457 + goto bad;
3458 +
3459 /* Optional parameters need to be read before cipher constructor */
3460 if (argc > 5) {
3461 ret = crypt_ctr_optional(ti, argc - 5, &argv[5]);
3462 @@ -2698,7 +2762,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
3463 ALIGN(sizeof(struct dm_crypt_io) + cc->dmreq_start + additional_req_size,
3464 ARCH_KMALLOC_MINALIGN);
3465
3466 - cc->page_pool = mempool_create_page_pool(BIO_MAX_PAGES, 0);
3467 + cc->page_pool = mempool_create(BIO_MAX_PAGES, crypt_page_alloc, crypt_page_free, cc);
3468 if (!cc->page_pool) {
3469 ti->error = "Cannot allocate page mempool";
3470 goto bad;
3471 diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
3472 index c1d1034ff7b7..335ebd46a986 100644
3473 --- a/drivers/md/dm-raid.c
3474 +++ b/drivers/md/dm-raid.c
3475 @@ -3408,7 +3408,8 @@ static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery,
3476 set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags);
3477
3478 } else {
3479 - if (!test_bit(MD_RECOVERY_INTR, &recovery) &&
3480 + if (!test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags) &&
3481 + !test_bit(MD_RECOVERY_INTR, &recovery) &&
3482 (test_bit(MD_RECOVERY_NEEDED, &recovery) ||
3483 test_bit(MD_RECOVERY_RESHAPE, &recovery) ||
3484 test_bit(MD_RECOVERY_RUNNING, &recovery)))
3485 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
3486 index 353ea0ede091..038c7572fdd4 100644
3487 --- a/drivers/md/dm.c
3488 +++ b/drivers/md/dm.c
3489 @@ -1477,6 +1477,23 @@ static int __send_write_zeroes(struct clone_info *ci, struct dm_target *ti)
3490 return __send_changing_extent_only(ci, ti, get_num_write_zeroes_bios, NULL);
3491 }
3492
3493 +static bool __process_abnormal_io(struct clone_info *ci, struct dm_target *ti,
3494 + int *result)
3495 +{
3496 + struct bio *bio = ci->bio;
3497 +
3498 + if (bio_op(bio) == REQ_OP_DISCARD)
3499 + *result = __send_discard(ci, ti);
3500 + else if (bio_op(bio) == REQ_OP_WRITE_SAME)
3501 + *result = __send_write_same(ci, ti);
3502 + else if (bio_op(bio) == REQ_OP_WRITE_ZEROES)
3503 + *result = __send_write_zeroes(ci, ti);
3504 + else
3505 + return false;
3506 +
3507 + return true;
3508 +}
3509 +
3510 /*
3511 * Select the correct strategy for processing a non-flush bio.
3512 */
3513 @@ -1491,12 +1508,8 @@ static int __split_and_process_non_flush(struct clone_info *ci)
3514 if (!dm_target_is_valid(ti))
3515 return -EIO;
3516
3517 - if (unlikely(bio_op(bio) == REQ_OP_DISCARD))
3518 - return __send_discard(ci, ti);
3519 - else if (unlikely(bio_op(bio) == REQ_OP_WRITE_SAME))
3520 - return __send_write_same(ci, ti);
3521 - else if (unlikely(bio_op(bio) == REQ_OP_WRITE_ZEROES))
3522 - return __send_write_zeroes(ci, ti);
3523 + if (unlikely(__process_abnormal_io(ci, ti, &r)))
3524 + return r;
3525
3526 if (bio_op(bio) == REQ_OP_ZONE_REPORT)
3527 len = ci->sector_count;
3528 @@ -1617,9 +1630,12 @@ static blk_qc_t __process_bio(struct mapped_device *md,
3529 goto out;
3530 }
3531
3532 - tio = alloc_tio(&ci, ti, 0, GFP_NOIO);
3533 ci.bio = bio;
3534 ci.sector_count = bio_sectors(bio);
3535 + if (unlikely(__process_abnormal_io(&ci, ti, &error)))
3536 + goto out;
3537 +
3538 + tio = alloc_tio(&ci, ti, 0, GFP_NOIO);
3539 ret = __clone_and_map_simple_bio(&ci, tio, NULL);
3540 }
3541 out:
3542 diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
3543 index debe35fc66b4..d3f7bb33a54d 100644
3544 --- a/drivers/media/common/videobuf2/videobuf2-core.c
3545 +++ b/drivers/media/common/videobuf2/videobuf2-core.c
3546 @@ -1696,6 +1696,15 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
3547 for (i = 0; i < q->num_buffers; ++i) {
3548 struct vb2_buffer *vb = q->bufs[i];
3549
3550 + if (vb->state == VB2_BUF_STATE_PREPARED ||
3551 + vb->state == VB2_BUF_STATE_QUEUED) {
3552 + unsigned int plane;
3553 +
3554 + for (plane = 0; plane < vb->num_planes; ++plane)
3555 + call_void_memop(vb, finish,
3556 + vb->planes[plane].mem_priv);
3557 + }
3558 +
3559 if (vb->state != VB2_BUF_STATE_DEQUEUED) {
3560 vb->state = VB2_BUF_STATE_PREPARED;
3561 call_void_vb_qop(vb, buf_finish, vb);
3562 diff --git a/drivers/media/platform/vivid/vivid-vid-common.c b/drivers/media/platform/vivid/vivid-vid-common.c
3563 index a651527d80db..23888fdb94fb 100644
3564 --- a/drivers/media/platform/vivid/vivid-vid-common.c
3565 +++ b/drivers/media/platform/vivid/vivid-vid-common.c
3566 @@ -874,7 +874,8 @@ int vidioc_g_edid(struct file *file, void *_fh,
3567 return -EINVAL;
3568 if (edid->start_block + edid->blocks > dev->edid_blocks)
3569 edid->blocks = dev->edid_blocks - edid->start_block;
3570 - cec_set_edid_phys_addr(dev->edid, dev->edid_blocks * 128, adap->phys_addr);
3571 + if (adap)
3572 + cec_set_edid_phys_addr(dev->edid, dev->edid_blocks * 128, adap->phys_addr);
3573 memcpy(edid->edid, dev->edid + edid->start_block * 128, edid->blocks * 128);
3574 return 0;
3575 }
3576 diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
3577 index f7f3b4b2c2de..8bd6b2f1af15 100644
3578 --- a/drivers/media/platform/vsp1/vsp1_wpf.c
3579 +++ b/drivers/media/platform/vsp1/vsp1_wpf.c
3580 @@ -452,7 +452,7 @@ static void wpf_configure(struct vsp1_entity *entity,
3581 : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index);
3582 }
3583
3584 - if (pipe->bru || pipe->num_inputs > 1)
3585 + if (pipe->bru)
3586 srcrpf |= pipe->bru->type == VSP1_ENTITY_BRU
3587 ? VI6_WPF_SRCRPF_VIRACT_MST
3588 : VI6_WPF_SRCRPF_VIRACT2_MST;
3589 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
3590 index 1db8d38fed7c..9b78818c0282 100644
3591 --- a/drivers/media/rc/rc-main.c
3592 +++ b/drivers/media/rc/rc-main.c
3593 @@ -1929,12 +1929,12 @@ void rc_unregister_device(struct rc_dev *dev)
3594 if (!dev)
3595 return;
3596
3597 - del_timer_sync(&dev->timer_keyup);
3598 - del_timer_sync(&dev->timer_repeat);
3599 -
3600 if (dev->driver_type == RC_DRIVER_IR_RAW)
3601 ir_raw_event_unregister(dev);
3602
3603 + del_timer_sync(&dev->timer_keyup);
3604 + del_timer_sync(&dev->timer_repeat);
3605 +
3606 rc_free_rx_device(dev);
3607
3608 mutex_lock(&dev->lock);
3609 diff --git a/drivers/misc/cxl/cxllib.c b/drivers/misc/cxl/cxllib.c
3610 index 30ccba436b3b..55cd35d1a9cc 100644
3611 --- a/drivers/misc/cxl/cxllib.c
3612 +++ b/drivers/misc/cxl/cxllib.c
3613 @@ -208,49 +208,74 @@ int cxllib_get_PE_attributes(struct task_struct *task,
3614 }
3615 EXPORT_SYMBOL_GPL(cxllib_get_PE_attributes);
3616
3617 -int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags)
3618 +static int get_vma_info(struct mm_struct *mm, u64 addr,
3619 + u64 *vma_start, u64 *vma_end,
3620 + unsigned long *page_size)
3621 {
3622 - int rc;
3623 - u64 dar;
3624 struct vm_area_struct *vma = NULL;
3625 - unsigned long page_size;
3626 -
3627 - if (mm == NULL)
3628 - return -EFAULT;
3629 + int rc = 0;
3630
3631 down_read(&mm->mmap_sem);
3632
3633 vma = find_vma(mm, addr);
3634 if (!vma) {
3635 - pr_err("Can't find vma for addr %016llx\n", addr);
3636 rc = -EFAULT;
3637 goto out;
3638 }
3639 - /* get the size of the pages allocated */
3640 - page_size = vma_kernel_pagesize(vma);
3641 -
3642 - for (dar = (addr & ~(page_size - 1)); dar < (addr + size); dar += page_size) {
3643 - if (dar < vma->vm_start || dar >= vma->vm_end) {
3644 - vma = find_vma(mm, addr);
3645 - if (!vma) {
3646 - pr_err("Can't find vma for addr %016llx\n", addr);
3647 - rc = -EFAULT;
3648 - goto out;
3649 - }
3650 - /* get the size of the pages allocated */
3651 - page_size = vma_kernel_pagesize(vma);
3652 + *page_size = vma_kernel_pagesize(vma);
3653 + *vma_start = vma->vm_start;
3654 + *vma_end = vma->vm_end;
3655 +out:
3656 + up_read(&mm->mmap_sem);
3657 + return rc;
3658 +}
3659 +
3660 +int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags)
3661 +{
3662 + int rc;
3663 + u64 dar, vma_start, vma_end;
3664 + unsigned long page_size;
3665 +
3666 + if (mm == NULL)
3667 + return -EFAULT;
3668 +
3669 + /*
3670 + * The buffer we have to process can extend over several pages
3671 + * and may also cover several VMAs.
3672 + * We iterate over all the pages. The page size could vary
3673 + * between VMAs.
3674 + */
3675 + rc = get_vma_info(mm, addr, &vma_start, &vma_end, &page_size);
3676 + if (rc)
3677 + return rc;
3678 +
3679 + for (dar = (addr & ~(page_size - 1)); dar < (addr + size);
3680 + dar += page_size) {
3681 + if (dar < vma_start || dar >= vma_end) {
3682 + /*
3683 + * We don't hold the mm->mmap_sem semaphore
3684 + * while iterating, since the semaphore is
3685 + * required by one of the lower-level page
3686 + * fault processing functions and it could
3687 + * create a deadlock.
3688 + *
3689 + * It means the VMAs can be altered between 2
3690 + * loop iterations and we could theoretically
3691 + * miss a page (however unlikely). But that's
3692 + * not really a problem, as the driver will
3693 + * retry access, get another page fault on the
3694 + * missing page and call us again.
3695 + */
3696 + rc = get_vma_info(mm, dar, &vma_start, &vma_end,
3697 + &page_size);
3698 + if (rc)
3699 + return rc;
3700 }
3701
3702 rc = cxl_handle_mm_fault(mm, flags, dar);
3703 - if (rc) {
3704 - pr_err("cxl_handle_mm_fault failed %d", rc);
3705 - rc = -EFAULT;
3706 - goto out;
3707 - }
3708 + if (rc)
3709 + return -EFAULT;
3710 }
3711 - rc = 0;
3712 -out:
3713 - up_read(&mm->mmap_sem);
3714 - return rc;
3715 + return 0;
3716 }
3717 EXPORT_SYMBOL_GPL(cxllib_handle_fault);
3718 diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
3719 index 2cfb963d9f37..9c6f639d8a57 100644
3720 --- a/drivers/mmc/core/block.c
3721 +++ b/drivers/mmc/core/block.c
3722 @@ -3087,6 +3087,7 @@ static void __exit mmc_blk_exit(void)
3723 mmc_unregister_driver(&mmc_driver);
3724 unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
3725 unregister_chrdev_region(mmc_rpmb_devt, MAX_DEVICES);
3726 + bus_unregister(&mmc_rpmb_bus_type);
3727 }
3728
3729 module_init(mmc_blk_init);
3730 diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
3731 index 712e08d9a45e..a0168e9e4fce 100644
3732 --- a/drivers/mmc/host/jz4740_mmc.c
3733 +++ b/drivers/mmc/host/jz4740_mmc.c
3734 @@ -362,9 +362,9 @@ static void jz4740_mmc_set_irq_enabled(struct jz4740_mmc_host *host,
3735 host->irq_mask &= ~irq;
3736 else
3737 host->irq_mask |= irq;
3738 - spin_unlock_irqrestore(&host->lock, flags);
3739
3740 writew(host->irq_mask, host->base + JZ_REG_MMC_IMASK);
3741 + spin_unlock_irqrestore(&host->lock, flags);
3742 }
3743
3744 static void jz4740_mmc_clock_enable(struct jz4740_mmc_host *host,
3745 diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
3746 index 82c4f05f91d8..0a0852524491 100644
3747 --- a/drivers/mmc/host/sdhci-pci-core.c
3748 +++ b/drivers/mmc/host/sdhci-pci-core.c
3749 @@ -1318,7 +1318,7 @@ static void amd_enable_manual_tuning(struct pci_dev *pdev)
3750 pci_write_config_dword(pdev, AMD_SD_MISC_CONTROL, val);
3751 }
3752
3753 -static int amd_execute_tuning(struct sdhci_host *host, u32 opcode)
3754 +static int amd_execute_tuning_hs200(struct sdhci_host *host, u32 opcode)
3755 {
3756 struct sdhci_pci_slot *slot = sdhci_priv(host);
3757 struct pci_dev *pdev = slot->chip->pdev;
3758 @@ -1357,6 +1357,27 @@ static int amd_execute_tuning(struct sdhci_host *host, u32 opcode)
3759 return 0;
3760 }
3761
3762 +static int amd_execute_tuning(struct mmc_host *mmc, u32 opcode)
3763 +{
3764 + struct sdhci_host *host = mmc_priv(mmc);
3765 +
3766 + /* AMD requires custom HS200 tuning */
3767 + if (host->timing == MMC_TIMING_MMC_HS200)
3768 + return amd_execute_tuning_hs200(host, opcode);
3769 +
3770 + /* Otherwise perform standard SDHCI tuning */
3771 + return sdhci_execute_tuning(mmc, opcode);
3772 +}
3773 +
3774 +static int amd_probe_slot(struct sdhci_pci_slot *slot)
3775 +{
3776 + struct mmc_host_ops *ops = &slot->host->mmc_host_ops;
3777 +
3778 + ops->execute_tuning = amd_execute_tuning;
3779 +
3780 + return 0;
3781 +}
3782 +
3783 static int amd_probe(struct sdhci_pci_chip *chip)
3784 {
3785 struct pci_dev *smbus_dev;
3786 @@ -1391,12 +1412,12 @@ static const struct sdhci_ops amd_sdhci_pci_ops = {
3787 .set_bus_width = sdhci_set_bus_width,
3788 .reset = sdhci_reset,
3789 .set_uhs_signaling = sdhci_set_uhs_signaling,
3790 - .platform_execute_tuning = amd_execute_tuning,
3791 };
3792
3793 static const struct sdhci_pci_fixes sdhci_amd = {
3794 .probe = amd_probe,
3795 .ops = &amd_sdhci_pci_ops,
3796 + .probe_slot = amd_probe_slot,
3797 };
3798
3799 static const struct pci_device_id pci_ids[] = {
3800 diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c
3801 index 33494241245a..8fce18253465 100644
3802 --- a/drivers/mmc/host/tmio_mmc_core.c
3803 +++ b/drivers/mmc/host/tmio_mmc_core.c
3804 @@ -911,7 +911,7 @@ static void tmio_mmc_finish_request(struct tmio_mmc_host *host)
3805 host->check_scc_error(host);
3806
3807 /* If SET_BLOCK_COUNT, continue with main command */
3808 - if (host->mrq) {
3809 + if (host->mrq && !mrq->cmd->error) {
3810 tmio_process_mrq(host, mrq);
3811 return;
3812 }
3813 diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
3814 index b1fc28f63882..d0b63bbf46a7 100644
3815 --- a/drivers/mtd/ubi/block.c
3816 +++ b/drivers/mtd/ubi/block.c
3817 @@ -244,7 +244,7 @@ static int ubiblock_open(struct block_device *bdev, fmode_t mode)
3818 * in any case.
3819 */
3820 if (mode & FMODE_WRITE) {
3821 - ret = -EPERM;
3822 + ret = -EROFS;
3823 goto out_unlock;
3824 }
3825
3826 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
3827 index e941395de3ae..753494e042d5 100644
3828 --- a/drivers/mtd/ubi/build.c
3829 +++ b/drivers/mtd/ubi/build.c
3830 @@ -854,6 +854,17 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
3831 return -EINVAL;
3832 }
3833
3834 + /*
3835 + * Both UBI and UBIFS have been designed for SLC NAND and NOR flashes.
3836 + * MLC NAND is different and needs special care, otherwise UBI or UBIFS
3837 + * will die soon and you will lose all your data.
3838 + */
3839 + if (mtd->type == MTD_MLCNANDFLASH) {
3840 + pr_err("ubi: refuse attaching mtd%d - MLC NAND is not supported\n",
3841 + mtd->index);
3842 + return -EINVAL;
3843 + }
3844 +
3845 if (ubi_num == UBI_DEV_NUM_AUTO) {
3846 /* Search for an empty slot in the @ubi_devices array */
3847 for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++)
3848 diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
3849 index 590d967011bb..98f7d6be8d1f 100644
3850 --- a/drivers/mtd/ubi/fastmap-wl.c
3851 +++ b/drivers/mtd/ubi/fastmap-wl.c
3852 @@ -362,7 +362,6 @@ static void ubi_fastmap_close(struct ubi_device *ubi)
3853 {
3854 int i;
3855
3856 - flush_work(&ubi->fm_work);
3857 return_unused_pool_pebs(ubi, &ubi->fm_pool);
3858 return_unused_pool_pebs(ubi, &ubi->fm_wl_pool);
3859
3860 diff --git a/drivers/nvdimm/dimm.c b/drivers/nvdimm/dimm.c
3861 index f8913b8124b6..233907889f96 100644
3862 --- a/drivers/nvdimm/dimm.c
3863 +++ b/drivers/nvdimm/dimm.c
3864 @@ -67,9 +67,11 @@ static int nvdimm_probe(struct device *dev)
3865 ndd->ns_next = nd_label_next_nsindex(ndd->ns_current);
3866 nd_label_copy(ndd, to_next_namespace_index(ndd),
3867 to_current_namespace_index(ndd));
3868 - rc = nd_label_reserve_dpa(ndd);
3869 - if (ndd->ns_current >= 0)
3870 - nvdimm_set_aliasing(dev);
3871 + if (ndd->ns_current >= 0) {
3872 + rc = nd_label_reserve_dpa(ndd);
3873 + if (rc == 0)
3874 + nvdimm_set_aliasing(dev);
3875 + }
3876 nvdimm_clear_locked(dev);
3877 nvdimm_bus_unlock(dev);
3878
3879 diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c
3880 index 097794d9f786..175e200939b0 100644
3881 --- a/drivers/nvdimm/dimm_devs.c
3882 +++ b/drivers/nvdimm/dimm_devs.c
3883 @@ -88,9 +88,9 @@ int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd)
3884 int nvdimm_init_config_data(struct nvdimm_drvdata *ndd)
3885 {
3886 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev);
3887 + int rc = validate_dimm(ndd), cmd_rc = 0;
3888 struct nd_cmd_get_config_data_hdr *cmd;
3889 struct nvdimm_bus_descriptor *nd_desc;
3890 - int rc = validate_dimm(ndd);
3891 u32 max_cmd_size, config_size;
3892 size_t offset;
3893
3894 @@ -124,9 +124,11 @@ int nvdimm_init_config_data(struct nvdimm_drvdata *ndd)
3895 cmd->in_offset = offset;
3896 rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev),
3897 ND_CMD_GET_CONFIG_DATA, cmd,
3898 - cmd->in_length + sizeof(*cmd), NULL);
3899 - if (rc || cmd->status) {
3900 - rc = -ENXIO;
3901 + cmd->in_length + sizeof(*cmd), &cmd_rc);
3902 + if (rc < 0)
3903 + break;
3904 + if (cmd_rc < 0) {
3905 + rc = cmd_rc;
3906 break;
3907 }
3908 memcpy(ndd->data + offset, cmd->out_buf, cmd->in_length);
3909 @@ -140,9 +142,9 @@ int nvdimm_init_config_data(struct nvdimm_drvdata *ndd)
3910 int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
3911 void *buf, size_t len)
3912 {
3913 - int rc = validate_dimm(ndd);
3914 size_t max_cmd_size, buf_offset;
3915 struct nd_cmd_set_config_hdr *cmd;
3916 + int rc = validate_dimm(ndd), cmd_rc = 0;
3917 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev);
3918 struct nvdimm_bus_descriptor *nd_desc = nvdimm_bus->nd_desc;
3919
3920 @@ -164,7 +166,6 @@ int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
3921 for (buf_offset = 0; len; len -= cmd->in_length,
3922 buf_offset += cmd->in_length) {
3923 size_t cmd_size;
3924 - u32 *status;
3925
3926 cmd->in_offset = offset + buf_offset;
3927 cmd->in_length = min(max_cmd_size, len);
3928 @@ -172,12 +173,13 @@ int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
3929
3930 /* status is output in the last 4-bytes of the command buffer */
3931 cmd_size = sizeof(*cmd) + cmd->in_length + sizeof(u32);
3932 - status = ((void *) cmd) + cmd_size - sizeof(u32);
3933
3934 rc = nd_desc->ndctl(nd_desc, to_nvdimm(ndd->dev),
3935 - ND_CMD_SET_CONFIG_DATA, cmd, cmd_size, NULL);
3936 - if (rc || *status) {
3937 - rc = rc ? rc : -ENXIO;
3938 + ND_CMD_SET_CONFIG_DATA, cmd, cmd_size, &cmd_rc);
3939 + if (rc < 0)
3940 + break;
3941 + if (cmd_rc < 0) {
3942 + rc = cmd_rc;
3943 break;
3944 }
3945 }
3946 diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
3947 index 658ada497be0..6747d899f46e 100644
3948 --- a/drivers/nvdimm/namespace_devs.c
3949 +++ b/drivers/nvdimm/namespace_devs.c
3950 @@ -1926,7 +1926,7 @@ static struct device *create_namespace_pmem(struct nd_region *nd_region,
3951 }
3952
3953 if (i < nd_region->ndr_mappings) {
3954 - struct nvdimm_drvdata *ndd = to_ndd(&nd_region->mapping[i]);
3955 + struct nvdimm *nvdimm = nd_region->mapping[i].nvdimm;
3956
3957 /*
3958 * Give up if we don't find an instance of a uuid at each
3959 @@ -1934,7 +1934,7 @@ static struct device *create_namespace_pmem(struct nd_region *nd_region,
3960 * find a dimm with two instances of the same uuid.
3961 */
3962 dev_err(&nd_region->dev, "%s missing label for %pUb\n",
3963 - dev_name(ndd->dev), nd_label->uuid);
3964 + nvdimm_name(nvdimm), nd_label->uuid);
3965 rc = -EINVAL;
3966 goto err;
3967 }
3968 diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
3969 index e2198a2feeca..b45b375c0e6c 100644
3970 --- a/drivers/pci/hotplug/acpiphp_glue.c
3971 +++ b/drivers/pci/hotplug/acpiphp_glue.c
3972 @@ -541,6 +541,7 @@ static unsigned int get_slot_status(struct acpiphp_slot *slot)
3973 {
3974 unsigned long long sta = 0;
3975 struct acpiphp_func *func;
3976 + u32 dvid;
3977
3978 list_for_each_entry(func, &slot->funcs, sibling) {
3979 if (func->flags & FUNC_HAS_STA) {
3980 @@ -551,19 +552,27 @@ static unsigned int get_slot_status(struct acpiphp_slot *slot)
3981 if (ACPI_SUCCESS(status) && sta)
3982 break;
3983 } else {
3984 - u32 dvid;
3985 -
3986 - pci_bus_read_config_dword(slot->bus,
3987 - PCI_DEVFN(slot->device,
3988 - func->function),
3989 - PCI_VENDOR_ID, &dvid);
3990 - if (dvid != 0xffffffff) {
3991 + if (pci_bus_read_dev_vendor_id(slot->bus,
3992 + PCI_DEVFN(slot->device, func->function),
3993 + &dvid, 0)) {
3994 sta = ACPI_STA_ALL;
3995 break;
3996 }
3997 }
3998 }
3999
4000 + if (!sta) {
4001 + /*
4002 + * Check for the slot itself since it may be that the
4003 + * ACPI slot is a device below PCIe upstream port so in
4004 + * that case it may not even be reachable yet.
4005 + */
4006 + if (pci_bus_read_dev_vendor_id(slot->bus,
4007 + PCI_DEVFN(slot->device, 0), &dvid, 0)) {
4008 + sta = ACPI_STA_ALL;
4009 + }
4010 + }
4011 +
4012 return (unsigned int)sta;
4013 }
4014
4015 diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
4016 index 46d47bd6ca1f..81241f981ad7 100644
4017 --- a/drivers/pci/quirks.c
4018 +++ b/drivers/pci/quirks.c
4019 @@ -4815,9 +4815,13 @@ static void quirk_no_ext_tags(struct pci_dev *pdev)
4020
4021 pci_walk_bus(bridge->bus, pci_configure_extended_tags, NULL);
4022 }
4023 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0132, quirk_no_ext_tags);
4024 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0140, quirk_no_ext_tags);
4025 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0141, quirk_no_ext_tags);
4026 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0142, quirk_no_ext_tags);
4027 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0144, quirk_no_ext_tags);
4028 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0420, quirk_no_ext_tags);
4029 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0422, quirk_no_ext_tags);
4030
4031 #ifdef CONFIG_PCI_ATS
4032 /*
4033 diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
4034 index aa857be692cf..d5ae307ef4e1 100644
4035 --- a/drivers/phy/allwinner/phy-sun4i-usb.c
4036 +++ b/drivers/phy/allwinner/phy-sun4i-usb.c
4037 @@ -410,11 +410,13 @@ static bool sun4i_usb_phy0_poll(struct sun4i_usb_phy_data *data)
4038 return true;
4039
4040 /*
4041 - * The A31 companion pmic (axp221) does not generate vbus change
4042 - * interrupts when the board is driving vbus, so we must poll
4043 + * The A31/A23/A33 companion pmics (AXP221/AXP223) do not
4044 + * generate vbus change interrupts when the board is driving
4045 + * vbus using the N_VBUSEN pin on the pmic, so we must poll
4046 * when using the pmic for vbus-det _and_ we're driving vbus.
4047 */
4048 - if (data->cfg->type == sun6i_a31_phy &&
4049 + if ((data->cfg->type == sun6i_a31_phy ||
4050 + data->cfg->type == sun8i_a33_phy) &&
4051 data->vbus_power_supply && data->phys[0].regulator_on)
4052 return true;
4053
4054 @@ -885,7 +887,7 @@ static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
4055
4056 static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
4057 .num_phys = 2,
4058 - .type = sun4i_a10_phy,
4059 + .type = sun6i_a31_phy,
4060 .disc_thresh = 3,
4061 .phyctl_offset = REG_PHYCTL_A10,
4062 .dedicated_clocks = true,
4063 diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
4064 index f5d97e0ad52b..98b0a933a946 100644
4065 --- a/drivers/pwm/pwm-mediatek.c
4066 +++ b/drivers/pwm/pwm-mediatek.c
4067 @@ -29,7 +29,9 @@
4068 #define PWMGDUR 0x0c
4069 #define PWMWAVENUM 0x28
4070 #define PWMDWIDTH 0x2c
4071 +#define PWM45DWIDTH_FIXUP 0x30
4072 #define PWMTHRES 0x30
4073 +#define PWM45THRES_FIXUP 0x34
4074
4075 #define PWM_CLK_DIV_MAX 7
4076
4077 @@ -54,6 +56,7 @@ static const char * const mtk_pwm_clk_name[MTK_CLK_MAX] = {
4078
4079 struct mtk_pwm_platform_data {
4080 unsigned int num_pwms;
4081 + bool pwm45_fixup;
4082 };
4083
4084 /**
4085 @@ -66,6 +69,7 @@ struct mtk_pwm_chip {
4086 struct pwm_chip chip;
4087 void __iomem *regs;
4088 struct clk *clks[MTK_CLK_MAX];
4089 + const struct mtk_pwm_platform_data *soc;
4090 };
4091
4092 static const unsigned int mtk_pwm_reg_offset[] = {
4093 @@ -131,18 +135,25 @@ static int mtk_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
4094 {
4095 struct mtk_pwm_chip *pc = to_mtk_pwm_chip(chip);
4096 struct clk *clk = pc->clks[MTK_CLK_PWM1 + pwm->hwpwm];
4097 - u32 resolution, clkdiv = 0;
4098 + u32 clkdiv = 0, cnt_period, cnt_duty, reg_width = PWMDWIDTH,
4099 + reg_thres = PWMTHRES;
4100 + u64 resolution;
4101 int ret;
4102
4103 ret = mtk_pwm_clk_enable(chip, pwm);
4104 if (ret < 0)
4105 return ret;
4106
4107 - resolution = NSEC_PER_SEC / clk_get_rate(clk);
4108 + /* Using resolution in picosecond gets accuracy higher */
4109 + resolution = (u64)NSEC_PER_SEC * 1000;
4110 + do_div(resolution, clk_get_rate(clk));
4111
4112 - while (period_ns / resolution > 8191) {
4113 + cnt_period = DIV_ROUND_CLOSEST_ULL((u64)period_ns * 1000, resolution);
4114 + while (cnt_period > 8191) {
4115 resolution *= 2;
4116 clkdiv++;
4117 + cnt_period = DIV_ROUND_CLOSEST_ULL((u64)period_ns * 1000,
4118 + resolution);
4119 }
4120
4121 if (clkdiv > PWM_CLK_DIV_MAX) {
4122 @@ -151,9 +162,19 @@ static int mtk_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
4123 return -EINVAL;
4124 }
4125
4126 + if (pc->soc->pwm45_fixup && pwm->hwpwm > 2) {
4127 + /*
4128 + * PWM[4,5] has distinct offset for PWMDWIDTH and PWMTHRES
4129 + * from the other PWMs on MT7623.
4130 + */
4131 + reg_width = PWM45DWIDTH_FIXUP;
4132 + reg_thres = PWM45THRES_FIXUP;
4133 + }
4134 +
4135 + cnt_duty = DIV_ROUND_CLOSEST_ULL((u64)duty_ns * 1000, resolution);
4136 mtk_pwm_writel(pc, pwm->hwpwm, PWMCON, BIT(15) | clkdiv);
4137 - mtk_pwm_writel(pc, pwm->hwpwm, PWMDWIDTH, period_ns / resolution);
4138 - mtk_pwm_writel(pc, pwm->hwpwm, PWMTHRES, duty_ns / resolution);
4139 + mtk_pwm_writel(pc, pwm->hwpwm, reg_width, cnt_period);
4140 + mtk_pwm_writel(pc, pwm->hwpwm, reg_thres, cnt_duty);
4141
4142 mtk_pwm_clk_disable(chip, pwm);
4143
4144 @@ -211,6 +232,7 @@ static int mtk_pwm_probe(struct platform_device *pdev)
4145 data = of_device_get_match_data(&pdev->dev);
4146 if (data == NULL)
4147 return -EINVAL;
4148 + pc->soc = data;
4149
4150 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4151 pc->regs = devm_ioremap_resource(&pdev->dev, res);
4152 @@ -251,14 +273,17 @@ static int mtk_pwm_remove(struct platform_device *pdev)
4153
4154 static const struct mtk_pwm_platform_data mt2712_pwm_data = {
4155 .num_pwms = 8,
4156 + .pwm45_fixup = false,
4157 };
4158
4159 static const struct mtk_pwm_platform_data mt7622_pwm_data = {
4160 .num_pwms = 6,
4161 + .pwm45_fixup = false,
4162 };
4163
4164 static const struct mtk_pwm_platform_data mt7623_pwm_data = {
4165 .num_pwms = 5,
4166 + .pwm45_fixup = true,
4167 };
4168
4169 static const struct of_device_id mtk_pwm_of_match[] = {
4170 diff --git a/drivers/pwm/pwm-rcar.c b/drivers/pwm/pwm-rcar.c
4171 index 1c85ecc9e7ac..0fcf94ffad32 100644
4172 --- a/drivers/pwm/pwm-rcar.c
4173 +++ b/drivers/pwm/pwm-rcar.c
4174 @@ -156,8 +156,12 @@ static int rcar_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
4175 if (div < 0)
4176 return div;
4177
4178 - /* Let the core driver set pwm->period if disabled and duty_ns == 0 */
4179 - if (!pwm_is_enabled(pwm) && !duty_ns)
4180 + /*
4181 + * Let the core driver set pwm->period if disabled and duty_ns == 0.
4182 + * But, this driver should prevent to set the new duty_ns if current
4183 + * duty_cycle is not set
4184 + */
4185 + if (!pwm_is_enabled(pwm) && !duty_ns && !pwm->state.duty_cycle)
4186 return 0;
4187
4188 rcar_pwm_update(rp, RCAR_PWMCR_SYNC, RCAR_PWMCR_SYNC, RCAR_PWMCR);
4189 diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c
4190 index 435ce5ec648a..59bd749c2f25 100644
4191 --- a/drivers/soc/mediatek/mtk-scpsys.c
4192 +++ b/drivers/soc/mediatek/mtk-scpsys.c
4193 @@ -992,7 +992,7 @@ static int scpsys_probe(struct platform_device *pdev)
4194
4195 pd_data = &scp->pd_data;
4196
4197 - for (i = 0, sd = soc->subdomains ; i < soc->num_subdomains ; i++) {
4198 + for (i = 0, sd = soc->subdomains; i < soc->num_subdomains; i++, sd++) {
4199 ret = pm_genpd_add_subdomain(pd_data->domains[sd->origin],
4200 pd_data->domains[sd->subdomain]);
4201 if (ret && IS_ENABLED(CONFIG_PM))
4202 diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
4203 index 4a11fc0d4136..b7936f815373 100644
4204 --- a/drivers/spi/spi-atmel.c
4205 +++ b/drivers/spi/spi-atmel.c
4206 @@ -1512,6 +1512,11 @@ static void atmel_spi_init(struct atmel_spi *as)
4207 {
4208 spi_writel(as, CR, SPI_BIT(SWRST));
4209 spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
4210 +
4211 + /* It is recommended to enable FIFOs first thing after reset */
4212 + if (as->fifo_size)
4213 + spi_writel(as, CR, SPI_BIT(FIFOEN));
4214 +
4215 if (as->caps.has_wdrbt) {
4216 spi_writel(as, MR, SPI_BIT(WDRBT) | SPI_BIT(MODFDIS)
4217 | SPI_BIT(MSTR));
4218 @@ -1522,9 +1527,6 @@ static void atmel_spi_init(struct atmel_spi *as)
4219 if (as->use_pdc)
4220 spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
4221 spi_writel(as, CR, SPI_BIT(SPIEN));
4222 -
4223 - if (as->fifo_size)
4224 - spi_writel(as, CR, SPI_BIT(FIFOEN));
4225 }
4226
4227 static int atmel_spi_probe(struct platform_device *pdev)
4228 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
4229 index b33a727a0158..7b213faa0a2b 100644
4230 --- a/drivers/spi/spi.c
4231 +++ b/drivers/spi/spi.c
4232 @@ -779,8 +779,14 @@ static int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
4233 for (i = 0; i < sgs; i++) {
4234
4235 if (vmalloced_buf || kmap_buf) {
4236 - min = min_t(size_t,
4237 - len, desc_len - offset_in_page(buf));
4238 + /*
4239 + * Next scatterlist entry size is the minimum between
4240 + * the desc_len and the remaining buffer length that
4241 + * fits in a page.
4242 + */
4243 + min = min_t(size_t, desc_len,
4244 + min_t(size_t, len,
4245 + PAGE_SIZE - offset_in_page(buf)));
4246 if (vmalloced_buf)
4247 vm_page = vmalloc_to_page(buf);
4248 else
4249 @@ -2254,12 +2260,6 @@ void spi_unregister_controller(struct spi_controller *ctlr)
4250 mutex_lock(&board_lock);
4251 found = idr_find(&spi_master_idr, id);
4252 mutex_unlock(&board_lock);
4253 - if (found != ctlr) {
4254 - dev_dbg(&ctlr->dev,
4255 - "attempting to delete unregistered controller [%s]\n",
4256 - dev_name(&ctlr->dev));
4257 - return;
4258 - }
4259 if (ctlr->queued) {
4260 if (spi_destroy_queue(ctlr))
4261 dev_err(&ctlr->dev, "queue remove failed\n");
4262 @@ -2272,7 +2272,8 @@ void spi_unregister_controller(struct spi_controller *ctlr)
4263 device_unregister(&ctlr->dev);
4264 /* free bus id */
4265 mutex_lock(&board_lock);
4266 - idr_remove(&spi_master_idr, id);
4267 + if (found == ctlr)
4268 + idr_remove(&spi_master_idr, id);
4269 mutex_unlock(&board_lock);
4270 }
4271 EXPORT_SYMBOL_GPL(spi_unregister_controller);
4272 diff --git a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c
4273 index 4f9f9dca5e6a..545ef024841d 100644
4274 --- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c
4275 +++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c
4276 @@ -1279,7 +1279,10 @@ const struct v4l2_file_operations atomisp_fops = {
4277 .mmap = atomisp_mmap,
4278 .unlocked_ioctl = video_ioctl2,
4279 #ifdef CONFIG_COMPAT
4280 + /*
4281 + * There are problems with this code. Disable this for now.
4282 .compat_ioctl32 = atomisp_compat_ioctl32,
4283 + */
4284 #endif
4285 .poll = atomisp_poll,
4286 };
4287 @@ -1291,7 +1294,10 @@ const struct v4l2_file_operations atomisp_file_fops = {
4288 .mmap = atomisp_file_mmap,
4289 .unlocked_ioctl = video_ioctl2,
4290 #ifdef CONFIG_COMPAT
4291 + /*
4292 + * There are problems with this code. Disable this for now.
4293 .compat_ioctl32 = atomisp_compat_ioctl32,
4294 + */
4295 #endif
4296 .poll = atomisp_poll,
4297 };
4298 diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
4299 index a67781b7a0b2..ee3a215b333a 100644
4300 --- a/drivers/thermal/imx_thermal.c
4301 +++ b/drivers/thermal/imx_thermal.c
4302 @@ -637,6 +637,9 @@ static int imx_thermal_probe(struct platform_device *pdev)
4303 regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN);
4304 regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP);
4305
4306 + data->irq_enabled = true;
4307 + data->mode = THERMAL_DEVICE_ENABLED;
4308 +
4309 ret = devm_request_threaded_irq(&pdev->dev, data->irq,
4310 imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread,
4311 0, "imx_thermal", data);
4312 @@ -649,9 +652,6 @@ static int imx_thermal_probe(struct platform_device *pdev)
4313 return ret;
4314 }
4315
4316 - data->irq_enabled = true;
4317 - data->mode = THERMAL_DEVICE_ENABLED;
4318 -
4319 return 0;
4320 }
4321
4322 diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c
4323 index ab02d13f40b7..3e12cb8a23cc 100644
4324 --- a/drivers/thunderbolt/icm.c
4325 +++ b/drivers/thunderbolt/icm.c
4326 @@ -383,6 +383,15 @@ static void remove_switch(struct tb_switch *sw)
4327 tb_switch_remove(sw);
4328 }
4329
4330 +static void remove_xdomain(struct tb_xdomain *xd)
4331 +{
4332 + struct tb_switch *sw;
4333 +
4334 + sw = tb_to_switch(xd->dev.parent);
4335 + tb_port_at(xd->route, sw)->xdomain = NULL;
4336 + tb_xdomain_remove(xd);
4337 +}
4338 +
4339 static void
4340 icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
4341 {
4342 @@ -391,6 +400,7 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
4343 struct tb_switch *sw, *parent_sw;
4344 struct icm *icm = tb_priv(tb);
4345 bool authorized = false;
4346 + struct tb_xdomain *xd;
4347 u8 link, depth;
4348 u64 route;
4349 int ret;
4350 @@ -467,6 +477,13 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
4351 tb_switch_put(sw);
4352 }
4353
4354 + /* Remove existing XDomain connection if found */
4355 + xd = tb_xdomain_find_by_link_depth(tb, link, depth);
4356 + if (xd) {
4357 + remove_xdomain(xd);
4358 + tb_xdomain_put(xd);
4359 + }
4360 +
4361 parent_sw = tb_switch_find_by_link_depth(tb, link, depth - 1);
4362 if (!parent_sw) {
4363 tb_err(tb, "failed to find parent switch for %u.%u\n",
4364 @@ -529,15 +546,6 @@ icm_fr_device_disconnected(struct tb *tb, const struct icm_pkg_header *hdr)
4365 tb_switch_put(sw);
4366 }
4367
4368 -static void remove_xdomain(struct tb_xdomain *xd)
4369 -{
4370 - struct tb_switch *sw;
4371 -
4372 - sw = tb_to_switch(xd->dev.parent);
4373 - tb_port_at(xd->route, sw)->xdomain = NULL;
4374 - tb_xdomain_remove(xd);
4375 -}
4376 -
4377 static void
4378 icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr)
4379 {
4380 @@ -728,14 +736,14 @@ static bool icm_ar_is_supported(struct tb *tb)
4381 static int icm_ar_get_mode(struct tb *tb)
4382 {
4383 struct tb_nhi *nhi = tb->nhi;
4384 - int retries = 5;
4385 + int retries = 60;
4386 u32 val;
4387
4388 do {
4389 val = ioread32(nhi->iobase + REG_FW_STS);
4390 if (val & REG_FW_STS_NVM_AUTH_DONE)
4391 break;
4392 - msleep(30);
4393 + msleep(50);
4394 } while (--retries);
4395
4396 if (!retries) {
4397 @@ -915,6 +923,9 @@ static int icm_firmware_reset(struct tb *tb, struct tb_nhi *nhi)
4398 struct icm *icm = tb_priv(tb);
4399 u32 val;
4400
4401 + if (!icm->upstream_port)
4402 + return -ENODEV;
4403 +
4404 /* Put ARC to wait for CIO reset event to happen */
4405 val = ioread32(nhi->iobase + REG_FW_STS);
4406 val |= REG_FW_STS_CIO_RESET_REQ;
4407 @@ -1054,6 +1065,9 @@ static int icm_firmware_init(struct tb *tb)
4408 break;
4409
4410 default:
4411 + if (ret < 0)
4412 + return ret;
4413 +
4414 tb_err(tb, "ICM firmware is in wrong mode: %u\n", ret);
4415 return -ENODEV;
4416 }
4417 diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
4418 index f45bcbc63738..80c33c7404f5 100644
4419 --- a/drivers/thunderbolt/nhi.c
4420 +++ b/drivers/thunderbolt/nhi.c
4421 @@ -1064,6 +1064,7 @@ static const struct dev_pm_ops nhi_pm_ops = {
4422 * we just disable hotplug, the
4423 * pci-tunnels stay alive.
4424 */
4425 + .thaw_noirq = nhi_resume_noirq,
4426 .restore_noirq = nhi_resume_noirq,
4427 .suspend = nhi_suspend,
4428 .freeze = nhi_suspend,
4429 diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
4430 index da54ace4dd2f..1cc79785ce42 100644
4431 --- a/drivers/thunderbolt/switch.c
4432 +++ b/drivers/thunderbolt/switch.c
4433 @@ -716,6 +716,13 @@ static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val)
4434 if (sw->authorized)
4435 goto unlock;
4436
4437 + /*
4438 + * Make sure there is no PCIe rescan ongoing when a new PCIe
4439 + * tunnel is created. Otherwise the PCIe rescan code might find
4440 + * the new tunnel too early.
4441 + */
4442 + pci_lock_rescan_remove();
4443 +
4444 switch (val) {
4445 /* Approve switch */
4446 case 1:
4447 @@ -735,6 +742,8 @@ static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val)
4448 break;
4449 }
4450
4451 + pci_unlock_rescan_remove();
4452 +
4453 if (!ret) {
4454 sw->authorized = val;
4455 /* Notify status change to the userspace */
4456 diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
4457 index 83c14dda6300..bc8242bc4564 100644
4458 --- a/drivers/usb/core/generic.c
4459 +++ b/drivers/usb/core/generic.c
4460 @@ -210,8 +210,13 @@ static int generic_suspend(struct usb_device *udev, pm_message_t msg)
4461 if (!udev->parent)
4462 rc = hcd_bus_suspend(udev, msg);
4463
4464 - /* Non-root devices don't need to do anything for FREEZE or PRETHAW */
4465 - else if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_PRETHAW)
4466 + /*
4467 + * Non-root USB2 devices don't need to do anything for FREEZE
4468 + * or PRETHAW. USB3 devices don't support global suspend and
4469 + * needs to be selectively suspended.
4470 + */
4471 + else if ((msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_PRETHAW)
4472 + && (udev->speed < USB_SPEED_SUPER))
4473 rc = 0;
4474 else
4475 rc = usb_port_suspend(udev, msg);
4476 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
4477 index e94bf91cc58a..df4569df7eaf 100644
4478 --- a/drivers/usb/dwc3/core.c
4479 +++ b/drivers/usb/dwc3/core.c
4480 @@ -119,6 +119,9 @@ static void __dwc3_set_mode(struct work_struct *work)
4481 if (dwc->dr_mode != USB_DR_MODE_OTG)
4482 return;
4483
4484 + if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG)
4485 + return;
4486 +
4487 switch (dwc->current_dr_role) {
4488 case DWC3_GCTL_PRTCAP_HOST:
4489 dwc3_host_exit(dwc);
4490 diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
4491 index 3ba11136ebf0..c961a94d136b 100644
4492 --- a/drivers/usb/dwc3/dwc3-pci.c
4493 +++ b/drivers/usb/dwc3/dwc3-pci.c
4494 @@ -222,7 +222,7 @@ static int dwc3_pci_probe(struct pci_dev *pci,
4495 ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
4496 if (ret) {
4497 dev_err(dev, "couldn't add resources to dwc3 device\n");
4498 - return ret;
4499 + goto err;
4500 }
4501
4502 dwc->pci = pci;
4503 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
4504 index 2bda4eb1e9ac..100454c514d5 100644
4505 --- a/drivers/usb/dwc3/gadget.c
4506 +++ b/drivers/usb/dwc3/gadget.c
4507 @@ -166,18 +166,8 @@ static void dwc3_ep_inc_deq(struct dwc3_ep *dep)
4508 dwc3_ep_inc_trb(&dep->trb_dequeue);
4509 }
4510
4511 -/**
4512 - * dwc3_gadget_giveback - call struct usb_request's ->complete callback
4513 - * @dep: The endpoint to whom the request belongs to
4514 - * @req: The request we're giving back
4515 - * @status: completion code for the request
4516 - *
4517 - * Must be called with controller's lock held and interrupts disabled. This
4518 - * function will unmap @req and call its ->complete() callback to notify upper
4519 - * layers that it has completed.
4520 - */
4521 -void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
4522 - int status)
4523 +void dwc3_gadget_del_and_unmap_request(struct dwc3_ep *dep,
4524 + struct dwc3_request *req, int status)
4525 {
4526 struct dwc3 *dwc = dep->dwc;
4527
4528 @@ -190,18 +180,35 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
4529
4530 if (req->trb)
4531 usb_gadget_unmap_request_by_dev(dwc->sysdev,
4532 - &req->request, req->direction);
4533 + &req->request, req->direction);
4534
4535 req->trb = NULL;
4536 -
4537 trace_dwc3_gadget_giveback(req);
4538
4539 + if (dep->number > 1)
4540 + pm_runtime_put(dwc->dev);
4541 +}
4542 +
4543 +/**
4544 + * dwc3_gadget_giveback - call struct usb_request's ->complete callback
4545 + * @dep: The endpoint to whom the request belongs to
4546 + * @req: The request we're giving back
4547 + * @status: completion code for the request
4548 + *
4549 + * Must be called with controller's lock held and interrupts disabled. This
4550 + * function will unmap @req and call its ->complete() callback to notify upper
4551 + * layers that it has completed.
4552 + */
4553 +void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
4554 + int status)
4555 +{
4556 + struct dwc3 *dwc = dep->dwc;
4557 +
4558 + dwc3_gadget_del_and_unmap_request(dep, req, status);
4559 +
4560 spin_unlock(&dwc->lock);
4561 usb_gadget_giveback_request(&dep->endpoint, &req->request);
4562 spin_lock(&dwc->lock);
4563 -
4564 - if (dep->number > 1)
4565 - pm_runtime_put(dwc->dev);
4566 }
4567
4568 /**
4569 @@ -1227,7 +1234,7 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep)
4570 if (req->trb)
4571 memset(req->trb, 0, sizeof(struct dwc3_trb));
4572 dep->queued_requests--;
4573 - dwc3_gadget_giveback(dep, req, ret);
4574 + dwc3_gadget_del_and_unmap_request(dep, req, ret);
4575 return ret;
4576 }
4577
4578 diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
4579 index 4eb96b91cc40..e8f35db42394 100644
4580 --- a/drivers/usb/gadget/function/f_midi.c
4581 +++ b/drivers/usb/gadget/function/f_midi.c
4582 @@ -404,7 +404,8 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
4583 if (err) {
4584 ERROR(midi, "%s: couldn't enqueue request: %d\n",
4585 midi->out_ep->name, err);
4586 - free_ep_req(midi->out_ep, req);
4587 + if (req->buf != NULL)
4588 + free_ep_req(midi->out_ep, req);
4589 return err;
4590 }
4591 }
4592 diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
4593 index c3fbef2bb5db..09f90447fed5 100644
4594 --- a/drivers/usb/gadget/u_f.h
4595 +++ b/drivers/usb/gadget/u_f.h
4596 @@ -61,7 +61,9 @@ struct usb_request *alloc_ep_req(struct usb_ep *ep, size_t len);
4597 /* Frees a usb_request previously allocated by alloc_ep_req() */
4598 static inline void free_ep_req(struct usb_ep *ep, struct usb_request *req)
4599 {
4600 + WARN_ON(req->buf == NULL);
4601 kfree(req->buf);
4602 + req->buf = NULL;
4603 usb_ep_free_request(ep, req);
4604 }
4605
4606 diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
4607 index 1f8b19d9cf97..6a266687ca99 100644
4608 --- a/drivers/usb/gadget/udc/core.c
4609 +++ b/drivers/usb/gadget/udc/core.c
4610 @@ -238,6 +238,9 @@ EXPORT_SYMBOL_GPL(usb_ep_free_request);
4611 * arranges to poll once per interval, and the gadget driver usually will
4612 * have queued some data to transfer at that time.
4613 *
4614 + * Note that @req's ->complete() callback must never be called from
4615 + * within usb_ep_queue() as that can create deadlock situations.
4616 + *
4617 * Returns zero, or a negative error code. Endpoints that are not enabled
4618 * report errors; errors will also be
4619 * reported when the usb peripheral is disconnected.
4620 diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
4621 index 18da4873e52e..91a5027b5c1f 100644
4622 --- a/drivers/usb/musb/musb_gadget_ep0.c
4623 +++ b/drivers/usb/musb/musb_gadget_ep0.c
4624 @@ -89,15 +89,19 @@ static int service_tx_status_request(
4625 }
4626
4627 is_in = epnum & USB_DIR_IN;
4628 - if (is_in) {
4629 - epnum &= 0x0f;
4630 + epnum &= 0x0f;
4631 + if (epnum >= MUSB_C_NUM_EPS) {
4632 + handled = -EINVAL;
4633 + break;
4634 + }
4635 +
4636 + if (is_in)
4637 ep = &musb->endpoints[epnum].ep_in;
4638 - } else {
4639 + else
4640 ep = &musb->endpoints[epnum].ep_out;
4641 - }
4642 regs = musb->endpoints[epnum].regs;
4643
4644 - if (epnum >= MUSB_C_NUM_EPS || !ep->desc) {
4645 + if (!ep->desc) {
4646 handled = -EINVAL;
4647 break;
4648 }
4649 diff --git a/drivers/watchdog/f71808e_wdt.c b/drivers/watchdog/f71808e_wdt.c
4650 index 3a33c5344bd5..9a1c761258ce 100644
4651 --- a/drivers/watchdog/f71808e_wdt.c
4652 +++ b/drivers/watchdog/f71808e_wdt.c
4653 @@ -496,7 +496,7 @@ static bool watchdog_is_running(void)
4654
4655 is_running = (superio_inb(watchdog.sioaddr, SIO_REG_ENABLE) & BIT(0))
4656 && (superio_inb(watchdog.sioaddr, F71808FG_REG_WDT_CONF)
4657 - & F71808FG_FLAG_WD_EN);
4658 + & BIT(F71808FG_FLAG_WD_EN));
4659
4660 superio_exit(watchdog.sioaddr);
4661
4662 diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
4663 index 82e8f6edfb48..b12e37f27530 100644
4664 --- a/fs/autofs4/root.c
4665 +++ b/fs/autofs4/root.c
4666 @@ -749,7 +749,7 @@ static int autofs4_dir_mkdir(struct inode *dir,
4667
4668 autofs4_del_active(dentry);
4669
4670 - inode = autofs4_get_inode(dir->i_sb, S_IFDIR | 0555);
4671 + inode = autofs4_get_inode(dir->i_sb, S_IFDIR | mode);
4672 if (!inode)
4673 return -ENOMEM;
4674 d_add(dentry, inode);
4675 diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
4676 index c6ec5aa46100..236313efd347 100644
4677 --- a/fs/ceph/inode.c
4678 +++ b/fs/ceph/inode.c
4679 @@ -660,13 +660,15 @@ void ceph_fill_file_time(struct inode *inode, int issued,
4680 CEPH_CAP_FILE_BUFFER|
4681 CEPH_CAP_AUTH_EXCL|
4682 CEPH_CAP_XATTR_EXCL)) {
4683 - if (timespec_compare(ctime, &inode->i_ctime) > 0) {
4684 + if (ci->i_version == 0 ||
4685 + timespec_compare(ctime, &inode->i_ctime) > 0) {
4686 dout("ctime %ld.%09ld -> %ld.%09ld inc w/ cap\n",
4687 inode->i_ctime.tv_sec, inode->i_ctime.tv_nsec,
4688 ctime->tv_sec, ctime->tv_nsec);
4689 inode->i_ctime = *ctime;
4690 }
4691 - if (ceph_seq_cmp(time_warp_seq, ci->i_time_warp_seq) > 0) {
4692 + if (ci->i_version == 0 ||
4693 + ceph_seq_cmp(time_warp_seq, ci->i_time_warp_seq) > 0) {
4694 /* the MDS did a utimes() */
4695 dout("mtime %ld.%09ld -> %ld.%09ld "
4696 "tw %d -> %d\n",
4697 @@ -786,7 +788,6 @@ static int fill_inode(struct inode *inode, struct page *locked_page,
4698 new_issued = ~issued & le32_to_cpu(info->cap.caps);
4699
4700 /* update inode */
4701 - ci->i_version = le64_to_cpu(info->version);
4702 inode->i_rdev = le32_to_cpu(info->rdev);
4703 inode->i_blkbits = fls(le32_to_cpu(info->layout.fl_stripe_unit)) - 1;
4704
4705 @@ -857,6 +858,9 @@ static int fill_inode(struct inode *inode, struct page *locked_page,
4706 xattr_blob = NULL;
4707 }
4708
4709 + /* finally update i_version */
4710 + ci->i_version = le64_to_cpu(info->version);
4711 +
4712 inode->i_mapping->a_ops = &ceph_aops;
4713
4714 switch (inode->i_mode & S_IFMT) {
4715 diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig
4716 index 687da62daf4e..e901ef6a4813 100644
4717 --- a/fs/cifs/Kconfig
4718 +++ b/fs/cifs/Kconfig
4719 @@ -189,6 +189,7 @@ config CIFS_NFSD_EXPORT
4720 config CIFS_SMB311
4721 bool "SMB3.1.1 network file system support (Experimental)"
4722 depends on CIFS
4723 + select CRYPTO_SHA512
4724
4725 help
4726 This enables experimental support for the newest, SMB3.1.1, dialect.
4727 diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
4728 index f2b0a7f124da..a6ef088e057b 100644
4729 --- a/fs/cifs/cifsencrypt.c
4730 +++ b/fs/cifs/cifsencrypt.c
4731 @@ -36,37 +36,6 @@
4732 #include <crypto/skcipher.h>
4733 #include <crypto/aead.h>
4734
4735 -static int
4736 -cifs_crypto_shash_md5_allocate(struct TCP_Server_Info *server)
4737 -{
4738 - int rc;
4739 - unsigned int size;
4740 -
4741 - if (server->secmech.sdescmd5 != NULL)
4742 - return 0; /* already allocated */
4743 -
4744 - server->secmech.md5 = crypto_alloc_shash("md5", 0, 0);
4745 - if (IS_ERR(server->secmech.md5)) {
4746 - cifs_dbg(VFS, "could not allocate crypto md5\n");
4747 - rc = PTR_ERR(server->secmech.md5);
4748 - server->secmech.md5 = NULL;
4749 - return rc;
4750 - }
4751 -
4752 - size = sizeof(struct shash_desc) +
4753 - crypto_shash_descsize(server->secmech.md5);
4754 - server->secmech.sdescmd5 = kmalloc(size, GFP_KERNEL);
4755 - if (!server->secmech.sdescmd5) {
4756 - crypto_free_shash(server->secmech.md5);
4757 - server->secmech.md5 = NULL;
4758 - return -ENOMEM;
4759 - }
4760 - server->secmech.sdescmd5->shash.tfm = server->secmech.md5;
4761 - server->secmech.sdescmd5->shash.flags = 0x0;
4762 -
4763 - return 0;
4764 -}
4765 -
4766 int __cifs_calc_signature(struct smb_rqst *rqst,
4767 struct TCP_Server_Info *server, char *signature,
4768 struct shash_desc *shash)
4769 @@ -132,13 +101,10 @@ static int cifs_calc_signature(struct smb_rqst *rqst,
4770 if (!rqst->rq_iov || !signature || !server)
4771 return -EINVAL;
4772
4773 - if (!server->secmech.sdescmd5) {
4774 - rc = cifs_crypto_shash_md5_allocate(server);
4775 - if (rc) {
4776 - cifs_dbg(VFS, "%s: Can't alloc md5 crypto\n", __func__);
4777 - return -1;
4778 - }
4779 - }
4780 + rc = cifs_alloc_hash("md5", &server->secmech.md5,
4781 + &server->secmech.sdescmd5);
4782 + if (rc)
4783 + return -1;
4784
4785 rc = crypto_shash_init(&server->secmech.sdescmd5->shash);
4786 if (rc) {
4787 @@ -663,37 +629,6 @@ CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
4788 return rc;
4789 }
4790
4791 -static int crypto_hmacmd5_alloc(struct TCP_Server_Info *server)
4792 -{
4793 - int rc;
4794 - unsigned int size;
4795 -
4796 - /* check if already allocated */
4797 - if (server->secmech.sdeschmacmd5)
4798 - return 0;
4799 -
4800 - server->secmech.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0);
4801 - if (IS_ERR(server->secmech.hmacmd5)) {
4802 - cifs_dbg(VFS, "could not allocate crypto hmacmd5\n");
4803 - rc = PTR_ERR(server->secmech.hmacmd5);
4804 - server->secmech.hmacmd5 = NULL;
4805 - return rc;
4806 - }
4807 -
4808 - size = sizeof(struct shash_desc) +
4809 - crypto_shash_descsize(server->secmech.hmacmd5);
4810 - server->secmech.sdeschmacmd5 = kmalloc(size, GFP_KERNEL);
4811 - if (!server->secmech.sdeschmacmd5) {
4812 - crypto_free_shash(server->secmech.hmacmd5);
4813 - server->secmech.hmacmd5 = NULL;
4814 - return -ENOMEM;
4815 - }
4816 - server->secmech.sdeschmacmd5->shash.tfm = server->secmech.hmacmd5;
4817 - server->secmech.sdeschmacmd5->shash.flags = 0x0;
4818 -
4819 - return 0;
4820 -}
4821 -
4822 int
4823 setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
4824 {
4825 @@ -757,9 +692,10 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
4826
4827 mutex_lock(&ses->server->srv_mutex);
4828
4829 - rc = crypto_hmacmd5_alloc(ses->server);
4830 + rc = cifs_alloc_hash("hmac(md5)",
4831 + &ses->server->secmech.hmacmd5,
4832 + &ses->server->secmech.sdeschmacmd5);
4833 if (rc) {
4834 - cifs_dbg(VFS, "could not crypto alloc hmacmd5 rc %d\n", rc);
4835 goto unlock;
4836 }
4837
4838 @@ -893,6 +829,11 @@ cifs_crypto_secmech_release(struct TCP_Server_Info *server)
4839 server->secmech.md5 = NULL;
4840 }
4841
4842 + if (server->secmech.sha512) {
4843 + crypto_free_shash(server->secmech.sha512);
4844 + server->secmech.sha512 = NULL;
4845 + }
4846 +
4847 if (server->secmech.hmacmd5) {
4848 crypto_free_shash(server->secmech.hmacmd5);
4849 server->secmech.hmacmd5 = NULL;
4850 @@ -916,4 +857,6 @@ cifs_crypto_secmech_release(struct TCP_Server_Info *server)
4851 server->secmech.sdeschmacmd5 = NULL;
4852 kfree(server->secmech.sdescmd5);
4853 server->secmech.sdescmd5 = NULL;
4854 + kfree(server->secmech.sdescsha512);
4855 + server->secmech.sdescsha512 = NULL;
4856 }
4857 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
4858 index 32cdea67bbfd..f715609b13f3 100644
4859 --- a/fs/cifs/cifsfs.c
4860 +++ b/fs/cifs/cifsfs.c
4861 @@ -1486,6 +1486,7 @@ MODULE_SOFTDEP("pre: nls");
4862 MODULE_SOFTDEP("pre: aes");
4863 MODULE_SOFTDEP("pre: cmac");
4864 MODULE_SOFTDEP("pre: sha256");
4865 +MODULE_SOFTDEP("pre: sha512");
4866 MODULE_SOFTDEP("pre: aead2");
4867 MODULE_SOFTDEP("pre: ccm");
4868 module_init(init_cifs)
4869 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
4870 index 48f7c197cd2d..edc640db0842 100644
4871 --- a/fs/cifs/cifsglob.h
4872 +++ b/fs/cifs/cifsglob.h
4873 @@ -130,10 +130,12 @@ struct cifs_secmech {
4874 struct crypto_shash *md5; /* md5 hash function */
4875 struct crypto_shash *hmacsha256; /* hmac-sha256 hash function */
4876 struct crypto_shash *cmacaes; /* block-cipher based MAC function */
4877 + struct crypto_shash *sha512; /* sha512 hash function */
4878 struct sdesc *sdeschmacmd5; /* ctxt to generate ntlmv2 hash, CR1 */
4879 struct sdesc *sdescmd5; /* ctxt to generate cifs/smb signature */
4880 struct sdesc *sdeschmacsha256; /* ctxt to generate smb2 signature */
4881 struct sdesc *sdesccmacaes; /* ctxt to generate smb3 signature */
4882 + struct sdesc *sdescsha512; /* ctxt to generate smb3.11 signing key */
4883 struct crypto_aead *ccmaesencrypt; /* smb3 encryption aead */
4884 struct crypto_aead *ccmaesdecrypt; /* smb3 decryption aead */
4885 };
4886 @@ -673,7 +675,8 @@ struct TCP_Server_Info {
4887 unsigned int max_read;
4888 unsigned int max_write;
4889 #ifdef CONFIG_CIFS_SMB311
4890 - __u8 preauth_sha_hash[64]; /* save initital negprot hash */
4891 + /* save initital negprot hash */
4892 + __u8 preauth_sha_hash[SMB2_PREAUTH_HASH_SIZE];
4893 #endif /* 3.1.1 */
4894 struct delayed_work reconnect; /* reconnect workqueue job */
4895 struct mutex reconnect_mutex; /* prevent simultaneous reconnects */
4896 @@ -862,7 +865,7 @@ struct cifs_ses {
4897 __u8 smb3encryptionkey[SMB3_SIGN_KEY_SIZE];
4898 __u8 smb3decryptionkey[SMB3_SIGN_KEY_SIZE];
4899 #ifdef CONFIG_CIFS_SMB311
4900 - __u8 preauth_sha_hash[64];
4901 + __u8 preauth_sha_hash[SMB2_PREAUTH_HASH_SIZE];
4902 #endif /* 3.1.1 */
4903 };
4904
4905 @@ -1466,6 +1469,7 @@ struct dfs_info3_param {
4906 #define CIFS_FATTR_NEED_REVAL 0x4
4907 #define CIFS_FATTR_INO_COLLISION 0x8
4908 #define CIFS_FATTR_UNKNOWN_NLINK 0x10
4909 +#define CIFS_FATTR_FAKE_ROOT_INO 0x20
4910
4911 struct cifs_fattr {
4912 u32 cf_flags;
4913 diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
4914 index 93d565186698..365a414a75e9 100644
4915 --- a/fs/cifs/cifsproto.h
4916 +++ b/fs/cifs/cifsproto.h
4917 @@ -542,4 +542,9 @@ enum securityEnum cifs_select_sectype(struct TCP_Server_Info *,
4918 struct cifs_aio_ctx *cifs_aio_ctx_alloc(void);
4919 void cifs_aio_ctx_release(struct kref *refcount);
4920 int setup_aio_ctx_iter(struct cifs_aio_ctx *ctx, struct iov_iter *iter, int rw);
4921 +
4922 +int cifs_alloc_hash(const char *name, struct crypto_shash **shash,
4923 + struct sdesc **sdesc);
4924 +void cifs_free_hash(struct crypto_shash **shash, struct sdesc **sdesc);
4925 +
4926 #endif /* _CIFSPROTO_H */
4927 diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
4928 index 8f9a8cc7cc62..ef8580139cef 100644
4929 --- a/fs/cifs/inode.c
4930 +++ b/fs/cifs/inode.c
4931 @@ -707,6 +707,18 @@ cifs_get_file_info(struct file *filp)
4932 return rc;
4933 }
4934
4935 +/* Simple function to return a 64 bit hash of string. Rarely called */
4936 +static __u64 simple_hashstr(const char *str)
4937 +{
4938 + const __u64 hash_mult = 1125899906842597L; /* a big enough prime */
4939 + __u64 hash = 0;
4940 +
4941 + while (*str)
4942 + hash = (hash + (__u64) *str++) * hash_mult;
4943 +
4944 + return hash;
4945 +}
4946 +
4947 int
4948 cifs_get_inode_info(struct inode **inode, const char *full_path,
4949 FILE_ALL_INFO *data, struct super_block *sb, int xid,
4950 @@ -816,6 +828,14 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
4951 tmprc);
4952 fattr.cf_uniqueid = iunique(sb, ROOT_I);
4953 cifs_autodisable_serverino(cifs_sb);
4954 + } else if ((fattr.cf_uniqueid == 0) &&
4955 + strlen(full_path) == 0) {
4956 + /* some servers ret bad root ino ie 0 */
4957 + cifs_dbg(FYI, "Invalid (0) inodenum\n");
4958 + fattr.cf_flags |=
4959 + CIFS_FATTR_FAKE_ROOT_INO;
4960 + fattr.cf_uniqueid =
4961 + simple_hashstr(tcon->treeName);
4962 }
4963 }
4964 } else
4965 @@ -832,6 +852,16 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
4966 &fattr.cf_uniqueid, data);
4967 if (tmprc)
4968 fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid;
4969 + else if ((fattr.cf_uniqueid == 0) &&
4970 + strlen(full_path) == 0) {
4971 + /*
4972 + * Reuse existing root inode num since
4973 + * inum zero for root causes ls of . and .. to
4974 + * not be returned
4975 + */
4976 + cifs_dbg(FYI, "Srv ret 0 inode num for root\n");
4977 + fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid;
4978 + }
4979 } else
4980 fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid;
4981 }
4982 @@ -893,6 +923,9 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
4983 }
4984
4985 cgii_exit:
4986 + if ((*inode) && ((*inode)->i_ino == 0))
4987 + cifs_dbg(FYI, "inode number of zero returned\n");
4988 +
4989 kfree(buf);
4990 cifs_put_tlink(tlink);
4991 return rc;
4992 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
4993 index 60b5a11ee11b..889a840172eb 100644
4994 --- a/fs/cifs/link.c
4995 +++ b/fs/cifs/link.c
4996 @@ -50,25 +50,12 @@ static int
4997 symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
4998 {
4999 int rc;
5000 - unsigned int size;
5001 - struct crypto_shash *md5;
5002 - struct sdesc *sdescmd5;
5003 -
5004 - md5 = crypto_alloc_shash("md5", 0, 0);
5005 - if (IS_ERR(md5)) {
5006 - rc = PTR_ERR(md5);
5007 - cifs_dbg(VFS, "%s: Crypto md5 allocation error %d\n",
5008 - __func__, rc);
5009 - return rc;
5010 - }
5011 - size = sizeof(struct shash_desc) + crypto_shash_descsize(md5);
5012 - sdescmd5 = kmalloc(size, GFP_KERNEL);
5013 - if (!sdescmd5) {
5014 - rc = -ENOMEM;
5015 + struct crypto_shash *md5 = NULL;
5016 + struct sdesc *sdescmd5 = NULL;
5017 +
5018 + rc = cifs_alloc_hash("md5", &md5, &sdescmd5);
5019 + if (rc)
5020 goto symlink_hash_err;
5021 - }
5022 - sdescmd5->shash.tfm = md5;
5023 - sdescmd5->shash.flags = 0x0;
5024
5025 rc = crypto_shash_init(&sdescmd5->shash);
5026 if (rc) {
5027 @@ -85,9 +72,7 @@ symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
5028 cifs_dbg(VFS, "%s: Could not generate md5 hash\n", __func__);
5029
5030 symlink_hash_err:
5031 - crypto_free_shash(md5);
5032 - kfree(sdescmd5);
5033 -
5034 + cifs_free_hash(&md5, &sdescmd5);
5035 return rc;
5036 }
5037
5038 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
5039 index a0dbced4a45c..460084a8eac5 100644
5040 --- a/fs/cifs/misc.c
5041 +++ b/fs/cifs/misc.c
5042 @@ -848,3 +848,57 @@ setup_aio_ctx_iter(struct cifs_aio_ctx *ctx, struct iov_iter *iter, int rw)
5043 iov_iter_bvec(&ctx->iter, ITER_BVEC | rw, ctx->bv, npages, ctx->len);
5044 return 0;
5045 }
5046 +
5047 +/**
5048 + * cifs_alloc_hash - allocate hash and hash context together
5049 + *
5050 + * The caller has to make sure @sdesc is initialized to either NULL or
5051 + * a valid context. Both can be freed via cifs_free_hash().
5052 + */
5053 +int
5054 +cifs_alloc_hash(const char *name,
5055 + struct crypto_shash **shash, struct sdesc **sdesc)
5056 +{
5057 + int rc = 0;
5058 + size_t size;
5059 +
5060 + if (*sdesc != NULL)
5061 + return 0;
5062 +
5063 + *shash = crypto_alloc_shash(name, 0, 0);
5064 + if (IS_ERR(*shash)) {
5065 + cifs_dbg(VFS, "could not allocate crypto %s\n", name);
5066 + rc = PTR_ERR(*shash);
5067 + *shash = NULL;
5068 + *sdesc = NULL;
5069 + return rc;
5070 + }
5071 +
5072 + size = sizeof(struct shash_desc) + crypto_shash_descsize(*shash);
5073 + *sdesc = kmalloc(size, GFP_KERNEL);
5074 + if (*sdesc == NULL) {
5075 + cifs_dbg(VFS, "no memory left to allocate crypto %s\n", name);
5076 + crypto_free_shash(*shash);
5077 + *shash = NULL;
5078 + return -ENOMEM;
5079 + }
5080 +
5081 + (*sdesc)->shash.tfm = *shash;
5082 + (*sdesc)->shash.flags = 0x0;
5083 + return 0;
5084 +}
5085 +
5086 +/**
5087 + * cifs_free_hash - free hash and hash context together
5088 + *
5089 + * Freeing a NULL hash or context is safe.
5090 + */
5091 +void
5092 +cifs_free_hash(struct crypto_shash **shash, struct sdesc **sdesc)
5093 +{
5094 + kfree(*sdesc);
5095 + *sdesc = NULL;
5096 + if (*shash)
5097 + crypto_free_shash(*shash);
5098 + *shash = NULL;
5099 +}
5100 diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c
5101 index 76d03abaa38c..da012c3ab700 100644
5102 --- a/fs/cifs/smb2misc.c
5103 +++ b/fs/cifs/smb2misc.c
5104 @@ -706,3 +706,67 @@ smb2_handle_cancelled_mid(char *buffer, struct TCP_Server_Info *server)
5105
5106 return 0;
5107 }
5108 +
5109 +#ifdef CONFIG_CIFS_SMB311
5110 +/**
5111 + * smb311_update_preauth_hash - update @ses hash with the packet data in @iov
5112 + *
5113 + * Assumes @iov does not contain the rfc1002 length and iov[0] has the
5114 + * SMB2 header.
5115 + */
5116 +int
5117 +smb311_update_preauth_hash(struct cifs_ses *ses, struct kvec *iov, int nvec)
5118 +{
5119 + int i, rc;
5120 + struct sdesc *d;
5121 + struct smb2_sync_hdr *hdr;
5122 +
5123 + if (ses->server->tcpStatus == CifsGood) {
5124 + /* skip non smb311 connections */
5125 + if (ses->server->dialect != SMB311_PROT_ID)
5126 + return 0;
5127 +
5128 + /* skip last sess setup response */
5129 + hdr = (struct smb2_sync_hdr *)iov[0].iov_base;
5130 + if (hdr->Flags & SMB2_FLAGS_SIGNED)
5131 + return 0;
5132 + }
5133 +
5134 + rc = smb311_crypto_shash_allocate(ses->server);
5135 + if (rc)
5136 + return rc;
5137 +
5138 + d = ses->server->secmech.sdescsha512;
5139 + rc = crypto_shash_init(&d->shash);
5140 + if (rc) {
5141 + cifs_dbg(VFS, "%s: could not init sha512 shash\n", __func__);
5142 + return rc;
5143 + }
5144 +
5145 + rc = crypto_shash_update(&d->shash, ses->preauth_sha_hash,
5146 + SMB2_PREAUTH_HASH_SIZE);
5147 + if (rc) {
5148 + cifs_dbg(VFS, "%s: could not update sha512 shash\n", __func__);
5149 + return rc;
5150 + }
5151 +
5152 + for (i = 0; i < nvec; i++) {
5153 + rc = crypto_shash_update(&d->shash,
5154 + iov[i].iov_base, iov[i].iov_len);
5155 + if (rc) {
5156 + cifs_dbg(VFS, "%s: could not update sha512 shash\n",
5157 + __func__);
5158 + return rc;
5159 + }
5160 + }
5161 +
5162 + rc = crypto_shash_final(&d->shash, ses->preauth_sha_hash);
5163 + if (rc) {
5164 + cifs_dbg(VFS, "%s: could not finalize sha512 shash\n",
5165 + __func__);
5166 + return rc;
5167 + }
5168 +
5169 + return 0;
5170 +}
5171 +#endif
5172 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
5173 index eb68e2fcc500..dfd6fb02b7a3 100644
5174 --- a/fs/cifs/smb2ops.c
5175 +++ b/fs/cifs/smb2ops.c
5176 @@ -2066,6 +2066,15 @@ fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, struct smb_rqst *old_rq)
5177 inc_rfc1001_len(tr_hdr, orig_len);
5178 }
5179
5180 +/* We can not use the normal sg_set_buf() as we will sometimes pass a
5181 + * stack object as buf.
5182 + */
5183 +static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
5184 + unsigned int buflen)
5185 +{
5186 + sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
5187 +}
5188 +
5189 static struct scatterlist *
5190 init_sg(struct smb_rqst *rqst, u8 *sign)
5191 {
5192 @@ -2080,16 +2089,16 @@ init_sg(struct smb_rqst *rqst, u8 *sign)
5193 return NULL;
5194
5195 sg_init_table(sg, sg_len);
5196 - sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len);
5197 + smb2_sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len);
5198 for (i = 1; i < rqst->rq_nvec; i++)
5199 - sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base,
5200 + smb2_sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base,
5201 rqst->rq_iov[i].iov_len);
5202 for (j = 0; i < sg_len - 1; i++, j++) {
5203 unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz
5204 : rqst->rq_tailsz;
5205 sg_set_page(&sg[i], rqst->rq_pages[j], len, 0);
5206 }
5207 - sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE);
5208 + smb2_sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE);
5209 return sg;
5210 }
5211
5212 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
5213 index 63778ac22fd9..af62c75b17c4 100644
5214 --- a/fs/cifs/smb2pdu.c
5215 +++ b/fs/cifs/smb2pdu.c
5216 @@ -453,6 +453,10 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
5217 return rc;
5218
5219 req->sync_hdr.SessionId = 0;
5220 +#ifdef CONFIG_CIFS_SMB311
5221 + memset(server->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE);
5222 + memset(ses->preauth_sha_hash, 0, SMB2_PREAUTH_HASH_SIZE);
5223 +#endif
5224
5225 if (strcmp(ses->server->vals->version_string,
5226 SMB3ANY_VERSION_STRING) == 0) {
5227 @@ -564,6 +568,15 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
5228
5229 /* BB: add check that dialect was valid given dialect(s) we asked for */
5230
5231 +#ifdef CONFIG_CIFS_SMB311
5232 + /*
5233 + * Keep a copy of the hash after negprot. This hash will be
5234 + * the starting hash value for all sessions made from this
5235 + * server.
5236 + */
5237 + memcpy(server->preauth_sha_hash, ses->preauth_sha_hash,
5238 + SMB2_PREAUTH_HASH_SIZE);
5239 +#endif
5240 /* SMB2 only has an extended negflavor */
5241 server->negflavor = CIFS_NEGFLAVOR_EXTENDED;
5242 /* set it to the maximum buffer size value we can send with 1 credit */
5243 @@ -621,6 +634,10 @@ int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon)
5244 return 0;
5245 #endif
5246
5247 + /* In SMB3.11 preauth integrity supersedes validate negotiate */
5248 + if (tcon->ses->server->dialect == SMB311_PROT_ID)
5249 + return 0;
5250 +
5251 /*
5252 * validation ioctl must be signed, so no point sending this if we
5253 * can not sign it (ie are not known user). Even if signing is not
5254 @@ -1148,6 +1165,14 @@ SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
5255 sess_data->buf0_type = CIFS_NO_BUFFER;
5256 sess_data->nls_cp = (struct nls_table *) nls_cp;
5257
5258 +#ifdef CONFIG_CIFS_SMB311
5259 + /*
5260 + * Initialize the session hash with the server one.
5261 + */
5262 + memcpy(ses->preauth_sha_hash, ses->server->preauth_sha_hash,
5263 + SMB2_PREAUTH_HASH_SIZE);
5264 +#endif
5265 +
5266 while (sess_data->func)
5267 sess_data->func(sess_data);
5268
5269 @@ -1280,6 +1305,11 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
5270 iov[1].iov_base = unc_path;
5271 iov[1].iov_len = unc_path_len;
5272
5273 + /* 3.11 tcon req must be signed if not encrypted. See MS-SMB2 3.2.4.1.1 */
5274 + if ((ses->server->dialect == SMB311_PROT_ID) &&
5275 + !encryption_required(tcon))
5276 + req->sync_hdr.Flags |= SMB2_FLAGS_SIGNED;
5277 +
5278 rc = smb2_send_recv(xid, ses, iov, 2, &resp_buftype, flags, &rsp_iov);
5279 cifs_small_buf_release(req);
5280 rsp = (struct smb2_tree_connect_rsp *)rsp_iov.iov_base;
5281 @@ -1738,8 +1768,10 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
5282 rc = alloc_path_with_tree_prefix(&copy_path, &copy_size,
5283 &name_len,
5284 tcon->treeName, path);
5285 - if (rc)
5286 + if (rc) {
5287 + cifs_small_buf_release(req);
5288 return rc;
5289 + }
5290 req->NameLength = cpu_to_le16(name_len * 2);
5291 uni_path_len = copy_size;
5292 path = copy_path;
5293 @@ -1750,8 +1782,10 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
5294 if (uni_path_len % 8 != 0) {
5295 copy_size = roundup(uni_path_len, 8);
5296 copy_path = kzalloc(copy_size, GFP_KERNEL);
5297 - if (!copy_path)
5298 + if (!copy_path) {
5299 + cifs_small_buf_release(req);
5300 return -ENOMEM;
5301 + }
5302 memcpy((char *)copy_path, (const char *)path,
5303 uni_path_len);
5304 uni_path_len = copy_size;
5305 diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
5306 index 2a2b34ccaf49..8b901c69a65a 100644
5307 --- a/fs/cifs/smb2pdu.h
5308 +++ b/fs/cifs/smb2pdu.h
5309 @@ -264,6 +264,7 @@ struct smb2_negotiate_req {
5310 #define SMB311_SALT_SIZE 32
5311 /* Hash Algorithm Types */
5312 #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
5313 +#define SMB2_PREAUTH_HASH_SIZE 64
5314
5315 struct smb2_preauth_neg_context {
5316 __le16 ContextType; /* 1 */
5317 diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h
5318 index 05287b01f596..cbcce3f7e86f 100644
5319 --- a/fs/cifs/smb2proto.h
5320 +++ b/fs/cifs/smb2proto.h
5321 @@ -202,4 +202,9 @@ extern int smb3_validate_negotiate(const unsigned int, struct cifs_tcon *);
5322
5323 extern enum securityEnum smb2_select_sectype(struct TCP_Server_Info *,
5324 enum securityEnum);
5325 +#ifdef CONFIG_CIFS_SMB311
5326 +extern int smb311_crypto_shash_allocate(struct TCP_Server_Info *server);
5327 +extern int smb311_update_preauth_hash(struct cifs_ses *ses,
5328 + struct kvec *iov, int nvec);
5329 +#endif
5330 #endif /* _SMB2PROTO_H */
5331 diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c
5332 index 99493946e2f9..bf49cb73b9e6 100644
5333 --- a/fs/cifs/smb2transport.c
5334 +++ b/fs/cifs/smb2transport.c
5335 @@ -43,77 +43,62 @@
5336 static int
5337 smb2_crypto_shash_allocate(struct TCP_Server_Info *server)
5338 {
5339 - int rc;
5340 - unsigned int size;
5341 + return cifs_alloc_hash("hmac(sha256)",
5342 + &server->secmech.hmacsha256,
5343 + &server->secmech.sdeschmacsha256);
5344 +}
5345
5346 - if (server->secmech.sdeschmacsha256 != NULL)
5347 - return 0; /* already allocated */
5348 +static int
5349 +smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
5350 +{
5351 + struct cifs_secmech *p = &server->secmech;
5352 + int rc;
5353
5354 - server->secmech.hmacsha256 = crypto_alloc_shash("hmac(sha256)", 0, 0);
5355 - if (IS_ERR(server->secmech.hmacsha256)) {
5356 - cifs_dbg(VFS, "could not allocate crypto hmacsha256\n");
5357 - rc = PTR_ERR(server->secmech.hmacsha256);
5358 - server->secmech.hmacsha256 = NULL;
5359 - return rc;
5360 - }
5361 + rc = cifs_alloc_hash("hmac(sha256)",
5362 + &p->hmacsha256,
5363 + &p->sdeschmacsha256);
5364 + if (rc)
5365 + goto err;
5366
5367 - size = sizeof(struct shash_desc) +
5368 - crypto_shash_descsize(server->secmech.hmacsha256);
5369 - server->secmech.sdeschmacsha256 = kmalloc(size, GFP_KERNEL);
5370 - if (!server->secmech.sdeschmacsha256) {
5371 - crypto_free_shash(server->secmech.hmacsha256);
5372 - server->secmech.hmacsha256 = NULL;
5373 - return -ENOMEM;
5374 - }
5375 - server->secmech.sdeschmacsha256->shash.tfm = server->secmech.hmacsha256;
5376 - server->secmech.sdeschmacsha256->shash.flags = 0x0;
5377 + rc = cifs_alloc_hash("cmac(aes)", &p->cmacaes, &p->sdesccmacaes);
5378 + if (rc)
5379 + goto err;
5380
5381 return 0;
5382 +err:
5383 + cifs_free_hash(&p->hmacsha256, &p->sdeschmacsha256);
5384 + return rc;
5385 }
5386
5387 -static int
5388 -smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
5389 +#ifdef CONFIG_CIFS_SMB311
5390 +int
5391 +smb311_crypto_shash_allocate(struct TCP_Server_Info *server)
5392 {
5393 - unsigned int size;
5394 - int rc;
5395 -
5396 - if (server->secmech.sdesccmacaes != NULL)
5397 - return 0; /* already allocated */
5398 + struct cifs_secmech *p = &server->secmech;
5399 + int rc = 0;
5400
5401 - rc = smb2_crypto_shash_allocate(server);
5402 + rc = cifs_alloc_hash("hmac(sha256)",
5403 + &p->hmacsha256,
5404 + &p->sdeschmacsha256);
5405 if (rc)
5406 return rc;
5407
5408 - server->secmech.cmacaes = crypto_alloc_shash("cmac(aes)", 0, 0);
5409 - if (IS_ERR(server->secmech.cmacaes)) {
5410 - cifs_dbg(VFS, "could not allocate crypto cmac-aes");
5411 - kfree(server->secmech.sdeschmacsha256);
5412 - server->secmech.sdeschmacsha256 = NULL;
5413 - crypto_free_shash(server->secmech.hmacsha256);
5414 - server->secmech.hmacsha256 = NULL;
5415 - rc = PTR_ERR(server->secmech.cmacaes);
5416 - server->secmech.cmacaes = NULL;
5417 - return rc;
5418 - }
5419 + rc = cifs_alloc_hash("cmac(aes)", &p->cmacaes, &p->sdesccmacaes);
5420 + if (rc)
5421 + goto err;
5422
5423 - size = sizeof(struct shash_desc) +
5424 - crypto_shash_descsize(server->secmech.cmacaes);
5425 - server->secmech.sdesccmacaes = kmalloc(size, GFP_KERNEL);
5426 - if (!server->secmech.sdesccmacaes) {
5427 - cifs_dbg(VFS, "%s: Can't alloc cmacaes\n", __func__);
5428 - kfree(server->secmech.sdeschmacsha256);
5429 - server->secmech.sdeschmacsha256 = NULL;
5430 - crypto_free_shash(server->secmech.hmacsha256);
5431 - crypto_free_shash(server->secmech.cmacaes);
5432 - server->secmech.hmacsha256 = NULL;
5433 - server->secmech.cmacaes = NULL;
5434 - return -ENOMEM;
5435 - }
5436 - server->secmech.sdesccmacaes->shash.tfm = server->secmech.cmacaes;
5437 - server->secmech.sdesccmacaes->shash.flags = 0x0;
5438 + rc = cifs_alloc_hash("sha512", &p->sha512, &p->sdescsha512);
5439 + if (rc)
5440 + goto err;
5441
5442 return 0;
5443 +
5444 +err:
5445 + cifs_free_hash(&p->cmacaes, &p->sdesccmacaes);
5446 + cifs_free_hash(&p->hmacsha256, &p->sdeschmacsha256);
5447 + return rc;
5448 }
5449 +#endif
5450
5451 static struct cifs_ses *
5452 smb2_find_smb_ses_unlocked(struct TCP_Server_Info *server, __u64 ses_id)
5453 @@ -457,7 +442,7 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
5454 cifs_dbg(VFS, "%s: Could not init cmac aes\n", __func__);
5455 return rc;
5456 }
5457 -
5458 +
5459 rc = __cifs_calc_signature(rqst, server, sigptr,
5460 &server->secmech.sdesccmacaes->shash);
5461
5462 diff --git a/fs/cifs/smbdirect.c b/fs/cifs/smbdirect.c
5463 index 91710eb571fb..52cccdbb7e14 100644
5464 --- a/fs/cifs/smbdirect.c
5465 +++ b/fs/cifs/smbdirect.c
5466 @@ -862,6 +862,8 @@ static int smbd_post_send_negotiate_req(struct smbd_connection *info)
5467 ib_dma_unmap_single(info->id->device, request->sge[0].addr,
5468 request->sge[0].length, DMA_TO_DEVICE);
5469
5470 + smbd_disconnect_rdma_connection(info);
5471 +
5472 dma_mapping_failed:
5473 mempool_free(request, info->request_mempool);
5474 return rc;
5475 @@ -1061,6 +1063,7 @@ static int smbd_post_send(struct smbd_connection *info,
5476 if (atomic_dec_and_test(&info->send_pending))
5477 wake_up(&info->wait_send_pending);
5478 }
5479 + smbd_disconnect_rdma_connection(info);
5480 } else
5481 /* Reset timer for idle connection after packet is sent */
5482 mod_delayed_work(info->workqueue, &info->idle_timer_work,
5483 @@ -1202,7 +1205,7 @@ static int smbd_post_recv(
5484 if (rc) {
5485 ib_dma_unmap_single(info->id->device, response->sge.addr,
5486 response->sge.length, DMA_FROM_DEVICE);
5487 -
5488 + smbd_disconnect_rdma_connection(info);
5489 log_rdma_recv(ERR, "ib_post_recv failed rc=%d\n", rc);
5490 }
5491
5492 @@ -1498,8 +1501,8 @@ int smbd_reconnect(struct TCP_Server_Info *server)
5493 log_rdma_event(INFO, "reconnecting rdma session\n");
5494
5495 if (!server->smbd_conn) {
5496 - log_rdma_event(ERR, "rdma session already destroyed\n");
5497 - return -EINVAL;
5498 + log_rdma_event(INFO, "rdma session already destroyed\n");
5499 + goto create_conn;
5500 }
5501
5502 /*
5503 @@ -1512,15 +1515,19 @@ int smbd_reconnect(struct TCP_Server_Info *server)
5504 }
5505
5506 /* wait until the transport is destroyed */
5507 - wait_event(server->smbd_conn->wait_destroy,
5508 - server->smbd_conn->transport_status == SMBD_DESTROYED);
5509 + if (!wait_event_timeout(server->smbd_conn->wait_destroy,
5510 + server->smbd_conn->transport_status == SMBD_DESTROYED, 5*HZ))
5511 + return -EAGAIN;
5512
5513 destroy_workqueue(server->smbd_conn->workqueue);
5514 kfree(server->smbd_conn);
5515
5516 +create_conn:
5517 log_rdma_event(INFO, "creating rdma session\n");
5518 server->smbd_conn = smbd_get_connection(
5519 server, (struct sockaddr *) &server->dstaddr);
5520 + log_rdma_event(INFO, "created rdma session info=%p\n",
5521 + server->smbd_conn);
5522
5523 return server->smbd_conn ? 0 : -ENOENT;
5524 }
5525 @@ -2542,6 +2549,8 @@ struct smbd_mr *smbd_register_mr(
5526 if (atomic_dec_and_test(&info->mr_used_count))
5527 wake_up(&info->wait_for_mr_cleanup);
5528
5529 + smbd_disconnect_rdma_connection(info);
5530 +
5531 return NULL;
5532 }
5533
5534 diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c
5535 index c12bffefa3c9..a0b80ac651a6 100644
5536 --- a/fs/cifs/smbencrypt.c
5537 +++ b/fs/cifs/smbencrypt.c
5538 @@ -121,25 +121,12 @@ int
5539 mdfour(unsigned char *md4_hash, unsigned char *link_str, int link_len)
5540 {
5541 int rc;
5542 - unsigned int size;
5543 - struct crypto_shash *md4;
5544 - struct sdesc *sdescmd4;
5545 -
5546 - md4 = crypto_alloc_shash("md4", 0, 0);
5547 - if (IS_ERR(md4)) {
5548 - rc = PTR_ERR(md4);
5549 - cifs_dbg(VFS, "%s: Crypto md4 allocation error %d\n",
5550 - __func__, rc);
5551 - return rc;
5552 - }
5553 - size = sizeof(struct shash_desc) + crypto_shash_descsize(md4);
5554 - sdescmd4 = kmalloc(size, GFP_KERNEL);
5555 - if (!sdescmd4) {
5556 - rc = -ENOMEM;
5557 + struct crypto_shash *md4 = NULL;
5558 + struct sdesc *sdescmd4 = NULL;
5559 +
5560 + rc = cifs_alloc_hash("md4", &md4, &sdescmd4);
5561 + if (rc)
5562 goto mdfour_err;
5563 - }
5564 - sdescmd4->shash.tfm = md4;
5565 - sdescmd4->shash.flags = 0x0;
5566
5567 rc = crypto_shash_init(&sdescmd4->shash);
5568 if (rc) {
5569 @@ -156,9 +143,7 @@ mdfour(unsigned char *md4_hash, unsigned char *link_str, int link_len)
5570 cifs_dbg(VFS, "%s: Could not generate md4 hash\n", __func__);
5571
5572 mdfour_err:
5573 - crypto_free_shash(md4);
5574 - kfree(sdescmd4);
5575 -
5576 + cifs_free_hash(&md4, &sdescmd4);
5577 return rc;
5578 }
5579
5580 diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
5581 index 9779b3292d8e..665661464067 100644
5582 --- a/fs/cifs/transport.c
5583 +++ b/fs/cifs/transport.c
5584 @@ -37,6 +37,7 @@
5585 #include "cifsglob.h"
5586 #include "cifsproto.h"
5587 #include "cifs_debug.h"
5588 +#include "smb2proto.h"
5589 #include "smbdirect.h"
5590
5591 /* Max number of iovectors we can use off the stack when sending requests. */
5592 @@ -751,6 +752,12 @@ cifs_send_recv(const unsigned int xid, struct cifs_ses *ses,
5593 if (rc < 0)
5594 goto out;
5595
5596 +#ifdef CONFIG_CIFS_SMB311
5597 + if (ses->status == CifsNew)
5598 + smb311_update_preauth_hash(ses, rqst->rq_iov+1,
5599 + rqst->rq_nvec-1);
5600 +#endif
5601 +
5602 if (timeout == CIFS_ASYNC_OP)
5603 goto out;
5604
5605 @@ -789,6 +796,16 @@ cifs_send_recv(const unsigned int xid, struct cifs_ses *ses,
5606 else
5607 *resp_buf_type = CIFS_SMALL_BUFFER;
5608
5609 +#ifdef CONFIG_CIFS_SMB311
5610 + if (ses->status == CifsNew) {
5611 + struct kvec iov = {
5612 + .iov_base = buf + 4,
5613 + .iov_len = get_rfc1002_length(buf)
5614 + };
5615 + smb311_update_preauth_hash(ses, &iov, 1);
5616 + }
5617 +#endif
5618 +
5619 credits = ses->server->ops->get_credits(midQ);
5620
5621 rc = ses->server->ops->check_receive(midQ, ses->server,
5622 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
5623 index f9b3e0a83526..f82c4966f4ce 100644
5624 --- a/fs/ext4/balloc.c
5625 +++ b/fs/ext4/balloc.c
5626 @@ -243,8 +243,6 @@ static int ext4_init_block_bitmap(struct super_block *sb,
5627 */
5628 ext4_mark_bitmap_end(num_clusters_in_group(sb, block_group),
5629 sb->s_blocksize * 8, bh->b_data);
5630 - ext4_block_bitmap_csum_set(sb, block_group, gdp, bh);
5631 - ext4_group_desc_csum_set(sb, block_group, gdp);
5632 return 0;
5633 }
5634
5635 @@ -448,6 +446,7 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
5636 err = ext4_init_block_bitmap(sb, bh, block_group, desc);
5637 set_bitmap_uptodate(bh);
5638 set_buffer_uptodate(bh);
5639 + set_buffer_verified(bh);
5640 ext4_unlock_group(sb, block_group);
5641 unlock_buffer(bh);
5642 if (err) {
5643 diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
5644 index da87cf757f7d..e2902d394f1b 100644
5645 --- a/fs/ext4/dir.c
5646 +++ b/fs/ext4/dir.c
5647 @@ -365,13 +365,15 @@ static loff_t ext4_dir_llseek(struct file *file, loff_t offset, int whence)
5648 {
5649 struct inode *inode = file->f_mapping->host;
5650 int dx_dir = is_dx_dir(inode);
5651 - loff_t htree_max = ext4_get_htree_eof(file);
5652 + loff_t ret, htree_max = ext4_get_htree_eof(file);
5653
5654 if (likely(dx_dir))
5655 - return generic_file_llseek_size(file, offset, whence,
5656 + ret = generic_file_llseek_size(file, offset, whence,
5657 htree_max, htree_max);
5658 else
5659 - return ext4_llseek(file, offset, whence);
5660 + ret = ext4_llseek(file, offset, whence);
5661 + file->f_version = inode_peek_iversion(inode) - 1;
5662 + return ret;
5663 }
5664
5665 /*
5666 diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
5667 index 2d593201cf7a..7c70b08d104c 100644
5668 --- a/fs/ext4/ext4_jbd2.c
5669 +++ b/fs/ext4/ext4_jbd2.c
5670 @@ -166,13 +166,6 @@ int __ext4_journal_get_write_access(const char *where, unsigned int line,
5671 might_sleep();
5672
5673 if (ext4_handle_valid(handle)) {
5674 - struct super_block *sb;
5675 -
5676 - sb = handle->h_transaction->t_journal->j_private;
5677 - if (unlikely(ext4_forced_shutdown(EXT4_SB(sb)))) {
5678 - jbd2_journal_abort_handle(handle);
5679 - return -EIO;
5680 - }
5681 err = jbd2_journal_get_write_access(handle, bh);
5682 if (err)
5683 ext4_journal_abort_handle(where, line, __func__, bh,
5684 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
5685 index 7830d28df331..3fa93665b4a3 100644
5686 --- a/fs/ext4/ialloc.c
5687 +++ b/fs/ext4/ialloc.c
5688 @@ -66,44 +66,6 @@ void ext4_mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
5689 memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3);
5690 }
5691
5692 -/* Initializes an uninitialized inode bitmap */
5693 -static int ext4_init_inode_bitmap(struct super_block *sb,
5694 - struct buffer_head *bh,
5695 - ext4_group_t block_group,
5696 - struct ext4_group_desc *gdp)
5697 -{
5698 - struct ext4_group_info *grp;
5699 - struct ext4_sb_info *sbi = EXT4_SB(sb);
5700 - J_ASSERT_BH(bh, buffer_locked(bh));
5701 -
5702 - /* If checksum is bad mark all blocks and inodes use to prevent
5703 - * allocation, essentially implementing a per-group read-only flag. */
5704 - if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) {
5705 - grp = ext4_get_group_info(sb, block_group);
5706 - if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
5707 - percpu_counter_sub(&sbi->s_freeclusters_counter,
5708 - grp->bb_free);
5709 - set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state);
5710 - if (!EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) {
5711 - int count;
5712 - count = ext4_free_inodes_count(sb, gdp);
5713 - percpu_counter_sub(&sbi->s_freeinodes_counter,
5714 - count);
5715 - }
5716 - set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state);
5717 - return -EFSBADCRC;
5718 - }
5719 -
5720 - memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8);
5721 - ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), sb->s_blocksize * 8,
5722 - bh->b_data);
5723 - ext4_inode_bitmap_csum_set(sb, block_group, gdp, bh,
5724 - EXT4_INODES_PER_GROUP(sb) / 8);
5725 - ext4_group_desc_csum_set(sb, block_group, gdp);
5726 -
5727 - return 0;
5728 -}
5729 -
5730 void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate)
5731 {
5732 if (uptodate) {
5733 @@ -187,17 +149,14 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
5734
5735 ext4_lock_group(sb, block_group);
5736 if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {
5737 - err = ext4_init_inode_bitmap(sb, bh, block_group, desc);
5738 + memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8);
5739 + ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb),
5740 + sb->s_blocksize * 8, bh->b_data);
5741 set_bitmap_uptodate(bh);
5742 set_buffer_uptodate(bh);
5743 set_buffer_verified(bh);
5744 ext4_unlock_group(sb, block_group);
5745 unlock_buffer(bh);
5746 - if (err) {
5747 - ext4_error(sb, "Failed to init inode bitmap for group "
5748 - "%u: %d", block_group, err);
5749 - goto out;
5750 - }
5751 return bh;
5752 }
5753 ext4_unlock_group(sb, block_group);
5754 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
5755 index c94780075b04..3350454fc5a7 100644
5756 --- a/fs/ext4/inode.c
5757 +++ b/fs/ext4/inode.c
5758 @@ -3524,7 +3524,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
5759 iomap->flags |= IOMAP_F_DIRTY;
5760 iomap->bdev = inode->i_sb->s_bdev;
5761 iomap->dax_dev = sbi->s_daxdev;
5762 - iomap->offset = first_block << blkbits;
5763 + iomap->offset = (u64)first_block << blkbits;
5764 iomap->length = (u64)map.m_len << blkbits;
5765
5766 if (ret == 0) {
5767 @@ -3658,7 +3658,6 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
5768 {
5769 struct file *file = iocb->ki_filp;
5770 struct inode *inode = file->f_mapping->host;
5771 - struct ext4_inode_info *ei = EXT4_I(inode);
5772 ssize_t ret;
5773 loff_t offset = iocb->ki_pos;
5774 size_t count = iov_iter_count(iter);
5775 @@ -3682,7 +3681,7 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
5776 goto out;
5777 }
5778 orphan = 1;
5779 - ei->i_disksize = inode->i_size;
5780 + ext4_update_i_disksize(inode, inode->i_size);
5781 ext4_journal_stop(handle);
5782 }
5783
5784 @@ -3790,7 +3789,7 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
5785 if (ret > 0) {
5786 loff_t end = offset + ret;
5787 if (end > inode->i_size) {
5788 - ei->i_disksize = end;
5789 + ext4_update_i_disksize(inode, end);
5790 i_size_write(inode, end);
5791 /*
5792 * We're going to return a positive `ret'
5793 @@ -4746,6 +4745,12 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
5794 goto bad_inode;
5795 raw_inode = ext4_raw_inode(&iloc);
5796
5797 + if ((ino == EXT4_ROOT_INO) && (raw_inode->i_links_count == 0)) {
5798 + EXT4_ERROR_INODE(inode, "root inode unallocated");
5799 + ret = -EFSCORRUPTED;
5800 + goto bad_inode;
5801 + }
5802 +
5803 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
5804 ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize);
5805 if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
5806 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
5807 index 7e99ad02f1ba..be8d78472ef8 100644
5808 --- a/fs/ext4/ioctl.c
5809 +++ b/fs/ext4/ioctl.c
5810 @@ -492,15 +492,13 @@ static int ext4_shutdown(struct super_block *sb, unsigned long arg)
5811 set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
5812 if (sbi->s_journal && !is_journal_aborted(sbi->s_journal)) {
5813 (void) ext4_force_commit(sb);
5814 - jbd2_journal_abort(sbi->s_journal, 0);
5815 + jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN);
5816 }
5817 break;
5818 case EXT4_GOING_FLAGS_NOLOGFLUSH:
5819 set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags);
5820 - if (sbi->s_journal && !is_journal_aborted(sbi->s_journal)) {
5821 - msleep(100);
5822 - jbd2_journal_abort(sbi->s_journal, 0);
5823 - }
5824 + if (sbi->s_journal && !is_journal_aborted(sbi->s_journal))
5825 + jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN);
5826 break;
5827 default:
5828 return -EINVAL;
5829 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
5830 index 39bf464c35f1..192c5ad09d71 100644
5831 --- a/fs/ext4/super.c
5832 +++ b/fs/ext4/super.c
5833 @@ -2333,6 +2333,8 @@ static int ext4_check_descriptors(struct super_block *sb,
5834 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
5835 "Block bitmap for group %u overlaps "
5836 "superblock", i);
5837 + if (!sb_rdonly(sb))
5838 + return 0;
5839 }
5840 if (block_bitmap < first_block || block_bitmap > last_block) {
5841 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
5842 @@ -2345,6 +2347,8 @@ static int ext4_check_descriptors(struct super_block *sb,
5843 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
5844 "Inode bitmap for group %u overlaps "
5845 "superblock", i);
5846 + if (!sb_rdonly(sb))
5847 + return 0;
5848 }
5849 if (inode_bitmap < first_block || inode_bitmap > last_block) {
5850 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
5851 @@ -2357,6 +2361,8 @@ static int ext4_check_descriptors(struct super_block *sb,
5852 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
5853 "Inode table for group %u overlaps "
5854 "superblock", i);
5855 + if (!sb_rdonly(sb))
5856 + return 0;
5857 }
5858 if (inode_table < first_block ||
5859 inode_table + sbi->s_itb_per_group - 1 > last_block) {
5860 @@ -3490,15 +3496,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
5861 }
5862
5863 /* Load the checksum driver */
5864 - if (ext4_has_feature_metadata_csum(sb) ||
5865 - ext4_has_feature_ea_inode(sb)) {
5866 - sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
5867 - if (IS_ERR(sbi->s_chksum_driver)) {
5868 - ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
5869 - ret = PTR_ERR(sbi->s_chksum_driver);
5870 - sbi->s_chksum_driver = NULL;
5871 - goto failed_mount;
5872 - }
5873 + sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
5874 + if (IS_ERR(sbi->s_chksum_driver)) {
5875 + ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
5876 + ret = PTR_ERR(sbi->s_chksum_driver);
5877 + sbi->s_chksum_driver = NULL;
5878 + goto failed_mount;
5879 }
5880
5881 /* Check superblock checksum */
5882 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
5883 index 63656dbafdc4..499cb4b1fbd2 100644
5884 --- a/fs/ext4/xattr.c
5885 +++ b/fs/ext4/xattr.c
5886 @@ -195,10 +195,13 @@ ext4_xattr_check_entries(struct ext4_xattr_entry *entry, void *end,
5887
5888 /* Check the values */
5889 while (!IS_LAST_ENTRY(entry)) {
5890 - if (entry->e_value_size != 0 &&
5891 - entry->e_value_inum == 0) {
5892 + u32 size = le32_to_cpu(entry->e_value_size);
5893 +
5894 + if (size > EXT4_XATTR_SIZE_MAX)
5895 + return -EFSCORRUPTED;
5896 +
5897 + if (size != 0 && entry->e_value_inum == 0) {
5898 u16 offs = le16_to_cpu(entry->e_value_offs);
5899 - u32 size = le32_to_cpu(entry->e_value_size);
5900 void *value;
5901
5902 /*
5903 @@ -222,25 +225,36 @@ ext4_xattr_check_entries(struct ext4_xattr_entry *entry, void *end,
5904 }
5905
5906 static inline int
5907 -ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh)
5908 +__ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh,
5909 + const char *function, unsigned int line)
5910 {
5911 - int error;
5912 + int error = -EFSCORRUPTED;
5913
5914 if (buffer_verified(bh))
5915 return 0;
5916
5917 if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
5918 BHDR(bh)->h_blocks != cpu_to_le32(1))
5919 - return -EFSCORRUPTED;
5920 + goto errout;
5921 + error = -EFSBADCRC;
5922 if (!ext4_xattr_block_csum_verify(inode, bh))
5923 - return -EFSBADCRC;
5924 + goto errout;
5925 error = ext4_xattr_check_entries(BFIRST(bh), bh->b_data + bh->b_size,
5926 bh->b_data);
5927 - if (!error)
5928 +errout:
5929 + if (error)
5930 + __ext4_error_inode(inode, function, line, 0,
5931 + "corrupted xattr block %llu",
5932 + (unsigned long long) bh->b_blocknr);
5933 + else
5934 set_buffer_verified(bh);
5935 return error;
5936 }
5937
5938 +#define ext4_xattr_check_block(inode, bh) \
5939 + __ext4_xattr_check_block((inode), (bh), __func__, __LINE__)
5940 +
5941 +
5942 static int
5943 __xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header,
5944 void *end, const char *function, unsigned int line)
5945 @@ -262,18 +276,22 @@ __xattr_check_inode(struct inode *inode, struct ext4_xattr_ibody_header *header,
5946 __xattr_check_inode((inode), (header), (end), __func__, __LINE__)
5947
5948 static int
5949 -ext4_xattr_find_entry(struct ext4_xattr_entry **pentry, int name_index,
5950 - const char *name, int sorted)
5951 +xattr_find_entry(struct inode *inode, struct ext4_xattr_entry **pentry,
5952 + void *end, int name_index, const char *name, int sorted)
5953 {
5954 - struct ext4_xattr_entry *entry;
5955 + struct ext4_xattr_entry *entry, *next;
5956 size_t name_len;
5957 int cmp = 1;
5958
5959 if (name == NULL)
5960 return -EINVAL;
5961 name_len = strlen(name);
5962 - entry = *pentry;
5963 - for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
5964 + for (entry = *pentry; !IS_LAST_ENTRY(entry); entry = next) {
5965 + next = EXT4_XATTR_NEXT(entry);
5966 + if ((void *) next >= end) {
5967 + EXT4_ERROR_INODE(inode, "corrupted xattr entries");
5968 + return -EFSCORRUPTED;
5969 + }
5970 cmp = name_index - entry->e_name_index;
5971 if (!cmp)
5972 cmp = name_len - entry->e_name_len;
5973 @@ -495,6 +513,7 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
5974 struct buffer_head *bh = NULL;
5975 struct ext4_xattr_entry *entry;
5976 size_t size;
5977 + void *end;
5978 int error;
5979 struct mb_cache *ea_block_cache = EA_BLOCK_CACHE(inode);
5980
5981 @@ -511,20 +530,20 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
5982 goto cleanup;
5983 ea_bdebug(bh, "b_count=%d, refcount=%d",
5984 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
5985 - if (ext4_xattr_check_block(inode, bh)) {
5986 - EXT4_ERROR_INODE(inode, "bad block %llu",
5987 - EXT4_I(inode)->i_file_acl);
5988 - error = -EFSCORRUPTED;
5989 + error = ext4_xattr_check_block(inode, bh);
5990 + if (error)
5991 goto cleanup;
5992 - }
5993 ext4_xattr_block_cache_insert(ea_block_cache, bh);
5994 entry = BFIRST(bh);
5995 - error = ext4_xattr_find_entry(&entry, name_index, name, 1);
5996 + end = bh->b_data + bh->b_size;
5997 + error = xattr_find_entry(inode, &entry, end, name_index, name, 1);
5998 if (error)
5999 goto cleanup;
6000 size = le32_to_cpu(entry->e_value_size);
6001 + error = -ERANGE;
6002 + if (unlikely(size > EXT4_XATTR_SIZE_MAX))
6003 + goto cleanup;
6004 if (buffer) {
6005 - error = -ERANGE;
6006 if (size > buffer_size)
6007 goto cleanup;
6008 if (entry->e_value_inum) {
6009 @@ -533,8 +552,12 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
6010 if (error)
6011 goto cleanup;
6012 } else {
6013 - memcpy(buffer, bh->b_data +
6014 - le16_to_cpu(entry->e_value_offs), size);
6015 + u16 offset = le16_to_cpu(entry->e_value_offs);
6016 + void *p = bh->b_data + offset;
6017 +
6018 + if (unlikely(p + size > end))
6019 + goto cleanup;
6020 + memcpy(buffer, p, size);
6021 }
6022 }
6023 error = size;
6024 @@ -568,12 +591,14 @@ ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
6025 if (error)
6026 goto cleanup;
6027 entry = IFIRST(header);
6028 - error = ext4_xattr_find_entry(&entry, name_index, name, 0);
6029 + error = xattr_find_entry(inode, &entry, end, name_index, name, 0);
6030 if (error)
6031 goto cleanup;
6032 size = le32_to_cpu(entry->e_value_size);
6033 + error = -ERANGE;
6034 + if (unlikely(size > EXT4_XATTR_SIZE_MAX))
6035 + goto cleanup;
6036 if (buffer) {
6037 - error = -ERANGE;
6038 if (size > buffer_size)
6039 goto cleanup;
6040 if (entry->e_value_inum) {
6041 @@ -582,8 +607,12 @@ ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
6042 if (error)
6043 goto cleanup;
6044 } else {
6045 - memcpy(buffer, (void *)IFIRST(header) +
6046 - le16_to_cpu(entry->e_value_offs), size);
6047 + u16 offset = le16_to_cpu(entry->e_value_offs);
6048 + void *p = (void *)IFIRST(header) + offset;
6049 +
6050 + if (unlikely(p + size > end))
6051 + goto cleanup;
6052 + memcpy(buffer, p, size);
6053 }
6054 }
6055 error = size;
6056 @@ -676,12 +705,9 @@ ext4_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size)
6057 goto cleanup;
6058 ea_bdebug(bh, "b_count=%d, refcount=%d",
6059 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
6060 - if (ext4_xattr_check_block(inode, bh)) {
6061 - EXT4_ERROR_INODE(inode, "bad block %llu",
6062 - EXT4_I(inode)->i_file_acl);
6063 - error = -EFSCORRUPTED;
6064 + error = ext4_xattr_check_block(inode, bh);
6065 + if (error)
6066 goto cleanup;
6067 - }
6068 ext4_xattr_block_cache_insert(EA_BLOCK_CACHE(inode), bh);
6069 error = ext4_xattr_list_entries(dentry, BFIRST(bh), buffer, buffer_size);
6070
6071 @@ -808,10 +834,9 @@ int ext4_get_inode_usage(struct inode *inode, qsize_t *usage)
6072 goto out;
6073 }
6074
6075 - if (ext4_xattr_check_block(inode, bh)) {
6076 - ret = -EFSCORRUPTED;
6077 + ret = ext4_xattr_check_block(inode, bh);
6078 + if (ret)
6079 goto out;
6080 - }
6081
6082 for (entry = BFIRST(bh); !IS_LAST_ENTRY(entry);
6083 entry = EXT4_XATTR_NEXT(entry))
6084 @@ -1793,19 +1818,16 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
6085 ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
6086 atomic_read(&(bs->bh->b_count)),
6087 le32_to_cpu(BHDR(bs->bh)->h_refcount));
6088 - if (ext4_xattr_check_block(inode, bs->bh)) {
6089 - EXT4_ERROR_INODE(inode, "bad block %llu",
6090 - EXT4_I(inode)->i_file_acl);
6091 - error = -EFSCORRUPTED;
6092 + error = ext4_xattr_check_block(inode, bs->bh);
6093 + if (error)
6094 goto cleanup;
6095 - }
6096 /* Find the named attribute. */
6097 bs->s.base = BHDR(bs->bh);
6098 bs->s.first = BFIRST(bs->bh);
6099 bs->s.end = bs->bh->b_data + bs->bh->b_size;
6100 bs->s.here = bs->s.first;
6101 - error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
6102 - i->name, 1);
6103 + error = xattr_find_entry(inode, &bs->s.here, bs->s.end,
6104 + i->name_index, i->name, 1);
6105 if (error && error != -ENODATA)
6106 goto cleanup;
6107 bs->s.not_found = error;
6108 @@ -2164,8 +2186,8 @@ int ext4_xattr_ibody_find(struct inode *inode, struct ext4_xattr_info *i,
6109 if (error)
6110 return error;
6111 /* Find the named attribute. */
6112 - error = ext4_xattr_find_entry(&is->s.here, i->name_index,
6113 - i->name, 0);
6114 + error = xattr_find_entry(inode, &is->s.here, is->s.end,
6115 + i->name_index, i->name, 0);
6116 if (error && error != -ENODATA)
6117 return error;
6118 is->s.not_found = error;
6119 @@ -2721,13 +2743,9 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
6120 error = -EIO;
6121 if (!bh)
6122 goto cleanup;
6123 - if (ext4_xattr_check_block(inode, bh)) {
6124 - EXT4_ERROR_INODE(inode, "bad block %llu",
6125 - EXT4_I(inode)->i_file_acl);
6126 - error = -EFSCORRUPTED;
6127 - brelse(bh);
6128 + error = ext4_xattr_check_block(inode, bh);
6129 + if (error)
6130 goto cleanup;
6131 - }
6132 base = BHDR(bh);
6133 end = bh->b_data + bh->b_size;
6134 min_offs = end - base;
6135 @@ -2884,11 +2902,8 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
6136 goto cleanup;
6137 }
6138 error = ext4_xattr_check_block(inode, bh);
6139 - if (error) {
6140 - EXT4_ERROR_INODE(inode, "bad block %llu (error %d)",
6141 - EXT4_I(inode)->i_file_acl, error);
6142 + if (error)
6143 goto cleanup;
6144 - }
6145
6146 if (ext4_has_feature_ea_inode(inode->i_sb)) {
6147 for (entry = BFIRST(bh); !IS_LAST_ENTRY(entry);
6148 diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h
6149 index dd54c4f995c8..f39cad2abe2a 100644
6150 --- a/fs/ext4/xattr.h
6151 +++ b/fs/ext4/xattr.h
6152 @@ -70,6 +70,17 @@ struct ext4_xattr_entry {
6153 EXT4_I(inode)->i_extra_isize))
6154 #define IFIRST(hdr) ((struct ext4_xattr_entry *)((hdr)+1))
6155
6156 +/*
6157 + * XATTR_SIZE_MAX is currently 64k, but for the purposes of checking
6158 + * for file system consistency errors, we use a somewhat bigger value.
6159 + * This allows XATTR_SIZE_MAX to grow in the future, but by using this
6160 + * instead of INT_MAX for certain consistency checks, we don't need to
6161 + * worry about arithmetic overflows. (Actually XATTR_SIZE_MAX is
6162 + * defined in include/uapi/linux/limits.h, so changing it is going
6163 + * not going to be trivial....)
6164 + */
6165 +#define EXT4_XATTR_SIZE_MAX (1 << 24)
6166 +
6167 /*
6168 * The minimum size of EA value when you start storing it in an external inode
6169 * size of block - size of header - size of 1 entry - 4 null bytes
6170 diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
6171 index d4d04fee568a..40c34a0ef58a 100644
6172 --- a/fs/fs-writeback.c
6173 +++ b/fs/fs-writeback.c
6174 @@ -745,11 +745,12 @@ int inode_congested(struct inode *inode, int cong_bits)
6175 */
6176 if (inode && inode_to_wb_is_valid(inode)) {
6177 struct bdi_writeback *wb;
6178 - bool locked, congested;
6179 + struct wb_lock_cookie lock_cookie = {};
6180 + bool congested;
6181
6182 - wb = unlocked_inode_to_wb_begin(inode, &locked);
6183 + wb = unlocked_inode_to_wb_begin(inode, &lock_cookie);
6184 congested = wb_congested(wb, cong_bits);
6185 - unlocked_inode_to_wb_end(inode, locked);
6186 + unlocked_inode_to_wb_end(inode, &lock_cookie);
6187 return congested;
6188 }
6189
6190 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
6191 index 3fbf48ec2188..dfb057900e79 100644
6192 --- a/fs/jbd2/journal.c
6193 +++ b/fs/jbd2/journal.c
6194 @@ -974,7 +974,7 @@ int __jbd2_update_log_tail(journal_t *journal, tid_t tid, unsigned long block)
6195 }
6196
6197 /*
6198 - * This is a variaon of __jbd2_update_log_tail which checks for validity of
6199 + * This is a variation of __jbd2_update_log_tail which checks for validity of
6200 * provided log tail and locks j_checkpoint_mutex. So it is safe against races
6201 * with other threads updating log tail.
6202 */
6203 @@ -1417,6 +1417,9 @@ int jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid,
6204 journal_superblock_t *sb = journal->j_superblock;
6205 int ret;
6206
6207 + if (is_journal_aborted(journal))
6208 + return -EIO;
6209 +
6210 BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex));
6211 jbd_debug(1, "JBD2: updating superblock (start %lu, seq %u)\n",
6212 tail_block, tail_tid);
6213 @@ -1483,12 +1486,15 @@ static void jbd2_mark_journal_empty(journal_t *journal, int write_op)
6214 void jbd2_journal_update_sb_errno(journal_t *journal)
6215 {
6216 journal_superblock_t *sb = journal->j_superblock;
6217 + int errcode;
6218
6219 read_lock(&journal->j_state_lock);
6220 - jbd_debug(1, "JBD2: updating superblock error (errno %d)\n",
6221 - journal->j_errno);
6222 - sb->s_errno = cpu_to_be32(journal->j_errno);
6223 + errcode = journal->j_errno;
6224 read_unlock(&journal->j_state_lock);
6225 + if (errcode == -ESHUTDOWN)
6226 + errcode = 0;
6227 + jbd_debug(1, "JBD2: updating superblock error (errno %d)\n", errcode);
6228 + sb->s_errno = cpu_to_be32(errcode);
6229
6230 jbd2_write_superblock(journal, REQ_SYNC | REQ_FUA);
6231 }
6232 @@ -2105,12 +2111,22 @@ void __jbd2_journal_abort_hard(journal_t *journal)
6233 * but don't do any other IO. */
6234 static void __journal_abort_soft (journal_t *journal, int errno)
6235 {
6236 - if (journal->j_flags & JBD2_ABORT)
6237 - return;
6238 + int old_errno;
6239
6240 - if (!journal->j_errno)
6241 + write_lock(&journal->j_state_lock);
6242 + old_errno = journal->j_errno;
6243 + if (!journal->j_errno || errno == -ESHUTDOWN)
6244 journal->j_errno = errno;
6245
6246 + if (journal->j_flags & JBD2_ABORT) {
6247 + write_unlock(&journal->j_state_lock);
6248 + if (!old_errno && old_errno != -ESHUTDOWN &&
6249 + errno == -ESHUTDOWN)
6250 + jbd2_journal_update_sb_errno(journal);
6251 + return;
6252 + }
6253 + write_unlock(&journal->j_state_lock);
6254 +
6255 __jbd2_journal_abort_hard(journal);
6256
6257 if (errno) {
6258 diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
6259 index f60dee7faf03..87bdf0f4cba1 100644
6260 --- a/fs/jffs2/super.c
6261 +++ b/fs/jffs2/super.c
6262 @@ -342,7 +342,7 @@ static void jffs2_put_super (struct super_block *sb)
6263 static void jffs2_kill_sb(struct super_block *sb)
6264 {
6265 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
6266 - if (!sb_rdonly(sb))
6267 + if (c && !sb_rdonly(sb))
6268 jffs2_stop_garbage_collect_thread(c);
6269 kill_mtd_super(sb);
6270 kfree(c);
6271 diff --git a/fs/namespace.c b/fs/namespace.c
6272 index 9d1374ab6e06..c3ed9dc78655 100644
6273 --- a/fs/namespace.c
6274 +++ b/fs/namespace.c
6275 @@ -1089,7 +1089,8 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,
6276 goto out_free;
6277 }
6278
6279 - mnt->mnt.mnt_flags = old->mnt.mnt_flags & ~(MNT_WRITE_HOLD|MNT_MARKED);
6280 + mnt->mnt.mnt_flags = old->mnt.mnt_flags;
6281 + mnt->mnt.mnt_flags &= ~(MNT_WRITE_HOLD|MNT_MARKED|MNT_INTERNAL);
6282 /* Don't allow unprivileged users to change mount flags */
6283 if (flag & CL_UNPRIVILEGED) {
6284 mnt->mnt.mnt_flags |= MNT_LOCK_ATIME;
6285 diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
6286 index 6702a6a0bbb5..e0e6a9d627df 100644
6287 --- a/fs/notify/fanotify/fanotify.c
6288 +++ b/fs/notify/fanotify/fanotify.c
6289 @@ -92,7 +92,7 @@ static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark,
6290 u32 event_mask,
6291 const void *data, int data_type)
6292 {
6293 - __u32 marks_mask, marks_ignored_mask;
6294 + __u32 marks_mask = 0, marks_ignored_mask = 0;
6295 const struct path *path = data;
6296
6297 pr_debug("%s: inode_mark=%p vfsmnt_mark=%p mask=%x data=%p"
6298 @@ -108,24 +108,20 @@ static bool fanotify_should_send_event(struct fsnotify_mark *inode_mark,
6299 !d_can_lookup(path->dentry))
6300 return false;
6301
6302 - if (inode_mark && vfsmnt_mark) {
6303 - marks_mask = (vfsmnt_mark->mask | inode_mark->mask);
6304 - marks_ignored_mask = (vfsmnt_mark->ignored_mask | inode_mark->ignored_mask);
6305 - } else if (inode_mark) {
6306 - /*
6307 - * if the event is for a child and this inode doesn't care about
6308 - * events on the child, don't send it!
6309 - */
6310 - if ((event_mask & FS_EVENT_ON_CHILD) &&
6311 - !(inode_mark->mask & FS_EVENT_ON_CHILD))
6312 - return false;
6313 - marks_mask = inode_mark->mask;
6314 - marks_ignored_mask = inode_mark->ignored_mask;
6315 - } else if (vfsmnt_mark) {
6316 - marks_mask = vfsmnt_mark->mask;
6317 - marks_ignored_mask = vfsmnt_mark->ignored_mask;
6318 - } else {
6319 - BUG();
6320 + /*
6321 + * if the event is for a child and this inode doesn't care about
6322 + * events on the child, don't send it!
6323 + */
6324 + if (inode_mark &&
6325 + (!(event_mask & FS_EVENT_ON_CHILD) ||
6326 + (inode_mark->mask & FS_EVENT_ON_CHILD))) {
6327 + marks_mask |= inode_mark->mask;
6328 + marks_ignored_mask |= inode_mark->ignored_mask;
6329 + }
6330 +
6331 + if (vfsmnt_mark) {
6332 + marks_mask |= vfsmnt_mark->mask;
6333 + marks_ignored_mask |= vfsmnt_mark->ignored_mask;
6334 }
6335
6336 if (d_is_dir(path->dentry) &&
6337 diff --git a/fs/orangefs/super.c b/fs/orangefs/super.c
6338 index 3ae5fdba0225..10796d3fe27d 100644
6339 --- a/fs/orangefs/super.c
6340 +++ b/fs/orangefs/super.c
6341 @@ -579,6 +579,11 @@ void orangefs_kill_sb(struct super_block *sb)
6342 /* provided sb cleanup */
6343 kill_anon_super(sb);
6344
6345 + if (!ORANGEFS_SB(sb)) {
6346 + mutex_lock(&orangefs_request_mutex);
6347 + mutex_unlock(&orangefs_request_mutex);
6348 + return;
6349 + }
6350 /*
6351 * issue the unmount to userspace to tell it to remove the
6352 * dynamic mount info it has for this superblock
6353 diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
6354 index 70057359fbaf..23148c3ed675 100644
6355 --- a/fs/reiserfs/journal.c
6356 +++ b/fs/reiserfs/journal.c
6357 @@ -2643,7 +2643,7 @@ static int journal_init_dev(struct super_block *super,
6358 if (IS_ERR(journal->j_dev_bd)) {
6359 result = PTR_ERR(journal->j_dev_bd);
6360 journal->j_dev_bd = NULL;
6361 - reiserfs_warning(super,
6362 + reiserfs_warning(super, "sh-457",
6363 "journal_init_dev: Cannot open '%s': %i",
6364 jdev_name, result);
6365 return result;
6366 diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
6367 index b16ef162344a..6c397a389105 100644
6368 --- a/fs/ubifs/super.c
6369 +++ b/fs/ubifs/super.c
6370 @@ -1737,8 +1737,11 @@ static void ubifs_remount_ro(struct ubifs_info *c)
6371
6372 dbg_save_space_info(c);
6373
6374 - for (i = 0; i < c->jhead_cnt; i++)
6375 - ubifs_wbuf_sync(&c->jheads[i].wbuf);
6376 + for (i = 0; i < c->jhead_cnt; i++) {
6377 + err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
6378 + if (err)
6379 + ubifs_ro_mode(c, err);
6380 + }
6381
6382 c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY);
6383 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS);
6384 @@ -1804,8 +1807,11 @@ static void ubifs_put_super(struct super_block *sb)
6385 int err;
6386
6387 /* Synchronize write-buffers */
6388 - for (i = 0; i < c->jhead_cnt; i++)
6389 - ubifs_wbuf_sync(&c->jheads[i].wbuf);
6390 + for (i = 0; i < c->jhead_cnt; i++) {
6391 + err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
6392 + if (err)
6393 + ubifs_ro_mode(c, err);
6394 + }
6395
6396 /*
6397 * We are being cleanly unmounted which means the
6398 diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c
6399 index f897e55f2cd0..16a8ad21b77e 100644
6400 --- a/fs/udf/unicode.c
6401 +++ b/fs/udf/unicode.c
6402 @@ -28,6 +28,9 @@
6403
6404 #include "udf_sb.h"
6405
6406 +#define SURROGATE_MASK 0xfffff800
6407 +#define SURROGATE_PAIR 0x0000d800
6408 +
6409 static int udf_uni2char_utf8(wchar_t uni,
6410 unsigned char *out,
6411 int boundlen)
6412 @@ -37,6 +40,9 @@ static int udf_uni2char_utf8(wchar_t uni,
6413 if (boundlen <= 0)
6414 return -ENAMETOOLONG;
6415
6416 + if ((uni & SURROGATE_MASK) == SURROGATE_PAIR)
6417 + return -EINVAL;
6418 +
6419 if (uni < 0x80) {
6420 out[u_len++] = (unsigned char)uni;
6421 } else if (uni < 0x800) {
6422 diff --git a/include/dt-bindings/clock/mt2701-clk.h b/include/dt-bindings/clock/mt2701-clk.h
6423 index 551f7600ab58..24e93dfcee9f 100644
6424 --- a/include/dt-bindings/clock/mt2701-clk.h
6425 +++ b/include/dt-bindings/clock/mt2701-clk.h
6426 @@ -176,7 +176,8 @@
6427 #define CLK_TOP_AUD_EXT1 156
6428 #define CLK_TOP_AUD_EXT2 157
6429 #define CLK_TOP_NFI1X_PAD 158
6430 -#define CLK_TOP_NR 159
6431 +#define CLK_TOP_AXISEL_D4 159
6432 +#define CLK_TOP_NR 160
6433
6434 /* APMIXEDSYS */
6435
6436 diff --git a/include/linux/backing-dev-defs.h b/include/linux/backing-dev-defs.h
6437 index bfe86b54f6c1..0bd432a4d7bd 100644
6438 --- a/include/linux/backing-dev-defs.h
6439 +++ b/include/linux/backing-dev-defs.h
6440 @@ -223,6 +223,11 @@ static inline void set_bdi_congested(struct backing_dev_info *bdi, int sync)
6441 set_wb_congested(bdi->wb.congested, sync);
6442 }
6443
6444 +struct wb_lock_cookie {
6445 + bool locked;
6446 + unsigned long flags;
6447 +};
6448 +
6449 #ifdef CONFIG_CGROUP_WRITEBACK
6450
6451 /**
6452 diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
6453 index 3e4ce54d84ab..82e8b73117d1 100644
6454 --- a/include/linux/backing-dev.h
6455 +++ b/include/linux/backing-dev.h
6456 @@ -346,7 +346,7 @@ static inline struct bdi_writeback *inode_to_wb(const struct inode *inode)
6457 /**
6458 * unlocked_inode_to_wb_begin - begin unlocked inode wb access transaction
6459 * @inode: target inode
6460 - * @lockedp: temp bool output param, to be passed to the end function
6461 + * @cookie: output param, to be passed to the end function
6462 *
6463 * The caller wants to access the wb associated with @inode but isn't
6464 * holding inode->i_lock, mapping->tree_lock or wb->list_lock. This
6465 @@ -354,12 +354,12 @@ static inline struct bdi_writeback *inode_to_wb(const struct inode *inode)
6466 * association doesn't change until the transaction is finished with
6467 * unlocked_inode_to_wb_end().
6468 *
6469 - * The caller must call unlocked_inode_to_wb_end() with *@lockdep
6470 - * afterwards and can't sleep during transaction. IRQ may or may not be
6471 - * disabled on return.
6472 + * The caller must call unlocked_inode_to_wb_end() with *@cookie afterwards and
6473 + * can't sleep during the transaction. IRQs may or may not be disabled on
6474 + * return.
6475 */
6476 static inline struct bdi_writeback *
6477 -unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
6478 +unlocked_inode_to_wb_begin(struct inode *inode, struct wb_lock_cookie *cookie)
6479 {
6480 rcu_read_lock();
6481
6482 @@ -367,10 +367,10 @@ unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
6483 * Paired with store_release in inode_switch_wb_work_fn() and
6484 * ensures that we see the new wb if we see cleared I_WB_SWITCH.
6485 */
6486 - *lockedp = smp_load_acquire(&inode->i_state) & I_WB_SWITCH;
6487 + cookie->locked = smp_load_acquire(&inode->i_state) & I_WB_SWITCH;
6488
6489 - if (unlikely(*lockedp))
6490 - spin_lock_irq(&inode->i_mapping->tree_lock);
6491 + if (unlikely(cookie->locked))
6492 + spin_lock_irqsave(&inode->i_mapping->tree_lock, cookie->flags);
6493
6494 /*
6495 * Protected by either !I_WB_SWITCH + rcu_read_lock() or tree_lock.
6496 @@ -382,12 +382,13 @@ unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
6497 /**
6498 * unlocked_inode_to_wb_end - end inode wb access transaction
6499 * @inode: target inode
6500 - * @locked: *@lockedp from unlocked_inode_to_wb_begin()
6501 + * @cookie: @cookie from unlocked_inode_to_wb_begin()
6502 */
6503 -static inline void unlocked_inode_to_wb_end(struct inode *inode, bool locked)
6504 +static inline void unlocked_inode_to_wb_end(struct inode *inode,
6505 + struct wb_lock_cookie *cookie)
6506 {
6507 - if (unlikely(locked))
6508 - spin_unlock_irq(&inode->i_mapping->tree_lock);
6509 + if (unlikely(cookie->locked))
6510 + spin_unlock_irqrestore(&inode->i_mapping->tree_lock, cookie->flags);
6511
6512 rcu_read_unlock();
6513 }
6514 @@ -434,12 +435,13 @@ static inline struct bdi_writeback *inode_to_wb(struct inode *inode)
6515 }
6516
6517 static inline struct bdi_writeback *
6518 -unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
6519 +unlocked_inode_to_wb_begin(struct inode *inode, struct wb_lock_cookie *cookie)
6520 {
6521 return inode_to_wb(inode);
6522 }
6523
6524 -static inline void unlocked_inode_to_wb_end(struct inode *inode, bool locked)
6525 +static inline void unlocked_inode_to_wb_end(struct inode *inode,
6526 + struct wb_lock_cookie *cookie)
6527 {
6528 }
6529
6530 diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
6531 index bf18b95ed92d..17b18b91ebac 100644
6532 --- a/include/linux/blk_types.h
6533 +++ b/include/linux/blk_types.h
6534 @@ -20,8 +20,13 @@ typedef void (bio_end_io_t) (struct bio *);
6535
6536 /*
6537 * Block error status values. See block/blk-core:blk_errors for the details.
6538 + * Alpha cannot write a byte atomically, so we need to use 32-bit value.
6539 */
6540 +#if defined(CONFIG_ALPHA) && !defined(__alpha_bwx__)
6541 +typedef u32 __bitwise blk_status_t;
6542 +#else
6543 typedef u8 __bitwise blk_status_t;
6544 +#endif
6545 #define BLK_STS_OK 0
6546 #define BLK_STS_NOTSUPP ((__force blk_status_t)1)
6547 #define BLK_STS_TIMEOUT ((__force blk_status_t)2)
6548 diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
6549 index d3f264a5b04d..ceb96ecab96e 100644
6550 --- a/include/linux/compiler-clang.h
6551 +++ b/include/linux/compiler-clang.h
6552 @@ -17,9 +17,6 @@
6553 */
6554 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
6555
6556 -#define randomized_struct_fields_start struct {
6557 -#define randomized_struct_fields_end };
6558 -
6559 /* all clang versions usable with the kernel support KASAN ABI version 5 */
6560 #define KASAN_ABI_VERSION 5
6561
6562 diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
6563 index e2c7f4369eff..b4bf73f5e38f 100644
6564 --- a/include/linux/compiler-gcc.h
6565 +++ b/include/linux/compiler-gcc.h
6566 @@ -242,6 +242,9 @@
6567 #if defined(RANDSTRUCT_PLUGIN) && !defined(__CHECKER__)
6568 #define __randomize_layout __attribute__((randomize_layout))
6569 #define __no_randomize_layout __attribute__((no_randomize_layout))
6570 +/* This anon struct can add padding, so only enable it under randstruct. */
6571 +#define randomized_struct_fields_start struct {
6572 +#define randomized_struct_fields_end } __randomize_layout;
6573 #endif
6574
6575 #endif /* GCC_VERSION >= 40500 */
6576 @@ -256,15 +259,6 @@
6577 */
6578 #define __visible __attribute__((externally_visible))
6579
6580 -/*
6581 - * RANDSTRUCT_PLUGIN wants to use an anonymous struct, but it is only
6582 - * possible since GCC 4.6. To provide as much build testing coverage
6583 - * as possible, this is used for all GCC 4.6+ builds, and not just on
6584 - * RANDSTRUCT_PLUGIN builds.
6585 - */
6586 -#define randomized_struct_fields_start struct {
6587 -#define randomized_struct_fields_end } __randomize_layout;
6588 -
6589 #endif /* GCC_VERSION >= 40600 */
6590
6591
6592 diff --git a/include/linux/hid.h b/include/linux/hid.h
6593 index 091a81cf330f..29b981b1694d 100644
6594 --- a/include/linux/hid.h
6595 +++ b/include/linux/hid.h
6596 @@ -515,6 +515,12 @@ enum hid_type {
6597 HID_TYPE_USBNONE
6598 };
6599
6600 +enum hid_battery_status {
6601 + HID_BATTERY_UNKNOWN = 0,
6602 + HID_BATTERY_QUERIED, /* Kernel explicitly queried battery strength */
6603 + HID_BATTERY_REPORTED, /* Device sent unsolicited battery strength report */
6604 +};
6605 +
6606 struct hid_driver;
6607 struct hid_ll_driver;
6608
6609 @@ -557,7 +563,8 @@ struct hid_device { /* device report descriptor */
6610 __s32 battery_max;
6611 __s32 battery_report_type;
6612 __s32 battery_report_id;
6613 - bool battery_reported;
6614 + enum hid_battery_status battery_status;
6615 + bool battery_avoid_query;
6616 #endif
6617
6618 unsigned int status; /* see STAT flags above */
6619 @@ -851,7 +858,7 @@ extern int hidinput_connect(struct hid_device *hid, unsigned int force);
6620 extern void hidinput_disconnect(struct hid_device *);
6621
6622 int hid_set_field(struct hid_field *, unsigned, __s32);
6623 -int hid_input_report(struct hid_device *, int type, u8 *, int, int);
6624 +int hid_input_report(struct hid_device *, int type, u8 *, u32, int);
6625 int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field);
6626 struct hid_field *hidinput_get_led_field(struct hid_device *hid);
6627 unsigned int hidinput_count_leds(struct hid_device *hid);
6628 @@ -1102,13 +1109,13 @@ static inline void hid_hw_wait(struct hid_device *hdev)
6629 *
6630 * @report: the report we want to know the length
6631 */
6632 -static inline int hid_report_len(struct hid_report *report)
6633 +static inline u32 hid_report_len(struct hid_report *report)
6634 {
6635 /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */
6636 return ((report->size - 1) >> 3) + 1 + (report->id > 0);
6637 }
6638
6639 -int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
6640 +int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size,
6641 int interrupt);
6642
6643 /* HID quirks API */
6644 diff --git a/include/linux/hmm.h b/include/linux/hmm.h
6645 index 325017ad9311..36dd21fe5caf 100644
6646 --- a/include/linux/hmm.h
6647 +++ b/include/linux/hmm.h
6648 @@ -498,23 +498,16 @@ struct hmm_device {
6649 struct hmm_device *hmm_device_new(void *drvdata);
6650 void hmm_device_put(struct hmm_device *hmm_device);
6651 #endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */
6652 -#endif /* IS_ENABLED(CONFIG_HMM) */
6653
6654 /* Below are for HMM internal use only! Not to be used by device driver! */
6655 -#if IS_ENABLED(CONFIG_HMM_MIRROR)
6656 void hmm_mm_destroy(struct mm_struct *mm);
6657
6658 static inline void hmm_mm_init(struct mm_struct *mm)
6659 {
6660 mm->hmm = NULL;
6661 }
6662 -#else /* IS_ENABLED(CONFIG_HMM_MIRROR) */
6663 -static inline void hmm_mm_destroy(struct mm_struct *mm) {}
6664 -static inline void hmm_mm_init(struct mm_struct *mm) {}
6665 -#endif /* IS_ENABLED(CONFIG_HMM_MIRROR) */
6666 -
6667 -
6668 #else /* IS_ENABLED(CONFIG_HMM) */
6669 static inline void hmm_mm_destroy(struct mm_struct *mm) {}
6670 static inline void hmm_mm_init(struct mm_struct *mm) {}
6671 +#endif /* IS_ENABLED(CONFIG_HMM) */
6672 #endif /* LINUX_HMM_H */
6673 diff --git a/include/linux/mm.h b/include/linux/mm.h
6674 index ad06d42adb1a..95a2d748e978 100644
6675 --- a/include/linux/mm.h
6676 +++ b/include/linux/mm.h
6677 @@ -2604,6 +2604,7 @@ enum mf_action_page_type {
6678 MF_MSG_POISONED_HUGE,
6679 MF_MSG_HUGE,
6680 MF_MSG_FREE_HUGE,
6681 + MF_MSG_NON_PMD_HUGE,
6682 MF_MSG_UNMAP_FAILED,
6683 MF_MSG_DIRTY_SWAPCACHE,
6684 MF_MSG_CLEAN_SWAPCACHE,
6685 diff --git a/include/sound/pcm_oss.h b/include/sound/pcm_oss.h
6686 index 760c969d885d..12bbf8c81112 100644
6687 --- a/include/sound/pcm_oss.h
6688 +++ b/include/sound/pcm_oss.h
6689 @@ -57,6 +57,7 @@ struct snd_pcm_oss_runtime {
6690 char *buffer; /* vmallocated period */
6691 size_t buffer_used; /* used length from period buffer */
6692 struct mutex params_lock;
6693 + atomic_t rw_ref; /* concurrent read/write accesses */
6694 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
6695 struct snd_pcm_plugin *plugin_first;
6696 struct snd_pcm_plugin *plugin_last;
6697 diff --git a/include/uapi/linux/random.h b/include/uapi/linux/random.h
6698 index c34f4490d025..26ee91300e3e 100644
6699 --- a/include/uapi/linux/random.h
6700 +++ b/include/uapi/linux/random.h
6701 @@ -35,6 +35,9 @@
6702 /* Clear the entropy pool and associated counters. (Superuser only.) */
6703 #define RNDCLEARPOOL _IO( 'R', 0x06 )
6704
6705 +/* Reseed CRNG. (Superuser only.) */
6706 +#define RNDRESEEDCRNG _IO( 'R', 0x07 )
6707 +
6708 struct rand_pool_info {
6709 int entropy_count;
6710 int buf_size;
6711 diff --git a/ipc/shm.c b/ipc/shm.c
6712 index 93e0e3a4d009..f68420b1ad93 100644
6713 --- a/ipc/shm.c
6714 +++ b/ipc/shm.c
6715 @@ -203,6 +203,12 @@ static int __shm_open(struct vm_area_struct *vma)
6716 if (IS_ERR(shp))
6717 return PTR_ERR(shp);
6718
6719 + if (shp->shm_file != sfd->file) {
6720 + /* ID was reused */
6721 + shm_unlock(shp);
6722 + return -EINVAL;
6723 + }
6724 +
6725 shp->shm_atim = ktime_get_real_seconds();
6726 shp->shm_lprid = task_tgid_vnr(current);
6727 shp->shm_nattch++;
6728 @@ -431,8 +437,9 @@ static int shm_mmap(struct file *file, struct vm_area_struct *vma)
6729 int ret;
6730
6731 /*
6732 - * In case of remap_file_pages() emulation, the file can represent
6733 - * removed IPC ID: propogate shm_lock() error to caller.
6734 + * In case of remap_file_pages() emulation, the file can represent an
6735 + * IPC ID that was removed, and possibly even reused by another shm
6736 + * segment already. Propagate this case as an error to caller.
6737 */
6738 ret = __shm_open(vma);
6739 if (ret)
6740 @@ -456,6 +463,7 @@ static int shm_release(struct inode *ino, struct file *file)
6741 struct shm_file_data *sfd = shm_file_data(file);
6742
6743 put_ipc_ns(sfd->ns);
6744 + fput(sfd->file);
6745 shm_file_data(file) = NULL;
6746 kfree(sfd);
6747 return 0;
6748 @@ -1402,7 +1410,16 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg,
6749 file->f_mapping = shp->shm_file->f_mapping;
6750 sfd->id = shp->shm_perm.id;
6751 sfd->ns = get_ipc_ns(ns);
6752 - sfd->file = shp->shm_file;
6753 + /*
6754 + * We need to take a reference to the real shm file to prevent the
6755 + * pointer from becoming stale in cases where the lifetime of the outer
6756 + * file extends beyond that of the shm segment. It's not usually
6757 + * possible, but it can happen during remap_file_pages() emulation as
6758 + * that unmaps the memory, then does ->mmap() via file reference only.
6759 + * We'll deny the ->mmap() if the shm segment was since removed, but to
6760 + * detect shm ID reuse we need to compare the file pointers.
6761 + */
6762 + sfd->file = get_file(shp->shm_file);
6763 sfd->vm_ops = NULL;
6764
6765 err = security_mmap_file(file, prot, flags);
6766 diff --git a/kernel/resource.c b/kernel/resource.c
6767 index e270b5048988..2af6c03858b9 100644
6768 --- a/kernel/resource.c
6769 +++ b/kernel/resource.c
6770 @@ -651,7 +651,8 @@ static int __find_resource(struct resource *root, struct resource *old,
6771 alloc.start = constraint->alignf(constraint->alignf_data, &avail,
6772 size, constraint->align);
6773 alloc.end = alloc.start + size - 1;
6774 - if (resource_contains(&avail, &alloc)) {
6775 + if (alloc.start <= alloc.end &&
6776 + resource_contains(&avail, &alloc)) {
6777 new->start = alloc.start;
6778 new->end = alloc.end;
6779 return 0;
6780 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
6781 index dcf1c4dd3efe..7ac7b08b563a 100644
6782 --- a/kernel/trace/ring_buffer.c
6783 +++ b/kernel/trace/ring_buffer.c
6784 @@ -1136,6 +1136,11 @@ static int __rb_allocate_pages(long nr_pages, struct list_head *pages, int cpu)
6785 struct buffer_page *bpage, *tmp;
6786 long i;
6787
6788 + /* Check if the available memory is there first */
6789 + i = si_mem_available();
6790 + if (i < nr_pages)
6791 + return -ENOMEM;
6792 +
6793 for (i = 0; i < nr_pages; i++) {
6794 struct page *page;
6795 /*
6796 diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
6797 index 268029ae1be6..df08863e6d53 100644
6798 --- a/kernel/trace/trace_uprobe.c
6799 +++ b/kernel/trace/trace_uprobe.c
6800 @@ -608,7 +608,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
6801
6802 /* Don't print "0x (null)" when offset is 0 */
6803 if (tu->offset) {
6804 - seq_printf(m, "0x%px", (void *)tu->offset);
6805 + seq_printf(m, "0x%0*lx", (int)(sizeof(void *) * 2), tu->offset);
6806 } else {
6807 switch (sizeof(void *)) {
6808 case 4:
6809 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
6810 index c43ec2271469..44f7eb408fdb 100644
6811 --- a/lib/swiotlb.c
6812 +++ b/lib/swiotlb.c
6813 @@ -732,7 +732,7 @@ swiotlb_alloc_buffer(struct device *dev, size_t size, dma_addr_t *dma_handle,
6814 goto out_warn;
6815
6816 *dma_handle = swiotlb_phys_to_dma(dev, phys_addr);
6817 - if (dma_coherent_ok(dev, *dma_handle, size))
6818 + if (!dma_coherent_ok(dev, *dma_handle, size))
6819 goto out_unmap;
6820
6821 memset(phys_to_virt(phys_addr), 0, size);
6822 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
6823 index d7a708f82559..89f8a4a4b770 100644
6824 --- a/lib/vsprintf.c
6825 +++ b/lib/vsprintf.c
6826 @@ -2591,6 +2591,8 @@ int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args)
6827 case 's':
6828 case 'F':
6829 case 'f':
6830 + case 'x':
6831 + case 'K':
6832 save_arg(void *);
6833 break;
6834 default:
6835 @@ -2765,6 +2767,8 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
6836 case 's':
6837 case 'F':
6838 case 'f':
6839 + case 'x':
6840 + case 'K':
6841 process = true;
6842 break;
6843 default:
6844 diff --git a/mm/filemap.c b/mm/filemap.c
6845 index 693f62212a59..787ff18663bf 100644
6846 --- a/mm/filemap.c
6847 +++ b/mm/filemap.c
6848 @@ -785,7 +785,7 @@ int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask)
6849 VM_BUG_ON_PAGE(!PageLocked(new), new);
6850 VM_BUG_ON_PAGE(new->mapping, new);
6851
6852 - error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM);
6853 + error = radix_tree_preload(gfp_mask & GFP_RECLAIM_MASK);
6854 if (!error) {
6855 struct address_space *mapping = old->mapping;
6856 void (*freepage)(struct page *);
6857 @@ -841,7 +841,7 @@ static int __add_to_page_cache_locked(struct page *page,
6858 return error;
6859 }
6860
6861 - error = radix_tree_maybe_preload(gfp_mask & ~__GFP_HIGHMEM);
6862 + error = radix_tree_maybe_preload(gfp_mask & GFP_RECLAIM_MASK);
6863 if (error) {
6864 if (!huge)
6865 mem_cgroup_cancel_charge(page, memcg, false);
6866 @@ -1584,8 +1584,7 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
6867 if (fgp_flags & FGP_ACCESSED)
6868 __SetPageReferenced(page);
6869
6870 - err = add_to_page_cache_lru(page, mapping, offset,
6871 - gfp_mask & GFP_RECLAIM_MASK);
6872 + err = add_to_page_cache_lru(page, mapping, offset, gfp_mask);
6873 if (unlikely(err)) {
6874 put_page(page);
6875 page = NULL;
6876 @@ -2388,7 +2387,7 @@ static int page_cache_read(struct file *file, pgoff_t offset, gfp_t gfp_mask)
6877 if (!page)
6878 return -ENOMEM;
6879
6880 - ret = add_to_page_cache_lru(page, mapping, offset, gfp_mask & GFP_KERNEL);
6881 + ret = add_to_page_cache_lru(page, mapping, offset, gfp_mask);
6882 if (ret == 0)
6883 ret = mapping->a_ops->readpage(file, page);
6884 else if (ret == -EEXIST)
6885 diff --git a/mm/hmm.c b/mm/hmm.c
6886 index 320545b98ff5..91d3f062dd28 100644
6887 --- a/mm/hmm.c
6888 +++ b/mm/hmm.c
6889 @@ -277,7 +277,8 @@ static int hmm_pfns_bad(unsigned long addr,
6890 unsigned long end,
6891 struct mm_walk *walk)
6892 {
6893 - struct hmm_range *range = walk->private;
6894 + struct hmm_vma_walk *hmm_vma_walk = walk->private;
6895 + struct hmm_range *range = hmm_vma_walk->range;
6896 hmm_pfn_t *pfns = range->pfns;
6897 unsigned long i;
6898
6899 diff --git a/mm/ksm.c b/mm/ksm.c
6900 index 293721f5da70..2d6b35234926 100644
6901 --- a/mm/ksm.c
6902 +++ b/mm/ksm.c
6903 @@ -1131,6 +1131,13 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
6904 } else {
6905 newpte = pte_mkspecial(pfn_pte(page_to_pfn(kpage),
6906 vma->vm_page_prot));
6907 + /*
6908 + * We're replacing an anonymous page with a zero page, which is
6909 + * not anonymous. We need to do proper accounting otherwise we
6910 + * will get wrong values in /proc, and a BUG message in dmesg
6911 + * when tearing down the mm.
6912 + */
6913 + dec_mm_counter(mm, MM_ANONPAGES);
6914 }
6915
6916 flush_cache_page(vma, addr, pte_pfn(*ptep));
6917 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
6918 index 8291b75f42c8..2d4bf647cf01 100644
6919 --- a/mm/memory-failure.c
6920 +++ b/mm/memory-failure.c
6921 @@ -502,6 +502,7 @@ static const char * const action_page_types[] = {
6922 [MF_MSG_POISONED_HUGE] = "huge page already hardware poisoned",
6923 [MF_MSG_HUGE] = "huge page",
6924 [MF_MSG_FREE_HUGE] = "free huge page",
6925 + [MF_MSG_NON_PMD_HUGE] = "non-pmd-sized huge page",
6926 [MF_MSG_UNMAP_FAILED] = "unmapping failed page",
6927 [MF_MSG_DIRTY_SWAPCACHE] = "dirty swapcache page",
6928 [MF_MSG_CLEAN_SWAPCACHE] = "clean swapcache page",
6929 @@ -1084,6 +1085,21 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags)
6930 return 0;
6931 }
6932
6933 + /*
6934 + * TODO: hwpoison for pud-sized hugetlb doesn't work right now, so
6935 + * simply disable it. In order to make it work properly, we need
6936 + * make sure that:
6937 + * - conversion of a pud that maps an error hugetlb into hwpoison
6938 + * entry properly works, and
6939 + * - other mm code walking over page table is aware of pud-aligned
6940 + * hwpoison entries.
6941 + */
6942 + if (huge_page_size(page_hstate(head)) > PMD_SIZE) {
6943 + action_result(pfn, MF_MSG_NON_PMD_HUGE, MF_IGNORED);
6944 + res = -EBUSY;
6945 + goto out;
6946 + }
6947 +
6948 if (!hwpoison_user_mappings(p, pfn, flags, &head)) {
6949 action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED);
6950 res = -EBUSY;
6951 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
6952 index 586f31261c83..8369572e1f7d 100644
6953 --- a/mm/page-writeback.c
6954 +++ b/mm/page-writeback.c
6955 @@ -2501,13 +2501,13 @@ void account_page_redirty(struct page *page)
6956 if (mapping && mapping_cap_account_dirty(mapping)) {
6957 struct inode *inode = mapping->host;
6958 struct bdi_writeback *wb;
6959 - bool locked;
6960 + struct wb_lock_cookie cookie = {};
6961
6962 - wb = unlocked_inode_to_wb_begin(inode, &locked);
6963 + wb = unlocked_inode_to_wb_begin(inode, &cookie);
6964 current->nr_dirtied--;
6965 dec_node_page_state(page, NR_DIRTIED);
6966 dec_wb_stat(wb, WB_DIRTIED);
6967 - unlocked_inode_to_wb_end(inode, locked);
6968 + unlocked_inode_to_wb_end(inode, &cookie);
6969 }
6970 }
6971 EXPORT_SYMBOL(account_page_redirty);
6972 @@ -2613,15 +2613,15 @@ void __cancel_dirty_page(struct page *page)
6973 if (mapping_cap_account_dirty(mapping)) {
6974 struct inode *inode = mapping->host;
6975 struct bdi_writeback *wb;
6976 - bool locked;
6977 + struct wb_lock_cookie cookie = {};
6978
6979 lock_page_memcg(page);
6980 - wb = unlocked_inode_to_wb_begin(inode, &locked);
6981 + wb = unlocked_inode_to_wb_begin(inode, &cookie);
6982
6983 if (TestClearPageDirty(page))
6984 account_page_cleaned(page, mapping, wb);
6985
6986 - unlocked_inode_to_wb_end(inode, locked);
6987 + unlocked_inode_to_wb_end(inode, &cookie);
6988 unlock_page_memcg(page);
6989 } else {
6990 ClearPageDirty(page);
6991 @@ -2653,7 +2653,7 @@ int clear_page_dirty_for_io(struct page *page)
6992 if (mapping && mapping_cap_account_dirty(mapping)) {
6993 struct inode *inode = mapping->host;
6994 struct bdi_writeback *wb;
6995 - bool locked;
6996 + struct wb_lock_cookie cookie = {};
6997
6998 /*
6999 * Yes, Virginia, this is indeed insane.
7000 @@ -2690,14 +2690,14 @@ int clear_page_dirty_for_io(struct page *page)
7001 * always locked coming in here, so we get the desired
7002 * exclusion.
7003 */
7004 - wb = unlocked_inode_to_wb_begin(inode, &locked);
7005 + wb = unlocked_inode_to_wb_begin(inode, &cookie);
7006 if (TestClearPageDirty(page)) {
7007 dec_lruvec_page_state(page, NR_FILE_DIRTY);
7008 dec_zone_page_state(page, NR_ZONE_WRITE_PENDING);
7009 dec_wb_stat(wb, WB_RECLAIMABLE);
7010 ret = 1;
7011 }
7012 - unlocked_inode_to_wb_end(inode, locked);
7013 + unlocked_inode_to_wb_end(inode, &cookie);
7014 return ret;
7015 }
7016 return TestClearPageDirty(page);
7017 diff --git a/mm/slab.c b/mm/slab.c
7018 index 9095c3945425..a76006aae857 100644
7019 --- a/mm/slab.c
7020 +++ b/mm/slab.c
7021 @@ -4074,7 +4074,8 @@ static void cache_reap(struct work_struct *w)
7022 next_reap_node();
7023 out:
7024 /* Set up the next iteration */
7025 - schedule_delayed_work(work, round_jiffies_relative(REAPTIMEOUT_AC));
7026 + schedule_delayed_work_on(smp_processor_id(), work,
7027 + round_jiffies_relative(REAPTIMEOUT_AC));
7028 }
7029
7030 void get_slabinfo(struct kmem_cache *cachep, struct slabinfo *sinfo)
7031 diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
7032 index fc97fc3ed637..0178ea878b75 100644
7033 --- a/net/sunrpc/rpc_pipe.c
7034 +++ b/net/sunrpc/rpc_pipe.c
7035 @@ -1375,6 +1375,7 @@ rpc_gssd_dummy_depopulate(struct dentry *pipe_dentry)
7036 struct dentry *clnt_dir = pipe_dentry->d_parent;
7037 struct dentry *gssd_dir = clnt_dir->d_parent;
7038
7039 + dget(pipe_dentry);
7040 __rpc_rmpipe(d_inode(clnt_dir), pipe_dentry);
7041 __rpc_depopulate(clnt_dir, gssd_dummy_info_file, 0, 1);
7042 __rpc_depopulate(gssd_dir, gssd_dummy_clnt_dir, 0, 1);
7043 diff --git a/net/sunrpc/xprtrdma/rpc_rdma.c b/net/sunrpc/xprtrdma/rpc_rdma.c
7044 index f0855a959a27..4bc0f4d94a01 100644
7045 --- a/net/sunrpc/xprtrdma/rpc_rdma.c
7046 +++ b/net/sunrpc/xprtrdma/rpc_rdma.c
7047 @@ -1366,7 +1366,7 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep)
7048
7049 trace_xprtrdma_reply(rqst->rq_task, rep, req, credits);
7050
7051 - queue_work_on(req->rl_cpu, rpcrdma_receive_wq, &rep->rr_work);
7052 + queue_work(rpcrdma_receive_wq, &rep->rr_work);
7053 return;
7054
7055 out_badstatus:
7056 diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
7057 index 4b1ecfe979cf..f86021e3b853 100644
7058 --- a/net/sunrpc/xprtrdma/transport.c
7059 +++ b/net/sunrpc/xprtrdma/transport.c
7060 @@ -52,7 +52,6 @@
7061 #include <linux/slab.h>
7062 #include <linux/seq_file.h>
7063 #include <linux/sunrpc/addr.h>
7064 -#include <linux/smp.h>
7065
7066 #include "xprt_rdma.h"
7067
7068 @@ -651,7 +650,6 @@ xprt_rdma_allocate(struct rpc_task *task)
7069 if (!rpcrdma_get_recvbuf(r_xprt, req, rqst->rq_rcvsize, flags))
7070 goto out_fail;
7071
7072 - req->rl_cpu = smp_processor_id();
7073 req->rl_connect_cookie = 0; /* our reserved value */
7074 rpcrdma_set_xprtdata(rqst, req);
7075 rqst->rq_buffer = req->rl_sendbuf->rg_base;
7076 diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c
7077 index e6f84a6434a0..25b0ecbd37e2 100644
7078 --- a/net/sunrpc/xprtrdma/verbs.c
7079 +++ b/net/sunrpc/xprtrdma/verbs.c
7080 @@ -250,7 +250,6 @@ rpcrdma_conn_upcall(struct rdma_cm_id *id, struct rdma_cm_event *event)
7081 wait_for_completion(&ia->ri_remove_done);
7082
7083 ia->ri_id = NULL;
7084 - ia->ri_pd = NULL;
7085 ia->ri_device = NULL;
7086 /* Return 1 to ensure the core destroys the id. */
7087 return 1;
7088 @@ -445,7 +444,9 @@ rpcrdma_ia_remove(struct rpcrdma_ia *ia)
7089 ia->ri_id->qp = NULL;
7090 }
7091 ib_free_cq(ep->rep_attr.recv_cq);
7092 + ep->rep_attr.recv_cq = NULL;
7093 ib_free_cq(ep->rep_attr.send_cq);
7094 + ep->rep_attr.send_cq = NULL;
7095
7096 /* The ULP is responsible for ensuring all DMA
7097 * mappings and MRs are gone.
7098 @@ -458,6 +459,8 @@ rpcrdma_ia_remove(struct rpcrdma_ia *ia)
7099 rpcrdma_dma_unmap_regbuf(req->rl_recvbuf);
7100 }
7101 rpcrdma_mrs_destroy(buf);
7102 + ib_dealloc_pd(ia->ri_pd);
7103 + ia->ri_pd = NULL;
7104
7105 /* Allow waiters to continue */
7106 complete(&ia->ri_remove_done);
7107 @@ -628,14 +631,16 @@ rpcrdma_ep_destroy(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
7108 {
7109 cancel_delayed_work_sync(&ep->rep_connect_worker);
7110
7111 - if (ia->ri_id->qp) {
7112 + if (ia->ri_id && ia->ri_id->qp) {
7113 rpcrdma_ep_disconnect(ep, ia);
7114 rdma_destroy_qp(ia->ri_id);
7115 ia->ri_id->qp = NULL;
7116 }
7117
7118 - ib_free_cq(ep->rep_attr.recv_cq);
7119 - ib_free_cq(ep->rep_attr.send_cq);
7120 + if (ep->rep_attr.recv_cq)
7121 + ib_free_cq(ep->rep_attr.recv_cq);
7122 + if (ep->rep_attr.send_cq)
7123 + ib_free_cq(ep->rep_attr.send_cq);
7124 }
7125
7126 /* Re-establish a connection after a device removal event.
7127 diff --git a/net/sunrpc/xprtrdma/xprt_rdma.h b/net/sunrpc/xprtrdma/xprt_rdma.h
7128 index 69883a960a3f..430a6de8300e 100644
7129 --- a/net/sunrpc/xprtrdma/xprt_rdma.h
7130 +++ b/net/sunrpc/xprtrdma/xprt_rdma.h
7131 @@ -334,7 +334,6 @@ enum {
7132 struct rpcrdma_buffer;
7133 struct rpcrdma_req {
7134 struct list_head rl_list;
7135 - int rl_cpu;
7136 unsigned int rl_connect_cookie;
7137 struct rpcrdma_buffer *rl_buffer;
7138 struct rpcrdma_rep *rl_reply;
7139 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
7140 index 441405081195..1980f68246cb 100644
7141 --- a/sound/core/oss/pcm_oss.c
7142 +++ b/sound/core/oss/pcm_oss.c
7143 @@ -823,8 +823,25 @@ static int choose_rate(struct snd_pcm_substream *substream,
7144 return snd_pcm_hw_param_near(substream, params, SNDRV_PCM_HW_PARAM_RATE, best_rate, NULL);
7145 }
7146
7147 -static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream,
7148 - bool trylock)
7149 +/* parameter locking: returns immediately if tried during streaming */
7150 +static int lock_params(struct snd_pcm_runtime *runtime)
7151 +{
7152 + if (mutex_lock_interruptible(&runtime->oss.params_lock))
7153 + return -ERESTARTSYS;
7154 + if (atomic_read(&runtime->oss.rw_ref)) {
7155 + mutex_unlock(&runtime->oss.params_lock);
7156 + return -EBUSY;
7157 + }
7158 + return 0;
7159 +}
7160 +
7161 +static void unlock_params(struct snd_pcm_runtime *runtime)
7162 +{
7163 + mutex_unlock(&runtime->oss.params_lock);
7164 +}
7165 +
7166 +/* call with params_lock held */
7167 +static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
7168 {
7169 struct snd_pcm_runtime *runtime = substream->runtime;
7170 struct snd_pcm_hw_params *params, *sparams;
7171 @@ -838,11 +855,8 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream,
7172 const struct snd_mask *sformat_mask;
7173 struct snd_mask mask;
7174
7175 - if (trylock) {
7176 - if (!(mutex_trylock(&runtime->oss.params_lock)))
7177 - return -EAGAIN;
7178 - } else if (mutex_lock_interruptible(&runtime->oss.params_lock))
7179 - return -ERESTARTSYS;
7180 + if (!runtime->oss.params)
7181 + return 0;
7182 sw_params = kzalloc(sizeof(*sw_params), GFP_KERNEL);
7183 params = kmalloc(sizeof(*params), GFP_KERNEL);
7184 sparams = kmalloc(sizeof(*sparams), GFP_KERNEL);
7185 @@ -1068,6 +1082,23 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream,
7186 kfree(sw_params);
7187 kfree(params);
7188 kfree(sparams);
7189 + return err;
7190 +}
7191 +
7192 +/* this one takes the lock by itself */
7193 +static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream,
7194 + bool trylock)
7195 +{
7196 + struct snd_pcm_runtime *runtime = substream->runtime;
7197 + int err;
7198 +
7199 + if (trylock) {
7200 + if (!(mutex_trylock(&runtime->oss.params_lock)))
7201 + return -EAGAIN;
7202 + } else if (mutex_lock_interruptible(&runtime->oss.params_lock))
7203 + return -ERESTARTSYS;
7204 +
7205 + err = snd_pcm_oss_change_params_locked(substream);
7206 mutex_unlock(&runtime->oss.params_lock);
7207 return err;
7208 }
7209 @@ -1096,6 +1127,10 @@ static int snd_pcm_oss_get_active_substream(struct snd_pcm_oss_file *pcm_oss_fil
7210 return 0;
7211 }
7212
7213 +/* call with params_lock held */
7214 +/* NOTE: this always call PREPARE unconditionally no matter whether
7215 + * runtime->oss.prepare is set or not
7216 + */
7217 static int snd_pcm_oss_prepare(struct snd_pcm_substream *substream)
7218 {
7219 int err;
7220 @@ -1120,14 +1155,35 @@ static int snd_pcm_oss_make_ready(struct snd_pcm_substream *substream)
7221 struct snd_pcm_runtime *runtime;
7222 int err;
7223
7224 - if (substream == NULL)
7225 - return 0;
7226 runtime = substream->runtime;
7227 if (runtime->oss.params) {
7228 err = snd_pcm_oss_change_params(substream, false);
7229 if (err < 0)
7230 return err;
7231 }
7232 + if (runtime->oss.prepare) {
7233 + if (mutex_lock_interruptible(&runtime->oss.params_lock))
7234 + return -ERESTARTSYS;
7235 + err = snd_pcm_oss_prepare(substream);
7236 + mutex_unlock(&runtime->oss.params_lock);
7237 + if (err < 0)
7238 + return err;
7239 + }
7240 + return 0;
7241 +}
7242 +
7243 +/* call with params_lock held */
7244 +static int snd_pcm_oss_make_ready_locked(struct snd_pcm_substream *substream)
7245 +{
7246 + struct snd_pcm_runtime *runtime;
7247 + int err;
7248 +
7249 + runtime = substream->runtime;
7250 + if (runtime->oss.params) {
7251 + err = snd_pcm_oss_change_params_locked(substream);
7252 + if (err < 0)
7253 + return err;
7254 + }
7255 if (runtime->oss.prepare) {
7256 err = snd_pcm_oss_prepare(substream);
7257 if (err < 0)
7258 @@ -1332,13 +1388,15 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
7259 if (atomic_read(&substream->mmap_count))
7260 return -ENXIO;
7261
7262 - if ((tmp = snd_pcm_oss_make_ready(substream)) < 0)
7263 - return tmp;
7264 + atomic_inc(&runtime->oss.rw_ref);
7265 while (bytes > 0) {
7266 if (mutex_lock_interruptible(&runtime->oss.params_lock)) {
7267 tmp = -ERESTARTSYS;
7268 break;
7269 }
7270 + tmp = snd_pcm_oss_make_ready_locked(substream);
7271 + if (tmp < 0)
7272 + goto err;
7273 if (bytes < runtime->oss.period_bytes || runtime->oss.buffer_used > 0) {
7274 tmp = bytes;
7275 if (tmp + runtime->oss.buffer_used > runtime->oss.period_bytes)
7276 @@ -1394,6 +1452,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
7277 }
7278 tmp = 0;
7279 }
7280 + atomic_dec(&runtime->oss.rw_ref);
7281 return xfer > 0 ? (snd_pcm_sframes_t)xfer : tmp;
7282 }
7283
7284 @@ -1439,13 +1498,15 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
7285 if (atomic_read(&substream->mmap_count))
7286 return -ENXIO;
7287
7288 - if ((tmp = snd_pcm_oss_make_ready(substream)) < 0)
7289 - return tmp;
7290 + atomic_inc(&runtime->oss.rw_ref);
7291 while (bytes > 0) {
7292 if (mutex_lock_interruptible(&runtime->oss.params_lock)) {
7293 tmp = -ERESTARTSYS;
7294 break;
7295 }
7296 + tmp = snd_pcm_oss_make_ready_locked(substream);
7297 + if (tmp < 0)
7298 + goto err;
7299 if (bytes < runtime->oss.period_bytes || runtime->oss.buffer_used > 0) {
7300 if (runtime->oss.buffer_used == 0) {
7301 tmp = snd_pcm_oss_read2(substream, runtime->oss.buffer, runtime->oss.period_bytes, 1);
7302 @@ -1486,6 +1547,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
7303 }
7304 tmp = 0;
7305 }
7306 + atomic_dec(&runtime->oss.rw_ref);
7307 return xfer > 0 ? (snd_pcm_sframes_t)xfer : tmp;
7308 }
7309
7310 @@ -1501,10 +1563,12 @@ static int snd_pcm_oss_reset(struct snd_pcm_oss_file *pcm_oss_file)
7311 continue;
7312 runtime = substream->runtime;
7313 snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
7314 + mutex_lock(&runtime->oss.params_lock);
7315 runtime->oss.prepare = 1;
7316 runtime->oss.buffer_used = 0;
7317 runtime->oss.prev_hw_ptr_period = 0;
7318 runtime->oss.period_ptr = 0;
7319 + mutex_unlock(&runtime->oss.params_lock);
7320 }
7321 return 0;
7322 }
7323 @@ -1590,9 +1654,13 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
7324 goto __direct;
7325 if ((err = snd_pcm_oss_make_ready(substream)) < 0)
7326 return err;
7327 + atomic_inc(&runtime->oss.rw_ref);
7328 + if (mutex_lock_interruptible(&runtime->oss.params_lock)) {
7329 + atomic_dec(&runtime->oss.rw_ref);
7330 + return -ERESTARTSYS;
7331 + }
7332 format = snd_pcm_oss_format_from(runtime->oss.format);
7333 width = snd_pcm_format_physical_width(format);
7334 - mutex_lock(&runtime->oss.params_lock);
7335 if (runtime->oss.buffer_used > 0) {
7336 #ifdef OSS_DEBUG
7337 pcm_dbg(substream->pcm, "sync: buffer_used\n");
7338 @@ -1602,10 +1670,8 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
7339 runtime->oss.buffer + runtime->oss.buffer_used,
7340 size);
7341 err = snd_pcm_oss_sync1(substream, runtime->oss.period_bytes);
7342 - if (err < 0) {
7343 - mutex_unlock(&runtime->oss.params_lock);
7344 - return err;
7345 - }
7346 + if (err < 0)
7347 + goto unlock;
7348 } else if (runtime->oss.period_ptr > 0) {
7349 #ifdef OSS_DEBUG
7350 pcm_dbg(substream->pcm, "sync: period_ptr\n");
7351 @@ -1615,10 +1681,8 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
7352 runtime->oss.buffer,
7353 size * 8 / width);
7354 err = snd_pcm_oss_sync1(substream, size);
7355 - if (err < 0) {
7356 - mutex_unlock(&runtime->oss.params_lock);
7357 - return err;
7358 - }
7359 + if (err < 0)
7360 + goto unlock;
7361 }
7362 /*
7363 * The ALSA's period might be a bit large than OSS one.
7364 @@ -1632,7 +1696,11 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
7365 else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED)
7366 snd_pcm_lib_writev(substream, NULL, size);
7367 }
7368 +unlock:
7369 mutex_unlock(&runtime->oss.params_lock);
7370 + atomic_dec(&runtime->oss.rw_ref);
7371 + if (err < 0)
7372 + return err;
7373 /*
7374 * finish sync: drain the buffer
7375 */
7376 @@ -1643,7 +1711,9 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
7377 substream->f_flags = saved_f_flags;
7378 if (err < 0)
7379 return err;
7380 + mutex_lock(&runtime->oss.params_lock);
7381 runtime->oss.prepare = 1;
7382 + mutex_unlock(&runtime->oss.params_lock);
7383 }
7384
7385 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
7386 @@ -1654,8 +1724,10 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
7387 err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
7388 if (err < 0)
7389 return err;
7390 + mutex_lock(&runtime->oss.params_lock);
7391 runtime->oss.buffer_used = 0;
7392 runtime->oss.prepare = 1;
7393 + mutex_unlock(&runtime->oss.params_lock);
7394 }
7395 return 0;
7396 }
7397 @@ -1667,6 +1739,8 @@ static int snd_pcm_oss_set_rate(struct snd_pcm_oss_file *pcm_oss_file, int rate)
7398 for (idx = 1; idx >= 0; --idx) {
7399 struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
7400 struct snd_pcm_runtime *runtime;
7401 + int err;
7402 +
7403 if (substream == NULL)
7404 continue;
7405 runtime = substream->runtime;
7406 @@ -1674,10 +1748,14 @@ static int snd_pcm_oss_set_rate(struct snd_pcm_oss_file *pcm_oss_file, int rate)
7407 rate = 1000;
7408 else if (rate > 192000)
7409 rate = 192000;
7410 + err = lock_params(runtime);
7411 + if (err < 0)
7412 + return err;
7413 if (runtime->oss.rate != rate) {
7414 runtime->oss.params = 1;
7415 runtime->oss.rate = rate;
7416 }
7417 + unlock_params(runtime);
7418 }
7419 return snd_pcm_oss_get_rate(pcm_oss_file);
7420 }
7421 @@ -1702,13 +1780,19 @@ static int snd_pcm_oss_set_channels(struct snd_pcm_oss_file *pcm_oss_file, unsig
7422 for (idx = 1; idx >= 0; --idx) {
7423 struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
7424 struct snd_pcm_runtime *runtime;
7425 + int err;
7426 +
7427 if (substream == NULL)
7428 continue;
7429 runtime = substream->runtime;
7430 + err = lock_params(runtime);
7431 + if (err < 0)
7432 + return err;
7433 if (runtime->oss.channels != channels) {
7434 runtime->oss.params = 1;
7435 runtime->oss.channels = channels;
7436 }
7437 + unlock_params(runtime);
7438 }
7439 return snd_pcm_oss_get_channels(pcm_oss_file);
7440 }
7441 @@ -1781,6 +1865,7 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file)
7442 static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int format)
7443 {
7444 int formats, idx;
7445 + int err;
7446
7447 if (format != AFMT_QUERY) {
7448 formats = snd_pcm_oss_get_formats(pcm_oss_file);
7449 @@ -1794,10 +1879,14 @@ static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int for
7450 if (substream == NULL)
7451 continue;
7452 runtime = substream->runtime;
7453 + err = lock_params(runtime);
7454 + if (err < 0)
7455 + return err;
7456 if (runtime->oss.format != format) {
7457 runtime->oss.params = 1;
7458 runtime->oss.format = format;
7459 }
7460 + unlock_params(runtime);
7461 }
7462 }
7463 return snd_pcm_oss_get_format(pcm_oss_file);
7464 @@ -1817,8 +1906,6 @@ static int snd_pcm_oss_set_subdivide1(struct snd_pcm_substream *substream, int s
7465 {
7466 struct snd_pcm_runtime *runtime;
7467
7468 - if (substream == NULL)
7469 - return 0;
7470 runtime = substream->runtime;
7471 if (subdivide == 0) {
7472 subdivide = runtime->oss.subdivision;
7473 @@ -1842,9 +1929,17 @@ static int snd_pcm_oss_set_subdivide(struct snd_pcm_oss_file *pcm_oss_file, int
7474
7475 for (idx = 1; idx >= 0; --idx) {
7476 struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
7477 + struct snd_pcm_runtime *runtime;
7478 +
7479 if (substream == NULL)
7480 continue;
7481 - if ((err = snd_pcm_oss_set_subdivide1(substream, subdivide)) < 0)
7482 + runtime = substream->runtime;
7483 + err = lock_params(runtime);
7484 + if (err < 0)
7485 + return err;
7486 + err = snd_pcm_oss_set_subdivide1(substream, subdivide);
7487 + unlock_params(runtime);
7488 + if (err < 0)
7489 return err;
7490 }
7491 return err;
7492 @@ -1854,8 +1949,6 @@ static int snd_pcm_oss_set_fragment1(struct snd_pcm_substream *substream, unsign
7493 {
7494 struct snd_pcm_runtime *runtime;
7495
7496 - if (substream == NULL)
7497 - return 0;
7498 runtime = substream->runtime;
7499 if (runtime->oss.subdivision || runtime->oss.fragshift)
7500 return -EINVAL;
7501 @@ -1875,9 +1968,17 @@ static int snd_pcm_oss_set_fragment(struct snd_pcm_oss_file *pcm_oss_file, unsig
7502
7503 for (idx = 1; idx >= 0; --idx) {
7504 struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
7505 + struct snd_pcm_runtime *runtime;
7506 +
7507 if (substream == NULL)
7508 continue;
7509 - if ((err = snd_pcm_oss_set_fragment1(substream, val)) < 0)
7510 + runtime = substream->runtime;
7511 + err = lock_params(runtime);
7512 + if (err < 0)
7513 + return err;
7514 + err = snd_pcm_oss_set_fragment1(substream, val);
7515 + unlock_params(runtime);
7516 + if (err < 0)
7517 return err;
7518 }
7519 return err;
7520 @@ -1961,6 +2062,9 @@ static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int tr
7521 }
7522 if (psubstream) {
7523 runtime = psubstream->runtime;
7524 + cmd = 0;
7525 + if (mutex_lock_interruptible(&runtime->oss.params_lock))
7526 + return -ERESTARTSYS;
7527 if (trigger & PCM_ENABLE_OUTPUT) {
7528 if (runtime->oss.trigger)
7529 goto _skip1;
7530 @@ -1978,13 +2082,19 @@ static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int tr
7531 cmd = SNDRV_PCM_IOCTL_DROP;
7532 runtime->oss.prepare = 1;
7533 }
7534 - err = snd_pcm_kernel_ioctl(psubstream, cmd, NULL);
7535 - if (err < 0)
7536 - return err;
7537 - }
7538 _skip1:
7539 + mutex_unlock(&runtime->oss.params_lock);
7540 + if (cmd) {
7541 + err = snd_pcm_kernel_ioctl(psubstream, cmd, NULL);
7542 + if (err < 0)
7543 + return err;
7544 + }
7545 + }
7546 if (csubstream) {
7547 runtime = csubstream->runtime;
7548 + cmd = 0;
7549 + if (mutex_lock_interruptible(&runtime->oss.params_lock))
7550 + return -ERESTARTSYS;
7551 if (trigger & PCM_ENABLE_INPUT) {
7552 if (runtime->oss.trigger)
7553 goto _skip2;
7554 @@ -1999,11 +2109,14 @@ static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int tr
7555 cmd = SNDRV_PCM_IOCTL_DROP;
7556 runtime->oss.prepare = 1;
7557 }
7558 - err = snd_pcm_kernel_ioctl(csubstream, cmd, NULL);
7559 - if (err < 0)
7560 - return err;
7561 - }
7562 _skip2:
7563 + mutex_unlock(&runtime->oss.params_lock);
7564 + if (cmd) {
7565 + err = snd_pcm_kernel_ioctl(csubstream, cmd, NULL);
7566 + if (err < 0)
7567 + return err;
7568 + }
7569 + }
7570 return 0;
7571 }
7572
7573 @@ -2255,6 +2368,7 @@ static void snd_pcm_oss_init_substream(struct snd_pcm_substream *substream,
7574 runtime->oss.maxfrags = 0;
7575 runtime->oss.subdivision = 0;
7576 substream->pcm_release = snd_pcm_oss_release_substream;
7577 + atomic_set(&runtime->oss.rw_ref, 0);
7578 }
7579
7580 static int snd_pcm_oss_release_file(struct snd_pcm_oss_file *pcm_oss_file)
7581 diff --git a/sound/core/pcm.c b/sound/core/pcm.c
7582 index 09ee8c6b9f75..66ac89aad681 100644
7583 --- a/sound/core/pcm.c
7584 +++ b/sound/core/pcm.c
7585 @@ -28,6 +28,7 @@
7586 #include <sound/core.h>
7587 #include <sound/minors.h>
7588 #include <sound/pcm.h>
7589 +#include <sound/timer.h>
7590 #include <sound/control.h>
7591 #include <sound/info.h>
7592
7593 @@ -1054,8 +1055,13 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
7594 snd_free_pages((void*)runtime->control,
7595 PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)));
7596 kfree(runtime->hw_constraints.rules);
7597 - kfree(runtime);
7598 + /* Avoid concurrent access to runtime via PCM timer interface */
7599 + if (substream->timer)
7600 + spin_lock_irq(&substream->timer->lock);
7601 substream->runtime = NULL;
7602 + if (substream->timer)
7603 + spin_unlock_irq(&substream->timer->lock);
7604 + kfree(runtime);
7605 put_pid(substream->pid);
7606 substream->pid = NULL;
7607 substream->pstr->substream_opened--;
7608 diff --git a/sound/core/rawmidi_compat.c b/sound/core/rawmidi_compat.c
7609 index f69764d7cdd7..e30e30ba6e39 100644
7610 --- a/sound/core/rawmidi_compat.c
7611 +++ b/sound/core/rawmidi_compat.c
7612 @@ -36,8 +36,6 @@ static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile,
7613 struct snd_rawmidi_params params;
7614 unsigned int val;
7615
7616 - if (rfile->output == NULL)
7617 - return -EINVAL;
7618 if (get_user(params.stream, &src->stream) ||
7619 get_user(params.buffer_size, &src->buffer_size) ||
7620 get_user(params.avail_min, &src->avail_min) ||
7621 @@ -46,8 +44,12 @@ static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile,
7622 params.no_active_sensing = val;
7623 switch (params.stream) {
7624 case SNDRV_RAWMIDI_STREAM_OUTPUT:
7625 + if (!rfile->output)
7626 + return -EINVAL;
7627 return snd_rawmidi_output_params(rfile->output, &params);
7628 case SNDRV_RAWMIDI_STREAM_INPUT:
7629 + if (!rfile->input)
7630 + return -EINVAL;
7631 return snd_rawmidi_input_params(rfile->input, &params);
7632 }
7633 return -EINVAL;
7634 @@ -67,16 +69,18 @@ static int snd_rawmidi_ioctl_status_compat(struct snd_rawmidi_file *rfile,
7635 int err;
7636 struct snd_rawmidi_status status;
7637
7638 - if (rfile->output == NULL)
7639 - return -EINVAL;
7640 if (get_user(status.stream, &src->stream))
7641 return -EFAULT;
7642
7643 switch (status.stream) {
7644 case SNDRV_RAWMIDI_STREAM_OUTPUT:
7645 + if (!rfile->output)
7646 + return -EINVAL;
7647 err = snd_rawmidi_output_status(rfile->output, &status);
7648 break;
7649 case SNDRV_RAWMIDI_STREAM_INPUT:
7650 + if (!rfile->input)
7651 + return -EINVAL;
7652 err = snd_rawmidi_input_status(rfile->input, &status);
7653 break;
7654 default:
7655 @@ -112,16 +116,18 @@ static int snd_rawmidi_ioctl_status_x32(struct snd_rawmidi_file *rfile,
7656 int err;
7657 struct snd_rawmidi_status status;
7658
7659 - if (rfile->output == NULL)
7660 - return -EINVAL;
7661 if (get_user(status.stream, &src->stream))
7662 return -EFAULT;
7663
7664 switch (status.stream) {
7665 case SNDRV_RAWMIDI_STREAM_OUTPUT:
7666 + if (!rfile->output)
7667 + return -EINVAL;
7668 err = snd_rawmidi_output_status(rfile->output, &status);
7669 break;
7670 case SNDRV_RAWMIDI_STREAM_INPUT:
7671 + if (!rfile->input)
7672 + return -EINVAL;
7673 err = snd_rawmidi_input_status(rfile->input, &status);
7674 break;
7675 default:
7676 diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
7677 index c507c69029e3..738e1fe90312 100644
7678 --- a/sound/pci/hda/hda_intel.c
7679 +++ b/sound/pci/hda/hda_intel.c
7680 @@ -1645,7 +1645,8 @@ static void azx_check_snoop_available(struct azx *chip)
7681 */
7682 u8 val;
7683 pci_read_config_byte(chip->pci, 0x42, &val);
7684 - if (!(val & 0x80) && chip->pci->revision == 0x30)
7685 + if (!(val & 0x80) && (chip->pci->revision == 0x30 ||
7686 + chip->pci->revision == 0x20))
7687 snoop = false;
7688 }
7689
7690 diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
7691 index aef1f52db7d9..fc77bf7a1544 100644
7692 --- a/sound/pci/hda/patch_realtek.c
7693 +++ b/sound/pci/hda/patch_realtek.c
7694 @@ -6370,6 +6370,8 @@ static const struct hda_fixup alc269_fixups[] = {
7695 { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
7696 { }
7697 },
7698 + .chained = true,
7699 + .chain_id = ALC269_FIXUP_HEADSET_MIC
7700 },
7701 };
7702
7703 @@ -6573,6 +6575,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
7704 SND_PCI_QUIRK(0x17aa, 0x30bb, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
7705 SND_PCI_QUIRK(0x17aa, 0x30e2, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
7706 SND_PCI_QUIRK(0x17aa, 0x310c, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
7707 + SND_PCI_QUIRK(0x17aa, 0x3138, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
7708 SND_PCI_QUIRK(0x17aa, 0x313c, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
7709 SND_PCI_QUIRK(0x17aa, 0x3112, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
7710 SND_PCI_QUIRK(0x17aa, 0x3902, "Lenovo E50-80", ALC269_FIXUP_DMIC_THINKPAD_ACPI),
7711 diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c
7712 index 9b341c23f62b..5e80867d09ef 100644
7713 --- a/sound/soc/codecs/ssm2602.c
7714 +++ b/sound/soc/codecs/ssm2602.c
7715 @@ -54,10 +54,17 @@ struct ssm2602_priv {
7716 * using 2 wire for device control, so we cache them instead.
7717 * There is no point in caching the reset register
7718 */
7719 -static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = {
7720 - 0x0097, 0x0097, 0x0079, 0x0079,
7721 - 0x000a, 0x0008, 0x009f, 0x000a,
7722 - 0x0000, 0x0000
7723 +static const struct reg_default ssm2602_reg[SSM2602_CACHEREGNUM] = {
7724 + { .reg = 0x00, .def = 0x0097 },
7725 + { .reg = 0x01, .def = 0x0097 },
7726 + { .reg = 0x02, .def = 0x0079 },
7727 + { .reg = 0x03, .def = 0x0079 },
7728 + { .reg = 0x04, .def = 0x000a },
7729 + { .reg = 0x05, .def = 0x0008 },
7730 + { .reg = 0x06, .def = 0x009f },
7731 + { .reg = 0x07, .def = 0x000a },
7732 + { .reg = 0x08, .def = 0x0000 },
7733 + { .reg = 0x09, .def = 0x0000 }
7734 };
7735
7736
7737 @@ -620,8 +627,8 @@ const struct regmap_config ssm2602_regmap_config = {
7738 .volatile_reg = ssm2602_register_volatile,
7739
7740 .cache_type = REGCACHE_RBTREE,
7741 - .reg_defaults_raw = ssm2602_reg,
7742 - .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg),
7743 + .reg_defaults = ssm2602_reg,
7744 + .num_reg_defaults = ARRAY_SIZE(ssm2602_reg),
7745 };
7746 EXPORT_SYMBOL_GPL(ssm2602_regmap_config);
7747
7748 diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
7749 index 01a50413c66f..782c580b7aa3 100644
7750 --- a/sound/soc/soc-topology.c
7751 +++ b/sound/soc/soc-topology.c
7752 @@ -523,6 +523,7 @@ static void remove_widget(struct snd_soc_component *comp,
7753 kfree(se->dobj.control.dtexts[j]);
7754
7755 kfree(se);
7756 + kfree(w->kcontrol_news[i].name);
7757 }
7758 kfree(w->kcontrol_news);
7759 } else {
7760 @@ -540,6 +541,7 @@ static void remove_widget(struct snd_soc_component *comp,
7761 */
7762 kfree((void *)kcontrol->private_value);
7763 snd_ctl_remove(card, kcontrol);
7764 + kfree(w->kcontrol_news[i].name);
7765 }
7766 kfree(w->kcontrol_news);
7767 }
7768 @@ -1233,7 +1235,9 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dmixer_create(
7769 dev_dbg(tplg->dev, " adding DAPM widget mixer control %s at %d\n",
7770 mc->hdr.name, i);
7771
7772 - kc[i].name = mc->hdr.name;
7773 + kc[i].name = kstrdup(mc->hdr.name, GFP_KERNEL);
7774 + if (kc[i].name == NULL)
7775 + goto err_str;
7776 kc[i].private_value = (long)sm;
7777 kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
7778 kc[i].access = mc->hdr.access;
7779 @@ -1278,8 +1282,10 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dmixer_create(
7780 err_str:
7781 kfree(sm);
7782 err:
7783 - for (--i; i >= 0; i--)
7784 + for (--i; i >= 0; i--) {
7785 kfree((void *)kc[i].private_value);
7786 + kfree(kc[i].name);
7787 + }
7788 kfree(kc);
7789 return NULL;
7790 }
7791 @@ -1310,7 +1316,9 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_denum_create(
7792 dev_dbg(tplg->dev, " adding DAPM widget enum control %s\n",
7793 ec->hdr.name);
7794
7795 - kc[i].name = ec->hdr.name;
7796 + kc[i].name = kstrdup(ec->hdr.name, GFP_KERNEL);
7797 + if (kc[i].name == NULL)
7798 + goto err_se;
7799 kc[i].private_value = (long)se;
7800 kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
7801 kc[i].access = ec->hdr.access;
7802 @@ -1386,6 +1394,7 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_denum_create(
7803 kfree(se->dobj.control.dtexts[j]);
7804
7805 kfree(se);
7806 + kfree(kc[i].name);
7807 }
7808 err:
7809 kfree(kc);
7810 @@ -1424,7 +1433,9 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dbytes_create(
7811 "ASoC: adding bytes kcontrol %s with access 0x%x\n",
7812 be->hdr.name, be->hdr.access);
7813
7814 - kc[i].name = be->hdr.name;
7815 + kc[i].name = kstrdup(be->hdr.name, GFP_KERNEL);
7816 + if (kc[i].name == NULL)
7817 + goto err;
7818 kc[i].private_value = (long)sbe;
7819 kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
7820 kc[i].access = be->hdr.access;
7821 @@ -1454,8 +1465,10 @@ static struct snd_kcontrol_new *soc_tplg_dapm_widget_dbytes_create(
7822 return kc;
7823
7824 err:
7825 - for (--i; i >= 0; i--)
7826 + for (--i; i >= 0; i--) {
7827 kfree((void *)kc[i].private_value);
7828 + kfree(kc[i].name);
7829 + }
7830
7831 kfree(kc);
7832 return NULL;
7833 diff --git a/sound/usb/line6/midi.c b/sound/usb/line6/midi.c
7834 index 6d7cde56a355..e2cf55c53ea8 100644
7835 --- a/sound/usb/line6/midi.c
7836 +++ b/sound/usb/line6/midi.c
7837 @@ -125,7 +125,7 @@ static int send_midi_async(struct usb_line6 *line6, unsigned char *data,
7838 }
7839
7840 usb_fill_int_urb(urb, line6->usbdev,
7841 - usb_sndbulkpipe(line6->usbdev,
7842 + usb_sndintpipe(line6->usbdev,
7843 line6->properties->ep_ctrl_w),
7844 transfer_buffer, length, midi_sent, line6,
7845 line6->interval);
7846 diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
7847 index 465095355666..a8f07243aa9f 100644
7848 --- a/virt/kvm/arm/vgic/vgic-its.c
7849 +++ b/virt/kvm/arm/vgic/vgic-its.c
7850 @@ -316,21 +316,24 @@ static int vgic_copy_lpi_list(struct kvm_vcpu *vcpu, u32 **intid_ptr)
7851 struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
7852 struct vgic_irq *irq;
7853 u32 *intids;
7854 - int irq_count = dist->lpi_list_count, i = 0;
7855 + int irq_count, i = 0;
7856
7857 /*
7858 - * We use the current value of the list length, which may change
7859 - * after the kmalloc. We don't care, because the guest shouldn't
7860 - * change anything while the command handling is still running,
7861 - * and in the worst case we would miss a new IRQ, which one wouldn't
7862 - * expect to be covered by this command anyway.
7863 + * There is an obvious race between allocating the array and LPIs
7864 + * being mapped/unmapped. If we ended up here as a result of a
7865 + * command, we're safe (locks are held, preventing another
7866 + * command). If coming from another path (such as enabling LPIs),
7867 + * we must be careful not to overrun the array.
7868 */
7869 + irq_count = READ_ONCE(dist->lpi_list_count);
7870 intids = kmalloc_array(irq_count, sizeof(intids[0]), GFP_KERNEL);
7871 if (!intids)
7872 return -ENOMEM;
7873
7874 spin_lock(&dist->lpi_list_lock);
7875 list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) {
7876 + if (i == irq_count)
7877 + break;
7878 /* We don't need to "get" the IRQ, as we hold the list lock. */
7879 if (irq->target_vcpu != vcpu)
7880 continue;