Skip to content

Commit 03767b4

Browse files
Merge branch 'robadams-cicd305-refdoc' into 'linux-6.6.y-memorizer-dev'
Robadams cicd305 refdoc See merge request ring0/memorizer!45
2 parents a4fa357 + e875d0f commit 03767b4

File tree

3 files changed

+224
-101
lines changed

3 files changed

+224
-101
lines changed

Documentation/memorizer/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ run the memorizer kernel, along with collecting and sending kmap data.
1515

1616

1717
.. toctree::
18-
:maxdepth: 1
18+
:maxdepth: 2
1919

2020
quick_start
2121
using_memorizer

Documentation/memorizer/reference.rst

Lines changed: 193 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,29 @@ Config Variables
153153
Boolean, enables/disables the Memorizer tool. Memorizer traces the memory allocations of kernel objects to track patterns across an object's lifetime.
154154

155155
``MEMORIZER_STATS``
156-
Boolean, enables/disables the Memorizer statistics summary. The statistics summary includes the number of accesses and shadow objects allocated for Memorizer which will slow down the performance of the system.
156+
Boolean, enables/disables the Memorizer statistics summary. The
157+
statistics summary includes the number of accesses and shadow objects
158+
allocated for Memorizer which will slow down the performance of
159+
the system.
157160

158161
``MEMORIZER_TRACKPIDS``
159-
Boolean, enables/disables the segregation of memory access counts by process id (PID) within Memorizer data.
162+
Boolean, enables/disables the segregation of memory access counts by
163+
process id (PID) within Memorizer data.
160164

161165
``MEMORIZER_DEBUGFS_RAM``
162-
Boolean, enables/disables the exposure of Memorizer's buffer via a debugfs file.
166+
Boolean, enables/disables the exposure of Memorizer's buffer via a
167+
debugfs file.
163168

164169
``INLINE_LIBS``
165-
Boolean, forces gcc to use inline calls for some library functions. This must be enabled to run Memorizer.
170+
Boolean, forces gcc to use inline calls for some library functions. This
171+
must be enabled to run Memorizer.
166172

167173
Dependencies
168174
~~~~~~~~~~~~
169175
``KASAN``
170-
Boolean, enables/disables Kernel Address Sanitizer (KASAN). This is an error detector designed to find out-of-bounds and use-after-free bugs in dynamic memory. This must be enabled to run Memorizer.
176+
Boolean, enables/disables Kernel Address Sanitizer (KASAN). This is
177+
an error detector designed to find out-of-bounds and use-after-free
178+
bugs in dynamic memory. This must be enabled to run Memorizer.
171179

172180
.. _`debugfs-files`:
173181

@@ -333,24 +341,29 @@ Status Files
333341

334342
``stats``
335343
Reading this file generates human-readable statistical data
336-
about the current state of Memorizer. For more information,
337-
see :ref:`debugfs-stat`.
344+
about the current state of Memorizer. The format is intended
345+
to be self-evident and is subject to change from release to release.
346+
347+
External scripts should not rely upon the format of this file.
338348

339349

340350
File Formats
341351
============
342352

343-
.. _`debugfs-stat`:
344-
345353
``stat``
346354
~~~~~~~~
347355

348-
blah.
356+
Reading this file generates human-readable statistical data
357+
about the current state of Memorizer. The format is intended
358+
to be self-evident and is subject to change from release to release.
349359

350-
.. _`debugfs-kmap`:
360+
External scripts should not rely upon the format of this file.
351361

352-
``kmap``
353-
~~~~~~~~
362+
.. _debugfs-kmap-stream:
363+
.. _debugfs-kmap:
364+
365+
``kmap`` and ``kmap_stream``
366+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
354367

355368
.. note::
356369

@@ -365,16 +378,73 @@ Memorizer outputs data as text. The format of the ``kmap`` file is as follows::
365378
...
366379
...
367380

368-
The longer line represents the allocation and destruction of a kernel object.
369-
The shorter, indented, line represents the memory accesses of that same object.
370-
Each shorter line refers to the immediately preceding long line. There may be
371-
any number of shorter lines per long line. There may be any number of long lines
372-
in a kmap file.
381+
The longer line represents the allocation and destruction of a kernel
382+
object. The shorter, indented, line represents the memory accesses of
383+
that same object. Each shorter line refers to the immediately preceding
384+
long line. There may be any number of shorter lines per long line. There
385+
may be any number of long lines in a kmap file.
386+
387+
The following fields are printed as unsigned hexadecimal values:
388+
389+
* ``alloc_ip``
390+
* ``obj_va_ptr``
391+
* ``free_ip``
392+
393+
The following fields are printed as unsigned decimal values:
394+
395+
* ``size``
396+
* ``alloc_index``
397+
* ``free_index``
398+
399+
The following fields are printed as (possibly blank) character strings:
400+
401+
* ``alloc_type``
402+
* ``command``
403+
* ``slabname``
404+
* ``new_alloc_type``
405+
406+
* The following field is printed as a signed decimal value:
407+
408+
* ``pid``
409+
410+
373411

