]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0181-x86-mm-Put-MMU-to-hardware-ASID-translation-in-one-p.patch
KPTI: add follow-up fixes
[pve-kernel.git] / patches / kernel / 0181-x86-mm-Put-MMU-to-hardware-ASID-translation-in-one-p.patch
CommitLineData
321d628a
FG
1From 427fbe54a8df451acd3cd31a4d6dbb1753036dee Mon Sep 17 00:00:00 2001
2From: Dave Hansen <dave.hansen@linux.intel.com>
3Date: Mon, 4 Dec 2017 15:07:56 +0100
e4cdf2a5 4Subject: [PATCH 181/241] x86/mm: Put MMU to hardware ASID translation in one
321d628a
FG
5 place
6MIME-Version: 1.0
7Content-Type: text/plain; charset=UTF-8
8Content-Transfer-Encoding: 8bit
9
10CVE-2017-5754
11
12There are effectively two ASID types:
13
14 1. The one stored in the mmu_context that goes from 0..5
15 2. The one programmed into the hardware that goes from 1..6
16
17This consolidates the locations where converting between the two (by doing
18a +1) to a single place which gives us a nice place to comment.
19PAGE_TABLE_ISOLATION will also need to, given an ASID, know which hardware
20ASID to flush for the userspace mapping.
21
22Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
23Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
24Cc: Andy Lutomirski <luto@kernel.org>
25Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
26Cc: Borislav Petkov <bp@alien8.de>
27Cc: Brian Gerst <brgerst@gmail.com>
28Cc: Dave Hansen <dave.hansen@intel.com>
29Cc: David Laight <David.Laight@aculab.com>
30Cc: Denys Vlasenko <dvlasenk@redhat.com>
31Cc: Eduardo Valentin <eduval@amazon.com>
32Cc: Greg KH <gregkh@linuxfoundation.org>
33Cc: H. Peter Anvin <hpa@zytor.com>
34Cc: Josh Poimboeuf <jpoimboe@redhat.com>
35Cc: Juergen Gross <jgross@suse.com>
36Cc: Linus Torvalds <torvalds@linux-foundation.org>
37Cc: Peter Zijlstra <peterz@infradead.org>
38Cc: Will Deacon <will.deacon@arm.com>
39Cc: aliguori@amazon.com
40Cc: daniel.gruss@iaik.tugraz.at
41Cc: hughd@google.com
42Cc: keescook@google.com
43Cc: linux-mm@kvack.org
44Signed-off-by: Ingo Molnar <mingo@kernel.org>
45(cherry picked from commit dd95f1a4b5ca904c78e6a097091eb21436478abb)
46Signed-off-by: Andy Whitcroft <apw@canonical.com>
47Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
48(cherry picked from commit 6f3e88a8f41123ac339d28cfdda5da0e85bec550)
49Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
50---
51 arch/x86/include/asm/tlbflush.h | 31 +++++++++++++++++++------------
52 1 file changed, 19 insertions(+), 12 deletions(-)
53
54diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
55index c1c10db4156c..ecd634f87e4e 100644
56--- a/arch/x86/include/asm/tlbflush.h
57+++ b/arch/x86/include/asm/tlbflush.h
58@@ -84,30 +84,37 @@ static inline u64 inc_mm_tlb_gen(struct mm_struct *mm)
59 */
60 #define MAX_ASID_AVAILABLE ((1 << CR3_AVAIL_ASID_BITS) - 2)
61
62-/*
63- * If PCID is on, ASID-aware code paths put the ASID+1 into the PCID bits.
64- * This serves two purposes. It prevents a nasty situation in which
65- * PCID-unaware code saves CR3, loads some other value (with PCID == 0),
66- * and then restores CR3, thus corrupting the TLB for ASID 0 if the saved
67- * ASID was nonzero. It also means that any bugs involving loading a
68- * PCID-enabled CR3 with CR4.PCIDE off will trigger deterministically.
69- */
70+static inline u16 kern_pcid(u16 asid)
71+{
72+ VM_WARN_ON_ONCE(asid > MAX_ASID_AVAILABLE);
73+ /*
74+ * If PCID is on, ASID-aware code paths put the ASID+1 into the
75+ * PCID bits. This serves two purposes. It prevents a nasty
76+ * situation in which PCID-unaware code saves CR3, loads some other
77+ * value (with PCID == 0), and then restores CR3, thus corrupting
78+ * the TLB for ASID 0 if the saved ASID was nonzero. It also means
79+ * that any bugs involving loading a PCID-enabled CR3 with
80+ * CR4.PCIDE off will trigger deterministically.
81+ */
82+ return asid + 1;
83+}
84+
85 struct pgd_t;
86 static inline unsigned long build_cr3(pgd_t *pgd, u16 asid)
87 {
88 if (static_cpu_has(X86_FEATURE_PCID)) {
89- VM_WARN_ON_ONCE(asid > MAX_ASID_AVAILABLE);
90- return __sme_pa(pgd) | (asid + 1);
91+ return __pa(pgd) | kern_pcid(asid);
92 } else {
93 VM_WARN_ON_ONCE(asid != 0);
94- return __sme_pa(pgd);
95+ return __pa(pgd);
96 }
97 }
98
99 static inline unsigned long build_cr3_noflush(pgd_t *pgd, u16 asid)
100 {
101 VM_WARN_ON_ONCE(asid > MAX_ASID_AVAILABLE);
102- return __sme_pa(pgd) | (asid + 1) | CR3_NOFLUSH;
103+ VM_WARN_ON_ONCE(!this_cpu_has(X86_FEATURE_PCID));
104+ return __pa(pgd) | kern_pcid(asid) | CR3_NOFLUSH;
105 }
106
107 #ifdef CONFIG_PARAVIRT
108--
1092.14.2
110