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 2BD8737996C for ; Sat, 1 Aug 2026 08:48:59 +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=1785574141; cv=none; b=Vtw5lCulesSkURng28BJflfxyaE5Qb6Whvntx/7N7yaH51BFkexOE721ieeNBtE+1tzf4Vl0KMYd5WJcKqQRxeZgJu866l/mXGqfP5VIg5aoYeJnRFjWsNdFRNSrx9TZ/0xEtyj9Ber3oqxyZi9pZ7OrgFS5Szn0GK8F49phhns= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785574141; c=relaxed/simple; bh=Lch81SPFe6mAikXlqJ8EkJkXdA1Hz9PKUA3aepmpXvc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oSRRBeKZ22+fGz3xq9GQVJAFWru6isMeQGbJG1UBO2DfO7LGaEhO0NMLNC16k10cn+u3YyQTFfx4EYZhnX7FyG/hQbpnqDhQx2PqtUZZKHf1D+h8OYg7yzE68q6w7/5RtoZ2rfgMxiuejVcotnotg1G3mw7GgDXxmoLEV0vAeuY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iN6maE3x; 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="iN6maE3x" 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> 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.571.g244d577d93-goog