From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C02CC7EE2A for ; Wed, 25 Jun 2025 23:20:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DDFF6B00B0; Wed, 25 Jun 2025 19:19:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 017BD6B00B5; Wed, 25 Jun 2025 19:19:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E21BD6B00D3; Wed, 25 Jun 2025 19:19:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CBD4C6B00B0 for ; Wed, 25 Jun 2025 19:19:36 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9A3A35B84B for ; Wed, 25 Jun 2025 23:19:36 +0000 (UTC) X-FDA: 83595491952.22.D5E450C Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) by imf15.hostedemail.com (Postfix) with ESMTP id C8C95A0005 for ; Wed, 25 Jun 2025 23:19:34 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b="3TbJcI/z"; spf=pass (imf15.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.171 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750893574; a=rsa-sha256; cv=none; b=cHI64gsQmA9l52BL6dn8n+J81RHeMSbv/3OPraIb+rmiAPHOM6R93xt025cudQpHOGbvBG T3fnfDKFEXR1I9c0mw0WLxg1QqauTGCFXe6kL40fTLz9eSENkMhDLNNs5Z4Us39kLooGPy Apj1YXUP2sDq2vUlTdo9tkxf7CiixuE= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b="3TbJcI/z"; spf=pass (imf15.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.171 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750893574; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zNUWS5sHgPJ3/TtkkLsM0l/sndwzOVEqU/iJZvqTlnw=; b=OoS+ed4kHxtOXi0WEmDKf/GqNH2Jwui5v83hoYj7n3SR6aGBzWs4jl/0/UKWjHs0YeYAHe F0+bFZwG1xt9EAaLftaCJZMjBvx2ilsFHRhmviIup7DRcBHDKjq77e1BbBYkV45frLkHro 8nx0tdwqLma0xOL9uuqKbP3gXMlvk/U= Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-e731a56e111so352411276.1 for ; Wed, 25 Jun 2025 16:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893574; x=1751498374; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=zNUWS5sHgPJ3/TtkkLsM0l/sndwzOVEqU/iJZvqTlnw=; b=3TbJcI/z6CqYDmyFdl1JsumJSvvNuFNboVxuIUmPwWFImwUKqcQHIDwtAC3naHo5Jt NszKC2BEOEl0fIOJAWVUETg5AlzVBTpv6GddAqd6C+zGSZalrXMb4qSyXM9tl13LIpGm YW259kxs3w/LayFEfR4VyA93noJ3qK/MFx8wsXBU3dtu8VmI3PV5P1CMem/gMkdKl7AM LRVUGZHWrKPk3Bx8M2Rqqnm8QUyTUpn4tDuixG/wjVkcCJJYQAhLj/620Z19nSSCnvf9 29oJ+MleH6PbD6JNiUMrtZIWoLDrjl6ibMetLe1E7ewW/24WEEf+YM/kwmevQylmqqJV QaFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893574; x=1751498374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zNUWS5sHgPJ3/TtkkLsM0l/sndwzOVEqU/iJZvqTlnw=; b=wWkCglNdci2aSgFNOcorC6knsc2VKeXoAHHdvuhWLVi07mzlwqYxFYy5aUbJfa4uBI diHBpquLnRtstxVkdsJBL+JABhq5qKq0a1MH5WddVyoBGYRI9o99zy4+yblh8MhjyPjn PDf3emwPn09Q1LfCaR86N/M0MNfu9jSqwKNPT5gDxYdffx0lzHaTsVA1m7SCkgfjxHsc Ai457W1YQoekd1DvjJMcTyv6owH82L9hMGWfLXHtr95SZHALhkrDfn/VSa4zQD1v9tiu VHvK8wTbLOFRZgUWox7muw8uiWrmJQT5Rn6aM7gK2vFrjlKwmEdI2w6kaYfBSgCtIxF7 Ld/Q== X-Forwarded-Encrypted: i=1; AJvYcCXt7gwe3lamoUzn4iuT0yvXgAwT6YGLWlIrSxQbV/WiYFENx7qHZQp4ee28cWOTiXaSwJ0DFMX7rA==@kvack.org X-Gm-Message-State: AOJu0YwbXGxw9ocpTZJ7a2g3vrt3wcnrGYBHBAr4+XZmNdReglI/j7Qf pOGcE+6kHqC0DsKpfICl2PCjZDpW8QJ7rm6jRwKX2PYB7Ct+S59G6zHha1nWslVK0AM= X-Gm-Gg: ASbGncsWBWQ9yqmsYMus8G22S8MJho5Ug7s5FaSEWslBWXDw2i305UQoNx0jtsJJtVz xCExH1ZLpJLhf6yIoRWE5EMoRvQ/e+bEWD7Zc8eWQNYrjbM2zRrvYxuV+Ko7cmfWStgqntYZAyT ZrRSZL8JR9ymNrM4X2JekGj9AHKCyzFR0X9rwVnckS4uWxa9dIBaD2ycotaO1ceMtJqnShqX4XT ouGoq6GjDAKNi8G091qWbaU2dqsVq0qLpgd+pFwIU4QHtFGLPwtAr4uHzRf0OgsCglvsfU4DdFE Zsi9bxohwBZCWtEl+F5PWQdCVA02v650tcnUYQsS+PjKdV/uLE5wOBXDxk9FRCFbhqSET8xhzJr YoaDinvNisroBCGKyo13tYTO+vQacEUP7R7GY/YJq+Kw6pwWAMs9Y X-Google-Smtp-Source: AGHT+IFDGX7NrsfyyxA53ENg0MYMTOghBYuaJBxDrL4i/eRQ4joSzHgyrsvnmaeCiyZ/P1GWMue8rQ== X-Received: by 2002:a05:6902:278a:b0:e85:eac6:7ae5 with SMTP id 3f1490d57ef6-e860176b5e1mr6314395276.9.1750893573720; Wed, 25 Jun 2025 16:19:33 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:33 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 29/32] docs: add documentation for memfd preservation via LUO Date: Wed, 25 Jun 2025 23:18:16 +0000 Message-ID: <20250625231838.1897085-30-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: aspyw4rm8xcjsegwuczpemf57eb1cie8 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C8C95A0005 X-Rspam-User: X-HE-Tag: 1750893574-741884 X-HE-Meta: U2FsdGVkX18oByMQmM42I+KBfyAJwlnws8JAH7D01RngbcQcb3BpHkvcmxssNX9EsYf9oH8UAk9PGcgQCtyeQykAhqrr23sHtUasGD7s8fv4jG91L8NMQ7yx36lhG9iaPBndcXo3JOjAR/lT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ZfakVaPNSuSvqWuRJjcLffEmK/RPvjbsPyqWGHFz7ofWLu9Q1/IQlBVzAl8xrTeDU7ieN40e61mQiry9vrXOcxHQxhPtrhe7utL6nZZdJtVR/DytW4MHdwrmzbw25hDhOocSKA2pD4N1Gm2ofe5UtY/jNZ2g9H5Mpz938AJ3uWYWaEzY3WmzJLZzw1u0KmwOA11uJxabitrFm/yS6p3cBaS+hJbfnZlbFb087PqkvWd74Jk8Y6jbBZrtH8U2UvmZEqJ1duE7slobJcTfUyeg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Pratyush Yadav Add the documentation under the "Preserving file descriptors" section of LUO's documentation. The doc describes the properties preserved, behaviour of the file under different LUO states, serialization format, and current limitations. Signed-off-by: Pratyush Yadav Signed-off-by: Pasha Tatashin --- Documentation/core-api/liveupdate.rst | 7 ++ Documentation/mm/index.rst | 1 + Documentation/mm/memfd_preservation.rst | 138 ++++++++++++++++++++++++ MAINTAINERS | 1 + 4 files changed, 147 insertions(+) create mode 100644 Documentation/mm/memfd_preservation.rst diff --git a/Documentation/core-api/liveupdate.rst b/Documentation/core-api/liveupdate.rst index 41c4b76cd3ec..232d5f623992 100644 --- a/Documentation/core-api/liveupdate.rst +++ b/Documentation/core-api/liveupdate.rst @@ -18,6 +18,13 @@ LUO Preserving File Descriptors .. kernel-doc:: kernel/liveupdate/luo_files.c :doc: LUO file descriptors +The following types of file descriptors can be preserved + +.. toctree:: + :maxdepth: 1 + + ../mm/memfd_preservation + Public API ========== .. kernel-doc:: include/linux/liveupdate.h diff --git a/Documentation/mm/index.rst b/Documentation/mm/index.rst index d3ada3e45e10..97267567ef80 100644 --- a/Documentation/mm/index.rst +++ b/Documentation/mm/index.rst @@ -47,6 +47,7 @@ documentation, or deleted if it has served its purpose. hugetlbfs_reserv ksm memory-model + memfd_preservation mmu_notifier multigen_lru numa diff --git a/Documentation/mm/memfd_preservation.rst b/Documentation/mm/memfd_preservation.rst new file mode 100644 index 000000000000..416cd1dafc97 --- /dev/null +++ b/Documentation/mm/memfd_preservation.rst @@ -0,0 +1,138 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +========================== +Memfd Preservation via LUO +========================== + +Overview +======== + +Memory file descriptors (memfd) can be preserved over a kexec using the Live +Update Orchestrator (LUO) file preservation. This allows userspace to transfer +its memory contents to the next kernel after a kexec. + +The preservation is not intended to be transparent. Only select properties of +the file are preserved. All others are reset to default. The preserved +properties are described below. + +.. note:: + The LUO API is not stabilized yet, so the preserved properties of a memfd are + also not stable and are subject to backwards incompatible changes. + +.. note:: + Currently a memfd backed by Hugetlb is not supported. Memfds created + with ``MFD_HUGETLB`` will be rejected. + +Preserved Properties +==================== + +The following properties of the memfd are preserved across kexec: + +File Contents + All data stored in the file is preserved. + +File Size + The size of the file is preserved. Holes in the file are filled by allocating + pages for them during preservation. + +File Position + The current file position is preserved, allowing applications to continue + reading/writing from their last position. + +File Status Flags + memfds are always opened with ``O_RDWR`` and ``O_LARGEFILE``. This property is + maintained. + +Non-Preserved Properties +======================== + +All properties which are not preserved must be assumed to be reset to default. +This section describes some of those properties which may be more of note. + +``FD_CLOEXEC`` flag + A memfd can be created with the ``MFD_CLOEXEC`` flag that sets the + ``FD_CLOEXEC`` on the file. This flag is not preserved and must be set again + after restore via ``fcntl()``. + +Seals + File seals are not preserved. The file is unsealed on restore and if needed, + must be sealed again via ``fcntl()``. + +Behavior with LUO states +======================== + +This section described the behavior of the memfd in the different LUO states. + +Normal Phase + During the normal phase, the memfd can be marked for preservation using the + ``LIVEUPDATE_IOCTL_FD_PRESERVE`` ioctl. The memfd acts as a regular memfd + during this phase with no additional restrictions. + +Prepared Phase + After LUO enters ``LIVEUPDATE_STATE_PREPARED``, the memfd is serialized and + prepared for the next kernel. During this phase, the below things happen: + + - All the folios are pinned. If some folios reside in ``ZONE_MIGRATE``, they + are migrated out. This ensures none of the preserved folios land in KHO + scratch area. + - Pages in swap are swapped in. Currently, there is no way to pass pages in + swap over KHO, so all swapped out pages are swapped back in and pinned. + - The memfd goes into "frozen mapping" mode. The file can no longer grow or + shrink, or punch holes. This ensures the serialized mappings stay in sync. + The file can still be read from or written to or mmap-ed. + +Freeze Phase + Updates the current file position in the serialized data to capture any + changes that occurred between prepare and freeze phases. After this, the FD is + not allowed to be accessed. + +Restoration Phase + After being restored, the memfd is functional as normal with the properties + listed above restored. + +Cancellation + If the liveupdate is canceled after going into prepared phase, the memfd + functions like in normal phase. + +Serialization format +==================== + +The state is serialized in an FDT with the following structure:: + + /dts-v1/; + + / { + compatible = "memfd-v1"; + pos = ; + size = ; + folios = ; + }; + +Each folio descriptor contains: + +- PFN + flags (8 bytes) + + - Physical frame number (PFN) of the preserved folio (bits 63:12). + - Folio flags (bits 11:0): + + - ``PRESERVED_FLAG_DIRTY`` (bit 0) + - ``PRESERVED_FLAG_UPTODATE`` (bit 1) + +- Folio index within the file (8 bytes). + +Limitations +=========== + +The current implementation has the following limitations: + +Size + Currently the size of the file is limited by the size of the FDT. The FDT can + be at of most ``MAX_PAGE_ORDER`` order. By default this is 4 MiB with 4K + pages. Each page in the file is tracked using 16 bytes. This limits the + maximum size of the file to 1 GiB. + +See Also +======== + +- :doc:`Live Update Orchestrator ` +- :doc:`/core-api/kho/concepts` diff --git a/MAINTAINERS b/MAINTAINERS index 163f38cd55b5..8114ce1be57b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14017,6 +14017,7 @@ S: Maintained F: Documentation/ABI/testing/sysfs-kernel-liveupdate F: Documentation/admin-guide/liveupdate.rst F: Documentation/core-api/liveupdate.rst +F: Documentation/mm/memfd_preservation.rst F: Documentation/userspace-api/liveupdate.rst F: include/linux/liveupdate.h F: include/uapi/linux/liveupdate.h -- 2.50.0.727.gbf7dc18ff4-goog