printk-formats.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. If variable is of Type, use printk format specifier:
  2. ---------------------------------------------------------
  3. int %d or %x
  4. unsigned int %u or %x
  5. long %ld or %lx
  6. unsigned long %lu or %lx
  7. long long %lld or %llx
  8. unsigned long long %llu or %llx
  9. size_t %zu or %zx
  10. ssize_t %zd or %zx
  11. s32 %d or %x
  12. u32 %u or %x
  13. s64 %lld or %llx
  14. u64 %llu or %llx
  15. If <type> is dependent on a config option for its size (e.g., sector_t,
  16. blkcnt_t) or is architecture-dependent for its size (e.g., tcflag_t), use a
  17. format specifier of its largest possible type and explicitly cast to it.
  18. Example:
  19. printk("test: sector number/total blocks: %llu/%llu\n",
  20. (unsigned long long)sector, (unsigned long long)blockcount);
  21. Reminder: sizeof() result is of type size_t.
  22. The kernel's printf does not support %n. For obvious reasons, floating
  23. point formats (%e, %f, %g, %a) are also not recognized. Use of any
  24. unsupported specifier or length qualifier results in a WARN and early
  25. return from vsnprintf.
  26. Raw pointer value SHOULD be printed with %p. The kernel supports
  27. the following extended format specifiers for pointer types:
  28. Pointer Types:
  29. Pointers printed without a specifier extension (i.e unadorned %p) are
  30. hashed to give a unique identifier without leaking kernel addresses to user
  31. space. On 64 bit machines the first 32 bits are zeroed. If you _really_
  32. want the address see %px below.
  33. %p abcdef12 or 00000000abcdef12
  34. Symbols/Function Pointers:
  35. %pF versatile_init+0x0/0x110
  36. %pf versatile_init
  37. %pS versatile_init+0x0/0x110
  38. %pSR versatile_init+0x9/0x110
  39. (with __builtin_extract_return_addr() translation)
  40. %ps versatile_init
  41. %pB prev_fn_of_versatile_init+0x88/0x88
  42. For printing symbols and function pointers. The 'S' and 's' specifiers
  43. result in the symbol name with ('S') or without ('s') offsets. Where
  44. this is used on a kernel without KALLSYMS - the symbol address is
  45. printed instead.
  46. The 'B' specifier results in the symbol name with offsets and should be
  47. used when printing stack backtraces. The specifier takes into
  48. consideration the effect of compiler optimisations which may occur
  49. when tail-call's are used and marked with the noreturn GCC attribute.
  50. On ia64, ppc64 and parisc64 architectures function pointers are
  51. actually function descriptors which must first be resolved. The 'F' and
  52. 'f' specifiers perform this resolution and then provide the same
  53. functionality as the 'S' and 's' specifiers.
  54. Kernel Pointers:
  55. %pK 01234567 or 0123456789abcdef
  56. For printing kernel pointers which should be hidden from unprivileged
  57. users. The behaviour of %pK depends on the kptr_restrict sysctl - see
  58. Documentation/sysctl/kernel.txt for more details.
  59. Unmodified Addresses:
  60. %px 01234567 or 0123456789abcdef
  61. For printing pointers when you _really_ want to print the address. Please
  62. consider whether or not you are leaking sensitive information about the
  63. Kernel layout in memory before printing pointers with %px. %px is
  64. functionally equivalent to %lx. %px is preferred to %lx because it is more
  65. uniquely grep'able. If, in the future, we need to modify the way the Kernel
  66. handles printing pointers it will be nice to be able to find the call
  67. sites.
  68. Struct Resources:
  69. %pr [mem 0x60000000-0x6fffffff flags 0x2200] or
  70. [mem 0x0000000060000000-0x000000006fffffff flags 0x2200]
  71. %pR [mem 0x60000000-0x6fffffff pref] or
  72. [mem 0x0000000060000000-0x000000006fffffff pref]
  73. For printing struct resources. The 'R' and 'r' specifiers result in a
  74. printed resource with ('R') or without ('r') a decoded flags member.
  75. Passed by reference.
  76. Physical addresses types phys_addr_t:
  77. %pa[p] 0x01234567 or 0x0123456789abcdef
  78. For printing a phys_addr_t type (and its derivatives, such as
  79. resource_size_t) which can vary based on build options, regardless of
  80. the width of the CPU data path. Passed by reference.
  81. DMA addresses types dma_addr_t:
  82. %pad 0x01234567 or 0x0123456789abcdef
  83. For printing a dma_addr_t type which can vary based on build options,
  84. regardless of the width of the CPU data path. Passed by reference.
  85. Raw buffer as an escaped string:
  86. %*pE[achnops]
  87. For printing raw buffer as an escaped string. For the following buffer
  88. 1b 62 20 5c 43 07 22 90 0d 5d
  89. few examples show how the conversion would be done (the result string
  90. without surrounding quotes):
  91. %*pE "\eb \C\a"\220\r]"
  92. %*pEhp "\x1bb \C\x07"\x90\x0d]"
  93. %*pEa "\e\142\040\\\103\a\042\220\r\135"
  94. The conversion rules are applied according to an optional combination
  95. of flags (see string_escape_mem() kernel documentation for the
  96. details):
  97. a - ESCAPE_ANY
  98. c - ESCAPE_SPECIAL
  99. h - ESCAPE_HEX
  100. n - ESCAPE_NULL
  101. o - ESCAPE_OCTAL
  102. p - ESCAPE_NP
  103. s - ESCAPE_SPACE
  104. By default ESCAPE_ANY_NP is used.
  105. ESCAPE_ANY_NP is the sane choice for many cases, in particularly for
  106. printing SSIDs.
  107. If field width is omitted the 1 byte only will be escaped.
  108. Raw buffer as a hex string:
  109. %*ph 00 01 02 ... 3f
  110. %*phC 00:01:02: ... :3f
  111. %*phD 00-01-02- ... -3f
  112. %*phN 000102 ... 3f
  113. For printing a small buffers (up to 64 bytes long) as a hex string with
  114. certain separator. For the larger buffers consider to use
  115. print_hex_dump().
  116. MAC/FDDI addresses:
  117. %pM 00:01:02:03:04:05
  118. %pMR 05:04:03:02:01:00
  119. %pMF 00-01-02-03-04-05
  120. %pm 000102030405
  121. %pmR 050403020100
  122. For printing 6-byte MAC/FDDI addresses in hex notation. The 'M' and 'm'
  123. specifiers result in a printed address with ('M') or without ('m') byte
  124. separators. The default byte separator is the colon (':').
  125. Where FDDI addresses are concerned the 'F' specifier can be used after
  126. the 'M' specifier to use dash ('-') separators instead of the default
  127. separator.
  128. For Bluetooth addresses the 'R' specifier shall be used after the 'M'
  129. specifier to use reversed byte order suitable for visual interpretation
  130. of Bluetooth addresses which are in the little endian order.
  131. Passed by reference.
  132. IPv4 addresses:
  133. %pI4 1.2.3.4
  134. %pi4 001.002.003.004
  135. %p[Ii]4[hnbl]
  136. For printing IPv4 dot-separated decimal addresses. The 'I4' and 'i4'
  137. specifiers result in a printed address with ('i4') or without ('I4')
  138. leading zeros.
  139. The additional 'h', 'n', 'b', and 'l' specifiers are used to specify
  140. host, network, big or little endian order addresses respectively. Where
  141. no specifier is provided the default network/big endian order is used.
  142. Passed by reference.
  143. IPv6 addresses:
  144. %pI6 0001:0002:0003:0004:0005:0006:0007:0008
  145. %pi6 00010002000300040005000600070008
  146. %pI6c 1:2:3:4:5:6:7:8
  147. For printing IPv6 network-order 16-bit hex addresses. The 'I6' and 'i6'
  148. specifiers result in a printed address with ('I6') or without ('i6')
  149. colon-separators. Leading zeros are always used.
  150. The additional 'c' specifier can be used with the 'I' specifier to
  151. print a compressed IPv6 address as described by
  152. http://tools.ietf.org/html/rfc5952
  153. Passed by reference.
  154. IPv4/IPv6 addresses (generic, with port, flowinfo, scope):
  155. %pIS 1.2.3.4 or 0001:0002:0003:0004:0005:0006:0007:0008
  156. %piS 001.002.003.004 or 00010002000300040005000600070008
  157. %pISc 1.2.3.4 or 1:2:3:4:5:6:7:8
  158. %pISpc 1.2.3.4:12345 or [1:2:3:4:5:6:7:8]:12345
  159. %p[Ii]S[pfschnbl]
  160. For printing an IP address without the need to distinguish whether it's
  161. of type AF_INET or AF_INET6, a pointer to a valid 'struct sockaddr',
  162. specified through 'IS' or 'iS', can be passed to this format specifier.
  163. The additional 'p', 'f', and 's' specifiers are used to specify port
  164. (IPv4, IPv6), flowinfo (IPv6) and scope (IPv6). Ports have a ':' prefix,
  165. flowinfo a '/' and scope a '%', each followed by the actual value.
  166. In case of an IPv6 address the compressed IPv6 address as described by
  167. http://tools.ietf.org/html/rfc5952 is being used if the additional
  168. specifier 'c' is given. The IPv6 address is surrounded by '[', ']' in
  169. case of additional specifiers 'p', 'f' or 's' as suggested by
  170. https://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07
  171. In case of IPv4 addresses, the additional 'h', 'n', 'b', and 'l'
  172. specifiers can be used as well and are ignored in case of an IPv6
  173. address.
  174. Passed by reference.
  175. Further examples:
  176. %pISfc 1.2.3.4 or [1:2:3:4:5:6:7:8]/123456789
  177. %pISsc 1.2.3.4 or [1:2:3:4:5:6:7:8]%1234567890
  178. %pISpfc 1.2.3.4:12345 or [1:2:3:4:5:6:7:8]:12345/123456789
  179. UUID/GUID addresses:
  180. %pUb 00010203-0405-0607-0809-0a0b0c0d0e0f
  181. %pUB 00010203-0405-0607-0809-0A0B0C0D0E0F
  182. %pUl 03020100-0504-0706-0809-0a0b0c0e0e0f
  183. %pUL 03020100-0504-0706-0809-0A0B0C0E0E0F
  184. For printing 16-byte UUID/GUIDs addresses. The additional 'l', 'L',
  185. 'b' and 'B' specifiers are used to specify a little endian order in
  186. lower ('l') or upper case ('L') hex characters - and big endian order
  187. in lower ('b') or upper case ('B') hex characters.
  188. Where no additional specifiers are used the default big endian
  189. order with lower case hex characters will be printed.
  190. Passed by reference.
  191. dentry names:
  192. %pd{,2,3,4}
  193. %pD{,2,3,4}
  194. For printing dentry name; if we race with d_move(), the name might be
  195. a mix of old and new ones, but it won't oops. %pd dentry is a safer
  196. equivalent of %s dentry->d_name.name we used to use, %pd<n> prints
  197. n last components. %pD does the same thing for struct file.
  198. Passed by reference.
  199. block_device names:
  200. %pg sda, sda1 or loop0p1
  201. For printing name of block_device pointers.
  202. struct va_format:
  203. %pV
  204. For printing struct va_format structures. These contain a format string
  205. and va_list as follows:
  206. struct va_format {
  207. const char *fmt;
  208. va_list *va;
  209. };
  210. Implements a "recursive vsnprintf".
  211. Do not use this feature without some mechanism to verify the
  212. correctness of the format string and va_list arguments.
  213. Passed by reference.
  214. struct clk:
  215. %pC pll1
  216. %pCn pll1
  217. For printing struct clk structures. '%pC' and '%pCn' print the name
  218. (Common Clock Framework) or address (legacy clock framework) of the
  219. structure.
  220. Passed by reference.
  221. bitmap and its derivatives such as cpumask and nodemask:
  222. %*pb 0779
  223. %*pbl 0,3-6,8-10
  224. For printing bitmap and its derivatives such as cpumask and nodemask,
  225. %*pb output the bitmap with field width as the number of bits and %*pbl
  226. output the bitmap as range list with field width as the number of bits.
  227. Passed by reference.
  228. Flags bitfields such as page flags, gfp_flags:
  229. %pGp referenced|uptodate|lru|active|private
  230. %pGg GFP_USER|GFP_DMA32|GFP_NOWARN
  231. %pGv read|exec|mayread|maywrite|mayexec|denywrite
  232. For printing flags bitfields as a collection of symbolic constants that
  233. would construct the value. The type of flags is given by the third
  234. character. Currently supported are [p]age flags, [v]ma_flags (both
  235. expect unsigned long *) and [g]fp_flags (expects gfp_t *). The flag
  236. names and print order depends on the particular type.
  237. Note that this format should not be used directly in TP_printk() part
  238. of a tracepoint. Instead, use the show_*_flags() functions from
  239. <trace/events/mmflags.h>.
  240. Passed by reference.
  241. Network device features:
  242. %pNF 0x000000000000c000
  243. For printing netdev_features_t.
  244. Passed by reference.
  245. If you add other %p extensions, please extend lib/test_printf.c with
  246. one or more test cases, if at all feasible.
  247. Thank you for your cooperation and attention.
  248. By Randy Dunlap <[email protected]> and
  249. Andrew Murray <[email protected]>