From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 2AC3234DB74 for ; Mon, 13 Jul 2026 20:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783975780; cv=none; b=OYA8iH4DARmY6vCcg78/8rrYexg1ojHZZqSiyEEhNp/k+DLKdLsYd+gGpPAI4hxppQnY/9qPktbE1SsHH/aGoGEVX6RnN0KKBSrj02tylTuCqoB0nNCb2ZABdnyyDXzoqmpgoYKr9PaHMyxtdA+3pIiabkzTDcQfr0DzKKfZ5u8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783975780; c=relaxed/simple; bh=I+2xE0Ac232QSvoVAiVpXs9HTmV1T/GW62YkOGmx49k=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=gZO6ofysxHkW18gSoJvQ+lo1aE3rIX1/lFiwpH+xMVoNX03qHSTWFvct/e3UXjpXXNwx1s4ITwOb4VUsrCpyxmJG4DH4QVly9zz4muED2W3soaNyP9rFM22xKRlfzOrycbE1FC4s+XKIkoiEtMHIJqsu1/GRXJvm3LXQpK/XIrw= 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=Yqlo03E3; arc=none smtp.client-ip=209.85.215.202 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="Yqlo03E3" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-caf5fa127d4so374839a12.0 for ; Mon, 13 Jul 2026 13:49:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783975778; x=1784580578; 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=eBZnUR39vw6RjG/0+G3LAv2Ug55ZNjpQuLX/y4dLZaU=; b=Yqlo03E386NUFikH28XOQGIHhPd8Zr75ibqpN0t+Qpu1h+uivEUUZwVBbj2Q9xKuM7 z+iFgROHNR/UedgFU/+GSljTuyXKgazGE6THf8te9k7ZrwG3RktjCiSx5vVRR/Cip5kN cRZJM0sLxF0zuWb19U4f/ovf4wdTemk+l+uzQqlBl5Z2u1QshCgV6mzgLy56cHvjMbeQ KjzawXvGuudazRryUOVxIszTvKxa7Vo5mngBbyqg5yoifq4WkJrWyd14Srnoeifxbzh5 aEAHO7GsIlNcPEBwruEwV+yUkNA7+VhNGHEzwzb9MnxFWlJ/lldHNm9k38c6sWoQ7V8B 7f+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783975778; x=1784580578; 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=eBZnUR39vw6RjG/0+G3LAv2Ug55ZNjpQuLX/y4dLZaU=; b=nZKnsGRbBYGpPzVFRvggjHRsd4OQJhEdE7dkvXYnS3n9Os6b3FjK80TkXlLFAtI4t9 9LS/8yBOZ9UNgvbHGS7t4byNniC8G7UXKLG4mzKrJu+q4Y9uJXFA5DACkt2E7pzm8/8w Zcfk+tR7OeME422307MbT57XmoYfz8dF5tHkFxesPjeIgOyu+iZZOls62J3Ty1qbGA8w SAneSmKBEbLwfW3QZIVgarpHrtPPfxYuzLx2B1/7LQ5DldeCTJqELavQeuhntPY8QD57 hn95vNPs7hZ8RuiI7098mNrGFcZFHSZAEeoCMVLKdYkVzPvYNpnjiIHzPlr/QHmR7t78 Aeog== X-Forwarded-Encrypted: i=1; AHgh+RptD9LkuoRHWXcdNR8HAgG1hLVcfoZIGskchvgn+TzCoNmdAeOODEmUAHCueHQhTwdBoaBL0FbOibmTtrQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0Vi4uTBNX6wyfF+egp6gFhzW447V4BpNGNl2Y6LYNSO+xF664 AGWr3+653Zy3DhI7fCOeenHdYhsomuxiFLjlp4snJL342Rxj7q992+Bn3DmAWlnLPyjQYQtX7mE D2w== X-Received: from pfbha14.prod.google.com ([2002:a05:6a00:850e:b0:847:9540:3064]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:22ce:b0:847:8f0d:cc09 with SMTP id d2e1a72fcca58-8488970ab05mr9541989b3a.44.1783975778163; Mon, 13 Jul 2026 13:49:38 -0700 (PDT) Date: Mon, 13 Jul 2026 20:49:33 +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.141.g00534a21ce-goog Message-ID: <20260713204935.3069000-1-praan@google.com> Subject: [RFC PATCH v2 0/2] kho: support preserving unsplit 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" 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 unsplit state, only the head page carries a refcount of 1, while all tail pages have a refcount of 0. Consequently, when these contiguous but unsplit 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 unsplit pages. Callers are now explicitly specify if a block is unsplit & preserve it 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_unsplit_pages(), which is shared between folios and unsplit page restore APIs. [v2] - 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 & unsplit 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 unsplit pages kho: Introduce preserve/restore APIs for unsplit pages include/linux/kexec_handover.h | 10 +++ kernel/liveupdate/kexec_handover.c | 115 +++++++++++++++++++++++++---- 2 files changed, 111 insertions(+), 14 deletions(-) base-commit: 0f26556c5eeea62cc934fa8938b148aa5844a6b6 -- 2.55.0.141.g00534a21ce-goog