android_kernel_xiaomi_sm8350/arch/x86_64/kernel
Rafael J. Wysocki 3dd083255d [PATCH] x86_64: Set up safe page tables during resume
The following patch makes swsusp avoid the possible temporary corruption
of page translation tables during resume on x86-64.  This is achieved by
creating a copy of the relevant page tables that will not be modified by
swsusp and can be safely used by it on resume.

The problem is that during resume on x86-64 swsusp may temporarily
corrupt the page tables used for the direct mapping of RAM.  If that
happens, a page fault occurs and cannot be handled properly, which leads
to the solid hang of the affected system.  This leads to the loss of the
system's state from before suspend and may result in the loss of data or
the corruption of filesystems, so it is a serious issue.  Also, it
appears to happen quite often (for me, as often as 50% of the time).

The problem is related to the fact that (at least) one of the PMD
entries used in the direct memory mapping (starting at PAGE_OFFSET)
points to a page table the physical address of which is much greater
than the physical address of the PMD entry itself.  Moreover,
unfortunately, the physical address of the page table before suspend
(i.e.  the one stored in the suspend image) happens to be different to
the physical address of the corresponding page table used during resume
(i.e.  the one that is valid right before swsusp_arch_resume() in
arch/x86_64/kernel/suspend_asm.S is executed).  Thus while the image is
restored, the "offending" PMD entry gets overwritten, so it does not
point to the right physical address any more (i.e.  there's no page
table at the address pointed to by it, because it points to the address
the page table has been at during suspend).  Consequently, if the PMD
entry is used later on, and it _is_ used in the process of copying the
image pages, a page fault occurs, but it cannot be handled in the normal
way and the system hangs.

In principle we can call create_resume_mapping() from
swsusp_arch_resume() (ie.  from suspend_asm.S), but then the memory
allocations in create_resume_mapping(), resume_pud_mapping(), and
resume_pmd_mapping() must be made carefully so that we use _only_
NosaveFree pages in them (the other pages are overwritten by the loop in
swsusp_arch_resume()).  Additionally, we are in atomic context at that
time, so we cannot use GFP_KERNEL.  Moreover, if one of the allocations
fails, we should free all of the allocated pages, so we need to trace
them somehow.

All of this is done in the appended patch, except that the functions
populating the page tables are located in arch/x86_64/kernel/suspend.c
rather than in init.c.  It may be done in a more elegan way in the
future, with the help of some swsusp patches that are in the works now.

[AK: move some externs into headers, renamed a function]

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-10-10 08:36:46 -07:00
..
acpi [PATCH] x86-64: more gratitious linux/irq.h includes 2005-09-12 10:50:58 -07:00
cpufreq
aperture.c [PATCH] x86-64: Don't allocate aperture when swiotlb is enabled and no AGP found 2005-09-12 10:49:56 -07:00
apic.c [PATCH] x86-64: more gratitious linux/irq.h includes 2005-09-12 10:50:58 -07:00
asm-offsets.c [PATCH] x86-64: Some cleanup and optimization to the processor data area. 2005-09-12 10:49:58 -07:00
crash.c [PATCH] x86-64: more gratitious linux/irq.h includes 2005-09-12 10:50:58 -07:00
e820.c [PATCH] x86_64: e820.c needs module.h 2005-09-17 11:50:00 -07:00
early_printk.c [PATCH] x86-64: Add simnow console 2005-09-12 10:49:58 -07:00
entry.S [PATCH] x86-64: Fix CFI information 2005-09-12 10:50:56 -07:00
genapic_cluster.c [PATCH] x86-64: Remove obsolete APIC "write around" bug workaround 2005-09-12 10:49:55 -07:00
genapic_flat.c [PATCH] x86-64: Delivery mode should be APIC_DM_FIXED when using physical mode. 2005-09-12 10:50:56 -07:00
genapic.c [PATCH] x86-64: Use physflat on Intel for < 8 CPUs with CPU hotplug 2005-09-12 10:50:56 -07:00
head64.c
head.S [PATCH] x86_64: Drop global bit from early low mappings 2005-10-04 15:56:52 -07:00
i387.c
i8259.c [PATCH] x86-64: more gratitious linux/irq.h includes 2005-09-12 10:50:58 -07:00
init_task.c [PATCH] x86-64: Set the stack pointer correctly in init_thread and init_tss 2005-09-12 10:50:57 -07:00
io_apic.c Partially revert "Fix time going twice as fast problem on ATI Xpress chipsets" 2005-09-14 15:56:27 -07:00
ioport.c
irq.c [PATCH] Remove unnecessary BUG_ON in irq.c 2005-09-12 10:50:55 -07:00
kprobes.c [PATCH] utilization of kprobe_mutex is incorrect on x86_64 2005-09-30 12:41:20 -07:00
ldt.c
machine_kexec.c
Makefile [PATCH] x86-64: Merge msr.c with i386 version 2005-09-12 10:50:57 -07:00
mce_intel.c
mce.c [PATCH] x86_64: Fix mce_log 2005-09-29 15:41:42 -07:00
module.c
mpparse.c [PATCH] x86-64: more gratitious linux/irq.h includes 2005-09-12 10:50:58 -07:00
nmi.c [PATCH] x86_64: NMI watchdog frequency calculation adjustments 2005-09-13 08:22:33 -07:00
pci-dma.c
pci-gart.c [PATCH] x86-64: Micro optimization to dma_alloc_coherent node lookup 2005-09-12 10:49:57 -07:00
pci-nommu.c
pmtimer.c
process.c [PATCH] x86-64: more gratitious linux/irq.h includes 2005-09-12 10:50:58 -07:00
ptrace.c
reboot.c
relocate_kernel.S
setup64.c [PATCH] x86-64: Only allocate per cpu data for possible CPUs, not compiled in CPUs. 2005-09-12 10:49:58 -07:00
setup.c [PATCH] x86_64: Fix numa node topology detection for srat based x86_64 boxes 2005-10-03 10:54:22 -07:00
signal.c
smp.c [PATCH] x86-64: more gratitious linux/irq.h includes 2005-09-12 10:50:58 -07:00
smpboot.c [PATCH] x86-64: more gratitious linux/irq.h includes 2005-09-12 10:50:58 -07:00
suspend_asm.S [PATCH] x86_64: Set up safe page tables during resume 2005-10-10 08:36:46 -07:00
suspend.c [PATCH] x86_64: Set up safe page tables during resume 2005-10-10 08:36:46 -07:00
sys_x86_64.c
syscall.c
time.c [PATCH] x86-64: Fix bad assumption that dualcore cpus have synced TSCs 2005-09-28 07:46:41 -07:00
trampoline.S
traps.c [PATCH] x86-64: reduce x86-64 bug frame by 4 bytes 2005-09-12 10:50:58 -07:00
vmlinux.lds.S [PATCH] x86_64 linker script cleanups for debug sections 2005-09-10 12:00:17 -07:00
vsyscall.c [PATCH] x86-64: Prevent gcc 4 from optimizing away vsyscalls 2005-09-12 10:50:56 -07:00
x8664_ksyms.c [LIB]: Consolidate _atomic_dec_and_lock() 2005-09-14 21:47:01 -07:00