From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (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 219253B9DAB for ; Mon, 3 Aug 2026 11:39:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785757188; cv=none; b=bYLZ0RZ0jOT9nYxENs8DN7e2vu/uug2EM/hcprONWePh8vsaXnuYiytXWMpXW7C0yJonNu+CwloTBtE+eJvgQgk4jl7clh4wYonPExKOglwGR7yMKja5tomPcSm/oto64AvSan2gBfC259hRWbRxCVY7r70THuopHl7GZWmabv8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785757188; c=relaxed/simple; bh=pr1Y7eRsXSGVNPSF2q0MJMydBPBevwNUpTj+xlbqJIM=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=oPmLsSMerhOJM0Yo9N159GKoMq0U0UrAeUbz0ZOl7wrtFuPrsmnPkIRyI7PZNMC3lYjwi5nZ7lh+TzX2yho/k2H4/b+5fVJ+X5d+JqSkcJrIFO/RrqlRwGigSUzUiPTjUOLbw7/jRcFh0kueYeB9p+ZmsdE+07KGr/iqD5LfJic= 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=WgeUKJtn; arc=none smtp.client-ip=209.85.215.199 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="WgeUKJtn" Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-cb835525b13so4142587a12.1 for ; Mon, 03 Aug 2026 04:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785757186; x=1786361986; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=93Zcj2NXzxZtscFdS8APS888IZfB2IV9unzK92NNaNs=; b=WgeUKJtnq4VEYDy+mVsWQoc84IOpftCohFEQ+9hBmyb7+kreKlBLEgCTHChUk21kcA dAHwiFcI3w3I+y7/vGIpv6dRiWvc/jWY5l6Xz8+5r0uf3ZmjwzEhSpLoZtkIWKeufElq pTWr5ehLzYGnhJo49USpaCvbusNp+AqnM7slga4gx0CLPZq4gHT4GhEvPzBsBNyVh8o1 MgnIslQuNLtKR1biVzJwVeeQSySTKVJ128w+76EXpIwwkktwzzfVNb1HBbD98qUOI+FI ItsBWn2DvV/c1DbgTK4/p9DUvd6oS1Ts6OqilvphMvmP1Qe43qWINzeQrOxXwPEONlEf xqUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785757186; x=1786361986; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=93Zcj2NXzxZtscFdS8APS888IZfB2IV9unzK92NNaNs=; b=movelxdIpzftUnf7rtF5wtJFs0JSeqrwIXnJfa+S+zCP6M4d7U/ojwbpNQj2ds6B2L plR8MzxFWB1ykx8QzfCZxJkc16wNfNAGbsw5untkhVurBC5B1xkT1v48HYeagY3XinnM AFaDMoBX8TXlbi0ZUpoODSUURbkGJdd3MTyZ/Y8FCwNnHmg8OdIKqBvWBF9UBut//3sm nd16yHEfxS2ImaRc5ruXNhlW/ZSMto1LOM5t2qsTuyOf1UTsnSHz62V8q9NDA4uvWQF1 TxFWFGFbdw2tciiUMqevVw+TapDPpJtnkJCCq55gq1f1H6046ZbYtbsrULv89q/1s57Z 3cAw== X-Forwarded-Encrypted: i=1; AHgh+Rr46TDhcKGSP5cvGHbH3XxdiigtBXeyIepiPshpAyRUXxWdjZmQ7Z0IDOkjxmEM2IXmKWsVWvC0UW0YLKA=@vger.kernel.org X-Gm-Message-State: AOJu0YzEdyVjvd8xEYxEMafs8AS9lqXeigglk6+NhQ5pJ13IE76vBa8n rFmsBK2/f0u4z9zgqlPtQseEhgUFCjUe3pFOxKCSkgSuUtnt8Osl+rOxSBENjDb3uIPyhKcb20D 6nQ== X-Received: from pgmn11.prod.google.com ([2002:a63:5c4b:0:b0:c8c:68c0:9240]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:114c:b0:3c9:1c8:2b60 with SMTP id adf61e73a8af0-3c92a94eed9mr9848362637.65.1785757186070; Mon, 03 Aug 2026 04:39:46 -0700 (PDT) Date: Mon, 3 Aug 2026 11:39:41 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.508.g3f0d502094-goog Message-ID: <20260803113944.3694290-1-praan@google.com> Subject: [PATCH v4 0/2] kho: support preserving high-order non-compound 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" Introduction ============ This series is required for the ongoing effort to preserve DMA allocations across KHO [1]. It addresses a fundamental mismatch between the current KHO restoration logic and the physical reality of high-order buddy allocations. The Problem =========== The current KHO restore implementation treats all multi-page blocks as split pages during restoration. Specifically, kho_restore_pages() initializes every 4KB sub-page with a refcount of 1. However, many kernel subsystems, most notably the DMA allocator (via dma_alloc_coherent), frequently return high-order non-compound pages. In this state, only the head page carries a refcount of 1, while all tail pages have a refcount of 0. Consequently, when these contiguous blocks are restored by KHO in the new kernel, the forced reference count of 1 on tail pages causes some trouble with the buddy allocator. Downstream of the eventual free path, __free_pages_prepare() [2] ends up calling page_expected_state() [3] when is_check_pages_enabled() returns true (triggered when CONFIG_DEBUG_VM is enabled or debug_pagealloc=on). This detects the unexpected non-zero reference counts on tail pages [4] and incorrectly taints the kernel while leaking the physical pages in question. Proposed Solution ================= Following feedback on the v1 RFC, this series moves away from auto type detection and instead introduces explicit preserve / restore APIs for high-order pages. Callers now explicitly preserve these high-order blocks as a single unit by using kho_preserve_page() and kho_restore_page(). These functions apply a refcount of 1 to the head page while leaving tail pages at 0. The existing APIs (kho_preserve_pages / kho_restore_pages) remain as is for ranges of independent 4KB pages, continuing to use the split refcount. The internal initialization logic is refactored to provide a helper: kho_init_high_order_page(), which is shared between folios and high-order page restore APIs. We also consolidate the common metadata validation, state clearing, and managed page accounting into __kho_restore_page() to avoid duplication. [v4] - Consolidated adjust_managed_page_count() within __kho_restore_page() [v3] - Renamed "unsplit" terminology to "high-order". - Consolidated the common restoration code (magic checks, private clearing etc.) into the internal __kho_restore_page() helper. [v2] - https://lore.kernel.org/all/20260713204935.3069000-1-praan@google.com/ - Dropped automatic type detection via higher bits in Radix key. - Introduced explicit kho_preserve_page and kho_restore_page helpers. - Refactored internal init logic to share code between folios & high-order pages. [v1] https://lore.kernel.org/all/20260703020832.1731864-1-praan@google.com/ Thanks, Praan [1] https://lore.kernel.org/all/20260708234854.4044652-1-skhawaja@google.com/ [2] https://elixir.bootlin.com/linux/v7.1.1/source/mm/page_alloc.c#L1370 [3] https://elixir.bootlin.com/linux/v7.1.1/source/mm/page_alloc.c#L1027 [4] https://elixir.bootlin.com/linux/v7.1.1/source/mm/page_alloc.c#L1034 Pranjal Shrivastava (2): kho: Introduce a helper to init high order pages kho: Introduce preserve/restore APIs for high-order pages include/linux/kexec_handover.h | 10 +++ kernel/liveupdate/kexec_handover.c | 127 ++++++++++++++++++++++++----- 2 files changed, 115 insertions(+), 22 deletions(-) base-commit: 8ba098e6b6ff0db8edf28528d1552be261af30d4 -- 2.55.0.508.g3f0d502094-goog