Skip to contentSkip to conversation

x86, bts: clear bts bits on fork

PATCH Applied Markus Metzger 2 participants 2 messages Dec 16, 2008

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 x86, bts: clear bts bits on fork

Clear the DS context as well as the bts tracer and corresponding fields in task_struct on fork.

Correct the CONFIG guard.

---

arch/x86/kernel/process_32.c +13 -2
Index: ftrace/arch/x86/kernel/process_32.c
===================================================================
@@ -251,7 +251,7 @@
 		tss->x86_tss.io_bitmap_base = INVALID_IO_BITMAP_OFFSET;
 		put_cpu();
 	}
-#ifdef CONFIG_X86_DS
+#ifdef CONFIG_X86_PTRACE_BTS
 	/* Free any BTS tracers that have not been properly released. */
 	if (unlikely(current->bts)) {
 		ds_release_bts(current->bts);
@@ -261,7 +261,7 @@
 		current->bts_buffer = NULL;
 		current->bts_size = 0;
 	}
-#endif /* CONFIG_X86_DS */
+#endif /* CONFIG_X86_PTRACE_BTS */
 }
 
 void flush_thread(void)
@@ -343,6 +343,17 @@
 		kfree(p->thread.io_bitmap_ptr);
 		p->thread.io_bitmap_max = 0;
 	}
+
+#ifdef CONFIG_X86_DS
+	clear_tsk_thread_flag(p, TIF_DS_AREA_MSR);
+	p->thread.ds_ctx = NULL;
+#endif
+#ifdef CONFIG_X86_PTRACE_BTS
+	p->thread.bts_ovfl_signal = 0;
+#endif
+	clear_tsk_thread_flag(p, TIF_DEBUGCTLMSR);
+	p->thread.debugctlmsr = 0;
+
 	return err;
 }
 
arch/x86/kernel/process_64.c +13 -2
Index: ftrace/arch/x86/kernel/process_64.c
===================================================================
@@ -248,7 +248,7 @@
 		t->io_bitmap_max = 0;
 		put_cpu();
 	}
-#ifdef CONFIG_X86_DS
+#ifdef CONFIG_X86_PTRACE_BTS
 	/* Free any BTS tracers that have not been properly released. */
 	if (unlikely(current->bts)) {
 		ds_release_bts(current->bts);
@@ -258,7 +258,7 @@
 		current->bts_buffer = NULL;
 		current->bts_size = 0;
 	}
-#endif /* CONFIG_X86_DS */
+#endif /* CONFIG_X86_PTRACE_BTS */
 }
 
 void flush_thread(void)
@@ -388,6 +388,17 @@
 		if (err)
 			goto out;
 	}
+
+#ifdef CONFIG_X86_DS
+	clear_tsk_thread_flag(p, TIF_DS_AREA_MSR);
+	p->thread.ds_ctx = NULL;
+#endif
+#ifdef CONFIG_X86_PTRACE_BTS
+	p->thread.bts_ovfl_signal = 0;
+#endif
+	clear_tsk_thread_flag(p, TIF_DEBUGCTLMSR);
+	p->thread.debugctlmsr = 0;
+
 	err = 0;
 out:
 	if (err && p->thread.io_bitmap_ptr) {
kernel/fork.c +5 -1
Index: ftrace/kernel/fork.c
===================================================================
@@ -1102,7 +1102,11 @@
 #ifdef CONFIG_DEBUG_MUTEXES
 	p->blocked_on = NULL; /* not blocked yet */
 #endif
-
+#ifdef CONFIG_X86_PTRACE_BTS
+	p->bts = NULL;
+	p->bts_buffer = NULL;
+	p->bts_size = 0;
+#endif
 	/* Perform scheduler related setup. Assign this task to a CPU. */
 	sched_fork(p, clone_flags);
 

---------------------------------------------------------------------
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.

#1 lore raw

arch/x86/kernel/process_32.c line 261

Quoted 10 lines · Markus Metzger
arch/x86/kernel/process_32.c +1 -2
-#ifdef CONFIG_X86_DS
+#ifdef CONFIG_X86_PTRACE_BTS
 	/* Free any BTS tracers that have not been properly released. */
 	if (unlikely(current->bts)) {
 		ds_release_bts(current->bts);
@@ -258,7 +258,7 @@
 		current->bts_buffer = NULL;
 		current->bts_size = 0;
 	}
-#endif /* CONFIG_X86_DS */

Please eliminate the #ifdef from here by introducing a helper function - possibly inlined.

arch/x86/kernel/process_32.c line 353

Quoted 7 lines
arch/x86/kernel/process_32.c +7 -0
+#ifdef CONFIG_X86_DS
+	clear_tsk_thread_flag(p, TIF_DS_AREA_MSR);
+	p->thread.ds_ctx = NULL;
+#endif
+#ifdef CONFIG_X86_PTRACE_BTS
+	p->thread.bts_ovfl_signal = 0;
+#endif

ditto.

kernel/fork.c line 1109

Quoted 5 lines
kernel/fork.c +5 -0
+#ifdef CONFIG_X86_PTRACE_BTS
+	p->bts = NULL;
+	p->bts_buffer = NULL;
+	p->bts_size = 0;
+#endif

this one too please.

There's generally little reason to put #ifdefs into .c files.

Ingo