From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 D1D0834252C for ; Wed, 13 May 2026 15:07:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778684853; cv=none; b=WDCcpZIHVtKif5wHBImPSc77HYvs4ptAUFK2DOiWrKWH1jc/2mBvhHem/hwmx7AA9U6FOYWWJHAQW2AZlQVX0jN9z/y/Lj4Oq1YF31pLHruaUiMcxR2ubGj/4NXKm1SNLvCigP0TiYyzsemald7ZTaTkkhd73ZMiWi3xmcXEFzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778684853; c=relaxed/simple; bh=Q1jDygLFUp/AqljlvGb7Nng18GUuZ3qU4nI/WEGT6hE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mHYXSPtxuSLzNWI/cwTL15Gs77MtrBIljVaJvlpL8v2JTTSdxapRwZacNsv7GQNZ3Oz8gI+rd1pASQqUO5KXeI6HESWiqqeG4weQp93RhN0HRUhJEMxCp0Xl895CF8Z627RQ52FoXDxdAKaYspJ1SCn7/aUMv9mJQ7anqtz1fSw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=NE/mD9WC; arc=none smtp.client-ip=95.215.58.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="NE/mD9WC" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778684848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U5FgpYdWutcIouGicjgojW9gOVO0tiNobAoLydLLHpI=; b=NE/mD9WC9zOAcd3zhlSYl0Cqj9YZsIOlgArz6a2uSxTzDzgPNbdatWQb46xgsRMfDyQyuO FbhokL+ZCFFbeOjECotujV7IQL/rnfpmKH9ArHa+ck4pceT+KZILLm/yK/zSjPk4buHBk5 /v8g66veXLhfQVWNf+k3kxmXnoKJajI= From: George Guo To: pratyush@kernel.org Cc: akpm@linux-foundation.org, dongtai.guo@linux.dev, graf@amazon.com, guodongtai@kylinos.cn, jasonmiu@google.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, liukexin@kylinos.cn, pasha.tatashin@soleen.com, ran.xiaokai@zte.com.cn, rppt@kernel.org Subject: Re: [PATCH 1/1] kho: fix KHO_TREE_MAX_DEPTH for non-4KB page sizes Date: Wed, 13 May 2026 23:07:18 +0800 Message-Id: <20260513150718.182224-1-dongtai.guo@linux.dev> In-Reply-To: <2vxzcxz2dybi.fsf@kernel.org> References: <2vxzcxz2dybi.fsf@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 X-Migadu-Flow: FLOW_OUT Sorry for the late reply. On Mon, May 11 2026, Pratyush Yadav wrote: > As of now, we only support KHO on x86 and arm64. Are you working on > supporting it for LoongArch? What is your use case? Yes, we are adding KHO support for LoongArch (16KB page size). The LoongArch patches are being prepared separately. This fix is a prerequisite. > Maybe I don't understand the math so well, but I can't see the problem. > ... > level = 4, s = 50, idx = 1 > What am I missing? The issue is that all three operations start the traversal at KHO_TREE_MAX_DEPTH - 1, not KHO_TREE_MAX_DEPTH: kho_radix_add_page() line 180: for (i = KHO_TREE_MAX_DEPTH - 1; i > 0; i--) kho_radix_del_page() line 255: for (i = KHO_TREE_MAX_DEPTH - 1; i > 0; i--) kho_radix_walk_tree() line 356: __kho_radix_walk_tree(..., KHO_TREE_MAX_DEPTH - 1, ...) So with depth=4 the effective top level is 3, not 4. phys_to_page() of that address faults in kho_preserved_memory_reserve(). This is confirmed by a kernel panic on 7.1-rc3 LoongArch (16KB pages) without the fix. With depth=5 the top level is 4 (shift=50): (key >> 50) % 2048 = 1 /* order bit correctly captured */ Signed-off-by: George Guo Panic log on 7.1-rc3 LoongArch (16KB pages) without the fix: [ 0.000000] CPU 0 Unable to handle kernel paging request at virtual address 00003d3ffe000028, era == 90000000c162f10c, ra == 90000000c162f0f8 [ 0.000000] Oops[#1]: ... [ 0.000000] Call Trace: [ 0.000000] [<90000000c162f10c>] kho_preserved_memory_reserve+0xc4/0xe8 [ 0.000000] [<90000000c0129f88>] __kho_radix_walk_tree+0xf0/0x138 [ 0.000000] [<90000000c0129f10>] __kho_radix_walk_tree+0x78/0x138 [ 0.000000] [<90000000c012b730>] kho_radix_walk_tree+0x88/0xe8 [ 0.000000] [<90000000c162f874>] kho_memory_init+0x220/0x4e4 [ 0.000000] [<90000000c1639b38>] mm_core_init+0x168/0x1a0 [ 0.000000] [<90000000c1620d50>] start_kernel+0x5c4/0x778 [ 0.000000] Kernel panic - not syncing: Attempted to kill the idle task!