From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f46.google.com (mail-yx1-f46.google.com [74.125.224.46]) (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 58EF3337BB0 for ; Fri, 15 May 2026 14:19:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778854755; cv=none; b=ikMePSgRd+LoCi0g0aTcu/2SikhA2Me3QEDo0ujriDExNHs9nej8cN7/zesMNF86h3+iK6zq35Vqb9k8BzhK7wlUiB9YEYHVO3y3rGpO+5N+EhAR0doF+xUPdGHp/Y38AbK+vbQ2bF+HuLsmC5RK21iEFdoJTZOOmu/Olx0KZeI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778854755; c=relaxed/simple; bh=Dzxq3dHMRuxx2d48IolFyJeDDSQk1wok1ljc42dK3Gg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AWnEivYNuq8PxnhedPj66igof6BKTGc9AvDx2fk0qX5jyqEor5xN601uE5Sc+se95SvO2psSD6aojumrKA48XMm0lrOqQYNmoUXowzP0aB95wDT0h71bfORKRblwas06+/bGSMdFZWIJO+CPAblwa7P72Fh0AGc0VLP5NCjj9ko= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=LJeIPy+n; arc=none smtp.client-ip=74.125.224.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="LJeIPy+n" Received: by mail-yx1-f46.google.com with SMTP id 956f58d0204a3-6530287803cso11838534d50.1 for ; Fri, 15 May 2026 07:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1778854753; x=1779459553; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=cRDBDq+fY1oMHQKVFr7tarGavnnf2HzpsD2dAXXMIQM=; b=LJeIPy+ngWtMRFX+x7TkqUuU/vTeyuq/X2q2Xg0xEVp+7YttAbD+bE/gV/GchwefWn WmHUjsFJuUCLyFnXAt0u5PvLFZrdPIMYsWF6lvornkmGWUUIRa2fgueqvyhhSg8K31qT DBCwa9fMUeK8NgWsAZp/T4kW+TtY2yFnQdpkyGu+S5W65a8dp2cOs/RBUSnD3vUeqpgE GQ0GrhtOpT4PG3scHkGqUAFlWlL0rrsEfjEMW0WT9i+hZfymXtRuVtIb1jcvcBv7yIP1 anS6PRIyWG/G1lLHCHYDkMyPvXjkAwjcV3950U4aIxwLNSfHcAKDbw1RV1gJu9+Iw/mn Kicg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778854753; x=1779459553; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cRDBDq+fY1oMHQKVFr7tarGavnnf2HzpsD2dAXXMIQM=; b=QPE86sqXPPl1VaA88LJqJgt10Ve1O+R1Y8mXhgfdHpHT8ZwZuDIp6OfYwmH9UcMaB1 aXdOjU0niK77eEfzWNwwRm4MEpqJVUDmcanIGyfiBRBY5QH6kyd1qXO/1I445fgdwFRU 5z/5Pl7tP2VHA5/4ZoS8oolJyMWho1KGs8J8E8YmIeveZ504nEPKLeOp5Y3MMzZ7DM9T TgRdFDLOQ2KtNqQUE3vI6RFDkTCln2JQrxONKYs60A37yvTF6J7AIkJpWdIJKz19Q0F+ ForqWUL6rdDkdSRJpm2Uo0pfqiobujxsWlsJe9nbPfzqoYT/WgaRD4VZgbWmiD2NhP7J tRyw== X-Forwarded-Encrypted: i=1; AFNElJ9UOEZzMFSXIBQUh4NcD0X7bXOcp5ln4JoeXaf0SkjpQCqg3EbAZiTRP23xj+zaRqzxqClqBPyoUQg8Goc=@vger.kernel.org X-Gm-Message-State: AOJu0YyV6I9YdqePu5NK5lu9cvh3FVpkNk/0i3XcJzNrkHQBsIyUgGi1 9usxiQIGBCQ/rZGXFw5d39DfH9Vsxe2A6HS6wciuKv0ehNtxAiULW9oI6Bo0vCb7nkI= X-Gm-Gg: Acq92OESg5Z7Eh7pRkg7NlXwQQ5SJV/NOwKuT8PlZoctmFrfsmU0AnHuVekz0AOSF5v PgCGyS+4XG/FX5mRLlSPlhf7bQVGArpyj9oAGRzY/mbYb9cE7SsVe53BFy2SS2LCFZ16PWCpXP7 t6eP3OJLvDnxQYuwfA6qU8X1H2mppgidjPAHMFvcGarX1JZvjbzMXK7Ck7Txr50mYbNAdXwAPiI J0iP6nNUPWq/Z0vhUyVnxg9PLleRqOpscJPrfOHdN46Mb6OevUaIZlF7tx2U4M/Qxu8KHVkHzEg FVplLfSn4Ytpb8PHC1m7U+zGZgSpIvViZRk6cLGbZ85PkG4jcfcZU9A/DVQXs0CscEUDYEDIrzO Ye9QuJHHl5Sxt2qZ6eCOiDuvC9ckrgzmDkc9vGzudQujNvoy9Q1f9GdofuW/CLi70mK/LzdPVD4 kBj9h2G3BU5u3gd0HgQwfJgsKSpVBxw9ohu0nGulbV3Qmyt7V3ves= X-Received: by 2002:a05:690e:1544:20b0:651:bd70:1622 with SMTP id 956f58d0204a3-65e2261db18mr3576259d50.10.1778854752017; Fri, 15 May 2026 07:19:12 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8c90c359c74sm52887436d6.45.2026.05.15.07.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 07:19:11 -0700 (PDT) Date: Fri, 15 May 2026 14:19:10 +0000 From: Pasha Tatashin To: George Guo Cc: pasha.tatashin@soleen.com, rppt@kernel.org, pratyush@kernel.org, graf@amazon.com, jasonmiu@google.com, ran.xiaokai@zte.com.cn, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org, George Guo , Kexin Liu Subject: Re: [PATCH 1/1] kho: fix KHO_TREE_MAX_DEPTH for non-4KB page sizes Message-ID: References: <20260509024415.33190-1-dongtai.guo@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260509024415.33190-1-dongtai.guo@linux.dev> On 05-09 10:44, George Guo wrote: > From: George Guo > > KHO_TREE_MAX_DEPTH is calculated as: > > DIV_ROUND_UP(KHO_ORDER_0_LOG2 - KHO_BITMAP_SIZE_LOG2, > KHO_TABLE_SIZE_LOG2) + 1 > > For systems with 16KB pages (e.g. LoongArch), this gives a depth of 4, > with the top-level shift at bit 39. The order-0 bit sits at bit 50 > (KHO_ORDER_0_LOG2 = 64 - PAGE_SHIFT = 50). When inserting or reading > a key, the index extracted at the top level is: > > (1 << 50) >> 39 = 2048 > > 2048 is exactly the table size (PAGE_SIZE / sizeof(phys_addr_t) = 2048 > for 16KB pages), so it wraps to 0, aliasing the order bit to index 0 > and losing it silently. > > On the second kernel, kho_radix_decode_key() sees a key without the > order bit, calls fls64() on the wrong bit, computes a wrong order and > thus a garbage physical address. phys_to_page() of that address faults > in kho_preserved_memory_reserve(), causing a kernel panic early in boot. > > Fix by adding +1 to the DIV_ROUND_UP numerator so the formula accounts > for the order bit itself, giving depth 5 for 16KB pages. The top-level > shift becomes 50, and (1 << 50) >> 50 = 1, which is nonzero and > unambiguous. For 4KB and 64KB page sizes the depth is unchanged. > > Fixes: 3f2ad90060f6 ("kho: adopt radix tree for preserved memory tracking") > > Tested-by: Kexin Liu > Signed-off-by: George Guo Reviewed-by: Pasha Tatashin The patch fixes 16K support on ARM64. Pasha