android_kernel_xiaomi_sm7250/include
Zachary Amsden 6e5882cfa2 [PATCH] x86/PAE: Fix pte_clear for the >4GB RAM case
Proposed fix for ptep_get_and_clear_full PAE bug.  Pte_clear had the same bug,
so use the same fix for both.  Turns out pmd_clear had it as well, but pgds
are not affected.

The problem is rather intricate.  Page table entries in PAE mode are 64-bits
wide, but the only atomic 8-byte write operation available in 32-bit mode is
cmpxchg8b, which is expensive (at least on P4), and thus avoided.  But it can
happen that the processor may prefetch entries into the TLB in the middle of an
operation which clears a page table entry.  So one must always clear the P-bit
in the low word of the page table entry first when clearing it.

Since the sequence *ptep = __pte(0) leaves the order of the write dependent on
the compiler, it must be coded explicitly as a clear of the low word followed
by a clear of the high word.  Further, there must be a write memory barrier
here to enforce proper ordering by the compiler (and, in the future, by the
processor as well).

On > 4GB memory machines, the implementation of pte_clear for PAE was clearly
deficient, as it could leave virtual mappings of physical memory above 4GB
aliased to memory below 4GB in the TLB.  The implementation of
ptep_get_and_clear_full has a similar bug, although not nearly as likely to
occur, since the mappings being cleared are in the process of being destroyed,
and should never be dereferenced again.

But, as luck would have it, it is possible to trigger bugs even without ever
dereferencing these bogus TLB mappings, even if the clear is followed fairly
soon after with a TLB flush or invalidation.  The problem is that memory above
4GB may now be aliased into the first 4GB of memory, and in fact, may hit a
region of memory with non-memory semantics.  These regions include AGP and PCI
space.  As such, these memory regions are not cached by the processor.  This
introduces the bug.

The processor can speculate memory operations, including memory writes, as long
as they are committed with the proper ordering.  Speculating a memory write to
a linear address that has a bogus TLB mapping is possible.  Normally, the
speculation is harmless.  But for cached memory, it does leave the falsely
speculated cacheline unmodified, but in a dirty state.  This cache line will be
eventually written back.  If this cacheline happens to intersect a region of
memory that is not protected by the cache coherency protocol, it can corrupt
data in I/O memory, which is generally a very bad thing to do, and can cause
total system failure or just plain undefined behavior.

These bugs are extremely unlikely, but the severity is of such magnitude, and
the fix so simple that I think fixing them immediately is justified.  Also,
they are nearly impossible to debug.

Signed-off-by: Zachary Amsden <zach@vmware.com>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-04-27 12:00:59 -07:00
..
acpi [PATCH] s/;;/;/g 2006-03-24 07:33:24 -08:00
asm-alpha [PATCH] Configurable NODES_SHIFT 2006-04-11 06:18:39 -07:00
asm-arm Merge master.kernel.org:/home/rmk/linux-2.6-arm 2006-04-15 16:01:39 -07:00
asm-arm26 [PATCH] unify pfn_to_page: arm26 pfn_to_page 2006-03-27 08:44:44 -08:00
asm-cris [PATCH] sys_kexec_load() naming fixups 2006-04-11 06:18:42 -07:00
asm-frv [PATCH] sys_kexec_load() naming fixups 2006-04-11 06:18:42 -07:00
asm-generic [PATCH] mutex: some cleanups 2006-03-31 12:19:01 -08:00
asm-h8300 [PATCH] sys_kexec_load() naming fixups 2006-04-11 06:18:42 -07:00
asm-i386 [PATCH] x86/PAE: Fix pte_clear for the >4GB RAM case 2006-04-27 12:00:59 -07:00
asm-ia64 [PATCH] Add support for the sys_vmsplice syscall 2006-04-26 10:59:21 +02:00
asm-m32r [PATCH] m32r: update switch_to macro for tuning 2006-04-19 09:13:51 -07:00
asm-m68k [PATCH] m68k: fix undefined reference to generic_find_next_zero_le_bit 2006-03-26 08:57:13 -08:00
asm-m68knommu [PATCH] bitops: m68knommu: use generic bitops 2006-03-26 08:57:13 -08:00
asm-mips [MIPS] Handle IDE PIO cache aliases on SMP. 2006-04-19 04:14:29 +02:00
asm-parisc [PARISC] Make ioremap default to _nocache 2006-04-21 22:20:35 +00:00
asm-powerpc [PATCH] Add support for the sys_vmsplice syscall 2006-04-26 10:59:21 +02:00
asm-ppc [PATCH] lock PTE before updating it in 440/BookE page fault handler 2006-03-29 13:44:15 +11:00
asm-s390 [PATCH] S390: fix implicit declaration of (un)likely. 2006-04-11 06:18:39 -07:00
asm-sh [PATCH] sys_kexec_load() naming fixups 2006-04-11 06:18:42 -07:00
asm-sh64 [PATCH] sys_kexec_load() naming fixups 2006-04-11 06:18:42 -07:00
asm-sparc [SPARC]: __NR_sys removal 2006-04-24 13:48:51 -07:00
asm-sparc64 [SPARC]: __NR_sys removal 2006-04-24 13:48:51 -07:00
asm-um [PATCH] uml: fix "extern-vs-static" proto conflict in TLS code 2006-04-11 06:18:36 -07:00
asm-v850 [PATCH] Remove unused prepare_to_switch macro 2006-04-11 06:18:34 -07:00
asm-x86_64 [PATCH] Add support for the sys_vmsplice syscall 2006-04-26 10:59:21 +02:00
asm-xtensa [PATCH] xtensa: Fix TIOCGICOUNT macro 2006-04-20 07:54:03 -07:00
keys
linux Merge branch 'splice' of git://brick.kernel.dk/data/git/linux-2.6-block 2006-04-26 07:47:55 -07:00
math-emu
media V4L/DVB (3702): Make msp3400 routing defines more consistent 2006-04-02 04:56:11 -03:00
mtd
net [PATCH] softmac: fix SIOCSIWAP 2006-04-24 15:20:23 -04:00
pcmcia [PATCH] pcmcia: declare pccard_iodyn_ops (fix m8xx_pcmcia.c compilation error) 2006-03-31 21:49:51 +02:00
rdma IB: simplify static rate encoding 2006-04-10 09:43:47 -07:00
rxrpc
scsi [SCSI] FC transport: fixes for workq deadlocks 2006-04-13 13:25:16 -05:00
sound [ALSA] sound/core/pcm.c: make snd_pcm_format_name() static 2006-04-12 11:34:21 +02:00
video [PATCH] Remove MODULE_PARM 2006-03-25 08:22:52 -08:00