printk: hash addresses printed with %p
[linux-2.6-block.git] / Documentation / printk-formats.txt
CommitLineData
3b033380
MCC
1=========================================
2How to get printk format specifiers right
3=========================================
4
5:Author: Randy Dunlap <rdunlap@infradead.org>
6:Author: Andrew Murray <amurray@mpc-data.co.uk>
7
3b033380
MCC
8Integer types
9=============
10
11::
12
13 If variable is of Type, use printk format specifier:
14 ------------------------------------------------------------
b67ad18b
RD
15 int %d or %x
16 unsigned int %u or %x
17 long %ld or %lx
18 unsigned long %lu or %lx
19 long long %lld or %llx
20 unsigned long long %llu or %llx
21 size_t %zu or %zx
22 ssize_t %zd or %zx
e8a7ba5f
GU
23 s32 %d or %x
24 u32 %u or %x
25 s64 %lld or %llx
26 u64 %llu or %llx
27
3b033380
MCC
28If <type> is dependent on a config option for its size (e.g., ``sector_t``,
29``blkcnt_t``) or is architecture-dependent for its size (e.g., ``tcflag_t``),
30use a format specifier of its largest possible type and explicitly cast to it.
31
32Example::
e8a7ba5f
GU
33
34 printk("test: sector number/total blocks: %llu/%llu\n",
35 (unsigned long long)sector, (unsigned long long)blockcount);
36
3b033380 37Reminder: ``sizeof()`` result is of type ``size_t``.
e8a7ba5f 38
3b033380
MCC
39The kernel's printf does not support ``%n``. For obvious reasons, floating
40point formats (``%e, %f, %g, %a``) are also not recognized. Use of any
d7ec9a05
RV
41unsupported specifier or length qualifier results in a WARN and early
42return from vsnprintf.
b67ad18b 43
04c55715
AM
44Raw pointer value SHOULD be printed with %p. The kernel supports
45the following extended format specifiers for pointer types:
46
ad67b74d
TH
47Pointer Types
48=============
49
50Pointers printed without a specifier extension (i.e unadorned %p) are
51hashed to give a unique identifier without leaking kernel addresses to user
52space. On 64 bit machines the first 32 bits are zeroed.
53
54::
55
56 %p abcdef12 or 00000000abcdef12
57
3b033380
MCC
58Symbols/Function Pointers
59=========================
60
61::
04c55715
AM
62
63 %pF versatile_init+0x0/0x110
64 %pf versatile_init
65 %pS versatile_init+0x0/0x110
b0d33c2b
JP
66 %pSR versatile_init+0x9/0x110
67 (with __builtin_extract_return_addr() translation)
04c55715
AM
68 %ps versatile_init
69 %pB prev_fn_of_versatile_init+0x88/0x88
70
d6957f33
HD
71The ``F`` and ``f`` specifiers are for printing function pointers,
72for example, f->func, &gettimeofday. They have the same result as
73``S`` and ``s`` specifiers. But they do an extra conversion on
74ia64, ppc64 and parisc64 architectures where the function pointers
75are actually function descriptors.
76
77The ``S`` and ``s`` specifiers can be used for printing symbols
78from direct addresses, for example, __builtin_return_address(0),
79(void *)regs->ip. They result in the symbol name with (``S``) or
80without (``s``) offsets. If KALLSYMS are disabled then the symbol
81address is printed instead.
3b033380
MCC
82
83The ``B`` specifier results in the symbol name with offsets and should be
84used when printing stack backtraces. The specifier takes into
85consideration the effect of compiler optimisations which may occur
86when tail-call``s are used and marked with the noreturn GCC attribute.
04c55715 87
fd46cd55
HD
88Examples::
89
90 printk("Going to call: %pF\n", gettimeofday);
91 printk("Going to call: %pF\n", p->func);
92 printk("%s: called from %pS\n", __func__, (void *)_RET_IP_);
93 printk("%s: called from %pS\n", __func__,
94 (void *)__builtin_return_address(0));
95 printk("Faulted at %pS\n", (void *)regs->ip);
96 printk(" %s%pB\n", (reliable ? "" : "? "), (void *)*stack);
97
3b033380
MCC
98Kernel Pointers
99===============
04c55715 100
3b033380 101::
04c55715 102
553d8e8b 103 %pK 01234567 or 0123456789abcdef
04c55715 104
3b033380
MCC
105For printing kernel pointers which should be hidden from unprivileged
106users. The behaviour of ``%pK`` depends on the ``kptr_restrict sysctl`` - see
107Documentation/sysctl/kernel.txt for more details.
108
109Struct Resources
110================
04c55715 111
3b033380 112::
04c55715
AM
113
114 %pr [mem 0x60000000-0x6fffffff flags 0x2200] or
115 [mem 0x0000000060000000-0x000000006fffffff flags 0x2200]
116 %pR [mem 0x60000000-0x6fffffff pref] or
117 [mem 0x0000000060000000-0x000000006fffffff pref]
118
3b033380
MCC
119For printing struct resources. The ``R`` and ``r`` specifiers result in a
120printed resource with (``R``) or without (``r``) a decoded flags member.
121Passed by reference.
122
123Physical addresses types ``phys_addr_t``
124========================================
04c55715 125
3b033380 126::
7d799210 127
aaf07621 128 %pa[p] 0x01234567 or 0x0123456789abcdef
7d799210 129
3b033380
MCC
130For printing a ``phys_addr_t`` type (and its derivatives, such as
131``resource_size_t``) which can vary based on build options, regardless of
132the width of the CPU data path. Passed by reference.
7d799210 133
3b033380
MCC
134DMA addresses types ``dma_addr_t``
135==================================
136
137::
aaf07621
JP
138
139 %pad 0x01234567 or 0x0123456789abcdef
140
3b033380
MCC
141For printing a ``dma_addr_t`` type which can vary based on build options,
142regardless of the width of the CPU data path. Passed by reference.
143
144Raw buffer as an escaped string
145===============================
aaf07621 146
3b033380 147::
71dca95d
AS
148
149 %*pE[achnops]
150
3b033380 151For printing raw buffer as an escaped string. For the following buffer::
71dca95d
AS
152
153 1b 62 20 5c 43 07 22 90 0d 5d
154
3b033380
MCC
155few examples show how the conversion would be done (the result string
156without surrounding quotes)::
71dca95d
AS
157
158 %*pE "\eb \C\a"\220\r]"
159 %*pEhp "\x1bb \C\x07"\x90\x0d]"
160 %*pEa "\e\142\040\\\103\a\042\220\r\135"
161
3b033380
MCC
162The conversion rules are applied according to an optional combination
163of flags (see :c:func:`string_escape_mem` kernel documentation for the
164details):
165
166 - ``a`` - ESCAPE_ANY
167 - ``c`` - ESCAPE_SPECIAL
168 - ``h`` - ESCAPE_HEX
169 - ``n`` - ESCAPE_NULL
170 - ``o`` - ESCAPE_OCTAL
171 - ``p`` - ESCAPE_NP
172 - ``s`` - ESCAPE_SPACE
71dca95d 173
3b033380 174By default ESCAPE_ANY_NP is used.
71dca95d 175
3b033380
MCC
176ESCAPE_ANY_NP is the sane choice for many cases, in particularly for
177printing SSIDs.
71dca95d 178
3b033380
MCC
179If field width is omitted the 1 byte only will be escaped.
180
181Raw buffer as a hex string
182==========================
183
184::
5e4ee7b1 185
31550a16
AS
186 %*ph 00 01 02 ... 3f
187 %*phC 00:01:02: ... :3f
188 %*phD 00-01-02- ... -3f
189 %*phN 000102 ... 3f
190
3b033380
MCC
191For printing a small buffers (up to 64 bytes long) as a hex string with
192certain separator. For the larger buffers consider to use
193:c:func:`print_hex_dump`.
194
195MAC/FDDI addresses
196==================
31550a16 197
3b033380 198::
04c55715
AM
199
200 %pM 00:01:02:03:04:05
76597ff9 201 %pMR 05:04:03:02:01:00
04c55715
AM
202 %pMF 00-01-02-03-04-05
203 %pm 000102030405
7c59154e 204 %pmR 050403020100
04c55715 205
3b033380
MCC
206For printing 6-byte MAC/FDDI addresses in hex notation. The ``M`` and ``m``
207specifiers result in a printed address with (``M``) or without (``m``) byte
208separators. The default byte separator is the colon (``:``).
04c55715 209
3b033380
MCC
210Where FDDI addresses are concerned the ``F`` specifier can be used after
211the ``M`` specifier to use dash (``-``) separators instead of the default
212separator.
04c55715 213
3b033380
MCC
214For Bluetooth addresses the ``R`` specifier shall be used after the ``M``
215specifier to use reversed byte order suitable for visual interpretation
216of Bluetooth addresses which are in the little endian order.
76597ff9 217
3b033380
MCC
218Passed by reference.
219
220IPv4 addresses
221==============
7330660e 222
3b033380 223::
04c55715
AM
224
225 %pI4 1.2.3.4
226 %pi4 001.002.003.004
8ecada16 227 %p[Ii]4[hnbl]
04c55715 228
3b033380
MCC
229For printing IPv4 dot-separated decimal addresses. The ``I4`` and ``i4``
230specifiers result in a printed address with (``i4``) or without (``I4``)
231leading zeros.
04c55715 232
3b033380
MCC
233The additional ``h``, ``n``, ``b``, and ``l`` specifiers are used to specify
234host, network, big or little endian order addresses respectively. Where
235no specifier is provided the default network/big endian order is used.
04c55715 236
3b033380 237Passed by reference.
7330660e 238
3b033380
MCC
239IPv6 addresses
240==============
241
242::
04c55715
AM
243
244 %pI6 0001:0002:0003:0004:0005:0006:0007:0008
245 %pi6 00010002000300040005000600070008
246 %pI6c 1:2:3:4:5:6:7:8
247
3b033380
MCC
248For printing IPv6 network-order 16-bit hex addresses. The ``I6`` and ``i6``
249specifiers result in a printed address with (``I6``) or without (``i6``)
250colon-separators. Leading zeros are always used.
04c55715 251
3b033380
MCC
252The additional ``c`` specifier can be used with the ``I`` specifier to
253print a compressed IPv6 address as described by
254http://tools.ietf.org/html/rfc5952
04c55715 255
3b033380 256Passed by reference.
7330660e 257
3b033380
MCC
258IPv4/IPv6 addresses (generic, with port, flowinfo, scope)
259=========================================================
260
261::
10679643
DB
262
263 %pIS 1.2.3.4 or 0001:0002:0003:0004:0005:0006:0007:0008
264 %piS 001.002.003.004 or 00010002000300040005000600070008
265 %pISc 1.2.3.4 or 1:2:3:4:5:6:7:8
266 %pISpc 1.2.3.4:12345 or [1:2:3:4:5:6:7:8]:12345
267 %p[Ii]S[pfschnbl]
268
3b033380
MCC
269For printing an IP address without the need to distinguish whether it``s
270of type AF_INET or AF_INET6, a pointer to a valid ``struct sockaddr``,
271specified through ``IS`` or ``iS``, can be passed to this format specifier.
10679643 272
3b033380
MCC
273The additional ``p``, ``f``, and ``s`` specifiers are used to specify port
274(IPv4, IPv6), flowinfo (IPv6) and scope (IPv6). Ports have a ``:`` prefix,
275flowinfo a ``/`` and scope a ``%``, each followed by the actual value.
10679643 276
3b033380
MCC
277In case of an IPv6 address the compressed IPv6 address as described by
278http://tools.ietf.org/html/rfc5952 is being used if the additional
279specifier ``c`` is given. The IPv6 address is surrounded by ``[``, ``]`` in
280case of additional specifiers ``p``, ``f`` or ``s`` as suggested by
281https://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07
10679643 282
3b033380
MCC
283In case of IPv4 addresses, the additional ``h``, ``n``, ``b``, and ``l``
284specifiers can be used as well and are ignored in case of an IPv6
285address.
10679643 286
3b033380 287Passed by reference.
7330660e 288
3b033380 289Further examples::
10679643
DB
290
291 %pISfc 1.2.3.4 or [1:2:3:4:5:6:7:8]/123456789
292 %pISsc 1.2.3.4 or [1:2:3:4:5:6:7:8]%1234567890
293 %pISpfc 1.2.3.4:12345 or [1:2:3:4:5:6:7:8]:12345/123456789
294
3b033380
MCC
295UUID/GUID addresses
296===================
297
298::
04c55715
AM
299
300 %pUb 00010203-0405-0607-0809-0a0b0c0d0e0f
301 %pUB 00010203-0405-0607-0809-0A0B0C0D0E0F
302 %pUl 03020100-0504-0706-0809-0a0b0c0e0e0f
303 %pUL 03020100-0504-0706-0809-0A0B0C0E0E0F
304
3b033380
MCC
305For printing 16-byte UUID/GUIDs addresses. The additional 'l', 'L',
306'b' and 'B' specifiers are used to specify a little endian order in
307lower ('l') or upper case ('L') hex characters - and big endian order
308in lower ('b') or upper case ('B') hex characters.
04c55715 309
3b033380
MCC
310Where no additional specifiers are used the default big endian
311order with lower case hex characters will be printed.
04c55715 312
3b033380
MCC
313Passed by reference.
314
315dentry names
316============
7330660e 317
3b033380 318::
5e4ee7b1 319
4b6ccca7
AV
320 %pd{,2,3,4}
321 %pD{,2,3,4}
322
3b033380
MCC
323For printing dentry name; if we race with :c:func:`d_move`, the name might be
324a mix of old and new ones, but it won't oops. ``%pd`` dentry is a safer
325equivalent of ``%s`` ``dentry->d_name.name`` we used to use, ``%pd<n>`` prints
326``n`` last components. ``%pD`` does the same thing for struct file.
4b6ccca7 327
3b033380 328Passed by reference.
7330660e 329
3b033380
MCC
330block_device names
331==================
332
333::
1031bc58
DM
334
335 %pg sda, sda1 or loop0p1
336
3b033380
MCC
337For printing name of block_device pointers.
338
339struct va_format
340================
1031bc58 341
3b033380 342::
04c55715
AM
343
344 %pV
345
3b033380
MCC
346For printing struct va_format structures. These contain a format string
347and va_list as follows::
04c55715
AM
348
349 struct va_format {
350 const char *fmt;
351 va_list *va;
352 };
353
3b033380 354Implements a "recursive vsnprintf".
5e4ee7b1 355
3b033380
MCC
356Do not use this feature without some mechanism to verify the
357correctness of the format string and va_list arguments.
b67ad18b 358
3b033380
MCC
359Passed by reference.
360
361kobjects
362========
363
364::
7330660e 365
ce4fecf1
PA
366 %pO
367
368 Base specifier for kobject based structs. Must be followed with
369 character for specific type of kobject as listed below:
370
371 Device tree nodes:
372
373 %pOF[fnpPcCF]
374
375 For printing device tree nodes. The optional arguments are:
376 f device node full_name
377 n device node name
378 p device node phandle
379 P device node path spec (name + @unit)
380 F device node flags
381 c major compatible string
382 C full compatible string
383 Without any arguments prints full_name (same as %pOFf)
384 The separator when using multiple arguments is ':'
385
386 Examples:
387
388 %pOF /foo/bar@0 - Node full name
389 %pOFf /foo/bar@0 - Same as above
390 %pOFfp /foo/bar@0:10 - Node full name + phandle
391 %pOFfcF /foo/bar@0:foo,device:--P- - Node full name +
392 major compatible string +
393 node flags
394 D - dynamic
395 d - detached
396 P - Populated
397 B - Populated bus
398
399 Passed by reference.
400
3b033380
MCC
401
402struct clk
403==========
404
405::
900cca29
GU
406
407 %pC pll1
408 %pCn pll1
409 %pCr 1560000000
410
3b033380
MCC
411For printing struct clk structures. ``%pC`` and ``%pCn`` print the name
412(Common Clock Framework) or address (legacy clock framework) of the
413structure; ``%pCr`` prints the current clock rate.
900cca29 414
3b033380 415Passed by reference.
900cca29 416
3b033380
MCC
417bitmap and its derivatives such as cpumask and nodemask
418=======================================================
419
420::
d0724961
WL
421
422 %*pb 0779
423 %*pbl 0,3-6,8-10
424
3b033380
MCC
425For printing bitmap and its derivatives such as cpumask and nodemask,
426``%*pb`` output the bitmap with field width as the number of bits and ``%*pbl``
427output the bitmap as range list with field width as the number of bits.
d0724961 428
3b033380
MCC
429Passed by reference.
430
431Flags bitfields such as page flags, gfp_flags
432=============================================
b67ad18b 433
3b033380 434::
edf14cdb
VB
435
436 %pGp referenced|uptodate|lru|active|private
437 %pGg GFP_USER|GFP_DMA32|GFP_NOWARN
438 %pGv read|exec|mayread|maywrite|mayexec|denywrite
439
3b033380
MCC
440For printing flags bitfields as a collection of symbolic constants that
441would construct the value. The type of flags is given by the third
442character. Currently supported are [p]age flags, [v]ma_flags (both
443expect ``unsigned long *``) and [g]fp_flags (expects ``gfp_t *``). The flag
444names and print order depends on the particular type.
edf14cdb 445
3b033380
MCC
446Note that this format should not be used directly in :c:func:`TP_printk()` part
447of a tracepoint. Instead, use the ``show_*_flags()`` functions from
448<trace/events/mmflags.h>.
edf14cdb 449
3b033380
MCC
450Passed by reference.
451
452Network device features
453=======================
edf14cdb 454
3b033380 455::
5e4ee7b1
MK
456
457 %pNF 0x000000000000c000
458
3b033380 459For printing netdev_features_t.
5e4ee7b1 460
3b033380 461Passed by reference.
5e4ee7b1 462
3b033380 463If you add other ``%p`` extensions, please extend lib/test_printf.c with
d7ec9a05 464one or more test cases, if at all feasible.
5e4ee7b1 465
5e4ee7b1 466
b67ad18b 467Thank you for your cooperation and attention.