invpcid.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. asm volatile("invpcid %[desc], %[type]"
  15. :: [desc] "m" (desc), [type] "r" (type) : "memory");
  16. }
  17. #define INVPCID_TYPE_INDIV_ADDR 0
  18. #define INVPCID_TYPE_SINGLE_CTXT 1
  19. #define INVPCID_TYPE_ALL_INCL_GLOBAL 2
  20. #define INVPCID_TYPE_ALL_NON_GLOBAL 3
  21. /* Flush all mappings for a given pcid and addr, not including globals. */
  22. static inline void invpcid_flush_one(unsigned long pcid,
  23. unsigned long addr)
  24. {
  25. __invpcid(pcid, addr, INVPCID_TYPE_INDIV_ADDR);
  26. }
  27. /* Flush all mappings for a given PCID, not including globals. */
  28. static inline void invpcid_flush_single_context(unsigned long pcid)
  29. {
  30. __invpcid(pcid, 0, INVPCID_TYPE_SINGLE_CTXT);
  31. }
  32. /* Flush all mappings, including globals, for all PCIDs. */
  33. static inline void invpcid_flush_all(void)
  34. {
  35. __invpcid(0, 0, INVPCID_TYPE_ALL_INCL_GLOBAL);
  36. }
  37. /* Flush all mappings for all PCIDs except globals. */
  38. static inline void invpcid_flush_all_nonglobals(void)
  39. {
  40. __invpcid(0, 0, INVPCID_TYPE_ALL_NON_GLOBAL);
  41. }
  42. #endif /* _ASM_X86_INVPCID */