/*1* Kernel Debugger Architecture Independent Console I/O handler2*3* This file is subject to the terms and conditions of the GNU General Public4* License. See the file "COPYING" in the main directory of this archive5* for more details.6*7* Copyright (c) 1999-2006 Silicon Graphics, Inc. All Rights Reserved.8* Copyright (c) 2009 Wind River Systems, Inc. All Rights Reserved.9*/1011#include <linux/types.h>12#include <linux/ctype.h>13#include <linux/kernel.h>14#include <linux/init.h>15#include <linux/kdev_t.h>16#include <linux/console.h>17#include <linux/string.h>18#include <linux/sched.h>19#include <linux/smp.h>20#include <linux/nmi.h>21#include <linux/delay.h>22#include <linux/kgdb.h>23#include <linux/kdb.h>24#include <linux/kallsyms.h>25#include "kdb_private.h"2627#define CMD_BUFLEN 25628char kdb_prompt_str[CMD_BUFLEN];2930int kdb_trap_printk;31int kdb_printf_cpu = -1;3233static int kgdb_transition_check(char *buffer)34{35if (buffer[0] != '+' && buffer[0] != '$') {36KDB_STATE_SET(KGDB_TRANS);37kdb_printf("%s", buffer);38} else {39int slen = strlen(buffer);40if (slen > 3 && buffer[slen - 3] == '#') {41kdb_gdb_state_pass(buffer);42strcpy(buffer, "kgdb");43KDB_STATE_SET(DOING_KGDB);44return 1;45}46}47return 0;48}4950/**51* kdb_handle_escape() - validity check on an accumulated escape sequence.52* @buf: Accumulated escape characters to be examined. Note that buf53* is not a string, it is an array of characters and need not be54* nil terminated.55* @sz: Number of accumulated escape characters.56*57* Return: -1 if the escape sequence is unwanted, 0 if it is incomplete,58* otherwise it returns a mapped key value to pass to the upper layers.59*/60static int kdb_handle_escape(char *buf, size_t sz)61{62char *lastkey = buf + sz - 1;6364switch (sz) {65case 1:66if (*lastkey == '\e')67return 0;68break;6970case 2: /* \e<something> */71if (*lastkey == '[')72return 0;73break;7475case 3:76switch (*lastkey) {77case 'A': /* \e[A, up arrow */78return 16;79case 'B': /* \e[B, down arrow */80return 14;81case 'C': /* \e[C, right arrow */82return 6;83case 'D': /* \e[D, left arrow */84return 2;85case '1': /* \e[<1,3,4>], may be home, del, end */86case '3':87case '4':88return 0;89}90break;9192case 4:93if (*lastkey == '~') {94switch (buf[2]) {95case '1': /* \e[1~, home */96return 1;97case '3': /* \e[3~, del */98return 4;99case '4': /* \e[4~, end */100return 5;101}102}103break;104}105106return -1;107}108109/**110* kdb_getchar() - Read a single character from a kdb console (or consoles).111*112* Other than polling the various consoles that are currently enabled,113* most of the work done in this function is dealing with escape sequences.114*115* An escape key could be the start of a vt100 control sequence such as \e[D116* (left arrow) or it could be a character in its own right. The standard117* method for detecting the difference is to wait for 2 seconds to see if there118* are any other characters. kdb is complicated by the lack of a timer service119* (interrupts are off), by multiple input sources. Escape sequence processing120* has to be done as states in the polling loop.121*122* Return: The key pressed or a control code derived from an escape sequence.123*/124char kdb_getchar(void)125{126#define ESCAPE_UDELAY 1000127#define ESCAPE_DELAY (2*1000000/ESCAPE_UDELAY) /* 2 seconds worth of udelays */128char buf[4]; /* longest vt100 escape sequence is 4 bytes */129char *pbuf = buf;130int escape_delay = 0;131get_char_func *f, *f_prev = NULL;132int key;133static bool last_char_was_cr;134135for (f = &kdb_poll_funcs[0]; ; ++f) {136if (*f == NULL) {137/* Reset NMI watchdog once per poll loop */138touch_nmi_watchdog();139f = &kdb_poll_funcs[0];140}141142key = (*f)();143if (key == -1) {144if (escape_delay) {145udelay(ESCAPE_UDELAY);146if (--escape_delay == 0)147return '\e';148}149continue;150}151152/*153* The caller expects that newlines are either CR or LF. However154* some terminals send _both_ CR and LF. Avoid having to handle155* this in the caller by stripping the LF if we saw a CR right156* before.157*/158if (last_char_was_cr && key == '\n') {159last_char_was_cr = false;160continue;161}162last_char_was_cr = (key == '\r');163164/*165* When the first character is received (or we get a change166* input source) we set ourselves up to handle an escape167* sequences (just in case).168*/169if (f_prev != f) {170f_prev = f;171pbuf = buf;172escape_delay = ESCAPE_DELAY;173}174175*pbuf++ = key;176key = kdb_handle_escape(buf, pbuf - buf);177if (key < 0) /* no escape sequence; return best character */178return buf[pbuf - buf == 2 ? 1 : 0];179if (key > 0)180return key;181}182183unreachable();184}185186/**187* kdb_position_cursor() - Place cursor in the correct horizontal position188* @prompt: Nil-terminated string containing the prompt string189* @buffer: Nil-terminated string containing the entire command line190* @cp: Cursor position, pointer the character in buffer where the cursor191* should be positioned.192*193* The cursor is positioned by sending a carriage-return and then printing194* the content of the line until we reach the correct cursor position.195*196* There is some additional fine detail here.197*198* Firstly, even though kdb_printf() will correctly format zero-width fields199* we want the second call to kdb_printf() to be conditional. That keeps things200* a little cleaner when LOGGING=1.201*202* Secondly, we can't combine everything into one call to kdb_printf() since203* that renders into a fixed length buffer and the combined print could result204* in unwanted truncation.205*/206static void kdb_position_cursor(char *prompt, char *buffer, char *cp)207{208kdb_printf("\r%s", prompt);209if (cp > buffer)210kdb_printf("%.*s", (int)(cp - buffer), buffer);211}212213/*214* kdb_read215*216* This function reads a string of characters, terminated by217* a newline, or by reaching the end of the supplied buffer,218* from the current kernel debugger console device.219* Parameters:220* buffer - Address of character buffer to receive input characters.221* bufsize - size, in bytes, of the character buffer222* Returns:223* Returns a pointer to the buffer containing the received224* character string. This string will be terminated by a225* newline character.226* Locking:227* No locks are required to be held upon entry to this228* function. It is not reentrant - it relies on the fact229* that while kdb is running on only one "master debug" cpu.230* Remarks:231* The buffer size must be >= 2.232*/233234static char *kdb_read(char *buffer, size_t bufsize)235{236char *cp = buffer;237char *bufend = buffer+bufsize-2; /* Reserve space for newline238* and null byte */239char *lastchar;240char *p_tmp;241char tmp;242static char tmpbuffer[CMD_BUFLEN];243int len = strlen(buffer);244int len_tmp;245int tab = 0;246int count;247int i;248int diag, dtab_count;249int key, ret;250251diag = kdbgetintenv("DTABCOUNT", &dtab_count);252if (diag)253dtab_count = 30;254255if (len > 0) {256cp += len;257if (*(buffer+len-1) == '\n')258cp--;259}260261lastchar = cp;262*cp = '\0';263kdb_printf("%s", buffer);264poll_again:265key = kdb_getchar();266if (key != 9)267tab = 0;268switch (key) {269case 8: /* backspace */270if (cp > buffer) {271memmove(cp-1, cp, lastchar - cp + 1);272lastchar--;273cp--;274kdb_printf("\b%s ", cp);275kdb_position_cursor(kdb_prompt_str, buffer, cp);276}277break;278case 10: /* linefeed */279case 13: /* carriage return */280*lastchar++ = '\n';281*lastchar++ = '\0';282if (!KDB_STATE(KGDB_TRANS)) {283KDB_STATE_SET(KGDB_TRANS);284kdb_printf("%s", buffer);285}286kdb_printf("\n");287return buffer;288case 4: /* Del */289if (cp < lastchar) {290memmove(cp, cp+1, lastchar - cp);291lastchar--;292kdb_printf("%s ", cp);293kdb_position_cursor(kdb_prompt_str, buffer, cp);294}295break;296case 1: /* Home */297if (cp > buffer) {298cp = buffer;299kdb_position_cursor(kdb_prompt_str, buffer, cp);300}301break;302case 5: /* End */303if (cp < lastchar) {304kdb_printf("%s", cp);305cp = lastchar;306}307break;308case 2: /* Left */309if (cp > buffer) {310kdb_printf("\b");311--cp;312}313break;314case 14: /* Down */315case 16: /* Up */316kdb_printf("\r%*c\r",317(int)(strlen(kdb_prompt_str) + (lastchar - buffer)),318' ');319*lastchar = (char)key;320*(lastchar+1) = '\0';321return lastchar;322case 6: /* Right */323if (cp < lastchar) {324kdb_printf("%c", *cp);325++cp;326}327break;328case 9: /* Tab */329if (tab < 2)330++tab;331332tmp = *cp;333*cp = '\0';334p_tmp = strrchr(buffer, ' ');335p_tmp = (p_tmp ? p_tmp + 1 : buffer);336strscpy(tmpbuffer, p_tmp);337*cp = tmp;338339len = strlen(tmpbuffer);340count = kallsyms_symbol_complete(tmpbuffer, sizeof(tmpbuffer));341if (tab == 2 && count > 0) {342kdb_printf("\n%d symbols are found.", count);343if (count > dtab_count) {344count = dtab_count;345kdb_printf(" But only first %d symbols will"346" be printed.\nYou can change the"347" environment variable DTABCOUNT.",348count);349}350kdb_printf("\n");351for (i = 0; i < count; i++) {352ret = kallsyms_symbol_next(tmpbuffer, i, sizeof(tmpbuffer));353if (WARN_ON(!ret))354break;355if (ret != -E2BIG)356kdb_printf("%s ", tmpbuffer);357else358kdb_printf("%s... ", tmpbuffer);359tmpbuffer[len] = '\0';360}361if (i >= dtab_count)362kdb_printf("...");363kdb_printf("\n");364kdb_printf("%s", kdb_prompt_str);365kdb_printf("%s", buffer);366if (cp != lastchar)367kdb_position_cursor(kdb_prompt_str, buffer, cp);368} else if (tab != 2 && count > 0) {369/* How many new characters do we want from tmpbuffer? */370len_tmp = strlen(tmpbuffer) - len;371if (lastchar + len_tmp >= bufend)372len_tmp = bufend - lastchar;373374if (len_tmp) {375/* + 1 ensures the '\0' is memmove'd */376memmove(cp+len_tmp, cp, (lastchar-cp) + 1);377memcpy(cp, tmpbuffer+len, len_tmp);378kdb_printf("%s", cp);379cp += len_tmp;380lastchar += len_tmp;381if (cp != lastchar)382kdb_position_cursor(kdb_prompt_str,383buffer, cp);384}385}386kdb_nextline = 1; /* reset output line number */387break;388default:389if (key >= 32 && lastchar < bufend) {390if (cp < lastchar) {391memmove(cp+1, cp, lastchar - cp + 1);392lastchar++;393*cp = key;394kdb_printf("%s", cp);395++cp;396kdb_position_cursor(kdb_prompt_str, buffer, cp);397} else {398*++lastchar = '\0';399*cp++ = key;400/* The kgdb transition check will hide401* printed characters if we think that402* kgdb is connecting, until the check403* fails */404if (!KDB_STATE(KGDB_TRANS)) {405if (kgdb_transition_check(buffer))406return buffer;407} else {408kdb_printf("%c", key);409}410}411/* Special escape to kgdb */412if (lastchar - buffer >= 5 &&413strcmp(lastchar - 5, "$?#3f") == 0) {414kdb_gdb_state_pass(lastchar - 5);415strcpy(buffer, "kgdb");416KDB_STATE_SET(DOING_KGDB);417return buffer;418}419if (lastchar - buffer >= 11 &&420strcmp(lastchar - 11, "$qSupported") == 0) {421kdb_gdb_state_pass(lastchar - 11);422strcpy(buffer, "kgdb");423KDB_STATE_SET(DOING_KGDB);424return buffer;425}426}427break;428}429goto poll_again;430}431432/*433* kdb_getstr434*435* Print the prompt string and read a command from the436* input device.437*438* Parameters:439* buffer Address of buffer to receive command440* bufsize Size of buffer in bytes441* prompt Pointer to string to use as prompt string442* Returns:443* Pointer to command buffer.444* Locking:445* None.446* Remarks:447* For SMP kernels, the processor number will be448* substituted for %d, %x or %o in the prompt.449*/450451char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt)452{453if (prompt && kdb_prompt_str != prompt)454strscpy(kdb_prompt_str, prompt);455kdb_printf("%s", kdb_prompt_str);456kdb_nextline = 1; /* Prompt and input resets line number */457return kdb_read(buffer, bufsize);458}459460/*461* kdb_input_flush462*463* Get rid of any buffered console input.464*465* Parameters:466* none467* Returns:468* nothing469* Locking:470* none471* Remarks:472* Call this function whenever you want to flush input. If there is any473* outstanding input, it ignores all characters until there has been no474* data for approximately 1ms.475*/476477static void kdb_input_flush(void)478{479get_char_func *f;480int res;481int flush_delay = 1;482while (flush_delay) {483flush_delay--;484empty:485touch_nmi_watchdog();486for (f = &kdb_poll_funcs[0]; *f; ++f) {487res = (*f)();488if (res != -1) {489flush_delay = 1;490goto empty;491}492}493if (flush_delay)494mdelay(1);495}496}497498/*499* kdb_printf500*501* Print a string to the output device(s).502*503* Parameters:504* printf-like format and optional args.505* Returns:506* 0507* Locking:508* None.509* Remarks:510* use 'kdbcons->write()' to avoid polluting 'log_buf' with511* kdb output.512*513* If the user is doing a cmd args | grep srch514* then kdb_grepping_flag is set.515* In that case we need to accumulate full lines (ending in \n) before516* searching for the pattern.517*/518519static char kdb_buffer[256]; /* A bit too big to go on stack */520static char *next_avail = kdb_buffer;521static int size_avail;522static int suspend_grep;523524/*525* search arg1 to see if it contains arg2526* (kdmain.c provides flags for ^pat and pat$)527*528* return 1 for found, 0 for not found529*/530static int kdb_search_string(char *searched, char *searchfor)531{532char firstchar, *cp;533int len1, len2;534535/* not counting the newline at the end of "searched" */536len1 = strlen(searched)-1;537len2 = strlen(searchfor);538if (len1 < len2)539return 0;540if (kdb_grep_leading && kdb_grep_trailing && len1 != len2)541return 0;542if (kdb_grep_leading) {543if (!strncmp(searched, searchfor, len2))544return 1;545} else if (kdb_grep_trailing) {546if (!strncmp(searched+len1-len2, searchfor, len2))547return 1;548} else {549firstchar = *searchfor;550cp = searched;551while ((cp = strchr(cp, firstchar))) {552if (!strncmp(cp, searchfor, len2))553return 1;554cp++;555}556}557return 0;558}559560static void kdb_msg_write(const char *msg, int msg_len)561{562struct console *c;563const char *cp;564int cookie;565int len;566567if (msg_len == 0)568return;569570cp = msg;571len = msg_len;572573while (len--) {574dbg_io_ops->write_char(*cp);575cp++;576}577578/*579* The console_srcu_read_lock() only provides safe console list580* traversal. The use of the ->write() callback relies on all other581* CPUs being stopped at the moment and console drivers being able to582* handle reentrance when @oops_in_progress is set.583*584* There is no guarantee that every console driver can handle585* reentrance in this way; the developer deploying the debugger586* is responsible for ensuring that the console drivers they587* have selected handle reentrance appropriately.588*/589cookie = console_srcu_read_lock();590for_each_console_srcu(c) {591short flags = console_srcu_read_flags(c);592593if (!console_is_usable(c, flags, true))594continue;595if (c == dbg_io_ops->cons)596continue;597598if (flags & CON_NBCON) {599struct nbcon_write_context wctxt = { };600601/*602* Do not continue if the console is NBCON and the context603* can't be acquired.604*/605if (!nbcon_kdb_try_acquire(c, &wctxt))606continue;607608nbcon_write_context_set_buf(&wctxt, (char *)msg, msg_len);609610c->write_atomic(c, &wctxt);611nbcon_kdb_release(&wctxt);612} else {613/*614* Set oops_in_progress to encourage the console drivers to615* disregard their internal spin locks: in the current calling616* context the risk of deadlock is a bigger problem than risks617* due to re-entering the console driver. We operate directly on618* oops_in_progress rather than using bust_spinlocks() because619* the calls bust_spinlocks() makes on exit are not appropriate620* for this calling context.621*/622++oops_in_progress;623c->write(c, msg, msg_len);624--oops_in_progress;625}626touch_nmi_watchdog();627}628console_srcu_read_unlock(cookie);629}630631int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)632{633int diag;634int linecount;635int colcount;636int logging, saved_loglevel = 0;637int retlen = 0;638int fnd, len;639int this_cpu, old_cpu;640char *cp, *cp2, *cphold = NULL, replaced_byte = ' ';641char *moreprompt = "more> ";642unsigned long flags;643644/* Serialize kdb_printf if multiple cpus try to write at once.645* But if any cpu goes recursive in kdb, just print the output,646* even if it is interleaved with any other text.647*/648local_irq_save(flags);649this_cpu = smp_processor_id();650for (;;) {651old_cpu = cmpxchg(&kdb_printf_cpu, -1, this_cpu);652if (old_cpu == -1 || old_cpu == this_cpu)653break;654655cpu_relax();656}657658diag = kdbgetintenv("LINES", &linecount);659if (diag || linecount <= 1)660linecount = 24;661662diag = kdbgetintenv("COLUMNS", &colcount);663if (diag || colcount <= 1)664colcount = 80;665666diag = kdbgetintenv("LOGGING", &logging);667if (diag)668logging = 0;669670if (!kdb_grepping_flag || suspend_grep) {671/* normally, every vsnprintf starts a new buffer */672next_avail = kdb_buffer;673size_avail = sizeof(kdb_buffer);674}675vsnprintf(next_avail, size_avail, fmt, ap);676677/*678* If kdb_parse() found that the command was cmd xxx | grep yyy679* then kdb_grepping_flag is set, and kdb_grep_string contains yyy680*681* Accumulate the print data up to a newline before searching it.682* (vsnprintf does null-terminate the string that it generates)683*/684685/* skip the search if prints are temporarily unconditional */686if (!suspend_grep && kdb_grepping_flag) {687cp = strchr(kdb_buffer, '\n');688if (!cp) {689/*690* Special cases that don't end with newlines691* but should be written without one:692* The "[nn]kdb> " prompt should693* appear at the front of the buffer.694*695* The "[nn]more " prompt should also be696* (MOREPROMPT -> moreprompt)697* written * but we print that ourselves,698* we set the suspend_grep flag to make699* it unconditional.700*701*/702if (next_avail == kdb_buffer) {703/*704* these should occur after a newline,705* so they will be at the front of the706* buffer707*/708cp2 = kdb_buffer;709len = strlen(kdb_prompt_str);710if (!strncmp(cp2, kdb_prompt_str, len)) {711/*712* We're about to start a new713* command, so we can go back714* to normal mode.715*/716kdb_grepping_flag = 0;717goto kdb_printit;718}719}720/* no newline; don't search/write the buffer721until one is there */722len = strlen(kdb_buffer);723next_avail = kdb_buffer + len;724size_avail = sizeof(kdb_buffer) - len;725goto kdb_print_out;726}727728/*729* The newline is present; print through it or discard730* it, depending on the results of the search.731*/732cp++; /* to byte after the newline */733replaced_byte = *cp; /* remember what it was */734cphold = cp; /* remember where it was */735*cp = '\0'; /* end the string for our search */736737/*738* We now have a newline at the end of the string739* Only continue with this output if it contains the740* search string.741*/742fnd = kdb_search_string(kdb_buffer, kdb_grep_string);743if (!fnd) {744/*745* At this point the complete line at the start746* of kdb_buffer can be discarded, as it does747* not contain what the user is looking for.748* Shift the buffer left.749*/750*cphold = replaced_byte;751len = strlen(cphold);752/* Use memmove() because the buffers overlap */753memmove(kdb_buffer, cphold, len + 1);754next_avail = kdb_buffer + len;755size_avail = sizeof(kdb_buffer) - len;756goto kdb_print_out;757}758if (kdb_grepping_flag >= KDB_GREPPING_FLAG_SEARCH) {759/*760* This was a interactive search (using '/' at more761* prompt) and it has completed. Replace the \0 with762* its original value to ensure multi-line strings763* are handled properly, and return to normal mode.764*/765*cphold = replaced_byte;766kdb_grepping_flag = 0;767}768/*769* at this point the string is a full line and770* should be printed, up to the null.771*/772}773kdb_printit:774775/*776* Write to all consoles.777*/778retlen = strlen(kdb_buffer);779cp = (char *) printk_skip_headers(kdb_buffer);780if (!dbg_kdb_mode && kgdb_connected)781gdbstub_msg_write(cp, retlen - (cp - kdb_buffer));782else783kdb_msg_write(cp, retlen - (cp - kdb_buffer));784785if (logging) {786saved_loglevel = console_loglevel;787console_loglevel = CONSOLE_LOGLEVEL_SILENT;788if (printk_get_level(kdb_buffer) || src == KDB_MSGSRC_PRINTK)789printk("%s", kdb_buffer);790else791pr_info("%s", kdb_buffer);792}793794if (KDB_STATE(PAGER)) {795/*796* Check printed string to decide how to bump the797* kdb_nextline to control when the more prompt should798* show up.799*/800int got = 0;801len = retlen;802while (len--) {803if (kdb_buffer[len] == '\n') {804kdb_nextline++;805got = 0;806} else if (kdb_buffer[len] == '\r') {807got = 0;808} else {809got++;810}811}812kdb_nextline += got / (colcount + 1);813}814815/* check for having reached the LINES number of printed lines */816if (kdb_nextline >= linecount) {817char ch;818819/* Watch out for recursion here. Any routine that calls820* kdb_printf will come back through here. And kdb_read821* uses kdb_printf to echo on serial consoles ...822*/823kdb_nextline = 1; /* In case of recursion */824825/*826* Pause until cr.827*/828moreprompt = kdbgetenv("MOREPROMPT");829if (moreprompt == NULL)830moreprompt = "more> ";831832kdb_input_flush();833kdb_msg_write(moreprompt, strlen(moreprompt));834835if (logging)836printk("%s", moreprompt);837838ch = kdb_getchar();839kdb_nextline = 1; /* Really set output line 1 */840841/* empty and reset the buffer: */842kdb_buffer[0] = '\0';843next_avail = kdb_buffer;844size_avail = sizeof(kdb_buffer);845if ((ch == 'q') || (ch == 'Q')) {846/* user hit q or Q */847KDB_FLAG_SET(CMD_INTERRUPT); /* command interrupted */848KDB_STATE_CLEAR(PAGER);849/* end of command output; back to normal mode */850kdb_grepping_flag = 0;851kdb_printf("\n");852} else if (ch == ' ') {853kdb_printf("\r");854suspend_grep = 1; /* for this recursion */855} else if (ch == '\n' || ch == '\r') {856kdb_nextline = linecount - 1;857kdb_printf("\r");858suspend_grep = 1; /* for this recursion */859} else if (ch == '/' && !kdb_grepping_flag) {860kdb_printf("\r");861kdb_getstr(kdb_grep_string, KDB_GREP_STRLEN,862kdbgetenv("SEARCHPROMPT") ?: "search> ");863*strchrnul(kdb_grep_string, '\n') = '\0';864kdb_grepping_flag += KDB_GREPPING_FLAG_SEARCH;865suspend_grep = 1; /* for this recursion */866} else if (ch) {867/* user hit something unexpected */868suspend_grep = 1; /* for this recursion */869if (ch != '/')870kdb_printf(871"\nOnly 'q', 'Q' or '/' are processed at "872"more prompt, input ignored\n");873else874kdb_printf("\n'/' cannot be used during | "875"grep filtering, input ignored\n");876} else if (kdb_grepping_flag) {877/* user hit enter */878suspend_grep = 1; /* for this recursion */879kdb_printf("\n");880}881kdb_input_flush();882}883884/*885* For grep searches, shift the printed string left.886* replaced_byte contains the character that was overwritten with887* the terminating null, and cphold points to the null.888* Then adjust the notion of available space in the buffer.889*/890if (kdb_grepping_flag && !suspend_grep) {891*cphold = replaced_byte;892len = strlen(cphold);893/* Use memmove() because the buffers overlap */894memmove(kdb_buffer, cphold, len + 1);895next_avail = kdb_buffer + len;896size_avail = sizeof(kdb_buffer) - len;897}898899kdb_print_out:900suspend_grep = 0; /* end of what may have been a recursive call */901if (logging)902console_loglevel = saved_loglevel;903/* kdb_printf_cpu locked the code above. */904smp_store_release(&kdb_printf_cpu, old_cpu);905local_irq_restore(flags);906return retlen;907}908909int kdb_printf(const char *fmt, ...)910{911va_list ap;912int r;913914va_start(ap, fmt);915r = vkdb_printf(KDB_MSGSRC_INTERNAL, fmt, ap);916va_end(ap);917918return r;919}920EXPORT_SYMBOL_GPL(kdb_printf);921922923