ptrace/x86: Partly fix set_task_blockstep()->update_debugctlmsr() logic
Oleg Nesterov authored
Afaics the usage of update_debugctlmsr() and TIF_BLOCKSTEP in
step.c was always very wrong.

1. update_debugctlmsr() was simply unneeded. The child sleeps
   TASK_TRACED, __switch_to_xtra(next_p => child) should notice
   TIF_BLOCKSTEP and set/clear DEBUGCTLMSR_BTF after resume if
   needed.

2. It is wrong. The state of DEBUGCTLMSR_BTF bit in CPU register
   should always match the state of current's TIF_BLOCKSTEP bit.

3. Even get_debugctlmsr() + update_debugctlmsr() itself does not
   look right. Irq can change other bits in MSR_IA32_DEBUGCTLMSR
   register or the caller can be preempted in between.

4. It is not safe to play with TIF_BLOCKSTEP if task != current.
   DEBUGCTLMSR_BTF and TIF_BLOCKSTEP should always match each
   other if the task is running. The tracee is stopped but it
   can be SIGKILL'ed right before set/clear_tsk_thread_flag().

However, now that uprobes uses user_enable_single_step(current)
we can't simply remove update_debugctlmsr(). So this patch adds
the additional "task == current" check and disables irqs to avoid
the race with interrupts/preemption.

Unfortunately this patch doesn't solve the last problem, we need
another fix. Probably we should teach ptrace_stop() to set/clear
single/block stepping after resume.

And afaics there is yet another problem: perf can play with
MSR_IA32_DEBUGCTLMSR from nmi, this obviously means that even
__switch_to_xtra() has problems.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
95cf00fa
Name Last commit Last update
..
alpha alpha: Fix fall-out from disintegrating asm/system.h
arm Merge tag 'fixes-3.6-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
avr32 ipc: use Kconfig options for __ARCH_WANT_[COMPAT_]IPC_PARSE_VERSION
blackfin Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k
c6x Merge tag 'for-linus' of git://linux-c6x.org/git/projects/linux-c6x-upstreaming
cris ipc: use Kconfig options for __ARCH_WANT_[COMPAT_]IPC_PARSE_VERSION
frv Merge branch 'akpm' (Andrew's patch-bomb)
h8300 ipc: use Kconfig options for __ARCH_WANT_[COMPAT_]IPC_PARSE_VERSION
hexagon Merge branch 'trivial' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
ia64 [IA64] defconfig: Remove CONFIG_MISC_DEVICES
m32r ipc: use Kconfig options for __ARCH_WANT_[COMPAT_]IPC_PARSE_VERSION
m68k m68k: select CONFIG_GENERIC_ATOMIC64 for all m68k CPU types
microblaze Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k
mips MIPS: pci-ar724x: avoid data bus error due to a missing PCIe module
mn10300 Merge branch 'akpm' (Andrew's patch-bomb)
openrisc Remove useless wrappers of asm-generic/rmap.h
parisc Merge tag 'for-3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci
powerpc Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
s390 s390/compat: fix mmap compat system calls
score new helper: signal_delivered()
sh Merge branches 'sh/urgent' and 'sh/gpiolib' into sh-latest
sparc sparc64: Be less verbose during vmemmap population.
tile memcg: rename config variables
um Merge branch 'for-linus-3.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/uml
unicore32 Merge tag 'for-3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci
x86 ptrace/x86: Partly fix set_task_blockstep()->update_debugctlmsr() logic
xtensa xtensa: select generic atomic64_t support
.gitignore arch: Ignore arch/i386 and arch/x86_64
Kconfig perf: Add ability to attach user stack dump to sample