Merge branch 'paul' (Fixups from Paul Gortmaker)
[linux-flexiantxendom0-3.2.10.git] / kernel / printk.c
index 37dff34..b663c2c 100644 (file)
@@ -44,6 +44,9 @@
 
 #include <asm/uaccess.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/printk.h>
+
 /*
  * Architectures can override it:
  */
@@ -100,7 +103,7 @@ static int console_locked, console_suspended;
  * It is also used in interesting ways to provide interlocking in
  * console_unlock();.
  */
-static DEFINE_SPINLOCK(logbuf_lock);
+static DEFINE_RAW_SPINLOCK(logbuf_lock);
 
 #define LOG_BUF_MASK (log_buf_len-1)
 #define LOG_BUF(idx) (log_buf[(idx) & LOG_BUF_MASK])
@@ -199,7 +202,7 @@ void __init setup_log_buf(int early)
                unsigned long mem;
 
                mem = memblock_alloc(new_log_buf_len, PAGE_SIZE);
-               if (mem == MEMBLOCK_ERROR)
+               if (!mem)
                        return;
                new_log_buf = __va(mem);
        } else {
@@ -212,7 +215,7 @@ void __init setup_log_buf(int early)
                return;
        }
 
-       spin_lock_irqsave(&logbuf_lock, flags);
+       raw_spin_lock_irqsave(&logbuf_lock, flags);
        log_buf_len = new_log_buf_len;
        log_buf = new_log_buf;
        new_log_buf_len = 0;
@@ -230,7 +233,7 @@ void __init setup_log_buf(int early)
        log_start -= offset;
        con_start -= offset;
        log_end -= offset;
-       spin_unlock_irqrestore(&logbuf_lock, flags);
+       raw_spin_unlock_irqrestore(&logbuf_lock, flags);
 
        pr_info("log_buf_len: %d\n", log_buf_len);
        pr_info("early log buf free: %d(%d%%)\n",
@@ -318,8 +321,10 @@ static int check_syslog_permissions(int type, bool from_file)
                        return 0;
                /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
                if (capable(CAP_SYS_ADMIN)) {
-                       WARN_ONCE(1, "Attempt to access syslog with CAP_SYS_ADMIN "
-                                "but no CAP_SYSLOG (deprecated).\n");
+                       printk_once(KERN_WARNING "%s (%d): "
+                                "Attempt to access syslog with CAP_SYS_ADMIN "
+                                "but no CAP_SYSLOG (deprecated).\n",
+                                current->comm, task_pid_nr(current));
                        return 0;
                }
                return -EPERM;
@@ -363,18 +368,18 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
                if (error)
                        goto out;
                i = 0;
-               spin_lock_irq(&logbuf_lock);
+               raw_spin_lock_irq(&logbuf_lock);
                while (!error && (log_start != log_end) && i < len) {
                        c = LOG_BUF(log_start);
                        log_start++;
-                       spin_unlock_irq(&logbuf_lock);
+                       raw_spin_unlock_irq(&logbuf_lock);
                        error = __put_user(c,buf);
                        buf++;
                        i++;
                        cond_resched();
-                       spin_lock_irq(&logbuf_lock);
+                       raw_spin_lock_irq(&logbuf_lock);
                }
-               spin_unlock_irq(&logbuf_lock);
+               raw_spin_unlock_irq(&logbuf_lock);
                if (!error)
                        error = i;
                break;
@@ -397,7 +402,7 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
                count = len;
                if (count > log_buf_len)
                        count = log_buf_len;
-               spin_lock_irq(&logbuf_lock);
+               raw_spin_lock_irq(&logbuf_lock);
                if (count > logged_chars)
                        count = logged_chars;
                if (do_clear)
@@ -414,12 +419,12 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
                        if (j + log_buf_len < log_end)
                                break;
                        c = LOG_BUF(j);
-                       spin_unlock_irq(&logbuf_lock);
+                       raw_spin_unlock_irq(&logbuf_lock);
                        error = __put_user(c,&buf[count-1-i]);
                        cond_resched();
-                       spin_lock_irq(&logbuf_lock);
+                       raw_spin_lock_irq(&logbuf_lock);
                }
-               spin_unlock_irq(&logbuf_lock);
+               raw_spin_unlock_irq(&logbuf_lock);
                if (error)
                        break;
                error = i;
@@ -519,7 +524,7 @@ static void __call_console_drivers(unsigned start, unsigned end)
        }
 }
 
-static int __read_mostly ignore_loglevel;
+static bool __read_mostly ignore_loglevel;
 
 static int __init ignore_loglevel_setup(char *str)
 {
@@ -530,6 +535,9 @@ static int __init ignore_loglevel_setup(char *str)
 }
 
 early_param("ignore_loglevel", ignore_loglevel_setup);
