1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 /* 4 * Copyright (c) 2025, Google LLC. 5 * Pasha Tatashin <pasha.tatashin@soleen.com> 6 * 7 * Copyright (C) 2025 Amazon.com Inc. or its affiliates. 8 * Pratyush Yadav <ptyadav@amazon.de> 9 */ 10 11 #ifndef _LINUX_KHO_ABI_MEMFD_H 12 #define _LINUX_KHO_ABI_MEMFD_H 13 14 #include <linux/types.h> 15 #include <linux/kexec_handover.h> 16 17 /** 18 * DOC: memfd Live Update ABI 19 * 20 * This header defines the ABI for preserving the state of a memfd across a 21 * kexec reboot using the LUO. 22 * 23 * The state is serialized into a packed structure `struct memfd_luo_ser` 24 * which is handed over to the next kernel via the KHO mechanism. 25 * 26 * This interface is a contract. Any modification to the structure layout 27 * constitutes a breaking change. Such changes require incrementing the 28 * version number in the MEMFD_LUO_FH_COMPATIBLE string. 29 */ 30 31 /** 32 * MEMFD_LUO_FOLIO_DIRTY - The folio is dirty. 33 * 34 * This flag indicates the folio contains data from user. A non-dirty folio is 35 * one that was allocated (say using fallocate(2)) but not written to. 36 */ 37 #define MEMFD_LUO_FOLIO_DIRTY BIT(0) 38 39 /** 40 * MEMFD_LUO_FOLIO_UPTODATE - The folio is up-to-date. 41 * 42 * An up-to-date folio has been zeroed out. shmem zeroes out folios on first 43 * use. This flag tracks which folios need zeroing. 44 */ 45 #define MEMFD_LUO_FOLIO_UPTODATE BIT(1) 46 47 /** 48 * struct memfd_luo_folio_ser - Serialized state of a single folio. 49 * @pfn: The page frame number of the folio. 50 * @flags: Flags to describe the state of the folio. 51 * @index: The page offset (pgoff_t) of the folio within the original file. 52 */ 53 struct memfd_luo_folio_ser { 54 u64 pfn:52; 55 u64 flags:12; 56 u64 index; 57 } __packed; 58 59 /** 60 * struct memfd_luo_ser - Main serialization structure for a memfd. 61 * @pos: The file's current position (f_pos). 62 * @size: The total size of the file in bytes (i_size). 63 * @nr_folios: Number of folios in the folios array. 64 * @folios: KHO vmalloc descriptor pointing to the array of 65 * struct memfd_luo_folio_ser. 66 */ 67 struct memfd_luo_ser { 68 u64 pos; 69 u64 size; 70 u64 nr_folios; 71 struct kho_vmalloc folios; 72 } __packed; 73 74 /* The compatibility string for memfd file handler */ 75 #define MEMFD_LUO_FH_COMPATIBLE "memfd-v1" 76 77 #endif /* _LINUX_KHO_ABI_MEMFD_H */ 78