374412
``alloc_ip``
375-
The instruction pointer of the ``call`` instruction which resulted
413+
The return instruction pointer of the ``call`` instruction which resulted
376414
in the allocation of the object.
377415

416+
For some allocations, it is either not useful or not possible
417+
to describe the actual ``call`` instruction. For example, a
418+
statically-declared object does not have the same vmalloc-use-vfree
419+
life cycle as a dynamically-allocated object. In those cases synthetic
420+
values are used, each with a special meaning.
421+
422+
``MEMORIZER_PREALLOCATED(0xfeedbeef)``
423+
This flag is used when Slub allocates new objects for a cache.
424+
Memorizer preallocates objects here so any accesses from constructors
425+
are captured correctly. This value is subsequently overwritten with
426+
the actual instruction pointer of the ``call`` instruction which
427+
resulted in the allocation of the object.
428+
429+
``0``
430+
Memorizer maintains a set of general-purpose object descriptors,
431+
each with ``alloc_ip`` set to zero and with ``alloc_type`` set to
432+
a valid :ref:alloc_type value. These are used when a memory access
433+
occurs and the memory address is not described by an existing
434+
object descriptor.
435+
436+
Other ``alloc_type`` values
437+
Some memory accesses which cannot be associated with existing
438+
object descriptors result in the creation of new descriptors
439+
with ``alloc_ip`` set equal to :ref:alloc_type. These
440+
types include UFO_MEMBLOCK(0x14), STACK_PAGE(0x3),
441+
UFO_GLOBAL(0x18), and UFO_NONE(0x19),
442+
443+
.. note::
444+
``alloc_ip`` is printed as a hexadecimal value without a ``0x``
445+
prefix. The printed value ``14``, for example is ``0x14`` or
446+
decimal 20.
447+
378448
``pid``
379449
The process ID of the process that allocated the object.
380450

@@ -394,7 +464,7 @@ in a kmap file.
394464
`memorizer_index_type`_ for a description.
395465

396466
``free_ip``
397-
The instruction pointer of the `call` instruction which destroyed the object.
467+
The instruction pointer of the ``call`` instruction which destroyed the object.
398468

399469
There are a few special cases:
400470

@@ -403,57 +473,114 @@ in a kmap file.
403473
the free, then ``free_ip`` is also zero.
404474

405475
- If a subsequently allocated object exists in the same virtual addresses
406-
as a previously allocated, not freed, object, then Memorizer probably
407-
did not observe the intervening free.
408-
409-
In this case, ``free_ip`` of the previous object is ``0xdeadbeef`` and
410-
the ``free_index`` of the previous object is set equal to the
411-
``alloc_ip`` of the subsequent object.
412-
``new_alloc_type`` of the previous
413-
allocation is set to the ``alloc_type`` of the subsequent allocation.
414-
415-
- If a subsequently allocated object has exactly the same virtual address
416-
as the immediately preceding allocation, this represents a
417-
nested allocation. In this case, ``free_ip`` is set to ``0xfedbeef``.
418-
``new_alloc_type`` of the previous
419-
allocation is set to the ``alloc_type`` of the subsequent allocation.
420-
``free_index`` of the previous allocation is set to ``alloc_index``
421-
of the subsequent allocation.
476+
as a previously allocated, not freed, object, then either Memorizer
477+
did not observe the intervening free, or there was no interveneing free.
478+
479+
* If this is the result of nested allocations, then ``free_ip`` of
480+
the previous allocation will have ``0xfedbeef``.
481+
482+
* If this occurs for some other, unknown, reason, then ``free_ip`` of
483+
the previous allocation will have ``0xdeadbeef``.
484+
485+
In either case, the ``free_index`` of the previous allocation is
486+
set equal to the ``alloc_index`` of the subsequent allocation.
422487

423488
``alloc_type``
424489
Memorizer tracks various sorts of object allocation. This field
425490
gives an indication of which type this is.
426491

