All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
	Anton Arapov <anton@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Roland McGrath <roland@hack.frob.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] ptrace: fix set_task_blockstep()->update_debugctlmsr() logic
Date: Fri, 3 Aug 2012 18:29:54 +0200	[thread overview]
Message-ID: <20120803162954.GA19806@redhat.com> (raw)
In-Reply-To: <20120803162912.GA19767@redhat.com>

Afaics the usage of update_debugctlmsr() 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.

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.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 arch/x86/kernel/step.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
index afa60db..636402e 100644
--- a/arch/x86/kernel/step.c
+++ b/arch/x86/kernel/step.c
@@ -166,12 +166,18 @@ static void set_task_blockstep(struct task_struct *task, bool on)
 	else
 		clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
 
+	if (task != current)
+		return;
+
+	/* ensure irq/preemption can't change debugctl in between */
+	local_irq_disable();
 	debugctl = get_debugctlmsr();
 	if (on)
 		debugctl |= DEBUGCTLMSR_BTF;
 	else
 		debugctl &= ~DEBUGCTLMSR_BTF;
 	update_debugctlmsr(debugctl);
+	local_irq_enable();
 }
 
 /*
-- 
1.5.5.1


  parent reply	other threads:[~2012-08-03 16:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-03 16:29 [PATCH 0/2] ptrace: DEBUGCTLMSR_BTF fixes Oleg Nesterov
2012-08-03 16:29 ` [PATCH 1/2] ptrace: introduce set_task_blockstep() helper Oleg Nesterov
2012-08-03 16:29 ` Oleg Nesterov [this message]
2012-08-03 16:43   ` [PATCH 2/2] ptrace: fix set_task_blockstep()->update_debugctlmsr() logic Sebastian Andrzej Siewior
2012-08-03 17:38     ` Oleg Nesterov
2012-08-03 18:28       ` Sebastian Andrzej Siewior
2012-08-07 15:13         ` Oleg Nesterov
2012-08-07  9:41   ` Sebastian Andrzej Siewior
2012-08-07 10:52     ` Sebastian Andrzej Siewior
2012-08-07 15:15     ` Oleg Nesterov
2012-08-07 15:29       ` Sebastian Andrzej Siewior
2012-08-07 15:31         ` Oleg Nesterov
2012-08-07 15:12   ` Oleg Nesterov
2012-08-06 16:14 ` [PATCH 0/2] ptrace: DEBUGCTLMSR_BTF fixes Sebastian Andrzej Siewior
2012-08-07 15:15   ` Oleg Nesterov
2012-08-07 15:38     ` Sebastian Andrzej Siewior
2012-08-07 15:46       ` Oleg Nesterov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120803162954.GA19806@redhat.com \
    --to=oleg@redhat.com \
    --cc=ananth@in.ibm.com \
    --cc=anton@redhat.com \
    --cc=bigeasy@linutronix.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=roland@hack.frob.com \
    --cc=srikar@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.