acrn-kernel/tools/testing/memblock
Ranjan Dutta a2989f3ed0 This is the 6.1.59 stable release
-----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmUxmvQACgkQONu9yGCS
 aT79txAAsdMG7H4n6wai9EsZa6fpenp5MaQdice97FinKvS3El1hmlNOJPY2idAC
 hFnfhebrWsyStCUcUs2KeiosZwKoKSRuIZ2l43P9o4tNbAoaJfp7EOihCKSJyl1K
 qcu1P7AJZH2GfR3wS86grRjlembwxYNaFVS+n4a9X3XfoMOTM9TLwIPyKzXmruUv
 4FjTH6clfQbg7lu80nPBeps1FKd2XXhiLfFH21ilnSY8ESQEKo0x10Vbi0/LqE/F
 QxvP2bFRMXyKl9HHQMAkIIjpQH+hZDzpbGx1hoC2I0xc92dTERHzzZxWkuUt2e/Y
 zGrgQ3gQR8VkpuhPuFRrSu3bZUlEr74zRyp3sXBG0RSOpK13xSYgcdRzBac/L0zT
 aSqvmIYuLnjf6qE85LEp/NAQAgKxQ2S2nGwSoN+cePb/zB0qlyXNfSsPg2mptOTi
 MOxgldZg10oNh0VXEayhtoJGUCJBjk1XUor0bAFj4u4GCiBbFfAt3e5fF0jauMva
 9b2s89qE5444dr98kdAcd79mEI0xkX9SbjCTY9lwTzA7xk+7iw+vOchLC7fQWoyf
 gspg7PdzCaFnDAS3WiIR3NqkSlGpv426Kr3kd/8jrLA3VB81Rb6bFX+E7iRzVJsd
 /YShEGesDA16aZ5BDnOMXMHzFbTEgfNDH1AiJoJcjq/V5cIuSc0=
 =Dwcv
 -----END PGP SIGNATURE-----

Merge tag 'v6.1.59' into lts2022/linux

This is the 6.1.59 stable release

# gpg verification failed.

# By Pablo Neira Ayuso (15) and others
# Via Greg Kroah-Hartman
* tag 'v6.1.59': (694 commits)
  Linux 6.1.59
  ALSA: hda/realtek - Fixed two speaker platform
  powerpc/64e: Fix wrong test in __ptep_test_and_clear_young()
  powerpc/8xx: Fix pte_access_permitted() for PAGE_NONE
  dmaengine: mediatek: Fix deadlock caused by synchronize_irq()
  dmaengine: idxd: use spin_lock_irqsave before wait_event_lock_irq
  x86/alternatives: Disable KASAN in apply_alternatives()
  usb: cdnsp: Fixes issue with dequeuing not queued requests
  usb: gadget: ncm: Handle decoding of multiple NTB's in unwrap call
  usb: gadget: udc-xilinx: replace memcpy with memcpy_toio
  usb: typec: ucsi: Clear EVENT_PENDING bit if ucsi_send_command fails
  usb: typec: altmodes/displayport: Signal hpd low when exiting mode
  counter: microchip-tcb-capture: Fix the use of internal GCLK logic
  counter: chrdev: fix getting array extensions
  scsi: ufs: core: Correct clear TM error log
  pinctrl: avoid unsafe code pattern in find_pinctrl()
  dma-buf: add dma_fence_timestamp helper
  cgroup: Remove duplicates in cgroup v1 tasks file
  usb: typec: ucsi: Use GET_CAPABILITY attributes data to set power supply scope
  nfp: flower: avoid rmmod nfp crash issues
  ...

# Conflicts:
#	drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
#	drivers/gpu/drm/i915/gt/gen8_engine_cs.c
#	sound/soc/intel/boards/sof_es8336.c
#	sound/soc/intel/common/soc-acpi-intel-mtl-match.c
2023-10-28 02:52:56 +08:00
..
asm
lib
linux mm, treewide: redefine MAX_ORDER sanely 2023-07-18 13:23:04 +08:00
scripts memblock tests: add simulation of physical memory with multiple NUMA nodes 2022-09-18 10:30:20 +03:00
tests memblock tests: fix warning ‘struct seq_file’ declared inside parameter list 2023-10-06 14:56:56 +02:00
.gitignore memblock tests: Fix compilation error. 2023-01-24 07:24:32 +01:00
Makefile memblock tests: Fix compilation error. 2023-01-24 07:24:32 +01:00
README memblock test: Modify the obsolete description in README 2022-07-30 11:46:49 +03:00
TODO memblock tests: remove completed TODO items 2022-07-04 19:58:28 +03:00
internal.h Revert "mm: Always release pages to the buddy allocator in memblock_free_late()." 2023-02-22 12:59:50 +01:00
main.c memblock tests: change build options to run-time options 2022-07-20 10:46:33 +03:00
mmzone.c

