Magellan Linux

Annotation of /trunk/kernel-alx/patches-4.9/0262-4.9.163-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3322 - (hide annotations) (download)
Thu Mar 14 15:04:22 2019 UTC (5 years, 2 months ago) by niro
File size: 118013 byte(s)
-linux-4.9.163
1 niro 3322 diff --git a/Makefile b/Makefile
2     index fce163d09139..8a5330e279ad 100644
3     --- a/Makefile
4     +++ b/Makefile
5     @@ -1,6 +1,6 @@
6     VERSION = 4
7     PATCHLEVEL = 9
8     -SUBLEVEL = 162
9     +SUBLEVEL = 163
10     EXTRAVERSION =
11     NAME = Roaring Lionus
12    
13     diff --git a/arch/arm/boot/dts/exynos3250.dtsi b/arch/arm/boot/dts/exynos3250.dtsi
14     index 2a531beef4c7..51dbd8cb91cb 100644
15     --- a/arch/arm/boot/dts/exynos3250.dtsi
16     +++ b/arch/arm/boot/dts/exynos3250.dtsi
17     @@ -170,6 +170,9 @@
18     interrupt-controller;
19     #interrupt-cells = <3>;
20     interrupt-parent = <&gic>;
21     + clock-names = "clkout8";
22     + clocks = <&cmu CLK_FIN_PLL>;
23     + #clock-cells = <1>;
24     };
25    
26     mipi_phy: video-phy {
27     diff --git a/arch/arm/boot/dts/exynos4412-odroid-common.dtsi b/arch/arm/boot/dts/exynos4412-odroid-common.dtsi
28     index 5282d69e55bd..2d83cbf672b2 100644
29     --- a/arch/arm/boot/dts/exynos4412-odroid-common.dtsi
30     +++ b/arch/arm/boot/dts/exynos4412-odroid-common.dtsi
31     @@ -70,7 +70,7 @@
32     };
33    
34     emmc_pwrseq: pwrseq {
35     - pinctrl-0 = <&sd1_cd>;
36     + pinctrl-0 = <&emmc_rstn>;
37     pinctrl-names = "default";
38     compatible = "mmc-pwrseq-emmc";
39     reset-gpios = <&gpk1 2 GPIO_ACTIVE_LOW>;
40     @@ -161,12 +161,6 @@
41     cpu0-supply = <&buck2_reg>;
42     };
43    
44     -/* RSTN signal for eMMC */
45     -&sd1_cd {
46     - samsung,pin-pud = <EXYNOS_PIN_PULL_NONE>;
47     - samsung,pin-drv = <EXYNOS4_PIN_DRV_LV1>;
48     -};
49     -
50     &pinctrl_1 {
51     gpio_power_key: power_key {
52     samsung,pins = "gpx1-3";
53     @@ -184,6 +178,11 @@
54     samsung,pins = "gpx3-7";
55     samsung,pin-pud = <EXYNOS_PIN_PULL_DOWN>;
56     };
57     +
58     + emmc_rstn: emmc-rstn {
59     + samsung,pins = "gpk1-2";
60     + samsung,pin-pud = <EXYNOS_PIN_PULL_NONE>;
61     + };
62     };
63    
64     &ehci {
65     diff --git a/arch/arm/boot/dts/exynos5420-tmu-sensor-conf.dtsi b/arch/arm/boot/dts/exynos5420-tmu-sensor-conf.dtsi
66     new file mode 100644
67     index 000000000000..c8771c660550
68     --- /dev/null
69     +++ b/arch/arm/boot/dts/exynos5420-tmu-sensor-conf.dtsi
70     @@ -0,0 +1,25 @@
71     +/*
72     + * Device tree sources for Exynos5420 TMU sensor configuration
73     + *
74     + * Copyright (c) 2014 Lukasz Majewski <l.majewski@samsung.com>
75     + * Copyright (c) 2017 Krzysztof Kozlowski <krzk@kernel.org>
76     + *
77     + * This program is free software; you can redistribute it and/or modify
78     + * it under the terms of the GNU General Public License version 2 as
79     + * published by the Free Software Foundation.
80     + *
81     + */
82     +
83     +#include <dt-bindings/thermal/thermal_exynos.h>
84     +
85     +#thermal-sensor-cells = <0>;
86     +samsung,tmu_gain = <8>;
87     +samsung,tmu_reference_voltage = <16>;
88     +samsung,tmu_noise_cancel_mode = <4>;
89     +samsung,tmu_efuse_value = <55>;
90     +samsung,tmu_min_efuse_value = <0>;
91     +samsung,tmu_max_efuse_value = <100>;
92     +samsung,tmu_first_point_trim = <25>;
93     +samsung,tmu_second_point_trim = <85>;
94     +samsung,tmu_default_temp_offset = <50>;
95     +samsung,tmu_cal_type = <TYPE_ONE_POINT_TRIMMING>;
96     diff --git a/arch/arm/boot/dts/exynos5420.dtsi b/arch/arm/boot/dts/exynos5420.dtsi
97     index 00c4cfa54839..52f3d911f67f 100644
98     --- a/arch/arm/boot/dts/exynos5420.dtsi
99     +++ b/arch/arm/boot/dts/exynos5420.dtsi
100     @@ -694,7 +694,7 @@
101     interrupts = <0 65 0>;
102     clocks = <&clock CLK_TMU>;
103     clock-names = "tmu_apbif";
104     - #include "exynos4412-tmu-sensor-conf.dtsi"
105     + #include "exynos5420-tmu-sensor-conf.dtsi"
106     };
107    
108     tmu_cpu1: tmu@10064000 {
109     @@ -703,7 +703,7 @@
110     interrupts = <0 183 0>;
111     clocks = <&clock CLK_TMU>;
112     clock-names = "tmu_apbif";
113     - #include "exynos4412-tmu-sensor-conf.dtsi"
114     + #include "exynos5420-tmu-sensor-conf.dtsi"
115     };
116    
117     tmu_cpu2: tmu@10068000 {
118     @@ -712,7 +712,7 @@
119     interrupts = <0 184 0>;
120     clocks = <&clock CLK_TMU>, <&clock CLK_TMU>;
121     clock-names = "tmu_apbif", "tmu_triminfo_apbif";
122     - #include "exynos4412-tmu-sensor-conf.dtsi"
123     + #include "exynos5420-tmu-sensor-conf.dtsi"
124     };
125    
126     tmu_cpu3: tmu@1006c000 {
127     @@ -721,7 +721,7 @@
128     interrupts = <0 185 0>;
129     clocks = <&clock CLK_TMU>, <&clock CLK_TMU_GPU>;
130     clock-names = "tmu_apbif", "tmu_triminfo_apbif";
131     - #include "exynos4412-tmu-sensor-conf.dtsi"
132     + #include "exynos5420-tmu-sensor-conf.dtsi"
133     };
134    
135     tmu_gpu: tmu@100a0000 {
136     @@ -730,7 +730,7 @@
137     interrupts = <0 215 0>;
138     clocks = <&clock CLK_TMU_GPU>, <&clock CLK_TMU>;
139     clock-names = "tmu_apbif", "tmu_triminfo_apbif";
140     - #include "exynos4412-tmu-sensor-conf.dtsi"
141     + #include "exynos5420-tmu-sensor-conf.dtsi"
142     };
143    
144     sysmmu_g2dr: sysmmu@0x10A60000 {
145     diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
146     index 56be67ecf0fa..d69adfb3d79e 100644
147     --- a/arch/arm/kernel/entry-common.S
148     +++ b/arch/arm/kernel/entry-common.S
149     @@ -32,6 +32,7 @@
150     * features make this path too inefficient.
151     */
152     ret_fast_syscall:
153     +__ret_fast_syscall:
154     UNWIND(.fnstart )
155     UNWIND(.cantunwind )
156     disable_irq_notrace @ disable interrupts
157     @@ -57,6 +58,7 @@ fast_work_pending:
158     * r0 first to avoid needing to save registers around each C function call.
159     */
160     ret_fast_syscall:
161     +__ret_fast_syscall:
162     UNWIND(.fnstart )
163     UNWIND(.cantunwind )
164     str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
165     @@ -223,7 +225,7 @@ local_restart:
166     tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
167     bne __sys_trace
168    
169     - invoke_syscall tbl, scno, r10, ret_fast_syscall
170     + invoke_syscall tbl, scno, r10, __ret_fast_syscall
171    
172     add r1, sp, #S_OFF
173     2: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
174     diff --git a/arch/arm/plat-pxa/ssp.c b/arch/arm/plat-pxa/ssp.c
175     index ba13f793fbce..b92673efffff 100644
176     --- a/arch/arm/plat-pxa/ssp.c
177     +++ b/arch/arm/plat-pxa/ssp.c
178     @@ -237,8 +237,6 @@ static int pxa_ssp_remove(struct platform_device *pdev)
179     if (ssp == NULL)
180     return -ENODEV;
181    
182     - iounmap(ssp->mmio_base);
183     -
184     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
185     release_mem_region(res->start, resource_size(res));
186    
187     @@ -248,7 +246,6 @@ static int pxa_ssp_remove(struct platform_device *pdev)
188     list_del(&ssp->node);
189     mutex_unlock(&ssp_lock);
190    
191     - kfree(ssp);
192     return 0;
193     }
194    
195     diff --git a/arch/arm64/boot/dts/qcom/msm8996.dtsi b/arch/arm64/boot/dts/qcom/msm8996.dtsi
196     index 2c93de7fffe5..bdea2d6fde94 100644
197     --- a/arch/arm64/boot/dts/qcom/msm8996.dtsi
198     +++ b/arch/arm64/boot/dts/qcom/msm8996.dtsi
199     @@ -219,7 +219,7 @@
200     compatible = "simple-bus";
201    
202     intc: interrupt-controller@9bc0000 {
203     - compatible = "arm,gic-v3";
204     + compatible = "qcom,msm8996-gic-v3", "arm,gic-v3";
205     #interrupt-cells = <3>;
206     interrupt-controller;
207     #redistributor-regions = <1>;
208     diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
209     index 30bcae0aef2a..d2b1b624ddc3 100644
210     --- a/arch/arm64/kernel/probes/kprobes.c
211     +++ b/arch/arm64/kernel/probes/kprobes.c
212     @@ -546,13 +546,13 @@ bool arch_within_kprobe_blacklist(unsigned long addr)
213     addr < (unsigned long)__entry_text_end) ||
214     (addr >= (unsigned long)__idmap_text_start &&
215     addr < (unsigned long)__idmap_text_end) ||
216     + (addr >= (unsigned long)__hyp_text_start &&
217     + addr < (unsigned long)__hyp_text_end) ||
218     !!search_exception_tables(addr))
219     return true;
220    
221     if (!is_kernel_in_hyp_mode()) {
222     - if ((addr >= (unsigned long)__hyp_text_start &&
223     - addr < (unsigned long)__hyp_text_end) ||
224     - (addr >= (unsigned long)__hyp_idmap_text_start &&
225     + if ((addr >= (unsigned long)__hyp_idmap_text_start &&
226     addr < (unsigned long)__hyp_idmap_text_end))
227     return true;
228     }
229     diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
230     index 2b0a371b42af..24444ed456c8 100644
231     --- a/arch/mips/kernel/irq.c
232     +++ b/arch/mips/kernel/irq.c
233     @@ -52,6 +52,7 @@ asmlinkage void spurious_interrupt(void)
234     void __init init_IRQ(void)
235     {
236     int i;
237     + unsigned int order = get_order(IRQ_STACK_SIZE);
238    
239     for (i = 0; i < NR_IRQS; i++)
240     irq_set_noprobe(i);
241     @@ -62,8 +63,7 @@ void __init init_IRQ(void)
242     arch_init_irq();
243    
244     for_each_possible_cpu(i) {
245     - int irq_pages = IRQ_STACK_SIZE / PAGE_SIZE;
246     - void *s = (void *)__get_free_pages(GFP_KERNEL, irq_pages);
247     + void *s = (void *)__get_free_pages(GFP_KERNEL, order);
248    
249     irq_stack[i] = s;
250     pr_debug("CPU%d IRQ stack at 0x%p - 0x%p\n", i,
251     diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
252     index 1cc133e7026f..fffd031dc6b6 100644
253     --- a/arch/mips/kernel/process.c
254     +++ b/arch/mips/kernel/process.c
255     @@ -344,7 +344,7 @@ static inline int is_sp_move_ins(union mips_instruction *ip)
256     static int get_frame_info(struct mips_frame_info *info)
257     {
258     bool is_mmips = IS_ENABLED(CONFIG_CPU_MICROMIPS);
259     - union mips_instruction insn, *ip, *ip_end;
260     + union mips_instruction insn, *ip;
261     const unsigned int max_insns = 128;
262     unsigned int last_insn_size = 0;
263     unsigned int i;
264     @@ -356,10 +356,9 @@ static int get_frame_info(struct mips_frame_info *info)
265     if (!ip)
266     goto err;
267    
268     - ip_end = (void *)ip + info->func_size;
269     -
270     - for (i = 0; i < max_insns && ip < ip_end; i++) {
271     + for (i = 0; i < max_insns; i++) {
272     ip = (void *)ip + last_insn_size;
273     +
274     if (is_mmips && mm_insn_16bit(ip->halfword[0])) {
275     insn.halfword[0] = 0;
276     insn.halfword[1] = ip->halfword[0];
277     diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
278     index ab04751a12b6..1e9f610d36a4 100644
279     --- a/arch/x86/events/core.c
280     +++ b/arch/x86/events/core.c
281     @@ -1942,7 +1942,7 @@ static int x86_pmu_commit_txn(struct pmu *pmu)
282     */
283     static void free_fake_cpuc(struct cpu_hw_events *cpuc)
284     {
285     - kfree(cpuc->shared_regs);
286     + intel_cpuc_finish(cpuc);
287     kfree(cpuc);
288     }
289    
290     @@ -1954,14 +1954,11 @@ static struct cpu_hw_events *allocate_fake_cpuc(void)
291     cpuc = kzalloc(sizeof(*cpuc), GFP_KERNEL);
292     if (!cpuc)
293     return ERR_PTR(-ENOMEM);
294     -
295     - /* only needed, if we have extra_regs */
296     - if (x86_pmu.extra_regs) {
297     - cpuc->shared_regs = allocate_shared_regs(cpu);
298     - if (!cpuc->shared_regs)
299     - goto error;
300     - }
301     cpuc->is_fake = 1;
302     +
303     + if (intel_cpuc_prepare(cpuc, cpu))
304     + goto error;
305     +
306     return cpuc;
307     error:
308     free_fake_cpuc(cpuc);
309     diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
310     index f0639c8ebcb6..098ab775135f 100644
311     --- a/arch/x86/events/intel/core.c
312     +++ b/arch/x86/events/intel/core.c
313     @@ -2492,6 +2492,35 @@ intel_stop_scheduling(struct cpu_hw_events *cpuc)
314     raw_spin_unlock(&excl_cntrs->lock);
315     }
316    
317     +static struct event_constraint *
318     +dyn_constraint(struct cpu_hw_events *cpuc, struct event_constraint *c, int idx)
319     +{
320     + WARN_ON_ONCE(!cpuc->constraint_list);
321     +
322     + if (!(c->flags & PERF_X86_EVENT_DYNAMIC)) {
323     + struct event_constraint *cx;
324     +
325     + /*
326     + * grab pre-allocated constraint entry
327     + */
328     + cx = &cpuc->constraint_list[idx];
329     +
330     + /*
331     + * initialize dynamic constraint
332     + * with static constraint
333     + */
334     + *cx = *c;
335     +
336     + /*
337     + * mark constraint as dynamic
338     + */
339     + cx->flags |= PERF_X86_EVENT_DYNAMIC;
340     + c = cx;
341     + }
342     +
343     + return c;
344     +}
345     +
346     static struct event_constraint *
347     intel_get_excl_constraints(struct cpu_hw_events *cpuc, struct perf_event *event,
348     int idx, struct event_constraint *c)
349     @@ -2522,27 +2551,7 @@ intel_get_excl_constraints(struct cpu_hw_events *cpuc, struct perf_event *event,
350     * only needed when constraint has not yet
351     * been cloned (marked dynamic)
352     */
353     - if (!(c->flags & PERF_X86_EVENT_DYNAMIC)) {
354     - struct event_constraint *cx;
355     -
356     - /*
357     - * grab pre-allocated constraint entry
358     - */
359     - cx = &cpuc->constraint_list[idx];
360     -
361     - /*
362     - * initialize dynamic constraint
363     - * with static constraint
364     - */
365     - *cx = *c;
366     -
367     - /*
368     - * mark constraint as dynamic, so we
369     - * can free it later on
370     - */
371     - cx->flags |= PERF_X86_EVENT_DYNAMIC;
372     - c = cx;
373     - }
374     + c = dyn_constraint(cpuc, c, idx);
375    
376     /*
377     * From here on, the constraint is dynamic.
378     @@ -3093,7 +3102,7 @@ ssize_t intel_event_sysfs_show(char *page, u64 config)
379     return x86_event_sysfs_show(page, config, event);
380     }
381    
382     -struct intel_shared_regs *allocate_shared_regs(int cpu)
383     +static struct intel_shared_regs *allocate_shared_regs(int cpu)
384     {
385     struct intel_shared_regs *regs;
386     int i;
387     @@ -3125,10 +3134,9 @@ static struct intel_excl_cntrs *allocate_excl_cntrs(int cpu)
388     return c;
389     }
390    
391     -static int intel_pmu_cpu_prepare(int cpu)
392     -{
393     - struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
394    
395     +int intel_cpuc_prepare(struct cpu_hw_events *cpuc, int cpu)
396     +{
397     if (x86_pmu.extra_regs || x86_pmu.lbr_sel_map) {
398     cpuc->shared_regs = allocate_shared_regs(cpu);
399     if (!cpuc->shared_regs)
400     @@ -3138,7 +3146,7 @@ static int intel_pmu_cpu_prepare(int cpu)
401     if (x86_pmu.flags & PMU_FL_EXCL_CNTRS) {
402     size_t sz = X86_PMC_IDX_MAX * sizeof(struct event_constraint);
403    
404     - cpuc->constraint_list = kzalloc(sz, GFP_KERNEL);
405     + cpuc->constraint_list = kzalloc_node(sz, GFP_KERNEL, cpu_to_node(cpu));
406     if (!cpuc->constraint_list)
407     goto err_shared_regs;
408    
409     @@ -3163,6 +3171,11 @@ err:
410     return -ENOMEM;
411     }
412    
413     +static int intel_pmu_cpu_prepare(int cpu)
414     +{
415     + return intel_cpuc_prepare(&per_cpu(cpu_hw_events, cpu), cpu);
416     +}
417     +
418     static void intel_pmu_cpu_starting(int cpu)
419     {
420     struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
421     @@ -3218,9 +3231,8 @@ static void intel_pmu_cpu_starting(int cpu)
422     }
423     }
424    
425     -static void free_excl_cntrs(int cpu)
426     +static void free_excl_cntrs(struct cpu_hw_events *cpuc)
427     {
428     - struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
429     struct intel_excl_cntrs *c;
430    
431     c = cpuc->excl_cntrs;
432     @@ -3238,9 +3250,8 @@ static void intel_pmu_cpu_dying(int cpu)
433     fini_debug_store_on_cpu(cpu);
434     }
435    
436     -static void intel_pmu_cpu_dead(int cpu)
437     +void intel_cpuc_finish(struct cpu_hw_events *cpuc)
438     {
439     - struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
440     struct intel_shared_regs *pc;
441    
442     pc = cpuc->shared_regs;
443     @@ -3250,7 +3261,12 @@ static void intel_pmu_cpu_dead(int cpu)
444     cpuc->shared_regs = NULL;
445     }
446    
447     - free_excl_cntrs(cpu);
448     + free_excl_cntrs(cpuc);
449     +}
450     +
451     +static void intel_pmu_cpu_dead(int cpu)
452     +{
453     + intel_cpuc_finish(&per_cpu(cpu_hw_events, cpu));
454     }
455    
456     static void intel_pmu_sched_task(struct perf_event_context *ctx,
457     @@ -4132,7 +4148,7 @@ static __init int fixup_ht_bug(void)
458     get_online_cpus();
459    
460     for_each_online_cpu(c) {
461     - free_excl_cntrs(c);
462     + free_excl_cntrs(&per_cpu(cpu_hw_events, c));
463     }
464    
465     put_online_cpus();
466     diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
467     index 5c21680b0a69..1ce6ae35f6a2 100644
468     --- a/arch/x86/events/perf_event.h
469     +++ b/arch/x86/events/perf_event.h
470     @@ -865,7 +865,8 @@ struct event_constraint *
471     x86_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
472     struct perf_event *event);
473    
474     -struct intel_shared_regs *allocate_shared_regs(int cpu);
475     +extern int intel_cpuc_prepare(struct cpu_hw_events *cpuc, int cpu);
476     +extern void intel_cpuc_finish(struct cpu_hw_events *cpuc);
477    
478     int intel_pmu_init(void);
479    
480     @@ -995,9 +996,13 @@ static inline int intel_pmu_init(void)
481     return 0;
482     }
483    
484     -static inline struct intel_shared_regs *allocate_shared_regs(int cpu)
485     +static inline int intel_cpuc_prepare(struct cpu_hw_event *cpuc, int cpu)
486     +{
487     + return 0;
488     +}
489     +
490     +static inline void intel_cpuc_finish(struct cpu_hw_event *cpuc)
491     {
492     - return NULL;
493     }
494    
495     static inline int is_ht_workaround_enabled(void)
496     diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
497     index c56c24347f15..98444b77fbe3 100644
498     --- a/arch/x86/include/asm/cpufeatures.h
499     +++ b/arch/x86/include/asm/cpufeatures.h
500     @@ -314,6 +314,7 @@
501     /* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */
502     #define X86_FEATURE_AVX512_4VNNIW (18*32+ 2) /* AVX-512 Neural Network Instructions */
503     #define X86_FEATURE_AVX512_4FMAPS (18*32+ 3) /* AVX-512 Multiply Accumulation Single precision */
504     +#define X86_FEATURE_TSX_FORCE_ABORT (18*32+13) /* "" TSX_FORCE_ABORT */
505     #define X86_FEATURE_PCONFIG (18*32+18) /* Intel PCONFIG */
506     #define X86_FEATURE_SPEC_CTRL (18*32+26) /* "" Speculation Control (IBRS + IBPB) */
507     #define X86_FEATURE_INTEL_STIBP (18*32+27) /* "" Single Thread Indirect Branch Predictors */
508     diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
509     index bbbb9b14ade1..9963e21ac443 100644
510     --- a/arch/x86/include/asm/msr-index.h
511     +++ b/arch/x86/include/asm/msr-index.h
512     @@ -575,6 +575,12 @@
513    
514     #define MSR_IA32_TSC_DEADLINE 0x000006E0
515    
516     +
517     +#define MSR_TSX_FORCE_ABORT 0x0000010F
518     +
519     +#define MSR_TFA_RTM_FORCE_ABORT_BIT 0
520     +#define MSR_TFA_RTM_FORCE_ABORT BIT_ULL(MSR_TFA_RTM_FORCE_ABORT_BIT)
521     +
522     /* P4/Xeon+ specific */
523     #define MSR_IA32_MCG_EAX 0x00000180
524     #define MSR_IA32_MCG_EBX 0x00000181
525     diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
526     index 9215e0527647..390fdd39e0e2 100644
527     --- a/arch/x86/include/asm/page_64_types.h
528     +++ b/arch/x86/include/asm/page_64_types.h
529     @@ -6,7 +6,11 @@
530     #endif
531    
532     #ifdef CONFIG_KASAN
533     +#ifdef CONFIG_KASAN_EXTRA
534     +#define KASAN_STACK_ORDER 2
535     +#else
536     #define KASAN_STACK_ORDER 1
537     +#endif
538     #else
539     #define KASAN_STACK_ORDER 0
540     #endif
541     diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
542     index 4c2648b96c9a..be6d0543e626 100644
543     --- a/arch/x86/kernel/cpu/amd.c
544     +++ b/arch/x86/kernel/cpu/amd.c
545     @@ -765,11 +765,9 @@ static void init_amd_bd(struct cpuinfo_x86 *c)
546     static void init_amd_zn(struct cpuinfo_x86 *c)
547     {
548     set_cpu_cap(c, X86_FEATURE_ZEN);
549     - /*
550     - * Fix erratum 1076: CPB feature bit not being set in CPUID. It affects
551     - * all up to and including B1.
552     - */
553     - if (c->x86_model <= 1 && c->x86_stepping <= 1)
554     +
555     + /* Fix erratum 1076: CPB feature bit not being set in CPUID. */
556     + if (!cpu_has(c, X86_FEATURE_CPB))
557     set_cpu_cap(c, X86_FEATURE_CPB);
558     }
559    
560     diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
561     index 490f9be3fda2..167ecc270ca5 100644
562     --- a/arch/x86/kernel/kexec-bzimage64.c
563     +++ b/arch/x86/kernel/kexec-bzimage64.c
564     @@ -167,6 +167,9 @@ setup_efi_state(struct boot_params *params, unsigned long params_load_addr,
565     struct efi_info *current_ei = &boot_params.efi_info;
566     struct efi_info *ei = &params->efi_info;
567    
568     + if (!efi_enabled(EFI_RUNTIME_SERVICES))
569     + return 0;
570     +
571     if (!current_ei->efi_memmap_size)
572     return 0;
573    
574     diff --git a/arch/xtensa/configs/smp_lx200_defconfig b/arch/xtensa/configs/smp_lx200_defconfig
575     index 14e3ca353ac8..5035b86a2e49 100644
576     --- a/arch/xtensa/configs/smp_lx200_defconfig
577     +++ b/arch/xtensa/configs/smp_lx200_defconfig
578     @@ -34,6 +34,7 @@ CONFIG_SMP=y
579     CONFIG_HOTPLUG_CPU=y
580     # CONFIG_INITIALIZE_XTENSA_MMU_INSIDE_VMLINUX is not set
581     # CONFIG_PCI is not set
582     +CONFIG_VECTORS_OFFSET=0x00002000
583     CONFIG_XTENSA_PLATFORM_XTFPGA=y
584     CONFIG_CMDLINE_BOOL=y
585     CONFIG_CMDLINE="earlycon=uart8250,mmio32native,0xfd050020,115200n8 console=ttyS0,115200n8 ip=dhcp root=/dev/nfs rw debug memmap=96M@0"
586     diff --git a/arch/xtensa/kernel/head.S b/arch/xtensa/kernel/head.S
587     index 27c8e07ace43..29f445b410b3 100644
588     --- a/arch/xtensa/kernel/head.S
589     +++ b/arch/xtensa/kernel/head.S
590     @@ -281,12 +281,13 @@ should_never_return:
591    
592     movi a2, cpu_start_ccount
593     1:
594     + memw
595     l32i a3, a2, 0
596     beqi a3, 0, 1b
597     movi a3, 0
598     s32i a3, a2, 0
599     - memw
600     1:
601     + memw
602     l32i a3, a2, 0
603     beqi a3, 0, 1b
604     wsr a3, ccount
605     @@ -323,11 +324,13 @@ ENTRY(cpu_restart)
606     rsr a0, prid
607     neg a2, a0
608     movi a3, cpu_start_id
609     + memw
610     s32i a2, a3, 0
611     #if XCHAL_DCACHE_IS_WRITEBACK
612     dhwbi a3, 0
613     #endif
614     1:
615     + memw
616     l32i a2, a3, 0
617     dhi a3, 0
618     bne a2, a0, 1b
619     diff --git a/arch/xtensa/kernel/smp.c b/arch/xtensa/kernel/smp.c
620     index fc4ad21a5ed4..44805673a250 100644
621     --- a/arch/xtensa/kernel/smp.c
622     +++ b/arch/xtensa/kernel/smp.c
623     @@ -80,7 +80,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
624     {
625     unsigned i;
626    
627     - for (i = 0; i < max_cpus; ++i)
628     + for_each_possible_cpu(i)
629     set_cpu_present(i, true);
630     }
631    
632     @@ -93,6 +93,11 @@ void __init smp_init_cpus(void)
633     pr_info("%s: Core Count = %d\n", __func__, ncpus);
634     pr_info("%s: Core Id = %d\n", __func__, core_id);
635    
636     + if (ncpus > NR_CPUS) {
637     + ncpus = NR_CPUS;
638     + pr_info("%s: limiting core count by %d\n", __func__, ncpus);
639     + }
640     +
641     for (i = 0; i < ncpus; ++i)
642     set_cpu_possible(i, true);
643     }
644     @@ -192,9 +197,11 @@ static int boot_secondary(unsigned int cpu, struct task_struct *ts)
645     int i;
646    
647     #ifdef CONFIG_HOTPLUG_CPU
648     - cpu_start_id = cpu;
649     - system_flush_invalidate_dcache_range(
650     - (unsigned long)&cpu_start_id, sizeof(cpu_start_id));
651     + WRITE_ONCE(cpu_start_id, cpu);
652     + /* Pairs with the third memw in the cpu_restart */
653     + mb();
654     + system_flush_invalidate_dcache_range((unsigned long)&cpu_start_id,
655     + sizeof(cpu_start_id));
656     #endif
657     smp_call_function_single(0, mx_cpu_start, (void *)cpu, 1);
658    
659     @@ -203,18 +210,21 @@ static int boot_secondary(unsigned int cpu, struct task_struct *ts)
660     ccount = get_ccount();
661     while (!ccount);
662    
663     - cpu_start_ccount = ccount;
664     + WRITE_ONCE(cpu_start_ccount, ccount);
665    
666     - while (time_before(jiffies, timeout)) {
667     + do {
668     + /*
669     + * Pairs with the first two memws in the
670     + * .Lboot_secondary.
671     + */
672     mb();
673     - if (!cpu_start_ccount)
674     - break;
675     - }
676     + ccount = READ_ONCE(cpu_start_ccount);
677     + } while (ccount && time_before(jiffies, timeout));
678    
679     - if (cpu_start_ccount) {
680     + if (ccount) {
681     smp_call_function_single(0, mx_cpu_stop,
682     - (void *)cpu, 1);
683     - cpu_start_ccount = 0;
684     + (void *)cpu, 1);
685     + WRITE_ONCE(cpu_start_ccount, 0);
686     return -EIO;
687     }
688     }
689     @@ -234,6 +244,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)
690     pr_debug("%s: Calling wakeup_secondary(cpu:%d, idle:%p, sp: %08lx)\n",
691     __func__, cpu, idle, start_info.stack);
692    
693     + init_completion(&cpu_running);
694     ret = boot_secondary(cpu, idle);
695     if (ret == 0) {
696     wait_for_completion_timeout(&cpu_running,
697     @@ -295,8 +306,10 @@ void __cpu_die(unsigned int cpu)
698     unsigned long timeout = jiffies + msecs_to_jiffies(1000);
699     while (time_before(jiffies, timeout)) {
700     system_invalidate_dcache_range((unsigned long)&cpu_start_id,
701     - sizeof(cpu_start_id));
702     - if (cpu_start_id == -cpu) {
703     + sizeof(cpu_start_id));
704     + /* Pairs with the second memw in the cpu_restart */
705     + mb();
706     + if (READ_ONCE(cpu_start_id) == -cpu) {
707     platform_cpu_kill(cpu);
708     return;
709     }
710     diff --git a/arch/xtensa/kernel/time.c b/arch/xtensa/kernel/time.c
711     index be81e69b25bc..2251a6e0973a 100644
712     --- a/arch/xtensa/kernel/time.c
713     +++ b/arch/xtensa/kernel/time.c
714     @@ -89,7 +89,7 @@ static int ccount_timer_shutdown(struct clock_event_device *evt)
715     container_of(evt, struct ccount_timer, evt);
716    
717     if (timer->irq_enabled) {
718     - disable_irq(evt->irq);
719     + disable_irq_nosync(evt->irq);
720     timer->irq_enabled = 0;
721     }
722     return 0;
723     diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
724     index 14790304b84b..9fcd51095d13 100644
725     --- a/drivers/char/applicom.c
726     +++ b/drivers/char/applicom.c
727     @@ -32,6 +32,7 @@
728     #include <linux/wait.h>
729     #include <linux/init.h>
730     #include <linux/fs.h>
731     +#include <linux/nospec.h>
732    
733     #include <asm/io.h>
734     #include <asm/uaccess.h>
735     @@ -386,7 +387,11 @@ static ssize_t ac_write(struct file *file, const char __user *buf, size_t count,
736     TicCard = st_loc.tic_des_from_pc; /* tic number to send */
737     IndexCard = NumCard - 1;
738    
739     - if((NumCard < 1) || (NumCard > MAX_BOARD) || !apbs[IndexCard].RamIO)
740     + if (IndexCard >= MAX_BOARD)
741     + return -EINVAL;
742     + IndexCard = array_index_nospec(IndexCard, MAX_BOARD);
743     +
744     + if (!apbs[IndexCard].RamIO)
745     return -EINVAL;
746    
747     #ifdef DEBUG
748     @@ -697,6 +702,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
749     unsigned char IndexCard;
750     void __iomem *pmem;
751     int ret = 0;
752     + static int warncount = 10;
753     volatile unsigned char byte_reset_it;
754     struct st_ram_io *adgl;
755     void __user *argp = (void __user *)arg;
756     @@ -711,16 +717,12 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
757     mutex_lock(&ac_mutex);
758     IndexCard = adgl->num_card-1;
759    
760     - if(cmd != 6 && ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {
761     - static int warncount = 10;
762     - if (warncount) {
763     - printk( KERN_WARNING "APPLICOM driver IOCTL, bad board number %d\n",(int)IndexCard+1);
764     - warncount--;
765     - }
766     - kfree(adgl);
767     - mutex_unlock(&ac_mutex);
768     - return -EINVAL;
769     - }
770     + if (cmd != 6 && IndexCard >= MAX_BOARD)
771     + goto err;
772     + IndexCard = array_index_nospec(IndexCard, MAX_BOARD);
773     +
774     + if (cmd != 6 && !apbs[IndexCard].RamIO)
775     + goto err;
776    
777     switch (cmd) {
778    
779     @@ -838,5 +840,16 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
780     kfree(adgl);
781     mutex_unlock(&ac_mutex);
782     return 0;
783     +
784     +err:
785     + if (warncount) {
786     + pr_warn("APPLICOM driver IOCTL, bad board number %d\n",
787     + (int)IndexCard + 1);
788     + warncount--;
789     + }
790     + kfree(adgl);
791     + mutex_unlock(&ac_mutex);
792     + return -EINVAL;
793     +
794     }
795    
796     diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
797     index 61fe4bbc6dc0..a38a23f0b3f4 100644
798     --- a/drivers/cpufreq/cpufreq.c
799     +++ b/drivers/cpufreq/cpufreq.c
800     @@ -528,13 +528,13 @@ EXPORT_SYMBOL_GPL(cpufreq_driver_resolve_freq);
801     * SYSFS INTERFACE *
802     *********************************************************************/
803     static ssize_t show_boost(struct kobject *kobj,
804     - struct attribute *attr, char *buf)
805     + struct kobj_attribute *attr, char *buf)
806     {
807     return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled);
808     }
809    
810     -static ssize_t store_boost(struct kobject *kobj, struct attribute *attr,
811     - const char *buf, size_t count)
812     +static ssize_t store_boost(struct kobject *kobj, struct kobj_attribute *attr,
813     + const char *buf, size_t count)
814     {
815     int ret, enable;
816    
817     diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
818     index a59ae8e24d3d..f690085b1ad9 100644
819     --- a/drivers/cpufreq/intel_pstate.c
820     +++ b/drivers/cpufreq/intel_pstate.c
821     @@ -659,13 +659,13 @@ static void __init intel_pstate_debug_expose_params(void)
822     /************************** sysfs begin ************************/
823     #define show_one(file_name, object) \
824     static ssize_t show_##file_name \
825     - (struct kobject *kobj, struct attribute *attr, char *buf) \
826     + (struct kobject *kobj, struct kobj_attribute *attr, char *buf) \
827     { \
828     return sprintf(buf, "%u\n", limits->object); \
829     }
830    
831     static ssize_t show_turbo_pct(struct kobject *kobj,
832     - struct attribute *attr, char *buf)
833     + struct kobj_attribute *attr, char *buf)
834     {
835     struct cpudata *cpu;
836     int total, no_turbo, turbo_pct;
837     @@ -681,7 +681,7 @@ static ssize_t show_turbo_pct(struct kobject *kobj,
838     }
839    
840     static ssize_t show_num_pstates(struct kobject *kobj,
841     - struct attribute *attr, char *buf)
842     + struct kobj_attribute *attr, char *buf)
843     {
844     struct cpudata *cpu;
845     int total;
846     @@ -692,7 +692,7 @@ static ssize_t show_num_pstates(struct kobject *kobj,
847     }
848    
849     static ssize_t show_no_turbo(struct kobject *kobj,
850     - struct attribute *attr, char *buf)
851     + struct kobj_attribute *attr, char *buf)
852     {
853     ssize_t ret;
854    
855     @@ -705,7 +705,7 @@ static ssize_t show_no_turbo(struct kobject *kobj,
856     return ret;
857     }
858    
859     -static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
860     +static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
861     const char *buf, size_t count)
862     {
863     unsigned int input;
864     @@ -729,7 +729,7 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
865     return count;
866     }
867    
868     -static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
869     +static ssize_t store_max_perf_pct(struct kobject *a, struct kobj_attribute *b,
870     const char *buf, size_t count)
871     {
872     unsigned int input;
873     @@ -753,7 +753,7 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
874     return count;
875     }
876    
877     -static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
878     +static ssize_t store_min_perf_pct(struct kobject *a, struct kobj_attribute *b,
879     const char *buf, size_t count)
880     {
881     unsigned int input;
882     diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c
883     index ee7b48d5243c..b222dd7afe8e 100644
884     --- a/drivers/dma/at_xdmac.c
885     +++ b/drivers/dma/at_xdmac.c
886     @@ -203,6 +203,7 @@ struct at_xdmac_chan {
887     u32 save_cim;
888     u32 save_cnda;
889     u32 save_cndc;
890     + u32 irq_status;
891     unsigned long status;
892     struct tasklet_struct tasklet;
893     struct dma_slave_config sconfig;
894     @@ -1582,8 +1583,8 @@ static void at_xdmac_tasklet(unsigned long data)
895     struct at_xdmac_desc *desc;
896     u32 error_mask;
897    
898     - dev_dbg(chan2dev(&atchan->chan), "%s: status=0x%08lx\n",
899     - __func__, atchan->status);
900     + dev_dbg(chan2dev(&atchan->chan), "%s: status=0x%08x\n",
901     + __func__, atchan->irq_status);
902    
903     error_mask = AT_XDMAC_CIS_RBEIS
904     | AT_XDMAC_CIS_WBEIS
905     @@ -1591,15 +1592,15 @@ static void at_xdmac_tasklet(unsigned long data)
906    
907     if (at_xdmac_chan_is_cyclic(atchan)) {
908     at_xdmac_handle_cyclic(atchan);
909     - } else if ((atchan->status & AT_XDMAC_CIS_LIS)
910     - || (atchan->status & error_mask)) {
911     + } else if ((atchan->irq_status & AT_XDMAC_CIS_LIS)
912     + || (atchan->irq_status & error_mask)) {
913     struct dma_async_tx_descriptor *txd;
914    
915     - if (atchan->status & AT_XDMAC_CIS_RBEIS)
916     + if (atchan->irq_status & AT_XDMAC_CIS_RBEIS)
917     dev_err(chan2dev(&atchan->chan), "read bus error!!!");
918     - if (atchan->status & AT_XDMAC_CIS_WBEIS)
919     + if (atchan->irq_status & AT_XDMAC_CIS_WBEIS)
920     dev_err(chan2dev(&atchan->chan), "write bus error!!!");
921     - if (atchan->status & AT_XDMAC_CIS_ROIS)
922     + if (atchan->irq_status & AT_XDMAC_CIS_ROIS)
923     dev_err(chan2dev(&atchan->chan), "request overflow error!!!");
924    
925     spin_lock_bh(&atchan->lock);
926     @@ -1654,7 +1655,7 @@ static irqreturn_t at_xdmac_interrupt(int irq, void *dev_id)
927     atchan = &atxdmac->chan[i];
928     chan_imr = at_xdmac_chan_read(atchan, AT_XDMAC_CIM);
929     chan_status = at_xdmac_chan_read(atchan, AT_XDMAC_CIS);
930     - atchan->status = chan_status & chan_imr;
931     + atchan->irq_status = chan_status & chan_imr;
932     dev_vdbg(atxdmac->dma.dev,
933     "%s: chan%d: imr=0x%x, status=0x%x\n",
934     __func__, i, chan_imr, chan_status);
935     @@ -1668,7 +1669,7 @@ static irqreturn_t at_xdmac_interrupt(int irq, void *dev_id)
936     at_xdmac_chan_read(atchan, AT_XDMAC_CDA),
937     at_xdmac_chan_read(atchan, AT_XDMAC_CUBC));
938    
939     - if (atchan->status & (AT_XDMAC_CIS_RBEIS | AT_XDMAC_CIS_WBEIS))
940     + if (atchan->irq_status & (AT_XDMAC_CIS_RBEIS | AT_XDMAC_CIS_WBEIS))
941     at_xdmac_write(atxdmac, AT_XDMAC_GD, atchan->mask);
942    
943     tasklet_schedule(&atchan->tasklet);
944     diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
945     index ebe72a466587..7dd46cf5ed84 100644
946     --- a/drivers/dma/dmatest.c
947     +++ b/drivers/dma/dmatest.c
948     @@ -583,11 +583,9 @@ static int dmatest_func(void *data)
949     srcs[i] = um->addr[i] + src_off;
950     ret = dma_mapping_error(dev->dev, um->addr[i]);
951     if (ret) {
952     - dmaengine_unmap_put(um);
953     result("src mapping error", total_tests,
954     src_off, dst_off, len, ret);
955     - failed_tests++;
956     - continue;
957     + goto error_unmap_continue;
958     }
959     um->to_cnt++;
960     }
961     @@ -602,11 +600,9 @@ static int dmatest_func(void *data)
962     DMA_BIDIRECTIONAL);
963     ret = dma_mapping_error(dev->dev, dsts[i]);
964     if (ret) {
965     - dmaengine_unmap_put(um);
966     result("dst mapping error", total_tests,
967     src_off, dst_off, len, ret);
968     - failed_tests++;
969     - continue;
970     + goto error_unmap_continue;
971     }
972     um->bidi_cnt++;
973     }
974     @@ -643,12 +639,10 @@ static int dmatest_func(void *data)
975     }
976    
977     if (!tx) {
978     - dmaengine_unmap_put(um);
979     result("prep error", total_tests, src_off,
980     dst_off, len, ret);
981     msleep(100);
982     - failed_tests++;
983     - continue;
984     + goto error_unmap_continue;
985     }
986    
987     done->done = false;
988     @@ -657,12 +651,10 @@ static int dmatest_func(void *data)
989     cookie = tx->tx_submit(tx);
990    
991     if (dma_submit_error(cookie)) {
992     - dmaengine_unmap_put(um);
993     result("submit error", total_tests, src_off,
994     dst_off, len, ret);
995     msleep(100);
996     - failed_tests++;
997     - continue;
998     + goto error_unmap_continue;
999     }
1000     dma_async_issue_pending(chan);
1001    
1002     @@ -675,16 +667,14 @@ static int dmatest_func(void *data)
1003     dmaengine_unmap_put(um);
1004     result("test timed out", total_tests, src_off, dst_off,
1005     len, 0);
1006     - failed_tests++;
1007     - continue;
1008     + goto error_unmap_continue;
1009     } else if (status != DMA_COMPLETE) {
1010     dmaengine_unmap_put(um);
1011     result(status == DMA_ERROR ?
1012     "completion error status" :
1013     "completion busy status", total_tests, src_off,
1014     dst_off, len, ret);
1015     - failed_tests++;
1016     - continue;
1017     + goto error_unmap_continue;
1018     }
1019    
1020     dmaengine_unmap_put(um);
1021     @@ -727,6 +717,12 @@ static int dmatest_func(void *data)
1022     verbose_result("test passed", total_tests, src_off,
1023     dst_off, len, 0);
1024     }
1025     +
1026     + continue;
1027     +
1028     +error_unmap_continue:
1029     + dmaengine_unmap_put(um);
1030     + failed_tests++;
1031     }
1032     ktime = ktime_sub(ktime_get(), ktime);
1033     ktime = ktime_sub(ktime, comparetime);
1034     diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c
1035     index 14042a64bdd5..132b9bae4b6a 100644
1036     --- a/drivers/firmware/iscsi_ibft.c
1037     +++ b/drivers/firmware/iscsi_ibft.c
1038     @@ -542,6 +542,7 @@ static umode_t __init ibft_check_tgt_for(void *data, int type)
1039     case ISCSI_BOOT_TGT_NIC_ASSOC:
1040     case ISCSI_BOOT_TGT_CHAP_TYPE:
1041     rc = S_IRUGO;
1042     + break;
1043     case ISCSI_BOOT_TGT_NAME:
1044     if (tgt->tgt_name_len)
1045     rc = S_IRUGO;
1046     diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
1047     index 3edb09cb9ee0..1f599bc08237 100644
1048     --- a/drivers/gpio/gpio-vf610.c
1049     +++ b/drivers/gpio/gpio-vf610.c
1050     @@ -221,6 +221,7 @@ static int vf610_gpio_probe(struct platform_device *pdev)
1051     struct vf610_gpio_port *port;
1052     struct resource *iores;
1053     struct gpio_chip *gc;
1054     + int i;
1055     int ret;
1056    
1057     port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
1058     @@ -259,6 +260,10 @@ static int vf610_gpio_probe(struct platform_device *pdev)
1059     if (ret < 0)
1060     return ret;
1061    
1062     + /* Mask all GPIO interrupts */
1063     + for (i = 0; i < gc->ngpio; i++)
1064     + vf610_gpio_writel(0, port->base + PORT_PCR(i));
1065     +
1066     /* Clear the interrupt status register for all GPIO's */
1067     vf610_gpio_writel(~0, port->base + PORT_ISFR);
1068    
1069     diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c
1070     index f2975a1525be..2796fea70a42 100644
1071     --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c
1072     +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c
1073     @@ -327,6 +327,7 @@ static int sun4i_tcon_init_clocks(struct device *dev,
1074     dev_err(dev, "Couldn't get the TCON channel 0 clock\n");
1075     return PTR_ERR(tcon->sclk0);
1076     }
1077     + clk_prepare_enable(tcon->sclk0);
1078    
1079     if (tcon->quirks->has_channel_1) {
1080     tcon->sclk1 = devm_clk_get(dev, "tcon-ch1");
1081     @@ -341,6 +342,7 @@ static int sun4i_tcon_init_clocks(struct device *dev,
1082    
1083     static void sun4i_tcon_free_clocks(struct sun4i_tcon *tcon)
1084     {
1085     + clk_disable_unprepare(tcon->sclk0);
1086     clk_disable_unprepare(tcon->clk);
1087     }
1088    
1089     diff --git a/drivers/infiniband/hw/hfi1/ud.c b/drivers/infiniband/hw/hfi1/ud.c
1090     index 1a7ce1d740ce..292d7b6a0536 100644
1091     --- a/drivers/infiniband/hw/hfi1/ud.c
1092     +++ b/drivers/infiniband/hw/hfi1/ud.c
1093     @@ -772,7 +772,6 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
1094     opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) {
1095     wc.ex.imm_data = ohdr->u.ud.imm_data;
1096     wc.wc_flags = IB_WC_WITH_IMM;
1097     - tlen -= sizeof(u32);
1098     } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
1099     wc.ex.imm_data = 0;
1100     wc.wc_flags = 0;
1101     diff --git a/drivers/infiniband/hw/qib/qib_ud.c b/drivers/infiniband/hw/qib/qib_ud.c
1102     index f45cad1198b0..93012fba287d 100644
1103     --- a/drivers/infiniband/hw/qib/qib_ud.c
1104     +++ b/drivers/infiniband/hw/qib/qib_ud.c
1105     @@ -525,7 +525,6 @@ void qib_ud_rcv(struct qib_ibport *ibp, struct ib_header *hdr,
1106     opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) {
1107     wc.ex.imm_data = ohdr->u.ud.imm_data;
1108     wc.wc_flags = IB_WC_WITH_IMM;
1109     - tlen -= sizeof(u32);
1110     } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
1111     wc.ex.imm_data = 0;
1112     wc.wc_flags = 0;
1113     diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c
1114     index 25ce9047b682..16f5d5660053 100644
1115     --- a/drivers/input/mouse/elan_i2c_core.c
1116     +++ b/drivers/input/mouse/elan_i2c_core.c
1117     @@ -1241,6 +1241,7 @@ static const struct acpi_device_id elan_acpi_id[] = {
1118     { "ELAN0000", 0 },
1119     { "ELAN0100", 0 },
1120     { "ELAN0600", 0 },
1121     + { "ELAN0601", 0 },
1122     { "ELAN0602", 0 },
1123     { "ELAN0605", 0 },
1124     { "ELAN0608", 0 },
1125     diff --git a/drivers/input/tablet/wacom_serial4.c b/drivers/input/tablet/wacom_serial4.c
1126     index 20ab802461e7..1d46b763aae6 100644
1127     --- a/drivers/input/tablet/wacom_serial4.c
1128     +++ b/drivers/input/tablet/wacom_serial4.c
1129     @@ -187,6 +187,7 @@ enum {
1130     MODEL_DIGITIZER_II = 0x5544, /* UD */
1131     MODEL_GRAPHIRE = 0x4554, /* ET */
1132     MODEL_PENPARTNER = 0x4354, /* CT */
1133     + MODEL_ARTPAD_II = 0x4B54, /* KT */
1134     };
1135    
1136     static void wacom_handle_model_response(struct wacom *wacom)
1137     @@ -245,6 +246,7 @@ static void wacom_handle_model_response(struct wacom *wacom)
1138     wacom->flags = F_HAS_STYLUS2 | F_HAS_SCROLLWHEEL;
1139     break;
1140    
1141     + case MODEL_ARTPAD_II:
1142     case MODEL_DIGITIZER_II:
1143     wacom->dev->name = "Wacom Digitizer II";
1144     wacom->dev->id.version = MODEL_DIGITIZER_II;
1145     diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
1146     index e984418ffa2a..ca22483d253f 100644
1147     --- a/drivers/iommu/amd_iommu.c
1148     +++ b/drivers/iommu/amd_iommu.c
1149     @@ -1896,6 +1896,7 @@ static void do_attach(struct iommu_dev_data *dev_data,
1150    
1151     static void do_detach(struct iommu_dev_data *dev_data)
1152     {
1153     + struct protection_domain *domain = dev_data->domain;
1154     struct amd_iommu *iommu;
1155     u16 alias;
1156    
1157     @@ -1911,10 +1912,6 @@ static void do_detach(struct iommu_dev_data *dev_data)
1158     iommu = amd_iommu_rlookup_table[dev_data->devid];
1159     alias = dev_data->alias;
1160    
1161     - /* decrease reference counters */
1162     - dev_data->domain->dev_iommu[iommu->index] -= 1;
1163     - dev_data->domain->dev_cnt -= 1;
1164     -
1165     /* Update data structures */
1166     dev_data->domain = NULL;
1167     list_del(&dev_data->list);
1168     @@ -1924,6 +1921,16 @@ static void do_detach(struct iommu_dev_data *dev_data)
1169    
1170     /* Flush the DTE entry */
1171     device_flush_dte(dev_data);
1172     +
1173     + /* Flush IOTLB */
1174     + domain_flush_tlb_pde(domain);
1175     +
1176     + /* Wait for the flushes to finish */
1177     + domain_flush_complete(domain);
1178     +
1179     + /* decrease reference counters - needs to happen after the flushes */
1180     + domain->dev_iommu[iommu->index] -= 1;
1181     + domain->dev_cnt -= 1;
1182     }
1183    
1184     /*
1185     @@ -2611,13 +2618,13 @@ out_unmap:
1186     bus_addr = address + s->dma_address + (j << PAGE_SHIFT);
1187     iommu_unmap_page(domain, bus_addr, PAGE_SIZE);
1188    
1189     - if (--mapped_pages)
1190     + if (--mapped_pages == 0)
1191     goto out_free_iova;
1192     }
1193     }
1194    
1195     out_free_iova:
1196     - free_iova_fast(&dma_dom->iovad, address, npages);
1197     + free_iova_fast(&dma_dom->iovad, address >> PAGE_SHIFT, npages);
1198    
1199     out_err:
1200     return 0;
1201     diff --git a/drivers/irqchip/irq-mmp.c b/drivers/irqchip/irq-mmp.c
1202     index 013fc9659a84..2fe2bcb63a71 100644
1203     --- a/drivers/irqchip/irq-mmp.c
1204     +++ b/drivers/irqchip/irq-mmp.c
1205     @@ -34,6 +34,9 @@
1206     #define SEL_INT_PENDING (1 << 6)
1207     #define SEL_INT_NUM_MASK 0x3f
1208    
1209     +#define MMP2_ICU_INT_ROUTE_PJ4_IRQ (1 << 5)
1210     +#define MMP2_ICU_INT_ROUTE_PJ4_FIQ (1 << 6)
1211     +
1212     struct icu_chip_data {
1213     int nr_irqs;
1214     unsigned int virq_base;
1215     @@ -190,7 +193,8 @@ static struct mmp_intc_conf mmp_conf = {
1216     static struct mmp_intc_conf mmp2_conf = {
1217     .conf_enable = 0x20,
1218     .conf_disable = 0x0,
1219     - .conf_mask = 0x7f,
1220     + .conf_mask = MMP2_ICU_INT_ROUTE_PJ4_IRQ |
1221     + MMP2_ICU_INT_ROUTE_PJ4_FIQ,
1222     };
1223    
1224     static void __exception_irq_entry mmp_handle_irq(struct pt_regs *regs)
1225     diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
1226     index d4e0d1602c80..6b7eed722e43 100644
1227     --- a/drivers/isdn/i4l/isdn_tty.c
1228     +++ b/drivers/isdn/i4l/isdn_tty.c
1229     @@ -786,7 +786,7 @@ isdn_tty_suspend(char *id, modem_info *info, atemu *m)
1230     cmd.parm.cmsg.para[3] = 4; /* 16 bit 0x0004 Suspend */
1231     cmd.parm.cmsg.para[4] = 0;
1232     cmd.parm.cmsg.para[5] = l;
1233     - strncpy(&cmd.parm.cmsg.para[6], id, l);
1234     + strscpy(&cmd.parm.cmsg.para[6], id, l);
1235     cmd.command = CAPI_PUT_MESSAGE;
1236     cmd.driver = info->isdn_driver;
1237     cmd.arg = info->isdn_channel;
1238     diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
1239     index cde43b63c3da..c630a9f8e356 100644
1240     --- a/drivers/media/usb/uvc/uvc_driver.c
1241     +++ b/drivers/media/usb/uvc/uvc_driver.c
1242     @@ -1019,11 +1019,19 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
1243     return -EINVAL;
1244     }
1245    
1246     - /* Make sure the terminal type MSB is not null, otherwise it
1247     - * could be confused with a unit.
1248     + /*
1249     + * Reject invalid terminal types that would cause issues:
1250     + *
1251     + * - The high byte must be non-zero, otherwise it would be
1252     + * confused with a unit.
1253     + *
1254     + * - Bit 15 must be 0, as we use it internally as a terminal
1255     + * direction flag.
1256     + *
1257     + * Other unknown types are accepted.
1258     */
1259     type = get_unaligned_le16(&buffer[4]);
1260     - if ((type & 0xff00) == 0) {
1261     + if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) {
1262     uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
1263     "interface %d INPUT_TERMINAL %d has invalid "
1264     "type 0x%04x, skipping\n", udev->devnum,
1265     diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
1266     index 883fd9809dd2..7cee3e5db56c 100644
1267     --- a/drivers/net/dsa/mv88e6xxx/chip.c
1268     +++ b/drivers/net/dsa/mv88e6xxx/chip.c
1269     @@ -798,7 +798,7 @@ static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
1270     if (s->sizeof_stat == 8)
1271     _mv88e6xxx_stats_read(chip, s->reg + 1, &high);
1272     }
1273     - value = (((u64)high) << 16) | low;
1274     + value = (((u64)high) << 32) | low;
1275     return value;
1276     }
1277    
1278     diff --git a/drivers/net/ethernet/altera/altera_msgdma.c b/drivers/net/ethernet/altera/altera_msgdma.c
1279     index 0fb986ba3290..0ae723f75341 100644
1280     --- a/drivers/net/ethernet/altera/altera_msgdma.c
1281     +++ b/drivers/net/ethernet/altera/altera_msgdma.c
1282     @@ -145,7 +145,8 @@ u32 msgdma_tx_completions(struct altera_tse_private *priv)
1283     & 0xffff;
1284    
1285     if (inuse) { /* Tx FIFO is not empty */
1286     - ready = priv->tx_prod - priv->tx_cons - inuse - 1;
1287     + ready = max_t(int,
1288     + priv->tx_prod - priv->tx_cons - inuse - 1, 0);
1289     } else {
1290     /* Check for buffered last packet */
1291     status = csrrd32(priv->tx_dma_csr, msgdma_csroffs(status));
1292     diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
1293     index a036f7039d76..737f0f6f4075 100644
1294     --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
1295     +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
1296     @@ -428,6 +428,12 @@ normal_tx:
1297     }
1298    
1299     length >>= 9;
1300     + if (unlikely(length >= ARRAY_SIZE(bnxt_lhint_arr))) {
1301     + dev_warn_ratelimited(&pdev->dev, "Dropped oversize %d bytes TX packet.\n",
1302     + skb->len);
1303     + i = 0;
1304     + goto tx_dma_error;
1305     + }
1306     flags |= bnxt_lhint_arr[length];
1307     txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
1308    
1309     diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
1310     index a2f7d0834071..ad8681cf5ef0 100644
1311     --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
1312     +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
1313     @@ -2078,6 +2078,8 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
1314     out_notify_fail:
1315     (void)cancel_work_sync(&priv->service_task);
1316     out_read_prop_fail:
1317     + /* safe for ACPI FW */
1318     + of_node_put(to_of_node(priv->fwnode));
1319     free_netdev(ndev);
1320     return ret;
1321     }
1322     @@ -2107,6 +2109,9 @@ static int hns_nic_dev_remove(struct platform_device *pdev)
1323     set_bit(NIC_STATE_REMOVING, &priv->state);
1324     (void)cancel_work_sync(&priv->service_task);
1325    
1326     + /* safe for ACPI FW */
1327     + of_node_put(to_of_node(priv->fwnode));
1328     +
1329     free_netdev(ndev);
1330     return 0;
1331     }
1332     diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c b/drivers/net/ethernet/hisilicon/hns_mdio.c
1333     index 501eb2090ca6..de23a0ead5d7 100644
1334     --- a/drivers/net/ethernet/hisilicon/hns_mdio.c
1335     +++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
1336     @@ -329,7 +329,7 @@ static int hns_mdio_read(struct mii_bus *bus, int phy_id, int regnum)
1337     }
1338    
1339     hns_mdio_cmd_write(mdio_dev, is_c45,
1340     - MDIO_C45_WRITE_ADDR, phy_id, devad);
1341     + MDIO_C45_READ, phy_id, devad);
1342     }
1343    
1344     /* Step 5: waitting for MDIO_COMMAND_REG 's mdio_start==0,*/
1345     diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
1346     index af11781fe5f9..4ac023a37936 100644
1347     --- a/drivers/net/ethernet/marvell/sky2.c
1348     +++ b/drivers/net/ethernet/marvell/sky2.c
1349     @@ -46,6 +46,7 @@
1350     #include <linux/mii.h>
1351     #include <linux/of_device.h>
1352     #include <linux/of_net.h>
1353     +#include <linux/dmi.h>
1354    
1355     #include <asm/irq.h>
1356    
1357     @@ -93,7 +94,7 @@ static int copybreak __read_mostly = 128;
1358     module_param(copybreak, int, 0);
1359     MODULE_PARM_DESC(copybreak, "Receive copy threshold");
1360    
1361     -static int disable_msi = 0;
1362     +static int disable_msi = -1;
1363     module_param(disable_msi, int, 0);
1364     MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
1365    
1366     @@ -4923,6 +4924,24 @@ static const char *sky2_name(u8 chipid, char *buf, int sz)
1367     return buf;
1368     }
1369    
1370     +static const struct dmi_system_id msi_blacklist[] = {
1371     + {
1372     + .ident = "Dell Inspiron 1545",
1373     + .matches = {
1374     + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1375     + DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1545"),
1376     + },
1377     + },
1378     + {
1379     + .ident = "Gateway P-79",
1380     + .matches = {
1381     + DMI_MATCH(DMI_SYS_VENDOR, "Gateway"),
1382     + DMI_MATCH(DMI_PRODUCT_NAME, "P-79"),
1383     + },
1384     + },
1385     + {}
1386     +};
1387     +
1388     static int sky2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1389     {
1390     struct net_device *dev, *dev1;
1391     @@ -5034,6 +5053,9 @@ static int sky2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1392     goto err_out_free_pci;
1393     }
1394    
1395     + if (disable_msi == -1)
1396     + disable_msi = !!dmi_check_system(msi_blacklist);
1397     +
1398     if (!disable_msi && pci_enable_msi(pdev) == 0) {
1399     err = sky2_test_msi(hw);
1400     if (err) {
1401     diff --git a/drivers/net/ethernet/qlogic/qed/qed_vf.c b/drivers/net/ethernet/qlogic/qed/qed_vf.c
1402     index 9cc02b94328a..cf34908ec8e1 100644
1403     --- a/drivers/net/ethernet/qlogic/qed/qed_vf.c
1404     +++ b/drivers/net/ethernet/qlogic/qed/qed_vf.c
1405     @@ -158,6 +158,7 @@ static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
1406     struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
1407     struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
1408     struct vf_pf_resc_request *p_resc;
1409     + u8 retry_cnt = VF_ACQUIRE_THRESH;
1410     bool resources_acquired = false;
1411     struct vfpf_acquire_tlv *req;
1412     int rc = 0, attempts = 0;
1413     @@ -203,6 +204,15 @@ static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
1414    
1415     /* send acquire request */
1416     rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1417     +
1418     + /* Re-try acquire in case of vf-pf hw channel timeout */
1419     + if (retry_cnt && rc == -EBUSY) {
1420     + DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1421     + "VF retrying to acquire due to VPC timeout\n");
1422     + retry_cnt--;
1423     + continue;
1424     + }
1425     +
1426     if (rc)
1427     goto exit;
1428    
1429     diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
1430     index d80c88bd2bba..6e61bccc90b3 100644
1431     --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
1432     +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
1433     @@ -877,8 +877,10 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
1434     }
1435    
1436     ret = phy_power_on(bsp_priv, true);
1437     - if (ret)
1438     + if (ret) {
1439     + gmac_clk_enable(bsp_priv, false);
1440     return ret;
1441     + }
1442    
1443     ret = gmac_clk_enable(bsp_priv, true);
1444     if (ret)
1445     diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
1446     index 53602fdf5b47..06f77ec44a15 100644
1447     --- a/drivers/net/hyperv/netvsc_drv.c
1448     +++ b/drivers/net/hyperv/netvsc_drv.c
1449     @@ -593,6 +593,14 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,
1450     schedule_delayed_work(&ndev_ctx->dwork, 0);
1451     }
1452    
1453     +static void netvsc_comp_ipcsum(struct sk_buff *skb)
1454     +{
1455     + struct iphdr *iph = (struct iphdr *)skb->data;
1456     +
1457     + iph->check = 0;
1458     + iph->check = ip_fast_csum(iph, iph->ihl);
1459     +}
1460     +
1461     static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net,
1462     struct hv_netvsc_packet *packet,
1463     struct ndis_tcp_ip_checksum_info *csum_info,
1464     @@ -616,9 +624,17 @@ static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net,
1465     /* skb is already created with CHECKSUM_NONE */
1466     skb_checksum_none_assert(skb);
1467    
1468     - /*
1469     - * In Linux, the IP checksum is always checked.
1470     - * Do L4 checksum offload if enabled and present.
1471     + /* Incoming packets may have IP header checksum verified by the host.
1472     + * They may not have IP header checksum computed after coalescing.
1473     + * We compute it here if the flags are set, because on Linux, the IP
1474     + * checksum is always checked.
1475     + */
1476     + if (csum_info && csum_info->receive.ip_checksum_value_invalid &&
1477     + csum_info->receive.ip_checksum_succeeded &&
1478     + skb->protocol == htons(ETH_P_IP))
1479     + netvsc_comp_ipcsum(skb);
1480     +
1481     + /* Do L4 checksum offload if enabled and present.
1482     */
1483     if (csum_info && (net->features & NETIF_F_RXCSUM)) {
1484     if (csum_info->receive.tcp_checksum_succeeded ||
1485     diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
1486     index 707190d3ada0..16f074408813 100644
1487     --- a/drivers/net/phy/micrel.c
1488     +++ b/drivers/net/phy/micrel.c
1489     @@ -341,6 +341,17 @@ static int ksz8041_config_aneg(struct phy_device *phydev)
1490     return genphy_config_aneg(phydev);
1491     }
1492    
1493     +static int ksz8061_config_init(struct phy_device *phydev)
1494     +{
1495     + int ret;
1496     +
1497     + ret = phy_write_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_DEVID1, 0xB61A);
1498     + if (ret)
1499     + return ret;
1500     +
1501     + return kszphy_config_init(phydev);
1502     +}
1503     +
1504     static int ksz9021_load_values_from_of(struct phy_device *phydev,
1505     const struct device_node *of_node,
1506     u16 reg,
1507     @@ -940,7 +951,7 @@ static struct phy_driver ksphy_driver[] = {
1508     .phy_id_mask = MICREL_PHY_ID_MASK,
1509     .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
1510     .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
1511     - .config_init = kszphy_config_init,
1512     + .config_init = ksz8061_config_init,
1513     .config_aneg = genphy_config_aneg,
1514     .read_status = genphy_read_status,
1515     .ack_interrupt = kszphy_ack_interrupt,
1516     diff --git a/drivers/net/team/team_mode_loadbalance.c b/drivers/net/team/team_mode_loadbalance.c
1517     index b228bea7931f..de2530830d93 100644
1518     --- a/drivers/net/team/team_mode_loadbalance.c
1519     +++ b/drivers/net/team/team_mode_loadbalance.c
1520     @@ -319,6 +319,20 @@ static int lb_bpf_func_set(struct team *team, struct team_gsetter_ctx *ctx)
1521     return 0;
1522     }
1523    
1524     +static void lb_bpf_func_free(struct team *team)
1525     +{
1526     + struct lb_priv *lb_priv = get_lb_priv(team);
1527     + struct bpf_prog *fp;
1528     +
1529     + if (!lb_priv->ex->orig_fprog)
1530     + return;
1531     +
1532     + __fprog_destroy(lb_priv->ex->orig_fprog);
1533     + fp = rcu_dereference_protected(lb_priv->fp,
1534     + lockdep_is_held(&team->lock));
1535     + bpf_prog_destroy(fp);
1536     +}
1537     +
1538     static int lb_tx_method_get(struct team *team, struct team_gsetter_ctx *ctx)
1539     {
1540     struct lb_priv *lb_priv = get_lb_priv(team);
1541     @@ -633,6 +647,7 @@ static void lb_exit(struct team *team)
1542    
1543     team_options_unregister(team, lb_options,
1544     ARRAY_SIZE(lb_options));
1545     + lb_bpf_func_free(team);
1546     cancel_delayed_work_sync(&lb_priv->ex->stats.refresh_dw);
1547     free_percpu(lb_priv->pcpu_stats);
1548     kfree(lb_priv->ex);
1549     diff --git a/drivers/net/tun.c b/drivers/net/tun.c
1550     index 7a0d5e928bec..24cc94453d38 100644
1551     --- a/drivers/net/tun.c
1552     +++ b/drivers/net/tun.c
1553     @@ -1471,9 +1471,9 @@ static struct sk_buff *tun_ring_recv(struct tun_file *tfile, int noblock,
1554     }
1555    
1556     add_wait_queue(&tfile->wq.wait, &wait);
1557     - current->state = TASK_INTERRUPTIBLE;
1558    
1559     while (1) {
1560     + set_current_state(TASK_INTERRUPTIBLE);
1561     skb = skb_array_consume(&tfile->tx_array);
1562     if (skb)
1563     break;
1564     @@ -1489,7 +1489,7 @@ static struct sk_buff *tun_ring_recv(struct tun_file *tfile, int noblock,
1565     schedule();
1566     }
1567    
1568     - current->state = TASK_RUNNING;
1569     + __set_current_state(TASK_RUNNING);
1570     remove_wait_queue(&tfile->wq.wait, &wait);
1571    
1572     out:
1573     diff --git a/drivers/net/xen-netback/hash.c b/drivers/net/xen-netback/hash.c
1574     index 3b6fb5b3bdb2..6414cc6b9032 100644
1575     --- a/drivers/net/xen-netback/hash.c
1576     +++ b/drivers/net/xen-netback/hash.c
1577     @@ -435,6 +435,8 @@ void xenvif_init_hash(struct xenvif *vif)
1578     if (xenvif_hash_cache_size == 0)
1579     return;
1580    
1581     + BUG_ON(vif->hash.cache.count);
1582     +
1583     spin_lock_init(&vif->hash.cache.lock);
1584     INIT_LIST_HEAD(&vif->hash.cache.list);
1585     }
1586     diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
1587     index 618013e7f87b..cae691486105 100644
1588     --- a/drivers/net/xen-netback/interface.c
1589     +++ b/drivers/net/xen-netback/interface.c
1590     @@ -152,6 +152,13 @@ static u16 xenvif_select_queue(struct net_device *dev, struct sk_buff *skb,
1591     {
1592     struct xenvif *vif = netdev_priv(dev);
1593     unsigned int size = vif->hash.size;
1594     + unsigned int num_queues;
1595     +
1596     + /* If queues are not set up internally - always return 0
1597     + * as the packet going to be dropped anyway */
1598     + num_queues = READ_ONCE(vif->num_queues);
1599     + if (num_queues < 1)
1600     + return 0;
1601    
1602     if (vif->hash.alg == XEN_NETIF_CTRL_HASH_ALGORITHM_NONE)
1603     return fallback(dev, skb) % dev->real_num_tx_queues;
1604     diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
1605     index a7bdb1ffac2e..f57815befc90 100644
1606     --- a/drivers/net/xen-netback/netback.c
1607     +++ b/drivers/net/xen-netback/netback.c
1608     @@ -1074,11 +1074,6 @@ static int xenvif_handle_frag_list(struct xenvif_queue *queue, struct sk_buff *s
1609     skb_frag_size_set(&frags[i], len);
1610     }
1611    
1612     - /* Copied all the bits from the frag list -- free it. */
1613     - skb_frag_list_init(skb);
1614     - xenvif_skb_zerocopy_prepare(queue, nskb);
1615     - kfree_skb(nskb);
1616     -
1617     /* Release all the original (foreign) frags. */
1618     for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
1619     skb_frag_unref(skb, f);
1620     @@ -1147,6 +1142,8 @@ static int xenvif_tx_submit(struct xenvif_queue *queue)
1621     xenvif_fill_frags(queue, skb);
1622    
1623     if (unlikely(skb_has_frag_list(skb))) {
1624     + struct sk_buff *nskb = skb_shinfo(skb)->frag_list;
1625     + xenvif_skb_zerocopy_prepare(queue, nskb);
1626     if (xenvif_handle_frag_list(queue, skb)) {
1627     if (net_ratelimit())
1628     netdev_err(queue->vif->dev,
1629     @@ -1155,6 +1152,9 @@ static int xenvif_tx_submit(struct xenvif_queue *queue)
1630     kfree_skb(skb);
1631     continue;
1632     }
1633     + /* Copied all the bits from the frag list -- free it. */
1634     + skb_frag_list_init(skb);
1635     + kfree_skb(nskb);
1636     }
1637    
1638     skb->dev = queue->vif->dev;
1639     diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
1640     index b8a21d7b25d4..1d81149c9ea4 100644
1641     --- a/drivers/platform/x86/Kconfig
1642     +++ b/drivers/platform/x86/Kconfig
1643     @@ -945,6 +945,7 @@ config INTEL_OAKTRAIL
1644     config SAMSUNG_Q10
1645     tristate "Samsung Q10 Extras"
1646     depends on ACPI
1647     + depends on BACKLIGHT_LCD_SUPPORT
1648     select BACKLIGHT_CLASS_DEVICE
1649     ---help---
1650     This driver provides support for backlight control on Samsung Q10
1651     diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
1652     index 8f77fc0630ce..86a02592b982 100644
1653     --- a/drivers/s390/net/qeth_core_main.c
1654     +++ b/drivers/s390/net/qeth_core_main.c
1655     @@ -2449,11 +2449,12 @@ out:
1656     return rc;
1657     }
1658    
1659     -static void qeth_free_qdio_out_buf(struct qeth_qdio_out_q *q)
1660     +static void qeth_free_output_queue(struct qeth_qdio_out_q *q)
1661     {
1662     if (!q)
1663     return;
1664    
1665     + qeth_clear_outq_buffers(q, 1);
1666     qdio_free_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
1667     kfree(q);
1668     }
1669     @@ -2526,10 +2527,8 @@ out_freeoutqbufs:
1670     card->qdio.out_qs[i]->bufs[j] = NULL;
1671     }
1672     out_freeoutq:
1673     - while (i > 0) {
1674     - qeth_free_qdio_out_buf(card->qdio.out_qs[--i]);
1675     - qeth_clear_outq_buffers(card->qdio.out_qs[i], 1);
1676     - }
1677     + while (i > 0)
1678     + qeth_free_output_queue(card->qdio.out_qs[--i]);
1679     kfree(card->qdio.out_qs);
1680     card->qdio.out_qs = NULL;
1681     out_freepool:
1682     @@ -2562,10 +2561,8 @@ static void qeth_free_qdio_buffers(struct qeth_card *card)
1683     qeth_free_buffer_pool(card);
1684     /* free outbound qdio_qs */
1685     if (card->qdio.out_qs) {
1686     - for (i = 0; i < card->qdio.no_out_queues; ++i) {
1687     - qeth_clear_outq_buffers(card->qdio.out_qs[i], 1);
1688     - qeth_free_qdio_out_buf(card->qdio.out_qs[i]);
1689     - }
1690     + for (i = 0; i < card->qdio.no_out_queues; i++)
1691     + qeth_free_output_queue(card->qdio.out_qs[i]);
1692     kfree(card->qdio.out_qs);
1693     card->qdio.out_qs = NULL;
1694     }
1695     diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
1696     index fe670b696251..2d9696b3d432 100644
1697     --- a/drivers/scsi/aacraid/commsup.c
1698     +++ b/drivers/scsi/aacraid/commsup.c
1699     @@ -1179,8 +1179,9 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
1700     ADD : DELETE;
1701     break;
1702     }
1703     - case AifBuManagerEvent:
1704     - aac_handle_aif_bu(dev, aifcmd);
1705     + break;
1706     + case AifBuManagerEvent:
1707     + aac_handle_aif_bu(dev, aifcmd);
1708     break;
1709     }
1710    
1711     diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
1712     index 50c71678a156..ae93f45f9cd8 100644
1713     --- a/drivers/scsi/libfc/fc_lport.c
1714     +++ b/drivers/scsi/libfc/fc_lport.c
1715     @@ -1736,14 +1736,14 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
1716     fc_frame_payload_op(fp) != ELS_LS_ACC) {
1717     FC_LPORT_DBG(lport, "FLOGI not accepted or bad response\n");
1718     fc_lport_error(lport, fp);
1719     - goto err;
1720     + goto out;
1721     }
1722    
1723     flp = fc_frame_payload_get(fp, sizeof(*flp));
1724     if (!flp) {
1725     FC_LPORT_DBG(lport, "FLOGI bad response\n");
1726     fc_lport_error(lport, fp);
1727     - goto err;
1728     + goto out;
1729     }
1730    
1731     mfs = ntohs(flp->fl_csp.sp_bb_data) &
1732     @@ -1753,7 +1753,7 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
1733     FC_LPORT_DBG(lport, "FLOGI bad mfs:%hu response, "
1734     "lport->mfs:%hu\n", mfs, lport->mfs);
1735     fc_lport_error(lport, fp);
1736     - goto err;
1737     + goto out;
1738     }
1739    
1740     if (mfs <= lport->mfs) {
1741     diff --git a/drivers/soc/fsl/qbman/qman.c b/drivers/soc/fsl/qbman/qman.c
1742     index 2cc82ed6433a..91f5c951850f 100644
1743     --- a/drivers/soc/fsl/qbman/qman.c
1744     +++ b/drivers/soc/fsl/qbman/qman.c
1745     @@ -1073,18 +1073,19 @@ static void qm_mr_process_task(struct work_struct *work);
1746     static irqreturn_t portal_isr(int irq, void *ptr)
1747     {
1748     struct qman_portal *p = ptr;
1749     -
1750     - u32 clear = QM_DQAVAIL_MASK | p->irq_sources;
1751     u32 is = qm_in(&p->p, QM_REG_ISR) & p->irq_sources;
1752     + u32 clear = 0;
1753    
1754     if (unlikely(!is))
1755     return IRQ_NONE;
1756    
1757     /* DQRR-handling if it's interrupt-driven */
1758     - if (is & QM_PIRQ_DQRI)
1759     + if (is & QM_PIRQ_DQRI) {
1760     __poll_portal_fast(p, QMAN_POLL_LIMIT);
1761     + clear = QM_DQAVAIL_MASK | QM_PIRQ_DQRI;
1762     + }
1763     /* Handling of anything else that's interrupt-driven */
1764     - clear |= __poll_portal_slow(p, is);
1765     + clear |= __poll_portal_slow(p, is) & QM_PIRQ_SLOW;
1766     qm_out(&p->p, QM_REG_ISR, clear);
1767     return IRQ_HANDLED;
1768     }
1769     diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
1770     index d270a424ecac..22c481f2ae4f 100644
1771     --- a/drivers/staging/android/ion/ion_system_heap.c
1772     +++ b/drivers/staging/android/ion/ion_system_heap.c
1773     @@ -307,10 +307,10 @@ static int ion_system_heap_create_pools(struct ion_page_pool **pools,
1774     bool cached)
1775     {
1776     int i;
1777     - gfp_t gfp_flags = low_order_gfp_flags;
1778    
1779     for (i = 0; i < NUM_ORDERS; i++) {
1780     struct ion_page_pool *pool;
1781     + gfp_t gfp_flags = low_order_gfp_flags;
1782    
1783     if (orders[i] > 4)
1784     gfp_flags = high_order_gfp_flags;
1785     diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c
1786     index 0dcb826a9f1f..723bdd2c2c74 100644
1787     --- a/drivers/staging/comedi/drivers/ni_660x.c
1788     +++ b/drivers/staging/comedi/drivers/ni_660x.c
1789     @@ -606,6 +606,7 @@ static int ni_660x_set_pfi_routing(struct comedi_device *dev,
1790     case NI_660X_PFI_OUTPUT_DIO:
1791     if (chan > 31)
1792     return -EINVAL;
1793     + break;
1794     default:
1795     return -EINVAL;
1796     }
1797     diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
1798     index 2e5e3b368532..b7203867ea9d 100644
1799     --- a/drivers/staging/wilc1000/linux_wlan.c
1800     +++ b/drivers/staging/wilc1000/linux_wlan.c
1801     @@ -1263,8 +1263,8 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
1802     vif->wilc = *wilc;
1803     vif->ndev = ndev;
1804     wl->vif[i] = vif;
1805     - wl->vif_num = i;
1806     - vif->idx = wl->vif_num;
1807     + wl->vif_num = i + 1;
1808     + vif->idx = i;
1809    
1810     ndev->netdev_ops = &wilc_netdev_ops;
1811    
1812     diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
1813     index 125cea1c3c8d..19ce615455c1 100644
1814     --- a/drivers/usb/phy/Kconfig
1815     +++ b/drivers/usb/phy/Kconfig
1816     @@ -20,7 +20,7 @@ config AB8500_USB
1817    
1818     config FSL_USB2_OTG
1819     bool "Freescale USB OTG Transceiver Driver"
1820     - depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_OTG_FSM && PM
1821     + depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_OTG_FSM=y && PM
1822     depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y'
1823     select USB_PHY
1824     help
1825     diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
1826     index c2b120021443..7bbf2ca73f68 100644
1827     --- a/drivers/usb/serial/cp210x.c
1828     +++ b/drivers/usb/serial/cp210x.c
1829     @@ -58,6 +58,7 @@ static const struct usb_device_id id_table[] = {
1830     { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */
1831     { USB_DEVICE(0x08FD, 0x000A) }, /* Digianswer A/S , ZigBee/802.15.4 MAC Device */
1832     { USB_DEVICE(0x0908, 0x01FF) }, /* Siemens RUGGEDCOM USB Serial Console */
1833     + { USB_DEVICE(0x0B00, 0x3070) }, /* Ingenico 3070 */
1834     { USB_DEVICE(0x0BED, 0x1100) }, /* MEI (TM) Cashflow-SC Bill/Voucher Acceptor */
1835     { USB_DEVICE(0x0BED, 0x1101) }, /* MEI series 2000 Combo Acceptor */
1836     { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */
1837     diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
1838     index 2e2f736384ab..b88a72220acd 100644
1839     --- a/drivers/usb/serial/ftdi_sio.c
1840     +++ b/drivers/usb/serial/ftdi_sio.c
1841     @@ -1020,6 +1020,8 @@ static const struct usb_device_id id_table_combined[] = {
1842     { USB_DEVICE(CYPRESS_VID, CYPRESS_WICED_BT_USB_PID) },
1843     { USB_DEVICE(CYPRESS_VID, CYPRESS_WICED_WL_USB_PID) },
1844     { USB_DEVICE(AIRBUS_DS_VID, AIRBUS_DS_P8GR) },
1845     + /* EZPrototypes devices */
1846     + { USB_DEVICE(EZPROTOTYPES_VID, HJELMSLUND_USB485_ISO_PID) },
1847     { } /* Terminating entry */
1848     };
1849    
1850     diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
1851     index 76a10b222ff9..ddf5ab983dc9 100644
1852     --- a/drivers/usb/serial/ftdi_sio_ids.h
1853     +++ b/drivers/usb/serial/ftdi_sio_ids.h
1854     @@ -1307,6 +1307,12 @@
1855     #define IONICS_VID 0x1c0c
1856     #define IONICS_PLUGCOMPUTER_PID 0x0102
1857    
1858     +/*
1859     + * EZPrototypes (PID reseller)
1860     + */
1861     +#define EZPROTOTYPES_VID 0x1c40
1862     +#define HJELMSLUND_USB485_ISO_PID 0x0477
1863     +
1864     /*
1865     * Dresden Elektronik Sensor Terminal Board
1866     */
1867     diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
1868     index 7bc2c9fef605..b2b7c12e5c86 100644
1869     --- a/drivers/usb/serial/option.c
1870     +++ b/drivers/usb/serial/option.c
1871     @@ -1147,6 +1147,8 @@ static const struct usb_device_id option_ids[] = {
1872     .driver_info = NCTRL(0) | RSVD(1) | RSVD(3) },
1873     { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_ME910_DUAL_MODEM),
1874     .driver_info = NCTRL(0) | RSVD(3) },
1875     + { USB_DEVICE_INTERFACE_CLASS(TELIT_VENDOR_ID, 0x1102, 0xff), /* Telit ME910 (ECM) */
1876     + .driver_info = NCTRL(0) },
1877     { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE910),
1878     .driver_info = NCTRL(0) | RSVD(1) | RSVD(2) },
1879     { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_LE910_USBCFG4),
1880     diff --git a/fs/autofs4/expire.c b/fs/autofs4/expire.c
1881     index d8e6d421c27f..2e1f50e467f1 100644
1882     --- a/fs/autofs4/expire.c
1883     +++ b/fs/autofs4/expire.c
1884     @@ -563,7 +563,6 @@ int autofs4_expire_run(struct super_block *sb,
1885     pkt.len = dentry->d_name.len;
1886     memcpy(pkt.name, dentry->d_name.name, pkt.len);
1887     pkt.name[pkt.len] = '\0';
1888     - dput(dentry);
1889    
1890     if (copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)))
1891     ret = -EFAULT;
1892     @@ -576,6 +575,8 @@ int autofs4_expire_run(struct super_block *sb,
1893     complete_all(&ino->expire_complete);
1894     spin_unlock(&sbi->fs_lock);
1895    
1896     + dput(dentry);
1897     +
1898     return ret;
1899     }
1900    
1901     diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
1902     index ce0c6ea96a87..d9a3264909d0 100644
1903     --- a/fs/autofs4/inode.c
1904     +++ b/fs/autofs4/inode.c
1905     @@ -259,8 +259,10 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
1906     }
1907     root_inode = autofs4_get_inode(s, S_IFDIR | 0755);
1908     root = d_make_root(root_inode);
1909     - if (!root)
1910     + if (!root) {
1911     + ret = -ENOMEM;
1912     goto fail_ino;
1913     + }
1914     pipe = NULL;
1915    
1916     root->d_fsdata = ino;
1917     diff --git a/fs/buffer.c b/fs/buffer.c
1918     index 5d8f496d624e..e0d46d47e358 100644
1919     --- a/fs/buffer.c
1920     +++ b/fs/buffer.c
1921     @@ -207,6 +207,7 @@ __find_get_block_slow(struct block_device *bdev, sector_t block)
1922     struct buffer_head *head;
1923     struct page *page;
1924     int all_mapped = 1;
1925     + static DEFINE_RATELIMIT_STATE(last_warned, HZ, 1);
1926    
1927     index = block >> (PAGE_SHIFT - bd_inode->i_blkbits);
1928     page = find_get_page_flags(bd_mapping, index, FGP_ACCESSED);
1929     @@ -234,15 +235,15 @@ __find_get_block_slow(struct block_device *bdev, sector_t block)
1930     * file io on the block device and getblk. It gets dealt with
1931     * elsewhere, don't buffer_error if we had some unmapped buffers
1932     */
1933     - if (all_mapped) {
1934     - printk("__find_get_block_slow() failed. "
1935     - "block=%llu, b_blocknr=%llu\n",
1936     - (unsigned long long)block,
1937     - (unsigned long long)bh->b_blocknr);
1938     - printk("b_state=0x%08lx, b_size=%zu\n",
1939     - bh->b_state, bh->b_size);
1940     - printk("device %pg blocksize: %d\n", bdev,
1941     - 1 << bd_inode->i_blkbits);
1942     + ratelimit_set_flags(&last_warned, RATELIMIT_MSG_ON_RELEASE);
1943     + if (all_mapped && __ratelimit(&last_warned)) {
1944     + printk("__find_get_block_slow() failed. block=%llu, "
1945     + "b_blocknr=%llu, b_state=0x%08lx, b_size=%zu, "
1946     + "device %pg blocksize: %d\n",
1947     + (unsigned long long)block,
1948     + (unsigned long long)bh->b_blocknr,
1949     + bh->b_state, bh->b_size, bdev,
1950     + 1 << bd_inode->i_blkbits);
1951     }
1952     out_unlock:
1953     spin_unlock(&bd_mapping->private_lock);
1954     diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
1955     index 1e1449ad00e8..1af7afae3ad1 100644
1956     --- a/fs/cifs/smb2pdu.h
1957     +++ b/fs/cifs/smb2pdu.h
1958     @@ -84,8 +84,8 @@
1959    
1960     #define NUMBER_OF_SMB2_COMMANDS 0x0013
1961    
1962     -/* 4 len + 52 transform hdr + 64 hdr + 56 create rsp */
1963     -#define MAX_SMB2_HDR_SIZE 0x00b0
1964     +/* 52 transform hdr + 64 hdr + 88 create rsp */
1965     +#define MAX_SMB2_HDR_SIZE 204
1966    
1967     #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
1968     #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
1969     diff --git a/fs/drop_caches.c b/fs/drop_caches.c
1970     index d72d52b90433..280460fef066 100644
1971     --- a/fs/drop_caches.c
1972     +++ b/fs/drop_caches.c
1973     @@ -20,8 +20,13 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
1974     spin_lock(&sb->s_inode_list_lock);
1975     list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
1976     spin_lock(&inode->i_lock);
1977     + /*
1978     + * We must skip inodes in unusual state. We may also skip
1979     + * inodes without pages but we deliberately won't in case
1980     + * we need to reschedule to avoid softlockups.
1981     + */
1982     if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) ||
1983     - (inode->i_mapping->nrpages == 0)) {
1984     + (inode->i_mapping->nrpages == 0 && !need_resched())) {
1985     spin_unlock(&inode->i_lock);
1986     continue;
1987     }
1988     @@ -29,6 +34,7 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
1989     spin_unlock(&inode->i_lock);
1990     spin_unlock(&sb->s_inode_list_lock);
1991    
1992     + cond_resched();
1993     invalidate_mapping_pages(inode->i_mapping, 0, -1);
1994     iput(toput_inode);
1995     toput_inode = inode;
1996     diff --git a/fs/exec.c b/fs/exec.c
1997     index fcd8642ef2d2..81477116035d 100644
1998     --- a/fs/exec.c
1999     +++ b/fs/exec.c
2000     @@ -938,7 +938,7 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size,
2001     i_size - pos);
2002     if (bytes < 0) {
2003     ret = bytes;
2004     - goto out;
2005     + goto out_free;
2006     }
2007    
2008     if (bytes == 0)
2009     diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
2010     index f53c139c312e..001487b230b5 100644
2011     --- a/fs/hugetlbfs/inode.c
2012     +++ b/fs/hugetlbfs/inode.c
2013     @@ -861,6 +861,18 @@ static int hugetlbfs_migrate_page(struct address_space *mapping,
2014     rc = migrate_huge_page_move_mapping(mapping, newpage, page);
2015     if (rc != MIGRATEPAGE_SUCCESS)
2016     return rc;
2017     +
2018     + /*
2019     + * page_private is subpool pointer in hugetlb pages. Transfer to
2020     + * new page. PagePrivate is not associated with page_private for
2021     + * hugetlb pages and can not be set here as only page_huge_active
2022     + * pages can be migrated.
2023     + */
2024     + if (page_private(page)) {
2025     + set_page_private(newpage, page_private(page));
2026     + set_page_private(page, 0);
2027     + }
2028     +
2029     migrate_page_copy(newpage, page);
2030    
2031     return MIGRATEPAGE_SUCCESS;
2032     diff --git a/fs/ncpfs/ioctl.c b/fs/ncpfs/ioctl.c
2033     index 0a3f9b594602..37779ed3f790 100644
2034     --- a/fs/ncpfs/ioctl.c
2035     +++ b/fs/ncpfs/ioctl.c
2036     @@ -233,7 +233,7 @@ ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
2037     len = strlen(server->nls_vol->charset);
2038     if (len > NCP_IOCSNAME_LEN)
2039     len = NCP_IOCSNAME_LEN;
2040     - strncpy(user.codepage, server->nls_vol->charset, len);
2041     + strscpy(user.codepage, server->nls_vol->charset, NCP_IOCSNAME_LEN);
2042     user.codepage[len] = 0;
2043     }
2044    
2045     @@ -243,7 +243,7 @@ ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
2046     len = strlen(server->nls_io->charset);
2047     if (len > NCP_IOCSNAME_LEN)
2048     len = NCP_IOCSNAME_LEN;
2049     - strncpy(user.iocharset, server->nls_io->charset, len);
2050     + strscpy(user.iocharset, server->nls_io->charset, NCP_IOCSNAME_LEN);
2051     user.iocharset[len] = 0;
2052     }
2053     mutex_unlock(&server->root_setup_lock);
2054     diff --git a/fs/nfs/super.c b/fs/nfs/super.c
2055     index 35aef192a13f..659ad12e33ba 100644
2056     --- a/fs/nfs/super.c
2057     +++ b/fs/nfs/super.c
2058     @@ -1904,6 +1904,11 @@ static int nfs_parse_devname(const char *dev_name,
2059     size_t len;
2060     char *end;
2061    
2062     + if (unlikely(!dev_name || !*dev_name)) {
2063     + dfprintk(MOUNT, "NFS: device name not specified\n");
2064     + return -EINVAL;
2065     + }
2066     +
2067     /* Is the host name protected with square brakcets? */
2068     if (*dev_name == '[') {
2069     end = strchr(++dev_name, ']');
2070     diff --git a/include/drm/drm_cache.h b/include/drm/drm_cache.h
2071     index cebecff536a3..c5fb6f871930 100644
2072     --- a/include/drm/drm_cache.h
2073     +++ b/include/drm/drm_cache.h
2074     @@ -41,6 +41,24 @@ static inline bool drm_arch_can_wc_memory(void)
2075     return false;
2076     #elif defined(CONFIG_MIPS) && defined(CONFIG_CPU_LOONGSON3)
2077     return false;
2078     +#elif defined(CONFIG_ARM) || defined(CONFIG_ARM64)
2079     + /*
2080     + * The DRM driver stack is designed to work with cache coherent devices
2081     + * only, but permits an optimization to be enabled in some cases, where
2082     + * for some buffers, both the CPU and the GPU use uncached mappings,
2083     + * removing the need for DMA snooping and allocation in the CPU caches.
2084     + *
2085     + * The use of uncached GPU mappings relies on the correct implementation
2086     + * of the PCIe NoSnoop TLP attribute by the platform, otherwise the GPU
2087     + * will use cached mappings nonetheless. On x86 platforms, this does not
2088     + * seem to matter, as uncached CPU mappings will snoop the caches in any
2089     + * case. However, on ARM and arm64, enabling this optimization on a
2090     + * platform where NoSnoop is ignored results in loss of coherency, which
2091     + * breaks correct operation of the device. Since we have no way of
2092     + * detecting whether NoSnoop works or not, just disable this
2093     + * optimization entirely for ARM and arm64.
2094     + */
2095     + return false;
2096     #else
2097     return true;
2098     #endif
2099     diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
2100     index 32dc0cbd51ca..9d9e0b54f831 100644
2101     --- a/include/linux/cpufreq.h
2102     +++ b/include/linux/cpufreq.h
2103     @@ -234,20 +234,12 @@ __ATTR(_name, _perm, show_##_name, NULL)
2104     static struct freq_attr _name = \
2105     __ATTR(_name, 0644, show_##_name, store_##_name)
2106    
2107     -struct global_attr {
2108     - struct attribute attr;
2109     - ssize_t (*show)(struct kobject *kobj,
2110     - struct attribute *attr, char *buf);
2111     - ssize_t (*store)(struct kobject *a, struct attribute *b,
2112     - const char *c, size_t count);
2113     -};
2114     -
2115     #define define_one_global_ro(_name) \
2116     -static struct global_attr _name = \
2117     +static struct kobj_attribute _name = \
2118     __ATTR(_name, 0444, show_##_name, NULL)
2119    
2120     #define define_one_global_rw(_name) \
2121     -static struct global_attr _name = \
2122     +static struct kobj_attribute _name = \
2123     __ATTR(_name, 0644, show_##_name, store_##_name)
2124    
2125    
2126     diff --git a/include/net/icmp.h b/include/net/icmp.h
2127     index 3ef2743a8eec..8665bf24e3b7 100644
2128     --- a/include/net/icmp.h
2129     +++ b/include/net/icmp.h
2130     @@ -22,6 +22,7 @@
2131    
2132     #include <net/inet_sock.h>
2133     #include <net/snmp.h>
2134     +#include <net/ip.h>
2135    
2136     struct icmp_err {
2137     int errno;
2138     @@ -39,7 +40,13 @@ struct net_proto_family;
2139     struct sk_buff;
2140     struct net;
2141    
2142     -void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info);
2143     +void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info,
2144     + const struct ip_options *opt);
2145     +static inline void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
2146     +{
2147     + __icmp_send(skb_in, type, code, info, &IPCB(skb_in)->opt);
2148     +}
2149     +
2150     int icmp_rcv(struct sk_buff *skb);
2151     void icmp_err(struct sk_buff *skb, u32 info);
2152     int icmp_init(void);
2153     diff --git a/include/net/ip.h b/include/net/ip.h
2154     index 8646da034851..f06cd30bb44c 100644
2155     --- a/include/net/ip.h
2156     +++ b/include/net/ip.h
2157     @@ -570,6 +570,8 @@ static inline int ip_options_echo(struct ip_options *dopt, struct sk_buff *skb)
2158     }
2159    
2160     void ip_options_fragment(struct sk_buff *skb);
2161     +int __ip_options_compile(struct net *net, struct ip_options *opt,
2162     + struct sk_buff *skb, __be32 *info);
2163     int ip_options_compile(struct net *net, struct ip_options *opt,
2164     struct sk_buff *skb);
2165     int ip_options_get(struct net *net, struct ip_options_rcu **optp,
2166     diff --git a/kernel/events/core.c b/kernel/events/core.c
2167     index 17339506f9f8..5cbb2eda80b5 100644
2168     --- a/kernel/events/core.c
2169     +++ b/kernel/events/core.c
2170     @@ -428,18 +428,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
2171     void __user *buffer, size_t *lenp,
2172     loff_t *ppos)
2173     {
2174     - int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2175     -
2176     - if (ret || !write)
2177     - return ret;
2178     -
2179     + int ret;
2180     + int perf_cpu = sysctl_perf_cpu_time_max_percent;
2181     /*
2182     * If throttling is disabled don't allow the write:
2183     */
2184     - if (sysctl_perf_cpu_time_max_percent == 100 ||
2185     - sysctl_perf_cpu_time_max_percent == 0)
2186     + if (write && (perf_cpu == 100 || perf_cpu == 0))
2187     return -EINVAL;
2188    
2189     + ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2190     + if (ret || !write)
2191     + return ret;
2192     +
2193     max_samples_per_tick = DIV_ROUND_UP(sysctl_perf_event_sample_rate, HZ);
2194     perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate;
2195     update_perf_cpu_limits();
2196     diff --git a/kernel/futex.c b/kernel/futex.c
2197     index 053d7be08be5..30fe0432c46d 100644
2198     --- a/kernel/futex.c
2199     +++ b/kernel/futex.c
2200     @@ -2966,10 +2966,13 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
2201     */
2202     WARN_ON(!q.pi_state);
2203     pi_mutex = &q.pi_state->pi_mutex;
2204     - ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter);
2205     - debug_rt_mutex_free_waiter(&rt_waiter);
2206     + ret = rt_mutex_wait_proxy_lock(pi_mutex, to, &rt_waiter);
2207    
2208     spin_lock(q.lock_ptr);
2209     + if (ret && !rt_mutex_cleanup_proxy_lock(pi_mutex, &rt_waiter))
2210     + ret = 0;
2211     +
2212     + debug_rt_mutex_free_waiter(&rt_waiter);
2213     /*
2214     * Fixup the pi_state owner and possibly acquire the lock if we
2215     * haven't already.
2216     diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
2217     index 196cc460e38d..7615e7722258 100644
2218     --- a/kernel/locking/rtmutex.c
2219     +++ b/kernel/locking/rtmutex.c
2220     @@ -1746,21 +1746,23 @@ struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock)
2221     }
2222    
2223     /**
2224     - * rt_mutex_finish_proxy_lock() - Complete lock acquisition
2225     + * rt_mutex_wait_proxy_lock() - Wait for lock acquisition
2226     * @lock: the rt_mutex we were woken on
2227     * @to: the timeout, null if none. hrtimer should already have
2228     * been started.
2229     * @waiter: the pre-initialized rt_mutex_waiter
2230     *
2231     - * Complete the lock acquisition started our behalf by another thread.
2232     + * Wait for the the lock acquisition started on our behalf by
2233     + * rt_mutex_start_proxy_lock(). Upon failure, the caller must call
2234     + * rt_mutex_cleanup_proxy_lock().
2235     *
2236     * Returns:
2237     * 0 - success
2238     * <0 - error, one of -EINTR, -ETIMEDOUT
2239     *
2240     - * Special API call for PI-futex requeue support
2241     + * Special API call for PI-futex support
2242     */
2243     -int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
2244     +int rt_mutex_wait_proxy_lock(struct rt_mutex *lock,
2245     struct hrtimer_sleeper *to,
2246     struct rt_mutex_waiter *waiter)
2247     {
2248     @@ -1773,9 +1775,6 @@ int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
2249     /* sleep on the mutex */
2250     ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);
2251    
2252     - if (unlikely(ret))
2253     - remove_waiter(lock, waiter);
2254     -
2255     /*
2256     * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might
2257     * have to fix that up.
2258     @@ -1786,3 +1785,42 @@ int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
2259    
2260     return ret;
2261     }
2262     +
2263     +/**
2264     + * rt_mutex_cleanup_proxy_lock() - Cleanup failed lock acquisition
2265     + * @lock: the rt_mutex we were woken on
2266     + * @waiter: the pre-initialized rt_mutex_waiter
2267     + *
2268     + * Attempt to clean up after a failed rt_mutex_wait_proxy_lock().
2269     + *
2270     + * Unless we acquired the lock; we're still enqueued on the wait-list and can
2271     + * in fact still be granted ownership until we're removed. Therefore we can
2272     + * find we are in fact the owner and must disregard the
2273     + * rt_mutex_wait_proxy_lock() failure.
2274     + *
2275     + * Returns:
2276     + * true - did the cleanup, we done.
2277     + * false - we acquired the lock after rt_mutex_wait_proxy_lock() returned,
2278     + * caller should disregards its return value.
2279     + *
2280     + * Special API call for PI-futex support
2281     + */
2282     +bool rt_mutex_cleanup_proxy_lock(struct rt_mutex *lock,
2283     + struct rt_mutex_waiter *waiter)
2284     +{
2285     + bool cleanup = false;
2286     +
2287     + raw_spin_lock_irq(&lock->wait_lock);
2288     + /*
2289     + * Unless we're the owner; we're still enqueued on the wait_list.
2290     + * So check if we became owner, if not, take us off the wait_list.
2291     + */
2292     + if (rt_mutex_owner(lock) != current) {
2293     + remove_waiter(lock, waiter);
2294     + fixup_rt_mutex_waiters(lock);
2295     + cleanup = true;
2296     + }
2297     + raw_spin_unlock_irq(&lock->wait_lock);
2298     +
2299     + return cleanup;
2300     +}
2301     diff --git a/kernel/locking/rtmutex_common.h b/kernel/locking/rtmutex_common.h
2302     index 50848b460851..14cbafed0014 100644
2303     --- a/kernel/locking/rtmutex_common.h
2304     +++ b/kernel/locking/rtmutex_common.h
2305     @@ -107,9 +107,11 @@ extern void rt_mutex_proxy_unlock(struct rt_mutex *lock,
2306     extern int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
2307     struct rt_mutex_waiter *waiter,
2308     struct task_struct *task);
2309     -extern int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
2310     - struct hrtimer_sleeper *to,
2311     - struct rt_mutex_waiter *waiter);
2312     +extern int rt_mutex_wait_proxy_lock(struct rt_mutex *lock,
2313     + struct hrtimer_sleeper *to,
2314     + struct rt_mutex_waiter *waiter);
2315     +extern bool rt_mutex_cleanup_proxy_lock(struct rt_mutex *lock,
2316     + struct rt_mutex_waiter *waiter);
2317     extern int rt_mutex_timed_futex_lock(struct rt_mutex *l, struct hrtimer_sleeper *to);
2318     extern bool rt_mutex_futex_unlock(struct rt_mutex *lock,
2319     struct wake_q_head *wqh);
2320     diff --git a/mm/hugetlb.c b/mm/hugetlb.c
2321     index 3e50fcfe6ad8..8b682da98d95 100644
2322     --- a/mm/hugetlb.c
2323     +++ b/mm/hugetlb.c
2324     @@ -3579,7 +3579,6 @@ retry_avoidcopy:
2325     copy_user_huge_page(new_page, old_page, address, vma,
2326     pages_per_huge_page(h));
2327     __SetPageUptodate(new_page);
2328     - set_page_huge_active(new_page);
2329    
2330     mmun_start = address & huge_page_mask(h);
2331     mmun_end = mmun_start + huge_page_size(h);
2332     @@ -3601,6 +3600,7 @@ retry_avoidcopy:
2333     make_huge_pte(vma, new_page, 1));
2334     page_remove_rmap(old_page, true);
2335     hugepage_add_new_anon_rmap(new_page, vma, address);
2336     + set_page_huge_active(new_page);
2337     /* Make the old page be freed below */
2338     new_page = old_page;
2339     }
2340     @@ -3683,6 +3683,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
2341     struct page *page;
2342     pte_t new_pte;
2343     spinlock_t *ptl;
2344     + bool new_page = false;
2345    
2346     /*
2347     * Currently, we are forced to kill the process in the event the
2348     @@ -3716,7 +3717,7 @@ retry:
2349     }
2350     clear_huge_page(page, address, pages_per_huge_page(h));
2351     __SetPageUptodate(page);
2352     - set_page_huge_active(page);
2353     + new_page = true;
2354    
2355     if (vma->vm_flags & VM_MAYSHARE) {
2356     int err = huge_add_to_page_cache(page, mapping, idx);
2357     @@ -3788,6 +3789,15 @@ retry:
2358     }
2359    
2360     spin_unlock(ptl);
2361     +
2362     + /*
2363     + * Only make newly allocated pages active. Existing pages found
2364     + * in the pagecache could be !page_huge_active() if they have been
2365     + * isolated for migration.
2366     + */
2367     + if (new_page)
2368     + set_page_huge_active(page);
2369     +
2370     unlock_page(page);
2371     out:
2372     return ret;
2373     diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
2374     index e4c271298074..b4c8d7b9ab82 100644
2375     --- a/mm/memory_hotplug.c
2376     +++ b/mm/memory_hotplug.c
2377     @@ -1471,7 +1471,8 @@ static struct page *next_active_pageblock(struct page *page)
2378     bool is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)
2379     {
2380     struct page *page = pfn_to_page(start_pfn);
2381     - struct page *end_page = page + nr_pages;
2382     + unsigned long end_pfn = min(start_pfn + nr_pages, zone_end_pfn(page_zone(page)));
2383     + struct page *end_page = pfn_to_page(end_pfn);
2384    
2385     /* Check the starting page of each pageblock within the range */
2386     for (; page < end_page; page = next_active_pageblock(page)) {
2387     @@ -1511,6 +1512,9 @@ int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn,
2388     i++;
2389     if (i == MAX_ORDER_NR_PAGES || pfn + i >= end_pfn)
2390     continue;
2391     + /* Check if we got outside of the zone */
2392     + if (zone && !zone_spans_pfn(zone, pfn + i))
2393     + return 0;
2394     page = pfn_to_page(pfn + i);
2395     if (zone && page_zone(page) != zone)
2396     return 0;
2397     diff --git a/mm/migrate.c b/mm/migrate.c
2398     index b08c1a4a1c22..b810ac1359f0 100644
2399     --- a/mm/migrate.c
2400     +++ b/mm/migrate.c
2401     @@ -1234,6 +1234,16 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
2402     lock_page(hpage);
2403     }
2404    
2405     + /*
2406     + * Check for pages which are in the process of being freed. Without
2407     + * page_mapping() set, hugetlbfs specific move page routine will not
2408     + * be called and we could leak usage counts for subpools.
2409     + */
2410     + if (page_private(hpage) && !page_mapping(hpage)) {
2411     + rc = -EBUSY;
2412     + goto out_unlock;
2413     + }
2414     +
2415     if (PageAnon(hpage))
2416     anon_vma = page_get_anon_vma(hpage);
2417    
2418     @@ -1265,6 +1275,7 @@ put_anon:
2419     set_page_owner_migrate_reason(new_hpage, reason);
2420     }
2421    
2422     +out_unlock:
2423     unlock_page(hpage);
2424     out:
2425     if (rc != -EAGAIN)
2426     diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
2427     index 6e4f34721080..3333693d8052 100644
2428     --- a/net/core/net-sysfs.c
2429     +++ b/net/core/net-sysfs.c
2430     @@ -1380,6 +1380,9 @@ static int register_queue_kobjects(struct net_device *dev)
2431     error:
2432     netdev_queue_update_kobjects(dev, txq, 0);
2433     net_rx_queue_update_kobjects(dev, rxq, 0);
2434     +#ifdef CONFIG_SYSFS
2435     + kset_unregister(dev->queues_kset);
2436     +#endif
2437     return error;
2438     }
2439    
2440     diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
2441     index 571d079e262f..71bcab94c5c7 100644
2442     --- a/net/ipv4/cipso_ipv4.c
2443     +++ b/net/ipv4/cipso_ipv4.c
2444     @@ -667,7 +667,8 @@ static int cipso_v4_map_lvl_valid(const struct cipso_v4_doi *doi_def, u8 level)
2445     case CIPSO_V4_MAP_PASS:
2446     return 0;
2447     case CIPSO_V4_MAP_TRANS:
2448     - if (doi_def->map.std->lvl.cipso[level] < CIPSO_V4_INV_LVL)
2449     + if ((level < doi_def->map.std->lvl.cipso_size) &&
2450     + (doi_def->map.std->lvl.cipso[level] < CIPSO_V4_INV_LVL))
2451     return 0;
2452     break;
2453     }
2454     @@ -1735,13 +1736,26 @@ validate_return:
2455     */
2456     void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway)
2457     {
2458     + unsigned char optbuf[sizeof(struct ip_options) + 40];
2459     + struct ip_options *opt = (struct ip_options *)optbuf;
2460     +
2461     if (ip_hdr(skb)->protocol == IPPROTO_ICMP || error != -EACCES)
2462     return;
2463    
2464     + /*
2465     + * We might be called above the IP layer,
2466     + * so we can not use icmp_send and IPCB here.
2467     + */
2468     +
2469     + memset(opt, 0, sizeof(struct ip_options));
2470     + opt->optlen = ip_hdr(skb)->ihl*4 - sizeof(struct iphdr);
2471     + if (__ip_options_compile(dev_net(skb->dev), opt, skb, NULL))
2472     + return;
2473     +
2474     if (gateway)
2475     - icmp_send(skb, ICMP_DEST_UNREACH, ICMP_NET_ANO, 0);
2476     + __icmp_send(skb, ICMP_DEST_UNREACH, ICMP_NET_ANO, 0, opt);
2477     else
2478     - icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_ANO, 0);
2479     + __icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_ANO, 0, opt);
2480     }
2481    
2482     /**
2483     diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
2484     index 31f17f0bbd1c..172d3dfed0c4 100644
2485     --- a/net/ipv4/icmp.c
2486     +++ b/net/ipv4/icmp.c
2487     @@ -565,7 +565,8 @@ relookup_failed:
2488     * MUST reply to only the first fragment.
2489     */
2490    
2491     -void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
2492     +void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info,
2493     + const struct ip_options *opt)
2494     {
2495     struct iphdr *iph;
2496     int room;
2497     @@ -679,7 +680,7 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info)
2498     iph->tos;
2499     mark = IP4_REPLY_MARK(net, skb_in->mark);
2500    
2501     - if (ip_options_echo(&icmp_param->replyopts.opt.opt, skb_in))
2502     + if (__ip_options_echo(&icmp_param->replyopts.opt.opt, skb_in, opt))
2503     goto out_unlock;
2504    
2505    
2506     @@ -731,7 +732,7 @@ out_free:
2507     kfree(icmp_param);
2508     out:;
2509     }
2510     -EXPORT_SYMBOL(icmp_send);
2511     +EXPORT_SYMBOL(__icmp_send);
2512    
2513    
2514     static void icmp_socket_deliver(struct sk_buff *skb, u32 info)
2515     diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c
2516     index 4d158ff1def1..4cd3b5ad9cee 100644
2517     --- a/net/ipv4/ip_options.c
2518     +++ b/net/ipv4/ip_options.c
2519     @@ -253,8 +253,9 @@ static void spec_dst_fill(__be32 *spec_dst, struct sk_buff *skb)
2520     * If opt == NULL, then skb->data should point to IP header.
2521     */
2522    
2523     -int ip_options_compile(struct net *net,
2524     - struct ip_options *opt, struct sk_buff *skb)
2525     +int __ip_options_compile(struct net *net,
2526     + struct ip_options *opt, struct sk_buff *skb,
2527     + __be32 *info)
2528     {
2529     __be32 spec_dst = htonl(INADDR_ANY);
2530     unsigned char *pp_ptr = NULL;
2531     @@ -470,11 +471,22 @@ eol:
2532     return 0;
2533    
2534     error:
2535     - if (skb) {
2536     - icmp_send(skb, ICMP_PARAMETERPROB, 0, htonl((pp_ptr-iph)<<24));
2537     - }
2538     + if (info)
2539     + *info = htonl((pp_ptr-iph)<<24);
2540     return -EINVAL;
2541     }
2542     +
2543     +int ip_options_compile(struct net *net,
2544     + struct ip_options *opt, struct sk_buff *skb)
2545     +{
2546     + int ret;
2547     + __be32 info;
2548     +
2549     + ret = __ip_options_compile(net, opt, skb, &info);
2550     + if (ret != 0 && skb)
2551     + icmp_send(skb, ICMP_PARAMETERPROB, 0, info);
2552     + return ret;
2553     +}
2554     EXPORT_SYMBOL(ip_options_compile);
2555    
2556     /*
2557     diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
2558     index cbff0d6ff1ac..270e79f4d40e 100644
2559     --- a/net/ipv4/ip_vti.c
2560     +++ b/net/ipv4/ip_vti.c
2561     @@ -74,6 +74,33 @@ drop:
2562     return 0;
2563     }
2564    
2565     +static int vti_input_ipip(struct sk_buff *skb, int nexthdr, __be32 spi,
2566     + int encap_type)
2567     +{
2568     + struct ip_tunnel *tunnel;
2569     + const struct iphdr *iph = ip_hdr(skb);
2570     + struct net *net = dev_net(skb->dev);
2571     + struct ip_tunnel_net *itn = net_generic(net, vti_net_id);
2572     +
2573     + tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
2574     + iph->saddr, iph->daddr, 0);
2575     + if (tunnel) {
2576     + if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
2577     + goto drop;
2578     +
2579     + XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel;
2580     +
2581     + skb->dev = tunnel->dev;
2582     +
2583     + return xfrm_input(skb, nexthdr, spi, encap_type);
2584     + }
2585     +
2586     + return -EINVAL;
2587     +drop:
2588     + kfree_skb(skb);
2589     + return 0;
2590     +}
2591     +
2592     static int vti_rcv(struct sk_buff *skb)
2593     {
2594     XFRM_SPI_SKB_CB(skb)->family = AF_INET;
2595     @@ -82,6 +109,14 @@ static int vti_rcv(struct sk_buff *skb)
2596     return vti_input(skb, ip_hdr(skb)->protocol, 0, 0);
2597     }
2598    
2599     +static int vti_rcv_ipip(struct sk_buff *skb)
2600     +{
2601     + XFRM_SPI_SKB_CB(skb)->family = AF_INET;
2602     + XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
2603     +
2604     + return vti_input_ipip(skb, ip_hdr(skb)->protocol, ip_hdr(skb)->saddr, 0);
2605     +}
2606     +
2607     static int vti_rcv_cb(struct sk_buff *skb, int err)
2608     {
2609     unsigned short family;
2610     @@ -439,6 +474,12 @@ static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = {
2611     .priority = 100,
2612     };
2613    
2614     +static struct xfrm_tunnel ipip_handler __read_mostly = {
2615     + .handler = vti_rcv_ipip,
2616     + .err_handler = vti4_err,
2617     + .priority = 0,
2618     +};
2619     +
2620     static int __net_init vti_init_net(struct net *net)
2621     {
2622     int err;
2623     @@ -622,6 +663,13 @@ static int __init vti_init(void)
2624     if (err < 0)
2625     goto xfrm_proto_comp_failed;
2626    
2627     + msg = "ipip tunnel";
2628     + err = xfrm4_tunnel_register(&ipip_handler, AF_INET);
2629     + if (err < 0) {
2630     + pr_info("%s: cant't register tunnel\n",__func__);
2631     + goto xfrm_tunnel_failed;
2632     + }
2633     +
2634     msg = "netlink interface";
2635     err = rtnl_link_register(&vti_link_ops);
2636     if (err < 0)
2637     @@ -631,6 +679,8 @@ static int __init vti_init(void)
2638    
2639     rtnl_link_failed:
2640     xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP);
2641     +xfrm_tunnel_failed:
2642     + xfrm4_tunnel_deregister(&ipip_handler, AF_INET);
2643     xfrm_proto_comp_failed:
2644     xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH);
2645     xfrm_proto_ah_failed:
2646     diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
2647     index ad597b4b22a0..41f67629ae59 100644
2648     --- a/net/ipv6/ip6mr.c
2649     +++ b/net/ipv6/ip6mr.c
2650     @@ -1992,10 +1992,10 @@ int ip6mr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg)
2651    
2652     static inline int ip6mr_forward2_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
2653     {
2654     - __IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
2655     - IPSTATS_MIB_OUTFORWDATAGRAMS);
2656     - __IP6_ADD_STATS(net, ip6_dst_idev(skb_dst(skb)),
2657     - IPSTATS_MIB_OUTOCTETS, skb->len);
2658     + IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
2659     + IPSTATS_MIB_OUTFORWDATAGRAMS);
2660     + IP6_ADD_STATS(net, ip6_dst_idev(skb_dst(skb)),
2661     + IPSTATS_MIB_OUTOCTETS, skb->len);
2662     return dst_output(net, sk, skb);
2663     }
2664    
2665     diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
2666     index 4381ea53fa91..75de3dd8b862 100644
2667     --- a/net/ipv6/sit.c
2668     +++ b/net/ipv6/sit.c
2669     @@ -1851,6 +1851,7 @@ static int __net_init sit_init_net(struct net *net)
2670    
2671     err_reg_dev:
2672     ipip6_dev_free(sitn->fb_tunnel_dev);
2673     + free_netdev(sitn->fb_tunnel_dev);
2674     err_alloc_dev:
2675     return err;
2676     }
2677     diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
2678     index 8382b7880b24..8037b25ddb76 100644
2679     --- a/net/netfilter/ipvs/ip_vs_ctl.c
2680     +++ b/net/netfilter/ipvs/ip_vs_ctl.c
2681     @@ -2258,6 +2258,18 @@ static int ip_vs_set_timeout(struct netns_ipvs *ipvs, struct ip_vs_timeout_user
2682     u->tcp_fin_timeout,
2683     u->udp_timeout);
2684    
2685     +#ifdef CONFIG_IP_VS_PROTO_TCP
2686     + if (u->tcp_timeout < 0 || u->tcp_timeout > (INT_MAX / HZ) ||
2687     + u->tcp_fin_timeout < 0 || u->tcp_fin_timeout > (INT_MAX / HZ)) {
2688     + return -EINVAL;
2689     + }
2690     +#endif
2691     +
2692     +#ifdef CONFIG_IP_VS_PROTO_UDP
2693     + if (u->udp_timeout < 0 || u->udp_timeout > (INT_MAX / HZ))
2694     + return -EINVAL;
2695     +#endif
2696     +
2697     #ifdef CONFIG_IP_VS_PROTO_TCP
2698     if (u->tcp_timeout) {
2699     pd = ip_vs_proto_data_get(ipvs, IPPROTO_TCP);
2700     diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
2701     index 19b3f4fbea52..df1d5618b008 100644
2702     --- a/net/netfilter/nf_conntrack_core.c
2703     +++ b/net/netfilter/nf_conntrack_core.c
2704     @@ -855,6 +855,22 @@ nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
2705     }
2706    
2707     if (nf_ct_key_equal(h, tuple, zone, net)) {
2708     + /* Tuple is taken already, so caller will need to find
2709     + * a new source port to use.
2710     + *
2711     + * Only exception:
2712     + * If the *original tuples* are identical, then both
2713     + * conntracks refer to the same flow.
2714     + * This is a rare situation, it can occur e.g. when
2715     + * more than one UDP packet is sent from same socket
2716     + * in different threads.
2717     + *
2718     + * Let nf_ct_resolve_clash() deal with this later.
2719     + */
2720     + if (nf_ct_tuple_equal(&ignored_conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
2721     + &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple))
2722     + continue;
2723     +
2724     NF_CT_STAT_INC_ATOMIC(net, found);
2725     rcu_read_unlock();
2726     return 1;
2727     diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c
2728     index 28c56b95fb7f..cb9d1d1210cb 100644
2729     --- a/net/netlabel/netlabel_kapi.c
2730     +++ b/net/netlabel/netlabel_kapi.c
2731     @@ -903,7 +903,8 @@ int netlbl_bitmap_walk(const unsigned char *bitmap, u32 bitmap_len,
2732     (state == 0 && (byte & bitmask) == 0))
2733     return bit_spot;
2734    
2735     - bit_spot++;
2736     + if (++bit_spot >= bitmap_len)
2737     + return -1;
2738     bitmask >>= 1;
2739     if (bitmask == 0) {
2740     byte = bitmap[++byte_offset];
2741     diff --git a/net/nfc/llcp_commands.c b/net/nfc/llcp_commands.c
2742     index 04759a0c3273..6ba829f2df91 100644
2743     --- a/net/nfc/llcp_commands.c
2744     +++ b/net/nfc/llcp_commands.c
2745     @@ -419,6 +419,10 @@ int nfc_llcp_send_connect(struct nfc_llcp_sock *sock)
2746     sock->service_name,
2747     sock->service_name_len,
2748     &service_name_tlv_length);
2749     + if (!service_name_tlv) {
2750     + err = -ENOMEM;
2751     + goto error_tlv;
2752     + }
2753     size += service_name_tlv_length;
2754     }
2755    
2756     @@ -429,9 +433,17 @@ int nfc_llcp_send_connect(struct nfc_llcp_sock *sock)
2757    
2758     miux_tlv = nfc_llcp_build_tlv(LLCP_TLV_MIUX, (u8 *)&miux, 0,
2759     &miux_tlv_length);
2760     + if (!miux_tlv) {
2761     + err = -ENOMEM;
2762     + goto error_tlv;
2763     + }
2764     size += miux_tlv_length;
2765    
2766     rw_tlv = nfc_llcp_build_tlv(LLCP_TLV_RW, &rw, 0, &rw_tlv_length);
2767     + if (!rw_tlv) {
2768     + err = -ENOMEM;
2769     + goto error_tlv;
2770     + }
2771     size += rw_tlv_length;
2772    
2773     pr_debug("SKB size %d SN length %zu\n", size, sock->service_name_len);
2774     @@ -484,9 +496,17 @@ int nfc_llcp_send_cc(struct nfc_llcp_sock *sock)
2775    
2776     miux_tlv = nfc_llcp_build_tlv(LLCP_TLV_MIUX, (u8 *)&miux, 0,
2777     &miux_tlv_length);
2778     + if (!miux_tlv) {
2779     + err = -ENOMEM;
2780     + goto error_tlv;
2781     + }
2782     size += miux_tlv_length;
2783    
2784     rw_tlv = nfc_llcp_build_tlv(LLCP_TLV_RW, &rw, 0, &rw_tlv_length);
2785     + if (!rw_tlv) {
2786     + err = -ENOMEM;
2787     + goto error_tlv;
2788     + }
2789     size += rw_tlv_length;
2790    
2791     skb = llcp_allocate_pdu(sock, LLCP_PDU_CC, size);
2792     diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
2793     index e69786c6804c..a121d796fa51 100644
2794     --- a/net/nfc/llcp_core.c
2795     +++ b/net/nfc/llcp_core.c
2796     @@ -532,10 +532,10 @@ static u8 nfc_llcp_reserve_sdp_ssap(struct nfc_llcp_local *local)
2797    
2798     static int nfc_llcp_build_gb(struct nfc_llcp_local *local)
2799     {
2800     - u8 *gb_cur, *version_tlv, version, version_length;
2801     - u8 *lto_tlv, lto_length;
2802     - u8 *wks_tlv, wks_length;
2803     - u8 *miux_tlv, miux_length;
2804     + u8 *gb_cur, version, version_length;
2805     + u8 lto_length, wks_length, miux_length;
2806     + u8 *version_tlv = NULL, *lto_tlv = NULL,
2807     + *wks_tlv = NULL, *miux_tlv = NULL;
2808     __be16 wks = cpu_to_be16(local->local_wks);
2809     u8 gb_len = 0;
2810     int ret = 0;
2811     @@ -543,17 +543,33 @@ static int nfc_llcp_build_gb(struct nfc_llcp_local *local)
2812     version = LLCP_VERSION_11;
2813     version_tlv = nfc_llcp_build_tlv(LLCP_TLV_VERSION, &version,
2814     1, &version_length);
2815     + if (!version_tlv) {
2816     + ret = -ENOMEM;
2817     + goto out;
2818     + }
2819     gb_len += version_length;
2820    
2821     lto_tlv = nfc_llcp_build_tlv(LLCP_TLV_LTO, &local->lto, 1, &lto_length);
2822     + if (!lto_tlv) {
2823     + ret = -ENOMEM;
2824     + goto out;
2825     + }
2826     gb_len += lto_length;
2827    
2828     pr_debug("Local wks 0x%lx\n", local->local_wks);
2829     wks_tlv = nfc_llcp_build_tlv(LLCP_TLV_WKS, (u8 *)&wks, 2, &wks_length);
2830     + if (!wks_tlv) {
2831     + ret = -ENOMEM;
2832     + goto out;
2833     + }
2834     gb_len += wks_length;
2835    
2836     miux_tlv = nfc_llcp_build_tlv(LLCP_TLV_MIUX, (u8 *)&local->miux, 0,
2837     &miux_length);
2838     + if (!miux_tlv) {
2839     + ret = -ENOMEM;
2840     + goto out;
2841     + }
2842     gb_len += miux_length;
2843    
2844     gb_len += ARRAY_SIZE(llcp_magic);
2845     diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
2846     index 2e417c907a28..e9812e21dbc9 100644
2847     --- a/net/sched/sch_netem.c
2848     +++ b/net/sched/sch_netem.c
2849     @@ -441,6 +441,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
2850     int nb = 0;
2851     int count = 1;
2852     int rc = NET_XMIT_SUCCESS;
2853     + int rc_drop = NET_XMIT_DROP;
2854    
2855     /* Do not fool qdisc_drop_all() */
2856     skb->prev = NULL;
2857     @@ -480,6 +481,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
2858     q->duplicate = 0;
2859     rootq->enqueue(skb2, rootq, to_free);
2860     q->duplicate = dupsave;
2861     + rc_drop = NET_XMIT_SUCCESS;
2862     }
2863    
2864     /*
2865     @@ -492,7 +494,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
2866     if (skb_is_gso(skb)) {
2867     segs = netem_segment(skb, sch, to_free);
2868     if (!segs)
2869     - return NET_XMIT_DROP;
2870     + return rc_drop;
2871     } else {
2872     segs = skb;
2873     }
2874     @@ -515,8 +517,10 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
2875     1<<(prandom_u32() % 8);
2876     }
2877    
2878     - if (unlikely(sch->q.qlen >= sch->limit))
2879     - return qdisc_drop_all(skb, sch, to_free);
2880     + if (unlikely(sch->q.qlen >= sch->limit)) {
2881     + qdisc_drop_all(skb, sch, to_free);
2882     + return rc_drop;
2883     + }
2884    
2885     qdisc_qstats_backlog_inc(sch, skb);
2886    
2887     diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
2888     index 936d7eee62d0..f66a6010ae07 100644
2889     --- a/net/vmw_vsock/virtio_transport.c
2890     +++ b/net/vmw_vsock/virtio_transport.c
2891     @@ -71,6 +71,9 @@ static u32 virtio_transport_get_local_cid(void)
2892     {
2893     struct virtio_vsock *vsock = virtio_vsock_get();
2894    
2895     + if (!vsock)
2896     + return VMADDR_CID_ANY;
2897     +
2898     return vsock->guest_cid;
2899     }
2900    
2901     @@ -495,10 +498,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
2902    
2903     virtio_vsock_update_guest_cid(vsock);
2904    
2905     - ret = vsock_core_init(&virtio_transport.transport);
2906     - if (ret < 0)
2907     - goto out_vqs;
2908     -
2909     vsock->rx_buf_nr = 0;
2910     vsock->rx_buf_max_nr = 0;
2911     atomic_set(&vsock->queued_replies, 0);
2912     @@ -526,8 +525,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
2913     mutex_unlock(&the_virtio_vsock_mutex);
2914     return 0;
2915    
2916     -out_vqs:
2917     - vsock->vdev->config->del_vqs(vsock->vdev);
2918     out:
2919     kfree(vsock);
2920     mutex_unlock(&the_virtio_vsock_mutex);
2921     @@ -544,6 +541,9 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
2922     flush_work(&vsock->event_work);
2923     flush_work(&vsock->send_pkt_work);
2924    
2925     + /* Reset all connected sockets when the device disappear */
2926     + vsock_for_each_connected_socket(virtio_vsock_reset_sock);
2927     +
2928     vdev->config->reset(vdev);
2929    
2930     mutex_lock(&vsock->rx_lock);
2931     @@ -567,7 +567,6 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
2932    
2933     mutex_lock(&the_virtio_vsock_mutex);
2934     the_virtio_vsock = NULL;
2935     - vsock_core_exit();
2936     mutex_unlock(&the_virtio_vsock_mutex);
2937    
2938     vdev->config->del_vqs(vdev);
2939     @@ -600,14 +599,28 @@ static int __init virtio_vsock_init(void)
2940     virtio_vsock_workqueue = alloc_workqueue("virtio_vsock", 0, 0);
2941     if (!virtio_vsock_workqueue)
2942     return -ENOMEM;
2943     +
2944     ret = register_virtio_driver(&virtio_vsock_driver);
2945     if (ret)
2946     - destroy_workqueue(virtio_vsock_workqueue);
2947     + goto out_wq;
2948     +
2949     + ret = vsock_core_init(&virtio_transport.transport);
2950     + if (ret)
2951     + goto out_vdr;
2952     +
2953     + return 0;
2954     +
2955     +out_vdr:
2956     + unregister_virtio_driver(&virtio_vsock_driver);
2957     +out_wq:
2958     + destroy_workqueue(virtio_vsock_workqueue);
2959     return ret;
2960     +
2961     }
2962    
2963     static void __exit virtio_vsock_exit(void)
2964     {
2965     + vsock_core_exit();
2966     unregister_virtio_driver(&virtio_vsock_driver);
2967     destroy_workqueue(virtio_vsock_workqueue);
2968     }
2969     diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
2970     index 2c0b52264a46..a625cb1500f9 100644
2971     --- a/tools/perf/util/cpumap.c
2972     +++ b/tools/perf/util/cpumap.c
2973     @@ -129,7 +129,12 @@ struct cpu_map *cpu_map__new(const char *cpu_list)
2974     if (!cpu_list)
2975     return cpu_map__read_all_cpu_map();
2976    
2977     - if (!isdigit(*cpu_list))
2978     + /*
2979     + * must handle the case of empty cpumap to cover
2980     + * TOPOLOGY header for NUMA nodes with no CPU
2981     + * ( e.g., because of CPU hotplug)
2982     + */
2983     + if (!isdigit(*cpu_list) && *cpu_list != '\0')
2984     goto out;
2985    
2986     while (isdigit(*cpu_list)) {
2987     @@ -176,8 +181,10 @@ struct cpu_map *cpu_map__new(const char *cpu_list)
2988    
2989     if (nr_cpus > 0)
2990     cpus = cpu_map__trim_new(nr_cpus, tmp_cpus);
2991     - else
2992     + else if (*cpu_list != '\0')
2993     cpus = cpu_map__default_new();
2994     + else
2995     + cpus = cpu_map__dummy_new();
2996     invalid:
2997     free(tmp_cpus);
2998     out:
2999     diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
3000     index adbc6c02c3aa..20ba5a9aeae4 100644
3001     --- a/tools/perf/util/symbol-elf.c
3002     +++ b/tools/perf/util/symbol-elf.c
3003     @@ -85,6 +85,11 @@ static inline uint8_t elf_sym__type(const GElf_Sym *sym)
3004     return GELF_ST_TYPE(sym->st_info);
3005     }
3006    
3007     +static inline uint8_t elf_sym__visibility(const GElf_Sym *sym)
3008     +{
3009     + return GELF_ST_VISIBILITY(sym->st_other);
3010     +}
3011     +
3012     #ifndef STT_GNU_IFUNC
3013     #define STT_GNU_IFUNC 10
3014     #endif
3015     @@ -109,7 +114,9 @@ static inline int elf_sym__is_label(const GElf_Sym *sym)
3016     return elf_sym__type(sym) == STT_NOTYPE &&
3017     sym->st_name != 0 &&
3018     sym->st_shndx != SHN_UNDEF &&
3019     - sym->st_shndx != SHN_ABS;
3020     + sym->st_shndx != SHN_ABS &&
3021     + elf_sym__visibility(sym) != STV_HIDDEN &&
3022     + elf_sym__visibility(sym) != STV_INTERNAL;
3023     }
3024    
3025     static bool elf_sym__is_a(GElf_Sym *sym, enum map_type type)
3026     diff --git a/tools/testing/selftests/netfilter/Makefile b/tools/testing/selftests/netfilter/Makefile
3027     index 47ed6cef93fb..c9ff2b47bd1c 100644
3028     --- a/tools/testing/selftests/netfilter/Makefile
3029     +++ b/tools/testing/selftests/netfilter/Makefile
3030     @@ -1,6 +1,6 @@
3031     # SPDX-License-Identifier: GPL-2.0
3032     # Makefile for netfilter selftests
3033    
3034     -TEST_PROGS := nft_trans_stress.sh
3035     +TEST_PROGS := nft_trans_stress.sh nft_nat.sh
3036    
3037     include ../lib.mk
3038     diff --git a/tools/testing/selftests/netfilter/config b/tools/testing/selftests/netfilter/config
3039     index 1017313e41a8..59caa8f71cd8 100644
3040     --- a/tools/testing/selftests/netfilter/config
3041     +++ b/tools/testing/selftests/netfilter/config
3042     @@ -1,2 +1,2 @@
3043     CONFIG_NET_NS=y
3044     -NF_TABLES_INET=y
3045     +CONFIG_NF_TABLES_INET=y
3046     diff --git a/tools/testing/selftests/netfilter/nft_nat.sh b/tools/testing/selftests/netfilter/nft_nat.sh
3047     new file mode 100755
3048     index 000000000000..8ec76681605c
3049     --- /dev/null
3050     +++ b/tools/testing/selftests/netfilter/nft_nat.sh
3051     @@ -0,0 +1,762 @@
3052     +#!/bin/bash
3053     +#
3054     +# This test is for basic NAT functionality: snat, dnat, redirect, masquerade.
3055     +#
3056     +
3057     +# Kselftest framework requirement - SKIP code is 4.
3058     +ksft_skip=4
3059     +ret=0
3060     +
3061     +nft --version > /dev/null 2>&1
3062     +if [ $? -ne 0 ];then
3063     + echo "SKIP: Could not run test without nft tool"
3064     + exit $ksft_skip
3065     +fi
3066     +
3067     +ip -Version > /dev/null 2>&1
3068     +if [ $? -ne 0 ];then
3069     + echo "SKIP: Could not run test without ip tool"
3070     + exit $ksft_skip
3071     +fi
3072     +
3073     +ip netns add ns0
3074     +ip netns add ns1
3075     +ip netns add ns2
3076     +
3077     +ip link add veth0 netns ns0 type veth peer name eth0 netns ns1
3078     +ip link add veth1 netns ns0 type veth peer name eth0 netns ns2
3079     +
3080     +ip -net ns0 link set lo up
3081     +ip -net ns0 link set veth0 up
3082     +ip -net ns0 addr add 10.0.1.1/24 dev veth0
3083     +ip -net ns0 addr add dead:1::1/64 dev veth0
3084     +
3085     +ip -net ns0 link set veth1 up
3086     +ip -net ns0 addr add 10.0.2.1/24 dev veth1
3087     +ip -net ns0 addr add dead:2::1/64 dev veth1
3088     +
3089     +for i in 1 2; do
3090     + ip -net ns$i link set lo up
3091     + ip -net ns$i link set eth0 up
3092     + ip -net ns$i addr add 10.0.$i.99/24 dev eth0
3093     + ip -net ns$i route add default via 10.0.$i.1
3094     + ip -net ns$i addr add dead:$i::99/64 dev eth0
3095     + ip -net ns$i route add default via dead:$i::1
3096     +done
3097     +
3098     +bad_counter()
3099     +{
3100     + local ns=$1
3101     + local counter=$2
3102     + local expect=$3
3103     +
3104     + echo "ERROR: $counter counter in $ns has unexpected value (expected $expect)" 1>&2
3105     + ip netns exec $ns nft list counter inet filter $counter 1>&2
3106     +}
3107     +
3108     +check_counters()
3109     +{
3110     + ns=$1
3111     + local lret=0
3112     +
3113     + cnt=$(ip netns exec $ns nft list counter inet filter ns0in | grep -q "packets 1 bytes 84")
3114     + if [ $? -ne 0 ]; then
3115     + bad_counter $ns ns0in "packets 1 bytes 84"
3116     + lret=1
3117     + fi
3118     + cnt=$(ip netns exec $ns nft list counter inet filter ns0out | grep -q "packets 1 bytes 84")
3119     + if [ $? -ne 0 ]; then
3120     + bad_counter $ns ns0out "packets 1 bytes 84"
3121     + lret=1
3122     + fi
3123     +
3124     + expect="packets 1 bytes 104"
3125     + cnt=$(ip netns exec $ns nft list counter inet filter ns0in6 | grep -q "$expect")
3126     + if [ $? -ne 0 ]; then
3127     + bad_counter $ns ns0in6 "$expect"
3128     + lret=1
3129     + fi
3130     + cnt=$(ip netns exec $ns nft list counter inet filter ns0out6 | grep -q "$expect")
3131     + if [ $? -ne 0 ]; then
3132     + bad_counter $ns ns0out6 "$expect"
3133     + lret=1
3134     + fi
3135     +
3136     + return $lret
3137     +}
3138     +
3139     +check_ns0_counters()
3140     +{
3141     + local ns=$1
3142     + local lret=0
3143     +
3144     + cnt=$(ip netns exec ns0 nft list counter inet filter ns0in | grep -q "packets 0 bytes 0")
3145     + if [ $? -ne 0 ]; then
3146     + bad_counter ns0 ns0in "packets 0 bytes 0"
3147     + lret=1
3148     + fi
3149     +
3150     + cnt=$(ip netns exec ns0 nft list counter inet filter ns0in6 | grep -q "packets 0 bytes 0")
3151     + if [ $? -ne 0 ]; then
3152     + bad_counter ns0 ns0in6 "packets 0 bytes 0"
3153     + lret=1
3154     + fi
3155     +
3156     + cnt=$(ip netns exec ns0 nft list counter inet filter ns0out | grep -q "packets 0 bytes 0")
3157     + if [ $? -ne 0 ]; then
3158     + bad_counter ns0 ns0out "packets 0 bytes 0"
3159     + lret=1
3160     + fi
3161     + cnt=$(ip netns exec ns0 nft list counter inet filter ns0out6 | grep -q "packets 0 bytes 0")
3162     + if [ $? -ne 0 ]; then
3163     + bad_counter ns0 ns0out6 "packets 0 bytes 0"
3164     + lret=1
3165     + fi
3166     +
3167     + for dir in "in" "out" ; do
3168     + expect="packets 1 bytes 84"
3169     + cnt=$(ip netns exec ns0 nft list counter inet filter ${ns}${dir} | grep -q "$expect")
3170     + if [ $? -ne 0 ]; then
3171     + bad_counter ns0 $ns$dir "$expect"
3172     + lret=1
3173     + fi
3174     +
3175     + expect="packets 1 bytes 104"
3176     + cnt=$(ip netns exec ns0 nft list counter inet filter ${ns}${dir}6 | grep -q "$expect")
3177     + if [ $? -ne 0 ]; then
3178     + bad_counter ns0 $ns$dir6 "$expect"
3179     + lret=1
3180     + fi
3181     + done
3182     +
3183     + return $lret
3184     +}
3185     +
3186     +reset_counters()
3187     +{
3188     + for i in 0 1 2;do
3189     + ip netns exec ns$i nft reset counters inet > /dev/null
3190     + done
3191     +}
3192     +
3193     +test_local_dnat6()
3194     +{
3195     + local lret=0
3196     +ip netns exec ns0 nft -f - <<EOF
3197     +table ip6 nat {
3198     + chain output {
3199     + type nat hook output priority 0; policy accept;
3200     + ip6 daddr dead:1::99 dnat to dead:2::99
3201     + }
3202     +}
3203     +EOF
3204     + if [ $? -ne 0 ]; then
3205     + echo "SKIP: Could not add add ip6 dnat hook"
3206     + return $ksft_skip
3207     + fi
3208     +
3209     + # ping netns1, expect rewrite to netns2
3210     + ip netns exec ns0 ping -q -c 1 dead:1::99 > /dev/null
3211     + if [ $? -ne 0 ]; then
3212     + lret=1
3213     + echo "ERROR: ping6 failed"
3214     + return $lret
3215     + fi
3216     +
3217     + expect="packets 0 bytes 0"
3218     + for dir in "in6" "out6" ; do
3219     + cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect")
3220     + if [ $? -ne 0 ]; then
3221     + bad_counter ns0 ns1$dir "$expect"
3222     + lret=1
3223     + fi
3224     + done
3225     +
3226     + expect="packets 1 bytes 104"
3227     + for dir in "in6" "out6" ; do
3228     + cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
3229     + if [ $? -ne 0 ]; then
3230     + bad_counter ns0 ns2$dir "$expect"
3231     + lret=1
3232     + fi
3233     + done
3234     +
3235     + # expect 0 count in ns1
3236     + expect="packets 0 bytes 0"
3237     + for dir in "in6" "out6" ; do
3238     + cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
3239     + if [ $? -ne 0 ]; then
3240     + bad_counter ns1 ns0$dir "$expect"
3241     + lret=1
3242     + fi
3243     + done
3244     +
3245     + # expect 1 packet in ns2
3246     + expect="packets 1 bytes 104"
3247     + for dir in "in6" "out6" ; do
3248     + cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect")
3249     + if [ $? -ne 0 ]; then
3250     + bad_counter ns2 ns0$dir "$expect"
3251     + lret=1
3252     + fi
3253     + done
3254     +
3255     + test $lret -eq 0 && echo "PASS: ipv6 ping to ns1 was NATted to ns2"
3256     + ip netns exec ns0 nft flush chain ip6 nat output
3257     +
3258     + return $lret
3259     +}
3260     +
3261     +test_local_dnat()
3262     +{
3263     + local lret=0
3264     +ip netns exec ns0 nft -f - <<EOF
3265     +table ip nat {
3266     + chain output {
3267     + type nat hook output priority 0; policy accept;
3268     + ip daddr 10.0.1.99 dnat to 10.0.2.99
3269     + }
3270     +}
3271     +EOF
3272     + # ping netns1, expect rewrite to netns2
3273     + ip netns exec ns0 ping -q -c 1 10.0.1.99 > /dev/null
3274     + if [ $? -ne 0 ]; then
3275     + lret=1
3276     + echo "ERROR: ping failed"
3277     + return $lret
3278     + fi
3279     +
3280     + expect="packets 0 bytes 0"
3281     + for dir in "in" "out" ; do
3282     + cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect")
3283     + if [ $? -ne 0 ]; then
3284     + bad_counter ns0 ns1$dir "$expect"
3285     + lret=1
3286     + fi
3287     + done
3288     +
3289     + expect="packets 1 bytes 84"
3290     + for dir in "in" "out" ; do
3291     + cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
3292     + if [ $? -ne 0 ]; then
3293     + bad_counter ns0 ns2$dir "$expect"
3294     + lret=1
3295     + fi
3296     + done
3297     +
3298     + # expect 0 count in ns1
3299     + expect="packets 0 bytes 0"
3300     + for dir in "in" "out" ; do
3301     + cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
3302     + if [ $? -ne 0 ]; then
3303     + bad_counter ns1 ns0$dir "$expect"
3304     + lret=1
3305     + fi
3306     + done
3307     +
3308     + # expect 1 packet in ns2
3309     + expect="packets 1 bytes 84"
3310     + for dir in "in" "out" ; do
3311     + cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect")
3312     + if [ $? -ne 0 ]; then
3313     + bad_counter ns2 ns0$dir "$expect"
3314     + lret=1
3315     + fi
3316     + done
3317     +
3318     + test $lret -eq 0 && echo "PASS: ping to ns1 was NATted to ns2"
3319     +
3320     + ip netns exec ns0 nft flush chain ip nat output
3321     +
3322     + reset_counters
3323     + ip netns exec ns0 ping -q -c 1 10.0.1.99 > /dev/null
3324     + if [ $? -ne 0 ]; then
3325     + lret=1
3326     + echo "ERROR: ping failed"
3327     + return $lret
3328     + fi
3329     +
3330     + expect="packets 1 bytes 84"
3331     + for dir in "in" "out" ; do
3332     + cnt=$(ip netns exec ns0 nft list counter inet filter ns1${dir} | grep -q "$expect")
3333     + if [ $? -ne 0 ]; then
3334     + bad_counter ns1 ns1$dir "$expect"
3335     + lret=1
3336     + fi
3337     + done
3338     + expect="packets 0 bytes 0"
3339     + for dir in "in" "out" ; do
3340     + cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
3341     + if [ $? -ne 0 ]; then
3342     + bad_counter ns0 ns2$dir "$expect"
3343     + lret=1
3344     + fi
3345     + done
3346     +
3347     + # expect 1 count in ns1
3348     + expect="packets 1 bytes 84"
3349     + for dir in "in" "out" ; do
3350     + cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
3351     + if [ $? -ne 0 ]; then
3352     + bad_counter ns0 ns0$dir "$expect"
3353     + lret=1
3354     + fi
3355     + done
3356     +
3357     + # expect 0 packet in ns2
3358     + expect="packets 0 bytes 0"
3359     + for dir in "in" "out" ; do
3360     + cnt=$(ip netns exec ns2 nft list counter inet filter ns0${dir} | grep -q "$expect")
3361     + if [ $? -ne 0 ]; then
3362     + bad_counter ns2 ns2$dir "$expect"
3363     + lret=1
3364     + fi
3365     + done
3366     +
3367     + test $lret -eq 0 && echo "PASS: ping to ns1 OK after nat output chain flush"
3368     +
3369     + return $lret
3370     +}
3371     +
3372     +
3373     +test_masquerade6()
3374     +{
3375     + local lret=0
3376     +
3377     + ip netns exec ns0 sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
3378     +
3379     + ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
3380     + if [ $? -ne 0 ] ; then
3381     + echo "ERROR: cannot ping ns1 from ns2 via ipv6"
3382     + return 1
3383     + lret=1
3384     + fi
3385     +
3386     + expect="packets 1 bytes 104"
3387     + for dir in "in6" "out6" ; do
3388     + cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
3389     + if [ $? -ne 0 ]; then
3390     + bad_counter ns1 ns2$dir "$expect"
3391     + lret=1
3392     + fi
3393     +
3394     + cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
3395     + if [ $? -ne 0 ]; then
3396     + bad_counter ns2 ns1$dir "$expect"
3397     + lret=1
3398     + fi
3399     + done
3400     +
3401     + reset_counters
3402     +
3403     +# add masquerading rule
3404     +ip netns exec ns0 nft -f - <<EOF
3405     +table ip6 nat {
3406     + chain postrouting {
3407     + type nat hook postrouting priority 0; policy accept;
3408     + meta oif veth0 masquerade
3409     + }
3410     +}
3411     +EOF
3412     + ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
3413     + if [ $? -ne 0 ] ; then
3414     + echo "ERROR: cannot ping ns1 from ns2 with active ipv6 masquerading"
3415     + lret=1
3416     + fi
3417     +
3418     + # ns1 should have seen packets from ns0, due to masquerade
3419     + expect="packets 1 bytes 104"
3420     + for dir in "in6" "out6" ; do
3421     +
3422     + cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
3423     + if [ $? -ne 0 ]; then
3424     + bad_counter ns1 ns0$dir "$expect"
3425     + lret=1
3426     + fi
3427     +
3428     + cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
3429     + if [ $? -ne 0 ]; then
3430     + bad_counter ns2 ns1$dir "$expect"
3431     + lret=1
3432     + fi
3433     + done
3434     +
3435     + # ns1 should not have seen packets from ns2, due to masquerade
3436     + expect="packets 0 bytes 0"
3437     + for dir in "in6" "out6" ; do
3438     + cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
3439     + if [ $? -ne 0 ]; then
3440     + bad_counter ns1 ns0$dir "$expect"
3441     + lret=1
3442     + fi
3443     +
3444     + cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
3445     + if [ $? -ne 0 ]; then
3446     + bad_counter ns2 ns1$dir "$expect"
3447     + lret=1
3448     + fi
3449     + done
3450     +
3451     + ip netns exec ns0 nft flush chain ip6 nat postrouting
3452     + if [ $? -ne 0 ]; then
3453     + echo "ERROR: Could not flush ip6 nat postrouting" 1>&2
3454     + lret=1
3455     + fi
3456     +
3457     + test $lret -eq 0 && echo "PASS: IPv6 masquerade for ns2"
3458     +
3459     + return $lret
3460     +}
3461     +
3462     +test_masquerade()
3463     +{
3464     + local lret=0
3465     +
3466     + ip netns exec ns0 sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
3467     + ip netns exec ns0 sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
3468     +
3469     + ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
3470     + if [ $? -ne 0 ] ; then
3471     + echo "ERROR: canot ping ns1 from ns2"
3472     + lret=1
3473     + fi
3474     +
3475     + expect="packets 1 bytes 84"
3476     + for dir in "in" "out" ; do
3477     + cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
3478     + if [ $? -ne 0 ]; then
3479     + bad_counter ns1 ns2$dir "$expect"
3480     + lret=1
3481     + fi
3482     +
3483     + cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
3484     + if [ $? -ne 0 ]; then
3485     + bad_counter ns2 ns1$dir "$expect"
3486     + lret=1
3487     + fi
3488     + done
3489     +
3490     + reset_counters
3491     +
3492     +# add masquerading rule
3493     +ip netns exec ns0 nft -f - <<EOF
3494     +table ip nat {
3495     + chain postrouting {
3496     + type nat hook postrouting priority 0; policy accept;
3497     + meta oif veth0 masquerade
3498     + }
3499     +}
3500     +EOF
3501     + ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
3502     + if [ $? -ne 0 ] ; then
3503     + echo "ERROR: cannot ping ns1 from ns2 with active ip masquerading"
3504     + lret=1
3505     + fi
3506     +
3507     + # ns1 should have seen packets from ns0, due to masquerade
3508     + expect="packets 1 bytes 84"
3509     + for dir in "in" "out" ; do
3510     + cnt=$(ip netns exec ns1 nft list counter inet filter ns0${dir} | grep -q "$expect")
3511     + if [ $? -ne 0 ]; then
3512     + bad_counter ns1 ns0$dir "$expect"
3513     + lret=1
3514     + fi
3515     +
3516     + cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
3517     + if [ $? -ne 0 ]; then
3518     + bad_counter ns2 ns1$dir "$expect"
3519     + lret=1
3520     + fi
3521     + done
3522     +
3523     + # ns1 should not have seen packets from ns2, due to masquerade
3524     + expect="packets 0 bytes 0"
3525     + for dir in "in" "out" ; do
3526     + cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
3527     + if [ $? -ne 0 ]; then
3528     + bad_counter ns1 ns0$dir "$expect"
3529     + lret=1
3530     + fi
3531     +
3532     + cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
3533     + if [ $? -ne 0 ]; then
3534     + bad_counter ns2 ns1$dir "$expect"
3535     + lret=1
3536     + fi
3537     + done
3538     +
3539     + ip netns exec ns0 nft flush chain ip nat postrouting
3540     + if [ $? -ne 0 ]; then
3541     + echo "ERROR: Could not flush nat postrouting" 1>&2
3542     + lret=1
3543     + fi
3544     +
3545     + test $lret -eq 0 && echo "PASS: IP masquerade for ns2"
3546     +
3547     + return $lret
3548     +}
3549     +
3550     +test_redirect6()
3551     +{
3552     + local lret=0
3553     +
3554     + ip netns exec ns0 sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
3555     +
3556     + ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
3557     + if [ $? -ne 0 ] ; then
3558     + echo "ERROR: cannnot ping ns1 from ns2 via ipv6"
3559     + lret=1
3560     + fi
3561     +
3562     + expect="packets 1 bytes 104"
3563     + for dir in "in6" "out6" ; do
3564     + cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
3565     + if [ $? -ne 0 ]; then
3566     + bad_counter ns1 ns2$dir "$expect"
3567     + lret=1
3568     + fi
3569     +
3570     + cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
3571     + if [ $? -ne 0 ]; then
3572     + bad_counter ns2 ns1$dir "$expect"
3573     + lret=1
3574     + fi
3575     + done
3576     +
3577     + reset_counters
3578     +
3579     +# add redirect rule
3580     +ip netns exec ns0 nft -f - <<EOF
3581     +table ip6 nat {
3582     + chain prerouting {
3583     + type nat hook prerouting priority 0; policy accept;
3584     + meta iif veth1 meta l4proto icmpv6 ip6 saddr dead:2::99 ip6 daddr dead:1::99 redirect
3585     + }
3586     +}
3587     +EOF
3588     + ip netns exec ns2 ping -q -c 1 dead:1::99 > /dev/null # ping ns2->ns1
3589     + if [ $? -ne 0 ] ; then
3590     + echo "ERROR: cannot ping ns1 from ns2 with active ip6 redirect"
3591     + lret=1
3592     + fi
3593     +
3594     + # ns1 should have seen no packets from ns2, due to redirection
3595     + expect="packets 0 bytes 0"
3596     + for dir in "in6" "out6" ; do
3597     + cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
3598     + if [ $? -ne 0 ]; then
3599     + bad_counter ns1 ns0$dir "$expect"
3600     + lret=1
3601     + fi
3602     + done
3603     +
3604     + # ns0 should have seen packets from ns2, due to masquerade
3605     + expect="packets 1 bytes 104"
3606     + for dir in "in6" "out6" ; do
3607     + cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
3608     + if [ $? -ne 0 ]; then
3609     + bad_counter ns1 ns0$dir "$expect"
3610     + lret=1
3611     + fi
3612     + done
3613     +
3614     + ip netns exec ns0 nft delete table ip6 nat
3615     + if [ $? -ne 0 ]; then
3616     + echo "ERROR: Could not delete ip6 nat table" 1>&2
3617     + lret=1
3618     + fi
3619     +
3620     + test $lret -eq 0 && echo "PASS: IPv6 redirection for ns2"
3621     +
3622     + return $lret
3623     +}
3624     +
3625     +test_redirect()
3626     +{
3627     + local lret=0
3628     +
3629     + ip netns exec ns0 sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
3630     + ip netns exec ns0 sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
3631     +
3632     + ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
3633     + if [ $? -ne 0 ] ; then
3634     + echo "ERROR: cannot ping ns1 from ns2"
3635     + lret=1
3636     + fi
3637     +
3638     + expect="packets 1 bytes 84"
3639     + for dir in "in" "out" ; do
3640     + cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
3641     + if [ $? -ne 0 ]; then
3642     + bad_counter ns1 ns2$dir "$expect"
3643     + lret=1
3644     + fi
3645     +
3646     + cnt=$(ip netns exec ns2 nft list counter inet filter ns1${dir} | grep -q "$expect")
3647     + if [ $? -ne 0 ]; then
3648     + bad_counter ns2 ns1$dir "$expect"
3649     + lret=1
3650     + fi
3651     + done
3652     +
3653     + reset_counters
3654     +
3655     +# add redirect rule
3656     +ip netns exec ns0 nft -f - <<EOF
3657     +table ip nat {
3658     + chain prerouting {
3659     + type nat hook prerouting priority 0; policy accept;
3660     + meta iif veth1 ip protocol icmp ip saddr 10.0.2.99 ip daddr 10.0.1.99 redirect
3661     + }
3662     +}
3663     +EOF
3664     + ip netns exec ns2 ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
3665     + if [ $? -ne 0 ] ; then
3666     + echo "ERROR: cannot ping ns1 from ns2 with active ip redirect"
3667     + lret=1
3668     + fi
3669     +
3670     + # ns1 should have seen no packets from ns2, due to redirection
3671     + expect="packets 0 bytes 0"
3672     + for dir in "in" "out" ; do
3673     +
3674     + cnt=$(ip netns exec ns1 nft list counter inet filter ns2${dir} | grep -q "$expect")
3675     + if [ $? -ne 0 ]; then
3676     + bad_counter ns1 ns0$dir "$expect"
3677     + lret=1
3678     + fi
3679     + done
3680     +
3681     + # ns0 should have seen packets from ns2, due to masquerade
3682     + expect="packets 1 bytes 84"
3683     + for dir in "in" "out" ; do
3684     + cnt=$(ip netns exec ns0 nft list counter inet filter ns2${dir} | grep -q "$expect")
3685     + if [ $? -ne 0 ]; then
3686     + bad_counter ns1 ns0$dir "$expect"
3687     + lret=1
3688     + fi
3689     + done
3690     +
3691     + ip netns exec ns0 nft delete table ip nat
3692     + if [ $? -ne 0 ]; then
3693     + echo "ERROR: Could not delete nat table" 1>&2
3694     + lret=1
3695     + fi
3696     +
3697     + test $lret -eq 0 && echo "PASS: IP redirection for ns2"
3698     +
3699     + return $lret
3700     +}
3701     +
3702     +
3703     +# ip netns exec ns0 ping -c 1 -q 10.0.$i.99
3704     +for i in 0 1 2; do
3705     +ip netns exec ns$i nft -f - <<EOF
3706     +table inet filter {
3707     + counter ns0in {}
3708     + counter ns1in {}
3709     + counter ns2in {}
3710     +
3711     + counter ns0out {}
3712     + counter ns1out {}
3713     + counter ns2out {}
3714     +
3715     + counter ns0in6 {}
3716     + counter ns1in6 {}
3717     + counter ns2in6 {}
3718     +
3719     + counter ns0out6 {}
3720     + counter ns1out6 {}
3721     + counter ns2out6 {}
3722     +
3723     + map nsincounter {
3724     + type ipv4_addr : counter
3725     + elements = { 10.0.1.1 : "ns0in",
3726     + 10.0.2.1 : "ns0in",
3727     + 10.0.1.99 : "ns1in",
3728     + 10.0.2.99 : "ns2in" }
3729     + }
3730     +
3731     + map nsincounter6 {
3732     + type ipv6_addr : counter
3733     + elements = { dead:1::1 : "ns0in6",
3734     + dead:2::1 : "ns0in6",
3735     + dead:1::99 : "ns1in6",
3736     + dead:2::99 : "ns2in6" }
3737     + }
3738     +
3739     + map nsoutcounter {
3740     + type ipv4_addr : counter
3741     + elements = { 10.0.1.1 : "ns0out",
3742     + 10.0.2.1 : "ns0out",
3743     + 10.0.1.99: "ns1out",
3744     + 10.0.2.99: "ns2out" }
3745     + }
3746     +
3747     + map nsoutcounter6 {
3748     + type ipv6_addr : counter
3749     + elements = { dead:1::1 : "ns0out6",
3750     + dead:2::1 : "ns0out6",
3751     + dead:1::99 : "ns1out6",
3752     + dead:2::99 : "ns2out6" }
3753     + }
3754     +
3755     + chain input {
3756     + type filter hook input priority 0; policy accept;
3757     + counter name ip saddr map @nsincounter
3758     + icmpv6 type { "echo-request", "echo-reply" } counter name ip6 saddr map @nsincounter6
3759     + }
3760     + chain output {
3761     + type filter hook output priority 0; policy accept;
3762     + counter name ip daddr map @nsoutcounter
3763     + icmpv6 type { "echo-request", "echo-reply" } counter name ip6 daddr map @nsoutcounter6
3764     + }
3765     +}
3766     +EOF
3767     +done
3768     +
3769     +sleep 3
3770     +# test basic connectivity
3771     +for i in 1 2; do
3772     + ip netns exec ns0 ping -c 1 -q 10.0.$i.99 > /dev/null
3773     + if [ $? -ne 0 ];then
3774     + echo "ERROR: Could not reach other namespace(s)" 1>&2
3775     + ret=1
3776     + fi
3777     +
3778     + ip netns exec ns0 ping -c 1 -q dead:$i::99 > /dev/null
3779     + if [ $? -ne 0 ];then
3780     + echo "ERROR: Could not reach other namespace(s) via ipv6" 1>&2
3781     + ret=1
3782     + fi
3783     + check_counters ns$i
3784     + if [ $? -ne 0 ]; then
3785     + ret=1
3786     + fi
3787     +
3788     + check_ns0_counters ns$i
3789     + if [ $? -ne 0 ]; then
3790     + ret=1
3791     + fi
3792     + reset_counters
3793     +done
3794     +
3795     +if [ $ret -eq 0 ];then
3796     + echo "PASS: netns routing/connectivity: ns0 can reach ns1 and ns2"
3797     +fi
3798     +
3799     +reset_counters
3800     +test_local_dnat
3801     +test_local_dnat6
3802     +
3803     +reset_counters
3804     +test_masquerade
3805     +test_masquerade6
3806     +
3807     +reset_counters
3808     +test_redirect
3809     +test_redirect6
3810     +
3811     +for i in 0 1 2; do ip netns del ns$i;done
3812     +
3813     +exit $ret