From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 868ACC55178 for ; Sat, 1 Aug 2026 08:49:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+OQu0ViRo+OKTRZtwaee8K/r5CdM00+NfXwsPcZOUfQ=; b=le3J67gP1EyX0FQegZSh7Jiofs CSucI4NmUBsqtUENpG/5fztRn/TX6TCm0crn9uVGI5RTQnCnMahip/xSM8KHvcfnkOBwWtdc/86YJ 583bZ1t4tFRku7VuxVUpwx8ixN3OpcYNlYfCjrHpk7LMa9MtKIrHibSyGuvj3CchnFv1KmqRe5FEk EDggW1WuF62HVbJjY9HEM31ntI1f2C/TUiSfTntCaETj8qmN0j//NTCjVM+SBcmj2ITBgRRF70Bmo Xf4q1OfUj6V1J7HuUrKKsNPqOeBZggBxq8VusvAhrTL32B9OCqQh8gI2d3lN7rGsWaDqvS4ze9+qo W+TP26PQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wq5Ov-0000000E4Xz-1pn5; Sat, 01 Aug 2026 08:49:01 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wq5Ou-0000000E4XV-2ECT for kexec@lists.infradead.org; Sat, 01 Aug 2026 08:49:00 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id A7B8160AA4; Sat, 1 Aug 2026 08:48:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 375B71F00ADB; Sat, 1 Aug 2026 08:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785574139; bh=+OQu0ViRo+OKTRZtwaee8K/r5CdM00+NfXwsPcZOUfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iN6maE3xvRcvR9jUGbwce4rn96e5OwQIjdICPdPSrYF8kYF+fzXqXuSbf13He+JhU Pr5+jVVB2uie3CfEUIAY0LPGj7jLGkqeJkecAExLNEV44UkmthUtGbyOivpi31JwDA wp8sb1Yh2r4W9SVGP1recS3Ehlctyc9rgXdbenDouG07UMdUv5+e+mI8EHzW7/Eiot HwMzW0I0eZZaichos3gsrd9zGAIN2J8Lko1akYOl36He7VFzCLONjkFIZ5rxU5/n9L 4rOBjqxuNRpv22rz+iCjQkekW8Eh9fmzalOwDd2RD6md8bNVSyktoSHfYTgF92oiQM KKZfhF7CY3YOA== 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 v6 03/22] kho: disallow wide keys in radix tree Date: Sat, 1 Aug 2026 10:48:12 +0200 Message-ID: <20260801084833.1897543-4-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.571.g244d577d93-goog In-Reply-To: <20260801084833.1897543-1-pratyush@kernel.org> References: <20260801084833.1897543-1-pratyush@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org 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.571.g244d577d93-goog