]> Pileus Git - ~andy/linux/commitdiff
s390/ptrace: PTRACE_TE_ABORT_RAND
authorMichael Mueller <mimu@linux.vnet.ibm.com>
Tue, 2 Jul 2013 20:58:26 +0000 (22:58 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Tue, 16 Jul 2013 10:21:56 +0000 (12:21 +0200)
The patch implements a s390 specific ptrace request
PTRACE_TE_ABORT_RAND to modify the randomness of spontaneous
aborts of memory transactions of the transaction execution
facility. The data argument of the ptrace request is used to
specify the levels of randomness, 0 for normal operation, 1 to
abort every transaction at a random instruction, and 2 to abort
a random transaction at a random instruction. The default is 0
for normal operation.

Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Michael Mueller <mimu@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
arch/s390/include/asm/processor.h
arch/s390/include/asm/switch_to.h
arch/s390/include/uapi/asm/ptrace.h
arch/s390/kernel/ptrace.c

index 6b499870662f2dddbb14dd613943ef10e6303b89..b0e6435b2f02195e60303a9c46f0c199220c5225 100644 (file)
@@ -91,7 +91,15 @@ struct thread_struct {
 #endif
 };
 
-#define PER_FLAG_NO_TE         1UL     /* Flag to disable transactions. */
+/* Flag to disable transactions. */
+#define PER_FLAG_NO_TE                 1UL
+/* Flag to enable random transaction aborts. */
+#define PER_FLAG_TE_ABORT_RAND         2UL
+/* Flag to specify random transaction abort mode:
+ * - abort each transaction at a random instruction before TEND if set.
+ * - abort random transactions at a random instruction if cleared.
+ */
+#define PER_FLAG_TE_ABORT_RAND_TEND    4UL
 
 typedef struct thread_struct thread_struct;
 
index f3a9e0f9270451056c674f854d49bbcd0817ea25..80b6f11263c456233a6defaac28fd502bc7ad9f4 100644 (file)
@@ -10,7 +10,7 @@
 #include <linux/thread_info.h>
 
 extern struct task_struct *__switch_to(void *, void *);
-extern void update_per_regs(struct task_struct *task);
+extern void update_cr_regs(struct task_struct *task);
 
 static inline void save_fp_regs(s390_fp_regs *fpregs)
 {
@@ -86,7 +86,7 @@ static inline void restore_access_regs(unsigned int *acrs)
                restore_fp_regs(&next->thread.fp_regs);                 \
                restore_access_regs(&next->thread.acrs[0]);             \
                restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb);  \
-               update_per_regs(next);                                  \
+               update_cr_regs(next);                                   \
        }                                                               \
        prev = __switch_to(prev,next);                                  \
 } while (0)
index 3aa9f1ec5b295f0c530998610d04fa7de34dc93f..7a84619e315e804af6d7c6a535c4df7981e082e3 100644 (file)
@@ -400,6 +400,7 @@ typedef struct
 #define PTRACE_POKE_SYSTEM_CALL              0x5008
 #define PTRACE_ENABLE_TE             0x5009
 #define PTRACE_DISABLE_TE            0x5010
+#define PTRACE_TE_ABORT_RAND         0x5011
 
 /*
  * PT_PROT definition is loosely based on hppa bsd definition in
index a314c57f4e94a5a91c162de68360556babd71f8a..e9fadb04e3c61e0b71b6eb238a12941359edba0d 100644 (file)
@@ -47,7 +47,7 @@ enum s390_regset {
        REGSET_GENERAL_EXTENDED,
 };
 
-void update_per_regs(struct task_struct *task)
+void update_cr_regs(struct task_struct *task)
 {
        struct pt_regs *regs = task_pt_regs(task);
        struct thread_struct *thread = &task->thread;
@@ -56,17 +56,25 @@ void update_per_regs(struct task_struct *task)
 #ifdef CONFIG_64BIT
        /* Take care of the enable/disable of transactional execution. */
        if (MACHINE_HAS_TE) {
-               unsigned long cr0, cr0_new;
+               unsigned long cr[3], cr_new[3];
 
-               __ctl_store(cr0, 0, 0);
-               /* set or clear transaction execution bits 8 and 9. */
+               __ctl_store(cr, 0, 2);
+               cr_new[1] = cr[1];
+               /* Set or clear transaction execution TXC/PIFO bits 8 and 9. */
                if (task->thread.per_flags & PER_FLAG_NO_TE)
-                       cr0_new = cr0 & ~(3UL << 54);
+                       cr_new[0] = cr[0] & ~(3UL << 54);
                else
-                       cr0_new = cr0 | (3UL << 54);
-               /* Only load control register 0 if necessary. */
-               if (cr0 != cr0_new)
-                       __ctl_load(cr0_new, 0, 0);
+                       cr_new[0] = cr[0] | (3UL << 54);
+               /* Set or clear transaction execution TDC bits 62 and 63. */
+               cr_new[2] = cr[2] & ~3UL;
+               if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND) {
+                       if (task->thread.per_flags & PER_FLAG_TE_ABORT_RAND_TEND)
+                               cr_new[2] |= 1UL;
+                       else
+                               cr_new[2] |= 2UL;
+               }
+               if (memcmp(&cr_new, &cr, sizeof(cr)))
+                       __ctl_load(cr_new, 0, 2);
        }
 #endif
        /* Copy user specified PER registers */
@@ -100,14 +108,14 @@ void user_enable_single_step(struct task_struct *task)
 {
        set_tsk_thread_flag(task, TIF_SINGLE_STEP);
        if (task == current)
-               update_per_regs(task);
+               update_cr_regs(task);
 }
 
 void user_disable_single_step(struct task_struct *task)
 {
        clear_tsk_thread_flag(task, TIF_SINGLE_STEP);
        if (task == current)
-               update_per_regs(task);
+               update_cr_regs(task);
 }
 
 /*
@@ -447,6 +455,26 @@ long arch_ptrace(struct task_struct *child, long request,
                if (!MACHINE_HAS_TE)
                        return -EIO;
                child->thread.per_flags |= PER_FLAG_NO_TE;
+               child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
+               return 0;
+       case PTRACE_TE_ABORT_RAND:
+               if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE))
+                       return -EIO;
+               switch (data) {
+               case 0UL:
+                       child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND;
+                       break;
+               case 1UL:
+                       child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
+                       child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND_TEND;
+                       break;
+               case 2UL:
+                       child->thread.per_flags |= PER_FLAG_TE_ABORT_RAND;
+                       child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND_TEND;
+                       break;
+               default:
+                       return -EINVAL;
+               }
                return 0;
        default:
                /* Removing high order bit from addr (only for 31 bit). */