+module_param(ignore_loglevel, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(ignore_loglevel, "ignore loglevel setting, to"
+       "print all kernel messages to the console.");
 
 /*
  * Write out chars from start to end - 1 inclusive
@@ -537,6 +545,8 @@ early_param("ignore_loglevel", ignore_loglevel_setup);
 static void _call_console_drivers(unsigned start,
                                unsigned end, int msg_log_level)
 {
+       trace_console(&LOG_BUF(0), start, end, log_buf_len);
+
        if ((msg_log_level < console_loglevel || ignore_loglevel) &&
                        console_drivers && start != end) {
                if ((start & LOG_BUF_MASK) > (end & LOG_BUF_MASK)) {
@@ -590,9 +600,6 @@ static size_t log_prefix(const char *p, unsigned int *level, char *special)
                /* multi digit including the level and facility number */
                char *endp = NULL;
 
-               if (p[1] < '0' && p[1] > '9')
-                       return 0;
-
                lev = (simple_strtoul(&p[1], &endp, 10) & 7);
                if (endp == NULL || endp[0] != '>')
                        return 0;
@@ -686,19 +693,23 @@ static void zap_locks(void)
 
        oops_timestamp = jiffies;
 
+       debug_locks_off();
        /* If a crash is occurring, make sure we can't deadlock */
-       spin_lock_init(&logbuf_lock);
+       raw_spin_lock_init(&logbuf_lock);
        /* And make sure that we print immediately */
        sema_init(&console_sem, 1);
 }
 
 #if defined(CONFIG_PRINTK_TIME)
-static int printk_time = 1;
+static bool printk_time = 1;
 #else
-static int printk_time = 0;
+static bool printk_time = 0;
 #endif
 module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
 
+static bool always_kmsg_dump;
+module_param_named(always_kmsg_dump, always_kmsg_dump, bool, S_IRUGO | S_IWUSR);
+
 /* Check if we have any console registered that can be called early in boot. */
 static int have_callable_console(void)
 {
@@ -800,9 +811,9 @@ static int console_trylock_for_printk(unsigned int cpu)
                }
        }
        printk_cpu = UINT_MAX;
-       spin_unlock(&logbuf_lock);
        if (wake)
                up(&console_sem);
+       raw_spin_unlock(&logbuf_lock);
        return retval;
 }
 static const char recursion_bug_msg [] =
@@ -838,9 +849,8 @@ asmlinkage int vprintk(const char *fmt, va_list args)
        boot_delay_msec();
        printk_delay();
 
-       preempt_disable();
        /* This stops the holder of console_sem just where we want him */
-       raw_local_irq_save(flags);
+       local_irq_save(flags);
        this_cpu = smp_processor_id();
 
        /*
@@ -854,7 +864,7 @@ asmlinkage int vprintk(const char *fmt, va_list args)
                 * recursion and return - but flag the recursion so that
                 * it can be printed at the next appropriate moment:
                 */
-               if (!oops_in_progress) {
+               if (!oops_in_progress && !lockdep_recursing(current)) {
                        recursion_bug = 1;
                        goto out_restore_irqs;
                }
@@ -862,7 +872,7 @@ asmlinkage int vprintk(const char *fmt, va_list args)
        }
 
        lockdep_off();
-       spin_lock(&logbuf_lock);
+       raw_spin_lock(&logbuf_lock);
        printk_cpu = this_cpu;
 
        if (recursion_bug) {
@@ -960,9 +970,8 @@ asmlinkage int vprintk(const char *fmt, va_list args)
 
        lockdep_on();
 out_restore_irqs:
-       raw_local_irq_restore(flags);
+       local_irq_restore(flags);
 
-       preempt_enable();
        return printed_len;
 }
 EXPORT_SYMBOL(printk);
@@ -1097,7 +1106,7 @@ int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, cha
        return -1;
 }
 
-int console_suspend_enabled = 1;
+bool console_suspend_enabled = 1;
 EXPORT_SYMBOL(console_suspend_enabled);
 
 static int __init console_suspend_disable(char *str)
@@ -1106,6 +1115,10 @@ static int __init console_suspend_disable(char *str)
        return 1;
 }
 __setup("no_console_suspend", console_suspend_disable);
