2005-04-17 06:20:36 +08:00
|
|
|
#ifndef _I386_PGTABLE_2LEVEL_H
|
|
|
|
#define _I386_PGTABLE_2LEVEL_H
|
|
|
|
|
|
|
|
#define pte_ERROR(e) \
|
|
|
|
printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, (e).pte_low)
|
|
|
|
#define pgd_ERROR(e) \
|
|
|
|
printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Certain architectures need to do special things when PTEs
|
|
|
|
* within a page table are directly modified. Thus, the following
|
|
|
|
* hook is made available.
|
|
|
|
*/
|
2007-05-03 01:27:13 +08:00
|
|
|
static inline void native_set_pte(pte_t *ptep , pte_t pte)
|
|
|
|
{
|
|
|
|
*ptep = pte;
|
|
|
|
}
|
2008-01-30 20:32:58 +08:00
|
|
|
|
2007-05-03 01:27:13 +08:00
|
|
|
static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
|
|
|
|
{
|
|
|
|
*pmdp = pmd;
|
|
|
|
}
|
2006-12-07 09:14:08 +08:00
|
|
|
|
2008-01-30 20:32:58 +08:00
|
|
|
static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
|
|
|
|
{
|
|
|
|
native_set_pte(ptep, pte);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-30 20:32:58 +08:00
|
|
|
static inline void native_set_pte_present(struct mm_struct *mm, unsigned long addr,
|
|
|
|
pte_t *ptep, pte_t pte)
|
|
|
|
{
|
|
|
|
native_set_pte(ptep, pte);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void native_pmd_clear(pmd_t *pmdp)
|
|
|
|
{
|
|
|
|
native_set_pmd(pmdp, __pmd(0));
|
|
|
|
}
|
[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-28 02:32:29 +08:00
|
|
|
|
2007-05-03 01:27:19 +08:00
|
|
|
static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *xp)
|
|
|
|
{
|
2008-01-30 20:32:58 +08:00
|
|
|
*xp = native_make_pte(0);
|
2007-05-03 01:27:19 +08:00
|
|
|
}
|
|
|
|
|
2007-05-03 01:27:19 +08:00
|
|
|
#ifdef CONFIG_SMP
|
2007-05-03 01:27:13 +08:00
|
|
|
static inline pte_t native_ptep_get_and_clear(pte_t *xp)
|
|
|
|
{
|
|
|
|
return __pte(xchg(&xp->pte_low, 0));
|
|
|
|
}
|
2007-05-03 01:27:19 +08:00
|
|
|
#else
|
|
|
|
#define native_ptep_get_and_clear(xp) native_local_ptep_get_and_clear(xp)
|
|
|
|
#endif
|
2006-09-26 14:32:30 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define pte_page(x) pfn_to_page(pte_pfn(x))
|
|
|
|
#define pte_none(x) (!(x).pte_low)
|
2007-05-03 01:27:13 +08:00
|
|
|
#define pte_pfn(x) (pte_val(x) >> PAGE_SHIFT)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bits 0, 6 and 7 are taken, split up the 29 bits of offset
|
|
|
|
* into this range:
|
|
|
|
*/
|
|
|
|
#define PTE_FILE_MAX_BITS 29
|
|
|
|
|
|
|
|
#define pte_to_pgoff(pte) \
|
|
|
|
((((pte).pte_low >> 1) & 0x1f ) + (((pte).pte_low >> 8) << 5 ))
|
|
|
|
|
|
|
|
#define pgoff_to_pte(off) \
|
2008-01-30 20:32:57 +08:00
|
|
|
((pte_t) { .pte_low = (((off) & 0x1f) << 1) + (((off) >> 5) << 8) + _PAGE_FILE })
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Encode and de-code a swap entry */
|
|
|
|
#define __swp_type(x) (((x).val >> 1) & 0x1f)
|
|
|
|
#define __swp_offset(x) ((x).val >> 8)
|
|
|
|
#define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | ((offset) << 8) })
|
|
|
|
#define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_low })
|
2008-01-30 20:32:57 +08:00
|
|
|
#define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#endif /* _I386_PGTABLE_2LEVEL_H */
|