427492
This field has several possible values. Consult the source code
428-
for information on each of these::
429-
430-
STACK
431-
STACK_FRAME
432-
STACK_ARGS
433-
STACK_PAGE
434-
GEN_HEAP
435-
UFO_HEAP
436-
GLOBAL
437-
KMALLOC
438-
KMALLOC_ND
439-
KMEM_CACHE
440-
KMEM_CACHE_ND
441-
KMEM_CACHE_BULK
442-
ALLOC_PAGES
443-
ALLOC_PAGES_EXACT
444-
ALLOC_PAGES_GETFREEPAGES
445-
ALLOC_PAGES_FOLIO
446-
VMALLOC
447-
INDUCED_ALLOC
448-
BOOTMEM
449-
MEMBLOCK
450-
UFO_MEMBLOCK
451-
MEMORIZER
452-
USER
453-
BUG
454-
UFO_GLOBAL
455-
UFO_NONE
456-
NONE
493+
for more information on each of these:
494+
495+
STACK (MEM_STACK, 0x0)
496+
Unused.
497+
498+
STACK_FRAME (MEM_STACK_FRAME, 0x1)
499+
Used in the generation of call frame graphs (CFGs).This value should
500+
not appear in kmap.
501+
502+
STACK_ARGS (MEM_STACK_ARGS, 0x2)
503+
Used in the generation of call frame graphs (CFGs).This value should
504+
not appear in kmap.
505+
506+
STACK_PAGE (MEM_STACK_PAGE, 0x3)
507+
Used to describe a kernel object allocated in a stack frame.
508+
509+
GEN_HEAP (MEM_HEAP, 0x4)
510+
Unused.
511+
512+
UFO_HEAP (MEM_UFO_HEAP, 0x5)
513+
Unused.
514+
515+
GLOBAL (MEM_GLOBAL, 0x6)
516+
The object is globally declared.
517+
518+
KMALLOC (MEM_KMALLOC, 0x7)
519+
The subject allocation was from either the ``kmalloc`` or
520+
``kmalloc_node`` family of allocators.
521+
522+
KMALLOC_ND (MEM_KMALLOC_ND, 0x8)
523+
The subject allocation was from either the ``kmalloc`` or
524+
``kmalloc_node`` family of allocators.
525+
526+
KMEM_CACHE (MEM_KMEM_CACHE, 0x9)
527+
The subject allocation was from the kmem_cache_alloc family of allocators.
528+
529+
KMEM_CACHE_ND (MEM_KMEM_CACHE_ND, 0xA)
530+
The subject allocation was from the kmem_cache_alloc family of allocators.
531+
532+
KMEM_CACHE_BULK (MEM_KMEM_CACHE_BULK, 0xB)
533+
The subject allocation was from the kmem_cache_alloc family of allocators.
534+
535+
VMALLOC (MEM_VMALLOC, 0xC)
536+
The subject allocation was from ``vmalloc``.
537+
538+
ALLOC_PAGES (MEM_ALLOC_PAGES, 0xD)
539+
The subject allocation was from ``__alloc_pages``., et al.
540+
541+
ALLOC_PAGES_EXACT (MEM_ALLOC_PAGES_EXACT, 0xE)
542+
The subject allocation was from ``alloc_pages_exact``.
543+
544+
ALLOC_PAGES_GETFREEPAGES (MEM_ALLOC_PAGES_GETFREEPAGES, 0xF)
545+
The subject allocation was from ``__get_free_page``.
546+
547+
ALLOC_PAGES_FOLIO (MEM_ALLOC_PAGES_FOLIO, 0x10)
548+
The subject allocation was from ``__folio_alloc``.
549+
550+
INDUCED_ALLOC (MEM_INDUCED_ALLOC, 0x11)
551+
This object was allocated during (and, presumably as a result of)
552+
Memorizer itself. In order to avoid either deadlock or infinite
553+
recursion, we mark this object as INDUCED.
554+
555+
BOOTMEM (MEM_BOOTMEM, 0x12)
556+
Unused.
557+
558+
MEMBLOCK (MEM_MEMBLOCK, 0x13)
559+
This object is inside a region returned by ``memblock_insert_region``.
560+
561+
UFO_MEMBLOCK (MEM_UFO_MEMBLOCK, 0x14)
562+
This object is inside a ``memblock_insert_region``,
563+
but is (incorrectly) not in the Memorizer tracking system.
564+
565+
MEMORIZER (MEM_MEMORIZER, 0x15)
566+
This object is inside Memorizer's private memory pool.
567+
568+
USER (MEM_MZ_USER, 0x16)
569+
This object exists in user space.
570+
571+
BUG (MEM_BUG, 0x17)
572+
This object exists within the first page or is an address
573+
from which the software can infer no meaning.
574+
575+
UFO_GLOBAL (MEM_UFO_GLOBAL, 0x18)
576+
The object is globally declared,
577+
but is (incorrectly) not in the Memorizer tracking system.
578+
579+
UFO_NONE (MEM_UFO_NONE, 0x19)
580+
Memorizer can infer no information about the object.
581+
582+
NONE (MEM_NONE, 0x1A)
583+
Memorizer can infer no information about the object.
457584

458585
``command``
459586
The executable name, excluding the path, of the program running
@@ -468,7 +595,7 @@ in a kmap file.
468595

469596
``new_alloc_type``
470597
Every allocator must, itself, be a client of a more generic
471-
allocator. For example, ``kmalloc`` might gets its memory from
598+
allocator. For example, ``kmalloc`` might get its memory from
472599
``__alloc_pages``. When that happens, the allocation kmap
473600
entry for the more generic allocation will include the
474601
``alloc_type`` of the more specific allocation in this

0 commit comments

Comments
 (0)