From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 7A8CA25B083 for ; Fri, 3 Jul 2026 02:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783044521; cv=none; b=Oi7fuv6fQDgxzYFdxUAtZExEfICVBLT8YCwhZZQ3bNYqhABiwbB+hhIt0mKWlHObS8QfiVaqGyP57DLp66SN1RRW7REFXLK3tD0ZjN/+/GyDWb8TR4xCljCNM7mYlEnvsoDX2SkUF/dKz3Pn8lUYu15Z6zIQzinscpaARdEQjU4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783044521; c=relaxed/simple; bh=GnsgeqUgdMifxgidM7Ih7aeDsEvVc3yLoeYWmqH+5+g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eGKNxTqrC0QEUczAsVevvBFuVEupp2O2Kmy66PAE52gBWfEoNEhcE+oJOeZhJ8ILLcbp3W1zsl/WdHnYT0mKpoD3XZDIN2OPRyxilFCJvPi0cUmBZW4WqnyA82i0BF0m+s4O5Hn+Yj5aoaXAWT3e+pAFAUiwMItkap9xSr2ijDE= 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=QI5EzCKE; arc=none smtp.client-ip=209.85.215.201 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="QI5EzCKE" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c85a298cd62so91089a12.0 for ; Thu, 02 Jul 2026 19:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783044520; x=1783649320; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gHbIAhxt5ZWMRxF4xCIzHhL4IjTclNl9UE6kteWsf7g=; b=QI5EzCKESrSJ1HcqJl5cS8MnzVCqrksy9FdJm6ez/leINpSKYWKy2e1qGhsv3FOzTH m5gq6Qfy3dflz7Tyeu4hBaAxmJ/eDWaOf4s6okrruLMzQEhGUjiI9pMMLCcTAN/V0iih MYmdVSkcadPmuaqsuIU001U2ufrmgIm25wNQuRedsX7mysNsijypXt9dUGCHb2C3zhYA PnWOxXeH1QiPTe6uDJvhnkcr0sRN6Sd7wW3dkGs/2NiRH4sj2u0U8u9bSIYcZONDcHhN z6df6Hn983JhNH9uje9aR7Sj796qRptMQHkudWosAjKzZnJiFf6EDIozQbB4zLvPiRx7 MbPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783044520; x=1783649320; h=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; bh=gHbIAhxt5ZWMRxF4xCIzHhL4IjTclNl9UE6kteWsf7g=; b=c+IyZTLZTQpHZ5cadkbv5HpzSNrY3RJlLBu1iWp2nvArjLynfBs2RDwai0xGl4PtZ4 2mp58jyGmWMJWHPspHZSCPm1LlASM+jWHPQr8ZmBSNWqU8qKuh7aUFfUNxep91rdjq9Y q7GCeO9E3yAucebd5PmadyPANakjk9pGleWOgrSeeWn/7hoWWOyBaeYYNGgYioEe0l4e HDGmNQRz+BVT0FuXMaQ+fsU4hrGrxFyboYAounu21ROnh5TGW8/UtjjEnQjcCJ5pmu+d IOZh+DtEnikR7dXZ7jj4xNViz2Ie4vgoTD/HDv2c70YDA5RXROKc+eIBh/m3fgOvzbgv 0kSg== X-Forwarded-Encrypted: i=1; AFNElJ+Gb+kADp4omRd12p4/XqGqjZ+TrCZl+dVgzEG595IXv96ItFMH/DCCSfQYP6IrFqVBM/xi1CcIlYRmRyU=@vger.kernel.org X-Gm-Message-State: AOJu0YydvdPulktuLJrOozbGcQ+g62OpauPBeJgPX7EMky4VdJSxawYt f4hjAMHeDDK3Tq/LZBOTyQ2OdK3VWffD509jbsR8KmZpdHI5Vb1sbruIKPbVLIpTYGItAbLBRQd thg== X-Received: from pgbr31.prod.google.com ([2002:a63:5d1f:0:b0:c9a:37aa:b17d]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:6a1b:b0:3b2:924c:566e with SMTP id adf61e73a8af0-3bfed3dfce5mr9656083637.36.1783044519485; Thu, 02 Jul 2026 19:08:39 -0700 (PDT) Date: Fri, 3 Jul 2026 02:08:30 +0000 In-Reply-To: <20260703020832.1731864-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: <20260703020832.1731864-1-praan@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260703020832.1731864-3-praan@google.com> Subject: [RFC PATCH 2/4] kho: Detect preserved page types 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" Detect page types in kho_preserve_pages() by peeking into the refcount of the second page in each block of order > 0. If the second page has a non-zero reference count, it indicates that the block has been split. Otherwise, treated it as a contiguous, unsplit block. Since the page type is now part of the radix tree key, update the unpreserve path to use the same detection logic to ensure it can correctly locate and delete existing entries. Signed-off-by: Pranjal Shrivastava --- kernel/liveupdate/kexec_handover.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index f829ffdd00f4..d6e81f72fe5d 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -918,15 +918,29 @@ static unsigned int __kho_preserve_pages_order(unsigned long start_pfn, return order; } +static bool kho_is_page_split(unsigned long pfn, unsigned int order) +{ + /* + * If the refcount of the second page is non-zero, this block + * has been split. + */ + if (order > 0 && page_ref_count(pfn_to_page(pfn + 1)) != 0) + return true; + + return false; +} + static void __kho_unpreserve(struct kho_radix_tree *tree, unsigned long pfn, unsigned long end_pfn) { - unsigned int order; - while (pfn < end_pfn) { - order = __kho_preserve_pages_order(pfn, end_pfn); + unsigned int order = __kho_preserve_pages_order(pfn, end_pfn); + enum kho_page_type type; - kho_radix_del_page(tree, pfn, order, KHO_PAGE_CONTIG); + type = kho_is_page_split(pfn, order) ? KHO_PAGE_SPLIT : + KHO_PAGE_CONTIG; + + kho_radix_del_page(tree, pfn, order, type); pfn += 1 << order; } @@ -958,8 +972,12 @@ int kho_preserve_pages(struct page *page, unsigned long nr_pages) while (pfn < end_pfn) { unsigned int order = __kho_preserve_pages_order(pfn, end_pfn); + enum kho_page_type type; + + type = kho_is_page_split(pfn, order) ? KHO_PAGE_SPLIT : + KHO_PAGE_CONTIG; - err = kho_radix_add_page(tree, pfn, order, KHO_PAGE_CONTIG); + err = kho_radix_add_page(tree, pfn, order, type); if (err) { failed_pfn = pfn; break; -- 2.55.0.rc0.799.gd6f94ed593-goog