Magellan Linux

Contents of /trunk/kernel-alx/patches-4.14/0138-4.14.39-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, 6 months ago) by niro
File size: 117374 byte(s)
-added up to patches-4.14.79
1 diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
2 index 0f9089416b4c..88ad78c6f605 100644
3 --- a/Documentation/virtual/kvm/api.txt
4 +++ b/Documentation/virtual/kvm/api.txt
5 @@ -1940,6 +1940,9 @@ ARM 32-bit VFP control registers have the following id bit patterns:
6 ARM 64-bit FP registers have the following id bit patterns:
7 0x4030 0000 0012 0 <regno:12>
8
9 +ARM firmware pseudo-registers have the following bit pattern:
10 + 0x4030 0000 0014 <regno:16>
11 +
12
13 arm64 registers are mapped using the lower 32 bits. The upper 16 of
14 that is the register group type, or coprocessor number:
15 @@ -1956,6 +1959,9 @@ arm64 CCSIDR registers are demultiplexed by CSSELR value:
16 arm64 system registers have the following id bit patterns:
17 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3>
18
19 +arm64 firmware pseudo-registers have the following bit pattern:
20 + 0x6030 0000 0014 <regno:16>
21 +
22
23 MIPS registers are mapped using the lower 32 bits. The upper 16 of that is
24 the register group type:
25 @@ -2490,7 +2496,8 @@ Possible features:
26 and execute guest code when KVM_RUN is called.
27 - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode.
28 Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
29 - - KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 for the CPU.
30 + - KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 (or a future revision
31 + backward compatible with v0.2) for the CPU.
32 Depends on KVM_CAP_ARM_PSCI_0_2.
33 - KVM_ARM_VCPU_PMU_V3: Emulate PMUv3 for the CPU.
34 Depends on KVM_CAP_ARM_PMU_V3.
35 diff --git a/Documentation/virtual/kvm/arm/psci.txt b/Documentation/virtual/kvm/arm/psci.txt
36 new file mode 100644
37 index 000000000000..aafdab887b04
38 --- /dev/null
39 +++ b/Documentation/virtual/kvm/arm/psci.txt
40 @@ -0,0 +1,30 @@
41 +KVM implements the PSCI (Power State Coordination Interface)
42 +specification in order to provide services such as CPU on/off, reset
43 +and power-off to the guest.
44 +
45 +The PSCI specification is regularly updated to provide new features,
46 +and KVM implements these updates if they make sense from a virtualization
47 +point of view.
48 +
49 +This means that a guest booted on two different versions of KVM can
50 +observe two different "firmware" revisions. This could cause issues if
51 +a given guest is tied to a particular PSCI revision (unlikely), or if
52 +a migration causes a different PSCI version to be exposed out of the
53 +blue to an unsuspecting guest.
54 +
55 +In order to remedy this situation, KVM exposes a set of "firmware
56 +pseudo-registers" that can be manipulated using the GET/SET_ONE_REG
57 +interface. These registers can be saved/restored by userspace, and set
58 +to a convenient value if required.
59 +
60 +The following register is defined:
61 +
62 +* KVM_REG_ARM_PSCI_VERSION:
63 +
64 + - Only valid if the vcpu has the KVM_ARM_VCPU_PSCI_0_2 feature set
65 + (and thus has already been initialized)
66 + - Returns the current PSCI version on GET_ONE_REG (defaulting to the
67 + highest PSCI version implemented by KVM and compatible with v0.2)
68 + - Allows any PSCI version implemented by KVM and compatible with
69 + v0.2 to be set with SET_ONE_REG
70 + - Affects the whole VM (even if the register view is per-vcpu)
71 diff --git a/Makefile b/Makefile
72 index 27a8d5c37180..248b99283f71 100644
73 --- a/Makefile
74 +++ b/Makefile
75 @@ -1,7 +1,7 @@
76 # SPDX-License-Identifier: GPL-2.0
77 VERSION = 4
78 PATCHLEVEL = 14
79 -SUBLEVEL = 38
80 +SUBLEVEL = 39
81 EXTRAVERSION =
82 NAME = Petit Gorille
83
84 diff --git a/arch/arm/configs/socfpga_defconfig b/arch/arm/configs/socfpga_defconfig
85 index 2620ce790db0..371fca4e1ab7 100644
86 --- a/arch/arm/configs/socfpga_defconfig
87 +++ b/arch/arm/configs/socfpga_defconfig
88 @@ -57,6 +57,7 @@ CONFIG_MTD_M25P80=y
89 CONFIG_MTD_NAND=y
90 CONFIG_MTD_NAND_DENALI_DT=y
91 CONFIG_MTD_SPI_NOR=y
92 +# CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is not set
93 CONFIG_SPI_CADENCE_QUADSPI=y
94 CONFIG_OF_OVERLAY=y
95 CONFIG_OF_CONFIGFS=y
96 diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
97 index 31fbb9285f62..8f973e3b7348 100644
98 --- a/arch/arm/include/asm/kvm_host.h
99 +++ b/arch/arm/include/asm/kvm_host.h
100 @@ -75,6 +75,9 @@ struct kvm_arch {
101 /* Interrupt controller */
102 struct vgic_dist vgic;
103 int max_vcpus;
104 +
105 + /* Mandated version of PSCI */
106 + u32 psci_version;
107 };
108
109 #define KVM_NR_MEM_OBJS 40
110 diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h
111 index 1f57bbe82b6f..df24fc8da1bc 100644
112 --- a/arch/arm/include/uapi/asm/kvm.h
113 +++ b/arch/arm/include/uapi/asm/kvm.h
114 @@ -180,6 +180,12 @@ struct kvm_arch_memory_slot {
115 #define KVM_REG_ARM_VFP_FPINST 0x1009
116 #define KVM_REG_ARM_VFP_FPINST2 0x100A
117
118 +/* KVM-as-firmware specific pseudo-registers */
119 +#define KVM_REG_ARM_FW (0x0014 << KVM_REG_ARM_COPROC_SHIFT)
120 +#define KVM_REG_ARM_FW_REG(r) (KVM_REG_ARM | KVM_REG_SIZE_U64 | \
121 + KVM_REG_ARM_FW | ((r) & 0xffff))
122 +#define KVM_REG_ARM_PSCI_VERSION KVM_REG_ARM_FW_REG(0)
123 +
124 /* Device Control API: ARM VGIC */
125 #define KVM_DEV_ARM_VGIC_GRP_ADDR 0
126 #define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
127 diff --git a/arch/arm/kvm/guest.c b/arch/arm/kvm/guest.c
128 index 1e0784ebbfd6..a18f33edc471 100644
129 --- a/arch/arm/kvm/guest.c
130 +++ b/arch/arm/kvm/guest.c
131 @@ -22,6 +22,7 @@
132 #include <linux/module.h>
133 #include <linux/vmalloc.h>
134 #include <linux/fs.h>
135 +#include <kvm/arm_psci.h>
136 #include <asm/cputype.h>
137 #include <linux/uaccess.h>
138 #include <asm/kvm.h>
139 @@ -176,6 +177,7 @@ static unsigned long num_core_regs(void)
140 unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu)
141 {
142 return num_core_regs() + kvm_arm_num_coproc_regs(vcpu)
143 + + kvm_arm_get_fw_num_regs(vcpu)
144 + NUM_TIMER_REGS;
145 }
146
147 @@ -196,6 +198,11 @@ int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices)
148 uindices++;
149 }
150
151 + ret = kvm_arm_copy_fw_reg_indices(vcpu, uindices);
152 + if (ret)
153 + return ret;
154 + uindices += kvm_arm_get_fw_num_regs(vcpu);
155 +
156 ret = copy_timer_indices(vcpu, uindices);
157 if (ret)
158 return ret;
159 @@ -214,6 +221,9 @@ int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
160 if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_CORE)
161 return get_core_reg(vcpu, reg);
162
163 + if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_FW)
164 + return kvm_arm_get_fw_reg(vcpu, reg);
165 +
166 if (is_timer_reg(reg->id))
167 return get_timer_reg(vcpu, reg);
168
169 @@ -230,6 +240,9 @@ int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
170 if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_CORE)
171 return set_core_reg(vcpu, reg);
172
173 + if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_FW)
174 + return kvm_arm_set_fw_reg(vcpu, reg);
175 +
176 if (is_timer_reg(reg->id))
177 return set_timer_reg(vcpu, reg);
178
179 diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
180 index 8ad208cb866c..8abec9f7f430 100644
181 --- a/arch/arm64/include/asm/kvm_host.h
182 +++ b/arch/arm64/include/asm/kvm_host.h
183 @@ -71,6 +71,9 @@ struct kvm_arch {
184
185 /* Interrupt controller */
186 struct vgic_dist vgic;
187 +
188 + /* Mandated version of PSCI */
189 + u32 psci_version;
190 };
191
192 #define KVM_NR_MEM_OBJS 40
193 diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
194 index 51149ec75fe4..9f74ce5899f0 100644
195 --- a/arch/arm64/include/uapi/asm/kvm.h
196 +++ b/arch/arm64/include/uapi/asm/kvm.h
197 @@ -200,6 +200,12 @@ struct kvm_arch_memory_slot {
198 #define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2)
199 #define KVM_REG_ARM_TIMER_CVAL ARM64_SYS_REG(3, 3, 14, 0, 2)
200
201 +/* KVM-as-firmware specific pseudo-registers */
202 +#define KVM_REG_ARM_FW (0x0014 << KVM_REG_ARM_COPROC_SHIFT)
203 +#define KVM_REG_ARM_FW_REG(r) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
204 + KVM_REG_ARM_FW | ((r) & 0xffff))
205 +#define KVM_REG_ARM_PSCI_VERSION KVM_REG_ARM_FW_REG(0)
206 +
207 /* Device Control API: ARM VGIC */
208 #define KVM_DEV_ARM_VGIC_GRP_ADDR 0
209 #define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
210 diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
211 index 5c7f657dd207..811f04c5760e 100644
212 --- a/arch/arm64/kvm/guest.c
213 +++ b/arch/arm64/kvm/guest.c
214 @@ -25,6 +25,7 @@
215 #include <linux/module.h>
216 #include <linux/vmalloc.h>
217 #include <linux/fs.h>
218 +#include <kvm/arm_psci.h>
219 #include <asm/cputype.h>
220 #include <linux/uaccess.h>
221 #include <asm/kvm.h>
222 @@ -205,7 +206,7 @@ static int get_timer_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
223 unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu)
224 {
225 return num_core_regs() + kvm_arm_num_sys_reg_descs(vcpu)
226 - + NUM_TIMER_REGS;
227 + + kvm_arm_get_fw_num_regs(vcpu) + NUM_TIMER_REGS;
228 }
229
230 /**
231 @@ -225,6 +226,11 @@ int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices)
232 uindices++;
233 }
234
235 + ret = kvm_arm_copy_fw_reg_indices(vcpu, uindices);
236 + if (ret)
237 + return ret;
238 + uindices += kvm_arm_get_fw_num_regs(vcpu);
239 +
240 ret = copy_timer_indices(vcpu, uindices);
241 if (ret)
242 return ret;
243 @@ -243,6 +249,9 @@ int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
244 if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_CORE)
245 return get_core_reg(vcpu, reg);
246
247 + if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_FW)
248 + return kvm_arm_get_fw_reg(vcpu, reg);
249 +
250 if (is_timer_reg(reg->id))
251 return get_timer_reg(vcpu, reg);
252
253 @@ -259,6 +268,9 @@ int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
254 if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_CORE)
255 return set_core_reg(vcpu, reg);
256
257 + if ((reg->id & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_FW)
258 + return kvm_arm_set_fw_reg(vcpu, reg);
259 +
260 if (is_timer_reg(reg->id))
261 return set_timer_reg(vcpu, reg);
262
263 diff --git a/arch/powerpc/kernel/eeh_driver.c b/arch/powerpc/kernel/eeh_driver.c
264 index 8b840191df59..ca2243df9cb2 100644
265 --- a/arch/powerpc/kernel/eeh_driver.c
266 +++ b/arch/powerpc/kernel/eeh_driver.c
267 @@ -207,18 +207,18 @@ static void *eeh_report_error(void *data, void *userdata)
268
269 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
270 return NULL;
271 +
272 + device_lock(&dev->dev);
273 dev->error_state = pci_channel_io_frozen;
274
275 driver = eeh_pcid_get(dev);
276 - if (!driver) return NULL;
277 + if (!driver) goto out_no_dev;
278
279 eeh_disable_irq(dev);
280
281 if (!driver->err_handler ||
282 - !driver->err_handler->error_detected) {
283 - eeh_pcid_put(dev);
284 - return NULL;
285 - }
286 + !driver->err_handler->error_detected)
287 + goto out;
288
289 rc = driver->err_handler->error_detected(dev, pci_channel_io_frozen);
290
291 @@ -227,7 +227,10 @@ static void *eeh_report_error(void *data, void *userdata)
292 if (*res == PCI_ERS_RESULT_NONE) *res = rc;
293
294 edev->in_error = true;
295 +out:
296 eeh_pcid_put(dev);
297 +out_no_dev:
298 + device_unlock(&dev->dev);
299 return NULL;
300 }
301
302 @@ -250,15 +253,14 @@ static void *eeh_report_mmio_enabled(void *data, void *userdata)
303 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
304 return NULL;
305
306 + device_lock(&dev->dev);
307 driver = eeh_pcid_get(dev);
308 - if (!driver) return NULL;
309 + if (!driver) goto out_no_dev;
310
311 if (!driver->err_handler ||
312 !driver->err_handler->mmio_enabled ||
313 - (edev->mode & EEH_DEV_NO_HANDLER)) {
314 - eeh_pcid_put(dev);
315 - return NULL;
316 - }
317 + (edev->mode & EEH_DEV_NO_HANDLER))
318 + goto out;
319
320 rc = driver->err_handler->mmio_enabled(dev);
321
322 @@ -266,7 +268,10 @@ static void *eeh_report_mmio_enabled(void *data, void *userdata)
323 if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
324 if (*res == PCI_ERS_RESULT_NONE) *res = rc;
325
326 +out:
327 eeh_pcid_put(dev);
328 +out_no_dev:
329 + device_unlock(&dev->dev);
330 return NULL;
331 }
332
333 @@ -289,20 +294,20 @@ static void *eeh_report_reset(void *data, void *userdata)
334
335 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
336 return NULL;
337 +
338 + device_lock(&dev->dev);
339 dev->error_state = pci_channel_io_normal;
340
341 driver = eeh_pcid_get(dev);
342 - if (!driver) return NULL;
343 + if (!driver) goto out_no_dev;
344
345 eeh_enable_irq(dev);
346
347 if (!driver->err_handler ||
348 !driver->err_handler->slot_reset ||
349 (edev->mode & EEH_DEV_NO_HANDLER) ||
350 - (!edev->in_error)) {
351 - eeh_pcid_put(dev);
352 - return NULL;
353 - }
354 + (!edev->in_error))
355 + goto out;
356
357 rc = driver->err_handler->slot_reset(dev);
358 if ((*res == PCI_ERS_RESULT_NONE) ||
359 @@ -310,7 +315,10 @@ static void *eeh_report_reset(void *data, void *userdata)
360 if (*res == PCI_ERS_RESULT_DISCONNECT &&
361 rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
362
363 +out:
364 eeh_pcid_put(dev);
365 +out_no_dev:
366 + device_unlock(&dev->dev);
367 return NULL;
368 }
369
370 @@ -361,10 +369,12 @@ static void *eeh_report_resume(void *data, void *userdata)
371
372 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
373 return NULL;
374 +
375 + device_lock(&dev->dev);
376 dev->error_state = pci_channel_io_normal;
377
378 driver = eeh_pcid_get(dev);
379 - if (!driver) return NULL;
380 + if (!driver) goto out_no_dev;
381
382 was_in_error = edev->in_error;
383 edev->in_error = false;
384 @@ -374,13 +384,15 @@ static void *eeh_report_resume(void *data, void *userdata)
385 !driver->err_handler->resume ||
386 (edev->mode & EEH_DEV_NO_HANDLER) || !was_in_error) {
387 edev->mode &= ~EEH_DEV_NO_HANDLER;
388 - eeh_pcid_put(dev);
389 - return NULL;
390 + goto out;
391 }
392
393 driver->err_handler->resume(dev);
394
395 +out:
396 eeh_pcid_put(dev);
397 +out_no_dev:
398 + device_unlock(&dev->dev);
399 return NULL;
400 }
401
402 @@ -400,22 +412,25 @@ static void *eeh_report_failure(void *data, void *userdata)
403
404 if (!dev || eeh_dev_removed(edev) || eeh_pe_passed(edev->pe))
405 return NULL;
406 +
407 + device_lock(&dev->dev);
408 dev->error_state = pci_channel_io_perm_failure;
409
410 driver = eeh_pcid_get(dev);
411 - if (!driver) return NULL;
412 + if (!driver) goto out_no_dev;
413
414 eeh_disable_irq(dev);
415
416 if (!driver->err_handler ||
417 - !driver->err_handler->error_detected) {
418 - eeh_pcid_put(dev);
419 - return NULL;
420 - }
421 + !driver->err_handler->error_detected)
422 + goto out;
423
424 driver->err_handler->error_detected(dev, pci_channel_io_perm_failure);
425
426 +out:
427 eeh_pcid_put(dev);
428 +out_no_dev:
429 + device_unlock(&dev->dev);
430 return NULL;
431 }
432
433 diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
434 index 4362b86ef84c..9c2f83331e5b 100644
435 --- a/arch/powerpc/mm/mem.c
436 +++ b/arch/powerpc/mm/mem.c
437 @@ -143,6 +143,7 @@ int arch_add_memory(int nid, u64 start, u64 size, bool want_memblock)
438 start, start + size, rc);
439 return -EFAULT;
440 }
441 + flush_inval_dcache_range(start, start + size);
442
443 return __add_pages(nid, start_pfn, nr_pages, want_memblock);
444 }
445 @@ -171,6 +172,7 @@ int arch_remove_memory(u64 start, u64 size)
446
447 /* Remove htab bolted mappings for this section of memory */
448 start = (unsigned long)__va(start);
449 + flush_inval_dcache_range(start, start + size);
450 ret = remove_section_mapping(start, start + size);
451
452 /* Ensure all vmalloc mappings are flushed in case they also
453 diff --git a/arch/powerpc/platforms/powernv/npu-dma.c b/arch/powerpc/platforms/powernv/npu-dma.c
454 index 2cb6cbea4b3b..4043109f4051 100644
455 --- a/arch/powerpc/platforms/powernv/npu-dma.c
456 +++ b/arch/powerpc/platforms/powernv/npu-dma.c
457 @@ -33,6 +33,13 @@
458
459 #define npu_to_phb(x) container_of(x, struct pnv_phb, npu)
460
461 +/*
462 + * When an address shootdown range exceeds this threshold we invalidate the
463 + * entire TLB on the GPU for the given PID rather than each specific address in
464 + * the range.
465 + */
466 +#define ATSD_THRESHOLD (2*1024*1024)
467 +
468 /*
469 * Other types of TCE cache invalidation are not functional in the
470 * hardware.
471 @@ -621,11 +628,19 @@ static void pnv_npu2_mn_invalidate_range(struct mmu_notifier *mn,
472 struct npu_context *npu_context = mn_to_npu_context(mn);
473 unsigned long address;
474
475 - for (address = start; address < end; address += PAGE_SIZE)
476 - mmio_invalidate(npu_context, 1, address, false);
477 + if (end - start > ATSD_THRESHOLD) {
478 + /*
479 + * Just invalidate the entire PID if the address range is too
480 + * large.
481 + */
482 + mmio_invalidate(npu_context, 0, 0, true);
483 + } else {
484 + for (address = start; address < end; address += PAGE_SIZE)
485 + mmio_invalidate(npu_context, 1, address, false);
486
487 - /* Do the flush only on the final addess == end */
488 - mmio_invalidate(npu_context, 1, address, true);
489 + /* Do the flush only on the final addess == end */
490 + mmio_invalidate(npu_context, 1, address, true);
491 + }
492 }
493
494 static const struct mmu_notifier_ops nv_nmmu_notifier_ops = {
495 diff --git a/arch/powerpc/platforms/powernv/opal-rtc.c b/arch/powerpc/platforms/powernv/opal-rtc.c
496 index f8868864f373..aa2a5139462e 100644
497 --- a/arch/powerpc/platforms/powernv/opal-rtc.c
498 +++ b/arch/powerpc/platforms/powernv/opal-rtc.c
499 @@ -48,10 +48,12 @@ unsigned long __init opal_get_boot_time(void)
500
501 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
502 rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms);
503 - if (rc == OPAL_BUSY_EVENT)
504 + if (rc == OPAL_BUSY_EVENT) {
505 + mdelay(OPAL_BUSY_DELAY_MS);
506 opal_poll_events(NULL);
507 - else if (rc == OPAL_BUSY)
508 - mdelay(10);
509 + } else if (rc == OPAL_BUSY) {
510 + mdelay(OPAL_BUSY_DELAY_MS);
511 + }
512 }
513 if (rc != OPAL_SUCCESS)
514 return 0;
515 diff --git a/arch/x86/include/uapi/asm/msgbuf.h b/arch/x86/include/uapi/asm/msgbuf.h
516 index 809134c644a6..90ab9a795b49 100644
517 --- a/arch/x86/include/uapi/asm/msgbuf.h
518 +++ b/arch/x86/include/uapi/asm/msgbuf.h
519 @@ -1 +1,32 @@
520 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
521 +#ifndef __ASM_X64_MSGBUF_H
522 +#define __ASM_X64_MSGBUF_H
523 +
524 +#if !defined(__x86_64__) || !defined(__ILP32__)
525 #include <asm-generic/msgbuf.h>
526 +#else
527 +/*
528 + * The msqid64_ds structure for x86 architecture with x32 ABI.
529 + *
530 + * On x86-32 and x86-64 we can just use the generic definition, but
531 + * x32 uses the same binary layout as x86_64, which is differnet
532 + * from other 32-bit architectures.
533 + */
534 +
535 +struct msqid64_ds {
536 + struct ipc64_perm msg_perm;
537 + __kernel_time_t msg_stime; /* last msgsnd time */
538 + __kernel_time_t msg_rtime; /* last msgrcv time */
539 + __kernel_time_t msg_ctime; /* last change time */
540 + __kernel_ulong_t msg_cbytes; /* current number of bytes on queue */
541 + __kernel_ulong_t msg_qnum; /* number of messages in queue */
542 + __kernel_ulong_t msg_qbytes; /* max number of bytes on queue */
543 + __kernel_pid_t msg_lspid; /* pid of last msgsnd */
544 + __kernel_pid_t msg_lrpid; /* last receive pid */
545 + __kernel_ulong_t __unused4;
546 + __kernel_ulong_t __unused5;
547 +};
548 +
549 +#endif
550 +
551 +#endif /* __ASM_GENERIC_MSGBUF_H */
552 diff --git a/arch/x86/include/uapi/asm/shmbuf.h b/arch/x86/include/uapi/asm/shmbuf.h
553 index 83c05fc2de38..644421f3823b 100644
554 --- a/arch/x86/include/uapi/asm/shmbuf.h
555 +++ b/arch/x86/include/uapi/asm/shmbuf.h
556 @@ -1 +1,43 @@
557 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
558 +#ifndef __ASM_X86_SHMBUF_H
559 +#define __ASM_X86_SHMBUF_H
560 +
561 +#if !defined(__x86_64__) || !defined(__ILP32__)
562 #include <asm-generic/shmbuf.h>
563 +#else
564 +/*
565 + * The shmid64_ds structure for x86 architecture with x32 ABI.
566 + *
567 + * On x86-32 and x86-64 we can just use the generic definition, but
568 + * x32 uses the same binary layout as x86_64, which is differnet
569 + * from other 32-bit architectures.
570 + */
571 +
572 +struct shmid64_ds {
573 + struct ipc64_perm shm_perm; /* operation perms */
574 + size_t shm_segsz; /* size of segment (bytes) */
575 + __kernel_time_t shm_atime; /* last attach time */
576 + __kernel_time_t shm_dtime; /* last detach time */
577 + __kernel_time_t shm_ctime; /* last change time */
578 + __kernel_pid_t shm_cpid; /* pid of creator */
579 + __kernel_pid_t shm_lpid; /* pid of last operator */
580 + __kernel_ulong_t shm_nattch; /* no. of current attaches */
581 + __kernel_ulong_t __unused4;
582 + __kernel_ulong_t __unused5;
583 +};
584 +
585 +struct shminfo64 {
586 + __kernel_ulong_t shmmax;
587 + __kernel_ulong_t shmmin;
588 + __kernel_ulong_t shmmni;
589 + __kernel_ulong_t shmseg;
590 + __kernel_ulong_t shmall;
591 + __kernel_ulong_t __unused1;
592 + __kernel_ulong_t __unused2;
593 + __kernel_ulong_t __unused3;
594 + __kernel_ulong_t __unused4;
595 +};
596 +
597 +#endif
598 +
599 +#endif /* __ASM_X86_SHMBUF_H */
600 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
601 index 021c90464cc2..c8e0cda0f272 100644
602 --- a/arch/x86/kernel/cpu/microcode/core.c
603 +++ b/arch/x86/kernel/cpu/microcode/core.c
604 @@ -564,14 +564,12 @@ static int __reload_late(void *info)
605 apply_microcode_local(&err);
606 spin_unlock(&update_lock);
607
608 + /* siblings return UCODE_OK because their engine got updated already */
609 if (err > UCODE_NFOUND) {
610 pr_warn("Error reloading microcode on CPU %d\n", cpu);
611 - return -1;
612 - /* siblings return UCODE_OK because their engine got updated already */
613 + ret = -1;
614 } else if (err == UCODE_UPDATED || err == UCODE_OK) {
615 ret = 1;
616 - } else {
617 - return ret;
618 }
619
620 /*
621 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
622 index 32b8e5724f96..1c2cfa0644aa 100644
623 --- a/arch/x86/kernel/cpu/microcode/intel.c
624 +++ b/arch/x86/kernel/cpu/microcode/intel.c
625 @@ -485,7 +485,6 @@ static void show_saved_mc(void)
626 */
627 static void save_mc_for_early(u8 *mc, unsigned int size)
628 {
629 -#ifdef CONFIG_HOTPLUG_CPU
630 /* Synchronization during CPU hotplug. */
631 static DEFINE_MUTEX(x86_cpu_microcode_mutex);
632
633 @@ -495,7 +494,6 @@ static void save_mc_for_early(u8 *mc, unsigned int size)
634 show_saved_mc();
635
636 mutex_unlock(&x86_cpu_microcode_mutex);
637 -#endif
638 }
639
640 static bool load_builtin_intel_microcode(struct cpio_data *cp)
641 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
642 index 2651ca2112c4..6b841262b790 100644
643 --- a/arch/x86/kernel/smpboot.c
644 +++ b/arch/x86/kernel/smpboot.c
645 @@ -1613,6 +1613,8 @@ static inline void mwait_play_dead(void)
646 void *mwait_ptr;
647 int i;
648
649 + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
650 + return;
651 if (!this_cpu_has(X86_FEATURE_MWAIT))
652 return;
653 if (!this_cpu_has(X86_FEATURE_CLFLUSH))
654 diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
655 index 0f860cf0d56d..56c9cd01fd1d 100644
656 --- a/block/bfq-iosched.c
657 +++ b/block/bfq-iosched.c
658 @@ -4447,8 +4447,16 @@ static void bfq_prepare_request(struct request *rq, struct bio *bio)
659 bool new_queue = false;
660 bool bfqq_already_existing = false, split = false;
661
662 - if (!rq->elv.icq)
663 + /*
664 + * Even if we don't have an icq attached, we should still clear
665 + * the scheduler pointers, as they might point to previously
666 + * allocated bic/bfqq structs.
667 + */
668 + if (!rq->elv.icq) {
669 + rq->elv.priv[0] = rq->elv.priv[1] = NULL;
670 return;
671 + }
672 +
673 bic = icq_to_bic(rq->elv.icq);
674
675 spin_lock_irq(&bfqd->lock);
676 diff --git a/crypto/drbg.c b/crypto/drbg.c
677 index 70018397e59a..6c3221313753 100644
678 --- a/crypto/drbg.c
679 +++ b/crypto/drbg.c
680 @@ -1134,8 +1134,10 @@ static inline void drbg_dealloc_state(struct drbg_state *drbg)
681 if (!drbg)
682 return;
683 kzfree(drbg->Vbuf);
684 + drbg->Vbuf = NULL;
685 drbg->V = NULL;
686 kzfree(drbg->Cbuf);
687 + drbg->Cbuf = NULL;
688 drbg->C = NULL;
689 kzfree(drbg->scratchpadbuf);
690 drbg->scratchpadbuf = NULL;
691 diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
692 index e0f74ddc22b7..8a99fbe5759f 100644
693 --- a/drivers/amba/bus.c
694 +++ b/drivers/amba/bus.c
695 @@ -69,11 +69,12 @@ static ssize_t driver_override_show(struct device *_dev,
696 struct device_attribute *attr, char *buf)
697 {
698 struct amba_device *dev = to_amba_device(_dev);
699 + ssize_t len;
700
701 - if (!dev->driver_override)
702 - return 0;
703 -
704 - return sprintf(buf, "%s\n", dev->driver_override);
705 + device_lock(_dev);
706 + len = sprintf(buf, "%s\n", dev->driver_override);
707 + device_unlock(_dev);
708 + return len;
709 }
710
711 static ssize_t driver_override_store(struct device *_dev,
712 @@ -81,9 +82,10 @@ static ssize_t driver_override_store(struct device *_dev,
713 const char *buf, size_t count)
714 {
715 struct amba_device *dev = to_amba_device(_dev);
716 - char *driver_override, *old = dev->driver_override, *cp;
717 + char *driver_override, *old, *cp;
718
719 - if (count > PATH_MAX)
720 + /* We need to keep extra room for a newline */
721 + if (count >= (PAGE_SIZE - 1))
722 return -EINVAL;
723
724 driver_override = kstrndup(buf, count, GFP_KERNEL);
725 @@ -94,12 +96,15 @@ static ssize_t driver_override_store(struct device *_dev,
726 if (cp)
727 *cp = '\0';
728
729 + device_lock(_dev);
730 + old = dev->driver_override;
731 if (strlen(driver_override)) {
732 dev->driver_override = driver_override;
733 } else {
734 kfree(driver_override);
735 dev->driver_override = NULL;
736 }
737 + device_unlock(_dev);
738
739 kfree(old);
740
741 diff --git a/drivers/android/binder.c b/drivers/android/binder.c
742 index b7efdc8badee..a86c27948fca 100644
743 --- a/drivers/android/binder.c
744 +++ b/drivers/android/binder.c
745 @@ -2785,6 +2785,14 @@ static void binder_transaction(struct binder_proc *proc,
746 else
747 return_error = BR_DEAD_REPLY;
748 mutex_unlock(&context->context_mgr_node_lock);
749 + if (target_node && target_proc == proc) {
750 + binder_user_error("%d:%d got transaction to context manager from process owning it\n",
751 + proc->pid, thread->pid);
752 + return_error = BR_FAILED_REPLY;
753 + return_error_param = -EINVAL;
754 + return_error_line = __LINE__;
755 + goto err_invalid_target_handle;
756 + }
757 }
758 if (!target_node) {
759 /*
760 diff --git a/drivers/char/random.c b/drivers/char/random.c
761 index 58a2ff7df392..ddc493d976fd 100644
762 --- a/drivers/char/random.c
763 +++ b/drivers/char/random.c
764 @@ -261,6 +261,7 @@
765 #include <linux/ptrace.h>
766 #include <linux/workqueue.h>
767 #include <linux/irq.h>
768 +#include <linux/ratelimit.h>
769 #include <linux/syscalls.h>
770 #include <linux/completion.h>
771 #include <linux/uuid.h>
772 @@ -438,6 +439,16 @@ static void _crng_backtrack_protect(struct crng_state *crng,
773 static void process_random_ready_list(void);
774 static void _get_random_bytes(void *buf, int nbytes);
775
776 +static struct ratelimit_state unseeded_warning =
777 + RATELIMIT_STATE_INIT("warn_unseeded_randomness", HZ, 3);
778 +static struct ratelimit_state urandom_warning =
779 + RATELIMIT_STATE_INIT("warn_urandom_randomness", HZ, 3);
780 +
781 +static int ratelimit_disable __read_mostly;
782 +
783 +module_param_named(ratelimit_disable, ratelimit_disable, int, 0644);
784 +MODULE_PARM_DESC(ratelimit_disable, "Disable random ratelimit suppression");
785 +
786 /**********************************************************************
787 *
788 * OS independent entropy store. Here are the functions which handle
789 @@ -787,6 +798,39 @@ static void crng_initialize(struct crng_state *crng)
790 crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1;
791 }
792
793 +#ifdef CONFIG_NUMA
794 +static void do_numa_crng_init(struct work_struct *work)
795 +{
796 + int i;
797 + struct crng_state *crng;
798 + struct crng_state **pool;
799 +
800 + pool = kcalloc(nr_node_ids, sizeof(*pool), GFP_KERNEL|__GFP_NOFAIL);
801 + for_each_online_node(i) {
802 + crng = kmalloc_node(sizeof(struct crng_state),
803 + GFP_KERNEL | __GFP_NOFAIL, i);
804 + spin_lock_init(&crng->lock);
805 + crng_initialize(crng);
806 + pool[i] = crng;
807 + }
808 + mb();
809 + if (cmpxchg(&crng_node_pool, NULL, pool)) {
810 + for_each_node(i)
811 + kfree(pool[i]);
812 + kfree(pool);
813 + }
814 +}
815 +
816 +static DECLARE_WORK(numa_crng_init_work, do_numa_crng_init);
817 +
818 +static void numa_crng_init(void)
819 +{
820 + schedule_work(&numa_crng_init_work);
821 +}
822 +#else
823 +static void numa_crng_init(void) {}
824 +#endif
825 +
826 /*
827 * crng_fast_load() can be called by code in the interrupt service
828 * path. So we can't afford to dilly-dally.
829 @@ -893,10 +937,23 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r)
830 spin_unlock_irqrestore(&crng->lock, flags);
831 if (crng == &primary_crng && crng_init < 2) {
832 invalidate_batched_entropy();
833 + numa_crng_init();
834 crng_init = 2;
835 process_random_ready_list();
836 wake_up_interruptible(&crng_init_wait);
837 pr_notice("random: crng init done\n");
838 + if (unseeded_warning.missed) {
839 + pr_notice("random: %d get_random_xx warning(s) missed "
840 + "due to ratelimiting\n",
841 + unseeded_warning.missed);
842 + unseeded_warning.missed = 0;
843 + }
844 + if (urandom_warning.missed) {
845 + pr_notice("random: %d urandom warning(s) missed "
846 + "due to ratelimiting\n",
847 + urandom_warning.missed);
848 + urandom_warning.missed = 0;
849 + }
850 }
851 }
852
853 @@ -1540,8 +1597,9 @@ static void _warn_unseeded_randomness(const char *func_name, void *caller,
854 #ifndef CONFIG_WARN_ALL_UNSEEDED_RANDOM
855 print_once = true;
856 #endif
857 - pr_notice("random: %s called from %pS with crng_init=%d\n",
858 - func_name, caller, crng_init);
859 + if (__ratelimit(&unseeded_warning))
860 + pr_notice("random: %s called from %pS with crng_init=%d\n",
861 + func_name, caller, crng_init);
862 }
863
864 /*
865 @@ -1731,29 +1789,14 @@ static void init_std_data(struct entropy_store *r)
866 */
867 static int rand_initialize(void)
868 {
869 -#ifdef CONFIG_NUMA
870 - int i;
871 - struct crng_state *crng;
872 - struct crng_state **pool;
873 -#endif
874 -
875 init_std_data(&input_pool);
876 init_std_data(&blocking_pool);
877 crng_initialize(&primary_crng);
878 crng_global_init_time = jiffies;
879 -
880 -#ifdef CONFIG_NUMA
881 - pool = kcalloc(nr_node_ids, sizeof(*pool), GFP_KERNEL|__GFP_NOFAIL);
882 - for_each_online_node(i) {
883 - crng = kmalloc_node(sizeof(struct crng_state),
884 - GFP_KERNEL | __GFP_NOFAIL, i);
885 - spin_lock_init(&crng->lock);
886 - crng_initialize(crng);
887 - pool[i] = crng;
888 + if (ratelimit_disable) {
889 + urandom_warning.interval = 0;
890 + unseeded_warning.interval = 0;
891 }
892 - mb();
893 - crng_node_pool = pool;
894 -#endif
895 return 0;
896 }
897 early_initcall(rand_initialize);
898 @@ -1821,9 +1864,10 @@ urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
899
900 if (!crng_ready() && maxwarn > 0) {
901 maxwarn--;
902 - printk(KERN_NOTICE "random: %s: uninitialized urandom read "
903 - "(%zd bytes read)\n",
904 - current->comm, nbytes);
905 + if (__ratelimit(&urandom_warning))
906 + printk(KERN_NOTICE "random: %s: uninitialized "
907 + "urandom read (%zd bytes read)\n",
908 + current->comm, nbytes);
909 spin_lock_irqsave(&primary_crng.lock, flags);
910 crng_init_cnt = 0;
911 spin_unlock_irqrestore(&primary_crng.lock, flags);
912 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
913 index d1aed2513bd9..a089474cb046 100644
914 --- a/drivers/char/virtio_console.c
915 +++ b/drivers/char/virtio_console.c
916 @@ -422,7 +422,7 @@ static void reclaim_dma_bufs(void)
917 }
918 }
919
920 -static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size,
921 +static struct port_buffer *alloc_buf(struct virtio_device *vdev, size_t buf_size,
922 int pages)
923 {
924 struct port_buffer *buf;
925 @@ -445,16 +445,16 @@ static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size,
926 return buf;
927 }
928
929 - if (is_rproc_serial(vq->vdev)) {
930 + if (is_rproc_serial(vdev)) {
931 /*
932 * Allocate DMA memory from ancestor. When a virtio
933 * device is created by remoteproc, the DMA memory is
934 * associated with the grandparent device:
935 * vdev => rproc => platform-dev.
936 */
937 - if (!vq->vdev->dev.parent || !vq->vdev->dev.parent->parent)
938 + if (!vdev->dev.parent || !vdev->dev.parent->parent)
939 goto free_buf;
940 - buf->dev = vq->vdev->dev.parent->parent;
941 + buf->dev = vdev->dev.parent->parent;
942
943 /* Increase device refcnt to avoid freeing it */
944 get_device(buf->dev);
945 @@ -838,7 +838,7 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
946
947 count = min((size_t)(32 * 1024), count);
948
949 - buf = alloc_buf(port->out_vq, count, 0);
950 + buf = alloc_buf(port->portdev->vdev, count, 0);
951 if (!buf)
952 return -ENOMEM;
953
954 @@ -957,7 +957,7 @@ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe,
955 if (ret < 0)
956 goto error_out;
957
958 - buf = alloc_buf(port->out_vq, 0, pipe->nrbufs);
959 + buf = alloc_buf(port->portdev->vdev, 0, pipe->nrbufs);
960 if (!buf) {
961 ret = -ENOMEM;
962 goto error_out;
963 @@ -1374,7 +1374,7 @@ static unsigned int fill_queue(struct virtqueue *vq, spinlock_t *lock)
964
965 nr_added_bufs = 0;
966 do {
967 - buf = alloc_buf(vq, PAGE_SIZE, 0);
968 + buf = alloc_buf(vq->vdev, PAGE_SIZE, 0);
969 if (!buf)
970 break;
971
972 @@ -1402,7 +1402,6 @@ static int add_port(struct ports_device *portdev, u32 id)
973 {
974 char debugfs_name[16];
975 struct port *port;
976 - struct port_buffer *buf;
977 dev_t devt;
978 unsigned int nr_added_bufs;
979 int err;
980 @@ -1513,8 +1512,6 @@ static int add_port(struct ports_device *portdev, u32 id)
981 return 0;
982
983 free_inbufs:
984 - while ((buf = virtqueue_detach_unused_buf(port->in_vq)))
985 - free_buf(buf, true);
986 free_device:
987 device_destroy(pdrvdata.class, port->dev->devt);
988 free_cdev:
989 @@ -1539,34 +1536,14 @@ static void remove_port(struct kref *kref)
990
991 static void remove_port_data(struct port *port)
992 {
993 - struct port_buffer *buf;
994 -
995 spin_lock_irq(&port->inbuf_lock);
996 /* Remove unused data this port might have received. */
997 discard_port_data(port);
998 spin_unlock_irq(&port->inbuf_lock);
999
1000 - /* Remove buffers we queued up for the Host to send us data in. */
1001 - do {
1002 - spin_lock_irq(&port->inbuf_lock);
1003 - buf = virtqueue_detach_unused_buf(port->in_vq);
1004 - spin_unlock_irq(&port->inbuf_lock);
1005 - if (buf)
1006 - free_buf(buf, true);
1007 - } while (buf);
1008 -
1009 spin_lock_irq(&port->outvq_lock);
1010 reclaim_consumed_buffers(port);
1011 spin_unlock_irq(&port->outvq_lock);
1012 -
1013 - /* Free pending buffers from the out-queue. */
1014 - do {
1015 - spin_lock_irq(&port->outvq_lock);
1016 - buf = virtqueue_detach_unused_buf(port->out_vq);
1017 - spin_unlock_irq(&port->outvq_lock);
1018 - if (buf)
1019 - free_buf(buf, true);
1020 - } while (buf);
1021 }
1022
1023 /*
1024 @@ -1791,13 +1768,24 @@ static void control_work_handler(struct work_struct *work)
1025 spin_unlock(&portdev->c_ivq_lock);
1026 }
1027
1028 +static void flush_bufs(struct virtqueue *vq, bool can_sleep)
1029 +{
1030 + struct port_buffer *buf;
1031 + unsigned int len;
1032 +
1033 + while ((buf = virtqueue_get_buf(vq, &len)))
1034 + free_buf(buf, can_sleep);
1035 +}
1036 +
1037 static void out_intr(struct virtqueue *vq)
1038 {
1039 struct port *port;
1040
1041 port = find_port_by_vq(vq->vdev->priv, vq);
1042 - if (!port)
1043 + if (!port) {
1044 + flush_bufs(vq, false);
1045 return;
1046 + }
1047
1048 wake_up_interruptible(&port->waitqueue);
1049 }
1050 @@ -1808,8 +1796,10 @@ static void in_intr(struct virtqueue *vq)
1051 unsigned long flags;
1052
1053 port = find_port_by_vq(vq->vdev->priv, vq);
1054 - if (!port)
1055 + if (!port) {
1056 + flush_bufs(vq, false);
1057 return;
1058 + }
1059
1060 spin_lock_irqsave(&port->inbuf_lock, flags);
1061 port->inbuf = get_inbuf(port);
1062 @@ -1984,24 +1974,54 @@ static const struct file_operations portdev_fops = {
1063
1064 static void remove_vqs(struct ports_device *portdev)
1065 {
1066 + struct virtqueue *vq;
1067 +
1068 + virtio_device_for_each_vq(portdev->vdev, vq) {
1069 + struct port_buffer *buf;
1070 +
1071 + flush_bufs(vq, true);
1072 + while ((buf = virtqueue_detach_unused_buf(vq)))
1073 + free_buf(buf, true);
1074 + }
1075 portdev->vdev->config->del_vqs(portdev->vdev);
1076 kfree(portdev->in_vqs);
1077 kfree(portdev->out_vqs);
1078 }
1079
1080 -static void remove_controlq_data(struct ports_device *portdev)
1081 +static void virtcons_remove(struct virtio_device *vdev)
1082 {
1083 - struct port_buffer *buf;
1084 - unsigned int len;
1085 + struct ports_device *portdev;
1086 + struct port *port, *port2;
1087
1088 - if (!use_multiport(portdev))
1089 - return;
1090 + portdev = vdev->priv;
1091
1092 - while ((buf = virtqueue_get_buf(portdev->c_ivq, &len)))
1093 - free_buf(buf, true);
1094 + spin_lock_irq(&pdrvdata_lock);
1095 + list_del(&portdev->list);
1096 + spin_unlock_irq(&pdrvdata_lock);
1097
1098 - while ((buf = virtqueue_detach_unused_buf(portdev->c_ivq)))
1099 - free_buf(buf, true);
1100 + /* Disable interrupts for vqs */
1101 + vdev->config->reset(vdev);
1102 + /* Finish up work that's lined up */
1103 + if (use_multiport(portdev))
1104 + cancel_work_sync(&portdev->control_work);
1105 + else
1106 + cancel_work_sync(&portdev->config_work);
1107 +
1108 + list_for_each_entry_safe(port, port2, &portdev->ports, list)
1109 + unplug_port(port);
1110 +
1111 + unregister_chrdev(portdev->chr_major, "virtio-portsdev");
1112 +
1113 + /*
1114 + * When yanking out a device, we immediately lose the
1115 + * (device-side) queues. So there's no point in keeping the
1116 + * guest side around till we drop our final reference. This
1117 + * also means that any ports which are in an open state will
1118 + * have to just stop using the port, as the vqs are going
1119 + * away.
1120 + */
1121 + remove_vqs(portdev);
1122 + kfree(portdev);
1123 }
1124
1125 /*
1126 @@ -2070,6 +2090,7 @@ static int virtcons_probe(struct virtio_device *vdev)
1127
1128 spin_lock_init(&portdev->ports_lock);
1129 INIT_LIST_HEAD(&portdev->ports);
1130 + INIT_LIST_HEAD(&portdev->list);
1131
1132 virtio_device_ready(portdev->vdev);
1133
1134 @@ -2087,8 +2108,15 @@ static int virtcons_probe(struct virtio_device *vdev)
1135 if (!nr_added_bufs) {
1136 dev_err(&vdev->dev,
1137 "Error allocating buffers for control queue\n");
1138 - err = -ENOMEM;
1139 - goto free_vqs;
1140 + /*
1141 + * The host might want to notify mgmt sw about device
1142 + * add failure.
1143 + */
1144 + __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
1145 + VIRTIO_CONSOLE_DEVICE_READY, 0);
1146 + /* Device was functional: we need full cleanup. */
1147 + virtcons_remove(vdev);
1148 + return -ENOMEM;
1149 }
1150 } else {
1151 /*
1152 @@ -2119,11 +2147,6 @@ static int virtcons_probe(struct virtio_device *vdev)
1153
1154 return 0;
1155
1156 -free_vqs:
1157 - /* The host might want to notify mgmt sw about device add failure */
1158 - __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
1159 - VIRTIO_CONSOLE_DEVICE_READY, 0);
1160 - remove_vqs(portdev);
1161 free_chrdev:
1162 unregister_chrdev(portdev->chr_major, "virtio-portsdev");
1163 free:
1164 @@ -2132,43 +2155,6 @@ static int virtcons_probe(struct virtio_device *vdev)
1165 return err;
1166 }
1167
1168 -static void virtcons_remove(struct virtio_device *vdev)
1169 -{
1170 - struct ports_device *portdev;
1171 - struct port *port, *port2;
1172 -
1173 - portdev = vdev->priv;
1174 -
1175 - spin_lock_irq(&pdrvdata_lock);
1176 - list_del(&portdev->list);
1177 - spin_unlock_irq(&pdrvdata_lock);
1178 -
1179 - /* Disable interrupts for vqs */
1180 - vdev->config->reset(vdev);
1181 - /* Finish up work that's lined up */
1182 - if (use_multiport(portdev))
1183 - cancel_work_sync(&portdev->control_work);
1184 - else
1185 - cancel_work_sync(&portdev->config_work);
1186 -
1187 - list_for_each_entry_safe(port, port2, &portdev->ports, list)
1188 - unplug_port(port);
1189 -
1190 - unregister_chrdev(portdev->chr_major, "virtio-portsdev");
1191 -
1192 - /*
1193 - * When yanking out a device, we immediately lose the
1194 - * (device-side) queues. So there's no point in keeping the
1195 - * guest side around till we drop our final reference. This
1196 - * also means that any ports which are in an open state will
1197 - * have to just stop using the port, as the vqs are going
1198 - * away.
1199 - */
1200 - remove_controlq_data(portdev);
1201 - remove_vqs(portdev);
1202 - kfree(portdev);
1203 -}
1204 -
1205 static struct virtio_device_id id_table[] = {
1206 { VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID },
1207 { 0 },
1208 @@ -2209,7 +2195,6 @@ static int virtcons_freeze(struct virtio_device *vdev)
1209 */
1210 if (use_multiport(portdev))
1211 virtqueue_disable_cb(portdev->c_ivq);
1212 - remove_controlq_data(portdev);
1213
1214 list_for_each_entry(port, &portdev->ports, list) {
1215 virtqueue_disable_cb(port->in_vq);
1216 diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
1217 index 6b3a63545619..a28bb8f3f395 100644
1218 --- a/drivers/cpufreq/powernv-cpufreq.c
1219 +++ b/drivers/cpufreq/powernv-cpufreq.c
1220 @@ -646,6 +646,16 @@ void gpstate_timer_handler(unsigned long data)
1221
1222 if (!spin_trylock(&gpstates->gpstate_lock))
1223 return;
1224 + /*
1225 + * If the timer has migrated to the different cpu then bring
1226 + * it back to one of the policy->cpus
1227 + */
1228 + if (!cpumask_test_cpu(raw_smp_processor_id(), policy->cpus)) {
1229 + gpstates->timer.expires = jiffies + msecs_to_jiffies(1);
1230 + add_timer_on(&gpstates->timer, cpumask_first(policy->cpus));
1231 + spin_unlock(&gpstates->gpstate_lock);
1232 + return;
1233 + }
1234
1235 /*
1236 * If PMCR was last updated was using fast_swtich then
1237 @@ -685,10 +695,8 @@ void gpstate_timer_handler(unsigned long data)
1238 if (gpstate_idx != gpstates->last_lpstate_idx)
1239 queue_gpstate_timer(gpstates);
1240
1241 + set_pstate(&freq_data);
1242 spin_unlock(&gpstates->gpstate_lock);
1243 -
1244 - /* Timer may get migrated to a different cpu on cpu hot unplug */
1245 - smp_call_function_any(policy->cpus, set_pstate, &freq_data, 1);
1246 }
1247
1248 /*
1249 diff --git a/drivers/fpga/altera-ps-spi.c b/drivers/fpga/altera-ps-spi.c
1250 index 14f14efdf0d5..06d212a3d49d 100644
1251 --- a/drivers/fpga/altera-ps-spi.c
1252 +++ b/drivers/fpga/altera-ps-spi.c
1253 @@ -249,7 +249,7 @@ static int altera_ps_probe(struct spi_device *spi)
1254
1255 conf->data = of_id->data;
1256 conf->spi = spi;
1257 - conf->config = devm_gpiod_get(&spi->dev, "nconfig", GPIOD_OUT_HIGH);
1258 + conf->config = devm_gpiod_get(&spi->dev, "nconfig", GPIOD_OUT_LOW);
1259 if (IS_ERR(conf->config)) {
1260 dev_err(&spi->dev, "Failed to get config gpio: %ld\n",
1261 PTR_ERR(conf->config));
1262 diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
1263 index fc260c13b1da..a7e54820a330 100644
1264 --- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
1265 +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
1266 @@ -1398,10 +1398,11 @@ static const u32 sgpr_init_compute_shader[] =
1267 static const u32 vgpr_init_regs[] =
1268 {
1269 mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0xffffffff,
1270 - mmCOMPUTE_RESOURCE_LIMITS, 0,
1271 + mmCOMPUTE_RESOURCE_LIMITS, 0x1000000, /* CU_GROUP_COUNT=1 */
1272 mmCOMPUTE_NUM_THREAD_X, 256*4,
1273 mmCOMPUTE_NUM_THREAD_Y, 1,
1274 mmCOMPUTE_NUM_THREAD_Z, 1,
1275 + mmCOMPUTE_PGM_RSRC1, 0x100004f, /* VGPRS=15 (64 logical VGPRs), SGPRS=1 (16 SGPRs), BULKY=1 */
1276 mmCOMPUTE_PGM_RSRC2, 20,
1277 mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1278 mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1279 @@ -1418,10 +1419,11 @@ static const u32 vgpr_init_regs[] =
1280 static const u32 sgpr1_init_regs[] =
1281 {
1282 mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0x0f,
1283 - mmCOMPUTE_RESOURCE_LIMITS, 0x1000000,
1284 + mmCOMPUTE_RESOURCE_LIMITS, 0x1000000, /* CU_GROUP_COUNT=1 */
1285 mmCOMPUTE_NUM_THREAD_X, 256*5,
1286 mmCOMPUTE_NUM_THREAD_Y, 1,
1287 mmCOMPUTE_NUM_THREAD_Z, 1,
1288 + mmCOMPUTE_PGM_RSRC1, 0x240, /* SGPRS=9 (80 GPRS) */
1289 mmCOMPUTE_PGM_RSRC2, 20,
1290 mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1291 mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1292 @@ -1442,6 +1444,7 @@ static const u32 sgpr2_init_regs[] =
1293 mmCOMPUTE_NUM_THREAD_X, 256*5,
1294 mmCOMPUTE_NUM_THREAD_Y, 1,
1295 mmCOMPUTE_NUM_THREAD_Z, 1,
1296 + mmCOMPUTE_PGM_RSRC1, 0x240, /* SGPRS=9 (80 GPRS) */
1297 mmCOMPUTE_PGM_RSRC2, 20,
1298 mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1299 mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1300 diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
1301 index bcccacba1ec6..bcfc1c235966 100644
1302 --- a/drivers/gpu/drm/i915/intel_runtime_pm.c
1303 +++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
1304 @@ -622,19 +622,18 @@ void skl_enable_dc6(struct drm_i915_private *dev_priv)
1305
1306 DRM_DEBUG_KMS("Enabling DC6\n");
1307
1308 - gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
1309 + /* Wa Display #1183: skl,kbl,cfl */
1310 + if (IS_GEN9_BC(dev_priv))
1311 + I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
1312 + SKL_SELECT_ALTERNATE_DC_EXIT);
1313
1314 + gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
1315 }
1316
1317 void skl_disable_dc6(struct drm_i915_private *dev_priv)
1318 {
1319 DRM_DEBUG_KMS("Disabling DC6\n");
1320
1321 - /* Wa Display #1183: skl,kbl,cfl */
1322 - if (IS_GEN9_BC(dev_priv))
1323 - I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
1324 - SKL_SELECT_ALTERNATE_DC_EXIT);
1325 -
1326 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
1327 }
1328
1329 diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c
1330 index 9eb96fb2c147..26a2da1f712d 100644
1331 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c
1332 +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
1333 @@ -291,7 +291,7 @@ static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
1334 ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC);
1335 if (ret == -ENOSPC) {
1336 spin_unlock(&vgdev->ctrlq.qlock);
1337 - wait_event(vgdev->ctrlq.ack_queue, vq->num_free);
1338 + wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= outcnt + incnt);
1339 spin_lock(&vgdev->ctrlq.qlock);
1340 goto retry;
1341 } else {
1342 @@ -366,7 +366,7 @@ static int virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev,
1343 ret = virtqueue_add_sgs(vq, sgs, outcnt, 0, vbuf, GFP_ATOMIC);
1344 if (ret == -ENOSPC) {
1345 spin_unlock(&vgdev->cursorq.qlock);
1346 - wait_event(vgdev->cursorq.ack_queue, vq->num_free);
1347 + wait_event(vgdev->cursorq.ack_queue, vq->num_free >= outcnt);
1348 spin_lock(&vgdev->cursorq.qlock);
1349 goto retry;
1350 } else {
1351 diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
1352 index 5e1b68cbcd0a..e1b603ca0170 100644
1353 --- a/drivers/mtd/chips/cfi_cmdset_0001.c
1354 +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
1355 @@ -45,6 +45,7 @@
1356 #define I82802AB 0x00ad
1357 #define I82802AC 0x00ac
1358 #define PF38F4476 0x881c
1359 +#define M28F00AP30 0x8963
1360 /* STMicroelectronics chips */
1361 #define M50LPW080 0x002F
1362 #define M50FLW080A 0x0080
1363 @@ -375,6 +376,17 @@ static void cfi_fixup_major_minor(struct cfi_private *cfi,
1364 extp->MinorVersion = '1';
1365 }
1366
1367 +static int cfi_is_micron_28F00AP30(struct cfi_private *cfi, struct flchip *chip)
1368 +{
1369 + /*
1370 + * Micron(was Numonyx) 1Gbit bottom boot are buggy w.r.t
1371 + * Erase Supend for their small Erase Blocks(0x8000)
1372 + */
1373 + if (cfi->mfr == CFI_MFR_INTEL && cfi->id == M28F00AP30)
1374 + return 1;
1375 + return 0;
1376 +}
1377 +
1378 static inline struct cfi_pri_intelext *
1379 read_pri_intelext(struct map_info *map, __u16 adr)
1380 {
1381 @@ -831,21 +843,30 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
1382 (mode == FL_WRITING && (cfip->SuspendCmdSupport & 1))))
1383 goto sleep;
1384
1385 + /* Do not allow suspend iff read/write to EB address */
1386 + if ((adr & chip->in_progress_block_mask) ==
1387 + chip->in_progress_block_addr)
1388 + goto sleep;
1389 +
1390 + /* do not suspend small EBs, buggy Micron Chips */
1391 + if (cfi_is_micron_28F00AP30(cfi, chip) &&
1392 + (chip->in_progress_block_mask == ~(0x8000-1)))
1393 + goto sleep;
1394
1395 /* Erase suspend */
1396 - map_write(map, CMD(0xB0), adr);
1397 + map_write(map, CMD(0xB0), chip->in_progress_block_addr);
1398
1399 /* If the flash has finished erasing, then 'erase suspend'
1400 * appears to make some (28F320) flash devices switch to
1401 * 'read' mode. Make sure that we switch to 'read status'
1402 * mode so we get the right data. --rmk
1403 */
1404 - map_write(map, CMD(0x70), adr);
1405 + map_write(map, CMD(0x70), chip->in_progress_block_addr);
1406 chip->oldstate = FL_ERASING;
1407 chip->state = FL_ERASE_SUSPENDING;
1408 chip->erase_suspended = 1;
1409 for (;;) {
1410 - status = map_read(map, adr);
1411 + status = map_read(map, chip->in_progress_block_addr);
1412 if (map_word_andequal(map, status, status_OK, status_OK))
1413 break;
1414
1415 @@ -1041,8 +1062,8 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
1416 sending the 0x70 (Read Status) command to an erasing
1417 chip and expecting it to be ignored, that's what we
1418 do. */
1419 - map_write(map, CMD(0xd0), adr);
1420 - map_write(map, CMD(0x70), adr);
1421 + map_write(map, CMD(0xd0), chip->in_progress_block_addr);
1422 + map_write(map, CMD(0x70), chip->in_progress_block_addr);
1423 chip->oldstate = FL_READY;
1424 chip->state = FL_ERASING;
1425 break;
1426 @@ -1933,6 +1954,8 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
1427 map_write(map, CMD(0xD0), adr);
1428 chip->state = FL_ERASING;
1429 chip->erase_suspended = 0;
1430 + chip->in_progress_block_addr = adr;
1431 + chip->in_progress_block_mask = ~(len - 1);
1432
1433 ret = INVAL_CACHE_AND_WAIT(map, chip, adr,
1434 adr, len,
1435 diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
1436 index 56aa6b75213d..d524a64ed754 100644
1437 --- a/drivers/mtd/chips/cfi_cmdset_0002.c
1438 +++ b/drivers/mtd/chips/cfi_cmdset_0002.c
1439 @@ -816,9 +816,10 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
1440 (mode == FL_WRITING && (cfip->EraseSuspend & 0x2))))
1441 goto sleep;
1442
1443 - /* We could check to see if we're trying to access the sector
1444 - * that is currently being erased. However, no user will try
1445 - * anything like that so we just wait for the timeout. */
1446 + /* Do not allow suspend iff read/write to EB address */
1447 + if ((adr & chip->in_progress_block_mask) ==
1448 + chip->in_progress_block_addr)
1449 + goto sleep;
1450
1451 /* Erase suspend */
1452 /* It's harmless to issue the Erase-Suspend and Erase-Resume
1453 @@ -2267,6 +2268,7 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
1454 chip->state = FL_ERASING;
1455 chip->erase_suspended = 0;
1456 chip->in_progress_block_addr = adr;
1457 + chip->in_progress_block_mask = ~(map->size - 1);
1458
1459 INVALIDATE_CACHE_UDELAY(map, chip,
1460 adr, map->size,
1461 @@ -2356,6 +2358,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
1462 chip->state = FL_ERASING;
1463 chip->erase_suspended = 0;
1464 chip->in_progress_block_addr = adr;
1465 + chip->in_progress_block_mask = ~(len - 1);
1466
1467 INVALIDATE_CACHE_UDELAY(map, chip,
1468 adr, len,
1469 diff --git a/drivers/mtd/nand/tango_nand.c b/drivers/mtd/nand/tango_nand.c
1470 index 766906f03943..ce366816a7ef 100644
1471 --- a/drivers/mtd/nand/tango_nand.c
1472 +++ b/drivers/mtd/nand/tango_nand.c
1473 @@ -654,7 +654,7 @@ static int tango_nand_probe(struct platform_device *pdev)
1474
1475 writel_relaxed(MODE_RAW, nfc->pbus_base + PBUS_PAD_MODE);
1476
1477 - clk = clk_get(&pdev->dev, NULL);
1478 + clk = devm_clk_get(&pdev->dev, NULL);
1479 if (IS_ERR(clk))
1480 return PTR_ERR(clk);
1481
1482 diff --git a/drivers/mtd/spi-nor/cadence-quadspi.c b/drivers/mtd/spi-nor/cadence-quadspi.c
1483 index 53c7d8e0327a..8d89204b90d2 100644
1484 --- a/drivers/mtd/spi-nor/cadence-quadspi.c
1485 +++ b/drivers/mtd/spi-nor/cadence-quadspi.c
1486 @@ -495,7 +495,9 @@ static int cqspi_indirect_read_execute(struct spi_nor *nor,
1487 void __iomem *reg_base = cqspi->iobase;
1488 void __iomem *ahb_base = cqspi->ahb_base;
1489 unsigned int remaining = n_rx;
1490 + unsigned int mod_bytes = n_rx % 4;
1491 unsigned int bytes_to_read = 0;
1492 + u8 *rxbuf_end = rxbuf + n_rx;
1493 int ret = 0;
1494
1495 writel(remaining, reg_base + CQSPI_REG_INDIRECTRDBYTES);
1496 @@ -523,11 +525,24 @@ static int cqspi_indirect_read_execute(struct spi_nor *nor,
1497 }
1498
1499 while (bytes_to_read != 0) {
1500 + unsigned int word_remain = round_down(remaining, 4);
1501 +
1502 bytes_to_read *= cqspi->fifo_width;
1503 bytes_to_read = bytes_to_read > remaining ?
1504 remaining : bytes_to_read;
1505 - ioread32_rep(ahb_base, rxbuf,
1506 - DIV_ROUND_UP(bytes_to_read, 4));
1507 + bytes_to_read = round_down(bytes_to_read, 4);
1508 + /* Read 4 byte word chunks then single bytes */
1509 + if (bytes_to_read) {
1510 + ioread32_rep(ahb_base, rxbuf,
1511 + (bytes_to_read / 4));
1512 + } else if (!word_remain && mod_bytes) {
1513 + unsigned int temp = ioread32(ahb_base);
1514 +
1515 + bytes_to_read = mod_bytes;
1516 + memcpy(rxbuf, &temp, min((unsigned int)
1517 + (rxbuf_end - rxbuf),
1518 + bytes_to_read));
1519 + }
1520 rxbuf += bytes_to_read;
1521 remaining -= bytes_to_read;
1522 bytes_to_read = cqspi_get_rd_sram_level(cqspi);
1523 diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
1524 index ce30c9a588a4..6337c394bfe3 100644
1525 --- a/drivers/of/fdt.c
1526 +++ b/drivers/of/fdt.c
1527 @@ -975,7 +975,7 @@ int __init early_init_dt_scan_chosen_stdout(void)
1528 int offset;
1529 const char *p, *q, *options = NULL;
1530 int l;
1531 - const struct earlycon_id *match;
1532 + const struct earlycon_id **p_match;
1533 const void *fdt = initial_boot_params;
1534
1535 offset = fdt_path_offset(fdt, "/chosen");
1536 @@ -1002,7 +1002,10 @@ int __init early_init_dt_scan_chosen_stdout(void)
1537 return 0;
1538 }
1539
1540 - for (match = __earlycon_table; match < __earlycon_table_end; match++) {
1541 + for (p_match = __earlycon_table; p_match < __earlycon_table_end;
1542 + p_match++) {
1543 + const struct earlycon_id *match = *p_match;
1544 +
1545 if (!match->compatible[0])
1546 continue;
1547
1548 diff --git a/drivers/pci/host/pci-aardvark.c b/drivers/pci/host/pci-aardvark.c
1549 index 26ed0c08f209..9bfc22b5da4b 100644
1550 --- a/drivers/pci/host/pci-aardvark.c
1551 +++ b/drivers/pci/host/pci-aardvark.c
1552 @@ -32,6 +32,7 @@
1553 #define PCIE_CORE_DEV_CTRL_STATS_MAX_PAYLOAD_SZ_SHIFT 5
1554 #define PCIE_CORE_DEV_CTRL_STATS_SNOOP_DISABLE (0 << 11)
1555 #define PCIE_CORE_DEV_CTRL_STATS_MAX_RD_REQ_SIZE_SHIFT 12
1556 +#define PCIE_CORE_DEV_CTRL_STATS_MAX_RD_REQ_SZ 0x2
1557 #define PCIE_CORE_LINK_CTRL_STAT_REG 0xd0
1558 #define PCIE_CORE_LINK_L0S_ENTRY BIT(0)
1559 #define PCIE_CORE_LINK_TRAINING BIT(5)
1560 @@ -103,7 +104,8 @@
1561 #define PCIE_ISR1_MASK_REG (CONTROL_BASE_ADDR + 0x4C)
1562 #define PCIE_ISR1_POWER_STATE_CHANGE BIT(4)
1563 #define PCIE_ISR1_FLUSH BIT(5)
1564 -#define PCIE_ISR1_ALL_MASK GENMASK(5, 4)
1565 +#define PCIE_ISR1_INTX_ASSERT(val) BIT(8 + (val))
1566 +#define PCIE_ISR1_ALL_MASK GENMASK(11, 4)
1567 #define PCIE_MSI_ADDR_LOW_REG (CONTROL_BASE_ADDR + 0x50)
1568 #define PCIE_MSI_ADDR_HIGH_REG (CONTROL_BASE_ADDR + 0x54)
1569 #define PCIE_MSI_STATUS_REG (CONTROL_BASE_ADDR + 0x58)
1570 @@ -175,8 +177,6 @@
1571 #define PCIE_CONFIG_WR_TYPE0 0xa
1572 #define PCIE_CONFIG_WR_TYPE1 0xb
1573
1574 -/* PCI_BDF shifts 8bit, so we need extra 4bit shift */
1575 -#define PCIE_BDF(dev) (dev << 4)
1576 #define PCIE_CONF_BUS(bus) (((bus) & 0xff) << 20)
1577 #define PCIE_CONF_DEV(dev) (((dev) & 0x1f) << 15)
1578 #define PCIE_CONF_FUNC(fun) (((fun) & 0x7) << 12)
1579 @@ -299,7 +299,8 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)
1580 reg = PCIE_CORE_DEV_CTRL_STATS_RELAX_ORDER_DISABLE |
1581 (7 << PCIE_CORE_DEV_CTRL_STATS_MAX_PAYLOAD_SZ_SHIFT) |
1582 PCIE_CORE_DEV_CTRL_STATS_SNOOP_DISABLE |
1583 - PCIE_CORE_DEV_CTRL_STATS_MAX_RD_REQ_SIZE_SHIFT;
1584 + (PCIE_CORE_DEV_CTRL_STATS_MAX_RD_REQ_SZ <<
1585 + PCIE_CORE_DEV_CTRL_STATS_MAX_RD_REQ_SIZE_SHIFT);
1586 advk_writel(pcie, reg, PCIE_CORE_DEV_CTRL_STATS_REG);
1587
1588 /* Program PCIe Control 2 to disable strict ordering */
1589 @@ -440,7 +441,7 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
1590 u32 reg;
1591 int ret;
1592
1593 - if (PCI_SLOT(devfn) != 0) {
1594 + if ((bus->number == pcie->root_bus_nr) && PCI_SLOT(devfn) != 0) {
1595 *val = 0xffffffff;
1596 return PCIBIOS_DEVICE_NOT_FOUND;
1597 }
1598 @@ -459,7 +460,7 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
1599 advk_writel(pcie, reg, PIO_CTRL);
1600
1601 /* Program the address registers */
1602 - reg = PCIE_BDF(devfn) | PCIE_CONF_REG(where);
1603 + reg = PCIE_CONF_ADDR(bus->number, devfn, where);
1604 advk_writel(pcie, reg, PIO_ADDR_LS);
1605 advk_writel(pcie, 0, PIO_ADDR_MS);
1606
1607 @@ -494,7 +495,7 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
1608 int offset;
1609 int ret;
1610
1611 - if (PCI_SLOT(devfn) != 0)
1612 + if ((bus->number == pcie->root_bus_nr) && PCI_SLOT(devfn) != 0)
1613 return PCIBIOS_DEVICE_NOT_FOUND;
1614
1615 if (where % size)
1616 @@ -612,9 +613,9 @@ static void advk_pcie_irq_mask(struct irq_data *d)
1617 irq_hw_number_t hwirq = irqd_to_hwirq(d);
1618 u32 mask;
1619
1620 - mask = advk_readl(pcie, PCIE_ISR0_MASK_REG);
1621 - mask |= PCIE_ISR0_INTX_ASSERT(hwirq);
1622 - advk_writel(pcie, mask, PCIE_ISR0_MASK_REG);
1623 + mask = advk_readl(pcie, PCIE_ISR1_MASK_REG);
1624 + mask |= PCIE_ISR1_INTX_ASSERT(hwirq);
1625 + advk_writel(pcie, mask, PCIE_ISR1_MASK_REG);
1626 }
1627
1628 static void advk_pcie_irq_unmask(struct irq_data *d)
1629 @@ -623,9 +624,9 @@ static void advk_pcie_irq_unmask(struct irq_data *d)
1630 irq_hw_number_t hwirq = irqd_to_hwirq(d);
1631 u32 mask;
1632
1633 - mask = advk_readl(pcie, PCIE_ISR0_MASK_REG);
1634 - mask &= ~PCIE_ISR0_INTX_ASSERT(hwirq);
1635 - advk_writel(pcie, mask, PCIE_ISR0_MASK_REG);
1636 + mask = advk_readl(pcie, PCIE_ISR1_MASK_REG);
1637 + mask &= ~PCIE_ISR1_INTX_ASSERT(hwirq);
1638 + advk_writel(pcie, mask, PCIE_ISR1_MASK_REG);
1639 }
1640
1641 static int advk_pcie_irq_map(struct irq_domain *h,
1642 @@ -768,29 +769,35 @@ static void advk_pcie_handle_msi(struct advk_pcie *pcie)
1643
1644 static void advk_pcie_handle_int(struct advk_pcie *pcie)
1645 {
1646 - u32 val, mask, status;
1647 + u32 isr0_val, isr0_mask, isr0_status;
1648 + u32 isr1_val, isr1_mask, isr1_status;
1649 int i, virq;
1650
1651 - val = advk_readl(pcie, PCIE_ISR0_REG);
1652 - mask = advk_readl(pcie, PCIE_ISR0_MASK_REG);
1653 - status = val & ((~mask) & PCIE_ISR0_ALL_MASK);
1654 + isr0_val = advk_readl(pcie, PCIE_ISR0_REG);
1655 + isr0_mask = advk_readl(pcie, PCIE_ISR0_MASK_REG);
1656 + isr0_status = isr0_val & ((~isr0_mask) & PCIE_ISR0_ALL_MASK);
1657 +
1658 + isr1_val = advk_readl(pcie, PCIE_ISR1_REG);
1659 + isr1_mask = advk_readl(pcie, PCIE_ISR1_MASK_REG);
1660 + isr1_status = isr1_val & ((~isr1_mask) & PCIE_ISR1_ALL_MASK);
1661
1662 - if (!status) {
1663 - advk_writel(pcie, val, PCIE_ISR0_REG);
1664 + if (!isr0_status && !isr1_status) {
1665 + advk_writel(pcie, isr0_val, PCIE_ISR0_REG);
1666 + advk_writel(pcie, isr1_val, PCIE_ISR1_REG);
1667 return;
1668 }
1669
1670 /* Process MSI interrupts */
1671 - if (status & PCIE_ISR0_MSI_INT_PENDING)
1672 + if (isr0_status & PCIE_ISR0_MSI_INT_PENDING)
1673 advk_pcie_handle_msi(pcie);
1674
1675 /* Process legacy interrupts */
1676 for (i = 0; i < PCI_NUM_INTX; i++) {
1677 - if (!(status & PCIE_ISR0_INTX_ASSERT(i)))
1678 + if (!(isr1_status & PCIE_ISR1_INTX_ASSERT(i)))
1679 continue;
1680
1681 - advk_writel(pcie, PCIE_ISR0_INTX_ASSERT(i),
1682 - PCIE_ISR0_REG);
1683 + advk_writel(pcie, PCIE_ISR1_INTX_ASSERT(i),
1684 + PCIE_ISR1_REG);
1685
1686 virq = irq_find_mapping(pcie->irq_domain, i);
1687 generic_handle_irq(virq);
1688 diff --git a/drivers/rtc/rtc-opal.c b/drivers/rtc/rtc-opal.c
1689 index 304e891e35fc..60f2250fd96b 100644
1690 --- a/drivers/rtc/rtc-opal.c
1691 +++ b/drivers/rtc/rtc-opal.c
1692 @@ -57,7 +57,7 @@ static void tm_to_opal(struct rtc_time *tm, u32 *y_m_d, u64 *h_m_s_ms)
1693
1694 static int opal_get_rtc_time(struct device *dev, struct rtc_time *tm)
1695 {
1696 - long rc = OPAL_BUSY;
1697 + s64 rc = OPAL_BUSY;
1698 int retries = 10;
1699 u32 y_m_d;
1700 u64 h_m_s_ms;
1701 @@ -66,13 +66,17 @@ static int opal_get_rtc_time(struct device *dev, struct rtc_time *tm)
1702
1703 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
1704 rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms);
1705 - if (rc == OPAL_BUSY_EVENT)
1706 + if (rc == OPAL_BUSY_EVENT) {
1707 + msleep(OPAL_BUSY_DELAY_MS);
1708 opal_poll_events(NULL);
1709 - else if (retries-- && (rc == OPAL_HARDWARE
1710 - || rc == OPAL_INTERNAL_ERROR))
1711 - msleep(10);
1712 - else if (rc != OPAL_BUSY && rc != OPAL_BUSY_EVENT)
1713 - break;
1714 + } else if (rc == OPAL_BUSY) {
1715 + msleep(OPAL_BUSY_DELAY_MS);
1716 + } else if (rc == OPAL_HARDWARE || rc == OPAL_INTERNAL_ERROR) {
1717 + if (retries--) {
1718 + msleep(10); /* Wait 10ms before retry */
1719 + rc = OPAL_BUSY; /* go around again */
1720 + }
1721 + }
1722 }
1723
1724 if (rc != OPAL_SUCCESS)
1725 @@ -87,21 +91,26 @@ static int opal_get_rtc_time(struct device *dev, struct rtc_time *tm)
1726
1727 static int opal_set_rtc_time(struct device *dev, struct rtc_time *tm)
1728 {
1729 - long rc = OPAL_BUSY;
1730 + s64 rc = OPAL_BUSY;
1731 int retries = 10;
1732 u32 y_m_d = 0;
1733 u64 h_m_s_ms = 0;
1734
1735 tm_to_opal(tm, &y_m_d, &h_m_s_ms);
1736 +
1737 while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
1738 rc = opal_rtc_write(y_m_d, h_m_s_ms);
1739 - if (rc == OPAL_BUSY_EVENT)
1740 + if (rc == OPAL_BUSY_EVENT) {
1741 + msleep(OPAL_BUSY_DELAY_MS);
1742 opal_poll_events(NULL);
1743 - else if (retries-- && (rc == OPAL_HARDWARE
1744 - || rc == OPAL_INTERNAL_ERROR))
1745 - msleep(10);
1746 - else if (rc != OPAL_BUSY && rc != OPAL_BUSY_EVENT)
1747 - break;
1748 + } else if (rc == OPAL_BUSY) {
1749 + msleep(OPAL_BUSY_DELAY_MS);
1750 + } else if (rc == OPAL_HARDWARE || rc == OPAL_INTERNAL_ERROR) {
1751 + if (retries--) {
1752 + msleep(10); /* Wait 10ms before retry */
1753 + rc = OPAL_BUSY; /* go around again */
1754 + }
1755 + }
1756 }
1757
1758 return rc == OPAL_SUCCESS ? 0 : -EIO;
1759 diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c
1760 index c30420c517b1..e96b85579f21 100644
1761 --- a/drivers/s390/cio/vfio_ccw_fsm.c
1762 +++ b/drivers/s390/cio/vfio_ccw_fsm.c
1763 @@ -20,12 +20,12 @@ static int fsm_io_helper(struct vfio_ccw_private *private)
1764 int ccode;
1765 __u8 lpm;
1766 unsigned long flags;
1767 + int ret;
1768
1769 sch = private->sch;
1770
1771 spin_lock_irqsave(sch->lock, flags);
1772 private->state = VFIO_CCW_STATE_BUSY;
1773 - spin_unlock_irqrestore(sch->lock, flags);
1774
1775 orb = cp_get_orb(&private->cp, (u32)(addr_t)sch, sch->lpm);
1776
1777 @@ -38,10 +38,12 @@ static int fsm_io_helper(struct vfio_ccw_private *private)
1778 * Initialize device status information
1779 */
1780 sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
1781 - return 0;
1782 + ret = 0;
1783 + break;
1784 case 1: /* Status pending */
1785 case 2: /* Busy */
1786 - return -EBUSY;
1787 + ret = -EBUSY;
1788 + break;
1789 case 3: /* Device/path not operational */
1790 {
1791 lpm = orb->cmd.lpm;
1792 @@ -51,13 +53,16 @@ static int fsm_io_helper(struct vfio_ccw_private *private)
1793 sch->lpm = 0;
1794
1795 if (cio_update_schib(sch))
1796 - return -ENODEV;
1797 -
1798 - return sch->lpm ? -EACCES : -ENODEV;
1799 + ret = -ENODEV;
1800 + else
1801 + ret = sch->lpm ? -EACCES : -ENODEV;
1802 + break;
1803 }
1804 default:
1805 - return ccode;
1806 + ret = ccode;
1807 }
1808 + spin_unlock_irqrestore(sch->lock, flags);
1809 + return ret;
1810 }
1811
1812 static void fsm_notoper(struct vfio_ccw_private *private,
1813 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
1814 index 72db0f7d221a..2f9912de2212 100644
1815 --- a/drivers/scsi/sd.c
1816 +++ b/drivers/scsi/sd.c
1817 @@ -2132,6 +2132,8 @@ sd_spinup_disk(struct scsi_disk *sdkp)
1818 break; /* standby */
1819 if (sshdr.asc == 4 && sshdr.ascq == 0xc)
1820 break; /* unavailable */
1821 + if (sshdr.asc == 4 && sshdr.ascq == 0x1b)
1822 + break; /* sanitize in progress */
1823 /*
1824 * Issue command to spin up drive when not ready
1825 */
1826 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
1827 index 7253e8d2c6d9..f46bd1af7a10 100644
1828 --- a/drivers/tty/n_gsm.c
1829 +++ b/drivers/tty/n_gsm.c
1830 @@ -133,6 +133,9 @@ struct gsm_dlci {
1831 struct mutex mutex;
1832
1833 /* Link layer */
1834 + int mode;
1835 +#define DLCI_MODE_ABM 0 /* Normal Asynchronous Balanced Mode */
1836 +#define DLCI_MODE_ADM 1 /* Asynchronous Disconnected Mode */
1837 spinlock_t lock; /* Protects the internal state */
1838 struct timer_list t1; /* Retransmit timer for SABM and UA */
1839 int retries;
1840 @@ -1376,7 +1379,13 @@ static struct gsm_control *gsm_control_send(struct gsm_mux *gsm,
1841 ctrl->data = data;
1842 ctrl->len = clen;
1843 gsm->pending_cmd = ctrl;
1844 - gsm->cretries = gsm->n2;
1845 +
1846 + /* If DLCI0 is in ADM mode skip retries, it won't respond */
1847 + if (gsm->dlci[0]->mode == DLCI_MODE_ADM)
1848 + gsm->cretries = 1;
1849 + else
1850 + gsm->cretries = gsm->n2;
1851 +
1852 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100);
1853 gsm_control_transmit(gsm, ctrl);
1854 spin_unlock_irqrestore(&gsm->control_lock, flags);
1855 @@ -1484,6 +1493,7 @@ static void gsm_dlci_t1(unsigned long data)
1856 if (debug & 8)
1857 pr_info("DLCI %d opening in ADM mode.\n",
1858 dlci->addr);
1859 + dlci->mode = DLCI_MODE_ADM;
1860 gsm_dlci_open(dlci);
1861 } else {
1862 gsm_dlci_close(dlci);
1863 @@ -2875,11 +2885,22 @@ static int gsmtty_modem_update(struct gsm_dlci *dlci, u8 brk)
1864 static int gsm_carrier_raised(struct tty_port *port)
1865 {
1866 struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port);
1867 + struct gsm_mux *gsm = dlci->gsm;
1868 +
1869 /* Not yet open so no carrier info */
1870 if (dlci->state != DLCI_OPEN)
1871 return 0;
1872 if (debug & 2)
1873 return 1;
1874 +
1875 + /*
1876 + * Basic mode with control channel in ADM mode may not respond
1877 + * to CMD_MSC at all and modem_rx is empty.
1878 + */
1879 + if (gsm->encoding == 0 && gsm->dlci[0]->mode == DLCI_MODE_ADM &&
1880 + !dlci->modem_rx)
1881 + return 1;
1882 +
1883 return dlci->modem_rx & TIOCM_CD;
1884 }
1885
1886 diff --git a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
1887 index 17dba0af5ee9..ac667b47f199 100644
1888 --- a/drivers/tty/serial/earlycon.c
1889 +++ b/drivers/tty/serial/earlycon.c
1890 @@ -172,7 +172,7 @@ static int __init register_earlycon(char *buf, const struct earlycon_id *match)
1891 */
1892 int __init setup_earlycon(char *buf)
1893 {
1894 - const struct earlycon_id *match;
1895 + const struct earlycon_id **p_match;
1896
1897 if (!buf || !buf[0])
1898 return -EINVAL;
1899 @@ -180,7 +180,9 @@ int __init setup_earlycon(char *buf)
1900 if (early_con.flags & CON_ENABLED)
1901 return -EALREADY;
1902
1903 - for (match = __earlycon_table; match < __earlycon_table_end; match++) {
1904 + for (p_match = __earlycon_table; p_match < __earlycon_table_end;
1905 + p_match++) {
1906 + const struct earlycon_id *match = *p_match;
1907 size_t len = strlen(match->name);
1908
1909 if (strncmp(buf, match->name, len))
1910 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
1911 index 52627478ab61..562d31073f9a 100644
1912 --- a/drivers/tty/tty_io.c
1913 +++ b/drivers/tty/tty_io.c
1914 @@ -2815,7 +2815,10 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)
1915
1916 kref_init(&tty->kref);
1917 tty->magic = TTY_MAGIC;
1918 - tty_ldisc_init(tty);
1919 + if (tty_ldisc_init(tty)) {
1920 + kfree(tty);
1921 + return NULL;
1922 + }
1923 tty->session = NULL;
1924 tty->pgrp = NULL;
1925 mutex_init(&tty->legacy_mutex);
1926 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
1927 index 7c895684c3ef..ca656ef8de64 100644
1928 --- a/drivers/tty/tty_ldisc.c
1929 +++ b/drivers/tty/tty_ldisc.c
1930 @@ -175,12 +175,11 @@ static struct tty_ldisc *tty_ldisc_get(struct tty_struct *tty, int disc)
1931 return ERR_CAST(ldops);
1932 }
1933
1934 - ld = kmalloc(sizeof(struct tty_ldisc), GFP_KERNEL);
1935 - if (ld == NULL) {
1936 - put_ldops(ldops);
1937 - return ERR_PTR(-ENOMEM);
1938 - }
1939 -
1940 + /*
1941 + * There is no way to handle allocation failure of only 16 bytes.
1942 + * Let's simplify error handling and save more memory.
1943 + */
1944 + ld = kmalloc(sizeof(struct tty_ldisc), GFP_KERNEL | __GFP_NOFAIL);
1945 ld->ops = ldops;
1946 ld->tty = tty;
1947
1948 @@ -526,19 +525,16 @@ static int tty_ldisc_failto(struct tty_struct *tty, int ld)
1949 static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
1950 {
1951 /* There is an outstanding reference here so this is safe */
1952 - old = tty_ldisc_get(tty, old->ops->num);
1953 - WARN_ON(IS_ERR(old));
1954 - tty->ldisc = old;
1955 - tty_set_termios_ldisc(tty, old->ops->num);
1956 - if (tty_ldisc_open(tty, old) < 0) {
1957 - tty_ldisc_put(old);
1958 + if (tty_ldisc_failto(tty, old->ops->num) < 0) {
1959 + const char *name = tty_name(tty);
1960 +
1961 + pr_warn("Falling back ldisc for %s.\n", name);
1962 /* The traditional behaviour is to fall back to N_TTY, we
1963 want to avoid falling back to N_NULL unless we have no
1964 choice to avoid the risk of breaking anything */
1965 if (tty_ldisc_failto(tty, N_TTY) < 0 &&
1966 tty_ldisc_failto(tty, N_NULL) < 0)
1967 - panic("Couldn't open N_NULL ldisc for %s.",
1968 - tty_name(tty));
1969 + panic("Couldn't open N_NULL ldisc for %s.", name);
1970 }
1971 }
1972
1973 @@ -823,12 +819,13 @@ EXPORT_SYMBOL_GPL(tty_ldisc_release);
1974 * the tty structure is not completely set up when this call is made.
1975 */
1976
1977 -void tty_ldisc_init(struct tty_struct *tty)
1978 +int tty_ldisc_init(struct tty_struct *tty)
1979 {
1980 struct tty_ldisc *ld = tty_ldisc_get(tty, N_TTY);
1981 if (IS_ERR(ld))
1982 - panic("n_tty: init_tty");
1983 + return PTR_ERR(ld);
1984 tty->ldisc = ld;
1985 + return 0;
1986 }
1987
1988 /**
1989 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
1990 index 75ad6718858c..d0b2e0ed9bab 100644
1991 --- a/drivers/usb/core/hcd.c
1992 +++ b/drivers/usb/core/hcd.c
1993 @@ -2376,6 +2376,7 @@ void usb_hcd_resume_root_hub (struct usb_hcd *hcd)
1994
1995 spin_lock_irqsave (&hcd_root_hub_lock, flags);
1996 if (hcd->rh_registered) {
1997 + pm_wakeup_event(&hcd->self.root_hub->dev, 0);
1998 set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags);
1999 queue_work(pm_wq, &hcd->wakeup_work);
2000 }
2001 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
2002 index 8f7d94239ee3..442be7f312f6 100644
2003 --- a/drivers/usb/core/hub.c
2004 +++ b/drivers/usb/core/hub.c
2005 @@ -650,12 +650,17 @@ void usb_wakeup_notification(struct usb_device *hdev,
2006 unsigned int portnum)
2007 {
2008 struct usb_hub *hub;
2009 + struct usb_port *port_dev;
2010
2011 if (!hdev)
2012 return;
2013
2014 hub = usb_hub_to_struct_hub(hdev);
2015 if (hub) {
2016 + port_dev = hub->ports[portnum - 1];
2017 + if (port_dev && port_dev->child)
2018 + pm_wakeup_event(&port_dev->child->dev, 0);
2019 +
2020 set_bit(portnum, hub->wakeup_bits);
2021 kick_hub_wq(hub);
2022 }
2023 @@ -3415,8 +3420,11 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
2024
2025 /* Skip the initial Clear-Suspend step for a remote wakeup */
2026 status = hub_port_status(hub, port1, &portstatus, &portchange);
2027 - if (status == 0 && !port_is_suspended(hub, portstatus))
2028 + if (status == 0 && !port_is_suspended(hub, portstatus)) {
2029 + if (portchange & USB_PORT_STAT_C_SUSPEND)
2030 + pm_wakeup_event(&udev->dev, 0);
2031 goto SuspendCleared;
2032 + }
2033
2034 /* see 7.1.7.7; affects power usage, but not budgeting */
2035 if (hub_is_superspeed(hub->hdev))
2036 diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
2037 index 4f1c6f8d4352..40ce175655e6 100644
2038 --- a/drivers/usb/core/quirks.c
2039 +++ b/drivers/usb/core/quirks.c
2040 @@ -45,6 +45,9 @@ static const struct usb_device_id usb_quirk_list[] = {
2041 { USB_DEVICE(0x03f0, 0x0701), .driver_info =
2042 USB_QUIRK_STRING_FETCH_255 },
2043
2044 + /* HP v222w 16GB Mini USB Drive */
2045 + { USB_DEVICE(0x03f0, 0x3f40), .driver_info = USB_QUIRK_DELAY_INIT },
2046 +
2047 /* Creative SB Audigy 2 NX */
2048 { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME },
2049
2050 diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
2051 index 3fb57cf8abb8..d79ab0d85924 100644
2052 --- a/drivers/usb/host/xhci-pci.c
2053 +++ b/drivers/usb/host/xhci-pci.c
2054 @@ -134,7 +134,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
2055 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info())
2056 xhci->quirks |= XHCI_AMD_PLL_FIX;
2057
2058 - if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x43bb)
2059 + if (pdev->vendor == PCI_VENDOR_ID_AMD &&
2060 + (pdev->device == 0x15e0 ||
2061 + pdev->device == 0x15e1 ||
2062 + pdev->device == 0x43bb))
2063 xhci->quirks |= XHCI_SUSPEND_DELAY;
2064
2065 if (pdev->vendor == PCI_VENDOR_ID_AMD)
2066 diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
2067 index 1cb6eaef4ae1..7d9e085f7b85 100644
2068 --- a/drivers/usb/host/xhci-plat.c
2069 +++ b/drivers/usb/host/xhci-plat.c
2070 @@ -423,7 +423,6 @@ MODULE_DEVICE_TABLE(acpi, usb_xhci_acpi_match);
2071 static struct platform_driver usb_xhci_driver = {
2072 .probe = xhci_plat_probe,
2073 .remove = xhci_plat_remove,
2074 - .shutdown = usb_hcd_platform_shutdown,
2075 .driver = {
2076 .name = "xhci-hcd",
2077 .pm = &xhci_plat_pm_ops,
2078 diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
2079 index c66b93664d54..c508e2d7104b 100644
2080 --- a/drivers/usb/serial/Kconfig
2081 +++ b/drivers/usb/serial/Kconfig
2082 @@ -62,6 +62,7 @@ config USB_SERIAL_SIMPLE
2083 - Fundamental Software dongle.
2084 - Google USB serial devices
2085 - HP4x calculators
2086 + - Libtransistor USB console
2087 - a number of Motorola phones
2088 - Motorola Tetra devices
2089 - Novatel Wireless GPS receivers
2090 diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
2091 index 2836acf73a07..d0f00274d16c 100644
2092 --- a/drivers/usb/serial/cp210x.c
2093 +++ b/drivers/usb/serial/cp210x.c
2094 @@ -217,6 +217,7 @@ static const struct usb_device_id id_table[] = {
2095 { USB_DEVICE(0x3195, 0xF190) }, /* Link Instruments MSO-19 */
2096 { USB_DEVICE(0x3195, 0xF280) }, /* Link Instruments MSO-28 */
2097 { USB_DEVICE(0x3195, 0xF281) }, /* Link Instruments MSO-28 */
2098 + { USB_DEVICE(0x3923, 0x7A0B) }, /* National Instruments USB Serial Console */
2099 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */
2100 { } /* Terminating Entry */
2101 };
2102 diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
2103 index a2a5232751cb..385f2ae3be24 100644
2104 --- a/drivers/usb/serial/ftdi_sio.c
2105 +++ b/drivers/usb/serial/ftdi_sio.c
2106 @@ -1902,7 +1902,8 @@ static int ftdi_8u2232c_probe(struct usb_serial *serial)
2107 return ftdi_jtag_probe(serial);
2108
2109 if (udev->product &&
2110 - (!strcmp(udev->product, "BeagleBone/XDS100V2") ||
2111 + (!strcmp(udev->product, "Arrow USB Blaster") ||
2112 + !strcmp(udev->product, "BeagleBone/XDS100V2") ||
2113 !strcmp(udev->product, "SNAP Connect E10")))
2114 return ftdi_jtag_probe(serial);
2115
2116 diff --git a/drivers/usb/serial/usb-serial-simple.c b/drivers/usb/serial/usb-serial-simple.c
2117 index 6aa7ff2c1cf7..2674da40d9cd 100644
2118 --- a/drivers/usb/serial/usb-serial-simple.c
2119 +++ b/drivers/usb/serial/usb-serial-simple.c
2120 @@ -66,6 +66,11 @@ DEVICE(flashloader, FLASHLOADER_IDS);
2121 0x01) }
2122 DEVICE(google, GOOGLE_IDS);
2123
2124 +/* Libtransistor USB console */
2125 +#define LIBTRANSISTOR_IDS() \
2126 + { USB_DEVICE(0x1209, 0x8b00) }
2127 +DEVICE(libtransistor, LIBTRANSISTOR_IDS);
2128 +
2129 /* ViVOpay USB Serial Driver */
2130 #define VIVOPAY_IDS() \
2131 { USB_DEVICE(0x1d5f, 0x1004) } /* ViVOpay 8800 */
2132 @@ -113,6 +118,7 @@ static struct usb_serial_driver * const serial_drivers[] = {
2133 &funsoft_device,
2134 &flashloader_device,
2135 &google_device,
2136 + &libtransistor_device,
2137 &vivopay_device,
2138 &moto_modem_device,
2139 &motorola_tetra_device,
2140 @@ -129,6 +135,7 @@ static const struct usb_device_id id_table[] = {
2141 FUNSOFT_IDS(),
2142 FLASHLOADER_IDS(),
2143 GOOGLE_IDS(),
2144 + LIBTRANSISTOR_IDS(),
2145 VIVOPAY_IDS(),
2146 MOTO_IDS(),
2147 MOTOROLA_TETRA_IDS(),
2148 diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
2149 index 714c5bcedf2b..dd24c5c1534d 100644
2150 --- a/drivers/usb/typec/ucsi/ucsi.c
2151 +++ b/drivers/usb/typec/ucsi/ucsi.c
2152 @@ -31,7 +31,7 @@
2153 * difficult to estimate the time it takes for the system to process the command
2154 * before it is actually passed to the PPM.
2155 */
2156 -#define UCSI_TIMEOUT_MS 1000
2157 +#define UCSI_TIMEOUT_MS 5000
2158
2159 /*
2160 * UCSI_SWAP_TIMEOUT_MS - Timeout for role swap requests
2161 diff --git a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c
2162 index 6968c906fa29..b59a253a8479 100644
2163 --- a/drivers/usb/usbip/stub_main.c
2164 +++ b/drivers/usb/usbip/stub_main.c
2165 @@ -200,7 +200,12 @@ static ssize_t rebind_store(struct device_driver *dev, const char *buf,
2166 if (!bid)
2167 return -ENODEV;
2168
2169 + /* device_attach() callers should hold parent lock for USB */
2170 + if (bid->udev->dev.parent)
2171 + device_lock(bid->udev->dev.parent);
2172 ret = device_attach(&bid->udev->dev);
2173 + if (bid->udev->dev.parent)
2174 + device_unlock(bid->udev->dev.parent);
2175 if (ret < 0) {
2176 dev_err(&bid->udev->dev, "rebind failed\n");
2177 return ret;
2178 diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_common.h
2179 index 33737b612b1f..c81c44c13a56 100644
2180 --- a/drivers/usb/usbip/usbip_common.h
2181 +++ b/drivers/usb/usbip/usbip_common.h
2182 @@ -257,7 +257,7 @@ enum usbip_side {
2183 #define VUDC_EVENT_ERROR_USB (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE)
2184 #define VUDC_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE)
2185
2186 -#define VDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_BYE)
2187 +#define VDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE)
2188 #define VDEV_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
2189 #define VDEV_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
2190 #define VDEV_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE)
2191 diff --git a/drivers/usb/usbip/usbip_event.c b/drivers/usb/usbip/usbip_event.c
2192 index f1635662c299..f8f7f3803a99 100644
2193 --- a/drivers/usb/usbip/usbip_event.c
2194 +++ b/drivers/usb/usbip/usbip_event.c
2195 @@ -105,10 +105,6 @@ static void event_handler(struct work_struct *work)
2196 unset_event(ud, USBIP_EH_UNUSABLE);
2197 }
2198
2199 - /* Stop the error handler. */
2200 - if (ud->event & USBIP_EH_BYE)
2201 - usbip_dbg_eh("removed %p\n", ud);
2202 -
2203 wake_up(&ud->eh_waitq);
2204 }
2205 }
2206 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
2207 index 89858aeed647..05aa1ba351b6 100644
2208 --- a/drivers/usb/usbip/vhci_hcd.c
2209 +++ b/drivers/usb/usbip/vhci_hcd.c
2210 @@ -368,6 +368,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2211 usbip_dbg_vhci_rh(" ClearHubFeature\n");
2212 break;
2213 case ClearPortFeature:
2214 + if (rhport < 0)
2215 + goto error;
2216 switch (wValue) {
2217 case USB_PORT_FEAT_SUSPEND:
2218 if (hcd->speed == HCD_USB3) {
2219 @@ -525,11 +527,16 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2220 goto error;
2221 }
2222
2223 + if (rhport < 0)
2224 + goto error;
2225 +
2226 vhci_hcd->port_status[rhport] |= USB_PORT_STAT_SUSPEND;
2227 break;
2228 case USB_PORT_FEAT_POWER:
2229 usbip_dbg_vhci_rh(
2230 " SetPortFeature: USB_PORT_FEAT_POWER\n");
2231 + if (rhport < 0)
2232 + goto error;
2233 if (hcd->speed == HCD_USB3)
2234 vhci_hcd->port_status[rhport] |= USB_SS_PORT_STAT_POWER;
2235 else
2236 @@ -538,6 +545,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2237 case USB_PORT_FEAT_BH_PORT_RESET:
2238 usbip_dbg_vhci_rh(
2239 " SetPortFeature: USB_PORT_FEAT_BH_PORT_RESET\n");
2240 + if (rhport < 0)
2241 + goto error;
2242 /* Applicable only for USB3.0 hub */
2243 if (hcd->speed != HCD_USB3) {
2244 pr_err("USB_PORT_FEAT_BH_PORT_RESET req not "
2245 @@ -548,6 +557,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2246 case USB_PORT_FEAT_RESET:
2247 usbip_dbg_vhci_rh(
2248 " SetPortFeature: USB_PORT_FEAT_RESET\n");
2249 + if (rhport < 0)
2250 + goto error;
2251 /* if it's already enabled, disable */
2252 if (hcd->speed == HCD_USB3) {
2253 vhci_hcd->port_status[rhport] = 0;
2254 @@ -568,6 +579,8 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2255 default:
2256 usbip_dbg_vhci_rh(" SetPortFeature: default %d\n",
2257 wValue);
2258 + if (rhport < 0)
2259 + goto error;
2260 if (hcd->speed == HCD_USB3) {
2261 if ((vhci_hcd->port_status[rhport] &
2262 USB_SS_PORT_STAT_POWER) != 0) {
2263 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
2264 index db5be5e2e6f2..58db8109defa 100644
2265 --- a/fs/ext4/balloc.c
2266 +++ b/fs/ext4/balloc.c
2267 @@ -321,6 +321,7 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
2268 struct ext4_sb_info *sbi = EXT4_SB(sb);
2269 ext4_grpblk_t offset;
2270 ext4_grpblk_t next_zero_bit;
2271 + ext4_grpblk_t max_bit = EXT4_CLUSTERS_PER_GROUP(sb);
2272 ext4_fsblk_t blk;
2273 ext4_fsblk_t group_first_block;
2274
2275 @@ -338,20 +339,25 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
2276 /* check whether block bitmap block number is set */
2277 blk = ext4_block_bitmap(sb, desc);
2278 offset = blk - group_first_block;
2279 - if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
2280 + if (offset < 0 || EXT4_B2C(sbi, offset) >= max_bit ||
2281 + !ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
2282 /* bad block bitmap */
2283 return blk;
2284
2285 /* check whether the inode bitmap block number is set */
2286 blk = ext4_inode_bitmap(sb, desc);
2287 offset = blk - group_first_block;
2288 - if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
2289 + if (offset < 0 || EXT4_B2C(sbi, offset) >= max_bit ||
2290 + !ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
2291 /* bad block bitmap */
2292 return blk;
2293
2294 /* check whether the inode table block number is set */
2295 blk = ext4_inode_table(sb, desc);
2296 offset = blk - group_first_block;
2297 + if (offset < 0 || EXT4_B2C(sbi, offset) >= max_bit ||
2298 + EXT4_B2C(sbi, offset + sbi->s_itb_per_group) >= max_bit)
2299 + return blk;
2300 next_zero_bit = ext4_find_next_zero_bit(bh->b_data,
2301 EXT4_B2C(sbi, offset + EXT4_SB(sb)->s_itb_per_group),
2302 EXT4_B2C(sbi, offset));
2303 @@ -417,6 +423,7 @@ struct buffer_head *
2304 ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
2305 {
2306 struct ext4_group_desc *desc;
2307 + struct ext4_sb_info *sbi = EXT4_SB(sb);
2308 struct buffer_head *bh;
2309 ext4_fsblk_t bitmap_blk;
2310 int err;
2311 @@ -425,6 +432,12 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
2312 if (!desc)
2313 return ERR_PTR(-EFSCORRUPTED);
2314 bitmap_blk = ext4_block_bitmap(sb, desc);
2315 + if ((bitmap_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
2316 + (bitmap_blk >= ext4_blocks_count(sbi->s_es))) {
2317 + ext4_error(sb, "Invalid block bitmap block %llu in "
2318 + "block_group %u", bitmap_blk, block_group);
2319 + return ERR_PTR(-EFSCORRUPTED);
2320 + }
2321 bh = sb_getblk(sb, bitmap_blk);
2322 if (unlikely(!bh)) {
2323 ext4_error(sb, "Cannot get buffer for block bitmap - "
2324 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
2325 index c941251ac0c0..883e89a903d1 100644
2326 --- a/fs/ext4/extents.c
2327 +++ b/fs/ext4/extents.c
2328 @@ -5346,8 +5346,9 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
2329 stop = le32_to_cpu(extent->ee_block);
2330
2331 /*
2332 - * In case of left shift, Don't start shifting extents until we make
2333 - * sure the hole is big enough to accommodate the shift.
2334 + * For left shifts, make sure the hole on the left is big enough to
2335 + * accommodate the shift. For right shifts, make sure the last extent
2336 + * won't be shifted beyond EXT_MAX_BLOCKS.
2337 */
2338 if (SHIFT == SHIFT_LEFT) {
2339 path = ext4_find_extent(inode, start - 1, &path,
2340 @@ -5367,9 +5368,14 @@ ext4_ext_shift_extents(struct inode *inode, handle_t *handle,
2341
2342 if ((start == ex_start && shift > ex_start) ||
2343 (shift > start - ex_end)) {
2344 - ext4_ext_drop_refs(path);
2345 - kfree(path);
2346 - return -EINVAL;
2347 + ret = -EINVAL;
2348 + goto out;
2349 + }
2350 + } else {
2351 + if (shift > EXT_MAX_BLOCKS -
2352 + (stop + ext4_ext_get_actual_len(extent))) {
2353 + ret = -EINVAL;
2354 + goto out;
2355 }
2356 }
2357
2358 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
2359 index 7ec55dd8db56..f420124ac035 100644
2360 --- a/fs/ext4/ialloc.c
2361 +++ b/fs/ext4/ialloc.c
2362 @@ -122,6 +122,7 @@ static struct buffer_head *
2363 ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
2364 {
2365 struct ext4_group_desc *desc;
2366 + struct ext4_sb_info *sbi = EXT4_SB(sb);
2367 struct buffer_head *bh = NULL;
2368 ext4_fsblk_t bitmap_blk;
2369 int err;
2370 @@ -131,6 +132,12 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
2371 return ERR_PTR(-EFSCORRUPTED);
2372
2373 bitmap_blk = ext4_inode_bitmap(sb, desc);
2374 + if ((bitmap_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
2375 + (bitmap_blk >= ext4_blocks_count(sbi->s_es))) {
2376 + ext4_error(sb, "Invalid inode bitmap blk %llu in "
2377 + "block_group %u", bitmap_blk, block_group);
2378 + return ERR_PTR(-EFSCORRUPTED);
2379 + }
2380 bh = sb_getblk(sb, bitmap_blk);
2381 if (unlikely(!bh)) {
2382 ext4_error(sb, "Cannot read inode bitmap - "
2383 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
2384 index 3a605c672649..9102ae7709d3 100644
2385 --- a/fs/ext4/super.c
2386 +++ b/fs/ext4/super.c
2387 @@ -5865,5 +5865,6 @@ static void __exit ext4_exit_fs(void)
2388 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
2389 MODULE_DESCRIPTION("Fourth Extended Filesystem");
2390 MODULE_LICENSE("GPL");
2391 +MODULE_SOFTDEP("pre: crc32c");
2392 module_init(ext4_init_fs)
2393 module_exit(ext4_exit_fs)
2394 diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
2395 index c0681814c379..07793e25c976 100644
2396 --- a/fs/jbd2/transaction.c
2397 +++ b/fs/jbd2/transaction.c
2398 @@ -535,6 +535,7 @@ int jbd2_journal_start_reserved(handle_t *handle, unsigned int type,
2399 */
2400 ret = start_this_handle(journal, handle, GFP_NOFS);
2401 if (ret < 0) {
2402 + handle->h_journal = journal;
2403 jbd2_journal_free_reserved(handle);
2404 return ret;
2405 }
2406 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
2407 index 353f52fdc35e..fcec26d60d8c 100644
2408 --- a/include/asm-generic/vmlinux.lds.h
2409 +++ b/include/asm-generic/vmlinux.lds.h
2410 @@ -170,7 +170,7 @@
2411 #endif
2412
2413 #ifdef CONFIG_SERIAL_EARLYCON
2414 -#define EARLYCON_TABLE() STRUCT_ALIGN(); \
2415 +#define EARLYCON_TABLE() . = ALIGN(8); \
2416 VMLINUX_SYMBOL(__earlycon_table) = .; \
2417 KEEP(*(__earlycon_table)) \
2418 VMLINUX_SYMBOL(__earlycon_table_end) = .;
2419 diff --git a/include/kvm/arm_psci.h b/include/kvm/arm_psci.h
2420 index e518e4e3dfb5..4b1548129fa2 100644
2421 --- a/include/kvm/arm_psci.h
2422 +++ b/include/kvm/arm_psci.h
2423 @@ -37,10 +37,15 @@ static inline int kvm_psci_version(struct kvm_vcpu *vcpu, struct kvm *kvm)
2424 * Our PSCI implementation stays the same across versions from
2425 * v0.2 onward, only adding the few mandatory functions (such
2426 * as FEATURES with 1.0) that are required by newer
2427 - * revisions. It is thus safe to return the latest.
2428 + * revisions. It is thus safe to return the latest, unless
2429 + * userspace has instructed us otherwise.
2430 */
2431 - if (test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features))
2432 + if (test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features)) {
2433 + if (vcpu->kvm->arch.psci_version)
2434 + return vcpu->kvm->arch.psci_version;
2435 +
2436 return KVM_ARM_PSCI_LATEST;
2437 + }
2438
2439 return KVM_ARM_PSCI_0_1;
2440 }
2441 @@ -48,4 +53,11 @@ static inline int kvm_psci_version(struct kvm_vcpu *vcpu, struct kvm *kvm)
2442
2443 int kvm_hvc_call_handler(struct kvm_vcpu *vcpu);
2444
2445 +struct kvm_one_reg;
2446 +
2447 +int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu);
2448 +int kvm_arm_copy_fw_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
2449 +int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
2450 +int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
2451 +
2452 #endif /* __KVM_ARM_PSCI_H__ */
2453 diff --git a/include/linux/mtd/flashchip.h b/include/linux/mtd/flashchip.h
2454 index b63fa457febd..3529683f691e 100644
2455 --- a/include/linux/mtd/flashchip.h
2456 +++ b/include/linux/mtd/flashchip.h
2457 @@ -85,6 +85,7 @@ struct flchip {
2458 unsigned int write_suspended:1;
2459 unsigned int erase_suspended:1;
2460 unsigned long in_progress_block_addr;
2461 + unsigned long in_progress_block_mask;
2462
2463 struct mutex mutex;
2464 wait_queue_head_t wq; /* Wait on here when we're waiting for the chip
2465 diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
2466 index 5553e04e59c9..74fc82d22310 100644
2467 --- a/include/linux/serial_core.h
2468 +++ b/include/linux/serial_core.h
2469 @@ -351,10 +351,10 @@ struct earlycon_id {
2470 char name[16];
2471 char compatible[128];
2472 int (*setup)(struct earlycon_device *, const char *options);
2473 -} __aligned(32);
2474 +};
2475
2476 -extern const struct earlycon_id __earlycon_table[];
2477 -extern const struct earlycon_id __earlycon_table_end[];
2478 +extern const struct earlycon_id *__earlycon_table[];
2479 +extern const struct earlycon_id *__earlycon_table_end[];
2480
2481 #if defined(CONFIG_SERIAL_EARLYCON) && !defined(MODULE)
2482 #define EARLYCON_USED_OR_UNUSED __used
2483 @@ -362,12 +362,19 @@ extern const struct earlycon_id __earlycon_table_end[];
2484 #define EARLYCON_USED_OR_UNUSED __maybe_unused
2485 #endif
2486
2487 -#define OF_EARLYCON_DECLARE(_name, compat, fn) \
2488 - static const struct earlycon_id __UNIQUE_ID(__earlycon_##_name) \
2489 - EARLYCON_USED_OR_UNUSED __section(__earlycon_table) \
2490 +#define _OF_EARLYCON_DECLARE(_name, compat, fn, unique_id) \
2491 + static const struct earlycon_id unique_id \
2492 + EARLYCON_USED_OR_UNUSED __initconst \
2493 = { .name = __stringify(_name), \
2494 .compatible = compat, \
2495 - .setup = fn }
2496 + .setup = fn }; \
2497 + static const struct earlycon_id EARLYCON_USED_OR_UNUSED \
2498 + __section(__earlycon_table) \
2499 + * const __PASTE(__p, unique_id) = &unique_id
2500 +
2501 +#define OF_EARLYCON_DECLARE(_name, compat, fn) \
2502 + _OF_EARLYCON_DECLARE(_name, compat, fn, \
2503 + __UNIQUE_ID(__earlycon_##_name))
2504
2505 #define EARLYCON_DECLARE(_name, fn) OF_EARLYCON_DECLARE(_name, "", fn)
2506
2507 diff --git a/include/linux/tty.h b/include/linux/tty.h
2508 index 47f8af22f216..1dd587ba6d88 100644
2509 --- a/include/linux/tty.h
2510 +++ b/include/linux/tty.h
2511 @@ -701,7 +701,7 @@ extern int tty_unregister_ldisc(int disc);
2512 extern int tty_set_ldisc(struct tty_struct *tty, int disc);
2513 extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty);
2514 extern void tty_ldisc_release(struct tty_struct *tty);
2515 -extern void tty_ldisc_init(struct tty_struct *tty);
2516 +extern int __must_check tty_ldisc_init(struct tty_struct *tty);
2517 extern void tty_ldisc_deinit(struct tty_struct *tty);
2518 extern int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p,
2519 char *f, int count);
2520 diff --git a/include/linux/virtio.h b/include/linux/virtio.h
2521 index 988c7355bc22..fa1b5da2804e 100644
2522 --- a/include/linux/virtio.h
2523 +++ b/include/linux/virtio.h
2524 @@ -157,6 +157,9 @@ int virtio_device_freeze(struct virtio_device *dev);
2525 int virtio_device_restore(struct virtio_device *dev);
2526 #endif
2527
2528 +#define virtio_device_for_each_vq(vdev, vq) \
2529 + list_for_each_entry(vq, &vdev->vqs, list)
2530 +
2531 /**
2532 * virtio_driver - operations for a virtio I/O driver
2533 * @driver: underlying device driver (populate name and owner).
2534 diff --git a/include/sound/control.h b/include/sound/control.h
2535 index ca13a44ae9d4..6011a58d3e20 100644
2536 --- a/include/sound/control.h
2537 +++ b/include/sound/control.h
2538 @@ -23,6 +23,7 @@
2539 */
2540
2541 #include <linux/wait.h>
2542 +#include <linux/nospec.h>
2543 #include <sound/asound.h>
2544
2545 #define snd_kcontrol_chip(kcontrol) ((kcontrol)->private_data)
2546 @@ -148,12 +149,14 @@ int snd_ctl_get_preferred_subdevice(struct snd_card *card, int type);
2547
2548 static inline unsigned int snd_ctl_get_ioffnum(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
2549 {
2550 - return id->numid - kctl->id.numid;
2551 + unsigned int ioff = id->numid - kctl->id.numid;
2552 + return array_index_nospec(ioff, kctl->count);
2553 }
2554
2555 static inline unsigned int snd_ctl_get_ioffidx(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
2556 {
2557 - return id->index - kctl->id.index;
2558 + unsigned int ioff = id->index - kctl->id.index;
2559 + return array_index_nospec(ioff, kctl->count);
2560 }
2561
2562 static inline unsigned int snd_ctl_get_ioff(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
2563 diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
2564 index dfa4a117fee3..bb2af74e6b62 100644
2565 --- a/kernel/time/tick-sched.c
2566 +++ b/kernel/time/tick-sched.c
2567 @@ -820,12 +820,13 @@ static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts,
2568 goto out;
2569 }
2570
2571 - hrtimer_set_expires(&ts->sched_timer, tick);
2572 -
2573 - if (ts->nohz_mode == NOHZ_MODE_HIGHRES)
2574 - hrtimer_start_expires(&ts->sched_timer, HRTIMER_MODE_ABS_PINNED);
2575 - else
2576 + if (ts->nohz_mode == NOHZ_MODE_HIGHRES) {
2577 + hrtimer_start(&ts->sched_timer, tick, HRTIMER_MODE_ABS_PINNED);
2578 + } else {
2579 + hrtimer_set_expires(&ts->sched_timer, tick);
2580 tick_program_event(tick, 1);
2581 + }
2582 +
2583 out:
2584 /*
2585 * Update the estimated sleep length until the next timer
2586 diff --git a/lib/kobject.c b/lib/kobject.c
2587 index 763d70a18941..34f847252c02 100644
2588 --- a/lib/kobject.c
2589 +++ b/lib/kobject.c
2590 @@ -234,14 +234,12 @@ static int kobject_add_internal(struct kobject *kobj)
2591
2592 /* be noisy on error issues */
2593 if (error == -EEXIST)
2594 - WARN(1, "%s failed for %s with "
2595 - "-EEXIST, don't try to register things with "
2596 - "the same name in the same directory.\n",
2597 - __func__, kobject_name(kobj));
2598 + pr_err("%s failed for %s with -EEXIST, don't try to register things with the same name in the same directory.\n",
2599 + __func__, kobject_name(kobj));
2600 else
2601 - WARN(1, "%s failed for %s (error: %d parent: %s)\n",
2602 - __func__, kobject_name(kobj), error,
2603 - parent ? kobject_name(parent) : "'none'");
2604 + pr_err("%s failed for %s (error: %d parent: %s)\n",
2605 + __func__, kobject_name(kobj), error,
2606 + parent ? kobject_name(parent) : "'none'");
2607 } else
2608 kobj->state_in_sysfs = 1;
2609
2610 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
2611 index ad93342c90d7..5c4e85296cf6 100644
2612 --- a/net/ceph/messenger.c
2613 +++ b/net/ceph/messenger.c
2614 @@ -2530,6 +2530,11 @@ static int try_write(struct ceph_connection *con)
2615 int ret = 1;
2616
2617 dout("try_write start %p state %lu\n", con, con->state);
2618 + if (con->state != CON_STATE_PREOPEN &&
2619 + con->state != CON_STATE_CONNECTING &&
2620 + con->state != CON_STATE_NEGOTIATING &&
2621 + con->state != CON_STATE_OPEN)
2622 + return 0;
2623
2624 more:
2625 dout("try_write out_kvec_bytes %d\n", con->out_kvec_bytes);
2626 @@ -2555,6 +2560,8 @@ static int try_write(struct ceph_connection *con)
2627 }
2628
2629 more_kvec:
2630 + BUG_ON(!con->sock);
2631 +
2632 /* kvec data queued? */
2633 if (con->out_kvec_left) {
2634 ret = write_partial_kvec(con);
2635 diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c
2636 index 9ae1bab8c05d..f14498a7eaec 100644
2637 --- a/net/ceph/mon_client.c
2638 +++ b/net/ceph/mon_client.c
2639 @@ -209,6 +209,14 @@ static void reopen_session(struct ceph_mon_client *monc)
2640 __open_session(monc);
2641 }
2642
2643 +static void un_backoff(struct ceph_mon_client *monc)
2644 +{
2645 + monc->hunt_mult /= 2; /* reduce by 50% */
2646 + if (monc->hunt_mult < 1)
2647 + monc->hunt_mult = 1;
2648 + dout("%s hunt_mult now %d\n", __func__, monc->hunt_mult);
2649 +}
2650 +
2651 /*
2652 * Reschedule delayed work timer.
2653 */
2654 @@ -963,6 +971,7 @@ static void delayed_work(struct work_struct *work)
2655 if (!monc->hunting) {
2656 ceph_con_keepalive(&monc->con);
2657 __validate_auth(monc);
2658 + un_backoff(monc);
2659 }
2660
2661 if (is_auth &&
2662 @@ -1123,9 +1132,8 @@ static void finish_hunting(struct ceph_mon_client *monc)
2663 dout("%s found mon%d\n", __func__, monc->cur_mon);
2664 monc->hunting = false;
2665 monc->had_a_connection = true;
2666 - monc->hunt_mult /= 2; /* reduce by 50% */
2667 - if (monc->hunt_mult < 1)
2668 - monc->hunt_mult = 1;
2669 + un_backoff(monc);
2670 + __schedule_delayed(monc);
2671 }
2672 }
2673
2674 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
2675 index b719d0bd833e..06d7c40af570 100644
2676 --- a/sound/core/pcm_compat.c
2677 +++ b/sound/core/pcm_compat.c
2678 @@ -27,10 +27,11 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
2679 s32 __user *src)
2680 {
2681 snd_pcm_sframes_t delay;
2682 + int err;
2683
2684 - delay = snd_pcm_delay(substream);
2685 - if (delay < 0)
2686 - return delay;
2687 + err = snd_pcm_delay(substream, &delay);
2688 + if (err)
2689 + return err;
2690 if (put_user(delay, src))
2691 return -EFAULT;
2692 return 0;
2693 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
2694 index eba2bedcbc81..ab3bf36786b6 100644
2695 --- a/sound/core/pcm_native.c
2696 +++ b/sound/core/pcm_native.c
2697 @@ -2689,7 +2689,8 @@ static int snd_pcm_hwsync(struct snd_pcm_substream *substream)
2698 return err;
2699 }
2700
2701 -static snd_pcm_sframes_t snd_pcm_delay(struct snd_pcm_substream *substream)
2702 +static int snd_pcm_delay(struct snd_pcm_substream *substream,
2703 + snd_pcm_sframes_t *delay)
2704 {
2705 struct snd_pcm_runtime *runtime = substream->runtime;
2706 int err;
2707 @@ -2705,7 +2706,9 @@ static snd_pcm_sframes_t snd_pcm_delay(struct snd_pcm_substream *substream)
2708 n += runtime->delay;
2709 }
2710 snd_pcm_stream_unlock_irq(substream);
2711 - return err < 0 ? err : n;
2712 + if (!err)
2713 + *delay = n;
2714 + return err;
2715 }
2716
2717 static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream,
2718 @@ -2748,6 +2751,7 @@ static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream,
2719 sync_ptr.s.status.hw_ptr = status->hw_ptr;
2720 sync_ptr.s.status.tstamp = status->tstamp;
2721 sync_ptr.s.status.suspended_state = status->suspended_state;
2722 + sync_ptr.s.status.audio_tstamp = status->audio_tstamp;
2723 snd_pcm_stream_unlock_irq(substream);
2724 if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr)))
2725 return -EFAULT;
2726 @@ -2913,11 +2917,13 @@ static int snd_pcm_common_ioctl(struct file *file,
2727 return snd_pcm_hwsync(substream);
2728 case SNDRV_PCM_IOCTL_DELAY:
2729 {
2730 - snd_pcm_sframes_t delay = snd_pcm_delay(substream);
2731 + snd_pcm_sframes_t delay;
2732 snd_pcm_sframes_t __user *res = arg;
2733 + int err;
2734
2735 - if (delay < 0)
2736 - return delay;
2737 + err = snd_pcm_delay(substream, &delay);
2738 + if (err)
2739 + return err;
2740 if (put_user(delay, res))
2741 return -EFAULT;
2742 return 0;
2743 @@ -3005,13 +3011,7 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
2744 case SNDRV_PCM_IOCTL_DROP:
2745 return snd_pcm_drop(substream);
2746 case SNDRV_PCM_IOCTL_DELAY:
2747 - {
2748 - result = snd_pcm_delay(substream);
2749 - if (result < 0)
2750 - return result;
2751 - *frames = result;
2752 - return 0;
2753 - }
2754 + return snd_pcm_delay(substream, frames);
2755 default:
2756 return -EINVAL;
2757 }
2758 diff --git a/sound/core/seq/oss/seq_oss_event.c b/sound/core/seq/oss/seq_oss_event.c
2759 index c3908862bc8b..86ca584c27b2 100644
2760 --- a/sound/core/seq/oss/seq_oss_event.c
2761 +++ b/sound/core/seq/oss/seq_oss_event.c
2762 @@ -26,6 +26,7 @@
2763 #include <sound/seq_oss_legacy.h>
2764 #include "seq_oss_readq.h"
2765 #include "seq_oss_writeq.h"
2766 +#include <linux/nospec.h>
2767
2768
2769 /*
2770 @@ -287,10 +288,10 @@ note_on_event(struct seq_oss_devinfo *dp, int dev, int ch, int note, int vel, st
2771 {
2772 struct seq_oss_synthinfo *info;
2773
2774 - if (!snd_seq_oss_synth_is_valid(dp, dev))
2775 + info = snd_seq_oss_synth_info(dp, dev);
2776 + if (!info)
2777 return -ENXIO;
2778
2779 - info = &dp->synths[dev];
2780 switch (info->arg.event_passing) {
2781 case SNDRV_SEQ_OSS_PROCESS_EVENTS:
2782 if (! info->ch || ch < 0 || ch >= info->nr_voices) {
2783 @@ -298,6 +299,7 @@ note_on_event(struct seq_oss_devinfo *dp, int dev, int ch, int note, int vel, st
2784 return set_note_event(dp, dev, SNDRV_SEQ_EVENT_NOTEON, ch, note, vel, ev);
2785 }
2786
2787 + ch = array_index_nospec(ch, info->nr_voices);
2788 if (note == 255 && info->ch[ch].note >= 0) {
2789 /* volume control */
2790 int type;
2791 @@ -347,10 +349,10 @@ note_off_event(struct seq_oss_devinfo *dp, int dev, int ch, int note, int vel, s
2792 {
2793 struct seq_oss_synthinfo *info;
2794
2795 - if (!snd_seq_oss_synth_is_valid(dp, dev))
2796 + info = snd_seq_oss_synth_info(dp, dev);
2797 + if (!info)
2798 return -ENXIO;
2799
2800 - info = &dp->synths[dev];
2801 switch (info->arg.event_passing) {
2802 case SNDRV_SEQ_OSS_PROCESS_EVENTS:
2803 if (! info->ch || ch < 0 || ch >= info->nr_voices) {
2804 @@ -358,6 +360,7 @@ note_off_event(struct seq_oss_devinfo *dp, int dev, int ch, int note, int vel, s
2805 return set_note_event(dp, dev, SNDRV_SEQ_EVENT_NOTEON, ch, note, vel, ev);
2806 }
2807
2808 + ch = array_index_nospec(ch, info->nr_voices);
2809 if (info->ch[ch].note >= 0) {
2810 note = info->ch[ch].note;
2811 info->ch[ch].vel = 0;
2812 @@ -381,7 +384,7 @@ note_off_event(struct seq_oss_devinfo *dp, int dev, int ch, int note, int vel, s
2813 static int
2814 set_note_event(struct seq_oss_devinfo *dp, int dev, int type, int ch, int note, int vel, struct snd_seq_event *ev)
2815 {
2816 - if (! snd_seq_oss_synth_is_valid(dp, dev))
2817 + if (!snd_seq_oss_synth_info(dp, dev))
2818 return -ENXIO;
2819
2820 ev->type = type;
2821 @@ -399,7 +402,7 @@ set_note_event(struct seq_oss_devinfo *dp, int dev, int type, int ch, int note,
2822 static int
2823 set_control_event(struct seq_oss_devinfo *dp, int dev, int type, int ch, int param, int val, struct snd_seq_event *ev)
2824 {
2825 - if (! snd_seq_oss_synth_is_valid(dp, dev))
2826 + if (!snd_seq_oss_synth_info(dp, dev))
2827 return -ENXIO;
2828
2829 ev->type = type;
2830 diff --git a/sound/core/seq/oss/seq_oss_midi.c b/sound/core/seq/oss/seq_oss_midi.c
2831 index b30b2139e3f0..9debd1b8fd28 100644
2832 --- a/sound/core/seq/oss/seq_oss_midi.c
2833 +++ b/sound/core/seq/oss/seq_oss_midi.c
2834 @@ -29,6 +29,7 @@
2835 #include "../seq_lock.h"
2836 #include <linux/init.h>
2837 #include <linux/slab.h>
2838 +#include <linux/nospec.h>
2839
2840
2841 /*
2842 @@ -315,6 +316,7 @@ get_mididev(struct seq_oss_devinfo *dp, int dev)
2843 {
2844 if (dev < 0 || dev >= dp->max_mididev)
2845 return NULL;
2846 + dev = array_index_nospec(dev, dp->max_mididev);
2847 return get_mdev(dev);
2848 }
2849
2850 diff --git a/sound/core/seq/oss/seq_oss_synth.c b/sound/core/seq/oss/seq_oss_synth.c
2851 index cd0e0ebbfdb1..278ebb993122 100644
2852 --- a/sound/core/seq/oss/seq_oss_synth.c
2853 +++ b/sound/core/seq/oss/seq_oss_synth.c
2854 @@ -26,6 +26,7 @@
2855 #include <linux/init.h>
2856 #include <linux/module.h>
2857 #include <linux/slab.h>
2858 +#include <linux/nospec.h>
2859
2860 /*
2861 * constants
2862 @@ -339,17 +340,13 @@ snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp)
2863 dp->max_synthdev = 0;
2864 }
2865
2866 -/*
2867 - * check if the specified device is MIDI mapped device
2868 - */
2869 -static int
2870 -is_midi_dev(struct seq_oss_devinfo *dp, int dev)
2871 +static struct seq_oss_synthinfo *
2872 +get_synthinfo_nospec(struct seq_oss_devinfo *dp, int dev)
2873 {
2874 if (dev < 0 || dev >= dp->max_synthdev)
2875 - return 0;
2876 - if (dp->synths[dev].is_midi)
2877 - return 1;
2878 - return 0;
2879 + return NULL;
2880 + dev = array_index_nospec(dev, SNDRV_SEQ_OSS_MAX_SYNTH_DEVS);
2881 + return &dp->synths[dev];
2882 }
2883
2884 /*
2885 @@ -359,14 +356,20 @@ static struct seq_oss_synth *
2886 get_synthdev(struct seq_oss_devinfo *dp, int dev)
2887 {
2888 struct seq_oss_synth *rec;
2889 - if (dev < 0 || dev >= dp->max_synthdev)
2890 - return NULL;
2891 - if (! dp->synths[dev].opened)
2892 + struct seq_oss_synthinfo *info = get_synthinfo_nospec(dp, dev);
2893 +
2894 + if (!info)
2895 return NULL;
2896 - if (dp->synths[dev].is_midi)
2897 - return &midi_synth_dev;
2898 - if ((rec = get_sdev(dev)) == NULL)
2899 + if (!info->opened)
2900 return NULL;
2901 + if (info->is_midi) {
2902 + rec = &midi_synth_dev;
2903 + snd_use_lock_use(&rec->use_lock);
2904 + } else {
2905 + rec = get_sdev(dev);
2906 + if (!rec)
2907 + return NULL;
2908 + }
2909 if (! rec->opened) {
2910 snd_use_lock_free(&rec->use_lock);
2911 return NULL;
2912 @@ -402,10 +405,8 @@ snd_seq_oss_synth_reset(struct seq_oss_devinfo *dp, int dev)
2913 struct seq_oss_synth *rec;
2914 struct seq_oss_synthinfo *info;
2915
2916 - if (snd_BUG_ON(dev < 0 || dev >= dp->max_synthdev))
2917 - return;
2918 - info = &dp->synths[dev];
2919 - if (! info->opened)
2920 + info = get_synthinfo_nospec(dp, dev);
2921 + if (!info || !info->opened)
2922 return;
2923 if (info->sysex)
2924 info->sysex->len = 0; /* reset sysex */
2925 @@ -454,12 +455,14 @@ snd_seq_oss_synth_load_patch(struct seq_oss_devinfo *dp, int dev, int fmt,
2926 const char __user *buf, int p, int c)
2927 {
2928 struct seq_oss_synth *rec;
2929 + struct seq_oss_synthinfo *info;
2930 int rc;
2931
2932 - if (dev < 0 || dev >= dp->max_synthdev)
2933 + info = get_synthinfo_nospec(dp, dev);
2934 + if (!info)
2935 return -ENXIO;
2936
2937 - if (is_midi_dev(dp, dev))
2938 + if (info->is_midi)
2939 return 0;
2940 if ((rec = get_synthdev(dp, dev)) == NULL)
2941 return -ENXIO;
2942 @@ -467,24 +470,25 @@ snd_seq_oss_synth_load_patch(struct seq_oss_devinfo *dp, int dev, int fmt,
2943 if (rec->oper.load_patch == NULL)
2944 rc = -ENXIO;
2945 else
2946 - rc = rec->oper.load_patch(&dp->synths[dev].arg, fmt, buf, p, c);
2947 + rc = rec->oper.load_patch(&info->arg, fmt, buf, p, c);
2948 snd_use_lock_free(&rec->use_lock);
2949 return rc;
2950 }
2951
2952 /*
2953 - * check if the device is valid synth device
2954 + * check if the device is valid synth device and return the synth info
2955 */
2956 -int
2957 -snd_seq_oss_synth_is_valid(struct seq_oss_devinfo *dp, int dev)
2958 +struct seq_oss_synthinfo *
2959 +snd_seq_oss_synth_info(struct seq_oss_devinfo *dp, int dev)
2960 {
2961 struct seq_oss_synth *rec;
2962 +
2963 rec = get_synthdev(dp, dev);
2964 if (rec) {
2965 snd_use_lock_free(&rec->use_lock);
2966 - return 1;
2967 + return get_synthinfo_nospec(dp, dev);
2968 }
2969 - return 0;
2970 + return NULL;
2971 }
2972
2973
2974 @@ -499,16 +503,18 @@ snd_seq_oss_synth_sysex(struct seq_oss_devinfo *dp, int dev, unsigned char *buf,
2975 int i, send;
2976 unsigned char *dest;
2977 struct seq_oss_synth_sysex *sysex;
2978 + struct seq_oss_synthinfo *info;
2979
2980 - if (! snd_seq_oss_synth_is_valid(dp, dev))
2981 + info = snd_seq_oss_synth_info(dp, dev);
2982 + if (!info)
2983 return -ENXIO;
2984
2985 - sysex = dp->synths[dev].sysex;
2986 + sysex = info->sysex;
2987 if (sysex == NULL) {
2988 sysex = kzalloc(sizeof(*sysex), GFP_KERNEL);
2989 if (sysex == NULL)
2990 return -ENOMEM;
2991 - dp->synths[dev].sysex = sysex;
2992 + info->sysex = sysex;
2993 }
2994
2995 send = 0;
2996 @@ -553,10 +559,12 @@ snd_seq_oss_synth_sysex(struct seq_oss_devinfo *dp, int dev, unsigned char *buf,
2997 int
2998 snd_seq_oss_synth_addr(struct seq_oss_devinfo *dp, int dev, struct snd_seq_event *ev)
2999 {
3000 - if (! snd_seq_oss_synth_is_valid(dp, dev))
3001 + struct seq_oss_synthinfo *info = snd_seq_oss_synth_info(dp, dev);
3002 +
3003 + if (!info)
3004 return -EINVAL;
3005 - snd_seq_oss_fill_addr(dp, ev, dp->synths[dev].arg.addr.client,
3006 - dp->synths[dev].arg.addr.port);
3007 + snd_seq_oss_fill_addr(dp, ev, info->arg.addr.client,
3008 + info->arg.addr.port);
3009 return 0;
3010 }
3011
3012 @@ -568,16 +576,18 @@ int
3013 snd_seq_oss_synth_ioctl(struct seq_oss_devinfo *dp, int dev, unsigned int cmd, unsigned long addr)
3014 {
3015 struct seq_oss_synth *rec;
3016 + struct seq_oss_synthinfo *info;
3017 int rc;
3018
3019 - if (is_midi_dev(dp, dev))
3020 + info = get_synthinfo_nospec(dp, dev);
3021 + if (!info || info->is_midi)
3022 return -ENXIO;
3023 if ((rec = get_synthdev(dp, dev)) == NULL)
3024 return -ENXIO;
3025 if (rec->oper.ioctl == NULL)
3026 rc = -ENXIO;
3027 else
3028 - rc = rec->oper.ioctl(&dp->synths[dev].arg, cmd, addr);
3029 + rc = rec->oper.ioctl(&info->arg, cmd, addr);
3030 snd_use_lock_free(&rec->use_lock);
3031 return rc;
3032 }
3033 @@ -589,7 +599,10 @@ snd_seq_oss_synth_ioctl(struct seq_oss_devinfo *dp, int dev, unsigned int cmd, u
3034 int
3035 snd_seq_oss_synth_raw_event(struct seq_oss_devinfo *dp, int dev, unsigned char *data, struct snd_seq_event *ev)
3036 {
3037 - if (! snd_seq_oss_synth_is_valid(dp, dev) || is_midi_dev(dp, dev))
3038 + struct seq_oss_synthinfo *info;
3039 +
3040 + info = snd_seq_oss_synth_info(dp, dev);
3041 + if (!info || info->is_midi)
3042 return -ENXIO;
3043 ev->type = SNDRV_SEQ_EVENT_OSS;
3044 memcpy(ev->data.raw8.d, data, 8);
3045 diff --git a/sound/core/seq/oss/seq_oss_synth.h b/sound/core/seq/oss/seq_oss_synth.h
3046 index 74ac55f166b6..a63f9e22974d 100644
3047 --- a/sound/core/seq/oss/seq_oss_synth.h
3048 +++ b/sound/core/seq/oss/seq_oss_synth.h
3049 @@ -37,7 +37,8 @@ void snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp);
3050 void snd_seq_oss_synth_reset(struct seq_oss_devinfo *dp, int dev);
3051 int snd_seq_oss_synth_load_patch(struct seq_oss_devinfo *dp, int dev, int fmt,
3052 const char __user *buf, int p, int c);
3053 -int snd_seq_oss_synth_is_valid(struct seq_oss_devinfo *dp, int dev);
3054 +struct seq_oss_synthinfo *snd_seq_oss_synth_info(struct seq_oss_devinfo *dp,
3055 + int dev);
3056 int snd_seq_oss_synth_sysex(struct seq_oss_devinfo *dp, int dev, unsigned char *buf,
3057 struct snd_seq_event *ev);
3058 int snd_seq_oss_synth_addr(struct seq_oss_devinfo *dp, int dev, struct snd_seq_event *ev);
3059 diff --git a/sound/drivers/opl3/opl3_synth.c b/sound/drivers/opl3/opl3_synth.c
3060 index ddcc1a325a61..42920a243328 100644
3061 --- a/sound/drivers/opl3/opl3_synth.c
3062 +++ b/sound/drivers/opl3/opl3_synth.c
3063 @@ -21,6 +21,7 @@
3064
3065 #include <linux/slab.h>
3066 #include <linux/export.h>
3067 +#include <linux/nospec.h>
3068 #include <sound/opl3.h>
3069 #include <sound/asound_fm.h>
3070
3071 @@ -448,7 +449,7 @@ static int snd_opl3_set_voice(struct snd_opl3 * opl3, struct snd_dm_fm_voice * v
3072 {
3073 unsigned short reg_side;
3074 unsigned char op_offset;
3075 - unsigned char voice_offset;
3076 + unsigned char voice_offset, voice_op;
3077
3078 unsigned short opl3_reg;
3079 unsigned char reg_val;
3080 @@ -473,7 +474,9 @@ static int snd_opl3_set_voice(struct snd_opl3 * opl3, struct snd_dm_fm_voice * v
3081 voice_offset = voice->voice - MAX_OPL2_VOICES;
3082 }
3083 /* Get register offset of operator */
3084 - op_offset = snd_opl3_regmap[voice_offset][voice->op];
3085 + voice_offset = array_index_nospec(voice_offset, MAX_OPL2_VOICES);
3086 + voice_op = array_index_nospec(voice->op, 4);
3087 + op_offset = snd_opl3_regmap[voice_offset][voice_op];
3088
3089 reg_val = 0x00;
3090 /* Set amplitude modulation (tremolo) effect */
3091 diff --git a/sound/firewire/dice/dice-stream.c b/sound/firewire/dice/dice-stream.c
3092 index 8573289c381e..928a255bfc35 100644
3093 --- a/sound/firewire/dice/dice-stream.c
3094 +++ b/sound/firewire/dice/dice-stream.c
3095 @@ -435,7 +435,7 @@ int snd_dice_stream_init_duplex(struct snd_dice *dice)
3096 err = init_stream(dice, AMDTP_IN_STREAM, i);
3097 if (err < 0) {
3098 for (; i >= 0; i--)
3099 - destroy_stream(dice, AMDTP_OUT_STREAM, i);
3100 + destroy_stream(dice, AMDTP_IN_STREAM, i);
3101 goto end;
3102 }
3103 }
3104 diff --git a/sound/firewire/dice/dice.c b/sound/firewire/dice/dice.c
3105 index 4ddb4cdd054b..96bb01b6b751 100644
3106 --- a/sound/firewire/dice/dice.c
3107 +++ b/sound/firewire/dice/dice.c
3108 @@ -14,7 +14,7 @@ MODULE_LICENSE("GPL v2");
3109 #define OUI_WEISS 0x001c6a
3110 #define OUI_LOUD 0x000ff2
3111 #define OUI_FOCUSRITE 0x00130e
3112 -#define OUI_TCELECTRONIC 0x001486
3113 +#define OUI_TCELECTRONIC 0x000166
3114
3115 #define DICE_CATEGORY_ID 0x04
3116 #define WEISS_CATEGORY_ID 0x00
3117 diff --git a/sound/pci/asihpi/hpimsginit.c b/sound/pci/asihpi/hpimsginit.c
3118 index 7eb617175fde..a31a70dccecf 100644
3119 --- a/sound/pci/asihpi/hpimsginit.c
3120 +++ b/sound/pci/asihpi/hpimsginit.c
3121 @@ -23,6 +23,7 @@
3122
3123 #include "hpi_internal.h"
3124 #include "hpimsginit.h"
3125 +#include <linux/nospec.h>
3126
3127 /* The actual message size for each object type */
3128 static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT;
3129 @@ -39,10 +40,12 @@ static void hpi_init_message(struct hpi_message *phm, u16 object,
3130 {
3131 u16 size;
3132
3133 - if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
3134 + if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
3135 + object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
3136 size = msg_size[object];
3137 - else
3138 + } else {
3139 size = sizeof(*phm);
3140 + }
3141
3142 memset(phm, 0, size);
3143 phm->size = size;
3144 @@ -66,10 +69,12 @@ void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
3145 {
3146 u16 size;
3147
3148 - if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
3149 + if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
3150 + object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
3151 size = res_size[object];
3152 - else
3153 + } else {
3154 size = sizeof(*phr);
3155 + }
3156
3157 memset(phr, 0, sizeof(*phr));
3158 phr->size = size;
3159 diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c
3160 index 5badd08e1d69..b1a2a7ea4172 100644
3161 --- a/sound/pci/asihpi/hpioctl.c
3162 +++ b/sound/pci/asihpi/hpioctl.c
3163 @@ -33,6 +33,7 @@
3164 #include <linux/stringify.h>
3165 #include <linux/module.h>
3166 #include <linux/vmalloc.h>
3167 +#include <linux/nospec.h>
3168
3169 #ifdef MODULE_FIRMWARE
3170 MODULE_FIRMWARE("asihpi/dsp5000.bin");
3171 @@ -186,7 +187,8 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3172 struct hpi_adapter *pa = NULL;
3173
3174 if (hm->h.adapter_index < ARRAY_SIZE(adapters))
3175 - pa = &adapters[hm->h.adapter_index];
3176 + pa = &adapters[array_index_nospec(hm->h.adapter_index,
3177 + ARRAY_SIZE(adapters))];
3178
3179 if (!pa || !pa->adapter || !pa->adapter->type) {
3180 hpi_init_response(&hr->r0, hm->h.object,
3181 diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
3182 index 57df06e76968..cc009a4a3d1d 100644
3183 --- a/sound/pci/hda/hda_hwdep.c
3184 +++ b/sound/pci/hda/hda_hwdep.c
3185 @@ -21,6 +21,7 @@
3186 #include <linux/init.h>
3187 #include <linux/slab.h>
3188 #include <linux/compat.h>
3189 +#include <linux/nospec.h>
3190 #include <sound/core.h>
3191 #include "hda_codec.h"
3192 #include "hda_local.h"
3193 @@ -51,7 +52,16 @@ static int get_wcap_ioctl(struct hda_codec *codec,
3194
3195 if (get_user(verb, &arg->verb))
3196 return -EFAULT;
3197 - res = get_wcaps(codec, verb >> 24);
3198 + /* open-code get_wcaps(verb>>24) with nospec */
3199 + verb >>= 24;
3200 + if (verb < codec->core.start_nid ||
3201 + verb >= codec->core.start_nid + codec->core.num_nodes) {
3202 + res = 0;
3203 + } else {
3204 + verb -= codec->core.start_nid;
3205 + verb = array_index_nospec(verb, codec->core.num_nodes);
3206 + res = codec->wcaps[verb];
3207 + }
3208 if (put_user(res, &arg->res))
3209 return -EFAULT;
3210 return 0;
3211 diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
3212 index b4f1b6e88305..7d7eb1354eee 100644
3213 --- a/sound/pci/hda/patch_hdmi.c
3214 +++ b/sound/pci/hda/patch_hdmi.c
3215 @@ -1383,6 +1383,8 @@ static void hdmi_pcm_setup_pin(struct hdmi_spec *spec,
3216 pcm = get_pcm_rec(spec, per_pin->pcm_idx);
3217 else
3218 return;
3219 + if (!pcm->pcm)
3220 + return;
3221 if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use))
3222 return;
3223
3224 @@ -2151,8 +2153,13 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
3225 int dev, err;
3226 int pin_idx, pcm_idx;
3227
3228 -
3229 for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
3230 + if (!get_pcm_rec(spec, pcm_idx)->pcm) {
3231 + /* no PCM: mark this for skipping permanently */
3232 + set_bit(pcm_idx, &spec->pcm_bitmap);
3233 + continue;
3234 + }
3235 +
3236 err = generic_hdmi_build_jack(codec, pcm_idx);
3237 if (err < 0)
3238 return err;
3239 diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
3240 index 590887d9b7a1..59daf9901466 100644
3241 --- a/sound/pci/hda/patch_realtek.c
3242 +++ b/sound/pci/hda/patch_realtek.c
3243 @@ -331,6 +331,7 @@ static void alc_fill_eapd_coef(struct hda_codec *codec)
3244 /* fallthrough */
3245 case 0x10ec0215:
3246 case 0x10ec0233:
3247 + case 0x10ec0235:
3248 case 0x10ec0236:
3249 case 0x10ec0255:
3250 case 0x10ec0256:
3251 @@ -6435,6 +6436,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
3252 SND_PCI_QUIRK(0x17aa, 0x30bb, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
3253 SND_PCI_QUIRK(0x17aa, 0x30e2, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
3254 SND_PCI_QUIRK(0x17aa, 0x310c, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
3255 + SND_PCI_QUIRK(0x17aa, 0x312f, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
3256 SND_PCI_QUIRK(0x17aa, 0x3138, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
3257 SND_PCI_QUIRK(0x17aa, 0x313c, "ThinkCentre Station", ALC294_FIXUP_LENOVO_MIC_LOCATION),
3258 SND_PCI_QUIRK(0x17aa, 0x3112, "ThinkCentre AIO", ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
3259 @@ -7015,8 +7017,11 @@ static int patch_alc269(struct hda_codec *codec)
3260 case 0x10ec0298:
3261 spec->codec_variant = ALC269_TYPE_ALC298;
3262 break;
3263 + case 0x10ec0235:
3264 case 0x10ec0255:
3265 spec->codec_variant = ALC269_TYPE_ALC255;
3266 + spec->shutup = alc256_shutup;
3267 + spec->init_hook = alc256_init;
3268 break;
3269 case 0x10ec0236:
3270 case 0x10ec0256:
3271 diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
3272 index f20d42714e4d..343f533906ba 100644
3273 --- a/sound/pci/rme9652/hdspm.c
3274 +++ b/sound/pci/rme9652/hdspm.c
3275 @@ -137,6 +137,7 @@
3276 #include <linux/pci.h>
3277 #include <linux/math64.h>
3278 #include <linux/io.h>
3279 +#include <linux/nospec.h>
3280
3281 #include <sound/core.h>
3282 #include <sound/control.h>
3283 @@ -5698,40 +5699,43 @@ static int snd_hdspm_channel_info(struct snd_pcm_substream *substream,
3284 struct snd_pcm_channel_info *info)
3285 {
3286 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3287 + unsigned int channel = info->channel;
3288
3289 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3290 - if (snd_BUG_ON(info->channel >= hdspm->max_channels_out)) {
3291 + if (snd_BUG_ON(channel >= hdspm->max_channels_out)) {
3292 dev_info(hdspm->card->dev,
3293 "snd_hdspm_channel_info: output channel out of range (%d)\n",
3294 - info->channel);
3295 + channel);
3296 return -EINVAL;
3297 }
3298
3299 - if (hdspm->channel_map_out[info->channel] < 0) {
3300 + channel = array_index_nospec(channel, hdspm->max_channels_out);
3301 + if (hdspm->channel_map_out[channel] < 0) {
3302 dev_info(hdspm->card->dev,
3303 "snd_hdspm_channel_info: output channel %d mapped out\n",
3304 - info->channel);
3305 + channel);
3306 return -EINVAL;
3307 }
3308
3309 - info->offset = hdspm->channel_map_out[info->channel] *
3310 + info->offset = hdspm->channel_map_out[channel] *
3311 HDSPM_CHANNEL_BUFFER_BYTES;
3312 } else {
3313 - if (snd_BUG_ON(info->channel >= hdspm->max_channels_in)) {
3314 + if (snd_BUG_ON(channel >= hdspm->max_channels_in)) {
3315 dev_info(hdspm->card->dev,
3316 "snd_hdspm_channel_info: input channel out of range (%d)\n",
3317 - info->channel);
3318 + channel);
3319 return -EINVAL;
3320 }
3321
3322 - if (hdspm->channel_map_in[info->channel] < 0) {
3323 + channel = array_index_nospec(channel, hdspm->max_channels_in);
3324 + if (hdspm->channel_map_in[channel] < 0) {
3325 dev_info(hdspm->card->dev,
3326 "snd_hdspm_channel_info: input channel %d mapped out\n",
3327 - info->channel);
3328 + channel);
3329 return -EINVAL;
3330 }
3331
3332 - info->offset = hdspm->channel_map_in[info->channel] *
3333 + info->offset = hdspm->channel_map_in[channel] *
3334 HDSPM_CHANNEL_BUFFER_BYTES;
3335 }
3336
3337 diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
3338 index df648b1d9217..edd765e22377 100644
3339 --- a/sound/pci/rme9652/rme9652.c
3340 +++ b/sound/pci/rme9652/rme9652.c
3341 @@ -26,6 +26,7 @@
3342 #include <linux/pci.h>
3343 #include <linux/module.h>
3344 #include <linux/io.h>
3345 +#include <linux/nospec.h>
3346
3347 #include <sound/core.h>
3348 #include <sound/control.h>
3349 @@ -2071,9 +2072,10 @@ static int snd_rme9652_channel_info(struct snd_pcm_substream *substream,
3350 if (snd_BUG_ON(info->channel >= RME9652_NCHANNELS))
3351 return -EINVAL;
3352
3353 - if ((chn = rme9652->channel_map[info->channel]) < 0) {
3354 + chn = rme9652->channel_map[array_index_nospec(info->channel,
3355 + RME9652_NCHANNELS)];
3356 + if (chn < 0)
3357 return -EINVAL;
3358 - }
3359
3360 info->offset = chn * RME9652_CHANNEL_BUFFER_BYTES;
3361 info->first = 0;
3362 diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c
3363 index cef79a1a620b..81268760b7a9 100644
3364 --- a/sound/soc/fsl/fsl_esai.c
3365 +++ b/sound/soc/fsl/fsl_esai.c
3366 @@ -144,6 +144,13 @@ static int fsl_esai_divisor_cal(struct snd_soc_dai *dai, bool tx, u32 ratio,
3367
3368 psr = ratio <= 256 * maxfp ? ESAI_xCCR_xPSR_BYPASS : ESAI_xCCR_xPSR_DIV8;
3369
3370 + /* Do not loop-search if PM (1 ~ 256) alone can serve the ratio */
3371 + if (ratio <= 256) {
3372 + pm = ratio;
3373 + fp = 1;
3374 + goto out;
3375 + }
3376 +
3377 /* Set the max fluctuation -- 0.1% of the max devisor */
3378 savesub = (psr ? 1 : 8) * 256 * maxfp / 1000;
3379
3380 diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c
3381 index 9038b2e7df73..eaa03acd4686 100644
3382 --- a/sound/usb/mixer_maps.c
3383 +++ b/sound/usb/mixer_maps.c
3384 @@ -353,8 +353,11 @@ static struct usbmix_name_map bose_companion5_map[] = {
3385 /*
3386 * Dell usb dock with ALC4020 codec had a firmware problem where it got
3387 * screwed up when zero volume is passed; just skip it as a workaround
3388 + *
3389 + * Also the extension unit gives an access error, so skip it as well.
3390 */
3391 static const struct usbmix_name_map dell_alc4020_map[] = {
3392 + { 4, NULL }, /* extension unit */
3393 { 16, NULL },
3394 { 19, NULL },
3395 { 0 }
3396 diff --git a/tools/lib/str_error_r.c b/tools/lib/str_error_r.c
3397 index d6d65537b0d9..6aad8308a0ac 100644
3398 --- a/tools/lib/str_error_r.c
3399 +++ b/tools/lib/str_error_r.c
3400 @@ -22,6 +22,6 @@ char *str_error_r(int errnum, char *buf, size_t buflen)
3401 {
3402 int err = strerror_r(errnum, buf, buflen);
3403 if (err)
3404 - snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
3405 + snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, [buf], %zd)=%d", errnum, buflen, err);
3406 return buf;
3407 }
3408 diff --git a/tools/lib/subcmd/pager.c b/tools/lib/subcmd/pager.c
3409 index 5ba754d17952..9997a8805a82 100644
3410 --- a/tools/lib/subcmd/pager.c
3411 +++ b/tools/lib/subcmd/pager.c
3412 @@ -30,10 +30,13 @@ static void pager_preexec(void)
3413 * have real input
3414 */
3415 fd_set in;
3416 + fd_set exception;
3417
3418 FD_ZERO(&in);
3419 + FD_ZERO(&exception);
3420 FD_SET(0, &in);
3421 - select(1, &in, NULL, &in, NULL);
3422 + FD_SET(0, &exception);
3423 + select(1, &in, NULL, &exception, NULL);
3424
3425 setenv("LESS", "FRSX", 0);
3426 }
3427 diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
3428 index 1366462a3ab2..9bee849db682 100644
3429 --- a/virt/kvm/arm/arm.c
3430 +++ b/virt/kvm/arm/arm.c
3431 @@ -61,7 +61,7 @@ static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3432 static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3433 static u32 kvm_next_vmid;
3434 static unsigned int kvm_vmid_bits __read_mostly;
3435 -static DEFINE_SPINLOCK(kvm_vmid_lock);
3436 +static DEFINE_RWLOCK(kvm_vmid_lock);
3437
3438 static bool vgic_present;
3439
3440 @@ -462,11 +462,16 @@ static void update_vttbr(struct kvm *kvm)
3441 {
3442 phys_addr_t pgd_phys;
3443 u64 vmid;
3444 + bool new_gen;
3445
3446 - if (!need_new_vmid_gen(kvm))
3447 + read_lock(&kvm_vmid_lock);
3448 + new_gen = need_new_vmid_gen(kvm);
3449 + read_unlock(&kvm_vmid_lock);
3450 +
3451 + if (!new_gen)
3452 return;
3453
3454 - spin_lock(&kvm_vmid_lock);
3455 + write_lock(&kvm_vmid_lock);
3456
3457 /*
3458 * We need to re-check the vmid_gen here to ensure that if another vcpu
3459 @@ -474,7 +479,7 @@ static void update_vttbr(struct kvm *kvm)
3460 * use the same vmid.
3461 */
3462 if (!need_new_vmid_gen(kvm)) {
3463 - spin_unlock(&kvm_vmid_lock);
3464 + write_unlock(&kvm_vmid_lock);
3465 return;
3466 }
3467
3468 @@ -508,7 +513,7 @@ static void update_vttbr(struct kvm *kvm)
3469 vmid = ((u64)(kvm->arch.vmid) << VTTBR_VMID_SHIFT) & VTTBR_VMID_MASK(kvm_vmid_bits);
3470 kvm->arch.vttbr = pgd_phys | vmid;
3471
3472 - spin_unlock(&kvm_vmid_lock);
3473 + write_unlock(&kvm_vmid_lock);
3474 }
3475
3476 static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)
3477 diff --git a/virt/kvm/arm/psci.c b/virt/kvm/arm/psci.c
3478 index 6919352cbf15..c4762bef13c6 100644
3479 --- a/virt/kvm/arm/psci.c
3480 +++ b/virt/kvm/arm/psci.c
3481 @@ -18,6 +18,7 @@
3482 #include <linux/arm-smccc.h>
3483 #include <linux/preempt.h>
3484 #include <linux/kvm_host.h>
3485 +#include <linux/uaccess.h>
3486 #include <linux/wait.h>
3487
3488 #include <asm/cputype.h>
3489 @@ -427,3 +428,62 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)
3490 smccc_set_retval(vcpu, val, 0, 0, 0);
3491 return 1;
3492 }
3493 +
3494 +int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu)
3495 +{
3496 + return 1; /* PSCI version */
3497 +}
3498 +
3499 +int kvm_arm_copy_fw_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices)
3500 +{
3501 + if (put_user(KVM_REG_ARM_PSCI_VERSION, uindices))
3502 + return -EFAULT;
3503 +
3504 + return 0;
3505 +}
3506 +
3507 +int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
3508 +{
3509 + if (reg->id == KVM_REG_ARM_PSCI_VERSION) {
3510 + void __user *uaddr = (void __user *)(long)reg->addr;
3511 + u64 val;
3512 +
3513 + val = kvm_psci_version(vcpu, vcpu->kvm);
3514 + if (copy_to_user(uaddr, &val, KVM_REG_SIZE(reg->id)))
3515 + return -EFAULT;
3516 +
3517 + return 0;
3518 + }
3519 +
3520 + return -EINVAL;
3521 +}
3522 +
3523 +int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
3524 +{
3525 + if (reg->id == KVM_REG_ARM_PSCI_VERSION) {
3526 + void __user *uaddr = (void __user *)(long)reg->addr;
3527 + bool wants_02;
3528 + u64 val;
3529 +
3530 + if (copy_from_user(&val, uaddr, KVM_REG_SIZE(reg->id)))
3531 + return -EFAULT;
3532 +
3533 + wants_02 = test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features);
3534 +
3535 + switch (val) {
3536 + case KVM_ARM_PSCI_0_1:
3537 + if (wants_02)
3538 + return -EINVAL;
3539 + vcpu->kvm->arch.psci_version = val;
3540 + return 0;
3541 + case KVM_ARM_PSCI_0_2:
3542 + case KVM_ARM_PSCI_1_0:
3543 + if (!wants_02)
3544 + return -EINVAL;
3545 + vcpu->kvm->arch.psci_version = val;
3546 + return 0;
3547 + }
3548 + }
3549 +
3550 + return -EINVAL;
3551 +}