Magellan Linux

Annotation of /trunk/kernel-magellan/patches-4.11/0101-4.11.2-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2931 - (hide annotations) (download)
Fri May 26 08:57:45 2017 UTC (7 years ago) by niro
File size: 168413 byte(s)
-linux-4.11.2
1 niro 2931 diff --git a/Makefile b/Makefile
2     index 9dc2aec1c2e5..d7b64830a7b7 100644
3     --- a/Makefile
4     +++ b/Makefile
5     @@ -1,6 +1,6 @@
6     VERSION = 4
7     PATCHLEVEL = 11
8     -SUBLEVEL = 1
9     +SUBLEVEL = 2
10     EXTRAVERSION =
11     NAME = Fearless Coyote
12    
13     diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c
14     index c2b131527a64..a08d7a93aebb 100644
15     --- a/arch/arm/kvm/psci.c
16     +++ b/arch/arm/kvm/psci.c
17     @@ -208,9 +208,10 @@ int kvm_psci_version(struct kvm_vcpu *vcpu)
18    
19     static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
20     {
21     - int ret = 1;
22     + struct kvm *kvm = vcpu->kvm;
23     unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0);
24     unsigned long val;
25     + int ret = 1;
26    
27     switch (psci_fn) {
28     case PSCI_0_2_FN_PSCI_VERSION:
29     @@ -230,7 +231,9 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
30     break;
31     case PSCI_0_2_FN_CPU_ON:
32     case PSCI_0_2_FN64_CPU_ON:
33     + mutex_lock(&kvm->lock);
34     val = kvm_psci_vcpu_on(vcpu);
35     + mutex_unlock(&kvm->lock);
36     break;
37     case PSCI_0_2_FN_AFFINITY_INFO:
38     case PSCI_0_2_FN64_AFFINITY_INFO:
39     @@ -279,6 +282,7 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
40    
41     static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)
42     {
43     + struct kvm *kvm = vcpu->kvm;
44     unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0);
45     unsigned long val;
46    
47     @@ -288,7 +292,9 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)
48     val = PSCI_RET_SUCCESS;
49     break;
50     case KVM_PSCI_FN_CPU_ON:
51     + mutex_lock(&kvm->lock);
52     val = kvm_psci_vcpu_on(vcpu);
53     + mutex_unlock(&kvm->lock);
54     break;
55     default:
56     val = PSCI_RET_NOT_SUPPORTED;
57     diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
58     index f5ea0ba70f07..fe39e6841326 100644
59     --- a/arch/arm64/include/asm/kvm_emulate.h
60     +++ b/arch/arm64/include/asm/kvm_emulate.h
61     @@ -240,6 +240,12 @@ static inline u8 kvm_vcpu_trap_get_fault_type(const struct kvm_vcpu *vcpu)
62     return kvm_vcpu_get_hsr(vcpu) & ESR_ELx_FSC_TYPE;
63     }
64    
65     +static inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu)
66     +{
67     + u32 esr = kvm_vcpu_get_hsr(vcpu);
68     + return (esr & ESR_ELx_SYS64_ISS_RT_MASK) >> ESR_ELx_SYS64_ISS_RT_SHIFT;
69     +}
70     +
71     static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu)
72     {
73     return vcpu_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK;
74     diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
75     index 0e26f8c2b56f..79168b38eeba 100644
76     --- a/arch/arm64/kvm/sys_regs.c
77     +++ b/arch/arm64/kvm/sys_regs.c
78     @@ -1638,8 +1638,8 @@ static int kvm_handle_cp_64(struct kvm_vcpu *vcpu,
79     {
80     struct sys_reg_params params;
81     u32 hsr = kvm_vcpu_get_hsr(vcpu);
82     - int Rt = (hsr >> 5) & 0xf;
83     - int Rt2 = (hsr >> 10) & 0xf;
84     + int Rt = kvm_vcpu_sys_get_rt(vcpu);
85     + int Rt2 = (hsr >> 10) & 0x1f;
86    
87     params.is_aarch32 = true;
88     params.is_32bit = false;
89     @@ -1690,7 +1690,7 @@ static int kvm_handle_cp_32(struct kvm_vcpu *vcpu,
90     {
91     struct sys_reg_params params;
92     u32 hsr = kvm_vcpu_get_hsr(vcpu);
93     - int Rt = (hsr >> 5) & 0xf;
94     + int Rt = kvm_vcpu_sys_get_rt(vcpu);
95    
96     params.is_aarch32 = true;
97     params.is_32bit = true;
98     @@ -1805,7 +1805,7 @@ int kvm_handle_sys_reg(struct kvm_vcpu *vcpu, struct kvm_run *run)
99     {
100     struct sys_reg_params params;
101     unsigned long esr = kvm_vcpu_get_hsr(vcpu);
102     - int Rt = (esr >> 5) & 0x1f;
103     + int Rt = kvm_vcpu_sys_get_rt(vcpu);
104     int ret;
105    
106     trace_kvm_handle_sys_reg(esr);
107     diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c
108     index d5e2b8309939..021db31b40ba 100644
109     --- a/arch/powerpc/kernel/nvram_64.c
110     +++ b/arch/powerpc/kernel/nvram_64.c
111     @@ -561,6 +561,7 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
112     static struct pstore_info nvram_pstore_info = {
113     .owner = THIS_MODULE,
114     .name = "nvram",
115     + .flags = PSTORE_FLAGS_DMESG,
116     .open = nvram_pstore_open,
117     .read = nvram_pstore_read,
118     .write = nvram_pstore_write,
119     diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
120     index 9b42b6d1e902..ef5a9cc66fb8 100644
121     --- a/arch/x86/boot/boot.h
122     +++ b/arch/x86/boot/boot.h
123     @@ -16,7 +16,7 @@
124     #ifndef BOOT_BOOT_H
125     #define BOOT_BOOT_H
126    
127     -#define STACK_SIZE 512 /* Minimum number of bytes for stack */
128     +#define STACK_SIZE 1024 /* Minimum number of bytes for stack */
129    
130     #ifndef __ASSEMBLY__
131    
132     diff --git a/arch/x86/events/intel/rapl.c b/arch/x86/events/intel/rapl.c
133     index 9d05c7e67f60..a45e2114a846 100644
134     --- a/arch/x86/events/intel/rapl.c
135     +++ b/arch/x86/events/intel/rapl.c
136     @@ -761,7 +761,7 @@ static const struct x86_cpu_id rapl_cpu_match[] __initconst = {
137    
138     X86_RAPL_MODEL_MATCH(INTEL_FAM6_BROADWELL_CORE, hsw_rapl_init),
139     X86_RAPL_MODEL_MATCH(INTEL_FAM6_BROADWELL_GT3E, hsw_rapl_init),
140     - X86_RAPL_MODEL_MATCH(INTEL_FAM6_BROADWELL_X, hsw_rapl_init),
141     + X86_RAPL_MODEL_MATCH(INTEL_FAM6_BROADWELL_X, hsx_rapl_init),
142     X86_RAPL_MODEL_MATCH(INTEL_FAM6_BROADWELL_XEON_D, hsw_rapl_init),
143    
144     X86_RAPL_MODEL_MATCH(INTEL_FAM6_XEON_PHI_KNL, knl_rapl_init),
145     diff --git a/arch/x86/include/asm/pmem.h b/arch/x86/include/asm/pmem.h
146     index 529bb4a6487a..e2904373010d 100644
147     --- a/arch/x86/include/asm/pmem.h
148     +++ b/arch/x86/include/asm/pmem.h
149     @@ -103,7 +103,7 @@ static inline size_t arch_copy_from_iter_pmem(void *addr, size_t bytes,
150    
151     if (bytes < 8) {
152     if (!IS_ALIGNED(dest, 4) || (bytes != 4))
153     - arch_wb_cache_pmem(addr, 1);
154     + arch_wb_cache_pmem(addr, bytes);
155     } else {
156     if (!IS_ALIGNED(dest, 8)) {
157     dest = ALIGN(dest, boot_cpu_data.x86_clflush_size);
158     diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
159     index bad6a25067bc..9fa5b8164961 100644
160     --- a/arch/x86/kvm/lapic.c
161     +++ b/arch/x86/kvm/lapic.c
162     @@ -529,14 +529,16 @@ int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq,
163    
164     static int pv_eoi_put_user(struct kvm_vcpu *vcpu, u8 val)
165     {
166     - return kvm_vcpu_write_guest_cached(vcpu, &vcpu->arch.pv_eoi.data, &val,
167     - sizeof(val));
168     +
169     + return kvm_write_guest_cached(vcpu->kvm, &vcpu->arch.pv_eoi.data, &val,
170     + sizeof(val));
171     }
172    
173     static int pv_eoi_get_user(struct kvm_vcpu *vcpu, u8 *val)
174     {
175     - return kvm_vcpu_read_guest_cached(vcpu, &vcpu->arch.pv_eoi.data, val,
176     - sizeof(*val));
177     +
178     + return kvm_read_guest_cached(vcpu->kvm, &vcpu->arch.pv_eoi.data, val,
179     + sizeof(*val));
180     }
181    
182     static inline bool pv_eoi_enabled(struct kvm_vcpu *vcpu)
183     @@ -2285,8 +2287,8 @@ void kvm_lapic_sync_from_vapic(struct kvm_vcpu *vcpu)
184     if (!test_bit(KVM_APIC_CHECK_VAPIC, &vcpu->arch.apic_attention))
185     return;
186    
187     - if (kvm_vcpu_read_guest_cached(vcpu, &vcpu->arch.apic->vapic_cache, &data,
188     - sizeof(u32)))
189     + if (kvm_read_guest_cached(vcpu->kvm, &vcpu->arch.apic->vapic_cache, &data,
190     + sizeof(u32)))
191     return;
192    
193     apic_set_tpr(vcpu->arch.apic, data & 0xff);
194     @@ -2338,14 +2340,14 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu)
195     max_isr = 0;
196     data = (tpr & 0xff) | ((max_isr & 0xf0) << 8) | (max_irr << 24);
197    
198     - kvm_vcpu_write_guest_cached(vcpu, &vcpu->arch.apic->vapic_cache, &data,
199     - sizeof(u32));
200     + kvm_write_guest_cached(vcpu->kvm, &vcpu->arch.apic->vapic_cache, &data,
201     + sizeof(u32));
202     }
203    
204     int kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr)
205     {
206     if (vapic_addr) {
207     - if (kvm_vcpu_gfn_to_hva_cache_init(vcpu,
208     + if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
209     &vcpu->arch.apic->vapic_cache,
210     vapic_addr, sizeof(u32)))
211     return -EINVAL;
212     @@ -2439,7 +2441,7 @@ int kvm_lapic_enable_pv_eoi(struct kvm_vcpu *vcpu, u64 data)
213     vcpu->arch.pv_eoi.msr_val = data;
214     if (!pv_eoi_enabled(vcpu))
215     return 0;
216     - return kvm_vcpu_gfn_to_hva_cache_init(vcpu, &vcpu->arch.pv_eoi.data,
217     + return kvm_gfn_to_hva_cache_init(vcpu->kvm, &vcpu->arch.pv_eoi.data,
218     addr, sizeof(u8));
219     }
220    
221     diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
222     index ccbd45ecd41a..421a069b5429 100644
223     --- a/arch/x86/kvm/x86.c
224     +++ b/arch/x86/kvm/x86.c
225     @@ -1813,7 +1813,7 @@ static void kvm_setup_pvclock_page(struct kvm_vcpu *v)
226     struct kvm_vcpu_arch *vcpu = &v->arch;
227     struct pvclock_vcpu_time_info guest_hv_clock;
228    
229     - if (unlikely(kvm_vcpu_read_guest_cached(v, &vcpu->pv_time,
230     + if (unlikely(kvm_read_guest_cached(v->kvm, &vcpu->pv_time,
231     &guest_hv_clock, sizeof(guest_hv_clock))))
232     return;
233    
234     @@ -1834,9 +1834,9 @@ static void kvm_setup_pvclock_page(struct kvm_vcpu *v)
235     BUILD_BUG_ON(offsetof(struct pvclock_vcpu_time_info, version) != 0);
236    
237     vcpu->hv_clock.version = guest_hv_clock.version + 1;
238     - kvm_vcpu_write_guest_cached(v, &vcpu->pv_time,
239     - &vcpu->hv_clock,
240     - sizeof(vcpu->hv_clock.version));
241     + kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
242     + &vcpu->hv_clock,
243     + sizeof(vcpu->hv_clock.version));
244    
245     smp_wmb();
246    
247     @@ -1850,16 +1850,16 @@ static void kvm_setup_pvclock_page(struct kvm_vcpu *v)
248    
249     trace_kvm_pvclock_update(v->vcpu_id, &vcpu->hv_clock);
250    
251     - kvm_vcpu_write_guest_cached(v, &vcpu->pv_time,
252     - &vcpu->hv_clock,
253     - sizeof(vcpu->hv_clock));
254     + kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
255     + &vcpu->hv_clock,
256     + sizeof(vcpu->hv_clock));
257    
258     smp_wmb();
259    
260     vcpu->hv_clock.version++;
261     - kvm_vcpu_write_guest_cached(v, &vcpu->pv_time,
262     - &vcpu->hv_clock,
263     - sizeof(vcpu->hv_clock.version));
264     + kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
265     + &vcpu->hv_clock,
266     + sizeof(vcpu->hv_clock.version));
267     }
268    
269     static int kvm_guest_time_update(struct kvm_vcpu *v)
270     @@ -2092,7 +2092,7 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
271     return 0;
272     }
273    
274     - if (kvm_vcpu_gfn_to_hva_cache_init(vcpu, &vcpu->arch.apf.data, gpa,
275     + if (kvm_gfn_to_hva_cache_init(vcpu->kvm, &vcpu->arch.apf.data, gpa,
276     sizeof(u32)))
277     return 1;
278    
279     @@ -2111,7 +2111,7 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
280     if (!(vcpu->arch.st.msr_val & KVM_MSR_ENABLED))
281     return;
282    
283     - if (unlikely(kvm_vcpu_read_guest_cached(vcpu, &vcpu->arch.st.stime,
284     + if (unlikely(kvm_read_guest_cached(vcpu->kvm, &vcpu->arch.st.stime,
285     &vcpu->arch.st.steal, sizeof(struct kvm_steal_time))))
286     return;
287    
288     @@ -2122,7 +2122,7 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
289    
290     vcpu->arch.st.steal.version += 1;
291    
292     - kvm_vcpu_write_guest_cached(vcpu, &vcpu->arch.st.stime,
293     + kvm_write_guest_cached(vcpu->kvm, &vcpu->arch.st.stime,
294     &vcpu->arch.st.steal, sizeof(struct kvm_steal_time));
295    
296     smp_wmb();
297     @@ -2131,14 +2131,14 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
298     vcpu->arch.st.last_steal;
299     vcpu->arch.st.last_steal = current->sched_info.run_delay;
300    
301     - kvm_vcpu_write_guest_cached(vcpu, &vcpu->arch.st.stime,
302     + kvm_write_guest_cached(vcpu->kvm, &vcpu->arch.st.stime,
303     &vcpu->arch.st.steal, sizeof(struct kvm_steal_time));
304    
305     smp_wmb();
306    
307     vcpu->arch.st.steal.version += 1;
308    
309     - kvm_vcpu_write_guest_cached(vcpu, &vcpu->arch.st.stime,
310     + kvm_write_guest_cached(vcpu->kvm, &vcpu->arch.st.stime,
311     &vcpu->arch.st.steal, sizeof(struct kvm_steal_time));
312     }
313    
314     @@ -2243,7 +2243,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
315     if (!(data & 1))
316     break;
317    
318     - if (kvm_vcpu_gfn_to_hva_cache_init(vcpu,
319     + if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
320     &vcpu->arch.pv_time, data & ~1ULL,
321     sizeof(struct pvclock_vcpu_time_info)))
322     vcpu->arch.pv_time_enabled = false;
323     @@ -2264,7 +2264,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
324     if (data & KVM_STEAL_RESERVED_MASK)
325     return 1;
326    
327     - if (kvm_vcpu_gfn_to_hva_cache_init(vcpu, &vcpu->arch.st.stime,
328     + if (kvm_gfn_to_hva_cache_init(vcpu->kvm, &vcpu->arch.st.stime,
329     data & KVM_STEAL_VALID_BITS,
330     sizeof(struct kvm_steal_time)))
331     return 1;
332     @@ -2878,7 +2878,7 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
333    
334     vcpu->arch.st.steal.preempted = 1;
335    
336     - kvm_vcpu_write_guest_offset_cached(vcpu, &vcpu->arch.st.stime,
337     + kvm_write_guest_offset_cached(vcpu->kvm, &vcpu->arch.st.stime,
338     &vcpu->arch.st.steal.preempted,
339     offsetof(struct kvm_steal_time, preempted),
340     sizeof(vcpu->arch.st.steal.preempted));
341     @@ -3127,6 +3127,12 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
342     (events->exception.nr > 31 || events->exception.nr == NMI_VECTOR))
343     return -EINVAL;
344    
345     + /* INITs are latched while in SMM */
346     + if (events->flags & KVM_VCPUEVENT_VALID_SMM &&
347     + (events->smi.smm || events->smi.pending) &&
348     + vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED)
349     + return -EINVAL;
350     +
351     process_nmi(vcpu);
352     vcpu->arch.exception.pending = events->exception.injected;
353     vcpu->arch.exception.nr = events->exception.nr;
354     @@ -7355,6 +7361,12 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
355     mp_state->mp_state != KVM_MP_STATE_RUNNABLE)
356     return -EINVAL;
357    
358     + /* INITs are latched while in SMM */
359     + if ((is_smm(vcpu) || vcpu->arch.smi_pending) &&
360     + (mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED ||
361     + mp_state->mp_state == KVM_MP_STATE_INIT_RECEIVED))
362     + return -EINVAL;
363     +
364     if (mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED) {
365     vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED;
366     set_bit(KVM_APIC_SIPI, &vcpu->arch.apic->pending_events);
367     @@ -8536,8 +8548,9 @@ static void kvm_del_async_pf_gfn(struct kvm_vcpu *vcpu, gfn_t gfn)
368    
369     static int apf_put_user(struct kvm_vcpu *vcpu, u32 val)
370     {
371     - return kvm_vcpu_write_guest_cached(vcpu, &vcpu->arch.apf.data, &val,
372     - sizeof(val));
373     +
374     + return kvm_write_guest_cached(vcpu->kvm, &vcpu->arch.apf.data, &val,
375     + sizeof(val));
376     }
377    
378     void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
379     diff --git a/arch/x86/um/ptrace_64.c b/arch/x86/um/ptrace_64.c
380     index a5c9910d234f..09a085bde0d4 100644
381     --- a/arch/x86/um/ptrace_64.c
382     +++ b/arch/x86/um/ptrace_64.c
383     @@ -125,7 +125,7 @@ int poke_user(struct task_struct *child, long addr, long data)
384     else if ((addr >= offsetof(struct user, u_debugreg[0])) &&
385     (addr <= offsetof(struct user, u_debugreg[7]))) {
386     addr -= offsetof(struct user, u_debugreg[0]);
387     - addr = addr >> 2;
388     + addr = addr >> 3;
389     if ((addr == 4) || (addr == 5))
390     return -EIO;
391     child->thread.arch.debugregs[addr] = data;
392     diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
393     index 37cb5aad71de..07b13e26215e 100644
394     --- a/arch/x86/xen/mmu.c
395     +++ b/arch/x86/xen/mmu.c
396     @@ -2023,7 +2023,8 @@ static unsigned long __init xen_read_phys_ulong(phys_addr_t addr)
397    
398     /*
399     * Translate a virtual address to a physical one without relying on mapped
400     - * page tables.
401     + * page tables. Don't rely on big pages being aligned in (guest) physical
402     + * space!
403     */
404     static phys_addr_t __init xen_early_virt_to_phys(unsigned long vaddr)
405     {
406     @@ -2044,7 +2045,7 @@ static phys_addr_t __init xen_early_virt_to_phys(unsigned long vaddr)
407     sizeof(pud)));
408     if (!pud_present(pud))
409     return 0;
410     - pa = pud_pfn(pud) << PAGE_SHIFT;
411     + pa = pud_val(pud) & PTE_PFN_MASK;
412     if (pud_large(pud))
413     return pa + (vaddr & ~PUD_MASK);
414    
415     @@ -2052,7 +2053,7 @@ static phys_addr_t __init xen_early_virt_to_phys(unsigned long vaddr)
416     sizeof(pmd)));
417     if (!pmd_present(pmd))
418     return 0;
419     - pa = pmd_pfn(pmd) << PAGE_SHIFT;
420     + pa = pmd_val(pmd) & PTE_PFN_MASK;
421     if (pmd_large(pmd))
422     return pa + (vaddr & ~PMD_MASK);
423    
424     diff --git a/block/blk-integrity.c b/block/blk-integrity.c
425     index 35c5af1ea068..e4ebd79de679 100644
426     --- a/block/blk-integrity.c
427     +++ b/block/blk-integrity.c
428     @@ -412,7 +412,8 @@ void blk_integrity_register(struct gendisk *disk, struct blk_integrity *template
429    
430     bi->flags = BLK_INTEGRITY_VERIFY | BLK_INTEGRITY_GENERATE |
431     template->flags;
432     - bi->interval_exp = ilog2(queue_logical_block_size(disk->queue));
433     + bi->interval_exp = template->interval_exp ? :
434     + ilog2(queue_logical_block_size(disk->queue));
435     bi->profile = template->profile ? template->profile : &nop_profile;
436     bi->tuple_size = template->tuple_size;
437     bi->tag_size = template->tag_size;
438     diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c
439     index ef59d9926ee9..8af664f7d27c 100644
440     --- a/crypto/algif_aead.c
441     +++ b/crypto/algif_aead.c
442     @@ -45,6 +45,11 @@ struct aead_async_req {
443     char iv[];
444     };
445    
446     +struct aead_tfm {
447     + struct crypto_aead *aead;
448     + bool has_key;
449     +};
450     +
451     struct aead_ctx {
452     struct aead_sg_list tsgl;
453     struct aead_async_rsgl first_rsgl;
454     @@ -723,24 +728,146 @@ static struct proto_ops algif_aead_ops = {
455     .poll = aead_poll,
456     };
457    
458     +static int aead_check_key(struct socket *sock)
459     +{
460     + int err = 0;
461     + struct sock *psk;
462     + struct alg_sock *pask;
463     + struct aead_tfm *tfm;
464     + struct sock *sk = sock->sk;
465     + struct alg_sock *ask = alg_sk(sk);
466     +
467     + lock_sock(sk);
468     + if (ask->refcnt)
469     + goto unlock_child;
470     +
471     + psk = ask->parent;
472     + pask = alg_sk(ask->parent);
473     + tfm = pask->private;
474     +
475     + err = -ENOKEY;
476     + lock_sock_nested(psk, SINGLE_DEPTH_NESTING);
477     + if (!tfm->has_key)
478     + goto unlock;
479     +
480     + if (!pask->refcnt++)
481     + sock_hold(psk);
482     +
483     + ask->refcnt = 1;
484     + sock_put(psk);
485     +
486     + err = 0;
487     +
488     +unlock:
489     + release_sock(psk);
490     +unlock_child:
491     + release_sock(sk);
492     +
493     + return err;
494     +}
495     +
496     +static int aead_sendmsg_nokey(struct socket *sock, struct msghdr *msg,
497     + size_t size)
498     +{
499     + int err;
500     +
501     + err = aead_check_key(sock);
502     + if (err)
503     + return err;
504     +
505     + return aead_sendmsg(sock, msg, size);
506     +}
507     +
508     +static ssize_t aead_sendpage_nokey(struct socket *sock, struct page *page,
509     + int offset, size_t size, int flags)
510     +{
511     + int err;
512     +
513     + err = aead_check_key(sock);
514     + if (err)
515     + return err;
516     +
517     + return aead_sendpage(sock, page, offset, size, flags);
518     +}
519     +
520     +static int aead_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
521     + size_t ignored, int flags)
522     +{
523     + int err;
524     +
525     + err = aead_check_key(sock);
526     + if (err)
527     + return err;
528     +
529     + return aead_recvmsg(sock, msg, ignored, flags);
530     +}
531     +
532     +static struct proto_ops algif_aead_ops_nokey = {
533     + .family = PF_ALG,
534     +
535     + .connect = sock_no_connect,
536     + .socketpair = sock_no_socketpair,
537     + .getname = sock_no_getname,
538     + .ioctl = sock_no_ioctl,
539     + .listen = sock_no_listen,
540     + .shutdown = sock_no_shutdown,
541     + .getsockopt = sock_no_getsockopt,
542     + .mmap = sock_no_mmap,
543     + .bind = sock_no_bind,
544     + .accept = sock_no_accept,
545     + .setsockopt = sock_no_setsockopt,
546     +
547     + .release = af_alg_release,
548     + .sendmsg = aead_sendmsg_nokey,
549     + .sendpage = aead_sendpage_nokey,
550     + .recvmsg = aead_recvmsg_nokey,
551     + .poll = aead_poll,
552     +};
553     +
554     static void *aead_bind(const char *name, u32 type, u32 mask)
555     {
556     - return crypto_alloc_aead(name, type, mask);
557     + struct aead_tfm *tfm;
558     + struct crypto_aead *aead;
559     +
560     + tfm = kzalloc(sizeof(*tfm), GFP_KERNEL);
561     + if (!tfm)
562     + return ERR_PTR(-ENOMEM);
563     +
564     + aead = crypto_alloc_aead(name, type, mask);
565     + if (IS_ERR(aead)) {
566     + kfree(tfm);
567     + return ERR_CAST(aead);
568     + }
569     +
570     + tfm->aead = aead;
571     +
572     + return tfm;
573     }
574    
575     static void aead_release(void *private)
576     {
577     - crypto_free_aead(private);
578     + struct aead_tfm *tfm = private;
579     +
580     + crypto_free_aead(tfm->aead);
581     + kfree(tfm);
582     }
583    
584     static int aead_setauthsize(void *private, unsigned int authsize)
585     {
586     - return crypto_aead_setauthsize(private, authsize);
587     + struct aead_tfm *tfm = private;
588     +
589     + return crypto_aead_setauthsize(tfm->aead, authsize);
590     }
591    
592     static int aead_setkey(void *private, const u8 *key, unsigned int keylen)
593     {
594     - return crypto_aead_setkey(private, key, keylen);
595     + struct aead_tfm *tfm = private;
596     + int err;
597     +
598     + err = crypto_aead_setkey(tfm->aead, key, keylen);
599     + tfm->has_key = !err;
600     +
601     + return err;
602     }
603    
604     static void aead_sock_destruct(struct sock *sk)
605     @@ -757,12 +884,14 @@ static void aead_sock_destruct(struct sock *sk)
606     af_alg_release_parent(sk);
607     }
608    
609     -static int aead_accept_parent(void *private, struct sock *sk)
610     +static int aead_accept_parent_nokey(void *private, struct sock *sk)
611     {
612     struct aead_ctx *ctx;
613     struct alg_sock *ask = alg_sk(sk);
614     - unsigned int len = sizeof(*ctx) + crypto_aead_reqsize(private);
615     - unsigned int ivlen = crypto_aead_ivsize(private);
616     + struct aead_tfm *tfm = private;
617     + struct crypto_aead *aead = tfm->aead;
618     + unsigned int len = sizeof(*ctx) + crypto_aead_reqsize(aead);
619     + unsigned int ivlen = crypto_aead_ivsize(aead);
620    
621     ctx = sock_kmalloc(sk, len, GFP_KERNEL);
622     if (!ctx)
623     @@ -789,7 +918,7 @@ static int aead_accept_parent(void *private, struct sock *sk)
624    
625     ask->private = ctx;
626    
627     - aead_request_set_tfm(&ctx->aead_req, private);
628     + aead_request_set_tfm(&ctx->aead_req, aead);
629     aead_request_set_callback(&ctx->aead_req, CRYPTO_TFM_REQ_MAY_BACKLOG,
630     af_alg_complete, &ctx->completion);
631    
632     @@ -798,13 +927,25 @@ static int aead_accept_parent(void *private, struct sock *sk)
633     return 0;
634     }
635    
636     +static int aead_accept_parent(void *private, struct sock *sk)
637     +{
638     + struct aead_tfm *tfm = private;
639     +
640     + if (!tfm->has_key)
641     + return -ENOKEY;
642     +
643     + return aead_accept_parent_nokey(private, sk);
644     +}
645     +
646     static const struct af_alg_type algif_type_aead = {
647     .bind = aead_bind,
648     .release = aead_release,
649     .setkey = aead_setkey,
650     .setauthsize = aead_setauthsize,
651     .accept = aead_accept_parent,
652     + .accept_nokey = aead_accept_parent_nokey,
653     .ops = &algif_aead_ops,
654     + .ops_nokey = &algif_aead_ops_nokey,
655     .name = "aead",
656     .owner = THIS_MODULE
657     };
658     diff --git a/drivers/Makefile b/drivers/Makefile
659     index 2eced9afba53..8f8bdc9e3d29 100644
660     --- a/drivers/Makefile
661     +++ b/drivers/Makefile
662     @@ -104,6 +104,7 @@ obj-$(CONFIG_USB_PHY) += usb/
663     obj-$(CONFIG_USB) += usb/
664     obj-$(CONFIG_PCI) += usb/
665     obj-$(CONFIG_USB_GADGET) += usb/
666     +obj-$(CONFIG_OF) += usb/
667     obj-$(CONFIG_SERIO) += input/serio/
668     obj-$(CONFIG_GAMEPORT) += input/gameport/
669     obj-$(CONFIG_INPUT) += input/
670     diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
671     index 1ac70744ae7b..50f56d066936 100644
672     --- a/drivers/ata/libata-scsi.c
673     +++ b/drivers/ata/libata-scsi.c
674     @@ -3462,6 +3462,14 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc)
675     if (unlikely(!dev->dma_mode))
676     goto invalid_opcode;
677    
678     + /*
679     + * We only allow sending this command through the block layer,
680     + * as it modifies the DATA OUT buffer, which would corrupt user
681     + * memory for SG_IO commands.
682     + */
683     + if (unlikely(blk_rq_is_passthrough(scmd->request)))
684     + goto invalid_opcode;
685     +
686     if (unlikely(scmd->cmd_len < 16)) {
687     fp = 15;
688     goto invalid_fld;
689     diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
690     index 5262a2077d7a..11f30e5cec2c 100644
691     --- a/drivers/bluetooth/hci_bcm.c
692     +++ b/drivers/bluetooth/hci_bcm.c
693     @@ -287,6 +287,9 @@ static int bcm_open(struct hci_uart *hu)
694    
695     hu->priv = bcm;
696    
697     + if (!hu->tty->dev)
698     + goto out;
699     +
700     mutex_lock(&bcm_device_lock);
701     list_for_each(p, &bcm_device_list) {
702     struct bcm_device *dev = list_entry(p, struct bcm_device, list);
703     @@ -307,7 +310,7 @@ static int bcm_open(struct hci_uart *hu)
704     }
705    
706     mutex_unlock(&bcm_device_lock);
707     -
708     +out:
709     return 0;
710     }
711    
712     diff --git a/drivers/bluetooth/hci_intel.c b/drivers/bluetooth/hci_intel.c
713     index 9e271286c5e5..73306384af6c 100644
714     --- a/drivers/bluetooth/hci_intel.c
715     +++ b/drivers/bluetooth/hci_intel.c
716     @@ -307,6 +307,9 @@ static int intel_set_power(struct hci_uart *hu, bool powered)
717     struct list_head *p;
718     int err = -ENODEV;
719    
720     + if (!hu->tty->dev)
721     + return err;
722     +
723     mutex_lock(&intel_device_list_lock);
724    
725     list_for_each(p, &intel_device_list) {
726     @@ -379,6 +382,9 @@ static void intel_busy_work(struct work_struct *work)
727     struct intel_data *intel = container_of(work, struct intel_data,
728     busy_work);
729    
730     + if (!intel->hu->tty->dev)
731     + return;
732     +
733     /* Link is busy, delay the suspend */
734     mutex_lock(&intel_device_list_lock);
735     list_for_each(p, &intel_device_list) {
736     @@ -889,6 +895,8 @@ static int intel_setup(struct hci_uart *hu)
737     list_for_each(p, &intel_device_list) {
738     struct intel_device *dev = list_entry(p, struct intel_device,
739     list);
740     + if (!hu->tty->dev)
741     + break;
742     if (hu->tty->dev->parent == dev->pdev->dev.parent) {
743     if (device_may_wakeup(&dev->pdev->dev)) {
744     set_bit(STATE_LPM_ENABLED, &intel->flags);
745     @@ -1056,6 +1064,9 @@ static int intel_enqueue(struct hci_uart *hu, struct sk_buff *skb)
746    
747     BT_DBG("hu %p skb %p", hu, skb);
748    
749     + if (!hu->tty->dev)
750     + goto out_enqueue;
751     +
752     /* Be sure our controller is resumed and potential LPM transaction
753     * completed before enqueuing any packet.
754     */
755     @@ -1072,7 +1083,7 @@ static int intel_enqueue(struct hci_uart *hu, struct sk_buff *skb)
756     }
757     }
758     mutex_unlock(&intel_device_list_lock);
759     -
760     +out_enqueue:
761     skb_queue_tail(&intel->txq, skb);
762    
763     return 0;
764     diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
765     index cca6e5bc1cea..51ba67de862e 100644
766     --- a/drivers/char/ipmi/ipmi_ssif.c
767     +++ b/drivers/char/ipmi/ipmi_ssif.c
768     @@ -891,6 +891,7 @@ static void msg_written_handler(struct ssif_info *ssif_info, int result,
769     * for details on the intricacies of this.
770     */
771     int left;
772     + unsigned char *data_to_send;
773    
774     ssif_inc_stat(ssif_info, sent_messages_parts);
775    
776     @@ -899,6 +900,7 @@ static void msg_written_handler(struct ssif_info *ssif_info, int result,
777     left = 32;
778     /* Length byte. */
779     ssif_info->multi_data[ssif_info->multi_pos] = left;
780     + data_to_send = ssif_info->multi_data + ssif_info->multi_pos;
781     ssif_info->multi_pos += left;
782     if (left < 32)
783     /*
784     @@ -912,7 +914,7 @@ static void msg_written_handler(struct ssif_info *ssif_info, int result,
785     rv = ssif_i2c_send(ssif_info, msg_written_handler,
786     I2C_SMBUS_WRITE,
787     SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE,
788     - ssif_info->multi_data + ssif_info->multi_pos,
789     + data_to_send,
790     I2C_SMBUS_BLOCK_DATA);
791     if (rv < 0) {
792     /* request failed, just return the error. */
793     diff --git a/drivers/crypto/ccp/ccp-dev-v3.c b/drivers/crypto/ccp/ccp-dev-v3.c
794     index 7bc09989e18a..c46eeda71595 100644
795     --- a/drivers/crypto/ccp/ccp-dev-v3.c
796     +++ b/drivers/crypto/ccp/ccp-dev-v3.c
797     @@ -315,17 +315,73 @@ static int ccp_perform_ecc(struct ccp_op *op)
798     return ccp_do_cmd(op, cr, ARRAY_SIZE(cr));
799     }
800    
801     +static void ccp_disable_queue_interrupts(struct ccp_device *ccp)
802     +{
803     + iowrite32(0x00, ccp->io_regs + IRQ_MASK_REG);
804     +}
805     +
806     +static void ccp_enable_queue_interrupts(struct ccp_device *ccp)
807     +{
808     + iowrite32(ccp->qim, ccp->io_regs + IRQ_MASK_REG);
809     +}
810     +
811     +static void ccp_irq_bh(unsigned long data)
812     +{
813     + struct ccp_device *ccp = (struct ccp_device *)data;
814     + struct ccp_cmd_queue *cmd_q;
815     + u32 q_int, status;
816     + unsigned int i;
817     +
818     + status = ioread32(ccp->io_regs + IRQ_STATUS_REG);
819     +
820     + for (i = 0; i < ccp->cmd_q_count; i++) {
821     + cmd_q = &ccp->cmd_q[i];
822     +
823     + q_int = status & (cmd_q->int_ok | cmd_q->int_err);
824     + if (q_int) {
825     + cmd_q->int_status = status;
826     + cmd_q->q_status = ioread32(cmd_q->reg_status);
827     + cmd_q->q_int_status = ioread32(cmd_q->reg_int_status);
828     +
829     + /* On error, only save the first error value */
830     + if ((q_int & cmd_q->int_err) && !cmd_q->cmd_error)
831     + cmd_q->cmd_error = CMD_Q_ERROR(cmd_q->q_status);
832     +
833     + cmd_q->int_rcvd = 1;
834     +
835     + /* Acknowledge the interrupt and wake the kthread */
836     + iowrite32(q_int, ccp->io_regs + IRQ_STATUS_REG);
837     + wake_up_interruptible(&cmd_q->int_queue);
838     + }
839     + }
840     + ccp_enable_queue_interrupts(ccp);
841     +}
842     +
843     +static irqreturn_t ccp_irq_handler(int irq, void *data)
844     +{
845     + struct device *dev = data;
846     + struct ccp_device *ccp = dev_get_drvdata(dev);
847     +
848     + ccp_disable_queue_interrupts(ccp);
849     + if (ccp->use_tasklet)
850     + tasklet_schedule(&ccp->irq_tasklet);
851     + else
852     + ccp_irq_bh((unsigned long)ccp);
853     +
854     + return IRQ_HANDLED;
855     +}
856     +
857     static int ccp_init(struct ccp_device *ccp)
858     {
859     struct device *dev = ccp->dev;
860     struct ccp_cmd_queue *cmd_q;
861     struct dma_pool *dma_pool;
862     char dma_pool_name[MAX_DMAPOOL_NAME_LEN];
863     - unsigned int qmr, qim, i;
864     + unsigned int qmr, i;
865     int ret;
866    
867     /* Find available queues */
868     - qim = 0;
869     + ccp->qim = 0;
870     qmr = ioread32(ccp->io_regs + Q_MASK_REG);
871     for (i = 0; i < MAX_HW_QUEUES; i++) {
872     if (!(qmr & (1 << i)))
873     @@ -370,7 +426,7 @@ static int ccp_init(struct ccp_device *ccp)
874     init_waitqueue_head(&cmd_q->int_queue);
875    
876     /* Build queue interrupt mask (two interrupts per queue) */
877     - qim |= cmd_q->int_ok | cmd_q->int_err;
878     + ccp->qim |= cmd_q->int_ok | cmd_q->int_err;
879    
880     #ifdef CONFIG_ARM64
881     /* For arm64 set the recommended queue cache settings */
882     @@ -388,14 +444,14 @@ static int ccp_init(struct ccp_device *ccp)
883     dev_notice(dev, "%u command queues available\n", ccp->cmd_q_count);
884    
885     /* Disable and clear interrupts until ready */
886     - iowrite32(0x00, ccp->io_regs + IRQ_MASK_REG);
887     + ccp_disable_queue_interrupts(ccp);
888     for (i = 0; i < ccp->cmd_q_count; i++) {
889     cmd_q = &ccp->cmd_q[i];
890    
891     ioread32(cmd_q->reg_int_status);
892     ioread32(cmd_q->reg_status);
893     }
894     - iowrite32(qim, ccp->io_regs + IRQ_STATUS_REG);
895     + iowrite32(ccp->qim, ccp->io_regs + IRQ_STATUS_REG);
896    
897     /* Request an irq */
898     ret = ccp->get_irq(ccp);
899     @@ -404,6 +460,11 @@ static int ccp_init(struct ccp_device *ccp)
900     goto e_pool;
901     }
902    
903     + /* Initialize the ISR tasklet? */
904     + if (ccp->use_tasklet)
905     + tasklet_init(&ccp->irq_tasklet, ccp_irq_bh,
906     + (unsigned long)ccp);
907     +
908     dev_dbg(dev, "Starting threads...\n");
909     /* Create a kthread for each queue */
910     for (i = 0; i < ccp->cmd_q_count; i++) {
911     @@ -426,7 +487,7 @@ static int ccp_init(struct ccp_device *ccp)
912    
913     dev_dbg(dev, "Enabling interrupts...\n");
914     /* Enable interrupts */
915     - iowrite32(qim, ccp->io_regs + IRQ_MASK_REG);
916     + ccp_enable_queue_interrupts(ccp);
917    
918     dev_dbg(dev, "Registering device...\n");
919     ccp_add_device(ccp);
920     @@ -463,7 +524,7 @@ static void ccp_destroy(struct ccp_device *ccp)
921     {
922     struct ccp_cmd_queue *cmd_q;
923     struct ccp_cmd *cmd;
924     - unsigned int qim, i;
925     + unsigned int i;
926    
927     /* Unregister the DMA engine */
928     ccp_dmaengine_unregister(ccp);
929     @@ -474,22 +535,15 @@ static void ccp_destroy(struct ccp_device *ccp)
930     /* Remove this device from the list of available units */
931     ccp_del_device(ccp);
932    
933     - /* Build queue interrupt mask (two interrupt masks per queue) */
934     - qim = 0;
935     - for (i = 0; i < ccp->cmd_q_count; i++) {
936     - cmd_q = &ccp->cmd_q[i];
937     - qim |= cmd_q->int_ok | cmd_q->int_err;
938     - }
939     -
940     /* Disable and clear interrupts */
941     - iowrite32(0x00, ccp->io_regs + IRQ_MASK_REG);
942     + ccp_disable_queue_interrupts(ccp);
943     for (i = 0; i < ccp->cmd_q_count; i++) {
944     cmd_q = &ccp->cmd_q[i];
945    
946     ioread32(cmd_q->reg_int_status);
947     ioread32(cmd_q->reg_status);
948     }
949     - iowrite32(qim, ccp->io_regs + IRQ_STATUS_REG);
950     + iowrite32(ccp->qim, ccp->io_regs + IRQ_STATUS_REG);
951    
952     /* Stop the queue kthreads */
953     for (i = 0; i < ccp->cmd_q_count; i++)
954     @@ -516,40 +570,6 @@ static void ccp_destroy(struct ccp_device *ccp)
955     }
956     }
957    
958     -static irqreturn_t ccp_irq_handler(int irq, void *data)
959     -{
960     - struct device *dev = data;
961     - struct ccp_device *ccp = dev_get_drvdata(dev);
962     - struct ccp_cmd_queue *cmd_q;
963     - u32 q_int, status;
964     - unsigned int i;
965     -
966     - status = ioread32(ccp->io_regs + IRQ_STATUS_REG);
967     -
968     - for (i = 0; i < ccp->cmd_q_count; i++) {
969     - cmd_q = &ccp->cmd_q[i];
970     -
971     - q_int = status & (cmd_q->int_ok | cmd_q->int_err);
972     - if (q_int) {
973     - cmd_q->int_status = status;
974     - cmd_q->q_status = ioread32(cmd_q->reg_status);
975     - cmd_q->q_int_status = ioread32(cmd_q->reg_int_status);
976     -
977     - /* On error, only save the first error value */
978     - if ((q_int & cmd_q->int_err) && !cmd_q->cmd_error)
979     - cmd_q->cmd_error = CMD_Q_ERROR(cmd_q->q_status);
980     -
981     - cmd_q->int_rcvd = 1;
982     -
983     - /* Acknowledge the interrupt and wake the kthread */
984     - iowrite32(q_int, ccp->io_regs + IRQ_STATUS_REG);
985     - wake_up_interruptible(&cmd_q->int_queue);
986     - }
987     - }
988     -
989     - return IRQ_HANDLED;
990     -}
991     -
992     static const struct ccp_actions ccp3_actions = {
993     .aes = ccp_perform_aes,
994     .xts_aes = ccp_perform_xts_aes,
995     diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
996     index fc08b4ed69d9..4e2b01091715 100644
997     --- a/drivers/crypto/ccp/ccp-dev-v5.c
998     +++ b/drivers/crypto/ccp/ccp-dev-v5.c
999     @@ -653,6 +653,65 @@ static int ccp_assign_lsbs(struct ccp_device *ccp)
1000     return rc;
1001     }
1002    
1003     +static void ccp5_disable_queue_interrupts(struct ccp_device *ccp)
1004     +{
1005     + unsigned int i;
1006     +
1007     + for (i = 0; i < ccp->cmd_q_count; i++)
1008     + iowrite32(0x0, ccp->cmd_q[i].reg_int_enable);
1009     +}
1010     +
1011     +static void ccp5_enable_queue_interrupts(struct ccp_device *ccp)
1012     +{
1013     + unsigned int i;
1014     +
1015     + for (i = 0; i < ccp->cmd_q_count; i++)
1016     + iowrite32(SUPPORTED_INTERRUPTS, ccp->cmd_q[i].reg_int_enable);
1017     +}
1018     +
1019     +static void ccp5_irq_bh(unsigned long data)
1020     +{
1021     + struct ccp_device *ccp = (struct ccp_device *)data;
1022     + u32 status;
1023     + unsigned int i;
1024     +
1025     + for (i = 0; i < ccp->cmd_q_count; i++) {
1026     + struct ccp_cmd_queue *cmd_q = &ccp->cmd_q[i];
1027     +
1028     + status = ioread32(cmd_q->reg_interrupt_status);
1029     +
1030     + if (status) {
1031     + cmd_q->int_status = status;
1032     + cmd_q->q_status = ioread32(cmd_q->reg_status);
1033     + cmd_q->q_int_status = ioread32(cmd_q->reg_int_status);
1034     +
1035     + /* On error, only save the first error value */
1036     + if ((status & INT_ERROR) && !cmd_q->cmd_error)
1037     + cmd_q->cmd_error = CMD_Q_ERROR(cmd_q->q_status);
1038     +
1039     + cmd_q->int_rcvd = 1;
1040     +
1041     + /* Acknowledge the interrupt and wake the kthread */
1042     + iowrite32(status, cmd_q->reg_interrupt_status);
1043     + wake_up_interruptible(&cmd_q->int_queue);
1044     + }
1045     + }
1046     + ccp5_enable_queue_interrupts(ccp);
1047     +}
1048     +
1049     +static irqreturn_t ccp5_irq_handler(int irq, void *data)
1050     +{
1051     + struct device *dev = data;
1052     + struct ccp_device *ccp = dev_get_drvdata(dev);
1053     +
1054     + ccp5_disable_queue_interrupts(ccp);
1055     + if (ccp->use_tasklet)
1056     + tasklet_schedule(&ccp->irq_tasklet);
1057     + else
1058     + ccp5_irq_bh((unsigned long)ccp);
1059     + return IRQ_HANDLED;
1060     +}
1061     +
1062     static int ccp5_init(struct ccp_device *ccp)
1063     {
1064     struct device *dev = ccp->dev;
1065     @@ -736,19 +795,18 @@ static int ccp5_init(struct ccp_device *ccp)
1066     }
1067    
1068     /* Turn off the queues and disable interrupts until ready */
1069     + ccp5_disable_queue_interrupts(ccp);
1070     for (i = 0; i < ccp->cmd_q_count; i++) {
1071     cmd_q = &ccp->cmd_q[i];
1072    
1073     cmd_q->qcontrol = 0; /* Start with nothing */
1074     iowrite32(cmd_q->qcontrol, cmd_q->reg_control);
1075    
1076     - /* Disable the interrupts */
1077     - iowrite32(0x00, cmd_q->reg_int_enable);
1078     ioread32(cmd_q->reg_int_status);
1079     ioread32(cmd_q->reg_status);
1080    
1081     - /* Clear the interrupts */
1082     - iowrite32(ALL_INTERRUPTS, cmd_q->reg_interrupt_status);
1083     + /* Clear the interrupt status */
1084     + iowrite32(SUPPORTED_INTERRUPTS, cmd_q->reg_interrupt_status);
1085     }
1086    
1087     dev_dbg(dev, "Requesting an IRQ...\n");
1088     @@ -758,6 +816,10 @@ static int ccp5_init(struct ccp_device *ccp)
1089     dev_err(dev, "unable to allocate an IRQ\n");
1090     goto e_pool;
1091     }
1092     + /* Initialize the ISR tasklet */
1093     + if (ccp->use_tasklet)
1094     + tasklet_init(&ccp->irq_tasklet, ccp5_irq_bh,
1095     + (unsigned long)ccp);
1096    
1097     dev_dbg(dev, "Loading LSB map...\n");
1098     /* Copy the private LSB mask to the public registers */
1099     @@ -826,11 +888,7 @@ static int ccp5_init(struct ccp_device *ccp)
1100     }
1101    
1102     dev_dbg(dev, "Enabling interrupts...\n");
1103     - /* Enable interrupts */
1104     - for (i = 0; i < ccp->cmd_q_count; i++) {
1105     - cmd_q = &ccp->cmd_q[i];
1106     - iowrite32(ALL_INTERRUPTS, cmd_q->reg_int_enable);
1107     - }
1108     + ccp5_enable_queue_interrupts(ccp);
1109    
1110     dev_dbg(dev, "Registering device...\n");
1111     /* Put this on the unit list to make it available */
1112     @@ -882,17 +940,15 @@ static void ccp5_destroy(struct ccp_device *ccp)
1113     ccp_del_device(ccp);
1114    
1115     /* Disable and clear interrupts */
1116     + ccp5_disable_queue_interrupts(ccp);
1117     for (i = 0; i < ccp->cmd_q_count; i++) {
1118     cmd_q = &ccp->cmd_q[i];
1119    
1120     /* Turn off the run bit */
1121     iowrite32(cmd_q->qcontrol & ~CMD5_Q_RUN, cmd_q->reg_control);
1122    
1123     - /* Disable the interrupts */
1124     - iowrite32(ALL_INTERRUPTS, cmd_q->reg_interrupt_status);
1125     -
1126     /* Clear the interrupt status */
1127     - iowrite32(0x00, cmd_q->reg_int_enable);
1128     + iowrite32(SUPPORTED_INTERRUPTS, cmd_q->reg_interrupt_status);
1129     ioread32(cmd_q->reg_int_status);
1130     ioread32(cmd_q->reg_status);
1131     }
1132     @@ -925,38 +981,6 @@ static void ccp5_destroy(struct ccp_device *ccp)
1133     }
1134     }
1135    
1136     -static irqreturn_t ccp5_irq_handler(int irq, void *data)
1137     -{
1138     - struct device *dev = data;
1139     - struct ccp_device *ccp = dev_get_drvdata(dev);
1140     - u32 status;
1141     - unsigned int i;
1142     -
1143     - for (i = 0; i < ccp->cmd_q_count; i++) {
1144     - struct ccp_cmd_queue *cmd_q = &ccp->cmd_q[i];
1145     -
1146     - status = ioread32(cmd_q->reg_interrupt_status);
1147     -
1148     - if (status) {
1149     - cmd_q->int_status = status;
1150     - cmd_q->q_status = ioread32(cmd_q->reg_status);
1151     - cmd_q->q_int_status = ioread32(cmd_q->reg_int_status);
1152     -
1153     - /* On error, only save the first error value */
1154     - if ((status & INT_ERROR) && !cmd_q->cmd_error)
1155     - cmd_q->cmd_error = CMD_Q_ERROR(cmd_q->q_status);
1156     -
1157     - cmd_q->int_rcvd = 1;
1158     -
1159     - /* Acknowledge the interrupt and wake the kthread */
1160     - iowrite32(ALL_INTERRUPTS, cmd_q->reg_interrupt_status);
1161     - wake_up_interruptible(&cmd_q->int_queue);
1162     - }
1163     - }
1164     -
1165     - return IRQ_HANDLED;
1166     -}
1167     -
1168     static void ccp5_config(struct ccp_device *ccp)
1169     {
1170     /* Public side */
1171     diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
1172     index aa36f3f81860..6bb60e11b0e6 100644
1173     --- a/drivers/crypto/ccp/ccp-dev.h
1174     +++ b/drivers/crypto/ccp/ccp-dev.h
1175     @@ -109,9 +109,8 @@
1176     #define INT_COMPLETION 0x1
1177     #define INT_ERROR 0x2
1178     #define INT_QUEUE_STOPPED 0x4
1179     -#define ALL_INTERRUPTS (INT_COMPLETION| \
1180     - INT_ERROR| \
1181     - INT_QUEUE_STOPPED)
1182     +#define INT_EMPTY_QUEUE 0x8
1183     +#define SUPPORTED_INTERRUPTS (INT_COMPLETION | INT_ERROR)
1184    
1185     #define LSB_REGION_WIDTH 5
1186     #define MAX_LSB_CNT 8
1187     @@ -337,7 +336,10 @@ struct ccp_device {
1188     void *dev_specific;
1189     int (*get_irq)(struct ccp_device *ccp);
1190     void (*free_irq)(struct ccp_device *ccp);
1191     + unsigned int qim;
1192     unsigned int irq;
1193     + bool use_tasklet;
1194     + struct tasklet_struct irq_tasklet;
1195    
1196     /* I/O area used for device communication. The register mapping
1197     * starts at an offset into the mapped bar.
1198     diff --git a/drivers/crypto/ccp/ccp-pci.c b/drivers/crypto/ccp/ccp-pci.c
1199     index 28a9996c1085..e880d4cf4ada 100644
1200     --- a/drivers/crypto/ccp/ccp-pci.c
1201     +++ b/drivers/crypto/ccp/ccp-pci.c
1202     @@ -69,6 +69,7 @@ static int ccp_get_msix_irqs(struct ccp_device *ccp)
1203     goto e_irq;
1204     }
1205     }
1206     + ccp->use_tasklet = true;
1207    
1208     return 0;
1209    
1210     @@ -100,6 +101,7 @@ static int ccp_get_msi_irq(struct ccp_device *ccp)
1211     dev_notice(dev, "unable to allocate MSI IRQ (%d)\n", ret);
1212     goto e_msi;
1213     }
1214     + ccp->use_tasklet = true;
1215    
1216     return 0;
1217    
1218     diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c
1219     index 1b9da3dc799b..6c620487e9c2 100644
1220     --- a/drivers/crypto/s5p-sss.c
1221     +++ b/drivers/crypto/s5p-sss.c
1222     @@ -287,7 +287,6 @@ static void s5p_sg_done(struct s5p_aes_dev *dev)
1223     static void s5p_aes_complete(struct s5p_aes_dev *dev, int err)
1224     {
1225     dev->req->base.complete(&dev->req->base, err);
1226     - dev->busy = false;
1227     }
1228    
1229     static void s5p_unset_outdata(struct s5p_aes_dev *dev)
1230     @@ -462,7 +461,7 @@ static irqreturn_t s5p_aes_interrupt(int irq, void *dev_id)
1231     spin_unlock_irqrestore(&dev->lock, flags);
1232    
1233     s5p_aes_complete(dev, 0);
1234     - dev->busy = true;
1235     + /* Device is still busy */
1236     tasklet_schedule(&dev->tasklet);
1237     } else {
1238     /*
1239     @@ -483,6 +482,7 @@ static irqreturn_t s5p_aes_interrupt(int irq, void *dev_id)
1240    
1241     error:
1242     s5p_sg_done(dev);
1243     + dev->busy = false;
1244     spin_unlock_irqrestore(&dev->lock, flags);
1245     s5p_aes_complete(dev, err);
1246    
1247     @@ -634,6 +634,7 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *dev, unsigned long mode)
1248    
1249     indata_error:
1250     s5p_sg_done(dev);
1251     + dev->busy = false;
1252     spin_unlock_irqrestore(&dev->lock, flags);
1253     s5p_aes_complete(dev, err);
1254     }
1255     diff --git a/drivers/dax/dax.c b/drivers/dax/dax.c
1256     index 806f180c80d8..f71ececd2678 100644
1257     --- a/drivers/dax/dax.c
1258     +++ b/drivers/dax/dax.c
1259     @@ -77,36 +77,27 @@ struct dax_dev {
1260     struct resource res[0];
1261     };
1262    
1263     +/*
1264     + * Rely on the fact that drvdata is set before the attributes are
1265     + * registered, and that the attributes are unregistered before drvdata
1266     + * is cleared to assume that drvdata is always valid.
1267     + */
1268     static ssize_t id_show(struct device *dev,
1269     struct device_attribute *attr, char *buf)
1270     {
1271     - struct dax_region *dax_region;
1272     - ssize_t rc = -ENXIO;
1273     + struct dax_region *dax_region = dev_get_drvdata(dev);
1274    
1275     - device_lock(dev);
1276     - dax_region = dev_get_drvdata(dev);
1277     - if (dax_region)
1278     - rc = sprintf(buf, "%d\n", dax_region->id);
1279     - device_unlock(dev);
1280     -
1281     - return rc;
1282     + return sprintf(buf, "%d\n", dax_region->id);
1283     }
1284     static DEVICE_ATTR_RO(id);
1285    
1286     static ssize_t region_size_show(struct device *dev,
1287     struct device_attribute *attr, char *buf)
1288     {
1289     - struct dax_region *dax_region;
1290     - ssize_t rc = -ENXIO;
1291     + struct dax_region *dax_region = dev_get_drvdata(dev);
1292    
1293     - device_lock(dev);
1294     - dax_region = dev_get_drvdata(dev);
1295     - if (dax_region)
1296     - rc = sprintf(buf, "%llu\n", (unsigned long long)
1297     - resource_size(&dax_region->res));
1298     - device_unlock(dev);
1299     -
1300     - return rc;
1301     + return sprintf(buf, "%llu\n", (unsigned long long)
1302     + resource_size(&dax_region->res));
1303     }
1304     static struct device_attribute dev_attr_region_size = __ATTR(size, 0444,
1305     region_size_show, NULL);
1306     @@ -114,16 +105,9 @@ static struct device_attribute dev_attr_region_size = __ATTR(size, 0444,
1307     static ssize_t align_show(struct device *dev,
1308     struct device_attribute *attr, char *buf)
1309     {
1310     - struct dax_region *dax_region;
1311     - ssize_t rc = -ENXIO;
1312     + struct dax_region *dax_region = dev_get_drvdata(dev);
1313    
1314     - device_lock(dev);
1315     - dax_region = dev_get_drvdata(dev);
1316     - if (dax_region)
1317     - rc = sprintf(buf, "%u\n", dax_region->align);
1318     - device_unlock(dev);
1319     -
1320     - return rc;
1321     + return sprintf(buf, "%u\n", dax_region->align);
1322     }
1323     static DEVICE_ATTR_RO(align);
1324    
1325     @@ -703,13 +687,10 @@ static void dax_dev_release(struct device *dev)
1326     kfree(dax_dev);
1327     }
1328    
1329     -static void unregister_dax_dev(void *dev)
1330     +static void kill_dax_dev(struct dax_dev *dax_dev)
1331     {
1332     - struct dax_dev *dax_dev = to_dax_dev(dev);
1333     struct cdev *cdev = &dax_dev->cdev;
1334    
1335     - dev_dbg(dev, "%s\n", __func__);
1336     -
1337     /*
1338     * Note, rcu is not protecting the liveness of dax_dev, rcu is
1339     * ensuring that any fault handlers that might have seen
1340     @@ -721,6 +702,15 @@ static void unregister_dax_dev(void *dev)
1341     synchronize_srcu(&dax_srcu);
1342     unmap_mapping_range(dax_dev->inode->i_mapping, 0, 0, 1);
1343     cdev_del(cdev);
1344     +}
1345     +
1346     +static void unregister_dax_dev(void *dev)
1347     +{
1348     + struct dax_dev *dax_dev = to_dax_dev(dev);
1349     +
1350     + dev_dbg(dev, "%s\n", __func__);
1351     +
1352     + kill_dax_dev(dax_dev);
1353     device_unregister(dev);
1354     }
1355    
1356     @@ -797,6 +787,7 @@ struct dax_dev *devm_create_dax_dev(struct dax_region *dax_region,
1357     dev_set_name(dev, "dax%d.%d", dax_region->id, dax_dev->id);
1358     rc = device_add(dev);
1359     if (rc) {
1360     + kill_dax_dev(dax_dev);
1361     put_device(dev);
1362     return ERR_PTR(rc);
1363     }
1364     diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
1365     index 7c9e34d679d3..81d447da0048 100644
1366     --- a/drivers/infiniband/core/device.c
1367     +++ b/drivers/infiniband/core/device.c
1368     @@ -172,8 +172,16 @@ static void ib_device_release(struct device *device)
1369     {
1370     struct ib_device *dev = container_of(device, struct ib_device, dev);
1371    
1372     - ib_cache_release_one(dev);
1373     - kfree(dev->port_immutable);
1374     + WARN_ON(dev->reg_state == IB_DEV_REGISTERED);
1375     + if (dev->reg_state == IB_DEV_UNREGISTERED) {
1376     + /*
1377     + * In IB_DEV_UNINITIALIZED state, cache or port table
1378     + * is not even created. Free cache and port table only when
1379     + * device reaches UNREGISTERED state.
1380     + */
1381     + ib_cache_release_one(dev);
1382     + kfree(dev->port_immutable);
1383     + }
1384     kfree(dev);
1385     }
1386    
1387     @@ -380,32 +388,27 @@ int ib_register_device(struct ib_device *device,
1388     ret = ib_cache_setup_one(device);
1389     if (ret) {
1390     pr_warn("Couldn't set up InfiniBand P_Key/GID cache\n");
1391     - goto out;
1392     + goto port_cleanup;
1393     }
1394    
1395     ret = ib_device_register_rdmacg(device);
1396     if (ret) {
1397     pr_warn("Couldn't register device with rdma cgroup\n");
1398     - ib_cache_cleanup_one(device);
1399     - goto out;
1400     + goto cache_cleanup;
1401     }
1402    
1403     memset(&device->attrs, 0, sizeof(device->attrs));
1404     ret = device->query_device(device, &device->attrs, &uhw);
1405     if (ret) {
1406     pr_warn("Couldn't query the device attributes\n");
1407     - ib_device_unregister_rdmacg(device);
1408     - ib_cache_cleanup_one(device);
1409     - goto out;
1410     + goto cache_cleanup;
1411     }
1412    
1413     ret = ib_device_register_sysfs(device, port_callback);
1414     if (ret) {
1415     pr_warn("Couldn't register device %s with driver model\n",
1416     device->name);
1417     - ib_device_unregister_rdmacg(device);
1418     - ib_cache_cleanup_one(device);
1419     - goto out;
1420     + goto cache_cleanup;
1421     }
1422    
1423     device->reg_state = IB_DEV_REGISTERED;
1424     @@ -417,6 +420,14 @@ int ib_register_device(struct ib_device *device,
1425     down_write(&lists_rwsem);
1426     list_add_tail(&device->core_list, &device_list);
1427     up_write(&lists_rwsem);
1428     + mutex_unlock(&device_mutex);
1429     + return 0;
1430     +
1431     +cache_cleanup:
1432     + ib_cache_cleanup_one(device);
1433     + ib_cache_release_one(device);
1434     +port_cleanup:
1435     + kfree(device->port_immutable);
1436     out:
1437     mutex_unlock(&device_mutex);
1438     return ret;
1439     diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
1440     index daadf3130c9f..48bb75503255 100644
1441     --- a/drivers/infiniband/core/sysfs.c
1442     +++ b/drivers/infiniband/core/sysfs.c
1443     @@ -1301,7 +1301,7 @@ int ib_device_register_sysfs(struct ib_device *device,
1444     free_port_list_attributes(device);
1445    
1446     err_unregister:
1447     - device_unregister(class_dev);
1448     + device_del(class_dev);
1449    
1450     err:
1451     return ret;
1452     diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
1453     index 85ed5051fdfd..207e5c2457cc 100644
1454     --- a/drivers/infiniband/core/verbs.c
1455     +++ b/drivers/infiniband/core/verbs.c
1456     @@ -1519,7 +1519,9 @@ int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid)
1457    
1458     if (!qp->device->attach_mcast)
1459     return -ENOSYS;
1460     - if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD)
1461     + if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD ||
1462     + lid < be16_to_cpu(IB_MULTICAST_LID_BASE) ||
1463     + lid == be16_to_cpu(IB_LID_PERMISSIVE))
1464     return -EINVAL;
1465    
1466     ret = qp->device->attach_mcast(qp, gid, lid);
1467     @@ -1535,7 +1537,9 @@ int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid)
1468    
1469     if (!qp->device->detach_mcast)
1470     return -ENOSYS;
1471     - if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD)
1472     + if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD ||
1473     + lid < be16_to_cpu(IB_MULTICAST_LID_BASE) ||
1474     + lid == be16_to_cpu(IB_LID_PERMISSIVE))
1475     return -EINVAL;
1476    
1477     ret = qp->device->detach_mcast(qp, gid, lid);
1478     diff --git a/drivers/infiniband/hw/hfi1/ruc.c b/drivers/infiniband/hw/hfi1/ruc.c
1479     index aa15bcbfb079..17d7578de6e5 100644
1480     --- a/drivers/infiniband/hw/hfi1/ruc.c
1481     +++ b/drivers/infiniband/hw/hfi1/ruc.c
1482     @@ -1,5 +1,5 @@
1483     /*
1484     - * Copyright(c) 2015, 2016 Intel Corporation.
1485     + * Copyright(c) 2015 - 2017 Intel Corporation.
1486     *
1487     * This file is provided under a dual BSD/GPLv2 license. When using or
1488     * redistributing this file, you may do so under either license.
1489     @@ -784,23 +784,29 @@ void hfi1_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr,
1490     /* when sending, force a reschedule every one of these periods */
1491     #define SEND_RESCHED_TIMEOUT (5 * HZ) /* 5s in jiffies */
1492    
1493     +void hfi1_do_send_from_rvt(struct rvt_qp *qp)
1494     +{
1495     + hfi1_do_send(qp, false);
1496     +}
1497     +
1498     void _hfi1_do_send(struct work_struct *work)
1499     {
1500     struct iowait *wait = container_of(work, struct iowait, iowork);
1501     struct rvt_qp *qp = iowait_to_qp(wait);
1502    
1503     - hfi1_do_send(qp);
1504     + hfi1_do_send(qp, true);
1505     }
1506    
1507     /**
1508     * hfi1_do_send - perform a send on a QP
1509     * @work: contains a pointer to the QP
1510     + * @in_thread: true if in a workqueue thread
1511     *
1512     * Process entries in the send work queue until credit or queue is
1513     * exhausted. Only allow one CPU to send a packet per QP.
1514     * Otherwise, two threads could send packets out of order.
1515     */
1516     -void hfi1_do_send(struct rvt_qp *qp)
1517     +void hfi1_do_send(struct rvt_qp *qp, bool in_thread)
1518     {
1519     struct hfi1_pkt_state ps;
1520     struct hfi1_qp_priv *priv = qp->priv;
1521     @@ -868,8 +874,10 @@ void hfi1_do_send(struct rvt_qp *qp)
1522     qp->s_hdrwords = 0;
1523     /* allow other tasks to run */
1524     if (unlikely(time_after(jiffies, timeout))) {
1525     - if (workqueue_congested(cpu,
1526     - ps.ppd->hfi1_wq)) {
1527     + if (!in_thread ||
1528     + workqueue_congested(
1529     + cpu,
1530     + ps.ppd->hfi1_wq)) {
1531     spin_lock_irqsave(
1532     &qp->s_lock,
1533     ps.flags);
1534     @@ -882,11 +890,9 @@ void hfi1_do_send(struct rvt_qp *qp)
1535     *ps.ppd->dd->send_schedule);
1536     return;
1537     }
1538     - if (!irqs_disabled()) {
1539     - cond_resched();
1540     - this_cpu_inc(
1541     - *ps.ppd->dd->send_schedule);
1542     - }
1543     + cond_resched();
1544     + this_cpu_inc(
1545     + *ps.ppd->dd->send_schedule);
1546     timeout = jiffies + (timeout_int) / 8;
1547     }
1548     spin_lock_irqsave(&qp->s_lock, ps.flags);
1549     diff --git a/drivers/infiniband/hw/hfi1/verbs.c b/drivers/infiniband/hw/hfi1/verbs.c
1550     index 222315fadab1..16ef7b12b0b8 100644
1551     --- a/drivers/infiniband/hw/hfi1/verbs.c
1552     +++ b/drivers/infiniband/hw/hfi1/verbs.c
1553     @@ -1,5 +1,5 @@
1554     /*
1555     - * Copyright(c) 2015, 2016 Intel Corporation.
1556     + * Copyright(c) 2015 - 2017 Intel Corporation.
1557     *
1558     * This file is provided under a dual BSD/GPLv2 license. When using or
1559     * redistributing this file, you may do so under either license.
1560     @@ -1751,7 +1751,7 @@ int hfi1_register_ib_device(struct hfi1_devdata *dd)
1561     dd->verbs_dev.rdi.driver_f.qp_priv_free = qp_priv_free;
1562     dd->verbs_dev.rdi.driver_f.free_all_qps = free_all_qps;
1563     dd->verbs_dev.rdi.driver_f.notify_qp_reset = notify_qp_reset;
1564     - dd->verbs_dev.rdi.driver_f.do_send = hfi1_do_send;
1565     + dd->verbs_dev.rdi.driver_f.do_send = hfi1_do_send_from_rvt;
1566     dd->verbs_dev.rdi.driver_f.schedule_send = hfi1_schedule_send;
1567     dd->verbs_dev.rdi.driver_f.schedule_send_no_lock = _hfi1_schedule_send;
1568     dd->verbs_dev.rdi.driver_f.get_pmtu_from_attr = get_pmtu_from_attr;
1569     diff --git a/drivers/infiniband/hw/hfi1/verbs.h b/drivers/infiniband/hw/hfi1/verbs.h
1570     index 3a0b589e41c2..92e72ab2b610 100644
1571     --- a/drivers/infiniband/hw/hfi1/verbs.h
1572     +++ b/drivers/infiniband/hw/hfi1/verbs.h
1573     @@ -1,5 +1,5 @@
1574     /*
1575     - * Copyright(c) 2015, 2016 Intel Corporation.
1576     + * Copyright(c) 2015 - 2017 Intel Corporation.
1577     *
1578     * This file is provided under a dual BSD/GPLv2 license. When using or
1579     * redistributing this file, you may do so under either license.
1580     @@ -350,7 +350,9 @@ void hfi1_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr,
1581    
1582     void _hfi1_do_send(struct work_struct *work);
1583    
1584     -void hfi1_do_send(struct rvt_qp *qp);
1585     +void hfi1_do_send_from_rvt(struct rvt_qp *qp);
1586     +
1587     +void hfi1_do_send(struct rvt_qp *qp, bool in_thread);
1588    
1589     void hfi1_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
1590     enum ib_wc_status status);
1591     diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
1592     index fba94df28cf1..c7e6d137c162 100644
1593     --- a/drivers/infiniband/hw/mlx4/main.c
1594     +++ b/drivers/infiniband/hw/mlx4/main.c
1595     @@ -2941,6 +2941,7 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
1596     mlx4_ib_delete_counters_table(ibdev, &ibdev->counters_table[i]);
1597    
1598     err_map:
1599     + mlx4_ib_free_eqs(dev, ibdev);
1600     iounmap(ibdev->uar_map);
1601    
1602     err_uar:
1603     diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
1604     index e010fe459e67..8772d88d324d 100644
1605     --- a/drivers/infiniband/hw/mlx4/mcg.c
1606     +++ b/drivers/infiniband/hw/mlx4/mcg.c
1607     @@ -1102,7 +1102,8 @@ static void _mlx4_ib_mcg_port_cleanup(struct mlx4_ib_demux_ctx *ctx, int destroy
1608     while ((p = rb_first(&ctx->mcg_table)) != NULL) {
1609     group = rb_entry(p, struct mcast_group, node);
1610     if (atomic_read(&group->refcount))
1611     - mcg_warn_group(group, "group refcount %d!!! (pointer %p)\n", atomic_read(&group->refcount), group);
1612     + mcg_debug_group(group, "group refcount %d!!! (pointer %p)\n",
1613     + atomic_read(&group->refcount), group);
1614    
1615     force_clean_group(group);
1616     }
1617     diff --git a/drivers/infiniband/ulp/ipoib/ipoib_fs.c b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
1618     index 6bd5740e2691..09396bd7b02d 100644
1619     --- a/drivers/infiniband/ulp/ipoib/ipoib_fs.c
1620     +++ b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
1621     @@ -281,8 +281,11 @@ void ipoib_delete_debug_files(struct net_device *dev)
1622     {
1623     struct ipoib_dev_priv *priv = netdev_priv(dev);
1624    
1625     + WARN_ONCE(!priv->mcg_dentry, "null mcg debug file\n");
1626     + WARN_ONCE(!priv->path_dentry, "null path debug file\n");
1627     debugfs_remove(priv->mcg_dentry);
1628     debugfs_remove(priv->path_dentry);
1629     + priv->mcg_dentry = priv->path_dentry = NULL;
1630     }
1631    
1632     int ipoib_register_debugfs(void)
1633     diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
1634     index d1d3fb7a6127..b319cc26c9a7 100644
1635     --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
1636     +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
1637     @@ -108,6 +108,33 @@ static struct ib_client ipoib_client = {
1638     .get_net_dev_by_params = ipoib_get_net_dev_by_params,
1639     };
1640    
1641     +#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
1642     +static int ipoib_netdev_event(struct notifier_block *this,
1643     + unsigned long event, void *ptr)
1644     +{
1645     + struct netdev_notifier_info *ni = ptr;
1646     + struct net_device *dev = ni->dev;
1647     +
1648     + if (dev->netdev_ops->ndo_open != ipoib_open)
1649     + return NOTIFY_DONE;
1650     +
1651     + switch (event) {
1652     + case NETDEV_REGISTER:
1653     + ipoib_create_debug_files(dev);
1654     + break;
1655     + case NETDEV_CHANGENAME:
1656     + ipoib_delete_debug_files(dev);
1657     + ipoib_create_debug_files(dev);
1658     + break;
1659     + case NETDEV_UNREGISTER:
1660     + ipoib_delete_debug_files(dev);
1661     + break;
1662     + }
1663     +
1664     + return NOTIFY_DONE;
1665     +}
1666     +#endif
1667     +
1668     int ipoib_open(struct net_device *dev)
1669     {
1670     struct ipoib_dev_priv *priv = netdev_priv(dev);
1671     @@ -1674,8 +1701,6 @@ void ipoib_dev_cleanup(struct net_device *dev)
1672    
1673     ASSERT_RTNL();
1674    
1675     - ipoib_delete_debug_files(dev);
1676     -
1677     /* Delete any child interfaces first */
1678     list_for_each_entry_safe(cpriv, tcpriv, &priv->child_intfs, list) {
1679     /* Stop GC on child */
1680     @@ -2090,8 +2115,6 @@ static struct net_device *ipoib_add_port(const char *format,
1681     goto register_failed;
1682     }
1683    
1684     - ipoib_create_debug_files(priv->dev);
1685     -
1686     if (ipoib_cm_add_mode_attr(priv->dev))
1687     goto sysfs_failed;
1688     if (ipoib_add_pkey_attr(priv->dev))
1689     @@ -2106,7 +2129,6 @@ static struct net_device *ipoib_add_port(const char *format,
1690     return priv->dev;
1691    
1692     sysfs_failed:
1693     - ipoib_delete_debug_files(priv->dev);
1694     unregister_netdev(priv->dev);
1695    
1696     register_failed:
1697     @@ -2191,6 +2213,12 @@ static void ipoib_remove_one(struct ib_device *device, void *client_data)
1698     kfree(dev_list);
1699     }
1700    
1701     +#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
1702     +static struct notifier_block ipoib_netdev_notifier = {
1703     + .notifier_call = ipoib_netdev_event,
1704     +};
1705     +#endif
1706     +
1707     static int __init ipoib_init_module(void)
1708     {
1709     int ret;
1710     @@ -2243,6 +2271,9 @@ static int __init ipoib_init_module(void)
1711     if (ret)
1712     goto err_client;
1713    
1714     +#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
1715     + register_netdevice_notifier(&ipoib_netdev_notifier);
1716     +#endif
1717     return 0;
1718    
1719     err_client:
1720     @@ -2260,6 +2291,9 @@ static int __init ipoib_init_module(void)
1721    
1722     static void __exit ipoib_cleanup_module(void)
1723     {
1724     +#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
1725     + unregister_netdevice_notifier(&ipoib_netdev_notifier);
1726     +#endif
1727     ipoib_netlink_fini();
1728     ib_unregister_client(&ipoib_client);
1729     ib_sa_unregister_client(&ipoib_sa_client);
1730     diff --git a/drivers/infiniband/ulp/ipoib/ipoib_vlan.c b/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
1731     index 3e10e3dac2e7..e543bc745f34 100644
1732     --- a/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
1733     +++ b/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
1734     @@ -86,8 +86,6 @@ int __ipoib_vlan_add(struct ipoib_dev_priv *ppriv, struct ipoib_dev_priv *priv,
1735     goto register_failed;
1736     }
1737    
1738     - ipoib_create_debug_files(priv->dev);
1739     -
1740     /* RTNL childs don't need proprietary sysfs entries */
1741     if (type == IPOIB_LEGACY_CHILD) {
1742     if (ipoib_cm_add_mode_attr(priv->dev))
1743     @@ -108,7 +106,6 @@ int __ipoib_vlan_add(struct ipoib_dev_priv *ppriv, struct ipoib_dev_priv *priv,
1744    
1745     sysfs_failed:
1746     result = -ENOMEM;
1747     - ipoib_delete_debug_files(priv->dev);
1748     unregister_netdevice(priv->dev);
1749    
1750     register_failed:
1751     diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
1752     index 389a3637ffcc..b8f3d77d3b5c 100644
1753     --- a/drivers/md/dm-crypt.c
1754     +++ b/drivers/md/dm-crypt.c
1755     @@ -1649,12 +1649,16 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
1756    
1757     static int crypt_wipe_key(struct crypt_config *cc)
1758     {
1759     + int r;
1760     +
1761     clear_bit(DM_CRYPT_KEY_VALID, &cc->flags);
1762     - memset(&cc->key, 0, cc->key_size * sizeof(u8));
1763     + get_random_bytes(&cc->key, cc->key_size);
1764     kzfree(cc->key_string);
1765     cc->key_string = NULL;
1766     + r = crypt_setkey(cc);
1767     + memset(&cc->key, 0, cc->key_size * sizeof(u8));
1768    
1769     - return crypt_setkey(cc);
1770     + return r;
1771     }
1772    
1773     static void crypt_dtr(struct dm_target *ti)
1774     diff --git a/drivers/md/dm-era-target.c b/drivers/md/dm-era-target.c
1775     index 9fab33b113c4..68d4084377ad 100644
1776     --- a/drivers/md/dm-era-target.c
1777     +++ b/drivers/md/dm-era-target.c
1778     @@ -961,15 +961,15 @@ static int metadata_commit(struct era_metadata *md)
1779     }
1780     }
1781    
1782     - r = save_sm_root(md);
1783     + r = dm_tm_pre_commit(md->tm);
1784     if (r) {
1785     - DMERR("%s: save_sm_root failed", __func__);
1786     + DMERR("%s: pre commit failed", __func__);
1787     return r;
1788     }
1789    
1790     - r = dm_tm_pre_commit(md->tm);
1791     + r = save_sm_root(md);
1792     if (r) {
1793     - DMERR("%s: pre commit failed", __func__);
1794     + DMERR("%s: save_sm_root failed", __func__);
1795     return r;
1796     }
1797    
1798     diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
1799     index 0b081d170087..505b9f6b4a47 100644
1800     --- a/drivers/md/dm-rq.c
1801     +++ b/drivers/md/dm-rq.c
1802     @@ -810,10 +810,14 @@ int dm_mq_init_request_queue(struct mapped_device *md, struct dm_table *t)
1803     dm_init_md_queue(md);
1804    
1805     /* backfill 'mq' sysfs registration normally done in blk_register_queue */
1806     - blk_mq_register_dev(disk_to_dev(md->disk), q);
1807     + err = blk_mq_register_dev(disk_to_dev(md->disk), q);
1808     + if (err)
1809     + goto out_cleanup_queue;
1810    
1811     return 0;
1812    
1813     +out_cleanup_queue:
1814     + blk_cleanup_queue(q);
1815     out_tag_set:
1816     blk_mq_free_tag_set(md->tag_set);
1817     out_kfree_tag_set:
1818     diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
1819     index 2b266a2b5035..5742e5eb0704 100644
1820     --- a/drivers/md/dm-thin.c
1821     +++ b/drivers/md/dm-thin.c
1822     @@ -1069,6 +1069,7 @@ static void passdown_endio(struct bio *bio)
1823     * to unmap (we ignore err).
1824     */
1825     queue_passdown_pt2(bio->bi_private);
1826     + bio_put(bio);
1827     }
1828    
1829     static void process_prepared_discard_passdown_pt1(struct dm_thin_new_mapping *m)
1830     diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
1831     index a34f58772022..839ead062645 100644
1832     --- a/drivers/md/raid1.c
1833     +++ b/drivers/md/raid1.c
1834     @@ -2222,6 +2222,8 @@ static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio)
1835     (i == r1_bio->read_disk ||
1836     !test_bit(MD_RECOVERY_SYNC, &mddev->recovery))))
1837     continue;
1838     + if (test_bit(Faulty, &conf->mirrors[i].rdev->flags))
1839     + continue;
1840    
1841     bio_set_op_attrs(wbio, REQ_OP_WRITE, 0);
1842     if (test_bit(FailFast, &conf->mirrors[i].rdev->flags))
1843     diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
1844     index 97dd2925ed6e..4b76af2b8715 100644
1845     --- a/drivers/nvdimm/btt_devs.c
1846     +++ b/drivers/nvdimm/btt_devs.c
1847     @@ -314,7 +314,7 @@ int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns)
1848     if (rc < 0) {
1849     struct nd_btt *nd_btt = to_nd_btt(btt_dev);
1850    
1851     - __nd_detach_ndns(btt_dev, &nd_btt->ndns);
1852     + nd_detach_ndns(btt_dev, &nd_btt->ndns);
1853     put_device(btt_dev);
1854     }
1855    
1856     diff --git a/drivers/nvdimm/claim.c b/drivers/nvdimm/claim.c
1857     index ca6d572c48fc..8513c8ac963b 100644
1858     --- a/drivers/nvdimm/claim.c
1859     +++ b/drivers/nvdimm/claim.c
1860     @@ -21,8 +21,13 @@
1861     void __nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns)
1862     {
1863     struct nd_namespace_common *ndns = *_ndns;
1864     + struct nvdimm_bus *nvdimm_bus;
1865    
1866     - lockdep_assert_held(&ndns->dev.mutex);
1867     + if (!ndns)
1868     + return;
1869     +
1870     + nvdimm_bus = walk_to_nvdimm_bus(&ndns->dev);
1871     + lockdep_assert_held(&nvdimm_bus->reconfig_mutex);
1872     dev_WARN_ONCE(dev, ndns->claim != dev, "%s: invalid claim\n", __func__);
1873     ndns->claim = NULL;
1874     *_ndns = NULL;
1875     @@ -37,18 +42,20 @@ void nd_detach_ndns(struct device *dev,
1876     if (!ndns)
1877     return;
1878     get_device(&ndns->dev);
1879     - device_lock(&ndns->dev);
1880     + nvdimm_bus_lock(&ndns->dev);
1881     __nd_detach_ndns(dev, _ndns);
1882     - device_unlock(&ndns->dev);
1883     + nvdimm_bus_unlock(&ndns->dev);
1884     put_device(&ndns->dev);
1885     }
1886    
1887     bool __nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
1888     struct nd_namespace_common **_ndns)
1889     {
1890     + struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&attach->dev);
1891     +
1892     if (attach->claim)
1893     return false;
1894     - lockdep_assert_held(&attach->dev.mutex);
1895     + lockdep_assert_held(&nvdimm_bus->reconfig_mutex);
1896     dev_WARN_ONCE(dev, *_ndns, "%s: invalid claim\n", __func__);
1897     attach->claim = dev;
1898     *_ndns = attach;
1899     @@ -61,9 +68,9 @@ bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
1900     {
1901     bool claimed;
1902    
1903     - device_lock(&attach->dev);
1904     + nvdimm_bus_lock(&attach->dev);
1905     claimed = __nd_attach_ndns(dev, attach, _ndns);
1906     - device_unlock(&attach->dev);
1907     + nvdimm_bus_unlock(&attach->dev);
1908     return claimed;
1909     }
1910    
1911     @@ -114,7 +121,7 @@ static void nd_detach_and_reset(struct device *dev,
1912     struct nd_namespace_common **_ndns)
1913     {
1914     /* detach the namespace and destroy / reset the device */
1915     - nd_detach_ndns(dev, _ndns);
1916     + __nd_detach_ndns(dev, _ndns);
1917     if (is_idle(dev, *_ndns)) {
1918     nd_device_unregister(dev, ND_ASYNC);
1919     } else if (is_nd_btt(dev)) {
1920     @@ -184,7 +191,7 @@ ssize_t nd_namespace_store(struct device *dev,
1921     }
1922    
1923     WARN_ON_ONCE(!is_nvdimm_bus_locked(dev));
1924     - if (!nd_attach_ndns(dev, ndns, _ndns)) {
1925     + if (!__nd_attach_ndns(dev, ndns, _ndns)) {
1926     dev_dbg(dev, "%s already claimed\n",
1927     dev_name(&ndns->dev));
1928     len = -EBUSY;
1929     diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c
1930     index 45fa82cae87c..c1b6556aea6e 100644
1931     --- a/drivers/nvdimm/dax_devs.c
1932     +++ b/drivers/nvdimm/dax_devs.c
1933     @@ -124,7 +124,7 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns)
1934     dev_dbg(dev, "%s: dax: %s\n", __func__,
1935     rc == 0 ? dev_name(dax_dev) : "<none>");
1936     if (rc < 0) {
1937     - __nd_detach_ndns(dax_dev, &nd_pfn->ndns);
1938     + nd_detach_ndns(dax_dev, &nd_pfn->ndns);
1939     put_device(dax_dev);
1940     } else
1941     __nd_device_register(dax_dev);
1942     diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c
1943     index 6c033c9a2f06..335c8175410b 100644
1944     --- a/drivers/nvdimm/pfn_devs.c
1945     +++ b/drivers/nvdimm/pfn_devs.c
1946     @@ -484,7 +484,7 @@ int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns)
1947     dev_dbg(dev, "%s: pfn: %s\n", __func__,
1948     rc == 0 ? dev_name(pfn_dev) : "<none>");
1949     if (rc < 0) {
1950     - __nd_detach_ndns(pfn_dev, &nd_pfn->ndns);
1951     + nd_detach_ndns(pfn_dev, &nd_pfn->ndns);
1952     put_device(pfn_dev);
1953     } else
1954     __nd_device_register(pfn_dev);
1955     @@ -538,7 +538,8 @@ static struct vmem_altmap *__nvdimm_setup_pfn(struct nd_pfn *nd_pfn,
1956     nd_pfn->npfns = le64_to_cpu(pfn_sb->npfns);
1957     altmap = NULL;
1958     } else if (nd_pfn->mode == PFN_MODE_PMEM) {
1959     - nd_pfn->npfns = (resource_size(res) - offset) / PAGE_SIZE;
1960     + nd_pfn->npfns = PFN_SECTION_ALIGN_UP((resource_size(res)
1961     + - offset) / PAGE_SIZE);
1962     if (le64_to_cpu(nd_pfn->pfn_sb->npfns) > nd_pfn->npfns)
1963     dev_info(&nd_pfn->dev,
1964     "number of pfns truncated from %lld to %ld\n",
1965     @@ -625,7 +626,8 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
1966     */
1967     start += start_pad;
1968     size = resource_size(&nsio->res);
1969     - npfns = (size - start_pad - end_trunc - SZ_8K) / SZ_4K;
1970     + npfns = PFN_SECTION_ALIGN_UP((size - start_pad - end_trunc - SZ_8K)
1971     + / PAGE_SIZE);
1972     if (nd_pfn->mode == PFN_MODE_PMEM) {
1973     /*
1974     * vmemmap_populate_hugepages() allocates the memmap array in
1975     diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
1976     index 5b536be5a12e..0fc18262a2bc 100644
1977     --- a/drivers/nvdimm/pmem.c
1978     +++ b/drivers/nvdimm/pmem.c
1979     @@ -388,12 +388,12 @@ static void nd_pmem_shutdown(struct device *dev)
1980    
1981     static void nd_pmem_notify(struct device *dev, enum nvdimm_event event)
1982     {
1983     - struct pmem_device *pmem = dev_get_drvdata(dev);
1984     - struct nd_region *nd_region = to_region(pmem);
1985     + struct nd_region *nd_region;
1986     resource_size_t offset = 0, end_trunc = 0;
1987     struct nd_namespace_common *ndns;
1988     struct nd_namespace_io *nsio;
1989     struct resource res;
1990     + struct badblocks *bb;
1991    
1992     if (event != NVDIMM_REVALIDATE_POISON)
1993     return;
1994     @@ -402,20 +402,33 @@ static void nd_pmem_notify(struct device *dev, enum nvdimm_event event)
1995     struct nd_btt *nd_btt = to_nd_btt(dev);
1996    
1997     ndns = nd_btt->ndns;
1998     - } else if (is_nd_pfn(dev)) {
1999     - struct nd_pfn *nd_pfn = to_nd_pfn(dev);
2000     - struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
2001     + nd_region = to_nd_region(ndns->dev.parent);
2002     + nsio = to_nd_namespace_io(&ndns->dev);
2003     + bb = &nsio->bb;
2004     + } else {
2005     + struct pmem_device *pmem = dev_get_drvdata(dev);
2006    
2007     - ndns = nd_pfn->ndns;
2008     - offset = pmem->data_offset + __le32_to_cpu(pfn_sb->start_pad);
2009     - end_trunc = __le32_to_cpu(pfn_sb->end_trunc);
2010     - } else
2011     - ndns = to_ndns(dev);
2012     + nd_region = to_region(pmem);
2013     + bb = &pmem->bb;
2014     +
2015     + if (is_nd_pfn(dev)) {
2016     + struct nd_pfn *nd_pfn = to_nd_pfn(dev);
2017     + struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
2018     +
2019     + ndns = nd_pfn->ndns;
2020     + offset = pmem->data_offset +
2021     + __le32_to_cpu(pfn_sb->start_pad);
2022     + end_trunc = __le32_to_cpu(pfn_sb->end_trunc);
2023     + } else {
2024     + ndns = to_ndns(dev);
2025     + }
2026     +
2027     + nsio = to_nd_namespace_io(&ndns->dev);
2028     + }
2029    
2030     - nsio = to_nd_namespace_io(&ndns->dev);
2031     res.start = nsio->res.start + offset;
2032     res.end = nsio->res.end - end_trunc;
2033     - nvdimm_badblocks_populate(nd_region, &pmem->bb, &res);
2034     + nvdimm_badblocks_populate(nd_region, bb, &res);
2035     }
2036    
2037     MODULE_ALIAS("pmem");
2038     diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
2039     index b7cb5066d961..378885f4050b 100644
2040     --- a/drivers/nvdimm/region_devs.c
2041     +++ b/drivers/nvdimm/region_devs.c
2042     @@ -968,17 +968,20 @@ EXPORT_SYMBOL_GPL(nvdimm_flush);
2043     */
2044     int nvdimm_has_flush(struct nd_region *nd_region)
2045     {
2046     - struct nd_region_data *ndrd = dev_get_drvdata(&nd_region->dev);
2047     int i;
2048    
2049     /* no nvdimm == flushing capability unknown */
2050     if (nd_region->ndr_mappings == 0)
2051     return -ENXIO;
2052    
2053     - for (i = 0; i < nd_region->ndr_mappings; i++)
2054     - /* flush hints present, flushing required */
2055     - if (ndrd_get_flush_wpq(ndrd, i, 0))
2056     + for (i = 0; i < nd_region->ndr_mappings; i++) {
2057     + struct nd_mapping *nd_mapping = &nd_region->mapping[i];
2058     + struct nvdimm *nvdimm = nd_mapping->nvdimm;
2059     +
2060     + /* flush hints present / available */
2061     + if (nvdimm->num_flush)
2062     return 1;
2063     + }
2064    
2065     /*
2066     * The platform defines dimm devices without hints, assume
2067     diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c
2068     index 70390de66e0e..eb0a095efe9c 100644
2069     --- a/drivers/staging/comedi/drivers/jr3_pci.c
2070     +++ b/drivers/staging/comedi/drivers/jr3_pci.c
2071     @@ -611,7 +611,7 @@ static void jr3_pci_poll_dev(unsigned long data)
2072     s = &dev->subdevices[i];
2073     spriv = s->private;
2074    
2075     - if (now > spriv->next_time_min) {
2076     + if (time_after_eq(now, spriv->next_time_min)) {
2077     struct jr3_pci_poll_delay sub_delay;
2078    
2079     sub_delay = jr3_pci_poll_subdevice(s);
2080     @@ -727,11 +727,12 @@ static int jr3_pci_auto_attach(struct comedi_device *dev,
2081     s->insn_read = jr3_pci_ai_insn_read;
2082    
2083     spriv = jr3_pci_alloc_spriv(dev, s);
2084     - if (spriv) {
2085     - /* Channel specific range and maxdata */
2086     - s->range_table_list = spriv->range_table_list;
2087     - s->maxdata_list = spriv->maxdata_list;
2088     - }
2089     + if (!spriv)
2090     + return -ENOMEM;
2091     +
2092     + /* Channel specific range and maxdata */
2093     + s->range_table_list = spriv->range_table_list;
2094     + s->maxdata_list = spriv->maxdata_list;
2095     }
2096    
2097     /* Reset DSP card */
2098     diff --git a/drivers/staging/gdm724x/gdm_mux.c b/drivers/staging/gdm724x/gdm_mux.c
2099     index 400969170d1c..f03e43b1b5f6 100644
2100     --- a/drivers/staging/gdm724x/gdm_mux.c
2101     +++ b/drivers/staging/gdm724x/gdm_mux.c
2102     @@ -664,9 +664,8 @@ static int __init gdm_usb_mux_init(void)
2103    
2104     static void __exit gdm_usb_mux_exit(void)
2105     {
2106     - unregister_lte_tty_driver();
2107     -
2108     usb_deregister(&gdm_mux_driver);
2109     + unregister_lte_tty_driver();
2110     }
2111    
2112     module_init(gdm_usb_mux_init);
2113     diff --git a/drivers/staging/media/lirc/lirc_sir.c b/drivers/staging/media/lirc/lirc_sir.c
2114     index c6c3de94adaa..edb607a45505 100644
2115     --- a/drivers/staging/media/lirc/lirc_sir.c
2116     +++ b/drivers/staging/media/lirc/lirc_sir.c
2117     @@ -227,6 +227,7 @@ static int init_chrdev(void)
2118     if (!rcdev)
2119     return -ENOMEM;
2120    
2121     + rcdev->input_name = "SIR IrDA port";
2122     rcdev->input_phys = KBUILD_MODNAME "/input0";
2123     rcdev->input_id.bustype = BUS_HOST;
2124     rcdev->input_id.vendor = 0x0001;
2125     @@ -234,6 +235,7 @@ static int init_chrdev(void)
2126     rcdev->input_id.version = 0x0100;
2127     rcdev->tx_ir = sir_tx_ir;
2128     rcdev->allowed_protocols = RC_BIT_ALL_IR_DECODER;
2129     + rcdev->driver_name = KBUILD_MODNAME;
2130     rcdev->map_name = RC_MAP_RC6_MCE;
2131     rcdev->timeout = IR_DEFAULT_TIMEOUT;
2132     rcdev->dev.parent = &sir_ir_dev->dev;
2133     @@ -740,7 +742,13 @@ static int init_sir_ir(void)
2134    
2135     static int sir_ir_probe(struct platform_device *dev)
2136     {
2137     - return 0;
2138     + int retval;
2139     +
2140     + retval = init_chrdev();
2141     + if (retval < 0)
2142     + return retval;
2143     +
2144     + return init_sir_ir();
2145     }
2146    
2147     static int sir_ir_remove(struct platform_device *dev)
2148     @@ -780,18 +788,8 @@ static int __init sir_ir_init(void)
2149     goto pdev_add_fail;
2150     }
2151    
2152     - retval = init_chrdev();
2153     - if (retval < 0)
2154     - goto fail;
2155     -
2156     - retval = init_sir_ir();
2157     - if (retval)
2158     - goto fail;
2159     -
2160     return 0;
2161    
2162     -fail:
2163     - platform_device_del(sir_ir_dev);
2164     pdev_add_fail:
2165     platform_device_put(sir_ir_dev);
2166     pdev_alloc_fail:
2167     diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c
2168     index 1ae6a64c7fd4..dc11a05be8c4 100644
2169     --- a/drivers/staging/vt6656/usbpipe.c
2170     +++ b/drivers/staging/vt6656/usbpipe.c
2171     @@ -47,15 +47,25 @@ int vnt_control_out(struct vnt_private *priv, u8 request, u16 value,
2172     u16 index, u16 length, u8 *buffer)
2173     {
2174     int status = 0;
2175     + u8 *usb_buffer;
2176    
2177     if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
2178     return STATUS_FAILURE;
2179    
2180     mutex_lock(&priv->usb_lock);
2181    
2182     + usb_buffer = kmemdup(buffer, length, GFP_KERNEL);
2183     + if (!usb_buffer) {
2184     + mutex_unlock(&priv->usb_lock);
2185     + return -ENOMEM;
2186     + }
2187     +
2188     status = usb_control_msg(priv->usb,
2189     - usb_sndctrlpipe(priv->usb, 0), request, 0x40, value,
2190     - index, buffer, length, USB_CTL_WAIT);
2191     + usb_sndctrlpipe(priv->usb, 0),
2192     + request, 0x40, value,
2193     + index, usb_buffer, length, USB_CTL_WAIT);
2194     +
2195     + kfree(usb_buffer);
2196    
2197     mutex_unlock(&priv->usb_lock);
2198    
2199     @@ -75,15 +85,28 @@ int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
2200     u16 index, u16 length, u8 *buffer)
2201     {
2202     int status;
2203     + u8 *usb_buffer;
2204    
2205     if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
2206     return STATUS_FAILURE;
2207    
2208     mutex_lock(&priv->usb_lock);
2209    
2210     + usb_buffer = kmalloc(length, GFP_KERNEL);
2211     + if (!usb_buffer) {
2212     + mutex_unlock(&priv->usb_lock);
2213     + return -ENOMEM;
2214     + }
2215     +
2216     status = usb_control_msg(priv->usb,
2217     - usb_rcvctrlpipe(priv->usb, 0), request, 0xc0, value,
2218     - index, buffer, length, USB_CTL_WAIT);
2219     + usb_rcvctrlpipe(priv->usb, 0),
2220     + request, 0xc0, value,
2221     + index, usb_buffer, length, USB_CTL_WAIT);
2222     +
2223     + if (status == length)
2224     + memcpy(buffer, usb_buffer, length);
2225     +
2226     + kfree(usb_buffer);
2227    
2228     mutex_unlock(&priv->usb_lock);
2229    
2230     diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
2231     index 2eebc6215cac..bdf11c9f44a8 100644
2232     --- a/drivers/staging/wilc1000/linux_wlan.c
2233     +++ b/drivers/staging/wilc1000/linux_wlan.c
2234     @@ -1251,11 +1251,12 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
2235     else
2236     strcpy(ndev->name, "p2p%d");
2237    
2238     - vif->idx = wl->vif_num;
2239     vif->wilc = *wilc;
2240     vif->ndev = ndev;
2241     wl->vif[i] = vif;
2242     wl->vif_num = i;
2243     + vif->idx = wl->vif_num;
2244     +
2245     ndev->netdev_ops = &wilc_netdev_ops;
2246    
2247     {
2248     diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
2249     index e3f9ed3690b7..8beed3451346 100644
2250     --- a/drivers/target/iscsi/iscsi_target.c
2251     +++ b/drivers/target/iscsi/iscsi_target.c
2252     @@ -4683,6 +4683,7 @@ int iscsit_release_sessions_for_tpg(struct iscsi_portal_group *tpg, int force)
2253     continue;
2254     }
2255     atomic_set(&sess->session_reinstatement, 1);
2256     + atomic_set(&sess->session_fall_back_to_erl0, 1);
2257     spin_unlock(&sess->conn_lock);
2258    
2259     list_move_tail(&se_sess->sess_list, &free_list);
2260     diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c
2261     index 344e8448869c..96d9c73af1ae 100644
2262     --- a/drivers/target/iscsi/iscsi_target_configfs.c
2263     +++ b/drivers/target/iscsi/iscsi_target_configfs.c
2264     @@ -1528,6 +1528,7 @@ static void lio_tpg_close_session(struct se_session *se_sess)
2265     return;
2266     }
2267     atomic_set(&sess->session_reinstatement, 1);
2268     + atomic_set(&sess->session_fall_back_to_erl0, 1);
2269     spin_unlock(&sess->conn_lock);
2270    
2271     iscsit_stop_time2retain_timer(sess);
2272     diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c
2273     index ad8f3011bdc2..66238477137b 100644
2274     --- a/drivers/target/iscsi/iscsi_target_login.c
2275     +++ b/drivers/target/iscsi/iscsi_target_login.c
2276     @@ -208,6 +208,7 @@ int iscsi_check_for_session_reinstatement(struct iscsi_conn *conn)
2277     initiatorname_param->value) &&
2278     (sess_p->sess_ops->SessionType == sessiontype))) {
2279     atomic_set(&sess_p->session_reinstatement, 1);
2280     + atomic_set(&sess_p->session_fall_back_to_erl0, 1);
2281     spin_unlock(&sess_p->conn_lock);
2282     iscsit_inc_session_usage_count(sess_p);
2283     iscsit_stop_time2retain_timer(sess_p);
2284     diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
2285     index 87aa376a1a1a..e00050ccb61d 100644
2286     --- a/drivers/target/target_core_file.c
2287     +++ b/drivers/target/target_core_file.c
2288     @@ -595,8 +595,7 @@ fd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
2289     if (ret < 0)
2290     return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
2291    
2292     - if (ret)
2293     - target_complete_cmd(cmd, SAM_STAT_GOOD);
2294     + target_complete_cmd(cmd, SAM_STAT_GOOD);
2295     return 0;
2296     }
2297    
2298     diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
2299     index c194063f169b..6ec390bb178e 100644
2300     --- a/drivers/target/target_core_sbc.c
2301     +++ b/drivers/target/target_core_sbc.c
2302     @@ -507,8 +507,11 @@ static sense_reason_t compare_and_write_callback(struct se_cmd *cmd, bool succes
2303     * been failed with a non-zero SCSI status.
2304     */
2305     if (cmd->scsi_status) {
2306     - pr_err("compare_and_write_callback: non zero scsi_status:"
2307     + pr_debug("compare_and_write_callback: non zero scsi_status:"
2308     " 0x%02x\n", cmd->scsi_status);
2309     + *post_ret = 1;
2310     + if (cmd->scsi_status == SAM_STAT_CHECK_CONDITION)
2311     + ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
2312     goto out;
2313     }
2314    
2315     diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
2316     index 66b59a15780d..65799575c666 100644
2317     --- a/drivers/tty/pty.c
2318     +++ b/drivers/tty/pty.c
2319     @@ -216,16 +216,11 @@ static int pty_signal(struct tty_struct *tty, int sig)
2320     static void pty_flush_buffer(struct tty_struct *tty)
2321     {
2322     struct tty_struct *to = tty->link;
2323     - struct tty_ldisc *ld;
2324    
2325     if (!to)
2326     return;
2327    
2328     - ld = tty_ldisc_ref(to);
2329     - tty_buffer_flush(to, ld);
2330     - if (ld)
2331     - tty_ldisc_deref(ld);
2332     -
2333     + tty_buffer_flush(to, NULL);
2334     if (to->packet) {
2335     spin_lock_irq(&tty->ctrl_lock);
2336     tty->ctrl_status |= TIOCPKT_FLUSHWRITE;
2337     diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
2338     index b0a377725d63..f2503d862f3a 100644
2339     --- a/drivers/tty/serial/amba-pl011.c
2340     +++ b/drivers/tty/serial/amba-pl011.c
2341     @@ -2470,19 +2470,34 @@ static int __init pl011_early_console_setup(struct earlycon_device *device,
2342     if (!device->port.membase)
2343     return -ENODEV;
2344    
2345     - /* On QDF2400 SOCs affected by Erratum 44, the "qdf2400_e44" must
2346     - * also be specified, e.g. "earlycon=pl011,<address>,qdf2400_e44".
2347     - */
2348     - if (!strcmp(device->options, "qdf2400_e44"))
2349     - device->con->write = qdf2400_e44_early_write;
2350     - else
2351     - device->con->write = pl011_early_write;
2352     + device->con->write = pl011_early_write;
2353    
2354     return 0;
2355     }
2356     OF_EARLYCON_DECLARE(pl011, "arm,pl011", pl011_early_console_setup);
2357     OF_EARLYCON_DECLARE(pl011, "arm,sbsa-uart", pl011_early_console_setup);
2358     -EARLYCON_DECLARE(qdf2400_e44, pl011_early_console_setup);
2359     +
2360     +/*
2361     + * On Qualcomm Datacenter Technologies QDF2400 SOCs affected by
2362     + * Erratum 44, traditional earlycon can be enabled by specifying
2363     + * "earlycon=qdf2400_e44,<address>". Any options are ignored.
2364     + *
2365     + * Alternatively, you can just specify "earlycon", and the early console
2366     + * will be enabled with the information from the SPCR table. In this
2367     + * case, the SPCR code will detect the need for the E44 work-around,
2368     + * and set the console name to "qdf2400_e44".
2369     + */
2370     +static int __init
2371     +qdf2400_e44_early_console_setup(struct earlycon_device *device,
2372     + const char *opt)
2373     +{
2374     + if (!device->port.membase)
2375     + return -ENODEV;
2376     +
2377     + device->con->write = qdf2400_e44_early_write;
2378     + return 0;
2379     +}
2380     +EARLYCON_DECLARE(qdf2400_e44, qdf2400_e44_early_console_setup);
2381    
2382     #else
2383     #define AMBA_CONSOLE NULL
2384     diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
2385     index 6c6f82ad8d5c..e4210b9ad0d3 100644
2386     --- a/drivers/tty/serial/omap-serial.c
2387     +++ b/drivers/tty/serial/omap-serial.c
2388     @@ -1767,7 +1767,8 @@ static int serial_omap_probe(struct platform_device *pdev)
2389     return 0;
2390    
2391     err_add_port:
2392     - pm_runtime_put(&pdev->dev);
2393     + pm_runtime_dont_use_autosuspend(&pdev->dev);
2394     + pm_runtime_put_sync(&pdev->dev);
2395     pm_runtime_disable(&pdev->dev);
2396     pm_qos_remove_request(&up->pm_qos_request);
2397     device_init_wakeup(up->dev, false);
2398     @@ -1780,9 +1781,13 @@ static int serial_omap_remove(struct platform_device *dev)
2399     {
2400     struct uart_omap_port *up = platform_get_drvdata(dev);
2401    
2402     + pm_runtime_get_sync(up->dev);
2403     +
2404     + uart_remove_one_port(&serial_omap_reg, &up->port);
2405     +
2406     + pm_runtime_dont_use_autosuspend(up->dev);
2407     pm_runtime_put_sync(up->dev);
2408     pm_runtime_disable(up->dev);
2409     - uart_remove_one_port(&serial_omap_reg, &up->port);
2410     pm_qos_remove_request(&up->pm_qos_request);
2411     device_init_wakeup(&dev->dev, false);
2412    
2413     diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
2414     index 7a17aedbf902..43c84c9bb904 100644
2415     --- a/drivers/tty/serial/samsung.c
2416     +++ b/drivers/tty/serial/samsung.c
2417     @@ -860,6 +860,7 @@ static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p)
2418     {
2419     struct s3c24xx_uart_dma *dma = p->dma;
2420     unsigned long flags;
2421     + int ret;
2422    
2423     /* Default slave configuration parameters */
2424     dma->rx_conf.direction = DMA_DEV_TO_MEM;
2425     @@ -884,8 +885,8 @@ static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p)
2426    
2427     dma->tx_chan = dma_request_chan(p->port.dev, "tx");
2428     if (IS_ERR(dma->tx_chan)) {
2429     - dma_release_channel(dma->rx_chan);
2430     - return PTR_ERR(dma->tx_chan);
2431     + ret = PTR_ERR(dma->tx_chan);
2432     + goto err_release_rx;
2433     }
2434    
2435     dmaengine_slave_config(dma->tx_chan, &dma->tx_conf);
2436     @@ -894,26 +895,42 @@ static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p)
2437     dma->rx_size = PAGE_SIZE;
2438    
2439     dma->rx_buf = kmalloc(dma->rx_size, GFP_KERNEL);
2440     -
2441     if (!dma->rx_buf) {
2442     - dma_release_channel(dma->rx_chan);
2443     - dma_release_channel(dma->tx_chan);
2444     - return -ENOMEM;
2445     + ret = -ENOMEM;
2446     + goto err_release_tx;
2447     }
2448    
2449     - dma->rx_addr = dma_map_single(dma->rx_chan->device->dev, dma->rx_buf,
2450     + dma->rx_addr = dma_map_single(p->port.dev, dma->rx_buf,
2451     dma->rx_size, DMA_FROM_DEVICE);
2452     + if (dma_mapping_error(p->port.dev, dma->rx_addr)) {
2453     + ret = -EIO;
2454     + goto err_free_rx;
2455     + }
2456    
2457     spin_lock_irqsave(&p->port.lock, flags);
2458    
2459     /* TX buffer */
2460     - dma->tx_addr = dma_map_single(dma->tx_chan->device->dev,
2461     - p->port.state->xmit.buf,
2462     + dma->tx_addr = dma_map_single(p->port.dev, p->port.state->xmit.buf,
2463     UART_XMIT_SIZE, DMA_TO_DEVICE);
2464    
2465     spin_unlock_irqrestore(&p->port.lock, flags);
2466     + if (dma_mapping_error(p->port.dev, dma->tx_addr)) {
2467     + ret = -EIO;
2468     + goto err_unmap_rx;
2469     + }
2470    
2471     return 0;
2472     +
2473     +err_unmap_rx:
2474     + dma_unmap_single(p->port.dev, dma->rx_addr, dma->rx_size,
2475     + DMA_FROM_DEVICE);
2476     +err_free_rx:
2477     + kfree(dma->rx_buf);
2478     +err_release_tx:
2479     + dma_release_channel(dma->tx_chan);
2480     +err_release_rx:
2481     + dma_release_channel(dma->rx_chan);
2482     + return ret;
2483     }
2484    
2485     static void s3c24xx_serial_release_dma(struct s3c24xx_uart_port *p)
2486     @@ -922,7 +939,7 @@ static void s3c24xx_serial_release_dma(struct s3c24xx_uart_port *p)
2487    
2488     if (dma->rx_chan) {
2489     dmaengine_terminate_all(dma->rx_chan);
2490     - dma_unmap_single(dma->rx_chan->device->dev, dma->rx_addr,
2491     + dma_unmap_single(p->port.dev, dma->rx_addr,
2492     dma->rx_size, DMA_FROM_DEVICE);
2493     kfree(dma->rx_buf);
2494     dma_release_channel(dma->rx_chan);
2495     @@ -931,7 +948,7 @@ static void s3c24xx_serial_release_dma(struct s3c24xx_uart_port *p)
2496    
2497     if (dma->tx_chan) {
2498     dmaengine_terminate_all(dma->tx_chan);
2499     - dma_unmap_single(dma->tx_chan->device->dev, dma->tx_addr,
2500     + dma_unmap_single(p->port.dev, dma->tx_addr,
2501     UART_XMIT_SIZE, DMA_TO_DEVICE);
2502     dma_release_channel(dma->tx_chan);
2503     dma->tx_chan = NULL;
2504     diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
2505     index 8fda45a45bd3..08669fee6d7f 100644
2506     --- a/drivers/usb/class/cdc-wdm.c
2507     +++ b/drivers/usb/class/cdc-wdm.c
2508     @@ -58,7 +58,6 @@ MODULE_DEVICE_TABLE (usb, wdm_ids);
2509     #define WDM_SUSPENDING 8
2510     #define WDM_RESETTING 9
2511     #define WDM_OVERFLOW 10
2512     -#define WDM_DRAIN_ON_OPEN 11
2513    
2514     #define WDM_MAX 16
2515    
2516     @@ -182,7 +181,7 @@ static void wdm_in_callback(struct urb *urb)
2517     "nonzero urb status received: -ESHUTDOWN\n");
2518     goto skip_error;
2519     case -EPIPE:
2520     - dev_dbg(&desc->intf->dev,
2521     + dev_err(&desc->intf->dev,
2522     "nonzero urb status received: -EPIPE\n");
2523     break;
2524     default:
2525     @@ -210,25 +209,6 @@ static void wdm_in_callback(struct urb *urb)
2526     desc->reslength = length;
2527     }
2528     }
2529     -
2530     - /*
2531     - * Handling devices with the WDM_DRAIN_ON_OPEN flag set:
2532     - * If desc->resp_count is unset, then the urb was submitted
2533     - * without a prior notification. If the device returned any
2534     - * data, then this implies that it had messages queued without
2535     - * notifying us. Continue reading until that queue is flushed.
2536     - */
2537     - if (!desc->resp_count) {
2538     - if (!length) {
2539     - /* do not propagate the expected -EPIPE */
2540     - desc->rerr = 0;
2541     - goto unlock;
2542     - }
2543     - dev_dbg(&desc->intf->dev, "got %d bytes without notification\n", length);
2544     - set_bit(WDM_RESPONDING, &desc->flags);
2545     - usb_submit_urb(desc->response, GFP_ATOMIC);
2546     - }
2547     -
2548     skip_error:
2549     set_bit(WDM_READ, &desc->flags);
2550     wake_up(&desc->wait);
2551     @@ -243,7 +223,6 @@ static void wdm_in_callback(struct urb *urb)
2552     service_outstanding_interrupt(desc);
2553     }
2554    
2555     -unlock:
2556     spin_unlock(&desc->iuspin);
2557     }
2558    
2559     @@ -686,17 +665,6 @@ static int wdm_open(struct inode *inode, struct file *file)
2560     dev_err(&desc->intf->dev,
2561     "Error submitting int urb - %d\n", rv);
2562     rv = usb_translate_errors(rv);
2563     - } else if (test_bit(WDM_DRAIN_ON_OPEN, &desc->flags)) {
2564     - /*
2565     - * Some devices keep pending messages queued
2566     - * without resending notifications. We must
2567     - * flush the message queue before we can
2568     - * assume a one-to-one relationship between
2569     - * notifications and messages in the queue
2570     - */
2571     - dev_dbg(&desc->intf->dev, "draining queued data\n");
2572     - set_bit(WDM_RESPONDING, &desc->flags);
2573     - rv = usb_submit_urb(desc->response, GFP_KERNEL);
2574     }
2575     } else {
2576     rv = 0;
2577     @@ -803,8 +771,7 @@ static void wdm_rxwork(struct work_struct *work)
2578     /* --- hotplug --- */
2579    
2580     static int wdm_create(struct usb_interface *intf, struct usb_endpoint_descriptor *ep,
2581     - u16 bufsize, int (*manage_power)(struct usb_interface *, int),
2582     - bool drain_on_open)
2583     + u16 bufsize, int (*manage_power)(struct usb_interface *, int))
2584     {
2585     int rv = -ENOMEM;
2586     struct wdm_device *desc;
2587     @@ -891,68 +858,6 @@ static int wdm_create(struct usb_interface *intf, struct usb_endpoint_descriptor
2588    
2589     desc->manage_power = manage_power;
2590    
2591     - /*
2592     - * "drain_on_open" enables a hack to work around a firmware
2593     - * issue observed on network functions, in particular MBIM
2594     - * functions.
2595     - *
2596     - * Quoting section 7 of the CDC-WMC r1.1 specification:
2597     - *
2598     - * "The firmware shall interpret GetEncapsulatedResponse as a
2599     - * request to read response bytes. The firmware shall send
2600     - * the next wLength bytes from the response. The firmware
2601     - * shall allow the host to retrieve data using any number of
2602     - * GetEncapsulatedResponse requests. The firmware shall
2603     - * return a zero- length reply if there are no data bytes
2604     - * available.
2605     - *
2606     - * The firmware shall send ResponseAvailable notifications
2607     - * periodically, using any appropriate algorithm, to inform
2608     - * the host that there is data available in the reply
2609     - * buffer. The firmware is allowed to send ResponseAvailable
2610     - * notifications even if there is no data available, but
2611     - * this will obviously reduce overall performance."
2612     - *
2613     - * These requirements, although they make equally sense, are
2614     - * often not implemented by network functions. Some firmwares
2615     - * will queue data indefinitely, without ever resending a
2616     - * notification. The result is that the driver and firmware
2617     - * loses "syncronization" if the driver ever fails to respond
2618     - * to a single notification, something which easily can happen
2619     - * on release(). When this happens, the driver will appear to
2620     - * never receive notifications for the most current data. Each
2621     - * notification will only cause a single read, which returns
2622     - * the oldest data in the firmware's queue.
2623     - *
2624     - * The "drain_on_open" hack resolves the situation by draining
2625     - * data from the firmware until none is returned, without a
2626     - * prior notification.
2627     - *
2628     - * This will inevitably race with the firmware, risking that
2629     - * we read data from the device before handling the associated
2630     - * notification. To make things worse, some of the devices
2631     - * needing the hack do not implement the "return zero if no
2632     - * data is available" requirement either. Instead they return
2633     - * an error on the subsequent read in this case. This means
2634     - * that "winning" the race can cause an unexpected EIO to
2635     - * userspace.
2636     - *
2637     - * "winning" the race is more likely on resume() than on
2638     - * open(), and the unexpected error is more harmful in the
2639     - * middle of an open session. The hack is therefore only
2640     - * applied on open(), and not on resume() where it logically
2641     - * would be equally necessary. So we define open() as the only
2642     - * driver <-> device "syncronization point". Should we happen
2643     - * to lose a notification after open(), then syncronization
2644     - * will be lost until release()
2645     - *
2646     - * The hack should not be enabled for CDC WDM devices
2647     - * conforming to the CDC-WMC r1.1 specification. This is
2648     - * ensured by setting drain_on_open to false in wdm_probe().
2649     - */
2650     - if (drain_on_open)
2651     - set_bit(WDM_DRAIN_ON_OPEN, &desc->flags);
2652     -
2653     spin_lock(&wdm_device_list_lock);
2654     list_add(&desc->device_list, &wdm_device_list);
2655     spin_unlock(&wdm_device_list_lock);
2656     @@ -1006,7 +911,7 @@ static int wdm_probe(struct usb_interface *intf, const struct usb_device_id *id)
2657     goto err;
2658     ep = &iface->endpoint[0].desc;
2659    
2660     - rv = wdm_create(intf, ep, maxcom, &wdm_manage_power, false);
2661     + rv = wdm_create(intf, ep, maxcom, &wdm_manage_power);
2662    
2663     err:
2664     return rv;
2665     @@ -1038,7 +943,7 @@ struct usb_driver *usb_cdc_wdm_register(struct usb_interface *intf,
2666     {
2667     int rv = -EINVAL;
2668    
2669     - rv = wdm_create(intf, ep, bufsize, manage_power, true);
2670     + rv = wdm_create(intf, ep, bufsize, manage_power);
2671     if (rv < 0)
2672     goto err;
2673    
2674     diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
2675     index cdee5130638b..eb87a259d55c 100644
2676     --- a/drivers/usb/core/driver.c
2677     +++ b/drivers/usb/core/driver.c
2678     @@ -1331,6 +1331,24 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
2679     */
2680     if (udev->parent && !PMSG_IS_AUTO(msg))
2681     status = 0;
2682     +
2683     + /*
2684     + * If the device is inaccessible, don't try to resume
2685     + * suspended interfaces and just return the error.
2686     + */
2687     + if (status && status != -EBUSY) {
2688     + int err;
2689     + u16 devstat;
2690     +
2691     + err = usb_get_status(udev, USB_RECIP_DEVICE, 0,
2692     + &devstat);
2693     + if (err) {
2694     + dev_err(&udev->dev,
2695     + "Failed to suspend device, error %d\n",
2696     + status);
2697     + goto done;
2698     + }
2699     + }
2700     }
2701    
2702     /* If the suspend failed, resume interfaces that did get suspended */
2703     @@ -1763,6 +1781,9 @@ static int autosuspend_check(struct usb_device *udev)
2704     int w, i;
2705     struct usb_interface *intf;
2706    
2707     + if (udev->state == USB_STATE_NOTATTACHED)
2708     + return -ENODEV;
2709     +
2710     /* Fail if autosuspend is disabled, or any interfaces are in use, or
2711     * any interface drivers require remote wakeup but it isn't available.
2712     */
2713     diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
2714     index e26bd5e773ad..87ad6b6bfee8 100644
2715     --- a/drivers/usb/core/file.c
2716     +++ b/drivers/usb/core/file.c
2717     @@ -29,6 +29,7 @@
2718     #define MAX_USB_MINORS 256
2719     static const struct file_operations *usb_minors[MAX_USB_MINORS];
2720     static DECLARE_RWSEM(minor_rwsem);
2721     +static DEFINE_MUTEX(init_usb_class_mutex);
2722    
2723     static int usb_open(struct inode *inode, struct file *file)
2724     {
2725     @@ -111,8 +112,9 @@ static void release_usb_class(struct kref *kref)
2726    
2727     static void destroy_usb_class(void)
2728     {
2729     - if (usb_class)
2730     - kref_put(&usb_class->kref, release_usb_class);
2731     + mutex_lock(&init_usb_class_mutex);
2732     + kref_put(&usb_class->kref, release_usb_class);
2733     + mutex_unlock(&init_usb_class_mutex);
2734     }
2735    
2736     int usb_major_init(void)
2737     @@ -173,7 +175,10 @@ int usb_register_dev(struct usb_interface *intf,
2738     if (intf->minor >= 0)
2739     return -EADDRINUSE;
2740    
2741     + mutex_lock(&init_usb_class_mutex);
2742     retval = init_usb_class();
2743     + mutex_unlock(&init_usb_class_mutex);
2744     +
2745     if (retval)
2746     return retval;
2747    
2748     diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
2749     index 5286bf67869a..9dca59ef18b3 100644
2750     --- a/drivers/usb/core/hub.c
2751     +++ b/drivers/usb/core/hub.c
2752     @@ -1066,6 +1066,9 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
2753    
2754     portstatus = portchange = 0;
2755     status = hub_port_status(hub, port1, &portstatus, &portchange);
2756     + if (status)
2757     + goto abort;
2758     +
2759     if (udev || (portstatus & USB_PORT_STAT_CONNECTION))
2760     dev_dbg(&port_dev->dev, "status %04x change %04x\n",
2761     portstatus, portchange);
2762     @@ -1198,7 +1201,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
2763    
2764     /* Scan all ports that need attention */
2765     kick_hub_wq(hub);
2766     -
2767     + abort:
2768     if (type == HUB_INIT2 || type == HUB_INIT3) {
2769     /* Allow autosuspend if it was suppressed */
2770     disconnected:
2771     @@ -2084,6 +2087,12 @@ void usb_disconnect(struct usb_device **pdev)
2772     dev_info(&udev->dev, "USB disconnect, device number %d\n",
2773     udev->devnum);
2774    
2775     + /*
2776     + * Ensure that the pm runtime code knows that the USB device
2777     + * is in the process of being disconnected.
2778     + */
2779     + pm_runtime_barrier(&udev->dev);
2780     +
2781     usb_lock_device(udev);
2782    
2783     hub_disconnect_children(udev);
2784     diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
2785     index 8ad203296079..f3ee80ece682 100644
2786     --- a/drivers/usb/gadget/Kconfig
2787     +++ b/drivers/usb/gadget/Kconfig
2788     @@ -460,6 +460,7 @@ config USB_CONFIGFS_F_TCM
2789     choice
2790     tristate "USB Gadget Drivers"
2791     default USB_ETH
2792     + optional
2793     help
2794     A Linux "Gadget Driver" talks to the USB Peripheral Controller
2795     driver through the abstract "gadget" API. Some other operating
2796     diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
2797     index ba1853f4e407..3f8f28f6fa94 100644
2798     --- a/drivers/usb/host/xhci-mem.c
2799     +++ b/drivers/usb/host/xhci-mem.c
2800     @@ -1502,6 +1502,17 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
2801     */
2802     max_esit_payload = xhci_get_max_esit_payload(udev, ep);
2803     interval = xhci_get_endpoint_interval(udev, ep);
2804     +
2805     + /* Periodic endpoint bInterval limit quirk */
2806     + if (usb_endpoint_xfer_int(&ep->desc) ||
2807     + usb_endpoint_xfer_isoc(&ep->desc)) {
2808     + if ((xhci->quirks & XHCI_LIMIT_ENDPOINT_INTERVAL_7) &&
2809     + udev->speed >= USB_SPEED_HIGH &&
2810     + interval >= 7) {
2811     + interval = 6;
2812     + }
2813     + }
2814     +
2815     mult = xhci_get_endpoint_mult(udev, ep);
2816     max_packet = usb_endpoint_maxp(&ep->desc);
2817     max_burst = xhci_get_endpoint_max_burst(udev, ep);
2818     @@ -2480,7 +2491,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2819     (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) |
2820     xhci->cmd_ring->cycle_state;
2821     xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2822     - "// Setting command ring address to 0x%x", val);
2823     + "// Setting command ring address to 0x%016llx", val_64);
2824     xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
2825     xhci_dbg_cmd_ptrs(xhci);
2826    
2827     diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
2828     index fc99f51d12e1..7b86508ac8cf 100644
2829     --- a/drivers/usb/host/xhci-pci.c
2830     +++ b/drivers/usb/host/xhci-pci.c
2831     @@ -199,6 +199,9 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
2832     pdev->device == 0x1042)
2833     xhci->quirks |= XHCI_BROKEN_STREAMS;
2834    
2835     + if (pdev->vendor == PCI_VENDOR_ID_TI && pdev->device == 0x8241)
2836     + xhci->quirks |= XHCI_LIMIT_ENDPOINT_INTERVAL_7;
2837     +
2838     if (xhci->quirks & XHCI_RESET_ON_RESUME)
2839     xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
2840     "QUIRK: Resetting on resume");
2841     diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
2842     index da3eb695fe54..2496bd6304ca 100644
2843     --- a/drivers/usb/host/xhci.h
2844     +++ b/drivers/usb/host/xhci.h
2845     @@ -1818,6 +1818,7 @@ struct xhci_hcd {
2846     #define XHCI_MISSING_CAS (1 << 24)
2847     /* For controller with a broken Port Disable implementation */
2848     #define XHCI_BROKEN_PORT_PED (1 << 25)
2849     +#define XHCI_LIMIT_ENDPOINT_INTERVAL_7 (1 << 26)
2850    
2851     unsigned int num_active_eps;
2852     unsigned int limit_active_eps;
2853     diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
2854     index 17c081068257..26ae5d1a2a4e 100644
2855     --- a/drivers/usb/misc/usbtest.c
2856     +++ b/drivers/usb/misc/usbtest.c
2857     @@ -159,6 +159,7 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
2858     case USB_ENDPOINT_XFER_INT:
2859     if (dev->info->intr)
2860     goto try_intr;
2861     + continue;
2862     case USB_ENDPOINT_XFER_ISOC:
2863     if (dev->info->iso)
2864     goto try_iso;
2865     diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
2866     index c540de15aad2..03e6319b6d1c 100644
2867     --- a/drivers/usb/serial/ftdi_sio.c
2868     +++ b/drivers/usb/serial/ftdi_sio.c
2869     @@ -873,6 +873,7 @@ static const struct usb_device_id id_table_combined[] = {
2870     { USB_DEVICE_AND_INTERFACE_INFO(MICROCHIP_VID, MICROCHIP_USB_BOARD_PID,
2871     USB_CLASS_VENDOR_SPEC,
2872     USB_SUBCLASS_VENDOR_SPEC, 0x00) },
2873     + { USB_DEVICE_INTERFACE_NUMBER(ACTEL_VID, MICROSEMI_ARROW_SF2PLUS_BOARD_PID, 2) },
2874     { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) },
2875     { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID),
2876     .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
2877     diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
2878     index 48ee04c94a75..71fb9e59db71 100644
2879     --- a/drivers/usb/serial/ftdi_sio_ids.h
2880     +++ b/drivers/usb/serial/ftdi_sio_ids.h
2881     @@ -873,6 +873,12 @@
2882     #define FIC_VID 0x1457
2883     #define FIC_NEO1973_DEBUG_PID 0x5118
2884    
2885     +/*
2886     + * Actel / Microsemi
2887     + */
2888     +#define ACTEL_VID 0x1514
2889     +#define MICROSEMI_ARROW_SF2PLUS_BOARD_PID 0x2008
2890     +
2891     /* Olimex */
2892     #define OLIMEX_VID 0x15BA
2893     #define OLIMEX_ARM_USB_OCD_PID 0x0003
2894     diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
2895     index 32d2633092a3..a8a079ba9477 100644
2896     --- a/drivers/vfio/vfio_iommu_type1.c
2897     +++ b/drivers/vfio/vfio_iommu_type1.c
2898     @@ -246,69 +246,46 @@ static int vfio_iova_put_vfio_pfn(struct vfio_dma *dma, struct vfio_pfn *vpfn)
2899     return ret;
2900     }
2901    
2902     -struct vwork {
2903     - struct mm_struct *mm;
2904     - long npage;
2905     - struct work_struct work;
2906     -};
2907     -
2908     -/* delayed decrement/increment for locked_vm */
2909     -static void vfio_lock_acct_bg(struct work_struct *work)
2910     -{
2911     - struct vwork *vwork = container_of(work, struct vwork, work);
2912     - struct mm_struct *mm;
2913     -
2914     - mm = vwork->mm;
2915     - down_write(&mm->mmap_sem);
2916     - mm->locked_vm += vwork->npage;
2917     - up_write(&mm->mmap_sem);
2918     - mmput(mm);
2919     - kfree(vwork);
2920     -}
2921     -
2922     -static void vfio_lock_acct(struct task_struct *task, long npage)
2923     +static int vfio_lock_acct(struct task_struct *task, long npage, bool *lock_cap)
2924     {
2925     - struct vwork *vwork;
2926     struct mm_struct *mm;
2927     bool is_current;
2928     + int ret;
2929    
2930     if (!npage)
2931     - return;
2932     + return 0;
2933    
2934     is_current = (task->mm == current->mm);
2935    
2936     mm = is_current ? task->mm : get_task_mm(task);
2937     if (!mm)
2938     - return; /* process exited */
2939     + return -ESRCH; /* process exited */
2940    
2941     - if (down_write_trylock(&mm->mmap_sem)) {
2942     - mm->locked_vm += npage;
2943     - up_write(&mm->mmap_sem);
2944     - if (!is_current)
2945     - mmput(mm);
2946     - return;
2947     - }
2948     + ret = down_write_killable(&mm->mmap_sem);
2949     + if (!ret) {
2950     + if (npage > 0) {
2951     + if (lock_cap ? !*lock_cap :
2952     + !has_capability(task, CAP_IPC_LOCK)) {
2953     + unsigned long limit;
2954     +
2955     + limit = task_rlimit(task,
2956     + RLIMIT_MEMLOCK) >> PAGE_SHIFT;
2957     +
2958     + if (mm->locked_vm + npage > limit)
2959     + ret = -ENOMEM;
2960     + }
2961     + }
2962     +
2963     + if (!ret)
2964     + mm->locked_vm += npage;
2965    
2966     - if (is_current) {
2967     - mm = get_task_mm(task);
2968     - if (!mm)
2969     - return;
2970     + up_write(&mm->mmap_sem);
2971     }
2972    
2973     - /*
2974     - * Couldn't get mmap_sem lock, so must setup to update
2975     - * mm->locked_vm later. If locked_vm were atomic, we
2976     - * wouldn't need this silliness
2977     - */
2978     - vwork = kmalloc(sizeof(struct vwork), GFP_KERNEL);
2979     - if (WARN_ON(!vwork)) {
2980     + if (!is_current)
2981     mmput(mm);
2982     - return;
2983     - }
2984     - INIT_WORK(&vwork->work, vfio_lock_acct_bg);
2985     - vwork->mm = mm;
2986     - vwork->npage = npage;
2987     - schedule_work(&vwork->work);
2988     +
2989     + return ret;
2990     }
2991    
2992     /*
2993     @@ -405,7 +382,7 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,
2994     static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
2995     long npage, unsigned long *pfn_base)
2996     {
2997     - unsigned long limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
2998     + unsigned long pfn = 0, limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
2999     bool lock_cap = capable(CAP_IPC_LOCK);
3000     long ret, pinned = 0, lock_acct = 0;
3001     bool rsvd;
3002     @@ -442,8 +419,6 @@ static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
3003     /* Lock all the consecutive pages from pfn_base */
3004     for (vaddr += PAGE_SIZE, iova += PAGE_SIZE; pinned < npage;
3005     pinned++, vaddr += PAGE_SIZE, iova += PAGE_SIZE) {
3006     - unsigned long pfn = 0;
3007     -
3008     ret = vaddr_get_pfn(current->mm, vaddr, dma->prot, &pfn);
3009     if (ret)
3010     break;
3011     @@ -460,14 +435,25 @@ static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
3012     put_pfn(pfn, dma->prot);
3013     pr_warn("%s: RLIMIT_MEMLOCK (%ld) exceeded\n",
3014     __func__, limit << PAGE_SHIFT);
3015     - break;
3016     + ret = -ENOMEM;
3017     + goto unpin_out;
3018     }
3019     lock_acct++;
3020     }
3021     }
3022    
3023     out:
3024     - vfio_lock_acct(current, lock_acct);
3025     + ret = vfio_lock_acct(current, lock_acct, &lock_cap);
3026     +
3027     +unpin_out:
3028     + if (ret) {
3029     + if (!rsvd) {
3030     + for (pfn = *pfn_base ; pinned ; pfn++, pinned--)
3031     + put_pfn(pfn, dma->prot);
3032     + }
3033     +
3034     + return ret;
3035     + }
3036    
3037     return pinned;
3038     }
3039     @@ -488,7 +474,7 @@ static long vfio_unpin_pages_remote(struct vfio_dma *dma, dma_addr_t iova,
3040     }
3041    
3042     if (do_accounting)
3043     - vfio_lock_acct(dma->task, locked - unlocked);
3044     + vfio_lock_acct(dma->task, locked - unlocked, NULL);
3045    
3046     return unlocked;
3047     }
3048     @@ -522,8 +508,14 @@ static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
3049     goto pin_page_exit;
3050     }
3051    
3052     - if (!rsvd && do_accounting)
3053     - vfio_lock_acct(dma->task, 1);
3054     + if (!rsvd && do_accounting) {
3055     + ret = vfio_lock_acct(dma->task, 1, &lock_cap);
3056     + if (ret) {
3057     + put_pfn(*pfn_base, dma->prot);
3058     + goto pin_page_exit;
3059     + }
3060     + }
3061     +
3062     ret = 1;
3063    
3064     pin_page_exit:
3065     @@ -543,7 +535,7 @@ static int vfio_unpin_page_external(struct vfio_dma *dma, dma_addr_t iova,
3066     unlocked = vfio_iova_put_vfio_pfn(dma, vpfn);
3067    
3068     if (do_accounting)
3069     - vfio_lock_acct(dma->task, -unlocked);
3070     + vfio_lock_acct(dma->task, -unlocked, NULL);
3071    
3072     return unlocked;
3073     }
3074     @@ -740,7 +732,7 @@ static long vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma,
3075    
3076     dma->iommu_mapped = false;
3077     if (do_accounting) {
3078     - vfio_lock_acct(dma->task, -unlocked);
3079     + vfio_lock_acct(dma->task, -unlocked, NULL);
3080     return 0;
3081     }
3082     return unlocked;
3083     @@ -1382,7 +1374,7 @@ static void vfio_iommu_unmap_unpin_reaccount(struct vfio_iommu *iommu)
3084     if (!is_invalid_reserved_pfn(vpfn->pfn))
3085     locked++;
3086     }
3087     - vfio_lock_acct(dma->task, locked - unlocked);
3088     + vfio_lock_acct(dma->task, locked - unlocked, NULL);
3089     }
3090     }
3091    
3092     diff --git a/fs/block_dev.c b/fs/block_dev.c
3093     index 56039dfbc674..c2a7ec8e9c03 100644
3094     --- a/fs/block_dev.c
3095     +++ b/fs/block_dev.c
3096     @@ -103,12 +103,11 @@ void invalidate_bdev(struct block_device *bdev)
3097     {
3098     struct address_space *mapping = bdev->bd_inode->i_mapping;
3099    
3100     - if (mapping->nrpages == 0)
3101     - return;
3102     -
3103     - invalidate_bh_lrus();
3104     - lru_add_drain_all(); /* make sure all lru add caches are flushed */
3105     - invalidate_mapping_pages(mapping, 0, -1);
3106     + if (mapping->nrpages) {
3107     + invalidate_bh_lrus();
3108     + lru_add_drain_all(); /* make sure all lru add caches are flushed */
3109     + invalidate_mapping_pages(mapping, 0, -1);
3110     + }
3111     /* 99% of the time, we don't need to flush the cleancache on the bdev.
3112     * But, for the strange corners, lets be cautious
3113     */
3114     diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
3115     index febc28f9e2c2..75267cdd5dfd 100644
3116     --- a/fs/ceph/xattr.c
3117     +++ b/fs/ceph/xattr.c
3118     @@ -392,6 +392,7 @@ static int __set_xattr(struct ceph_inode_info *ci,
3119    
3120     if (update_xattr) {
3121     int err = 0;
3122     +
3123     if (xattr && (flags & XATTR_CREATE))
3124     err = -EEXIST;
3125     else if (!xattr && (flags & XATTR_REPLACE))
3126     @@ -399,12 +400,14 @@ static int __set_xattr(struct ceph_inode_info *ci,
3127     if (err) {
3128     kfree(name);
3129     kfree(val);
3130     + kfree(*newxattr);
3131     return err;
3132     }
3133     if (update_xattr < 0) {
3134     if (xattr)
3135     __remove_xattr(ci, xattr);
3136     kfree(name);
3137     + kfree(*newxattr);
3138     return 0;
3139     }
3140     }
3141     diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
3142     index 02b071bf3732..a0b3e7d1be48 100644
3143     --- a/fs/cifs/cifs_unicode.c
3144     +++ b/fs/cifs/cifs_unicode.c
3145     @@ -83,6 +83,9 @@ convert_sfm_char(const __u16 src_char, char *target)
3146     case SFM_COLON:
3147     *target = ':';
3148     break;
3149     + case SFM_DOUBLEQUOTE:
3150     + *target = '"';
3151     + break;
3152     case SFM_ASTERISK:
3153     *target = '*';
3154     break;
3155     @@ -418,6 +421,9 @@ static __le16 convert_to_sfm_char(char src_char, bool end_of_string)
3156     case ':':
3157     dest_char = cpu_to_le16(SFM_COLON);
3158     break;
3159     + case '"':
3160     + dest_char = cpu_to_le16(SFM_DOUBLEQUOTE);
3161     + break;
3162     case '*':
3163     dest_char = cpu_to_le16(SFM_ASTERISK);
3164     break;
3165     diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
3166     index 3d7298cc0aeb..8a79a34e66b8 100644
3167     --- a/fs/cifs/cifs_unicode.h
3168     +++ b/fs/cifs/cifs_unicode.h
3169     @@ -57,6 +57,7 @@
3170     * not conflict (although almost does) with the mapping above.
3171     */
3172    
3173     +#define SFM_DOUBLEQUOTE ((__u16) 0xF020)
3174     #define SFM_ASTERISK ((__u16) 0xF021)
3175     #define SFM_QUESTION ((__u16) 0xF025)
3176     #define SFM_COLON ((__u16) 0xF022)
3177     @@ -64,8 +65,8 @@
3178     #define SFM_LESSTHAN ((__u16) 0xF023)
3179     #define SFM_PIPE ((__u16) 0xF027)
3180     #define SFM_SLASH ((__u16) 0xF026)
3181     -#define SFM_PERIOD ((__u16) 0xF028)
3182     -#define SFM_SPACE ((__u16) 0xF029)
3183     +#define SFM_SPACE ((__u16) 0xF028)
3184     +#define SFM_PERIOD ((__u16) 0xF029)
3185    
3186     /*
3187     * Mapping mechanism to use when one of the seven reserved characters is
3188     diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
3189     index dd3f5fabfdf6..aa553d0b58db 100644
3190     --- a/fs/cifs/cifsfs.c
3191     +++ b/fs/cifs/cifsfs.c
3192     @@ -87,6 +87,7 @@ extern mempool_t *cifs_req_poolp;
3193     extern mempool_t *cifs_mid_poolp;
3194    
3195     struct workqueue_struct *cifsiod_wq;
3196     +struct workqueue_struct *cifsoplockd_wq;
3197     __u32 cifs_lock_secret;
3198    
3199     /*
3200     @@ -1369,9 +1370,16 @@ init_cifs(void)
3201     goto out_clean_proc;
3202     }
3203    
3204     + cifsoplockd_wq = alloc_workqueue("cifsoplockd",
3205     + WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
3206     + if (!cifsoplockd_wq) {
3207     + rc = -ENOMEM;
3208     + goto out_destroy_cifsiod_wq;
3209     + }
3210     +
3211     rc = cifs_fscache_register();
3212     if (rc)
3213     - goto out_destroy_wq;
3214     + goto out_destroy_cifsoplockd_wq;
3215    
3216     rc = cifs_init_inodecache();
3217     if (rc)
3218     @@ -1419,7 +1427,9 @@ init_cifs(void)
3219     cifs_destroy_inodecache();
3220     out_unreg_fscache:
3221     cifs_fscache_unregister();
3222     -out_destroy_wq:
3223     +out_destroy_cifsoplockd_wq:
3224     + destroy_workqueue(cifsoplockd_wq);
3225     +out_destroy_cifsiod_wq:
3226     destroy_workqueue(cifsiod_wq);
3227     out_clean_proc:
3228     cifs_proc_clean();
3229     @@ -1442,6 +1452,7 @@ exit_cifs(void)
3230     cifs_destroy_mids();
3231     cifs_destroy_inodecache();
3232     cifs_fscache_unregister();
3233     + destroy_workqueue(cifsoplockd_wq);
3234     destroy_workqueue(cifsiod_wq);
3235     cifs_proc_clean();
3236     }
3237     diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
3238     index 37f5a41cc50c..17f0e732eedc 100644
3239     --- a/fs/cifs/cifsglob.h
3240     +++ b/fs/cifs/cifsglob.h
3241     @@ -1683,6 +1683,7 @@ void cifs_oplock_break(struct work_struct *work);
3242    
3243     extern const struct slow_work_ops cifs_oplock_break_ops;
3244     extern struct workqueue_struct *cifsiod_wq;
3245     +extern struct workqueue_struct *cifsoplockd_wq;
3246     extern __u32 cifs_lock_secret;
3247    
3248     extern mempool_t *cifs_mid_poolp;
3249     diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
3250     index 5d21f00ae341..205fd94f52fd 100644
3251     --- a/fs/cifs/cifssmb.c
3252     +++ b/fs/cifs/cifssmb.c
3253     @@ -718,6 +718,9 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
3254     if (rc)
3255     return rc;
3256    
3257     + if (server->capabilities & CAP_UNICODE)
3258     + smb->hdr.Flags2 |= SMBFLG2_UNICODE;
3259     +
3260     /* set up echo request */
3261     smb->hdr.Tid = 0xffff;
3262     smb->hdr.WordCount = 1;
3263     diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
3264     index d82467cfb0e2..d95744d8b8ab 100644
3265     --- a/fs/cifs/connect.c
3266     +++ b/fs/cifs/connect.c
3267     @@ -2912,16 +2912,14 @@ match_prepath(struct super_block *sb, struct cifs_mnt_data *mnt_data)
3268     {
3269     struct cifs_sb_info *old = CIFS_SB(sb);
3270     struct cifs_sb_info *new = mnt_data->cifs_sb;
3271     + bool old_set = old->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH;
3272     + bool new_set = new->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH;
3273    
3274     - if (old->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH) {
3275     - if (!(new->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH))
3276     - return 0;
3277     - /* The prepath should be null terminated strings */
3278     - if (strcmp(new->prepath, old->prepath))
3279     - return 0;
3280     -
3281     + if (old_set && new_set && !strcmp(new->prepath, old->prepath))
3282     return 1;
3283     - }
3284     + else if (!old_set && !new_set)
3285     + return 1;
3286     +
3287     return 0;
3288     }
3289    
3290     diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c
3291     index 265c45fe4ea5..76fb0917dc8c 100644
3292     --- a/fs/cifs/ioctl.c
3293     +++ b/fs/cifs/ioctl.c
3294     @@ -74,7 +74,8 @@ static long cifs_ioctl_copychunk(unsigned int xid, struct file *dst_file,
3295    
3296     rc = cifs_file_copychunk_range(xid, src_file.file, 0, dst_file, 0,
3297     src_inode->i_size, 0);
3298     -
3299     + if (rc > 0)
3300     + rc = 0;
3301     out_fput:
3302     fdput(src_file);
3303     out_drop_write:
3304     @@ -208,10 +209,14 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
3305     rc = -EOPNOTSUPP;
3306     break;
3307     case CIFS_IOC_GET_MNT_INFO:
3308     + if (pSMBFile == NULL)
3309     + break;
3310     tcon = tlink_tcon(pSMBFile->tlink);
3311     rc = smb_mnt_get_fsinfo(xid, tcon, (void __user *)arg);
3312     break;
3313     case CIFS_ENUMERATE_SNAPSHOTS:
3314     + if (pSMBFile == NULL)
3315     + break;
3316     if (arg == 0) {
3317     rc = -EINVAL;
3318     goto cifs_ioc_exit;
3319     diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
3320     index d3fb11529ed9..b578c6d09597 100644
3321     --- a/fs/cifs/misc.c
3322     +++ b/fs/cifs/misc.c
3323     @@ -492,7 +492,7 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
3324     CIFS_INODE_DOWNGRADE_OPLOCK_TO_L2,
3325     &pCifsInode->flags);
3326    
3327     - queue_work(cifsiod_wq,
3328     + queue_work(cifsoplockd_wq,
3329     &netfile->oplock_break);
3330     netfile->oplock_break_cancelled = false;
3331    
3332     diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c
3333     index 1a04b3a5beb1..7b08a1446a7f 100644
3334     --- a/fs/cifs/smb2misc.c
3335     +++ b/fs/cifs/smb2misc.c
3336     @@ -499,7 +499,7 @@ smb2_tcon_has_lease(struct cifs_tcon *tcon, struct smb2_lease_break *rsp,
3337     else
3338     cfile->oplock_break_cancelled = true;
3339    
3340     - queue_work(cifsiod_wq, &cfile->oplock_break);
3341     + queue_work(cifsoplockd_wq, &cfile->oplock_break);
3342     kfree(lw);
3343     return true;
3344     }
3345     @@ -643,7 +643,8 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)
3346     CIFS_INODE_DOWNGRADE_OPLOCK_TO_L2,
3347     &cinode->flags);
3348     spin_unlock(&cfile->file_info_lock);
3349     - queue_work(cifsiod_wq, &cfile->oplock_break);
3350     + queue_work(cifsoplockd_wq,
3351     + &cfile->oplock_break);
3352    
3353     spin_unlock(&tcon->open_file_lock);
3354     spin_unlock(&cifs_tcp_ses_lock);
3355     diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
3356     index 152e37f2ad92..c58691834eb2 100644
3357     --- a/fs/cifs/smb2ops.c
3358     +++ b/fs/cifs/smb2ops.c
3359     @@ -942,6 +942,7 @@ smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
3360     }
3361     if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) {
3362     rc = -ERANGE;
3363     + kfree(retbuf);
3364     return rc;
3365     }
3366    
3367     diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
3368     index 02da648041fc..0fd63f0bc440 100644
3369     --- a/fs/cifs/smb2pdu.c
3370     +++ b/fs/cifs/smb2pdu.c
3371     @@ -632,8 +632,12 @@ int smb3_validate_negotiate(const unsigned int xid, struct cifs_tcon *tcon)
3372     }
3373    
3374     if (rsplen != sizeof(struct validate_negotiate_info_rsp)) {
3375     - cifs_dbg(VFS, "invalid size of protocol negotiate response\n");
3376     - return -EIO;
3377     + cifs_dbg(VFS, "invalid protocol negotiate response size: %d\n",
3378     + rsplen);
3379     +
3380     + /* relax check since Mac returns max bufsize allowed on ioctl */
3381     + if (rsplen > CIFSMaxBufSize)
3382     + return -EIO;
3383     }
3384    
3385     /* check validate negotiate info response matches what we got earlier */
3386     @@ -1853,8 +1857,12 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
3387     * than one credit. Windows typically sets this smaller, but for some
3388     * ioctls it may be useful to allow server to send more. No point
3389     * limiting what the server can send as long as fits in one credit
3390     + * Unfortunately - we can not handle more than CIFS_MAX_MSG_SIZE
3391     + * (by default, note that it can be overridden to make max larger)
3392     + * in responses (except for read responses which can be bigger.
3393     + * We may want to bump this limit up
3394     */
3395     - req->MaxOutputResponse = cpu_to_le32(0xFF00); /* < 64K uses 1 credit */
3396     + req->MaxOutputResponse = cpu_to_le32(CIFSMaxBufSize);
3397    
3398     if (is_fsctl)
3399     req->Flags = cpu_to_le32(SMB2_0_IOCTL_IS_FSCTL);
3400     diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c
3401     index 37b49894c762..15bf9c31a34d 100644
3402     --- a/fs/crypto/fname.c
3403     +++ b/fs/crypto/fname.c
3404     @@ -300,7 +300,7 @@ int fscrypt_fname_disk_to_usr(struct inode *inode,
3405     } else {
3406     memset(buf, 0, 8);
3407     }
3408     - memcpy(buf + 8, iname->name + iname->len - 16, 16);
3409     + memcpy(buf + 8, iname->name + ((iname->len - 17) & ~15), 16);
3410     oname->name[0] = '_';
3411     oname->len = 1 + digest_encode(buf, 24, oname->name + 1);
3412     return 0;
3413     diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c
3414     index 4908906d54d5..fc3660d82a7f 100644
3415     --- a/fs/crypto/policy.c
3416     +++ b/fs/crypto/policy.c
3417     @@ -143,27 +143,61 @@ int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
3418     }
3419     EXPORT_SYMBOL(fscrypt_ioctl_get_policy);
3420    
3421     +/**
3422     + * fscrypt_has_permitted_context() - is a file's encryption policy permitted
3423     + * within its directory?
3424     + *
3425     + * @parent: inode for parent directory
3426     + * @child: inode for file being looked up, opened, or linked into @parent
3427     + *
3428     + * Filesystems must call this before permitting access to an inode in a
3429     + * situation where the parent directory is encrypted (either before allowing
3430     + * ->lookup() to succeed, or for a regular file before allowing it to be opened)
3431     + * and before any operation that involves linking an inode into an encrypted
3432     + * directory, including link, rename, and cross rename. It enforces the
3433     + * constraint that within a given encrypted directory tree, all files use the
3434     + * same encryption policy. The pre-access check is needed to detect potentially
3435     + * malicious offline violations of this constraint, while the link and rename
3436     + * checks are needed to prevent online violations of this constraint.
3437     + *
3438     + * Return: 1 if permitted, 0 if forbidden. If forbidden, the caller must fail
3439     + * the filesystem operation with EPERM.
3440     + */
3441     int fscrypt_has_permitted_context(struct inode *parent, struct inode *child)
3442     {
3443     - struct fscrypt_info *parent_ci, *child_ci;
3444     + const struct fscrypt_operations *cops = parent->i_sb->s_cop;
3445     + const struct fscrypt_info *parent_ci, *child_ci;
3446     + struct fscrypt_context parent_ctx, child_ctx;
3447     int res;
3448    
3449     - if ((parent == NULL) || (child == NULL)) {
3450     - printk(KERN_ERR "parent %p child %p\n", parent, child);
3451     - BUG_ON(1);
3452     - }
3453     -
3454     /* No restrictions on file types which are never encrypted */
3455     if (!S_ISREG(child->i_mode) && !S_ISDIR(child->i_mode) &&
3456     !S_ISLNK(child->i_mode))
3457     return 1;
3458    
3459     - /* no restrictions if the parent directory is not encrypted */
3460     - if (!parent->i_sb->s_cop->is_encrypted(parent))
3461     + /* No restrictions if the parent directory is unencrypted */
3462     + if (!cops->is_encrypted(parent))
3463     return 1;
3464     - /* if the child directory is not encrypted, this is always a problem */
3465     - if (!parent->i_sb->s_cop->is_encrypted(child))
3466     +
3467     + /* Encrypted directories must not contain unencrypted files */
3468     + if (!cops->is_encrypted(child))
3469     return 0;
3470     +
3471     + /*
3472     + * Both parent and child are encrypted, so verify they use the same
3473     + * encryption policy. Compare the fscrypt_info structs if the keys are
3474     + * available, otherwise retrieve and compare the fscrypt_contexts.
3475     + *
3476     + * Note that the fscrypt_context retrieval will be required frequently
3477     + * when accessing an encrypted directory tree without the key.
3478     + * Performance-wise this is not a big deal because we already don't
3479     + * really optimize for file access without the key (to the extent that
3480     + * such access is even possible), given that any attempted access
3481     + * already causes a fscrypt_context retrieval and keyring search.
3482     + *
3483     + * In any case, if an unexpected error occurs, fall back to "forbidden".
3484     + */
3485     +
3486     res = fscrypt_get_encryption_info(parent);
3487     if (res)
3488     return 0;
3489     @@ -172,17 +206,32 @@ int fscrypt_has_permitted_context(struct inode *parent, struct inode *child)
3490     return 0;
3491     parent_ci = parent->i_crypt_info;
3492     child_ci = child->i_crypt_info;
3493     - if (!parent_ci && !child_ci)
3494     - return 1;
3495     - if (!parent_ci || !child_ci)
3496     +
3497     + if (parent_ci && child_ci) {
3498     + return memcmp(parent_ci->ci_master_key, child_ci->ci_master_key,
3499     + FS_KEY_DESCRIPTOR_SIZE) == 0 &&
3500     + (parent_ci->ci_data_mode == child_ci->ci_data_mode) &&
3501     + (parent_ci->ci_filename_mode ==
3502     + child_ci->ci_filename_mode) &&
3503     + (parent_ci->ci_flags == child_ci->ci_flags);
3504     + }
3505     +
3506     + res = cops->get_context(parent, &parent_ctx, sizeof(parent_ctx));
3507     + if (res != sizeof(parent_ctx))
3508     + return 0;
3509     +
3510     + res = cops->get_context(child, &child_ctx, sizeof(child_ctx));
3511     + if (res != sizeof(child_ctx))
3512     return 0;
3513    
3514     - return (memcmp(parent_ci->ci_master_key,
3515     - child_ci->ci_master_key,
3516     - FS_KEY_DESCRIPTOR_SIZE) == 0 &&
3517     - (parent_ci->ci_data_mode == child_ci->ci_data_mode) &&
3518     - (parent_ci->ci_filename_mode == child_ci->ci_filename_mode) &&
3519     - (parent_ci->ci_flags == child_ci->ci_flags));
3520     + return memcmp(parent_ctx.master_key_descriptor,
3521     + child_ctx.master_key_descriptor,
3522     + FS_KEY_DESCRIPTOR_SIZE) == 0 &&
3523     + (parent_ctx.contents_encryption_mode ==
3524     + child_ctx.contents_encryption_mode) &&
3525     + (parent_ctx.filenames_encryption_mode ==
3526     + child_ctx.filenames_encryption_mode) &&
3527     + (parent_ctx.flags == child_ctx.flags);
3528     }
3529     EXPORT_SYMBOL(fscrypt_has_permitted_context);
3530    
3531     diff --git a/fs/dax.c b/fs/dax.c
3532     index 85abd741253d..b87f3ab742ba 100644
3533     --- a/fs/dax.c
3534     +++ b/fs/dax.c
3535     @@ -507,35 +507,6 @@ int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index)
3536     }
3537    
3538     /*
3539     - * Invalidate exceptional DAX entry if easily possible. This handles DAX
3540     - * entries for invalidate_inode_pages() so we evict the entry only if we can
3541     - * do so without blocking.
3542     - */
3543     -int dax_invalidate_mapping_entry(struct address_space *mapping, pgoff_t index)
3544     -{
3545     - int ret = 0;
3546     - void *entry, **slot;
3547     - struct radix_tree_root *page_tree = &mapping->page_tree;
3548     -
3549     - spin_lock_irq(&mapping->tree_lock);
3550     - entry = __radix_tree_lookup(page_tree, index, NULL, &slot);
3551     - if (!entry || !radix_tree_exceptional_entry(entry) ||
3552     - slot_locked(mapping, slot))
3553     - goto out;
3554     - if (radix_tree_tag_get(page_tree, index, PAGECACHE_TAG_DIRTY) ||
3555     - radix_tree_tag_get(page_tree, index, PAGECACHE_TAG_TOWRITE))
3556     - goto out;
3557     - radix_tree_delete(page_tree, index);
3558     - mapping->nrexceptional--;
3559     - ret = 1;
3560     -out:
3561     - spin_unlock_irq(&mapping->tree_lock);
3562     - if (ret)
3563     - dax_wake_mapping_entry_waiter(mapping, index, entry, true);
3564     - return ret;
3565     -}
3566     -
3567     -/*
3568     * Invalidate exceptional DAX entry if it is clean.
3569     */
3570     int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
3571     @@ -1032,7 +1003,7 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
3572     * into page tables. We have to tear down these mappings so that data
3573     * written by write(2) is visible in mmap.
3574     */
3575     - if ((iomap->flags & IOMAP_F_NEW) && inode->i_mapping->nrpages) {
3576     + if (iomap->flags & IOMAP_F_NEW) {
3577     invalidate_inode_pages2_range(inode->i_mapping,
3578     pos >> PAGE_SHIFT,
3579     (end - 1) >> PAGE_SHIFT);
3580     @@ -1382,6 +1353,16 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf,
3581     goto fallback;
3582    
3583     /*
3584     + * grab_mapping_entry() will make sure we get a 2M empty entry, a DAX
3585     + * PMD or a HZP entry. If it can't (because a 4k page is already in
3586     + * the tree, for instance), it will return -EEXIST and we just fall
3587     + * back to 4k entries.
3588     + */
3589     + entry = grab_mapping_entry(mapping, pgoff, RADIX_DAX_PMD);
3590     + if (IS_ERR(entry))
3591     + goto fallback;
3592     +
3593     + /*
3594     * Note that we don't use iomap_apply here. We aren't doing I/O, only
3595     * setting up a mapping, so really we're using iomap_begin() as a way
3596     * to look up our filesystem block.
3597     @@ -1389,21 +1370,11 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf,
3598     pos = (loff_t)pgoff << PAGE_SHIFT;
3599     error = ops->iomap_begin(inode, pos, PMD_SIZE, iomap_flags, &iomap);
3600     if (error)
3601     - goto fallback;
3602     + goto unlock_entry;
3603    
3604     if (iomap.offset + iomap.length < pos + PMD_SIZE)
3605     goto finish_iomap;
3606    
3607     - /*
3608     - * grab_mapping_entry() will make sure we get a 2M empty entry, a DAX
3609     - * PMD or a HZP entry. If it can't (because a 4k page is already in
3610     - * the tree, for instance), it will return -EEXIST and we just fall
3611     - * back to 4k entries.
3612     - */
3613     - entry = grab_mapping_entry(mapping, pgoff, RADIX_DAX_PMD);
3614     - if (IS_ERR(entry))
3615     - goto finish_iomap;
3616     -
3617     switch (iomap.type) {
3618     case IOMAP_MAPPED:
3619     result = dax_pmd_insert_mapping(vmf, &iomap, pos, &entry);
3620     @@ -1411,7 +1382,7 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf,
3621     case IOMAP_UNWRITTEN:
3622     case IOMAP_HOLE:
3623     if (WARN_ON_ONCE(write))
3624     - goto unlock_entry;
3625     + break;
3626     result = dax_pmd_load_hole(vmf, &iomap, &entry);
3627     break;
3628     default:
3629     @@ -1419,8 +1390,6 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf,
3630     break;
3631     }
3632    
3633     - unlock_entry:
3634     - put_locked_mapping_entry(mapping, pgoff, entry);
3635     finish_iomap:
3636     if (ops->iomap_end) {
3637     int copied = PMD_SIZE;
3638     @@ -1436,6 +1405,8 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf,
3639     ops->iomap_end(inode, pos, PMD_SIZE, copied, iomap_flags,
3640     &iomap);
3641     }
3642     + unlock_entry:
3643     + put_locked_mapping_entry(mapping, pgoff, entry);
3644     fallback:
3645     if (result == VM_FAULT_FALLBACK) {
3646     split_huge_pmd(vma, vmf->pmd, vmf->address);
3647     diff --git a/fs/ext4/file.c b/fs/ext4/file.c
3648     index cefa9835f275..831fd6beebf0 100644
3649     --- a/fs/ext4/file.c
3650     +++ b/fs/ext4/file.c
3651     @@ -257,6 +257,7 @@ static int ext4_dax_huge_fault(struct vm_fault *vmf,
3652     enum page_entry_size pe_size)
3653     {
3654     int result;
3655     + handle_t *handle = NULL;
3656     struct inode *inode = file_inode(vmf->vma->vm_file);
3657     struct super_block *sb = inode->i_sb;
3658     bool write = vmf->flags & FAULT_FLAG_WRITE;
3659     @@ -264,12 +265,24 @@ static int ext4_dax_huge_fault(struct vm_fault *vmf,
3660     if (write) {
3661     sb_start_pagefault(sb);
3662     file_update_time(vmf->vma->vm_file);
3663     + down_read(&EXT4_I(inode)->i_mmap_sem);
3664     + handle = ext4_journal_start_sb(sb, EXT4_HT_WRITE_PAGE,
3665     + EXT4_DATA_TRANS_BLOCKS(sb));
3666     + } else {
3667     + down_read(&EXT4_I(inode)->i_mmap_sem);
3668     }
3669     - down_read(&EXT4_I(inode)->i_mmap_sem);
3670     - result = dax_iomap_fault(vmf, pe_size, &ext4_iomap_ops);
3671     - up_read(&EXT4_I(inode)->i_mmap_sem);
3672     - if (write)
3673     + if (!IS_ERR(handle))
3674     + result = dax_iomap_fault(vmf, pe_size, &ext4_iomap_ops);
3675     + else
3676     + result = VM_FAULT_SIGBUS;
3677     + if (write) {
3678     + if (!IS_ERR(handle))
3679     + ext4_journal_stop(handle);
3680     + up_read(&EXT4_I(inode)->i_mmap_sem);
3681     sb_end_pagefault(sb);
3682     + } else {
3683     + up_read(&EXT4_I(inode)->i_mmap_sem);
3684     + }
3685    
3686     return result;
3687     }
3688     diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
3689     index b9ffa9f4191f..88203ae5b154 100644
3690     --- a/fs/ext4/inode.c
3691     +++ b/fs/ext4/inode.c
3692     @@ -5874,6 +5874,11 @@ int ext4_page_mkwrite(struct vm_fault *vmf)
3693     file_update_time(vma->vm_file);
3694    
3695     down_read(&EXT4_I(inode)->i_mmap_sem);
3696     +
3697     + ret = ext4_convert_inline_data(inode);
3698     + if (ret)
3699     + goto out_ret;
3700     +
3701     /* Delalloc case is easy... */
3702     if (test_opt(inode->i_sb, DELALLOC) &&
3703     !ext4_should_journal_data(inode) &&
3704     diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
3705     index 07e5e1405771..eb2dea8287c1 100644
3706     --- a/fs/ext4/namei.c
3707     +++ b/fs/ext4/namei.c
3708     @@ -1255,9 +1255,9 @@ static inline int ext4_match(struct ext4_filename *fname,
3709     if (unlikely(!name)) {
3710     if (fname->usr_fname->name[0] == '_') {
3711     int ret;
3712     - if (de->name_len < 16)
3713     + if (de->name_len <= 32)
3714     return 0;
3715     - ret = memcmp(de->name + de->name_len - 16,
3716     + ret = memcmp(de->name + ((de->name_len - 17) & ~15),
3717     fname->crypto_buf.name + 8, 16);
3718     return (ret == 0) ? 1 : 0;
3719     }
3720     diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
3721     index 1602b4bccae6..dd24476e8d2c 100644
3722     --- a/fs/f2fs/data.c
3723     +++ b/fs/f2fs/data.c
3724     @@ -309,7 +309,7 @@ static void __f2fs_submit_merged_bio(struct f2fs_sb_info *sbi,
3725     if (type >= META_FLUSH) {
3726     io->fio.type = META_FLUSH;
3727     io->fio.op = REQ_OP_WRITE;
3728     - io->fio.op_flags = REQ_META | REQ_PRIO;
3729     + io->fio.op_flags = REQ_META | REQ_PRIO | REQ_SYNC;
3730     if (!test_opt(sbi, NOBARRIER))
3731     io->fio.op_flags |= REQ_PREFLUSH | REQ_FUA;
3732     }
3733     diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
3734     index 8d5c62b07b28..96e9e7fa64dd 100644
3735     --- a/fs/f2fs/dir.c
3736     +++ b/fs/f2fs/dir.c
3737     @@ -130,19 +130,29 @@ struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname,
3738     continue;
3739     }
3740    
3741     - /* encrypted case */
3742     + if (de->hash_code != namehash)
3743     + goto not_match;
3744     +
3745     de_name.name = d->filename[bit_pos];
3746     de_name.len = le16_to_cpu(de->name_len);
3747    
3748     - /* show encrypted name */
3749     - if (fname->hash) {
3750     - if (de->hash_code == cpu_to_le32(fname->hash))
3751     - goto found;
3752     - } else if (de_name.len == name->len &&
3753     - de->hash_code == namehash &&
3754     - !memcmp(de_name.name, name->name, name->len))
3755     +#ifdef CONFIG_F2FS_FS_ENCRYPTION
3756     + if (unlikely(!name->name)) {
3757     + if (fname->usr_fname->name[0] == '_') {
3758     + if (de_name.len > 32 &&
3759     + !memcmp(de_name.name + ((de_name.len - 17) & ~15),
3760     + fname->crypto_buf.name + 8, 16))
3761     + goto found;
3762     + goto not_match;
3763     + }
3764     + name->name = fname->crypto_buf.name;
3765     + name->len = fname->crypto_buf.len;
3766     + }
3767     +#endif
3768     + if (de_name.len == name->len &&
3769     + !memcmp(de_name.name, name->name, name->len))
3770     goto found;
3771     -
3772     +not_match:
3773     if (max_slots && max_len > *max_slots)
3774     *max_slots = max_len;
3775     max_len = 0;
3776     @@ -170,12 +180,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir,
3777     struct f2fs_dir_entry *de = NULL;
3778     bool room = false;
3779     int max_slots;
3780     - f2fs_hash_t namehash;
3781     -
3782     - if(fname->hash)
3783     - namehash = cpu_to_le32(fname->hash);
3784     - else
3785     - namehash = f2fs_dentry_hash(&name);
3786     + f2fs_hash_t namehash = f2fs_dentry_hash(&name, fname);
3787    
3788     nbucket = dir_buckets(level, F2FS_I(dir)->i_dir_level);
3789     nblock = bucket_blocks(level);
3790     @@ -207,13 +212,9 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir,
3791     f2fs_put_page(dentry_page, 0);
3792     }
3793    
3794     - /* This is to increase the speed of f2fs_create */
3795     - if (!de && room) {
3796     - F2FS_I(dir)->task = current;
3797     - if (F2FS_I(dir)->chash != namehash) {
3798     - F2FS_I(dir)->chash = namehash;
3799     - F2FS_I(dir)->clevel = level;
3800     - }
3801     + if (!de && room && F2FS_I(dir)->chash != namehash) {
3802     + F2FS_I(dir)->chash = namehash;
3803     + F2FS_I(dir)->clevel = level;
3804     }
3805    
3806     return de;
3807     @@ -254,6 +255,9 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
3808     break;
3809     }
3810     out:
3811     + /* This is to increase the speed of f2fs_create */
3812     + if (!de)
3813     + F2FS_I(dir)->task = current;
3814     return de;
3815     }
3816    
3817     @@ -542,7 +546,7 @@ int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name,
3818    
3819     level = 0;
3820     slots = GET_DENTRY_SLOTS(new_name->len);
3821     - dentry_hash = f2fs_dentry_hash(new_name);
3822     + dentry_hash = f2fs_dentry_hash(new_name, NULL);
3823    
3824     current_depth = F2FS_I(dir)->i_current_depth;
3825     if (F2FS_I(dir)->chash == dentry_hash) {
3826     diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
3827     index 0a6e115562f6..05d7e2cefc56 100644
3828     --- a/fs/f2fs/f2fs.h
3829     +++ b/fs/f2fs/f2fs.h
3830     @@ -2133,7 +2133,8 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi);
3831     /*
3832     * hash.c
3833     */
3834     -f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info);
3835     +f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info,
3836     + struct fscrypt_name *fname);
3837    
3838     /*
3839     * node.c
3840     diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
3841     index 418fd9881646..b5a62d4a3a69 100644
3842     --- a/fs/f2fs/gc.c
3843     +++ b/fs/f2fs/gc.c
3844     @@ -182,7 +182,7 @@ static unsigned int get_max_cost(struct f2fs_sb_info *sbi,
3845     if (p->alloc_mode == SSR)
3846     return sbi->blocks_per_seg;
3847     if (p->gc_mode == GC_GREEDY)
3848     - return sbi->blocks_per_seg * p->ofs_unit;
3849     + return 2 * sbi->blocks_per_seg * p->ofs_unit;
3850     else if (p->gc_mode == GC_CB)
3851     return UINT_MAX;
3852     else /* No other gc_mode */
3853     diff --git a/fs/f2fs/hash.c b/fs/f2fs/hash.c
3854     index 71b7206c431e..eb2e031ea887 100644
3855     --- a/fs/f2fs/hash.c
3856     +++ b/fs/f2fs/hash.c
3857     @@ -70,7 +70,8 @@ static void str2hashbuf(const unsigned char *msg, size_t len,
3858     *buf++ = pad;
3859     }
3860    
3861     -f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info)
3862     +f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info,
3863     + struct fscrypt_name *fname)
3864     {
3865     __u32 hash;
3866     f2fs_hash_t f2fs_hash;
3867     @@ -79,6 +80,10 @@ f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info)
3868     const unsigned char *name = name_info->name;
3869     size_t len = name_info->len;
3870    
3871     + /* encrypted bigname case */
3872     + if (fname && !fname->disk_name.name)
3873     + return cpu_to_le32(fname->hash);
3874     +
3875     if (is_dot_dotdot(name_info))
3876     return 0;
3877    
3878     diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
3879     index e32a9e527968..fa729ff6b2f9 100644
3880     --- a/fs/f2fs/inline.c
3881     +++ b/fs/f2fs/inline.c
3882     @@ -296,7 +296,7 @@ struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir,
3883     return NULL;
3884     }
3885    
3886     - namehash = f2fs_dentry_hash(&name);
3887     + namehash = f2fs_dentry_hash(&name, fname);
3888    
3889     inline_dentry = inline_data_addr(ipage);
3890    
3891     @@ -533,7 +533,7 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
3892    
3893     f2fs_wait_on_page_writeback(ipage, NODE, true);
3894    
3895     - name_hash = f2fs_dentry_hash(new_name);
3896     + name_hash = f2fs_dentry_hash(new_name, NULL);
3897     make_dentry_ptr(NULL, &d, (void *)dentry_blk, 2);
3898     f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos);
3899    
3900     diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
3901     index 24bb8213d974..a204f22eba5b 100644
3902     --- a/fs/f2fs/inode.c
3903     +++ b/fs/f2fs/inode.c
3904     @@ -316,7 +316,6 @@ int update_inode_page(struct inode *inode)
3905     } else if (err != -ENOENT) {
3906     f2fs_stop_checkpoint(sbi, false);
3907     }
3908     - f2fs_inode_synced(inode);
3909     return 0;
3910     }
3911     ret = update_inode(inode, node_page);
3912     @@ -448,6 +447,7 @@ void handle_failed_inode(struct inode *inode)
3913     * in a panic when flushing dirty inodes in gdirty_list.
3914     */
3915     update_inode_page(inode);
3916     + f2fs_inode_synced(inode);
3917    
3918     /* don't make bad inode, since it becomes a regular file. */
3919     unlock_new_inode(inode);
3920     diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
3921     index 98f00a3a7f50..a30f323b7b2b 100644
3922     --- a/fs/f2fs/namei.c
3923     +++ b/fs/f2fs/namei.c
3924     @@ -148,8 +148,6 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
3925     inode->i_mapping->a_ops = &f2fs_dblock_aops;
3926     ino = inode->i_ino;
3927    
3928     - f2fs_balance_fs(sbi, true);
3929     -
3930     f2fs_lock_op(sbi);
3931     err = f2fs_add_link(dentry, inode);
3932     if (err)
3933     @@ -163,6 +161,8 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
3934    
3935     if (IS_DIRSYNC(dir))
3936     f2fs_sync_fs(sbi->sb, 1);
3937     +
3938     + f2fs_balance_fs(sbi, true);
3939     return 0;
3940     out:
3941     handle_failed_inode(inode);
3942     @@ -423,8 +423,6 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
3943     inode_nohighmem(inode);
3944     inode->i_mapping->a_ops = &f2fs_dblock_aops;
3945    
3946     - f2fs_balance_fs(sbi, true);
3947     -
3948     f2fs_lock_op(sbi);
3949     err = f2fs_add_link(dentry, inode);
3950     if (err)
3951     @@ -487,6 +485,8 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
3952     }
3953    
3954     kfree(sd);
3955     +
3956     + f2fs_balance_fs(sbi, true);
3957     return err;
3958     out:
3959     handle_failed_inode(inode);
3960     @@ -508,8 +508,6 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
3961     inode->i_mapping->a_ops = &f2fs_dblock_aops;
3962     mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO);
3963    
3964     - f2fs_balance_fs(sbi, true);
3965     -
3966     set_inode_flag(inode, FI_INC_LINK);
3967     f2fs_lock_op(sbi);
3968     err = f2fs_add_link(dentry, inode);
3969     @@ -524,6 +522,8 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
3970    
3971     if (IS_DIRSYNC(dir))
3972     f2fs_sync_fs(sbi->sb, 1);
3973     +
3974     + f2fs_balance_fs(sbi, true);
3975     return 0;
3976    
3977     out_fail:
3978     @@ -554,8 +554,6 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
3979     init_special_inode(inode, inode->i_mode, rdev);
3980     inode->i_op = &f2fs_special_inode_operations;
3981    
3982     - f2fs_balance_fs(sbi, true);
3983     -
3984     f2fs_lock_op(sbi);
3985     err = f2fs_add_link(dentry, inode);
3986     if (err)
3987     @@ -569,6 +567,8 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
3988    
3989     if (IS_DIRSYNC(dir))
3990     f2fs_sync_fs(sbi->sb, 1);
3991     +
3992     + f2fs_balance_fs(sbi, true);
3993     return 0;
3994     out:
3995     handle_failed_inode(inode);
3996     @@ -595,8 +595,6 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
3997     inode->i_mapping->a_ops = &f2fs_dblock_aops;
3998     }
3999    
4000     - f2fs_balance_fs(sbi, true);
4001     -
4002     f2fs_lock_op(sbi);
4003     err = acquire_orphan_inode(sbi);
4004     if (err)
4005     @@ -622,6 +620,8 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
4006     /* link_count was changed by d_tmpfile as well. */
4007     f2fs_unlock_op(sbi);
4008     unlock_new_inode(inode);
4009     +
4010     + f2fs_balance_fs(sbi, true);
4011     return 0;
4012    
4013     release_out:
4014     diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
4015     index 29ef7088c558..56670c5058b7 100644
4016     --- a/fs/f2fs/segment.c
4017     +++ b/fs/f2fs/segment.c
4018     @@ -416,7 +416,7 @@ static int __submit_flush_wait(struct block_device *bdev)
4019     struct bio *bio = f2fs_bio_alloc(0);
4020     int ret;
4021    
4022     - bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
4023     + bio->bi_opf = REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH;
4024     bio->bi_bdev = bdev;
4025     ret = submit_bio_wait(bio);
4026     bio_put(bio);
4027     @@ -1788,15 +1788,14 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
4028    
4029     stat_inc_block_count(sbi, curseg);
4030    
4031     + if (!__has_curseg_space(sbi, type))
4032     + sit_i->s_ops->allocate_segment(sbi, type, false);
4033     /*
4034     - * SIT information should be updated before segment allocation,
4035     - * since SSR needs latest valid block information.
4036     + * SIT information should be updated after segment allocation,
4037     + * since we need to keep dirty segments precisely under SSR.
4038     */
4039     refresh_sit_entry(sbi, old_blkaddr, *new_blkaddr);
4040    
4041     - if (!__has_curseg_space(sbi, type))
4042     - sit_i->s_ops->allocate_segment(sbi, type, false);
4043     -
4044     mutex_unlock(&sit_i->sentry_lock);
4045    
4046     if (page && IS_NODESEG(type))
4047     diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
4048     index 858aef564a58..5ca78308d5ec 100644
4049     --- a/fs/f2fs/super.c
4050     +++ b/fs/f2fs/super.c
4051     @@ -1307,7 +1307,7 @@ static int __f2fs_commit_super(struct buffer_head *bh,
4052     unlock_buffer(bh);
4053    
4054     /* it's rare case, we can do fua all the time */
4055     - return __sync_dirty_buffer(bh, REQ_PREFLUSH | REQ_FUA);
4056     + return __sync_dirty_buffer(bh, REQ_SYNC | REQ_PREFLUSH | REQ_FUA);
4057     }
4058    
4059     static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
4060     diff --git a/fs/iomap.c b/fs/iomap.c
4061     index 141c3cd55a8b..1c25ae30500e 100644
4062     --- a/fs/iomap.c
4063     +++ b/fs/iomap.c
4064     @@ -887,16 +887,14 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
4065     flags |= IOMAP_WRITE;
4066     }
4067    
4068     - if (mapping->nrpages) {
4069     - ret = filemap_write_and_wait_range(mapping, start, end);
4070     - if (ret)
4071     - goto out_free_dio;
4072     + ret = filemap_write_and_wait_range(mapping, start, end);
4073     + if (ret)
4074     + goto out_free_dio;
4075    
4076     - ret = invalidate_inode_pages2_range(mapping,
4077     - start >> PAGE_SHIFT, end >> PAGE_SHIFT);
4078     - WARN_ON_ONCE(ret);
4079     - ret = 0;
4080     - }
4081     + ret = invalidate_inode_pages2_range(mapping,
4082     + start >> PAGE_SHIFT, end >> PAGE_SHIFT);
4083     + WARN_ON_ONCE(ret);
4084     + ret = 0;
4085    
4086     inode_dio_begin(inode);
4087    
4088     @@ -951,7 +949,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
4089     * one is a pretty crazy thing to do, so we don't support it 100%. If
4090     * this invalidation fails, tough, the write still worked...
4091     */
4092     - if (iov_iter_rw(iter) == WRITE && mapping->nrpages) {
4093     + if (iov_iter_rw(iter) == WRITE) {
4094     int err = invalidate_inode_pages2_range(mapping,
4095     start >> PAGE_SHIFT, end >> PAGE_SHIFT);
4096     WARN_ON_ONCE(err);
4097     diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
4098     index 5adc2fb62b0f..e768126f6a72 100644
4099     --- a/fs/jbd2/journal.c
4100     +++ b/fs/jbd2/journal.c
4101     @@ -1348,7 +1348,7 @@ static int jbd2_write_superblock(journal_t *journal, int write_flags)
4102     jbd2_superblock_csum_set(journal, sb);
4103     get_bh(bh);
4104     bh->b_end_io = end_buffer_write_sync;
4105     - ret = submit_bh(REQ_OP_WRITE, write_flags, bh);
4106     + ret = submit_bh(REQ_OP_WRITE, write_flags | REQ_SYNC, bh);
4107     wait_on_buffer(bh);
4108     if (buffer_write_io_error(bh)) {
4109     clear_buffer_write_io_error(bh);
4110     diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
4111     index a304bf34b212..5ebe19353da6 100644
4112     --- a/fs/orangefs/inode.c
4113     +++ b/fs/orangefs/inode.c
4114     @@ -218,8 +218,7 @@ int orangefs_setattr(struct dentry *dentry, struct iattr *iattr)
4115     if (ret)
4116     goto out;
4117    
4118     - if ((iattr->ia_valid & ATTR_SIZE) &&
4119     - iattr->ia_size != i_size_read(inode)) {
4120     + if (iattr->ia_valid & ATTR_SIZE) {
4121     ret = orangefs_setattr_size(inode, iattr);
4122     if (ret)
4123     goto out;
4124     diff --git a/fs/orangefs/namei.c b/fs/orangefs/namei.c
4125     index a290ff6ec756..7c315938e9c2 100644
4126     --- a/fs/orangefs/namei.c
4127     +++ b/fs/orangefs/namei.c
4128     @@ -193,8 +193,6 @@ static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
4129     goto out;
4130     }
4131    
4132     - ORANGEFS_I(inode)->getattr_time = jiffies - 1;
4133     -
4134     gossip_debug(GOSSIP_NAME_DEBUG,
4135     "%s:%s:%d "
4136     "Found good inode [%lu] with count [%d]\n",
4137     diff --git a/fs/orangefs/xattr.c b/fs/orangefs/xattr.c
4138     index 74a81b1daaac..237c9c04dc3b 100644
4139     --- a/fs/orangefs/xattr.c
4140     +++ b/fs/orangefs/xattr.c
4141     @@ -76,11 +76,8 @@ ssize_t orangefs_inode_getxattr(struct inode *inode, const char *name,
4142     if (S_ISLNK(inode->i_mode))
4143     return -EOPNOTSUPP;
4144    
4145     - if (strlen(name) >= ORANGEFS_MAX_XATTR_NAMELEN) {
4146     - gossip_err("Invalid key length (%d)\n",
4147     - (int)strlen(name));
4148     + if (strlen(name) > ORANGEFS_MAX_XATTR_NAMELEN)
4149     return -EINVAL;
4150     - }
4151    
4152     fsuid = from_kuid(&init_user_ns, current_fsuid());
4153     fsgid = from_kgid(&init_user_ns, current_fsgid());
4154     @@ -172,6 +169,9 @@ static int orangefs_inode_removexattr(struct inode *inode, const char *name,
4155     struct orangefs_kernel_op_s *new_op = NULL;
4156     int ret = -ENOMEM;
4157    
4158     + if (strlen(name) > ORANGEFS_MAX_XATTR_NAMELEN)
4159     + return -EINVAL;
4160     +
4161     down_write(&orangefs_inode->xattr_sem);
4162     new_op = op_alloc(ORANGEFS_VFS_OP_REMOVEXATTR);
4163     if (!new_op)
4164     @@ -231,23 +231,13 @@ int orangefs_inode_setxattr(struct inode *inode, const char *name,
4165     "%s: name %s, buffer_size %zd\n",
4166     __func__, name, size);
4167    
4168     - if (size >= ORANGEFS_MAX_XATTR_VALUELEN ||
4169     - flags < 0) {
4170     - gossip_err("orangefs_inode_setxattr: bogus values of size(%d), flags(%d)\n",
4171     - (int)size,
4172     - flags);
4173     + if (size > ORANGEFS_MAX_XATTR_VALUELEN)
4174     + return -EINVAL;
4175     + if (strlen(name) > ORANGEFS_MAX_XATTR_NAMELEN)
4176     return -EINVAL;
4177     - }
4178    
4179     internal_flag = convert_to_internal_xattr_flags(flags);
4180    
4181     - if (strlen(name) >= ORANGEFS_MAX_XATTR_NAMELEN) {
4182     - gossip_err
4183     - ("orangefs_inode_setxattr: bogus key size (%d)\n",
4184     - (int)(strlen(name)));
4185     - return -EINVAL;
4186     - }
4187     -
4188     /* This is equivalent to a removexattr */
4189     if (size == 0 && value == NULL) {
4190     gossip_debug(GOSSIP_XATTR_DEBUG,
4191     @@ -358,7 +348,7 @@ ssize_t orangefs_listxattr(struct dentry *dentry, char *buffer, size_t size)
4192    
4193     returned_count = new_op->downcall.resp.listxattr.returned_count;
4194     if (returned_count < 0 ||
4195     - returned_count >= ORANGEFS_MAX_XATTR_LISTLEN) {
4196     + returned_count > ORANGEFS_MAX_XATTR_LISTLEN) {
4197     gossip_err("%s: impossible value for returned_count:%d:\n",
4198     __func__,
4199     returned_count);
4200     diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
4201     index 6515796460df..bfabc65fdc74 100644
4202     --- a/fs/overlayfs/dir.c
4203     +++ b/fs/overlayfs/dir.c
4204     @@ -210,7 +210,7 @@ static int ovl_create_upper(struct dentry *dentry, struct inode *inode,
4205     if (err)
4206     goto out_dput;
4207    
4208     - if (ovl_type_merge(dentry->d_parent)) {
4209     + if (ovl_type_merge(dentry->d_parent) && d_is_dir(newdentry)) {
4210     /* Setting opaque here is just an optimization, allow to fail */
4211     ovl_set_opaque(dentry, newdentry);
4212     }
4213     diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
4214     index efab7b64925b..b81ce8ddf14a 100644
4215     --- a/fs/pstore/platform.c
4216     +++ b/fs/pstore/platform.c
4217     @@ -709,6 +709,7 @@ int pstore_register(struct pstore_info *psi)
4218     if (psi->flags & PSTORE_FLAGS_PMSG)
4219     pstore_register_pmsg();
4220    
4221     + /* Start watching for new records, if desired. */
4222     if (pstore_update_ms >= 0) {
4223     pstore_timer.expires = jiffies +
4224     msecs_to_jiffies(pstore_update_ms);
4225     @@ -731,6 +732,11 @@ EXPORT_SYMBOL_GPL(pstore_register);
4226    
4227     void pstore_unregister(struct pstore_info *psi)
4228     {
4229     + /* Stop timer and make sure all work has finished. */
4230     + pstore_update_ms = -1;
4231     + del_timer_sync(&pstore_timer);
4232     + flush_work(&pstore_work);
4233     +
4234     if (psi->flags & PSTORE_FLAGS_PMSG)
4235     pstore_unregister_pmsg();
4236     if (psi->flags & PSTORE_FLAGS_FTRACE)
4237     @@ -830,7 +836,9 @@ static void pstore_timefunc(unsigned long dummy)
4238     schedule_work(&pstore_work);
4239     }
4240    
4241     - mod_timer(&pstore_timer, jiffies + msecs_to_jiffies(pstore_update_ms));
4242     + if (pstore_update_ms >= 0)
4243     + mod_timer(&pstore_timer,
4244     + jiffies + msecs_to_jiffies(pstore_update_ms));
4245     }
4246    
4247     module_param(backend, charp, 0444);
4248     diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
4249     index bc927e30bdcc..e11672aa4575 100644
4250     --- a/fs/pstore/ram_core.c
4251     +++ b/fs/pstore/ram_core.c
4252     @@ -532,7 +532,7 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
4253     }
4254    
4255     /* Initialize general buffer state. */
4256     - prz->buffer_lock = __RAW_SPIN_LOCK_UNLOCKED(buffer_lock);
4257     + raw_spin_lock_init(&prz->buffer_lock);
4258     prz->flags = flags;
4259    
4260     ret = persistent_ram_buffer_map(start, size, prz, memtype);
4261     diff --git a/fs/xattr.c b/fs/xattr.c
4262     index 7e3317cf4045..94f49a082dd2 100644
4263     --- a/fs/xattr.c
4264     +++ b/fs/xattr.c
4265     @@ -530,7 +530,7 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,
4266     size = XATTR_SIZE_MAX;
4267     kvalue = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
4268     if (!kvalue) {
4269     - kvalue = vmalloc(size);
4270     + kvalue = vzalloc(size);
4271     if (!kvalue)
4272     return -ENOMEM;
4273     }
4274     diff --git a/include/linux/dax.h b/include/linux/dax.h
4275     index d8a3dc042e1c..f8e1833f81f6 100644
4276     --- a/include/linux/dax.h
4277     +++ b/include/linux/dax.h
4278     @@ -41,7 +41,6 @@ ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
4279     int dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
4280     const struct iomap_ops *ops);
4281     int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
4282     -int dax_invalidate_mapping_entry(struct address_space *mapping, pgoff_t index);
4283     int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
4284     pgoff_t index);
4285     void dax_wake_mapping_entry_waiter(struct address_space *mapping,
4286     diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
4287     index d0250744507a..333af5a41c78 100644
4288     --- a/include/linux/kvm_host.h
4289     +++ b/include/linux/kvm_host.h
4290     @@ -641,18 +641,18 @@ int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
4291     int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
4292     unsigned long len);
4293     int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
4294     -int kvm_vcpu_read_guest_cached(struct kvm_vcpu *vcpu, struct gfn_to_hva_cache *ghc,
4295     - void *data, unsigned long len);
4296     +int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
4297     + void *data, unsigned long len);
4298     int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
4299     int offset, int len);
4300     int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
4301     unsigned long len);
4302     -int kvm_vcpu_write_guest_cached(struct kvm_vcpu *v, struct gfn_to_hva_cache *ghc,
4303     - void *data, unsigned long len);
4304     -int kvm_vcpu_write_guest_offset_cached(struct kvm_vcpu *v, struct gfn_to_hva_cache *ghc,
4305     - void *data, int offset, unsigned long len);
4306     -int kvm_vcpu_gfn_to_hva_cache_init(struct kvm_vcpu *v, struct gfn_to_hva_cache *ghc,
4307     - gpa_t gpa, unsigned long len);
4308     +int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
4309     + void *data, unsigned long len);
4310     +int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
4311     + void *data, int offset, unsigned long len);
4312     +int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
4313     + gpa_t gpa, unsigned long len);
4314     int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
4315     int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
4316     struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
4317     diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
4318     index bb7250c45cb8..e650f6f7d0bf 100644
4319     --- a/include/linux/memcontrol.h
4320     +++ b/include/linux/memcontrol.h
4321     @@ -56,6 +56,9 @@ enum mem_cgroup_stat_index {
4322     MEMCG_SLAB_RECLAIMABLE,
4323     MEMCG_SLAB_UNRECLAIMABLE,
4324     MEMCG_SOCK,
4325     + MEMCG_WORKINGSET_REFAULT,
4326     + MEMCG_WORKINGSET_ACTIVATE,
4327     + MEMCG_WORKINGSET_NODERECLAIM,
4328     MEMCG_NR_STAT,
4329     };
4330    
4331     @@ -494,6 +497,40 @@ extern int do_swap_account;
4332     void lock_page_memcg(struct page *page);
4333     void unlock_page_memcg(struct page *page);
4334    
4335     +static inline unsigned long mem_cgroup_read_stat(struct mem_cgroup *memcg,
4336     + enum mem_cgroup_stat_index idx)
4337     +{
4338     + long val = 0;
4339     + int cpu;
4340     +
4341     + for_each_possible_cpu(cpu)
4342     + val += per_cpu(memcg->stat->count[idx], cpu);
4343     +
4344     + if (val < 0)
4345     + val = 0;
4346     +
4347     + return val;
4348     +}
4349     +
4350     +static inline void mem_cgroup_update_stat(struct mem_cgroup *memcg,
4351     + enum mem_cgroup_stat_index idx, int val)
4352     +{
4353     + if (!mem_cgroup_disabled())
4354     + this_cpu_add(memcg->stat->count[idx], val);
4355     +}
4356     +
4357     +static inline void mem_cgroup_inc_stat(struct mem_cgroup *memcg,
4358     + enum mem_cgroup_stat_index idx)
4359     +{
4360     + mem_cgroup_update_stat(memcg, idx, 1);
4361     +}
4362     +
4363     +static inline void mem_cgroup_dec_stat(struct mem_cgroup *memcg,
4364     + enum mem_cgroup_stat_index idx)
4365     +{
4366     + mem_cgroup_update_stat(memcg, idx, -1);
4367     +}
4368     +
4369     /**
4370     * mem_cgroup_update_page_stat - update page state statistics
4371     * @page: the page
4372     @@ -508,14 +545,14 @@ void unlock_page_memcg(struct page *page);
4373     * if (TestClearPageState(page))
4374     * mem_cgroup_update_page_stat(page, state, -1);
4375     * unlock_page(page) or unlock_page_memcg(page)
4376     + *
4377     + * Kernel pages are an exception to this, since they'll never move.
4378     */
4379     static inline void mem_cgroup_update_page_stat(struct page *page,
4380     enum mem_cgroup_stat_index idx, int val)
4381     {
4382     - VM_BUG_ON(!(rcu_read_lock_held() || PageLocked(page)));
4383     -
4384     if (page->mem_cgroup)
4385     - this_cpu_add(page->mem_cgroup->stat->count[idx], val);
4386     + mem_cgroup_update_stat(page->mem_cgroup, idx, val);
4387     }
4388    
4389     static inline void mem_cgroup_inc_page_stat(struct page *page,
4390     @@ -740,6 +777,27 @@ static inline bool mem_cgroup_oom_synchronize(bool wait)
4391     return false;
4392     }
4393    
4394     +static inline unsigned long mem_cgroup_read_stat(struct mem_cgroup *memcg,
4395     + enum mem_cgroup_stat_index idx)
4396     +{
4397     + return 0;
4398     +}
4399     +
4400     +static inline void mem_cgroup_update_stat(struct mem_cgroup *memcg,
4401     + enum mem_cgroup_stat_index idx, int val)
4402     +{
4403     +}
4404     +
4405     +static inline void mem_cgroup_inc_stat(struct mem_cgroup *memcg,
4406     + enum mem_cgroup_stat_index idx)
4407     +{
4408     +}
4409     +
4410     +static inline void mem_cgroup_dec_stat(struct mem_cgroup *memcg,
4411     + enum mem_cgroup_stat_index idx)
4412     +{
4413     +}
4414     +
4415     static inline void mem_cgroup_update_page_stat(struct page *page,
4416     enum mem_cgroup_stat_index idx,
4417     int nr)
4418     diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
4419     index 8e02b3750fe0..d45172b559d8 100644
4420     --- a/include/linux/mmzone.h
4421     +++ b/include/linux/mmzone.h
4422     @@ -226,6 +226,8 @@ struct lruvec {
4423     struct zone_reclaim_stat reclaim_stat;
4424     /* Evictions & activations on the inactive file list */
4425     atomic_long_t inactive_age;
4426     + /* Refaults at the time of last reclaim cycle */
4427     + unsigned long refaults;
4428     #ifdef CONFIG_MEMCG
4429     struct pglist_data *pgdat;
4430     #endif
4431     diff --git a/init/initramfs.c b/init/initramfs.c
4432     index 981f286c1d16..8daf7ac6c7e2 100644
4433     --- a/init/initramfs.c
4434     +++ b/init/initramfs.c
4435     @@ -608,9 +608,11 @@ static void __init clean_rootfs(void)
4436    
4437     static int __init populate_rootfs(void)
4438     {
4439     + /* Load the built in initramfs */
4440     char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
4441     if (err)
4442     panic("%s", err); /* Failed to decompress INTERNAL initramfs */
4443     + /* If available load the bootloader supplied initrd */
4444     if (initrd_start) {
4445     #ifdef CONFIG_BLK_DEV_RAM
4446     int fd;
4447     @@ -640,6 +642,7 @@ static int __init populate_rootfs(void)
4448     free_initrd();
4449     }
4450     done:
4451     + /* empty statement */;
4452     #else
4453     printk(KERN_INFO "Unpacking initramfs...\n");
4454     err = unpack_to_rootfs((char *)initrd_start,
4455     @@ -648,13 +651,14 @@ static int __init populate_rootfs(void)
4456     printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
4457     free_initrd();
4458     #endif
4459     - flush_delayed_fput();
4460     - /*
4461     - * Try loading default modules from initramfs. This gives
4462     - * us a chance to load before device_initcalls.
4463     - */
4464     - load_default_modules();
4465     }
4466     + flush_delayed_fput();
4467     + /*
4468     + * Try loading default modules from initramfs. This gives
4469     + * us a chance to load before device_initcalls.
4470     + */
4471     + load_default_modules();
4472     +
4473     return 0;
4474     }
4475     rootfs_initcall(populate_rootfs);
4476     diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
4477     index 687f5e0194ef..b507f1889a72 100644
4478     --- a/kernel/cgroup/cgroup.c
4479     +++ b/kernel/cgroup/cgroup.c
4480     @@ -438,6 +438,11 @@ struct cgroup_subsys_state *cgroup_get_e_css(struct cgroup *cgrp,
4481    
4482     static void cgroup_get(struct cgroup *cgrp)
4483     {
4484     + css_get(&cgrp->self);
4485     +}
4486     +
4487     +static void cgroup_get_live(struct cgroup *cgrp)
4488     +{
4489     WARN_ON_ONCE(cgroup_is_dead(cgrp));
4490     css_get(&cgrp->self);
4491     }
4492     @@ -932,7 +937,7 @@ static void link_css_set(struct list_head *tmp_links, struct css_set *cset,
4493     list_add_tail(&link->cgrp_link, &cset->cgrp_links);
4494    
4495     if (cgroup_parent(cgrp))
4496     - cgroup_get(cgrp);
4497     + cgroup_get_live(cgrp);
4498     }
4499    
4500     /**
4501     @@ -1802,7 +1807,7 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
4502     return ERR_PTR(-EINVAL);
4503     }
4504     cgrp_dfl_visible = true;
4505     - cgroup_get(&cgrp_dfl_root.cgrp);
4506     + cgroup_get_live(&cgrp_dfl_root.cgrp);
4507    
4508     dentry = cgroup_do_mount(&cgroup2_fs_type, flags, &cgrp_dfl_root,
4509     CGROUP2_SUPER_MAGIC, ns);
4510     @@ -2576,7 +2581,7 @@ void cgroup_lock_and_drain_offline(struct cgroup *cgrp)
4511     if (!css || !percpu_ref_is_dying(&css->refcnt))
4512     continue;
4513    
4514     - cgroup_get(dsct);
4515     + cgroup_get_live(dsct);
4516     prepare_to_wait(&dsct->offline_waitq, &wait,
4517     TASK_UNINTERRUPTIBLE);
4518    
4519     @@ -3947,7 +3952,7 @@ static void init_and_link_css(struct cgroup_subsys_state *css,
4520     {
4521     lockdep_assert_held(&cgroup_mutex);
4522    
4523     - cgroup_get(cgrp);
4524     + cgroup_get_live(cgrp);
4525    
4526     memset(css, 0, sizeof(*css));
4527     css->cgroup = cgrp;
4528     @@ -4123,7 +4128,7 @@ static struct cgroup *cgroup_create(struct cgroup *parent)
4529     /* allocation complete, commit to creation */
4530     list_add_tail_rcu(&cgrp->self.sibling, &cgroup_parent(cgrp)->self.children);
4531     atomic_inc(&root->nr_cgrps);
4532     - cgroup_get(parent);
4533     + cgroup_get_live(parent);
4534    
4535     /*
4536     * @cgrp is now fully operational. If something fails after this
4537     @@ -4947,7 +4952,7 @@ struct cgroup *cgroup_get_from_path(const char *path)
4538     if (kn) {
4539     if (kernfs_type(kn) == KERNFS_DIR) {
4540     cgrp = kn->priv;
4541     - cgroup_get(cgrp);
4542     + cgroup_get_live(cgrp);
4543     } else {
4544     cgrp = ERR_PTR(-ENOTDIR);
4545     }
4546     @@ -5027,6 +5032,11 @@ void cgroup_sk_alloc(struct sock_cgroup_data *skcd)
4547    
4548     /* Socket clone path */
4549     if (skcd->val) {
4550     + /*
4551     + * We might be cloning a socket which is left in an empty
4552     + * cgroup and the cgroup might have already been rmdir'd.
4553     + * Don't use cgroup_get_live().
4554     + */
4555     cgroup_get(sock_cgroup_ptr(skcd));
4556     return;
4557     }
4558     diff --git a/kernel/padata.c b/kernel/padata.c
4559     index 3202aa17492c..f1aef1639204 100644
4560     --- a/kernel/padata.c
4561     +++ b/kernel/padata.c
4562     @@ -354,7 +354,7 @@ static int padata_setup_cpumasks(struct parallel_data *pd,
4563    
4564     cpumask_and(pd->cpumask.pcpu, pcpumask, cpu_online_mask);
4565     if (!alloc_cpumask_var(&pd->cpumask.cbcpu, GFP_KERNEL)) {
4566     - free_cpumask_var(pd->cpumask.cbcpu);
4567     + free_cpumask_var(pd->cpumask.pcpu);
4568     return -ENOMEM;
4569     }
4570    
4571     diff --git a/mm/filemap.c b/mm/filemap.c
4572     index 1694623a6289..157c047b180a 100644
4573     --- a/mm/filemap.c
4574     +++ b/mm/filemap.c
4575     @@ -2719,18 +2719,16 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
4576     * about to write. We do this *before* the write so that we can return
4577     * without clobbering -EIOCBQUEUED from ->direct_IO().
4578     */
4579     - if (mapping->nrpages) {
4580     - written = invalidate_inode_pages2_range(mapping,
4581     + written = invalidate_inode_pages2_range(mapping,
4582     pos >> PAGE_SHIFT, end);
4583     - /*
4584     - * If a page can not be invalidated, return 0 to fall back
4585     - * to buffered write.
4586     - */
4587     - if (written) {
4588     - if (written == -EBUSY)
4589     - return 0;
4590     - goto out;
4591     - }
4592     + /*
4593     + * If a page can not be invalidated, return 0 to fall back
4594     + * to buffered write.
4595     + */
4596     + if (written) {
4597     + if (written == -EBUSY)
4598     + return 0;
4599     + goto out;
4600     }
4601    
4602     data = *from;
4603     @@ -2744,10 +2742,8 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
4604     * so we don't support it 100%. If this invalidation
4605     * fails, tough, the write still worked...
4606     */
4607     - if (mapping->nrpages) {
4608     - invalidate_inode_pages2_range(mapping,
4609     - pos >> PAGE_SHIFT, end);
4610     - }
4611     + invalidate_inode_pages2_range(mapping,
4612     + pos >> PAGE_SHIFT, end);
4613    
4614     if (written > 0) {
4615     pos += written;
4616     diff --git a/mm/memcontrol.c b/mm/memcontrol.c
4617     index 2bd7541d7c11..a4b8fc7aaf80 100644
4618     --- a/mm/memcontrol.c
4619     +++ b/mm/memcontrol.c
4620     @@ -568,23 +568,6 @@ mem_cgroup_largest_soft_limit_node(struct mem_cgroup_tree_per_node *mctz)
4621     * common workload, threshold and synchronization as vmstat[] should be
4622     * implemented.
4623     */
4624     -static unsigned long
4625     -mem_cgroup_read_stat(struct mem_cgroup *memcg, enum mem_cgroup_stat_index idx)
4626     -{
4627     - long val = 0;
4628     - int cpu;
4629     -
4630     - /* Per-cpu values can be negative, use a signed accumulator */
4631     - for_each_possible_cpu(cpu)
4632     - val += per_cpu(memcg->stat->count[idx], cpu);
4633     - /*
4634     - * Summing races with updates, so val may be negative. Avoid exposing
4635     - * transient negative values.
4636     - */
4637     - if (val < 0)
4638     - val = 0;
4639     - return val;
4640     -}
4641    
4642     static unsigned long mem_cgroup_read_events(struct mem_cgroup *memcg,
4643     enum mem_cgroup_events_index idx)
4644     @@ -5237,6 +5220,13 @@ static int memory_stat_show(struct seq_file *m, void *v)
4645     seq_printf(m, "pgmajfault %lu\n",
4646     events[MEM_CGROUP_EVENTS_PGMAJFAULT]);
4647    
4648     + seq_printf(m, "workingset_refault %lu\n",
4649     + stat[MEMCG_WORKINGSET_REFAULT]);
4650     + seq_printf(m, "workingset_activate %lu\n",
4651     + stat[MEMCG_WORKINGSET_ACTIVATE]);
4652     + seq_printf(m, "workingset_nodereclaim %lu\n",
4653     + stat[MEMCG_WORKINGSET_NODERECLAIM]);
4654     +
4655     return 0;
4656     }
4657    
4658     diff --git a/mm/page_alloc.c b/mm/page_alloc.c
4659     index 07efbc3a8656..c5fee5a0316d 100644
4660     --- a/mm/page_alloc.c
4661     +++ b/mm/page_alloc.c
4662     @@ -3245,6 +3245,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
4663     enum compact_priority prio, enum compact_result *compact_result)
4664     {
4665     struct page *page;
4666     + unsigned int noreclaim_flag = current->flags & PF_MEMALLOC;
4667    
4668     if (!order)
4669     return NULL;
4670     @@ -3252,7 +3253,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
4671     current->flags |= PF_MEMALLOC;
4672     *compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac,
4673     prio);
4674     - current->flags &= ~PF_MEMALLOC;
4675     + current->flags = (current->flags & ~PF_MEMALLOC) | noreclaim_flag;
4676    
4677     if (*compact_result <= COMPACT_INACTIVE)
4678     return NULL;
4679     diff --git a/mm/truncate.c b/mm/truncate.c
4680     index 6263affdef88..5f1c4b65239e 100644
4681     --- a/mm/truncate.c
4682     +++ b/mm/truncate.c
4683     @@ -67,17 +67,14 @@ static void truncate_exceptional_entry(struct address_space *mapping,
4684    
4685     /*
4686     * Invalidate exceptional entry if easily possible. This handles exceptional
4687     - * entries for invalidate_inode_pages() so for DAX it evicts only unlocked and
4688     - * clean entries.
4689     + * entries for invalidate_inode_pages().
4690     */
4691     static int invalidate_exceptional_entry(struct address_space *mapping,
4692     pgoff_t index, void *entry)
4693     {
4694     - /* Handled by shmem itself */
4695     - if (shmem_mapping(mapping))
4696     + /* Handled by shmem itself, or for DAX we do nothing. */
4697     + if (shmem_mapping(mapping) || dax_mapping(mapping))
4698     return 1;
4699     - if (dax_mapping(mapping))
4700     - return dax_invalidate_mapping_entry(mapping, index);
4701     clear_shadow_entry(mapping, index, entry);
4702     return 1;
4703     }
4704     @@ -686,6 +683,17 @@ int invalidate_inode_pages2_range(struct address_space *mapping,
4705     cond_resched();
4706     index++;
4707     }
4708     + /*
4709     + * For DAX we invalidate page tables after invalidating radix tree. We
4710     + * could invalidate page tables while invalidating each entry however
4711     + * that would be expensive. And doing range unmapping before doesn't
4712     + * work as we have no cheap way to find whether radix tree entry didn't
4713     + * get remapped later.
4714     + */
4715     + if (dax_mapping(mapping)) {
4716     + unmap_mapping_range(mapping, (loff_t)start << PAGE_SHIFT,
4717     + (loff_t)(end - start + 1) << PAGE_SHIFT, 0);
4718     + }
4719     cleancache_invalidate_inode(mapping);
4720     return ret;
4721     }
4722     diff --git a/mm/vmscan.c b/mm/vmscan.c
4723     index bc8031ef994d..1345d5fba4a2 100644
4724     --- a/mm/vmscan.c
4725     +++ b/mm/vmscan.c
4726     @@ -2033,6 +2033,8 @@ static void shrink_active_list(unsigned long nr_to_scan,
4727     * Both inactive lists should also be large enough that each inactive
4728     * page has a chance to be referenced again before it is reclaimed.
4729     *
4730     + * If that fails and refaulting is observed, the inactive list grows.
4731     + *
4732     * The inactive_ratio is the target ratio of ACTIVE to INACTIVE pages
4733     * on this LRU, maintained by the pageout code. A zone->inactive_ratio
4734     * of 3 means 3:1 or 25% of the pages are kept on the inactive list.
4735     @@ -2049,12 +2051,15 @@ static void shrink_active_list(unsigned long nr_to_scan,
4736     * 10TB 320 32GB
4737     */
4738     static bool inactive_list_is_low(struct lruvec *lruvec, bool file,
4739     - struct scan_control *sc, bool trace)
4740     + struct mem_cgroup *memcg,
4741     + struct scan_control *sc, bool actual_reclaim)
4742     {
4743     - unsigned long inactive_ratio;
4744     - unsigned long inactive, active;
4745     - enum lru_list inactive_lru = file * LRU_FILE;
4746     enum lru_list active_lru = file * LRU_FILE + LRU_ACTIVE;
4747     + struct pglist_data *pgdat = lruvec_pgdat(lruvec);
4748     + enum lru_list inactive_lru = file * LRU_FILE;
4749     + unsigned long inactive, active;
4750     + unsigned long inactive_ratio;
4751     + unsigned long refaults;
4752     unsigned long gb;
4753    
4754     /*
4755     @@ -2067,27 +2072,43 @@ static bool inactive_list_is_low(struct lruvec *lruvec, bool file,
4756     inactive = lruvec_lru_size(lruvec, inactive_lru, sc->reclaim_idx);
4757     active = lruvec_lru_size(lruvec, active_lru, sc->reclaim_idx);
4758    
4759     - gb = (inactive + active) >> (30 - PAGE_SHIFT);
4760     - if (gb)
4761     - inactive_ratio = int_sqrt(10 * gb);
4762     + if (memcg)
4763     + refaults = mem_cgroup_read_stat(memcg,
4764     + MEMCG_WORKINGSET_ACTIVATE);
4765     else
4766     - inactive_ratio = 1;
4767     + refaults = node_page_state(pgdat, WORKINGSET_ACTIVATE);
4768     +
4769     + /*
4770     + * When refaults are being observed, it means a new workingset
4771     + * is being established. Disable active list protection to get
4772     + * rid of the stale workingset quickly.
4773     + */
4774     + if (file && actual_reclaim && lruvec->refaults != refaults) {
4775     + inactive_ratio = 0;
4776     + } else {
4777     + gb = (inactive + active) >> (30 - PAGE_SHIFT);
4778     + if (gb)
4779     + inactive_ratio = int_sqrt(10 * gb);
4780     + else
4781     + inactive_ratio = 1;
4782     + }
4783    
4784     - if (trace)
4785     - trace_mm_vmscan_inactive_list_is_low(lruvec_pgdat(lruvec)->node_id,
4786     - sc->reclaim_idx,
4787     - lruvec_lru_size(lruvec, inactive_lru, MAX_NR_ZONES), inactive,
4788     - lruvec_lru_size(lruvec, active_lru, MAX_NR_ZONES), active,
4789     - inactive_ratio, file);
4790     + if (actual_reclaim)
4791     + trace_mm_vmscan_inactive_list_is_low(pgdat->node_id, sc->reclaim_idx,
4792     + lruvec_lru_size(lruvec, inactive_lru, MAX_NR_ZONES), inactive,
4793     + lruvec_lru_size(lruvec, active_lru, MAX_NR_ZONES), active,
4794     + inactive_ratio, file);
4795    
4796     return inactive * inactive_ratio < active;
4797     }
4798    
4799     static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
4800     - struct lruvec *lruvec, struct scan_control *sc)
4801     + struct lruvec *lruvec, struct mem_cgroup *memcg,
4802     + struct scan_control *sc)
4803     {
4804     if (is_active_lru(lru)) {
4805     - if (inactive_list_is_low(lruvec, is_file_lru(lru), sc, true))
4806     + if (inactive_list_is_low(lruvec, is_file_lru(lru),
4807     + memcg, sc, true))
4808     shrink_active_list(nr_to_scan, lruvec, sc, lru);
4809     return 0;
4810     }
4811     @@ -2218,7 +2239,7 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg,
4812     * lruvec even if it has plenty of old anonymous pages unless the
4813     * system is under heavy pressure.
4814     */
4815     - if (!inactive_list_is_low(lruvec, true, sc, false) &&
4816     + if (!inactive_list_is_low(lruvec, true, memcg, sc, false) &&
4817     lruvec_lru_size(lruvec, LRU_INACTIVE_FILE, sc->reclaim_idx) >> sc->priority) {
4818     scan_balance = SCAN_FILE;
4819     goto out;
4820     @@ -2376,7 +2397,7 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc
4821     nr[lru] -= nr_to_scan;
4822    
4823     nr_reclaimed += shrink_list(lru, nr_to_scan,
4824     - lruvec, sc);
4825     + lruvec, memcg, sc);
4826     }
4827     }
4828    
4829     @@ -2443,7 +2464,7 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc
4830     * Even if we did not try to evict anon pages at all, we want to
4831     * rebalance the anon lru active/inactive ratio.
4832     */
4833     - if (inactive_list_is_low(lruvec, false, sc, true))
4834     + if (inactive_list_is_low(lruvec, false, memcg, sc, true))
4835     shrink_active_list(SWAP_CLUSTER_MAX, lruvec,
4836     sc, LRU_ACTIVE_ANON);
4837     }
4838     @@ -2752,6 +2773,26 @@ static void shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
4839     sc->gfp_mask = orig_mask;
4840     }
4841    
4842     +static void snapshot_refaults(struct mem_cgroup *root_memcg, pg_data_t *pgdat)
4843     +{
4844     + struct mem_cgroup *memcg;
4845     +
4846     + memcg = mem_cgroup_iter(root_memcg, NULL, NULL);
4847     + do {
4848     + unsigned long refaults;
4849     + struct lruvec *lruvec;
4850     +
4851     + if (memcg)
4852     + refaults = mem_cgroup_read_stat(memcg,
4853     + MEMCG_WORKINGSET_ACTIVATE);
4854     + else
4855     + refaults = node_page_state(pgdat, WORKINGSET_ACTIVATE);
4856     +
4857     + lruvec = mem_cgroup_lruvec(pgdat, memcg);
4858     + lruvec->refaults = refaults;
4859     + } while ((memcg = mem_cgroup_iter(root_memcg, memcg, NULL)));
4860     +}
4861     +
4862     /*
4863     * This is the main entry point to direct page reclaim.
4864     *
4865     @@ -2772,6 +2813,9 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
4866     struct scan_control *sc)
4867     {
4868     int initial_priority = sc->priority;
4869     + pg_data_t *last_pgdat;
4870     + struct zoneref *z;
4871     + struct zone *zone;
4872     retry:
4873     delayacct_freepages_start();
4874    
4875     @@ -2798,6 +2842,15 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
4876     sc->may_writepage = 1;
4877     } while (--sc->priority >= 0);
4878    
4879     + last_pgdat = NULL;
4880     + for_each_zone_zonelist_nodemask(zone, z, zonelist, sc->reclaim_idx,
4881     + sc->nodemask) {
4882     + if (zone->zone_pgdat == last_pgdat)
4883     + continue;
4884     + last_pgdat = zone->zone_pgdat;
4885     + snapshot_refaults(sc->target_mem_cgroup, zone->zone_pgdat);
4886     + }
4887     +
4888     delayacct_freepages_end();
4889    
4890     if (sc->nr_reclaimed)
4891     @@ -3076,7 +3129,7 @@ static void age_active_anon(struct pglist_data *pgdat,
4892     do {
4893     struct lruvec *lruvec = mem_cgroup_lruvec(pgdat, memcg);
4894    
4895     - if (inactive_list_is_low(lruvec, false, sc, true))
4896     + if (inactive_list_is_low(lruvec, false, memcg, sc, true))
4897     shrink_active_list(SWAP_CLUSTER_MAX, lruvec,
4898     sc, LRU_ACTIVE_ANON);
4899    
4900     @@ -3311,6 +3364,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx)
4901     } while (sc.priority >= 1);
4902    
4903     out:
4904     + snapshot_refaults(NULL, pgdat);
4905     /*
4906     * Return the order kswapd stopped reclaiming at as
4907     * prepare_kswapd_sleep() takes it into account. If another caller
4908     diff --git a/mm/workingset.c b/mm/workingset.c
4909     index eda05c71fa49..51c6f61d4cea 100644
4910     --- a/mm/workingset.c
4911     +++ b/mm/workingset.c
4912     @@ -269,7 +269,6 @@ bool workingset_refault(void *shadow)
4913     lruvec = mem_cgroup_lruvec(pgdat, memcg);
4914     refault = atomic_long_read(&lruvec->inactive_age);
4915     active_file = lruvec_lru_size(lruvec, LRU_ACTIVE_FILE, MAX_NR_ZONES);
4916     - rcu_read_unlock();
4917    
4918     /*
4919     * The unsigned subtraction here gives an accurate distance
4920     @@ -290,11 +289,15 @@ bool workingset_refault(void *shadow)
4921     refault_distance = (refault - eviction) & EVICTION_MASK;
4922    
4923     inc_node_state(pgdat, WORKINGSET_REFAULT);
4924     + mem_cgroup_inc_stat(memcg, MEMCG_WORKINGSET_REFAULT);
4925    
4926     if (refault_distance <= active_file) {
4927     inc_node_state(pgdat, WORKINGSET_ACTIVATE);
4928     + mem_cgroup_inc_stat(memcg, MEMCG_WORKINGSET_ACTIVATE);
4929     + rcu_read_unlock();
4930     return true;
4931     }
4932     + rcu_read_unlock();
4933     return false;
4934     }
4935    
4936     @@ -472,6 +475,8 @@ static enum lru_status shadow_lru_isolate(struct list_head *item,
4937     if (WARN_ON_ONCE(node->exceptional))
4938     goto out_invalid;
4939     inc_node_state(page_pgdat(virt_to_page(node)), WORKINGSET_NODERECLAIM);
4940     + mem_cgroup_inc_page_stat(virt_to_page(node),
4941     + MEMCG_WORKINGSET_NODERECLAIM);
4942     __radix_tree_delete_node(&mapping->page_tree, node,
4943     workingset_update_node, mapping);
4944    
4945     diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
4946     index f64d6566021f..638bf0e1a2e3 100644
4947     --- a/net/bluetooth/hci_sock.c
4948     +++ b/net/bluetooth/hci_sock.c
4949     @@ -1680,7 +1680,8 @@ static int hci_sock_sendmsg(struct socket *sock, struct msghdr *msg,
4950     if (msg->msg_flags & MSG_OOB)
4951     return -EOPNOTSUPP;
4952    
4953     - if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_NOSIGNAL|MSG_ERRQUEUE))
4954     + if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_NOSIGNAL|MSG_ERRQUEUE|
4955     + MSG_CMSG_COMPAT))
4956     return -EINVAL;
4957    
4958     if (len < 4 || len > HCI_MAX_FRAME_SIZE)
4959     diff --git a/net/core/datagram.c b/net/core/datagram.c
4960     index f4947e737f34..d797baa69e43 100644
4961     --- a/net/core/datagram.c
4962     +++ b/net/core/datagram.c
4963     @@ -760,7 +760,7 @@ int skb_copy_and_csum_datagram_msg(struct sk_buff *skb,
4964    
4965     if (msg_data_left(msg) < chunk) {
4966     if (__skb_checksum_complete(skb))
4967     - goto csum_error;
4968     + return -EINVAL;
4969     if (skb_copy_datagram_msg(skb, hlen, msg, chunk))
4970     goto fault;
4971     } else {
4972     @@ -768,15 +768,16 @@ int skb_copy_and_csum_datagram_msg(struct sk_buff *skb,
4973     if (skb_copy_and_csum_datagram(skb, hlen, &msg->msg_iter,
4974     chunk, &csum))
4975     goto fault;
4976     - if (csum_fold(csum))
4977     - goto csum_error;
4978     +
4979     + if (csum_fold(csum)) {
4980     + iov_iter_revert(&msg->msg_iter, chunk);
4981     + return -EINVAL;
4982     + }
4983     +
4984     if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE))
4985     netdev_rx_csum_fault(skb->dev);
4986     }
4987     return 0;
4988     -csum_error:
4989     - iov_iter_revert(&msg->msg_iter, chunk);
4990     - return -EINVAL;
4991     fault:
4992     return -EFAULT;
4993     }
4994     diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/arch/s390/annotate/instructions.c
4995     new file mode 100644
4996     index 000000000000..745b4b1b8b21
4997     --- /dev/null
4998     +++ b/tools/perf/arch/s390/annotate/instructions.c
4999     @@ -0,0 +1,30 @@
5000     +static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const char *name)
5001     +{
5002     + struct ins_ops *ops = NULL;
5003     +
5004     + /* catch all kind of jumps */
5005     + if (strchr(name, 'j') ||
5006     + !strncmp(name, "bct", 3) ||
5007     + !strncmp(name, "br", 2))
5008     + ops = &jump_ops;
5009     + /* override call/returns */
5010     + if (!strcmp(name, "bras") ||
5011     + !strcmp(name, "brasl") ||
5012     + !strcmp(name, "basr"))
5013     + ops = &call_ops;
5014     + if (!strcmp(name, "br"))
5015     + ops = &ret_ops;
5016     +
5017     + arch__associate_ins_ops(arch, name, ops);
5018     + return ops;
5019     +}
5020     +
5021     +static int s390__annotate_init(struct arch *arch)
5022     +{
5023     + if (!arch->initialized) {
5024     + arch->initialized = true;
5025     + arch->associate_instruction_ops = s390__associate_ins_ops;
5026     + }
5027     +
5028     + return 0;
5029     +}
5030     diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
5031     index 7aa57225cbf7..83c57a11dc5b 100644
5032     --- a/tools/perf/util/annotate.c
5033     +++ b/tools/perf/util/annotate.c
5034     @@ -108,6 +108,7 @@ static int arch__associate_ins_ops(struct arch* arch, const char *name, struct i
5035     #include "arch/arm64/annotate/instructions.c"
5036     #include "arch/x86/annotate/instructions.c"
5037     #include "arch/powerpc/annotate/instructions.c"
5038     +#include "arch/s390/annotate/instructions.c"
5039    
5040     static struct arch architectures[] = {
5041     {
5042     @@ -132,6 +133,13 @@ static struct arch architectures[] = {
5043     },
5044     {
5045     .name = "s390",
5046     + .init = s390__annotate_init,
5047     + .objdump = {
5048     + .comment_char = '#',
5049     + },
5050     + },
5051     + {
5052     + .name = "s390",
5053     .objdump = {
5054     .comment_char = '#',
5055     },
5056     diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
5057     index c5a6e0b12452..78bd632f144d 100644
5058     --- a/tools/perf/util/auxtrace.c
5059     +++ b/tools/perf/util/auxtrace.c
5060     @@ -1826,7 +1826,7 @@ static int addr_filter__resolve_kernel_syms(struct addr_filter *filt)
5061     filt->addr = start;
5062     if (filt->range && !filt->size && !filt->sym_to) {
5063     filt->size = size;
5064     - no_size = !!size;
5065     + no_size = !size;
5066     }
5067     }
5068    
5069     @@ -1840,7 +1840,7 @@ static int addr_filter__resolve_kernel_syms(struct addr_filter *filt)
5070     if (err)
5071     return err;
5072     filt->size = start + size - filt->addr;
5073     - no_size = !!size;
5074     + no_size = !size;
5075     }
5076    
5077     /* The very last symbol in kallsyms does not imply a particular size */
5078     diff --git a/tools/testing/selftests/x86/ldt_gdt.c b/tools/testing/selftests/x86/ldt_gdt.c
5079     index f6121612e769..b9a22f18566a 100644
5080     --- a/tools/testing/selftests/x86/ldt_gdt.c
5081     +++ b/tools/testing/selftests/x86/ldt_gdt.c
5082     @@ -409,6 +409,51 @@ static void *threadproc(void *ctx)
5083     }
5084     }
5085    
5086     +#ifdef __i386__
5087     +
5088     +#ifndef SA_RESTORE
5089     +#define SA_RESTORER 0x04000000
5090     +#endif
5091     +
5092     +/*
5093     + * The UAPI header calls this 'struct sigaction', which conflicts with
5094     + * glibc. Sigh.
5095     + */
5096     +struct fake_ksigaction {
5097     + void *handler; /* the real type is nasty */
5098     + unsigned long sa_flags;
5099     + void (*sa_restorer)(void);
5100     + unsigned char sigset[8];
5101     +};
5102     +
5103     +static void fix_sa_restorer(int sig)
5104     +{
5105     + struct fake_ksigaction ksa;
5106     +
5107     + if (syscall(SYS_rt_sigaction, sig, NULL, &ksa, 8) == 0) {
5108     + /*
5109     + * glibc has a nasty bug: it sometimes writes garbage to
5110     + * sa_restorer. This interacts quite badly with anything
5111     + * that fiddles with SS because it can trigger legacy
5112     + * stack switching. Patch it up. See:
5113     + *
5114     + * https://sourceware.org/bugzilla/show_bug.cgi?id=21269
5115     + */
5116     + if (!(ksa.sa_flags & SA_RESTORER) && ksa.sa_restorer) {
5117     + ksa.sa_restorer = NULL;
5118     + if (syscall(SYS_rt_sigaction, sig, &ksa, NULL,
5119     + sizeof(ksa.sigset)) != 0)
5120     + err(1, "rt_sigaction");
5121     + }
5122     + }
5123     +}
5124     +#else
5125     +static void fix_sa_restorer(int sig)
5126     +{
5127     + /* 64-bit glibc works fine. */
5128     +}
5129     +#endif
5130     +
5131     static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
5132     int flags)
5133     {
5134     @@ -420,6 +465,7 @@ static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
5135     if (sigaction(sig, &sa, 0))
5136     err(1, "sigaction");
5137    
5138     + fix_sa_restorer(sig);
5139     }
5140    
5141     static jmp_buf jmpbuf;
5142     diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
5143     index 88257b311cb5..7e80f62f034c 100644
5144     --- a/virt/kvm/kvm_main.c
5145     +++ b/virt/kvm/kvm_main.c
5146     @@ -1973,18 +1973,18 @@ static int __kvm_gfn_to_hva_cache_init(struct kvm_memslots *slots,
5147     return 0;
5148     }
5149    
5150     -int kvm_vcpu_gfn_to_hva_cache_init(struct kvm_vcpu *vcpu, struct gfn_to_hva_cache *ghc,
5151     +int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
5152     gpa_t gpa, unsigned long len)
5153     {
5154     - struct kvm_memslots *slots = kvm_vcpu_memslots(vcpu);
5155     + struct kvm_memslots *slots = kvm_memslots(kvm);
5156     return __kvm_gfn_to_hva_cache_init(slots, ghc, gpa, len);
5157     }
5158     -EXPORT_SYMBOL_GPL(kvm_vcpu_gfn_to_hva_cache_init);
5159     +EXPORT_SYMBOL_GPL(kvm_gfn_to_hva_cache_init);
5160    
5161     -int kvm_vcpu_write_guest_offset_cached(struct kvm_vcpu *vcpu, struct gfn_to_hva_cache *ghc,
5162     - void *data, int offset, unsigned long len)
5163     +int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
5164     + void *data, int offset, unsigned long len)
5165     {
5166     - struct kvm_memslots *slots = kvm_vcpu_memslots(vcpu);
5167     + struct kvm_memslots *slots = kvm_memslots(kvm);
5168     int r;
5169     gpa_t gpa = ghc->gpa + offset;
5170    
5171     @@ -1994,7 +1994,7 @@ int kvm_vcpu_write_guest_offset_cached(struct kvm_vcpu *vcpu, struct gfn_to_hva_
5172     __kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len);
5173    
5174     if (unlikely(!ghc->memslot))
5175     - return kvm_vcpu_write_guest(vcpu, gpa, data, len);
5176     + return kvm_write_guest(kvm, gpa, data, len);
5177    
5178     if (kvm_is_error_hva(ghc->hva))
5179     return -EFAULT;
5180     @@ -2006,19 +2006,19 @@ int kvm_vcpu_write_guest_offset_cached(struct kvm_vcpu *vcpu, struct gfn_to_hva_
5181    
5182     return 0;
5183     }
5184     -EXPORT_SYMBOL_GPL(kvm_vcpu_write_guest_offset_cached);
5185     +EXPORT_SYMBOL_GPL(kvm_write_guest_offset_cached);
5186    
5187     -int kvm_vcpu_write_guest_cached(struct kvm_vcpu *vcpu, struct gfn_to_hva_cache *ghc,
5188     - void *data, unsigned long len)
5189     +int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
5190     + void *data, unsigned long len)
5191     {
5192     - return kvm_vcpu_write_guest_offset_cached(vcpu, ghc, data, 0, len);
5193     + return kvm_write_guest_offset_cached(kvm, ghc, data, 0, len);
5194     }
5195     -EXPORT_SYMBOL_GPL(kvm_vcpu_write_guest_cached);
5196     +EXPORT_SYMBOL_GPL(kvm_write_guest_cached);
5197    
5198     -int kvm_vcpu_read_guest_cached(struct kvm_vcpu *vcpu, struct gfn_to_hva_cache *ghc,
5199     - void *data, unsigned long len)
5200     +int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
5201     + void *data, unsigned long len)
5202     {
5203     - struct kvm_memslots *slots = kvm_vcpu_memslots(vcpu);
5204     + struct kvm_memslots *slots = kvm_memslots(kvm);
5205     int r;
5206    
5207     BUG_ON(len > ghc->len);
5208     @@ -2027,7 +2027,7 @@ int kvm_vcpu_read_guest_cached(struct kvm_vcpu *vcpu, struct gfn_to_hva_cache *g
5209     __kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len);
5210    
5211     if (unlikely(!ghc->memslot))
5212     - return kvm_vcpu_read_guest(vcpu, ghc->gpa, data, len);
5213     + return kvm_read_guest(kvm, ghc->gpa, data, len);
5214    
5215     if (kvm_is_error_hva(ghc->hva))
5216     return -EFAULT;
5217     @@ -2038,7 +2038,7 @@ int kvm_vcpu_read_guest_cached(struct kvm_vcpu *vcpu, struct gfn_to_hva_cache *g
5218    
5219     return 0;
5220     }
5221     -EXPORT_SYMBOL_GPL(kvm_vcpu_read_guest_cached);
5222     +EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
5223    
5224     int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
5225     {