blob: 60d0f90153178b3fb104360536854d676f7429ee [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07002#ifndef _ASM_X86_PGTABLE_2LEVEL_H
3#define _ASM_X86_PGTABLE_2LEVEL_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#define pte_ERROR(e) \
Joe Perchesc767a542012-05-21 19:50:07 -07006 pr_err("%s:%d: bad pte %08lx\n", __FILE__, __LINE__, (e).pte_low)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#define pgd_ERROR(e) \
Joe Perchesc767a542012-05-21 19:50:07 -07008 pr_err("%s:%d: bad pgd %08lx\n", __FILE__, __LINE__, pgd_val(e))
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10/*
11 * Certain architectures need to do special things when PTEs
12 * within a page table are directly modified. Thus, the following
13 * hook is made available.
14 */
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020015static inline void native_set_pte(pte_t *ptep , pte_t pte)
16{
17 *ptep = pte;
18}
Jeremy Fitzhardinge48916452008-01-30 13:32:58 +010019
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020020static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
21{
22 *pmdp = pmd;
23}
Rusty Russellda181a82006-12-07 02:14:08 +010024
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -080025static inline void native_set_pud(pud_t *pudp, pud_t pud)
26{
27}
28
Jeremy Fitzhardinge48916452008-01-30 13:32:58 +010029static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
30{
31 native_set_pte(ptep, pte);
32}
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Jeremy Fitzhardinge48916452008-01-30 13:32:58 +010034static inline void native_pmd_clear(pmd_t *pmdp)
35{
36 native_set_pmd(pmdp, __pmd(0));
37}
Zachary Amsden6e5882c2006-04-27 11:32:29 -070038
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -080039static inline void native_pud_clear(pud_t *pudp)
40{
41}
42
Joe Perches65e05d12008-03-23 01:03:08 -070043static inline void native_pte_clear(struct mm_struct *mm,
44 unsigned long addr, pte_t *xp)
Zachary Amsdenc2c1acc2007-05-02 19:27:19 +020045{
Jeremy Fitzhardinge48916452008-01-30 13:32:58 +010046 *xp = native_make_pte(0);
Zachary Amsdenc2c1acc2007-05-02 19:27:19 +020047}
48
Zachary Amsden142dd972007-05-02 19:27:19 +020049#ifdef CONFIG_SMP
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020050static inline pte_t native_ptep_get_and_clear(pte_t *xp)
51{
52 return __pte(xchg(&xp->pte_low, 0));
53}
Zachary Amsden142dd972007-05-02 19:27:19 +020054#else
55#define native_ptep_get_and_clear(xp) native_local_ptep_get_and_clear(xp)
56#endif
Rusty Russell60497422006-09-25 23:32:30 -070057
Johannes Weinerf2d6bfe2011-01-13 15:47:01 -080058#ifdef CONFIG_SMP
59static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
60{
61 return __pmd(xchg((pmdval_t *)xp, 0));
62}
63#else
64#define native_pmdp_get_and_clear(xp) native_local_pmdp_get_and_clear(xp)
65#endif
66
Matthew Wilcoxa00cc7d2017-02-24 14:57:02 -080067#ifdef CONFIG_SMP
68static inline pud_t native_pudp_get_and_clear(pud_t *xp)
69{
70 return __pud(xchg((pudval_t *)xp, 0));
71}
72#else
73#define native_pudp_get_and_clear(xp) native_local_pudp_get_and_clear(xp)
74#endif
75
Cyrill Gorcunov5305ca12013-11-15 14:14:00 -080076/* Bit manipulation helper on pte/pgoff entry */
77static inline unsigned long pte_bitop(unsigned long value, unsigned int rightshift,
78 unsigned long mask, unsigned int leftshift)
79{
80 return ((value >> rightshift) & mask) << leftshift;
81}
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083/* Encode and de-code a swap entry */
Kirill A. Shutemov0a191362015-02-10 14:11:22 -080084#define SWP_TYPE_BITS 5
Jan Beulich17963162008-12-16 11:35:24 +000085#define SWP_OFFSET_SHIFT (_PAGE_BIT_PROTNONE + 1)
Jan Beulich17963162008-12-16 11:35:24 +000086
87#define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS)
88
89#define __swp_type(x) (((x).val >> (_PAGE_BIT_PRESENT + 1)) \
90 & ((1U << SWP_TYPE_BITS) - 1))
91#define __swp_offset(x) ((x).val >> SWP_OFFSET_SHIFT)
92#define __swp_entry(type, offset) ((swp_entry_t) { \
93 ((type) << (_PAGE_BIT_PRESENT + 1)) \
94 | ((offset) << SWP_OFFSET_SHIFT) })
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_low })
Jeremy Fitzhardingec8e53932008-01-30 13:32:57 +010096#define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Andi Kleen6b28bac2018-06-13 15:48:24 -070098/* No inverted PFNs on 2 level page tables */
99
100static inline u64 protnone_mask(u64 val)
101{
102 return 0;
103}
104
105static inline u64 flip_protnone_guard(u64 oldval, u64 val, u64 mask)
106{
107 return val;
108}
109
110static inline bool __pte_needs_invert(u64 val)
111{
112 return false;
113}
114
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700115#endif /* _ASM_X86_PGTABLE_2LEVEL_H */