Magellan Linux

Contents of /trunk/kernel-alx/patches-4.9/0280-4.9.181-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3357 - (show annotations) (download)
Tue Jun 18 09:42:10 2019 UTC (4 years, 10 months ago) by niro
File size: 125350 byte(s)
-linux-4.9.181
1 diff --git a/Documentation/conf.py b/Documentation/conf.py
2 index d769cd89a9f7..da7b54388eff 100644
3 --- a/Documentation/conf.py
4 +++ b/Documentation/conf.py
5 @@ -37,7 +37,7 @@ from load_config import loadConfig
6 extensions = ['kernel-doc', 'rstFlatTable', 'kernel_include', 'cdomain']
7
8 # The name of the math extension changed on Sphinx 1.4
9 -if major == 1 and minor > 3:
10 +if (major == 1 and minor > 3) or (major > 1):
11 extensions.append("sphinx.ext.imgmath")
12 else:
13 extensions.append("sphinx.ext.pngmath")
14 diff --git a/Makefile b/Makefile
15 index 0b996e9d2c5f..584af2e57735 100644
16 --- a/Makefile
17 +++ b/Makefile
18 @@ -1,6 +1,6 @@
19 VERSION = 4
20 PATCHLEVEL = 9
21 -SUBLEVEL = 180
22 +SUBLEVEL = 181
23 EXTRAVERSION =
24 NAME = Roaring Lionus
25
26 diff --git a/arch/mips/ath79/setup.c b/arch/mips/ath79/setup.c
27 index c7c31e214813..26a058d58d37 100644
28 --- a/arch/mips/ath79/setup.c
29 +++ b/arch/mips/ath79/setup.c
30 @@ -183,6 +183,12 @@ const char *get_system_type(void)
31 return ath79_sys_type;
32 }
33
34 +int get_c0_perfcount_int(void)
35 +{
36 + return ATH79_MISC_IRQ(5);
37 +}
38 +EXPORT_SYMBOL_GPL(get_c0_perfcount_int);
39 +
40 unsigned int get_c0_compare_int(void)
41 {
42 return CP0_LEGACY_COMPARE_IRQ;
43 diff --git a/arch/mips/pistachio/Platform b/arch/mips/pistachio/Platform
44 index d80cd612df1f..c3592b374ad2 100644
45 --- a/arch/mips/pistachio/Platform
46 +++ b/arch/mips/pistachio/Platform
47 @@ -6,3 +6,4 @@ cflags-$(CONFIG_MACH_PISTACHIO) += \
48 -I$(srctree)/arch/mips/include/asm/mach-pistachio
49 load-$(CONFIG_MACH_PISTACHIO) += 0xffffffff80400000
50 zload-$(CONFIG_MACH_PISTACHIO) += 0xffffffff81000000
51 +all-$(CONFIG_MACH_PISTACHIO) := uImage.gz
52 diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
53 index 771edffa2d40..ba49ae6625f1 100644
54 --- a/arch/powerpc/perf/core-book3s.c
55 +++ b/arch/powerpc/perf/core-book3s.c
56 @@ -1800,6 +1800,7 @@ static int power_pmu_event_init(struct perf_event *event)
57 int n;
58 int err;
59 struct cpu_hw_events *cpuhw;
60 + u64 bhrb_filter;
61
62 if (!ppmu)
63 return -ENOENT;
64 @@ -1896,13 +1897,14 @@ static int power_pmu_event_init(struct perf_event *event)
65 err = power_check_constraints(cpuhw, events, cflags, n + 1);
66
67 if (has_branch_stack(event)) {
68 - cpuhw->bhrb_filter = ppmu->bhrb_filter_map(
69 + bhrb_filter = ppmu->bhrb_filter_map(
70 event->attr.branch_sample_type);
71
72 - if (cpuhw->bhrb_filter == -1) {
73 + if (bhrb_filter == -1) {
74 put_cpu_var(cpu_hw_events);
75 return -EOPNOTSUPP;
76 }
77 + cpuhw->bhrb_filter = bhrb_filter;
78 }
79
80 put_cpu_var(cpu_hw_events);
81 diff --git a/arch/powerpc/perf/power8-pmu.c b/arch/powerpc/perf/power8-pmu.c
82 index ab830d106ec5..5fbd9bdefa4e 100644
83 --- a/arch/powerpc/perf/power8-pmu.c
84 +++ b/arch/powerpc/perf/power8-pmu.c
85 @@ -29,6 +29,7 @@ enum {
86 #define POWER8_MMCRA_IFM1 0x0000000040000000UL
87 #define POWER8_MMCRA_IFM2 0x0000000080000000UL
88 #define POWER8_MMCRA_IFM3 0x00000000C0000000UL
89 +#define POWER8_MMCRA_BHRB_MASK 0x00000000C0000000UL
90
91 /* Table of alternatives, sorted by column 0 */
92 static const unsigned int event_alternatives[][MAX_ALT] = {
93 @@ -262,6 +263,8 @@ static u64 power8_bhrb_filter_map(u64 branch_sample_type)
94
95 static void power8_config_bhrb(u64 pmu_bhrb_filter)
96 {
97 + pmu_bhrb_filter &= POWER8_MMCRA_BHRB_MASK;
98 +
99 /* Enable BHRB filter in PMU */
100 mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter));
101 }
102 diff --git a/arch/powerpc/perf/power9-pmu.c b/arch/powerpc/perf/power9-pmu.c
103 index 9abcd8f65504..c396d5e5098c 100644
104 --- a/arch/powerpc/perf/power9-pmu.c
105 +++ b/arch/powerpc/perf/power9-pmu.c
106 @@ -30,6 +30,7 @@ enum {
107 #define POWER9_MMCRA_IFM1 0x0000000040000000UL
108 #define POWER9_MMCRA_IFM2 0x0000000080000000UL
109 #define POWER9_MMCRA_IFM3 0x00000000C0000000UL
110 +#define POWER9_MMCRA_BHRB_MASK 0x00000000C0000000UL
111
112 GENERIC_EVENT_ATTR(cpu-cycles, PM_CYC);
113 GENERIC_EVENT_ATTR(stalled-cycles-frontend, PM_ICT_NOSLOT_CYC);
114 @@ -177,6 +178,8 @@ static u64 power9_bhrb_filter_map(u64 branch_sample_type)
115
116 static void power9_config_bhrb(u64 pmu_bhrb_filter)
117 {
118 + pmu_bhrb_filter &= POWER9_MMCRA_BHRB_MASK;
119 +
120 /* Enable BHRB filter in PMU */
121 mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter));
122 }
123 diff --git a/arch/sparc/mm/ultra.S b/arch/sparc/mm/ultra.S
124 index fcf4d27a38fb..e09f7b440b8c 100644
125 --- a/arch/sparc/mm/ultra.S
126 +++ b/arch/sparc/mm/ultra.S
127 @@ -586,7 +586,7 @@ xcall_flush_tlb_kernel_range: /* 44 insns */
128 sub %g7, %g1, %g3
129 srlx %g3, 18, %g2
130 brnz,pn %g2, 2f
131 - add %g2, 1, %g2
132 + sethi %hi(PAGE_SIZE), %g2
133 sub %g3, %g2, %g3
134 or %g1, 0x20, %g1 ! Nucleus
135 1: stxa %g0, [%g1 + %g3] ASI_DMMU_DEMAP
136 @@ -750,7 +750,7 @@ __cheetah_xcall_flush_tlb_kernel_range: /* 44 insns */
137 sub %g7, %g1, %g3
138 srlx %g3, 18, %g2
139 brnz,pn %g2, 2f
140 - add %g2, 1, %g2
141 + sethi %hi(PAGE_SIZE), %g2
142 sub %g3, %g2, %g3
143 or %g1, 0x20, %g1 ! Nucleus
144 1: stxa %g0, [%g1 + %g3] ASI_DMMU_DEMAP
145 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
146 index 51b772f9d886..55f04875293f 100644
147 --- a/arch/x86/kernel/vmlinux.lds.S
148 +++ b/arch/x86/kernel/vmlinux.lds.S
149 @@ -111,10 +111,10 @@ SECTIONS
150 *(.text.__x86.indirect_thunk)
151 __indirect_thunk_end = .;
152 #endif
153 - } :text = 0x9090
154
155 - /* End of text section */
156 - _etext = .;
157 + /* End of text section */
158 + _etext = .;
159 + } :text = 0x9090
160
161 NOTES :text :note
162
163 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
164 index 054e27671df9..29dc59baf0c2 100644
165 --- a/arch/x86/power/cpu.c
166 +++ b/arch/x86/power/cpu.c
167 @@ -292,7 +292,17 @@ int hibernate_resume_nonboot_cpu_disable(void)
168 * address in its instruction pointer may not be possible to resolve
169 * any more at that point (the page tables used by it previously may
170 * have been overwritten by hibernate image data).
171 + *
172 + * First, make sure that we wake up all the potentially disabled SMT
173 + * threads which have been initially brought up and then put into
174 + * mwait/cpuidle sleep.
175 + * Those will be put to proper (not interfering with hibernation
176 + * resume) sleep afterwards, and the resumed kernel will decide itself
177 + * what to do with them.
178 */
179 + ret = cpuhp_smt_enable();
180 + if (ret)
181 + return ret;
182 smp_ops.play_dead = resume_play_dead;
183 ret = disable_nonboot_cpus();
184 smp_ops.play_dead = play_dead;
185 diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c
186 index fef485b789ca..6120046bb7dd 100644
187 --- a/arch/x86/power/hibernate_64.c
188 +++ b/arch/x86/power/hibernate_64.c
189 @@ -11,6 +11,7 @@
190 #include <linux/gfp.h>
191 #include <linux/smp.h>
192 #include <linux/suspend.h>
193 +#include <linux/cpu.h>
194
195 #include <asm/init.h>
196 #include <asm/proto.h>
197 @@ -218,3 +219,35 @@ int arch_hibernation_header_restore(void *addr)
198 restore_cr3 = rdr->cr3;
199 return (rdr->magic == RESTORE_MAGIC) ? 0 : -EINVAL;
200 }
201 +
202 +int arch_resume_nosmt(void)
203 +{
204 + int ret = 0;
205 + /*
206 + * We reached this while coming out of hibernation. This means
207 + * that SMT siblings are sleeping in hlt, as mwait is not safe
208 + * against control transition during resume (see comment in
209 + * hibernate_resume_nonboot_cpu_disable()).
210 + *
211 + * If the resumed kernel has SMT disabled, we have to take all the
212 + * SMT siblings out of hlt, and offline them again so that they
213 + * end up in mwait proper.
214 + *
215 + * Called with hotplug disabled.
216 + */
217 + cpu_hotplug_enable();
218 + if (cpu_smt_control == CPU_SMT_DISABLED ||
219 + cpu_smt_control == CPU_SMT_FORCE_DISABLED) {
220 + enum cpuhp_smt_control old = cpu_smt_control;
221 +
222 + ret = cpuhp_smt_enable();
223 + if (ret)
224 + goto out;
225 + ret = cpuhp_smt_disable(old);
226 + if (ret)
227 + goto out;
228 + }
229 +out:
230 + cpu_hotplug_disable();
231 + return ret;
232 +}
233 diff --git a/drivers/android/binder.c b/drivers/android/binder.c
234 index 80499f421a29..29632a6dd1c6 100644
235 --- a/drivers/android/binder.c
236 +++ b/drivers/android/binder.c
237 @@ -488,7 +488,7 @@ static void binder_insert_free_buffer(struct binder_proc *proc,
238 new_buffer_size = binder_buffer_size(proc, new_buffer);
239
240 binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
241 - "%d: add free buffer, size %zd, at %p\n",
242 + "%d: add free buffer, size %zd, at %pK\n",
243 proc->pid, new_buffer_size, new_buffer);
244
245 while (*p) {
246 @@ -566,7 +566,7 @@ static int binder_update_page_range(struct binder_proc *proc, int allocate,
247 struct mm_struct *mm;
248
249 binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
250 - "%d: %s pages %p-%p\n", proc->pid,
251 + "%d: %s pages %pK-%pK\n", proc->pid,
252 allocate ? "allocate" : "free", start, end);
253
254 if (end <= start)
255 @@ -606,7 +606,7 @@ static int binder_update_page_range(struct binder_proc *proc, int allocate,
256 BUG_ON(*page);
257 *page = alloc_page(GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
258 if (*page == NULL) {
259 - pr_err("%d: binder_alloc_buf failed for page at %p\n",
260 + pr_err("%d: binder_alloc_buf failed for page at %pK\n",
261 proc->pid, page_addr);
262 goto err_alloc_page_failed;
263 }
264 @@ -615,7 +615,7 @@ static int binder_update_page_range(struct binder_proc *proc, int allocate,
265 flush_cache_vmap((unsigned long)page_addr,
266 (unsigned long)page_addr + PAGE_SIZE);
267 if (ret != 1) {
268 - pr_err("%d: binder_alloc_buf failed to map page at %p in kernel\n",
269 + pr_err("%d: binder_alloc_buf failed to map page at %pK in kernel\n",
270 proc->pid, page_addr);
271 goto err_map_kernel_failed;
272 }
273 @@ -719,7 +719,7 @@ static struct binder_buffer *binder_alloc_buf(struct binder_proc *proc,
274 }
275
276 binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
277 - "%d: binder_alloc_buf size %zd got buffer %p size %zd\n",
278 + "%d: binder_alloc_buf size %zd got buffer %pK size %zd\n",
279 proc->pid, size, buffer, buffer_size);
280
281 has_page_addr =
282 @@ -749,7 +749,7 @@ static struct binder_buffer *binder_alloc_buf(struct binder_proc *proc,
283 binder_insert_free_buffer(proc, new_buffer);
284 }
285 binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
286 - "%d: binder_alloc_buf size %zd got %p\n",
287 + "%d: binder_alloc_buf size %zd got %pK\n",
288 proc->pid, size, buffer);
289 buffer->data_size = data_size;
290 buffer->offsets_size = offsets_size;
291 @@ -789,7 +789,7 @@ static void binder_delete_free_buffer(struct binder_proc *proc,
292 if (buffer_end_page(prev) == buffer_end_page(buffer))
293 free_page_end = 0;
294 binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
295 - "%d: merge free, buffer %p share page with %p\n",
296 + "%d: merge free, buffer %pK share page with %pK\n",
297 proc->pid, buffer, prev);
298 }
299
300 @@ -802,14 +802,14 @@ static void binder_delete_free_buffer(struct binder_proc *proc,
301 buffer_start_page(buffer))
302 free_page_start = 0;
303 binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
304 - "%d: merge free, buffer %p share page with %p\n",
305 + "%d: merge free, buffer %pK share page with %pK\n",
306 proc->pid, buffer, prev);
307 }
308 }
309 list_del(&buffer->entry);
310 if (free_page_start || free_page_end) {
311 binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
312 - "%d: merge free, buffer %p do not share page%s%s with %p or %p\n",
313 + "%d: merge free, buffer %pK do not share page%s%s with %pK or %pK\n",
314 proc->pid, buffer, free_page_start ? "" : " end",
315 free_page_end ? "" : " start", prev, next);
316 binder_update_page_range(proc, 0, free_page_start ?
317 @@ -830,7 +830,7 @@ static void binder_free_buf(struct binder_proc *proc,
318 ALIGN(buffer->offsets_size, sizeof(void *));
319
320 binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
321 - "%d: binder_free_buf %p size %zd buffer_size %zd\n",
322 + "%d: binder_free_buf %pK size %zd buffer_size %zd\n",
323 proc->pid, buffer, size, buffer_size);
324
325 BUG_ON(buffer->free);
326 @@ -1260,7 +1260,7 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
327 int debug_id = buffer->debug_id;
328
329 binder_debug(BINDER_DEBUG_TRANSACTION,
330 - "%d buffer release %d, size %zd-%zd, failed at %p\n",
331 + "%d buffer release %d, size %zd-%zd, failed at %pK\n",
332 proc->pid, buffer->debug_id,
333 buffer->data_size, buffer->offsets_size, failed_at);
334
335 @@ -2123,7 +2123,7 @@ static int binder_thread_write(struct binder_proc *proc,
336 }
337 }
338 binder_debug(BINDER_DEBUG_DEAD_BINDER,
339 - "%d:%d BC_DEAD_BINDER_DONE %016llx found %p\n",
340 + "%d:%d BC_DEAD_BINDER_DONE %016llx found %pK\n",
341 proc->pid, thread->pid, (u64)cookie,
342 death);
343 if (death == NULL) {
344 @@ -2930,7 +2930,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
345 #ifdef CONFIG_CPU_CACHE_VIPT
346 if (cache_is_vipt_aliasing()) {
347 while (CACHE_COLOUR((vma->vm_start ^ (uint32_t)proc->buffer))) {
348 - pr_info("binder_mmap: %d %lx-%lx maps %p bad alignment\n", proc->pid, vma->vm_start, vma->vm_end, proc->buffer);
349 + pr_info("binder_mmap: %d %lx-%lx maps %pK bad alignment\n", proc->pid, vma->vm_start, vma->vm_end, proc->buffer);
350 vma->vm_start += PAGE_SIZE;
351 }
352 }
353 @@ -3191,7 +3191,7 @@ static void binder_deferred_release(struct binder_proc *proc)
354
355 page_addr = proc->buffer + i * PAGE_SIZE;
356 binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
357 - "%s: %d: page %d at %p not freed\n",
358 + "%s: %d: page %d at %pK not freed\n",
359 __func__, proc->pid, i, page_addr);
360 unmap_kernel_range((unsigned long)page_addr, PAGE_SIZE);
361 __free_page(proc->pages[i]);
362 @@ -3272,7 +3272,7 @@ static void print_binder_transaction(struct seq_file *m, const char *prefix,
363 struct binder_transaction *t)
364 {
365 seq_printf(m,
366 - "%s %d: %p from %d:%d to %d:%d code %x flags %x pri %ld r%d",
367 + "%s %d: %pK from %d:%d to %d:%d code %x flags %x pri %ld r%d",
368 prefix, t->debug_id, t,
369 t->from ? t->from->proc->pid : 0,
370 t->from ? t->from->pid : 0,
371 @@ -3286,7 +3286,7 @@ static void print_binder_transaction(struct seq_file *m, const char *prefix,
372 if (t->buffer->target_node)
373 seq_printf(m, " node %d",
374 t->buffer->target_node->debug_id);
375 - seq_printf(m, " size %zd:%zd data %p\n",
376 + seq_printf(m, " size %zd:%zd data %pK\n",
377 t->buffer->data_size, t->buffer->offsets_size,
378 t->buffer->data);
379 }
380 @@ -3294,7 +3294,7 @@ static void print_binder_transaction(struct seq_file *m, const char *prefix,
381 static void print_binder_buffer(struct seq_file *m, const char *prefix,
382 struct binder_buffer *buffer)
383 {
384 - seq_printf(m, "%s %d: %p size %zd:%zd %s\n",
385 + seq_printf(m, "%s %d: %pK size %zd:%zd %s\n",
386 prefix, buffer->debug_id, buffer->data,
387 buffer->data_size, buffer->offsets_size,
388 buffer->transaction ? "active" : "delivered");
389 @@ -3397,7 +3397,7 @@ static void print_binder_node(struct seq_file *m, struct binder_node *node)
390
391 static void print_binder_ref(struct seq_file *m, struct binder_ref *ref)
392 {
393 - seq_printf(m, " ref %d: desc %d %snode %d s %d w %d d %p\n",
394 + seq_printf(m, " ref %d: desc %d %snode %d s %d w %d d %pK\n",
395 ref->debug_id, ref->desc, ref->node->proc ? "" : "dead ",
396 ref->node->debug_id, ref->strong, ref->weak, ref->death);
397 }
398 diff --git a/drivers/crypto/vmx/ghash.c b/drivers/crypto/vmx/ghash.c
399 index 1c4b5b889fba..1bfe867c0b7b 100644
400 --- a/drivers/crypto/vmx/ghash.c
401 +++ b/drivers/crypto/vmx/ghash.c
402 @@ -1,22 +1,14 @@
403 +// SPDX-License-Identifier: GPL-2.0
404 /**
405 * GHASH routines supporting VMX instructions on the Power 8
406 *
407 - * Copyright (C) 2015 International Business Machines Inc.
408 - *
409 - * This program is free software; you can redistribute it and/or modify
410 - * it under the terms of the GNU General Public License as published by
411 - * the Free Software Foundation; version 2 only.
412 - *
413 - * This program is distributed in the hope that it will be useful,
414 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
415 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
416 - * GNU General Public License for more details.
417 - *
418 - * You should have received a copy of the GNU General Public License
419 - * along with this program; if not, write to the Free Software
420 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
421 + * Copyright (C) 2015, 2019 International Business Machines Inc.
422 *
423 * Author: Marcelo Henrique Cerri <mhcerri@br.ibm.com>
424 + *
425 + * Extended by Daniel Axtens <dja@axtens.net> to replace the fallback
426 + * mechanism. The new approach is based on arm64 code, which is:
427 + * Copyright (C) 2014 - 2018 Linaro Ltd. <ard.biesheuvel@linaro.org>
428 */
429
430 #include <linux/types.h>
431 @@ -39,71 +31,25 @@ void gcm_ghash_p8(u64 Xi[2], const u128 htable[16],
432 const u8 *in, size_t len);
433
434 struct p8_ghash_ctx {
435 + /* key used by vector asm */
436 u128 htable[16];
437 - struct crypto_shash *fallback;
438 + /* key used by software fallback */
439 + be128 key;
440 };
441
442 struct p8_ghash_desc_ctx {
443 u64 shash[2];
444 u8 buffer[GHASH_DIGEST_SIZE];
445 int bytes;
446 - struct shash_desc fallback_desc;
447 };
448
449 -static int p8_ghash_init_tfm(struct crypto_tfm *tfm)
450 -{
451 - const char *alg = "ghash-generic";
452 - struct crypto_shash *fallback;
453 - struct crypto_shash *shash_tfm = __crypto_shash_cast(tfm);
454 - struct p8_ghash_ctx *ctx = crypto_tfm_ctx(tfm);
455 -
456 - fallback = crypto_alloc_shash(alg, 0, CRYPTO_ALG_NEED_FALLBACK);
457 - if (IS_ERR(fallback)) {
458 - printk(KERN_ERR
459 - "Failed to allocate transformation for '%s': %ld\n",
460 - alg, PTR_ERR(fallback));
461 - return PTR_ERR(fallback);
462 - }
463 -
464 - crypto_shash_set_flags(fallback,
465 - crypto_shash_get_flags((struct crypto_shash
466 - *) tfm));
467 -
468 - /* Check if the descsize defined in the algorithm is still enough. */
469 - if (shash_tfm->descsize < sizeof(struct p8_ghash_desc_ctx)
470 - + crypto_shash_descsize(fallback)) {
471 - printk(KERN_ERR
472 - "Desc size of the fallback implementation (%s) does not match the expected value: %lu vs %u\n",
473 - alg,
474 - shash_tfm->descsize - sizeof(struct p8_ghash_desc_ctx),
475 - crypto_shash_descsize(fallback));
476 - return -EINVAL;
477 - }
478 - ctx->fallback = fallback;
479 -
480 - return 0;
481 -}
482 -
483 -static void p8_ghash_exit_tfm(struct crypto_tfm *tfm)
484 -{
485 - struct p8_ghash_ctx *ctx = crypto_tfm_ctx(tfm);
486 -
487 - if (ctx->fallback) {
488 - crypto_free_shash(ctx->fallback);
489 - ctx->fallback = NULL;
490 - }
491 -}
492 -
493 static int p8_ghash_init(struct shash_desc *desc)
494 {
495 - struct p8_ghash_ctx *ctx = crypto_tfm_ctx(crypto_shash_tfm(desc->tfm));
496 struct p8_ghash_desc_ctx *dctx = shash_desc_ctx(desc);
497
498 dctx->bytes = 0;
499 memset(dctx->shash, 0, GHASH_DIGEST_SIZE);
500 - dctx->fallback_desc.tfm = ctx->fallback;
501 - dctx->fallback_desc.flags = desc->flags;
502 - return crypto_shash_init(&dctx->fallback_desc);
503 + return 0;
504 }
505
506 static int p8_ghash_setkey(struct crypto_shash *tfm, const u8 *key,
507 @@ -121,7 +67,51 @@ static int p8_ghash_setkey(struct crypto_shash *tfm, const u8 *key,
508 disable_kernel_vsx();
509 pagefault_enable();
510 preempt_enable();
511 - return crypto_shash_setkey(ctx->fallback, key, keylen);
512 +
513 + memcpy(&ctx->key, key, GHASH_BLOCK_SIZE);
514 +
515 + return 0;
516 +}
517 +
518 +static inline void __ghash_block(struct p8_ghash_ctx *ctx,
519 + struct p8_ghash_desc_ctx *dctx)
520 +{
521 + if (!IN_INTERRUPT) {
522 + preempt_disable();
523 + pagefault_disable();
524 + enable_kernel_vsx();
525 + gcm_ghash_p8(dctx->shash, ctx->htable,
526 + dctx->buffer, GHASH_DIGEST_SIZE);
527 + disable_kernel_vsx();
528 + pagefault_enable();
529 + preempt_enable();
530 + } else {
531 + crypto_xor((u8 *)dctx->shash, dctx->buffer, GHASH_BLOCK_SIZE);
532 + gf128mul_lle((be128 *)dctx->shash, &ctx->key);
533 + }
534 +}
535 +
536 +static inline void __ghash_blocks(struct p8_ghash_ctx *ctx,
537 + struct p8_ghash_desc_ctx *dctx,
538 + const u8 *src, unsigned int srclen)
539 +{
540 + if (!IN_INTERRUPT) {
541 + preempt_disable();
542 + pagefault_disable();
543 + enable_kernel_vsx();
544 + gcm_ghash_p8(dctx->shash, ctx->htable,
545 + src, srclen);
546 + disable_kernel_vsx();
547 + pagefault_enable();
548 + preempt_enable();
549 + } else {
550 + while (srclen >= GHASH_BLOCK_SIZE) {
551 + crypto_xor((u8 *)dctx->shash, src, GHASH_BLOCK_SIZE);
552 + gf128mul_lle((be128 *)dctx->shash, &ctx->key);
553 + srclen -= GHASH_BLOCK_SIZE;
554 + src += GHASH_BLOCK_SIZE;
555 + }
556 + }
557 }
558
559 static int p8_ghash_update(struct shash_desc *desc,
560 @@ -131,49 +121,33 @@ static int p8_ghash_update(struct shash_desc *desc,
561 struct p8_ghash_ctx *ctx = crypto_tfm_ctx(crypto_shash_tfm(desc->tfm));
562 struct p8_ghash_desc_ctx *dctx = shash_desc_ctx(desc);
563
564 - if (IN_INTERRUPT) {
565 - return crypto_shash_update(&dctx->fallback_desc, src,
566 - srclen);
567 - } else {
568 - if (dctx->bytes) {
569 - if (dctx->bytes + srclen < GHASH_DIGEST_SIZE) {
570 - memcpy(dctx->buffer + dctx->bytes, src,
571 - srclen);
572 - dctx->bytes += srclen;
573 - return 0;
574 - }
575 + if (dctx->bytes) {
576 + if (dctx->bytes + srclen < GHASH_DIGEST_SIZE) {
577 memcpy(dctx->buffer + dctx->bytes, src,
578 - GHASH_DIGEST_SIZE - dctx->bytes);
579 - preempt_disable();
580 - pagefault_disable();
581 - enable_kernel_vsx();
582 - gcm_ghash_p8(dctx->shash, ctx->htable,
583 - dctx->buffer, GHASH_DIGEST_SIZE);
584 - disable_kernel_vsx();
585 - pagefault_enable();
586 - preempt_enable();
587 - src += GHASH_DIGEST_SIZE - dctx->bytes;
588 - srclen -= GHASH_DIGEST_SIZE - dctx->bytes;
589 - dctx->bytes = 0;
590 - }
591 - len = srclen & ~(GHASH_DIGEST_SIZE - 1);
592 - if (len) {
593 - preempt_disable();
594 - pagefault_disable();
595 - enable_kernel_vsx();
596 - gcm_ghash_p8(dctx->shash, ctx->htable, src, len);
597 - disable_kernel_vsx();
598 - pagefault_enable();
599 - preempt_enable();
600 - src += len;
601 - srclen -= len;
602 - }
603 - if (srclen) {
604 - memcpy(dctx->buffer, src, srclen);
605 - dctx->bytes = srclen;
606 + srclen);
607 + dctx->bytes += srclen;
608 + return 0;
609 }
610 - return 0;
611 + memcpy(dctx->buffer + dctx->bytes, src,
612 + GHASH_DIGEST_SIZE - dctx->bytes);
613 +
614 + __ghash_block(ctx, dctx);
615 +
616 + src += GHASH_DIGEST_SIZE - dctx->bytes;
617 + srclen -= GHASH_DIGEST_SIZE - dctx->bytes;
618 + dctx->bytes = 0;
619 + }
620 + len = srclen & ~(GHASH_DIGEST_SIZE - 1);
621 + if (len) {
622 + __ghash_blocks(ctx, dctx, src, len);
623 + src += len;
624 + srclen -= len;
625 }
626 + if (srclen) {
627 + memcpy(dctx->buffer, src, srclen);
628 + dctx->bytes = srclen;
629 + }
630 + return 0;
631 }
632
633 static int p8_ghash_final(struct shash_desc *desc, u8 *out)
634 @@ -182,25 +156,14 @@ static int p8_ghash_final(struct shash_desc *desc, u8 *out)
635 struct p8_ghash_ctx *ctx = crypto_tfm_ctx(crypto_shash_tfm(desc->tfm));
636 struct p8_ghash_desc_ctx *dctx = shash_desc_ctx(desc);
637
638 - if (IN_INTERRUPT) {
639 - return crypto_shash_final(&dctx->fallback_desc, out);
640 - } else {
641 - if (dctx->bytes) {
642 - for (i = dctx->bytes; i < GHASH_DIGEST_SIZE; i++)
643 - dctx->buffer[i] = 0;
644 - preempt_disable();
645 - pagefault_disable();
646 - enable_kernel_vsx();
647 - gcm_ghash_p8(dctx->shash, ctx->htable,
648 - dctx->buffer, GHASH_DIGEST_SIZE);
649 - disable_kernel_vsx();
650 - pagefault_enable();
651 - preempt_enable();
652 - dctx->bytes = 0;
653 - }
654 - memcpy(out, dctx->shash, GHASH_DIGEST_SIZE);
655 - return 0;
656 + if (dctx->bytes) {
657 + for (i = dctx->bytes; i < GHASH_DIGEST_SIZE; i++)
658 + dctx->buffer[i] = 0;
659 + __ghash_block(ctx, dctx);
660 + dctx->bytes = 0;
661 }
662 + memcpy(out, dctx->shash, GHASH_DIGEST_SIZE);
663 + return 0;
664 }
665
666 struct shash_alg p8_ghash_alg = {
667 @@ -215,11 +178,9 @@ struct shash_alg p8_ghash_alg = {
668 .cra_name = "ghash",
669 .cra_driver_name = "p8_ghash",
670 .cra_priority = 1000,
671 - .cra_flags = CRYPTO_ALG_TYPE_SHASH | CRYPTO_ALG_NEED_FALLBACK,
672 + .cra_flags = CRYPTO_ALG_TYPE_SHASH,
673 .cra_blocksize = GHASH_BLOCK_SIZE,
674 .cra_ctxsize = sizeof(struct p8_ghash_ctx),
675 .cra_module = THIS_MODULE,
676 - .cra_init = p8_ghash_init_tfm,
677 - .cra_exit = p8_ghash_exit_tfm,
678 },
679 };
680 diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c
681 index 993aa56755f6..726d1467b778 100644
682 --- a/drivers/firmware/efi/libstub/arm-stub.c
683 +++ b/drivers/firmware/efi/libstub/arm-stub.c
684 @@ -18,7 +18,6 @@
685
686 #include "efistub.h"
687
688 -bool __nokaslr;
689
690 static int efi_get_secureboot(efi_system_table_t *sys_table_arg)
691 {
692 @@ -268,18 +267,6 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
693 goto fail;
694 }
695
696 - /* check whether 'nokaslr' was passed on the command line */
697 - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
698 - static const u8 default_cmdline[] = CONFIG_CMDLINE;
699 - const u8 *str, *cmdline = cmdline_ptr;
700 -
701 - if (IS_ENABLED(CONFIG_CMDLINE_FORCE))
702 - cmdline = default_cmdline;
703 - str = strstr(cmdline, "nokaslr");
704 - if (str == cmdline || (str > cmdline && *(str - 1) == ' '))
705 - __nokaslr = true;
706 - }
707 -
708 si = setup_graphics(sys_table);
709
710 status = handle_kernel_image(sys_table, image_addr, &image_size,
711 @@ -291,9 +278,13 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
712 goto fail_free_cmdline;
713 }
714
715 - status = efi_parse_options(cmdline_ptr);
716 - if (status != EFI_SUCCESS)
717 - pr_efi_err(sys_table, "Failed to parse EFI cmdline options\n");
718 + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
719 + IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
720 + cmdline_size == 0)
721 + efi_parse_options(CONFIG_CMDLINE);
722 +
723 + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0)
724 + efi_parse_options(cmdline_ptr);
725
726 secure_boot = efi_get_secureboot(sys_table);
727 if (secure_boot > 0)
728 diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
729 index 959d9b8d4845..f7a6970e9abc 100644
730 --- a/drivers/firmware/efi/libstub/arm64-stub.c
731 +++ b/drivers/firmware/efi/libstub/arm64-stub.c
732 @@ -24,8 +24,6 @@
733
734 #include "efistub.h"
735
736 -extern bool __nokaslr;
737 -
738 efi_status_t check_platform_features(efi_system_table_t *sys_table_arg)
739 {
740 u64 tg;
741 @@ -60,7 +58,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
742 u64 phys_seed = 0;
743
744 if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
745 - if (!__nokaslr) {
746 + if (!nokaslr()) {
747 status = efi_get_random_bytes(sys_table_arg,
748 sizeof(phys_seed),
749 (u8 *)&phys_seed);
750 diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
751 index 09d10dcf1fc6..1c963c4d1bde 100644
752 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
753 +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
754 @@ -32,6 +32,13 @@
755
756 static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE;
757
758 +static int __section(.data) __nokaslr;
759 +
760 +int __pure nokaslr(void)
761 +{
762 + return __nokaslr;
763 +}
764 +
765 /*
766 * Allow the platform to override the allocation granularity: this allows
767 * systems that have the capability to run with a larger page size to deal
768 @@ -351,17 +358,13 @@ void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
769 * environments, first in the early boot environment of the EFI boot
770 * stub, and subsequently during the kernel boot.
771 */
772 -efi_status_t efi_parse_options(char *cmdline)
773 +efi_status_t efi_parse_options(char const *cmdline)
774 {
775 char *str;
776
777 - /*
778 - * Currently, the only efi= option we look for is 'nochunk', which
779 - * is intended to work around known issues on certain x86 UEFI
780 - * versions. So ignore for now on other architectures.
781 - */
782 - if (!IS_ENABLED(CONFIG_X86))
783 - return EFI_SUCCESS;
784 + str = strstr(cmdline, "nokaslr");
785 + if (str == cmdline || (str && str > cmdline && *(str - 1) == ' '))
786 + __nokaslr = 1;
787
788 /*
789 * If no EFI parameters were specified on the cmdline we've got
790 diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
791 index fac67992bede..d0e5acab547f 100644
792 --- a/drivers/firmware/efi/libstub/efistub.h
793 +++ b/drivers/firmware/efi/libstub/efistub.h
794 @@ -15,6 +15,8 @@
795 */
796 #undef __init
797
798 +extern int __pure nokaslr(void);
799 +
800 void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
801
802 efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image,
803 diff --git a/drivers/gpu/drm/gma500/cdv_intel_lvds.c b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
804 index ea733ab5b1e0..d83be4623c7f 100644
805 --- a/drivers/gpu/drm/gma500/cdv_intel_lvds.c
806 +++ b/drivers/gpu/drm/gma500/cdv_intel_lvds.c
807 @@ -609,6 +609,9 @@ void cdv_intel_lvds_init(struct drm_device *dev,
808 int pipe;
809 u8 pin;
810
811 + if (!dev_priv->lvds_enabled_in_vbt)
812 + return;
813 +
814 pin = GMBUS_PORT_PANEL;
815 if (!lvds_is_present_in_vbt(dev, &pin)) {
816 DRM_DEBUG_KMS("LVDS is not present in VBT\n");
817 diff --git a/drivers/gpu/drm/gma500/intel_bios.c b/drivers/gpu/drm/gma500/intel_bios.c
818 index 63bde4e86c6a..e019ea271ffc 100644
819 --- a/drivers/gpu/drm/gma500/intel_bios.c
820 +++ b/drivers/gpu/drm/gma500/intel_bios.c
821 @@ -436,6 +436,9 @@ parse_driver_features(struct drm_psb_private *dev_priv,
822 if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
823 dev_priv->edp.support = 1;
824
825 + dev_priv->lvds_enabled_in_vbt = driver->lvds_config != 0;
826 + DRM_DEBUG_KMS("LVDS VBT config bits: 0x%x\n", driver->lvds_config);
827 +
828 /* This bit means to use 96Mhz for DPLL_A or not */
829 if (driver->primary_lfp_id)
830 dev_priv->dplla_96mhz = true;
831 diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h
832 index b74372760d7f..d18e11d61312 100644
833 --- a/drivers/gpu/drm/gma500/psb_drv.h
834 +++ b/drivers/gpu/drm/gma500/psb_drv.h
835 @@ -538,6 +538,7 @@ struct drm_psb_private {
836 int lvds_ssc_freq;
837 bool is_lvds_on;
838 bool is_mipi_on;
839 + bool lvds_enabled_in_vbt;
840 u32 mipi_ctrl_display;
841
842 unsigned int core_freq;
843 diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h
844 index a63c5ac69f66..23b8f25402d0 100644
845 --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h
846 +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/i2c.h
847 @@ -37,6 +37,7 @@ struct nvkm_i2c_bus {
848 struct mutex mutex;
849 struct list_head head;
850 struct i2c_adapter i2c;
851 + u8 enabled;
852 };
853
854 int nvkm_i2c_bus_acquire(struct nvkm_i2c_bus *);
855 @@ -56,6 +57,7 @@ struct nvkm_i2c_aux {
856 struct mutex mutex;
857 struct list_head head;
858 struct i2c_adapter i2c;
859 + u8 enabled;
860
861 u32 intr;
862 };
863 diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c
864 index f0851d57df2f..f89692cb2bc7 100644
865 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c
866 +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c
867 @@ -105,9 +105,15 @@ nvkm_i2c_aux_acquire(struct nvkm_i2c_aux *aux)
868 {
869 struct nvkm_i2c_pad *pad = aux->pad;
870 int ret;
871 +
872 AUX_TRACE(aux, "acquire");
873 mutex_lock(&aux->mutex);
874 - ret = nvkm_i2c_pad_acquire(pad, NVKM_I2C_PAD_AUX);
875 +
876 + if (aux->enabled)
877 + ret = nvkm_i2c_pad_acquire(pad, NVKM_I2C_PAD_AUX);
878 + else
879 + ret = -EIO;
880 +
881 if (ret)
882 mutex_unlock(&aux->mutex);
883 return ret;
884 @@ -141,6 +147,24 @@ nvkm_i2c_aux_del(struct nvkm_i2c_aux **paux)
885 }
886 }
887
888 +void
889 +nvkm_i2c_aux_init(struct nvkm_i2c_aux *aux)
890 +{
891 + AUX_TRACE(aux, "init");
892 + mutex_lock(&aux->mutex);
893 + aux->enabled = true;
894 + mutex_unlock(&aux->mutex);
895 +}
896 +
897 +void
898 +nvkm_i2c_aux_fini(struct nvkm_i2c_aux *aux)
899 +{
900 + AUX_TRACE(aux, "fini");
901 + mutex_lock(&aux->mutex);
902 + aux->enabled = false;
903 + mutex_unlock(&aux->mutex);
904 +}
905 +
906 int
907 nvkm_i2c_aux_ctor(const struct nvkm_i2c_aux_func *func,
908 struct nvkm_i2c_pad *pad, int id,
909 diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.h b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.h
910 index fc6b162fa0b1..1be175a8fb02 100644
911 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.h
912 +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.h
913 @@ -14,6 +14,8 @@ int nvkm_i2c_aux_ctor(const struct nvkm_i2c_aux_func *, struct nvkm_i2c_pad *,
914 int nvkm_i2c_aux_new_(const struct nvkm_i2c_aux_func *, struct nvkm_i2c_pad *,
915 int id, struct nvkm_i2c_aux **);
916 void nvkm_i2c_aux_del(struct nvkm_i2c_aux **);
917 +void nvkm_i2c_aux_init(struct nvkm_i2c_aux *);
918 +void nvkm_i2c_aux_fini(struct nvkm_i2c_aux *);
919 int nvkm_i2c_aux_xfer(struct nvkm_i2c_aux *, bool retry, u8 type,
920 u32 addr, u8 *data, u8 size);
921
922 diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c
923 index 4f197b15acf6..ecacb22834d7 100644
924 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c
925 +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c
926 @@ -160,8 +160,18 @@ nvkm_i2c_fini(struct nvkm_subdev *subdev, bool suspend)
927 {
928 struct nvkm_i2c *i2c = nvkm_i2c(subdev);
929 struct nvkm_i2c_pad *pad;
930 + struct nvkm_i2c_bus *bus;
931 + struct nvkm_i2c_aux *aux;
932 u32 mask;
933
934 + list_for_each_entry(aux, &i2c->aux, head) {
935 + nvkm_i2c_aux_fini(aux);
936 + }
937 +
938 + list_for_each_entry(bus, &i2c->bus, head) {
939 + nvkm_i2c_bus_fini(bus);
940 + }
941 +
942 if ((mask = (1 << i2c->func->aux) - 1), i2c->func->aux_stat) {
943 i2c->func->aux_mask(i2c, NVKM_I2C_ANY, mask, 0);
944 i2c->func->aux_stat(i2c, &mask, &mask, &mask, &mask);
945 @@ -180,6 +190,7 @@ nvkm_i2c_init(struct nvkm_subdev *subdev)
946 struct nvkm_i2c *i2c = nvkm_i2c(subdev);
947 struct nvkm_i2c_bus *bus;
948 struct nvkm_i2c_pad *pad;
949 + struct nvkm_i2c_aux *aux;
950
951 list_for_each_entry(pad, &i2c->pad, head) {
952 nvkm_i2c_pad_init(pad);
953 @@ -189,6 +200,10 @@ nvkm_i2c_init(struct nvkm_subdev *subdev)
954 nvkm_i2c_bus_init(bus);
955 }
956
957 + list_for_each_entry(aux, &i2c->aux, head) {
958 + nvkm_i2c_aux_init(aux);
959 + }
960 +
961 return 0;
962 }
963
964 diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/bus.c b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/bus.c
965 index 807a2b67bd64..ed50cc3736b9 100644
966 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/bus.c
967 +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/bus.c
968 @@ -110,6 +110,19 @@ nvkm_i2c_bus_init(struct nvkm_i2c_bus *bus)
969 BUS_TRACE(bus, "init");
970 if (bus->func->init)
971 bus->func->init(bus);
972 +
973 + mutex_lock(&bus->mutex);
974 + bus->enabled = true;
975 + mutex_unlock(&bus->mutex);
976 +}
977 +
978 +void
979 +nvkm_i2c_bus_fini(struct nvkm_i2c_bus *bus)
980 +{
981 + BUS_TRACE(bus, "fini");
982 + mutex_lock(&bus->mutex);
983 + bus->enabled = false;
984 + mutex_unlock(&bus->mutex);
985 }
986
987 void
988 @@ -126,9 +139,15 @@ nvkm_i2c_bus_acquire(struct nvkm_i2c_bus *bus)
989 {
990 struct nvkm_i2c_pad *pad = bus->pad;
991 int ret;
992 +
993 BUS_TRACE(bus, "acquire");
994 mutex_lock(&bus->mutex);
995 - ret = nvkm_i2c_pad_acquire(pad, NVKM_I2C_PAD_I2C);
996 +
997 + if (bus->enabled)
998 + ret = nvkm_i2c_pad_acquire(pad, NVKM_I2C_PAD_I2C);
999 + else
1000 + ret = -EIO;
1001 +
1002 if (ret)
1003 mutex_unlock(&bus->mutex);
1004 return ret;
1005 diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/bus.h b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/bus.h
1006 index e1be14c23e54..2fdb1b8e7164 100644
1007 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/bus.h
1008 +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/bus.h
1009 @@ -17,6 +17,7 @@ int nvkm_i2c_bus_new_(const struct nvkm_i2c_bus_func *, struct nvkm_i2c_pad *,
1010 int id, struct nvkm_i2c_bus **);
1011 void nvkm_i2c_bus_del(struct nvkm_i2c_bus **);
1012 void nvkm_i2c_bus_init(struct nvkm_i2c_bus *);
1013 +void nvkm_i2c_bus_fini(struct nvkm_i2c_bus *);
1014
1015 int nvkm_i2c_bit_xfer(struct nvkm_i2c_bus *, struct i2c_msg *, int);
1016
1017 diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
1018 index ca1caf405832..8b6f8aa23806 100644
1019 --- a/drivers/gpu/drm/radeon/radeon_display.c
1020 +++ b/drivers/gpu/drm/radeon/radeon_display.c
1021 @@ -935,12 +935,12 @@ static void avivo_get_fb_ref_div(unsigned nom, unsigned den, unsigned post_div,
1022 ref_div_max = max(min(100 / post_div, ref_div_max), 1u);
1023
1024 /* get matching reference and feedback divider */
1025 - *ref_div = min(max(DIV_ROUND_CLOSEST(den, post_div), 1u), ref_div_max);
1026 + *ref_div = min(max(den/post_div, 1u), ref_div_max);
1027 *fb_div = DIV_ROUND_CLOSEST(nom * *ref_div * post_div, den);
1028
1029 /* limit fb divider to its maximum */
1030 if (*fb_div > fb_div_max) {
1031 - *ref_div = DIV_ROUND_CLOSEST(*ref_div * fb_div_max, *fb_div);
1032 + *ref_div = (*ref_div * fb_div_max)/(*fb_div);
1033 *fb_div = fb_div_max;
1034 }
1035 }
1036 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
1037 index 4b556e698f13..6c30c24c779f 100644
1038 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
1039 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
1040 @@ -1245,7 +1245,13 @@ static int vmw_master_set(struct drm_device *dev,
1041 }
1042
1043 dev_priv->active_master = vmaster;
1044 - drm_sysfs_hotplug_event(dev);
1045 +
1046 + /*
1047 + * Inform a new master that the layout may have changed while
1048 + * it was gone.
1049 + */
1050 + if (!from_open)
1051 + drm_sysfs_hotplug_event(dev);
1052
1053 return 0;
1054 }
1055 diff --git a/drivers/irqchip/irq-ath79-misc.c b/drivers/irqchip/irq-ath79-misc.c
1056 index 0390603170b4..aa7290784636 100644
1057 --- a/drivers/irqchip/irq-ath79-misc.c
1058 +++ b/drivers/irqchip/irq-ath79-misc.c
1059 @@ -22,15 +22,6 @@
1060 #define AR71XX_RESET_REG_MISC_INT_ENABLE 4
1061
1062 #define ATH79_MISC_IRQ_COUNT 32
1063 -#define ATH79_MISC_PERF_IRQ 5
1064 -
1065 -static int ath79_perfcount_irq;
1066 -
1067 -int get_c0_perfcount_int(void)
1068 -{
1069 - return ath79_perfcount_irq;
1070 -}
1071 -EXPORT_SYMBOL_GPL(get_c0_perfcount_int);
1072
1073 static void ath79_misc_irq_handler(struct irq_desc *desc)
1074 {
1075 @@ -122,8 +113,6 @@ static void __init ath79_misc_intc_domain_init(
1076 {
1077 void __iomem *base = domain->host_data;
1078
1079 - ath79_perfcount_irq = irq_create_mapping(domain, ATH79_MISC_PERF_IRQ);
1080 -
1081 /* Disable and clear all interrupts */
1082 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
1083 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
1084 diff --git a/drivers/media/usb/siano/smsusb.c b/drivers/media/usb/siano/smsusb.c
1085 index 18b41b9dc2e4..73889d6cfd50 100644
1086 --- a/drivers/media/usb/siano/smsusb.c
1087 +++ b/drivers/media/usb/siano/smsusb.c
1088 @@ -402,6 +402,7 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
1089 struct smsusb_device_t *dev;
1090 void *mdev;
1091 int i, rc;
1092 + int align = 0;
1093
1094 /* create device object */
1095 dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL);
1096 @@ -413,6 +414,24 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
1097 dev->udev = interface_to_usbdev(intf);
1098 dev->state = SMSUSB_DISCONNECTED;
1099
1100 + for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
1101 + struct usb_endpoint_descriptor *desc =
1102 + &intf->cur_altsetting->endpoint[i].desc;
1103 +
1104 + if (desc->bEndpointAddress & USB_DIR_IN) {
1105 + dev->in_ep = desc->bEndpointAddress;
1106 + align = usb_endpoint_maxp(desc) - sizeof(struct sms_msg_hdr);
1107 + } else {
1108 + dev->out_ep = desc->bEndpointAddress;
1109 + }
1110 + }
1111 +
1112 + pr_debug("in_ep = %02x, out_ep = %02x\n", dev->in_ep, dev->out_ep);
1113 + if (!dev->in_ep || !dev->out_ep || align < 0) { /* Missing endpoints? */
1114 + smsusb_term_device(intf);
1115 + return -ENODEV;
1116 + }
1117 +
1118 params.device_type = sms_get_board(board_id)->type;
1119
1120 switch (params.device_type) {
1121 @@ -427,24 +446,12 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
1122 /* fall-thru */
1123 default:
1124 dev->buffer_size = USB2_BUFFER_SIZE;
1125 - dev->response_alignment =
1126 - le16_to_cpu(dev->udev->ep_in[1]->desc.wMaxPacketSize) -
1127 - sizeof(struct sms_msg_hdr);
1128 + dev->response_alignment = align;
1129
1130 params.flags |= SMS_DEVICE_FAMILY2;
1131 break;
1132 }
1133
1134 - for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
1135 - if (intf->cur_altsetting->endpoint[i].desc. bEndpointAddress & USB_DIR_IN)
1136 - dev->in_ep = intf->cur_altsetting->endpoint[i].desc.bEndpointAddress;
1137 - else
1138 - dev->out_ep = intf->cur_altsetting->endpoint[i].desc.bEndpointAddress;
1139 - }
1140 -
1141 - pr_debug("in_ep = %02x, out_ep = %02x\n",
1142 - dev->in_ep, dev->out_ep);
1143 -
1144 params.device = &dev->udev->dev;
1145 params.buffer_size = dev->buffer_size;
1146 params.num_buffers = MAX_BUFFERS;
1147 diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
1148 index c630a9f8e356..a905d79381da 100644
1149 --- a/drivers/media/usb/uvc/uvc_driver.c
1150 +++ b/drivers/media/usb/uvc/uvc_driver.c
1151 @@ -868,7 +868,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
1152 unsigned int size;
1153 unsigned int i;
1154
1155 - extra_size = ALIGN(extra_size, sizeof(*entity->pads));
1156 + extra_size = roundup(extra_size, sizeof(*entity->pads));
1157 num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
1158 size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
1159 + num_inputs;
1160 diff --git a/drivers/misc/genwqe/card_dev.c b/drivers/misc/genwqe/card_dev.c
1161 index c0012ca4229e..74923ffb0df1 100644
1162 --- a/drivers/misc/genwqe/card_dev.c
1163 +++ b/drivers/misc/genwqe/card_dev.c
1164 @@ -782,6 +782,8 @@ static int genwqe_pin_mem(struct genwqe_file *cfile, struct genwqe_mem *m)
1165
1166 if ((m->addr == 0x0) || (m->size == 0))
1167 return -EINVAL;
1168 + if (m->size > ULONG_MAX - PAGE_SIZE - (m->addr & ~PAGE_MASK))
1169 + return -EINVAL;
1170
1171 map_addr = (m->addr & PAGE_MASK);
1172 map_size = round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE);
1173 diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c
1174 index 466a9b711480..b642b4fd731b 100644
1175 --- a/drivers/misc/genwqe/card_utils.c
1176 +++ b/drivers/misc/genwqe/card_utils.c
1177 @@ -582,6 +582,10 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr,
1178 /* determine space needed for page_list. */
1179 data = (unsigned long)uaddr;
1180 offs = offset_in_page(data);
1181 + if (size > ULONG_MAX - PAGE_SIZE - offs) {
1182 + m->size = 0; /* mark unused and not added */
1183 + return -EINVAL;
1184 + }
1185 m->nr_pages = DIV_ROUND_UP(offs + size, PAGE_SIZE);
1186
1187 m->page_list = kcalloc(m->nr_pages,
1188 diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
1189 index 7cee3e5db56c..dc510069d37b 100644
1190 --- a/drivers/net/dsa/mv88e6xxx/chip.c
1191 +++ b/drivers/net/dsa/mv88e6xxx/chip.c
1192 @@ -789,7 +789,7 @@ static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
1193 err = mv88e6xxx_port_read(chip, port, s->reg + 1, &reg);
1194 if (err)
1195 return UINT64_MAX;
1196 - high = reg;
1197 + low |= ((u32)reg) << 16;
1198 }
1199 break;
1200 case BANK0:
1201 diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
1202 index 620a470eb4c8..fbe3c2c114f9 100644
1203 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
1204 +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
1205 @@ -1425,6 +1425,8 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
1206 skb = bnxt_copy_skb(bnapi, data, len, dma_addr);
1207 bnxt_reuse_rx_data(rxr, cons, data);
1208 if (!skb) {
1209 + if (agg_bufs)
1210 + bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
1211 rc = -ENOMEM;
1212 goto next_rx;
1213 }
1214 diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
1215 index 051ecc76a7ef..1eb34109b207 100644
1216 --- a/drivers/net/ethernet/freescale/fec_main.c
1217 +++ b/drivers/net/ethernet/freescale/fec_main.c
1218 @@ -3508,7 +3508,7 @@ failed_init:
1219 if (fep->reg_phy)
1220 regulator_disable(fep->reg_phy);
1221 failed_reset:
1222 - pm_runtime_put(&pdev->dev);
1223 + pm_runtime_put_noidle(&pdev->dev);
1224 pm_runtime_disable(&pdev->dev);
1225 failed_regulator:
1226 failed_clk_ipg:
1227 diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
1228 index d98b874a7238..f2904afe10e4 100644
1229 --- a/drivers/net/ethernet/marvell/mvneta.c
1230 +++ b/drivers/net/ethernet/marvell/mvneta.c
1231 @@ -4162,7 +4162,7 @@ static int mvneta_probe(struct platform_device *pdev)
1232 err = register_netdev(dev);
1233 if (err < 0) {
1234 dev_err(&pdev->dev, "failed to register\n");
1235 - goto err_free_stats;
1236 + goto err_netdev;
1237 }
1238
1239 netdev_info(dev, "Using %s mac address %pM\n", mac_from,
1240 @@ -4181,13 +4181,11 @@ static int mvneta_probe(struct platform_device *pdev)
1241 return 0;
1242
1243 err_netdev:
1244 - unregister_netdev(dev);
1245 if (pp->bm_priv) {
1246 mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_long, 1 << pp->id);
1247 mvneta_bm_pool_destroy(pp->bm_priv, pp->pool_short,
1248 1 << pp->id);
1249 }
1250 -err_free_stats:
1251 free_percpu(pp->stats);
1252 err_free_ports:
1253 free_percpu(pp->ports);
1254 diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
1255 index ff62dc7485d5..0ea1c05f5f0e 100644
1256 --- a/drivers/net/ethernet/marvell/mvpp2.c
1257 +++ b/drivers/net/ethernet/marvell/mvpp2.c
1258 @@ -3938,7 +3938,7 @@ static inline void mvpp2_gmac_max_rx_size_set(struct mvpp2_port *port)
1259 /* Set defaults to the MVPP2 port */
1260 static void mvpp2_defaults_set(struct mvpp2_port *port)
1261 {
1262 - int tx_port_num, val, queue, ptxq, lrxq;
1263 + int tx_port_num, val, queue, lrxq;
1264
1265 /* Configure port to loopback if needed */
1266 if (port->flags & MVPP2_F_LOOPBACK)
1267 @@ -3958,11 +3958,9 @@ static void mvpp2_defaults_set(struct mvpp2_port *port)
1268 mvpp2_write(port->priv, MVPP2_TXP_SCHED_CMD_1_REG, 0);
1269
1270 /* Close bandwidth for all queues */
1271 - for (queue = 0; queue < MVPP2_MAX_TXQ; queue++) {
1272 - ptxq = mvpp2_txq_phys(port->id, queue);
1273 + for (queue = 0; queue < MVPP2_MAX_TXQ; queue++)
1274 mvpp2_write(port->priv,
1275 - MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(ptxq), 0);
1276 - }
1277 + MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(queue), 0);
1278
1279 /* Set refill period to 1 usec, refill tokens
1280 * and bucket size to maximum
1281 @@ -4709,7 +4707,7 @@ static void mvpp2_txq_deinit(struct mvpp2_port *port,
1282 txq->descs_phys = 0;
1283
1284 /* Set minimum bandwidth for disabled TXQs */
1285 - mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(txq->id), 0);
1286 + mvpp2_write(port->priv, MVPP2_TXQ_SCHED_TOKEN_CNTR_REG(txq->log_id), 0);
1287
1288 /* Set Tx descriptors queue starting address and size */
1289 mvpp2_write(port->priv, MVPP2_TXQ_NUM_REG, txq->id);
1290 diff --git a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
1291 index 8a9a332d78b4..74d2db505866 100644
1292 --- a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
1293 +++ b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
1294 @@ -1930,6 +1930,8 @@ static int mlx4_en_set_tunable(struct net_device *dev,
1295 return ret;
1296 }
1297
1298 +#define MLX4_EEPROM_PAGE_LEN 256
1299 +
1300 static int mlx4_en_get_module_info(struct net_device *dev,
1301 struct ethtool_modinfo *modinfo)
1302 {
1303 @@ -1964,7 +1966,7 @@ static int mlx4_en_get_module_info(struct net_device *dev,
1304 break;
1305 case MLX4_MODULE_ID_SFP:
1306 modinfo->type = ETH_MODULE_SFF_8472;
1307 - modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1308 + modinfo->eeprom_len = MLX4_EEPROM_PAGE_LEN;
1309 break;
1310 default:
1311 return -ENOSYS;
1312 diff --git a/drivers/net/ethernet/mellanox/mlx4/port.c b/drivers/net/ethernet/mellanox/mlx4/port.c
1313 index b656dd5772e5..3173875a715f 100644
1314 --- a/drivers/net/ethernet/mellanox/mlx4/port.c
1315 +++ b/drivers/net/ethernet/mellanox/mlx4/port.c
1316 @@ -1960,11 +1960,6 @@ int mlx4_get_module_info(struct mlx4_dev *dev, u8 port,
1317 size -= offset + size - I2C_PAGE_SIZE;
1318
1319 i2c_addr = I2C_ADDR_LOW;
1320 - if (offset >= I2C_PAGE_SIZE) {
1321 - /* Reset offset to high page */
1322 - i2c_addr = I2C_ADDR_HIGH;
1323 - offset -= I2C_PAGE_SIZE;
1324 - }
1325
1326 cable_info = (struct mlx4_cable_info *)inmad->data;
1327 cable_info->dev_mem_address = cpu_to_be16(offset);
1328 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
1329 index 2abeba41c0af..5fe3622d27d7 100644
1330 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
1331 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
1332 @@ -240,7 +240,8 @@ int stmmac_mdio_reset(struct mii_bus *bus)
1333 of_property_read_u32_array(np,
1334 "snps,reset-delays-us", data->delays, 3);
1335
1336 - if (gpio_request(data->reset_gpio, "mdio-reset"))
1337 + if (devm_gpio_request(priv->device, data->reset_gpio,
1338 + "mdio-reset"))
1339 return 0;
1340 }
1341
1342 diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
1343 index 4ab82b998a0f..a5acbcb3c044 100644
1344 --- a/drivers/net/usb/usbnet.c
1345 +++ b/drivers/net/usb/usbnet.c
1346 @@ -508,6 +508,7 @@ static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
1347
1348 if (netif_running (dev->net) &&
1349 netif_device_present (dev->net) &&
1350 + test_bit(EVENT_DEV_OPEN, &dev->flags) &&
1351 !test_bit (EVENT_RX_HALT, &dev->flags) &&
1352 !test_bit (EVENT_DEV_ASLEEP, &dev->flags)) {
1353 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)) {
1354 @@ -1394,6 +1395,11 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
1355 spin_unlock_irqrestore(&dev->txq.lock, flags);
1356 goto drop;
1357 }
1358 + if (netif_queue_stopped(net)) {
1359 + usb_autopm_put_interface_async(dev->intf);
1360 + spin_unlock_irqrestore(&dev->txq.lock, flags);
1361 + goto drop;
1362 + }
1363
1364 #ifdef CONFIG_PM
1365 /* if this triggers the device is still a sleep */
1366 diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
1367 index 8f8fe6f2af5b..64f8f404c53f 100644
1368 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
1369 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
1370 @@ -3220,6 +3220,7 @@ brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
1371 struct brcmf_pno_scanresults_le *pfn_result;
1372 u32 result_count;
1373 u32 status;
1374 + u32 datalen;
1375
1376 brcmf_dbg(SCAN, "Enter\n");
1377
1378 @@ -3245,6 +3246,14 @@ brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
1379 if (result_count > 0) {
1380 int i;
1381
1382 + data += sizeof(struct brcmf_pno_scanresults_le);
1383 + netinfo_start = (struct brcmf_pno_net_info_le *)data;
1384 + datalen = e->datalen - ((void *)netinfo_start - (void *)pfn_result);
1385 + if (datalen < result_count * sizeof(*netinfo)) {
1386 + brcmf_err("insufficient event data\n");
1387 + goto out_err;
1388 + }
1389 +
1390 request = kzalloc(sizeof(*request), GFP_KERNEL);
1391 ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL);
1392 channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL);
1393 @@ -3254,9 +3263,6 @@ brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
1394 }
1395
1396 request->wiphy = wiphy;
1397 - data += sizeof(struct brcmf_pno_scanresults_le);
1398 - netinfo_start = (struct brcmf_pno_net_info_le *)data;
1399 -
1400 for (i = 0; i < result_count; i++) {
1401 netinfo = &netinfo_start[i];
1402 if (!netinfo) {
1403 @@ -3266,6 +3272,8 @@ brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
1404 goto out_err;
1405 }
1406
1407 + if (netinfo->SSID_len > IEEE80211_MAX_SSID_LEN)
1408 + netinfo->SSID_len = IEEE80211_MAX_SSID_LEN;
1409 brcmf_dbg(SCAN, "SSID:%s Channel:%d\n",
1410 netinfo->SSID, netinfo->channel);
1411 memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len);
1412 @@ -3571,6 +3579,8 @@ brcmf_wowl_nd_results(struct brcmf_if *ifp, const struct brcmf_event_msg *e,
1413
1414 data += sizeof(struct brcmf_pno_scanresults_le);
1415 netinfo = (struct brcmf_pno_net_info_le *)data;
1416 + if (netinfo->SSID_len > IEEE80211_MAX_SSID_LEN)
1417 + netinfo->SSID_len = IEEE80211_MAX_SSID_LEN;
1418 memcpy(cfg->wowl.nd->ssid.ssid, netinfo->SSID, netinfo->SSID_len);
1419 cfg->wowl.nd->ssid.ssid_len = netinfo->SSID_len;
1420 cfg->wowl.nd->n_channels = 1;
1421 diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
1422 index ecfe056d7643..349cc5cb9e80 100644
1423 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
1424 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
1425 @@ -339,7 +339,8 @@ void brcmf_rx_frame(struct device *dev, struct sk_buff *skb, bool handle_event)
1426 } else {
1427 /* Process special event packets */
1428 if (handle_event)
1429 - brcmf_fweh_process_skb(ifp->drvr, skb);
1430 + brcmf_fweh_process_skb(ifp->drvr, skb,
1431 + BCMILCP_SUBTYPE_VENDOR_LONG);
1432
1433 brcmf_netif_rx(ifp, skb);
1434 }
1435 @@ -356,7 +357,7 @@ void brcmf_rx_event(struct device *dev, struct sk_buff *skb)
1436 if (brcmf_rx_hdrpull(drvr, skb, &ifp))
1437 return;
1438
1439 - brcmf_fweh_process_skb(ifp->drvr, skb);
1440 + brcmf_fweh_process_skb(ifp->drvr, skb, 0);
1441 brcmu_pkt_buf_free_skb(skb);
1442 }
1443
1444 diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h
1445 index 26ff5a9648f3..9cd112ef87d7 100644
1446 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h
1447 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h
1448 @@ -181,7 +181,7 @@ enum brcmf_fweh_event_code {
1449 */
1450 #define BRCM_OUI "\x00\x10\x18"
1451 #define BCMILCP_BCM_SUBTYPE_EVENT 1
1452 -
1453 +#define BCMILCP_SUBTYPE_VENDOR_LONG 32769
1454
1455 /**
1456 * struct brcm_ethhdr - broadcom specific ether header.
1457 @@ -302,10 +302,10 @@ void brcmf_fweh_process_event(struct brcmf_pub *drvr,
1458 void brcmf_fweh_p2pdev_setup(struct brcmf_if *ifp, bool ongoing);
1459
1460 static inline void brcmf_fweh_process_skb(struct brcmf_pub *drvr,
1461 - struct sk_buff *skb)
1462 + struct sk_buff *skb, u16 stype)
1463 {
1464 struct brcmf_event *event_packet;
1465 - u16 usr_stype;
1466 + u16 subtype, usr_stype;
1467
1468 /* only process events when protocol matches */
1469 if (skb->protocol != cpu_to_be16(ETH_P_LINK_CTL))
1470 @@ -314,8 +314,16 @@ static inline void brcmf_fweh_process_skb(struct brcmf_pub *drvr,
1471 if ((skb->len + ETH_HLEN) < sizeof(*event_packet))
1472 return;
1473
1474 - /* check for BRCM oui match */
1475 event_packet = (struct brcmf_event *)skb_mac_header(skb);
1476 +
1477 + /* check subtype if needed */
1478 + if (unlikely(stype)) {
1479 + subtype = get_unaligned_be16(&event_packet->hdr.subtype);
1480 + if (subtype != stype)
1481 + return;
1482 + }
1483 +
1484 + /* check for BRCM oui match */
1485 if (memcmp(BRCM_OUI, &event_packet->hdr.oui[0],
1486 sizeof(event_packet->hdr.oui)))
1487 return;
1488 diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
1489 index 2b9a2bc429d6..ab9f136c1593 100644
1490 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
1491 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
1492 @@ -1114,7 +1114,7 @@ static void brcmf_msgbuf_process_event(struct brcmf_msgbuf *msgbuf, void *buf)
1493
1494 skb->protocol = eth_type_trans(skb, ifp->ndev);
1495
1496 - brcmf_fweh_process_skb(ifp->drvr, skb);
1497 + brcmf_fweh_process_skb(ifp->drvr, skb, 0);
1498
1499 exit:
1500 brcmu_pkt_buf_free_skb(skb);
1501 diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
1502 index c4953eca907d..7a5306bf56c8 100644
1503 --- a/drivers/parisc/ccio-dma.c
1504 +++ b/drivers/parisc/ccio-dma.c
1505 @@ -563,8 +563,6 @@ ccio_io_pdir_entry(u64 *pdir_ptr, space_t sid, unsigned long vba,
1506 /* We currently only support kernel addresses */
1507 BUG_ON(sid != KERNEL_SPACE);
1508
1509 - mtsp(sid,1);
1510 -
1511 /*
1512 ** WORD 1 - low order word
1513 ** "hints" parm includes the VALID bit!
1514 @@ -595,7 +593,7 @@ ccio_io_pdir_entry(u64 *pdir_ptr, space_t sid, unsigned long vba,
1515 ** Grab virtual index [0:11]
1516 ** Deposit virt_idx bits into I/O PDIR word
1517 */
1518 - asm volatile ("lci %%r0(%%sr1, %1), %0" : "=r" (ci) : "r" (vba));
1519 + asm volatile ("lci %%r0(%1), %0" : "=r" (ci) : "r" (vba));
1520 asm volatile ("extru %1,19,12,%0" : "+r" (ci) : "r" (ci));
1521 asm volatile ("depw %1,15,12,%0" : "+r" (pa) : "r" (ci));
1522
1523 diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
1524 index 56918d1c0ed3..188fab57d170 100644
1525 --- a/drivers/parisc/sba_iommu.c
1526 +++ b/drivers/parisc/sba_iommu.c
1527 @@ -573,8 +573,7 @@ sba_io_pdir_entry(u64 *pdir_ptr, space_t sid, unsigned long vba,
1528 pa = virt_to_phys(vba);
1529 pa &= IOVP_MASK;
1530
1531 - mtsp(sid,1);
1532 - asm("lci 0(%%sr1, %1), %0" : "=r" (ci) : "r" (vba));
1533 + asm("lci 0(%1), %0" : "=r" (ci) : "r" (vba));
1534 pa |= (ci >> PAGE_SHIFT) & 0xff; /* move CI (8 bits) into lowest byte */
1535
1536 pa |= SBA_PDIR_VALID_BIT; /* set "valid" bit */
1537 diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
1538 index a39a74500e23..aeb93478482f 100644
1539 --- a/drivers/s390/scsi/zfcp_ext.h
1540 +++ b/drivers/s390/scsi/zfcp_ext.h
1541 @@ -161,6 +161,7 @@ extern const struct attribute_group *zfcp_port_attr_groups[];
1542 extern struct mutex zfcp_sysfs_port_units_mutex;
1543 extern struct device_attribute *zfcp_sysfs_sdev_attrs[];
1544 extern struct device_attribute *zfcp_sysfs_shost_attrs[];
1545 +bool zfcp_sysfs_port_is_removing(const struct zfcp_port *const port);
1546
1547 /* zfcp_unit.c */
1548 extern int zfcp_unit_add(struct zfcp_port *, u64);
1549 diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
1550 index bdb257eaa2e5..68146b398603 100644
1551 --- a/drivers/s390/scsi/zfcp_scsi.c
1552 +++ b/drivers/s390/scsi/zfcp_scsi.c
1553 @@ -124,6 +124,15 @@ static int zfcp_scsi_slave_alloc(struct scsi_device *sdev)
1554
1555 zfcp_sdev->erp_action.port = port;
1556
1557 + mutex_lock(&zfcp_sysfs_port_units_mutex);
1558 + if (zfcp_sysfs_port_is_removing(port)) {
1559 + /* port is already gone */
1560 + mutex_unlock(&zfcp_sysfs_port_units_mutex);
1561 + put_device(&port->dev); /* undo zfcp_get_port_by_wwpn() */
1562 + return -ENXIO;
1563 + }
1564 + mutex_unlock(&zfcp_sysfs_port_units_mutex);
1565 +
1566 unit = zfcp_unit_find(port, zfcp_scsi_dev_lun(sdev));
1567 if (unit)
1568 put_device(&unit->dev);
1569 diff --git a/drivers/s390/scsi/zfcp_sysfs.c b/drivers/s390/scsi/zfcp_sysfs.c
1570 index 96a0be13e841..5df597d1b978 100644
1571 --- a/drivers/s390/scsi/zfcp_sysfs.c
1572 +++ b/drivers/s390/scsi/zfcp_sysfs.c
1573 @@ -237,6 +237,53 @@ static ZFCP_DEV_ATTR(adapter, port_rescan, S_IWUSR, NULL,
1574
1575 DEFINE_MUTEX(zfcp_sysfs_port_units_mutex);
1576
1577 +static void zfcp_sysfs_port_set_removing(struct zfcp_port *const port)
1578 +{
1579 + lockdep_assert_held(&zfcp_sysfs_port_units_mutex);
1580 + atomic_set(&port->units, -1);
1581 +}
1582 +
1583 +bool zfcp_sysfs_port_is_removing(const struct zfcp_port *const port)
1584 +{
1585 + lockdep_assert_held(&zfcp_sysfs_port_units_mutex);
1586 + return atomic_read(&port->units) == -1;
1587 +}
1588 +
1589 +static bool zfcp_sysfs_port_in_use(struct zfcp_port *const port)
1590 +{
1591 + struct zfcp_adapter *const adapter = port->adapter;
1592 + unsigned long flags;
1593 + struct scsi_device *sdev;
1594 + bool in_use = true;
1595 +
1596 + mutex_lock(&zfcp_sysfs_port_units_mutex);
1597 + if (atomic_read(&port->units) > 0)
1598 + goto unlock_port_units_mutex; /* zfcp_unit(s) under port */
1599 +
1600 + spin_lock_irqsave(adapter->scsi_host->host_lock, flags);
1601 + __shost_for_each_device(sdev, adapter->scsi_host) {
1602 + const struct zfcp_scsi_dev *zsdev = sdev_to_zfcp(sdev);
1603 +
1604 + if (sdev->sdev_state == SDEV_DEL ||
1605 + sdev->sdev_state == SDEV_CANCEL)
1606 + continue;
1607 + if (zsdev->port != port)
1608 + continue;
1609 + /* alive scsi_device under port of interest */
1610 + goto unlock_host_lock;
1611 + }
1612 +
1613 + /* port is about to be removed, so no more unit_add or slave_alloc */
1614 + zfcp_sysfs_port_set_removing(port);
1615 + in_use = false;
1616 +
1617 +unlock_host_lock:
1618 + spin_unlock_irqrestore(adapter->scsi_host->host_lock, flags);
1619 +unlock_port_units_mutex:
1620 + mutex_unlock(&zfcp_sysfs_port_units_mutex);
1621 + return in_use;
1622 +}
1623 +
1624 static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,
1625 struct device_attribute *attr,
1626 const char *buf, size_t count)
1627 @@ -259,15 +306,11 @@ static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,
1628 else
1629 retval = 0;
1630
1631 - mutex_lock(&zfcp_sysfs_port_units_mutex);
1632 - if (atomic_read(&port->units) > 0) {
1633 + if (zfcp_sysfs_port_in_use(port)) {
1634 retval = -EBUSY;
1635 - mutex_unlock(&zfcp_sysfs_port_units_mutex);
1636 + put_device(&port->dev); /* undo zfcp_get_port_by_wwpn() */
1637 goto out;
1638 }
1639 - /* port is about to be removed, so no more unit_add */
1640 - atomic_set(&port->units, -1);
1641 - mutex_unlock(&zfcp_sysfs_port_units_mutex);
1642
1643 write_lock_irq(&adapter->port_list_lock);
1644 list_del(&port->list);
1645 diff --git a/drivers/s390/scsi/zfcp_unit.c b/drivers/s390/scsi/zfcp_unit.c
1646 index 9310a547b89f..1435029ade55 100644
1647 --- a/drivers/s390/scsi/zfcp_unit.c
1648 +++ b/drivers/s390/scsi/zfcp_unit.c
1649 @@ -123,7 +123,7 @@ int zfcp_unit_add(struct zfcp_port *port, u64 fcp_lun)
1650 int retval = 0;
1651
1652 mutex_lock(&zfcp_sysfs_port_units_mutex);
1653 - if (atomic_read(&port->units) == -1) {
1654 + if (zfcp_sysfs_port_is_removing(port)) {
1655 /* port is already gone */
1656 retval = -ENODEV;
1657 goto out;
1658 @@ -167,8 +167,14 @@ int zfcp_unit_add(struct zfcp_port *port, u64 fcp_lun)
1659 write_lock_irq(&port->unit_list_lock);
1660 list_add_tail(&unit->list, &port->unit_list);
1661 write_unlock_irq(&port->unit_list_lock);
1662 + /*
1663 + * lock order: shost->scan_mutex before zfcp_sysfs_port_units_mutex
1664 + * due to zfcp_unit_scsi_scan() => zfcp_scsi_slave_alloc()
1665 + */
1666 + mutex_unlock(&zfcp_sysfs_port_units_mutex);
1667
1668 zfcp_unit_scsi_scan(unit);
1669 + return retval;
1670
1671 out:
1672 mutex_unlock(&zfcp_sysfs_port_units_mutex);
1673 diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
1674 index f72eebc71dd8..94590ac5b3cf 100644
1675 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
1676 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
1677 @@ -381,9 +381,18 @@ create_pagelist(char __user *buf, size_t count, unsigned short type,
1678 int run, addridx, actual_pages;
1679 unsigned long *need_release;
1680
1681 + if (count >= INT_MAX - PAGE_SIZE)
1682 + return NULL;
1683 +
1684 offset = (unsigned int)buf & (PAGE_SIZE - 1);
1685 num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
1686
1687 + if (num_pages > (SIZE_MAX - sizeof(PAGELIST_T) -
1688 + sizeof(struct vchiq_pagelist_info)) /
1689 + (sizeof(u32) + sizeof(pages[0]) +
1690 + sizeof(struct scatterlist)))
1691 + return NULL;
1692 +
1693 *ppagelist = NULL;
1694
1695 /* Allocate enough storage to hold the page pointers and the page
1696 diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
1697 index 5331baf3f699..ec3db8d8306c 100644
1698 --- a/drivers/tty/serial/max310x.c
1699 +++ b/drivers/tty/serial/max310x.c
1700 @@ -579,7 +579,7 @@ static int max310x_set_ref_clk(struct max310x_port *s, unsigned long freq,
1701 }
1702
1703 /* Configure clock source */
1704 - clksrc = xtal ? MAX310X_CLKSRC_CRYST_BIT : MAX310X_CLKSRC_EXTCLK_BIT;
1705 + clksrc = MAX310X_CLKSRC_EXTCLK_BIT | (xtal ? MAX310X_CLKSRC_CRYST_BIT : 0);
1706
1707 /* Configure PLL */
1708 if (pllcfg) {
1709 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
1710 index 6788e7532dff..7dc8272c6b15 100644
1711 --- a/drivers/tty/serial/msm_serial.c
1712 +++ b/drivers/tty/serial/msm_serial.c
1713 @@ -868,6 +868,7 @@ static void msm_handle_tx(struct uart_port *port)
1714 struct circ_buf *xmit = &msm_port->uart.state->xmit;
1715 struct msm_dma *dma = &msm_port->tx_dma;
1716 unsigned int pio_count, dma_count, dma_min;
1717 + char buf[4] = { 0 };
1718 void __iomem *tf;
1719 int err = 0;
1720
1721 @@ -877,10 +878,12 @@ static void msm_handle_tx(struct uart_port *port)
1722 else
1723 tf = port->membase + UART_TF;
1724
1725 + buf[0] = port->x_char;
1726 +
1727 if (msm_port->is_uartdm)
1728 msm_reset_dm_count(port, 1);
1729
1730 - iowrite8_rep(tf, &port->x_char, 1);
1731 + iowrite32_rep(tf, buf, 1);
1732 port->icount.tx++;
1733 port->x_char = 0;
1734 return;
1735 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
1736 index 55ed4c66f77f..680fb3f9be2d 100644
1737 --- a/drivers/tty/serial/serial_core.c
1738 +++ b/drivers/tty/serial/serial_core.c
1739 @@ -141,9 +141,6 @@ static void uart_start(struct tty_struct *tty)
1740 struct uart_port *port;
1741 unsigned long flags;
1742
1743 - if (!state)
1744 - return;
1745 -
1746 port = uart_port_lock(state, flags);
1747 __uart_start(tty);
1748 uart_port_unlock(port, flags);
1749 @@ -1714,11 +1711,8 @@ static void uart_dtr_rts(struct tty_port *port, int onoff)
1750 */
1751 static int uart_open(struct tty_struct *tty, struct file *filp)
1752 {
1753 - struct uart_driver *drv = tty->driver->driver_state;
1754 - int retval, line = tty->index;
1755 - struct uart_state *state = drv->state + line;
1756 -
1757 - tty->driver_data = state;
1758 + struct uart_state *state = tty->driver_data;
1759 + int retval;
1760
1761 retval = tty_port_open(&state->port, tty, filp);
1762 if (retval > 0)
1763 @@ -2409,9 +2403,6 @@ static void uart_poll_put_char(struct tty_driver *driver, int line, char ch)
1764 struct uart_state *state = drv->state + line;
1765 struct uart_port *port;
1766
1767 - if (!state)
1768 - return;
1769 -
1770 port = uart_port_ref(state);
1771 if (!port)
1772 return;
1773 @@ -2423,7 +2414,18 @@ static void uart_poll_put_char(struct tty_driver *driver, int line, char ch)
1774 }
1775 #endif
1776
1777 +static int uart_install(struct tty_driver *driver, struct tty_struct *tty)
1778 +{
1779 + struct uart_driver *drv = driver->driver_state;
1780 + struct uart_state *state = drv->state + tty->index;
1781 +
1782 + tty->driver_data = state;
1783 +
1784 + return tty_standard_install(driver, tty);
1785 +}
1786 +
1787 static const struct tty_operations uart_ops = {
1788 + .install = uart_install,
1789 .open = uart_open,
1790 .close = uart_close,
1791 .write = uart_write,
1792 diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
1793 index 5e6136d2ed71..eb12eea13770 100644
1794 --- a/drivers/usb/core/config.c
1795 +++ b/drivers/usb/core/config.c
1796 @@ -931,8 +931,8 @@ int usb_get_bos_descriptor(struct usb_device *dev)
1797
1798 /* Get BOS descriptor */
1799 ret = usb_get_descriptor(dev, USB_DT_BOS, 0, bos, USB_DT_BOS_SIZE);
1800 - if (ret < USB_DT_BOS_SIZE) {
1801 - dev_err(ddev, "unable to get BOS descriptor\n");
1802 + if (ret < USB_DT_BOS_SIZE || bos->bLength < USB_DT_BOS_SIZE) {
1803 + dev_err(ddev, "unable to get BOS descriptor or descriptor too short\n");
1804 if (ret >= 0)
1805 ret = -ENOMSG;
1806 kfree(bos);
1807 diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
1808 index 733479ddf8a7..38c7676e7a82 100644
1809 --- a/drivers/usb/core/quirks.c
1810 +++ b/drivers/usb/core/quirks.c
1811 @@ -64,6 +64,9 @@ static const struct usb_device_id usb_quirk_list[] = {
1812 /* Microsoft LifeCam-VX700 v2.0 */
1813 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME },
1814
1815 + /* Microsoft Surface Dock Ethernet (RTL8153 GigE) */
1816 + { USB_DEVICE(0x045e, 0x07c6), .driver_info = USB_QUIRK_NO_LPM },
1817 +
1818 /* Cherry Stream G230 2.0 (G85-231) and 3.0 (G85-232) */
1819 { USB_DEVICE(0x046a, 0x0023), .driver_info = USB_QUIRK_RESET_RESUME },
1820
1821 diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
1822 index 879d82223068..d2e3917cbd91 100644
1823 --- a/drivers/usb/host/xhci-ring.c
1824 +++ b/drivers/usb/host/xhci-ring.c
1825 @@ -678,6 +678,7 @@ void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci, struct xhci_ring *ring,
1826 struct device *dev = xhci_to_hcd(xhci)->self.controller;
1827 struct xhci_segment *seg = td->bounce_seg;
1828 struct urb *urb = td->urb;
1829 + size_t len;
1830
1831 if (!seg || !urb)
1832 return;
1833 @@ -688,11 +689,14 @@ void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci, struct xhci_ring *ring,
1834 return;
1835 }
1836
1837 - /* for in tranfers we need to copy the data from bounce to sg */
1838 - sg_pcopy_from_buffer(urb->sg, urb->num_mapped_sgs, seg->bounce_buf,
1839 - seg->bounce_len, seg->bounce_offs);
1840 dma_unmap_single(dev, seg->bounce_dma, ring->bounce_buf_len,
1841 DMA_FROM_DEVICE);
1842 + /* for in tranfers we need to copy the data from bounce to sg */
1843 + len = sg_pcopy_from_buffer(urb->sg, urb->num_sgs, seg->bounce_buf,
1844 + seg->bounce_len, seg->bounce_offs);
1845 + if (len != seg->bounce_len)
1846 + xhci_warn(xhci, "WARN Wrong bounce buffer read length: %zu != %d\n",
1847 + len, seg->bounce_len);
1848 seg->bounce_len = 0;
1849 seg->bounce_offs = 0;
1850 }
1851 @@ -3163,6 +3167,7 @@ static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len,
1852 unsigned int unalign;
1853 unsigned int max_pkt;
1854 u32 new_buff_len;
1855 + size_t len;
1856
1857 max_pkt = GET_MAX_PACKET(usb_endpoint_maxp(&urb->ep->desc));
1858 unalign = (enqd_len + *trb_buff_len) % max_pkt;
1859 @@ -3193,8 +3198,12 @@ static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len,
1860
1861 /* create a max max_pkt sized bounce buffer pointed to by last trb */
1862 if (usb_urb_dir_out(urb)) {
1863 - sg_pcopy_to_buffer(urb->sg, urb->num_mapped_sgs,
1864 + len = sg_pcopy_to_buffer(urb->sg, urb->num_sgs,
1865 seg->bounce_buf, new_buff_len, enqd_len);
1866 + if (len != seg->bounce_len)
1867 + xhci_warn(xhci,
1868 + "WARN Wrong bounce buffer write length: %zu != %d\n",
1869 + len, seg->bounce_len);
1870 seg->bounce_dma = dma_map_single(dev, seg->bounce_buf,
1871 max_pkt, DMA_TO_DEVICE);
1872 } else {
1873 diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
1874 index 7ff32088cfa4..ebdd82091a42 100644
1875 --- a/drivers/usb/host/xhci.c
1876 +++ b/drivers/usb/host/xhci.c
1877 @@ -21,6 +21,7 @@
1878 */
1879
1880 #include <linux/pci.h>
1881 +#include <linux/iopoll.h>
1882 #include <linux/irq.h>
1883 #include <linux/log2.h>
1884 #include <linux/module.h>
1885 @@ -47,7 +48,6 @@ static unsigned int quirks;
1886 module_param(quirks, uint, S_IRUGO);
1887 MODULE_PARM_DESC(quirks, "Bit flags for quirks to be enabled as default");
1888
1889 -/* TODO: copied from ehci-hcd.c - can this be refactored? */
1890 /*
1891 * xhci_handshake - spin reading hc until handshake completes or fails
1892 * @ptr: address of hc register to be read
1893 @@ -64,18 +64,16 @@ MODULE_PARM_DESC(quirks, "Bit flags for quirks to be enabled as default");
1894 int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec)
1895 {
1896 u32 result;
1897 + int ret;
1898
1899 - do {
1900 - result = readl(ptr);
1901 - if (result == ~(u32)0) /* card removed */
1902 - return -ENODEV;
1903 - result &= mask;
1904 - if (result == done)
1905 - return 0;
1906 - udelay(1);
1907 - usec--;
1908 - } while (usec > 0);
1909 - return -ETIMEDOUT;
1910 + ret = readl_poll_timeout_atomic(ptr, result,
1911 + (result & mask) == done ||
1912 + result == U32_MAX,
1913 + 1, usec);
1914 + if (result == U32_MAX) /* card removed */
1915 + return -ENODEV;
1916 +
1917 + return ret;
1918 }
1919
1920 /*
1921 @@ -4174,7 +4172,6 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
1922 pm_addr = port_array[port_num] + PORTPMSC;
1923 pm_val = readl(pm_addr);
1924 hlpm_addr = port_array[port_num] + PORTHLPMC;
1925 - field = le32_to_cpu(udev->bos->ext_cap->bmAttributes);
1926
1927 xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n",
1928 enable ? "enable" : "disable", port_num + 1);
1929 @@ -4186,6 +4183,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
1930 * default one which works with mixed HIRD and BESL
1931 * systems. See XHCI_DEFAULT_BESL definition in xhci.h
1932 */
1933 + field = le32_to_cpu(udev->bos->ext_cap->bmAttributes);
1934 if ((field & USB_BESL_SUPPORT) &&
1935 (field & USB_BESL_BASELINE_VALID))
1936 hird = USB_GET_BESL_BASELINE(field);
1937 diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
1938 index 13731d512624..6e761fabffca 100644
1939 --- a/drivers/usb/misc/rio500.c
1940 +++ b/drivers/usb/misc/rio500.c
1941 @@ -103,9 +103,22 @@ static int close_rio(struct inode *inode, struct file *file)
1942 {
1943 struct rio_usb_data *rio = &rio_instance;
1944
1945 - rio->isopen = 0;
1946 + /* against disconnect() */
1947 + mutex_lock(&rio500_mutex);
1948 + mutex_lock(&(rio->lock));
1949
1950 - dev_info(&rio->rio_dev->dev, "Rio closed.\n");
1951 + rio->isopen = 0;
1952 + if (!rio->present) {
1953 + /* cleanup has been delayed */
1954 + kfree(rio->ibuf);
1955 + kfree(rio->obuf);
1956 + rio->ibuf = NULL;
1957 + rio->obuf = NULL;
1958 + } else {
1959 + dev_info(&rio->rio_dev->dev, "Rio closed.\n");
1960 + }
1961 + mutex_unlock(&(rio->lock));
1962 + mutex_unlock(&rio500_mutex);
1963 return 0;
1964 }
1965
1966 @@ -464,15 +477,23 @@ static int probe_rio(struct usb_interface *intf,
1967 {
1968 struct usb_device *dev = interface_to_usbdev(intf);
1969 struct rio_usb_data *rio = &rio_instance;
1970 - int retval;
1971 + int retval = 0;
1972
1973 - dev_info(&intf->dev, "USB Rio found at address %d\n", dev->devnum);
1974 + mutex_lock(&rio500_mutex);
1975 + if (rio->present) {
1976 + dev_info(&intf->dev, "Second USB Rio at address %d refused\n", dev->devnum);
1977 + retval = -EBUSY;
1978 + goto bail_out;
1979 + } else {
1980 + dev_info(&intf->dev, "USB Rio found at address %d\n", dev->devnum);
1981 + }
1982
1983 retval = usb_register_dev(intf, &usb_rio_class);
1984 if (retval) {
1985 dev_err(&dev->dev,
1986 "Not able to get a minor for this device.\n");
1987 - return -ENOMEM;
1988 + retval = -ENOMEM;
1989 + goto bail_out;
1990 }
1991
1992 rio->rio_dev = dev;
1993 @@ -481,7 +502,8 @@ static int probe_rio(struct usb_interface *intf,
1994 dev_err(&dev->dev,
1995 "probe_rio: Not enough memory for the output buffer\n");
1996 usb_deregister_dev(intf, &usb_rio_class);
1997 - return -ENOMEM;
1998 + retval = -ENOMEM;
1999 + goto bail_out;
2000 }
2001 dev_dbg(&intf->dev, "obuf address:%p\n", rio->obuf);
2002
2003 @@ -490,7 +512,8 @@ static int probe_rio(struct usb_interface *intf,
2004 "probe_rio: Not enough memory for the input buffer\n");
2005 usb_deregister_dev(intf, &usb_rio_class);
2006 kfree(rio->obuf);
2007 - return -ENOMEM;
2008 + retval = -ENOMEM;
2009 + goto bail_out;
2010 }
2011 dev_dbg(&intf->dev, "ibuf address:%p\n", rio->ibuf);
2012
2013 @@ -498,8 +521,10 @@ static int probe_rio(struct usb_interface *intf,
2014
2015 usb_set_intfdata (intf, rio);
2016 rio->present = 1;
2017 +bail_out:
2018 + mutex_unlock(&rio500_mutex);
2019
2020 - return 0;
2021 + return retval;
2022 }
2023
2024 static void disconnect_rio(struct usb_interface *intf)
2025 diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
2026 index 05bd39d62568..b7a4ba020893 100644
2027 --- a/drivers/usb/misc/sisusbvga/sisusb.c
2028 +++ b/drivers/usb/misc/sisusbvga/sisusb.c
2029 @@ -3041,6 +3041,13 @@ static int sisusb_probe(struct usb_interface *intf,
2030
2031 mutex_init(&(sisusb->lock));
2032
2033 + sisusb->sisusb_dev = dev;
2034 + sisusb->vrambase = SISUSB_PCI_MEMBASE;
2035 + sisusb->mmiobase = SISUSB_PCI_MMIOBASE;
2036 + sisusb->mmiosize = SISUSB_PCI_MMIOSIZE;
2037 + sisusb->ioportbase = SISUSB_PCI_IOPORTBASE;
2038 + /* Everything else is zero */
2039 +
2040 /* Register device */
2041 retval = usb_register_dev(intf, &usb_sisusb_class);
2042 if (retval) {
2043 @@ -3051,13 +3058,7 @@ static int sisusb_probe(struct usb_interface *intf,
2044 goto error_1;
2045 }
2046
2047 - sisusb->sisusb_dev = dev;
2048 - sisusb->minor = intf->minor;
2049 - sisusb->vrambase = SISUSB_PCI_MEMBASE;
2050 - sisusb->mmiobase = SISUSB_PCI_MMIOBASE;
2051 - sisusb->mmiosize = SISUSB_PCI_MMIOSIZE;
2052 - sisusb->ioportbase = SISUSB_PCI_IOPORTBASE;
2053 - /* Everything else is zero */
2054 + sisusb->minor = intf->minor;
2055
2056 /* Allocate buffers */
2057 sisusb->ibufsize = SISUSB_IBUF_SIZE;
2058 diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
2059 index 8e629b6a6f3f..a5a6a114219a 100644
2060 --- a/drivers/usb/usbip/stub_dev.c
2061 +++ b/drivers/usb/usbip/stub_dev.c
2062 @@ -315,9 +315,17 @@ static int stub_probe(struct usb_device *udev)
2063 const char *udev_busid = dev_name(&udev->dev);
2064 struct bus_id_priv *busid_priv;
2065 int rc = 0;
2066 + char save_status;
2067
2068 dev_dbg(&udev->dev, "Enter probe\n");
2069
2070 + /* Not sure if this is our device. Allocate here to avoid
2071 + * calling alloc while holding busid_table lock.
2072 + */
2073 + sdev = stub_device_alloc(udev);
2074 + if (!sdev)
2075 + return -ENOMEM;
2076 +
2077 /* check we should claim or not by busid_table */
2078 busid_priv = get_busid_priv(udev_busid);
2079 if (!busid_priv || (busid_priv->status == STUB_BUSID_REMOV) ||
2080 @@ -332,6 +340,9 @@ static int stub_probe(struct usb_device *udev)
2081 * See driver_probe_device() in driver/base/dd.c
2082 */
2083 rc = -ENODEV;
2084 + if (!busid_priv)
2085 + goto sdev_free;
2086 +
2087 goto call_put_busid_priv;
2088 }
2089
2090 @@ -351,12 +362,6 @@ static int stub_probe(struct usb_device *udev)
2091 goto call_put_busid_priv;
2092 }
2093
2094 - /* ok, this is my device */
2095 - sdev = stub_device_alloc(udev);
2096 - if (!sdev) {
2097 - rc = -ENOMEM;
2098 - goto call_put_busid_priv;
2099 - }
2100
2101 dev_info(&udev->dev,
2102 "usbip-host: register new device (bus %u dev %u)\n",
2103 @@ -366,9 +371,16 @@ static int stub_probe(struct usb_device *udev)
2104
2105 /* set private data to usb_device */
2106 dev_set_drvdata(&udev->dev, sdev);
2107 +
2108 busid_priv->sdev = sdev;
2109 busid_priv->udev = udev;
2110
2111 + save_status = busid_priv->status;
2112 + busid_priv->status = STUB_BUSID_ALLOC;
2113 +
2114 + /* release the busid_lock */
2115 + put_busid_priv(busid_priv);
2116 +
2117 /*
2118 * Claim this hub port.
2119 * It doesn't matter what value we pass as owner
2120 @@ -386,10 +398,8 @@ static int stub_probe(struct usb_device *udev)
2121 dev_err(&udev->dev, "stub_add_files for %s\n", udev_busid);
2122 goto err_files;
2123 }
2124 - busid_priv->status = STUB_BUSID_ALLOC;
2125
2126 - rc = 0;
2127 - goto call_put_busid_priv;
2128 + return 0;
2129
2130 err_files:
2131 usb_hub_release_port(udev->parent, udev->portnum,
2132 @@ -398,23 +408,30 @@ err_port:
2133 dev_set_drvdata(&udev->dev, NULL);
2134 usb_put_dev(udev);
2135
2136 + /* we already have busid_priv, just lock busid_lock */
2137 + spin_lock(&busid_priv->busid_lock);
2138 busid_priv->sdev = NULL;
2139 - stub_device_free(sdev);
2140 + busid_priv->status = save_status;
2141 + spin_unlock(&busid_priv->busid_lock);
2142 + /* lock is released - go to free */
2143 + goto sdev_free;
2144
2145 call_put_busid_priv:
2146 + /* release the busid_lock */
2147 put_busid_priv(busid_priv);
2148 +
2149 +sdev_free:
2150 + stub_device_free(sdev);
2151 +
2152 return rc;
2153 }
2154
2155 static void shutdown_busid(struct bus_id_priv *busid_priv)
2156 {
2157 - if (busid_priv->sdev && !busid_priv->shutdown_busid) {
2158 - busid_priv->shutdown_busid = 1;
2159 - usbip_event_add(&busid_priv->sdev->ud, SDEV_EVENT_REMOVED);
2160 + usbip_event_add(&busid_priv->sdev->ud, SDEV_EVENT_REMOVED);
2161
2162 - /* wait for the stop of the event handler */
2163 - usbip_stop_eh(&busid_priv->sdev->ud);
2164 - }
2165 + /* wait for the stop of the event handler */
2166 + usbip_stop_eh(&busid_priv->sdev->ud);
2167 }
2168
2169 /*
2170 @@ -441,11 +458,16 @@ static void stub_disconnect(struct usb_device *udev)
2171 /* get stub_device */
2172 if (!sdev) {
2173 dev_err(&udev->dev, "could not get device");
2174 - goto call_put_busid_priv;
2175 + /* release busid_lock */
2176 + put_busid_priv(busid_priv);
2177 + return;
2178 }
2179
2180 dev_set_drvdata(&udev->dev, NULL);
2181
2182 + /* release busid_lock before call to remove device files */
2183 + put_busid_priv(busid_priv);
2184 +
2185 /*
2186 * NOTE: rx/tx threads are invoked for each usb_device.
2187 */
2188 @@ -456,27 +478,36 @@ static void stub_disconnect(struct usb_device *udev)
2189 (struct usb_dev_state *) udev);
2190 if (rc) {
2191 dev_dbg(&udev->dev, "unable to release port\n");
2192 - goto call_put_busid_priv;
2193 + return;
2194 }
2195
2196 /* If usb reset is called from event handler */
2197 if (usbip_in_eh(current))
2198 - goto call_put_busid_priv;
2199 + return;
2200 +
2201 + /* we already have busid_priv, just lock busid_lock */
2202 + spin_lock(&busid_priv->busid_lock);
2203 + if (!busid_priv->shutdown_busid)
2204 + busid_priv->shutdown_busid = 1;
2205 + /* release busid_lock */
2206 + spin_unlock(&busid_priv->busid_lock);
2207
2208 /* shutdown the current connection */
2209 shutdown_busid(busid_priv);
2210
2211 usb_put_dev(sdev->udev);
2212
2213 + /* we already have busid_priv, just lock busid_lock */
2214 + spin_lock(&busid_priv->busid_lock);
2215 /* free sdev */
2216 busid_priv->sdev = NULL;
2217 stub_device_free(sdev);
2218
2219 if (busid_priv->status == STUB_BUSID_ALLOC)
2220 busid_priv->status = STUB_BUSID_ADDED;
2221 -
2222 -call_put_busid_priv:
2223 - put_busid_priv(busid_priv);
2224 + /* release busid_lock */
2225 + spin_unlock(&busid_priv->busid_lock);
2226 + return;
2227 }
2228
2229 #ifdef CONFIG_PM
2230 diff --git a/drivers/xen/xen-pciback/pciback_ops.c b/drivers/xen/xen-pciback/pciback_ops.c
2231 index f8c77751f330..e7fbed56c044 100644
2232 --- a/drivers/xen/xen-pciback/pciback_ops.c
2233 +++ b/drivers/xen/xen-pciback/pciback_ops.c
2234 @@ -126,8 +126,6 @@ void xen_pcibk_reset_device(struct pci_dev *dev)
2235 if (pci_is_enabled(dev))
2236 pci_disable_device(dev);
2237
2238 - pci_write_config_word(dev, PCI_COMMAND, 0);
2239 -
2240 dev->is_busmaster = 0;
2241 } else {
2242 pci_read_config_word(dev, PCI_COMMAND, &cmd);
2243 diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
2244 index 0a3c6762df1b..07f6ba6ccaa7 100644
2245 --- a/drivers/xen/xenbus/xenbus_dev_frontend.c
2246 +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
2247 @@ -536,7 +536,7 @@ static int xenbus_file_open(struct inode *inode, struct file *filp)
2248 if (xen_store_evtchn == 0)
2249 return -ENOENT;
2250
2251 - nonseekable_open(inode, filp);
2252 + stream_open(inode, filp);
2253
2254 u = kzalloc(sizeof(*u), GFP_KERNEL);
2255 if (u == NULL)
2256 diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
2257 index a36bb75383dc..02bb7b52cb36 100644
2258 --- a/fs/btrfs/tree-log.c
2259 +++ b/fs/btrfs/tree-log.c
2260 @@ -2826,6 +2826,12 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
2261 root->log_transid++;
2262 log->log_transid = root->log_transid;
2263 root->log_start_pid = 0;
2264 + /*
2265 + * Update or create log root item under the root's log_mutex to prevent
2266 + * races with concurrent log syncs that can lead to failure to update
2267 + * log root item because it was not created yet.
2268 + */
2269 + ret = update_log_root(trans, log);
2270 /*
2271 * IO has been started, blocks of the log tree have WRITTEN flag set
2272 * in their headers. new modifications of the log will be written to
2273 @@ -2845,8 +2851,6 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
2274
2275 mutex_unlock(&log_root_tree->log_mutex);
2276
2277 - ret = update_log_root(trans, log);
2278 -
2279 mutex_lock(&log_root_tree->log_mutex);
2280 if (atomic_dec_and_test(&log_root_tree->log_writers)) {
2281 /*
2282 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
2283 index e7f1773b25d6..df3ee0b6264f 100644
2284 --- a/fs/cifs/file.c
2285 +++ b/fs/cifs/file.c
2286 @@ -2892,7 +2892,9 @@ cifs_read_allocate_pages(struct cifs_readdata *rdata, unsigned int nr_pages)
2287 }
2288
2289 if (rc) {
2290 - for (i = 0; i < nr_pages; i++) {
2291 + unsigned int nr_page_failed = i;
2292 +
2293 + for (i = 0; i < nr_page_failed; i++) {
2294 put_page(rdata->pages[i]);
2295 rdata->pages[i] = NULL;
2296 }
2297 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
2298 index 411f16101d1a..eaedbc1a3e95 100644
2299 --- a/fs/fuse/dev.c
2300 +++ b/fs/fuse/dev.c
2301 @@ -1975,10 +1975,8 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
2302 rem += pipe->bufs[(pipe->curbuf + idx) & (pipe->buffers - 1)].len;
2303
2304 ret = -EINVAL;
2305 - if (rem < len) {
2306 - pipe_unlock(pipe);
2307 - goto out;
2308 - }
2309 + if (rem < len)
2310 + goto out_free;
2311
2312 rem = len;
2313 while (rem) {
2314 @@ -1996,7 +1994,9 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
2315 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
2316 pipe->nrbufs--;
2317 } else {
2318 - pipe_buf_get(pipe, ibuf);
2319 + if (!pipe_buf_get(pipe, ibuf))
2320 + goto out_free;
2321 +
2322 *obuf = *ibuf;
2323 obuf->flags &= ~PIPE_BUF_FLAG_GIFT;
2324 obuf->len = rem;
2325 @@ -2019,11 +2019,11 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
2326 ret = fuse_dev_do_write(fud, &cs, len);
2327
2328 pipe_lock(pipe);
2329 +out_free:
2330 for (idx = 0; idx < nbuf; idx++)
2331 pipe_buf_release(pipe, &bufs[idx]);
2332 pipe_unlock(pipe);
2333
2334 -out:
2335 kfree(bufs);
2336 return ret;
2337 }
2338 diff --git a/fs/fuse/file.c b/fs/fuse/file.c
2339 index 037990342321..72be347a0469 100644
2340 --- a/fs/fuse/file.c
2341 +++ b/fs/fuse/file.c
2342 @@ -178,7 +178,9 @@ void fuse_finish_open(struct inode *inode, struct file *file)
2343 file->f_op = &fuse_direct_io_file_operations;
2344 if (!(ff->open_flags & FOPEN_KEEP_CACHE))
2345 invalidate_inode_pages2(inode->i_mapping);
2346 - if (ff->open_flags & FOPEN_NONSEEKABLE)
2347 + if (ff->open_flags & FOPEN_STREAM)
2348 + stream_open(inode, file);
2349 + else if (ff->open_flags & FOPEN_NONSEEKABLE)
2350 nonseekable_open(inode, file);
2351 if (fc->atomic_o_trunc && (file->f_flags & O_TRUNC)) {
2352 struct fuse_inode *fi = get_fuse_inode(inode);
2353 @@ -2965,7 +2967,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
2354 offset + length > i_size_read(inode)) {
2355 err = inode_newsize_ok(inode, offset + length);
2356 if (err)
2357 - return err;
2358 + goto out;
2359 }
2360
2361 if (!(mode & FALLOC_FL_KEEP_SIZE))
2362 diff --git a/fs/open.c b/fs/open.c
2363 index f1deb36ee1b7..6ad9a21f2459 100644
2364 --- a/fs/open.c
2365 +++ b/fs/open.c
2366 @@ -1192,3 +1192,21 @@ int nonseekable_open(struct inode *inode, struct file *filp)
2367 }
2368
2369 EXPORT_SYMBOL(nonseekable_open);
2370 +
2371 +/*
2372 + * stream_open is used by subsystems that want stream-like file descriptors.
2373 + * Such file descriptors are not seekable and don't have notion of position
2374 + * (file.f_pos is always 0). Contrary to file descriptors of other regular
2375 + * files, .read() and .write() can run simultaneously.
2376 + *
2377 + * stream_open never fails and is marked to return int so that it could be
2378 + * directly used as file_operations.open .
2379 + */
2380 +int stream_open(struct inode *inode, struct file *filp)
2381 +{
2382 + filp->f_mode &= ~(FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE | FMODE_ATOMIC_POS);
2383 + filp->f_mode |= FMODE_STREAM;
2384 + return 0;
2385 +}
2386 +
2387 +EXPORT_SYMBOL(stream_open);
2388 diff --git a/fs/pipe.c b/fs/pipe.c
2389 index 388e09a689de..347c6dc888c8 100644
2390 --- a/fs/pipe.c
2391 +++ b/fs/pipe.c
2392 @@ -193,9 +193,9 @@ EXPORT_SYMBOL(generic_pipe_buf_steal);
2393 * in the tee() system call, when we duplicate the buffers in one
2394 * pipe into another.
2395 */
2396 -void generic_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf)
2397 +bool generic_pipe_buf_get(struct pipe_inode_info *pipe, struct pipe_buffer *buf)
2398 {
2399 - get_page(buf->page);
2400 + return try_get_page(buf->page);
2401 }
2402 EXPORT_SYMBOL(generic_pipe_buf_get);
2403
2404 diff --git a/fs/read_write.c b/fs/read_write.c
2405 index 6ab67b860159..9e1fd4c20e89 100644
2406 --- a/fs/read_write.c
2407 +++ b/fs/read_write.c
2408 @@ -575,12 +575,13 @@ EXPORT_SYMBOL(vfs_write);
2409
2410 static inline loff_t file_pos_read(struct file *file)
2411 {
2412 - return file->f_pos;
2413 + return file->f_mode & FMODE_STREAM ? 0 : file->f_pos;
2414 }
2415
2416 static inline void file_pos_write(struct file *file, loff_t pos)
2417 {
2418 - file->f_pos = pos;
2419 + if ((file->f_mode & FMODE_STREAM) == 0)
2420 + file->f_pos = pos;
2421 }
2422
2423 SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
2424 diff --git a/fs/splice.c b/fs/splice.c
2425 index 01983bea760c..8bfbc8a50164 100644
2426 --- a/fs/splice.c
2427 +++ b/fs/splice.c
2428 @@ -1585,7 +1585,11 @@ retry:
2429 * Get a reference to this pipe buffer,
2430 * so we can copy the contents over.
2431 */
2432 - pipe_buf_get(ipipe, ibuf);
2433 + if (!pipe_buf_get(ipipe, ibuf)) {
2434 + if (ret == 0)
2435 + ret = -EFAULT;
2436 + break;
2437 + }
2438 *obuf = *ibuf;
2439
2440 /*
2441 @@ -1659,7 +1663,11 @@ static int link_pipe(struct pipe_inode_info *ipipe,
2442 * Get a reference to this pipe buffer,
2443 * so we can copy the contents over.
2444 */
2445 - pipe_buf_get(ipipe, ibuf);
2446 + if (!pipe_buf_get(ipipe, ibuf)) {
2447 + if (ret == 0)
2448 + ret = -EFAULT;
2449 + break;
2450 + }
2451
2452 obuf = opipe->bufs + nbuf;
2453 *obuf = *ibuf;
2454 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
2455 index d4b167fc9ecb..76ad8a957ffa 100644
2456 --- a/include/linux/bitops.h
2457 +++ b/include/linux/bitops.h
2458 @@ -58,7 +58,7 @@ static __always_inline unsigned long hweight_long(unsigned long w)
2459 */
2460 static inline __u64 rol64(__u64 word, unsigned int shift)
2461 {
2462 - return (word << shift) | (word >> (64 - shift));
2463 + return (word << (shift & 63)) | (word >> ((-shift) & 63));
2464 }
2465
2466 /**
2467 @@ -68,7 +68,7 @@ static inline __u64 rol64(__u64 word, unsigned int shift)
2468 */
2469 static inline __u64 ror64(__u64 word, unsigned int shift)
2470 {
2471 - return (word >> shift) | (word << (64 - shift));
2472 + return (word >> (shift & 63)) | (word << ((-shift) & 63));
2473 }
2474
2475 /**
2476 @@ -78,7 +78,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
2477 */
2478 static inline __u32 rol32(__u32 word, unsigned int shift)
2479 {
2480 - return (word << shift) | (word >> ((-shift) & 31));
2481 + return (word << (shift & 31)) | (word >> ((-shift) & 31));
2482 }
2483
2484 /**
2485 @@ -88,7 +88,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
2486 */
2487 static inline __u32 ror32(__u32 word, unsigned int shift)
2488 {
2489 - return (word >> shift) | (word << (32 - shift));
2490 + return (word >> (shift & 31)) | (word << ((-shift) & 31));
2491 }
2492
2493 /**
2494 @@ -98,7 +98,7 @@ static inline __u32 ror32(__u32 word, unsigned int shift)
2495 */
2496 static inline __u16 rol16(__u16 word, unsigned int shift)
2497 {
2498 - return (word << shift) | (word >> (16 - shift));
2499 + return (word << (shift & 15)) | (word >> ((-shift) & 15));
2500 }
2501
2502 /**
2503 @@ -108,7 +108,7 @@ static inline __u16 rol16(__u16 word, unsigned int shift)
2504 */
2505 static inline __u16 ror16(__u16 word, unsigned int shift)
2506 {
2507 - return (word >> shift) | (word << (16 - shift));
2508 + return (word >> (shift & 15)) | (word << ((-shift) & 15));
2509 }
2510
2511 /**
2512 @@ -118,7 +118,7 @@ static inline __u16 ror16(__u16 word, unsigned int shift)
2513 */
2514 static inline __u8 rol8(__u8 word, unsigned int shift)
2515 {
2516 - return (word << shift) | (word >> (8 - shift));
2517 + return (word << (shift & 7)) | (word >> ((-shift) & 7));
2518 }
2519
2520 /**
2521 @@ -128,7 +128,7 @@ static inline __u8 rol8(__u8 word, unsigned int shift)
2522 */
2523 static inline __u8 ror8(__u8 word, unsigned int shift)
2524 {
2525 - return (word >> shift) | (word << (8 - shift));
2526 + return (word >> (shift & 7)) | (word << ((-shift) & 7));
2527 }
2528
2529 /**
2530 diff --git a/include/linux/cpu.h b/include/linux/cpu.h
2531 index 166686209f2c..b27c9b2e683f 100644
2532 --- a/include/linux/cpu.h
2533 +++ b/include/linux/cpu.h
2534 @@ -271,11 +271,15 @@ extern enum cpuhp_smt_control cpu_smt_control;
2535 extern void cpu_smt_disable(bool force);
2536 extern void cpu_smt_check_topology_early(void);
2537 extern void cpu_smt_check_topology(void);
2538 +extern int cpuhp_smt_enable(void);
2539 +extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval);
2540 #else
2541 # define cpu_smt_control (CPU_SMT_ENABLED)
2542 static inline void cpu_smt_disable(bool force) { }
2543 static inline void cpu_smt_check_topology_early(void) { }
2544 static inline void cpu_smt_check_topology(void) { }
2545 +static inline int cpuhp_smt_enable(void) { return 0; }
2546 +static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; }
2547 #endif
2548
2549 /*
2550 diff --git a/include/linux/efi.h b/include/linux/efi.h
2551 index e6711bf9f0d1..02c4f16685b6 100644
2552 --- a/include/linux/efi.h
2553 +++ b/include/linux/efi.h
2554 @@ -1427,7 +1427,7 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
2555 unsigned long *load_addr,
2556 unsigned long *load_size);
2557
2558 -efi_status_t efi_parse_options(char *cmdline);
2559 +efi_status_t efi_parse_options(char const *cmdline);
2560
2561 efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg,
2562 struct screen_info *si, efi_guid_t *proto,
2563 diff --git a/include/linux/fs.h b/include/linux/fs.h
2564 index bcad2b963296..5244df520bed 100644
2565 --- a/include/linux/fs.h
2566 +++ b/include/linux/fs.h
2567 @@ -143,6 +143,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
2568 /* Has write method(s) */
2569 #define FMODE_CAN_WRITE ((__force fmode_t)0x40000)
2570
2571 +/* File is stream-like */
2572 +#define FMODE_STREAM ((__force fmode_t)0x200000)
2573 +
2574 /* File was opened by fanotify and shouldn't generate fanotify events */
2575 #define FMODE_NONOTIFY ((__force fmode_t)0x4000000)
2576
2577 @@ -2843,6 +2846,7 @@ extern loff_t no_seek_end_llseek_size(struct file *, loff_t, int, loff_t);
2578 extern loff_t no_seek_end_llseek(struct file *, loff_t, int);
2579 extern int generic_file_open(struct inode * inode, struct file * filp);
2580 extern int nonseekable_open(struct inode * inode, struct file * filp);
2581 +extern int stream_open(struct inode * inode, struct file * filp);
2582
2583 #ifdef CONFIG_BLOCK
2584 typedef void (dio_submit_t)(struct bio *bio, struct inode *inode,
2585 diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h
2586 index fa7fd03cb5f9..f2e966937e39 100644
2587 --- a/include/linux/list_lru.h
2588 +++ b/include/linux/list_lru.h
2589 @@ -51,6 +51,7 @@ struct list_lru {
2590 struct list_lru_node *node;
2591 #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
2592 struct list_head list;
2593 + bool memcg_aware;
2594 #endif
2595 };
2596
2597 diff --git a/include/linux/mm.h b/include/linux/mm.h
2598 index e3c8d40a18b5..478466081265 100644
2599 --- a/include/linux/mm.h
2600 +++ b/include/linux/mm.h
2601 @@ -763,6 +763,10 @@ static inline bool is_zone_device_page(const struct page *page)
2602 }
2603 #endif
2604
2605 +/* 127: arbitrary random number, small enough to assemble well */
2606 +#define page_ref_zero_or_close_to_overflow(page) \
2607 + ((unsigned int) page_ref_count(page) + 127u <= 127u)
2608 +
2609 static inline void get_page(struct page *page)
2610 {
2611 page = compound_head(page);
2612 @@ -770,7 +774,7 @@ static inline void get_page(struct page *page)
2613 * Getting a normal page or the head of a compound page
2614 * requires to already have an elevated page->_refcount.
2615 */
2616 - VM_BUG_ON_PAGE(page_ref_count(page) <= 0, page);
2617 + VM_BUG_ON_PAGE(page_ref_zero_or_close_to_overflow(page), page);
2618 page_ref_inc(page);
2619
2620 if (unlikely(is_zone_device_page(page)))
2621 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
2622 index 4f7129389855..c6ae0d5e9f0f 100644
2623 --- a/include/linux/pipe_fs_i.h
2624 +++ b/include/linux/pipe_fs_i.h
2625 @@ -107,18 +107,20 @@ struct pipe_buf_operations {
2626 /*
2627 * Get a reference to the pipe buffer.
2628 */
2629 - void (*get)(struct pipe_inode_info *, struct pipe_buffer *);
2630 + bool (*get)(struct pipe_inode_info *, struct pipe_buffer *);
2631 };
2632
2633 /**
2634 * pipe_buf_get - get a reference to a pipe_buffer
2635 * @pipe: the pipe that the buffer belongs to
2636 * @buf: the buffer to get a reference to
2637 + *
2638 + * Return: %true if the reference was successfully obtained.
2639 */
2640 -static inline void pipe_buf_get(struct pipe_inode_info *pipe,
2641 +static inline __must_check bool pipe_buf_get(struct pipe_inode_info *pipe,
2642 struct pipe_buffer *buf)
2643 {
2644 - buf->ops->get(pipe, buf);
2645 + return buf->ops->get(pipe, buf);
2646 }
2647
2648 /**
2649 @@ -178,7 +180,7 @@ struct pipe_inode_info *alloc_pipe_info(void);
2650 void free_pipe_info(struct pipe_inode_info *);
2651
2652 /* Generic pipe buffer ops functions */
2653 -void generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
2654 +bool generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
2655 int generic_pipe_buf_confirm(struct pipe_inode_info *, struct pipe_buffer *);
2656 int generic_pipe_buf_steal(struct pipe_inode_info *, struct pipe_buffer *);
2657 void generic_pipe_buf_release(struct pipe_inode_info *, struct pipe_buffer *);
2658 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
2659 index 01f71e1d2e94..aa2935779e43 100644
2660 --- a/include/linux/rcupdate.h
2661 +++ b/include/linux/rcupdate.h
2662 @@ -306,14 +306,12 @@ void synchronize_rcu(void);
2663
2664 static inline void __rcu_read_lock(void)
2665 {
2666 - if (IS_ENABLED(CONFIG_PREEMPT_COUNT))
2667 - preempt_disable();
2668 + preempt_disable();
2669 }
2670
2671 static inline void __rcu_read_unlock(void)
2672 {
2673 - if (IS_ENABLED(CONFIG_PREEMPT_COUNT))
2674 - preempt_enable();
2675 + preempt_enable();
2676 }
2677
2678 static inline void synchronize_rcu(void)
2679 diff --git a/include/net/arp.h b/include/net/arp.h
2680 index 1b3f86981757..92d2f7d7d1cb 100644
2681 --- a/include/net/arp.h
2682 +++ b/include/net/arp.h
2683 @@ -17,6 +17,7 @@ static inline u32 arp_hashfn(const void *pkey, const struct net_device *dev, u32
2684 return val * hash_rnd[0];
2685 }
2686
2687 +#ifdef CONFIG_INET
2688 static inline struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key)
2689 {
2690 if (dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))
2691 @@ -24,6 +25,13 @@ static inline struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev
2692
2693 return ___neigh_lookup_noref(&arp_tbl, neigh_key_eq32, arp_hashfn, &key, dev);
2694 }
2695 +#else
2696 +static inline
2697 +struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key)
2698 +{
2699 + return NULL;
2700 +}
2701 +#endif
2702
2703 static inline struct neighbour *__ipv4_neigh_lookup(struct net_device *dev, u32 key)
2704 {
2705 diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
2706 index 03725fe89859..02137b508666 100644
2707 --- a/include/uapi/drm/i915_drm.h
2708 +++ b/include/uapi/drm/i915_drm.h
2709 @@ -756,7 +756,7 @@ struct drm_i915_gem_execbuffer2 {
2710 __u32 num_cliprects;
2711 /** This is a struct drm_clip_rect *cliprects */
2712 __u64 cliprects_ptr;
2713 -#define I915_EXEC_RING_MASK (7<<0)
2714 +#define I915_EXEC_RING_MASK (0x3f)
2715 #define I915_EXEC_DEFAULT (0<<0)
2716 #define I915_EXEC_RENDER (1<<0)
2717 #define I915_EXEC_BSD (2<<0)
2718 diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h
2719 index 42fa977e3b14..8ca749a109d5 100644
2720 --- a/include/uapi/linux/fuse.h
2721 +++ b/include/uapi/linux/fuse.h
2722 @@ -215,10 +215,12 @@ struct fuse_file_lock {
2723 * FOPEN_DIRECT_IO: bypass page cache for this open file
2724 * FOPEN_KEEP_CACHE: don't invalidate the data cache on open
2725 * FOPEN_NONSEEKABLE: the file is not seekable
2726 + * FOPEN_STREAM: the file is stream-like (no file position at all)
2727 */
2728 #define FOPEN_DIRECT_IO (1 << 0)
2729 #define FOPEN_KEEP_CACHE (1 << 1)
2730 #define FOPEN_NONSEEKABLE (1 << 2)
2731 +#define FOPEN_STREAM (1 << 4)
2732
2733 /**
2734 * INIT request/reply flags
2735 diff --git a/include/uapi/linux/tipc_config.h b/include/uapi/linux/tipc_config.h
2736 index 087b0ef82c07..bbebd258cf07 100644
2737 --- a/include/uapi/linux/tipc_config.h
2738 +++ b/include/uapi/linux/tipc_config.h
2739 @@ -301,8 +301,10 @@ static inline int TLV_SET(void *tlv, __u16 type, void *data, __u16 len)
2740 tlv_ptr = (struct tlv_desc *)tlv;
2741 tlv_ptr->tlv_type = htons(type);
2742 tlv_ptr->tlv_len = htons(tlv_len);
2743 - if (len && data)
2744 - memcpy(TLV_DATA(tlv_ptr), data, tlv_len);
2745 + if (len && data) {
2746 + memcpy(TLV_DATA(tlv_ptr), data, len);
2747 + memset(TLV_DATA(tlv_ptr) + len, 0, TLV_SPACE(len) - tlv_len);
2748 + }
2749 return TLV_SPACE(len);
2750 }
2751
2752 @@ -399,8 +401,10 @@ static inline int TCM_SET(void *msg, __u16 cmd, __u16 flags,
2753 tcm_hdr->tcm_len = htonl(msg_len);
2754 tcm_hdr->tcm_type = htons(cmd);
2755 tcm_hdr->tcm_flags = htons(flags);
2756 - if (data_len && data)
2757 + if (data_len && data) {
2758 memcpy(TCM_DATA(msg), data, data_len);
2759 + memset(TCM_DATA(msg) + data_len, 0, TCM_SPACE(data_len) - msg_len);
2760 + }
2761 return TCM_SPACE(data_len);
2762 }
2763
2764 diff --git a/kernel/cpu.c b/kernel/cpu.c
2765 index db1a0bc46c3e..be8cc6c9c87d 100644
2766 --- a/kernel/cpu.c
2767 +++ b/kernel/cpu.c
2768 @@ -1995,7 +1995,7 @@ static void cpuhp_online_cpu_device(unsigned int cpu)
2769 kobject_uevent(&dev->kobj, KOBJ_ONLINE);
2770 }
2771
2772 -static int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval)
2773 +int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval)
2774 {
2775 int cpu, ret = 0;
2776
2777 @@ -2029,7 +2029,7 @@ static int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval)
2778 return ret;
2779 }
2780
2781 -static int cpuhp_smt_enable(void)
2782 +int cpuhp_smt_enable(void)
2783 {
2784 int cpu, ret = 0;
2785
2786 diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
2787 index b26dbc48c75b..81695a492ebe 100644
2788 --- a/kernel/power/hibernate.c
2789 +++ b/kernel/power/hibernate.c
2790 @@ -256,6 +256,11 @@ void swsusp_show_speed(ktime_t start, ktime_t stop,
2791 kps / 1000, (kps % 1000) / 10);
2792 }
2793
2794 +__weak int arch_resume_nosmt(void)
2795 +{
2796 + return 0;
2797 +}
2798 +
2799 /**
2800 * create_image - Create a hibernation image.
2801 * @platform_mode: Whether or not to use the platform driver.
2802 @@ -322,6 +327,10 @@ static int create_image(int platform_mode)
2803 Enable_cpus:
2804 enable_nonboot_cpus();
2805
2806 + /* Allow architectures to do nosmt-specific post-resume dances */
2807 + if (!in_suspend)
2808 + error = arch_resume_nosmt();
2809 +
2810 Platform_finish:
2811 platform_finish(platform_mode);
2812
2813 diff --git a/kernel/signal.c b/kernel/signal.c
2814 index c091dcc9f19b..2bb1f9dc86c7 100644
2815 --- a/kernel/signal.c
2816 +++ b/kernel/signal.c
2817 @@ -2244,6 +2244,8 @@ relock:
2818 if (signal_group_exit(signal)) {
2819 ksig->info.si_signo = signr = SIGKILL;
2820 sigdelset(&current->pending.signal, SIGKILL);
2821 + trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
2822 + &sighand->action[SIGKILL - 1]);
2823 recalc_sigpending();
2824 goto fatal;
2825 }
2826 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
2827 index a2d8bd68c16e..fc59dd11090d 100644
2828 --- a/kernel/trace/trace.c
2829 +++ b/kernel/trace/trace.c
2830 @@ -6145,12 +6145,16 @@ static void buffer_pipe_buf_release(struct pipe_inode_info *pipe,
2831 buf->private = 0;
2832 }
2833
2834 -static void buffer_pipe_buf_get(struct pipe_inode_info *pipe,
2835 +static bool buffer_pipe_buf_get(struct pipe_inode_info *pipe,
2836 struct pipe_buffer *buf)
2837 {
2838 struct buffer_ref *ref = (struct buffer_ref *)buf->private;
2839
2840 + if (ref->ref > INT_MAX/2)
2841 + return false;
2842 +
2843 ref->ref++;
2844 + return true;
2845 }
2846
2847 /* Pipe buffer operations for a buffer. */
2848 diff --git a/mm/gup.c b/mm/gup.c
2849 index 99c2f10188c0..6bb7a8eb7f82 100644
2850 --- a/mm/gup.c
2851 +++ b/mm/gup.c
2852 @@ -153,7 +153,10 @@ retry:
2853 }
2854
2855 if (flags & FOLL_GET) {
2856 - get_page(page);
2857 + if (unlikely(!try_get_page(page))) {
2858 + page = ERR_PTR(-ENOMEM);
2859 + goto out;
2860 + }
2861
2862 /* drop the pgmap reference now that we hold the page */
2863 if (pgmap) {
2864 @@ -292,7 +295,10 @@ struct page *follow_page_mask(struct vm_area_struct *vma,
2865 if (pmd_trans_unstable(pmd))
2866 ret = -EBUSY;
2867 } else {
2868 - get_page(page);
2869 + if (unlikely(!try_get_page(page))) {
2870 + spin_unlock(ptl);
2871 + return ERR_PTR(-ENOMEM);
2872 + }
2873 spin_unlock(ptl);
2874 lock_page(page);
2875 ret = split_huge_page(page);
2876 @@ -348,7 +354,10 @@ static int get_gate_page(struct mm_struct *mm, unsigned long address,
2877 goto unmap;
2878 *page = pte_page(*pte);
2879 }
2880 - get_page(*page);
2881 + if (unlikely(!try_get_page(*page))) {
2882 + ret = -ENOMEM;
2883 + goto unmap;
2884 + }
2885 out:
2886 ret = 0;
2887 unmap:
2888 @@ -1231,6 +1240,20 @@ struct page *get_dump_page(unsigned long addr)
2889 */
2890 #ifdef CONFIG_HAVE_GENERIC_RCU_GUP
2891
2892 +/*
2893 + * Return the compund head page with ref appropriately incremented,
2894 + * or NULL if that failed.
2895 + */
2896 +static inline struct page *try_get_compound_head(struct page *page, int refs)
2897 +{
2898 + struct page *head = compound_head(page);
2899 + if (WARN_ON_ONCE(page_ref_count(head) < 0))
2900 + return NULL;
2901 + if (unlikely(!page_cache_add_speculative(head, refs)))
2902 + return NULL;
2903 + return head;
2904 +}
2905 +
2906 #ifdef __HAVE_ARCH_PTE_SPECIAL
2907 static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
2908 int write, struct page **pages, int *nr)
2909 @@ -1263,9 +1286,9 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
2910
2911 VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
2912 page = pte_page(pte);
2913 - head = compound_head(page);
2914
2915 - if (!page_cache_get_speculative(head))
2916 + head = try_get_compound_head(page, 1);
2917 + if (!head)
2918 goto pte_unmap;
2919
2920 if (unlikely(pte_val(pte) != pte_val(*ptep))) {
2921 @@ -1313,17 +1336,16 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,
2922 return 0;
2923
2924 refs = 0;
2925 - head = pmd_page(orig);
2926 - page = head + ((addr & ~PMD_MASK) >> PAGE_SHIFT);
2927 + page = pmd_page(orig) + ((addr & ~PMD_MASK) >> PAGE_SHIFT);
2928 do {
2929 - VM_BUG_ON_PAGE(compound_head(page) != head, page);
2930 pages[*nr] = page;
2931 (*nr)++;
2932 page++;
2933 refs++;
2934 } while (addr += PAGE_SIZE, addr != end);
2935
2936 - if (!page_cache_add_speculative(head, refs)) {
2937 + head = try_get_compound_head(pmd_page(orig), refs);
2938 + if (!head) {
2939 *nr -= refs;
2940 return 0;
2941 }
2942 @@ -1348,17 +1370,16 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, unsigned long addr,
2943 return 0;
2944
2945 refs = 0;
2946 - head = pud_page(orig);
2947 - page = head + ((addr & ~PUD_MASK) >> PAGE_SHIFT);
2948 + page = pud_page(orig) + ((addr & ~PUD_MASK) >> PAGE_SHIFT);
2949 do {
2950 - VM_BUG_ON_PAGE(compound_head(page) != head, page);
2951 pages[*nr] = page;
2952 (*nr)++;
2953 page++;
2954 refs++;
2955 } while (addr += PAGE_SIZE, addr != end);
2956
2957 - if (!page_cache_add_speculative(head, refs)) {
2958 + head = try_get_compound_head(pud_page(orig), refs);
2959 + if (!head) {
2960 *nr -= refs;
2961 return 0;
2962 }
2963 @@ -1384,17 +1405,16 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr,
2964 return 0;
2965
2966 refs = 0;
2967 - head = pgd_page(orig);
2968 - page = head + ((addr & ~PGDIR_MASK) >> PAGE_SHIFT);
2969 + page = pgd_page(orig) + ((addr & ~PGDIR_MASK) >> PAGE_SHIFT);
2970 do {
2971 - VM_BUG_ON_PAGE(compound_head(page) != head, page);
2972 pages[*nr] = page;
2973 (*nr)++;
2974 page++;
2975 refs++;
2976 } while (addr += PAGE_SIZE, addr != end);
2977
2978 - if (!page_cache_add_speculative(head, refs)) {
2979 + head = try_get_compound_head(pgd_page(orig), refs);
2980 + if (!head) {
2981 *nr -= refs;
2982 return 0;
2983 }
2984 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
2985 index 75d8bd7e8798..6b03cd9b6d37 100644
2986 --- a/mm/hugetlb.c
2987 +++ b/mm/hugetlb.c
2988 @@ -3984,6 +3984,7 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
2989 unsigned long vaddr = *position;
2990 unsigned long remainder = *nr_pages;
2991 struct hstate *h = hstate_vma(vma);
2992 + int err = -EFAULT;
2993
2994 while (vaddr < vma->vm_end && remainder) {
2995 pte_t *pte;
2996 @@ -4055,6 +4056,19 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
2997
2998 pfn_offset = (vaddr & ~huge_page_mask(h)) >> PAGE_SHIFT;
2999 page = pte_page(huge_ptep_get(pte));
3000 +
3001 + /*
3002 + * Instead of doing 'try_get_page()' below in the same_page
3003 + * loop, just check the count once here.
3004 + */
3005 + if (unlikely(page_count(page) <= 0)) {
3006 + if (pages) {
3007 + spin_unlock(ptl);
3008 + remainder = 0;
3009 + err = -ENOMEM;
3010 + break;
3011 + }
3012 + }
3013 same_page:
3014 if (pages) {
3015 pages[i] = mem_map_offset(page, pfn_offset);
3016 @@ -4081,7 +4095,7 @@ same_page:
3017 *nr_pages = remainder;
3018 *position = vaddr;
3019
3020 - return i ? i : -EFAULT;
3021 + return i ? i : err;
3022 }
3023
3024 #ifndef __HAVE_ARCH_FLUSH_HUGETLB_TLB_RANGE
3025 diff --git a/mm/list_lru.c b/mm/list_lru.c
3026 index 7a40fa2be858..db3a77c60201 100644
3027 --- a/mm/list_lru.c
3028 +++ b/mm/list_lru.c
3029 @@ -42,11 +42,7 @@ static void list_lru_unregister(struct list_lru *lru)
3030 #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
3031 static inline bool list_lru_memcg_aware(struct list_lru *lru)
3032 {
3033 - /*
3034 - * This needs node 0 to be always present, even
3035 - * in the systems supporting sparse numa ids.
3036 - */
3037 - return !!lru->node[0].memcg_lrus;
3038 + return lru->memcg_aware;
3039 }
3040
3041 static inline struct list_lru_one *
3042 @@ -389,6 +385,8 @@ static int memcg_init_list_lru(struct list_lru *lru, bool memcg_aware)
3043 {
3044 int i;
3045
3046 + lru->memcg_aware = memcg_aware;
3047 +
3048 if (!memcg_aware)
3049 return 0;
3050
3051 diff --git a/net/core/dev.c b/net/core/dev.c
3052 index 5a3196448bd7..4e10bae5e3da 100644
3053 --- a/net/core/dev.c
3054 +++ b/net/core/dev.c
3055 @@ -4828,7 +4828,6 @@ static struct sk_buff *napi_frags_skb(struct napi_struct *napi)
3056 skb_reset_mac_header(skb);
3057 skb_gro_reset_offset(skb);
3058
3059 - eth = skb_gro_header_fast(skb, 0);
3060 if (unlikely(skb_gro_header_hard(skb, hlen))) {
3061 eth = skb_gro_header_slow(skb, hlen, 0);
3062 if (unlikely(!eth)) {
3063 @@ -4838,6 +4837,7 @@ static struct sk_buff *napi_frags_skb(struct napi_struct *napi)
3064 return NULL;
3065 }
3066 } else {
3067 + eth = (const struct ethhdr *)skb->data;
3068 gro_pull_from_frag0(skb, hlen);
3069 NAPI_GRO_CB(skb)->frag0 += hlen;
3070 NAPI_GRO_CB(skb)->frag0_len -= hlen;
3071 diff --git a/net/core/ethtool.c b/net/core/ethtool.c
3072 index 20ae57fbe009..ffe7b03c9ab5 100644
3073 --- a/net/core/ethtool.c
3074 +++ b/net/core/ethtool.c
3075 @@ -878,8 +878,13 @@ static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
3076 if (rc >= 0)
3077 info.n_priv_flags = rc;
3078 }
3079 - if (ops->get_regs_len)
3080 - info.regdump_len = ops->get_regs_len(dev);
3081 + if (ops->get_regs_len) {
3082 + int ret = ops->get_regs_len(dev);
3083 +
3084 + if (ret > 0)
3085 + info.regdump_len = ret;
3086 + }
3087 +
3088 if (ops->get_eeprom_len)
3089 info.eedump_len = ops->get_eeprom_len(dev);
3090
3091 @@ -1380,6 +1385,9 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
3092 return -EFAULT;
3093
3094 reglen = ops->get_regs_len(dev);
3095 + if (reglen <= 0)
3096 + return reglen;
3097 +
3098 if (regs.len > reglen)
3099 regs.len = reglen;
3100
3101 @@ -1390,13 +1398,16 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
3102 return -ENOMEM;
3103 }
3104
3105 + if (regs.len < reglen)
3106 + reglen = regs.len;
3107 +
3108 ops->get_regs(dev, &regs, regbuf);
3109
3110 ret = -EFAULT;
3111 if (copy_to_user(useraddr, &regs, sizeof(regs)))
3112 goto out;
3113 useraddr += offsetof(struct ethtool_regs, data);
3114 - if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
3115 + if (copy_to_user(useraddr, regbuf, reglen))
3116 goto out;
3117 ret = 0;
3118
3119 diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
3120 index c03dd2104d33..be4629c344a6 100644
3121 --- a/net/core/fib_rules.c
3122 +++ b/net/core/fib_rules.c
3123 @@ -429,10 +429,9 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh)
3124 if (rule->l3mdev && rule->table)
3125 goto errout_free;
3126
3127 - if (rule_exists(ops, frh, tb, rule)) {
3128 - err = 0;
3129 - if (nlh->nlmsg_flags & NLM_F_EXCL)
3130 - err = -EEXIST;
3131 + if ((nlh->nlmsg_flags & NLM_F_EXCL) &&
3132 + rule_exists(ops, frh, tb, rule)) {
3133 + err = -EEXIST;
3134 goto errout_free;
3135 }
3136
3137 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
3138 index 8eb1916b742c..428dd614a18a 100644
3139 --- a/net/core/neighbour.c
3140 +++ b/net/core/neighbour.c
3141 @@ -30,6 +30,7 @@
3142 #include <linux/times.h>
3143 #include <net/net_namespace.h>
3144 #include <net/neighbour.h>
3145 +#include <net/arp.h>
3146 #include <net/dst.h>
3147 #include <net/sock.h>
3148 #include <net/netevent.h>
3149 @@ -2489,7 +2490,13 @@ int neigh_xmit(int index, struct net_device *dev,
3150 if (!tbl)
3151 goto out;
3152 rcu_read_lock_bh();
3153 - neigh = __neigh_lookup_noref(tbl, addr, dev);
3154 + if (index == NEIGH_ARP_TABLE) {
3155 + u32 key = *((u32 *)addr);
3156 +
3157 + neigh = __ipv4_neigh_lookup_noref(dev, key);
3158 + } else {
3159 + neigh = __neigh_lookup_noref(tbl, addr, dev);
3160 + }
3161 if (!neigh)
3162 neigh = __neigh_create(tbl, addr, dev, false);
3163 err = PTR_ERR(neigh);
3164 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
3165 index 306b8f0e03c1..433b26feb320 100644
3166 --- a/net/core/pktgen.c
3167 +++ b/net/core/pktgen.c
3168 @@ -3147,7 +3147,13 @@ static int pktgen_wait_thread_run(struct pktgen_thread *t)
3169 {
3170 while (thread_is_running(t)) {
3171
3172 + /* note: 't' will still be around even after the unlock/lock
3173 + * cycle because pktgen_thread threads are only cleared at
3174 + * net exit
3175 + */
3176 + mutex_unlock(&pktgen_thread_lock);
3177 msleep_interruptible(100);
3178 + mutex_lock(&pktgen_thread_lock);
3179
3180 if (signal_pending(current))
3181 goto signal;
3182 @@ -3162,6 +3168,10 @@ static int pktgen_wait_all_threads_run(struct pktgen_net *pn)
3183 struct pktgen_thread *t;
3184 int sig = 1;
3185
3186 + /* prevent from racing with rmmod */
3187 + if (!try_module_get(THIS_MODULE))
3188 + return sig;
3189 +
3190 mutex_lock(&pktgen_thread_lock);
3191
3192 list_for_each_entry(t, &pn->pktgen_threads, th_list) {
3193 @@ -3175,6 +3185,7 @@ static int pktgen_wait_all_threads_run(struct pktgen_net *pn)
3194 t->control |= (T_STOP);
3195
3196 mutex_unlock(&pktgen_thread_lock);
3197 + module_put(THIS_MODULE);
3198 return sig;
3199 }
3200
3201 diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
3202 index f2e6e874e4ec..780dc6fe899d 100644
3203 --- a/net/ipv4/igmp.c
3204 +++ b/net/ipv4/igmp.c
3205 @@ -190,6 +190,17 @@ static void ip_ma_put(struct ip_mc_list *im)
3206 pmc != NULL; \
3207 pmc = rtnl_dereference(pmc->next_rcu))
3208
3209 +static void ip_sf_list_clear_all(struct ip_sf_list *psf)
3210 +{
3211 + struct ip_sf_list *next;
3212 +
3213 + while (psf) {
3214 + next = psf->sf_next;
3215 + kfree(psf);
3216 + psf = next;
3217 + }
3218 +}
3219 +
3220 #ifdef CONFIG_IP_MULTICAST
3221
3222 /*
3223 @@ -635,6 +646,13 @@ static void igmpv3_clear_zeros(struct ip_sf_list **ppsf)
3224 }
3225 }
3226
3227 +static void kfree_pmc(struct ip_mc_list *pmc)
3228 +{
3229 + ip_sf_list_clear_all(pmc->sources);
3230 + ip_sf_list_clear_all(pmc->tomb);
3231 + kfree(pmc);
3232 +}
3233 +
3234 static void igmpv3_send_cr(struct in_device *in_dev)
3235 {
3236 struct ip_mc_list *pmc, *pmc_prev, *pmc_next;
3237 @@ -671,7 +689,7 @@ static void igmpv3_send_cr(struct in_device *in_dev)
3238 else
3239 in_dev->mc_tomb = pmc_next;
3240 in_dev_put(pmc->interface);
3241 - kfree(pmc);
3242 + kfree_pmc(pmc);
3243 } else
3244 pmc_prev = pmc;
3245 }
3246 @@ -1195,12 +1213,16 @@ static void igmpv3_del_delrec(struct in_device *in_dev, struct ip_mc_list *im)
3247 im->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv;
3248 if (im->sfmode == MCAST_INCLUDE) {
3249 im->tomb = pmc->tomb;
3250 + pmc->tomb = NULL;
3251 +
3252 im->sources = pmc->sources;
3253 + pmc->sources = NULL;
3254 +
3255 for (psf = im->sources; psf; psf = psf->sf_next)
3256 psf->sf_crcount = im->crcount;
3257 }
3258 in_dev_put(pmc->interface);
3259 - kfree(pmc);
3260 + kfree_pmc(pmc);
3261 }
3262 spin_unlock_bh(&im->lock);
3263 }
3264 @@ -1221,21 +1243,18 @@ static void igmpv3_clear_delrec(struct in_device *in_dev)
3265 nextpmc = pmc->next;
3266 ip_mc_clear_src(pmc);
3267 in_dev_put(pmc->interface);
3268 - kfree(pmc);
3269 + kfree_pmc(pmc);
3270 }
3271 /* clear dead sources, too */
3272 rcu_read_lock();
3273 for_each_pmc_rcu(in_dev, pmc) {
3274 - struct ip_sf_list *psf, *psf_next;
3275 + struct ip_sf_list *psf;
3276
3277 spin_lock_bh(&pmc->lock);
3278 psf = pmc->tomb;
3279 pmc->tomb = NULL;
3280 spin_unlock_bh(&pmc->lock);
3281 - for (; psf; psf = psf_next) {
3282 - psf_next = psf->sf_next;
3283 - kfree(psf);
3284 - }
3285 + ip_sf_list_clear_all(psf);
3286 }
3287 rcu_read_unlock();
3288 }
3289 @@ -2099,7 +2118,7 @@ static int ip_mc_add_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
3290
3291 static void ip_mc_clear_src(struct ip_mc_list *pmc)
3292 {
3293 - struct ip_sf_list *psf, *nextpsf, *tomb, *sources;
3294 + struct ip_sf_list *tomb, *sources;
3295
3296 spin_lock_bh(&pmc->lock);
3297 tomb = pmc->tomb;
3298 @@ -2111,14 +2130,8 @@ static void ip_mc_clear_src(struct ip_mc_list *pmc)
3299 pmc->sfcount[MCAST_EXCLUDE] = 1;
3300 spin_unlock_bh(&pmc->lock);
3301
3302 - for (psf = tomb; psf; psf = nextpsf) {
3303 - nextpsf = psf->sf_next;
3304 - kfree(psf);
3305 - }
3306 - for (psf = sources; psf; psf = nextpsf) {
3307 - nextpsf = psf->sf_next;
3308 - kfree(psf);
3309 - }
3310 + ip_sf_list_clear_all(tomb);
3311 + ip_sf_list_clear_all(sources);
3312 }
3313
3314 /* Join a multicast group
3315 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
3316 index a4f979ff31b9..301978df650e 100644
3317 --- a/net/ipv6/raw.c
3318 +++ b/net/ipv6/raw.c
3319 @@ -283,7 +283,9 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
3320 /* Binding to link-local address requires an interface */
3321 if (!sk->sk_bound_dev_if)
3322 goto out_unlock;
3323 + }
3324
3325 + if (sk->sk_bound_dev_if) {
3326 err = -ENODEV;
3327 dev = dev_get_by_index_rcu(sock_net(sk),
3328 sk->sk_bound_dev_if);
3329 @@ -772,6 +774,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
3330 struct sockcm_cookie sockc;
3331 struct ipcm6_cookie ipc6;
3332 int addr_len = msg->msg_namelen;
3333 + int hdrincl;
3334 u16 proto;
3335 int err;
3336
3337 @@ -785,6 +788,13 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
3338 if (msg->msg_flags & MSG_OOB)
3339 return -EOPNOTSUPP;
3340
3341 + /* hdrincl should be READ_ONCE(inet->hdrincl)
3342 + * but READ_ONCE() doesn't work with bit fields.
3343 + * Doing this indirectly yields the same result.
3344 + */
3345 + hdrincl = inet->hdrincl;
3346 + hdrincl = READ_ONCE(hdrincl);
3347 +
3348 /*
3349 * Get and verify the address.
3350 */
3351 @@ -878,11 +888,14 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
3352 opt = ipv6_fixup_options(&opt_space, opt);
3353
3354 fl6.flowi6_proto = proto;
3355 - rfv.msg = msg;
3356 - rfv.hlen = 0;
3357 - err = rawv6_probe_proto_opt(&rfv, &fl6);
3358 - if (err)
3359 - goto out;
3360 +
3361 + if (!hdrincl) {
3362 + rfv.msg = msg;
3363 + rfv.hlen = 0;
3364 + err = rawv6_probe_proto_opt(&rfv, &fl6);
3365 + if (err)
3366 + goto out;
3367 + }
3368
3369 if (!ipv6_addr_any(daddr))
3370 fl6.daddr = *daddr;
3371 @@ -899,7 +912,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
3372 fl6.flowi6_oif = np->ucast_oif;
3373 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
3374
3375 - if (inet->hdrincl)
3376 + if (hdrincl)
3377 fl6.flowi6_flags |= FLOWI_FLAG_KNOWN_NH;
3378
3379 if (ipc6.tclass < 0)
3380 @@ -922,7 +935,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
3381 goto do_confirm;
3382
3383 back_from_confirm:
3384 - if (inet->hdrincl)
3385 + if (hdrincl)
3386 err = rawv6_send_hdrinc(sk, msg, len, &fl6, &dst, msg->msg_flags);
3387 else {
3388 ipc6.opt = opt;
3389 diff --git a/net/llc/llc_output.c b/net/llc/llc_output.c
3390 index 94425e421213..9e4b6bcf6920 100644
3391 --- a/net/llc/llc_output.c
3392 +++ b/net/llc/llc_output.c
3393 @@ -72,6 +72,8 @@ int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
3394 rc = llc_mac_hdr_init(skb, skb->dev->dev_addr, dmac);
3395 if (likely(!rc))
3396 rc = dev_queue_xmit(skb);
3397 + else
3398 + kfree_skb(skb);
3399 return rc;
3400 }
3401
3402 diff --git a/net/rds/ib_rdma.c b/net/rds/ib_rdma.c
3403 index 91b53d462fc0..78d5d68cbbce 100644
3404 --- a/net/rds/ib_rdma.c
3405 +++ b/net/rds/ib_rdma.c
3406 @@ -416,12 +416,14 @@ int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool,
3407 wait_clean_list_grace();
3408
3409 list_to_llist_nodes(pool, &unmap_list, &clean_nodes, &clean_tail);
3410 - if (ibmr_ret)
3411 + if (ibmr_ret) {
3412 *ibmr_ret = llist_entry(clean_nodes, struct rds_ib_mr, llnode);
3413 -
3414 + clean_nodes = clean_nodes->next;
3415 + }
3416 /* more than one entry in llist nodes */
3417 - if (clean_nodes->next)
3418 - llist_add_batch(clean_nodes->next, clean_tail, &pool->clean_list);
3419 + if (clean_nodes)
3420 + llist_add_batch(clean_nodes, clean_tail,
3421 + &pool->clean_list);
3422
3423 }
3424
3425 diff --git a/net/tipc/core.c b/net/tipc/core.c
3426 index 974694121ce9..816c125bfc13 100644
3427 --- a/net/tipc/core.c
3428 +++ b/net/tipc/core.c
3429 @@ -62,10 +62,6 @@ static int __net_init tipc_init_net(struct net *net)
3430 INIT_LIST_HEAD(&tn->node_list);
3431 spin_lock_init(&tn->node_list_lock);
3432
3433 - err = tipc_socket_init();
3434 - if (err)
3435 - goto out_socket;
3436 -
3437 err = tipc_sk_rht_init(net);
3438 if (err)
3439 goto out_sk_rht;
3440 @@ -75,9 +71,6 @@ static int __net_init tipc_init_net(struct net *net)
3441 goto out_nametbl;
3442
3443 INIT_LIST_HEAD(&tn->dist_queue);
3444 - err = tipc_topsrv_start(net);
3445 - if (err)
3446 - goto out_subscr;
3447
3448 err = tipc_bcast_init(net);
3449 if (err)
3450 @@ -86,25 +79,19 @@ static int __net_init tipc_init_net(struct net *net)
3451 return 0;
3452
3453 out_bclink:
3454 - tipc_bcast_stop(net);
3455 -out_subscr:
3456 tipc_nametbl_stop(net);
3457 out_nametbl:
3458 tipc_sk_rht_destroy(net);
3459 out_sk_rht:
3460 - tipc_socket_stop();
3461 -out_socket:
3462 return err;
3463 }
3464
3465 static void __net_exit tipc_exit_net(struct net *net)
3466 {
3467 - tipc_topsrv_stop(net);
3468 tipc_net_stop(net);
3469 tipc_bcast_stop(net);
3470 tipc_nametbl_stop(net);
3471 tipc_sk_rht_destroy(net);
3472 - tipc_socket_stop();
3473 }
3474
3475 static struct pernet_operations tipc_net_ops = {
3476 @@ -114,6 +101,11 @@ static struct pernet_operations tipc_net_ops = {
3477 .size = sizeof(struct tipc_net),
3478 };
3479
3480 +static struct pernet_operations tipc_topsrv_net_ops = {
3481 + .init = tipc_topsrv_init_net,
3482 + .exit = tipc_topsrv_exit_net,
3483 +};
3484 +
3485 static int __init tipc_init(void)
3486 {
3487 int err;
3488 @@ -140,6 +132,14 @@ static int __init tipc_init(void)
3489 if (err)
3490 goto out_pernet;
3491
3492 + err = tipc_socket_init();
3493 + if (err)
3494 + goto out_socket;
3495 +
3496 + err = register_pernet_subsys(&tipc_topsrv_net_ops);
3497 + if (err)
3498 + goto out_pernet_topsrv;
3499 +
3500 err = tipc_bearer_setup();
3501 if (err)
3502 goto out_bearer;
3503 @@ -147,6 +147,10 @@ static int __init tipc_init(void)
3504 pr_info("Started in single node mode\n");
3505 return 0;
3506 out_bearer:
3507 + unregister_pernet_subsys(&tipc_topsrv_net_ops);
3508 +out_pernet_topsrv:
3509 + tipc_socket_stop();
3510 +out_socket:
3511 unregister_pernet_subsys(&tipc_net_ops);
3512 out_pernet:
3513 tipc_unregister_sysctl();
3514 @@ -162,6 +166,8 @@ out_netlink:
3515 static void __exit tipc_exit(void)
3516 {
3517 tipc_bearer_cleanup();
3518 + unregister_pernet_subsys(&tipc_topsrv_net_ops);
3519 + tipc_socket_stop();
3520 unregister_pernet_subsys(&tipc_net_ops);
3521 tipc_netlink_stop();
3522 tipc_netlink_compat_stop();
3523 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
3524 index d62affeb2a38..5e6dc7276abe 100644
3525 --- a/net/tipc/subscr.c
3526 +++ b/net/tipc/subscr.c
3527 @@ -358,7 +358,7 @@ static void *tipc_subscrb_connect_cb(int conid)
3528 return (void *)tipc_subscrb_create(conid);
3529 }
3530
3531 -int tipc_topsrv_start(struct net *net)
3532 +static int tipc_topsrv_start(struct net *net)
3533 {
3534 struct tipc_net *tn = net_generic(net, tipc_net_id);
3535 const char name[] = "topology_server";
3536 @@ -396,7 +396,7 @@ int tipc_topsrv_start(struct net *net)
3537 return tipc_server_start(topsrv);
3538 }
3539
3540 -void tipc_topsrv_stop(struct net *net)
3541 +static void tipc_topsrv_stop(struct net *net)
3542 {
3543 struct tipc_net *tn = net_generic(net, tipc_net_id);
3544 struct tipc_server *topsrv = tn->topsrv;
3545 @@ -405,3 +405,13 @@ void tipc_topsrv_stop(struct net *net)
3546 kfree(topsrv->saddr);
3547 kfree(topsrv);
3548 }
3549 +
3550 +int __net_init tipc_topsrv_init_net(struct net *net)
3551 +{
3552 + return tipc_topsrv_start(net);
3553 +}
3554 +
3555 +void __net_exit tipc_topsrv_exit_net(struct net *net)
3556 +{
3557 + tipc_topsrv_stop(net);
3558 +}
3559 diff --git a/net/tipc/subscr.h b/net/tipc/subscr.h
3560 index ffdc214c117a..814dfcef33c2 100644
3561 --- a/net/tipc/subscr.h
3562 +++ b/net/tipc/subscr.h
3563 @@ -75,7 +75,8 @@ void tipc_subscrp_report_overlap(struct tipc_subscription *sub,
3564 void tipc_subscrp_convert_seq(struct tipc_name_seq *in, int swap,
3565 struct tipc_name_seq *out);
3566 u32 tipc_subscrp_convert_seq_type(u32 type, int swap);
3567 -int tipc_topsrv_start(struct net *net);
3568 -void tipc_topsrv_stop(struct net *net);
3569 +
3570 +int __net_init tipc_topsrv_init_net(struct net *net);
3571 +void __net_exit tipc_topsrv_exit_net(struct net *net);
3572
3573 #endif
3574 diff --git a/scripts/coccinelle/api/stream_open.cocci b/scripts/coccinelle/api/stream_open.cocci
3575 new file mode 100644
3576 index 000000000000..350145da7669
3577 --- /dev/null
3578 +++ b/scripts/coccinelle/api/stream_open.cocci
3579 @@ -0,0 +1,363 @@
3580 +// SPDX-License-Identifier: GPL-2.0
3581 +// Author: Kirill Smelkov (kirr@nexedi.com)
3582 +//
3583 +// Search for stream-like files that are using nonseekable_open and convert
3584 +// them to stream_open. A stream-like file is a file that does not use ppos in
3585 +// its read and write. Rationale for the conversion is to avoid deadlock in
3586 +// between read and write.
3587 +
3588 +virtual report
3589 +virtual patch
3590 +virtual explain // explain decisions in the patch (SPFLAGS="-D explain")
3591 +
3592 +// stream-like reader & writer - ones that do not depend on f_pos.
3593 +@ stream_reader @
3594 +identifier readstream, ppos;
3595 +identifier f, buf, len;
3596 +type loff_t;
3597 +@@
3598 + ssize_t readstream(struct file *f, char *buf, size_t len, loff_t *ppos)
3599 + {
3600 + ... when != ppos
3601 + }
3602 +
3603 +@ stream_writer @
3604 +identifier writestream, ppos;
3605 +identifier f, buf, len;
3606 +type loff_t;
3607 +@@
3608 + ssize_t writestream(struct file *f, const char *buf, size_t len, loff_t *ppos)
3609 + {
3610 + ... when != ppos
3611 + }
3612 +
3613 +
3614 +// a function that blocks
3615 +@ blocks @
3616 +identifier block_f;
3617 +identifier wait_event =~ "^wait_event_.*";
3618 +@@
3619 + block_f(...) {
3620 + ... when exists
3621 + wait_event(...)
3622 + ... when exists
3623 + }
3624 +
3625 +// stream_reader that can block inside.
3626 +//
3627 +// XXX wait_* can be called not directly from current function (e.g. func -> f -> g -> wait())
3628 +// XXX currently reader_blocks supports only direct and 1-level indirect cases.
3629 +@ reader_blocks_direct @
3630 +identifier stream_reader.readstream;
3631 +identifier wait_event =~ "^wait_event_.*";
3632 +@@
3633 + readstream(...)
3634 + {
3635 + ... when exists
3636 + wait_event(...)
3637 + ... when exists
3638 + }
3639 +
3640 +@ reader_blocks_1 @
3641 +identifier stream_reader.readstream;
3642 +identifier blocks.block_f;
3643 +@@
3644 + readstream(...)
3645 + {
3646 + ... when exists
3647 + block_f(...)
3648 + ... when exists
3649 + }
3650 +
3651 +@ reader_blocks depends on reader_blocks_direct || reader_blocks_1 @
3652 +identifier stream_reader.readstream;
3653 +@@
3654 + readstream(...) {
3655 + ...
3656 + }
3657 +
3658 +
3659 +// file_operations + whether they have _any_ .read, .write, .llseek ... at all.
3660 +//
3661 +// XXX add support for file_operations xxx[N] = ... (sound/core/pcm_native.c)
3662 +@ fops0 @
3663 +identifier fops;
3664 +@@
3665 + struct file_operations fops = {
3666 + ...
3667 + };
3668 +
3669 +@ has_read @
3670 +identifier fops0.fops;
3671 +identifier read_f;
3672 +@@
3673 + struct file_operations fops = {
3674 + .read = read_f,
3675 + };
3676 +
3677 +@ has_read_iter @
3678 +identifier fops0.fops;
3679 +identifier read_iter_f;
3680 +@@
3681 + struct file_operations fops = {
3682 + .read_iter = read_iter_f,
3683 + };
3684 +
3685 +@ has_write @
3686 +identifier fops0.fops;
3687 +identifier write_f;
3688 +@@
3689 + struct file_operations fops = {
3690 + .write = write_f,
3691 + };
3692 +
3693 +@ has_write_iter @
3694 +identifier fops0.fops;
3695 +identifier write_iter_f;
3696 +@@
3697 + struct file_operations fops = {
3698 + .write_iter = write_iter_f,
3699 + };
3700 +
3701 +@ has_llseek @
3702 +identifier fops0.fops;
3703 +identifier llseek_f;
3704 +@@
3705 + struct file_operations fops = {
3706 + .llseek = llseek_f,
3707 + };
3708 +
3709 +@ has_no_llseek @
3710 +identifier fops0.fops;
3711 +@@
3712 + struct file_operations fops = {
3713 + .llseek = no_llseek,
3714 + };
3715 +
3716 +@ has_mmap @
3717 +identifier fops0.fops;
3718 +identifier mmap_f;
3719 +@@
3720 + struct file_operations fops = {
3721 + .mmap = mmap_f,
3722 + };
3723 +
3724 +@ has_copy_file_range @
3725 +identifier fops0.fops;
3726 +identifier copy_file_range_f;
3727 +@@
3728 + struct file_operations fops = {
3729 + .copy_file_range = copy_file_range_f,
3730 + };
3731 +
3732 +@ has_remap_file_range @
3733 +identifier fops0.fops;
3734 +identifier remap_file_range_f;
3735 +@@
3736 + struct file_operations fops = {
3737 + .remap_file_range = remap_file_range_f,
3738 + };
3739 +
3740 +@ has_splice_read @
3741 +identifier fops0.fops;
3742 +identifier splice_read_f;
3743 +@@
3744 + struct file_operations fops = {
3745 + .splice_read = splice_read_f,
3746 + };
3747 +
3748 +@ has_splice_write @
3749 +identifier fops0.fops;
3750 +identifier splice_write_f;
3751 +@@
3752 + struct file_operations fops = {
3753 + .splice_write = splice_write_f,
3754 + };
3755 +
3756 +
3757 +// file_operations that is candidate for stream_open conversion - it does not
3758 +// use mmap and other methods that assume @offset access to file.
3759 +//
3760 +// XXX for simplicity require no .{read/write}_iter and no .splice_{read/write} for now.
3761 +// XXX maybe_steam.fops cannot be used in other rules - it gives "bad rule maybe_stream or bad variable fops".
3762 +@ maybe_stream depends on (!has_llseek || has_no_llseek) && !has_mmap && !has_copy_file_range && !has_remap_file_range && !has_read_iter && !has_write_iter && !has_splice_read && !has_splice_write @
3763 +identifier fops0.fops;
3764 +@@
3765 + struct file_operations fops = {
3766 + };
3767 +
3768 +
3769 +// ---- conversions ----
3770 +
3771 +// XXX .open = nonseekable_open -> .open = stream_open
3772 +// XXX .open = func -> openfunc -> nonseekable_open
3773 +
3774 +// read & write
3775 +//
3776 +// if both are used in the same file_operations together with an opener -
3777 +// under that conditions we can use stream_open instead of nonseekable_open.
3778 +@ fops_rw depends on maybe_stream @
3779 +identifier fops0.fops, openfunc;
3780 +identifier stream_reader.readstream;
3781 +identifier stream_writer.writestream;
3782 +@@
3783 + struct file_operations fops = {
3784 + .open = openfunc,
3785 + .read = readstream,
3786 + .write = writestream,
3787 + };
3788 +
3789 +@ report_rw depends on report @
3790 +identifier fops_rw.openfunc;
3791 +position p1;
3792 +@@
3793 + openfunc(...) {
3794 + <...
3795 + nonseekable_open@p1
3796 + ...>
3797 + }
3798 +
3799 +@ script:python depends on report && reader_blocks @
3800 +fops << fops0.fops;
3801 +p << report_rw.p1;
3802 +@@
3803 +coccilib.report.print_report(p[0],
3804 + "ERROR: %s: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix." % (fops,))
3805 +
3806 +@ script:python depends on report && !reader_blocks @
3807 +fops << fops0.fops;
3808 +p << report_rw.p1;
3809 +@@
3810 +coccilib.report.print_report(p[0],
3811 + "WARNING: %s: .read() and .write() have stream semantic; safe to change nonseekable_open -> stream_open." % (fops,))
3812 +
3813 +
3814 +@ explain_rw_deadlocked depends on explain && reader_blocks @
3815 +identifier fops_rw.openfunc;
3816 +@@
3817 + openfunc(...) {
3818 + <...
3819 +- nonseekable_open
3820 ++ nonseekable_open /* read & write (was deadlock) */
3821 + ...>
3822 + }
3823 +
3824 +
3825 +@ explain_rw_nodeadlock depends on explain && !reader_blocks @
3826 +identifier fops_rw.openfunc;
3827 +@@
3828 + openfunc(...) {
3829 + <...
3830 +- nonseekable_open
3831 ++ nonseekable_open /* read & write (no direct deadlock) */
3832 + ...>
3833 + }
3834 +
3835 +@ patch_rw depends on patch @
3836 +identifier fops_rw.openfunc;
3837 +@@
3838 + openfunc(...) {
3839 + <...
3840 +- nonseekable_open
3841 ++ stream_open
3842 + ...>
3843 + }
3844 +
3845 +
3846 +// read, but not write
3847 +@ fops_r depends on maybe_stream && !has_write @
3848 +identifier fops0.fops, openfunc;
3849 +identifier stream_reader.readstream;
3850 +@@
3851 + struct file_operations fops = {
3852 + .open = openfunc,
3853 + .read = readstream,
3854 + };
3855 +
3856 +@ report_r depends on report @
3857 +identifier fops_r.openfunc;
3858 +position p1;
3859 +@@
3860 + openfunc(...) {
3861 + <...
3862 + nonseekable_open@p1
3863 + ...>
3864 + }
3865 +
3866 +@ script:python depends on report @
3867 +fops << fops0.fops;
3868 +p << report_r.p1;
3869 +@@
3870 +coccilib.report.print_report(p[0],
3871 + "WARNING: %s: .read() has stream semantic; safe to change nonseekable_open -> stream_open." % (fops,))
3872 +
3873 +@ explain_r depends on explain @
3874 +identifier fops_r.openfunc;
3875 +@@
3876 + openfunc(...) {
3877 + <...
3878 +- nonseekable_open
3879 ++ nonseekable_open /* read only */
3880 + ...>
3881 + }
3882 +
3883 +@ patch_r depends on patch @
3884 +identifier fops_r.openfunc;
3885 +@@
3886 + openfunc(...) {
3887 + <...
3888 +- nonseekable_open
3889 ++ stream_open
3890 + ...>
3891 + }
3892 +
3893 +
3894 +// write, but not read
3895 +@ fops_w depends on maybe_stream && !has_read @
3896 +identifier fops0.fops, openfunc;
3897 +identifier stream_writer.writestream;
3898 +@@
3899 + struct file_operations fops = {
3900 + .open = openfunc,
3901 + .write = writestream,
3902 + };
3903 +
3904 +@ report_w depends on report @
3905 +identifier fops_w.openfunc;
3906 +position p1;
3907 +@@
3908 + openfunc(...) {
3909 + <...
3910 + nonseekable_open@p1
3911 + ...>
3912 + }
3913 +
3914 +@ script:python depends on report @
3915 +fops << fops0.fops;
3916 +p << report_w.p1;
3917 +@@
3918 +coccilib.report.print_report(p[0],
3919 + "WARNING: %s: .write() has stream semantic; safe to change nonseekable_open -> stream_open." % (fops,))
3920 +
3921 +@ explain_w depends on explain @
3922 +identifier fops_w.openfunc;
3923 +@@
3924 + openfunc(...) {
3925 + <...
3926 +- nonseekable_open
3927 ++ nonseekable_open /* write only */
3928 + ...>
3929 + }
3930 +
3931 +@ patch_w depends on patch @
3932 +identifier fops_w.openfunc;
3933 +@@
3934 + openfunc(...) {
3935 + <...
3936 +- nonseekable_open
3937 ++ stream_open
3938 + ...>
3939 + }
3940 +
3941 +
3942 +// no read, no write - don't change anything
3943 diff --git a/scripts/gcc-plugins/gcc-common.h b/scripts/gcc-plugins/gcc-common.h
3944 index 12262c0cc691..08fe09c28bd2 100644
3945 --- a/scripts/gcc-plugins/gcc-common.h
3946 +++ b/scripts/gcc-plugins/gcc-common.h
3947 @@ -135,8 +135,12 @@ extern void print_gimple_expr(FILE *, gimple, int, int);
3948 extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
3949 #endif
3950
3951 +#ifndef __unused
3952 #define __unused __attribute__((__unused__))
3953 +#endif
3954 +#ifndef __visible
3955 #define __visible __attribute__((visibility("default")))
3956 +#endif
3957
3958 #define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
3959 #define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
3960 diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
3961 index 822650d907fa..95fb213cf94b 100644
3962 --- a/sound/pci/hda/patch_realtek.c
3963 +++ b/sound/pci/hda/patch_realtek.c
3964 @@ -6317,7 +6317,7 @@ static int patch_alc269(struct hda_codec *codec)
3965
3966 spec = codec->spec;
3967 spec->gen.shared_mic_vref_pin = 0x18;
3968 - codec->power_save_node = 1;
3969 + codec->power_save_node = 0;
3970
3971 #ifdef CONFIG_PM
3972 codec->patch_ops.suspend = alc269_suspend;