From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A395248867 for ; Fri, 3 Jul 2026 02:08:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783044529; cv=none; b=N6nzaHdzwOUwGfXJQUr2dX4Qfdbf7YWBbROWUgVnag0LHIzGD/LDZFPEEhTFRSix0kKKRy20UFC3Gh/ppU7tw7QZx78S06hxvHr5qumYpdpah3Q1ULIdxbZn5VScbrUo0j7GFEhk2OrbXaw0O99JN5am6RH7mBQqPromgqML7Y8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783044529; c=relaxed/simple; bh=2OCT5EQzqjYqKl7NIP7QWGtIsmDealH6FlXo34zkA6g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=s80R7dtsF4mobVkFRNtfv+hPbhNHAQBWSKG4uPSa2vd5xYK+6gd0SVM19CRYHk3n9cjqtajQtf/oQ6Gyvbix/+XuXZY7VET2Hn6aQx7SuwHIH/r/tOCD7MZ/L3mqq9gaLP3Hj4gL0bTRwRwVGjlkrjTTg2ICtLU1dMUzpKG9UDw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--praan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MbFlDb3+; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--praan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MbFlDb3+" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-847c3a12ce8so77305b3a.1 for ; Thu, 02 Jul 2026 19:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783044525; x=1783649325; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=R42hNae76A7CXiYkYtHihW2CvpPOkdd31plc72X+MXE=; b=MbFlDb3+Oiwt59Pyz5AHv6MFdnKujYPMmREqjD4H9KI5AQSmhrCKNapjjp2IafDitB D2TTSpVhmC74emIcRE781LGs12SvC+fE44TxxN3qlw1ALZfNN9XUOx+vcpB8kUBH/0ia sqHTQVpcN3xE/oPxsUSj200iWocPWTHpQ8x/sY93oOA/cJGNDlBpXc/mXohBaxRdRThh P9xXwIK+mSU4tkIF4Jh+UYZgOapKvDZKyOsUSjWz6+iaIxAj0EYO4DBYmiI16eex6Pe2 mJ0AyrQTTjAttxHARxoDWYiJZDUEWS0298sfs7PzCSKMOua/A6MJglf4tLh4pAWotrWS Il4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783044525; x=1783649325; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R42hNae76A7CXiYkYtHihW2CvpPOkdd31plc72X+MXE=; b=XTtJtswyK6uhQ7VtObzWsyDTLjoBeLRxmfUhJ27OrzC1Uf+3XsWwYw5cBu0/btq75u aN/jnpfGY/jlZW1RBHLAruMiQVib9a2I8GZbumyjJrYr9/yyC+fT8UrrJYLJ2HtHKOnT 7z8gqOGj95n24s3qzo0it6DUvg8L+yUuIcghv5NEGPvE1/xRzAMKQYRJFKV4XVcozACA dr/54VHavPltQV8np8wkXDFTSIQKqlloVoqfvYfrG2HGCwgFljXV+yENG+ZtV0edbSQ9 Np2tXH37hnzpdB3DyxZPsW3kaS+7JOMFzKzvkLxYz46EJzpsFbZh5d8SY7znfTajJkH7 ctDw== X-Forwarded-Encrypted: i=1; AFNElJ+FuasbZ1gv4STx7CSLfZgeP0C55e1ucUzV2W9iayqRfhyu1wo8qRYjhb9Ryf4Q5M1/XwwKD63IKg77Sgg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1TxM9TbMsphmdO9mPQsoa9EgScdbbX8Q1xCAfBDPkXPKvIyQV CHSQulnCoU8ngyWszRygEVyoXrxECsGWNZkr5AZhsJauewc6a0TTnOjId87Ql7EcbxLSVZpuFD/ cBQ== X-Received: from pfcg5.prod.google.com ([2002:a05:6a00:23c5:b0:847:92f6:92e1]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2918:b0:845:c373:6525 with SMTP id d2e1a72fcca58-847c09344f7mr8276323b3a.41.1783044524457; Thu, 02 Jul 2026 19:08:44 -0700 (PDT) Date: Fri, 3 Jul 2026 02:08:32 +0000 In-Reply-To: <20260703020832.1731864-1-praan@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260703020832.1731864-1-praan@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260703020832.1731864-5-praan@google.com> Subject: [RFC PATCH 4/4] kho: Introduce kho_split_preserved_pages() helper From: Pranjal Shrivastava To: Mike Rapoport , Pasha Tatashin , Pratyush Yadav Cc: Alexander Graf , Samiullah Khawaja , David Matlack , kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Pranjal Shrivastava Content-Type: text/plain; charset="UTF-8" A driver may need to split a high-order allocation that has already been preserved. If the pages are split using split_page() manually, the refcounts would change but KHO won't record the change in the preserved page-type, resulting in a metadata mismatch during restoration in the new kernel. Introduce kho_split_preserved_pages() to handle splitting of preserved pages. The helper follows an unpreserve -> split -> re-preserve sequence, while ensuring that the KHO radix tree is updated with the correct KHO_PAGE_SPLIT type bits. The helper returns 0 on success, or a negative error code if the re-preservation fails. Callers must ensure the provided order matches the original allocation and that the operation is serialized against other preservation API calls. Signed-off-by: Pranjal Shrivastava --- include/linux/kexec_handover.h | 7 +++++++ kernel/liveupdate/kexec_handover.c | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 8968c56d2d73..452e38bb2076 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -24,6 +24,7 @@ int kho_preserve_folio(struct folio *folio); void kho_unpreserve_folio(struct folio *folio); int kho_preserve_pages(struct page *page, unsigned long nr_pages); void kho_unpreserve_pages(struct page *page, unsigned long nr_pages); +int kho_split_preserved_pages(struct page *page, unsigned int order); int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation); void kho_unpreserve_vmalloc(struct kho_vmalloc *preservation); void *kho_alloc_preserve(size_t size); @@ -65,6 +66,12 @@ static inline int kho_preserve_pages(struct page *page, unsigned int nr_pages) static inline void kho_unpreserve_pages(struct page *page, unsigned int nr_pages) { } +static inline int kho_split_preserved_pages(struct page *page, + unsigned int order) +{ + return -EOPNOTSUPP; +} + static inline int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation) { diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index f6ca5e24c740..ea08248901b5 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1018,6 +1018,29 @@ void kho_unpreserve_pages(struct page *page, unsigned long nr_pages) } EXPORT_SYMBOL_GPL(kho_unpreserve_pages); +/** + * kho_split_preserved_pages - split contiguous pages that are preserved + * @page: first page in the list. + * @order: the order of the original allocation. + * + * This function allows to split a high-order allocation that has been + * preserved across kexec. It unpreserves the pages, splits them using + * split_page() and then re-preserves them as individual pages. + * + * This function MUST only be called on pages that are currently preserved. + * The @order provided MUST match the order used during the initial + * preservation. + * + * Return: 0 on success, or a negative error code on failure. + */ +int kho_split_preserved_pages(struct page *page, unsigned int order) +{ + kho_unpreserve_pages(page, 1UL << order); + split_page(page, order); + return kho_preserve_pages(page, 1UL << order); +} +EXPORT_SYMBOL_GPL(kho_split_preserved_pages); + /* vmalloc flags KHO supports */ #define KHO_VMALLOC_SUPPORTED_FLAGS (VM_ALLOC | VM_ALLOW_HUGE_VMAP) -- 2.55.0.rc0.799.gd6f94ed593-goog