# SPDX-License-Identifier: GPL-2.0-only

menu "Live Kernel Upgrade"
	depends on !DEFERRED_STRUCT_PAGE_INIT

config KEXEC_MEMORY_TRANSFER
	bool "kexec memory transfer"
	depends on ARCH_SUPPORTS_KEXEC_MEMORY_TRANSFER && ARCH_SUPPORTS_KEXEC_FILE
	depends on !DEFERRED_STRUCT_PAGE_INIT
	select MEMBLOCK_KMT_BUFFER
	select KEXEC_FILE
	select LIBFDT
	select CMA
	help
	  Enable Kexec Memory Transfer (KMT), a mechanism that allows kexec to
	  hand over state across kernels by generating and passing additional
	  metadata to the target kernel via a Flattened Device Tree (FDT).

	  KMT reserves special buffer regions during early boot that are used to:
	    - Store metadata and state information that needs to be preserved
	    - Provide safe memory for loading new kexec images
	    - Handle early allocations before the page allocator is initialized

	  The system can be controlled via the kernel command line parameter 'kmt':
	    - kmt=on   : Enable KMT (default if this option is selected)
	    - kmt=off  : Disable KMT

	  For state handover to work correctly, both source and target kernels
	  must have this option enabled. The feature also requires architecture
	  support for kexec file-based loading and memory transfer operations.

	  This is the foundation for Live Kernel Upgrade (LKFU) and other
	  features that require state preservation across kernel transitions.

config KEXEC_MEMORY_TRANSFER_DEBUG
	bool "Enable Kexec memory transfer debug checks"
	depends on KEXEC_MEMORY_TRANSFER
	help
	  Enable extra sanity checks and validation for the Kexec Memory
	  Transfer subsystem. This option adds additional runtime checks to
	  detect potential issues during state handover operations.

	  Debug checks include:
	    - Buffer overlap detection to prevent memory corruption
	    - Validation of FDT structure and properties
	    - Additional bounds checking on preserved memory regions

	  Since KMT performance is crucial in live update scenarios, the extra
	  code path may add overhead. This option is primarily intended for
	  development and debugging purposes, and should be disabled in production
	  environments unless troubleshooting specific issues.

	  If unsure, say N.

config KEXEC_MEMORY_TRANSFER_DEBUGFS
	bool "kexec memory transfer debugfs interface"
	default KEXEC_MEMORY_TRANSFER
	depends on KEXEC_MEMORY_TRANSFER
	select DEBUG_FS
	help
	  Expose KMT control and inspection interfaces via debugfs under
	  /sys/kernel/debug/kmt/. This provides runtime visibility and control
	  over the Kexec Memory Transfer subsystem.

	  Available debugfs interfaces:
	    - /sys/kernel/debug/kmt/out/finalize
	        Write 1 to finalize the KMT FDT for the next kernel
	    - /sys/kernel/debug/kmt/out/buffer_phys
	        Display physical addresses of KMT buffer regions
	    - /sys/kernel/debug/kmt/out/buffer_len
	        Display sizes of KMT buffer regions
	    - /sys/kernel/debug/kmt/out/fdt
	        Binary blob of the outgoing FDT tree
	    - /sys/kernel/debug/kmt/out/sub_fdts/
	        Directory containing registered subtree FDTs
	    - /sys/kernel/debug/kmt/in/fdt
	        Binary blob of the incoming FDT from previous kernel
	    - /sys/kernel/debug/kmt/in/sub_fdts/
	        Directory containing subtree FDTs from previous kernel

	  This option is useful for debugging, development, and understanding
	  the state handover process. It allows inspection of the FDT trees
	  and manual triggering of finalization operations.

	  If unsure, say Y (this is the default when KMT is enabled).

config KEXEC_MEMORY_TRANSFER_ENABLE_DEFAULT
	bool "Enable kexec memory transfer by default"
	depends on KEXEC_MEMORY_TRANSFER
	help
	  Enable Kexec Memory Transfer by default at boot time. When this
	  option is selected, KMT will be automatically enabled without
	  requiring the 'kmt=on' kernel command line parameter.

	  This is useful for systems where KMT is a prerequisite for other
	  features, such as Live Kernel Upgrade, ensuring the mechanism is
	  always active and ready for use.

	  The default behavior can still be overridden at boot time by
	  passing 'kmt=off' on the kernel command line.

	  Buffer size configuration:
	    - kmt_buffer=<size>[:<size>]:<size>
	        Specify buffer sizes for lowmem, global, and per-node regions
	        (e.g., "128M:256M:64M")
	    - kmt_buffer=<percentage>%
	        Specify buffer size as percentage of kernel reserved memory
	        (e.g., "200%" for 2x the reserved memory, default is 200%)

	  If unsure, say Y if you plan to use Live Kernel Upgrade or other
	  features that depend on KMT.

config LIVE_KERNEL_UPGRADE
	bool "Live Kernel Upgrade"
	depends on KEXEC_MEMORY_TRANSFER
	help
	  Enable the Live Kernel Upgrade (LKU), a mechanism that
	  allows the kernel to be updated while keeping selected devices and
	  state operational across the transition. This is built on top of the
	  Kexec Memory Transfer (KMT) infrastructure.

	  LKU provides:
	    - Session-based state management for preserving kernel state
	    - File descriptor preservation across kernel transitions
	    - Memory allocation and preservation APIs for kernel modules
	    - Device handover coordination through driver callbacks
	    - Userspace interface via /dev/livekernelupgrade device

	  The feature works by:
	    1. Freezing all registered sessions and their associated resources
	    2. Serializing state into FDT structures via KMT
	    3. Performing kexec to the new kernel
	    4. Deserializing and resuming sessions in the new kernel

	  Device handover capability depends on specific support within device
	  drivers and related kernel subsystems. Drivers must implement the
	  appropriate freeze/thaw callbacks to participate in live updates.

	  This feature primarily targets virtual machine hosts to quickly update
	  the kernel hypervisor with minimal disruption to the running virtual
	  machines, but can be used in other scenarios where kernel updates
	  without full system reboot are desirable.

	  Kernel command line options:
	    - lfm=on   : Enable LKU (default if this option is selected)
	    - lfm=off  : Disable LKU

	  If unsure, say N unless you specifically need live kernel upgrade
	  functionality.

config LIVE_KERNEL_UPGRADE_MEMFD
	bool "Live kernel upgrade support for memfd"
	depends on LIVE_KERNEL_UPGRADE
	depends on MEMFD_CREATE
	depends on SHMEM
	default LIVE_KERNEL_UPGRADE
	help
	  Enable live kernel upgrade support for memfd regions, allowing memfd-backed
	  memory to be preserved during kernel live updates. This feature can
	  be used to back virtual machine memory with memfds, enabling guest
	  memory persistence, or to meet the needs of other user workloads
	  requiring page preservation.

	  If unsure, say N.

endmenu
