invpcid.h 1.6 KB

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