Guest User

Untitled

a guest
Oct 6th, 2026
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.28 KB | None | 0 0
  1. FINAL DRAFT
  2. ========================================================================
  3.  
  4. From: Michael Reeves <[email protected]>
  5. Date: Tue, 6 Oct 2026 12:15:25 +1100
  6. Subject: [PATCH 0/2] KVM: arm64: Work around Apple M3 LPI EOI hangs
  7.  
  8. Hi,
  9.  
  10. There's an erratum on Apple M3 CPUs where an LPI EOI after VM exit
  11. can leave the running priority unchanged. This can block later
  12. interrupts and therefore hang the guest.
  13.  
  14. This series updates KVM to trap Group-1 accesses on affected
  15. CPUs, which resolves the issue and restores normal VM functioning.
  16.  
  17. In the first patch, CPU IDs for Apple M3 CPUs are introduced.
  18.  
  19. In the second patch, an erratum capability for this issue is added,
  20. and when present, Group-1 accesses are trapped. Therefore, KVM
  21. emulates the EOI in software, and the running priority is properly
  22. cleared.
  23.  
  24. This can reduce guest interrupt performance, but is required in order
  25. for KVM to work correctly on these devices.
  26.  
  27. The erratum was reproduced on M3, M3 Pro (by myself) and M3 Max (by
  28. Myria). On all devices, kvm-arm.vgic_v3_group1_trap=1 prevented the
  29. guest hang.
  30.  
  31. This series was tested on J613 (MacBook Air M3, 2024, 13").
  32.  
  33. Myria Sarvay (1):
  34. arm64: Add Apple M3 CPU part numbers
  35.  
  36. Michael Reeves (1):
  37. KVM: arm64: vgic: Fix Apple M3 LPI EOI hangs
  38.  
  39. Documentation/arch/arm64/silicon-errata.rst | 3 +++
  40. arch/arm64/Kconfig | 14 +++++++++++
  41. arch/arm64/include/asm/cpucaps.h | 2 ++
  42. arch/arm64/include/asm/cputype.h | 12 +++++++++
  43. arch/arm64/kernel/cpu_errata.c | 28 +++++++++++++++++++++
  44. arch/arm64/kvm/vgic/vgic-v3.c | 4 +++
  45. arch/arm64/tools/cpucaps | 1 +
  46. 7 files changed, 64 insertions(+)
  47.  
  48.  
  49. base-commit: 67f0943b394d920b6c142aad8c6af94340342ae7
  50.  
  51.  
  52. ========================================================================
  53.  
  54. From: Myria Sarvay <[email protected]>
  55. Date: Tue, 6 Oct 2026 12:15:25 +1100
  56. Subject: [PATCH 1/2] arm64: Add Apple M3 CPU part numbers
  57.  
  58. Add Sawtooth and Everest CPU IDs for M3, M3 Pro, and M3 Max. The LPI EOI
  59. workaround needs these IDs to find the affected CPUs.
  60.  
  61. Signed-off-by: Myria Sarvay <[email protected]>
  62. Signed-off-by: Michael Reeves <[email protected]>
  63. ---
  64. arch/arm64/include/asm/cputype.h | 12 ++++++++++++
  65. 1 file changed, 12 insertions(+)
  66.  
  67. diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h
  68. index 1fa2961..886294e 100644
  69. --- a/arch/arm64/include/asm/cputype.h
  70. +++ b/arch/arm64/include/asm/cputype.h
  71. @@ -155,6 +155,12 @@
  72. #define APPLE_CPU_PART_M2_AVALANCHE_PRO 0x035
  73. #define APPLE_CPU_PART_M2_BLIZZARD_MAX 0x038
  74. #define APPLE_CPU_PART_M2_AVALANCHE_MAX 0x039
  75. +#define APPLE_CPU_PART_M3_SAWTOOTH 0x042
  76. +#define APPLE_CPU_PART_M3_EVEREST 0x043
  77. +#define APPLE_CPU_PART_M3_SAWTOOTH_PRO 0x044
  78. +#define APPLE_CPU_PART_M3_EVEREST_PRO 0x045
  79. +#define APPLE_CPU_PART_M3_SAWTOOTH_MAX 0x048
  80. +#define APPLE_CPU_PART_M3_EVEREST_MAX 0x049
  81.  
  82. #define AMPERE_CPU_PART_AMPERE1 0xAC3
  83. #define AMPERE_CPU_PART_AMPERE1A 0xAC4
  84. @@ -250,6 +256,12 @@
  85. #define MIDR_APPLE_M2_AVALANCHE_PRO MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_AVALANCHE_PRO)
  86. #define MIDR_APPLE_M2_BLIZZARD_MAX MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_BLIZZARD_MAX)
  87. #define MIDR_APPLE_M2_AVALANCHE_MAX MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_AVALANCHE_MAX)
  88. +#define MIDR_APPLE_M3_SAWTOOTH MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M3_SAWTOOTH)
  89. +#define MIDR_APPLE_M3_EVEREST MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M3_EVEREST)
  90. +#define MIDR_APPLE_M3_SAWTOOTH_PRO MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M3_SAWTOOTH_PRO)
  91. +#define MIDR_APPLE_M3_EVEREST_PRO MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M3_EVEREST_PRO)
  92. +#define MIDR_APPLE_M3_SAWTOOTH_MAX MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M3_SAWTOOTH_MAX)
  93. +#define MIDR_APPLE_M3_EVEREST_MAX MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M3_EVEREST_MAX)
  94. #define MIDR_AMPERE1 MIDR_CPU_MODEL(ARM_CPU_IMP_AMPERE, AMPERE_CPU_PART_AMPERE1)
  95. #define MIDR_AMPERE1A MIDR_CPU_MODEL(ARM_CPU_IMP_AMPERE, AMPERE_CPU_PART_AMPERE1A)
  96. #define MIDR_MICROSOFT_AZURE_COBALT_100 MIDR_CPU_MODEL(ARM_CPU_IMP_MICROSOFT, MICROSOFT_CPU_PART_AZURE_COBALT_100)
  97.  
  98. ========================================================================
  99.  
  100. From: Michael Reeves <[email protected]>
  101. Date: Tue, 6 Oct 2026 12:15:25 +1100
  102. Subject: [PATCH 2/2] KVM: arm64: vgic: Fix Apple M3 LPI EOI hangs
  103.  
  104. On Apple M3, an LPI EOI after a VM exit can leave the running priority
  105. unchanged. This can block later interrupts and hang the guest.
  106.  
  107. Introduce a new CPU erratum capability to represent this issue.
  108.  
  109. When the erratum is present, trap Group-1 CPU interface accesses
  110. on M3, M3 Pro, and M3 Max at EL2. The existing EOI handler then
  111. drops the priority in software.
  112.  
  113. Other Group-1 accesses also trap, which can reduce guest interrupt
  114. performance.
  115.  
  116. Signed-off-by: Michael Reeves <[email protected]>
  117. ---
  118. Documentation/arch/arm64/silicon-errata.rst | 3 +++
  119. arch/arm64/Kconfig | 14 +++++++++++
  120. arch/arm64/include/asm/cpucaps.h | 2 ++
  121. arch/arm64/kernel/cpu_errata.c | 28 +++++++++++++++++++++
  122. arch/arm64/kvm/vgic/vgic-v3.c | 4 +++
  123. arch/arm64/tools/cpucaps | 1 +
  124. 6 files changed, 52 insertions(+)
  125.  
  126. diff --git a/Documentation/arch/arm64/silicon-errata.rst b/Documentation/arch/arm64/silicon-errata.rst
  127. index 99a1eb4..d2995a0 100644
  128. --- a/Documentation/arch/arm64/silicon-errata.rst
  129. +++ b/Documentation/arch/arm64/silicon-errata.rst
  130. @@ -64,6 +64,9 @@ stable kernels.
  131. | Ampere | AmpereOne AC04 | AC04_CPU_29 | N/A |
  132. +----------------+-----------------+-----------------+-----------------------------+
  133. +----------------+-----------------+-----------------+-----------------------------+
  134. +| Apple | M3/M3 Pro/M3 Max| N/A | APPLE_M3_LPI_EOI_ERRATUM |
  135. ++----------------+-----------------+-----------------+-----------------------------+
  136. ++----------------+-----------------+-----------------+-----------------------------+
  137. | ARM | Cortex-A510 | #2457168 | ARM64_ERRATUM_2457168 |
  138. +----------------+-----------------+-----------------+-----------------------------+
  139. | ARM | Cortex-A510 | #2064142 | ARM64_ERRATUM_2064142 |
  140. diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
  141. index cab741a..0606c0d 100644
  142. --- a/arch/arm64/Kconfig
  143. +++ b/arch/arm64/Kconfig
  144. @@ -454,6 +454,20 @@ config AMPERE_ERRATUM_AC04_CPU_23
  145.  
  146. If unsure, say Y.
  147.  
  148. +config APPLE_M3_LPI_EOI_ERRATUM
  149. + bool "Apple M3: virtual GIC LPI EOI fails to drop priority"
  150. + depends on KVM
  151. + default y
  152. + help
  153. + On Apple M3, M3 Pro, and M3 Max, an LPI EOI after a VM exit can
  154. + leave the running priority unchanged. This can hang the guest.
  155. +
  156. + The workaround traps Group-1 CPU interface accesses at EL2.
  157. + KVM then handles EOI in software. These traps can reduce guest
  158. + interrupt performance.
  159. +
  160. + If unsure, say Y.
  161. +
  162. config ARM64_WORKAROUND_CLEAN_CACHE
  163. bool
  164.  
  165. diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h
  166. index 76350b3..4f879eb 100644
  167. --- a/arch/arm64/include/asm/cpucaps.h
  168. +++ b/arch/arm64/include/asm/cpucaps.h
  169. @@ -56,6 +56,8 @@ cpucap_is_possible(const unsigned int cap)
  170. return IS_ENABLED(CONFIG_ARM64_ERRATUM_2645198);
  171. case ARM64_WORKAROUND_2658417:
  172. return IS_ENABLED(CONFIG_ARM64_ERRATUM_2658417);
  173. + case ARM64_WORKAROUND_APPLE_M3_LPI_EOI:
  174. + return IS_ENABLED(CONFIG_APPLE_M3_LPI_EOI_ERRATUM);
  175. case ARM64_WORKAROUND_CAVIUM_23154:
  176. return IS_ENABLED(CONFIG_CAVIUM_ERRATUM_23154);
  177. case ARM64_WORKAROUND_DISABLE_CNP:
  178. diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
  179. index e0c0940..ae982b3 100644
  180. --- a/arch/arm64/kernel/cpu_errata.c
  181. +++ b/arch/arm64/kernel/cpu_errata.c
  182. @@ -314,6 +314,25 @@ static bool has_broken_gic_v3_seis(const struct arm64_cpu_capabilities *entry, i
  183. (read_sysreg_s(SYS_ICH_VTR_EL2) & ICH_VTR_EL2_SEIS));
  184. }
  185.  
  186. +#ifdef CONFIG_APPLE_M3_LPI_EOI_ERRATUM
  187. +static const struct midr_range apple_m3_lpi_eoi_cpus[] = {
  188. + MIDR_ALL_VERSIONS(MIDR_APPLE_M3_SAWTOOTH),
  189. + MIDR_ALL_VERSIONS(MIDR_APPLE_M3_EVEREST),
  190. + MIDR_ALL_VERSIONS(MIDR_APPLE_M3_SAWTOOTH_PRO),
  191. + MIDR_ALL_VERSIONS(MIDR_APPLE_M3_EVEREST_PRO),
  192. + MIDR_ALL_VERSIONS(MIDR_APPLE_M3_SAWTOOTH_MAX),
  193. + MIDR_ALL_VERSIONS(MIDR_APPLE_M3_EVEREST_MAX),
  194. + {},
  195. +};
  196. +
  197. +static bool has_apple_m3_lpi_eoi(const struct arm64_cpu_capabilities *entry,
  198. + int scope)
  199. +{
  200. + return is_kernel_in_hyp_mode() &&
  201. + is_affected_midr_range_list(entry, scope);
  202. +}
  203. +#endif
  204. +
  205. static void cpu_enable_impdef_pmuv3_traps(const struct arm64_cpu_capabilities *__unused)
  206. {
  207. sysreg_clear_set_s(SYS_HACR_EL2, 0, BIT(56));
  208. @@ -1039,6 +1058,15 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
  209. .matches = has_impdef_pmuv3,
  210. .cpu_enable = cpu_enable_impdef_pmuv3_traps,
  211. },
  212. +#ifdef CONFIG_APPLE_M3_LPI_EOI_ERRATUM
  213. + {
  214. + .desc = "Apple M3 virtual GIC LPI EOI workaround",
  215. + .capability = ARM64_WORKAROUND_APPLE_M3_LPI_EOI,
  216. + .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  217. + .matches = has_apple_m3_lpi_eoi,
  218. + .midr_range_list = apple_m3_lpi_eoi_cpus,
  219. + },
  220. +#endif
  221. {
  222. .desc = "Known broken GICv3 SEIS implementation",
  223. .capability = ARM64_WORKAROUND_GICv3_BROKEN_SEIS,
  224. diff --git a/arch/arm64/kvm/vgic/vgic-v3.c b/arch/arm64/kvm/vgic/vgic-v3.c
  225. index 346bacb..83fdd41 100644
  226. --- a/arch/arm64/kvm/vgic/vgic-v3.c
  227. +++ b/arch/arm64/kvm/vgic/vgic-v3.c
  228. @@ -847,6 +847,10 @@ void noinstr kvm_compute_ich_hcr_trap_bits(struct alt_instr *alt,
  229. dir_trap = true;
  230. }
  231.  
  232. + /* Trap Group-1 accesses so software drops the LPI priority. */
  233. + if (cpus_have_cap(ARM64_WORKAROUND_APPLE_M3_LPI_EOI))
  234. + group1_trap = true;
  235. +
  236. if (!cpus_have_cap(ARM64_HAS_ICH_HCR_EL2_TDIR))
  237. common_trap = true;
  238.  
  239. diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps
  240. index 58b6c08..fd9c8bb 100644
  241. --- a/arch/arm64/tools/cpucaps
  242. +++ b/arch/arm64/tools/cpucaps
  243. @@ -111,6 +111,7 @@ WORKAROUND_4193714
  244. WORKAROUND_4311569
  245. WORKAROUND_AMPERE_AC03_CPU_38
  246. WORKAROUND_AMPERE_AC04_CPU_23
  247. +WORKAROUND_APPLE_M3_LPI_EOI
  248. WORKAROUND_TRBE_OVERWRITE_FILL_MODE
  249. WORKAROUND_TSB_FLUSH_FAILURE
  250. WORKAROUND_TRBE_WRITE_OUT_OF_RANGE
  251.  
Advertisement
Add Comment
Please, Sign In to add comment