Annotation of /trunk/kernel-alx/patches-4.9/0289-4.9.190-all-fixes.patch
Parent Directory | Revision Log
Revision 3564 -
(hide annotations)
(download)
Thu Aug 13 10:21:09 2020 UTC (4 years, 1 month ago) by niro
File size: 142749 byte(s)
Thu Aug 13 10:21:09 2020 UTC (4 years, 1 month ago) by niro
File size: 142749 byte(s)
linux-190
1 | niro | 3564 | diff --git a/Documentation/siphash.txt b/Documentation/siphash.txt |
2 | new file mode 100644 | ||
3 | index 000000000000..908d348ff777 | ||
4 | --- /dev/null | ||
5 | +++ b/Documentation/siphash.txt | ||
6 | @@ -0,0 +1,175 @@ | ||
7 | + SipHash - a short input PRF | ||
8 | +----------------------------------------------- | ||
9 | +Written by Jason A. Donenfeld <jason@zx2c4.com> | ||
10 | + | ||
11 | +SipHash is a cryptographically secure PRF -- a keyed hash function -- that | ||
12 | +performs very well for short inputs, hence the name. It was designed by | ||
13 | +cryptographers Daniel J. Bernstein and Jean-Philippe Aumasson. It is intended | ||
14 | +as a replacement for some uses of: `jhash`, `md5_transform`, `sha_transform`, | ||
15 | +and so forth. | ||
16 | + | ||
17 | +SipHash takes a secret key filled with randomly generated numbers and either | ||
18 | +an input buffer or several input integers. It spits out an integer that is | ||
19 | +indistinguishable from random. You may then use that integer as part of secure | ||
20 | +sequence numbers, secure cookies, or mask it off for use in a hash table. | ||
21 | + | ||
22 | +1. Generating a key | ||
23 | + | ||
24 | +Keys should always be generated from a cryptographically secure source of | ||
25 | +random numbers, either using get_random_bytes or get_random_once: | ||
26 | + | ||
27 | +siphash_key_t key; | ||
28 | +get_random_bytes(&key, sizeof(key)); | ||
29 | + | ||
30 | +If you're not deriving your key from here, you're doing it wrong. | ||
31 | + | ||
32 | +2. Using the functions | ||
33 | + | ||
34 | +There are two variants of the function, one that takes a list of integers, and | ||
35 | +one that takes a buffer: | ||
36 | + | ||
37 | +u64 siphash(const void *data, size_t len, const siphash_key_t *key); | ||
38 | + | ||
39 | +And: | ||
40 | + | ||
41 | +u64 siphash_1u64(u64, const siphash_key_t *key); | ||
42 | +u64 siphash_2u64(u64, u64, const siphash_key_t *key); | ||
43 | +u64 siphash_3u64(u64, u64, u64, const siphash_key_t *key); | ||
44 | +u64 siphash_4u64(u64, u64, u64, u64, const siphash_key_t *key); | ||
45 | +u64 siphash_1u32(u32, const siphash_key_t *key); | ||
46 | +u64 siphash_2u32(u32, u32, const siphash_key_t *key); | ||
47 | +u64 siphash_3u32(u32, u32, u32, const siphash_key_t *key); | ||
48 | +u64 siphash_4u32(u32, u32, u32, u32, const siphash_key_t *key); | ||
49 | + | ||
50 | +If you pass the generic siphash function something of a constant length, it | ||
51 | +will constant fold at compile-time and automatically choose one of the | ||
52 | +optimized functions. | ||
53 | + | ||
54 | +3. Hashtable key function usage: | ||
55 | + | ||
56 | +struct some_hashtable { | ||
57 | + DECLARE_HASHTABLE(hashtable, 8); | ||
58 | + siphash_key_t key; | ||
59 | +}; | ||
60 | + | ||
61 | +void init_hashtable(struct some_hashtable *table) | ||
62 | +{ | ||
63 | + get_random_bytes(&table->key, sizeof(table->key)); | ||
64 | +} | ||
65 | + | ||
66 | +static inline hlist_head *some_hashtable_bucket(struct some_hashtable *table, struct interesting_input *input) | ||
67 | +{ | ||
68 | + return &table->hashtable[siphash(input, sizeof(*input), &table->key) & (HASH_SIZE(table->hashtable) - 1)]; | ||
69 | +} | ||
70 | + | ||
71 | +You may then iterate like usual over the returned hash bucket. | ||
72 | + | ||
73 | +4. Security | ||
74 | + | ||
75 | +SipHash has a very high security margin, with its 128-bit key. So long as the | ||
76 | +key is kept secret, it is impossible for an attacker to guess the outputs of | ||
77 | +the function, even if being able to observe many outputs, since 2^128 outputs | ||
78 | +is significant. | ||
79 | + | ||
80 | +Linux implements the "2-4" variant of SipHash. | ||
81 | + | ||
82 | +5. Struct-passing Pitfalls | ||
83 | + | ||
84 | +Often times the XuY functions will not be large enough, and instead you'll | ||
85 | +want to pass a pre-filled struct to siphash. When doing this, it's important | ||
86 | +to always ensure the struct has no padding holes. The easiest way to do this | ||
87 | +is to simply arrange the members of the struct in descending order of size, | ||
88 | +and to use offsetendof() instead of sizeof() for getting the size. For | ||
89 | +performance reasons, if possible, it's probably a good thing to align the | ||
90 | +struct to the right boundary. Here's an example: | ||
91 | + | ||
92 | +const struct { | ||
93 | + struct in6_addr saddr; | ||
94 | + u32 counter; | ||
95 | + u16 dport; | ||
96 | +} __aligned(SIPHASH_ALIGNMENT) combined = { | ||
97 | + .saddr = *(struct in6_addr *)saddr, | ||
98 | + .counter = counter, | ||
99 | + .dport = dport | ||
100 | +}; | ||
101 | +u64 h = siphash(&combined, offsetofend(typeof(combined), dport), &secret); | ||
102 | + | ||
103 | +6. Resources | ||
104 | + | ||
105 | +Read the SipHash paper if you're interested in learning more: | ||
106 | +https://131002.net/siphash/siphash.pdf | ||
107 | + | ||
108 | + | ||
109 | +~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ | ||
110 | + | ||
111 | +HalfSipHash - SipHash's insecure younger cousin | ||
112 | +----------------------------------------------- | ||
113 | +Written by Jason A. Donenfeld <jason@zx2c4.com> | ||
114 | + | ||
115 | +On the off-chance that SipHash is not fast enough for your needs, you might be | ||
116 | +able to justify using HalfSipHash, a terrifying but potentially useful | ||
117 | +possibility. HalfSipHash cuts SipHash's rounds down from "2-4" to "1-3" and, | ||
118 | +even scarier, uses an easily brute-forcable 64-bit key (with a 32-bit output) | ||
119 | +instead of SipHash's 128-bit key. However, this may appeal to some | ||
120 | +high-performance `jhash` users. | ||
121 | + | ||
122 | +Danger! | ||
123 | + | ||
124 | +Do not ever use HalfSipHash except for as a hashtable key function, and only | ||
125 | +then when you can be absolutely certain that the outputs will never be | ||
126 | +transmitted out of the kernel. This is only remotely useful over `jhash` as a | ||
127 | +means of mitigating hashtable flooding denial of service attacks. | ||
128 | + | ||
129 | +1. Generating a key | ||
130 | + | ||
131 | +Keys should always be generated from a cryptographically secure source of | ||
132 | +random numbers, either using get_random_bytes or get_random_once: | ||
133 | + | ||
134 | +hsiphash_key_t key; | ||
135 | +get_random_bytes(&key, sizeof(key)); | ||
136 | + | ||
137 | +If you're not deriving your key from here, you're doing it wrong. | ||
138 | + | ||
139 | +2. Using the functions | ||
140 | + | ||
141 | +There are two variants of the function, one that takes a list of integers, and | ||
142 | +one that takes a buffer: | ||
143 | + | ||
144 | +u32 hsiphash(const void *data, size_t len, const hsiphash_key_t *key); | ||
145 | + | ||
146 | +And: | ||
147 | + | ||
148 | +u32 hsiphash_1u32(u32, const hsiphash_key_t *key); | ||
149 | +u32 hsiphash_2u32(u32, u32, const hsiphash_key_t *key); | ||
150 | +u32 hsiphash_3u32(u32, u32, u32, const hsiphash_key_t *key); | ||
151 | +u32 hsiphash_4u32(u32, u32, u32, u32, const hsiphash_key_t *key); | ||
152 | + | ||
153 | +If you pass the generic hsiphash function something of a constant length, it | ||
154 | +will constant fold at compile-time and automatically choose one of the | ||
155 | +optimized functions. | ||
156 | + | ||
157 | +3. Hashtable key function usage: | ||
158 | + | ||
159 | +struct some_hashtable { | ||
160 | + DECLARE_HASHTABLE(hashtable, 8); | ||
161 | + hsiphash_key_t key; | ||
162 | +}; | ||
163 | + | ||
164 | +void init_hashtable(struct some_hashtable *table) | ||
165 | +{ | ||
166 | + get_random_bytes(&table->key, sizeof(table->key)); | ||
167 | +} | ||
168 | + | ||
169 | +static inline hlist_head *some_hashtable_bucket(struct some_hashtable *table, struct interesting_input *input) | ||
170 | +{ | ||
171 | + return &table->hashtable[hsiphash(input, sizeof(*input), &table->key) & (HASH_SIZE(table->hashtable) - 1)]; | ||
172 | +} | ||
173 | + | ||
174 | +You may then iterate like usual over the returned hash bucket. | ||
175 | + | ||
176 | +4. Performance | ||
177 | + | ||
178 | +HalfSipHash is roughly 3 times slower than JenkinsHash. For many replacements, | ||
179 | +this will not be a problem, as the hashtable lookup isn't the bottleneck. And | ||
180 | +in general, this is probably a good sacrifice to make for the security and DoS | ||
181 | +resistance of HalfSipHash. | ||
182 | diff --git a/Documentation/sysctl/net.txt b/Documentation/sysctl/net.txt | ||
183 | index f0480f7ea740..4d5e3b0cab3f 100644 | ||
184 | --- a/Documentation/sysctl/net.txt | ||
185 | +++ b/Documentation/sysctl/net.txt | ||
186 | @@ -54,6 +54,14 @@ Values : | ||
187 | 1 - enable JIT hardening for unprivileged users only | ||
188 | 2 - enable JIT hardening for all users | ||
189 | |||
190 | +bpf_jit_limit | ||
191 | +------------- | ||
192 | + | ||
193 | +This enforces a global limit for memory allocations to the BPF JIT | ||
194 | +compiler in order to reject unprivileged JIT requests once it has | ||
195 | +been surpassed. bpf_jit_limit contains the value of the global limit | ||
196 | +in bytes. | ||
197 | + | ||
198 | dev_weight | ||
199 | -------------- | ||
200 | |||
201 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
202 | index 4f559f5b3a89..98ee40591a9b 100644 | ||
203 | --- a/MAINTAINERS | ||
204 | +++ b/MAINTAINERS | ||
205 | @@ -11068,6 +11068,13 @@ F: arch/arm/mach-s3c24xx/mach-bast.c | ||
206 | F: arch/arm/mach-s3c24xx/bast-ide.c | ||
207 | F: arch/arm/mach-s3c24xx/bast-irq.c | ||
208 | |||
209 | +SIPHASH PRF ROUTINES | ||
210 | +M: Jason A. Donenfeld <Jason@zx2c4.com> | ||
211 | +S: Maintained | ||
212 | +F: lib/siphash.c | ||
213 | +F: lib/test_siphash.c | ||
214 | +F: include/linux/siphash.h | ||
215 | + | ||
216 | TI DAVINCI MACHINE SUPPORT | ||
217 | M: Sekhar Nori <nsekhar@ti.com> | ||
218 | M: Kevin Hilman <khilman@kernel.org> | ||
219 | diff --git a/Makefile b/Makefile | ||
220 | index 4fdc9d984f80..4b6cf4641eba 100644 | ||
221 | --- a/Makefile | ||
222 | +++ b/Makefile | ||
223 | @@ -1,6 +1,6 @@ | ||
224 | VERSION = 4 | ||
225 | PATCHLEVEL = 9 | ||
226 | -SUBLEVEL = 189 | ||
227 | +SUBLEVEL = 190 | ||
228 | EXTRAVERSION = | ||
229 | NAME = Roaring Lionus | ||
230 | |||
231 | diff --git a/arch/arm/mach-davinci/sleep.S b/arch/arm/mach-davinci/sleep.S | ||
232 | index cd350dee4df3..efcd400b2abb 100644 | ||
233 | --- a/arch/arm/mach-davinci/sleep.S | ||
234 | +++ b/arch/arm/mach-davinci/sleep.S | ||
235 | @@ -37,6 +37,7 @@ | ||
236 | #define DEEPSLEEP_SLEEPENABLE_BIT BIT(31) | ||
237 | |||
238 | .text | ||
239 | + .arch armv5te | ||
240 | /* | ||
241 | * Move DaVinci into deep sleep state | ||
242 | * | ||
243 | diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c | ||
244 | index 93d0b6d0b63e..7fd448b23b94 100644 | ||
245 | --- a/arch/arm/net/bpf_jit_32.c | ||
246 | +++ b/arch/arm/net/bpf_jit_32.c | ||
247 | @@ -72,8 +72,6 @@ struct jit_ctx { | ||
248 | #endif | ||
249 | }; | ||
250 | |||
251 | -int bpf_jit_enable __read_mostly; | ||
252 | - | ||
253 | static inline int call_neg_helper(struct sk_buff *skb, int offset, void *ret, | ||
254 | unsigned int size) | ||
255 | { | ||
256 | diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h | ||
257 | index 65615820155e..65db124a44bf 100644 | ||
258 | --- a/arch/arm64/include/asm/efi.h | ||
259 | +++ b/arch/arm64/include/asm/efi.h | ||
260 | @@ -52,7 +52,11 @@ int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md); | ||
261 | #define efi_is_64bit() (true) | ||
262 | |||
263 | #define alloc_screen_info(x...) &screen_info | ||
264 | -#define free_screen_info(x...) | ||
265 | + | ||
266 | +static inline void free_screen_info(efi_system_table_t *sys_table_arg, | ||
267 | + struct screen_info *si) | ||
268 | +{ | ||
269 | +} | ||
270 | |||
271 | /* redeclare as 'hidden' so the compiler will generate relative references */ | ||
272 | extern struct screen_info screen_info __attribute__((__visibility__("hidden"))); | ||
273 | diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h | ||
274 | index 73e3718356b0..edb2c359480d 100644 | ||
275 | --- a/arch/arm64/include/asm/pgtable.h | ||
276 | +++ b/arch/arm64/include/asm/pgtable.h | ||
277 | @@ -387,8 +387,8 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, | ||
278 | PMD_TYPE_SECT) | ||
279 | |||
280 | #if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS < 3 | ||
281 | -#define pud_sect(pud) (0) | ||
282 | -#define pud_table(pud) (1) | ||
283 | +static inline bool pud_sect(pud_t pud) { return false; } | ||
284 | +static inline bool pud_table(pud_t pud) { return true; } | ||
285 | #else | ||
286 | #define pud_sect(pud) ((pud_val(pud) & PUD_TYPE_MASK) == \ | ||
287 | PUD_TYPE_SECT) | ||
288 | diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c | ||
289 | index 0b9e5f6290f9..d168e52ee622 100644 | ||
290 | --- a/arch/arm64/kernel/hw_breakpoint.c | ||
291 | +++ b/arch/arm64/kernel/hw_breakpoint.c | ||
292 | @@ -508,13 +508,14 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp) | ||
293 | /* Aligned */ | ||
294 | break; | ||
295 | case 1: | ||
296 | - /* Allow single byte watchpoint. */ | ||
297 | - if (info->ctrl.len == ARM_BREAKPOINT_LEN_1) | ||
298 | - break; | ||
299 | case 2: | ||
300 | /* Allow halfword watchpoints and breakpoints. */ | ||
301 | if (info->ctrl.len == ARM_BREAKPOINT_LEN_2) | ||
302 | break; | ||
303 | + case 3: | ||
304 | + /* Allow single byte watchpoint. */ | ||
305 | + if (info->ctrl.len == ARM_BREAKPOINT_LEN_1) | ||
306 | + break; | ||
307 | default: | ||
308 | return -EINVAL; | ||
309 | } | ||
310 | diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c | ||
311 | index b47a26f4290c..939c607b1376 100644 | ||
312 | --- a/arch/arm64/net/bpf_jit_comp.c | ||
313 | +++ b/arch/arm64/net/bpf_jit_comp.c | ||
314 | @@ -30,8 +30,6 @@ | ||
315 | |||
316 | #include "bpf_jit.h" | ||
317 | |||
318 | -int bpf_jit_enable __read_mostly; | ||
319 | - | ||
320 | #define TMP_REG_1 (MAX_BPF_JIT_REG + 0) | ||
321 | #define TMP_REG_2 (MAX_BPF_JIT_REG + 1) | ||
322 | #define TCALL_CNT (MAX_BPF_JIT_REG + 2) | ||
323 | diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c | ||
324 | index 248603739198..bb9f779326d0 100644 | ||
325 | --- a/arch/mips/net/bpf_jit.c | ||
326 | +++ b/arch/mips/net/bpf_jit.c | ||
327 | @@ -1194,8 +1194,6 @@ jmp_cmp: | ||
328 | return 0; | ||
329 | } | ||
330 | |||
331 | -int bpf_jit_enable __read_mostly; | ||
332 | - | ||
333 | void bpf_jit_compile(struct bpf_prog *fp) | ||
334 | { | ||
335 | struct jit_ctx ctx; | ||
336 | diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c | ||
337 | index 9c58194c7ea5..158f43008314 100644 | ||
338 | --- a/arch/powerpc/net/bpf_jit_comp.c | ||
339 | +++ b/arch/powerpc/net/bpf_jit_comp.c | ||
340 | @@ -18,8 +18,6 @@ | ||
341 | |||
342 | #include "bpf_jit32.h" | ||
343 | |||
344 | -int bpf_jit_enable __read_mostly; | ||
345 | - | ||
346 | static inline void bpf_flush_icache(void *start, void *end) | ||
347 | { | ||
348 | smp_wmb(); | ||
349 | diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c | ||
350 | index 9f0810cfe5f3..888ee95340da 100644 | ||
351 | --- a/arch/powerpc/net/bpf_jit_comp64.c | ||
352 | +++ b/arch/powerpc/net/bpf_jit_comp64.c | ||
353 | @@ -21,8 +21,6 @@ | ||
354 | |||
355 | #include "bpf_jit64.h" | ||
356 | |||
357 | -int bpf_jit_enable __read_mostly; | ||
358 | - | ||
359 | static void bpf_jit_fill_ill_insns(void *area, unsigned int size) | ||
360 | { | ||
361 | int *p = area; | ||
362 | diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c | ||
363 | index 8bd25aebf488..896344b6e036 100644 | ||
364 | --- a/arch/s390/net/bpf_jit_comp.c | ||
365 | +++ b/arch/s390/net/bpf_jit_comp.c | ||
366 | @@ -28,8 +28,6 @@ | ||
367 | #include <asm/nospec-branch.h> | ||
368 | #include "bpf_jit.h" | ||
369 | |||
370 | -int bpf_jit_enable __read_mostly; | ||
371 | - | ||
372 | struct bpf_jit { | ||
373 | u32 seen; /* Flags to remember seen eBPF instructions */ | ||
374 | u32 seen_reg[16]; /* Array to remember which registers are used */ | ||
375 | diff --git a/arch/sh/kernel/hw_breakpoint.c b/arch/sh/kernel/hw_breakpoint.c | ||
376 | index 2197fc584186..000cc3343867 100644 | ||
377 | --- a/arch/sh/kernel/hw_breakpoint.c | ||
378 | +++ b/arch/sh/kernel/hw_breakpoint.c | ||
379 | @@ -160,6 +160,7 @@ int arch_bp_generic_fields(int sh_len, int sh_type, | ||
380 | switch (sh_type) { | ||
381 | case SH_BREAKPOINT_READ: | ||
382 | *gen_type = HW_BREAKPOINT_R; | ||
383 | + break; | ||
384 | case SH_BREAKPOINT_WRITE: | ||
385 | *gen_type = HW_BREAKPOINT_W; | ||
386 | break; | ||
387 | diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c | ||
388 | index a6d9204a6a0b..98a4da3012e3 100644 | ||
389 | --- a/arch/sparc/net/bpf_jit_comp.c | ||
390 | +++ b/arch/sparc/net/bpf_jit_comp.c | ||
391 | @@ -10,8 +10,6 @@ | ||
392 | |||
393 | #include "bpf_jit.h" | ||
394 | |||
395 | -int bpf_jit_enable __read_mostly; | ||
396 | - | ||
397 | static inline bool is_simm13(unsigned int value) | ||
398 | { | ||
399 | return value + 0x1000 < 0x2000; | ||
400 | diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c | ||
401 | index c140198d9fa5..7f4b3c59df47 100644 | ||
402 | --- a/arch/x86/mm/fault.c | ||
403 | +++ b/arch/x86/mm/fault.c | ||
404 | @@ -273,13 +273,14 @@ static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address) | ||
405 | |||
406 | pmd = pmd_offset(pud, address); | ||
407 | pmd_k = pmd_offset(pud_k, address); | ||
408 | - if (!pmd_present(*pmd_k)) | ||
409 | - return NULL; | ||
410 | |||
411 | - if (!pmd_present(*pmd)) | ||
412 | + if (pmd_present(*pmd) != pmd_present(*pmd_k)) | ||
413 | set_pmd(pmd, *pmd_k); | ||
414 | + | ||
415 | + if (!pmd_present(*pmd_k)) | ||
416 | + return NULL; | ||
417 | else | ||
418 | - BUG_ON(pmd_page(*pmd) != pmd_page(*pmd_k)); | ||
419 | + BUG_ON(pmd_pfn(*pmd) != pmd_pfn(*pmd_k)); | ||
420 | |||
421 | return pmd_k; | ||
422 | } | ||
423 | @@ -299,17 +300,13 @@ void vmalloc_sync_all(void) | ||
424 | spin_lock(&pgd_lock); | ||
425 | list_for_each_entry(page, &pgd_list, lru) { | ||
426 | spinlock_t *pgt_lock; | ||
427 | - pmd_t *ret; | ||
428 | |||
429 | /* the pgt_lock only for Xen */ | ||
430 | pgt_lock = &pgd_page_get_mm(page)->page_table_lock; | ||
431 | |||
432 | spin_lock(pgt_lock); | ||
433 | - ret = vmalloc_sync_one(page_address(page), address); | ||
434 | + vmalloc_sync_one(page_address(page), address); | ||
435 | spin_unlock(pgt_lock); | ||
436 | - | ||
437 | - if (!ret) | ||
438 | - break; | ||
439 | } | ||
440 | spin_unlock(&pgd_lock); | ||
441 | } | ||
442 | diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c | ||
443 | index cd9764520851..d9dabd0c31fc 100644 | ||
444 | --- a/arch/x86/net/bpf_jit_comp.c | ||
445 | +++ b/arch/x86/net/bpf_jit_comp.c | ||
446 | @@ -15,8 +15,6 @@ | ||
447 | #include <asm/nospec-branch.h> | ||
448 | #include <linux/bpf.h> | ||
449 | |||
450 | -int bpf_jit_enable __read_mostly; | ||
451 | - | ||
452 | /* | ||
453 | * assembly code in arch/x86/net/bpf_jit.S | ||
454 | */ | ||
455 | diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c | ||
456 | index a45d32abea26..b9beae798d72 100644 | ||
457 | --- a/arch/xtensa/kernel/setup.c | ||
458 | +++ b/arch/xtensa/kernel/setup.c | ||
459 | @@ -626,6 +626,7 @@ void cpu_reset(void) | ||
460 | "add %2, %2, %7\n\t" | ||
461 | "addi %0, %0, -1\n\t" | ||
462 | "bnez %0, 1b\n\t" | ||
463 | + "isync\n\t" | ||
464 | /* Jump to identity mapping */ | ||
465 | "jx %3\n" | ||
466 | "2:\n\t" | ||
467 | diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c | ||
468 | index 6b81746cd13c..e5b1b3f1c231 100644 | ||
469 | --- a/drivers/acpi/arm64/iort.c | ||
470 | +++ b/drivers/acpi/arm64/iort.c | ||
471 | @@ -324,8 +324,8 @@ static int iort_dev_find_its_id(struct device *dev, u32 req_id, | ||
472 | |||
473 | /* Move to ITS specific data */ | ||
474 | its = (struct acpi_iort_its_group *)node->node_data; | ||
475 | - if (idx > its->its_count) { | ||
476 | - dev_err(dev, "requested ITS ID index [%d] is greater than available [%d]\n", | ||
477 | + if (idx >= its->its_count) { | ||
478 | + dev_err(dev, "requested ITS ID index [%d] overruns ITS entries [%d]\n", | ||
479 | idx, its->its_count); | ||
480 | return -ENXIO; | ||
481 | } | ||
482 | diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c | ||
483 | index cd2eab6aa92e..65371e1befe8 100644 | ||
484 | --- a/drivers/ata/libahci_platform.c | ||
485 | +++ b/drivers/ata/libahci_platform.c | ||
486 | @@ -300,6 +300,9 @@ static int ahci_platform_get_phy(struct ahci_host_priv *hpriv, u32 port, | ||
487 | hpriv->phys[port] = NULL; | ||
488 | rc = 0; | ||
489 | break; | ||
490 | + case -EPROBE_DEFER: | ||
491 | + /* Do not complain yet */ | ||
492 | + break; | ||
493 | |||
494 | default: | ||
495 | dev_err(dev, | ||
496 | diff --git a/drivers/ata/libata-zpodd.c b/drivers/ata/libata-zpodd.c | ||
497 | index 7017a81d53cf..083856272e92 100644 | ||
498 | --- a/drivers/ata/libata-zpodd.c | ||
499 | +++ b/drivers/ata/libata-zpodd.c | ||
500 | @@ -55,7 +55,7 @@ static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev) | ||
501 | unsigned int ret; | ||
502 | struct rm_feature_desc *desc; | ||
503 | struct ata_taskfile tf; | ||
504 | - static const char cdb[] = { GPCMD_GET_CONFIGURATION, | ||
505 | + static const char cdb[ATAPI_CDB_LEN] = { GPCMD_GET_CONFIGURATION, | ||
506 | 2, /* only 1 feature descriptor requested */ | ||
507 | 0, 3, /* 3, removable medium feature */ | ||
508 | 0, 0, 0,/* reserved */ | ||
509 | diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c | ||
510 | index 83957a1e15ed..8e8e4ccb128f 100644 | ||
511 | --- a/drivers/block/drbd/drbd_receiver.c | ||
512 | +++ b/drivers/block/drbd/drbd_receiver.c | ||
513 | @@ -5297,7 +5297,7 @@ static int drbd_do_auth(struct drbd_connection *connection) | ||
514 | unsigned int key_len; | ||
515 | char secret[SHARED_SECRET_MAX]; /* 64 byte */ | ||
516 | unsigned int resp_size; | ||
517 | - SHASH_DESC_ON_STACK(desc, connection->cram_hmac_tfm); | ||
518 | + struct shash_desc *desc; | ||
519 | struct packet_info pi; | ||
520 | struct net_conf *nc; | ||
521 | int err, rv; | ||
522 | @@ -5310,6 +5310,13 @@ static int drbd_do_auth(struct drbd_connection *connection) | ||
523 | memcpy(secret, nc->shared_secret, key_len); | ||
524 | rcu_read_unlock(); | ||
525 | |||
526 | + desc = kmalloc(sizeof(struct shash_desc) + | ||
527 | + crypto_shash_descsize(connection->cram_hmac_tfm), | ||
528 | + GFP_KERNEL); | ||
529 | + if (!desc) { | ||
530 | + rv = -1; | ||
531 | + goto fail; | ||
532 | + } | ||
533 | desc->tfm = connection->cram_hmac_tfm; | ||
534 | desc->flags = 0; | ||
535 | |||
536 | @@ -5452,7 +5459,10 @@ static int drbd_do_auth(struct drbd_connection *connection) | ||
537 | kfree(peers_ch); | ||
538 | kfree(response); | ||
539 | kfree(right_response); | ||
540 | - shash_desc_zero(desc); | ||
541 | + if (desc) { | ||
542 | + shash_desc_zero(desc); | ||
543 | + kfree(desc); | ||
544 | + } | ||
545 | |||
546 | return rv; | ||
547 | } | ||
548 | diff --git a/drivers/cpufreq/pasemi-cpufreq.c b/drivers/cpufreq/pasemi-cpufreq.c | ||
549 | index 58c933f48300..991b6a3062c4 100644 | ||
550 | --- a/drivers/cpufreq/pasemi-cpufreq.c | ||
551 | +++ b/drivers/cpufreq/pasemi-cpufreq.c | ||
552 | @@ -145,10 +145,18 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy) | ||
553 | int err = -ENODEV; | ||
554 | |||
555 | cpu = of_get_cpu_node(policy->cpu, NULL); | ||
556 | + if (!cpu) | ||
557 | + goto out; | ||
558 | |||
559 | + max_freqp = of_get_property(cpu, "clock-frequency", NULL); | ||
560 | of_node_put(cpu); | ||
561 | - if (!cpu) | ||
562 | + if (!max_freqp) { | ||
563 | + err = -EINVAL; | ||
564 | goto out; | ||
565 | + } | ||
566 | + | ||
567 | + /* we need the freq in kHz */ | ||
568 | + max_freq = *max_freqp / 1000; | ||
569 | |||
570 | dn = of_find_compatible_node(NULL, NULL, "1682m-sdc"); | ||
571 | if (!dn) | ||
572 | @@ -185,16 +193,6 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy) | ||
573 | } | ||
574 | |||
575 | pr_debug("init cpufreq on CPU %d\n", policy->cpu); | ||
576 | - | ||
577 | - max_freqp = of_get_property(cpu, "clock-frequency", NULL); | ||
578 | - if (!max_freqp) { | ||
579 | - err = -EINVAL; | ||
580 | - goto out_unmap_sdcpwr; | ||
581 | - } | ||
582 | - | ||
583 | - /* we need the freq in kHz */ | ||
584 | - max_freq = *max_freqp / 1000; | ||
585 | - | ||
586 | pr_debug("max clock-frequency is at %u kHz\n", max_freq); | ||
587 | pr_debug("initializing frequency table\n"); | ||
588 | |||
589 | @@ -212,9 +210,6 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy) | ||
590 | |||
591 | return cpufreq_generic_init(policy, pas_freqs, get_gizmo_latency()); | ||
592 | |||
593 | -out_unmap_sdcpwr: | ||
594 | - iounmap(sdcpwr_mapbase); | ||
595 | - | ||
596 | out_unmap_sdcasr: | ||
597 | iounmap(sdcasr_mapbase); | ||
598 | out: | ||
599 | diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig | ||
600 | index bca172d42c74..854df538ae01 100644 | ||
601 | --- a/drivers/firmware/Kconfig | ||
602 | +++ b/drivers/firmware/Kconfig | ||
603 | @@ -144,7 +144,7 @@ config DMI_SCAN_MACHINE_NON_EFI_FALLBACK | ||
604 | |||
605 | config ISCSI_IBFT_FIND | ||
606 | bool "iSCSI Boot Firmware Table Attributes" | ||
607 | - depends on X86 && ACPI | ||
608 | + depends on X86 && ISCSI_IBFT | ||
609 | default n | ||
610 | help | ||
611 | This option enables the kernel to find the region of memory | ||
612 | @@ -155,7 +155,8 @@ config ISCSI_IBFT_FIND | ||
613 | config ISCSI_IBFT | ||
614 | tristate "iSCSI Boot Firmware Table Attributes module" | ||
615 | select ISCSI_BOOT_SYSFS | ||
616 | - depends on ISCSI_IBFT_FIND && SCSI && SCSI_LOWLEVEL | ||
617 | + select ISCSI_IBFT_FIND if X86 | ||
618 | + depends on ACPI && SCSI && SCSI_LOWLEVEL | ||
619 | default n | ||
620 | help | ||
621 | This option enables support for detection and exposing of iSCSI | ||
622 | diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c | ||
623 | index 132b9bae4b6a..220bbc91cebd 100644 | ||
624 | --- a/drivers/firmware/iscsi_ibft.c | ||
625 | +++ b/drivers/firmware/iscsi_ibft.c | ||
626 | @@ -93,6 +93,10 @@ MODULE_DESCRIPTION("sysfs interface to BIOS iBFT information"); | ||
627 | MODULE_LICENSE("GPL"); | ||
628 | MODULE_VERSION(IBFT_ISCSI_VERSION); | ||
629 | |||
630 | +#ifndef CONFIG_ISCSI_IBFT_FIND | ||
631 | +struct acpi_table_ibft *ibft_addr; | ||
632 | +#endif | ||
633 | + | ||
634 | struct ibft_hdr { | ||
635 | u8 id; | ||
636 | u8 version; | ||
637 | diff --git a/drivers/hid/hid-holtek-kbd.c b/drivers/hid/hid-holtek-kbd.c | ||
638 | index 6e1a4a4fc0c1..ab9da597106f 100644 | ||
639 | --- a/drivers/hid/hid-holtek-kbd.c | ||
640 | +++ b/drivers/hid/hid-holtek-kbd.c | ||
641 | @@ -126,9 +126,14 @@ static int holtek_kbd_input_event(struct input_dev *dev, unsigned int type, | ||
642 | |||
643 | /* Locate the boot interface, to receive the LED change events */ | ||
644 | struct usb_interface *boot_interface = usb_ifnum_to_if(usb_dev, 0); | ||
645 | + struct hid_device *boot_hid; | ||
646 | + struct hid_input *boot_hid_input; | ||
647 | |||
648 | - struct hid_device *boot_hid = usb_get_intfdata(boot_interface); | ||
649 | - struct hid_input *boot_hid_input = list_first_entry(&boot_hid->inputs, | ||
650 | + if (unlikely(boot_interface == NULL)) | ||
651 | + return -ENODEV; | ||
652 | + | ||
653 | + boot_hid = usb_get_intfdata(boot_interface); | ||
654 | + boot_hid_input = list_first_entry(&boot_hid->inputs, | ||
655 | struct hid_input, list); | ||
656 | |||
657 | return boot_hid_input->input->event(boot_hid_input->input, type, code, | ||
658 | diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c | ||
659 | index 308d8432fea3..8903ea09ac58 100644 | ||
660 | --- a/drivers/hid/usbhid/hiddev.c | ||
661 | +++ b/drivers/hid/usbhid/hiddev.c | ||
662 | @@ -308,6 +308,14 @@ static int hiddev_open(struct inode *inode, struct file *file) | ||
663 | spin_unlock_irq(&list->hiddev->list_lock); | ||
664 | |||
665 | mutex_lock(&hiddev->existancelock); | ||
666 | + /* | ||
667 | + * recheck exist with existance lock held to | ||
668 | + * avoid opening a disconnected device | ||
669 | + */ | ||
670 | + if (!list->hiddev->exist) { | ||
671 | + res = -ENODEV; | ||
672 | + goto bail_unlock; | ||
673 | + } | ||
674 | if (!list->hiddev->open++) | ||
675 | if (list->hiddev->exist) { | ||
676 | struct hid_device *hid = hiddev->hid; | ||
677 | @@ -322,6 +330,10 @@ static int hiddev_open(struct inode *inode, struct file *file) | ||
678 | return 0; | ||
679 | bail_unlock: | ||
680 | mutex_unlock(&hiddev->existancelock); | ||
681 | + | ||
682 | + spin_lock_irq(&list->hiddev->list_lock); | ||
683 | + list_del(&list->node); | ||
684 | + spin_unlock_irq(&list->hiddev->list_lock); | ||
685 | bail: | ||
686 | file->private_data = NULL; | ||
687 | vfree(list); | ||
688 | diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c | ||
689 | index 2b31b84d0a5b..006f090c1b0a 100644 | ||
690 | --- a/drivers/hwmon/nct6775.c | ||
691 | +++ b/drivers/hwmon/nct6775.c | ||
692 | @@ -698,7 +698,7 @@ static const u16 NCT6106_REG_TARGET[] = { 0x111, 0x121, 0x131 }; | ||
693 | static const u16 NCT6106_REG_WEIGHT_TEMP_SEL[] = { 0x168, 0x178, 0x188 }; | ||
694 | static const u16 NCT6106_REG_WEIGHT_TEMP_STEP[] = { 0x169, 0x179, 0x189 }; | ||
695 | static const u16 NCT6106_REG_WEIGHT_TEMP_STEP_TOL[] = { 0x16a, 0x17a, 0x18a }; | ||
696 | -static const u16 NCT6106_REG_WEIGHT_DUTY_STEP[] = { 0x16b, 0x17b, 0x17c }; | ||
697 | +static const u16 NCT6106_REG_WEIGHT_DUTY_STEP[] = { 0x16b, 0x17b, 0x18b }; | ||
698 | static const u16 NCT6106_REG_WEIGHT_TEMP_BASE[] = { 0x16c, 0x17c, 0x18c }; | ||
699 | static const u16 NCT6106_REG_WEIGHT_DUTY_BASE[] = { 0x16d, 0x17d, 0x18d }; | ||
700 | |||
701 | @@ -3481,6 +3481,7 @@ static int nct6775_probe(struct platform_device *pdev) | ||
702 | data->REG_FAN_TIME[0] = NCT6106_REG_FAN_STOP_TIME; | ||
703 | data->REG_FAN_TIME[1] = NCT6106_REG_FAN_STEP_UP_TIME; | ||
704 | data->REG_FAN_TIME[2] = NCT6106_REG_FAN_STEP_DOWN_TIME; | ||
705 | + data->REG_TOLERANCE_H = NCT6106_REG_TOLERANCE_H; | ||
706 | data->REG_PWM[0] = NCT6106_REG_PWM; | ||
707 | data->REG_PWM[1] = NCT6106_REG_FAN_START_OUTPUT; | ||
708 | data->REG_PWM[2] = NCT6106_REG_FAN_STOP_OUTPUT; | ||
709 | diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c | ||
710 | index 12b94b094c0d..7f8738a83cb9 100644 | ||
711 | --- a/drivers/hwmon/nct7802.c | ||
712 | +++ b/drivers/hwmon/nct7802.c | ||
713 | @@ -768,7 +768,7 @@ static struct attribute *nct7802_in_attrs[] = { | ||
714 | &sensor_dev_attr_in3_alarm.dev_attr.attr, | ||
715 | &sensor_dev_attr_in3_beep.dev_attr.attr, | ||
716 | |||
717 | - &sensor_dev_attr_in4_input.dev_attr.attr, /* 17 */ | ||
718 | + &sensor_dev_attr_in4_input.dev_attr.attr, /* 16 */ | ||
719 | &sensor_dev_attr_in4_min.dev_attr.attr, | ||
720 | &sensor_dev_attr_in4_max.dev_attr.attr, | ||
721 | &sensor_dev_attr_in4_alarm.dev_attr.attr, | ||
722 | @@ -794,9 +794,9 @@ static umode_t nct7802_in_is_visible(struct kobject *kobj, | ||
723 | |||
724 | if (index >= 6 && index < 11 && (reg & 0x03) != 0x03) /* VSEN1 */ | ||
725 | return 0; | ||
726 | - if (index >= 11 && index < 17 && (reg & 0x0c) != 0x0c) /* VSEN2 */ | ||
727 | + if (index >= 11 && index < 16 && (reg & 0x0c) != 0x0c) /* VSEN2 */ | ||
728 | return 0; | ||
729 | - if (index >= 17 && (reg & 0x30) != 0x30) /* VSEN3 */ | ||
730 | + if (index >= 16 && (reg & 0x30) != 0x30) /* VSEN3 */ | ||
731 | return 0; | ||
732 | |||
733 | return attr->mode; | ||
734 | diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c | ||
735 | index 3e2ab04201e2..25a28e706072 100644 | ||
736 | --- a/drivers/infiniband/core/mad.c | ||
737 | +++ b/drivers/infiniband/core/mad.c | ||
738 | @@ -3155,18 +3155,18 @@ static int ib_mad_port_open(struct ib_device *device, | ||
739 | if (has_smi) | ||
740 | cq_size *= 2; | ||
741 | |||
742 | + port_priv->pd = ib_alloc_pd(device, 0); | ||
743 | + if (IS_ERR(port_priv->pd)) { | ||
744 | + dev_err(&device->dev, "Couldn't create ib_mad PD\n"); | ||
745 | + ret = PTR_ERR(port_priv->pd); | ||
746 | + goto error3; | ||
747 | + } | ||
748 | + | ||
749 | port_priv->cq = ib_alloc_cq(port_priv->device, port_priv, cq_size, 0, | ||
750 | IB_POLL_WORKQUEUE); | ||
751 | if (IS_ERR(port_priv->cq)) { | ||
752 | dev_err(&device->dev, "Couldn't create ib_mad CQ\n"); | ||
753 | ret = PTR_ERR(port_priv->cq); | ||
754 | - goto error3; | ||
755 | - } | ||
756 | - | ||
757 | - port_priv->pd = ib_alloc_pd(device, 0); | ||
758 | - if (IS_ERR(port_priv->pd)) { | ||
759 | - dev_err(&device->dev, "Couldn't create ib_mad PD\n"); | ||
760 | - ret = PTR_ERR(port_priv->pd); | ||
761 | goto error4; | ||
762 | } | ||
763 | |||
764 | @@ -3209,11 +3209,11 @@ error8: | ||
765 | error7: | ||
766 | destroy_mad_qp(&port_priv->qp_info[0]); | ||
767 | error6: | ||
768 | - ib_dealloc_pd(port_priv->pd); | ||
769 | -error4: | ||
770 | ib_free_cq(port_priv->cq); | ||
771 | cleanup_recv_queue(&port_priv->qp_info[1]); | ||
772 | cleanup_recv_queue(&port_priv->qp_info[0]); | ||
773 | +error4: | ||
774 | + ib_dealloc_pd(port_priv->pd); | ||
775 | error3: | ||
776 | kfree(port_priv); | ||
777 | |||
778 | @@ -3243,8 +3243,8 @@ static int ib_mad_port_close(struct ib_device *device, int port_num) | ||
779 | destroy_workqueue(port_priv->wq); | ||
780 | destroy_mad_qp(&port_priv->qp_info[1]); | ||
781 | destroy_mad_qp(&port_priv->qp_info[0]); | ||
782 | - ib_dealloc_pd(port_priv->pd); | ||
783 | ib_free_cq(port_priv->cq); | ||
784 | + ib_dealloc_pd(port_priv->pd); | ||
785 | cleanup_recv_queue(&port_priv->qp_info[1]); | ||
786 | cleanup_recv_queue(&port_priv->qp_info[0]); | ||
787 | /* XXX: Handle deallocation of MAD registration tables */ | ||
788 | diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c | ||
789 | index 415a3185cde7..cf93a96b6324 100644 | ||
790 | --- a/drivers/infiniband/core/user_mad.c | ||
791 | +++ b/drivers/infiniband/core/user_mad.c | ||
792 | @@ -49,6 +49,7 @@ | ||
793 | #include <linux/sched.h> | ||
794 | #include <linux/semaphore.h> | ||
795 | #include <linux/slab.h> | ||
796 | +#include <linux/nospec.h> | ||
797 | |||
798 | #include <asm/uaccess.h> | ||
799 | |||
800 | @@ -843,11 +844,14 @@ static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg) | ||
801 | |||
802 | if (get_user(id, arg)) | ||
803 | return -EFAULT; | ||
804 | + if (id >= IB_UMAD_MAX_AGENTS) | ||
805 | + return -EINVAL; | ||
806 | |||
807 | mutex_lock(&file->port->file_mutex); | ||
808 | mutex_lock(&file->mutex); | ||
809 | |||
810 | - if (id >= IB_UMAD_MAX_AGENTS || !__get_agent(file, id)) { | ||
811 | + id = array_index_nospec(id, IB_UMAD_MAX_AGENTS); | ||
812 | + if (!__get_agent(file, id)) { | ||
813 | ret = -EINVAL; | ||
814 | goto out; | ||
815 | } | ||
816 | diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c | ||
817 | index db64adfbe1af..3e1ea912b41d 100644 | ||
818 | --- a/drivers/input/joystick/iforce/iforce-usb.c | ||
819 | +++ b/drivers/input/joystick/iforce/iforce-usb.c | ||
820 | @@ -145,7 +145,12 @@ static int iforce_usb_probe(struct usb_interface *intf, | ||
821 | return -ENODEV; | ||
822 | |||
823 | epirq = &interface->endpoint[0].desc; | ||
824 | + if (!usb_endpoint_is_int_in(epirq)) | ||
825 | + return -ENODEV; | ||
826 | + | ||
827 | epout = &interface->endpoint[1].desc; | ||
828 | + if (!usb_endpoint_is_int_out(epout)) | ||
829 | + return -ENODEV; | ||
830 | |||
831 | if (!(iforce = kzalloc(sizeof(struct iforce) + 32, GFP_KERNEL))) | ||
832 | goto fail; | ||
833 | diff --git a/drivers/input/mouse/trackpoint.h b/drivers/input/mouse/trackpoint.h | ||
834 | index 88055755f82e..821b446a85dd 100644 | ||
835 | --- a/drivers/input/mouse/trackpoint.h | ||
836 | +++ b/drivers/input/mouse/trackpoint.h | ||
837 | @@ -153,7 +153,8 @@ struct trackpoint_data | ||
838 | #ifdef CONFIG_MOUSE_PS2_TRACKPOINT | ||
839 | int trackpoint_detect(struct psmouse *psmouse, bool set_properties); | ||
840 | #else | ||
841 | -inline int trackpoint_detect(struct psmouse *psmouse, bool set_properties) | ||
842 | +static inline int trackpoint_detect(struct psmouse *psmouse, | ||
843 | + bool set_properties) | ||
844 | { | ||
845 | return -ENOSYS; | ||
846 | } | ||
847 | diff --git a/drivers/input/tablet/kbtab.c b/drivers/input/tablet/kbtab.c | ||
848 | index 4d9d64908b59..b7ea64ec1205 100644 | ||
849 | --- a/drivers/input/tablet/kbtab.c | ||
850 | +++ b/drivers/input/tablet/kbtab.c | ||
851 | @@ -125,6 +125,10 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i | ||
852 | if (intf->cur_altsetting->desc.bNumEndpoints < 1) | ||
853 | return -ENODEV; | ||
854 | |||
855 | + endpoint = &intf->cur_altsetting->endpoint[0].desc; | ||
856 | + if (!usb_endpoint_is_int_in(endpoint)) | ||
857 | + return -ENODEV; | ||
858 | + | ||
859 | kbtab = kzalloc(sizeof(struct kbtab), GFP_KERNEL); | ||
860 | input_dev = input_allocate_device(); | ||
861 | if (!kbtab || !input_dev) | ||
862 | @@ -163,8 +167,6 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i | ||
863 | input_set_abs_params(input_dev, ABS_Y, 0, 0x1750, 4, 0); | ||
864 | input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xff, 0, 0); | ||
865 | |||
866 | - endpoint = &intf->cur_altsetting->endpoint[0].desc; | ||
867 | - | ||
868 | usb_fill_int_urb(kbtab->irq, dev, | ||
869 | usb_rcvintpipe(dev, endpoint->bEndpointAddress), | ||
870 | kbtab->data, 8, | ||
871 | diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c | ||
872 | index 13bbe5795e4e..9bb8d64b6f94 100644 | ||
873 | --- a/drivers/iommu/amd_iommu_init.c | ||
874 | +++ b/drivers/iommu/amd_iommu_init.c | ||
875 | @@ -1534,7 +1534,7 @@ static const struct attribute_group *amd_iommu_groups[] = { | ||
876 | NULL, | ||
877 | }; | ||
878 | |||
879 | -static int iommu_init_pci(struct amd_iommu *iommu) | ||
880 | +static int __init iommu_init_pci(struct amd_iommu *iommu) | ||
881 | { | ||
882 | int cap_ptr = iommu->cap_ptr; | ||
883 | u32 range, misc, low, high; | ||
884 | diff --git a/drivers/irqchip/irq-imx-gpcv2.c b/drivers/irqchip/irq-imx-gpcv2.c | ||
885 | index 2d203b422129..c56da0b13da5 100644 | ||
886 | --- a/drivers/irqchip/irq-imx-gpcv2.c | ||
887 | +++ b/drivers/irqchip/irq-imx-gpcv2.c | ||
888 | @@ -145,6 +145,7 @@ static struct irq_chip gpcv2_irqchip_data_chip = { | ||
889 | .irq_unmask = imx_gpcv2_irq_unmask, | ||
890 | .irq_set_wake = imx_gpcv2_irq_set_wake, | ||
891 | .irq_retrigger = irq_chip_retrigger_hierarchy, | ||
892 | + .irq_set_type = irq_chip_set_type_parent, | ||
893 | #ifdef CONFIG_SMP | ||
894 | .irq_set_affinity = irq_chip_set_affinity_parent, | ||
895 | #endif | ||
896 | diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c | ||
897 | index 5b116ec756b4..d338c319b30e 100644 | ||
898 | --- a/drivers/net/bonding/bond_main.c | ||
899 | +++ b/drivers/net/bonding/bond_main.c | ||
900 | @@ -1107,7 +1107,9 @@ static void bond_compute_features(struct bonding *bond) | ||
901 | |||
902 | done: | ||
903 | bond_dev->vlan_features = vlan_features; | ||
904 | - bond_dev->hw_enc_features = enc_features | NETIF_F_GSO_ENCAP_ALL; | ||
905 | + bond_dev->hw_enc_features = enc_features | NETIF_F_GSO_ENCAP_ALL | | ||
906 | + NETIF_F_HW_VLAN_CTAG_TX | | ||
907 | + NETIF_F_HW_VLAN_STAG_TX; | ||
908 | bond_dev->hard_header_len = max_hard_header_len; | ||
909 | bond_dev->gso_max_segs = gso_max_segs; | ||
910 | netif_set_gso_max_size(bond_dev, gso_max_size); | ||
911 | diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c | ||
912 | index 0b0302af3bd2..54c2354053ac 100644 | ||
913 | --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c | ||
914 | +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c | ||
915 | @@ -592,16 +592,16 @@ static int peak_usb_ndo_stop(struct net_device *netdev) | ||
916 | dev->state &= ~PCAN_USB_STATE_STARTED; | ||
917 | netif_stop_queue(netdev); | ||
918 | |||
919 | + close_candev(netdev); | ||
920 | + | ||
921 | + dev->can.state = CAN_STATE_STOPPED; | ||
922 | + | ||
923 | /* unlink all pending urbs and free used memory */ | ||
924 | peak_usb_unlink_all_urbs(dev); | ||
925 | |||
926 | if (dev->adapter->dev_stop) | ||
927 | dev->adapter->dev_stop(dev); | ||
928 | |||
929 | - close_candev(netdev); | ||
930 | - | ||
931 | - dev->can.state = CAN_STATE_STOPPED; | ||
932 | - | ||
933 | /* can set bus off now */ | ||
934 | if (dev->adapter->dev_set_bus) { | ||
935 | int err = dev->adapter->dev_set_bus(dev, 0); | ||
936 | diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c | ||
937 | index 7f5ec40e2b4d..40647b837b31 100644 | ||
938 | --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c | ||
939 | +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c | ||
940 | @@ -851,7 +851,7 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev) | ||
941 | goto err_out; | ||
942 | |||
943 | /* allocate command buffer once for all for the interface */ | ||
944 | - pdev->cmd_buffer_addr = kmalloc(PCAN_UFD_CMD_BUFFER_SIZE, | ||
945 | + pdev->cmd_buffer_addr = kzalloc(PCAN_UFD_CMD_BUFFER_SIZE, | ||
946 | GFP_KERNEL); | ||
947 | if (!pdev->cmd_buffer_addr) | ||
948 | goto err_out_1; | ||
949 | diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c | ||
950 | index bbdd6058cd2f..d85fdc6949c6 100644 | ||
951 | --- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c | ||
952 | +++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c | ||
953 | @@ -500,7 +500,7 @@ static int pcan_usb_pro_drv_loaded(struct peak_usb_device *dev, int loaded) | ||
954 | u8 *buffer; | ||
955 | int err; | ||
956 | |||
957 | - buffer = kmalloc(PCAN_USBPRO_FCT_DRVLD_REQ_LEN, GFP_KERNEL); | ||
958 | + buffer = kzalloc(PCAN_USBPRO_FCT_DRVLD_REQ_LEN, GFP_KERNEL); | ||
959 | if (!buffer) | ||
960 | return -ENOMEM; | ||
961 | |||
962 | diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | ||
963 | index 53a71166e784..46a7dcf2ff4a 100644 | ||
964 | --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | ||
965 | +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | ||
966 | @@ -3062,12 +3062,13 @@ int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode, bool keep_link) | ||
967 | /* if VF indicate to PF this function is going down (PF will delete sp | ||
968 | * elements and clear initializations | ||
969 | */ | ||
970 | - if (IS_VF(bp)) | ||
971 | + if (IS_VF(bp)) { | ||
972 | + bnx2x_clear_vlan_info(bp); | ||
973 | bnx2x_vfpf_close_vf(bp); | ||
974 | - else if (unload_mode != UNLOAD_RECOVERY) | ||
975 | + } else if (unload_mode != UNLOAD_RECOVERY) { | ||
976 | /* if this is a normal/close unload need to clean up chip*/ | ||
977 | bnx2x_chip_cleanup(bp, unload_mode, keep_link); | ||
978 | - else { | ||
979 | + } else { | ||
980 | /* Send the UNLOAD_REQUEST to the MCP */ | ||
981 | bnx2x_send_unload_req(bp, unload_mode); | ||
982 | |||
983 | diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h | ||
984 | index 243cb9748d35..2ec1c43270b7 100644 | ||
985 | --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h | ||
986 | +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h | ||
987 | @@ -425,6 +425,8 @@ void bnx2x_set_reset_global(struct bnx2x *bp); | ||
988 | void bnx2x_disable_close_the_gate(struct bnx2x *bp); | ||
989 | int bnx2x_init_hw_func_cnic(struct bnx2x *bp); | ||
990 | |||
991 | +void bnx2x_clear_vlan_info(struct bnx2x *bp); | ||
992 | + | ||
993 | /** | ||
994 | * bnx2x_sp_event - handle ramrods completion. | ||
995 | * | ||
996 | diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | ||
997 | index 2ef6012c3dc5..a9681b191304 100644 | ||
998 | --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | ||
999 | +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | ||
1000 | @@ -8488,11 +8488,21 @@ int bnx2x_set_vlan_one(struct bnx2x *bp, u16 vlan, | ||
1001 | return rc; | ||
1002 | } | ||
1003 | |||
1004 | +void bnx2x_clear_vlan_info(struct bnx2x *bp) | ||
1005 | +{ | ||
1006 | + struct bnx2x_vlan_entry *vlan; | ||
1007 | + | ||
1008 | + /* Mark that hw forgot all entries */ | ||
1009 | + list_for_each_entry(vlan, &bp->vlan_reg, link) | ||
1010 | + vlan->hw = false; | ||
1011 | + | ||
1012 | + bp->vlan_cnt = 0; | ||
1013 | +} | ||
1014 | + | ||
1015 | static int bnx2x_del_all_vlans(struct bnx2x *bp) | ||
1016 | { | ||
1017 | struct bnx2x_vlan_mac_obj *vlan_obj = &bp->sp_objs[0].vlan_obj; | ||
1018 | unsigned long ramrod_flags = 0, vlan_flags = 0; | ||
1019 | - struct bnx2x_vlan_entry *vlan; | ||
1020 | int rc; | ||
1021 | |||
1022 | __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); | ||
1023 | @@ -8501,10 +8511,7 @@ static int bnx2x_del_all_vlans(struct bnx2x *bp) | ||
1024 | if (rc) | ||
1025 | return rc; | ||
1026 | |||
1027 | - /* Mark that hw forgot all entries */ | ||
1028 | - list_for_each_entry(vlan, &bp->vlan_reg, link) | ||
1029 | - vlan->hw = false; | ||
1030 | - bp->vlan_cnt = 0; | ||
1031 | + bnx2x_clear_vlan_info(bp); | ||
1032 | |||
1033 | return 0; | ||
1034 | } | ||
1035 | diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c | ||
1036 | index 4a51fc6908ad..098a6b56fd54 100644 | ||
1037 | --- a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c | ||
1038 | +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c | ||
1039 | @@ -441,12 +441,6 @@ arfs_hash_bucket(struct arfs_table *arfs_t, __be16 src_port, | ||
1040 | return &arfs_t->rules_hash[bucket_idx]; | ||
1041 | } | ||
1042 | |||
1043 | -static u8 arfs_get_ip_proto(const struct sk_buff *skb) | ||
1044 | -{ | ||
1045 | - return (skb->protocol == htons(ETH_P_IP)) ? | ||
1046 | - ip_hdr(skb)->protocol : ipv6_hdr(skb)->nexthdr; | ||
1047 | -} | ||
1048 | - | ||
1049 | static struct arfs_table *arfs_get_table(struct mlx5e_arfs_tables *arfs, | ||
1050 | u8 ip_proto, __be16 etype) | ||
1051 | { | ||
1052 | @@ -605,31 +599,9 @@ out: | ||
1053 | arfs_may_expire_flow(priv); | ||
1054 | } | ||
1055 | |||
1056 | -/* return L4 destination port from ip4/6 packets */ | ||
1057 | -static __be16 arfs_get_dst_port(const struct sk_buff *skb) | ||
1058 | -{ | ||
1059 | - char *transport_header; | ||
1060 | - | ||
1061 | - transport_header = skb_transport_header(skb); | ||
1062 | - if (arfs_get_ip_proto(skb) == IPPROTO_TCP) | ||
1063 | - return ((struct tcphdr *)transport_header)->dest; | ||
1064 | - return ((struct udphdr *)transport_header)->dest; | ||
1065 | -} | ||
1066 | - | ||
1067 | -/* return L4 source port from ip4/6 packets */ | ||
1068 | -static __be16 arfs_get_src_port(const struct sk_buff *skb) | ||
1069 | -{ | ||
1070 | - char *transport_header; | ||
1071 | - | ||
1072 | - transport_header = skb_transport_header(skb); | ||
1073 | - if (arfs_get_ip_proto(skb) == IPPROTO_TCP) | ||
1074 | - return ((struct tcphdr *)transport_header)->source; | ||
1075 | - return ((struct udphdr *)transport_header)->source; | ||
1076 | -} | ||
1077 | - | ||
1078 | static struct arfs_rule *arfs_alloc_rule(struct mlx5e_priv *priv, | ||
1079 | struct arfs_table *arfs_t, | ||
1080 | - const struct sk_buff *skb, | ||
1081 | + const struct flow_keys *fk, | ||
1082 | u16 rxq, u32 flow_id) | ||
1083 | { | ||
1084 | struct arfs_rule *rule; | ||
1085 | @@ -644,19 +616,19 @@ static struct arfs_rule *arfs_alloc_rule(struct mlx5e_priv *priv, | ||
1086 | INIT_WORK(&rule->arfs_work, arfs_handle_work); | ||
1087 | |||
1088 | tuple = &rule->tuple; | ||
1089 | - tuple->etype = skb->protocol; | ||
1090 | + tuple->etype = fk->basic.n_proto; | ||
1091 | + tuple->ip_proto = fk->basic.ip_proto; | ||
1092 | if (tuple->etype == htons(ETH_P_IP)) { | ||
1093 | - tuple->src_ipv4 = ip_hdr(skb)->saddr; | ||
1094 | - tuple->dst_ipv4 = ip_hdr(skb)->daddr; | ||
1095 | + tuple->src_ipv4 = fk->addrs.v4addrs.src; | ||
1096 | + tuple->dst_ipv4 = fk->addrs.v4addrs.dst; | ||
1097 | } else { | ||
1098 | - memcpy(&tuple->src_ipv6, &ipv6_hdr(skb)->saddr, | ||
1099 | + memcpy(&tuple->src_ipv6, &fk->addrs.v6addrs.src, | ||
1100 | sizeof(struct in6_addr)); | ||
1101 | - memcpy(&tuple->dst_ipv6, &ipv6_hdr(skb)->daddr, | ||
1102 | + memcpy(&tuple->dst_ipv6, &fk->addrs.v6addrs.dst, | ||
1103 | sizeof(struct in6_addr)); | ||
1104 | } | ||
1105 | - tuple->ip_proto = arfs_get_ip_proto(skb); | ||
1106 | - tuple->src_port = arfs_get_src_port(skb); | ||
1107 | - tuple->dst_port = arfs_get_dst_port(skb); | ||
1108 | + tuple->src_port = fk->ports.src; | ||
1109 | + tuple->dst_port = fk->ports.dst; | ||
1110 | |||
1111 | rule->flow_id = flow_id; | ||
1112 | rule->filter_id = priv->fs.arfs.last_filter_id++ % RPS_NO_FILTER; | ||
1113 | @@ -667,37 +639,33 @@ static struct arfs_rule *arfs_alloc_rule(struct mlx5e_priv *priv, | ||
1114 | return rule; | ||
1115 | } | ||
1116 | |||
1117 | -static bool arfs_cmp_ips(struct arfs_tuple *tuple, | ||
1118 | - const struct sk_buff *skb) | ||
1119 | +static bool arfs_cmp(const struct arfs_tuple *tuple, const struct flow_keys *fk) | ||
1120 | { | ||
1121 | - if (tuple->etype == htons(ETH_P_IP) && | ||
1122 | - tuple->src_ipv4 == ip_hdr(skb)->saddr && | ||
1123 | - tuple->dst_ipv4 == ip_hdr(skb)->daddr) | ||
1124 | - return true; | ||
1125 | - if (tuple->etype == htons(ETH_P_IPV6) && | ||
1126 | - (!memcmp(&tuple->src_ipv6, &ipv6_hdr(skb)->saddr, | ||
1127 | - sizeof(struct in6_addr))) && | ||
1128 | - (!memcmp(&tuple->dst_ipv6, &ipv6_hdr(skb)->daddr, | ||
1129 | - sizeof(struct in6_addr)))) | ||
1130 | - return true; | ||
1131 | + if (tuple->src_port != fk->ports.src || tuple->dst_port != fk->ports.dst) | ||
1132 | + return false; | ||
1133 | + if (tuple->etype != fk->basic.n_proto) | ||
1134 | + return false; | ||
1135 | + if (tuple->etype == htons(ETH_P_IP)) | ||
1136 | + return tuple->src_ipv4 == fk->addrs.v4addrs.src && | ||
1137 | + tuple->dst_ipv4 == fk->addrs.v4addrs.dst; | ||
1138 | + if (tuple->etype == htons(ETH_P_IPV6)) | ||
1139 | + return !memcmp(&tuple->src_ipv6, &fk->addrs.v6addrs.src, | ||
1140 | + sizeof(struct in6_addr)) && | ||
1141 | + !memcmp(&tuple->dst_ipv6, &fk->addrs.v6addrs.dst, | ||
1142 | + sizeof(struct in6_addr)); | ||
1143 | return false; | ||
1144 | } | ||
1145 | |||
1146 | static struct arfs_rule *arfs_find_rule(struct arfs_table *arfs_t, | ||
1147 | - const struct sk_buff *skb) | ||
1148 | + const struct flow_keys *fk) | ||
1149 | { | ||
1150 | struct arfs_rule *arfs_rule; | ||
1151 | struct hlist_head *head; | ||
1152 | - __be16 src_port = arfs_get_src_port(skb); | ||
1153 | - __be16 dst_port = arfs_get_dst_port(skb); | ||
1154 | |||
1155 | - head = arfs_hash_bucket(arfs_t, src_port, dst_port); | ||
1156 | + head = arfs_hash_bucket(arfs_t, fk->ports.src, fk->ports.dst); | ||
1157 | hlist_for_each_entry(arfs_rule, head, hlist) { | ||
1158 | - if (arfs_rule->tuple.src_port == src_port && | ||
1159 | - arfs_rule->tuple.dst_port == dst_port && | ||
1160 | - arfs_cmp_ips(&arfs_rule->tuple, skb)) { | ||
1161 | + if (arfs_cmp(&arfs_rule->tuple, fk)) | ||
1162 | return arfs_rule; | ||
1163 | - } | ||
1164 | } | ||
1165 | |||
1166 | return NULL; | ||
1167 | @@ -710,20 +678,24 @@ int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, | ||
1168 | struct mlx5e_arfs_tables *arfs = &priv->fs.arfs; | ||
1169 | struct arfs_table *arfs_t; | ||
1170 | struct arfs_rule *arfs_rule; | ||
1171 | + struct flow_keys fk; | ||
1172 | + | ||
1173 | + if (!skb_flow_dissect_flow_keys(skb, &fk, 0)) | ||
1174 | + return -EPROTONOSUPPORT; | ||
1175 | |||
1176 | - if (skb->protocol != htons(ETH_P_IP) && | ||
1177 | - skb->protocol != htons(ETH_P_IPV6)) | ||
1178 | + if (fk.basic.n_proto != htons(ETH_P_IP) && | ||
1179 | + fk.basic.n_proto != htons(ETH_P_IPV6)) | ||
1180 | return -EPROTONOSUPPORT; | ||
1181 | |||
1182 | if (skb->encapsulation) | ||
1183 | return -EPROTONOSUPPORT; | ||
1184 | |||
1185 | - arfs_t = arfs_get_table(arfs, arfs_get_ip_proto(skb), skb->protocol); | ||
1186 | + arfs_t = arfs_get_table(arfs, fk.basic.ip_proto, fk.basic.n_proto); | ||
1187 | if (!arfs_t) | ||
1188 | return -EPROTONOSUPPORT; | ||
1189 | |||
1190 | spin_lock_bh(&arfs->arfs_lock); | ||
1191 | - arfs_rule = arfs_find_rule(arfs_t, skb); | ||
1192 | + arfs_rule = arfs_find_rule(arfs_t, &fk); | ||
1193 | if (arfs_rule) { | ||
1194 | if (arfs_rule->rxq == rxq_index) { | ||
1195 | spin_unlock_bh(&arfs->arfs_lock); | ||
1196 | @@ -731,8 +703,7 @@ int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, | ||
1197 | } | ||
1198 | arfs_rule->rxq = rxq_index; | ||
1199 | } else { | ||
1200 | - arfs_rule = arfs_alloc_rule(priv, arfs_t, skb, | ||
1201 | - rxq_index, flow_id); | ||
1202 | + arfs_rule = arfs_alloc_rule(priv, arfs_t, &fk, rxq_index, flow_id); | ||
1203 | if (!arfs_rule) { | ||
1204 | spin_unlock_bh(&arfs->arfs_lock); | ||
1205 | return -ENOMEM; | ||
1206 | diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | ||
1207 | index 54872f8f2f7d..e42ece20cd0b 100644 | ||
1208 | --- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | ||
1209 | +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | ||
1210 | @@ -1149,6 +1149,9 @@ static int mlx5e_set_pauseparam(struct net_device *netdev, | ||
1211 | struct mlx5_core_dev *mdev = priv->mdev; | ||
1212 | int err; | ||
1213 | |||
1214 | + if (!MLX5_CAP_GEN(mdev, vport_group_manager)) | ||
1215 | + return -EOPNOTSUPP; | ||
1216 | + | ||
1217 | if (pauseparam->autoneg) | ||
1218 | return -EINVAL; | ||
1219 | |||
1220 | diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c | ||
1221 | index 0acdf73aa1b0..fd2573cca803 100644 | ||
1222 | --- a/drivers/net/team/team.c | ||
1223 | +++ b/drivers/net/team/team.c | ||
1224 | @@ -1014,7 +1014,9 @@ static void ___team_compute_features(struct team *team) | ||
1225 | } | ||
1226 | |||
1227 | team->dev->vlan_features = vlan_features; | ||
1228 | - team->dev->hw_enc_features = enc_features | NETIF_F_GSO_ENCAP_ALL; | ||
1229 | + team->dev->hw_enc_features = enc_features | NETIF_F_GSO_ENCAP_ALL | | ||
1230 | + NETIF_F_HW_VLAN_CTAG_TX | | ||
1231 | + NETIF_F_HW_VLAN_STAG_TX; | ||
1232 | team->dev->hard_header_len = max_hard_header_len; | ||
1233 | |||
1234 | team->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE; | ||
1235 | diff --git a/drivers/net/usb/pegasus.c b/drivers/net/usb/pegasus.c | ||
1236 | index ee40ac23507a..5fe9f1273fe2 100644 | ||
1237 | --- a/drivers/net/usb/pegasus.c | ||
1238 | +++ b/drivers/net/usb/pegasus.c | ||
1239 | @@ -285,7 +285,7 @@ static void mdio_write(struct net_device *dev, int phy_id, int loc, int val) | ||
1240 | static int read_eprom_word(pegasus_t *pegasus, __u8 index, __u16 *retdata) | ||
1241 | { | ||
1242 | int i; | ||
1243 | - __u8 tmp; | ||
1244 | + __u8 tmp = 0; | ||
1245 | __le16 retdatai; | ||
1246 | int ret; | ||
1247 | |||
1248 | diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c | ||
1249 | index e1bfc9522cbe..174e45d78c46 100644 | ||
1250 | --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c | ||
1251 | +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c | ||
1252 | @@ -439,6 +439,8 @@ static void iwl_pcie_tfd_unmap(struct iwl_trans *trans, | ||
1253 | DMA_TO_DEVICE); | ||
1254 | } | ||
1255 | |||
1256 | + meta->tbs = 0; | ||
1257 | + | ||
1258 | if (trans->cfg->use_tfh) { | ||
1259 | struct iwl_tfh_tfd *tfd_fh = (void *)tfd; | ||
1260 | |||
1261 | diff --git a/drivers/net/wireless/marvell/mwifiex/main.h b/drivers/net/wireless/marvell/mwifiex/main.h | ||
1262 | index 26df28f4bfb2..d4e19efb75af 100644 | ||
1263 | --- a/drivers/net/wireless/marvell/mwifiex/main.h | ||
1264 | +++ b/drivers/net/wireless/marvell/mwifiex/main.h | ||
1265 | @@ -120,6 +120,7 @@ enum { | ||
1266 | |||
1267 | #define MWIFIEX_MAX_TOTAL_SCAN_TIME (MWIFIEX_TIMER_10S - MWIFIEX_TIMER_1S) | ||
1268 | |||
1269 | +#define WPA_GTK_OUI_OFFSET 2 | ||
1270 | #define RSN_GTK_OUI_OFFSET 2 | ||
1271 | |||
1272 | #define MWIFIEX_OUI_NOT_PRESENT 0 | ||
1273 | diff --git a/drivers/net/wireless/marvell/mwifiex/scan.c b/drivers/net/wireless/marvell/mwifiex/scan.c | ||
1274 | index 97847eee2dfb..7e96b6a37946 100644 | ||
1275 | --- a/drivers/net/wireless/marvell/mwifiex/scan.c | ||
1276 | +++ b/drivers/net/wireless/marvell/mwifiex/scan.c | ||
1277 | @@ -181,7 +181,8 @@ mwifiex_is_wpa_oui_present(struct mwifiex_bssdescriptor *bss_desc, u32 cipher) | ||
1278 | u8 ret = MWIFIEX_OUI_NOT_PRESENT; | ||
1279 | |||
1280 | if (has_vendor_hdr(bss_desc->bcn_wpa_ie, WLAN_EID_VENDOR_SPECIFIC)) { | ||
1281 | - iebody = (struct ie_body *) bss_desc->bcn_wpa_ie->data; | ||
1282 | + iebody = (struct ie_body *)((u8 *)bss_desc->bcn_wpa_ie->data + | ||
1283 | + WPA_GTK_OUI_OFFSET); | ||
1284 | oui = &mwifiex_wpa_oui[cipher][0]; | ||
1285 | ret = mwifiex_search_oui_in_ie(iebody, oui); | ||
1286 | if (ret) | ||
1287 | diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c | ||
1288 | index f57815befc90..a469fbe1abaf 100644 | ||
1289 | --- a/drivers/net/xen-netback/netback.c | ||
1290 | +++ b/drivers/net/xen-netback/netback.c | ||
1291 | @@ -927,6 +927,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue, | ||
1292 | skb_shinfo(skb)->nr_frags = MAX_SKB_FRAGS; | ||
1293 | nskb = xenvif_alloc_skb(0); | ||
1294 | if (unlikely(nskb == NULL)) { | ||
1295 | + skb_shinfo(skb)->nr_frags = 0; | ||
1296 | kfree_skb(skb); | ||
1297 | xenvif_tx_err(queue, &txreq, extra_count, idx); | ||
1298 | if (net_ratelimit()) | ||
1299 | @@ -942,6 +943,7 @@ static void xenvif_tx_build_gops(struct xenvif_queue *queue, | ||
1300 | |||
1301 | if (xenvif_set_skb_gso(queue->vif, skb, gso)) { | ||
1302 | /* Failure in xenvif_set_skb_gso is fatal. */ | ||
1303 | + skb_shinfo(skb)->nr_frags = 0; | ||
1304 | kfree_skb(skb); | ||
1305 | kfree_skb(nskb); | ||
1306 | break; | ||
1307 | diff --git a/drivers/s390/cio/qdio_main.c b/drivers/s390/cio/qdio_main.c | ||
1308 | index 58cd0e0c9680..b65cab444802 100644 | ||
1309 | --- a/drivers/s390/cio/qdio_main.c | ||
1310 | +++ b/drivers/s390/cio/qdio_main.c | ||
1311 | @@ -1576,13 +1576,13 @@ static int handle_outbound(struct qdio_q *q, unsigned int callflags, | ||
1312 | rc = qdio_kick_outbound_q(q, phys_aob); | ||
1313 | } else if (need_siga_sync(q)) { | ||
1314 | rc = qdio_siga_sync_q(q); | ||
1315 | + } else if (count < QDIO_MAX_BUFFERS_PER_Q && | ||
1316 | + get_buf_state(q, prev_buf(bufnr), &state, 0) > 0 && | ||
1317 | + state == SLSB_CU_OUTPUT_PRIMED) { | ||
1318 | + /* The previous buffer is not processed yet, tack on. */ | ||
1319 | + qperf_inc(q, fast_requeue); | ||
1320 | } else { | ||
1321 | - /* try to fast requeue buffers */ | ||
1322 | - get_buf_state(q, prev_buf(bufnr), &state, 0); | ||
1323 | - if (state != SLSB_CU_OUTPUT_PRIMED) | ||
1324 | - rc = qdio_kick_outbound_q(q, 0); | ||
1325 | - else | ||
1326 | - qperf_inc(q, fast_requeue); | ||
1327 | + rc = qdio_kick_outbound_q(q, 0); | ||
1328 | } | ||
1329 | |||
1330 | /* in case of SIGA errors we must process the error immediately */ | ||
1331 | diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c | ||
1332 | index d3145799b92f..98787588247b 100644 | ||
1333 | --- a/drivers/scsi/device_handler/scsi_dh_alua.c | ||
1334 | +++ b/drivers/scsi/device_handler/scsi_dh_alua.c | ||
1335 | @@ -53,6 +53,7 @@ | ||
1336 | #define ALUA_FAILOVER_TIMEOUT 60 | ||
1337 | #define ALUA_FAILOVER_RETRIES 5 | ||
1338 | #define ALUA_RTPG_DELAY_MSECS 5 | ||
1339 | +#define ALUA_RTPG_RETRY_DELAY 2 | ||
1340 | |||
1341 | /* device handler flags */ | ||
1342 | #define ALUA_OPTIMIZE_STPG 0x01 | ||
1343 | @@ -681,7 +682,7 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) | ||
1344 | case SCSI_ACCESS_STATE_TRANSITIONING: | ||
1345 | if (time_before(jiffies, pg->expiry)) { | ||
1346 | /* State transition, retry */ | ||
1347 | - pg->interval = 2; | ||
1348 | + pg->interval = ALUA_RTPG_RETRY_DELAY; | ||
1349 | err = SCSI_DH_RETRY; | ||
1350 | } else { | ||
1351 | struct alua_dh_data *h; | ||
1352 | @@ -809,6 +810,8 @@ static void alua_rtpg_work(struct work_struct *work) | ||
1353 | spin_lock_irqsave(&pg->lock, flags); | ||
1354 | pg->flags &= ~ALUA_PG_RUNNING; | ||
1355 | pg->flags |= ALUA_PG_RUN_RTPG; | ||
1356 | + if (!pg->interval) | ||
1357 | + pg->interval = ALUA_RTPG_RETRY_DELAY; | ||
1358 | spin_unlock_irqrestore(&pg->lock, flags); | ||
1359 | queue_delayed_work(alua_wq, &pg->rtpg_work, | ||
1360 | pg->interval * HZ); | ||
1361 | @@ -820,6 +823,8 @@ static void alua_rtpg_work(struct work_struct *work) | ||
1362 | spin_lock_irqsave(&pg->lock, flags); | ||
1363 | if (err == SCSI_DH_RETRY || pg->flags & ALUA_PG_RUN_RTPG) { | ||
1364 | pg->flags &= ~ALUA_PG_RUNNING; | ||
1365 | + if (!pg->interval && !(pg->flags & ALUA_PG_RUN_RTPG)) | ||
1366 | + pg->interval = ALUA_RTPG_RETRY_DELAY; | ||
1367 | pg->flags |= ALUA_PG_RUN_RTPG; | ||
1368 | spin_unlock_irqrestore(&pg->lock, flags); | ||
1369 | queue_delayed_work(alua_wq, &pg->rtpg_work, | ||
1370 | diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c | ||
1371 | index 9f98c7211ec2..b82df8cdf962 100644 | ||
1372 | --- a/drivers/scsi/hpsa.c | ||
1373 | +++ b/drivers/scsi/hpsa.c | ||
1374 | @@ -2236,6 +2236,8 @@ static int handle_ioaccel_mode2_error(struct ctlr_info *h, | ||
1375 | case IOACCEL2_SERV_RESPONSE_COMPLETE: | ||
1376 | switch (c2->error_data.status) { | ||
1377 | case IOACCEL2_STATUS_SR_TASK_COMP_GOOD: | ||
1378 | + if (cmd) | ||
1379 | + cmd->result = 0; | ||
1380 | break; | ||
1381 | case IOACCEL2_STATUS_SR_TASK_COMP_CHK_COND: | ||
1382 | cmd->result |= SAM_STAT_CHECK_CONDITION; | ||
1383 | @@ -2423,8 +2425,10 @@ static void process_ioaccel2_completion(struct ctlr_info *h, | ||
1384 | |||
1385 | /* check for good status */ | ||
1386 | if (likely(c2->error_data.serv_response == 0 && | ||
1387 | - c2->error_data.status == 0)) | ||
1388 | + c2->error_data.status == 0)) { | ||
1389 | + cmd->result = 0; | ||
1390 | return hpsa_cmd_free_and_done(h, c, cmd); | ||
1391 | + } | ||
1392 | |||
1393 | /* | ||
1394 | * Any RAID offload error results in retry which will use | ||
1395 | @@ -5511,6 +5515,12 @@ static int hpsa_scsi_queue_command(struct Scsi_Host *sh, struct scsi_cmnd *cmd) | ||
1396 | } | ||
1397 | c = cmd_tagged_alloc(h, cmd); | ||
1398 | |||
1399 | + /* | ||
1400 | + * This is necessary because the SML doesn't zero out this field during | ||
1401 | + * error recovery. | ||
1402 | + */ | ||
1403 | + cmd->result = 0; | ||
1404 | + | ||
1405 | /* | ||
1406 | * Call alternate submit routine for I/O accelerated commands. | ||
1407 | * Retries always go down the normal I/O path. | ||
1408 | diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c | ||
1409 | index 7e487c78279c..54dea767dfde 100644 | ||
1410 | --- a/drivers/scsi/ibmvscsi/ibmvfc.c | ||
1411 | +++ b/drivers/scsi/ibmvscsi/ibmvfc.c | ||
1412 | @@ -4883,8 +4883,8 @@ static int ibmvfc_remove(struct vio_dev *vdev) | ||
1413 | |||
1414 | spin_lock_irqsave(vhost->host->host_lock, flags); | ||
1415 | ibmvfc_purge_requests(vhost, DID_ERROR); | ||
1416 | - ibmvfc_free_event_pool(vhost); | ||
1417 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | ||
1418 | + ibmvfc_free_event_pool(vhost); | ||
1419 | |||
1420 | ibmvfc_free_mem(vhost); | ||
1421 | spin_lock(&ibmvfc_driver_lock); | ||
1422 | diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c | ||
1423 | index 5b1c37e3913c..d90693b2767f 100644 | ||
1424 | --- a/drivers/scsi/megaraid/megaraid_sas_base.c | ||
1425 | +++ b/drivers/scsi/megaraid/megaraid_sas_base.c | ||
1426 | @@ -2847,6 +2847,7 @@ megasas_fw_crash_buffer_show(struct device *cdev, | ||
1427 | u32 size; | ||
1428 | unsigned long buff_addr; | ||
1429 | unsigned long dmachunk = CRASH_DMA_BUF_SIZE; | ||
1430 | + unsigned long chunk_left_bytes; | ||
1431 | unsigned long src_addr; | ||
1432 | unsigned long flags; | ||
1433 | u32 buff_offset; | ||
1434 | @@ -2872,6 +2873,8 @@ megasas_fw_crash_buffer_show(struct device *cdev, | ||
1435 | } | ||
1436 | |||
1437 | size = (instance->fw_crash_buffer_size * dmachunk) - buff_offset; | ||
1438 | + chunk_left_bytes = dmachunk - (buff_offset % dmachunk); | ||
1439 | + size = (size > chunk_left_bytes) ? chunk_left_bytes : size; | ||
1440 | size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size; | ||
1441 | |||
1442 | src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] + | ||
1443 | diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c | ||
1444 | index a1a5ceb42ce6..6ccde2b41517 100644 | ||
1445 | --- a/drivers/scsi/mpt3sas/mpt3sas_base.c | ||
1446 | +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c | ||
1447 | @@ -1707,9 +1707,11 @@ _base_config_dma_addressing(struct MPT3SAS_ADAPTER *ioc, struct pci_dev *pdev) | ||
1448 | { | ||
1449 | struct sysinfo s; | ||
1450 | u64 consistent_dma_mask; | ||
1451 | + /* Set 63 bit DMA mask for all SAS3 and SAS35 controllers */ | ||
1452 | + int dma_mask = (ioc->hba_mpi_version_belonged > MPI2_VERSION) ? 63 : 64; | ||
1453 | |||
1454 | if (ioc->dma_mask) | ||
1455 | - consistent_dma_mask = DMA_BIT_MASK(64); | ||
1456 | + consistent_dma_mask = DMA_BIT_MASK(dma_mask); | ||
1457 | else | ||
1458 | consistent_dma_mask = DMA_BIT_MASK(32); | ||
1459 | |||
1460 | @@ -1717,11 +1719,11 @@ _base_config_dma_addressing(struct MPT3SAS_ADAPTER *ioc, struct pci_dev *pdev) | ||
1461 | const uint64_t required_mask = | ||
1462 | dma_get_required_mask(&pdev->dev); | ||
1463 | if ((required_mask > DMA_BIT_MASK(32)) && | ||
1464 | - !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && | ||
1465 | + !pci_set_dma_mask(pdev, DMA_BIT_MASK(dma_mask)) && | ||
1466 | !pci_set_consistent_dma_mask(pdev, consistent_dma_mask)) { | ||
1467 | ioc->base_add_sg_single = &_base_add_sg_single_64; | ||
1468 | ioc->sge_size = sizeof(Mpi2SGESimple64_t); | ||
1469 | - ioc->dma_mask = 64; | ||
1470 | + ioc->dma_mask = dma_mask; | ||
1471 | goto out; | ||
1472 | } | ||
1473 | } | ||
1474 | @@ -1747,7 +1749,7 @@ static int | ||
1475 | _base_change_consistent_dma_mask(struct MPT3SAS_ADAPTER *ioc, | ||
1476 | struct pci_dev *pdev) | ||
1477 | { | ||
1478 | - if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { | ||
1479 | + if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(ioc->dma_mask))) { | ||
1480 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) | ||
1481 | return -ENODEV; | ||
1482 | } | ||
1483 | @@ -3381,7 +3383,7 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc) | ||
1484 | total_sz += sz; | ||
1485 | } while (ioc->rdpq_array_enable && (++i < ioc->reply_queue_count)); | ||
1486 | |||
1487 | - if (ioc->dma_mask == 64) { | ||
1488 | + if (ioc->dma_mask > 32) { | ||
1489 | if (_base_change_consistent_dma_mask(ioc, ioc->pdev) != 0) { | ||
1490 | pr_warn(MPT3SAS_FMT | ||
1491 | "no suitable consistent DMA mask for %s\n", | ||
1492 | diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c | ||
1493 | index 19e0b7be8495..917d13abef88 100644 | ||
1494 | --- a/drivers/staging/comedi/drivers/dt3000.c | ||
1495 | +++ b/drivers/staging/comedi/drivers/dt3000.c | ||
1496 | @@ -351,9 +351,9 @@ static irqreturn_t dt3k_interrupt(int irq, void *d) | ||
1497 | static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec, | ||
1498 | unsigned int flags) | ||
1499 | { | ||
1500 | - int divider, base, prescale; | ||
1501 | + unsigned int divider, base, prescale; | ||
1502 | |||
1503 | - /* This function needs improvment */ | ||
1504 | + /* This function needs improvement */ | ||
1505 | /* Don't know if divider==0 works. */ | ||
1506 | |||
1507 | for (prescale = 0; prescale < 16; prescale++) { | ||
1508 | @@ -367,7 +367,7 @@ static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec, | ||
1509 | divider = (*nanosec) / base; | ||
1510 | break; | ||
1511 | case CMDF_ROUND_UP: | ||
1512 | - divider = (*nanosec) / base; | ||
1513 | + divider = DIV_ROUND_UP(*nanosec, base); | ||
1514 | break; | ||
1515 | } | ||
1516 | if (divider < 65536) { | ||
1517 | @@ -377,7 +377,7 @@ static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec, | ||
1518 | } | ||
1519 | |||
1520 | prescale = 15; | ||
1521 | - base = timer_base * (1 << prescale); | ||
1522 | + base = timer_base * (prescale + 1); | ||
1523 | divider = 65535; | ||
1524 | *nanosec = divider * base; | ||
1525 | return (prescale << 16) | (divider); | ||
1526 | diff --git a/drivers/tty/tty_ldsem.c b/drivers/tty/tty_ldsem.c | ||
1527 | index dbd7ba32caac..6c5eb99fcfce 100644 | ||
1528 | --- a/drivers/tty/tty_ldsem.c | ||
1529 | +++ b/drivers/tty/tty_ldsem.c | ||
1530 | @@ -137,8 +137,7 @@ static void __ldsem_wake_readers(struct ld_semaphore *sem) | ||
1531 | |||
1532 | list_for_each_entry_safe(waiter, next, &sem->read_wait, list) { | ||
1533 | tsk = waiter->task; | ||
1534 | - smp_mb(); | ||
1535 | - waiter->task = NULL; | ||
1536 | + smp_store_release(&waiter->task, NULL); | ||
1537 | wake_up_process(tsk); | ||
1538 | put_task_struct(tsk); | ||
1539 | } | ||
1540 | @@ -234,7 +233,7 @@ down_read_failed(struct ld_semaphore *sem, long count, long timeout) | ||
1541 | for (;;) { | ||
1542 | set_task_state(tsk, TASK_UNINTERRUPTIBLE); | ||
1543 | |||
1544 | - if (!waiter.task) | ||
1545 | + if (!smp_load_acquire(&waiter.task)) | ||
1546 | break; | ||
1547 | if (!timeout) | ||
1548 | break; | ||
1549 | diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c | ||
1550 | index 8d4d46f3fd16..b2edbd4bf8c4 100644 | ||
1551 | --- a/drivers/usb/class/cdc-acm.c | ||
1552 | +++ b/drivers/usb/class/cdc-acm.c | ||
1553 | @@ -1264,10 +1264,6 @@ made_compressed_probe: | ||
1554 | if (acm == NULL) | ||
1555 | goto alloc_fail; | ||
1556 | |||
1557 | - minor = acm_alloc_minor(acm); | ||
1558 | - if (minor < 0) | ||
1559 | - goto alloc_fail1; | ||
1560 | - | ||
1561 | ctrlsize = usb_endpoint_maxp(epctrl); | ||
1562 | readsize = usb_endpoint_maxp(epread) * | ||
1563 | (quirks == SINGLE_RX_URB ? 1 : 2); | ||
1564 | @@ -1275,6 +1271,13 @@ made_compressed_probe: | ||
1565 | acm->writesize = usb_endpoint_maxp(epwrite) * 20; | ||
1566 | acm->control = control_interface; | ||
1567 | acm->data = data_interface; | ||
1568 | + | ||
1569 | + usb_get_intf(acm->control); /* undone in destruct() */ | ||
1570 | + | ||
1571 | + minor = acm_alloc_minor(acm); | ||
1572 | + if (minor < 0) | ||
1573 | + goto alloc_fail1; | ||
1574 | + | ||
1575 | acm->minor = minor; | ||
1576 | acm->dev = usb_dev; | ||
1577 | if (h.usb_cdc_acm_descriptor) | ||
1578 | @@ -1420,7 +1423,6 @@ skip_countries: | ||
1579 | usb_driver_claim_interface(&acm_driver, data_interface, acm); | ||
1580 | usb_set_intfdata(data_interface, acm); | ||
1581 | |||
1582 | - usb_get_intf(control_interface); | ||
1583 | tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor, | ||
1584 | &control_interface->dev); | ||
1585 | if (IS_ERR(tty_dev)) { | ||
1586 | diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c | ||
1587 | index 52fc2084b310..06a8f645106b 100644 | ||
1588 | --- a/drivers/usb/core/devio.c | ||
1589 | +++ b/drivers/usb/core/devio.c | ||
1590 | @@ -1810,8 +1810,6 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb | ||
1591 | return 0; | ||
1592 | |||
1593 | error: | ||
1594 | - if (as && as->usbm) | ||
1595 | - dec_usb_memory_use_count(as->usbm, &as->usbm->urb_use_count); | ||
1596 | kfree(isopkt); | ||
1597 | kfree(dr); | ||
1598 | if (as) | ||
1599 | diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c | ||
1600 | index 422ce7b20d73..1626abeca8e8 100644 | ||
1601 | --- a/drivers/usb/core/file.c | ||
1602 | +++ b/drivers/usb/core/file.c | ||
1603 | @@ -191,9 +191,10 @@ int usb_register_dev(struct usb_interface *intf, | ||
1604 | intf->minor = minor; | ||
1605 | break; | ||
1606 | } | ||
1607 | - up_write(&minor_rwsem); | ||
1608 | - if (intf->minor < 0) | ||
1609 | + if (intf->minor < 0) { | ||
1610 | + up_write(&minor_rwsem); | ||
1611 | return -EXFULL; | ||
1612 | + } | ||
1613 | |||
1614 | /* create a usb class device for this usb interface */ | ||
1615 | snprintf(name, sizeof(name), class_driver->name, minor - minor_base); | ||
1616 | @@ -201,12 +202,11 @@ int usb_register_dev(struct usb_interface *intf, | ||
1617 | MKDEV(USB_MAJOR, minor), class_driver, | ||
1618 | "%s", kbasename(name)); | ||
1619 | if (IS_ERR(intf->usb_dev)) { | ||
1620 | - down_write(&minor_rwsem); | ||
1621 | usb_minors[minor] = NULL; | ||
1622 | intf->minor = -1; | ||
1623 | - up_write(&minor_rwsem); | ||
1624 | retval = PTR_ERR(intf->usb_dev); | ||
1625 | } | ||
1626 | + up_write(&minor_rwsem); | ||
1627 | return retval; | ||
1628 | } | ||
1629 | EXPORT_SYMBOL_GPL(usb_register_dev); | ||
1630 | @@ -232,12 +232,12 @@ void usb_deregister_dev(struct usb_interface *intf, | ||
1631 | return; | ||
1632 | |||
1633 | dev_dbg(&intf->dev, "removing %d minor\n", intf->minor); | ||
1634 | + device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor)); | ||
1635 | |||
1636 | down_write(&minor_rwsem); | ||
1637 | usb_minors[intf->minor] = NULL; | ||
1638 | up_write(&minor_rwsem); | ||
1639 | |||
1640 | - device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor)); | ||
1641 | intf->usb_dev = NULL; | ||
1642 | intf->minor = -1; | ||
1643 | destroy_usb_class(); | ||
1644 | diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c | ||
1645 | index 955cd6552e95..d6075d45e10a 100644 | ||
1646 | --- a/drivers/usb/core/message.c | ||
1647 | +++ b/drivers/usb/core/message.c | ||
1648 | @@ -2142,14 +2142,14 @@ int cdc_parse_cdc_header(struct usb_cdc_parsed_header *hdr, | ||
1649 | (struct usb_cdc_dmm_desc *)buffer; | ||
1650 | break; | ||
1651 | case USB_CDC_MDLM_TYPE: | ||
1652 | - if (elength < sizeof(struct usb_cdc_mdlm_desc *)) | ||
1653 | + if (elength < sizeof(struct usb_cdc_mdlm_desc)) | ||
1654 | goto next_desc; | ||
1655 | if (desc) | ||
1656 | return -EINVAL; | ||
1657 | desc = (struct usb_cdc_mdlm_desc *)buffer; | ||
1658 | break; | ||
1659 | case USB_CDC_MDLM_DETAIL_TYPE: | ||
1660 | - if (elength < sizeof(struct usb_cdc_mdlm_detail_desc *)) | ||
1661 | + if (elength < sizeof(struct usb_cdc_mdlm_detail_desc)) | ||
1662 | goto next_desc; | ||
1663 | if (detail) | ||
1664 | return -EINVAL; | ||
1665 | diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c | ||
1666 | index 0ef29d202263..318e087f8442 100644 | ||
1667 | --- a/drivers/usb/misc/iowarrior.c | ||
1668 | +++ b/drivers/usb/misc/iowarrior.c | ||
1669 | @@ -886,19 +886,20 @@ static void iowarrior_disconnect(struct usb_interface *interface) | ||
1670 | dev = usb_get_intfdata(interface); | ||
1671 | mutex_lock(&iowarrior_open_disc_lock); | ||
1672 | usb_set_intfdata(interface, NULL); | ||
1673 | + /* prevent device read, write and ioctl */ | ||
1674 | + dev->present = 0; | ||
1675 | |||
1676 | minor = dev->minor; | ||
1677 | + mutex_unlock(&iowarrior_open_disc_lock); | ||
1678 | + /* give back our minor - this will call close() locks need to be dropped at this point*/ | ||
1679 | |||
1680 | - /* give back our minor */ | ||
1681 | usb_deregister_dev(interface, &iowarrior_class); | ||
1682 | |||
1683 | mutex_lock(&dev->mutex); | ||
1684 | |||
1685 | /* prevent device read, write and ioctl */ | ||
1686 | - dev->present = 0; | ||
1687 | |||
1688 | mutex_unlock(&dev->mutex); | ||
1689 | - mutex_unlock(&iowarrior_open_disc_lock); | ||
1690 | |||
1691 | if (dev->opened) { | ||
1692 | /* There is a process that holds a filedescriptor to the device , | ||
1693 | diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c | ||
1694 | index efa3c86bd262..9744e5f996c1 100644 | ||
1695 | --- a/drivers/usb/misc/yurex.c | ||
1696 | +++ b/drivers/usb/misc/yurex.c | ||
1697 | @@ -96,7 +96,6 @@ static void yurex_delete(struct kref *kref) | ||
1698 | |||
1699 | dev_dbg(&dev->interface->dev, "%s\n", __func__); | ||
1700 | |||
1701 | - usb_put_dev(dev->udev); | ||
1702 | if (dev->cntl_urb) { | ||
1703 | usb_kill_urb(dev->cntl_urb); | ||
1704 | kfree(dev->cntl_req); | ||
1705 | @@ -112,6 +111,7 @@ static void yurex_delete(struct kref *kref) | ||
1706 | dev->int_buffer, dev->urb->transfer_dma); | ||
1707 | usb_free_urb(dev->urb); | ||
1708 | } | ||
1709 | + usb_put_dev(dev->udev); | ||
1710 | kfree(dev); | ||
1711 | } | ||
1712 | |||
1713 | diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c | ||
1714 | index d7b31fdce94d..1bceb11f3782 100644 | ||
1715 | --- a/drivers/usb/serial/option.c | ||
1716 | +++ b/drivers/usb/serial/option.c | ||
1717 | @@ -967,6 +967,11 @@ static const struct usb_device_id option_ids[] = { | ||
1718 | { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x7B) }, | ||
1719 | { USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0xff, 0x06, 0x7C) }, | ||
1720 | |||
1721 | + /* Motorola devices */ | ||
1722 | + { USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x2a70, 0xff, 0xff, 0xff) }, /* mdm6600 */ | ||
1723 | + { USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x2e0a, 0xff, 0xff, 0xff) }, /* mdm9600 */ | ||
1724 | + { USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x4281, 0x0a, 0x00, 0xfc) }, /* mdm ram dl */ | ||
1725 | + { USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x900e, 0xff, 0xff, 0xff) }, /* mdm qc dl */ | ||
1726 | |||
1727 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, | ||
1728 | { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) }, | ||
1729 | @@ -1544,6 +1549,7 @@ static const struct usb_device_id option_ids[] = { | ||
1730 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1428, 0xff, 0xff, 0xff), /* Telewell TW-LTE 4G v2 */ | ||
1731 | .driver_info = RSVD(2) }, | ||
1732 | { USB_DEVICE_INTERFACE_CLASS(ZTE_VENDOR_ID, 0x1476, 0xff) }, /* GosunCn ZTE WeLink ME3630 (ECM/NCM mode) */ | ||
1733 | + { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1481, 0xff, 0x00, 0x00) }, /* ZTE MF871A */ | ||
1734 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1533, 0xff, 0xff, 0xff) }, | ||
1735 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1534, 0xff, 0xff, 0xff) }, | ||
1736 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1535, 0xff, 0xff, 0xff) }, | ||
1737 | @@ -1949,11 +1955,15 @@ static const struct usb_device_id option_ids[] = { | ||
1738 | .driver_info = RSVD(4) }, | ||
1739 | { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7e35, 0xff), /* D-Link DWM-222 */ | ||
1740 | .driver_info = RSVD(4) }, | ||
1741 | + { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7e3d, 0xff), /* D-Link DWM-222 A2 */ | ||
1742 | + .driver_info = RSVD(4) }, | ||
1743 | { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e01, 0xff, 0xff, 0xff) }, /* D-Link DWM-152/C1 */ | ||
1744 | { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e02, 0xff, 0xff, 0xff) }, /* D-Link DWM-156/C1 */ | ||
1745 | { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x7e11, 0xff, 0xff, 0xff) }, /* D-Link DWM-156/A3 */ | ||
1746 | { USB_DEVICE_INTERFACE_CLASS(0x2020, 0x2031, 0xff), /* Olicard 600 */ | ||
1747 | .driver_info = RSVD(4) }, | ||
1748 | + { USB_DEVICE_INTERFACE_CLASS(0x2020, 0x2060, 0xff), /* BroadMobi BM818 */ | ||
1749 | + .driver_info = RSVD(4) }, | ||
1750 | { USB_DEVICE_INTERFACE_CLASS(0x2020, 0x4000, 0xff) }, /* OLICARD300 - MT6225 */ | ||
1751 | { USB_DEVICE(INOVIA_VENDOR_ID, INOVIA_SEW858) }, | ||
1752 | { USB_DEVICE(VIATELECOM_VENDOR_ID, VIATELECOM_PRODUCT_CDS7) }, | ||
1753 | diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c | ||
1754 | index 75e1089dfb01..dd8798bf88e7 100644 | ||
1755 | --- a/drivers/vhost/net.c | ||
1756 | +++ b/drivers/vhost/net.c | ||
1757 | @@ -39,6 +39,12 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;" | ||
1758 | * Using this limit prevents one virtqueue from starving others. */ | ||
1759 | #define VHOST_NET_WEIGHT 0x80000 | ||
1760 | |||
1761 | +/* Max number of packets transferred before requeueing the job. | ||
1762 | + * Using this limit prevents one virtqueue from starving others with small | ||
1763 | + * pkts. | ||
1764 | + */ | ||
1765 | +#define VHOST_NET_PKT_WEIGHT 256 | ||
1766 | + | ||
1767 | /* MAX number of TX used buffers for outstanding zerocopy */ | ||
1768 | #define VHOST_MAX_PEND 128 | ||
1769 | #define VHOST_GOODCOPY_LEN 256 | ||
1770 | @@ -372,6 +378,7 @@ static void handle_tx(struct vhost_net *net) | ||
1771 | struct socket *sock; | ||
1772 | struct vhost_net_ubuf_ref *uninitialized_var(ubufs); | ||
1773 | bool zcopy, zcopy_used; | ||
1774 | + int sent_pkts = 0; | ||
1775 | |||
1776 | mutex_lock(&vq->mutex); | ||
1777 | sock = vq->private_data; | ||
1778 | @@ -386,7 +393,7 @@ static void handle_tx(struct vhost_net *net) | ||
1779 | hdr_size = nvq->vhost_hlen; | ||
1780 | zcopy = nvq->ubufs; | ||
1781 | |||
1782 | - for (;;) { | ||
1783 | + do { | ||
1784 | /* Release DMAs done buffers first */ | ||
1785 | if (zcopy) | ||
1786 | vhost_zerocopy_signal_used(net, vq); | ||
1787 | @@ -474,11 +481,7 @@ static void handle_tx(struct vhost_net *net) | ||
1788 | vhost_zerocopy_signal_used(net, vq); | ||
1789 | total_len += len; | ||
1790 | vhost_net_tx_packet(net); | ||
1791 | - if (unlikely(total_len >= VHOST_NET_WEIGHT)) { | ||
1792 | - vhost_poll_queue(&vq->poll); | ||
1793 | - break; | ||
1794 | - } | ||
1795 | - } | ||
1796 | + } while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len))); | ||
1797 | out: | ||
1798 | mutex_unlock(&vq->mutex); | ||
1799 | } | ||
1800 | @@ -656,6 +659,7 @@ static void handle_rx(struct vhost_net *net) | ||
1801 | struct socket *sock; | ||
1802 | struct iov_iter fixup; | ||
1803 | __virtio16 num_buffers; | ||
1804 | + int recv_pkts = 0; | ||
1805 | |||
1806 | mutex_lock_nested(&vq->mutex, 0); | ||
1807 | sock = vq->private_data; | ||
1808 | @@ -675,7 +679,10 @@ static void handle_rx(struct vhost_net *net) | ||
1809 | vq->log : NULL; | ||
1810 | mergeable = vhost_has_feature(vq, VIRTIO_NET_F_MRG_RXBUF); | ||
1811 | |||
1812 | - while ((sock_len = vhost_net_rx_peek_head_len(net, sock->sk))) { | ||
1813 | + do { | ||
1814 | + sock_len = vhost_net_rx_peek_head_len(net, sock->sk); | ||
1815 | + if (!sock_len) | ||
1816 | + break; | ||
1817 | sock_len += sock_hlen; | ||
1818 | vhost_len = sock_len + vhost_hlen; | ||
1819 | headcount = get_rx_bufs(vq, vq->heads, vhost_len, | ||
1820 | @@ -754,12 +761,10 @@ static void handle_rx(struct vhost_net *net) | ||
1821 | vhost_log_write(vq, vq_log, log, vhost_len, | ||
1822 | vq->iov, in); | ||
1823 | total_len += vhost_len; | ||
1824 | - if (unlikely(total_len >= VHOST_NET_WEIGHT)) { | ||
1825 | - vhost_poll_queue(&vq->poll); | ||
1826 | - goto out; | ||
1827 | - } | ||
1828 | - } | ||
1829 | - vhost_net_enable_vq(net, vq); | ||
1830 | + } while (likely(!vhost_exceeds_weight(vq, ++recv_pkts, total_len))); | ||
1831 | + | ||
1832 | + if (!sock_len) | ||
1833 | + vhost_net_enable_vq(net, vq); | ||
1834 | out: | ||
1835 | mutex_unlock(&vq->mutex); | ||
1836 | } | ||
1837 | @@ -828,7 +833,8 @@ static int vhost_net_open(struct inode *inode, struct file *f) | ||
1838 | n->vqs[i].vhost_hlen = 0; | ||
1839 | n->vqs[i].sock_hlen = 0; | ||
1840 | } | ||
1841 | - vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX); | ||
1842 | + vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX, | ||
1843 | + VHOST_NET_PKT_WEIGHT, VHOST_NET_WEIGHT); | ||
1844 | |||
1845 | vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, POLLOUT, dev); | ||
1846 | vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, POLLIN, dev); | ||
1847 | diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c | ||
1848 | index 17f9ad6fdfa5..dad90f6cc3e1 100644 | ||
1849 | --- a/drivers/vhost/scsi.c | ||
1850 | +++ b/drivers/vhost/scsi.c | ||
1851 | @@ -58,6 +58,12 @@ | ||
1852 | #define VHOST_SCSI_PREALLOC_UPAGES 2048 | ||
1853 | #define VHOST_SCSI_PREALLOC_PROT_SGLS 512 | ||
1854 | |||
1855 | +/* Max number of requests before requeueing the job. | ||
1856 | + * Using this limit prevents one virtqueue from starving others with | ||
1857 | + * request. | ||
1858 | + */ | ||
1859 | +#define VHOST_SCSI_WEIGHT 256 | ||
1860 | + | ||
1861 | struct vhost_scsi_inflight { | ||
1862 | /* Wait for the flush operation to finish */ | ||
1863 | struct completion comp; | ||
1864 | @@ -845,7 +851,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) | ||
1865 | u64 tag; | ||
1866 | u32 exp_data_len, data_direction; | ||
1867 | unsigned out, in; | ||
1868 | - int head, ret, prot_bytes; | ||
1869 | + int head, ret, prot_bytes, c = 0; | ||
1870 | size_t req_size, rsp_size = sizeof(struct virtio_scsi_cmd_resp); | ||
1871 | size_t out_size, in_size; | ||
1872 | u16 lun; | ||
1873 | @@ -864,7 +870,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) | ||
1874 | |||
1875 | vhost_disable_notify(&vs->dev, vq); | ||
1876 | |||
1877 | - for (;;) { | ||
1878 | + do { | ||
1879 | head = vhost_get_vq_desc(vq, vq->iov, | ||
1880 | ARRAY_SIZE(vq->iov), &out, &in, | ||
1881 | NULL, NULL); | ||
1882 | @@ -1080,7 +1086,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) | ||
1883 | */ | ||
1884 | INIT_WORK(&cmd->work, vhost_scsi_submission_work); | ||
1885 | queue_work(vhost_scsi_workqueue, &cmd->work); | ||
1886 | - } | ||
1887 | + } while (likely(!vhost_exceeds_weight(vq, ++c, 0))); | ||
1888 | out: | ||
1889 | mutex_unlock(&vq->mutex); | ||
1890 | } | ||
1891 | @@ -1433,7 +1439,8 @@ static int vhost_scsi_open(struct inode *inode, struct file *f) | ||
1892 | vqs[i] = &vs->vqs[i].vq; | ||
1893 | vs->vqs[i].vq.handle_kick = vhost_scsi_handle_kick; | ||
1894 | } | ||
1895 | - vhost_dev_init(&vs->dev, vqs, VHOST_SCSI_MAX_VQ); | ||
1896 | + vhost_dev_init(&vs->dev, vqs, VHOST_SCSI_MAX_VQ, | ||
1897 | + VHOST_SCSI_WEIGHT, 0); | ||
1898 | |||
1899 | vhost_scsi_init_inflight(vs, NULL); | ||
1900 | |||
1901 | diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c | ||
1902 | index a54dbfe664cd..8da95d4ac4b7 100644 | ||
1903 | --- a/drivers/vhost/vhost.c | ||
1904 | +++ b/drivers/vhost/vhost.c | ||
1905 | @@ -393,8 +393,24 @@ static void vhost_dev_free_iovecs(struct vhost_dev *dev) | ||
1906 | vhost_vq_free_iovecs(dev->vqs[i]); | ||
1907 | } | ||
1908 | |||
1909 | +bool vhost_exceeds_weight(struct vhost_virtqueue *vq, | ||
1910 | + int pkts, int total_len) | ||
1911 | +{ | ||
1912 | + struct vhost_dev *dev = vq->dev; | ||
1913 | + | ||
1914 | + if ((dev->byte_weight && total_len >= dev->byte_weight) || | ||
1915 | + pkts >= dev->weight) { | ||
1916 | + vhost_poll_queue(&vq->poll); | ||
1917 | + return true; | ||
1918 | + } | ||
1919 | + | ||
1920 | + return false; | ||
1921 | +} | ||
1922 | +EXPORT_SYMBOL_GPL(vhost_exceeds_weight); | ||
1923 | + | ||
1924 | void vhost_dev_init(struct vhost_dev *dev, | ||
1925 | - struct vhost_virtqueue **vqs, int nvqs) | ||
1926 | + struct vhost_virtqueue **vqs, int nvqs, | ||
1927 | + int weight, int byte_weight) | ||
1928 | { | ||
1929 | struct vhost_virtqueue *vq; | ||
1930 | int i; | ||
1931 | @@ -408,6 +424,8 @@ void vhost_dev_init(struct vhost_dev *dev, | ||
1932 | dev->iotlb = NULL; | ||
1933 | dev->mm = NULL; | ||
1934 | dev->worker = NULL; | ||
1935 | + dev->weight = weight; | ||
1936 | + dev->byte_weight = byte_weight; | ||
1937 | init_llist_head(&dev->work_list); | ||
1938 | init_waitqueue_head(&dev->wait); | ||
1939 | INIT_LIST_HEAD(&dev->read_list); | ||
1940 | diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h | ||
1941 | index e8efe1af7487..7932ad8d071a 100644 | ||
1942 | --- a/drivers/vhost/vhost.h | ||
1943 | +++ b/drivers/vhost/vhost.h | ||
1944 | @@ -164,9 +164,13 @@ struct vhost_dev { | ||
1945 | struct list_head read_list; | ||
1946 | struct list_head pending_list; | ||
1947 | wait_queue_head_t wait; | ||
1948 | + int weight; | ||
1949 | + int byte_weight; | ||
1950 | }; | ||
1951 | |||
1952 | -void vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs, int nvqs); | ||
1953 | +bool vhost_exceeds_weight(struct vhost_virtqueue *vq, int pkts, int total_len); | ||
1954 | +void vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs, | ||
1955 | + int nvqs, int weight, int byte_weight); | ||
1956 | long vhost_dev_set_owner(struct vhost_dev *dev); | ||
1957 | bool vhost_dev_has_owner(struct vhost_dev *dev); | ||
1958 | long vhost_dev_check_owner(struct vhost_dev *); | ||
1959 | diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c | ||
1960 | index 3cefd602b5b1..a775493b7b67 100644 | ||
1961 | --- a/drivers/vhost/vsock.c | ||
1962 | +++ b/drivers/vhost/vsock.c | ||
1963 | @@ -21,6 +21,14 @@ | ||
1964 | #include "vhost.h" | ||
1965 | |||
1966 | #define VHOST_VSOCK_DEFAULT_HOST_CID 2 | ||
1967 | +/* Max number of bytes transferred before requeueing the job. | ||
1968 | + * Using this limit prevents one virtqueue from starving others. */ | ||
1969 | +#define VHOST_VSOCK_WEIGHT 0x80000 | ||
1970 | +/* Max number of packets transferred before requeueing the job. | ||
1971 | + * Using this limit prevents one virtqueue from starving others with | ||
1972 | + * small pkts. | ||
1973 | + */ | ||
1974 | +#define VHOST_VSOCK_PKT_WEIGHT 256 | ||
1975 | |||
1976 | enum { | ||
1977 | VHOST_VSOCK_FEATURES = VHOST_FEATURES, | ||
1978 | @@ -529,7 +537,9 @@ static int vhost_vsock_dev_open(struct inode *inode, struct file *file) | ||
1979 | vsock->vqs[VSOCK_VQ_TX].handle_kick = vhost_vsock_handle_tx_kick; | ||
1980 | vsock->vqs[VSOCK_VQ_RX].handle_kick = vhost_vsock_handle_rx_kick; | ||
1981 | |||
1982 | - vhost_dev_init(&vsock->dev, vqs, ARRAY_SIZE(vsock->vqs)); | ||
1983 | + vhost_dev_init(&vsock->dev, vqs, ARRAY_SIZE(vsock->vqs), | ||
1984 | + VHOST_VSOCK_PKT_WEIGHT, | ||
1985 | + VHOST_VSOCK_WEIGHT); | ||
1986 | |||
1987 | file->private_data = vsock; | ||
1988 | spin_lock_init(&vsock->send_pkt_list_lock); | ||
1989 | diff --git a/drivers/xen/xen-pciback/conf_space_capability.c b/drivers/xen/xen-pciback/conf_space_capability.c | ||
1990 | index 7f83e9083e9d..b1a1d7de0894 100644 | ||
1991 | --- a/drivers/xen/xen-pciback/conf_space_capability.c | ||
1992 | +++ b/drivers/xen/xen-pciback/conf_space_capability.c | ||
1993 | @@ -115,13 +115,12 @@ static int pm_ctrl_write(struct pci_dev *dev, int offset, u16 new_value, | ||
1994 | { | ||
1995 | int err; | ||
1996 | u16 old_value; | ||
1997 | - pci_power_t new_state, old_state; | ||
1998 | + pci_power_t new_state; | ||
1999 | |||
2000 | err = pci_read_config_word(dev, offset, &old_value); | ||
2001 | if (err) | ||
2002 | goto out; | ||
2003 | |||
2004 | - old_state = (pci_power_t)(old_value & PCI_PM_CTRL_STATE_MASK); | ||
2005 | new_state = (pci_power_t)(new_value & PCI_PM_CTRL_STATE_MASK); | ||
2006 | |||
2007 | new_value &= PM_OK_BITS; | ||
2008 | diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c | ||
2009 | index 52b6e4a40748..5255deac86b2 100644 | ||
2010 | --- a/fs/cifs/smb2pdu.c | ||
2011 | +++ b/fs/cifs/smb2pdu.c | ||
2012 | @@ -168,7 +168,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon) | ||
2013 | if (tcon == NULL) | ||
2014 | return 0; | ||
2015 | |||
2016 | - if (smb2_command == SMB2_TREE_CONNECT) | ||
2017 | + if (smb2_command == SMB2_TREE_CONNECT || smb2_command == SMB2_IOCTL) | ||
2018 | return 0; | ||
2019 | |||
2020 | if (tcon->tidStatus == CifsExiting) { | ||
2021 | @@ -660,7 +660,12 @@ SMB2_sess_alloc_buffer(struct SMB2_sess_data *sess_data) | ||
2022 | else | ||
2023 | req->SecurityMode = 0; | ||
2024 | |||
2025 | +#ifdef CONFIG_CIFS_DFS_UPCALL | ||
2026 | + req->Capabilities = cpu_to_le32(SMB2_GLOBAL_CAP_DFS); | ||
2027 | +#else | ||
2028 | req->Capabilities = 0; | ||
2029 | +#endif /* DFS_UPCALL */ | ||
2030 | + | ||
2031 | req->Channel = 0; /* MBZ */ | ||
2032 | |||
2033 | sess_data->iov[0].iov_base = (char *)req; | ||
2034 | diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c | ||
2035 | index 01932763b4d1..e108c945ac1f 100644 | ||
2036 | --- a/fs/ocfs2/xattr.c | ||
2037 | +++ b/fs/ocfs2/xattr.c | ||
2038 | @@ -3832,7 +3832,6 @@ static int ocfs2_xattr_bucket_find(struct inode *inode, | ||
2039 | u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); | ||
2040 | int low_bucket = 0, bucket, high_bucket; | ||
2041 | struct ocfs2_xattr_bucket *search; | ||
2042 | - u32 last_hash; | ||
2043 | u64 blkno, lower_blkno = 0; | ||
2044 | |||
2045 | search = ocfs2_xattr_bucket_new(inode); | ||
2046 | @@ -3876,8 +3875,6 @@ static int ocfs2_xattr_bucket_find(struct inode *inode, | ||
2047 | if (xh->xh_count) | ||
2048 | xe = &xh->xh_entries[le16_to_cpu(xh->xh_count) - 1]; | ||
2049 | |||
2050 | - last_hash = le32_to_cpu(xe->xe_name_hash); | ||
2051 | - | ||
2052 | /* record lower_blkno which may be the insert place. */ | ||
2053 | lower_blkno = blkno; | ||
2054 | |||
2055 | diff --git a/include/asm-generic/getorder.h b/include/asm-generic/getorder.h | ||
2056 | index 65e4468ac53d..52fbf236a90e 100644 | ||
2057 | --- a/include/asm-generic/getorder.h | ||
2058 | +++ b/include/asm-generic/getorder.h | ||
2059 | @@ -6,24 +6,6 @@ | ||
2060 | #include <linux/compiler.h> | ||
2061 | #include <linux/log2.h> | ||
2062 | |||
2063 | -/* | ||
2064 | - * Runtime evaluation of get_order() | ||
2065 | - */ | ||
2066 | -static inline __attribute_const__ | ||
2067 | -int __get_order(unsigned long size) | ||
2068 | -{ | ||
2069 | - int order; | ||
2070 | - | ||
2071 | - size--; | ||
2072 | - size >>= PAGE_SHIFT; | ||
2073 | -#if BITS_PER_LONG == 32 | ||
2074 | - order = fls(size); | ||
2075 | -#else | ||
2076 | - order = fls64(size); | ||
2077 | -#endif | ||
2078 | - return order; | ||
2079 | -} | ||
2080 | - | ||
2081 | /** | ||
2082 | * get_order - Determine the allocation order of a memory size | ||
2083 | * @size: The size for which to get the order | ||
2084 | @@ -42,19 +24,27 @@ int __get_order(unsigned long size) | ||
2085 | * to hold an object of the specified size. | ||
2086 | * | ||
2087 | * The result is undefined if the size is 0. | ||
2088 | - * | ||
2089 | - * This function may be used to initialise variables with compile time | ||
2090 | - * evaluations of constants. | ||
2091 | */ | ||
2092 | -#define get_order(n) \ | ||
2093 | -( \ | ||
2094 | - __builtin_constant_p(n) ? ( \ | ||
2095 | - ((n) == 0UL) ? BITS_PER_LONG - PAGE_SHIFT : \ | ||
2096 | - (((n) < (1UL << PAGE_SHIFT)) ? 0 : \ | ||
2097 | - ilog2((n) - 1) - PAGE_SHIFT + 1) \ | ||
2098 | - ) : \ | ||
2099 | - __get_order(n) \ | ||
2100 | -) | ||
2101 | +static inline __attribute_const__ int get_order(unsigned long size) | ||
2102 | +{ | ||
2103 | + if (__builtin_constant_p(size)) { | ||
2104 | + if (!size) | ||
2105 | + return BITS_PER_LONG - PAGE_SHIFT; | ||
2106 | + | ||
2107 | + if (size < (1UL << PAGE_SHIFT)) | ||
2108 | + return 0; | ||
2109 | + | ||
2110 | + return ilog2((size) - 1) - PAGE_SHIFT + 1; | ||
2111 | + } | ||
2112 | + | ||
2113 | + size--; | ||
2114 | + size >>= PAGE_SHIFT; | ||
2115 | +#if BITS_PER_LONG == 32 | ||
2116 | + return fls(size); | ||
2117 | +#else | ||
2118 | + return fls64(size); | ||
2119 | +#endif | ||
2120 | +} | ||
2121 | |||
2122 | #endif /* __ASSEMBLY__ */ | ||
2123 | |||
2124 | diff --git a/include/linux/filter.h b/include/linux/filter.h | ||
2125 | index 1f09c521adfe..0837d904405a 100644 | ||
2126 | --- a/include/linux/filter.h | ||
2127 | +++ b/include/linux/filter.h | ||
2128 | @@ -599,6 +599,7 @@ void bpf_warn_invalid_xdp_action(u32 act); | ||
2129 | #ifdef CONFIG_BPF_JIT | ||
2130 | extern int bpf_jit_enable; | ||
2131 | extern int bpf_jit_harden; | ||
2132 | +extern long bpf_jit_limit; | ||
2133 | |||
2134 | typedef void (*bpf_jit_fill_hole_t)(void *area, unsigned int size); | ||
2135 | |||
2136 | diff --git a/include/linux/siphash.h b/include/linux/siphash.h | ||
2137 | new file mode 100644 | ||
2138 | index 000000000000..bf21591a9e5e | ||
2139 | --- /dev/null | ||
2140 | +++ b/include/linux/siphash.h | ||
2141 | @@ -0,0 +1,145 @@ | ||
2142 | +/* Copyright (C) 2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. | ||
2143 | + * | ||
2144 | + * This file is provided under a dual BSD/GPLv2 license. | ||
2145 | + * | ||
2146 | + * SipHash: a fast short-input PRF | ||
2147 | + * https://131002.net/siphash/ | ||
2148 | + * | ||
2149 | + * This implementation is specifically for SipHash2-4 for a secure PRF | ||
2150 | + * and HalfSipHash1-3/SipHash1-3 for an insecure PRF only suitable for | ||
2151 | + * hashtables. | ||
2152 | + */ | ||
2153 | + | ||
2154 | +#ifndef _LINUX_SIPHASH_H | ||
2155 | +#define _LINUX_SIPHASH_H | ||
2156 | + | ||
2157 | +#include <linux/types.h> | ||
2158 | +#include <linux/kernel.h> | ||
2159 | + | ||
2160 | +#define SIPHASH_ALIGNMENT __alignof__(u64) | ||
2161 | +typedef struct { | ||
2162 | + u64 key[2]; | ||
2163 | +} siphash_key_t; | ||
2164 | + | ||
2165 | +static inline bool siphash_key_is_zero(const siphash_key_t *key) | ||
2166 | +{ | ||
2167 | + return !(key->key[0] | key->key[1]); | ||
2168 | +} | ||
2169 | + | ||
2170 | +u64 __siphash_aligned(const void *data, size_t len, const siphash_key_t *key); | ||
2171 | +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | ||
2172 | +u64 __siphash_unaligned(const void *data, size_t len, const siphash_key_t *key); | ||
2173 | +#endif | ||
2174 | + | ||
2175 | +u64 siphash_1u64(const u64 a, const siphash_key_t *key); | ||
2176 | +u64 siphash_2u64(const u64 a, const u64 b, const siphash_key_t *key); | ||
2177 | +u64 siphash_3u64(const u64 a, const u64 b, const u64 c, | ||
2178 | + const siphash_key_t *key); | ||
2179 | +u64 siphash_4u64(const u64 a, const u64 b, const u64 c, const u64 d, | ||
2180 | + const siphash_key_t *key); | ||
2181 | +u64 siphash_1u32(const u32 a, const siphash_key_t *key); | ||
2182 | +u64 siphash_3u32(const u32 a, const u32 b, const u32 c, | ||
2183 | + const siphash_key_t *key); | ||
2184 | + | ||
2185 | +static inline u64 siphash_2u32(const u32 a, const u32 b, | ||
2186 | + const siphash_key_t *key) | ||
2187 | +{ | ||
2188 | + return siphash_1u64((u64)b << 32 | a, key); | ||
2189 | +} | ||
2190 | +static inline u64 siphash_4u32(const u32 a, const u32 b, const u32 c, | ||
2191 | + const u32 d, const siphash_key_t *key) | ||
2192 | +{ | ||
2193 | + return siphash_2u64((u64)b << 32 | a, (u64)d << 32 | c, key); | ||
2194 | +} | ||
2195 | + | ||
2196 | + | ||
2197 | +static inline u64 ___siphash_aligned(const __le64 *data, size_t len, | ||
2198 | + const siphash_key_t *key) | ||
2199 | +{ | ||
2200 | + if (__builtin_constant_p(len) && len == 4) | ||
2201 | + return siphash_1u32(le32_to_cpup((const __le32 *)data), key); | ||
2202 | + if (__builtin_constant_p(len) && len == 8) | ||
2203 | + return siphash_1u64(le64_to_cpu(data[0]), key); | ||
2204 | + if (__builtin_constant_p(len) && len == 16) | ||
2205 | + return siphash_2u64(le64_to_cpu(data[0]), le64_to_cpu(data[1]), | ||
2206 | + key); | ||
2207 | + if (__builtin_constant_p(len) && len == 24) | ||
2208 | + return siphash_3u64(le64_to_cpu(data[0]), le64_to_cpu(data[1]), | ||
2209 | + le64_to_cpu(data[2]), key); | ||
2210 | + if (__builtin_constant_p(len) && len == 32) | ||
2211 | + return siphash_4u64(le64_to_cpu(data[0]), le64_to_cpu(data[1]), | ||
2212 | + le64_to_cpu(data[2]), le64_to_cpu(data[3]), | ||
2213 | + key); | ||
2214 | + return __siphash_aligned(data, len, key); | ||
2215 | +} | ||
2216 | + | ||
2217 | +/** | ||
2218 | + * siphash - compute 64-bit siphash PRF value | ||
2219 | + * @data: buffer to hash | ||
2220 | + * @size: size of @data | ||
2221 | + * @key: the siphash key | ||
2222 | + */ | ||
2223 | +static inline u64 siphash(const void *data, size_t len, | ||
2224 | + const siphash_key_t *key) | ||
2225 | +{ | ||
2226 | +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | ||
2227 | + if (!IS_ALIGNED((unsigned long)data, SIPHASH_ALIGNMENT)) | ||
2228 | + return __siphash_unaligned(data, len, key); | ||
2229 | +#endif | ||
2230 | + return ___siphash_aligned(data, len, key); | ||
2231 | +} | ||
2232 | + | ||
2233 | +#define HSIPHASH_ALIGNMENT __alignof__(unsigned long) | ||
2234 | +typedef struct { | ||
2235 | + unsigned long key[2]; | ||
2236 | +} hsiphash_key_t; | ||
2237 | + | ||
2238 | +u32 __hsiphash_aligned(const void *data, size_t len, | ||
2239 | + const hsiphash_key_t *key); | ||
2240 | +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | ||
2241 | +u32 __hsiphash_unaligned(const void *data, size_t len, | ||
2242 | + const hsiphash_key_t *key); | ||
2243 | +#endif | ||
2244 | + | ||
2245 | +u32 hsiphash_1u32(const u32 a, const hsiphash_key_t *key); | ||
2246 | +u32 hsiphash_2u32(const u32 a, const u32 b, const hsiphash_key_t *key); | ||
2247 | +u32 hsiphash_3u32(const u32 a, const u32 b, const u32 c, | ||
2248 | + const hsiphash_key_t *key); | ||
2249 | +u32 hsiphash_4u32(const u32 a, const u32 b, const u32 c, const u32 d, | ||
2250 | + const hsiphash_key_t *key); | ||
2251 | + | ||
2252 | +static inline u32 ___hsiphash_aligned(const __le32 *data, size_t len, | ||
2253 | + const hsiphash_key_t *key) | ||
2254 | +{ | ||
2255 | + if (__builtin_constant_p(len) && len == 4) | ||
2256 | + return hsiphash_1u32(le32_to_cpu(data[0]), key); | ||
2257 | + if (__builtin_constant_p(len) && len == 8) | ||
2258 | + return hsiphash_2u32(le32_to_cpu(data[0]), le32_to_cpu(data[1]), | ||
2259 | + key); | ||
2260 | + if (__builtin_constant_p(len) && len == 12) | ||
2261 | + return hsiphash_3u32(le32_to_cpu(data[0]), le32_to_cpu(data[1]), | ||
2262 | + le32_to_cpu(data[2]), key); | ||
2263 | + if (__builtin_constant_p(len) && len == 16) | ||
2264 | + return hsiphash_4u32(le32_to_cpu(data[0]), le32_to_cpu(data[1]), | ||
2265 | + le32_to_cpu(data[2]), le32_to_cpu(data[3]), | ||
2266 | + key); | ||
2267 | + return __hsiphash_aligned(data, len, key); | ||
2268 | +} | ||
2269 | + | ||
2270 | +/** | ||
2271 | + * hsiphash - compute 32-bit hsiphash PRF value | ||
2272 | + * @data: buffer to hash | ||
2273 | + * @size: size of @data | ||
2274 | + * @key: the hsiphash key | ||
2275 | + */ | ||
2276 | +static inline u32 hsiphash(const void *data, size_t len, | ||
2277 | + const hsiphash_key_t *key) | ||
2278 | +{ | ||
2279 | +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | ||
2280 | + if (!IS_ALIGNED((unsigned long)data, HSIPHASH_ALIGNMENT)) | ||
2281 | + return __hsiphash_unaligned(data, len, key); | ||
2282 | +#endif | ||
2283 | + return ___hsiphash_aligned(data, len, key); | ||
2284 | +} | ||
2285 | + | ||
2286 | +#endif /* _LINUX_SIPHASH_H */ | ||
2287 | diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h | ||
2288 | index 9ae819e27940..b57a9f37c297 100644 | ||
2289 | --- a/include/net/netfilter/nf_conntrack.h | ||
2290 | +++ b/include/net/netfilter/nf_conntrack.h | ||
2291 | @@ -336,6 +336,8 @@ struct nf_conn *nf_ct_tmpl_alloc(struct net *net, | ||
2292 | gfp_t flags); | ||
2293 | void nf_ct_tmpl_free(struct nf_conn *tmpl); | ||
2294 | |||
2295 | +u32 nf_ct_get_id(const struct nf_conn *ct); | ||
2296 | + | ||
2297 | #define NF_CT_STAT_INC(net, count) __this_cpu_inc((net)->ct.stat->count) | ||
2298 | #define NF_CT_STAT_INC_ATOMIC(net, count) this_cpu_inc((net)->ct.stat->count) | ||
2299 | #define NF_CT_STAT_ADD_ATOMIC(net, count, v) this_cpu_add((net)->ct.stat->count, (v)) | ||
2300 | diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h | ||
2301 | index bf619a67ec03..af1c5e7c7e94 100644 | ||
2302 | --- a/include/net/netns/ipv4.h | ||
2303 | +++ b/include/net/netns/ipv4.h | ||
2304 | @@ -8,6 +8,7 @@ | ||
2305 | #include <linux/uidgid.h> | ||
2306 | #include <net/inet_frag.h> | ||
2307 | #include <linux/rcupdate.h> | ||
2308 | +#include <linux/siphash.h> | ||
2309 | |||
2310 | struct tcpm_hash_bucket; | ||
2311 | struct ctl_table_header; | ||
2312 | @@ -137,5 +138,6 @@ struct netns_ipv4 { | ||
2313 | int sysctl_fib_multipath_use_neigh; | ||
2314 | #endif | ||
2315 | atomic_t rt_genid; | ||
2316 | + siphash_key_t ip_id_key; | ||
2317 | }; | ||
2318 | #endif | ||
2319 | diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h | ||
2320 | index 96bc5acdade3..49482080311a 100644 | ||
2321 | --- a/include/sound/compress_driver.h | ||
2322 | +++ b/include/sound/compress_driver.h | ||
2323 | @@ -185,10 +185,7 @@ static inline void snd_compr_drain_notify(struct snd_compr_stream *stream) | ||
2324 | if (snd_BUG_ON(!stream)) | ||
2325 | return; | ||
2326 | |||
2327 | - if (stream->direction == SND_COMPRESS_PLAYBACK) | ||
2328 | - stream->runtime->state = SNDRV_PCM_STATE_SETUP; | ||
2329 | - else | ||
2330 | - stream->runtime->state = SNDRV_PCM_STATE_PREPARED; | ||
2331 | + stream->runtime->state = SNDRV_PCM_STATE_SETUP; | ||
2332 | |||
2333 | wake_up(&stream->runtime->sleep); | ||
2334 | } | ||
2335 | diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c | ||
2336 | index 879ca844ba1d..df2ebce927ec 100644 | ||
2337 | --- a/kernel/bpf/core.c | ||
2338 | +++ b/kernel/bpf/core.c | ||
2339 | @@ -208,27 +208,80 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off, | ||
2340 | } | ||
2341 | |||
2342 | #ifdef CONFIG_BPF_JIT | ||
2343 | +/* All BPF JIT sysctl knobs here. */ | ||
2344 | +int bpf_jit_enable __read_mostly = IS_BUILTIN(CONFIG_BPF_JIT_ALWAYS_ON); | ||
2345 | +int bpf_jit_harden __read_mostly; | ||
2346 | +long bpf_jit_limit __read_mostly; | ||
2347 | + | ||
2348 | +static atomic_long_t bpf_jit_current; | ||
2349 | + | ||
2350 | +/* Can be overridden by an arch's JIT compiler if it has a custom, | ||
2351 | + * dedicated BPF backend memory area, or if neither of the two | ||
2352 | + * below apply. | ||
2353 | + */ | ||
2354 | +u64 __weak bpf_jit_alloc_exec_limit(void) | ||
2355 | +{ | ||
2356 | +#if defined(MODULES_VADDR) | ||
2357 | + return MODULES_END - MODULES_VADDR; | ||
2358 | +#else | ||
2359 | + return VMALLOC_END - VMALLOC_START; | ||
2360 | +#endif | ||
2361 | +} | ||
2362 | + | ||
2363 | +static int __init bpf_jit_charge_init(void) | ||
2364 | +{ | ||
2365 | + /* Only used as heuristic here to derive limit. */ | ||
2366 | + bpf_jit_limit = min_t(u64, round_up(bpf_jit_alloc_exec_limit() >> 2, | ||
2367 | + PAGE_SIZE), LONG_MAX); | ||
2368 | + return 0; | ||
2369 | +} | ||
2370 | +pure_initcall(bpf_jit_charge_init); | ||
2371 | + | ||
2372 | +static int bpf_jit_charge_modmem(u32 pages) | ||
2373 | +{ | ||
2374 | + if (atomic_long_add_return(pages, &bpf_jit_current) > | ||
2375 | + (bpf_jit_limit >> PAGE_SHIFT)) { | ||
2376 | + if (!capable(CAP_SYS_ADMIN)) { | ||
2377 | + atomic_long_sub(pages, &bpf_jit_current); | ||
2378 | + return -EPERM; | ||
2379 | + } | ||
2380 | + } | ||
2381 | + | ||
2382 | + return 0; | ||
2383 | +} | ||
2384 | + | ||
2385 | +static void bpf_jit_uncharge_modmem(u32 pages) | ||
2386 | +{ | ||
2387 | + atomic_long_sub(pages, &bpf_jit_current); | ||
2388 | +} | ||
2389 | + | ||
2390 | struct bpf_binary_header * | ||
2391 | bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr, | ||
2392 | unsigned int alignment, | ||
2393 | bpf_jit_fill_hole_t bpf_fill_ill_insns) | ||
2394 | { | ||
2395 | struct bpf_binary_header *hdr; | ||
2396 | - unsigned int size, hole, start; | ||
2397 | + u32 size, hole, start, pages; | ||
2398 | |||
2399 | /* Most of BPF filters are really small, but if some of them | ||
2400 | * fill a page, allow at least 128 extra bytes to insert a | ||
2401 | * random section of illegal instructions. | ||
2402 | */ | ||
2403 | size = round_up(proglen + sizeof(*hdr) + 128, PAGE_SIZE); | ||
2404 | + pages = size / PAGE_SIZE; | ||
2405 | + | ||
2406 | + if (bpf_jit_charge_modmem(pages)) | ||
2407 | + return NULL; | ||
2408 | hdr = module_alloc(size); | ||
2409 | - if (hdr == NULL) | ||
2410 | + if (!hdr) { | ||
2411 | + bpf_jit_uncharge_modmem(pages); | ||
2412 | return NULL; | ||
2413 | + } | ||
2414 | |||
2415 | /* Fill space with illegal/arch-dep instructions. */ | ||
2416 | bpf_fill_ill_insns(hdr, size); | ||
2417 | |||
2418 | - hdr->pages = size / PAGE_SIZE; | ||
2419 | + hdr->pages = pages; | ||
2420 | hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)), | ||
2421 | PAGE_SIZE - sizeof(*hdr)); | ||
2422 | start = (get_random_int() % hole) & ~(alignment - 1); | ||
2423 | @@ -241,11 +294,12 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr, | ||
2424 | |||
2425 | void bpf_jit_binary_free(struct bpf_binary_header *hdr) | ||
2426 | { | ||
2427 | + u32 pages = hdr->pages; | ||
2428 | + | ||
2429 | module_memfree(hdr); | ||
2430 | + bpf_jit_uncharge_modmem(pages); | ||
2431 | } | ||
2432 | |||
2433 | -int bpf_jit_harden __read_mostly; | ||
2434 | - | ||
2435 | static int bpf_jit_blind_insn(const struct bpf_insn *from, | ||
2436 | const struct bpf_insn *aux, | ||
2437 | struct bpf_insn *to_buff) | ||
2438 | @@ -925,8 +979,13 @@ load_byte: | ||
2439 | STACK_FRAME_NON_STANDARD(__bpf_prog_run); /* jump table */ | ||
2440 | |||
2441 | #else | ||
2442 | -static unsigned int __bpf_prog_ret0(void *ctx, const struct bpf_insn *insn) | ||
2443 | +static unsigned int __bpf_prog_ret0_warn(void *ctx, | ||
2444 | + const struct bpf_insn *insn) | ||
2445 | { | ||
2446 | + /* If this handler ever gets executed, then BPF_JIT_ALWAYS_ON | ||
2447 | + * is not working properly, so warn about it! | ||
2448 | + */ | ||
2449 | + WARN_ON_ONCE(1); | ||
2450 | return 0; | ||
2451 | } | ||
2452 | #endif | ||
2453 | @@ -981,7 +1040,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) | ||
2454 | #ifndef CONFIG_BPF_JIT_ALWAYS_ON | ||
2455 | fp->bpf_func = (void *) __bpf_prog_run; | ||
2456 | #else | ||
2457 | - fp->bpf_func = (void *) __bpf_prog_ret0; | ||
2458 | + fp->bpf_func = (void *) __bpf_prog_ret0_warn; | ||
2459 | #endif | ||
2460 | |||
2461 | /* eBPF JITs can rewrite the program in case constant | ||
2462 | diff --git a/kernel/events/core.c b/kernel/events/core.c | ||
2463 | index 93d7333c64d8..5bbf7537a612 100644 | ||
2464 | --- a/kernel/events/core.c | ||
2465 | +++ b/kernel/events/core.c | ||
2466 | @@ -10130,7 +10130,7 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu, | ||
2467 | goto err_unlock; | ||
2468 | } | ||
2469 | |||
2470 | - perf_install_in_context(ctx, event, cpu); | ||
2471 | + perf_install_in_context(ctx, event, event->cpu); | ||
2472 | perf_unpin_context(ctx); | ||
2473 | mutex_unlock(&ctx->mutex); | ||
2474 | |||
2475 | diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug | ||
2476 | index 58a22ca10f33..4f561860bf41 100644 | ||
2477 | --- a/lib/Kconfig.debug | ||
2478 | +++ b/lib/Kconfig.debug | ||
2479 | @@ -1822,9 +1822,9 @@ config TEST_HASH | ||
2480 | tristate "Perform selftest on hash functions" | ||
2481 | default n | ||
2482 | help | ||
2483 | - Enable this option to test the kernel's integer (<linux/hash,h>) | ||
2484 | - and string (<linux/stringhash.h>) hash functions on boot | ||
2485 | - (or module load). | ||
2486 | + Enable this option to test the kernel's integer (<linux/hash.h>), | ||
2487 | + string (<linux/stringhash.h>), and siphash (<linux/siphash.h>) | ||
2488 | + hash functions on boot (or module load). | ||
2489 | |||
2490 | This is intended to help people writing architecture-specific | ||
2491 | optimized versions. If unsure, say N. | ||
2492 | diff --git a/lib/Makefile b/lib/Makefile | ||
2493 | index 2447a218fff8..452d2956a5a2 100644 | ||
2494 | --- a/lib/Makefile | ||
2495 | +++ b/lib/Makefile | ||
2496 | @@ -22,7 +22,8 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ | ||
2497 | sha1.o chacha20.o md5.o irq_regs.o argv_split.o \ | ||
2498 | flex_proportions.o ratelimit.o show_mem.o \ | ||
2499 | is_single_threaded.o plist.o decompress.o kobject_uevent.o \ | ||
2500 | - earlycpio.o seq_buf.o nmi_backtrace.o nodemask.o win_minmax.o | ||
2501 | + earlycpio.o seq_buf.o siphash.o \ | ||
2502 | + nmi_backtrace.o nodemask.o win_minmax.o | ||
2503 | |||
2504 | lib-$(CONFIG_MMU) += ioremap.o | ||
2505 | lib-$(CONFIG_SMP) += cpumask.o | ||
2506 | @@ -44,7 +45,7 @@ obj-$(CONFIG_TEST_HEXDUMP) += test_hexdump.o | ||
2507 | obj-y += kstrtox.o | ||
2508 | obj-$(CONFIG_TEST_BPF) += test_bpf.o | ||
2509 | obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o | ||
2510 | -obj-$(CONFIG_TEST_HASH) += test_hash.o | ||
2511 | +obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o | ||
2512 | obj-$(CONFIG_TEST_KASAN) += test_kasan.o | ||
2513 | CFLAGS_test_kasan.o += -fno-builtin | ||
2514 | obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o | ||
2515 | diff --git a/lib/siphash.c b/lib/siphash.c | ||
2516 | new file mode 100644 | ||
2517 | index 000000000000..3ae58b4edad6 | ||
2518 | --- /dev/null | ||
2519 | +++ b/lib/siphash.c | ||
2520 | @@ -0,0 +1,551 @@ | ||
2521 | +/* Copyright (C) 2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. | ||
2522 | + * | ||
2523 | + * This file is provided under a dual BSD/GPLv2 license. | ||
2524 | + * | ||
2525 | + * SipHash: a fast short-input PRF | ||
2526 | + * https://131002.net/siphash/ | ||
2527 | + * | ||
2528 | + * This implementation is specifically for SipHash2-4 for a secure PRF | ||
2529 | + * and HalfSipHash1-3/SipHash1-3 for an insecure PRF only suitable for | ||
2530 | + * hashtables. | ||
2531 | + */ | ||
2532 | + | ||
2533 | +#include <linux/siphash.h> | ||
2534 | +#include <asm/unaligned.h> | ||
2535 | + | ||
2536 | +#if defined(CONFIG_DCACHE_WORD_ACCESS) && BITS_PER_LONG == 64 | ||
2537 | +#include <linux/dcache.h> | ||
2538 | +#include <asm/word-at-a-time.h> | ||
2539 | +#endif | ||
2540 | + | ||
2541 | +#define SIPROUND \ | ||
2542 | + do { \ | ||
2543 | + v0 += v1; v1 = rol64(v1, 13); v1 ^= v0; v0 = rol64(v0, 32); \ | ||
2544 | + v2 += v3; v3 = rol64(v3, 16); v3 ^= v2; \ | ||
2545 | + v0 += v3; v3 = rol64(v3, 21); v3 ^= v0; \ | ||
2546 | + v2 += v1; v1 = rol64(v1, 17); v1 ^= v2; v2 = rol64(v2, 32); \ | ||
2547 | + } while (0) | ||
2548 | + | ||
2549 | +#define PREAMBLE(len) \ | ||
2550 | + u64 v0 = 0x736f6d6570736575ULL; \ | ||
2551 | + u64 v1 = 0x646f72616e646f6dULL; \ | ||
2552 | + u64 v2 = 0x6c7967656e657261ULL; \ | ||
2553 | + u64 v3 = 0x7465646279746573ULL; \ | ||
2554 | + u64 b = ((u64)(len)) << 56; \ | ||
2555 | + v3 ^= key->key[1]; \ | ||
2556 | + v2 ^= key->key[0]; \ | ||
2557 | + v1 ^= key->key[1]; \ | ||
2558 | + v0 ^= key->key[0]; | ||
2559 | + | ||
2560 | +#define POSTAMBLE \ | ||
2561 | + v3 ^= b; \ | ||
2562 | + SIPROUND; \ | ||
2563 | + SIPROUND; \ | ||
2564 | + v0 ^= b; \ | ||
2565 | + v2 ^= 0xff; \ | ||
2566 | + SIPROUND; \ | ||
2567 | + SIPROUND; \ | ||
2568 | + SIPROUND; \ | ||
2569 | + SIPROUND; \ | ||
2570 | + return (v0 ^ v1) ^ (v2 ^ v3); | ||
2571 | + | ||
2572 | +u64 __siphash_aligned(const void *data, size_t len, const siphash_key_t *key) | ||
2573 | +{ | ||
2574 | + const u8 *end = data + len - (len % sizeof(u64)); | ||
2575 | + const u8 left = len & (sizeof(u64) - 1); | ||
2576 | + u64 m; | ||
2577 | + PREAMBLE(len) | ||
2578 | + for (; data != end; data += sizeof(u64)) { | ||
2579 | + m = le64_to_cpup(data); | ||
2580 | + v3 ^= m; | ||
2581 | + SIPROUND; | ||
2582 | + SIPROUND; | ||
2583 | + v0 ^= m; | ||
2584 | + } | ||
2585 | +#if defined(CONFIG_DCACHE_WORD_ACCESS) && BITS_PER_LONG == 64 | ||
2586 | + if (left) | ||
2587 | + b |= le64_to_cpu((__force __le64)(load_unaligned_zeropad(data) & | ||
2588 | + bytemask_from_count(left))); | ||
2589 | +#else | ||
2590 | + switch (left) { | ||
2591 | + case 7: b |= ((u64)end[6]) << 48; | ||
2592 | + case 6: b |= ((u64)end[5]) << 40; | ||
2593 | + case 5: b |= ((u64)end[4]) << 32; | ||
2594 | + case 4: b |= le32_to_cpup(data); break; | ||
2595 | + case 3: b |= ((u64)end[2]) << 16; | ||
2596 | + case 2: b |= le16_to_cpup(data); break; | ||
2597 | + case 1: b |= end[0]; | ||
2598 | + } | ||
2599 | +#endif | ||
2600 | + POSTAMBLE | ||
2601 | +} | ||
2602 | +EXPORT_SYMBOL(__siphash_aligned); | ||
2603 | + | ||
2604 | +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | ||
2605 | +u64 __siphash_unaligned(const void *data, size_t len, const siphash_key_t *key) | ||
2606 | +{ | ||
2607 | + const u8 *end = data + len - (len % sizeof(u64)); | ||
2608 | + const u8 left = len & (sizeof(u64) - 1); | ||
2609 | + u64 m; | ||
2610 | + PREAMBLE(len) | ||
2611 | + for (; data != end; data += sizeof(u64)) { | ||
2612 | + m = get_unaligned_le64(data); | ||
2613 | + v3 ^= m; | ||
2614 | + SIPROUND; | ||
2615 | + SIPROUND; | ||
2616 | + v0 ^= m; | ||
2617 | + } | ||
2618 | +#if defined(CONFIG_DCACHE_WORD_ACCESS) && BITS_PER_LONG == 64 | ||
2619 | + if (left) | ||
2620 | + b |= le64_to_cpu((__force __le64)(load_unaligned_zeropad(data) & | ||
2621 | + bytemask_from_count(left))); | ||
2622 | +#else | ||
2623 | + switch (left) { | ||
2624 | + case 7: b |= ((u64)end[6]) << 48; | ||
2625 | + case 6: b |= ((u64)end[5]) << 40; | ||
2626 | + case 5: b |= ((u64)end[4]) << 32; | ||
2627 | + case 4: b |= get_unaligned_le32(end); break; | ||
2628 | + case 3: b |= ((u64)end[2]) << 16; | ||
2629 | + case 2: b |= get_unaligned_le16(end); break; | ||
2630 | + case 1: b |= end[0]; | ||
2631 | + } | ||
2632 | +#endif | ||
2633 | + POSTAMBLE | ||
2634 | +} | ||
2635 | +EXPORT_SYMBOL(__siphash_unaligned); | ||
2636 | +#endif | ||
2637 | + | ||
2638 | +/** | ||
2639 | + * siphash_1u64 - compute 64-bit siphash PRF value of a u64 | ||
2640 | + * @first: first u64 | ||
2641 | + * @key: the siphash key | ||
2642 | + */ | ||
2643 | +u64 siphash_1u64(const u64 first, const siphash_key_t *key) | ||
2644 | +{ | ||
2645 | + PREAMBLE(8) | ||
2646 | + v3 ^= first; | ||
2647 | + SIPROUND; | ||
2648 | + SIPROUND; | ||
2649 | + v0 ^= first; | ||
2650 | + POSTAMBLE | ||
2651 | +} | ||
2652 | +EXPORT_SYMBOL(siphash_1u64); | ||
2653 | + | ||
2654 | +/** | ||
2655 | + * siphash_2u64 - compute 64-bit siphash PRF value of 2 u64 | ||
2656 | + * @first: first u64 | ||
2657 | + * @second: second u64 | ||
2658 | + * @key: the siphash key | ||
2659 | + */ | ||
2660 | +u64 siphash_2u64(const u64 first, const u64 second, const siphash_key_t *key) | ||
2661 | +{ | ||
2662 | + PREAMBLE(16) | ||
2663 | + v3 ^= first; | ||
2664 | + SIPROUND; | ||
2665 | + SIPROUND; | ||
2666 | + v0 ^= first; | ||
2667 | + v3 ^= second; | ||
2668 | + SIPROUND; | ||
2669 | + SIPROUND; | ||
2670 | + v0 ^= second; | ||
2671 | + POSTAMBLE | ||
2672 | +} | ||
2673 | +EXPORT_SYMBOL(siphash_2u64); | ||
2674 | + | ||
2675 | +/** | ||
2676 | + * siphash_3u64 - compute 64-bit siphash PRF value of 3 u64 | ||
2677 | + * @first: first u64 | ||
2678 | + * @second: second u64 | ||
2679 | + * @third: third u64 | ||
2680 | + * @key: the siphash key | ||
2681 | + */ | ||
2682 | +u64 siphash_3u64(const u64 first, const u64 second, const u64 third, | ||
2683 | + const siphash_key_t *key) | ||
2684 | +{ | ||
2685 | + PREAMBLE(24) | ||
2686 | + v3 ^= first; | ||
2687 | + SIPROUND; | ||
2688 | + SIPROUND; | ||
2689 | + v0 ^= first; | ||
2690 | + v3 ^= second; | ||
2691 | + SIPROUND; | ||
2692 | + SIPROUND; | ||
2693 | + v0 ^= second; | ||
2694 | + v3 ^= third; | ||
2695 | + SIPROUND; | ||
2696 | + SIPROUND; | ||
2697 | + v0 ^= third; | ||
2698 | + POSTAMBLE | ||
2699 | +} | ||
2700 | +EXPORT_SYMBOL(siphash_3u64); | ||
2701 | + | ||
2702 | +/** | ||
2703 | + * siphash_4u64 - compute 64-bit siphash PRF value of 4 u64 | ||
2704 | + * @first: first u64 | ||
2705 | + * @second: second u64 | ||
2706 | + * @third: third u64 | ||
2707 | + * @forth: forth u64 | ||
2708 | + * @key: the siphash key | ||
2709 | + */ | ||
2710 | +u64 siphash_4u64(const u64 first, const u64 second, const u64 third, | ||
2711 | + const u64 forth, const siphash_key_t *key) | ||
2712 | +{ | ||
2713 | + PREAMBLE(32) | ||
2714 | + v3 ^= first; | ||
2715 | + SIPROUND; | ||
2716 | + SIPROUND; | ||
2717 | + v0 ^= first; | ||
2718 | + v3 ^= second; | ||
2719 | + SIPROUND; | ||
2720 | + SIPROUND; | ||
2721 | + v0 ^= second; | ||
2722 | + v3 ^= third; | ||
2723 | + SIPROUND; | ||
2724 | + SIPROUND; | ||
2725 | + v0 ^= third; | ||
2726 | + v3 ^= forth; | ||
2727 | + SIPROUND; | ||
2728 | + SIPROUND; | ||
2729 | + v0 ^= forth; | ||
2730 | + POSTAMBLE | ||
2731 | +} | ||
2732 | +EXPORT_SYMBOL(siphash_4u64); | ||
2733 | + | ||
2734 | +u64 siphash_1u32(const u32 first, const siphash_key_t *key) | ||
2735 | +{ | ||
2736 | + PREAMBLE(4) | ||
2737 | + b |= first; | ||
2738 | + POSTAMBLE | ||
2739 | +} | ||
2740 | +EXPORT_SYMBOL(siphash_1u32); | ||
2741 | + | ||
2742 | +u64 siphash_3u32(const u32 first, const u32 second, const u32 third, | ||
2743 | + const siphash_key_t *key) | ||
2744 | +{ | ||
2745 | + u64 combined = (u64)second << 32 | first; | ||
2746 | + PREAMBLE(12) | ||
2747 | + v3 ^= combined; | ||
2748 | + SIPROUND; | ||
2749 | + SIPROUND; | ||
2750 | + v0 ^= combined; | ||
2751 | + b |= third; | ||
2752 | + POSTAMBLE | ||
2753 | +} | ||
2754 | +EXPORT_SYMBOL(siphash_3u32); | ||
2755 | + | ||
2756 | +#if BITS_PER_LONG == 64 | ||
2757 | +/* Note that on 64-bit, we make HalfSipHash1-3 actually be SipHash1-3, for | ||
2758 | + * performance reasons. On 32-bit, below, we actually implement HalfSipHash1-3. | ||
2759 | + */ | ||
2760 | + | ||
2761 | +#define HSIPROUND SIPROUND | ||
2762 | +#define HPREAMBLE(len) PREAMBLE(len) | ||
2763 | +#define HPOSTAMBLE \ | ||
2764 | + v3 ^= b; \ | ||
2765 | + HSIPROUND; \ | ||
2766 | + v0 ^= b; \ | ||
2767 | + v2 ^= 0xff; \ | ||
2768 | + HSIPROUND; \ | ||
2769 | + HSIPROUND; \ | ||
2770 | + HSIPROUND; \ | ||
2771 | + return (v0 ^ v1) ^ (v2 ^ v3); | ||
2772 | + | ||
2773 | +u32 __hsiphash_aligned(const void *data, size_t len, const hsiphash_key_t *key) | ||
2774 | +{ | ||
2775 | + const u8 *end = data + len - (len % sizeof(u64)); | ||
2776 | + const u8 left = len & (sizeof(u64) - 1); | ||
2777 | + u64 m; | ||
2778 | + HPREAMBLE(len) | ||
2779 | + for (; data != end; data += sizeof(u64)) { | ||
2780 | + m = le64_to_cpup(data); | ||
2781 | + v3 ^= m; | ||
2782 | + HSIPROUND; | ||
2783 | + v0 ^= m; | ||
2784 | + } | ||
2785 | +#if defined(CONFIG_DCACHE_WORD_ACCESS) && BITS_PER_LONG == 64 | ||
2786 | + if (left) | ||
2787 | + b |= le64_to_cpu((__force __le64)(load_unaligned_zeropad(data) & | ||
2788 | + bytemask_from_count(left))); | ||
2789 | +#else | ||
2790 | + switch (left) { | ||
2791 | + case 7: b |= ((u64)end[6]) << 48; | ||
2792 | + case 6: b |= ((u64)end[5]) << 40; | ||
2793 | + case 5: b |= ((u64)end[4]) << 32; | ||
2794 | + case 4: b |= le32_to_cpup(data); break; | ||
2795 | + case 3: b |= ((u64)end[2]) << 16; | ||
2796 | + case 2: b |= le16_to_cpup(data); break; | ||
2797 | + case 1: b |= end[0]; | ||
2798 | + } | ||
2799 | +#endif | ||
2800 | + HPOSTAMBLE | ||
2801 | +} | ||
2802 | +EXPORT_SYMBOL(__hsiphash_aligned); | ||
2803 | + | ||
2804 | +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | ||
2805 | +u32 __hsiphash_unaligned(const void *data, size_t len, | ||
2806 | + const hsiphash_key_t *key) | ||
2807 | +{ | ||
2808 | + const u8 *end = data + len - (len % sizeof(u64)); | ||
2809 | + const u8 left = len & (sizeof(u64) - 1); | ||
2810 | + u64 m; | ||
2811 | + HPREAMBLE(len) | ||
2812 | + for (; data != end; data += sizeof(u64)) { | ||
2813 | + m = get_unaligned_le64(data); | ||
2814 | + v3 ^= m; | ||
2815 | + HSIPROUND; | ||
2816 | + v0 ^= m; | ||
2817 | + } | ||
2818 | +#if defined(CONFIG_DCACHE_WORD_ACCESS) && BITS_PER_LONG == 64 | ||
2819 | + if (left) | ||
2820 | + b |= le64_to_cpu((__force __le64)(load_unaligned_zeropad(data) & | ||
2821 | + bytemask_from_count(left))); | ||
2822 | +#else | ||
2823 | + switch (left) { | ||
2824 | + case 7: b |= ((u64)end[6]) << 48; | ||
2825 | + case 6: b |= ((u64)end[5]) << 40; | ||
2826 | + case 5: b |= ((u64)end[4]) << 32; | ||
2827 | + case 4: b |= get_unaligned_le32(end); break; | ||
2828 | + case 3: b |= ((u64)end[2]) << 16; | ||
2829 | + case 2: b |= get_unaligned_le16(end); break; | ||
2830 | + case 1: b |= end[0]; | ||
2831 | + } | ||
2832 | +#endif | ||
2833 | + HPOSTAMBLE | ||
2834 | +} | ||
2835 | +EXPORT_SYMBOL(__hsiphash_unaligned); | ||
2836 | +#endif | ||
2837 | + | ||
2838 | +/** | ||
2839 | + * hsiphash_1u32 - compute 64-bit hsiphash PRF value of a u32 | ||
2840 | + * @first: first u32 | ||
2841 | + * @key: the hsiphash key | ||
2842 | + */ | ||
2843 | +u32 hsiphash_1u32(const u32 first, const hsiphash_key_t *key) | ||
2844 | +{ | ||
2845 | + HPREAMBLE(4) | ||
2846 | + b |= first; | ||
2847 | + HPOSTAMBLE | ||
2848 | +} | ||
2849 | +EXPORT_SYMBOL(hsiphash_1u32); | ||
2850 | + | ||
2851 | +/** | ||
2852 | + * hsiphash_2u32 - compute 32-bit hsiphash PRF value of 2 u32 | ||
2853 | + * @first: first u32 | ||
2854 | + * @second: second u32 | ||
2855 | + * @key: the hsiphash key | ||
2856 | + */ | ||
2857 | +u32 hsiphash_2u32(const u32 first, const u32 second, const hsiphash_key_t *key) | ||
2858 | +{ | ||
2859 | + u64 combined = (u64)second << 32 | first; | ||
2860 | + HPREAMBLE(8) | ||
2861 | + v3 ^= combined; | ||
2862 | + HSIPROUND; | ||
2863 | + v0 ^= combined; | ||
2864 | + HPOSTAMBLE | ||
2865 | +} | ||
2866 | +EXPORT_SYMBOL(hsiphash_2u32); | ||
2867 | + | ||
2868 | +/** | ||
2869 | + * hsiphash_3u32 - compute 32-bit hsiphash PRF value of 3 u32 | ||
2870 | + * @first: first u32 | ||
2871 | + * @second: second u32 | ||
2872 | + * @third: third u32 | ||
2873 | + * @key: the hsiphash key | ||
2874 | + */ | ||
2875 | +u32 hsiphash_3u32(const u32 first, const u32 second, const u32 third, | ||
2876 | + const hsiphash_key_t *key) | ||
2877 | +{ | ||
2878 | + u64 combined = (u64)second << 32 | first; | ||
2879 | + HPREAMBLE(12) | ||
2880 | + v3 ^= combined; | ||
2881 | + HSIPROUND; | ||
2882 | + v0 ^= combined; | ||
2883 | + b |= third; | ||
2884 | + HPOSTAMBLE | ||
2885 | +} | ||
2886 | +EXPORT_SYMBOL(hsiphash_3u32); | ||
2887 | + | ||
2888 | +/** | ||
2889 | + * hsiphash_4u32 - compute 32-bit hsiphash PRF value of 4 u32 | ||
2890 | + * @first: first u32 | ||
2891 | + * @second: second u32 | ||
2892 | + * @third: third u32 | ||
2893 | + * @forth: forth u32 | ||
2894 | + * @key: the hsiphash key | ||
2895 | + */ | ||
2896 | +u32 hsiphash_4u32(const u32 first, const u32 second, const u32 third, | ||
2897 | + const u32 forth, const hsiphash_key_t *key) | ||
2898 | +{ | ||
2899 | + u64 combined = (u64)second << 32 | first; | ||
2900 | + HPREAMBLE(16) | ||
2901 | + v3 ^= combined; | ||
2902 | + HSIPROUND; | ||
2903 | + v0 ^= combined; | ||
2904 | + combined = (u64)forth << 32 | third; | ||
2905 | + v3 ^= combined; | ||
2906 | + HSIPROUND; | ||
2907 | + v0 ^= combined; | ||
2908 | + HPOSTAMBLE | ||
2909 | +} | ||
2910 | +EXPORT_SYMBOL(hsiphash_4u32); | ||
2911 | +#else | ||
2912 | +#define HSIPROUND \ | ||
2913 | + do { \ | ||
2914 | + v0 += v1; v1 = rol32(v1, 5); v1 ^= v0; v0 = rol32(v0, 16); \ | ||
2915 | + v2 += v3; v3 = rol32(v3, 8); v3 ^= v2; \ | ||
2916 | + v0 += v3; v3 = rol32(v3, 7); v3 ^= v0; \ | ||
2917 | + v2 += v1; v1 = rol32(v1, 13); v1 ^= v2; v2 = rol32(v2, 16); \ | ||
2918 | + } while (0) | ||
2919 | + | ||
2920 | +#define HPREAMBLE(len) \ | ||
2921 | + u32 v0 = 0; \ | ||
2922 | + u32 v1 = 0; \ | ||
2923 | + u32 v2 = 0x6c796765U; \ | ||
2924 | + u32 v3 = 0x74656462U; \ | ||
2925 | + u32 b = ((u32)(len)) << 24; \ | ||
2926 | + v3 ^= key->key[1]; \ | ||
2927 | + v2 ^= key->key[0]; \ | ||
2928 | + v1 ^= key->key[1]; \ | ||
2929 | + v0 ^= key->key[0]; | ||
2930 | + | ||
2931 | +#define HPOSTAMBLE \ | ||
2932 | + v3 ^= b; \ | ||
2933 | + HSIPROUND; \ | ||
2934 | + v0 ^= b; \ | ||
2935 | + v2 ^= 0xff; \ | ||
2936 | + HSIPROUND; \ | ||
2937 | + HSIPROUND; \ | ||
2938 | + HSIPROUND; \ | ||
2939 | + return v1 ^ v3; | ||
2940 | + | ||
2941 | +u32 __hsiphash_aligned(const void *data, size_t len, const hsiphash_key_t *key) | ||
2942 | +{ | ||
2943 | + const u8 *end = data + len - (len % sizeof(u32)); | ||
2944 | + const u8 left = len & (sizeof(u32) - 1); | ||
2945 | + u32 m; | ||
2946 | + HPREAMBLE(len) | ||
2947 | + for (; data != end; data += sizeof(u32)) { | ||
2948 | + m = le32_to_cpup(data); | ||
2949 | + v3 ^= m; | ||
2950 | + HSIPROUND; | ||
2951 | + v0 ^= m; | ||
2952 | + } | ||
2953 | + switch (left) { | ||
2954 | + case 3: b |= ((u32)end[2]) << 16; | ||
2955 | + case 2: b |= le16_to_cpup(data); break; | ||
2956 | + case 1: b |= end[0]; | ||
2957 | + } | ||
2958 | + HPOSTAMBLE | ||
2959 | +} | ||
2960 | +EXPORT_SYMBOL(__hsiphash_aligned); | ||
2961 | + | ||
2962 | +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | ||
2963 | +u32 __hsiphash_unaligned(const void *data, size_t len, | ||
2964 | + const hsiphash_key_t *key) | ||
2965 | +{ | ||
2966 | + const u8 *end = data + len - (len % sizeof(u32)); | ||
2967 | + const u8 left = len & (sizeof(u32) - 1); | ||
2968 | + u32 m; | ||
2969 | + HPREAMBLE(len) | ||
2970 | + for (; data != end; data += sizeof(u32)) { | ||
2971 | + m = get_unaligned_le32(data); | ||
2972 | + v3 ^= m; | ||
2973 | + HSIPROUND; | ||
2974 | + v0 ^= m; | ||
2975 | + } | ||
2976 | + switch (left) { | ||
2977 | + case 3: b |= ((u32)end[2]) << 16; | ||
2978 | + case 2: b |= get_unaligned_le16(end); break; | ||
2979 | + case 1: b |= end[0]; | ||
2980 | + } | ||
2981 | + HPOSTAMBLE | ||
2982 | +} | ||
2983 | +EXPORT_SYMBOL(__hsiphash_unaligned); | ||
2984 | +#endif | ||
2985 | + | ||
2986 | +/** | ||
2987 | + * hsiphash_1u32 - compute 32-bit hsiphash PRF value of a u32 | ||
2988 | + * @first: first u32 | ||
2989 | + * @key: the hsiphash key | ||
2990 | + */ | ||
2991 | +u32 hsiphash_1u32(const u32 first, const hsiphash_key_t *key) | ||
2992 | +{ | ||
2993 | + HPREAMBLE(4) | ||
2994 | + v3 ^= first; | ||
2995 | + HSIPROUND; | ||
2996 | + v0 ^= first; | ||
2997 | + HPOSTAMBLE | ||
2998 | +} | ||
2999 | +EXPORT_SYMBOL(hsiphash_1u32); | ||
3000 | + | ||
3001 | +/** | ||
3002 | + * hsiphash_2u32 - compute 32-bit hsiphash PRF value of 2 u32 | ||
3003 | + * @first: first u32 | ||
3004 | + * @second: second u32 | ||
3005 | + * @key: the hsiphash key | ||
3006 | + */ | ||
3007 | +u32 hsiphash_2u32(const u32 first, const u32 second, const hsiphash_key_t *key) | ||
3008 | +{ | ||
3009 | + HPREAMBLE(8) | ||
3010 | + v3 ^= first; | ||
3011 | + HSIPROUND; | ||
3012 | + v0 ^= first; | ||
3013 | + v3 ^= second; | ||
3014 | + HSIPROUND; | ||
3015 | + v0 ^= second; | ||
3016 | + HPOSTAMBLE | ||
3017 | +} | ||
3018 | +EXPORT_SYMBOL(hsiphash_2u32); | ||
3019 | + | ||
3020 | +/** | ||
3021 | + * hsiphash_3u32 - compute 32-bit hsiphash PRF value of 3 u32 | ||
3022 | + * @first: first u32 | ||
3023 | + * @second: second u32 | ||
3024 | + * @third: third u32 | ||
3025 | + * @key: the hsiphash key | ||
3026 | + */ | ||
3027 | +u32 hsiphash_3u32(const u32 first, const u32 second, const u32 third, | ||
3028 | + const hsiphash_key_t *key) | ||
3029 | +{ | ||
3030 | + HPREAMBLE(12) | ||
3031 | + v3 ^= first; | ||
3032 | + HSIPROUND; | ||
3033 | + v0 ^= first; | ||
3034 | + v3 ^= second; | ||
3035 | + HSIPROUND; | ||
3036 | + v0 ^= second; | ||
3037 | + v3 ^= third; | ||
3038 | + HSIPROUND; | ||
3039 | + v0 ^= third; | ||
3040 | + HPOSTAMBLE | ||
3041 | +} | ||
3042 | +EXPORT_SYMBOL(hsiphash_3u32); | ||
3043 | + | ||
3044 | +/** | ||
3045 | + * hsiphash_4u32 - compute 32-bit hsiphash PRF value of 4 u32 | ||
3046 | + * @first: first u32 | ||
3047 | + * @second: second u32 | ||
3048 | + * @third: third u32 | ||
3049 | + * @forth: forth u32 | ||
3050 | + * @key: the hsiphash key | ||
3051 | + */ | ||
3052 | +u32 hsiphash_4u32(const u32 first, const u32 second, const u32 third, | ||
3053 | + const u32 forth, const hsiphash_key_t *key) | ||
3054 | +{ | ||
3055 | + HPREAMBLE(16) | ||
3056 | + v3 ^= first; | ||
3057 | + HSIPROUND; | ||
3058 | + v0 ^= first; | ||
3059 | + v3 ^= second; | ||
3060 | + HSIPROUND; | ||
3061 | + v0 ^= second; | ||
3062 | + v3 ^= third; | ||
3063 | + HSIPROUND; | ||
3064 | + v0 ^= third; | ||
3065 | + v3 ^= forth; | ||
3066 | + HSIPROUND; | ||
3067 | + v0 ^= forth; | ||
3068 | + HPOSTAMBLE | ||
3069 | +} | ||
3070 | +EXPORT_SYMBOL(hsiphash_4u32); | ||
3071 | +#endif | ||
3072 | diff --git a/lib/test_siphash.c b/lib/test_siphash.c | ||
3073 | new file mode 100644 | ||
3074 | index 000000000000..a6d854d933bf | ||
3075 | --- /dev/null | ||
3076 | +++ b/lib/test_siphash.c | ||
3077 | @@ -0,0 +1,223 @@ | ||
3078 | +/* Test cases for siphash.c | ||
3079 | + * | ||
3080 | + * Copyright (C) 2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. | ||
3081 | + * | ||
3082 | + * This file is provided under a dual BSD/GPLv2 license. | ||
3083 | + * | ||
3084 | + * SipHash: a fast short-input PRF | ||
3085 | + * https://131002.net/siphash/ | ||
3086 | + * | ||
3087 | + * This implementation is specifically for SipHash2-4 for a secure PRF | ||
3088 | + * and HalfSipHash1-3/SipHash1-3 for an insecure PRF only suitable for | ||
3089 | + * hashtables. | ||
3090 | + */ | ||
3091 | + | ||
3092 | +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
3093 | + | ||
3094 | +#include <linux/siphash.h> | ||
3095 | +#include <linux/kernel.h> | ||
3096 | +#include <linux/string.h> | ||
3097 | +#include <linux/errno.h> | ||
3098 | +#include <linux/module.h> | ||
3099 | + | ||
3100 | +/* Test vectors taken from reference source available at: | ||
3101 | + * https://github.com/veorq/SipHash | ||
3102 | + */ | ||
3103 | + | ||
3104 | +static const siphash_key_t test_key_siphash = | ||
3105 | + {{ 0x0706050403020100ULL, 0x0f0e0d0c0b0a0908ULL }}; | ||
3106 | + | ||
3107 | +static const u64 test_vectors_siphash[64] = { | ||
3108 | + 0x726fdb47dd0e0e31ULL, 0x74f839c593dc67fdULL, 0x0d6c8009d9a94f5aULL, | ||
3109 | + 0x85676696d7fb7e2dULL, 0xcf2794e0277187b7ULL, 0x18765564cd99a68dULL, | ||
3110 | + 0xcbc9466e58fee3ceULL, 0xab0200f58b01d137ULL, 0x93f5f5799a932462ULL, | ||
3111 | + 0x9e0082df0ba9e4b0ULL, 0x7a5dbbc594ddb9f3ULL, 0xf4b32f46226bada7ULL, | ||
3112 | + 0x751e8fbc860ee5fbULL, 0x14ea5627c0843d90ULL, 0xf723ca908e7af2eeULL, | ||
3113 | + 0xa129ca6149be45e5ULL, 0x3f2acc7f57c29bdbULL, 0x699ae9f52cbe4794ULL, | ||
3114 | + 0x4bc1b3f0968dd39cULL, 0xbb6dc91da77961bdULL, 0xbed65cf21aa2ee98ULL, | ||
3115 | + 0xd0f2cbb02e3b67c7ULL, 0x93536795e3a33e88ULL, 0xa80c038ccd5ccec8ULL, | ||
3116 | + 0xb8ad50c6f649af94ULL, 0xbce192de8a85b8eaULL, 0x17d835b85bbb15f3ULL, | ||
3117 | + 0x2f2e6163076bcfadULL, 0xde4daaaca71dc9a5ULL, 0xa6a2506687956571ULL, | ||
3118 | + 0xad87a3535c49ef28ULL, 0x32d892fad841c342ULL, 0x7127512f72f27cceULL, | ||
3119 | + 0xa7f32346f95978e3ULL, 0x12e0b01abb051238ULL, 0x15e034d40fa197aeULL, | ||
3120 | + 0x314dffbe0815a3b4ULL, 0x027990f029623981ULL, 0xcadcd4e59ef40c4dULL, | ||
3121 | + 0x9abfd8766a33735cULL, 0x0e3ea96b5304a7d0ULL, 0xad0c42d6fc585992ULL, | ||
3122 | + 0x187306c89bc215a9ULL, 0xd4a60abcf3792b95ULL, 0xf935451de4f21df2ULL, | ||
3123 | + 0xa9538f0419755787ULL, 0xdb9acddff56ca510ULL, 0xd06c98cd5c0975ebULL, | ||
3124 | + 0xe612a3cb9ecba951ULL, 0xc766e62cfcadaf96ULL, 0xee64435a9752fe72ULL, | ||
3125 | + 0xa192d576b245165aULL, 0x0a8787bf8ecb74b2ULL, 0x81b3e73d20b49b6fULL, | ||
3126 | + 0x7fa8220ba3b2eceaULL, 0x245731c13ca42499ULL, 0xb78dbfaf3a8d83bdULL, | ||
3127 | + 0xea1ad565322a1a0bULL, 0x60e61c23a3795013ULL, 0x6606d7e446282b93ULL, | ||
3128 | + 0x6ca4ecb15c5f91e1ULL, 0x9f626da15c9625f3ULL, 0xe51b38608ef25f57ULL, | ||
3129 | + 0x958a324ceb064572ULL | ||
3130 | +}; | ||
3131 | + | ||
3132 | +#if BITS_PER_LONG == 64 | ||
3133 | +static const hsiphash_key_t test_key_hsiphash = | ||
3134 | + {{ 0x0706050403020100ULL, 0x0f0e0d0c0b0a0908ULL }}; | ||
3135 | + | ||
3136 | +static const u32 test_vectors_hsiphash[64] = { | ||
3137 | + 0x050fc4dcU, 0x7d57ca93U, 0x4dc7d44dU, | ||
3138 | + 0xe7ddf7fbU, 0x88d38328U, 0x49533b67U, | ||
3139 | + 0xc59f22a7U, 0x9bb11140U, 0x8d299a8eU, | ||
3140 | + 0x6c063de4U, 0x92ff097fU, 0xf94dc352U, | ||
3141 | + 0x57b4d9a2U, 0x1229ffa7U, 0xc0f95d34U, | ||
3142 | + 0x2a519956U, 0x7d908b66U, 0x63dbd80cU, | ||
3143 | + 0xb473e63eU, 0x8d297d1cU, 0xa6cce040U, | ||
3144 | + 0x2b45f844U, 0xa320872eU, 0xdae6c123U, | ||
3145 | + 0x67349c8cU, 0x705b0979U, 0xca9913a5U, | ||
3146 | + 0x4ade3b35U, 0xef6cd00dU, 0x4ab1e1f4U, | ||
3147 | + 0x43c5e663U, 0x8c21d1bcU, 0x16a7b60dU, | ||
3148 | + 0x7a8ff9bfU, 0x1f2a753eU, 0xbf186b91U, | ||
3149 | + 0xada26206U, 0xa3c33057U, 0xae3a36a1U, | ||
3150 | + 0x7b108392U, 0x99e41531U, 0x3f1ad944U, | ||
3151 | + 0xc8138825U, 0xc28949a6U, 0xfaf8876bU, | ||
3152 | + 0x9f042196U, 0x68b1d623U, 0x8b5114fdU, | ||
3153 | + 0xdf074c46U, 0x12cc86b3U, 0x0a52098fU, | ||
3154 | + 0x9d292f9aU, 0xa2f41f12U, 0x43a71ed0U, | ||
3155 | + 0x73f0bce6U, 0x70a7e980U, 0x243c6d75U, | ||
3156 | + 0xfdb71513U, 0xa67d8a08U, 0xb7e8f148U, | ||
3157 | + 0xf7a644eeU, 0x0f1837f2U, 0x4b6694e0U, | ||
3158 | + 0xb7bbb3a8U | ||
3159 | +}; | ||
3160 | +#else | ||
3161 | +static const hsiphash_key_t test_key_hsiphash = | ||
3162 | + {{ 0x03020100U, 0x07060504U }}; | ||
3163 | + | ||
3164 | +static const u32 test_vectors_hsiphash[64] = { | ||
3165 | + 0x5814c896U, 0xe7e864caU, 0xbc4b0e30U, | ||
3166 | + 0x01539939U, 0x7e059ea6U, 0x88e3d89bU, | ||
3167 | + 0xa0080b65U, 0x9d38d9d6U, 0x577999b1U, | ||
3168 | + 0xc839caedU, 0xe4fa32cfU, 0x959246eeU, | ||
3169 | + 0x6b28096cU, 0x66dd9cd6U, 0x16658a7cU, | ||
3170 | + 0xd0257b04U, 0x8b31d501U, 0x2b1cd04bU, | ||
3171 | + 0x06712339U, 0x522aca67U, 0x911bb605U, | ||
3172 | + 0x90a65f0eU, 0xf826ef7bU, 0x62512debU, | ||
3173 | + 0x57150ad7U, 0x5d473507U, 0x1ec47442U, | ||
3174 | + 0xab64afd3U, 0x0a4100d0U, 0x6d2ce652U, | ||
3175 | + 0x2331b6a3U, 0x08d8791aU, 0xbc6dda8dU, | ||
3176 | + 0xe0f6c934U, 0xb0652033U, 0x9b9851ccU, | ||
3177 | + 0x7c46fb7fU, 0x732ba8cbU, 0xf142997aU, | ||
3178 | + 0xfcc9aa1bU, 0x05327eb2U, 0xe110131cU, | ||
3179 | + 0xf9e5e7c0U, 0xa7d708a6U, 0x11795ab1U, | ||
3180 | + 0x65671619U, 0x9f5fff91U, 0xd89c5267U, | ||
3181 | + 0x007783ebU, 0x95766243U, 0xab639262U, | ||
3182 | + 0x9c7e1390U, 0xc368dda6U, 0x38ddc455U, | ||
3183 | + 0xfa13d379U, 0x979ea4e8U, 0x53ecd77eU, | ||
3184 | + 0x2ee80657U, 0x33dbb66aU, 0xae3f0577U, | ||
3185 | + 0x88b4c4ccU, 0x3e7f480bU, 0x74c1ebf8U, | ||
3186 | + 0x87178304U | ||
3187 | +}; | ||
3188 | +#endif | ||
3189 | + | ||
3190 | +static int __init siphash_test_init(void) | ||
3191 | +{ | ||
3192 | + u8 in[64] __aligned(SIPHASH_ALIGNMENT); | ||
3193 | + u8 in_unaligned[65] __aligned(SIPHASH_ALIGNMENT); | ||
3194 | + u8 i; | ||
3195 | + int ret = 0; | ||
3196 | + | ||
3197 | + for (i = 0; i < 64; ++i) { | ||
3198 | + in[i] = i; | ||
3199 | + in_unaligned[i + 1] = i; | ||
3200 | + if (siphash(in, i, &test_key_siphash) != | ||
3201 | + test_vectors_siphash[i]) { | ||
3202 | + pr_info("siphash self-test aligned %u: FAIL\n", i + 1); | ||
3203 | + ret = -EINVAL; | ||
3204 | + } | ||
3205 | + if (siphash(in_unaligned + 1, i, &test_key_siphash) != | ||
3206 | + test_vectors_siphash[i]) { | ||
3207 | + pr_info("siphash self-test unaligned %u: FAIL\n", i + 1); | ||
3208 | + ret = -EINVAL; | ||
3209 | + } | ||
3210 | + if (hsiphash(in, i, &test_key_hsiphash) != | ||
3211 | + test_vectors_hsiphash[i]) { | ||
3212 | + pr_info("hsiphash self-test aligned %u: FAIL\n", i + 1); | ||
3213 | + ret = -EINVAL; | ||
3214 | + } | ||
3215 | + if (hsiphash(in_unaligned + 1, i, &test_key_hsiphash) != | ||
3216 | + test_vectors_hsiphash[i]) { | ||
3217 | + pr_info("hsiphash self-test unaligned %u: FAIL\n", i + 1); | ||
3218 | + ret = -EINVAL; | ||
3219 | + } | ||
3220 | + } | ||
3221 | + if (siphash_1u64(0x0706050403020100ULL, &test_key_siphash) != | ||
3222 | + test_vectors_siphash[8]) { | ||
3223 | + pr_info("siphash self-test 1u64: FAIL\n"); | ||
3224 | + ret = -EINVAL; | ||
3225 | + } | ||
3226 | + if (siphash_2u64(0x0706050403020100ULL, 0x0f0e0d0c0b0a0908ULL, | ||
3227 | + &test_key_siphash) != test_vectors_siphash[16]) { | ||
3228 | + pr_info("siphash self-test 2u64: FAIL\n"); | ||
3229 | + ret = -EINVAL; | ||
3230 | + } | ||
3231 | + if (siphash_3u64(0x0706050403020100ULL, 0x0f0e0d0c0b0a0908ULL, | ||
3232 | + 0x1716151413121110ULL, &test_key_siphash) != | ||
3233 | + test_vectors_siphash[24]) { | ||
3234 | + pr_info("siphash self-test 3u64: FAIL\n"); | ||
3235 | + ret = -EINVAL; | ||
3236 | + } | ||
3237 | + if (siphash_4u64(0x0706050403020100ULL, 0x0f0e0d0c0b0a0908ULL, | ||
3238 | + 0x1716151413121110ULL, 0x1f1e1d1c1b1a1918ULL, | ||
3239 | + &test_key_siphash) != test_vectors_siphash[32]) { | ||
3240 | + pr_info("siphash self-test 4u64: FAIL\n"); | ||
3241 | + ret = -EINVAL; | ||
3242 | + } | ||
3243 | + if (siphash_1u32(0x03020100U, &test_key_siphash) != | ||
3244 | + test_vectors_siphash[4]) { | ||
3245 | + pr_info("siphash self-test 1u32: FAIL\n"); | ||
3246 | + ret = -EINVAL; | ||
3247 | + } | ||
3248 | + if (siphash_2u32(0x03020100U, 0x07060504U, &test_key_siphash) != | ||
3249 | + test_vectors_siphash[8]) { | ||
3250 | + pr_info("siphash self-test 2u32: FAIL\n"); | ||
3251 | + ret = -EINVAL; | ||
3252 | + } | ||
3253 | + if (siphash_3u32(0x03020100U, 0x07060504U, | ||
3254 | + 0x0b0a0908U, &test_key_siphash) != | ||
3255 | + test_vectors_siphash[12]) { | ||
3256 | + pr_info("siphash self-test 3u32: FAIL\n"); | ||
3257 | + ret = -EINVAL; | ||
3258 | + } | ||
3259 | + if (siphash_4u32(0x03020100U, 0x07060504U, | ||
3260 | + 0x0b0a0908U, 0x0f0e0d0cU, &test_key_siphash) != | ||
3261 | + test_vectors_siphash[16]) { | ||
3262 | + pr_info("siphash self-test 4u32: FAIL\n"); | ||
3263 | + ret = -EINVAL; | ||
3264 | + } | ||
3265 | + if (hsiphash_1u32(0x03020100U, &test_key_hsiphash) != | ||
3266 | + test_vectors_hsiphash[4]) { | ||
3267 | + pr_info("hsiphash self-test 1u32: FAIL\n"); | ||
3268 | + ret = -EINVAL; | ||
3269 | + } | ||
3270 | + if (hsiphash_2u32(0x03020100U, 0x07060504U, &test_key_hsiphash) != | ||
3271 | + test_vectors_hsiphash[8]) { | ||
3272 | + pr_info("hsiphash self-test 2u32: FAIL\n"); | ||
3273 | + ret = -EINVAL; | ||
3274 | + } | ||
3275 | + if (hsiphash_3u32(0x03020100U, 0x07060504U, | ||
3276 | + 0x0b0a0908U, &test_key_hsiphash) != | ||
3277 | + test_vectors_hsiphash[12]) { | ||
3278 | + pr_info("hsiphash self-test 3u32: FAIL\n"); | ||
3279 | + ret = -EINVAL; | ||
3280 | + } | ||
3281 | + if (hsiphash_4u32(0x03020100U, 0x07060504U, | ||
3282 | + 0x0b0a0908U, 0x0f0e0d0cU, &test_key_hsiphash) != | ||
3283 | + test_vectors_hsiphash[16]) { | ||
3284 | + pr_info("hsiphash self-test 4u32: FAIL\n"); | ||
3285 | + ret = -EINVAL; | ||
3286 | + } | ||
3287 | + if (!ret) | ||
3288 | + pr_info("self-tests: pass\n"); | ||
3289 | + return ret; | ||
3290 | +} | ||
3291 | + | ||
3292 | +static void __exit siphash_test_exit(void) | ||
3293 | +{ | ||
3294 | +} | ||
3295 | + | ||
3296 | +module_init(siphash_test_init); | ||
3297 | +module_exit(siphash_test_exit); | ||
3298 | + | ||
3299 | +MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>"); | ||
3300 | +MODULE_LICENSE("Dual BSD/GPL"); | ||
3301 | diff --git a/mm/memcontrol.c b/mm/memcontrol.c | ||
3302 | index 86a6b331b964..cbcbba028c2d 100644 | ||
3303 | --- a/mm/memcontrol.c | ||
3304 | +++ b/mm/memcontrol.c | ||
3305 | @@ -887,26 +887,45 @@ void mem_cgroup_iter_break(struct mem_cgroup *root, | ||
3306 | css_put(&prev->css); | ||
3307 | } | ||
3308 | |||
3309 | -static void invalidate_reclaim_iterators(struct mem_cgroup *dead_memcg) | ||
3310 | +static void __invalidate_reclaim_iterators(struct mem_cgroup *from, | ||
3311 | + struct mem_cgroup *dead_memcg) | ||
3312 | { | ||
3313 | - struct mem_cgroup *memcg = dead_memcg; | ||
3314 | struct mem_cgroup_reclaim_iter *iter; | ||
3315 | struct mem_cgroup_per_node *mz; | ||
3316 | int nid; | ||
3317 | int i; | ||
3318 | |||
3319 | - for (; memcg; memcg = parent_mem_cgroup(memcg)) { | ||
3320 | - for_each_node(nid) { | ||
3321 | - mz = mem_cgroup_nodeinfo(memcg, nid); | ||
3322 | - for (i = 0; i <= DEF_PRIORITY; i++) { | ||
3323 | - iter = &mz->iter[i]; | ||
3324 | - cmpxchg(&iter->position, | ||
3325 | - dead_memcg, NULL); | ||
3326 | - } | ||
3327 | + for_each_node(nid) { | ||
3328 | + mz = mem_cgroup_nodeinfo(from, nid); | ||
3329 | + for (i = 0; i <= DEF_PRIORITY; i++) { | ||
3330 | + iter = &mz->iter[i]; | ||
3331 | + cmpxchg(&iter->position, | ||
3332 | + dead_memcg, NULL); | ||
3333 | } | ||
3334 | } | ||
3335 | } | ||
3336 | |||
3337 | +static void invalidate_reclaim_iterators(struct mem_cgroup *dead_memcg) | ||
3338 | +{ | ||
3339 | + struct mem_cgroup *memcg = dead_memcg; | ||
3340 | + struct mem_cgroup *last; | ||
3341 | + | ||
3342 | + do { | ||
3343 | + __invalidate_reclaim_iterators(memcg, dead_memcg); | ||
3344 | + last = memcg; | ||
3345 | + } while ((memcg = parent_mem_cgroup(memcg))); | ||
3346 | + | ||
3347 | + /* | ||
3348 | + * When cgruop1 non-hierarchy mode is used, | ||
3349 | + * parent_mem_cgroup() does not walk all the way up to the | ||
3350 | + * cgroup root (root_mem_cgroup). So we have to handle | ||
3351 | + * dead_memcg from cgroup root separately. | ||
3352 | + */ | ||
3353 | + if (last != root_mem_cgroup) | ||
3354 | + __invalidate_reclaim_iterators(root_mem_cgroup, | ||
3355 | + dead_memcg); | ||
3356 | +} | ||
3357 | + | ||
3358 | /* | ||
3359 | * Iteration constructs for visiting all cgroups (under a tree). If | ||
3360 | * loops are exited prematurely (break), mem_cgroup_iter_break() must | ||
3361 | diff --git a/mm/usercopy.c b/mm/usercopy.c | ||
3362 | index 3c8da0af9695..7683c22551ff 100644 | ||
3363 | --- a/mm/usercopy.c | ||
3364 | +++ b/mm/usercopy.c | ||
3365 | @@ -124,7 +124,7 @@ static inline const char *check_kernel_text_object(const void *ptr, | ||
3366 | static inline const char *check_bogus_address(const void *ptr, unsigned long n) | ||
3367 | { | ||
3368 | /* Reject if object wraps past end of memory. */ | ||
3369 | - if ((unsigned long)ptr + n < (unsigned long)ptr) | ||
3370 | + if ((unsigned long)ptr + (n - 1) < (unsigned long)ptr) | ||
3371 | return "<wrapped address>"; | ||
3372 | |||
3373 | /* Reject if NULL or ZERO-allocation. */ | ||
3374 | diff --git a/mm/vmalloc.c b/mm/vmalloc.c | ||
3375 | index 73afe460caf0..dd66f1fb3fcf 100644 | ||
3376 | --- a/mm/vmalloc.c | ||
3377 | +++ b/mm/vmalloc.c | ||
3378 | @@ -1707,6 +1707,12 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, | ||
3379 | if (!addr) | ||
3380 | return NULL; | ||
3381 | |||
3382 | + /* | ||
3383 | + * First make sure the mappings are removed from all page-tables | ||
3384 | + * before they are freed. | ||
3385 | + */ | ||
3386 | + vmalloc_sync_all(); | ||
3387 | + | ||
3388 | /* | ||
3389 | * In this function, newly allocated vm_struct has VM_UNINITIALIZED | ||
3390 | * flag. It means that vm_struct is not fully initialized. | ||
3391 | @@ -2243,6 +2249,9 @@ EXPORT_SYMBOL(remap_vmalloc_range); | ||
3392 | /* | ||
3393 | * Implement a stub for vmalloc_sync_all() if the architecture chose not to | ||
3394 | * have one. | ||
3395 | + * | ||
3396 | + * The purpose of this function is to make sure the vmalloc area | ||
3397 | + * mappings are identical in all page-tables in the system. | ||
3398 | */ | ||
3399 | void __weak vmalloc_sync_all(void) | ||
3400 | { | ||
3401 | diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c | ||
3402 | index 546ba76b35a5..a6fc82704f0c 100644 | ||
3403 | --- a/net/core/sysctl_net_core.c | ||
3404 | +++ b/net/core/sysctl_net_core.c | ||
3405 | @@ -24,9 +24,12 @@ | ||
3406 | |||
3407 | static int zero = 0; | ||
3408 | static int one = 1; | ||
3409 | +static int two __maybe_unused = 2; | ||
3410 | static int min_sndbuf = SOCK_MIN_SNDBUF; | ||
3411 | static int min_rcvbuf = SOCK_MIN_RCVBUF; | ||
3412 | static int max_skb_frags = MAX_SKB_FRAGS; | ||
3413 | +static long long_one __maybe_unused = 1; | ||
3414 | +static long long_max __maybe_unused = LONG_MAX; | ||
3415 | |||
3416 | static int net_msg_warn; /* Unused, but still a sysctl */ | ||
3417 | |||
3418 | @@ -231,6 +234,50 @@ static int proc_do_rss_key(struct ctl_table *table, int write, | ||
3419 | return proc_dostring(&fake_table, write, buffer, lenp, ppos); | ||
3420 | } | ||
3421 | |||
3422 | +#ifdef CONFIG_BPF_JIT | ||
3423 | +static int proc_dointvec_minmax_bpf_enable(struct ctl_table *table, int write, | ||
3424 | + void __user *buffer, size_t *lenp, | ||
3425 | + loff_t *ppos) | ||
3426 | +{ | ||
3427 | + int ret, jit_enable = *(int *)table->data; | ||
3428 | + struct ctl_table tmp = *table; | ||
3429 | + | ||
3430 | + if (write && !capable(CAP_SYS_ADMIN)) | ||
3431 | + return -EPERM; | ||
3432 | + | ||
3433 | + tmp.data = &jit_enable; | ||
3434 | + ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); | ||
3435 | + if (write && !ret) { | ||
3436 | + *(int *)table->data = jit_enable; | ||
3437 | + if (jit_enable == 2) | ||
3438 | + pr_warn("bpf_jit_enable = 2 was set! NEVER use this in production, only for JIT debugging!\n"); | ||
3439 | + } | ||
3440 | + return ret; | ||
3441 | +} | ||
3442 | + | ||
3443 | +static int | ||
3444 | +proc_dointvec_minmax_bpf_restricted(struct ctl_table *table, int write, | ||
3445 | + void __user *buffer, size_t *lenp, | ||
3446 | + loff_t *ppos) | ||
3447 | +{ | ||
3448 | + if (!capable(CAP_SYS_ADMIN)) | ||
3449 | + return -EPERM; | ||
3450 | + | ||
3451 | + return proc_dointvec_minmax(table, write, buffer, lenp, ppos); | ||
3452 | +} | ||
3453 | + | ||
3454 | +static int | ||
3455 | +proc_dolongvec_minmax_bpf_restricted(struct ctl_table *table, int write, | ||
3456 | + void __user *buffer, size_t *lenp, | ||
3457 | + loff_t *ppos) | ||
3458 | +{ | ||
3459 | + if (!capable(CAP_SYS_ADMIN)) | ||
3460 | + return -EPERM; | ||
3461 | + | ||
3462 | + return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); | ||
3463 | +} | ||
3464 | +#endif | ||
3465 | + | ||
3466 | static struct ctl_table net_core_table[] = { | ||
3467 | #ifdef CONFIG_NET | ||
3468 | { | ||
3469 | @@ -292,13 +339,14 @@ static struct ctl_table net_core_table[] = { | ||
3470 | .data = &bpf_jit_enable, | ||
3471 | .maxlen = sizeof(int), | ||
3472 | .mode = 0644, | ||
3473 | -#ifndef CONFIG_BPF_JIT_ALWAYS_ON | ||
3474 | - .proc_handler = proc_dointvec | ||
3475 | -#else | ||
3476 | - .proc_handler = proc_dointvec_minmax, | ||
3477 | + .proc_handler = proc_dointvec_minmax_bpf_enable, | ||
3478 | +# ifdef CONFIG_BPF_JIT_ALWAYS_ON | ||
3479 | .extra1 = &one, | ||
3480 | .extra2 = &one, | ||
3481 | -#endif | ||
3482 | +# else | ||
3483 | + .extra1 = &zero, | ||
3484 | + .extra2 = &two, | ||
3485 | +# endif | ||
3486 | }, | ||
3487 | # ifdef CONFIG_HAVE_EBPF_JIT | ||
3488 | { | ||
3489 | @@ -306,9 +354,20 @@ static struct ctl_table net_core_table[] = { | ||
3490 | .data = &bpf_jit_harden, | ||
3491 | .maxlen = sizeof(int), | ||
3492 | .mode = 0600, | ||
3493 | - .proc_handler = proc_dointvec, | ||
3494 | + .proc_handler = proc_dointvec_minmax_bpf_restricted, | ||
3495 | + .extra1 = &zero, | ||
3496 | + .extra2 = &two, | ||
3497 | }, | ||
3498 | # endif | ||
3499 | + { | ||
3500 | + .procname = "bpf_jit_limit", | ||
3501 | + .data = &bpf_jit_limit, | ||
3502 | + .maxlen = sizeof(long), | ||
3503 | + .mode = 0600, | ||
3504 | + .proc_handler = proc_dolongvec_minmax_bpf_restricted, | ||
3505 | + .extra1 = &long_one, | ||
3506 | + .extra2 = &long_max, | ||
3507 | + }, | ||
3508 | #endif | ||
3509 | { | ||
3510 | .procname = "netdev_tstamp_prequeue", | ||
3511 | diff --git a/net/ipv4/route.c b/net/ipv4/route.c | ||
3512 | index 02c49857b5a7..d558dc076577 100644 | ||
3513 | --- a/net/ipv4/route.c | ||
3514 | +++ b/net/ipv4/route.c | ||
3515 | @@ -496,15 +496,17 @@ EXPORT_SYMBOL(ip_idents_reserve); | ||
3516 | |||
3517 | void __ip_select_ident(struct net *net, struct iphdr *iph, int segs) | ||
3518 | { | ||
3519 | - static u32 ip_idents_hashrnd __read_mostly; | ||
3520 | u32 hash, id; | ||
3521 | |||
3522 | - net_get_random_once(&ip_idents_hashrnd, sizeof(ip_idents_hashrnd)); | ||
3523 | + /* Note the following code is not safe, but this is okay. */ | ||
3524 | + if (unlikely(siphash_key_is_zero(&net->ipv4.ip_id_key))) | ||
3525 | + get_random_bytes(&net->ipv4.ip_id_key, | ||
3526 | + sizeof(net->ipv4.ip_id_key)); | ||
3527 | |||
3528 | - hash = jhash_3words((__force u32)iph->daddr, | ||
3529 | + hash = siphash_3u32((__force u32)iph->daddr, | ||
3530 | (__force u32)iph->saddr, | ||
3531 | - iph->protocol ^ net_hash_mix(net), | ||
3532 | - ip_idents_hashrnd); | ||
3533 | + iph->protocol, | ||
3534 | + &net->ipv4.ip_id_key); | ||
3535 | id = ip_idents_reserve(hash, segs); | ||
3536 | iph->id = htons(id); | ||
3537 | } | ||
3538 | diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c | ||
3539 | index a338bbc33cf3..6a6d01cb1ace 100644 | ||
3540 | --- a/net/ipv6/output_core.c | ||
3541 | +++ b/net/ipv6/output_core.c | ||
3542 | @@ -10,15 +10,25 @@ | ||
3543 | #include <net/secure_seq.h> | ||
3544 | #include <linux/netfilter.h> | ||
3545 | |||
3546 | -static u32 __ipv6_select_ident(struct net *net, u32 hashrnd, | ||
3547 | +static u32 __ipv6_select_ident(struct net *net, | ||
3548 | const struct in6_addr *dst, | ||
3549 | const struct in6_addr *src) | ||
3550 | { | ||
3551 | + const struct { | ||
3552 | + struct in6_addr dst; | ||
3553 | + struct in6_addr src; | ||
3554 | + } __aligned(SIPHASH_ALIGNMENT) combined = { | ||
3555 | + .dst = *dst, | ||
3556 | + .src = *src, | ||
3557 | + }; | ||
3558 | u32 hash, id; | ||
3559 | |||
3560 | - hash = __ipv6_addr_jhash(dst, hashrnd); | ||
3561 | - hash = __ipv6_addr_jhash(src, hash); | ||
3562 | - hash ^= net_hash_mix(net); | ||
3563 | + /* Note the following code is not safe, but this is okay. */ | ||
3564 | + if (unlikely(siphash_key_is_zero(&net->ipv4.ip_id_key))) | ||
3565 | + get_random_bytes(&net->ipv4.ip_id_key, | ||
3566 | + sizeof(net->ipv4.ip_id_key)); | ||
3567 | + | ||
3568 | + hash = siphash(&combined, sizeof(combined), &net->ipv4.ip_id_key); | ||
3569 | |||
3570 | /* Treat id of 0 as unset and if we get 0 back from ip_idents_reserve, | ||
3571 | * set the hight order instead thus minimizing possible future | ||
3572 | @@ -41,7 +51,6 @@ static u32 __ipv6_select_ident(struct net *net, u32 hashrnd, | ||
3573 | */ | ||
3574 | void ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb) | ||
3575 | { | ||
3576 | - static u32 ip6_proxy_idents_hashrnd __read_mostly; | ||
3577 | struct in6_addr buf[2]; | ||
3578 | struct in6_addr *addrs; | ||
3579 | u32 id; | ||
3580 | @@ -53,11 +62,7 @@ void ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb) | ||
3581 | if (!addrs) | ||
3582 | return; | ||
3583 | |||
3584 | - net_get_random_once(&ip6_proxy_idents_hashrnd, | ||
3585 | - sizeof(ip6_proxy_idents_hashrnd)); | ||
3586 | - | ||
3587 | - id = __ipv6_select_ident(net, ip6_proxy_idents_hashrnd, | ||
3588 | - &addrs[1], &addrs[0]); | ||
3589 | + id = __ipv6_select_ident(net, &addrs[1], &addrs[0]); | ||
3590 | skb_shinfo(skb)->ip6_frag_id = htonl(id); | ||
3591 | } | ||
3592 | EXPORT_SYMBOL_GPL(ipv6_proxy_select_ident); | ||
3593 | @@ -66,12 +71,9 @@ __be32 ipv6_select_ident(struct net *net, | ||
3594 | const struct in6_addr *daddr, | ||
3595 | const struct in6_addr *saddr) | ||
3596 | { | ||
3597 | - static u32 ip6_idents_hashrnd __read_mostly; | ||
3598 | u32 id; | ||
3599 | |||
3600 | - net_get_random_once(&ip6_idents_hashrnd, sizeof(ip6_idents_hashrnd)); | ||
3601 | - | ||
3602 | - id = __ipv6_select_ident(net, ip6_idents_hashrnd, daddr, saddr); | ||
3603 | + id = __ipv6_select_ident(net, daddr, saddr); | ||
3604 | return htonl(id); | ||
3605 | } | ||
3606 | EXPORT_SYMBOL(ipv6_select_ident); | ||
3607 | diff --git a/net/mac80211/driver-ops.c b/net/mac80211/driver-ops.c | ||
3608 | index bb886e7db47f..f783d1377d9a 100644 | ||
3609 | --- a/net/mac80211/driver-ops.c | ||
3610 | +++ b/net/mac80211/driver-ops.c | ||
3611 | @@ -169,11 +169,16 @@ int drv_conf_tx(struct ieee80211_local *local, | ||
3612 | if (!check_sdata_in_driver(sdata)) | ||
3613 | return -EIO; | ||
3614 | |||
3615 | - if (WARN_ONCE(params->cw_min == 0 || | ||
3616 | - params->cw_min > params->cw_max, | ||
3617 | - "%s: invalid CW_min/CW_max: %d/%d\n", | ||
3618 | - sdata->name, params->cw_min, params->cw_max)) | ||
3619 | + if (params->cw_min == 0 || params->cw_min > params->cw_max) { | ||
3620 | + /* | ||
3621 | + * If we can't configure hardware anyway, don't warn. We may | ||
3622 | + * never have initialized the CW parameters. | ||
3623 | + */ | ||
3624 | + WARN_ONCE(local->ops->conf_tx, | ||
3625 | + "%s: invalid CW_min/CW_max: %d/%d\n", | ||
3626 | + sdata->name, params->cw_min, params->cw_max); | ||
3627 | return -EINVAL; | ||
3628 | + } | ||
3629 | |||
3630 | trace_drv_conf_tx(local, sdata, ac, params); | ||
3631 | if (local->ops->conf_tx) | ||
3632 | diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c | ||
3633 | index d787717140e5..f462f026fc6a 100644 | ||
3634 | --- a/net/mac80211/mlme.c | ||
3635 | +++ b/net/mac80211/mlme.c | ||
3636 | @@ -1873,6 +1873,16 @@ static bool ieee80211_sta_wmm_params(struct ieee80211_local *local, | ||
3637 | } | ||
3638 | } | ||
3639 | |||
3640 | + /* WMM specification requires all 4 ACIs. */ | ||
3641 | + for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { | ||
3642 | + if (params[ac].cw_min == 0) { | ||
3643 | + sdata_info(sdata, | ||
3644 | + "AP has invalid WMM params (missing AC %d), using defaults\n", | ||
3645 | + ac); | ||
3646 | + return false; | ||
3647 | + } | ||
3648 | + } | ||
3649 | + | ||
3650 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { | ||
3651 | mlme_dbg(sdata, | ||
3652 | "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n", | ||
3653 | diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c | ||
3654 | index df1d5618b008..1bdae8f188e1 100644 | ||
3655 | --- a/net/netfilter/nf_conntrack_core.c | ||
3656 | +++ b/net/netfilter/nf_conntrack_core.c | ||
3657 | @@ -25,6 +25,7 @@ | ||
3658 | #include <linux/slab.h> | ||
3659 | #include <linux/random.h> | ||
3660 | #include <linux/jhash.h> | ||
3661 | +#include <linux/siphash.h> | ||
3662 | #include <linux/err.h> | ||
3663 | #include <linux/percpu.h> | ||
3664 | #include <linux/moduleparam.h> | ||
3665 | @@ -301,6 +302,40 @@ nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse, | ||
3666 | } | ||
3667 | EXPORT_SYMBOL_GPL(nf_ct_invert_tuple); | ||
3668 | |||
3669 | +/* Generate a almost-unique pseudo-id for a given conntrack. | ||
3670 | + * | ||
3671 | + * intentionally doesn't re-use any of the seeds used for hash | ||
3672 | + * table location, we assume id gets exposed to userspace. | ||
3673 | + * | ||
3674 | + * Following nf_conn items do not change throughout lifetime | ||
3675 | + * of the nf_conn: | ||
3676 | + * | ||
3677 | + * 1. nf_conn address | ||
3678 | + * 2. nf_conn->master address (normally NULL) | ||
3679 | + * 3. the associated net namespace | ||
3680 | + * 4. the original direction tuple | ||
3681 | + */ | ||
3682 | +u32 nf_ct_get_id(const struct nf_conn *ct) | ||
3683 | +{ | ||
3684 | + static __read_mostly siphash_key_t ct_id_seed; | ||
3685 | + unsigned long a, b, c, d; | ||
3686 | + | ||
3687 | + net_get_random_once(&ct_id_seed, sizeof(ct_id_seed)); | ||
3688 | + | ||
3689 | + a = (unsigned long)ct; | ||
3690 | + b = (unsigned long)ct->master; | ||
3691 | + c = (unsigned long)nf_ct_net(ct); | ||
3692 | + d = (unsigned long)siphash(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, | ||
3693 | + sizeof(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple), | ||
3694 | + &ct_id_seed); | ||
3695 | +#ifdef CONFIG_64BIT | ||
3696 | + return siphash_4u64((u64)a, (u64)b, (u64)c, (u64)d, &ct_id_seed); | ||
3697 | +#else | ||
3698 | + return siphash_4u32((u32)a, (u32)b, (u32)c, (u32)d, &ct_id_seed); | ||
3699 | +#endif | ||
3700 | +} | ||
3701 | +EXPORT_SYMBOL_GPL(nf_ct_get_id); | ||
3702 | + | ||
3703 | static void | ||
3704 | clean_from_lists(struct nf_conn *ct) | ||
3705 | { | ||
3706 | diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c | ||
3707 | index 9e30fd0ab227..deea281ab169 100644 | ||
3708 | --- a/net/netfilter/nf_conntrack_netlink.c | ||
3709 | +++ b/net/netfilter/nf_conntrack_netlink.c | ||
3710 | @@ -29,6 +29,7 @@ | ||
3711 | #include <linux/spinlock.h> | ||
3712 | #include <linux/interrupt.h> | ||
3713 | #include <linux/slab.h> | ||
3714 | +#include <linux/siphash.h> | ||
3715 | |||
3716 | #include <linux/netfilter.h> | ||
3717 | #include <net/netlink.h> | ||
3718 | @@ -441,7 +442,9 @@ static int ctnetlink_dump_ct_seq_adj(struct sk_buff *skb, | ||
3719 | |||
3720 | static int ctnetlink_dump_id(struct sk_buff *skb, const struct nf_conn *ct) | ||
3721 | { | ||
3722 | - if (nla_put_be32(skb, CTA_ID, htonl((unsigned long)ct))) | ||
3723 | + __be32 id = (__force __be32)nf_ct_get_id(ct); | ||
3724 | + | ||
3725 | + if (nla_put_be32(skb, CTA_ID, id)) | ||
3726 | goto nla_put_failure; | ||
3727 | return 0; | ||
3728 | |||
3729 | @@ -1166,8 +1169,9 @@ static int ctnetlink_del_conntrack(struct net *net, struct sock *ctnl, | ||
3730 | ct = nf_ct_tuplehash_to_ctrack(h); | ||
3731 | |||
3732 | if (cda[CTA_ID]) { | ||
3733 | - u_int32_t id = ntohl(nla_get_be32(cda[CTA_ID])); | ||
3734 | - if (id != (u32)(unsigned long)ct) { | ||
3735 | + __be32 id = nla_get_be32(cda[CTA_ID]); | ||
3736 | + | ||
3737 | + if (id != (__force __be32)nf_ct_get_id(ct)) { | ||
3738 | nf_ct_put(ct); | ||
3739 | return -ENOENT; | ||
3740 | } | ||
3741 | @@ -2472,6 +2476,25 @@ nla_put_failure: | ||
3742 | |||
3743 | static const union nf_inet_addr any_addr; | ||
3744 | |||
3745 | +static __be32 nf_expect_get_id(const struct nf_conntrack_expect *exp) | ||
3746 | +{ | ||
3747 | + static __read_mostly siphash_key_t exp_id_seed; | ||
3748 | + unsigned long a, b, c, d; | ||
3749 | + | ||
3750 | + net_get_random_once(&exp_id_seed, sizeof(exp_id_seed)); | ||
3751 | + | ||
3752 | + a = (unsigned long)exp; | ||
3753 | + b = (unsigned long)exp->helper; | ||
3754 | + c = (unsigned long)exp->master; | ||
3755 | + d = (unsigned long)siphash(&exp->tuple, sizeof(exp->tuple), &exp_id_seed); | ||
3756 | + | ||
3757 | +#ifdef CONFIG_64BIT | ||
3758 | + return (__force __be32)siphash_4u64((u64)a, (u64)b, (u64)c, (u64)d, &exp_id_seed); | ||
3759 | +#else | ||
3760 | + return (__force __be32)siphash_4u32((u32)a, (u32)b, (u32)c, (u32)d, &exp_id_seed); | ||
3761 | +#endif | ||
3762 | +} | ||
3763 | + | ||
3764 | static int | ||
3765 | ctnetlink_exp_dump_expect(struct sk_buff *skb, | ||
3766 | const struct nf_conntrack_expect *exp) | ||
3767 | @@ -2519,7 +2542,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb, | ||
3768 | } | ||
3769 | #endif | ||
3770 | if (nla_put_be32(skb, CTA_EXPECT_TIMEOUT, htonl(timeout)) || | ||
3771 | - nla_put_be32(skb, CTA_EXPECT_ID, htonl((unsigned long)exp)) || | ||
3772 | + nla_put_be32(skb, CTA_EXPECT_ID, nf_expect_get_id(exp)) || | ||
3773 | nla_put_be32(skb, CTA_EXPECT_FLAGS, htonl(exp->flags)) || | ||
3774 | nla_put_be32(skb, CTA_EXPECT_CLASS, htonl(exp->class))) | ||
3775 | goto nla_put_failure; | ||
3776 | @@ -2818,7 +2841,8 @@ static int ctnetlink_get_expect(struct net *net, struct sock *ctnl, | ||
3777 | |||
3778 | if (cda[CTA_EXPECT_ID]) { | ||
3779 | __be32 id = nla_get_be32(cda[CTA_EXPECT_ID]); | ||
3780 | - if (ntohl(id) != (u32)(unsigned long)exp) { | ||
3781 | + | ||
3782 | + if (id != nf_expect_get_id(exp)) { | ||
3783 | nf_ct_expect_put(exp); | ||
3784 | return -ENOENT; | ||
3785 | } | ||
3786 | diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c | ||
3787 | index 2278d9ab723b..9837a61cb3e3 100644 | ||
3788 | --- a/net/netfilter/nfnetlink.c | ||
3789 | +++ b/net/netfilter/nfnetlink.c | ||
3790 | @@ -490,7 +490,7 @@ static int nfnetlink_bind(struct net *net, int group) | ||
3791 | ss = nfnetlink_get_subsys(type << 8); | ||
3792 | rcu_read_unlock(); | ||
3793 | if (!ss) | ||
3794 | - request_module("nfnetlink-subsys-%d", type); | ||
3795 | + request_module_nowait("nfnetlink-subsys-%d", type); | ||
3796 | return 0; | ||
3797 | } | ||
3798 | #endif | ||
3799 | diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c | ||
3800 | index 3578121da79c..b1dbea544d64 100644 | ||
3801 | --- a/net/packet/af_packet.c | ||
3802 | +++ b/net/packet/af_packet.c | ||
3803 | @@ -2651,6 +2651,13 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) | ||
3804 | |||
3805 | mutex_lock(&po->pg_vec_lock); | ||
3806 | |||
3807 | + /* packet_sendmsg() check on tx_ring.pg_vec was lockless, | ||
3808 | + * we need to confirm it under protection of pg_vec_lock. | ||
3809 | + */ | ||
3810 | + if (unlikely(!po->tx_ring.pg_vec)) { | ||
3811 | + err = -EBUSY; | ||
3812 | + goto out; | ||
3813 | + } | ||
3814 | if (likely(saddr == NULL)) { | ||
3815 | dev = packet_cached_dev_get(po); | ||
3816 | proto = po->num; | ||
3817 | diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c | ||
3818 | index c345bf153bed..b1ead1776e81 100644 | ||
3819 | --- a/net/sctp/sm_sideeffect.c | ||
3820 | +++ b/net/sctp/sm_sideeffect.c | ||
3821 | @@ -508,7 +508,7 @@ static void sctp_do_8_2_transport_strike(sctp_cmd_seq_t *commands, | ||
3822 | */ | ||
3823 | if (net->sctp.pf_enable && | ||
3824 | (transport->state == SCTP_ACTIVE) && | ||
3825 | - (asoc->pf_retrans < transport->pathmaxrxt) && | ||
3826 | + (transport->error_count < transport->pathmaxrxt) && | ||
3827 | (transport->error_count > asoc->pf_retrans)) { | ||
3828 | |||
3829 | sctp_assoc_control_transport(asoc, transport, | ||
3830 | diff --git a/net/socket.c b/net/socket.c | ||
3831 | index d9e2989c10c4..bf99bc1fab2c 100644 | ||
3832 | --- a/net/socket.c | ||
3833 | +++ b/net/socket.c | ||
3834 | @@ -2550,15 +2550,6 @@ out_fs: | ||
3835 | |||
3836 | core_initcall(sock_init); /* early initcall */ | ||
3837 | |||
3838 | -static int __init jit_init(void) | ||
3839 | -{ | ||
3840 | -#ifdef CONFIG_BPF_JIT_ALWAYS_ON | ||
3841 | - bpf_jit_enable = 1; | ||
3842 | -#endif | ||
3843 | - return 0; | ||
3844 | -} | ||
3845 | -pure_initcall(jit_init); | ||
3846 | - | ||
3847 | #ifdef CONFIG_PROC_FS | ||
3848 | void socket_seq_show(struct seq_file *seq) | ||
3849 | { | ||
3850 | diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost | ||
3851 | index 16923ba4b5b1..8cb7971b3f25 100644 | ||
3852 | --- a/scripts/Makefile.modpost | ||
3853 | +++ b/scripts/Makefile.modpost | ||
3854 | @@ -74,7 +74,7 @@ modpost = scripts/mod/modpost \ | ||
3855 | $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a,) \ | ||
3856 | $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \ | ||
3857 | $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \ | ||
3858 | - $(if $(KBUILD_EXTRA_SYMBOLS), $(patsubst %, -e %,$(KBUILD_EXTRA_SYMBOLS))) \ | ||
3859 | + $(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS))) \ | ||
3860 | $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ | ||
3861 | $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \ | ||
3862 | $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ | ||
3863 | diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c | ||
3864 | index 555df64d46ff..2e2d18468491 100644 | ||
3865 | --- a/sound/core/compress_offload.c | ||
3866 | +++ b/sound/core/compress_offload.c | ||
3867 | @@ -575,10 +575,7 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) | ||
3868 | stream->metadata_set = false; | ||
3869 | stream->next_track = false; | ||
3870 | |||
3871 | - if (stream->direction == SND_COMPRESS_PLAYBACK) | ||
3872 | - stream->runtime->state = SNDRV_PCM_STATE_SETUP; | ||
3873 | - else | ||
3874 | - stream->runtime->state = SNDRV_PCM_STATE_PREPARED; | ||
3875 | + stream->runtime->state = SNDRV_PCM_STATE_SETUP; | ||
3876 | } else { | ||
3877 | return -EPERM; | ||
3878 | } | ||
3879 | @@ -694,8 +691,17 @@ static int snd_compr_start(struct snd_compr_stream *stream) | ||
3880 | { | ||
3881 | int retval; | ||
3882 | |||
3883 | - if (stream->runtime->state != SNDRV_PCM_STATE_PREPARED) | ||
3884 | + switch (stream->runtime->state) { | ||
3885 | + case SNDRV_PCM_STATE_SETUP: | ||
3886 | + if (stream->direction != SND_COMPRESS_CAPTURE) | ||
3887 | + return -EPERM; | ||
3888 | + break; | ||
3889 | + case SNDRV_PCM_STATE_PREPARED: | ||
3890 | + break; | ||
3891 | + default: | ||
3892 | return -EPERM; | ||
3893 | + } | ||
3894 | + | ||
3895 | retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_START); | ||
3896 | if (!retval) | ||
3897 | stream->runtime->state = SNDRV_PCM_STATE_RUNNING; | ||
3898 | @@ -706,9 +712,15 @@ static int snd_compr_stop(struct snd_compr_stream *stream) | ||
3899 | { | ||
3900 | int retval; | ||
3901 | |||
3902 | - if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED || | ||
3903 | - stream->runtime->state == SNDRV_PCM_STATE_SETUP) | ||
3904 | + switch (stream->runtime->state) { | ||
3905 | + case SNDRV_PCM_STATE_OPEN: | ||
3906 | + case SNDRV_PCM_STATE_SETUP: | ||
3907 | + case SNDRV_PCM_STATE_PREPARED: | ||
3908 | return -EPERM; | ||
3909 | + default: | ||
3910 | + break; | ||
3911 | + } | ||
3912 | + | ||
3913 | retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); | ||
3914 | if (!retval) { | ||
3915 | snd_compr_drain_notify(stream); | ||
3916 | @@ -796,9 +808,17 @@ static int snd_compr_drain(struct snd_compr_stream *stream) | ||
3917 | { | ||
3918 | int retval; | ||
3919 | |||
3920 | - if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED || | ||
3921 | - stream->runtime->state == SNDRV_PCM_STATE_SETUP) | ||
3922 | + switch (stream->runtime->state) { | ||
3923 | + case SNDRV_PCM_STATE_OPEN: | ||
3924 | + case SNDRV_PCM_STATE_SETUP: | ||
3925 | + case SNDRV_PCM_STATE_PREPARED: | ||
3926 | + case SNDRV_PCM_STATE_PAUSED: | ||
3927 | return -EPERM; | ||
3928 | + case SNDRV_PCM_STATE_XRUN: | ||
3929 | + return -EPIPE; | ||
3930 | + default: | ||
3931 | + break; | ||
3932 | + } | ||
3933 | |||
3934 | retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN); | ||
3935 | if (retval) { | ||
3936 | @@ -818,6 +838,10 @@ static int snd_compr_next_track(struct snd_compr_stream *stream) | ||
3937 | if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) | ||
3938 | return -EPERM; | ||
3939 | |||
3940 | + /* next track doesn't have any meaning for capture streams */ | ||
3941 | + if (stream->direction == SND_COMPRESS_CAPTURE) | ||
3942 | + return -EPERM; | ||
3943 | + | ||
3944 | /* you can signal next track if this is intended to be a gapless stream | ||
3945 | * and current track metadata is set | ||
3946 | */ | ||
3947 | @@ -835,9 +859,23 @@ static int snd_compr_next_track(struct snd_compr_stream *stream) | ||
3948 | static int snd_compr_partial_drain(struct snd_compr_stream *stream) | ||
3949 | { | ||
3950 | int retval; | ||
3951 | - if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED || | ||
3952 | - stream->runtime->state == SNDRV_PCM_STATE_SETUP) | ||
3953 | + | ||
3954 | + switch (stream->runtime->state) { | ||
3955 | + case SNDRV_PCM_STATE_OPEN: | ||
3956 | + case SNDRV_PCM_STATE_SETUP: | ||
3957 | + case SNDRV_PCM_STATE_PREPARED: | ||
3958 | + case SNDRV_PCM_STATE_PAUSED: | ||
3959 | + return -EPERM; | ||
3960 | + case SNDRV_PCM_STATE_XRUN: | ||
3961 | + return -EPIPE; | ||
3962 | + default: | ||
3963 | + break; | ||
3964 | + } | ||
3965 | + | ||
3966 | + /* partial drain doesn't have any meaning for capture streams */ | ||
3967 | + if (stream->direction == SND_COMPRESS_CAPTURE) | ||
3968 | return -EPERM; | ||
3969 | + | ||
3970 | /* stream can be drained only when next track has been signalled */ | ||
3971 | if (stream->next_track == false) | ||
3972 | return -EPERM; | ||
3973 | diff --git a/sound/firewire/packets-buffer.c b/sound/firewire/packets-buffer.c | ||
3974 | index ea1506679c66..3b09b8ef3a09 100644 | ||
3975 | --- a/sound/firewire/packets-buffer.c | ||
3976 | +++ b/sound/firewire/packets-buffer.c | ||
3977 | @@ -37,7 +37,7 @@ int iso_packets_buffer_init(struct iso_packets_buffer *b, struct fw_unit *unit, | ||
3978 | packets_per_page = PAGE_SIZE / packet_size; | ||
3979 | if (WARN_ON(!packets_per_page)) { | ||
3980 | err = -EINVAL; | ||
3981 | - goto error; | ||
3982 | + goto err_packets; | ||
3983 | } | ||
3984 | pages = DIV_ROUND_UP(count, packets_per_page); | ||
3985 | |||
3986 | diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c | ||
3987 | index 56af7308a2fd..85dbe2420248 100644 | ||
3988 | --- a/sound/pci/hda/hda_controller.c | ||
3989 | +++ b/sound/pci/hda/hda_controller.c | ||
3990 | @@ -609,11 +609,9 @@ static int azx_pcm_open(struct snd_pcm_substream *substream) | ||
3991 | } | ||
3992 | runtime->private_data = azx_dev; | ||
3993 | |||
3994 | - if (chip->gts_present) | ||
3995 | - azx_pcm_hw.info = azx_pcm_hw.info | | ||
3996 | - SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME; | ||
3997 | - | ||
3998 | runtime->hw = azx_pcm_hw; | ||
3999 | + if (chip->gts_present) | ||
4000 | + runtime->hw.info |= SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME; | ||
4001 | runtime->hw.channels_min = hinfo->channels_min; | ||
4002 | runtime->hw.channels_max = hinfo->channels_max; | ||
4003 | runtime->hw.formats = hinfo->formats; | ||
4004 | diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c | ||
4005 | index b0bd29003b5d..98594cbe34c8 100644 | ||
4006 | --- a/sound/pci/hda/hda_generic.c | ||
4007 | +++ b/sound/pci/hda/hda_generic.c | ||
4008 | @@ -5849,6 +5849,24 @@ void snd_hda_gen_free(struct hda_codec *codec) | ||
4009 | } | ||
4010 | EXPORT_SYMBOL_GPL(snd_hda_gen_free); | ||
4011 | |||
4012 | +/** | ||
4013 | + * snd_hda_gen_reboot_notify - Make codec enter D3 before rebooting | ||
4014 | + * @codec: the HDA codec | ||
4015 | + * | ||
4016 | + * This can be put as patch_ops reboot_notify function. | ||
4017 | + */ | ||
4018 | +void snd_hda_gen_reboot_notify(struct hda_codec *codec) | ||
4019 | +{ | ||
4020 | + /* Make the codec enter D3 to avoid spurious noises from the internal | ||
4021 | + * speaker during (and after) reboot | ||
4022 | + */ | ||
4023 | + snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3); | ||
4024 | + snd_hda_codec_write(codec, codec->core.afg, 0, | ||
4025 | + AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | ||
4026 | + msleep(10); | ||
4027 | +} | ||
4028 | +EXPORT_SYMBOL_GPL(snd_hda_gen_reboot_notify); | ||
4029 | + | ||
4030 | #ifdef CONFIG_PM | ||
4031 | /** | ||
4032 | * snd_hda_gen_check_power_status - check the loopback power save state | ||
4033 | @@ -5876,6 +5894,7 @@ static const struct hda_codec_ops generic_patch_ops = { | ||
4034 | .init = snd_hda_gen_init, | ||
4035 | .free = snd_hda_gen_free, | ||
4036 | .unsol_event = snd_hda_jack_unsol_event, | ||
4037 | + .reboot_notify = snd_hda_gen_reboot_notify, | ||
4038 | #ifdef CONFIG_PM | ||
4039 | .check_power_status = snd_hda_gen_check_power_status, | ||
4040 | #endif | ||
4041 | @@ -5898,7 +5917,7 @@ static int snd_hda_parse_generic_codec(struct hda_codec *codec) | ||
4042 | |||
4043 | err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0); | ||
4044 | if (err < 0) | ||
4045 | - return err; | ||
4046 | + goto error; | ||
4047 | |||
4048 | err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg); | ||
4049 | if (err < 0) | ||
4050 | diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h | ||
4051 | index f66fc7e25e07..932b533feb48 100644 | ||
4052 | --- a/sound/pci/hda/hda_generic.h | ||
4053 | +++ b/sound/pci/hda/hda_generic.h | ||
4054 | @@ -322,6 +322,7 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec, | ||
4055 | struct auto_pin_cfg *cfg); | ||
4056 | int snd_hda_gen_build_controls(struct hda_codec *codec); | ||
4057 | int snd_hda_gen_build_pcms(struct hda_codec *codec); | ||
4058 | +void snd_hda_gen_reboot_notify(struct hda_codec *codec); | ||
4059 | |||
4060 | /* standard jack event callbacks */ | ||
4061 | void snd_hda_gen_hp_automute(struct hda_codec *codec, | ||
4062 | diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c | ||
4063 | index df66969b124d..8557b94e462c 100644 | ||
4064 | --- a/sound/pci/hda/patch_conexant.c | ||
4065 | +++ b/sound/pci/hda/patch_conexant.c | ||
4066 | @@ -204,23 +204,10 @@ static void cx_auto_reboot_notify(struct hda_codec *codec) | ||
4067 | { | ||
4068 | struct conexant_spec *spec = codec->spec; | ||
4069 | |||
4070 | - switch (codec->core.vendor_id) { | ||
4071 | - case 0x14f12008: /* CX8200 */ | ||
4072 | - case 0x14f150f2: /* CX20722 */ | ||
4073 | - case 0x14f150f4: /* CX20724 */ | ||
4074 | - break; | ||
4075 | - default: | ||
4076 | - return; | ||
4077 | - } | ||
4078 | - | ||
4079 | /* Turn the problematic codec into D3 to avoid spurious noises | ||
4080 | from the internal speaker during (and after) reboot */ | ||
4081 | cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, false); | ||
4082 | - | ||
4083 | - snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3); | ||
4084 | - snd_hda_codec_write(codec, codec->core.afg, 0, | ||
4085 | - AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | ||
4086 | - msleep(10); | ||
4087 | + snd_hda_gen_reboot_notify(codec); | ||
4088 | } | ||
4089 | |||
4090 | static void cx_auto_free(struct hda_codec *codec) | ||
4091 | diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c | ||
4092 | index 04d2dc7097a1..8e995fb27312 100644 | ||
4093 | --- a/sound/pci/hda/patch_realtek.c | ||
4094 | +++ b/sound/pci/hda/patch_realtek.c | ||
4095 | @@ -802,15 +802,6 @@ static void alc_reboot_notify(struct hda_codec *codec) | ||
4096 | alc_shutup(codec); | ||
4097 | } | ||
4098 | |||
4099 | -/* power down codec to D3 at reboot/shutdown; set as reboot_notify ops */ | ||
4100 | -static void alc_d3_at_reboot(struct hda_codec *codec) | ||
4101 | -{ | ||
4102 | - snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3); | ||
4103 | - snd_hda_codec_write(codec, codec->core.afg, 0, | ||
4104 | - AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | ||
4105 | - msleep(10); | ||
4106 | -} | ||
4107 | - | ||
4108 | #define alc_free snd_hda_gen_free | ||
4109 | |||
4110 | #ifdef CONFIG_PM | ||
4111 | @@ -4473,7 +4464,7 @@ static void alc_fixup_tpt440_dock(struct hda_codec *codec, | ||
4112 | struct alc_spec *spec = codec->spec; | ||
4113 | |||
4114 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { | ||
4115 | - spec->reboot_notify = alc_d3_at_reboot; /* reduce noise */ | ||
4116 | + spec->reboot_notify = snd_hda_gen_reboot_notify; /* reduce noise */ | ||
4117 | spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; | ||
4118 | codec->power_save_node = 0; /* avoid click noises */ | ||
4119 | snd_hda_apply_pincfgs(codec, pincfgs); | ||
4120 | diff --git a/sound/sound_core.c b/sound/sound_core.c | ||
4121 | index 99b73c675743..20d4e2e1bacf 100644 | ||
4122 | --- a/sound/sound_core.c | ||
4123 | +++ b/sound/sound_core.c | ||
4124 | @@ -287,7 +287,8 @@ retry: | ||
4125 | goto retry; | ||
4126 | } | ||
4127 | spin_unlock(&sound_loader_lock); | ||
4128 | - return -EBUSY; | ||
4129 | + r = -EBUSY; | ||
4130 | + goto fail; | ||
4131 | } | ||
4132 | } | ||
4133 | |||
4134 | diff --git a/tools/perf/arch/s390/util/machine.c b/tools/perf/arch/s390/util/machine.c | ||
4135 | index d3d1452021d4..f4f8aff8a9bb 100644 | ||
4136 | --- a/tools/perf/arch/s390/util/machine.c | ||
4137 | +++ b/tools/perf/arch/s390/util/machine.c | ||
4138 | @@ -6,7 +6,7 @@ | ||
4139 | #include "api/fs/fs.h" | ||
4140 | #include "debug.h" | ||
4141 | |||
4142 | -int arch__fix_module_text_start(u64 *start, const char *name) | ||
4143 | +int arch__fix_module_text_start(u64 *start, u64 *size, const char *name) | ||
4144 | { | ||
4145 | u64 m_start = *start; | ||
4146 | char path[PATH_MAX]; | ||
4147 | @@ -16,6 +16,18 @@ int arch__fix_module_text_start(u64 *start, const char *name) | ||
4148 | if (sysfs__read_ull(path, (unsigned long long *)start) < 0) { | ||
4149 | pr_debug2("Using module %s start:%#lx\n", path, m_start); | ||
4150 | *start = m_start; | ||
4151 | + } else { | ||
4152 | + /* Successful read of the modules segment text start address. | ||
4153 | + * Calculate difference between module start address | ||
4154 | + * in memory and module text segment start address. | ||
4155 | + * For example module load address is 0x3ff8011b000 | ||
4156 | + * (from /proc/modules) and module text segment start | ||
4157 | + * address is 0x3ff8011b870 (from file above). | ||
4158 | + * | ||
4159 | + * Adjust the module size and subtract the GOT table | ||
4160 | + * size located at the beginning of the module. | ||
4161 | + */ | ||
4162 | + *size -= (*start - m_start); | ||
4163 | } | ||
4164 | |||
4165 | return 0; | ||
4166 | diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c | ||
4167 | index 9a250c71840e..2b420e7a92c0 100644 | ||
4168 | --- a/tools/perf/builtin-probe.c | ||
4169 | +++ b/tools/perf/builtin-probe.c | ||
4170 | @@ -675,6 +675,16 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) | ||
4171 | |||
4172 | ret = perf_add_probe_events(params.events, params.nevents); | ||
4173 | if (ret < 0) { | ||
4174 | + | ||
4175 | + /* | ||
4176 | + * When perf_add_probe_events() fails it calls | ||
4177 | + * cleanup_perf_probe_events(pevs, npevs), i.e. | ||
4178 | + * cleanup_perf_probe_events(params.events, params.nevents), which | ||
4179 | + * will call clear_perf_probe_event(), so set nevents to zero | ||
4180 | + * to avoid cleanup_params() to call clear_perf_probe_event() again | ||
4181 | + * on the same pevs. | ||
4182 | + */ | ||
4183 | + params.nevents = 0; | ||
4184 | pr_err_with_code(" Error: Failed to add events.", ret); | ||
4185 | return ret; | ||
4186 | } | ||
4187 | diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c | ||
4188 | index 283148104ffb..258b19b251a8 100644 | ||
4189 | --- a/tools/perf/util/header.c | ||
4190 | +++ b/tools/perf/util/header.c | ||
4191 | @@ -2854,6 +2854,13 @@ int perf_session__read_header(struct perf_session *session) | ||
4192 | file->path); | ||
4193 | } | ||
4194 | |||
4195 | + if (f_header.attr_size == 0) { | ||
4196 | + pr_err("ERROR: The %s file's attr size field is 0 which is unexpected.\n" | ||
4197 | + "Was the 'perf record' command properly terminated?\n", | ||
4198 | + file->path); | ||
4199 | + return -EINVAL; | ||
4200 | + } | ||
4201 | + | ||
4202 | nr_attrs = f_header.attrs.size / f_header.attr_size; | ||
4203 | lseek(fd, f_header.attrs.offset, SEEK_SET); | ||
4204 | |||
4205 | @@ -2936,7 +2943,7 @@ int perf_event__synthesize_attr(struct perf_tool *tool, | ||
4206 | size += sizeof(struct perf_event_header); | ||
4207 | size += ids * sizeof(u64); | ||
4208 | |||
4209 | - ev = malloc(size); | ||
4210 | + ev = zalloc(size); | ||
4211 | |||
4212 | if (ev == NULL) | ||
4213 | return -ENOMEM; | ||
4214 | diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c | ||
4215 | index df85b9efd80f..45ea7a8cd818 100644 | ||
4216 | --- a/tools/perf/util/machine.c | ||
4217 | +++ b/tools/perf/util/machine.c | ||
4218 | @@ -1074,22 +1074,25 @@ static int machine__set_modules_path(struct machine *machine) | ||
4219 | return map_groups__set_modules_path_dir(&machine->kmaps, modules_path, 0); | ||
4220 | } | ||
4221 | int __weak arch__fix_module_text_start(u64 *start __maybe_unused, | ||
4222 | + u64 *size __maybe_unused, | ||
4223 | const char *name __maybe_unused) | ||
4224 | { | ||
4225 | return 0; | ||
4226 | } | ||
4227 | |||
4228 | -static int machine__create_module(void *arg, const char *name, u64 start) | ||
4229 | +static int machine__create_module(void *arg, const char *name, u64 start, | ||
4230 | + u64 size) | ||
4231 | { | ||
4232 | struct machine *machine = arg; | ||
4233 | struct map *map; | ||
4234 | |||
4235 | - if (arch__fix_module_text_start(&start, name) < 0) | ||
4236 | + if (arch__fix_module_text_start(&start, &size, name) < 0) | ||
4237 | return -1; | ||
4238 | |||
4239 | map = machine__findnew_module_map(machine, start, name); | ||
4240 | if (map == NULL) | ||
4241 | return -1; | ||
4242 | + map->end = start + size; | ||
4243 | |||
4244 | dso__kernel_module_get_build_id(map->dso, machine->root_dir); | ||
4245 | |||
4246 | diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h | ||
4247 | index 354de6e56109..9b87b8b870ae 100644 | ||
4248 | --- a/tools/perf/util/machine.h | ||
4249 | +++ b/tools/perf/util/machine.h | ||
4250 | @@ -205,7 +205,7 @@ struct symbol *machine__find_kernel_function_by_name(struct machine *machine, | ||
4251 | |||
4252 | struct map *machine__findnew_module_map(struct machine *machine, u64 start, | ||
4253 | const char *filename); | ||
4254 | -int arch__fix_module_text_start(u64 *start, const char *name); | ||
4255 | +int arch__fix_module_text_start(u64 *start, u64 *size, const char *name); | ||
4256 | |||
4257 | int __machine__load_kallsyms(struct machine *machine, const char *filename, | ||
4258 | enum map_type type, bool no_kcore); | ||
4259 | diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c | ||
4260 | index 20ba5a9aeae4..5a50326c8158 100644 | ||
4261 | --- a/tools/perf/util/symbol-elf.c | ||
4262 | +++ b/tools/perf/util/symbol-elf.c | ||
4263 | @@ -1478,7 +1478,7 @@ static int kcore_copy__parse_kallsyms(struct kcore_copy_info *kci, | ||
4264 | |||
4265 | static int kcore_copy__process_modules(void *arg, | ||
4266 | const char *name __maybe_unused, | ||
4267 | - u64 start) | ||
4268 | + u64 start, u64 size __maybe_unused) | ||
4269 | { | ||
4270 | struct kcore_copy_info *kci = arg; | ||
4271 | |||
4272 | diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c | ||
4273 | index f199d5b11d76..acde8e489352 100644 | ||
4274 | --- a/tools/perf/util/symbol.c | ||
4275 | +++ b/tools/perf/util/symbol.c | ||
4276 | @@ -217,7 +217,8 @@ void __map_groups__fixup_end(struct map_groups *mg, enum map_type type) | ||
4277 | goto out_unlock; | ||
4278 | |||
4279 | for (next = map__next(curr); next; next = map__next(curr)) { | ||
4280 | - curr->end = next->start; | ||
4281 | + if (!curr->end) | ||
4282 | + curr->end = next->start; | ||
4283 | curr = next; | ||
4284 | } | ||
4285 | |||
4286 | @@ -225,7 +226,8 @@ void __map_groups__fixup_end(struct map_groups *mg, enum map_type type) | ||
4287 | * We still haven't the actual symbols, so guess the | ||
4288 | * last map final address. | ||
4289 | */ | ||
4290 | - curr->end = ~0ULL; | ||
4291 | + if (!curr->end) | ||
4292 | + curr->end = ~0ULL; | ||
4293 | |||
4294 | out_unlock: | ||
4295 | pthread_rwlock_unlock(&maps->lock); | ||
4296 | @@ -512,7 +514,7 @@ void dso__sort_by_name(struct dso *dso, enum map_type type) | ||
4297 | |||
4298 | int modules__parse(const char *filename, void *arg, | ||
4299 | int (*process_module)(void *arg, const char *name, | ||
4300 | - u64 start)) | ||
4301 | + u64 start, u64 size)) | ||
4302 | { | ||
4303 | char *line = NULL; | ||
4304 | size_t n; | ||
4305 | @@ -525,8 +527,8 @@ int modules__parse(const char *filename, void *arg, | ||
4306 | |||
4307 | while (1) { | ||
4308 | char name[PATH_MAX]; | ||
4309 | - u64 start; | ||
4310 | - char *sep; | ||
4311 | + u64 start, size; | ||
4312 | + char *sep, *endptr; | ||
4313 | ssize_t line_len; | ||
4314 | |||
4315 | line_len = getline(&line, &n, file); | ||
4316 | @@ -558,7 +560,11 @@ int modules__parse(const char *filename, void *arg, | ||
4317 | |||
4318 | scnprintf(name, sizeof(name), "[%s]", line); | ||
4319 | |||
4320 | - err = process_module(arg, name, start); | ||
4321 | + size = strtoul(sep + 1, &endptr, 0); | ||
4322 | + if (*endptr != ' ' && *endptr != '\t') | ||
4323 | + continue; | ||
4324 | + | ||
4325 | + err = process_module(arg, name, start, size); | ||
4326 | if (err) | ||
4327 | break; | ||
4328 | } | ||
4329 | @@ -905,7 +911,8 @@ static struct module_info *find_module(const char *name, | ||
4330 | return NULL; | ||
4331 | } | ||
4332 | |||
4333 | -static int __read_proc_modules(void *arg, const char *name, u64 start) | ||
4334 | +static int __read_proc_modules(void *arg, const char *name, u64 start, | ||
4335 | + u64 size __maybe_unused) | ||
4336 | { | ||
4337 | struct rb_root *modules = arg; | ||
4338 | struct module_info *mi; | ||
4339 | diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h | ||
4340 | index d964844eb314..833b1be2fb29 100644 | ||
4341 | --- a/tools/perf/util/symbol.h | ||
4342 | +++ b/tools/perf/util/symbol.h | ||
4343 | @@ -268,7 +268,7 @@ int filename__read_build_id(const char *filename, void *bf, size_t size); | ||
4344 | int sysfs__read_build_id(const char *filename, void *bf, size_t size); | ||
4345 | int modules__parse(const char *filename, void *arg, | ||
4346 | int (*process_module)(void *arg, const char *name, | ||
4347 | - u64 start)); | ||
4348 | + u64 start, u64 size)); | ||
4349 | int filename__read_debuglink(const char *filename, char *debuglink, | ||
4350 | size_t size); | ||
4351 | |||
4352 | diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c | ||
4353 | index f5af87f66663..81aee5adc8a2 100644 | ||
4354 | --- a/tools/perf/util/thread.c | ||
4355 | +++ b/tools/perf/util/thread.c | ||
4356 | @@ -114,14 +114,24 @@ struct comm *thread__comm(const struct thread *thread) | ||
4357 | |||
4358 | struct comm *thread__exec_comm(const struct thread *thread) | ||
4359 | { | ||
4360 | - struct comm *comm, *last = NULL; | ||
4361 | + struct comm *comm, *last = NULL, *second_last = NULL; | ||
4362 | |||
4363 | list_for_each_entry(comm, &thread->comm_list, list) { | ||
4364 | if (comm->exec) | ||
4365 | return comm; | ||
4366 | + second_last = last; | ||
4367 | last = comm; | ||
4368 | } | ||
4369 | |||
4370 | + /* | ||
4371 | + * 'last' with no start time might be the parent's comm of a synthesized | ||
4372 | + * thread (created by processing a synthesized fork event). For a main | ||
4373 | + * thread, that is very probably wrong. Prefer a later comm to avoid | ||
4374 | + * that case. | ||
4375 | + */ | ||
4376 | + if (second_last && !last->start && thread->pid_ == thread->tid) | ||
4377 | + return second_last; | ||
4378 | + | ||
4379 | return last; | ||
4380 | } | ||
4381 |