Magellan Linux

Contents of /trunk/kernel-alx/patches-4.14/0134-4.14.35-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3238 - (show annotations) (download)
Fri Nov 9 12:14:58 2018 UTC (5 years, 5 months ago) by niro
File size: 60980 byte(s)
-added up to patches-4.14.79
1 diff --git a/Makefile b/Makefile
2 index a6906dfb112e..995666d5e57b 100644
3 --- a/Makefile
4 +++ b/Makefile
5 @@ -1,7 +1,7 @@
6 # SPDX-License-Identifier: GPL-2.0
7 VERSION = 4
8 PATCHLEVEL = 14
9 -SUBLEVEL = 34
10 +SUBLEVEL = 35
11 EXTRAVERSION =
12 NAME = Petit Gorille
13
14 diff --git a/arch/parisc/kernel/drivers.c b/arch/parisc/kernel/drivers.c
15 index d8f77358e2ba..513826a43efd 100644
16 --- a/arch/parisc/kernel/drivers.c
17 +++ b/arch/parisc/kernel/drivers.c
18 @@ -651,6 +651,10 @@ static int match_pci_device(struct device *dev, int index,
19 (modpath->mod == PCI_FUNC(devfn)));
20 }
21
22 + /* index might be out of bounds for bc[] */
23 + if (index >= 6)
24 + return 0;
25 +
26 id = PCI_SLOT(pdev->devfn) | (PCI_FUNC(pdev->devfn) << 5);
27 return (modpath->bc[index] == id);
28 }
29 diff --git a/arch/parisc/kernel/hpmc.S b/arch/parisc/kernel/hpmc.S
30 index 8d072c44f300..781c3b9a3e46 100644
31 --- a/arch/parisc/kernel/hpmc.S
32 +++ b/arch/parisc/kernel/hpmc.S
33 @@ -84,6 +84,7 @@ END(hpmc_pim_data)
34 .text
35
36 .import intr_save, code
37 + .align 16
38 ENTRY_CFI(os_hpmc)
39 .os_hpmc:
40
41 @@ -300,12 +301,15 @@ os_hpmc_6:
42
43 b .
44 nop
45 + .align 16 /* make function length multiple of 16 bytes */
46 ENDPROC_CFI(os_hpmc)
47 .os_hpmc_end:
48
49
50 __INITRODATA
51 +.globl os_hpmc_size
52 .align 4
53 - .export os_hpmc_size
54 + .type os_hpmc_size, @object
55 + .size os_hpmc_size, 4
56 os_hpmc_size:
57 .word .os_hpmc_end-.os_hpmc
58 diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
59 index 4efe364f1188..4962d537c186 100644
60 --- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
61 +++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
62 @@ -447,8 +447,6 @@ static void do_tlbies(struct kvm *kvm, unsigned long *rbvalues,
63 for (i = 0; i < npages; ++i) {
64 asm volatile(PPC_TLBIE_5(%0,%1,0,0,0) : :
65 "r" (rbvalues[i]), "r" (kvm->arch.lpid));
66 - trace_tlbie(kvm->arch.lpid, 0, rbvalues[i],
67 - kvm->arch.lpid, 0, 0, 0);
68 }
69 asm volatile("eieio; tlbsync; ptesync" : : : "memory");
70 kvm->arch.tlbie_lock = 0;
71 @@ -458,8 +456,6 @@ static void do_tlbies(struct kvm *kvm, unsigned long *rbvalues,
72 for (i = 0; i < npages; ++i) {
73 asm volatile(PPC_TLBIEL(%0,%1,0,0,0) : :
74 "r" (rbvalues[i]), "r" (0));
75 - trace_tlbie(kvm->arch.lpid, 1, rbvalues[i],
76 - 0, 0, 0, 0);
77 }
78 asm volatile("ptesync" : : : "memory");
79 }
80 diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
81 index 8e622bb52f7a..d1a0e2c521d7 100644
82 --- a/arch/s390/kernel/ipl.c
83 +++ b/arch/s390/kernel/ipl.c
84 @@ -799,6 +799,7 @@ static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
85 /* copy and convert to ebcdic */
86 memcpy(ipb->hdr.loadparm, buf, lp_len);
87 ASCEBC(ipb->hdr.loadparm, LOADPARM_LEN);
88 + ipb->hdr.flags |= DIAG308_FLAGS_LP_VALID;
89 return len;
90 }
91
92 diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h
93 index b1e8d8db921f..340070415c2c 100644
94 --- a/arch/x86/include/asm/mce.h
95 +++ b/arch/x86/include/asm/mce.h
96 @@ -346,6 +346,7 @@ enum smca_bank_types {
97 SMCA_IF, /* Instruction Fetch */
98 SMCA_L2_CACHE, /* L2 Cache */
99 SMCA_DE, /* Decoder Unit */
100 + SMCA_RESERVED, /* Reserved */
101 SMCA_EX, /* Execution Unit */
102 SMCA_FP, /* Floating Point */
103 SMCA_L3_CACHE, /* L3 Cache */
104 @@ -376,6 +377,7 @@ struct smca_bank {
105 extern struct smca_bank smca_banks[MAX_NR_BANKS];
106
107 extern const char *smca_get_long_name(enum smca_bank_types t);
108 +extern bool amd_mce_is_memory_error(struct mce *m);
109
110 extern int mce_threshold_create_device(unsigned int cpu);
111 extern int mce_threshold_remove_device(unsigned int cpu);
112 @@ -384,6 +386,7 @@ extern int mce_threshold_remove_device(unsigned int cpu);
113
114 static inline int mce_threshold_create_device(unsigned int cpu) { return 0; };
115 static inline int mce_threshold_remove_device(unsigned int cpu) { return 0; };
116 +static inline bool amd_mce_is_memory_error(struct mce *m) { return false; };
117
118 #endif
119
120 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
121 index e13d652fc30a..28d27de08545 100644
122 --- a/arch/x86/kernel/cpu/mcheck/mce.c
123 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
124 @@ -512,10 +512,8 @@ static int mce_usable_address(struct mce *m)
125 bool mce_is_memory_error(struct mce *m)
126 {
127 if (m->cpuvendor == X86_VENDOR_AMD) {
128 - /* ErrCodeExt[20:16] */
129 - u8 xec = (m->status >> 16) & 0x1f;
130 + return amd_mce_is_memory_error(m);
131
132 - return (xec == 0x0 || xec == 0x8);
133 } else if (m->cpuvendor == X86_VENDOR_INTEL) {
134 /*
135 * Intel SDM Volume 3B - 15.9.2 Compound Error Codes
136 diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
137 index 486f640b02ef..259c75d7a2a0 100644
138 --- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
139 +++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
140 @@ -82,6 +82,7 @@ static struct smca_bank_name smca_names[] = {
141 [SMCA_IF] = { "insn_fetch", "Instruction Fetch Unit" },
142 [SMCA_L2_CACHE] = { "l2_cache", "L2 Cache" },
143 [SMCA_DE] = { "decode_unit", "Decode Unit" },
144 + [SMCA_RESERVED] = { "reserved", "Reserved" },
145 [SMCA_EX] = { "execution_unit", "Execution Unit" },
146 [SMCA_FP] = { "floating_point", "Floating Point Unit" },
147 [SMCA_L3_CACHE] = { "l3_cache", "L3 Cache" },
148 @@ -110,9 +111,26 @@ const char *smca_get_long_name(enum smca_bank_types t)
149 }
150 EXPORT_SYMBOL_GPL(smca_get_long_name);
151
152 +static enum smca_bank_types smca_get_bank_type(unsigned int bank)
153 +{
154 + struct smca_bank *b;
155 +
156 + if (bank >= MAX_NR_BANKS)
157 + return N_SMCA_BANK_TYPES;
158 +
159 + b = &smca_banks[bank];
160 + if (!b->hwid)
161 + return N_SMCA_BANK_TYPES;
162 +
163 + return b->hwid->bank_type;
164 +}
165 +
166 static struct smca_hwid smca_hwid_mcatypes[] = {
167 /* { bank_type, hwid_mcatype, xec_bitmap } */
168
169 + /* Reserved type */
170 + { SMCA_RESERVED, HWID_MCATYPE(0x00, 0x0), 0x0 },
171 +
172 /* ZN Core (HWID=0xB0) MCA types */
173 { SMCA_LS, HWID_MCATYPE(0xB0, 0x0), 0x1FFFEF },
174 { SMCA_IF, HWID_MCATYPE(0xB0, 0x1), 0x3FFF },
175 @@ -416,7 +434,25 @@ static u32 get_block_address(unsigned int cpu, u32 current_addr, u32 low, u32 hi
176 {
177 u32 addr = 0, offset = 0;
178
179 + if ((bank >= mca_cfg.banks) || (block >= NR_BLOCKS))
180 + return addr;
181 +
182 + /* Get address from already initialized block. */
183 + if (per_cpu(threshold_banks, cpu)) {
184 + struct threshold_bank *bankp = per_cpu(threshold_banks, cpu)[bank];
185 +
186 + if (bankp && bankp->blocks) {
187 + struct threshold_block *blockp = &bankp->blocks[block];
188 +
189 + if (blockp)
190 + return blockp->address;
191 + }
192 + }
193 +
194 if (mce_flags.smca) {
195 + if (smca_get_bank_type(bank) == SMCA_RESERVED)
196 + return addr;
197 +
198 if (!block) {
199 addr = MSR_AMD64_SMCA_MCx_MISC(bank);
200 } else {
201 @@ -738,6 +774,17 @@ int umc_normaddr_to_sysaddr(u64 norm_addr, u16 nid, u8 umc, u64 *sys_addr)
202 }
203 EXPORT_SYMBOL_GPL(umc_normaddr_to_sysaddr);
204
205 +bool amd_mce_is_memory_error(struct mce *m)
206 +{
207 + /* ErrCodeExt[20:16] */
208 + u8 xec = (m->status >> 16) & 0x1f;
209 +
210 + if (mce_flags.smca)
211 + return smca_get_bank_type(m->bank) == SMCA_UMC && xec == 0x0;
212 +
213 + return m->bank == 4 && xec == 0x8;
214 +}
215 +
216 static void __log_error(unsigned int bank, u64 status, u64 addr, u64 misc)
217 {
218 struct mce m;
219 @@ -1036,7 +1083,7 @@ static struct kobj_type threshold_ktype = {
220
221 static const char *get_name(unsigned int bank, struct threshold_block *b)
222 {
223 - unsigned int bank_type;
224 + enum smca_bank_types bank_type;
225
226 if (!mce_flags.smca) {
227 if (b && bank == 4)
228 @@ -1045,11 +1092,10 @@ static const char *get_name(unsigned int bank, struct threshold_block *b)
229 return th_names[bank];
230 }
231
232 - if (!smca_banks[bank].hwid)
233 + bank_type = smca_get_bank_type(bank);
234 + if (bank_type >= N_SMCA_BANK_TYPES)
235 return NULL;
236
237 - bank_type = smca_banks[bank].hwid->bank_type;
238 -
239 if (b && bank_type == SMCA_UMC) {
240 if (b->block < ARRAY_SIZE(smca_umc_block_names))
241 return smca_umc_block_names[b->block];
242 diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c
243 index 9f8cffc8a701..3eb169f15842 100644
244 --- a/block/blk-mq-cpumap.c
245 +++ b/block/blk-mq-cpumap.c
246 @@ -16,11 +16,6 @@
247
248 static int cpu_to_queue_index(unsigned int nr_queues, const int cpu)
249 {
250 - /*
251 - * Non present CPU will be mapped to queue index 0.
252 - */
253 - if (!cpu_present(cpu))
254 - return 0;
255 return cpu % nr_queues;
256 }
257
258 diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
259 index f14b4326e855..67a860790560 100644
260 --- a/drivers/acpi/nfit/core.c
261 +++ b/drivers/acpi/nfit/core.c
262 @@ -2748,15 +2748,21 @@ static void acpi_nfit_scrub(struct work_struct *work)
263 static int acpi_nfit_register_regions(struct acpi_nfit_desc *acpi_desc)
264 {
265 struct nfit_spa *nfit_spa;
266 - int rc;
267
268 - list_for_each_entry(nfit_spa, &acpi_desc->spas, list)
269 - if (nfit_spa_type(nfit_spa->spa) == NFIT_SPA_DCR) {
270 - /* BLK regions don't need to wait for ars results */
271 - rc = acpi_nfit_register_region(acpi_desc, nfit_spa);
272 - if (rc)
273 - return rc;
274 - }
275 + list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
276 + int rc, type = nfit_spa_type(nfit_spa->spa);
277 +
278 + /* PMEM and VMEM will be registered by the ARS workqueue */
279 + if (type == NFIT_SPA_PM || type == NFIT_SPA_VOLATILE)
280 + continue;
281 + /* BLK apertures belong to BLK region registration below */
282 + if (type == NFIT_SPA_BDW)
283 + continue;
284 + /* BLK regions don't need to wait for ARS results */
285 + rc = acpi_nfit_register_region(acpi_desc, nfit_spa);
286 + if (rc)
287 + return rc;
288 + }
289
290 acpi_desc->ars_start_flags = 0;
291 if (!acpi_desc->cancel)
292 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
293 index 19858a146f30..754852156622 100644
294 --- a/drivers/block/loop.c
295 +++ b/drivers/block/loop.c
296 @@ -1098,11 +1098,15 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
297 if (info->lo_encrypt_type) {
298 unsigned int type = info->lo_encrypt_type;
299
300 - if (type >= MAX_LO_CRYPT)
301 - return -EINVAL;
302 + if (type >= MAX_LO_CRYPT) {
303 + err = -EINVAL;
304 + goto exit;
305 + }
306 xfer = xfer_funcs[type];
307 - if (xfer == NULL)
308 - return -EINVAL;
309 + if (xfer == NULL) {
310 + err = -EINVAL;
311 + goto exit;
312 + }
313 } else
314 xfer = NULL;
315
316 diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
317 index 73d2d88ddc03..32527bdf4b50 100644
318 --- a/drivers/bluetooth/hci_bcm.c
319 +++ b/drivers/bluetooth/hci_bcm.c
320 @@ -694,22 +694,6 @@ static const struct acpi_gpio_mapping acpi_bcm_int_first_gpios[] = {
321 #ifdef CONFIG_ACPI
322 /* IRQ polarity of some chipsets are not defined correctly in ACPI table. */
323 static const struct dmi_system_id bcm_active_low_irq_dmi_table[] = {
324 - {
325 - .ident = "Asus T100TA",
326 - .matches = {
327 - DMI_EXACT_MATCH(DMI_SYS_VENDOR,
328 - "ASUSTeK COMPUTER INC."),
329 - DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
330 - },
331 - },
332 - {
333 - .ident = "Asus T100CHI",
334 - .matches = {
335 - DMI_EXACT_MATCH(DMI_SYS_VENDOR,
336 - "ASUSTeK COMPUTER INC."),
337 - DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100CHI"),
338 - },
339 - },
340 { /* Handle ThinkPad 8 tablets with BCM2E55 chipset ACPI ID */
341 .ident = "Lenovo ThinkPad 8",
342 .matches = {
343 @@ -730,7 +714,9 @@ static int bcm_resource(struct acpi_resource *ares, void *data)
344 switch (ares->type) {
345 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
346 irq = &ares->data.extended_irq;
347 - dev->irq_active_low = irq->polarity == ACPI_ACTIVE_LOW;
348 + if (irq->polarity != ACPI_ACTIVE_LOW)
349 + dev_info(&dev->pdev->dev, "ACPI Interrupt resource is active-high, this is usually wrong, treating the IRQ as active-low\n");
350 + dev->irq_active_low = true;
351 break;
352
353 case ACPI_RESOURCE_TYPE_GPIO:
354 diff --git a/drivers/edac/mce_amd.c b/drivers/edac/mce_amd.c
355 index a11a671c7a38..2ab4d61ee47e 100644
356 --- a/drivers/edac/mce_amd.c
357 +++ b/drivers/edac/mce_amd.c
358 @@ -854,21 +854,24 @@ static void decode_mc6_mce(struct mce *m)
359 static void decode_smca_error(struct mce *m)
360 {
361 struct smca_hwid *hwid;
362 - unsigned int bank_type;
363 + enum smca_bank_types bank_type;
364 const char *ip_name;
365 u8 xec = XEC(m->status, xec_mask);
366
367 if (m->bank >= ARRAY_SIZE(smca_banks))
368 return;
369
370 - if (x86_family(m->cpuid) >= 0x17 && m->bank == 4)
371 - pr_emerg(HW_ERR "Bank 4 is reserved on Fam17h.\n");
372 -
373 hwid = smca_banks[m->bank].hwid;
374 if (!hwid)
375 return;
376
377 bank_type = hwid->bank_type;
378 +
379 + if (bank_type == SMCA_RESERVED) {
380 + pr_emerg(HW_ERR "Bank %d is reserved.\n", m->bank);
381 + return;
382 + }
383 +
384 ip_name = smca_get_long_name(bank_type);
385
386 pr_emerg(HW_ERR "%s Extended Error Code: %d\n", ip_name, xec);
387 diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
388 index baadb706c276..b19a54dd18de 100644
389 --- a/drivers/gpu/drm/radeon/radeon_object.c
390 +++ b/drivers/gpu/drm/radeon/radeon_object.c
391 @@ -240,9 +240,10 @@ int radeon_bo_create(struct radeon_device *rdev,
392 * may be slow
393 * See https://bugs.freedesktop.org/show_bug.cgi?id=88758
394 */
395 -
396 +#ifndef CONFIG_COMPILE_TEST
397 #warning Please enable CONFIG_MTRR and CONFIG_X86_PAT for better performance \
398 thanks to write-combining
399 +#endif
400
401 if (bo->flags & RADEON_GEM_GTT_WC)
402 DRM_INFO_ONCE("Please enable CONFIG_MTRR and CONFIG_X86_PAT for "
403 diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
404 index 65c6d6bdce4c..1939c0ca3741 100644
405 --- a/drivers/hv/channel_mgmt.c
406 +++ b/drivers/hv/channel_mgmt.c
407 @@ -71,7 +71,7 @@ static const struct vmbus_device vmbus_devs[] = {
408 /* PCIE */
409 { .dev_type = HV_PCIE,
410 HV_PCIE_GUID,
411 - .perf_device = true,
412 + .perf_device = false,
413 },
414
415 /* Synthetic Frame Buffer */
416 diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
417 index e362a932fe8c..e9e6aeabbf84 100644
418 --- a/drivers/hwmon/ina2xx.c
419 +++ b/drivers/hwmon/ina2xx.c
420 @@ -454,6 +454,7 @@ static int ina2xx_probe(struct i2c_client *client,
421
422 /* set the device type */
423 data->config = &ina2xx_config[chip];
424 + mutex_init(&data->config_lock);
425
426 if (of_property_read_u32(dev->of_node, "shunt-resistor", &val) < 0) {
427 struct ina2xx_platform_data *pdata = dev_get_platdata(dev);
428 @@ -480,8 +481,6 @@ static int ina2xx_probe(struct i2c_client *client,
429 return -ENODEV;
430 }
431
432 - mutex_init(&data->config_lock);
433 -
434 data->groups[group++] = &ina2xx_group;
435 if (id->driver_data == ina226)
436 data->groups[group++] = &ina226_group;
437 diff --git a/drivers/media/platform/vsp1/vsp1_dl.c b/drivers/media/platform/vsp1/vsp1_dl.c
438 index 8b5cbb6b7a70..e5d8d99e124c 100644
439 --- a/drivers/media/platform/vsp1/vsp1_dl.c
440 +++ b/drivers/media/platform/vsp1/vsp1_dl.c
441 @@ -508,7 +508,8 @@ static bool vsp1_dl_list_hw_update_pending(struct vsp1_dl_manager *dlm)
442 return !!(vsp1_read(vsp1, VI6_DL_BODY_SIZE)
443 & VI6_DL_BODY_SIZE_UPD);
444 else
445 - return !!(vsp1_read(vsp1, VI6_CMD(dlm->index) & VI6_CMD_UPDHDR));
446 + return !!(vsp1_read(vsp1, VI6_CMD(dlm->index))
447 + & VI6_CMD_UPDHDR);
448 }
449
450 static void vsp1_dl_list_hw_enqueue(struct vsp1_dl_list *dl)
451 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
452 index cbeea8343a5c..6730fd08ef03 100644
453 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
454 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
455 @@ -101,7 +101,7 @@ static int get_v4l2_window32(struct v4l2_window __user *kp,
456 static int put_v4l2_window32(struct v4l2_window __user *kp,
457 struct v4l2_window32 __user *up)
458 {
459 - struct v4l2_clip __user *kclips = kp->clips;
460 + struct v4l2_clip __user *kclips;
461 struct v4l2_clip32 __user *uclips;
462 compat_caddr_t p;
463 u32 clipcount;
464 @@ -116,6 +116,8 @@ static int put_v4l2_window32(struct v4l2_window __user *kp,
465 if (!clipcount)
466 return 0;
467
468 + if (get_user(kclips, &kp->clips))
469 + return -EFAULT;
470 if (get_user(p, &up->clips))
471 return -EFAULT;
472 uclips = compat_ptr(p);
473 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
474 index 5782733959f0..f4e93f5fc204 100644
475 --- a/drivers/net/slip/slhc.c
476 +++ b/drivers/net/slip/slhc.c
477 @@ -509,6 +509,10 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
478 if(x < 0 || x > comp->rslot_limit)
479 goto bad;
480
481 + /* Check if the cstate is initialized */
482 + if (!comp->rstate[x].initialized)
483 + goto bad;
484 +
485 comp->flags &=~ SLF_TOSS;
486 comp->recv_current = x;
487 } else {
488 @@ -673,6 +677,7 @@ slhc_remember(struct slcompress *comp, unsigned char *icp, int isize)
489 if (cs->cs_tcp.doff > 5)
490 memcpy(cs->cs_tcpopt, icp + ihl*4 + sizeof(struct tcphdr), (cs->cs_tcp.doff - 5) * 4);
491 cs->cs_hsize = ihl*2 + cs->cs_tcp.doff*2;
492 + cs->initialized = true;
493 /* Put headers back on packet
494 * Neither header checksum is recalculated
495 */
496 diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
497 index 05dca3e5c93d..178b956501a7 100644
498 --- a/drivers/net/usb/cdc_ether.c
499 +++ b/drivers/net/usb/cdc_ether.c
500 @@ -895,6 +895,12 @@ static const struct usb_device_id products[] = {
501 USB_CDC_SUBCLASS_ETHERNET,
502 USB_CDC_PROTO_NONE),
503 .driver_info = (unsigned long)&wwan_info,
504 +}, {
505 + /* Cinterion AHS3 modem by GEMALTO */
506 + USB_DEVICE_AND_INTERFACE_INFO(0x1e2d, 0x0055, USB_CLASS_COMM,
507 + USB_CDC_SUBCLASS_ETHERNET,
508 + USB_CDC_PROTO_NONE),
509 + .driver_info = (unsigned long)&wwan_info,
510 }, {
511 USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
512 USB_CDC_PROTO_NONE),
513 diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
514 index 89d82c4ee8df..1fb464837b3e 100644
515 --- a/drivers/net/usb/lan78xx.c
516 +++ b/drivers/net/usb/lan78xx.c
517 @@ -928,7 +928,8 @@ static int lan78xx_read_otp(struct lan78xx_net *dev, u32 offset,
518 offset += 0x100;
519 else
520 ret = -EINVAL;
521 - ret = lan78xx_read_raw_otp(dev, offset, length, data);
522 + if (!ret)
523 + ret = lan78xx_read_raw_otp(dev, offset, length, data);
524 }
525
526 return ret;
527 diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
528 index 396bf05c6bf6..d8b041f48ca8 100644
529 --- a/drivers/net/wireless/ath/ath9k/xmit.c
530 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
531 @@ -2892,6 +2892,8 @@ void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
532 struct ath_txq *txq;
533 int tidno;
534
535 + rcu_read_lock();
536 +
537 for (tidno = 0; tidno < IEEE80211_NUM_TIDS; tidno++) {
538 tid = ath_node_to_tid(an, tidno);
539 txq = tid->txq;
540 @@ -2909,6 +2911,8 @@ void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an)
541 if (!an->sta)
542 break; /* just one multicast ath_atx_tid */
543 }
544 +
545 + rcu_read_unlock();
546 }
547
548 #ifdef CONFIG_ATH9K_TX99
549 diff --git a/drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c b/drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c
550 index 121b94f09714..9a1d15b3ce45 100644
551 --- a/drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c
552 +++ b/drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c
553 @@ -1450,6 +1450,7 @@ static int rtl8187_probe(struct usb_interface *intf,
554 goto err_free_dev;
555 }
556 mutex_init(&priv->io_mutex);
557 + mutex_init(&priv->conf_mutex);
558
559 SET_IEEE80211_DEV(dev, &intf->dev);
560 usb_set_intfdata(intf, dev);
561 @@ -1625,7 +1626,6 @@ static int rtl8187_probe(struct usb_interface *intf,
562 printk(KERN_ERR "rtl8187: Cannot register device\n");
563 goto err_free_dmabuf;
564 }
565 - mutex_init(&priv->conf_mutex);
566 skb_queue_head_init(&priv->b_tx_status.queue);
567
568 wiphy_info(dev->wiphy, "hwaddr %pM, %s V%d + %s, rfkill mask %d\n",
569 diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
570 index 04dac6a42c9f..73b724143be0 100644
571 --- a/drivers/pci/host/pci-hyperv.c
572 +++ b/drivers/pci/host/pci-hyperv.c
573 @@ -457,7 +457,6 @@ struct hv_pcibus_device {
574 spinlock_t device_list_lock; /* Protect lists below */
575 void __iomem *cfg_addr;
576
577 - struct semaphore enum_sem;
578 struct list_head resources_for_children;
579
580 struct list_head children;
581 @@ -471,6 +470,8 @@ struct hv_pcibus_device {
582 struct retarget_msi_interrupt retarget_msi_interrupt_params;
583
584 spinlock_t retarget_msi_interrupt_lock;
585 +
586 + struct workqueue_struct *wq;
587 };
588
589 /*
590 @@ -1604,12 +1605,8 @@ static struct hv_pci_dev *get_pcichild_wslot(struct hv_pcibus_device *hbus,
591 * It must also treat the omission of a previously observed device as
592 * notification that the device no longer exists.
593 *
594 - * Note that this function is a work item, and it may not be
595 - * invoked in the order that it was queued. Back to back
596 - * updates of the list of present devices may involve queuing
597 - * multiple work items, and this one may run before ones that
598 - * were sent later. As such, this function only does something
599 - * if is the last one in the queue.
600 + * Note that this function is serialized with hv_eject_device_work(),
601 + * because both are pushed to the ordered workqueue hbus->wq.
602 */
603 static void pci_devices_present_work(struct work_struct *work)
604 {
605 @@ -1630,11 +1627,6 @@ static void pci_devices_present_work(struct work_struct *work)
606
607 INIT_LIST_HEAD(&removed);
608
609 - if (down_interruptible(&hbus->enum_sem)) {
610 - put_hvpcibus(hbus);
611 - return;
612 - }
613 -
614 /* Pull this off the queue and process it if it was the last one. */
615 spin_lock_irqsave(&hbus->device_list_lock, flags);
616 while (!list_empty(&hbus->dr_list)) {
617 @@ -1651,7 +1643,6 @@ static void pci_devices_present_work(struct work_struct *work)
618 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
619
620 if (!dr) {
621 - up(&hbus->enum_sem);
622 put_hvpcibus(hbus);
623 return;
624 }
625 @@ -1738,7 +1729,6 @@ static void pci_devices_present_work(struct work_struct *work)
626 break;
627 }
628
629 - up(&hbus->enum_sem);
630 put_hvpcibus(hbus);
631 kfree(dr);
632 }
633 @@ -1784,7 +1774,7 @@ static void hv_pci_devices_present(struct hv_pcibus_device *hbus,
634 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
635
636 get_hvpcibus(hbus);
637 - schedule_work(&dr_wrk->wrk);
638 + queue_work(hbus->wq, &dr_wrk->wrk);
639 }
640
641 /**
642 @@ -1862,7 +1852,7 @@ static void hv_pci_eject_device(struct hv_pci_dev *hpdev)
643 get_pcichild(hpdev, hv_pcidev_ref_pnp);
644 INIT_WORK(&hpdev->wrk, hv_eject_device_work);
645 get_hvpcibus(hpdev->hbus);
646 - schedule_work(&hpdev->wrk);
647 + queue_work(hpdev->hbus->wq, &hpdev->wrk);
648 }
649
650 /**
651 @@ -2475,13 +2465,18 @@ static int hv_pci_probe(struct hv_device *hdev,
652 spin_lock_init(&hbus->config_lock);
653 spin_lock_init(&hbus->device_list_lock);
654 spin_lock_init(&hbus->retarget_msi_interrupt_lock);
655 - sema_init(&hbus->enum_sem, 1);
656 init_completion(&hbus->remove_event);
657 + hbus->wq = alloc_ordered_workqueue("hv_pci_%x", 0,
658 + hbus->sysdata.domain);
659 + if (!hbus->wq) {
660 + ret = -ENOMEM;
661 + goto free_bus;
662 + }
663
664 ret = vmbus_open(hdev->channel, pci_ring_size, pci_ring_size, NULL, 0,
665 hv_pci_onchannelcallback, hbus);
666 if (ret)
667 - goto free_bus;
668 + goto destroy_wq;
669
670 hv_set_drvdata(hdev, hbus);
671
672 @@ -2550,6 +2545,8 @@ static int hv_pci_probe(struct hv_device *hdev,
673 hv_free_config_window(hbus);
674 close:
675 vmbus_close(hdev->channel);
676 +destroy_wq:
677 + destroy_workqueue(hbus->wq);
678 free_bus:
679 free_page((unsigned long)hbus);
680 return ret;
681 @@ -2629,6 +2626,7 @@ static int hv_pci_remove(struct hv_device *hdev)
682 irq_domain_free_fwnode(hbus->sysdata.fwnode);
683 put_hvpcibus(hbus);
684 wait_for_completion(&hbus->remove_event);
685 + destroy_workqueue(hbus->wq);
686 free_page((unsigned long)hbus);
687 return 0;
688 }
689 diff --git a/drivers/s390/cio/qdio_main.c b/drivers/s390/cio/qdio_main.c
690 index a4ad39ba3873..8941e7caaf4d 100644
691 --- a/drivers/s390/cio/qdio_main.c
692 +++ b/drivers/s390/cio/qdio_main.c
693 @@ -126,7 +126,7 @@ static inline int qdio_check_ccq(struct qdio_q *q, unsigned int ccq)
694 static int qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
695 int start, int count, int auto_ack)
696 {
697 - int rc, tmp_count = count, tmp_start = start, nr = q->nr, retried = 0;
698 + int rc, tmp_count = count, tmp_start = start, nr = q->nr;
699 unsigned int ccq = 0;
700
701 qperf_inc(q, eqbs);
702 @@ -149,14 +149,7 @@ static int qdio_do_eqbs(struct qdio_q *q, unsigned char *state,
703 qperf_inc(q, eqbs_partial);
704 DBF_DEV_EVENT(DBF_WARN, q->irq_ptr, "EQBS part:%02x",
705 tmp_count);
706 - /*
707 - * Retry once, if that fails bail out and process the
708 - * extracted buffers before trying again.
709 - */
710 - if (!retried++)
711 - goto again;
712 - else
713 - return count - tmp_count;
714 + return count - tmp_count;
715 }
716
717 DBF_ERROR("%4x EQBS ERROR", SCH_NO(q));
718 @@ -212,7 +205,10 @@ static int qdio_do_sqbs(struct qdio_q *q, unsigned char state, int start,
719 return 0;
720 }
721
722 -/* returns number of examined buffers and their common state in *state */
723 +/*
724 + * Returns number of examined buffers and their common state in *state.
725 + * Requested number of buffers-to-examine must be > 0.
726 + */
727 static inline int get_buf_states(struct qdio_q *q, unsigned int bufnr,
728 unsigned char *state, unsigned int count,
729 int auto_ack, int merge_pending)
730 @@ -223,17 +219,23 @@ static inline int get_buf_states(struct qdio_q *q, unsigned int bufnr,
731 if (is_qebsm(q))
732 return qdio_do_eqbs(q, state, bufnr, count, auto_ack);
733
734 - for (i = 0; i < count; i++) {
735 - if (!__state) {
736 - __state = q->slsb.val[bufnr];
737 - if (merge_pending && __state == SLSB_P_OUTPUT_PENDING)
738 - __state = SLSB_P_OUTPUT_EMPTY;
739 - } else if (merge_pending) {
740 - if ((q->slsb.val[bufnr] & __state) != __state)
741 - break;
742 - } else if (q->slsb.val[bufnr] != __state)
743 - break;
744 + /* get initial state: */
745 + __state = q->slsb.val[bufnr];
746 + if (merge_pending && __state == SLSB_P_OUTPUT_PENDING)
747 + __state = SLSB_P_OUTPUT_EMPTY;
748 +
749 + for (i = 1; i < count; i++) {
750 bufnr = next_buf(bufnr);
751 +
752 + /* merge PENDING into EMPTY: */
753 + if (merge_pending &&
754 + q->slsb.val[bufnr] == SLSB_P_OUTPUT_PENDING &&
755 + __state == SLSB_P_OUTPUT_EMPTY)
756 + continue;
757 +
758 + /* stop if next state differs from initial state: */
759 + if (q->slsb.val[bufnr] != __state)
760 + break;
761 }
762 *state = __state;
763 return i;
764 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
765 index 1e17175692d3..8e7c0626f8b5 100644
766 --- a/drivers/scsi/qla2xxx/qla_os.c
767 +++ b/drivers/scsi/qla2xxx/qla_os.c
768 @@ -459,9 +459,6 @@ static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
769
770 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
771 {
772 - if (!ha->req_q_map)
773 - return;
774 -
775 if (IS_QLAFX00(ha)) {
776 if (req && req->ring_fx00)
777 dma_free_coherent(&ha->pdev->dev,
778 @@ -472,17 +469,14 @@ static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
779 (req->length + 1) * sizeof(request_t),
780 req->ring, req->dma);
781
782 - if (req) {
783 + if (req)
784 kfree(req->outstanding_cmds);
785 - kfree(req);
786 - }
787 +
788 + kfree(req);
789 }
790
791 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
792 {
793 - if (!ha->rsp_q_map)
794 - return;
795 -
796 if (IS_QLAFX00(ha)) {
797 if (rsp && rsp->ring)
798 dma_free_coherent(&ha->pdev->dev,
799 @@ -493,8 +487,7 @@ static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
800 (rsp->length + 1) * sizeof(response_t),
801 rsp->ring, rsp->dma);
802 }
803 - if (rsp)
804 - kfree(rsp);
805 + kfree(rsp);
806 }
807
808 static void qla2x00_free_queues(struct qla_hw_data *ha)
809 @@ -3075,7 +3068,8 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
810 goto probe_failed;
811
812 /* Alloc arrays of request and response ring ptrs */
813 - if (qla2x00_alloc_queues(ha, req, rsp)) {
814 + ret = qla2x00_alloc_queues(ha, req, rsp);
815 + if (ret) {
816 ql_log(ql_log_fatal, base_vha, 0x003d,
817 "Failed to allocate memory for queue pointers..."
818 "aborting.\n");
819 @@ -3368,8 +3362,15 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
820 }
821
822 qla2x00_free_device(base_vha);
823 -
824 scsi_host_put(base_vha->host);
825 + /*
826 + * Need to NULL out local req/rsp after
827 + * qla2x00_free_device => qla2x00_free_queues frees
828 + * what these are pointing to. Or else we'll
829 + * fall over below in qla2x00_free_req/rsp_que.
830 + */
831 + req = NULL;
832 + rsp = NULL;
833
834 probe_hw_failed:
835 qla2x00_mem_free(ha);
836 @@ -4062,6 +4063,7 @@ qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
837 (*rsp)->dma = 0;
838 fail_rsp_ring:
839 kfree(*rsp);
840 + *rsp = NULL;
841 fail_rsp:
842 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
843 sizeof(request_t), (*req)->ring, (*req)->dma);
844 @@ -4069,6 +4071,7 @@ qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
845 (*req)->dma = 0;
846 fail_req_ring:
847 kfree(*req);
848 + *req = NULL;
849 fail_req:
850 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
851 ha->ct_sns, ha->ct_sns_dma);
852 @@ -4436,16 +4439,11 @@ qla2x00_mem_free(struct qla_hw_data *ha)
853 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
854 ha->init_cb, ha->init_cb_dma);
855
856 - if (ha->optrom_buffer)
857 - vfree(ha->optrom_buffer);
858 - if (ha->nvram)
859 - kfree(ha->nvram);
860 - if (ha->npiv_info)
861 - kfree(ha->npiv_info);
862 - if (ha->swl)
863 - kfree(ha->swl);
864 - if (ha->loop_id_map)
865 - kfree(ha->loop_id_map);
866 + vfree(ha->optrom_buffer);
867 + kfree(ha->nvram);
868 + kfree(ha->npiv_info);
869 + kfree(ha->swl);
870 + kfree(ha->loop_id_map);
871
872 ha->srb_mempool = NULL;
873 ha->ctx_mempool = NULL;
874 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
875 index c692e0b13242..8e3ca4400766 100644
876 --- a/drivers/vhost/vhost.c
877 +++ b/drivers/vhost/vhost.c
878 @@ -756,7 +756,7 @@ static int vhost_copy_to_user(struct vhost_virtqueue *vq, void __user *to,
879 struct iov_iter t;
880 void __user *uaddr = vhost_vq_meta_fetch(vq,
881 (u64)(uintptr_t)to, size,
882 - VHOST_ADDR_DESC);
883 + VHOST_ADDR_USED);
884
885 if (uaddr)
886 return __copy_to_user(uaddr, from, size);
887 @@ -1252,10 +1252,12 @@ static int vq_log_access_ok(struct vhost_virtqueue *vq,
888 /* Caller should have vq mutex and device mutex */
889 int vhost_vq_access_ok(struct vhost_virtqueue *vq)
890 {
891 - int ret = vq_log_access_ok(vq, vq->log_base);
892 + if (!vq_log_access_ok(vq, vq->log_base))
893 + return 0;
894
895 - if (ret || vq->iotlb)
896 - return ret;
897 + /* Access validation occurs at prefetch time with IOTLB */
898 + if (vq->iotlb)
899 + return 1;
900
901 return vq_access_ok(vq, vq->num, vq->desc, vq->avail, vq->used);
902 }
903 diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
904 index f3b089b7c0b6..d2edbc79384a 100644
905 --- a/drivers/xen/xenbus/xenbus_dev_frontend.c
906 +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
907 @@ -365,7 +365,7 @@ void xenbus_dev_queue_reply(struct xb_req_data *req)
908 if (WARN_ON(rc))
909 goto out;
910 }
911 - } else if (req->msg.type == XS_TRANSACTION_END) {
912 + } else if (req->type == XS_TRANSACTION_END) {
913 trans = xenbus_get_transaction(u, req->msg.tx_id);
914 if (WARN_ON(!trans))
915 goto out;
916 diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
917 index bfe6a8ccc3a0..d5021ba69e7a 100644
918 --- a/fs/f2fs/gc.c
919 +++ b/fs/f2fs/gc.c
920 @@ -191,8 +191,9 @@ static void select_policy(struct f2fs_sb_info *sbi, int gc_type,
921 if (gc_type != FG_GC && p->max_search > sbi->max_victim_search)
922 p->max_search = sbi->max_victim_search;
923
924 - /* let's select beginning hot/small space first */
925 - if (type == CURSEG_HOT_DATA || IS_NODESEG(type))
926 + /* let's select beginning hot/small space first in no_heap mode*/
927 + if (test_opt(sbi, NOHEAP) &&
928 + (type == CURSEG_HOT_DATA || IS_NODESEG(type)))
929 p->offset = 0;
930 else
931 p->offset = SIT_I(sbi)->last_victim[p->gc_mode];
932 diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
933 index c695ff462ee6..271516db8939 100644
934 --- a/fs/f2fs/segment.c
935 +++ b/fs/f2fs/segment.c
936 @@ -1992,7 +1992,8 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)
937 if (sbi->segs_per_sec != 1)
938 return CURSEG_I(sbi, type)->segno;
939
940 - if (type == CURSEG_HOT_DATA || IS_NODESEG(type))
941 + if (test_opt(sbi, NOHEAP) &&
942 + (type == CURSEG_HOT_DATA || IS_NODESEG(type)))
943 return 0;
944
945 if (SIT_I(sbi)->last_victim[ALLOC_NEXT])
946 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
947 index 3b293d0d1785..2a6ed036d207 100644
948 --- a/fs/hugetlbfs/inode.c
949 +++ b/fs/hugetlbfs/inode.c
950 @@ -148,10 +148,14 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
951
952 /*
953 * page based offset in vm_pgoff could be sufficiently large to
954 - * overflow a (l)off_t when converted to byte offset.
955 + * overflow a loff_t when converted to byte offset. This can
956 + * only happen on architectures where sizeof(loff_t) ==
957 + * sizeof(unsigned long). So, only check in those instances.
958 */
959 - if (vma->vm_pgoff & PGOFF_LOFFT_MAX)
960 - return -EINVAL;
961 + if (sizeof(unsigned long) == sizeof(loff_t)) {
962 + if (vma->vm_pgoff & PGOFF_LOFFT_MAX)
963 + return -EINVAL;
964 + }
965
966 /* must be huge page aligned */
967 if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT))
968 diff --git a/fs/namei.c b/fs/namei.c
969 index f839b0750ca3..0b46b858cd42 100644
970 --- a/fs/namei.c
971 +++ b/fs/namei.c
972 @@ -222,9 +222,10 @@ getname_kernel(const char * filename)
973 if (len <= EMBEDDED_NAME_MAX) {
974 result->name = (char *)result->iname;
975 } else if (len <= PATH_MAX) {
976 + const size_t size = offsetof(struct filename, iname[1]);
977 struct filename *tmp;
978
979 - tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
980 + tmp = kmalloc(size, GFP_KERNEL);
981 if (unlikely(!tmp)) {
982 __putname(result);
983 return ERR_PTR(-ENOMEM);
984 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
985 index 8ce60986fb75..5b6ff168d11a 100644
986 --- a/fs/nfsd/nfs4proc.c
987 +++ b/fs/nfsd/nfs4proc.c
988 @@ -32,6 +32,7 @@
989 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
990 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
991 */
992 +#include <linux/fs_struct.h>
993 #include <linux/file.h>
994 #include <linux/falloc.h>
995 #include <linux/slab.h>
996 @@ -252,11 +253,13 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru
997 * Note: create modes (UNCHECKED,GUARDED...) are the same
998 * in NFSv4 as in v3 except EXCLUSIVE4_1.
999 */
1000 + current->fs->umask = open->op_umask;
1001 status = do_nfsd_create(rqstp, current_fh, open->op_fname.data,
1002 open->op_fname.len, &open->op_iattr,
1003 *resfh, open->op_createmode,
1004 (u32 *)open->op_verf.data,
1005 &open->op_truncate, &open->op_created);
1006 + current->fs->umask = 0;
1007
1008 if (!status && open->op_label.len)
1009 nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval);
1010 @@ -608,6 +611,7 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1011 if (status)
1012 return status;
1013
1014 + current->fs->umask = create->cr_umask;
1015 switch (create->cr_type) {
1016 case NF4LNK:
1017 status = nfsd_symlink(rqstp, &cstate->current_fh,
1018 @@ -616,20 +620,22 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1019 break;
1020
1021 case NF4BLK:
1022 + status = nfserr_inval;
1023 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
1024 if (MAJOR(rdev) != create->cr_specdata1 ||
1025 MINOR(rdev) != create->cr_specdata2)
1026 - return nfserr_inval;
1027 + goto out_umask;
1028 status = nfsd_create(rqstp, &cstate->current_fh,
1029 create->cr_name, create->cr_namelen,
1030 &create->cr_iattr, S_IFBLK, rdev, &resfh);
1031 break;
1032
1033 case NF4CHR:
1034 + status = nfserr_inval;
1035 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
1036 if (MAJOR(rdev) != create->cr_specdata1 ||
1037 MINOR(rdev) != create->cr_specdata2)
1038 - return nfserr_inval;
1039 + goto out_umask;
1040 status = nfsd_create(rqstp, &cstate->current_fh,
1041 create->cr_name, create->cr_namelen,
1042 &create->cr_iattr,S_IFCHR, rdev, &resfh);
1043 @@ -673,6 +679,8 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1044 fh_dup2(&cstate->current_fh, &resfh);
1045 out:
1046 fh_put(&resfh);
1047 +out_umask:
1048 + current->fs->umask = 0;
1049 return status;
1050 }
1051
1052 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
1053 index 2c61c6b8ae09..df2b8849a63b 100644
1054 --- a/fs/nfsd/nfs4xdr.c
1055 +++ b/fs/nfsd/nfs4xdr.c
1056 @@ -33,7 +33,6 @@
1057 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1058 */
1059
1060 -#include <linux/fs_struct.h>
1061 #include <linux/file.h>
1062 #include <linux/slab.h>
1063 #include <linux/namei.h>
1064 @@ -683,7 +682,7 @@ nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create
1065
1066 status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr,
1067 &create->cr_acl, &create->cr_label,
1068 - &current->fs->umask);
1069 + &create->cr_umask);
1070 if (status)
1071 goto out;
1072
1073 @@ -928,7 +927,6 @@ nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
1074 case NFS4_OPEN_NOCREATE:
1075 break;
1076 case NFS4_OPEN_CREATE:
1077 - current->fs->umask = 0;
1078 READ_BUF(4);
1079 open->op_createmode = be32_to_cpup(p++);
1080 switch (open->op_createmode) {
1081 @@ -936,7 +934,7 @@ nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
1082 case NFS4_CREATE_GUARDED:
1083 status = nfsd4_decode_fattr(argp, open->op_bmval,
1084 &open->op_iattr, &open->op_acl, &open->op_label,
1085 - &current->fs->umask);
1086 + &open->op_umask);
1087 if (status)
1088 goto out;
1089 break;
1090 @@ -951,7 +949,7 @@ nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
1091 COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE);
1092 status = nfsd4_decode_fattr(argp, open->op_bmval,
1093 &open->op_iattr, &open->op_acl, &open->op_label,
1094 - &current->fs->umask);
1095 + &open->op_umask);
1096 if (status)
1097 goto out;
1098 break;
1099 diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
1100 index 1e4edbf70052..aa4375eac475 100644
1101 --- a/fs/nfsd/xdr4.h
1102 +++ b/fs/nfsd/xdr4.h
1103 @@ -118,6 +118,7 @@ struct nfsd4_create {
1104 } u;
1105 u32 cr_bmval[3]; /* request */
1106 struct iattr cr_iattr; /* request */
1107 + int cr_umask; /* request */
1108 struct nfsd4_change_info cr_cinfo; /* response */
1109 struct nfs4_acl *cr_acl;
1110 struct xdr_netobj cr_label;
1111 @@ -228,6 +229,7 @@ struct nfsd4_open {
1112 u32 op_why_no_deleg; /* response - DELEG_NONE_EXT only */
1113 u32 op_create; /* request */
1114 u32 op_createmode; /* request */
1115 + int op_umask; /* request */
1116 u32 op_bmval[3]; /* request */
1117 struct iattr op_iattr; /* UNCHECKED4, GUARDED4, EXCLUSIVE4_1 */
1118 nfs4_verifier op_verf __attribute__((aligned(32)));
1119 diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
1120 index 4bb7e4f53ea6..8a10506db993 100644
1121 --- a/fs/overlayfs/namei.c
1122 +++ b/fs/overlayfs/namei.c
1123 @@ -56,6 +56,15 @@ static int ovl_check_redirect(struct dentry *dentry, struct ovl_lookup_data *d,
1124 if (s == next)
1125 goto invalid;
1126 }
1127 + /*
1128 + * One of the ancestor path elements in an absolute path
1129 + * lookup in ovl_lookup_layer() could have been opaque and
1130 + * that will stop further lookup in lower layers (d->stop=true)
1131 + * But we have found an absolute redirect in decendant path
1132 + * element and that should force continue lookup in lower
1133 + * layers (reset d->stop).
1134 + */
1135 + d->stop = false;
1136 } else {
1137 if (strchr(buf, '/') != NULL)
1138 goto invalid;
1139 diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
1140 index 95ccc1eef558..b619a190ff12 100644
1141 --- a/include/net/bluetooth/hci_core.h
1142 +++ b/include/net/bluetooth/hci_core.h
1143 @@ -895,7 +895,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
1144 u16 conn_timeout);
1145 struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
1146 u8 dst_type, u8 sec_level, u16 conn_timeout,
1147 - u8 role);
1148 + u8 role, bdaddr_t *direct_rpa);
1149 struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
1150 u8 sec_level, u8 auth_type);
1151 struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
1152 diff --git a/include/net/slhc_vj.h b/include/net/slhc_vj.h
1153 index 8716d5942b65..8fcf8908a694 100644
1154 --- a/include/net/slhc_vj.h
1155 +++ b/include/net/slhc_vj.h
1156 @@ -127,6 +127,7 @@ typedef __u32 int32;
1157 */
1158 struct cstate {
1159 byte_t cs_this; /* connection id number (xmit) */
1160 + bool initialized; /* true if initialized */
1161 struct cstate *next; /* next in ring (xmit) */
1162 struct iphdr cs_ip; /* ip/tcp hdr from most recent packet */
1163 struct tcphdr cs_tcp;
1164 diff --git a/kernel/events/core.c b/kernel/events/core.c
1165 index cecd72eb09b8..e9b0beca830f 100644
1166 --- a/kernel/events/core.c
1167 +++ b/kernel/events/core.c
1168 @@ -4199,6 +4199,9 @@ static void _free_event(struct perf_event *event)
1169 if (event->ctx)
1170 put_ctx(event->ctx);
1171
1172 + if (event->hw.target)
1173 + put_task_struct(event->hw.target);
1174 +
1175 exclusive_event_destroy(event);
1176 module_put(event->pmu->module);
1177
1178 @@ -9508,6 +9511,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
1179 * and we cannot use the ctx information because we need the
1180 * pmu before we get a ctx.
1181 */
1182 + get_task_struct(task);
1183 event->hw.target = task;
1184 }
1185
1186 @@ -9623,6 +9627,8 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
1187 perf_detach_cgroup(event);
1188 if (event->ns)
1189 put_pid_ns(event->ns);
1190 + if (event->hw.target)
1191 + put_task_struct(event->hw.target);
1192 kfree(event);
1193
1194 return ERR_PTR(err);
1195 diff --git a/lib/bitmap.c b/lib/bitmap.c
1196 index c82c61b66e16..2a9373ef4054 100644
1197 --- a/lib/bitmap.c
1198 +++ b/lib/bitmap.c
1199 @@ -605,7 +605,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
1200 /* if no digit is after '-', it's wrong*/
1201 if (at_start && in_range)
1202 return -EINVAL;
1203 - if (!(a <= b) || !(used_size <= group_size))
1204 + if (!(a <= b) || group_size == 0 || !(used_size <= group_size))
1205 return -EINVAL;
1206 if (b >= nmaskbits)
1207 return -ERANGE;
1208 diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
1209 index aa1f2669bdd5..0ddf293cfac3 100644
1210 --- a/lib/test_bitmap.c
1211 +++ b/lib/test_bitmap.c
1212 @@ -218,6 +218,10 @@ static const struct test_bitmap_parselist parselist_tests[] __initconst = {
1213 {-EINVAL, "-1", NULL, 8, 0},
1214 {-EINVAL, "-0", NULL, 8, 0},
1215 {-EINVAL, "10-1", NULL, 8, 0},
1216 + {-EINVAL, "0-31:", NULL, 8, 0},
1217 + {-EINVAL, "0-31:0", NULL, 8, 0},
1218 + {-EINVAL, "0-31:0/0", NULL, 8, 0},
1219 + {-EINVAL, "0-31:1/0", NULL, 8, 0},
1220 {-EINVAL, "0-31:10/1", NULL, 8, 0},
1221 };
1222
1223 diff --git a/mm/gup.c b/mm/gup.c
1224 index e0d82b6706d7..8fc23a60487d 100644
1225 --- a/mm/gup.c
1226 +++ b/mm/gup.c
1227 @@ -1816,9 +1816,12 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
1228 len = (unsigned long) nr_pages << PAGE_SHIFT;
1229 end = start + len;
1230
1231 + if (nr_pages <= 0)
1232 + return 0;
1233 +
1234 if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
1235 (void __user *)start, len)))
1236 - return 0;
1237 + return -EFAULT;
1238
1239 if (gup_fast_permitted(start, nr_pages, write)) {
1240 local_irq_disable();
1241 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
1242 index dc59eae54717..cc061495f653 100644
1243 --- a/net/bluetooth/hci_conn.c
1244 +++ b/net/bluetooth/hci_conn.c
1245 @@ -749,18 +749,31 @@ static bool conn_use_rpa(struct hci_conn *conn)
1246 }
1247
1248 static void hci_req_add_le_create_conn(struct hci_request *req,
1249 - struct hci_conn *conn)
1250 + struct hci_conn *conn,
1251 + bdaddr_t *direct_rpa)
1252 {
1253 struct hci_cp_le_create_conn cp;
1254 struct hci_dev *hdev = conn->hdev;
1255 u8 own_addr_type;
1256
1257 - /* Update random address, but set require_privacy to false so
1258 - * that we never connect with an non-resolvable address.
1259 + /* If direct address was provided we use it instead of current
1260 + * address.
1261 */
1262 - if (hci_update_random_address(req, false, conn_use_rpa(conn),
1263 - &own_addr_type))
1264 - return;
1265 + if (direct_rpa) {
1266 + if (bacmp(&req->hdev->random_addr, direct_rpa))
1267 + hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6,
1268 + direct_rpa);
1269 +
1270 + /* direct address is always RPA */
1271 + own_addr_type = ADDR_LE_DEV_RANDOM;
1272 + } else {
1273 + /* Update random address, but set require_privacy to false so
1274 + * that we never connect with an non-resolvable address.
1275 + */
1276 + if (hci_update_random_address(req, false, conn_use_rpa(conn),
1277 + &own_addr_type))
1278 + return;
1279 + }
1280
1281 memset(&cp, 0, sizeof(cp));
1282
1283 @@ -825,7 +838,7 @@ static void hci_req_directed_advertising(struct hci_request *req,
1284
1285 struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
1286 u8 dst_type, u8 sec_level, u16 conn_timeout,
1287 - u8 role)
1288 + u8 role, bdaddr_t *direct_rpa)
1289 {
1290 struct hci_conn_params *params;
1291 struct hci_conn *conn;
1292 @@ -940,7 +953,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
1293 hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED);
1294 }
1295
1296 - hci_req_add_le_create_conn(&req, conn);
1297 + hci_req_add_le_create_conn(&req, conn, direct_rpa);
1298
1299 create_conn:
1300 err = hci_req_run(&req, create_le_conn_complete);
1301 diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
1302 index 0b4dba08a14e..01f211e31f47 100644
1303 --- a/net/bluetooth/hci_event.c
1304 +++ b/net/bluetooth/hci_event.c
1305 @@ -4646,7 +4646,8 @@ static void hci_le_conn_update_complete_evt(struct hci_dev *hdev,
1306 /* This function requires the caller holds hdev->lock */
1307 static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
1308 bdaddr_t *addr,
1309 - u8 addr_type, u8 adv_type)
1310 + u8 addr_type, u8 adv_type,
1311 + bdaddr_t *direct_rpa)
1312 {
1313 struct hci_conn *conn;
1314 struct hci_conn_params *params;
1315 @@ -4697,7 +4698,8 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
1316 }
1317
1318 conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW,
1319 - HCI_LE_AUTOCONN_TIMEOUT, HCI_ROLE_MASTER);
1320 + HCI_LE_AUTOCONN_TIMEOUT, HCI_ROLE_MASTER,
1321 + direct_rpa);
1322 if (!IS_ERR(conn)) {
1323 /* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned
1324 * by higher layer that tried to connect, if no then
1325 @@ -4807,8 +4809,13 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
1326 bdaddr_type = irk->addr_type;
1327 }
1328
1329 - /* Check if we have been requested to connect to this device */
1330 - conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, type);
1331 + /* Check if we have been requested to connect to this device.
1332 + *
1333 + * direct_addr is set only for directed advertising reports (it is NULL
1334 + * for advertising reports) and is already verified to be RPA above.
1335 + */
1336 + conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, type,
1337 + direct_addr);
1338 if (conn && type == LE_ADV_IND) {
1339 /* Store report for later inclusion by
1340 * mgmt_device_connected
1341 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
1342 index fc6615d59165..9b7907ebfa01 100644
1343 --- a/net/bluetooth/l2cap_core.c
1344 +++ b/net/bluetooth/l2cap_core.c
1345 @@ -7156,7 +7156,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
1346 hcon = hci_connect_le(hdev, dst, dst_type,
1347 chan->sec_level,
1348 HCI_LE_CONN_TIMEOUT,
1349 - HCI_ROLE_SLAVE);
1350 + HCI_ROLE_SLAVE, NULL);
1351 else
1352 hcon = hci_connect_le_scan(hdev, dst, dst_type,
1353 chan->sec_level,
1354 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
1355 index cf84f7b37cd9..9d2ce1459cec 100644
1356 --- a/net/netfilter/ipset/ip_set_core.c
1357 +++ b/net/netfilter/ipset/ip_set_core.c
1358 @@ -2055,6 +2055,7 @@ ip_set_net_exit(struct net *net)
1359
1360 inst->is_deleted = true; /* flag for ip_set_nfnl_put */
1361
1362 + nfnl_lock(NFNL_SUBSYS_IPSET);
1363 for (i = 0; i < inst->ip_set_max; i++) {
1364 set = ip_set(inst, i);
1365 if (set) {
1366 @@ -2062,6 +2063,7 @@ ip_set_net_exit(struct net *net)
1367 ip_set_destroy_set(set);
1368 }
1369 }
1370 + nfnl_unlock(NFNL_SUBSYS_IPSET);
1371 kfree(rcu_dereference_protected(inst->ip_set_list, 1));
1372 }
1373
1374 diff --git a/net/rds/send.c b/net/rds/send.c
1375 index f72466c63f0c..23f2d81e7967 100644
1376 --- a/net/rds/send.c
1377 +++ b/net/rds/send.c
1378 @@ -1,5 +1,5 @@
1379 /*
1380 - * Copyright (c) 2006 Oracle. All rights reserved.
1381 + * Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
1382 *
1383 * This software is available to you under a choice of one of two
1384 * licenses. You may choose to be licensed under the terms of the GNU
1385 @@ -986,10 +986,15 @@ static int rds_send_mprds_hash(struct rds_sock *rs, struct rds_connection *conn)
1386 if (conn->c_npaths == 0 && hash != 0) {
1387 rds_send_ping(conn, 0);
1388
1389 - if (conn->c_npaths == 0) {
1390 - wait_event_interruptible(conn->c_hs_waitq,
1391 - (conn->c_npaths != 0));
1392 - }
1393 + /* The underlying connection is not up yet. Need to wait
1394 + * until it is up to be sure that the non-zero c_path can be
1395 + * used. But if we are interrupted, we have to use the zero
1396 + * c_path in case the connection ends up being non-MP capable.
1397 + */
1398 + if (conn->c_npaths == 0)
1399 + if (wait_event_interruptible(conn->c_hs_waitq,
1400 + conn->c_npaths != 0))
1401 + hash = 0;
1402 if (conn->c_npaths == 1)
1403 hash = 0;
1404 }
1405 diff --git a/net/sunrpc/auth_gss/gss_krb5_crypto.c b/net/sunrpc/auth_gss/gss_krb5_crypto.c
1406 index 12649c9fedab..8654494b4d0a 100644
1407 --- a/net/sunrpc/auth_gss/gss_krb5_crypto.c
1408 +++ b/net/sunrpc/auth_gss/gss_krb5_crypto.c
1409 @@ -237,9 +237,6 @@ make_checksum_hmac_md5(struct krb5_ctx *kctx, char *header, int hdrlen,
1410
1411 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL, NULL);
1412
1413 - err = crypto_ahash_init(req);
1414 - if (err)
1415 - goto out;
1416 err = crypto_ahash_setkey(hmac_md5, cksumkey, kctx->gk5e->keylength);
1417 if (err)
1418 goto out;
1419 diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
1420 index caaf51dda648..0e03377bb83e 100644
1421 --- a/security/apparmor/apparmorfs.c
1422 +++ b/security/apparmor/apparmorfs.c
1423 @@ -1189,9 +1189,7 @@ static int seq_ns_level_show(struct seq_file *seq, void *v)
1424 static int seq_ns_name_show(struct seq_file *seq, void *v)
1425 {
1426 struct aa_label *label = begin_current_label_crit_section();
1427 -
1428 - seq_printf(seq, "%s\n", aa_ns_name(labels_ns(label),
1429 - labels_ns(label), true));
1430 + seq_printf(seq, "%s\n", labels_ns(label)->base.name);
1431 end_current_label_crit_section(label);
1432
1433 return 0;
1434 diff --git a/security/apparmor/include/audit.h b/security/apparmor/include/audit.h
1435 index 4ac095118717..2ebc00a579fd 100644
1436 --- a/security/apparmor/include/audit.h
1437 +++ b/security/apparmor/include/audit.h
1438 @@ -126,6 +126,10 @@ struct apparmor_audit_data {
1439 const char *target;
1440 kuid_t ouid;
1441 } fs;
1442 + struct {
1443 + int rlim;
1444 + unsigned long max;
1445 + } rlim;
1446 int signal;
1447 };
1448 };
1449 @@ -134,10 +138,6 @@ struct apparmor_audit_data {
1450 const char *ns;
1451 long pos;
1452 } iface;
1453 - struct {
1454 - int rlim;
1455 - unsigned long max;
1456 - } rlim;
1457 struct {
1458 const char *src_name;
1459 const char *type;
1460 diff --git a/security/apparmor/include/sig_names.h b/security/apparmor/include/sig_names.h
1461 index 92e62fe95292..5ca47c50dfa7 100644
1462 --- a/security/apparmor/include/sig_names.h
1463 +++ b/security/apparmor/include/sig_names.h
1464 @@ -2,6 +2,8 @@
1465
1466 #define SIGUNKNOWN 0
1467 #define MAXMAPPED_SIG 35
1468 +#define MAXMAPPED_SIGNAME (MAXMAPPED_SIG + 1)
1469 +
1470 /* provide a mapping of arch signal to internal signal # for mediation
1471 * those that are always an alias SIGCLD for SIGCLHD and SIGPOLL for SIGIO
1472 * map to the same entry those that may/or may not get a separate entry
1473 @@ -56,7 +58,7 @@ static const int sig_map[MAXMAPPED_SIG] = {
1474 };
1475
1476 /* this table is ordered post sig_map[sig] mapping */
1477 -static const char *const sig_names[MAXMAPPED_SIG + 1] = {
1478 +static const char *const sig_names[MAXMAPPED_SIGNAME] = {
1479 "unknown",
1480 "hup",
1481 "int",
1482 diff --git a/security/apparmor/ipc.c b/security/apparmor/ipc.c
1483 index b40678f3c1d5..586facd35f7c 100644
1484 --- a/security/apparmor/ipc.c
1485 +++ b/security/apparmor/ipc.c
1486 @@ -174,7 +174,7 @@ static void audit_signal_cb(struct audit_buffer *ab, void *va)
1487 audit_signal_mask(ab, aad(sa)->denied);
1488 }
1489 }
1490 - if (aad(sa)->signal < MAXMAPPED_SIG)
1491 + if (aad(sa)->signal < MAXMAPPED_SIGNAME)
1492 audit_log_format(ab, " signal=%s", sig_names[aad(sa)->signal]);
1493 else
1494 audit_log_format(ab, " signal=rtmin+%d",
1495 diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
1496 index aa1593ce551d..f9157aed1289 100644
1497 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
1498 +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
1499 @@ -1378,6 +1378,7 @@ static int intel_pt_overflow(struct intel_pt_decoder *decoder)
1500 intel_pt_clear_tx_flags(decoder);
1501 decoder->have_tma = false;
1502 decoder->cbr = 0;
1503 + decoder->timestamp_insn_cnt = 0;
1504 decoder->pkt_state = INTEL_PT_STATE_ERR_RESYNC;
1505 decoder->overflow = true;
1506 return -EOVERFLOW;
1507 @@ -1616,6 +1617,7 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
1508 case INTEL_PT_PWRX:
1509 intel_pt_log("ERROR: Missing TIP after FUP\n");
1510 decoder->pkt_state = INTEL_PT_STATE_ERR3;
1511 + decoder->pkt_step = 0;
1512 return -ENOENT;
1513
1514 case INTEL_PT_OVF:
1515 @@ -2390,14 +2392,6 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
1516 return &decoder->state;
1517 }
1518
1519 -static bool intel_pt_at_psb(unsigned char *buf, size_t len)
1520 -{
1521 - if (len < INTEL_PT_PSB_LEN)
1522 - return false;
1523 - return memmem(buf, INTEL_PT_PSB_LEN, INTEL_PT_PSB_STR,
1524 - INTEL_PT_PSB_LEN);
1525 -}
1526 -
1527 /**
1528 * intel_pt_next_psb - move buffer pointer to the start of the next PSB packet.
1529 * @buf: pointer to buffer pointer
1530 @@ -2486,6 +2480,7 @@ static unsigned char *intel_pt_last_psb(unsigned char *buf, size_t len)
1531 * @buf: buffer
1532 * @len: size of buffer
1533 * @tsc: TSC value returned
1534 + * @rem: returns remaining size when TSC is found
1535 *
1536 * Find a TSC packet in @buf and return the TSC value. This function assumes
1537 * that @buf starts at a PSB and that PSB+ will contain TSC and so stops if a
1538 @@ -2493,7 +2488,8 @@ static unsigned char *intel_pt_last_psb(unsigned char *buf, size_t len)
1539 *
1540 * Return: %true if TSC is found, false otherwise.
1541 */
1542 -static bool intel_pt_next_tsc(unsigned char *buf, size_t len, uint64_t *tsc)
1543 +static bool intel_pt_next_tsc(unsigned char *buf, size_t len, uint64_t *tsc,
1544 + size_t *rem)
1545 {
1546 struct intel_pt_pkt packet;
1547 int ret;
1548 @@ -2504,6 +2500,7 @@ static bool intel_pt_next_tsc(unsigned char *buf, size_t len, uint64_t *tsc)
1549 return false;
1550 if (packet.type == INTEL_PT_TSC) {
1551 *tsc = packet.payload;
1552 + *rem = len;
1553 return true;
1554 }
1555 if (packet.type == INTEL_PT_PSBEND)
1556 @@ -2554,6 +2551,8 @@ static int intel_pt_tsc_cmp(uint64_t tsc1, uint64_t tsc2)
1557 * @len_a: size of first buffer
1558 * @buf_b: second buffer
1559 * @len_b: size of second buffer
1560 + * @consecutive: returns true if there is data in buf_b that is consecutive
1561 + * to buf_a
1562 *
1563 * If the trace contains TSC we can look at the last TSC of @buf_a and the
1564 * first TSC of @buf_b in order to determine if the buffers overlap, and then
1565 @@ -2566,33 +2565,41 @@ static int intel_pt_tsc_cmp(uint64_t tsc1, uint64_t tsc2)
1566 static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a,
1567 size_t len_a,
1568 unsigned char *buf_b,
1569 - size_t len_b)
1570 + size_t len_b, bool *consecutive)
1571 {
1572 uint64_t tsc_a, tsc_b;
1573 unsigned char *p;
1574 - size_t len;
1575 + size_t len, rem_a, rem_b;
1576
1577 p = intel_pt_last_psb(buf_a, len_a);
1578 if (!p)
1579 return buf_b; /* No PSB in buf_a => no overlap */
1580
1581 len = len_a - (p - buf_a);
1582 - if (!intel_pt_next_tsc(p, len, &tsc_a)) {
1583 + if (!intel_pt_next_tsc(p, len, &tsc_a, &rem_a)) {
1584 /* The last PSB+ in buf_a is incomplete, so go back one more */
1585 len_a -= len;
1586 p = intel_pt_last_psb(buf_a, len_a);
1587 if (!p)
1588 return buf_b; /* No full PSB+ => assume no overlap */
1589 len = len_a - (p - buf_a);
1590 - if (!intel_pt_next_tsc(p, len, &tsc_a))
1591 + if (!intel_pt_next_tsc(p, len, &tsc_a, &rem_a))
1592 return buf_b; /* No TSC in buf_a => assume no overlap */
1593 }
1594
1595 while (1) {
1596 /* Ignore PSB+ with no TSC */
1597 - if (intel_pt_next_tsc(buf_b, len_b, &tsc_b) &&
1598 - intel_pt_tsc_cmp(tsc_a, tsc_b) < 0)
1599 - return buf_b; /* tsc_a < tsc_b => no overlap */
1600 + if (intel_pt_next_tsc(buf_b, len_b, &tsc_b, &rem_b)) {
1601 + int cmp = intel_pt_tsc_cmp(tsc_a, tsc_b);
1602 +
1603 + /* Same TSC, so buffers are consecutive */
1604 + if (!cmp && rem_b >= rem_a) {
1605 + *consecutive = true;
1606 + return buf_b + len_b - (rem_b - rem_a);
1607 + }
1608 + if (cmp < 0)
1609 + return buf_b; /* tsc_a < tsc_b => no overlap */
1610 + }
1611
1612 if (!intel_pt_step_psb(&buf_b, &len_b))
1613 return buf_b + len_b; /* No PSB in buf_b => no data */
1614 @@ -2606,6 +2613,8 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a,
1615 * @buf_b: second buffer
1616 * @len_b: size of second buffer
1617 * @have_tsc: can use TSC packets to detect overlap
1618 + * @consecutive: returns true if there is data in buf_b that is consecutive
1619 + * to buf_a
1620 *
1621 * When trace samples or snapshots are recorded there is the possibility that
1622 * the data overlaps. Note that, for the purposes of decoding, data is only
1623 @@ -2616,7 +2625,7 @@ static unsigned char *intel_pt_find_overlap_tsc(unsigned char *buf_a,
1624 */
1625 unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
1626 unsigned char *buf_b, size_t len_b,
1627 - bool have_tsc)
1628 + bool have_tsc, bool *consecutive)
1629 {
1630 unsigned char *found;
1631
1632 @@ -2628,7 +2637,8 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
1633 return buf_b; /* No overlap */
1634
1635 if (have_tsc) {
1636 - found = intel_pt_find_overlap_tsc(buf_a, len_a, buf_b, len_b);
1637 + found = intel_pt_find_overlap_tsc(buf_a, len_a, buf_b, len_b,
1638 + consecutive);
1639 if (found)
1640 return found;
1641 }
1642 @@ -2643,28 +2653,16 @@ unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
1643 }
1644
1645 /* Now len_b >= len_a */
1646 - if (len_b > len_a) {
1647 - /* The leftover buffer 'b' must start at a PSB */
1648 - while (!intel_pt_at_psb(buf_b + len_a, len_b - len_a)) {
1649 - if (!intel_pt_step_psb(&buf_a, &len_a))
1650 - return buf_b; /* No overlap */
1651 - }
1652 - }
1653 -
1654 while (1) {
1655 /* Potential overlap so check the bytes */
1656 found = memmem(buf_a, len_a, buf_b, len_a);
1657 - if (found)
1658 + if (found) {
1659 + *consecutive = true;
1660 return buf_b + len_a;
1661 + }
1662
1663 /* Try again at next PSB in buffer 'a' */
1664 if (!intel_pt_step_psb(&buf_a, &len_a))
1665 return buf_b; /* No overlap */
1666 -
1667 - /* The leftover buffer 'b' must start at a PSB */
1668 - while (!intel_pt_at_psb(buf_b + len_a, len_b - len_a)) {
1669 - if (!intel_pt_step_psb(&buf_a, &len_a))
1670 - return buf_b; /* No overlap */
1671 - }
1672 }
1673 }
1674 diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
1675 index 921b22e8ca0e..fc1752d50019 100644
1676 --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
1677 +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
1678 @@ -117,7 +117,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder);
1679
1680 unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
1681 unsigned char *buf_b, size_t len_b,
1682 - bool have_tsc);
1683 + bool have_tsc, bool *consecutive);
1684
1685 int intel_pt__strerror(int code, char *buf, size_t buflen);
1686
1687 diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
1688 index b58f9fd1e2ee..d9573c1fa555 100644
1689 --- a/tools/perf/util/intel-pt.c
1690 +++ b/tools/perf/util/intel-pt.c
1691 @@ -145,6 +145,7 @@ struct intel_pt_queue {
1692 bool stop;
1693 bool step_through_buffers;
1694 bool use_buffer_pid_tid;
1695 + bool sync_switch;
1696 pid_t pid, tid;
1697 int cpu;
1698 int switch_state;
1699 @@ -209,14 +210,17 @@ static void intel_pt_dump_event(struct intel_pt *pt, unsigned char *buf,
1700 static int intel_pt_do_fix_overlap(struct intel_pt *pt, struct auxtrace_buffer *a,
1701 struct auxtrace_buffer *b)
1702 {
1703 + bool consecutive = false;
1704 void *start;
1705
1706 start = intel_pt_find_overlap(a->data, a->size, b->data, b->size,
1707 - pt->have_tsc);
1708 + pt->have_tsc, &consecutive);
1709 if (!start)
1710 return -EINVAL;
1711 b->use_size = b->data + b->size - start;
1712 b->use_data = start;
1713 + if (b->use_size && consecutive)
1714 + b->consecutive = true;
1715 return 0;
1716 }
1717
1718 @@ -962,10 +966,12 @@ static int intel_pt_setup_queue(struct intel_pt *pt,
1719 if (pt->timeless_decoding || !pt->have_sched_switch)
1720 ptq->use_buffer_pid_tid = true;
1721 }
1722 +
1723 + ptq->sync_switch = pt->sync_switch;
1724 }
1725
1726 if (!ptq->on_heap &&
1727 - (!pt->sync_switch ||
1728 + (!ptq->sync_switch ||
1729 ptq->switch_state != INTEL_PT_SS_EXPECTING_SWITCH_EVENT)) {
1730 const struct intel_pt_state *state;
1731 int ret;
1732 @@ -1549,7 +1555,7 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
1733 if (pt->synth_opts.last_branch)
1734 intel_pt_update_last_branch_rb(ptq);
1735
1736 - if (!pt->sync_switch)
1737 + if (!ptq->sync_switch)
1738 return 0;
1739
1740 if (intel_pt_is_switch_ip(ptq, state->to_ip)) {
1741 @@ -1630,6 +1636,21 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)
1742 return switch_ip;
1743 }
1744
1745 +static void intel_pt_enable_sync_switch(struct intel_pt *pt)
1746 +{
1747 + unsigned int i;
1748 +
1749 + pt->sync_switch = true;
1750 +
1751 + for (i = 0; i < pt->queues.nr_queues; i++) {
1752 + struct auxtrace_queue *queue = &pt->queues.queue_array[i];
1753 + struct intel_pt_queue *ptq = queue->priv;
1754 +
1755 + if (ptq)
1756 + ptq->sync_switch = true;
1757 + }
1758 +}
1759 +
1760 static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp)
1761 {
1762 const struct intel_pt_state *state = ptq->state;
1763 @@ -1646,7 +1667,7 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp)
1764 if (pt->switch_ip) {
1765 intel_pt_log("switch_ip: %"PRIx64" ptss_ip: %"PRIx64"\n",
1766 pt->switch_ip, pt->ptss_ip);
1767 - pt->sync_switch = true;
1768 + intel_pt_enable_sync_switch(pt);
1769 }
1770 }
1771 }
1772 @@ -1662,9 +1683,9 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp)
1773 if (state->err) {
1774 if (state->err == INTEL_PT_ERR_NODATA)
1775 return 1;
1776 - if (pt->sync_switch &&
1777 + if (ptq->sync_switch &&
1778 state->from_ip >= pt->kernel_start) {
1779 - pt->sync_switch = false;
1780 + ptq->sync_switch = false;
1781 intel_pt_next_tid(pt, ptq);
1782 }
1783 if (pt->synth_opts.errors) {
1784 @@ -1690,7 +1711,7 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp)
1785 state->timestamp, state->est_timestamp);
1786 ptq->timestamp = state->est_timestamp;
1787 /* Use estimated TSC in unknown switch state */
1788 - } else if (pt->sync_switch &&
1789 + } else if (ptq->sync_switch &&
1790 ptq->switch_state == INTEL_PT_SS_UNKNOWN &&
1791 intel_pt_is_switch_ip(ptq, state->to_ip) &&
1792 ptq->next_tid == -1) {
1793 @@ -1837,7 +1858,7 @@ static int intel_pt_sync_switch(struct intel_pt *pt, int cpu, pid_t tid,
1794 return 1;
1795
1796 ptq = intel_pt_cpu_to_ptq(pt, cpu);
1797 - if (!ptq)
1798 + if (!ptq || !ptq->sync_switch)
1799 return 1;
1800
1801 switch (ptq->switch_state) {