diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-05-21 01:31:33 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-05-21 01:31:33 -0400 |
| commit | 5469dc270cd44c451590d40c031e6a71c1f637e8 (patch) | |
| tree | 5ca6330c2d754dbe82bfa75964a7f828f364e48f /kernel | |
| parent | 2f37dd131c5d3a2eac21cd5baf80658b1b02a8ac (diff) | |
| parent | ea9b50133ffebbd580cb5cd0aa222784d7a2fcb1 (diff) | |
Merge branch 'akpm' (patches from Andrew)
Merge more updates from Andrew Morton:
- the rest of MM
- KASAN updates
- procfs updates
- exit, fork updates
- printk updates
- lib/ updates
- radix-tree testsuite updates
- checkpatch updates
- kprobes updates
- a few other misc bits
* emailed patches from Andrew Morton <akpm@linux-foundation.org>: (162 commits)
samples/kprobes: print out the symbol name for the hooks
samples/kprobes: add a new module parameter
kprobes: add the "tls" argument for j_do_fork
init/main.c: simplify initcall_blacklisted()
fs/efs/super.c: fix return value
checkpatch: improve --git <commit-count> shortcut
checkpatch: reduce number of `git log` calls with --git
checkpatch: add support to check already applied git commits
checkpatch: add --list-types to show message types to show or ignore
checkpatch: advertise the --fix and --fix-inplace options more
checkpatch: whine about ACCESS_ONCE
checkpatch: add test for keywords not starting on tabstops
checkpatch: improve CONSTANT_COMPARISON test for structure members
checkpatch: add PREFER_IS_ENABLED test
lib/GCD.c: use binary GCD algorithm instead of Euclidean
radix-tree: free up the bottom bit of exceptional entries for reuse
dax: move RADIX_DAX_ definitions to dax.c
radix-tree: make radix_tree_descend() more useful
radix-tree: introduce radix_tree_replace_clear_tags()
radix-tree: tidy up __radix_tree_create()
...
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/exit.c | 2 | ||||
| -rw-r--r-- | kernel/fork.c | 54 | ||||
| -rw-r--r-- | kernel/irq/irqdomain.c | 7 | ||||
| -rw-r--r-- | kernel/kexec_core.c | 1 | ||||
| -rw-r--r-- | kernel/panic.c | 6 | ||||
| -rw-r--r-- | kernel/printk/Makefile | 1 | ||||
| -rw-r--r-- | kernel/printk/internal.h | 57 | ||||
| -rw-r--r-- | kernel/printk/nmi.c | 260 | ||||
| -rw-r--r-- | kernel/printk/printk.c | 31 | ||||
| -rw-r--r-- | kernel/sysctl_binary.c | 23 |
10 files changed, 383 insertions, 59 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index fd90195667e1..75b34fe835b2 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
| @@ -746,7 +746,7 @@ void do_exit(long code) | |||
| 746 | disassociate_ctty(1); | 746 | disassociate_ctty(1); |
| 747 | exit_task_namespaces(tsk); | 747 | exit_task_namespaces(tsk); |
| 748 | exit_task_work(tsk); | 748 | exit_task_work(tsk); |
| 749 | exit_thread(); | 749 | exit_thread(tsk); |
| 750 | 750 | ||
| 751 | /* | 751 | /* |
| 752 | * Flush inherited counters to the parent - before the parent | 752 | * Flush inherited counters to the parent - before the parent |
diff --git a/kernel/fork.c b/kernel/fork.c index 3e8451527cbe..103d78fd8f75 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
| @@ -699,6 +699,26 @@ void __mmdrop(struct mm_struct *mm) | |||
| 699 | } | 699 | } |
| 700 | EXPORT_SYMBOL_GPL(__mmdrop); | 700 | EXPORT_SYMBOL_GPL(__mmdrop); |
| 701 | 701 | ||
| 702 | static inline void __mmput(struct mm_struct *mm) | ||
| 703 | { | ||
| 704 | VM_BUG_ON(atomic_read(&mm->mm_users)); | ||
| 705 | |||
| 706 | uprobe_clear_state(mm); | ||
| 707 | exit_aio(mm); | ||
| 708 | ksm_exit(mm); | ||
| 709 | khugepaged_exit(mm); /* must run before exit_mmap */ | ||
| 710 | exit_mmap(mm); | ||
| 711 | set_mm_exe_file(mm, NULL); | ||
| 712 | if (!list_empty(&mm->mmlist)) { | ||
| 713 | spin_lock(&mmlist_lock); | ||
| 714 | list_del(&mm->mmlist); | ||
| 715 | spin_unlock(&mmlist_lock); | ||
| 716 | } | ||
| 717 | if (mm->binfmt) | ||
| 718 | module_put(mm->binfmt->module); | ||
| 719 | mmdrop(mm); | ||
| 720 | } | ||
| 721 | |||
| 702 | /* | 722 | /* |
| 703 | * Decrement the use count and release all resources for an mm. | 723 | * Decrement the use count and release all resources for an mm. |
| 704 | */ | 724 | */ |
| @@ -706,24 +726,24 @@ void mmput(struct mm_struct *mm) | |||
| 706 | { | 726 | { |
| 707 | might_sleep(); | 727 | might_sleep(); |
| 708 | 728 | ||
| 729 | if (atomic_dec_and_test(&mm->mm_users)) | ||
| 730 | __mmput(mm); | ||
| 731 | } | ||
| 732 | EXPORT_SYMBOL_GPL(mmput); | ||
| 733 | |||
| 734 | static void mmput_async_fn(struct work_struct *work) | ||
| 735 | { | ||
| 736 | struct mm_struct *mm = container_of(work, struct mm_struct, async_put_work); | ||
| 737 | __mmput(mm); | ||
| 738 | } | ||
| 739 | |||
| 740 | void mmput_async(struct mm_struct *mm) | ||
| 741 | { | ||
| 709 | if (atomic_dec_and_test(&mm->mm_users)) { | 742 | if (atomic_dec_and_test(&mm->mm_users)) { |
| 710 | uprobe_clear_state(mm); | 743 | INIT_WORK(&mm->async_put_work, mmput_async_fn); |
| 711 | exit_aio(mm); | 744 | schedule_work(&mm->async_put_work); |
| 712 | ksm_exit(mm); | ||
| 713 | khugepaged_exit(mm); /* must run before exit_mmap */ | ||
| 714 | exit_mmap(mm); | ||
| 715 | set_mm_exe_file(mm, NULL); | ||
| 716 | if (!list_empty(&mm->mmlist)) { | ||
| 717 | spin_lock(&mmlist_lock); | ||
| 718 | list_del(&mm->mmlist); | ||
| 719 | spin_unlock(&mmlist_lock); | ||
| 720 | } | ||
| 721 | if (mm->binfmt) | ||
| 722 | module_put(mm->binfmt->module); | ||
| 723 | mmdrop(mm); | ||
| 724 | } | 745 | } |
| 725 | } | 746 | } |
| 726 | EXPORT_SYMBOL_GPL(mmput); | ||
| 727 | 747 | ||
| 728 | /** | 748 | /** |
| 729 | * set_mm_exe_file - change a reference to the mm's executable file | 749 | * set_mm_exe_file - change a reference to the mm's executable file |
| @@ -1470,7 +1490,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
| 1470 | pid = alloc_pid(p->nsproxy->pid_ns_for_children); | 1490 | pid = alloc_pid(p->nsproxy->pid_ns_for_children); |
| 1471 | if (IS_ERR(pid)) { | 1491 | if (IS_ERR(pid)) { |
| 1472 | retval = PTR_ERR(pid); | 1492 | retval = PTR_ERR(pid); |
| 1473 | goto bad_fork_cleanup_io; | 1493 | goto bad_fork_cleanup_thread; |
| 1474 | } | 1494 | } |
| 1475 | } | 1495 | } |
| 1476 | 1496 | ||
| @@ -1632,6 +1652,8 @@ bad_fork_cancel_cgroup: | |||
| 1632 | bad_fork_free_pid: | 1652 | bad_fork_free_pid: |
| 1633 | if (pid != &init_struct_pid) | 1653 | if (pid != &init_struct_pid) |
| 1634 | free_pid(pid); | 1654 | free_pid(pid); |
| 1655 | bad_fork_cleanup_thread: | ||
| 1656 | exit_thread(p); | ||
| 1635 | bad_fork_cleanup_io: | 1657 | bad_fork_cleanup_io: |
| 1636 | if (p->io_context) | 1658 | if (p->io_context) |
| 1637 | exit_io_context(p); | 1659 | exit_io_context(p); |
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index d65f6f31a5b3..8798b6c9e945 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c | |||
| @@ -139,12 +139,7 @@ void irq_domain_remove(struct irq_domain *domain) | |||
| 139 | { | 139 | { |
| 140 | mutex_lock(&irq_domain_mutex); | 140 | mutex_lock(&irq_domain_mutex); |
| 141 | 141 | ||
| 142 | /* | 142 | WARN_ON(!radix_tree_empty(&domain->revmap_tree)); |
| 143 | * radix_tree_delete() takes care of destroying the root | ||
| 144 | * node when all entries are removed. Shout if there are | ||
| 145 | * any mappings left. | ||
| 146 | */ | ||
| 147 | WARN_ON(domain->revmap_tree.height); | ||
| 148 | 143 | ||
| 149 | list_del(&domain->link); | 144 | list_del(&domain->link); |
| 150 | 145 | ||
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 1c03dfb4abfd..d5d408252992 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c | |||
| @@ -893,6 +893,7 @@ void crash_kexec(struct pt_regs *regs) | |||
| 893 | old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu); | 893 | old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu); |
| 894 | if (old_cpu == PANIC_CPU_INVALID) { | 894 | if (old_cpu == PANIC_CPU_INVALID) { |
| 895 | /* This is the 1st CPU which comes here, so go ahead. */ | 895 | /* This is the 1st CPU which comes here, so go ahead. */ |
| 896 | printk_nmi_flush_on_panic(); | ||
| 896 | __crash_kexec(regs); | 897 | __crash_kexec(regs); |
| 897 | 898 | ||
| 898 | /* | 899 | /* |
diff --git a/kernel/panic.c b/kernel/panic.c index 535c96510a44..8aa74497cc5a 100644 --- a/kernel/panic.c +++ b/kernel/panic.c | |||
| @@ -160,8 +160,10 @@ void panic(const char *fmt, ...) | |||
| 160 | * | 160 | * |
| 161 | * Bypass the panic_cpu check and call __crash_kexec directly. | 161 | * Bypass the panic_cpu check and call __crash_kexec directly. |
| 162 | */ | 162 | */ |
| 163 | if (!crash_kexec_post_notifiers) | 163 | if (!crash_kexec_post_notifiers) { |
| 164 | printk_nmi_flush_on_panic(); | ||
| 164 | __crash_kexec(NULL); | 165 | __crash_kexec(NULL); |
| 166 | } | ||
| 165 | 167 | ||
| 166 | /* | 168 | /* |
| 167 | * Note smp_send_stop is the usual smp shutdown function, which | 169 | * Note smp_send_stop is the usual smp shutdown function, which |
| @@ -176,6 +178,8 @@ void panic(const char *fmt, ...) | |||
| 176 | */ | 178 | */ |
| 177 | atomic_notifier_call_chain(&panic_notifier_list, 0, buf); | 179 | atomic_notifier_call_chain(&panic_notifier_list, 0, buf); |
| 178 | 180 | ||
| 181 | /* Call flush even twice. It tries harder with a single online CPU */ | ||
| 182 | printk_nmi_flush_on_panic(); | ||
| 179 | kmsg_dump(KMSG_DUMP_PANIC); | 183 | kmsg_dump(KMSG_DUMP_PANIC); |
| 180 | 184 | ||
| 181 | /* | 185 | /* |
diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile index 85405bdcf2b3..abb0042a427b 100644 --- a/kernel/printk/Makefile +++ b/kernel/printk/Makefile | |||
| @@ -1,2 +1,3 @@ | |||
| 1 | obj-y = printk.o | 1 | obj-y = printk.o |
| 2 | obj-$(CONFIG_PRINTK_NMI) += nmi.o | ||
| 2 | obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o | 3 | obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o |
diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h new file mode 100644 index 000000000000..7fd2838fa417 --- /dev/null +++ b/kernel/printk/internal.h | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /* | ||
| 2 | * internal.h - printk internal definitions | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU General Public License | ||
| 6 | * as published by the Free Software Foundation; either version 2 | ||
| 7 | * of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include <linux/percpu.h> | ||
| 18 | |||
| 19 | typedef __printf(1, 0) int (*printk_func_t)(const char *fmt, va_list args); | ||
| 20 | |||
| 21 | int __printf(1, 0) vprintk_default(const char *fmt, va_list args); | ||
| 22 | |||
| 23 | #ifdef CONFIG_PRINTK_NMI | ||
| 24 | |||
| 25 | extern raw_spinlock_t logbuf_lock; | ||
| 26 | |||
| 27 | /* | ||
| 28 | * printk() could not take logbuf_lock in NMI context. Instead, | ||
| 29 | * it temporary stores the strings into a per-CPU buffer. | ||
| 30 | * The alternative implementation is chosen transparently | ||
| 31 | * via per-CPU variable. | ||
| 32 | */ | ||
| 33 | DECLARE_PER_CPU(printk_func_t, printk_func); | ||
| 34 | static inline __printf(1, 0) int vprintk_func(const char *fmt, va_list args) | ||
| 35 | { | ||
| 36 | return this_cpu_read(printk_func)(fmt, args); | ||
| 37 | } | ||
| 38 | |||
| 39 | extern atomic_t nmi_message_lost; | ||
| 40 | static inline int get_nmi_message_lost(void) | ||
| 41 | { | ||
| 42 | return atomic_xchg(&nmi_message_lost, 0); | ||
| 43 | } | ||
| 44 | |||
| 45 | #else /* CONFIG_PRINTK_NMI */ | ||
| 46 | |||
| 47 | static inline __printf(1, 0) int vprintk_func(const char *fmt, va_list args) | ||
| 48 | { | ||
| 49 | return vprintk_default(fmt, args); | ||
| 50 | } | ||
| 51 | |||
| 52 | static inline int get_nmi_message_lost(void) | ||
| 53 | { | ||
| 54 | return 0; | ||
| 55 | } | ||
| 56 | |||
| 57 | #endif /* CONFIG_PRINTK_NMI */ | ||
diff --git a/kernel/printk/nmi.c b/kernel/printk/nmi.c new file mode 100644 index 000000000000..b69eb8a2876f --- /dev/null +++ b/kernel/printk/nmi.c | |||
| @@ -0,0 +1,260 @@ | |||
| 1 | /* | ||
| 2 | * nmi.c - Safe printk in NMI context | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU General Public License | ||
| 6 | * as published by the Free Software Foundation; either version 2 | ||
| 7 | * of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <linux/preempt.h> | ||
| 19 | #include <linux/spinlock.h> | ||
| 20 | #include <linux/debug_locks.h> | ||
| 21 | #include <linux/smp.h> | ||
| 22 | #include <linux/cpumask.h> | ||
| 23 | #include <linux/irq_work.h> | ||
| 24 | #include <linux/printk.h> | ||
| 25 | |||
| 26 | #include "internal.h" | ||
| 27 | |||
| 28 | /* | ||
| 29 | * printk() could not take logbuf_lock in NMI context. Instead, | ||
| 30 | * it uses an alternative implementation that temporary stores | ||
| 31 | * the strings into a per-CPU buffer. The content of the buffer | ||
| 32 | * is later flushed into the main ring buffer via IRQ work. | ||
| 33 | * | ||
| 34 | * The alternative implementation is chosen transparently | ||
| 35 | * via @printk_func per-CPU variable. | ||
| 36 | * | ||
| 37 | * The implementation allows to flush the strings also from another CPU. | ||
| 38 | * There are situations when we want to make sure that all buffers | ||
| 39 | * were handled or when IRQs are blocked. | ||
| 40 | */ | ||
| 41 | DEFINE_PER_CPU(printk_func_t, printk_func) = vprintk_default; | ||
| 42 | static int printk_nmi_irq_ready; | ||
| 43 | atomic_t nmi_message_lost; | ||
| 44 | |||
| 45 | #define NMI_LOG_BUF_LEN ((1 << CONFIG_NMI_LOG_BUF_SHIFT) - \ | ||
| 46 | sizeof(atomic_t) - sizeof(struct irq_work)) | ||
| 47 | |||
| 48 | struct nmi_seq_buf { | ||
| 49 | atomic_t len; /* length of written data */ | ||
| 50 | struct irq_work work; /* IRQ work that flushes the buffer */ | ||
| 51 | unsigned char buffer[NMI_LOG_BUF_LEN]; | ||
| 52 | }; | ||
| 53 | static DEFINE_PER_CPU(struct nmi_seq_buf, nmi_print_seq); | ||
| 54 | |||
| 55 | /* | ||
| 56 | * Safe printk() for NMI context. It uses a per-CPU buffer to | ||
| 57 | * store the message. NMIs are not nested, so there is always only | ||
| 58 | * one writer running. But the buffer might get flushed from another | ||
| 59 | * CPU, so we need to be careful. | ||
| 60 | */ | ||
| 61 | static int vprintk_nmi(const char *fmt, va_list args) | ||
| 62 | { | ||
| 63 | struct nmi_seq_buf *s = this_cpu_ptr(&nmi_print_seq); | ||
| 64 | int add = 0; | ||
| 65 | size_t len; | ||
| 66 | |||
| 67 | again: | ||
| 68 | len = atomic_read(&s->len); | ||
| 69 | |||
| 70 | if (len >= sizeof(s->buffer)) { | ||
| 71 | atomic_inc(&nmi_message_lost); | ||
| 72 | return 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | /* | ||
| 76 | * Make sure that all old data have been read before the buffer was | ||
| 77 | * reseted. This is not needed when we just append data. | ||
| 78 | */ | ||
| 79 | if (!len) | ||
| 80 | smp_rmb(); | ||
| 81 | |||
| 82 | add = vsnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, args); | ||
| 83 | |||
| 84 | /* | ||
| 85 | * Do it once again if the buffer has been flushed in the meantime. | ||
| 86 | * Note that atomic_cmpxchg() is an implicit memory barrier that | ||
| 87 | * makes sure that the data were written before updating s->len. | ||
| 88 | */ | ||
| 89 | if (atomic_cmpxchg(&s->len, len, len + add) != len) | ||
| 90 | goto again; | ||
| 91 | |||
| 92 | /* Get flushed in a more safe context. */ | ||
| 93 | if (add && printk_nmi_irq_ready) { | ||
| 94 | /* Make sure that IRQ work is really initialized. */ | ||
| 95 | smp_rmb(); | ||
| 96 | irq_work_queue(&s->work); | ||
| 97 | } | ||
| 98 | |||
| 99 | return add; | ||
| 100 | } | ||
| 101 | |||
| 102 | /* | ||
| 103 | * printk one line from the temporary buffer from @start index until | ||
| 104 | * and including the @end index. | ||
| 105 | */ | ||
| 106 | static void print_nmi_seq_line(struct nmi_seq_buf *s, int start, int end) | ||
| 107 | { | ||
| 108 | const char *buf = s->buffer + start; | ||
| 109 | |||
| 110 | /* | ||
| 111 | * The buffers are flushed in NMI only on panic. The messages must | ||
| 112 | * go only into the ring buffer at this stage. Consoles will get | ||
| 113 | * explicitly called later when a crashdump is not generated. | ||
| 114 | */ | ||
| 115 | if (in_nmi()) | ||
| 116 | printk_deferred("%.*s", (end - start) + 1, buf); | ||
| 117 | else | ||
| 118 | printk("%.*s", (end - start) + 1, buf); | ||
| 119 | |||
| 120 | } | ||
| 121 | |||
| 122 | /* | ||
| 123 | * Flush data from the associated per_CPU buffer. The function | ||
| 124 | * can be called either via IRQ work or independently. | ||
| 125 | */ | ||
| 126 | static void __printk_nmi_flush(struct irq_work *work) | ||
| 127 | { | ||
| 128 | static raw_spinlock_t read_lock = | ||
| 129 | __RAW_SPIN_LOCK_INITIALIZER(read_lock); | ||
| 130 | struct nmi_seq_buf *s = container_of(work, struct nmi_seq_buf, work); | ||
| 131 | unsigned long flags; | ||
| 132 | size_t len, size; | ||
| 133 | int i, last_i; | ||
| 134 | |||
| 135 | /* | ||
| 136 | * The lock has two functions. First, one reader has to flush all | ||
| 137 | * available message to make the lockless synchronization with | ||
| 138 | * writers easier. Second, we do not want to mix messages from | ||
| 139 | * different CPUs. This is especially important when printing | ||
| 140 | * a backtrace. | ||
| 141 | */ | ||
| 142 | raw_spin_lock_irqsave(&read_lock, flags); | ||
| 143 | |||
| 144 | i = 0; | ||
| 145 | more: | ||
| 146 | len = atomic_read(&s->len); | ||
| 147 | |||
| 148 | /* | ||
| 149 | * This is just a paranoid check that nobody has manipulated | ||
| 150 | * the buffer an unexpected way. If we printed something then | ||
| 151 | * @len must only increase. | ||
| 152 | */ | ||
| 153 | if (i && i >= len) | ||
| 154 | pr_err("printk_nmi_flush: internal error: i=%d >= len=%zu\n", | ||
| 155 | i, len); | ||
| 156 | |||
| 157 | if (!len) | ||
| 158 | goto out; /* Someone else has already flushed the buffer. */ | ||
| 159 | |||
| 160 | /* Make sure that data has been written up to the @len */ | ||
| 161 | smp_rmb(); | ||
| 162 | |||
| 163 | size = min(len, sizeof(s->buffer)); | ||
| 164 | last_i = i; | ||
| 165 | |||
| 166 | /* Print line by line. */ | ||
| 167 | for (; i < size; i++) { | ||
| 168 | if (s->buffer[i] == '\n') { | ||
| 169 | print_nmi_seq_line(s, last_i, i); | ||
| 170 | last_i = i + 1; | ||
| 171 | } | ||
| 172 | } | ||
| 173 | /* Check if there was a partial line. */ | ||
| 174 | if (last_i < size) { | ||
| 175 | print_nmi_seq_line(s, last_i, size - 1); | ||
| 176 | pr_cont("\n"); | ||
| 177 | } | ||
| 178 | |||
| 179 | /* | ||
| 180 | * Check that nothing has got added in the meantime and truncate | ||
| 181 | * the buffer. Note that atomic_cmpxchg() is an implicit memory | ||
| 182 | * barrier that makes sure that the data were copied before | ||
| 183 | * updating s->len. | ||
| 184 | */ | ||
| 185 | if (atomic_cmpxchg(&s->len, len, 0) != len) | ||
| 186 | goto more; | ||
| 187 | |||
| 188 | out: | ||
| 189 | raw_spin_unlock_irqrestore(&read_lock, flags); | ||
| 190 | } | ||
| 191 | |||
| 192 | /** | ||
| 193 | * printk_nmi_flush - flush all per-cpu nmi buffers. | ||
| 194 | * | ||
| 195 | * The buffers are flushed automatically via IRQ work. This function | ||
| 196 | * is useful only when someone wants to be sure that all buffers have | ||
| 197 | * been flushed at some point. | ||
| 198 | */ | ||
| 199 | void printk_nmi_flush(void) | ||
| 200 | { | ||
| 201 | int cpu; | ||
| 202 | |||
| 203 | for_each_possible_cpu(cpu) | ||
| 204 | __printk_nmi_flush(&per_cpu(nmi_print_seq, cpu).work); | ||
| 205 | } | ||
| 206 | |||
| 207 | /** | ||
| 208 | * printk_nmi_flush_on_panic - flush all per-cpu nmi buffers when the system | ||
| 209 | * goes down. | ||
| 210 | * | ||
| 211 | * Similar to printk_nmi_flush() but it can be called even in NMI context when | ||
| 212 | * the system goes down. It does the best effort to get NMI messages into | ||
| 213 | * the main ring buffer. | ||
| 214 | * | ||
| 215 | * Note that it could try harder when there is only one CPU online. | ||
| 216 | */ | ||
| 217 | void printk_nmi_flush_on_panic(void) | ||
| 218 | { | ||
| 219 | /* | ||
| 220 | * Make sure that we could access the main ring buffer. | ||
| 221 | * Do not risk a double release when more CPUs are up. | ||
| 222 | */ | ||
| 223 | if (in_nmi() && raw_spin_is_locked(&logbuf_lock)) { | ||
| 224 | if (num_online_cpus() > 1) | ||
| 225 | return; | ||
| 226 | |||
| 227 | debug_locks_off(); | ||
| 228 | raw_spin_lock_init(&logbuf_lock); | ||
| 229 | } | ||
| 230 | |||
| 231 | printk_nmi_flush(); | ||
| 232 | } | ||
| 233 | |||
| 234 | void __init printk_nmi_init(void) | ||
| 235 | { | ||
| 236 | int cpu; | ||
| 237 | |||
| 238 | for_each_possible_cpu(cpu) { | ||
| 239 | struct nmi_seq_buf *s = &per_cpu(nmi_print_seq, cpu); | ||
| 240 | |||
| 241 | init_irq_work(&s->work, __printk_nmi_flush); | ||
| 242 | } | ||
| 243 | |||
| 244 | /* Make sure that IRQ works are initialized before enabling. */ | ||
| 245 | smp_wmb(); | ||
| 246 | printk_nmi_irq_ready = 1; | ||
| 247 | |||
| 248 | /* Flush pending messages that did not have scheduled IRQ works. */ | ||
| 249 | printk_nmi_flush(); | ||
| 250 | } | ||
| 251 | |||
| 252 | void printk_nmi_enter(void) | ||
| 253 | { | ||
| 254 | this_cpu_write(printk_func, vprintk_nmi); | ||
| 255 | } | ||
| 256 | |||
| 257 | void printk_nmi_exit(void) | ||
| 258 | { | ||
| 259 | this_cpu_write(printk_func, vprintk_default); | ||
| 260 | } | ||
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index bfbf284e4218..60cdf6386763 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c | |||
| @@ -55,6 +55,7 @@ | |||
| 55 | 55 | ||
| 56 | #include "console_cmdline.h" | 56 | #include "console_cmdline.h" |
| 57 | #include "braille.h" | 57 | #include "braille.h" |
| 58 | #include "internal.h" | ||
| 58 | 59 | ||
| 59 | int console_printk[4] = { | 60 | int console_printk[4] = { |
| 60 | CONSOLE_LOGLEVEL_DEFAULT, /* console_loglevel */ | 61 | CONSOLE_LOGLEVEL_DEFAULT, /* console_loglevel */ |
| @@ -244,7 +245,7 @@ __packed __aligned(4) | |||
| 244 | * within the scheduler's rq lock. It must be released before calling | 245 | * within the scheduler's rq lock. It must be released before calling |
| 245 | * console_unlock() or anything else that might wake up a process. | 246 | * console_unlock() or anything else that might wake up a process. |
| 246 | */ | 247 | */ |
| 247 | static DEFINE_RAW_SPINLOCK(logbuf_lock); | 248 | DEFINE_RAW_SPINLOCK(logbuf_lock); |
| 248 | 249 | ||
| 249 | #ifdef CONFIG_PRINTK | 250 | #ifdef CONFIG_PRINTK |
| 250 | DECLARE_WAIT_QUEUE_HEAD(log_wait); | 251 | DECLARE_WAIT_QUEUE_HEAD(log_wait); |
| @@ -1616,6 +1617,7 @@ asmlinkage int vprintk_emit(int facility, int level, | |||
| 1616 | unsigned long flags; | 1617 | unsigned long flags; |
| 1617 | int this_cpu; | 1618 | int this_cpu; |
| 1618 | int printed_len = 0; | 1619 | int printed_len = 0; |
| 1620 | int nmi_message_lost; | ||
| 1619 | bool in_sched = false; | 1621 | bool in_sched = false; |
| 1620 | /* cpu currently holding logbuf_lock in this function */ | 1622 | /* cpu currently holding logbuf_lock in this function */ |
| 1621 | static unsigned int logbuf_cpu = UINT_MAX; | 1623 | static unsigned int logbuf_cpu = UINT_MAX; |
| @@ -1666,6 +1668,15 @@ asmlinkage int vprintk_emit(int facility, int level, | |||
| 1666 | strlen(recursion_msg)); | 1668 | strlen(recursion_msg)); |
| 1667 | } | 1669 | } |
| 1668 | 1670 | ||
| 1671 | nmi_message_lost = get_nmi_message_lost(); | ||
| 1672 | if (unlikely(nmi_message_lost)) { | ||
| 1673 | text_len = scnprintf(textbuf, sizeof(textbuf), | ||
| 1674 | "BAD LUCK: lost %d message(s) from NMI context!", | ||
| 1675 | nmi_message_lost); | ||
| 1676 | printed_len += log_store(0, 2, LOG_PREFIX|LOG_NEWLINE, 0, | ||
| 1677 | NULL, 0, textbuf, text_len); | ||
| 1678 | } | ||
| 1679 | |||
| 1669 | /* | 1680 | /* |
| 1670 | * The printf needs to come first; we need the syslog | 1681 | * The printf needs to come first; we need the syslog |
| 1671 | * prefix which might be passed-in as a parameter. | 1682 | * prefix which might be passed-in as a parameter. |
| @@ -1807,14 +1818,6 @@ int vprintk_default(const char *fmt, va_list args) | |||
| 1807 | } | 1818 | } |
| 1808 | EXPORT_SYMBOL_GPL(vprintk_default); | 1819 | EXPORT_SYMBOL_GPL(vprintk_default); |
| 1809 | 1820 | ||
| 1810 | /* | ||
| 1811 | * This allows printk to be diverted to another function per cpu. | ||
| 1812 | * This is useful for calling printk functions from within NMI | ||
| 1813 | * without worrying about race conditions that can lock up the | ||
| 1814 | * box. | ||
| 1815 | */ | ||
| 1816 | DEFINE_PER_CPU(printk_func_t, printk_func) = vprintk_default; | ||
| 1817 | |||
| 1818 | /** | 1821 | /** |
| 1819 | * printk - print a kernel message | 1822 | * printk - print a kernel message |
| 1820 | * @fmt: format string | 1823 | * @fmt: format string |
| @@ -1838,21 +1841,11 @@ DEFINE_PER_CPU(printk_func_t, printk_func) = vprintk_default; | |||
| 1838 | */ | 1841 | */ |
| 1839 | asmlinkage __visible int printk(const char *fmt, ...) | 1842 | asmlinkage __visible int printk(const char *fmt, ...) |
| 1840 | { | 1843 | { |
| 1841 | printk_func_t vprintk_func; | ||
| 1842 | va_list args; | 1844 | va_list args; |
| 1843 | int r; | 1845 | int r; |
| 1844 | 1846 | ||
| 1845 | va_start(args, fmt); | 1847 | va_start(args, fmt); |
| 1846 | |||
| 1847 | /* | ||
| 1848 | * If a caller overrides the per_cpu printk_func, then it needs | ||
| 1849 | * to disable preemption when calling printk(). Otherwise | ||
| 1850 | * the printk_func should be set to the default. No need to | ||
| 1851 | * disable preemption here. | ||
| 1852 | */ | ||
| 1853 | vprintk_func = this_cpu_read(printk_func); | ||
| 1854 | r = vprintk_func(fmt, args); | 1848 | r = vprintk_func(fmt, args); |
| 1855 | |||
| 1856 | va_end(args); | 1849 | va_end(args); |
| 1857 | 1850 | ||
| 1858 | return r; | 1851 | return r; |
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c index 10a1d7dc9313..6eb99c17dbd8 100644 --- a/kernel/sysctl_binary.c +++ b/kernel/sysctl_binary.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <linux/ctype.h> | 13 | #include <linux/ctype.h> |
| 14 | #include <linux/netdevice.h> | 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/uuid.h> | ||
| 16 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
| 17 | #include <linux/compat.h> | 18 | #include <linux/compat.h> |
| 18 | 19 | ||
| @@ -1117,9 +1118,8 @@ static ssize_t bin_uuid(struct file *file, | |||
| 1117 | 1118 | ||
| 1118 | /* Only supports reads */ | 1119 | /* Only supports reads */ |
| 1119 | if (oldval && oldlen) { | 1120 | if (oldval && oldlen) { |
| 1120 | char buf[40], *str = buf; | 1121 | char buf[UUID_STRING_LEN + 1]; |
| 1121 | unsigned char uuid[16]; | 1122 | uuid_be uuid; |
| 1122 | int i; | ||
| 1123 | 1123 | ||
| 1124 | result = kernel_read(file, 0, buf, sizeof(buf) - 1); | 1124 | result = kernel_read(file, 0, buf, sizeof(buf) - 1); |
| 1125 | if (result < 0) | 1125 | if (result < 0) |
| @@ -1127,24 +1127,15 @@ static ssize_t bin_uuid(struct file *file, | |||
| 1127 | 1127 | ||
| 1128 | buf[result] = '\0'; | 1128 | buf[result] = '\0'; |
| 1129 | 1129 | ||
| 1130 | /* Convert the uuid to from a string to binary */ | 1130 | result = -EIO; |
| 1131 | for (i = 0; i < 16; i++) { | 1131 | if (uuid_be_to_bin(buf, &uuid)) |
| 1132 | result = -EIO; | 1132 | goto out; |
| 1133 | if (!isxdigit(str[0]) || !isxdigit(str[1])) | ||
| 1134 | goto out; | ||
| 1135 | |||
| 1136 | uuid[i] = (hex_to_bin(str[0]) << 4) | | ||
| 1137 | hex_to_bin(str[1]); | ||
| 1138 | str += 2; | ||
| 1139 | if (*str == '-') | ||
| 1140 | str++; | ||
| 1141 | } | ||
| 1142 | 1133 | ||
| 1143 | if (oldlen > 16) | 1134 | if (oldlen > 16) |
| 1144 | oldlen = 16; | 1135 | oldlen = 16; |
| 1145 | 1136 | ||
| 1146 | result = -EFAULT; | 1137 | result = -EFAULT; |
| 1147 | if (copy_to_user(oldval, uuid, oldlen)) | 1138 | if (copy_to_user(oldval, &uuid, oldlen)) |
| 1148 | goto out; | 1139 | goto out; |
| 1149 | 1140 | ||
| 1150 | copied = oldlen; | 1141 | copied = oldlen; |
