From 2a139ee95deecdfd4f7e23d5ab6e76ec7320a0cb Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Wed, 9 Dec 2020 10:10:39 -0800 Subject: [PATCH] x86: pte_atomic_update should not return flipped KPTI gymnastics need to be abstracted away from callers to page_map_set(). Signed-off-by: Andrew Boie --- arch/x86/core/x86_mmu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/core/x86_mmu.c b/arch/x86/core/x86_mmu.c index 6caaf88a84e..70e346f6178 100644 --- a/arch/x86/core/x86_mmu.c +++ b/arch/x86/core/x86_mmu.c @@ -861,6 +861,13 @@ static inline pentry_t pte_atomic_update(pentry_t *pte, pentry_t update_val, new_val = pte_finalize_value(new_val, user_table); } while (atomic_pte_cas(pte, old_val, new_val) == false); +#ifdef CONFIG_X86_KPTI + if (is_flipped_pte(old_val)) { + /* Page was flipped for KPTI. Un-flip it */ + old_val = ~old_val; + } +#endif /* CONFIG_X86_KPTI */ + return old_val; }