README

==================
Memblock simulator
==================

Introduction
============

Memblock is a boot time memory allocator[1] that manages memory regions before
the actual memory management is initialized. Its APIs allow to register physical
memory regions, mark them as available or reserved, allocate a block of memory
within the requested range and/or in specific NUMA node, and many more.

Because it is used so early in the booting process, testing and debugging it is
difficult. This test suite, usually referred as memblock simulator, is
an attempt at testing the memblock mechanism. It runs one monolithic test that
consist of a series of checks that exercise both the basic operations and
allocation functionalities of memblock. The main data structure of the boot time
memory allocator is initialized at the build time, so the checks here reuse its
instance throughout the duration of the test. To ensure that tests don't affect
each other, region arrays are reset in between.

As this project uses the actual memblock code and has to run in user space,
some of the kernel definitions were stubbed by the initial commit that
introduced memblock simulator (commit 16802e55dea9 ("memblock tests: Add
skeleton of the memblock simulator")) and a few preparation commits just
before it. Most of them don't match the kernel implementation, so one should
consult them first before making any significant changes to the project.

Usage
=====

To run the tests, build the main target and run it:

$ make && ./main

A successful run produces no output. It is possible to control the behavior
by passing options from command line. For example, to include verbose output,
append the `-v` options when you run the tests:

$ ./main -v

This will print information about which functions are being tested and the
number of test cases that passed.

For the full list of options from command line, see `./main --help`.

It is also possible to override different configuration parameters to change
the test functions. For example, to simulate enabled NUMA, use:

$ make NUMA=1

For the full list of build options, see `make help`.

Project structure
=================

The project has one target, main, which calls a group of checks for basic and
allocation functions. Tests for each group are defined in dedicated files, as it
can be seen here:

memblock
|-- asm       ------------------,
|-- lib                         |-- implement function and struct stubs
|-- linux     ------------------'
|-- scripts
|    |-- Makefile.include        -- handles `make` parameters
|-- tests
|    |-- alloc_api.(c|h)         -- memblock_alloc tests
|    |-- alloc_helpers_api.(c|h) -- memblock_alloc_from tests
|    |-- alloc_nid_api.(c|h)     -- memblock_alloc_try_nid tests
|    |-- basic_api.(c|h)         -- memblock_add/memblock_reserve/... tests
|    |-- common.(c|h)            -- helper functions for resetting memblock;
|-- main.c        --------------.   dummy physical memory definition
|-- Makefile                     `- test runner
|-- README
|-- TODO
|-- .gitignore

Simulating physical memory
==========================

Some allocation functions clear the memory in the process, so it is required for
memblock to track valid memory ranges. To achieve this, the test suite registers
with memblock memory stored by test_memory struct. It is a small wrapper that
points to a block of memory allocated via malloc. For each group of allocation
tests, dummy physical memory is allocated, added to memblock, and then released
at the end of the test run. The structure of a test runner checking allocation
functions is as follows:

int memblock_alloc_foo_checks(void)
{
	reset_memblock_attributes();     /* data structure reset */
	dummy_physical_memory_init();    /* allocate and register memory */

	(...allocation checks...)

	dummy_physical_memory_cleanup(); /* free the memory */
}

There's no need to explicitly free the dummy memory from memblock via
memblock_free() call. The entry will be erased by reset_memblock_regions(),
called at the beginning of each test.

Known issues
============

1. Requesting a specific NUMA node via memblock_alloc_node() does not work as
   intended. Once the fix is in place, tests for this function can be added.

2. Tests for memblock_alloc_low() can't be easily implemented. The function uses
   ARCH_LOW_ADDRESS_LIMIT marco, which can't be changed to point at the low
   memory of the memory_block.

References
==========

1. Boot time memory management documentation page:
   https://www.kernel.org/doc/html/latest/core-api/boot-time-mm.html