From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 4A59A3F39C2 for ; Thu, 23 Jul 2026 20:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784839337; cv=none; b=GO9IuKrIswGq+dxMLMACqTBZlrVd6TIleqs9EUhZJv2uZT+oF/GP8cJL7UD9taVWCUFec6kSWUqEnusZPkccyTGBvWobOEV7Z+NVT7viIrrX7ljggBvkVQyCIgi3pYwmN9KjIfzDkXgQnLaWVsPZt5XgL1GDlOJn0zGE1GgqPWY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784839337; c=relaxed/simple; bh=+/twtWfTOMAhvQXtQTU0c9mQP7LYwclosx+QVrgBKN4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=r87yifxRRt1qHEMz5S1WFXU+NXMoHPKkdaYKeUFna4Yv9B2Ll5oU/b7+V7MwKoGSMDfnAGAtgrnqHvl4Gxl27KjXXZB9JQFRikSasZTCJa2JmgilWrdu4EMWojaNSNrUserYRnf9GW9a0EkNYVVexYNPY+o52+76IP2grkygE2Q= 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=ncE6mlBh; arc=none smtp.client-ip=209.85.214.197 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="ncE6mlBh" Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2cfa55c9430so11230165ad.0 for ; Thu, 23 Jul 2026 13:42:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784839331; x=1785444131; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=pIhtxPilZww/6qXFXyt6pCELZXv5C+7yA4sMxjjosZU=; b=ncE6mlBh2ns+yaHARn/oCjKCDqascBBByIQnKaGGHu90Z/ESkHl27iad/WYjD2C6PL F8ricuYxoi2som996RJwqe6ZBRH+sBEnRJ71C2gPSia/hyS2/DGr23V3kOG8ntNL1WXG Wd130xvm6iOS3Dhobxm1vHS7oZYm3NV2wUvS+46UwfuT/UJf92ZVjNiFEeVkAl3755o6 E6X69MhFn2ku+9fkbUGhIXxPScsarQ47Jis9dTgZ8bo4UM+3Y7X3tC2Ca4txA3wMq+cA kPwCHeNZRPuZ5k9vxazO/W3BzJ2eQFNkfNQnOXRpasMNRr+gWoQ3W2rKL9o54xqCOz5O BPfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784839331; x=1785444131; h=content-type: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:content-type; bh=pIhtxPilZww/6qXFXyt6pCELZXv5C+7yA4sMxjjosZU=; b=YRvU8aCsc6gLjyO2VhqlZeNJTRdDS9EMvtujV3nXANSUwUJIi9p7XQ0kK9WhnPNkoy WNS0jn91UDHGFOTwHrprownWNi6hYZJ89OwGQJE2lNlGle9nntE6QzsW8fTF0RsAVEF/ R2hzOkk498waVr3tkXbU1QWpV+8gjR2jAwOBFNDyH/b0hxZhJdcU0ZIvLxzFMN9osrmg n34UUdJwi1cdMD+3yVITXkqUbrSPz+8CyGVY2V/7TlZNFc0GEYJjO4eH1nMdt7eoBNKB odpZa3wQXhHGiF4qJZQqUAE81m6LvORvUZioGyJXrG1nSrmUHUFBgSe6nWIo7adg/Dr6 3bSQ== X-Forwarded-Encrypted: i=1; AHgh+Ro/JPVEtoGqH4qOQGc9ZaiWLMunsQbWi1h9BSypk1kc4OWhLzFADTicmcwsSUjrMGSBRzutmlJ7cQUTeBI=@vger.kernel.org X-Gm-Message-State: AOJu0YzvG4j1a5wASon+nng1+ZvTCHcOhn4E/EiWqTsCtVBHGjzXBvkW cCtY63HJAUPqO9WVcITLPFBs7Z9pLO9dVI/WKjEvZbj44UeIHcKlTFlEy9o5D1WISNRMvXkhkQL Lsg== X-Received: from plgi16.prod.google.com ([2002:a17:902:cf10:b0:2ca:f1f8:ea00]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d2c9:b0:2ca:6514:9201 with SMTP id d9443c01a7336-2cfa6b7a10dmr57623865ad.15.1784839330855; Thu, 23 Jul 2026 13:42:10 -0700 (PDT) Date: Thu, 23 Jul 2026 20:42:01 +0000 In-Reply-To: <20260723204203.2997395-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: <20260723204203.2997395-1-praan@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260723204203.2997395-2-praan@google.com> Subject: [PATCH v3 1/2] kho: Introduce a helper to init high order pages 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" The current KHO restoration logic assumes all multi-page blocks are split into independent 4KB pages. Break out a helper to prepare for supporting high-order non-compound pages. Extract kho_init_high_order_page() to handle the refcount pattern where only the head page is refcounted. Use the helper for folio restoration that requires a similar refcount logic. Reviewed-by: Samiullah Khawaja Signed-off-by: Pranjal Shrivastava --- kernel/liveupdate/kexec_handover.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index 4834a809985a..e836efd98795 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -357,6 +357,24 @@ int kho_radix_walk_tree(struct kho_radix_tree *tree, } EXPORT_SYMBOL_GPL(kho_radix_walk_tree); +/* For physically contiguous pages. */ +static void kho_init_high_order_page(struct page *page, unsigned int order) +{ + unsigned long nr_pages = (1UL << order); + + /* Head page gets refcount of 1. */ + set_page_count(page, 1); + /* Clear head page's codetag to avoid accounting mismatch. */ + clear_page_tag_ref(page); + + /* For high-order blocks, tail pages get a page count of zero. */ + for (unsigned long i = 1; i < nr_pages; i++) { + set_page_count(page + i, 0); + /* Clear each page's codetag to avoid accounting mismatch. */ + clear_page_tag_ref(page + i); + } +} + /* For physically contiguous 0-order pages. */ static void kho_init_pages(struct page *page, unsigned long nr_pages) { @@ -369,16 +387,7 @@ static void kho_init_pages(struct page *page, unsigned long nr_pages) static void kho_init_folio(struct page *page, unsigned int order) { - unsigned long nr_pages = (1 << order); - - /* Head page gets refcount of 1. */ - set_page_count(page, 1); - /* Clear head page's codetag to avoid accounting mismatch. */ - clear_page_tag_ref(page); - - /* For higher order folios, tail pages get a page count of zero. */ - for (unsigned long i = 1; i < nr_pages; i++) - set_page_count(page + i, 0); + kho_init_high_order_page(page, order); if (order > 0) prep_compound_page(page, order); -- 2.55.0.229.g6434b31f56-goog