+module_param_named(console_suspend, console_suspend_enabled,
+               bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(console_suspend, "suspend console during suspend"
+       " and hibernate operations");
 
 /**
  * suspend_console - suspend the console subsystem
@@ -1203,13 +1216,27 @@ int is_console_locked(void)
        return console_locked;
 }
 
+/*
+ * Delayed printk facility, for scheduler-internal messages:
+ */
+#define PRINTK_BUF_SIZE                512
+
+#define PRINTK_PENDING_WAKEUP  0x01
+#define PRINTK_PENDING_SCHED   0x02
+
 static DEFINE_PER_CPU(int, printk_pending);
+static DEFINE_PER_CPU(char [PRINTK_BUF_SIZE], printk_sched_buf);
 
 void printk_tick(void)
 {
        if (__this_cpu_read(printk_pending)) {
-               __this_cpu_write(printk_pending, 0);
-               wake_up_interruptible(&log_wait);
+               int pending = __this_cpu_xchg(printk_pending, 0);
+               if (pending & PRINTK_PENDING_SCHED) {
+                       char *buf = __get_cpu_var(printk_sched_buf);
+                       printk(KERN_WARNING "[sched_delayed] %s", buf);
+               }
+               if (pending & PRINTK_PENDING_WAKEUP)
+                       wake_up_interruptible(&log_wait);
        }
 }
 
@@ -1223,7 +1250,7 @@ int printk_needs_cpu(int cpu)
 void wake_up_klogd(void)
 {
        if (waitqueue_active(&log_wait))
-               this_cpu_write(printk_pending, 1);
+               this_cpu_or(printk_pending, PRINTK_PENDING_WAKEUP);
 }
 
 /**
@@ -1255,14 +1282,14 @@ void console_unlock(void)
 
 again:
        for ( ; ; ) {
-               spin_lock_irqsave(&logbuf_lock, flags);
+               raw_spin_lock_irqsave(&logbuf_lock, flags);
                wake_klogd |= log_start - log_end;
                if (con_start == log_end)
                        break;                  /* Nothing to print */
                _con_start = con_start;
                _log_end = log_end;
                con_start = log_end;            /* Flush */
-               spin_unlock(&logbuf_lock);
+               raw_spin_unlock(&logbuf_lock);
                stop_critical_timings();        /* don't trace print latency */
                call_console_drivers(_con_start, _log_end);
                start_critical_timings();
@@ -1274,7 +1301,7 @@ again:
        if (unlikely(exclusive_console))
                exclusive_console = NULL;
 
-       spin_unlock(&logbuf_lock);
+       raw_spin_unlock(&logbuf_lock);
 
        up(&console_sem);
 
@@ -1284,10 +1311,11 @@ again:
         * there's a new owner and the console_unlock() from them will do the
         * flush, no worries.
         */
-       spin_lock(&logbuf_lock);
+       raw_spin_lock(&logbuf_lock);
        if (con_start != log_end)
                retry = 1;
-       spin_unlock_irqrestore(&logbuf_lock, flags);
+       raw_spin_unlock_irqrestore(&logbuf_lock, flags);
+
        if (retry && console_trylock())
                goto again;
 
@@ -1520,9 +1548,9 @@ void register_console(struct console *newcon)
                 * console_unlock(); will print out the buffered messages
                 * for us.
                 */
-               spin_lock_irqsave(&logbuf_lock, flags);
+               raw_spin_lock_irqsave(&logbuf_lock, flags);
                con_start = log_start;
-               spin_unlock_irqrestore(&logbuf_lock, flags);
+               raw_spin_unlock_irqrestore(&logbuf_lock, flags);
                /*
                 * We're about to replay the log buffer.  Only do this to the
                 * just-registered console to avoid excessive message spam to
@@ -1602,7 +1630,7 @@ static int __init printk_late_init(void)
        struct console *con;
 
        for_each_console(con) {
-               if (con->flags & CON_BOOT) {
+               if (!keep_bootcon && con->flags & CON_BOOT) {
                        printk(KERN_INFO "turn off boot console %s%d\n",
                                con->name, con->index);
                        unregister_console(con);
@@ -1615,6 +1643,26 @@ late_initcall(printk_late_init);
 
 #if defined CONFIG_PRINTK
 
+int printk_sched(const char *fmt, ...)
+{
+       unsigned long flags;
+       va_list args;
+       char *buf;
+       int r;
+
+       local_irq_save(flags);
+       buf = __get_cpu_var(printk_sched_buf);
+
+       va_start(args, fmt);
+       r = vsnprintf(buf, PRINTK_BUF_SIZE, fmt, args);
+       va_end(args);
+
+       __this_cpu_or(printk_pending, PRINTK_PENDING_SCHED);
+       local_irq_restore(flags);
+
+       return r;
+}
+
 /*
  * printk rate limiting, lifted from the networking subsystem.
  *
@@ -1726,13 +1774,16 @@ void kmsg_dump(enum kmsg_dump_reason reason)
        unsigned long l1, l2;
        unsigned long flags;
 
+       if ((reason > KMSG_DUMP_OOPS) && !always_kmsg_dump)
+               return;
+
        /* Theoretically, the log could move on after we do this, but
           there's not a lot we can do about that. The new messages
           will overwrite the start of what we dump. */
-       spin_lock_irqsave(&logbuf_lock, flags);
+       raw_spin_lock_irqsave(&logbuf_lock, flags);
        end = log_end & LOG_BUF_MASK;
        chars = logged_chars;
-       spin_unlock_irqrestore(&logbuf_lock, flags);
+       raw_spin_unlock_irqrestore(&logbuf_lock, flags);
 
        if (chars > end) {
                s1 = log_buf + log_buf_len - chars + end;