cpuinfo.rst 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. .. SPDX-License-Identifier: GPL-2.0
  2. =================
  3. x86 Feature Flags
  4. =================
  5. Introduction
  6. ============
  7. On x86, flags appearing in /proc/cpuinfo have an X86_FEATURE definition
  8. in arch/x86/include/asm/cpufeatures.h. If the kernel cares about a feature
  9. or KVM want to expose the feature to a KVM guest, it can and should have
  10. an X86_FEATURE_* defined. These flags represent hardware features as
  11. well as software features.
  12. If users want to know if a feature is available on a given system, they
  13. try to find the flag in /proc/cpuinfo. If a given flag is present, it
  14. means that the kernel supports it and is currently making it available.
  15. If such flag represents a hardware feature, it also means that the
  16. hardware supports it.
  17. If the expected flag does not appear in /proc/cpuinfo, things are murkier.
  18. Users need to find out the reason why the flag is missing and find the way
  19. how to enable it, which is not always easy. There are several factors that
  20. can explain missing flags: the expected feature failed to enable, the feature
  21. is missing in hardware, platform firmware did not enable it, the feature is
  22. disabled at build or run time, an old kernel is in use, or the kernel does
  23. not support the feature and thus has not enabled it. In general, /proc/cpuinfo
  24. shows features which the kernel supports. For a full list of CPUID flags
  25. which the CPU supports, use tools/arch/x86/kcpuid.
  26. How are feature flags created?
  27. ==============================
  28. a: Feature flags can be derived from the contents of CPUID leaves.
  29. ------------------------------------------------------------------
  30. These feature definitions are organized mirroring the layout of CPUID
  31. leaves and grouped in words with offsets as mapped in enum cpuid_leafs
  32. in cpufeatures.h (see arch/x86/include/asm/cpufeatures.h for details).
  33. If a feature is defined with a X86_FEATURE_<name> definition in
  34. cpufeatures.h, and if it is detected at run time, the flags will be
  35. displayed accordingly in /proc/cpuinfo. For example, the flag "avx2"
  36. comes from X86_FEATURE_AVX2 in cpufeatures.h.
  37. b: Flags can be from scattered CPUID-based features.
  38. ----------------------------------------------------
  39. Hardware features enumerated in sparsely populated CPUID leaves get
  40. software-defined values. Still, CPUID needs to be queried to determine
  41. if a given feature is present. This is done in init_scattered_cpuid_features().
  42. For instance, X86_FEATURE_CQM_LLC is defined as 11*32 + 0 and its presence is
  43. checked at runtime in the respective CPUID leaf [EAX=f, ECX=0] bit EDX[1].
  44. The intent of scattering CPUID leaves is to not bloat struct
  45. cpuinfo_x86.x86_capability[] unnecessarily. For instance, the CPUID leaf
  46. [EAX=7, ECX=0] has 30 features and is dense, but the CPUID leaf [EAX=7, EAX=1]
  47. has only one feature and would waste 31 bits of space in the x86_capability[]
  48. array. Since there is a struct cpuinfo_x86 for each possible CPU, the wasted
  49. memory is not trivial.
  50. c: Flags can be created synthetically under certain conditions for hardware features.
  51. -------------------------------------------------------------------------------------
  52. Examples of conditions include whether certain features are present in
  53. MSR_IA32_CORE_CAPS or specific CPU models are identified. If the needed
  54. conditions are met, the features are enabled by the set_cpu_cap or
  55. setup_force_cpu_cap macros. For example, if bit 5 is set in MSR_IA32_CORE_CAPS,
  56. the feature X86_FEATURE_SPLIT_LOCK_DETECT will be enabled and
  57. "split_lock_detect" will be displayed. The flag "ring3mwait" will be
  58. displayed only when running on INTEL_FAM6_XEON_PHI_[KNL|KNM] processors.
  59. d: Flags can represent purely software features.
  60. ------------------------------------------------
  61. These flags do not represent hardware features. Instead, they represent a
  62. software feature implemented in the kernel. For example, Kernel Page Table
  63. Isolation is purely software feature and its feature flag X86_FEATURE_PTI is
  64. also defined in cpufeatures.h.
  65. Naming of Flags
  66. ===============
  67. The script arch/x86/kernel/cpu/mkcapflags.sh processes the
  68. #define X86_FEATURE_<name> from cpufeatures.h and generates the
  69. x86_cap/bug_flags[] arrays in kernel/cpu/capflags.c. The names in the
  70. resulting x86_cap/bug_flags[] are used to populate /proc/cpuinfo. The naming
  71. of flags in the x86_cap/bug_flags[] are as follows:
  72. a: The name of the flag is from the string in X86_FEATURE_<name> by default.
  73. ----------------------------------------------------------------------------
  74. By default, the flag <name> in /proc/cpuinfo is extracted from the respective
  75. X86_FEATURE_<name> in cpufeatures.h. For example, the flag "avx2" is from
  76. X86_FEATURE_AVX2.
  77. b: The naming can be overridden.
  78. --------------------------------
  79. If the comment on the line for the #define X86_FEATURE_* starts with a
  80. double-quote character (""), the string inside the double-quote characters
  81. will be the name of the flags. For example, the flag "sse4_1" comes from
  82. the comment "sse4_1" following the X86_FEATURE_XMM4_1 definition.
  83. There are situations in which overriding the displayed name of the flag is
  84. needed. For instance, /proc/cpuinfo is a userspace interface and must remain
  85. constant. If, for some reason, the naming of X86_FEATURE_<name> changes, one
  86. shall override the new naming with the name already used in /proc/cpuinfo.
  87. c: The naming override can be "", which means it will not appear in /proc/cpuinfo.
  88. ----------------------------------------------------------------------------------
  89. The feature shall be omitted from /proc/cpuinfo if it does not make sense for
  90. the feature to be exposed to userspace. For example, X86_FEATURE_ALWAYS is
  91. defined in cpufeatures.h but that flag is an internal kernel feature used
  92. in the alternative runtime patching functionality. So, its name is overridden
  93. with "". Its flag will not appear in /proc/cpuinfo.
  94. Flags are missing when one or more of these happen
  95. ==================================================
  96. a: The hardware does not enumerate support for it.
  97. --------------------------------------------------
  98. For example, when a new kernel is running on old hardware or the feature is
  99. not enabled by boot firmware. Even if the hardware is new, there might be a
  100. problem enabling the feature at run time, the flag will not be displayed.
  101. b: The kernel does not know about the flag.
  102. -------------------------------------------
  103. For example, when an old kernel is running on new hardware.
  104. c: The kernel disabled support for it at compile-time.
  105. ------------------------------------------------------
  106. For example, if 5-level-paging is not enabled when building (i.e.,
  107. CONFIG_X86_5LEVEL is not selected) the flag "la57" will not show up [#f1]_.
  108. Even though the feature will still be detected via CPUID, the kernel disables
  109. it by clearing via setup_clear_cpu_cap(X86_FEATURE_LA57).
  110. d: The feature is disabled at boot-time.
  111. ----------------------------------------
  112. A feature can be disabled either using a command-line parameter or because
  113. it failed to be enabled. The command-line parameter clearcpuid= can be used
  114. to disable features using the feature number as defined in
  115. /arch/x86/include/asm/cpufeatures.h. For instance, User Mode Instruction
  116. Protection can be disabled using clearcpuid=514. The number 514 is calculated
  117. from #define X86_FEATURE_UMIP (16*32 + 2).
  118. In addition, there exists a variety of custom command-line parameters that
  119. disable specific features. The list of parameters includes, but is not limited
  120. to, nofsgsbase, nosmap, and nosmep. 5-level paging can also be disabled using
  121. "no5lvl". SMAP and SMEP are disabled with the aforementioned parameters,
  122. respectively.
  123. e: The feature was known to be non-functional.
  124. ----------------------------------------------
  125. The feature was known to be non-functional because a dependency was
  126. missing at runtime. For example, AVX flags will not show up if XSAVE feature
  127. is disabled since they depend on XSAVE feature. Another example would be broken
  128. CPUs and them missing microcode patches. Due to that, the kernel decides not to
  129. enable a feature.
  130. .. [#f1] 5-level paging uses linear address of 57 bits.