2008-10-22 22:26:29 -07:00
|
|
|
#ifndef _ASM_X86_PGTABLE_64_H
|
|
|
|
#define _ASM_X86_PGTABLE_64_H
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-05-08 00:31:11 -07:00
|
|
|
#include <linux/const.h>
|
2009-02-08 18:50:52 -08:00
|
|
|
#include <asm/pgtable_64_types.h>
|
|
|
|
|
2007-05-02 19:27:06 +02:00
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* This file contains the functions and defines necessary to modify and use
|
|
|
|
* the x86-64 page table tree.
|
|
|
|
*/
|
|
|
|
#include <asm/processor.h>
|
2007-10-18 23:40:25 -07:00
|
|
|
#include <linux/bitops.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/threads.h>
|
|
|
|
|
|
|
|
extern pud_t level3_kernel_pgt[512];
|
|
|
|
extern pud_t level3_ident_pgt[512];
|
|
|
|
extern pmd_t level2_kernel_pgt[512];
|
2008-07-08 15:06:50 -07:00
|
|
|
extern pmd_t level2_fixmap_pgt[512];
|
|
|
|
extern pmd_t level2_ident_pgt[512];
|
2014-09-02 11:16:01 +01:00
|
|
|
extern pte_t level1_fixmap_pgt[512];
|
2005-04-16 15:20:36 -07:00
|
|
|
extern pgd_t init_level4_pgt[];
|
|
|
|
|
Revert "[PATCH] x86: __pa and __pa_symbol address space separation"
This was broken. It adds complexity, for no good reason. Rather than
separate __pa() and __pa_symbol(), we should deprecate __pa_symbol(),
and preferably __pa() too - and just use "virt_to_phys()" instead, which
is more readable and has nicer semantics.
However, right now, just undo the separation, and make __pa_symbol() be
the exact same as __pa(). That fixes the bugs this patch introduced,
and we can do the fairly obvious cleanups later.
Do the new __phys_addr() function (which is now the actual workhorse for
the unified __pa()/__pa_symbol()) as a real external function, that way
all the potential issues with compile/link-time optimizations of
constant symbol addresses go away, and we can also, if we choose to, add
more sanity-checking of the argument.
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Vivek Goyal <vgoyal@in.ibm.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-07 08:44:24 -07:00
|
|
|
#define swapper_pg_dir init_level4_pgt
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
extern void paging_init(void);
|
|
|
|
|
2008-03-23 01:03:11 -07:00
|
|
|
#define pte_ERROR(e) \
|
2012-05-21 19:50:07 -07:00
|
|
|
pr_err("%s:%d: bad pte %p(%016lx)\n", \
|
2008-03-23 01:03:11 -07:00
|
|
|
__FILE__, __LINE__, &(e), pte_val(e))
|
|
|
|
#define pmd_ERROR(e) \
|
2012-05-21 19:50:07 -07:00
|
|
|
pr_err("%s:%d: bad pmd %p(%016lx)\n", \
|
2008-03-23 01:03:11 -07:00
|
|
|
__FILE__, __LINE__, &(e), pmd_val(e))
|
|
|
|
#define pud_ERROR(e) \
|
2012-05-21 19:50:07 -07:00
|
|
|
pr_err("%s:%d: bad pud %p(%016lx)\n", \
|
2008-03-23 01:03:11 -07:00
|
|
|
__FILE__, __LINE__, &(e), pud_val(e))
|
|
|
|
#define pgd_ERROR(e) \
|
2012-05-21 19:50:07 -07:00
|
|
|
pr_err("%s:%d: bad pgd %p(%016lx)\n", \
|
2008-03-23 01:03:11 -07:00
|
|
|
__FILE__, __LINE__, &(e), pgd_val(e))
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-01-30 13:32:58 +01:00
|
|
|
struct mm_struct;
|
|
|
|
|
2008-06-25 00:19:22 -04:00
|
|
|
void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte);
|
|
|
|
|
|
|
|
|
2008-01-30 13:32:58 +01:00
|
|
|
static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
|
|
|
|
pte_t *ptep)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2008-01-30 13:32:58 +01:00
|
|
|
*ptep = native_make_pte(0);
|
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-01-30 13:32:58 +01:00
|
|
|
static inline void native_set_pte(pte_t *ptep, pte_t pte)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2008-01-30 13:32:58 +01:00
|
|
|
*ptep = pte;
|
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-01-30 13:34:01 +01:00
|
|
|
static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
|
|
|
|
{
|
|
|
|
native_set_pte(ptep, pte);
|
|
|
|
}
|
|
|
|
|
2011-01-13 15:46:41 -08:00
|
|
|
static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
|
|
|
|
{
|
|
|
|
*pmdp = pmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void native_pmd_clear(pmd_t *pmd)
|
|
|
|
{
|
|
|
|
native_set_pmd(pmd, native_make_pmd(0));
|
|
|
|
}
|
|
|
|
|
2008-01-30 13:32:58 +01:00
|
|
|
static inline pte_t native_ptep_get_and_clear(pte_t *xp)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2008-01-30 13:32:58 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
return native_make_pte(xchg(&xp->pte, 0));
|
|
|
|
#else
|
2008-03-23 01:03:11 -07:00
|
|
|
/* native_local_ptep_get_and_clear,
|
|
|
|
but duplicated because of cyclic dependency */
|
2008-01-30 13:32:58 +01:00
|
|
|
pte_t ret = *xp;
|
|
|
|
native_pte_clear(NULL, 0, xp);
|
|
|
|
return ret;
|
|
|
|
#endif
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2011-01-13 15:46:41 -08:00
|
|
|
static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2011-01-13 15:46:41 -08:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
return native_make_pmd(xchg(&xp->pmd, 0));
|
|
|
|
#else
|
|
|
|
/* native_local_pmdp_get_and_clear,
|
|
|
|
but duplicated because of cyclic dependency */
|
|
|
|
pmd_t ret = *xp;
|
|
|
|
native_pmd_clear(xp);
|
|
|
|
return ret;
|
|
|
|
#endif
|
2008-01-30 13:32:58 +01:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-01-30 13:32:58 +01:00
|
|
|
static inline void native_set_pud(pud_t *pudp, pud_t pud)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2008-01-30 13:32:58 +01:00
|
|
|
*pudp = pud;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2008-01-30 13:32:58 +01:00
|
|
|
static inline void native_pud_clear(pud_t *pud)
|
|
|
|
{
|
|
|
|
native_set_pud(pud, native_make_pud(0));
|
|
|
|
}
|
2005-09-03 15:55:06 -07:00
|
|
|
|
2018-01-03 10:43:15 -08:00
|
|
|
#ifdef CONFIG_PAGE_TABLE_ISOLATION
|
kaiser: do not set _PAGE_NX on pgd_none
native_pgd_clear() uses native_set_pgd(), so native_set_pgd() must
avoid setting the _PAGE_NX bit on an otherwise pgd_none() entry:
usually that just generated a warning on exit, but sometimes
more mysterious and damaging failures (our production machines
could not complete booting).
The original fix to this just avoided adding _PAGE_NX to
an empty entry; but eventually more problems surfaced with kexec,
and EFI mapping expected to be a problem too. So now instead
change native_set_pgd() to update shadow only if _PAGE_USER:
A few places (kernel/machine_kexec_64.c, platform/efi/efi_64.c for sure)
use set_pgd() to set up a temporary internal virtual address space, with
physical pages remapped at what Kaiser regards as userspace addresses:
Kaiser then assumes a shadow pgd follows, which it will try to corrupt.
This appears to be responsible for the recent kexec and kdump failures;
though it's unclear how those did not manifest as a problem before.
Ah, the shadow pgd will only be assumed to "follow" if the requested
pgd is on an even-numbered page: so I suppose it was going wrong 50%
of the time all along.
What we need is a flag to set_pgd(), to tell it we're dealing with
userspace. Er, isn't that what the pgd's _PAGE_USER bit is saying?
Add a test for that. But we cannot do the same for pgd_clear()
(which may be called to clear corrupted entries - set aside the
question of "corrupt in which pgd?" until later), so there just
rely on pgd_clear() not being called in the problematic cases -
with a WARN_ON_ONCE() which should fire half the time if it is.
But this is getting too big for an inline function: move it into
arch/x86/mm/kaiser.c (which then demands a boot/compressed mod);
and de-void and de-space native_get_shadow/normal_pgd() while here.
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-05 12:05:01 -07:00
|
|
|
extern pgd_t kaiser_set_shadow_pgd(pgd_t *pgdp, pgd_t pgd);
|
|
|
|
|
|
|
|
static inline pgd_t *native_get_shadow_pgd(pgd_t *pgdp)
|
2017-08-30 16:23:00 -07:00
|
|
|
{
|
kaiser: add "nokaiser" boot option, using ALTERNATIVE
Added "nokaiser" boot option: an early param like "noinvpcid".
Most places now check int kaiser_enabled (#defined 0 when not
CONFIG_KAISER) instead of #ifdef CONFIG_KAISER; but entry_64.S
and entry_64_compat.S are using the ALTERNATIVE technique, which
patches in the preferred instructions at runtime. That technique
is tied to x86 cpu features, so X86_FEATURE_KAISER is fabricated.
Prior to "nokaiser", Kaiser #defined _PAGE_GLOBAL 0: revert that,
but be careful with both _PAGE_GLOBAL and CR4.PGE: setting them when
nokaiser like when !CONFIG_KAISER, but not setting either when kaiser -
neither matters on its own, but it's hard to be sure that _PAGE_GLOBAL
won't get set in some obscure corner, or something add PGE into CR4.
By omitting _PAGE_GLOBAL from __supported_pte_mask when kaiser_enabled,
all page table setup which uses pte_pfn() masks it out of the ptes.
It's slightly shameful that the same declaration versus definition of
kaiser_enabled appears in not one, not two, but in three header files
(asm/kaiser.h, asm/pgtable.h, asm/tlbflush.h). I felt safer that way,
than with #including any of those in any of the others; and did not
feel it worth an asm/kaiser_enabled.h - kernel/cpu/common.c includes
them all, so we shall hear about it if they get out of synch.
Cleanups while in the area: removed the silly #ifdef CONFIG_KAISER
from kaiser.c; removed the unused native_get_normal_pgd(); removed
the spurious reg clutter from SWITCH_*_CR3 macro stubs; corrected some
comments. But more interestingly, set CR4.PSE in secondary_startup_64:
the manual is clear that it does not matter whether it's 0 or 1 when
4-level-pts are enabled, but I was distracted to find cr4 different on
BSP and auxiliaries - BSP alone was adding PSE, in probe_page_size_mask().
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-24 16:59:49 -07:00
|
|
|
#ifdef CONFIG_DEBUG_VM
|
|
|
|
/* linux/mmdebug.h may not have been included at this point */
|
|
|
|
BUG_ON(!kaiser_enabled);
|
|
|
|
#endif
|
kaiser: do not set _PAGE_NX on pgd_none
native_pgd_clear() uses native_set_pgd(), so native_set_pgd() must
avoid setting the _PAGE_NX bit on an otherwise pgd_none() entry:
usually that just generated a warning on exit, but sometimes
more mysterious and damaging failures (our production machines
could not complete booting).
The original fix to this just avoided adding _PAGE_NX to
an empty entry; but eventually more problems surfaced with kexec,
and EFI mapping expected to be a problem too. So now instead
change native_set_pgd() to update shadow only if _PAGE_USER:
A few places (kernel/machine_kexec_64.c, platform/efi/efi_64.c for sure)
use set_pgd() to set up a temporary internal virtual address space, with
physical pages remapped at what Kaiser regards as userspace addresses:
Kaiser then assumes a shadow pgd follows, which it will try to corrupt.
This appears to be responsible for the recent kexec and kdump failures;
though it's unclear how those did not manifest as a problem before.
Ah, the shadow pgd will only be assumed to "follow" if the requested
pgd is on an even-numbered page: so I suppose it was going wrong 50%
of the time all along.
What we need is a flag to set_pgd(), to tell it we're dealing with
userspace. Er, isn't that what the pgd's _PAGE_USER bit is saying?
Add a test for that. But we cannot do the same for pgd_clear()
(which may be called to clear corrupted entries - set aside the
question of "corrupt in which pgd?" until later), so there just
rely on pgd_clear() not being called in the problematic cases -
with a WARN_ON_ONCE() which should fire half the time if it is.
But this is getting too big for an inline function: move it into
arch/x86/mm/kaiser.c (which then demands a boot/compressed mod);
and de-void and de-space native_get_shadow/normal_pgd() while here.
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-05 12:05:01 -07:00
|
|
|
return (pgd_t *)((unsigned long)pgdp | (unsigned long)PAGE_SIZE);
|
2017-05-04 14:26:50 +02:00
|
|
|
}
|
2017-08-30 16:23:00 -07:00
|
|
|
#else
|
kaiser: do not set _PAGE_NX on pgd_none
native_pgd_clear() uses native_set_pgd(), so native_set_pgd() must
avoid setting the _PAGE_NX bit on an otherwise pgd_none() entry:
usually that just generated a warning on exit, but sometimes
more mysterious and damaging failures (our production machines
could not complete booting).
The original fix to this just avoided adding _PAGE_NX to
an empty entry; but eventually more problems surfaced with kexec,
and EFI mapping expected to be a problem too. So now instead
change native_set_pgd() to update shadow only if _PAGE_USER:
A few places (kernel/machine_kexec_64.c, platform/efi/efi_64.c for sure)
use set_pgd() to set up a temporary internal virtual address space, with
physical pages remapped at what Kaiser regards as userspace addresses:
Kaiser then assumes a shadow pgd follows, which it will try to corrupt.
This appears to be responsible for the recent kexec and kdump failures;
though it's unclear how those did not manifest as a problem before.
Ah, the shadow pgd will only be assumed to "follow" if the requested
pgd is on an even-numbered page: so I suppose it was going wrong 50%
of the time all along.
What we need is a flag to set_pgd(), to tell it we're dealing with
userspace. Er, isn't that what the pgd's _PAGE_USER bit is saying?
Add a test for that. But we cannot do the same for pgd_clear()
(which may be called to clear corrupted entries - set aside the
question of "corrupt in which pgd?" until later), so there just
rely on pgd_clear() not being called in the problematic cases -
with a WARN_ON_ONCE() which should fire half the time if it is.
But this is getting too big for an inline function: move it into
arch/x86/mm/kaiser.c (which then demands a boot/compressed mod);
and de-void and de-space native_get_shadow/normal_pgd() while here.
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-05 12:05:01 -07:00
|
|
|
static inline pgd_t kaiser_set_shadow_pgd(pgd_t *pgdp, pgd_t pgd)
|
|
|
|
{
|
|
|
|
return pgd;
|
|
|
|
}
|
|
|
|
static inline pgd_t *native_get_shadow_pgd(pgd_t *pgdp)
|
2017-08-30 16:23:00 -07:00
|
|
|
{
|
|
|
|
BUILD_BUG_ON(1);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-01-03 10:43:15 -08:00
|
|
|
#endif /* CONFIG_PAGE_TABLE_ISOLATION */
|
2017-05-04 14:26:50 +02:00
|
|
|
|
2008-01-30 13:32:58 +01:00
|
|
|
static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
|
|
|
|
{
|
kaiser: do not set _PAGE_NX on pgd_none
native_pgd_clear() uses native_set_pgd(), so native_set_pgd() must
avoid setting the _PAGE_NX bit on an otherwise pgd_none() entry:
usually that just generated a warning on exit, but sometimes
more mysterious and damaging failures (our production machines
could not complete booting).
The original fix to this just avoided adding _PAGE_NX to
an empty entry; but eventually more problems surfaced with kexec,
and EFI mapping expected to be a problem too. So now instead
change native_set_pgd() to update shadow only if _PAGE_USER:
A few places (kernel/machine_kexec_64.c, platform/efi/efi_64.c for sure)
use set_pgd() to set up a temporary internal virtual address space, with
physical pages remapped at what Kaiser regards as userspace addresses:
Kaiser then assumes a shadow pgd follows, which it will try to corrupt.
This appears to be responsible for the recent kexec and kdump failures;
though it's unclear how those did not manifest as a problem before.
Ah, the shadow pgd will only be assumed to "follow" if the requested
pgd is on an even-numbered page: so I suppose it was going wrong 50%
of the time all along.
What we need is a flag to set_pgd(), to tell it we're dealing with
userspace. Er, isn't that what the pgd's _PAGE_USER bit is saying?
Add a test for that. But we cannot do the same for pgd_clear()
(which may be called to clear corrupted entries - set aside the
question of "corrupt in which pgd?" until later), so there just
rely on pgd_clear() not being called in the problematic cases -
with a WARN_ON_ONCE() which should fire half the time if it is.
But this is getting too big for an inline function: move it into
arch/x86/mm/kaiser.c (which then demands a boot/compressed mod);
and de-void and de-space native_get_shadow/normal_pgd() while here.
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-09-05 12:05:01 -07:00
|
|
|
*pgdp = kaiser_set_shadow_pgd(pgdp, pgd);
|
2008-01-30 13:32:58 +01:00
|
|
|
}
|
2005-11-07 00:59:43 -08:00
|
|
|
|
2008-03-23 01:03:11 -07:00
|
|
|
static inline void native_pgd_clear(pgd_t *pgd)
|
2005-09-03 15:55:06 -07:00
|
|
|
{
|
2008-01-30 13:32:58 +01:00
|
|
|
native_set_pgd(pgd, native_make_pgd(0));
|
2005-09-03 15:55:06 -07:00
|
|
|
}
|
|
|
|
|
2014-08-22 13:27:34 -07:00
|
|
|
extern void sync_global_pgds(unsigned long start, unsigned long end,
|
|
|
|
int removed);
|
2010-05-19 17:42:14 +08:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* Conversion functions: convert a page and protection to a page entry,
|
|
|
|
* and a page entry and page directory to the page they refer to.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Level 4 access.
|
|
|
|
*/
|
2008-02-19 16:18:32 +01:00
|
|
|
static inline int pgd_large(pgd_t pgd) { return 0; }
|
2008-06-25 00:19:05 -04:00
|
|
|
#define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/* PUD - Level3 access */
|
|
|
|
|
|
|
|
/* PMD - Level 2 access */
|
|
|
|
|
|
|
|
/* PTE - Level 1 access. */
|
|
|
|
|
|
|
|
/* x86-64 always has all page tables mapped. */
|
2008-03-23 01:03:11 -07:00
|
|
|
#define pte_offset_map(dir, address) pte_offset_kernel((dir), (address))
|
2010-08-09 17:19:03 -07:00
|
|
|
#define pte_unmap(pte) ((void)(pte))/* NOP */
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/* Encode and de-code a swap entry */
|
2015-02-10 14:11:22 -08:00
|
|
|
#define SWP_TYPE_BITS 5
|
2008-12-16 11:35:24 +00:00
|
|
|
#define SWP_OFFSET_SHIFT (_PAGE_BIT_PROTNONE + 1)
|
|
|
|
|
|
|
|
#define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS)
|
|
|
|
|
|
|
|
#define __swp_type(x) (((x).val >> (_PAGE_BIT_PRESENT + 1)) \
|
|
|
|
& ((1U << SWP_TYPE_BITS) - 1))
|
|
|
|
#define __swp_offset(x) ((x).val >> SWP_OFFSET_SHIFT)
|
|
|
|
#define __swp_entry(type, offset) ((swp_entry_t) { \
|
|
|
|
((type) << (_PAGE_BIT_PRESENT + 1)) \
|
|
|
|
| ((offset) << SWP_OFFSET_SHIFT) })
|
2008-03-23 01:03:11 -07:00
|
|
|
#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) })
|
2008-01-30 13:32:57 +01:00
|
|
|
#define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-03-23 01:03:11 -07:00
|
|
|
extern int kern_addr_valid(unsigned long addr);
|
2008-02-15 17:29:12 +01:00
|
|
|
extern void cleanup_highmap(void);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
#define HAVE_ARCH_UNMAPPED_AREA
|
2008-01-30 13:31:07 +01:00
|
|
|
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
#define pgtable_cache_init() do { } while (0)
|
2007-09-21 12:09:41 -07:00
|
|
|
#define check_pgt_cache() do { } while (0)
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
#define PAGE_AGP PAGE_KERNEL_NOCACHE
|
|
|
|
#define HAVE_PAGE_AGP 1
|
|
|
|
|
|
|
|
/* fs/proc/kcore.c */
|
|
|
|
#define kc_vaddr_to_offset(v) ((v) & __VIRTUAL_MASK)
|
x86, 64-bit: Clean up user address masking
The discussion about using "access_ok()" in get_user_pages_fast() (see
commit 7f8189068726492950bf1a2dcfd9b51314560abf: "x86: don't use
'access_ok()' as a range check in get_user_pages_fast()" for details and
end result), made us notice that x86-64 was really being very sloppy
about virtual address checking.
So be way more careful and straightforward about masking x86-64 virtual
addresses:
- All the VIRTUAL_MASK* variants now cover half of the address
space, it's not like we can use the full mask on a signed
integer, and the larger mask just invites mistakes when
applying it to either half of the 48-bit address space.
- /proc/kcore's kc_offset_to_vaddr() becomes a lot more
obvious when it transforms a file offset into a
(kernel-half) virtual address.
- Unify/simplify the 32-bit and 64-bit USER_DS definition to
be based on TASK_SIZE_MAX.
This cleanup and more careful/obvious user virtual address checking also
uncovered a buglet in the x86-64 implementation of strnlen_user(): it
would do an "access_ok()" check on the whole potential area, even if the
string itself was much shorter, and thus return an error even for valid
strings. Our sloppy checking had hidden this.
So this fixes 'strnlen_user()' to do this properly, the same way we
already handled user strings in 'strncpy_from_user()'. Namely by just
checking the first byte, and then relying on fault handling for the
rest. That always works, since we impose a guard page that cannot be
mapped at the end of the user space address space (and even if we
didn't, we'd have the address space hole).
Acked-by: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nick Piggin <npiggin@suse.de>
Cc: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-06-20 15:40:00 -07:00
|
|
|
#define kc_offset_to_vaddr(o) ((o) | ~__VIRTUAL_MASK)
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
#define __HAVE_ARCH_PTE_SAME
|
2011-01-13 15:46:40 -08:00
|
|
|
|
2012-11-16 13:53:09 -08:00
|
|
|
#define vmemmap ((struct page *)VMEMMAP_START)
|
|
|
|
|
|
|
|
extern void init_extra_mapping_uc(unsigned long phys, unsigned long size);
|
|
|
|
extern void init_extra_mapping_wb(unsigned long phys, unsigned long size);
|
|
|
|
|
2007-05-02 19:27:06 +02:00
|
|
|
#endif /* !__ASSEMBLY__ */
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-10-22 22:26:29 -07:00
|
|
|
#endif /* _ASM_X86_PGTABLE_64_H */
|