Skip to content

Commit 1a3b0ca

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
x86/mm: Create asm/invpcid.h
Unclutter tlbflush.h a little. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Laight <David.Laight@aculab.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Eduardo Valentin <eduval@amazon.com> Cc: Greg KH <gregkh@linuxfoundation.org> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Juergen Gross <jgross@suse.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will.deacon@arm.com> Cc: aliguori@amazon.com Cc: daniel.gruss@iaik.tugraz.at Cc: hughd@google.com Cc: keescook@google.com Cc: linux-mm@kvack.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent dd95f1a commit 1a3b0ca

File tree

2 files changed

+54
-48
lines changed

2 files changed

+54
-48
lines changed

arch/x86/include/asm/invpcid.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_X86_INVPCID
3+
#define _ASM_X86_INVPCID
4+
5+
static inline void __invpcid(unsigned long pcid, unsigned long addr,
6+
unsigned long type)
7+
{
8+
struct { u64 d[2]; } desc = { { pcid, addr } };
9+
10+
/*
11+
* The memory clobber is because the whole point is to invalidate
12+
* stale TLB entries and, especially if we're flushing global
13+
* mappings, we don't want the compiler to reorder any subsequent
14+
* memory accesses before the TLB flush.
15+
*
16+
* The hex opcode is invpcid (%ecx), %eax in 32-bit mode and
17+
* invpcid (%rcx), %rax in long mode.
18+
*/
19+
asm volatile (".byte 0x66, 0x0f, 0x38, 0x82, 0x01"
20+
: : "m" (desc), "a" (type), "c" (&desc) : "memory");
21+
}
22+
23+
#define INVPCID_TYPE_INDIV_ADDR 0
24+
#define INVPCID_TYPE_SINGLE_CTXT 1
25+
#define INVPCID_TYPE_ALL_INCL_GLOBAL 2
26+
#define INVPCID_TYPE_ALL_NON_GLOBAL 3
27+
28+
/* Flush all mappings for a given pcid and addr, not including globals. */
29+
static inline void invpcid_flush_one(unsigned long pcid,
30+
unsigned long addr)
31+
{
32+
__invpcid(pcid, addr, INVPCID_TYPE_INDIV_ADDR);
33+
}
34+
35+
/* Flush all mappings for a given PCID, not including globals. */
36+
static inline void invpcid_flush_single_context(unsigned long pcid)
37+
{
38+
__invpcid(pcid, 0, INVPCID_TYPE_SINGLE_CTXT);
39+
}
40+
41+
/* Flush all mappings, including globals, for all PCIDs. */
42+
static inline void invpcid_flush_all(void)
43+
{
44+
__invpcid(0, 0, INVPCID_TYPE_ALL_INCL_GLOBAL);
45+
}
46+
47+
/* Flush all mappings for all PCIDs except globals. */
48+
static inline void invpcid_flush_all_nonglobals(void)
49+
{
50+
__invpcid(0, 0, INVPCID_TYPE_ALL_NON_GLOBAL);
51+
}
52+
53+
#endif /* _ASM_X86_INVPCID */

arch/x86/include/asm/tlbflush.h

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,7 @@
99
#include <asm/cpufeature.h>
1010
#include <asm/special_insns.h>
1111
#include <asm/smp.h>
12-
13-
static inline void __invpcid(unsigned long pcid, unsigned long addr,
14-
unsigned long type)
15-
{
16-
struct { u64 d[2]; } desc = { { pcid, addr } };
17-
18-
/*
19-
* The memory clobber is because the whole point is to invalidate
20-
* stale TLB entries and, especially if we're flushing global
21-
* mappings, we don't want the compiler to reorder any subsequent
22-
* memory accesses before the TLB flush.
23-
*
24-
* The hex opcode is invpcid (%ecx), %eax in 32-bit mode and
25-
* invpcid (%rcx), %rax in long mode.
26-
*/
27-
asm volatile (".byte 0x66, 0x0f, 0x38, 0x82, 0x01"
28-
: : "m" (desc), "a" (type), "c" (&desc) : "memory");
29-
}
30-
31-
#define INVPCID_TYPE_INDIV_ADDR 0
32-
#define INVPCID_TYPE_SINGLE_CTXT 1
33-
#define INVPCID_TYPE_ALL_INCL_GLOBAL 2
34-
#define INVPCID_TYPE_ALL_NON_GLOBAL 3
35-
36-
/* Flush all mappings for a given pcid and addr, not including globals. */
37-
static inline void invpcid_flush_one(unsigned long pcid,
38-
unsigned long addr)
39-
{
40-
__invpcid(pcid, addr, INVPCID_TYPE_INDIV_ADDR);
41-
}
42-
43-
/* Flush all mappings for a given PCID, not including globals. */
44-
static inline void invpcid_flush_single_context(unsigned long pcid)
45-
{
46-
__invpcid(pcid, 0, INVPCID_TYPE_SINGLE_CTXT);
47-
}
48-
49-
/* Flush all mappings, including globals, for all PCIDs. */
50-
static inline void invpcid_flush_all(void)
51-
{
52-
__invpcid(0, 0, INVPCID_TYPE_ALL_INCL_GLOBAL);
53-
}
54-
55-
/* Flush all mappings for all PCIDs except globals. */
56-
static inline void invpcid_flush_all_nonglobals(void)
57-
{
58-
__invpcid(0, 0, INVPCID_TYPE_ALL_NON_GLOBAL);
59-
}
12+
#include <asm/invpcid.h>
6013

6114
static inline u64 inc_mm_tlb_gen(struct mm_struct *mm)
6215
{

0 commit comments

Comments
 (0)