| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- From a67ab82a8f60f725b002034dff10f28c7e2ac88e Mon Sep 17 00:00:00 2001
- From: Peter Zijlstra <[email protected]>
- Date: Tue, 5 Dec 2017 13:34:47 +0100
- Subject: [PATCH 182/232] x86/mm: Create asm/invpcid.h
- MIME-Version: 1.0
- Content-Type: text/plain; charset=UTF-8
- Content-Transfer-Encoding: 8bit
- CVE-2017-5754
- Unclutter tlbflush.h a little.
- Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
- Cc: Andy Lutomirski <[email protected]>
- Cc: Boris Ostrovsky <[email protected]>
- Cc: Borislav Petkov <[email protected]>
- Cc: Brian Gerst <[email protected]>
- Cc: Dave Hansen <[email protected]>
- Cc: David Laight <[email protected]>
- Cc: Denys Vlasenko <[email protected]>
- Cc: Eduardo Valentin <[email protected]>
- Cc: Greg KH <[email protected]>
- Cc: H. Peter Anvin <[email protected]>
- Cc: Josh Poimboeuf <[email protected]>
- Cc: Juergen Gross <[email protected]>
- Cc: Linus Torvalds <[email protected]>
- Cc: Peter Zijlstra <[email protected]>
- Cc: Thomas Gleixner <[email protected]>
- Cc: Will Deacon <[email protected]>
- Cc: [email protected]
- Cc: [email protected]
- Cc: [email protected]
- Cc: [email protected]
- Cc: [email protected]
- Signed-off-by: Ingo Molnar <[email protected]>
- (cherry picked from commit 1a3b0caeb77edeac5ce5fa05e6a61c474c9a9745)
- Signed-off-by: Andy Whitcroft <[email protected]>
- Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
- (cherry picked from commit 5af02a8c43ce521f460891f6ba68af69428abe90)
- Signed-off-by: Fabian Grünbichler <[email protected]>
- ---
- arch/x86/include/asm/invpcid.h | 53 +++++++++++++++++++++++++++++++++++++++++
- arch/x86/include/asm/tlbflush.h | 49 +------------------------------------
- 2 files changed, 54 insertions(+), 48 deletions(-)
- create mode 100644 arch/x86/include/asm/invpcid.h
- diff --git a/arch/x86/include/asm/invpcid.h b/arch/x86/include/asm/invpcid.h
- new file mode 100644
- index 000000000000..989cfa86de85
- --- /dev/null
- +++ b/arch/x86/include/asm/invpcid.h
- @@ -0,0 +1,53 @@
- +/* SPDX-License-Identifier: GPL-2.0 */
- +#ifndef _ASM_X86_INVPCID
- +#define _ASM_X86_INVPCID
- +
- +static inline void __invpcid(unsigned long pcid, unsigned long addr,
- + unsigned long type)
- +{
- + struct { u64 d[2]; } desc = { { pcid, addr } };
- +
- + /*
- + * The memory clobber is because the whole point is to invalidate
- + * stale TLB entries and, especially if we're flushing global
- + * mappings, we don't want the compiler to reorder any subsequent
- + * memory accesses before the TLB flush.
- + *
- + * The hex opcode is invpcid (%ecx), %eax in 32-bit mode and
- + * invpcid (%rcx), %rax in long mode.
- + */
- + asm volatile (".byte 0x66, 0x0f, 0x38, 0x82, 0x01"
- + : : "m" (desc), "a" (type), "c" (&desc) : "memory");
- +}
- +
- +#define INVPCID_TYPE_INDIV_ADDR 0
- +#define INVPCID_TYPE_SINGLE_CTXT 1
- +#define INVPCID_TYPE_ALL_INCL_GLOBAL 2
- +#define INVPCID_TYPE_ALL_NON_GLOBAL 3
- +
- +/* Flush all mappings for a given pcid and addr, not including globals. */
- +static inline void invpcid_flush_one(unsigned long pcid,
- + unsigned long addr)
- +{
- + __invpcid(pcid, addr, INVPCID_TYPE_INDIV_ADDR);
- +}
- +
- +/* Flush all mappings for a given PCID, not including globals. */
- +static inline void invpcid_flush_single_context(unsigned long pcid)
- +{
- + __invpcid(pcid, 0, INVPCID_TYPE_SINGLE_CTXT);
- +}
- +
- +/* Flush all mappings, including globals, for all PCIDs. */
- +static inline void invpcid_flush_all(void)
- +{
- + __invpcid(0, 0, INVPCID_TYPE_ALL_INCL_GLOBAL);
- +}
- +
- +/* Flush all mappings for all PCIDs except globals. */
- +static inline void invpcid_flush_all_nonglobals(void)
- +{
- + __invpcid(0, 0, INVPCID_TYPE_ALL_NON_GLOBAL);
- +}
- +
- +#endif /* _ASM_X86_INVPCID */
- diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
- index ecd634f87e4e..503f87c30c15 100644
- --- a/arch/x86/include/asm/tlbflush.h
- +++ b/arch/x86/include/asm/tlbflush.h
- @@ -8,54 +8,7 @@
- #include <asm/cpufeature.h>
- #include <asm/special_insns.h>
- #include <asm/smp.h>
- -
- -static inline void __invpcid(unsigned long pcid, unsigned long addr,
- - unsigned long type)
- -{
- - struct { u64 d[2]; } desc = { { pcid, addr } };
- -
- - /*
- - * The memory clobber is because the whole point is to invalidate
- - * stale TLB entries and, especially if we're flushing global
- - * mappings, we don't want the compiler to reorder any subsequent
- - * memory accesses before the TLB flush.
- - *
- - * The hex opcode is invpcid (%ecx), %eax in 32-bit mode and
- - * invpcid (%rcx), %rax in long mode.
- - */
- - asm volatile (".byte 0x66, 0x0f, 0x38, 0x82, 0x01"
- - : : "m" (desc), "a" (type), "c" (&desc) : "memory");
- -}
- -
- -#define INVPCID_TYPE_INDIV_ADDR 0
- -#define INVPCID_TYPE_SINGLE_CTXT 1
- -#define INVPCID_TYPE_ALL_INCL_GLOBAL 2
- -#define INVPCID_TYPE_ALL_NON_GLOBAL 3
- -
- -/* Flush all mappings for a given pcid and addr, not including globals. */
- -static inline void invpcid_flush_one(unsigned long pcid,
- - unsigned long addr)
- -{
- - __invpcid(pcid, addr, INVPCID_TYPE_INDIV_ADDR);
- -}
- -
- -/* Flush all mappings for a given PCID, not including globals. */
- -static inline void invpcid_flush_single_context(unsigned long pcid)
- -{
- - __invpcid(pcid, 0, INVPCID_TYPE_SINGLE_CTXT);
- -}
- -
- -/* Flush all mappings, including globals, for all PCIDs. */
- -static inline void invpcid_flush_all(void)
- -{
- - __invpcid(0, 0, INVPCID_TYPE_ALL_INCL_GLOBAL);
- -}
- -
- -/* Flush all mappings for all PCIDs except globals. */
- -static inline void invpcid_flush_all_nonglobals(void)
- -{
- - __invpcid(0, 0, INVPCID_TYPE_ALL_NON_GLOBAL);
- -}
- +#include <asm/invpcid.h>
-
- static inline u64 inc_mm_tlb_gen(struct mm_struct *mm)
- {
- --
- 2.14.2
|