fpsimd.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. /*
  2. * FP/SIMD context switching and fault handling
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. * Author: Catalin Marinas <catalin.marinas@arm.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/bitmap.h>
  20. #include <linux/bottom_half.h>
  21. #include <linux/bug.h>
  22. #include <linux/cache.h>
  23. #include <linux/compat.h>
  24. #include <linux/cpu.h>
  25. #include <linux/cpu_pm.h>
  26. #include <linux/kernel.h>
  27. #include <linux/linkage.h>
  28. #include <linux/irqflags.h>
  29. #include <linux/init.h>
  30. #include <linux/percpu.h>
  31. #include <linux/prctl.h>
  32. #include <linux/preempt.h>
  33. #include <linux/ptrace.h>
  34. #include <linux/sched/signal.h>
  35. #include <linux/sched/task_stack.h>
  36. #include <linux/signal.h>
  37. #include <linux/slab.h>
  38. #include <linux/stddef.h>
  39. #include <linux/sysctl.h>
  40. #include <asm/esr.h>
  41. #include <asm/fpsimd.h>
  42. #include <asm/cpufeature.h>
  43. #include <asm/cputype.h>
  44. #include <asm/processor.h>
  45. #include <asm/simd.h>
  46. #include <asm/sigcontext.h>
  47. #include <asm/sysreg.h>
  48. #include <asm/traps.h>
  49. #define FPEXC_IOF (1 << 0)
  50. #define FPEXC_DZF (1 << 1)
  51. #define FPEXC_OFF (1 << 2)
  52. #define FPEXC_UFF (1 << 3)
  53. #define FPEXC_IXF (1 << 4)
  54. #define FPEXC_IDF (1 << 7)
  55. /*
  56. * (Note: in this discussion, statements about FPSIMD apply equally to SVE.)
  57. *
  58. * In order to reduce the number of times the FPSIMD state is needlessly saved
  59. * and restored, we need to keep track of two things:
  60. * (a) for each task, we need to remember which CPU was the last one to have
  61. * the task's FPSIMD state loaded into its FPSIMD registers;
  62. * (b) for each CPU, we need to remember which task's userland FPSIMD state has
  63. * been loaded into its FPSIMD registers most recently, or whether it has
  64. * been used to perform kernel mode NEON in the meantime.
  65. *
  66. * For (a), we add a fpsimd_cpu field to thread_struct, which gets updated to
  67. * the id of the current CPU every time the state is loaded onto a CPU. For (b),
  68. * we add the per-cpu variable 'fpsimd_last_state' (below), which contains the
  69. * address of the userland FPSIMD state of the task that was loaded onto the CPU
  70. * the most recently, or NULL if kernel mode NEON has been performed after that.
  71. *
  72. * With this in place, we no longer have to restore the next FPSIMD state right
  73. * when switching between tasks. Instead, we can defer this check to userland
  74. * resume, at which time we verify whether the CPU's fpsimd_last_state and the
  75. * task's fpsimd_cpu are still mutually in sync. If this is the case, we
  76. * can omit the FPSIMD restore.
  77. *
  78. * As an optimization, we use the thread_info flag TIF_FOREIGN_FPSTATE to
  79. * indicate whether or not the userland FPSIMD state of the current task is
  80. * present in the registers. The flag is set unless the FPSIMD registers of this
  81. * CPU currently contain the most recent userland FPSIMD state of the current
  82. * task.
  83. *
  84. * In order to allow softirq handlers to use FPSIMD, kernel_neon_begin() may
  85. * save the task's FPSIMD context back to task_struct from softirq context.
  86. * To prevent this from racing with the manipulation of the task's FPSIMD state
  87. * from task context and thereby corrupting the state, it is necessary to
  88. * protect any manipulation of a task's fpsimd_state or TIF_FOREIGN_FPSTATE
  89. * flag with local_bh_disable() unless softirqs are already masked.
  90. *
  91. * For a certain task, the sequence may look something like this:
  92. * - the task gets scheduled in; if both the task's fpsimd_cpu field
  93. * contains the id of the current CPU, and the CPU's fpsimd_last_state per-cpu
  94. * variable points to the task's fpsimd_state, the TIF_FOREIGN_FPSTATE flag is
  95. * cleared, otherwise it is set;
  96. *
  97. * - the task returns to userland; if TIF_FOREIGN_FPSTATE is set, the task's
  98. * userland FPSIMD state is copied from memory to the registers, the task's
  99. * fpsimd_cpu field is set to the id of the current CPU, the current
  100. * CPU's fpsimd_last_state pointer is set to this task's fpsimd_state and the
  101. * TIF_FOREIGN_FPSTATE flag is cleared;
  102. *
  103. * - the task executes an ordinary syscall; upon return to userland, the
  104. * TIF_FOREIGN_FPSTATE flag will still be cleared, so no FPSIMD state is
  105. * restored;
  106. *
  107. * - the task executes a syscall which executes some NEON instructions; this is
  108. * preceded by a call to kernel_neon_begin(), which copies the task's FPSIMD
  109. * register contents to memory, clears the fpsimd_last_state per-cpu variable
  110. * and sets the TIF_FOREIGN_FPSTATE flag;
  111. *
  112. * - the task gets preempted after kernel_neon_end() is called; as we have not
  113. * returned from the 2nd syscall yet, TIF_FOREIGN_FPSTATE is still set so
  114. * whatever is in the FPSIMD registers is not saved to memory, but discarded.
  115. */
  116. struct fpsimd_last_state_struct {
  117. struct user_fpsimd_state *st;
  118. };
  119. static DEFINE_PER_CPU(struct fpsimd_last_state_struct, fpsimd_last_state);
  120. /* Default VL for tasks that don't set it explicitly: */
  121. static int sve_default_vl = -1;
  122. #ifdef CONFIG_ARM64_SVE
  123. /* Maximum supported vector length across all CPUs (initially poisoned) */
  124. int __ro_after_init sve_max_vl = SVE_VL_MIN;
  125. /* Set of available vector lengths, as vq_to_bit(vq): */
  126. static __ro_after_init DECLARE_BITMAP(sve_vq_map, SVE_VQ_MAX);
  127. static void __percpu *efi_sve_state;
  128. #else /* ! CONFIG_ARM64_SVE */
  129. /* Dummy declaration for code that will be optimised out: */
  130. extern __ro_after_init DECLARE_BITMAP(sve_vq_map, SVE_VQ_MAX);
  131. extern void __percpu *efi_sve_state;
  132. #endif /* ! CONFIG_ARM64_SVE */
  133. /*
  134. * Call __sve_free() directly only if you know task can't be scheduled
  135. * or preempted.
  136. */
  137. static void __sve_free(struct task_struct *task)
  138. {
  139. kfree(task->thread.sve_state);
  140. task->thread.sve_state = NULL;
  141. }
  142. static void sve_free(struct task_struct *task)
  143. {
  144. WARN_ON(test_tsk_thread_flag(task, TIF_SVE));
  145. __sve_free(task);
  146. }
  147. /*
  148. * TIF_SVE controls whether a task can use SVE without trapping while
  149. * in userspace, and also the way a task's FPSIMD/SVE state is stored
  150. * in thread_struct.
  151. *
  152. * The kernel uses this flag to track whether a user task is actively
  153. * using SVE, and therefore whether full SVE register state needs to
  154. * be tracked. If not, the cheaper FPSIMD context handling code can
  155. * be used instead of the more costly SVE equivalents.
  156. *
  157. * * TIF_SVE set:
  158. *
  159. * The task can execute SVE instructions while in userspace without
  160. * trapping to the kernel.
  161. *
  162. * When stored, Z0-Z31 (incorporating Vn in bits[127:0] or the
  163. * corresponding Zn), P0-P15 and FFR are encoded in in
  164. * task->thread.sve_state, formatted appropriately for vector
  165. * length task->thread.sve_vl.
  166. *
  167. * task->thread.sve_state must point to a valid buffer at least
  168. * sve_state_size(task) bytes in size.
  169. *
  170. * During any syscall, the kernel may optionally clear TIF_SVE and
  171. * discard the vector state except for the FPSIMD subset.
  172. *
  173. * * TIF_SVE clear:
  174. *
  175. * An attempt by the user task to execute an SVE instruction causes
  176. * do_sve_acc() to be called, which does some preparation and then
  177. * sets TIF_SVE.
  178. *
  179. * When stored, FPSIMD registers V0-V31 are encoded in
  180. * task->thread.uw.fpsimd_state; bits [max : 128] for each of Z0-Z31 are
  181. * logically zero but not stored anywhere; P0-P15 and FFR are not
  182. * stored and have unspecified values from userspace's point of
  183. * view. For hygiene purposes, the kernel zeroes them on next use,
  184. * but userspace is discouraged from relying on this.
  185. *
  186. * task->thread.sve_state does not need to be non-NULL, valid or any
  187. * particular size: it must not be dereferenced.
  188. *
  189. * * FPSR and FPCR are always stored in task->thread.uw.fpsimd_state
  190. * irrespective of whether TIF_SVE is clear or set, since these are
  191. * not vector length dependent.
  192. */
  193. /*
  194. * Update current's FPSIMD/SVE registers from thread_struct.
  195. *
  196. * This function should be called only when the FPSIMD/SVE state in
  197. * thread_struct is known to be up to date, when preparing to enter
  198. * userspace.
  199. *
  200. * Softirqs (and preemption) must be disabled.
  201. */
  202. static void task_fpsimd_load(void)
  203. {
  204. WARN_ON(!in_softirq() && !irqs_disabled());
  205. if (system_supports_sve() && test_thread_flag(TIF_SVE))
  206. sve_load_state(sve_pffr(&current->thread),
  207. &current->thread.uw.fpsimd_state.fpsr,
  208. sve_vq_from_vl(current->thread.sve_vl) - 1);
  209. else
  210. fpsimd_load_state(&current->thread.uw.fpsimd_state);
  211. }
  212. /*
  213. * Ensure FPSIMD/SVE storage in memory for the loaded context is up to
  214. * date with respect to the CPU registers.
  215. *
  216. * Softirqs (and preemption) must be disabled.
  217. */
  218. void fpsimd_save(void)
  219. {
  220. struct user_fpsimd_state *st = __this_cpu_read(fpsimd_last_state.st);
  221. /* set by fpsimd_bind_task_to_cpu() or fpsimd_bind_state_to_cpu() */
  222. WARN_ON(!in_softirq() && !irqs_disabled());
  223. if (!test_thread_flag(TIF_FOREIGN_FPSTATE)) {
  224. if (system_supports_sve() && test_thread_flag(TIF_SVE)) {
  225. if (WARN_ON(sve_get_vl() != current->thread.sve_vl)) {
  226. /*
  227. * Can't save the user regs, so current would
  228. * re-enter user with corrupt state.
  229. * There's no way to recover, so kill it:
  230. */
  231. force_signal_inject(SIGKILL, SI_KERNEL, 0);
  232. return;
  233. }
  234. sve_save_state(sve_pffr(&current->thread), &st->fpsr);
  235. } else
  236. fpsimd_save_state(st);
  237. }
  238. }
  239. /*
  240. * Helpers to translate bit indices in sve_vq_map to VQ values (and
  241. * vice versa). This allows find_next_bit() to be used to find the
  242. * _maximum_ VQ not exceeding a certain value.
  243. */
  244. static unsigned int vq_to_bit(unsigned int vq)
  245. {
  246. return SVE_VQ_MAX - vq;
  247. }
  248. static unsigned int bit_to_vq(unsigned int bit)
  249. {
  250. if (WARN_ON(bit >= SVE_VQ_MAX))
  251. bit = SVE_VQ_MAX - 1;
  252. return SVE_VQ_MAX - bit;
  253. }
  254. /*
  255. * All vector length selection from userspace comes through here.
  256. * We're on a slow path, so some sanity-checks are included.
  257. * If things go wrong there's a bug somewhere, but try to fall back to a
  258. * safe choice.
  259. */
  260. static unsigned int find_supported_vector_length(unsigned int vl)
  261. {
  262. int bit;
  263. int max_vl = sve_max_vl;
  264. if (WARN_ON(!sve_vl_valid(vl)))
  265. vl = SVE_VL_MIN;
  266. if (WARN_ON(!sve_vl_valid(max_vl)))
  267. max_vl = SVE_VL_MIN;
  268. if (vl > max_vl)
  269. vl = max_vl;
  270. bit = find_next_bit(sve_vq_map, SVE_VQ_MAX,
  271. vq_to_bit(sve_vq_from_vl(vl)));
  272. return sve_vl_from_vq(bit_to_vq(bit));
  273. }
  274. #ifdef CONFIG_SYSCTL
  275. static int sve_proc_do_default_vl(struct ctl_table *table, int write,
  276. void __user *buffer, size_t *lenp,
  277. loff_t *ppos)
  278. {
  279. int ret;
  280. int vl = sve_default_vl;
  281. struct ctl_table tmp_table = {
  282. .data = &vl,
  283. .maxlen = sizeof(vl),
  284. };
  285. ret = proc_dointvec(&tmp_table, write, buffer, lenp, ppos);
  286. if (ret || !write)
  287. return ret;
  288. /* Writing -1 has the special meaning "set to max": */
  289. if (vl == -1)
  290. vl = sve_max_vl;
  291. if (!sve_vl_valid(vl))
  292. return -EINVAL;
  293. sve_default_vl = find_supported_vector_length(vl);
  294. return 0;
  295. }
  296. static struct ctl_table sve_default_vl_table[] = {
  297. {
  298. .procname = "sve_default_vector_length",
  299. .mode = 0644,
  300. .proc_handler = sve_proc_do_default_vl,
  301. },
  302. { }
  303. };
  304. static int __init sve_sysctl_init(void)
  305. {
  306. if (system_supports_sve())
  307. if (!register_sysctl("abi", sve_default_vl_table))
  308. return -EINVAL;
  309. return 0;
  310. }
  311. #else /* ! CONFIG_SYSCTL */
  312. static int __init sve_sysctl_init(void) { return 0; }
  313. #endif /* ! CONFIG_SYSCTL */
  314. #define ZREG(sve_state, vq, n) ((char *)(sve_state) + \
  315. (SVE_SIG_ZREG_OFFSET(vq, n) - SVE_SIG_REGS_OFFSET))
  316. /*
  317. * Transfer the FPSIMD state in task->thread.uw.fpsimd_state to
  318. * task->thread.sve_state.
  319. *
  320. * Task can be a non-runnable task, or current. In the latter case,
  321. * softirqs (and preemption) must be disabled.
  322. * task->thread.sve_state must point to at least sve_state_size(task)
  323. * bytes of allocated kernel memory.
  324. * task->thread.uw.fpsimd_state must be up to date before calling this
  325. * function.
  326. */
  327. static void fpsimd_to_sve(struct task_struct *task)
  328. {
  329. unsigned int vq;
  330. void *sst = task->thread.sve_state;
  331. struct user_fpsimd_state const *fst = &task->thread.uw.fpsimd_state;
  332. unsigned int i;
  333. if (!system_supports_sve())
  334. return;
  335. vq = sve_vq_from_vl(task->thread.sve_vl);
  336. for (i = 0; i < 32; ++i)
  337. memcpy(ZREG(sst, vq, i), &fst->vregs[i],
  338. sizeof(fst->vregs[i]));
  339. }
  340. /*
  341. * Transfer the SVE state in task->thread.sve_state to
  342. * task->thread.uw.fpsimd_state.
  343. *
  344. * Task can be a non-runnable task, or current. In the latter case,
  345. * softirqs (and preemption) must be disabled.
  346. * task->thread.sve_state must point to at least sve_state_size(task)
  347. * bytes of allocated kernel memory.
  348. * task->thread.sve_state must be up to date before calling this function.
  349. */
  350. static void sve_to_fpsimd(struct task_struct *task)
  351. {
  352. unsigned int vq;
  353. void const *sst = task->thread.sve_state;
  354. struct user_fpsimd_state *fst = &task->thread.uw.fpsimd_state;
  355. unsigned int i;
  356. if (!system_supports_sve())
  357. return;
  358. vq = sve_vq_from_vl(task->thread.sve_vl);
  359. for (i = 0; i < 32; ++i)
  360. memcpy(&fst->vregs[i], ZREG(sst, vq, i),
  361. sizeof(fst->vregs[i]));
  362. }
  363. #ifdef CONFIG_ARM64_SVE
  364. /*
  365. * Return how many bytes of memory are required to store the full SVE
  366. * state for task, given task's currently configured vector length.
  367. */
  368. size_t sve_state_size(struct task_struct const *task)
  369. {
  370. return SVE_SIG_REGS_SIZE(sve_vq_from_vl(task->thread.sve_vl));
  371. }
  372. /*
  373. * Ensure that task->thread.sve_state is allocated and sufficiently large.
  374. *
  375. * This function should be used only in preparation for replacing
  376. * task->thread.sve_state with new data. The memory is always zeroed
  377. * here to prevent stale data from showing through: this is done in
  378. * the interest of testability and predictability: except in the
  379. * do_sve_acc() case, there is no ABI requirement to hide stale data
  380. * written previously be task.
  381. */
  382. void sve_alloc(struct task_struct *task)
  383. {
  384. if (task->thread.sve_state) {
  385. memset(task->thread.sve_state, 0, sve_state_size(current));
  386. return;
  387. }
  388. /* This is a small allocation (maximum ~8KB) and Should Not Fail. */
  389. task->thread.sve_state =
  390. kzalloc(sve_state_size(task), GFP_KERNEL);
  391. /*
  392. * If future SVE revisions can have larger vectors though,
  393. * this may cease to be true:
  394. */
  395. BUG_ON(!task->thread.sve_state);
  396. }
  397. /*
  398. * Ensure that task->thread.sve_state is up to date with respect to
  399. * the user task, irrespective of when SVE is in use or not.
  400. *
  401. * This should only be called by ptrace. task must be non-runnable.
  402. * task->thread.sve_state must point to at least sve_state_size(task)
  403. * bytes of allocated kernel memory.
  404. */
  405. void fpsimd_sync_to_sve(struct task_struct *task)
  406. {
  407. if (!test_tsk_thread_flag(task, TIF_SVE))
  408. fpsimd_to_sve(task);
  409. }
  410. /*
  411. * Ensure that task->thread.uw.fpsimd_state is up to date with respect to
  412. * the user task, irrespective of whether SVE is in use or not.
  413. *
  414. * This should only be called by ptrace. task must be non-runnable.
  415. * task->thread.sve_state must point to at least sve_state_size(task)
  416. * bytes of allocated kernel memory.
  417. */
  418. void sve_sync_to_fpsimd(struct task_struct *task)
  419. {
  420. if (test_tsk_thread_flag(task, TIF_SVE))
  421. sve_to_fpsimd(task);
  422. }
  423. /*
  424. * Ensure that task->thread.sve_state is up to date with respect to
  425. * the task->thread.uw.fpsimd_state.
  426. *
  427. * This should only be called by ptrace to merge new FPSIMD register
  428. * values into a task for which SVE is currently active.
  429. * task must be non-runnable.
  430. * task->thread.sve_state must point to at least sve_state_size(task)
  431. * bytes of allocated kernel memory.
  432. * task->thread.uw.fpsimd_state must already have been initialised with
  433. * the new FPSIMD register values to be merged in.
  434. */
  435. void sve_sync_from_fpsimd_zeropad(struct task_struct *task)
  436. {
  437. unsigned int vq;
  438. void *sst = task->thread.sve_state;
  439. struct user_fpsimd_state const *fst = &task->thread.uw.fpsimd_state;
  440. unsigned int i;
  441. if (!test_tsk_thread_flag(task, TIF_SVE))
  442. return;
  443. vq = sve_vq_from_vl(task->thread.sve_vl);
  444. memset(sst, 0, SVE_SIG_REGS_SIZE(vq));
  445. for (i = 0; i < 32; ++i)
  446. memcpy(ZREG(sst, vq, i), &fst->vregs[i],
  447. sizeof(fst->vregs[i]));
  448. }
  449. int sve_set_vector_length(struct task_struct *task,
  450. unsigned long vl, unsigned long flags)
  451. {
  452. if (flags & ~(unsigned long)(PR_SVE_VL_INHERIT |
  453. PR_SVE_SET_VL_ONEXEC))
  454. return -EINVAL;
  455. if (!sve_vl_valid(vl))
  456. return -EINVAL;
  457. /*
  458. * Clamp to the maximum vector length that VL-agnostic SVE code can
  459. * work with. A flag may be assigned in the future to allow setting
  460. * of larger vector lengths without confusing older software.
  461. */
  462. if (vl > SVE_VL_ARCH_MAX)
  463. vl = SVE_VL_ARCH_MAX;
  464. vl = find_supported_vector_length(vl);
  465. if (flags & (PR_SVE_VL_INHERIT |
  466. PR_SVE_SET_VL_ONEXEC))
  467. task->thread.sve_vl_onexec = vl;
  468. else
  469. /* Reset VL to system default on next exec: */
  470. task->thread.sve_vl_onexec = 0;
  471. /* Only actually set the VL if not deferred: */
  472. if (flags & PR_SVE_SET_VL_ONEXEC)
  473. goto out;
  474. if (vl == task->thread.sve_vl)
  475. goto out;
  476. /*
  477. * To ensure the FPSIMD bits of the SVE vector registers are preserved,
  478. * write any live register state back to task_struct, and convert to a
  479. * non-SVE thread.
  480. */
  481. if (task == current) {
  482. local_bh_disable();
  483. fpsimd_save();
  484. set_thread_flag(TIF_FOREIGN_FPSTATE);
  485. }
  486. fpsimd_flush_task_state(task);
  487. if (test_and_clear_tsk_thread_flag(task, TIF_SVE))
  488. sve_to_fpsimd(task);
  489. if (task == current)
  490. local_bh_enable();
  491. /*
  492. * Force reallocation of task SVE state to the correct size
  493. * on next use:
  494. */
  495. sve_free(task);
  496. task->thread.sve_vl = vl;
  497. out:
  498. update_tsk_thread_flag(task, TIF_SVE_VL_INHERIT,
  499. flags & PR_SVE_VL_INHERIT);
  500. return 0;
  501. }
  502. /*
  503. * Encode the current vector length and flags for return.
  504. * This is only required for prctl(): ptrace has separate fields
  505. *
  506. * flags are as for sve_set_vector_length().
  507. */
  508. static int sve_prctl_status(unsigned long flags)
  509. {
  510. int ret;
  511. if (flags & PR_SVE_SET_VL_ONEXEC)
  512. ret = current->thread.sve_vl_onexec;
  513. else
  514. ret = current->thread.sve_vl;
  515. if (test_thread_flag(TIF_SVE_VL_INHERIT))
  516. ret |= PR_SVE_VL_INHERIT;
  517. return ret;
  518. }
  519. /* PR_SVE_SET_VL */
  520. int sve_set_current_vl(unsigned long arg)
  521. {
  522. unsigned long vl, flags;
  523. int ret;
  524. vl = arg & PR_SVE_VL_LEN_MASK;
  525. flags = arg & ~vl;
  526. if (!system_supports_sve())
  527. return -EINVAL;
  528. ret = sve_set_vector_length(current, vl, flags);
  529. if (ret)
  530. return ret;
  531. return sve_prctl_status(flags);
  532. }
  533. /* PR_SVE_GET_VL */
  534. int sve_get_current_vl(void)
  535. {
  536. if (!system_supports_sve())
  537. return -EINVAL;
  538. return sve_prctl_status(0);
  539. }
  540. /*
  541. * Bitmap for temporary storage of the per-CPU set of supported vector lengths
  542. * during secondary boot.
  543. */
  544. static DECLARE_BITMAP(sve_secondary_vq_map, SVE_VQ_MAX);
  545. static void sve_probe_vqs(DECLARE_BITMAP(map, SVE_VQ_MAX))
  546. {
  547. unsigned int vq, vl;
  548. unsigned long zcr;
  549. bitmap_zero(map, SVE_VQ_MAX);
  550. zcr = ZCR_ELx_LEN_MASK;
  551. zcr = read_sysreg_s(SYS_ZCR_EL1) & ~zcr;
  552. for (vq = SVE_VQ_MAX; vq >= SVE_VQ_MIN; --vq) {
  553. write_sysreg_s(zcr | (vq - 1), SYS_ZCR_EL1); /* self-syncing */
  554. vl = sve_get_vl();
  555. vq = sve_vq_from_vl(vl); /* skip intervening lengths */
  556. set_bit(vq_to_bit(vq), map);
  557. }
  558. }
  559. void __init sve_init_vq_map(void)
  560. {
  561. sve_probe_vqs(sve_vq_map);
  562. }
  563. /*
  564. * If we haven't committed to the set of supported VQs yet, filter out
  565. * those not supported by the current CPU.
  566. */
  567. void sve_update_vq_map(void)
  568. {
  569. sve_probe_vqs(sve_secondary_vq_map);
  570. bitmap_and(sve_vq_map, sve_vq_map, sve_secondary_vq_map, SVE_VQ_MAX);
  571. }
  572. /* Check whether the current CPU supports all VQs in the committed set */
  573. int sve_verify_vq_map(void)
  574. {
  575. int ret = 0;
  576. sve_probe_vqs(sve_secondary_vq_map);
  577. bitmap_andnot(sve_secondary_vq_map, sve_vq_map, sve_secondary_vq_map,
  578. SVE_VQ_MAX);
  579. if (!bitmap_empty(sve_secondary_vq_map, SVE_VQ_MAX)) {
  580. pr_warn("SVE: cpu%d: Required vector length(s) missing\n",
  581. smp_processor_id());
  582. ret = -EINVAL;
  583. }
  584. return ret;
  585. }
  586. static void __init sve_efi_setup(void)
  587. {
  588. if (!IS_ENABLED(CONFIG_EFI))
  589. return;
  590. /*
  591. * alloc_percpu() warns and prints a backtrace if this goes wrong.
  592. * This is evidence of a crippled system and we are returning void,
  593. * so no attempt is made to handle this situation here.
  594. */
  595. if (!sve_vl_valid(sve_max_vl))
  596. goto fail;
  597. efi_sve_state = __alloc_percpu(
  598. SVE_SIG_REGS_SIZE(sve_vq_from_vl(sve_max_vl)), SVE_VQ_BYTES);
  599. if (!efi_sve_state)
  600. goto fail;
  601. return;
  602. fail:
  603. panic("Cannot allocate percpu memory for EFI SVE save/restore");
  604. }
  605. /*
  606. * Enable SVE for EL1.
  607. * Intended for use by the cpufeatures code during CPU boot.
  608. */
  609. void sve_kernel_enable(const struct arm64_cpu_capabilities *__always_unused p)
  610. {
  611. write_sysreg(read_sysreg(CPACR_EL1) | CPACR_EL1_ZEN_EL1EN, CPACR_EL1);
  612. isb();
  613. }
  614. /*
  615. * Read the pseudo-ZCR used by cpufeatures to identify the supported SVE
  616. * vector length.
  617. *
  618. * Use only if SVE is present.
  619. * This function clobbers the SVE vector length.
  620. */
  621. u64 read_zcr_features(void)
  622. {
  623. u64 zcr;
  624. unsigned int vq_max;
  625. /*
  626. * Set the maximum possible VL, and write zeroes to all other
  627. * bits to see if they stick.
  628. */
  629. sve_kernel_enable(NULL);
  630. write_sysreg_s(ZCR_ELx_LEN_MASK, SYS_ZCR_EL1);
  631. zcr = read_sysreg_s(SYS_ZCR_EL1);
  632. zcr &= ~(u64)ZCR_ELx_LEN_MASK; /* find sticky 1s outside LEN field */
  633. vq_max = sve_vq_from_vl(sve_get_vl());
  634. zcr |= vq_max - 1; /* set LEN field to maximum effective value */
  635. return zcr;
  636. }
  637. void __init sve_setup(void)
  638. {
  639. u64 zcr;
  640. if (!system_supports_sve())
  641. return;
  642. /*
  643. * The SVE architecture mandates support for 128-bit vectors,
  644. * so sve_vq_map must have at least SVE_VQ_MIN set.
  645. * If something went wrong, at least try to patch it up:
  646. */
  647. if (WARN_ON(!test_bit(vq_to_bit(SVE_VQ_MIN), sve_vq_map)))
  648. set_bit(vq_to_bit(SVE_VQ_MIN), sve_vq_map);
  649. zcr = read_sanitised_ftr_reg(SYS_ZCR_EL1);
  650. sve_max_vl = sve_vl_from_vq((zcr & ZCR_ELx_LEN_MASK) + 1);
  651. /*
  652. * Sanity-check that the max VL we determined through CPU features
  653. * corresponds properly to sve_vq_map. If not, do our best:
  654. */
  655. if (WARN_ON(sve_max_vl != find_supported_vector_length(sve_max_vl)))
  656. sve_max_vl = find_supported_vector_length(sve_max_vl);
  657. /*
  658. * For the default VL, pick the maximum supported value <= 64.
  659. * VL == 64 is guaranteed not to grow the signal frame.
  660. */
  661. sve_default_vl = find_supported_vector_length(64);
  662. pr_info("SVE: maximum available vector length %u bytes per vector\n",
  663. sve_max_vl);
  664. pr_info("SVE: default vector length %u bytes per vector\n",
  665. sve_default_vl);
  666. sve_efi_setup();
  667. }
  668. /*
  669. * Called from the put_task_struct() path, which cannot get here
  670. * unless dead_task is really dead and not schedulable.
  671. */
  672. void fpsimd_release_task(struct task_struct *dead_task)
  673. {
  674. __sve_free(dead_task);
  675. }
  676. #endif /* CONFIG_ARM64_SVE */
  677. /*
  678. * Trapped SVE access
  679. *
  680. * Storage is allocated for the full SVE state, the current FPSIMD
  681. * register contents are migrated across, and TIF_SVE is set so that
  682. * the SVE access trap will be disabled the next time this task
  683. * reaches ret_to_user.
  684. *
  685. * TIF_SVE should be clear on entry: otherwise, task_fpsimd_load()
  686. * would have disabled the SVE access trap for userspace during
  687. * ret_to_user, making an SVE access trap impossible in that case.
  688. */
  689. asmlinkage void do_sve_acc(unsigned int esr, struct pt_regs *regs)
  690. {
  691. /* Even if we chose not to use SVE, the hardware could still trap: */
  692. if (unlikely(!system_supports_sve()) || WARN_ON(is_compat_task())) {
  693. force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc);
  694. return;
  695. }
  696. sve_alloc(current);
  697. local_bh_disable();
  698. fpsimd_save();
  699. fpsimd_to_sve(current);
  700. /* Force ret_to_user to reload the registers: */
  701. fpsimd_flush_task_state(current);
  702. set_thread_flag(TIF_FOREIGN_FPSTATE);
  703. if (test_and_set_thread_flag(TIF_SVE))
  704. WARN_ON(1); /* SVE access shouldn't have trapped */
  705. local_bh_enable();
  706. }
  707. /*
  708. * Trapped FP/ASIMD access.
  709. */
  710. asmlinkage void do_fpsimd_acc(unsigned int esr, struct pt_regs *regs)
  711. {
  712. /* TODO: implement lazy context saving/restoring */
  713. WARN_ON(1);
  714. }
  715. /*
  716. * Raise a SIGFPE for the current process.
  717. */
  718. asmlinkage void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs)
  719. {
  720. unsigned int si_code = FPE_FLTUNK;
  721. if (esr & ESR_ELx_FP_EXC_TFV) {
  722. if (esr & FPEXC_IOF)
  723. si_code = FPE_FLTINV;
  724. else if (esr & FPEXC_DZF)
  725. si_code = FPE_FLTDIV;
  726. else if (esr & FPEXC_OFF)
  727. si_code = FPE_FLTOVF;
  728. else if (esr & FPEXC_UFF)
  729. si_code = FPE_FLTUND;
  730. else if (esr & FPEXC_IXF)
  731. si_code = FPE_FLTRES;
  732. }
  733. send_sig_fault(SIGFPE, si_code,
  734. (void __user *)instruction_pointer(regs),
  735. current);
  736. }
  737. void fpsimd_thread_switch(struct task_struct *next)
  738. {
  739. bool wrong_task, wrong_cpu;
  740. if (!system_supports_fpsimd())
  741. return;
  742. /* Save unsaved fpsimd state, if any: */
  743. fpsimd_save();
  744. /*
  745. * Fix up TIF_FOREIGN_FPSTATE to correctly describe next's
  746. * state. For kernel threads, FPSIMD registers are never loaded
  747. * and wrong_task and wrong_cpu will always be true.
  748. */
  749. wrong_task = __this_cpu_read(fpsimd_last_state.st) !=
  750. &next->thread.uw.fpsimd_state;
  751. wrong_cpu = next->thread.fpsimd_cpu != smp_processor_id();
  752. update_tsk_thread_flag(next, TIF_FOREIGN_FPSTATE,
  753. wrong_task || wrong_cpu);
  754. }
  755. void fpsimd_flush_thread(void)
  756. {
  757. int vl, supported_vl;
  758. if (!system_supports_fpsimd())
  759. return;
  760. local_bh_disable();
  761. memset(&current->thread.uw.fpsimd_state, 0,
  762. sizeof(current->thread.uw.fpsimd_state));
  763. fpsimd_flush_task_state(current);
  764. if (system_supports_sve()) {
  765. clear_thread_flag(TIF_SVE);
  766. sve_free(current);
  767. /*
  768. * Reset the task vector length as required.
  769. * This is where we ensure that all user tasks have a valid
  770. * vector length configured: no kernel task can become a user
  771. * task without an exec and hence a call to this function.
  772. * By the time the first call to this function is made, all
  773. * early hardware probing is complete, so sve_default_vl
  774. * should be valid.
  775. * If a bug causes this to go wrong, we make some noise and
  776. * try to fudge thread.sve_vl to a safe value here.
  777. */
  778. vl = current->thread.sve_vl_onexec ?
  779. current->thread.sve_vl_onexec : sve_default_vl;
  780. if (WARN_ON(!sve_vl_valid(vl)))
  781. vl = SVE_VL_MIN;
  782. supported_vl = find_supported_vector_length(vl);
  783. if (WARN_ON(supported_vl != vl))
  784. vl = supported_vl;
  785. current->thread.sve_vl = vl;
  786. /*
  787. * If the task is not set to inherit, ensure that the vector
  788. * length will be reset by a subsequent exec:
  789. */
  790. if (!test_thread_flag(TIF_SVE_VL_INHERIT))
  791. current->thread.sve_vl_onexec = 0;
  792. }
  793. set_thread_flag(TIF_FOREIGN_FPSTATE);
  794. local_bh_enable();
  795. }
  796. /*
  797. * Save the userland FPSIMD state of 'current' to memory, but only if the state
  798. * currently held in the registers does in fact belong to 'current'
  799. */
  800. void fpsimd_preserve_current_state(void)
  801. {
  802. if (!system_supports_fpsimd())
  803. return;
  804. local_bh_disable();
  805. fpsimd_save();
  806. local_bh_enable();
  807. }
  808. /*
  809. * Like fpsimd_preserve_current_state(), but ensure that
  810. * current->thread.uw.fpsimd_state is updated so that it can be copied to
  811. * the signal frame.
  812. */
  813. void fpsimd_signal_preserve_current_state(void)
  814. {
  815. fpsimd_preserve_current_state();
  816. if (system_supports_sve() && test_thread_flag(TIF_SVE))
  817. sve_to_fpsimd(current);
  818. }
  819. /*
  820. * Associate current's FPSIMD context with this cpu
  821. * Preemption must be disabled when calling this function.
  822. */
  823. void fpsimd_bind_task_to_cpu(void)
  824. {
  825. struct fpsimd_last_state_struct *last =
  826. this_cpu_ptr(&fpsimd_last_state);
  827. last->st = &current->thread.uw.fpsimd_state;
  828. current->thread.fpsimd_cpu = smp_processor_id();
  829. if (system_supports_sve()) {
  830. /* Toggle SVE trapping for userspace if needed */
  831. if (test_thread_flag(TIF_SVE))
  832. sve_user_enable();
  833. else
  834. sve_user_disable();
  835. /* Serialised by exception return to user */
  836. }
  837. }
  838. void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *st)
  839. {
  840. struct fpsimd_last_state_struct *last =
  841. this_cpu_ptr(&fpsimd_last_state);
  842. WARN_ON(!in_softirq() && !irqs_disabled());
  843. last->st = st;
  844. }
  845. /*
  846. * Load the userland FPSIMD state of 'current' from memory, but only if the
  847. * FPSIMD state already held in the registers is /not/ the most recent FPSIMD
  848. * state of 'current'
  849. */
  850. void fpsimd_restore_current_state(void)
  851. {
  852. if (!system_supports_fpsimd())
  853. return;
  854. local_bh_disable();
  855. if (test_and_clear_thread_flag(TIF_FOREIGN_FPSTATE)) {
  856. task_fpsimd_load();
  857. fpsimd_bind_task_to_cpu();
  858. }
  859. local_bh_enable();
  860. }
  861. /*
  862. * Load an updated userland FPSIMD state for 'current' from memory and set the
  863. * flag that indicates that the FPSIMD register contents are the most recent
  864. * FPSIMD state of 'current'
  865. */
  866. void fpsimd_update_current_state(struct user_fpsimd_state const *state)
  867. {
  868. if (!system_supports_fpsimd())
  869. return;
  870. local_bh_disable();
  871. current->thread.uw.fpsimd_state = *state;
  872. if (system_supports_sve() && test_thread_flag(TIF_SVE))
  873. fpsimd_to_sve(current);
  874. task_fpsimd_load();
  875. fpsimd_bind_task_to_cpu();
  876. clear_thread_flag(TIF_FOREIGN_FPSTATE);
  877. local_bh_enable();
  878. }
  879. /*
  880. * Invalidate live CPU copies of task t's FPSIMD state
  881. */
  882. void fpsimd_flush_task_state(struct task_struct *t)
  883. {
  884. t->thread.fpsimd_cpu = NR_CPUS;
  885. }
  886. void fpsimd_flush_cpu_state(void)
  887. {
  888. __this_cpu_write(fpsimd_last_state.st, NULL);
  889. set_thread_flag(TIF_FOREIGN_FPSTATE);
  890. }
  891. #ifdef CONFIG_KERNEL_MODE_NEON
  892. DEFINE_PER_CPU(bool, kernel_neon_busy);
  893. EXPORT_PER_CPU_SYMBOL(kernel_neon_busy);
  894. /*
  895. * Kernel-side NEON support functions
  896. */
  897. /*
  898. * kernel_neon_begin(): obtain the CPU FPSIMD registers for use by the calling
  899. * context
  900. *
  901. * Must not be called unless may_use_simd() returns true.
  902. * Task context in the FPSIMD registers is saved back to memory as necessary.
  903. *
  904. * A matching call to kernel_neon_end() must be made before returning from the
  905. * calling context.
  906. *
  907. * The caller may freely use the FPSIMD registers until kernel_neon_end() is
  908. * called.
  909. */
  910. void kernel_neon_begin(void)
  911. {
  912. if (WARN_ON(!system_supports_fpsimd()))
  913. return;
  914. BUG_ON(!may_use_simd());
  915. local_bh_disable();
  916. __this_cpu_write(kernel_neon_busy, true);
  917. /* Save unsaved fpsimd state, if any: */
  918. fpsimd_save();
  919. /* Invalidate any task state remaining in the fpsimd regs: */
  920. fpsimd_flush_cpu_state();
  921. preempt_disable();
  922. local_bh_enable();
  923. }
  924. EXPORT_SYMBOL(kernel_neon_begin);
  925. /*
  926. * kernel_neon_end(): give the CPU FPSIMD registers back to the current task
  927. *
  928. * Must be called from a context in which kernel_neon_begin() was previously
  929. * called, with no call to kernel_neon_end() in the meantime.
  930. *
  931. * The caller must not use the FPSIMD registers after this function is called,
  932. * unless kernel_neon_begin() is called again in the meantime.
  933. */
  934. void kernel_neon_end(void)
  935. {
  936. bool busy;
  937. if (!system_supports_fpsimd())
  938. return;
  939. busy = __this_cpu_xchg(kernel_neon_busy, false);
  940. WARN_ON(!busy); /* No matching kernel_neon_begin()? */
  941. preempt_enable();
  942. }
  943. EXPORT_SYMBOL(kernel_neon_end);
  944. #ifdef CONFIG_EFI
  945. static DEFINE_PER_CPU(struct user_fpsimd_state, efi_fpsimd_state);
  946. static DEFINE_PER_CPU(bool, efi_fpsimd_state_used);
  947. static DEFINE_PER_CPU(bool, efi_sve_state_used);
  948. /*
  949. * EFI runtime services support functions
  950. *
  951. * The ABI for EFI runtime services allows EFI to use FPSIMD during the call.
  952. * This means that for EFI (and only for EFI), we have to assume that FPSIMD
  953. * is always used rather than being an optional accelerator.
  954. *
  955. * These functions provide the necessary support for ensuring FPSIMD
  956. * save/restore in the contexts from which EFI is used.
  957. *
  958. * Do not use them for any other purpose -- if tempted to do so, you are
  959. * either doing something wrong or you need to propose some refactoring.
  960. */
  961. /*
  962. * __efi_fpsimd_begin(): prepare FPSIMD for making an EFI runtime services call
  963. */
  964. void __efi_fpsimd_begin(void)
  965. {
  966. if (!system_supports_fpsimd())
  967. return;
  968. WARN_ON(preemptible());
  969. if (may_use_simd()) {
  970. kernel_neon_begin();
  971. } else {
  972. /*
  973. * If !efi_sve_state, SVE can't be in use yet and doesn't need
  974. * preserving:
  975. */
  976. if (system_supports_sve() && likely(efi_sve_state)) {
  977. char *sve_state = this_cpu_ptr(efi_sve_state);
  978. __this_cpu_write(efi_sve_state_used, true);
  979. sve_save_state(sve_state + sve_ffr_offset(sve_max_vl),
  980. &this_cpu_ptr(&efi_fpsimd_state)->fpsr);
  981. } else {
  982. fpsimd_save_state(this_cpu_ptr(&efi_fpsimd_state));
  983. }
  984. __this_cpu_write(efi_fpsimd_state_used, true);
  985. }
  986. }
  987. /*
  988. * __efi_fpsimd_end(): clean up FPSIMD after an EFI runtime services call
  989. */
  990. void __efi_fpsimd_end(void)
  991. {
  992. if (!system_supports_fpsimd())
  993. return;
  994. if (!__this_cpu_xchg(efi_fpsimd_state_used, false)) {
  995. kernel_neon_end();
  996. } else {
  997. if (system_supports_sve() &&
  998. likely(__this_cpu_read(efi_sve_state_used))) {
  999. char const *sve_state = this_cpu_ptr(efi_sve_state);
  1000. sve_load_state(sve_state + sve_ffr_offset(sve_max_vl),
  1001. &this_cpu_ptr(&efi_fpsimd_state)->fpsr,
  1002. sve_vq_from_vl(sve_get_vl()) - 1);
  1003. __this_cpu_write(efi_sve_state_used, false);
  1004. } else {
  1005. fpsimd_load_state(this_cpu_ptr(&efi_fpsimd_state));
  1006. }
  1007. }
  1008. }
  1009. #endif /* CONFIG_EFI */
  1010. #endif /* CONFIG_KERNEL_MODE_NEON */
  1011. #ifdef CONFIG_CPU_PM
  1012. static int fpsimd_cpu_pm_notifier(struct notifier_block *self,
  1013. unsigned long cmd, void *v)
  1014. {
  1015. switch (cmd) {
  1016. case CPU_PM_ENTER:
  1017. fpsimd_save();
  1018. fpsimd_flush_cpu_state();
  1019. break;
  1020. case CPU_PM_EXIT:
  1021. break;
  1022. case CPU_PM_ENTER_FAILED:
  1023. default:
  1024. return NOTIFY_DONE;
  1025. }
  1026. return NOTIFY_OK;
  1027. }
  1028. static struct notifier_block fpsimd_cpu_pm_notifier_block = {
  1029. .notifier_call = fpsimd_cpu_pm_notifier,
  1030. };
  1031. static void __init fpsimd_pm_init(void)
  1032. {
  1033. cpu_pm_register_notifier(&fpsimd_cpu_pm_notifier_block);
  1034. }
  1035. #else
  1036. static inline void fpsimd_pm_init(void) { }
  1037. #endif /* CONFIG_CPU_PM */
  1038. #ifdef CONFIG_HOTPLUG_CPU
  1039. static int fpsimd_cpu_dead(unsigned int cpu)
  1040. {
  1041. per_cpu(fpsimd_last_state.st, cpu) = NULL;
  1042. return 0;
  1043. }
  1044. static inline void fpsimd_hotplug_init(void)
  1045. {
  1046. cpuhp_setup_state_nocalls(CPUHP_ARM64_FPSIMD_DEAD, "arm64/fpsimd:dead",
  1047. NULL, fpsimd_cpu_dead);
  1048. }
  1049. #else
  1050. static inline void fpsimd_hotplug_init(void) { }
  1051. #endif
  1052. /*
  1053. * FP/SIMD support code initialisation.
  1054. */
  1055. static int __init fpsimd_init(void)
  1056. {
  1057. if (elf_hwcap & HWCAP_FP) {
  1058. fpsimd_pm_init();
  1059. fpsimd_hotplug_init();
  1060. } else {
  1061. pr_notice("Floating-point is not implemented\n");
  1062. }
  1063. if (!(elf_hwcap & HWCAP_ASIMD))
  1064. pr_notice("Advanced SIMD is not implemented\n");
  1065. return sve_sysctl_init();
  1066. }
  1067. core_initcall(fpsimd_init);