Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:4.14 commit in: /
Date: Mon, 30 Apr 2018 10:30:05
Message-Id: 1525084191.645f3565be0d4dce743c0b1a2b71093f0889d815.mpagano@gentoo
1 commit: 645f3565be0d4dce743c0b1a2b71093f0889d815
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Mon Apr 30 10:29:51 2018 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Mon Apr 30 10:29:51 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=645f3565
7
8 Linux patch 4.14.38
9
10 0000_README | 4 +
11 1037_linux-4.14.38.patch | 4524 ++++++++++++++++++++++++++++++++++++++++++++++
12 2 files changed, 4528 insertions(+)
13
14 diff --git a/0000_README b/0000_README
15 index 73aafae..03b1461 100644
16 --- a/0000_README
17 +++ b/0000_README
18 @@ -191,6 +191,10 @@ Patch: 1036_linux-4.14.37.patch
19 From: http://www.kernel.org
20 Desc: Linux 4.14.37
21
22 +Patch: 1037_linux-4.14.38.patch
23 +From: http://www.kernel.org
24 +Desc: Linux 4.14.38
25 +
26 Patch: 1500_XATTR_USER_PREFIX.patch
27 From: https://bugs.gentoo.org/show_bug.cgi?id=470644
28 Desc: Support for namespace user.pax.* on tmpfs.
29
30 diff --git a/1037_linux-4.14.38.patch b/1037_linux-4.14.38.patch
31 new file mode 100644
32 index 0000000..4612b61
33 --- /dev/null
34 +++ b/1037_linux-4.14.38.patch
35 @@ -0,0 +1,4524 @@
36 +diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
37 +index fb385af482ff..8cfb44ffe853 100644
38 +--- a/Documentation/admin-guide/kernel-parameters.txt
39 ++++ b/Documentation/admin-guide/kernel-parameters.txt
40 +@@ -2541,6 +2541,9 @@
41 +
42 + noalign [KNL,ARM]
43 +
44 ++ noaltinstr [S390] Disables alternative instructions patching
45 ++ (CPU alternatives feature).
46 ++
47 + noapic [SMP,APIC] Tells the kernel to not make use of any
48 + IOAPICs that may be present in the system.
49 +
50 +diff --git a/Makefile b/Makefile
51 +index ee330f5449e6..27a8d5c37180 100644
52 +--- a/Makefile
53 ++++ b/Makefile
54 +@@ -1,7 +1,7 @@
55 + # SPDX-License-Identifier: GPL-2.0
56 + VERSION = 4
57 + PATCHLEVEL = 14
58 +-SUBLEVEL = 37
59 ++SUBLEVEL = 38
60 + EXTRAVERSION =
61 + NAME = Petit Gorille
62 +
63 +diff --git a/arch/arm64/boot/dts/rockchip/rk3399-puma.dtsi b/arch/arm64/boot/dts/rockchip/rk3399-puma.dtsi
64 +index 910628d18add..1fc5060d7027 100644
65 +--- a/arch/arm64/boot/dts/rockchip/rk3399-puma.dtsi
66 ++++ b/arch/arm64/boot/dts/rockchip/rk3399-puma.dtsi
67 +@@ -155,17 +155,6 @@
68 + regulator-min-microvolt = <5000000>;
69 + regulator-max-microvolt = <5000000>;
70 + };
71 +-
72 +- vdd_log: vdd-log {
73 +- compatible = "pwm-regulator";
74 +- pwms = <&pwm2 0 25000 0>;
75 +- regulator-name = "vdd_log";
76 +- regulator-min-microvolt = <800000>;
77 +- regulator-max-microvolt = <1400000>;
78 +- regulator-always-on;
79 +- regulator-boot-on;
80 +- status = "okay";
81 +- };
82 + };
83 +
84 + &cpu_b0 {
85 +diff --git a/arch/microblaze/Kconfig.platform b/arch/microblaze/Kconfig.platform
86 +index 1b3d8c849101..f7f1739c11b9 100644
87 +--- a/arch/microblaze/Kconfig.platform
88 ++++ b/arch/microblaze/Kconfig.platform
89 +@@ -20,6 +20,7 @@ config OPT_LIB_FUNCTION
90 + config OPT_LIB_ASM
91 + bool "Optimalized lib function ASM"
92 + depends on OPT_LIB_FUNCTION && (XILINX_MICROBLAZE0_USE_BARREL = 1)
93 ++ depends on CPU_BIG_ENDIAN
94 + default n
95 + help
96 + Allows turn on optimalized library function (memcpy and memmove).
97 +diff --git a/arch/microblaze/lib/fastcopy.S b/arch/microblaze/lib/fastcopy.S
98 +index 62021d7e249e..fdc48bb065d8 100644
99 +--- a/arch/microblaze/lib/fastcopy.S
100 ++++ b/arch/microblaze/lib/fastcopy.S
101 +@@ -29,10 +29,6 @@
102 + * between mem locations with size of xfer spec'd in bytes
103 + */
104 +
105 +-#ifdef __MICROBLAZEEL__
106 +-#error Microblaze LE not support ASM optimized lib func. Disable OPT_LIB_ASM.
107 +-#endif
108 +-
109 + #include <linux/linkage.h>
110 + .text
111 + .globl memcpy
112 +diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
113 +index ae55e715cc74..49fb6614ea8c 100644
114 +--- a/arch/s390/Kconfig
115 ++++ b/arch/s390/Kconfig
116 +@@ -121,6 +121,7 @@ config S390
117 + select GENERIC_CLOCKEVENTS
118 + select GENERIC_CPU_AUTOPROBE
119 + select GENERIC_CPU_DEVICES if !SMP
120 ++ select GENERIC_CPU_VULNERABILITIES
121 + select GENERIC_FIND_FIRST_BIT
122 + select GENERIC_SMP_IDLE_THREAD
123 + select GENERIC_TIME_VSYSCALL
124 +@@ -538,6 +539,51 @@ config ARCH_RANDOM
125 +
126 + If unsure, say Y.
127 +
128 ++config KERNEL_NOBP
129 ++ def_bool n
130 ++ prompt "Enable modified branch prediction for the kernel by default"
131 ++ help
132 ++ If this option is selected the kernel will switch to a modified
133 ++ branch prediction mode if the firmware interface is available.
134 ++ The modified branch prediction mode improves the behaviour in
135 ++ regard to speculative execution.
136 ++
137 ++ With the option enabled the kernel parameter "nobp=0" or "nospec"
138 ++ can be used to run the kernel in the normal branch prediction mode.
139 ++
140 ++ With the option disabled the modified branch prediction mode is
141 ++ enabled with the "nobp=1" kernel parameter.
142 ++
143 ++ If unsure, say N.
144 ++
145 ++config EXPOLINE
146 ++ def_bool n
147 ++ prompt "Avoid speculative indirect branches in the kernel"
148 ++ help
149 ++ Compile the kernel with the expoline compiler options to guard
150 ++ against kernel-to-user data leaks by avoiding speculative indirect
151 ++ branches.
152 ++ Requires a compiler with -mindirect-branch=thunk support for full
153 ++ protection. The kernel may run slower.
154 ++
155 ++ If unsure, say N.
156 ++
157 ++choice
158 ++ prompt "Expoline default"
159 ++ depends on EXPOLINE
160 ++ default EXPOLINE_FULL
161 ++
162 ++config EXPOLINE_OFF
163 ++ bool "spectre_v2=off"
164 ++
165 ++config EXPOLINE_AUTO
166 ++ bool "spectre_v2=auto"
167 ++
168 ++config EXPOLINE_FULL
169 ++ bool "spectre_v2=on"
170 ++
171 ++endchoice
172 ++
173 + endmenu
174 +
175 + menu "Memory setup"
176 +@@ -812,6 +858,7 @@ config PFAULT
177 + config SHARED_KERNEL
178 + bool "VM shared kernel support"
179 + depends on !JUMP_LABEL
180 ++ depends on !ALTERNATIVES
181 + help
182 + Select this option, if you want to share the text segment of the
183 + Linux kernel between different VM guests. This reduces memory
184 +diff --git a/arch/s390/Makefile b/arch/s390/Makefile
185 +index dac821cfcd43..ec3fa105f448 100644
186 +--- a/arch/s390/Makefile
187 ++++ b/arch/s390/Makefile
188 +@@ -81,6 +81,16 @@ ifeq ($(call cc-option-yn,-mwarn-dynamicstack),y)
189 + cflags-$(CONFIG_WARN_DYNAMIC_STACK) += -mwarn-dynamicstack
190 + endif
191 +
192 ++ifdef CONFIG_EXPOLINE
193 ++ ifeq ($(call cc-option-yn,$(CC_FLAGS_MARCH) -mindirect-branch=thunk),y)
194 ++ CC_FLAGS_EXPOLINE := -mindirect-branch=thunk
195 ++ CC_FLAGS_EXPOLINE += -mfunction-return=thunk
196 ++ CC_FLAGS_EXPOLINE += -mindirect-branch-table
197 ++ export CC_FLAGS_EXPOLINE
198 ++ cflags-y += $(CC_FLAGS_EXPOLINE) -DCC_USING_EXPOLINE
199 ++ endif
200 ++endif
201 ++
202 + ifdef CONFIG_FUNCTION_TRACER
203 + # make use of hotpatch feature if the compiler supports it
204 + cc_hotpatch := -mhotpatch=0,3
205 +diff --git a/arch/s390/include/asm/alternative.h b/arch/s390/include/asm/alternative.h
206 +new file mode 100644
207 +index 000000000000..a72002056b54
208 +--- /dev/null
209 ++++ b/arch/s390/include/asm/alternative.h
210 +@@ -0,0 +1,149 @@
211 ++#ifndef _ASM_S390_ALTERNATIVE_H
212 ++#define _ASM_S390_ALTERNATIVE_H
213 ++
214 ++#ifndef __ASSEMBLY__
215 ++
216 ++#include <linux/types.h>
217 ++#include <linux/stddef.h>
218 ++#include <linux/stringify.h>
219 ++
220 ++struct alt_instr {
221 ++ s32 instr_offset; /* original instruction */
222 ++ s32 repl_offset; /* offset to replacement instruction */
223 ++ u16 facility; /* facility bit set for replacement */
224 ++ u8 instrlen; /* length of original instruction */
225 ++ u8 replacementlen; /* length of new instruction */
226 ++} __packed;
227 ++
228 ++void apply_alternative_instructions(void);
229 ++void apply_alternatives(struct alt_instr *start, struct alt_instr *end);
230 ++
231 ++/*
232 ++ * |661: |662: |6620 |663:
233 ++ * +-----------+---------------------+
234 ++ * | oldinstr | oldinstr_padding |
235 ++ * | +----------+----------+
236 ++ * | | | |
237 ++ * | | >6 bytes |6/4/2 nops|
238 ++ * | |6 bytes jg----------->
239 ++ * +-----------+---------------------+
240 ++ * ^^ static padding ^^
241 ++ *
242 ++ * .altinstr_replacement section
243 ++ * +---------------------+-----------+
244 ++ * |6641: |6651:
245 ++ * | alternative instr 1 |
246 ++ * +-----------+---------+- - - - - -+
247 ++ * |6642: |6652: |
248 ++ * | alternative instr 2 | padding
249 ++ * +---------------------+- - - - - -+
250 ++ * ^ runtime ^
251 ++ *
252 ++ * .altinstructions section
253 ++ * +---------------------------------+
254 ++ * | alt_instr entries for each |
255 ++ * | alternative instr |
256 ++ * +---------------------------------+
257 ++ */
258 ++
259 ++#define b_altinstr(num) "664"#num
260 ++#define e_altinstr(num) "665"#num
261 ++
262 ++#define e_oldinstr_pad_end "663"
263 ++#define oldinstr_len "662b-661b"
264 ++#define oldinstr_total_len e_oldinstr_pad_end"b-661b"
265 ++#define altinstr_len(num) e_altinstr(num)"b-"b_altinstr(num)"b"
266 ++#define oldinstr_pad_len(num) \
267 ++ "-(((" altinstr_len(num) ")-(" oldinstr_len ")) > 0) * " \
268 ++ "((" altinstr_len(num) ")-(" oldinstr_len "))"
269 ++
270 ++#define INSTR_LEN_SANITY_CHECK(len) \
271 ++ ".if " len " > 254\n" \
272 ++ "\t.error \"cpu alternatives does not support instructions " \
273 ++ "blocks > 254 bytes\"\n" \
274 ++ ".endif\n" \
275 ++ ".if (" len ") %% 2\n" \
276 ++ "\t.error \"cpu alternatives instructions length is odd\"\n" \
277 ++ ".endif\n"
278 ++
279 ++#define OLDINSTR_PADDING(oldinstr, num) \
280 ++ ".if " oldinstr_pad_len(num) " > 6\n" \
281 ++ "\tjg " e_oldinstr_pad_end "f\n" \
282 ++ "6620:\n" \
283 ++ "\t.fill (" oldinstr_pad_len(num) " - (6620b-662b)) / 2, 2, 0x0700\n" \
284 ++ ".else\n" \
285 ++ "\t.fill " oldinstr_pad_len(num) " / 6, 6, 0xc0040000\n" \
286 ++ "\t.fill " oldinstr_pad_len(num) " %% 6 / 4, 4, 0x47000000\n" \
287 ++ "\t.fill " oldinstr_pad_len(num) " %% 6 %% 4 / 2, 2, 0x0700\n" \
288 ++ ".endif\n"
289 ++
290 ++#define OLDINSTR(oldinstr, num) \
291 ++ "661:\n\t" oldinstr "\n662:\n" \
292 ++ OLDINSTR_PADDING(oldinstr, num) \
293 ++ e_oldinstr_pad_end ":\n" \
294 ++ INSTR_LEN_SANITY_CHECK(oldinstr_len)
295 ++
296 ++#define OLDINSTR_2(oldinstr, num1, num2) \
297 ++ "661:\n\t" oldinstr "\n662:\n" \
298 ++ ".if " altinstr_len(num1) " < " altinstr_len(num2) "\n" \
299 ++ OLDINSTR_PADDING(oldinstr, num2) \
300 ++ ".else\n" \
301 ++ OLDINSTR_PADDING(oldinstr, num1) \
302 ++ ".endif\n" \
303 ++ e_oldinstr_pad_end ":\n" \
304 ++ INSTR_LEN_SANITY_CHECK(oldinstr_len)
305 ++
306 ++#define ALTINSTR_ENTRY(facility, num) \
307 ++ "\t.long 661b - .\n" /* old instruction */ \
308 ++ "\t.long " b_altinstr(num)"b - .\n" /* alt instruction */ \
309 ++ "\t.word " __stringify(facility) "\n" /* facility bit */ \
310 ++ "\t.byte " oldinstr_total_len "\n" /* source len */ \
311 ++ "\t.byte " altinstr_len(num) "\n" /* alt instruction len */
312 ++
313 ++#define ALTINSTR_REPLACEMENT(altinstr, num) /* replacement */ \
314 ++ b_altinstr(num)":\n\t" altinstr "\n" e_altinstr(num) ":\n" \
315 ++ INSTR_LEN_SANITY_CHECK(altinstr_len(num))
316 ++
317 ++/* alternative assembly primitive: */
318 ++#define ALTERNATIVE(oldinstr, altinstr, facility) \
319 ++ ".pushsection .altinstr_replacement, \"ax\"\n" \
320 ++ ALTINSTR_REPLACEMENT(altinstr, 1) \
321 ++ ".popsection\n" \
322 ++ OLDINSTR(oldinstr, 1) \
323 ++ ".pushsection .altinstructions,\"a\"\n" \
324 ++ ALTINSTR_ENTRY(facility, 1) \
325 ++ ".popsection\n"
326 ++
327 ++#define ALTERNATIVE_2(oldinstr, altinstr1, facility1, altinstr2, facility2)\
328 ++ ".pushsection .altinstr_replacement, \"ax\"\n" \
329 ++ ALTINSTR_REPLACEMENT(altinstr1, 1) \
330 ++ ALTINSTR_REPLACEMENT(altinstr2, 2) \
331 ++ ".popsection\n" \
332 ++ OLDINSTR_2(oldinstr, 1, 2) \
333 ++ ".pushsection .altinstructions,\"a\"\n" \
334 ++ ALTINSTR_ENTRY(facility1, 1) \
335 ++ ALTINSTR_ENTRY(facility2, 2) \
336 ++ ".popsection\n"
337 ++
338 ++/*
339 ++ * Alternative instructions for different CPU types or capabilities.
340 ++ *
341 ++ * This allows to use optimized instructions even on generic binary
342 ++ * kernels.
343 ++ *
344 ++ * oldinstr is padded with jump and nops at compile time if altinstr is
345 ++ * longer. altinstr is padded with jump and nops at run-time during patching.
346 ++ *
347 ++ * For non barrier like inlines please define new variants
348 ++ * without volatile and memory clobber.
349 ++ */
350 ++#define alternative(oldinstr, altinstr, facility) \
351 ++ asm volatile(ALTERNATIVE(oldinstr, altinstr, facility) : : : "memory")
352 ++
353 ++#define alternative_2(oldinstr, altinstr1, facility1, altinstr2, facility2) \
354 ++ asm volatile(ALTERNATIVE_2(oldinstr, altinstr1, facility1, \
355 ++ altinstr2, facility2) ::: "memory")
356 ++
357 ++#endif /* __ASSEMBLY__ */
358 ++
359 ++#endif /* _ASM_S390_ALTERNATIVE_H */
360 +diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
361 +index 10432607a573..f9eddbca79d2 100644
362 +--- a/arch/s390/include/asm/barrier.h
363 ++++ b/arch/s390/include/asm/barrier.h
364 +@@ -49,6 +49,30 @@ do { \
365 + #define __smp_mb__before_atomic() barrier()
366 + #define __smp_mb__after_atomic() barrier()
367 +
368 ++/**
369 ++ * array_index_mask_nospec - generate a mask for array_idx() that is
370 ++ * ~0UL when the bounds check succeeds and 0 otherwise
371 ++ * @index: array element index
372 ++ * @size: number of elements in array
373 ++ */
374 ++#define array_index_mask_nospec array_index_mask_nospec
375 ++static inline unsigned long array_index_mask_nospec(unsigned long index,
376 ++ unsigned long size)
377 ++{
378 ++ unsigned long mask;
379 ++
380 ++ if (__builtin_constant_p(size) && size > 0) {
381 ++ asm(" clgr %2,%1\n"
382 ++ " slbgr %0,%0\n"
383 ++ :"=d" (mask) : "d" (size-1), "d" (index) :"cc");
384 ++ return mask;
385 ++ }
386 ++ asm(" clgr %1,%2\n"
387 ++ " slbgr %0,%0\n"
388 ++ :"=d" (mask) : "d" (size), "d" (index) :"cc");
389 ++ return ~mask;
390 ++}
391 ++
392 + #include <asm-generic/barrier.h>
393 +
394 + #endif /* __ASM_BARRIER_H */
395 +diff --git a/arch/s390/include/asm/facility.h b/arch/s390/include/asm/facility.h
396 +index f040644575b7..2d58478c2745 100644
397 +--- a/arch/s390/include/asm/facility.h
398 ++++ b/arch/s390/include/asm/facility.h
399 +@@ -15,6 +15,24 @@
400 +
401 + #define MAX_FACILITY_BIT (sizeof(((struct lowcore *)0)->stfle_fac_list) * 8)
402 +
403 ++static inline void __set_facility(unsigned long nr, void *facilities)
404 ++{
405 ++ unsigned char *ptr = (unsigned char *) facilities;
406 ++
407 ++ if (nr >= MAX_FACILITY_BIT)
408 ++ return;
409 ++ ptr[nr >> 3] |= 0x80 >> (nr & 7);
410 ++}
411 ++
412 ++static inline void __clear_facility(unsigned long nr, void *facilities)
413 ++{
414 ++ unsigned char *ptr = (unsigned char *) facilities;
415 ++
416 ++ if (nr >= MAX_FACILITY_BIT)
417 ++ return;
418 ++ ptr[nr >> 3] &= ~(0x80 >> (nr & 7));
419 ++}
420 ++
421 + static inline int __test_facility(unsigned long nr, void *facilities)
422 + {
423 + unsigned char *ptr;
424 +diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
425 +index 51375e766e90..d660e784e445 100644
426 +--- a/arch/s390/include/asm/kvm_host.h
427 ++++ b/arch/s390/include/asm/kvm_host.h
428 +@@ -210,7 +210,8 @@ struct kvm_s390_sie_block {
429 + __u16 ipa; /* 0x0056 */
430 + __u32 ipb; /* 0x0058 */
431 + __u32 scaoh; /* 0x005c */
432 +- __u8 reserved60; /* 0x0060 */
433 ++#define FPF_BPBC 0x20
434 ++ __u8 fpf; /* 0x0060 */
435 + #define ECB_GS 0x40
436 + #define ECB_TE 0x10
437 + #define ECB_SRSI 0x04
438 +diff --git a/arch/s390/include/asm/lowcore.h b/arch/s390/include/asm/lowcore.h
439 +index 917f7344cab6..88a212df0dbc 100644
440 +--- a/arch/s390/include/asm/lowcore.h
441 ++++ b/arch/s390/include/asm/lowcore.h
442 +@@ -140,7 +140,9 @@ struct lowcore {
443 + /* Per cpu primary space access list */
444 + __u32 paste[16]; /* 0x0400 */
445 +
446 +- __u8 pad_0x04c0[0x0e00-0x0440]; /* 0x0440 */
447 ++ /* br %r1 trampoline */
448 ++ __u16 br_r1_trampoline; /* 0x0440 */
449 ++ __u8 pad_0x0442[0x0e00-0x0442]; /* 0x0442 */
450 +
451 + /*
452 + * 0xe00 contains the address of the IPL Parameter Information
453 +@@ -155,7 +157,8 @@ struct lowcore {
454 + __u8 pad_0x0e20[0x0f00-0x0e20]; /* 0x0e20 */
455 +
456 + /* Extended facility list */
457 +- __u64 stfle_fac_list[32]; /* 0x0f00 */
458 ++ __u64 stfle_fac_list[16]; /* 0x0f00 */
459 ++ __u64 alt_stfle_fac_list[16]; /* 0x0f80 */
460 + __u8 pad_0x1000[0x11b0-0x1000]; /* 0x1000 */
461 +
462 + /* Pointer to the machine check extended save area */
463 +diff --git a/arch/s390/include/asm/nospec-branch.h b/arch/s390/include/asm/nospec-branch.h
464 +new file mode 100644
465 +index 000000000000..b4bd8c41e9d3
466 +--- /dev/null
467 ++++ b/arch/s390/include/asm/nospec-branch.h
468 +@@ -0,0 +1,17 @@
469 ++/* SPDX-License-Identifier: GPL-2.0 */
470 ++#ifndef _ASM_S390_EXPOLINE_H
471 ++#define _ASM_S390_EXPOLINE_H
472 ++
473 ++#ifndef __ASSEMBLY__
474 ++
475 ++#include <linux/types.h>
476 ++
477 ++extern int nospec_disable;
478 ++
479 ++void nospec_init_branches(void);
480 ++void nospec_auto_detect(void);
481 ++void nospec_revert(s32 *start, s32 *end);
482 ++
483 ++#endif /* __ASSEMBLY__ */
484 ++
485 ++#endif /* _ASM_S390_EXPOLINE_H */
486 +diff --git a/arch/s390/include/asm/processor.h b/arch/s390/include/asm/processor.h
487 +index 9cf92abe23c3..0a39cd102c49 100644
488 +--- a/arch/s390/include/asm/processor.h
489 ++++ b/arch/s390/include/asm/processor.h
490 +@@ -89,6 +89,7 @@ void cpu_detect_mhz_feature(void);
491 + extern const struct seq_operations cpuinfo_op;
492 + extern int sysctl_ieee_emulation_warnings;
493 + extern void execve_tail(void);
494 ++extern void __bpon(void);
495 +
496 + /*
497 + * User space process size: 2GB for 31 bit, 4TB or 8PT for 64 bit.
498 +@@ -377,6 +378,9 @@ extern void memcpy_absolute(void *, void *, size_t);
499 + memcpy_absolute(&(dest), &__tmp, sizeof(__tmp)); \
500 + } while (0)
501 +
502 ++extern int s390_isolate_bp(void);
503 ++extern int s390_isolate_bp_guest(void);
504 ++
505 + #endif /* __ASSEMBLY__ */
506 +
507 + #endif /* __ASM_S390_PROCESSOR_H */
508 +diff --git a/arch/s390/include/asm/thread_info.h b/arch/s390/include/asm/thread_info.h
509 +index 0880a37b6d3b..301b4f70bf31 100644
510 +--- a/arch/s390/include/asm/thread_info.h
511 ++++ b/arch/s390/include/asm/thread_info.h
512 +@@ -60,6 +60,8 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
513 + #define TIF_GUARDED_STORAGE 4 /* load guarded storage control block */
514 + #define TIF_PATCH_PENDING 5 /* pending live patching update */
515 + #define TIF_PGSTE 6 /* New mm's will use 4K page tables */
516 ++#define TIF_ISOLATE_BP 8 /* Run process with isolated BP */
517 ++#define TIF_ISOLATE_BP_GUEST 9 /* Run KVM guests with isolated BP */
518 +
519 + #define TIF_31BIT 16 /* 32bit process */
520 + #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
521 +@@ -80,6 +82,8 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
522 + #define _TIF_UPROBE _BITUL(TIF_UPROBE)
523 + #define _TIF_GUARDED_STORAGE _BITUL(TIF_GUARDED_STORAGE)
524 + #define _TIF_PATCH_PENDING _BITUL(TIF_PATCH_PENDING)
525 ++#define _TIF_ISOLATE_BP _BITUL(TIF_ISOLATE_BP)
526 ++#define _TIF_ISOLATE_BP_GUEST _BITUL(TIF_ISOLATE_BP_GUEST)
527 +
528 + #define _TIF_31BIT _BITUL(TIF_31BIT)
529 + #define _TIF_SINGLE_STEP _BITUL(TIF_SINGLE_STEP)
530 +diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
531 +index 9ad172dcd912..a3938db010f7 100644
532 +--- a/arch/s390/include/uapi/asm/kvm.h
533 ++++ b/arch/s390/include/uapi/asm/kvm.h
534 +@@ -228,6 +228,7 @@ struct kvm_guest_debug_arch {
535 + #define KVM_SYNC_RICCB (1UL << 7)
536 + #define KVM_SYNC_FPRS (1UL << 8)
537 + #define KVM_SYNC_GSCB (1UL << 9)
538 ++#define KVM_SYNC_BPBC (1UL << 10)
539 + /* length and alignment of the sdnx as a power of two */
540 + #define SDNXC 8
541 + #define SDNXL (1UL << SDNXC)
542 +@@ -251,7 +252,9 @@ struct kvm_sync_regs {
543 + };
544 + __u8 reserved[512]; /* for future vector expansion */
545 + __u32 fpc; /* valid on KVM_SYNC_VRS or KVM_SYNC_FPRS */
546 +- __u8 padding1[52]; /* riccb needs to be 64byte aligned */
547 ++ __u8 bpbc : 1; /* bp mode */
548 ++ __u8 reserved2 : 7;
549 ++ __u8 padding1[51]; /* riccb needs to be 64byte aligned */
550 + __u8 riccb[64]; /* runtime instrumentation controls block */
551 + __u8 padding2[192]; /* sdnx needs to be 256byte aligned */
552 + union {
553 +diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile
554 +index 4ce2d05929a7..a3a4cafb6080 100644
555 +--- a/arch/s390/kernel/Makefile
556 ++++ b/arch/s390/kernel/Makefile
557 +@@ -29,6 +29,7 @@ UBSAN_SANITIZE_early.o := n
558 + #
559 + ifneq ($(CC_FLAGS_MARCH),-march=z900)
560 + CFLAGS_REMOVE_als.o += $(CC_FLAGS_MARCH)
561 ++CFLAGS_REMOVE_als.o += $(CC_FLAGS_EXPOLINE)
562 + CFLAGS_als.o += -march=z900
563 + AFLAGS_REMOVE_head.o += $(CC_FLAGS_MARCH)
564 + AFLAGS_head.o += -march=z900
565 +@@ -57,10 +58,13 @@ obj-y += processor.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o nmi.o
566 + obj-y += debug.o irq.o ipl.o dis.o diag.o vdso.o als.o
567 + obj-y += sysinfo.o jump_label.o lgr.o os_info.o machine_kexec.o pgm_check.o
568 + obj-y += runtime_instr.o cache.o fpu.o dumpstack.o guarded_storage.o
569 +-obj-y += entry.o reipl.o relocate_kernel.o kdebugfs.o
570 ++obj-y += entry.o reipl.o relocate_kernel.o kdebugfs.o alternative.o
571 ++obj-y += nospec-branch.o
572 +
573 + extra-y += head.o head64.o vmlinux.lds
574 +
575 ++CFLAGS_REMOVE_nospec-branch.o += $(CC_FLAGS_EXPOLINE)
576 ++
577 + obj-$(CONFIG_MODULES) += module.o
578 + obj-$(CONFIG_SMP) += smp.o
579 + obj-$(CONFIG_SCHED_TOPOLOGY) += topology.o
580 +diff --git a/arch/s390/kernel/alternative.c b/arch/s390/kernel/alternative.c
581 +new file mode 100644
582 +index 000000000000..b57b293998dc
583 +--- /dev/null
584 ++++ b/arch/s390/kernel/alternative.c
585 +@@ -0,0 +1,112 @@
586 ++#include <linux/module.h>
587 ++#include <asm/alternative.h>
588 ++#include <asm/facility.h>
589 ++#include <asm/nospec-branch.h>
590 ++
591 ++#define MAX_PATCH_LEN (255 - 1)
592 ++
593 ++static int __initdata_or_module alt_instr_disabled;
594 ++
595 ++static int __init disable_alternative_instructions(char *str)
596 ++{
597 ++ alt_instr_disabled = 1;
598 ++ return 0;
599 ++}
600 ++
601 ++early_param("noaltinstr", disable_alternative_instructions);
602 ++
603 ++struct brcl_insn {
604 ++ u16 opc;
605 ++ s32 disp;
606 ++} __packed;
607 ++
608 ++static u16 __initdata_or_module nop16 = 0x0700;
609 ++static u32 __initdata_or_module nop32 = 0x47000000;
610 ++static struct brcl_insn __initdata_or_module nop48 = {
611 ++ 0xc004, 0
612 ++};
613 ++
614 ++static const void *nops[] __initdata_or_module = {
615 ++ &nop16,
616 ++ &nop32,
617 ++ &nop48
618 ++};
619 ++
620 ++static void __init_or_module add_jump_padding(void *insns, unsigned int len)
621 ++{
622 ++ struct brcl_insn brcl = {
623 ++ 0xc0f4,
624 ++ len / 2
625 ++ };
626 ++
627 ++ memcpy(insns, &brcl, sizeof(brcl));
628 ++ insns += sizeof(brcl);
629 ++ len -= sizeof(brcl);
630 ++
631 ++ while (len > 0) {
632 ++ memcpy(insns, &nop16, 2);
633 ++ insns += 2;
634 ++ len -= 2;
635 ++ }
636 ++}
637 ++
638 ++static void __init_or_module add_padding(void *insns, unsigned int len)
639 ++{
640 ++ if (len > 6)
641 ++ add_jump_padding(insns, len);
642 ++ else if (len >= 2)
643 ++ memcpy(insns, nops[len / 2 - 1], len);
644 ++}
645 ++
646 ++static void __init_or_module __apply_alternatives(struct alt_instr *start,
647 ++ struct alt_instr *end)
648 ++{
649 ++ struct alt_instr *a;
650 ++ u8 *instr, *replacement;
651 ++ u8 insnbuf[MAX_PATCH_LEN];
652 ++
653 ++ /*
654 ++ * The scan order should be from start to end. A later scanned
655 ++ * alternative code can overwrite previously scanned alternative code.
656 ++ */
657 ++ for (a = start; a < end; a++) {
658 ++ int insnbuf_sz = 0;
659 ++
660 ++ instr = (u8 *)&a->instr_offset + a->instr_offset;
661 ++ replacement = (u8 *)&a->repl_offset + a->repl_offset;
662 ++
663 ++ if (!__test_facility(a->facility,
664 ++ S390_lowcore.alt_stfle_fac_list))
665 ++ continue;
666 ++
667 ++ if (unlikely(a->instrlen % 2 || a->replacementlen % 2)) {
668 ++ WARN_ONCE(1, "cpu alternatives instructions length is "
669 ++ "odd, skipping patching\n");
670 ++ continue;
671 ++ }
672 ++
673 ++ memcpy(insnbuf, replacement, a->replacementlen);
674 ++ insnbuf_sz = a->replacementlen;
675 ++
676 ++ if (a->instrlen > a->replacementlen) {
677 ++ add_padding(insnbuf + a->replacementlen,
678 ++ a->instrlen - a->replacementlen);
679 ++ insnbuf_sz += a->instrlen - a->replacementlen;
680 ++ }
681 ++
682 ++ s390_kernel_write(instr, insnbuf, insnbuf_sz);
683 ++ }
684 ++}
685 ++
686 ++void __init_or_module apply_alternatives(struct alt_instr *start,
687 ++ struct alt_instr *end)
688 ++{
689 ++ if (!alt_instr_disabled)
690 ++ __apply_alternatives(start, end);
691 ++}
692 ++
693 ++extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
694 ++void __init apply_alternative_instructions(void)
695 ++{
696 ++ apply_alternatives(__alt_instructions, __alt_instructions_end);
697 ++}
698 +diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c
699 +index f7b280f0ab16..a3219837fa70 100644
700 +--- a/arch/s390/kernel/early.c
701 ++++ b/arch/s390/kernel/early.c
702 +@@ -329,6 +329,11 @@ static noinline __init void setup_facility_list(void)
703 + {
704 + stfle(S390_lowcore.stfle_fac_list,
705 + ARRAY_SIZE(S390_lowcore.stfle_fac_list));
706 ++ memcpy(S390_lowcore.alt_stfle_fac_list,
707 ++ S390_lowcore.stfle_fac_list,
708 ++ sizeof(S390_lowcore.alt_stfle_fac_list));
709 ++ if (!IS_ENABLED(CONFIG_KERNEL_NOBP))
710 ++ __clear_facility(82, S390_lowcore.alt_stfle_fac_list);
711 + }
712 +
713 + static __init void detect_diag9c(void)
714 +diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
715 +index 7c6904d616d8..ed9aaa212d4a 100644
716 +--- a/arch/s390/kernel/entry.S
717 ++++ b/arch/s390/kernel/entry.S
718 +@@ -106,6 +106,7 @@ _PIF_WORK = (_PIF_PER_TRAP | _PIF_SYSCALL_RESTART)
719 + aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
720 + j 3f
721 + 1: UPDATE_VTIME %r14,%r15,\timer
722 ++ BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
723 + 2: lg %r15,__LC_ASYNC_STACK # load async stack
724 + 3: la %r11,STACK_FRAME_OVERHEAD(%r15)
725 + .endm
726 +@@ -158,6 +159,130 @@ _PIF_WORK = (_PIF_PER_TRAP | _PIF_SYSCALL_RESTART)
727 + tm off+\addr, \mask
728 + .endm
729 +
730 ++ .macro BPOFF
731 ++ .pushsection .altinstr_replacement, "ax"
732 ++660: .long 0xb2e8c000
733 ++ .popsection
734 ++661: .long 0x47000000
735 ++ .pushsection .altinstructions, "a"
736 ++ .long 661b - .
737 ++ .long 660b - .
738 ++ .word 82
739 ++ .byte 4
740 ++ .byte 4
741 ++ .popsection
742 ++ .endm
743 ++
744 ++ .macro BPON
745 ++ .pushsection .altinstr_replacement, "ax"
746 ++662: .long 0xb2e8d000
747 ++ .popsection
748 ++663: .long 0x47000000
749 ++ .pushsection .altinstructions, "a"
750 ++ .long 663b - .
751 ++ .long 662b - .
752 ++ .word 82
753 ++ .byte 4
754 ++ .byte 4
755 ++ .popsection
756 ++ .endm
757 ++
758 ++ .macro BPENTER tif_ptr,tif_mask
759 ++ .pushsection .altinstr_replacement, "ax"
760 ++662: .word 0xc004, 0x0000, 0x0000 # 6 byte nop
761 ++ .word 0xc004, 0x0000, 0x0000 # 6 byte nop
762 ++ .popsection
763 ++664: TSTMSK \tif_ptr,\tif_mask
764 ++ jz . + 8
765 ++ .long 0xb2e8d000
766 ++ .pushsection .altinstructions, "a"
767 ++ .long 664b - .
768 ++ .long 662b - .
769 ++ .word 82
770 ++ .byte 12
771 ++ .byte 12
772 ++ .popsection
773 ++ .endm
774 ++
775 ++ .macro BPEXIT tif_ptr,tif_mask
776 ++ TSTMSK \tif_ptr,\tif_mask
777 ++ .pushsection .altinstr_replacement, "ax"
778 ++662: jnz . + 8
779 ++ .long 0xb2e8d000
780 ++ .popsection
781 ++664: jz . + 8
782 ++ .long 0xb2e8c000
783 ++ .pushsection .altinstructions, "a"
784 ++ .long 664b - .
785 ++ .long 662b - .
786 ++ .word 82
787 ++ .byte 8
788 ++ .byte 8
789 ++ .popsection
790 ++ .endm
791 ++
792 ++#ifdef CONFIG_EXPOLINE
793 ++
794 ++ .macro GEN_BR_THUNK name,reg,tmp
795 ++ .section .text.\name,"axG",@progbits,\name,comdat
796 ++ .globl \name
797 ++ .hidden \name
798 ++ .type \name,@function
799 ++\name:
800 ++ .cfi_startproc
801 ++#ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
802 ++ exrl 0,0f
803 ++#else
804 ++ larl \tmp,0f
805 ++ ex 0,0(\tmp)
806 ++#endif
807 ++ j .
808 ++0: br \reg
809 ++ .cfi_endproc
810 ++ .endm
811 ++
812 ++ GEN_BR_THUNK __s390x_indirect_jump_r1use_r9,%r9,%r1
813 ++ GEN_BR_THUNK __s390x_indirect_jump_r1use_r14,%r14,%r1
814 ++ GEN_BR_THUNK __s390x_indirect_jump_r11use_r14,%r14,%r11
815 ++
816 ++ .macro BASR_R14_R9
817 ++0: brasl %r14,__s390x_indirect_jump_r1use_r9
818 ++ .pushsection .s390_indirect_branches,"a",@progbits
819 ++ .long 0b-.
820 ++ .popsection
821 ++ .endm
822 ++
823 ++ .macro BR_R1USE_R14
824 ++0: jg __s390x_indirect_jump_r1use_r14
825 ++ .pushsection .s390_indirect_branches,"a",@progbits
826 ++ .long 0b-.
827 ++ .popsection
828 ++ .endm
829 ++
830 ++ .macro BR_R11USE_R14
831 ++0: jg __s390x_indirect_jump_r11use_r14
832 ++ .pushsection .s390_indirect_branches,"a",@progbits
833 ++ .long 0b-.
834 ++ .popsection
835 ++ .endm
836 ++
837 ++#else /* CONFIG_EXPOLINE */
838 ++
839 ++ .macro BASR_R14_R9
840 ++ basr %r14,%r9
841 ++ .endm
842 ++
843 ++ .macro BR_R1USE_R14
844 ++ br %r14
845 ++ .endm
846 ++
847 ++ .macro BR_R11USE_R14
848 ++ br %r14
849 ++ .endm
850 ++
851 ++#endif /* CONFIG_EXPOLINE */
852 ++
853 ++
854 + .section .kprobes.text, "ax"
855 + .Ldummy:
856 + /*
857 +@@ -170,6 +295,11 @@ _PIF_WORK = (_PIF_PER_TRAP | _PIF_SYSCALL_RESTART)
858 + */
859 + nop 0
860 +
861 ++ENTRY(__bpon)
862 ++ .globl __bpon
863 ++ BPON
864 ++ BR_R1USE_R14
865 ++
866 + /*
867 + * Scheduler resume function, called by switch_to
868 + * gpr2 = (task_struct *) prev
869 +@@ -193,9 +323,9 @@ ENTRY(__switch_to)
870 + mvc __LC_CURRENT_PID(4,%r0),__TASK_pid(%r3) # store pid of next
871 + lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
872 + TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_LPP
873 +- bzr %r14
874 ++ jz 0f
875 + .insn s,0xb2800000,__LC_LPP # set program parameter
876 +- br %r14
877 ++0: BR_R1USE_R14
878 +
879 + .L__critical_start:
880 +
881 +@@ -207,9 +337,11 @@ ENTRY(__switch_to)
882 + */
883 + ENTRY(sie64a)
884 + stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers
885 ++ lg %r12,__LC_CURRENT
886 + stg %r2,__SF_EMPTY(%r15) # save control block pointer
887 + stg %r3,__SF_EMPTY+8(%r15) # save guest register save area
888 + xc __SF_EMPTY+16(8,%r15),__SF_EMPTY+16(%r15) # reason code = 0
889 ++ mvc __SF_EMPTY+24(8,%r15),__TI_flags(%r12) # copy thread flags
890 + TSTMSK __LC_CPU_FLAGS,_CIF_FPU # load guest fp/vx registers ?
891 + jno .Lsie_load_guest_gprs
892 + brasl %r14,load_fpu_regs # load guest fp/vx regs
893 +@@ -226,8 +358,12 @@ ENTRY(sie64a)
894 + jnz .Lsie_skip
895 + TSTMSK __LC_CPU_FLAGS,_CIF_FPU
896 + jo .Lsie_skip # exit if fp/vx regs changed
897 ++ BPEXIT __SF_EMPTY+24(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
898 + .Lsie_entry:
899 + sie 0(%r14)
900 ++.Lsie_exit:
901 ++ BPOFF
902 ++ BPENTER __SF_EMPTY+24(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
903 + .Lsie_skip:
904 + ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE
905 + lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
906 +@@ -248,9 +384,15 @@ ENTRY(sie64a)
907 + sie_exit:
908 + lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
909 + stmg %r0,%r13,0(%r14) # save guest gprs 0-13
910 ++ xgr %r0,%r0 # clear guest registers to
911 ++ xgr %r1,%r1 # prevent speculative use
912 ++ xgr %r2,%r2
913 ++ xgr %r3,%r3
914 ++ xgr %r4,%r4
915 ++ xgr %r5,%r5
916 + lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
917 + lg %r2,__SF_EMPTY+16(%r15) # return exit reason code
918 +- br %r14
919 ++ BR_R1USE_R14
920 + .Lsie_fault:
921 + lghi %r14,-EFAULT
922 + stg %r14,__SF_EMPTY+16(%r15) # set exit reason code
923 +@@ -273,6 +415,7 @@ ENTRY(system_call)
924 + stpt __LC_SYNC_ENTER_TIMER
925 + .Lsysc_stmg:
926 + stmg %r8,%r15,__LC_SAVE_AREA_SYNC
927 ++ BPOFF
928 + lg %r12,__LC_CURRENT
929 + lghi %r13,__TASK_thread
930 + lghi %r14,_PIF_SYSCALL
931 +@@ -281,12 +424,15 @@ ENTRY(system_call)
932 + la %r11,STACK_FRAME_OVERHEAD(%r15) # pointer to pt_regs
933 + .Lsysc_vtime:
934 + UPDATE_VTIME %r8,%r9,__LC_SYNC_ENTER_TIMER
935 ++ BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
936 + stmg %r0,%r7,__PT_R0(%r11)
937 + mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
938 + mvc __PT_PSW(16,%r11),__LC_SVC_OLD_PSW
939 + mvc __PT_INT_CODE(4,%r11),__LC_SVC_ILC
940 + stg %r14,__PT_FLAGS(%r11)
941 + .Lsysc_do_svc:
942 ++ # clear user controlled register to prevent speculative use
943 ++ xgr %r0,%r0
944 + # load address of system call table
945 + lg %r10,__THREAD_sysc_table(%r13,%r12)
946 + llgh %r8,__PT_INT_CODE+2(%r11)
947 +@@ -305,7 +451,7 @@ ENTRY(system_call)
948 + lgf %r9,0(%r8,%r10) # get system call add.
949 + TSTMSK __TI_flags(%r12),_TIF_TRACE
950 + jnz .Lsysc_tracesys
951 +- basr %r14,%r9 # call sys_xxxx
952 ++ BASR_R14_R9 # call sys_xxxx
953 + stg %r2,__PT_R2(%r11) # store return value
954 +
955 + .Lsysc_return:
956 +@@ -317,6 +463,7 @@ ENTRY(system_call)
957 + jnz .Lsysc_work # check for work
958 + TSTMSK __LC_CPU_FLAGS,_CIF_WORK
959 + jnz .Lsysc_work
960 ++ BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP
961 + .Lsysc_restore:
962 + lg %r14,__LC_VDSO_PER_CPU
963 + lmg %r0,%r10,__PT_R0(%r11)
964 +@@ -481,7 +628,7 @@ ENTRY(system_call)
965 + lmg %r3,%r7,__PT_R3(%r11)
966 + stg %r7,STACK_FRAME_OVERHEAD(%r15)
967 + lg %r2,__PT_ORIG_GPR2(%r11)
968 +- basr %r14,%r9 # call sys_xxx
969 ++ BASR_R14_R9 # call sys_xxx
970 + stg %r2,__PT_R2(%r11) # store return value
971 + .Lsysc_tracenogo:
972 + TSTMSK __TI_flags(%r12),_TIF_TRACE
973 +@@ -505,7 +652,7 @@ ENTRY(ret_from_fork)
974 + lmg %r9,%r10,__PT_R9(%r11) # load gprs
975 + ENTRY(kernel_thread_starter)
976 + la %r2,0(%r10)
977 +- basr %r14,%r9
978 ++ BASR_R14_R9
979 + j .Lsysc_tracenogo
980 +
981 + /*
982 +@@ -514,6 +661,7 @@ ENTRY(kernel_thread_starter)
983 +
984 + ENTRY(pgm_check_handler)
985 + stpt __LC_SYNC_ENTER_TIMER
986 ++ BPOFF
987 + stmg %r8,%r15,__LC_SAVE_AREA_SYNC
988 + lg %r10,__LC_LAST_BREAK
989 + lg %r12,__LC_CURRENT
990 +@@ -540,6 +688,7 @@ ENTRY(pgm_check_handler)
991 + aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
992 + j 4f
993 + 2: UPDATE_VTIME %r14,%r15,__LC_SYNC_ENTER_TIMER
994 ++ BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
995 + lg %r15,__LC_KERNEL_STACK
996 + lgr %r14,%r12
997 + aghi %r14,__TASK_thread # pointer to thread_struct
998 +@@ -550,6 +699,15 @@ ENTRY(pgm_check_handler)
999 + 3: stg %r10,__THREAD_last_break(%r14)
1000 + 4: la %r11,STACK_FRAME_OVERHEAD(%r15)
1001 + stmg %r0,%r7,__PT_R0(%r11)
1002 ++ # clear user controlled registers to prevent speculative use
1003 ++ xgr %r0,%r0
1004 ++ xgr %r1,%r1
1005 ++ xgr %r2,%r2
1006 ++ xgr %r3,%r3
1007 ++ xgr %r4,%r4
1008 ++ xgr %r5,%r5
1009 ++ xgr %r6,%r6
1010 ++ xgr %r7,%r7
1011 + mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
1012 + stmg %r8,%r9,__PT_PSW(%r11)
1013 + mvc __PT_INT_CODE(4,%r11),__LC_PGM_ILC
1014 +@@ -571,9 +729,9 @@ ENTRY(pgm_check_handler)
1015 + nill %r10,0x007f
1016 + sll %r10,2
1017 + je .Lpgm_return
1018 +- lgf %r1,0(%r10,%r1) # load address of handler routine
1019 ++ lgf %r9,0(%r10,%r1) # load address of handler routine
1020 + lgr %r2,%r11 # pass pointer to pt_regs
1021 +- basr %r14,%r1 # branch to interrupt-handler
1022 ++ BASR_R14_R9 # branch to interrupt-handler
1023 + .Lpgm_return:
1024 + LOCKDEP_SYS_EXIT
1025 + tm __PT_PSW+1(%r11),0x01 # returning to user ?
1026 +@@ -609,12 +767,23 @@ ENTRY(pgm_check_handler)
1027 + ENTRY(io_int_handler)
1028 + STCK __LC_INT_CLOCK
1029 + stpt __LC_ASYNC_ENTER_TIMER
1030 ++ BPOFF
1031 + stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
1032 + lg %r12,__LC_CURRENT
1033 + larl %r13,cleanup_critical
1034 + lmg %r8,%r9,__LC_IO_OLD_PSW
1035 + SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_ENTER_TIMER
1036 + stmg %r0,%r7,__PT_R0(%r11)
1037 ++ # clear user controlled registers to prevent speculative use
1038 ++ xgr %r0,%r0
1039 ++ xgr %r1,%r1
1040 ++ xgr %r2,%r2
1041 ++ xgr %r3,%r3
1042 ++ xgr %r4,%r4
1043 ++ xgr %r5,%r5
1044 ++ xgr %r6,%r6
1045 ++ xgr %r7,%r7
1046 ++ xgr %r10,%r10
1047 + mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
1048 + stmg %r8,%r9,__PT_PSW(%r11)
1049 + mvc __PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
1050 +@@ -649,9 +818,13 @@ ENTRY(io_int_handler)
1051 + lg %r14,__LC_VDSO_PER_CPU
1052 + lmg %r0,%r10,__PT_R0(%r11)
1053 + mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
1054 ++ tm __PT_PSW+1(%r11),0x01 # returning to user ?
1055 ++ jno .Lio_exit_kernel
1056 ++ BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP
1057 + .Lio_exit_timer:
1058 + stpt __LC_EXIT_TIMER
1059 + mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
1060 ++.Lio_exit_kernel:
1061 + lmg %r11,%r15,__PT_R11(%r11)
1062 + lpswe __LC_RETURN_PSW
1063 + .Lio_done:
1064 +@@ -814,12 +987,23 @@ ENTRY(io_int_handler)
1065 + ENTRY(ext_int_handler)
1066 + STCK __LC_INT_CLOCK
1067 + stpt __LC_ASYNC_ENTER_TIMER
1068 ++ BPOFF
1069 + stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
1070 + lg %r12,__LC_CURRENT
1071 + larl %r13,cleanup_critical
1072 + lmg %r8,%r9,__LC_EXT_OLD_PSW
1073 + SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_ENTER_TIMER
1074 + stmg %r0,%r7,__PT_R0(%r11)
1075 ++ # clear user controlled registers to prevent speculative use
1076 ++ xgr %r0,%r0
1077 ++ xgr %r1,%r1
1078 ++ xgr %r2,%r2
1079 ++ xgr %r3,%r3
1080 ++ xgr %r4,%r4
1081 ++ xgr %r5,%r5
1082 ++ xgr %r6,%r6
1083 ++ xgr %r7,%r7
1084 ++ xgr %r10,%r10
1085 + mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
1086 + stmg %r8,%r9,__PT_PSW(%r11)
1087 + lghi %r1,__LC_EXT_PARAMS2
1088 +@@ -852,11 +1036,12 @@ ENTRY(psw_idle)
1089 + .Lpsw_idle_stcctm:
1090 + #endif
1091 + oi __LC_CPU_FLAGS+7,_CIF_ENABLED_WAIT
1092 ++ BPON
1093 + STCK __CLOCK_IDLE_ENTER(%r2)
1094 + stpt __TIMER_IDLE_ENTER(%r2)
1095 + .Lpsw_idle_lpsw:
1096 + lpswe __SF_EMPTY(%r15)
1097 +- br %r14
1098 ++ BR_R1USE_R14
1099 + .Lpsw_idle_end:
1100 +
1101 + /*
1102 +@@ -870,7 +1055,7 @@ ENTRY(save_fpu_regs)
1103 + lg %r2,__LC_CURRENT
1104 + aghi %r2,__TASK_thread
1105 + TSTMSK __LC_CPU_FLAGS,_CIF_FPU
1106 +- bor %r14
1107 ++ jo .Lsave_fpu_regs_exit
1108 + stfpc __THREAD_FPU_fpc(%r2)
1109 + lg %r3,__THREAD_FPU_regs(%r2)
1110 + TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_VX
1111 +@@ -897,7 +1082,8 @@ ENTRY(save_fpu_regs)
1112 + std 15,120(%r3)
1113 + .Lsave_fpu_regs_done:
1114 + oi __LC_CPU_FLAGS+7,_CIF_FPU
1115 +- br %r14
1116 ++.Lsave_fpu_regs_exit:
1117 ++ BR_R1USE_R14
1118 + .Lsave_fpu_regs_end:
1119 + EXPORT_SYMBOL(save_fpu_regs)
1120 +
1121 +@@ -915,7 +1101,7 @@ load_fpu_regs:
1122 + lg %r4,__LC_CURRENT
1123 + aghi %r4,__TASK_thread
1124 + TSTMSK __LC_CPU_FLAGS,_CIF_FPU
1125 +- bnor %r14
1126 ++ jno .Lload_fpu_regs_exit
1127 + lfpc __THREAD_FPU_fpc(%r4)
1128 + TSTMSK __LC_MACHINE_FLAGS,MACHINE_FLAG_VX
1129 + lg %r4,__THREAD_FPU_regs(%r4) # %r4 <- reg save area
1130 +@@ -942,7 +1128,8 @@ load_fpu_regs:
1131 + ld 15,120(%r4)
1132 + .Lload_fpu_regs_done:
1133 + ni __LC_CPU_FLAGS+7,255-_CIF_FPU
1134 +- br %r14
1135 ++.Lload_fpu_regs_exit:
1136 ++ BR_R1USE_R14
1137 + .Lload_fpu_regs_end:
1138 +
1139 + .L__critical_end:
1140 +@@ -952,6 +1139,7 @@ load_fpu_regs:
1141 + */
1142 + ENTRY(mcck_int_handler)
1143 + STCK __LC_MCCK_CLOCK
1144 ++ BPOFF
1145 + la %r1,4095 # revalidate r1
1146 + spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # revalidate cpu timer
1147 + lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# revalidate gprs
1148 +@@ -982,6 +1170,16 @@ ENTRY(mcck_int_handler)
1149 + .Lmcck_skip:
1150 + lghi %r14,__LC_GPREGS_SAVE_AREA+64
1151 + stmg %r0,%r7,__PT_R0(%r11)
1152 ++ # clear user controlled registers to prevent speculative use
1153 ++ xgr %r0,%r0
1154 ++ xgr %r1,%r1
1155 ++ xgr %r2,%r2
1156 ++ xgr %r3,%r3
1157 ++ xgr %r4,%r4
1158 ++ xgr %r5,%r5
1159 ++ xgr %r6,%r6
1160 ++ xgr %r7,%r7
1161 ++ xgr %r10,%r10
1162 + mvc __PT_R8(64,%r11),0(%r14)
1163 + stmg %r8,%r9,__PT_PSW(%r11)
1164 + xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
1165 +@@ -1007,6 +1205,7 @@ ENTRY(mcck_int_handler)
1166 + mvc __LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW
1167 + tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
1168 + jno 0f
1169 ++ BPEXIT __TI_flags(%r12),_TIF_ISOLATE_BP
1170 + stpt __LC_EXIT_TIMER
1171 + mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
1172 + 0: lmg %r11,%r15,__PT_R11(%r11)
1173 +@@ -1102,7 +1301,7 @@ cleanup_critical:
1174 + jl 0f
1175 + clg %r9,BASED(.Lcleanup_table+104) # .Lload_fpu_regs_end
1176 + jl .Lcleanup_load_fpu_regs
1177 +-0: br %r14
1178 ++0: BR_R11USE_R14
1179 +
1180 + .align 8
1181 + .Lcleanup_table:
1182 +@@ -1133,11 +1332,12 @@ cleanup_critical:
1183 + clg %r9,BASED(.Lsie_crit_mcck_length)
1184 + jh 1f
1185 + oi __LC_CPU_FLAGS+7, _CIF_MCCK_GUEST
1186 +-1: lg %r9,__SF_EMPTY(%r15) # get control block pointer
1187 ++1: BPENTER __SF_EMPTY+24(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
1188 ++ lg %r9,__SF_EMPTY(%r15) # get control block pointer
1189 + ni __SIE_PROG0C+3(%r9),0xfe # no longer in SIE
1190 + lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
1191 + larl %r9,sie_exit # skip forward to sie_exit
1192 +- br %r14
1193 ++ BR_R11USE_R14
1194 + #endif
1195 +
1196 + .Lcleanup_system_call:
1197 +@@ -1175,6 +1375,7 @@ cleanup_critical:
1198 + stg %r15,__LC_SYSTEM_TIMER
1199 + 0: # update accounting time stamp
1200 + mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
1201 ++ BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
1202 + # set up saved register r11
1203 + lg %r15,__LC_KERNEL_STACK
1204 + la %r9,STACK_FRAME_OVERHEAD(%r15)
1205 +@@ -1190,7 +1391,7 @@ cleanup_critical:
1206 + stg %r15,56(%r11) # r15 stack pointer
1207 + # set new psw address and exit
1208 + larl %r9,.Lsysc_do_svc
1209 +- br %r14
1210 ++ BR_R11USE_R14
1211 + .Lcleanup_system_call_insn:
1212 + .quad system_call
1213 + .quad .Lsysc_stmg
1214 +@@ -1202,7 +1403,7 @@ cleanup_critical:
1215 +
1216 + .Lcleanup_sysc_tif:
1217 + larl %r9,.Lsysc_tif
1218 +- br %r14
1219 ++ BR_R11USE_R14
1220 +
1221 + .Lcleanup_sysc_restore:
1222 + # check if stpt has been executed
1223 +@@ -1219,14 +1420,14 @@ cleanup_critical:
1224 + mvc 0(64,%r11),__PT_R8(%r9)
1225 + lmg %r0,%r7,__PT_R0(%r9)
1226 + 1: lmg %r8,%r9,__LC_RETURN_PSW
1227 +- br %r14
1228 ++ BR_R11USE_R14
1229 + .Lcleanup_sysc_restore_insn:
1230 + .quad .Lsysc_exit_timer
1231 + .quad .Lsysc_done - 4
1232 +
1233 + .Lcleanup_io_tif:
1234 + larl %r9,.Lio_tif
1235 +- br %r14
1236 ++ BR_R11USE_R14
1237 +
1238 + .Lcleanup_io_restore:
1239 + # check if stpt has been executed
1240 +@@ -1240,7 +1441,7 @@ cleanup_critical:
1241 + mvc 0(64,%r11),__PT_R8(%r9)
1242 + lmg %r0,%r7,__PT_R0(%r9)
1243 + 1: lmg %r8,%r9,__LC_RETURN_PSW
1244 +- br %r14
1245 ++ BR_R11USE_R14
1246 + .Lcleanup_io_restore_insn:
1247 + .quad .Lio_exit_timer
1248 + .quad .Lio_done - 4
1249 +@@ -1293,17 +1494,17 @@ cleanup_critical:
1250 + # prepare return psw
1251 + nihh %r8,0xfcfd # clear irq & wait state bits
1252 + lg %r9,48(%r11) # return from psw_idle
1253 +- br %r14
1254 ++ BR_R11USE_R14
1255 + .Lcleanup_idle_insn:
1256 + .quad .Lpsw_idle_lpsw
1257 +
1258 + .Lcleanup_save_fpu_regs:
1259 + larl %r9,save_fpu_regs
1260 +- br %r14
1261 ++ BR_R11USE_R14
1262 +
1263 + .Lcleanup_load_fpu_regs:
1264 + larl %r9,load_fpu_regs
1265 +- br %r14
1266 ++ BR_R11USE_R14
1267 +
1268 + /*
1269 + * Integer constants
1270 +@@ -1323,7 +1524,6 @@ cleanup_critical:
1271 + .Lsie_crit_mcck_length:
1272 + .quad .Lsie_skip - .Lsie_entry
1273 + #endif
1274 +-
1275 + .section .rodata, "a"
1276 + #define SYSCALL(esame,emu) .long esame
1277 + .globl sys_call_table
1278 +diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
1279 +index d1a0e2c521d7..b565e784bae8 100644
1280 +--- a/arch/s390/kernel/ipl.c
1281 ++++ b/arch/s390/kernel/ipl.c
1282 +@@ -564,6 +564,7 @@ static struct kset *ipl_kset;
1283 +
1284 + static void __ipl_run(void *unused)
1285 + {
1286 ++ __bpon();
1287 + diag308(DIAG308_LOAD_CLEAR, NULL);
1288 + if (MACHINE_IS_VM)
1289 + __cpcmd("IPL", NULL, 0, NULL);
1290 +diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
1291 +index 1a27f307a920..b441e069e674 100644
1292 +--- a/arch/s390/kernel/module.c
1293 ++++ b/arch/s390/kernel/module.c
1294 +@@ -31,6 +31,9 @@
1295 + #include <linux/kernel.h>
1296 + #include <linux/moduleloader.h>
1297 + #include <linux/bug.h>
1298 ++#include <asm/alternative.h>
1299 ++#include <asm/nospec-branch.h>
1300 ++#include <asm/facility.h>
1301 +
1302 + #if 0
1303 + #define DEBUGP printk
1304 +@@ -168,7 +171,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
1305 + me->arch.got_offset = me->core_layout.size;
1306 + me->core_layout.size += me->arch.got_size;
1307 + me->arch.plt_offset = me->core_layout.size;
1308 +- me->core_layout.size += me->arch.plt_size;
1309 ++ if (me->arch.plt_size) {
1310 ++ if (IS_ENABLED(CONFIG_EXPOLINE) && !nospec_disable)
1311 ++ me->arch.plt_size += PLT_ENTRY_SIZE;
1312 ++ me->core_layout.size += me->arch.plt_size;
1313 ++ }
1314 + return 0;
1315 + }
1316 +
1317 +@@ -322,9 +329,20 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
1318 + unsigned int *ip;
1319 + ip = me->core_layout.base + me->arch.plt_offset +
1320 + info->plt_offset;
1321 +- ip[0] = 0x0d10e310; /* basr 1,0; lg 1,10(1); br 1 */
1322 +- ip[1] = 0x100a0004;
1323 +- ip[2] = 0x07f10000;
1324 ++ ip[0] = 0x0d10e310; /* basr 1,0 */
1325 ++ ip[1] = 0x100a0004; /* lg 1,10(1) */
1326 ++ if (IS_ENABLED(CONFIG_EXPOLINE) && !nospec_disable) {
1327 ++ unsigned int *ij;
1328 ++ ij = me->core_layout.base +
1329 ++ me->arch.plt_offset +
1330 ++ me->arch.plt_size - PLT_ENTRY_SIZE;
1331 ++ ip[2] = 0xa7f40000 + /* j __jump_r1 */
1332 ++ (unsigned int)(u16)
1333 ++ (((unsigned long) ij - 8 -
1334 ++ (unsigned long) ip) / 2);
1335 ++ } else {
1336 ++ ip[2] = 0x07f10000; /* br %r1 */
1337 ++ }
1338 + ip[3] = (unsigned int) (val >> 32);
1339 + ip[4] = (unsigned int) val;
1340 + info->plt_initialized = 1;
1341 +@@ -429,6 +447,45 @@ int module_finalize(const Elf_Ehdr *hdr,
1342 + const Elf_Shdr *sechdrs,
1343 + struct module *me)
1344 + {
1345 ++ const Elf_Shdr *s;
1346 ++ char *secstrings, *secname;
1347 ++ void *aseg;
1348 ++
1349 ++ if (IS_ENABLED(CONFIG_EXPOLINE) &&
1350 ++ !nospec_disable && me->arch.plt_size) {
1351 ++ unsigned int *ij;
1352 ++
1353 ++ ij = me->core_layout.base + me->arch.plt_offset +
1354 ++ me->arch.plt_size - PLT_ENTRY_SIZE;
1355 ++ if (test_facility(35)) {
1356 ++ ij[0] = 0xc6000000; /* exrl %r0,.+10 */
1357 ++ ij[1] = 0x0005a7f4; /* j . */
1358 ++ ij[2] = 0x000007f1; /* br %r1 */
1359 ++ } else {
1360 ++ ij[0] = 0x44000000 | (unsigned int)
1361 ++ offsetof(struct lowcore, br_r1_trampoline);
1362 ++ ij[1] = 0xa7f40000; /* j . */
1363 ++ }
1364 ++ }
1365 ++
1366 ++ secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
1367 ++ for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
1368 ++ aseg = (void *) s->sh_addr;
1369 ++ secname = secstrings + s->sh_name;
1370 ++
1371 ++ if (!strcmp(".altinstructions", secname))
1372 ++ /* patch .altinstructions */
1373 ++ apply_alternatives(aseg, aseg + s->sh_size);
1374 ++
1375 ++ if (IS_ENABLED(CONFIG_EXPOLINE) &&
1376 ++ (!strncmp(".s390_indirect", secname, 14)))
1377 ++ nospec_revert(aseg, aseg + s->sh_size);
1378 ++
1379 ++ if (IS_ENABLED(CONFIG_EXPOLINE) &&
1380 ++ (!strncmp(".s390_return", secname, 12)))
1381 ++ nospec_revert(aseg, aseg + s->sh_size);
1382 ++ }
1383 ++
1384 + jump_label_apply_nops(me);
1385 + return 0;
1386 + }
1387 +diff --git a/arch/s390/kernel/nospec-branch.c b/arch/s390/kernel/nospec-branch.c
1388 +new file mode 100644
1389 +index 000000000000..9f3b5b382743
1390 +--- /dev/null
1391 ++++ b/arch/s390/kernel/nospec-branch.c
1392 +@@ -0,0 +1,169 @@
1393 ++// SPDX-License-Identifier: GPL-2.0
1394 ++#include <linux/module.h>
1395 ++#include <linux/device.h>
1396 ++#include <asm/facility.h>
1397 ++#include <asm/nospec-branch.h>
1398 ++
1399 ++static int __init nobp_setup_early(char *str)
1400 ++{
1401 ++ bool enabled;
1402 ++ int rc;
1403 ++
1404 ++ rc = kstrtobool(str, &enabled);
1405 ++ if (rc)
1406 ++ return rc;
1407 ++ if (enabled && test_facility(82)) {
1408 ++ /*
1409 ++ * The user explicitely requested nobp=1, enable it and
1410 ++ * disable the expoline support.
1411 ++ */
1412 ++ __set_facility(82, S390_lowcore.alt_stfle_fac_list);
1413 ++ if (IS_ENABLED(CONFIG_EXPOLINE))
1414 ++ nospec_disable = 1;
1415 ++ } else {
1416 ++ __clear_facility(82, S390_lowcore.alt_stfle_fac_list);
1417 ++ }
1418 ++ return 0;
1419 ++}
1420 ++early_param("nobp", nobp_setup_early);
1421 ++
1422 ++static int __init nospec_setup_early(char *str)
1423 ++{
1424 ++ __clear_facility(82, S390_lowcore.alt_stfle_fac_list);
1425 ++ return 0;
1426 ++}
1427 ++early_param("nospec", nospec_setup_early);
1428 ++
1429 ++static int __init nospec_report(void)
1430 ++{
1431 ++ if (IS_ENABLED(CC_USING_EXPOLINE) && !nospec_disable)
1432 ++ pr_info("Spectre V2 mitigation: execute trampolines.\n");
1433 ++ if (__test_facility(82, S390_lowcore.alt_stfle_fac_list))
1434 ++ pr_info("Spectre V2 mitigation: limited branch prediction.\n");
1435 ++ return 0;
1436 ++}
1437 ++arch_initcall(nospec_report);
1438 ++
1439 ++#ifdef CONFIG_SYSFS
1440 ++ssize_t cpu_show_spectre_v1(struct device *dev,
1441 ++ struct device_attribute *attr, char *buf)
1442 ++{
1443 ++ return sprintf(buf, "Mitigation: __user pointer sanitization\n");
1444 ++}
1445 ++
1446 ++ssize_t cpu_show_spectre_v2(struct device *dev,
1447 ++ struct device_attribute *attr, char *buf)
1448 ++{
1449 ++ if (IS_ENABLED(CC_USING_EXPOLINE) && !nospec_disable)
1450 ++ return sprintf(buf, "Mitigation: execute trampolines\n");
1451 ++ if (__test_facility(82, S390_lowcore.alt_stfle_fac_list))
1452 ++ return sprintf(buf, "Mitigation: limited branch prediction.\n");
1453 ++ return sprintf(buf, "Vulnerable\n");
1454 ++}
1455 ++#endif
1456 ++
1457 ++#ifdef CONFIG_EXPOLINE
1458 ++
1459 ++int nospec_disable = IS_ENABLED(CONFIG_EXPOLINE_OFF);
1460 ++
1461 ++static int __init nospectre_v2_setup_early(char *str)
1462 ++{
1463 ++ nospec_disable = 1;
1464 ++ return 0;
1465 ++}
1466 ++early_param("nospectre_v2", nospectre_v2_setup_early);
1467 ++
1468 ++void __init nospec_auto_detect(void)
1469 ++{
1470 ++ if (IS_ENABLED(CC_USING_EXPOLINE)) {
1471 ++ /*
1472 ++ * The kernel has been compiled with expolines.
1473 ++ * Keep expolines enabled and disable nobp.
1474 ++ */
1475 ++ nospec_disable = 0;
1476 ++ __clear_facility(82, S390_lowcore.alt_stfle_fac_list);
1477 ++ }
1478 ++ /*
1479 ++ * If the kernel has not been compiled with expolines the
1480 ++ * nobp setting decides what is done, this depends on the
1481 ++ * CONFIG_KERNEL_NP option and the nobp/nospec parameters.
1482 ++ */
1483 ++}
1484 ++
1485 ++static int __init spectre_v2_setup_early(char *str)
1486 ++{
1487 ++ if (str && !strncmp(str, "on", 2)) {
1488 ++ nospec_disable = 0;
1489 ++ __clear_facility(82, S390_lowcore.alt_stfle_fac_list);
1490 ++ }
1491 ++ if (str && !strncmp(str, "off", 3))
1492 ++ nospec_disable = 1;
1493 ++ if (str && !strncmp(str, "auto", 4))
1494 ++ nospec_auto_detect();
1495 ++ return 0;
1496 ++}
1497 ++early_param("spectre_v2", spectre_v2_setup_early);
1498 ++
1499 ++static void __init_or_module __nospec_revert(s32 *start, s32 *end)
1500 ++{
1501 ++ enum { BRCL_EXPOLINE, BRASL_EXPOLINE } type;
1502 ++ u8 *instr, *thunk, *br;
1503 ++ u8 insnbuf[6];
1504 ++ s32 *epo;
1505 ++
1506 ++ /* Second part of the instruction replace is always a nop */
1507 ++ memcpy(insnbuf + 2, (char[]) { 0x47, 0x00, 0x00, 0x00 }, 4);
1508 ++ for (epo = start; epo < end; epo++) {
1509 ++ instr = (u8 *) epo + *epo;
1510 ++ if (instr[0] == 0xc0 && (instr[1] & 0x0f) == 0x04)
1511 ++ type = BRCL_EXPOLINE; /* brcl instruction */
1512 ++ else if (instr[0] == 0xc0 && (instr[1] & 0x0f) == 0x05)
1513 ++ type = BRASL_EXPOLINE; /* brasl instruction */
1514 ++ else
1515 ++ continue;
1516 ++ thunk = instr + (*(int *)(instr + 2)) * 2;
1517 ++ if (thunk[0] == 0xc6 && thunk[1] == 0x00)
1518 ++ /* exrl %r0,<target-br> */
1519 ++ br = thunk + (*(int *)(thunk + 2)) * 2;
1520 ++ else if (thunk[0] == 0xc0 && (thunk[1] & 0x0f) == 0x00 &&
1521 ++ thunk[6] == 0x44 && thunk[7] == 0x00 &&
1522 ++ (thunk[8] & 0x0f) == 0x00 && thunk[9] == 0x00 &&
1523 ++ (thunk[1] & 0xf0) == (thunk[8] & 0xf0))
1524 ++ /* larl %rx,<target br> + ex %r0,0(%rx) */
1525 ++ br = thunk + (*(int *)(thunk + 2)) * 2;
1526 ++ else
1527 ++ continue;
1528 ++ if (br[0] != 0x07 || (br[1] & 0xf0) != 0xf0)
1529 ++ continue;
1530 ++ switch (type) {
1531 ++ case BRCL_EXPOLINE:
1532 ++ /* brcl to thunk, replace with br + nop */
1533 ++ insnbuf[0] = br[0];
1534 ++ insnbuf[1] = (instr[1] & 0xf0) | (br[1] & 0x0f);
1535 ++ break;
1536 ++ case BRASL_EXPOLINE:
1537 ++ /* brasl to thunk, replace with basr + nop */
1538 ++ insnbuf[0] = 0x0d;
1539 ++ insnbuf[1] = (instr[1] & 0xf0) | (br[1] & 0x0f);
1540 ++ break;
1541 ++ }
1542 ++
1543 ++ s390_kernel_write(instr, insnbuf, 6);
1544 ++ }
1545 ++}
1546 ++
1547 ++void __init_or_module nospec_revert(s32 *start, s32 *end)
1548 ++{
1549 ++ if (nospec_disable)
1550 ++ __nospec_revert(start, end);
1551 ++}
1552 ++
1553 ++extern s32 __nospec_call_start[], __nospec_call_end[];
1554 ++extern s32 __nospec_return_start[], __nospec_return_end[];
1555 ++void __init nospec_init_branches(void)
1556 ++{
1557 ++ nospec_revert(__nospec_call_start, __nospec_call_end);
1558 ++ nospec_revert(__nospec_return_start, __nospec_return_end);
1559 ++}
1560 ++
1561 ++#endif /* CONFIG_EXPOLINE */
1562 +diff --git a/arch/s390/kernel/processor.c b/arch/s390/kernel/processor.c
1563 +index 5362fd868d0d..6fe2e1875058 100644
1564 +--- a/arch/s390/kernel/processor.c
1565 ++++ b/arch/s390/kernel/processor.c
1566 +@@ -197,3 +197,21 @@ const struct seq_operations cpuinfo_op = {
1567 + .stop = c_stop,
1568 + .show = show_cpuinfo,
1569 + };
1570 ++
1571 ++int s390_isolate_bp(void)
1572 ++{
1573 ++ if (!test_facility(82))
1574 ++ return -EOPNOTSUPP;
1575 ++ set_thread_flag(TIF_ISOLATE_BP);
1576 ++ return 0;
1577 ++}
1578 ++EXPORT_SYMBOL(s390_isolate_bp);
1579 ++
1580 ++int s390_isolate_bp_guest(void)
1581 ++{
1582 ++ if (!test_facility(82))
1583 ++ return -EOPNOTSUPP;
1584 ++ set_thread_flag(TIF_ISOLATE_BP_GUEST);
1585 ++ return 0;
1586 ++}
1587 ++EXPORT_SYMBOL(s390_isolate_bp_guest);
1588 +diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
1589 +index 164a1e16b53e..98c1f7941142 100644
1590 +--- a/arch/s390/kernel/setup.c
1591 ++++ b/arch/s390/kernel/setup.c
1592 +@@ -66,6 +66,8 @@
1593 + #include <asm/sclp.h>
1594 + #include <asm/sysinfo.h>
1595 + #include <asm/numa.h>
1596 ++#include <asm/alternative.h>
1597 ++#include <asm/nospec-branch.h>
1598 + #include "entry.h"
1599 +
1600 + /*
1601 +@@ -338,7 +340,9 @@ static void __init setup_lowcore(void)
1602 + lc->preempt_count = S390_lowcore.preempt_count;
1603 + lc->stfl_fac_list = S390_lowcore.stfl_fac_list;
1604 + memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
1605 +- MAX_FACILITY_BIT/8);
1606 ++ sizeof(lc->stfle_fac_list));
1607 ++ memcpy(lc->alt_stfle_fac_list, S390_lowcore.alt_stfle_fac_list,
1608 ++ sizeof(lc->alt_stfle_fac_list));
1609 + if (MACHINE_HAS_VX || MACHINE_HAS_GS) {
1610 + unsigned long bits, size;
1611 +
1612 +@@ -381,6 +385,7 @@ static void __init setup_lowcore(void)
1613 + #ifdef CONFIG_SMP
1614 + lc->spinlock_lockval = arch_spin_lockval(0);
1615 + #endif
1616 ++ lc->br_r1_trampoline = 0x07f1; /* br %r1 */
1617 +
1618 + set_prefix((u32)(unsigned long) lc);
1619 + lowcore_ptr[0] = lc;
1620 +@@ -892,6 +897,9 @@ void __init setup_arch(char **cmdline_p)
1621 + init_mm.end_data = (unsigned long) &_edata;
1622 + init_mm.brk = (unsigned long) &_end;
1623 +
1624 ++ if (IS_ENABLED(CONFIG_EXPOLINE_AUTO))
1625 ++ nospec_auto_detect();
1626 ++
1627 + parse_early_param();
1628 + #ifdef CONFIG_CRASH_DUMP
1629 + /* Deactivate elfcorehdr= kernel parameter */
1630 +@@ -955,6 +963,10 @@ void __init setup_arch(char **cmdline_p)
1631 + conmode_default();
1632 + set_preferred_console();
1633 +
1634 ++ apply_alternative_instructions();
1635 ++ if (IS_ENABLED(CONFIG_EXPOLINE))
1636 ++ nospec_init_branches();
1637 ++
1638 + /* Setup zfcpdump support */
1639 + setup_zfcpdump();
1640 +
1641 +diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c
1642 +index 7ffaf9fd6d19..ae5df4177803 100644
1643 +--- a/arch/s390/kernel/smp.c
1644 ++++ b/arch/s390/kernel/smp.c
1645 +@@ -228,6 +228,7 @@ static int pcpu_alloc_lowcore(struct pcpu *pcpu, int cpu)
1646 + lc->mcesad = mcesa_origin | mcesa_bits;
1647 + lc->cpu_nr = cpu;
1648 + lc->spinlock_lockval = arch_spin_lockval(cpu);
1649 ++ lc->br_r1_trampoline = 0x07f1; /* br %r1 */
1650 + if (vdso_alloc_per_cpu(lc))
1651 + goto out;
1652 + lowcore_ptr[cpu] = lc;
1653 +@@ -282,7 +283,9 @@ static void pcpu_prepare_secondary(struct pcpu *pcpu, int cpu)
1654 + __ctl_store(lc->cregs_save_area, 0, 15);
1655 + save_access_regs((unsigned int *) lc->access_regs_save_area);
1656 + memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
1657 +- MAX_FACILITY_BIT/8);
1658 ++ sizeof(lc->stfle_fac_list));
1659 ++ memcpy(lc->alt_stfle_fac_list, S390_lowcore.alt_stfle_fac_list,
1660 ++ sizeof(lc->alt_stfle_fac_list));
1661 + }
1662 +
1663 + static void pcpu_attach_task(struct pcpu *pcpu, struct task_struct *tsk)
1664 +@@ -332,6 +335,7 @@ static void pcpu_delegate(struct pcpu *pcpu, void (*func)(void *),
1665 + mem_assign_absolute(lc->restart_fn, (unsigned long) func);
1666 + mem_assign_absolute(lc->restart_data, (unsigned long) data);
1667 + mem_assign_absolute(lc->restart_source, source_cpu);
1668 ++ __bpon();
1669 + asm volatile(
1670 + "0: sigp 0,%0,%2 # sigp restart to target cpu\n"
1671 + " brc 2,0b # busy, try again\n"
1672 +@@ -907,6 +911,7 @@ void __cpu_die(unsigned int cpu)
1673 + void __noreturn cpu_die(void)
1674 + {
1675 + idle_task_exit();
1676 ++ __bpon();
1677 + pcpu_sigp_retry(pcpu_devices + smp_processor_id(), SIGP_STOP, 0);
1678 + for (;;) ;
1679 + }
1680 +diff --git a/arch/s390/kernel/uprobes.c b/arch/s390/kernel/uprobes.c
1681 +index d9d1f512f019..5007fac01bb5 100644
1682 +--- a/arch/s390/kernel/uprobes.c
1683 ++++ b/arch/s390/kernel/uprobes.c
1684 +@@ -150,6 +150,15 @@ unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline,
1685 + return orig;
1686 + }
1687 +
1688 ++bool arch_uretprobe_is_alive(struct return_instance *ret, enum rp_check ctx,
1689 ++ struct pt_regs *regs)
1690 ++{
1691 ++ if (ctx == RP_CHECK_CHAIN_CALL)
1692 ++ return user_stack_pointer(regs) <= ret->stack;
1693 ++ else
1694 ++ return user_stack_pointer(regs) < ret->stack;
1695 ++}
1696 ++
1697 + /* Instruction Emulation */
1698 +
1699 + static void adjust_psw_addr(psw_t *psw, unsigned long len)
1700 +diff --git a/arch/s390/kernel/vmlinux.lds.S b/arch/s390/kernel/vmlinux.lds.S
1701 +index 96a713a470e7..85dd3c7bdd86 100644
1702 +--- a/arch/s390/kernel/vmlinux.lds.S
1703 ++++ b/arch/s390/kernel/vmlinux.lds.S
1704 +@@ -105,6 +105,43 @@ SECTIONS
1705 + EXIT_DATA
1706 + }
1707 +
1708 ++ /*
1709 ++ * struct alt_inst entries. From the header (alternative.h):
1710 ++ * "Alternative instructions for different CPU types or capabilities"
1711 ++ * Think locking instructions on spinlocks.
1712 ++ * Note, that it is a part of __init region.
1713 ++ */
1714 ++ . = ALIGN(8);
1715 ++ .altinstructions : {
1716 ++ __alt_instructions = .;
1717 ++ *(.altinstructions)
1718 ++ __alt_instructions_end = .;
1719 ++ }
1720 ++
1721 ++ /*
1722 ++ * And here are the replacement instructions. The linker sticks
1723 ++ * them as binary blobs. The .altinstructions has enough data to
1724 ++ * get the address and the length of them to patch the kernel safely.
1725 ++ * Note, that it is a part of __init region.
1726 ++ */
1727 ++ .altinstr_replacement : {
1728 ++ *(.altinstr_replacement)
1729 ++ }
1730 ++
1731 ++ /*
1732 ++ * Table with the patch locations to undo expolines
1733 ++ */
1734 ++ .nospec_call_table : {
1735 ++ __nospec_call_start = . ;
1736 ++ *(.s390_indirect*)
1737 ++ __nospec_call_end = . ;
1738 ++ }
1739 ++ .nospec_return_table : {
1740 ++ __nospec_return_start = . ;
1741 ++ *(.s390_return*)
1742 ++ __nospec_return_end = . ;
1743 ++ }
1744 ++
1745 + /* early.c uses stsi, which requires page aligned data. */
1746 + . = ALIGN(PAGE_SIZE);
1747 + INIT_DATA_SECTION(0x100)
1748 +diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
1749 +index 0bce918db11a..4f6adbea592b 100644
1750 +--- a/arch/s390/kvm/kvm-s390.c
1751 ++++ b/arch/s390/kvm/kvm-s390.c
1752 +@@ -449,6 +449,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
1753 + case KVM_CAP_S390_GS:
1754 + r = test_facility(133);
1755 + break;
1756 ++ case KVM_CAP_S390_BPB:
1757 ++ r = test_facility(82);
1758 ++ break;
1759 + default:
1760 + r = 0;
1761 + }
1762 +@@ -2231,6 +2234,8 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
1763 + kvm_s390_set_prefix(vcpu, 0);
1764 + if (test_kvm_facility(vcpu->kvm, 64))
1765 + vcpu->run->kvm_valid_regs |= KVM_SYNC_RICCB;
1766 ++ if (test_kvm_facility(vcpu->kvm, 82))
1767 ++ vcpu->run->kvm_valid_regs |= KVM_SYNC_BPBC;
1768 + if (test_kvm_facility(vcpu->kvm, 133))
1769 + vcpu->run->kvm_valid_regs |= KVM_SYNC_GSCB;
1770 + /* fprs can be synchronized via vrs, even if the guest has no vx. With
1771 +@@ -2372,6 +2377,7 @@ static void kvm_s390_vcpu_initial_reset(struct kvm_vcpu *vcpu)
1772 + current->thread.fpu.fpc = 0;
1773 + vcpu->arch.sie_block->gbea = 1;
1774 + vcpu->arch.sie_block->pp = 0;
1775 ++ vcpu->arch.sie_block->fpf &= ~FPF_BPBC;
1776 + vcpu->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
1777 + kvm_clear_async_pf_completion_queue(vcpu);
1778 + if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm))
1779 +@@ -3318,6 +3324,11 @@ static void sync_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1780 + vcpu->arch.sie_block->ecd |= ECD_HOSTREGMGMT;
1781 + vcpu->arch.gs_enabled = 1;
1782 + }
1783 ++ if ((kvm_run->kvm_dirty_regs & KVM_SYNC_BPBC) &&
1784 ++ test_kvm_facility(vcpu->kvm, 82)) {
1785 ++ vcpu->arch.sie_block->fpf &= ~FPF_BPBC;
1786 ++ vcpu->arch.sie_block->fpf |= kvm_run->s.regs.bpbc ? FPF_BPBC : 0;
1787 ++ }
1788 + save_access_regs(vcpu->arch.host_acrs);
1789 + restore_access_regs(vcpu->run->s.regs.acrs);
1790 + /* save host (userspace) fprs/vrs */
1791 +@@ -3364,6 +3375,7 @@ static void store_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1792 + kvm_run->s.regs.pft = vcpu->arch.pfault_token;
1793 + kvm_run->s.regs.pfs = vcpu->arch.pfault_select;
1794 + kvm_run->s.regs.pfc = vcpu->arch.pfault_compare;
1795 ++ kvm_run->s.regs.bpbc = (vcpu->arch.sie_block->fpf & FPF_BPBC) == FPF_BPBC;
1796 + save_access_regs(vcpu->run->s.regs.acrs);
1797 + restore_access_regs(vcpu->arch.host_acrs);
1798 + /* Save guest register state */
1799 +diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
1800 +index a74204db759b..eb7b530d1783 100644
1801 +--- a/arch/s390/kvm/vsie.c
1802 ++++ b/arch/s390/kvm/vsie.c
1803 +@@ -234,6 +234,12 @@ static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
1804 + memcpy(scb_o->gcr, scb_s->gcr, 128);
1805 + scb_o->pp = scb_s->pp;
1806 +
1807 ++ /* branch prediction */
1808 ++ if (test_kvm_facility(vcpu->kvm, 82)) {
1809 ++ scb_o->fpf &= ~FPF_BPBC;
1810 ++ scb_o->fpf |= scb_s->fpf & FPF_BPBC;
1811 ++ }
1812 ++
1813 + /* interrupt intercept */
1814 + switch (scb_s->icptcode) {
1815 + case ICPT_PROGI:
1816 +@@ -280,6 +286,7 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
1817 + scb_s->ecb3 = 0;
1818 + scb_s->ecd = 0;
1819 + scb_s->fac = 0;
1820 ++ scb_s->fpf = 0;
1821 +
1822 + rc = prepare_cpuflags(vcpu, vsie_page);
1823 + if (rc)
1824 +@@ -339,6 +346,9 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
1825 + prefix_unmapped(vsie_page);
1826 + scb_s->ecb |= ECB_TE;
1827 + }
1828 ++ /* branch prediction */
1829 ++ if (test_kvm_facility(vcpu->kvm, 82))
1830 ++ scb_s->fpf |= scb_o->fpf & FPF_BPBC;
1831 + /* SIMD */
1832 + if (test_kvm_facility(vcpu->kvm, 129)) {
1833 + scb_s->eca |= scb_o->eca & ECA_VX;
1834 +@@ -821,6 +831,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
1835 + {
1836 + struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
1837 + struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
1838 ++ int guest_bp_isolation;
1839 + int rc;
1840 +
1841 + handle_last_fault(vcpu, vsie_page);
1842 +@@ -831,6 +842,20 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
1843 + s390_handle_mcck();
1844 +
1845 + srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
1846 ++
1847 ++ /* save current guest state of bp isolation override */
1848 ++ guest_bp_isolation = test_thread_flag(TIF_ISOLATE_BP_GUEST);
1849 ++
1850 ++ /*
1851 ++ * The guest is running with BPBC, so we have to force it on for our
1852 ++ * nested guest. This is done by enabling BPBC globally, so the BPBC
1853 ++ * control in the SCB (which the nested guest can modify) is simply
1854 ++ * ignored.
1855 ++ */
1856 ++ if (test_kvm_facility(vcpu->kvm, 82) &&
1857 ++ vcpu->arch.sie_block->fpf & FPF_BPBC)
1858 ++ set_thread_flag(TIF_ISOLATE_BP_GUEST);
1859 ++
1860 + local_irq_disable();
1861 + guest_enter_irqoff();
1862 + local_irq_enable();
1863 +@@ -840,6 +865,11 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
1864 + local_irq_disable();
1865 + guest_exit_irqoff();
1866 + local_irq_enable();
1867 ++
1868 ++ /* restore guest state for bp isolation override */
1869 ++ if (!guest_bp_isolation)
1870 ++ clear_thread_flag(TIF_ISOLATE_BP_GUEST);
1871 ++
1872 + vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
1873 +
1874 + if (rc == -EINTR) {
1875 +diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
1876 +index f53ccc680238..dbdd460a9958 100644
1877 +--- a/drivers/acpi/acpi_video.c
1878 ++++ b/drivers/acpi/acpi_video.c
1879 +@@ -2123,6 +2123,25 @@ static int __init intel_opregion_present(void)
1880 + return opregion;
1881 + }
1882 +
1883 ++static bool dmi_is_desktop(void)
1884 ++{
1885 ++ const char *chassis_type;
1886 ++
1887 ++ chassis_type = dmi_get_system_info(DMI_CHASSIS_TYPE);
1888 ++ if (!chassis_type)
1889 ++ return false;
1890 ++
1891 ++ if (!strcmp(chassis_type, "3") || /* 3: Desktop */
1892 ++ !strcmp(chassis_type, "4") || /* 4: Low Profile Desktop */
1893 ++ !strcmp(chassis_type, "5") || /* 5: Pizza Box */
1894 ++ !strcmp(chassis_type, "6") || /* 6: Mini Tower */
1895 ++ !strcmp(chassis_type, "7") || /* 7: Tower */
1896 ++ !strcmp(chassis_type, "11")) /* 11: Main Server Chassis */
1897 ++ return true;
1898 ++
1899 ++ return false;
1900 ++}
1901 ++
1902 + int acpi_video_register(void)
1903 + {
1904 + int ret = 0;
1905 +@@ -2143,8 +2162,12 @@ int acpi_video_register(void)
1906 + * win8 ready (where we also prefer the native backlight driver, so
1907 + * normally the acpi_video code should not register there anyways).
1908 + */
1909 +- if (only_lcd == -1)
1910 +- only_lcd = acpi_osi_is_win8();
1911 ++ if (only_lcd == -1) {
1912 ++ if (dmi_is_desktop() && acpi_osi_is_win8())
1913 ++ only_lcd = true;
1914 ++ else
1915 ++ only_lcd = false;
1916 ++ }
1917 +
1918 + dmi_check_system(video_dmi_table);
1919 +
1920 +diff --git a/drivers/block/swim.c b/drivers/block/swim.c
1921 +index 84434d3ea19b..e88d50f75a4a 100644
1922 +--- a/drivers/block/swim.c
1923 ++++ b/drivers/block/swim.c
1924 +@@ -110,7 +110,7 @@ struct iwm {
1925 + /* Select values for swim_select and swim_readbit */
1926 +
1927 + #define READ_DATA_0 0x074
1928 +-#define TWOMEG_DRIVE 0x075
1929 ++#define ONEMEG_DRIVE 0x075
1930 + #define SINGLE_SIDED 0x076
1931 + #define DRIVE_PRESENT 0x077
1932 + #define DISK_IN 0x170
1933 +@@ -118,9 +118,9 @@ struct iwm {
1934 + #define TRACK_ZERO 0x172
1935 + #define TACHO 0x173
1936 + #define READ_DATA_1 0x174
1937 +-#define MFM_MODE 0x175
1938 ++#define GCR_MODE 0x175
1939 + #define SEEK_COMPLETE 0x176
1940 +-#define ONEMEG_MEDIA 0x177
1941 ++#define TWOMEG_MEDIA 0x177
1942 +
1943 + /* Bits in handshake register */
1944 +
1945 +@@ -612,7 +612,6 @@ static void setup_medium(struct floppy_state *fs)
1946 + struct floppy_struct *g;
1947 + fs->disk_in = 1;
1948 + fs->write_protected = swim_readbit(base, WRITE_PROT);
1949 +- fs->type = swim_readbit(base, ONEMEG_MEDIA);
1950 +
1951 + if (swim_track00(base))
1952 + printk(KERN_ERR
1953 +@@ -620,6 +619,9 @@ static void setup_medium(struct floppy_state *fs)
1954 +
1955 + swim_track00(base);
1956 +
1957 ++ fs->type = swim_readbit(base, TWOMEG_MEDIA) ?
1958 ++ HD_MEDIA : DD_MEDIA;
1959 ++ fs->head_number = swim_readbit(base, SINGLE_SIDED) ? 1 : 2;
1960 + get_floppy_geometry(fs, 0, &g);
1961 + fs->total_secs = g->size;
1962 + fs->secpercyl = g->head * g->sect;
1963 +@@ -646,7 +648,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1964 +
1965 + swim_write(base, setup, S_IBM_DRIVE | S_FCLK_DIV2);
1966 + udelay(10);
1967 +- swim_drive(base, INTERNAL_DRIVE);
1968 ++ swim_drive(base, fs->location);
1969 + swim_motor(base, ON);
1970 + swim_action(base, SETMFM);
1971 + if (fs->ejected)
1972 +@@ -656,6 +658,8 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1973 + goto out;
1974 + }
1975 +
1976 ++ set_capacity(fs->disk, fs->total_secs);
1977 ++
1978 + if (mode & FMODE_NDELAY)
1979 + return 0;
1980 +
1981 +@@ -727,14 +731,9 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
1982 + if (copy_to_user((void __user *) param, (void *) &floppy_type,
1983 + sizeof(struct floppy_struct)))
1984 + return -EFAULT;
1985 +- break;
1986 +-
1987 +- default:
1988 +- printk(KERN_DEBUG "SWIM floppy_ioctl: unknown cmd %d\n",
1989 +- cmd);
1990 +- return -ENOSYS;
1991 ++ return 0;
1992 + }
1993 +- return 0;
1994 ++ return -ENOTTY;
1995 + }
1996 +
1997 + static int floppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1998 +@@ -795,7 +794,7 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data)
1999 + struct swim_priv *swd = data;
2000 + int drive = (*part & 3);
2001 +
2002 +- if (drive > swd->floppy_count)
2003 ++ if (drive >= swd->floppy_count)
2004 + return NULL;
2005 +
2006 + *part = 0;
2007 +@@ -813,10 +812,9 @@ static int swim_add_floppy(struct swim_priv *swd, enum drive_location location)
2008 +
2009 + swim_motor(base, OFF);
2010 +
2011 +- if (swim_readbit(base, SINGLE_SIDED))
2012 +- fs->head_number = 1;
2013 +- else
2014 +- fs->head_number = 2;
2015 ++ fs->type = HD_MEDIA;
2016 ++ fs->head_number = 2;
2017 ++
2018 + fs->ref_count = 0;
2019 + fs->ejected = 1;
2020 +
2021 +@@ -834,10 +832,12 @@ static int swim_floppy_init(struct swim_priv *swd)
2022 + /* scan floppy drives */
2023 +
2024 + swim_drive(base, INTERNAL_DRIVE);
2025 +- if (swim_readbit(base, DRIVE_PRESENT))
2026 ++ if (swim_readbit(base, DRIVE_PRESENT) &&
2027 ++ !swim_readbit(base, ONEMEG_DRIVE))
2028 + swim_add_floppy(swd, INTERNAL_DRIVE);
2029 + swim_drive(base, EXTERNAL_DRIVE);
2030 +- if (swim_readbit(base, DRIVE_PRESENT))
2031 ++ if (swim_readbit(base, DRIVE_PRESENT) &&
2032 ++ !swim_readbit(base, ONEMEG_DRIVE))
2033 + swim_add_floppy(swd, EXTERNAL_DRIVE);
2034 +
2035 + /* register floppy drives */
2036 +@@ -861,7 +861,6 @@ static int swim_floppy_init(struct swim_priv *swd)
2037 + &swd->lock);
2038 + if (!swd->unit[drive].disk->queue) {
2039 + err = -ENOMEM;
2040 +- put_disk(swd->unit[drive].disk);
2041 + goto exit_put_disks;
2042 + }
2043 + blk_queue_bounce_limit(swd->unit[drive].disk->queue,
2044 +@@ -911,7 +910,7 @@ static int swim_probe(struct platform_device *dev)
2045 + goto out;
2046 + }
2047 +
2048 +- swim_base = ioremap(res->start, resource_size(res));
2049 ++ swim_base = (struct swim __iomem *)res->start;
2050 + if (!swim_base) {
2051 + ret = -ENOMEM;
2052 + goto out_release_io;
2053 +@@ -923,7 +922,7 @@ static int swim_probe(struct platform_device *dev)
2054 + if (!get_swim_mode(swim_base)) {
2055 + printk(KERN_INFO "SWIM device not found !\n");
2056 + ret = -ENODEV;
2057 +- goto out_iounmap;
2058 ++ goto out_release_io;
2059 + }
2060 +
2061 + /* set platform driver data */
2062 +@@ -931,7 +930,7 @@ static int swim_probe(struct platform_device *dev)
2063 + swd = kzalloc(sizeof(struct swim_priv), GFP_KERNEL);
2064 + if (!swd) {
2065 + ret = -ENOMEM;
2066 +- goto out_iounmap;
2067 ++ goto out_release_io;
2068 + }
2069 + platform_set_drvdata(dev, swd);
2070 +
2071 +@@ -945,8 +944,6 @@ static int swim_probe(struct platform_device *dev)
2072 +
2073 + out_kfree:
2074 + kfree(swd);
2075 +-out_iounmap:
2076 +- iounmap(swim_base);
2077 + out_release_io:
2078 + release_mem_region(res->start, resource_size(res));
2079 + out:
2080 +@@ -974,8 +971,6 @@ static int swim_remove(struct platform_device *dev)
2081 + for (drive = 0; drive < swd->floppy_count; drive++)
2082 + floppy_eject(&swd->unit[drive]);
2083 +
2084 +- iounmap(swd->base);
2085 +-
2086 + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
2087 + if (res)
2088 + release_mem_region(res->start, resource_size(res));
2089 +diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
2090 +index 9f931f8f6b4c..0d7527c6825a 100644
2091 +--- a/drivers/block/swim3.c
2092 ++++ b/drivers/block/swim3.c
2093 +@@ -148,7 +148,7 @@ struct swim3 {
2094 + #define MOTOR_ON 2
2095 + #define RELAX 3 /* also eject in progress */
2096 + #define READ_DATA_0 4
2097 +-#define TWOMEG_DRIVE 5
2098 ++#define ONEMEG_DRIVE 5
2099 + #define SINGLE_SIDED 6 /* drive or diskette is 4MB type? */
2100 + #define DRIVE_PRESENT 7
2101 + #define DISK_IN 8
2102 +@@ -156,9 +156,9 @@ struct swim3 {
2103 + #define TRACK_ZERO 10
2104 + #define TACHO 11
2105 + #define READ_DATA_1 12
2106 +-#define MFM_MODE 13
2107 ++#define GCR_MODE 13
2108 + #define SEEK_COMPLETE 14
2109 +-#define ONEMEG_MEDIA 15
2110 ++#define TWOMEG_MEDIA 15
2111 +
2112 + /* Definitions of values used in writing and formatting */
2113 + #define DATA_ESCAPE 0x99
2114 +diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
2115 +index e36d160c458f..5f7d86509f2f 100644
2116 +--- a/drivers/cdrom/cdrom.c
2117 ++++ b/drivers/cdrom/cdrom.c
2118 +@@ -2374,7 +2374,7 @@ static int cdrom_ioctl_media_changed(struct cdrom_device_info *cdi,
2119 + if (!CDROM_CAN(CDC_SELECT_DISC) || arg == CDSL_CURRENT)
2120 + return media_changed(cdi, 1);
2121 +
2122 +- if ((unsigned int)arg >= cdi->capacity)
2123 ++ if (arg >= cdi->capacity)
2124 + return -EINVAL;
2125 +
2126 + info = kmalloc(sizeof(*info), GFP_KERNEL);
2127 +diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
2128 +index 1d01a8f77db1..dba5259def60 100644
2129 +--- a/drivers/char/tpm/tpm-interface.c
2130 ++++ b/drivers/char/tpm/tpm-interface.c
2131 +@@ -369,20 +369,40 @@ static int tpm_validate_command(struct tpm_chip *chip,
2132 + return -EINVAL;
2133 + }
2134 +
2135 +-/**
2136 +- * tmp_transmit - Internal kernel interface to transmit TPM commands.
2137 +- *
2138 +- * @chip: TPM chip to use
2139 +- * @buf: TPM command buffer
2140 +- * @bufsiz: length of the TPM command buffer
2141 +- * @flags: tpm transmit flags - bitmap
2142 +- *
2143 +- * Return:
2144 +- * 0 when the operation is successful.
2145 +- * A negative number for system errors (errno).
2146 +- */
2147 +-ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
2148 +- u8 *buf, size_t bufsiz, unsigned int flags)
2149 ++static int tpm_request_locality(struct tpm_chip *chip)
2150 ++{
2151 ++ int rc;
2152 ++
2153 ++ if (!chip->ops->request_locality)
2154 ++ return 0;
2155 ++
2156 ++ rc = chip->ops->request_locality(chip, 0);
2157 ++ if (rc < 0)
2158 ++ return rc;
2159 ++
2160 ++ chip->locality = rc;
2161 ++
2162 ++ return 0;
2163 ++}
2164 ++
2165 ++static void tpm_relinquish_locality(struct tpm_chip *chip)
2166 ++{
2167 ++ int rc;
2168 ++
2169 ++ if (!chip->ops->relinquish_locality)
2170 ++ return;
2171 ++
2172 ++ rc = chip->ops->relinquish_locality(chip, chip->locality);
2173 ++ if (rc)
2174 ++ dev_err(&chip->dev, "%s: : error %d\n", __func__, rc);
2175 ++
2176 ++ chip->locality = -1;
2177 ++}
2178 ++
2179 ++static ssize_t tpm_try_transmit(struct tpm_chip *chip,
2180 ++ struct tpm_space *space,
2181 ++ u8 *buf, size_t bufsiz,
2182 ++ unsigned int flags)
2183 + {
2184 + struct tpm_output_header *header = (void *)buf;
2185 + int rc;
2186 +@@ -422,8 +442,6 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
2187 + if (!(flags & TPM_TRANSMIT_UNLOCKED))
2188 + mutex_lock(&chip->tpm_mutex);
2189 +
2190 +- if (chip->dev.parent)
2191 +- pm_runtime_get_sync(chip->dev.parent);
2192 +
2193 + if (chip->ops->clk_enable != NULL)
2194 + chip->ops->clk_enable(chip, true);
2195 +@@ -431,14 +449,15 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
2196 + /* Store the decision as chip->locality will be changed. */
2197 + need_locality = chip->locality == -1;
2198 +
2199 +- if (!(flags & TPM_TRANSMIT_RAW) &&
2200 +- need_locality && chip->ops->request_locality) {
2201 +- rc = chip->ops->request_locality(chip, 0);
2202 ++ if (!(flags & TPM_TRANSMIT_RAW) && need_locality) {
2203 ++ rc = tpm_request_locality(chip);
2204 + if (rc < 0)
2205 + goto out_no_locality;
2206 +- chip->locality = rc;
2207 + }
2208 +
2209 ++ if (chip->dev.parent)
2210 ++ pm_runtime_get_sync(chip->dev.parent);
2211 ++
2212 + rc = tpm2_prepare_space(chip, space, ordinal, buf);
2213 + if (rc)
2214 + goto out;
2215 +@@ -499,27 +518,83 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
2216 + rc = tpm2_commit_space(chip, space, ordinal, buf, &len);
2217 +
2218 + out:
2219 +- if (need_locality && chip->ops->relinquish_locality) {
2220 +- chip->ops->relinquish_locality(chip, chip->locality);
2221 +- chip->locality = -1;
2222 +- }
2223 ++ if (chip->dev.parent)
2224 ++ pm_runtime_put_sync(chip->dev.parent);
2225 ++
2226 ++ if (need_locality)
2227 ++ tpm_relinquish_locality(chip);
2228 ++
2229 + out_no_locality:
2230 + if (chip->ops->clk_enable != NULL)
2231 + chip->ops->clk_enable(chip, false);
2232 +
2233 +- if (chip->dev.parent)
2234 +- pm_runtime_put_sync(chip->dev.parent);
2235 +-
2236 + if (!(flags & TPM_TRANSMIT_UNLOCKED))
2237 + mutex_unlock(&chip->tpm_mutex);
2238 + return rc ? rc : len;
2239 + }
2240 +
2241 + /**
2242 +- * tmp_transmit_cmd - send a tpm command to the device
2243 ++ * tpm_transmit - Internal kernel interface to transmit TPM commands.
2244 ++ *
2245 ++ * @chip: TPM chip to use
2246 ++ * @space: tpm space
2247 ++ * @buf: TPM command buffer
2248 ++ * @bufsiz: length of the TPM command buffer
2249 ++ * @flags: tpm transmit flags - bitmap
2250 ++ *
2251 ++ * A wrapper around tpm_try_transmit that handles TPM2_RC_RETRY
2252 ++ * returns from the TPM and retransmits the command after a delay up
2253 ++ * to a maximum wait of TPM2_DURATION_LONG.
2254 ++ *
2255 ++ * Note: TPM1 never returns TPM2_RC_RETRY so the retry logic is TPM2
2256 ++ * only
2257 ++ *
2258 ++ * Return:
2259 ++ * the length of the return when the operation is successful.
2260 ++ * A negative number for system errors (errno).
2261 ++ */
2262 ++ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,
2263 ++ u8 *buf, size_t bufsiz, unsigned int flags)
2264 ++{
2265 ++ struct tpm_output_header *header = (struct tpm_output_header *)buf;
2266 ++ /* space for header and handles */
2267 ++ u8 save[TPM_HEADER_SIZE + 3*sizeof(u32)];
2268 ++ unsigned int delay_msec = TPM2_DURATION_SHORT;
2269 ++ u32 rc = 0;
2270 ++ ssize_t ret;
2271 ++ const size_t save_size = min(space ? sizeof(save) : TPM_HEADER_SIZE,
2272 ++ bufsiz);
2273 ++
2274 ++ /*
2275 ++ * Subtlety here: if we have a space, the handles will be
2276 ++ * transformed, so when we restore the header we also have to
2277 ++ * restore the handles.
2278 ++ */
2279 ++ memcpy(save, buf, save_size);
2280 ++
2281 ++ for (;;) {
2282 ++ ret = tpm_try_transmit(chip, space, buf, bufsiz, flags);
2283 ++ if (ret < 0)
2284 ++ break;
2285 ++ rc = be32_to_cpu(header->return_code);
2286 ++ if (rc != TPM2_RC_RETRY)
2287 ++ break;
2288 ++ delay_msec *= 2;
2289 ++ if (delay_msec > TPM2_DURATION_LONG) {
2290 ++ dev_err(&chip->dev, "TPM is in retry loop\n");
2291 ++ break;
2292 ++ }
2293 ++ tpm_msleep(delay_msec);
2294 ++ memcpy(buf, save, save_size);
2295 ++ }
2296 ++ return ret;
2297 ++}
2298 ++/**
2299 ++ * tpm_transmit_cmd - send a tpm command to the device
2300 + * The function extracts tpm out header return code
2301 + *
2302 + * @chip: TPM chip to use
2303 ++ * @space: tpm space
2304 + * @buf: TPM command buffer
2305 + * @bufsiz: length of the buffer
2306 + * @min_rsp_body_length: minimum expected length of response body
2307 +diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
2308 +index 0b5b499f726a..b83b30a3eea5 100644
2309 +--- a/drivers/char/tpm/tpm.h
2310 ++++ b/drivers/char/tpm/tpm.h
2311 +@@ -106,6 +106,7 @@ enum tpm2_return_codes {
2312 + TPM2_RC_COMMAND_CODE = 0x0143,
2313 + TPM2_RC_TESTING = 0x090A, /* RC_WARN */
2314 + TPM2_RC_REFERENCE_H0 = 0x0910,
2315 ++ TPM2_RC_RETRY = 0x0922,
2316 + };
2317 +
2318 + enum tpm2_algorithms {
2319 +diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
2320 +index 8f0a98dea327..bb756ad7897e 100644
2321 +--- a/drivers/char/tpm/tpm_crb.c
2322 ++++ b/drivers/char/tpm/tpm_crb.c
2323 +@@ -117,6 +117,25 @@ struct tpm2_crb_smc {
2324 + u32 smc_func_id;
2325 + };
2326 +
2327 ++static bool crb_wait_for_reg_32(u32 __iomem *reg, u32 mask, u32 value,
2328 ++ unsigned long timeout)
2329 ++{
2330 ++ ktime_t start;
2331 ++ ktime_t stop;
2332 ++
2333 ++ start = ktime_get();
2334 ++ stop = ktime_add(start, ms_to_ktime(timeout));
2335 ++
2336 ++ do {
2337 ++ if ((ioread32(reg) & mask) == value)
2338 ++ return true;
2339 ++
2340 ++ usleep_range(50, 100);
2341 ++ } while (ktime_before(ktime_get(), stop));
2342 ++
2343 ++ return ((ioread32(reg) & mask) == value);
2344 ++}
2345 ++
2346 + /**
2347 + * crb_go_idle - request tpm crb device to go the idle state
2348 + *
2349 +@@ -132,37 +151,24 @@ struct tpm2_crb_smc {
2350 + *
2351 + * Return: 0 always
2352 + */
2353 +-static int __maybe_unused crb_go_idle(struct device *dev, struct crb_priv *priv)
2354 ++static int crb_go_idle(struct device *dev, struct crb_priv *priv)
2355 + {
2356 + if ((priv->flags & CRB_FL_ACPI_START) ||
2357 + (priv->flags & CRB_FL_CRB_SMC_START))
2358 + return 0;
2359 +
2360 + iowrite32(CRB_CTRL_REQ_GO_IDLE, &priv->regs_t->ctrl_req);
2361 +- /* we don't really care when this settles */
2362 +
2363 ++ if (!crb_wait_for_reg_32(&priv->regs_t->ctrl_req,
2364 ++ CRB_CTRL_REQ_GO_IDLE/* mask */,
2365 ++ 0, /* value */
2366 ++ TPM2_TIMEOUT_C)) {
2367 ++ dev_warn(dev, "goIdle timed out\n");
2368 ++ return -ETIME;
2369 ++ }
2370 + return 0;
2371 + }
2372 +
2373 +-static bool crb_wait_for_reg_32(u32 __iomem *reg, u32 mask, u32 value,
2374 +- unsigned long timeout)
2375 +-{
2376 +- ktime_t start;
2377 +- ktime_t stop;
2378 +-
2379 +- start = ktime_get();
2380 +- stop = ktime_add(start, ms_to_ktime(timeout));
2381 +-
2382 +- do {
2383 +- if ((ioread32(reg) & mask) == value)
2384 +- return true;
2385 +-
2386 +- usleep_range(50, 100);
2387 +- } while (ktime_before(ktime_get(), stop));
2388 +-
2389 +- return false;
2390 +-}
2391 +-
2392 + /**
2393 + * crb_cmd_ready - request tpm crb device to enter ready state
2394 + *
2395 +@@ -177,8 +183,7 @@ static bool crb_wait_for_reg_32(u32 __iomem *reg, u32 mask, u32 value,
2396 + *
2397 + * Return: 0 on success -ETIME on timeout;
2398 + */
2399 +-static int __maybe_unused crb_cmd_ready(struct device *dev,
2400 +- struct crb_priv *priv)
2401 ++static int crb_cmd_ready(struct device *dev, struct crb_priv *priv)
2402 + {
2403 + if ((priv->flags & CRB_FL_ACPI_START) ||
2404 + (priv->flags & CRB_FL_CRB_SMC_START))
2405 +@@ -196,11 +201,11 @@ static int __maybe_unused crb_cmd_ready(struct device *dev,
2406 + return 0;
2407 + }
2408 +
2409 +-static int crb_request_locality(struct tpm_chip *chip, int loc)
2410 ++static int __crb_request_locality(struct device *dev,
2411 ++ struct crb_priv *priv, int loc)
2412 + {
2413 +- struct crb_priv *priv = dev_get_drvdata(&chip->dev);
2414 + u32 value = CRB_LOC_STATE_LOC_ASSIGNED |
2415 +- CRB_LOC_STATE_TPM_REG_VALID_STS;
2416 ++ CRB_LOC_STATE_TPM_REG_VALID_STS;
2417 +
2418 + if (!priv->regs_h)
2419 + return 0;
2420 +@@ -208,21 +213,45 @@ static int crb_request_locality(struct tpm_chip *chip, int loc)
2421 + iowrite32(CRB_LOC_CTRL_REQUEST_ACCESS, &priv->regs_h->loc_ctrl);
2422 + if (!crb_wait_for_reg_32(&priv->regs_h->loc_state, value, value,
2423 + TPM2_TIMEOUT_C)) {
2424 +- dev_warn(&chip->dev, "TPM_LOC_STATE_x.requestAccess timed out\n");
2425 ++ dev_warn(dev, "TPM_LOC_STATE_x.requestAccess timed out\n");
2426 + return -ETIME;
2427 + }
2428 +
2429 + return 0;
2430 + }
2431 +
2432 +-static void crb_relinquish_locality(struct tpm_chip *chip, int loc)
2433 ++static int crb_request_locality(struct tpm_chip *chip, int loc)
2434 + {
2435 + struct crb_priv *priv = dev_get_drvdata(&chip->dev);
2436 +
2437 ++ return __crb_request_locality(&chip->dev, priv, loc);
2438 ++}
2439 ++
2440 ++static int __crb_relinquish_locality(struct device *dev,
2441 ++ struct crb_priv *priv, int loc)
2442 ++{
2443 ++ u32 mask = CRB_LOC_STATE_LOC_ASSIGNED |
2444 ++ CRB_LOC_STATE_TPM_REG_VALID_STS;
2445 ++ u32 value = CRB_LOC_STATE_TPM_REG_VALID_STS;
2446 ++
2447 + if (!priv->regs_h)
2448 +- return;
2449 ++ return 0;
2450 +
2451 + iowrite32(CRB_LOC_CTRL_RELINQUISH, &priv->regs_h->loc_ctrl);
2452 ++ if (!crb_wait_for_reg_32(&priv->regs_h->loc_state, mask, value,
2453 ++ TPM2_TIMEOUT_C)) {
2454 ++ dev_warn(dev, "TPM_LOC_STATE_x.requestAccess timed out\n");
2455 ++ return -ETIME;
2456 ++ }
2457 ++
2458 ++ return 0;
2459 ++}
2460 ++
2461 ++static int crb_relinquish_locality(struct tpm_chip *chip, int loc)
2462 ++{
2463 ++ struct crb_priv *priv = dev_get_drvdata(&chip->dev);
2464 ++
2465 ++ return __crb_relinquish_locality(&chip->dev, priv, loc);
2466 + }
2467 +
2468 + static u8 crb_status(struct tpm_chip *chip)
2469 +@@ -466,6 +495,10 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
2470 + dev_warn(dev, FW_BUG "Bad ACPI memory layout");
2471 + }
2472 +
2473 ++ ret = __crb_request_locality(dev, priv, 0);
2474 ++ if (ret)
2475 ++ return ret;
2476 ++
2477 + priv->regs_t = crb_map_res(dev, priv, &io_res, buf->control_address,
2478 + sizeof(struct crb_regs_tail));
2479 + if (IS_ERR(priv->regs_t))
2480 +@@ -522,6 +555,8 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
2481 +
2482 + crb_go_idle(dev, priv);
2483 +
2484 ++ __crb_relinquish_locality(dev, priv, 0);
2485 ++
2486 + return ret;
2487 + }
2488 +
2489 +@@ -589,10 +624,14 @@ static int crb_acpi_add(struct acpi_device *device)
2490 + chip->acpi_dev_handle = device->handle;
2491 + chip->flags = TPM_CHIP_FLAG_TPM2;
2492 +
2493 +- rc = crb_cmd_ready(dev, priv);
2494 ++ rc = __crb_request_locality(dev, priv, 0);
2495 + if (rc)
2496 + return rc;
2497 +
2498 ++ rc = crb_cmd_ready(dev, priv);
2499 ++ if (rc)
2500 ++ goto out;
2501 ++
2502 + pm_runtime_get_noresume(dev);
2503 + pm_runtime_set_active(dev);
2504 + pm_runtime_enable(dev);
2505 +@@ -602,12 +641,15 @@ static int crb_acpi_add(struct acpi_device *device)
2506 + crb_go_idle(dev, priv);
2507 + pm_runtime_put_noidle(dev);
2508 + pm_runtime_disable(dev);
2509 +- return rc;
2510 ++ goto out;
2511 + }
2512 +
2513 +- pm_runtime_put(dev);
2514 ++ pm_runtime_put_sync(dev);
2515 +
2516 +- return 0;
2517 ++out:
2518 ++ __crb_relinquish_locality(dev, priv, 0);
2519 ++
2520 ++ return rc;
2521 + }
2522 +
2523 + static int crb_acpi_remove(struct acpi_device *device)
2524 +diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
2525 +index a21e31c2b952..58123df6b5f6 100644
2526 +--- a/drivers/char/tpm/tpm_tis_core.c
2527 ++++ b/drivers/char/tpm/tpm_tis_core.c
2528 +@@ -77,11 +77,13 @@ static bool check_locality(struct tpm_chip *chip, int l)
2529 + return false;
2530 + }
2531 +
2532 +-static void release_locality(struct tpm_chip *chip, int l)
2533 ++static int release_locality(struct tpm_chip *chip, int l)
2534 + {
2535 + struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
2536 +
2537 + tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY);
2538 ++
2539 ++ return 0;
2540 + }
2541 +
2542 + static int request_locality(struct tpm_chip *chip, int l)
2543 +diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
2544 +index bf14214fa464..4db31b89507c 100644
2545 +--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
2546 ++++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
2547 +@@ -1634,6 +1634,8 @@ static void dw_hdmi_clear_overflow(struct dw_hdmi *hdmi)
2548 + * (and possibly on the platform). So far only i.MX6Q (v1.30a) and
2549 + * i.MX6DL (v1.31a) have been identified as needing the workaround, with
2550 + * 4 and 1 iterations respectively.
2551 ++ * The Amlogic Meson GX SoCs (v2.01a) have been identified as needing
2552 ++ * the workaround with a single iteration.
2553 + */
2554 +
2555 + switch (hdmi->version) {
2556 +@@ -1641,6 +1643,7 @@ static void dw_hdmi_clear_overflow(struct dw_hdmi *hdmi)
2557 + count = 4;
2558 + break;
2559 + case 0x131a:
2560 ++ case 0x201a:
2561 + count = 1;
2562 + break;
2563 + default:
2564 +diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
2565 +index 345f6035599e..f1d93676b0fc 100644
2566 +--- a/drivers/message/fusion/mptsas.c
2567 ++++ b/drivers/message/fusion/mptsas.c
2568 +@@ -1995,6 +1995,7 @@ static struct scsi_host_template mptsas_driver_template = {
2569 + .cmd_per_lun = 7,
2570 + .use_clustering = ENABLE_CLUSTERING,
2571 + .shost_attrs = mptscsih_host_attrs,
2572 ++ .no_write_same = 1,
2573 + };
2574 +
2575 + static int mptsas_get_linkerrors(struct sas_phy *phy)
2576 +diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
2577 +index 82f28ffccddf..bf3be2e6d4a8 100644
2578 +--- a/drivers/net/bonding/bond_main.c
2579 ++++ b/drivers/net/bonding/bond_main.c
2580 +@@ -1656,8 +1656,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
2581 + } /* switch(bond_mode) */
2582 +
2583 + #ifdef CONFIG_NET_POLL_CONTROLLER
2584 +- slave_dev->npinfo = bond->dev->npinfo;
2585 +- if (slave_dev->npinfo) {
2586 ++ if (bond->dev->npinfo) {
2587 + if (slave_enable_netpoll(new_slave)) {
2588 + netdev_info(bond_dev, "master_dev is using netpoll, but new slave device does not support netpoll\n");
2589 + res = -EBUSY;
2590 +diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
2591 +index 7ea72ef11a55..d272dc6984ac 100644
2592 +--- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
2593 ++++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
2594 +@@ -1321,6 +1321,10 @@
2595 + #define MDIO_VEND2_AN_STAT 0x8002
2596 + #endif
2597 +
2598 ++#ifndef MDIO_VEND2_PMA_CDR_CONTROL
2599 ++#define MDIO_VEND2_PMA_CDR_CONTROL 0x8056
2600 ++#endif
2601 ++
2602 + #ifndef MDIO_CTRL1_SPEED1G
2603 + #define MDIO_CTRL1_SPEED1G (MDIO_CTRL1_SPEED10G & ~BMCR_SPEED100)
2604 + #endif
2605 +@@ -1369,6 +1373,10 @@
2606 + #define XGBE_AN_CL37_TX_CONFIG_MASK 0x08
2607 + #define XGBE_AN_CL37_MII_CTRL_8BIT 0x0100
2608 +
2609 ++#define XGBE_PMA_CDR_TRACK_EN_MASK 0x01
2610 ++#define XGBE_PMA_CDR_TRACK_EN_OFF 0x00
2611 ++#define XGBE_PMA_CDR_TRACK_EN_ON 0x01
2612 ++
2613 + /* Bit setting and getting macros
2614 + * The get macro will extract the current bit field value from within
2615 + * the variable
2616 +diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
2617 +index 7d128be61310..b91143947ed2 100644
2618 +--- a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
2619 ++++ b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
2620 +@@ -519,6 +519,22 @@ void xgbe_debugfs_init(struct xgbe_prv_data *pdata)
2621 + "debugfs_create_file failed\n");
2622 + }
2623 +
2624 ++ if (pdata->vdata->an_cdr_workaround) {
2625 ++ pfile = debugfs_create_bool("an_cdr_workaround", 0600,
2626 ++ pdata->xgbe_debugfs,
2627 ++ &pdata->debugfs_an_cdr_workaround);
2628 ++ if (!pfile)
2629 ++ netdev_err(pdata->netdev,
2630 ++ "debugfs_create_bool failed\n");
2631 ++
2632 ++ pfile = debugfs_create_bool("an_cdr_track_early", 0600,
2633 ++ pdata->xgbe_debugfs,
2634 ++ &pdata->debugfs_an_cdr_track_early);
2635 ++ if (!pfile)
2636 ++ netdev_err(pdata->netdev,
2637 ++ "debugfs_create_bool failed\n");
2638 ++ }
2639 ++
2640 + kfree(buf);
2641 + }
2642 +
2643 +diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
2644 +index d91fa595be98..e31d9d1fb6a6 100644
2645 +--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
2646 ++++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
2647 +@@ -349,6 +349,7 @@ int xgbe_config_netdev(struct xgbe_prv_data *pdata)
2648 + XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1);
2649 +
2650 + /* Call MDIO/PHY initialization routine */
2651 ++ pdata->debugfs_an_cdr_workaround = pdata->vdata->an_cdr_workaround;
2652 + ret = pdata->phy_if.phy_init(pdata);
2653 + if (ret)
2654 + return ret;
2655 +diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
2656 +index 072b9f664597..1b45cd73a258 100644
2657 +--- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
2658 ++++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
2659 +@@ -432,11 +432,16 @@ static void xgbe_an73_disable(struct xgbe_prv_data *pdata)
2660 + xgbe_an73_set(pdata, false, false);
2661 + xgbe_an73_disable_interrupts(pdata);
2662 +
2663 ++ pdata->an_start = 0;
2664 ++
2665 + netif_dbg(pdata, link, pdata->netdev, "CL73 AN disabled\n");
2666 + }
2667 +
2668 + static void xgbe_an_restart(struct xgbe_prv_data *pdata)
2669 + {
2670 ++ if (pdata->phy_if.phy_impl.an_pre)
2671 ++ pdata->phy_if.phy_impl.an_pre(pdata);
2672 ++
2673 + switch (pdata->an_mode) {
2674 + case XGBE_AN_MODE_CL73:
2675 + case XGBE_AN_MODE_CL73_REDRV:
2676 +@@ -453,6 +458,9 @@ static void xgbe_an_restart(struct xgbe_prv_data *pdata)
2677 +
2678 + static void xgbe_an_disable(struct xgbe_prv_data *pdata)
2679 + {
2680 ++ if (pdata->phy_if.phy_impl.an_post)
2681 ++ pdata->phy_if.phy_impl.an_post(pdata);
2682 ++
2683 + switch (pdata->an_mode) {
2684 + case XGBE_AN_MODE_CL73:
2685 + case XGBE_AN_MODE_CL73_REDRV:
2686 +@@ -505,11 +513,11 @@ static enum xgbe_an xgbe_an73_tx_training(struct xgbe_prv_data *pdata,
2687 + XMDIO_WRITE(pdata, MDIO_MMD_PMAPMD, MDIO_PMA_10GBR_PMD_CTRL,
2688 + reg);
2689 +
2690 +- if (pdata->phy_if.phy_impl.kr_training_post)
2691 +- pdata->phy_if.phy_impl.kr_training_post(pdata);
2692 +-
2693 + netif_dbg(pdata, link, pdata->netdev,
2694 + "KR training initiated\n");
2695 ++
2696 ++ if (pdata->phy_if.phy_impl.kr_training_post)
2697 ++ pdata->phy_if.phy_impl.kr_training_post(pdata);
2698 + }
2699 +
2700 + return XGBE_AN_PAGE_RECEIVED;
2701 +@@ -637,11 +645,11 @@ static enum xgbe_an xgbe_an73_incompat_link(struct xgbe_prv_data *pdata)
2702 + return XGBE_AN_NO_LINK;
2703 + }
2704 +
2705 +- xgbe_an73_disable(pdata);
2706 ++ xgbe_an_disable(pdata);
2707 +
2708 + xgbe_switch_mode(pdata);
2709 +
2710 +- xgbe_an73_restart(pdata);
2711 ++ xgbe_an_restart(pdata);
2712 +
2713 + return XGBE_AN_INCOMPAT_LINK;
2714 + }
2715 +@@ -820,6 +828,9 @@ static void xgbe_an37_state_machine(struct xgbe_prv_data *pdata)
2716 + pdata->an_result = pdata->an_state;
2717 + pdata->an_state = XGBE_AN_READY;
2718 +
2719 ++ if (pdata->phy_if.phy_impl.an_post)
2720 ++ pdata->phy_if.phy_impl.an_post(pdata);
2721 ++
2722 + netif_dbg(pdata, link, pdata->netdev, "CL37 AN result: %s\n",
2723 + xgbe_state_as_string(pdata->an_result));
2724 + }
2725 +@@ -903,6 +914,9 @@ static void xgbe_an73_state_machine(struct xgbe_prv_data *pdata)
2726 + pdata->kx_state = XGBE_RX_BPA;
2727 + pdata->an_start = 0;
2728 +
2729 ++ if (pdata->phy_if.phy_impl.an_post)
2730 ++ pdata->phy_if.phy_impl.an_post(pdata);
2731 ++
2732 + netif_dbg(pdata, link, pdata->netdev, "CL73 AN result: %s\n",
2733 + xgbe_state_as_string(pdata->an_result));
2734 + }
2735 +diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c
2736 +index eb23f9ba1a9a..82d1f416ee2a 100644
2737 +--- a/drivers/net/ethernet/amd/xgbe/xgbe-pci.c
2738 ++++ b/drivers/net/ethernet/amd/xgbe/xgbe-pci.c
2739 +@@ -456,6 +456,7 @@ static const struct xgbe_version_data xgbe_v2a = {
2740 + .irq_reissue_support = 1,
2741 + .tx_desc_prefetch = 5,
2742 + .rx_desc_prefetch = 5,
2743 ++ .an_cdr_workaround = 1,
2744 + };
2745 +
2746 + static const struct xgbe_version_data xgbe_v2b = {
2747 +@@ -470,6 +471,7 @@ static const struct xgbe_version_data xgbe_v2b = {
2748 + .irq_reissue_support = 1,
2749 + .tx_desc_prefetch = 5,
2750 + .rx_desc_prefetch = 5,
2751 ++ .an_cdr_workaround = 1,
2752 + };
2753 +
2754 + static const struct pci_device_id xgbe_pci_table[] = {
2755 +diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
2756 +index 3304a291aa96..aac884314000 100644
2757 +--- a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
2758 ++++ b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
2759 +@@ -147,6 +147,14 @@
2760 + /* Rate-change complete wait/retry count */
2761 + #define XGBE_RATECHANGE_COUNT 500
2762 +
2763 ++/* CDR delay values for KR support (in usec) */
2764 ++#define XGBE_CDR_DELAY_INIT 10000
2765 ++#define XGBE_CDR_DELAY_INC 10000
2766 ++#define XGBE_CDR_DELAY_MAX 100000
2767 ++
2768 ++/* RRC frequency during link status check */
2769 ++#define XGBE_RRC_FREQUENCY 10
2770 ++
2771 + enum xgbe_port_mode {
2772 + XGBE_PORT_MODE_RSVD = 0,
2773 + XGBE_PORT_MODE_BACKPLANE,
2774 +@@ -245,6 +253,10 @@ enum xgbe_sfp_speed {
2775 + #define XGBE_SFP_BASE_VENDOR_SN 4
2776 + #define XGBE_SFP_BASE_VENDOR_SN_LEN 16
2777 +
2778 ++#define XGBE_SFP_EXTD_OPT1 1
2779 ++#define XGBE_SFP_EXTD_OPT1_RX_LOS BIT(1)
2780 ++#define XGBE_SFP_EXTD_OPT1_TX_FAULT BIT(3)
2781 ++
2782 + #define XGBE_SFP_EXTD_DIAG 28
2783 + #define XGBE_SFP_EXTD_DIAG_ADDR_CHANGE BIT(2)
2784 +
2785 +@@ -324,6 +336,7 @@ struct xgbe_phy_data {
2786 +
2787 + unsigned int sfp_gpio_address;
2788 + unsigned int sfp_gpio_mask;
2789 ++ unsigned int sfp_gpio_inputs;
2790 + unsigned int sfp_gpio_rx_los;
2791 + unsigned int sfp_gpio_tx_fault;
2792 + unsigned int sfp_gpio_mod_absent;
2793 +@@ -355,6 +368,10 @@ struct xgbe_phy_data {
2794 + unsigned int redrv_addr;
2795 + unsigned int redrv_lane;
2796 + unsigned int redrv_model;
2797 ++
2798 ++ /* KR AN support */
2799 ++ unsigned int phy_cdr_notrack;
2800 ++ unsigned int phy_cdr_delay;
2801 + };
2802 +
2803 + /* I2C, MDIO and GPIO lines are muxed, so only one device at a time */
2804 +@@ -974,6 +991,49 @@ static void xgbe_phy_sfp_external_phy(struct xgbe_prv_data *pdata)
2805 + phy_data->sfp_phy_avail = 1;
2806 + }
2807 +
2808 ++static bool xgbe_phy_check_sfp_rx_los(struct xgbe_phy_data *phy_data)
2809 ++{
2810 ++ u8 *sfp_extd = phy_data->sfp_eeprom.extd;
2811 ++
2812 ++ if (!(sfp_extd[XGBE_SFP_EXTD_OPT1] & XGBE_SFP_EXTD_OPT1_RX_LOS))
2813 ++ return false;
2814 ++
2815 ++ if (phy_data->sfp_gpio_mask & XGBE_GPIO_NO_RX_LOS)
2816 ++ return false;
2817 ++
2818 ++ if (phy_data->sfp_gpio_inputs & (1 << phy_data->sfp_gpio_rx_los))
2819 ++ return true;
2820 ++
2821 ++ return false;
2822 ++}
2823 ++
2824 ++static bool xgbe_phy_check_sfp_tx_fault(struct xgbe_phy_data *phy_data)
2825 ++{
2826 ++ u8 *sfp_extd = phy_data->sfp_eeprom.extd;
2827 ++
2828 ++ if (!(sfp_extd[XGBE_SFP_EXTD_OPT1] & XGBE_SFP_EXTD_OPT1_TX_FAULT))
2829 ++ return false;
2830 ++
2831 ++ if (phy_data->sfp_gpio_mask & XGBE_GPIO_NO_TX_FAULT)
2832 ++ return false;
2833 ++
2834 ++ if (phy_data->sfp_gpio_inputs & (1 << phy_data->sfp_gpio_tx_fault))
2835 ++ return true;
2836 ++
2837 ++ return false;
2838 ++}
2839 ++
2840 ++static bool xgbe_phy_check_sfp_mod_absent(struct xgbe_phy_data *phy_data)
2841 ++{
2842 ++ if (phy_data->sfp_gpio_mask & XGBE_GPIO_NO_MOD_ABSENT)
2843 ++ return false;
2844 ++
2845 ++ if (phy_data->sfp_gpio_inputs & (1 << phy_data->sfp_gpio_mod_absent))
2846 ++ return true;
2847 ++
2848 ++ return false;
2849 ++}
2850 ++
2851 + static bool xgbe_phy_belfuse_parse_quirks(struct xgbe_prv_data *pdata)
2852 + {
2853 + struct xgbe_phy_data *phy_data = pdata->phy_data;
2854 +@@ -1019,6 +1079,10 @@ static void xgbe_phy_sfp_parse_eeprom(struct xgbe_prv_data *pdata)
2855 + if (sfp_base[XGBE_SFP_BASE_EXT_ID] != XGBE_SFP_EXT_ID_SFP)
2856 + return;
2857 +
2858 ++ /* Update transceiver signals (eeprom extd/options) */
2859 ++ phy_data->sfp_tx_fault = xgbe_phy_check_sfp_tx_fault(phy_data);
2860 ++ phy_data->sfp_rx_los = xgbe_phy_check_sfp_rx_los(phy_data);
2861 ++
2862 + if (xgbe_phy_sfp_parse_quirks(pdata))
2863 + return;
2864 +
2865 +@@ -1184,7 +1248,6 @@ static int xgbe_phy_sfp_read_eeprom(struct xgbe_prv_data *pdata)
2866 + static void xgbe_phy_sfp_signals(struct xgbe_prv_data *pdata)
2867 + {
2868 + struct xgbe_phy_data *phy_data = pdata->phy_data;
2869 +- unsigned int gpio_input;
2870 + u8 gpio_reg, gpio_ports[2];
2871 + int ret;
2872 +
2873 +@@ -1199,23 +1262,9 @@ static void xgbe_phy_sfp_signals(struct xgbe_prv_data *pdata)
2874 + return;
2875 + }
2876 +
2877 +- gpio_input = (gpio_ports[1] << 8) | gpio_ports[0];
2878 +-
2879 +- if (phy_data->sfp_gpio_mask & XGBE_GPIO_NO_MOD_ABSENT) {
2880 +- /* No GPIO, just assume the module is present for now */
2881 +- phy_data->sfp_mod_absent = 0;
2882 +- } else {
2883 +- if (!(gpio_input & (1 << phy_data->sfp_gpio_mod_absent)))
2884 +- phy_data->sfp_mod_absent = 0;
2885 +- }
2886 +-
2887 +- if (!(phy_data->sfp_gpio_mask & XGBE_GPIO_NO_RX_LOS) &&
2888 +- (gpio_input & (1 << phy_data->sfp_gpio_rx_los)))
2889 +- phy_data->sfp_rx_los = 1;
2890 ++ phy_data->sfp_gpio_inputs = (gpio_ports[1] << 8) | gpio_ports[0];
2891 +
2892 +- if (!(phy_data->sfp_gpio_mask & XGBE_GPIO_NO_TX_FAULT) &&
2893 +- (gpio_input & (1 << phy_data->sfp_gpio_tx_fault)))
2894 +- phy_data->sfp_tx_fault = 1;
2895 ++ phy_data->sfp_mod_absent = xgbe_phy_check_sfp_mod_absent(phy_data);
2896 + }
2897 +
2898 + static void xgbe_phy_sfp_mod_absent(struct xgbe_prv_data *pdata)
2899 +@@ -2361,7 +2410,7 @@ static int xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart)
2900 + return 1;
2901 +
2902 + /* No link, attempt a receiver reset cycle */
2903 +- if (phy_data->rrc_count++) {
2904 ++ if (phy_data->rrc_count++ > XGBE_RRC_FREQUENCY) {
2905 + phy_data->rrc_count = 0;
2906 + xgbe_phy_rrc(pdata);
2907 + }
2908 +@@ -2669,6 +2718,103 @@ static bool xgbe_phy_port_enabled(struct xgbe_prv_data *pdata)
2909 + return true;
2910 + }
2911 +
2912 ++static void xgbe_phy_cdr_track(struct xgbe_prv_data *pdata)
2913 ++{
2914 ++ struct xgbe_phy_data *phy_data = pdata->phy_data;
2915 ++
2916 ++ if (!pdata->debugfs_an_cdr_workaround)
2917 ++ return;
2918 ++
2919 ++ if (!phy_data->phy_cdr_notrack)
2920 ++ return;
2921 ++
2922 ++ usleep_range(phy_data->phy_cdr_delay,
2923 ++ phy_data->phy_cdr_delay + 500);
2924 ++
2925 ++ XMDIO_WRITE_BITS(pdata, MDIO_MMD_PMAPMD, MDIO_VEND2_PMA_CDR_CONTROL,
2926 ++ XGBE_PMA_CDR_TRACK_EN_MASK,
2927 ++ XGBE_PMA_CDR_TRACK_EN_ON);
2928 ++
2929 ++ phy_data->phy_cdr_notrack = 0;
2930 ++}
2931 ++
2932 ++static void xgbe_phy_cdr_notrack(struct xgbe_prv_data *pdata)
2933 ++{
2934 ++ struct xgbe_phy_data *phy_data = pdata->phy_data;
2935 ++
2936 ++ if (!pdata->debugfs_an_cdr_workaround)
2937 ++ return;
2938 ++
2939 ++ if (phy_data->phy_cdr_notrack)
2940 ++ return;
2941 ++
2942 ++ XMDIO_WRITE_BITS(pdata, MDIO_MMD_PMAPMD, MDIO_VEND2_PMA_CDR_CONTROL,
2943 ++ XGBE_PMA_CDR_TRACK_EN_MASK,
2944 ++ XGBE_PMA_CDR_TRACK_EN_OFF);
2945 ++
2946 ++ xgbe_phy_rrc(pdata);
2947 ++
2948 ++ phy_data->phy_cdr_notrack = 1;
2949 ++}
2950 ++
2951 ++static void xgbe_phy_kr_training_post(struct xgbe_prv_data *pdata)
2952 ++{
2953 ++ if (!pdata->debugfs_an_cdr_track_early)
2954 ++ xgbe_phy_cdr_track(pdata);
2955 ++}
2956 ++
2957 ++static void xgbe_phy_kr_training_pre(struct xgbe_prv_data *pdata)
2958 ++{
2959 ++ if (pdata->debugfs_an_cdr_track_early)
2960 ++ xgbe_phy_cdr_track(pdata);
2961 ++}
2962 ++
2963 ++static void xgbe_phy_an_post(struct xgbe_prv_data *pdata)
2964 ++{
2965 ++ struct xgbe_phy_data *phy_data = pdata->phy_data;
2966 ++
2967 ++ switch (pdata->an_mode) {
2968 ++ case XGBE_AN_MODE_CL73:
2969 ++ case XGBE_AN_MODE_CL73_REDRV:
2970 ++ if (phy_data->cur_mode != XGBE_MODE_KR)
2971 ++ break;
2972 ++
2973 ++ xgbe_phy_cdr_track(pdata);
2974 ++
2975 ++ switch (pdata->an_result) {
2976 ++ case XGBE_AN_READY:
2977 ++ case XGBE_AN_COMPLETE:
2978 ++ break;
2979 ++ default:
2980 ++ if (phy_data->phy_cdr_delay < XGBE_CDR_DELAY_MAX)
2981 ++ phy_data->phy_cdr_delay += XGBE_CDR_DELAY_INC;
2982 ++ else
2983 ++ phy_data->phy_cdr_delay = XGBE_CDR_DELAY_INIT;
2984 ++ break;
2985 ++ }
2986 ++ break;
2987 ++ default:
2988 ++ break;
2989 ++ }
2990 ++}
2991 ++
2992 ++static void xgbe_phy_an_pre(struct xgbe_prv_data *pdata)
2993 ++{
2994 ++ struct xgbe_phy_data *phy_data = pdata->phy_data;
2995 ++
2996 ++ switch (pdata->an_mode) {
2997 ++ case XGBE_AN_MODE_CL73:
2998 ++ case XGBE_AN_MODE_CL73_REDRV:
2999 ++ if (phy_data->cur_mode != XGBE_MODE_KR)
3000 ++ break;
3001 ++
3002 ++ xgbe_phy_cdr_notrack(pdata);
3003 ++ break;
3004 ++ default:
3005 ++ break;
3006 ++ }
3007 ++}
3008 ++
3009 + static void xgbe_phy_stop(struct xgbe_prv_data *pdata)
3010 + {
3011 + struct xgbe_phy_data *phy_data = pdata->phy_data;
3012 +@@ -2680,6 +2826,9 @@ static void xgbe_phy_stop(struct xgbe_prv_data *pdata)
3013 + xgbe_phy_sfp_reset(phy_data);
3014 + xgbe_phy_sfp_mod_absent(pdata);
3015 +
3016 ++ /* Reset CDR support */
3017 ++ xgbe_phy_cdr_track(pdata);
3018 ++
3019 + /* Power off the PHY */
3020 + xgbe_phy_power_off(pdata);
3021 +
3022 +@@ -2712,6 +2861,9 @@ static int xgbe_phy_start(struct xgbe_prv_data *pdata)
3023 + /* Start in highest supported mode */
3024 + xgbe_phy_set_mode(pdata, phy_data->start_mode);
3025 +
3026 ++ /* Reset CDR support */
3027 ++ xgbe_phy_cdr_track(pdata);
3028 ++
3029 + /* After starting the I2C controller, we can check for an SFP */
3030 + switch (phy_data->port_mode) {
3031 + case XGBE_PORT_MODE_SFP:
3032 +@@ -3019,6 +3171,8 @@ static int xgbe_phy_init(struct xgbe_prv_data *pdata)
3033 + }
3034 + }
3035 +
3036 ++ phy_data->phy_cdr_delay = XGBE_CDR_DELAY_INIT;
3037 ++
3038 + /* Register for driving external PHYs */
3039 + mii = devm_mdiobus_alloc(pdata->dev);
3040 + if (!mii) {
3041 +@@ -3071,4 +3225,10 @@ void xgbe_init_function_ptrs_phy_v2(struct xgbe_phy_if *phy_if)
3042 + phy_impl->an_advertising = xgbe_phy_an_advertising;
3043 +
3044 + phy_impl->an_outcome = xgbe_phy_an_outcome;
3045 ++
3046 ++ phy_impl->an_pre = xgbe_phy_an_pre;
3047 ++ phy_impl->an_post = xgbe_phy_an_post;
3048 ++
3049 ++ phy_impl->kr_training_pre = xgbe_phy_kr_training_pre;
3050 ++ phy_impl->kr_training_post = xgbe_phy_kr_training_post;
3051 + }
3052 +diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
3053 +index ad102c8bac7b..95d4b56448c6 100644
3054 +--- a/drivers/net/ethernet/amd/xgbe/xgbe.h
3055 ++++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
3056 +@@ -833,6 +833,7 @@ struct xgbe_hw_if {
3057 + /* This structure represents implementation specific routines for an
3058 + * implementation of a PHY. All routines are required unless noted below.
3059 + * Optional routines:
3060 ++ * an_pre, an_post
3061 + * kr_training_pre, kr_training_post
3062 + */
3063 + struct xgbe_phy_impl_if {
3064 +@@ -875,6 +876,10 @@ struct xgbe_phy_impl_if {
3065 + /* Process results of auto-negotiation */
3066 + enum xgbe_mode (*an_outcome)(struct xgbe_prv_data *);
3067 +
3068 ++ /* Pre/Post auto-negotiation support */
3069 ++ void (*an_pre)(struct xgbe_prv_data *);
3070 ++ void (*an_post)(struct xgbe_prv_data *);
3071 ++
3072 + /* Pre/Post KR training enablement support */
3073 + void (*kr_training_pre)(struct xgbe_prv_data *);
3074 + void (*kr_training_post)(struct xgbe_prv_data *);
3075 +@@ -989,6 +994,7 @@ struct xgbe_version_data {
3076 + unsigned int irq_reissue_support;
3077 + unsigned int tx_desc_prefetch;
3078 + unsigned int rx_desc_prefetch;
3079 ++ unsigned int an_cdr_workaround;
3080 + };
3081 +
3082 + struct xgbe_vxlan_data {
3083 +@@ -1257,6 +1263,9 @@ struct xgbe_prv_data {
3084 + unsigned int debugfs_xprop_reg;
3085 +
3086 + unsigned int debugfs_xi2c_reg;
3087 ++
3088 ++ bool debugfs_an_cdr_workaround;
3089 ++ bool debugfs_an_cdr_track_early;
3090 + };
3091 +
3092 + /* Function prototypes*/
3093 +diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
3094 +index e368b0237a1b..4a85a24ced1c 100644
3095 +--- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
3096 ++++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
3097 +@@ -2781,6 +2781,7 @@ int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
3098 + int ret = 0;
3099 + struct hlist_node *h;
3100 + int bkt;
3101 ++ u8 i;
3102 +
3103 + /* validate the request */
3104 + if (vf_id >= pf->num_alloc_vfs) {
3105 +@@ -2792,6 +2793,16 @@ int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
3106 +
3107 + vf = &(pf->vf[vf_id]);
3108 + vsi = pf->vsi[vf->lan_vsi_idx];
3109 ++
3110 ++ /* When the VF is resetting wait until it is done.
3111 ++ * It can take up to 200 milliseconds,
3112 ++ * but wait for up to 300 milliseconds to be safe.
3113 ++ */
3114 ++ for (i = 0; i < 15; i++) {
3115 ++ if (test_bit(I40E_VF_STATE_INIT, &vf->vf_states))
3116 ++ break;
3117 ++ msleep(20);
3118 ++ }
3119 + if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
3120 + dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
3121 + vf_id);
3122 +diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
3123 +index a5bb7b19040e..992c43b1868f 100644
3124 +--- a/drivers/net/ethernet/ti/cpsw.c
3125 ++++ b/drivers/net/ethernet/ti/cpsw.c
3126 +@@ -124,7 +124,7 @@ do { \
3127 +
3128 + #define RX_PRIORITY_MAPPING 0x76543210
3129 + #define TX_PRIORITY_MAPPING 0x33221100
3130 +-#define CPDMA_TX_PRIORITY_MAP 0x01234567
3131 ++#define CPDMA_TX_PRIORITY_MAP 0x76543210
3132 +
3133 + #define CPSW_VLAN_AWARE BIT(1)
3134 + #define CPSW_ALE_VLAN_AWARE 1
3135 +diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
3136 +index 5aa59f41bf8c..71e2aef6b7a1 100644
3137 +--- a/drivers/net/ppp/pppoe.c
3138 ++++ b/drivers/net/ppp/pppoe.c
3139 +@@ -620,6 +620,10 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,
3140 + lock_sock(sk);
3141 +
3142 + error = -EINVAL;
3143 ++
3144 ++ if (sockaddr_len != sizeof(struct sockaddr_pppox))
3145 ++ goto end;
3146 ++
3147 + if (sp->sa_protocol != PX_PROTO_OE)
3148 + goto end;
3149 +
3150 +diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
3151 +index 2a366554c503..8a222ae5950e 100644
3152 +--- a/drivers/net/team/team.c
3153 ++++ b/drivers/net/team/team.c
3154 +@@ -261,6 +261,17 @@ static void __team_option_inst_mark_removed_port(struct team *team,
3155 + }
3156 + }
3157 +
3158 ++static bool __team_option_inst_tmp_find(const struct list_head *opts,
3159 ++ const struct team_option_inst *needle)
3160 ++{
3161 ++ struct team_option_inst *opt_inst;
3162 ++
3163 ++ list_for_each_entry(opt_inst, opts, tmp_list)
3164 ++ if (opt_inst == needle)
3165 ++ return true;
3166 ++ return false;
3167 ++}
3168 ++
3169 + static int __team_options_register(struct team *team,
3170 + const struct team_option *option,
3171 + size_t option_count)
3172 +@@ -1061,14 +1072,11 @@ static void team_port_leave(struct team *team, struct team_port *port)
3173 + }
3174 +
3175 + #ifdef CONFIG_NET_POLL_CONTROLLER
3176 +-static int team_port_enable_netpoll(struct team *team, struct team_port *port)
3177 ++static int __team_port_enable_netpoll(struct team_port *port)
3178 + {
3179 + struct netpoll *np;
3180 + int err;
3181 +
3182 +- if (!team->dev->npinfo)
3183 +- return 0;
3184 +-
3185 + np = kzalloc(sizeof(*np), GFP_KERNEL);
3186 + if (!np)
3187 + return -ENOMEM;
3188 +@@ -1082,6 +1090,14 @@ static int team_port_enable_netpoll(struct team *team, struct team_port *port)
3189 + return err;
3190 + }
3191 +
3192 ++static int team_port_enable_netpoll(struct team_port *port)
3193 ++{
3194 ++ if (!port->team->dev->npinfo)
3195 ++ return 0;
3196 ++
3197 ++ return __team_port_enable_netpoll(port);
3198 ++}
3199 ++
3200 + static void team_port_disable_netpoll(struct team_port *port)
3201 + {
3202 + struct netpoll *np = port->np;
3203 +@@ -1096,7 +1112,7 @@ static void team_port_disable_netpoll(struct team_port *port)
3204 + kfree(np);
3205 + }
3206 + #else
3207 +-static int team_port_enable_netpoll(struct team *team, struct team_port *port)
3208 ++static int team_port_enable_netpoll(struct team_port *port)
3209 + {
3210 + return 0;
3211 + }
3212 +@@ -1204,7 +1220,7 @@ static int team_port_add(struct team *team, struct net_device *port_dev)
3213 + goto err_vids_add;
3214 + }
3215 +
3216 +- err = team_port_enable_netpoll(team, port);
3217 ++ err = team_port_enable_netpoll(port);
3218 + if (err) {
3219 + netdev_err(dev, "Failed to enable netpoll on device %s\n",
3220 + portname);
3221 +@@ -1901,7 +1917,7 @@ static int team_netpoll_setup(struct net_device *dev,
3222 +
3223 + mutex_lock(&team->lock);
3224 + list_for_each_entry(port, &team->port_list, list) {
3225 +- err = team_port_enable_netpoll(team, port);
3226 ++ err = __team_port_enable_netpoll(port);
3227 + if (err) {
3228 + __team_netpoll_cleanup(team);
3229 + break;
3230 +@@ -2561,6 +2577,14 @@ static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info)
3231 + if (err)
3232 + goto team_put;
3233 + opt_inst->changed = true;
3234 ++
3235 ++ /* dumb/evil user-space can send us duplicate opt,
3236 ++ * keep only the last one
3237 ++ */
3238 ++ if (__team_option_inst_tmp_find(&opt_inst_list,
3239 ++ opt_inst))
3240 ++ continue;
3241 ++
3242 + list_add(&opt_inst->tmp_list, &opt_inst_list);
3243 + }
3244 + if (!opt_found) {
3245 +diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
3246 +index b0a038e6fda0..bb15b3012aa5 100644
3247 +--- a/drivers/net/virtio_net.c
3248 ++++ b/drivers/net/virtio_net.c
3249 +@@ -116,6 +116,17 @@ struct receive_queue {
3250 + char name[40];
3251 + };
3252 +
3253 ++/* Control VQ buffers: protected by the rtnl lock */
3254 ++struct control_buf {
3255 ++ struct virtio_net_ctrl_hdr hdr;
3256 ++ virtio_net_ctrl_ack status;
3257 ++ struct virtio_net_ctrl_mq mq;
3258 ++ u8 promisc;
3259 ++ u8 allmulti;
3260 ++ __virtio16 vid;
3261 ++ u64 offloads;
3262 ++};
3263 ++
3264 + struct virtnet_info {
3265 + struct virtio_device *vdev;
3266 + struct virtqueue *cvq;
3267 +@@ -164,14 +175,7 @@ struct virtnet_info {
3268 + struct hlist_node node;
3269 + struct hlist_node node_dead;
3270 +
3271 +- /* Control VQ buffers: protected by the rtnl lock */
3272 +- struct virtio_net_ctrl_hdr ctrl_hdr;
3273 +- virtio_net_ctrl_ack ctrl_status;
3274 +- struct virtio_net_ctrl_mq ctrl_mq;
3275 +- u8 ctrl_promisc;
3276 +- u8 ctrl_allmulti;
3277 +- u16 ctrl_vid;
3278 +- u64 ctrl_offloads;
3279 ++ struct control_buf *ctrl;
3280 +
3281 + /* Ethtool settings */
3282 + u8 duplex;
3283 +@@ -1340,25 +1344,25 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
3284 + /* Caller should know better */
3285 + BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ));
3286 +
3287 +- vi->ctrl_status = ~0;
3288 +- vi->ctrl_hdr.class = class;
3289 +- vi->ctrl_hdr.cmd = cmd;
3290 ++ vi->ctrl->status = ~0;
3291 ++ vi->ctrl->hdr.class = class;
3292 ++ vi->ctrl->hdr.cmd = cmd;
3293 + /* Add header */
3294 +- sg_init_one(&hdr, &vi->ctrl_hdr, sizeof(vi->ctrl_hdr));
3295 ++ sg_init_one(&hdr, &vi->ctrl->hdr, sizeof(vi->ctrl->hdr));
3296 + sgs[out_num++] = &hdr;
3297 +
3298 + if (out)
3299 + sgs[out_num++] = out;
3300 +
3301 + /* Add return status. */
3302 +- sg_init_one(&stat, &vi->ctrl_status, sizeof(vi->ctrl_status));
3303 ++ sg_init_one(&stat, &vi->ctrl->status, sizeof(vi->ctrl->status));
3304 + sgs[out_num] = &stat;
3305 +
3306 + BUG_ON(out_num + 1 > ARRAY_SIZE(sgs));
3307 + virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
3308 +
3309 + if (unlikely(!virtqueue_kick(vi->cvq)))
3310 +- return vi->ctrl_status == VIRTIO_NET_OK;
3311 ++ return vi->ctrl->status == VIRTIO_NET_OK;
3312 +
3313 + /* Spin for a response, the kick causes an ioport write, trapping
3314 + * into the hypervisor, so the request should be handled immediately.
3315 +@@ -1367,7 +1371,7 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
3316 + !virtqueue_is_broken(vi->cvq))
3317 + cpu_relax();
3318 +
3319 +- return vi->ctrl_status == VIRTIO_NET_OK;
3320 ++ return vi->ctrl->status == VIRTIO_NET_OK;
3321 + }
3322 +
3323 + static int virtnet_set_mac_address(struct net_device *dev, void *p)
3324 +@@ -1478,8 +1482,8 @@ static int _virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
3325 + if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ))
3326 + return 0;
3327 +
3328 +- vi->ctrl_mq.virtqueue_pairs = cpu_to_virtio16(vi->vdev, queue_pairs);
3329 +- sg_init_one(&sg, &vi->ctrl_mq, sizeof(vi->ctrl_mq));
3330 ++ vi->ctrl->mq.virtqueue_pairs = cpu_to_virtio16(vi->vdev, queue_pairs);
3331 ++ sg_init_one(&sg, &vi->ctrl->mq, sizeof(vi->ctrl->mq));
3332 +
3333 + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MQ,
3334 + VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET, &sg)) {
3335 +@@ -1537,22 +1541,22 @@ static void virtnet_set_rx_mode(struct net_device *dev)
3336 + if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX))
3337 + return;
3338 +
3339 +- vi->ctrl_promisc = ((dev->flags & IFF_PROMISC) != 0);
3340 +- vi->ctrl_allmulti = ((dev->flags & IFF_ALLMULTI) != 0);
3341 ++ vi->ctrl->promisc = ((dev->flags & IFF_PROMISC) != 0);
3342 ++ vi->ctrl->allmulti = ((dev->flags & IFF_ALLMULTI) != 0);
3343 +
3344 +- sg_init_one(sg, &vi->ctrl_promisc, sizeof(vi->ctrl_promisc));
3345 ++ sg_init_one(sg, &vi->ctrl->promisc, sizeof(vi->ctrl->promisc));
3346 +
3347 + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
3348 + VIRTIO_NET_CTRL_RX_PROMISC, sg))
3349 + dev_warn(&dev->dev, "Failed to %sable promisc mode.\n",
3350 +- vi->ctrl_promisc ? "en" : "dis");
3351 ++ vi->ctrl->promisc ? "en" : "dis");
3352 +
3353 +- sg_init_one(sg, &vi->ctrl_allmulti, sizeof(vi->ctrl_allmulti));
3354 ++ sg_init_one(sg, &vi->ctrl->allmulti, sizeof(vi->ctrl->allmulti));
3355 +
3356 + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
3357 + VIRTIO_NET_CTRL_RX_ALLMULTI, sg))
3358 + dev_warn(&dev->dev, "Failed to %sable allmulti mode.\n",
3359 +- vi->ctrl_allmulti ? "en" : "dis");
3360 ++ vi->ctrl->allmulti ? "en" : "dis");
3361 +
3362 + uc_count = netdev_uc_count(dev);
3363 + mc_count = netdev_mc_count(dev);
3364 +@@ -1598,8 +1602,8 @@ static int virtnet_vlan_rx_add_vid(struct net_device *dev,
3365 + struct virtnet_info *vi = netdev_priv(dev);
3366 + struct scatterlist sg;
3367 +
3368 +- vi->ctrl_vid = vid;
3369 +- sg_init_one(&sg, &vi->ctrl_vid, sizeof(vi->ctrl_vid));
3370 ++ vi->ctrl->vid = cpu_to_virtio16(vi->vdev, vid);
3371 ++ sg_init_one(&sg, &vi->ctrl->vid, sizeof(vi->ctrl->vid));
3372 +
3373 + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,
3374 + VIRTIO_NET_CTRL_VLAN_ADD, &sg))
3375 +@@ -1613,8 +1617,8 @@ static int virtnet_vlan_rx_kill_vid(struct net_device *dev,
3376 + struct virtnet_info *vi = netdev_priv(dev);
3377 + struct scatterlist sg;
3378 +
3379 +- vi->ctrl_vid = vid;
3380 +- sg_init_one(&sg, &vi->ctrl_vid, sizeof(vi->ctrl_vid));
3381 ++ vi->ctrl->vid = cpu_to_virtio16(vi->vdev, vid);
3382 ++ sg_init_one(&sg, &vi->ctrl->vid, sizeof(vi->ctrl->vid));
3383 +
3384 + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN,
3385 + VIRTIO_NET_CTRL_VLAN_DEL, &sg))
3386 +@@ -1912,9 +1916,9 @@ static int virtnet_restore_up(struct virtio_device *vdev)
3387 + static int virtnet_set_guest_offloads(struct virtnet_info *vi, u64 offloads)
3388 + {
3389 + struct scatterlist sg;
3390 +- vi->ctrl_offloads = cpu_to_virtio64(vi->vdev, offloads);
3391 ++ vi->ctrl->offloads = cpu_to_virtio64(vi->vdev, offloads);
3392 +
3393 +- sg_init_one(&sg, &vi->ctrl_offloads, sizeof(vi->ctrl_offloads));
3394 ++ sg_init_one(&sg, &vi->ctrl->offloads, sizeof(vi->ctrl->offloads));
3395 +
3396 + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_GUEST_OFFLOADS,
3397 + VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET, &sg)) {
3398 +@@ -2134,6 +2138,7 @@ static void virtnet_free_queues(struct virtnet_info *vi)
3399 +
3400 + kfree(vi->rq);
3401 + kfree(vi->sq);
3402 ++ kfree(vi->ctrl);
3403 + }
3404 +
3405 + static void _free_receive_bufs(struct virtnet_info *vi)
3406 +@@ -2326,6 +2331,9 @@ static int virtnet_alloc_queues(struct virtnet_info *vi)
3407 + {
3408 + int i;
3409 +
3410 ++ vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL);
3411 ++ if (!vi->ctrl)
3412 ++ goto err_ctrl;
3413 + vi->sq = kzalloc(sizeof(*vi->sq) * vi->max_queue_pairs, GFP_KERNEL);
3414 + if (!vi->sq)
3415 + goto err_sq;
3416 +@@ -2351,6 +2359,8 @@ static int virtnet_alloc_queues(struct virtnet_info *vi)
3417 + err_rq:
3418 + kfree(vi->sq);
3419 + err_sq:
3420 ++ kfree(vi->ctrl);
3421 ++err_ctrl:
3422 + return -ENOMEM;
3423 + }
3424 +
3425 +diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
3426 +index 252c2206cbb5..c1772215702a 100644
3427 +--- a/drivers/net/wireless/ath/ath10k/mac.c
3428 ++++ b/drivers/net/wireless/ath/ath10k/mac.c
3429 +@@ -5955,9 +5955,8 @@ static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3430 + sta->addr, smps, err);
3431 + }
3432 +
3433 +- if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3434 +- changed & IEEE80211_RC_NSS_CHANGED) {
3435 +- ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
3436 ++ if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
3437 ++ ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
3438 + sta->addr);
3439 +
3440 + err = ath10k_station_assoc(ar, arvif->vif, sta, true);
3441 +diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
3442 +index 72b4527d690f..71df0f70b61f 100644
3443 +--- a/drivers/pinctrl/intel/pinctrl-intel.c
3444 ++++ b/drivers/pinctrl/intel/pinctrl-intel.c
3445 +@@ -427,18 +427,6 @@ static void __intel_gpio_set_direction(void __iomem *padcfg0, bool input)
3446 + writel(value, padcfg0);
3447 + }
3448 +
3449 +-static void intel_gpio_set_gpio_mode(void __iomem *padcfg0)
3450 +-{
3451 +- u32 value;
3452 +-
3453 +- /* Put the pad into GPIO mode */
3454 +- value = readl(padcfg0) & ~PADCFG0_PMODE_MASK;
3455 +- /* Disable SCI/SMI/NMI generation */
3456 +- value &= ~(PADCFG0_GPIROUTIOXAPIC | PADCFG0_GPIROUTSCI);
3457 +- value &= ~(PADCFG0_GPIROUTSMI | PADCFG0_GPIROUTNMI);
3458 +- writel(value, padcfg0);
3459 +-}
3460 +-
3461 + static int intel_gpio_request_enable(struct pinctrl_dev *pctldev,
3462 + struct pinctrl_gpio_range *range,
3463 + unsigned pin)
3464 +@@ -446,6 +434,7 @@ static int intel_gpio_request_enable(struct pinctrl_dev *pctldev,
3465 + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
3466 + void __iomem *padcfg0;
3467 + unsigned long flags;
3468 ++ u32 value;
3469 +
3470 + raw_spin_lock_irqsave(&pctrl->lock, flags);
3471 +
3472 +@@ -455,7 +444,13 @@ static int intel_gpio_request_enable(struct pinctrl_dev *pctldev,
3473 + }
3474 +
3475 + padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0);
3476 +- intel_gpio_set_gpio_mode(padcfg0);
3477 ++ /* Put the pad into GPIO mode */
3478 ++ value = readl(padcfg0) & ~PADCFG0_PMODE_MASK;
3479 ++ /* Disable SCI/SMI/NMI generation */
3480 ++ value &= ~(PADCFG0_GPIROUTIOXAPIC | PADCFG0_GPIROUTSCI);
3481 ++ value &= ~(PADCFG0_GPIROUTSMI | PADCFG0_GPIROUTNMI);
3482 ++ writel(value, padcfg0);
3483 ++
3484 + /* Disable TX buffer and enable RX (this will be input) */
3485 + __intel_gpio_set_direction(padcfg0, true);
3486 +
3487 +@@ -940,8 +935,6 @@ static int intel_gpio_irq_type(struct irq_data *d, unsigned type)
3488 +
3489 + raw_spin_lock_irqsave(&pctrl->lock, flags);
3490 +
3491 +- intel_gpio_set_gpio_mode(reg);
3492 +-
3493 + value = readl(reg);
3494 +
3495 + value &= ~(PADCFG0_RXEVCFG_MASK | PADCFG0_RXINV);
3496 +diff --git a/drivers/s390/block/dasd_alias.c b/drivers/s390/block/dasd_alias.c
3497 +index 62f5f04d8f61..5e963fe0e38d 100644
3498 +--- a/drivers/s390/block/dasd_alias.c
3499 ++++ b/drivers/s390/block/dasd_alias.c
3500 +@@ -592,13 +592,22 @@ static int _schedule_lcu_update(struct alias_lcu *lcu,
3501 + int dasd_alias_add_device(struct dasd_device *device)
3502 + {
3503 + struct dasd_eckd_private *private = device->private;
3504 +- struct alias_lcu *lcu;
3505 ++ __u8 uaddr = private->uid.real_unit_addr;
3506 ++ struct alias_lcu *lcu = private->lcu;
3507 + unsigned long flags;
3508 + int rc;
3509 +
3510 +- lcu = private->lcu;
3511 + rc = 0;
3512 + spin_lock_irqsave(&lcu->lock, flags);
3513 ++ /*
3514 ++ * Check if device and lcu type differ. If so, the uac data may be
3515 ++ * outdated and needs to be updated.
3516 ++ */
3517 ++ if (private->uid.type != lcu->uac->unit[uaddr].ua_type) {
3518 ++ lcu->flags |= UPDATE_PENDING;
3519 ++ DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3520 ++ "uid type mismatch - trigger rescan");
3521 ++ }
3522 + if (!(lcu->flags & UPDATE_PENDING)) {
3523 + rc = _add_device_to_lcu(lcu, device, device);
3524 + if (rc)
3525 +diff --git a/drivers/s390/char/Makefile b/drivers/s390/char/Makefile
3526 +index 05ac6ba15a53..ecc24a46e71a 100644
3527 +--- a/drivers/s390/char/Makefile
3528 ++++ b/drivers/s390/char/Makefile
3529 +@@ -17,6 +17,8 @@ CFLAGS_REMOVE_sclp_early_core.o += $(CC_FLAGS_MARCH)
3530 + CFLAGS_sclp_early_core.o += -march=z900
3531 + endif
3532 +
3533 ++CFLAGS_REMOVE_sclp_early_core.o += $(CC_FLAGS_EXPOLINE)
3534 ++
3535 + obj-y += ctrlchar.o keyboard.o defkeymap.o sclp.o sclp_rw.o sclp_quiesce.o \
3536 + sclp_cmd.o sclp_config.o sclp_cpi_sys.o sclp_ocf.o sclp_ctl.o \
3537 + sclp_early.o sclp_early_core.o
3538 +diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
3539 +index 7b0b295b2313..69687c16a150 100644
3540 +--- a/drivers/s390/cio/chsc.c
3541 ++++ b/drivers/s390/cio/chsc.c
3542 +@@ -451,6 +451,7 @@ static void chsc_process_sei_link_incident(struct chsc_sei_nt0_area *sei_area)
3543 +
3544 + static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area *sei_area)
3545 + {
3546 ++ struct channel_path *chp;
3547 + struct chp_link link;
3548 + struct chp_id chpid;
3549 + int status;
3550 +@@ -463,10 +464,17 @@ static void chsc_process_sei_res_acc(struct chsc_sei_nt0_area *sei_area)
3551 + chpid.id = sei_area->rsid;
3552 + /* allocate a new channel path structure, if needed */
3553 + status = chp_get_status(chpid);
3554 +- if (status < 0)
3555 +- chp_new(chpid);
3556 +- else if (!status)
3557 ++ if (!status)
3558 + return;
3559 ++
3560 ++ if (status < 0) {
3561 ++ chp_new(chpid);
3562 ++ } else {
3563 ++ chp = chpid_to_chp(chpid);
3564 ++ mutex_lock(&chp->lock);
3565 ++ chp_update_desc(chp);
3566 ++ mutex_unlock(&chp->lock);
3567 ++ }
3568 + memset(&link, 0, sizeof(struct chp_link));
3569 + link.chpid = chpid;
3570 + if ((sei_area->vf & 0xc0) != 0) {
3571 +diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
3572 +index 3597ef78df4d..ce74278a454a 100644
3573 +--- a/include/linux/fsnotify_backend.h
3574 ++++ b/include/linux/fsnotify_backend.h
3575 +@@ -217,12 +217,10 @@ struct fsnotify_mark_connector {
3576 + union { /* Object pointer [lock] */
3577 + struct inode *inode;
3578 + struct vfsmount *mnt;
3579 +- };
3580 +- union {
3581 +- struct hlist_head list;
3582 + /* Used listing heads to free after srcu period expires */
3583 + struct fsnotify_mark_connector *destroy_next;
3584 + };
3585 ++ struct hlist_head list;
3586 + };
3587 +
3588 + /*
3589 +diff --git a/include/linux/hmm.h b/include/linux/hmm.h
3590 +index 8198faf16ed6..96e69979f84d 100644
3591 +--- a/include/linux/hmm.h
3592 ++++ b/include/linux/hmm.h
3593 +@@ -498,16 +498,23 @@ struct hmm_device {
3594 + struct hmm_device *hmm_device_new(void *drvdata);
3595 + void hmm_device_put(struct hmm_device *hmm_device);
3596 + #endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */
3597 ++#endif /* IS_ENABLED(CONFIG_HMM) */
3598 +
3599 + /* Below are for HMM internal use only! Not to be used by device driver! */
3600 ++#if IS_ENABLED(CONFIG_HMM_MIRROR)
3601 + void hmm_mm_destroy(struct mm_struct *mm);
3602 +
3603 + static inline void hmm_mm_init(struct mm_struct *mm)
3604 + {
3605 + mm->hmm = NULL;
3606 + }
3607 ++#else /* IS_ENABLED(CONFIG_HMM_MIRROR) */
3608 ++static inline void hmm_mm_destroy(struct mm_struct *mm) {}
3609 ++static inline void hmm_mm_init(struct mm_struct *mm) {}
3610 ++#endif /* IS_ENABLED(CONFIG_HMM_MIRROR) */
3611 ++
3612 ++
3613 + #else /* IS_ENABLED(CONFIG_HMM) */
3614 + static inline void hmm_mm_destroy(struct mm_struct *mm) {}
3615 + static inline void hmm_mm_init(struct mm_struct *mm) {}
3616 +-#endif /* IS_ENABLED(CONFIG_HMM) */
3617 + #endif /* LINUX_HMM_H */
3618 +diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h
3619 +index 5e6a2d4dc366..ab927383c99d 100644
3620 +--- a/include/linux/if_vlan.h
3621 ++++ b/include/linux/if_vlan.h
3622 +@@ -584,7 +584,7 @@ static inline bool skb_vlan_tagged(const struct sk_buff *skb)
3623 + * Returns true if the skb is tagged with multiple vlan headers, regardless
3624 + * of whether it is hardware accelerated or not.
3625 + */
3626 +-static inline bool skb_vlan_tagged_multi(const struct sk_buff *skb)
3627 ++static inline bool skb_vlan_tagged_multi(struct sk_buff *skb)
3628 + {
3629 + __be16 protocol = skb->protocol;
3630 +
3631 +@@ -594,6 +594,9 @@ static inline bool skb_vlan_tagged_multi(const struct sk_buff *skb)
3632 + if (likely(!eth_type_vlan(protocol)))
3633 + return false;
3634 +
3635 ++ if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN)))
3636 ++ return false;
3637 ++
3638 + veh = (struct vlan_ethhdr *)skb->data;
3639 + protocol = veh->h_vlan_encapsulated_proto;
3640 + }
3641 +@@ -611,7 +614,7 @@ static inline bool skb_vlan_tagged_multi(const struct sk_buff *skb)
3642 + *
3643 + * Returns features without unsafe ones if the skb has multiple tags.
3644 + */
3645 +-static inline netdev_features_t vlan_features_check(const struct sk_buff *skb,
3646 ++static inline netdev_features_t vlan_features_check(struct sk_buff *skb,
3647 + netdev_features_t features)
3648 + {
3649 + if (skb_vlan_tagged_multi(skb)) {
3650 +diff --git a/include/linux/tpm.h b/include/linux/tpm.h
3651 +index 881312d85574..2a6c3d96b31f 100644
3652 +--- a/include/linux/tpm.h
3653 ++++ b/include/linux/tpm.h
3654 +@@ -49,7 +49,7 @@ struct tpm_class_ops {
3655 + bool (*update_timeouts)(struct tpm_chip *chip,
3656 + unsigned long *timeout_cap);
3657 + int (*request_locality)(struct tpm_chip *chip, int loc);
3658 +- void (*relinquish_locality)(struct tpm_chip *chip, int loc);
3659 ++ int (*relinquish_locality)(struct tpm_chip *chip, int loc);
3660 + void (*clk_enable)(struct tpm_chip *chip, bool value);
3661 + };
3662 +
3663 +diff --git a/include/net/ife.h b/include/net/ife.h
3664 +index 44b9c00f7223..e117617e3c34 100644
3665 +--- a/include/net/ife.h
3666 ++++ b/include/net/ife.h
3667 +@@ -12,7 +12,8 @@
3668 + void *ife_encode(struct sk_buff *skb, u16 metalen);
3669 + void *ife_decode(struct sk_buff *skb, u16 *metalen);
3670 +
3671 +-void *ife_tlv_meta_decode(void *skbdata, u16 *attrtype, u16 *dlen, u16 *totlen);
3672 ++void *ife_tlv_meta_decode(void *skbdata, const void *ifehdr_end, u16 *attrtype,
3673 ++ u16 *dlen, u16 *totlen);
3674 + int ife_tlv_meta_encode(void *skbdata, u16 attrtype, u16 dlen,
3675 + const void *dval);
3676 +
3677 +diff --git a/include/net/llc_conn.h b/include/net/llc_conn.h
3678 +index fe994d2e5286..ea985aa7a6c5 100644
3679 +--- a/include/net/llc_conn.h
3680 ++++ b/include/net/llc_conn.h
3681 +@@ -97,6 +97,7 @@ static __inline__ char llc_backlog_type(struct sk_buff *skb)
3682 +
3683 + struct sock *llc_sk_alloc(struct net *net, int family, gfp_t priority,
3684 + struct proto *prot, int kern);
3685 ++void llc_sk_stop_all_timers(struct sock *sk, bool sync);
3686 + void llc_sk_free(struct sock *sk);
3687 +
3688 + void llc_sk_reset(struct sock *sk);
3689 +diff --git a/include/net/tcp.h b/include/net/tcp.h
3690 +index d323d4fa742c..fb653736f335 100644
3691 +--- a/include/net/tcp.h
3692 ++++ b/include/net/tcp.h
3693 +@@ -1616,6 +1616,7 @@ static inline void tcp_write_queue_purge(struct sock *sk)
3694 + sk_mem_reclaim(sk);
3695 + tcp_clear_all_retrans_hints(tcp_sk(sk));
3696 + tcp_init_send_head(sk);
3697 ++ tcp_sk(sk)->packets_out = 0;
3698 + }
3699 +
3700 + static inline struct sk_buff *tcp_write_queue_head(const struct sock *sk)
3701 +diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
3702 +index 7e99999d6236..857bad91c454 100644
3703 +--- a/include/uapi/linux/kvm.h
3704 ++++ b/include/uapi/linux/kvm.h
3705 +@@ -931,6 +931,7 @@ struct kvm_ppc_resize_hpt {
3706 + #define KVM_CAP_PPC_SMT_POSSIBLE 147
3707 + #define KVM_CAP_HYPERV_SYNIC2 148
3708 + #define KVM_CAP_HYPERV_VP_INDEX 149
3709 ++#define KVM_CAP_S390_BPB 152
3710 +
3711 + #ifdef KVM_CAP_IRQ_ROUTING
3712 +
3713 +diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h
3714 +index e954ae3d82c0..e3a658bac10f 100644
3715 +--- a/kernel/trace/trace_entries.h
3716 ++++ b/kernel/trace/trace_entries.h
3717 +@@ -356,7 +356,7 @@ FTRACE_ENTRY(hwlat, hwlat_entry,
3718 + __field( unsigned int, seqnum )
3719 + ),
3720 +
3721 +- F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llunmi-ts:%llu\tnmi-count:%u\n",
3722 ++ F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llu\tnmi-ts:%llu\tnmi-count:%u\n",
3723 + __entry->seqnum,
3724 + __entry->tv_sec,
3725 + __entry->tv_nsec,
3726 +diff --git a/net/core/dev.c b/net/core/dev.c
3727 +index 4be2a4047640..e7d56c5adde6 100644
3728 +--- a/net/core/dev.c
3729 ++++ b/net/core/dev.c
3730 +@@ -2903,7 +2903,7 @@ netdev_features_t passthru_features_check(struct sk_buff *skb,
3731 + }
3732 + EXPORT_SYMBOL(passthru_features_check);
3733 +
3734 +-static netdev_features_t dflt_features_check(const struct sk_buff *skb,
3735 ++static netdev_features_t dflt_features_check(struct sk_buff *skb,
3736 + struct net_device *dev,
3737 + netdev_features_t features)
3738 + {
3739 +diff --git a/net/core/neighbour.c b/net/core/neighbour.c
3740 +index 741ae2554190..514d697d4691 100644
3741 +--- a/net/core/neighbour.c
3742 ++++ b/net/core/neighbour.c
3743 +@@ -55,7 +55,8 @@ static void neigh_timer_handler(unsigned long arg);
3744 + static void __neigh_notify(struct neighbour *n, int type, int flags,
3745 + u32 pid);
3746 + static void neigh_update_notify(struct neighbour *neigh, u32 nlmsg_pid);
3747 +-static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev);
3748 ++static int pneigh_ifdown_and_unlock(struct neigh_table *tbl,
3749 ++ struct net_device *dev);
3750 +
3751 + #ifdef CONFIG_PROC_FS
3752 + static const struct file_operations neigh_stat_seq_fops;
3753 +@@ -291,8 +292,7 @@ int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev)
3754 + {
3755 + write_lock_bh(&tbl->lock);
3756 + neigh_flush_dev(tbl, dev);
3757 +- pneigh_ifdown(tbl, dev);
3758 +- write_unlock_bh(&tbl->lock);
3759 ++ pneigh_ifdown_and_unlock(tbl, dev);
3760 +
3761 + del_timer_sync(&tbl->proxy_timer);
3762 + pneigh_queue_purge(&tbl->proxy_queue);
3763 +@@ -681,9 +681,10 @@ int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey,
3764 + return -ENOENT;
3765 + }
3766 +
3767 +-static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev)
3768 ++static int pneigh_ifdown_and_unlock(struct neigh_table *tbl,
3769 ++ struct net_device *dev)
3770 + {
3771 +- struct pneigh_entry *n, **np;
3772 ++ struct pneigh_entry *n, **np, *freelist = NULL;
3773 + u32 h;
3774 +
3775 + for (h = 0; h <= PNEIGH_HASHMASK; h++) {
3776 +@@ -691,16 +692,23 @@ static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev)
3777 + while ((n = *np) != NULL) {
3778 + if (!dev || n->dev == dev) {
3779 + *np = n->next;
3780 +- if (tbl->pdestructor)
3781 +- tbl->pdestructor(n);
3782 +- if (n->dev)
3783 +- dev_put(n->dev);
3784 +- kfree(n);
3785 ++ n->next = freelist;
3786 ++ freelist = n;
3787 + continue;
3788 + }
3789 + np = &n->next;
3790 + }
3791 + }
3792 ++ write_unlock_bh(&tbl->lock);
3793 ++ while ((n = freelist)) {
3794 ++ freelist = n->next;
3795 ++ n->next = NULL;
3796 ++ if (tbl->pdestructor)
3797 ++ tbl->pdestructor(n);
3798 ++ if (n->dev)
3799 ++ dev_put(n->dev);
3800 ++ kfree(n);
3801 ++ }
3802 + return -ENOENT;
3803 + }
3804 +
3805 +@@ -2323,12 +2331,16 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
3806 +
3807 + err = nlmsg_parse(nlh, sizeof(struct ndmsg), tb, NDA_MAX, NULL, NULL);
3808 + if (!err) {
3809 +- if (tb[NDA_IFINDEX])
3810 ++ if (tb[NDA_IFINDEX]) {
3811 ++ if (nla_len(tb[NDA_IFINDEX]) != sizeof(u32))
3812 ++ return -EINVAL;
3813 + filter_idx = nla_get_u32(tb[NDA_IFINDEX]);
3814 +-
3815 +- if (tb[NDA_MASTER])
3816 ++ }
3817 ++ if (tb[NDA_MASTER]) {
3818 ++ if (nla_len(tb[NDA_MASTER]) != sizeof(u32))
3819 ++ return -EINVAL;
3820 + filter_master_idx = nla_get_u32(tb[NDA_MASTER]);
3821 +-
3822 ++ }
3823 + if (filter_idx || filter_master_idx)
3824 + flags |= NLM_F_DUMP_FILTERED;
3825 + }
3826 +diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
3827 +index e1d4d898a007..f0252768ecf4 100644
3828 +--- a/net/dns_resolver/dns_key.c
3829 ++++ b/net/dns_resolver/dns_key.c
3830 +@@ -25,6 +25,7 @@
3831 + #include <linux/moduleparam.h>
3832 + #include <linux/slab.h>
3833 + #include <linux/string.h>
3834 ++#include <linux/ratelimit.h>
3835 + #include <linux/kernel.h>
3836 + #include <linux/keyctl.h>
3837 + #include <linux/err.h>
3838 +@@ -91,9 +92,9 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
3839 +
3840 + next_opt = memchr(opt, '#', end - opt) ?: end;
3841 + opt_len = next_opt - opt;
3842 +- if (!opt_len) {
3843 +- printk(KERN_WARNING
3844 +- "Empty option to dns_resolver key\n");
3845 ++ if (opt_len <= 0 || opt_len > 128) {
3846 ++ pr_warn_ratelimited("Invalid option length (%d) for dns_resolver key\n",
3847 ++ opt_len);
3848 + return -EINVAL;
3849 + }
3850 +
3851 +@@ -127,10 +128,8 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
3852 + }
3853 +
3854 + bad_option_value:
3855 +- printk(KERN_WARNING
3856 +- "Option '%*.*s' to dns_resolver key:"
3857 +- " bad/missing value\n",
3858 +- opt_nlen, opt_nlen, opt);
3859 ++ pr_warn_ratelimited("Option '%*.*s' to dns_resolver key: bad/missing value\n",
3860 ++ opt_nlen, opt_nlen, opt);
3861 + return -EINVAL;
3862 + } while (opt = next_opt + 1, opt < end);
3863 + }
3864 +diff --git a/net/ife/ife.c b/net/ife/ife.c
3865 +index 7d1ec76e7f43..13bbf8cb6a39 100644
3866 +--- a/net/ife/ife.c
3867 ++++ b/net/ife/ife.c
3868 +@@ -69,6 +69,9 @@ void *ife_decode(struct sk_buff *skb, u16 *metalen)
3869 + int total_pull;
3870 + u16 ifehdrln;
3871 +
3872 ++ if (!pskb_may_pull(skb, skb->dev->hard_header_len + IFE_METAHDRLEN))
3873 ++ return NULL;
3874 ++
3875 + ifehdr = (struct ifeheadr *) (skb->data + skb->dev->hard_header_len);
3876 + ifehdrln = ntohs(ifehdr->metalen);
3877 + total_pull = skb->dev->hard_header_len + ifehdrln;
3878 +@@ -92,12 +95,43 @@ struct meta_tlvhdr {
3879 + __be16 len;
3880 + };
3881 +
3882 ++static bool __ife_tlv_meta_valid(const unsigned char *skbdata,
3883 ++ const unsigned char *ifehdr_end)
3884 ++{
3885 ++ const struct meta_tlvhdr *tlv;
3886 ++ u16 tlvlen;
3887 ++
3888 ++ if (unlikely(skbdata + sizeof(*tlv) > ifehdr_end))
3889 ++ return false;
3890 ++
3891 ++ tlv = (const struct meta_tlvhdr *)skbdata;
3892 ++ tlvlen = ntohs(tlv->len);
3893 ++
3894 ++ /* tlv length field is inc header, check on minimum */
3895 ++ if (tlvlen < NLA_HDRLEN)
3896 ++ return false;
3897 ++
3898 ++ /* overflow by NLA_ALIGN check */
3899 ++ if (NLA_ALIGN(tlvlen) < tlvlen)
3900 ++ return false;
3901 ++
3902 ++ if (unlikely(skbdata + NLA_ALIGN(tlvlen) > ifehdr_end))
3903 ++ return false;
3904 ++
3905 ++ return true;
3906 ++}
3907 ++
3908 + /* Caller takes care of presenting data in network order
3909 + */
3910 +-void *ife_tlv_meta_decode(void *skbdata, u16 *attrtype, u16 *dlen, u16 *totlen)
3911 ++void *ife_tlv_meta_decode(void *skbdata, const void *ifehdr_end, u16 *attrtype,
3912 ++ u16 *dlen, u16 *totlen)
3913 + {
3914 +- struct meta_tlvhdr *tlv = (struct meta_tlvhdr *) skbdata;
3915 ++ struct meta_tlvhdr *tlv;
3916 ++
3917 ++ if (!__ife_tlv_meta_valid(skbdata, ifehdr_end))
3918 ++ return NULL;
3919 +
3920 ++ tlv = (struct meta_tlvhdr *)skbdata;
3921 + *dlen = ntohs(tlv->len) - NLA_HDRLEN;
3922 + *attrtype = ntohs(tlv->type);
3923 +
3924 +diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
3925 +index 38b9a6276a9d..d023f879e7bb 100644
3926 +--- a/net/ipv4/tcp.c
3927 ++++ b/net/ipv4/tcp.c
3928 +@@ -2354,7 +2354,6 @@ int tcp_disconnect(struct sock *sk, int flags)
3929 + icsk->icsk_backoff = 0;
3930 + tp->snd_cwnd = 2;
3931 + icsk->icsk_probes_out = 0;
3932 +- tp->packets_out = 0;
3933 + tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
3934 + tp->snd_cwnd_cnt = 0;
3935 + tp->window_clamp = 0;
3936 +@@ -2742,8 +2741,10 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
3937 + #ifdef CONFIG_TCP_MD5SIG
3938 + case TCP_MD5SIG:
3939 + case TCP_MD5SIG_EXT:
3940 +- /* Read the IP->Key mappings from userspace */
3941 +- err = tp->af_specific->md5_parse(sk, optname, optval, optlen);
3942 ++ if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))
3943 ++ err = tp->af_specific->md5_parse(sk, optname, optval, optlen);
3944 ++ else
3945 ++ err = -EINVAL;
3946 + break;
3947 + #endif
3948 + case TCP_USER_TIMEOUT:
3949 +diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
3950 +index 14474acea0bb..ebbb54bcbcac 100644
3951 +--- a/net/ipv4/tcp_input.c
3952 ++++ b/net/ipv4/tcp_input.c
3953 +@@ -3892,11 +3892,8 @@ const u8 *tcp_parse_md5sig_option(const struct tcphdr *th)
3954 + int length = (th->doff << 2) - sizeof(*th);
3955 + const u8 *ptr = (const u8 *)(th + 1);
3956 +
3957 +- /* If the TCP option is too short, we can short cut */
3958 +- if (length < TCPOLEN_MD5SIG)
3959 +- return NULL;
3960 +-
3961 +- while (length > 0) {
3962 ++ /* If not enough data remaining, we can short cut */
3963 ++ while (length >= TCPOLEN_MD5SIG) {
3964 + int opcode = *ptr++;
3965 + int opsize;
3966 +
3967 +diff --git a/net/ipv6/route.c b/net/ipv6/route.c
3968 +index 0126d9bfa670..e04c534b573e 100644
3969 +--- a/net/ipv6/route.c
3970 ++++ b/net/ipv6/route.c
3971 +@@ -2959,6 +2959,7 @@ void rt6_mtu_change(struct net_device *dev, unsigned int mtu)
3972 +
3973 + static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
3974 + [RTA_GATEWAY] = { .len = sizeof(struct in6_addr) },
3975 ++ [RTA_PREFSRC] = { .len = sizeof(struct in6_addr) },
3976 + [RTA_OIF] = { .type = NLA_U32 },
3977 + [RTA_IIF] = { .type = NLA_U32 },
3978 + [RTA_PRIORITY] = { .type = NLA_U32 },
3979 +@@ -2970,6 +2971,7 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
3980 + [RTA_EXPIRES] = { .type = NLA_U32 },
3981 + [RTA_UID] = { .type = NLA_U32 },
3982 + [RTA_MARK] = { .type = NLA_U32 },
3983 ++ [RTA_TABLE] = { .type = NLA_U32 },
3984 + };
3985 +
3986 + static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
3987 +diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c
3988 +index f343e6f0fc95..5fe139484919 100644
3989 +--- a/net/ipv6/seg6_iptunnel.c
3990 ++++ b/net/ipv6/seg6_iptunnel.c
3991 +@@ -136,7 +136,7 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
3992 + isrh->nexthdr = proto;
3993 +
3994 + hdr->daddr = isrh->segments[isrh->first_segment];
3995 +- set_tun_src(net, ip6_dst_idev(dst)->dev, &hdr->daddr, &hdr->saddr);
3996 ++ set_tun_src(net, dst->dev, &hdr->daddr, &hdr->saddr);
3997 +
3998 + #ifdef CONFIG_IPV6_SEG6_HMAC
3999 + if (sr_has_hmac(isrh)) {
4000 +diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
4001 +index 0c2738349442..8bef35aa8786 100644
4002 +--- a/net/l2tp/l2tp_ppp.c
4003 ++++ b/net/l2tp/l2tp_ppp.c
4004 +@@ -591,6 +591,13 @@ static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
4005 + lock_sock(sk);
4006 +
4007 + error = -EINVAL;
4008 ++
4009 ++ if (sockaddr_len != sizeof(struct sockaddr_pppol2tp) &&
4010 ++ sockaddr_len != sizeof(struct sockaddr_pppol2tpv3) &&
4011 ++ sockaddr_len != sizeof(struct sockaddr_pppol2tpin6) &&
4012 ++ sockaddr_len != sizeof(struct sockaddr_pppol2tpv3in6))
4013 ++ goto end;
4014 ++
4015 + if (sp->sa_protocol != PX_PROTO_OL2TP)
4016 + goto end;
4017 +
4018 +diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
4019 +index c38d16f22d2a..cf41d9b4a0b8 100644
4020 +--- a/net/llc/af_llc.c
4021 ++++ b/net/llc/af_llc.c
4022 +@@ -199,9 +199,19 @@ static int llc_ui_release(struct socket *sock)
4023 + llc->laddr.lsap, llc->daddr.lsap);
4024 + if (!llc_send_disc(sk))
4025 + llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
4026 +- if (!sock_flag(sk, SOCK_ZAPPED))
4027 ++ if (!sock_flag(sk, SOCK_ZAPPED)) {
4028 ++ struct llc_sap *sap = llc->sap;
4029 ++
4030 ++ /* Hold this for release_sock(), so that llc_backlog_rcv()
4031 ++ * could still use it.
4032 ++ */
4033 ++ llc_sap_hold(sap);
4034 + llc_sap_remove_socket(llc->sap, sk);
4035 +- release_sock(sk);
4036 ++ release_sock(sk);
4037 ++ llc_sap_put(sap);
4038 ++ } else {
4039 ++ release_sock(sk);
4040 ++ }
4041 + if (llc->dev)
4042 + dev_put(llc->dev);
4043 + sock_put(sk);
4044 +diff --git a/net/llc/llc_c_ac.c b/net/llc/llc_c_ac.c
4045 +index ea225bd2672c..f8d4ab8ca1a5 100644
4046 +--- a/net/llc/llc_c_ac.c
4047 ++++ b/net/llc/llc_c_ac.c
4048 +@@ -1096,14 +1096,7 @@ int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
4049 +
4050 + int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
4051 + {
4052 +- struct llc_sock *llc = llc_sk(sk);
4053 +-
4054 +- del_timer(&llc->pf_cycle_timer.timer);
4055 +- del_timer(&llc->ack_timer.timer);
4056 +- del_timer(&llc->rej_sent_timer.timer);
4057 +- del_timer(&llc->busy_state_timer.timer);
4058 +- llc->ack_must_be_send = 0;
4059 +- llc->ack_pf = 0;
4060 ++ llc_sk_stop_all_timers(sk, false);
4061 + return 0;
4062 + }
4063 +
4064 +diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c
4065 +index 5e91b47f0d2a..9a42448eb182 100644
4066 +--- a/net/llc/llc_conn.c
4067 ++++ b/net/llc/llc_conn.c
4068 +@@ -951,6 +951,26 @@ struct sock *llc_sk_alloc(struct net *net, int family, gfp_t priority, struct pr
4069 + return sk;
4070 + }
4071 +
4072 ++void llc_sk_stop_all_timers(struct sock *sk, bool sync)
4073 ++{
4074 ++ struct llc_sock *llc = llc_sk(sk);
4075 ++
4076 ++ if (sync) {
4077 ++ del_timer_sync(&llc->pf_cycle_timer.timer);
4078 ++ del_timer_sync(&llc->ack_timer.timer);
4079 ++ del_timer_sync(&llc->rej_sent_timer.timer);
4080 ++ del_timer_sync(&llc->busy_state_timer.timer);
4081 ++ } else {
4082 ++ del_timer(&llc->pf_cycle_timer.timer);
4083 ++ del_timer(&llc->ack_timer.timer);
4084 ++ del_timer(&llc->rej_sent_timer.timer);
4085 ++ del_timer(&llc->busy_state_timer.timer);
4086 ++ }
4087 ++
4088 ++ llc->ack_must_be_send = 0;
4089 ++ llc->ack_pf = 0;
4090 ++}
4091 ++
4092 + /**
4093 + * llc_sk_free - Frees a LLC socket
4094 + * @sk - socket to free
4095 +@@ -963,7 +983,7 @@ void llc_sk_free(struct sock *sk)
4096 +
4097 + llc->state = LLC_CONN_OUT_OF_SVC;
4098 + /* Stop all (possibly) running timers */
4099 +- llc_conn_ac_stop_all_timers(sk, NULL);
4100 ++ llc_sk_stop_all_timers(sk, true);
4101 + #ifdef DEBUG_LLC_CONN_ALLOC
4102 + printk(KERN_INFO "%s: unackq=%d, txq=%d\n", __func__,
4103 + skb_queue_len(&llc->pdu_unack_q),
4104 +diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
4105 +index f4a0587b7d5e..3994b71f8197 100644
4106 +--- a/net/packet/af_packet.c
4107 ++++ b/net/packet/af_packet.c
4108 +@@ -331,11 +331,11 @@ static void packet_pick_tx_queue(struct net_device *dev, struct sk_buff *skb)
4109 + skb_set_queue_mapping(skb, queue_index);
4110 + }
4111 +
4112 +-/* register_prot_hook must be invoked with the po->bind_lock held,
4113 ++/* __register_prot_hook must be invoked through register_prot_hook
4114 + * or from a context in which asynchronous accesses to the packet
4115 + * socket is not possible (packet_create()).
4116 + */
4117 +-static void register_prot_hook(struct sock *sk)
4118 ++static void __register_prot_hook(struct sock *sk)
4119 + {
4120 + struct packet_sock *po = pkt_sk(sk);
4121 +
4122 +@@ -350,8 +350,13 @@ static void register_prot_hook(struct sock *sk)
4123 + }
4124 + }
4125 +
4126 +-/* {,__}unregister_prot_hook() must be invoked with the po->bind_lock
4127 +- * held. If the sync parameter is true, we will temporarily drop
4128 ++static void register_prot_hook(struct sock *sk)
4129 ++{
4130 ++ lockdep_assert_held_once(&pkt_sk(sk)->bind_lock);
4131 ++ __register_prot_hook(sk);
4132 ++}
4133 ++
4134 ++/* If the sync parameter is true, we will temporarily drop
4135 + * the po->bind_lock and do a synchronize_net to make sure no
4136 + * asynchronous packet processing paths still refer to the elements
4137 + * of po->prot_hook. If the sync parameter is false, it is the
4138 +@@ -361,6 +366,8 @@ static void __unregister_prot_hook(struct sock *sk, bool sync)
4139 + {
4140 + struct packet_sock *po = pkt_sk(sk);
4141 +
4142 ++ lockdep_assert_held_once(&po->bind_lock);
4143 ++
4144 + po->running = 0;
4145 +
4146 + if (po->fanout)
4147 +@@ -3017,6 +3024,7 @@ static int packet_release(struct socket *sock)
4148 +
4149 + packet_flush_mclist(sk);
4150 +
4151 ++ lock_sock(sk);
4152 + if (po->rx_ring.pg_vec) {
4153 + memset(&req_u, 0, sizeof(req_u));
4154 + packet_set_ring(sk, &req_u, 1, 0);
4155 +@@ -3026,6 +3034,7 @@ static int packet_release(struct socket *sock)
4156 + memset(&req_u, 0, sizeof(req_u));
4157 + packet_set_ring(sk, &req_u, 1, 1);
4158 + }
4159 ++ release_sock(sk);
4160 +
4161 + f = fanout_release(sk);
4162 +
4163 +@@ -3259,7 +3268,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
4164 +
4165 + if (proto) {
4166 + po->prot_hook.type = proto;
4167 +- register_prot_hook(sk);
4168 ++ __register_prot_hook(sk);
4169 + }
4170 +
4171 + mutex_lock(&net->packet.sklist_lock);
4172 +@@ -3654,6 +3663,7 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
4173 + union tpacket_req_u req_u;
4174 + int len;
4175 +
4176 ++ lock_sock(sk);
4177 + switch (po->tp_version) {
4178 + case TPACKET_V1:
4179 + case TPACKET_V2:
4180 +@@ -3664,12 +3674,17 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
4181 + len = sizeof(req_u.req3);
4182 + break;
4183 + }
4184 +- if (optlen < len)
4185 +- return -EINVAL;
4186 +- if (copy_from_user(&req_u.req, optval, len))
4187 +- return -EFAULT;
4188 +- return packet_set_ring(sk, &req_u, 0,
4189 +- optname == PACKET_TX_RING);
4190 ++ if (optlen < len) {
4191 ++ ret = -EINVAL;
4192 ++ } else {
4193 ++ if (copy_from_user(&req_u.req, optval, len))
4194 ++ ret = -EFAULT;
4195 ++ else
4196 ++ ret = packet_set_ring(sk, &req_u, 0,
4197 ++ optname == PACKET_TX_RING);
4198 ++ }
4199 ++ release_sock(sk);
4200 ++ return ret;
4201 + }
4202 + case PACKET_COPY_THRESH:
4203 + {
4204 +@@ -3735,12 +3750,18 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
4205 +
4206 + if (optlen != sizeof(val))
4207 + return -EINVAL;
4208 +- if (po->rx_ring.pg_vec || po->tx_ring.pg_vec)
4209 +- return -EBUSY;
4210 + if (copy_from_user(&val, optval, sizeof(val)))
4211 + return -EFAULT;
4212 +- po->tp_loss = !!val;
4213 +- return 0;
4214 ++
4215 ++ lock_sock(sk);
4216 ++ if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) {
4217 ++ ret = -EBUSY;
4218 ++ } else {
4219 ++ po->tp_loss = !!val;
4220 ++ ret = 0;
4221 ++ }
4222 ++ release_sock(sk);
4223 ++ return ret;
4224 + }
4225 + case PACKET_AUXDATA:
4226 + {
4227 +@@ -3751,7 +3772,9 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
4228 + if (copy_from_user(&val, optval, sizeof(val)))
4229 + return -EFAULT;
4230 +
4231 ++ lock_sock(sk);
4232 + po->auxdata = !!val;
4233 ++ release_sock(sk);
4234 + return 0;
4235 + }
4236 + case PACKET_ORIGDEV:
4237 +@@ -3763,7 +3786,9 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
4238 + if (copy_from_user(&val, optval, sizeof(val)))
4239 + return -EFAULT;
4240 +
4241 ++ lock_sock(sk);
4242 + po->origdev = !!val;
4243 ++ release_sock(sk);
4244 + return 0;
4245 + }
4246 + case PACKET_VNET_HDR:
4247 +@@ -3772,15 +3797,20 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
4248 +
4249 + if (sock->type != SOCK_RAW)
4250 + return -EINVAL;
4251 +- if (po->rx_ring.pg_vec || po->tx_ring.pg_vec)
4252 +- return -EBUSY;
4253 + if (optlen < sizeof(val))
4254 + return -EINVAL;
4255 + if (copy_from_user(&val, optval, sizeof(val)))
4256 + return -EFAULT;
4257 +
4258 +- po->has_vnet_hdr = !!val;
4259 +- return 0;
4260 ++ lock_sock(sk);
4261 ++ if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) {
4262 ++ ret = -EBUSY;
4263 ++ } else {
4264 ++ po->has_vnet_hdr = !!val;
4265 ++ ret = 0;
4266 ++ }
4267 ++ release_sock(sk);
4268 ++ return ret;
4269 + }
4270 + case PACKET_TIMESTAMP:
4271 + {
4272 +@@ -3818,11 +3848,17 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
4273 +
4274 + if (optlen != sizeof(val))
4275 + return -EINVAL;
4276 +- if (po->rx_ring.pg_vec || po->tx_ring.pg_vec)
4277 +- return -EBUSY;
4278 + if (copy_from_user(&val, optval, sizeof(val)))
4279 + return -EFAULT;
4280 +- po->tp_tx_has_off = !!val;
4281 ++
4282 ++ lock_sock(sk);
4283 ++ if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) {
4284 ++ ret = -EBUSY;
4285 ++ } else {
4286 ++ po->tp_tx_has_off = !!val;
4287 ++ ret = 0;
4288 ++ }
4289 ++ release_sock(sk);
4290 + return 0;
4291 + }
4292 + case PACKET_QDISC_BYPASS:
4293 +@@ -4219,8 +4255,6 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
4294 + /* Added to avoid minimal code churn */
4295 + struct tpacket_req *req = &req_u->req;
4296 +
4297 +- lock_sock(sk);
4298 +-
4299 + rb = tx_ring ? &po->tx_ring : &po->rx_ring;
4300 + rb_queue = tx_ring ? &sk->sk_write_queue : &sk->sk_receive_queue;
4301 +
4302 +@@ -4358,7 +4392,6 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
4303 + if (pg_vec)
4304 + free_pg_vec(pg_vec, order, req->tp_block_nr);
4305 + out:
4306 +- release_sock(sk);
4307 + return err;
4308 + }
4309 +
4310 +diff --git a/net/packet/internal.h b/net/packet/internal.h
4311 +index a1d2b2319ae9..3bb7c5fb3bff 100644
4312 +--- a/net/packet/internal.h
4313 ++++ b/net/packet/internal.h
4314 +@@ -112,10 +112,12 @@ struct packet_sock {
4315 + int copy_thresh;
4316 + spinlock_t bind_lock;
4317 + struct mutex pg_vec_lock;
4318 +- unsigned int running:1, /* prot_hook is attached*/
4319 +- auxdata:1,
4320 ++ unsigned int running; /* bind_lock must be held */
4321 ++ unsigned int auxdata:1, /* writer must hold sock lock */
4322 + origdev:1,
4323 +- has_vnet_hdr:1;
4324 ++ has_vnet_hdr:1,
4325 ++ tp_loss:1,
4326 ++ tp_tx_has_off:1;
4327 + int pressure;
4328 + int ifindex; /* bound device */
4329 + __be16 num;
4330 +@@ -125,8 +127,6 @@ struct packet_sock {
4331 + enum tpacket_versions tp_version;
4332 + unsigned int tp_hdrlen;
4333 + unsigned int tp_reserve;
4334 +- unsigned int tp_loss:1;
4335 +- unsigned int tp_tx_has_off:1;
4336 + unsigned int tp_tstamp;
4337 + struct net_device __rcu *cached_dev;
4338 + int (*xmit)(struct sk_buff *skb);
4339 +diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c
4340 +index 8ccd35825b6b..85757af7f150 100644
4341 +--- a/net/sched/act_ife.c
4342 ++++ b/net/sched/act_ife.c
4343 +@@ -605,7 +605,7 @@ static int find_decode_metaid(struct sk_buff *skb, struct tcf_ife_info *ife,
4344 + }
4345 + }
4346 +
4347 +- return 0;
4348 ++ return -ENOENT;
4349 + }
4350 +
4351 + static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
4352 +@@ -639,7 +639,12 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
4353 + u16 mtype;
4354 + u16 dlen;
4355 +
4356 +- curr_data = ife_tlv_meta_decode(tlv_data, &mtype, &dlen, NULL);
4357 ++ curr_data = ife_tlv_meta_decode(tlv_data, ifehdr_end, &mtype,
4358 ++ &dlen, NULL);
4359 ++ if (!curr_data) {
4360 ++ qstats_drop_inc(this_cpu_ptr(ife->common.cpu_qstats));
4361 ++ return TC_ACT_SHOT;
4362 ++ }
4363 +
4364 + if (find_decode_metaid(skb, ife, mtype, dlen, curr_data)) {
4365 + /* abuse overlimits to count when we receive metadata
4366 +diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
4367 +index 08b5705e7381..7219a1c041f7 100644
4368 +--- a/net/sctp/ipv6.c
4369 ++++ b/net/sctp/ipv6.c
4370 +@@ -521,46 +521,49 @@ static void sctp_v6_to_addr(union sctp_addr *addr, struct in6_addr *saddr,
4371 + addr->v6.sin6_scope_id = 0;
4372 + }
4373 +
4374 +-/* Compare addresses exactly.
4375 +- * v4-mapped-v6 is also in consideration.
4376 +- */
4377 +-static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
4378 +- const union sctp_addr *addr2)
4379 ++static int __sctp_v6_cmp_addr(const union sctp_addr *addr1,
4380 ++ const union sctp_addr *addr2)
4381 + {
4382 + if (addr1->sa.sa_family != addr2->sa.sa_family) {
4383 + if (addr1->sa.sa_family == AF_INET &&
4384 + addr2->sa.sa_family == AF_INET6 &&
4385 +- ipv6_addr_v4mapped(&addr2->v6.sin6_addr)) {
4386 +- if (addr2->v6.sin6_port == addr1->v4.sin_port &&
4387 +- addr2->v6.sin6_addr.s6_addr32[3] ==
4388 +- addr1->v4.sin_addr.s_addr)
4389 +- return 1;
4390 +- }
4391 ++ ipv6_addr_v4mapped(&addr2->v6.sin6_addr) &&
4392 ++ addr2->v6.sin6_addr.s6_addr32[3] ==
4393 ++ addr1->v4.sin_addr.s_addr)
4394 ++ return 1;
4395 ++
4396 + if (addr2->sa.sa_family == AF_INET &&
4397 + addr1->sa.sa_family == AF_INET6 &&
4398 +- ipv6_addr_v4mapped(&addr1->v6.sin6_addr)) {
4399 +- if (addr1->v6.sin6_port == addr2->v4.sin_port &&
4400 +- addr1->v6.sin6_addr.s6_addr32[3] ==
4401 +- addr2->v4.sin_addr.s_addr)
4402 +- return 1;
4403 +- }
4404 ++ ipv6_addr_v4mapped(&addr1->v6.sin6_addr) &&
4405 ++ addr1->v6.sin6_addr.s6_addr32[3] ==
4406 ++ addr2->v4.sin_addr.s_addr)
4407 ++ return 1;
4408 ++
4409 + return 0;
4410 + }
4411 +- if (addr1->v6.sin6_port != addr2->v6.sin6_port)
4412 +- return 0;
4413 ++
4414 + if (!ipv6_addr_equal(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr))
4415 + return 0;
4416 ++
4417 + /* If this is a linklocal address, compare the scope_id. */
4418 +- if (ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) {
4419 +- if (addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id &&
4420 +- (addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)) {
4421 +- return 0;
4422 +- }
4423 +- }
4424 ++ if ((ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) &&
4425 ++ addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id &&
4426 ++ addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)
4427 ++ return 0;
4428 +
4429 + return 1;
4430 + }
4431 +
4432 ++/* Compare addresses exactly.
4433 ++ * v4-mapped-v6 is also in consideration.
4434 ++ */
4435 ++static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
4436 ++ const union sctp_addr *addr2)
4437 ++{
4438 ++ return __sctp_v6_cmp_addr(addr1, addr2) &&
4439 ++ addr1->v6.sin6_port == addr2->v6.sin6_port;
4440 ++}
4441 ++
4442 + /* Initialize addr struct to INADDR_ANY. */
4443 + static void sctp_v6_inaddr_any(union sctp_addr *addr, __be16 port)
4444 + {
4445 +@@ -845,8 +848,8 @@ static int sctp_inet6_cmp_addr(const union sctp_addr *addr1,
4446 + const union sctp_addr *addr2,
4447 + struct sctp_sock *opt)
4448 + {
4449 +- struct sctp_af *af1, *af2;
4450 + struct sock *sk = sctp_opt2sk(opt);
4451 ++ struct sctp_af *af1, *af2;
4452 +
4453 + af1 = sctp_get_af_specific(addr1->sa.sa_family);
4454 + af2 = sctp_get_af_specific(addr2->sa.sa_family);
4455 +@@ -862,10 +865,7 @@ static int sctp_inet6_cmp_addr(const union sctp_addr *addr1,
4456 + if (sctp_is_any(sk, addr1) || sctp_is_any(sk, addr2))
4457 + return 1;
4458 +
4459 +- if (addr1->sa.sa_family != addr2->sa.sa_family)
4460 +- return 0;
4461 +-
4462 +- return af1->cmp_addr(addr1, addr2);
4463 ++ return __sctp_v6_cmp_addr(addr1, addr2);
4464 + }
4465 +
4466 + /* Verify that the provided sockaddr looks bindable. Common verification,
4467 +diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
4468 +index a6d604fd9695..f9c289e05707 100644
4469 +--- a/net/smc/af_smc.c
4470 ++++ b/net/smc/af_smc.c
4471 +@@ -1203,14 +1203,12 @@ static int smc_shutdown(struct socket *sock, int how)
4472 + rc = smc_close_shutdown_write(smc);
4473 + break;
4474 + case SHUT_RD:
4475 +- if (sk->sk_state == SMC_LISTEN)
4476 +- rc = smc_close_active(smc);
4477 +- else
4478 +- rc = 0;
4479 +- /* nothing more to do because peer is not involved */
4480 ++ rc = 0;
4481 ++ /* nothing more to do because peer is not involved */
4482 + break;
4483 + }
4484 +- rc1 = kernel_sock_shutdown(smc->clcsock, how);
4485 ++ if (smc->clcsock)
4486 ++ rc1 = kernel_sock_shutdown(smc->clcsock, how);
4487 + /* map sock_shutdown_cmd constants to sk_shutdown value range */
4488 + sk->sk_shutdown |= how + 1;
4489 +
4490 +diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c
4491 +index 4a3a3f1331ee..c741365f77da 100644
4492 +--- a/net/strparser/strparser.c
4493 ++++ b/net/strparser/strparser.c
4494 +@@ -67,7 +67,7 @@ static void strp_abort_strp(struct strparser *strp, int err)
4495 +
4496 + static void strp_start_timer(struct strparser *strp, long timeo)
4497 + {
4498 +- if (timeo)
4499 ++ if (timeo && timeo != LONG_MAX)
4500 + mod_delayed_work(strp_wq, &strp->msg_timer_work, timeo);
4501 + }
4502 +
4503 +@@ -296,9 +296,9 @@ static int __strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb,
4504 + strp_start_timer(strp, timeo);
4505 + }
4506 +
4507 ++ stm->accum_len += cand_len;
4508 + strp->need_bytes = stm->strp.full_len -
4509 + stm->accum_len;
4510 +- stm->accum_len += cand_len;
4511 + stm->early_eaten = cand_len;
4512 + STRP_STATS_ADD(strp->stats.bytes, cand_len);
4513 + desc->count = 0; /* Stop reading socket */
4514 +@@ -321,6 +321,7 @@ static int __strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb,
4515 + /* Hurray, we have a new message! */
4516 + cancel_delayed_work(&strp->msg_timer_work);
4517 + strp->skb_head = NULL;
4518 ++ strp->need_bytes = 0;
4519 + STRP_STATS_INCR(strp->stats.msgs);
4520 +
4521 + /* Give skb to upper layer */
4522 +@@ -410,9 +411,7 @@ void strp_data_ready(struct strparser *strp)
4523 + return;
4524 +
4525 + if (strp->need_bytes) {
4526 +- if (strp_peek_len(strp) >= strp->need_bytes)
4527 +- strp->need_bytes = 0;
4528 +- else
4529 ++ if (strp_peek_len(strp) < strp->need_bytes)
4530 + return;
4531 + }
4532 +
4533 +diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
4534 +index b76f13f6fea1..d4e0bbeee727 100644
4535 +--- a/net/tipc/netlink.c
4536 ++++ b/net/tipc/netlink.c
4537 +@@ -79,7 +79,8 @@ const struct nla_policy tipc_nl_sock_policy[TIPC_NLA_SOCK_MAX + 1] = {
4538 +
4539 + const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = {
4540 + [TIPC_NLA_NET_UNSPEC] = { .type = NLA_UNSPEC },
4541 +- [TIPC_NLA_NET_ID] = { .type = NLA_U32 }
4542 ++ [TIPC_NLA_NET_ID] = { .type = NLA_U32 },
4543 ++ [TIPC_NLA_NET_ADDR] = { .type = NLA_U32 },
4544 + };
4545 +
4546 + const struct nla_policy tipc_nl_link_policy[TIPC_NLA_LINK_MAX + 1] = {
4547 +diff --git a/security/commoncap.c b/security/commoncap.c
4548 +index 7b01431d1e19..1c1f64582bb5 100644
4549 +--- a/security/commoncap.c
4550 ++++ b/security/commoncap.c
4551 +@@ -449,6 +449,8 @@ int cap_inode_getsecurity(struct inode *inode, const char *name, void **buffer,
4552 + magic |= VFS_CAP_FLAGS_EFFECTIVE;
4553 + memcpy(&cap->data, &nscap->data, sizeof(__le32) * 2 * VFS_CAP_U32);
4554 + cap->magic_etc = cpu_to_le32(magic);
4555 ++ } else {
4556 ++ size = -ENOMEM;
4557 + }
4558 + }
4559 + kfree(tmpbuf);