diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arc/include/asm/delay.h linux-libre-4.8.13-gnu/arch/arc/include/asm/delay.h
--- linux-libre-4.8.12-gnu/arch/arc/include/asm/delay.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arc/include/asm/delay.h	2016-12-08 01:16:36.000000000 -0500
@@ -22,10 +22,11 @@
 static inline void __delay(unsigned long loops)
 {
 	__asm__ __volatile__(
-	"	lp  1f	\n"
-	"	nop	\n"
-	"1:		\n"
-	: "+l"(loops));
+	"	mov lp_count, %0	\n"
+	"	lp  1f			\n"
+	"	nop			\n"
+	"1:				\n"
+	: : "r"(loops));
 }
 
 extern void __bad_udelay(void);
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arc/include/asm/pgtable.h linux-libre-4.8.13-gnu/arch/arc/include/asm/pgtable.h
--- linux-libre-4.8.12-gnu/arch/arc/include/asm/pgtable.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arc/include/asm/pgtable.h	2016-12-08 01:16:36.000000000 -0500
@@ -280,7 +280,7 @@ static inline void pmd_set(pmd_t *pmdp,
 
 #define pte_page(pte)		pfn_to_page(pte_pfn(pte))
 #define mk_pte(page, prot)	pfn_pte(page_to_pfn(page), prot)
-#define pfn_pte(pfn, prot)	__pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
+#define pfn_pte(pfn, prot)	__pte(__pfn_to_phys(pfn) | pgprot_val(prot))
 
 /* Don't use virt_to_pfn for macros below: could cause truncations for PAE40*/
 #define pte_pfn(pte)		(pte_val(pte) >> PAGE_SHIFT)
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arm64/boot/dts/arm/juno.dts linux-libre-4.8.13-gnu/arch/arm64/boot/dts/arm/juno.dts
--- linux-libre-4.8.12-gnu/arch/arm64/boot/dts/arm/juno.dts	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arm64/boot/dts/arm/juno.dts	2016-12-08 01:16:36.000000000 -0500
@@ -76,7 +76,7 @@
 				compatible = "arm,idle-state";
 				arm,psci-suspend-param = <0x1010000>;
 				local-timer-stop;
-				entry-latency-us = <300>;
+				entry-latency-us = <400>;
 				exit-latency-us = <1200>;
 				min-residency-us = <2500>;
 			};
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arm64/boot/dts/arm/juno-r1.dts linux-libre-4.8.13-gnu/arch/arm64/boot/dts/arm/juno-r1.dts
--- linux-libre-4.8.12-gnu/arch/arm64/boot/dts/arm/juno-r1.dts	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arm64/boot/dts/arm/juno-r1.dts	2016-12-08 01:16:36.000000000 -0500
@@ -76,7 +76,7 @@
 				compatible = "arm,idle-state";
 				arm,psci-suspend-param = <0x1010000>;
 				local-timer-stop;
-				entry-latency-us = <300>;
+				entry-latency-us = <400>;
 				exit-latency-us = <1200>;
 				min-residency-us = <2500>;
 			};
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arm64/boot/dts/arm/juno-r2.dts linux-libre-4.8.13-gnu/arch/arm64/boot/dts/arm/juno-r2.dts
--- linux-libre-4.8.12-gnu/arch/arm64/boot/dts/arm/juno-r2.dts	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arm64/boot/dts/arm/juno-r2.dts	2016-12-08 01:16:36.000000000 -0500
@@ -76,7 +76,7 @@
 				compatible = "arm,idle-state";
 				arm,psci-suspend-param = <0x1010000>;
 				local-timer-stop;
