Commit 0f9a623dd6c9b5b4dd00c232f29525bfc7a8ecf2

Authored by Stuart Bennett
Committed by Ingo Molnar
1 parent 46e91d00b1

tracing: x86, mmiotrace: only register for die notifier when tracer active

Follow up to afcfe024aebd74b0984a41af9a34e009cf5badaf in Linus' tree
("x86: mmiotrace: quieten spurious warning message")

Signed-off-by: Stuart Bennett <stuart@freedesktop.org>
Acked-by: Pekka Paalanen <pq@iki.fi>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1240946271-7083-5-git-send-email-stuart@freedesktop.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 3 changed files with 26 additions and 5 deletions Side-by-side Diff

... ... @@ -311,7 +311,12 @@
311 311 struct kmmio_context *ctx = &get_cpu_var(kmmio_ctx);
312 312  
313 313 if (!ctx->active) {
314   - pr_debug("kmmio: spurious debug trap on CPU %d.\n",
  314 + /*
  315 + * debug traps without an active context are due to either
  316 + * something external causing them (f.e. using a debugger while
  317 + * mmio tracing enabled), or erroneous behaviour
  318 + */
  319 + pr_warning("kmmio: unexpected debug trap on CPU %d.\n",
315 320 smp_processor_id());
316 321 goto out;
317 322 }
... ... @@ -529,8 +534,8 @@
529 534 }
530 535 EXPORT_SYMBOL(unregister_kmmio_probe);
531 536  
532   -static int kmmio_die_notifier(struct notifier_block *nb, unsigned long val,
533   - void *args)
  537 +static int
  538 +kmmio_die_notifier(struct notifier_block *nb, unsigned long val, void *args)
534 539 {
535 540 struct die_args *arg = args;
536 541  
537 542  
538 543  
539 544  
... ... @@ -545,12 +550,24 @@
545 550 .notifier_call = kmmio_die_notifier
546 551 };
547 552  
548   -static int __init init_kmmio(void)
  553 +int kmmio_init(void)
549 554 {
550 555 int i;
  556 +
551 557 for (i = 0; i < KMMIO_PAGE_TABLE_SIZE; i++)
552 558 INIT_LIST_HEAD(&kmmio_page_table[i]);
  559 +
553 560 return register_die_notifier(&nb_die);
554 561 }
555   -fs_initcall(init_kmmio); /* should be before device_initcall() */
  562 +
  563 +void kmmio_cleanup(void)
  564 +{
  565 + int i;
  566 +
  567 + unregister_die_notifier(&nb_die);
  568 + for (i = 0; i < KMMIO_PAGE_TABLE_SIZE; i++) {
  569 + WARN_ONCE(!list_empty(&kmmio_page_table[i]),
  570 + KERN_ERR "kmmio_page_table not empty at cleanup, any further tracing will leak memory.\n");
  571 + }
  572 +}
arch/x86/mm/mmio-mod.c
... ... @@ -451,6 +451,7 @@
451 451  
452 452 if (nommiotrace)
453 453 pr_info(NAME "MMIO tracing disabled.\n");
  454 + kmmio_init();
454 455 enter_uniprocessor();
455 456 spin_lock_irq(&trace_lock);
456 457 atomic_inc(&mmiotrace_enabled);
... ... @@ -473,6 +474,7 @@
473 474  
474 475 clear_trace_list(); /* guarantees: no more kmmio callbacks */
475 476 leave_uniprocessor();
  477 + kmmio_cleanup();
476 478 pr_info(NAME "disabled.\n");
477 479 out:
478 480 mutex_unlock(&mmiotrace_mutex);
include/linux/mmiotrace.h
... ... @@ -30,6 +30,8 @@
30 30  
31 31 extern int register_kmmio_probe(struct kmmio_probe *p);
32 32 extern void unregister_kmmio_probe(struct kmmio_probe *p);
  33 +extern int kmmio_init(void);
  34 +extern void kmmio_cleanup(void);
33 35  
34 36 #ifdef CONFIG_MMIOTRACE
35 37 /* kmmio is active by some kmmio_probes? */