Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arch/tile: clean up tile-specific PTRACE_SETOPTIONS

Use the newer idioms for setting PTRACE_O_xxx and PT_TRACE_xxx flags.
Only set/clear tile-specific flags if the generic routine returns
success, since otherwise we want to avoid setting any flags at all.
Atomically update the ptrace flags with the new values. Eliminate
the PT_TRACE_MASK_TILE bitmask and just shift PTRACE_O_MASK_TILE.
Add a BUILD_BUG_ON to avoid overlapping with generic bits.

Acked-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>

+9 -6
+1 -2
arch/tile/include/asm/ptrace.h
··· 24 24 #include <uapi/asm/ptrace.h> 25 25 26 26 #define PTRACE_O_MASK_TILE (PTRACE_O_TRACEMIGRATE) 27 - #define PT_TRACE_MIGRATE 0x00080000 28 - #define PT_TRACE_MASK_TILE (PT_TRACE_MIGRATE) 27 + #define PT_TRACE_MIGRATE PT_EVENT_FLAG(PTRACE_EVENT_MIGRATE) 29 28 30 29 /* Flag bits in pt_regs.flags */ 31 30 #define PT_FLAGS_DISABLE_IRQ 1 /* on return to kernel, disable irqs */
+1 -1
arch/tile/include/uapi/asm/ptrace.h
··· 81 81 #define PTRACE_SETFPREGS 15 82 82 83 83 /* Support TILE-specific ptrace options, with events starting at 16. */ 84 - #define PTRACE_O_TRACEMIGRATE 0x00010000 85 84 #define PTRACE_EVENT_MIGRATE 16 85 + #define PTRACE_O_TRACEMIGRATE (1 << PTRACE_EVENT_MIGRATE) 86 86 87 87 /* 88 88 * Flag bits in pt_regs.flags that are part of the ptrace API.
+7 -3
arch/tile/kernel/ptrace.c
··· 151 151 152 152 case PTRACE_SETOPTIONS: 153 153 /* Support TILE-specific ptrace options. */ 154 - child->ptrace &= ~PT_TRACE_MASK_TILE; 154 + BUILD_BUG_ON(PTRACE_O_MASK_TILE & PTRACE_O_MASK); 155 155 tmp = data & PTRACE_O_MASK_TILE; 156 156 data &= ~PTRACE_O_MASK_TILE; 157 157 ret = ptrace_request(child, request, addr, data); 158 - if (tmp & PTRACE_O_TRACEMIGRATE) 159 - child->ptrace |= PT_TRACE_MIGRATE; 158 + if (ret == 0) { 159 + unsigned int flags = child->ptrace; 160 + flags &= ~(PTRACE_O_MASK_TILE << PT_OPT_FLAG_SHIFT); 161 + flags |= (tmp << PT_OPT_FLAG_SHIFT); 162 + child->ptrace = flags; 163 + } 160 164 break; 161 165 162 166 default: