mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Metzger <markus.t.metzger@intel.com>
To: linux-kernel@vger.kernel.org, mingo@elte.hu, tglx@linutronix.de,
	hpa@zytor.com
Cc: markus.t.metzger@intel.com, markus.t.metzger@gmail.com,
	roland@redhat.com, eranian@googlemail.com, oleg@redhat.com,
	juan.villacis@intel.com, ak@linux.jf.intel.com
Subject: [patch 1/21] x86, bts: fix race when bts tracer is removed
Date: Tue, 31 Mar 2009 14:50:51 +0200	[thread overview]
Message-ID: <20090331145051.A12111@sedona.ch.intel.com> (raw)

When the bts tracer is removed while the traced task is running,
the write to clear the bts tracer pointer races with context switch code.

Read the tracer once during a context switch.


When a new tracer is installed, the bts tracer is set in the ds context
before the tracer is initialized in order to claim the context for that
tracer.
This may result in write accesses using an uninitialized trace configuration
when scheduling timestamps have been requested.

Store active tracing flags separately and only set active flags after
the tracing configuration has been initialized.


Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
---

Index: git-tip/arch/x86/kernel/ds.c
===================================================================
--- git-tip.orig/arch/x86/kernel/ds.c	2009-03-30 17:47:21.000000000 +0200
+++ git-tip/arch/x86/kernel/ds.c	2009-03-30 17:48:31.000000000 +0200
@@ -89,6 +89,9 @@ struct bts_tracer {
 
 	/* Buffer overflow notification function: */
 	bts_ovfl_callback_t	ovfl;
+
+	/* Active flags affecting trace collection. */
+	unsigned int		flags;
 };
 
 struct pebs_tracer {
@@ -799,6 +802,8 @@ void ds_suspend_bts(struct bts_tracer *t
 	if (!tracer)
 		return;
 
+	tracer->flags = 0;
+
 	task = tracer->ds.context->task;
 
 	if (!task || (task == current))
@@ -820,6 +825,8 @@ void ds_resume_bts(struct bts_tracer *tr
 	if (!tracer)
 		return;
 
+	tracer->flags = tracer->trace.ds.flags;
+
 	task = tracer->ds.context->task;
 
 	control = ds_cfg.ctl[dsf_bts];
@@ -1044,36 +1051,39 @@ void ds_switch_to(struct task_struct *pr
 {
 	struct ds_context *prev_ctx = prev->thread.ds_ctx;
 	struct ds_context *next_ctx = next->thread.ds_ctx;
+	unsigned long debugctlmsr = next->thread.debugctlmsr;
 
 	if (prev_ctx) {
+		struct bts_tracer *tracer = prev_ctx->bts_master;
+
 		update_debugctlmsr(0);
 
-		if (prev_ctx->bts_master &&
-		    (prev_ctx->bts_master->trace.ds.flags & BTS_TIMESTAMPS)) {
+		if (tracer && (tracer->flags & BTS_TIMESTAMPS)) {
 			struct bts_struct ts = {
 				.qualifier = bts_task_departs,
 				.variant.timestamp.jiffies = jiffies_64,
 				.variant.timestamp.pid = prev->pid
 			};
-			bts_write(prev_ctx->bts_master, &ts);
+			bts_write(tracer, &ts);
 		}
 	}
 
 	if (next_ctx) {
-		if (next_ctx->bts_master &&
-		    (next_ctx->bts_master->trace.ds.flags & BTS_TIMESTAMPS)) {
+		struct bts_tracer *tracer = next_ctx->bts_master;
+
+		if (tracer && (tracer->flags & BTS_TIMESTAMPS)) {
 			struct bts_struct ts = {
 				.qualifier = bts_task_arrives,
 				.variant.timestamp.jiffies = jiffies_64,
 				.variant.timestamp.pid = next->pid
 			};
-			bts_write(next_ctx->bts_master, &ts);
+			bts_write(tracer, &ts);
 		}
 
 		wrmsrl(MSR_IA32_DS_AREA, (unsigned long)next_ctx->ds);
 	}
 
-	update_debugctlmsr(next->thread.debugctlmsr);
+	update_debugctlmsr(debugctlmsr);
 }
 
 void ds_copy_thread(struct task_struct *tsk, struct task_struct *father)
---------------------------------------------------------------------
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen Germany
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456 Ust.-IdNr.
VAT Registration No.: DE129385895
Citibank Frankfurt (BLZ 502 109 00) 600119052

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


             reply	other threads:[~2009-03-31 13:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-31 12:50 Markus Metzger [this message]
2009-03-31 23:48 ` Oleg Nesterov
2009-04-01  8:10   ` Metzger, Markus T
2009-04-01 11:34     ` Ingo Molnar

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=20090331145051.A12111@sedona.ch.intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=ak@linux.jf.intel.com \
    --cc=eranian@googlemail.com \
    --cc=hpa@zytor.com \
    --cc=juan.villacis@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markus.t.metzger@gmail.com \
    --cc=mingo@elte.hu \
    --cc=oleg@redhat.com \
    --cc=roland@redhat.com \
    --cc=tglx@linutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®