From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 6F8274DB54E for ; Thu, 9 Jul 2026 17:38:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783618721; cv=none; b=dgAC/RGg1QFwAbwrvjas8wK78ZIHuwQibxe5Mi+kZtDNyscXq8Rs0e27lsDn5akXHX+Qh6M0RXmkZZ9OoPo6bzv1HLG4sdUYdYrQ1vEsIN0bqZ7lYKLmb/pLil5jpBdlBokafmyHYt9pk6QtjTUBJa1cqkdcReUDH5PxUkWHEho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783618721; c=relaxed/simple; bh=V+Cardtzfn0V8lS59A12JZHQEE7v7WKvv0/gICttwxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=izWh2dDNaGKp5f1Z80gvX/u0KfLJ94bcHttGp5o5y45zY0ZwNpcqV8wxDa/SghIKnjq3IX6z82QJPEo9Wq6WKIccgYhvPQ549mQ4VB4wQ9NXFHfC51E8uWBMI7opxEh0Lh4oy8WESsJF4sVjktiKcGoGYcB8z/+jb4dAaGpnFjM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VM411R6N; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VM411R6N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFF611F00A3D; Thu, 9 Jul 2026 17:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783618720; bh=s8rhN8Ms1XeLpjAPQvoH3qTAPCovc8Zjh9DU+rsKIjo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VM411R6NNGWqRKQ924XabZNdvhSd0XEacZDp7SuXrbTuQCp3xqeKcPaK8g+sQv41y 2ay5kW6bqgErIuCKzUr7+krx9dlWwPd+Z0GMhqwVKh5CC4u8A0A7kTfwjdSAG1Tni8 Im+e/zfCSOwDK6zIvUNc8SJQJW/CFkcKmK27t+oARDKsX5GO6tVKfS2V2Ar0lGtkcL lL2RmJ0uAc6NFOzoJafHM77HVZ2YW0dfGDIoV7W50jpDRN0oCw0a0jTGR16V2T2l/I +I0/14rBSt+clzDG35ZUVE3hXxpVyx0tj8+63qKVTZOWLNRNnCL0yifhrPY/hcI9W1 E+UybyB5AD+Xg== From: Pratyush Yadav To: Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Alexander Graf , Muchun Song , Oscar Salvador , David Hildenbrand , Andrew Morton , Jason Miu , Jork Loeser Cc: kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 03/21] kho: disallow wide keys in radix tree Date: Thu, 9 Jul 2026 19:37:52 +0200 Message-ID: <20260709173821.429921-4-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260709173821.429921-1-pratyush@kernel.org> References: <20260709173821.429921-1-pratyush@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pratyush Yadav (Google)" The KHO radix tree was designed to track preserved pages. So it does not provide the capability to track any 64-bit key. Instead, it limits the key width to how much it needs for tracking PFNs and their orders. Limiting the width reduces the number of levels in the tree. KHO is not expected to be the only user of the radix tree. With the API generalized to allow other users, now it is possible to add any key to the tree. Check the key width at kho_radix_add_key(), and error out if it exceeds what the tree can handle. Do this instead of increasing the tree depth since right now there are no users that need to use wider keys, so this avoids memory overhead and ABI breakage. Signed-off-by: Pratyush Yadav (Google) --- kernel/liveupdate/kexec_handover.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index ea24f23ce292..e7451743b87e 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -156,6 +156,11 @@ static unsigned long kho_radix_get_table_index(unsigned long key, * intermediate nodes do not exist along the path, they are allocated and added * to the tree. * + * NOTE: Currently only keys of width up to %KHO_RADIX_KEY_WIDTH are supported. + * This limit only exists because current users of the radix tree don't use more + * than that. Changing the maximum width requires changing the tree depth, which + * needs bumping the ABI version. + * * Return: 0 on success, or a negative error code on failure. */ int kho_radix_add_key(struct kho_radix_tree *tree, unsigned long key) @@ -172,6 +177,9 @@ int kho_radix_add_key(struct kho_radix_tree *tree, unsigned long key) if (WARN_ON_ONCE(!tree->root)) return -EINVAL; + if (unlikely(fls64(key) > KHO_RADIX_KEY_WIDTH)) + return -ERANGE; + might_sleep(); guard(mutex)(&tree->lock); @@ -244,6 +252,10 @@ void kho_radix_del_key(struct kho_radix_tree *tree, unsigned long key) if (WARN_ON_ONCE(!tree->root)) return; + /* Keys wider than KHO_RADIX_KEY_WIDTH are not allowed to be added. */ + if (unlikely(fls64(key) > KHO_RADIX_KEY_WIDTH)) + return; + might_sleep(); guard(mutex)(&tree->lock); -- 2.55.0.141.g00534a21ce-goog