From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 EF4D81EEA54 for ; Fri, 1 May 2026 09:49:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777628972; cv=none; b=l7RypW/l55bUXI/IwxbiRSoVyf2fwQvw6rKsWmAxdZ89A4ZxYR0M0qyRdVMTqR7mQCNtdPdSyE69bk4pP1pYt9khXfTBCL/IDGH7p6EXwoL+0lV3KrUo7OLe7Szt3BsuppcZA+0TDpM38RKp3f4OVJloIDVXTJurIYYfW+HyKes= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777628972; c=relaxed/simple; bh=U4PedywE6nlu7XEW35KkVkhp/J/rX1qJ2BYv5Pn/fC0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TOcJlfICYtvnTBzcF4E9oEKok69FOgF4t+Lpk1R6MwfhbWphZFDCYtO4xUo8oUFqxDsp48zQ4WUKYtFKO6DtoJR8h9Zj8Uj6OkwSumh6gpdYU7/apJ3ib1mdxCRaHARTP31rvUKdVuBygL3dKB7QCox2meXjT1zbB5tMhXfpkg0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lzEpjfF7; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lzEpjfF7" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-82f431c0ab6so865565b3a.0 for ; Fri, 01 May 2026 02:49:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777628970; x=1778233770; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D3bCYUylpNTAuWyS15iXLK7eGG+AcPbkT8lStAYKXTI=; b=lzEpjfF7E8z9LE65pX/QBVi3OIO8jMHLL8w5T1yJS6CVUpbp2e0CAqmfX0ySl+0crU 8eV2APaQKA4XntDor2W4dc9yKCQYX9lQD68jcugRHrKk4ROx5lNVZpnnXLIWinwdltAK Ek+ZC3RJCjNkVp+ODGC741YjmMFA7emt55jNrH2tOumE1jR2ckPKQ5nmlRqo88bseMvN FzVPuPCKvGKnFa69RLMf9SmrG9onZb3ko6glV9LqPi0/aF1XwRTMwp97R/S6HSmS9ZS4 hE2+KkkxK8TvfqXOvpV6vkbXhoGHW8bzxRnHrSuXP4/NNPuJda0jimP4yL+PpNnrswnA aTZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777628970; x=1778233770; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=D3bCYUylpNTAuWyS15iXLK7eGG+AcPbkT8lStAYKXTI=; b=NvL21gnAFL9HsEvuvBmgXlpZOioUO1bPYD6i4qWrob+HCIR1dL13i6xldVTzXtYIRO od8kpEsm8DqTgNK+4Nq9R8+Zn7VdggQajPKnGEprqYCZCst4twUrnl69Wy7/YN9G2kJF fumgtRTFZhyZnkFn2TiwLH7nLhv5iHrHYqUjItxzGdoTWbtgo1gZBGtVB6M43mt8Gdlr G4phIyff3iucUvK38KilX5OSnyjsQxnsOWswK/3K7tXXY45t1NxcUvL5XxBPvknZRLgy xjI1MERMjsSZkdLRRcYlGwuvSVpQ+usbMtdue0mKVUWoOyMyl/qSPVi4EqSSzvNp1UCs ixdw== X-Forwarded-Encrypted: i=1; AFNElJ8r6J0GWYWZhg/yCqA09dcwuexFusbRZ5p+ISUd0+WaRk32rh5wZ1wVjO04s62+ciRjoCMfRBwMZHkTGok=@vger.kernel.org X-Gm-Message-State: AOJu0YzyrZlxy7KQuepzncTdYSBDTHlBdXlyD0+pIDjXtXLJ3NSnLB3p P2NpUvxubMduCpem3rxbyrfq+a///wRd8yDHcRvEniaL+U55lGvC9ixx X-Gm-Gg: AeBDiet1kQI7UYVj39THB6DFaLTtWba2d842ORPke5CfrUNW8/IrIzzV2Ra/sqSW3/q m/8ozoraE4Joy6MgmlaShcDZNpOv3j4OcDmo8ajm+06fWtBgHeb1rS3IU8lWyYLbg7iF2SW+WFU R/GVmsUBY9IIv4gTwo73fvEkXhxfNBID6qS2bua+9PteaiWIjx8r3Hwa4HVEmdSSmNUIdavUnNH QaUY7VstJo28v16BhaJHekDUUNTeEoZHo/Yg/yEQlPWb6yiaBJtv/mbCoGbuT/HloE55+wGnwPU lKKnTIkRzYVomxXv28KDAQQD+PCkM3XoiHsNiu5UP3HgvcqUsJKULw2YoCZZgyauNakJJgV0WuX eAWsxF4bw10tZ6NZKFAxN7+i3u46ieSSP5Mo8DjBX845F94bjv2BaUnFC8YzlQ9abZgAgW4royV 5qI5ZDRX/WdMjXLJGpYciCqSFcI/WCSibPof7Eew== X-Received: by 2002:aa7:8886:0:b0:82f:9985:d4a1 with SMTP id d2e1a72fcca58-8351a58db50mr2518784b3a.24.1777628970155; Fri, 01 May 2026 02:49:30 -0700 (PDT) Received: from laptop ([2001:4455:8025:be00:eebe:247e:613c:24d7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8351582dd55sm2042729b3a.1.2026.05.01.02.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 02:49:29 -0700 (PDT) From: Cris Jacob Maamor To: Mike Rapoport , Pasha Tatashin , Pratyush Yadav Cc: Alexander Graf , Andrew Morton , Dan Carpenter , Greg Kroah-Hartman , kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC 1/5] kexec: handover: add helper to check preserved page ranges Date: Fri, 1 May 2026 17:46:33 +0800 Message-ID: <20260501094637.38650-2-crisjacobmaamor@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260501094637.38650-1-crisjacobmaamor@gmail.com> References: <20260501094637.38650-1-crisjacobmaamor@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Signed-off-by: Cris Jacob Maamor --- include/linux/kexec_handover.h | 6 +++++ kernel/liveupdate/kexec_handover.c | 35 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 8968c56d2d73..fb09943ab232 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -19,6 +19,7 @@ struct page; #ifdef CONFIG_KEXEC_HANDOVER bool kho_is_enabled(void); bool is_kho_boot(void); +bool kho_is_preserved(phys_addr_t phys, unsigned long nr_pages); int kho_preserve_folio(struct folio *folio); void kho_unpreserve_folio(struct folio *folio); @@ -51,6 +52,11 @@ static inline bool is_kho_boot(void) return false; } +static inline bool kho_is_preserved(phys_addr_t phys, unsigned long nr_pages) +{ + return false; +} + static inline int kho_preserve_folio(struct folio *folio) { return -EOPNOTSUPP; diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index 94762de1fe5f..fe9f11190705 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -10,6 +10,7 @@ #define pr_fmt(fmt) "KHO: " fmt +#include #include #include #include @@ -429,6 +430,40 @@ static struct page *kho_restore_page(phys_addr_t phys, bool is_folio) return page; } +/** + * kho_is_preserved - Verify that a physical page range belongs to KHO. + * @phys: physical address of the first page in the range. + * @nr_pages: number of pages that the caller expects to access. + * + * Use this before phys_to_virt() when a physical address comes from restored + * metadata. It checks that @phys starts a KHO-preserved allocation large + * enough to cover @nr_pages. + * + * This only checks the KHO marker. It does not restore, free, or take + * ownership of the pages. + * + * Return: true if @phys starts a preserved KHO allocation large enough to cover + * @nr_pages, false otherwise. + */ +bool kho_is_preserved(phys_addr_t phys, unsigned long nr_pages) +{ + struct page *page; + union kho_page_info info; + + if (!nr_pages || !IS_ALIGNED(phys, PAGE_SIZE)) + return false; + + page = pfn_to_online_page(PHYS_PFN(phys)); + if (!page) + return false; + + info.page_private = page->private; + if (info.magic != KHO_PAGE_MAGIC || info.order >= BITS_PER_LONG) + return false; + + return nr_pages <= BIT(info.order); +} + /** * kho_restore_folio - recreates the folio from the preserved memory. * @phys: physical address of the folio. -- 2.53.0