[{"id":1764238,"web_url":"http://patchwork.ozlabs.org/comment/1764238/","msgid":"<5FA513F682BE7F4EAAB8EE035D5B08E44109DFE8@G01JPEXMBKW02>","list_archive_url":null,"date":"2017-09-06T16:21:50","subject":"RE: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","submitter":{"id":72310,"url":"http://patchwork.ozlabs.org/api/people/72310/","name":"Okamoto, Takayuki","email":"tokamoto@jp.fujitsu.com"},"content":"Hi Dave,\r\n\r\nI am an engineer of the postK computer from Fujitsu.\r\n\r\nWhen I tried to read \"max_vl\" by ptrace with this patch on our local SVE \r\nsimulator, it was read as zero.\r\nI think the cause of this incident is that \"max_vl\" is set as \"header->vl\" \r\nonly on warning case in sve_init_header_from_task().\r\n\"max_vl\" should be set up also on normal case, like the following patch.\r\n\r\n\r\n--- a/arch/arm64/kernel/ptrace.c\r\n+++ b/arch/arm64/kernel/ptrace.c\r\n@@ -755,6 +755,8 @@ static void sve_init_header_from_task(struct user_sve_header *header,\r\n\r\n        if (WARN_ON(!sve_vl_valid(sve_max_vl)))\r\n                header->max_vl = header->vl;\r\n+       else\r\n+               header->max_vl = sve_max_vl;\r\n\r\n        header->size = SVE_PT_SIZE(vq, header->flags);\r\n        header->max_size = SVE_PT_SIZE(sve_vq_from_vl(header->max_vl),\r\n\r\n\r\nBest regards,\r\nTakayuki Okamoto\r\n\r\n-----Original Message-----\r\nFrom: gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] On Behalf Of Dave Martin\r\nSent: Friday, September 1, 2017 2:01 AM\r\nTo: linux-arm-kernel@lists.infradead.org\r\nCc: Catalin Marinas <catalin.marinas@arm.com>; Will Deacon <will.deacon@arm.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>; Alex Bennée <alex.bennee@linaro.org>; Szabolcs Nagy <szabolcs.nagy@arm.com>; Richard Sandiford <richard.sandiford@arm.com>; kvmarm@lists.cs.columbia.edu; libc-alpha@sourceware.org; linux-arch@vger.kernel.org; gdb@sourceware.org; Alan Hayward <alan.hayward@arm.com>; Yao Qi <Yao.Qi@arm.com>; Oleg Nesterov <oleg@redhat.com>; Alexander Viro <viro@zeniv.linux.org.uk>\r\nSubject: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support\r\n\r\nThis patch defines and implements a new regset NT_ARM_SVE, which\r\ndescribes a thread's SVE register state.  This allows a debugger to\r\nmanipulate the SVE state, as well as being included in ELF\r\ncoredumps for post-mortem debugging.\r\n\r\nBecause the regset size and layout are dependent on the thread's\r\ncurrent vector length, it is not possible to define a C struct to\r\ndescribe the regset contents as is done for existing regsets.\r\nInstead, and for the same reasons, NT_ARM_SVE is based on the\r\nfreeform variable-layout approach used for the SVE signal frame.\r\n\r\nAdditionally, to reduce debug overhead when debugging threads that\r\nmight or might not have live SVE register state, NT_ARM_SVE may be\r\npresented in one of two different formats: the old struct\r\nuser_fpsimd_state format is embedded for describing the state of a\r\nthread with no live SVE state, whereas a new variable-layout\r\nstructure is embedded for describing live SVE state.  This avoids a\r\ndebugger needing to poll NT_PRFPREG in addition to NT_ARM_SVE, and\r\nallows existing userspace code to handle the non-SVE case without\r\ntoo much modification.\r\n\r\nFor this to work, NT_ARM_SVE is defined with a fixed-format header\r\nof type struct user_sve_header, which the recipient can use to\r\nfigure out the content, size and layout of the reset of the regset.\r\nAccessor macros are defined to allow the vector-length-dependent\r\nparts of the regset to be manipulated.\r\n\r\nSigned-off-by: Alan Hayward <alan.hayward@arm.com>\r\nSigned-off-by: Dave Martin <Dave.Martin@arm.com>\r\nCc: Alex Bennée <alex.bennee@linaro.org>\r\n\r\n---\r\n\r\nChanges since v1\r\n----------------\r\n\r\nOther changes related to Alex Bennée's comments:\r\n\r\n* Migrate to SVE_VQ_BYTES instead of magic numbers.\r\n\r\nRequested by Alex Bennée:\r\n\r\n* Thin out BUG_ON()s:\r\nRedundant BUG_ON()s and ones that just check invariants are removed.\r\nImportant sanity-checks are migrated to WARN_ON()s, with some\r\nminimal best-effort patch-up code.\r\n\r\nOther:\r\n\r\n* [ABI fix] Bail out with -EIO if attempting to set the\r\nSVE regs for an unsupported VL, instead of misparsing the regset data.\r\n\r\n* Replace some in-kernel open-coded arithmetic with ALIGN()/\r\nDIV_ROUND_UP().\r\n---\r\n arch/arm64/include/asm/fpsimd.h      |  13 +-\r\n arch/arm64/include/uapi/asm/ptrace.h | 135 ++++++++++++++++++\r\n arch/arm64/kernel/fpsimd.c           |  40 +++++-\r\n arch/arm64/kernel/ptrace.c           | 270 +++++++++++++++++++++++++++++++++--\r\n include/uapi/linux/elf.h             |   1 +\r\n 5 files changed, 449 insertions(+), 10 deletions(-)\r\n\r\ndiff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h\r\nindex 6c22624..2723cca 100644\r\n--- a/arch/arm64/include/asm/fpsimd.h\r\n+++ b/arch/arm64/include/asm/fpsimd.h\r\n@@ -38,13 +38,16 @@ struct fpsimd_state {\r\n \t\t\t__uint128_t vregs[32];\r\n \t\t\tu32 fpsr;\r\n \t\t\tu32 fpcr;\r\n+\t\t\t/*\r\n+\t\t\t * For ptrace compatibility, pad to next 128-bit\r\n+\t\t\t * boundary here if extending this struct.\r\n+\t\t\t */\r\n \t\t};\r\n \t};\r\n \t/* the id of the last cpu to have restored this state */\r\n \tunsigned int cpu;\r\n };\r\n \r\n-\r\n #if defined(__KERNEL__) && defined(CONFIG_COMPAT)\r\n /* Masks for extracting the FPSR and FPCR from the FPSCR */\r\n #define VFP_FPSCR_STAT_MASK\t0xf800009f\r\n@@ -89,6 +92,10 @@ extern void sve_alloc(struct task_struct *task);\r\n extern void fpsimd_release_thread(struct task_struct *task);\r\n extern void fpsimd_dup_sve(struct task_struct *dst,\r\n \t\t\t   struct task_struct const *src);\r\n+extern void fpsimd_sync_to_sve(struct task_struct *task);\r\n+extern void sve_sync_to_fpsimd(struct task_struct *task);\r\n+extern void sve_sync_from_fpsimd_zeropad(struct task_struct *task);\r\n+\r\n extern int sve_set_vector_length(struct task_struct *task,\r\n \t\t\t\t unsigned long vl, unsigned long flags);\r\n \r\n@@ -103,6 +110,10 @@ static void __maybe_unused sve_alloc(struct task_struct *task) { }\r\n static void __maybe_unused fpsimd_release_thread(struct task_struct *task) { }\r\n static void __maybe_unused fpsimd_dup_sve(struct task_struct *dst,\r\n \t\t\t\t\t  struct task_struct const *src) { }\r\n+static void __maybe_unused sve_sync_to_fpsimd(struct task_struct *task) { }\r\n+static void __maybe_unused sve_sync_from_fpsimd_zeropad(\r\n+\tstruct task_struct *task) { }\r\n+\r\n static void __maybe_unused sve_init_vq_map(void) { }\r\n static void __maybe_unused sve_update_vq_map(void) { }\r\n static int __maybe_unused sve_verify_vq_map(void) { return 0; }\r\ndiff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h\r\nindex d1ff83d..1915ab0 100644\r\n--- a/arch/arm64/include/uapi/asm/ptrace.h\r\n+++ b/arch/arm64/include/uapi/asm/ptrace.h\r\n@@ -22,6 +22,7 @@\r\n #include <linux/types.h>\r\n \r\n #include <asm/hwcap.h>\r\n+#include <asm/sigcontext.h>\r\n \r\n \r\n /*\r\n@@ -63,6 +64,8 @@\r\n \r\n #ifndef __ASSEMBLY__\r\n \r\n+#include <linux/prctl.h>\r\n+\r\n /*\r\n  * User structures for general purpose, floating point and debug registers.\r\n  */\r\n@@ -90,6 +93,138 @@ struct user_hwdebug_state {\r\n \t}\t\tdbg_regs[16];\r\n };\r\n \r\n+/* SVE/FP/SIMD state (NT_ARM_SVE) */\r\n+\r\n+struct user_sve_header {\r\n+\t__u32 size; /* total meaningful regset content in bytes */\r\n+\t__u32 max_size; /* maxmium possible size for this thread */\r\n+\t__u16 vl; /* current vector length */\r\n+\t__u16 max_vl; /* maximum possible vector length */\r\n+\t__u16 flags;\r\n+\t__u16 __reserved;\r\n+};\r\n+\r\n+/* Definitions for user_sve_header.flags: */\r\n+#define SVE_PT_REGS_MASK\t\t(1 << 0)\r\n+\r\n+/* Flags: must be kept in sync with prctl interface in <linux/ptrace.h> */\r\n+#define SVE_PT_REGS_FPSIMD\t\t0\r\n+#define SVE_PT_REGS_SVE\t\t\tSVE_PT_REGS_MASK\r\n+\r\n+#define SVE_PT_VL_INHERIT\t\t(PR_SVE_VL_INHERIT >> 16)\r\n+#define SVE_PT_VL_ONEXEC\t\t(PR_SVE_SET_VL_ONEXEC >> 16)\r\n+\r\n+\r\n+/*\r\n+ * The remainder of the SVE state follows struct user_sve_header.  The\r\n+ * total size of the SVE state (including header) depends on the\r\n+ * metadata in the header:  SVE_PT_SIZE(vq, flags) gives the total size\r\n+ * of the state in bytes, including the header.\r\n+ *\r\n+ * Refer to <asm/sigcontext.h> for details of how to pass the correct\r\n+ * \"vq\" argument to these macros.\r\n+ */\r\n+\r\n+/* Offset from the start of struct user_sve_header to the register data */\r\n+#define SVE_PT_REGS_OFFSET\t\t\t\t\t\\\r\n+\t((sizeof(struct sve_context) + (SVE_VQ_BYTES - 1))\t\\\r\n+\t\t/ SVE_VQ_BYTES * SVE_VQ_BYTES)\r\n+\r\n+/*\r\n+ * The register data content and layout depends on the value of the\r\n+ * flags field.\r\n+ */\r\n+\r\n+/*\r\n+ * (flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_FPSIMD case:\r\n+ *\r\n+ * The payload starts at offset SVE_PT_FPSIMD_OFFSET, and is of type\r\n+ * struct user_fpsimd_state.  Additional data might be appended in the\r\n+ * future: use SVE_PT_FPSIMD_SIZE(vq, flags) to compute the total size.\r\n+ * SVE_PT_FPSIMD_SIZE(vq, flags) will never be less than\r\n+ * sizeof(struct user_fpsimd_state).\r\n+ */\r\n+\r\n+#define SVE_PT_FPSIMD_OFFSET\t\tSVE_PT_REGS_OFFSET\r\n+\r\n+#define SVE_PT_FPSIMD_SIZE(vq, flags)\t(sizeof(struct user_fpsimd_state))\r\n+\r\n+/*\r\n+ * (flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_SVE case:\r\n+ *\r\n+ * The payload starts at offset SVE_PT_SVE_OFFSET, and is of size\r\n+ * SVE_PT_SVE_SIZE(vq, flags).\r\n+ *\r\n+ * Additional macros describe the contents and layout of the payload.\r\n+ * For each, SVE_PT_SVE_x_OFFSET(args) is the start offset relative to\r\n+ * the start of struct user_sve_header, and SVE_PT_SVE_x_SIZE(args) is\r\n+ * the size in bytes:\r\n+ *\r\n+ *\tx\ttype\t\t\t\tdescription\r\n+ *\t-\t----\t\t\t\t-----------\r\n+ *\tZREGS\t\t\\\r\n+ *\tZREG\t\t|\r\n+ *\tPREGS\t\t| refer to <asm/sigcontext.h>\r\n+ *\tPREG\t\t|\r\n+ *\tFFR\t\t/\r\n+ *\r\n+ *\tFPSR\tuint32_t\t\t\tFPSR\r\n+ *\tFPCR\tuint32_t\t\t\tFPCR\r\n+ *\r\n+ * Additional data might be appended in the future.\r\n+ */\r\n+\r\n+#define SVE_PT_SVE_ZREG_SIZE(vq)\tSVE_SIG_ZREG_SIZE(vq)\r\n+#define SVE_PT_SVE_PREG_SIZE(vq)\tSVE_SIG_PREG_SIZE(vq)\r\n+#define SVE_PT_SVE_FFR_SIZE(vq)\t\tSVE_SIG_FFR_SIZE(vq)\r\n+#define SVE_PT_SVE_FPSR_SIZE\t\tsizeof(__u32)\r\n+#define SVE_PT_SVE_FPCR_SIZE\t\tsizeof(__u32)\r\n+\r\n+#define __SVE_SIG_TO_PT(offset) \\\r\n+\t((offset) - SVE_SIG_REGS_OFFSET + SVE_PT_REGS_OFFSET)\r\n+\r\n+#define SVE_PT_SVE_OFFSET\t\tSVE_PT_REGS_OFFSET\r\n+\r\n+#define SVE_PT_SVE_ZREGS_OFFSET \\\r\n+\t__SVE_SIG_TO_PT(SVE_SIG_ZREGS_OFFSET)\r\n+#define SVE_PT_SVE_ZREG_OFFSET(vq, n) \\\r\n+\t__SVE_SIG_TO_PT(SVE_SIG_ZREG_OFFSET(vq, n))\r\n+#define SVE_PT_SVE_ZREGS_SIZE(vq) \\\r\n+\t(SVE_PT_SVE_ZREG_OFFSET(vq, SVE_NUM_ZREGS) - SVE_PT_SVE_ZREGS_OFFSET)\r\n+\r\n+#define SVE_PT_SVE_PREGS_OFFSET(vq) \\\r\n+\t__SVE_SIG_TO_PT(SVE_SIG_PREGS_OFFSET(vq))\r\n+#define SVE_PT_SVE_PREG_OFFSET(vq, n) \\\r\n+\t__SVE_SIG_TO_PT(SVE_SIG_PREG_OFFSET(vq, n))\r\n+#define SVE_PT_SVE_PREGS_SIZE(vq) \\\r\n+\t(SVE_PT_SVE_PREG_OFFSET(vq, SVE_NUM_PREGS) - \\\r\n+\t\tSVE_PT_SVE_PREGS_OFFSET(vq))\r\n+\r\n+#define SVE_PT_SVE_FFR_OFFSET(vq) \\\r\n+\t__SVE_SIG_TO_PT(SVE_SIG_FFR_OFFSET(vq))\r\n+\r\n+#define SVE_PT_SVE_FPSR_OFFSET(vq)\t\t\t\t\\\r\n+\t((SVE_PT_SVE_FFR_OFFSET(vq) + SVE_PT_SVE_FFR_SIZE(vq) +\t\\\r\n+\t\t\t(SVE_VQ_BYTES - 1))\t\t\t\\\r\n+\t\t/ SVE_VQ_BYTES * SVE_VQ_BYTES)\r\n+#define SVE_PT_SVE_FPCR_OFFSET(vq) \\\r\n+\t(SVE_PT_SVE_FPSR_OFFSET(vq) + SVE_PT_SVE_FPSR_SIZE)\r\n+\r\n+/*\r\n+ * Any future extension appended after FPCR must be aligned to the next\r\n+ * 128-bit boundary.\r\n+ */\r\n+\r\n+#define SVE_PT_SVE_SIZE(vq, flags)\t\t\t\t\t\\\r\n+\t((SVE_PT_SVE_FPCR_OFFSET(vq) + SVE_PT_SVE_FPCR_SIZE\t\t\\\r\n+\t\t\t- SVE_PT_SVE_OFFSET + (SVE_VQ_BYTES - 1))\t\\\r\n+\t\t/ SVE_VQ_BYTES * SVE_VQ_BYTES)\r\n+\r\n+#define SVE_PT_SIZE(vq, flags)\t\t\t\t\t\t\\\r\n+\t (((flags) & SVE_PT_REGS_MASK) == SVE_PT_REGS_SVE ?\t\t\\\r\n+\t\t  SVE_PT_SVE_OFFSET + SVE_PT_SVE_SIZE(vq, flags)\t\\\r\n+\t\t: SVE_PT_FPSIMD_OFFSET + SVE_PT_FPSIMD_SIZE(vq, flags))\r\n+\r\n #endif /* __ASSEMBLY__ */\r\n \r\n #endif /* _UAPI__ASM_PTRACE_H */\r\ndiff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c\r\nindex fff9fcf..361c019 100644\r\n--- a/arch/arm64/kernel/fpsimd.c\r\n+++ b/arch/arm64/kernel/fpsimd.c\r\n@@ -303,6 +303,37 @@ void sve_alloc(struct task_struct *task)\r\n \tBUG_ON(!task->thread.sve_state);\r\n }\r\n \r\n+void fpsimd_sync_to_sve(struct task_struct *task)\r\n+{\r\n+\tif (!test_tsk_thread_flag(task, TIF_SVE))\r\n+\t\tfpsimd_to_sve(task);\r\n+}\r\n+\r\n+void sve_sync_to_fpsimd(struct task_struct *task)\r\n+{\r\n+\tif (test_tsk_thread_flag(task, TIF_SVE))\r\n+\t\tsve_to_fpsimd(task);\r\n+}\r\n+\r\n+void sve_sync_from_fpsimd_zeropad(struct task_struct *task)\r\n+{\r\n+\tunsigned int vq;\r\n+\tvoid *sst = task->thread.sve_state;\r\n+\tstruct fpsimd_state const *fst = &task->thread.fpsimd_state;\r\n+\tunsigned int i;\r\n+\r\n+\tif (!test_tsk_thread_flag(task, TIF_SVE))\r\n+\t\treturn;\r\n+\r\n+\tvq = sve_vq_from_vl(task->thread.sve_vl);\r\n+\r\n+\tmemset(sst, 0, SVE_SIG_REGS_SIZE(vq));\r\n+\r\n+\tfor (i = 0; i < 32; ++i)\r\n+\t\tmemcpy(ZREG(sst, vq, i), &fst->vregs[i],\r\n+\t\t       sizeof(fst->vregs[i]));\r\n+}\r\n+\r\n /*\r\n  * Handle SVE state across fork():\r\n  *\r\n@@ -459,10 +490,17 @@ static void __init sve_efi_setup(void)\r\n \t * This is evidence of a crippled system and we are returning void,\r\n \t * so no attempt is made to handle this situation here.\r\n \t */\r\n-\tBUG_ON(!sve_vl_valid(sve_max_vl));\r\n+\tif (!sve_vl_valid(sve_max_vl))\r\n+\t\tgoto fail;\r\n+\r\n \tefi_sve_state = __alloc_percpu(\r\n \t\tSVE_SIG_REGS_SIZE(sve_vq_from_vl(sve_max_vl)), SVE_VQ_BYTES);\r\n \tif (!efi_sve_state)\r\n+\t\tgoto fail;\r\n+\r\n+\treturn;\r\n+\r\n+fail:\r\n \t\tpanic(\"Cannot allocate percpu memory for EFI SVE save/restore\");\r\n }\r\n \r\ndiff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c\r\nindex 9cbb612..5ef4735b 100644\r\n--- a/arch/arm64/kernel/ptrace.c\r\n+++ b/arch/arm64/kernel/ptrace.c\r\n@@ -32,6 +32,7 @@\r\n #include <linux/security.h>\r\n #include <linux/init.h>\r\n #include <linux/signal.h>\r\n+#include <linux/string.h>\r\n #include <linux/uaccess.h>\r\n #include <linux/perf_event.h>\r\n #include <linux/hw_breakpoint.h>\r\n@@ -40,6 +41,7 @@\r\n #include <linux/elf.h>\r\n \r\n #include <asm/compat.h>\r\n+#include <asm/cpufeature.h>\r\n #include <asm/debug-monitors.h>\r\n #include <asm/pgtable.h>\r\n #include <asm/stacktrace.h>\r\n@@ -618,33 +620,66 @@ static int gpr_set(struct task_struct *target, const struct user_regset *regset,\r\n /*\r\n  * TODO: update fp accessors for lazy context switching (sync/flush hwstate)\r\n  */\r\n-static int fpr_get(struct task_struct *target, const struct user_regset *regset,\r\n-\t\t   unsigned int pos, unsigned int count,\r\n-\t\t   void *kbuf, void __user *ubuf)\r\n+static int __fpr_get(struct task_struct *target,\r\n+\t\t     const struct user_regset *regset,\r\n+\t\t     unsigned int pos, unsigned int count,\r\n+\t\t     void *kbuf, void __user *ubuf, unsigned int start_pos)\r\n {\r\n \tstruct user_fpsimd_state *uregs;\r\n+\r\n+\tsve_sync_to_fpsimd(target);\r\n+\r\n \turegs = &target->thread.fpsimd_state.user_fpsimd;\r\n \r\n+\treturn user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs,\r\n+\t\t\t\t   start_pos, start_pos + sizeof(*uregs));\r\n+}\r\n+\r\n+static int fpr_get(struct task_struct *target, const struct user_regset *regset,\r\n+\t\t   unsigned int pos, unsigned int count,\r\n+\t\t   void *kbuf, void __user *ubuf)\r\n+{\r\n \tif (target == current)\r\n \t\tfpsimd_preserve_current_state();\r\n \r\n-\treturn user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0, -1);\r\n+\treturn __fpr_get(target, regset, pos, count, kbuf, ubuf, 0);\r\n }\r\n \r\n-static int fpr_set(struct task_struct *target, const struct user_regset *regset,\r\n-\t\t   unsigned int pos, unsigned int count,\r\n-\t\t   const void *kbuf, const void __user *ubuf)\r\n+static int __fpr_set(struct task_struct *target,\r\n+\t\t     const struct user_regset *regset,\r\n+\t\t     unsigned int pos, unsigned int count,\r\n+\t\t     const void *kbuf, const void __user *ubuf,\r\n+\t\t     unsigned int start_pos)\r\n {\r\n \tint ret;\r\n \tstruct user_fpsimd_state newstate =\r\n \t\ttarget->thread.fpsimd_state.user_fpsimd;\r\n \r\n-\tret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newstate, 0, -1);\r\n+\tsve_sync_to_fpsimd(target);\r\n+\r\n+\tret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newstate,\r\n+\t\t\t\t start_pos, start_pos + sizeof(newstate));\r\n \tif (ret)\r\n \t\treturn ret;\r\n \r\n \ttarget->thread.fpsimd_state.user_fpsimd = newstate;\r\n+\r\n+\treturn ret;\r\n+}\r\n+\r\n+static int fpr_set(struct task_struct *target, const struct user_regset *regset,\r\n+\t\t   unsigned int pos, unsigned int count,\r\n+\t\t   const void *kbuf, const void __user *ubuf)\r\n+{\r\n+\tint ret;\r\n+\r\n+\tret = __fpr_set(target, regset, pos, count, kbuf, ubuf, 0);\r\n+\tif (ret)\r\n+\t\treturn ret;\r\n+\r\n+\tsve_sync_from_fpsimd_zeropad(target);\r\n \tfpsimd_flush_task_state(target);\r\n+\r\n \treturn ret;\r\n }\r\n \r\n@@ -702,6 +737,210 @@ static int system_call_set(struct task_struct *target,\r\n \treturn ret;\r\n }\r\n \r\n+#ifdef CONFIG_ARM64_SVE\r\n+\r\n+static void sve_init_header_from_task(struct user_sve_header *header,\r\n+\t\t\t\t      struct task_struct *target)\r\n+{\r\n+\tunsigned int vq;\r\n+\r\n+\tmemset(header, 0, sizeof(*header));\r\n+\r\n+\theader->flags = test_tsk_thread_flag(target, TIF_SVE) ?\r\n+\t\tSVE_PT_REGS_SVE : SVE_PT_REGS_FPSIMD;\r\n+\tif (test_tsk_thread_flag(target, TIF_SVE_VL_INHERIT))\r\n+\t\theader->flags |= SVE_PT_VL_INHERIT;\r\n+\r\n+\theader->vl = target->thread.sve_vl;\r\n+\tvq = sve_vq_from_vl(header->vl);\r\n+\r\n+\tif (WARN_ON(!sve_vl_valid(sve_max_vl)))\r\n+\t\theader->max_vl = header->vl;\r\n+\r\n+\theader->size = SVE_PT_SIZE(vq, header->flags);\r\n+\theader->max_size = SVE_PT_SIZE(sve_vq_from_vl(header->max_vl),\r\n+\t\t\t\t      SVE_PT_REGS_SVE);\r\n+}\r\n+\r\n+static unsigned int sve_size_from_header(struct user_sve_header const *header)\r\n+{\r\n+\treturn ALIGN(header->size, SVE_VQ_BYTES);\r\n+}\r\n+\r\n+static unsigned int sve_get_size(struct task_struct *target,\r\n+\t\t\t\t const struct user_regset *regset)\r\n+{\r\n+\tstruct user_sve_header header;\r\n+\r\n+\tif (!system_supports_sve())\r\n+\t\treturn 0;\r\n+\r\n+\tsve_init_header_from_task(&header, target);\r\n+\treturn sve_size_from_header(&header);\r\n+}\r\n+\r\n+static int sve_get(struct task_struct *target,\r\n+\t\t   const struct user_regset *regset,\r\n+\t\t   unsigned int pos, unsigned int count,\r\n+\t\t   void *kbuf, void __user *ubuf)\r\n+{\r\n+\tint ret;\r\n+\tstruct user_sve_header header;\r\n+\tunsigned int vq;\r\n+\tunsigned long start, end;\r\n+\r\n+\tif (!system_supports_sve())\r\n+\t\treturn -EINVAL;\r\n+\r\n+\t/* Header */\r\n+\tsve_init_header_from_task(&header, target);\r\n+\tvq = sve_vq_from_vl(header.vl);\r\n+\r\n+\tret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &header,\r\n+\t\t\t\t  0, sizeof(header));\r\n+\tif (ret)\r\n+\t\treturn ret;\r\n+\r\n+\tif (target == current)\r\n+\t\tfpsimd_preserve_current_state();\r\n+\r\n+\t/* Registers: FPSIMD-only case */\r\n+\r\n+\tBUILD_BUG_ON(SVE_PT_FPSIMD_OFFSET != sizeof(header));\r\n+\tif ((header.flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_FPSIMD)\r\n+\t\treturn __fpr_get(target, regset, pos, count, kbuf, ubuf,\r\n+\t\t\t\t SVE_PT_FPSIMD_OFFSET);\r\n+\r\n+\t/* Otherwise: full SVE case */\r\n+\r\n+\tBUILD_BUG_ON(SVE_PT_SVE_OFFSET != sizeof(header));\r\n+\tstart = SVE_PT_SVE_OFFSET;\r\n+\tend = SVE_PT_SVE_FFR_OFFSET(vq) + SVE_PT_SVE_FFR_SIZE(vq);\r\n+\tret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,\r\n+\t\t\t\t  target->thread.sve_state,\r\n+\t\t\t\t  start, end);\r\n+\tif (ret)\r\n+\t\treturn ret;\r\n+\r\n+\tstart = end;\r\n+\tend = SVE_PT_SVE_FPSR_OFFSET(vq);\r\n+\tret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,\r\n+\t\t\t\t       start, end);\r\n+\tif (ret)\r\n+\t\treturn ret;\r\n+\r\n+\t/*\r\n+\t * Copy fpsr, and fpcr which must follow contiguously in\r\n+\t * struct fpsimd_state:\r\n+\t */\r\n+\tstart = end;\r\n+\tend = SVE_PT_SVE_FPCR_OFFSET(vq) + SVE_PT_SVE_FPCR_SIZE;\r\n+\tret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,\r\n+\t\t\t\t  &target->thread.fpsimd_state.fpsr,\r\n+\t\t\t\t  start, end);\r\n+\tif (ret)\r\n+\t\treturn ret;\r\n+\r\n+\tstart = end;\r\n+\tend = sve_size_from_header(&header);\r\n+\treturn user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,\r\n+\t\t\t\t\tstart, end);\r\n+}\r\n+\r\n+static int sve_set(struct task_struct *target,\r\n+\t\t   const struct user_regset *regset,\r\n+\t\t   unsigned int pos, unsigned int count,\r\n+\t\t   const void *kbuf, const void __user *ubuf)\r\n+{\r\n+\tint ret;\r\n+\tstruct user_sve_header header;\r\n+\tunsigned int vq;\r\n+\tunsigned long start, end;\r\n+\r\n+\tif (!system_supports_sve())\r\n+\t\treturn -EINVAL;\r\n+\r\n+\t/* Header */\r\n+\tif (count < sizeof(header))\r\n+\t\treturn -EINVAL;\r\n+\tret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &header,\r\n+\t\t\t\t 0, sizeof(header));\r\n+\tif (ret)\r\n+\t\tgoto out;\r\n+\r\n+\t/*\r\n+\t * Apart from PT_SVE_REGS_MASK, all PT_SVE_* flags are consumed by\r\n+\t * sve_set_vector_length(), which will also validate them for us:\r\n+\t */\r\n+\tret = sve_set_vector_length(target, header.vl,\r\n+\t\t\t\t    header.flags & ~SVE_PT_REGS_MASK);\r\n+\tif (ret)\r\n+\t\tgoto out;\r\n+\r\n+\t/* Actual VL set may be less than the user asked for: */\r\n+\tvq = sve_vq_from_vl(target->thread.sve_vl);\r\n+\r\n+\t/* Registers: FPSIMD-only case */\r\n+\r\n+\tBUILD_BUG_ON(SVE_PT_FPSIMD_OFFSET != sizeof(header));\r\n+\tif ((header.flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_FPSIMD) {\r\n+\t\tsve_sync_to_fpsimd(target);\r\n+\r\n+\t\tret = __fpr_set(target, regset, pos, count, kbuf, ubuf,\r\n+\t\t\t\tSVE_PT_FPSIMD_OFFSET);\r\n+\t\tclear_tsk_thread_flag(target, TIF_SVE);\r\n+\t\tgoto out;\r\n+\t}\r\n+\r\n+\t/* Otherwise: full SVE case */\r\n+\r\n+\t/*\r\n+\t * If setting a different VL from the requested VL and there is\r\n+\t * register data, the data layout will be wrong: don't even\r\n+\t * try to set the registers in this case.\r\n+\t */\r\n+\tif (count && vq != sve_vq_from_vl(header.vl)) {\r\n+\t\tret = -EIO;\r\n+\t\tgoto out;\r\n+\t}\r\n+\r\n+\tsve_alloc(target);\r\n+\tfpsimd_sync_to_sve(target);\r\n+\tset_tsk_thread_flag(target, TIF_SVE);\r\n+\r\n+\tBUILD_BUG_ON(SVE_PT_SVE_OFFSET != sizeof(header));\r\n+\tstart = SVE_PT_SVE_OFFSET;\r\n+\tend = SVE_PT_SVE_FFR_OFFSET(vq) + SVE_PT_SVE_FFR_SIZE(vq);\r\n+\tret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,\r\n+\t\t\t\t target->thread.sve_state,\r\n+\t\t\t\t start, end);\r\n+\tif (ret)\r\n+\t\tgoto out;\r\n+\r\n+\tstart = end;\r\n+\tend = SVE_PT_SVE_FPSR_OFFSET(vq);\r\n+\tret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,\r\n+\t\t\t\t\tstart, end);\r\n+\tif (ret)\r\n+\t\tgoto out;\r\n+\r\n+\t/*\r\n+\t * Copy fpsr, and fpcr which must follow contiguously in\r\n+\t * struct fpsimd_state:\r\n+\t */\r\n+\tstart = end;\r\n+\tend = SVE_PT_SVE_FPCR_OFFSET(vq) + SVE_PT_SVE_FPCR_SIZE;\r\n+\tret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,\r\n+\t\t\t\t &target->thread.fpsimd_state.fpsr,\r\n+\t\t\t\t start, end);\r\n+\r\n+out:\r\n+\tfpsimd_flush_task_state(target);\r\n+\treturn ret;\r\n+}\r\n+\r\n+#endif /* CONFIG_ARM64_SVE */\r\n+\r\n enum aarch64_regset {\r\n \tREGSET_GPR,\r\n \tREGSET_FPR,\r\n@@ -711,6 +950,9 @@ enum aarch64_regset {\r\n \tREGSET_HW_WATCH,\r\n #endif\r\n \tREGSET_SYSTEM_CALL,\r\n+#ifdef CONFIG_ARM64_SVE\r\n+\tREGSET_SVE,\r\n+#endif\r\n };\r\n \r\n static const struct user_regset aarch64_regsets[] = {\r\n@@ -768,6 +1010,18 @@ static const struct user_regset aarch64_regsets[] = {\r\n \t\t.get = system_call_get,\r\n \t\t.set = system_call_set,\r\n \t},\r\n+#ifdef CONFIG_ARM64_SVE\r\n+\t[REGSET_SVE] = { /* Scalable Vector Extension */\r\n+\t\t.core_note_type = NT_ARM_SVE,\r\n+\t\t.n = DIV_ROUND_UP(SVE_PT_SIZE(SVE_VQ_MAX, SVE_PT_REGS_SVE),\r\n+\t\t\t\t  SVE_VQ_BYTES),\r\n+\t\t.size = SVE_VQ_BYTES,\r\n+\t\t.align = SVE_VQ_BYTES,\r\n+\t\t.get = sve_get,\r\n+\t\t.set = sve_set,\r\n+\t\t.get_size = sve_get_size,\r\n+\t},\r\n+#endif\r\n };\r\n \r\n static const struct user_regset_view user_aarch64_view = {\r\ndiff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h\r\nindex b5280db..735b8f4 100644\r\n--- a/include/uapi/linux/elf.h\r\n+++ b/include/uapi/linux/elf.h\r\n@@ -416,6 +416,7 @@ typedef struct elf64_shdr {\r\n #define NT_ARM_HW_BREAK\t0x402\t\t/* ARM hardware breakpoint registers */\r\n #define NT_ARM_HW_WATCH\t0x403\t\t/* ARM hardware watchpoint registers */\r\n #define NT_ARM_SYSTEM_CALL\t0x404\t/* ARM system call number */\r\n+#define NT_ARM_SVE\t0x405\t\t/* ARM Scalable Vector Extension registers */\r\n #define NT_METAG_CBUF\t0x500\t\t/* Metag catch buffer registers */\r\n #define NT_METAG_RPIPE\t0x501\t\t/* Metag read pipeline state */\r\n #define NT_METAG_TLS\t0x502\t\t/* Metag TLS pointer */\r\n-- \r\n2.1.4","headers":{"Return-Path":"<libc-alpha-return-84270-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-84270-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"VshhfN/l\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnTPj0qJQz9s7F\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  7 Sep 2017 02:22:16 +1000 (AEST)","(qmail 87474 invoked by alias); 6 Sep 2017 16:22:07 -0000","(qmail 87384 invoked by uid 89); 6 Sep 2017 16:22:07 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:references\n\t:in-reply-to:content-type:content-transfer-encoding\n\t:mime-version; q=dns; s=default; b=B0tBWvMcLCSdCh6Xi7JHIxZVr6DL4\n\t7kJ79RFXzww/+e5QoSuiTrnmeYIBWlVp7yJeKpfamJVeMZJqF/fHm+2mw0uFnkZq\n\tyA8t6Dqb6scRGArUWeMsKZE9J6r9+rjKVl+KCkeTMU8O7uLlBMFuaT82eDptgKdC\n\tt+I5y21dy1swNs=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:references\n\t:in-reply-to:content-type:content-transfer-encoding\n\t:mime-version; s=default; bh=VT6QZZO80R9YNdqMk7cP3nAaOZc=; b=Vsh\n\thfN/lKWqi3W1GigaLnqVlQW0JO6tAC5hcdg9712ZD41r5iRtTgoX+/FSWeOTpNmW\n\tozTJRoN5uLhDQWOd6UdcJoBoKqU1nruTQTmxqeNTuIEvGbnrmYq9HnCCtfOVv+w1\n\tFrDOBjkIoI9aWnOA7yIFdtfPWp/toEGEQpE9/8Rk=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, MIME_BASE64_BLANKS,\n\tRP_MATCHES_RCVD,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=ard, fujitsu,\n\tH*r:0900, 62066","X-Spam-User":"qpsmtpd, 2 recipients","X-HELO":"mgwym02.jp.fujitsu.com","From":"\"Okamoto, Takayuki\" <tokamoto@jp.fujitsu.com>","To":"'Dave Martin' <Dave.Martin@arm.com>,\n\t\"linux-arm-kernel@lists.infradead.org\"\n\t<linux-arm-kernel@lists.infradead.org>","CC":"Catalin Marinas <catalin.marinas@arm.com>, Will Deacon\n\t<will.deacon@arm.com>, Ard Biesheuvel <ard.biesheuvel@linaro.org>, \n\t=?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?=\n\t<alex.bennee@linaro.org>, Szabolcs Nagy <szabolcs.nagy@arm.com>,\n\tRichard Sandiford <richard.sandiford@arm.com>, \n\t\"kvmarm@lists.cs.columbia.edu\" <kvmarm@lists.cs.columbia.edu>, \n\t\"libc-alpha@sourceware.org\" <libc-alpha@sourceware.org>, \n\t\"linux-arch@vger.kernel.org\" <linux-arch@vger.kernel.org>, \n\t\"gdb@sourceware.org\" <gdb@sourceware.org>, Alan Hayward\n\t<alan.hayward@arm.com>, Yao Qi <Yao.Qi@arm.com>, Oleg Nesterov\n\t<oleg@redhat.com>, Alexander Viro <viro@zeniv.linux.org.uk>","Subject":"RE: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","Date":"Wed, 6 Sep 2017 16:21:50 +0000","Message-ID":"<5FA513F682BE7F4EAAB8EE035D5B08E44109DFE8@G01JPEXMBKW02>","References":"<1504198860-12951-1-git-send-email-Dave.Martin@arm.com>\n\t<1504198860-12951-20-git-send-email-Dave.Martin@arm.com>","In-Reply-To":"<1504198860-12951-20-git-send-email-Dave.Martin@arm.com>","x-securitypolicycheck":"OK by SHieldMailChecker v2.4.6","x-shieldmailcheckerpolicyversion":"FJ-ISEC-20160315","x-shieldmailcheckermailid":"4d1366ccb9ed4978b85333ddc83656de","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","MIME-Version":"1.0","X-SecurityPolicyCheck-GC":"OK by FENCE-Mail","X-TM-AS-MML":"disable"}},{"id":1764301,"web_url":"http://patchwork.ozlabs.org/comment/1764301/","msgid":"<20170906181634.GF6321@e103592.cambridge.arm.com>","list_archive_url":null,"date":"2017-09-06T18:16:35","subject":"Re: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","submitter":{"id":26612,"url":"http://patchwork.ozlabs.org/api/people/26612/","name":"Dave Martin","email":"Dave.Martin@arm.com"},"content":"On Wed, Sep 06, 2017 at 04:21:50PM +0000, Okamoto, Takayuki wrote:\n> Hi Dave,\n> \n> I am an engineer of the postK computer from Fujitsu.\n> \n> When I tried to read \"max_vl\" by ptrace with this patch on our local SVE \n> simulator, it was read as zero.\n> I think the cause of this incident is that \"max_vl\" is set as \"header->vl\" \n> only on warning case in sve_init_header_from_task().\n> \"max_vl\" should be set up also on normal case, like the following patch.\n> \n> \n> --- a/arch/arm64/kernel/ptrace.c\n> +++ b/arch/arm64/kernel/ptrace.c\n> @@ -755,6 +755,8 @@ static void sve_init_header_from_task(struct user_sve_header *header,\n> \n>         if (WARN_ON(!sve_vl_valid(sve_max_vl)))\n>                 header->max_vl = header->vl;\n> +       else\n> +               header->max_vl = sve_max_vl;\n> \n>         header->size = SVE_PT_SIZE(vq, header->flags);\n>         header->max_size = SVE_PT_SIZE(sve_vq_from_vl(header->max_vl),\n\nHi, thanks for reporting this.\n\nIt looks like a refactoring mistake I made while removing BUG_ON()s,\nwhich I missed in my testing.\n\nYour fix looks correct and seems to work.  For stylistic reasons, I may\nwrite it like this instead, but the effect should be the same:\n\n\theader->max_vl = sve_max_vl;\n\tif (WARN_ON(!sve_vl_valid(sve_max_vl))\n\t\theader->max_vl = header->vl;\n\nCheers\n---Dave\n\n> \n> \n> Best regards,\n> Takayuki Okamoto\n> \n> -----Original Message-----\n> From: gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] On Behalf Of Dave Martin\n> Sent: Friday, September 1, 2017 2:01 AM\n> To: linux-arm-kernel@lists.infradead.org\n> Cc: Catalin Marinas <catalin.marinas@arm.com>; Will Deacon <will.deacon@arm.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>; Alex Bennée <alex.bennee@linaro.org>; Szabolcs Nagy <szabolcs.nagy@arm.com>; Richard Sandiford <richard.sandiford@arm.com>; kvmarm@lists.cs.columbia.edu; libc-alpha@sourceware.org; linux-arch@vger.kernel.org; gdb@sourceware.org; Alan Hayward <alan.hayward@arm.com>; Yao Qi <Yao.Qi@arm.com>; Oleg Nesterov <oleg@redhat.com>; Alexander Viro <viro@zeniv.linux.org.uk>\n> Subject: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support\n> \n\n[...]\n\n> @@ -702,6 +737,210 @@ static int system_call_set(struct task_struct *target,\n>  \treturn ret;\n>  }\n>  \n> +#ifdef CONFIG_ARM64_SVE\n> +\n> +static void sve_init_header_from_task(struct user_sve_header *header,\n> +\t\t\t\t      struct task_struct *target)\n> +{\n> +\tunsigned int vq;\n> +\n> +\tmemset(header, 0, sizeof(*header));\n> +\n> +\theader->flags = test_tsk_thread_flag(target, TIF_SVE) ?\n> +\t\tSVE_PT_REGS_SVE : SVE_PT_REGS_FPSIMD;\n> +\tif (test_tsk_thread_flag(target, TIF_SVE_VL_INHERIT))\n> +\t\theader->flags |= SVE_PT_VL_INHERIT;\n> +\n> +\theader->vl = target->thread.sve_vl;\n> +\tvq = sve_vq_from_vl(header->vl);\n> +\n> +\tif (WARN_ON(!sve_vl_valid(sve_max_vl)))\n> +\t\theader->max_vl = header->vl;\n> +\n> +\theader->size = SVE_PT_SIZE(vq, header->flags);\n> +\theader->max_size = SVE_PT_SIZE(sve_vq_from_vl(header->max_vl),\n> +\t\t\t\t      SVE_PT_REGS_SVE);\n> +}\n\n[...]","headers":{"Return-Path":"<libc-alpha-return-84274-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-84274-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"x4JLK9sQ\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnWxw3GSQz9sRY\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  7 Sep 2017 04:16:52 +1000 (AEST)","(qmail 32893 invoked by alias); 6 Sep 2017 18:16:45 -0000","(qmail 32872 invoked by uid 89); 6 Sep 2017 18:16:44 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-type:content-transfer-encoding\n\t:in-reply-to; q=dns; s=default; b=tRAvM3u4DwQxJ6A67suG93PAVwR0YS\n\t+exRMvZckIH/e0EL1ltsQYHqn9v1jMQijzO1eMMNTBAG9f/oLaBM4Opn7cbzy42l\n\tAnvRIaVY7GZz0NkPSq8gEmM6AABeUiU6DVxBVDF0wL8Qjmhx1VLedSuUzKfkL0iK\n\tVhaWeiQF6hQvg=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-type:content-transfer-encoding\n\t:in-reply-to; s=default; bh=LoKzLBWz8kFkhJl/xb/oaUHGYDg=; b=x4JL\n\tK9sQQ4K73qa2SYwude3rf9OL14FlLTr+3oKiXo2eEBjYLb5ofzmvOtttGbrHOQXa\n\taYLyR5XfC+UcROfB973PRb23fs720Q9XkGuuF2XSFUwRzgM73euRgZZvkgIcd5Vd\n\tRuWNlXBYb22qLMgpVDpOk8QvmC2FJ6c4CjKDGfs=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2,\n\tGIT_PATCH_3, RP_MATCHES_RCVD,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=","X-Spam-User":"qpsmtpd, 2 recipients","X-HELO":"foss.arm.com","Date":"Wed, 6 Sep 2017 19:16:35 +0100","From":"Dave Martin <Dave.Martin@arm.com>","To":"\"Okamoto, Takayuki\" <tokamoto@jp.fujitsu.com>","Cc":"\"linux-arm-kernel@lists.infradead.org\"\n\t<linux-arm-kernel@lists.infradead.org>, \"linux-arch@vger.kernel.org\"\n\t<linux-arch@vger.kernel.org>, \"libc-alpha@sourceware.org\"\n\t<libc-alpha@sourceware.org>, \"gdb@sourceware.org\" <gdb@sourceware.org>, \n\tArd Biesheuvel <ard.biesheuvel@linaro.org>, \n\tSzabolcs Nagy <szabolcs.nagy@arm.com>, Catalin Marinas\n\t<catalin.marinas@arm.com>, Yao Qi <Yao.Qi@arm.com>, Alan Hayward\n\t<alan.hayward@arm.com>, Will Deacon <will.deacon@arm.com>,\n\tOleg Nesterov <oleg@redhat.com>, Alexander Viro\n\t<viro@zeniv.linux.org.uk>, \n\tRichard Sandiford <richard.sandiford@arm.com>, Alex =?iso-8859-1?q?Ben?=\n\t=?iso-8859-1?q?n=E9e?= <alex.bennee@linaro.org>,\n\t\"kvmarm@lists.cs.columbia.edu\" <kvmarm@lists.cs.columbia.edu>","Subject":"Re: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","Message-ID":"<20170906181634.GF6321@e103592.cambridge.arm.com>","References":"<1504198860-12951-1-git-send-email-Dave.Martin@arm.com>\n\t<1504198860-12951-20-git-send-email-Dave.Martin@arm.com>\n\t<5FA513F682BE7F4EAAB8EE035D5B08E44109DFE8@G01JPEXMBKW02>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<5FA513F682BE7F4EAAB8EE035D5B08E44109DFE8@G01JPEXMBKW02>","User-Agent":"Mutt/1.5.23 (2014-03-12)"}},{"id":1764505,"web_url":"http://patchwork.ozlabs.org/comment/1764505/","msgid":"<5FA513F682BE7F4EAAB8EE035D5B08E44109EBDF@G01JPEXMBKW02>","list_archive_url":null,"date":"2017-09-07T05:11:45","subject":"RE: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","submitter":{"id":72310,"url":"http://patchwork.ozlabs.org/api/people/72310/","name":"Okamoto, Takayuki","email":"tokamoto@jp.fujitsu.com"},"content":"Hi Dave,\r\n\r\nThank you for your reply.\r\n\r\n> Your fix looks correct and seems to work.  For stylistic reasons, I may\r\n> write it like this instead, but the effect should be the same:\r\n> \r\n> \theader->max_vl = sve_max_vl;\r\n> \tif (WARN_ON(!sve_vl_valid(sve_max_vl))\r\n> \t\theader->max_vl = header->vl;\r\n\r\nIt is better than my fix.\r\nPlease, apply it at next version.\r\n\r\nBest regards,\r\nTakayuki Okamoto\r\n\r\n> -----Original Message-----\r\n> From: linux-arm-kernel\r\n> [mailto:linux-arm-kernel-bounces@lists.infradead.org] On Behalf Of Dave\r\n> Martin\r\n> Sent: Thursday, September 7, 2017 3:17 AM\r\n> To: Okamoto, Takayuki <tokamoto@jp.fujitsu.com>\r\n> Cc: linux-arch@vger.kernel.org; libc-alpha@sourceware.org; Ard\r\n> Biesheuvel <ard.biesheuvel@linaro.org>; Szabolcs Nagy\r\n> <szabolcs.nagy@arm.com>; gdb@sourceware.org; Yao Qi <Yao.Qi@arm.com>;\r\n> Alan Hayward <alan.hayward@arm.com>; Will Deacon <will.deacon@arm.com>;\r\n> Oleg Nesterov <oleg@redhat.com>; Richard Sandiford\r\n> <richard.sandiford@arm.com>; Alexander Viro <viro@zeniv.linux.org.uk>;\r\n> Catalin Marinas <catalin.marinas@arm.com>; Alex Bennée\r\n> <alex.bennee@linaro.org>; kvmarm@lists.cs.columbia.edu;\r\n> linux-arm-kernel@lists.infradead.org\r\n> Subject: Re: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support\r\n> \r\n> On Wed, Sep 06, 2017 at 04:21:50PM +0000, Okamoto, Takayuki wrote:\r\n> > Hi Dave,\r\n> >\r\n> > I am an engineer of the postK computer from Fujitsu.\r\n> >\r\n> > When I tried to read \"max_vl\" by ptrace with this patch on our local SVE\r\n> > simulator, it was read as zero.\r\n> > I think the cause of this incident is that \"max_vl\" is set as \"header->vl\"\r\n> > only on warning case in sve_init_header_from_task().\r\n> > \"max_vl\" should be set up also on normal case, like the following patch.\r\n> >\r\n> >\r\n> > --- a/arch/arm64/kernel/ptrace.c\r\n> > +++ b/arch/arm64/kernel/ptrace.c\r\n> > @@ -755,6 +755,8 @@ static void sve_init_header_from_task(struct\r\n> user_sve_header *header,\r\n> >\r\n> >         if (WARN_ON(!sve_vl_valid(sve_max_vl)))\r\n> >                 header->max_vl = header->vl;\r\n> > +       else\r\n> > +               header->max_vl = sve_max_vl;\r\n> >\r\n> >         header->size = SVE_PT_SIZE(vq, header->flags);\r\n> >         header->max_size =\r\n> SVE_PT_SIZE(sve_vq_from_vl(header->max_vl),\r\n> \r\n> Hi, thanks for reporting this.\r\n> \r\n> It looks like a refactoring mistake I made while removing BUG_ON()s,\r\n> which I missed in my testing.\r\n> \r\n> Your fix looks correct and seems to work.  For stylistic reasons, I may\r\n> write it like this instead, but the effect should be the same:\r\n> \r\n> \theader->max_vl = sve_max_vl;\r\n> \tif (WARN_ON(!sve_vl_valid(sve_max_vl))\r\n> \t\theader->max_vl = header->vl;\r\n> \r\n> Cheers\r\n> ---Dave\r\n> \r\n> >\r\n> >\r\n> > Best regards,\r\n> > Takayuki Okamoto\r\n> >\r\n> > -----Original Message-----\r\n> > From: gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] On\r\n> Behalf Of Dave Martin\r\n> > Sent: Friday, September 1, 2017 2:01 AM\r\n> > To: linux-arm-kernel@lists.infradead.org\r\n> > Cc: Catalin Marinas <catalin.marinas@arm.com>; Will Deacon\r\n> <will.deacon@arm.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>; Alex\r\n> Bennée <alex.bennee@linaro.org>; Szabolcs Nagy <szabolcs.nagy@arm.com>;\r\n> Richard Sandiford <richard.sandiford@arm.com>;\r\n> kvmarm@lists.cs.columbia.edu; libc-alpha@sourceware.org;\r\n> linux-arch@vger.kernel.org; gdb@sourceware.org; Alan Hayward\r\n> <alan.hayward@arm.com>; Yao Qi <Yao.Qi@arm.com>; Oleg Nesterov\r\n> <oleg@redhat.com>; Alexander Viro <viro@zeniv.linux.org.uk>\r\n> > Subject: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support\r\n> >\r\n> \r\n> [...]\r\n> \r\n> > @@ -702,6 +737,210 @@ static int system_call_set(struct task_struct\r\n> *target,\r\n> >  \treturn ret;\r\n> >  }\r\n> >\r\n> > +#ifdef CONFIG_ARM64_SVE\r\n> > +\r\n> > +static void sve_init_header_from_task(struct user_sve_header *header,\r\n> > +\t\t\t\t      struct task_struct *target)\r\n> > +{\r\n> > +\tunsigned int vq;\r\n> > +\r\n> > +\tmemset(header, 0, sizeof(*header));\r\n> > +\r\n> > +\theader->flags = test_tsk_thread_flag(target, TIF_SVE) ?\r\n> > +\t\tSVE_PT_REGS_SVE : SVE_PT_REGS_FPSIMD;\r\n> > +\tif (test_tsk_thread_flag(target, TIF_SVE_VL_INHERIT))\r\n> > +\t\theader->flags |= SVE_PT_VL_INHERIT;\r\n> > +\r\n> > +\theader->vl = target->thread.sve_vl;\r\n> > +\tvq = sve_vq_from_vl(header->vl);\r\n> > +\r\n> > +\tif (WARN_ON(!sve_vl_valid(sve_max_vl)))\r\n> > +\t\theader->max_vl = header->vl;\r\n> > +\r\n> > +\theader->size = SVE_PT_SIZE(vq, header->flags);\r\n> > +\theader->max_size = SVE_PT_SIZE(sve_vq_from_vl(header->max_vl),\r\n> > +\t\t\t\t      SVE_PT_REGS_SVE);\r\n> > +}\r\n> \r\n> [...]\r\n> \r\n> _______________________________________________\r\n> linux-arm-kernel mailing list\r\n> linux-arm-kernel@lists.infradead.org\r\n> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel","headers":{"Return-Path":"<libc-alpha-return-84282-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-84282-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"eWraCdF0\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnpTy4P01z9s8J\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  7 Sep 2017 15:12:06 +1000 (AEST)","(qmail 78896 invoked by alias); 7 Sep 2017 05:11:57 -0000","(qmail 78877 invoked by uid 89); 7 Sep 2017 05:11:57 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:references\n\t:in-reply-to:content-type:content-transfer-encoding\n\t:mime-version; q=dns; s=default; b=AasqfzAKwNgEtEbL1+Foxulc+Yrzz\n\tK4Sho5Ph77A4HxTvZZdM+sCGWJcf+kmkgqd4tBZH8jiOtDuO61q01qJPJKXGU4Jo\n\tQUtfbxlzVupmbLPkV2WF0Lh5NhIM9zcB6iXqH1OcHd4DhqvETO1zwX8MUXW0vDKY\n\tThZzBO2dgWK6UM=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:references\n\t:in-reply-to:content-type:content-transfer-encoding\n\t:mime-version; s=default; bh=+q8y6qNIKftoiBooE9TmpM7l8cw=; b=eWr\n\taCdF0UqtXcbeiLFKYXXO90Iph7RE8yL3lzt+NUH1WsF36EBgqNhhmTKC3ZMkPhxJ\n\tH0DSRwr0kDvzVI91aMCBzbdHiX/a+LPhudO4Z2kVlTIdLaDRtZPKcXOLZ2qrPU4k\n\tiY2gO9ujW5F0LGQP2F6oLz1ZUK8PRVg0+XK6Qay0=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2,\n\tGIT_PATCH_3, MIME_BASE64_BLANKS, RP_MATCHES_RCVD,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=H*c:gb2312","X-Spam-User":"qpsmtpd, 2 recipients","X-HELO":"mgwym01.jp.fujitsu.com","From":"\"Okamoto, Takayuki\" <tokamoto@jp.fujitsu.com>","To":"'Dave Martin' <Dave.Martin@arm.com>","CC":"\"linux-arch@vger.kernel.org\" <linux-arch@vger.kernel.org>,\n\t\"libc-alpha@sourceware.org\" <libc-alpha@sourceware.org>, Ard Biesheuvel\n\t<ard.biesheuvel@linaro.org>, Szabolcs Nagy <szabolcs.nagy@arm.com>, \n\t\"gdb@sourceware.org\" <gdb@sourceware.org>, Yao Qi <Yao.Qi@arm.com>, \"Alan\n\tHayward\" <alan.hayward@arm.com>, Will Deacon <will.deacon@arm.com>, \"Oleg\n\tNesterov\" <oleg@redhat.com>,\n\tRichard Sandiford <richard.sandiford@arm.com>, Alexander Viro\n\t<viro@zeniv.linux.org.uk>, Catalin Marinas <catalin.marinas@arm.com>, \n\t=?gb2312?b?QWxleCBCZW5u?= =?gb2312?b?qKZl?=\n\t<alex.bennee@linaro.org>, \"kvmarm@lists.cs.columbia.edu\"\n\t<kvmarm@lists.cs.columbia.edu>, \"linux-arm-kernel@lists.infradead.org\"\n\t<linux-arm-kernel@lists.infradead.org>","Subject":"RE: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","Date":"Thu, 7 Sep 2017 05:11:45 +0000","Message-ID":"<5FA513F682BE7F4EAAB8EE035D5B08E44109EBDF@G01JPEXMBKW02>","References":"<1504198860-12951-1-git-send-email-Dave.Martin@arm.com>\n\t<1504198860-12951-20-git-send-email-Dave.Martin@arm.com>\n\t<5FA513F682BE7F4EAAB8EE035D5B08E44109DFE8@G01JPEXMBKW02>\n\t<20170906181634.GF6321@e103592.cambridge.arm.com>","In-Reply-To":"<20170906181634.GF6321@e103592.cambridge.arm.com>","x-securitypolicycheck":"OK by SHieldMailChecker v2.4.6","x-shieldmailcheckerpolicyversion":"FJ-ISEC-20160315","x-shieldmailcheckermailid":"a96d12fce9af45d0a94000d6f54939cb","Content-Type":"text/plain; charset=\"gb2312\"","Content-Transfer-Encoding":"base64","MIME-Version":"1.0","X-SecurityPolicyCheck-GC":"OK by FENCE-Mail","X-TM-AS-MML":"disable"}},{"id":1765338,"web_url":"http://patchwork.ozlabs.org/comment/1765338/","msgid":"<20170908131136.GG6321@e103592.cambridge.arm.com>","list_archive_url":null,"date":"2017-09-08T13:11:40","subject":"Re: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","submitter":{"id":26612,"url":"http://patchwork.ozlabs.org/api/people/26612/","name":"Dave Martin","email":"Dave.Martin@arm.com"},"content":"On Thu, Sep 07, 2017 at 05:11:45AM +0000, Okamoto, Takayuki wrote:\n> Hi Dave,\n> \n> Thank you for your reply.\n> \n> > Your fix looks correct and seems to work.  For stylistic reasons, I may\n> > write it like this instead, but the effect should be the same:\n> > \n> > \theader->max_vl = sve_max_vl;\n> > \tif (WARN_ON(!sve_vl_valid(sve_max_vl))\n> > \t\theader->max_vl = header->vl;\n> \n> It is better than my fix.\n> Please, apply it at next version.\n\nI've rebased to v4.13 and pushed a branch to track fixes against v2,\nhere:\n\n * http://linux-arm.org/git?p=linux-dm.git;a=shortlog;h=refs/heads/sve/v2%2Bfixes\n\n * git://linux-arm.org/linux-dm.git sve/v2+fixes\n\nCheers\n---Dave","headers":{"Return-Path":"<libc-alpha-return-84381-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-84381-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"YdaD42n+\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xpd574Wm9z9s7c\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 23:11:55 +1000 (AEST)","(qmail 94696 invoked by alias); 8 Sep 2017 13:11:49 -0000","(qmail 94678 invoked by uid 89); 8 Sep 2017 13:11:48 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-type:in-reply-to; q=dns; s=default; b=yyph\n\tBOlBh6Bx2E/U31AggzKF9ZMJP7yLPSUrutnJlpuLalt0u4mfTNxR4tT5lN3l524o\n\tclK6ckpGPp6VSjSjf9RioHLmHvMTW5UxsImch9ABqmWRpLYvQzosM4mu5+cYdyQt\n\tvf1hDC6vdsh7PggqOK3ampiFAkosTBNl7thXS9I=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-type:in-reply-to; s=default; bh=3MCkFJTGmE\n\txxvsiVLru60Ps8hR0=; b=YdaD42n+Qq35r1mV5lDtxlkMaeCKmoYP7PS+ioceOv\n\tplQqL7vljtUKWbQHwADf0AuFLeSF7CzUfDY+n9GZRcEZcW+jPgQCQa+MCb362pVw\n\tlnG4JuJKh9e78HBGyi7ekmnzXi0JG9+GfqqCln9xLKgf0f37cfPJEePwsPF4zWMR\n\tU=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-1.9 required=5.0 tests=BAYES_00,\n\tRP_MATCHES_RCVD,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:721","X-Spam-User":"qpsmtpd, 2 recipients","X-HELO":"foss.arm.com","Date":"Fri, 8 Sep 2017 14:11:40 +0100","From":"Dave Martin <Dave.Martin@arm.com>","To":"\"Okamoto, Takayuki\" <tokamoto@jp.fujitsu.com>","Cc":"\"linux-arch@vger.kernel.org\" <linux-arch@vger.kernel.org>,\n\t\"libc-alpha@sourceware.org\" <libc-alpha@sourceware.org>, Ard Biesheuvel\n\t<ard.biesheuvel@linaro.org>, \tSzabolcs Nagy <szabolcs.nagy@arm.com>,\n\t\"gdb@sourceware.org\" <gdb@sourceware.org>, Yao Qi <Yao.Qi@arm.com>, \n\tWill Deacon <will.deacon@arm.com>, Oleg Nesterov <oleg@redhat.com>, Alex\n\t=?iso-8859-1?q?Benn=E9e?= <alex.bennee@linaro.org>,\n\tRichard Sandiford <richard.sandiford@arm.com>, Alexander Viro\n\t<viro@zeniv.linux.org.uk>, \tAlan Hayward <alan.hayward@arm.com>,\n\tCatalin Marinas <catalin.marinas@arm.com>, \n\t\"kvmarm@lists.cs.columbia.edu\" <kvmarm@lists.cs.columbia.edu>, \n\t\"linux-arm-kernel@lists.infradead.org\"\n\t<linux-arm-kernel@lists.infradead.org>","Subject":"Re: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","Message-ID":"<20170908131136.GG6321@e103592.cambridge.arm.com>","References":"<1504198860-12951-1-git-send-email-Dave.Martin@arm.com>\n\t<1504198860-12951-20-git-send-email-Dave.Martin@arm.com>\n\t<5FA513F682BE7F4EAAB8EE035D5B08E44109DFE8@G01JPEXMBKW02>\n\t<20170906181634.GF6321@e103592.cambridge.arm.com>\n\t<5FA513F682BE7F4EAAB8EE035D5B08E44109EBDF@G01JPEXMBKW02>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<5FA513F682BE7F4EAAB8EE035D5B08E44109EBDF@G01JPEXMBKW02>","User-Agent":"Mutt/1.5.23 (2014-03-12)"}},{"id":1768573,"web_url":"http://patchwork.ozlabs.org/comment/1768573/","msgid":"<87bmmda15n.fsf@linaro.org>","list_archive_url":null,"date":"2017-09-14T12:57:08","subject":"Re: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","submitter":{"id":39532,"url":"http://patchwork.ozlabs.org/api/people/39532/","name":"Alex Bennée","email":"alex.bennee@linaro.org"},"content":"Dave Martin <Dave.Martin@arm.com> writes:\n\n> This patch defines and implements a new regset NT_ARM_SVE, which\n> describes a thread's SVE register state.  This allows a debugger to\n> manipulate the SVE state, as well as being included in ELF\n> coredumps for post-mortem debugging.\n>\n> Because the regset size and layout are dependent on the thread's\n> current vector length, it is not possible to define a C struct to\n> describe the regset contents as is done for existing regsets.\n> Instead, and for the same reasons, NT_ARM_SVE is based on the\n> freeform variable-layout approach used for the SVE signal frame.\n>\n> Additionally, to reduce debug overhead when debugging threads that\n> might or might not have live SVE register state, NT_ARM_SVE may be\n> presented in one of two different formats: the old struct\n> user_fpsimd_state format is embedded for describing the state of a\n> thread with no live SVE state, whereas a new variable-layout\n> structure is embedded for describing live SVE state.  This avoids a\n> debugger needing to poll NT_PRFPREG in addition to NT_ARM_SVE, and\n> allows existing userspace code to handle the non-SVE case without\n> too much modification.\n>\n> For this to work, NT_ARM_SVE is defined with a fixed-format header\n> of type struct user_sve_header, which the recipient can use to\n> figure out the content, size and layout of the reset of the regset.\n> Accessor macros are defined to allow the vector-length-dependent\n> parts of the regset to be manipulated.\n>\n> Signed-off-by: Alan Hayward <alan.hayward@arm.com>\n> Signed-off-by: Dave Martin <Dave.Martin@arm.com>\n> Cc: Alex Bennée <alex.bennee@linaro.org>\n>\n> ---\n>\n> Changes since v1\n> ----------------\n>\n> Other changes related to Alex Bennée's comments:\n>\n> * Migrate to SVE_VQ_BYTES instead of magic numbers.\n>\n> Requested by Alex Bennée:\n>\n> * Thin out BUG_ON()s:\n> Redundant BUG_ON()s and ones that just check invariants are removed.\n> Important sanity-checks are migrated to WARN_ON()s, with some\n> minimal best-effort patch-up code.\n>\n> Other:\n>\n> * [ABI fix] Bail out with -EIO if attempting to set the\n> SVE regs for an unsupported VL, instead of misparsing the regset data.\n>\n> * Replace some in-kernel open-coded arithmetic with ALIGN()/\n> DIV_ROUND_UP().\n> ---\n>  arch/arm64/include/asm/fpsimd.h      |  13 +-\n>  arch/arm64/include/uapi/asm/ptrace.h | 135 ++++++++++++++++++\n>  arch/arm64/kernel/fpsimd.c           |  40 +++++-\n>  arch/arm64/kernel/ptrace.c           | 270 +++++++++++++++++++++++++++++++++--\n>  include/uapi/linux/elf.h             |   1 +\n>  5 files changed, 449 insertions(+), 10 deletions(-)\n>\n> diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h\n> index 6c22624..2723cca 100644\n> --- a/arch/arm64/include/asm/fpsimd.h\n> +++ b/arch/arm64/include/asm/fpsimd.h\n> @@ -38,13 +38,16 @@ struct fpsimd_state {\n>  \t\t\t__uint128_t vregs[32];\n>  \t\t\tu32 fpsr;\n>  \t\t\tu32 fpcr;\n> +\t\t\t/*\n> +\t\t\t * For ptrace compatibility, pad to next 128-bit\n> +\t\t\t * boundary here if extending this struct.\n> +\t\t\t */\n>  \t\t};\n>  \t};\n>  \t/* the id of the last cpu to have restored this state */\n>  \tunsigned int cpu;\n>  };\n>\n> -\n>  #if defined(__KERNEL__) && defined(CONFIG_COMPAT)\n>  /* Masks for extracting the FPSR and FPCR from the FPSCR */\n>  #define VFP_FPSCR_STAT_MASK\t0xf800009f\n> @@ -89,6 +92,10 @@ extern void sve_alloc(struct task_struct *task);\n>  extern void fpsimd_release_thread(struct task_struct *task);\n>  extern void fpsimd_dup_sve(struct task_struct *dst,\n>  \t\t\t   struct task_struct const *src);\n> +extern void fpsimd_sync_to_sve(struct task_struct *task);\n> +extern void sve_sync_to_fpsimd(struct task_struct *task);\n> +extern void sve_sync_from_fpsimd_zeropad(struct task_struct *task);\n> +\n>  extern int sve_set_vector_length(struct task_struct *task,\n>  \t\t\t\t unsigned long vl, unsigned long flags);\n>\n> @@ -103,6 +110,10 @@ static void __maybe_unused sve_alloc(struct task_struct *task) { }\n>  static void __maybe_unused fpsimd_release_thread(struct task_struct *task) { }\n>  static void __maybe_unused fpsimd_dup_sve(struct task_struct *dst,\n>  \t\t\t\t\t  struct task_struct const *src) { }\n> +static void __maybe_unused sve_sync_to_fpsimd(struct task_struct *task) { }\n> +static void __maybe_unused sve_sync_from_fpsimd_zeropad(\n> +\tstruct task_struct *task) { }\n> +\n>  static void __maybe_unused sve_init_vq_map(void) { }\n>  static void __maybe_unused sve_update_vq_map(void) { }\n>  static int __maybe_unused sve_verify_vq_map(void) { return 0; }\n> diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h\n> index d1ff83d..1915ab0 100644\n> --- a/arch/arm64/include/uapi/asm/ptrace.h\n> +++ b/arch/arm64/include/uapi/asm/ptrace.h\n> @@ -22,6 +22,7 @@\n>  #include <linux/types.h>\n>\n>  #include <asm/hwcap.h>\n> +#include <asm/sigcontext.h>\n>\n>\n>  /*\n> @@ -63,6 +64,8 @@\n>\n>  #ifndef __ASSEMBLY__\n>\n> +#include <linux/prctl.h>\n> +\n>  /*\n>   * User structures for general purpose, floating point and debug registers.\n>   */\n> @@ -90,6 +93,138 @@ struct user_hwdebug_state {\n>  \t}\t\tdbg_regs[16];\n>  };\n>\n> +/* SVE/FP/SIMD state (NT_ARM_SVE) */\n> +\n> +struct user_sve_header {\n> +\t__u32 size; /* total meaningful regset content in bytes */\n> +\t__u32 max_size; /* maxmium possible size for this thread */\n> +\t__u16 vl; /* current vector length */\n> +\t__u16 max_vl; /* maximum possible vector length */\n> +\t__u16 flags;\n> +\t__u16 __reserved;\n> +};\n> +\n> +/* Definitions for user_sve_header.flags: */\n> +#define SVE_PT_REGS_MASK\t\t(1 << 0)\n> +\n> +/* Flags: must be kept in sync with prctl interface in\n> <linux/ptrace.h> */\n\nWhich flags? We base some on PR_foo flags but we seem to shift them\nanyway so where is the requirement for them to match from?\n\n> +#define SVE_PT_REGS_FPSIMD\t\t0\n> +#define SVE_PT_REGS_SVE\t\t\tSVE_PT_REGS_MASK\n> +\n> +#define SVE_PT_VL_INHERIT\t\t(PR_SVE_VL_INHERIT >> 16)\n> +#define SVE_PT_VL_ONEXEC\t\t(PR_SVE_SET_VL_ONEXEC >> 16)\n> +\n> +\n> +/*\n> + * The remainder of the SVE state follows struct user_sve_header.  The\n> + * total size of the SVE state (including header) depends on the\n> + * metadata in the header:  SVE_PT_SIZE(vq, flags) gives the total size\n> + * of the state in bytes, including the header.\n> + *\n> + * Refer to <asm/sigcontext.h> for details of how to pass the correct\n> + * \"vq\" argument to these macros.\n> + */\n> +\n> +/* Offset from the start of struct user_sve_header to the register data */\n> +#define SVE_PT_REGS_OFFSET\t\t\t\t\t\\\n> +\t((sizeof(struct sve_context) + (SVE_VQ_BYTES - 1))\t\\\n> +\t\t/ SVE_VQ_BYTES * SVE_VQ_BYTES)\n> +\n> +/*\n> + * The register data content and layout depends on the value of the\n> + * flags field.\n> + */\n> +\n> +/*\n> + * (flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_FPSIMD case:\n> + *\n> + * The payload starts at offset SVE_PT_FPSIMD_OFFSET, and is of type\n> + * struct user_fpsimd_state.  Additional data might be appended in the\n> + * future: use SVE_PT_FPSIMD_SIZE(vq, flags) to compute the total size.\n> + * SVE_PT_FPSIMD_SIZE(vq, flags) will never be less than\n> + * sizeof(struct user_fpsimd_state).\n> + */\n> +\n> +#define SVE_PT_FPSIMD_OFFSET\t\tSVE_PT_REGS_OFFSET\n> +\n> +#define SVE_PT_FPSIMD_SIZE(vq, flags)\t(sizeof(struct user_fpsimd_state))\n> +\n> +/*\n> + * (flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_SVE case:\n> + *\n> + * The payload starts at offset SVE_PT_SVE_OFFSET, and is of size\n> + * SVE_PT_SVE_SIZE(vq, flags).\n> + *\n> + * Additional macros describe the contents and layout of the payload.\n> + * For each, SVE_PT_SVE_x_OFFSET(args) is the start offset relative to\n> + * the start of struct user_sve_header, and SVE_PT_SVE_x_SIZE(args) is\n> + * the size in bytes:\n> + *\n> + *\tx\ttype\t\t\t\tdescription\n> + *\t-\t----\t\t\t\t-----------\n> + *\tZREGS\t\t\\\n> + *\tZREG\t\t|\n> + *\tPREGS\t\t| refer to <asm/sigcontext.h>\n> + *\tPREG\t\t|\n> + *\tFFR\t\t/\n> + *\n> + *\tFPSR\tuint32_t\t\t\tFPSR\n> + *\tFPCR\tuint32_t\t\t\tFPCR\n> + *\n> + * Additional data might be appended in the future.\n> + */\n> +\n> +#define SVE_PT_SVE_ZREG_SIZE(vq)\tSVE_SIG_ZREG_SIZE(vq)\n> +#define SVE_PT_SVE_PREG_SIZE(vq)\tSVE_SIG_PREG_SIZE(vq)\n> +#define SVE_PT_SVE_FFR_SIZE(vq)\t\tSVE_SIG_FFR_SIZE(vq)\n> +#define SVE_PT_SVE_FPSR_SIZE\t\tsizeof(__u32)\n> +#define SVE_PT_SVE_FPCR_SIZE\t\tsizeof(__u32)\n> +\n> +#define __SVE_SIG_TO_PT(offset) \\\n> +\t((offset) - SVE_SIG_REGS_OFFSET + SVE_PT_REGS_OFFSET)\n> +\n> +#define SVE_PT_SVE_OFFSET\t\tSVE_PT_REGS_OFFSET\n> +\n> +#define SVE_PT_SVE_ZREGS_OFFSET \\\n> +\t__SVE_SIG_TO_PT(SVE_SIG_ZREGS_OFFSET)\n> +#define SVE_PT_SVE_ZREG_OFFSET(vq, n) \\\n> +\t__SVE_SIG_TO_PT(SVE_SIG_ZREG_OFFSET(vq, n))\n> +#define SVE_PT_SVE_ZREGS_SIZE(vq) \\\n> +\t(SVE_PT_SVE_ZREG_OFFSET(vq, SVE_NUM_ZREGS) - SVE_PT_SVE_ZREGS_OFFSET)\n> +\n> +#define SVE_PT_SVE_PREGS_OFFSET(vq) \\\n> +\t__SVE_SIG_TO_PT(SVE_SIG_PREGS_OFFSET(vq))\n> +#define SVE_PT_SVE_PREG_OFFSET(vq, n) \\\n> +\t__SVE_SIG_TO_PT(SVE_SIG_PREG_OFFSET(vq, n))\n> +#define SVE_PT_SVE_PREGS_SIZE(vq) \\\n> +\t(SVE_PT_SVE_PREG_OFFSET(vq, SVE_NUM_PREGS) - \\\n> +\t\tSVE_PT_SVE_PREGS_OFFSET(vq))\n> +\n> +#define SVE_PT_SVE_FFR_OFFSET(vq) \\\n> +\t__SVE_SIG_TO_PT(SVE_SIG_FFR_OFFSET(vq))\n> +\n> +#define SVE_PT_SVE_FPSR_OFFSET(vq)\t\t\t\t\\\n> +\t((SVE_PT_SVE_FFR_OFFSET(vq) + SVE_PT_SVE_FFR_SIZE(vq) +\t\\\n> +\t\t\t(SVE_VQ_BYTES - 1))\t\t\t\\\n> +\t\t/ SVE_VQ_BYTES * SVE_VQ_BYTES)\n> +#define SVE_PT_SVE_FPCR_OFFSET(vq) \\\n> +\t(SVE_PT_SVE_FPSR_OFFSET(vq) + SVE_PT_SVE_FPSR_SIZE)\n> +\n> +/*\n> + * Any future extension appended after FPCR must be aligned to the next\n> + * 128-bit boundary.\n> + */\n> +\n> +#define SVE_PT_SVE_SIZE(vq, flags)\t\t\t\t\t\\\n> +\t((SVE_PT_SVE_FPCR_OFFSET(vq) + SVE_PT_SVE_FPCR_SIZE\t\t\\\n> +\t\t\t- SVE_PT_SVE_OFFSET + (SVE_VQ_BYTES - 1))\t\\\n> +\t\t/ SVE_VQ_BYTES * SVE_VQ_BYTES)\n> +\n> +#define SVE_PT_SIZE(vq, flags)\t\t\t\t\t\t\\\n> +\t (((flags) & SVE_PT_REGS_MASK) == SVE_PT_REGS_SVE ?\t\t\\\n> +\t\t  SVE_PT_SVE_OFFSET + SVE_PT_SVE_SIZE(vq, flags)\t\\\n> +\t\t: SVE_PT_FPSIMD_OFFSET + SVE_PT_FPSIMD_SIZE(vq, flags))\n> +\n>  #endif /* __ASSEMBLY__ */\n>\n>  #endif /* _UAPI__ASM_PTRACE_H */\n> diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c\n> index fff9fcf..361c019 100644\n> --- a/arch/arm64/kernel/fpsimd.c\n> +++ b/arch/arm64/kernel/fpsimd.c\n> @@ -303,6 +303,37 @@ void sve_alloc(struct task_struct *task)\n>  \tBUG_ON(!task->thread.sve_state);\n>  }\n>\n> +void fpsimd_sync_to_sve(struct task_struct *task)\n> +{\n> +\tif (!test_tsk_thread_flag(task, TIF_SVE))\n> +\t\tfpsimd_to_sve(task);\n> +}\n> +\n> +void sve_sync_to_fpsimd(struct task_struct *task)\n> +{\n> +\tif (test_tsk_thread_flag(task, TIF_SVE))\n> +\t\tsve_to_fpsimd(task);\n> +}\n> +\n> +void sve_sync_from_fpsimd_zeropad(struct task_struct *task)\n> +{\n> +\tunsigned int vq;\n> +\tvoid *sst = task->thread.sve_state;\n> +\tstruct fpsimd_state const *fst = &task->thread.fpsimd_state;\n> +\tunsigned int i;\n> +\n> +\tif (!test_tsk_thread_flag(task, TIF_SVE))\n> +\t\treturn;\n> +\n> +\tvq = sve_vq_from_vl(task->thread.sve_vl);\n> +\n> +\tmemset(sst, 0, SVE_SIG_REGS_SIZE(vq));\n> +\n> +\tfor (i = 0; i < 32; ++i)\n> +\t\tmemcpy(ZREG(sst, vq, i), &fst->vregs[i],\n> +\t\t       sizeof(fst->vregs[i]));\n> +}\n> +\n>  /*\n>   * Handle SVE state across fork():\n>   *\n> @@ -459,10 +490,17 @@ static void __init sve_efi_setup(void)\n>  \t * This is evidence of a crippled system and we are returning void,\n>  \t * so no attempt is made to handle this situation here.\n>  \t */\n> -\tBUG_ON(!sve_vl_valid(sve_max_vl));\n> +\tif (!sve_vl_valid(sve_max_vl))\n> +\t\tgoto fail;\n> +\n>  \tefi_sve_state = __alloc_percpu(\n>  \t\tSVE_SIG_REGS_SIZE(sve_vq_from_vl(sve_max_vl)), SVE_VQ_BYTES);\n>  \tif (!efi_sve_state)\n> +\t\tgoto fail;\n> +\n> +\treturn;\n> +\n> +fail:\n>  \t\tpanic(\"Cannot allocate percpu memory for EFI SVE save/restore\");\n>  }\n>\n> diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c\n> index 9cbb612..5ef4735b 100644\n> --- a/arch/arm64/kernel/ptrace.c\n> +++ b/arch/arm64/kernel/ptrace.c\n> @@ -32,6 +32,7 @@\n>  #include <linux/security.h>\n>  #include <linux/init.h>\n>  #include <linux/signal.h>\n> +#include <linux/string.h>\n>  #include <linux/uaccess.h>\n>  #include <linux/perf_event.h>\n>  #include <linux/hw_breakpoint.h>\n> @@ -40,6 +41,7 @@\n>  #include <linux/elf.h>\n>\n>  #include <asm/compat.h>\n> +#include <asm/cpufeature.h>\n>  #include <asm/debug-monitors.h>\n>  #include <asm/pgtable.h>\n>  #include <asm/stacktrace.h>\n> @@ -618,33 +620,66 @@ static int gpr_set(struct task_struct *target, const struct user_regset *regset,\n>  /*\n>   * TODO: update fp accessors for lazy context switching (sync/flush hwstate)\n>   */\n> -static int fpr_get(struct task_struct *target, const struct user_regset *regset,\n> -\t\t   unsigned int pos, unsigned int count,\n> -\t\t   void *kbuf, void __user *ubuf)\n> +static int __fpr_get(struct task_struct *target,\n> +\t\t     const struct user_regset *regset,\n> +\t\t     unsigned int pos, unsigned int count,\n> +\t\t     void *kbuf, void __user *ubuf, unsigned int start_pos)\n>  {\n>  \tstruct user_fpsimd_state *uregs;\n> +\n> +\tsve_sync_to_fpsimd(target);\n> +\n>  \turegs = &target->thread.fpsimd_state.user_fpsimd;\n>\n> +\treturn user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs,\n> +\t\t\t\t   start_pos, start_pos + sizeof(*uregs));\n> +}\n> +\n> +static int fpr_get(struct task_struct *target, const struct user_regset *regset,\n> +\t\t   unsigned int pos, unsigned int count,\n> +\t\t   void *kbuf, void __user *ubuf)\n> +{\n>  \tif (target == current)\n>  \t\tfpsimd_preserve_current_state();\n>\n> -\treturn user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0, -1);\n> +\treturn __fpr_get(target, regset, pos, count, kbuf, ubuf, 0);\n>  }\n>\n> -static int fpr_set(struct task_struct *target, const struct user_regset *regset,\n> -\t\t   unsigned int pos, unsigned int count,\n> -\t\t   const void *kbuf, const void __user *ubuf)\n> +static int __fpr_set(struct task_struct *target,\n> +\t\t     const struct user_regset *regset,\n> +\t\t     unsigned int pos, unsigned int count,\n> +\t\t     const void *kbuf, const void __user *ubuf,\n> +\t\t     unsigned int start_pos)\n>  {\n>  \tint ret;\n>  \tstruct user_fpsimd_state newstate =\n>  \t\ttarget->thread.fpsimd_state.user_fpsimd;\n>\n> -\tret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newstate, 0, -1);\n> +\tsve_sync_to_fpsimd(target);\n> +\n> +\tret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newstate,\n> +\t\t\t\t start_pos, start_pos + sizeof(newstate));\n>  \tif (ret)\n>  \t\treturn ret;\n>\n>  \ttarget->thread.fpsimd_state.user_fpsimd = newstate;\n> +\n> +\treturn ret;\n> +}\n> +\n> +static int fpr_set(struct task_struct *target, const struct user_regset *regset,\n> +\t\t   unsigned int pos, unsigned int count,\n> +\t\t   const void *kbuf, const void __user *ubuf)\n> +{\n> +\tint ret;\n> +\n> +\tret = __fpr_set(target, regset, pos, count, kbuf, ubuf, 0);\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n> +\tsve_sync_from_fpsimd_zeropad(target);\n>  \tfpsimd_flush_task_state(target);\n> +\n>  \treturn ret;\n>  }\n>\n> @@ -702,6 +737,210 @@ static int system_call_set(struct task_struct *target,\n>  \treturn ret;\n>  }\n>\n> +#ifdef CONFIG_ARM64_SVE\n> +\n> +static void sve_init_header_from_task(struct user_sve_header *header,\n> +\t\t\t\t      struct task_struct *target)\n> +{\n> +\tunsigned int vq;\n> +\n> +\tmemset(header, 0, sizeof(*header));\n> +\n> +\theader->flags = test_tsk_thread_flag(target, TIF_SVE) ?\n> +\t\tSVE_PT_REGS_SVE : SVE_PT_REGS_FPSIMD;\n> +\tif (test_tsk_thread_flag(target, TIF_SVE_VL_INHERIT))\n> +\t\theader->flags |= SVE_PT_VL_INHERIT;\n> +\n> +\theader->vl = target->thread.sve_vl;\n> +\tvq = sve_vq_from_vl(header->vl);\n> +\n> +\tif (WARN_ON(!sve_vl_valid(sve_max_vl)))\n> +\t\theader->max_vl = header->vl;\n> +\n> +\theader->size = SVE_PT_SIZE(vq, header->flags);\n> +\theader->max_size = SVE_PT_SIZE(sve_vq_from_vl(header->max_vl),\n> +\t\t\t\t      SVE_PT_REGS_SVE);\n> +}\n> +\n> +static unsigned int sve_size_from_header(struct user_sve_header const *header)\n> +{\n> +\treturn ALIGN(header->size, SVE_VQ_BYTES);\n> +}\n> +\n> +static unsigned int sve_get_size(struct task_struct *target,\n> +\t\t\t\t const struct user_regset *regset)\n> +{\n> +\tstruct user_sve_header header;\n> +\n> +\tif (!system_supports_sve())\n> +\t\treturn 0;\n> +\n> +\tsve_init_header_from_task(&header, target);\n> +\treturn sve_size_from_header(&header);\n> +}\n> +\n> +static int sve_get(struct task_struct *target,\n> +\t\t   const struct user_regset *regset,\n> +\t\t   unsigned int pos, unsigned int count,\n> +\t\t   void *kbuf, void __user *ubuf)\n> +{\n> +\tint ret;\n> +\tstruct user_sve_header header;\n> +\tunsigned int vq;\n> +\tunsigned long start, end;\n> +\n> +\tif (!system_supports_sve())\n> +\t\treturn -EINVAL;\n> +\n> +\t/* Header */\n> +\tsve_init_header_from_task(&header, target);\n> +\tvq = sve_vq_from_vl(header.vl);\n> +\n> +\tret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &header,\n> +\t\t\t\t  0, sizeof(header));\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n> +\tif (target == current)\n> +\t\tfpsimd_preserve_current_state();\n> +\n> +\t/* Registers: FPSIMD-only case */\n> +\n> +\tBUILD_BUG_ON(SVE_PT_FPSIMD_OFFSET != sizeof(header));\n> +\tif ((header.flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_FPSIMD)\n> +\t\treturn __fpr_get(target, regset, pos, count, kbuf, ubuf,\n> +\t\t\t\t SVE_PT_FPSIMD_OFFSET);\n> +\n> +\t/* Otherwise: full SVE case */\n> +\n> +\tBUILD_BUG_ON(SVE_PT_SVE_OFFSET != sizeof(header));\n> +\tstart = SVE_PT_SVE_OFFSET;\n> +\tend = SVE_PT_SVE_FFR_OFFSET(vq) + SVE_PT_SVE_FFR_SIZE(vq);\n> +\tret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,\n> +\t\t\t\t  target->thread.sve_state,\n> +\t\t\t\t  start, end);\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n> +\tstart = end;\n> +\tend = SVE_PT_SVE_FPSR_OFFSET(vq);\n> +\tret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,\n> +\t\t\t\t       start, end);\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n> +\t/*\n> +\t * Copy fpsr, and fpcr which must follow contiguously in\n> +\t * struct fpsimd_state:\n> +\t */\n> +\tstart = end;\n> +\tend = SVE_PT_SVE_FPCR_OFFSET(vq) + SVE_PT_SVE_FPCR_SIZE;\n> +\tret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,\n> +\t\t\t\t  &target->thread.fpsimd_state.fpsr,\n> +\t\t\t\t  start, end);\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n> +\tstart = end;\n> +\tend = sve_size_from_header(&header);\n> +\treturn user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,\n> +\t\t\t\t\tstart, end);\n> +}\n> +\n> +static int sve_set(struct task_struct *target,\n> +\t\t   const struct user_regset *regset,\n> +\t\t   unsigned int pos, unsigned int count,\n> +\t\t   const void *kbuf, const void __user *ubuf)\n> +{\n> +\tint ret;\n> +\tstruct user_sve_header header;\n> +\tunsigned int vq;\n> +\tunsigned long start, end;\n> +\n> +\tif (!system_supports_sve())\n> +\t\treturn -EINVAL;\n> +\n> +\t/* Header */\n> +\tif (count < sizeof(header))\n> +\t\treturn -EINVAL;\n> +\tret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &header,\n> +\t\t\t\t 0, sizeof(header));\n> +\tif (ret)\n> +\t\tgoto out;\n> +\n> +\t/*\n> +\t * Apart from PT_SVE_REGS_MASK, all PT_SVE_* flags are consumed by\n> +\t * sve_set_vector_length(), which will also validate them for us:\n> +\t */\n> +\tret = sve_set_vector_length(target, header.vl,\n> +\t\t\t\t    header.flags & ~SVE_PT_REGS_MASK);\n> +\tif (ret)\n> +\t\tgoto out;\n> +\n> +\t/* Actual VL set may be less than the user asked for: */\n> +\tvq = sve_vq_from_vl(target->thread.sve_vl);\n> +\n> +\t/* Registers: FPSIMD-only case */\n> +\n> +\tBUILD_BUG_ON(SVE_PT_FPSIMD_OFFSET != sizeof(header));\n> +\tif ((header.flags & SVE_PT_REGS_MASK) == SVE_PT_REGS_FPSIMD) {\n> +\t\tsve_sync_to_fpsimd(target);\n> +\n> +\t\tret = __fpr_set(target, regset, pos, count, kbuf, ubuf,\n> +\t\t\t\tSVE_PT_FPSIMD_OFFSET);\n> +\t\tclear_tsk_thread_flag(target, TIF_SVE);\n> +\t\tgoto out;\n> +\t}\n> +\n> +\t/* Otherwise: full SVE case */\n> +\n> +\t/*\n> +\t * If setting a different VL from the requested VL and there is\n> +\t * register data, the data layout will be wrong: don't even\n> +\t * try to set the registers in this case.\n> +\t */\n> +\tif (count && vq != sve_vq_from_vl(header.vl)) {\n> +\t\tret = -EIO;\n> +\t\tgoto out;\n> +\t}\n> +\n> +\tsve_alloc(target);\n> +\tfpsimd_sync_to_sve(target);\n> +\tset_tsk_thread_flag(target, TIF_SVE);\n> +\n> +\tBUILD_BUG_ON(SVE_PT_SVE_OFFSET != sizeof(header));\n> +\tstart = SVE_PT_SVE_OFFSET;\n> +\tend = SVE_PT_SVE_FFR_OFFSET(vq) + SVE_PT_SVE_FFR_SIZE(vq);\n> +\tret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,\n> +\t\t\t\t target->thread.sve_state,\n> +\t\t\t\t start, end);\n> +\tif (ret)\n> +\t\tgoto out;\n> +\n> +\tstart = end;\n> +\tend = SVE_PT_SVE_FPSR_OFFSET(vq);\n> +\tret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,\n> +\t\t\t\t\tstart, end);\n> +\tif (ret)\n> +\t\tgoto out;\n> +\n> +\t/*\n> +\t * Copy fpsr, and fpcr which must follow contiguously in\n> +\t * struct fpsimd_state:\n> +\t */\n> +\tstart = end;\n> +\tend = SVE_PT_SVE_FPCR_OFFSET(vq) + SVE_PT_SVE_FPCR_SIZE;\n> +\tret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,\n> +\t\t\t\t &target->thread.fpsimd_state.fpsr,\n> +\t\t\t\t start, end);\n> +\n> +out:\n> +\tfpsimd_flush_task_state(target);\n> +\treturn ret;\n> +}\n> +\n> +#endif /* CONFIG_ARM64_SVE */\n> +\n>  enum aarch64_regset {\n>  \tREGSET_GPR,\n>  \tREGSET_FPR,\n> @@ -711,6 +950,9 @@ enum aarch64_regset {\n>  \tREGSET_HW_WATCH,\n>  #endif\n>  \tREGSET_SYSTEM_CALL,\n> +#ifdef CONFIG_ARM64_SVE\n> +\tREGSET_SVE,\n> +#endif\n>  };\n>\n>  static const struct user_regset aarch64_regsets[] = {\n> @@ -768,6 +1010,18 @@ static const struct user_regset aarch64_regsets[] = {\n>  \t\t.get = system_call_get,\n>  \t\t.set = system_call_set,\n>  \t},\n> +#ifdef CONFIG_ARM64_SVE\n> +\t[REGSET_SVE] = { /* Scalable Vector Extension */\n> +\t\t.core_note_type = NT_ARM_SVE,\n> +\t\t.n = DIV_ROUND_UP(SVE_PT_SIZE(SVE_VQ_MAX, SVE_PT_REGS_SVE),\n> +\t\t\t\t  SVE_VQ_BYTES),\n> +\t\t.size = SVE_VQ_BYTES,\n> +\t\t.align = SVE_VQ_BYTES,\n> +\t\t.get = sve_get,\n> +\t\t.set = sve_set,\n> +\t\t.get_size = sve_get_size,\n> +\t},\n> +#endif\n>  };\n>\n>  static const struct user_regset_view user_aarch64_view = {\n> diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h\n> index b5280db..735b8f4 100644\n> --- a/include/uapi/linux/elf.h\n> +++ b/include/uapi/linux/elf.h\n> @@ -416,6 +416,7 @@ typedef struct elf64_shdr {\n>  #define NT_ARM_HW_BREAK\t0x402\t\t/* ARM hardware breakpoint registers */\n>  #define NT_ARM_HW_WATCH\t0x403\t\t/* ARM hardware watchpoint registers */\n>  #define NT_ARM_SYSTEM_CALL\t0x404\t/* ARM system call number */\n> +#define NT_ARM_SVE\t0x405\t\t/* ARM Scalable Vector Extension registers */\n>  #define NT_METAG_CBUF\t0x500\t\t/* Metag catch buffer registers */\n>  #define NT_METAG_RPIPE\t0x501\t\t/* Metag read pipeline state */\n>  #define NT_METAG_TLS\t0x502\t\t/* Metag TLS pointer */\n\nOtherwise:\n\nReviewed-by: Alex Bennée <alex.bennee@linaro.org>\n\n--\nAlex Bennée","headers":{"Return-Path":"<libc-alpha-return-84611-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-84611-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"O24C6uPb\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xtJTd3CLzz9s7f\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 14 Sep 2017 22:57:25 +1000 (AEST)","(qmail 24222 invoked by alias); 14 Sep 2017 12:57:17 -0000","(qmail 23376 invoked by uid 89); 14 Sep 2017 12:57:16 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:references:from:to:cc:subject:in-reply-to:date\n\t:message-id:mime-version:content-type:content-transfer-encoding;\n\tq=dns; s=default; b=H7WpUOz288ajL2EzTy8Oip9zNI0hfEJa699ASCQPYxL\n\tUS9pWkODkRrO9NdA7o2vZfg9mTJElGTVpqf5nXgOYZrVoZaqOf6IOjGSiMqsJD8C\n\tGz05Gf6MNXRqpnKs/a4SCRfaTDKko5C4Jn5EOfRGcL449SezieC2uTK7e3t7lQNw\n\t=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:references:from:to:cc:subject:in-reply-to:date\n\t:message-id:mime-version:content-type:content-transfer-encoding;\n\ts=default; bh=8ODGJlN6Z/j1pCX2o6bcebkX/YM=; b=O24C6uPbPwCZkA5Ei\n\t8TCDN2zFjQwwAuRytdGzHduZTy03Nl3gGfC5aypa9mXJm1OWu4+kpPx2cDZiSs/t\n\t5ZUaY++Vxy0M+IzHjMjvhh6nthDSUN2WiA0iKhuLIW9xhI/Q9e+8sQOk0D1ptzor\n\tUGZd0eGpqc4s2+hHPGxVbyZU+M=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.4 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tRCVD_IN_DNSWL_NONE,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=consumed","X-HELO":"mail-wm0-f49.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:references:user-agent:from:to:cc:subject\n\t:in-reply-to:date:message-id:mime-version:content-transfer-encoding; \n\tbh=kKTnha+9FxLFcgfhxQBTfMTsJ1GZCK77Z3kP38HX/yo=;\n\tb=qtSKw/ie01s72ZSPpixzEyi+yindak1jwtb5n5prxfErwWOIFnYTFno5jxV1hjO+WL\n\th/64X3VI97Gx3jD5L4F7v4WI3GcLeIZf/toz988pzAifA4KkU73FAU/k5tuzggJS9KWT\n\tO6tgY5JjArXBMSk0rl+armrRsJiQrVwFsm0YC6xrixSlkLJTiurerjglydzS5vYXpYkW\n\t83iagalX0x2lqyX9s8ogjQWGta3IBbDBmbrsphoLaxwW4rCN5+ywosMtqCcVGDNcLT1F\n\tfRJWaMMsfna9yKHIpcBW/ceBzWItIVjS0Q6+k7SbXtLwZnI+tQY8enSIKZorNxCpXMqH\n\t4pEA==","X-Gm-Message-State":"AHPjjUitHjgTKPPqQDcnQAIIS7xCjEqeQ3zvhwlGN/OWjdTMes1s4GIC\n\tUjtxAS5XVEZS55CU","X-Google-Smtp-Source":"AOwi7QCNa+pYNsrFr9pQ0iU2KtKzzES6XwmSFrjbFEitJKc2vvFVIzsMBT3TOugFSIZworONr93aoQ==","X-Received":"by 10.28.45.14 with SMTP id t14mr1903371wmt.50.1505393829924;\n\tThu, 14 Sep 2017 05:57:09 -0700 (PDT)","References":"<1504198860-12951-1-git-send-email-Dave.Martin@arm.com>\n\t<1504198860-12951-20-git-send-email-Dave.Martin@arm.com>","User-agent":"mu4e 0.9.19; emacs 25.2.50.3","From":"Alex =?utf-8?q?Benn=C3=A9e?= <alex.bennee@linaro.org>","To":"Dave Martin <Dave.Martin@arm.com>","Cc":"linux-arm-kernel@lists.infradead.org,\n\tCatalin Marinas <catalin.marinas@arm.com>,\n\tWill Deacon <will.deacon@arm.com>,\n\tArd Biesheuvel <ard.biesheuvel@linaro.org>,\n\tSzabolcs Nagy <szabolcs.nagy@arm.com>,\n\tRichard Sandiford <richard.sandiford@arm.com>,\n\tkvmarm@lists.cs.columbia.edu, libc-alpha@sourceware.org,\n\tlinux-arch@vger.kernel.org, gdb@sourceware.org,\n\tAlan Hayward <alan.hayward@arm.com>, Yao Qi <Yao.Qi@arm.com>,\n\tOleg Nesterov <oleg@redhat.com>, Alexander Viro <viro@zeniv.linux.org.uk>","Subject":"Re: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","In-reply-to":"<1504198860-12951-20-git-send-email-Dave.Martin@arm.com>","Date":"Thu, 14 Sep 2017 13:57:08 +0100","Message-ID":"<87bmmda15n.fsf@linaro.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"8bit"}},{"id":1777081,"web_url":"http://patchwork.ozlabs.org/comment/1777081/","msgid":"<20170928145717.GD3611@e103592.cambridge.arm.com>","list_archive_url":null,"date":"2017-09-28T14:57:18","subject":"Re: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","submitter":{"id":26612,"url":"http://patchwork.ozlabs.org/api/people/26612/","name":"Dave Martin","email":"Dave.Martin@arm.com"},"content":"On Thu, Sep 14, 2017 at 01:57:08PM +0100, Alex Bennée wrote:\n> \n> Dave Martin <Dave.Martin@arm.com> writes:\n> \n> > This patch defines and implements a new regset NT_ARM_SVE, which\n> > describes a thread's SVE register state.  This allows a debugger to\n> > manipulate the SVE state, as well as being included in ELF\n> > coredumps for post-mortem debugging.\n> >\n> > Because the regset size and layout are dependent on the thread's\n> > current vector length, it is not possible to define a C struct to\n> > describe the regset contents as is done for existing regsets.\n> > Instead, and for the same reasons, NT_ARM_SVE is based on the\n> > freeform variable-layout approach used for the SVE signal frame.\n> >\n> > Additionally, to reduce debug overhead when debugging threads that\n> > might or might not have live SVE register state, NT_ARM_SVE may be\n> > presented in one of two different formats: the old struct\n> > user_fpsimd_state format is embedded for describing the state of a\n> > thread with no live SVE state, whereas a new variable-layout\n> > structure is embedded for describing live SVE state.  This avoids a\n> > debugger needing to poll NT_PRFPREG in addition to NT_ARM_SVE, and\n> > allows existing userspace code to handle the non-SVE case without\n> > too much modification.\n> >\n> > For this to work, NT_ARM_SVE is defined with a fixed-format header\n> > of type struct user_sve_header, which the recipient can use to\n> > figure out the content, size and layout of the reset of the regset.\n> > Accessor macros are defined to allow the vector-length-dependent\n> > parts of the regset to be manipulated.\n> >\n> > Signed-off-by: Alan Hayward <alan.hayward@arm.com>\n> > Signed-off-by: Dave Martin <Dave.Martin@arm.com>\n> > Cc: Alex Bennée <alex.bennee@linaro.org>\n> >\n> > ---\n> >\n> > Changes since v1\n> > ----------------\n> >\n> > Other changes related to Alex Bennée's comments:\n> >\n> > * Migrate to SVE_VQ_BYTES instead of magic numbers.\n> >\n> > Requested by Alex Bennée:\n> >\n> > * Thin out BUG_ON()s:\n> > Redundant BUG_ON()s and ones that just check invariants are removed.\n> > Important sanity-checks are migrated to WARN_ON()s, with some\n> > minimal best-effort patch-up code.\n> >\n> > Other:\n> >\n> > * [ABI fix] Bail out with -EIO if attempting to set the\n> > SVE regs for an unsupported VL, instead of misparsing the regset data.\n> >\n> > * Replace some in-kernel open-coded arithmetic with ALIGN()/\n> > DIV_ROUND_UP().\n> > ---\n\n[...]\n\n> > diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h\n> > index d1ff83d..1915ab0 100644\n> > --- a/arch/arm64/include/uapi/asm/ptrace.h\n> > +++ b/arch/arm64/include/uapi/asm/ptrace.h\n> > @@ -22,6 +22,7 @@\n> >  #include <linux/types.h>\n> >\n> >  #include <asm/hwcap.h>\n> > +#include <asm/sigcontext.h>\n> >\n> >\n> >  /*\n> > @@ -63,6 +64,8 @@\n> >\n> >  #ifndef __ASSEMBLY__\n> >\n> > +#include <linux/prctl.h>\n> > +\n> >  /*\n> >   * User structures for general purpose, floating point and debug registers.\n> >   */\n> > @@ -90,6 +93,138 @@ struct user_hwdebug_state {\n> >  \t}\t\tdbg_regs[16];\n> >  };\n> >\n> > +/* SVE/FP/SIMD state (NT_ARM_SVE) */\n> > +\n> > +struct user_sve_header {\n> > +\t__u32 size; /* total meaningful regset content in bytes */\n> > +\t__u32 max_size; /* maxmium possible size for this thread */\n> > +\t__u16 vl; /* current vector length */\n> > +\t__u16 max_vl; /* maximum possible vector length */\n> > +\t__u16 flags;\n> > +\t__u16 __reserved;\n> > +};\n> > +\n> > +/* Definitions for user_sve_header.flags: */\n> > +#define SVE_PT_REGS_MASK\t\t(1 << 0)\n> > +\n> > +/* Flags: must be kept in sync with prctl interface in\n> > <linux/ptrace.h> */\n> \n> Which flags? We base some on PR_foo flags but we seem to shift them\n\nAll the prctl flags that have equivalents here, because they're part of\nthe internal API to sve_set_vector_length().  It didn't quite seem\nappropriate to document that in a userspace header, but it's probably\nbetter to say something here than not.  I'll improve the comment.\n\n> anyway so where is the requirement for them to match from?\n\nThere is a bug here though: sve_set() in ptrace.c is supposed to shift\nthe flags from header.flags (which is a u16) back into the\nPR_SVE_SET_VL position (<< 16) for the flags argument of\nsve_set_vector_length().  But this isn't done, so attempting to set (or\nrestore) those flags through ptrace may resulting EINVALs from\nsve_set_vector_length().\n\nI'll write a test for this case and implement a fix, something like...\n\n-8<-\n\n static int sve_set(struct task_struct *target,\n[...]\n \tret = sve_set_vector_length(target, header.vl,\n-\t\t\t\t    header.flags & ~SVE_PT_REGS_MASK);\n+\t\t\t\t    (header.flags & ~SVE_PT_REGS_MASK) << 16UL);\n\n\n->8-\n\nWhat do you think?\n\n[...]\n\n> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>\n\nAgain, I'll wait for your feedback first.\n\nCheers\n---Dave","headers":{"Return-Path":"<libc-alpha-return-85078-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-85078-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"sd1k992o\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y2yTr052cz9t66\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 29 Sep 2017 00:57:35 +1000 (AEST)","(qmail 109512 invoked by alias); 28 Sep 2017 14:57:28 -0000","(qmail 109484 invoked by uid 89); 28 Sep 2017 14:57:27 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-type:content-transfer-encoding\n\t:in-reply-to; q=dns; s=default; b=pItcKqeYyRIG2K63RQ0Yvbkpdvpk7Q\n\tTJ5lUxkizBsOSLHSriCl2UpbWVme9C9rHJG9Q6vMMSMpEGcielgw1Ks3iLFIgggu\n\tifA+te2hBdCRpauQ8wMnR8UlvQhqTMQDqtRlstjkiPcKxn/LMZgxH6HbZN2F0Dsh\n\tPsXC7zSyTh8Cc=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-type:content-transfer-encoding\n\t:in-reply-to; s=default; bh=El5Ms1sAIVHKbY7to8rlj8W1X+w=; b=sd1k\n\t992oEwJbm3Ca9j+2/1ERMyBPx3abzFt8qHQDnVGnXIOJokNISeE4sYpg73juXqjU\n\tqrqMRKonhscmCG5adxKQ2i9HOX1AZDnkCImvCwuzGvqPWY5TsSxK0GBrU0FFCEB2\n\tFj44uoNNodfMtHjhvdddh87I8ZpwgdYrp2Cd8oQ=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=08pm, 08PM","X-Spam-User":"qpsmtpd, 2 recipients","X-HELO":"foss.arm.com","Date":"Thu, 28 Sep 2017 15:57:18 +0100","From":"Dave Martin <Dave.Martin@arm.com>","To":"Alex =?iso-8859-1?q?Benn=E9e?= <alex.bennee@linaro.org>","Cc":"linux-arch@vger.kernel.org, libc-alpha@sourceware.org,\n\tgdb@sourceware.org, Ard Biesheuvel <ard.biesheuvel@linaro.org>,\n\tSzabolcs Nagy <szabolcs.nagy@arm.com>,\n\tCatalin Marinas <catalin.marinas@arm.com>, Yao Qi <Yao.Qi@arm.com>,\n\tAlan Hayward <alan.hayward@arm.com>,\n\tWill Deacon <will.deacon@arm.com>, Oleg Nesterov <oleg@redhat.com>,\n\tAlexander Viro <viro@zeniv.linux.org.uk>,\n\tRichard Sandiford <richard.sandiford@arm.com>,\n\tkvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org","Subject":"Re: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","Message-ID":"<20170928145717.GD3611@e103592.cambridge.arm.com>","References":"<1504198860-12951-1-git-send-email-Dave.Martin@arm.com>\n\t<1504198860-12951-20-git-send-email-Dave.Martin@arm.com>\n\t<87bmmda15n.fsf@linaro.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<87bmmda15n.fsf@linaro.org>","User-Agent":"Mutt/1.5.23 (2014-03-12)"}},{"id":1777520,"web_url":"http://patchwork.ozlabs.org/comment/1777520/","msgid":"<20170929124605.GF3611@e103592.cambridge.arm.com>","list_archive_url":null,"date":"2017-09-29T12:46:06","subject":"Re: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","submitter":{"id":26612,"url":"http://patchwork.ozlabs.org/api/people/26612/","name":"Dave Martin","email":"Dave.Martin@arm.com"},"content":"On Thu, Sep 14, 2017 at 01:57:08PM +0100, Alex Bennée wrote:\n> \n> Dave Martin <Dave.Martin@arm.com> writes:\n> \n> > This patch defines and implements a new regset NT_ARM_SVE, which\n> > describes a thread's SVE register state.  This allows a debugger to\n> > manipulate the SVE state, as well as being included in ELF\n> > coredumps for post-mortem debugging.\n> >\n> > Because the regset size and layout are dependent on the thread's\n> > current vector length, it is not possible to define a C struct to\n> > describe the regset contents as is done for existing regsets.\n> > Instead, and for the same reasons, NT_ARM_SVE is based on the\n> > freeform variable-layout approach used for the SVE signal frame.\n> >\n> > Additionally, to reduce debug overhead when debugging threads that\n> > might or might not have live SVE register state, NT_ARM_SVE may be\n> > presented in one of two different formats: the old struct\n> > user_fpsimd_state format is embedded for describing the state of a\n> > thread with no live SVE state, whereas a new variable-layout\n> > structure is embedded for describing live SVE state.  This avoids a\n> > debugger needing to poll NT_PRFPREG in addition to NT_ARM_SVE, and\n> > allows existing userspace code to handle the non-SVE case without\n> > too much modification.\n> >\n> > For this to work, NT_ARM_SVE is defined with a fixed-format header\n> > of type struct user_sve_header, which the recipient can use to\n> > figure out the content, size and layout of the reset of the regset.\n> > Accessor macros are defined to allow the vector-length-dependent\n> > parts of the regset to be manipulated.\n> >\n> > Signed-off-by: Alan Hayward <alan.hayward@arm.com>\n> > Signed-off-by: Dave Martin <Dave.Martin@arm.com>\n> > Cc: Alex Bennée <alex.bennee@linaro.org>\n> >\n> > ---\n> >\n> > Changes since v1\n> > ----------------\n> >\n> > Other changes related to Alex Bennée's comments:\n> >\n> > * Migrate to SVE_VQ_BYTES instead of magic numbers.\n> >\n> > Requested by Alex Bennée:\n> >\n> > * Thin out BUG_ON()s:\n> > Redundant BUG_ON()s and ones that just check invariants are removed.\n> > Important sanity-checks are migrated to WARN_ON()s, with some\n> > minimal best-effort patch-up code.\n> >\n> > Other:\n> >\n> > * [ABI fix] Bail out with -EIO if attempting to set the\n> > SVE regs for an unsupported VL, instead of misparsing the regset data.\n> >\n> > * Replace some in-kernel open-coded arithmetic with ALIGN()/\n> > DIV_ROUND_UP().\n> > ---\n\n[...]\n\n> > diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h\n\n[...]\n\n> > +/* Definitions for user_sve_header.flags: */\n> > +#define SVE_PT_REGS_MASK\t\t(1 << 0)\n> > +\n> > +/* Flags: must be kept in sync with prctl interface in\n> > <linux/ptrace.h> */\n> \n> Which flags? We base some on PR_foo flags but we seem to shift them\n> anyway so where is the requirement for them to match from?\n\nI've rearranged this as:\n\n-8<-\n\n/* Definitions for user_sve_header.flags: */\n#define SVE_PT_REGS_MASK\t\t(1 << 0)\n\n#define SVE_PT_REGS_FPSIMD\t\t0\n#define SVE_PT_REGS_SVE\t\t\tSVE_PT_REGS_MASK\n\n/*\n * Common SVE_PT_* flags:\n * These must be kept in sync with prctl interface in <linux/ptrace.h>\n */\n#define SVE_PT_VL_INHERIT\t\t(PR_SVE_VL_INHERIT >> 16)\n#define SVE_PT_VL_ONEXEC\t\t(PR_SVE_SET_VL_ONEXEC >> 16)\n\n->8-\n\nThis avoids the suggestion that SVE_PT_REGS_{MASK,FPSIMD,SVE} are\nsupposed to have prctl counterparts.\n\nI don't really want to write more, in case it is misinterpreted as\nspecification of behaviour.\n\nThis comment is really only meant as a reminder to maintainers that\nthey should go look at prctl.h too, before blindly making changes\nhere.\n\n\nAny good?  If you have a different suggestion, I'm all ears...\n\n[...]\n\nCheers\n---Dave","headers":{"Return-Path":"<libc-alpha-return-85109-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-85109-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"fn5pJhls\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y3WWz4vSGz9t4R\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 29 Sep 2017 22:46:23 +1000 (AEST)","(qmail 4585 invoked by alias); 29 Sep 2017 12:46:14 -0000","(qmail 4310 invoked by uid 89); 29 Sep 2017 12:46:14 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-type:content-transfer-encoding\n\t:in-reply-to; q=dns; s=default; b=hDAP96XZBTtLPY6kIuSBfx8I6iud8H\n\tSrnhzKRkFmpbsP7ejTD9Gy7X2xdnJm1hwKZT2DBaPSikbOOw1liUdM51rUFgjY7W\n\tb3d4kEK76raXcXeJuIMjFwZmPPK7WCFYlwMyhwJlKyfhWdRG+kyOjFRWF3Q9aaTG\n\tMdp6VxHLDMyYM=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-type:content-transfer-encoding\n\t:in-reply-to; s=default; bh=B+5Z23FEli8kicQC5YVWMTrpU7Q=; b=fn5p\n\tJhlsGeLaqFOpirYOXKotUxQYFcMvBnF4z9KVQKDqaFtyCEcUZhzmgwQAdztLYbTQ\n\t5vJbzZn6xL8BeS5NYu5AhjVjVBEidR8fe5B+eKALT7ZoiCeFsGPuP5dU/AZURVav\n\tm8COrl5d+C0X37avcT2f2iV4HoKtDKIWQTEligY=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-16.9 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_2, RP_MATCHES_RCVD,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=ears,\n\tH*Ad:D*org.uk","X-Spam-User":"qpsmtpd, 2 recipients","X-HELO":"foss.arm.com","Date":"Fri, 29 Sep 2017 13:46:06 +0100","From":"Dave Martin <Dave.Martin@arm.com>","To":"Alex =?iso-8859-1?q?Benn=E9e?= <alex.bennee@linaro.org>","Cc":"linux-arch@vger.kernel.org, libc-alpha@sourceware.org,\n\tgdb@sourceware.org, Ard Biesheuvel <ard.biesheuvel@linaro.org>,\n\tSzabolcs Nagy <szabolcs.nagy@arm.com>,\n\tCatalin Marinas <catalin.marinas@arm.com>, Yao Qi <Yao.Qi@arm.com>,\n\tAlan Hayward <alan.hayward@arm.com>,\n\tWill Deacon <will.deacon@arm.com>, Oleg Nesterov <oleg@redhat.com>,\n\tAlexander Viro <viro@zeniv.linux.org.uk>,\n\tRichard Sandiford <richard.sandiford@arm.com>,\n\tkvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org","Subject":"Re: [PATCH v2 19/28] arm64/sve: ptrace and ELF coredump support","Message-ID":"<20170929124605.GF3611@e103592.cambridge.arm.com>","References":"<1504198860-12951-1-git-send-email-Dave.Martin@arm.com>\n\t<1504198860-12951-20-git-send-email-Dave.Martin@arm.com>\n\t<87bmmda15n.fsf@linaro.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<87bmmda15n.fsf@linaro.org>","User-Agent":"Mutt/1.5.23 (2014-03-12)"}}]