Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2833210E3 for ; Sat, 22 Nov 2025 03:45:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763783146; cv=none; b=Zhi7wzjr1Gv9BLGLtCYWIqwAMSzfkqGe0GRYqkkbySDhlkhsb90FccZQtKvva+uYlFLf/THAbWTwxAUxA8vQYaxwZrFL/dk4tUdmpoGcCpwBBEDzg2TXvnZHkw8BAtxv29+u/9b/2D04ipolQGf2QoTUZjj13TMln0JZo/CIXp8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763783146; c=relaxed/simple; bh=R6Y/a9yEVa7YpN12Y2+HTZihoyeXGjuVBOtBLQVy0ro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oin/vHh+cP8264kE13O7UwDBlh0f6f9vSlX4udgKwwzXhweMRn7hzHSNdAVyhHfKMxJ1Phh5+m4qdA9KMrFqVhaNaYkAQI13QCeUbKLp8Ckt+3dMiIf7vloyqAgxYDa/iX1wED1+Uaq/tDUMr5Wf1WGl275fz4DzX5pvFRZjmpo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r0T7cF5L; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r0T7cF5L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 654C9C4CEF5; Sat, 22 Nov 2025 03:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763783145; bh=R6Y/a9yEVa7YpN12Y2+HTZihoyeXGjuVBOtBLQVy0ro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r0T7cF5LM2VwTmtBbywifAKFaEYuub41SNvnbccGa8maItaya06uFTwufZDTCFVXW 4T+tXyLZpdi3YrjopSxmM0rdJLDJ92TmTDRcl3SmHfqKIvBlg4dop3TIRGIo4ABZ1q zyhVaoN8fJdK5mGnnT53x8n5telqQHMgrxFhYdScul22fTcKVPTHb/1J7AVoA8I6Mp eVXJTlzni9PQbI4cbukdqct4XDg4WVhOVLTMsrfUGRIMVIwfF+pvXBhgM0H+U71Mej 02/AMMQm9F4UyUU7l77jmcqq6hdFbcDZrlxGNZJwCvfoFKupWRHnbsHlR/8RNqpvVG mFoaCKksJGeQA== From: Sasha Levin To: stable@vger.kernel.org Cc: "Mike Rapoport (Microsoft)" , Pratyush Yadav , Alexander Graf , Baoquan He , Changyuan Lyu , Chris Li , Jason Gunthorpe , Pasha Tatashin , Andrew Morton , Sasha Levin Subject: [PATCH 6.17.y 1/2] kho: check if kho is finalized in __kho_preserve_order() Date: Fri, 21 Nov 2025 22:45:41 -0500 Message-ID: <20251122034542.2782459-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2025112117-pursuant-varmint-6bbc@gregkh> References: <2025112117-pursuant-varmint-6bbc@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Mike Rapoport (Microsoft)" [ Upstream commit 469661d0d3a55a7ba1e7cb847c26baf78cace086 ] Patch series "kho: add support for preserving vmalloc allocations", v5. Following the discussion about preservation of memfd with LUO [1] these patches add support for preserving vmalloc allocations. Any KHO uses case presumes that there's a data structure that lists physical addresses of preserved folios (and potentially some additional metadata). Allowing vmalloc preservations with KHO allows scalable preservation of such data structures. For instance, instead of allocating array describing preserved folios in the fdt, memfd preservation can use vmalloc: preserved_folios = vmalloc_array(nr_folios, sizeof(*preserved_folios)); memfd_luo_preserve_folios(preserved_folios, folios, nr_folios); kho_preserve_vmalloc(preserved_folios, &folios_info); This patch (of 4): Instead of checking if kho is finalized in each caller of __kho_preserve_order(), do it in the core function itself. Link: https://lkml.kernel.org/r/20250921054458.4043761-1-rppt@kernel.org Link: https://lkml.kernel.org/r/20250921054458.4043761-2-rppt@kernel.org Link: https://lore.kernel.org/all/20250807014442.3829950-30-pasha.tatashin@soleen.com [1] Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav Cc: Alexander Graf Cc: Baoquan He Cc: Changyuan Lyu Cc: Chris Li Cc: Jason Gunthorpe Cc: Pasha Tatashin Signed-off-by: Andrew Morton Stable-dep-of: e38f65d317df ("kho: warn and fail on metadata or preserved memory in scratch area") Signed-off-by: Sasha Levin --- kernel/kexec_handover.c | 55 +++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c index c58afd23a241f..4e5774a6f0738 100644 --- a/kernel/kexec_handover.c +++ b/kernel/kexec_handover.c @@ -91,6 +91,29 @@ struct kho_serialization { struct khoser_mem_chunk *preserved_mem_map; }; +struct kho_out { + struct blocking_notifier_head chain_head; + + struct dentry *dir; + + struct mutex lock; /* protects KHO FDT finalization */ + + struct kho_serialization ser; + bool finalized; +}; + +static struct kho_out kho_out = { + .chain_head = BLOCKING_NOTIFIER_INIT(kho_out.chain_head), + .lock = __MUTEX_INITIALIZER(kho_out.lock), + .ser = { + .fdt_list = LIST_HEAD_INIT(kho_out.ser.fdt_list), + .track = { + .orders = XARRAY_INIT(kho_out.ser.track.orders, 0), + }, + }, + .finalized = false, +}; + static void *xa_load_or_alloc(struct xarray *xa, unsigned long index, size_t sz) { void *elm, *res; @@ -149,6 +172,9 @@ static int __kho_preserve_order(struct kho_mem_track *track, unsigned long pfn, might_sleep(); + if (kho_out.finalized) + return -EBUSY; + physxa = xa_load(&track->orders, order); if (!physxa) { int err; @@ -631,29 +657,6 @@ int kho_add_subtree(struct kho_serialization *ser, const char *name, void *fdt) } EXPORT_SYMBOL_GPL(kho_add_subtree); -struct kho_out { - struct blocking_notifier_head chain_head; - - struct dentry *dir; - - struct mutex lock; /* protects KHO FDT finalization */ - - struct kho_serialization ser; - bool finalized; -}; - -static struct kho_out kho_out = { - .chain_head = BLOCKING_NOTIFIER_INIT(kho_out.chain_head), - .lock = __MUTEX_INITIALIZER(kho_out.lock), - .ser = { - .fdt_list = LIST_HEAD_INIT(kho_out.ser.fdt_list), - .track = { - .orders = XARRAY_INIT(kho_out.ser.track.orders, 0), - }, - }, - .finalized = false, -}; - int register_kho_notifier(struct notifier_block *nb) { return blocking_notifier_chain_register(&kho_out.chain_head, nb); @@ -681,9 +684,6 @@ int kho_preserve_folio(struct folio *folio) const unsigned int order = folio_order(folio); struct kho_mem_track *track = &kho_out.ser.track; - if (kho_out.finalized) - return -EBUSY; - return __kho_preserve_order(track, pfn, order); } EXPORT_SYMBOL_GPL(kho_preserve_folio); @@ -707,9 +707,6 @@ int kho_preserve_phys(phys_addr_t phys, size_t size) int err = 0; struct kho_mem_track *track = &kho_out.ser.track; - if (kho_out.finalized) - return -EBUSY; - if (!PAGE_ALIGNED(phys) || !PAGE_ALIGNED(size)) return -EINVAL; -- 2.51.0