-				entry-latency-us = <300>;
+				entry-latency-us = <400>;
 				exit-latency-us = <1200>;
 				min-residency-us = <2500>;
 			};
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arm64/include/asm/cpufeature.h linux-libre-4.8.13-gnu/arch/arm64/include/asm/cpufeature.h
--- linux-libre-4.8.12-gnu/arch/arm64/include/asm/cpufeature.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arm64/include/asm/cpufeature.h	2016-12-08 01:16:36.000000000 -0500
@@ -90,7 +90,7 @@ struct arm64_cpu_capabilities {
 	u16 capability;
 	int def_scope;			/* default scope */
 	bool (*matches)(const struct arm64_cpu_capabilities *caps, int scope);
-	void (*enable)(void *);		/* Called on all active CPUs */
+	int (*enable)(void *);		/* Called on all active CPUs */
 	union {
 		struct {	/* To be used for erratum handling only */
 			u32 midr_model;
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arm64/include/asm/exec.h linux-libre-4.8.13-gnu/arch/arm64/include/asm/exec.h
--- linux-libre-4.8.12-gnu/arch/arm64/include/asm/exec.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arm64/include/asm/exec.h	2016-12-08 01:16:36.000000000 -0500
@@ -18,6 +18,9 @@
 #ifndef __ASM_EXEC_H
 #define __ASM_EXEC_H
 
+#include <linux/sched.h>
+
 extern unsigned long arch_align_stack(unsigned long sp);
+void uao_thread_switch(struct task_struct *next);
 
 #endif	/* __ASM_EXEC_H */
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arm64/include/asm/processor.h linux-libre-4.8.13-gnu/arch/arm64/include/asm/processor.h
--- linux-libre-4.8.12-gnu/arch/arm64/include/asm/processor.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arm64/include/asm/processor.h	2016-12-08 01:16:36.000000000 -0500
@@ -190,8 +190,8 @@ static inline void spin_lock_prefetch(co
 
 #endif
 
-void cpu_enable_pan(void *__unused);
-void cpu_enable_uao(void *__unused);
-void cpu_enable_cache_maint_trap(void *__unused);
+int cpu_enable_pan(void *__unused);
+int cpu_enable_uao(void *__unused);
+int cpu_enable_cache_maint_trap(void *__unused);
 
 #endif /* __ASM_PROCESSOR_H */
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arm64/kernel/cpufeature.c linux-libre-4.8.13-gnu/arch/arm64/kernel/cpufeature.c
--- linux-libre-4.8.12-gnu/arch/arm64/kernel/cpufeature.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arm64/kernel/cpufeature.c	2016-12-08 01:16:36.000000000 -0500
@@ -19,7 +19,9 @@
 #define pr_fmt(fmt) "CPU features: " fmt
 
 #include <linux/bsearch.h>
+#include <linux/cpumask.h>
 #include <linux/sort.h>
+#include <linux/stop_machine.h>
 #include <linux/types.h>
 #include <asm/cpu.h>
 #include <asm/cpufeature.h>
@@ -936,7 +938,13 @@ void __init enable_cpu_capabilities(cons
 {
 	for (; caps->matches; caps++)
 		if (caps->enable && cpus_have_cap(caps->capability))
-			on_each_cpu(caps->enable, NULL, true);
+			/*
+			 * Use stop_machine() as it schedules the work allowing
+			 * us to modify PSTATE, instead of on_each_cpu() which
+			 * uses an IPI, giving us a PSTATE that disappears when
+			 * we return.
+			 */
+			stop_machine(caps->enable, NULL, cpu_online_mask);
 }
 
 /*
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arm64/kernel/process.c linux-libre-4.8.13-gnu/arch/arm64/kernel/process.c
--- linux-libre-4.8.12-gnu/arch/arm64/kernel/process.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arm64/kernel/process.c	2016-12-08 01:16:36.000000000 -0500
@@ -49,6 +49,7 @@
 #include <asm/alternative.h>
 #include <asm/compat.h>
 #include <asm/cacheflush.h>
+#include <asm/exec.h>
 #include <asm/fpsimd.h>
 #include <asm/mmu_context.h>
 #include <asm/processor.h>
@@ -303,7 +304,7 @@ static void tls_thread_switch(struct tas
 }
 
 /* Restore the UAO state depending on next's addr_limit */
-static void uao_thread_switch(struct task_struct *next)
+void uao_thread_switch(struct task_struct *next)
 {
 	if (IS_ENABLED(CONFIG_ARM64_UAO)) {
 		if (task_thread_info(next)->addr_limit == KERNEL_DS)
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arm64/kernel/suspend.c linux-libre-4.8.13-gnu/arch/arm64/kernel/suspend.c
--- linux-libre-4.8.12-gnu/arch/arm64/kernel/suspend.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arm64/kernel/suspend.c	2016-12-08 01:16:36.000000000 -0500
@@ -1,8 +1,11 @@
 #include <linux/ftrace.h>
 #include <linux/percpu.h>
 #include <linux/slab.h>
+#include <asm/alternative.h>
 #include <asm/cacheflush.h>
+#include <asm/cpufeature.h>
 #include <asm/debug-monitors.h>
+#include <asm/exec.h>
 #include <asm/pgtable.h>
 #include <asm/memory.h>
 #include <asm/mmu_context.h>
@@ -48,6 +51,14 @@ void notrace __cpu_suspend_exit(void)
 	set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
 
 	/*
+	 * PSTATE was not saved over suspend/resume, re-enable any detected
+	 * features that might not have been set correctly.
+	 */
+	asm(ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN,
+			CONFIG_ARM64_PAN));
+	uao_thread_switch(current);
+
+	/*
 	 * Restore HW breakpoint registers to sane values
 	 * before debug exceptions are possibly reenabled
 	 * through local_dbg_restore.
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arm64/kernel/traps.c linux-libre-4.8.13-gnu/arch/arm64/kernel/traps.c
--- linux-libre-4.8.12-gnu/arch/arm64/kernel/traps.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arm64/kernel/traps.c	2016-12-08 01:16:36.000000000 -0500
@@ -428,9 +428,10 @@ asmlinkage void __exception do_undefinst
 	force_signal_inject(SIGILL, ILL_ILLOPC, regs, 0);
 }
 
-void cpu_enable_cache_maint_trap(void *__unused)
+int cpu_enable_cache_maint_trap(void *__unused)
 {
 	config_sctlr_el1(SCTLR_EL1_UCI, 0);
+	return 0;
 }
 
 #define __user_cache_maint(insn, address, res)			\
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/arm64/mm/fault.c linux-libre-4.8.13-gnu/arch/arm64/mm/fault.c
--- linux-libre-4.8.12-gnu/arch/arm64/mm/fault.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/arm64/mm/fault.c	2016-12-08 01:16:36.000000000 -0500
@@ -29,7 +29,9 @@
 #include <linux/sched.h>
 #include <linux/highmem.h>
 #include <linux/perf_event.h>
+#include <linux/preempt.h>
 
+#include <asm/bug.h>
 #include <asm/cpufeature.h>
 #include <asm/exception.h>
 #include <asm/debug-monitors.h>
@@ -671,9 +673,17 @@ asmlinkage int __exception do_debug_exce
 NOKPROBE_SYMBOL(do_debug_exception);
 
 #ifdef CONFIG_ARM64_PAN
-void cpu_enable_pan(void *__unused)
+int cpu_enable_pan(void *__unused)
 {
+	/*
+	 * We modify PSTATE. This won't work from irq context as the PSTATE
+	 * is discarded once we return from the exception.
+	 */
+	WARN_ON_ONCE(in_interrupt());
+
 	config_sctlr_el1(SCTLR_EL1_SPAN, 0);
+	asm(SET_PSTATE_PAN(1));
+	return 0;
 }
 #endif /* CONFIG_ARM64_PAN */
 
@@ -684,8 +694,9 @@ void cpu_enable_pan(void *__unused)
  * We need to enable the feature at runtime (instead of adding it to
  * PSR_MODE_EL1h) as the feature may not be implemented by the cpu.
  */
-void cpu_enable_uao(void *__unused)
+int cpu_enable_uao(void *__unused)
 {
 	asm(SET_PSTATE_UAO(1));
+	return 0;
 }
 #endif /* CONFIG_ARM64_UAO */
diff -druNp --no-dereference linux-libre-4.8.12-gnu/arch/x86/events/core.c linux-libre-4.8.13-gnu/arch/x86/events/core.c
--- linux-libre-4.8.12-gnu/arch/x86/events/core.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/arch/x86/events/core.c	2016-12-08 01:16:36.000000000 -0500
@@ -2344,7 +2344,7 @@ perf_callchain_user32(struct pt_regs *re
 		frame.next_frame     = 0;
 		frame.return_address = 0;
 
-		if (!access_ok(VERIFY_READ, fp, 8))
+		if (!valid_user_frame(fp, sizeof(frame)))
 			break;
 
 		bytes = __copy_from_user_nmi(&frame.next_frame, fp, 4);
@@ -2354,9 +2354,6 @@ perf_callchain_user32(struct pt_regs *re
 		if (bytes != 0)
 			break;
 
-		if (!valid_user_frame(fp, sizeof(frame)))
-			break;
-
 		perf_callchain_store(entry, cs_base + frame.return_address);
 		fp = compat_ptr(ss_base + frame.next_frame);
 	}
@@ -2405,7 +2402,7 @@ perf_callchain_user(struct perf_callchai
 		frame.next_frame	     = NULL;
 		frame.return_address = 0;
 
-		if (!access_ok(VERIFY_READ, fp, sizeof(*fp) * 2))
+		if (!valid_user_frame(fp, sizeof(frame)))
 			break;
 
 		bytes = __copy_from_user_nmi(&frame.next_frame, fp, sizeof(*fp));
@@ -2415,9 +2412,6 @@ perf_callchain_user(struct perf_callchai
 		if (bytes != 0)
 			break;
 
-		if (!valid_user_frame(fp, sizeof(frame)))
-			break;
-
 		perf_callchain_store(entry, frame.return_address);
 		fp = (void __user *)frame.next_frame;
 	}
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/ata/libata-scsi.c linux-libre-4.8.13-gnu/drivers/ata/libata-scsi.c
--- linux-libre-4.8.12-gnu/drivers/ata/libata-scsi.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/ata/libata-scsi.c	2016-12-08 01:16:36.000000000 -0500
@@ -1088,7 +1088,7 @@ static void ata_gen_passthru_sense(struc
 		desc[1] = tf->command; /* status */
 		desc[2] = tf->device;
 		desc[3] = tf->nsect;
-		desc[0] = 0;
+		desc[7] = 0;
 		if (tf->flags & ATA_TFLAG_LBA48)  {
 			desc[8] |= 0x80;
 			if (tf->hob_nsect)
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/block/zram/zram_drv.c linux-libre-4.8.13-gnu/drivers/block/zram/zram_drv.c
--- linux-libre-4.8.12-gnu/drivers/block/zram/zram_drv.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/block/zram/zram_drv.c	2016-12-08 01:16:36.000000000 -0500
@@ -1403,7 +1403,8 @@ static ssize_t hot_remove_store(struct c
 	zram = idr_find(&zram_index_idr, dev_id);
 	if (zram) {
 		ret = zram_remove(zram);
-		idr_remove(&zram_index_idr, dev_id);
+		if (!ret)
+			idr_remove(&zram_index_idr, dev_id);
 	} else {
 		ret = -ENODEV;
 	}
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/clk/sunxi/clk-sunxi.c linux-libre-4.8.13-gnu/drivers/clk/sunxi/clk-sunxi.c
--- linux-libre-4.8.12-gnu/drivers/clk/sunxi/clk-sunxi.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/clk/sunxi/clk-sunxi.c	2016-12-08 01:16:36.000000000 -0500
@@ -373,7 +373,7 @@ static void sun4i_get_apb1_factors(struc
 	else
 		calcp = 3;
 
-	calcm = (req->parent_rate >> calcp) - 1;
+	calcm = (div >> calcp) - 1;
 
 	req->rate = (req->parent_rate >> calcp) / (calcm + 1);
 	req->m = calcm;
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c linux-libre-4.8.13-gnu/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
--- linux-libre-4.8.12-gnu/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c	2016-12-08 01:16:36.000000000 -0500
@@ -33,6 +33,7 @@ struct amdgpu_atpx {
 
 static struct amdgpu_atpx_priv {
 	bool atpx_detected;
+	bool bridge_pm_usable;
 	/* handle for device - and atpx */
 	acpi_handle dhandle;
 	acpi_handle other_handle;
@@ -200,7 +201,11 @@ static int amdgpu_atpx_validate(struct a
 	atpx->is_hybrid = false;
 	if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) {
 		printk("ATPX Hybrid Graphics\n");
-		atpx->functions.power_cntl = false;
+		/*
+		 * Disable legacy PM methods only when pcie port PM is usable,
+		 * otherwise the device might fail to power off or power on.
+		 */
+		atpx->functions.power_cntl = !amdgpu_atpx_priv.bridge_pm_usable;
 		atpx->is_hybrid = true;
 	}
 
@@ -546,17 +551,25 @@ static bool amdgpu_atpx_detect(void)
 	struct pci_dev *pdev = NULL;
 	bool has_atpx = false;
 	int vga_count = 0;
+	bool d3_supported = false;
+	struct pci_dev *parent_pdev;
 
 	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
 		vga_count++;
 
 		has_atpx |= (amdgpu_atpx_pci_probe_handle(pdev) == true);
+
+		parent_pdev = pci_upstream_bridge(pdev);
+		d3_supported |= parent_pdev && parent_pdev->bridge_d3;
 	}
 
 	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
 		vga_count++;
 
 		has_atpx |= (amdgpu_atpx_pci_probe_handle(pdev) == true);
+
+		parent_pdev = pci_upstream_bridge(pdev);
+		d3_supported |= parent_pdev && parent_pdev->bridge_d3;
 	}
 
 	if (has_atpx && vga_count == 2) {
@@ -564,6 +577,7 @@ static bool amdgpu_atpx_detect(void)
 		printk(KERN_INFO "vga_switcheroo: detected switching method %s handle\n",
 		       acpi_method_name);
 		amdgpu_atpx_priv.atpx_detected = true;
+		amdgpu_atpx_priv.bridge_pm_usable = d3_supported;
 		amdgpu_atpx_init();
 		return true;
 	}
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/gpu/drm/i915/i915_gem.c linux-libre-4.8.13-gnu/drivers/gpu/drm/i915/i915_gem.c
--- linux-libre-4.8.12-gnu/drivers/gpu/drm/i915/i915_gem.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/gpu/drm/i915/i915_gem.c	2016-12-08 01:16:36.000000000 -0500
@@ -2540,7 +2540,7 @@ i915_gem_object_get_pages_gtt(struct drm
 			page = shmem_read_mapping_page(mapping, i);
 			if (IS_ERR(page)) {
 				ret = PTR_ERR(page);
-				goto err_pages;
+				goto err_sg;
 			}
 		}
 #ifdef CONFIG_SWIOTLB
@@ -2583,8 +2583,9 @@ i915_gem_object_get_pages_gtt(struct drm
 
 	return 0;
 
-err_pages:
+err_sg:
 	sg_mark_end(sg);
+err_pages:
 	for_each_sgt_page(page, sgt_iter, st)
 		put_page(page);
 	sg_free_table(st);
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/gpu/drm/i915/intel_display.c linux-libre-4.8.13-gnu/drivers/gpu/drm/i915/intel_display.c
--- linux-libre-4.8.12-gnu/drivers/gpu/drm/i915/intel_display.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/gpu/drm/i915/intel_display.c	2016-12-08 01:16:36.000000000 -0500
@@ -11791,7 +11791,7 @@ static int intel_crtc_page_flip(struct d
 	intel_crtc->reset_counter = i915_reset_counter(&dev_priv->gpu_error);
 	if (__i915_reset_in_progress_or_wedged(intel_crtc->reset_counter)) {
 		ret = -EIO;
-		goto cleanup;
+		goto unlock;
 	}
 
 	atomic_inc(&intel_crtc->unpin_work_count);
@@ -11877,6 +11877,7 @@ cleanup_pending:
 	if (!IS_ERR_OR_NULL(request))
 		i915_add_request_no_flush(request);
 	atomic_dec(&intel_crtc->unpin_work_count);
+unlock:
 	mutex_unlock(&dev->struct_mutex);
 cleanup:
 	crtc->primary->fb = old_fb;
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/gpu/drm/mediatek/mtk_disp_ovl.c linux-libre-4.8.13-gnu/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
--- linux-libre-4.8.12-gnu/drivers/gpu/drm/mediatek/mtk_disp_ovl.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/gpu/drm/mediatek/mtk_disp_ovl.c	2016-12-08 01:16:36.000000000 -0500
@@ -249,13 +249,6 @@ static int mtk_disp_ovl_probe(struct pla
 	if (irq < 0)
 		return irq;
 
-	ret = devm_request_irq(dev, irq, mtk_disp_ovl_irq_handler,
-			       IRQF_TRIGGER_NONE, dev_name(dev), priv);
-	if (ret < 0) {
-		dev_err(dev, "Failed to request irq %d: %d\n", irq, ret);
-		return ret;
-	}
-
 	comp_id = mtk_ddp_comp_get_id(dev->of_node, MTK_DISP_OVL);
 	if (comp_id < 0) {
 		dev_err(dev, "Failed to identify by alias: %d\n", comp_id);
@@ -271,6 +264,13 @@ static int mtk_disp_ovl_probe(struct pla
 
 	platform_set_drvdata(pdev, priv);
 
+	ret = devm_request_irq(dev, irq, mtk_disp_ovl_irq_handler,
+			       IRQF_TRIGGER_NONE, dev_name(dev), priv);
+	if (ret < 0) {
+		dev_err(dev, "Failed to request irq %d: %d\n", irq, ret);
+		return ret;
+	}
+
 	ret = component_add(dev, &mtk_disp_ovl_component_ops);
 	if (ret)
 		dev_err(dev, "Failed to add component: %d\n", ret);
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/gpu/drm/radeon/radeon_atpx_handler.c linux-libre-4.8.13-gnu/drivers/gpu/drm/radeon/radeon_atpx_handler.c
--- linux-libre-4.8.12-gnu/drivers/gpu/drm/radeon/radeon_atpx_handler.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/gpu/drm/radeon/radeon_atpx_handler.c	2016-12-08 01:16:36.000000000 -0500
@@ -33,6 +33,7 @@ struct radeon_atpx {
 
 static struct radeon_atpx_priv {
 	bool atpx_detected;
+	bool bridge_pm_usable;
 	/* handle for device - and atpx */
 	acpi_handle dhandle;
 	struct radeon_atpx atpx;
@@ -198,7 +199,11 @@ static int radeon_atpx_validate(struct r
 	atpx->is_hybrid = false;
 	if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) {
 		printk("ATPX Hybrid Graphics\n");
-		atpx->functions.power_cntl = false;
+		/*
+		 * Disable legacy PM methods only when pcie port PM is usable,
+		 * otherwise the device might fail to power off or power on.
+		 */
+		atpx->functions.power_cntl = !radeon_atpx_priv.bridge_pm_usable;
 		atpx->is_hybrid = true;
 	}
 
@@ -543,11 +548,16 @@ static bool radeon_atpx_detect(void)
 	struct pci_dev *pdev = NULL;
 	bool has_atpx = false;
 	int vga_count = 0;
+	bool d3_supported = false;
+	struct pci_dev *parent_pdev;
 
 	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
 		vga_count++;
 
 		has_atpx |= (radeon_atpx_pci_probe_handle(pdev) == true);
+
+		parent_pdev = pci_upstream_bridge(pdev);
+		d3_supported |= parent_pdev && parent_pdev->bridge_d3;
 	}
 
 	/* some newer PX laptops mark the dGPU as a non-VGA display device */
@@ -555,6 +565,9 @@ static bool radeon_atpx_detect(void)
 		vga_count++;
 
 		has_atpx |= (radeon_atpx_pci_probe_handle(pdev) == true);
+
+		parent_pdev = pci_upstream_bridge(pdev);
+		d3_supported |= parent_pdev && parent_pdev->bridge_d3;
 	}
 
 	if (has_atpx && vga_count == 2) {
@@ -562,6 +575,7 @@ static bool radeon_atpx_detect(void)
 		printk(KERN_INFO "vga_switcheroo: detected switching method %s handle\n",
 		       acpi_method_name);
 		radeon_atpx_priv.atpx_detected = true;
+		radeon_atpx_priv.bridge_pm_usable = d3_supported;
 		radeon_atpx_init();
 		return true;
 	}
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/input/mouse/psmouse-base.c linux-libre-4.8.13-gnu/drivers/input/mouse/psmouse-base.c
--- linux-libre-4.8.12-gnu/drivers/input/mouse/psmouse-base.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/input/mouse/psmouse-base.c	2016-12-08 01:16:36.000000000 -0500
@@ -1115,10 +1115,6 @@ static int psmouse_extensions(struct psm
 		if (psmouse_try_protocol(psmouse, PSMOUSE_TOUCHKIT_PS2,
 					 &max_proto, set_properties, true))
 			return PSMOUSE_TOUCHKIT_PS2;
-
-		if (psmouse_try_protocol(psmouse, PSMOUSE_BYD,
-					 &max_proto, set_properties, true))
-			return PSMOUSE_BYD;
 	}
 
 	/*
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/net/wireless/marvell/mwifiex/cfg80211.c linux-libre-4.8.13-gnu/drivers/net/wireless/marvell/mwifiex/cfg80211.c
--- linux-libre-4.8.12-gnu/drivers/net/wireless/marvell/mwifiex/cfg80211.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/net/wireless/marvell/mwifiex/cfg80211.c	2016-12-08 01:16:36.000000000 -0500
@@ -2203,8 +2203,9 @@ done:
 			is_scanning_required = 1;
 		} else {
 			mwifiex_dbg(priv->adapter, MSG,
-				    "info: trying to associate to '%s' bssid %pM\n",
-				    (char *)req_ssid.ssid, bss->bssid);
+				    "info: trying to associate to '%.*s' bssid %pM\n",
+				    req_ssid.ssid_len, (char *)req_ssid.ssid,
+				    bss->bssid);
 			memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
 			break;
 		}
@@ -2264,8 +2265,8 @@ mwifiex_cfg80211_connect(struct wiphy *w
 	}
 
 	mwifiex_dbg(adapter, INFO,
-		    "info: Trying to associate to %s and bssid %pM\n",
-		    (char *)sme->ssid, sme->bssid);
+		    "info: Trying to associate to %.*s and bssid %pM\n",
+		    (int)sme->ssid_len, (char *)sme->ssid, sme->bssid);
 
 	if (!mwifiex_stop_bg_scan(priv))
 		cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
@@ -2398,8 +2399,8 @@ mwifiex_cfg80211_join_ibss(struct wiphy
 	}
 
 	mwifiex_dbg(priv->adapter, MSG,
-		    "info: trying to join to %s and bssid %pM\n",
-		    (char *)params->ssid, params->bssid);
+		    "info: trying to join to %.*s and bssid %pM\n",
+		    params->ssid_len, (char *)params->ssid, params->bssid);
 
 	mwifiex_set_ibss_params(priv, params);
 
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/pci/pcie/aer/aer_inject.c linux-libre-4.8.13-gnu/drivers/pci/pcie/aer/aer_inject.c
--- linux-libre-4.8.12-gnu/drivers/pci/pcie/aer/aer_inject.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/pci/pcie/aer/aer_inject.c	2016-12-08 01:16:36.000000000 -0500
@@ -307,20 +307,6 @@ out:
 	return 0;
 }
 
-static struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
-{
-	while (1) {
-		if (!pci_is_pcie(dev))
-			break;
-		if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
-			return dev;
-		if (!dev->bus->self)
-			break;
-		dev = dev->bus->self;
-	}
-	return NULL;
-}
-
 static int find_aer_device_iter(struct device *device, void *data)
 {
 	struct pcie_device **result = data;
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/pci/probe.c linux-libre-4.8.13-gnu/drivers/pci/probe.c
--- linux-libre-4.8.12-gnu/drivers/pci/probe.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/pci/probe.c	2016-12-08 01:16:36.000000000 -0500
@@ -1439,6 +1439,21 @@ static void program_hpp_type1(struct pci
 		dev_warn(&dev->dev, "PCI-X settings not supported\n");
 }
 
+static bool pcie_root_rcb_set(struct pci_dev *dev)
+{
+	struct pci_dev *rp = pcie_find_root_port(dev);
+	u16 lnkctl;
+
+	if (!rp)
+		return false;
+
+	pcie_capability_read_word(rp, PCI_EXP_LNKCTL, &lnkctl);
+	if (lnkctl & PCI_EXP_LNKCTL_RCB)
+		return true;
+
+	return false;
+}
+
 static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
 {
 	int pos;
@@ -1468,9 +1483,20 @@ static void program_hpp_type2(struct pci
 			~hpp->pci_exp_devctl_and, hpp->pci_exp_devctl_or);
 
 	/* Initialize Link Control Register */
-	if (pcie_cap_has_lnkctl(dev))
+	if (pcie_cap_has_lnkctl(dev)) {
+
+		/*
+		 * If the Root Port supports Read Completion Boundary of
+		 * 128, set RCB to 128.  Otherwise, clear it.
+		 */
+		hpp->pci_exp_lnkctl_and |= PCI_EXP_LNKCTL_RCB;
+		hpp->pci_exp_lnkctl_or &= ~PCI_EXP_LNKCTL_RCB;
+		if (pcie_root_rcb_set(dev))
+			hpp->pci_exp_lnkctl_or |= PCI_EXP_LNKCTL_RCB;
+
 		pcie_capability_clear_and_set_word(dev, PCI_EXP_LNKCTL,
 			~hpp->pci_exp_lnkctl_and, hpp->pci_exp_lnkctl_or);
+	}
 
 	/* Find Advanced Error Reporting Enhanced Capability */
 	pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/pwm/sysfs.c linux-libre-4.8.13-gnu/drivers/pwm/sysfs.c
--- linux-libre-4.8.12-gnu/drivers/pwm/sysfs.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/pwm/sysfs.c	2016-12-08 01:16:36.000000000 -0500
@@ -425,6 +425,8 @@ void pwmchip_sysfs_unexport_children(str
 		if (test_bit(PWMF_EXPORTED, &pwm->flags))
 			pwm_unexport_child(parent, pwm);
 	}
+
+	put_device(parent);
 }
 
 static int __init pwm_sysfs_init(void)
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/scsi/hpsa.c linux-libre-4.8.13-gnu/drivers/scsi/hpsa.c
--- linux-libre-4.8.12-gnu/drivers/scsi/hpsa.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/scsi/hpsa.c	2016-12-08 01:16:36.000000000 -0500
@@ -2007,7 +2007,7 @@ static struct hpsa_scsi_dev_t *lookup_hp
 
 static int hpsa_slave_alloc(struct scsi_device *sdev)
 {
-	struct hpsa_scsi_dev_t *sd;
+	struct hpsa_scsi_dev_t *sd = NULL;
 	unsigned long flags;
 	struct ctlr_info *h;
 
@@ -2024,7 +2024,8 @@ static int hpsa_slave_alloc(struct scsi_
 			sd->target = sdev_id(sdev);
 			sd->lun = sdev->lun;
 		}
-	} else
+	}
+	if (!sd)
 		sd = lookup_hpsa_scsi_dev(h, sdev_channel(sdev),
 					sdev_id(sdev), sdev->lun);
 
@@ -3805,6 +3806,7 @@ static int hpsa_update_device_info(struc
 		sizeof(this_device->vendor));
 	memcpy(this_device->model, &inq_buff[16],
 		sizeof(this_device->model));
+	this_device->rev = inq_buff[2];
 	memset(this_device->device_id, 0,
 		sizeof(this_device->device_id));
 	hpsa_get_device_id(h, scsi3addr, this_device->device_id, 8,
@@ -3887,10 +3889,14 @@ static void figure_bus_target_lun(struct
 
 	if (!is_logical_dev_addr_mode(lunaddrbytes)) {
 		/* physical device, target and lun filled in later */
-		if (is_hba_lunid(lunaddrbytes))
+		if (is_hba_lunid(lunaddrbytes)) {
+			int bus = HPSA_HBA_BUS;
+
+			if (!device->rev)
+				bus = HPSA_LEGACY_HBA_BUS;
 			hpsa_set_bus_target_lun(device,
-					HPSA_HBA_BUS, 0, lunid & 0x3fff);
-		else
+					bus, 0, lunid & 0x3fff);
+		} else
 			/* defer target, lun assignment for physical devices */
 			hpsa_set_bus_target_lun(device,
 					HPSA_PHYSICAL_DEVICE_BUS, -1, -1);
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/scsi/hpsa.h linux-libre-4.8.13-gnu/drivers/scsi/hpsa.h
--- linux-libre-4.8.12-gnu/drivers/scsi/hpsa.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/scsi/hpsa.h	2016-12-08 01:16:36.000000000 -0500
@@ -69,6 +69,7 @@ struct hpsa_scsi_dev_t {
 	u64 sas_address;
 	unsigned char vendor[8];        /* bytes 8-15 of inquiry data */
 	unsigned char model[16];        /* bytes 16-31 of inquiry data */
+	unsigned char rev;		/* byte 2 of inquiry data */
 	unsigned char raid_level;	/* from inquiry page 0xC1 */
 	unsigned char volume_offline;	/* discovered via TUR or VPD */
 	u16 queue_depth;		/* max queue_depth for this device */
@@ -403,6 +404,7 @@ struct offline_device_entry {
 #define HPSA_RAID_VOLUME_BUS		1
 #define HPSA_EXTERNAL_RAID_VOLUME_BUS	2
 #define HPSA_HBA_BUS			0
+#define HPSA_LEGACY_HBA_BUS		3
 
 /*
 	Send the command to the hardware
diff -druNp --no-dereference linux-libre-4.8.12-gnu/drivers/scsi/libfc/fc_lport.c linux-libre-4.8.13-gnu/drivers/scsi/libfc/fc_lport.c
--- linux-libre-4.8.12-gnu/drivers/scsi/libfc/fc_lport.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/drivers/scsi/libfc/fc_lport.c	2016-12-08 01:16:36.000000000 -0500
@@ -308,7 +308,7 @@ struct fc_host_statistics *fc_get_host_s
 	fc_stats = &lport->host_stats;
 	memset(fc_stats, 0, sizeof(struct fc_host_statistics));
 
-	fc_stats->seconds_since_last_reset = (lport->boot_time - jiffies) / HZ;
+	fc_stats->seconds_since_last_reset = (jiffies - lport->boot_time) / HZ;
 
 	for_each_possible_cpu(cpu) {
 		struct fc_stats *stats;
diff -druNp --no-dereference linux-libre-4.8.12-gnu/fs/overlayfs/super.c linux-libre-4.8.13-gnu/fs/overlayfs/super.c
--- linux-libre-4.8.12-gnu/fs/overlayfs/super.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/fs/overlayfs/super.c	2016-12-08 01:16:36.000000000 -0500
@@ -329,11 +329,11 @@ static struct dentry *ovl_d_real(struct
 	if (!real)
 		goto bug;
 
+	/* Handle recursion */
+	real = d_real(real, inode, open_flags);
+
 	if (!inode || inode == d_inode(real))
 		return real;
-
-	/* Handle recursion */
-	return d_real(real, inode, open_flags);
 bug:
 	WARN(1, "ovl_d_real(%pd4, %s:%lu): real dentry not found\n", dentry,
 	     inode ? inode->i_sb->s_id : "NULL", inode ? inode->i_ino : 0);
diff -druNp --no-dereference linux-libre-4.8.12-gnu/include/linux/compiler-gcc.h linux-libre-4.8.13-gnu/include/linux/compiler-gcc.h
--- linux-libre-4.8.12-gnu/include/linux/compiler-gcc.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/include/linux/compiler-gcc.h	2016-12-08 01:16:36.000000000 -0500
@@ -256,7 +256,9 @@
 #endif
 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP && !__CHECKER__ */
 
-#if GCC_VERSION >= 50000
+#if GCC_VERSION >= 70000
+#define KASAN_ABI_VERSION 5
+#elif GCC_VERSION >= 50000
 #define KASAN_ABI_VERSION 4
 #elif GCC_VERSION >= 40902
 #define KASAN_ABI_VERSION 3
diff -druNp --no-dereference linux-libre-4.8.12-gnu/include/linux/pagemap.h linux-libre-4.8.13-gnu/include/linux/pagemap.h
--- linux-libre-4.8.12-gnu/include/linux/pagemap.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/include/linux/pagemap.h	2016-12-08 01:16:36.000000000 -0500
@@ -364,16 +364,13 @@ static inline struct page *read_mapping_
 }
 
 /*
- * Get the offset in PAGE_SIZE.
- * (TODO: hugepage should have ->index in PAGE_SIZE)
+ * Get index of the page with in radix-tree
+ * (TODO: remove once hugetlb pages will have ->index in PAGE_SIZE)
  */
-static inline pgoff_t page_to_pgoff(struct page *page)
+static inline pgoff_t page_to_index(struct page *page)
 {
 	pgoff_t pgoff;
 
-	if (unlikely(PageHeadHuge(page)))
-		return page->index << compound_order(page);
-
 	if (likely(!PageTransTail(page)))
 		return page->index;
 
@@ -387,6 +384,18 @@ static inline pgoff_t page_to_pgoff(stru
 }
 
 /*
+ * Get the offset in PAGE_SIZE.
+ * (TODO: hugepage should have ->index in PAGE_SIZE)
+ */
+static inline pgoff_t page_to_pgoff(struct page *page)
+{
+	if (unlikely(PageHeadHuge(page)))
+		return page->index << compound_order(page);
+
+	return page_to_index(page);
+}
+
+/*
  * Return byte-offset into filesystem object for page.
  */
 static inline loff_t page_offset(struct page *page)
diff -druNp --no-dereference linux-libre-4.8.12-gnu/include/linux/pci.h linux-libre-4.8.13-gnu/include/linux/pci.h
--- linux-libre-4.8.12-gnu/include/linux/pci.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/include/linux/pci.h	2016-12-08 01:16:36.000000000 -0500
@@ -1896,6 +1896,20 @@ static inline int pci_pcie_type(const st
 	return (pcie_caps_reg(dev) & PCI_EXP_FLAGS_TYPE) >> 4;
 }
 
+static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
+{
+	while (1) {
+		if (!pci_is_pcie(dev))
+			break;
+		if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
+			return dev;
+		if (!dev->bus->self)
+			break;
+		dev = dev->bus->self;
+	}
+	return NULL;
+}
+
 void pci_request_acs(void);
 bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags);
 bool pci_acs_path_enabled(struct pci_dev *start,
diff -druNp --no-dereference linux-libre-4.8.12-gnu/include/uapi/linux/input-event-codes.h linux-libre-4.8.13-gnu/include/uapi/linux/input-event-codes.h
--- linux-libre-4.8.12-gnu/include/uapi/linux/input-event-codes.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/include/uapi/linux/input-event-codes.h	2016-12-08 01:16:36.000000000 -0500
@@ -640,7 +640,7 @@
  * Control a data application associated with the currently viewed channel,
  * e.g. teletext or data broadcast application (MHEG, MHP, HbbTV, etc.)
  */
-#define KEY_DATA			0x275
+#define KEY_DATA			0x277
 
 #define BTN_TRIGGER_HAPPY		0x2c0
 #define BTN_TRIGGER_HAPPY1		0x2c0
diff -druNp --no-dereference linux-libre-4.8.12-gnu/kernel/rcu/tree_plugin.h linux-libre-4.8.13-gnu/kernel/rcu/tree_plugin.h
--- linux-libre-4.8.12-gnu/kernel/rcu/tree_plugin.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/kernel/rcu/tree_plugin.h	2016-12-08 01:16:36.000000000 -0500
@@ -2173,6 +2173,7 @@ static int rcu_nocb_kthread(void *arg)
 				cl++;
 			c++;
 			local_bh_enable();
+			cond_resched_rcu_qs();
 			list = next;
 		}
 		trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
diff -druNp --no-dereference linux-libre-4.8.12-gnu/Makefile linux-libre-4.8.13-gnu/Makefile
--- linux-libre-4.8.12-gnu/Makefile	2016-12-02 11:00:51.000000000 -0500
+++ linux-libre-4.8.13-gnu/Makefile	2016-12-09 08:06:55.000000000 -0500
@@ -1,6 +1,6 @@
 VERSION = 4
 PATCHLEVEL = 8
-SUBLEVEL = 12
+SUBLEVEL = 13
 EXTRAVERSION = -gnu
 NAME = Psychotic Stoned Sheep
 
diff -druNp --no-dereference linux-libre-4.8.12-gnu/mm/kasan/kasan.h linux-libre-4.8.13-gnu/mm/kasan/kasan.h
--- linux-libre-4.8.12-gnu/mm/kasan/kasan.h	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/mm/kasan/kasan.h	2016-12-08 01:16:36.000000000 -0500
@@ -53,6 +53,9 @@ struct kasan_global {
 #if KASAN_ABI_VERSION >= 4
 	struct kasan_source_location *location;
 #endif
+#if KASAN_ABI_VERSION >= 5
+	char *odr_indicator;
+#endif
 };
 
 /**
diff -druNp --no-dereference linux-libre-4.8.12-gnu/mm/khugepaged.c linux-libre-4.8.13-gnu/mm/khugepaged.c
--- linux-libre-4.8.12-gnu/mm/khugepaged.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/mm/khugepaged.c	2016-12-08 01:16:36.000000000 -0500
@@ -103,6 +103,7 @@ static struct khugepaged_scan khugepaged
 	.mm_head = LIST_HEAD_INIT(khugepaged_scan.mm_head),
 };
 
+#ifdef CONFIG_SYSFS
 static ssize_t scan_sleep_millisecs_show(struct kobject *kobj,
 					 struct kobj_attribute *attr,
 					 char *buf)
@@ -295,6 +296,7 @@ struct attribute_group khugepaged_attr_g
 	.attrs = khugepaged_attr,
 	.name = "khugepaged",
 };
+#endif /* CONFIG_SYSFS */
 
 #define VM_NO_KHUGEPAGED (VM_SPECIAL | VM_HUGETLB)
 
diff -druNp --no-dereference linux-libre-4.8.12-gnu/mm/mlock.c linux-libre-4.8.13-gnu/mm/mlock.c
--- linux-libre-4.8.12-gnu/mm/mlock.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/mm/mlock.c	2016-12-08 01:16:36.000000000 -0500
@@ -190,10 +190,13 @@ unsigned int munlock_vma_page(struct pag
 	 */
 	spin_lock_irq(zone_lru_lock(zone));
 
-	nr_pages = hpage_nr_pages(page);
-	if (!TestClearPageMlocked(page))
+	if (!TestClearPageMlocked(page)) {
+		/* Potentially, PTE-mapped THP: do not skip the rest PTEs */
+		nr_pages = 1;
 		goto unlock_out;
+	}
 
+	nr_pages = hpage_nr_pages(page);
 	__mod_zone_page_state(zone, NR_MLOCK, -nr_pages);
 
 	if (__munlock_isolate_lru_page(page, true)) {
diff -druNp --no-dereference linux-libre-4.8.12-gnu/mm/truncate.c linux-libre-4.8.13-gnu/mm/truncate.c
--- linux-libre-4.8.12-gnu/mm/truncate.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/mm/truncate.c	2016-12-08 01:16:36.000000000 -0500
@@ -283,7 +283,7 @@ void truncate_inode_pages_range(struct a
 
 			if (!trylock_page(page))
 				continue;
-			WARN_ON(page_to_pgoff(page) != index);
+			WARN_ON(page_to_index(page) != index);
 			if (PageWriteback(page)) {
 				unlock_page(page);
 				continue;
@@ -371,7 +371,7 @@ void truncate_inode_pages_range(struct a
 			}
 
 			lock_page(page);
-			WARN_ON(page_to_pgoff(page) != index);
+			WARN_ON(page_to_index(page) != index);
 			wait_on_page_writeback(page);
 			truncate_inode_page(mapping, page);
 			unlock_page(page);
@@ -492,7 +492,7 @@ unsigned long invalidate_mapping_pages(s
 			if (!trylock_page(page))
 				continue;
 
-			WARN_ON(page_to_pgoff(page) != index);
+			WARN_ON(page_to_index(page) != index);
 
 			/* Middle of THP: skip */
 			if (PageTransTail(page)) {
@@ -612,7 +612,7 @@ int invalidate_inode_pages2_range(struct
 			}
 
 			lock_page(page);
-			WARN_ON(page_to_pgoff(page) != index);
+			WARN_ON(page_to_index(page) != index);
 			if (page->mapping != mapping) {
 				unlock_page(page);
 				continue;
diff -druNp --no-dereference linux-libre-4.8.12-gnu/mm/workingset.c linux-libre-4.8.13-gnu/mm/workingset.c
--- linux-libre-4.8.12-gnu/mm/workingset.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/mm/workingset.c	2016-12-08 01:16:36.000000000 -0500
@@ -348,7 +348,7 @@ static unsigned long count_shadow_nodes(
 	shadow_nodes = list_lru_shrink_count(&workingset_shadow_nodes, sc);
 	local_irq_enable();
 
-	if (memcg_kmem_enabled()) {
+	if (sc->memcg) {
 		pages = mem_cgroup_node_nr_lru_pages(sc->memcg, sc->nid,
 						     LRU_ALL_FILE);
 	} else {
diff -druNp --no-dereference linux-libre-4.8.12-gnu/net/batman-adv/tp_meter.c linux-libre-4.8.13-gnu/net/batman-adv/tp_meter.c
--- linux-libre-4.8.12-gnu/net/batman-adv/tp_meter.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/net/batman-adv/tp_meter.c	2016-12-08 01:16:36.000000000 -0500
@@ -837,6 +837,7 @@ static int batadv_tp_send(void *arg)
 	primary_if = batadv_primary_if_get_selected(bat_priv);
 	if (unlikely(!primary_if)) {
 		err = BATADV_TP_REASON_DST_UNREACHABLE;
+		tp_vars->reason = err;
 		goto out;
 	}
 
diff -druNp --no-dereference linux-libre-4.8.12-gnu/virt/kvm/arm/vgic/vgic-v2.c linux-libre-4.8.13-gnu/virt/kvm/arm/vgic/vgic-v2.c
--- linux-libre-4.8.12-gnu/virt/kvm/arm/vgic/vgic-v2.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/virt/kvm/arm/vgic/vgic-v2.c	2016-12-08 01:16:36.000000000 -0500
@@ -50,8 +50,10 @@ void vgic_v2_process_maintenance(struct
 
 			WARN_ON(cpuif->vgic_lr[lr] & GICH_LR_STATE);
 
-			kvm_notify_acked_irq(vcpu->kvm, 0,
-					     intid - VGIC_NR_PRIVATE_IRQS);
+			/* Only SPIs require notification */
+			if (vgic_valid_spi(vcpu->kvm, intid))
+				kvm_notify_acked_irq(vcpu->kvm, 0,
+						     intid - VGIC_NR_PRIVATE_IRQS);
 		}
 	}
 
diff -druNp --no-dereference linux-libre-4.8.12-gnu/virt/kvm/arm/vgic/vgic-v3.c linux-libre-4.8.13-gnu/virt/kvm/arm/vgic/vgic-v3.c
--- linux-libre-4.8.12-gnu/virt/kvm/arm/vgic/vgic-v3.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/virt/kvm/arm/vgic/vgic-v3.c	2016-12-08 01:16:36.000000000 -0500
@@ -41,8 +41,10 @@ void vgic_v3_process_maintenance(struct
 
 			WARN_ON(cpuif->vgic_lr[lr] & ICH_LR_STATE);
 
-			kvm_notify_acked_irq(vcpu->kvm, 0,
-					     intid - VGIC_NR_PRIVATE_IRQS);
+			/* Only SPIs require notification */
+			if (vgic_valid_spi(vcpu->kvm, intid))
+				kvm_notify_acked_irq(vcpu->kvm, 0,
+						     intid - VGIC_NR_PRIVATE_IRQS);
 		}
 
 		/*
diff -druNp --no-dereference linux-libre-4.8.12-gnu/virt/kvm/kvm_main.c linux-libre-4.8.13-gnu/virt/kvm/kvm_main.c
--- linux-libre-4.8.12-gnu/virt/kvm/kvm_main.c	2016-12-02 03:11:45.000000000 -0500
+++ linux-libre-4.8.13-gnu/virt/kvm/kvm_main.c	2016-12-08 01:16:36.000000000 -0500
@@ -2852,10 +2852,10 @@ static int kvm_ioctl_create_device(struc
 
 	ret = anon_inode_getfd(ops->name, &kvm_device_fops, dev, O_RDWR | O_CLOEXEC);
 	if (ret < 0) {
-		ops->destroy(dev);
 		mutex_lock(&kvm->lock);
 		list_del(&dev->vm_node);
 		mutex_unlock(&kvm->lock);
+		ops->destroy(dev);
 		return ret;
 	}
 
