From nobody Thu Apr 2 15:41:19 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 B5BAF3E51CF for ; Tue, 17 Mar 2026 14:15:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773756947; cv=none; b=e3L10RwBPaTPazlxBBFfWPXYHN0rA6vxEW7U0OI6MPCRDO7x/AlGyTIYvJ/IB6+9hc5+1LxWil/8IW7bakjzkGWMOV2tXDwRKKZ2mWuwZSg1yzGqtoC6Hn6IW4+sfw8intRIl4kcTwwx3T8jKqLzqhy1tQNqiWxC14fRyr/apxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773756947; c=relaxed/simple; bh=LOrfLnP3RZxCRYFPh7LcX+0C3qA1PGoymsVNK00PspE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XNZfQiXK8D89zWtShRH6hnkpCrPn84f7c89G8GvYcYb/XEz+jNlkbZJEBetz3mzqxHxlemE3ZjY7QGzwZ6zkGwd72T3Wk+ShZ+p4aUXTJ2Ex0d+pcDYQtvPnHUMSV+Bb4hSoJxZ7JIpoIipKvPeaBrTUjDMGoUQC/+LWGuTppa4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mclapinski.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aK74jQuO; arc=none smtp.client-ip=209.85.128.74 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--mclapinski.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aK74jQuO" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-485350666bfso46293565e9.3 for ; Tue, 17 Mar 2026 07:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773756944; x=1774361744; 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=6pQdqVuW3s3IY2V2/GcIHf4+cwJRcBc6iC91+pnO9/s=; b=aK74jQuOKNaZi954mU/EZtTwO79pyq7J/ehEEWd7NL3Z1BdyoajwHriku1SdIz/LeR 2BemxXa5q74FjTaGxIFp4E6FfECmbuf5MBohByzXANrWk7yJhz4Ru3p9TBV/NrHGapxI 4u/BCu68qGL1oYjoQqA9bK1+PEWhAwRJkX5Bx43O6SgFeiO570zlmXCWGjGS5urRgVy9 mBcMwZbg2rGnugb0M3J3c5IRTPx7NWwspgAHoHj8v2c9HnFz96/pU9HNiGV4Ot2c2BU3 lBvsbDskfkKw23mlOC3En/S7Byh6hNc9Dji0a3TQkx6Fe/88Etc/uI4OwnBaHNhz7u4+ OGhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773756944; x=1774361744; 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=6pQdqVuW3s3IY2V2/GcIHf4+cwJRcBc6iC91+pnO9/s=; b=sk4zGD4zFaO71OLw98RDJyq6YiaSUU+VtYn7j9a2sabicLJtX/92Xckl6FVW6/jXZm 8W86rsMNzKvF5VB8g0RyeGTqX9EUtqQCub35BQ4DFlUyCNT1Gn14ReNhDU2ySycmBEaS 46GH8uTi7+7CDbe2GVk700emmye5BJ+NqcwVn8UtRf1mwALqApKRb5MmyHZtdoZ6eJoB qUbCrbgufdSQfQFEuLFIovquNoJh+p6lRq8w6EaF8QpKs42REyJlqC8nPgW0KROw6QLr rzGuQ6nq1+TMq2yaahcdMfCVRNMhY1QKMSyZtdQLw/WdRyPiDoQRYb72FyIeYdPJPEKl s5iw== X-Gm-Message-State: AOJu0YzCzd+yVLPiGg/E5vWd7sC/GvKqXGiN620OGeBdkT2+7iiotAJu DBbqeKRuhFjisnQuGvNxQwWhNcQfpPLhF76QqID/zfdjcDH/lN4ivqXoaX7BvO5GREAOyNW+e41 P/ZCUc/nv6K/PJEkJ2xUWRA== X-Received: from wmz7.prod.google.com ([2002:a05:600c:6b67:b0:485:3aa2:da59]) (user=mclapinski job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4583:b0:485:3f17:410 with SMTP id 5b1f17b1804b1-485566fd031mr299341025e9.16.1773756943916; Tue, 17 Mar 2026 07:15:43 -0700 (PDT) Date: Tue, 17 Mar 2026 15:15:32 +0100 In-Reply-To: <20260317141534.815634-1-mclapinski@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260317141534.815634-1-mclapinski@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260317141534.815634-2-mclapinski@google.com> Subject: [PATCH v7 1/3] kho: make kho_scratch_overlap usable outside debugging From: Michal Clapinski To: Evangelos Petrongonas , Pasha Tatashin , Mike Rapoport , Pratyush Yadav , Alexander Graf , Samiullah Khawaja , kexec@lists.infradead.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Michal Clapinski Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Also return false if kho_scratch is NULL. Signed-off-by: Michal Clapinski --- include/linux/kexec_handover.h | 6 +++++ kernel/liveupdate/Makefile | 1 - kernel/liveupdate/kexec_handover.c | 28 ++++++++++++++++++--- kernel/liveupdate/kexec_handover_debug.c | 25 ------------------ kernel/liveupdate/kexec_handover_internal.h | 7 ++++-- 5 files changed, 35 insertions(+), 32 deletions(-) delete mode 100644 kernel/liveupdate/kexec_handover_debug.c diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index ac4129d1d741..6a0e572c3adc 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -35,6 +35,7 @@ void *kho_restore_vmalloc(const struct kho_vmalloc *prese= rvation); int kho_add_subtree(const char *name, void *fdt); void kho_remove_subtree(void *fdt); int kho_retrieve_subtree(const char *name, phys_addr_t *phys); +bool kho_scratch_overlap(phys_addr_t phys, size_t size); =20 void kho_memory_init(void); =20 @@ -109,6 +110,11 @@ static inline int kho_retrieve_subtree(const char *nam= e, phys_addr_t *phys) return -EOPNOTSUPP; } =20 +static inline bool kho_scratch_overlap(phys_addr_t phys, size_t size) +{ + return false; +} + static inline void kho_memory_init(void) { } =20 static inline void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, diff --git a/kernel/liveupdate/Makefile b/kernel/liveupdate/Makefile index d2f779cbe279..dc352839ccf0 100644 --- a/kernel/liveupdate/Makefile +++ b/kernel/liveupdate/Makefile @@ -7,7 +7,6 @@ luo-y :=3D \ luo_session.o =20 obj-$(CONFIG_KEXEC_HANDOVER) +=3D kexec_handover.o -obj-$(CONFIG_KEXEC_HANDOVER_DEBUG) +=3D kexec_handover_debug.o obj-$(CONFIG_KEXEC_HANDOVER_DEBUGFS) +=3D kexec_handover_debugfs.o =20 obj-$(CONFIG_LIVEUPDATE) +=3D luo.o diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 532f455c5d4f..c9b982372d6e 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -820,7 +820,8 @@ int kho_preserve_folio(struct folio *folio) const unsigned long pfn =3D folio_pfn(folio); const unsigned int order =3D folio_order(folio); =20 - if (WARN_ON(kho_scratch_overlap(pfn << PAGE_SHIFT, PAGE_SIZE << order))) + if (WARN_ON(kho_scratch_overlap_debug(pfn << PAGE_SHIFT, + PAGE_SIZE << order))) return -EINVAL; =20 return kho_radix_add_page(tree, pfn, order); @@ -864,10 +865,9 @@ int kho_preserve_pages(struct page *page, unsigned lon= g nr_pages) unsigned long failed_pfn =3D 0; int err =3D 0; =20 - if (WARN_ON(kho_scratch_overlap(start_pfn << PAGE_SHIFT, - nr_pages << PAGE_SHIFT))) { + if (WARN_ON(kho_scratch_overlap_debug(start_pfn << PAGE_SHIFT, + nr_pages << PAGE_SHIFT))) return -EINVAL; - } =20 while (pfn < end_pfn) { unsigned int order =3D @@ -1327,6 +1327,26 @@ int kho_retrieve_subtree(const char *name, phys_addr= _t *phys) } EXPORT_SYMBOL_GPL(kho_retrieve_subtree); =20 +bool kho_scratch_overlap(phys_addr_t phys, size_t size) +{ + phys_addr_t scratch_start, scratch_end; + unsigned int i; + + if (!kho_scratch) + return false; + + for (i =3D 0; i < kho_scratch_cnt; i++) { + scratch_start =3D kho_scratch[i].addr; + scratch_end =3D kho_scratch[i].addr + kho_scratch[i].size; + + if (phys < scratch_end && (phys + size) > scratch_start) + return true; + } + + return false; +} +EXPORT_SYMBOL_GPL(kho_scratch_overlap); + static int __init kho_mem_retrieve(const void *fdt) { struct kho_radix_tree tree; diff --git a/kernel/liveupdate/kexec_handover_debug.c b/kernel/liveupdate/k= exec_handover_debug.c deleted file mode 100644 index 6efb696f5426..000000000000 --- a/kernel/liveupdate/kexec_handover_debug.c +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * kexec_handover_debug.c - kexec handover optional debug functionality - * Copyright (C) 2025 Google LLC, Pasha Tatashin - */ - -#define pr_fmt(fmt) "KHO: " fmt - -#include "kexec_handover_internal.h" - -bool kho_scratch_overlap(phys_addr_t phys, size_t size) -{ - phys_addr_t scratch_start, scratch_end; - unsigned int i; - - for (i =3D 0; i < kho_scratch_cnt; i++) { - scratch_start =3D kho_scratch[i].addr; - scratch_end =3D kho_scratch[i].addr + kho_scratch[i].size; - - if (phys < scratch_end && (phys + size) > scratch_start) - return true; - } - - return false; -} diff --git a/kernel/liveupdate/kexec_handover_internal.h b/kernel/liveupdat= e/kexec_handover_internal.h index 9a832a35254c..804d6a1209b8 100644 --- a/kernel/liveupdate/kexec_handover_internal.h +++ b/kernel/liveupdate/kexec_handover_internal.h @@ -41,9 +41,12 @@ static inline void kho_debugfs_fdt_remove(struct kho_deb= ugfs *dbg, #endif /* CONFIG_KEXEC_HANDOVER_DEBUGFS */ =20 #ifdef CONFIG_KEXEC_HANDOVER_DEBUG -bool kho_scratch_overlap(phys_addr_t phys, size_t size); +static inline bool kho_scratch_overlap_debug(phys_addr_t phys, size_t size) +{ + return kho_scratch_overlap(phys, size); +} #else -static inline bool kho_scratch_overlap(phys_addr_t phys, size_t size) +static inline bool kho_scratch_overlap_debug(phys_addr_t phys, size_t size) { return false; } --=20 2.53.0.851.ga537e3e6e9-goog