blob: 177564187fc063c5f16af8b405c7dc1d90d54b64 [file] [log] [blame]
Andi Kleen33182fe2018-06-13 15:48:24 -07001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_PGTABLE_INVERT_H
3#define _ASM_PGTABLE_INVERT_H 1
4
5#ifndef __ASSEMBLY__
6
7static inline bool __pte_needs_invert(u64 val)
8{
9 return (val & (_PAGE_PRESENT|_PAGE_PROTNONE)) == _PAGE_PROTNONE;
10}
11
12/* Get a mask to xor with the page table entry to get the correct pfn. */
13static inline u64 protnone_mask(u64 val)
14{
15 return __pte_needs_invert(val) ? ~0ull : 0;
16}
17
18static inline u64 flip_protnone_guard(u64 oldval, u64 val, u64 mask)
19{
20 /*
21 * When a PTE transitions from NONE to !NONE or vice-versa
22 * invert the PFN part to stop speculation.
23 * pte_pfn undoes this when needed.
24 */
25 if (__pte_needs_invert(oldval) != __pte_needs_invert(val))
26 val = (val & ~mask) | (~val & mask);
27 return val;
28}
29
30#endif /* __ASSEMBLY__ */
31
32#endif