From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 4A6E1403B18 for ; Mon, 3 Aug 2026 11:39:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785757192; cv=none; b=ULSkRdNrBwb9ldIaVHZgxsbM6WsNo5jN7uE/cku4u3jAKVgRXr/V+W3B3Ulid77mlooBe5HI3QVj3BpNL3w0s2KzmK0YqsKh9H0oFT7uddzBEta+SiNP2+rZ3JsSQqCeV+Qn6h4jIJwS7DXuhx+19hh+W2OA5xQYJSw+SXvT9jg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785757192; c=relaxed/simple; bh=7iCE6EPLEMQ+f44j4KmLuOJ6AsOZQdBDHPzhD2tIc3k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=em+ydXchwg2o05jlrrpqQsoptKKIrfhZb9QJbe5AmsEQUspMSYZ/itML6g9bvN3PqrU4Ff2hKU1bv+7QlJdqm0E43UI9OXbMo1QxvjhVAKIIDkXWf/7GEHXX3Qy6/9cLBj1SvicdHqNcoP6hUdcbtRydKyf8ixQIB2UhrhiyYQE= 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=RWglqRU9; arc=none smtp.client-ip=209.85.215.198 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="RWglqRU9" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-ca6bd8a190cso4109520a12.0 for ; Mon, 03 Aug 2026 04:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785757190; x=1786361990; 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=vv6DECOvSmngHsx3EI9j0R7ut4SHpWl9EkNqXk3pPjk=; b=RWglqRU9EqinXpznbmQcJOiBs+DqTljoSy9zzWTCCPiyJhh0ElrSZr3aioQEyWcsDE ZlIgxi+L6hzdUzcNQRK8hDTCBI+WNXS0oYa298a/P7sEhKP2ll9t0bR7JWBfdZiyfHsN LbOQEvq4BsTaTvvbnahlXEOJ9VWzNtUBD4lvOIr5UNyaxz+BVy60UA/BJ3vrhCbTDQP9 0xEm3J9QqKKJAbKaVlJ0rYxkz31x1kFaIfegg6f6ATlYa5qfgHBoc0tQJ0Hup0YhWtIg aa46a8Ko08ovT3BrLWpkxC4uf8xsBLDxNQ1x70hlSsdiufwMmJzNuUPobPtiM2bpQ5ES aT8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785757190; x=1786361990; 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=vv6DECOvSmngHsx3EI9j0R7ut4SHpWl9EkNqXk3pPjk=; b=pUQWL/COpTEwOpG9oE8xxQFHH3ctGZo8g2TpmC/m4qreECDMeRFyMJ/qvXHq7/jHcC Lnpg6ph7HyZXUVq3+G/3zqaFC7axor7+OwqokSAWKkn2lDCo+6ppnN56b4uclOmnP580 ST4Pq6u6vy9WBxwsCskEM90Bqh1TfpUJm/gGA5lV1IAdKb+fIUDpJOlLXsZZN2h58Ohy 3Rx77R4GRlN2LrJVqyWpUci/DndNWUikX+8JD3jOeTgpV8yGJwQ2wtdprMVOmuk9tl45 8FrNoX+cR0D0DJ/TLWm+46DTTzX88JW/T4lk2tOtC9OWp/aHhaNulFzRlv5kR9j6wzad 4p3Q== X-Forwarded-Encrypted: i=1; AHgh+RriCKH6fGpCjTcAgk1LjperFbT+/1eO7SyBoFzezzsXLqxLdAbZGpDJCXj4IZp7MttS4EJPXck2OT0e5/Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yyvf7Z3DjRd9VIfnoQ+yNJ65eepYqYU+ls4FWmh/k5NakwYD4CF ZkONuJIIev7MnwwZpzE1F6s9Qy8GBOReLQL+79g6r3Xy7HZIR0o/PieaewTcUSdJUrgyuKBc/G/ +gw== X-Received: from pgvi9.prod.google.com ([2002:a65:61a9:0:b0:c9a:c533:8329]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:e58d:b0:3bf:e3d6:ab5a with SMTP id adf61e73a8af0-3c92a8f327cmr10771333637.52.1785757190359; Mon, 03 Aug 2026 04:39:50 -0700 (PDT) Date: Mon, 3 Aug 2026 11:39:42 +0000 In-Reply-To: <20260803113944.3694290-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: <20260803113944.3694290-1-praan@google.com> X-Mailer: git-send-email 2.55.0.508.g3f0d502094-goog Message-ID: <20260803113944.3694290-2-praan@google.com> Subject: [PATCH v4 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.508.g3f0d502094-goog