Subject: + printk-enable-interrupts-before-calling-console_trylock_for_printk.patch added to -mm tree To: jack@xxxxxxx From: akpm@xxxxxxxxxxxxxxxxxxxx Date: Wed, 23 Apr 2014 13:58:52 -0700 The patch titled Subject: printk: enable interrupts before calling console_trylock_for_printk() has been added to the -mm tree. Its filename is printk-enable-interrupts-before-calling-console_trylock_for_printk.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/printk-enable-interrupts-before-calling-console_trylock_for_printk.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/printk-enable-interrupts-before-calling-console_trylock_for_printk.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Jan Kara <jack@xxxxxxx> Subject: printk: enable interrupts before calling console_trylock_for_printk() We need interrupts disabled when calling console_trylock_for_printk() only so that cpu id we pass to can_use_console() remains valid (for other things console_sem provides all the exclusion we need and deadlocks on console_sem due to interrupts are impossible because we use down_trylock()). However if we are rescheduled, we are guaranteed to run on an online cpu so we can easily just get the cpu id in can_use_console(). We can lose a bit of performance when we enable interrupts in vprintk_emit() and then disable them again in console_unlock() but OTOH it can somewhat reduce interrupt latency caused by console_unlock() especially since later in the patch series we will want to spin on console_sem in console_trylock_for_printk(). Signed-off-by: Jan Kara <jack@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- kernel/printk/printk.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff -puN kernel/printk/printk.c~printk-enable-interrupts-before-calling-console_trylock_for_printk kernel/printk/printk.c --- a/kernel/printk/printk.c~printk-enable-interrupts-before-calling-console_trylock_for_printk +++ a/kernel/printk/printk.c @@ -1394,10 +1394,9 @@ static int have_callable_console(void) /* * Can we actually use the console at this time on this cpu? * - * Console drivers may assume that per-cpu resources have - * been allocated. So unless they're explicitly marked as - * being able to cope (CON_ANYTIME) don't call them until - * this CPU is officially up. + * Console drivers may assume that per-cpu resources have been allocated. So + * unless they're explicitly marked as being able to cope (CON_ANYTIME) don't + * call them until this CPU is officially up. */ static inline int can_use_console(unsigned int cpu) { @@ -1410,8 +1409,10 @@ static inline int can_use_console(unsign * console_lock held, and 'console_locked' set) if it * is successful, false otherwise. */ -static int console_trylock_for_printk(unsigned int cpu) +static int console_trylock_for_printk(void) { + unsigned int cpu = smp_processor_id(); + if (!console_trylock()) return 0; /* @@ -1581,7 +1582,8 @@ asmlinkage int vprintk_emit(int facility */ if (!oops_in_progress && !lockdep_recursing(current)) { recursion_bug = 1; - goto out_restore_irqs; + local_irq_restore(flags); + return 0; } zap_locks(); } @@ -1684,17 +1686,22 @@ asmlinkage int vprintk_emit(int facility logbuf_cpu = UINT_MAX; raw_spin_unlock(&logbuf_lock); + lockdep_on(); + local_irq_restore(flags); + + /* + * Disable preemption to avoid being preempted while holding + * console_sem which would prevent anyone from printing to console + */ + preempt_disable(); /* * Try to acquire and then immediately release the console semaphore. * The release will print out buffers and wake up /dev/kmsg and syslog() * users. */ - if (console_trylock_for_printk(this_cpu)) + if (console_trylock_for_printk()) console_unlock(); - - lockdep_on(); -out_restore_irqs: - local_irq_restore(flags); + preempt_enable(); return printed_len; } _ Patches currently in -mm which might be from jack@xxxxxxx are origin.patch fanotify-fan_mark_flush-avoid-having-to-provide-a-fake-invalid-fd-and-path.patch fanotify-create-fan_access-event-for-readdir.patch fs-notify-markc-trivial-cleanup.patch fs-mpagec-forgotten-write_sync-in-case-of-data-integrity-write.patch printk-split-code-for-making-free-space-in-the-log-buffer.patch printk-ignore-too-long-messages.patch printk-split-message-size-computation.patch printk-shrink-too-long-messages.patch printk-return-really-stored-message-length.patch printk-remove-outdated-comment.patch printk-release-lockbuf_lock-before-calling-console_trylock_for_printk.patch printk-release-lockbuf_lock-before-calling-console_trylock_for_printk-fix.patch printk-enable-interrupts-before-calling-console_trylock_for_printk.patch printk-remove-separate-printk_sched-buffers-and-use-printk-buf-instead.patch linux-next.patch mm-add-strictlimit-knob-v2.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html