2015-12-01 03:36:30 +00:00
|
|
|
#ifndef _ASM_POWERPC_BOOK3S_64_HASH_64K_H
|
|
|
|
#define _ASM_POWERPC_BOOK3S_64_HASH_64K_H
|
|
|
|
|
|
|
|
#include <asm-generic/pgtable-nopud.h>
|
|
|
|
|
|
|
|
#define PTE_INDEX_SIZE 8
|
|
|
|
#define PMD_INDEX_SIZE 10
|
|
|
|
#define PUD_INDEX_SIZE 0
|
|
|
|
#define PGD_INDEX_SIZE 12
|
|
|
|
|
|
|
|
#define PTRS_PER_PTE (1 << PTE_INDEX_SIZE)
|
|
|
|
#define PTRS_PER_PMD (1 << PMD_INDEX_SIZE)
|
|
|
|
#define PTRS_PER_PGD (1 << PGD_INDEX_SIZE)
|
|
|
|
|
|
|
|
/* With 4k base page size, hugepage PTEs go at the PMD level */
|
|
|
|
#define MIN_HUGEPTE_SHIFT PAGE_SHIFT
|
|
|
|
|
|
|
|
/* PMD_SHIFT determines what a second-level page table entry can map */
|
|
|
|
#define PMD_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE)
|
|
|
|
#define PMD_SIZE (1UL << PMD_SHIFT)
|
|
|
|
#define PMD_MASK (~(PMD_SIZE-1))
|
|
|
|
|
|
|
|
/* PGDIR_SHIFT determines what a third-level page table entry can map */
|
|
|
|
#define PGDIR_SHIFT (PMD_SHIFT + PMD_INDEX_SIZE)
|
|
|
|
#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
|
|
|
|
#define PGDIR_MASK (~(PGDIR_SIZE-1))
|
|
|
|
|
|
|
|
/* Bits to mask out from a PMD to get to the PTE page */
|
|
|
|
/* PMDs point to PTE table fragments which are 4K aligned. */
|
|
|
|
#define PMD_MASKED_BITS 0xfff
|
|
|
|
/* Bits to mask out from a PGD/PUD to get to the PMD page */
|
|
|
|
#define PUD_MASKED_BITS 0x1ff
|
2005-11-07 00:06:55 +00:00
|
|
|
|
2015-12-01 03:36:45 +00:00
|
|
|
#define _PAGE_COMBO 0x00020000 /* this is a combo 4k page */
|
|
|
|
#define _PAGE_4K_PFN 0x00040000 /* PFN is for a single 4k page */
|
|
|
|
/*
|
|
|
|
* Used to track subpage group valid if _PAGE_COMBO is set
|
|
|
|
* This overloads _PAGE_F_GIX and _PAGE_F_SECOND
|
2007-05-08 06:27:28 +00:00
|
|
|
*/
|
2015-12-01 03:36:45 +00:00
|
|
|
#define _PAGE_COMBO_VALID (_PAGE_F_GIX | _PAGE_F_SECOND)
|
2005-11-07 00:06:55 +00:00
|
|
|
|
|
|
|
/* PTE flags to conserve for HPTE identification */
|
2008-06-11 05:37:10 +00:00
|
|
|
#define _PAGE_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE | _PAGE_COMBO)
|
2005-11-07 00:06:55 +00:00
|
|
|
|
|
|
|
/* Shift to put page number into pte.
|
|
|
|
*
|
2007-08-03 04:08:24 +00:00
|
|
|
* That gives us a max RPN of 34 bits, which means a max of 50 bits
|
|
|
|
* of addressable physical space, or 46 bits for the special 4k PFNs.
|
2005-11-07 00:06:55 +00:00
|
|
|
*/
|
2007-08-03 04:08:24 +00:00
|
|
|
#define PTE_RPN_SHIFT (30)
|
2005-11-07 00:06:55 +00:00
|
|
|
|
2009-03-10 17:53:29 +00:00
|
|
|
#ifndef __ASSEMBLY__
|
2005-11-07 00:06:55 +00:00
|
|
|
|
2009-03-10 17:53:29 +00:00
|
|
|
/*
|
|
|
|
* With 64K pages on hash table, we have a special PTE format that
|
|
|
|
* uses a second "half" of the page table to encode sub-page information
|
|
|
|
* in order to deal with 64K made of 4K HW pages. Thus we override the
|
|
|
|
* generic accessors and iterators here
|
|
|
|
*/
|
2014-08-13 07:02:03 +00:00
|
|
|
#define __real_pte __real_pte
|
|
|
|
static inline real_pte_t __real_pte(pte_t pte, pte_t *ptep)
|
|
|
|
{
|
|
|
|
real_pte_t rpte;
|
|
|
|
|
|
|
|
rpte.pte = pte;
|
|
|
|
rpte.hidx = 0;
|
|
|
|
if (pte_val(pte) & _PAGE_COMBO) {
|
|
|
|
/*
|
|
|
|
* Make sure we order the hidx load against the _PAGE_COMBO
|
|
|
|
* check. The store side ordering is done in __hash_page_4K
|
|
|
|
*/
|
|
|
|
smp_rmb();
|
|
|
|
rpte.hidx = pte_val(*((ptep) + PTRS_PER_PTE));
|
|
|
|
}
|
|
|
|
return rpte;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long __rpte_to_hidx(real_pte_t rpte, unsigned long index)
|
|
|
|
{
|
|
|
|
if ((pte_val(rpte.pte) & _PAGE_COMBO))
|
|
|
|
return (rpte.hidx >> (index<<2)) & 0xf;
|
|
|
|
return (pte_val(rpte.pte) >> 12) & 0xf;
|
|
|
|
}
|
|
|
|
|
2005-11-07 00:06:55 +00:00
|
|
|
#define __rpte_to_pte(r) ((r).pte)
|
2015-12-01 03:36:45 +00:00
|
|
|
extern bool __rpte_sub_valid(real_pte_t rpte, unsigned long index);
|
2015-12-01 03:36:30 +00:00
|
|
|
/*
|
|
|
|
* Trick: we set __end to va + 64k, which happens works for
|
2005-11-07 00:06:55 +00:00
|
|
|
* a 16M page as well as we want only one iteration
|
|
|
|
*/
|
2012-09-10 02:52:50 +00:00
|
|
|
#define pte_iterate_hashed_subpages(rpte, psize, vpn, index, shift) \
|
|
|
|
do { \
|
|
|
|
unsigned long __end = vpn + (1UL << (PAGE_SHIFT - VPN_SHIFT)); \
|
|
|
|
unsigned __split = (psize == MMU_PAGE_4K || \
|
|
|
|
psize == MMU_PAGE_64K_AP); \
|
|
|
|
shift = mmu_psize_defs[psize].shift; \
|
|
|
|
for (index = 0; vpn < __end; index++, \
|
|
|
|
vpn += (1L << (shift - VPN_SHIFT))) { \
|
|
|
|
if (!__split || __rpte_sub_valid(rpte, index)) \
|
|
|
|
do {
|
2005-11-07 00:06:55 +00:00
|
|
|
|
|
|
|
#define pte_iterate_hashed_end() } while(0); } } while(0)
|
|
|
|
|
2007-05-08 06:27:28 +00:00
|
|
|
#define pte_pagesize_index(mm, addr, pte) \
|
2006-06-15 00:45:18 +00:00
|
|
|
(((pte) & _PAGE_COMBO)? MMU_PAGE_4K: MMU_PAGE_64K)
|
2005-11-07 00:06:55 +00:00
|
|
|
|
[POWERPC] Allow drivers to map individual 4k pages to userspace
Some drivers have resources that they want to be able to map into
userspace that are 4k in size. On a kernel configured with 64k pages
we currently end up mapping the 4k we want plus another 60k of
physical address space, which could contain anything. This can
introduce security problems, for example in the case of an infiniband
adaptor where the other 60k could contain registers that some other
program is using for its communications.
This patch adds a new function, remap_4k_pfn, which drivers can use to
map a single 4k page to userspace regardless of whether the kernel is
using a 4k or a 64k page size. Like remap_pfn_range, it would
typically be called in a driver's mmap function. It only maps a
single 4k page, which on a 64k page kernel appears replicated 16 times
throughout a 64k page. On a 4k page kernel it reduces to a call to
remap_pfn_range.
The way this works on a 64k kernel is that a new bit, _PAGE_4K_PFN,
gets set on the linux PTE. This alters the way that __hash_page_4K
computes the real address to put in the HPTE. The RPN field of the
linux PTE becomes the 4k RPN directly rather than being interpreted as
a 64k RPN. Since the RPN field is 32 bits, this means that physical
addresses being mapped with remap_4k_pfn have to be below 2^44,
i.e. 0x100000000000.
The patch also factors out the code in arch/powerpc/mm/hash_utils_64.c
that deals with demoting a process to use 4k pages into one function
that gets called in the various different places where we need to do
that. There were some discrepancies between exactly what was done in
the various places, such as a call to spu_flush_all_slbs in one case
but not in others.
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-04-03 11:24:02 +00:00
|
|
|
#define remap_4k_pfn(vma, addr, pfn, prot) \
|
2014-07-10 15:15:13 +00:00
|
|
|
(WARN_ON(((pfn) >= (1UL << (64 - PTE_RPN_SHIFT)))) ? -EINVAL : \
|
|
|
|
remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, \
|
|
|
|
__pgprot(pgprot_val((prot)) | _PAGE_4K_PFN)))
|
[POWERPC] Allow drivers to map individual 4k pages to userspace
Some drivers have resources that they want to be able to map into
userspace that are 4k in size. On a kernel configured with 64k pages
we currently end up mapping the 4k we want plus another 60k of
physical address space, which could contain anything. This can
introduce security problems, for example in the case of an infiniband
adaptor where the other 60k could contain registers that some other
program is using for its communications.
This patch adds a new function, remap_4k_pfn, which drivers can use to
map a single 4k page to userspace regardless of whether the kernel is
using a 4k or a 64k page size. Like remap_pfn_range, it would
typically be called in a driver's mmap function. It only maps a
single 4k page, which on a 64k page kernel appears replicated 16 times
throughout a 64k page. On a 4k page kernel it reduces to a call to
remap_pfn_range.
The way this works on a 64k kernel is that a new bit, _PAGE_4K_PFN,
gets set on the linux PTE. This alters the way that __hash_page_4K
computes the real address to put in the HPTE. The RPN field of the
linux PTE becomes the 4k RPN directly rather than being interpreted as
a 64k RPN. Since the RPN field is 32 bits, this means that physical
addresses being mapped with remap_4k_pfn have to be below 2^44,
i.e. 0x100000000000.
The patch also factors out the code in arch/powerpc/mm/hash_utils_64.c
that deals with demoting a process to use 4k pages into one function
that gets called in the various different places where we need to do
that. There were some discrepancies between exactly what was done in
the various places, such as a call to spu_flush_all_slbs in one case
but not in others.
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-04-03 11:24:02 +00:00
|
|
|
|
2015-12-01 03:36:30 +00:00
|
|
|
#define PTE_TABLE_SIZE (sizeof(real_pte_t) << PTE_INDEX_SIZE)
|
|
|
|
#define PMD_TABLE_SIZE (sizeof(pmd_t) << PMD_INDEX_SIZE)
|
|
|
|
#define PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE)
|
|
|
|
|
|
|
|
#define pgd_pte(pgd) (pud_pte(((pud_t){ pgd })))
|
|
|
|
#define pte_pgd(pte) ((pgd_t)pte_pud(pte))
|
|
|
|
|
2009-03-10 17:53:29 +00:00
|
|
|
#endif /* __ASSEMBLY__ */
|
2015-12-01 03:36:30 +00:00
|
|
|
|
|
|
|
#endif /* _ASM_POWERPC_BOOK3S_64_HASH_64K_H */
|