2019-06-04 15:11:33 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2005-06-24 12:01:26 +07:00
|
|
|
/*
|
2007-08-23 00:14:51 +07:00
|
|
|
* include/asm-xtensa/pgtable.h
|
2005-06-24 12:01:26 +07:00
|
|
|
*
|
2013-05-21 01:09:13 +07:00
|
|
|
* Copyright (C) 2001 - 2013 Tensilica Inc.
|
2005-06-24 12:01:26 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _XTENSA_PGTABLE_H
|
|
|
|
#define _XTENSA_PGTABLE_H
|
|
|
|
|
|
|
|
#include <asm/page.h>
|
2016-04-12 01:07:30 +07:00
|
|
|
#include <asm/kmem_layout.h>
|
2017-12-04 04:28:52 +07:00
|
|
|
#include <asm-generic/pgtable-nopmd.h>
|
2005-06-24 12:01:26 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We only use two ring levels, user and kernel space.
|
|
|
|
*/
|
|
|
|
|
2015-09-20 18:45:37 +07:00
|
|
|
#ifdef CONFIG_MMU
|
2005-06-24 12:01:26 +07:00
|
|
|
#define USER_RING 1 /* user ring level */
|
2015-09-20 18:45:37 +07:00
|
|
|
#else
|
|
|
|
#define USER_RING 0
|
|
|
|
#endif
|
2005-06-24 12:01:26 +07:00
|
|
|
#define KERNEL_RING 0 /* kernel ring level */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The Xtensa architecture port of Linux has a two-level page table system,
|
2007-08-07 13:57:57 +07:00
|
|
|
* i.e. the logical three-level Linux page table layout is folded.
|
2005-06-24 12:01:26 +07:00
|
|
|
* Each task has the following memory page tables:
|
|
|
|
*
|
|
|
|
* PGD table (page directory), ie. 3rd-level page table:
|
|
|
|
* One page (4 kB) of 1024 (PTRS_PER_PGD) pointers to PTE tables
|
|
|
|
* (Architectures that don't have the PMD folded point to the PMD tables)
|
|
|
|
*
|
|
|
|
* The pointer to the PGD table for a given task can be retrieved from
|
|
|
|
* the task structure (struct task_struct*) t, e.g. current():
|
|
|
|
* (t->mm ? t->mm : t->active_mm)->pgd
|
|
|
|
*
|
|
|
|
* PMD tables (page middle-directory), ie. 2nd-level page tables:
|
|
|
|
* Absent for the Xtensa architecture (folded, PTRS_PER_PMD == 1).
|
|
|
|
*
|
|
|
|
* PTE tables (page table entry), ie. 1st-level page tables:
|
|
|
|
* One page (4 kB) of 1024 (PTRS_PER_PTE) PTEs with a special PTE
|
|
|
|
* invalid_pte_table for absent mappings.
|
|
|
|
*
|
|
|
|
* The individual pages are 4 kB big with special pages for the empty_zero_page.
|
|
|
|
*/
|
2007-08-07 13:57:57 +07:00
|
|
|
|
2005-06-24 12:01:26 +07:00
|
|
|
#define PGDIR_SHIFT 22
|
|
|
|
#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
|
|
|
|
#define PGDIR_MASK (~(PGDIR_SIZE-1))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Entries per page directory level: we use two-level, so
|
|
|
|
* we don't really have any PMD directory physically.
|
|
|
|
*/
|
|
|
|
#define PTRS_PER_PTE 1024
|
|
|
|
#define PTRS_PER_PTE_SHIFT 10
|
|
|
|
#define PTRS_PER_PGD 1024
|
|
|
|
#define PGD_ORDER 0
|
|
|
|
#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
|
2015-02-12 06:26:41 +07:00
|
|
|
#define FIRST_USER_ADDRESS 0UL
|
2005-06-24 12:01:26 +07:00
|
|
|
#define FIRST_USER_PGD_NR (FIRST_USER_ADDRESS >> PGDIR_SHIFT)
|
|
|
|
|
2018-07-12 04:33:41 +07:00
|
|
|
#ifdef CONFIG_MMU
|
2007-08-23 00:14:51 +07:00
|
|
|
/*
|
|
|
|
* Virtual memory area. We keep a distance to other memory regions to be
|
2005-06-24 12:01:26 +07:00
|
|
|
* on the safe side. We also use this area for cache aliasing.
|
|
|
|
*/
|
2016-04-12 01:07:30 +07:00
|
|
|
#define VMALLOC_START (XCHAL_KSEG_CACHED_VADDR - 0x10000000)
|
|
|
|
#define VMALLOC_END (VMALLOC_START + 0x07FEFFFF)
|
|
|
|
#define TLBTEMP_BASE_1 (VMALLOC_END + 1)
|
2014-07-22 01:01:51 +07:00
|
|
|
#define TLBTEMP_BASE_2 (TLBTEMP_BASE_1 + DCACHE_WAY_SIZE)
|
|
|
|
#if 2 * DCACHE_WAY_SIZE > ICACHE_WAY_SIZE
|
|
|
|
#define TLBTEMP_SIZE (2 * DCACHE_WAY_SIZE)
|
|
|
|
#else
|
|
|
|
#define TLBTEMP_SIZE ICACHE_WAY_SIZE
|
|
|
|
#endif
|
2005-06-24 12:01:26 +07:00
|
|
|
|
2018-07-12 04:33:41 +07:00
|
|
|
#else
|
|
|
|
|
|
|
|
#define VMALLOC_START __XTENSA_UL_CONST(0)
|
|
|
|
#define VMALLOC_END __XTENSA_UL_CONST(0xffffffff)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-08-23 00:14:51 +07:00
|
|
|
/*
|
2013-05-21 01:09:13 +07:00
|
|
|
* For the Xtensa architecture, the PTE layout is as follows:
|
|
|
|
*
|
|
|
|
* 31------12 11 10-9 8-6 5-4 3-2 1-0
|
|
|
|
* +-----------------------------------------+
|
|
|
|
* | | Software | HARDWARE |
|
|
|
|
* | PPN | ADW | RI |Attribute|
|
|
|
|
* +-----------------------------------------+
|
|
|
|
* pte_none | MBZ | 01 | 11 | 00 |
|
|
|
|
* +-----------------------------------------+
|
|
|
|
* present | PPN | 0 | 00 | ADW | RI | CA | wx |
|
|
|
|
* +- - - - - - - - - - - - - - - - - - - - -+
|
|
|
|
* (PAGE_NONE)| PPN | 0 | 00 | ADW | 01 | 11 | 11 |
|
|
|
|
* +-----------------------------------------+
|
|
|
|
* swap | index | type | 01 | 11 | 00 |
|
|
|
|
* +-----------------------------------------+
|
|
|
|
*
|
|
|
|
* For T1050 hardware and earlier the layout differs for present and (PAGE_NONE)
|
|
|
|
* +-----------------------------------------+
|
|
|
|
* present | PPN | 0 | 00 | ADW | RI | CA | w1 |
|
|
|
|
* +-----------------------------------------+
|
|
|
|
* (PAGE_NONE)| PPN | 0 | 00 | ADW | 01 | 01 | 00 |
|
|
|
|
* +-----------------------------------------+
|
2005-06-24 12:01:26 +07:00
|
|
|
*
|
2013-05-21 01:09:13 +07:00
|
|
|
* Legend:
|
|
|
|
* PPN Physical Page Number
|
|
|
|
* ADW software: accessed (young) / dirty / writable
|
|
|
|
* RI ring (0=privileged, 1=user, 2 and 3 are unused)
|
|
|
|
* CA cache attribute: 00 bypass, 01 writeback, 10 writethrough
|
|
|
|
* (11 is invalid and used to mark pages that are not present)
|
|
|
|
* w page is writable (hw)
|
|
|
|
* x page is executable (hw)
|
|
|
|
* index swap offset / PAGE_SIZE (bit 11-31: 21 bits -> 8 GB)
|
|
|
|
* (note that the index is always non-zero)
|
|
|
|
* type swap type (5 bits -> 32 types)
|
2005-06-24 12:01:26 +07:00
|
|
|
*
|
2013-05-21 01:09:13 +07:00
|
|
|
* Notes:
|
|
|
|
* - (PROT_NONE) is a special case of 'present' but causes an exception for
|
|
|
|
* any access (read, write, and execute).
|
|
|
|
* - 'multihit-exception' has the highest priority of all MMU exceptions,
|
|
|
|
* so the ring must be set to 'RING_USER' even for 'non-present' pages.
|
|
|
|
* - on older hardware, the exectuable flag was not supported and
|
|
|
|
* used as a 'valid' flag, so it needs to be always set.
|
|
|
|
* - we need to keep track of certain flags in software (dirty and young)
|
|
|
|
* to do this, we use write exceptions and have a separate software w-flag.
|
|
|
|
* - attribute value 1101 (and 1111 on T1050 and earlier) is reserved
|
2005-06-24 12:01:26 +07:00
|
|
|
*/
|
|
|
|
|
2013-05-21 01:09:13 +07:00
|
|
|
#define _PAGE_ATTRIB_MASK 0xf
|
|
|
|
|
2007-08-07 13:57:57 +07:00
|
|
|
#define _PAGE_HW_EXEC (1<<0) /* hardware: page is executable */
|
|
|
|
#define _PAGE_HW_WRITE (1<<1) /* hardware: page is writable */
|
|
|
|
|
|
|
|
#define _PAGE_CA_BYPASS (0<<2) /* bypass, non-speculative */
|
|
|
|
#define _PAGE_CA_WB (1<<2) /* write-back */
|
|
|
|
#define _PAGE_CA_WT (2<<2) /* write-through */
|
|
|
|
#define _PAGE_CA_MASK (3<<2)
|
2013-05-21 01:09:13 +07:00
|
|
|
#define _PAGE_CA_INVALID (3<<2)
|
|
|
|
|
|
|
|
/* We use invalid attribute values to distinguish special pte entries */
|
|
|
|
#if XCHAL_HW_VERSION_MAJOR < 2000
|
|
|
|
#define _PAGE_HW_VALID 0x01 /* older HW needed this bit set */
|
|
|
|
#define _PAGE_NONE 0x04
|
|
|
|
#else
|
|
|
|
#define _PAGE_HW_VALID 0x00
|
|
|
|
#define _PAGE_NONE 0x0f
|
|
|
|
#endif
|
2005-06-24 12:01:26 +07:00
|
|
|
|
|
|
|
#define _PAGE_USER (1<<4) /* user access (ring=1) */
|
|
|
|
|
|
|
|
/* Software */
|
2007-08-07 13:57:57 +07:00
|
|
|
#define _PAGE_WRITABLE_BIT 6
|
|
|
|
#define _PAGE_WRITABLE (1<<6) /* software: page writable */
|
2005-06-24 12:01:26 +07:00
|
|
|
#define _PAGE_DIRTY (1<<7) /* software: page dirty */
|
|
|
|
#define _PAGE_ACCESSED (1<<8) /* software: page accessed (read) */
|
|
|
|
|
|
|
|
#ifdef CONFIG_MMU
|
|
|
|
|
2013-05-21 01:09:13 +07:00
|
|
|
#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
|
|
|
|
#define _PAGE_PRESENT (_PAGE_HW_VALID | _PAGE_CA_WB | _PAGE_ACCESSED)
|
|
|
|
|
|
|
|
#define PAGE_NONE __pgprot(_PAGE_NONE | _PAGE_USER)
|
2007-08-07 13:57:57 +07:00
|
|
|
#define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_USER)
|
|
|
|
#define PAGE_COPY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_HW_EXEC)
|
|
|
|
#define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER)
|
|
|
|
#define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_HW_EXEC)
|
|
|
|
#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_WRITABLE)
|
|
|
|
#define PAGE_SHARED_EXEC \
|
|
|
|
__pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_WRITABLE | _PAGE_HW_EXEC)
|
2007-08-23 00:14:51 +07:00
|
|
|
#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_HW_WRITE)
|
2017-12-04 04:28:52 +07:00
|
|
|
#define PAGE_KERNEL_RO __pgprot(_PAGE_PRESENT)
|
2007-08-23 00:14:51 +07:00
|
|
|
#define PAGE_KERNEL_EXEC __pgprot(_PAGE_PRESENT|_PAGE_HW_WRITE|_PAGE_HW_EXEC)
|
2007-08-07 13:57:57 +07:00
|
|
|
|
|
|
|
#if (DCACHE_WAY_SIZE > PAGE_SIZE)
|
2013-05-21 01:09:13 +07:00
|
|
|
# define _PAGE_DIRECTORY (_PAGE_HW_VALID | _PAGE_ACCESSED | _PAGE_CA_BYPASS)
|
2007-08-07 13:57:57 +07:00
|
|
|
#else
|
2013-05-21 01:09:13 +07:00
|
|
|
# define _PAGE_DIRECTORY (_PAGE_HW_VALID | _PAGE_ACCESSED | _PAGE_CA_WB)
|
2007-08-07 13:57:57 +07:00
|
|
|
#endif
|
2005-06-24 12:01:26 +07:00
|
|
|
|
|
|
|
#else /* no mmu */
|
|
|
|
|
2014-09-22 09:32:47 +07:00
|
|
|
# define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
|
2005-06-24 12:01:26 +07:00
|
|
|
# define PAGE_NONE __pgprot(0)
|
|
|
|
# define PAGE_SHARED __pgprot(0)
|
|
|
|
# define PAGE_COPY __pgprot(0)
|
|
|
|
# define PAGE_READONLY __pgprot(0)
|
|
|
|
# define PAGE_KERNEL __pgprot(0)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On certain configurations of Xtensa MMUs (eg. the initial Linux config),
|
|
|
|
* the MMU can't do page protection for execute, and considers that the same as
|
|
|
|
* read. Also, write permissions may imply read permissions.
|
|
|
|
* What follows is the closest we can get by reasonable means..
|
|
|
|
* See linux/mm/mmap.c for protection_map[] array that uses these definitions.
|
|
|
|
*/
|
2007-08-07 13:57:57 +07:00
|
|
|
#define __P000 PAGE_NONE /* private --- */
|
|
|
|
#define __P001 PAGE_READONLY /* private --r */
|
|
|
|
#define __P010 PAGE_COPY /* private -w- */
|
|
|
|
#define __P011 PAGE_COPY /* private -wr */
|
|
|
|
#define __P100 PAGE_READONLY_EXEC /* private x-- */
|
|
|
|
#define __P101 PAGE_READONLY_EXEC /* private x-r */
|
|
|
|
#define __P110 PAGE_COPY_EXEC /* private xw- */
|
|
|
|
#define __P111 PAGE_COPY_EXEC /* private xwr */
|
|
|
|
|
|
|
|
#define __S000 PAGE_NONE /* shared --- */
|
|
|
|
#define __S001 PAGE_READONLY /* shared --r */
|
|
|
|
#define __S010 PAGE_SHARED /* shared -w- */
|
|
|
|
#define __S011 PAGE_SHARED /* shared -wr */
|
|
|
|
#define __S100 PAGE_READONLY_EXEC /* shared x-- */
|
|
|
|
#define __S101 PAGE_READONLY_EXEC /* shared x-r */
|
|
|
|
#define __S110 PAGE_SHARED_EXEC /* shared xw- */
|
|
|
|
#define __S111 PAGE_SHARED_EXEC /* shared xwr */
|
2005-06-24 12:01:26 +07:00
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
|
|
|
#define pte_ERROR(e) \
|
|
|
|
printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
|
|
|
|
#define pgd_ERROR(e) \
|
|
|
|
printk("%s:%d: bad pgd entry %08lx.\n", __FILE__, __LINE__, pgd_val(e))
|
|
|
|
|
|
|
|
extern unsigned long empty_zero_page[1024];
|
|
|
|
|
|
|
|
#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
|
|
|
|
|
2009-03-04 22:21:31 +07:00
|
|
|
#ifdef CONFIG_MMU
|
2005-06-24 12:01:26 +07:00
|
|
|
extern pgd_t swapper_pg_dir[PAGE_SIZE/sizeof(pgd_t)];
|
2009-03-04 22:21:31 +07:00
|
|
|
extern void paging_init(void);
|
|
|
|
#else
|
|
|
|
# define swapper_pg_dir NULL
|
|
|
|
static inline void paging_init(void) { }
|
|
|
|
#endif
|
2005-06-24 12:01:26 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The pmd contains the kernel virtual address of the pte page.
|
|
|
|
*/
|
2006-09-26 13:31:48 +07:00
|
|
|
#define pmd_page_vaddr(pmd) ((unsigned long)(pmd_val(pmd) & PAGE_MASK))
|
2005-06-24 12:01:26 +07:00
|
|
|
#define pmd_page(pmd) virt_to_page(pmd_val(pmd))
|
|
|
|
|
|
|
|
/*
|
2007-08-07 13:57:57 +07:00
|
|
|
* pte status.
|
2005-06-24 12:01:26 +07:00
|
|
|
*/
|
2013-05-21 01:09:13 +07:00
|
|
|
# define pte_none(pte) (pte_val(pte) == (_PAGE_CA_INVALID | _PAGE_USER))
|
|
|
|
#if XCHAL_HW_VERSION_MAJOR < 2000
|
|
|
|
# define pte_present(pte) ((pte_val(pte) & _PAGE_CA_MASK) != _PAGE_CA_INVALID)
|
|
|
|
#else
|
|
|
|
# define pte_present(pte) \
|
|
|
|
(((pte_val(pte) & _PAGE_CA_MASK) != _PAGE_CA_INVALID) \
|
|
|
|
|| ((pte_val(pte) & _PAGE_ATTRIB_MASK) == _PAGE_NONE))
|
|
|
|
#endif
|
2005-06-24 12:01:26 +07:00
|
|
|
#define pte_clear(mm,addr,ptep) \
|
2013-05-21 01:09:13 +07:00
|
|
|
do { update_pte(ptep, __pte(_PAGE_CA_INVALID | _PAGE_USER)); } while (0)
|
2005-06-24 12:01:26 +07:00
|
|
|
|
|
|
|
#define pmd_none(pmd) (!pmd_val(pmd))
|
|
|
|
#define pmd_present(pmd) (pmd_val(pmd) & PAGE_MASK)
|
|
|
|
#define pmd_bad(pmd) (pmd_val(pmd) & ~PAGE_MASK)
|
2007-08-07 13:57:57 +07:00
|
|
|
#define pmd_clear(pmdp) do { set_pmd(pmdp, __pmd(0)); } while (0)
|
2005-06-24 12:01:26 +07:00
|
|
|
|
2007-08-07 13:57:57 +07:00
|
|
|
static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITABLE; }
|
2005-06-24 12:01:26 +07:00
|
|
|
static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
|
|
|
|
static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
|
mm: introduce pte_special pte bit
s390 for one, cannot implement VM_MIXEDMAP with pfn_valid, due to their memory
model (which is more dynamic than most). Instead, they had proposed to
implement it with an additional path through vm_normal_page(), using a bit in
the pte to determine whether or not the page should be refcounted:
vm_normal_page()
{
...
if (unlikely(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP))) {
if (vma->vm_flags & VM_MIXEDMAP) {
#ifdef s390
if (!mixedmap_refcount_pte(pte))
return NULL;
#else
if (!pfn_valid(pfn))
return NULL;
#endif
goto out;
}
...
}
This is fine, however if we are allowed to use a bit in the pte to determine
refcountedness, we can use that to _completely_ replace all the vma based
schemes. So instead of adding more cases to the already complex vma-based
scheme, we can have a clearly seperate and simple pte-based scheme (and get
slightly better code generation in the process):
vm_normal_page()
{
#ifdef s390
if (!mixedmap_refcount_pte(pte))
return NULL;
return pte_page(pte);
#else
...
#endif
}
And finally, we may rather make this concept usable by any architecture rather
than making it s390 only, so implement a new type of pte state for this.
Unfortunately the old vma based code must stay, because some architectures may
not be able to spare pte bits. This makes vm_normal_page a little bit more
ugly than we would like, but the 2 cases are clearly seperate.
So introduce a pte_special pte state, and use it in mm/memory.c. It is
currently a noop for all architectures, so this doesn't actually result in any
compiled code changes to mm/memory.o.
BTW:
I haven't put vm_normal_page() into arch code as-per an earlier suggestion.
The reason is that, regardless of where vm_normal_page is actually
implemented, the *abstraction* is still exactly the same. Also, while it
depends on whether the architecture has pte_special or not, that is the
only two possible cases, and it really isn't an arch specific function --
the role of the arch code should be to provide primitive functions and
accessors with which to build the core code; pte_special does that. We do
not want architectures to know or care about vm_normal_page itself, and
we definitely don't want them being able to invent something new there
out of sight of mm/ code. If we made vm_normal_page an arch function, then
we have to make vm_insert_mixed (next patch) an arch function too. So I
don't think moving it to arch code fundamentally improves any abstractions,
while it does practically make the code more difficult to follow, for both
mm and arch developers, and easier to misuse.
[akpm@linux-foundation.org: build fix]
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Carsten Otte <cotte@de.ibm.com>
Cc: Jared Hulbert <jaredeh@gmail.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-04-28 16:13:00 +07:00
|
|
|
static inline int pte_special(pte_t pte) { return 0; }
|
|
|
|
|
2007-08-07 13:57:57 +07:00
|
|
|
static inline pte_t pte_wrprotect(pte_t pte)
|
|
|
|
{ pte_val(pte) &= ~(_PAGE_WRITABLE | _PAGE_HW_WRITE); return pte; }
|
|
|
|
static inline pte_t pte_mkclean(pte_t pte)
|
|
|
|
{ pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HW_WRITE); return pte; }
|
|
|
|
static inline pte_t pte_mkold(pte_t pte)
|
|
|
|
{ pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
|
|
|
|
static inline pte_t pte_mkdirty(pte_t pte)
|
|
|
|
{ pte_val(pte) |= _PAGE_DIRTY; return pte; }
|
|
|
|
static inline pte_t pte_mkyoung(pte_t pte)
|
|
|
|
{ pte_val(pte) |= _PAGE_ACCESSED; return pte; }
|
|
|
|
static inline pte_t pte_mkwrite(pte_t pte)
|
|
|
|
{ pte_val(pte) |= _PAGE_WRITABLE; return pte; }
|
mm: introduce pte_special pte bit
s390 for one, cannot implement VM_MIXEDMAP with pfn_valid, due to their memory
model (which is more dynamic than most). Instead, they had proposed to
implement it with an additional path through vm_normal_page(), using a bit in
the pte to determine whether or not the page should be refcounted:
vm_normal_page()
{
...
if (unlikely(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP))) {
if (vma->vm_flags & VM_MIXEDMAP) {
#ifdef s390
if (!mixedmap_refcount_pte(pte))
return NULL;
#else
if (!pfn_valid(pfn))
return NULL;
#endif
goto out;
}
...
}
This is fine, however if we are allowed to use a bit in the pte to determine
refcountedness, we can use that to _completely_ replace all the vma based
schemes. So instead of adding more cases to the already complex vma-based
scheme, we can have a clearly seperate and simple pte-based scheme (and get
slightly better code generation in the process):
vm_normal_page()
{
#ifdef s390
if (!mixedmap_refcount_pte(pte))
return NULL;
return pte_page(pte);
#else
...
#endif
}
And finally, we may rather make this concept usable by any architecture rather
than making it s390 only, so implement a new type of pte state for this.
Unfortunately the old vma based code must stay, because some architectures may
not be able to spare pte bits. This makes vm_normal_page a little bit more
ugly than we would like, but the 2 cases are clearly seperate.
So introduce a pte_special pte state, and use it in mm/memory.c. It is
currently a noop for all architectures, so this doesn't actually result in any
compiled code changes to mm/memory.o.
BTW:
I haven't put vm_normal_page() into arch code as-per an earlier suggestion.
The reason is that, regardless of where vm_normal_page is actually
implemented, the *abstraction* is still exactly the same. Also, while it
depends on whether the architecture has pte_special or not, that is the
only two possible cases, and it really isn't an arch specific function --
the role of the arch code should be to provide primitive functions and
accessors with which to build the core code; pte_special does that. We do
not want architectures to know or care about vm_normal_page itself, and
we definitely don't want them being able to invent something new there
out of sight of mm/ code. If we made vm_normal_page an arch function, then
we have to make vm_insert_mixed (next patch) an arch function too. So I
don't think moving it to arch code fundamentally improves any abstractions,
while it does practically make the code more difficult to follow, for both
mm and arch developers, and easier to misuse.
[akpm@linux-foundation.org: build fix]
Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Carsten Otte <cotte@de.ibm.com>
Cc: Jared Hulbert <jaredeh@gmail.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-04-28 16:13:00 +07:00
|
|
|
static inline pte_t pte_mkspecial(pte_t pte)
|
|
|
|
{ return pte; }
|
2005-06-24 12:01:26 +07:00
|
|
|
|
2014-09-11 11:05:21 +07:00
|
|
|
#define pgprot_noncached(prot) (__pgprot(pgprot_val(prot) & ~_PAGE_CA_MASK))
|
|
|
|
|
2005-06-24 12:01:26 +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.
|
|
|
|
*/
|
2007-08-07 13:57:57 +07:00
|
|
|
|
2005-06-24 12:01:26 +07:00
|
|
|
#define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT)
|
|
|
|
#define pte_same(a,b) (pte_val(a) == pte_val(b))
|
|
|
|
#define pte_page(x) pfn_to_page(pte_pfn(x))
|
|
|
|
#define pfn_pte(pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
|
|
|
|
#define mk_pte(page, prot) pfn_pte(page_to_pfn(page), prot)
|
|
|
|
|
2005-09-04 05:57:53 +07:00
|
|
|
static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
|
2005-06-24 12:01:26 +07:00
|
|
|
{
|
|
|
|
return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Certain architectures need to do special things when pte's
|
|
|
|
* within a page table are directly modified. Thus, the following
|
|
|
|
* hook is made available.
|
|
|
|
*/
|
|
|
|
static inline void update_pte(pte_t *ptep, pte_t pteval)
|
|
|
|
{
|
|
|
|
*ptep = pteval;
|
2007-08-23 00:14:51 +07:00
|
|
|
#if (DCACHE_WAY_SIZE > PAGE_SIZE) && XCHAL_DCACHE_IS_WRITEBACK
|
|
|
|
__asm__ __volatile__ ("dhwb %0, 0" :: "a" (ptep));
|
|
|
|
#endif
|
|
|
|
|
2005-06-24 12:01:26 +07:00
|
|
|
}
|
|
|
|
|
2005-11-07 15:59:43 +07:00
|
|
|
struct mm_struct;
|
|
|
|
|
2005-09-04 05:57:53 +07:00
|
|
|
static inline void
|
2005-06-24 12:01:26 +07:00
|
|
|
set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pteval)
|
|
|
|
{
|
|
|
|
update_pte(ptep, pteval);
|
|
|
|
}
|
|
|
|
|
2014-02-04 05:17:09 +07:00
|
|
|
static inline void set_pte(pte_t *ptep, pte_t pteval)
|
|
|
|
{
|
|
|
|
update_pte(ptep, pteval);
|
|
|
|
}
|
2005-06-24 12:01:26 +07:00
|
|
|
|
2005-09-04 05:57:53 +07:00
|
|
|
static inline void
|
2005-06-24 12:01:26 +07:00
|
|
|
set_pmd(pmd_t *pmdp, pmd_t pmdval)
|
|
|
|
{
|
|
|
|
*pmdp = pmdval;
|
|
|
|
}
|
|
|
|
|
2005-11-07 15:59:43 +07:00
|
|
|
struct vm_area_struct;
|
2005-06-24 12:01:26 +07:00
|
|
|
|
|
|
|
static inline int
|
|
|
|
ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr,
|
2012-11-29 07:53:51 +07:00
|
|
|
pte_t *ptep)
|
2005-06-24 12:01:26 +07:00
|
|
|
{
|
|
|
|
pte_t pte = *ptep;
|
|
|
|
if (!pte_young(pte))
|
|
|
|
return 0;
|
|
|
|
update_pte(ptep, pte_mkold(pte));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline pte_t
|
|
|
|
ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
|
|
|
|
{
|
|
|
|
pte_t pte = *ptep;
|
|
|
|
pte_clear(mm, addr, ptep);
|
|
|
|
return pte;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
|
|
|
|
{
|
2012-11-29 07:53:51 +07:00
|
|
|
pte_t pte = *ptep;
|
|
|
|
update_pte(ptep, pte_wrprotect(pte));
|
2005-06-24 12:01:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* to find an entry in a kernel page-table-directory */
|
|
|
|
#define pgd_offset_k(address) pgd_offset(&init_mm, address)
|
|
|
|
|
|
|
|
/* to find an entry in a page-table-directory */
|
|
|
|
#define pgd_offset(mm,address) ((mm)->pgd + pgd_index(address))
|
|
|
|
|
|
|
|
#define pgd_index(address) ((address) >> PGDIR_SHIFT)
|
|
|
|
|
|
|
|
/* Find an entry in the third-level page table.. */
|
|
|
|
#define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
|
|
|
|
#define pte_offset_kernel(dir,addr) \
|
2006-09-26 13:31:48 +07:00
|
|
|
((pte_t*) pmd_page_vaddr(*(dir)) + pte_index(addr))
|
2005-06-24 12:01:26 +07:00
|
|
|
#define pte_offset_map(dir,addr) pte_offset_kernel((dir),(addr))
|
|
|
|
#define pte_unmap(pte) do { } while (0)
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2013-05-21 01:09:13 +07:00
|
|
|
* Encode and decode a swap and file entry.
|
2005-06-24 12:01:26 +07:00
|
|
|
*/
|
2013-05-21 01:09:13 +07:00
|
|
|
#define SWP_TYPE_BITS 5
|
|
|
|
#define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS)
|
2005-06-24 12:01:26 +07:00
|
|
|
|
2007-08-07 13:57:57 +07:00
|
|
|
#define __swp_type(entry) (((entry).val >> 6) & 0x1f)
|
|
|
|
#define __swp_offset(entry) ((entry).val >> 11)
|
|
|
|
#define __swp_entry(type,offs) \
|
2013-05-21 01:09:13 +07:00
|
|
|
((swp_entry_t){((type) << 6) | ((offs) << 11) | \
|
|
|
|
_PAGE_CA_INVALID | _PAGE_USER})
|
2005-06-24 12:01:26 +07:00
|
|
|
#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
|
|
|
|
#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
|
|
|
|
|
|
|
|
#endif /* !defined (__ASSEMBLY__) */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __ASSEMBLY__
|
|
|
|
|
|
|
|
/* Assembly macro _PGD_INDEX is the same as C pgd_index(unsigned long),
|
|
|
|
* _PGD_OFFSET as C pgd_offset(struct mm_struct*, unsigned long),
|
|
|
|
* _PMD_OFFSET as C pmd_offset(pgd_t*, unsigned long)
|
|
|
|
* _PTE_OFFSET as C pte_offset(pmd_t*, unsigned long)
|
|
|
|
*
|
|
|
|
* Note: We require an additional temporary register which can be the same as
|
|
|
|
* the register that holds the address.
|
|
|
|
*
|
|
|
|
* ((pte_t*) ((unsigned long)(pmd_val(*pmd) & PAGE_MASK)) + pte_index(addr))
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define _PGD_INDEX(rt,rs) extui rt, rs, PGDIR_SHIFT, 32-PGDIR_SHIFT
|
|
|
|
#define _PTE_INDEX(rt,rs) extui rt, rs, PAGE_SHIFT, PTRS_PER_PTE_SHIFT
|
|
|
|
|
|
|
|
#define _PGD_OFFSET(mm,adr,tmp) l32i mm, mm, MM_PGD; \
|
|
|
|
_PGD_INDEX(tmp, adr); \
|
|
|
|
addx4 mm, tmp, mm
|
|
|
|
|
|
|
|
#define _PTE_OFFSET(pmd,adr,tmp) _PTE_INDEX(tmp, adr); \
|
|
|
|
srli pmd, pmd, PAGE_SHIFT; \
|
|
|
|
slli pmd, pmd, PAGE_SHIFT; \
|
|
|
|
addx4 pmd, tmp, pmd
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define kern_addr_valid(addr) (1)
|
|
|
|
|
|
|
|
extern void update_mmu_cache(struct vm_area_struct * vma,
|
MM: Pass a PTE pointer to update_mmu_cache() rather than the PTE itself
On VIVT ARM, when we have multiple shared mappings of the same file
in the same MM, we need to ensure that we have coherency across all
copies. We do this via make_coherent() by making the pages
uncacheable.
This used to work fine, until we allowed highmem with highpte - we
now have a page table which is mapped as required, and is not available
for modification via update_mmu_cache().
Ralf Beache suggested getting rid of the PTE value passed to
update_mmu_cache():
On MIPS update_mmu_cache() calls __update_tlb() which walks pagetables
to construct a pointer to the pte again. Passing a pte_t * is much
more elegant. Maybe we might even replace the pte argument with the
pte_t?
Ben Herrenschmidt would also like the pte pointer for PowerPC:
Passing the ptep in there is exactly what I want. I want that
-instead- of the PTE value, because I have issue on some ppc cases,
for I$/D$ coherency, where set_pte_at() may decide to mask out the
_PAGE_EXEC.
So, pass in the mapped page table pointer into update_mmu_cache(), and
remove the PTE value, updating all implementations and call sites to
suit.
Includes a fix from Stephen Rothwell:
sparc: fix fallout from update_mmu_cache API change
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2009-12-18 23:40:18 +07:00
|
|
|
unsigned long address, pte_t *ptep);
|
2005-06-24 12:01:26 +07:00
|
|
|
|
|
|
|
typedef pte_t *pte_addr_t;
|
|
|
|
|
|
|
|
#endif /* !defined (__ASSEMBLY__) */
|
|
|
|
|
|
|
|
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
|
|
|
|
#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
|
|
|
|
#define __HAVE_ARCH_PTEP_SET_WRPROTECT
|
|
|
|
#define __HAVE_ARCH_PTEP_MKDIRTY
|
|
|
|
#define __HAVE_ARCH_PTE_SAME
|
2012-12-22 09:35:04 +07:00
|
|
|
/* We provide our own get_unmapped_area to cope with
|
|
|
|
* SHM area cache aliasing for userland.
|
|
|
|
*/
|
|
|
|
#define HAVE_ARCH_UNMAPPED_AREA
|
2005-06-24 12:01:26 +07:00
|
|
|
|
|
|
|
#include <asm-generic/pgtable.h>
|
|
|
|
|
|
|
|
#endif /* _XTENSA_PGTABLE_H */
|