printk.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  1. /*
  2. * linux/kernel/printk.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. *
  6. * Modified to make sys_syslog() more flexible: added commands to
  7. * return the last 4k of kernel messages, regardless of whether
  8. * they've been read or not. Added option to suppress kernel printk's
  9. * to the console. Added hook for sending the console messages
  10. * elsewhere, in preparation for a serial line console (someday).
  11. * Ted Ts'o, 2/11/93.
  12. * Modified for sysctl support, 1/8/97, Chris Horn.
  13. * Fixed SMP synchronization, 08/08/99, Manfred Spraul
  14. * manfred@colorfullife.com
  15. * Rewrote bits to get rid of console_lock
  16. * 01Mar01 Andrew Morton
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/tty.h>
  21. #include <linux/tty_driver.h>
  22. #include <linux/console.h>
  23. #include <linux/init.h>
  24. #include <linux/jiffies.h>
  25. #include <linux/nmi.h>
  26. #include <linux/module.h>
  27. #include <linux/moduleparam.h>
  28. #include <linux/interrupt.h> /* For in_interrupt() */
  29. #include <linux/delay.h>
  30. #include <linux/smp.h>
  31. #include <linux/security.h>
  32. #include <linux/bootmem.h>
  33. #include <linux/syscalls.h>
  34. #include <linux/kexec.h>
  35. #include <asm/uaccess.h>
  36. /*
  37. * for_each_console() allows you to iterate on each console
  38. */
  39. #define for_each_console(con) \
  40. for (con = console_drivers; con != NULL; con = con->next)
  41. /*
  42. * Architectures can override it:
  43. */
  44. void asmlinkage __attribute__((weak)) early_printk(const char *fmt, ...)
  45. {
  46. }
  47. #define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
  48. /* printk's without a loglevel use this.. */
  49. #define DEFAULT_MESSAGE_LOGLEVEL 4 /* KERN_WARNING */
  50. /* We show everything that is MORE important than this.. */
  51. #define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */
  52. #define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */
  53. DECLARE_WAIT_QUEUE_HEAD(log_wait);
  54. int console_printk[4] = {
  55. DEFAULT_CONSOLE_LOGLEVEL, /* console_loglevel */
  56. DEFAULT_MESSAGE_LOGLEVEL, /* default_message_loglevel */
  57. MINIMUM_CONSOLE_LOGLEVEL, /* minimum_console_loglevel */
  58. DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */
  59. };
  60. static int saved_console_loglevel = -1;
  61. /*
  62. * Low level drivers may need that to know if they can schedule in
  63. * their unblank() callback or not. So let's export it.
  64. */
  65. int oops_in_progress;
  66. EXPORT_SYMBOL(oops_in_progress);
  67. /*
  68. * console_sem protects the console_drivers list, and also
  69. * provides serialisation for access to the entire console
  70. * driver system.
  71. */
  72. static DECLARE_MUTEX(console_sem);
  73. struct console *console_drivers;
  74. EXPORT_SYMBOL_GPL(console_drivers);
  75. /*
  76. * This is used for debugging the mess that is the VT code by
  77. * keeping track if we have the console semaphore held. It's
  78. * definitely not the perfect debug tool (we don't know if _WE_
  79. * hold it are racing, but it helps tracking those weird code
  80. * path in the console code where we end up in places I want
  81. * locked without the console sempahore held
  82. */
  83. static int console_locked, console_suspended;
  84. /*
  85. * logbuf_lock protects log_buf, log_start, log_end, con_start and logged_chars
  86. * It is also used in interesting ways to provide interlocking in
  87. * release_console_sem().
  88. */
  89. static DEFINE_SPINLOCK(logbuf_lock);
  90. #define LOG_BUF_MASK (log_buf_len-1)
  91. #define LOG_BUF(idx) (log_buf[(idx) & LOG_BUF_MASK])
  92. /*
  93. * The indices into log_buf are not constrained to log_buf_len - they
  94. * must be masked before subscripting
  95. */
  96. static unsigned log_start; /* Index into log_buf: next char to be read by syslog() */
  97. static unsigned con_start; /* Index into log_buf: next char to be sent to consoles */
  98. static unsigned log_end; /* Index into log_buf: most-recently-written-char + 1 */
  99. /*
  100. * Array of consoles built from command line options (console=)
  101. */
  102. struct console_cmdline
  103. {
  104. char name[8]; /* Name of the driver */
  105. int index; /* Minor dev. to use */
  106. char *options; /* Options for the driver */
  107. #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
  108. char *brl_options; /* Options for braille driver */
  109. #endif
  110. };
  111. #define MAX_CMDLINECONSOLES 8
  112. static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
  113. static int selected_console = -1;
  114. static int preferred_console = -1;
  115. int console_set_on_cmdline;
  116. EXPORT_SYMBOL(console_set_on_cmdline);
  117. /* Flag: console code may call schedule() */
  118. static int console_may_schedule;
  119. #ifdef CONFIG_PRINTK
  120. static char __log_buf[__LOG_BUF_LEN];
  121. static char *log_buf = __log_buf;
  122. static int log_buf_len = __LOG_BUF_LEN;
  123. static unsigned logged_chars; /* Number of chars produced since last read+clear operation */
  124. #ifdef CONFIG_KEXEC
  125. /*
  126. * This appends the listed symbols to /proc/vmcoreinfo
  127. *
  128. * /proc/vmcoreinfo is used by various utiilties, like crash and makedumpfile to
  129. * obtain access to symbols that are otherwise very difficult to locate. These
  130. * symbols are specifically used so that utilities can access and extract the
  131. * dmesg log from a vmcore file after a crash.
  132. */
  133. void log_buf_kexec_setup(void)
  134. {
  135. VMCOREINFO_SYMBOL(log_buf);
  136. VMCOREINFO_SYMBOL(log_end);
  137. VMCOREINFO_SYMBOL(log_buf_len);
  138. VMCOREINFO_SYMBOL(logged_chars);
  139. }
  140. #endif
  141. static int __init log_buf_len_setup(char *str)
  142. {
  143. unsigned size = memparse(str, &str);
  144. unsigned long flags;
  145. if (size)
  146. size = roundup_pow_of_two(size);
  147. if (size > log_buf_len) {
  148. unsigned start, dest_idx, offset;
  149. char *new_log_buf;
  150. new_log_buf = alloc_bootmem(size);
  151. if (!new_log_buf) {
  152. printk(KERN_WARNING "log_buf_len: allocation failed\n");
  153. goto out;
  154. }
  155. spin_lock_irqsave(&logbuf_lock, flags);
  156. log_buf_len = size;
  157. log_buf = new_log_buf;
  158. offset = start = min(con_start, log_start);
  159. dest_idx = 0;
  160. while (start != log_end) {
  161. log_buf[dest_idx] = __log_buf[start & (__LOG_BUF_LEN - 1)];
  162. start++;
  163. dest_idx++;
  164. }
  165. log_start -= offset;
  166. con_start -= offset;
  167. log_end -= offset;
  168. spin_unlock_irqrestore(&logbuf_lock, flags);
  169. printk(KERN_NOTICE "log_buf_len: %d\n", log_buf_len);
  170. }
  171. out:
  172. return 1;
  173. }
  174. __setup("log_buf_len=", log_buf_len_setup);
  175. #ifdef CONFIG_BOOT_PRINTK_DELAY
  176. static unsigned int boot_delay; /* msecs delay after each printk during bootup */
  177. static unsigned long long loops_per_msec; /* based on boot_delay */
  178. static int __init boot_delay_setup(char *str)
  179. {
  180. unsigned long lpj;
  181. lpj = preset_lpj ? preset_lpj : 1000000; /* some guess */
  182. loops_per_msec = (unsigned long long)lpj / 1000 * HZ;
  183. get_option(&str, &boot_delay);
  184. if (boot_delay > 10 * 1000)
  185. boot_delay = 0;
  186. pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
  187. "HZ: %d, loops_per_msec: %llu\n",
  188. boot_delay, preset_lpj, lpj, HZ, loops_per_msec);
  189. return 1;
  190. }
  191. __setup("boot_delay=", boot_delay_setup);
  192. static void boot_delay_msec(void)
  193. {
  194. unsigned long long k;
  195. unsigned long timeout;
  196. if (boot_delay == 0 || system_state != SYSTEM_BOOTING)
  197. return;
  198. k = (unsigned long long)loops_per_msec * boot_delay;
  199. timeout = jiffies + msecs_to_jiffies(boot_delay);
  200. while (k) {
  201. k--;
  202. cpu_relax();
  203. /*
  204. * use (volatile) jiffies to prevent
  205. * compiler reduction; loop termination via jiffies
  206. * is secondary and may or may not happen.
  207. */
  208. if (time_after(jiffies, timeout))
  209. break;
  210. touch_nmi_watchdog();
  211. }
  212. }
  213. #else
  214. static inline void boot_delay_msec(void)
  215. {
  216. }
  217. #endif
  218. /*
  219. * Commands to do_syslog:
  220. *
  221. * 0 -- Close the log. Currently a NOP.
  222. * 1 -- Open the log. Currently a NOP.
  223. * 2 -- Read from the log.
  224. * 3 -- Read all messages remaining in the ring buffer.
  225. * 4 -- Read and clear all messages remaining in the ring buffer
  226. * 5 -- Clear ring buffer.
  227. * 6 -- Disable printk's to console
  228. * 7 -- Enable printk's to console
  229. * 8 -- Set level of messages printed to console
  230. * 9 -- Return number of unread characters in the log buffer
  231. * 10 -- Return size of the log buffer
  232. */
  233. int do_syslog(int type, char __user *buf, int len)
  234. {
  235. unsigned i, j, limit, count;
  236. int do_clear = 0;
  237. char c;
  238. int error = 0;
  239. error = security_syslog(type);
  240. if (error)
  241. return error;
  242. switch (type) {
  243. case 0: /* Close log */
  244. break;
  245. case 1: /* Open log */
  246. break;
  247. case 2: /* Read from log */
  248. error = -EINVAL;
  249. if (!buf || len < 0)
  250. goto out;
  251. error = 0;
  252. if (!len)
  253. goto out;
  254. if (!access_ok(VERIFY_WRITE, buf, len)) {
  255. error = -EFAULT;
  256. goto out;
  257. }
  258. error = wait_event_interruptible(log_wait,
  259. (log_start - log_end));
  260. if (error)
  261. goto out;
  262. i = 0;
  263. spin_lock_irq(&logbuf_lock);
  264. while (!error && (log_start != log_end) && i < len) {
  265. c = LOG_BUF(log_start);
  266. log_start++;
  267. spin_unlock_irq(&logbuf_lock);
  268. error = __put_user(c,buf);
  269. buf++;
  270. i++;
  271. cond_resched();
  272. spin_lock_irq(&logbuf_lock);
  273. }
  274. spin_unlock_irq(&logbuf_lock);
  275. if (!error)
  276. error = i;
  277. break;
  278. case 4: /* Read/clear last kernel messages */
  279. do_clear = 1;
  280. /* FALL THRU */
  281. case 3: /* Read last kernel messages */
  282. error = -EINVAL;
  283. if (!buf || len < 0)
  284. goto out;
  285. error = 0;
  286. if (!len)
  287. goto out;
  288. if (!access_ok(VERIFY_WRITE, buf, len)) {
  289. error = -EFAULT;
  290. goto out;
  291. }
  292. count = len;
  293. if (count > log_buf_len)
  294. count = log_buf_len;
  295. spin_lock_irq(&logbuf_lock);
  296. if (count > logged_chars)
  297. count = logged_chars;
  298. if (do_clear)
  299. logged_chars = 0;
  300. limit = log_end;
  301. /*
  302. * __put_user() could sleep, and while we sleep
  303. * printk() could overwrite the messages
  304. * we try to copy to user space. Therefore
  305. * the messages are copied in reverse. <manfreds>
  306. */
  307. for (i = 0; i < count && !error; i++) {
  308. j = limit-1-i;
  309. if (j + log_buf_len < log_end)
  310. break;
  311. c = LOG_BUF(j);
  312. spin_unlock_irq(&logbuf_lock);
  313. error = __put_user(c,&buf[count-1-i]);
  314. cond_resched();
  315. spin_lock_irq(&logbuf_lock);
  316. }
  317. spin_unlock_irq(&logbuf_lock);
  318. if (error)
  319. break;
  320. error = i;
  321. if (i != count) {
  322. int offset = count-error;
  323. /* buffer overflow during copy, correct user buffer. */
  324. for (i = 0; i < error; i++) {
  325. if (__get_user(c,&buf[i+offset]) ||
  326. __put_user(c,&buf[i])) {
  327. error = -EFAULT;
  328. break;
  329. }
  330. cond_resched();
  331. }
  332. }
  333. break;
  334. case 5: /* Clear ring buffer */
  335. logged_chars = 0;
  336. break;
  337. case 6: /* Disable logging to console */
  338. if (saved_console_loglevel == -1)
  339. saved_console_loglevel = console_loglevel;
  340. console_loglevel = minimum_console_loglevel;
  341. break;
  342. case 7: /* Enable logging to console */
  343. if (saved_console_loglevel != -1) {
  344. console_loglevel = saved_console_loglevel;
  345. saved_console_loglevel = -1;
  346. }
  347. break;
  348. case 8: /* Set level of messages printed to console */
  349. error = -EINVAL;
  350. if (len < 1 || len > 8)
  351. goto out;
  352. if (len < minimum_console_loglevel)
  353. len = minimum_console_loglevel;
  354. console_loglevel = len;
  355. /* Implicitly re-enable logging to console */
  356. saved_console_loglevel = -1;
  357. error = 0;
  358. break;
  359. case 9: /* Number of chars in the log buffer */
  360. error = log_end - log_start;
  361. break;
  362. case 10: /* Size of the log buffer */
  363. error = log_buf_len;
  364. break;
  365. default:
  366. error = -EINVAL;
  367. break;
  368. }
  369. out:
  370. return error;
  371. }
  372. SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
  373. {
  374. return do_syslog(type, buf, len);
  375. }
  376. /*
  377. * Call the console drivers on a range of log_buf
  378. */
  379. static void __call_console_drivers(unsigned start, unsigned end)
  380. {
  381. struct console *con;
  382. for_each_console(con) {
  383. if ((con->flags & CON_ENABLED) && con->write &&
  384. (cpu_online(smp_processor_id()) ||
  385. (con->flags & CON_ANYTIME)))
  386. con->write(con, &LOG_BUF(start), end - start);
  387. }
  388. }
  389. static int __read_mostly ignore_loglevel;
  390. static int __init ignore_loglevel_setup(char *str)
  391. {
  392. ignore_loglevel = 1;
  393. printk(KERN_INFO "debug: ignoring loglevel setting.\n");
  394. return 0;
  395. }
  396. early_param("ignore_loglevel", ignore_loglevel_setup);
  397. /*
  398. * Write out chars from start to end - 1 inclusive
  399. */
  400. static void _call_console_drivers(unsigned start,
  401. unsigned end, int msg_log_level)
  402. {
  403. if ((msg_log_level < console_loglevel || ignore_loglevel) &&
  404. console_drivers && start != end) {
  405. if ((start & LOG_BUF_MASK) > (end & LOG_BUF_MASK)) {
  406. /* wrapped write */
  407. __call_console_drivers(start & LOG_BUF_MASK,
  408. log_buf_len);
  409. __call_console_drivers(0, end & LOG_BUF_MASK);
  410. } else {
  411. __call_console_drivers(start, end);
  412. }
  413. }
  414. }
  415. /*
  416. * Call the console drivers, asking them to write out
  417. * log_buf[start] to log_buf[end - 1].
  418. * The console_sem must be held.
  419. */
  420. static void call_console_drivers(unsigned start, unsigned end)
  421. {
  422. unsigned cur_index, start_print;
  423. static int msg_level = -1;
  424. BUG_ON(((int)(start - end)) > 0);
  425. cur_index = start;
  426. start_print = start;
  427. while (cur_index != end) {
  428. if (msg_level < 0 && ((end - cur_index) > 2) &&
  429. LOG_BUF(cur_index + 0) == '<' &&
  430. LOG_BUF(cur_index + 1) >= '0' &&
  431. LOG_BUF(cur_index + 1) <= '7' &&
  432. LOG_BUF(cur_index + 2) == '>') {
  433. msg_level = LOG_BUF(cur_index + 1) - '0';
  434. cur_index += 3;
  435. start_print = cur_index;
  436. }
  437. while (cur_index != end) {
  438. char c = LOG_BUF(cur_index);
  439. cur_index++;
  440. if (c == '\n') {
  441. if (msg_level < 0) {
  442. /*
  443. * printk() has already given us loglevel tags in
  444. * the buffer. This code is here in case the
  445. * log buffer has wrapped right round and scribbled
  446. * on those tags
  447. */
  448. msg_level = default_message_loglevel;
  449. }
  450. _call_console_drivers(start_print, cur_index, msg_level);
  451. msg_level = -1;
  452. start_print = cur_index;
  453. break;
  454. }
  455. }
  456. }
  457. _call_console_drivers(start_print, end, msg_level);
  458. }
  459. static void emit_log_char(char c)
  460. {
  461. LOG_BUF(log_end) = c;
  462. log_end++;
  463. if (log_end - log_start > log_buf_len)
  464. log_start = log_end - log_buf_len;
  465. if (log_end - con_start > log_buf_len)
  466. con_start = log_end - log_buf_len;
  467. if (logged_chars < log_buf_len)
  468. logged_chars++;
  469. }
  470. /*
  471. * Zap console related locks when oopsing. Only zap at most once
  472. * every 10 seconds, to leave time for slow consoles to print a
  473. * full oops.
  474. */
  475. static void zap_locks(void)
  476. {
  477. static unsigned long oops_timestamp;
  478. if (time_after_eq(jiffies, oops_timestamp) &&
  479. !time_after(jiffies, oops_timestamp + 30 * HZ))
  480. return;
  481. oops_timestamp = jiffies;
  482. /* If a crash is occurring, make sure we can't deadlock */
  483. spin_lock_init(&logbuf_lock);
  484. /* And make sure that we print immediately */
  485. init_MUTEX(&console_sem);
  486. }
  487. #if defined(CONFIG_PRINTK_TIME)
  488. static int printk_time = 1;
  489. #else
  490. static int printk_time = 0;
  491. #endif
  492. module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
  493. /* Check if we have any console registered that can be called early in boot. */
  494. static int have_callable_console(void)
  495. {
  496. struct console *con;
  497. for_each_console(con)
  498. if (con->flags & CON_ANYTIME)
  499. return 1;
  500. return 0;
  501. }
  502. /**
  503. * printk - print a kernel message
  504. * @fmt: format string
  505. *
  506. * This is printk(). It can be called from any context. We want it to work.
  507. *
  508. * We try to grab the console_sem. If we succeed, it's easy - we log the output and
  509. * call the console drivers. If we fail to get the semaphore we place the output
  510. * into the log buffer and return. The current holder of the console_sem will
  511. * notice the new output in release_console_sem() and will send it to the
  512. * consoles before releasing the semaphore.
  513. *
  514. * One effect of this deferred printing is that code which calls printk() and
  515. * then changes console_loglevel may break. This is because console_loglevel
  516. * is inspected when the actual printing occurs.
  517. *
  518. * See also:
  519. * printf(3)
  520. *
  521. * See the vsnprintf() documentation for format string extensions over C99.
  522. */
  523. asmlinkage int printk(const char *fmt, ...)
  524. {
  525. va_list args;
  526. int r;
  527. va_start(args, fmt);
  528. r = vprintk(fmt, args);
  529. va_end(args);
  530. return r;
  531. }
  532. /* cpu currently holding logbuf_lock */
  533. static volatile unsigned int printk_cpu = UINT_MAX;
  534. /*
  535. * Can we actually use the console at this time on this cpu?
  536. *
  537. * Console drivers may assume that per-cpu resources have
  538. * been allocated. So unless they're explicitly marked as
  539. * being able to cope (CON_ANYTIME) don't call them until
  540. * this CPU is officially up.
  541. */
  542. static inline int can_use_console(unsigned int cpu)
  543. {
  544. return cpu_online(cpu) || have_callable_console();
  545. }
  546. /*
  547. * Try to get console ownership to actually show the kernel
  548. * messages from a 'printk'. Return true (and with the
  549. * console_semaphore held, and 'console_locked' set) if it
  550. * is successful, false otherwise.
  551. *
  552. * This gets called with the 'logbuf_lock' spinlock held and
  553. * interrupts disabled. It should return with 'lockbuf_lock'
  554. * released but interrupts still disabled.
  555. */
  556. static int acquire_console_semaphore_for_printk(unsigned int cpu)
  557. {
  558. int retval = 0;
  559. if (!try_acquire_console_sem()) {
  560. retval = 1;
  561. /*
  562. * If we can't use the console, we need to release
  563. * the console semaphore by hand to avoid flushing
  564. * the buffer. We need to hold the console semaphore
  565. * in order to do this test safely.
  566. */
  567. if (!can_use_console(cpu)) {
  568. console_locked = 0;
  569. up(&console_sem);
  570. retval = 0;
  571. }
  572. }
  573. printk_cpu = UINT_MAX;
  574. spin_unlock(&logbuf_lock);
  575. return retval;
  576. }
  577. static const char recursion_bug_msg [] =
  578. KERN_CRIT "BUG: recent printk recursion!\n";
  579. static int recursion_bug;
  580. static int new_text_line = 1;
  581. static char printk_buf[1024];
  582. asmlinkage int vprintk(const char *fmt, va_list args)
  583. {
  584. int printed_len = 0;
  585. int current_log_level = default_message_loglevel;
  586. unsigned long flags;
  587. int this_cpu;
  588. char *p;
  589. boot_delay_msec();
  590. preempt_disable();
  591. /* This stops the holder of console_sem just where we want him */
  592. raw_local_irq_save(flags);
  593. this_cpu = smp_processor_id();
  594. /*
  595. * Ouch, printk recursed into itself!
  596. */
  597. if (unlikely(printk_cpu == this_cpu)) {
  598. /*
  599. * If a crash is occurring during printk() on this CPU,
  600. * then try to get the crash message out but make sure
  601. * we can't deadlock. Otherwise just return to avoid the
  602. * recursion and return - but flag the recursion so that
  603. * it can be printed at the next appropriate moment:
  604. */
  605. if (!oops_in_progress) {
  606. recursion_bug = 1;
  607. goto out_restore_irqs;
  608. }
  609. zap_locks();
  610. }
  611. lockdep_off();
  612. spin_lock(&logbuf_lock);
  613. printk_cpu = this_cpu;
  614. if (recursion_bug) {
  615. recursion_bug = 0;
  616. strcpy(printk_buf, recursion_bug_msg);
  617. printed_len = strlen(recursion_bug_msg);
  618. }
  619. /* Emit the output into the temporary buffer */
  620. printed_len += vscnprintf(printk_buf + printed_len,
  621. sizeof(printk_buf) - printed_len, fmt, args);
  622. p = printk_buf;
  623. /* Do we have a loglevel in the string? */
  624. if (p[0] == '<') {
  625. unsigned char c = p[1];
  626. if (c && p[2] == '>') {
  627. switch (c) {
  628. case '0' ... '7': /* loglevel */
  629. current_log_level = c - '0';
  630. /* Fallthrough - make sure we're on a new line */
  631. case 'd': /* KERN_DEFAULT */
  632. if (!new_text_line) {
  633. emit_log_char('\n');
  634. new_text_line = 1;
  635. }
  636. /* Fallthrough - skip the loglevel */
  637. case 'c': /* KERN_CONT */
  638. p += 3;
  639. break;
  640. }
  641. }
  642. }
  643. /*
  644. * Copy the output into log_buf. If the caller didn't provide
  645. * appropriate log level tags, we insert them here
  646. */
  647. for ( ; *p; p++) {
  648. if (new_text_line) {
  649. /* Always output the token */
  650. emit_log_char('<');
  651. emit_log_char(current_log_level + '0');
  652. emit_log_char('>');
  653. printed_len += 3;
  654. new_text_line = 0;
  655. if (printk_time) {
  656. /* Follow the token with the time */
  657. char tbuf[50], *tp;
  658. unsigned tlen;
  659. unsigned long long t;
  660. unsigned long nanosec_rem;
  661. t = cpu_clock(printk_cpu);
  662. nanosec_rem = do_div(t, 1000000000);
  663. tlen = sprintf(tbuf, "[%5lu.%06lu] ",
  664. (unsigned long) t,
  665. nanosec_rem / 1000);
  666. for (tp = tbuf; tp < tbuf + tlen; tp++)
  667. emit_log_char(*tp);
  668. printed_len += tlen;
  669. }
  670. if (!*p)
  671. break;
  672. }
  673. emit_log_char(*p);
  674. if (*p == '\n')
  675. new_text_line = 1;
  676. }
  677. /*
  678. * Try to acquire and then immediately release the
  679. * console semaphore. The release will do all the
  680. * actual magic (print out buffers, wake up klogd,
  681. * etc).
  682. *
  683. * The acquire_console_semaphore_for_printk() function
  684. * will release 'logbuf_lock' regardless of whether it
  685. * actually gets the semaphore or not.
  686. */
  687. if (acquire_console_semaphore_for_printk(this_cpu))
  688. release_console_sem();
  689. lockdep_on();
  690. out_restore_irqs:
  691. raw_local_irq_restore(flags);
  692. preempt_enable();
  693. return printed_len;
  694. }
  695. EXPORT_SYMBOL(printk);
  696. EXPORT_SYMBOL(vprintk);
  697. #else
  698. static void call_console_drivers(unsigned start, unsigned end)
  699. {
  700. }
  701. #endif
  702. static int __add_preferred_console(char *name, int idx, char *options,
  703. char *brl_options)
  704. {
  705. struct console_cmdline *c;
  706. int i;
  707. /*
  708. * See if this tty is not yet registered, and
  709. * if we have a slot free.
  710. */
  711. for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)
  712. if (strcmp(console_cmdline[i].name, name) == 0 &&
  713. console_cmdline[i].index == idx) {
  714. if (!brl_options)
  715. selected_console = i;
  716. return 0;
  717. }
  718. if (i == MAX_CMDLINECONSOLES)
  719. return -E2BIG;
  720. if (!brl_options)
  721. selected_console = i;
  722. c = &console_cmdline[i];
  723. strlcpy(c->name, name, sizeof(c->name));
  724. c->options = options;
  725. #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
  726. c->brl_options = brl_options;
  727. #endif
  728. c->index = idx;
  729. return 0;
  730. }
  731. /*
  732. * Set up a list of consoles. Called from init/main.c
  733. */
  734. static int __init console_setup(char *str)
  735. {
  736. char buf[sizeof(console_cmdline[0].name) + 4]; /* 4 for index */
  737. char *s, *options, *brl_options = NULL;
  738. int idx;
  739. #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
  740. if (!memcmp(str, "brl,", 4)) {
  741. brl_options = "";
  742. str += 4;
  743. } else if (!memcmp(str, "brl=", 4)) {
  744. brl_options = str + 4;
  745. str = strchr(brl_options, ',');
  746. if (!str) {
  747. printk(KERN_ERR "need port name after brl=\n");
  748. return 1;
  749. }
  750. *(str++) = 0;
  751. }
  752. #endif
  753. /*
  754. * Decode str into name, index, options.
  755. */
  756. if (str[0] >= '0' && str[0] <= '9') {
  757. strcpy(buf, "ttyS");
  758. strncpy(buf + 4, str, sizeof(buf) - 5);
  759. } else {
  760. strncpy(buf, str, sizeof(buf) - 1);
  761. }
  762. buf[sizeof(buf) - 1] = 0;
  763. if ((options = strchr(str, ',')) != NULL)
  764. *(options++) = 0;
  765. #ifdef __sparc__
  766. if (!strcmp(str, "ttya"))
  767. strcpy(buf, "ttyS0");
  768. if (!strcmp(str, "ttyb"))
  769. strcpy(buf, "ttyS1");
  770. #endif
  771. for (s = buf; *s; s++)
  772. if ((*s >= '0' && *s <= '9') || *s == ',')
  773. break;
  774. idx = simple_strtoul(s, NULL, 10);
  775. *s = 0;
  776. __add_preferred_console(buf, idx, options, brl_options);
  777. console_set_on_cmdline = 1;
  778. return 1;
  779. }
  780. __setup("console=", console_setup);
  781. /**
  782. * add_preferred_console - add a device to the list of preferred consoles.
  783. * @name: device name
  784. * @idx: device index
  785. * @options: options for this console
  786. *
  787. * The last preferred console added will be used for kernel messages
  788. * and stdin/out/err for init. Normally this is used by console_setup
  789. * above to handle user-supplied console arguments; however it can also
  790. * be used by arch-specific code either to override the user or more
  791. * commonly to provide a default console (ie from PROM variables) when
  792. * the user has not supplied one.
  793. */
  794. int add_preferred_console(char *name, int idx, char *options)
  795. {
  796. return __add_preferred_console(name, idx, options, NULL);
  797. }
  798. int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, char *options)
  799. {
  800. struct console_cmdline *c;
  801. int i;
  802. for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)
  803. if (strcmp(console_cmdline[i].name, name) == 0 &&
  804. console_cmdline[i].index == idx) {
  805. c = &console_cmdline[i];
  806. strlcpy(c->name, name_new, sizeof(c->name));
  807. c->name[sizeof(c->name) - 1] = 0;
  808. c->options = options;
  809. c->index = idx_new;
  810. return i;
  811. }
  812. /* not found */
  813. return -1;
  814. }
  815. int console_suspend_enabled = 1;
  816. EXPORT_SYMBOL(console_suspend_enabled);
  817. static int __init console_suspend_disable(char *str)
  818. {
  819. console_suspend_enabled = 0;
  820. return 1;
  821. }
  822. __setup("no_console_suspend", console_suspend_disable);
  823. /**
  824. * suspend_console - suspend the console subsystem
  825. *
  826. * This disables printk() while we go into suspend states
  827. */
  828. void suspend_console(void)
  829. {
  830. if (!console_suspend_enabled)
  831. return;
  832. printk("Suspending console(s) (use no_console_suspend to debug)\n");
  833. acquire_console_sem();
  834. console_suspended = 1;
  835. up(&console_sem);
  836. }
  837. void resume_console(void)
  838. {
  839. if (!console_suspend_enabled)
  840. return;
  841. down(&console_sem);
  842. console_suspended = 0;
  843. release_console_sem();
  844. }
  845. /**
  846. * acquire_console_sem - lock the console system for exclusive use.
  847. *
  848. * Acquires a semaphore which guarantees that the caller has
  849. * exclusive access to the console system and the console_drivers list.
  850. *
  851. * Can sleep, returns nothing.
  852. */
  853. void acquire_console_sem(void)
  854. {
  855. BUG_ON(in_interrupt());
  856. down(&console_sem);
  857. if (console_suspended)
  858. return;
  859. console_locked = 1;
  860. console_may_schedule = 1;
  861. }
  862. EXPORT_SYMBOL(acquire_console_sem);
  863. int try_acquire_console_sem(void)
  864. {
  865. if (down_trylock(&console_sem))
  866. return -1;
  867. if (console_suspended) {
  868. up(&console_sem);
  869. return -1;
  870. }
  871. console_locked = 1;
  872. console_may_schedule = 0;
  873. return 0;
  874. }
  875. EXPORT_SYMBOL(try_acquire_console_sem);
  876. int is_console_locked(void)
  877. {
  878. return console_locked;
  879. }
  880. static DEFINE_PER_CPU(int, printk_pending);
  881. void printk_tick(void)
  882. {
  883. if (__get_cpu_var(printk_pending)) {
  884. __get_cpu_var(printk_pending) = 0;
  885. wake_up_interruptible(&log_wait);
  886. }
  887. }
  888. int printk_needs_cpu(int cpu)
  889. {
  890. return per_cpu(printk_pending, cpu);
  891. }
  892. void wake_up_klogd(void)
  893. {
  894. if (waitqueue_active(&log_wait))
  895. __raw_get_cpu_var(printk_pending) = 1;
  896. }
  897. /**
  898. * release_console_sem - unlock the console system
  899. *
  900. * Releases the semaphore which the caller holds on the console system
  901. * and the console driver list.
  902. *
  903. * While the semaphore was held, console output may have been buffered
  904. * by printk(). If this is the case, release_console_sem() emits
  905. * the output prior to releasing the semaphore.
  906. *
  907. * If there is output waiting for klogd, we wake it up.
  908. *
  909. * release_console_sem() may be called from any context.
  910. */
  911. void release_console_sem(void)
  912. {
  913. unsigned long flags;
  914. unsigned _con_start, _log_end;
  915. unsigned wake_klogd = 0;
  916. if (console_suspended) {
  917. up(&console_sem);
  918. return;
  919. }
  920. console_may_schedule = 0;
  921. for ( ; ; ) {
  922. spin_lock_irqsave(&logbuf_lock, flags);
  923. wake_klogd |= log_start - log_end;
  924. if (con_start == log_end)
  925. break; /* Nothing to print */
  926. _con_start = con_start;
  927. _log_end = log_end;
  928. con_start = log_end; /* Flush */
  929. spin_unlock(&logbuf_lock);
  930. stop_critical_timings(); /* don't trace print latency */
  931. call_console_drivers(_con_start, _log_end);
  932. start_critical_timings();
  933. local_irq_restore(flags);
  934. }
  935. console_locked = 0;
  936. up(&console_sem);
  937. spin_unlock_irqrestore(&logbuf_lock, flags);
  938. if (wake_klogd)
  939. wake_up_klogd();
  940. }
  941. EXPORT_SYMBOL(release_console_sem);
  942. /**
  943. * console_conditional_schedule - yield the CPU if required
  944. *
  945. * If the console code is currently allowed to sleep, and
  946. * if this CPU should yield the CPU to another task, do
  947. * so here.
  948. *
  949. * Must be called within acquire_console_sem().
  950. */
  951. void __sched console_conditional_schedule(void)
  952. {
  953. if (console_may_schedule)
  954. cond_resched();
  955. }
  956. EXPORT_SYMBOL(console_conditional_schedule);
  957. void console_unblank(void)
  958. {
  959. struct console *c;
  960. /*
  961. * console_unblank can no longer be called in interrupt context unless
  962. * oops_in_progress is set to 1..
  963. */
  964. if (oops_in_progress) {
  965. if (down_trylock(&console_sem) != 0)
  966. return;
  967. } else
  968. acquire_console_sem();
  969. console_locked = 1;
  970. console_may_schedule = 0;
  971. for_each_console(c)
  972. if ((c->flags & CON_ENABLED) && c->unblank)
  973. c->unblank();
  974. release_console_sem();
  975. }
  976. /*
  977. * Return the console tty driver structure and its associated index
  978. */
  979. struct tty_driver *console_device(int *index)
  980. {
  981. struct console *c;
  982. struct tty_driver *driver = NULL;
  983. acquire_console_sem();
  984. for_each_console(c) {
  985. if (!c->device)
  986. continue;
  987. driver = c->device(c, index);
  988. if (driver)
  989. break;
  990. }
  991. release_console_sem();
  992. return driver;
  993. }
  994. /*
  995. * Prevent further output on the passed console device so that (for example)
  996. * serial drivers can disable console output before suspending a port, and can
  997. * re-enable output afterwards.
  998. */
  999. void console_stop(struct console *console)
  1000. {
  1001. acquire_console_sem();
  1002. console->flags &= ~CON_ENABLED;
  1003. release_console_sem();
  1004. }
  1005. EXPORT_SYMBOL(console_stop);
  1006. void console_start(struct console *console)
  1007. {
  1008. acquire_console_sem();
  1009. console->flags |= CON_ENABLED;
  1010. release_console_sem();
  1011. }
  1012. EXPORT_SYMBOL(console_start);
  1013. /*
  1014. * The console driver calls this routine during kernel initialization
  1015. * to register the console printing procedure with printk() and to
  1016. * print any messages that were printed by the kernel before the
  1017. * console driver was initialized.
  1018. *
  1019. * This can happen pretty early during the boot process (because of
  1020. * early_printk) - sometimes before setup_arch() completes - be careful
  1021. * of what kernel features are used - they may not be initialised yet.
  1022. *
  1023. * There are two types of consoles - bootconsoles (early_printk) and
  1024. * "real" consoles (everything which is not a bootconsole) which are
  1025. * handled differently.
  1026. * - Any number of bootconsoles can be registered at any time.
  1027. * - As soon as a "real" console is registered, all bootconsoles
  1028. * will be unregistered automatically.
  1029. * - Once a "real" console is registered, any attempt to register a
  1030. * bootconsoles will be rejected
  1031. */
  1032. void register_console(struct console *newcon)
  1033. {
  1034. int i;
  1035. unsigned long flags;
  1036. struct console *bcon = NULL;
  1037. /*
  1038. * before we register a new CON_BOOT console, make sure we don't
  1039. * already have a valid console
  1040. */
  1041. if (console_drivers && newcon->flags & CON_BOOT) {
  1042. /* find the last or real console */
  1043. for_each_console(bcon) {
  1044. if (!(bcon->flags & CON_BOOT)) {
  1045. printk(KERN_INFO "Too late to register bootconsole %s%d\n",
  1046. newcon->name, newcon->index);
  1047. return;
  1048. }
  1049. }
  1050. }
  1051. if (console_drivers && console_drivers->flags & CON_BOOT)
  1052. bcon = console_drivers;
  1053. if (preferred_console < 0 || bcon || !console_drivers)
  1054. preferred_console = selected_console;
  1055. if (newcon->early_setup)
  1056. newcon->early_setup();
  1057. /*
  1058. * See if we want to use this console driver. If we
  1059. * didn't select a console we take the first one
  1060. * that registers here.
  1061. */
  1062. if (preferred_console < 0) {
  1063. if (newcon->index < 0)
  1064. newcon->index = 0;
  1065. if (newcon->setup == NULL ||
  1066. newcon->setup(newcon, NULL) == 0) {
  1067. newcon->flags |= CON_ENABLED;
  1068. if (newcon->device) {
  1069. newcon->flags |= CON_CONSDEV;
  1070. preferred_console = 0;
  1071. }
  1072. }
  1073. }
  1074. /*
  1075. * See if this console matches one we selected on
  1076. * the command line.
  1077. */
  1078. for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0];
  1079. i++) {
  1080. if (strcmp(console_cmdline[i].name, newcon->name) != 0)
  1081. continue;
  1082. if (newcon->index >= 0 &&
  1083. newcon->index != console_cmdline[i].index)
  1084. continue;
  1085. if (newcon->index < 0)
  1086. newcon->index = console_cmdline[i].index;
  1087. #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
  1088. if (console_cmdline[i].brl_options) {
  1089. newcon->flags |= CON_BRL;
  1090. braille_register_console(newcon,
  1091. console_cmdline[i].index,
  1092. console_cmdline[i].options,
  1093. console_cmdline[i].brl_options);
  1094. return;
  1095. }
  1096. #endif
  1097. if (newcon->setup &&
  1098. newcon->setup(newcon, console_cmdline[i].options) != 0)
  1099. break;
  1100. newcon->flags |= CON_ENABLED;
  1101. newcon->index = console_cmdline[i].index;
  1102. if (i == selected_console) {
  1103. newcon->flags |= CON_CONSDEV;
  1104. preferred_console = selected_console;
  1105. }
  1106. break;
  1107. }
  1108. if (!(newcon->flags & CON_ENABLED))
  1109. return;
  1110. /*
  1111. * If we have a bootconsole, and are switching to a real console,
  1112. * don't print everything out again, since when the boot console, and
  1113. * the real console are the same physical device, it's annoying to
  1114. * see the beginning boot messages twice
  1115. */
  1116. if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV))
  1117. newcon->flags &= ~CON_PRINTBUFFER;
  1118. /*
  1119. * Put this console in the list - keep the
  1120. * preferred driver at the head of the list.
  1121. */
  1122. acquire_console_sem();
  1123. if ((newcon->flags & CON_CONSDEV) || console_drivers == NULL) {
  1124. newcon->next = console_drivers;
  1125. console_drivers = newcon;
  1126. if (newcon->next)
  1127. newcon->next->flags &= ~CON_CONSDEV;
  1128. } else {
  1129. newcon->next = console_drivers->next;
  1130. console_drivers->next = newcon;
  1131. }
  1132. if (newcon->flags & CON_PRINTBUFFER) {
  1133. /*
  1134. * release_console_sem() will print out the buffered messages
  1135. * for us.
  1136. */
  1137. spin_lock_irqsave(&logbuf_lock, flags);
  1138. con_start = log_start;
  1139. spin_unlock_irqrestore(&logbuf_lock, flags);
  1140. }
  1141. release_console_sem();
  1142. /*
  1143. * By unregistering the bootconsoles after we enable the real console
  1144. * we get the "console xxx enabled" message on all the consoles -
  1145. * boot consoles, real consoles, etc - this is to ensure that end
  1146. * users know there might be something in the kernel's log buffer that
  1147. * went to the bootconsole (that they do not see on the real console)
  1148. */
  1149. if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) {
  1150. /* we need to iterate through twice, to make sure we print
  1151. * everything out, before we unregister the console(s)
  1152. */
  1153. printk(KERN_INFO "console [%s%d] enabled, bootconsole disabled\n",
  1154. newcon->name, newcon->index);
  1155. for_each_console(bcon)
  1156. if (bcon->flags & CON_BOOT)
  1157. unregister_console(bcon);
  1158. } else {
  1159. printk(KERN_INFO "%sconsole [%s%d] enabled\n",
  1160. (newcon->flags & CON_BOOT) ? "boot" : "" ,
  1161. newcon->name, newcon->index);
  1162. }
  1163. }
  1164. EXPORT_SYMBOL(register_console);
  1165. int unregister_console(struct console *console)
  1166. {
  1167. struct console *a, *b;
  1168. int res = 1;
  1169. #ifdef CONFIG_A11Y_BRAILLE_CONSOLE
  1170. if (console->flags & CON_BRL)
  1171. return braille_unregister_console(console);
  1172. #endif
  1173. acquire_console_sem();
  1174. if (console_drivers == console) {
  1175. console_drivers=console->next;
  1176. res = 0;
  1177. } else if (console_drivers) {
  1178. for (a=console_drivers->next, b=console_drivers ;
  1179. a; b=a, a=b->next) {
  1180. if (a == console) {
  1181. b->next = a->next;
  1182. res = 0;
  1183. break;
  1184. }
  1185. }
  1186. }
  1187. /*
  1188. * If this isn't the last console and it has CON_CONSDEV set, we
  1189. * need to set it on the next preferred console.
  1190. */
  1191. if (console_drivers != NULL && console->flags & CON_CONSDEV)
  1192. console_drivers->flags |= CON_CONSDEV;
  1193. release_console_sem();
  1194. return res;
  1195. }
  1196. EXPORT_SYMBOL(unregister_console);
  1197. static int __init disable_boot_consoles(void)
  1198. {
  1199. struct console *con;
  1200. for_each_console(con) {
  1201. if (con->flags & CON_BOOT) {
  1202. printk(KERN_INFO "turn off boot console %s%d\n",
  1203. con->name, con->index);
  1204. unregister_console(con);
  1205. }
  1206. }
  1207. return 0;
  1208. }
  1209. late_initcall(disable_boot_consoles);
  1210. #if defined CONFIG_PRINTK
  1211. /*
  1212. * printk rate limiting, lifted from the networking subsystem.
  1213. *
  1214. * This enforces a rate limit: not more than 10 kernel messages
  1215. * every 5s to make a denial-of-service attack impossible.
  1216. */
  1217. DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
  1218. int printk_ratelimit(void)
  1219. {
  1220. return __ratelimit(&printk_ratelimit_state);
  1221. }
  1222. EXPORT_SYMBOL(printk_ratelimit);
  1223. /**
  1224. * printk_timed_ratelimit - caller-controlled printk ratelimiting
  1225. * @caller_jiffies: pointer to caller's state
  1226. * @interval_msecs: minimum interval between prints
  1227. *
  1228. * printk_timed_ratelimit() returns true if more than @interval_msecs
  1229. * milliseconds have elapsed since the last time printk_timed_ratelimit()
  1230. * returned true.
  1231. */
  1232. bool printk_timed_ratelimit(unsigned long *caller_jiffies,
  1233. unsigned int interval_msecs)
  1234. {
  1235. if (*caller_jiffies == 0
  1236. || !time_in_range(jiffies, *caller_jiffies,
  1237. *caller_jiffies
  1238. + msecs_to_jiffies(interval_msecs))) {
  1239. *caller_jiffies = jiffies;
  1240. return true;
  1241. }
  1242. return false;
  1243. }
  1244. EXPORT_SYMBOL(printk_timed_ratelimit);
  1245. #endif