History

arm64/sme: Implement signal handling for ZT

Add a new signal context type for ZT which is present in the signal frame when ZA is enabled and ZT is supported by the system. In order to account for the possible addition of further ZT registers in the future we make the number of registers variable in the ABI, though currently the only possible number is 1. We could just use a bare list head for the context since the number of registers can be inferred from the size of the context but for usability and future extensibility we define a header with the number of registers and some reserved fields in it.

Mark Brown committed 3 years ago

Commit ee072cf1 parent 95fcec73 files · +124 −3Browse files

Unified · Split

3 files
  1. arch/arm64/include/asm/fpsimd.h +0 −3
  2. arch/arm64/include/uapi/asm/sigcontext.h +19 −0
  3. arch/arm64/kernel/signal.c +105 −0
arch/arm64/include/asm/fpsimd.h+0−3
@@ -361,9 +361,6 @@ extern unsigned int sme_get_vl(void); · 360 unmodified lines
361extern int sme_set_current_vl(unsigned long arg);361extern int sme_set_current_vl(unsigned long arg);
362extern int sme_get_current_vl(void);362extern int sme_get_current_vl(void);
363 363
364/* Will move with signal support */
365#define ZT_SIG_REG_SIZE 512
366
367/*364/*
368 * Return how many bytes of memory are required to store the full SME365 * Return how many bytes of memory are required to store the full SME
369 * specific state for task, given task's currently configured vector366 * specific state for task, given task's currently configured vector
arch/arm64/include/uapi/asm/sigcontext.h+19−0
@@ -152,6 +152,14 @@ struct za_context { · 151 unmodified lines
152 __u16 __reserved[3];152 __u16 __reserved[3];
153};153};
154 154
155#define ZT_MAGIC 0x5a544e01
156
157struct zt_context {
158 struct _aarch64_ctx head;
159 __u16 nregs;
160 __u16 __reserved[3];
161};
162
155#endif /* !__ASSEMBLY__ */163#endif /* !__ASSEMBLY__ */
156 164
157#include <asm/sve_context.h>165#include <asm/sve_context.h>
@@ -304,4 +312,15 @@ struct za_context { · 146 unmodified lines
304#define ZA_SIG_CONTEXT_SIZE(vq) \312#define ZA_SIG_CONTEXT_SIZE(vq) \
305 (ZA_SIG_REGS_OFFSET + ZA_SIG_REGS_SIZE(vq))313 (ZA_SIG_REGS_OFFSET + ZA_SIG_REGS_SIZE(vq))
306 314
315#define ZT_SIG_REG_SIZE 512
316
317#define ZT_SIG_REG_BYTES (ZT_SIG_REG_SIZE / 8)
318
319#define ZT_SIG_REGS_OFFSET sizeof(struct zt_context)
320
321#define ZT_SIG_REGS_SIZE(n) (ZT_SIG_REG_BYTES * n)
322
323#define ZT_SIG_CONTEXT_SIZE(n) \
324 (sizeof(struct zt_context) + ZT_SIG_REGS_SIZE(n))
325
307#endif /* _UAPI__ASM_SIGCONTEXT_H */326#endif /* _UAPI__ASM_SIGCONTEXT_H */
arch/arm64/kernel/signal.c+105−0
@@ -57,6 +57,7 @@ struct rt_sigframe_user_layout { · 56 unmodified lines
57 unsigned long esr_offset;57 unsigned long esr_offset;
58 unsigned long sve_offset;58 unsigned long sve_offset;
59 unsigned long za_offset;59 unsigned long za_offset;
60 unsigned long zt_offset;
60 unsigned long extra_offset;61 unsigned long extra_offset;
61 unsigned long end_offset;62 unsigned long end_offset;
62};63};
@@ -221,6 +222,7 @@ struct user_ctxs { · 158 unmodified lines
221 struct fpsimd_context __user *fpsimd;222 struct fpsimd_context __user *fpsimd;
222 struct sve_context __user *sve;223 struct sve_context __user *sve;
223 struct za_context __user *za;224 struct za_context __user *za;
225 struct zt_context __user *zt;
224};226};
225 227
226#ifdef CONFIG_ARM64_SVE228#ifdef CONFIG_ARM64_SVE
@@ -447,11 +449,81 @@ static int restore_za_context(struct user_ctxs *user) · 220 unmodified lines
447 449
448 return 0;450 return 0;
449}451}
452
453static int preserve_zt_context(struct zt_context __user *ctx)
454{
455 int err = 0;
456 u16 reserved[ARRAY_SIZE(ctx->__reserved)];
457
458 if (WARN_ON(!thread_za_enabled(&current->thread)))
459 return -EINVAL;
460
461 memset(reserved, 0, sizeof(reserved));
462
463 __put_user_error(ZT_MAGIC, &ctx->head.magic, err);
464 __put_user_error(round_up(ZT_SIG_CONTEXT_SIZE(1), 16),
465 &ctx->head.size, err);
466 __put_user_error(1, &ctx->nregs, err);
467 BUILD_BUG_ON(sizeof(ctx->__reserved) != sizeof(reserved));
468 err |= __copy_to_user(&ctx->__reserved, reserved, sizeof(reserved));
469
470 /*
471 * This assumes that the ZT state has already been saved to
472 * the task struct by calling the function
473 * fpsimd_signal_preserve_current_state().
474 */
475 err |= __copy_to_user((char __user *)ctx + ZT_SIG_REGS_OFFSET,
476 thread_zt_state(&current->thread),
477 ZT_SIG_REGS_SIZE(1));
478
479 return err ? -EFAULT : 0;
480}
481
482static int restore_zt_context(struct user_ctxs *user)
483{
484 int err;
485 struct zt_context zt;
486
487 /* ZA must be restored first for this check to be valid */
488 if (!thread_za_enabled(&current->thread))
489 return -EINVAL;
490
491 if (__copy_from_user(&zt, user->zt, sizeof(zt)))
492 return -EFAULT;
493
494 if (zt.nregs != 1)
495 return -EINVAL;
496
497 if (zt.head.size != ZT_SIG_CONTEXT_SIZE(zt.nregs))
498 return -EINVAL;
499
500 /*
501 * Careful: we are about __copy_from_user() directly into
502 * thread.zt_state with preemption enabled, so protection is
503 * needed to prevent a racing context switch from writing stale
504 * registers back over the new data.
505 */
506
507 fpsimd_flush_task_state(current);
508 /* From now, fpsimd_thread_switch() won't touch ZT in thread state */
509
510 err = __copy_from_user(thread_zt_state(&current->thread),
511 (char __user const *)user->zt +
512 ZT_SIG_REGS_OFFSET,
513 ZT_SIG_REGS_SIZE(1));
514 if (err)
515 return -EFAULT;
516
517 return 0;
518}
519
450#else /* ! CONFIG_ARM64_SME */520#else /* ! CONFIG_ARM64_SME */
451 521
452/* Turn any non-optimised out attempts to use these into a link error: */522/* Turn any non-optimised out attempts to use these into a link error: */
453extern int preserve_za_context(void __user *ctx);523extern int preserve_za_context(void __user *ctx);
454extern int restore_za_context(struct user_ctxs *user);524extern int restore_za_context(struct user_ctxs *user);
525extern int preserve_zt_context(void __user *ctx);
526extern int restore_zt_context(struct user_ctxs *user);
455 527
456#endif /* ! CONFIG_ARM64_SME */528#endif /* ! CONFIG_ARM64_SME */
457 529
@@ -469,6 +541,7 @@ static int parse_user_sigframe(struct user_ctxs *user, · 11 unmodified lines
469 user->fpsimd = NULL;541 user->fpsimd = NULL;
470 user->sve = NULL;542 user->sve = NULL;
471 user->za = NULL;543 user->za = NULL;
544 user->zt = NULL;
472 545
473 if (!IS_ALIGNED((unsigned long)base, 16))546 if (!IS_ALIGNED((unsigned long)base, 16))
474 goto invalid;547 goto invalid;
@@ -547,6 +620,19 @@ static int parse_user_sigframe(struct user_ctxs *user, · 72 unmodified lines
547 user->za = (struct za_context __user *)head;620 user->za = (struct za_context __user *)head;
548 break;621 break;
549 622
623 case ZT_MAGIC:
624 if (!system_supports_sme2())
625 goto invalid;
626
627 if (user->zt)
628 goto invalid;
629
630 if (size < sizeof(*user->zt))
631 goto invalid;
632
633 user->zt = (struct zt_context __user *)head;
634 break;
635
550 case EXTRA_MAGIC:636 case EXTRA_MAGIC:
551 if (have_extra_context)637 if (have_extra_context)
552 goto invalid;638 goto invalid;
@@ -669,6 +755,9 @@ static int restore_sigframe(struct pt_regs *regs, · 116 unmodified lines
669 if (err == 0 && system_supports_sme() && user.za)755 if (err == 0 && system_supports_sme() && user.za)
670 err = restore_za_context(&user);756 err = restore_za_context(&user);
671 757
758 if (err == 0 && system_supports_sme2() && user.zt)
759 err = restore_zt_context(&user);
760
672 return err;761 return err;
673}762}
674 763
@@ -769,6 +858,15 @@ static int setup_sigframe_layout(struct rt_sigframe_user_layout *user, · 94 unmodified lines
769 return err;858 return err;
770 }859 }
771 860
861 if (system_supports_sme2()) {
862 if (add_all || thread_za_enabled(&current->thread)) {
863 err = sigframe_alloc(user, &user->zt_offset,
864 ZT_SIG_CONTEXT_SIZE(1));
865 if (err)
866 return err;
867 }
868 }
869
772 return sigframe_alloc_end(user);870 return sigframe_alloc_end(user);
773}871}
774 872
@@ -824,6 +922,13 @@ static int setup_sigframe(struct rt_sigframe_user_layout *user, · 49 unmodified lines
824 err |= preserve_za_context(za_ctx);922 err |= preserve_za_context(za_ctx);
825 }923 }
826 924
925 /* ZT state if present */
926 if (system_supports_sme2() && err == 0 && user->zt_offset) {
927 struct zt_context __user *zt_ctx =
928 apply_user_offset(user, user->zt_offset);
929 err |= preserve_zt_context(zt_ctx);
930 }
931
827 if (err == 0 && user->extra_offset) {932 if (err == 0 && user->extra_offset) {
828 char __user *sfp = (char __user *)user->sigframe;933 char __user *sfp = (char __user *)user->sigframe;
829 char __user *userp =934 char __user *userp =

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t