--- zzzz-none-000/linux-4.9.279/kernel/printk/printk.c 2021-08-08 06:38:54.000000000 +0000 +++ puma7-atom-6591-750/linux-4.9.279/kernel/printk/printk.c 2023-02-08 11:43:43.000000000 +0000 @@ -46,6 +46,13 @@ #include #include +#ifdef CONFIG_AVM_DEBUG +#include +#if defined(CONFIG_SMP) && defined(CONFIG_MIPS) +#include +#endif +#endif + #include #include @@ -328,6 +335,7 @@ LOG_NEWLINE = 2, /* text ended with a newline */ LOG_PREFIX = 4, /* text started with a prefix */ LOG_CONT = 8, /* text is a fragment of a continuation line */ + LOG_PRINTK_AVM = 16, /* AVM debug messages */ }; struct printk_log { @@ -338,6 +346,9 @@ u8 facility; /* syslog facility */ u8 flags:5; /* internal record flags */ u8 level:3; /* syslog level */ +#if defined(CONFIG_AVM_DEBUG) + u8 cpu; +#endif } #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS __packed __aligned(4) @@ -573,6 +584,9 @@ msg->facility = facility; msg->level = level & 7; msg->flags = flags & 0x1f; +#if defined(CONFIG_AVM_DEBUG) + msg->cpu = smp_processor_id(); +#endif if (ts_nsec > 0) msg->ts_nsec = ts_nsec; else @@ -1202,6 +1216,16 @@ } len += print_time(msg->ts_nsec, buf ? buf + len : NULL); + +#if defined(CONFIG_AVM_DEBUG) && defined(CONFIG_SMP) + if ((msg->flags & LOG_PRINTK_AVM) && buf) { + if (len && buf[len-1] == ' ') + len--; + len += sprintf(&buf[len], "[%s%x]", + msg->cpu & 0x80 ? "N" : "", msg->cpu & ~0x80); + } +#endif + return len; } @@ -1398,6 +1422,10 @@ if (error) goto out; + error = security_syslog(type); + if (error) + return error; + switch (type) { case SYSLOG_ACTION_CLOSE: /* Close log */ break; @@ -1522,6 +1550,9 @@ * The console_lock must be held. */ static void call_console_drivers(int level, +#if defined(CONFIG_AVM_DEBUG) + int flags, +#endif const char *ext_text, size_t ext_len, const char *text, size_t len) { @@ -1529,6 +1560,13 @@ trace_console_rcuidle(text, len); +#if defined(CONFIG_AVM_DEBUG) + if ((flags & LOG_PRINTK_AVM) && + (avm_debug_console_write(text, len) == 0)) { + return; + } +#endif + if (!console_drivers) return; @@ -1736,7 +1774,7 @@ char *text = textbuf; size_t text_len = 0; enum log_flags lflags = 0; - unsigned long flags; + unsigned long flags = 0; int this_cpu; int printed_len = 0; int nmi_message_lost; @@ -1811,6 +1849,17 @@ lflags |= LOG_NEWLINE; } +#if defined(CONFIG_AVM_DEBUG) + if (facility & FORCE_PRINTK_LINUX_FACILITIES_VALUE) + facility &= ~FORCE_PRINTK_LINUX_FACILITIES_VALUE; + else if (force_printk_avm || + (facility & FORCE_PRINTK_AVM_FACILITIES_VALUE)) { + facility &= ~FORCE_PRINTK_AVM_FACILITIES_VALUE; + /* force console-output over avm_debug_console_write() */ + lflags |= LOG_PRINTK_AVM; + } +#endif + /* strip kernel syslog prefix and extract log level or control flags */ if (facility == 0) { int kern_level; @@ -1963,6 +2012,9 @@ char *dict, size_t dict_len, char *text, size_t text_len) { return 0; } static void call_console_drivers(int level, +#if defined(CONFIG_AVM_DEBUG) + int flags, +#endif const char *ext_text, size_t ext_len, const char *text, size_t len) {} static size_t msg_print_text(const struct printk_log *msg, @@ -1973,6 +2025,16 @@ /* Still needs to be defined for users */ DEFINE_PER_CPU(printk_func_t, printk_func); +#ifdef CONFIG_AVM_DEBUG +static int no_vprintk(const char *fmt, + va_list args) +{ + return 0; +} + +asmlinkage int (*vprintk)(const char *fmt, va_list args) = no_vprintk; +#endif /* CONFIG_AVM_DEBUG */ + #endif /* CONFIG_PRINTK */ #ifdef CONFIG_EARLY_PRINTK @@ -2269,7 +2331,11 @@ len = cont_print_text(text, size); raw_spin_unlock(&logbuf_lock); stop_critical_timings(); +#if defined(CONFIG_AVM_DEBUG) + call_console_drivers(cont.level, cont.flags, NULL, 0, text, len); +#else call_console_drivers(cont.level, NULL, 0, text, len); +#endif start_critical_timings(); local_irq_restore(flags); return; @@ -2398,7 +2464,11 @@ raw_spin_unlock(&logbuf_lock); stop_critical_timings(); /* don't trace print latency */ +#if defined(CONFIG_AVM_DEBUG) + call_console_drivers(level, msg->flags, ext_text, ext_len, text, len); +#else call_console_drivers(level, ext_text, ext_len, text, len); +#endif start_critical_timings(); local_irq_restore(flags); @@ -2900,6 +2970,25 @@ static DEFINE_SPINLOCK(dump_list_lock); static LIST_HEAD(dump_list); +#if defined(CONFIG_AVM_DEBUG) +bool kmsg_dump_get_buffer_nocontext(bool syslog, char *buf, size_t size, size_t *len) { + struct kmsg_dumper _dumper, *dumper; + unsigned long flags; + + dumper = &_dumper; + /* initialize iterator with data about the stored records */ + dumper->active = true; + raw_spin_lock_irqsave(&logbuf_lock, flags); + dumper->cur_seq = clear_seq; + dumper->cur_idx = clear_idx; + dumper->next_seq = log_next_seq; + dumper->next_idx = log_next_idx; + raw_spin_unlock_irqrestore(&logbuf_lock, flags); + + return kmsg_dump_get_buffer(dumper, 0, buf, size, len); +} +#endif/*--- #if defined(CONFIG_AVM_DEBUG) ---*/ + /** * kmsg_dump_register - register a kernel log dumper. * @dumper: pointer to the kmsg_dumper structure @@ -3237,10 +3326,13 @@ * Arch-specific dump_stack() implementations can use this function to * print out the same debug information as the generic dump_stack(). */ -void dump_stack_print_info(const char *log_lvl) +void dump_stack_print_info(const char *log_lvl, struct task_struct *task) { + if (!task) + task = current; + printk("%sCPU: %d PID: %d Comm: %.20s %s %s %.*s\n", - log_lvl, raw_smp_processor_id(), current->pid, current->comm, + log_lvl, task_cpu(task), task->pid, task->comm, print_tainted(), init_utsname()->release, (int)strcspn(init_utsname()->version, " "), init_utsname()->version); @@ -3249,7 +3341,7 @@ printk("%sHardware name: %s\n", log_lvl, dump_stack_arch_desc_str); - print_worker_info(log_lvl, current); + print_worker_info(log_lvl, task); } /** @@ -3259,12 +3351,15 @@ * show_regs() implementations can use this function to print out generic * debug information. */ -void show_regs_print_info(const char *log_lvl) +void show_regs_print_info(const char *log_lvl, struct task_struct *task) { - dump_stack_print_info(log_lvl); + if (!task) + task = current; + + dump_stack_print_info(log_lvl, task); printk("%stask: %p task.stack: %p\n", - log_lvl, current, task_stack_page(current)); + log_lvl, task, task_stack_page(task)); } #endif